-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathFile_Dts.cpp
More file actions
2508 lines (2326 loc) · 94.5 KB
/
Copy pathFile_Dts.cpp
File metadata and controls
2508 lines (2326 loc) · 94.5 KB
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//---------------------------------------------------------------------------
// Pre-compilation
#include "MediaInfo/PreComp.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include "MediaInfo/Setup.h"
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#if defined(MEDIAINFO_DTS_YES)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include "MediaInfo/Audio/File_Dts.h"
#include "ZenLib/Utils.h"
#include "ZenLib/BitStream.h"
#include "MediaInfo/TimeCode.h"
#include "MediaInfo/MediaInfo_Config_MediaInfo.h"
#if MEDIAINFO_EVENTS
#include "MediaInfo/MediaInfo_Events.h"
#endif //MEDIAINFO_EVENTS
#include <algorithm>
using namespace ZenLib;
using namespace std;
//---------------------------------------------------------------------------
namespace MediaInfoLib
{
//***************************************************************************
// Infos
//***************************************************************************
//---------------------------------------------------------------------------
static constexpr int64u CHUNK_AUPR_HDR=0x415550522D484452LL;
static constexpr int64u CHUNK_BUILDVER=0x4255494C44564552LL;
static constexpr int64u CHUNK_CORESSMD=0x434F524553534D44LL;
static constexpr int64u CHUNK_DTSHDHDR=0x4454534844484452LL;
static constexpr int64u CHUNK_EXTSS_MD=0x45585453535F4D44LL;
static constexpr int64u CHUNK_FILEINFO=0x46494C45494E464FLL;
static constexpr int64u CHUNK_TIMECODE=0x54494D45434F4445LL;
static constexpr int64u CHUNK_STRMDATA=0x5354524D44415441LL;
//---------------------------------------------------------------------------
void Merge_FillTimeCode(File__Analyze& In, const string& Prefix, const TimeCode& TC_Time, float FramesPerSecondF, bool DropFrame, TimeCode::rounding Rounding=TimeCode::Nearest, int32u Frequency=0);
//---------------------------------------------------------------------------
static const float TC_Frame_Rate_Table[]=
{
// Value 0 means "not indicated"
24/1.001,
24,
25,
30/1.001, // Drop
30/1.001,
30, // Drop
30,
};
static constexpr size_t TC_Frame_Rate_Table_Size=sizeof(TC_Frame_Rate_Table)/sizeof(*TC_Frame_Rate_Table);
static bool TC_Frame_Rate_IsDrop(int8u Value)
{
return Value==4 || Value==6;
}
//---------------------------------------------------------------------------
static const int16u DTS_HD_RefClockCode[]=
{
32000,
44100,
48000,
};
static constexpr size_t DTS_HD_RefClockCode_Size=sizeof(DTS_HD_RefClockCode)/sizeof(*DTS_HD_RefClockCode);
//---------------------------------------------------------------------------
static const int16u CRC_CCIT_Table[256]=
{
0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770,
0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1,
0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662,
0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3,
0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554,
0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5,
0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446,
0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7,
0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338,
0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9,
0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A,
0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB,
0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C,
0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D,
0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E,
0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F,
0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1,
0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760,
0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3,
0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672,
0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5,
0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544,
0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7,
0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456,
0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9,
0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328,
0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB,
0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A,
0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D,
0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C,
0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F,
0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E,
};
uint16_t Dts_CRC_CCIT_Compute(const uint8_t* Buffer, size_t Size)
{
uint16_t C = 0xFFFF;
const uint8_t *End = Buffer + Size;
while (Buffer < End)
C = (C >> 8) ^ CRC_CCIT_Table[((uint8_t)C) ^ *Buffer++];
return C;
}
//---------------------------------------------------------------------------
static const char* DTS_FrameType[]=
{
"Termination",
"Normal",
};
//---------------------------------------------------------------------------
static const int32u DTS_SamplingRate[]=
{
0, 8000, 16000, 32000, 0, 0, 11025, 22050,
44100, 0, 0, 12000, 24000, 48000, 96000, 192000,
};
//---------------------------------------------------------------------------
static const int32u DTS_BitRate[]=
{
32000, 56000, 64000, 96000, 112000, 128000, 192000, 224000,
256000, 320000, 384000, 448000, 512000, 576000, 640000, 754500,
960000, 1024000, 1152000, 1280000, 1344000, 1408000, 1411200, 1472000,
1509750, 1920000, 2048000, 3072000, 3840000, 0, 0, 0,
};
//---------------------------------------------------------------------------
static const int8u DTS_Channels[]=
{
1, 2, 2, 2, 2, 3, 3, 4,
4, 5, 6, 6, 6, 7, 8, 8,
};
//---------------------------------------------------------------------------
static const int8u DTS_Resolution[]=
{16, 20, 24, 24};
//---------------------------------------------------------------------------
const char* DTS_ChannelPositions[16]=
{
"Front: C",
"Front: C C",
"Front: L R",
"Front: L R",
"Front: L R",
"Front: L C R",
"Front: L R, Back: C",
"Front: L C R, Back: C",
"Front: L R, Side: L R",
"Front: L C R, Side: L R",
"Front: L C C R, Side: L R",
"Front: L C R, Side: L R",
"Front: L R, Side: L R, Back: L R",
"Front: L C R, Side: L R, Back: L R",
"Front: L R, Side: L R, Back: L C C R",
"Front: L C R, Side: L R, Back: L C R",
};
//---------------------------------------------------------------------------
const char* DTS_ChannelPositions2[16]=
{
"1/0/0",
"2/0/0",
"2/0/0",
"2/0/0",
"2/0/0",
"3/0/0",
"2/1/0",
"3/1/0",
"2/2/0",
"3/2/0",
"4/2/0",
"3/2/0",
"2/2/2",
"3/2/2",
"2/2/4",
"3/2/3",
};
//---------------------------------------------------------------------------
static const char* DTS_ChannelLayout[16]=
{
"M",
"M M",
"L R",
"L R",
"Lt Rt",
"C L R",
"L R Cs",
"C L R Cs",
"L R Ls Rs",
"C L R Ls Rs",
"Cl Cr L R Ls Rs",
"C L R Ls Rs",
"C L R Ls Rs Lrs Rrs",
"C L R Ls Rs Lrs Rrs",
"L R Ls Rs Rls Cs Cs Rrs",
"C L R Ls Rs Rls Cs Rrs",
};
//---------------------------------------------------------------------------
static const char* DTS_ExtensionAudioDescriptor[]=
{
"Channel Extension",
"Reserved",
"Frequency Extension",
"Channel Extension + Frequency Extension",
"",
"",
"",
"",
};
//---------------------------------------------------------------------------
std::string DTS_HD_SpeakerActivityMask (int16u SpeakerActivityMask, bool AddCs=false, bool AddLrsRrs=false)
{
std::string Text;
if ((SpeakerActivityMask&0x0003)==0x0003)
Text+="Front: L C R";
else
{
if (SpeakerActivityMask&0x0001)
Text+="Front: C";
if (SpeakerActivityMask&0x0002)
Text+="Front: L R";
}
if (SpeakerActivityMask&0x0004)
Text+=", Side: L R";
if (SpeakerActivityMask&0x0010 || AddCs)
Text+=", Back: C";
if ((SpeakerActivityMask&0x00A0)==0x00A0)
Text+=", High: L C R";
else
{
if (SpeakerActivityMask&0x0020 || AddLrsRrs)
Text+=", High: L R";
if (SpeakerActivityMask&0x0080)
Text+=", High: C";
}
if (SpeakerActivityMask&0x0800)
Text+=", Side: L R";
if (SpeakerActivityMask&0x0040)
Text+=", Back: L R";
if (SpeakerActivityMask&0x0100)
Text+=", TopCtrSrrd";
if (SpeakerActivityMask&0x0200)
Text+=", Ctr: L R";
if (SpeakerActivityMask&0x0400)
Text+=", Wide: L R";
if (SpeakerActivityMask&0x2000)
Text+=", HiSide: L R";
if ((SpeakerActivityMask&0xC000)==0x0C000)
Text+=", HiRear: L C R";
else
{
if (SpeakerActivityMask&0x4000)
Text+=", HiRear: C";
if (SpeakerActivityMask&0x8000)
Text+=", HiRear: L R";
}
if (SpeakerActivityMask&0x0008)
Text+=", LFE";
if (SpeakerActivityMask&0x1000)
Text+=", LFE2";
return Text;
}
//---------------------------------------------------------------------------
std::string DTS_HD_SpeakerActivityMask2 (int16u SpeakerActivityMask, bool AddCs=false, bool AddLrsRrs=false)
{
std::string Text;
if ((SpeakerActivityMask&0x0003)==0x0003)
Text+="3";
else
{
if (SpeakerActivityMask&0x0001)
Text+="1";
else if (SpeakerActivityMask&0x0002)
Text+="2";
else
Text+="0";
}
if (SpeakerActivityMask&0x0004)
Text+="/2";
else if ((SpeakerActivityMask&0x0840)==0x0000)
Text+="/0";
if (SpeakerActivityMask&0x0010 || AddCs)
Text+="/1";
else if ((SpeakerActivityMask&0x0840)==0x0000)
Text+="/0";
if ((SpeakerActivityMask&0x00A0)==0x00A0)
Text+=".3";
else
{
if (SpeakerActivityMask&0x0020 || AddLrsRrs)
Text+=".2";
if (SpeakerActivityMask&0x0080)
Text+=".2";
}
if (SpeakerActivityMask&0x0800)
Text+="/2";
if (SpeakerActivityMask&0x0040)
Text+="/2";
if (SpeakerActivityMask&0x0100)
Text+=".1";
if (SpeakerActivityMask&0x0200)
Text+=".2";
if (SpeakerActivityMask&0x0400)
Text+=".2";
if (SpeakerActivityMask&0x2000)
Text+=".2";
if ((SpeakerActivityMask&0xC000)==0x0C000)
Text+=".3";
else
{
if (SpeakerActivityMask&0x4000)
Text+=".1";
if (SpeakerActivityMask&0x8000)
Text+=".2";
}
if (SpeakerActivityMask&0x0008)
Text+=".1";
if (SpeakerActivityMask&0x1000)
Text+=".1";
return Text;
}
//---------------------------------------------------------------------------
std::string DTS_HD_SpeakerActivityMask_ChannelLayout (int16u SpeakerActivityMask, bool AddCs=false, bool AddLrsRrs=false)
{
std::string Text;
if (SpeakerActivityMask==1)
return "M";
if (SpeakerActivityMask&0x0001)
Text+=" C";
if (SpeakerActivityMask&0x0002)
Text+=" L R";
if (SpeakerActivityMask&0x0004)
Text+=" Ls Rs";
if (SpeakerActivityMask&0x0008)
Text+=" LFE";
if (SpeakerActivityMask&0x0010 || AddCs)
Text+=" Cs";
if (SpeakerActivityMask&0x0020)
Text+=" Lh Rh";
if (SpeakerActivityMask&0x0040 || AddLrsRrs)
Text+=" Lsr Rsr";
if (SpeakerActivityMask&0x0080)
Text+=" Ch";
if (SpeakerActivityMask&0x0100)
Text+=" Oh";
if (SpeakerActivityMask&0x0200)
Text+=" Lc Rc";
if (SpeakerActivityMask&0x0400)
Text+=" Lw Rw";
if (SpeakerActivityMask&0x0800)
Text+=" Lss Rss";
if (SpeakerActivityMask&0x1000)
Text+=" LFE2";
if (SpeakerActivityMask&0x2000)
Text+=" Lhs Rhs";
if (SpeakerActivityMask&0x4000)
Text+=" Chr";
if (SpeakerActivityMask&0x8000)
Text+=" Lhr";
if (!Text.empty())
Text.erase(0, 1);
return Text;
}
//---------------------------------------------------------------------------
static const char* DTS_HD_TypeDescriptor[]=
{
"Music",
"Effects",
"Dialog",
"Commentary",
"Visually Impaired",
"Hearing Impaired",
"Isolated Music Object",
"Music and Effects",
"Dialog and Commentary",
"Effects and Commentary",
"Isolated Music Object and Commentary",
"Isolated Music Object and Effects",
"Karaoke",
"Music, Effects, Dialog",
"Complete Audio Presentation",
"",
};
//---------------------------------------------------------------------------
static int32u DTS_HD_MaximumSampleRate[]=
{
8000,
16000,
32000,
64000,
128000,
22050,
44100,
88200,
176400,
352800,
12000,
24000,
48000,
96000,
192000,
384000,
};
//---------------------------------------------------------------------------
static int8u DTS_HD_SamplePerFrames_Factor[]=
{
0,
1,
2,
3,
4,
1,
2,
3,
4,
5,
0,
1,
2,
3,
4,
5,
};
//---------------------------------------------------------------------------
enum extension
{
Ext_Padding4,
Ext_Core,
Ext_LBR,
Ext_X96,
Ext_XLL,
Ext_XXCH,
Ext_XCh,
Ext_XBR,
Ext_Aux,
Ext_Max
};
static int32u DTS_Extension_Mapping[]=
{
0x00000000,
0x02b09261,
0x0A801921,
0x1D95F262,
0x41A29547,
0x47004A03,
0x5A5A5A5A,
0x655E315E,
0x9A1105A0,
};
static_assert(sizeof(DTS_Extension_Mapping)/sizeof(decltype(*DTS_Extension_Mapping))==Ext_Max, "");
static const char* DTS_Extension_Names[]=
{
"Padding",
"Core",
"LBR (Low Bit Rate)",
"X96 (96 kHz / 24-bit)",
"XLL (LossLess)",
"XXCH (More Than 5.1 Channels)",
"XCh (6.1 Channels)",
"XBR (Extended Bit Rate)",
"Aux",
};
static_assert(sizeof(DTS_Extension_Names)/sizeof(decltype(*DTS_Extension_Names))==Ext_Max, "");
static size_t DTS_Extension_Index_Get(int32u SyncWord)
{
for (size_t i=0; i<Ext_Max; i++)
if (SyncWord==DTS_Extension_Mapping[i])
return i;
return (size_t)-1;
}
//***************************************************************************
// Constructor/Destructor
//***************************************************************************
//---------------------------------------------------------------------------
File_Dts::File_Dts()
:File_Dts_Common()
{
//Configuration
ParserName="Dts";
#if MEDIAINFO_EVENTS
ParserIDs[0]=MediaInfo_Parser_Dts;
StreamIDs_Width[0]=0;
#endif //MEDIAINFO_EVENTS
#if MEDIAINFO_TRACE
Trace_Layers_Update(8); //Stream
#endif //MEDIAINFO_TRACE
MustSynchronize=true;
Buffer_TotalBytes_FirstSynched_Max=64*1024;
PTS_DTS_Needed=true;
StreamSource=IsStream;
//In
Frame_Count_Valid=0;
//Buffer
Save_Buffer=NULL;
//Temp
HD_size=0;
Primary_Frame_Byte_Size=0;
HD_SpeakerActivityMask=(int16u)-1;
channel_arrangement=(int8u)-1;
sample_frequency=(int8u)-1;
bit_rate=(int8u)-1;
lfe_effects=(int8u)-1;
bits_per_sample=(int8u)-1;
ExtensionAudioDescriptor=(int8u)-1;
HD_BitResolution=(int8u)-1;
HD_BitResolution_Real=(int8u)-1;
HD_MaximumSampleRate=(int8u)-1;
HD_MaximumSampleRate_Real=(int8u)-1;
HD_TotalNumberChannels=(int8u)-1;
HD_ExSSFrameDurationCode=(int8u)-1;
AuxiliaryData=false;
ExtendedCoding=false;
ES=false;
Core_Exists=false;
}
//***************************************************************************
// Streams management
//***************************************************************************
//---------------------------------------------------------------------------
void File_Dts::Streams_Fill_Extension()
{
bool AddCs=false;
//bool AddLrsRrs=false;
//bool AddX=false;
if (HD_TotalNumberChannels!=(int8u)-1)
{
int8u i=HD_TotalNumberChannels;
int8u Core_Core_Channels=DTS_Channels[Core_Core_AMODE];
if (Presence[presence_Core_Core] && Core_Core_LFF)
Core_Core_Channels++;
if (Presence[presence_Core_XXCH] && i<Core_Core_Channels+Core_XXCH_nuNumChSetsInXXCH)
{
//switch (Core_XXCH_nuNumChSetsInXXCH)
//{
// case 1: AddCs=true; break;
// case 2: AddLrsRrs=true; break;
// default: AddX=true;
//}
//i=Core_Core_Channels+Core_XXCH_nuNumChSetsInXXCH;
}
if (Presence[presence_Core_XCh] && i<Core_Core_Channels+Core_XCh_AMODE)
{
//AddCs=true;
//i=Core_Core_Channels+Core_XCh_AMODE;
}
if (!Presence[presence_Core_XCh] && ES && i<Core_Core_Channels+1)
{
AddCs=true;
i=Core_Core_Channels+1; // Must count the Matrixed additional channels
}
Data[Channels].push_back(Ztring::ToZtring(i));
}
else
{
Data[Channels].push_back(Ztring());
}
if (HD_SpeakerActivityMask!=(int16u)-1) // && !AddX)
{
Data[ChannelPositions].push_back(DTS_HD_SpeakerActivityMask(HD_SpeakerActivityMask, AddCs).c_str()); //AddLrsRrs
Data[ChannelPositions2].push_back(DTS_HD_SpeakerActivityMask2(HD_SpeakerActivityMask, AddCs).c_str()); //AddLrsRrs
Data[ChannelLayout].push_back(DTS_HD_SpeakerActivityMask_ChannelLayout(HD_SpeakerActivityMask, AddCs).c_str()); //AddLrsRrs
}
else
{
Data[ChannelPositions].push_back(Ztring());
Data[ChannelPositions2].push_back(Ztring());
Data[ChannelLayout].push_back(Ztring());
}
if (HD_BitResolution_Real!=(int8u)-1)
{
Data[BitDepth].push_back(Ztring::ToZtring(HD_BitResolution_Real));
}
else if (HD_BitResolution!=(int8u)-1)
{
Data[BitDepth].push_back(Ztring::ToZtring(HD_BitResolution));
}
else
{
Data[BitDepth].push_back(Ztring());
}
if (HD_MaximumSampleRate_Real!=(int8u)-1)
{
Data[SamplingRate].push_back(Ztring::ToZtring(DTS_HD_MaximumSampleRate[HD_MaximumSampleRate_Real]));
Data[SamplesPerFrame].push_back(Ztring::ToZtring(HD_ExSSFrameDurationCode<<(7+DTS_HD_SamplePerFrames_Factor[HD_MaximumSampleRate_Real])));
}
else if (HD_MaximumSampleRate!=(int8u)-1)
{
Data[SamplingRate].push_back(Ztring::ToZtring(DTS_HD_MaximumSampleRate[HD_MaximumSampleRate]));
Data[SamplesPerFrame].push_back(Ztring::ToZtring(HD_ExSSFrameDurationCode<<(7+DTS_HD_SamplePerFrames_Factor[HD_MaximumSampleRate])));
}
else
{
Data[SamplingRate].push_back(Ztring());
Data[SamplesPerFrame].push_back(Ztring());
}
Data[BitRate].push_back(Ztring::ToZtring(BitRate_Get(true), 0));
Data[BitRate_Mode].push_back(__T("CBR"));
Data[Compression_Mode].push_back(__T("Lossy"));
}
//---------------------------------------------------------------------------
void File_Dts::Streams_Fill_Core_ES()
{
Streams_Fill_Core();
if (!ES && !Presence[presence_Core_XCh])
return;
int8u Channels_Before=Data[Channels][Data[Channels].size()-1].To_int8u();
Data[Channels].pop_back();
Data[ChannelPositions].pop_back();
Data[ChannelPositions2].pop_back();
Data[ChannelLayout].pop_back();
Data[Channels].push_back(Ztring::ToZtring(Channels_Before+(Presence[presence_Core_XCh]?Core_XCh_AMODE:1)));
if (Core_Core_AMODE == 9 && (!Presence[presence_Core_XCh] || Core_XCh_AMODE == 1))
{
Data[ChannelPositions].push_back(Ztring(__T("Front: L C R, Side: L R, Back: C"))+(Core_Core_LFF?__T(", LFE"):__T("")));
Data[ChannelPositions2].push_back(Ztring(__T("3/2/1"))+(Core_Core_LFF?__T(".1"):__T("")));
Data[ChannelLayout].push_back(Ztring(__T("C L R Ls Rs Cs"))+(Core_Core_LFF?__T(" LFE"):__T("")));
}
else if (Core_Core_AMODE == 9 && (Presence[presence_Core_XCh] && Core_XCh_AMODE == 2))
{
Data[ChannelPositions].push_back(Ztring(__T("Front: L C R, Side: L R, Back: L R"))+(Core_Core_LFF?__T(", LFE"):__T("")));
Data[ChannelPositions2].push_back(Ztring(__T("3/2/2"))+(Core_Core_LFF?__T(".1"):__T("")));
Data[ChannelLayout].push_back(Ztring(__T("C L R Ls Rs Lrs Rrs"))+(Core_Core_LFF?__T(" LFE"):__T("")));
}
else
{
Ztring Debug=__T("Debug, Core_Core_AMODE=")+Ztring::ToZtring(Core_Core_AMODE);
if(Presence[presence_Core_XCh])
Debug +=__T(", Core_XCh_AMODE=")+Ztring::ToZtring(Core_XCh_AMODE);
Debug +=__T(", Core_Core_LFF=")+Ztring::ToZtring(Core_Core_LFF);
Data[ChannelPositions].push_back(Debug);
Data[ChannelPositions2].push_back(Debug);
Data[ChannelLayout].push_back(Debug);
}
}
//---------------------------------------------------------------------------
void File_Dts::Streams_Fill_Core(bool With96k)
{
Ztring Core_BitRate;
if (bit_rate<25)
Core_BitRate=Ztring::ToZtring(BitRate_Get(), 0);
else if (bit_rate==29)
Core_BitRate=__T("Open");
else
Core_BitRate=__T("Unknown");
if (Core_Core_AMODE<16)
{
Data[Channels].push_back(Ztring::ToZtring(DTS_Channels[Core_Core_AMODE]+(Core_Core_LFF?1:0)));
Data[ChannelPositions].push_back(Ztring().From_UTF8(DTS_ChannelPositions[Core_Core_AMODE])+(Core_Core_LFF?__T(", LFE"):__T("")));
Data[ChannelPositions2].push_back(Ztring().From_UTF8(DTS_ChannelPositions2[Core_Core_AMODE])+(Core_Core_LFF?__T(".1"):__T(".0")));
Data[ChannelLayout].push_back(Ztring().From_UTF8(DTS_ChannelLayout[Core_Core_AMODE])+(Core_Core_LFF?__T(" LFE"):__T("")));
}
else
{
Data[Channels].push_back(__T("User Defined"));
Data[ChannelPositions].push_back(Ztring(__T("User Defined"))+(Core_Core_LFF?__T(", LFE"):__T("")));
Data[ChannelPositions2].push_back(Ztring(__T("User Defined"))+(Core_Core_LFF?__T(".1"):__T(".0")));
Data[ChannelLayout].push_back(Ztring(__T("User Defined"))+(Core_Core_LFF?__T(" LFE"):__T("")));
}
Data[BitDepth].push_back(Ztring::ToZtring(DTS_Resolution[bits_per_sample]));
Data[SamplingRate].push_back(Ztring::ToZtring(DTS_SamplingRate[sample_frequency]*(1+With96k)));
Data[SamplesPerFrame].push_back(Ztring::ToZtring(Number_Of_PCM_Sample_Blocks*32*(1+With96k)));
Data[BitRate].push_back(Core_BitRate);
Data[BitRate_Mode].push_back(__T("CBR"));
Data[Compression_Mode].push_back(__T("Lossy"));
}
//---------------------------------------------------------------------------
void File_Dts::Streams_Fill()
{
Fill(Stream_General, 0, General_Format, "DTS");
Stream_Prepare(Stream_Audio);
Fill(Stream_Audio, 0, Audio_Format, "DTS");
// IMAX DTS:X
if (Presence[presence_Extended_IMAX])
{
Data[Profiles].push_back(__T("IMAX"));
Streams_Fill_Extension();
Data[ChannelPositions].back()+=__T(", Objects");
Data[ChannelPositions2].back()+=__T(".?");
Data[ChannelLayout].back()+=__T(" Objects");
Data[BitRate].pop_back();
Data[BitRate_Mode].pop_back();
Data[BitRate].push_back(__T("Unknown"));
Data[BitRate_Mode].push_back(__T("VBR"));
if (Presence[presence_Extended_XLL])
{
Data[Compression_Mode].pop_back();
Data[Compression_Mode].push_back(__T("Lossless"));
}
}
// DTS:X
if (Presence[presence_Extended_X])
{
Data[Profiles].push_back(__T("X"));
Streams_Fill_Extension();
Data[ChannelPositions].back()+=__T(", Objects");
Data[ChannelPositions2].back()+=__T(".?");
Data[ChannelLayout].back()+=__T(" Objects");
Data[BitRate].pop_back();
Data[BitRate_Mode].pop_back();
Data[BitRate].push_back(__T("Unknown"));
Data[BitRate_Mode].push_back(__T("VBR"));
if (Presence[presence_Extended_XLL])
{
Data[Compression_Mode].pop_back();
Data[Compression_Mode].push_back(__T("Lossless"));
}
}
// DTS Express
if (Presence[presence_Extended_LBR])
{
Data[Profiles].push_back(__T("Express"));
Streams_Fill_Extension();
}
// DTS-HD MA
if (Presence[presence_Extended_XLL])
{
Data[Profiles].push_back(__T("MA"));
Streams_Fill_Extension();
Data[BitRate].pop_back();
Data[BitRate_Mode].pop_back();
Data[Compression_Mode].pop_back();
Data[BitRate].push_back(__T("Unknown"));
Data[BitRate_Mode].push_back(__T("VBR"));
Data[Compression_Mode].push_back(__T("Lossless"));
}
// DTS-HD XXCH
if (Presence[presence_Extended_XXCH])
{
Data[Profiles].push_back(__T("XXCH"));
Streams_Fill_Extension();
}
// DTS-HD XCh
if (Presence[presence_Extended_XCh])
{
Data[Profiles].push_back(__T("XCH"));
Streams_Fill_Extension();
}
// DTS-HD XBR
if (Presence[presence_Extended_XBR])
{
Data[Profiles].push_back(__T("XBR"));
Streams_Fill_Extension();
}
// DTS-HD 96/24
if (Presence[presence_Extended_X96])
{
Data[Profiles].push_back(__T("X96"));
Streams_Fill_Extension();
}
// DTS XXCH
if (Presence[presence_Core_XXCH])
{
Data[Profiles].push_back(__T("XXCh"));
Streams_Fill_Core();
}
// DTS 96/24
if (Presence[presence_Core_X96])
{
Data[Profiles].push_back(__T("x96"));
Streams_Fill_Core(true);
}
// DTS XCh
if (Presence[presence_Core_XCh])
{
Data[Profiles].push_back(__T("ES Discrete"));
Streams_Fill_Core_ES();
}
// ES
if (ES)
{
Data[Profiles].push_back(__T("ES Matrix"));
Streams_Fill_Core_ES();
}
// Core
if (Presence[presence_Core_Core])
{
Data[Profiles].push_back(__T("Core"));
Streams_Fill_Core();
}
// Cleanup up
for (auto& Item : Data)
{
Item.Separator_Set(0, __T(" / "));
if (Item.size()>1)
{
bool IsNotSame=false;
for (size_t i=1; i<Item.size(); ++i)
if (Item[i]!=Item[0])
IsNotSame=true;
if (!IsNotSame)
Item.resize(1);
}
}
if (Data[Profiles].size()==1 && Data[Profiles][0]==__T("Core"))
Data[Profiles].clear(); //Core is the default one
// Filling
bool LegacyStreamDisplay=MediaInfoLib::Config.LegacyStreamDisplay_Get();
Fill(Stream_Audio, 0, Audio_Format_Profile, Data[Profiles].Read());
Fill(Stream_Audio, 0, Audio_Codec, (Data[Profiles].Find(__T("MA"))!=string::npos || Data[Profiles].Find(__T("HRA"))!=string::npos)?"DTS-HD":"DTS");
Fill(Stream_General, 0, General_Format_Profile, Retrieve(Stream_Audio, 0, Audio_Format_Profile));
Fill(Stream_Audio, 0, Audio_Channel_s_, LegacyStreamDisplay?Data[Channels].Read():Data[Channels].Read(0));
Fill(Stream_Audio, 0, Audio_ChannelPositions, LegacyStreamDisplay?Data[ChannelPositions].Read():Data[ChannelPositions].Read(0));
Fill(Stream_Audio, 0, Audio_ChannelPositions_String2, LegacyStreamDisplay?Data[ChannelPositions2].Read():Data[ChannelPositions2].Read(0));
Fill(Stream_Audio, 0, Audio_ChannelLayout, LegacyStreamDisplay?Data[ChannelLayout].Read():Data[ChannelLayout].Read(0));
Fill(Stream_Audio, 0, Audio_BitDepth, LegacyStreamDisplay?Data[BitDepth].Read():Data[BitDepth].Read(0));
Fill(Stream_Audio, 0, Audio_SamplingRate, LegacyStreamDisplay?Data[SamplingRate].Read():Data[SamplingRate].Read(0));
Fill(Stream_Audio, 0, Audio_SamplesPerFrame, LegacyStreamDisplay?Data[SamplesPerFrame].Read():Data[SamplesPerFrame].Read(0));
Fill(Stream_Audio, 0, Audio_BitRate, LegacyStreamDisplay?Data[BitRate].Read():(Data[BitRate].Read(0)==__T("Unknown")?Ztring():Data[BitRate].Read(0)));
Fill(Stream_Audio, 0, Audio_BitRate_Mode, LegacyStreamDisplay?Data[BitRate_Mode].Read():Data[BitRate_Mode].Read(0), true);
Fill(Stream_General, 0, General_OverallBitRate_Mode, Retrieve(Stream_Audio, 0, Audio_BitRate_Mode));
Fill(Stream_Audio, 0, Audio_Compression_Mode, LegacyStreamDisplay?Data[Compression_Mode].Read():Data[Compression_Mode].Read(0), true);
// Cleanup up
for (size_t Pos=0; Pos<10; ++Pos)
Data[Pos].clear();
}
//---------------------------------------------------------------------------
void File_Dts::Streams_Finish()
{
Fill(Stream_Audio, 0, Audio_Format_Settings_Endianness, BigEndian?"Big":"Little", Unlimited, true, true);
Fill(Stream_Audio, 0, Audio_Format_Settings_Mode, Word?"16":"14", Unlimited, true, true);
if (FrameInfo.PTS!=(int64u)-1 && FrameInfo.PTS>PTS_Begin)
{
Fill(Stream_Audio, 0, Audio_Duration, ((float64)(FrameInfo.PTS-PTS_Begin))/1000000, 0, true);
float64 SamplesPerFrame=Retrieve(Stream_Audio, 0, Audio_SamplesPerFrame).To_float64();
float64 SamplingRate=Retrieve(Stream_Audio, 0, Audio_SamplingRate).To_float64();
if (SamplesPerFrame && SamplingRate)
Fill(Stream_Audio, 0, Audio_FrameCount, ((float64)(FrameInfo.PTS-PTS_Begin))/1000000000/(SamplesPerFrame/SamplingRate), 0, true);
}
}
//***************************************************************************
// Buffer - File header
//***************************************************************************
//---------------------------------------------------------------------------
bool File_Dts_Common::FileHeader_Begin()
{
//Must have enough buffer for having header
if (Buffer_Size<4)
return false; //Must wait for more data
//False positives detection: Detect WAV files, the parser can't detect it easily, there is only 70 bytes of beginning for saying WAV
switch (CC4(Buffer))
{
case 0x52494646 : //"RIFF"
case 0x000001FD : //MPEG-PS private
Finish("DTS");
return false;
default : ;
}
//All should be OK...
if (!Frame_Count_Valid)
Frame_Count_Valid=Config->ParseSpeed>=0.3?32:(IsSub?1:2);
return true;
}
//---------------------------------------------------------------------------
void File_Dts_Common::FileHeader_Parse()
{
//DTSHDHDR header
//https://www.atsc.org/wp-content/uploads/2015/03/Non-Real-Time-Content-Delivery.pdf
if (IsSub || CC8(Buffer)!=CHUNK_DTSHDHDR || CC4(Buffer+8))
return;
int64u StreamSize{ static_cast<int64u>(-1) };
int16u Bitw_Stream_Metadata{};
bool Header_Parsed{ false };
int64u Num_Samples_Orig_Audio_At_Max_Fs{ 0 };
int32u Num_Frames_Total{};
int32u TimeStamp{};
int32u Max_Sample_Rate_Hz{ 0 };
int32u Ext_Ss_Avg_Bit_Rate_Kbps{ 0 };
int32u Ext_Ss_Peak_Bit_Rate_Kbps{ 0 };
int16u Core_Ss_Bit_Rate_Kbps{ 0 };
int16u Samples_Per_Frame_At_Max_Fs{ 0 };
int16u Codec_Delay_At_Max_Fs{ 0 };
int8u RefClockCode{};
int8u TC_Frame_Rate{ static_cast<int8u>(-1) };
while (StreamSize==-1 && Element_Size-Element_Offset>=16)
{
int64u Name, Size;
Element_Begin1("Element");
Element_Begin1("Header");
Get_C8 (Name, "Name");
Get_B8 (Size, "Size");
Element_End0();
Ztring ToShow;
for (int i=0; i<8; i++)
ToShow.append(1, (ZenLib::Char)((Name>>(56-i*8)))&0xFF);
Element_Name(ToShow);
if (Name!=CHUNK_STRMDATA && Size>Element_Size-Element_Offset)
{
Element_End0();
Element_WaitForMoreData();
return;
}
auto End=Element_Offset+Size;
switch (Name)
{
case CHUNK_AUPR_HDR:
{
int16u Bitw_Aupres_Metadata;
Skip_B1( "Audio_Pres_Index");
Get_B2 (Bitw_Aupres_Metadata, "Bitw_Aupres_Metadata");
Skip_Flags(Bitw_Aupres_Metadata, 3, "Presence of a LBR coding componen");
Skip_Flags(Bitw_Aupres_Metadata, 2, "Presence of a lossless coding component");