|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Definition of an abstract base class for file format parsers. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __PARSER_H__ |
|
23 #define __PARSER_H__ |
|
24 |
|
25 // INCLUDES |
|
26 #ifndef __E32BASE_H__ |
|
27 #include <e32base.h> |
|
28 #endif |
|
29 |
|
30 // CONSTANTS |
|
31 // MACROS |
|
32 // DATA TYPES |
|
33 // FUNCTION PROTOTYPES |
|
34 // FORWARD DECLARATIONS |
|
35 // CLASS DECLARATION |
|
36 |
|
37 /** |
|
38 * Base class for file format parser |
|
39 * ?other_description_lines |
|
40 */ |
|
41 class CParser : public CBase |
|
42 { |
|
43 |
|
44 public: // Constants |
|
45 |
|
46 enum TErrorCode |
|
47 { |
|
48 EInternalAssertionFailure = -2200, |
|
49 EParserNotEnoughData = -2201, |
|
50 EParserEndOfStream = -2202, |
|
51 EParserBufferTooSmall = -2203, |
|
52 EParserUnsupportedFormat = -2204, |
|
53 EParserStreamCorrupted = -2205, |
|
54 EParserFailure = -2206 |
|
55 }; |
|
56 |
|
57 // file format |
|
58 enum TFileFormat { |
|
59 EFileFormatUnrecognized = 0, |
|
60 EFileFormat3GP, |
|
61 EFileFormatMP4 |
|
62 }; |
|
63 |
|
64 // video format |
|
65 enum TVideoFormat { |
|
66 EVideoFormatNone = 0, |
|
67 EVideoFormatH263Profile0Level10, |
|
68 EVideoFormatH263Profile0Level45, |
|
69 EVideoFormatMPEG4, |
|
70 EVideoFormatAVCProfileBaseline, |
|
71 EVideoFormatAVCProfileMain, |
|
72 EVideoFormatAVCProfileExtended |
|
73 }; |
|
74 |
|
75 // audio format |
|
76 enum TAudioFormat |
|
77 { |
|
78 EAudioFormatNone = 0, |
|
79 EAudioFormatAMR, |
|
80 EAudioFormatAAC |
|
81 }; |
|
82 |
|
83 #ifdef __VIDEOEDIT__ |
|
84 enum TProcessingMode |
|
85 { |
|
86 EParseOnly = 1, |
|
87 EParseAndDecode, |
|
88 EDecodeOnly |
|
89 }; |
|
90 #endif |
|
91 |
|
92 public: // Data structures |
|
93 |
|
94 // common stream parameters |
|
95 struct TStreamParameters |
|
96 { |
|
97 TBool iHaveVideo; // is there video in the stream ? |
|
98 TBool iHaveAudio; // is there audio in the stream ? |
|
99 TUint iNumDemuxChannels; // number of demux channels |
|
100 TFileFormat iFileFormat; // file format |
|
101 TVideoFormat iVideoFormat; // video format |
|
102 TAudioFormat iAudioFormat; // audio format |
|
103 |
|
104 TUint iAudioFramesInSample; // audio frames per one sample (3GPP) |
|
105 |
|
106 TUint iVideoWidth; // width of a video frame |
|
107 TUint iVideoHeight; // height of a video frame |
|
108 TInt64 iVideoPicturePeriodNsec; // one PCF tick period in nanoseconds |
|
109 TUint iVideoIntraFrequency; // intra frame frequency in stream |
|
110 |
|
111 TUint iStreamLength; // stream length in milliseconds |
|
112 TUint iVideoLength; |
|
113 TUint iAudioLength; |
|
114 |
|
115 TBool iCanSeek; // TRUE if seeking in file is possible |
|
116 |
|
117 TUint iStreamSize; // stream size in bytes |
|
118 TUint iStreamBitrate; // stream average bitrate |
|
119 |
|
120 TUint iMaxPacketSize; // The maximum media packet size |
|
121 TUint iLogicalChannelNumberVideo; // Logical channel number for video data |
|
122 TUint iLogicalChannelNumberAudio; // Logical channel number for audio data |
|
123 TUint iReferencePicturesNeeded; // Number of reference pictures |
|
124 // the video decoder needs to store. |
|
125 TUint iNumScalabilityLayers; // The number of different scalability layers used |
|
126 TUint iLayerFrameRates[8]; // Picture rate for each layer |
|
127 |
|
128 TReal iFrameRate; |
|
129 TUint iVideoTimeScale; |
|
130 TUint iAudioTimeScale; |
|
131 |
|
132 }; |
|
133 |
|
134 public: // New functions |
|
135 |
|
136 /** |
|
137 * Write a block of data to parser. |
|
138 * @param aBlock Block to be written. |
|
139 */ |
|
140 virtual TInt WriteDataBlock(const TDes8& aBlock) = 0; |
|
141 |
|
142 /** |
|
143 * Parses the stream header. |
|
144 * @param aStreamParameters Stream parameters |
|
145 */ |
|
146 |
|
147 virtual TInt ParseHeaderL(TStreamParameters& aStreamParameters) = 0; |
|
148 |
|
149 /** |
|
150 * Resets the parser to initial state. |
|
151 * => If input stream is in a file, rewinds it. |
|
152 * => If input is written to parser, all buffered bytes are flushed |
|
153 * @param aStreamParameters Stream parameters |
|
154 */ |
|
155 virtual TInt Reset() = 0; |
|
156 |
|
157 /** |
|
158 * Gets the number of frames in the current clip |
|
159 * |
|
160 * @return Number of frames |
|
161 */ |
|
162 inline TInt GetNumberOfFramesInClip() { return iNumberOfFrames; } |
|
163 |
|
164 virtual TInt GetNumberOfVideoFrames() = 0; |
|
165 |
|
166 virtual TInt GetNumberOfFrames() = 0; |
|
167 |
|
168 /** |
|
169 * Seeks to intra frame before given time |
|
170 * |
|
171 * @param aStartTime Time in microseconds to seek |
|
172 * @param aIndex Index of the frame at aStartTime, if known. 0 otherwise |
|
173 * |
|
174 * @return Number of frames |
|
175 */ |
|
176 virtual TInt SeekOptimalIntraFrame(TTimeIntervalMicroSeconds aStartTime, TInt aIndex, TBool aFirstTime) = 0; |
|
177 |
|
178 /** |
|
179 * Gets the size of video frame at given index |
|
180 * |
|
181 * @param aIndex Index of the frame |
|
182 * |
|
183 * @return Size of frame in bytes |
|
184 */ |
|
185 virtual TInt GetVideoFrameSize(TInt aIndex) = 0; |
|
186 |
|
187 /** |
|
188 * Gets the timestamp of video frame at given index |
|
189 * |
|
190 * @param aIndex Index of the frame |
|
191 * @param aTimeStamp Output: timestamp in ticks |
|
192 * |
|
193 * @return Timestamp in milliseconds |
|
194 */ |
|
195 virtual TInt GetVideoFrameStartTime(TInt aIndex, TInt* aTimeStampInTicks) = 0; |
|
196 |
|
197 /** |
|
198 * Gets the type of video frame at given index |
|
199 * |
|
200 * @param aIndex Index of the frame |
|
201 * |
|
202 * @return Frame type: 1 = INTRA, 0 = INTER |
|
203 */ |
|
204 virtual TInt8 GetVideoFrameType(TInt aIndex) = 0; |
|
205 |
|
206 /** |
|
207 * Gets the start frame index of the current clip |
|
208 * |
|
209 * @return Frame index |
|
210 */ |
|
211 inline TInt GetStartFrameIndex() { return iStartFrameIndex; } |
|
212 |
|
213 /** |
|
214 * From CParser Parser the stream header. |
|
215 * @param aAudioFrameSize average frame size of audio frame |
|
216 */ |
|
217 virtual TInt ParseAudioInfo(TInt& aAudioFrameSize) = 0; |
|
218 |
|
219 virtual TInt GetMP4SpecificSize() = 0; //Added for Mpeg-4 Support |
|
220 |
|
221 virtual TInt GetAudioBitrate(TInt& aBitrate) = 0; |
|
222 |
|
223 virtual TInt GetVideoFrameRate(TReal& aFrameRate) = 0; |
|
224 |
|
225 virtual TInt GetDecoderSpecificInfoSize() = 0; |
|
226 |
|
227 virtual TInt ReadAVCDecoderSpecificInfo(TDes8& aBuf) = 0; |
|
228 |
|
229 virtual TInt GetVideoDuration(TInt& aDurationInMs) = 0; |
|
230 |
|
231 |
|
232 public: // Data |
|
233 |
|
234 // stream parameters |
|
235 TStreamParameters iStreamParameters; |
|
236 // ETrue if parsing this clip for the first time |
|
237 TBool iFirstTimeClipParsing; |
|
238 // number of frames in output clip |
|
239 TInt iOutputNumberOfFrames; |
|
240 |
|
241 protected: // Data |
|
242 |
|
243 // current frame number |
|
244 TInt iFrameNumber; |
|
245 // number of frames in current clip |
|
246 TInt iNumberOfFrames; |
|
247 // index of the first included frame |
|
248 TInt iStartFrameIndex; |
|
249 |
|
250 }; |
|
251 |
|
252 #endif // __PARSER_H__ |
|
253 |
|
254 // End of File |