vdr
1.7.31
Main Page
Namespaces
Classes
Files
File List
File Members
include
libsi
include/libsi/si.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (c) 2003 by Marcel Wiesweg *
3
* *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
8
* *
9
* $Id: si.h 2.5 2012/01/11 11:35:17 kls Exp $
10
* *
11
***************************************************************************/
12
13
#ifndef LIBSI_SI_H
14
#define LIBSI_SI_H
15
16
#include <stdint.h>
17
18
#include "
util.h
"
19
#include "
headers.h
"
20
21
namespace
SI
{
22
23
enum
TableId
{
TableIdPAT
= 0x00,
//program association section
24
TableIdCAT
= 0x01,
//conditional access section
25
TableIdPMT
= 0x02,
//program map section
26
TableIdTSDT
= 0x03,
//transport stream description section
27
TableIdNIT
= 0x40,
//network information, actual network section
28
TableIdNIT_other
= 0x41,
//network information section, other network
29
TableIdSDT
= 0x42,
//service description section
30
TableIdSDT_other
= 0x46,
31
TableIdBAT
= 0x4A,
//bouquet association section
32
TableIdEIT_presentFollowing
= 0x4E,
//event information section
33
TableIdEIT_presentFollowing_other
= 0x4F,
34
//range from 0x50 to 0x5F
35
TableIdEIT_schedule_first
= 0x50,
36
TableIdEIT_schedule_last
= 0x5F,
37
//range from 0x60 to 0x6F
38
TableIdEIT_schedule_Other_first
= 0x60,
39
TableIdEIT_schedule_Other_last
= 0x6F,
40
TableIdTDT
= 0x70,
//time date section
41
TableIdRST
= 0x71,
//running status section
42
TableIdST
= 0x72,
//stuffing section
43
TableIdTOT
= 0x73,
//time offset section
44
TableIdDIT
= 0x7E,
//discontinuity information section
45
TableIdSIT
= 0x7F,
//service information section
46
TableIdAIT
= 0x74,
//application information section
47
TableIdPremiereCIT
= 0xA0
//premiere content information section
48
};
49
50
51
enum
DescriptorTag
{
52
// defined by ISO/IEC 13818-1
53
VideoStreamDescriptorTag
= 0x02,
54
AudioStreamDescriptorTag
= 0x03,
55
HierarchyDescriptorTag
= 0x04,
56
RegistrationDescriptorTag
= 0x05,
57
DataStreamAlignmentDescriptorTag
= 0x06,
58
TargetBackgroundGridDescriptorTag
= 0x07,
59
VideoWindowDescriptorTag
= 0x08,
60
CaDescriptorTag
= 0x09,
61
ISO639LanguageDescriptorTag
= 0x0A,
62
SystemClockDescriptorTag
= 0x0B,
63
MultiplexBufferUtilizationDescriptorTag
= 0x0C,
64
CopyrightDescriptorTag
= 0x0D,
65
MaximumBitrateDescriptorTag
= 0x0E,
66
PrivateDataIndicatorDescriptorTag
= 0x0F,
67
SmoothingBufferDescriptorTag
= 0x10,
68
STDDescriptorTag
= 0x11,
69
IBPDescriptorTag
= 0x12,
70
// defined by ISO-13818-6 (DSM-CC)
71
CarouselIdentifierDescriptorTag
= 0x13,
72
// 0x14 - 0x3F Reserved
73
// defined by ETSI (EN 300 468)
74
NetworkNameDescriptorTag
= 0x40,
75
ServiceListDescriptorTag
= 0x41,
76
StuffingDescriptorTag
= 0x42,
77
SatelliteDeliverySystemDescriptorTag
= 0x43,
78
CableDeliverySystemDescriptorTag
= 0x44,
79
VBIDataDescriptorTag
= 0x45,
80
VBITeletextDescriptorTag
= 0x46,
81
BouquetNameDescriptorTag
= 0x47,
82
ServiceDescriptorTag
= 0x48,
83
CountryAvailabilityDescriptorTag
= 0x49,
84
LinkageDescriptorTag
= 0x4A,
85
NVODReferenceDescriptorTag
= 0x4B,
86
TimeShiftedServiceDescriptorTag
= 0x4C,
87
ShortEventDescriptorTag
= 0x4D,
88
ExtendedEventDescriptorTag
= 0x4E,
89
TimeShiftedEventDescriptorTag
= 0x4F,
90
ComponentDescriptorTag
= 0x50,
91
MocaicDescriptorTag
= 0x51,
92
StreamIdentifierDescriptorTag
= 0x52,
93
CaIdentifierDescriptorTag
= 0x53,
94
ContentDescriptorTag
= 0x54,
95
ParentalRatingDescriptorTag
= 0x55,
96
TeletextDescriptorTag
= 0x56,
97
TelephoneDescriptorTag
= 0x57,
98
LocalTimeOffsetDescriptorTag
= 0x58,
99
SubtitlingDescriptorTag
= 0x59,
100
TerrestrialDeliverySystemDescriptorTag
= 0x5A,
101
MultilingualNetworkNameDescriptorTag
= 0x5B,
102
MultilingualBouquetNameDescriptorTag
= 0x5C,
103
MultilingualServiceNameDescriptorTag
= 0x5D,
104
MultilingualComponentDescriptorTag
= 0x5E,
105
PrivateDataSpecifierDescriptorTag
= 0x5F,
106
ServiceMoveDescriptorTag
= 0x60,
107
ShortSmoothingBufferDescriptorTag
= 0x61,
108
FrequencyListDescriptorTag
= 0x62,
109
PartialTransportStreamDescriptorTag
= 0x63,
110
DataBroadcastDescriptorTag
= 0x64,
111
ScramblingDescriptorTag
= 0x65,
112
DataBroadcastIdDescriptorTag
= 0x66,
113
TransportStreamDescriptorTag
= 0x67,
114
DSNGDescriptorTag
= 0x68,
115
PDCDescriptorTag
= 0x69,
116
AC3DescriptorTag
= 0x6A,
117
AncillaryDataDescriptorTag
= 0x6B,
118
CellListDescriptorTag
= 0x6C,
119
CellFrequencyLinkDescriptorTag
= 0x6D,
120
AnnouncementSupportDescriptorTag
= 0x6E,
121
ApplicationSignallingDescriptorTag
= 0x6F,
122
AdaptationFieldDataDescriptorTag
= 0x70,
123
ServiceIdentifierDescriptorTag
= 0x71,
124
ServiceAvailabilityDescriptorTag
= 0x72,
125
// defined by ETSI (EN 300 468) v 1.7.1
126
DefaultAuthorityDescriptorTag
= 0x73,
127
RelatedContentDescriptorTag
= 0x74,
128
TVAIdDescriptorTag
= 0x75,
129
ContentIdentifierDescriptorTag
= 0x76,
130
TimeSliceFecIdentifierDescriptorTag
= 0x77,
131
ECMRepetitionRateDescriptorTag
= 0x78,
132
S2SatelliteDeliverySystemDescriptorTag
= 0x79,
133
EnhancedAC3DescriptorTag
= 0x7A,
134
DTSDescriptorTag
= 0x7B,
135
AACDescriptorTag
= 0x7C,
136
ExtensionDescriptorTag
= 0x7F,
137
// Extension descriptors
138
ImageIconDescriptorTag
= 0x00,
139
CpcmDeliverySignallingDescriptor
= 0x01,
140
CPDescriptorTag
= 0x02,
141
CPIdentifierDescriptorTag
= 0x03,
142
T2DeliverySystemDescriptorTag
= 0x04,
143
SHDeliverySystemDescriptorTag
= 0x05,
144
SupplementaryAudioDescriptorTag
= 0x06,
145
NetworkChangeNotifyDescriptorTag
= 0x07,
146
MessageDescriptorTag
= 0x08,
147
TargetRegionDescriptorTag
= 0x09,
148
TargetRegionNameDescriptorTag
= 0x0A,
149
ServiceRelocatedDescriptorTag
= 0x0B,
150
151
// Defined by ETSI TS 102 812 (MHP)
152
// They once again start with 0x00 (see page 234, MHP specification)
153
MHP_ApplicationDescriptorTag
= 0x00,
154
MHP_ApplicationNameDescriptorTag
= 0x01,
155
MHP_TransportProtocolDescriptorTag
= 0x02,
156
MHP_DVBJApplicationDescriptorTag
= 0x03,
157
MHP_DVBJApplicationLocationDescriptorTag
= 0x04,
158
// 0x05 - 0x0A is unimplemented this library
159
MHP_ExternalApplicationAuthorisationDescriptorTag
= 0x05,
160
MHP_IPv4RoutingDescriptorTag
= 0x06,
161
MHP_IPv6RoutingDescriptorTag
= 0x07,
162
MHP_DVBHTMLApplicationDescriptorTag
= 0x08,
163
MHP_DVBHTMLApplicationLocationDescriptorTag
= 0x09,
164
MHP_DVBHTMLApplicationBoundaryDescriptorTag
= 0x0A,
165
MHP_ApplicationIconsDescriptorTag
= 0x0B,
166
MHP_PrefetchDescriptorTag
= 0x0C,
167
MHP_DelegatedApplicationDescriptorTag
= 0x0E,
168
MHP_ApplicationStorageDescriptorTag
= 0x10,
169
MHP_SimpleApplicationLocationDescriptorTag
= 0x15,
170
MHP_SimpleApplicationBoundaryDescriptorTag
= 0x17,
171
// Premiere private Descriptor Tags
172
PremiereContentTransmissionDescriptorTag
= 0xF2,
173
174
//a descriptor currently unimplemented in this library
175
//the actual value 0xFF is "forbidden" according to the spec.
176
UnimplementedDescriptorTag
= 0xFF
177
};
178
179
enum
DescriptorTagDomain
{
SI
,
MHP
,
PCIT
};
180
181
enum
RunningStatus
{
RunningStatusUndefined
= 0,
182
RunningStatusNotRunning
= 1,
183
RunningStatusStartsInAFewSeconds
= 2,
184
RunningStatusPausing
= 3,
185
RunningStatusRunning
= 4
186
};
187
188
enum
LinkageType
{
LinkageTypeInformationService
= 0x01,
189
LinkageTypeEPGService
= 0x02,
190
LinkageTypeCaReplacementService
= 0x03,
191
LinkageTypeTSContainingCompleteNetworkBouquetSi
= 0x04,
192
LinkageTypeServiceReplacementService
= 0x05,
193
LinkageTypeDataBroadcastService
= 0x06,
194
LinkageTypeRCSMap
= 0x07,
195
LinkageTypeMobileHandover
= 0x08,
196
LinkageTypeSystemSoftwareUpdateService
= 0x09,
197
LinkageTypeTSContainingSsuBatOrNit
= 0x0A
198
};
199
200
enum
AudioType
{
AudioTypeUndefined
= 0x00,
201
AudioTypeCleanEffects
= 0x01,
202
AudioTypeHearingImpaired
= 0x02,
203
AudioTypeVisualImpairedCommentary
= 0x03
204
};
205
206
/* Some principles:
207
- Objects that return references to other objects contained in their data must make sure
208
that the returned objects have been parsed.
209
(the Loop subclasses take care of that.)
210
Note that this does not apply to Loops and Strings (their are never returned by reference, BTW).
211
*/
212
213
class
Object
:
public
Parsable
{
214
public
:
215
Object
();
216
Object
(
CharArray
&d);
217
//can only be called once since data is immutable
218
void
setData
(
const
unsigned
char
*
data
,
int
size,
bool
doCopy=
true
);
219
CharArray
getData
() {
return
data
; }
220
//returns the valid flag which indicates if data is all right or errors have been encountered
221
bool
isValid
() {
return
data.isValid(); }
222
virtual
int
getLength
() = 0;
223
protected
:
224
CharArray
data
;
225
//is protected - not used for sections
226
template
<
class
T>
friend
class
StructureLoop
;
227
void
setData
(
CharArray
&d);
228
//returns whether the given offset fits within the limits of the actual data
229
//The valid flag will be set accordingly
230
bool
checkSize
(
int
offset);
231
};
232
233
class
Section
:
public
Object
{
234
public
:
235
//convenience: sets data and parses if doParse
236
Section
(
const
unsigned
char
*
data
,
bool
doCopy=
true
);
237
Section
() {}
238
TableId
getTableId
()
const
;
239
virtual
int
getLength
();
240
241
static
int
getLength
(
const
unsigned
char
*d);
242
static
TableId
getTableId
(
const
unsigned
char
*d);
243
};
244
245
class
CRCSection
:
public
Section
{
246
public
:
247
//convenience: sets data and parses if doParse
248
CRCSection
(
const
unsigned
char
*
data
,
bool
doCopy=
true
) :
Section
(data, doCopy) {}
249
CRCSection
() {}
250
bool
isCRCValid
();
251
//convenience: isValid+CheckParse
252
bool
CheckCRCAndParse
();
253
};
254
255
/* A section which has the ExtendedSectionHeader
256
(section_syntax_indicator==1) */
257
class
NumberedSection
:
public
CRCSection
{
258
public
:
259
NumberedSection
(
const
unsigned
char
*
data
,
bool
doCopy=
true
) :
CRCSection
(data, doCopy) {}
260
NumberedSection
() {}
261
int
getTableIdExtension
()
const
;
262
bool
getCurrentNextIndicator
()
const
;
263
int
getVersionNumber
()
const
;
264
int
getSectionNumber
()
const
;
265
int
getLastSectionNumber
()
const
;
266
bool
moreThanOneSection
()
const
{
return
getLastSectionNumber
()>0; }
267
268
static
int
getTableIdExtension
(
const
unsigned
char
*d);
269
};
270
271
class
VariableLengthPart
:
public
Object
{
272
public
:
273
//never forget to call this
274
void
setData
(
CharArray
d,
int
l) {
Object::setData
(d);
checkSize
(l);
length
=l; }
275
//convenience method
276
void
setDataAndOffset
(
CharArray
d,
int
l,
int
&offset) {
Object::setData
(d);
checkSize
(l);
length
=l; offset+=l; }
277
virtual
int
getLength
() {
return
length
; }
278
private
:
279
int
length
;
280
};
281
282
class
LoopElement
:
public
Object
{
283
};
284
285
class
Descriptor
:
public
LoopElement
{
286
public
:
287
virtual
int
getLength
();
288
DescriptorTag
getDescriptorTag
()
const
;
289
290
static
int
getLength
(
const
unsigned
char
*d);
291
static
DescriptorTag
getDescriptorTag
(
const
unsigned
char
*d);
292
protected
:
293
friend
class
DescriptorLoop
;
294
//returns a subclass of descriptor according to the data given.
295
//The object is allocated with new and must be delete'd.
296
//setData() will have been called, CheckParse() not.
297
//if returnUnimplemetedDescriptor==true:
298
// Never returns null - maybe the UnimplementedDescriptor.
299
//if returnUnimplemetedDescriptor==false:
300
// Never returns the UnimplementedDescriptor - maybe null
301
static
Descriptor
*
getDescriptor
(
CharArray
d,
DescriptorTagDomain
domain,
bool
returnUnimplemetedDescriptor);
302
};
303
304
class
Loop
:
public
VariableLengthPart
{
305
public
:
306
class
Iterator
{
307
public
:
308
Iterator
() {
i
=0; }
309
void
reset
() {
i
=0; }
310
private
:
311
template
<
class
T>
friend
class
StructureLoop
;
312
friend
class
DescriptorLoop
;
313
template
<
class
T>
friend
class
TypeLoop
;
314
friend
class
ExtendedEventDescriptors
;
315
int
i
;
316
};
317
protected
:
318
virtual
void
Parse
() {}
319
};
320
321
//contains LoopElements of one type only
322
template
<
class
T>
class
StructureLoop
:
public
Loop
{
323
public
:
324
//currently you must use a while-loop testing for hasNext()
325
//i must be 0 to get the first descriptor (with the first call)
326
bool
getNext
(T &obj,
Iterator
&it)
327
{
328
if
(!
isValid
() || it.
i
>=
getLength
())
329
return
false
;
330
CharArray
d=
data
;
331
d.
addOffset
(it.
i
);
332
T ret;
333
ret.setData(d);
334
ret.CheckParse();
335
if
(!
checkSize
(ret.getLength()))
336
return
false
;
337
it.
i
+=ret.getLength();
338
obj=ret;
339
return
true
;
340
}
341
T*
getNextAsPointer
(
Iterator
&it)
342
{
343
if
(!
isValid
() || it.
i
>=
getLength
())
344
return
0;
345
CharArray
d=
data
;
346
d.
addOffset
(it.
i
);
347
T *ret=
new
T();
348
ret->setData(d);
349
ret->CheckParse();
350
if
(!
checkSize
(ret->getLength()))
351
return
0;
352
it.
i
+=ret->getLength();
353
return
ret;
354
}
355
//bool hasNext(Iterator &it) { return getLength() > it.i; }
356
};
357
358
//contains descriptors of different types
359
class
DescriptorLoop
:
public
Loop
{
360
public
:
361
DescriptorLoop
() {
domain
=
SI
; }
362
//i must be 0 to get the first descriptor (with the first call)
363
//All returned descriptors must be delete'd.
364
//returns null if no more descriptors available
365
Descriptor
*
getNext
(Iterator &it);
366
//return the next descriptor with given tag, or 0 if not available.
367
//if returnUnimplemetedDescriptor==true:
368
// an UnimplementedDescriptor may be returned if the next matching descriptor is unimplemented,
369
// 0 will be returned if and only if no matching descriptor is found.
370
//if returnUnimplemetedDescriptor==false:
371
// if 0 is returned, either no descriptor with the given tag was found,
372
// or descriptors were found, but the descriptor type is not implemented
373
//In either case, a return value of 0 indicates that no further calls to this method
374
//with the iterator shall be made.
375
Descriptor
*
getNext
(Iterator &it,
DescriptorTag
tag,
bool
returnUnimplemetedDescriptor=
false
);
376
//return the next descriptor with one of the given tags, or 0 if not available.
377
//if returnUnimplemetedDescriptor==true:
378
// returns 0 if and only if no descriptor with one of the given tags was found.
379
// The UnimplementedDescriptor may be returned.
380
//if returnUnimplemetedDescriptor==false:
381
// if 0 is returned, either no descriptor with one of the given tags was found,
382
// or descriptors were found, but none of them are implemented.
383
// The UnimplementedDescriptor will never be returned.
384
//In either case, a return value of 0 indicates that no further calls to this method
385
//with the iterator shall be made.
386
Descriptor
*
getNext
(Iterator &it,
DescriptorTag
*tags,
int
arrayLength,
bool
returnUnimplemetedDescriptor=
false
);
387
//returns the number of descriptors in this loop
388
int
getNumberOfDescriptors
();
389
//writes the tags of the descriptors in this loop in the array,
390
// which must at least have the size getNumberOfDescriptors().
391
//The number of descriptors, i.e. getNumberOfDescriptors(), is returned.
392
// You can specify the array type (Descriptor tags are 8 Bit,
393
// you might e.g. choose a char, short, int or DescriptorTag array)
394
template
<
typename
T>
int
getDescriptorTags
(T *tags)
395
{
396
const
unsigned
char
*p=
data
.
getData
();
397
const
unsigned
char
*end=p+
getLength
();
398
int
count=0;
399
while
(p < end) {
400
tags[count++]=(T)
Descriptor::getDescriptorTag
(p);
401
p+=
Descriptor::getLength
(p);
402
}
403
return
count;
404
}
405
protected
:
406
Descriptor
*
createDescriptor
(
int
&i,
bool
returnUnimplemetedDescriptor);
407
DescriptorTagDomain
domain
;
408
};
409
410
typedef
uint8_t
EightBit
;
411
typedef
uint16_t
SixteenBit
;
412
typedef
uint32_t
ThirtyTwoBit
;
413
typedef
uint64_t
SixtyFourBit
;
414
415
template
<
typename
T>
class
TypeLoop
:
public
Loop
{
416
public
:
417
int
getCount
() {
return
getLength
()/
sizeof
(T); }
418
T
operator[]
(
const
int
index)
const
419
{
420
switch
(
sizeof
(T)) {
421
case
1:
422
return
data
[index];
423
case
2:
424
return
data
.
TwoBytes
(index);
425
case
4:
426
return
data
.
FourBytes
(index);
427
case
8:
428
return
(
SixtyFourBit
(
data
.
FourBytes
(index)) << 32) |
data
.
FourBytes
(index+4);
429
default
:
430
return
0;
// just to avoid a compiler warning
431
}
432
return
0;
// just to avoid a compiler warning
433
}
434
T
getNext
(
Iterator
&it)
const
435
{
436
T ret=
operator[]
(it.
i
);
437
it.
i
+=
sizeof
(T);
438
return
ret;
439
}
440
bool
hasNext
(
Iterator
&it) {
return
isValid
() && (
getLength
() > it.
i
); }
441
};
442
443
class
MHP_DescriptorLoop
:
public
DescriptorLoop
{
444
public
:
445
MHP_DescriptorLoop
() {
domain
=
MHP
; }
446
};
447
448
//Premiere Content Information Table
449
class
PCIT_DescriptorLoop
:
public
DescriptorLoop
{
450
public
:
451
PCIT_DescriptorLoop
() {
domain
=
PCIT
; }
452
};
453
454
//The content of the ExtendedEventDescriptor may be split over several
455
//descriptors if the text is longer than 256 bytes.
456
//The following classes provide base functionality to handle this case.
457
class
GroupDescriptor
:
public
Descriptor
{
458
public
:
459
virtual
int
getDescriptorNumber
() = 0;
460
virtual
int
getLastDescriptorNumber
() = 0;
461
};
462
463
class
DescriptorGroup
{
464
public
:
465
DescriptorGroup
(
bool
deleteOnDesctruction
=
true
);
466
~DescriptorGroup
();
467
void
Add
(
GroupDescriptor
*d);
468
void
Delete
();
469
int
getLength
() {
return
length
; }
470
GroupDescriptor
**
getDescriptors
() {
return
array
; }
471
bool
isComplete
();
//if all descriptors have been added
472
protected
:
473
int
length
;
474
GroupDescriptor
**
array
;
475
bool
deleteOnDesctruction
;
476
};
477
478
class
String
:
public
VariableLengthPart
{
479
public
:
480
//A note to the length: getLength() returns the length of the raw data.
481
//The text may be shorter. Its length can be obtained with one of the
482
//getText functions and strlen.
483
484
//returns text. Data is allocated with new and must be delete'd by the user.
485
char
*
getText
();
486
//copies text into given buffer.
487
//a buffer of size getLength()+1 is guaranteed to be sufficiently large.
488
//In most descriptors the string length is an 8-bit field,
489
//so the maximum there is 256.
490
//returns the given buffer for convenience.
491
//The emphasis marks 0x86 and 0x87 are still available.
492
char
*
getText
(
char
*buffer,
int
size);
493
//The same semantics as for getText(char*) apply.
494
//The short version of the text according to ETSI TR 101 211 (chapter 4.6)
495
//will be written into the shortVersion buffer (which should, therefore, have the same
496
//length as buffer). If no shortVersion is available, shortVersion will contain
497
//an empty string.
498
//The emphasis marks 0x86 and 0x87 are still available in buffer, but not in shortVersion.
499
char
*
getText
(
char
*buffer,
char
*shortVersion,
int
sizeBuffer,
int
sizeShortVersion);
500
protected
:
501
virtual
void
Parse
() {}
502
void
decodeText
(
char
*buffer,
int
size);
503
void
decodeText
(
char
*buffer,
char
*shortVersion,
int
sizeBuffer,
int
sizeShortVersion);
504
};
505
506
// Call this function to set the system character table. CharacterTable is a string
507
// like "iso8859-15" or "utf-8" (case insensitive).
508
// Returns true if the character table was recognized.
509
bool
SetSystemCharacterTable
(
const
char
*CharacterTable);
510
// Determines the character table used in the given buffer and returns
511
// a string indicating that table. If no table can be determined, the
512
// default ISO6937 is returned. If a table can be determined, the buffer
513
// and length are adjusted accordingly.
514
const
char
*
getCharacterTable
(
const
unsigned
char
*&buffer,
int
&length,
bool
*isSingleByte = NULL);
515
bool
convertCharacterTable
(
const
char
*from,
size_t
fromLength,
char
*to,
size_t
toLength,
const
char
*fromCode);
516
bool
systemCharacterTableIsSingleByte
(
void
);
517
518
}
//end of namespace
519
520
#endif //LIBSI_SI_H
Generated by
1.8.1.2