1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Video encoder client. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <devvideorecord.h> |
|
24 #include <devvideobase.h> |
|
25 #include <devvideoconstants.h> |
|
26 #include <H263.h> |
|
27 #include <AVC.h> |
|
28 #include <Mpeg4Visual.h> |
|
29 #include "ctrtranscoder.h" |
|
30 #include "ctrvideoencoderclient.h" |
|
31 #include "ctrdevvideoclientobserver.h" |
|
32 #include "ctrsettings.h" |
|
33 #include "ctrhwsettings.h" |
|
34 |
|
35 |
|
36 // MACROS |
|
37 #define TRASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CTRANSCODERVIDEOENCODERCLIENT"), -10000)) |
|
38 |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CTRVideoEncoderClient::NewL |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CTRVideoEncoderClient* CTRVideoEncoderClient::NewL(MTRDevVideoClientObserver& aObserver) |
|
51 { |
|
52 PRINT((_L("CTRVideoEncoderClient::NewL(), In"))) |
|
53 CTRVideoEncoderClient* self = new (ELeave) CTRVideoEncoderClient(aObserver); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(); |
|
57 |
|
58 PRINT((_L("CTRVideoEncoderClient::NewL(), Out"))) |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CTRVideoEncoderClient::CTRVideoEncoderClient |
|
65 // C++ default constructor can NOT contain any code, that |
|
66 // might leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CTRVideoEncoderClient::CTRVideoEncoderClient(MTRDevVideoClientObserver& aObserver) : |
|
70 iObserver(aObserver) |
|
71 { |
|
72 iDevVideoRecord = NULL; |
|
73 iOutputMediaBuffer = NULL; |
|
74 iCompresedFormat = NULL; |
|
75 iUid = TUid::Null(); |
|
76 iFallbackUid = TUid::Null(); |
|
77 iRealTime = EFalse; |
|
78 iState = ETRNone; |
|
79 iCodingOptions.iSyncIntervalInPicture = 0; |
|
80 iCodingOptions.iHeaderExtension = 0; |
|
81 iCodingOptions.iDataPartitioning = EFalse; |
|
82 iCodingOptions.iReversibleVLC = EFalse; |
|
83 iSrcRate = 0.0; |
|
84 iVolHeaderSent = EFalse; |
|
85 iRemoveHeader = EFalse; |
|
86 iVolLength = 0; |
|
87 iRateOptions.iControl = EBrControlStream; |
|
88 iRateOptions.iPictureRate = KTRTargetFrameRateDefault; |
|
89 iRateOptions.iBitrate = KTRMaxBitRateH263Level10; |
|
90 iBitRateSetting = EFalse; |
|
91 iFatalError = KErrNone; |
|
92 iErrorRate = 0.0; |
|
93 iVolHeader = KNullDesC8; |
|
94 iVideoBufferManagementCI = NULL; |
|
95 iLastTimestamp = -1; |
|
96 iAcceleratedCodecSelected = EFalse; |
|
97 iSetRandomAccessPoint = EFalse; |
|
98 iNumH264SPSPPS = 0; |
|
99 } |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CTRVideoEncoderClient::ConstructL |
|
104 // Symbian 2nd phase constructor can leave. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CTRVideoEncoderClient::ConstructL() |
|
108 { |
|
109 iDevVideoRecord = CMMFDevVideoRecord::NewL(*this); |
|
110 iOutputMediaBuffer = new(ELeave)CCMRMediaBuffer; |
|
111 } |
|
112 |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CTRVideoEncoderClient::~CTRVideoEncoderClient() |
|
116 // Destructor |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 CTRVideoEncoderClient::~CTRVideoEncoderClient() |
|
120 { |
|
121 PRINT((_L("CTRVideoEncoderClient::~CTRVideoEncoderClient(), In"))) |
|
122 |
|
123 if (iDevVideoRecord) |
|
124 { |
|
125 delete iDevVideoRecord; |
|
126 iDevVideoRecord = NULL; |
|
127 } |
|
128 |
|
129 if (iCompresedFormat) |
|
130 { |
|
131 delete iCompresedFormat; |
|
132 } |
|
133 |
|
134 if (iOutputMediaBuffer) |
|
135 { |
|
136 delete iOutputMediaBuffer; |
|
137 } |
|
138 |
|
139 PRINT((_L("CTRVideoEncoderClient::~CTRVideoEncoderClient(), Out"))) |
|
140 } |
|
141 |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CTRVideoEncoderClient::SupportsInputFormat |
|
145 // Checks whether given input format is supported |
|
146 // (other items were commented in a header). |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 TBool CTRVideoEncoderClient::SupportsCodec(const TDesC8& aFormat, const TDesC8& aShortFormat, TInt aUid, TInt aFallbackUid) |
|
150 { |
|
151 TBool supports = EFalse; |
|
152 TBool preferredFound = EFalse; |
|
153 TBool fallbackFound = EFalse; |
|
154 |
|
155 if (iDevVideoRecord) |
|
156 { |
|
157 RArray<TUid> encoders; |
|
158 |
|
159 TRAPD( status, iDevVideoRecord->FindEncodersL(aShortFormat, 0/*aPreProcType*/, encoders, EFalse/*aExactMatch*/) ); |
|
160 |
|
161 if( status != KErrNone ) |
|
162 { |
|
163 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), status[%d]"), status)) |
|
164 supports = EFalse; |
|
165 } |
|
166 else if( encoders.Count() <= 0 ) |
|
167 { |
|
168 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), No encoders found"))) |
|
169 supports = EFalse; |
|
170 } |
|
171 else |
|
172 { |
|
173 |
|
174 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), %d encoders found"), encoders.Count() )) |
|
175 |
|
176 // Check if any of the found encoders matches with the given Uids |
|
177 for( TInt i = 0; i < encoders.Count(); ++i ) |
|
178 { |
|
179 |
|
180 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), found codec 0x%x"), encoders[i].iUid)) |
|
181 |
|
182 if( encoders[i].iUid == aUid ) |
|
183 { |
|
184 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), preferred found"))) |
|
185 iUid = encoders[i]; |
|
186 preferredFound = ETrue; |
|
187 } |
|
188 if( encoders[i].iUid == aFallbackUid ) |
|
189 { |
|
190 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), fallback found"))) |
|
191 iFallbackUid = encoders[i]; |
|
192 fallbackFound = ETrue; |
|
193 } |
|
194 |
|
195 if( preferredFound && fallbackFound ) |
|
196 { |
|
197 // No need to search anymore |
|
198 break; |
|
199 } |
|
200 } |
|
201 } |
|
202 |
|
203 encoders.Reset(); |
|
204 encoders.Close(); |
|
205 } |
|
206 |
|
207 #if !( defined (__WINS__) || defined (__WINSCW__) ) |
|
208 if( !preferredFound ) |
|
209 #else |
|
210 if( !preferredFound && !fallbackFound ) |
|
211 #endif |
|
212 { |
|
213 // Preferred encoder was not found => Probably the given encoder Uid is wrong |
|
214 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), No supported encoders found"))) |
|
215 supports = EFalse; |
|
216 } |
|
217 else |
|
218 { |
|
219 PRINT((_L("CTRVideoEncoderClient::SupportsCodec(), Supported encoder found: 0x%x"), iUid.iUid)) |
|
220 iMimeType = aFormat; |
|
221 iShortMimeType = aShortFormat; |
|
222 supports = ETrue; |
|
223 } |
|
224 |
|
225 return supports; |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CTRVideoEncoderClient::SetCodecParametersL |
|
231 // Sets codec parameters |
|
232 // (other items were commented in a header). |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CTRVideoEncoderClient::SetCodecParametersL(TInt aCodecType, TInt aCodecLevel, const TTRVideoFormat& aInputFormat, |
|
236 const TTRVideoFormat& aOutputFormat) |
|
237 { |
|
238 PRINT((_L("CTRVideoEncoderClient::SetCodecParametersL(), In"))) |
|
239 TInt status = KErrNone; |
|
240 iCodecType = aCodecType; |
|
241 iCodecLevel = aCodecLevel; |
|
242 iPictureSize = aOutputFormat.iSize; |
|
243 iOutputDataType = aOutputFormat.iDataType; |
|
244 |
|
245 // RAW YUV |
|
246 iUncompressedFormat.iDataFormat = EYuvRawData; |
|
247 |
|
248 // U & V samples are taken from the middle of four luminance samples |
|
249 // (as specified in H.263 spec) |
|
250 switch ( aInputFormat.iDataType ) |
|
251 { |
|
252 case CTRTranscoder::ETRYuvRawData420: |
|
253 { |
|
254 iUncompressedFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
255 break; |
|
256 } |
|
257 |
|
258 case CTRTranscoder::ETRYuvRawData422: |
|
259 { |
|
260 iUncompressedFormat.iYuvFormat.iPattern = EYuv422Chroma2; |
|
261 break; |
|
262 } |
|
263 |
|
264 default: |
|
265 { |
|
266 iUncompressedFormat.iYuvFormat.iPattern = EYuv420Chroma2; |
|
267 break; |
|
268 } |
|
269 } |
|
270 |
|
271 // Output format |
|
272 if (!iCompresedFormat) |
|
273 { |
|
274 iCompresedFormat = CCompressedVideoFormat::NewL( iMimeType ); |
|
275 } |
|
276 |
|
277 TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) ); |
|
278 |
|
279 if (status != KErrNone) |
|
280 { |
|
281 // Try again with the fallback encoder if one exists |
|
282 if( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) ) |
|
283 { |
|
284 TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iFallbackUid) ); |
|
285 |
|
286 if (status != KErrNone) |
|
287 { |
|
288 PRINT((_L("CTRVideoEncoderClient::SetCodecParametersL(), Failed to get codec info"))) |
|
289 User::Leave(KErrNotSupported); |
|
290 } |
|
291 |
|
292 PRINT((_L("CTRVideoEncoderClient::SetCodecParametersL(), Reverting to fallback encoder"))) |
|
293 |
|
294 // Fallback ok, take it |
|
295 iUid = iFallbackUid; |
|
296 } |
|
297 else |
|
298 { |
|
299 PRINT((_L("CTRVideoEncoderClient::SetCodecParametersL(), No suitable encoders found"))) |
|
300 User::Leave(KErrNotSupported); |
|
301 } |
|
302 } |
|
303 |
|
304 // AA Set codec here (final hwdevice Uid should be known before checking CI buffermanag support) |
|
305 // Select encoder first |
|
306 this->SelectEncoderL(); |
|
307 |
|
308 PRINT((_L("CTRVideoEncoderClient::SetCodecParametersL(), Out"))) |
|
309 } |
|
310 |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CTRVideoEncoderClient::CheckCodecInfoL |
|
314 // Checks codec info |
|
315 // (other items were commented in a header). |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CTRVideoEncoderClient::CheckCodecInfoL(TUid aUid) |
|
319 { |
|
320 CVideoEncoderInfo* encoderInfo = NULL; // Encoder info for retrieving capabilities |
|
321 iMaxFrameRate = 0; |
|
322 TInt status = KErrNone; |
|
323 TUint32 dataUnitType = 0; |
|
324 TBool accelerated = EFalse; |
|
325 |
|
326 switch(iOutputDataType) |
|
327 { |
|
328 case CTRTranscoder::ETRDuCodedPicture: |
|
329 { |
|
330 dataUnitType = EDuCodedPicture; |
|
331 break; |
|
332 } |
|
333 |
|
334 case CTRTranscoder::ETRDuVideoSegment: |
|
335 { |
|
336 dataUnitType = EDuVideoSegment; |
|
337 break; |
|
338 } |
|
339 |
|
340 default: |
|
341 { |
|
342 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), should leave at the earlier stage, panic"))) |
|
343 TRASSERT(0); |
|
344 } |
|
345 } |
|
346 |
|
347 // Check encoder |
|
348 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), getting info from [0x%x]"), aUid.iUid )) |
|
349 encoderInfo = iDevVideoRecord->VideoEncoderInfoLC( aUid ); |
|
350 |
|
351 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), info [0x%x]"), encoderInfo )) |
|
352 |
|
353 if (!encoderInfo) |
|
354 { |
|
355 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), getting info from [0x%x] failed[%d]"), aUid.iUid, status )) |
|
356 User::Leave(KErrNotSupported); |
|
357 } |
|
358 else |
|
359 { |
|
360 // Check input format |
|
361 // 1. retrieve supported formats from encoder hwdevice (since exact options are unknown) |
|
362 RArray<TUncompressedVideoFormat> supportedInputFormats = encoderInfo->SupportedInputFormats(); |
|
363 |
|
364 TInt formatCount = supportedInputFormats.Count(); |
|
365 |
|
366 if (formatCount <= 0) |
|
367 { |
|
368 supportedInputFormats.Close(); |
|
369 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), There are no supported input formats") )) |
|
370 User::Leave(KErrNotSupported); |
|
371 } |
|
372 else |
|
373 { |
|
374 TUncompressedVideoFormat uncFormat; |
|
375 TBool found = EFalse; |
|
376 TInt pattern1, pattern2; |
|
377 TInt dataLayout; |
|
378 |
|
379 if (iUncompressedFormat.iYuvFormat.iPattern == EYuv420Chroma2) |
|
380 { |
|
381 pattern1 = EYuv420Chroma1; |
|
382 pattern2 = EYuv420Chroma2; |
|
383 dataLayout = EYuvDataPlanar; |
|
384 } |
|
385 else |
|
386 { |
|
387 pattern1 = EYuv422Chroma1; |
|
388 pattern2 = EYuv422Chroma2; |
|
389 dataLayout = EYuvDataInterleavedBE; |
|
390 } |
|
391 |
|
392 // Check the most important paramers |
|
393 for ( TInt i = 0; i < formatCount; i ++ ) |
|
394 { |
|
395 uncFormat = supportedInputFormats[i]; |
|
396 |
|
397 if ( (uncFormat.iDataFormat == iUncompressedFormat.iDataFormat) && |
|
398 (uncFormat.iYuvFormat.iDataLayout == dataLayout) && |
|
399 ( (uncFormat.iYuvFormat.iPattern == pattern1) || |
|
400 (uncFormat.iYuvFormat.iPattern == pattern2) ) ) |
|
401 { |
|
402 // Assign the rest of parameters |
|
403 iUncompressedFormat = uncFormat; |
|
404 |
|
405 if ( iCodecType != EH263 ) |
|
406 { |
|
407 // Set aspect ratio to 1:1 (square) |
|
408 iUncompressedFormat.iYuvFormat.iAspectRatioNum = 1; |
|
409 iUncompressedFormat.iYuvFormat.iAspectRatioDenom = 1; |
|
410 } |
|
411 |
|
412 found = ETrue; |
|
413 break; |
|
414 } |
|
415 } |
|
416 |
|
417 if (!found) |
|
418 { |
|
419 supportedInputFormats.Close(); |
|
420 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), Supported format is not found") )) |
|
421 User::Leave(KErrNotSupported); |
|
422 } |
|
423 } |
|
424 |
|
425 /*if ( !encoderInfo->SupportsOutputFormat(*iCompresedFormat) ) // comment until symbian error is fixed |
|
426 { |
|
427 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), Output format is not supported"))) |
|
428 status = KErrNotSupported; |
|
429 } |
|
430 else */ |
|
431 if ( (encoderInfo->SupportedDataUnitTypes() & dataUnitType) != dataUnitType ) |
|
432 { |
|
433 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), There's no support for this DUType"))) |
|
434 status = KErrNotSupported; |
|
435 } |
|
436 else |
|
437 { |
|
438 // Get max rate for requested image format |
|
439 RArray<TPictureRateAndSize> rateAndSize = encoderInfo->MaxPictureRates(); |
|
440 TUint rates = rateAndSize.Count(); |
|
441 |
|
442 TSize picSize = iPictureSize; |
|
443 if ( picSize == TSize(640, 352) ) // Use VGA max frame rate for VGA 16:9 |
|
444 picSize = TSize(640, 480); |
|
445 |
|
446 for ( TUint i = 0; i < rates; i++ ) |
|
447 { |
|
448 if ( rateAndSize[i].iPictureSize == picSize ) |
|
449 { |
|
450 status = KErrNone; |
|
451 iMaxFrameRate = rateAndSize[i].iPictureRate; |
|
452 PRINT((_L("CTRVideoEncoderClient::CheckCodecInfoL(), Needed picture size found!"))) |
|
453 break; |
|
454 } |
|
455 |
|
456 status = KErrNotSupported; |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 accelerated = encoderInfo->Accelerated(); |
|
462 |
|
463 // Delete codec info |
|
464 CleanupStack::PopAndDestroy(encoderInfo); |
|
465 |
|
466 if (status != KErrNone) |
|
467 { |
|
468 User::Leave(status); |
|
469 } |
|
470 |
|
471 return accelerated; |
|
472 } |
|
473 |
|
474 |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // CTRVideoEncoderClient::SetBitRate |
|
478 // Sets video bitrate |
|
479 // (other items were commented in a header). |
|
480 // ----------------------------------------------------------------------------- |
|
481 // |
|
482 void CTRVideoEncoderClient::SetBitRate(TUint aBitRate) |
|
483 { |
|
484 if ( (iState == ETRInitialized) || (iState == ETRRunning) || (iState == ETRPaused) ) |
|
485 { |
|
486 iRateOptions.iBitrate = aBitRate; |
|
487 iRateOptions.iPictureQuality = KTRPictureQuality; |
|
488 iRateOptions.iQualityTemporalTradeoff = KTRQualityTemporalTradeoff; |
|
489 |
|
490 if (iRealTime) |
|
491 { |
|
492 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffRT; |
|
493 } |
|
494 else |
|
495 { |
|
496 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffNonRT; |
|
497 } |
|
498 |
|
499 // Set bit rate to Encoder |
|
500 iDevVideoRecord->SetRateControlOptions(0/*Layer 0 is supported*/, iRateOptions); |
|
501 iBitRateSetting = ETrue; |
|
502 } |
|
503 else |
|
504 { |
|
505 // Keep bit rate and set it later |
|
506 iRateOptions.iBitrate = aBitRate; |
|
507 } |
|
508 } |
|
509 |
|
510 |
|
511 // ----------------------------------------------------------------------------- |
|
512 // CTRVideoEncoderClient::SetRealTime |
|
513 // Sets encoder mode to operate real-time |
|
514 // (other items were commented in a header). |
|
515 // ----------------------------------------------------------------------------- |
|
516 // |
|
517 void CTRVideoEncoderClient::SetRealTime(TBool aRealTime) |
|
518 { |
|
519 iRealTime = aRealTime; |
|
520 } |
|
521 |
|
522 |
|
523 // ----------------------------------------------------------------------------- |
|
524 // CTRVideoEncoderClient::SetFrameRate |
|
525 // Sets frame rate |
|
526 // (other items were commented in a header). |
|
527 // ----------------------------------------------------------------------------- |
|
528 // |
|
529 void CTRVideoEncoderClient::SetFrameRate(TReal& aFrameRate) |
|
530 { |
|
531 if ( (iState == ETRInitialized) || (iState == ETRRunning) || (iState == ETRPaused) ) |
|
532 { |
|
533 iRateOptions.iPictureRate = aFrameRate; |
|
534 |
|
535 // The target frame rate must not be greater than the source frame rate |
|
536 if ( (iSrcRate > 0.0) && (iRateOptions.iPictureRate > iSrcRate) ) |
|
537 { |
|
538 iRateOptions.iPictureRate = iSrcRate; |
|
539 } |
|
540 |
|
541 if (iRealTime) |
|
542 { |
|
543 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffRT; |
|
544 } |
|
545 else |
|
546 { |
|
547 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffNonRT; |
|
548 } |
|
549 |
|
550 // Set framerate rate to Encoder |
|
551 iDevVideoRecord->SetRateControlOptions(0/*Layer 0 is supported*/, iRateOptions); |
|
552 } |
|
553 else |
|
554 { |
|
555 // Keep frame rate and set it later |
|
556 iRateOptions.iPictureRate = aFrameRate; |
|
557 |
|
558 // The target frame rate must not be greater than the source frame rate |
|
559 if ( (iSrcRate > 0.0) && (iRateOptions.iPictureRate > iSrcRate) ) |
|
560 { |
|
561 iRateOptions.iPictureRate = iSrcRate; |
|
562 } |
|
563 } |
|
564 } |
|
565 |
|
566 |
|
567 // ----------------------------------------------------------------------------- |
|
568 // CTRVideoEncoderClient::SetChannelBitErrorRate |
|
569 // Sets channel bit error rate |
|
570 // (other items were commented in a header). |
|
571 // ----------------------------------------------------------------------------- |
|
572 // |
|
573 void CTRVideoEncoderClient::SetChannelBitErrorRate(TReal aErrorRate) |
|
574 { |
|
575 if ( (iState == ETRInitialized) || (iState == ETRRunning) || (iState == ETRPaused) ) |
|
576 { |
|
577 // Run-time setting |
|
578 iDevVideoRecord->SetChannelBitErrorRate(0/*Error protection level number*/, aErrorRate, 0.0/*Std deviation*/); |
|
579 } |
|
580 else |
|
581 { |
|
582 iErrorRate = aErrorRate; |
|
583 } |
|
584 } |
|
585 |
|
586 |
|
587 // ----------------------------------------------------------------------------- |
|
588 // CTRVideoEncoderClient::SetVideoCodingOptionsL |
|
589 // Sets video coding options |
|
590 // (other items were commented in a header). |
|
591 // ----------------------------------------------------------------------------- |
|
592 // |
|
593 void CTRVideoEncoderClient::SetVideoCodingOptionsL(TTRVideoCodingOptions& aOptions) |
|
594 { |
|
595 iCodingOptions = aOptions; |
|
596 } |
|
597 |
|
598 |
|
599 // ----------------------------------------------------------------------------- |
|
600 // CTRVideoEncoderClient::GetVideoBitRateL |
|
601 // Gets video bitrate |
|
602 // (other items were commented in a header). |
|
603 // ----------------------------------------------------------------------------- |
|
604 // |
|
605 TUint CTRVideoEncoderClient::GetVideoBitRateL() |
|
606 { |
|
607 return iRateOptions.iBitrate; |
|
608 } |
|
609 |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // CTRVideoEncoderClient::GetFrameRateL |
|
613 // Gets frame rate |
|
614 // (other items were commented in a header). |
|
615 // ----------------------------------------------------------------------------- |
|
616 // |
|
617 TReal CTRVideoEncoderClient::GetFrameRateL() |
|
618 { |
|
619 return iRateOptions.iPictureRate; |
|
620 } |
|
621 |
|
622 |
|
623 // ----------------------------------------------------------------------------- |
|
624 // CTRVideoEncoderClient::SetInputFrameRate |
|
625 // Sets source framerate |
|
626 // (other items were commented in a header). |
|
627 // ----------------------------------------------------------------------------- |
|
628 // |
|
629 void CTRVideoEncoderClient::SetInputFrameRate(TReal aFrameRate) |
|
630 { |
|
631 iSrcRate = aFrameRate; |
|
632 |
|
633 // The target frame rate must not be greater than the source frame rate |
|
634 if ( (iSrcRate > 0.0) && (iRateOptions.iPictureRate > iSrcRate) ) |
|
635 { |
|
636 iRateOptions.iPictureRate = iSrcRate; |
|
637 } |
|
638 } |
|
639 |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CTRVideoEncoderClient::InitializeL |
|
643 // Initializes encoder |
|
644 // (other items were commented in a header). |
|
645 // ----------------------------------------------------------------------------- |
|
646 // |
|
647 void CTRVideoEncoderClient::InitializeL() |
|
648 { |
|
649 PRINT((_L("CTRVideoEncoderClient::InitializeL(), In"))) |
|
650 TVideoDataUnitType dataUnitType = EDuCodedPicture; |
|
651 TEncoderBufferOptions bufferOptions; |
|
652 TUint maxBufferSize = 0; |
|
653 |
|
654 |
|
655 // Give Init settings |
|
656 // 1. Set output format. Output format was already set in SetCodecParametersL |
|
657 switch(iOutputDataType) |
|
658 { |
|
659 case CTRTranscoder::ETRDuCodedPicture: |
|
660 { |
|
661 dataUnitType = EDuCodedPicture; |
|
662 bufferOptions.iMinNumOutputBuffers = KTRMinNumberOfBuffersCodedPicture; |
|
663 break; |
|
664 } |
|
665 |
|
666 case CTRTranscoder::ETRDuVideoSegment: |
|
667 { |
|
668 dataUnitType = EDuVideoSegment; |
|
669 bufferOptions.iMinNumOutputBuffers = KTRMinNumberOfBuffersVideoSegment; |
|
670 break; |
|
671 } |
|
672 |
|
673 default: |
|
674 { |
|
675 // Should never happend. Encoder does not support uncompressed output format. |
|
676 TRASSERT(0); |
|
677 } |
|
678 } |
|
679 |
|
680 TVideoDataUnitEncapsulation dataUnitEncapsulation = EDuElementaryStream; |
|
681 |
|
682 // Use generic payload encapsulation for H.264 |
|
683 if (iCodecType == EH264) |
|
684 { |
|
685 dataUnitEncapsulation = EDuGenericPayload; |
|
686 } |
|
687 |
|
688 iDevVideoRecord->SetOutputFormatL(iHwDeviceId, *iCompresedFormat, dataUnitType, dataUnitEncapsulation, EFalse); |
|
689 |
|
690 // 2. Set input format |
|
691 iDevVideoRecord->SetInputFormatL(iHwDeviceId, iUncompressedFormat, iPictureSize); |
|
692 |
|
693 // 3. Buffer options |
|
694 bufferOptions.iMaxPreEncoderBufferPictures = bufferOptions.iMinNumOutputBuffers; |
|
695 bufferOptions.iHrdVbvSpec = EHrdVbvNone; |
|
696 bufferOptions.iHrdVbvParams.Set(NULL, 0); |
|
697 |
|
698 // Check max coded picture size for specified codec level |
|
699 switch(iCodecLevel) |
|
700 { |
|
701 case KTRH263CodecLevel10: |
|
702 { |
|
703 maxBufferSize = KTRMaxBufferSizeLevel10; |
|
704 break; |
|
705 } |
|
706 |
|
707 case KTRH263CodecLevel20: |
|
708 { |
|
709 maxBufferSize = KTRMaxBufferSizeLevel20; |
|
710 break; |
|
711 } |
|
712 |
|
713 case KTRH263CodecLevel30: |
|
714 { |
|
715 maxBufferSize = KTRMaxBufferSizeLevel30; |
|
716 break; |
|
717 } |
|
718 |
|
719 case KTRH263CodecLevel40: |
|
720 { |
|
721 maxBufferSize = KTRMaxBufferSizeLevel40; |
|
722 break; |
|
723 } |
|
724 |
|
725 case KTRH263CodecLevel45: |
|
726 { |
|
727 maxBufferSize = KTRMaxBufferSizeLevel45; |
|
728 break; |
|
729 } |
|
730 |
|
731 case KTRH263CodecLevel50: |
|
732 { |
|
733 maxBufferSize = KTRMaxBufferSizeLevel50; |
|
734 break; |
|
735 } |
|
736 |
|
737 case KTRH263CodecLevel60: |
|
738 { |
|
739 maxBufferSize = KTRMaxBufferSizeLevel60; |
|
740 break; |
|
741 } |
|
742 |
|
743 case KTRH263CodecLevel70: |
|
744 { |
|
745 maxBufferSize = KTRMaxBufferSizeLevel70; |
|
746 break; |
|
747 } |
|
748 |
|
749 case KTRH264CodecLevel10: |
|
750 { |
|
751 maxBufferSize = KTRMaxBufferSizeH264Level10; |
|
752 break; |
|
753 } |
|
754 |
|
755 case KTRH264CodecLevel10b: |
|
756 { |
|
757 maxBufferSize = KTRMaxBufferSizeH264Level10b; |
|
758 break; |
|
759 } |
|
760 |
|
761 case KTRH264CodecLevel11: |
|
762 { |
|
763 maxBufferSize = KTRMaxBufferSizeH264Level11; |
|
764 break; |
|
765 } |
|
766 |
|
767 case KTRH264CodecLevel12: |
|
768 { |
|
769 maxBufferSize = KTRMaxBufferSizeH264Level12; |
|
770 break; |
|
771 } |
|
772 |
|
773 case KTRH264CodecLevel13: |
|
774 { |
|
775 maxBufferSize = KTRMaxBufferSizeH264Level13; |
|
776 break; |
|
777 } |
|
778 |
|
779 case KTRH264CodecLevel20: |
|
780 { |
|
781 maxBufferSize = KTRMaxBufferSizeH264Level20; |
|
782 break; |
|
783 } |
|
784 |
|
785 case KTRH264CodecLevel30: |
|
786 { |
|
787 maxBufferSize = KTRMaxBufferSizeH264Level30; |
|
788 break; |
|
789 } |
|
790 |
|
791 case KTRH264CodecLevel31: |
|
792 { |
|
793 maxBufferSize = KTRMaxBufferSizeH264Level31; |
|
794 break; |
|
795 } |
|
796 |
|
797 case KTRMPEG4CodecLevel1: |
|
798 case KTRMPEG4CodecLevel0: |
|
799 { |
|
800 maxBufferSize = KTRMaxBufferSizeLevel0; |
|
801 break; |
|
802 } |
|
803 |
|
804 case KTRMPEG4CodecLevel0b: |
|
805 { |
|
806 maxBufferSize = KTRMaxBufferSizeLevel0b; |
|
807 break; |
|
808 } |
|
809 |
|
810 case KTRMPEG4CodecLevel2: |
|
811 { |
|
812 maxBufferSize = KTRMaxBufferSizeLevel2; |
|
813 break; |
|
814 } |
|
815 |
|
816 case KTRMPEG4CodecLevel3: |
|
817 { |
|
818 maxBufferSize = KTRMaxBufferSizeLevel3; |
|
819 break; |
|
820 } |
|
821 |
|
822 case KTRMPEG4CodecLevel4a: |
|
823 { |
|
824 maxBufferSize = KTRMaxBufferSizeLevel4a; |
|
825 break; |
|
826 } |
|
827 |
|
828 default: |
|
829 { |
|
830 maxBufferSize = KTRMaxBufferSizeLevel0; |
|
831 } |
|
832 } |
|
833 |
|
834 bufferOptions.iMaxOutputBufferSize = maxBufferSize; |
|
835 bufferOptions.iMaxCodedPictureSize = bufferOptions.iMaxOutputBufferSize; |
|
836 |
|
837 if ((iCodecType != EH263) && (iCodingOptions.iSyncIntervalInPicture > 0)) |
|
838 { |
|
839 // Set segment target size |
|
840 if ( iCodingOptions.iSyncIntervalInPicture < KTRMinSegmentSize ) |
|
841 { |
|
842 bufferOptions.iMaxCodedSegmentSize = KTRMinSegmentSize; |
|
843 } |
|
844 else if (iCodingOptions.iSyncIntervalInPicture > bufferOptions.iMaxCodedPictureSize) |
|
845 { |
|
846 bufferOptions.iMaxCodedSegmentSize = bufferOptions.iMaxCodedPictureSize; |
|
847 } |
|
848 else |
|
849 { |
|
850 bufferOptions.iMaxCodedSegmentSize = iCodingOptions.iSyncIntervalInPicture; |
|
851 } |
|
852 } |
|
853 else |
|
854 { |
|
855 // Set segment size to max video coded picture size |
|
856 bufferOptions.iMaxCodedSegmentSize = bufferOptions.iMaxCodedPictureSize; |
|
857 } |
|
858 |
|
859 PRINT((_L("CTRVideoEncoderClient::InitializeL(), iMaxOutputBufferSize[%d], iMinNumOutputBuffers[%d]"), |
|
860 bufferOptions.iMaxOutputBufferSize, bufferOptions.iMinNumOutputBuffers )) |
|
861 |
|
862 iDevVideoRecord->SetBufferOptionsL(bufferOptions); |
|
863 |
|
864 // 4. Random access point |
|
865 TReal accessRate = KTRDefaultAccessRate; /* ~0.2 fps */ |
|
866 |
|
867 if (iCodingOptions.iMinRandomAccessPeriodInSeconds > 0) |
|
868 { |
|
869 accessRate = 1.0 / TReal(iCodingOptions.iMinRandomAccessPeriodInSeconds); |
|
870 } |
|
871 |
|
872 PRINT((_L("CTRVideoEncoderClient::InitializeL(), RandomAcessRate[%f]"), accessRate)); |
|
873 iDevVideoRecord->SetMinRandomAccessRate(accessRate); |
|
874 |
|
875 // 5. Other coding options |
|
876 if (iCodecType == EH263) |
|
877 { |
|
878 if (iCodingOptions.iSyncIntervalInPicture > 0) |
|
879 { |
|
880 TH263VideoMode h263CodingOptions; |
|
881 |
|
882 h263CodingOptions.iAllowedPictureTypes = EH263PictureTypeI | EH263PictureTypeP; |
|
883 h263CodingOptions.iForceRoundingTypeToZero = ETrue; |
|
884 h263CodingOptions.iPictureHeaderRepetition = 0; |
|
885 h263CodingOptions.iGOBHeaderInterval = iCodingOptions.iSyncIntervalInPicture; |
|
886 |
|
887 TPckgC<TH263VideoMode> h263OptionsPckg(h263CodingOptions); |
|
888 iDevVideoRecord->SetCodingStandardSpecificOptionsL(h263OptionsPckg); |
|
889 } |
|
890 } |
|
891 else if (iCodecType == EH264) |
|
892 { |
|
893 // H.264 options |
|
894 TAvcVideoMode avcCodingOptions; |
|
895 |
|
896 avcCodingOptions.iAllowedPictureTypes = EAvcPictureTypeI | EAvcPictureTypeP; |
|
897 avcCodingOptions.iFlexibleMacroblockOrder = EFalse; |
|
898 avcCodingOptions.iRedundantPictures = EFalse; |
|
899 avcCodingOptions.iDataPartitioning = iCodingOptions.iDataPartitioning; |
|
900 avcCodingOptions.iFrameMBsOnly = ETrue; |
|
901 avcCodingOptions.iMBAFFCoding = EFalse; |
|
902 avcCodingOptions.iEntropyCodingCABAC = EFalse; |
|
903 avcCodingOptions.iWeightedPPrediction = EFalse; |
|
904 avcCodingOptions.iWeightedBipredicitonMode = 0; |
|
905 avcCodingOptions.iDirect8x8Inference = EFalse; |
|
906 |
|
907 TPckgC<TAvcVideoMode> avc4OptionsPckg(avcCodingOptions); |
|
908 iDevVideoRecord->SetCodingStandardSpecificOptionsL(avc4OptionsPckg); |
|
909 } |
|
910 else |
|
911 { |
|
912 // Mpeg4 options |
|
913 TMPEG4VisualMode mpeg4CodingOptions; |
|
914 mpeg4CodingOptions.iShortHeaderMode = EFalse; |
|
915 mpeg4CodingOptions.iMPEG4VisualNormalMPEG4Mode.iHeaderExtension = iCodingOptions.iHeaderExtension; |
|
916 mpeg4CodingOptions.iMPEG4VisualNormalMPEG4Mode.iDataPartitioning = iCodingOptions.iDataPartitioning; |
|
917 mpeg4CodingOptions.iMPEG4VisualNormalMPEG4Mode.iReversibleVLC = iCodingOptions.iReversibleVLC; |
|
918 |
|
919 mpeg4CodingOptions.iMPEG4VisualNormalMPEG4Mode.iAllowedVOPTypes = EMPEG4VisualVOPTypeI; |
|
920 |
|
921 TPckgC<TMPEG4VisualMode> mpeg4OptionsPckg(mpeg4CodingOptions); |
|
922 iDevVideoRecord->SetCodingStandardSpecificOptionsL(mpeg4OptionsPckg); |
|
923 } |
|
924 |
|
925 // Set source |
|
926 if (iSrcRate <= 0.0) |
|
927 { |
|
928 iSrcRate = KTRDefaultSrcRate; /* ~15.0 fps */ |
|
929 } |
|
930 |
|
931 iDevVideoRecord->SetSourceMemoryL(iSrcRate, ETrue, iRealTime); |
|
932 |
|
933 // Initialize devVideoRecord |
|
934 iDevVideoRecord->Initialize(); |
|
935 |
|
936 // Set media buffer type |
|
937 if (iCodecType == EH263) |
|
938 { |
|
939 // Set H.263 |
|
940 iBufferType = CCMRMediaBuffer::EVideoH263; |
|
941 } |
|
942 else if (iCodecType == EH264) |
|
943 { |
|
944 // Set H.264 |
|
945 iBufferType = CCMRMediaBuffer::EVideoMPEG4; // : What to set here? |
|
946 } |
|
947 else |
|
948 { |
|
949 // Set MPEG4 |
|
950 iBufferType = CCMRMediaBuffer::EVideoMPEG4; |
|
951 } |
|
952 |
|
953 PRINT((_L("CTRVideoEncoderClient::InitializeL(), Out"))) |
|
954 } |
|
955 |
|
956 |
|
957 // ----------------------------------------------------------------------------- |
|
958 // CTRVideoEncoderClient::SelectEncoderL |
|
959 // Selects encoder |
|
960 // (other items were commented in a header). |
|
961 // ----------------------------------------------------------------------------- |
|
962 // |
|
963 void CTRVideoEncoderClient::SelectEncoderL() |
|
964 { |
|
965 PRINT((_L("CTRVideoEncoderClient::SelectEncoderL(), In"))) |
|
966 TInt status = KErrNone; |
|
967 |
|
968 if (iUid != TUid::Null()) |
|
969 { |
|
970 TRAP(status, iHwDeviceId = iDevVideoRecord->SelectEncoderL(iUid)); |
|
971 } |
|
972 else |
|
973 { |
|
974 // Probably the error already exists, if iUid == NULL; |
|
975 status = KErrAlreadyExists; |
|
976 } |
|
977 |
|
978 if (status != KErrNone) |
|
979 { |
|
980 // Try again with the fallback encoder if one exists |
|
981 if( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) ) |
|
982 { |
|
983 PRINT((_L("CTRVideoEncoderClient::SelectEncoderL(), Reverting to fallback encoder"))) |
|
984 iUid = iFallbackUid; |
|
985 } |
|
986 else |
|
987 { |
|
988 PRINT((_L("CTRVideoEncoderClient::SelectDecoderL(), Failed to select encoder"))) |
|
989 User::Leave(KErrNotSupported); |
|
990 } |
|
991 |
|
992 TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) ); |
|
993 |
|
994 if (status != KErrNone) |
|
995 { |
|
996 PRINT((_L("CTRVideoEncoderClient::SelectDecoderL(), Failed to get codec info"))) |
|
997 User::Leave(KErrNotSupported); |
|
998 } |
|
999 |
|
1000 TRAP(status, iHwDeviceId = iDevVideoRecord->SelectEncoderL(iUid)); |
|
1001 |
|
1002 if (status != KErrNone) |
|
1003 { |
|
1004 PRINT((_L("CTRVideoEncoderClient::SelectDecoderL(), Failed to select encoder"))) |
|
1005 User::Leave(KErrNotSupported); |
|
1006 } |
|
1007 } |
|
1008 |
|
1009 PRINT((_L("CTRVideoEncoderClient::SelectEncoderL(), Out"))) |
|
1010 } |
|
1011 |
|
1012 |
|
1013 |
|
1014 // ----------------------------------------------------------------------------- |
|
1015 // CTRVideoEncoderClient::MdvroInitializeComplete |
|
1016 // Informs init status with received error code |
|
1017 // (other items were commented in a header). |
|
1018 // ----------------------------------------------------------------------------- |
|
1019 // |
|
1020 void CTRVideoEncoderClient::MdvroInitializeComplete(TInt aError) |
|
1021 { |
|
1022 if (aError == KErrNone) |
|
1023 { |
|
1024 iState = ETRInitialized; |
|
1025 } |
|
1026 else if ((aError == KErrHardwareNotAvailable) || (aError == KErrNotSupported)) |
|
1027 { |
|
1028 PRINT((_L("CTRVideoEncoderClient::MdvroInitializeComplete(), Error in initialization"))) |
|
1029 |
|
1030 // Map both error codes to the same |
|
1031 aError = KErrNotSupported; |
|
1032 |
|
1033 // Try again with the fallback encoder if one exists |
|
1034 while( (iFallbackUid != TUid::Null()) && (iFallbackUid.iUid != iUid.iUid) ) |
|
1035 { |
|
1036 PRINT((_L("CTRVideoEncoderClient::MdvroInitializeComplete(), Reverting to fallback encoder"))) |
|
1037 |
|
1038 iUid = iFallbackUid; |
|
1039 |
|
1040 // Devvideo must be recreated from scratch |
|
1041 if (iDevVideoRecord) |
|
1042 { |
|
1043 delete iDevVideoRecord; |
|
1044 iDevVideoRecord = NULL; |
|
1045 } |
|
1046 |
|
1047 TRAPD( status, iDevVideoRecord = CMMFDevVideoRecord::NewL(*this) ); |
|
1048 if (status != KErrNone) |
|
1049 { |
|
1050 // Something went wrong, let CTRTranscoderImp handle the error |
|
1051 PRINT((_L("CTRVideoEncoderClient::MdvroInitializeComplete(), Failed to create DevVideoRecord"))) |
|
1052 break; |
|
1053 } |
|
1054 |
|
1055 TRAP( status, iAcceleratedCodecSelected = CheckCodecInfoL(iUid) ); |
|
1056 if (status != KErrNone) |
|
1057 { |
|
1058 // Fallback encoder can not be used, let CTRTranscoderImp handle the error |
|
1059 PRINT((_L("CTRVideoEncoderClient::MdvroInitializeComplete(), Failed to get codec info"))) |
|
1060 break; |
|
1061 } |
|
1062 |
|
1063 TRAP( status, SelectEncoderL() ); |
|
1064 if (status != KErrNone) |
|
1065 { |
|
1066 // Fallback encoder can not be used, let CTRTranscoderImp handle the error |
|
1067 PRINT((_L("CTRVideoEncoderClient::MdvroInitializeComplete(), Failed to select encoder"))) |
|
1068 break; |
|
1069 } |
|
1070 |
|
1071 // We are now ready to reinitialize the encoder, let CTRTranscoderImp do it |
|
1072 aError = KErrHardwareNotAvailable; |
|
1073 break; |
|
1074 } |
|
1075 } |
|
1076 |
|
1077 iObserver.MtrdvcoEncInitializeComplete(aError); |
|
1078 } |
|
1079 |
|
1080 |
|
1081 // ----------------------------------------------------------------------------- |
|
1082 // CTRVideoEncoderClient::StartL |
|
1083 // Starts encoding |
|
1084 // (other items were commented in a header). |
|
1085 // ----------------------------------------------------------------------------- |
|
1086 // |
|
1087 void CTRVideoEncoderClient::StartL() |
|
1088 { |
|
1089 PRINT((_L("CTRVideoEncoderClient::StartL(), In"))) |
|
1090 |
|
1091 if ( (iCodecType == EMpeg4) && (iVolHeader == KNullDesC8) ) |
|
1092 { |
|
1093 // Before starting the encoder, request config data |
|
1094 HBufC8* condigDecInfo = iDevVideoRecord->CodingStandardSpecificInitOutputLC(); |
|
1095 |
|
1096 if (condigDecInfo) |
|
1097 { |
|
1098 PRINT((_L("CTRVideoEncoderClient::StartL(), Vol header length[%d]"), condigDecInfo->Length())) |
|
1099 |
|
1100 if ( (condigDecInfo->Length() > 0) && (condigDecInfo->Length() <= KMaxDesC8Length /*256*/) ) |
|
1101 { |
|
1102 iVolHeader.Des().Copy( condigDecInfo->Des() ); |
|
1103 |
|
1104 // Keep vol length for further use |
|
1105 iVolLength = iVolHeader.Des().Length(); |
|
1106 PRINT((_L("CTRVideoEncoderClient::StartL(), VolLength[%d]"), iVolLength)) |
|
1107 } |
|
1108 |
|
1109 CleanupStack::PopAndDestroy(condigDecInfo); |
|
1110 } |
|
1111 else |
|
1112 { |
|
1113 PRINT((_L("CTRVideoEncoderClient::StartL(), Invalid codingDecInfo, leave"))) |
|
1114 User::Leave(KErrAlreadyExists); |
|
1115 } |
|
1116 |
|
1117 PRINT((_L("CTRVideoEncoderClient::StartL(), Out"))) |
|
1118 } |
|
1119 |
|
1120 |
|
1121 // Set Rate control options |
|
1122 if (!iBitRateSetting) |
|
1123 { |
|
1124 iRateOptions.iPictureQuality = KTRPictureQuality; |
|
1125 iRateOptions.iQualityTemporalTradeoff = KTRQualityTemporalTradeoff; |
|
1126 |
|
1127 if (iRealTime) |
|
1128 { |
|
1129 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffRT; |
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 iRateOptions.iLatencyQualityTradeoff = KTRLatencyQualityTradeoffNonRT; |
|
1134 } |
|
1135 |
|
1136 iDevVideoRecord->SetRateControlOptions(0/*Layer 0 is supported*/, iRateOptions); |
|
1137 iBitRateSetting = ETrue; |
|
1138 } |
|
1139 |
|
1140 if ( (iCodecType != EH263) && (iCodingOptions.iSyncIntervalInPicture > 0) ) |
|
1141 { |
|
1142 // Set resync value (segment target size) |
|
1143 iDevVideoRecord->SetSegmentTargetSize(0/*aLayer*/, |
|
1144 iCodingOptions.iSyncIntervalInPicture/*aSizeBytes*/, |
|
1145 0/*aSizeMacroblocks*/); |
|
1146 } |
|
1147 |
|
1148 // Start encoding |
|
1149 if (iFatalError == KErrNone) |
|
1150 { |
|
1151 iDevVideoRecord->Start(); |
|
1152 iState = ETRRunning; |
|
1153 } |
|
1154 |
|
1155 // Reset ts monitor |
|
1156 iLastTimestamp = -1; |
|
1157 |
|
1158 iSetRandomAccessPoint = EFalse; |
|
1159 |
|
1160 PRINT((_L("CTRVideoEncoderClient::StartL(), Out"))) |
|
1161 } |
|
1162 |
|
1163 |
|
1164 // ----------------------------------------------------------------------------- |
|
1165 // CTRVideoEncoderClient::EncodePictureL |
|
1166 // Encodes video picture |
|
1167 // (other items were commented in a header). |
|
1168 // ----------------------------------------------------------------------------- |
|
1169 // |
|
1170 void CTRVideoEncoderClient::EncodePictureL(TVideoPicture* aPicture) |
|
1171 { |
|
1172 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), In"))) |
|
1173 |
|
1174 if (aPicture) |
|
1175 { |
|
1176 if (iFatalError == KErrNone) |
|
1177 { |
|
1178 // Set rest of picture options |
|
1179 aPicture->iOptions = TVideoPicture::ETimestamp; |
|
1180 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), picture timestamp [%d]"), TInt(aPicture->iTimestamp.Int64()) )) |
|
1181 |
|
1182 TTimeIntervalMicroSeconds ts = aPicture->iTimestamp; |
|
1183 |
|
1184 if ( ts <= iLastTimestamp) |
|
1185 { |
|
1186 // Prevent propagation of the error now |
|
1187 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Picture timestamp less than previously encoded"))) |
|
1188 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Dropping picture!!!"))) |
|
1189 iObserver.MtrdvcoEncoderReturnPicture(aPicture); |
|
1190 |
|
1191 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Out"))) |
|
1192 return; |
|
1193 } |
|
1194 else |
|
1195 { |
|
1196 iLastTimestamp = ts; |
|
1197 } |
|
1198 |
|
1199 // If random access point was requested |
|
1200 if( iSetRandomAccessPoint ) |
|
1201 { |
|
1202 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Instant Refresh requested"))); |
|
1203 aPicture->iOptions |= TVideoPicture::EReqInstantRefresh; |
|
1204 iSetRandomAccessPoint = EFalse; |
|
1205 } |
|
1206 else |
|
1207 { |
|
1208 aPicture->iOptions &= ~(TVideoPicture::EReqInstantRefresh); |
|
1209 } |
|
1210 |
|
1211 aPicture->iData.iDataFormat = EYuvRawData; // Force data format to YUV |
|
1212 |
|
1213 iDevVideoRecord->WritePictureL(aPicture); |
|
1214 } |
|
1215 else |
|
1216 { |
|
1217 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Operation is not possible, since FatalError was reported by low-level[%d]"), iFatalError)) |
|
1218 return; |
|
1219 } |
|
1220 } |
|
1221 else |
|
1222 { |
|
1223 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Picture is not valid, leave"))) |
|
1224 User::Leave(KErrArgument); |
|
1225 } |
|
1226 |
|
1227 PRINT((_L("CTRVideoEncoderClient::EncodePictureL(), Out"))) |
|
1228 } |
|
1229 |
|
1230 |
|
1231 // ----------------------------------------------------------------------------- |
|
1232 // CTRVideoEncoderClient::MdvroReturnPicture |
|
1233 // Returns picture |
|
1234 // (other items were commented in a header). |
|
1235 // ----------------------------------------------------------------------------- |
|
1236 // |
|
1237 void CTRVideoEncoderClient::MdvroReturnPicture(TVideoPicture *aPicture) |
|
1238 { |
|
1239 iObserver.MtrdvcoEncoderReturnPicture(aPicture); |
|
1240 } |
|
1241 |
|
1242 |
|
1243 // ----------------------------------------------------------------------------- |
|
1244 // CTRVideoEncoderClient::MdvroNewBuffers |
|
1245 // New buffers are available in the system |
|
1246 // (other items were commented in a header). |
|
1247 // ----------------------------------------------------------------------------- |
|
1248 // |
|
1249 void CTRVideoEncoderClient::MdvroNewBuffers() |
|
1250 { |
|
1251 TVideoOutputBuffer* newBuffer = NULL; |
|
1252 TInt status = KErrNone; |
|
1253 |
|
1254 |
|
1255 if ( (iCodecType == EMpeg4) && (!iVolHeaderSent) && (iVolHeader != KNullDesC8) ) |
|
1256 { |
|
1257 // Send vol header first to the client |
|
1258 iOutputMediaBuffer->Set( iVolHeader.Des(), |
|
1259 CCMRMediaBuffer::EVideoMPEG4DecSpecInfo, |
|
1260 iVolHeader.Des().Length(), |
|
1261 0, |
|
1262 0 ); |
|
1263 |
|
1264 iObserver.MtrdvcoNewBuffer(iOutputMediaBuffer); |
|
1265 iVolHeaderSent = ETrue; |
|
1266 |
|
1267 // VOS+VO+VOL header is now going to be stored to metadata, it must not be included in mediadata so remove it from the next buffer |
|
1268 iRemoveHeader = ETrue; |
|
1269 } |
|
1270 |
|
1271 // Get new buffer and forward it to the client |
|
1272 while( iDevVideoRecord->NumDataBuffers() > 0 ) |
|
1273 { |
|
1274 TRAP(status, newBuffer = iDevVideoRecord->NextBufferL()); |
|
1275 if (status != KErrNone) |
|
1276 { |
|
1277 PRINT((_L("CTRVideoEncoderClient::MdvroNewBuffers(), NextBufferL failed[%d]"), status)) |
|
1278 iObserver.MtrdvcoFatalError(status); |
|
1279 return; |
|
1280 } |
|
1281 |
|
1282 if (newBuffer) |
|
1283 { |
|
1284 PRINT((_L("CTRVideoEncoderClient::MdvroNewBuffers(), dataBuffer length[%d]"), newBuffer->iData.Length())) |
|
1285 |
|
1286 // Check data length if valid |
|
1287 if (newBuffer->iData.Length() <= 0) |
|
1288 { |
|
1289 // Data length is invalid |
|
1290 PRINT((_L("CTRVideoEncoderClient::MdvroNewBuffers(), encoder generates invalid bitstream, abort data processing"))) |
|
1291 iObserver.MtrdvcoFatalError(KErrAbort); |
|
1292 return; |
|
1293 } |
|
1294 |
|
1295 TBool outputMediaBufferSet = EFalse; |
|
1296 |
|
1297 // Remove vol header if needed from the bitstream |
|
1298 if ( iRemoveHeader ) |
|
1299 { |
|
1300 iRemoveHeader = EFalse; |
|
1301 |
|
1302 if ( iCodecType == EMpeg4 ) |
|
1303 { |
|
1304 // check if we need to remove VOS+VO+VOL header from the bitstream, since it is |
|
1305 // stored in metadata, and having it in 2 places may cause interoperability problems |
|
1306 |
|
1307 // Since the length of the vol is already known, remove that data from the beginning of |
|
1308 // the first buffer |
|
1309 if ( (iVolLength > 0) && (iVolLength < newBuffer->iData.Length()) ) |
|
1310 { |
|
1311 TPtr8* buffer = reinterpret_cast<TPtr8*>(&newBuffer->iData); |
|
1312 buffer->Delete(0, iVolLength); |
|
1313 } |
|
1314 } |
|
1315 |
|
1316 else if ( iCodecType == EH264 ) |
|
1317 { |
|
1318 |
|
1319 TPtr8* ptr = reinterpret_cast<TPtr8*>(&newBuffer->iData); |
|
1320 TPtr8& buffer(*ptr); |
|
1321 |
|
1322 // Offset to the end |
|
1323 TInt readOffset = buffer.Length(); |
|
1324 readOffset -= 4; |
|
1325 |
|
1326 TInt numNALUnits = 0; |
|
1327 TInt writeOffset = 0; |
|
1328 TInt firstFrameStart = 0; |
|
1329 TInt alignmentBytes = 0; |
|
1330 |
|
1331 numNALUnits = TInt(buffer[readOffset]) + |
|
1332 (TInt(buffer[readOffset + 1]) << 8 ) + |
|
1333 (TInt(buffer[readOffset + 2]) << 16) + |
|
1334 (TInt(buffer[readOffset + 3]) << 24); |
|
1335 |
|
1336 // figure out the payload length of all NAL's to |
|
1337 // determine the number of alignment bytes |
|
1338 |
|
1339 // point to first length field |
|
1340 readOffset -= (numNALUnits - 1) * 8; |
|
1341 readOffset -= 4; |
|
1342 |
|
1343 TInt allNALsLength = 0; |
|
1344 |
|
1345 for (TInt i = 0; i < numNALUnits; i++) |
|
1346 { |
|
1347 TInt len = TInt(buffer[readOffset]) + |
|
1348 (TInt(buffer[readOffset + 1]) << 8) + |
|
1349 (TInt(buffer[readOffset + 2]) << 16) + |
|
1350 (TInt(buffer[readOffset + 3]) << 24); |
|
1351 |
|
1352 allNALsLength += len; |
|
1353 readOffset += 8; |
|
1354 } |
|
1355 |
|
1356 // calculate alignment bytes |
|
1357 alignmentBytes = (allNALsLength % 4 != 0) * ( 4 - (allNALsLength % 4) ); |
|
1358 |
|
1359 // get pointer to end of last frame |
|
1360 writeOffset = buffer.Length() - 4 - numNALUnits * 8; |
|
1361 |
|
1362 // get number of frame NAL's |
|
1363 numNALUnits -= iNumH264SPSPPS; |
|
1364 |
|
1365 // point to offset field of first frame |
|
1366 readOffset = buffer.Length(); |
|
1367 readOffset -= 4; |
|
1368 readOffset -= numNALUnits * 8; |
|
1369 |
|
1370 firstFrameStart = TInt(buffer[readOffset]) + |
|
1371 (TInt(buffer[readOffset + 1]) << 8) + |
|
1372 (TInt(buffer[readOffset + 2]) << 16) + |
|
1373 (TInt(buffer[readOffset + 3]) << 24); |
|
1374 |
|
1375 // The buffer should have enough space for the new NAL header |
|
1376 // if ( frameStart + frameSize + 12 < buffer.Length() ) |
|
1377 |
|
1378 // point to length field of first frame |
|
1379 readOffset += 4; |
|
1380 |
|
1381 // first frame begins from offset 0 |
|
1382 TInt nalOffset = 0; |
|
1383 TInt totalLength = 0; |
|
1384 |
|
1385 for (TInt i = 0; i < numNALUnits; i++) |
|
1386 { |
|
1387 |
|
1388 // read NAL length |
|
1389 TInt length = TInt(buffer[readOffset]) + |
|
1390 (TInt(buffer[readOffset + 1]) << 8) + |
|
1391 (TInt(buffer[readOffset + 2]) << 16) + |
|
1392 (TInt(buffer[readOffset + 3]) << 24); |
|
1393 |
|
1394 totalLength += length; |
|
1395 |
|
1396 // write offset |
|
1397 buffer[writeOffset + 0] = TUint8(nalOffset & 0xff); |
|
1398 buffer[writeOffset + 1] = TUint8((nalOffset >> 8) & 0xff); |
|
1399 buffer[writeOffset + 2] = TUint8((nalOffset >> 16) & 0xff); |
|
1400 buffer[writeOffset + 3] = TUint8((nalOffset >> 24) & 0xff); |
|
1401 |
|
1402 // Write NAL length |
|
1403 writeOffset +=4; |
|
1404 buffer[writeOffset + 0] = TUint8(length & 0xff); |
|
1405 buffer[writeOffset + 1] = TUint8((length >> 8) & 0xff); |
|
1406 buffer[writeOffset + 2] = TUint8((length >> 16) & 0xff); |
|
1407 buffer[writeOffset + 3] = TUint8((length >> 24) & 0xff); |
|
1408 |
|
1409 writeOffset += 4; |
|
1410 readOffset += 8; |
|
1411 |
|
1412 nalOffset += length; |
|
1413 } |
|
1414 |
|
1415 // Write the number of NAL units |
|
1416 buffer[writeOffset + 0] = TUint8(numNALUnits & 0xff); |
|
1417 buffer[writeOffset + 1] = TUint8((numNALUnits >> 8) & 0xff); |
|
1418 buffer[writeOffset + 2] = TUint8((numNALUnits >> 16) & 0xff); |
|
1419 buffer[writeOffset + 3] = TUint8((numNALUnits >> 24) & 0xff); |
|
1420 |
|
1421 // Get a pointer to the position where the frame starts |
|
1422 TPtrC8 tmp(buffer.Ptr() + firstFrameStart, totalLength + alignmentBytes + numNALUnits * 8 + 4); |
|
1423 |
|
1424 // Set output media buffer |
|
1425 iOutputMediaBuffer->Set( tmp, static_cast<CCMRMediaBuffer::TBufferType>(iBufferType), |
|
1426 tmp.Length(), newBuffer->iRandomAccessPoint, |
|
1427 newBuffer->iCaptureTimestamp ); |
|
1428 |
|
1429 outputMediaBufferSet = ETrue; |
|
1430 |
|
1431 } |
|
1432 } |
|
1433 |
|
1434 if (!outputMediaBufferSet) |
|
1435 { |
|
1436 iOutputMediaBuffer->Set( newBuffer->iData, static_cast<CCMRMediaBuffer::TBufferType>(iBufferType), |
|
1437 newBuffer->iData.Length(), newBuffer->iRandomAccessPoint, |
|
1438 newBuffer->iCaptureTimestamp ); |
|
1439 } |
|
1440 |
|
1441 iObserver.MtrdvcoNewBuffer(iOutputMediaBuffer); |
|
1442 |
|
1443 // Return buffer to devvideo here, since observer call is synchronous |
|
1444 iDevVideoRecord->ReturnBuffer(newBuffer); |
|
1445 } |
|
1446 else |
|
1447 { |
|
1448 PRINT((_L("CTRVideoEncoderClient::MdvroNewBuffers(), newBuffer is not available, nothing to do"))) |
|
1449 break; |
|
1450 } |
|
1451 } |
|
1452 } |
|
1453 |
|
1454 |
|
1455 // ----------------------------------------------------------------------------- |
|
1456 // CTRVideoEncoderClient::StopL |
|
1457 // Stops encoding synchronously |
|
1458 // (other items were commented in a header). |
|
1459 // ----------------------------------------------------------------------------- |
|
1460 // |
|
1461 void CTRVideoEncoderClient::StopL() |
|
1462 { |
|
1463 PRINT((_L("CTRVideoEncoderClient::StopL(), In"))) |
|
1464 |
|
1465 if (iFatalError == KErrNone) |
|
1466 { |
|
1467 iDevVideoRecord->Stop(); |
|
1468 } |
|
1469 |
|
1470 // Reset flags here |
|
1471 iVolHeaderSent = EFalse; |
|
1472 iState = ETRStopped; |
|
1473 |
|
1474 PRINT((_L("CTRVideoEncoderClient::StopL(), Out"))) |
|
1475 } |
|
1476 |
|
1477 |
|
1478 // ----------------------------------------------------------------------------- |
|
1479 // CTRVideoEncoderClient::AsyncStopL |
|
1480 // Stops encoding asynchronoulsy |
|
1481 // (other items were commented in a header). |
|
1482 // ----------------------------------------------------------------------------- |
|
1483 // |
|
1484 void CTRVideoEncoderClient::AsyncStopL() |
|
1485 { |
|
1486 PRINT((_L("CTRVideoEncoderClient::StopL(), Async In"))) |
|
1487 |
|
1488 if (iFatalError == KErrNone) |
|
1489 { |
|
1490 iDevVideoRecord->InputEnd(); |
|
1491 } |
|
1492 |
|
1493 // Reset flags here |
|
1494 iVolHeaderSent = EFalse; |
|
1495 iState = ETRStopping; |
|
1496 |
|
1497 PRINT((_L("CTRVideoEncoderClient::StopL(), Async Out"))) |
|
1498 } |
|
1499 |
|
1500 |
|
1501 // ----------------------------------------------------------------------------- |
|
1502 // CTRVideoEncoderClient::MdvroStreamEnd |
|
1503 // End of stream is reached |
|
1504 // (other items were commented in a header). |
|
1505 // ----------------------------------------------------------------------------- |
|
1506 // |
|
1507 void CTRVideoEncoderClient::MdvroStreamEnd() |
|
1508 { |
|
1509 PRINT((_L("CTRVideoEncoderClient::MdvpoStreamEnd()"))) |
|
1510 iState = ETRStopped; |
|
1511 iObserver.MtrdvcoEncStreamEnd(); |
|
1512 } |
|
1513 |
|
1514 |
|
1515 // ----------------------------------------------------------------------------- |
|
1516 // CTRVideoEncoderClient::MdvroSupplementalInfoSent |
|
1517 // Signals that the supplemental info send request has completed. The buffer used for supplemental information can be re-used or freed. |
|
1518 // (other items were commented in a header). |
|
1519 // ----------------------------------------------------------------------------- |
|
1520 // |
|
1521 void CTRVideoEncoderClient::MdvroSupplementalInfoSent() |
|
1522 { |
|
1523 } |
|
1524 |
|
1525 |
|
1526 // ----------------------------------------------------------------------------- |
|
1527 // CTRVideoEncoderClient::MdvroFatalError |
|
1528 // Reports the fatal error |
|
1529 // (other items were commented in a header). |
|
1530 // ----------------------------------------------------------------------------- |
|
1531 // |
|
1532 void CTRVideoEncoderClient::MdvroFatalError(TInt aError) |
|
1533 { |
|
1534 PRINT((_L("CTRVideoEncoderClient::MdvroFatalError(), error[%d]"), aError)) |
|
1535 iFatalError = aError; |
|
1536 iObserver.MtrdvcoFatalError(iFatalError); |
|
1537 } |
|
1538 |
|
1539 |
|
1540 // ----------------------------------------------------------------------------- |
|
1541 // CTRVideoEncoderClient::GetCodingStandardSpecificInitOutputLC |
|
1542 // Requests video encoder codinc options |
|
1543 // (other items were commented in a header). |
|
1544 // ----------------------------------------------------------------------------- |
|
1545 // |
|
1546 HBufC8* CTRVideoEncoderClient::GetCodingStandardSpecificInitOutputLC() |
|
1547 { |
|
1548 if ( iDevVideoRecord ) |
|
1549 { |
|
1550 HBufC8* condigDecInfo = iDevVideoRecord->CodingStandardSpecificInitOutputLC(); |
|
1551 |
|
1552 if (condigDecInfo) |
|
1553 { |
|
1554 PRINT((_L("CTRVideoEncoderClient::GetCodingStandardSpecificInitOutputLC(), Vol header length[%d]"), condigDecInfo->Length())) |
|
1555 |
|
1556 if ( (condigDecInfo->Length() > 0) && (condigDecInfo->Length() <= KMaxDesC8Length /*256*/) ) |
|
1557 { |
|
1558 iVolHeader.Des().Copy( condigDecInfo->Des() ); |
|
1559 |
|
1560 // Keep vol length for further use |
|
1561 iVolLength = iVolHeader.Des().Length(); |
|
1562 PRINT((_L("CTRVideoEncoderClient::GetCodingStandardSpecificInitOutputLC(), VolLength[%d]"), iVolLength)) |
|
1563 |
|
1564 // VOS+VO+VOL header is now going to be stored to metadata, it must not be included in mediadata so remove it from the next buffer |
|
1565 iRemoveHeader = ETrue; |
|
1566 iVolHeaderSent = ETrue; |
|
1567 |
|
1568 if ( iCodecType == EH264 ) |
|
1569 { |
|
1570 TPtr8 temp = condigDecInfo->Des(); |
|
1571 |
|
1572 // get number of SPS/PPS units to be able to |
|
1573 // remove them later from a frame buffer |
|
1574 TInt index = condigDecInfo->Length() - 4; |
|
1575 |
|
1576 iNumH264SPSPPS = TInt(temp[index]) + |
|
1577 (TInt(temp[index + 1]) << 8 ) + |
|
1578 (TInt(temp[index + 2]) << 16) + |
|
1579 (TInt(temp[index + 3]) << 24); |
|
1580 |
|
1581 } |
|
1582 |
|
1583 // Return codingInfo to the client |
|
1584 return condigDecInfo; |
|
1585 } |
|
1586 } |
|
1587 } |
|
1588 |
|
1589 // If condigDecInfo is not valid or something is going wrong, return NULL |
|
1590 return NULL; |
|
1591 } |
|
1592 |
|
1593 |
|
1594 // ----------------------------------------------------------------------------- |
|
1595 // CTRVideoEncoderClient::UseDataTransferOptimization |
|
1596 // Client's request to use optimized data transfer via CI |
|
1597 // (other items were commented in a header). |
|
1598 // ----------------------------------------------------------------------------- |
|
1599 // |
|
1600 void CTRVideoEncoderClient::UseDataTransferOptimizationL() |
|
1601 { |
|
1602 PRINT((_L("CTRVideoEncoderClient::UseDataTransferOptimizationL(), In"))) |
|
1603 |
|
1604 // Check buffer management custom interface support before initializing |
|
1605 iVideoBufferManagementCI = (MMmfVideoBufferManagement*)iDevVideoRecord->CustomInterface( iHwDeviceId, KMmfVideoBuffermanagementUid ); |
|
1606 PRINT((_L("CTRVideoEncoderClient::UseDataTransferOptimizationL(), iVideoBufferManagementCI[0x%x]"), iVideoBufferManagementCI)) |
|
1607 |
|
1608 if (iVideoBufferManagementCI) |
|
1609 { |
|
1610 iVideoBufferManagementCI->MmvbmSetObserver(this); |
|
1611 iVideoBufferManagementCI->MmvbmEnable(ETrue); |
|
1612 |
|
1613 // Set buffer options for this mode |
|
1614 MMmfVideoBufferManagement::TBufferOptions bufferOptionsCI; |
|
1615 bufferOptionsCI.iNumInputBuffers = KTRPictureBuffersNumberBMCI; |
|
1616 bufferOptionsCI.iBufferSize = iPictureSize; |
|
1617 iVideoBufferManagementCI->MmvbmSetBufferOptionsL(bufferOptionsCI); |
|
1618 } |
|
1619 else |
|
1620 { |
|
1621 PRINT((_L("CTRVideoEncoderClient::UseDataTransferOptimizationL(), Optimized data transfer is not supported for this hwdevice"))) |
|
1622 User::Leave(KErrNotSupported); |
|
1623 } |
|
1624 |
|
1625 PRINT((_L("CTRVideoEncoderClient::UseDataTransferOptimizationL(), Out"))) |
|
1626 } |
|
1627 |
|
1628 |
|
1629 // ----------------------------------------------------------------------------- |
|
1630 // CTRVideoEncoderClient::MmvbmoNewBuffers |
|
1631 // One or several buffers are available throug CI |
|
1632 // (other items were commented in a header). |
|
1633 // ----------------------------------------------------------------------------- |
|
1634 // |
|
1635 void CTRVideoEncoderClient::MmvbmoNewBuffers() |
|
1636 { |
|
1637 PRINT((_L("CTRVideoEncoderClient::MmvbmoNewBuffers()"))) |
|
1638 |
|
1639 if (iVideoBufferManagementCI) |
|
1640 { |
|
1641 // Call CI observer to the client only in case, if CI was successfully initialized |
|
1642 iObserver.MtrdvcoNewBuffers(); |
|
1643 } |
|
1644 } |
|
1645 |
|
1646 |
|
1647 // ----------------------------------------------------------------------------- |
|
1648 // CTRVideoEncoderClient::MmvbmoReleaseBuffers |
|
1649 // Release buffers |
|
1650 // (other items were commented in a header). |
|
1651 // ----------------------------------------------------------------------------- |
|
1652 // |
|
1653 void CTRVideoEncoderClient::MmvbmoReleaseBuffers() |
|
1654 { |
|
1655 PRINT((_L("CTRVideoEncoderClient::MmvbmoReleaseBuffers()"))) |
|
1656 } |
|
1657 |
|
1658 |
|
1659 // ----------------------------------------------------------------------------- |
|
1660 // CTRVideoEncoderClient::GetTargetVideoPictureL |
|
1661 // Gets target video picture buffer |
|
1662 // (other items were commented in a header). |
|
1663 // ----------------------------------------------------------------------------- |
|
1664 // |
|
1665 TVideoPicture* CTRVideoEncoderClient::GetTargetVideoPictureL() |
|
1666 { |
|
1667 if (iVideoBufferManagementCI) |
|
1668 { |
|
1669 return iVideoBufferManagementCI->MmvbmGetBufferL(iPictureSize); |
|
1670 } |
|
1671 else |
|
1672 { |
|
1673 PRINT((_L("CTRVideoEncoderClient::GetTargetVideoPictureL(), optimized data transfer is not supported"))) |
|
1674 User::Leave(KErrNotSupported); |
|
1675 |
|
1676 // Make compiler happy |
|
1677 return NULL; |
|
1678 } |
|
1679 } |
|
1680 |
|
1681 |
|
1682 // ----------------------------------------------------------------------------- |
|
1683 // CTRVideoEncoderClient::SetRandomAccessPoint |
|
1684 // Requests to set random access point to bitstream |
|
1685 // (other items were commented in a header). |
|
1686 // ----------------------------------------------------------------------------- |
|
1687 // |
|
1688 void CTRVideoEncoderClient::SetRandomAccessPoint() |
|
1689 { |
|
1690 PRINT((_L("CTRVideoEncoderClient::SetRandomAccessPoint(), In"))) |
|
1691 |
|
1692 // There are several ways to requestI-Frame: |
|
1693 // 1. Pause() and immediately resume() should force to encoder to generate I-Frame. |
|
1694 // 2. Set TVideoPictureOption: some of encoders don't support this |
|
1695 // 3. PictureLoss(): some of encoders don't support this |
|
1696 |
|
1697 // Use TVideoPictureOption to request the I-frame later |
|
1698 iSetRandomAccessPoint = ETrue; |
|
1699 |
|
1700 PRINT((_L("CTRVideoEncoderClient::SetRandomAccessPoint(), Out"))) |
|
1701 } |
|
1702 |
|
1703 // ----------------------------------------------------------------------------- |
|
1704 // CTRVideoEncoderClient::EstimateEncodeFrameTimeL |
|
1705 // Returns a time estimate on long it takes to encode one frame |
|
1706 // (other items were commented in a header). |
|
1707 // ----------------------------------------------------------------------------- |
|
1708 // |
|
1709 TReal CTRVideoEncoderClient::EstimateEncodeFrameTimeL(const TTRVideoFormat& aOutput, TInt aCodecType) |
|
1710 { |
|
1711 if (iUid == TUid::Null()) |
|
1712 { |
|
1713 PRINT((_L("CTRVideoEncoderClient::EstimateEncodeFrameTimeL(), no encoder selected yet"))) |
|
1714 User::Leave(KErrNotReady); |
|
1715 } |
|
1716 |
|
1717 TReal time = 0.0; |
|
1718 |
|
1719 // Select the predefined constant using the current settings |
|
1720 if (aCodecType == EH263) |
|
1721 { |
|
1722 time = iAcceleratedCodecSelected ? KTREncodeTimeFactorH263HW : KTREncodeTimeFactorH263SW; |
|
1723 } |
|
1724 else if (aCodecType == EH264) |
|
1725 { |
|
1726 time = iAcceleratedCodecSelected ? KTREncodeTimeFactorH264HW : KTREncodeTimeFactorH264SW; |
|
1727 } |
|
1728 else |
|
1729 { |
|
1730 time = iAcceleratedCodecSelected ? KTREncodeTimeFactorMPEG4HW : KTREncodeTimeFactorMPEG4SW; |
|
1731 } |
|
1732 |
|
1733 // Multiply the time by the resolution of the output frame |
|
1734 time *= static_cast<TReal>(aOutput.iSize.iWidth + aOutput.iSize.iHeight) * KTRTimeFactorScale; |
|
1735 |
|
1736 PRINT((_L("CTRVideoEncoderClient::EstimateEncodeFrameTimeL(), encode frame time: %.2f"), time)) |
|
1737 |
|
1738 return time; |
|
1739 } |
|
1740 |
|
1741 // ----------------------------------------------------------------------------- |
|
1742 // CTRVideoEncoderClient::Pause |
|
1743 // Pauses encoding |
|
1744 // (other items were commented in a header). |
|
1745 // ----------------------------------------------------------------------------- |
|
1746 // |
|
1747 void CTRVideoEncoderClient::Pause() |
|
1748 { |
|
1749 if ((iFatalError == KErrNone) && (iState == ETRRunning)) |
|
1750 { |
|
1751 iDevVideoRecord->Pause(); |
|
1752 iState = ETRPaused; |
|
1753 } |
|
1754 } |
|
1755 |
|
1756 // ----------------------------------------------------------------------------- |
|
1757 // CTRVideoEncoderClient::Resume |
|
1758 // Resumes encoding |
|
1759 // (other items were commented in a header). |
|
1760 // ----------------------------------------------------------------------------- |
|
1761 // |
|
1762 void CTRVideoEncoderClient::Resume() |
|
1763 { |
|
1764 if ((iFatalError == KErrNone) && (iState == ETRPaused)) |
|
1765 { |
|
1766 iDevVideoRecord->Resume(); |
|
1767 iState = ETRRunning; |
|
1768 } |
|
1769 } |
|
1770 |
|
1771 // ----------------------------------------------------------------------------- |
|
1772 // CTRVideoEncoderClient::EnableResourceObserver |
|
1773 // Enable / Disable resourece observer |
|
1774 // (other items were commented in a header). |
|
1775 // ----------------------------------------------------------------------------- |
|
1776 // |
|
1777 void CTRVideoEncoderClient::EnableResourceObserver(TBool aEnable) |
|
1778 { |
|
1779 PRINT((_L("CTRVideoEncoderClient::EnableResourceObserver(), In"))) |
|
1780 |
|
1781 iVideoResourceHandlerCI = (MMmfVideoResourceHandler*)iDevVideoRecord->CustomInterface( iHwDeviceId, KUidMmfVideoResourceManagement ); |
|
1782 PRINT((_L("CTRVideoEncoderClient::EnableResourceObserver(), iVideoResourceHandlerCI[0x%x]"), iVideoResourceHandlerCI)) |
|
1783 |
|
1784 if (iVideoResourceHandlerCI) |
|
1785 { |
|
1786 if (aEnable) |
|
1787 { |
|
1788 iVideoResourceHandlerCI->MmvrhSetObserver(this); |
|
1789 PRINT((_L("CTRVideoEncoderClient::EnableResourceObserver(), Enabled"))) |
|
1790 } |
|
1791 else |
|
1792 { |
|
1793 iVideoResourceHandlerCI->MmvrhSetObserver(NULL); |
|
1794 } |
|
1795 } |
|
1796 |
|
1797 PRINT((_L("CTRVideoEncoderClient::EnableResourceObserver(), Out"))) |
|
1798 } |
|
1799 |
|
1800 // ----------------------------------------------------------------------------- |
|
1801 // CTRVideoEncoderClient::MmvroResourcesLost |
|
1802 // Indicates that a media device has lost its resources |
|
1803 // (other items were commented in a header). |
|
1804 // ----------------------------------------------------------------------------- |
|
1805 // |
|
1806 void CTRVideoEncoderClient::MmvroResourcesLost(TUid /*aMediaDevice*/) |
|
1807 { |
|
1808 iObserver.MtrdvcoResourcesLost(EFalse); |
|
1809 } |
|
1810 |
|
1811 |
|
1812 // ----------------------------------------------------------------------------- |
|
1813 // CTRVideoEncoderClient::MmvroResourcesRestored |
|
1814 // Indicates that a media device has regained its resources |
|
1815 // (other items were commented in a header). |
|
1816 // ----------------------------------------------------------------------------- |
|
1817 // |
|
1818 void CTRVideoEncoderClient::MmvroResourcesRestored(TUid /*aMediaDevice*/) |
|
1819 { |
|
1820 iObserver.MtrdvcoResourcesRestored(); |
|
1821 } |
|
1822 |
|
1823 // End of file |
|
1824 |
|