vdr 2.6.1
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 4.3 2020/05/15 12:32:51 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
21namespace SI {
22
23enum 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
31 TableIdBAT = 0x4A, //bouquet association section
32 TableIdEIT_presentFollowing = 0x4E, //event information section
34 //range from 0x50 to 0x5F
37 //range from 0x60 to 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
52 // defined by ISO/IEC 13818-1
70 // defined by ISO-13818-6 (DSM-CC)
72 // 0x14 - 0x3F Reserved
73 // defined by ISO/IEC 13818-1 Amendment
77 // defined by ETSI (EN 300 468)
129 // defined by ETSI (EN 300 468) v 1.7.1
141 // defined by EICTA/EACEM/DIGITALEUROPE
147 // Extension descriptors
160 // defined by ETSI (EN 300 468) v 1.12.1
163 // 0x0E - 0x0F Reserved
166
167 // Defined by ETSI TS 102 812 (MHP)
168 // They once again start with 0x00 (see page 234, MHP specification)
174 // 0x05 - 0x0A is unimplemented this library
187 // Premiere private Descriptor Tags
189
190 //a descriptor currently unimplemented in this library
191 //the actual value 0xFF is "forbidden" according to the spec.
194
196
202 };
203
215 };
216
221 };
222
223/* Some principles:
224 - Objects that return references to other objects contained in their data must make sure
225 that the returned objects have been parsed.
226 (the Loop subclasses take care of that.)
227 Note that this does not apply to Loops and Strings (their are never returned by reference, BTW).
228*/
229
230class Object : public Parsable {
231public:
232 Object();
233 Object(CharArray &d);
234 //can only be called once since data is immutable
235 void setData(const unsigned char*data, int size, bool doCopy=true);
236 CharArray getData() { return data; }
237 //returns the valid flag which indicates if data is all right or errors have been encountered
238 bool isValid() { return data.isValid(); }
239 virtual int getLength() = 0;
240protected:
242 //is protected - not used for sections
243 template <class T> friend class StructureLoop;
244 void setData(CharArray &d);
245 //returns whether the given offset fits within the limits of the actual data
246 //The valid flag will be set accordingly
247 bool checkSize(int offset);
248};
249
250class Section : public Object {
251public:
252 //convenience: sets data and parses if doParse
253 Section(const unsigned char *data, bool doCopy=true);
255 TableId getTableId() const;
256 virtual int getLength();
257
258 static int getLength(const unsigned char *d);
259 static TableId getTableId(const unsigned char *d);
260};
261
262class CRCSection : public Section {
263public:
264 //convenience: sets data and parses if doParse
265 CRCSection(const unsigned char *data, bool doCopy=true) : Section(data, doCopy) {}
267 bool isCRCValid();
268 //convenience: isValid+CheckParse
269 bool CheckCRCAndParse();
270};
271
272/* A section which has the ExtendedSectionHeader
273 (section_syntax_indicator==1) */
275public:
276 NumberedSection(const unsigned char *data, bool doCopy=true) : CRCSection(data, doCopy) {}
278 int getTableIdExtension() const;
279 bool getCurrentNextIndicator() const;
280 int getVersionNumber() const;
281 int getSectionNumber() const;
282 int getLastSectionNumber() const;
283 bool moreThanOneSection() const { return getLastSectionNumber()>0; }
284
285 static int getTableIdExtension(const unsigned char *d);
286};
287
289public:
290 //never forget to call this
291 void setData(CharArray d, int l) { Object::setData(d); checkSize(l); length=l; }
292 //convenience method
293 void setDataAndOffset(CharArray d, int l, int &offset) { Object::setData(d); checkSize(l); length=l; offset+=l; }
294 virtual int getLength() { return length; }
295private:
297};
298
299class LoopElement : public Object {
300};
301
302class Descriptor : public LoopElement {
303public:
304 virtual int getLength();
306
307 static int getLength(const unsigned char *d);
308 static DescriptorTag getDescriptorTag(const unsigned char *d);
309protected:
310 friend class DescriptorLoop;
311 //returns a subclass of descriptor according to the data given.
312 //The object is allocated with new and must be delete'd.
313 //setData() will have been called, CheckParse() not.
314 //if returnUnimplemetedDescriptor==true:
315 // Never returns null - maybe the UnimplementedDescriptor.
316 //if returnUnimplemetedDescriptor==false:
317 // Never returns the UnimplementedDescriptor - maybe null
318 static Descriptor *getDescriptor(CharArray d, DescriptorTagDomain domain, bool returnUnimplemetedDescriptor);
319};
320
321class Loop : public VariableLengthPart {
322public:
323 class Iterator {
324 public:
325 Iterator() { i=0; }
326 void reset() { i=0; }
327 private:
328 template <class T> friend class StructureLoop;
329 friend class DescriptorLoop;
330 template <class T> friend class TypeLoop;
332 int i;
333 };
334protected:
335 virtual void Parse() {}
336};
337
338//contains LoopElements of one type only
339template <class T> class StructureLoop : public Loop {
340public:
341 //currently you must use a while-loop testing for hasNext()
342 //i must be 0 to get the first descriptor (with the first call)
343 bool getNext(T &obj, Iterator &it)
344 {
345 if (!isValid() || it.i >= getLength())
346 return false;
347 CharArray d=data;
348 d.addOffset(it.i);
349 T ret;
350 ret.setData(d);
351 ret.CheckParse();
352 if (!checkSize(ret.getLength()))
353 return false;
354 it.i+=ret.getLength();
355 obj=ret;
356 return true;
357 }
359 {
360 if (!isValid() || it.i >= getLength())
361 return 0;
362 CharArray d=data;
363 d.addOffset(it.i);
364 T *ret=new T();
365 ret->setData(d);
366 ret->CheckParse();
367 if (!checkSize(ret->getLength())) {
368 delete ret;
369 return 0;
370 }
371 it.i+=ret->getLength();
372 return ret;
373 }
374 //bool hasNext(Iterator &it) { return getLength() > it.i; }
375};
376
377//contains descriptors of different types
378class DescriptorLoop : public Loop {
379public:
381 //i must be 0 to get the first descriptor (with the first call)
382 //All returned descriptors must be delete'd.
383 //returns null if no more descriptors available
384 Descriptor *getNext(Iterator &it);
385 //return the next descriptor with given tag, or 0 if not available.
386 //if returnUnimplemetedDescriptor==true:
387 // an UnimplementedDescriptor may be returned if the next matching descriptor is unimplemented,
388 // 0 will be returned if and only if no matching descriptor is found.
389 //if returnUnimplemetedDescriptor==false:
390 // if 0 is returned, either no descriptor with the given tag was found,
391 // or descriptors were found, but the descriptor type is not implemented
392 //In either case, a return value of 0 indicates that no further calls to this method
393 //with the iterator shall be made.
394 Descriptor *getNext(Iterator &it, DescriptorTag tag, bool returnUnimplemetedDescriptor=false);
395 //return the next descriptor with one of the given tags, or 0 if not available.
396 //if returnUnimplemetedDescriptor==true:
397 // returns 0 if and only if no descriptor with one of the given tags was found.
398 // The UnimplementedDescriptor may be returned.
399 //if returnUnimplemetedDescriptor==false:
400 // if 0 is returned, either no descriptor with one of the given tags was found,
401 // or descriptors were found, but none of them are implemented.
402 // The UnimplementedDescriptor will never be returned.
403 //In either case, a return value of 0 indicates that no further calls to this method
404 //with the iterator shall be made.
405 Descriptor *getNext(Iterator &it, DescriptorTag *tags, int arrayLength, bool returnUnimplemetedDescriptor=false);
406 //returns the number of descriptors in this loop
408 //writes the tags of the descriptors in this loop in the array,
409 // which must at least have the size getNumberOfDescriptors().
410 //The number of descriptors, i.e. getNumberOfDescriptors(), is returned.
411 // You can specify the array type (Descriptor tags are 8 Bit,
412 // you might e.g. choose a char, short, int or DescriptorTag array)
413 template <typename T> int getDescriptorTags(T *tags)
414 {
415 const unsigned char *p=data.getData();
416 const unsigned char *end=p+getLength();
417 int count=0;
418 while (p < end) {
419 tags[count++]=(T)Descriptor::getDescriptorTag(p);
421 }
422 return count;
423 }
424protected:
425 Descriptor *createDescriptor(int &i, bool returnUnimplemetedDescriptor);
427};
428
429typedef uint8_t EightBit;
430typedef uint16_t SixteenBit;
431typedef uint32_t ThirtyTwoBit;
432typedef uint64_t SixtyFourBit;
433
434template <typename T> class TypeLoop : public Loop {
435public:
436 int getCount() { return getLength()/sizeof(T); }
437 T operator[](const int index) const
438 {
439 switch (sizeof(T)) {
440 case 1:
441 return data[index];
442 case 2:
443 return data.TwoBytes(index);
444 case 4:
445 return data.FourBytes(index);
446 case 8:
447 return (SixtyFourBit(data.FourBytes(index)) << 32) | data.FourBytes(index+4);
448 default:
449 return 0; // just to avoid a compiler warning
450 }
451 return 0; // just to avoid a compiler warning
452 }
453 T getNext(Iterator &it) const
454 {
455 T ret=operator[](it.i);
456 it.i+=sizeof(T);
457 return ret;
458 }
459 bool hasNext(Iterator &it) { return isValid() && (getLength() > it.i); }
460};
461
463public:
465};
466
467//Premiere Content Information Table
469public:
471};
472
473//The content of the ExtendedEventDescriptor may be split over several
474//descriptors if the text is longer than 256 bytes.
475//The following classes provide base functionality to handle this case.
477public:
478 virtual int getDescriptorNumber() = 0;
479 virtual int getLastDescriptorNumber() = 0;
480};
481
483public:
486 bool Add(GroupDescriptor *d);
487 void Delete();
488 int getLength() { return length; }
490 bool isComplete(); //if all descriptors have been added
491protected:
495};
496
498public:
499 //A note to the length: getLength() returns the length of the raw data.
500 //The text may be shorter. Its length can be obtained with one of the
501 //getText functions and strlen.
502
503 //returns text. Data is allocated with new and must be delete'd by the user.
504 char *getText();
505 //copies text into given buffer.
506 //a buffer of size getLength()+1 is guaranteed to be sufficiently large.
507 //In most descriptors the string length is an 8-bit field,
508 //so the maximum there is 256.
509 //returns the given buffer for convenience.
510 //The emphasis marks 0x86 and 0x87 are still available.
511 //If fromCode is given, the string will be copied into buffer in its raw form,
512 //without conversion, and he code table of the string is returned in this variable
513 //if it is NULL.
514 char *getText(char *buffer, int size, const char **fromCode = NULL);
515 //The same semantics as for getText(char*) apply.
516 //The short version of the text according to ETSI TR 101 211 (chapter 4.6)
517 //will be written into the shortVersion buffer (which should, therefore, have the same
518 //length as buffer). If no shortVersion is available, shortVersion will contain
519 //an empty string.
520 //The emphasis marks 0x86 and 0x87 are still available in buffer, but not in shortVersion.
521 char *getText(char *buffer, char *shortVersion, int sizeBuffer, int sizeShortVersion);
522protected:
523 virtual void Parse() {}
524 void decodeText(char *buffer, int size, const char **fromCode = NULL);
525 void decodeText(char *buffer, char *shortVersion, int sizeBuffer, int sizeShortVersion);
526};
527
528// Set the character table to use for strings that do not begin with a character
529// table indicator. Call with NULL to turn this off.
530// Must be called *after* SetSystemCharacterTable()!
531// Returns true if the character table was recognized.
532bool SetOverrideCharacterTable(const char *CharacterTable);
533// Call this function to set the system character table. CharacterTable is a string
534// like "iso8859-15" or "utf-8" (case insensitive).
535// Returns true if the character table was recognized.
536bool SetSystemCharacterTable(const char *CharacterTable);
537// Determines the character table used in the given buffer and returns
538// a string indicating that table. If no table can be determined, the
539// default ISO6937 is returned. If a table can be determined, the buffer
540// and length are adjusted accordingly.
541// The isSingleByte parameter is deprecated and only present for backwards compatibility.
542const char *getCharacterTable(const unsigned char *&buffer, int &length, bool *isSingleByte = NULL);
543// Copies 'from' to 'to' and converts characters according to 'fromCode', if given.
544// Returns the length of the resulting string.
545size_t convertCharacterTable(const char *from, size_t fromLength, char *to, size_t toLength, const char *fromCode);
547
548} //end of namespace
549
550#endif //LIBSI_SI_H
bool CheckCRCAndParse()
Definition: si.c:65
CRCSection(const unsigned char *data, bool doCopy=true)
bool isCRCValid()
Definition: si.c:61
u_int32_t FourBytes(const int index) const
const unsigned char * getData() const
void addOffset(int offset)
u_int16_t TwoBytes(const int index) const
bool isValid() const
void Delete()
Definition: si.c:193
GroupDescriptor ** getDescriptors()
bool isComplete()
Definition: si.c:215
bool Add(GroupDescriptor *d)
Definition: si.c:201
DescriptorGroup(bool deleteOnDesctruction=true)
Definition: si.c:181
~DescriptorGroup()
Definition: si.c:187
GroupDescriptor ** array
int getNumberOfDescriptors()
Definition: si.c:170
int getDescriptorTags(T *tags)
DescriptorTagDomain domain
Descriptor * getNext(Iterator &it)
Definition: si.c:112
Descriptor * createDescriptor(int &i, bool returnUnimplemetedDescriptor)
Definition: si.c:159
DescriptorTag getDescriptorTag() const
Definition: si.c:100
virtual int getLength()
Definition: si.c:96
static Descriptor * getDescriptor(CharArray d, DescriptorTagDomain domain, bool returnUnimplemetedDescriptor)
Definition: si.c:530
virtual int getLastDescriptorNumber()=0
virtual int getDescriptorNumber()=0
virtual void Parse()
NumberedSection(const unsigned char *data, bool doCopy=true)
int getTableIdExtension() const
Definition: si.c:72
bool getCurrentNextIndicator() const
Definition: si.c:80
int getSectionNumber() const
Definition: si.c:88
int getLastSectionNumber() const
Definition: si.c:92
bool moreThanOneSection() const
int getVersionNumber() const
Definition: si.c:84
void setData(const unsigned char *data, int size, bool doCopy=true)
Definition: si.c:29
virtual int getLength()=0
CharArray getData()
Object()
Definition: si.c:23
bool checkSize(int offset)
Definition: si.c:37
CharArray data
virtual int getLength()
Definition: si.c:49
TableId getTableId() const
Definition: si.c:45
void decodeText(char *buffer, int size, const char **fromCode=NULL)
Definition: si.c:475
virtual void Parse()
char * getText()
Definition: si.c:222
bool getNext(T &obj, Iterator &it)
T * getNextAsPointer(Iterator &it)
T getNext(Iterator &it) const
bool hasNext(Iterator &it)
T operator[](const int index) const
void setDataAndOffset(CharArray d, int l, int &offset)
void setData(CharArray d, int l)
bool SetSystemCharacterTable(const char *CharacterTable)
Definition: si.c:339
@ RunningStatusStartsInAFewSeconds
@ RunningStatusNotRunning
@ RunningStatusPausing
@ RunningStatusRunning
@ RunningStatusUndefined
@ AudioTypeUndefined
@ AudioTypeHearingImpaired
@ AudioTypeCleanEffects
@ AudioTypeVisualImpairedCommentary
size_t convertCharacterTable(const char *from, size_t fromLength, char *to, size_t toLength, const char *fromCode)
Definition: si.c:414
uint32_t ThirtyTwoBit
uint64_t SixtyFourBit
uint16_t SixteenBit
@ TableIdTOT
@ TableIdRST
@ TableIdNIT
@ TableIdCAT
@ TableIdTDT
@ TableIdPremiereCIT
@ TableIdBAT
@ TableIdEIT_schedule_Other_last
@ TableIdEIT_schedule_Other_first
@ TableIdPAT
@ TableIdEIT_schedule_first
@ TableIdAIT
@ TableIdSIT
@ TableIdEIT_presentFollowing
@ TableIdSDT
@ TableIdDIT
@ TableIdEIT_schedule_last
@ TableIdSDT_other
@ TableIdPMT
@ TableIdST
@ TableIdNIT_other
@ TableIdTSDT
@ TableIdEIT_presentFollowing_other
DescriptorTagDomain
const char * getCharacterTable(const unsigned char *&buffer, int &length, bool *isSingleByte=NULL)
Definition: si.c:364
bool systemCharacterTableIsSingleByte(void)
Definition: si.c:317
@ MHP_DVBJApplicationDescriptorTag
@ MHP_ApplicationStorageDescriptorTag
@ MultiplexBufferUtilizationDescriptorTag
@ PreferredNameIdentifierDescriptorTag
@ TargetBackgroundGridDescriptorTag
@ TeletextDescriptorTag
@ DTSDescriptorTag
@ PreferredNameListDescriptorTag
@ CountryAvailabilityDescriptorTag
@ SupplementaryAudioDescriptorTag
@ CellListDescriptorTag
@ ContentDescriptorTag
@ IBPDescriptorTag
@ MaximumBitrateDescriptorTag
@ NetworkNameDescriptorTag
@ NVODReferenceDescriptorTag
@ MHP_SimpleApplicationBoundaryDescriptorTag
@ ShortEventDescriptorTag
@ MultilingualComponentDescriptorTag
@ CaDescriptorTag
@ CopyrightDescriptorTag
@ MHP_DVBHTMLApplicationLocationDescriptorTag
@ MHP_IPv4RoutingDescriptorTag
@ DataStreamAlignmentDescriptorTag
@ TimeShiftedEventDescriptorTag
@ AdaptationFieldDataDescriptorTag
@ ServiceListDescriptorTag
@ ImageIconDescriptorTag
@ DataBroadcastIdDescriptorTag
@ ComponentDescriptorTag
@ TransportStreamDescriptorTag
@ CableDeliverySystemDescriptorTag
@ ServiceIdentifierDescriptorTag
@ T2MIDescriptorTag
@ LinkageDescriptorTag
@ PremiereContentTransmissionDescriptorTag
@ CPIdentifierDescriptorTag
@ ServiceAvailabilityDescriptorTag
@ DataBroadcastDescriptorTag
@ MVCExtensionDescriptorTag
@ StuffingDescriptorTag
@ EacemStreamIdentifierDescriptorTag
@ TVAIdDescriptorTag
@ VideoStreamDescriptorTag
@ MultilingualNetworkNameDescriptorTag
@ TimeSliceFecIdentifierDescriptorTag
@ MHP_DVBHTMLApplicationDescriptorTag
@ SubtitlingDescriptorTag
@ VBITeletextDescriptorTag
@ SVCExtensionDescriptorTag
@ ExtensionDescriptorTag
@ ApplicationSignallingDescriptorTag
@ RegistrationDescriptorTag
@ LocalTimeOffsetDescriptorTag
@ MHP_ApplicationIconsDescriptorTag
@ MHP_ApplicationDescriptorTag
@ UnimplementedDescriptorTag
@ TerrestrialDeliverySystemDescriptorTag
@ ServiceMoveDescriptorTag
@ MHP_PrefetchDescriptorTag
@ AACDescriptorTag
@ MultilingualServiceNameDescriptorTag
@ BouquetNameDescriptorTag
@ HdSimulcastLogicalChannelDescriptorTag
@ S2SatelliteDeliverySystemDescriptorTag
@ PDCDescriptorTag
@ MHP_DVBHTMLApplicationBoundaryDescriptorTag
@ XAITPidDescriptorTag
@ DSNGDescriptorTag
@ C2DeliverySystemDescriptorTag
@ PartialTransportStreamDescriptorTag
@ CarouselIdentifierDescriptorTag
@ ExtendedEventDescriptorTag
@ CpcmDeliverySignallingDescriptor
@ ContentIdentifierDescriptorTag
@ MHP_DelegatedApplicationDescriptorTag
@ ScramblingDescriptorTag
@ AnnouncementSupportDescriptorTag
@ MHP_ApplicationNameDescriptorTag
@ HierarchyDescriptorTag
@ AVCDescriptorTag
@ MHP_SimpleApplicationLocationDescriptorTag
@ ISO639LanguageDescriptorTag
@ SystemClockDescriptorTag
@ FrequencyListDescriptorTag
@ VideoWindowDescriptorTag
@ CaIdentifierDescriptorTag
@ MHP_TransportProtocolDescriptorTag
@ SHDeliverySystemDescriptorTag
@ ECMRepetitionRateDescriptorTag
@ TimeShiftedServiceDescriptorTag
@ ShortSmoothingBufferDescriptorTag
@ PrivateDataIndicatorDescriptorTag
@ VBIDataDescriptorTag
@ AncillaryDataDescriptorTag
@ ParentalRatingDescriptorTag
@ DefaultAuthorityDescriptorTag
@ MessageDescriptorTag
@ MHP_ExternalApplicationAuthorisationDescriptorTag
@ CellFrequencyLinkDescriptorTag
@ TargetRegionDescriptorTag
@ LogicalChannelDescriptorTag
@ CPDescriptorTag
@ TelephoneDescriptorTag
@ MocaicDescriptorTag
@ SmoothingBufferDescriptorTag
@ STDDescriptorTag
@ RelatedContentDescriptorTag
@ ServiceRelocatedDescriptorTag
@ VideoDepthRangeDescriptorTag
@ T2DeliverySystemDescriptorTag
@ PrivateDataSpecifierDescriptorTag
@ AudioStreamDescriptorTag
@ TargetRegionNameDescriptorTag
@ NetworkChangeNotifyDescriptorTag
@ StreamIdentifierDescriptorTag
@ MHP_DVBJApplicationLocationDescriptorTag
@ MHP_IPv6RoutingDescriptorTag
@ ServiceDescriptorTag
@ MultilingualBouquetNameDescriptorTag
@ EnhancedAC3DescriptorTag
@ SatelliteDeliverySystemDescriptorTag
@ AC3DescriptorTag
@ LinkageTypeCaReplacementService
@ LinkageTypeRCSMap
@ LinkageTypeInformationService
@ LinkageTypePremiere
@ LinkageTypeTSContainingSsuBatOrNit
@ LinkageTypeSystemSoftwareUpdateService
@ LinkageTypeEPGService
@ LinkageTypeMobileHandover
@ LinkageTypeTSContainingCompleteNetworkBouquetSi
@ LinkageTypeDataBroadcastService
@ LinkageTypeServiceReplacementService
uint8_t EightBit
bool SetOverrideCharacterTable(const char *CharacterTable)
Definition: si.c:324