|
1 /* |
|
2 * Copyright (c) 2009 Aricent and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * Aricent - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of member functions of H264 encoder plugin class - |
|
16 * CAriH264encHwDeviceImpl. |
|
17 * |
|
18 */ |
|
19 |
|
20 // System Includes |
|
21 #include <e32base.h> |
|
22 #include <avc.h> |
|
23 #include <e32math.h> |
|
24 |
|
25 // User Includes |
|
26 #include "arih264enchwdeviceimpl.h" |
|
27 #include "arih264hwdeviceconstants.h" |
|
28 #include "arih264encwrapper.h" |
|
29 |
|
30 |
|
31 |
|
32 // MACRO DEFINITIONS - start |
|
33 |
|
34 // Uncomment this flag to enable instant rate calculations on-the-fly in urel |
|
35 // builds. In UDEB it is enabled automatically |
|
36 // By default it is commented |
|
37 //#define CALCINSTANTBITRATE |
|
38 |
|
39 // Uncomment to print additional debug information retrieved from |
|
40 // core encoder |
|
41 //#define DEBUG_INFO |
|
42 |
|
43 // MACRO DEFINITIONS - end |
|
44 |
|
45 //---------------------------------------------------------------------------- |
|
46 // Maps the num/denom from the MDF to the aspect_ratio_idc value supported |
|
47 //---------------------------------------------------------------------------- |
|
48 // |
|
49 TInt32 MapAspectRatio( TUint32 aNumerator, TUint32 aDenominator ) |
|
50 { |
|
51 PRINT_ENTRY; |
|
52 TInt32 aspectratio = -1; |
|
53 switch ( aDenominator ) |
|
54 { |
|
55 case 1: |
|
56 if ( aNumerator == 1 ) |
|
57 { |
|
58 aspectratio = 1; |
|
59 } |
|
60 break; |
|
61 case 11: |
|
62 switch ( aNumerator ) |
|
63 { |
|
64 case 12: |
|
65 aspectratio = 2; |
|
66 break; |
|
67 case 10: |
|
68 aspectratio = 3; |
|
69 break; |
|
70 case 16: |
|
71 aspectratio = 4; |
|
72 break; |
|
73 case 24: |
|
74 aspectratio = 6; |
|
75 break; |
|
76 case 20: |
|
77 aspectratio = 7; |
|
78 break; |
|
79 case 32: |
|
80 aspectratio = 8; |
|
81 break; |
|
82 case 18: |
|
83 aspectratio = 10; |
|
84 break; |
|
85 case 15: |
|
86 aspectratio = 11; |
|
87 break; |
|
88 default: |
|
89 break; |
|
90 } |
|
91 break; |
|
92 case 33: |
|
93 switch ( aNumerator ) |
|
94 { |
|
95 case 40: |
|
96 aspectratio = 5; |
|
97 break; |
|
98 case 80: |
|
99 aspectratio = 9; |
|
100 break; |
|
101 case 64: |
|
102 aspectratio = 12; |
|
103 break; |
|
104 default: |
|
105 break; |
|
106 } |
|
107 break; |
|
108 case 99: |
|
109 if ( aNumerator == 160 ) |
|
110 { |
|
111 aspectratio = 13; |
|
112 } |
|
113 |
|
114 break; |
|
115 default: |
|
116 break; |
|
117 } |
|
118 PRINT_EXIT; |
|
119 return aspectratio; |
|
120 } |
|
121 |
|
122 //---------------------------------------------------------------------------- |
|
123 // Two phase constructor for an object of CAriH264encHwDeviceImpl |
|
124 //---------------------------------------------------------------------------- |
|
125 // |
|
126 CAriH264encHwDeviceImpl* CAriH264encHwDeviceImpl::NewL() |
|
127 { |
|
128 PRINT_ENTRY; |
|
129 CAriH264encHwDeviceImpl* self = new ( ELeave ) CAriH264encHwDeviceImpl(); |
|
130 CleanupStack::PushL( self ); |
|
131 self->ConstructL(); |
|
132 CleanupStack::Pop( self ); |
|
133 PRINT_EXIT; |
|
134 return self; |
|
135 } |
|
136 |
|
137 //---------------------------------------------------------------------------- |
|
138 // Default constructor |
|
139 //---------------------------------------------------------------------------- |
|
140 // |
|
141 CAriH264encHwDeviceImpl::CAriH264encHwDeviceImpl() |
|
142 :iMMFDevVideoRecordProxy( NULL ), |
|
143 iInputDevice ( NULL ), |
|
144 iClockSource ( NULL ), |
|
145 iInputBufReturnToPreProc( EFalse ), |
|
146 iPeriodicTimer ( NULL ), |
|
147 iClockTimeWhenPaused( 0 ), |
|
148 //100 milli seconds |
|
149 iPollingInterval(TTimeIntervalMicroSeconds32( KPOLLINGINTERVAL ) ), |
|
150 iCodec( NULL ), |
|
151 iEngine( NULL ), |
|
152 iOutputBuffers( NULL ), |
|
153 iOutputBufferSize( 0 ), |
|
154 iPauseOffset( 0 ), |
|
155 iTotalTime( 0 ), |
|
156 iLastEncodedPictureTimestamp( 0 ), |
|
157 iPictureLoss( EFalse ), |
|
158 iInputEndCalled( EFalse ), |
|
159 iFrozen( EFalse ), |
|
160 iTotalLengthFilledSoFarInPacketMode( 0 ), |
|
161 iTotalOutputBufferLengthInPacketMode( 0 ), |
|
162 iPacketOffSetCurrentPosition( NULL ), |
|
163 iPacketOffSetAndLengthInfoBuffers( NULL ), |
|
164 iInternalOutputBuffers( NULL ), |
|
165 iNumOfBuffersAtClientInPacketModeNeedReAllocation( 0 ), |
|
166 iPacketsPending( EFalse ), |
|
167 iNumOfOutBuffersAvailableInPacketModeChange( 0 ), |
|
168 iNumofBuffersPendingFromClientInChangeToPacketMode( 0 ), |
|
169 iNumOfOutBuffersBeforeChangeToPacketMode( 0 ), |
|
170 iCodedBufferForPacketModeChange( NULL ), |
|
171 iSegmentBuffers( NULL ), |
|
172 iIsConfigDataFilledInFirstOutputBuffer( EFalse ), |
|
173 iIsSliceEnabledInCodedPicture( EFalse ), |
|
174 iNoOfOutputFramesPerSec( 0 ), |
|
175 iSizePerFrame( 0 ), |
|
176 iEncStateMac( NULL ) |
|
177 { |
|
178 PRINT_ENTRY; |
|
179 |
|
180 iSupportedDataUnitTypes = EDuCodedPicture | EDuVideoSegment; |
|
181 |
|
182 iSupportedDataUnitEncapsulations = EDuElementaryStream |
|
183 | EDuGenericPayload; |
|
184 |
|
185 // Default values for Init params - full range |
|
186 TUncompressedVideoFormat inputFormat; |
|
187 inputFormat.iDataFormat = EYuvRawData; |
|
188 inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range1; |
|
189 inputFormat.iYuvFormat.iPattern = EYuv420Chroma1; |
|
190 inputFormat.iYuvFormat.iDataLayout = EYuvDataPlanar; |
|
191 inputFormat.iYuvFormat.iYuv2RgbMatrix = NULL; |
|
192 inputFormat.iYuvFormat.iRgb2YuvMatrix = NULL; |
|
193 inputFormat.iYuvFormat.iAspectRatioNum = 1; |
|
194 inputFormat.iYuvFormat.iAspectRatioDenom = 1; |
|
195 |
|
196 iH264EncInitParams.iInputFormat = inputFormat; |
|
197 |
|
198 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_UNKNOWN; |
|
199 |
|
200 iH264EncInitParams.iAfterInitialize = 0; |
|
201 |
|
202 iH264EncInitParams.iOutputFormat = EH264; |
|
203 |
|
204 iH264EncInitParams.iMinNumOutputBuffers |
|
205 = KH264ENCIMPL_MAXNUM_OUTPUTBUFFERS; |
|
206 |
|
207 iH264EncInitParams.iMaxCodedSegmentSize |
|
208 = KH264ENCIMPL_DEFAULT_SEGMENTSIZE; |
|
209 |
|
210 iH264EncInitParams.iMaxPictureRate = KH264ENCIMPL_DEFAULT_PICTURERATE; |
|
211 |
|
212 // initialize picture counters |
|
213 iPictureCounters.iPicturesSkippedBufferOverflow = 0; |
|
214 iPictureCounters.iPicturesSkippedProcPower = 0; |
|
215 iPictureCounters.iPicturesSkippedRateControl = 0; |
|
216 iPictureCounters.iPicturesProcessed = 0; |
|
217 iPictureCounters.iInputPictures = 0; |
|
218 |
|
219 // default packet mode is off |
|
220 iH264EncInitParams.iDataEncapsulation = EDuElementaryStream; |
|
221 |
|
222 iH264EncInitParams.iDataUnitType = EDuCodedPicture; |
|
223 |
|
224 iH264EncInitParams.iBitRate = KH264ENCIMPL_DEFAULT_BITRATE; |
|
225 iH264EncInitParams.iTargetPictureRate = KH264ENCIMPL_DEFAULT_PICTURERATE; |
|
226 iH264EncInitParams.iRandomAccessRate |
|
227 = KH264ENCIMPL_DEFAULT_RANDOMACCESSRATE; |
|
228 |
|
229 PRINT_EXIT; |
|
230 |
|
231 } |
|
232 |
|
233 //---------------------------------------------------------------------------- |
|
234 // Destructor |
|
235 //---------------------------------------------------------------------------- |
|
236 // |
|
237 CAriH264encHwDeviceImpl::~CAriH264encHwDeviceImpl() |
|
238 { |
|
239 PRINT_ENTRY; |
|
240 PRINT_MSG( LEVEL_LOW, ( "this is %x", this ) ); |
|
241 |
|
242 iSupportedInputFormats.Close(); |
|
243 |
|
244 iLevels.Close(); |
|
245 |
|
246 //allocated formats should be deleted before closing |
|
247 while ( iSupportedOutputFormats.Count() > 0 ) |
|
248 { |
|
249 CCompressedVideoFormat* lCompFormat = iSupportedOutputFormats[0]; |
|
250 iSupportedOutputFormats.Remove( 0 ); |
|
251 delete lCompFormat; |
|
252 } |
|
253 |
|
254 iSupportedOutputFormats.Close(); |
|
255 |
|
256 // Stop processing |
|
257 if( !iEncStateMac->IsStopped() && ( !iEncStateMac->IsInDeadState() ) ) |
|
258 { |
|
259 if( iEncStateMac->IsInitialized() ) |
|
260 { |
|
261 Stop(); |
|
262 } |
|
263 } |
|
264 |
|
265 if( iEngine ) |
|
266 { |
|
267 iEngine->Reset(); |
|
268 delete iEngine; |
|
269 iEngine = NULL; |
|
270 } |
|
271 |
|
272 if( iCodec ) |
|
273 { |
|
274 delete iCodec; |
|
275 iCodec = NULL; |
|
276 } |
|
277 |
|
278 //delete output buffers |
|
279 iOutputFreeBufferQueue.Reset(); |
|
280 |
|
281 if( iOutputBuffers ) |
|
282 { |
|
283 if( iNumOfOutBuffersBeforeChangeToPacketMode ) |
|
284 { |
|
285 for ( TInt i = 0; i < iNumOfOutBuffersBeforeChangeToPacketMode |
|
286 ; i++ ) |
|
287 { |
|
288 if ( iOutputBuffers[i].iData.Ptr() ) |
|
289 { |
|
290 delete ( TUint8* )iOutputBuffers[i].iData.Ptr(); |
|
291 } |
|
292 } |
|
293 } |
|
294 else |
|
295 { |
|
296 for ( TInt i = 0; i < iH264EncInitParams.iMinNumOutputBuffers; |
|
297 i++ ) |
|
298 { |
|
299 if ( iOutputBuffers[i].iData.Ptr() ) |
|
300 { |
|
301 delete ( TUint8* )iOutputBuffers[i].iData.Ptr(); |
|
302 } |
|
303 } |
|
304 } |
|
305 delete []iOutputBuffers; |
|
306 } |
|
307 |
|
308 delete iPeriodicTimer; |
|
309 iPeriodicTimer = NULL; |
|
310 |
|
311 if ( iPacketOffSetAndLengthInfoBuffers ) |
|
312 { |
|
313 for( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
314 { |
|
315 delete [] ( TUint8* )iPacketOffSetAndLengthInfoBuffers[i]; |
|
316 } |
|
317 delete []( TUint* )iPacketOffSetAndLengthInfoBuffers; |
|
318 } |
|
319 |
|
320 //delete temp output buffers |
|
321 iInternalOutputBufferQueue.Reset(); |
|
322 |
|
323 if( iInternalOutputBuffers ) |
|
324 { |
|
325 for ( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
326 { |
|
327 if ( iInternalOutputBuffers[i].iData.Ptr() ) |
|
328 { |
|
329 delete ( TUint8* )iInternalOutputBuffers[i].iData.Ptr(); |
|
330 } |
|
331 } |
|
332 delete []iInternalOutputBuffers; |
|
333 } |
|
334 |
|
335 if ( iCodedBufferForPacketModeChange ) |
|
336 { |
|
337 if ( iCodedBufferForPacketModeChange->iData.Ptr() ) |
|
338 { |
|
339 delete iCodedBufferForPacketModeChange->iData.Ptr(); |
|
340 } |
|
341 |
|
342 delete iCodedBufferForPacketModeChange; |
|
343 } |
|
344 |
|
345 iFreeBufferQueueForPacketOffsetInfo.Reset(); |
|
346 iFilledBufferQueueForPacketOffsetInfo.Reset(); |
|
347 |
|
348 //delete the segment buffers |
|
349 if( iSegmentBuffers ) |
|
350 { |
|
351 for ( TInt i = 0; i < iH264EncInitParams.iMinNumOutputBuffers; i++ ) |
|
352 { |
|
353 if ( iSegmentBuffers[i].iData.Ptr() ) |
|
354 { |
|
355 delete ( TUint8* )iSegmentBuffers[i].iData.Ptr(); |
|
356 } |
|
357 } |
|
358 delete []iSegmentBuffers; |
|
359 } |
|
360 |
|
361 if ( iConfigData ) |
|
362 { |
|
363 delete iConfigData; |
|
364 iConfigData = NULL; |
|
365 } |
|
366 |
|
367 if ( iEncStateMac ) |
|
368 { |
|
369 delete iEncStateMac; |
|
370 iEncStateMac = NULL; |
|
371 } |
|
372 PRINT_EXIT; |
|
373 } |
|
374 |
|
375 //---------------------------------------------------------------------------- |
|
376 // Custom Interface supported by the HwDevice plugin |
|
377 //---------------------------------------------------------------------------- |
|
378 // |
|
379 TAny* CAriH264encHwDeviceImpl::CustomInterface( TUid aInterface ) |
|
380 { |
|
381 PRINT_ENTRY; |
|
382 if( aInterface == KH324AnnexKDefinedEncoderConfigDataCIUid ) |
|
383 { |
|
384 PRINT_EXIT; |
|
385 return ( ( MH324AnnexKDefinedEncoderConfigDataCI* ) this ); |
|
386 } |
|
387 else |
|
388 { |
|
389 PRINT_EXIT; |
|
390 return NULL; |
|
391 } |
|
392 } |
|
393 |
|
394 //---------------------------------------------------------------------------- |
|
395 // Returns information about this Encoder HW Device |
|
396 //---------------------------------------------------------------------------- |
|
397 // |
|
398 CVideoEncoderInfo* CAriH264encHwDeviceImpl::VideoEncoderInfoLC() |
|
399 { |
|
400 PRINT_ENTRY; |
|
401 |
|
402 TSize maxPictureSize = TSize( KH264ENCIMPL_SDTV_WIDTH, |
|
403 KH264ENCIMPL_SDTV_HEIGHT_PAL ); |
|
404 |
|
405 TUint32 maxBitRate = KMAXSUPPBITRATE; |
|
406 RArray<TPictureRateAndSize> maxPictureRatesAndSizes; |
|
407 CleanupClosePushL( maxPictureRatesAndSizes ); |
|
408 |
|
409 TPictureRateAndSize pictureRateAndSize; |
|
410 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
411 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_QCIF_WIDTH, |
|
412 KH264ENCIMPL_QCIF_HEIGHT ); |
|
413 |
|
414 TInt error = KErrNone; |
|
415 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
416 |
|
417 if( error != KErrNone ) |
|
418 { |
|
419 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
420 User::Leave( error ); |
|
421 } |
|
422 |
|
423 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
424 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_VGA_WIDTH, |
|
425 KH264ENCIMPL_VGA_HEIGHT ); |
|
426 |
|
427 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
428 if( error != KErrNone ) |
|
429 { |
|
430 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
431 User::Leave( error ); |
|
432 } |
|
433 |
|
434 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
435 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_CIF_WIDTH, |
|
436 KH264ENCIMPL_CIF_HEIGHT ); |
|
437 |
|
438 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
439 if( error != KErrNone ) |
|
440 { |
|
441 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
442 User::Leave( error ); |
|
443 } |
|
444 |
|
445 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
446 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_SQCIF_WIDTH, |
|
447 KH264ENCIMPL_SQCIF_HEIGHT ); |
|
448 |
|
449 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
450 if( error != KErrNone ) |
|
451 { |
|
452 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
453 User::Leave( error ); |
|
454 } |
|
455 |
|
456 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
457 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_QVGA_WIDTH, |
|
458 KH264ENCIMPL_QVGA_HEIGHT ); |
|
459 |
|
460 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
461 if( error != KErrNone ) |
|
462 { |
|
463 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
464 User::Leave( error ); |
|
465 } |
|
466 |
|
467 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
468 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_SDTV_WIDTH, |
|
469 KH264ENCIMPL_HALFSDTV_HEIGHT_NTSC); |
|
470 |
|
471 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
472 |
|
473 if( error != KErrNone ) |
|
474 { |
|
475 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
476 User::Leave( error ); |
|
477 } |
|
478 |
|
479 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
480 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_SDTV_WIDTH, |
|
481 KH264ENCIMPL_HALFSDTV_HEIGHT_PAL ); |
|
482 |
|
483 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
484 |
|
485 if( error != KErrNone ) |
|
486 { |
|
487 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
488 User::Leave( error ); |
|
489 } |
|
490 |
|
491 pictureRateAndSize.iPictureRate = KPictureRate30; |
|
492 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_SDTV_WIDTH, |
|
493 KH264ENCIMPL_SDTV_HEIGHT_NTSC ); |
|
494 |
|
495 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
496 |
|
497 if( error != KErrNone ) |
|
498 { |
|
499 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
500 User::Leave( error ); |
|
501 } |
|
502 |
|
503 pictureRateAndSize.iPictureRate = KH264ENCIMPL_PICTURERATE_25; |
|
504 pictureRateAndSize.iPictureSize = TSize( KH264ENCIMPL_SDTV_WIDTH, |
|
505 KH264ENCIMPL_SDTV_HEIGHT_PAL ); |
|
506 |
|
507 error = maxPictureRatesAndSizes.Append( pictureRateAndSize ); |
|
508 |
|
509 if( error != KErrNone ) |
|
510 { |
|
511 PRINT_ERR( "Error while appending maximum picture rate and size" ); |
|
512 User::Leave( error ); |
|
513 } |
|
514 |
|
515 TUint32 supportedPictureOptions = TVideoPicture::ETimestamp | |
|
516 TVideoPicture::EReqInstantRefresh; |
|
517 |
|
518 TUint32 supportedDataUnitEncapsulations = EDuElementaryStream | |
|
519 EDuGenericPayload; |
|
520 |
|
521 TUint32 supportedDataUnitTypes = EDuCodedPicture | |
|
522 EDuVideoSegment; |
|
523 |
|
524 CVideoEncoderInfo* lVideoEncoderInfo = CVideoEncoderInfo::NewL( TUid:: |
|
525 Uid( KUidH264EncoderHwDeviceImplUid ), |
|
526 KH264EncManufacturer, |
|
527 KH264EncIdentifier, |
|
528 TVersion( KH264ENCIMPL_MAJOR_VERSION, |
|
529 KH264ENCIMPL_MINOR_VERSION, |
|
530 KH264ENCIMPL_BUILD_VERSION ), |
|
531 // Accelerated |
|
532 EFalse, |
|
533 // Enc doesnt support direct capture |
|
534 EFalse, |
|
535 iSupportedInputFormats.Array(), |
|
536 iSupportedOutputFormats.Array(), |
|
537 maxPictureSize, |
|
538 supportedDataUnitTypes, |
|
539 supportedDataUnitEncapsulations, |
|
540 // Max bitrate layers |
|
541 1, |
|
542 //aSupportsSupplementalEnhancementInfo |
|
543 EFalse, |
|
544 //aMaxUnequalErrorProtectionLevels |
|
545 1, |
|
546 maxBitRate, |
|
547 maxPictureRatesAndSizes.Array(), |
|
548 //aMaxInLayerScalabilitySteps |
|
549 1, |
|
550 supportedPictureOptions, |
|
551 //aSupportsPictureLoss |
|
552 ETrue, |
|
553 //aSupportsSliceLoss |
|
554 ETrue, |
|
555 //aCodingStandardSpecificInfo |
|
556 KNullDesC8, |
|
557 //aImplementationSpecificInfo |
|
558 KNullDesC8 ); |
|
559 |
|
560 CleanupStack::PopAndDestroy(); |
|
561 CleanupStack::PushL( lVideoEncoderInfo ); |
|
562 |
|
563 PRINT_EXIT; |
|
564 return lVideoEncoderInfo; |
|
565 } |
|
566 |
|
567 |
|
568 //---------------------------------------------------------------------------- |
|
569 // Sets the encoder output format |
|
570 //---------------------------------------------------------------------------- |
|
571 // |
|
572 void CAriH264encHwDeviceImpl::SetOutputFormatL( |
|
573 const CCompressedVideoFormat& aFormat, |
|
574 TVideoDataUnitType aDataUnitType, |
|
575 TVideoDataUnitEncapsulation aDataEncapsulation, |
|
576 TBool aSegmentationAllowed ) |
|
577 { |
|
578 PRINT_ENTRY; |
|
579 |
|
580 if( iEncStateMac->IsInitialized() ) |
|
581 { |
|
582 PRINT_ERR( "SetOutputFormatL () called before Initialize ()" ); |
|
583 User::Leave( KErrPermissionDenied ); |
|
584 } |
|
585 |
|
586 TInt error = KErrNotFound; |
|
587 |
|
588 TPtrC8 mimeType( aFormat.MimeType() ); |
|
589 |
|
590 // Check if format is supported else return KErrNotSupported |
|
591 for ( TInt i = 0; i < iSupportedOutputFormats.Count(); i++ ) |
|
592 { |
|
593 CCompressedVideoFormat* lFormat = iSupportedOutputFormats[i]; |
|
594 |
|
595 if( mimeType.CompareF( lFormat->MimeType() ) == 0 ) |
|
596 { |
|
597 iH264EncInitParams.iLevel = iLevels[i]; |
|
598 error = KErrNone; |
|
599 break; |
|
600 } |
|
601 } |
|
602 |
|
603 if( error == KErrNotFound ) |
|
604 { |
|
605 PRINT_ERR( "CAriH264encHwDeviceImpl::SetOutputFormatL() Leaving" |
|
606 " because of unsupported output mimetype" ); |
|
607 |
|
608 User::Leave( KErrNotSupported ); |
|
609 return; |
|
610 } |
|
611 |
|
612 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetOutputFormatL() " |
|
613 "level is set to %d", (TInt)iH264EncInitParams.iLevel ) ); |
|
614 |
|
615 if ( ( ( aDataUnitType != EDuCodedPicture ) && |
|
616 ( aDataUnitType != EDuVideoSegment ) ) || |
|
617 ( ( aDataEncapsulation != EDuElementaryStream ) && |
|
618 ( aDataEncapsulation != EDuGenericPayload ) ) || |
|
619 ( ( aSegmentationAllowed ) ) ) |
|
620 { |
|
621 PRINT_ERR( "CAriH264encHwDeviceImpl::SetOutputFormatL() Leaving" |
|
622 " because of unsupported data unit type or data unit" |
|
623 " encapsulation" ); |
|
624 User::Leave( KErrNotSupported ); |
|
625 } |
|
626 |
|
627 if( aDataUnitType == EDuCodedPicture ) |
|
628 { |
|
629 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetOutputFormatL() " |
|
630 "Packet mode is OFF" ) ); |
|
631 } |
|
632 else |
|
633 { |
|
634 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetOutputFormatL() " |
|
635 "Packet mode is ON" ) ); |
|
636 // must be calculated from and levels set by the client |
|
637 iH264EncInitParams.iMinNumOutputBuffers |
|
638 = KH264ENCIMPL_MAXNUM_SEGMENTBUFFERS; |
|
639 } |
|
640 |
|
641 iH264EncInitParams.iDataUnitType = aDataUnitType; |
|
642 iH264EncInitParams.iDataEncapsulation = aDataEncapsulation; |
|
643 iH264EncInitParams.iSegmentationAllowed = aSegmentationAllowed; |
|
644 iH264EncInitParams.iBeforeInitialize |= EEncOutputFormat; |
|
645 |
|
646 PRINT_EXIT; |
|
647 } |
|
648 |
|
649 //---------------------------------------------------------------------------- |
|
650 // Sets the pre-processor device that will write data to this encoder |
|
651 //---------------------------------------------------------------------------- |
|
652 // |
|
653 void CAriH264encHwDeviceImpl::SetInputDevice( |
|
654 CMMFVideoPreProcHwDevice* aDevice ) |
|
655 { |
|
656 PRINT_ENTRY; |
|
657 |
|
658 if( iEncStateMac->IsInitialized() ) |
|
659 { |
|
660 ClientFatalError ( KErrPermissionDenied ); |
|
661 return; |
|
662 } |
|
663 |
|
664 if( !aDevice ) |
|
665 { |
|
666 ClientFatalError ( KErrArgument ); |
|
667 return; |
|
668 } |
|
669 |
|
670 iInputDevice = aDevice; |
|
671 iH264EncInitParams.iBeforeInitialize |= EEncInputDevice; |
|
672 iInputBufReturnToPreProc = ETrue; |
|
673 |
|
674 PRINT_EXIT; |
|
675 } |
|
676 |
|
677 //---------------------------------------------------------------------------- |
|
678 // Sets the number of bit-rate scalability layers to use |
|
679 //---------------------------------------------------------------------------- |
|
680 // |
|
681 void CAriH264encHwDeviceImpl::SetNumBitrateLayersL( TUint aNumLayers ) |
|
682 { |
|
683 PRINT_ENTRY; |
|
684 |
|
685 if( iEncStateMac->IsInitialized() ) |
|
686 { |
|
687 PRINT_ERR( "SetNumBitrateLayersL () called before Initialize" |
|
688 "..leaving" ); |
|
689 User::Leave( KErrPermissionDenied ); |
|
690 } |
|
691 |
|
692 if( aNumLayers != 1 ) |
|
693 { |
|
694 PRINT_ERR( "Wrong value passed for aNumLayers... Leaving" ); |
|
695 User::Leave( KErrNotSupported ); |
|
696 } |
|
697 |
|
698 PRINT_EXIT; |
|
699 } |
|
700 |
|
701 //---------------------------------------------------------------------------- |
|
702 // Sets the scalability type for a bit-rate scalability layer. Currently not |
|
703 // supported. |
|
704 //---------------------------------------------------------------------------- |
|
705 // |
|
706 void CAriH264encHwDeviceImpl::SetScalabilityLayerTypeL( |
|
707 TUint /*aLayer*/, |
|
708 TScalabilityType /*aScalabilityType*/ ) |
|
709 { |
|
710 PRINT_ENTRY; |
|
711 |
|
712 if( iEncStateMac->IsInitialized() ) |
|
713 { |
|
714 PRINT_ERR( "SetScalabilityLayerTypeL() called before Initialize" |
|
715 "..leaving" ); |
|
716 User::Leave( KErrPermissionDenied ); |
|
717 } |
|
718 |
|
719 PRINT_ERR( "SetScalabilityLayerTypeL() not supported...Leaving with " |
|
720 "KErrNotSupported" ); |
|
721 User::Leave( KErrNotSupported ); |
|
722 |
|
723 PRINT_EXIT; |
|
724 } |
|
725 |
|
726 |
|
727 //---------------------------------------------------------------------------- |
|
728 // Sets the reference picture options to be used for all scalability layers |
|
729 //---------------------------------------------------------------------------- |
|
730 // |
|
731 void CAriH264encHwDeviceImpl::SetGlobalReferenceOptions( |
|
732 TUint aMaxReferencePictures, |
|
733 TUint aMaxPictureOrderDelay ) |
|
734 { |
|
735 PRINT_ENTRY; |
|
736 |
|
737 if( iEncStateMac->IsInitialized() ) |
|
738 { |
|
739 ClientFatalError( KErrPermissionDenied ); |
|
740 return; |
|
741 } |
|
742 |
|
743 if( aMaxPictureOrderDelay != 0 || aMaxReferencePictures |
|
744 > KH264ENCIMPL_MAXNUM_REFERENCEPICTURES ) |
|
745 { |
|
746 ClientFatalError( KErrNotSupported ); |
|
747 return; |
|
748 } |
|
749 |
|
750 iH264EncInitParams.iLayerReferenceOptions[0].iMaxReferencePictures |
|
751 = aMaxReferencePictures; |
|
752 |
|
753 iH264EncInitParams.iLayerReferenceOptions[0].iMaxPictureOrderDelay |
|
754 = aMaxPictureOrderDelay; |
|
755 |
|
756 iH264EncInitParams.iBeforeInitialize |= EEncGlobalRefOptions; |
|
757 |
|
758 PRINT_EXIT |
|
759 } |
|
760 |
|
761 //---------------------------------------------------------------------------- |
|
762 // Sets the reference picture options to be used for a single scalability |
|
763 // layer |
|
764 //---------------------------------------------------------------------------- |
|
765 // |
|
766 void CAriH264encHwDeviceImpl::SetLayerReferenceOptions( TUint /*aLayer*/, |
|
767 TUint /*aMaxReferencePictures*/, |
|
768 TUint /*aMaxPictureOrderDelay*/ ) |
|
769 { |
|
770 PRINT_ENTRY; |
|
771 |
|
772 if( iEncStateMac->IsInitialized() ) |
|
773 { |
|
774 ClientFatalError( KErrPermissionDenied ); |
|
775 return; |
|
776 } |
|
777 ClientFatalError( KErrNotSupported ); |
|
778 |
|
779 PRINT_EXIT; |
|
780 } |
|
781 |
|
782 ///--------------------------------------------------------------------------- |
|
783 // Sets encoder buffering options |
|
784 //---------------------------------------------------------------------------- |
|
785 // |
|
786 void CAriH264encHwDeviceImpl::SetBufferOptionsL( |
|
787 const TEncoderBufferOptions& aOptions ) |
|
788 { |
|
789 PRINT_ENTRY; |
|
790 |
|
791 if( iEncStateMac->IsInitialized() ) |
|
792 { |
|
793 PRINT_ERR( "SetBufferOptionsL () called before Initialize ()" ); |
|
794 User::Leave( KErrPermissionDenied ); |
|
795 } |
|
796 |
|
797 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
798 "iMaxPreEncoderBufferPictures = %d" , |
|
799 (TInt)aOptions.iMaxPreEncoderBufferPictures ) ); |
|
800 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
801 "iMaxOutputBufferSize = %d", |
|
802 ( TInt ) aOptions.iMaxOutputBufferSize ) ); |
|
803 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
804 "iMaxCodedPictureSize = %d" , |
|
805 ( TInt )aOptions.iMaxCodedPictureSize ) ); |
|
806 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
807 "iHrdVbvSpec = %x", ( TInt ) aOptions.iHrdVbvSpec ) ); |
|
808 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
809 "iMinNumOutputBuffers = %d" , |
|
810 ( TInt ) aOptions.iMinNumOutputBuffers ) ); |
|
811 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetBufferOptionsL() " |
|
812 "iMaxCodedSegmentSize = %d" , |
|
813 ( TInt ) aOptions.iMaxCodedSegmentSize ) ); |
|
814 |
|
815 if( ( aOptions.iMaxPreEncoderBufferPictures == 0 ) || |
|
816 ( aOptions.iMaxOutputBufferSize == 0 ) || |
|
817 ( aOptions.iMinNumOutputBuffers == 0 ) || |
|
818 ( aOptions.iHrdVbvSpec == EHrdVbv3GPP ) ) |
|
819 { |
|
820 PRINT_ERR( "SetBufferOptionsL () - incorrect parameter passed ..." |
|
821 "leaving with KErrNotSupported" ); |
|
822 User::Leave ( KErrNotSupported ); |
|
823 return; |
|
824 } |
|
825 |
|
826 if ( aOptions.iHrdVbvParams != KNullDesC8 ) |
|
827 { |
|
828 if ( aOptions.iHrdVbvSpec == EHrdVbvNone ) |
|
829 { |
|
830 PRINT_ERR( "SetBufferOptionsL () - incorrect HrdVbvParams or" |
|
831 "iHrdVbvSpec passed ...leaving with KErrNotSupported" ); |
|
832 User::Leave( KErrNotSupported ); |
|
833 return; |
|
834 } |
|
835 |
|
836 TPckgBuf <TAvcPictureHeader> params; |
|
837 params.Copy ( aOptions.iHrdVbvParams ); |
|
838 TUint size = sizeof( TAvcPictureHeader ); |
|
839 if ( size != aOptions.iHrdVbvParams.Length() ) |
|
840 { |
|
841 PRINT_ERR( "CAriH264encHwDeviceImpl::SetBufferOptionsL() -" |
|
842 "invalid structure passed for iHrdVbvParams" ); |
|
843 User::Leave( KErrArgument ); |
|
844 } |
|
845 |
|
846 // Perform the checks on the members of |
|
847 if( ( params().iBaselineProfileConstraintSet == ( TBool )EFalse ) || |
|
848 ( params().iMainProfileConstraintSet == ( TBool )ETrue ) || |
|
849 ( params().iExtendedProfileConstraintSet == ( TBool )ETrue ) || |
|
850 ( ( params().iPictureType ) & EAvcPictureTypeB ) || |
|
851 ( ( params().iPictureType ) & EAvcPictureTypeSI ) || |
|
852 ( ( params().iPictureType ) & EAvcPictureTypeSP ) || |
|
853 ( params().iLongTermPicture == ( TBool )ETrue ) || |
|
854 ( params().iFrame == ( TBool )EFalse ) || |
|
855 ( params().iQPY < 10 ) || |
|
856 ( params().iQPY > 51 ) ) |
|
857 { |
|
858 PRINT_ERR( "CAriH264encHwDeviceImpl ::SetBufferOptionsL Invalid " |
|
859 "data passed in TAVCHrdParams" ); |
|
860 User::Leave( KErrNotSupported ); |
|
861 return; |
|
862 } |
|
863 } |
|
864 |
|
865 iH264EncInitParams.iMaxPreEncoderBufferPictures |
|
866 = aOptions.iMaxPreEncoderBufferPictures; |
|
867 |
|
868 iH264EncInitParams.iMaxOutputBufferSize = aOptions.iMaxOutputBufferSize; |
|
869 iH264EncInitParams.iMaxCodedPictureSize = aOptions.iMaxCodedPictureSize; |
|
870 iH264EncInitParams.iMaxCodedSegmentSize = aOptions.iMaxCodedSegmentSize; |
|
871 iH264EncInitParams.iMinNumOutputBuffers = aOptions.iMinNumOutputBuffers; |
|
872 iH264EncInitParams.iBeforeInitialize |= EEncBufferOptions; |
|
873 |
|
874 PRINT_EXIT; |
|
875 } |
|
876 |
|
877 //---------------------------------------------------------------------------- |
|
878 // Sets the encoder output rectangle |
|
879 //---------------------------------------------------------------------------- |
|
880 // |
|
881 void CAriH264encHwDeviceImpl::SetOutputRectL( const TRect& aRect ) |
|
882 { |
|
883 PRINT_ENTRY; |
|
884 |
|
885 if( ( aRect.iTl.iX >= aRect.iBr.iX ) || |
|
886 ( aRect.iTl.iY >= aRect.iBr.iY ) ) |
|
887 { |
|
888 PRINT_ERR( " Invalid parameteres passed..Leaving " ); |
|
889 User::Leave ( KErrNotSupported ); |
|
890 return; |
|
891 } |
|
892 |
|
893 iH264EncInitParams.iOutputRect = aRect; |
|
894 iH264EncInitParams.iBeforeInitialize |= EEncOutputRectSize; |
|
895 |
|
896 PRINT_EXIT; |
|
897 } |
|
898 |
|
899 //---------------------------------------------------------------------------- |
|
900 // Sets whether bit errors or packets losses can be expected in the video |
|
901 // transmission |
|
902 //---------------------------------------------------------------------------- |
|
903 // |
|
904 void CAriH264encHwDeviceImpl::SetErrorsExpected( TBool aBitErrors, |
|
905 TBool aPacketLosses ) |
|
906 { |
|
907 PRINT_ENTRY; |
|
908 |
|
909 // This can bel called before and after initialize |
|
910 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetErrorsExpected()" |
|
911 " BitErrors is set to [ %d ]", aBitErrors ) ); |
|
912 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::SetErrorsExpected() " |
|
913 "iPacketLosses is set to [ %d ]", aPacketLosses ) ); |
|
914 |
|
915 if( iEncStateMac->IsInitialized() ) |
|
916 { |
|
917 iCurSetH264EncParams.iBitErrors = aBitErrors; |
|
918 iCurSetH264EncParams.iPacketLosses = aPacketLosses; |
|
919 iCurSetH264EncParams.iAfterInitialize |= EEncErrorsExpected; |
|
920 } |
|
921 else |
|
922 { |
|
923 iH264EncInitParams.iBitErrors = aBitErrors; |
|
924 iH264EncInitParams.iPacketLosses = aPacketLosses; |
|
925 iH264EncInitParams.iBeforeInitialize |= EEncErrorsExpected; |
|
926 } |
|
927 |
|
928 PRINT_EXIT; |
|
929 } |
|
930 |
|
931 |
|
932 //---------------------------------------------------------------------------- |
|
933 // Sets the minimum frequency (in time) for instantaneous random access points |
|
934 // in the bitstream |
|
935 //---------------------------------------------------------------------------- |
|
936 // |
|
937 void CAriH264encHwDeviceImpl::SetMinRandomAccessRate( TReal aRate ) |
|
938 { |
|
939 PRINT_ENTRY; |
|
940 |
|
941 if( iEncStateMac->IsInitialized() ) |
|
942 { |
|
943 // simply return no further action is taken |
|
944 if( aRate <= 0.0 ) |
|
945 { |
|
946 return; |
|
947 } |
|
948 iCurSetH264EncParams.iRandomAccessRate = aRate; |
|
949 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl" |
|
950 "::SetMinRandomAccessRate() iRandomAccessRate is %f" , |
|
951 ( TReal )iH264EncInitParams.iRandomAccessRate ) ); |
|
952 |
|
953 iCurSetH264EncParams.iAfterInitialize |= EEncRandomAccessRate; |
|
954 } |
|
955 else |
|
956 { |
|
957 if( aRate <= 0.0 ) |
|
958 { |
|
959 ClientFatalError ( KErrNotSupported ); |
|
960 return; |
|
961 } |
|
962 iH264EncInitParams.iRandomAccessRate = aRate; |
|
963 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl" |
|
964 "::SetMinRandomAccessRate() iRandomAccessRate is %f" , |
|
965 ( TReal )iH264EncInitParams.iRandomAccessRate ) ); |
|
966 |
|
967 iH264EncInitParams.iBeforeInitialize |= EEncRandomAccessRate; |
|
968 } |
|
969 |
|
970 PRINT_EXIT; |
|
971 } |
|
972 |
|
973 //---------------------------------------------------------------------------- |
|
974 // Sets coding-standard specific encoder options. |
|
975 //---------------------------------------------------------------------------- |
|
976 // |
|
977 void CAriH264encHwDeviceImpl::SetCodingStandardSpecificOptionsL( |
|
978 const TDesC8& aOptions ) |
|
979 { |
|
980 PRINT_ENTRY; |
|
981 |
|
982 if ( aOptions == KNullDesC8 ) |
|
983 { |
|
984 PRINT_ERR( "CAriH264encHwDeviceImpl" |
|
985 "::SetCodingStandardSpecificOptionsL() Leaving because Null " |
|
986 "Descriptor Passed" ); |
|
987 User::Leave( KErrArgument ); |
|
988 } |
|
989 |
|
990 // validate the parameters |
|
991 TPckgBuf<TAvcVideoMode> avcVideoMode; |
|
992 TUint size = sizeof( TAvcVideoMode ); |
|
993 if ( size != aOptions.Length() ) |
|
994 { |
|
995 PRINT_MSG( LEVEL_HIGH, ( "CAriH264encHwDeviceImpl" |
|
996 "::SetCodingStandardSpecificOptionsL() - invalid structure passed") ); |
|
997 User::Leave( KErrArgument ); |
|
998 } |
|
999 |
|
1000 // before init |
|
1001 if( !iEncStateMac->IsInitialized() ) |
|
1002 { |
|
1003 iH264EncInitParams.iCodingStandardSpecificOptions = avcVideoMode(); |
|
1004 iH264EncInitParams.iBeforeInitialize |
|
1005 |= EEncCodingStandardSpecificOptions; |
|
1006 } |
|
1007 avcVideoMode.Copy( aOptions ); |
|
1008 |
|
1009 if ( ( avcVideoMode().iAllowedPictureTypes & EAvcPictureTypeB ) || |
|
1010 ( avcVideoMode().iAllowedPictureTypes & EAvcPictureTypeSI ) || |
|
1011 ( avcVideoMode().iAllowedPictureTypes & EAvcPictureTypeSP ) || |
|
1012 ( avcVideoMode().iFlexibleMacroblockOrder ) || |
|
1013 ( avcVideoMode().iRedundantPictures ) || |
|
1014 ( avcVideoMode().iDataPartitioning ) || |
|
1015 ( !avcVideoMode().iFrameMBsOnly ) || |
|
1016 ( avcVideoMode().iMBAFFCoding ) || |
|
1017 ( avcVideoMode().iEntropyCodingCABAC ) || |
|
1018 ( avcVideoMode().iWeightedPPrediction ) || |
|
1019 ( avcVideoMode().iWeightedBipredicitonMode ) ) |
|
1020 { |
|
1021 PRINT_ERR( "CAriH264encHwDeviceImpl" |
|
1022 "::SetCodingStandardSpecificOptionsL() - leaving invalid data " |
|
1023 "passed for TAvcVideoMode" ); |
|
1024 User::Leave( KErrNotSupported ); |
|
1025 } |
|
1026 |
|
1027 PRINT_EXIT; |
|
1028 } |
|
1029 |
|
1030 //---------------------------------------------------------------------------- |
|
1031 // Sets coding-standard specific encoder options. |
|
1032 //---------------------------------------------------------------------------- |
|
1033 // |
|
1034 void CAriH264encHwDeviceImpl::SetImplementationSpecificEncoderOptionsL( |
|
1035 const TDesC8& /*aOptions*/) |
|
1036 { |
|
1037 PRINT_ENTRY; |
|
1038 |
|
1039 //This API can be called at any point of time |
|
1040 PRINT_ERR( "SetImplementationSpecificEncoderOptionsL () called before " |
|
1041 "Initialize ()" ); |
|
1042 User::Leave( KErrNotSupported ); |
|
1043 |
|
1044 PRINT_EXIT; |
|
1045 } |
|
1046 |
|
1047 //---------------------------------------------------------------------------- |
|
1048 // Returns coding-standard specific initialization output from the encoder |
|
1049 //---------------------------------------------------------------------------- |
|
1050 // |
|
1051 HBufC8* CAriH264encHwDeviceImpl::CodingStandardSpecificInitOutputLC() |
|
1052 { |
|
1053 PRINT_ENTRY; |
|
1054 |
|
1055 TUint configlength; |
|
1056 if( !iEncStateMac->IsInitialized() ) |
|
1057 { |
|
1058 PRINT_ERR( "CodingStandardSpecificInitOutputLC () called before " |
|
1059 "Initialize ()" ); |
|
1060 User::Leave( KErrNotReady ); |
|
1061 } |
|
1062 TUint err = iCodec->GetParam( CONTROL_CMD_GET_CONFIG_LENGTH, |
|
1063 &configlength ); |
|
1064 if ( err ) |
|
1065 { |
|
1066 PRINT_ERR("GetParam failure"); |
|
1067 User::Leave( err ); |
|
1068 } |
|
1069 |
|
1070 iConfigData = HBufC8::NewL( configlength ); |
|
1071 err = iCodec->GetParam( CONTROL_CMD_GET_CONFIG_HEADER, iConfigData ); |
|
1072 |
|
1073 if ( err ) |
|
1074 { |
|
1075 PRINT_ERR("GetParam failure"); |
|
1076 User::Leave( err ); |
|
1077 } |
|
1078 |
|
1079 PRINT_EXIT; |
|
1080 return iConfigData; |
|
1081 } |
|
1082 |
|
1083 //---------------------------------------------------------------------------- |
|
1084 // Returns coding-standard specific initialization output from the encoder |
|
1085 //---------------------------------------------------------------------------- |
|
1086 // |
|
1087 HBufC8* CAriH264encHwDeviceImpl::ImplementationSpecificInitOutputLC() |
|
1088 { |
|
1089 PRINT_ENTRY; |
|
1090 |
|
1091 if( !iEncStateMac->IsInitialized() ) |
|
1092 { |
|
1093 PRINT_ERR( "ImplementationSpecificInitOutputLC () called before " |
|
1094 "Initialize ()" ); |
|
1095 User::Leave( KErrNotReady ); |
|
1096 return NULL; |
|
1097 } |
|
1098 |
|
1099 PRINT_ERR( "ImplementationSpecificInitOutputLC () not supported...leaving" |
|
1100 "with KErrNotSupported" ); |
|
1101 User::Leave( KErrNotSupported ); |
|
1102 |
|
1103 PRINT_EXIT; |
|
1104 return NULL; |
|
1105 } |
|
1106 |
|
1107 //---------------------------------------------------------------------------- |
|
1108 // Sets the number of unequal error protection levels |
|
1109 //---------------------------------------------------------------------------- |
|
1110 // |
|
1111 void CAriH264encHwDeviceImpl::SetErrorProtectionLevelsL(TUint /*aNumLevels*/, |
|
1112 TBool /*aSeparateBuffers*/) |
|
1113 { |
|
1114 PRINT_ENTRY; |
|
1115 |
|
1116 if( !iEncStateMac->IsInitialized() ) |
|
1117 { |
|
1118 PRINT_ERR( "SetErrorProtectionLevelsL () called before " |
|
1119 "Initialize ()" ); |
|
1120 User::Leave( KErrNotReady ); |
|
1121 } |
|
1122 |
|
1123 PRINT_ERR( "SetErrorProtectionLevelsL() not supported...leaving" |
|
1124 "with KErrNotSupported" ); |
|
1125 User::Leave( KErrNotSupported ); |
|
1126 |
|
1127 PRINT_EXIT; |
|
1128 } |
|
1129 |
|
1130 //---------------------------------------------------------------------------- |
|
1131 // Sets the number of unequal error protection levels |
|
1132 //---------------------------------------------------------------------------- |
|
1133 // |
|
1134 void CAriH264encHwDeviceImpl::SetErrorProtectionLevelL( TUint /*aLevel*/, |
|
1135 TUint /*aBitrate*/, |
|
1136 TUint /*aStrength*/ ) |
|
1137 { |
|
1138 PRINT_ENTRY; |
|
1139 |
|
1140 if( !iEncStateMac->IsInitialized() ) |
|
1141 { |
|
1142 PRINT_ERR( "SetErrorProtectionLevelsL () called before " |
|
1143 "Initialize ()" ); |
|
1144 User::Leave( KErrNotReady ); |
|
1145 } |
|
1146 |
|
1147 PRINT_ERR( "SetErrorProtectionLevelsL() not supported...leaving" |
|
1148 "with KErrNotSupported" ); |
|
1149 User::Leave( KErrNotSupported ); |
|
1150 |
|
1151 PRINT_EXIT; |
|
1152 } |
|
1153 |
|
1154 //---------------------------------------------------------------------------- |
|
1155 // Sets the expected or prevailing channel conditions for an unequal |
|
1156 // error protection level, in terms of expected packet loss rate |
|
1157 //---------------------------------------------------------------------------- |
|
1158 // |
|
1159 void CAriH264encHwDeviceImpl::SetChannelPacketLossRate( TUint /*aLevel*/, |
|
1160 TReal /*aLossRate*/, |
|
1161 TTimeIntervalMicroSeconds32 /*aLossBurstLength*/ ) |
|
1162 { |
|
1163 PRINT_ENTRY; |
|
1164 |
|
1165 if ( !iEncStateMac->IsInitialized() ) |
|
1166 { |
|
1167 ClientFatalError( KErrNotReady ); |
|
1168 return; |
|
1169 } |
|
1170 |
|
1171 //packet mode is already enabled |
|
1172 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
1173 { |
|
1174 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl" |
|
1175 " ::SetChannelPacketLossRate()- already in packet mode returning" ) ); |
|
1176 return; |
|
1177 } |
|
1178 |
|
1179 // Flush the output buffers |
|
1180 iEngine->ReturnOutputBuffers(); |
|
1181 |
|
1182 // output buffers status |
|
1183 iNumOfOutBuffersAvailableInPacketModeChange |
|
1184 = iOutputFreeBufferQueue.Count(); |
|
1185 |
|
1186 iNumofBuffersPendingFromClientInChangeToPacketMode |
|
1187 = iH264EncInitParams.iMinNumOutputBuffers |
|
1188 - iOutputFreeBufferQueue.Count(); |
|
1189 |
|
1190 iNumOfOutBuffersBeforeChangeToPacketMode |
|
1191 = iH264EncInitParams.iMinNumOutputBuffers; |
|
1192 |
|
1193 TInt error = KErrNone; |
|
1194 // some buffers are available |
|
1195 if ( iNumOfOutBuffersAvailableInPacketModeChange ) |
|
1196 { |
|
1197 while( iOutputFreeBufferQueue.Count() ) |
|
1198 { |
|
1199 // add to engine |
|
1200 iEngine->AddOutput( iOutputFreeBufferQueue[0] ); |
|
1201 |
|
1202 // remove this buffer |
|
1203 iOutputFreeBufferQueue.Remove( 0 ); |
|
1204 } |
|
1205 } |
|
1206 else |
|
1207 { |
|
1208 // create one buffer which can hold one encoded picture |
|
1209 TRAP( error, CreateCodedBufferForModeChangeL() ); |
|
1210 if( error != KErrNone ) |
|
1211 { |
|
1212 ClientFatalError( error ); |
|
1213 return; |
|
1214 } |
|
1215 } |
|
1216 |
|
1217 iH264EncInitParams.iMaxCodedSegmentSize |
|
1218 = KH264ENCIMPL_DEFAULT_SEGMENTSIZE; |
|
1219 |
|
1220 // Get the maximum output buffer size for the encoder |
|
1221 TUint maxOutputBufferSize =0; |
|
1222 error = iCodec->GetParam( CONTROL_CMD_GET_MAX_FRAME_SIZE, |
|
1223 &maxOutputBufferSize ); |
|
1224 if ( error != KErrNone ) |
|
1225 { |
|
1226 ClientFatalError( error ); |
|
1227 return; |
|
1228 } |
|
1229 |
|
1230 iH264EncInitParams.iMinNumOutputBuffers = ( maxOutputBufferSize / |
|
1231 iH264EncInitParams.iMaxCodedSegmentSize ) * |
|
1232 KH264ENCIMPL_MAXNUM_OUTPUTBUFFERS; |
|
1233 |
|
1234 TRAP( error, CreateSegmentOutputBuffersL ( |
|
1235 iH264EncInitParams.iMinNumOutputBuffers, |
|
1236 iH264EncInitParams.iMaxCodedSegmentSize ) ) |
|
1237 if( error != KErrNone ) |
|
1238 { |
|
1239 ClientFatalError( error ); |
|
1240 return; |
|
1241 } |
|
1242 |
|
1243 error = iCodec->GetParam( CONTROL_CMD_GET_MAX_NUM_PACKETS, |
|
1244 &iMaxNumOfPackets ); |
|
1245 if( error != KErrNone ) |
|
1246 { |
|
1247 ClientFatalError( error ); |
|
1248 return; |
|
1249 } |
|
1250 |
|
1251 TRAP( error, CreatePacketOffsetLengthInfoBuffersL( iMaxNumOfPackets ) ); |
|
1252 if( error != KErrNone ) |
|
1253 { |
|
1254 ClientFatalError( error ); |
|
1255 return; |
|
1256 } |
|
1257 |
|
1258 TBool yesorno = ETrue; |
|
1259 error = iCodec->SetParam( CONTROL_CMD_SET_PACKET_MODE, &yesorno ); |
|
1260 if( error != KErrNone ) |
|
1261 { |
|
1262 ClientFatalError( error ); |
|
1263 return; |
|
1264 } |
|
1265 |
|
1266 // change output mode to videosegment |
|
1267 iH264EncInitParams.iDataUnitType = EDuVideoSegment; |
|
1268 |
|
1269 PRINT_EXIT; |
|
1270 } |
|
1271 |
|
1272 //---------------------------------------------------------------------------- |
|
1273 // Sets the expected or prevailing channel conditions for an unequal error |
|
1274 // protection level, in terms of expected bit error rate |
|
1275 //---------------------------------------------------------------------------- |
|
1276 // |
|
1277 void CAriH264encHwDeviceImpl::SetChannelBitErrorRate( TUint /*aLevel*/, |
|
1278 TReal aErrorRate, TReal /*aStdDeviation*/ ) |
|
1279 { |
|
1280 PRINT_ENTRY; |
|
1281 |
|
1282 if( !iEncStateMac->IsInitialized() ) |
|
1283 { |
|
1284 ClientFatalError( KErrNotReady ); |
|
1285 return; |
|
1286 } |
|
1287 |
|
1288 // ignore the negative and 0 error rate values - #AANV-6QSC9N |
|
1289 if ( aErrorRate < 0.0 ) |
|
1290 { |
|
1291 return; |
|
1292 } |
|
1293 |
|
1294 TReal* bitErrorRate = NULL; |
|
1295 TRAPD( error , bitErrorRate = new( ELeave )TReal ); |
|
1296 |
|
1297 if ( error != KErrNone ) |
|
1298 { |
|
1299 ClientFatalError( error ); |
|
1300 return; |
|
1301 } |
|
1302 |
|
1303 *bitErrorRate = aErrorRate; |
|
1304 TRAP( error, iEngine->AddCommandL( CBaseEngine::EHighPriority, |
|
1305 CONTROL_CMD_SET_CHANNEL_BIT_ERROR_RATE, bitErrorRate ) ); |
|
1306 if( error != KErrNone ) |
|
1307 { |
|
1308 delete bitErrorRate; |
|
1309 ClientFatalError( error ); |
|
1310 return; |
|
1311 } |
|
1312 |
|
1313 PRINT_EXIT; |
|
1314 } |
|
1315 |
|
1316 //---------------------------------------------------------------------------- |
|
1317 // Sets the target size of each coded video segment |
|
1318 //---------------------------------------------------------------------------- |
|
1319 // |
|
1320 void CAriH264encHwDeviceImpl::SetSegmentTargetSize( TUint aLayer, |
|
1321 TUint aSizeBytes, |
|
1322 TUint /*aSizeMacroblocks*/ ) |
|
1323 { |
|
1324 PRINT_ENTRY; |
|
1325 |
|
1326 if( !iEncStateMac->IsInitialized() ) |
|
1327 { |
|
1328 ClientFatalError( KErrNotReady ); |
|
1329 return; |
|
1330 } |
|
1331 |
|
1332 if ( iH264EncInitParams.iDataUnitType == EDuCodedPicture ) |
|
1333 { |
|
1334 if( aSizeBytes== 0 ) |
|
1335 { |
|
1336 if( iIsSliceEnabledInCodedPicture ) |
|
1337 { |
|
1338 iIsSliceEnabledInCodedPicture= EFalse; |
|
1339 TInt error = iCodec->SetParam( CONTROL_CMD_SET_FRAME_MODE, |
|
1340 NULL ); |
|
1341 if ( error != KErrNone ) |
|
1342 { |
|
1343 ClientFatalError( error ); |
|
1344 return; |
|
1345 } |
|
1346 } |
|
1347 return; |
|
1348 } |
|
1349 TUint calculatedSegmentSize = 0; |
|
1350 if( aSizeBytes <= KH264ENCIMPL_MIN_SLICESIZE ) |
|
1351 { |
|
1352 calculatedSegmentSize = KH264ENCIMPL_MIN_SLICESIZE; |
|
1353 } |
|
1354 else |
|
1355 { |
|
1356 if ( iH264EncInitParams.iMaxCodedSegmentSize |
|
1357 < iH264EncInitParams.iMaxCodedPictureSize ) |
|
1358 { |
|
1359 if ( aSizeBytes > iH264EncInitParams.iMaxCodedSegmentSize ) |
|
1360 { |
|
1361 calculatedSegmentSize |
|
1362 = iH264EncInitParams.iMaxCodedSegmentSize; |
|
1363 } |
|
1364 else |
|
1365 { |
|
1366 calculatedSegmentSize = aSizeBytes; |
|
1367 } |
|
1368 } |
|
1369 else |
|
1370 { |
|
1371 if ( aSizeBytes < iH264EncInitParams.iMaxCodedPictureSize ) |
|
1372 { |
|
1373 calculatedSegmentSize = aSizeBytes; |
|
1374 } |
|
1375 else |
|
1376 { |
|
1377 return; |
|
1378 } |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 if( calculatedSegmentSize < KH264ENCIMPL_MIN_SLICESIZE ) |
|
1383 { |
|
1384 calculatedSegmentSize = KH264ENCIMPL_MIN_SLICESIZE; |
|
1385 } |
|
1386 |
|
1387 TBool yesorno = EFalse; |
|
1388 TInt error = iCodec->SetParam( CONTROL_CMD_SET_PACKET_MODE, |
|
1389 &yesorno ); |
|
1390 |
|
1391 if( error != KErrNone ) |
|
1392 { |
|
1393 ClientFatalError( error ); |
|
1394 return; |
|
1395 } |
|
1396 // Set the target size on codec |
|
1397 error = iCodec->SetParam( CONTROL_CMD_SET_PACKET_SIZE, |
|
1398 &calculatedSegmentSize ); |
|
1399 |
|
1400 if ( error != KErrNone ) |
|
1401 { |
|
1402 ClientFatalError( error ); |
|
1403 return; |
|
1404 } |
|
1405 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
1406 "::calculatedSegmentSize() is %d" , |
|
1407 ( TInt )calculatedSegmentSize ) ); |
|
1408 |
|
1409 iH264EncInitParams.iMaxCodedSegmentSize = calculatedSegmentSize; |
|
1410 iIsSliceEnabledInCodedPicture = ETrue; |
|
1411 return; |
|
1412 |
|
1413 } |
|
1414 |
|
1415 if ( iH264EncInitParams.iDataUnitType != EDuVideoSegment ) |
|
1416 { |
|
1417 return; |
|
1418 } |
|
1419 |
|
1420 // aLayer should be zero since layered bit-rate scalability is not used. |
|
1421 if ( aLayer != 0 ) |
|
1422 { |
|
1423 return; |
|
1424 } |
|
1425 |
|
1426 TUint calculatedSegmentSize = 0; |
|
1427 // if value < 0 or > iMaxOutputBufferSize the adjust this value |
|
1428 if ( aSizeBytes < KH264ENCIMPL_MIN_SEGMENTSIZE ) |
|
1429 { |
|
1430 calculatedSegmentSize = KH264ENCIMPL_MIN_SEGMENTSIZE; |
|
1431 } |
|
1432 else |
|
1433 { |
|
1434 if ( iH264EncInitParams.iMaxOutputBufferSize |
|
1435 > KH264ENCIMPL_MAX_SEGMENTSIZE ) |
|
1436 { |
|
1437 if ( aSizeBytes < KH264ENCIMPL_MAX_SEGMENTSIZE ) |
|
1438 { |
|
1439 calculatedSegmentSize = aSizeBytes; |
|
1440 } |
|
1441 else |
|
1442 { |
|
1443 calculatedSegmentSize = KH264ENCIMPL_MAX_SEGMENTSIZE; |
|
1444 } |
|
1445 } |
|
1446 else |
|
1447 { |
|
1448 if ( aSizeBytes < iH264EncInitParams.iMaxOutputBufferSize ) |
|
1449 { |
|
1450 calculatedSegmentSize = aSizeBytes; |
|
1451 } |
|
1452 else |
|
1453 { |
|
1454 calculatedSegmentSize |
|
1455 = iH264EncInitParams.iMaxOutputBufferSize; |
|
1456 } |
|
1457 } |
|
1458 } |
|
1459 |
|
1460 // Set the target size on codec |
|
1461 TInt error = iCodec->SetParam( CONTROL_CMD_SET_PACKET_SIZE, |
|
1462 &calculatedSegmentSize ); |
|
1463 |
|
1464 if ( error != KErrNone ) |
|
1465 { |
|
1466 ClientFatalError( error ); |
|
1467 return; |
|
1468 } |
|
1469 iH264EncInitParams.iMaxCodedSegmentSize = calculatedSegmentSize; |
|
1470 |
|
1471 PRINT_EXIT; |
|
1472 } |
|
1473 |
|
1474 |
|
1475 //---------------------------------------------------------------------------- |
|
1476 // Sets the bit-rate control options for a layer |
|
1477 //---------------------------------------------------------------------------- |
|
1478 // |
|
1479 void CAriH264encHwDeviceImpl::SetRateControlOptions( TUint aLayer, |
|
1480 const TRateControlOptions& aOptions ) |
|
1481 { |
|
1482 PRINT_ENTRY; |
|
1483 |
|
1484 if ( !iEncStateMac->IsInitialized() ) |
|
1485 { |
|
1486 ClientFatalError( KErrNotReady ); |
|
1487 return; |
|
1488 } |
|
1489 |
|
1490 // Since layered bit-rate scalability is not used, options are set for the |
|
1491 // entire stream |
|
1492 if ( aLayer != 0 ) |
|
1493 { |
|
1494 return; |
|
1495 } |
|
1496 |
|
1497 if ( ( aOptions.iPictureRate <= 0 ) || |
|
1498 ( aOptions.iControl & EBrControlPicture ) ) |
|
1499 { |
|
1500 return; |
|
1501 } |
|
1502 |
|
1503 if ( aOptions.iControl & EBrControlStream ) |
|
1504 { |
|
1505 if ( ( aOptions.iQualityTemporalTradeoff < 0 ) || |
|
1506 ( aOptions.iQualityTemporalTradeoff > 1 ) || |
|
1507 ( aOptions.iLatencyQualityTradeoff < 0 ) || |
|
1508 ( aOptions.iLatencyQualityTradeoff > 1 ) || |
|
1509 ( aOptions.iBitrate == 0 ) ) |
|
1510 { |
|
1511 return; |
|
1512 } |
|
1513 } |
|
1514 |
|
1515 TRateControlOptions* rateControlOptions = NULL; |
|
1516 TRAPD( error, rateControlOptions = new ( ELeave )TRateControlOptions ); |
|
1517 if( error != KErrNone ) |
|
1518 { |
|
1519 ClientFatalError( error ); |
|
1520 return; |
|
1521 } |
|
1522 |
|
1523 rateControlOptions->iControl = aOptions.iControl; |
|
1524 // default bit rate used |
|
1525 if( aOptions.iControl & EBrControlNone ) |
|
1526 { |
|
1527 rateControlOptions->iBitrate = iH264EncInitParams.iBitRate; |
|
1528 } |
|
1529 else |
|
1530 { |
|
1531 rateControlOptions->iBitrate = ( aOptions.iBitrate |
|
1532 <= iH264EncInitParams.iBitRate ) ? ( aOptions.iBitrate ) |
|
1533 : ( iH264EncInitParams.iBitRate ); |
|
1534 } |
|
1535 |
|
1536 rateControlOptions->iPictureQuality = aOptions.iPictureQuality; |
|
1537 rateControlOptions->iPictureRate = aOptions.iPictureRate; |
|
1538 rateControlOptions->iQualityTemporalTradeoff |
|
1539 = aOptions.iQualityTemporalTradeoff; |
|
1540 rateControlOptions->iLatencyQualityTradeoff |
|
1541 = aOptions.iLatencyQualityTradeoff; |
|
1542 |
|
1543 TRAP( error, iEngine->AddCommandL( CBaseEngine::EHighPriority, |
|
1544 CONTROL_CMD_SET_RATE_CONTROL_OPTIONS, rateControlOptions ) ); |
|
1545 |
|
1546 if( error != KErrNone ) |
|
1547 { |
|
1548 delete rateControlOptions; |
|
1549 ClientFatalError ( error ); |
|
1550 return; |
|
1551 } |
|
1552 |
|
1553 if( !iEncStateMac->IsPlaying() ) |
|
1554 { |
|
1555 TInt ret = iCodec->SetParam( CONTROL_CMD_SET_RATE_CONTROL_OPTIONS, |
|
1556 rateControlOptions ); |
|
1557 if ( ret ) |
|
1558 { |
|
1559 ClientFatalError( ret ); |
|
1560 } |
|
1561 } |
|
1562 |
|
1563 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1564 "iBitrate is %d", ( TInt )aOptions.iBitrate ) ); |
|
1565 |
|
1566 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1567 "iPictureQuality is %d" , ( TInt )aOptions.iPictureQuality ) ); |
|
1568 |
|
1569 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1570 " iPictureRate is %f", ( TReal )aOptions.iPictureRate ) ); |
|
1571 |
|
1572 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1573 "iQualityTemporalTradeoff is %f" , |
|
1574 ( TReal )aOptions.iQualityTemporalTradeoff ) ); |
|
1575 |
|
1576 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1577 " iLatencyQualityTradeoff is %f " , |
|
1578 ( TReal ) aOptions.iLatencyQualityTradeoff ) ); |
|
1579 |
|
1580 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetRateControlOptions()" |
|
1581 "iControl is %x" , ( TInt ) aOptions.iControl ) ); |
|
1582 |
|
1583 PRINT_EXIT; |
|
1584 } |
|
1585 |
|
1586 //---------------------------------------------------------------------------- |
|
1587 // Sets in-layer scalability options for a layer |
|
1588 //---------------------------------------------------------------------------- |
|
1589 // |
|
1590 void CAriH264encHwDeviceImpl::SetInLayerScalabilityL( TUint /*aLayer*/, |
|
1591 TUint /*aNumSteps*/, |
|
1592 TInLayerScalabilityType /*aScalabilityType*/, |
|
1593 const TArray<TUint>& /*aBitrateShare*/, |
|
1594 const TArray<TUint>& /*aPictureShare*/ ) |
|
1595 { |
|
1596 PRINT_ENTRY; |
|
1597 |
|
1598 if( !iEncStateMac->IsInitialized() ) |
|
1599 { |
|
1600 PRINT_ERR( "SetInLayerScalabilityL () called before " |
|
1601 "Initialize ()" ); |
|
1602 User::Leave( KErrNotReady ); |
|
1603 } |
|
1604 |
|
1605 PRINT_ERR( "SetInLayerScalabilityL () not supported..leaving with " |
|
1606 "KErrNotSupported" ); |
|
1607 User::Leave( KErrNotSupported ); |
|
1608 |
|
1609 PRINT_EXIT; |
|
1610 } |
|
1611 |
|
1612 //---------------------------------------------------------------------------- |
|
1613 // Sets the period for layer promotions points for a scalability layer |
|
1614 //---------------------------------------------------------------------------- |
|
1615 // |
|
1616 void CAriH264encHwDeviceImpl::SetLayerPromotionPointPeriod( TUint /*aLayer*/, |
|
1617 TUint /*aPeriod*/ ) |
|
1618 { |
|
1619 PRINT_ENTRY; |
|
1620 |
|
1621 if ( !iEncStateMac->IsInitialized() ) |
|
1622 { |
|
1623 ClientFatalError( KErrNotReady ); |
|
1624 return; |
|
1625 } |
|
1626 ClientFatalError( KErrNotSupported ); |
|
1627 |
|
1628 PRINT_EXIT; |
|
1629 } |
|
1630 |
|
1631 //---------------------------------------------------------------------------- |
|
1632 // Returns coding-standard specific settings output from the encoder |
|
1633 //---------------------------------------------------------------------------- |
|
1634 // |
|
1635 HBufC8* CAriH264encHwDeviceImpl::CodingStandardSpecificSettingsOutputLC() |
|
1636 { |
|
1637 PRINT_ENTRY; |
|
1638 |
|
1639 if( !iEncStateMac->IsInitialized() ) |
|
1640 { |
|
1641 PRINT_ERR( "CodingStandardSpecificSettingsOutputLC () called before " |
|
1642 "Initialize ()" ); |
|
1643 User::Leave( KErrNotReady ); |
|
1644 } |
|
1645 |
|
1646 PRINT_ERR( "CodingStandardSpecificSettingsOutputLC () not supported.." |
|
1647 "leaving with KErrNotSupported" ); |
|
1648 User::Leave( KErrNotSupported ); |
|
1649 |
|
1650 PRINT_EXIT; |
|
1651 return NULL; |
|
1652 } |
|
1653 |
|
1654 //---------------------------------------------------------------------------- |
|
1655 // Returns implementation-specific settings output from the encoder |
|
1656 //---------------------------------------------------------------------------- |
|
1657 // |
|
1658 HBufC8* CAriH264encHwDeviceImpl::ImplementationSpecificSettingsOutputLC() |
|
1659 { |
|
1660 PRINT_ENTRY; |
|
1661 |
|
1662 if( !iEncStateMac->IsInitialized() ) |
|
1663 { |
|
1664 PRINT_ERR( "ImplementationSpecificSettingsOutputLC () called before " |
|
1665 "Initialize ()" ); |
|
1666 User::Leave( KErrNotReady ); |
|
1667 } |
|
1668 |
|
1669 PRINT_ERR( "ImplementationSpecificSettingsOutputLC () not supported.." |
|
1670 "leaving with KErrNotSupported" ); |
|
1671 User::Leave( KErrNotSupported ); |
|
1672 |
|
1673 PRINT_EXIT; |
|
1674 return NULL; |
|
1675 } |
|
1676 |
|
1677 //---------------------------------------------------------------------------- |
|
1678 // Requests the encoder to sends supplemental information in the bitstream |
|
1679 //---------------------------------------------------------------------------- |
|
1680 // |
|
1681 void CAriH264encHwDeviceImpl::SendSupplementalInfoL( const TDesC8& /*aData*/ ) |
|
1682 { |
|
1683 PRINT_ENTRY; |
|
1684 |
|
1685 if( !iEncStateMac->IsInitialized() ) |
|
1686 { |
|
1687 PRINT_ERR( "SendSupplementalInfoL () called before " |
|
1688 "Initialize ()" ); |
|
1689 User::Leave( KErrNotReady ); |
|
1690 } |
|
1691 |
|
1692 PRINT_ERR( "SendSupplementalInfoL () not supported.." |
|
1693 "leaving with KErrNotSupported" ); |
|
1694 User::Leave( KErrNotSupported ); |
|
1695 |
|
1696 PRINT_EXIT; |
|
1697 } |
|
1698 |
|
1699 //---------------------------------------------------------------------------- |
|
1700 // Requests the encoder to sends supplemental information in the bitstream |
|
1701 //---------------------------------------------------------------------------- |
|
1702 // |
|
1703 void CAriH264encHwDeviceImpl::SendSupplementalInfoL( const TDesC8& /*aData*/, |
|
1704 const TTimeIntervalMicroSeconds& /*aTimestamp*/ ) |
|
1705 { |
|
1706 PRINT_ENTRY; |
|
1707 |
|
1708 if( !iEncStateMac->IsInitialized() ) |
|
1709 { |
|
1710 PRINT_ERR( "SendSupplementalInfoL () called before " |
|
1711 "Initialize ()" ); |
|
1712 User::Leave( KErrNotReady ); |
|
1713 } |
|
1714 |
|
1715 PRINT_ERR( "SendSupplementalInfoL () not supported.." |
|
1716 "leaving with KErrNotSupported" ); |
|
1717 User::Leave( KErrNotSupported ); |
|
1718 |
|
1719 PRINT_EXIT; |
|
1720 } |
|
1721 |
|
1722 //---------------------------------------------------------------------------- |
|
1723 // Cancels the current supplemental information send request |
|
1724 //---------------------------------------------------------------------------- |
|
1725 // |
|
1726 void CAriH264encHwDeviceImpl::CancelSupplementalInfo() |
|
1727 { |
|
1728 PRINT_ENTRY; |
|
1729 |
|
1730 if( !iEncStateMac->IsInitialized() ) |
|
1731 { |
|
1732 ClientFatalError( KErrNotReady ); |
|
1733 return; |
|
1734 } |
|
1735 ClientFatalError( KErrNotSupported ); |
|
1736 |
|
1737 PRINT_EXIT; |
|
1738 } |
|
1739 |
|
1740 //---------------------------------------------------------------------------- |
|
1741 // Gets the current output buffer status. The information includes |
|
1742 // the number of free output buffers and the total size of free buffers in |
|
1743 // bytes. |
|
1744 //---------------------------------------------------------------------------- |
|
1745 // |
|
1746 void CAriH264encHwDeviceImpl::GetOutputBufferStatus( TUint& aNumFreeBuffers, |
|
1747 TUint& aTotalFreeBytes ) |
|
1748 { |
|
1749 PRINT_ENTRY; |
|
1750 |
|
1751 if( !iEncStateMac->IsInitialized() ) |
|
1752 { |
|
1753 ClientFatalError( KErrNotReady ); |
|
1754 return; |
|
1755 } |
|
1756 |
|
1757 aNumFreeBuffers = iEngine->NumOutputBuffers() |
|
1758 + iOutputFreeBufferQueue.Count(); |
|
1759 |
|
1760 aTotalFreeBytes = aNumFreeBuffers * iOutputBufferSize; |
|
1761 |
|
1762 PRINT_EXIT; |
|
1763 } |
|
1764 //---------------------------------------------------------------------------- |
|
1765 // Returns a used output buffer back to the encoder |
|
1766 //---------------------------------------------------------------------------- |
|
1767 // |
|
1768 void CAriH264encHwDeviceImpl::ReturnBuffer( TVideoOutputBuffer* aBuffer ) |
|
1769 { |
|
1770 PRINT_ENTRY; |
|
1771 |
|
1772 if ( !iEncStateMac->IsInitialized() ) |
|
1773 { |
|
1774 ClientFatalError( KErrNotReady ); |
|
1775 return; |
|
1776 } |
|
1777 |
|
1778 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
1779 { |
|
1780 // coded picture buffers so add it to Interanal Q or process engine |
|
1781 if ( iNumofBuffersPendingFromClientInChangeToPacketMode ) |
|
1782 { |
|
1783 iEngine->AddOutput( aBuffer ); |
|
1784 --iNumofBuffersPendingFromClientInChangeToPacketMode; |
|
1785 return; |
|
1786 } |
|
1787 |
|
1788 // buffers returned by the client are |
|
1789 if ( iNumOfBuffersAtClientInPacketModeNeedReAllocation ) |
|
1790 { |
|
1791 TRAPD( error, ReallocateSegmentBufferL( aBuffer ) ); |
|
1792 if( error != KErrNone ) |
|
1793 { |
|
1794 ClientFatalError( error ); |
|
1795 return; |
|
1796 } |
|
1797 iNumOfBuffersAtClientInPacketModeNeedReAllocation--; |
|
1798 } |
|
1799 |
|
1800 TInt error = KErrNone; |
|
1801 error = iOutputFreeBufferQueue.Append( aBuffer ); |
|
1802 |
|
1803 if( error != KErrNone ) |
|
1804 { |
|
1805 ClientFatalError( error ); |
|
1806 return; |
|
1807 } |
|
1808 |
|
1809 if ( !iPacketsPending ) |
|
1810 { |
|
1811 return; |
|
1812 } |
|
1813 |
|
1814 // still has packets in temporary buffer |
|
1815 if ( iTotalLengthFilledSoFarInPacketMode |
|
1816 < iTotalOutputBufferLengthInPacketMode ) |
|
1817 { |
|
1818 TVideoOutputBuffer *outBuf = iOutputFreeBufferQueue[0]; |
|
1819 FillVideoSegment( outBuf, iInternalOutputBufferQueue[0] ); |
|
1820 iOutputFreeBufferQueue.Remove( 0 ); |
|
1821 |
|
1822 #ifdef CALCINSTANTBITRATE |
|
1823 CalculateInstantBitRate( *outBuf ); |
|
1824 #endif |
|
1825 |
|
1826 iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf ); |
|
1827 } |
|
1828 } |
|
1829 else |
|
1830 { |
|
1831 aBuffer->iData.Set( ( TUint8* )aBuffer->iData.Ptr(), |
|
1832 iOutputBufferSize ); |
|
1833 |
|
1834 // add the buffer back to queue or process engine |
|
1835 if ( ( !iEncStateMac->IsInputEndPending() ) |
|
1836 && ( !iEncStateMac->IsStopped() ) ) |
|
1837 { |
|
1838 iEngine->AddOutput( ( TAny* )aBuffer ); |
|
1839 } |
|
1840 else |
|
1841 { |
|
1842 TInt error = iOutputFreeBufferQueue.Append( aBuffer ); |
|
1843 if ( error != KErrNone ) |
|
1844 { |
|
1845 ClientFatalError( error ); |
|
1846 return; |
|
1847 } |
|
1848 } |
|
1849 } |
|
1850 |
|
1851 PRINT_EXIT; |
|
1852 } |
|
1853 |
|
1854 //---------------------------------------------------------------------------- |
|
1855 // Indicates a picture loss to the encoder, without specifying the lost |
|
1856 // picture |
|
1857 //---------------------------------------------------------------------------- |
|
1858 // |
|
1859 void CAriH264encHwDeviceImpl::PictureLoss() |
|
1860 { |
|
1861 PRINT_ENTRY; |
|
1862 |
|
1863 if( !iEncStateMac->IsInitialized() ) |
|
1864 { |
|
1865 ClientFatalError( KErrNotReady ); |
|
1866 return; |
|
1867 } |
|
1868 iPictureLoss = ETrue; |
|
1869 |
|
1870 PRINT_EXIT; |
|
1871 } |
|
1872 |
|
1873 //---------------------------------------------------------------------------- |
|
1874 // Indicates to the encoder the pictures that have been lost |
|
1875 //---------------------------------------------------------------------------- |
|
1876 // |
|
1877 void CAriH264encHwDeviceImpl::PictureLoss( |
|
1878 const TArray<TPictureId>& /*aPictures*/ ) |
|
1879 { |
|
1880 PRINT_ENTRY; |
|
1881 |
|
1882 if ( !iEncStateMac->IsInitialized() ) |
|
1883 { |
|
1884 ClientFatalError( KErrNotReady ); |
|
1885 return; |
|
1886 } |
|
1887 iPictureLoss = ETrue; |
|
1888 |
|
1889 PRINT_EXIT; |
|
1890 } |
|
1891 |
|
1892 //---------------------------------------------------------------------------- |
|
1893 // Indicates a slice loss to the encoder. |
|
1894 //---------------------------------------------------------------------------- |
|
1895 // |
|
1896 void CAriH264encHwDeviceImpl::SliceLoss( TUint aFirstMacroblock, |
|
1897 TUint aNumMacroblocks, |
|
1898 const TPictureId& /*aPicture*/ ) |
|
1899 { |
|
1900 PRINT_ENTRY; |
|
1901 |
|
1902 if( !iEncStateMac->IsInitialized() ) |
|
1903 { |
|
1904 ClientFatalError( KErrNotReady ); |
|
1905 return; |
|
1906 } |
|
1907 |
|
1908 if ( ( aFirstMacroblock == 0 ) || ( aNumMacroblocks == 0 ) ) |
|
1909 { |
|
1910 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SliceLoss() " |
|
1911 "aNumMacroblocks or aFirstMacroblock = 0 return" ) ); |
|
1912 return; |
|
1913 } |
|
1914 |
|
1915 TH264EncSliceLoss* sliceLossParams = NULL; |
|
1916 TRAPD( error, sliceLossParams = new( ELeave ) TH264EncSliceLoss ); |
|
1917 if( error != KErrNone ) |
|
1918 { |
|
1919 ClientFatalError( error ); |
|
1920 return; |
|
1921 } |
|
1922 |
|
1923 sliceLossParams->iFirstMacroblock = aFirstMacroblock; |
|
1924 sliceLossParams->iNumMacroblocks = aNumMacroblocks; |
|
1925 |
|
1926 TRAP( error, iEngine->AddCommandL( CBaseEngine::ENormalPriority, |
|
1927 CONTROL_CMD_SET_SLICELOSS, sliceLossParams ) ); |
|
1928 |
|
1929 if( error != KErrNone ) |
|
1930 { |
|
1931 delete sliceLossParams; |
|
1932 ClientFatalError ( error ); |
|
1933 return; |
|
1934 } |
|
1935 |
|
1936 PRINT_EXIT; |
|
1937 } |
|
1938 |
|
1939 //---------------------------------------------------------------------------- |
|
1940 // Sends a reference picture selection request to the encoder |
|
1941 //---------------------------------------------------------------------------- |
|
1942 // |
|
1943 void CAriH264encHwDeviceImpl::ReferencePictureSelection( |
|
1944 const TDesC8& /*aSelectionData*/) |
|
1945 { |
|
1946 PRINT_ENTRY; |
|
1947 |
|
1948 if( !iEncStateMac->IsInitialized() ) |
|
1949 { |
|
1950 ClientFatalError( KErrNotReady ); |
|
1951 return; |
|
1952 } |
|
1953 ClientFatalError( KErrNotSupported ); |
|
1954 |
|
1955 PRINT_EXIT; |
|
1956 } |
|
1957 |
|
1958 |
|
1959 //---------------------------------------------------------------------------- |
|
1960 // Initializes the device, and reserves hardware resources |
|
1961 //---------------------------------------------------------------------------- |
|
1962 // |
|
1963 void CAriH264encHwDeviceImpl::Initialize() |
|
1964 { |
|
1965 PRINT_ENTRY; |
|
1966 |
|
1967 //Device should be in unintialized state |
|
1968 if ( !iEncStateMac->IsTransitionValid( |
|
1969 CStateMachine::EInitializingCommand ) ) |
|
1970 { |
|
1971 iMMFDevVideoRecordProxy->MdvrpInitializeComplete(this |
|
1972 , KErrPermissionDenied ); |
|
1973 return; |
|
1974 } |
|
1975 |
|
1976 // check for input and output formats set by the client |
|
1977 if ( ! ( iH264EncInitParams.iBeforeInitialize & EEncInputFormat ) ) |
|
1978 { |
|
1979 PRINT_MSG( LEVEL_CRITICAL, ("CAriH264encHwDeviceImpl::Initialize() " |
|
1980 "- SetInputFormat not called" ) ); |
|
1981 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, |
|
1982 KErrNotSupported ); |
|
1983 return; |
|
1984 } |
|
1985 |
|
1986 // check for buffer sizes |
|
1987 if( iH264EncInitParams.iBeforeInitialize & EEncBufferOptions ) |
|
1988 { |
|
1989 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
1990 { |
|
1991 // Buffer size related checks |
|
1992 if ( ( iH264EncInitParams.iMaxOutputBufferSize > |
|
1993 ( KH264ENCIMPL_FACTOR_FOR_OUTPUTBUFFERSIZE_IN_PACKETMODE * |
|
1994 KH264ENCIMPL_MAX_SEGMENTSIZE ) ) || |
|
1995 ( iH264EncInitParams.iMaxCodedSegmentSize > |
|
1996 KH264ENCIMPL_MAX_SEGMENTSIZE ) || |
|
1997 ( iH264EncInitParams.iMaxCodedSegmentSize > |
|
1998 iH264EncInitParams.iMaxOutputBufferSize ) || |
|
1999 ( iH264EncInitParams.iMaxCodedSegmentSize == 0 ) ) |
|
2000 { |
|
2001 PRINT_MSG( LEVEL_CRITICAL, ( "CAriH264encHwDeviceImpl" |
|
2002 "::Initialize() - Wrong size for iMaxCodedSegmentSize" ) ); |
|
2003 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, |
|
2004 KErrNotSupported ); |
|
2005 return; |
|
2006 } |
|
2007 } |
|
2008 |
|
2009 else if ( iH264EncInitParams.iDataUnitType == EDuCodedPicture ) |
|
2010 { |
|
2011 if ( ( iH264EncInitParams.iMaxCodedPictureSize > |
|
2012 iH264EncInitParams.iMaxOutputBufferSize ) |
|
2013 || ( iH264EncInitParams.iMaxCodedPictureSize == 0 ) ) |
|
2014 { |
|
2015 PRINT_MSG( LEVEL_CRITICAL, ( "CAriH264encHwDeviceImpl" |
|
2016 "::Initialize() - Wrong size for iMaxCodedPictureSize" ) ); |
|
2017 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, |
|
2018 KErrNotSupported ); |
|
2019 return; |
|
2020 } |
|
2021 } |
|
2022 } |
|
2023 else |
|
2024 { |
|
2025 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2026 { |
|
2027 iH264EncInitParams.iMinNumOutputBuffers |
|
2028 = KH264ENCIMPL_MAXNUM_SEGMENTBUFFERS; |
|
2029 iH264EncInitParams.iMaxCodedSegmentSize |
|
2030 = KH264ENCIMPL_DEFAULT_SEGMENTSIZE; |
|
2031 iH264EncInitParams.iMaxOutputBufferSize |
|
2032 = KH264ENCIMPL_MAX_SEGMENTSIZE; |
|
2033 } |
|
2034 else |
|
2035 { |
|
2036 iH264EncInitParams.iMinNumOutputBuffers |
|
2037 = KH264ENCIMPL_MAXNUM_OUTPUTBUFFERS; |
|
2038 } |
|
2039 } |
|
2040 |
|
2041 // based on level set the max bit rate |
|
2042 switch ( iH264EncInitParams.iLevel ) |
|
2043 { |
|
2044 //Level 1b |
|
2045 case KH264ENCIMPL_LEVEL_1b: |
|
2046 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_1b; |
|
2047 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
2048 break; |
|
2049 |
|
2050 case KH264ENCIMPL_LEVEL_1: |
|
2051 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_1; |
|
2052 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
2053 break; |
|
2054 |
|
2055 case KH264ENCIMPL_LEVEL_11: |
|
2056 // Both Level 1b and 1.1 have this value |
|
2057 // need to decide if 1.1 or 1.b |
|
2058 // two options - client passes buffer options and client doesnt |
|
2059 // pass buffer options |
|
2060 { |
|
2061 TBool isLevel1b = EFalse; |
|
2062 if ( iH264EncInitParams.iBeforeInitialize & EEncBufferOptions ) |
|
2063 { |
|
2064 isLevel1b = ( ( KH264ENCIMPL_LEVEL1b_MAXCPBSIZE <= |
|
2065 iH264EncInitParams.iMaxCodedPictureSize ) && |
|
2066 ( iH264EncInitParams.iMaxCodedPictureSize < |
|
2067 KH264ENCIMPL_LEVEL11_MAXCPBSIZE ) ) |
|
2068 ? ( ETrue ) |
|
2069 : ( EFalse ); |
|
2070 } |
|
2071 //now we have input size information to decide 1b vs 1.1 |
|
2072 else |
|
2073 { |
|
2074 isLevel1b = ( ( iH264EncInitParams.iPictureSize.iWidth > |
|
2075 KH264ENCIMPL_QCIF_WIDTH ) |
|
2076 && ( iH264EncInitParams.iPictureSize.iHeight > |
|
2077 KH264ENCIMPL_QCIF_HEIGHT ) ) |
|
2078 ? ( EFalse ) |
|
2079 : ( ETrue ); |
|
2080 } |
|
2081 |
|
2082 if ( isLevel1b ) |
|
2083 { |
|
2084 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_1b; |
|
2085 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_1b; |
|
2086 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
2087 } |
|
2088 else |
|
2089 { |
|
2090 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_11; |
|
2091 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_11; |
|
2092 iH264EncInitParams.iTargetPictureRate |
|
2093 = ( ( iH264EncInitParams.iPictureSize.iWidth |
|
2094 <= KH264ENCIMPL_QCIF_WIDTH ) && |
|
2095 ( iH264EncInitParams.iPictureSize.iHeight |
|
2096 <= KH264ENCIMPL_QCIF_HEIGHT ) ) ? ( KPictureRate15 ) |
|
2097 : ( KPictureRate75 ); |
|
2098 } |
|
2099 } |
|
2100 break; |
|
2101 |
|
2102 case KH264ENCIMPL_LEVEL_12: |
|
2103 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_12; |
|
2104 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
2105 break; |
|
2106 |
|
2107 case KH264ENCIMPL_LEVEL_13: |
|
2108 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_13; |
|
2109 iH264EncInitParams.iTargetPictureRate = KPictureRate30; |
|
2110 break; |
|
2111 |
|
2112 case KH264ENCIMPL_LEVEL_2: |
|
2113 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_2; |
|
2114 iH264EncInitParams.iTargetPictureRate = KPictureRate30; |
|
2115 break; |
|
2116 |
|
2117 case KH264ENCIMPL_LEVEL_21: |
|
2118 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_21; |
|
2119 if ( iH264EncInitParams.iPictureSize.iHeight > |
|
2120 KH264ENCIMPL_HALFSDTV_HEIGHT_NTSC ) |
|
2121 { |
|
2122 // HALFSDTV-PAL |
|
2123 iH264EncInitParams.iTargetPictureRate = KPictureRate25; |
|
2124 } |
|
2125 else |
|
2126 { |
|
2127 // HALFSDTV-NTSC |
|
2128 iH264EncInitParams.iTargetPictureRate = KPictureRate30; |
|
2129 } |
|
2130 break; |
|
2131 |
|
2132 case KH264ENCIMPL_LEVEL_22: |
|
2133 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_22; |
|
2134 if ( iH264EncInitParams.iPictureSize.iHeight > |
|
2135 KH264ENCIMPL_SDTV_HEIGHT_NTSC ) |
|
2136 { |
|
2137 // SDTV-PAL |
|
2138 iH264EncInitParams.iTargetPictureRate |
|
2139 = KH264ENCIMPL_PICTURERATE_12_5; |
|
2140 } |
|
2141 else |
|
2142 { |
|
2143 // SDTV-NTSC |
|
2144 iH264EncInitParams.iTargetPictureRate |
|
2145 = KPictureRate15; |
|
2146 } |
|
2147 break; |
|
2148 |
|
2149 case KH264ENCIMPL_LEVEL_3: |
|
2150 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_3; |
|
2151 if ( iH264EncInitParams.iPictureSize.iHeight |
|
2152 > KH264ENCIMPL_SDTV_HEIGHT_NTSC ) |
|
2153 { |
|
2154 iH264EncInitParams.iTargetPictureRate = KPictureRate25; |
|
2155 } |
|
2156 else |
|
2157 { |
|
2158 // SDTV-NTSC |
|
2159 iH264EncInitParams.iTargetPictureRate = KPictureRate30; |
|
2160 } |
|
2161 break; |
|
2162 |
|
2163 // level unknown based on size decide bitrate and level |
|
2164 case 0: |
|
2165 SetLevelAndBitRate(); |
|
2166 break; |
|
2167 |
|
2168 default: |
|
2169 break; |
|
2170 }; |
|
2171 |
|
2172 // create codec |
|
2173 TRAPD( error, iCodec = CAriH264encWrapper::NewL( iH264EncInitParams ) ); |
|
2174 if( error != KErrNone ) |
|
2175 { |
|
2176 // init complete with error message |
|
2177 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2178 return; |
|
2179 } |
|
2180 |
|
2181 // set the sync options to the codec |
|
2182 if( iClockSource ) |
|
2183 { |
|
2184 TInt error = iCodec->SetSyncOptions( iClockSource ); |
|
2185 |
|
2186 if( error != KErrNone ) |
|
2187 { |
|
2188 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2189 return; |
|
2190 } |
|
2191 } |
|
2192 //Check whether picture is of QCIF format if VT fast call setup is set |
|
2193 |
|
2194 if ( iH264EncInitParams.iVTFastCallSetUp ) |
|
2195 { |
|
2196 if ( iH264EncInitParams.iPictureSize.iWidth |
|
2197 != KH264ENCIMPL_QCIF_WIDTH || |
|
2198 iH264EncInitParams.iPictureSize.iHeight |
|
2199 != KH264ENCIMPL_QCIF_HEIGHT ) |
|
2200 { |
|
2201 PRINT_MSG( LEVEL_LOW, ("Input resolution should be 176x144 for" |
|
2202 " VT Fast call setup" ) ); |
|
2203 ClientFatalError( KErrNotSupported ); |
|
2204 } |
|
2205 } |
|
2206 |
|
2207 if ( error != KErrNone ) |
|
2208 { |
|
2209 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2210 return; |
|
2211 } |
|
2212 |
|
2213 //create engine |
|
2214 TRAP( error, iEngine = CBaseEngine::NewL( this, |
|
2215 ( MBaseCodec* ) iCodec, EFalse ) ); |
|
2216 |
|
2217 if( error != KErrNone ) |
|
2218 { |
|
2219 //init complete with error message |
|
2220 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2221 return; |
|
2222 } |
|
2223 //get the max buffer length from the codec |
|
2224 TInt maxOutputBufferSize = 0; |
|
2225 error = iCodec->GetParam( CONTROL_CMD_GET_MAX_FRAME_SIZE, |
|
2226 &maxOutputBufferSize ); |
|
2227 |
|
2228 if( error != KErrNone ) |
|
2229 { |
|
2230 //init complete with error message |
|
2231 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2232 return; |
|
2233 } |
|
2234 |
|
2235 // if EduCodedPicture mode then check for buffer size passed |
|
2236 if( iH264EncInitParams.iDataUnitType == EDuCodedPicture ) |
|
2237 { |
|
2238 if ( iH264EncInitParams.iBeforeInitialize & EEncBufferOptions ) |
|
2239 { |
|
2240 if( maxOutputBufferSize |
|
2241 > iH264EncInitParams.iMaxCodedPictureSize ) |
|
2242 { |
|
2243 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::Initialize()" |
|
2244 "maxOutputBufferSize = %d", ( TInt ) maxOutputBufferSize ) ); |
|
2245 //init complete with error message |
|
2246 iMMFDevVideoRecordProxy->MdvrpInitializeComplete(this, |
|
2247 KErrNotSupported ); |
|
2248 return; |
|
2249 } |
|
2250 } |
|
2251 else |
|
2252 { |
|
2253 iH264EncInitParams.iMaxOutputBufferSize = maxOutputBufferSize; |
|
2254 iH264EncInitParams.iMaxCodedPictureSize = maxOutputBufferSize; |
|
2255 } |
|
2256 } |
|
2257 |
|
2258 // if packet mode is on then allocate memory for NAL information |
|
2259 TUint maxNumOfPackets = 0; |
|
2260 if( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2261 { |
|
2262 error = iCodec->GetParam( CONTROL_CMD_GET_MAX_NUM_PACKETS, |
|
2263 &iMaxNumOfPackets ); |
|
2264 if( error != KErrNone ) |
|
2265 { |
|
2266 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2267 return; |
|
2268 } |
|
2269 } |
|
2270 |
|
2271 if ( iH264EncInitParams.iDataUnitType != EDuVideoSegment ) |
|
2272 { |
|
2273 TInt maxSlices = 0; |
|
2274 if( maxOutputBufferSize ) |
|
2275 { |
|
2276 maxSlices = maxOutputBufferSize / KH264ENCIMPL_MIN_SLICESIZE; |
|
2277 if( maxOutputBufferSize % KH264ENCIMPL_MIN_SLICESIZE ) |
|
2278 { |
|
2279 maxSlices++; |
|
2280 } |
|
2281 } |
|
2282 |
|
2283 #ifndef EMZ_AVC_ENC_CODEC_SEIINFO_ENABLE |
|
2284 PRINT_MSG( LEVEL_LOW, ( "CreateCodedOutputBuffersL SEI disble " ) ); |
|
2285 |
|
2286 // included KNumOfConfigParams*KDoubleWordLength bytes which are |
|
2287 // required for filling offset length information |
|
2288 |
|
2289 TRAP( error, CreateCodedOutputBuffersL( ( maxOutputBufferSize + |
|
2290 KWordLength + ( ( KNumOfConfigParams + maxSlices ) |
|
2291 * KDoubleWordLength ) ) ) ); |
|
2292 #else |
|
2293 PRINT_MSG( LEVEL_LOW, ("CreateCodedOutputBuffersL SEI enable " ) ); |
|
2294 TRAP( error, CreateCodedOutputBuffersL( ( maxOutputBufferSize + |
|
2295 KWordLength + ( ( KNumOfNAL_SEI + maxSlices ) * |
|
2296 KDoubleWordLength ) ) ) ); |
|
2297 #endif |
|
2298 } |
|
2299 else |
|
2300 { |
|
2301 // Allocate sufficient segment mode buffers Comment it for some time. |
|
2302 iH264EncInitParams.iMinNumOutputBuffers = ( maxOutputBufferSize / |
|
2303 iH264EncInitParams.iMaxCodedSegmentSize ) * |
|
2304 KH264ENCIMPL_MAXNUM_OUTPUTBUFFERS; |
|
2305 |
|
2306 // holds output buffer 2. holds packet lenght and offset information |
|
2307 TRAP( error, CreateInternalOutputBuffersL( maxOutputBufferSize ) ); |
|
2308 if( error != KErrNone ) |
|
2309 { |
|
2310 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2311 return; |
|
2312 } |
|
2313 |
|
2314 TRAP( error, CreatePacketOffsetLengthInfoBuffersL( iMaxNumOfPackets * |
|
2315 KDoubleWordLength ) ); |
|
2316 if( error != KErrNone ) |
|
2317 { |
|
2318 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2319 return; |
|
2320 } |
|
2321 |
|
2322 //segement size will be the max segment size |
|
2323 TUint segmentSize = iH264EncInitParams.iMaxOutputBufferSize; |
|
2324 if ( ( iH264EncInitParams.iDataEncapsulation == EDuGenericPayload ) && |
|
2325 ( iH264EncInitParams.iMaxOutputBufferSize < |
|
2326 ( KH264ENCIMPL_MAX_SEGMENTSIZE + KDoubleWordLength |
|
2327 + KWordLength ) ) ) |
|
2328 { |
|
2329 segmentSize += KDoubleWordLength + KWordLength; |
|
2330 } |
|
2331 |
|
2332 TRAP( error, CreateCodedOutputBuffersL( segmentSize ) ); |
|
2333 if( error != KErrNone ) |
|
2334 { |
|
2335 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2336 return; |
|
2337 } |
|
2338 } |
|
2339 |
|
2340 if ( error != KErrNone ) |
|
2341 { |
|
2342 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error ); |
|
2343 return; |
|
2344 } |
|
2345 |
|
2346 //reset the picture counters |
|
2347 iPictureCounters.iInputPictures = 0; |
|
2348 iPictureCounters.iPicturesSkippedRateControl = 0; |
|
2349 iPictureCounters.iPicturesProcessed = 0; |
|
2350 |
|
2351 // reset the options set by client |
|
2352 iH264EncInitParams.iBeforeInitialize = 0; |
|
2353 iCurSetH264EncParams = iH264EncInitParams; |
|
2354 iEncStateMac->Transit( CStateMachine::EInitializingCommand ); |
|
2355 iEncStateMac->Transit( CStateMachine::EInitializeCommand ); |
|
2356 iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, KErrNone ); |
|
2357 |
|
2358 PRINT_EXIT; |
|
2359 } |
|
2360 |
|
2361 //---------------------------------------------------------------------------- |
|
2362 // Commit all changes since the last CommitL(), Revert() or Initialize() |
|
2363 // to the Hw device |
|
2364 //---------------------------------------------------------------------------- |
|
2365 // |
|
2366 void CAriH264encHwDeviceImpl::CommitL() |
|
2367 { |
|
2368 PRINT_ENTRY; |
|
2369 |
|
2370 // This method can only be called after Initialize |
|
2371 if( !iEncStateMac->IsInitialized() ) |
|
2372 { |
|
2373 PRINT_ERR( "CommitL () called before " |
|
2374 "Initialize ()" ); |
|
2375 User::Leave( KErrNotReady ); |
|
2376 } |
|
2377 |
|
2378 // Methods that will be affected by CommitL in our case: |
|
2379 // SetOutputRectL |
|
2380 // SetCodingStandardSpecificOptionsL |
|
2381 // SetErrorsExpected |
|
2382 // SetMinRandomAccessRate |
|
2383 |
|
2384 TH264EncInitParams *currentParams = new( ELeave ) TH264EncInitParams; |
|
2385 CleanupStack::PushL( currentParams ); |
|
2386 *currentParams = iCurSetH264EncParams; |
|
2387 |
|
2388 // Add command apply commit settings to the codec |
|
2389 iEngine->AddCommandL ( CBaseEngine::ENormalPriority, |
|
2390 CONTROL_CMD_SET_COMMIT_OPTIONS, currentParams ); |
|
2391 |
|
2392 iCurSetH264EncParams.iAfterInitialize = 0; |
|
2393 CleanupStack::Pop(); |
|
2394 |
|
2395 PRINT_EXIT; |
|
2396 } |
|
2397 |
|
2398 //---------------------------------------------------------------------------- |
|
2399 // Revert all changes since the last CommitL(), Revert() or Initialize() |
|
2400 // back to their previous settings |
|
2401 //---------------------------------------------------------------------------- |
|
2402 // |
|
2403 void CAriH264encHwDeviceImpl::Revert() |
|
2404 { |
|
2405 PRINT_ENTRY; |
|
2406 |
|
2407 // This method can only be called after Initialize |
|
2408 if( !iEncStateMac->IsInitialized() ) |
|
2409 { |
|
2410 ClientFatalError( KErrNotReady ); |
|
2411 return; |
|
2412 } |
|
2413 |
|
2414 // Methods that will be affected by Revert in our case: |
|
2415 // SetOutputRectL |
|
2416 // SetCodingStandardSpecificOptionsL |
|
2417 // SetErrorsExpected |
|
2418 // SetMinRandomAccessRate |
|
2419 |
|
2420 iCurSetH264EncParams = iH264EncInitParams; |
|
2421 iCurSetH264EncParams.iAfterInitialize = 0; |
|
2422 |
|
2423 PRINT_EXIT; |
|
2424 } |
|
2425 |
|
2426 //---------------------------------------------------------------------------- |
|
2427 // This method is called only in case of client memory buffers |
|
2428 //---------------------------------------------------------------------------- |
|
2429 // |
|
2430 void CAriH264encHwDeviceImpl::WritePictureL( TVideoPicture* aPicture ) |
|
2431 { |
|
2432 PRINT_ENTRY; |
|
2433 |
|
2434 // This method should only be called only in following states |
|
2435 if( !iEncStateMac->IsInitialized() ) |
|
2436 { |
|
2437 PRINT_ERR( "WritePictureL () called before Initialize ()" ); |
|
2438 User::Leave( KErrNotReady ); |
|
2439 } |
|
2440 |
|
2441 if( iEncStateMac->IsInputEndPending() ) |
|
2442 { |
|
2443 PRINT_ERR( "Input end is pending.. leaving with KErrEof" ); |
|
2444 User::Leave( KErrEof ); |
|
2445 } |
|
2446 |
|
2447 if( !aPicture || |
|
2448 ( aPicture->iData.iRawData->Length() == 0 ) || |
|
2449 ( aPicture->iData.iRawData->Length() != |
|
2450 ( ( iH264EncInitParams.iPictureSize.iWidth * |
|
2451 iH264EncInitParams.iPictureSize.iHeight * 3 ) / 2 ) ) || |
|
2452 ( aPicture->iData.iDataFormat != EYuvRawData ) ) |
|
2453 { |
|
2454 PRINT_ERR( "Incorrect parameter passed" ); |
|
2455 User::Leave( KErrArgument ); |
|
2456 return; |
|
2457 } |
|
2458 |
|
2459 // Added a check to return the input picture if application tries to add |
|
2460 // pictures after calling InputEnd() or Stop() and before calling |
|
2461 // Start() again. |
|
2462 |
|
2463 if ( iEncStateMac->IsStopped() ) |
|
2464 { |
|
2465 SkipInputPicture( aPicture ); |
|
2466 return; |
|
2467 } |
|
2468 |
|
2469 // counter to represent the num of input pictures received |
|
2470 iPictureCounters.iInputPictures++; |
|
2471 if( IsForcedIFrameRequired( aPicture ) ) |
|
2472 { |
|
2473 iEngine->AddCommandL( CBaseEngine::ENormalPriority, |
|
2474 CONTROL_CMD_SET_FORCED_I_FRAME, NULL ); |
|
2475 iPictureLoss = EFalse; |
|
2476 } |
|
2477 |
|
2478 //Check if clock source is enabled skip logic |
|
2479 if ( iClockSource ) |
|
2480 { |
|
2481 if ( ( !CanEncode( aPicture ) ) || iFrozen ) |
|
2482 { |
|
2483 SkipInputPicture( aPicture ); |
|
2484 return; |
|
2485 } |
|
2486 } |
|
2487 |
|
2488 TInt error = iEngine->AddInput( aPicture ); |
|
2489 if( error != KErrNone ) |
|
2490 { |
|
2491 PRINT_ERR( "CAriH264encHwDeviceImpl::WritePictureL()" |
|
2492 " AddInput() failed" ); |
|
2493 User::Leave( error ); |
|
2494 return; |
|
2495 } |
|
2496 |
|
2497 if( this->iH264EncInitParams.iProcessRealtime ) |
|
2498 { |
|
2499 // Check the iDataUnitType |
|
2500 if( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2501 { |
|
2502 TInt perPictureSegmentBuffers |
|
2503 = iH264EncInitParams.iMinNumOutputBuffers |
|
2504 / KH264ENCIMPL_MAXNUM_OUTPUTBUFFERS; |
|
2505 TInt queueCount = iOutputFreeBufferQueue.Count(); |
|
2506 // Check for availability of segment buffers |
|
2507 if ( queueCount < perPictureSegmentBuffers ) |
|
2508 { |
|
2509 // Sufficient number of segment buffers are not present |
|
2510 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl" |
|
2511 "::WritePictureL() Input returned EDuVideoSegment " ) ); |
|
2512 // Return the earlier input picture added to the queue |
|
2513 iEngine->ReturnInput(); |
|
2514 return; |
|
2515 } |
|
2516 } |
|
2517 else |
|
2518 { |
|
2519 // Check for availability of buffers. |
|
2520 if ( iEngine->NumOutputBuffers() == 0 ) |
|
2521 { |
|
2522 // Return the earlier input picture added to the queue |
|
2523 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
2524 "::WritePictureL() Input returned EDuCodedPicture " ) ); |
|
2525 iEngine->ReturnInput(); |
|
2526 return; |
|
2527 } |
|
2528 } |
|
2529 } |
|
2530 |
|
2531 PRINT_EXIT; |
|
2532 } |
|
2533 |
|
2534 //---------------------------------------------------------------------------- |
|
2535 // Notifies the hardware device that the end of input data has been reached |
|
2536 // and no more input pictures will be written |
|
2537 //---------------------------------------------------------------------------- |
|
2538 // |
|
2539 void CAriH264encHwDeviceImpl::InputEnd() |
|
2540 { |
|
2541 PRINT_ENTRY; |
|
2542 |
|
2543 if ( !iEncStateMac->IsTransitionValid( CStateMachine::EInputEndCommand ) ) |
|
2544 { |
|
2545 ClientFatalError( KErrPermissionDenied ); |
|
2546 return; |
|
2547 } |
|
2548 |
|
2549 if ( iEngine->NumInputBuffers() == 0 ) |
|
2550 { |
|
2551 PRINT_MSG( LEVEL_HIGH, ("CAriH264encHwDeviceImpl::InputEnds()" ) ); |
|
2552 Stop(); |
|
2553 iMMFDevVideoRecordProxy->MdvrpStreamEnd(); |
|
2554 return; |
|
2555 } |
|
2556 else |
|
2557 { |
|
2558 iInputEndCalled = ETrue; |
|
2559 } |
|
2560 |
|
2561 iEncStateMac->Transit( CStateMachine::EInputEndCommand ); |
|
2562 |
|
2563 PRINT_EXIT; |
|
2564 } |
|
2565 |
|
2566 //---------------------------------------------------------------------------- |
|
2567 // Starts recording video |
|
2568 //---------------------------------------------------------------------------- |
|
2569 // |
|
2570 void CAriH264encHwDeviceImpl::Start() |
|
2571 { |
|
2572 PRINT_ENTRY; |
|
2573 |
|
2574 if( iEncStateMac->IsPlaying() && !iEncStateMac->IsPaused() ) |
|
2575 { |
|
2576 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::Start()-already in" |
|
2577 "started state, So ignore" ) ); |
|
2578 return; |
|
2579 } |
|
2580 |
|
2581 if( !iEncStateMac->IsTransitionValid( CStateMachine::EStartCommand ) ) |
|
2582 { |
|
2583 ClientFatalError( KErrPermissionDenied ); |
|
2584 return; |
|
2585 } |
|
2586 |
|
2587 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2588 { |
|
2589 // Enable flag which indicates that all picture params and sequence |
|
2590 // params are put into 1st buffer |
|
2591 iIsConfigDataFilledInFirstOutputBuffer = ETrue; |
|
2592 for( TInt i = 0; i <= iInternalOutputBufferQueue.Count(); i++ ) |
|
2593 { |
|
2594 TVideoOutputBuffer *outputBuffer = iInternalOutputBufferQueue[0]; |
|
2595 iEngine->AddOutput( ( TAny* )outputBuffer ); |
|
2596 iInternalOutputBufferQueue.Remove( 0 ); |
|
2597 } |
|
2598 } |
|
2599 else |
|
2600 { |
|
2601 // add all output buffers to engine |
|
2602 for( TInt i = 0; i <= iOutputFreeBufferQueue.Count(); i++ ) |
|
2603 { |
|
2604 TVideoOutputBuffer *outputBuffer = iOutputFreeBufferQueue[0]; |
|
2605 iEngine->AddOutput( ( TAny* )outputBuffer ); |
|
2606 iOutputFreeBufferQueue.Remove( 0 ); |
|
2607 } |
|
2608 } |
|
2609 |
|
2610 if ( iClockSource ) |
|
2611 { |
|
2612 TTime lSystemTime; |
|
2613 lSystemTime.UniversalTime(); |
|
2614 UpdateTime(); |
|
2615 iPeriodicTimer->Start( iPollingInterval, iPollingInterval, |
|
2616 TCallBack( CAriH264encHwDeviceImpl::TimerCallBack, ( TAny* )this ) ); |
|
2617 } |
|
2618 |
|
2619 iEngine->Start(); |
|
2620 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::Start() Change to " |
|
2621 " start state** ") ) ; |
|
2622 iEncStateMac->Transit( CStateMachine::EStartCommand ); |
|
2623 |
|
2624 PRINT_EXIT; |
|
2625 |
|
2626 } |
|
2627 |
|
2628 //---------------------------------------------------------------------------- |
|
2629 // Callback function to CPeriodicTimer object |
|
2630 //---------------------------------------------------------------------------- |
|
2631 // |
|
2632 TInt CAriH264encHwDeviceImpl::TimerCallBack( TAny* aPtr ) |
|
2633 { |
|
2634 PRINT_ENTRY; |
|
2635 if ( !aPtr ) |
|
2636 { |
|
2637 ( ( CAriH264encHwDeviceImpl* )aPtr )->ClientFatalError( |
|
2638 KErrArgument ); |
|
2639 return KErrNone; |
|
2640 } |
|
2641 PRINT_EXIT; |
|
2642 return ( ( CAriH264encHwDeviceImpl* )aPtr )->UpdateTime(); |
|
2643 } |
|
2644 |
|
2645 //---------------------------------------------------------------------------- |
|
2646 // Stops recording video. |
|
2647 //---------------------------------------------------------------------------- |
|
2648 // |
|
2649 void CAriH264encHwDeviceImpl::Stop() |
|
2650 { |
|
2651 PRINT_ENTRY; |
|
2652 |
|
2653 if( iEncStateMac->IsStopped() ) |
|
2654 { |
|
2655 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::Stop() -> already " |
|
2656 "in stop state, so ignore" ) ); |
|
2657 return; |
|
2658 } |
|
2659 |
|
2660 if( !iEncStateMac->IsTransitionValid( CStateMachine::EStopCommand ) ) |
|
2661 { |
|
2662 PRINT_MSG( LEVEL_CRITICAL, ("CAriH264encHwDeviceImpl::Stop() -> " |
|
2663 "fatalerror because Stop called in invalid state" ) ); |
|
2664 ClientFatalError( KErrPermissionDenied ); |
|
2665 return; |
|
2666 } |
|
2667 |
|
2668 iInputEndCalled = EFalse; |
|
2669 iIsSliceEnabledInCodedPicture = EFalse; |
|
2670 |
|
2671 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2672 { |
|
2673 // new clip started so config data has to be filled in first output |
|
2674 // buffer |
|
2675 iIsConfigDataFilledInFirstOutputBuffer = ETrue; |
|
2676 iTotalOutputBufferLengthInPacketMode = 0; |
|
2677 iTotalLengthFilledSoFarInPacketMode = 0; |
|
2678 iPacketsPending = EFalse; |
|
2679 } |
|
2680 |
|
2681 iEngine->Stop(); |
|
2682 iEngine->Reset(); |
|
2683 |
|
2684 iFrozen = EFalse; |
|
2685 if( iPeriodicTimer ) |
|
2686 { |
|
2687 iPeriodicTimer->Cancel(); |
|
2688 } |
|
2689 iEncStateMac->Transit( CStateMachine::EStopCommand ); |
|
2690 |
|
2691 PRINT_EXIT; |
|
2692 } |
|
2693 |
|
2694 //---------------------------------------------------------------------------- |
|
2695 // Pauses video recording |
|
2696 //---------------------------------------------------------------------------- |
|
2697 // |
|
2698 void CAriH264encHwDeviceImpl::Pause() |
|
2699 { |
|
2700 PRINT_ENTRY; |
|
2701 |
|
2702 if( iEncStateMac->IsPaused() ) |
|
2703 { |
|
2704 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::Pause()-> already" |
|
2705 "in Paused state, so ignore" ) ); |
|
2706 return; |
|
2707 } |
|
2708 |
|
2709 if( !iEncStateMac->IsTransitionValid( CStateMachine::EPauseCommand ) ) |
|
2710 { |
|
2711 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::Pause() Pause " |
|
2712 "called in invalid state" ) ); |
|
2713 ClientFatalError( KErrPermissionDenied ); |
|
2714 return; |
|
2715 } |
|
2716 |
|
2717 // No arguments to be passed in Pause |
|
2718 if( iClockSource ) |
|
2719 { |
|
2720 iPeriodicTimer->Cancel(); |
|
2721 //Note down the clock when paued |
|
2722 iClockTimeWhenPaused = iClockSource->Time().Int64(); |
|
2723 } |
|
2724 |
|
2725 // Stop the engine |
|
2726 iEngine->Stop(); |
|
2727 |
|
2728 //Change the state of the encoder |
|
2729 iEncStateMac->Transit( CStateMachine::EPauseCommand ); |
|
2730 |
|
2731 PRINT_EXIT; |
|
2732 } |
|
2733 |
|
2734 //---------------------------------------------------------------------------- |
|
2735 // Resumes video recording |
|
2736 //---------------------------------------------------------------------------- |
|
2737 // |
|
2738 void CAriH264encHwDeviceImpl::Resume() |
|
2739 { |
|
2740 PRINT_ENTRY; |
|
2741 |
|
2742 // doing it before transitionvalid check because initialize->resume is |
|
2743 // not added |
|
2744 if( iEncStateMac->IsInInitializedState() ) |
|
2745 { |
|
2746 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::Resume()->Got resume" |
|
2747 " in initialized state. So go to start()" ) ); |
|
2748 Start(); |
|
2749 return; |
|
2750 } |
|
2751 |
|
2752 if( iEncStateMac->IsPlaying() && !iEncStateMac->IsPaused() ) |
|
2753 { |
|
2754 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::Resume()->already in" |
|
2755 " playing-not-paused state, so ignore" ) ); |
|
2756 return; |
|
2757 } |
|
2758 |
|
2759 if( !iEncStateMac->IsTransitionValid( CStateMachine::EResumeCommand ) ) |
|
2760 { |
|
2761 PRINT_MSG( LEVEL_CRITICAL, ("Resume called in invalid state" ) ); |
|
2762 ClientFatalError( KErrPermissionDenied ); |
|
2763 return; |
|
2764 } |
|
2765 |
|
2766 // No arguments to be passed in Resume |
|
2767 if ( iClockSource ) |
|
2768 { |
|
2769 //Clock may or may not be paused, when HWDevice is paused, so |
|
2770 //add the paused duration to clock |
|
2771 iPauseOffset = iClockSource->Time().Int64(); |
|
2772 iPauseOffset -= iClockTimeWhenPaused; |
|
2773 |
|
2774 //calculate the total time and deviation |
|
2775 iTotalTime += iPauseOffset; |
|
2776 TTime lSystemTime; |
|
2777 lSystemTime.UniversalTime(); |
|
2778 |
|
2779 // Send Update time before sending Resume command, so that clock |
|
2780 // source is set before |
|
2781 |
|
2782 UpdateTime (); |
|
2783 iPeriodicTimer->Start( iPollingInterval, iPollingInterval, |
|
2784 TCallBack( CAriH264encHwDeviceImpl::TimerCallBack, ( TAny* )this ) ); |
|
2785 } |
|
2786 |
|
2787 // Start the engine |
|
2788 iEngine->Start(); |
|
2789 |
|
2790 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
2791 { |
|
2792 |
|
2793 // send the remaining pending packets to client |
|
2794 while ( iOutputFreeBufferQueue.Count() && iPacketsPending ) |
|
2795 { |
|
2796 TVideoOutputBuffer *outBuf = iOutputFreeBufferQueue[0]; |
|
2797 FillVideoSegment( outBuf, iInternalOutputBufferQueue[0] ); |
|
2798 iOutputFreeBufferQueue.Remove( 0 ); |
|
2799 |
|
2800 #ifdef CALCINSTANTBITRATE |
|
2801 CalculateInstantBitRate( *outBuf ); |
|
2802 #endif |
|
2803 |
|
2804 iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf ); |
|
2805 } |
|
2806 } |
|
2807 //Change the state of the encoder |
|
2808 iEncStateMac->Transit( CStateMachine::EResumeCommand ); |
|
2809 |
|
2810 PRINT_EXIT; |
|
2811 } |
|
2812 |
|
2813 //---------------------------------------------------------------------------- |
|
2814 // Freezes the input picture |
|
2815 //---------------------------------------------------------------------------- |
|
2816 // |
|
2817 void CAriH264encHwDeviceImpl::Freeze() |
|
2818 { |
|
2819 PRINT_ENTRY; |
|
2820 |
|
2821 if( !iEncStateMac->IsInitialized() ) |
|
2822 { |
|
2823 PRINT_MSG( LEVEL_CRITICAL, ("CAriH264encHwDeviceImpl::Freeze() Freeze" |
|
2824 " called in invalid state" ) ); |
|
2825 ClientFatalError( KErrNotReady ); |
|
2826 return; |
|
2827 } |
|
2828 iFrozen = ETrue; |
|
2829 |
|
2830 PRINT_EXIT; |
|
2831 } |
|
2832 |
|
2833 //---------------------------------------------------------------------------- |
|
2834 // Releases a frozen input picture |
|
2835 //---------------------------------------------------------------------------- |
|
2836 // |
|
2837 void CAriH264encHwDeviceImpl::ReleaseFreeze() |
|
2838 { |
|
2839 PRINT_ENTRY; |
|
2840 |
|
2841 if( !iEncStateMac->IsInitialized() ) |
|
2842 { |
|
2843 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::ReleaseFreeze() " |
|
2844 "called in invalid state" ) ); |
|
2845 ClientFatalError( KErrNotReady ); |
|
2846 return; |
|
2847 } |
|
2848 iFrozen = EFalse; |
|
2849 |
|
2850 PRINT_EXIT; |
|
2851 } |
|
2852 |
|
2853 //---------------------------------------------------------------------------- |
|
2854 // Returns the current recording position |
|
2855 //---------------------------------------------------------------------------- |
|
2856 // |
|
2857 TTimeIntervalMicroSeconds CAriH264encHwDeviceImpl::RecordingPosition() |
|
2858 { |
|
2859 PRINT_ENTRY; |
|
2860 |
|
2861 if( !iEncStateMac->IsInitialized() ) |
|
2862 { |
|
2863 PRINT_MSG( LEVEL_HIGH, ("CAriH264encHwDeviceImpl::RecordingPosition()" |
|
2864 " called in invalid state" ) ); |
|
2865 ClientFatalError( KErrNotReady ); |
|
2866 return TTimeIntervalMicroSeconds( 0 ); |
|
2867 } |
|
2868 |
|
2869 PRINT_EXIT; |
|
2870 return TTimeIntervalMicroSeconds( iLastEncodedPictureTimestamp ); |
|
2871 } |
|
2872 |
|
2873 //---------------------------------------------------------------------------- |
|
2874 // Reads various counters related to processed video pictures |
|
2875 //---------------------------------------------------------------------------- |
|
2876 // |
|
2877 void CAriH264encHwDeviceImpl::GetPictureCounters( |
|
2878 CMMFDevVideoRecord::TPictureCounters& aCounters ) |
|
2879 { |
|
2880 PRINT_ENTRY; |
|
2881 |
|
2882 if( !iEncStateMac->IsInitialized() ) |
|
2883 { |
|
2884 ClientFatalError( KErrNotReady ); |
|
2885 return; |
|
2886 } |
|
2887 TUint numofpacktsskipped; |
|
2888 TUint err = iCodec->GetParam( CONTROL_CMD_GET_PICTURES_SKIPPED, |
|
2889 &numofpacktsskipped ); |
|
2890 if ( err ) |
|
2891 { |
|
2892 ClientFatalError( err ); |
|
2893 return; |
|
2894 } |
|
2895 |
|
2896 iPictureCounters.iPicturesSkippedRateControl |
|
2897 = iPictureCounters.iPicturesSkippedRateControl + numofpacktsskipped; |
|
2898 |
|
2899 iPictureCounters.iPicturesProcessed |
|
2900 = iPictureCounters.iInputPictures |
|
2901 - iPictureCounters.iPicturesSkippedRateControl; |
|
2902 |
|
2903 aCounters = iPictureCounters; |
|
2904 |
|
2905 //reset the counters |
|
2906 iPictureCounters.iInputPictures = 0; |
|
2907 iPictureCounters.iPicturesSkippedRateControl = 0; |
|
2908 iPictureCounters.iPicturesProcessed = 0; |
|
2909 |
|
2910 PRINT_EXIT; |
|
2911 } |
|
2912 |
|
2913 //---------------------------------------------------------------------------- |
|
2914 // Reads the frame stabilisation output picture position. |
|
2915 //---------------------------------------------------------------------------- |
|
2916 // |
|
2917 void CAriH264encHwDeviceImpl::GetFrameStabilisationOutput( TRect&/* aRect*/ ) |
|
2918 { |
|
2919 PRINT_ENTRY; |
|
2920 PRINT_EXIT; |
|
2921 ClientFatalError( KErrNotSupported ); |
|
2922 } |
|
2923 |
|
2924 //---------------------------------------------------------------------------- |
|
2925 // Retrieves the number of complexity control levels available for this |
|
2926 // hardware device |
|
2927 //---------------------------------------------------------------------------- |
|
2928 // |
|
2929 TUint CAriH264encHwDeviceImpl::NumComplexityLevels() |
|
2930 { |
|
2931 PRINT_ENTRY; |
|
2932 |
|
2933 if( !iEncStateMac->IsInitialized() ) |
|
2934 { |
|
2935 ClientFatalError( KErrNotReady ); |
|
2936 return 0; |
|
2937 } |
|
2938 |
|
2939 PRINT_EXIT; |
|
2940 return( KH264ENCIMPL_NUM_COMPLEXITYLEVELS ); |
|
2941 } |
|
2942 |
|
2943 //---------------------------------------------------------------------------- |
|
2944 // Sets the complexity level to use for video processing in a hardware device |
|
2945 //---------------------------------------------------------------------------- |
|
2946 // |
|
2947 void CAriH264encHwDeviceImpl::SetComplexityLevel( TUint aLevel ) |
|
2948 { |
|
2949 PRINT_ENTRY; |
|
2950 |
|
2951 if( !iEncStateMac->IsInitialized() ) |
|
2952 { |
|
2953 ClientFatalError( KErrNotReady ); |
|
2954 return; |
|
2955 } |
|
2956 |
|
2957 if( aLevel >= KH264ENCIMPL_NUM_COMPLEXITYLEVELS ) |
|
2958 { |
|
2959 PRINT_MSG( LEVEL_CRITICAL, ("CAriH264encHwDeviceImpl" |
|
2960 "::SetComplexityLevel() Unsupported level Passed" ) ); |
|
2961 ClientFatalError( KErrArgument ); |
|
2962 } |
|
2963 |
|
2964 iH264EncInitParams.iComplexityLevel = aLevel; |
|
2965 TH264EncInitParams *currentParams = NULL; |
|
2966 TRAPD( error, currentParams = new( ELeave ) TH264EncInitParams ); |
|
2967 *currentParams = iH264EncInitParams; |
|
2968 |
|
2969 // Add command apply commit settings to the codec |
|
2970 TRAP( error, iEngine->AddCommandL( CBaseEngine::ENormalPriority, |
|
2971 CONTROL_CMD_SET_COMPLEXITY_LEVEL, currentParams ) ); |
|
2972 |
|
2973 if( error != KErrNone ) |
|
2974 { |
|
2975 delete currentParams; |
|
2976 ClientFatalError( error ); |
|
2977 return; |
|
2978 } |
|
2979 |
|
2980 PRINT_EXIT; |
|
2981 } |
|
2982 |
|
2983 //---------------------------------------------------------------------------- |
|
2984 // Retrieves information about the pre-processing capabilities of this |
|
2985 // hardware device. |
|
2986 //---------------------------------------------------------------------------- |
|
2987 // |
|
2988 CPreProcessorInfo* CAriH264encHwDeviceImpl::PreProcessorInfoLC() |
|
2989 { |
|
2990 PRINT_ENTRY; |
|
2991 |
|
2992 TInt cleanupstackpushcount = 0; |
|
2993 if( iEncStateMac->IsInitialized() ) |
|
2994 { |
|
2995 PRINT_ERR( "SetErrorProtectionLevelsL () called after Initialize()" |
|
2996 "..leaving" ); |
|
2997 User::Leave( KErrPermissionDenied ); |
|
2998 } |
|
2999 |
|
3000 _LIT( KManufacturer, "" ); |
|
3001 _LIT( KIdentifier, "" ); |
|
3002 |
|
3003 TPtrC8 implementationSpecificInfo( NULL,0 ); |
|
3004 RArray<TUncompressedVideoFormat> inputFormats; |
|
3005 CleanupClosePushL( inputFormats ); |
|
3006 cleanupstackpushcount++; |
|
3007 inputFormats.Reset(); |
|
3008 |
|
3009 RArray<TUncompressedVideoFormat> outputFormats; |
|
3010 CleanupClosePushL( outputFormats ); |
|
3011 cleanupstackpushcount++; |
|
3012 outputFormats.Reset(); |
|
3013 |
|
3014 RArray<TUint32> supportedCombinations; |
|
3015 CleanupClosePushL( supportedCombinations ); |
|
3016 cleanupstackpushcount++; |
|
3017 supportedCombinations.Reset(); |
|
3018 |
|
3019 RArray<TScaleFactor> supportedScaleFactors; |
|
3020 CleanupClosePushL( supportedScaleFactors ); |
|
3021 cleanupstackpushcount++; |
|
3022 supportedScaleFactors.Reset(); |
|
3023 |
|
3024 TYuvToYuvCapabilities yuvToYuvCapabilities; |
|
3025 TUid uid; |
|
3026 |
|
3027 CPreProcessorInfo *preProcessorInfo = CPreProcessorInfo::NewL( uid.Null(), |
|
3028 KManufacturer, |
|
3029 KIdentifier, |
|
3030 TVersion( 0,0,0 ), |
|
3031 EFalse, |
|
3032 EFalse, |
|
3033 inputFormats.Array(), |
|
3034 outputFormats.Array(), |
|
3035 supportedCombinations.Array(), |
|
3036 EFalse, |
|
3037 EFalse, |
|
3038 supportedScaleFactors.Array(), |
|
3039 yuvToYuvCapabilities, |
|
3040 0, |
|
3041 0, |
|
3042 implementationSpecificInfo ); |
|
3043 |
|
3044 CleanupStack::PushL( preProcessorInfo ); |
|
3045 CleanupStack::Pop( cleanupstackpushcount ); |
|
3046 |
|
3047 PRINT_EXIT; |
|
3048 return preProcessorInfo ; |
|
3049 } |
|
3050 |
|
3051 //---------------------------------------------------------------------------- |
|
3052 // Sets the hardware device input format |
|
3053 //---------------------------------------------------------------------------- |
|
3054 // |
|
3055 void CAriH264encHwDeviceImpl::SetInputFormatL( |
|
3056 const TUncompressedVideoFormat& aFormat, const TSize& aPictureSize ) |
|
3057 { |
|
3058 PRINT_ENTRY; |
|
3059 |
|
3060 if( iEncStateMac->IsInitialized() ) |
|
3061 { |
|
3062 PRINT_ERR( "SetInputFormatL () called after Initialize()..leaving" ); |
|
3063 User::Leave( KErrPermissionDenied ); |
|
3064 } |
|
3065 |
|
3066 if( !CheckInputFormat( aFormat ) ) |
|
3067 { |
|
3068 PRINT_ERR("CAriH264encHwDeviceImpl" |
|
3069 "::SetInputFormatL() Leaving because of not support input format" ); |
|
3070 User::Leave( KErrNotSupported ); |
|
3071 } |
|
3072 |
|
3073 // Check if passed size is supported by encoder |
|
3074 // Check if encoder supports the passed input format |
|
3075 // supports all sizes which are multiple of 16 pixels |
|
3076 |
|
3077 if ( ( !aPictureSize.iWidth ) || ( !aPictureSize.iHeight ) || |
|
3078 ( aPictureSize.iWidth % 16 ) || ( aPictureSize.iHeight % 16 ) || |
|
3079 ( aPictureSize.iWidth > KH264ENCIMPL_SDTV_WIDTH ) || |
|
3080 ( aPictureSize.iHeight > KH264ENCIMPL_SDTV_HEIGHT_PAL ) ) |
|
3081 { |
|
3082 PRINT_ERR( "Incorrect parameter passed.. leaving" ); |
|
3083 User::Leave( KErrNotSupported ); |
|
3084 } |
|
3085 |
|
3086 TInt32 aspectratio = ::MapAspectRatio( |
|
3087 aFormat.iYuvFormat.iAspectRatioNum, |
|
3088 aFormat.iYuvFormat.iAspectRatioDenom ); |
|
3089 |
|
3090 if ( aspectratio == -1 ) |
|
3091 { |
|
3092 PRINT_ERR( "Aspect ratio is -1.. leaving" ); |
|
3093 User::Leave( KErrNotSupported ); |
|
3094 } |
|
3095 |
|
3096 iH264EncInitParams.iAspectRatio = aspectratio; |
|
3097 iH264EncInitParams.iInputFormat = aFormat; |
|
3098 iH264EncInitParams.iPictureSize = aPictureSize; |
|
3099 iH264EncInitParams.iBeforeInitialize |= EEncInputFormat; |
|
3100 |
|
3101 PRINT_EXIT; |
|
3102 } |
|
3103 |
|
3104 //---------------------------------------------------------------------------- |
|
3105 // Sets the data source to be a camera, and sets the device to use direct |
|
3106 // capture for input. |
|
3107 //---------------------------------------------------------------------------- |
|
3108 // |
|
3109 void CAriH264encHwDeviceImpl::SetSourceCameraL( TInt /*aCameraHandle*/, |
|
3110 TReal /*aPictureRate*/ ) |
|
3111 { |
|
3112 PRINT_ENTRY; |
|
3113 |
|
3114 if( iEncStateMac->IsInitialized() ) |
|
3115 { |
|
3116 PRINT_ERR( "SetSourceCameraL() called after Initialize()..leaving" ); |
|
3117 User::Leave( KErrPermissionDenied ); |
|
3118 return; |
|
3119 } |
|
3120 |
|
3121 User::Leave( KErrNotSupported ); |
|
3122 PRINT_EXIT; |
|
3123 } |
|
3124 |
|
3125 //---------------------------------------------------------------------------- |
|
3126 // Sets the data source to be memory buffers. |
|
3127 //---------------------------------------------------------------------------- |
|
3128 // |
|
3129 void CAriH264encHwDeviceImpl::SetSourceMemoryL( TReal aMaxPictureRate, |
|
3130 TBool aConstantPictureRate, |
|
3131 TBool aProcessRealtime ) |
|
3132 { |
|
3133 PRINT_ENTRY; |
|
3134 |
|
3135 if( iEncStateMac->IsInitialized() ) |
|
3136 { |
|
3137 PRINT_ERR( "SetSourceMemoryL() called after Initialize()..leaving" ); |
|
3138 User::Leave( KErrPermissionDenied ); |
|
3139 return; |
|
3140 } |
|
3141 |
|
3142 if( ( aMaxPictureRate <= 0 ) || |
|
3143 ( aMaxPictureRate > KH264ENCIMPL_MAX_PICTURERATE ) ) |
|
3144 { |
|
3145 PRINT_ERR( "Incorrect value of max picture rate..leaving" ); |
|
3146 User::Leave( KErrNotSupported ); |
|
3147 return; |
|
3148 } |
|
3149 |
|
3150 // Check for the picture rates supported |
|
3151 PRINT_MSG( LEVEL_LOW, ( "CAriH264encHwDeviceImpl::SetSourceMemoryL() " |
|
3152 "Memory Picture rate is set as %f", aMaxPictureRate ) ); |
|
3153 |
|
3154 iH264EncInitParams.iMaxPictureRate = aMaxPictureRate; |
|
3155 iH264EncInitParams.iConstantPictureRate = aConstantPictureRate; |
|
3156 iH264EncInitParams.iProcessRealtime = aProcessRealtime; |
|
3157 iH264EncInitParams.iBeforeInitialize |= EEncSourceMemory; |
|
3158 |
|
3159 PRINT_EXIT; |
|
3160 } |
|
3161 |
|
3162 |
|
3163 //---------------------------------------------------------------------------- |
|
3164 // Sets the clock source to use for video timing. If no clock |
|
3165 // source is set. video encoding will not be synchronized, but |
|
3166 // will proceed as fast as possible, depending on input data and |
|
3167 // output buffer availability. |
|
3168 //---------------------------------------------------------------------------- |
|
3169 // |
|
3170 |
|
3171 void CAriH264encHwDeviceImpl::SetClockSource( MMMFClockSource* aClock ) |
|
3172 { |
|
3173 PRINT_ENTRY; |
|
3174 |
|
3175 if( iEncStateMac->IsInitialized() ) |
|
3176 { |
|
3177 ClientFatalError( KErrPermissionDenied ); |
|
3178 return; |
|
3179 } |
|
3180 |
|
3181 if( !aClock ) |
|
3182 { |
|
3183 ClientFatalError( KErrArgument ); |
|
3184 return; |
|
3185 } |
|
3186 |
|
3187 PRINT_MSG( LEVEL_LOW, ( " CAriH264encHwDeviceImpl::SetClockSource() " |
|
3188 "encoder clockSource is %x", ( TInt ) aClock ) ); |
|
3189 |
|
3190 iClockSource = aClock; |
|
3191 |
|
3192 PRINT_EXIT; |
|
3193 } |
|
3194 |
|
3195 //---------------------------------------------------------------------------- |
|
3196 // Sets pre-processing options for RGB to YUV color space conversion |
|
3197 //---------------------------------------------------------------------------- |
|
3198 // |
|
3199 |
|
3200 void CAriH264encHwDeviceImpl::SetRgbToYuvOptionsL( TRgbRange /*aRange*/, |
|
3201 const TYuvFormat& /*aOutputFormat*/ ) |
|
3202 { |
|
3203 PRINT_ENTRY; |
|
3204 PRINT_ERR( "SetRgbToYuvOptionsL not supported...leaving \n" ); |
|
3205 PRINT_EXIT; |
|
3206 User::Leave( KErrNotSupported ); |
|
3207 } |
|
3208 |
|
3209 //---------------------------------------------------------------------------- |
|
3210 // Sets pre-processing options for YUV to YUV data format conversion |
|
3211 //---------------------------------------------------------------------------- |
|
3212 // |
|
3213 |
|
3214 void CAriH264encHwDeviceImpl::SetYuvToYuvOptionsL( |
|
3215 const TYuvFormat& /*aInputFormat*/, |
|
3216 const TYuvFormat& /*aOutputFormat*/ ) |
|
3217 { |
|
3218 PRINT_ENTRY; |
|
3219 PRINT_ERR( "SetYuvToYuvOptionsL not supported...leaving \n" ); |
|
3220 PRINT_EXIT; |
|
3221 User::Leave( KErrNotSupported ); |
|
3222 } |
|
3223 |
|
3224 //---------------------------------------------------------------------------- |
|
3225 // Sets the pre-processing types to be used in a hardware device |
|
3226 //---------------------------------------------------------------------------- |
|
3227 // |
|
3228 |
|
3229 void CAriH264encHwDeviceImpl::SetPreProcessTypesL( |
|
3230 TUint32 /*aPreProcessTypes*/ ) |
|
3231 { |
|
3232 PRINT_ENTRY; |
|
3233 PRINT_ERR( "SetPreProcessTypesL not supported...leaving \n" ); |
|
3234 PRINT_EXIT; |
|
3235 User::Leave( KErrNotSupported ); |
|
3236 } |
|
3237 |
|
3238 //---------------------------------------------------------------------------- |
|
3239 // Sets pre-processing options for rotation |
|
3240 //---------------------------------------------------------------------------- |
|
3241 // |
|
3242 |
|
3243 void CAriH264encHwDeviceImpl::SetRotateOptionsL( |
|
3244 TRotationType /*aRotationType*/ ) |
|
3245 { |
|
3246 PRINT_ENTRY; |
|
3247 PRINT_ERR( "SetRotateOptionsL not supported...leaving \n" ); |
|
3248 PRINT_EXIT; |
|
3249 User::Leave( KErrNotSupported ); |
|
3250 } |
|
3251 |
|
3252 //---------------------------------------------------------------------------- |
|
3253 // Sets pre-processing options for scaling |
|
3254 //---------------------------------------------------------------------------- |
|
3255 // |
|
3256 |
|
3257 void CAriH264encHwDeviceImpl::SetScaleOptionsL( const TSize& /*aTargetSize*/, |
|
3258 TBool /*aAntiAliasFiltering*/ ) |
|
3259 { |
|
3260 PRINT_ENTRY; |
|
3261 PRINT_ERR( "SetScaleOptionsL not supported...leaving \n" ); |
|
3262 PRINT_EXIT; |
|
3263 User::Leave( KErrNotSupported ); |
|
3264 } |
|
3265 |
|
3266 //---------------------------------------------------------------------------- |
|
3267 // Sets pre-processing options for input cropping |
|
3268 //---------------------------------------------------------------------------- |
|
3269 // |
|
3270 |
|
3271 void CAriH264encHwDeviceImpl::SetInputCropOptionsL( const TRect& /*aRect*/ ) |
|
3272 { |
|
3273 PRINT_ENTRY; |
|
3274 PRINT_ERR( "SetInputCropOptionsL not supported...leaving \n" ); |
|
3275 PRINT_EXIT; |
|
3276 User::Leave( KErrNotSupported ); |
|
3277 } |
|
3278 |
|
3279 //---------------------------------------------------------------------------- |
|
3280 // Sets pre-processing options for output cropping |
|
3281 //---------------------------------------------------------------------------- |
|
3282 // |
|
3283 |
|
3284 void CAriH264encHwDeviceImpl::SetOutputCropOptionsL( const TRect& /*aRect*/ ) |
|
3285 { |
|
3286 PRINT_ENTRY; |
|
3287 PRINT_ERR( "SetOutputCropOptionsL not supported...leaving \n" ); |
|
3288 PRINT_EXIT; |
|
3289 User::Leave( KErrNotSupported ); |
|
3290 } |
|
3291 |
|
3292 //---------------------------------------------------------------------------- |
|
3293 // Sets pre-processing options for output padding |
|
3294 //---------------------------------------------------------------------------- |
|
3295 // |
|
3296 |
|
3297 void CAriH264encHwDeviceImpl::SetOutputPadOptionsL( |
|
3298 const TSize& /*aOutputSize*/, const TPoint& /*aPicturePos*/ ) |
|
3299 { |
|
3300 PRINT_ENTRY; |
|
3301 PRINT_ERR( "SetOutputPadOptionsL not supported...leaving \n" ); |
|
3302 PRINT_EXIT; |
|
3303 User::Leave( KErrNotSupported ); |
|
3304 } |
|
3305 |
|
3306 //---------------------------------------------------------------------------- |
|
3307 // Sets color enhancement pre-processing options |
|
3308 //---------------------------------------------------------------------------- |
|
3309 // |
|
3310 |
|
3311 void CAriH264encHwDeviceImpl::SetColorEnhancementOptionsL( |
|
3312 const TColorEnhancementOptions& /*aOptions*/ ) |
|
3313 { |
|
3314 PRINT_ENTRY; |
|
3315 PRINT_ERR( "SetColorEnhancementOptionsL not supported...leaving \n" ); |
|
3316 PRINT_EXIT; |
|
3317 User::Leave( KErrNotSupported ); |
|
3318 } |
|
3319 |
|
3320 //---------------------------------------------------------------------------- |
|
3321 // Sets frame stabilisation options |
|
3322 //---------------------------------------------------------------------------- |
|
3323 // |
|
3324 |
|
3325 void CAriH264encHwDeviceImpl::SetFrameStabilisationOptionsL( |
|
3326 const TSize& /*aOutputSize*/, TBool /*aFrameStabilisation*/ ) |
|
3327 { |
|
3328 PRINT_ENTRY; |
|
3329 PRINT_ERR( "SetFrameStabilisationOptionsL not supported...leaving \n" ); |
|
3330 PRINT_EXIT; |
|
3331 User::Leave( KErrNotSupported ); |
|
3332 } |
|
3333 |
|
3334 //---------------------------------------------------------------------------- |
|
3335 // Sets custom implementation-specific pre-processing options. |
|
3336 //---------------------------------------------------------------------------- |
|
3337 // |
|
3338 void CAriH264encHwDeviceImpl::SetCustomPreProcessOptionsL( |
|
3339 const TDesC8& /*aOptions*/) |
|
3340 { |
|
3341 PRINT_ENTRY; |
|
3342 PRINT_ERR( "SetCustomPreProcessOptionsL not supported...leaving \n" ); |
|
3343 PRINT_EXIT; |
|
3344 User::Leave( KErrNotSupported ); |
|
3345 } |
|
3346 |
|
3347 //---------------------------------------------------------------------------- |
|
3348 // Proxy which recieves callbacks from Hw Device |
|
3349 //---------------------------------------------------------------------------- |
|
3350 // |
|
3351 |
|
3352 void CAriH264encHwDeviceImpl::SetProxy( MMMFDevVideoRecordProxy& aProxy ) |
|
3353 { |
|
3354 PRINT_ENTRY; |
|
3355 |
|
3356 if( iEncStateMac->IsInitialized() ) |
|
3357 { |
|
3358 ClientFatalError( KErrPermissionDenied ); |
|
3359 return ; |
|
3360 } |
|
3361 iMMFDevVideoRecordProxy = &aProxy; |
|
3362 |
|
3363 PRINT_EXIT; |
|
3364 } |
|
3365 |
|
3366 |
|
3367 //---------------------------------------------------------------------------- |
|
3368 // Callback to indicate the input buffer is consumed |
|
3369 //---------------------------------------------------------------------------- |
|
3370 // |
|
3371 |
|
3372 TInt CAriH264encHwDeviceImpl::InputBufferConsumed ( TAny* aInp, TInt aError ) |
|
3373 { |
|
3374 PRINT_ENTRY; |
|
3375 |
|
3376 if( !aInp ) |
|
3377 { |
|
3378 return KErrArgument; |
|
3379 } |
|
3380 |
|
3381 TVideoPicture *picture = (TVideoPicture *) aInp; |
|
3382 if( ( picture->iOptions & TVideoPicture::ETimestamp ) |
|
3383 && aError != ( KErrCancel ) ) |
|
3384 { |
|
3385 iLastEncodedPictureTimestamp = picture->iTimestamp.Int64(); |
|
3386 } |
|
3387 |
|
3388 // if custom buffer emabled then add it to queue else return the picture |
|
3389 // to client |
|
3390 if ( !iInputBufReturnToPreProc ) |
|
3391 { |
|
3392 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
3393 "::InputBufferConsumed()-return picture back to client" ) ); |
|
3394 |
|
3395 iMMFDevVideoRecordProxy->MdvrpReturnPicture( picture ); |
|
3396 } |
|
3397 else |
|
3398 { |
|
3399 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
3400 "::InputBufferConsumed()-return picture back to Input Device" ) ); |
|
3401 iInputDevice->ReturnPicture( picture ); |
|
3402 } |
|
3403 |
|
3404 if ( iInputEndCalled && ( iEngine->NumInputBuffers() == 0 ) |
|
3405 && ( iCodec->IsCurrentPictureSkipped() ) ) |
|
3406 { |
|
3407 PRINT_MSG( LEVEL_HIGH, ("CAriH264encHwDeviceImpl" |
|
3408 "::InputBufferConsumed()::Calling stream end " ) ); |
|
3409 Stop(); |
|
3410 iMMFDevVideoRecordProxy->MdvrpStreamEnd(); |
|
3411 return( KErrNone ); |
|
3412 } |
|
3413 |
|
3414 PRINT_EXIT; |
|
3415 return KErrNone; |
|
3416 } |
|
3417 |
|
3418 //---------------------------------------------------------------------------- |
|
3419 // Callback to indicate the output buffer is ready |
|
3420 //---------------------------------------------------------------------------- |
|
3421 // |
|
3422 |
|
3423 TInt CAriH264encHwDeviceImpl::OutputBufferReady ( TAny* aOup, TInt aError ) |
|
3424 { |
|
3425 PRINT_ENTRY; |
|
3426 |
|
3427 TVideoOutputBuffer *outputBuf = ( TVideoOutputBuffer* ) aOup; |
|
3428 TInt error = KErrNone; |
|
3429 TInt length = outputBuf->iData.Length(); |
|
3430 |
|
3431 if (iFrozen) |
|
3432 { |
|
3433 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::OutputBufferReady() " |
|
3434 "Frozen state, so drop output picture" ) ); |
|
3435 outputBuf->iData.Set( ( TUint8* )outputBuf->iData.Ptr() |
|
3436 ,iOutputBufferSize ); |
|
3437 iEngine->AddOutput( outputBuf ); |
|
3438 return KErrNone; |
|
3439 } |
|
3440 |
|
3441 if( aError == KErrNone ) |
|
3442 { |
|
3443 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
3444 { |
|
3445 error = iInternalOutputBufferQueue.Append( outputBuf ); |
|
3446 if ( error != KErrNone ) |
|
3447 { |
|
3448 ClientFatalError ( error ); |
|
3449 return KErrNone; |
|
3450 } |
|
3451 |
|
3452 // get the packet offset infor |
|
3453 error = iCodec->GetParam( CONTROL_CMD_GET_PACKET_OFFSET_DATA, |
|
3454 iFreeBufferQueueForPacketOffsetInfo[0] ); |
|
3455 if ( error != KErrNone ) |
|
3456 { |
|
3457 ClientFatalError( error ); |
|
3458 return KErrNone; |
|
3459 } |
|
3460 |
|
3461 //remove the first element and add it to filled Queue |
|
3462 TUint* filledOffsetLengthInfoBuffer |
|
3463 = iFreeBufferQueueForPacketOffsetInfo[0]; |
|
3464 iFreeBufferQueueForPacketOffsetInfo.Remove( 0 ); |
|
3465 error = iFilledBufferQueueForPacketOffsetInfo.Append( |
|
3466 filledOffsetLengthInfoBuffer ); |
|
3467 if ( error != KErrNone ) |
|
3468 { |
|
3469 ClientFatalError( error ); |
|
3470 return KErrNone; |
|
3471 } |
|
3472 |
|
3473 if ( !iTotalLengthFilledSoFarInPacketMode ) |
|
3474 { |
|
3475 iTotalOutputBufferLengthInPacketMode |
|
3476 = iInternalOutputBufferQueue[0]->iData.Length(); |
|
3477 iPacketOffSetCurrentPosition |
|
3478 = iFilledBufferQueueForPacketOffsetInfo[0]; |
|
3479 iPacketsPending = ETrue; |
|
3480 |
|
3481 while ( iOutputFreeBufferQueue.Count() && iPacketsPending ) |
|
3482 { |
|
3483 TVideoOutputBuffer *outBuf = iOutputFreeBufferQueue[0]; |
|
3484 FillVideoSegment( outBuf, iInternalOutputBufferQueue[0] ); |
|
3485 iOutputFreeBufferQueue.Remove( 0 ); |
|
3486 |
|
3487 #ifdef CALCINSTANTBITRATE |
|
3488 CalculateInstantBitRate( *outBuf ); |
|
3489 #endif |
|
3490 |
|
3491 iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf ); |
|
3492 } |
|
3493 } |
|
3494 TInt ts |
|
3495 = ( TInt ) ( ( outputBuf->iCaptureTimestamp ).Int64() / 1000 ); |
|
3496 iSizePerFrame = 0; |
|
3497 } |
|
3498 else |
|
3499 { |
|
3500 #ifdef CALCINSTANTBITRATE |
|
3501 CalculateInstantBitRate( *outputBuf ); |
|
3502 #endif |
|
3503 |
|
3504 iSizePerFrame = outputBuf->iData.Length(); |
|
3505 iSizePerFrame = 0 ; |
|
3506 // inform devvideo record that the new encoded buffer is |
|
3507 // avaibable |
|
3508 iMMFDevVideoRecordProxy->MdvrpNewBuffer( outputBuf ); |
|
3509 } |
|
3510 iNoOfOutputFramesPerSec++; |
|
3511 } |
|
3512 |
|
3513 else if ( aError == KErrCancel ) |
|
3514 { |
|
3515 // add the buffer back to outputQueue |
|
3516 outputBuf->iData.Set( ( TUint8* )outputBuf->iData.Ptr(), |
|
3517 iOutputBufferSize ); |
|
3518 |
|
3519 if ( iH264EncInitParams.iDataUnitType == EDuVideoSegment ) |
|
3520 { |
|
3521 error = iInternalOutputBufferQueue.Append( outputBuf ); |
|
3522 if ( error != KErrNone ) |
|
3523 { |
|
3524 ClientFatalError( error ); |
|
3525 return KErrNone; |
|
3526 } |
|
3527 } |
|
3528 else |
|
3529 { |
|
3530 error = iOutputFreeBufferQueue.Append( outputBuf ); |
|
3531 if ( error != KErrNone ) |
|
3532 { |
|
3533 ClientFatalError( error ); |
|
3534 return KErrNone; |
|
3535 } |
|
3536 } |
|
3537 |
|
3538 if ( error != KErrNone ) |
|
3539 { |
|
3540 ClientFatalError( error ); |
|
3541 return KErrNone; |
|
3542 } |
|
3543 } |
|
3544 else |
|
3545 { |
|
3546 ClientFatalError( aError ); |
|
3547 return KErrNone; |
|
3548 } |
|
3549 |
|
3550 if ( iInputEndCalled && ( iEngine->NumInputBuffers() == 0 ) ) |
|
3551 { |
|
3552 PRINT_MSG( LEVEL_HIGH, ("CAriH264encHwDeviceImpl" |
|
3553 "::OutputBufferReady()::Calling stream end " ) ); |
|
3554 Stop(); |
|
3555 iMMFDevVideoRecordProxy->MdvrpStreamEnd(); |
|
3556 return( KErrNone ); |
|
3557 } |
|
3558 |
|
3559 PRINT_EXIT; |
|
3560 return KErrNone; |
|
3561 } |
|
3562 |
|
3563 //---------------------------------------------------------------------------- |
|
3564 // Callback to indicate the command has been processed |
|
3565 //---------------------------------------------------------------------------- |
|
3566 // |
|
3567 |
|
3568 void CAriH264encHwDeviceImpl::CommandProcessed ( TInt aCmd, TAny* aCmdData, |
|
3569 TInt aError ) |
|
3570 { |
|
3571 PRINT_ENTRY; |
|
3572 |
|
3573 switch( aCmd ) |
|
3574 { |
|
3575 case CONTROL_CMD_SET_RATE_CONTROL_OPTIONS: |
|
3576 { |
|
3577 TRateControlOptions *options = ( TRateControlOptions* ) aCmdData; |
|
3578 delete options; |
|
3579 } |
|
3580 break; |
|
3581 |
|
3582 case CONTROL_CMD_SET_FORCED_I_FRAME: |
|
3583 { |
|
3584 } |
|
3585 break; |
|
3586 |
|
3587 case CONTROL_CMD_SET_COMMIT_OPTIONS: |
|
3588 { |
|
3589 TH264EncInitParams *currentParams |
|
3590 = ( TH264EncInitParams* ) aCmdData; |
|
3591 if( ( aError != KErrNone ) || ( aError != KErrCancel ) ) |
|
3592 { |
|
3593 delete currentParams; |
|
3594 return; |
|
3595 } |
|
3596 else{ |
|
3597 iH264EncInitParams.iBitErrors |
|
3598 = currentParams->iBitErrors; |
|
3599 iH264EncInitParams.iPacketLosses |
|
3600 = currentParams->iPacketLosses; |
|
3601 iH264EncInitParams.iRandomAccessRate |
|
3602 = currentParams->iRandomAccessRate; |
|
3603 |
|
3604 delete currentParams; |
|
3605 } |
|
3606 } |
|
3607 break; |
|
3608 |
|
3609 case CONTROL_CMD_SET_COMPLEXITY_LEVEL: |
|
3610 { |
|
3611 TH264EncInitParams *currentParams |
|
3612 = ( TH264EncInitParams* ) aCmdData; |
|
3613 delete currentParams; |
|
3614 } |
|
3615 break; |
|
3616 |
|
3617 case CONTROL_CMD_SET_CHANNEL_BIT_ERROR_RATE: |
|
3618 { |
|
3619 TReal* currentParams = ( TReal* )aCmdData; |
|
3620 delete currentParams; |
|
3621 } |
|
3622 break; |
|
3623 |
|
3624 case CONTROL_CMD_SET_SLICELOSS: |
|
3625 { |
|
3626 TH264EncSliceLoss* currentParams |
|
3627 = ( TH264EncSliceLoss* )aCmdData; |
|
3628 delete currentParams; |
|
3629 } |
|
3630 break; |
|
3631 |
|
3632 default: |
|
3633 break; |
|
3634 } |
|
3635 PRINT_EXIT; |
|
3636 return; |
|
3637 } |
|
3638 |
|
3639 //---------------------------------------------------------------------------- |
|
3640 // Called when a fatal error occurs in process engine |
|
3641 //---------------------------------------------------------------------------- |
|
3642 // |
|
3643 |
|
3644 void CAriH264encHwDeviceImpl::FatalErrorFromProcessEngine( TInt aError ) |
|
3645 { |
|
3646 PRINT_ENTRY; |
|
3647 |
|
3648 ClientFatalError( aError ); |
|
3649 |
|
3650 PRINT_EXIT; |
|
3651 } |
|
3652 |
|
3653 |
|
3654 //---------------------------------------------------------------------------- |
|
3655 // Enables inserting H324 pre-defined config data (VOL / SPS / PPS / etc. ) |
|
3656 //---------------------------------------------------------------------------- |
|
3657 // |
|
3658 |
|
3659 TInt CAriH264encHwDeviceImpl::H324AnnexKDefinedEncoderConfigDataOn() |
|
3660 { |
|
3661 PRINT_ENTRY; |
|
3662 |
|
3663 if( iEncStateMac->IsInitialized() ) |
|
3664 { |
|
3665 PRINT_MSG( LEVEL_LOW, ("Not permitted as the encoder is already " |
|
3666 "initialised" ) ); |
|
3667 return KErrNotReady; |
|
3668 } |
|
3669 iH264EncInitParams.iVTFastCallSetUp = ETrue; |
|
3670 |
|
3671 PRINT_EXIT; |
|
3672 return KErrNone; |
|
3673 } |
|
3674 |
|
3675 |
|
3676 //---------------------------------------------------------------------------- |
|
3677 // 2 phase constructor |
|
3678 //---------------------------------------------------------------------------- |
|
3679 // |
|
3680 void CAriH264encHwDeviceImpl::ConstructL() |
|
3681 { |
|
3682 PRINT_ENTRY; |
|
3683 |
|
3684 TInt error = KErrNone; |
|
3685 |
|
3686 // Create Array of Supported Input Formats |
|
3687 TUncompressedVideoFormat inputFormat; |
|
3688 |
|
3689 inputFormat.iDataFormat = EYuvRawData; |
|
3690 inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range0; |
|
3691 inputFormat.iYuvFormat.iPattern = EYuv420Chroma1; |
|
3692 inputFormat.iYuvFormat.iDataLayout = EYuvDataPlanar; |
|
3693 inputFormat.iYuvFormat.iYuv2RgbMatrix = NULL; |
|
3694 inputFormat.iYuvFormat.iRgb2YuvMatrix = NULL; |
|
3695 inputFormat.iYuvFormat.iAspectRatioNum = 1; |
|
3696 inputFormat.iYuvFormat.iAspectRatioDenom = 1; |
|
3697 error = iSupportedInputFormats.Append( inputFormat ); |
|
3698 if( error != KErrNone ) |
|
3699 { |
|
3700 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3701 User::Leave( error ); |
|
3702 } |
|
3703 |
|
3704 inputFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
3705 error = iSupportedInputFormats.Append( inputFormat ); |
|
3706 if( error != KErrNone ) |
|
3707 { |
|
3708 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3709 User::Leave( error ); |
|
3710 } |
|
3711 |
|
3712 inputFormat.iYuvFormat.iPattern = EYuv420Chroma3; |
|
3713 error = iSupportedInputFormats.Append( inputFormat ); |
|
3714 if( error != KErrNone ) |
|
3715 { |
|
3716 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3717 User::Leave( error ); |
|
3718 } |
|
3719 |
|
3720 inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range1; |
|
3721 inputFormat.iYuvFormat.iPattern = EYuv420Chroma1; |
|
3722 error = iSupportedInputFormats.Append( inputFormat ); |
|
3723 if( error != KErrNone ) |
|
3724 { |
|
3725 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3726 User::Leave( error ); |
|
3727 } |
|
3728 |
|
3729 inputFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
3730 error = iSupportedInputFormats.Append( inputFormat ); |
|
3731 if( error != KErrNone ) |
|
3732 { |
|
3733 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3734 User::Leave( error ); |
|
3735 } |
|
3736 |
|
3737 inputFormat.iYuvFormat.iPattern = EYuv420Chroma3; |
|
3738 error = iSupportedInputFormats.Append( inputFormat ); |
|
3739 if( error != KErrNone ) |
|
3740 { |
|
3741 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3742 User::Leave( error ); |
|
3743 } |
|
3744 |
|
3745 |
|
3746 inputFormat.iYuvFormat.iCoefficients = EYuvBt601Range0; |
|
3747 inputFormat.iYuvFormat.iPattern = EYuv420Chroma1; |
|
3748 error = iSupportedInputFormats.Append( inputFormat ); |
|
3749 if( error != KErrNone ) |
|
3750 { |
|
3751 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3752 User::Leave( error ); |
|
3753 } |
|
3754 |
|
3755 inputFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
3756 error = iSupportedInputFormats.Append( inputFormat ); |
|
3757 if( error != KErrNone ) |
|
3758 { |
|
3759 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3760 User::Leave( error ); |
|
3761 } |
|
3762 |
|
3763 inputFormat.iYuvFormat.iPattern = EYuv420Chroma3; |
|
3764 error = iSupportedInputFormats.Append( inputFormat ); |
|
3765 if( error != KErrNone ) |
|
3766 { |
|
3767 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3768 User::Leave( error ); |
|
3769 } |
|
3770 |
|
3771 inputFormat.iYuvFormat.iCoefficients = EYuvBt601Range1; |
|
3772 inputFormat.iYuvFormat.iPattern = EYuv420Chroma1; |
|
3773 error = iSupportedInputFormats.Append( inputFormat ); |
|
3774 if( error != KErrNone ) |
|
3775 { |
|
3776 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3777 User::Leave( error ); |
|
3778 } |
|
3779 |
|
3780 inputFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
3781 error = iSupportedInputFormats.Append( inputFormat ); |
|
3782 if( error != KErrNone ) |
|
3783 { |
|
3784 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3785 User::Leave( error ); |
|
3786 } |
|
3787 |
|
3788 inputFormat.iYuvFormat.iPattern = EYuv420Chroma3; |
|
3789 error = iSupportedInputFormats.Append( inputFormat ); |
|
3790 if( error != KErrNone ) |
|
3791 { |
|
3792 PRINT_ERR( "Error while appending input format...leaving \n" ); |
|
3793 User::Leave( error ); |
|
3794 } |
|
3795 |
|
3796 // Create Array of Supported Output Formats |
|
3797 CCompressedVideoFormat* compressedVideoFormat = |
|
3798 CCompressedVideoFormat::NewL( KH264MimeType ); |
|
3799 |
|
3800 CleanupStack::PushL( compressedVideoFormat ); |
|
3801 error = iSupportedOutputFormats.Append( compressedVideoFormat ); |
|
3802 if( error != KErrNone ) |
|
3803 { |
|
3804 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3805 User::Leave( error ); |
|
3806 } |
|
3807 CleanupStack::Pop(); |
|
3808 |
|
3809 // unknown level is set for short mime type - decide in initialize |
|
3810 error = iLevels.Append( KH264ENCIMPL_LEVEL_UNKNOWN ); |
|
3811 if( error != KErrNone ) |
|
3812 { |
|
3813 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3814 User::Leave( error ); |
|
3815 } |
|
3816 |
|
3817 // Level 1 |
|
3818 CCompressedVideoFormat* compressedVideoFormat2 = |
|
3819 CCompressedVideoFormat::NewL( KH264MimeType2 ); |
|
3820 |
|
3821 CleanupStack::PushL( compressedVideoFormat2 ); |
|
3822 error = iSupportedOutputFormats.Append( compressedVideoFormat2 ); |
|
3823 if( error != KErrNone ) |
|
3824 { |
|
3825 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3826 User::Leave( error ); |
|
3827 } |
|
3828 CleanupStack::Pop(); |
|
3829 |
|
3830 error = iLevels.Append( KH264ENCIMPL_LEVEL_1 ); |
|
3831 if( error != KErrNone ) |
|
3832 { |
|
3833 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3834 User::Leave( error ); |
|
3835 } |
|
3836 |
|
3837 // Level 1.1 |
|
3838 // Bitrate and level will be decided in Initialize |
|
3839 CCompressedVideoFormat* compressedVideoFormat3 = |
|
3840 CCompressedVideoFormat::NewL( KH264MimeType3 ); |
|
3841 |
|
3842 CleanupStack::PushL( compressedVideoFormat3 ); |
|
3843 error = iSupportedOutputFormats.Append( compressedVideoFormat3 ); |
|
3844 if( error != KErrNone ) |
|
3845 { |
|
3846 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3847 User::Leave( error ); |
|
3848 } |
|
3849 CleanupStack::Pop(); |
|
3850 |
|
3851 error = iLevels.Append( KH264ENCIMPL_LEVEL_11 ); |
|
3852 if( error != KErrNone ) |
|
3853 { |
|
3854 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3855 User::Leave( error ); |
|
3856 } |
|
3857 |
|
3858 // Level 1.2 |
|
3859 CCompressedVideoFormat* compressedVideoFormat4 = |
|
3860 CCompressedVideoFormat::NewL( KH264MimeType4 ); |
|
3861 |
|
3862 CleanupStack::PushL( compressedVideoFormat4 ); |
|
3863 error = iSupportedOutputFormats.Append( compressedVideoFormat4 ); |
|
3864 if( error != KErrNone ) |
|
3865 { |
|
3866 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3867 User::Leave( error ); |
|
3868 } |
|
3869 CleanupStack::Pop(); |
|
3870 |
|
3871 error = iLevels.Append( KH264ENCIMPL_LEVEL_12 ); |
|
3872 if( error != KErrNone ) |
|
3873 { |
|
3874 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3875 User::Leave( error ); |
|
3876 } |
|
3877 |
|
3878 // Level 1.3 |
|
3879 CCompressedVideoFormat* compressedVideoFormat5 = |
|
3880 CCompressedVideoFormat::NewL( KH264MimeType5 ); |
|
3881 |
|
3882 CleanupStack::PushL( compressedVideoFormat5 ); |
|
3883 error = iSupportedOutputFormats.Append( compressedVideoFormat5 ); |
|
3884 if( error != KErrNone ) |
|
3885 { |
|
3886 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3887 User::Leave( error ); |
|
3888 } |
|
3889 CleanupStack::Pop(); |
|
3890 |
|
3891 error = iLevels.Append( KH264ENCIMPL_LEVEL_13 ); |
|
3892 if( error != KErrNone ) |
|
3893 { |
|
3894 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3895 User::Leave( error ); |
|
3896 } |
|
3897 |
|
3898 // Level 2 |
|
3899 CCompressedVideoFormat* compressedVideoFormat6 = |
|
3900 CCompressedVideoFormat::NewL( KH264MimeType6 ); |
|
3901 |
|
3902 CleanupStack::PushL( compressedVideoFormat6 ); |
|
3903 |
|
3904 error = iSupportedOutputFormats.Append( compressedVideoFormat6 ); |
|
3905 if( error != KErrNone ) |
|
3906 { |
|
3907 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3908 User::Leave( error ); |
|
3909 } |
|
3910 CleanupStack::Pop(); |
|
3911 |
|
3912 error = iLevels.Append( KH264ENCIMPL_LEVEL_2 ); |
|
3913 if( error != KErrNone ) |
|
3914 { |
|
3915 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3916 User::Leave( error ); |
|
3917 } |
|
3918 |
|
3919 // Level 2.1 |
|
3920 CCompressedVideoFormat* compressedVideoFormat7 = |
|
3921 CCompressedVideoFormat::NewL( KH264MimeType7 ); |
|
3922 |
|
3923 CleanupStack::PushL( compressedVideoFormat7 ); |
|
3924 |
|
3925 error = iSupportedOutputFormats.Append( compressedVideoFormat7 ); |
|
3926 if( error != KErrNone ) |
|
3927 { |
|
3928 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3929 User::Leave( error ); |
|
3930 } |
|
3931 CleanupStack::Pop(); |
|
3932 |
|
3933 error = iLevels.Append( KH264ENCIMPL_LEVEL_21 ); |
|
3934 if( error != KErrNone ) |
|
3935 { |
|
3936 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3937 User::Leave( error ); |
|
3938 } |
|
3939 |
|
3940 // Level 2.2 |
|
3941 CCompressedVideoFormat* compressedVideoFormat8 = |
|
3942 CCompressedVideoFormat::NewL( KH264MimeType8 ); |
|
3943 |
|
3944 CleanupStack::PushL( compressedVideoFormat8 ); |
|
3945 |
|
3946 error = iSupportedOutputFormats.Append( compressedVideoFormat8 ); |
|
3947 if( error != KErrNone ) |
|
3948 { |
|
3949 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3950 User::Leave( error ); |
|
3951 } |
|
3952 CleanupStack::Pop(); |
|
3953 |
|
3954 error = iLevels.Append( KH264ENCIMPL_LEVEL_22 ); |
|
3955 if( error != KErrNone ) |
|
3956 { |
|
3957 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3958 User::Leave( error ); |
|
3959 } |
|
3960 |
|
3961 // Level 3 |
|
3962 CCompressedVideoFormat* compressedVideoFormat9 = |
|
3963 CCompressedVideoFormat::NewL( KH264MimeType9 ); |
|
3964 |
|
3965 CleanupStack::PushL( compressedVideoFormat9 ); |
|
3966 |
|
3967 error = iSupportedOutputFormats.Append( compressedVideoFormat9 ); |
|
3968 if( error != KErrNone ) |
|
3969 { |
|
3970 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3971 User::Leave( error ); |
|
3972 } |
|
3973 CleanupStack::Pop(); |
|
3974 |
|
3975 error = iLevels.Append( KH264ENCIMPL_LEVEL_3 ); |
|
3976 if( error != KErrNone ) |
|
3977 { |
|
3978 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
3979 User::Leave( error ); |
|
3980 } |
|
3981 |
|
3982 // Level 1b |
|
3983 CCompressedVideoFormat* compressedVideoFormat10 = |
|
3984 CCompressedVideoFormat::NewL( KH264MimeType10 ); |
|
3985 |
|
3986 CleanupStack::PushL( compressedVideoFormat10 ); |
|
3987 |
|
3988 error = iSupportedOutputFormats.Append( compressedVideoFormat10 ); |
|
3989 if( error != KErrNone ) |
|
3990 { |
|
3991 PRINT_ERR( "Error while appending output format...leaving \n" ); |
|
3992 User::Leave( error ); |
|
3993 } |
|
3994 CleanupStack::Pop(); |
|
3995 |
|
3996 error = iLevels.Append( KH264ENCIMPL_LEVEL_1b ); |
|
3997 if( error != KErrNone ) |
|
3998 { |
|
3999 PRINT_ERR( "Error while appending supported level...leaving \n" ); |
|
4000 User::Leave( error ); |
|
4001 } |
|
4002 |
|
4003 iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityIdle ); |
|
4004 iOutputFreeBufferQueue.Reset(); |
|
4005 iInternalOutputBufferQueue.Reset(); |
|
4006 iEncStateMac = CStateMachine::NewL(); |
|
4007 |
|
4008 PRINT_EXIT; |
|
4009 } |
|
4010 |
|
4011 //---------------------------------------------------------------------------- |
|
4012 // Sends the updated time to the codec |
|
4013 //---------------------------------------------------------------------------- |
|
4014 // |
|
4015 TInt CAriH264encHwDeviceImpl::UpdateTime() |
|
4016 { |
|
4017 PRINT_ENTRY; |
|
4018 |
|
4019 if ( !iClockSource ) |
|
4020 { |
|
4021 ClientFatalError( KErrBadHandle ); |
|
4022 return -1; |
|
4023 } |
|
4024 |
|
4025 // send the time values to the codec |
|
4026 iCodec->SetUpdatedRefernceTime( iTotalTime ); |
|
4027 |
|
4028 PRINT_EXIT; |
|
4029 return 1; |
|
4030 } |
|
4031 |
|
4032 //---------------------------------------------------------------------------- |
|
4033 // Create the output buffers in Coded picture mode |
|
4034 //---------------------------------------------------------------------------- |
|
4035 // |
|
4036 void CAriH264encHwDeviceImpl::CreateCodedOutputBuffersL( TUint aSize ) |
|
4037 { |
|
4038 PRINT_ENTRY; |
|
4039 |
|
4040 if( iH264EncInitParams.iDataUnitType != EDuVideoSegment ) |
|
4041 { |
|
4042 iOutputBufferSize = aSize; |
|
4043 } |
|
4044 |
|
4045 // Allocate memory for TVideoOutputBuffer |
|
4046 iOutputBuffers = new ( ELeave ) TVideoOutputBuffer[ |
|
4047 iH264EncInitParams.iMinNumOutputBuffers]; |
|
4048 |
|
4049 for ( TInt i = 0; i < iH264EncInitParams.iMinNumOutputBuffers; i++ ) |
|
4050 { |
|
4051 iOutputBuffers[i].iData.Set( NULL, 0); |
|
4052 } |
|
4053 |
|
4054 // Create the Buffer and add it to Queue |
|
4055 for ( TInt i = 0; i < iH264EncInitParams.iMinNumOutputBuffers; i++ ) |
|
4056 { |
|
4057 TUint8* ptr = new ( ELeave ) TUint8[aSize]; |
|
4058 CleanupStack::PushL( ptr ); |
|
4059 iOutputBuffers[i].iData.Set( ptr, aSize ); |
|
4060 CleanupStack::Pop(); |
|
4061 InitializeOuputCodedBuffer( iOutputBuffers[i] ); |
|
4062 TInt error = iOutputFreeBufferQueue.Append( iOutputBuffers + i ); |
|
4063 if ( error != KErrNone ) |
|
4064 { |
|
4065 PRINT_ERR( "Error while appending output buffer to the" |
|
4066 "output buffer queue \n" ); |
|
4067 User::Leave( error ); |
|
4068 return; |
|
4069 } |
|
4070 } |
|
4071 |
|
4072 PRINT_EXIT; |
|
4073 } |
|
4074 |
|
4075 //---------------------------------------------------------------------------- |
|
4076 // Creates the temporary output buffers |
|
4077 //---------------------------------------------------------------------------- |
|
4078 // |
|
4079 void CAriH264encHwDeviceImpl::CreateInternalOutputBuffersL( |
|
4080 TUint aBufferSize ) |
|
4081 { |
|
4082 PRINT_ENTRY; |
|
4083 |
|
4084 iOutputBufferSize = aBufferSize; |
|
4085 |
|
4086 // Allocate memory for TVideoOutputBuffer |
|
4087 iInternalOutputBuffers = new ( ELeave ) TVideoOutputBuffer[ |
|
4088 KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS]; |
|
4089 |
|
4090 for ( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
4091 { |
|
4092 iInternalOutputBuffers[i].iData.Set( NULL, 0 ); |
|
4093 } |
|
4094 |
|
4095 // Create the Buffer and add it to Queue |
|
4096 for ( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
4097 { |
|
4098 TUint8* ptr = new ( ELeave ) TUint8[aBufferSize]; |
|
4099 CleanupStack::PushL( ptr ); |
|
4100 iInternalOutputBuffers[i].iData.Set( ptr, aBufferSize ); |
|
4101 CleanupStack::Pop(); |
|
4102 InitializeOuputCodedBuffer( iInternalOutputBuffers[i] ); |
|
4103 TInt error |
|
4104 = iInternalOutputBufferQueue.Append( iInternalOutputBuffers + i ); |
|
4105 |
|
4106 if ( error != KErrNone ) |
|
4107 { |
|
4108 ClientFatalError( error ); |
|
4109 return; |
|
4110 } |
|
4111 } |
|
4112 |
|
4113 PRINT_EXIT; |
|
4114 } |
|
4115 |
|
4116 |
|
4117 //---------------------------------------------------------------------------- |
|
4118 // Creates the buffers required to store length and offset |
|
4119 // info of packets |
|
4120 //---------------------------------------------------------------------------- |
|
4121 // |
|
4122 void CAriH264encHwDeviceImpl::CreatePacketOffsetLengthInfoBuffersL( |
|
4123 TUint aNumOfPackets ) |
|
4124 { |
|
4125 PRINT_ENTRY; |
|
4126 |
|
4127 iPacketOffSetAndLengthInfoBuffers = new ( ELeave ) |
|
4128 ( TUint*[KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS] ); |
|
4129 |
|
4130 for ( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
4131 { |
|
4132 iPacketOffSetAndLengthInfoBuffers[i] = NULL; |
|
4133 } |
|
4134 |
|
4135 for ( TInt i = 0; i < KH264ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ ) |
|
4136 { |
|
4137 iPacketOffSetAndLengthInfoBuffers[i] = ( TUint* ) ( new ( ELeave ) |
|
4138 TUint8[aNumOfPackets] ); |
|
4139 TInt error = iFreeBufferQueueForPacketOffsetInfo.Append( |
|
4140 iPacketOffSetAndLengthInfoBuffers[i] ); |
|
4141 if( error != KErrNone ) |
|
4142 { |
|
4143 PRINT_ERR( "Error while appending packet lengthoffset buffer to " |
|
4144 "queue \n" ); |
|
4145 User::Leave( error ); |
|
4146 } |
|
4147 } |
|
4148 |
|
4149 PRINT_EXIT; |
|
4150 } |
|
4151 |
|
4152 //---------------------------------------------------------------------------- |
|
4153 // decides whether picture can be encoded or not |
|
4154 //---------------------------------------------------------------------------- |
|
4155 // |
|
4156 TBool CAriH264encHwDeviceImpl::CanEncode( TVideoPicture *aPicture ) |
|
4157 { |
|
4158 PRINT_ENTRY; |
|
4159 |
|
4160 // check with the last encoded picture and decide whether it can be |
|
4161 // processed or skipped |
|
4162 if( aPicture->iTimestamp.Int64() < iLastEncodedPictureTimestamp ) |
|
4163 { |
|
4164 return EFalse; |
|
4165 } |
|
4166 |
|
4167 // check with current clock |
|
4168 if( ( aPicture->iTimestamp.Int64() ) < ( ( iClockSource->Time().Int64() - |
|
4169 iTotalTime ) + KH264ENCIMPL_ENCODEAHEAD ) ) |
|
4170 { |
|
4171 return EFalse; |
|
4172 } |
|
4173 |
|
4174 PRINT_EXIT; |
|
4175 return ETrue; |
|
4176 } |
|
4177 //---------------------------------------------------------------------------- |
|
4178 // Skips the Input Picture |
|
4179 //---------------------------------------------------------------------------- |
|
4180 // |
|
4181 void CAriH264encHwDeviceImpl::SkipInputPicture( TVideoPicture *aPicture ) |
|
4182 { |
|
4183 |
|
4184 PRINT_ENTRY; |
|
4185 |
|
4186 // add the buffer back to queue |
|
4187 if ( !iInputBufReturnToPreProc ) |
|
4188 { |
|
4189 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::SkipInputPicture()" |
|
4190 "-return picture back to client" ) ); |
|
4191 iMMFDevVideoRecordProxy->MdvrpReturnPicture( aPicture ); |
|
4192 } |
|
4193 else |
|
4194 { |
|
4195 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::SkipInputPicture()-" |
|
4196 "return picture back to Input Device" ) ); |
|
4197 iInputDevice->ReturnPicture( aPicture ); |
|
4198 } |
|
4199 |
|
4200 if ( !iFrozen ) |
|
4201 { |
|
4202 iPictureCounters.iPicturesSkippedRateControl++; |
|
4203 } |
|
4204 |
|
4205 PRINT_EXIT; |
|
4206 } |
|
4207 |
|
4208 //---------------------------------------------------------------------------- |
|
4209 // Indicates whether the next frame is to be encoded as an I frame |
|
4210 //---------------------------------------------------------------------------- |
|
4211 // |
|
4212 TBool CAriH264encHwDeviceImpl::IsForcedIFrameRequired( |
|
4213 TVideoPicture* aPicture ) |
|
4214 { |
|
4215 PRINT_ENTRY; |
|
4216 |
|
4217 if( ( aPicture->iOptions & TVideoPicture::EReqInstantRefresh ) || |
|
4218 iPictureLoss ) |
|
4219 { |
|
4220 PRINT_MSG( LEVEL_HIGH, ("CAriH264encHwDeviceImpl" |
|
4221 "::IsForcedIFrameRequired() ETrue 1--" ) ); |
|
4222 return ETrue; |
|
4223 } |
|
4224 |
|
4225 PRINT_EXIT; |
|
4226 return EFalse; |
|
4227 } |
|
4228 |
|
4229 //---------------------------------------------------------------------------- |
|
4230 // Extracts 1 packet from a frame and Fills output buffer with the same |
|
4231 //---------------------------------------------------------------------------- |
|
4232 // |
|
4233 void CAriH264encHwDeviceImpl::FillVideoSegment( |
|
4234 TVideoOutputBuffer* aOutputBuf, TVideoOutputBuffer* aSrcOutputBuf ) |
|
4235 { |
|
4236 PRINT_ENTRY; |
|
4237 |
|
4238 // first time fill all config information in one o/p buffer |
|
4239 if ( iIsConfigDataFilledInFirstOutputBuffer ) |
|
4240 { |
|
4241 TUint configDataLength = 0; |
|
4242 TUint* startPtr = iPacketOffSetCurrentPosition; |
|
4243 TInt noOfConfigParamas = 0; |
|
4244 |
|
4245 #ifdef EMZ_AVC_ENC_CODEC_SEIINFO_ENABLE |
|
4246 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::FillVideoSegment() " |
|
4247 "SEI enabled" ) ); |
|
4248 noOfConfigParamas= KNumOfConfigParams_SEI; |
|
4249 #else |
|
4250 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::FillVideoSegment() " |
|
4251 "SEI disabled" ) ); |
|
4252 noOfConfigParamas= KNumOfConfigParams; |
|
4253 #endif |
|
4254 for( TInt i = 0; i < noOfConfigParamas; i++ ) |
|
4255 { |
|
4256 configDataLength += * ( ++startPtr ) ++; |
|
4257 } |
|
4258 |
|
4259 // copy data into output buffer |
|
4260 Mem::Copy( ( TUint8* )( ( TUint8* )aOutputBuf->iData.Ptr() ), |
|
4261 ( TUint8* )( aSrcOutputBuf->iData.Ptr() ), configDataLength ); |
|
4262 |
|
4263 iTotalLengthFilledSoFarInPacketMode += configDataLength; |
|
4264 |
|
4265 if( iH264EncInitParams.iDataEncapsulation == EDuGenericPayload ) |
|
4266 { |
|
4267 |
|
4268 // word boundary calculation |
|
4269 TUint32 offset = ( TUint32 )( ( TUint8* )aOutputBuf->iData.Ptr() |
|
4270 + configDataLength ); |
|
4271 |
|
4272 if ( offset % KWordLength ) |
|
4273 { |
|
4274 offset = KWordLength - ( offset % KWordLength ); |
|
4275 } |
|
4276 else |
|
4277 { |
|
4278 offset = 0; |
|
4279 } |
|
4280 |
|
4281 configDataLength += offset; |
|
4282 TUint8* ptr = ( ( TUint8* )aOutputBuf->iData.Ptr() |
|
4283 + configDataLength ); |
|
4284 |
|
4285 // copy offset and length information |
|
4286 Mem::Copy( ptr, ( TUint8* )iPacketOffSetCurrentPosition, |
|
4287 ( noOfConfigParamas*KDoubleWordLength ) ); |
|
4288 |
|
4289 ptr += ( noOfConfigParamas * KDoubleWordLength ); |
|
4290 |
|
4291 //put the num of nal units information |
|
4292 TUint* nalInfo = ( TUint* )ptr; |
|
4293 nalInfo[0] = noOfConfigParamas; |
|
4294 |
|
4295 configDataLength += ( ( noOfConfigParamas*KDoubleWordLength ) + |
|
4296 KWordLength ); |
|
4297 } |
|
4298 |
|
4299 // increment the packet offsetpointer |
|
4300 iPacketOffSetCurrentPosition += ( noOfConfigParamas * 2 ); |
|
4301 aOutputBuf->iData.Set( aOutputBuf->iData.Ptr(),configDataLength ); |
|
4302 iIsConfigDataFilledInFirstOutputBuffer = EFalse; |
|
4303 } |
|
4304 else |
|
4305 { |
|
4306 TUint currentPacketLength = *( ++iPacketOffSetCurrentPosition ); |
|
4307 |
|
4308 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl::FillVideoSegment()" |
|
4309 " currentPacketLength is %d", ( TInt )currentPacketLength ) ); |
|
4310 |
|
4311 if ( iTotalLengthFilledSoFarInPacketMode |
|
4312 < iTotalOutputBufferLengthInPacketMode ) |
|
4313 { |
|
4314 Mem::Copy( ( TUint8* )( aOutputBuf->iData.Ptr() ), |
|
4315 ( TUint8* )( aSrcOutputBuf->iData.Ptr() + |
|
4316 iTotalLengthFilledSoFarInPacketMode ), currentPacketLength ); |
|
4317 |
|
4318 aOutputBuf->iData.Set( aOutputBuf->iData.Ptr(), |
|
4319 currentPacketLength ); |
|
4320 |
|
4321 iTotalLengthFilledSoFarInPacketMode |
|
4322 = iTotalLengthFilledSoFarInPacketMode + currentPacketLength; |
|
4323 |
|
4324 if ( iH264EncInitParams.iDataEncapsulation == EDuGenericPayload ) |
|
4325 { |
|
4326 // fill the offset and length information |
|
4327 TUint32 offset = ( TUint32 )( aOutputBuf->iData.Ptr() |
|
4328 + currentPacketLength ); |
|
4329 |
|
4330 if ( offset % KWordLength ) |
|
4331 { |
|
4332 offset = ( KWordLength - ( offset % KWordLength ) ); |
|
4333 } |
|
4334 else |
|
4335 { |
|
4336 offset = 0; |
|
4337 } |
|
4338 |
|
4339 TUint* ptr = ( TUint* ) ( aOutputBuf->iData.Ptr() |
|
4340 + currentPacketLength + offset ); |
|
4341 |
|
4342 ptr[0] = 0; |
|
4343 ptr[1] = *( iPacketOffSetCurrentPosition ); |
|
4344 ptr[2] = 1; |
|
4345 |
|
4346 aOutputBuf->iData.Set( aOutputBuf->iData.Ptr(), |
|
4347 currentPacketLength + offset + KDoubleWordLength |
|
4348 + KWordLength ); |
|
4349 } |
|
4350 |
|
4351 if ( iTotalLengthFilledSoFarInPacketMode == |
|
4352 iTotalOutputBufferLengthInPacketMode ) |
|
4353 { |
|
4354 iTotalLengthFilledSoFarInPacketMode = 0; |
|
4355 iPacketsPending = EFalse; |
|
4356 |
|
4357 // remove packet offset info buffer from filled Q and |
|
4358 // add it to free Q |
|
4359 TUint* freeOffsetLengthInfoBuffer |
|
4360 = iFilledBufferQueueForPacketOffsetInfo[0]; |
|
4361 |
|
4362 iFilledBufferQueueForPacketOffsetInfo.Remove( 0 ); |
|
4363 TInt error = iFreeBufferQueueForPacketOffsetInfo.Append( |
|
4364 freeOffsetLengthInfoBuffer ); |
|
4365 |
|
4366 if ( error != KErrNone ) |
|
4367 { |
|
4368 ClientFatalError( error ); |
|
4369 return; |
|
4370 } |
|
4371 |
|
4372 // Remove the internal buffer and add it back to process |
|
4373 // engine |
|
4374 if ( iInternalOutputBufferQueue.Count() ) |
|
4375 { |
|
4376 TVideoOutputBuffer* outBuf |
|
4377 = iInternalOutputBufferQueue[0]; |
|
4378 iInternalOutputBufferQueue.Remove( 0 ); |
|
4379 outBuf->iData.Set( ( TUint8* )outBuf->iData.Ptr(), |
|
4380 iOutputBufferSize ); |
|
4381 |
|
4382 // Add the Buffer back to the Process Engine |
|
4383 if( ( !iEncStateMac->IsInputEndPending() ) && |
|
4384 ( !iEncStateMac->IsStopped() ) ) |
|
4385 { |
|
4386 iEngine->AddOutput( ( TAny* )outBuf ); |
|
4387 } |
|
4388 } |
|
4389 |
|
4390 // Still more encoded packets are available |
|
4391 if( iInternalOutputBufferQueue.Count() ) |
|
4392 { |
|
4393 iPacketsPending = ETrue; |
|
4394 iTotalOutputBufferLengthInPacketMode |
|
4395 = iInternalOutputBufferQueue[0]->iData.Length(); |
|
4396 |
|
4397 // Get the packet offset info buffer |
|
4398 if( iFilledBufferQueueForPacketOffsetInfo.Count() ) |
|
4399 { |
|
4400 iPacketOffSetCurrentPosition |
|
4401 = iFilledBufferQueueForPacketOffsetInfo[0]; |
|
4402 } |
|
4403 } |
|
4404 } |
|
4405 else |
|
4406 { |
|
4407 ++iPacketOffSetCurrentPosition; |
|
4408 } |
|
4409 } |
|
4410 } |
|
4411 |
|
4412 // Update the specific members of the output buffer |
|
4413 aOutputBuf->iRequiredSeveralPictures |
|
4414 = aSrcOutputBuf->iRequiredSeveralPictures; |
|
4415 aOutputBuf->iRandomAccessPoint = aSrcOutputBuf->iRandomAccessPoint; |
|
4416 aOutputBuf->iCaptureTimestamp = aSrcOutputBuf->iCaptureTimestamp; |
|
4417 |
|
4418 PRINT_EXIT; |
|
4419 } |
|
4420 |
|
4421 //---------------------------------------------------------------------------- |
|
4422 // Initializes the members of the output coded buffers created |
|
4423 //---------------------------------------------------------------------------- |
|
4424 // |
|
4425 void CAriH264encHwDeviceImpl::InitializeOuputCodedBuffer( |
|
4426 TVideoOutputBuffer& aOutputBuffer ) |
|
4427 { |
|
4428 PRINT_ENTRY; |
|
4429 |
|
4430 aOutputBuffer.iOrderNumber = 0; |
|
4431 aOutputBuffer.iMinErrorProtectionLevel = 1; |
|
4432 aOutputBuffer.iMaxErrorProtectionLevel = 1; |
|
4433 aOutputBuffer.iRequiredThisPicture = EFalse; |
|
4434 aOutputBuffer.iLayer = 0; |
|
4435 aOutputBuffer.iInLayerScalabilityStep = 0; |
|
4436 aOutputBuffer.iDataPartitionNumber = 0; |
|
4437 aOutputBuffer.iHrdVbvParams.Set( NULL, 0 ); |
|
4438 aOutputBuffer.iCodingStandardSpecificData.Set( NULL, 0 ); |
|
4439 aOutputBuffer.iImplementationSpecificData.Set( NULL, 0 ); |
|
4440 |
|
4441 // The following members will be modified later during execution |
|
4442 aOutputBuffer.iRequiredSeveralPictures = EFalse; |
|
4443 aOutputBuffer.iRandomAccessPoint = EFalse; |
|
4444 aOutputBuffer.iCaptureTimestamp = 0; |
|
4445 |
|
4446 PRINT_EXIT; |
|
4447 } |
|
4448 |
|
4449 //---------------------------------------------------------------------------- |
|
4450 // Sets level and bitrate based on size information |
|
4451 //---------------------------------------------------------------------------- |
|
4452 // |
|
4453 |
|
4454 void CAriH264encHwDeviceImpl::SetLevelAndBitRate() |
|
4455 { |
|
4456 PRINT_ENTRY; |
|
4457 |
|
4458 if( (iH264EncInitParams.iPictureSize.iWidth <= KH264ENCIMPL_QCIF_WIDTH ) |
|
4459 && ( iH264EncInitParams.iPictureSize.iHeight |
|
4460 <= KH264ENCIMPL_QCIF_HEIGHT ) ) |
|
4461 { |
|
4462 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_1; |
|
4463 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_1; |
|
4464 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
4465 } |
|
4466 //QVGA |
|
4467 else |
|
4468 if( ( iH264EncInitParams.iPictureSize.iWidth |
|
4469 <= KH264ENCIMPL_QVGA_WIDTH ) && |
|
4470 ( iH264EncInitParams.iPictureSize.iHeight |
|
4471 <= KH264ENCIMPL_QVGA_HEIGHT ) ) |
|
4472 { |
|
4473 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_12; |
|
4474 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_12; |
|
4475 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
4476 } |
|
4477 //CIF |
|
4478 else |
|
4479 if( ( iH264EncInitParams.iPictureSize.iWidth |
|
4480 <= KH264ENCIMPL_CIF_WIDTH ) && |
|
4481 ( iH264EncInitParams.iPictureSize.iHeight |
|
4482 <= KH264ENCIMPL_CIF_HEIGHT ) ) |
|
4483 { |
|
4484 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_13; |
|
4485 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_13; |
|
4486 iH264EncInitParams.iTargetPictureRate = KPictureRate30; |
|
4487 } |
|
4488 // VGA |
|
4489 else |
|
4490 if( ( iH264EncInitParams.iPictureSize.iWidth |
|
4491 <= KH264ENCIMPL_VGA_WIDTH ) && |
|
4492 ( iH264EncInitParams.iPictureSize.iHeight |
|
4493 <= KH264ENCIMPL_VGA_HEIGHT ) ) |
|
4494 { |
|
4495 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_22; |
|
4496 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_22; |
|
4497 iH264EncInitParams.iTargetPictureRate = KPictureRate15; |
|
4498 } |
|
4499 else |
|
4500 { |
|
4501 iH264EncInitParams.iLevel = KH264ENCIMPL_LEVEL_3; |
|
4502 iH264EncInitParams.iBitRate = KH264ENCIMPL_BITRATE_LEVEL_3; |
|
4503 iH264EncInitParams.iTargetPictureRate = KPictureRate25; |
|
4504 } |
|
4505 |
|
4506 PRINT_EXIT; |
|
4507 } |
|
4508 |
|
4509 //---------------------------------------------------------------------------- |
|
4510 // Checks if the specified input format is supported or not |
|
4511 //---------------------------------------------------------------------------- |
|
4512 // |
|
4513 TBool CAriH264encHwDeviceImpl::CheckInputFormat( |
|
4514 const TUncompressedVideoFormat& aFormat ) |
|
4515 { |
|
4516 PRINT_ENTRY; |
|
4517 |
|
4518 // Check if encoder supports the passed input format |
|
4519 if ( aFormat.iDataFormat != EYuvRawData ) |
|
4520 { |
|
4521 return EFalse; |
|
4522 } |
|
4523 |
|
4524 if ( aFormat.iYuvFormat.iDataLayout != EYuvDataPlanar ) |
|
4525 { |
|
4526 PRINT_EXIT; |
|
4527 return EFalse; |
|
4528 } |
|
4529 |
|
4530 if ( ( aFormat.iYuvFormat.iCoefficients != EYuvBt709Range0 ) && |
|
4531 ( aFormat.iYuvFormat.iCoefficients != EYuvBt709Range1 ) && |
|
4532 ( aFormat.iYuvFormat.iCoefficients != EYuvBt601Range0 ) && |
|
4533 ( aFormat.iYuvFormat.iCoefficients != EYuvBt601Range1 ) ) |
|
4534 { |
|
4535 return EFalse; |
|
4536 } |
|
4537 |
|
4538 if ( ( aFormat.iYuvFormat.iPattern != EYuv420Chroma1 ) && |
|
4539 ( aFormat.iYuvFormat.iPattern != EYuv420Chroma2 ) && |
|
4540 ( aFormat.iYuvFormat.iPattern != EYuv420Chroma3 ) ) |
|
4541 { |
|
4542 return EFalse; |
|
4543 } |
|
4544 |
|
4545 PRINT_EXIT; |
|
4546 return ETrue; |
|
4547 } |
|
4548 |
|
4549 |
|
4550 //---------------------------------------------------------------------------- |
|
4551 // Nofities the client that the fatal error happend in Hw device |
|
4552 //---------------------------------------------------------------------------- |
|
4553 // |
|
4554 void CAriH264encHwDeviceImpl::ClientFatalError( TInt aError ) |
|
4555 { |
|
4556 PRINT_ENTRY; |
|
4557 PRINT_MSG( LEVEL_CRITICAL, ("CAriH264encHwDeviceImpl::ClientFatalError()" |
|
4558 " Error is %d", aError ) ); |
|
4559 |
|
4560 if( iClockSource ) |
|
4561 { |
|
4562 iPeriodicTimer->Cancel(); |
|
4563 } |
|
4564 |
|
4565 // Stop processing |
|
4566 if( !iEncStateMac->IsStopped() ) |
|
4567 { |
|
4568 if( iEncStateMac->IsInitialized() ) |
|
4569 { |
|
4570 Stop(); |
|
4571 } |
|
4572 } |
|
4573 iEncStateMac->Transit( CStateMachine::EDeadStateCommand ); |
|
4574 iMMFDevVideoRecordProxy->MdvrpFatalError( this, aError ); |
|
4575 |
|
4576 PRINT_EXIT; |
|
4577 } |
|
4578 |
|
4579 //---------------------------------------------------------------------------- |
|
4580 // Output buffers are created with the specified size |
|
4581 //---------------------------------------------------------------------------- |
|
4582 // |
|
4583 |
|
4584 void CAriH264encHwDeviceImpl::ReallocSegmentOutputBuffersL( TUint aSize ) |
|
4585 { |
|
4586 PRINT_ENTRY; |
|
4587 |
|
4588 TInt count = iOutputFreeBufferQueue.Count(); |
|
4589 for ( TInt i = 0; i < count; i++ ) |
|
4590 { |
|
4591 // dellallocate memory for this buffer |
|
4592 TVideoOutputBuffer* ouputBuf = iOutputFreeBufferQueue[i]; |
|
4593 if ( ouputBuf->iData.Ptr() ) |
|
4594 { |
|
4595 delete ( TUint8* )ouputBuf->iData.Ptr(); |
|
4596 } |
|
4597 |
|
4598 // and allocate memory and store it in temp Q |
|
4599 TUint8* ptr = new ( ELeave ) TUint8[aSize]; |
|
4600 CleanupStack::PushL( ptr ); |
|
4601 ouputBuf->iData.Set( ptr, aSize ); |
|
4602 CleanupStack::Pop(); |
|
4603 } |
|
4604 |
|
4605 PRINT_EXIT; |
|
4606 } |
|
4607 |
|
4608 //---------------------------------------------------------------------------- |
|
4609 // Reallocates single buffer |
|
4610 //---------------------------------------------------------------------------- |
|
4611 // |
|
4612 void CAriH264encHwDeviceImpl::ReallocateSegmentBufferL( |
|
4613 TVideoOutputBuffer* aBuffer ) |
|
4614 { |
|
4615 PRINT_ENTRY; |
|
4616 |
|
4617 TInt size = iH264EncInitParams.iMaxCodedSegmentSize; |
|
4618 if( iH264EncInitParams.iDataEncapsulation == EDuGenericPayload ) |
|
4619 { |
|
4620 size += KDoubleWordLength + KWordLength; |
|
4621 } |
|
4622 |
|
4623 if ( aBuffer->iData.Ptr() ) |
|
4624 { |
|
4625 delete ( TUint8* )aBuffer->iData.Ptr(); |
|
4626 } |
|
4627 |
|
4628 // and allocate memory and store it in temp Q |
|
4629 TUint8* ptr = new ( ELeave ) TUint8[size]; |
|
4630 CleanupStack::PushL( ptr ); |
|
4631 aBuffer->iData.Set( ptr, ( size ) ); |
|
4632 CleanupStack::Pop(); |
|
4633 |
|
4634 PRINT_EXIT; |
|
4635 } |
|
4636 |
|
4637 //---------------------------------------------------------------------------- |
|
4638 // Creates single buffer for frame mode to packet mode change |
|
4639 //---------------------------------------------------------------------------- |
|
4640 // |
|
4641 |
|
4642 void CAriH264encHwDeviceImpl::CreateCodedBufferForModeChangeL() |
|
4643 { |
|
4644 PRINT_ENTRY; |
|
4645 |
|
4646 iCodedBufferForPacketModeChange = new ( ELeave ) TVideoOutputBuffer; |
|
4647 TUint8* ptr = new ( ELeave ) TUint8[iOutputBufferSize]; |
|
4648 CleanupStack::PushL( ptr ); |
|
4649 iCodedBufferForPacketModeChange->iData.Set( ptr, iOutputBufferSize ); |
|
4650 CleanupStack::Pop(); |
|
4651 InitializeOuputCodedBuffer( *iCodedBufferForPacketModeChange ); |
|
4652 |
|
4653 PRINT_EXIT; |
|
4654 } |
|
4655 |
|
4656 |
|
4657 //---------------------------------------------------------------------------- |
|
4658 // Creates buffers which are used as output buffers in packet mode. Function |
|
4659 // is called only when frame mode - packet mode change occurs while encoding |
|
4660 //---------------------------------------------------------------------------- |
|
4661 // |
|
4662 |
|
4663 void CAriH264encHwDeviceImpl::CreateSegmentOutputBuffersL( |
|
4664 TUint aNumOfBuffers, TUint aSize ) |
|
4665 { |
|
4666 PRINT_ENTRY; |
|
4667 |
|
4668 TInt segmentSize = aSize; |
|
4669 // 4+4 bytes for offset and length |
|
4670 if( iH264EncInitParams.iDataEncapsulation == EDuGenericPayload ) |
|
4671 { |
|
4672 segmentSize += KDoubleWordLength + KWordLength; |
|
4673 } |
|
4674 |
|
4675 // Allocate memory for TVideoOutputBuffer |
|
4676 iSegmentBuffers = new ( ELeave ) TVideoOutputBuffer[aNumOfBuffers]; |
|
4677 for ( TInt i = 0; i < aNumOfBuffers; i++ ) |
|
4678 { |
|
4679 iSegmentBuffers[i].iData.Set( NULL, 0 ); |
|
4680 } |
|
4681 |
|
4682 // Create the Buffer and add it to Queue |
|
4683 for ( TInt i = 0; i < aNumOfBuffers; i++ ) |
|
4684 { |
|
4685 TUint8* ptr = new ( ELeave ) TUint8[segmentSize]; |
|
4686 CleanupStack::PushL( ptr ); |
|
4687 iSegmentBuffers[i].iData.Set( ptr, segmentSize ); |
|
4688 CleanupStack::Pop(); |
|
4689 InitializeOuputCodedBuffer( iSegmentBuffers[i] ); |
|
4690 TInt error = iOutputFreeBufferQueue.Append( iSegmentBuffers + i ); |
|
4691 if ( error != KErrNone ) |
|
4692 { |
|
4693 PRINT_ERR( "Error while appending segment output buffer to the" |
|
4694 "segment output buffer queue" ); |
|
4695 User::Leave( error ); |
|
4696 return; |
|
4697 } |
|
4698 } |
|
4699 |
|
4700 PRINT_EXIT; |
|
4701 } |
|
4702 |
|
4703 //---------------------------------------------------------------------------- |
|
4704 // Calculates the instant bit rate |
|
4705 //---------------------------------------------------------------------------- |
|
4706 // |
|
4707 |
|
4708 void CAriH264encHwDeviceImpl::CalculateInstantBitRate( |
|
4709 const TVideoOutputBuffer &aOutBuf ) |
|
4710 { |
|
4711 PRINT_ENTRY; |
|
4712 |
|
4713 TInt size = 0; |
|
4714 TReal ts = ( ( aOutBuf.iCaptureTimestamp ).Int64() ) / 1000000.0; |
|
4715 size = aOutBuf.iData.Length(); |
|
4716 TInt32 partInt = 0; |
|
4717 Math::Int( partInt, ts ); |
|
4718 |
|
4719 // Calculate stream size, averaged per 1 second |
|
4720 if ( partInt > iCurrentIntTS ) |
|
4721 { |
|
4722 #ifdef DEBUG_INFO |
|
4723 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
4724 "::CalculateInstantBitRate(), Stream size per 1 second: %d", |
|
4725 iStreamSize * 8 ) ); |
|
4726 PRINT_MSG( LEVEL_LOW, ("CAriH264encHwDeviceImpl" |
|
4727 "::CalculateInstantBitRate(), Number of frames per 1 second: " |
|
4728 " %d", iNoOfOutputFramesPerSec ) ); |
|
4729 #endif |
|
4730 // Reset global stream size |
|
4731 iStreamSize = 0; |
|
4732 iNoOfOutputFramesPerSec = 0; |
|
4733 iCurrentIntTS = partInt; |
|
4734 } |
|
4735 iSizePerFrame = iSizePerFrame + size; |
|
4736 iStreamSize = iStreamSize + size; |
|
4737 |
|
4738 PRINT_EXIT; |
|
4739 } |
|
4740 |
|
4741 //---------------------------------------------------------------------------- |
|
4742 // The implementation table entry which indicates the 1st function |
|
4743 // to call when H264 encoder hwdevice plugin is selected |
|
4744 //---------------------------------------------------------------------------- |
|
4745 // |
|
4746 const TImplementationProxy ImplementationTable[] = |
|
4747 { |
|
4748 { KUidH264EncoderHwDeviceImplUid, |
|
4749 ( TProxyNewLPtr )( CAriH264encHwDeviceImpl::NewL ) } |
|
4750 }; |
|
4751 |
|
4752 //---------------------------------------------------------------------------- |
|
4753 // Returns the implementation table |
|
4754 //---------------------------------------------------------------------------- |
|
4755 // |
|
4756 |
|
4757 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
4758 TInt& aTableCount ) |
|
4759 { |
|
4760 aTableCount = sizeof( ImplementationTable ) |
|
4761 / sizeof( TImplementationProxy ); |
|
4762 return ImplementationTable; |
|
4763 } |
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |