|
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 MCCVIDEOSOURCEIMPL_H |
|
22 #define MCCVIDEOSOURCEIMPL_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 <CCMRMediaRecorder.h> |
|
30 #include <CCMRMediaSink.h> |
|
31 |
|
32 #include "mmccevents.h" |
|
33 #include "mcccamerahandler.h" |
|
34 #include "mccinternalcodecs.h" |
|
35 |
|
36 class CMccVideoSourceWrapper; |
|
37 class MMccResources; |
|
38 // CLASS DECLARATION |
|
39 |
|
40 |
|
41 // Try to maintain the frame-rate |
|
42 // (1.0 means the picture quality is sacrificed |
|
43 // "all the way" to match the target fps |
|
44 const TReal KMccLatencyQyalityTradeoff = 0.0; |
|
45 |
|
46 /** |
|
47 * |
|
48 */ |
|
49 class CMccVideoSourceImpl: public CBase, |
|
50 public MCMRMediaSink, |
|
51 public MCMRMediaRecorderObserver, |
|
52 public MMccCameraHandlerObserver |
|
53 { |
|
54 |
|
55 public: // Methods called internally or by the controller |
|
56 |
|
57 /** |
|
58 * Two-phased constructor. |
|
59 * @param aConfigKeyRetrieval, ETrue if source is used for config key retrieval |
|
60 */ |
|
61 static CMccVideoSourceImpl* NewL( TUint32 aEndpointId, |
|
62 MMccResources* aMccResources = NULL, |
|
63 TBool aConfigKeyRetrieval = EFalse ); |
|
64 |
|
65 CMccVideoSourceImpl( TUint32 aEndpointId, |
|
66 MMccResources* aMccResources, |
|
67 TBool aConfigKeyRetrieval ); |
|
68 |
|
69 virtual ~CMccVideoSourceImpl(); |
|
70 |
|
71 public: // new |
|
72 |
|
73 void SetResources( MMccResources* aResources ); |
|
74 |
|
75 void SetCameraHandler( MMccCameraHandler& aCameraHandler ); |
|
76 |
|
77 void SetVideoCodecL( const TMccCodecInfo& aVideoCodec ); |
|
78 |
|
79 void GetVideoCodecL( TMccCodecInfo& aVideoCodec ); |
|
80 |
|
81 void GetSupportedVideoCodecsL( RArray<TFourCC>& aVideoTypes ); |
|
82 |
|
83 void SetAudioCodecL( const TMccCodecInfo& aAudioCodec ); |
|
84 |
|
85 void GetAudioCodecL( TMccCodecInfo& aAudioCodec ); |
|
86 |
|
87 void GetSupportedAudioCodecsL( RArray<TFourCC>& aAudioTypes ); |
|
88 |
|
89 void SetAudioEnabledL( TBool aEnabled ); |
|
90 |
|
91 TBool AudioEnabledL() const; |
|
92 |
|
93 void SetGainL( TInt aGain ); |
|
94 |
|
95 TInt GainL() const; |
|
96 |
|
97 TInt MaxGainL() const; |
|
98 |
|
99 TInt RateAdaptationRequest( const TMccEvent& aInputData, TMccEvent& aOutputData ); |
|
100 |
|
101 TBool IsStopped() const; |
|
102 |
|
103 void GetConfigKeyL( const TMccCodecInfo& aVideoCodec, |
|
104 TDes8& aConfigKey, |
|
105 TBool aAllowAsyncRetrieval = ETrue ); |
|
106 |
|
107 TBool HasConfigKey() const; |
|
108 |
|
109 public: |
|
110 |
|
111 /** |
|
112 * Returns the data type as a fourCC code of the data source. |
|
113 * |
|
114 * @since Series 60 3.0 |
|
115 * @param "aMediaId" |
|
116 * This identifies the type of media eg audio or video and the stream id. |
|
117 * Only KUidMediaTypeAudio -mediatype is supported. |
|
118 * @return The fourCC code identifying the source datatype for the specified aMediaId. |
|
119 */ |
|
120 TFourCC SourceDataTypeCode( TMediaId /*aMediaId*/ ); |
|
121 |
|
122 /** |
|
123 * Sets the data type as a fourCC code for the data source |
|
124 * |
|
125 * @since Series 60 3.0 |
|
126 * @param "aSourceFourCC" |
|
127 * This specifies the data type as a fourCC code to set the source to. |
|
128 * |
|
129 * @param "aMediaId" |
|
130 * This identifies the type of media eg audio or video and the stream id. |
|
131 * Only KUidMediaTypeAudio -mediatype is supported. |
|
132 * |
|
133 * @return KErrNone if successful, KErrNotSupported if the source does not support having |
|
134 * it's data type set, otherwise a system wide error code. |
|
135 */ |
|
136 TInt SetSourceDataTypeCode( TFourCC aCodec, |
|
137 TMediaId aMedia ); |
|
138 |
|
139 /** |
|
140 * Not used. Leaves with KErrNotSupported. |
|
141 * |
|
142 * @since Series 60 3.0 |
|
143 * @param "aBuffer" |
|
144 * The buffer that has been emptied by a data sink and is now available for reuse |
|
145 * @return None |
|
146 */ |
|
147 void BufferEmptiedL( CMMFBuffer* aBuffer ); |
|
148 |
|
149 /** |
|
150 * Method to indicate whether the data source can create a buffer. |
|
151 * |
|
152 * @since Series 60 3.0 |
|
153 * |
|
154 * @return EFalse |
|
155 */ |
|
156 TBool CanCreateSourceBuffer(); |
|
157 |
|
158 /** |
|
159 * Not used. Leaves with KErrNotSupported. |
|
160 * |
|
161 * @since Series 60 3.0 |
|
162 * @param "aMediaId" |
|
163 * This identifies the type of media eg audio or video and the stream id. |
|
164 * This parameter is required in cases where the source can supply data |
|
165 * of more than one media type and/or multiple strams of data eg a multimedia file. |
|
166 * |
|
167 * @param "aReference" |
|
168 * This must be written to by the method to indicate whether the created buffer is |
|
169 * a 'reference' buffer. A 'reference' buffer is a buffer that is owned by the source |
|
170 * and should be used in preference to the sink buffer provided the sink buffer |
|
171 * is also not a reference buffer. |
|
172 * . |
|
173 * @return The created buffer |
|
174 */ |
|
175 CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, |
|
176 TBool& aReference ); |
|
177 |
|
178 /** |
|
179 * Method to 'logon' the data source to the same thread that source will be supplying data in. |
|
180 * |
|
181 * Jitterbuffer for incoming packets and downlink timeout timer are created here. |
|
182 * |
|
183 * @param "aEventHandler" |
|
184 * This is an MAsyncEventHandler to handle asynchronous events that occur during the |
|
185 * transfer of multimedia data. The event handler must be in the same thread as the data transfer |
|
186 * thread - hence the reason it is passed in the SourceThreadLogon as opposed to say the constructor. |
|
187 * |
|
188 * |
|
189 * @return KErrNone if successful, otherwise a system wide error code. |
|
190 */ |
|
191 TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
192 |
|
193 /** |
|
194 * Method to 'logoff' the data source from the same thread that source supplies data in. |
|
195 * |
|
196 * Jitterbuffer for incoming packets and downlink timeout timer are deleted. Datasource deletes the |
|
197 * stream(s) and unregisters itself as an observer for the RTP session for incoming RTP and RTCP packets. |
|
198 * |
|
199 * @return None |
|
200 */ |
|
201 void SourceThreadLogoff(); |
|
202 |
|
203 /** |
|
204 * Method to 'prime' the data source. |
|
205 * |
|
206 * Datasource is set to primed state. If multiple codecs are using the source, |
|
207 * prime is not done fully yet at this stage, instead it is done later once once of the codecs |
|
208 * starts using the source. |
|
209 * |
|
210 * @param aMultipleCodecs, ETrue if multiple codecs are using the source |
|
211 * |
|
212 * @since Series 60 3.0 |
|
213 * @return None |
|
214 */ |
|
215 void SourcePrimeL( TBool aMultipleCodecs = EFalse ); |
|
216 |
|
217 /** |
|
218 * Method to 'play' the data source. |
|
219 * |
|
220 * Downlink timeout timer is started and datasource is set to playing state. |
|
221 * |
|
222 * @since Series 60 3.0 |
|
223 * @return None |
|
224 */ |
|
225 void SourcePlayL(); |
|
226 |
|
227 /** |
|
228 * Method to 'pause' the data source. |
|
229 * |
|
230 * Downlink timeout timer is stopped and datasource is set to paused state. |
|
231 * |
|
232 * @since Series 60 3.0 |
|
233 * @return None |
|
234 */ |
|
235 void SourcePauseL(); |
|
236 |
|
237 /** |
|
238 * Method to 'stop' the data source. |
|
239 * |
|
240 * Downlink timeout timer is stopped and datasource is set to stopped state. |
|
241 * |
|
242 * @since Series 60 3.0 |
|
243 * @return None |
|
244 */ |
|
245 void SourceStopL(); |
|
246 |
|
247 /** |
|
248 * Method called by a MDataSink to request the data source to fill aBuffer with data. |
|
249 * |
|
250 * Datasource gets packet from jitterbuffer and forwards it to the payloadformatdecoder |
|
251 * for further processing. Datasource works synchronously; consumers BufferFilledL |
|
252 * is called when RTP packet is got succesfully from jitterbuffer. |
|
253 * |
|
254 * @since Series 60 3.0 |
|
255 * @param "aBuffer" |
|
256 * The buffer that needs filling with data |
|
257 * |
|
258 * @param "aConsumer" |
|
259 * The data sink that consumes the data. The data source needs this to make the BufferFilledL |
|
260 * callback on aConsumer when the data source has completed filling the aBuffer. |
|
261 * |
|
262 * @param "aMediaId" |
|
263 * This identifies the type of media eg audio or video and the stream id. |
|
264 * This parameter is required in cases where the source can supply data |
|
265 * of more than one media type and/or multiple strams of data eg a multimedia file. |
|
266 * @return None |
|
267 */ |
|
268 void FillBufferL( CMMFBuffer* aBuffer, |
|
269 MDataSink* aConsumer, |
|
270 TMediaId aMediaId ); |
|
271 |
|
272 /** |
|
273 * Method to negotiate sink. |
|
274 */ |
|
275 void NegotiateSourceL( MDataSink& aDataSink ); |
|
276 |
|
277 public: // From MCMRMediaSink |
|
278 |
|
279 /** |
|
280 * Write a buffer to sink |
|
281 * @since 2.1 |
|
282 * @param CCMRMediaBuffer* aBuffer The buffer to write |
|
283 * @return TInt Error code |
|
284 */ |
|
285 virtual void WriteBufferL(CCMRMediaBuffer* aBuffer); |
|
286 |
|
287 /** |
|
288 * Inform video frame size to sink |
|
289 * @since 2.1 |
|
290 * @param TSize aSize Video frame size |
|
291 * @return TInt Error code |
|
292 */ |
|
293 virtual TInt SetVideoFrameSize(TSize aSize); |
|
294 |
|
295 /** |
|
296 * Inform average video bitrate to sink |
|
297 * @since 2.1 |
|
298 * @param TInt aBitRate Average video bitrate |
|
299 * @return TInt Error code |
|
300 */ |
|
301 virtual TInt SetAverageVideoBitRate(TInt aBitRate); |
|
302 |
|
303 /** |
|
304 * Inform maximum video bitrate to sink |
|
305 * @since 2.1 |
|
306 * @param TInt aBitRate Maximum expected video bitrate |
|
307 * @return TInt Error code |
|
308 */ |
|
309 virtual TInt SetMaxVideoBitRate(TInt aBitRate); |
|
310 |
|
311 /** |
|
312 * Inform average audio bitrate to sink |
|
313 * @since 2.1 |
|
314 * @param TInt aBitRate Average audio bitrate |
|
315 * @return TInt Error code |
|
316 */ |
|
317 virtual TInt SetAverageAudioBitRate(TInt aBitRate); |
|
318 |
|
319 public: // From MCMRMediaRecorderObserver |
|
320 |
|
321 /** |
|
322 * Informs the user that PrepareL() has been completed with or |
|
323 * without errors. If aError != KErrNone, media recorder remains in |
|
324 * open state |
|
325 * @since 2.1 |
|
326 * @param aError Error code |
|
327 * @return void |
|
328 */ |
|
329 virtual void MmroPrepareComplete(TInt aError); |
|
330 |
|
331 /** |
|
332 * Informs the user about a state change. |
|
333 * Useful to find out when a new prepare is needed after |
|
334 * a setting was changed |
|
335 * @since 2.1 |
|
336 * @param aState New state (CCMRMediaRecorder - TRecorderState) |
|
337 * @param aError Error code |
|
338 * @return void |
|
339 */ |
|
340 virtual void MmroStateChange(TInt aState, TInt aError); |
|
341 |
|
342 /** |
|
343 * Informs the user about a temporary runtime error. |
|
344 * Recording can't continue right now but it may |
|
345 * be possible to continue later (e.g. audio HW was |
|
346 * taken by a higher priority application) |
|
347 * @since 2.1 |
|
348 * @param aError Error code |
|
349 * @return void |
|
350 */ |
|
351 virtual void MmroTemporaryError(TInt aError); |
|
352 |
|
353 /** |
|
354 * Informs the user about a fatal runtime error (e.g. OOM). |
|
355 * MediaRecorder must be deleted and recreated. |
|
356 * @since 2.1 |
|
357 * @param aError Error code |
|
358 * @return void |
|
359 */ |
|
360 virtual void MmroFatalError(TInt aError); |
|
361 |
|
362 public: // From MMccCameraHandlerObserver |
|
363 |
|
364 virtual void CameraReady( TInt aError ); |
|
365 |
|
366 private: |
|
367 |
|
368 void SendStreamEventToClient( TMccEventType aEventType, |
|
369 TInt aError = KErrNone, |
|
370 TUint32 aEventNumData = 0 ); |
|
371 |
|
372 void SetAutoPlayMode( TBool aIsInAutoPlayMode ); |
|
373 |
|
374 TBool AutoPlayMode() const; |
|
375 |
|
376 TBool CopyBufferData( CMMFBuffer& aDstBuffer, |
|
377 CCMRMediaBuffer& aSrcBuffer ); |
|
378 |
|
379 TBool CopyBufferData( CMMFBuffer& aDstBuffer, |
|
380 CMMFDataBuffer& aSrcBuffer ); |
|
381 |
|
382 TBool QueueBufferL( CCMRMediaBuffer& aBuffer ); |
|
383 |
|
384 CMMFDataBuffer* FetchQueuedBuffer(); |
|
385 |
|
386 void DoBufferFilledL(); |
|
387 |
|
388 void ConstructL(); |
|
389 |
|
390 TInt SetVideoBitrate( TUint& aVideoBitrate ); |
|
391 |
|
392 void RateAdaptationRequestL( const TMccEvent& aInputData, |
|
393 TMccEvent& aOutputData ); |
|
394 |
|
395 void DoCodecSpecificConfigurationL( TUid& aEncoderUid ); |
|
396 |
|
397 HBufC8* GetFmtpLC( const TMccCodecInfo& aCodecInfo ); |
|
398 |
|
399 void SetConfigKeyL( const TDesC8& aData ); |
|
400 |
|
401 TBool FullPrepareAllowed(); |
|
402 |
|
403 void WriteFirstBufferL(); |
|
404 |
|
405 /** |
|
406 * Adds buffer to queue |
|
407 * @param aBuffer, ownership is transferred |
|
408 */ |
|
409 void AddIFrameToQueueL( CMMFDataBuffer* aBuffer ); |
|
410 |
|
411 void HandleCameraReservationL(); |
|
412 |
|
413 void StopCameraMonitoring(); |
|
414 |
|
415 private: |
|
416 |
|
417 // video codec fourcc code |
|
418 HBufC8* iVideoCodecFourCC; |
|
419 TFourCC iVideoFourCC; |
|
420 TFourCC iAudioFourCC; |
|
421 |
|
422 CMccVideoSourceWrapper* iMediaRecorder; |
|
423 |
|
424 MDataSource* iAudioSource; |
|
425 MMccCameraHandler* iCameraHandler; |
|
426 TMMFPrioritySettings iPrioritySettings; |
|
427 |
|
428 TMccCodecInfo iVideoCodec; |
|
429 |
|
430 TInt iAverageAudioBitRate; |
|
431 TInt iAudioGain; |
|
432 TBool iAudioEnabled; |
|
433 |
|
434 TReal32 iFrameRate; |
|
435 |
|
436 CMMFDataBuffer* iFrameVideoBufferOne; |
|
437 MDataSink* iVideoConsumer; |
|
438 CMMFBuffer* iVideoConsumerBuffer; |
|
439 |
|
440 MAsyncEventHandler* iAsyncEventHandler; |
|
441 |
|
442 TUint32 iEndpointId; |
|
443 MMccResources* iMccResources; |
|
444 TUint iMaxNegBitRate; |
|
445 |
|
446 TBool iAutoPlayMode; |
|
447 |
|
448 RPointerArray<CMMFDataBuffer> iVideoQueue; |
|
449 |
|
450 TBool iMultipleCodecs; |
|
451 |
|
452 // Key as base64 encoded |
|
453 HBufC8* iConfigKey; |
|
454 |
|
455 // Key as raw data |
|
456 HBufC8* iConfigKeyData; |
|
457 |
|
458 TBool iConfigKeyRetrieval; |
|
459 |
|
460 TBool iFirstIFrameQueued; |
|
461 |
|
462 private: |
|
463 #ifdef TEST_EUNIT |
|
464 friend class UT_CMccVideoSourceImpl; |
|
465 friend class UT_CMccVideoSource; |
|
466 #endif |
|
467 }; |
|
468 |
|
469 |
|
470 #endif |
|
471 |
|
472 |
|
473 // End of file |