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 // Pre-compilation
9 #include "MediaInfo/PreComp.h"
10 #ifdef __BORLANDC__
11     #pragma hdrstop
12 #endif
13 //---------------------------------------------------------------------------
14 
15 //---------------------------------------------------------------------------
16 #include "MediaInfo/Setup.h"
17 //---------------------------------------------------------------------------
18 
19 //---------------------------------------------------------------------------
20 #if defined(MEDIAINFO_AVSV_YES)
21 //---------------------------------------------------------------------------
22 
23 //---------------------------------------------------------------------------
24 #include "MediaInfo/Video/File_AvsV.h"
25 #undef FILLING_BEGIN
26 #define FILLING_BEGIN() \
27     while (Element_Offset<Element_Size && Buffer[Buffer_Offset+(size_t)Element_Offset]==0x00) \
28         Element_Offset++; \
29     if (Element_Offset!=Element_Size) \
30         Trusted_IsNot("Size error"); \
31     else if (Element_IsOK()) \
32     {
33 //---------------------------------------------------------------------------
34 
35 namespace MediaInfoLib
36 {
37 
38 //***************************************************************************
39 // Infos
40 //***************************************************************************
41 
42 //---------------------------------------------------------------------------
AvsV_profile(int8u profile_id)43 Ztring AvsV_profile(int8u profile_id)
44 {
45     switch (profile_id)
46     {
47         case 0x20 : return "Base";
48         default :
49             return Ztring::ToZtring(profile_id);
50     }
51 }
52 
53 //---------------------------------------------------------------------------
AvsV_level(int8u level_id)54 Ztring AvsV_level(int8u level_id)
55 {
56     switch (level_id)
57     {
58         case 0x00 : return Ztring();
59         case 0x10 : return "@2.0";
60         case 0x20 : return "@4.0";
61         case 0x22 : return "@4.2";
62         case 0x40 : return "@6.0";
63         case 0x42 : return "@6.2";
64         default :
65             return __T('@')+Ztring::ToZtring(level_id);
66     }
67 }
68 
69 //---------------------------------------------------------------------------
70 static const float32 AvsV_frame_rate[]=
71 {
72     (float32)0,
73     ((float32)24000)/1001,
74     (float32)24,
75     (float32)25,
76     ((float32)30000)/1001,
77     (float32)30,
78     (float32)50,
79     ((float32)60000)/1001,
80     (float32)60,
81     (float32)0,
82     (float32)0,
83     (float32)0,
84     (float32)0,
85     (float32)0,
86     (float32)0,
87     (float32)0,
88 };
89 
90 //---------------------------------------------------------------------------
91 static const char* AvsV_chroma_format[]=
92 {
93     "",
94     "4:2:0",
95     "4:2:2",
96     "",
97 };
98 
99 //---------------------------------------------------------------------------
100 static const char* AvsV_extension_start_code_identifier[]=
101 {
102     "",
103     "",
104     "sequence_display",
105     "",
106     "copyright",
107     "",
108     "",
109     "picture_display",
110     "",
111     "",
112     "",
113     "camera_parameters",
114     "",
115     "",
116     "",
117     "",
118 };
119 
120 //---------------------------------------------------------------------------
121 static const char* AvsV_video_format[]=
122 {
123     "Component",
124     "PAL",
125     "NTSC",
126     "SECAM",
127     "MAC",
128     "",
129     "",
130     "",
131 };
132 
133 //---------------------------------------------------------------------------
134 static const float32 AvsV_aspect_ratio[]=
135 {
136     (float32)0,
137     (float32)1,
138     (float32)4/(float32)3,
139     (float32)16/(float32)9,
140     (float32)2.21,
141     (float32)0,
142     (float32)0,
143     (float32)0,
144     (float32)0,
145     (float32)0,
146     (float32)0,
147     (float32)0,
148     (float32)0,
149     (float32)0,
150     (float32)0,
151     (float32)0,
152 };
153 
154 //---------------------------------------------------------------------------
155 static const char* AvsV_picture_coding_type[]=
156 {
157     "",
158     "P",
159     "B",
160     "",
161 };
162 
163 //***************************************************************************
164 // Constructor/Destructor
165 //***************************************************************************
166 
167 //---------------------------------------------------------------------------
File_AvsV()168 File_AvsV::File_AvsV()
169 :File__Analyze()
170 {
171     //Config
172     MustSynchronize=true;
173     Buffer_TotalBytes_FirstSynched_Max=64*1024;
174 
175     //In
176     Frame_Count_Valid=30;
177     FrameIsAlwaysComplete=false;
178 
179     //Temp
180     video_sequence_start_IsParsed=false;
181 }
182 
183 //***************************************************************************
184 // Streams management
185 //***************************************************************************
186 
187 //---------------------------------------------------------------------------
Streams_Fill()188 void File_AvsV::Streams_Fill()
189 {
190     //Filling
191     Stream_Prepare(Stream_Video);
192     Fill(Stream_Video, 0, Video_Format, "AVS Video");
193     Fill(Stream_Video, 0, Video_Codec, "AVS Video");
194 
195     //From sequence header
196     Fill(Stream_Video, 0, Video_Format_Profile, AvsV_profile(profile_id)+AvsV_level(level_id));
197     Fill(Stream_Video, 0, Video_Codec_Profile, AvsV_profile(profile_id)+AvsV_level(level_id));
198     Fill(Stream_Video, StreamPos_Last, Video_Width, horizontal_size);
199     Fill(Stream_Video, StreamPos_Last, Video_Height, vertical_size);
200     Fill(Stream_Video, 0, Video_FrameRate, AvsV_frame_rate[frame_rate_code]/(progressive_sequence?1:2));
201     if (aspect_ratio==0)
202         ;//Forbidden
203     else if (aspect_ratio==1)
204             Fill(Stream_Video, 0, Video_PixelAspectRatio, 1.000, 3, true);
205     else if (display_horizontal_size && display_vertical_size)
206     {
207         if (vertical_size && AvsV_aspect_ratio[aspect_ratio])
208             Fill(Stream_Video, StreamPos_Last, Video_DisplayAspectRatio, (float)horizontal_size/vertical_size
209                                                                          *AvsV_aspect_ratio[aspect_ratio]/((float)display_horizontal_size/display_vertical_size), 3, true);
210     }
211     else if (AvsV_aspect_ratio[aspect_ratio])
212         Fill(Stream_Video, StreamPos_Last, Video_DisplayAspectRatio, AvsV_aspect_ratio[aspect_ratio], 3, true);
213     Fill(Stream_Video, 0, Video_ChromaSubsampling, AvsV_chroma_format[chroma_format]);
214     if (progressive_frame_Count && progressive_frame_Count!=Frame_Count)
215     {
216         //This is mixed
217     }
218     else if (Frame_Count>0) //Only if we have at least one progressive_frame definition
219     {
220         if (progressive_sequence || progressive_frame_Count==Frame_Count)
221         {
222             Fill(Stream_Video, 0, Video_ScanType, "Progressive");
223             Fill(Stream_Video, 0, Video_Interlacement, "PPF");
224         }
225         else
226         {
227             Fill(Stream_Video, 0, Video_ScanType, "Interlaced");
228             if ((Interlaced_Top && Interlaced_Bottom) || (!Interlaced_Top && !Interlaced_Bottom))
229                 Fill(Stream_Video, 0, Video_Interlacement, "Interlaced");
230             else
231             {
232                 Fill(Stream_Video, 0, Video_ScanOrder, Interlaced_Top?"TFF":"BFF");
233                 Fill(Stream_Video, 0, Video_Interlacement, Interlaced_Top?"TFF":"BFF");
234             }
235         }
236     }
237     Fill(Stream_Video, 0, Video_BitRate_Nominal, bit_rate*8);
238 
239     //From extensions
240     Fill(Stream_Video, 0, Video_Standard, AvsV_video_format[video_format]);
241 
242     //Library name
243     if (!Library.empty())
244     {
245         Fill(Stream_Video, 0, Video_Encoded_Library, Library);
246         Fill(Stream_Video, 0, Video_Encoded_Library_Name, Library_Name);
247         Fill(Stream_Video, 0, Video_Encoded_Library_Version, Library_Version);
248         Fill(Stream_Video, 0, Video_Encoded_Library_Date, Library_Date);
249     }
250 }
251 
252 //---------------------------------------------------------------------------
Streams_Finish()253 void File_AvsV::Streams_Finish()
254 {
255     //Purge what is not needed anymore
256     if (!File_Name.empty()) //Only if this is not a buffer, with buffer we can have more data
257         Streams.clear();
258 }
259 
260 //***************************************************************************
261 // Buffer - Synchro
262 //***************************************************************************
263 
264 //---------------------------------------------------------------------------
Synched_Test()265 bool File_AvsV::Synched_Test()
266 {
267     //Must have enough buffer for having header
268     if (Buffer_Offset+3>Buffer_Size)
269         return false;
270 
271     //Quick test of synchro
272     if (CC3(Buffer+Buffer_Offset)!=0x000001)
273         Synched=false;
274 
275     //Quick search
276     if (Synched && !Header_Parser_QuickSearch())
277         return false;
278 
279     //We continue
280     return true;
281 }
282 
283 //---------------------------------------------------------------------------
Synched_Init()284 void File_AvsV::Synched_Init()
285 {
286     //Count of a Packets
287     progressive_frame_Count=0;
288     Interlaced_Top=0;
289     Interlaced_Bottom=0;
290 
291     //Temp
292     bit_rate=0;
293     horizontal_size=0;
294     vertical_size=0;
295     display_horizontal_size=0;
296     display_vertical_size=0;
297     profile_id=0;
298     level_id=0;
299     chroma_format=0;
300     aspect_ratio=0;
301     frame_rate_code=0;
302     video_format=5; //Unspecified video format
303     progressive_sequence=false;
304     low_delay=false;
305 
306     //Default stream values
307     Streams.resize(0x100);
308     Streams[0xB0].Searching_Payload=true; //video_sequence_start
309     for (int8u Pos=0xFF; Pos>=0xB9; Pos--)
310         Streams[Pos].Searching_Payload=true; //Testing MPEG-PS
311 }
312 
313 //***************************************************************************
314 // Buffer - Per element
315 //***************************************************************************
316 
317 //---------------------------------------------------------------------------
Header_Parse()318 void File_AvsV::Header_Parse()
319 {
320     //Parsing
321     int8u start_code;
322     Skip_B3(                                                    "synchro");
323     Get_B1 (start_code,                                         "start_code");
324     if (!Header_Parser_Fill_Size())
325     {
326         Element_WaitForMoreData();
327         return;
328     }
329 
330     //Filling
331     Header_Fill_Code(start_code, Ztring().From_CC1(start_code));
332 }
333 
334 //---------------------------------------------------------------------------
Header_Parser_QuickSearch()335 bool File_AvsV::Header_Parser_QuickSearch()
336 {
337     while (       Buffer_Offset+4<=Buffer_Size
338       &&   Buffer[Buffer_Offset  ]==0x00
339       &&   Buffer[Buffer_Offset+1]==0x00
340       &&   Buffer[Buffer_Offset+2]==0x01)
341     {
342         //Getting start_code
343         int8u start_code=Buffer[Buffer_Offset+3];
344 
345         //Searching start or timestamp
346         if (Streams[start_code].Searching_Payload)
347             return true;
348 
349         //Synchronizing
350         Buffer_Offset+=4;
351         Synched=false;
352         if (!Synchronize_0x000001())
353         {
354             UnSynched_IsNotJunk=true;
355             return false;
356         }
357     }
358 
359     if (Buffer_Offset+3==Buffer_Size)
360         return false; //Sync is OK, but start_code is not available
361     Trusted_IsNot("AVS Video, Synchronisation lost");
362     return Synchronize();
363 }
364 
365 //---------------------------------------------------------------------------
Header_Parser_Fill_Size()366 bool File_AvsV::Header_Parser_Fill_Size()
367 {
368     //Look for next Sync word
369     if (Buffer_Offset_Temp==0) //Buffer_Offset_Temp is not 0 if Header_Parse_Fill_Size() has already parsed first frames
370         Buffer_Offset_Temp=Buffer_Offset+4;
371     while (Buffer_Offset_Temp+4<=Buffer_Size
372         && CC3(Buffer+Buffer_Offset_Temp)!=0x000001)
373     {
374         Buffer_Offset_Temp+=2;
375         while(Buffer_Offset_Temp<Buffer_Size && Buffer[Buffer_Offset_Temp]!=0x00)
376             Buffer_Offset_Temp+=2;
377         if (Buffer_Offset_Temp>=Buffer_Size || Buffer[Buffer_Offset_Temp-1]==0x00)
378             Buffer_Offset_Temp--;
379     }
380 
381     //Must wait more data?
382     if (Buffer_Offset_Temp+4>Buffer_Size)
383     {
384         if (FrameIsAlwaysComplete || File_Offset+Buffer_Size==File_Size)
385             Buffer_Offset_Temp=Buffer_Size; //We are sure that the next bytes are a start
386         else
387             return false;
388     }
389 
390     //OK, we continue
391     Header_Fill_Size(Buffer_Offset_Temp-Buffer_Offset);
392     Buffer_Offset_Temp=0;
393     return true;
394 }
395 
396 //---------------------------------------------------------------------------
Data_Parse()397 void File_AvsV::Data_Parse()
398 {
399     //Parsing
400     switch (Element_Code)
401     {
402         case 0xB0: video_sequence_start(); break;
403         case 0xB1: video_sequence_end(); break;
404         case 0xB2: user_data_start(); break;
405         case 0xB5: extension_start(); break;
406         case 0xB3:
407         case 0xB6: picture_start(); break;
408         case 0xB7: video_edit(); break;
409         case 0xB4:
410         case 0xB8: reserved(); break;
411         default:
412             if (Element_Code<=0xAF)
413                 slice();
414             else
415             {
416                 if (Frame_Count==0 && Buffer_TotalBytes>Buffer_TotalBytes_FirstSynched_Max)
417                     Trusted=0;
418                 Trusted_IsNot("Unattended element");
419 
420             }
421     }
422 
423     if (File_Offset+Buffer_Offset+Element_Size==File_Size && Frame_Count>0 && Count_Get(Stream_Video)==0) //Finalize frames in case of there are less than Frame_Count_Valid frames
424     {
425         //No need of more
426         Accept("AVS Video");
427         Finish("AVS Video");
428     }
429 }
430 
431 //***************************************************************************
432 // Elements
433 //***************************************************************************
434 
435 //---------------------------------------------------------------------------
436 // Packet "00" to "AF"
slice()437 void File_AvsV::slice()
438 {
439     Element_Name("Slice");
440 
441     //Parsing
442     Skip_XX(Element_Size,                                       "Unknown");
443 
444     FILLING_BEGIN();
445         //NextCode
446         NextCode_Test();
447     FILLING_END();
448 }
449 
450 //---------------------------------------------------------------------------
451 // Packet "B0"
video_sequence_start()452 void File_AvsV::video_sequence_start()
453 {
454     Element_Name("video_sequence_start");
455 
456     //Parsing
457     int32u bit_rate_upper, bit_rate_lower;
458     Get_B1 (    profile_id,                                     "profile_id");
459     Get_B1 (    level_id,                                       "level_id");
460     BS_Begin();
461     Get_SB (    progressive_sequence,                           "progressive_sequence");
462     Get_S2 (14, horizontal_size,                                "horizontal_size");
463     Get_S2 (14, vertical_size,                                  "vertical_size");
464     Get_S1 ( 2, chroma_format,                                  "chroma_format");
465     Skip_S1( 3,                                                 "sample_precision");
466     Get_S1 ( 4, aspect_ratio,                                   "aspect_ratio"); Param_Info1(AvsV_aspect_ratio[aspect_ratio]);
467     Get_S1 ( 4, frame_rate_code,                                "frame_rate_code"); Param_Info1(AvsV_frame_rate[frame_rate_code]);
468     Get_S3 (18, bit_rate_lower,                                 "bit_rate_lower");
469     Mark_1 ();
470     Get_S3 (12, bit_rate_upper,                                 "bit_rate_upper");
471     bit_rate=(bit_rate_upper<<18)+bit_rate_lower; Param_Info2(bit_rate*8, " bps");
472     Get_SB (    low_delay,                                      "low_delay");
473     Mark_1 ();
474     Skip_S3(18,                                                 "bbv_buffer_size");
475     Skip_SB(                                                    "reserved");
476     Skip_SB(                                                    "reserved");
477     Skip_SB(                                                    "reserved");
478     BS_End();
479 
480     //Not sure, but the 3 first official files have this
481     if (Element_Size-Element_Offset)
482     {
483         BS_Begin();
484         Mark_1();
485         BS_End();
486     }
487 
488     FILLING_BEGIN();
489         //NextCode
490         NextCode_Clear();
491         NextCode_Add(0xB2); //user_data_start
492         NextCode_Add(0xB3); //picture_start (I)
493         NextCode_Add(0xB5); //extension_start
494 
495         //Autorisation of other streams
496         Streams[0xB1].Searching_Payload=true, //video_sequence_end
497         Streams[0xB2].Searching_Payload=true; //user_data_start
498         Streams[0xB3].Searching_Payload=true, //picture_start (I)
499         Streams[0xB4].Searching_Payload=true, //reserved
500         Streams[0xB5].Searching_Payload=true; //extension_start
501         Streams[0xB6].Searching_Payload=true, //picture_start (P or B)
502         Streams[0xB7].Searching_Payload=true; //video_edit
503         Streams[0xB8].Searching_Payload=true, //reserved
504 
505         video_sequence_start_IsParsed=true;
506     FILLING_END();
507 }
508 
509 //---------------------------------------------------------------------------
510 // Packet "B1"
video_sequence_end()511 void File_AvsV::video_sequence_end()
512 {
513     Element_Name("video_sequence_start");
514 
515     FILLING_BEGIN();
516         //NextCode
517         NextCode_Clear();
518         NextCode_Add(0xB0); //SeqenceHeader
519     FILLING_END();
520 }
521 
522 //---------------------------------------------------------------------------
523 // Packet "B2", User defined size, this is often used of library name
user_data_start()524 void File_AvsV::user_data_start()
525 {
526     Element_Name("user_data_start");
527 
528     //Rejecting junk from the end
529     size_t Library_End_Offset=(size_t)Element_Size;
530     while (Library_End_Offset>0
531         && (Buffer[Buffer_Offset+Library_End_Offset-1]<0x20
532          || Buffer[Buffer_Offset+Library_End_Offset-1]>0x7D
533          || (Buffer[Buffer_Offset+Library_End_Offset-1]>=0x3A
534           && Buffer[Buffer_Offset+Library_End_Offset-1]<=0x40)))
535         Library_End_Offset--;
536     if (Library_End_Offset==0)
537         return; //No good info
538 
539     //Accepting good data after junk
540     size_t Library_Start_Offset=Library_End_Offset-1;
541     while (Library_Start_Offset>0 && (Buffer[Buffer_Offset+Library_Start_Offset-1]>=0x20 && Buffer[Buffer_Offset+Library_Start_Offset-1]<=0x7D))
542         Library_Start_Offset--;
543 
544     //But don't accept non-alpha caracters at the beginning (except for "3ivx")
545     if (Library_End_Offset-Library_Start_Offset!=4 || CC4(Buffer+Buffer_Offset+Library_Start_Offset)!=0x33697678) //3ivx
546         while (Library_Start_Offset<Library_End_Offset && Buffer[Buffer_Offset+Library_Start_Offset]<=0x40)
547             Library_Start_Offset++;
548 
549     //Parsing
550     Ztring Temp;
551     if (Library_Start_Offset>0)
552         Skip_XX(Library_Start_Offset,                           "junk");
553     if (Library_End_Offset-Library_Start_Offset)
554         Get_UTF8(Library_End_Offset-Library_Start_Offset, Temp, "data");
555     if (Element_Offset<Element_Size)
556         Skip_XX(Element_Size-Element_Offset,                    "junk");
557 
558     FILLING_BEGIN();
559         //NextCode
560         NextCode_Test();
561 
562         if (Temp.size()>=4)
563             Library=Temp;
564     FILLING_END();
565 }
566 
567 //---------------------------------------------------------------------------
568 // Packet "B5"
extension_start()569 void File_AvsV::extension_start()
570 {
571     Element_Name("Extension");
572 
573     //Parsing
574     int8u extension_start_code_identifier;
575     BS_Begin();
576     Get_S1 ( 4, extension_start_code_identifier,                "extension_start_code_identifier"); Param_Info1(AvsV_extension_start_code_identifier[extension_start_code_identifier]);
577     Element_Info1(AvsV_extension_start_code_identifier[extension_start_code_identifier]);
578 
579     switch (extension_start_code_identifier)
580     {
581         case 2  : //sequence_display
582                 {
583                     //Parsing
584                     Get_S1 ( 3, video_format,                   "video_format"); Param_Info1(AvsV_video_format[video_format]);
585                     Skip_SB(                                    "sample_range");
586                     TEST_SB_SKIP(                               "colour_description");
587                         Skip_S1( 8,                             "colour_primaries");
588                         Skip_S1( 8,                             "transfer_characteristics");
589                         Skip_S1( 8,                             "matrix_coefficients");
590                     TEST_SB_END();
591                     Get_S2 (14, display_horizontal_size,        "display_horizontal_size");
592                     Mark_1 ();
593                     Get_S2 (14, display_vertical_size,          "display_vertical_size");
594                     Skip_SB(                                    "reserved");
595                     Skip_SB(                                    "reserved");
596                     BS_End();
597                 }
598                 break;
599         case 4  : //copyright
600                 {
601                     //Parsing
602                     Skip_SB(                                    "copyright_flag");
603                     Skip_S1( 8,                                 "copyright_id");
604                     Skip_SB(                                    "original_or_copy");
605                     Skip_S1( 7,                                 "reserved");
606                     Mark_1 ();
607                     Info_S3(20, copyright_number_1,             "copyright_number_1");
608                     Mark_1 ();
609                     Info_S3(22, copyright_number_2,             "copyright_number_2");
610                     Mark_1 ();
611                     Info_S3(22, copyright_number_3,             "copyright_number_3"); Param_Info1(Ztring::ToZtring(((int64u)copyright_number_1<<44)+((int64u)copyright_number_2<<22)+(int64u)copyright_number_3, 16));
612                     BS_End();
613                 }
614                 break;
615         case 11 : //camera_parameters
616                 {
617                     //Parsing
618                     Skip_SB(                                    "reserved");
619                     Skip_S1( 7,                                 "camera_id");
620                     Mark_1 ();
621                     Skip_S3(22,                                 "height_of_image_device");
622                     Mark_1 ();
623                     Skip_S3(22,                                 "focal_length");
624                     Mark_1 ();
625                     Skip_S3(22,                                 "f_number");
626                     Mark_1 ();
627                     Skip_S3(22,                                 "vertical_angle_of_view");
628                     Mark_1 ();
629                     Skip_S3(16,                                 "camera_position_x_upper");
630                     Mark_1 ();
631                     Skip_S3(16,                                 "camera_position_x_lower");
632                     Mark_1 ();
633                     Skip_S3(16,                                 "camera_position_y_upper");
634                     Mark_1 ();
635                     Skip_S3(16,                                 "camera_position_y_lower");
636                     Mark_1 ();
637                     Skip_S3(16,                                 "camera_position_z_upper");
638                     Mark_1 ();
639                     Skip_S3(16,                                 "camera_position_z_lower");
640                     Mark_1 ();
641                     Skip_S3(22,                                 "camera_direction_x");
642                     Mark_1 ();
643                     Skip_S3(22,                                 "camera_direction_y");
644                     Mark_1 ();
645                     Skip_S3(22,                                 "camera_direction_z");
646                     Mark_1 ();
647                     Skip_S3(22,                                 "camera_plane_vertical_x");
648                     Mark_1 ();
649                     Skip_S3(22,                                 "camera_plane_vertical_y");
650                     Mark_1 ();
651                     Skip_S3(22,                                 "camera_plane_vertical_z");
652                     Mark_1 ();
653                     Skip_S4(32,                                 "reserved");
654                     BS_End();
655                 }
656                 break;
657         default :
658                 {
659                     //Parsing
660                     Skip_S1(4,                                  "data");
661                     BS_End();
662                     Skip_XX(Element_Size-Element_Offset,        "data");
663                 }
664     }
665 
666     //Not sure, but the 3 first official files have this
667     if (Element_Size-Element_Offset)
668     {
669         BS_Begin();
670         Mark_1();
671         BS_End();
672     }
673 
674     FILLING_BEGIN();
675         //NextCode
676         NextCode_Test();
677     FILLING_END();
678 }
679 
680 //---------------------------------------------------------------------------
681 // Packet "B3" or "B6"
picture_start()682 void File_AvsV::picture_start()
683 {
684     //Counting
685     if (File_Offset+Buffer_Offset+Element_Size==File_Size)
686         Frame_Count_Valid=Frame_Count; //Finalize frames in case of there are less than Frame_Count_Valid frames
687     Frame_Count++;
688 
689     //Name
690     Element_Name("picture_start");
691     Element_Info1(Ztring::ToZtring(Frame_Count));
692     Element_Info1C((Element_Code==0xB3), __T("I"));
693 
694     //Parsing
695     int8u picture_coding_type=(int8u)-1;
696     bool time_code_flag, progressive_frame, picture_structure=true, top_field_first, repeat_first_field, skip_mode_flag=false, loop_filter_disable;
697     Skip_B2(                                                    "bbv_delay");
698     BS_Begin();
699     if (Element_Code==0xB3) //Only I
700     {
701         Get_SB (    time_code_flag,                             "time_code_flag");
702         if (time_code_flag)
703         {
704             Skip_SB(                                            "time_code_dropframe");
705             Skip_S1(5,                                          "time_code_hours");
706             Skip_S1(6,                                          "time_code_minutes");
707             Skip_S1(6,                                          "time_code_seconds");
708             Skip_S1(6,                                          "time_code_pictures");
709         }
710     }
711     if (Element_Code==0xB6) //Only P or B
712     {
713         Get_S1 ( 2, picture_coding_type,                        "picture_coding_type"); Element_Info1(AvsV_picture_coding_type[picture_coding_type]);
714     }
715     Skip_S1( 8,                                                 "picture_distance");
716     if (low_delay)
717         Skip_UE(                                                "bbv_check_times");
718     Get_SB (    progressive_frame,                              "progressive_frame");
719     if (!progressive_frame)
720     {
721         Get_SB(    picture_structure,                           "picture_structure");
722         if (Element_Code==0xB6) //Only P or B
723         {
724             if (picture_structure)
725                 Skip_SB(                                        "advanced_pred_mode_disable");
726         }
727     }
728     Get_SB (    top_field_first,                                "top_field_first");
729     Get_SB (    repeat_first_field,                             "repeat_first_field");
730     Skip_SB(                                                    "fixed_picture_qp");
731     Skip_S1( 6,                                                 "picture_qp");
732     if (Element_Code==0xB3) //Only I
733     {
734         if (!progressive_frame && !picture_structure)
735             Get_SB(    skip_mode_flag,                          "skip_mode_flag");
736     }
737     if (Element_Code==0xB6) //Only P or B
738     {
739         if (picture_coding_type!=2 || !picture_structure)
740             Skip_SB(                                            "picture_reference_flag");
741     }
742     Skip_SB(                                                    "reserved");
743     Skip_SB(                                                    "reserved");
744     Skip_SB(                                                    "reserved");
745     Skip_SB(                                                    "reserved");
746     if (Element_Code==0xB6) //Only P or B
747     {
748         Get_SB(    skip_mode_flag,                              "skip_mode_flag");
749     }
750     Get_SB (    loop_filter_disable,                            "loop_filter_disable");
751     if (!loop_filter_disable)
752     {
753         bool loop_filter_parameter_flag;
754         Get_SB (    loop_filter_parameter_flag,                 "loop_filter_parameter_flag");
755         if (loop_filter_parameter_flag)
756         {
757             Skip_SE(                                            "alpha_c_offset");
758             Skip_SE(                                            "beta_offset");
759         }
760     }
761     BS_End();
762 
763     if (Element_Size-Element_Offset)
764         Skip_XX(Element_Size-Element_Offset,                    "Unknown");
765 
766     FILLING_BEGIN();
767         if (progressive_frame==false)
768         {
769             if (picture_structure==true)           //Frame
770             {
771                 if (top_field_first)
772                     Interlaced_Top++;
773                 else
774                     Interlaced_Bottom++;
775             }
776         }
777         else
778             progressive_frame_Count++;
779 
780         //NextCode
781         NextCode_Test();
782         NextCode_Clear();
783         for (int8u Pos=0x00; Pos<=0xAF; Pos++)
784             NextCode_Add(Pos); //slice
785         NextCode_Add(0xB0); //video_sequence_start
786         NextCode_Add(0xB3); //picture_start
787         NextCode_Add(0xB6); //picture_start
788 
789         //Autorisation of other streams
790         for (int8u Pos=0x00; Pos<=0xAF; Pos++)
791             Streams[Pos].Searching_Payload=true; //slice
792 
793         //Filling only if not already done
794         if (Frame_Count>=Frame_Count_Valid && Count_Get(Stream_Video)==0)
795         {
796             //No need of more
797             Accept("AVS Video");
798             Finish("AVS Video");
799         }
800     FILLING_END();
801 }
802 
803 //---------------------------------------------------------------------------
804 // Packet "B7"
video_edit()805 void File_AvsV::video_edit()
806 {
807     Element_Name("video_edit");
808 }
809 
810 //---------------------------------------------------------------------------
811 // Packet "B4" and "B8"
reserved()812 void File_AvsV::reserved()
813 {
814     Element_Name("reserved");
815 
816     //Parsing
817     if (Element_Size)
818         Skip_XX(Element_Size,                                   "reserved");
819 }
820 
821 //***************************************************************************
822 // C++
823 //***************************************************************************
824 
825 } //NameSpace
826 
827 #endif //MEDIAINFO_AVSV_*
828