Welcome to mirror list, hosted at ThFree Co, Russian Federation.

File_Ancillary.cpp « Multiple « MediaInfo « MediaInfo « thirdparty « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c7c221a322bb3a2f60bb4508c4e494a04ac2ac8 (plain)
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
/*  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_ANCILLARY_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Multiple/File_Ancillary.h"
#if defined(MEDIAINFO_CDP_YES)
    #include "MediaInfo/Text/File_Cdp.h"
#endif
#if MEDIAINFO_EVENTS
    #include "MediaInfo/MediaInfo_Events.h"
#endif //MEDIAINFO_EVENTS
#if defined(MEDIAINFO_TIMECODE_YES)
    #include "MediaInfo/Multiple/File_Gxf_TimeCode.h"
#endif
#if defined(MEDIAINFO_ARIBSTDB24B37_YES)
    #include "MediaInfo/Text/File_AribStdB24B37.h"
#endif
#if defined(MEDIAINFO_SDP_YES)
    #include "MediaInfo/Text/File_Sdp.h"
#endif
#include "MediaInfo/MediaInfo_Config_MediaInfo.h"
#include <cstring>
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
namespace MediaInfoLib
{
//---------------------------------------------------------------------------

//***************************************************************************
// Infos
//***************************************************************************

const char* Ancillary_DataID(int8u DataID, int8u SecondaryDataID)
{
    switch (DataID)
    {
        case 0x00 : return "Undefined";
        case 0x08 :
                    switch (SecondaryDataID)
                    {
                        case 0x0C : return "MPEG-2 Recoding Information";       //SMPTE ST 353
                        default   : return "(Reserved for 8-bit applications)";
                    }
                    break;
        case 0x40 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 :                                             //SMPTE ST 305
                        case 0x02 : return "SDTI";                              //SMPTE ST 348
                        case 0x04 :                                             //SMPTE ST 427
                        case 0x05 :                                             //SMPTE ST 427
                        case 0x06 : return "Link Encryption Key";               //SMPTE ST 427
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x41 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "Payload identifier";                //SMPTE ST 352
                        case 0x05 : return "Bar Data";                          //SMPTE ST 2016
                        case 0x06 : return "Pan-Scan Information";              //SMPTE ST 2016
                        case 0x07 : return "ANSI/SCTE 104 Messages";            //SMPTE ST 2010
                        case 0x08 : return "DVB/SCTE VBI Data";                 //SMPTE ST 2031
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x43 :
                    switch (SecondaryDataID)
                    {
                        case 0x02 : return "SDP";                               //OP-47 SDP, also RDD 8
                        case 0x03 : return "Multipacket";                       //OP-47 Multipacket, also RDD 8
                        case 0x05 : return "Acquisition Metadata";              //RDD 18
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x44 :
                    switch (SecondaryDataID)
                    {
                        case 0x44 : return "ISAN or UMID";                      //SMPTE RP 223
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x45 :
                    //SMPTE 2020-1-2008
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "Audio Metadata - No association";
                        case 0x02 : return "Audio Metadata - Channels 1/2";
                        case 0x03 : return "Audio Metadata - Channels 3/4";
                        case 0x04 : return "Audio Metadata - Channels 5/6";
                        case 0x05 : return "Audio Metadata - Channels 7/8";
                        case 0x06 : return "Audio Metadata - Channels 9/10";
                        case 0x07 : return "Audio Metadata - Channels 11/12";
                        case 0x08 : return "Audio Metadata - Channels 13/14";
                        case 0x09 : return "Audio Metadata - Channels 15/16";
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x46 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "Two-Frame Marker";                  //SMPTE RP 2051
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x50 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "WSS";                               //RDD 8
                        default   : return "(Reserved)";
                    }
                    break;
        case 0x5F :
                    switch (SecondaryDataID&0xF0)
                    {
                        case 0xD0 : return "ARIB STD B37";                      //ARIB STD B37
                        default   : return "(Reserved)";
                    }
                    break;
        case 0x60 :
                    switch (SecondaryDataID)
                    {
                        case 0x60 : return "ATC";                               //SMPTE RP 188 / SMPTE ST 12-2
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x61 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "CDP";                               //SMPTE 334
                        case 0x02 : return "CEA-608";                           //SMPTE 334
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x62 :
                    switch (SecondaryDataID)
                    {
                        case 0x01 : return "Program description";               //SMPTE 334
                        case 0x02 : return "Data broadcast";                    //SMPTE 334
                        case 0x03 : return "VBI data";                          //SMPTE 334
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x64 :
                    switch (SecondaryDataID)
                    {
                        case 0x64 : return "LTC";                               //SMPTE RP 196
                        case 0x6F : return "VITC";                              //SMPTE RP 196
                        default   : return "(Internationally registered)";
                    }
                    break;
        case 0x80 : return "Marked for deletion";
        case 0x84 : return "Data end marker";
        case 0x88 : return "Data start marker";
        default   :
                     if (DataID<=0x03)
                    return "(Reserved)";
                else if (DataID<=0x0F)
                    return "(Reserved for 8-bit applications)";
                else if (DataID<=0x3F)
                    return "(Reserved)";
                else if (DataID<=0x4F)
                    return "(Internationally registered)";
                else if (DataID<=0x5F)
                    return "(Reserved)";
                else if (DataID<=0x7F)
                    return "(Internationally registered)";
                else if (DataID<=0x83)
                    return "(Reserved)";
                else if (DataID<=0x87)
                    return "(Reserved)";
                else if (DataID<=0x9F)
                    return "(Reserved)";
                else if (DataID<=0xBF)
                    return "(Internationally registered)";
                else if (DataID<=0xCF)
                    return "User application";
                else
                    return "(Internationally registered)";
    }
}

//***************************************************************************
// Constructor/Destructor
//***************************************************************************

//---------------------------------------------------------------------------
File_Ancillary::File_Ancillary()
:File__Analyze()
{
    //Configuration
    ParserName=__T("Ancillary");
    PTS_DTS_Needed=true;

    //In
    WithTenBit=false;
    WithChecksum=false;
    HasBFrames=false;
    InDecodingOrder=false;
    LineNumber_IsSecondField=false;
    AspectRatio=0;
    FrameRate=0;
    LineNumber=(int32u)-1;
    #if defined(MEDIAINFO_CDP_YES)
        Cdp_Parser=NULL;
    #endif //defined(MEDIAINFO_CDP_YES)
    #if defined(MEDIAINFO_ARIBSTDB24B37_YES)
        AribStdB34B37_Parser=NULL;
    #endif //defined(MEDIAINFO_ARIBSTDB24B37_YES)
    #if defined(MEDIAINFO_SDP_YES)
        Sdp_Parser=NULL;
    #endif //defined(MEDIAINFO_SDP_YES)
}

//---------------------------------------------------------------------------
File_Ancillary::~File_Ancillary()
{
    #if defined(MEDIAINFO_CDP_YES)
        delete Cdp_Parser; //Cdp_Parser=NULL;
        for (size_t Pos=0; Pos<Cdp_Data.size(); Pos++)
            delete Cdp_Data[Pos]; //Cdp_Data[Pos]=NULL;
    #endif //defined(MEDIAINFO_CDP_YES)
    #if defined(MEDIAINFO_AFDBARDATA_YES)
        for (size_t Pos=0; Pos<AfdBarData_Data.size(); Pos++)
            delete AfdBarData_Data[Pos]; //AfdBarData_Data[Pos]=NULL;
    #endif //defined(MEDIAINFO_AFDBARDATA_YES)
    #if defined(MEDIAINFO_ARIBSTDB24B37_YES)
        delete AribStdB34B37_Parser; //AribStdB34B37_Parser=NULL;
    #endif //defined(MEDIAINFO_ARIBSTDB24B37_YES)
    #if defined(MEDIAINFO_SDP_YES)
        delete Sdp_Parser; //Sdp_Parser=NULL;
    #endif //defined(MEDIAINFO_SDP_YES)
}

//---------------------------------------------------------------------------
void File_Ancillary::Streams_Finish()
{
    #if defined(MEDIAINFO_CDP_YES)
        if (Cdp_Parser && !Cdp_Parser->Status[IsFinished] && Cdp_Parser->Status[IsAccepted])
        {
            Finish(Cdp_Parser);
            for (size_t StreamPos=0; StreamPos<Cdp_Parser->Count_Get(Stream_Text); StreamPos++)
            {
                Merge(*Cdp_Parser, Stream_Text, StreamPos, StreamPos);
                Ztring MuxingMode=Cdp_Parser->Retrieve(Stream_Text, StreamPos, "MuxingMode");
                Fill(Stream_Text, StreamPos, "MuxingMode", __T("Ancillary data / ")+MuxingMode, true);
            }

            Ztring LawRating=Cdp_Parser->Retrieve(Stream_General, 0, General_LawRating);
            if (!LawRating.empty())
                Fill(Stream_General, 0, General_LawRating, LawRating, true);
            Ztring Title=Cdp_Parser->Retrieve(Stream_General, 0, General_Title);
            if (!Title.empty() && Retrieve(Stream_General, 0, General_Title).empty())
                Fill(Stream_General, 0, General_Title, Title);
        }
    #endif //defined(MEDIAINFO_CDP_YES)

    #if defined(MEDIAINFO_ARIBSTDB24B37_YES)
        if (AribStdB34B37_Parser && !AribStdB34B37_Parser->Status[IsFinished] && AribStdB34B37_Parser->Status[IsAccepted])
        {
            Finish(AribStdB34B37_Parser);
            for (size_t StreamPos=0; StreamPos<AribStdB34B37_Parser->Count_Get(Stream_Text); StreamPos++)
            {
                Merge(*AribStdB34B37_Parser, Stream_Text, StreamPos, StreamPos);
                Ztring MuxingMode=AribStdB34B37_Parser->Retrieve(Stream_Text, StreamPos, "MuxingMode");
                Fill(Stream_Text, StreamPos, "MuxingMode", __T("Ancillary data / ")+MuxingMode, true);
            }
        }
    #endif //defined(MEDIAINFO_ARIBSTDB24B37_YES)

    #if defined(MEDIAINFO_SDP_YES)
        if (Sdp_Parser && !Sdp_Parser->Status[IsFinished] && Sdp_Parser->Status[IsAccepted])
        {
            Finish(Sdp_Parser);
            for (size_t StreamPos=0; StreamPos<Sdp_Parser->Count_Get(Stream_Text); StreamPos++)
            {
                Merge(*Sdp_Parser, Stream_Text, StreamPos, StreamPos);
                Ztring MuxingMode=Sdp_Parser->Retrieve(Stream_General, 0, General_Format);
                Fill(Stream_Text, StreamPos, "MuxingMode", __T("Ancillary data / OP-47 / ")+MuxingMode, true);
            }
        }
    #endif //defined(MEDIAINFO_SDP_YES)
}

//***************************************************************************
// Buffer - Synchro
//***************************************************************************

//---------------------------------------------------------------------------
bool File_Ancillary::Synchronize()
{
    //Synchronizing
    while (Buffer_Offset+6<=Buffer_Size && ( Buffer[Buffer_Offset  ]!=0x00
                                         ||  Buffer[Buffer_Offset+ 1]!=0xFF
                                         ||  Buffer[Buffer_Offset+ 2]!=0xFF))
        Buffer_Offset++;

    if (!Status[IsAccepted])
    {
        Accept();

        Fill(Stream_General, 0, General_Format, "Ancillary");
    }

    //Synched is OK
    return true;
}

//---------------------------------------------------------------------------
bool File_Ancillary::Synched_Test()
{
    Synchronize(); //This is not always in synch directly, there may be some garbage

    //Must have enough buffer for having header
    if (Buffer_Offset+6>Buffer_Size)
        return false;

    //Quick test of synchro
    if (CC3(Buffer+Buffer_Offset)!=0x00FFFF)
        Synched=false;

    //We continue
    return true;
}

//***************************************************************************
// Buffer - Global
//***************************************************************************

//---------------------------------------------------------------------------
void File_Ancillary::Read_Buffer_Continue()
{
    if (!Cdp_Data.empty() && AspectRatio && FrameRate)
    {
        ((File_Cdp*)Cdp_Parser)->AspectRatio=AspectRatio;
        for (size_t Pos=0; Pos<Cdp_Data.size(); Pos++)
        {
            if (Cdp_Parser->PTS_DTS_Needed)
                Cdp_Parser->FrameInfo.DTS=FrameInfo.DTS-(Cdp_Data.size()-Pos)*FrameInfo.DUR;
            Open_Buffer_Continue(Cdp_Parser, Cdp_Data[Pos]->Data, Cdp_Data[Pos]->Size);
            delete Cdp_Data[Pos]; //Cdp_Data[0]=NULL;
        }
        Cdp_Data.clear();
    }

    if (Element_Size==0)
    {
        #if defined(MEDIAINFO_AFDBARDATA_YES)
            //Keeping only one, TODO: parse it without video stream
            for (size_t Pos=1; Pos<AfdBarData_Data.size(); Pos++)
                delete AfdBarData_Data[Pos]; //AfdBarData_Data[0]=NULL;
            if (!AfdBarData_Data.empty())
                AfdBarData_Data.resize(1);
        #endif //defined(MEDIAINFO_AFDBARDATA_YES)

        return;
    }

    if (!Status[IsAccepted] && !MustSynchronize)
        Accept();
}

//---------------------------------------------------------------------------
void File_Ancillary::Read_Buffer_AfterParsing()
{
    Buffer_Offset=Buffer_Size; //This is per frame

    Frame_Count++;
    Frame_Count_InThisBlock++;
    if (Frame_Count_NotParsedIncluded!=(int64u)-1)
        Frame_Count_NotParsedIncluded++;
}

//---------------------------------------------------------------------------
void File_Ancillary::Read_Buffer_Unsynched()
{
    #if defined(MEDIAINFO_CDP_YES)
        for (size_t Pos=0; Pos<Cdp_Data.size(); Pos++)
            delete Cdp_Data[Pos]; //Cdp_Data[Pos]=NULL;
        Cdp_Data.clear();
        if (Cdp_Parser)
            Cdp_Parser->Open_Buffer_Unsynch();
    #endif //defined(MEDIAINFO_CDP_YES)
    #if defined(MEDIAINFO_AFDBARDATA_YES)
        for (size_t Pos=0; Pos<AfdBarData_Data.size(); Pos++)
            delete AfdBarData_Data[Pos]; //AfdBarData_Data[Pos]=NULL;
        AfdBarData_Data.clear();
    #endif //defined(MEDIAINFO_AFDBARDATA_YES)
    #if defined(MEDIAINFO_ARIBSTDB24B37_YES)
        if (AribStdB34B37_Parser)
            AribStdB34B37_Parser->Open_Buffer_Unsynch();
    #endif //defined(MEDIAINFO_ARIBSTDB24B37_YES)
    #if defined(MEDIAINFO_SDP_YES)
        if (Sdp_Parser)
            Sdp_Parser->Open_Buffer_Unsynch();
    #endif //defined(MEDIAINFO_SDP_YES)
    AspectRatio=0;
}

//***************************************************************************
// Buffer - Per element
//***************************************************************************

//---------------------------------------------------------------------------
void File_Ancillary::Header_Parse()
{
    //Parsing
    if (MustSynchronize)
    {
        if (WithTenBit)
        {
            Skip_L2(                                            "Ancillary data flag");
            Skip_L2(                                            "Ancillary data flag");
            Skip_L2(                                            "Ancillary data flag");
        }
        else
        {
            Skip_L1(                                            "Ancillary data flag");
            Skip_L1(                                            "Ancillary data flag");
            Skip_L1(                                            "Ancillary data flag");
        }
    }
    Get_L1 (DataID,                                             "Data ID");
    if (WithTenBit)
        Skip_L1(                                                "Parity+Unused"); //even:1, odd:2
    Get_L1 (SecondaryDataID,                                    "Secondary Data ID"); Param_Info1(Ancillary_DataID(DataID, SecondaryDataID));
    if (WithTenBit)
        Skip_L1(                                                "Parity+Unused"); //even:1, odd:2
    Get_L1 (DataCount,                                          "Data count");
    if (WithTenBit)
        Skip_L1(                                                "Parity+Unused"); //even:1, odd:2

    //Test (in some container formats, Cheksum is present sometimes)
    bool WithChecksum_Temp=WithChecksum;
    if (!MustSynchronize && !WithChecksum && (size_t)((3+DataCount+1)*(WithTenBit?2:1))==Buffer_Size)
        WithChecksum_Temp=true;

    //Filling
    Header_Fill_Code((((int16u)DataID)<<8)|SecondaryDataID, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
    Header_Fill_Size(((MustSynchronize?3:0)+3+DataCount+(WithChecksum_Temp?1:0))*(WithTenBit?2:1));
}

//---------------------------------------------------------------------------
void File_Ancillary::Data_Parse()
{
    Element_Info1(Ancillary_DataID(DataID, SecondaryDataID));

    //Buffer
    int8u* Payload=new int8u[DataCount];
    Element_Begin1("Raw data");
    for(int8u Pos=0; Pos<DataCount; Pos++)
    {
        Get_L1 (Payload[Pos],                                   "Data");
        if (WithTenBit)
            Skip_L1(                                            "Parity+Unused"); //even:1, odd:2
    }

    //Parsing
    if (WithChecksum)
        Skip_L1(                                                "Checksum");
    if (WithTenBit)
        Skip_L1(                                                "Parity+Unused"); //even:1, odd:2
    Element_End0();

    FILLING_BEGIN();
        switch (DataID)
        {
            case 0x08 :
                        switch (SecondaryDataID)
                        {
                            case 0x0C : // (from SMPTE ST 353)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "MPEG-2 Recoding Information");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 353");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x40 :
                        switch (SecondaryDataID)
                        {
                            case 0x01 : // (from SMPTE ST 305)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "SDTI");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 305");
                                        }
                                        break;
                            case 0x02 : // (from SMPTE ST 348)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "SDTI");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 348");
                                        }
                                        break;
                            case 0x04 :
                            case 0x05 :
                            case 0x06 : // (from SMPTE ST 427)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Link Encryption Key");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 427");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x41 :
                        switch (SecondaryDataID)
                        {
                            case 0x01 : //SMPTE ST 352
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Payload identifier");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 352");
                                        }
                                        break;
                            case 0x05 : //Bar Data (from SMPTE 2016-3), saving data for future use
                                        #if defined(MEDIAINFO_AFDBARDATA_YES)
                                        {
                                            buffered_data* AfdBarData=new buffered_data;
                                            AfdBarData->Data=new int8u[(size_t)DataCount];
                                            std::memcpy(AfdBarData->Data, Payload, (size_t)DataCount);
                                            AfdBarData->Size=(size_t)DataCount;
                                            AfdBarData_Data.push_back(AfdBarData);
                                        }
                                        #endif //MEDIAINFO_AFDBARDATA_YES
                                        break;
                            case 0x06 : //SMPTE ST 2016
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Pan-Scan Information");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 2016");
                                        }
                                        break;
                            case 0x07 : //SMPTE ST 2010
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "ANSI/SCTE 104 Messages");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 2010");
                                        }
                                        break;
                            case 0x08 : //SMPTE ST 2031
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "DVB/SCTE VBI Data");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 2031");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x43 :
                        switch (SecondaryDataID)
                        {
                            case 0x02 : //OP-47 SDP, also RDD 8
                                        /*
                                        if (Count_Get(Stream_Text)==0)
                                        {
                                            Stream_Prepare(Stream_Text);
                                            Fill(Stream_Text, StreamPos_Last, Text_Format, "Teletext Subtitle");
                                            Fill(Stream_Text, StreamPos_Last, Text_MuxingMode, "Ancillary data / OP-47 / SDP");
                                        }
                                        */
                                        #if defined(MEDIAINFO_SDP_YES)
                                        if (Sdp_Parser==NULL)
                                        {
                                            Sdp_Parser=new File_Sdp;
                                            Open_Buffer_Init(Sdp_Parser);
                                        }
                                        if (!Sdp_Parser->Status[IsFinished])
                                        {
                                            if (Sdp_Parser->PTS_DTS_Needed)
                                                Sdp_Parser->FrameInfo=FrameInfo;
                                            Open_Buffer_Continue(Sdp_Parser, Payload, (size_t)DataCount);
                                        }
                                        #endif //defined(MEDIAINFO_SDP_YES)
                                        break;
                            case 0x03 : //OP-47 Multipacket, also RDD 8
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / OP-47 / Multipacket");
                                        }
                                        break;
                            case 0x05 : //RDD 18
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Acquisition Metadata");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / RDD 18");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x44 :
                        switch (SecondaryDataID)
                        {
                            case 0x44 : //SMPTE RP 223
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            switch (DataCount)
                                            {
                                                case 0x19: Fill(Stream_Other, StreamPos_Last, Other_Format, "ISAN"); break;
                                                case 0x20:
                                                case 0x40: Fill(Stream_Other, StreamPos_Last, Other_Format, "UMID"); break;
                                            }

                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE RP 223");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x45 : // (from SMPTE 2020-1)
                        switch (SecondaryDataID)
                        {
                            case 0x01 : //No association
                            case 0x02 : //Channel pair 1/2
                            case 0x03 : //Channel pair 3/4
                            case 0x04 : //Channel pair 5/6
                            case 0x05 : //Channel pair 7/8
                            case 0x06 : //Channel pair 9/10
                            case 0x07 : //Channel pair 11/12
                            case 0x08 : //Channel pair 13/14
                            case 0x09 : //Channel pair 15/16
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Audio Metadata");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 2020");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x46 :
                        switch (SecondaryDataID)
                        {
                            case 0x01 : // (from SMPTE ST 2051)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Two-Frame Marker");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 2051");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x50 :
                        switch (SecondaryDataID)
                        {
                            case 0x01: //RDD 8
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "WSS"); //TODO: inject it in the video stream when a sample is available
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / RDD 8");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x5F : // (from ARIB STD-B37)
                        if ((SecondaryDataID&0xF0)==0xD0) //Digital Closed Caption
                        {
                            #if defined(MEDIAINFO_ARIBSTDB24B37_YES)
                            if (AribStdB34B37_Parser==NULL)
                            {
                                AribStdB34B37_Parser=new File_AribStdB24B37;
                                ((File_AribStdB24B37*)AribStdB34B37_Parser)->IsAncillaryData=true;
                                ((File_AribStdB24B37*)AribStdB34B37_Parser)->ParseCcis=true;
                                Open_Buffer_Init(AribStdB34B37_Parser);
                            }
                            if (!AribStdB34B37_Parser->Status[IsFinished])
                            {
                                if (AribStdB34B37_Parser->PTS_DTS_Needed)
                                    AribStdB34B37_Parser->FrameInfo=FrameInfo;
                                Open_Buffer_Continue(AribStdB34B37_Parser, Payload, (size_t)DataCount);
                            }
                            #endif //defined(MEDIAINFO_ARIBSTDB24B37_YES)
                        }
                        else
                            if (Count_Get(Stream_Other)==0)
                            {
                                Stream_Prepare(Stream_Other);
                                Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                            }
                        break;
            case 0x60 :
                        switch (SecondaryDataID)
                        {
                            case 0x60 : // (from SMPTE RP 188 / SMPTE ST 12-2)
                                        // Time code ATC
                                        #if defined(MEDIAINFO_TIMECODE_YES)
                                        {
                                        File_Gxf_TimeCode Parser;
                                        Parser.IsAtc=true;
                                        Open_Buffer_Init(&Parser);
                                        Open_Buffer_Continue(&Parser, Payload, (size_t)DataCount);

                                        bool Exists=false;
                                        if (LineNumber!=(int32u)-1)
                                            for (size_t Pos=0; Pos<Count_Get(Stream_Other); Pos++)
                                            {
                                                if (__T("Line")+Ztring::ToZtring(LineNumber)==Retrieve(Stream_Other, Pos, Other_ID)
                                                 && ((!LineNumber_IsSecondField && Retrieve(Stream_Other, Pos, "IsSecondField").empty()) || (LineNumber_IsSecondField && !Retrieve(Stream_Other, Pos, "IsSecondField").empty()))
                                                 && Parser.Settings==Retrieve(Stream_Other, Pos, Other_TimeCode_Settings).To_UTF8())
                                                    Exists=true;
                                            }
                                        else
                                            for (size_t Pos=0; Pos<Count_Get(Stream_Other); Pos++)
                                            {
                                                if (Parser.Settings==Retrieve(Stream_Other, Pos, Other_TimeCode_Settings).To_UTF8())
                                                    Exists=true;
                                            }
                                        if (!Exists)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Type, "Time code");
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "SMPTE ATC");
                                            Fill(Stream_Other, StreamPos_Last, Other_TimeCode_FirstFrame, Parser.TimeCode_FirstFrame);
                                            Fill(Stream_Other, StreamPos_Last, Other_TimeCode_Settings, Parser.Settings);
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE RP 188");
                                            if (LineNumber!=(int32u)-1)
                                                Fill(Stream_Other, StreamPos_Last, Other_ID, __T("Line")+Ztring::ToZtring(LineNumber));
                                            if (LineNumber_IsSecondField)
                                                Fill(Stream_Other, StreamPos_Last, "IsSecondField", "Yes");
                                        }
                                        }
                                        #endif //defined(MEDIAINFO_TIMECODE_YES)
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x61 : //Defined data services (from SMPTE 334-1)
                        switch (SecondaryDataID)
                        {
                            case 0x01 : //CDP (from SMPTE 334-1)
                                        #if defined(MEDIAINFO_CDP_YES)
                                        {
                                            if (Cdp_Parser==NULL)
                                            {
                                                Cdp_Parser=new File_Cdp;
                                                Open_Buffer_Init(Cdp_Parser);
                                            }
                                            Demux(Payload, (size_t)DataCount, ContentType_MainStream);
                                            if (InDecodingOrder || (!HasBFrames && AspectRatio && FrameRate))
                                            {
                                                if (!Cdp_Parser->Status[IsFinished])
                                                {
                                                    if (Cdp_Parser->PTS_DTS_Needed)
                                                        Cdp_Parser->FrameInfo.DTS=FrameInfo.DTS;
                                                    ((File_Cdp*)Cdp_Parser)->AspectRatio=AspectRatio;
                                                    Open_Buffer_Continue(Cdp_Parser, Payload, (size_t)DataCount);
                                                }
                                            }
                                            else
                                            {
                                                //Saving data for future use
                                                buffered_data* Cdp=new buffered_data;
                                                Cdp->Data=new int8u[(size_t)DataCount];
                                                std::memcpy(Cdp->Data, Payload, (size_t)DataCount);
                                                Cdp->Size=(size_t)DataCount;
                                                Cdp_Data.push_back(Cdp);
                                            }
                                        }
                                        #endif //MEDIAINFO_CDP_YES
                                        break;
                            case 0x02 : //CEA-608 (from SMPTE 334-1)
                                        if (Count_Get(Stream_Text)==0)
                                        {
                                            Stream_Prepare(Stream_Text);
                                            Fill(Stream_Text, StreamPos_Last, Text_Format, "CEA-608");
                                            Fill(Stream_Text, StreamPos_Last, Text_MuxingMode, "Ancillary data / SMPTE 334");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x62 : //Variable-format data services (from SMPTE 334-1)
                        switch (SecondaryDataID)
                        {
                            case 0x01 : //Program description (from SMPTE 334-1),
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Program description");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 334");
                                        }
                                        break;
                            case 0x02 : //Data broadcast (from SMPTE 334-1)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "Data broadcast");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 334");
                                        }
                                        break;
                            case 0x03 : //VBI data (from SMPTE 334-1)
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "VBI data");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE ST 334");
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            case 0x64 :
                        switch (SecondaryDataID)
                        {
                            case 0x64 : // (from SMPTE RP 196)
                                        // LTC in HANC space
                                        {
                                        bool Exists=false;
                                        if (LineNumber!=(int32u)-1)
                                            for (size_t Pos=0; Pos<Count_Get(Stream_Other); Pos++)
                                            {
                                                if (__T("Line")+Ztring::ToZtring(LineNumber)==Retrieve(Stream_Other, Pos, Other_ID))
                                                    Exists=true;
                                            }
                                        else
                                            if (Count_Get(Stream_Other)!=0)
                                                Exists=true;
                                        if (!Exists)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Type, "Time code");
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "LTC");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE RP 196");
                                            if (LineNumber!=(int32u)-1)
                                                Fill(Stream_Other, StreamPos_Last, Other_ID, __T("Line")+Ztring::ToZtring(LineNumber));
                                        }
                                        }
                                        break;
                            case 0x7F : // (from SMPTE RP 196)
                                        // VITC in HANC space
                                        {
                                        bool Exists=false;
                                        if (LineNumber!=(int32u)-1)
                                            for (size_t Pos=0; Pos<Count_Get(Stream_Other); Pos++)
                                            {
                                                if (__T("Line")+Ztring::ToZtring(LineNumber)==Retrieve(Stream_Other, Pos, Other_ID))
                                                    Exists=true;
                                            }
                                        else
                                            if (Count_Get(Stream_Other)!=0)
                                                Exists=true;
                                        if (!Exists)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Type, "Time code");
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, "VITC");
                                            Fill(Stream_Other, StreamPos_Last, Other_MuxingMode, "Ancillary data / SMPTE RP 196");
                                            if (LineNumber!=(int32u)-1)
                                                Fill(Stream_Other, StreamPos_Last, Other_ID, __T("Line")+Ztring::ToZtring(LineNumber));
                                        }
                                        }
                                        break;
                            default   :
                                        if (Count_Get(Stream_Other)==0)
                                        {
                                            Stream_Prepare(Stream_Other);
                                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                                        }
                        }
                        break;
            default   :
                        if (Count_Get(Stream_Other)==0)
                        {
                            Stream_Prepare(Stream_Other);
                            Fill(Stream_Other, StreamPos_Last, Other_Format, Ztring().From_CC1(DataID)+__T('-')+Ztring().From_CC1(SecondaryDataID));
                        }
        }
    FILLING_END();

    delete[] Payload; //Payload=NULL
}

//***************************************************************************
// C++
//***************************************************************************

} //NameSpace

#endif //MEDIAINFO_ANCILLARY_YES