vdr
2.0.2
Main Page
Namespaces
Classes
Files
File List
File Members
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.6 2012/10/15 11:56:06 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
delete
ret;
352
return
0;
353
}
354
it.
i
+=ret->getLength();
355
return
ret;
356
}
357
//bool hasNext(Iterator &it) { return getLength() > it.i; }
358
};
359
360
//contains descriptors of different types
361
class
DescriptorLoop
:
public
Loop
{
362
public
:
363
DescriptorLoop
() {
domain
=
SI
; }
364
//i must be 0 to get the first descriptor (with the first call)
365
//All returned descriptors must be delete'd.
366
//returns null if no more descriptors available
367
Descriptor
*
getNext
(Iterator &it);
368
//return the next descriptor with given tag, or 0 if not available.
369
//if returnUnimplemetedDescriptor==true:
370
// an UnimplementedDescriptor may be returned if the next matching descriptor is unimplemented,
371
// 0 will be returned if and only if no matching descriptor is found.
372
//if returnUnimplemetedDescriptor==false:
373
// if 0 is returned, either no descriptor with the given tag was found,
374
// or descriptors were found, but the descriptor type is not implemented
375
//In either case, a return value of 0 indicates that no further calls to this method
376
//with the iterator shall be made.
377
Descriptor
*
getNext
(Iterator &it,
DescriptorTag
tag,
bool
returnUnimplemetedDescriptor=
false
);
378
//return the next descriptor with one of the given tags, or 0 if not available.
379
//if returnUnimplemetedDescriptor==true:
380
// returns 0 if and only if no descriptor with one of the given tags was found.
381
// The UnimplementedDescriptor may be returned.
382
//if returnUnimplemetedDescriptor==false:
383
// if 0 is returned, either no descriptor with one of the given tags was found,
384
// or descriptors were found, but none of them are implemented.
385
// The UnimplementedDescriptor will never be returned.
386
//In either case, a return value of 0 indicates that no further calls to this method
387
//with the iterator shall be made.
388
Descriptor
*
getNext
(Iterator &it,
DescriptorTag
*tags,
int
arrayLength,
bool
returnUnimplemetedDescriptor=
false
);
389
//returns the number of descriptors in this loop
390
int
getNumberOfDescriptors
();
391
//writes the tags of the descriptors in this loop in the array,
392
// which must at least have the size getNumberOfDescriptors().
393
//The number of descriptors, i.e. getNumberOfDescriptors(), is returned.
394
// You can specify the array type (Descriptor tags are 8 Bit,
395
// you might e.g. choose a char, short, int or DescriptorTag array)
396
template
<
typename
T>
int
getDescriptorTags
(T *tags)
397
{
398
const
unsigned
char
*p=
data
.
getData
();
399
const
unsigned
char
*end=p+
getLength
();
400
int
count=0;
401
while
(p < end) {
402
tags[count++]=(T)
Descriptor::getDescriptorTag
(p);
403
p+=
Descriptor::getLength
(p);
404
}
405
return
count;
406
}
407
protected
:
408
Descriptor
*
createDescriptor
(
int
&i,
bool
returnUnimplemetedDescriptor);
409
DescriptorTagDomain
domain
;
410
};
411
412
typedef
uint8_t
EightBit
;
413
typedef
uint16_t
SixteenBit
;
414
typedef
uint32_t
ThirtyTwoBit
;
415
typedef
uint64_t
SixtyFourBit
;
416
417
template
<
typename
T>
class
TypeLoop
:
public
Loop
{
418
public
:
419
int
getCount
() {
return
getLength
()/
sizeof
(T); }
420
T
operator[]
(
const
int
index)
const
421
{
422
switch
(
sizeof
(T)) {
423
case
1:
424
return
data
[index];
425
case
2:
426
return
data
.
TwoBytes
(index);
427
case
4:
428
return
data
.
FourBytes
(index);
429
case
8:
430
return
(
SixtyFourBit
(
data
.
FourBytes
(index)) << 32) |
data
.
FourBytes
(index+4);
431
default
:
432
return
0;
// just to avoid a compiler warning
433
}
434
return
0;
// just to avoid a compiler warning
435
}
436
T
getNext
(
Iterator
&it)
const
437
{
438
T ret=
operator[]
(it.
i
);
439
it.
i
+=
sizeof
(T);
440
return
ret;
441
}
442
bool
hasNext
(
Iterator
&it) {
return
isValid
() && (
getLength
() > it.
i
); }
443
};
444
445
class
MHP_DescriptorLoop
:
public
DescriptorLoop
{
446
public
:
447
MHP_DescriptorLoop
() {
domain
=
MHP
; }
448
};
449
450
//Premiere Content Information Table
451
class
PCIT_DescriptorLoop
:
public
DescriptorLoop
{
452
public
:
453
PCIT_DescriptorLoop
() {
domain
=
PCIT
; }
454
};
455
456
//The content of the ExtendedEventDescriptor may be split over several
457
//descriptors if the text is longer than 256 bytes.
458
//The following classes provide base functionality to handle this case.
459
class
GroupDescriptor
:
public
Descriptor
{
460
public
:
461
virtual
int
getDescriptorNumber
() = 0;
462
virtual
int
getLastDescriptorNumber
() = 0;
463
};
464
465
class
DescriptorGroup
{
466
public
:
467
DescriptorGroup
(
bool
deleteOnDesctruction
=
true
);
468
~DescriptorGroup
();
469
void
Add
(
GroupDescriptor
*d);
470
void
Delete
();
471
int
getLength
() {
return
length
; }
472
GroupDescriptor
**
getDescriptors
() {
return
array
; }
473
bool
isComplete
();
//if all descriptors have been added
474
protected
:
475
int
length
;
476
GroupDescriptor
**
array
;
477
bool
deleteOnDesctruction
;
478
};
479
480
class
String
:
public
VariableLengthPart
{
481
public
:
482
//A note to the length: getLength() returns the length of the raw data.
483
//The text may be shorter. Its length can be obtained with one of the
484
//getText functions and strlen.
485
486
//returns text. Data is allocated with new and must be delete'd by the user.
487
char
*
getText
();
488
//copies text into given buffer.
489
//a buffer of size getLength()+1 is guaranteed to be sufficiently large.
490
//In most descriptors the string length is an 8-bit field,
491
//so the maximum there is 256.
492
//returns the given buffer for convenience.
493
//The emphasis marks 0x86 and 0x87 are still available.
494
char
*
getText
(
char
*buffer,
int
size);
495
//The same semantics as for getText(char*) apply.
496
//The short version of the text according to ETSI TR 101 211 (chapter 4.6)
497
//will be written into the shortVersion buffer (which should, therefore, have the same
498
//length as buffer). If no shortVersion is available, shortVersion will contain
499
//an empty string.
500
//The emphasis marks 0x86 and 0x87 are still available in buffer, but not in shortVersion.
501
char
*
getText
(
char
*buffer,
char
*shortVersion,
int
sizeBuffer,
int
sizeShortVersion);
502
protected
:
503
virtual
void
Parse
() {}
504
void
decodeText
(
char
*buffer,
int
size);
505
void
decodeText
(
char
*buffer,
char
*shortVersion,
int
sizeBuffer,
int
sizeShortVersion);
506
};
507
508
// Call this function to set the system character table. CharacterTable is a string
509
// like "iso8859-15" or "utf-8" (case insensitive).
510
// Returns true if the character table was recognized.
511
bool
SetSystemCharacterTable
(
const
char
*CharacterTable);
512
// Determines the character table used in the given buffer and returns
513
// a string indicating that table. If no table can be determined, the
514
// default ISO6937 is returned. If a table can be determined, the buffer
515
// and length are adjusted accordingly.
516
const
char
*
getCharacterTable
(
const
unsigned
char
*&buffer,
int
&length,
bool
*isSingleByte = NULL);
517
bool
convertCharacterTable
(
const
char
*from,
size_t
fromLength,
char
*to,
size_t
toLength,
const
char
*fromCode);
518
bool
systemCharacterTableIsSingleByte
(
void
);
519
520
}
//end of namespace
521
522
#endif //LIBSI_SI_H
523
Generated by
1.8.3.1