00001
00002
00003 #ifndef _MPEG_DESCRIPTORS_H_
00004 #define _MPEG_DESCRIPTORS_H_
00005
00006
00007 #include <vector>
00008 using namespace std;
00009
00010
00011 #include <QMutex>
00012 #include <QString>
00013
00014
00015 #include "iso639.h"
00016
00017 typedef vector<const unsigned char*> desc_list_t;
00018
00019 class DescriptorID
00020 {
00021 public:
00022 enum
00023 {
00024
00025 video = 0x02,
00026 audio = 0x03,
00027 hierarchy = 0x04,
00028 registration = 0x05,
00029 data_stream_alignment = 0x06,
00030 target_background_grid = 0x07,
00031 video_window = 0x08,
00032 conditional_access = 0x09,
00033 iso_639_language = 0x0A,
00034 system_clock = 0x0B,
00035 multiplex_buffer_utilization= 0x0C,
00036 copyright = 0x0D,
00037 maximum_bitrate = 0x0E,
00038 private_data_indicator = 0x0F,
00039 smoothing_buffer = 0x10,
00040 std = 0x11,
00041 ibp = 0x12,
00042 carousel_identifier = 0x13,
00043 association_tag = 0x14,
00044 deferred_association_tag = 0x15,
00045
00046 npt_reference = 0x17,
00047 npt_endpoint = 0x18,
00048 stream_mode = 0x19,
00049 stream_event = 0x1A,
00050 mpeg4_video = 0x1B,
00051 mpeg4_audio = 0x1C,
00052 iod = 0x1D,
00053 sl = 0x1E,
00054 fmc = 0x1F,
00055 external_es_id = 0x20,
00056 mux_code = 0x21,
00057 fmx_buffer_size = 0x22,
00058 multiplex_buffer = 0x23,
00059 content_labeling = 0x24,
00060 metadata_pointer = 0x25,
00061 metadata = 0x26,
00062 metadata_std = 0x27,
00063 avc_video = 0x28,
00064 ipmp = 0x29,
00065 avc_timing_and_hrd = 0x2A,
00066 mpeg2_aac_audio = 0x2B,
00067 flex_mux_timing = 0x2C,
00068
00069
00070 network_name = 0x40,
00071 service_list = 0x41,
00072 dvb_stuffing = 0x42,
00073 satellite_delivery_system = 0x43,
00074 cable_delivery_system = 0x44,
00075 vbi_data = 0x45,
00076 vbi_teletext = 0x46,
00077 bouquet_name = 0x47,
00078 service = 0x48,
00079 country_availability = 0x49,
00080 linkage = 0x4A,
00081 nvod_reference = 0x4B,
00082 dvb_time_shifted_service = 0x4C,
00083 short_event = 0x4D,
00084 extended_event = 0x4E,
00085 time_shifted_event = 0x4F,
00086
00087 component = 0x50,
00088 mosaic = 0x51,
00089 stream_identifier = 0x52,
00090 ca_identifier = 0x53,
00091 content = 0x54,
00092 parental_rating = 0x55,
00093 teletext = 0x56,
00094 telephone = 0x57,
00095 local_time_offset = 0x58,
00096 subtitling = 0x59,
00097 terrestrial_delivery_system = 0x5A,
00098 multilingual_network_name = 0x5B,
00099 multilingual_bouquet_name = 0x5C,
00100 multilingual_service_name = 0x5D,
00101 multilingual_component = 0x5E,
00102 private_data_specifier = 0x5F,
00103
00104 service_move = 0x60,
00105 short_smoothing_buffer = 0x61,
00106 frequency_list = 0x62,
00107 partial_transport_stream = 0x63,
00108 data_broadcast = 0x64,
00109 scrambling = 0x65,
00110 data_broadcast_id = 0x66,
00111 transport_stream = 0x67,
00112 dsng = 0x68,
00113 pdc = 0x69,
00114 ac3 = 0x6A,
00115 ancillary_data = 0x6B,
00116 cell_list = 0x6C,
00117 cell_frequency_link = 0x6D,
00118 announcement_support = 0x6E,
00119 application_signalling = 0x6F,
00120
00121 adaptation_field_data = 0x70,
00122 service_identifier = 0x71,
00123 service_availability = 0x72,
00124 default_authority = 0x73,
00125 related_content = 0x74,
00126 tva_id = 0x75,
00127 dvb_content_identifier = 0x76,
00128 time_slice_fec_identifier = 0x77,
00129 ecm_repetition_rate = 0x78,
00130 s2_delivery_system = 0x79,
00131 eac3 = 0x7A,
00132 dts = 0x7B,
00133 aac = 0x7C,
00134
00135
00136 atsc_stuffing = 0x80,
00137 ac3_audio_stream = 0x81,
00138 atsc_program_identifier = 0x85,
00139 caption_service = 0x86,
00140 content_advisory = 0x87,
00141 atsc_ca_descriptor = 0x88,
00142 atsc_descriptor_tag = 0x89,
00143
00144
00145 scte_frame_rate = 0x82,
00146 scte_extended_video = 0x83,
00147 scte_component_name = 0x84,
00148 scte_cue_identifier = 0x8A,
00149 scte_frequency_spec = 0x90,
00150 scte_modulation_params = 0x91,
00151 scte_transport_stream_id = 0x92,
00152 scte_revision_detection = 0x93,
00153
00154
00155 extended_channel_name = 0xA0,
00156 service_location = 0xA1,
00157 atsc_time_shifted_service = 0xA2,
00158 component_name = 0xA3,
00159 atsc_data_service = 0xA4,
00160 atsc_pid_count = 0xA5,
00161 atsc_download = 0xA6,
00162 multiprotocol_encapsulation = 0xA7,
00163 dcc_departing_request = 0xA8,
00164 dcc_arriving_request = 0xA9,
00165 drm_control = 0xAA,
00166 atsc_genre = 0xAB,
00167 atsc_private_information = 0xAD,
00168
00169 atsc_content_identifier = 0xB6,
00170 };
00171 };
00172
00173 class PrivateDescriptorID
00174 {
00175 public:
00176 enum
00177 {
00178
00179
00180
00181
00182 dvb_uk_channel_list = 0x83,
00183
00184
00185 dish_event_rights = 0x87,
00186 dish_event_mpaa = 0x89,
00187 dish_event_name = 0x91,
00188 dish_event_description = 0x92,
00189 dish_event_properties = 0x94,
00190 dish_event_vchip = 0x95,
00191 dish_event_tags = 0x96,
00192
00193
00194 premiere_content_order = 0xF0,
00195 premiere_parental_information = 0xF1,
00196 premiere_content_transmission = 0xF2,
00197 };
00198 };
00199
00200 class MPEGDescriptor
00201 {
00202 public:
00203 operator const unsigned char*() const { return _data; }
00204
00205 MPEGDescriptor(const unsigned char *data, int len = 300) : _data(data)
00206 {
00207 if ((len < 2) || (int(DescriptorLength()) + 2) > len)
00208 _data = NULL;
00209 }
00210 MPEGDescriptor(const unsigned char *data,
00211 int len, uint tag) : _data(data)
00212 {
00213 if ((len < 2) || (int(DescriptorLength()) + 2) > len)
00214 _data = NULL;
00215 else if (DescriptorTag() != tag)
00216 _data = NULL;
00217 }
00218 MPEGDescriptor(const unsigned char *data,
00219 int len, uint tag, uint req_desc_len) : _data(data)
00220 {
00221 if ((len < 2) || (int(DescriptorLength()) + 2) > len)
00222 _data = NULL;
00223 else if (DescriptorTag() != tag)
00224 _data = NULL;
00225 else if (DescriptorLength() != req_desc_len)
00226 _data = NULL;
00227 }
00228 virtual ~MPEGDescriptor() {}
00229
00230 bool IsValid(void) const { return _data; }
00231 uint size(void) const { return DescriptorLength() + 2; }
00232
00233 uint DescriptorTag(void) const { return _data[0]; }
00234 QString DescriptorTagString(void) const;
00235 uint DescriptorLength(void) const { return _data[1]; }
00236
00237 virtual QString toString(void) const;
00238 virtual QString toStringXML(uint indent_level) const;
00239
00240 static desc_list_t Parse(const unsigned char *data, uint len);
00241 static desc_list_t ParseAndExclude(const unsigned char *data, uint len,
00242 int descriptorid);
00243 static desc_list_t ParseOnlyInclude(const unsigned char *data, uint len,
00244 int descriptorid);
00245
00246 static const unsigned char *Find(const desc_list_t &parsed, uint desc_tag);
00247 static desc_list_t FindAll(const desc_list_t &parsed, uint desc_tag);
00248
00249 static const unsigned char *FindBestMatch(
00250 const desc_list_t &parsed, uint desc_tag, QMap<uint,uint> &langPref);
00251 static desc_list_t FindBestMatches(
00252 const desc_list_t &parsed, uint desc_tag, QMap<uint,uint> &langPref);
00253
00254 protected:
00255 const unsigned char *_data;
00256 };
00257
00258
00259 class RegistrationDescriptor : public MPEGDescriptor
00260 {
00261 public:
00262 RegistrationDescriptor(const unsigned char *data, int len = 300) :
00263 MPEGDescriptor(data, len, DescriptorID::registration)
00264 {
00265
00266
00267 if (DescriptorLength() < 4)
00268 _data = NULL;
00269 }
00270
00271 uint FormatIdentifier(void) const
00272 { return (_data[2]<<24) | (_data[3]<<16) | (_data[4]<<8) | _data[5]; }
00273 QString FormatIdentifierString(void) const
00274 {
00275 return QString("") + QChar(_data[2]) + QChar(_data[3]) +
00276 QChar(_data[4]) + QChar(_data[5]);
00277 }
00278 QString toString() const;
00279
00280 private:
00281 static void InitializeDescriptionMap(void);
00282 static QString GetDescription(const QString &fmt);
00283
00284 private:
00285 static QMutex description_map_lock;
00286 static bool description_map_initialized;
00287 static QMap<QString,QString> description_map;
00288 };
00289
00290 class ConditionalAccessDescriptor : public MPEGDescriptor
00291 {
00292 public:
00293 ConditionalAccessDescriptor(const unsigned char *data, int len = 300) :
00294 MPEGDescriptor(data, len, DescriptorID::conditional_access) { }
00295
00296 uint SystemID(void) const { return _data[2] << 8 | _data[3]; }
00297 uint PID(void) const { return (_data[4] & 0x1F) << 8 | _data[5]; }
00298 uint DataSize(void) const { return DescriptorLength() - 4; }
00299 const unsigned char *Data(void) const { return _data+6; }
00300 QString toString() const;
00301 };
00302
00303 class ISO639LanguageDescriptor : public MPEGDescriptor
00304 {
00305 public:
00306 ISO639LanguageDescriptor(const unsigned char *data, int len = 300) :
00307 MPEGDescriptor(data, len, DescriptorID::iso_639_language) { }
00308
00309 const unsigned char* CodeRaw() const { return &_data[2]; }
00310
00311 int LanguageKey(void) const
00312 { return iso639_str3_to_key(&_data[2]); }
00313 QString LanguageString(void) const
00314 { return iso639_key_to_str3(LanguageKey()); }
00315 int CanonicalLanguageKey(void) const
00316 { return iso639_key_to_canonical_key(LanguageKey()); }
00317 QString CanonicalLanguageString(void) const
00318 { return iso639_key_to_str3(CanonicalLanguageKey()); }
00319 QString toString() const;
00320 };
00321
00323 class AVCVideoDescriptor : public MPEGDescriptor
00324 {
00325 public:
00326 AVCVideoDescriptor(const unsigned char *data, int len = 300) :
00327 MPEGDescriptor(data, len, DescriptorID::avc_video) { }
00328
00329
00330
00331
00332 uint ProfileIDC(void) const { return _data[2]; }
00333
00334 bool ConstaintSet0(void) const { return _data[3]&0x80; }
00335
00336 bool ConstaintSet1(void) const { return _data[3]&0x40; }
00337
00338 bool ConstaintSet2(void) const { return _data[3]&0x20; }
00339
00340 uint AVCCompatible(void) const { return _data[3]&0x1f; }
00341
00342 uint LevelIDC(void) const { return _data[4]; }
00343
00344 bool AVCStill(void) const { return _data[5]&0x80; }
00345
00346 bool AVC24HourPicture(void) const { return _data[5]&0x40; }
00347 bool FramePackingSEINotPresentFlag(void)
00348 const { return _data[5]&0x20; }
00349
00350 QString toString() const;
00351 };
00352
00354 class AVCTimingAndHRDDescriptor : public MPEGDescriptor
00355 {
00356 AVCTimingAndHRDDescriptor(const unsigned char *data, int len = 300) :
00357 MPEGDescriptor(data, len, DescriptorID::avc_timing_and_hrd) { }
00358
00359
00360
00361
00362 bool HRDManagementValid(void) const { return _data[2]&0x80; }
00363
00364
00365 bool HasPictureAndTimingInfo(void) const { return _data[2]&0x01;}
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 };
00380
00381 #endif // _MPEG_DESCRIPTORS_H_