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 // Note : the buffer must be given in ONE call
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 #if defined(MEDIAINFO_THEORA_YES)
27 //---------------------------------------------------------------------------
28 
29 //---------------------------------------------------------------------------
30 #include "MediaInfo/Video/File_Theora.h"
31 using namespace std;
32 //---------------------------------------------------------------------------
33 
34 namespace MediaInfoLib
35 {
36 
37 //***************************************************************************
38 // Format
39 //***************************************************************************
40 
41 //---------------------------------------------------------------------------
Header_Parse()42 void File_Theora::Header_Parse()
43 {
44     //Filling
45     Header_Fill_Code(0, "Theora");
46     Header_Fill_Size(Element_Size);
47 }
48 
49 //---------------------------------------------------------------------------
Data_Parse()50 void File_Theora::Data_Parse()
51 {
52     //Parsing
53     if (Status[IsAccepted])
54         Setup();
55     else
56         Identification();
57 }
58 
59 //***************************************************************************
60 // Elements
61 //***************************************************************************
62 
63 //---------------------------------------------------------------------------
Identification()64 void File_Theora::Identification()
65 {
66     Element_Name("Identification");
67 
68     //Parsing
69     int32u Version, PICW=0, PICH=0, FRN=0, FRD=0, PARN=0, PARD=0, NOMBR=0;
70     Skip_B1   (                                                 "Signature");
71     Skip_Local(6,                                               "Signature");
72     Get_B3 (Version,                                            "Version");
73     if ((Version&0x030200)==0x030200) //Version 3.2.x
74     {
75         Skip_B2(                                                "FMBW");
76         Skip_B2(                                                "FMBH");
77         Get_B3 (PICW,                                           "PICW");
78         Get_B3 (PICH,                                           "PICH");
79         Skip_B1(                                                "PICX");
80         Skip_B1(                                                "PICY");
81         Get_B4 (FRN,                                            "FRN");
82         Get_B4 (FRD,                                            "FRD");
83         Get_B3 (PARN,                                           "PARN");
84         Get_B3 (PARD,                                           "PARD");
85         Skip_B1(                                                "CS"); // //0=4:2:0, 2=4:2:2, 3=4:4:4
86         Get_B3 (NOMBR,                                          "NOMBR"); //The nominal bitrate of the stream
87         BS_Begin();
88         Skip_BS( 6,                                             "QUAL"); //The quality hint.
89         Skip_BS( 5,                                             "KFGSHIFT");
90         Skip_BS( 2,                                             "PF"); //The Pixel Format
91         Skip_BS( 3,                                             "Reserved");
92         BS_End();
93     }
94 
95     //Filling
96     FILLING_BEGIN();
97         Accept("Theora");
98 
99         Stream_Prepare(Stream_Video);
100         Fill(Stream_Video, StreamPos_Last, Video_Format, "Theora");
101         Fill(Stream_Video, StreamPos_Last, Video_Codec, "Theora");
102         if ((Version&0x030200)!=0x030200) //Version 3.2.x
103             return;
104         if (FRN && FRD)
105             Fill(Stream_Video, StreamPos_Last, Video_FrameRate, ((float)FRN)/FRD, 3);
106         float PixelRatio=1;
107         if (PARN && PARD)
108             PixelRatio=((float)PARN)/(float)PARD;
109         Fill(Stream_Video, StreamPos_Last, Video_Width, PICW);
110         Fill(Stream_Video, StreamPos_Last, Video_Height, PICH);
111         Fill(Stream_Video, StreamPos_Last, Video_DisplayAspectRatio, ((float)PICW)/((float)PICH)*PixelRatio, 3, true);
112         if (NOMBR)
113             Fill(Stream_Video, StreamPos_Last, Video_BitRate_Nominal, NOMBR);
114     FILLING_END();
115 }
116 
117 //---------------------------------------------------------------------------
Setup()118 void File_Theora::Setup()
119 {
120     Element_Name("Setup");
121 
122     //Parsing
123     Skip_XX(Element_Size,                                       "Unknown");
124 
125     Finish("Theora");
126 }
127 
128 //***************************************************************************
129 // C++
130 //***************************************************************************
131 
132 } //NameSpace
133 
134 #endif //MEDIAINFO_THEORA_YES
135