1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2 *
3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the License.html file in the root of the source tree.
5 */
6
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // A good start : http://www.codeproject.com/audio/MPEGAudioInfo.asp
10 //
11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
13 //---------------------------------------------------------------------------
14 // Pre-compilation
15 #include "MediaInfo/PreComp.h"
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19 //---------------------------------------------------------------------------
20
21 //---------------------------------------------------------------------------
22 #include "MediaInfo/Setup.h"
23 //---------------------------------------------------------------------------
24
25 //***************************************************************************
26 // Constants (Common)
27 //***************************************************************************
28
29 //---------------------------------------------------------------------------
30 #if defined(MEDIAINFO_MPEGA_YES) || defined(MEDIAINFO_MPEGTS_YES) || defined(MEDIAINFO_MPEGPS_YES)
31 //---------------------------------------------------------------------------
32
33 #include "ZenLib/Conf.h"
34 using namespace ZenLib;
35
36 namespace MediaInfoLib
37 {
38
39 //---------------------------------------------------------------------------
40 const char* Mpega_Version[4]=
41 {
42 "MPA2.5",
43 "",
44 "MPA2",
45 "MPA1"
46 };
47
48 //---------------------------------------------------------------------------
49 const char* Mpega_Layer[4]=
50 {
51 "",
52 "L3",
53 "L2",
54 "L1",
55 };
56
57 //---------------------------------------------------------------------------
58 const char* Mpega_Format_Profile_Version[4]=
59 {
60 "Version 2.5",
61 "",
62 "Version 2",
63 "Version 1"
64 };
65
66 //---------------------------------------------------------------------------
67 const char* Mpega_Format_Profile_Layer[4]=
68 {
69 "",
70 "Layer 3",
71 "Layer 2",
72 "Layer 1",
73 };
74
75 //---------------------------------------------------------------------------
76 } //NameSpace
77
78 //---------------------------------------------------------------------------
79 #endif //...
80 //---------------------------------------------------------------------------
81
82 //***************************************************************************
83 //
84 //***************************************************************************
85
86 //---------------------------------------------------------------------------
87 #if defined(MEDIAINFO_MPEGA_YES)
88 //---------------------------------------------------------------------------
89
90 //---------------------------------------------------------------------------
91 #include "MediaInfo/Audio/File_Mpega.h"
92 #include "ZenLib/BitStream.h"
93 #include "ZenLib/Utils.h"
94 #include "MediaInfo/MediaInfo_Config_MediaInfo.h"
95 using namespace ZenLib;
96 //---------------------------------------------------------------------------
97
98 namespace MediaInfoLib
99 {
100
101 //***************************************************************************
102 // Constants
103 //***************************************************************************
104
105 //---------------------------------------------------------------------------
106 static const char* Mpega_Version_String[4]=
107 {
108 "MPEG-2.5 Audio",
109 "",
110 "MPEG-2 Audio",
111 "MPEG-1 Audio",
112 };
113
114 //---------------------------------------------------------------------------
115 static const char* Mpega_Layer_String[4]=
116 {
117 "",
118 " layer 3",
119 " layer 2",
120 " layer 1",
121 };
122
123 //---------------------------------------------------------------------------
124 static const int16u Mpega_BitRate[4][4][16]=
125 {
126 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio 2.5 layer X
127 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, //MPEG Audio 2.5 layer 3
128 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, //MPEG Audio 2.5 layer 2
129 {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0}}, //MPEG Audio 2.5 layer 1
130 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio X layer X
131 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio X layer 3
132 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio X layer 2
133 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //MPEG Audio X layer 1
134 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio 2 layer X
135 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, //MPEG Audio 2 layer 3
136 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, //MPEG Audio 2 layer 2
137 {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0}}, //MPEG Audio 2 layer 1
138 {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //MPEG Audio 1 layer X
139 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}, //MPEG Audio 1 layer 3
140 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0}, //MPEG Audio 1 layer 2
141 {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0}}, //MPEG Audio 1 layer 1
142 };
143
144 //---------------------------------------------------------------------------
145 static const int16u Mpega_SamplingRate[4][4]=
146 {
147 {11025, 12000, 8000, 0}, //MPEG Audio 2.5
148 { 0, 0, 0, 0}, //MPEG Audio X
149 {22050, 24000, 16000, 0}, //MPEG Audio 2
150 {44100, 48000, 32000, 0}, //MPEG Audio 1
151 };
152
153 //---------------------------------------------------------------------------
154 static const int16u Mpega_Channels[4]=
155 {
156 2,
157 2,
158 2,
159 1,
160 };
161
162 //---------------------------------------------------------------------------
163 static const char* Mpega_Codec_Profile[4]=
164 {
165 "",
166 "Joint stereo",
167 "Dual mono",
168 "",
169 };
170
171 //---------------------------------------------------------------------------
172 static const char* Mpega_Codec_Profile_Extension[]=
173 {
174 "",
175 "Intensity Stereo",
176 "MS Stereo",
177 "Intensity Stereo + MS Stereo",
178 };
179
180 //---------------------------------------------------------------------------
181 static const char* Mpega_Emphasis[]=
182 {
183 "",
184 "50/15ms",
185 "Reserved",
186 "CCITT",
187 };
188
189 //---------------------------------------------------------------------------
190 static const char* Lame_BitRate_Mode[]=
191 {
192 "",
193 "CBR",
194 "VBR",
195 "VBR",
196 "VBR",
197 "VBR",
198 "VBR",
199 "",
200 "CBR",
201 "VBR",
202 "",
203 "",
204 "",
205 "",
206 "",
207 "",
208 };
209
210 //---------------------------------------------------------------------------
211 static const char* Lame_Method[]=
212 {
213 "",
214 "CBR",
215 "ABR",
216 "VBR (rh)",
217 "VBR (mtrh)",
218 "VBR (rh)",
219 "VBR",
220 "",
221 "CBR (2-pass)",
222 "ABR (2-pass)",
223 "",
224 "",
225 "",
226 "",
227 "",
228 "",
229 };
230
231 //---------------------------------------------------------------------------
232 static const int8u Mpega_Coefficient[4][4] = //Samples per Frame / 8
233 {
234 { 0, 72, 144, 12}, //MPEG Audio 2.5
235 { 0, 0, 0, 0}, //MPEG Audio X
236 { 0, 72, 144, 12}, //MPEG Audio 2
237 { 0, 144, 144, 12}, //MPEG Audio 1
238 };
239
240 //---------------------------------------------------------------------------
241 static const int8u Mpega_SlotSize[4]= //A frame is coposed of slots
242 {
243 0, // Layer X
244 1, // Layer3
245 1, // Layer2
246 4, // Layer1
247 };
248
249 //---------------------------------------------------------------------------
250 static const int16u Mpega_CRC12_Table[]=
251 {
252 0x000, 0x80f, 0x811, 0x01e, 0x82d, 0x022, 0x03c, 0x833,
253 0x855, 0x05a, 0x044, 0x84b, 0x078, 0x877, 0x869, 0x066,
254 0x8a5, 0x0aa, 0x0b4, 0x8bb, 0x088, 0x887, 0x899, 0x096,
255 0x0f0, 0x8ff, 0x8e1, 0x0ee, 0x8dd, 0x0d2, 0x0cc, 0x8c3,
256 0x945, 0x14a, 0x154, 0x95b, 0x168, 0x967, 0x979, 0x176,
257 0x110, 0x91f, 0x901, 0x10e, 0x93d, 0x132, 0x12c, 0x923,
258 0x1e0, 0x9ef, 0x9f1, 0x1fe, 0x9cd, 0x1c2, 0x1dc, 0x9d3,
259 0x9b5, 0x1ba, 0x1a4, 0x9ab, 0x198, 0x997, 0x989, 0x186,
260 0xa85, 0x28a, 0x294, 0xa9b, 0x2a8, 0xaa7, 0xab9, 0x2b6,
261 0x2d0, 0xadf, 0xac1, 0x2ce, 0xafd, 0x2f2, 0x2ec, 0xae3,
262 0x220, 0xa2f, 0xa31, 0x23e, 0xa0d, 0x202, 0x21c, 0xa13,
263 0xa75, 0x27a, 0x264, 0xa6b, 0x258, 0xa57, 0xa49, 0x246,
264 0x3c0, 0xbcf, 0xbd1, 0x3de, 0xbed, 0x3e2, 0x3fc, 0xbf3,
265 0xb95, 0x39a, 0x384, 0xb8b, 0x3b8, 0xbb7, 0xba9, 0x3a6,
266 0xb65, 0x36a, 0x374, 0xb7b, 0x348, 0xb47, 0xb59, 0x356,
267 0x330, 0xb3f, 0xb21, 0x32e, 0xb1d, 0x312, 0x30c, 0xb03,
268 0xd05, 0x50a, 0x514, 0xd1b, 0x528, 0xd27, 0xd39, 0x536,
269 0x550, 0xd5f, 0xd41, 0x54e, 0xd7d, 0x572, 0x56c, 0xd63,
270 0x5a0, 0xdaf, 0xdb1, 0x5be, 0xd8d, 0x582, 0x59c, 0xd93,
271 0xdf5, 0x5fa, 0x5e4, 0xdeb, 0x5d8, 0xdd7, 0xdc9, 0x5c6,
272 0x440, 0xc4f, 0xc51, 0x45e, 0xc6d, 0x462, 0x47c, 0xc73,
273 0xc15, 0x41a, 0x404, 0xc0b, 0x438, 0xc37, 0xc29, 0x426,
274 0xce5, 0x4ea, 0x4f4, 0xcfb, 0x4c8, 0xcc7, 0xcd9, 0x4d6,
275 0x4b0, 0xcbf, 0xca1, 0x4ae, 0xc9d, 0x492, 0x48c, 0xc83,
276 0x780, 0xf8f, 0xf91, 0x79e, 0xfad, 0x7a2, 0x7bc, 0xfb3,
277 0xfd5, 0x7da, 0x7c4, 0xfcb, 0x7f8, 0xff7, 0xfe9, 0x7e6,
278 0xf25, 0x72a, 0x734, 0xf3b, 0x708, 0xf07, 0xf19, 0x716,
279 0x770, 0xf7f, 0xf61, 0x76e, 0xf5d, 0x752, 0x74c, 0xf43,
280 0xec5, 0x6ca, 0x6d4, 0xedb, 0x6e8, 0xee7, 0xef9, 0x6f6,
281 0x690, 0xe9f, 0xe81, 0x68e, 0xebd, 0x6b2, 0x6ac, 0xea3,
282 0x660, 0xe6f, 0xe71, 0x67e, 0xe4d, 0x642, 0x65c, 0xe53,
283 0xe35, 0x63a, 0x624, 0xe2b, 0x618, 0xe17, 0xe09, 0x606
284 };
285
286 //***************************************************************************
287 // Constructor/Destructor
288 //***************************************************************************
289
290 //---------------------------------------------------------------------------
File_Mpega()291 File_Mpega::File_Mpega()
292 :File__Analyze(), File__Tags_Helper()
293 {
294 //File__Tags_Helper
295 Base=this;
296
297 //Configuration
298 #if MEDIAINFO_TRACE
299 Trace_Layers_Update(8); //Stream
300 #endif //MEDIAINFO_TRACE
301 MustSynchronize=true;
302 Buffer_TotalBytes_FirstSynched_Max=64*1024;
303 PTS_DTS_Needed=true;
304 StreamSource=IsStream;
305 Frame_Count_NotParsedIncluded=0;
306
307 //In
308 Frame_Count_Valid=0;
309 FrameIsAlwaysComplete=false;
310 CalculateDelay=false;
311
312 //Temp - BitStream info
313 Surround_Frames=0;
314 Block_Count[0]=0;
315 Block_Count[1]=0;
316 Block_Count[2]=0;
317 Channels_Count[0]=0;
318 Channels_Count[1]=0;
319 Channels_Count[2]=0;
320 Channels_Count[3]=0;
321 Extension_Count[0]=0;
322 Extension_Count[1]=0;
323 Extension_Count[2]=0;
324 Extension_Count[3]=0;
325 Emphasis_Count[0]=0;
326 Emphasis_Count[1]=0;
327 Emphasis_Count[2]=0;
328 Emphasis_Count[3]=0;
329 Scfsi=0;
330 Scalefac=0;
331 Reservoir=0;
332 LastSync_Offset=(int64u)-1;
333 VBR_FileSize=0;
334 VBR_Frames=0;
335 Reservoir_Max=0;
336 Xing_Scale=0;
337 BitRate=0;
338 MpegPsPattern_Count=0;
339 VBR_Frames_IsCbr=false;
340 }
341
342 //***************************************************************************
343 // Streams management
344 //***************************************************************************
345
346 //---------------------------------------------------------------------------
Streams_Fill()347 void File_Mpega::Streams_Fill()
348 {
349 //VBR detection without header
350 if (VBR_Frames==0)
351 {
352 //How much kinds of bitrates?
353 if (BitRate_Count.size()>1)
354 BitRate_Mode=__T("VBR");
355 }
356
357 File__Tags_Helper::Stream_Prepare(Stream_Audio);
358 Fill(Stream_Audio, 0, Audio_Format, "MPEG Audio");
359 Fill(Stream_Audio, 0, Audio_Format_Version, Mpega_Format_Profile_Version[ID]);
360 Fill(Stream_Audio, 0, Audio_Format_Profile, Mpega_Format_Profile_Layer[layer]);
361 if (mode && mode<4)
362 {
363 Fill(Stream_Audio, 0, Audio_Format_Settings, Mpega_Codec_Profile[mode]);
364 Fill(Stream_Audio, 0, Audio_Format_Settings_Mode, Mpega_Codec_Profile[mode]);
365 }
366 if (mode_extension && mode_extension<4)
367 {
368 Fill(Stream_Audio, 0, Audio_Format_Settings, Mpega_Codec_Profile_Extension[mode_extension]);
369 Fill(Stream_Audio, 0, Audio_Format_Settings_ModeExtension, Mpega_Codec_Profile_Extension[mode_extension]);
370 }
371 if (emphasis && emphasis<4)
372 {
373 Fill(Stream_Audio, 0, Audio_Format_Settings, Mpega_Emphasis[emphasis]);
374 Fill(Stream_Audio, 0, Audio_Format_Settings_Emphasis, Mpega_Emphasis[emphasis]);
375 }
376 Fill(Stream_Audio, 0, Audio_Codec, Ztring(Mpega_Version[ID])+Ztring(Mpega_Layer[layer]));
377 Fill(Stream_Audio, 0, Audio_Codec_String, Ztring(Mpega_Version_String[ID])+Ztring(Mpega_Layer_String[layer]), true);
378 Fill(Stream_Audio, 0, Audio_SamplingRate, Mpega_SamplingRate[ID][sampling_frequency]);
379 if (mode<4)
380 {
381 Fill(Stream_Audio, 0, Audio_Channel_s_, Mpega_Channels[mode]);
382 Fill(Stream_Audio, 0, Audio_Codec_Profile, Mpega_Codec_Profile[mode]);
383 }
384
385 //Bitrate, if CBR
386 if (VBR_Frames==0 && BitRate_Mode!=__T("VBR"))
387 {
388 BitRate_Mode=__T("CBR");
389 BitRate=Mpega_BitRate[ID][layer][bitrate_index]*1000;
390 Fill(Stream_General, 0, General_OverallBitRate, BitRate);
391 Fill(Stream_Audio, 0, Audio_BitRate, BitRate);
392 if (CalculateDelay && Buffer_TotalBytes_FirstSynched>10 && BitRate>0)
393 {
394 Fill(Stream_Audio, 0, Audio_Delay, Buffer_TotalBytes_FirstSynched*8*1000/BitRate, 0);
395 Fill(Stream_Audio, 0, Audio_Delay_Source, "Stream");
396 }
397 }
398
399 //Bitrate mode
400 Fill(Stream_Audio, 0, Audio_BitRate_Mode, BitRate_Mode);
401 Fill(Stream_Audio, 0, Audio_BitRate_Minimum, BitRate_Minimum);
402 Fill(Stream_Audio, 0, Audio_BitRate_Nominal, BitRate_Nominal);
403
404 #if MEDIAINFO_ADVANCED
405 if (!IsSub && !VBR_Frames && !VBR_FileSize && BitRate_Mode==__T("VBR") && ID<4 && sampling_frequency<4 && Retrieve_Const(Stream_Audio, 0, Audio_BitRate).empty() && Config->File_RiskyBitRateEstimation_Get())
406 {
407 size_t Divider;
408 if (ID==3 && layer==3) //MPEG 1 layer 1
409 Divider=384/8;
410 else if ((ID==2 || ID==0) && layer==3) ///MPEG 2 or 2.5 layer 1
411 Divider=192/8;
412 else if ((ID==2 || ID==0) && layer==1) //MPEG 2 or 2.5 layer 3
413 Divider=576/8;
414 else
415 Divider=1152/8;
416 BitRate=(int32u)((File_Offset+Buffer_Offset+Element_Size)*Mpega_SamplingRate[ID][sampling_frequency]/Frame_Count/Divider);
417 Fill(Stream_Audio, 0, Audio_BitRate, BitRate);
418 }
419 #endif //MEDIAINFO_ADVANCED
420
421 //Tags
422 File__Tags_Helper::Streams_Fill();
423 }
424
425 //---------------------------------------------------------------------------
Streams_Finish()426 void File_Mpega::Streams_Finish()
427 {
428 //Reservoir
429 //Fill("Reservoir_Avg", Reservoir/Frame_Count);
430 //Fill("Reservoir_Max", Reservoir_Max);
431 //size_t Granules=(Mpeg==3?2:1);
432 //size_t Ch=Mpega_Channels[Channels];
433 //Fill("Scalefactors", Ztring::ToZtring(Scalefac*100/(Granules*Ch*Frame_Count))+__T('%'));
434
435 //VBR_FileSize calculation
436 if (!IsSub && (File_Size!=(int64u)-1 || LastSync_Offset!=(int64u)-1) && VBR_FileSize==0)
437 {
438 //We calculate VBR_FileSize from the last synch or File_Size
439 if (LastSync_Offset!=(int64u)-1)
440 {
441 VBR_FileSize=LastSync_Offset;
442 VBR_FileSize-=File_BeginTagSize;
443 }
444 else
445 {
446 VBR_FileSize=File_Size;
447 VBR_FileSize-=File_BeginTagSize;
448 VBR_FileSize-=File_EndTagSize;
449 }
450 }
451
452 //Bitrate calculation if VBR
453 int64u FrameCount=0;
454 if (VBR_Frames>0)
455 {
456 FrameCount=VBR_Frames;
457 float32 FrameLength=((float32)(VBR_FileSize?VBR_FileSize:File_Size-File_EndTagSize-File_BeginTagSize))/VBR_Frames;
458 size_t Divider;
459 if (ID==3 && layer==3) //MPEG 1 layer 1
460 Divider=384/8;
461 else if ((ID==2 || ID==0) && layer==3) ///MPEG 2 or 2.5 layer 1
462 Divider=192/8;
463 else if ((ID==2 || ID==0) && layer==1) //MPEG 2 or 2.5 layer 3
464 Divider=576/8;
465 else
466 Divider=1152/8;
467 if (ID<4 && sampling_frequency<4)
468 BitRate=float32_int32s(FrameLength*Mpega_SamplingRate[ID][sampling_frequency]/Divider);
469 BitRate_Mode=(VBR_Frames_IsCbr?__T("CBR"):__T("VBR"));
470 }
471 //if (BitRate_Count.size()>1)
472 //{
473 // Ztring BitRate_VBR;
474 // if (!BitRate_VBR.empty())
475 // BitRate_VBR+=__T(' ');
476 // BitRate_VBR+=Ztring::ToZtring(8);
477 // BitRate_VBR+=__T(':');
478 // BitRate_VBR+=Ztring::ToZtring(BitRate_Count[8]);
479 // Fill("BitRate_VBR", Ztring::ToZtring(BitRate_Count[8]));
480 //}
481 if (VBR_FileSize)
482 {
483 if (BitRate)
484 {
485 Fill(Stream_General, 0, General_Duration, VBR_FileSize*8*1000/BitRate, 10, true);
486 Fill(Stream_General, 0, General_OverallBitRate, BitRate, 10, true);
487 Fill(Stream_Audio, 0, Audio_BitRate, BitRate, 10, true);
488 if (CalculateDelay && Buffer_TotalBytes_FirstSynched>10 && BitRate>0)
489 {
490 Fill(Stream_Audio, 0, Audio_Delay, Buffer_TotalBytes_FirstSynched*8*1000/BitRate, 0, true);
491 Fill(Stream_Audio, 0, Audio_Delay_Source, "Stream", Unlimited, true, true);
492 }
493 }
494 Fill(Stream_Audio, 0, Audio_StreamSize, VBR_FileSize);
495 }
496 Fill(Stream_Audio, 0, Audio_BitRate_Mode, BitRate_Mode, true);
497
498 //Encoding library
499 if (Encoded_Library.empty())
500 Encoded_Library_Guess();
501 if (!Encoded_Library.empty())
502 {
503 Ztring Encoded_LibraryZ;
504 Encoded_LibraryZ.From_UTF8(Encoded_Library.c_str());
505 if (Encoded_LibraryZ.empty())
506 Encoded_LibraryZ.From_ISO_8859_1(Encoded_Library.c_str());
507 Fill(Stream_General, 0, General_Encoded_Library, Encoded_LibraryZ, true);
508 Fill(Stream_Audio, 0, Audio_Encoded_Library, Encoded_LibraryZ, true);
509 Fill(Stream_Audio, 0, Audio_Encoded_Library_Settings, Encoded_Library_Settings, true);
510 }
511
512 //Surround
513 if (Surround_Frames>=Frame_Count*0.9)
514 {
515 //Fill(Stream_Audio, 0, Audio_Channel_s_, 6);
516 }
517
518 if (FrameInfo.PTS!=(int64u)-1 && FrameInfo.PTS>PTS_Begin)
519 {
520 Fill(Stream_Audio, 0, Audio_Duration, float64_int64s(((float64)(FrameInfo.PTS-PTS_Begin))/1000000));
521 if (Retrieve(Stream_Audio, 0, Audio_BitRate_Mode)==__T("CBR") && ID<4 && sampling_frequency<4)
522 {
523 int16u Samples;
524 if (ID==3 && layer==3) //MPEG 1 layer 1
525 Samples=384;
526 else if ((ID==2 || ID==0) && layer==1) //MPEG 2 or 2.5 layer 3
527 Samples=576;
528 else
529 Samples=1152;
530
531 float64 Frame_Duration=((float64)1)/Mpega_SamplingRate[ID][sampling_frequency]*Samples;
532 FrameCount=float64_int64s(((float64)(FrameInfo.PTS-PTS_Begin))/1000000000/Frame_Duration);
533 }
534 }
535
536 if (FrameCount==0 && VBR_FileSize && Retrieve(Stream_Audio, 0, Audio_BitRate_Mode)==__T("CBR") && ID<4 && layer<4 && sampling_frequency<4 && bitrate_index<16 && Mpega_SamplingRate[ID][sampling_frequency])
537 {
538 float64 Size=((float64)Mpega_Coefficient[ID][layer]*Mpega_BitRate[ID][layer][bitrate_index]*1000/Mpega_SamplingRate[ID][sampling_frequency])*Mpega_SlotSize[layer];
539 if (Size)
540 FrameCount=float64_int64s(VBR_FileSize/Size);
541 }
542
543 if (FrameCount)
544 {
545 int16u Samples;
546 if (ID==3 && layer==3) //MPEG 1 layer 1
547 Samples=384;
548 else if ((ID==2 || ID==0) && layer==1) //MPEG 2 or 2.5 layer 3
549 Samples=576;
550 else
551 Samples=1152;
552 Fill(Stream_Audio, 0, Audio_FrameCount, FrameCount, 10, true);
553 Fill(Stream_Audio, 0, Audio_SamplingCount, FrameCount*Samples, 10, true);
554 float64 audio_fps = (float64)((float64)Mpega_SamplingRate[ID][sampling_frequency] / (float64)Samples);
555 Fill(Stream_Audio, 0, Audio_FrameRate, audio_fps, 3, true);
556 }
557
558 File__Tags_Helper::Streams_Finish();
559 }
560
561 //***************************************************************************
562 // Buffer - File header
563 //***************************************************************************
564
565 //---------------------------------------------------------------------------
FileHeader_Begin()566 bool File_Mpega::FileHeader_Begin()
567 {
568 //Buffer size
569 if (Buffer_Size<8)
570 return File_Size<8; //Must wait for more data
571
572 //Detecting WAV/SWF/FLV/ELF/DPG/WM/MZ/DLG files
573 int32u Magic4=CC4(Buffer);
574 int32u Magic3=Magic4>>8;
575 int16u Magic2=Magic4>>16;
576 if (Magic4==0x52494646 || Magic3==0x465753 || Magic3==0x464C56 || Magic4==0x7F454C46 || Magic4==0x44504730 || Magic4==0x3026B275 || Magic2==0x4D5A || Magic4==0x000001BA || Magic4==0x000001B3 || Magic4==0x00000100 || CC8(Buffer+Buffer_Offset)==0x444C472056312E30LL)
577 {
578 File__Tags_Helper::Reject("MPEG Audio");
579 return false;
580 }
581
582 //Seems OK
583 if (!Frame_Count_Valid)
584 Frame_Count_Valid=Config->ParseSpeed>=0.5?128:(Config->ParseSpeed>=0.3?32:4);
585 return true;
586 }
587
588 //***************************************************************************
589 // Buffer - Synchro
590 //***************************************************************************
591
592 //---------------------------------------------------------------------------
Synchronize()593 bool File_Mpega::Synchronize()
594 {
595 //Tags
596 bool Tag_Found_Begin;
597 if (!File__Tags_Helper::Synchronize(Tag_Found_Begin))
598 return false;
599 if (Tag_Found_Begin)
600 return true;
601
602 //Synchro
603 if (Buffer_Offset+3>Buffer_Size)
604 return false;
605 if (!Status[IsAccepted]
606 && Buffer[Buffer_Offset+0]==0x46 //"FLV"
607 && Buffer[Buffer_Offset+1]==0x4C
608 && Buffer[Buffer_Offset+2]==0x56)
609 {
610 File__Tags_Helper::Reject(); //Parser accepts too easily FLV files with MPEG Audio (synchronization lost due to FLV header is not enough), rejecting if FLV magic value is found before the first synchro
611 return false;
612 }
613
614 //Synchronizing
615 while (Buffer_Offset+4<=Buffer_Size)
616 {
617 while (Buffer_Offset+4<=Buffer_Size)
618 {
619 if (Buffer[Buffer_Offset ]==0xFF
620 && (Buffer[Buffer_Offset+1]&0xE0)==0xE0
621 && (Buffer[Buffer_Offset+2]&0xF0)!=0xF0
622 && (Buffer[Buffer_Offset+2]&0x0C)!=0x0C)
623 break; //while()
624
625 //Tags
626 bool Tag_Found_Synchro;
627 if (!File__Tags_Helper::Synchronize(Tag_Found_Synchro))
628 return false;
629 if (Tag_Found_Synchro)
630 return true;
631
632 //Better detect MPEG-PS
633 if (Frame_Count==0
634 && Buffer[Buffer_Offset ]==0x00
635 && Buffer[Buffer_Offset+1]==0x00
636 && Buffer[Buffer_Offset+2]==0x01
637 && Buffer[Buffer_Offset+3]==0xBA)
638 {
639 MpegPsPattern_Count++;
640 if (MpegPsPattern_Count>=2)
641 {
642 File__Tags_Helper::Reject("MPEG Audio");
643 return false;
644 }
645 }
646
647 Buffer_Offset++;
648 }
649
650 if (Buffer_Offset+4<=Buffer_Size)//Testing if size is coherant
651 {
652 //Retrieving some info
653 int8u ID0 =(CC1(Buffer+Buffer_Offset+1)>>3)&0x03;
654 int8u layer0 =(CC1(Buffer+Buffer_Offset+1)>>1)&0x03;
655 int8u bitrate_index0 =(CC1(Buffer+Buffer_Offset+2)>>4)&0x0F;
656 int8u sampling_frequency0=(CC1(Buffer+Buffer_Offset+2)>>2)&0x03;
657 int8u padding_bit0 =(CC1(Buffer+Buffer_Offset+2)>>1)&0x01;
658 //Coherancy
659 if (Mpega_SamplingRate[ID0][sampling_frequency0]==0 || Mpega_Coefficient[ID0][layer0]==0 || Mpega_BitRate[ID0][layer0][bitrate_index0]==0 || Mpega_SlotSize[layer0]==0)
660 Buffer_Offset++; //False start
661 else
662 {
663 //Testing next start, to be sure
664 size_t Size0=(Mpega_Coefficient[ID0][layer0]*Mpega_BitRate[ID0][layer0][bitrate_index0]*1000/Mpega_SamplingRate[ID0][sampling_frequency0]+(padding_bit0?1:0))*Mpega_SlotSize[layer0];
665 if (IsSub && Buffer_Offset+Size0==Buffer_Size)
666 break;
667 if (File_Offset+Buffer_Offset+Size0!=File_Size-File_EndTagSize)
668 {
669 //Padding
670 while (Buffer_Offset+Size0+4<=Buffer_Size && Buffer[Buffer_Offset+Size0]==0x00)
671 Size0++;
672
673 if (Buffer_Offset+Size0+4>Buffer_Size)
674 return false; //Need more data
675
676 //Tags
677 bool Tag_Found0;
678 if (!File__Tags_Helper::Synchronize(Tag_Found0, Size0))
679 return false;
680 if (Tag_Found0)
681 return true;
682 if (File_Offset+Buffer_Offset+Size0==File_Size-File_EndTagSize)
683 break;
684
685 //Testing
686 if ((CC2(Buffer+Buffer_Offset+Size0)&0xFFE0)!=0xFFE0 || (CC1(Buffer+Buffer_Offset+Size0+2)&0xF0)==0xF0 || (CC1(Buffer+Buffer_Offset+Size0+2)&0x0C)==0x0C)
687 {
688 //Testing VBRI in a malformed frame
689 bool VbriFound=false;
690 for (size_t Pos=Buffer_Offset+3; Pos+4<Buffer_Offset+Size0; Pos++)
691 {
692 if (Buffer[Pos ]==0x56
693 && Buffer[Pos+1]==0x42
694 && Buffer[Pos+2]==0x52
695 && Buffer[Pos+3]==0x49)
696 {
697 VbriFound=true;
698 break;
699 }
700 if (Buffer[Pos])
701 break; //Only NULL bytes are authorized before VBRI header
702 }
703 if (VbriFound)
704 break;
705 Buffer_Offset++;
706 }
707 else
708 {
709 //Retrieving some info
710 int8u ID1 =(CC1(Buffer+Buffer_Offset+Size0+1)>>3)&0x03;
711 int8u layer1 =(CC1(Buffer+Buffer_Offset+Size0+1)>>1)&0x03;
712 int8u bitrate_index1 =(CC1(Buffer+Buffer_Offset+Size0+2)>>4)&0x0F;
713 int8u sampling_frequency1=(CC1(Buffer+Buffer_Offset+Size0+2)>>2)&0x03;
714 int8u padding_bit1 =(CC1(Buffer+Buffer_Offset+Size0+2)>>1)&0x01;
715 //Coherancy
716 if (Mpega_SamplingRate[ID1][sampling_frequency1]==0 || Mpega_Coefficient[ID1][layer1]==0 || Mpega_BitRate[ID1][layer1][bitrate_index1]==0 || Mpega_SlotSize[layer1]==0)
717 Buffer_Offset++; //False start
718 else
719 {
720 //Testing next start, to be sure
721 size_t Size1=(Mpega_Coefficient[ID1][layer1]*Mpega_BitRate[ID1][layer1][bitrate_index1]*1000/Mpega_SamplingRate[ID1][sampling_frequency1]+(padding_bit1?1:0))*Mpega_SlotSize[layer1];
722 if (IsSub && Buffer_Offset+Size0+Size1==Buffer_Size)
723 break;
724 if (File_Offset+Buffer_Offset+Size0+Size1!=File_Size-File_EndTagSize)
725 {
726 //Padding
727 while (Buffer_Offset+Size0+Size1+4<=Buffer_Size && Buffer[Buffer_Offset+Size0+Size1]==0x00)
728 Size0++;
729
730 if (Buffer_Offset+Size0+Size1+4>Buffer_Size)
731 return false; //Need more data
732
733 //Tags
734 bool Tag_Found1;
735 if (!File__Tags_Helper::Synchronize(Tag_Found1, Size0+Size1))
736 return false;
737 if (Tag_Found1)
738 return true;
739 if (File_Offset+Buffer_Offset+Size0+Size1==File_Size-File_EndTagSize)
740 break;
741
742 //Testing
743 if ((CC2(Buffer+Buffer_Offset+Size0+Size1)&0xFFE0)!=0xFFE0 || (CC1(Buffer+Buffer_Offset+Size0+Size1+2)&0xF0)==0xF0 || (CC1(Buffer+Buffer_Offset+Size0+Size1+2)&0x0C)==0x0C)
744 Buffer_Offset++;
745 else
746 {
747 //Retrieving some info
748 int8u ID2 =(CC1(Buffer+Buffer_Offset+Size0+Size1+1)>>3)&0x03;
749 int8u layer2 =(CC1(Buffer+Buffer_Offset+Size0+Size1+1)>>1)&0x03;
750 int8u bitrate_index2 =(CC1(Buffer+Buffer_Offset+Size0+Size1+2)>>4)&0x0F;
751 int8u sampling_frequency2=(CC1(Buffer+Buffer_Offset+Size0+Size1+2)>>2)&0x03;
752 int8u padding_bit2 =(CC1(Buffer+Buffer_Offset+Size0+Size1+2)>>1)&0x01;
753 //Coherancy
754 if (Mpega_SamplingRate[ID2][sampling_frequency2]==0 || Mpega_Coefficient[ID2][layer2]==0 || Mpega_BitRate[ID2][layer2][bitrate_index2]==0 || Mpega_SlotSize[layer2]==0)
755 Buffer_Offset++; //False start
756 else
757 {
758 //Testing next start, to be sure
759 size_t Size2=(Mpega_Coefficient[ID2][layer2]*Mpega_BitRate[ID2][layer2][bitrate_index2]*1000/Mpega_SamplingRate[ID2][sampling_frequency2]+(padding_bit2?1:0))*Mpega_SlotSize[layer2];
760 if (IsSub && Buffer_Offset+Size0+Size1+Size2==Buffer_Size)
761 break;
762 if (File_Offset+Buffer_Offset+Size0+Size1+Size2!=File_Size-File_EndTagSize)
763 {
764 //Padding
765 while (Buffer_Offset+Size0+Size1+Size2+4<=Buffer_Size && Buffer[Buffer_Offset+Size0+Size1+Size2]==0x00)
766 Size0++;
767
768 if (Buffer_Offset+Size0+Size1+Size2+4>Buffer_Size)
769 {
770 if (IsSub || File_Offset+Buffer_Offset+Size0+Size1+Size2<File_Size)
771 break;
772 return false; //Need more data
773 }
774
775 //Tags
776 bool Tag_Found2;
777 if (!File__Tags_Helper::Synchronize(Tag_Found2, Size0+Size1+Size2))
778 return false;
779 if (Tag_Found2)
780 return true;
781 if (File_Offset+Buffer_Offset+Size0+Size1+Size2==File_Size-File_EndTagSize)
782 break;
783
784 //Testing
785 if ((CC2(Buffer+Buffer_Offset+Size0+Size1+Size2)&0xFFE0)!=0xFFE0 || (CC1(Buffer+Buffer_Offset+Size0+Size1+Size2+2)&0xF0)==0xF0 || (CC1(Buffer+Buffer_Offset+Size0+Size1+Size2+2)&0x0C)==0x0C)
786 Buffer_Offset++;
787 else
788 break; //while()
789 }
790 else
791 break; //while()
792 }
793 }
794 }
795 else
796 break; //while()
797 }
798 }
799 }
800 else
801 break; //while()
802 }
803 }
804 }
805
806 //Parsing last bytes if needed
807 if (Buffer_Offset+4>Buffer_Size)
808 {
809 if (Buffer_Offset+3==Buffer_Size && (CC2(Buffer+Buffer_Offset)&0xFFE0)!=0xFFE0)
810 Buffer_Offset++;
811 if (Buffer_Offset+2==Buffer_Size && (CC2(Buffer+Buffer_Offset)&0xFFE0)!=0xFFE0)
812 Buffer_Offset++;
813 if (Buffer_Offset+1==Buffer_Size && CC1(Buffer+Buffer_Offset)!=0x00)
814 Buffer_Offset++;
815 return false;
816 }
817
818 //Synched is OK
819 return true;
820 }
821
822 //---------------------------------------------------------------------------
Synched_Test()823 bool File_Mpega::Synched_Test()
824 {
825 //Tags
826 if (!File__Tags_Helper::Synched_Test())
827 return false;
828
829 //Padding
830 while (Buffer_Offset<Buffer_Size && Buffer[Buffer_Offset]==0x00)
831 Buffer_Offset++;
832
833 //Must have enough buffer for having header
834 if (Buffer_Offset+3>Buffer_Size)
835 return false;
836
837 //Quick test of synchro
838 if (Buffer[Buffer_Offset ]!=0xFF
839 || (Buffer[Buffer_Offset+1]&0xE0)!=0xE0
840 || (Buffer[Buffer_Offset+2]&0xF0)==0xF0
841 || (Buffer[Buffer_Offset+2]&0x0C)==0x0C)
842 {
843 Synched=false;
844 return true;
845 }
846
847 //Retrieving some info
848 int8u ID0 =(CC1(Buffer+Buffer_Offset+1)>>3)&0x03;
849 int8u layer0 =(CC1(Buffer+Buffer_Offset+1)>>1)&0x03;
850 int8u bitrate_index0 =(CC1(Buffer+Buffer_Offset+2)>>4)&0x0F;
851 int8u sampling_frequency0=(CC1(Buffer+Buffer_Offset+2)>>2)&0x03;
852 if (Mpega_SamplingRate[ID0][sampling_frequency0]==0 || Mpega_Coefficient[ID0][layer0]==0 || Mpega_BitRate[ID0][layer0][bitrate_index0]==0 || Mpega_SlotSize[layer0]==0)
853 {
854 Synched=false;
855 return true;
856 }
857
858 //We continue
859 return true;
860 }
861
862 //***************************************************************************
863 // Buffer - Demux
864 //***************************************************************************
865
866 //---------------------------------------------------------------------------
867 #if MEDIAINFO_DEMUX
Demux_UnpacketizeContainer_Test()868 bool File_Mpega::Demux_UnpacketizeContainer_Test()
869 {
870 //Retrieving some info
871 int8u ID0 =(CC1(Buffer+Buffer_Offset+1)>>3)&0x03;
872 int8u layer0 =(CC1(Buffer+Buffer_Offset+1)>>1)&0x03;
873 int8u bitrate_index0 =(CC1(Buffer+Buffer_Offset+2)>>4)&0x0F;
874 int8u sampling_frequency0=(CC1(Buffer+Buffer_Offset+2)>>2)&0x03;
875 int8u padding_bit0 =(CC1(Buffer+Buffer_Offset+2)>>1)&0x01;
876
877 if (Mpega_SamplingRate[ID][sampling_frequency]==0 || Mpega_Coefficient[ID][layer]==0 || Mpega_BitRate[ID][layer][bitrate_index]==0 || Mpega_SlotSize[layer]==0)
878 return true; //Synhro issue
879
880 #if MEDIAINFO_ADVANCED
881 if (Frame_Count && File_Demux_Unpacketize_StreamLayoutChange_Skip)
882 {
883 int8u mode0 =CC1(Buffer+Buffer_Offset+3)>>6;
884 if (sampling_frequency0!=sampling_frequency_Frame0 || Mpega_Channels[mode0]!=Mpega_Channels[mode_Frame0])
885 {
886 return true;
887 }
888 }
889 #endif //MEDIAINFO_ADVANCED
890
891 Demux_Offset=Buffer_Offset+(Mpega_Coefficient[ID0][layer0]*Mpega_BitRate[ID0][layer0][bitrate_index0]*1000/Mpega_SamplingRate[ID0][sampling_frequency0]+(padding_bit0?1:0))*Mpega_SlotSize[layer0];
892
893 if (Demux_Offset>Buffer_Size)
894 return false;
895
896 Demux_UnpacketizeContainer_Demux();
897
898 return true;
899 }
900 #endif //MEDIAINFO_DEMUX
901
902 //***************************************************************************
903 // Buffer - Per element
904 //***************************************************************************
905
906 //---------------------------------------------------------------------------
Header_Parse()907 void File_Mpega::Header_Parse()
908 {
909 //Parsing
910 BS_Begin();
911 Skip_S2(11, "syncword");
912 Get_S1 (2, ID, "ID"); Param_Info1(Mpega_Version[ID]);
913 Get_S1 (2, layer, "layer"); Param_Info1(Mpega_Layer[layer]);
914 Get_SB ( protection_bit, "protection_bit");
915 Get_S1 (4, bitrate_index, "bitrate_index"); Param_Info2(Mpega_BitRate[ID][layer][bitrate_index], " Kbps");
916 Get_S1 (2, sampling_frequency, "sampling_frequency"); Param_Info2(Mpega_SamplingRate[ID][sampling_frequency], " Hz");
917 Get_SB ( padding_bit, "padding_bit");
918 Skip_SB( "private_bit");
919 Get_S1 (2, mode, "mode"); Param_Info2(Mpega_Channels[mode], " channels"); Param_Info1(Mpega_Codec_Profile[mode]);
920 Get_S1 (2, mode_extension, "mode_extension"); Param_Info1(Mpega_Codec_Profile_Extension[mode_extension]);
921 Get_SB ( copyright, "copyright");
922 Get_SB ( original_home, "original_home");
923 Get_S1 (2, emphasis, "emphasis"); Param_Info1(Mpega_Emphasis[emphasis]);
924 BS_End();
925
926 //Coherancy
927 if (Mpega_SamplingRate[ID][sampling_frequency]==0 || Mpega_Coefficient[ID][layer]==0 || Mpega_BitRate[ID][layer][bitrate_index]==0 || Mpega_SlotSize[layer]==0)
928 {
929 Element_Offset=1;
930 Header_Fill_Size(1);
931 Header_Fill_Code(0, "False start");
932 Synched=false;
933 return;
934 }
935
936 //Filling
937 int64u Size = ((int64u)Mpega_Coefficient[ID][layer] * (int64u)Mpega_BitRate[ID][layer][bitrate_index] * 1000 / (int64u)Mpega_SamplingRate[ID][sampling_frequency] + (padding_bit ? 1 : 0)) * (int64u)Mpega_SlotSize[layer];
938
939 //Special case: tags is inside the last frame
940 if (File_Offset+Buffer_Offset+Size>=File_Size-File_EndTagSize)
941 Size=File_Size-File_EndTagSize-(File_Offset+Buffer_Offset);
942
943 Header_Fill_Size(Size);
944 Header_Fill_Code(0, "frame");
945
946 //Filling error detection
947 sampling_frequency_Count[sampling_frequency]++;
948 mode_Count[mode]++;
949
950 FILLING_BEGIN();
951 #if MEDIAINFO_DEMUX
952 #if MEDIAINFO_ADVANCED
953 if (!Frame_Count)
954 {
955 File_Demux_Unpacketize_StreamLayoutChange_Skip=Config->File_Demux_Unpacketize_StreamLayoutChange_Skip_Get();
956 if (File_Demux_Unpacketize_StreamLayoutChange_Skip)
957 {
958 sampling_frequency_Frame0=sampling_frequency;
959 mode_Frame0=mode;
960 }
961 }
962 #endif //MEDIAINFO_ADVANCED
963 #endif //MEDIAINFO_DEMUX
964 FILLING_END();
965 }
966
967 //***************************************************************************
968 // Elements
969 //***************************************************************************
970
971 //---------------------------------------------------------------------------
Data_Parse()972 void File_Mpega::Data_Parse()
973 {
974 //If false start
975 if (Element_Size==0)
976 {
977 Element_DoNotShow();
978 return;
979 }
980
981 //Partial frame
982 if (Header_Size + Element_Size<((int64u)Mpega_Coefficient[ID][layer] * (int64u)Mpega_BitRate[ID][layer][bitrate_index] * 1000 / (int64u)Mpega_SamplingRate[ID][sampling_frequency] + (padding_bit ? 1 : 0)) * (int64u)Mpega_SlotSize[layer])
983 {
984 Element_Name("Partial frame");
985 Skip_XX(Element_Size, "Data");
986 return;
987 }
988
989 //PTS
990 Element_Info1C((FrameInfo.PTS!=(int64u)-1), __T("PTS ")+Ztring().Duration_From_Milliseconds(float64_int64s(((float64)FrameInfo.PTS)/1000000)));
991
992 //Name
993 Element_Info1(__T("Frame ")+Ztring::ToZtring(Frame_Count));
994
995 //VBR and library headers
996 if (Frame_Count<3) //No need to do it too much
997 {
998 if (!Header_Xing())
999 Header_VBRI();
1000 }
1001
1002 //Counting
1003 if (File_Offset+Buffer_Offset+Element_Size==File_Size-File_EndTagSize)
1004 Frame_Count_Valid=Frame_Count; //Finish MPEG Audio frames in case of there are less than Frame_Count_Valid frames
1005 if (Frame_Count==0 && Frame_Count_NotParsedIncluded==0)
1006 PTS_Begin=FrameInfo.PTS;
1007 LastSync_Offset=File_Offset+Buffer_Offset+Element_Size;
1008 {
1009 int16u Samples;
1010 if (ID==3 && layer==3) //MPEG 1 layer 1
1011 Samples=384;
1012 else if ((ID==2 || ID==0) && layer==1) //MPEG 2 or 2.5 layer 3
1013 Samples=576;
1014 else
1015 Samples=1152;
1016
1017 Frequency_b=Mpega_SamplingRate[ID][sampling_frequency];
1018 TS_Add(Samples);
1019 }
1020
1021 //LAME
1022 if (Encoded_Library.empty() && (Frame_Count<Frame_Count_Valid || File_Offset+Buffer_Offset+Element_Size==File_Size-File_EndTagSize)) //Can be elsewhere... At the start, or end frame
1023 Header_Encoders();
1024
1025 //Filling
1026 BitRate_Count[Mpega_BitRate[ID][layer][bitrate_index]]++;
1027 Channels_Count[mode]++;
1028 Extension_Count[mode_extension]++;
1029 Emphasis_Count[emphasis]++;
1030
1031 if (Status[IsFilled])
1032 {
1033 Skip_XX(Element_Size, "Data");
1034 return;
1035 }
1036
1037 //error_check
1038 if (!protection_bit)
1039 {
1040 Element_Begin1("error_check");
1041 Skip_B2( "crc_check");
1042 Element_End0();
1043 }
1044
1045 //audio_data
1046 Element_Begin1("audio_data");
1047 switch (layer)
1048 {
1049 case 1 : //Layer 3
1050 audio_data_Layer3();
1051 break;
1052 default: Skip_XX(Element_Size-Element_Offset, "(data)");
1053 }
1054 Element_End0();
1055
1056 //MP3 Surround detection
1057 for (int64u Element_Offset_S=Element_Offset; Element_Offset_S+4<Element_Size; Element_Offset_S++)
1058 {
1059 if ( Buffer[(size_t)(Buffer_Offset+Element_Offset_S )] ==0xCF
1060 && (Buffer[(size_t)(Buffer_Offset+Element_Offset_S+1)]&0xF0)==0x30) //12 bits, 0xCF3x
1061 {
1062 int8u Surround_Size=((Buffer[(size_t)(Buffer_Offset+Element_Offset_S+1)]&0x0F)<<4)
1063 | ((Buffer[(size_t)(Buffer_Offset+Element_Offset_S+2)]&0xF0)>>4);
1064 int16u CRC12 =((Buffer[(size_t)(Buffer_Offset+Element_Offset_S+2)]&0x0F)<<8)
1065 | Buffer[(size_t)(Buffer_Offset+Element_Offset_S+3)];
1066 if (Element_Offset_S+Surround_Size-4>Element_Size)
1067 break;
1068
1069 //CRC
1070 int16u CRC12_Calculated=0x0FFF;
1071 int8u* Data=(int8u*)Buffer+(size_t)(Buffer_Offset+Element_Offset_S+4);
1072 if (Element_Offset_S+Surround_Size+4>=Element_Size)
1073 break;
1074 for (int8u Surround_Pos=0; Surround_Pos<Surround_Size-4; Surround_Pos++)
1075 CRC12_Calculated=0x0FFF & (((CRC12_Calculated<<8)&0xff00)^Mpega_CRC12_Table[((CRC12_Calculated>>4) ^ *Data++) & 0xff]);
1076 if (CRC12_Calculated!=CRC12)
1077 break;
1078
1079 //Parsing
1080 Skip_XX(Element_Offset_S-Element_Offset, "data");
1081 BS_Begin();
1082 Element_Begin1("Surround");
1083 Skip_S2(12, "Sync");
1084 Skip_S1( 8, "Size");
1085 Skip_S2(12, "CRC12");
1086 BS_End();
1087 Skip_XX(Surround_Size-4, "data");
1088 Element_End0();
1089
1090 //Filling
1091 Surround_Frames++;
1092 break;
1093 }
1094 }
1095
1096 if (Element_Offset<Element_Size)
1097 Skip_XX(Element_Size-Element_Offset, "next data");
1098
1099 FILLING_BEGIN();
1100 //Filling
1101 if (IsSub && BitRate_Count.size()>1 && !Encoded_Library.empty())
1102 Frame_Count_Valid=Frame_Count;
1103 if (!Status[IsAccepted])
1104 File__Analyze::Accept("MPEG Audio");
1105 if (!Status[IsFilled] && Frame_Count>=Frame_Count_Valid)
1106 {
1107 Fill("MPEG Audio");
1108
1109 //Jumping
1110 if (!IsSub && Config->ParseSpeed<1.0 && File_Offset+Buffer_Offset<File_Size/2)
1111 {
1112 File__Tags_Helper::GoToFromEnd(16*1024, "MPEG-A");
1113 LastSync_Offset=(int64u)-1;
1114 if (File_GoTo!=(int64u)-1)
1115 Open_Buffer_Unsynch();
1116 }
1117 }
1118
1119 //Detect Id3v1 tags inside a frame
1120 if (!IsSub && File_Offset+Buffer_Offset+(size_t)Element_Size>File_Size-File_EndTagSize)
1121 {
1122 Open_Buffer_Unsynch();
1123 File__Analyze::Data_GoTo(File_Size-File_EndTagSize, "Tags inside a frame, parsing the tags");
1124 }
1125 FILLING_END();
1126 }
1127
1128 //---------------------------------------------------------------------------
audio_data_Layer3()1129 void File_Mpega::audio_data_Layer3()
1130 {
1131 if (mode>=4)
1132 return;
1133 const bool mono=(mode==3);
1134 const bool mpeg1=(ID==3);
1135 int16u main_data_end;
1136 BS_Begin();
1137 Get_S2 (mpeg1?9:8, main_data_end, "main_data_end");
1138 if ((int32u)main_data_end>Reservoir_Max)
1139 Reservoir_Max=main_data_end;
1140 Reservoir+=main_data_end;
1141 if (mpeg1) //MPEG-1
1142 {
1143 Skip_S1(mono?5:3, "private_bits");
1144 }
1145 else
1146 {
1147 Skip_S1(mono?1:2, "private_bits");
1148 }
1149 if (mpeg1) //MPEG-1
1150 {
1151 Element_Begin1("scfsi");
1152 for(int8u ch=0; ch<Mpega_Channels[mode]; ch++)
1153 for(int8u scfsi_band=0; scfsi_band<4; scfsi_band++)
1154 {
1155 bool scfsi;
1156 Get_SB ( scfsi, "scfsi");
1157 if (scfsi)
1158 Scfsi++;
1159 }
1160 Element_End0();
1161 }
1162 for(int8u gr=0; gr<(ID==3?2:1); gr++)
1163 {
1164 Element_Begin1("granule");
1165 for(int8u ch=0; ch<Mpega_Channels[mode]; ch++)
1166 {
1167 Element_Begin1("channel");
1168 Skip_S2(12, "part2_3_length");
1169 Skip_S2(9, "big_values");
1170 Skip_S1(8, "global_gain");
1171 if (mpeg1) //MPEG-1
1172 Skip_S1(4, "scalefac_compress");
1173 else
1174 Skip_S2(9, "scalefac_compress");
1175 bool blocksplit_flag;
1176 Get_SB ( blocksplit_flag, "blocksplit_flag");
1177 if (blocksplit_flag==1)
1178 {
1179 int8u block_type;
1180 bool mixed_block_flag;
1181 Get_S1 (2, block_type, "block_type");
1182 Get_SB ( mixed_block_flag, "mixed_block_flag");
1183 for (int8u region=0; region<2; region++)
1184 Skip_S1(5, "table_select");
1185 for (int8u window=0; window<3; window++)
1186 Skip_S1(3, "subblock_gain");
1187 if (block_type == 2)
1188 {
1189 if (mixed_block_flag==1)
1190 {
1191 Param_Info1("Mixed");
1192 Block_Count[2]++; //Mixed
1193 }
1194 else
1195 {
1196 Param_Info1("Short");
1197 Block_Count[1]++; //Short
1198 }
1199 }
1200 else
1201 {
1202 Param_Info1("Long");
1203 Block_Count[0]++; //Long
1204 }
1205 }
1206 else
1207 {
1208 for (int8u region=0; region<3; region++)
1209 Skip_S1(5, "table_select");
1210 Skip_S1(4, "region0_count");
1211 Skip_S1(3, "region1_count");
1212 Param_Info1("Long");
1213 Block_Count[0]++; //Long
1214 }
1215 if (mpeg1) //MPEG-1
1216 Skip_SB( "preflag");
1217 bool scalefac;
1218 Get_SB ( scalefac, "scalefac_scale");
1219 if (scalefac)
1220 Scalefac++;
1221 Skip_SB( "count1table_select");
1222 Element_End0();
1223 } //channels
1224 Element_End0();
1225 } //granules
1226 BS_End();
1227 //Skip_XX(Element_Size-main_data_end-Element_Offset, "main_data");
1228 }
1229
1230 //---------------------------------------------------------------------------
Data_Parse_Fill()1231 void File_Mpega::Data_Parse_Fill()
1232 {
1233 }
1234
1235 //---------------------------------------------------------------------------
Header_Xing()1236 bool File_Mpega::Header_Xing()
1237 {
1238 int32u Xing_Header_Offset;
1239 if (ID==3) //MPEG-1
1240 if (mode==3) //Mono
1241 Xing_Header_Offset=21-4;
1242 else
1243 Xing_Header_Offset=36-4;
1244 else //MPEG-2 or 2.5
1245 if (mode==3) //Mono
1246 Xing_Header_Offset=13-4;
1247 else
1248 Xing_Header_Offset=21-4;
1249 if (Buffer_Offset+Xing_Header_Offset+128<Buffer_Size)
1250 {
1251 const int8u* Xing_Header=Buffer+Buffer_Offset+Xing_Header_Offset;
1252 if (CC4(Xing_Header)==CC4("Xing") || CC4(Xing_Header)==CC4("Info"))
1253 {
1254 //This is a "tag"
1255 Element_Info1("Tag (Xing)");
1256
1257 //Parsing
1258 Element_Begin1("Xing");
1259 Element_Begin1("Xing header");
1260 Skip_XX(Xing_Header_Offset, "Junk");
1261 int32u Flags;
1262 bool FrameCount, FileSize, TOC, Scale, Lame;
1263 Skip_C4( "Xing");
1264 Get_B4 (Flags, "Flags");
1265 Get_Flags(Flags, 0, FrameCount, "FrameCount");
1266 Get_Flags(Flags, 1, FileSize, "FileSize");
1267 Get_Flags(Flags, 2, TOC, "TOC");
1268 Get_Flags(Flags, 3, Scale, "Scale");
1269 Get_Flags(Flags, 4, Lame, "Lame");
1270 int32u Xing_Header_Size=8
1271 +(FrameCount? 4:0) //FrameCount
1272 +(FileSize? 4:0) //FileSize
1273 +(TOC? 100:0) //TOC
1274 +(Scale? 4:0) //Scale
1275 +(Lame? 348:0); //Lame
1276 Element_End0();
1277 //Element size
1278 if (Xing_Header_Size>Element_Size-Xing_Header_Offset)
1279 return false; //Error tag size
1280
1281 //Parsing
1282 if (FrameCount)
1283 {
1284 Get_B4 (VBR_Frames, "FrameCount"); //FrameCount exclude this frame
1285 VBR_Frames_IsCbr=(CC4(Xing_Header)==CC4("Info"));
1286 }
1287 if (FileSize)
1288 {
1289 int32u VBR_FileSize_Temp;
1290 Get_B4 (VBR_FileSize_Temp, "FileSize");
1291 if (VBR_FileSize_Temp>4+Element_Size)
1292 VBR_FileSize=VBR_FileSize_Temp-4-Element_Size; //FileSize include the Xing element
1293 }
1294 if (TOC)
1295 Skip_XX(100, "TOC");
1296 if (Scale)
1297 Get_B4 (Xing_Scale, "Scale");
1298 string Lib;
1299 Element_End0();
1300 Peek_String(4, Lib);
1301 if (Lame || Lib=="LAME" || Lib=="GOGO" || Lib=="L3.9")
1302 Header_Encoders_Lame();
1303
1304 //Clearing Error detection
1305 sampling_frequency_Count.clear();
1306 mode_Count.clear();
1307
1308 return true;
1309 }
1310 }
1311 return false;
1312 }
1313
1314 //---------------------------------------------------------------------------
Header_VBRI()1315 bool File_Mpega::Header_VBRI()
1316 {
1317 const size_t Fraunhofer_Header_Offset=36-4;
1318 if (Buffer_Offset+Fraunhofer_Header_Offset+32<Buffer_Size)
1319 {
1320 const int8u* Fraunhofer_Header=Buffer+Buffer_Offset+Fraunhofer_Header_Offset;
1321 if (CC4(Fraunhofer_Header)==CC4("VBRI") && CC2(Fraunhofer_Header+4)==0x0001) //VBRI v1 only
1322 {
1323 //This is a "tag"
1324
1325 Element_Info1("Tag (VBRI)");
1326
1327 //Parsing
1328 int32u VBR_FileSize_Temp;
1329 int16u TableSize, TableScale, EntryBytes;
1330 Skip_XX(Fraunhofer_Header_Offset, "Junk");
1331 Element_Begin1("VBRI");
1332 Skip_C4( "Sync");
1333 Skip_B2( "Version");
1334 Skip_B2( "Delay");
1335 Skip_B2( "Quality");
1336 Get_B4 (VBR_FileSize_Temp, "StreamBytes");
1337 Get_B4 (VBR_Frames, "StreamFrames"); //Multiplied by SamplesPerFrame (1152 for >=32KHz, else 576) --> Duration in samples
1338 Get_B2 (TableSize, "TableSize");
1339 Get_B2 (TableScale, "TableScale");
1340 Get_B2 (EntryBytes, "EntryBytes");
1341 Skip_B2( "EntryFrames"); //Count of frames per entry
1342 Element_Begin1("Table");
1343 for (int16u Pos=0; Pos<TableSize; Pos++)
1344 {
1345 switch (EntryBytes)
1346 {
1347 case 1 : {Info_B1(Entry, "Entry"); Param_Info2 (Entry*TableScale, " bytes");} break;
1348 case 2 : {Info_B2(Entry, "Entry"); Param_Info2 (Entry*TableScale, " bytes");} break;
1349 case 4 : {Info_B4(Entry, "Entry"); Param_Info2 (Entry*TableScale, " bytes");} break;
1350 default: Skip_XX(EntryBytes, "Entry");
1351 }
1352 }
1353 Element_End0();
1354 Element_End0();
1355 VBR_FileSize=VBR_FileSize_Temp;
1356
1357 //Clearing Error detection
1358 sampling_frequency_Count.clear();
1359 mode_Count.clear();
1360
1361 return true;
1362 }
1363 }
1364 return false;
1365 }
1366
1367 //---------------------------------------------------------------------------
Header_Encoders()1368 bool File_Mpega::Header_Encoders()
1369 {
1370 std::string BufferS((const char*)(Buffer+Buffer_Offset), (size_t)Element_Size);
1371 size_t Buffer_Pos;
1372
1373 //Lame
1374 Buffer_Pos=BufferS.find("LAME");
1375 if (Buffer_Pos!=std::string::npos && Buffer_Pos<=Element_Size-8)
1376 {
1377 Element_Info1("With tag (Lame)");
1378 Element_Offset=Buffer_Pos;
1379 if (Element_Offset+20<=Element_Size)
1380 Get_String (20, Encoded_Library, "Encoded_Library");
1381 else
1382 Get_String ( 8, Encoded_Library, "Encoded_Library");
1383 Encoded_Library.erase(Encoded_Library.find_last_not_of("AU\xAA")+1);
1384 Element_Offset=0; //Reseting it
1385 return true;
1386 }
1387
1388 //RCA
1389 Buffer_Pos=BufferS.find("RCA mp3PRO Encoder");
1390 if (Buffer_Pos!=std::string::npos && Buffer_Pos<Element_Size-23)
1391 {
1392 Element_Info1("With tag (RCA)");
1393 Encoded_Library="RCA ";
1394 Encoded_Library+=string((const char*)(Buffer+Buffer_Offset+18), 5);
1395 return true;
1396 }
1397
1398 //Thomson
1399 Buffer_Pos=BufferS.find("THOMSON mp3PRO Encoder");
1400 if (Buffer_Pos!=std::string::npos && Buffer_Pos<Element_Size-29)
1401 {
1402 Element_Info1("With tag (Thomson)");
1403 Encoded_Library="Thomson ";
1404 Encoded_Library+=string((const char*)(Buffer+Buffer_Offset+22), 6);
1405 return true;
1406 }
1407
1408 //Gogo (old)
1409 Buffer_Pos=BufferS.find("MPGE");
1410 if (Buffer_Pos!=std::string::npos)
1411 {
1412 Element_Info1("With tag (Gogo)");
1413 Encoded_Library="Gogo <3.0";
1414 return true;
1415 }
1416
1417 //Gogo (new)
1418 Buffer_Pos=BufferS.find("GOGO");
1419 if (Buffer_Pos!=std::string::npos)
1420 {
1421 Element_Info1("With tag (Gogo)");
1422 Encoded_Library="Gogo >=3.0";
1423 return true;
1424 }
1425
1426 return false;
1427 }
1428
Header_Encoders_Lame()1429 void File_Mpega::Header_Encoders_Lame()
1430 {
1431 bool HasInfoTag=false;
1432 if (Element_Offset+9<=Element_Size)
1433 {
1434 const int8u* Tag=Buffer+Buffer_Offset+(size_t)Element_Offset;
1435 int32u Name=BigEndian2int32u(Tag);
1436 if (Name==0x4C414D45 // "LAME"
1437 && Tag[5]=='.')
1438 {
1439 //Needs addtional tests, as v3.89 and less have no Lame Info tag, but v3.100 exists too
1440 if ( Tag[4]> '3' // v4 or more
1441 || (Tag[4]=='3' && Tag[6]=='9') // v3.9yz-v3.9yz
1442 || Tag[4]=='3' && Tag[8]>='0' && Tag[8]<='9') // v3.xy0-v3.xy9
1443 HasInfoTag=true;
1444 }
1445 if (Name==0x4C332E39 // "L3.9"
1446 && Tag[4]=='9')
1447 HasInfoTag=true; //Form old code, to be confirmed: Ugly version string in Lame 3.99.1 "L3.99r1\0".
1448 }
1449 if (HasInfoTag)
1450 {
1451 int8u Flags, lowpass, EncodingFlags, BitRate, StereoMode;
1452 Param_Info1(Ztring(__T("V "))+Ztring::ToZtring((100-Xing_Scale)/10));
1453 Param_Info1(Ztring(__T("q "))+Ztring::ToZtring((100-Xing_Scale)%10));
1454 Get_String (9, Encoded_Library, "Encoded_Library");
1455 Get_B1 (Flags, "Flags");
1456 if ((Flags&0xF0)<=0x20) //Rev. 0 or 1, http://gabriel.mp3-tech.org/mp3infotag.html and Rev. 2 was seen.
1457 {
1458 Param_Info1(Lame_Method[Flags&0x0F]);
1459 BitRate_Mode=Lame_BitRate_Mode[Flags&0x0F];
1460 if ((Flags&0x0F)==1 || (Flags&0x0F)==8) //2 possible values for CBR
1461 VBR_Frames=0;
1462 }
1463 Get_B1 (lowpass, "Lowpass filter value"); Param_Info2(lowpass*100, " Hz");
1464 Skip_B4( "Peak signal amplitude");
1465 Skip_B2( "Radio Replay Gain");
1466 Skip_B2( "Audiophile Replay Gain");
1467 Get_B1 (EncodingFlags, "Encoding Flags"); Param_Info1(Ztring(__T("ATH Type="))+Ztring::ToZtring(Flags&0x0F));
1468 Skip_Flags(EncodingFlags, 4, "nspsytune");
1469 Skip_Flags(EncodingFlags, 5, "nssafejoint");
1470 Skip_Flags(EncodingFlags, 6, "nogap (after)");
1471 Skip_Flags(EncodingFlags, 7, "nogap (before)");
1472 Get_B1 (BitRate, "BitRate");
1473 Skip_B3( "Encoder delays");
1474 BS_Begin();
1475 Skip_S1(2, "Source sample frequency");
1476 Skip_SB( "unwise settings used");
1477 Get_S1 (3, StereoMode, "Stereo mode");
1478 Skip_S1(2, "noise shapings");
1479 BS_End();
1480 Skip_B1( "MP3 Gain");
1481 Skip_B2( "Preset and surround info");
1482 Skip_B4( "MusicLength");
1483 Skip_B2( "MusicCRC");
1484 Skip_B2( "CRC-16 of Info Tag");
1485
1486 FILLING_BEGIN();
1487 Encoded_Library_Settings+=__T("-m ");
1488 switch(StereoMode)
1489 {
1490 case 0 : Encoded_Library_Settings+=__T("m"); break;
1491 case 1 : Encoded_Library_Settings+=__T("s"); break;
1492 case 2 : Encoded_Library_Settings+=__T("d"); break;
1493 case 3 : Encoded_Library_Settings+=__T("j"); break;
1494 case 4 : Encoded_Library_Settings+=__T("f"); break;
1495 case 5 : Encoded_Library_Settings+=__T("a"); break;
1496 case 6 : Encoded_Library_Settings+=__T("i"); break;
1497 default: ;
1498 }
1499 if (Xing_Scale<=100) //Xing_Scale is used for LAME quality
1500 {
1501 Encoded_Library_Settings+=__T( " -V ")+Ztring::ToZtring((100-Xing_Scale)/10);
1502 Encoded_Library_Settings+=__T( " -q ")+Ztring::ToZtring((100-Xing_Scale)%10);
1503 }
1504 if (lowpass)
1505 Encoded_Library_Settings+=(Encoded_Library_Settings.empty()?__T("-lowpass "):__T(" -lowpass "))+((lowpass%10)?Ztring::ToZtring(((float)lowpass)/10, 1):Ztring::ToZtring(lowpass/10));
1506 switch (Flags&0x0F)
1507 {
1508 case 2 :
1509 case 9 : //ABR
1510 Encoded_Library_Settings+=__T(" --abr"); break;
1511 case 3 : //VBR (old/rh)
1512 Encoded_Library_Settings+=__T(" --vbr-old"); break;
1513 case 4 : //VBR (new/mtrh)
1514 Encoded_Library_Settings+=__T(" --vbr-new"); break;
1515 case 5 : //VBR (?/mt)
1516 Encoded_Library_Settings+=__T(" --vbr-mt"); break;
1517 default : ;
1518 }
1519 if (BitRate!=0x00 && BitRate!=0xFF)
1520 {
1521 switch (Flags&0x0F)
1522 {
1523 case 1 :
1524 case 8 : //CBR
1525 Encoded_Library_Settings+=__T(" -b ")+Ztring::ToZtring(BitRate);
1526 break;
1527 case 2 :
1528 case 9 : //ABR
1529 BitRate_Nominal.From_Number(BitRate*1000);
1530 Encoded_Library_Settings+=__T(" ")+Ztring::ToZtring(BitRate);
1531 break;
1532 case 3 : //VBR (old/rh)
1533 case 4 : //VBR (new/mtrh)
1534 case 5 : //VBR (?/mt)
1535 BitRate_Minimum.From_Number(BitRate*1000);
1536 Encoded_Library_Settings+=__T(" -b ")+Ztring::ToZtring(BitRate);
1537 break;
1538 default : ;
1539 }
1540 }
1541 FILLING_END();
1542 }
1543 else
1544 Get_String (20, Encoded_Library, "Encoded_Library");
1545 }
1546
Encoded_Library_Guess()1547 void File_Mpega::Encoded_Library_Guess()
1548 {
1549 //TODO: Not yet enough precise
1550
1551 /*
1552 if (Block_Count[1]==0) //No short blocks
1553 {
1554 if (mode==2) //Dual Mono
1555 {
1556 if (Scfsi>0) //scfsi used
1557 {}
1558 else //no scfsi
1559 {
1560 if (Scalefac>0) //scalefacors used
1561 {}
1562 else //scalefacors not used
1563 Encoded_Library="Shine";
1564 }
1565 }
1566 else //Other than dual mono
1567 {
1568 if (Extension_Count[1]>0 || Extension_Count[3]>0) //Intensity Stereo
1569 Encoded_Library="Xing (very old)";
1570 else //No Intensity Stereo
1571 {
1572 if (Scfsi>0) //Scfsi used
1573 Encoded_Library="Xing (new)";
1574 else //Scsfi not used
1575 {
1576 if (Channels_Count[2]>0) //Joint Stereo
1577 {
1578 if (Channels_Count[0]>0) //also includes no Joint Stereo frames
1579 {
1580 if (padding_bit) //Padding
1581 {
1582 if (original_home)
1583 Encoded_Library="FhG (l3enc)";
1584 else
1585 Encoded_Library="FhG (fastenc or mp3enc)";
1586 }
1587 else //No padding
1588 Encoded_Library="FhG (ACM or producer pro)";
1589 }
1590 else //No stereo frames: joint stereo was forced
1591 {
1592 if (padding_bit && !original_home && !copyright)
1593 Encoded_Library="QDesign (fast mode)";
1594 }
1595 }
1596 else
1597 {
1598 if (Channels_Count[0]>0 && Scalefac==0 && !original_home) //Stereo
1599 Encoded_Library="Plugger";
1600 else
1601 Encoded_Library="Xing (old)";
1602 }
1603 }
1604 }
1605 }
1606 }
1607 else //Short blocks
1608 {
1609 if (Scfsi) //scfsi used
1610 {
1611 if (Scalefac>0) //Scalefactor used
1612 Encoded_Library="Gogo (after 3.0)"; //Could be lame, but with a label, detected elsewhere before
1613 else
1614 Encoded_Library="Lame (old) or m3e";
1615 }
1616 else //Scfsi not used
1617 {
1618 if (Scalefac>0) //Scalefactor used
1619 {
1620 if (padding_bit)
1621 {
1622 if (original_home)
1623 {
1624 //10 last bytes
1625 //int sum = get_final_sum(data);
1626 //if (sum==0)
1627 // return guess = __T("FhG (fastenc, low quality mode)");
1628 //else if (sum==10 * 0xFF)
1629 // return guess = __T("FhG (l3enc)");
1630 //else if (sum==5 * 0x20)
1631 // return guess = __T("FhG (fastenc, medium or high quality mode)");
1632 //else
1633 // return guess = __T("FhG (l3enc or fastenc)");
1634 }
1635 else
1636 {
1637 if (Channels_Count[1]>0 && Extension_Count[1]>0) //Joint Stereo and some Intensity Stereo
1638 Encoded_Library="Thomson mp3PRO Encoder";
1639 else
1640 Encoded_Library="FhG (fastenc or mp3enc)";
1641 }
1642 }
1643 else //No padding
1644 {
1645 if (BitRate_Mode.find(__T("VBR"))==0) //VBR
1646 Encoded_Library="FhG (fastenc)";
1647 else
1648 Encoded_Library="FhG (ACM or producer pro)";
1649 }
1650 }
1651 else //scalefactors not used
1652 {
1653 if (Channels_Count[1]>0) //Joint Stereo
1654 {
1655 if (padding_bit && !original_home && !copyright)
1656 Encoded_Library="QDesign";
1657 }
1658 else //Joint Stereo not used
1659 {
1660 if (BitRate_Mode.find(__T("VBR"))==0) //VBR
1661 Encoded_Library="Lame (old)";
1662 else //CBR
1663 {
1664
1665 if (mode==2) //Dual Mono
1666 {
1667 if (padding_bit)
1668 Encoded_Library="Blade";
1669 else
1670 Encoded_Library="dist10 encoder or other encoder";
1671 }
1672 else //Stereo or Mono
1673 {
1674 //if (data.av_reservoir < 40 && !data.vbr) //ISO based encoders are unable to properly use bit reservoir... average reservoir usage is about 10
1675 //{
1676 // if (data.padding)
1677 // return guess = __T("Blade");
1678 // else
1679 // return guess = __T("dist10 encoder or other encoder");
1680 //}
1681 //else
1682 // return guess = __T("Gogo (before 3.0)");
1683 }
1684 }
1685 }
1686 }
1687 }
1688 }
1689 */
1690 }
1691
1692 //***************************************************************************
1693 // C++
1694 //***************************************************************************
1695
1696 } //NameSpace
1697
1698 #endif //MEDIAINFO_MPEGA_YES
1699
1700