|
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 * Implementation for video encoder. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "statusmonitor.h" |
|
22 #include "videoencoder.h" |
|
23 #include "vedvideosettings.h" |
|
24 #include "vedvolreader.h" |
|
25 #include "vedavcedit.h" |
|
26 |
|
27 |
|
28 // Assertion macro wrapper for code cleanup |
|
29 #define VEASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CVIDEOENCODER"), EInternalAssertionFailure)) |
|
30 |
|
31 // Debug print macro |
|
32 #ifdef _DEBUG |
|
33 #include <e32svr.h> |
|
34 #define PRINT(x) RDebug::Print x |
|
35 #else |
|
36 #define PRINT(x) |
|
37 #endif |
|
38 |
|
39 // Constants |
|
40 |
|
41 |
|
42 // time increment resolution |
|
43 const TUint KTimeIncrementResolutionHW = 30000; |
|
44 //const TUint KTimeIncrementResolutionSW = 29; |
|
45 |
|
46 const TReal KMinRandomAccessRate = 0.2; |
|
47 //const TUint KPictureQuality = 50; |
|
48 //const TReal KLatencyQyalityTradeoff = 1.0; |
|
49 //const TReal KQualityTemporalTradeoff = 0.8; |
|
50 //const TBool KEncodingRealTime = EFalse; |
|
51 |
|
52 |
|
53 // ================= MEMBER FUNCTIONS ======================= |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CVideoEncoder::NewL |
|
57 // Two-phased constructor. |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 |
|
61 CVideoEncoder* CVideoEncoder::NewL(CStatusMonitor *aMonitor, CVedAVCEdit* aAvcEdit, |
|
62 const TPtrC8& aVideoMimeType) |
|
63 { |
|
64 PRINT((_L("CVideoEncoder::NewL() : MDF"))); |
|
65 |
|
66 CVideoEncoder* self = new (ELeave) CVideoEncoder(); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(aMonitor, aAvcEdit, aVideoMimeType); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 CVideoEncoder::CVideoEncoder() : CActive(EPriorityStandard), iInputBuffer(0,0) |
|
76 { |
|
77 iPreviousTimeStamp = TTimeIntervalMicroSeconds(0); |
|
78 iKeyFrame = EFalse; |
|
79 } |
|
80 |
|
81 |
|
82 void CVideoEncoder::ConstructL(CStatusMonitor *aMonitor, CVedAVCEdit* aAvcEdit, |
|
83 const TPtrC8& aVideoMimeType) |
|
84 { |
|
85 iTranscoder = NULL; |
|
86 iMonitor = aMonitor; |
|
87 iAvcEdit = aAvcEdit; |
|
88 |
|
89 iFrameSize = KVedResolutionQCIF; |
|
90 iFrameRate = 15.0; |
|
91 iInputFrameRate = 15.0; |
|
92 iRandomAccessRate = KMinRandomAccessRate; |
|
93 |
|
94 // interpret and store video codec MIME-type. Allocates also iDataBuffer |
|
95 SetVideoCodecL( aVideoMimeType ); |
|
96 |
|
97 iStatus = NULL; |
|
98 |
|
99 iVolReader = CVedVolReader::NewL(); |
|
100 |
|
101 // allocate input picture |
|
102 iInputPicture = new (ELeave) TTRVideoPicture; |
|
103 |
|
104 // Create a timer |
|
105 User::LeaveIfError(iTimer.CreateLocal()); |
|
106 iTimerCreated = ETrue; |
|
107 |
|
108 // Add us to active scheduler |
|
109 CActiveScheduler::Add(this); |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CVideoEncoder::~CVideoEncoder() |
|
115 // Destructor |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 CVideoEncoder::~CVideoEncoder() |
|
119 { |
|
120 |
|
121 Cancel(); |
|
122 |
|
123 if ( iInputPicture ) |
|
124 { |
|
125 delete iInputPicture; |
|
126 iInputPicture = 0; |
|
127 } |
|
128 |
|
129 if ( iDataBuffer ) |
|
130 { |
|
131 delete iDataBuffer; |
|
132 iDataBuffer = 0; |
|
133 } |
|
134 |
|
135 if ( iTranscoder ) |
|
136 { |
|
137 delete iTranscoder; |
|
138 iTranscoder = 0; |
|
139 } |
|
140 |
|
141 if ( iVolReader ) |
|
142 { |
|
143 delete iVolReader; |
|
144 iVolReader = 0; |
|
145 } |
|
146 |
|
147 if ( iTimerCreated ) |
|
148 { |
|
149 iTimer.Close(); |
|
150 iTimerCreated = EFalse; |
|
151 } |
|
152 |
|
153 |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------- |
|
158 // CVideoEncoder::SetVideoCodecL() |
|
159 // Interpret and store video mime type |
|
160 // --------------------------------------------------------- |
|
161 // |
|
162 void CVideoEncoder::SetVideoCodecL(const TPtrC8& aMimeType) |
|
163 { |
|
164 TBuf8<256> string; |
|
165 TBuf8<256> newMimeType; |
|
166 string = KVedMimeTypeH263; |
|
167 string += _L8( "*" ); |
|
168 TInt dataBufferSize = KMaxCodedPictureSizeQCIF; |
|
169 |
|
170 iMaxFrameRate = 15.0; |
|
171 iArbitrarySizeAllowed = EFalse; |
|
172 |
|
173 if ( aMimeType.MatchF( (const TDesC8& )string ) != KErrNotFound ) |
|
174 { |
|
175 // H.263 |
|
176 |
|
177 newMimeType = KVedMimeTypeH263; |
|
178 |
|
179 if ( aMimeType.MatchF( _L8("*profile*") ) != KErrNotFound ) |
|
180 { |
|
181 // profile given, check if we support it |
|
182 if ( aMimeType.MatchF( _L8("*profile=0*")) != KErrNotFound ) |
|
183 { |
|
184 // profile 0 requested |
|
185 newMimeType += _L8( "; profile=0" ); |
|
186 } |
|
187 else |
|
188 { |
|
189 // no other profiles supported |
|
190 PRINT((_L("CVideoEncoder::SetVideoCodecL() unsupported profile"))); |
|
191 User::Leave(KErrNotSupported); |
|
192 } |
|
193 } |
|
194 else |
|
195 { |
|
196 // no profile is given => assume 0 |
|
197 newMimeType += _L8( "; profile=0" ); |
|
198 } |
|
199 |
|
200 if ( aMimeType.MatchF( _L8("*level=10*") ) != KErrNotFound ) |
|
201 { |
|
202 iMaxBitRate = iBitRate = KVedBitRateH263Level10; |
|
203 iMaxResolution = KVedResolutionQCIF; |
|
204 dataBufferSize = KMaxCodedPictureSizeQCIF; |
|
205 newMimeType += _L8( "; level=10" ); |
|
206 } |
|
207 else if ( aMimeType.MatchF( _L8("*level=45*") ) != KErrNotFound ) |
|
208 { |
|
209 iMaxBitRate = iBitRate = KVedBitRateH263Level45; |
|
210 iMaxResolution = KVedResolutionQCIF; |
|
211 dataBufferSize = KMaxCodedPictureSizeQCIF; |
|
212 newMimeType += _L8( "; level=45" ); |
|
213 } |
|
214 else if ( aMimeType.MatchF( _L8("*level*") ) != KErrNotFound ) |
|
215 { |
|
216 // no other levels supported |
|
217 PRINT((_L("CVideoEncoder::SetVideoCodecL() unsupported level"))); |
|
218 User::Leave(KErrNotSupported); |
|
219 } |
|
220 else |
|
221 { |
|
222 // if no level is given assume 10 |
|
223 iMaxBitRate = iBitRate = KVedBitRateH263Level10; |
|
224 iMaxResolution = KVedResolutionQCIF; |
|
225 dataBufferSize = KMaxCodedPictureSizeQCIF; |
|
226 newMimeType += _L8( "; level=10" ); |
|
227 } |
|
228 } |
|
229 else |
|
230 { |
|
231 string = KVedMimeTypeMPEG4Visual; |
|
232 string += _L8( "*" ); |
|
233 |
|
234 if ( aMimeType.MatchF( string ) != KErrNotFound ) |
|
235 { |
|
236 // MPEG-4 Visual |
|
237 newMimeType = KVedMimeTypeMPEG4Visual; |
|
238 if ( aMimeType.MatchF( _L8("*profile-level-id=8*") ) != KErrNotFound ) |
|
239 { |
|
240 // simple profile level 0 |
|
241 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level0; |
|
242 iMaxResolution = KVedResolutionQCIF; |
|
243 // define max size 10K |
|
244 dataBufferSize = KMaxCodedPictureSizeMPEG4QCIF; |
|
245 newMimeType += _L8("; profile-level-id=8"); |
|
246 } |
|
247 else if ( aMimeType.MatchF( _L8("*profile-level-id=9*") ) != KErrNotFound ) |
|
248 { |
|
249 // simple profile level 0b |
|
250 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level0; |
|
251 iMaxResolution = KVedResolutionQCIF; |
|
252 // define max size 10K |
|
253 dataBufferSize = KMaxCodedPictureSizeMPEG4QCIF; |
|
254 newMimeType += _L8("; profile-level-id=9"); |
|
255 } |
|
256 else if ( aMimeType.MatchF( _L8("*profile-level-id=1*") ) != KErrNotFound ) |
|
257 { |
|
258 // simple profile level 1 |
|
259 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level0; |
|
260 iMaxResolution = KVedResolutionQCIF; |
|
261 // define max size 10K |
|
262 dataBufferSize = KMaxCodedPictureSizeMPEG4QCIF; |
|
263 iArbitrarySizeAllowed = ETrue; |
|
264 newMimeType += _L8("; profile-level-id=1"); |
|
265 } |
|
266 else if ( aMimeType.MatchF( _L8("*profile-level-id=2*") ) != KErrNotFound ) |
|
267 { |
|
268 // simple profile level 2 |
|
269 dataBufferSize = KMaxCodedPictureSizeMPEG4CIF; |
|
270 iMaxResolution = KVedResolutionCIF; |
|
271 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level2; |
|
272 iArbitrarySizeAllowed = ETrue; |
|
273 newMimeType += _L8("; profile-level-id=2"); |
|
274 } |
|
275 else if ( aMimeType.MatchF( _L8("*profile-level-id=3*") ) != KErrNotFound ) |
|
276 { |
|
277 // simple profile level 3 |
|
278 dataBufferSize = KMaxCodedPictureSizeMPEG4CIF; |
|
279 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level2; |
|
280 iMaxResolution = KVedResolutionCIF; |
|
281 iMaxFrameRate = 30.0; |
|
282 iArbitrarySizeAllowed = ETrue; |
|
283 newMimeType += _L8("; profile-level-id=3"); |
|
284 } |
|
285 else if ( aMimeType.MatchF( _L8("*profile-level-id=4*") ) != KErrNotFound ) |
|
286 { |
|
287 // simple profile level 4a |
|
288 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level4A; |
|
289 dataBufferSize = KMaxCodedPictureSizeVGA; |
|
290 iMaxResolution = KVedResolutionVGA; |
|
291 iMaxFrameRate = 30.0; |
|
292 iArbitrarySizeAllowed = ETrue; |
|
293 newMimeType += _L8("; profile-level-id=4"); |
|
294 } |
|
295 else if ( aMimeType.MatchF( _L8("*profile-level-id=*") ) != KErrNotFound ) |
|
296 { |
|
297 // no other profile-level ids supported |
|
298 PRINT((_L("CVideoEncoder::SetVideoCodecL() unsupported MPEG-4 profile-level"))); |
|
299 User::Leave(KErrNotSupported); |
|
300 } |
|
301 else |
|
302 { |
|
303 // Default is level 0 in our case (normally probably level 1) |
|
304 iMaxBitRate = iBitRate = KVedBitRateMPEG4Level0; |
|
305 iMaxResolution = KVedResolutionQCIF; |
|
306 // define max size 10K |
|
307 dataBufferSize = KMaxCodedPictureSizeMPEG4QCIF; |
|
308 newMimeType += _L8("; profile-level-id=8"); |
|
309 } |
|
310 } |
|
311 else |
|
312 { |
|
313 |
|
314 #ifdef VIDEOEDITORENGINE_AVC_EDITING |
|
315 string = KVedMimeTypeAVC; |
|
316 string += _L8( "*" ); |
|
317 if ( aMimeType.MatchF( string ) != KErrNotFound ) |
|
318 { |
|
319 // AVC |
|
320 newMimeType = KVedMimeTypeAVC; |
|
321 if ( aMimeType.MatchF( _L8("*profile-level-id=42800A*") ) != KErrNotFound ) |
|
322 { |
|
323 // baseline profile level 1 |
|
324 iMaxBitRate = iBitRate = KVedBitRateAVCLevel1; |
|
325 iMaxResolution = KVedResolutionQCIF; |
|
326 dataBufferSize = KMaxCodedPictureSizeAVCLevel1; |
|
327 iArbitrarySizeAllowed = ETrue; |
|
328 newMimeType += _L8("; profile-level-id=42800A"); |
|
329 } |
|
330 else if ( aMimeType.MatchF( _L8("*profile-level-id=42900B*") ) != KErrNotFound ) |
|
331 { |
|
332 // baseline profile level 1b |
|
333 iMaxBitRate = iBitRate = KVedBitRateAVCLevel1b; |
|
334 iMaxResolution = KVedResolutionQCIF; |
|
335 dataBufferSize = KMaxCodedPictureSizeAVCLevel1B; |
|
336 iArbitrarySizeAllowed = ETrue; |
|
337 newMimeType += _L8("; profile-level-id=42900B"); |
|
338 } |
|
339 else if ( aMimeType.MatchF( _L8("*profile-level-id=42800B*") ) != KErrNotFound ) |
|
340 { |
|
341 // baseline profile level 1.1 |
|
342 iMaxBitRate = iBitRate = KVedBitRateAVCLevel1_1; |
|
343 iMaxResolution = KVedResolutionCIF; |
|
344 dataBufferSize = KMaxCodedPictureSizeAVCLevel1_1; |
|
345 iArbitrarySizeAllowed = ETrue; |
|
346 newMimeType += _L8("; profile-level-id=42800B"); |
|
347 } |
|
348 else if ( aMimeType.MatchF( _L8("*profile-level-id=42800C*") ) != KErrNotFound ) |
|
349 { |
|
350 // baseline profile level 1.2 |
|
351 iMaxBitRate = iBitRate = KVedBitRateAVCLevel1_2; |
|
352 iMaxResolution = KVedResolutionCIF; |
|
353 dataBufferSize = KMaxCodedPictureSizeAVCLevel1_2; |
|
354 iArbitrarySizeAllowed = ETrue; |
|
355 newMimeType += _L8("; profile-level-id=42800C"); |
|
356 } |
|
357 //WVGA task |
|
358 else if ( aMimeType.MatchF( _L8("*profile-level-id=42801F*") ) != KErrNotFound ) |
|
359 { |
|
360 // baseline profile level 1.3 |
|
361 iMaxBitRate = iBitRate = KVedBitRateAVCLevel3_1; |
|
362 iMaxResolution = KVedResolutionWVGA; |
|
363 dataBufferSize = KMaxCodedPictureSizeAVCLevel3_1; |
|
364 iArbitrarySizeAllowed = ETrue; |
|
365 newMimeType += _L8("; profile-level-id=42801F"); |
|
366 } |
|
367 else if ( aMimeType.MatchF( _L8("*profile-level-id=*") ) != KErrNotFound ) |
|
368 { |
|
369 // no other profile-level ids supported |
|
370 PRINT((_L("CVideoEncoder::SetVideoCodecL() unsupported AVC profile-level"))); |
|
371 User::Leave(KErrNotSupported); |
|
372 } |
|
373 else |
|
374 { |
|
375 // Default is level 1 (?) |
|
376 iMaxBitRate = iBitRate = KVedBitRateAVCLevel1; |
|
377 iMaxResolution = KVedResolutionQCIF; |
|
378 dataBufferSize = KMaxCodedPictureSizeAVCLevel1; |
|
379 newMimeType += _L8("; profile-level-id=42800A"); |
|
380 } |
|
381 } |
|
382 else |
|
383 { |
|
384 // unknown mimetype |
|
385 User::Leave( KErrNotSupported ); |
|
386 } |
|
387 #else |
|
388 // unknown mimetype |
|
389 User::Leave( KErrNotSupported ); |
|
390 #endif |
|
391 } |
|
392 } |
|
393 |
|
394 // successfully interpreted the input mime type |
|
395 iMimeType = newMimeType; |
|
396 if ( iDataBuffer ) |
|
397 { |
|
398 delete iDataBuffer; |
|
399 iDataBuffer = NULL; |
|
400 } |
|
401 iDataBuffer = (HBufC8*) HBufC8::NewL(dataBufferSize); |
|
402 |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CVideoEncoder::SetFrameSizeL |
|
407 // Sets the used frame size |
|
408 // (other items were commented in a header). |
|
409 // --------------------------------------------------------- |
|
410 // |
|
411 void CVideoEncoder::SetFrameSizeL(const TSize& aSize) |
|
412 { |
|
413 |
|
414 if (iFrameSize == aSize) |
|
415 return; |
|
416 |
|
417 if ( (aSize.iWidth > iMaxResolution.iWidth) || (aSize.iHeight > iMaxResolution.iHeight)) |
|
418 { |
|
419 if ( iArbitrarySizeAllowed ) // This is for future-proofness. Currently the checking of standard sizes below overrules this one |
|
420 { |
|
421 if ( aSize.iWidth * aSize.iHeight > iMaxResolution.iWidth*iMaxResolution.iHeight ) |
|
422 { |
|
423 PRINT((_L("CVideoEncoder::SetFrameSizeL() too high resolution requested"))); |
|
424 User::Leave( KErrNotSupported ); |
|
425 } |
|
426 } |
|
427 else |
|
428 { |
|
429 PRINT((_L("CVideoEncoder::SetFrameSizeL() incompatible or too high resolution requested"))); |
|
430 User::Leave( KErrNotSupported ); |
|
431 } |
|
432 } |
|
433 |
|
434 // check new size. For now only standard sizes are allowed |
|
435 if ( (aSize != KVedResolutionSubQCIF) && |
|
436 (aSize != KVedResolutionQCIF) && |
|
437 (aSize != KVedResolutionCIF) && |
|
438 (aSize != KVedResolutionQVGA) && |
|
439 (aSize != KVedResolutionVGA16By9) && |
|
440 (aSize != KVedResolutionVGA) && |
|
441 //WVGA task |
|
442 (aSize != KVedResolutionWVGA) ) |
|
443 { |
|
444 User::Leave( KErrArgument ); |
|
445 } |
|
446 |
|
447 iFrameSize = aSize; |
|
448 |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------- |
|
452 // CVideoEncoder::GetFrameSize |
|
453 // Gets the used frame size |
|
454 // (other items were commented in a header). |
|
455 // --------------------------------------------------------- |
|
456 // |
|
457 void CVideoEncoder::FrameSize(TSize& aSize) const |
|
458 { |
|
459 |
|
460 aSize = iFrameSize; |
|
461 |
|
462 } |
|
463 |
|
464 // --------------------------------------------------------- |
|
465 // CVideoEncoder::SetFrameRate |
|
466 // Sets the used targt frame rate |
|
467 // (other items were commented in a header). |
|
468 // --------------------------------------------------------- |
|
469 // |
|
470 TInt CVideoEncoder::SetFrameRate(const TReal aFrameRate) |
|
471 { |
|
472 VEASSERT(aFrameRate > 0.0); |
|
473 |
|
474 if ( aFrameRate <= iMaxFrameRate ) |
|
475 { |
|
476 iFrameRate = TReal32(aFrameRate); |
|
477 } |
|
478 else |
|
479 { |
|
480 iFrameRate = iMaxFrameRate; |
|
481 } |
|
482 |
|
483 // target framerate cannot be larger than source framerate |
|
484 if (iFrameRate > iInputFrameRate) |
|
485 iFrameRate = iInputFrameRate; |
|
486 |
|
487 return KErrNone; |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------- |
|
491 // CVideoEncoder::SetInputFrameRate |
|
492 // Sets the used input sequence frame rate |
|
493 // (other items were commented in a header). |
|
494 // --------------------------------------------------------- |
|
495 // |
|
496 TInt CVideoEncoder::SetInputFrameRate(const TReal aFrameRate) |
|
497 { |
|
498 |
|
499 VEASSERT(aFrameRate > 0.0); |
|
500 |
|
501 iInputFrameRate = aFrameRate; |
|
502 |
|
503 // target framerate cannot be larger than source framerate |
|
504 if (iFrameRate > iInputFrameRate) |
|
505 iFrameRate = iInputFrameRate; |
|
506 |
|
507 return KErrNone; |
|
508 |
|
509 } |
|
510 |
|
511 |
|
512 // --------------------------------------------------------- |
|
513 // CVideoEncoder::SetRandomAccessRate |
|
514 // Sets the used target random access rate |
|
515 // (other items were commented in a header). |
|
516 // --------------------------------------------------------- |
|
517 // |
|
518 TInt CVideoEncoder::SetRandomAccessRate(const TReal aRate) |
|
519 { |
|
520 VEASSERT(aRate > 0.0); |
|
521 |
|
522 iRandomAccessRate = aRate; |
|
523 |
|
524 return KErrNone; |
|
525 } |
|
526 |
|
527 // --------------------------------------------------------- |
|
528 // CVideoEncoder::SetBitrate |
|
529 // Sets the used target bitrate |
|
530 // (other items were commented in a header). |
|
531 // --------------------------------------------------------- |
|
532 // |
|
533 TInt CVideoEncoder::SetBitrate(const TInt aBitrate) |
|
534 { |
|
535 VEASSERT(aBitrate > 0); |
|
536 |
|
537 if ( aBitrate <= iMaxBitRate ) |
|
538 { |
|
539 iBitRate = aBitrate; |
|
540 } |
|
541 else |
|
542 { |
|
543 iBitRate = iMaxBitRate; |
|
544 } |
|
545 |
|
546 return KErrNone; |
|
547 |
|
548 } |
|
549 |
|
550 // -------------------------------------------------------- |
|
551 |
|
552 |
|
553 |
|
554 // --------------------------------------------------------- |
|
555 // CVideoEncoder::InitializeL |
|
556 // Initializes the encoder |
|
557 // (other items were commented in a header). |
|
558 // --------------------------------------------------------- |
|
559 // |
|
560 void CVideoEncoder::InitializeL(TRequestStatus &aStatus) |
|
561 { |
|
562 |
|
563 PRINT((_L("CVideoEncoder::InitializeL() in"))); |
|
564 |
|
565 iResetRequestStatus = &aStatus; |
|
566 |
|
567 // Create DevVideoRecord & select video encoder |
|
568 |
|
569 if ( iTranscoder ) |
|
570 { |
|
571 // need to recreate since parameters changed |
|
572 delete iTranscoder; |
|
573 iTranscoder = 0; |
|
574 } |
|
575 |
|
576 iFatalError = EFalse; |
|
577 |
|
578 iTranscoder = CTRTranscoder::NewL(*this); |
|
579 |
|
580 // Select & set parameters to transcoder |
|
581 TRAPD(err, SetupEncoderL()); |
|
582 |
|
583 if ( err != KErrNone ) |
|
584 { |
|
585 // error |
|
586 User::Leave( err ); |
|
587 } |
|
588 |
|
589 iTranscoder->InitializeL(); |
|
590 |
|
591 PRINT((_L("CVideoEncoder::InitializeL() out"))); |
|
592 |
|
593 |
|
594 } |
|
595 |
|
596 // --------------------------------------------------------- |
|
597 // CVideoEncoder::Start |
|
598 // Starts the encoder |
|
599 // (other items were commented in a header). |
|
600 // --------------------------------------------------------- |
|
601 // |
|
602 |
|
603 void CVideoEncoder::Start() |
|
604 { |
|
605 TRAPD( error, iTranscoder->StartL() ); |
|
606 |
|
607 if (error != KErrNone) |
|
608 { |
|
609 if (iMonitor) |
|
610 iMonitor->Error(error); |
|
611 } |
|
612 } |
|
613 |
|
614 |
|
615 // --------------------------------------------------------- |
|
616 // CVideoEncoder::SetRandomAccessPoint |
|
617 // Forces the next encoded frame to Intra |
|
618 // (other items were commented in a header). |
|
619 // --------------------------------------------------------- |
|
620 // |
|
621 void CVideoEncoder::SetRandomAccessPoint() |
|
622 { |
|
623 VEASSERT(iTranscoder); |
|
624 |
|
625 iTranscoder->SetRandomAccessPoint(); |
|
626 |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------- |
|
630 // CVideoEncoder::Stop |
|
631 // Stops the encoder |
|
632 // (other items were commented in a header). |
|
633 // --------------------------------------------------------- |
|
634 // |
|
635 void CVideoEncoder::Stop() |
|
636 { |
|
637 |
|
638 if ( !iFatalError ) |
|
639 { |
|
640 |
|
641 if (iStarted) |
|
642 { |
|
643 TRAPD( error, iTranscoder->StopL() ); |
|
644 if (error != KErrNone) |
|
645 { |
|
646 if (iMonitor) |
|
647 iMonitor->Error(error); |
|
648 } |
|
649 } |
|
650 |
|
651 iStarted = EFalse; |
|
652 } |
|
653 } |
|
654 |
|
655 |
|
656 // --------------------------------------------------------- |
|
657 // CVideoEncoder::Reset |
|
658 // Resets the encoder |
|
659 // (other items were commented in a header). |
|
660 // --------------------------------------------------------- |
|
661 // |
|
662 void CVideoEncoder::Reset(TRequestStatus &aStatus) |
|
663 { |
|
664 |
|
665 PRINT((_L("CVideoEncoder::Reset() in"))); |
|
666 |
|
667 iPreviousTimeStamp = TTimeIntervalMicroSeconds(0); |
|
668 |
|
669 iResetRequestStatus = &aStatus; |
|
670 |
|
671 if ( iFatalError ) |
|
672 { |
|
673 MtroAsyncStopComplete(); |
|
674 } |
|
675 else |
|
676 { |
|
677 TRAPD(err, iTranscoder->AsyncStopL()); |
|
678 if (err != KErrNone) |
|
679 iMonitor->Error(err); |
|
680 } |
|
681 |
|
682 iStarted = EFalse; |
|
683 |
|
684 PRINT((_L("CVideoEncoder::Reset() out"))); |
|
685 } |
|
686 |
|
687 void CVideoEncoder::Reset() |
|
688 { |
|
689 |
|
690 PRINT((_L("CVideoEncoder::Reset() (sync.) in"))); |
|
691 |
|
692 iPreviousTimeStamp = TTimeIntervalMicroSeconds(0); |
|
693 |
|
694 if ( !iFatalError ) |
|
695 { |
|
696 if (iStarted) |
|
697 { |
|
698 TRAPD(err, iTranscoder->StopL()); |
|
699 if (err != KErrNone) |
|
700 iMonitor->Error(err); |
|
701 } |
|
702 } |
|
703 |
|
704 iStarted = EFalse; |
|
705 |
|
706 PRINT((_L("CVideoEncoder::Reset() (sync.) out"))); |
|
707 } |
|
708 |
|
709 // --------------------------------------------------------- |
|
710 // CVideoEncoder::RunL |
|
711 // Active object running method. |
|
712 // (other items were commented in a header). |
|
713 // --------------------------------------------------------- |
|
714 // |
|
715 void CVideoEncoder::RunL() |
|
716 { |
|
717 |
|
718 // Timer elapsed, complete encoding request |
|
719 // with KErrCancel |
|
720 |
|
721 PRINT((_L("CVideoEncoder::RunL() in"))); |
|
722 |
|
723 if (iTimerRequestPending) |
|
724 { |
|
725 iTimerRequestPending = EFalse; |
|
726 if (iEncodeRequestStatus) |
|
727 { |
|
728 #ifdef _DEBUG |
|
729 TTime current; |
|
730 current.UniversalTime(); |
|
731 TInt64 time = current.MicroSecondsFrom(iEncodeStartTime).Int64(); |
|
732 PRINT((_L("CVideoEncoder::RunL(), completing request, time since encoding started %d"), I64INT( time ))); |
|
733 #endif |
|
734 |
|
735 VEASSERT(*iEncodeRequestStatus == KRequestPending); |
|
736 // complete request |
|
737 User::RequestComplete(iEncodeRequestStatus, KErrCancel); |
|
738 iEncodeRequestStatus = 0; |
|
739 iEncodePending = EFalse; |
|
740 } |
|
741 } |
|
742 PRINT((_L("CVideoEncoder::RunL() out"))); |
|
743 |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CVideoEncoder::RunError |
|
748 // Active object error method. |
|
749 // (other items were commented in a header). |
|
750 // --------------------------------------------------------- |
|
751 // |
|
752 TInt CVideoEncoder::RunError(TInt aError) |
|
753 { |
|
754 PRINT((_L("CVideoEncoder::RunError() in"))); |
|
755 |
|
756 Cancel(); |
|
757 |
|
758 iMonitor->Error(aError); |
|
759 |
|
760 PRINT((_L("CVideoEncoder::RunError() out"))); |
|
761 |
|
762 return KErrNone; |
|
763 } |
|
764 |
|
765 // --------------------------------------------------------- |
|
766 // CVideoEncoder::DoCancel |
|
767 // Active object cancelling method |
|
768 // (other items were commented in a header). |
|
769 // --------------------------------------------------------- |
|
770 // |
|
771 void CVideoEncoder::DoCancel() |
|
772 { |
|
773 |
|
774 PRINT((_L("CVideoEncoder::DoCancel() in"))); |
|
775 |
|
776 // Cancel our timer request if we have one |
|
777 if ( iTimerRequestPending ) |
|
778 { |
|
779 iTimer.Cancel(); |
|
780 iTimerRequestPending = EFalse; |
|
781 return; |
|
782 } |
|
783 |
|
784 } |
|
785 |
|
786 // --------------------------------------------------------- |
|
787 // CVideoEncoder::EncodeFrameL |
|
788 // Encodes a frame |
|
789 // (other items were commented in a header). |
|
790 // --------------------------------------------------------- |
|
791 // |
|
792 void CVideoEncoder::EncodeFrameL(TPtr8& aYUVFrame, TRequestStatus &aStatus, TTimeIntervalMicroSeconds aTimeStamp) |
|
793 { |
|
794 PRINT((_L("CVideoEncoder::EncodeFrameL() in, aTimeStamp = %d"), I64INT( aTimeStamp.Int64() ) )); |
|
795 |
|
796 if ( iFatalError ) |
|
797 { |
|
798 PRINT((_L("CVideoEncoder::EncodeFrameL() can't encode since fatal error has occurred earlier"))); |
|
799 User::Leave( KErrGeneral ); |
|
800 } |
|
801 |
|
802 iEncodeRequestStatus = &aStatus; |
|
803 |
|
804 if (!iStarted) |
|
805 { |
|
806 PRINT((_L("CVideoEncoder::EncodeFrameL() - starting devVideoRec"))); |
|
807 //iTranscoder->StopL(); // NOTE: needed ?? |
|
808 iTranscoder->StartL(); |
|
809 iStarted = ETrue; |
|
810 } |
|
811 |
|
812 // wrap input frame to encoder input buffer |
|
813 iInputBuffer.Set(aYUVFrame); |
|
814 iInputPicture->iRawData = &iInputBuffer; |
|
815 iInputPicture->iDataSize.SetSize(iFrameSize.iWidth, iFrameSize.iHeight); |
|
816 |
|
817 if (aTimeStamp > TTimeIntervalMicroSeconds(0)) |
|
818 { |
|
819 TInt64 diff = aTimeStamp.Int64() - iPreviousTimeStamp.Int64(); |
|
820 |
|
821 if (diff < 0) |
|
822 { |
|
823 aTimeStamp = iPreviousTimeStamp.Int64() + TInt64(66667); |
|
824 } |
|
825 // NOTE: Could the real difference between two consecutive |
|
826 // frames be used instead of assuming 15 fps ? |
|
827 } |
|
828 iPreviousTimeStamp = aTimeStamp; |
|
829 |
|
830 iInputPicture->iTimestamp = aTimeStamp; |
|
831 //iInputPicture->iLink = NULL; |
|
832 iInputPicture->iUser = this; |
|
833 |
|
834 #ifdef _DEBUG |
|
835 iEncodeStartTime.UniversalTime(); |
|
836 #endif |
|
837 |
|
838 |
|
839 iEncodePending = ETrue; |
|
840 |
|
841 iTranscoder->SendPictureToTranscoderL( iInputPicture ); |
|
842 |
|
843 PRINT((_L("CVideoEncoder::EncodeFrameL() out"))); |
|
844 |
|
845 } |
|
846 |
|
847 |
|
848 // --------------------------------------------------------- |
|
849 // CVideoEncoder::GetBuffer |
|
850 // Gets encoded frame bitstream buffer |
|
851 // (other items were commented in a header). |
|
852 // --------------------------------------------------------- |
|
853 // |
|
854 TPtrC8& CVideoEncoder::GetBufferL(TBool& aKeyFrame) |
|
855 { |
|
856 if ( iFatalError ) |
|
857 { |
|
858 User::Leave( KErrNotReady ); |
|
859 } |
|
860 |
|
861 VEASSERT(iDataBuffer->Length() > 0); |
|
862 |
|
863 PRINT((_L("CVideoEncoder::GetBufferL(), keyFrame = %d"), iKeyFrame)); |
|
864 |
|
865 aKeyFrame = iKeyFrame; |
|
866 |
|
867 iReturnDes.Set(iDataBuffer->Des()); |
|
868 return iReturnDes; |
|
869 |
|
870 } |
|
871 |
|
872 // --------------------------------------------------------- |
|
873 // CVideoEncoder::ReturnBuffer |
|
874 // Returns used bitstream buffer to devVideoRec |
|
875 // (other items were commented in a header). |
|
876 // --------------------------------------------------------- |
|
877 // |
|
878 void CVideoEncoder::ReturnBuffer() |
|
879 { |
|
880 if ( iFatalError ) |
|
881 { |
|
882 return; |
|
883 } |
|
884 |
|
885 iDataBuffer->Des().Zero(); |
|
886 |
|
887 } |
|
888 |
|
889 // --------------------------------------------------------- |
|
890 // CVideoEncoder::SetupEncoderL |
|
891 // Private helper method to select & setup the encoder |
|
892 // plugin devvr must use |
|
893 // (other items were commented in a header). |
|
894 // --------------------------------------------------------- |
|
895 // |
|
896 void CVideoEncoder::SetupEncoderL() |
|
897 { |
|
898 |
|
899 if ( !(iTranscoder->SupportsOutputVideoFormat(iMimeType) ) ) |
|
900 { |
|
901 User::Leave(KErrNotSupported); |
|
902 } |
|
903 |
|
904 TTRVideoFormat videoInputFormat; |
|
905 TTRVideoFormat videoOutputFormat; |
|
906 |
|
907 videoInputFormat.iSize = iFrameSize; |
|
908 videoInputFormat.iDataType = CTRTranscoder::ETRYuvRawData420; |
|
909 |
|
910 videoOutputFormat.iSize = iFrameSize; |
|
911 videoOutputFormat.iDataType = CTRTranscoder::ETRDuCodedPicture; |
|
912 |
|
913 iTranscoder->OpenL( this, |
|
914 CTRTranscoder::EEncoding, |
|
915 KNullDesC8, |
|
916 iMimeType, |
|
917 videoInputFormat, |
|
918 videoOutputFormat, |
|
919 EFalse ); |
|
920 |
|
921 // default, will be updated by ParseVolHeader |
|
922 iTimeIncrementResolution = KTimeIncrementResolutionHW; //KTimeIncrementResolutionSW; |
|
923 |
|
924 iTranscoder->SetVideoBitRateL(iBitRate); |
|
925 |
|
926 iTranscoder->SetFrameRateL(iFrameRate); |
|
927 |
|
928 iTranscoder->SetChannelBitErrorRateL(0.0); |
|
929 |
|
930 // Get processing time estimate from transcoder, divide it by the framerate to get processing time per frame |
|
931 // and then multiply it by 2 to get some safety margin and by unit conversion factor 1000000. |
|
932 // The delay is used to determine if a frame was skipped, hence there should be some margin. |
|
933 #ifdef __WINSCW__ |
|
934 iMaxEncodingDelay = 5000000; // emulator can be really slow, use 5 seconds timeout |
|
935 #else |
|
936 iMaxEncodingDelay = (TUint)(2*1000000*iTranscoder->EstimateTranscodeTimeFactorL(videoInputFormat,videoOutputFormat)/iFrameRate); |
|
937 iMaxEncodingDelay += 100000; // Add 100 ms for safety margin |
|
938 #endif |
|
939 |
|
940 TTRVideoCodingOptions codingOptions; |
|
941 codingOptions.iSyncIntervalInPicture = 0; |
|
942 codingOptions.iMinRandomAccessPeriodInSeconds = (TInt) (1.0 / iRandomAccessRate); |
|
943 |
|
944 // NOTE: What about these ??? |
|
945 codingOptions.iDataPartitioning = EFalse; |
|
946 codingOptions.iReversibleVLC = EFalse; |
|
947 codingOptions.iHeaderExtension = 0; |
|
948 |
|
949 iTranscoder->SetVideoCodingOptionsL(codingOptions); |
|
950 |
|
951 iTranscoder->SetVideoPictureSinkOptionsL(iFrameSize, this); |
|
952 |
|
953 } |
|
954 |
|
955 |
|
956 // ----------------------------------------------------------------------------- |
|
957 // CVideoEncoder::MtroSetInputFrameRate |
|
958 // Sets input sequence frame rate for encoding |
|
959 // (other items were commented in a header). |
|
960 // ----------------------------------------------------------------------------- |
|
961 // |
|
962 void CVideoEncoder::MtroSetInputFrameRate(TReal& aRate) |
|
963 { |
|
964 |
|
965 aRate = iInputFrameRate; |
|
966 |
|
967 } |
|
968 |
|
969 |
|
970 // ----------------------------------------------------------------------------- |
|
971 // CVideoEncoder::MtroPictureFromTranscoder |
|
972 // Called by transcoder to return the input picture buffer |
|
973 // (other items were commented in a header). |
|
974 // ----------------------------------------------------------------------------- |
|
975 // |
|
976 void CVideoEncoder::MtroPictureFromTranscoder(TTRVideoPicture* aPicture) |
|
977 { |
|
978 PRINT((_L("CVideoEncoder::MtroPictureFromTranscoder() %x"), aPicture)); |
|
979 |
|
980 if (iInputPicture != aPicture) |
|
981 { |
|
982 iMonitor->Error(KErrGeneral); |
|
983 return; |
|
984 } |
|
985 |
|
986 if (iEncodePending) |
|
987 { |
|
988 if (!iTimerRequestPending) |
|
989 { |
|
990 // Activate timer to wait for encoding, if the encoding didn't complete already. |
|
991 // Timeout is needed since we don't get notification if frame was skipped. |
|
992 SetActive(); |
|
993 iStatus = KRequestPending; |
|
994 iTimer.After(iStatus, TTimeIntervalMicroSeconds32(iMaxEncodingDelay)); |
|
995 iTimerRequestPending = ETrue; |
|
996 } |
|
997 } |
|
998 } |
|
999 |
|
1000 |
|
1001 // ----------------------------------------------------------------------------- |
|
1002 // CVideoEncoder::WriteBufferL |
|
1003 // Called by transcoder to notify that new bitsream buffer is ready |
|
1004 // (other items were commented in a header). |
|
1005 // ----------------------------------------------------------------------------- |
|
1006 // |
|
1007 void CVideoEncoder::WriteBufferL(CCMRMediaBuffer* aBuffer) |
|
1008 { |
|
1009 |
|
1010 PRINT((_L("CVideoEncoder::WriteBufferL(), iEncodePending = %d"), iEncodePending)); |
|
1011 |
|
1012 #ifdef _DEBUG |
|
1013 TTime current; |
|
1014 current.UniversalTime(); |
|
1015 TInt64 time = current.MicroSecondsFrom(iEncodeStartTime).Int64(); |
|
1016 PRINT((_L("CVideoEncoder::WriteBufferL(), time spent encoding = %d ms, iEncodeRequestStatus = 0x%x"), |
|
1017 (I64INT(time))/1000 ,iEncodeRequestStatus)); |
|
1018 |
|
1019 #endif |
|
1020 |
|
1021 if (aBuffer->Type() == CCMRMediaBuffer::EVideoMPEG4DecSpecInfo) |
|
1022 { |
|
1023 // copy data to bitstream buffer |
|
1024 TPtr8 ptr = iDataBuffer->Des(); |
|
1025 ptr.Copy( aBuffer->Data() ); |
|
1026 return; |
|
1027 } |
|
1028 |
|
1029 // Cancel timer |
|
1030 Cancel(); |
|
1031 |
|
1032 iEncodePending = EFalse; |
|
1033 |
|
1034 if (aBuffer->BufferSize() == 0) |
|
1035 { |
|
1036 PRINT((_L("CVideoEncoder::WriteBufferL() buffer length == 0"))); |
|
1037 |
|
1038 if ( iEncodeRequestStatus != 0 ) |
|
1039 { |
|
1040 // complete request |
|
1041 User::RequestComplete(iEncodeRequestStatus, KErrUnderflow); |
|
1042 iEncodeRequestStatus = 0; |
|
1043 } |
|
1044 return; |
|
1045 } |
|
1046 |
|
1047 VEASSERT(aBuffer->Data().Length() <= KMaxCodedPictureSizeVGA); |
|
1048 |
|
1049 #ifdef VIDEOEDITORENGINE_AVC_EDITING |
|
1050 TInt avcFrameLen = 0; |
|
1051 if ( iMimeType.FindF(KVedMimeTypeAVC) != KErrNotFound ) |
|
1052 { |
|
1053 // get avc frame length |
|
1054 TUint8* tmp = const_cast<TUint8*>(aBuffer->Data().Ptr() + aBuffer->Data().Length()); |
|
1055 // support for 1 frame in 1 NAL unit currently |
|
1056 tmp -= 4; |
|
1057 TInt numNalUnits = TInt(tmp[0]) + (TInt(tmp[1])<<8) + (TInt(tmp[2])<<16) + (TInt(tmp[3])<<24); |
|
1058 if (numNalUnits > 0) { } |
|
1059 |
|
1060 VEASSERT( numNalUnits == 1 ); |
|
1061 tmp -=4; |
|
1062 |
|
1063 avcFrameLen = tmp[0] + (TInt(tmp[1])<<8) + (TInt(tmp[2])<<16) + (TInt(tmp[3])<<24); |
|
1064 |
|
1065 TInt error = KErrNone; |
|
1066 // check that there is enough room for length field and the frame |
|
1067 if ( iDataBuffer->Des().MaxLength() < (avcFrameLen + 4) ) |
|
1068 TRAP( error, iDataBuffer->ReAllocL(avcFrameLen + 4) ); |
|
1069 |
|
1070 if (error != KErrNone) |
|
1071 { |
|
1072 iMonitor->Error(error); |
|
1073 return; |
|
1074 } |
|
1075 |
|
1076 TUint8* buf = const_cast<TUint8*>(iDataBuffer->Des().Ptr()); |
|
1077 |
|
1078 // set length |
|
1079 buf[0] = TUint8((avcFrameLen >> 24) & 0xff); |
|
1080 buf[1] = TUint8((avcFrameLen >> 16) & 0xff); |
|
1081 buf[2] = TUint8((avcFrameLen >> 8) & 0xff); |
|
1082 buf[3] = TUint8(avcFrameLen & 0xff); |
|
1083 |
|
1084 iDataBuffer->Des().SetLength(4); |
|
1085 } |
|
1086 #endif |
|
1087 |
|
1088 // copy data to bitstream buffer |
|
1089 TPtr8 ptr = iDataBuffer->Des(); |
|
1090 |
|
1091 #ifdef VIDEOEDITORENGINE_AVC_EDITING |
|
1092 if ( iMimeType.FindF(KVedMimeTypeAVC) != KErrNotFound ) |
|
1093 { |
|
1094 ptr.Append( aBuffer->Data().Ptr(), avcFrameLen ); |
|
1095 } |
|
1096 else |
|
1097 #endif |
|
1098 { |
|
1099 ptr.Append( aBuffer->Data() ); |
|
1100 } |
|
1101 |
|
1102 // save keyframe flag |
|
1103 iKeyFrame = aBuffer->RandomAccessPoint(); |
|
1104 |
|
1105 if ( iEncodeRequestStatus != 0 ) |
|
1106 { |
|
1107 // complete request |
|
1108 User::RequestComplete(iEncodeRequestStatus, KErrNone); |
|
1109 iEncodeRequestStatus = 0; |
|
1110 } |
|
1111 |
|
1112 // --> user calls GetBuffer(); |
|
1113 |
|
1114 } |
|
1115 |
|
1116 TInt CVideoEncoder::SetVideoFrameSize(TSize /*aSize*/) |
|
1117 { |
|
1118 return KErrNone; |
|
1119 } |
|
1120 |
|
1121 TInt CVideoEncoder::SetAverageVideoBitRate(TInt /*aSize*/) |
|
1122 { |
|
1123 return KErrNone; |
|
1124 } |
|
1125 |
|
1126 TInt CVideoEncoder::SetMaxVideoBitRate(TInt /*aSize*/) |
|
1127 { |
|
1128 return KErrNone; |
|
1129 } |
|
1130 |
|
1131 TInt CVideoEncoder::SetAverageAudioBitRate(TInt /*aSize*/) |
|
1132 { |
|
1133 return KErrNone; |
|
1134 } |
|
1135 |
|
1136 // ----------------------------------------------------------------------------- |
|
1137 // CVideoEncoder::MtroFatalError |
|
1138 // Called by transcoder when a fatal error has occurred |
|
1139 // (other items were commented in a header). |
|
1140 // ----------------------------------------------------------------------------- |
|
1141 // |
|
1142 void CVideoEncoder::MtroFatalError(TInt aError) |
|
1143 { |
|
1144 |
|
1145 PRINT((_L("CVideoEncoder::MtroFatalError() %d"), aError)); |
|
1146 iFatalError = ETrue; |
|
1147 |
|
1148 iMonitor->Error(aError); |
|
1149 |
|
1150 } |
|
1151 |
|
1152 void CVideoEncoder::MtroReturnCodedBuffer(CCMRMediaBuffer* /*aBuffer*/) |
|
1153 { |
|
1154 |
|
1155 User::Panic(_L("CVIDEOENCODER"), EInternalAssertionFailure); |
|
1156 } |
|
1157 |
|
1158 |
|
1159 // ----------------------------------------------------------------------------- |
|
1160 // CVideoEncoder::MdvroInitializeComplete |
|
1161 // Called by transcoder when initialization is complete |
|
1162 // (other items were commented in a header). |
|
1163 // ----------------------------------------------------------------------------- |
|
1164 // |
|
1165 void CVideoEncoder::MtroInitializeComplete(TInt aError) |
|
1166 { |
|
1167 PRINT((_L("CVideoEncoder::MtroInitializeComplete %d, iResetRequestStatus %x"), aError, iResetRequestStatus)); |
|
1168 |
|
1169 VEASSERT(iResetRequestStatus); |
|
1170 |
|
1171 if ( aError != KErrNone ) |
|
1172 { |
|
1173 iMonitor->Error(aError); |
|
1174 if ( iResetRequestStatus != 0 ) |
|
1175 { |
|
1176 User::RequestComplete(iResetRequestStatus, aError); |
|
1177 iResetRequestStatus = 0; |
|
1178 } |
|
1179 return; |
|
1180 } |
|
1181 |
|
1182 TInt error = KErrNone; |
|
1183 // Handle MPEG-4 VOL / AVC SPS/PPS data reading/writing |
|
1184 TRAP(error, HandleCodingStandardSpecificInfoL()); |
|
1185 |
|
1186 if ( error != KErrNone ) |
|
1187 iMonitor->Error(error); |
|
1188 |
|
1189 if ( iResetRequestStatus != 0 ) |
|
1190 { |
|
1191 PRINT((_L("CVideoEncoder::MtroInitializeComplete() complete request"))); |
|
1192 // complete request: |
|
1193 User::RequestComplete(iResetRequestStatus, error); |
|
1194 iResetRequestStatus = 0; |
|
1195 } |
|
1196 |
|
1197 } |
|
1198 |
|
1199 // ----------------------------------------------------------------------------- |
|
1200 // CVideoEncoder::MtroAsyncStopComplete |
|
1201 // Called by transcoder when all pictures have been processed |
|
1202 // (other items were commented in a header). |
|
1203 // ----------------------------------------------------------------------------- |
|
1204 // |
|
1205 void CVideoEncoder::MtroAsyncStopComplete() |
|
1206 { |
|
1207 |
|
1208 PRINT((_L("CVideoEncoder::MtroAsyncStopComplete()"))); |
|
1209 |
|
1210 if ( iResetRequestStatus != 0 ) |
|
1211 { |
|
1212 PRINT((_L("CVideoEncoder::MdvroStreamEnd() complete request"))); |
|
1213 // complete request |
|
1214 User::RequestComplete(iResetRequestStatus, KErrNone); |
|
1215 iResetRequestStatus = 0; |
|
1216 } |
|
1217 |
|
1218 } |
|
1219 |
|
1220 // ----------------------------------------------------------------------------- |
|
1221 // CVideoEncoder::GetTimeIncrementResolution |
|
1222 // Gets time increment resolution used in MPEG-4 |
|
1223 // (other items were commented in a header). |
|
1224 // ----------------------------------------------------------------------------- |
|
1225 // |
|
1226 TInt CVideoEncoder::GetTimeIncrementResolution() const |
|
1227 { |
|
1228 if ( iVolReader->TimeIncrementResolution() != 0 ) |
|
1229 return iVolReader->TimeIncrementResolution(); |
|
1230 |
|
1231 return iTimeIncrementResolution; |
|
1232 } |
|
1233 |
|
1234 // ----------------------------------------------------------------------------- |
|
1235 // CVideoEncoder::HandleCodingStandardSpecificInfoL |
|
1236 // Parses the MPEG-4 VOL header / AVC Dec. configuration record |
|
1237 // (other items were commented in a header). |
|
1238 // ----------------------------------------------------------------------------- |
|
1239 // |
|
1240 void CVideoEncoder::HandleCodingStandardSpecificInfoL() |
|
1241 { |
|
1242 |
|
1243 // Parse the VOL header for mpeg-4 |
|
1244 if ( iMimeType.FindF(KVedMimeTypeMPEG4Visual) != KErrNotFound ) |
|
1245 { |
|
1246 HBufC8* headerData = iTranscoder->GetCodingStandardSpecificInitOutputLC(); |
|
1247 if ( headerData != 0 ) |
|
1248 { |
|
1249 iVolReader->ParseVolHeaderL( (TDesC8&) *headerData ); |
|
1250 |
|
1251 // Insert VOL header to bitstream buffer |
|
1252 TPtr8 ptr = iDataBuffer->Des(); |
|
1253 ptr.Append( *headerData ); |
|
1254 |
|
1255 CleanupStack::PopAndDestroy( headerData ); |
|
1256 } |
|
1257 } |
|
1258 |
|
1259 #ifdef VIDEOEDITORENGINE_AVC_EDITING |
|
1260 // Parse & write SPS/PPS data for AVC |
|
1261 else if ( iMimeType.FindF(KVedMimeTypeAVC) != KErrNotFound ) |
|
1262 { |
|
1263 HBufC8* headerData = iTranscoder->GetCodingStandardSpecificInitOutputLC(); |
|
1264 |
|
1265 if ( headerData != 0 ) |
|
1266 { |
|
1267 |
|
1268 HBufC8* outputAVCHeader = 0; |
|
1269 // is the max. size of AVCDecoderConfigurationRecord known here ?? |
|
1270 outputAVCHeader = (HBufC8*) HBufC8::NewLC(16384); |
|
1271 TPtr8 ptr = outputAVCHeader->Des(); |
|
1272 |
|
1273 // parse header & convert it to AVCDecoderConfigurationRecord -format |
|
1274 iAvcEdit->ConvertAVCHeaderL(*headerData, ptr); |
|
1275 |
|
1276 // save it to avc module for later use |
|
1277 iAvcEdit->SaveAVCDecoderConfigurationRecordL(ptr, ETrue /* aFromEncoder */); |
|
1278 |
|
1279 CleanupStack::PopAndDestroy( 2 ); // headerData, outputAVCHeader |
|
1280 |
|
1281 } |
|
1282 } |
|
1283 #endif |
|
1284 |
|
1285 } |