|
1 /* |
|
2 * Copyright (c) 2005-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: Implements format decode interface for redundancy plugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "rtpheader.h" |
|
24 #include "mccredpayloadread.h" |
|
25 #include "mccreddecoder.h" |
|
26 #include "mccredpayloadformatdefs.h" |
|
27 #include "formatstatemachine.h" |
|
28 |
|
29 // ============================= LOCAL FUNCTIONS =============================== |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMccRedPayloadRead::CMccRedPayloadRead |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CMccRedPayloadRead::CMccRedPayloadRead() |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CMccRedPayloadRead::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CMccRedPayloadRead::ConstructL( MDataSource* aSource ) |
|
49 { |
|
50 DP_RED_DECODE( "CMccRedPayloadRead::ConstructL" ) |
|
51 __ASSERT_ALWAYS( aSource, User::Leave( KErrArgument ) ); |
|
52 |
|
53 iClip = aSource; |
|
54 iRedDecoder = CMccRedDecoder::NewL(); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CMccRedPayloadRead::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CMccRedPayloadRead* CMccRedPayloadRead::NewL( MDataSource* aSource ) |
|
63 { |
|
64 DP_RED_DECODE( "CMccRedPayloadRead::NewL" ) |
|
65 __ASSERT_ALWAYS( aSource, User::Leave( KErrArgument ) ); |
|
66 |
|
67 CMccRedPayloadRead* self = new( ELeave ) CMccRedPayloadRead; |
|
68 |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL( aSource ); |
|
71 CleanupStack::Pop( self ); |
|
72 |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 // Destructor |
|
78 CMccRedPayloadRead::~CMccRedPayloadRead() |
|
79 { |
|
80 DP_RED_DECODE( "CMccRedPayloadRead::~CMccRedPayloadRead" ) |
|
81 |
|
82 delete iRedDecoder; |
|
83 if ( iSourceBufOwnership ) |
|
84 { |
|
85 delete iSourceBuffer; |
|
86 } |
|
87 else |
|
88 { |
|
89 iSourceBuffer = NULL; |
|
90 } |
|
91 |
|
92 iDataSink = NULL; |
|
93 iClip = NULL; |
|
94 iSinkBuffer = NULL; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CMccRedPayloadRead::ConfigurePayloadFormatL |
|
99 // Configure payload decoding parameters. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CMccRedPayloadRead::ConfigurePayloadFormatL( const TDesC8& aConfigParams ) |
|
103 { |
|
104 DP_RED_DECODE( "CMccRedPayloadRead::ConfigurePayloadFormatL" ) |
|
105 __ASSERT_ALWAYS( aConfigParams.Size() == sizeof( TMccRedPayloadReadConfig ), |
|
106 User::Leave( KErrArgument ) ); |
|
107 |
|
108 TMccRedPayloadReadPckg cPckg; |
|
109 cPckg.Copy( aConfigParams ); |
|
110 iPLConfig = cPckg(); |
|
111 |
|
112 __ASSERT_ALWAYS( iPLConfig.iRedBlockCount <= KMaxRedCount, |
|
113 User::Leave( KErrArgument ) ); |
|
114 |
|
115 if ( iSourceBuffer && iSourceBufOwnership ) |
|
116 { |
|
117 delete iSourceBuffer; |
|
118 iSourceBuffer = NULL; |
|
119 } |
|
120 |
|
121 // Extra variables for clarity |
|
122 TInt redPayloadSize |
|
123 = iPLConfig.iMaxPayloadSize * ( 1 + iPLConfig.iRedBlockCount ); |
|
124 TInt redHeadersSize |
|
125 = iPLConfig.iRedBlockCount * KRedHeaderSize + KFinalHeaderSize; |
|
126 |
|
127 iSourceBuffer = CreateClipBufferL( redPayloadSize + redHeadersSize, |
|
128 iSourceBufOwnership ); |
|
129 iRedDecoder->InitializeL( iPLConfig.iRedBlockCount, |
|
130 iPLConfig.iMaxPayloadSize, |
|
131 iPLConfig.iNumOfEncodings ); |
|
132 |
|
133 RArray<TUint> encPTs; |
|
134 CleanupClosePushL( encPTs ); |
|
135 |
|
136 TInt maxNumOfEncodings = iPLConfig.iEncPayloadTypes.Count(); |
|
137 for ( TInt i = 0; i < maxNumOfEncodings; i++ ) |
|
138 { |
|
139 if ( KPayloadNotDefined != iPLConfig.iEncPayloadTypes[i] ) |
|
140 { |
|
141 encPTs.AppendL( iPLConfig.iEncPayloadTypes[i] ); |
|
142 } |
|
143 } |
|
144 |
|
145 User::LeaveIfError( iRedDecoder->SetPayloadTypes( encPTs ) ); |
|
146 CleanupStack::PopAndDestroy( &encPTs ); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CMccRedPayloadRead::BufferFilledL |
|
151 // Redundancy format is decoded from parameter buffer and result is passed |
|
152 // to the data sink of redundancy payload plugin. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CMccRedPayloadRead::DataBufferFilledL( CMMFBuffer* aBuffer, |
|
156 const TRtpRecvHeader& aRecvHeader ) |
|
157 { |
|
158 DP_RED_DECODE( "CMccRedPayloadRead::DataBufferFilledL" ) |
|
159 |
|
160 __ASSERT_ALWAYS( aBuffer, User::Leave( KErrArgument ) ); |
|
161 __ASSERT_ALWAYS( KUidMmfDataBuffer == aBuffer->Type(), |
|
162 User::Leave( KErrNotSupported ) ); |
|
163 __ASSERT_ALWAYS( iDataSink, User::Leave( KErrNotReady ) ); |
|
164 |
|
165 if ( aRecvHeader.iPayloadType == iPLConfig.iRedPayloadType ) |
|
166 { |
|
167 iRedDecoder->SetEncodingBlockL( EMccRTPPayload, |
|
168 static_cast<CMMFDataBuffer*>( aBuffer )->Data() ); |
|
169 |
|
170 TInt numOfBlocks = User::LeaveIfError( |
|
171 iRedDecoder->DecodePayload( aRecvHeader.iTimestamp ) ); |
|
172 |
|
173 if ( numOfBlocks ) |
|
174 { |
|
175 iRedDecoder->GetEncodingBlockL( |
|
176 EMccPrimaryEncoding, iSinkBuffer->Data() ); |
|
177 } |
|
178 } |
|
179 else |
|
180 { |
|
181 iSinkBuffer->Data().Copy( static_cast<CMMFDataBuffer*>( aBuffer )->Data() ); |
|
182 } |
|
183 |
|
184 DP_RED_DECODE( "CMccRedPayloadRead::DataBufferFilledL - Buffer decoded" ) |
|
185 |
|
186 // Payload format read is data sink for redundancy plugin |
|
187 static_cast<CPayloadFormatRead*>( iDataSink ) |
|
188 ->DataBufferFilledL( iSinkBuffer, aRecvHeader ); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CMccRedPayloadRead::Streams |
|
193 // NOT USED. Pure virtual method implementation from CMMFormatDecode needed. |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TUint CMccRedPayloadRead::Streams( TUid aMediaType ) const |
|
197 { |
|
198 DP_RED_DECODE( "CMccRedPayloadRead::Streams" ) |
|
199 |
|
200 if ( KUidMediaTypeAudio == aMediaType ) |
|
201 { |
|
202 return 1; |
|
203 } |
|
204 else |
|
205 { |
|
206 return 0; |
|
207 } |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CMccRedPayloadRead::FrameTimeInterval |
|
212 // NOT USED. Pure virtual method implementation from CMMFormatDecode needed. |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 TTimeIntervalMicroSeconds CMccRedPayloadRead::FrameTimeInterval( |
|
216 TMediaId /*aMediaType*/ ) const |
|
217 { |
|
218 DP_RED_DECODE( "CMccRedPayloadRead::FrameTimeInterval" ) |
|
219 |
|
220 return TTimeIntervalMicroSeconds( TInt64( 0 ) ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CMccRedPayloadRead::Duration |
|
225 // NOT USED. Pure virtual method implementation from CMMFormatDecode needed. |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 TTimeIntervalMicroSeconds CMccRedPayloadRead::Duration( |
|
229 TMediaId /*aMediaType*/ ) const |
|
230 { |
|
231 DP_RED_DECODE( "CMccRedPayloadRead::Duration" ) |
|
232 |
|
233 return TTimeIntervalMicroSeconds( TInt64( 0 ) ); |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CMccRedPayloadRead::SourceDataTypeCode |
|
238 // Returns the current datatype FourCC code. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 TFourCC CMccRedPayloadRead::SourceDataTypeCode( TMediaId aMediaId ) |
|
242 { |
|
243 DP_RED_DECODE( "CMccRedPayloadRead::SourceDataTypeCode" ) |
|
244 |
|
245 if ( KUidMediaTypeAudio == aMediaId.iMediaType ) |
|
246 { |
|
247 return iFourCC; |
|
248 } |
|
249 else |
|
250 { |
|
251 return TFourCC(); //defaults to 'NULL' fourCC |
|
252 } |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CMccRedPayloadRead::SetSourceDataTypeCode |
|
257 // Sets source datatype fourCC code. |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 TInt CMccRedPayloadRead::SetSourceDataTypeCode( TFourCC aSourceFourCC, |
|
261 TMediaId aMediaId ) |
|
262 { |
|
263 DP_RED_DECODE( "CMccRedPayloadRead::SetSourceDataTypeCode" ) |
|
264 |
|
265 if ( KUidMediaTypeAudio != aMediaId.iMediaType ) |
|
266 { |
|
267 return KErrNotSupported; |
|
268 } |
|
269 |
|
270 iFourCC = aSourceFourCC; |
|
271 return KErrNone; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CMccRedPayloadRead::CanCreateSourceBuffer |
|
276 // |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 TBool CMccRedPayloadRead::CanCreateSourceBuffer() |
|
280 { |
|
281 DP_RED_DECODE( "CMccRedPayloadRead::CanCreateSourceBuffer" ) |
|
282 |
|
283 return ETrue; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CMccRedPayloadRead::CreateSourceBufferL |
|
288 // |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 CMMFBuffer* CMccRedPayloadRead::CreateSourceBufferL( TMediaId aMediaId, |
|
292 TBool& aReference ) |
|
293 { |
|
294 DP_RED_DECODE( "CMccRedPayloadRead::CreateSourceBufferL" ) |
|
295 __ASSERT_ALWAYS( KUidMediaTypeAudio == aMediaId.iMediaType, |
|
296 User::Leave( KErrNotSupported ) ); |
|
297 __ASSERT_ALWAYS( iSuggestedBufSize, User::Leave( KErrNotReady ) ); |
|
298 |
|
299 aReference = EFalse; |
|
300 |
|
301 CMMFDataBuffer* buf = CMMFDataBuffer::NewL( iSuggestedBufSize ); |
|
302 iSuggestedBufSize = 0; |
|
303 return buf; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CMccRedPayloadRead::FillBufferL |
|
308 // |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CMccRedPayloadRead::FillBufferL( CMMFBuffer* aBuffer, |
|
312 MDataSink* aConsumer, |
|
313 TMediaId aMediaId ) |
|
314 { |
|
315 DP_RED_DECODE( "CMccRedPayloadRead::FillBufferL" ) |
|
316 |
|
317 __ASSERT_ALWAYS( NULL != aBuffer, User::Leave( KErrArgument ) ); |
|
318 __ASSERT_ALWAYS( NULL != aConsumer, User::Leave( KErrArgument ) ); |
|
319 __ASSERT_ALWAYS( KUidMediaTypeAudio == aMediaId.iMediaType, |
|
320 User::Leave( KErrNotSupported ) ); |
|
321 __ASSERT_ALWAYS( KUidMmfDataBuffer == aBuffer->Type(), |
|
322 User::Leave( KErrNotSupported ) ); |
|
323 |
|
324 iDataSink = aConsumer; |
|
325 iSinkBuffer = static_cast<CMMFDataBuffer*>( aBuffer ); |
|
326 |
|
327 iClip->FillBufferL( iSourceBuffer, this, aMediaId ); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CMccRedPayloadRead::SourceThreadLogon |
|
332 // Passes state transition to the data source of redundancy payload plugin. |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 TInt CMccRedPayloadRead::SourceThreadLogon( MAsyncEventHandler& aEventHandler ) |
|
336 { |
|
337 DP_RED_DECODE( "CMccRedPayloadRead::SourceThreadLogon" ) |
|
338 |
|
339 return iClip->SourceThreadLogon( aEventHandler ); |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CMccRedPayloadRead::SourceThreadLogoff |
|
344 // Passes state transition to the data source of redundancy payload plugin. |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CMccRedPayloadRead::SourceThreadLogoff() |
|
348 { |
|
349 DP_RED_DECODE( "CMccRedPayloadRead::SourceThreadLogoff" ) |
|
350 |
|
351 iClip->SourceThreadLogoff(); |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CMccRedPayloadRead::SourcePrimeL |
|
356 // Passes state transition to the data source of redundancy payload plugin. |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CMccRedPayloadRead::SourcePrimeL() |
|
360 { |
|
361 DP_RED_DECODE( "CMccRedPayloadRead::SourcePrimeL" ) |
|
362 |
|
363 iClip->SourcePrimeL(); |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CMccRedPayloadRead::SourcePlayL |
|
368 // Passes state transition to the data source of redundancy payload plugin. |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CMccRedPayloadRead::SourcePlayL() |
|
372 { |
|
373 DP_RED_DECODE( "CMccRedPayloadRead::SourcePlayL" ) |
|
374 |
|
375 iClip->SourcePlayL(); |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CMccRedPayloadRead::SourcePauseL |
|
380 // Passes state transition to the data source of redundancy payload plugin. |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 void CMccRedPayloadRead::SourcePauseL() |
|
384 { |
|
385 DP_RED_DECODE( "CMccRedPayloadRead::SourcePauseL" ) |
|
386 |
|
387 iClip->SourcePauseL(); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CMccRedPayloadRead::SourceStopL |
|
392 // Passes state transition to the data source of redundancy payload plugin. |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 void CMccRedPayloadRead::SourceStopL() |
|
396 { |
|
397 DP_RED_DECODE( "CMccRedPayloadRead::SourceStopL" ) |
|
398 |
|
399 iClip->SourceStopL(); |
|
400 } |
|
401 |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CMccRedPayloadRead::NegotiateSourceL |
|
404 // Negotiate Source. |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CMccRedPayloadRead::NegotiateSourceL( MDataSink& aDataSink ) |
|
408 { |
|
409 DP_RED_DECODE( "CMccRedPayloadRead::NegotiateSourceL" ) |
|
410 |
|
411 iDataSink = &aDataSink; |
|
412 iClip->NegotiateSourceL( *this ); |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CMccRedPayloadRead::SuggestSourceBufferSize |
|
417 // |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 void CMccRedPayloadRead::SuggestSourceBufferSize( TUint aSuggestedBufferSize ) |
|
421 { |
|
422 iSuggestedBufSize = aSuggestedBufferSize; |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CMccRedPayloadRead::SinkDataTypeCode |
|
427 // Returns the current datatype FourCC code. |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 TFourCC CMccRedPayloadRead::SinkDataTypeCode( TMediaId aMediaId ) |
|
431 { |
|
432 DP_RED_DECODE( "CMccRedPayloadRead::SinkDataTypeCode" ) |
|
433 |
|
434 if ( KUidMediaTypeAudio == aMediaId.iMediaType ) |
|
435 { |
|
436 if ( iDataSink ) |
|
437 { |
|
438 return iDataSink->SinkDataTypeCode( aMediaId ); |
|
439 } |
|
440 else |
|
441 { |
|
442 return TFourCC(); |
|
443 } |
|
444 } |
|
445 else |
|
446 { |
|
447 return TFourCC(); //defaults to 'NULL' fourCC |
|
448 } |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // CMccRedPayloadRead::SetPayloadTypes |
|
453 // Set payload types to accept as encodings. |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 TInt CMccRedPayloadRead::SetPayloadTypes( RArray<TUint>& aPayloadTypes ) |
|
457 { |
|
458 DP_RED_DECODE( "CMccRedPayloadRead::SetPayloadTypes" ) |
|
459 |
|
460 if ( aPayloadTypes.Count() ) |
|
461 { |
|
462 iPLConfig.iRedPayloadType = static_cast<TUint8>( aPayloadTypes[0] ); |
|
463 aPayloadTypes.Remove( 0 ); |
|
464 |
|
465 return iRedDecoder->SetPayloadTypes( aPayloadTypes ); |
|
466 } |
|
467 else |
|
468 { |
|
469 return KErrArgument; |
|
470 } |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CMccRedPayloadRead::CreateClipBufferL |
|
475 // Creates buffer needed in data transfer with format readers clip. |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 CMMFDataBuffer* CMccRedPayloadRead::CreateClipBufferL( |
|
479 TUint aSize, TBool& aIsOwnBuffer ) |
|
480 { |
|
481 DP_RED_DECODE( "CMccRedPayloadRead::CreateClipBufferL" ) |
|
482 CMMFDataBuffer* buffer( NULL ); |
|
483 |
|
484 if ( iClip->CanCreateSourceBuffer() ) |
|
485 { |
|
486 static_cast<CMMFFormatDecode*>( iClip )->SuggestSourceBufferSize( aSize ); |
|
487 |
|
488 TBool reference( EFalse ); |
|
489 CMMFBuffer* sourceBuf |
|
490 = iClip->CreateSourceBufferL( KUidMediaTypeAudio, reference ); |
|
491 TBool isSupportedBuf |
|
492 = CMMFBuffer::IsSupportedDataBuffer( sourceBuf->Type() ); |
|
493 TBool isOwnBuffer = reference ? EFalse : ETrue; |
|
494 |
|
495 if ( !isSupportedBuf ) |
|
496 { |
|
497 if ( isOwnBuffer ) |
|
498 { |
|
499 delete sourceBuf; |
|
500 } |
|
501 |
|
502 User::Leave( KErrNotSupported ); |
|
503 } |
|
504 |
|
505 aIsOwnBuffer = isOwnBuffer; |
|
506 buffer = static_cast<CMMFDataBuffer*>( sourceBuf ); |
|
507 } |
|
508 else |
|
509 { |
|
510 aIsOwnBuffer = ETrue; |
|
511 buffer = CMMFDataBuffer::NewL( aSize ); |
|
512 } |
|
513 |
|
514 return buffer; |
|
515 } |
|
516 |
|
517 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
518 |
|
519 |
|
520 // End of File |