MythTV  0.26-pre
dvbdescriptors.h
Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 // Copyright (c) 2003-2004, Daniel Thor Kristjansson
00003 #ifndef _DVB_DESCRIPTORS_H_
00004 #define _DVB_DESCRIPTORS_H_
00005 
00006 #include <QMutex>
00007 #include <QString>
00008 
00009 #include "mythtvexp.h" // MTV_PUBLIC - Symbol Visibility
00010 #include "mpegdescriptors.h"
00011 #include "programinfo.h" // for subtitle types and audio and video properties
00012 
00013 /*
00014 // needed for scanning
00015         conditional_access          = 0x09, // maybe
00016         satellite_delivery_system   = 0x43,*
00017         cable_delivery_system       = 0x44,*
00018         service                     = 0x48,*
00019         terrestrial_delivery_system = 0x5A,*
00020         frequency_list              = 0x62,*
00021 
00022 // needed for captions
00023         teletext                    = 0x56,
00024         subtitling                  = 0x59,
00025 
00026 // needed for sound
00027         registration                = 0x05,
00028         AC3                         = 0x6A,
00029 
00030 // needed for eit
00031         short_event                 = 0x4D,
00032         extended_event              = 0x4E,
00033         content                     = 0x54,
00034 */
00035 
00036 static QString coderate_inner(uint coderate);
00037 
00038 extern QString dvb_decode_text(const unsigned char *src, uint length,
00039                                const unsigned char *encoding_override,
00040                                uint encoding_override_length);
00041 
00042 inline QString dvb_decode_text(const unsigned char *src, uint length)
00043 {
00044     return dvb_decode_text(src, length, NULL, 0);
00045 }
00046 
00047 QString dvb_decode_short_name(const unsigned char *src, uint raw_length);
00048 
00049 #define byteBCDH2int(i) (i >> 4)
00050 #define byteBCDL2int(i) (i & 0x0f)
00051 #define byteBCD2int(i) (byteBCDH2int(i) * 10 + byteBCDL2int(i))
00052 #define byte2BCD2int(i, j) \
00053   (byteBCDH2int(i) * 1000     + byteBCDL2int(i) * 100       + \
00054    byteBCDH2int(j) * 10       + byteBCDL2int(j))
00055 #define byte3BCD2int(i, j, k) \
00056   (byteBCDH2int(i) * 100000   + byteBCDL2int(i) * 10000     + \
00057    byteBCDH2int(j) * 1000     + byteBCDL2int(j) * 100       + \
00058    byteBCDH2int(k) * 10       + byteBCDL2int(k))
00059 #define byte4BCD2int(i, j, k, l) \
00060   (byteBCDH2int(i) * 10000000LL + byteBCDL2int(i) * 1000000 + \
00061    byteBCDH2int(j) * 100000     + byteBCDL2int(j) * 10000   + \
00062    byteBCDH2int(k) * 1000       + byteBCDL2int(k) * 100     + \
00063    byteBCDH2int(l) * 10         + byteBCDL2int(l))
00064 
00065 // DVB Bluebook A038 (Sept 2011) p 77
00066 class NetworkNameDescriptor : public MPEGDescriptor
00067 {
00068   public:
00069     NetworkNameDescriptor(const unsigned char *data, int len = 300) :
00070         MPEGDescriptor(data, len, DescriptorID::network_name) { }
00071     //       Name             bits  loc  expected value
00072     // descriptor_tag           8   0.0       0x40
00073     // descriptor_length        8   1.0
00074     // for (i=0;i<N;i++){ char 8 uimsbf }
00075     QString Name(void) const
00076         { return dvb_decode_text(_data+2, DescriptorLength()); }
00077     QString ShortName(void) const
00078         { return dvb_decode_short_name(_data+2, DescriptorLength()); }
00079     QString toString(void) const
00080         { return QString("NetworkNameDescriptor: ")+Name(); }
00081 };
00082 
00083 // DVB Bluebook A038 (Sept 2011) p 63
00084 class LinkageDescriptor : public MPEGDescriptor
00085 {
00086   public:
00087     LinkageDescriptor(const unsigned char *data, int len = 300) :
00088         MPEGDescriptor(data, len, DescriptorID::linkage)
00089     {
00090         if (!_data)
00091             return;
00092         if (DescriptorLength() < 7)
00093         {
00094             _data = NULL;
00095         }
00096         else if (kMobileHandOver == LinkageType())
00097         {
00098             uint end = 8;
00099             if (DescriptorLength() < end)
00100             {
00101                 _data = NULL;
00102                 return;
00103             }
00104             end += (HasMobileNetworkID()) ? 2 : 0;
00105             end += (HasMobileInitialServiceID()) ? 2 : 0;
00106             if (DescriptorLength() < end)
00107                 _data = NULL;
00108             m_offset = end + 2;
00109         }
00110         else if (kEventLinkage == LinkageType())
00111         {
00112             if (DescriptorLength() < 10)
00113                 _data = NULL;
00114             m_offset = 12;
00115         }
00116     }
00117     //       Name             bits  loc  expected value
00118     // descriptor_tag           8   0.0       0x4A
00119     // descriptor_length        8   1.0
00120     // transport_stream_id     16   2.0
00121     uint TSID(void)            const { return (_data[2]<<8) | _data[3]; }
00122     // original_network_id     16   4.0
00123     uint OriginalNetworkID()   const { return (_data[4]<<8) | _data[5]; }
00124     // service_id              16   6.0
00125     uint ServiceID(void)       const { return (_data[6]<<8) | _data[7]; }
00126     // linkage_type             8   8.0
00127     enum
00128     {
00129         kInformationService          = 0x01,
00130         kEPGService                  = 0x02,
00131         kCAReplacementService        = 0x03,
00132         kTSContainingCompleteNetworkBouquetSI = 0x04,
00133         kServiceReplacementService   = 0x05,
00134         kDataBroadcastService        = 0x06,
00135         kRCSMap                      = 0x07,
00136         kMobileHandOver              = 0x08,
00137         kSystemSoftwareUpdateService = 0x09,
00138         kTSContaining_SSU_BAT_NIT    = 0x0A,
00139         kIP_MACNotificationService   = 0x0B,
00140         kTSContaining_INT_BAT_NIT    = 0x0C,
00141         kEventLinkage                = 0x0D,
00142     };
00143     uint LinkageType(void)     const { return _data[8]; }
00144     QString LinkageTypeString(void) const;
00145 
00146     // if (linkage_type == 0x08)
00147     // {
00148     //    hand-over_type        4   9.0
00149     enum
00150     {
00151         kHandOverIdentical         = 0x01,
00152         kHandOverLocalVariation    = 0x02,
00153         kHandOverAssociatedService = 0x03,
00154     };
00155     uint MobileHandOverType(void) const { return _data[9]>>4; }
00156     QString MobileHandOverTypeString(void) const;
00157     //    reserved_future_use   3   9.4
00158     //    origin_type           1   9.7
00159     enum
00160     {
00161         kOriginNIT = 0x0,
00162         kOriginSDT = 0x1,
00163     };
00164     uint MobileOriginType(void) const { return _data[9]&0x1; }
00165     QString MobileOriginTypeString(void) const;
00166     //    if (hand-over_type == 0x01 || hand-over_type == 0x02 ||
00167     //        hand-over_type == 0x03)
00168     //    { network_id         16  10.0 }
00169     bool HasMobileNetworkID(void) const
00170         { return bool(MobileHandOverType() & 0x3); }
00171     uint MobileNetworkID(void) const { return (_data[10]<<8) | _data[11]; }
00172     //    if (origin_type ==0x00)
00173     //    { initial_service_id 16  HasNetworkID()?10.0:12.0 }
00174     bool HasMobileInitialServiceID(void) const
00175         { return kOriginNIT == MobileOriginType(); }
00176     uint MobileInitialServiceID(void) const
00177     {
00178         return HasMobileNetworkID() ?
00179             ((_data[12]<<8) | _data[13]) : ((_data[10]<<8) | _data[11]);
00180     }
00181     // }
00182     // if (linkage_type == 0x0D)
00183     // {
00184     //    target_event_id      16   9.0
00185     uint TargetEventID(void) const { return (_data[9]<<8) | _data[10]; }
00186     //    target_listed         1  11.0
00187     bool IsTargetListed(void) const { return _data[11]&0x80; }
00188     //    event_simulcast       1  11.1
00189     bool IsEventSimulcast(void) const { return _data[11]&0x40; }
00190     //    reserved              6  11.2
00191     // }
00192     //      for (i=0;i<N;i++)
00193     //        { private_data_byte 8 bslbf }
00194     const unsigned char *PrivateData(void) const
00195         { return _data + m_offset; }
00196     uint PrivateDataLength(void) const
00197         { return DescriptorLength() + 2 - m_offset; }
00198 
00199   private:
00200     uint m_offset;
00201 };
00202 
00203 // DVB Bluebook A038 (Sept 2011) p 38
00204 class AdaptationFieldDataDescriptor : public MPEGDescriptor
00205 {
00206   public:
00207     AdaptationFieldDataDescriptor(const unsigned char *data, int len = 300) :
00208         MPEGDescriptor(data, len, DescriptorID::adaptation_field_data, 1) { }
00209     //       Name             bits  loc  expected value
00210     // descriptor_tag           8   0.0       0x70
00211     // descriptor_length        8   1.0
00212     // adapt_field_data_id      8   2.0
00213     uint AdaptationFieldDataID(void) const { return _data[2]; }
00214     QString toString(void) const
00215     {
00216         return QString("AdaptationFieldDataDescriptor  "
00217                        "adaptation_field_data_identifier(%1)")
00218             .arg(AdaptationFieldDataID());
00219     }
00220 };
00221 
00222 // DVB Bluebook A038 (Sept 2011) p 38
00223 class AncillaryDataDescriptor : public MPEGDescriptor
00224 {
00225   public:
00226     AncillaryDataDescriptor(const unsigned char *data, int len = 300) :
00227         MPEGDescriptor(data, len, DescriptorID::ancillary_data, 1) { }
00228     //       Name             bits  loc  expected value
00229     // descriptor_tag           8   0.0       0x6b
00230     // descriptor_length        8   1.0
00231     // ancillary_data_id        8   2.0
00232     uint AncillaryDataID(void) const { return _data[2]; }
00233     QString toString(void) const
00234     {
00235         return QString("AncillaryDataDescriptor "
00236                        "ancillary_data_identifier(%1)")
00237             .arg(AncillaryDataID());
00238     }
00239 };
00240 
00241 // DVB Bluebook A038 (Sept 2011) p 39
00242 class AnnouncementSupportDescriptor : public MPEGDescriptor
00243 {
00244   public:
00245     AnnouncementSupportDescriptor(const unsigned char *data, int len = 300) :
00246         MPEGDescriptor(data, len, DescriptorID::announcement_support) { }
00247     //       Name             bits  loc  expected value
00248     // descriptor_tag           8   0.0       0x6e
00249     // descriptor_length        8   1.0
00250     // announcmnt_supprt_indic 16   2.0
00251     // for (i=0; i<N; i++)
00252     // {
00253     //   announcement_type      4   0.0+p
00254     //   reserved_future_use    1   0.4+p
00255     //   reference_type         3   0.5+p
00256     //   if (reference_type & 0x3)
00257     //   {
00258     //     original_network_id 16   0.0+p
00259     //     transport_stream_id 16   2.0+p
00260     //     service_id          16   4.0+p
00261     //     component_tag        8   6.0+p
00262     //   }                          7.0
00263     // }
00264 };
00265 
00266 // DVB Bluebook A038 (Sept 2011) p 41
00267 class BouquetNameDescriptor : public MPEGDescriptor
00268 {
00269   public:
00270     BouquetNameDescriptor(const unsigned char *data, int len = 300) :
00271         MPEGDescriptor(data, len, DescriptorID::bouquet_name) { }
00272     //       Name             bits  loc  expected value
00273     // descriptor_tag           8   0.0       0x47
00274     // descriptor_length        8   1.0
00275     // for(i=0;i<N;i++) { char 8 }
00276     QString BouquetName(void) const
00277          { return dvb_decode_text(_data+2, _data[1]); }
00278     QString BouquetShortName(void) const
00279          { return dvb_decode_short_name(_data+2, _data[1]); }
00280 
00281     QString toString(void) const
00282     {
00283         return QString("BouquetNameDescriptor: Bouquet Name(%1)")
00284             .arg(BouquetName());
00285     }
00286 };
00287 
00288 // DVB Bluebook A038 (Sept 2011) p 41
00289 class CAIdentifierDescriptor : public MPEGDescriptor
00290 {
00291   public:
00292     CAIdentifierDescriptor(const unsigned char *data, int len = 300) :
00293         MPEGDescriptor(data, len, DescriptorID::ca_identifier) { }
00294     //       Name             bits  loc  expected value
00295     // descriptor_tag           8   0.0       0x53
00296     // descriptor_length        8   1.0
00297     //
00298     uint CASystemCount(void) const { return DescriptorLength() >> 1; }
00299     // for (i=0; i<N; i++)
00300     //   { CA_system_id 16 }
00301     int CASystemId(uint i) const
00302         { return (_data[2 + i*2] << 8) | _data[3 + i*2]; }
00303     QString toString(void) const;
00304 };
00305 
00306 // DVB Bluebook A038 (Sept 2011) p 42
00307 class CellFrequencyLinkDescriptor : public MPEGDescriptor
00308 {
00309   public:
00310     CellFrequencyLinkDescriptor(const unsigned char *data, int len = 300) :
00311         MPEGDescriptor(data, len, DescriptorID::cell_frequency_link) { }
00312     //       Name             bits  loc  expected value
00313     // descriptor_tag           8   0.0       0x6d
00314     // descriptor_length        8   1.0
00315     // for (i=0; i<N; i++)
00316     // {
00317     //   cell_id               16   0.0+p
00318     //   frequency             32   2.0+p
00319     //   subcell_info_loop_len  8   6.0+p
00320     //   for (j=0;j<N;j++)
00321     //   {
00322     //     cell_id_extension    8   0.0+p2
00323     //     transposer_freq     32   1.0+p2
00324     //   }                          5.0
00325     // }
00326 };
00327 
00328 // DVB Bluebook A038 (Sept 2011) p 42
00329 class CellListDescriptor : public MPEGDescriptor
00330 {
00331   public:
00332     CellListDescriptor(const unsigned char *data, int len = 300) :
00333         MPEGDescriptor(data, len, DescriptorID::cell_list) { }
00334     //       Name             bits  loc  expected value
00335     // descriptor_tag           8   0.0       0x6c
00336     // descriptor_length        8   1.0
00337     // for (i=0; i<N; i++)
00338     // {
00339     //   cell_id               16  0.0+p
00340     //   cell_latitude         16  2.0+p
00341     //   cell_longitude        16  4.0+p
00342     //   cell_extent_of_lat    12  6.0+p
00343     //   cell_extent_of_longit 12  7.4+p
00344     //   subcell_info_loop_len  8  9.0+p
00345     //   for (j=0;j<N;j++)
00346     //   {
00347     //     cell_id_extension    8  0.0+p2
00348     //     subcell_latitude    16  1.0+p2
00349     //     subcell_longitude   16  3.0+p2
00350     //     subcell_ext_of_lat  12  4.0+p2
00351     //     subcell_ext_of_long 12  5.4+p2
00352     //   }                         7.0
00353     // }
00354 };
00355 
00356 // DVB Bluebook A038 (Sept 2011) p 44
00357 class ComponentDescriptor : public MPEGDescriptor
00358 {
00359   public:
00360     ComponentDescriptor(const unsigned char *data, int len = 300) :
00361         MPEGDescriptor(data, len, DescriptorID::component) { }
00362     //       Name             bits  loc  expected value
00363     // descriptor_tag           8   0.0       0x50
00364     // descriptor_length        8   1.0
00365     // reserved_future_use      4   2.0
00366     // stream_content           4   2.4
00367     uint StreamContent(void) const { return _data[2] & 0xf; }
00368     // component_type           8   3.0
00369     uint ComponentType(void) const { return _data[3]; }
00370     // component_tag            8   4.0
00371     uint ComponentTag(void)  const { return _data[4]; }
00372     // ISO_639_language_code   24   5.0
00373     int LanguageKey(void) const
00374         { return iso639_str3_to_key(&_data[5]); }
00375     QString LanguageString(void) const
00376         { return iso639_key_to_str3(LanguageKey()); }
00377     int CanonicalLanguageKey(void) const
00378         { return iso639_key_to_canonical_key(LanguageKey()); }
00379     QString CanonicalLanguageString(void) const
00380         { return iso639_key_to_str3(CanonicalLanguageKey()); }
00381     //
00382     // for (i=0; i<N; i++) { text_char 8 }
00383 
00384     bool IsVideo(void) const
00385     {
00386         return 0x1 == StreamContent() ||
00387                0x5 == StreamContent();
00388     }
00389     bool IsAudio(void) const
00390     {
00391         switch(StreamContent())
00392         {
00393             case 0x02:
00394             case 0x04:
00395             case 0x06:
00396             case 0x07:
00397                 return true;
00398             default:
00399                 return false;
00400         }
00401     }
00402     bool IsSubtitle(void) const { return 0x3 == StreamContent(); }
00403 
00404     unsigned char VideoProperties(void) const
00405     {
00406         if (0x1 == StreamContent())
00407             return MPEG2Properties();
00408         if (0x5 == StreamContent())
00409             return VID_AVC | AVCProperties();
00410 
00411         return VID_UNKNOWN;
00412     }
00413 
00414     unsigned char MPEG2Properties(void) const
00415     {
00416         switch(ComponentType())
00417         {
00418             case 0x2: case 0x3: case 0x4:
00419             case 0x6: case 0x7: case 0x8:
00420                 return VID_WIDESCREEN;
00421             case 0x09:
00422             case 0x0D:
00423                 return VID_HDTV;
00424             case 0x0A: case 0x0B: case 0x0C:
00425             case 0x0E: case 0x0F: case 0x10:
00426                 return VID_WIDESCREEN | VID_HDTV;
00427             default:
00428                 return VID_UNKNOWN;
00429         }
00430     }
00431 
00432     unsigned char AVCProperties(void) const
00433     {
00434         switch(ComponentType())
00435         {
00436             case 0x3: case 0x4:
00437             case 0x7: case 0x8:
00438                 return VID_WIDESCREEN;
00439             case 0x0B: case 0x0C:
00440             case 0x0F: case 0x10:
00441                 return VID_WIDESCREEN | VID_HDTV;
00442             default:
00443                 return VID_UNKNOWN;
00444         }
00445     }
00446 
00447     unsigned char AudioProperties(void) const
00448     {
00449         switch (StreamContent())
00450         {
00451             case 0x2:
00452                 return MP2Properties();
00453             case 0x04:
00454                 return AC3Properties();
00455             case 0x06:
00456                 return HEAACProperties();
00457             default:
00458                 return AUD_UNKNOWN;
00459         }
00460     }
00461 
00462     unsigned char MP2Properties(void) const
00463     {
00464         switch (ComponentType())
00465         {
00466             case 0x1:
00467                 return AUD_MONO;
00468             case 0x3:
00469                 return AUD_STEREO;
00470             case 0x5:
00471                 return AUD_SURROUND;
00472             case 0x40:
00473                 return AUD_VISUALIMPAIR;
00474             case 0x41:
00475                 return AUD_HARDHEAR;
00476             default:
00477                 return AUD_UNKNOWN;
00478         }
00479     }
00480 
00481     unsigned char AC3Properties(void) const
00482     {
00483         unsigned char properties = AUD_UNKNOWN;
00484 
00485         switch (ComponentType() & 0x7)
00486         {
00487             case 0x0:
00488                 properties |= AUD_MONO;
00489                 break;
00490             case 0x2:
00491                 properties |= AUD_STEREO;
00492                 break;
00493             case 0x3:
00494                 properties |= AUD_DOLBY;
00495                 break;
00496             case 0x4: case 0x5:
00497                 properties |= AUD_SURROUND;
00498                 break;
00499         }
00500 
00501         if (((ComponentType() >> 3) & 0x7) == 0x2)
00502             properties |= AUD_VISUALIMPAIR;
00503 
00504         if (((ComponentType() >> 3) & 0x7) == 0x3)
00505             properties |= AUD_HARDHEAR;
00506 
00507         return properties;
00508     }
00509 
00510     unsigned char HEAACProperties(void) const
00511     {
00512         switch (ComponentType())
00513         {
00514             case 0x1:
00515                 return AUD_MONO;
00516             case 0x3:
00517             case 0x43:
00518                 return AUD_STEREO;
00519             case 0x5:
00520                 return AUD_SURROUND;
00521             case 0x40:
00522             case 0x44:
00523                 return AUD_VISUALIMPAIR;
00524             case 0x41:
00525             case 0x45:
00526                 return AUD_HARDHEAR;
00527             default:
00528                 return AUD_UNKNOWN;
00529         }
00530     }
00531 
00532     unsigned char SubtitleType(void) const
00533     {
00534         if (!IsSubtitle())
00535             return SUB_UNKNOWN;
00536 
00537         switch (ComponentType())
00538         {
00539             case 0x1:
00540             case 0x3:
00541             case 0x10: case 0x11: case 0x12: case 0x13:
00542                 return SUB_NORMAL;
00543             case 0x20: case 0x21: case 0x22: case 0x23:
00544                 return SUB_HARDHEAR;
00545             default:
00546                 return SUB_UNKNOWN;
00547         }
00548     }
00549 
00550     QString toString(void) const
00551     {
00552         return QString("ComponentDescriptor(stream_content: 0x%1, "
00553                        "component_type: 0x%2)").arg(StreamContent(), 0, 16)
00554             .arg(ComponentType(), 0, 16);
00555     }
00556 };
00557 
00558 typedef enum
00559 {
00560     kCategoryNone = 0,
00561     kCategoryMovie,
00562     kCategorySeries,
00563     kCategorySports,
00564     kCategoryTVShow,
00565     kCategoryLast,
00566 } MythCategoryType;
00567 
00568 MTV_PUBLIC QString myth_category_type_to_string(uint category_type);
00569 MTV_PUBLIC MythCategoryType string_to_myth_category_type(const QString &type);
00570 
00571 // DVB Bluebook A038 (Sept 2011) p 46
00572 class ContentDescriptor : public MPEGDescriptor
00573 {
00574   public:
00575     ContentDescriptor(const unsigned char *data, int len = 300) :
00576         MPEGDescriptor(data, len, DescriptorID::content) { }
00577     //       Name             bits  loc  expected value
00578     // descriptor_tag           8   0.0       0x54
00579     // descriptor_length        8   1.0
00580 
00581     uint Count(void)         const { return DescriptorLength() >> 1; }
00582     // for (i=0;i<N;i++)
00583     // {
00584     //   content_nibble_level_1 4   0.0+p
00585     uint Nibble1(uint i)     const { return _data[2 + (i<<1)] >> 4; }
00586     //   content_nibble_level_2 4   0.4+p
00587     uint Nibble2(uint i)     const { return _data[2 + (i<<1)] & 0xf; }
00588 
00589     uint Nibble(uint i)      const { return _data[2 + (i<<1)]; }
00590 
00591     //   user_nibble            4   1.0+p
00592     uint UserNibble1(uint i) const { return _data[3 + (i<<1)] >> 4; }
00593     //   user_nibble            4   1.4+p
00594     uint UserNibble2(uint i) const { return _data[3 + (i<<1)] & 0xf; }
00595     uint UserNibble(uint i)  const { return _data[3 + (i<<1)]; }
00596     // }                            2.0
00597 
00598     MythCategoryType GetMythCategory(uint i) const;
00599     QString GetDescription(uint i) const;
00600     QString toString(void) const;
00601 
00602   protected:
00603     static void Init(void);
00604 
00605   protected:
00606     static QMutex             categoryLock;
00607     static QMap<uint,QString> categoryDesc;
00608     static volatile bool      categoryDescExists;
00609 };
00610 
00611 // DVB Bluebook A038 (Sept 2011) p 49
00612 class CountryAvailabilityDescriptor : public MPEGDescriptor
00613 {
00614   public:
00615     CountryAvailabilityDescriptor(const unsigned char *data, int len = 300) :
00616         MPEGDescriptor(data, len, DescriptorID::country_availability) { }
00617     //       Name             bits  loc  expected value
00618     // descriptor_tag           8   0.0       0x49
00619     // descriptor_length        8   1.0
00620 
00621     uint CountryCount(void) const { return ((DescriptorLength() - 1) / 3); }
00622 
00623     // country_avail_flag       1   2.0
00624     bool IsAvailable(void) const { return (_data[2] & 0x1); }
00625     // reserved_future_use      7   2.1
00626     //
00627     // for (i=0; i<N; i++)
00628     //   { country_code        24 }
00629     QString CountryNames(void) const
00630     {
00631         QString countries="";
00632         for (uint i=0; i<CountryCount(); i++)
00633         {
00634             if (i!=0) countries.append(" ");
00635             countries.append(QString::fromAscii(
00636                                  (const char *)_data+(3*(i+1)), 3));
00637         };
00638         return countries;
00639     }
00640 
00641     QString toString(void) const
00642     {
00643         return QString("CountryAvailabilityDescriptor: Available(%1) in (%2)")
00644             .arg(IsAvailable()).arg(CountryNames());
00645     }
00646 };
00647 
00648 // DVB Bluebook A038 (Sept 2011) p 50
00649 class DataBroadcastDescriptor : public MPEGDescriptor
00650 {
00651   public:
00652     DataBroadcastDescriptor(const unsigned char *data, int len = 300) :
00653         MPEGDescriptor(data, len, DescriptorID::data_broadcast) { }
00654     //       Name             bits  loc  expected value
00655     // descriptor_tag           8   0.0       0x64
00656     // descriptor_length        8   1.0
00657 
00658     // data_broadcast_id       16   2.0
00659     uint DataBroadcastId(void) const { return _data[2] << 8 | _data[3]; }
00660     // component_tag            8   4.0
00661     uint DataComponentTag(void) const { return _data[4]; }
00662     // selector_length          8   5.0
00663     uint SelectorLength(void) const { return _data[5]; }
00664     // for (i=0; i<selector_length; i++)
00665     // {
00666     //   selector_byte          8
00667     const unsigned char *Selector(void) const { return _data + 6; }
00668     // }
00669     // ISO_639_language_code   24
00670     int LanguageKey(void) const
00671         { return iso639_str3_to_key(&_data[6 + SelectorLength()]); }
00672     QString LanguageString(void) const
00673         { return iso639_key_to_str3(LanguageKey()); }
00674     int CanonicalLanguageKey(void) const
00675         { return iso639_key_to_canonical_key(LanguageKey()); }
00676     QString CanonicalLanguageString(void) const
00677         { return iso639_key_to_str3(CanonicalLanguageKey()); }
00678     // text_length              8
00679     uint TextLength(void) const { return _data[6 + SelectorLength() + 3]; }
00680     // for (i=0; i<text_length; i++) { text_char 8 }
00681     QString Text(void) const
00682     {
00683         return dvb_decode_text(&_data[6 + SelectorLength() + 4], TextLength());
00684     }
00685 
00686     QString toString(void) const;
00687 };
00688 
00689 // DVB Bluebook A038 (Sept 2011) p 51
00690 class DataBroadcastIdDescriptor : public MPEGDescriptor
00691 {
00692   public:
00693     DataBroadcastIdDescriptor(const unsigned char *data, int len = 300) :
00694         MPEGDescriptor(data, len, DescriptorID::data_broadcast_id) { }
00695     //       Name             bits  loc  expected value
00696     // descriptor_tag           8   0.0       0x66
00697     // descriptor_length        8   1.0
00698 
00699     // data_broadcast_id       16   2.0
00700     uint DataBroadCastId(void) const { return _data[2] << 8 | _data[3]; }
00701     // for(i=0; i < N;i++ )
00702     // { id_selector_byte       8 }
00703 };
00704 
00705 // DVB Bluebook A038 (Sept 2011) p 51
00706 class CableDeliverySystemDescriptor : public MPEGDescriptor
00707 {
00708   public:
00709     CableDeliverySystemDescriptor(const unsigned char *data, int len = 300) :
00710         MPEGDescriptor(data, len, DescriptorID::cable_delivery_system) { }
00711     //       Name             bits  loc  expected value
00712     // descriptor_tag           8   0.0       0x44
00713     // descriptor_length        8   1.0
00714 
00715     // frequency               32   2.0
00716     uint FrequencyRaw(void) const
00717     {
00718         return ((_data[2]<<24) | (_data[3]<<16) |
00719                 (_data[4]<<8)  | (_data[5]));
00720     }
00721     unsigned long long FrequencyHz(void) const
00722     {
00723         return byte4BCD2int(_data[2], _data[3], _data[4], _data[5]) * 100;
00724     }
00725     // reserved_future_use     12   6.0
00726     // FEC_outer                4   7.4
00727     enum
00728     {
00729         kOuterFEC_None        = 0x1,
00730         kOuterFEC_RS204_RS188 = 0x2,
00731     };
00732     uint FECOuter(void) const { return _data[7] & 0xf; }
00733     QString FECOuterString(void) const
00734     {
00735         return (FECOuter() == kOuterFEC_None) ? "None" :
00736             ((FECOuter() == kOuterFEC_RS204_RS188) ? "RS(204/188)" : "unknown");
00737     }
00738     // modulation               8   8.0
00739     enum
00740     {
00741         kModulationQAM16  = 0x01,
00742         kModulationQAM32  = 0x02,
00743         kModulationQAM64  = 0x03,
00744         kModulationQAM128 = 0x04,
00745         kModulationQAM256 = 0x05,
00746     };
00747     uint Modulation(void) const { return _data[8]; }
00748     QString ModulationString(void) const
00749     {
00750         static QString ms[] =
00751             { "auto", "qam_16", "qam_32", "qam_64", "qam_128", "qam_256" };
00752         return (Modulation() <= kModulationQAM256) ?
00753             ms[Modulation()] : QString("auto");
00754     }
00755     // symbol_rate             28   9.0
00756     uint SymbolRateRaw(void) const
00757     {
00758         return ((_data[9]<<20) | (_data[10]<<12) |
00759                 (_data[11]<<4) | (_data[12]>>4));
00760     }
00761     uint SymbolRateHz(void) const
00762     {
00763         return ((byte3BCD2int(_data[9], _data[10], _data[11]) * 1000) +
00764                 (byteBCDH2int(_data[12]) * 100));
00765     }
00766     // FEC_inner                4  12.4
00767     enum
00768     {
00769         kInnerFEC_1_2_ConvolutionCodeRate = 0x1,
00770         kInnerFEC_2_3_ConvolutionCodeRate = 0x2,
00771         kInnerFEC_3_4_ConvolutionCodeRate = 0x3,
00772         kInnerFEC_5_6_ConvolutionCodeRate = 0x4,
00773         kInnerFEC_7_8_ConvolutionCodeRate = 0x5,
00774         kInnerFEC_8_9_ConvolutionCodeRate = 0x6,
00775         kInnerFEC_None                    = 0xF,
00776     };
00777     uint FECInner(void) const { return _data[12] & 0xf; }
00778     QString FECInnerString(void) const { return coderate_inner(FECInner()); }
00779     QString toString(void) const;
00780 };
00781 
00782 // DVB Bluebook A038 (Sept 2011) p 53
00783 class SatelliteDeliverySystemDescriptor : public MPEGDescriptor
00784 {
00785   public:
00786     SatelliteDeliverySystemDescriptor(
00787         const unsigned char *data, int len = 300) :
00788         MPEGDescriptor(data, len, DescriptorID::satellite_delivery_system) { }
00789     //       Name             bits  loc  expected value
00790     // descriptor_tag           8   0.0       0x43
00791     // descriptor_length        8   1.0
00792 
00794     uint FrequencyRaw(void) const
00795     {
00796         return ((_data[2]<<24) | (_data[3]<<16) |
00797                 (_data[4]<<8)  | (_data[5]));
00798     }
00799     unsigned long long FrequencyHz(void) const
00800     {
00801         return byte4BCD2int(_data[2], _data[3], _data[4], _data[5]) * 10;
00802     }
00804     uint OrbitalPosition(void) const
00805         { return byte2BCD2int(_data[6], _data[7]); }
00806     QString OrbitalPositionString(void) const
00807     {
00808         uint num = OrbitalPosition();
00809         return QString("%1.%2 %3").arg(num / 10).arg(num % 10)
00810             .arg((IsEast()) ? "East" : "West");
00811     }
00812     double OrbitalPositionFloat()  const
00813         { return ((double) OrbitalPosition()) / 10.0; }
00815     bool IsEast(void)             const { return (_data[8]&0x80); }
00816     bool IsWest(void)             const { return !IsEast(); }
00817     // polarization             2   8.1
00818     uint Polarization(void)       const { return (_data[8]>>5)&0x3; }
00819     QString PolarizationString()  const
00820     {
00821         static QString ps[] = { "h", "v", "l", "r" };
00822         return ps[Polarization()];
00823     }
00824     bool IsCircularPolarization(void) const { return (_data[8]>>6)&0x1; }
00825     bool IsLinearPolarization(void) const { return !((_data[8]>>6)&0x1); }
00826     bool IsHorizontalLeftPolarization(void) const { return (_data[8]>>5)&0x1; }
00827     bool IsVerticalRightPolarization(void) const
00828         { return !((_data[8]>>5)&0x1); }
00829     // roll off                 2   8.3
00830     enum
00831     {
00832         kRollOff_35,
00833         kRollOff_20,
00834         kRollOff_25,
00835         kRollOff_Auto,
00836     };
00837     uint RollOff(void) const { return (_data[8]>>3)&0x3; }
00838     QString RollOffString(void) const
00839     {
00840         static QString ro[] = { "0.35", "0.20", "0.25", "auto" };
00841         return ro[RollOff()];
00842     }
00843     // modulation system        1   8.5
00844     uint ModulationSystem(void) const { return (_data[8]>>2)&0x1; }
00845     QString ModulationSystemString(void) const
00846     {
00847         return ModulationSystem() ? "DVB-S2" : "DVB-S";
00848     }
00849     // modulation               2   8.6
00850     enum
00851     {
00852         kModulationQPSK_NS = 0x0, // Non standard QPSK for Bell ExpressVu
00853         // should be "auto" according to DVB SI standard
00854         kModulationQPSK   = 0x1,
00855         kModulation8PSK   = 0x2,
00856         kModulationQAM16  = 0x3,
00857     };
00858     uint Modulation(void) const { return _data[8]&0x03; }
00859     QString ModulationString(void) const
00860     {
00861         static QString ms[] = { "qpsk", "qpsk", "8psk", "qam_16" };
00862         return ms[Modulation()];
00863     }
00864     // symbol_rate             28   9.0
00865     uint SymbolRate(void) const
00866     {
00867         return ((_data[9]<<20) | (_data[10]<<12) |
00868                 (_data[11]<<4) | (_data[12]>>4));
00869     }
00870     uint SymbolRateHz(void) const
00871     {
00872         return ((byte3BCD2int(_data[9], _data[10], _data[11]) * 1000) +
00873                 (byteBCDH2int(_data[12]) * 100));
00874     }
00875     // FEC_inner                4  12.4
00876     enum
00877     {
00878         kInnerFEC_1_2_ConvolutionCodeRate = 0x1,
00879         kInnerFEC_2_3_ConvolutionCodeRate = 0x2,
00880         kInnerFEC_3_4_ConvolutionCodeRate = 0x3,
00881         kInnerFEC_5_6_ConvolutionCodeRate = 0x4,
00882         kInnerFEC_7_8_ConvolutionCodeRate = 0x5,
00883         kInnerFEC_8_9_ConvolutionCodeRate = 0x6,
00884         kInnerFEC_None                    = 0xF,
00885     };
00886     uint FECInner(void) const { return _data[12] & 0xf; }
00887     QString FECInnerString(void) const { return coderate_inner(FECInner()); }
00888 
00889     QString toString(void) const;
00890 };
00891 
00892 // DVB Bluebook A038 (Sept 2011) p 55
00893 class TerrestrialDeliverySystemDescriptor : public MPEGDescriptor
00894 {
00895   public:
00896     TerrestrialDeliverySystemDescriptor(
00897         const unsigned char *data, int len = 300) :
00898         MPEGDescriptor(data, len, DescriptorID::terrestrial_delivery_system) { }
00899     //       Name             bits  loc  expected value
00900     // descriptor_tag           8   0.0       0x5a
00901     // descriptor_length        8   1.0
00902 
00903     // centre_frequency        32   2.0
00904     uint Frequency(void) const
00905     {
00906         return ((_data[2]<<24) | (_data[3]<<16) |
00907                 (_data[4]<<8)  | (_data[5]));
00908     }
00909     uint64_t FrequencyHz(void) const { return uint64_t(Frequency()) * 10ULL; }
00910 
00911     // bandwidth                3   6.0
00912     enum
00913     {
00914         kBandwidth8Mhz = 0x0,
00915         kBandwidth7Mhz = 0x1,
00916         kBandwidth6Mhz = 0x2,
00917         kBandwidth5Mhz = 0x3,
00918     };
00919     uint Bandwidth(void) const { return _data[6]>>5; }
00920     uint BandwidthHz(void) const { return (8 - Bandwidth()) * 1000000; }
00921     QString BandwidthString(void) const
00922     {
00923         static QString bs[] = { "8", "7", "6", "5" };
00924         return (Bandwidth() <= kBandwidth5Mhz) ? bs[Bandwidth()] : "auto";
00925     }
00926     // priority                 1   6.3
00927     bool HighPriority(void) const { return _data[6] & 0x10; }
00928     // time_slicing_indicator   1   6.4
00929     bool IsTimeSlicingIndicatorUsed(void) const { return !(_data[6] & 0x08); }
00930     // MPE-FEC_indicator        1   6.5
00931     bool IsMPE_FECUsed(void) const { return !(_data[6] & 0x04); }
00932     // reserved_future_use      2   6.6
00933     // constellation            2   7.0
00934     enum
00935     {
00936         kConstellationQPSK  = 0x0,
00937         kConstellationQAM16 = 0x1,
00938         kConstellationQAM64 = 0x2,
00939     };
00940     uint Constellation(void) const { return _data[7]>>6; }
00941     QString ConstellationString(void) const
00942     {
00943         static QString cs[] = { "qpsk", "qam_16", "qam_64" };
00944         return (Constellation() <= kConstellationQAM64) ?
00945             cs[Constellation()] : "auto";
00946     }
00947     // hierarchy_information    3   7.2
00948     enum
00949     {
00950         kHierarchyInfoNonHierarchicalNativeInterleaver  = 0x0,
00951         kHierarchyInfoAlpha1NativeInterleaver           = 0x1,
00952         kHierarchyInfoAlpha2NativeInterleaver           = 0x2,
00953         kHierarchyInfoAlpha4NativeInterleaver           = 0x3,
00954         kHierarchyInfoNonHierarchicalInDepthInterleaver = 0x4,
00955         kHierarchyInfoAlpha1InDepthInterleaver          = 0x5,
00956         kHierarchyInfoAlpha2InDepthInterleaver          = 0x6,
00957         kHierarchyInfoAlpha4InDepthInterleaver          = 0x7,
00958     };
00959     uint Hierarchy(void) const { return (_data[7]>>3) & 0x7; }
00960 
00962     QString HierarchyString(void) const
00963     {
00964         static QString hs[] = { "n", "1", "2", "4", "a", "a", "a", "a" };
00965         return hs[Hierarchy()];
00966     }
00967     bool NativeInterleaver(void) const { return _data[7] & 0x20; }
00968     uint Alpha(void) const
00969     {
00970         uint i = (_data[7]>>3) & 0x3;
00971         return (0x2 == i) ? 4 : i;
00972     }
00973     // code_rate-HP_stream      3   7.5
00974     enum
00975     {
00976         kCodeRate_1_2 = 0x0,
00977         kCodeRate_2_3 = 0x1,
00978         kCodeRate_3_4 = 0x2,
00979         kCodeRate_5_6 = 0x3,
00980         kCodeRate_7_8 = 0x4,
00981     };
00982     uint CodeRateHP(void) const { return _data[7] & 0x7; }
00983     QString CodeRateHPString(void) const
00984     {
00985         static QString cr[] = {
00986             "1/2", "2/3", "3/4", "5/6", "7/8", "auto", "auto", "auto"
00987         };
00988         return cr[CodeRateHP()];
00989     }
00990     // code_rate-LP_stream      3   8.0
00991     uint CodeRateLP(void) const { return (_data[8]>>5) & 0x7; }
00992     QString CodeRateLPString(void) const
00993     {
00994         static QString cr[] = {
00995             "1/2", "2/3", "3/4", "5/6", "7/8", "auto", "auto", "auto"
00996         };
00997         return cr[CodeRateLP()];
00998     }
00999     // guard_interval           2   8.3
01000     enum
01001     {
01002         kGuardInterval_1_32 = 0x0,
01003         kGuardInterval_1_16 = 0x1,
01004         kGuardInterval_1_8  = 0x2,
01005         kGuardInterval_1_4  = 0x3,
01006     };
01007     uint GuardInterval(void) const { return (_data[8]>>3) & 0x3; }
01008     QString GuardIntervalString(void) const
01009     {
01010         static QString gi[] = { "1/32", "1/16", "1/8", "1/4" };
01011         return gi[GuardInterval()];
01012     }
01013     // transmission_mode        2   8.5
01014     enum
01015     {
01016         kTransmissionMode2k = 0x00,
01017         kTransmissionMode8k = 0x01,
01018         kTransmissionMode4k = 0x02,
01019     };
01020     uint TransmissionMode(void) const { return (_data[8]>>1) & 0x3; }
01021     QString TransmissionModeString(void) const
01022     {
01023         static QString tm[] = { "2", "8", "4", "auto" };
01024         return tm[TransmissionMode()];
01025     }
01026     // other_frequency_flag     1   8.7
01027     bool OtherFrequencyInUse(void) const { return _data[8] & 0x1; }
01028     // reserved_future_use     32   9.0
01029 
01030     QString toString(void) const;
01031 };
01032 
01033 // DVB Bluebook A038 (Sept 2011) p 58
01034 class DSNGDescriptor : public MPEGDescriptor
01035 {
01036   public:
01037     DSNGDescriptor(const unsigned char *data, int len = 300) :
01038         MPEGDescriptor(data, len, DescriptorID::dsng) { }
01039     //       Name             bits  loc  expected value
01040     // descriptor_tag           8   0.0       0x68
01041     // descriptor_length        8   1.0
01042     // for (i=0;i<N;i++) { byte 8 }
01043 };
01044 
01045 // DVB Bluebook A038 (Sept 2011) p 58
01046 class ExtendedEventDescriptor : public MPEGDescriptor
01047 {
01048   public:
01049     ExtendedEventDescriptor(const unsigned char *data, int len = 300) :
01050         MPEGDescriptor(data, len, DescriptorID::extended_event) { }
01051     //       Name             bits  loc  expected value
01052     // descriptor_tag           8   0.0       0x4e
01053     // descriptor_length        8   1.0
01054 
01055     // descriptor_number        4   2.0
01056     uint DescriptorNumber(void) const { return _data[2] >> 4; }
01057     // last_number              4   2.4
01058     uint LastNumber(void)       const { return _data[2] & 0xf; }
01059     // ISO_639_language_code   24   3.0
01060     int LanguageKey(void) const
01061         { return iso639_str3_to_key(&_data[3]); }
01062     QString LanguageString(void) const
01063         { return iso639_key_to_str3(LanguageKey()); }
01064     int CanonicalLanguageKey(void) const
01065         { return iso639_key_to_canonical_key(LanguageKey()); }
01066     QString CanonicalLanguageString(void) const
01067         { return iso639_key_to_str3(CanonicalLanguageKey()); }
01068     // length_of_items          8   6.0
01069     uint LengthOfItems(void)    const { return _data[6]; }
01070     // for ( i=0;i<N;i++)
01071     // {
01072     //   item_description_len   8   0.0+p
01073     //   for (j=0;j<N;j++) { item_desc_char 8 }
01074     //   item_length            8   1.0+p2
01075     //   for (j=0;j<N;j++) { item_char 8 }
01076     // }
01077     // text_length 8
01078     uint TextLength(void)       const { return _data[7 + _data[6]]; }
01079     // for (i=0; i<N; i++) { text_char 8 }
01080     QString Text(void) const
01081         { return dvb_decode_text(&_data[8 + _data[6]], TextLength()); }
01082 
01083     // HACK beg -- Pro7Sat is missing encoding
01084     QString Text(const unsigned char *encoding_override,
01085                  uint encoding_length) const
01086     {
01087         return dvb_decode_text(&_data[8 + _data[6]], TextLength(),
01088                                encoding_override, encoding_length);
01089     }
01090     // HACK end -- Pro7Sat is missing encoding
01091 };
01092 
01093 // DVB Bluebook A038 (Sept 2011) p 60
01094 class FrequencyListDescriptor : public MPEGDescriptor
01095 {
01096   public:
01097     FrequencyListDescriptor(const unsigned char *data, int len = 300) :
01098         MPEGDescriptor(data, len, DescriptorID::frequency_list) { }
01099     //       Name             bits  loc  expected value
01100     // descriptor_tag           8   0.0       0x62
01101     // descriptor_length        8   1.0
01102 
01103     // reserved_future_use      6   2.0
01104     // coding_type              2   2.6
01105     enum
01106     {
01107         kCodingTypeNotDefined  = 0x0,
01108         kCodingTypeSatellite   = 0x1,
01109         kCodingTypeCable       = 0x2,
01110         kCodingTypeTerrestrial = 0x3,
01111     };
01112     uint CodingType(void)  const { return _data[2] & 0x3; }
01113     // for (i=0;I<N;i++)
01114     // {
01115     //   centre_frequency      32
01116     // }
01117     uint FrequencyCount()  const { return DescriptorLength()>>2; }
01118     unsigned long long Frequency(uint i) const
01119     {
01120         if (kCodingTypeTerrestrial == CodingType())
01121             return ((_data[3 + (i<<2)]<<24) | (_data[4 + (i<<2)]<<16) |
01122                     (_data[5 + (i<<2)]<<8)  | (_data[6 + (i<<2)]));
01123         else
01124             return byte4BCD2int(_data[3 + (i<<2)], _data[4 + (i<<2)],
01125                                 _data[5 + (i<<2)], _data[6 + (i<<2)]);
01126     }
01127     unsigned long long FrequencyHz(uint i) const
01128     {
01129         return Frequency(i) *
01130             ((kCodingTypeTerrestrial == CodingType()) ? 10 : 100);
01131     }
01132 
01133     QString toString(void) const;
01134 };
01135 
01136 // DVB Bluebook A038 (Sept 2011) p 70
01137 // ETSI EN 300 468 p 58
01138 class LocalTimeOffsetDescriptor : public MPEGDescriptor
01139 {
01140   public:
01141     LocalTimeOffsetDescriptor(const unsigned char *data, int len = 300) :
01142         MPEGDescriptor(data, len, DescriptorID::local_time_offset) { }
01143     //       Name             bits  loc  expected value
01144     // descriptor_tag           8   0.0       0x58
01145     // descriptor_length        8   1.0
01146     uint Count(void) const { return DescriptorLength() / 13; }
01147     // for(i=0;i<N;i++)
01148     // {
01149     //   country_code          24   0.0+p
01150     uint CountryCode(uint i) const
01151     {
01152         int o = 2 + i*13;
01153         return ((_data[o] << 16) | (_data[o+1] << 8) | _data[o+2]);
01154     }
01155     QString CountryCodeString(uint i) const
01156     {
01157         int o = 2 + i*13;
01158         return QString(_data[o]) + QChar(_data[o+1]) + QChar(_data[o+2]);
01159     }
01160     //   country_region_id      6   3.0+p
01161     uint CountryRegionId(uint i) const { return _data[2 + i*13 + 3] >> 2; }
01162     //   reserved               1   3.6+p
01163     //   local_time_off_polarity 1   3.7+p
01165     bool LocalTimeOffsetPolarity(uint i) const
01166         { return _data[2 + i*13 + 3] & 0x01; }
01167     //   local_time_offset     16   4.0+p
01168     uint LocalTimeOffset(uint i) const
01169         { return (_data[2 + i*13 + 4] << 8) | _data[2 + i*13 + 5]; }
01170     int LocalTimeOffsetWithPolarity(uint i) const
01171         { return (LocalTimeOffsetPolarity(i) ? -1 : +1) * LocalTimeOffset(i); }
01172     //   time_of_change        40   6.0+p
01173     // TODO decode this
01174     //   next_time_offset      16  11.0+p
01175     uint NextTimeOffset(uint i) const
01176         { return (_data[2 + i*13 + 11]<<8) | _data[2 + i*13 + 12]; }
01177     // }                           13.0
01178     QString toString(void) const;
01179 };
01180 
01181 // DVB Bluebook A038 (Sept 2011) p 71
01182 class MosaicDescriptor : public MPEGDescriptor
01183 {
01184   public:
01185     MosaicDescriptor(const unsigned char *data, int len = 300) :
01186         MPEGDescriptor(data, len, DescriptorID::mosaic) { }
01187     //       Name             bits  loc  expected value
01188     // descriptor_tag           8   0.0       0x51
01189     // descriptor_length        8   1.0
01190 
01191     // mosaic_entry_point       1   2.0
01192     // num_horiz_elem_cells     3   2.1
01193     // reserved_future_use      1   2.4
01194     // num_vert_elem_cells      3   2.5
01195     // for (i=0;i<N; i++)
01196     // {
01197     //   logical_cell_id        6   0.0+p
01198     //   reserved_future_use    7   0.6+p
01199     //   logical_cell_pres_info 3   1.5+p
01200     //   elem_cell_field_len    8   2.0+p
01201     //   for (i=0; j<elementary_cell_field_length; j++)
01202     //   {
01203     //     reserved_future_use  2
01204     //     elementary_cell_id   6
01205     //   }
01206     //   cell_linkage_info      8
01207     //   if (cell_linkage_info == 0x01)
01208     //   {
01209     //     bouquet_id          16
01210     //   }
01211     //   if (cell_linkage_info == 0x02)
01212     //   {
01213     //     original_network_id 16
01214     //     transport_stream_id 16
01215     //     service_id          16
01216     //   }
01217     //   if (cell_linkage_info == 0x03)
01218     //   {
01219     //     original_network_id 16
01220     //     transport_stream_id 16
01221     //     service_id          16
01222     //   }
01223     //   if (cell_linkage_info == 0x04)
01224     //   {
01225     //     original_network_id 16
01226     //     transport_stream_id 16
01227     //     service_id          16
01228     //     event_id            16
01229     //   }
01230     // }
01231 };
01232 
01233 // DVB Bluebook A038 (Sept 2011) p 74
01234 class MultilingualBouquetNameDescriptor : public MPEGDescriptor
01235 {
01236   public:
01237     MultilingualBouquetNameDescriptor(
01238         const unsigned char *data, int len = 300) :
01239         MPEGDescriptor(data, len, DescriptorID::multilingual_bouquet_name) { }
01240     //       Name             bits  loc  expected value
01241     // descriptor_tag           8   0.0       0x5c
01242     // descriptor_length        8   1.0
01243 
01244     // for (i=0;i<N;i++)
01245     // {
01246     //   ISO_639_language_code 24
01247     //   bouquet_name_length    8
01248     //   for (j=0;j<N;j++) { char 8 }
01249     // }
01250 };
01251 
01252 // DVB Bluebook A038 (Sept 2011) p 75
01253 class MultilingualNetworkNameDescriptor : public MPEGDescriptor
01254 {
01255   public:
01256     MultilingualNetworkNameDescriptor(
01257         const unsigned char *data, int len = 300) :
01258         MPEGDescriptor(data, len, DescriptorID::multilingual_network_name)
01259     {
01260     //       Name             bits  loc  expected value
01261     // descriptor_tag           8   0.0       0x5b
01262     // descriptor_length        8   1.0
01263     }
01264 
01265     // for (i=0;i<N;i++)
01266     // {
01267     //   ISO_639_language_code 24
01268     //   network_name_length    8
01269     //   for (j=0;j<N;j++) { char 8 }
01270     // }
01271 };
01272 
01273 // DVB Bluebook A038 (Sept 2011) p 76
01274 class MultilingualServiceNameDescriptor : public MPEGDescriptor
01275 {
01276   public:
01277     MultilingualServiceNameDescriptor(
01278         const unsigned char *data, int len = 300) :
01279         MPEGDescriptor(data, len, DescriptorID::multilingual_service_name) { }
01280     //       Name             bits  loc  expected value
01281     // descriptor_tag           8   0.0       0x5d
01282     // descriptor_length        8   1.0
01283 
01284     // for (i=0;i<N;i++)
01285     // {
01286     //   ISO_639_language_code 24
01287     //   service_provider_name_length 8
01288     //   for (j=0;j<N;j++) { char 8 }
01289     //   service_name_length    8
01290     //   for (j=0;j<N;j++) { char 8 }
01291     // }
01292 };
01293 
01294 // DVB Bluebook A038 (Sept 2011) p 76
01295 class NVODReferenceDescriptor : public MPEGDescriptor
01296 {
01297   public:
01298     NVODReferenceDescriptor(const unsigned char *data, int len = 300) :
01299         MPEGDescriptor(data, len, DescriptorID::nvod_reference) { }
01300     //       Name             bits  loc  expected value
01301     // descriptor_tag           8   0.0       0x4b
01302     // descriptor_length        8   1.0
01303     uint Count(void) const { return DescriptorLength() / 6; }
01304 
01305     // for (i=0;i<N;i++)
01306     // {
01307     //   transport_stream_id   16
01308     uint TransportStreamId(uint i) const
01309         { return (_data[i * 6 + 2] << 8) | _data[i * 6 + 3]; }
01310     //   original_network_id   16
01311     uint OriginalNetworkId(uint i) const
01312         { return (_data[i * 6 + 4] << 8) |  _data[i * 6 + 5]; }
01313     //   service_id            16
01314     uint ServiceId(uint i) const
01315         { return (_data[i * 6 + 6] << 8) | _data[i * 6 + 7]; }
01316     // }
01317     QString toString(void) const;
01318 };
01319 
01320 // DVB Bluebook A038 (Sept 2011) p 78
01321 class ParentalRatingDescriptor : public MPEGDescriptor
01322 {
01323   public:
01324     ParentalRatingDescriptor(const unsigned char *data, int len = 300) :
01325         MPEGDescriptor(data, len, DescriptorID::parental_rating) { }
01326     //       Name             bits  loc  expected value
01327     // descriptor_tag           8   0.0       0x55
01328     // descriptor_length        8   1.0
01329     uint Count(void) const { return DescriptorLength() / 4; }
01330 
01331     // for (i=0; i<N; i++)
01332     // {
01333     //   country_code          24
01334     //   rating                 8
01335     // }
01336 };
01337 
01338 // DVB Bluebook A038 (Sept 2011) p 78 (see also ETSI EN 300 231 PDC)
01339 class PDCDescriptor : public MPEGDescriptor
01340 {
01341   public:
01342     PDCDescriptor(const unsigned char *data, int len = 300) :
01343         MPEGDescriptor(data, len, DescriptorID::pdc, 3) { }
01344     //       Name             bits  loc  expected value
01345     // descriptor_tag           8   0.0       0x69
01346     // descriptor_length        8   1.0
01347 
01348     // reserved_future_use      4   2.0
01349     // program_id_label        20   2.4
01350     uint ProgramIdLabel(void) const
01351     { return  (_data[2] & 0x0F) << 16 | _data[3] << 8 |  _data[4]; }
01352     QString toString(void) const
01353     {
01354         return QString("PDCDescriptor program_id_label(%1)")
01355             .arg(ProgramIdLabel());
01356     }
01357 };
01358 
01359 // DVB Bluebook A038 (Sept 2011) p 79 (see also ETSI TS 101 162)
01360 class PrivateDataSpecifierDescriptor : public MPEGDescriptor
01361 {
01362   public:
01363     PrivateDataSpecifierDescriptor(const unsigned char *data, int len = 300) :
01364         MPEGDescriptor(data, len, DescriptorID::private_data_specifier) { }
01365     //       Name             bits  loc  expected value
01366     // descriptor_tag           8   0.0       0x5f
01367     // descriptor_length        8   1.0
01368 
01369     // private_data_specifier  32   2.0
01370 };
01371 
01372 // DVB Bluebook A038 (Sept 2011) p 79
01373 class ScramblingDescriptor : public MPEGDescriptor
01374 {
01375   public:
01376     ScramblingDescriptor(const unsigned char *data, int len = 300) :
01377         MPEGDescriptor(data, len, DescriptorID::scrambling, 1) { }
01378     //       Name             bits  loc  expected value
01379     // descriptor_tag           8   0.0       0x65
01380     // descriptor_length        8   1.0
01381 
01382     // scrambling_mode          8   2.0
01383     uint ScramblingMode(void) const { return _data[2]; }
01384     QString toString(void) const
01385     {
01386         return QString("ScramblingDescriptor scrambling_mode(%1)")
01387                 .arg(ScramblingMode());
01388     }
01389 };
01390 
01391 // Map serviceid's to their types
01392 class ServiceDescriptorMapping
01393 {
01394   public:
01395     ServiceDescriptorMapping(const uint serviceid) { m_serviceid = serviceid; }
01396     enum
01397     {
01398         kServiceTypeDigitalTelevision        = 0x01,
01399         kServiceTypeDigitalRadioSound        = 0x02,
01400         kServiceTypeTeletext                 = 0x03,
01401         kServiceTypeNVODReference            = 0x04,
01402         kServiceTypeNVODTimeShifted          = 0x05,
01403         kServiceTypeMosaic                   = 0x06,
01404         kServiceTypePALCodedSignal           = 0x07,
01405         kServiceTypeSECAMCodedSignal         = 0x08,
01406         kServiceTypeD_D2_MAC                 = 0x09,
01407         kServiceTypeAdvancedCodecDigitalRadioSound        = 0x0A,
01408         kServiceTypeNTSCCodedSignal          = 0x0B,
01409         kServiceTypeDataBroadcast            = 0x0C,
01410         kServiceTypeCommonInterface          = 0x0D,
01411         kServiceTypeRCS_Map                  = 0x0E,
01412         kServiceTypeRCS_FLS                  = 0x0F,
01413         kServiceTypeDVB_MHP                  = 0x10,
01414         kServiceTypeHDTV                     = 0x11,
01415         kServiceTypeAdvancedCodecSDDigitalTelevision       = 0x16,
01416         kServiceTypeAdvancedCodecHDDigitalTelevision       = 0x19,
01417         kServiceTypeAdvancedCodecFrameCompatiblePlanoStereoscopicHDTelevisionService = 0x1c,
01418         kServiceTypeEchoStarTV1              = 0x91,
01419         kServiceTypeEchoStarTV2              = 0x9a,
01420         kServiceTypeEchoStarTV3              = 0xa4,
01421         kServiceTypeEchoStarTV4              = 0xa6,
01422         kServiceTypeNimiqTV1                 = 0x81,
01423         kServiceTypeNimiqTV2                 = 0x85,
01424         kServiceTypeNimiqTV3                 = 0x86,
01425         kServiceTypeNimiqTV4                 = 0x89,
01426         kServiceTypeNimiqTV5                 = 0x8a,
01427         kServiceTypeNimiqTV6                 = 0x8d,
01428         kServiceTypeNimiqTV7                 = 0x8f,
01429         kServiceTypeNimiqTV8                 = 0x90,
01430         kServiceTypeNimiqTV9                 = 0x96,
01431 
01432     };
01433     uint ServiceType(void) const { return m_serviceid; }
01434     bool IsDTV(void) const
01435     {
01436         return ((ServiceType() == kServiceTypeDigitalTelevision) ||
01437                 (ServiceType() ==
01438                  kServiceTypeAdvancedCodecSDDigitalTelevision) ||
01439                 IsHDTV() ||
01440                 (ServiceType() == kServiceTypeEchoStarTV1) ||
01441                 (ServiceType() == kServiceTypeEchoStarTV2) ||
01442                 (ServiceType() == kServiceTypeEchoStarTV3) ||
01443                 (ServiceType() == kServiceTypeEchoStarTV4) ||
01444                 (ServiceType() == kServiceTypeNimiqTV1) ||
01445                 (ServiceType() == kServiceTypeNimiqTV2) ||
01446                 (ServiceType() == kServiceTypeNimiqTV3) ||
01447                 (ServiceType() == kServiceTypeNimiqTV4) ||
01448                 (ServiceType() == kServiceTypeNimiqTV5) ||
01449                 (ServiceType() == kServiceTypeNimiqTV6) ||
01450                 (ServiceType() == kServiceTypeNimiqTV7) ||
01451                 (ServiceType() == kServiceTypeNimiqTV8) ||
01452                 (ServiceType() == kServiceTypeNimiqTV9));
01453     }
01454     bool IsDigitalAudio(void) const
01455     {
01456         return ((ServiceType() == kServiceTypeDigitalRadioSound) ||
01457                 (ServiceType() == kServiceTypeAdvancedCodecDigitalRadioSound));
01458     }
01459     bool IsHDTV(void) const
01460     {
01461         return
01462             (ServiceType() == kServiceTypeHDTV) ||
01463             (ServiceType() == kServiceTypeAdvancedCodecHDDigitalTelevision) ||
01464             (ServiceType() == kServiceTypeAdvancedCodecFrameCompatiblePlanoStereoscopicHDTelevisionService);
01465     }
01466     bool IsTeletext(void) const
01467     {
01468         return ServiceType() == kServiceTypeDataBroadcast;
01469     }
01470     QString toString(void) const;
01471 
01472   private:
01473     uint m_serviceid;
01474 };
01475 
01476 // DVB Bluebook A038 (Sept 2011) p 80
01477 class ServiceDescriptor : public MPEGDescriptor
01478 {
01479   public:
01480     ServiceDescriptor(const unsigned char *data, int len = 300) :
01481         MPEGDescriptor(data, len, DescriptorID::service) { }
01482     //       Name             bits  loc  expected value
01483     // descriptor_tag           8   0.0       0x48
01484     // descriptor_length        8   1.0
01485 
01486     // service_type             8   2.0
01487     uint ServiceType(void) const { return _data[2]; }
01488     // svc_provider_name_len    8   3.0
01489     uint ServiceProviderNameLength(void) const { return _data[3]; }
01490     // for (i=0;i<N;I++) { char 8 }
01491     QString ServiceProviderName(void) const
01492         { return dvb_decode_text(_data + 4, ServiceProviderNameLength()); }
01493     QString ServiceProviderShortName(void) const
01494     {
01495         return dvb_decode_short_name(_data + 4, ServiceProviderNameLength());
01496     }
01497     // service_name_length      8
01498     uint ServiceNameLength(void) const
01499         { return _data[4 + ServiceProviderNameLength()]; }
01500     // for (i=0;i<N;I++) { char 8 }
01501     QString ServiceName(void) const
01502     {
01503         return dvb_decode_text(_data + 5 + ServiceProviderNameLength(),
01504                                ServiceNameLength());
01505     }
01506     QString ServiceShortName(void) const
01507     {
01508         return dvb_decode_short_name(_data + 5 + ServiceProviderNameLength(),
01509                                      ServiceNameLength());
01510     }
01511     bool IsDTV(void) const
01512         { return ServiceDescriptorMapping(ServiceType()).IsDTV(); }
01513     bool IsDigitalAudio(void) const
01514         { return ServiceDescriptorMapping(ServiceType()).IsDigitalAudio(); }
01515     bool IsHDTV(void) const
01516         { return ServiceDescriptorMapping(ServiceType()).IsHDTV(); }
01517     bool IsTeletext(void) const
01518         { return ServiceDescriptorMapping(ServiceType()).IsTeletext(); }
01519 
01520     QString toString(void) const
01521     {
01522         return QString("ServiceDescriptor: %1 %2").arg(ServiceName())
01523             .arg(ServiceDescriptorMapping(ServiceType()).toString());
01524     }
01525 };
01526 
01527 // DVB Bluebook A038 (Sept 2011) p 82
01528 class ServiceAvailabilityDescriptor : public MPEGDescriptor
01529 {
01530   public:
01531     ServiceAvailabilityDescriptor(const unsigned char *data, int len = 300) :
01532         MPEGDescriptor(data, len, DescriptorID::service_availability) { }
01533     //       Name             bits  loc  expected value
01534     // descriptor_tag           8   0.0       0x72
01535     // descriptor_length        8   1.0
01536 
01537     // availability_flag        1   2.0
01538     // reserved                 7   2.1
01539     // for (i=0;i<N;i++) { cell_id 16 }
01540 };
01541 
01542 // DVB Bluebook A038 (Sept 2011) p 82
01543 class ServiceListDescriptor : public MPEGDescriptor
01544 {
01545   public:
01546     ServiceListDescriptor(const unsigned char *data, int len = 300) :
01547         MPEGDescriptor(data, len, DescriptorID::service_list) { }
01548     //       Name             bits  loc  expected value
01549     // descriptor_tag           8   0.0       0x41
01550     // descriptor_length        8   1.0
01551 
01552     // for (i=0;i<N;I++)
01553     // {
01554     //   service_id            16  0.0+p
01555     //   service_type           8  2.0+p
01556     // }
01557     uint ServiceCount(void) const { return DescriptorLength() / 3; }
01558 
01559     uint ServiceID(uint i) const
01560         { return (_data[2+i*3] << 8) | _data[3+i*3]; }
01561 
01562     uint ServiceType(uint i) const { return _data[4+i*3]; }
01563 
01564     QString toString(void) const
01565     {
01566         QString str = QString("ServiceListDescriptor: %1 Services\n")
01567             .arg(ServiceCount());
01568         for (uint i=0; i<ServiceCount(); i++)
01569         {
01570             if (i!=0) str.append("\n");
01571             str.append(QString("      Service (%1) Type%2").arg(ServiceID(i))
01572                 .arg(ServiceDescriptorMapping(ServiceType(i)).toString()));
01573         }
01574         return str;
01575     }
01576 };
01577 
01578 // DVB Bluebook A038 (Sept 2011) p 82
01579 class ServiceMoveDescriptor : public MPEGDescriptor
01580 {
01581   public:
01582     ServiceMoveDescriptor(const unsigned char *data, int len = 300) :
01583         MPEGDescriptor(data, len, DescriptorID::service_move) { }
01584     //       Name             bits  loc  expected value
01585     // descriptor_tag           8   0.0       0x60
01586     // descriptor_length        8   1.0
01587 
01588     // new_original_network_id 16   2.0
01589     // new_transport_stream_id 16   4.0
01590     // new_service_id          16   6.0
01591 };
01592 
01593 // DVB Bluebook A038 (Sept 2011) p 83
01594 class ShortEventDescriptor : public MPEGDescriptor
01595 {
01596   public:
01597     ShortEventDescriptor(const unsigned char *data, int len = 300) :
01598         MPEGDescriptor(data, len, DescriptorID::short_event) { }
01599     //       Name             bits  loc  expected value
01600     // descriptor_tag           8   0.0       0x4d
01601     // descriptor_length        8   1.0
01602 
01603     // ISO_639_language_code   24   2.0
01604     int LanguageKey(void) const
01605         { return iso639_str3_to_key(&_data[2]); }
01606     QString LanguageString(void) const
01607         { return iso639_key_to_str3(LanguageKey()); }
01608     int CanonicalLanguageKey(void) const
01609         { return iso639_key_to_canonical_key(LanguageKey()); }
01610     QString CanonicalLanguageString(void) const
01611         { return iso639_key_to_str3(CanonicalLanguageKey()); }
01612     // event_name_length        8   5.0
01613     uint EventNameLength(void) const { return _data[5]; }
01614     // for (i=0;i<event_name_length;i++) { event_name_char 8 }
01615     QString EventName(void) const
01616         { return dvb_decode_text(&_data[6], _data[5]); }
01617     QString EventShortName(void) const
01618         { return dvb_decode_short_name(&_data[6], _data[5]); }
01619     // text_length              8
01620     uint TextLength(void) const { return _data[6 + _data[5]]; }
01621     // for (i=0;i<text_length;i++) { text_char 8 }
01622     QString Text(void) const
01623         { return dvb_decode_text(&_data[7 + _data[5]], TextLength()); }
01624 
01625     // HACK beg -- Pro7Sat is missing encoding
01626     QString EventName(const unsigned char *encoding_override,
01627                       uint encoding_length) const
01628     {
01629         return dvb_decode_text(&_data[6], _data[5],
01630                                encoding_override, encoding_length);
01631     }
01632 
01633     QString Text(const unsigned char *encoding_override,
01634                  uint encoding_length) const
01635     {
01636         return dvb_decode_text(&_data[7 + _data[5]], TextLength(),
01637                                encoding_override, encoding_length);
01638     }
01639     // HACK end -- Pro7Sat is missing encoding
01640 
01641     QString toString(void) const
01642         { return LanguageString() + " : " + EventName() + " : " + Text(); }
01643 };
01644 
01645 // DVB Bluebook A038 (Sept 2011) p 84
01646 class ShortSmoothingBufferDescriptor : public MPEGDescriptor
01647 {
01648   public:
01649     ShortSmoothingBufferDescriptor(const unsigned char *data, int len = 300) :
01650         MPEGDescriptor(data, len, DescriptorID::short_smoothing_buffer) { }
01651     //       Name             bits  loc  expected value
01652     // descriptor_tag           8   0.0       0x61
01653     // descriptor_length        8   1.0
01654 
01655     // sb_size                  2   2.0
01656     // sb_leak_rate             6   2.2
01657     // for (i=0; i<N; i++)
01658     // { DVB_reserved           8 }
01659 };
01660 
01661 // DVB Bluebook A038 (Sept 2011) p 85
01664 class StreamIdentifierDescriptor : public MPEGDescriptor
01665 {
01666   public:
01667     StreamIdentifierDescriptor(const unsigned char *data, int len = 300) :
01668         MPEGDescriptor(data, len, DescriptorID::stream_identifier, 1) { }
01669     //       Name             bits  loc  expected value
01670     // descriptor_tag           8   0.0       0x52
01671     // descriptor_length        8   1.0       0x01
01672 
01673     // component_tag            8   2.0
01674     uint ComponentTag(void) const { return _data[2]; }
01675     QString toString(void) const
01676     {
01677         return QString("Stream Identifier Descriptor (0x52): ComponentTag=0x%1")
01678             .arg(ComponentTag(),1,16);
01679     }
01680 };
01681 
01682 // DVB Bluebook A038 (Sept 2011) p 86
01683 class StuffingDescriptor : public MPEGDescriptor
01684 {
01685   public:
01686     StuffingDescriptor(const unsigned char *data, int len = 300) :
01687         MPEGDescriptor(data, len, DescriptorID::dvb_stuffing) { }
01688     //       Name             bits  loc  expected value
01689     // descriptor_tag           8   0.0       0x42
01690     // descriptor_length        8   1.0
01691     // stuffing_byte            *   2.0
01692     QString toString(void) const
01693     {
01694         return QString("Stuffing Descriptor (0x42) length(%1)")
01695             .arg(DescriptorLength());
01696     }
01697 };
01698 
01699 // DVB Bluebook A038 (Sept 2011) p 86
01700 class SubtitlingDescriptor : public MPEGDescriptor
01701 {
01702   public:
01703     SubtitlingDescriptor(const unsigned char *data, int len = 300) :
01704         MPEGDescriptor(data, len, DescriptorID::subtitling) { }
01705     //       Name             bits  loc  expected value
01706     // descriptor_tag           8   0.0       0x59
01707     // descriptor_length        8   1.0
01708 
01709     uint StreamCount(void) const { return DescriptorLength() >> 3; }
01710     // for (i= 0;i<N;I++)
01711     // {
01712     //   ISO_639_language_code 24   0.0+(i*8)
01713     int LanguageKey(uint i) const
01714         { return iso639_str3_to_key(&_data[2 + (i<<3)]); }
01715     QString LanguageString(uint i) const
01716         { return iso639_key_to_str3(LanguageKey(i)); }
01717     int CanonicalLanguageKey(uint i) const
01718         { return iso639_key_to_canonical_key(LanguageKey(i)); }
01719     QString CanonicalLanguageString(uint i) const
01720         { return iso639_key_to_str3(CanonicalLanguageKey(i)); }
01721 
01722     //   subtitling_type        8   3.0+(i*8)
01723     uint SubtitleType(uint i) const
01724         { return _data[5 + (i<<3)]; }
01725     //   composition_page_id   16   4.0+(i*8)
01726     uint CompositionPageID(uint i) const
01727         { return (_data[6 + (i<<3)] << 8) | _data[7 + (i<<3)]; }
01728     //   ancillary_page_id     16   6.0+(i*8)
01729     uint AncillaryPageID(uint i) const
01730         { return (_data[8 + (i<<3)] << 8) | _data[9 + (i<<3)]; }
01731     // }                            8.0
01732 };
01733 
01734 // DVB Bluebook A038 (Sept 2011) p 87
01735 class TelephoneDescriptor : public MPEGDescriptor
01736 {
01737   public:
01738     TelephoneDescriptor(const unsigned char *data, int len = 300) :
01739         MPEGDescriptor(data, len, DescriptorID::telephone) { }
01740     //       Name             bits  loc  expected value
01741     // descriptor_tag           8   0.0       0x57
01742     // descriptor_length        8   1.0
01743 
01744     // reserved_future_use      2   2.0
01745     // foreign_availability     1   2.2
01746     // connection_type          5   2.3
01747     // reserved_future_use      1   3.0
01748     // country_prefix_length    2   3.1
01749     // i18n_area_code_len       3   3.4
01750     // operator_code_length     2   3.6
01751     // reserved_future_use      1   3.7
01752     // national_area_code_len   3   4.0
01753     // core_number_length       4   4.4
01754     //
01755     // for (i=0; i<N; i++)
01756     //   { country_prefix_char   8 }
01757     // for (i=0; i<N; i++)
01758     //   { international_area_code_char 8 }
01759     // for (i=0; i<N; i++)
01760     //   { operator_code_char    8 }
01761     // for (i=0; i<N; i++)
01762     //   { national_area_code_char 8 }
01763     // for (i=0; i<N; i++)
01764     //   { core_number_char 8 }
01765 };
01766 
01767 // DVB Bluebook A038 (Sept 2011) p 88
01768 class TeletextDescriptor : public MPEGDescriptor
01769 {
01770   public:
01771     TeletextDescriptor(const unsigned char *data, int len = 300) :
01772         MPEGDescriptor(data, len, DescriptorID::teletext) { }
01773     //       Name             bits  loc  expected value
01774     // descriptor_tag           8   0.0       0x56
01775     // descriptor_length        8   1.0
01776 
01777     uint StreamCount(void) const { return DescriptorLength() / 5; }
01778 
01779     // for (i=0; i<N; i++)
01780     // {
01781     //   ISO_639_language_code 24  0.0
01782     int LanguageKey(uint i) const
01783         { return iso639_str3_to_key(&_data[2 + (i*5)]); }
01784     QString LanguageString(uint i) const
01785         { return iso639_key_to_str3(LanguageKey(i)); }
01786     int CanonicalLanguageKey(uint i) const
01787         { return iso639_key_to_canonical_key(LanguageKey(i)); }
01788     QString CanonicalLanguageString(uint i) const
01789         { return iso639_key_to_str3(CanonicalLanguageKey(i)); }
01790     //   teletext_type         5   3.0
01791     uint TeletextType(uint i) const
01792         { return _data[5 + (i*5)] >> 3; }
01793     //   teletext_magazine_num 3   3.5
01794     uint TeletextMagazineNum(uint i) const
01795         { return _data[5 + (i*5)] & 0x7; }
01796     //   teletext_page_num     8   4.0
01797     uint TeletextPageNum(uint i) const
01798         { return _data[6 + (i*5)]; }
01799     // }                           5.0
01800 };
01801 
01802 // DVB Bluebook A038 (Sept 2011) p 89
01803 class TimeShiftedEventDescriptor : public MPEGDescriptor
01804 {
01805   public:
01806     TimeShiftedEventDescriptor(const unsigned char *data, int len = 300) :
01807         MPEGDescriptor(data, len, DescriptorID::time_shifted_event) { }
01808     //       Name             bits  loc  expected value
01809     // descriptor_tag           8   0.0       0x4f
01810     // descriptor_length        8   1.0
01811 
01812     // reference_service_id    16   2.0
01813     // reference_event_id      16   4.0
01814 };
01815 
01816 // DVB Bluebook A038 (Sept 2011) p 90
01817 class TimeShiftedServiceDescriptor : public MPEGDescriptor
01818 {
01819   public:
01820     TimeShiftedServiceDescriptor(const unsigned char *data, int len = 300) :
01821         MPEGDescriptor(data, len, DescriptorID::dvb_time_shifted_service) { }
01822     //       Name             bits  loc  expected value
01823     // descriptor_tag           8   0.0       0x4c
01824     // descriptor_length        8   1.0
01825 
01826     // reference_service_id    16   2.0
01827 };
01828 
01829 // DVB Bluebook A038 (Sept 2011) p 90
01830 class TransportStreamDescriptor : public MPEGDescriptor
01831 {
01832   public:
01833     TransportStreamDescriptor(const unsigned char *data, int len = 300) :
01834         MPEGDescriptor(data, len, DescriptorID::transport_stream) { }
01835     //       Name             bits  loc  expected value
01836     // descriptor_tag           8   0.0       0x67
01837     // descriptor_length        8   1.0
01838 
01839     // for (i=0; i<N; i++) { byte 8 }
01840     QString Data(void) const
01841         { return dvb_decode_text(&_data[2], DescriptorLength()); }
01842     QString toString(void) const
01843         { return QString("TransportStreamDescriptor data(%1)").arg(Data()); }
01844 };
01845 
01846 // DVB Bluebook A038 (Sept 2011) p 91
01847 class VBIDataDescriptor : public MPEGDescriptor
01848 {
01849   public:
01850     VBIDataDescriptor(const unsigned char *data, int len = 300) :
01851         MPEGDescriptor(data, len, DescriptorID::vbi_data) { }
01852     //       Name             bits  loc  expected value
01853     // descriptor_tag           8   0.0       0x45
01854     // descriptor_length        8   1.0
01855 
01856     // for (i=0; i<N; i++)
01857     // {
01858     //   data_service_id        8  0.0+p
01859     //   data_service_length    8  1.0+p
01860     //   if ((data_service_id&0x7) && data_service_id!=0x3))
01861     //   {
01862     //     for (i=0; i<N; i++)
01863     //     {
01864     //       reserved           2  2.0+p2
01865     //       field_parity       1  2.2+p2
01866     //       line_offset        5  2.3+p2
01867     //     }
01868     //   }
01869     //   else
01870     //   {
01871     //     for (i=0; i<N; i++) { reserved 8 }
01872     //   }
01873     // }
01874 };
01875 
01876 // DVB Bluebook A038 (Sept 2011) p 92
01877 class VBITeletextDescriptor : public MPEGDescriptor
01878 {
01879   public:
01880     VBITeletextDescriptor(const unsigned char *data, int len = 300) :
01881         MPEGDescriptor(data, len, DescriptorID::vbi_teletext) { }
01882     //       Name             bits  loc  expected value
01883     // descriptor_tag           8   0.0       0x46
01884     // descriptor_length        8   1.0
01885 
01886     // for (i=0;i<N;i++)
01887     // {
01888     //   ISO_639_language_code 24   0.0+p
01889     //   teletext_type          5   3.0+p
01890     //   teletext_magazine_num  3   3.5+p
01891     //   teletext_page_num      8   4.0+p
01892     // }                            5.0
01893 };
01894 
01895 // DVB Bluebook A038 (Sept 2011) p 119
01896 class PartialTransportStreamDescriptor : public MPEGDescriptor
01897 {
01898   public:
01899     PartialTransportStreamDescriptor(const unsigned char *data, int len = 300) :
01900         MPEGDescriptor(data, len, DescriptorID::partial_transport_stream) { }
01901     //       Name             bits  loc  expected value
01902     // descriptor_tag           8   0.0       0x63
01903     // descriptor_length        8   1.0
01904 
01905     // DVB_reserved_future_use  2   2.0
01906     // peak_rate               22   2.2
01907     uint PeakRate(void) const
01908         { return (_data[2] & 0x3f) << 16 | _data[3] | _data[4]; }
01909     // DVB_reserved_future_use  2   5.0
01910     // min_overall_smooth_rate 22   5.2
01911     uint SmoothRate(void) const
01912         { return (_data[5] & 0x3f) << 16 | _data[6] | _data[7]; }
01913     // DVB_reserved_future_use  2   8.0
01914     // max_overall_smooth_buf  14   8.2
01915     uint SmoothBuf(void) const { return ((_data[8] & 0x3f) << 8) | _data[9]; }
01916     QString toString(void) const;
01917 };
01918 
01919 
01920 // a_52a.pdf p125 Table A7 (for DVB)
01921 class AC3Descriptor : public MPEGDescriptor
01922 {
01923   public:
01924     AC3Descriptor(const unsigned char *data, int len = 300) :
01925         MPEGDescriptor(data, len, DescriptorID::ac3) { }
01926     //       Name             bits  loc  expected value
01927     // descriptor_tag           8   0.0       0x6A
01928     // descriptor_length        8   1.0
01929 
01930     // component_type_flag      1   2.0
01931     bool HasComponentType(void) const { return _data[2] & 0x80; }
01932     // bsid_flag                1   2.1
01933     bool HasBSID(void) const { return _data[2] & 0x40; }
01934     // mainid_flag              1   2.2
01935     bool HasMainID(void) const { return _data[2] & 0x20; }
01936     // asvc_flag                1   2.3
01937     bool HasASVC(void) const { return _data[2] & 0x10; }
01938     // reserved_flags           4   2.4
01939     // if (component_type_flag == 1)
01940     //   { component_type       8 uimsbf }
01941     uint ComponentType(void) const { return _data[3]; }
01942     // if (bsid_flag == 1)
01943     //   { bsid                 8 uimsbf }
01944     uint BSID(void) const
01945         { return (HasComponentType()) ? _data[4] : _data[3]; }
01946     // if (mainid_flag == 1)
01947     //   { mainid               8 uimsbf }
01948     uint MainID(void) const
01949     {
01950         int offset = 3;
01951         offset += (HasComponentType()) ? 1 : 0;
01952         offset += (HasBSID()) ? 1 : 0;
01953         return _data[offset];
01954     }
01955     // if (asvc_flag==1)
01956     //   { asvc                 8 uimsbf }
01957     uint ASVC(void) const
01958     {
01959         int offset = 3;
01960         offset += (HasComponentType()) ? 1 : 0;
01961         offset += (HasBSID()) ? 1 : 0;
01962         offset += (HasMainID()) ? 1 : 0;
01963         return _data[offset];
01964     }
01965     // for (I=0;I<N;I++)
01966     //   { additional_info[i] N*8 uimsbf }
01967     //};
01968     QString toString(void) const;
01969 };
01970 
01971 static QString coderate_inner(uint cr)
01972 {
01973     switch (cr)
01974     {
01975         case 0x0:  return "auto"; // not actually defined in spec
01976         case 0x1:  return "1/2";
01977         case 0x2:  return "2/3";
01978         case 0x3:  return "3/4";
01979         case 0x4:  return "5/6";
01980         case 0x5:  return "7/8";
01981         case 0x8:  return "8/9";
01982         case 0xf:  return "none";
01983         default:   return "auto"; // not actually defined in spec
01984     }
01985 }
01986 
01987 class UKChannelListDescriptor : public MPEGDescriptor
01988 {
01989   public:
01990     UKChannelListDescriptor(const unsigned char *data, int len = 300) :
01991         MPEGDescriptor(data, len, PrivateDescriptorID::dvb_uk_channel_list) { }
01992     //       Name             bits  loc  expected value
01993     // descriptor_tag           8   0.0       0x83
01994     // descriptor_length        8   1.0
01995 
01996     uint ChannelCount(void) const { return DescriptorLength() >> 2; }
01997 
01998     uint ServiceID(uint i) const
01999         { return (_data[2 + (i<<2)] << 8) | _data[3 + (i<<2)]; }
02000 
02001     uint ChannelNumber(uint i) const
02002         { return ((_data[4 + (i<<2)] << 8) | _data[5 + (i<<2)]) & 0x3ff; }
02003 
02004     QString toString(void) const;
02005 };
02006 
02007 // ETSI TS 102 323 (TV Anytime)
02008 class DVBContentIdentifierDescriptor : public MPEGDescriptor
02009 {
02010   public:
02011     DVBContentIdentifierDescriptor(const unsigned char *data, int len = 300) :
02012         MPEGDescriptor(data, len, DescriptorID::dvb_content_identifier) { }
02013     //       Name             bits  loc  expected value
02014     // descriptor_tag           8   0.0       0x76
02015     // descriptor_length        8   1.0
02016 
02017     uint ContentType(void) const { return _data[2] >> 2; }
02018 
02019     uint ContentEncoding(void) const { return _data[2] & 0x03; }
02020 
02021     // A content identifier is a URI.  It may contain UTF-8 encoded using %XX.
02022     QString ContentId(void) const
02023     {
02024         return QString::fromAscii((const char *)_data+4, _data[3]);
02025     }
02026 };
02027 
02028 // ETSI TS 102 323 (TV Anytime)
02029 class DefaultAuthorityDescriptor : public MPEGDescriptor
02030 {
02031   public:
02032     DefaultAuthorityDescriptor(const unsigned char *data, int len = 300) :
02033         MPEGDescriptor(data, len, DescriptorID::default_authority) { }
02034     //       Name             bits  loc  expected value
02035     // descriptor_tag           8   0.0       0x73
02036     // descriptor_length        8   1.0
02037 
02038     QString DefaultAuthority(void) const
02039     {
02040         return QString::fromAscii((const char *)_data+2, _data[1]);
02041     }
02042 
02043     QString toString(void) const
02044     {
02045         return QString("DefaultAuthorityDescriptor: Authority(%1)")
02046             .arg(DefaultAuthority());
02047     }
02048 };
02049 
02050 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends