|
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 * Header for mp4parser.cpp. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __MP4PARSER_H__ |
|
23 #define __MP4PARSER_H__ |
|
24 |
|
25 // INCLUDES |
|
26 |
|
27 #include "Parser.h" |
|
28 #include <mp4lib.h> |
|
29 |
|
30 // CONSTANTS |
|
31 // MACROS |
|
32 // DATA TYPES |
|
33 // FUNCTION PROTOTYPES |
|
34 // FORWARD DECLARATIONS |
|
35 |
|
36 struct TAudioClipParameters; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 class CMovieProcessorImpl; |
|
40 |
|
41 /** |
|
42 * MP4 -format parser class |
|
43 * ?other_description_lines |
|
44 */ |
|
45 class CMP4Parser : public CParser |
|
46 { |
|
47 |
|
48 public: // Constants |
|
49 |
|
50 enum TFrameType |
|
51 { |
|
52 EFrameTypeNone = 0, |
|
53 EFrameTypeAudio, |
|
54 EFrameTypeVideo |
|
55 }; |
|
56 |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * C++ default constructor. |
|
61 */ |
|
62 CMP4Parser(); |
|
63 |
|
64 /** |
|
65 * Two-phased constructor. |
|
66 */ |
|
67 |
|
68 static CMP4Parser* NewL(CMovieProcessorImpl* aProcessor, const TDesC &aFileName); |
|
69 |
|
70 static CMP4Parser* NewL(CMovieProcessorImpl* aProcessor, RFile* aFileHandle); |
|
71 |
|
72 /** |
|
73 * Destructor. |
|
74 */ |
|
75 ~CMP4Parser(); |
|
76 |
|
77 |
|
78 public: // New functions |
|
79 |
|
80 /** |
|
81 * Determine if the file/data inserted is in streamable, i.e. interleaved format |
|
82 * @return TBool ETrue if streamable |
|
83 */ |
|
84 TInt IsStreamable(); |
|
85 |
|
86 /** |
|
87 * Seek to new position in input file |
|
88 * @param aPositionInMs Position to be seeked to in milliseconds |
|
89 * @param anAudioTimeAfter audio position in milliseconds after seek |
|
90 * @param aVideoTimeAfter video position in milliseconds after seek |
|
91 * @return TInt error code |
|
92 */ |
|
93 TInt Seek(TUint32 aPositionInMs, TUint32& anAudioTimeAfter, TUint32& aVideoTimeAfter); |
|
94 |
|
95 /** |
|
96 * Reads information of next available packet in inserted input data |
|
97 * @param aType Frame type |
|
98 * @param aFrameLength Frame length in bytes |
|
99 * @return TInt error code |
|
100 */ |
|
101 TInt GetNextFrameInformation(TFrameType& aType, TUint& aLength, TBool& aIsAvailable); |
|
102 |
|
103 /** |
|
104 * Read a number of frames of requested type from inserted data or file |
|
105 * @param aDstBuffer Destination buffer |
|
106 * @param aType Type of frame(s) to be read |
|
107 * @param aNumRead Number of frames actually read |
|
108 * @return TInt error code |
|
109 */ |
|
110 TInt ReadFrames(TDes8& aDstBuffer, TFrameType aType, TUint32& aNumRead, TUint32& aTimeStamp); |
|
111 |
|
112 /** |
|
113 * Initializes the module for AMR audio processing |
|
114 * @param aStartPosition Time to start reading from |
|
115 * @param aEndPosition Ending time for reading |
|
116 * @param aCurrentTime How long has audio been processed so far |
|
117 * @param aAudioOffset Offset from the beginning of movie timeline |
|
118 * @param aAudioPending ETrue if audio operation is pending |
|
119 * @param aPendingAudioDuration Duration for pending audio |
|
120 * @param aAudioClipParameters Audio clip parameter structure |
|
121 * |
|
122 * @return Error code |
|
123 */ |
|
124 void InitAudioProcessingL(TInt64 aStartPosition, TInt64 aEndPosition, |
|
125 TInt64& aCurrentTime, TInt64 aAudioOffset, |
|
126 TBool& aAudioPending, TInt64& aPendingAudioDuration); |
|
127 |
|
128 /** |
|
129 * Gets information about video frames |
|
130 * @param aVideoFrameInfoArray Array to store frame properties |
|
131 * @param aStartIndex Index of the first frame to get properties |
|
132 * @param aSizeOfArray Size of aVideoFrameInfoArray |
|
133 * @return TInt error code |
|
134 */ |
|
135 TInt GetVideoFrameProperties(TFrameInfoParameters* aVideoFrameInfoArray, |
|
136 TUint32 aStartIndex, TUint32 aSizeOfArray); |
|
137 |
|
138 /** |
|
139 * Obtains the AAC audio decoder specific info for current clip |
|
140 * @param aBytes -- buffer to be filled with the info |
|
141 * @param aBufferSize -- indicating the maximum size to be allocated |
|
142 */ |
|
143 TInt ReadAudioDecoderSpecificInfoL(HBufC8*& aBytes, TInt aBufferSize); |
|
144 |
|
145 /** |
|
146 * Obtains the AAC audio decoder specific info default for 16khz and LC and Single channel |
|
147 * @param aBytes -- buffer to be filled with the info |
|
148 * @param aBufferSize -- indicating the maximum size to be allocated |
|
149 */ |
|
150 TInt SetDefaultAudioDecoderSpecificInfoL(HBufC8*& aBytes, TInt aBufferSize); |
|
151 |
|
152 public: // Functions from base classes |
|
153 |
|
154 /** |
|
155 * From CParser Writes a block of data for parsing |
|
156 * @param aBlock Block to be written |
|
157 * @return TInt error code |
|
158 */ |
|
159 TInt WriteDataBlock(const TDes8& aBlock); |
|
160 |
|
161 /** |
|
162 * From CParser Parser the stream header. |
|
163 * @param aStreamParameters Common stream parameters |
|
164 */ |
|
165 TInt ParseHeaderL(CParser::TStreamParameters& aStreamParameters); |
|
166 |
|
167 /** |
|
168 * From CParser Resets parser to initial state. |
|
169 * @return TInt error code |
|
170 */ |
|
171 |
|
172 TInt Reset(); |
|
173 |
|
174 /** |
|
175 * From CParser Seek to optimal intra before given time |
|
176 */ |
|
177 |
|
178 TInt SeekOptimalIntraFrame(TTimeIntervalMicroSeconds aStartTime, TInt aIndex, TBool aFirstTime); |
|
179 |
|
180 /** |
|
181 * From CParser |
|
182 * Gets the number of frames in current clip |
|
183 */ |
|
184 TInt GetNumberOfVideoFrames(); |
|
185 TInt GetNumberOfFrames(); |
|
186 |
|
187 /** |
|
188 * From CParser |
|
189 * Gets the size of video frame at given index |
|
190 */ |
|
191 TInt GetVideoFrameSize(TInt aIndex); |
|
192 |
|
193 /** |
|
194 * From CParser |
|
195 * Gets the timestamp of video frame at given index |
|
196 */ |
|
197 TInt GetVideoFrameStartTime(TInt aIndex, TInt* iTimeStamp); |
|
198 |
|
199 /** |
|
200 * From CParser |
|
201 * Gets the type of video frame at given index |
|
202 */ |
|
203 TInt8 GetVideoFrameType(TInt aIndex); |
|
204 |
|
205 /** |
|
206 * From CParser Parser the stream header. |
|
207 * @param aAudioFrameSize average frame size of audio frame |
|
208 */ |
|
209 TInt ParseAudioInfo(TInt& aAudioFrameSize); |
|
210 |
|
211 TInt GetMP4SpecificSize(); // added for Mpeg-4 Support |
|
212 |
|
213 /** |
|
214 * From CParser Retrieves average audio bitrate of current clip |
|
215 * @param aBitrate Average bitrate |
|
216 * |
|
217 * @return error code |
|
218 */ |
|
219 TInt GetAudioBitrate(TInt& aBitrate); |
|
220 |
|
221 /** |
|
222 * From CParser Retrieves average video frame rate of current clip |
|
223 * @param aBitrate Average frame rate |
|
224 * |
|
225 * @return error code |
|
226 */ |
|
227 TInt GetVideoFrameRate(TReal& aFrameRate); |
|
228 |
|
229 /** |
|
230 * From CParser Returns the size of decoder specific info |
|
231 * |
|
232 * @return size in bytes |
|
233 */ |
|
234 TInt GetDecoderSpecificInfoSize(); |
|
235 |
|
236 /** |
|
237 * From CParser Reads AVC decoder specific info to buffer |
|
238 * @param aBuf Destination buffer |
|
239 * |
|
240 * @return error code |
|
241 */ |
|
242 TInt ReadAVCDecoderSpecificInfo(TDes8& aBuf); |
|
243 |
|
244 /** |
|
245 * From CParser Returns the duration of video track in milliseconds |
|
246 * @param aDurationInMs Duration |
|
247 * |
|
248 * @return error code |
|
249 */ |
|
250 TInt GetVideoDuration(TInt& aDurationInMs); |
|
251 |
|
252 private: |
|
253 |
|
254 /** |
|
255 * By default Symbian OS constructor is private. |
|
256 */ |
|
257 void ConstructL(CMovieProcessorImpl* aProcessor, const TDesC &aFileName); |
|
258 |
|
259 void ConstructL(CMovieProcessorImpl* aProcessor, RFile* aFileHandle); |
|
260 |
|
261 private: // Internal constants |
|
262 |
|
263 // Stream source type |
|
264 enum TStreamSource |
|
265 { |
|
266 ESourceNone = 0, // not set yet |
|
267 ESourceFile, // reading from a file |
|
268 ESourceUser // user of this object provides data |
|
269 }; |
|
270 |
|
271 public: |
|
272 |
|
273 |
|
274 private: // Data |
|
275 |
|
276 // video processor instance |
|
277 CMovieProcessorImpl *iProcessor; |
|
278 |
|
279 TStreamSource iStreamSource; |
|
280 |
|
281 mp4_u32 iVideoType; |
|
282 mp4_u32 iAudioType; |
|
283 |
|
284 TUint iBytesRead; |
|
285 |
|
286 // The MP4 parser library handle |
|
287 MP4Handle iMP4Handle; |
|
288 |
|
289 TFrameType iNextFrameType; |
|
290 TUint iNextFrameLength; |
|
291 |
|
292 TBool iFirstRead; |
|
293 TBool iFirstFrameInfo; |
|
294 |
|
295 // Max video frame length & AMR sample size, used for sanity checks to avoid crashes in case of corrupted input |
|
296 TInt iMaxVideoFrameLength; |
|
297 TInt iMaxAMRSampleSize; |
|
298 |
|
299 }; |
|
300 |
|
301 #endif // __MP4PARSER_H__ |
|
302 |
|
303 |
|
304 // End of File |