|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #ifndef MCCFILESOURCEIMPL_H |
|
22 #define MCCFILESOURCEIMPL_H |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include <e32std.h> |
|
27 #include <mmf/server/mmfdatasource.h> |
|
28 #include <mmf/server/mmfdatasink.h> |
|
29 #include <3gplibrary/mp4lib.h> |
|
30 |
|
31 #include "CCMRMediaSink.h" |
|
32 #include "mccperiodicrunner.h" |
|
33 #include "mmccevents.h" |
|
34 #include "mcceoftimer.h" |
|
35 |
|
36 // percentage that filereader is behind ROP for playback sync |
|
37 const TUint KMccMicroToMilliConst = 1000; |
|
38 |
|
39 // CLASS DECLARATION |
|
40 class CMccFileSourceTypeBase; |
|
41 class CMccFileAudio; |
|
42 class CMccFileVideo; |
|
43 class CMccEofTimer; |
|
44 class MMccResources; |
|
45 |
|
46 /** |
|
47 * |
|
48 */ |
|
49 class CMccFileSourceImpl : |
|
50 public CBase, public MMccEofTimerObserver |
|
51 { |
|
52 |
|
53 public: // Methods called internally or by the controller |
|
54 |
|
55 /** |
|
56 * Two-phased constructor. |
|
57 */ |
|
58 static CMccFileSourceImpl* NewL( TUint32 aEndpointId, MMccResources* aMccResources = NULL ); |
|
59 |
|
60 CMccFileSourceImpl( TUint32 aEndpointId ); |
|
61 |
|
62 virtual ~CMccFileSourceImpl(); |
|
63 |
|
64 /** |
|
65 * Sets the media sink for output |
|
66 * @since SWIS Lite |
|
67 * @param MCMRMediaSink* aSink |
|
68 */ |
|
69 virtual void AddDataSink( MCMRMediaSink* aSink ); |
|
70 |
|
71 /** |
|
72 * Opens a 3GP file for streaming |
|
73 * @since SWIS Lite |
|
74 * @param TFileName aFileName |
|
75 */ |
|
76 virtual void OpenFileL( TFileName aFileName, TBool aFileChangeMode = EFalse ); |
|
77 |
|
78 /** |
|
79 * Closes the 3GP file |
|
80 * @since SWIS Lite |
|
81 */ |
|
82 virtual void CloseFileL( TBool aFileChangeMode = EFalse ); |
|
83 |
|
84 /** |
|
85 * Gets filename |
|
86 */ |
|
87 TFileName& FileNameL(); |
|
88 |
|
89 /** |
|
90 * Seeks to given position in a file |
|
91 * @since SWIS Lite |
|
92 * @param TTimeIntervalMicroSeconds aPosition |
|
93 */ |
|
94 virtual void SetPositionL( TTimeIntervalMicroSeconds aPosition ); |
|
95 |
|
96 /** |
|
97 * Returns the current video type |
|
98 * @since SWIS Lite |
|
99 * @param |
|
100 * @return CCMRMediaBuffer::TBufferType |
|
101 */ |
|
102 virtual CCMRMediaBuffer::TBufferType VideoTypeL(); |
|
103 |
|
104 /** |
|
105 * Returns the current audio type |
|
106 * @since SWIS Lite |
|
107 * @return CCMRMediaBuffer::TBufferType |
|
108 */ |
|
109 virtual CCMRMediaBuffer::TBufferType AudioTypeL(); |
|
110 |
|
111 /** |
|
112 * Returns the current video framerate |
|
113 * @since SWIS Lite |
|
114 * @return TReal32 |
|
115 */ |
|
116 virtual TReal VideoFrameRateL(); |
|
117 |
|
118 /** |
|
119 * Returns the current audio bitrate |
|
120 * @since SWIS Lite |
|
121 * @param |
|
122 * @return TUint |
|
123 */ |
|
124 virtual TUint32 AudioBitRateL(); |
|
125 |
|
126 /** |
|
127 * Returns the duration of media clip |
|
128 * @since SWIS Lite |
|
129 * @param |
|
130 * @return TTimeIntervalMicroSeconds |
|
131 */ |
|
132 virtual TTimeIntervalMicroSeconds DurationL(); |
|
133 |
|
134 /** |
|
135 * Returns the video framesize |
|
136 * @since SWIS Lite |
|
137 * @param |
|
138 * @return TSize |
|
139 */ |
|
140 virtual TSize VideoFrameSizeL(); |
|
141 |
|
142 /** |
|
143 * Returns the video bitrate |
|
144 * @since SWIS Lite |
|
145 * @param |
|
146 * @return TUint |
|
147 */ |
|
148 virtual TUint32 VideoBitRateL(); |
|
149 |
|
150 /** |
|
151 * Returns the current reading position |
|
152 * @since SWIS Lite |
|
153 * @param |
|
154 * @return TTimeIntervalMicroSeconds |
|
155 */ |
|
156 virtual TTimeIntervalMicroSeconds PositionL(); |
|
157 |
|
158 /** |
|
159 * Returns the audio fourCC |
|
160 * @return TFourCC |
|
161 */ |
|
162 virtual TFourCC AudioFourCCL(); |
|
163 |
|
164 /** |
|
165 * Returns the video fourCC |
|
166 * @return TFourCC |
|
167 */ |
|
168 virtual TFourCC VideoFourCCL(); |
|
169 |
|
170 /** |
|
171 * Returns config key of opened clip |
|
172 * @param aConfigKey, config key is set to this input param |
|
173 */ |
|
174 void GetConfigKeyL( TDes8& aConfigKey ); |
|
175 |
|
176 |
|
177 public: // From MDataSource |
|
178 |
|
179 /** |
|
180 * From MDataSource. Returns the data type as a fourCC code of the data source. |
|
181 * |
|
182 * @since Series 60 3.0 |
|
183 * @param "aMediaId" |
|
184 * This identifies the type of media eg audio or video and the stream id. |
|
185 * Only KUidMediaTypeAudio -mediatype is supported. |
|
186 * @return The fourCC code identifying the source datatype for the specified aMediaId. |
|
187 */ |
|
188 TFourCC SourceDataTypeCode( TMediaId /*aMediaId*/ ); |
|
189 |
|
190 /** |
|
191 * From MDataSource. Sets the data type as a fourCC code for the data source |
|
192 * |
|
193 * @since Series 60 3.0 |
|
194 * @param "aSourceFourCC" |
|
195 * This specifies the data type as a fourCC code to set the source to. |
|
196 * |
|
197 * @param "aMediaId" |
|
198 * This identifies the type of media eg audio or video and the stream id. |
|
199 * Only KUidMediaTypeAudio -mediatype is supported. |
|
200 * |
|
201 * @return KErrNone if successful, KErrNotSupported if the source does not support having |
|
202 * it's data type set, otherwise a system wide error code. |
|
203 */ |
|
204 TInt SetSourceDataTypeCode( TFourCC aCodec, |
|
205 TMediaId aMedia ); |
|
206 |
|
207 |
|
208 /** |
|
209 * From MDataSource. Method to 'prime' the data source. |
|
210 * |
|
211 * Datasource is set to primed state. |
|
212 * |
|
213 * @since Series 60 3.0 |
|
214 * @return None |
|
215 */ |
|
216 void SourcePrimeL(); |
|
217 |
|
218 /** |
|
219 * From MDataSource. Method to 'play' the data source. |
|
220 * |
|
221 * Downlink timeout timer is started and datasource is set to playing state. |
|
222 * |
|
223 * @since Series 60 3.0 |
|
224 * @return None |
|
225 */ |
|
226 void SourcePlayL( TBool aIgnoreEvents = EFalse, TBool aFileChangeMode = EFalse ); |
|
227 |
|
228 /** |
|
229 * From MDataSource. Method to 'pause' the data source. |
|
230 * |
|
231 * Downlink timeout timer is stopped and datasource is set to paused state. |
|
232 * |
|
233 * @since Series 60 3.0 |
|
234 * @return None |
|
235 */ |
|
236 void SourcePauseL(); |
|
237 |
|
238 /** |
|
239 * From MDataSource. Method to 'stop' the data source. |
|
240 * |
|
241 * Downlink timeout timer is stopped and datasource is set to stopped state. |
|
242 * |
|
243 * @since Series 60 3.0 |
|
244 * @return None |
|
245 */ |
|
246 void SourceStopL( TBool aIgnoreEvents = EFalse, TBool aFileChangeMode = EFalse ); |
|
247 |
|
248 /** |
|
249 * From MDataSource. Method called by a MDataSink to request the data source to fill aBuffer with data. |
|
250 * |
|
251 * Datasource gets packet from jitterbuffer and forwards it to the payloadformatdecoder |
|
252 * for further processing. Datasource works synchronously; consumers BufferFilledL |
|
253 * is called when RTP packet is got succesfully from jitterbuffer. |
|
254 * |
|
255 * @since Series 60 3.0 |
|
256 * @param "aBuffer" |
|
257 * The buffer that needs filling with data |
|
258 * |
|
259 * @param "aConsumer" |
|
260 * The data sink that consumes the data. The data source needs this to make the BufferFilledL |
|
261 * callback on aConsumer when the data source has completed filling the aBuffer. |
|
262 * |
|
263 * @param "aMediaId" |
|
264 * This identifies the type of media eg audio or video and the stream id. |
|
265 * This parameter is required in cases where the source can supply data |
|
266 * of more than one media type and/or multiple strams of data eg a multimedia file. |
|
267 * @return None |
|
268 */ |
|
269 void FillBufferL( CMMFBuffer* aBuffer, |
|
270 MDataSink* aConsumer, |
|
271 TMediaId aMediaId ); |
|
272 |
|
273 TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
274 |
|
275 void SourceThreadLogoff(); |
|
276 |
|
277 public: |
|
278 void PauseAudioL( TInt aError = KErrNone ); |
|
279 void PauseVideoL( TInt aError = KErrNone ); |
|
280 |
|
281 void SetDelayAfterStop( TInt aDelay ); |
|
282 TInt DelayAfterStop() const; |
|
283 |
|
284 void StopEofTimer(); |
|
285 void EofTimerExpiredL(); // from MMccEofTimerObserver |
|
286 |
|
287 public: |
|
288 |
|
289 static TTimeIntervalMicroSeconds MilliToMicroSeconds( TUint32 aMilliSeconds ); |
|
290 static TUint32 MicroToMilliSeconds( TTimeIntervalMicroSeconds aMicroSeconds ); |
|
291 |
|
292 private: |
|
293 |
|
294 void ConstructL( MMccResources* aMccResources ); |
|
295 |
|
296 private: |
|
297 void FileOpenErrorL( MP4Err error ); |
|
298 |
|
299 void SendStreamEventToClient( TMccEventCategory aEventCategory, |
|
300 TMccEventType aEventType, |
|
301 TInt aError = KErrNone, |
|
302 TUint32 aEventNumData = 0 ); |
|
303 |
|
304 void SetFileName( const TFileName& aFileName ); |
|
305 |
|
306 void OpenFileForStreamingL( TFileName aFileName ); |
|
307 |
|
308 TBool AudioInUse() const; |
|
309 |
|
310 TBool VideoInUse() const; |
|
311 |
|
312 void DoCleanupL( TBool aFileChangeMode ); |
|
313 |
|
314 void StartEofTimerL(); |
|
315 |
|
316 void ClearEvent(); |
|
317 |
|
318 TBool StartNeededL( CMccFileSourceTypeBase& aFileSource ); |
|
319 |
|
320 |
|
321 private: |
|
322 |
|
323 // 3GP library handle |
|
324 MP4Handle iMP4Handle; |
|
325 |
|
326 enum TCurrentState |
|
327 { |
|
328 EConstructed = 0, |
|
329 EPrimed, |
|
330 EPaused, |
|
331 EWaitingPause, |
|
332 EStopped, // Equals EConstructed |
|
333 EPlaying // Streaming (timers active) |
|
334 }; |
|
335 |
|
336 TCurrentState iCurrentState; |
|
337 |
|
338 TBool iIsAudio; |
|
339 TBool iIsVideo; |
|
340 CMccFileAudio* iFileAudio; |
|
341 CMccFileVideo* iFileVideo; |
|
342 |
|
343 MAsyncEventHandler* iAsyncEventHandler; |
|
344 |
|
345 TUint32 iEndpointId; |
|
346 |
|
347 TFileName iFileName; |
|
348 |
|
349 TMccEvent iMccEvent; |
|
350 |
|
351 TInt iDelayAfterStop; |
|
352 |
|
353 CMccEofTimer* iEofTimer; |
|
354 |
|
355 #ifdef EUNIT_TEST |
|
356 friend class UT_CMccFileSourceImpl; |
|
357 friend class UT_CMccMultiplexer; |
|
358 #endif |
|
359 }; |
|
360 |
|
361 |
|
362 #endif // end of MCCFILESOURCEIMPL_H |
|
363 |
|
364 |
|
365 // End of file |