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_SDP_YES)
21 //---------------------------------------------------------------------------
22
23 //---------------------------------------------------------------------------
24 #include "MediaInfo/Text/File_Sdp.h"
25 #include "MediaInfo/Text/File_Teletext.h"
26 #include "MediaInfo/MediaInfo_Config_MediaInfo.h"
27 //---------------------------------------------------------------------------
28
29 namespace MediaInfoLib
30 {
31
32 //***************************************************************************
33 // Constructor/Destructor
34 //***************************************************************************
35
36 //---------------------------------------------------------------------------
File_Sdp()37 File_Sdp::File_Sdp()
38 :File__Analyze()
39 {
40 //Configuration
41 ParserName="SDP";
42 #if MEDIAINFO_EVENTS
43 ParserIDs[0]=MediaInfo_Parser_Sdp;
44 StreamIDs_Width[0]=2;
45 #endif //MEDIAINFO_EVENTS
46 #if MEDIAINFO_TRACE
47 Trace_Layers_Update(8); //Stream
48 #endif //MEDIAINFO_TRACE
49 PTS_DTS_Needed=true;
50 MustSynchronize=true;
51 }
52
53 //---------------------------------------------------------------------------
~File_Sdp()54 File_Sdp::~File_Sdp()
55 {
56 }
57
58 //***************************************************************************
59 // Streams management
60 //***************************************************************************
61
62 //---------------------------------------------------------------------------
Streams_Fill()63 void File_Sdp::Streams_Fill()
64 {
65 Fill(Stream_General, 0, General_Format, "SDP");
66 }
67
68 //---------------------------------------------------------------------------
Streams_Finish()69 void File_Sdp::Streams_Finish()
70 {
71 for (streams::iterator Stream=Streams.begin(); Stream!=Streams.end(); ++Stream)
72 {
73 if (Stream->second.Parser)
74 {
75 Finish(Stream->second.Parser);
76 for (size_t StreamKind=Stream_General+1; StreamKind<Stream_Max; StreamKind++)
77 for (size_t StreamPos=0; StreamPos<Stream->second.Parser->Count_Get((stream_t)StreamKind); StreamPos++)
78 {
79 Merge(*Stream->second.Parser, (stream_t)StreamKind, StreamPos, StreamPos);
80 Fill((stream_t)StreamKind, StreamPos, General_ID, Stream->second.Parser->Get((stream_t)StreamKind, StreamPos, General_ID), true);
81 }
82 }
83 }
84 }
85
86 //***************************************************************************
87 // Buffer - Synchro
88 //***************************************************************************
89
90 //---------------------------------------------------------------------------
Synchronize()91 bool File_Sdp::Synchronize()
92 {
93 //Synchronizing
94 while (Buffer_Offset+2<Buffer_Size)
95 {
96 while (Buffer_Offset+2<Buffer_Size)
97 {
98 if (Buffer[Buffer_Offset ]==0x51
99 && Buffer[Buffer_Offset+1]==0x15)
100 break; //while()
101
102 Buffer_Offset++;
103 }
104
105 if (IsSub)
106 break; // Found one file with unknown bytes at the end of the stream, so removing this integrity test for the moment
107
108 if (Buffer_Offset+2<Buffer_Size) //Testing if size is coherant
109 {
110 if (Buffer_Offset+Buffer[Buffer_Offset+2]==Buffer_Size)
111 break;
112
113 if (Buffer_Offset+Buffer[Buffer_Offset+2]+3>Buffer_Size)
114 return false; //Wait for more data
115
116 if (Buffer[Buffer_Offset+Buffer[Buffer_Offset+2] ]==0x51
117 && Buffer[Buffer_Offset+Buffer[Buffer_Offset+2]+1]==0x15)
118 break; //while()
119
120 Buffer_Offset++;
121 }
122 }
123
124 //Must have enough buffer for having header
125 if (Buffer_Offset+2>=Buffer_Size)
126 return false;
127
128 //Synched is OK
129 if (!Status[IsAccepted])
130 {
131 //For the moment, we accept only if the file is in sync, the test is not strict enough
132 if (Buffer_Offset)
133 {
134 Reject();
135 return false;
136 }
137
138 Accept();
139 }
140 return true;
141 }
142
143 //---------------------------------------------------------------------------
Synched_Test()144 bool File_Sdp::Synched_Test()
145 {
146 //Must have enough buffer for having header
147 if (Buffer_Offset+3>Buffer_Size)
148 return false;
149
150 //Quick test of synchro
151 if (Buffer[Buffer_Offset ]!=0x51
152 || Buffer[Buffer_Offset+1]!=0x15)
153 {
154 Synched=false;
155 return true;
156 }
157
158 //We continue
159 return true;
160 }
161
162 //***************************************************************************
163 // Buffer - Global
164 //***************************************************************************
165
166 //---------------------------------------------------------------------------
Read_Buffer_Unsynched()167 void File_Sdp::Read_Buffer_Unsynched()
168 {
169 for (streams::iterator Stream=Streams.begin(); Stream!=Streams.end(); ++Stream)
170 {
171 if (Stream->second.Parser)
172 {
173 Stream->second.Parser->Open_Buffer_Unsynch();
174 }
175 }
176 }
177
178 //***************************************************************************
179 // Buffer - Elements
180 //***************************************************************************
181
182 //---------------------------------------------------------------------------
Header_Parse()183 void File_Sdp::Header_Parse()
184 {
185 //Parsing
186 int8u Length, FormatCode;
187 Skip_B2( "Identifier");
188 Get_B1 (Length, "Length");
189 Get_B1 (FormatCode, "Format Code");
190 for (int8u Pos=0; Pos<5; Pos++)
191 {
192 FieldLines[Pos]=0;
193 #if MEDIAINFO_TRACE
194 Element_Begin1("Field/Line");
195 BS_Begin();
196 Info_SB( Field, "Field Number");
197 Info_S1(2, Reserved, "Reserved");
198 Info_S1(5, Line, "Line Number");
199 BS_End();
200 FieldLines[Pos]=((Field?1:0)<<7) |(Reserved<<5) | Line; //Removing field information ((Field?1:0)<<7) |
201 if (FieldLines[Pos])
202 {
203 Element_Info1(Field?2:1);
204 Element_Info1(Line);
205 }
206 else
207 Element_Info1("None");
208 Element_End0();
209 #else //MEDIAINFO_TRACE
210 Get_B1(FieldLines[Pos], "Field/Line");
211 FieldLines[Pos]&=0x7F; //Removing field information
212 #endif //MEDIAINFO_TRACE
213 }
214
215 if (IsSub)
216 Header_Fill_Size(Buffer_Size);
217 else
218 Header_Fill_Size(Length);
219 }
220
221 //---------------------------------------------------------------------------
Data_Parse()222 void File_Sdp::Data_Parse()
223 {
224 Element_Name("Packet");
225
226 for (int8u Pos=0; Pos<5; Pos++)
227 {
228 if (FieldLines[Pos])
229 {
230 Element_Code=(int64u)-1;
231 stream &Stream=Streams[0];
232 if (Stream.Parser==NULL)
233 {
234 Stream.Parser=new File_Teletext();
235 Open_Buffer_Init(Stream.Parser);
236 }
237 if (Stream.Parser->PTS_DTS_Needed)
238 Stream.Parser->FrameInfo=FrameInfo;
239 Demux(Buffer+Buffer_Offset+Element_Offset, 45, ContentType_MainStream);
240 Open_Buffer_Continue(Stream.Parser, Buffer+Buffer_Offset+Element_Offset, 45);
241 Element_Offset+=45;
242 }
243 }
244
245 Element_Begin1("SDP Footer");
246 Skip_B1( "Footer ID");
247 Skip_B2( "Footer Sequence number");
248 Skip_B1( "SDP Cheksum");
249 if (Element_Offset<Element_Size)
250 Skip_XX(Element_Size-Element_Offset, "Unknown, out of specs");
251 Element_End0();
252 }
253
254 //***************************************************************************
255 // C++
256 //***************************************************************************
257
258 } //NameSpace
259
260 #endif //MEDIAINFO_SDP_YES
261