/
mpegdescriptors.cpp
749 lines (680 loc) · 25.9 KB
/
mpegdescriptors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// -*- Mode: c++ -*-
// Copyright (c) 2005, Daniel Thor Kristjansson
#include <climits>
#include "sctedescriptors.h"
#include "atscdescriptors.h"
#include "dvbdescriptors.h"
#include "mythmiscutil.h" // for xml_indent
QMutex RegistrationDescriptor::description_map_lock;
bool RegistrationDescriptor::description_map_initialized = false;
QMap<QString,QString> RegistrationDescriptor::description_map;
desc_list_t MPEGDescriptor::Parse(
const unsigned char *data, uint len)
{
desc_list_t tmp;
uint off = 0;
while (off < len)
{
tmp.push_back(data+off);
MPEGDescriptor desc(data+off, len-off);
if (!desc.IsValid())
{
tmp.pop_back();
break;
}
off += desc.size();
}
return tmp;
}
desc_list_t MPEGDescriptor::ParseAndExclude(
const unsigned char *data, uint len, int excluded_descid)
{
desc_list_t tmp;
uint off = 0;
while (off < len)
{
if ((data+off)[0] != excluded_descid)
tmp.push_back(data+off);
MPEGDescriptor desc(data+off, len-off);
if (!desc.IsValid())
{
if ((data+off)[0] != excluded_descid)
tmp.pop_back();
break;
}
off += desc.size();
}
return tmp;
}
#include "mythlogging.h"
desc_list_t MPEGDescriptor::ParseOnlyInclude(
const unsigned char *data, uint len, int excluded_descid)
{
desc_list_t tmp;
uint off = 0;
while (off < len)
{
if ((data+off)[0] == excluded_descid)
tmp.push_back(data+off);
MPEGDescriptor desc(data+off, len-off);
if (!desc.IsValid())
{
if ((data+off)[0] == excluded_descid)
tmp.pop_back();
break;
}
off += desc.size();
}
return tmp;
}
const unsigned char *MPEGDescriptor::Find(const desc_list_t &parsed,
uint desc_tag)
{
for (auto item : parsed)
{
if (item[0] == desc_tag)
return item;
}
return nullptr;
}
desc_list_t MPEGDescriptor::FindAll(const desc_list_t &parsed, uint desc_tag)
{
desc_list_t tmp;
for (auto item : parsed)
{
if (item[0] == desc_tag)
tmp.push_back(item);
}
return tmp;
}
static uint maxPriority(const QMap<uint,uint> &langPrefs)
{
uint max_pri = 0;
for (uint pref : langPrefs)
max_pri = max(max_pri, pref);
return max_pri;
}
const unsigned char *MPEGDescriptor::FindBestMatch(
const desc_list_t &parsed, uint desc_tag, QMap<uint,uint> &langPrefs)
{
uint match_idx = 0;
uint match_pri = UINT_MAX;
int unmatched_idx = -1;
size_t i = (desc_tag == DescriptorID::short_event) ? 0 : parsed.size();
for (; i < parsed.size(); i++)
{
if (DescriptorID::short_event == parsed[i][0])
{
ShortEventDescriptor sed(parsed[i]);
if (!sed.IsValid())
continue;
QMap<uint,uint>::const_iterator it =
langPrefs.find(sed.CanonicalLanguageKey());
if ((it != langPrefs.end()) && (*it < match_pri))
{
match_idx = i;
match_pri = *it;
}
if (unmatched_idx < 0)
unmatched_idx = i;
}
}
if (match_pri != UINT_MAX)
return parsed[match_idx];
if ((desc_tag == DescriptorID::short_event) && (unmatched_idx >= 0))
{
ShortEventDescriptor sed(parsed[unmatched_idx]);
if (sed.IsValid())
{
langPrefs[sed.CanonicalLanguageKey()] = maxPriority(langPrefs) + 1;
return parsed[unmatched_idx];
}
}
return nullptr;
}
desc_list_t MPEGDescriptor::FindBestMatches(
const desc_list_t &parsed, uint desc_tag, QMap<uint,uint> &langPrefs)
{
uint match_pri = UINT_MAX;
int match_key = 0;
int unmatched_idx = -1;
size_t i = (desc_tag == DescriptorID::extended_event) ? 0 : parsed.size();
for (; i < parsed.size(); i++)
{
if (DescriptorID::extended_event == parsed[i][0])
{
ExtendedEventDescriptor eed(parsed[i]);
if (!eed.IsValid())
continue;
QMap<uint,uint>::const_iterator it =
langPrefs.find(eed.CanonicalLanguageKey());
if ((it != langPrefs.end()) && (*it < match_pri))
{
match_key = eed.LanguageKey();
match_pri = *it;
}
if (unmatched_idx < 0)
unmatched_idx = i;
}
}
if ((desc_tag == DescriptorID::extended_event) &&
(match_key == 0) && (unmatched_idx >= 0))
{
ExtendedEventDescriptor eed(parsed[unmatched_idx]);
if (eed.IsValid())
{
langPrefs[eed.CanonicalLanguageKey()] = maxPriority(langPrefs) + 1;
match_key = eed.LanguageKey();
}
}
desc_list_t tmp;
if (match_pri == UINT_MAX)
return tmp;
for (auto j : parsed)
{
if ((DescriptorID::extended_event == desc_tag) &&
(DescriptorID::extended_event == j[0]))
{
ExtendedEventDescriptor eed(j);
if (eed.IsValid() && (eed.LanguageKey() == match_key))
tmp.push_back(j);
}
}
return tmp;
}
#define EMPTY_STR_16 "","","","", "","","","", "","","","", "","","","",
const char *descriptor_tag_strings[256] =
{
/* 0x00 */ "", /* 0x01 */ "",
/* 0x02 */ "Video", /* 0x03 */ "Audio",
/* 0x04 */ "Hierarchy", /* 0x05 */ "Registration",
/* 0x06 */ "Data Stream Alignment", /* 0x07 */ "Target Background Grid",
/* 0x08 */ "Video Window", /* 0x09 */ "Conditional Access",
/* 0x0A */ "ISO-639 Language", /* 0x0B */ "System Clock",
/* 0x0C */ "Multiplex Buffer Utilization", /* 0x0D */ "Copyright",
/* 0x0E */ "Maximum Bitrate", /* 0x0F */ "Private Data Indicator",
/* 0x10 */ "Smooting Buffer", /* 0x11 */ "STD",
/* 0x12 */ "IBP", /* 0x13 */ "DSM-CC Carousel Identifier",
/* 0x14 */ "DSM-CC Association Tag",
/* 0x15 */ "DSM-CC Deferred Association Tag",
/* 0x16 */ "Reserved(0x16)", /* 0x17 */ "DSM-CC NPT Reference",
/* 0x18 */ "DSM-CC NPT Endpoint", /* 0x19 */ "DSM-CC Stream Mode",
/* 0x1A */ "DSM-CC Stream Event", /* 0x1B */ "MPEG-4 Video",
/* 0x1C */ "MPEG-4 Audio", /* 0x1D */ "IOD",
/* 0x1E */ "SL", /* 0x1F */ "FMC",
/* 0x20 */ "External ES ID", /* 0x21 */ "Multimpex Code",
/* 0x22 */ "FMX buffer Size", /* 0x23 */ "Multiplex Buffer",
/* 0x24 */ "Content Labeling", /* 0x25 */ "Metadata Pointer",
/* 0x26 */ "Metadata", /* 0x27 */ "Metadata Std",
/* 0x28 */ "AVC Video", /* 0x29 */ "IPMP DRM",
/* 0x2A */ "AVC Timing & HRD", /* 0x2B */ "AAC Audio",
/* 0x2C */ "Flex Mux Timing", /* 0x2D */ "",
/* 0x2E */ "", /* 0x2F */ "",
/* 0x30-0x3F */ EMPTY_STR_16
/* 0x40 */ "Network Name", /* 0x41 */ "Service List",
/* 0x42 */ "DVB Stuffing", /* 0x43 */ "Satellite Delivery System",
/* 0x44 */ "Cable Delivery System", /* 0x45 */ "VBI Data",
/* 0x46 */ "VBI Teletext", /* 0x47 */ "Bouquet Name",
/* 0x48 */ "Service", /* 0x49 */ "Country Availability",
/* 0x4A */ "Linkage", /* 0x4B */ "NVOD Reference",
/* 0x4C */ "DVB Time-shifted Service",/* 0x4D */ "Short Event",
/* 0x4E */ "Extended Event", /* 0x4F */ "Time-shifted Event",
/* 0x50 */ "Component", /* 0x51 */ "Mosaic",
/* 0x52 */ "Stream Identifier",
/* 0x53 */ "Conditional Access Identifier",
/* 0x54 */ "Content", /* 0x55 */ "Parental Rating",
/* 0x56 */ "Teletext", /* 0x57 */ "Telephone",
/* 0x58 */ "Local Time Offset", /* 0x59 */ "Subtitling",
/* 0x5A */ "Terrestrial Delivery System",
/* 0x5B */ "Multilingual Network Name",
/* 0x5C */ "Multilingual Bouquet Name",
/* 0x5D */ "Multilingual Service Name",
/* 0x5E */ "Multilingual Component",
/* 0x5F */ "Private Data Specifier",
/* 0x60 */ "Service Move", /* 0x61 */ "Short Smoothing Buffer",
/* 0x62 */ "Frequency List", /* 0x63 */ "Partial Transport Stream",
/* 0x64 */ "Data Broadcast", /* 0x65 */ "Scrambling",
/* 0x66 */ "Data Broadcast ID", /* 0x67 */ "Transport Stream",
/* 0x68 */ "DSNG", /* 0x69 */ "PDC",
/* 0x6A */ "AC-3", /* 0x6B */ "Ancillary Data",
/* 0x6C */ "Cell List", /* 0x6D */ "Cell Frequency Link",
/* 0x6E */ "Announcement Support", /* 0x6F */ "Application Signalling",
/* 0x70 */ "Adaptation Field Data", /* 0x71 */ "Service Identifier",
/* 0x72 */ "Service Availability", /* 0x73 */ "Default Authority",
/* 0x74 */ "Related Content", /* 0x75 */ "TVA ID",
/* 0x76 */ "DVB Content Identifier",/* 0x77 */ "Time Slice FEC Identifier",
/* 0x78 */ "ECM Repetition Rate", /* 0x79 */ "DVB-S2 Delivery Identifier",
/* 0x7A */ "E-AC-3", /* 0x7B */ "DTS",
/* 0x7C */ "AAC", /* 0x7D */ "",
/* 0x7E */ "", /* 0x7F */ "",
/* 0x80 */ "ATSC Stuffing", /* 0x81 */ "AC-3 Audio",
/* 0x82 */ "SCTE Frame Rate", /* 0x83 */ "SCTE Extended Video",
/* 0x84 */ "SCTE Component Name", /* 0x85 */ "ATSC Program Identifier",
/* 0x86 */ "Caption Service", /* 0x87 */ "Content Advisory",
/* 0x88 */ "ATSC CA Descriptor", /* 0x89 */ "ATSC Descriptor Tag",
/* 0x8A */ "SCTE CUE Identifier", /* 0x8B */ "",
/* 0x8C */ "TimeStamp", /* 0x8D */ "",
/* 0x8E */ "", /* 0x8F */ "",
/* 0x90 */ "SCTE Frequency Spec", /* 0x91 */ "SCTE Modulation Params",
/* 0x92 */ "SCTE TSID", /* 0x93 */ "SCTE Revision Detection",
/* 0x94 */ "SCTE Two part channel", /* 0x95 */ "SCTE Channel Properties",
/* 0x96 */ "SCTE Daylight Savings", /* 0x97 */ "SCTE AFD",
/* 0x98 */ "", /* 0x99 */ "",
/* 0x9A */ "", /* 0x9B */ "",
/* 0x9C */ "", /* 0x9D */ "",
/* 0x9E */ "", /* 0x9F */ "",
/* 0xA0 */ "Extended Channel Name", /* 0xA1 */ "Service Location",
/* 0xA2 */ "ATSC Time-shifted Service",/*0xA3*/"Component Name",
/* 0xA4 */ "ATSC Data Service", /* 0xA5 */ "ATSC PID Count",
/* 0xA6 */ "ATSC Download",
/* 0xA7 */ "ATSC Multiprotocol Encapsulation",
/* 0xA8 */ "DCC Departing Request", /* 0xA9 */ "DCC Arriving Request",
/* 0xAA */ "ATSC Restrictions Control",/*0xAB*/"ATSC Genre",
/* 0xAC */ "SCTE MAC Address List", /* 0xAD */ "ATSC Private Information",
/* 0xAE */ "ATSC Compatibility Wrap",/* 0xAF */"ATSC Broadcaster Policy",
/* 0xB0 */ "", /* 0xB1 */ "",
/* 0xB2 */ "", /* 0xB3 */ "",
/* 0xB4 */ "", /* 0xB5 */ "",
/* 0xB6 */ "ATSC Content ID", /* 0xB7 */ "",
/* 0xB8 */ "", /* 0xB9 */ "",
/* 0xBA */ "", /* 0xBB */ "",
/* 0xBC */ "", /* 0xBD */ "",
/* 0xBE */ "", /* 0xBF */ "",
/* 0xC0-0xCF */ EMPTY_STR_16
/* 0xD0-0xDF */ EMPTY_STR_16
/* 0xE0-0xEF */ EMPTY_STR_16
/* 0xF0-0xFF */ EMPTY_STR_16
};
static void comma_list_append(QString &str, const QString& extra)
{
if (str.isEmpty())
str = extra;
else
str = str + ", " + extra;
}
QString MPEGDescriptor::DescriptorTagString(void) const
{
QString str = descriptor_tag_strings[DescriptorTag()];
switch (DescriptorTag())
{
case PrivateDescriptorID::dvb_logical_channel_descriptor: /* 0x83 */
comma_list_append(str, "Possibly DVB Logical Channel Descriptor");
break;
case PrivateDescriptorID::dish_event_rights: /* 0x87 */
comma_list_append(str, "Possibly Dishnet Rights");
break;
case PrivateDescriptorID::dish_event_mpaa: /*0x89 */
comma_list_append(str, "Possibly Dishnet MPAA");
break;
case PrivateDescriptorID::dish_event_name: /*0x91 */
comma_list_append(str, "Possibly Dishnet EIT Name");
break;
case PrivateDescriptorID::dish_event_description: /* 0x92 */
comma_list_append(str, "Possibly Dishnet EIT Description");
break;
case PrivateDescriptorID::dish_event_properties: /* 0x94 */
comma_list_append(str, "Possibly Dishnet Properties");
break;
case PrivateDescriptorID::dish_event_vchip: /* 0x95 */
comma_list_append(str, "Possibly Dishnet V-Chip");
break;
case PrivateDescriptorID::dish_event_tags: /* 0x96 */
comma_list_append(str, "Possibly Dishnet Tag");
break;
case PrivateDescriptorID::premiere_content_order: /* 0xF0 */
comma_list_append(str, "Possibly Premiere DE Content Order");
break;
case PrivateDescriptorID::premiere_parental_information: /* 0xF1 */
comma_list_append(str, "Possibly Premiere DE Parental Information");
break;
case PrivateDescriptorID::premiere_content_transmission: /* 0xF2 */
comma_list_append(str, "Possibly Premiere DE Content Transmission");
break;
case PrivateDescriptorID::opentv_channel_list: /* 0xB1 */
comma_list_append(str, "Possibly DVB OpenTV Channel List");
break;
}
if (str.isEmpty())
str = QString("Unknown(%1)").arg(DescriptorTag());
return str;
}
#define SET_STRING(DESC_NAME) do { \
if (IsValid()) { DESC_NAME d(m_data, DescriptorLength()+2); \
if (d.IsValid()) str = d.toString(); } } while (false)
QString MPEGDescriptor::descrDump(const QString &name) const
{
QString str;
str = QString("%1 Descriptor (0x%2) length(%3). Dumping\n")
.arg(name)
.arg(DescriptorTag(),2,16,QChar('0'))
.arg(DescriptorLength());
str.append(hexdump());
return str;
}
QString MPEGDescriptor::toString(void) const
{
return toStringPD(0);
}
QString MPEGDescriptor::toStringPD(uint priv_dsid) const
{
QString str;
if (!IsValid())
{
str = "Invalid Descriptor";
}
else if (DescriptorID::registration == DescriptorTag())
{
SET_STRING(RegistrationDescriptor);
}
else if (DescriptorID::conditional_access == DescriptorTag())
{
SET_STRING(ConditionalAccessDescriptor);
}
else if (DescriptorID::iso_639_language == DescriptorTag())
{
SET_STRING(ISO639LanguageDescriptor);
}
else if (DescriptorID::avc_video == DescriptorTag())
{
SET_STRING(AVCVideoDescriptor);
}
else if (DescriptorID::hevc_video == DescriptorTag())
{
SET_STRING(HEVCVideoDescriptor);
}
else if (DescriptorID::network_name == DescriptorTag())
{
SET_STRING(NetworkNameDescriptor);
}
else if (DescriptorID::service_list == DescriptorTag())
{
SET_STRING(ServiceListDescriptor);
}
else if (DescriptorID::satellite_delivery_system == DescriptorTag())
{
SET_STRING(SatelliteDeliverySystemDescriptor);
}
else if (DescriptorID::cable_delivery_system == DescriptorTag())
{
SET_STRING(CableDeliverySystemDescriptor);
}
else if (DescriptorID::bouquet_name == DescriptorTag())
{
SET_STRING(BouquetNameDescriptor);
}
else if (DescriptorID::service == DescriptorTag())
{
SET_STRING(ServiceDescriptor);
}
else if (DescriptorID::country_availability == DescriptorTag())
{
SET_STRING(CountryAvailabilityDescriptor);
}
//else if (DescriptorID::linkage == DescriptorTag())
//{
// SET_STRING(LinkageDescriptor);
//}
else if (DescriptorID::stream_identifier == DescriptorTag())
{
SET_STRING(StreamIdentifierDescriptor);
}
else if (DescriptorID::teletext == DescriptorTag())
{
SET_STRING(TeletextDescriptor);
}
else if (DescriptorID::terrestrial_delivery_system == DescriptorTag())
{
SET_STRING(TerrestrialDeliverySystemDescriptor);
}
else if (DescriptorID::frequency_list == DescriptorTag())
{
SET_STRING(FrequencyListDescriptor);
}
//else if (DescriptorID::ancillary_data == DescriptorTag())
//{
// SET_STRING(AncillaryDataDescriptor);
//}
else if (DescriptorID::adaptation_field_data == DescriptorTag())
{
SET_STRING(AdaptationFieldDataDescriptor);
}
else if (DescriptorID::default_authority == DescriptorTag())
{
SET_STRING(DefaultAuthorityDescriptor);
}
//
// User Defined DVB descriptors, range 0x80-0xFE
else if (priv_dsid == PrivateDataSpecifierID::BSB1 &&
PrivateDescriptorID::bskyb_lcn_table== DescriptorTag())
{
SET_STRING(BSkyBLCNDescriptor);
}
else if (priv_dsid == PrivateDataSpecifierID::FSAT &&
PrivateDescriptorID::freesat_region_table == DescriptorTag())
{
SET_STRING(FreesatRegionDescriptor);
}
else if (priv_dsid == PrivateDataSpecifierID::FSAT &&
PrivateDescriptorID::freesat_lcn_table== DescriptorTag())
{
SET_STRING(FreesatLCNDescriptor);
}
else if (priv_dsid == PrivateDataSpecifierID::FSAT &&
PrivateDescriptorID::freesat_callsign== DescriptorTag())
{
SET_STRING(FreesatCallsignDescriptor);
}
else if (priv_dsid == PrivateDataSpecifierID::CASEMA &&
PrivateDescriptorID::casema_video_on_demand== DescriptorTag())
{
descrDump("Video on Demand");
}
else if ((priv_dsid == PrivateDataSpecifierID::EACEM ||
priv_dsid == PrivateDataSpecifierID::NORDIG ||
priv_dsid == PrivateDataSpecifierID::ITC ) &&
PrivateDescriptorID::dvb_simulcast_channel_descriptor == DescriptorTag())
{
SET_STRING(DVBSimulcastChannelDescriptor);
}
else if ((priv_dsid == PrivateDataSpecifierID::EACEM ||
priv_dsid == PrivateDataSpecifierID::NORDIG ||
priv_dsid == PrivateDataSpecifierID::ITC ) &&
PrivateDescriptorID::dvb_logical_channel_descriptor == DescriptorTag())
{
SET_STRING(DVBLogicalChannelDescriptor);
}
//
// POSSIBLY UNSAFE ! -- begin
// ATSC/SCTE descriptors, range 0x80-0xFE
else if (DescriptorID::ac3_audio_stream == DescriptorTag())
{
SET_STRING(AudioStreamDescriptor);
}
else if (DescriptorID::caption_service == DescriptorTag())
{
SET_STRING(CaptionServiceDescriptor);
}
else if (DescriptorID::scte_cue_identifier == DescriptorTag())
{
SET_STRING(CueIdentifierDescriptor);
}
else if (DescriptorID::scte_revision_detection == DescriptorTag())
{
SET_STRING(RevisionDetectionDescriptor);
}
else if (DescriptorID::extended_channel_name == DescriptorTag())
{
SET_STRING(ExtendedChannelNameDescriptor);
}
else if (priv_dsid == 0 &&
DescriptorID::component_name == DescriptorTag())
{
SET_STRING(ComponentNameDescriptor);
}
// OpenTV descriptors
else if (PrivateDescriptorID::opentv_channel_list == DescriptorTag())
{
SET_STRING(OpenTVChannelListDescriptor);
}
// POSSIBLY UNSAFE ! -- end
else
{
str = QString("%1 Descriptor (0x%2) length(%3). Dumping\n")
.arg(DescriptorTagString())
.arg(DescriptorTag(),2,16,QChar('0'))
.arg(DescriptorLength());
//for (uint i=0; i<DescriptorLength(); i++)
// str.append(QString(" 0x%1").arg(int(_data[i+2]), 0, 16));
str.append(hexdump());
}
return str;
}
/// Returns XML representation of string the TS Reader XML format.
/// When possible matching http://www.tsreader.com/tsreader/text-export.html
QString MPEGDescriptor::toStringXML(uint level) const
{
QString indent_0 = xml_indent(level);
QString indent_1 = xml_indent(level+1);
QString str;
str += indent_0 + "<Descriptor>\n";
str += indent_1 + QString("<Tag>0x%1</Tag>\n")
.arg(DescriptorTag(),2,16,QChar('0'));
str += indent_1 + QString("<Description>%1</Description>\n")
.arg(DescriptorTagString(),0,16);
str += indent_1 + "<Data>";
for (uint i = 0; i < DescriptorLength(); i++)
{
if (((i%8) == 0) && i)
str += "\n" + indent_1 + " ";
str += QString("0x%1 ").arg(m_data[i+2],2,16,QChar('0'));
}
str += "\n" + indent_1 + "</Data>\n";
str += indent_1 + "<Decoded>" + toString().toHtmlEscaped() + "</Decoded>\n";
str += indent_0 + "</Descriptor>";
return str;
}
// Dump the descriptor in the same format as hexdump -C
QString MPEGDescriptor::hexdump(void) const
{
uint i;
QString str;
QString hex;
QString prt;
for (i=0; i<DescriptorLength(); i++)
{
uint ch = m_data[i+2];
hex.append(QString(" %1").arg(ch, 2, 16, QChar('0')));
prt.append(QString("%1").arg(isprint(ch) ? QChar(ch) : '.'));
if (((i+1) % 8) == 0)
hex.append(" ");
if (((i+1) % 16) == 0)
{
str.append(QString(" %1 %2 |%3|\n")
.arg(i - (i % 16),3,16,QChar('0'))
.arg(hex).arg(prt));
hex.clear();
prt.clear();
}
}
str.append(QString(" %1 %2 |%3|")
.arg(i - (i % 16),3,16,QChar('0'))
.arg(hex,-50,' ').arg(prt));
return str;
}
void RegistrationDescriptor::InitializeDescriptionMap(void)
{
QMutexLocker locker(&description_map_lock);
if (description_map_initialized)
return;
description_map["AC-3"] = "ATSC audio stream A/52";
description_map["AVSV"] = "China A/V Working Group";
description_map["BDC0"] = "Broadcast Data Corporation Software Data Service";
description_map["BSSD"] = "SMPTE 302M-1998 Audio data as specified in (AES3)";
description_map["CAPO"] = "SMPTE 315M-1999 Camera Positioning Information";
description_map["CUEI"] = "SCTE 35 2003, Cable Digital Program Insertion Cueing Message";
description_map["DDED"] = "LGEUS Digital Delivery with encryption and decryption";
description_map["DISH"] = "EchoStar MPEG streams";
description_map["DRA1"] = "Chinese EIS SJ/T11368-2006 DRA digital audio";
description_map["DTS1"] = "DTS Frame size of 512 bytes";
description_map["DTS2"] = "DTS Frame size of 1024 bytes";
description_map["DTS3"] = "DTS Frame size of 2048";
description_map["DVDF"] = "DVD compatible MPEG2-TS";
description_map["ETV1"] = "CableLabs ETV info is present";
description_map["GA94"] = "ATSC program ID A/53";
description_map["GWKS"] = "GuideWorks EPG info";
description_map["HDMV"] = "Blu-Ray A/V for read-only media (H.264 TS)";
description_map["HDMX"] = "Matsushita-TS";
description_map["KLVA"] = "SMPTE RP 217-2001 MXF KLV packets present";
description_map["LU-A"] = "SMPTE RDD-11 HDSDI HD serial/video data";
description_map["MTRM"] = "D-VHS compatible MPEG2-TS";
description_map["NMR1"] = "Nielsen content identifier";
description_map["PAUX"] = "Philips ES containing low-speed data";
description_map["PMSF"] = "MPEG-TS stream modified by STB";
description_map["PRMC"] = "Philips ES containing remote control data";
description_map["SCTE"] = "SCTE 54 2003 Digital Video Service Multiplex and TS for Cable";
description_map["SEN1"] = "ATSC Private Information identifies source of stream";
description_map["SESF"] = "Blu-Ray A/V for ReWritable media (H.264 TS)";
description_map["SPLC"] = "SMPTE Proposed 312M Splice Point compatible TS";
description_map["SVMD"] = "SMPTE Proposed Video Metatdata Dictionary for MPEG2-TS";
description_map["SZMI"] = "ATSC Private Info from Building B";
description_map["TRIV"] = "ATSC Private Info from Triveni Digital";
description_map["TSBV"] = "Toshiba self-encoded H.264 TS";
description_map["TSHV"] = "Sony self-encoded MPEG-TS and private data";
description_map["TSMV"] = "Sony self-encoded MPEG-TS and private data";
description_map["TVG1"] = "TV Guide EPG Data";
description_map["TVG2"] = "TV Guide EPG Data";
description_map["TVG3"] = "TV Guide EPG Data";
description_map["ULE1"] = "IETF RFC4326 compatible MPEG2-TS";
description_map["VC-1"] = "SMPTE Draft RP 227 VC-1 Bitstream Transport Encodings";
for (uint i = 0; i <= 99; i++)
{
description_map[QString("US%1").arg(i, 2, QLatin1Char('0'))] =
"NIMA, Unspecified military application";
}
description_map_initialized = true;
}
QString RegistrationDescriptor::GetDescription(const QString &fmt)
{
InitializeDescriptionMap();
QString ret;
{
QMutexLocker locker(&description_map_lock);
QMap<QString,QString>::const_iterator it = description_map.find(fmt);
if (it != description_map.end())
ret = *it;
}
return ret;
}
QString RegistrationDescriptor::toString() const
{
QString fmt = FormatIdentifierString();
QString msg = QString("Registration Descriptor: '%1' ").arg(fmt);
QString msg2 = GetDescription(fmt);
if (msg2.isEmpty())
msg2 = "Unknown, see http://www.smpte-ra.org/mpegreg/mpegreg.html";
return msg + msg2;
}
QString ConditionalAccessDescriptor::toString() const
{
return QString("Conditional Access: sid(0x%1) pid(0x%2) data_size(%3)")
.arg(SystemID(),0,16).arg(PID(),0,16).arg(DataSize());
}
QString ISO639LanguageDescriptor::toString() const
{
return QString("ISO-639 Language: code(%1) canonical(%2) eng(%3)")
.arg(LanguageString()).arg(CanonicalLanguageString())
.arg(iso639_key_toName(CanonicalLanguageKey()));
}
QString AVCVideoDescriptor::toString() const
{
return QString("AVC Video: IDC prof(%1) IDC level(%2) sets(%3%4%5) "
"compat(%6) still(%7) 24hr(%8) FramePacking(%9)")
.arg(ProfileIDC()).arg(LevelIDC())
.arg(ConstaintSet0()).arg(ConstaintSet1()).arg(ConstaintSet2())
.arg(AVCCompatible()).arg(AVCStill()).arg(AVC24HourPicture())
.arg(FramePackingSEINotPresentFlag());
}
QString HEVCVideoDescriptor::toString() const
{
return QString("HEVC Video: ");
}