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

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

//---------------------------------------------------------------------------
#include "MediaInfo/Audio/File_Pcm.h"
#if MEDIAINFO_DEMUX
    #include "MediaInfo/MediaInfo_Config_MediaInfo.h"
#endif //MEDIAINFO_DEMUX
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

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

//---------------------------------------------------------------------------
const char* Smpte_St0302_ChannelsPositions(int8u Channels)
{
    switch (Channels)
    {
        case  2 : return "Front: L R";                                  //2 channels
        case  4 : return "Front: L C R, LFE";                           //4 channels
        case  6 : return "Front: L C R, Side: L R, LFE";                //6 channels
        case  8 : return "Front: L C R, Side: L R, Back: L R, LFE";     //8 channels
        default : return "";
    }
}

//---------------------------------------------------------------------------
const char* Smpte_St0302_ChannelsPositions2(int8u Channels)
{
    switch (Channels)
    {
        case  2 : return "2/0/0.0";                                     //2 channels
        case  4 : return "3/0/0.1";                                     //4 channels
        case  6 : return "3/2/0.1";                                     //6 channels
        case  8 : return "3/2/2.1";                                     //8 channels
        default : return "";
    }
}

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

//---------------------------------------------------------------------------
File_Pcm::File_Pcm()
{
    //Configuration
    ParserName=__T("PCM");
    #if MEDIAINFO_TRACE
        Trace_Layers_Update(8); //Stream
    #endif //MEDIAINFO_TRACE
    IsRawStream=true;
    PTS_DTS_Needed=true;

    //In
    Frame_Count_Valid=4;
    BitDepth=0;
    BitDepth_Significant=0;
    Channels=0;
    SamplingRate=0;
    Endianness='\0';
    Sign='\0';
    #if MEDIAINFO_DEMUX
    Frame_Count_Valid_Demux=0;
    #endif //MEDIAINFO_DEMUX
}

//***************************************************************************
// Streams management
//***************************************************************************

//---------------------------------------------------------------------------
void File_Pcm::Streams_Fill()
{
    if (Count_Get(Stream_Audio)==0)
    {
        Stream_Prepare(Stream_Audio);
        Fill(Stream_Audio, 0, Audio_Format, "PCM");
        Fill(Stream_Audio, 0, Audio_Codec, "PCM");
    }

    //Filling
    Ztring Firm, ITU;
         if (Codec==__T("EVOB"))             {Firm=__T("");      Endianness='B';            Sign='S';}                        //PCM Signed 16 bits Big Endian, Interleavement is for 2 samples*2 channels L0-1/L0-0/R0-1/R0-0/L1-1/L1-0/R1-1/R1-0/L0-2/R0-2/L1-2/R1-2, http://wiki.multimedia.cx/index.php?title=PCM
    else if (Codec==__T("VOB"))              {Firm=__T("");      Endianness='B';            Sign='S';}                        //PCM Signed 16 bits Big Endian, Interleavement is for 2 samples*2 channels L0-1/L0-0/R0-1/R0-0/L1-1/L1-0/R1-1/R1-0/L0-2/R0-2/L1-2/R1-2, http://wiki.multimedia.cx/index.php?title=PCM
    else if (Codec==__T("M2TS"))             {Firm=__T("");      Endianness='B';            Sign='S';}                        //PCM Signed         Big Endian
    else if (Codec==__T("A_PCM/INT/BIG"))    {Firm=__T("");      Endianness='B';}
    else if (Codec==__T("A_PCM/INT/LITTLE")) {Firm=__T("");      Endianness='L';}
    else if (Codec==__T("A_PCM/INT/FLOAT"))  {Firm=__T("");      Endianness='B';            Sign='F';}
    else if (Codec==__T("fl32"))             {  if (!Endianness) Endianness='B'; if (!Sign) Sign='F'; BitDepth=32;}
    else if (Codec==__T("fl64"))             {  if (!Endianness) Endianness='B'; if (!Sign) Sign='F'; BitDepth=64;}
    else if (Codec==__T("in24"))             {  if (!Endianness) Endianness='B'; if (!Sign) Sign='U'; BitDepth=24;}
    else if (Codec==__T("in32"))             {  if (!Endianness) Endianness='B'; if (!Sign) Sign='U'; BitDepth=32;}
    else if (Codec==__T("raw "))             {  if (!Endianness) Endianness='L';            Sign='U';}
    else if (Codec==__T("twos"))             {                   Endianness='B';            Sign='S';}
    else if (Codec==__T("sowt"))             {                   Endianness='L';            Sign='S';}
    else if (Codec==__T("lpcm"))             {  if (!Endianness) Endianness='B'; if (!Sign) Sign='S';}
    else if (Codec==__T("SWF ADPCM"))        {Firm=__T("SWF");}
    else if (Codec==__T("1"))                {   if (BitDepth)
                                                {
                                                    if (BitDepth>8)
                                                    {            Endianness='L';            Sign='S';}
                                                    else
                                                    {                                       Sign='U';}
                                                }
                                            }
    else if (Codec==__T("2"))                {Firm=__T("Microsoft");}
    else if (Codec==__T("3"))                {                   Endianness='F';}
    else if (Codec==__T("10"))               {Firm=__T("OKI");}
    else if (Codec==__T("11"))               {Firm=__T("Intel");}
    else if (Codec==__T("12"))               {Firm=__T("Mediaspace");}
    else if (Codec==__T("13"))               {Firm=__T("Sierra");}
    else if (Codec==__T("14"))               {Firm=__T("Antex");}
    else if (Codec==__T("17"))               {Firm=__T("Dialogic");}
    else if (Codec==__T("18"))               {Firm=__T("Mediavision");}
    else if (Codec==__T("20"))               {Firm=__T("Yamaha");}
    else if (Codec==__T("33"))               {Firm=__T("Antex");}
    else if (Codec==__T("36"))               {Firm=__T("DSP Solution");}
    else if (Codec==__T("38"))               {Firm=__T("Natural MicroSystems");}
    else if (Codec==__T("39"))               {Firm=__T("Crystal Semiconductor");}
    else if (Codec==__T("3B"))               {Firm=__T("Rockwell");}
    else if (Codec==__T("40"))               {Firm=__T("Antex Electronics");}
    else if (Codec==__T("42"))               {Firm=__T("IBM");}
    else if (Codec==__T("45"))               {Firm=__T("Microsoft"); ITU=__T("G.726");}
    else if (Codec==__T("64"))               {Firm=__T("Apicom"); ITU=__T("G.726");}
    else if (Codec==__T("65"))               {Firm=__T("Apicom"); ITU=__T("G.722");}
    else if (Codec==__T("85"))               {Firm=__T("DataFusion Systems"); ITU=__T("G.726");}
    else if (Codec==__T("8B"))               {Firm=__T("Infocom"); ITU=__T("G.721");}
    else if (Codec==__T("97"))               {Firm=__T("ZyXEL");}
    else if (Codec==__T("100"))              {Firm=__T("Rhetorex");}
    else if (Codec==__T("125"))              {Firm=__T("Sanyo");}
    else if (Codec==__T("140"))              {Firm=__T("Dictaphone"); ITU=__T("G.726");}
    else if (Codec==__T("170"))              {Firm=__T("Unisys");}
    else if (Codec==__T("175"))              {Firm=__T("SyCom"); ITU=__T("G.726");}
    else if (Codec==__T("178"))              {Firm=__T("Knownledge");}
    else if (Codec==__T("200"))              {Firm=__T("Creative");}
    else if (Codec==__T("210"))              {Firm=__T("Uher");}
    else if (Codec==__T("285"))              {Firm=__T("Norcom Voice Systems");}
    else if (Codec==__T("1001"))             {Firm=__T("Olivetti");}
    else if (Codec==__T("1C03"))             {Firm=__T("Lucent"); ITU=__T("G.723");}
    else if (Codec==__T("1C0C"))             {Firm=__T("Lucent"); ITU=__T("G.723");}
    else if (Codec==__T("4243"))             {ITU=__T("G.726");}
    else if (Codec==__T("A105"))             {ITU=__T("G.726");}
    else if (Codec==__T("A107"))             {ITU=__T("G.726");}

    //Format
    Fill(Stream_Audio, 0, Audio_Codec_String, "PCM");
    Fill(Stream_Audio, 0, Audio_Codec_Family, "PCM");
    Fill(Stream_Audio, 0, Audio_BitRate_Mode, "CBR");

    //SamplingRate
    if (SamplingRate)
        Fill(Stream_Audio, 0, Audio_SamplingRate, SamplingRate);

    //Firm
    Fill(Stream_Audio, 0, Audio_Format_Settings, Firm);
    Fill(Stream_Audio, 0, Audio_Format_Settings_Firm, Firm);
    Fill(Stream_Audio, 0, Audio_Codec_Settings, Firm);
    Fill(Stream_Audio, 0, Audio_Codec_Settings_Firm, Firm);

    //Endianess
    const char* Value;
    switch (Endianness)
    {
        case 'B': Value="Big"; break;
        case 'L': Value="Little"; break;
        default : Value="";
    }
    Fill(Stream_Audio, 0, Audio_Format_Settings, Value);
    Fill(Stream_Audio, 0, Audio_Format_Settings_Endianness, Value);
    Fill(Stream_Audio, 0, Audio_Codec_Settings, Value);
    Fill(Stream_Audio, 0, Audio_Codec_Settings_Endianness, Value);

    //Sign
    switch (Sign)
    {
        case 'S': Value="Signed"; break;
        case 'U': Value="Unsigned"; break;
        default : Value="";
    }
    Fill(Stream_Audio, 0, Audio_Format_Settings, Value);
    Fill(Stream_Audio, 0, Audio_Format_Settings_Sign, Value);
    Fill(Stream_Audio, 0, Audio_Codec_Settings, Value);
    Fill(Stream_Audio, 0, Audio_Codec_Settings_Sign, Value);

    //ITU
    Fill(Stream_Audio, 0, Audio_Format_Settings, ITU);
    Fill(Stream_Audio, 0, Audio_Format_Settings_ITU, ITU);
    Fill(Stream_Audio, 0, Audio_Codec_Settings, ITU);
    Fill(Stream_Audio, 0, Audio_Codec_Settings_ITU, ITU);

    //BitDepth
    if (BitDepth_Significant)
    {
        Fill(Stream_Audio, 0, Audio_BitDepth, BitDepth_Significant);
        Fill(Stream_Audio, 0, Audio_BitDepth_Stored, BitDepth);
    }
    else if (BitDepth)
        Fill(Stream_Audio, 0, Audio_BitDepth, BitDepth);

    //Channels
    if (Channels)
        Fill(Stream_Audio, 0, Audio_Channel_s_, Channels);

    //Bit rate
    if (SamplingRate && BitDepth && Channels)
        Fill(Stream_Audio, 0, Audio_BitRate, SamplingRate*BitDepth*Channels);

    //ChannelsPositions
    if (Codec==__T("SMPTE ST 337"))
    {
        Fill(Stream_Audio, 0, Audio_ChannelPositions, Smpte_St0302_ChannelsPositions(Channels));
        Fill(Stream_Audio, 0, Audio_ChannelPositions_String2, Smpte_St0302_ChannelsPositions2(Channels));
    }
}

//---------------------------------------------------------------------------
void File_Pcm::Streams_Finish()
{
    //No frames in PCM!
    Frame_Count=(int64u)-1;
    Frame_Count_NotParsedIncluded=(int64u)-1;
}

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

//---------------------------------------------------------------------------
#if MEDIAINFO_DEMUX
void File_Pcm::Read_Buffer_Continue()
{
    if (Demux_UnpacketizeContainer && !Status[IsAccepted])
    {
        Frame_Count_Valid_Demux++;
        if (Frame_Count_Valid_Demux<Frame_Count_Valid)
            Element_WaitForMoreData();
    }
}
#endif //MEDIAINFO_DEMUX

//***************************************************************************
// Buffer - File header
//***************************************************************************

//---------------------------------------------------------------------------
bool File_Pcm::FileHeader_Begin()
{
    if (!Frame_Count_Valid)
    {
        Accept();
        Finish();
    }

    return true;
}

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

//---------------------------------------------------------------------------
void File_Pcm::Header_Parse()
{
    //Filling
    Header_Fill_Code(0, "Block");
    if (BitDepth && Channels)
    {
        int64u Size=(Element_Size/(BitDepth*Channels/8))*(BitDepth*Channels/8); //A complete sample
        if (Element_Size && Size==0)
        {
            Element_WaitForMoreData();
            return;
        }
        Header_Fill_Size(Size);
    }
    else
        Header_Fill_Size(Element_Size); // Unknown sample size
}

//---------------------------------------------------------------------------
void File_Pcm::Data_Parse()
{
    #if MEDIAINFO_DEMUX
        FrameInfo.PTS=FrameInfo.DTS;
        if (Frame_Count_Valid_Demux)
        {
            if (FrameInfo.DUR!=(int64u)-1)
                FrameInfo.DUR*=Frame_Count_Valid_Demux;
            if (Frame_Count_NotParsedIncluded!=(int64u)-1 && Frame_Count_NotParsedIncluded>=Frame_Count_Valid_Demux)
                Frame_Count_NotParsedIncluded-=Frame_Count_Valid_Demux-1;
        }
        Demux_random_access=true;
        Element_Code=(int64u)-1;

        if (BitDepth==20 && Endianness=='L' && Config->Demux_PCM_20bitTo16bit_Get())
        {
            size_t Info_Offset=(size_t)Element_Size;
            const int8u* Info=Buffer+Buffer_Offset;
            size_t Info2_Size=Info_Offset*4/5;
            int8u* Info2=new int8u[Info2_Size];
            size_t Info2_Pos=0;
            size_t Info_Pos=0;

            //Removing bits 3-0 (Little endian)
            // Dest  : 20LE / L1L0 L3L2 R0L4 R2R1 R4R3
            // Source:        L2L1 L4L3 R2R1 R4R2
            while (Info_Pos+5<=Info_Offset)
            {
                Info2[Info2_Pos  ] =(Info[Info_Pos+1]<<4  ) | (Info[Info_Pos+0]>>4  );
                Info2[Info2_Pos+1] =(Info[Info_Pos+2]<<4  ) | (Info[Info_Pos+1]>>4  );
                Info2[Info2_Pos+2] = Info[Info_Pos+3]                                ;
                Info2[Info2_Pos+3] = Info[Info_Pos+4]                                ;

                Info2_Pos+=4;
                Info_Pos+=5;
            }

            Demux(Info2, Info2_Pos, ContentType_MainStream);

            delete[] Info2;
        }
        else if (BitDepth==20 && Endianness=='L' && Config->Demux_PCM_20bitTo24bit_Get())
        {
            size_t Info_Offset=(size_t)Element_Size;
            const int8u* Info=Buffer+Buffer_Offset;
            size_t Info2_Size=Info_Offset*6/5;
            int8u* Info2=new int8u[Info2_Size];
            size_t Info2_Pos=0;
            size_t Info_Pos=0;

            //Padding bits 3-0 (Little endian)
            // Dest  : 20LE / L1L0 L3L2 R0L4 R2R1 R4R3
            // Source:        L0XX L2L1 L4L3 R0XX R2R1 R4R2
            while (Info_Pos+5<=Info_Offset)
            {
                Info2[Info2_Pos  ] = Info[Info_Pos+0]<<4                             ;
                Info2[Info2_Pos+1] =(Info[Info_Pos+1]<<4  ) | (Info[Info_Pos+0]>>4  );
                Info2[Info2_Pos+2] =(Info[Info_Pos+2]<<4  ) | (Info[Info_Pos+1]>>4  );
                Info2[Info2_Pos+3] = Info[Info_Pos+2]&0xF0                           ;
                Info2[Info2_Pos+4] = Info[Info_Pos+3]                                ;
                Info2[Info2_Pos+5] = Info[Info_Pos+4]                                ;

                Info2_Pos+=6;
                Info_Pos+=5;
            }

            Demux(Info2, Info2_Pos, ContentType_MainStream);

            delete[] Info2;
        }
        else
        {
            Demux(Buffer+Buffer_Offset, (size_t)Element_Size, ContentType_MainStream);
        }
    #endif //MEDIAINFO_DEMUX

    //Parsing
    Skip_XX(Element_Size,                                       "Data"); //It is impossible to detect... Default is no detection, only filling

    #if MEDIAINFO_DEMUX
    if (Frame_Count_Valid_Demux)
    {
        Frame_Count+=Frame_Count_Valid_Demux-1;
        if (Frame_Count_NotParsedIncluded!=(int64u)-1)
            Frame_Count_NotParsedIncluded+=Frame_Count_Valid_Demux-1;
        FrameInfo.DUR/=Frame_Count_Valid_Demux;
        if (FrameInfo.DTS!=(int64u)-1)
            FrameInfo.DTS+=FrameInfo.DUR*Frame_Count;
        Frame_Count_Valid_Demux=0;
    }
    #endif //MEDIAINFO_DEMUX
    Frame_Count++;
    if (Frame_Count_NotParsedIncluded!=(int64u)-1)
        Frame_Count_NotParsedIncluded++;
    if (FrameInfo.DTS!=(int64u)-1 && FrameInfo.DUR!=(int64u)-1)
    {
        FrameInfo.DTS+=FrameInfo.DUR;
        FrameInfo.PTS=FrameInfo.DTS;
    }
    if ((!Status[IsAccepted] && Frame_Count>=Frame_Count_Valid) || File_Offset+Buffer_Size>=File_Size)
    {
        Accept();
        Fill();
    }
}

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

} //NameSpace

#endif //MEDIAINFO_PCM_YES