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 * Transcoder Implementation. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <centralrepository.h> |
|
24 #include "ctrvideopicturesink.h" |
|
25 #include "ctrtranscoderobserver.h" |
|
26 #include "ctrtranscoderimp.h" |
|
27 #include "ctrsettings.h" |
|
28 #include "ctrhwsettings.h" |
|
29 #include "ctrvideodecoderclient.h" |
|
30 #include "ctrvideoencoderclient.h" |
|
31 #include "ctrscaler.h" |
|
32 #include "ctrprivatecrkeys.h" |
|
33 |
|
34 |
|
35 // MACROS |
|
36 #define TRASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CTRANSCODERIMP"), KErrAbort)) |
|
37 |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CTRTranscoderImp::NewL |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CTRTranscoderImp* CTRTranscoderImp::NewL(MTRTranscoderObserver& aObserver) |
|
47 { |
|
48 PRINT(_L("CTRTranscoderImp::NewL(), In")) |
|
49 |
|
50 CTRTranscoderImp* self = new (ELeave) CTRTranscoderImp(aObserver); |
|
51 CleanupStack::PushL( reinterpret_cast<CTRTranscoder*>(self) ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(); |
|
54 |
|
55 PRINT(_L("CTRTranscoderImp::NewL(), Out")) |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CTRTranscoderImp::CTRTranscoderImp |
|
62 // C++ default constructor can NOT contain any code, that |
|
63 // might leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CTRTranscoderImp::CTRTranscoderImp(MTRTranscoderObserver& aObserver) : |
|
67 CActive(EPriorityStandard), |
|
68 iObserver(aObserver) |
|
69 { |
|
70 CActiveScheduler::Add(this); |
|
71 iVideoDecoderClient = NULL; |
|
72 iVideoEncoderClient = NULL; |
|
73 iRealTime = EFalse; |
|
74 iMediaSink = NULL; |
|
75 iScaler = NULL; |
|
76 iPictureSink = NULL; |
|
77 iPictureSinkTemp = NULL; |
|
78 iState = ETRNone; |
|
79 iEncoderInitStatus = KTRErrNotReady; /*Internal error status*/ |
|
80 iDecoderInitStatus = KTRErrNotReady; |
|
81 iEncoderStreamEnd = EFalse; |
|
82 iDecoderStreamEnd = EFalse; |
|
83 iDataArray = NULL; |
|
84 iVideoPictureArray = NULL; |
|
85 iDecodedPicture = NULL; |
|
86 iBitRateSetting = EFalse; |
|
87 iFatalError = KErrNone; |
|
88 iOptimizedDataTransfer = EFalse; |
|
89 iEncoderEnabled = ETrue; |
|
90 iPictureSinkEnabled = EFalse; |
|
91 iPictureSinkClientSetting = EFalse; |
|
92 iSetRandomAccessPoint = EFalse; |
|
93 iEncoderEnabledSettingChanged = EFalse; |
|
94 iPictureSinkSettingChanged = EFalse; |
|
95 iEncoderEnableClientSetting = ETrue; |
|
96 iWaitPictureFromClient = NULL; |
|
97 iWaitNewDecodedPicture = NULL; |
|
98 iNewEvent = NULL; |
|
99 iCurrentPictureSinkEnabled = EFalse; |
|
100 iCurrentAsyncPictureSinkEnabled = EFalse; |
|
101 iCurrentEncoderEnabled = ETrue; |
|
102 iCurrentAsyncEncoderEnabled = ETrue; |
|
103 iCurrentRandomAccess = EFalse; |
|
104 iAsyncStop = EFalse; |
|
105 iMaxFramesInProcessing = KTRMaxFramesInProcessingDefault; |
|
106 |
|
107 |
|
108 // Set offset for queues |
|
109 iTranscoderPictureQueue.SetOffset( static_cast<TInt>( _FOFF( TVideoPicture, iLink ))); |
|
110 iEncoderPictureQueue.SetOffset( static_cast<TInt>( _FOFF( TVideoPicture, iLink ))); |
|
111 iCIPictureBuffersQueue.SetOffset( static_cast<TInt>( _FOFF( TVideoPicture, iLink ))); |
|
112 iTranscoderTRPictureQueue.SetOffset( static_cast<TInt>( _FOFF( TTRVideoPicture, iLink ))); |
|
113 iContainerWaitQueue.SetOffset( static_cast<TInt>( _FOFF( TVideoPicture, iLink ))); |
|
114 iTranscoderEventSrc.SetOffset( static_cast<TInt>( _FOFF( CTREventItem, iLink ))); |
|
115 iTranscoderEventQueue.SetOffset( static_cast<TInt>( _FOFF( CTREventItem, iLink ))); |
|
116 iTranscoderAsyncEventQueue.SetOffset( static_cast<TInt>( _FOFF( CTREventItem, iLink ))); |
|
117 } |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CTRTranscoderImp::ConstructL |
|
122 // Symbian 2nd phase constructor can leave. |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CTRTranscoderImp::ConstructL() |
|
126 { |
|
127 PRINT((_L("CTRTranscoderImp::ConstructL(), In"))) |
|
128 |
|
129 // Allocate ivent quque |
|
130 iEvents = NULL; |
|
131 iEvents = new (ELeave) CTREventItem[KNumberOfEvents]; |
|
132 |
|
133 // Fill event's queue |
|
134 for (TInt i = 0; i < KNumberOfEvents; i ++) |
|
135 { |
|
136 iEvents[i].Reset(); |
|
137 iTranscoderEventSrc.AddLast( iEvents[i] ); |
|
138 } |
|
139 |
|
140 LoadCodecUids(); |
|
141 |
|
142 PRINT((_L("CTRTranscoderImp::ConstructL(), Out"))) |
|
143 } |
|
144 |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CTRTranscoderImp::~CTRTranscoderImp() |
|
148 // Destructor |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 CTRTranscoderImp::~CTRTranscoderImp() |
|
152 { |
|
153 PRINT((_L("CTRTranscoderImp::~CTRTranscoderImp(), In"))) |
|
154 TInt i = 0; |
|
155 |
|
156 |
|
157 if ( iState == ETRRunning ) |
|
158 { |
|
159 TRAPD(status, this->StopL()); |
|
160 PRINT((_L("CTRTranscoderImp::~CTRTranscoderImp(), StopL status[%d]"), status)) |
|
161 |
|
162 if (status != KErrNone) |
|
163 { |
|
164 // Nothing to do, since destruction of the app |
|
165 } |
|
166 } |
|
167 |
|
168 Cancel(); |
|
169 |
|
170 if (iVideoDecoderClient) |
|
171 { |
|
172 delete iVideoDecoderClient; |
|
173 iVideoDecoderClient = NULL; |
|
174 } |
|
175 |
|
176 if (iVideoEncoderClient) |
|
177 { |
|
178 delete iVideoEncoderClient; |
|
179 iVideoEncoderClient = NULL; |
|
180 } |
|
181 |
|
182 if (iScaler) |
|
183 { |
|
184 delete iScaler; |
|
185 iScaler = NULL; |
|
186 } |
|
187 |
|
188 if (iDataArray) |
|
189 { |
|
190 for (i = 0; i < KTRPictureBuffersNumber; i ++) |
|
191 { |
|
192 if ( iDataArray[i] ) |
|
193 { |
|
194 delete[] iDataArray[i]; |
|
195 iDataArray[i] = NULL; |
|
196 } |
|
197 } |
|
198 |
|
199 delete[] iDataArray; |
|
200 iDataArray = NULL; |
|
201 } |
|
202 |
|
203 if ( (iMode == EEncoding) && (iInputPictureSize == iOutputPictureSize) ) |
|
204 { |
|
205 // Clean iRawData ptrs, since the actual memory was allocated by the client |
|
206 if (iVideoPictureArray) |
|
207 { |
|
208 for (i = 0; i < KTRPictureBuffersNumber; i ++) |
|
209 { |
|
210 if (iVideoPictureArray[i].iData.iRawData) |
|
211 { |
|
212 iVideoPictureArray[i].iData.iRawData = NULL; |
|
213 } |
|
214 } |
|
215 } |
|
216 } |
|
217 |
|
218 if (iVideoPictureArray) |
|
219 { |
|
220 for (i = 0; i < KTRPictureBuffersNumber; i ++) |
|
221 { |
|
222 if (iVideoPictureArray[i].iData.iRawData) |
|
223 { |
|
224 delete iVideoPictureArray[i].iData.iRawData; |
|
225 iVideoPictureArray[i].iData.iRawData = NULL; |
|
226 } |
|
227 } |
|
228 |
|
229 delete[] iVideoPictureArray; |
|
230 iVideoPictureArray = NULL; |
|
231 } |
|
232 |
|
233 if (iTRVideoPictureArray) |
|
234 { |
|
235 delete[] iTRVideoPictureArray; |
|
236 iTRVideoPictureArray = NULL; |
|
237 } |
|
238 |
|
239 if (iEvents) |
|
240 { |
|
241 delete[] iEvents; |
|
242 } |
|
243 |
|
244 PRINT((_L("CTRTranscoderImp::~CTRTranscoderImp(), Out"))) |
|
245 } |
|
246 |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CTRTranscoderImp::SupportsInputVideoFormat |
|
250 // Checks whether given input format is supported |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 TBool CTRTranscoderImp::SupportsInputVideoFormat(const TDesC8& aMimeType) |
|
255 { |
|
256 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), In"))) |
|
257 TBool supports = EFalse; |
|
258 |
|
259 |
|
260 if ( aMimeType == KNullDesC8 ) |
|
261 { |
|
262 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), Mime type is undefined"))) |
|
263 return EFalse; |
|
264 } |
|
265 |
|
266 // Check video decoder |
|
267 if (!iVideoDecoderClient) |
|
268 { |
|
269 // Parse MIME |
|
270 TRAPD(status, this->ParseMimeTypeL(aMimeType, ETrue)); |
|
271 |
|
272 if (status != KErrNone) |
|
273 { |
|
274 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), ParseMimeTypeL[%d]"), status)) |
|
275 return EFalse; |
|
276 } |
|
277 |
|
278 // Create the decoder client first |
|
279 TRAP( status, iVideoDecoderClient = CTRVideoDecoderClient::NewL(*this) ); |
|
280 |
|
281 if (status != KErrNone) |
|
282 { |
|
283 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), VideoDecClient status[%d]"), status)) |
|
284 iVideoDecoderClient = NULL; |
|
285 return EFalse; |
|
286 } |
|
287 } |
|
288 |
|
289 // Choose the correct codec Uids to use |
|
290 TInt preferredUid = 0; |
|
291 TInt fallbackUid = 0; |
|
292 TInt resolutionUid = 0; |
|
293 |
|
294 if (iInputCodec == EH263) |
|
295 { |
|
296 preferredUid = iH263DecoderUid; |
|
297 fallbackUid = KTRFallbackDecoderUidH263; |
|
298 |
|
299 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() H.263, preferred = 0x%x"), preferredUid)) |
|
300 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() H.263, fallback = 0x%x"), fallbackUid)) |
|
301 |
|
302 if (iInputPictureSize.iWidth <= iH263DecoderLowResThreshold) |
|
303 { |
|
304 resolutionUid = iH263DecoderLowResUid; |
|
305 |
|
306 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() H.263, below, resolutions = 0x%x"), resolutionUid)) |
|
307 } |
|
308 } |
|
309 else if (iInputCodec == EH264) |
|
310 { |
|
311 preferredUid = iH264DecoderUid; |
|
312 fallbackUid = KTRFallbackDecoderUidH264; |
|
313 |
|
314 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() AVC, preferred = 0x%x"), preferredUid)) |
|
315 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() AVC, fallback = 0x%x"), fallbackUid)) |
|
316 |
|
317 if (iInputPictureSize.iWidth <= iH264DecoderLowResThreshold) |
|
318 { |
|
319 resolutionUid = iH264DecoderLowResUid; |
|
320 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() AVC, below, resolutions = 0x%x"), resolutionUid)) |
|
321 } |
|
322 } |
|
323 else |
|
324 { |
|
325 preferredUid = iMPEG4DecoderUid; |
|
326 fallbackUid = KTRFallbackDecoderUidMPEG4; |
|
327 |
|
328 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() MPEG-4, preferred = 0x%x"), preferredUid)) |
|
329 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() MPEG-4, fallback = 0x%x"), fallbackUid)) |
|
330 |
|
331 if (iInputPictureSize.iWidth <= iMPEG4DecoderLowResThreshold) |
|
332 { |
|
333 resolutionUid = iMPEG4DecoderLowResUid; |
|
334 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() MPEG-4, below, resolutions = 0x%x"), resolutionUid)) |
|
335 } |
|
336 } |
|
337 |
|
338 if (resolutionUid != 0) |
|
339 { |
|
340 preferredUid = resolutionUid; |
|
341 } |
|
342 |
|
343 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat() preferred = 0x%x"), preferredUid)) |
|
344 |
|
345 supports = iVideoDecoderClient->SupportsCodec(iInputMimeType, iInputShortMimeType, preferredUid, fallbackUid); |
|
346 |
|
347 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), supports[%d] Out"), supports)) |
|
348 return supports; |
|
349 } |
|
350 |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CTRTranscoderImp::SupportsOutputVideoFormat |
|
354 // Checks whether given output format is supported |
|
355 // (other items were commented in a header). |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 TBool CTRTranscoderImp::SupportsOutputVideoFormat(const TDesC8& aMimeType) |
|
359 { |
|
360 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat(), In"))) |
|
361 TBool supports = EFalse; |
|
362 |
|
363 |
|
364 if ( aMimeType == KNullDesC8 ) |
|
365 { |
|
366 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat(), Mime type is undefined"))) |
|
367 return EFalse; |
|
368 } |
|
369 |
|
370 // Check video encoder |
|
371 if (!iVideoEncoderClient) |
|
372 { |
|
373 // Parse MIME |
|
374 TRAPD(status, this->ParseMimeTypeL(aMimeType, EFalse)); |
|
375 |
|
376 if (status != KErrNone) |
|
377 { |
|
378 PRINT((_L("CTRTranscoderImp::SupportsInputVideoFormat(), ParseMimeTypeL[%d]"), status)) |
|
379 return EFalse; |
|
380 } |
|
381 |
|
382 // Create the encoder client first |
|
383 TRAP(status, iVideoEncoderClient = CTRVideoEncoderClient::NewL(*this) ); |
|
384 |
|
385 if (status != KErrNone) |
|
386 { |
|
387 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat(), VideoEncClient status[%d]"), status)) |
|
388 iVideoEncoderClient = NULL; |
|
389 return EFalse; |
|
390 } |
|
391 } |
|
392 |
|
393 // Choose the correct codec Uids to use |
|
394 TInt preferredUid = 0; |
|
395 TInt fallbackUid = 0; |
|
396 TInt resolutionUid = 0; |
|
397 |
|
398 if (iOutputCodec == EH263) |
|
399 { |
|
400 preferredUid = iH263EncoderUid; |
|
401 fallbackUid = KTRFallbackEncoderUidH263; |
|
402 |
|
403 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() H.263, preferred = 0x%x"), preferredUid)) |
|
404 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() H.263, fallback = 0x%x"), fallbackUid)) |
|
405 |
|
406 if (iOutputPictureSize.iWidth <= iH263EncoderLowResThreshold) |
|
407 { |
|
408 resolutionUid = iH263EncoderLowResUid; |
|
409 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() H.263, below, resolutions = 0x%x"), resolutionUid)) |
|
410 } |
|
411 } |
|
412 else if (iOutputCodec == EH264) |
|
413 { |
|
414 preferredUid = iH264EncoderUid; |
|
415 fallbackUid = KTRFallbackEncoderUidH264; |
|
416 |
|
417 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() AVC, preferred = 0x%x"), preferredUid)) |
|
418 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() AVC, fallback = 0x%x"), fallbackUid)) |
|
419 |
|
420 if (iOutputPictureSize.iWidth <= iH264EncoderLowResThreshold) |
|
421 { |
|
422 resolutionUid = iH264EncoderLowResUid; |
|
423 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() AVC, below, resolutions = 0x%x"), resolutionUid)) |
|
424 } |
|
425 } |
|
426 else |
|
427 { |
|
428 preferredUid = iMPEG4EncoderUid; |
|
429 fallbackUid = KTRFallbackEncoderUidMPEG4; |
|
430 |
|
431 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() MPEG-4, preferred = 0x%x"), preferredUid)) |
|
432 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() MPEG-4, fallback = 0x%x"), fallbackUid)) |
|
433 |
|
434 if (iOutputPictureSize.iWidth <= iMPEG4EncoderLowResThreshold) |
|
435 { |
|
436 resolutionUid = iMPEG4EncoderLowResUid; |
|
437 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() MPEG-4, below, resolutions = 0x%x"), resolutionUid)) |
|
438 } |
|
439 } |
|
440 |
|
441 if (resolutionUid != 0) |
|
442 { |
|
443 preferredUid = resolutionUid; |
|
444 } |
|
445 |
|
446 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat() preferred = 0x%x"), preferredUid)) |
|
447 |
|
448 supports = iVideoEncoderClient->SupportsCodec(iOutputMimeType, iOutputShortMimeType, preferredUid, fallbackUid); |
|
449 |
|
450 PRINT((_L("CTRTranscoderImp::SupportsOutputVideoFormat(), supports[%d] Out"), supports)) |
|
451 return supports; |
|
452 } |
|
453 |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CTRTranscoderImp::LoadCodecUids |
|
457 // Loads codec Uids from central repository |
|
458 // (other items were commented in a header). |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 void CTRTranscoderImp::LoadCodecUids() |
|
462 { |
|
463 PRINT((_L("CTRTranscoderImp::LoadCodecUids(), In"))) |
|
464 |
|
465 CRepository* repository = NULL; |
|
466 |
|
467 TRAPD(error, repository = CRepository::NewL(KCRUidTranscoder)); |
|
468 |
|
469 if (error != KErrNone) |
|
470 { |
|
471 PRINT((_L("CTRTranscoderImp::LoadCodecUids(), Error: %d, Out"), error)) |
|
472 return; |
|
473 } |
|
474 |
|
475 if (repository->Get(KTRH263DecoderUid, iH263DecoderUid) != KErrNone) |
|
476 { |
|
477 iH263DecoderUid = 0; |
|
478 } |
|
479 if (repository->Get(KTRH264DecoderUid, iH264DecoderUid) != KErrNone) |
|
480 { |
|
481 iH264DecoderUid = 0; |
|
482 } |
|
483 if (repository->Get(KTRMPEG4DecoderUid, iMPEG4DecoderUid) != KErrNone) |
|
484 { |
|
485 iMPEG4DecoderUid = 0; |
|
486 } |
|
487 |
|
488 if (repository->Get(KTRH263EncoderUid, iH263EncoderUid) != KErrNone) |
|
489 { |
|
490 iH263EncoderUid = 0; |
|
491 } |
|
492 if (repository->Get(KTRH264EncoderUid, iH264EncoderUid) != KErrNone) |
|
493 { |
|
494 iH264EncoderUid = 0; |
|
495 } |
|
496 if (repository->Get(KTRMPEG4EncoderUid, iMPEG4EncoderUid) != KErrNone) |
|
497 { |
|
498 iMPEG4EncoderUid = 0; |
|
499 } |
|
500 |
|
501 if (repository->Get(KTRH263DecoderLowResUid, iH263DecoderLowResUid) != KErrNone) |
|
502 { |
|
503 iH263DecoderLowResUid = 0; |
|
504 } |
|
505 if (repository->Get(KTRH264DecoderLowResUid, iH264DecoderLowResUid) != KErrNone) |
|
506 { |
|
507 iH264DecoderLowResUid = 0; |
|
508 } |
|
509 if (repository->Get(KTRMPEG4DecoderLowResUid, iMPEG4DecoderLowResUid) != KErrNone) |
|
510 { |
|
511 iMPEG4DecoderLowResUid = 0; |
|
512 } |
|
513 |
|
514 if (repository->Get(KTRH263EncoderLowResUid, iH263EncoderLowResUid) != KErrNone) |
|
515 { |
|
516 iH263EncoderLowResUid = 0; |
|
517 } |
|
518 if (repository->Get(KTRH264EncoderLowResUid, iH264EncoderLowResUid) != KErrNone) |
|
519 { |
|
520 iH264EncoderLowResUid = 0; |
|
521 } |
|
522 if (repository->Get(KTRMPEG4EncoderLowResUid, iMPEG4EncoderLowResUid) != KErrNone) |
|
523 { |
|
524 iMPEG4EncoderLowResUid = 0; |
|
525 } |
|
526 |
|
527 if (repository->Get(KTRH263DecoderLowResThreshold, iH263DecoderLowResThreshold) != KErrNone) |
|
528 { |
|
529 iH263DecoderLowResThreshold = 0; |
|
530 } |
|
531 if (repository->Get(KTRH264DecoderLowResThreshold, iH264DecoderLowResThreshold) != KErrNone) |
|
532 { |
|
533 iH264DecoderLowResThreshold = 0; |
|
534 } |
|
535 if (repository->Get(KTRMPEG4DecoderLowResThreshold, iMPEG4DecoderLowResThreshold) != KErrNone) |
|
536 { |
|
537 iMPEG4DecoderLowResThreshold = 0; |
|
538 } |
|
539 |
|
540 if (repository->Get(KTRH263EncoderLowResThreshold, iH263EncoderLowResThreshold) != KErrNone) |
|
541 { |
|
542 iH263EncoderLowResThreshold = 0; |
|
543 } |
|
544 if (repository->Get(KTRH264EncoderLowResThreshold, iH264EncoderLowResThreshold) != KErrNone) |
|
545 { |
|
546 iH264EncoderLowResThreshold = 0; |
|
547 } |
|
548 if (repository->Get(KTRMPEG4EncoderLowResThreshold, iMPEG4EncoderLowResThreshold) != KErrNone) |
|
549 { |
|
550 iMPEG4EncoderLowResThreshold = 0; |
|
551 } |
|
552 |
|
553 delete repository; |
|
554 |
|
555 PRINT((_L("CTRTranscoderImp::LoadCodecUids(), Out"))) |
|
556 } |
|
557 |
|
558 |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // CTRTranscoderImp::OpenL |
|
562 // Opens the transcoder |
|
563 // (other items were commented in a header). |
|
564 // ----------------------------------------------------------------------------- |
|
565 // |
|
566 void CTRTranscoderImp::OpenL( MCMRMediaSink* aMediaSink, |
|
567 CTRTranscoder::TTROperationalMode aMode, |
|
568 const TDesC8& aInputMimeType, |
|
569 const TDesC8& aOutputMimeType, |
|
570 const TTRVideoFormat& aVideoInputFormat, |
|
571 const TTRVideoFormat& aVideoOutputFormat, |
|
572 TBool aRealTime ) |
|
573 { |
|
574 PRINT((_L("CTRTranscoderImp::OpenL(), In, OperationalMode[%d]"), aMode)) |
|
575 TBool supports = EFalse; |
|
576 |
|
577 if (iState != ETRNone) |
|
578 { |
|
579 PRINT((_L("CTRTranscoderImp::OpenL(), Transcoder is in wrong state"))) |
|
580 User::Leave(KErrNotReady); |
|
581 } |
|
582 |
|
583 // Set picture size |
|
584 |
|
585 // If decoding then accept all resolutions that are divisible by 16 |
|
586 if ( (aMode == EDecoding) && |
|
587 ((aVideoInputFormat.iSize.iWidth & 0xf) == 0) && |
|
588 ((aVideoInputFormat.iSize.iHeight & 0xf) == 0) && |
|
589 ((aVideoOutputFormat.iSize.iWidth & 0xf) == 0) && |
|
590 ((aVideoOutputFormat.iSize.iHeight & 0xf) == 0) ) |
|
591 { |
|
592 iOutputPictureSize = aVideoOutputFormat.iSize; |
|
593 iInputPictureSize = aVideoInputFormat.iSize; |
|
594 } |
|
595 else if ( ( this->IsValid( const_cast<TSize&>(aVideoOutputFormat.iSize) ) ) && |
|
596 ( this->IsValid( const_cast<TSize&>(aVideoInputFormat.iSize) ) ) ) |
|
597 { |
|
598 iOutputPictureSize = aVideoOutputFormat.iSize; |
|
599 iInputPictureSize = aVideoInputFormat.iSize; |
|
600 } |
|
601 else |
|
602 { |
|
603 PRINT((_L("CTRTranscoderImp::OpenL(), picture size is not valid"))) |
|
604 User::Leave(KErrNotSupported); |
|
605 } |
|
606 |
|
607 // By default the decoded picture is the same size as the input picture |
|
608 iDecodedPictureSize = iInputPictureSize; |
|
609 |
|
610 // Create Scaler |
|
611 if (!iScaler) |
|
612 { |
|
613 PRINT((_L("CTRTranscoderImp::OpenL(), create scaler"))) |
|
614 iScaler = CTRScaler::NewL(); |
|
615 } |
|
616 |
|
617 |
|
618 switch(aMode) |
|
619 { |
|
620 case EFullTranscoding: |
|
621 { |
|
622 if ( (aInputMimeType != KNullDesC8) && (aOutputMimeType != KNullDesC8) && (aMediaSink != NULL) ) |
|
623 { |
|
624 if ( (aVideoInputFormat.iDataType != CTRTranscoder::ETRDuCodedPicture) && |
|
625 (aVideoInputFormat.iDataType != CTRTranscoder::ETRDuVideoSegment) || |
|
626 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRDuCodedPicture) && |
|
627 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRDuVideoSegment) ) |
|
628 { |
|
629 PRINT((_L("CTRTranscoderImp::OpenL(), data format is not supported in selected operational mode"))) |
|
630 User::Leave(KErrNotSupported); |
|
631 } |
|
632 |
|
633 // Parse mime type and check / define max parameters for requested codec profile-level. |
|
634 this->ParseMimeTypeL(aInputMimeType, ETrue); |
|
635 this->ParseMimeTypeL(aOutputMimeType, EFalse); |
|
636 |
|
637 if (!iVideoDecoderClient) |
|
638 { |
|
639 iVideoDecoderClient = CTRVideoDecoderClient::NewL(*this); |
|
640 } |
|
641 |
|
642 // Check input format |
|
643 supports = this->SupportsInputVideoFormat( iInputShortMimeType.Des() ); |
|
644 |
|
645 if (!supports) |
|
646 { |
|
647 PRINT((_L("CTRTranscoderImp::OpenL(), Input format is not supported by video decoder"))) |
|
648 User::Leave(KErrNotSupported); |
|
649 } |
|
650 |
|
651 if (!iVideoEncoderClient) |
|
652 { |
|
653 iVideoEncoderClient = CTRVideoEncoderClient::NewL(*this); |
|
654 } |
|
655 |
|
656 // Check output format |
|
657 supports = this->SupportsOutputVideoFormat( iOutputShortMimeType.Des() ); |
|
658 |
|
659 if (!supports) |
|
660 { |
|
661 PRINT((_L("CTRTranscoderImp::OpenL(), Output format is not supported by video encoder"))) |
|
662 User::Leave(KErrNotSupported); |
|
663 } |
|
664 } |
|
665 else |
|
666 { |
|
667 // Inform user about wrong argument |
|
668 User::Leave(KErrArgument); |
|
669 } |
|
670 |
|
671 // Set codec parameters |
|
672 iVideoDecoderClient->SetCodecParametersL(iInputCodec, iInputCodecLevel, aVideoInputFormat, aVideoOutputFormat); |
|
673 iVideoEncoderClient->SetCodecParametersL(iOutputCodec, iOutputCodecLevel, aVideoInputFormat, aVideoOutputFormat); |
|
674 |
|
675 TBool srcWide = iScaler->IsWideAspectRatio(iInputPictureSize); |
|
676 TBool dstWide = iScaler->IsWideAspectRatio(iOutputPictureSize); |
|
677 |
|
678 if (srcWide != dstWide) |
|
679 { |
|
680 // get intermediate size from scaler |
|
681 TSize resolution; |
|
682 TSize bb = TSize(0,0); |
|
683 |
|
684 TBool scale = iScaler->GetIntermediateResolution(iInputPictureSize, iOutputPictureSize, |
|
685 resolution, bb); |
|
686 |
|
687 if (scale && iVideoDecoderClient->SetDecoderScaling(iInputPictureSize, resolution)) |
|
688 { |
|
689 |
|
690 PRINT((_L("CTRTranscoderImp::OpenL(), decoder scaling supported"))) |
|
691 |
|
692 //iDecodedPictureSize = iOutputPictureSize; |
|
693 iDecodedPictureSize = resolution; |
|
694 |
|
695 // NOTE: What if decoder init. fails, this would have to be reseted! |
|
696 // Increase the max number of frames in processing since scaling is used |
|
697 iMaxFramesInProcessing = KTRMaxFramesInProcessingScaling; |
|
698 } |
|
699 } |
|
700 |
|
701 else if (iVideoDecoderClient->SetDecoderScaling(iInputPictureSize, iOutputPictureSize)) |
|
702 { |
|
703 // Scaling is supported |
|
704 iDecodedPictureSize = iOutputPictureSize; |
|
705 |
|
706 // Increase the max number of frames in processing since scaling is used |
|
707 iMaxFramesInProcessing = KTRMaxFramesInProcessingScaling; |
|
708 } |
|
709 |
|
710 iVideoEncoderClient->SetRealTime(aRealTime); |
|
711 |
|
712 break; |
|
713 } |
|
714 |
|
715 case EDecoding: |
|
716 { |
|
717 if ( aInputMimeType != KNullDesC8 ) |
|
718 { |
|
719 if ( (aVideoInputFormat.iDataType != CTRTranscoder::ETRDuCodedPicture) && |
|
720 (aVideoInputFormat.iDataType != CTRTranscoder::ETRDuVideoSegment) || |
|
721 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRYuvRawData420) && |
|
722 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRYuvRawData422) ) |
|
723 { |
|
724 PRINT((_L("CTRTranscoderImp::OpenL(), data format is not supported in selected operational mode"))) |
|
725 User::Leave(KErrNotSupported); |
|
726 } |
|
727 |
|
728 // Check mime |
|
729 this->ParseMimeTypeL(aInputMimeType, ETrue); |
|
730 |
|
731 if (!iVideoDecoderClient) |
|
732 { |
|
733 iVideoDecoderClient = CTRVideoDecoderClient::NewL(*this); |
|
734 } |
|
735 |
|
736 // Check input format |
|
737 supports = this->SupportsInputVideoFormat( iInputShortMimeType.Des() ); |
|
738 |
|
739 if (!supports) |
|
740 { |
|
741 PRINT((_L("CTRTranscoderImp::OpenL(), Input format is not supported by video decoder"))) |
|
742 User::Leave(KErrNotSupported); |
|
743 } |
|
744 } |
|
745 else |
|
746 { |
|
747 // Inform user about wrong argument |
|
748 User::Leave(KErrArgument); |
|
749 } |
|
750 |
|
751 // Set codec information |
|
752 iVideoDecoderClient->SetCodecParametersL(iInputCodec, iInputCodecLevel, aVideoInputFormat, aVideoOutputFormat); |
|
753 |
|
754 // Check if decoder supports scaling |
|
755 if (iVideoDecoderClient->SetDecoderScaling(iInputPictureSize, iOutputPictureSize)) |
|
756 { |
|
757 // Scaling is supported |
|
758 iDecodedPictureSize = iOutputPictureSize; |
|
759 } |
|
760 |
|
761 break; |
|
762 } |
|
763 |
|
764 case EEncoding: |
|
765 { |
|
766 if ( aMediaSink && (aOutputMimeType != KNullDesC8) ) |
|
767 { |
|
768 if ( (aVideoInputFormat.iDataType != CTRTranscoder::ETRYuvRawData420) && |
|
769 (aVideoInputFormat.iDataType != CTRTranscoder::ETRYuvRawData422) || |
|
770 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRDuCodedPicture) && |
|
771 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRDuVideoSegment) ) |
|
772 { |
|
773 PRINT((_L("CTRTranscoderImp::OpenL(), data format is not supported in selected operational mode"))) |
|
774 User::Leave(KErrNotSupported); |
|
775 } |
|
776 |
|
777 // Check mime |
|
778 this->ParseMimeTypeL(aOutputMimeType, EFalse); |
|
779 |
|
780 if (!iVideoEncoderClient) |
|
781 { |
|
782 iVideoEncoderClient = CTRVideoEncoderClient::NewL(*this); |
|
783 } |
|
784 |
|
785 // Check output format |
|
786 supports = this->SupportsOutputVideoFormat( iOutputShortMimeType.Des() ); |
|
787 |
|
788 if (!supports) |
|
789 { |
|
790 PRINT((_L("CTRTranscoderImp::OpenL(), Output format is not supported by video encoder"))) |
|
791 User::Leave(KErrNotSupported); |
|
792 } |
|
793 } |
|
794 else |
|
795 { |
|
796 // Inform user about wrong argument |
|
797 User::Leave(KErrArgument); |
|
798 } |
|
799 |
|
800 // Set codec parameters |
|
801 iVideoEncoderClient->SetCodecParametersL(iOutputCodec, iOutputCodecLevel, aVideoInputFormat, aVideoOutputFormat); |
|
802 |
|
803 break; |
|
804 } |
|
805 |
|
806 case EResampling: |
|
807 { |
|
808 if ( (aVideoInputFormat.iDataType != CTRTranscoder::ETRYuvRawData420) || |
|
809 (aVideoOutputFormat.iDataType != CTRTranscoder::ETRYuvRawData420) ) |
|
810 { |
|
811 PRINT((_L("CTRTranscoderImp::OpenL(), data format is not supported in selected operational mode"))) |
|
812 User::Leave(KErrNotSupported); |
|
813 } |
|
814 |
|
815 break; |
|
816 } |
|
817 |
|
818 default: |
|
819 { |
|
820 // Given option is not supported |
|
821 User::Leave(KErrNotSupported); |
|
822 } |
|
823 } |
|
824 |
|
825 iMode = aMode; |
|
826 iRealTime = aRealTime; |
|
827 iMediaSink = aMediaSink; |
|
828 iState = ETROpened; |
|
829 |
|
830 if ( (iMode == EFullTranscoding) || (iMode == EEncoding) ) |
|
831 { |
|
832 // Get frame rate for initial input coded stream |
|
833 TReal frameRate = 0.0; |
|
834 iObserver.MtroSetInputFrameRate(frameRate); |
|
835 |
|
836 if (frameRate > 0.0) |
|
837 { |
|
838 iVideoEncoderClient->SetInputFrameRate(frameRate); |
|
839 } |
|
840 } |
|
841 |
|
842 PRINT((_L("CTRTranscoderImp::OpenL(), Out"))) |
|
843 } |
|
844 |
|
845 |
|
846 // ----------------------------------------------------------------------------- |
|
847 // CTRTranscoderImp::SetVideoBitRateL |
|
848 // Sets video bitrate |
|
849 // (other items were commented in a header). |
|
850 // ----------------------------------------------------------------------------- |
|
851 // |
|
852 void CTRTranscoderImp::SetVideoBitRateL(TUint aBitRate) |
|
853 { |
|
854 PRINT((_L("CTRTranscoderImp::SetVideoBitRateL(), In"))) |
|
855 |
|
856 if ( (iState != ETROpened) && (iState != ETRInitialized) && (iState != ETRRunning) ) |
|
857 { |
|
858 PRINT((_L("CTRTranscoderImp::SetVideoBitRateL(), Transcoder is in wrong state"))) |
|
859 User::Leave(KErrNotReady); |
|
860 } |
|
861 |
|
862 if (iVideoEncoderClient) |
|
863 { |
|
864 iVideoEncoderClient->SetBitRate(aBitRate); |
|
865 } |
|
866 |
|
867 iBitRateSetting = ETrue; |
|
868 |
|
869 PRINT((_L("CTRTranscoderImp::SetVideoBitRateL(), Out"))) |
|
870 } |
|
871 |
|
872 |
|
873 // ----------------------------------------------------------------------------- |
|
874 // CTRTranscoderImp::SetFrameRateL |
|
875 // Sets frame rate |
|
876 // (other items were commented in a header). |
|
877 // ----------------------------------------------------------------------------- |
|
878 // |
|
879 void CTRTranscoderImp::SetFrameRateL(TReal aFrameRate) |
|
880 { |
|
881 PRINT((_L("CTRTranscoderImp::SetFrameRateL(), In"))) |
|
882 |
|
883 if ( (iState != ETROpened) && (iState != ETRInitialized) && (iState != ETRRunning) ) |
|
884 { |
|
885 PRINT((_L("CTRTranscoderImp::SetFrameRateL(), Transcoder is in wrong state"))) |
|
886 User::Leave(KErrNotReady); |
|
887 } |
|
888 |
|
889 if (iVideoEncoderClient) |
|
890 { |
|
891 iVideoEncoderClient->SetFrameRate(aFrameRate); |
|
892 } |
|
893 |
|
894 PRINT((_L("CTRTranscoderImp::SetFrameRateL(), Out"))) |
|
895 } |
|
896 |
|
897 |
|
898 // ----------------------------------------------------------------------------- |
|
899 // CTRTranscoderImp::SetChannelBitErrorRateL |
|
900 // Sets channel bit error rate |
|
901 // (other items were commented in a header). |
|
902 // ----------------------------------------------------------------------------- |
|
903 // |
|
904 void CTRTranscoderImp::SetChannelBitErrorRateL(TReal aErrorRate) |
|
905 { |
|
906 PRINT((_L("CTRTranscoderImp::SetChannelBitErrorRateL(), In"))) |
|
907 |
|
908 if ( (iState != ETROpened) && (iState != ETRInitialized) && (iState != ETRRunning) ) |
|
909 { |
|
910 PRINT((_L("CTRTranscoderImp::SetChannelBitErrorRateL(), Transcoder is in wrong state"))) |
|
911 User::Leave(KErrNotReady); |
|
912 } |
|
913 |
|
914 if (iVideoEncoderClient) |
|
915 { |
|
916 iVideoEncoderClient->SetChannelBitErrorRate(aErrorRate); |
|
917 } |
|
918 |
|
919 PRINT((_L("CTRTranscoderImp::SetChannelBitErrorRateL(), Out"))) |
|
920 } |
|
921 |
|
922 |
|
923 // ----------------------------------------------------------------------------- |
|
924 // CTRTranscoderImp::SetVideoCodingOptionsL |
|
925 // Sets video coding options |
|
926 // (other items were commented in a header). |
|
927 // ----------------------------------------------------------------------------- |
|
928 // |
|
929 void CTRTranscoderImp::SetVideoCodingOptionsL(TTRVideoCodingOptions& aOptions) |
|
930 { |
|
931 if (iState != ETROpened) |
|
932 { |
|
933 PRINT((_L("CTRTranscoderImp::SetVideoCodingOptionsL(), Transcoder is in wrong state"))) |
|
934 User::Leave(KErrNotReady); |
|
935 } |
|
936 |
|
937 if (iVideoEncoderClient) |
|
938 { |
|
939 iVideoEncoderClient->SetVideoCodingOptionsL(aOptions); |
|
940 } |
|
941 } |
|
942 |
|
943 |
|
944 // ----------------------------------------------------------------------------- |
|
945 // CTRTranscoderImp::SetVideoPictureSinkOptionsL |
|
946 // Sets picture sing and options for intermediate format |
|
947 // (other items were commented in a header). |
|
948 // ----------------------------------------------------------------------------- |
|
949 // |
|
950 void CTRTranscoderImp::SetVideoPictureSinkOptionsL(TSize& aSize, MTRVideoPictureSink* aSink) |
|
951 { |
|
952 if (iState == ETRNone) |
|
953 { |
|
954 PRINT((_L("CTRTranscoderImp::SetVideoPictureSinkOptionsL(), Transcoder is in wrong state"))) |
|
955 User::Leave(KErrNotReady); |
|
956 } |
|
957 |
|
958 if (aSink) |
|
959 { |
|
960 if ((iMode != EDecoding) && (!this->IsValid(aSize))) |
|
961 { |
|
962 PRINT((_L("CTRTranscoderImp::SetVideoPictureSinkOptionsL(), invalid size"))) |
|
963 User::Leave(KErrNotSupported); |
|
964 } |
|
965 |
|
966 switch(iMode) |
|
967 { |
|
968 case EFullTranscoding: |
|
969 case EDecoding: |
|
970 { |
|
971 if ( aSize == iOutputPictureSize ) |
|
972 { |
|
973 iIntermediatePictureSize = aSize; |
|
974 } |
|
975 else |
|
976 { |
|
977 // In full transcoding mode (intermediate picture size = outputTarget size) is supported only |
|
978 PRINT((_L("CTRTranscoderImp::SetVideoPictureSinkOptionsL(), Intermediate picture size is not supported"))) |
|
979 User::Leave(KErrNotSupported); |
|
980 } |
|
981 } |
|
982 break; |
|
983 |
|
984 case EEncoding: |
|
985 { |
|
986 if ( (aSize == iInputPictureSize) || (aSize == iOutputPictureSize) ) |
|
987 { |
|
988 iIntermediatePictureSize = aSize; |
|
989 } |
|
990 else |
|
991 { |
|
992 PRINT((_L("CTRTranscoderImp::SetVideoPictureSinkOptionsL(), invalid intermediate size"))) |
|
993 User::Leave(KErrNotSupported); |
|
994 } |
|
995 } |
|
996 break; |
|
997 |
|
998 case EResampling: |
|
999 { |
|
1000 // No need to check size, since it's iOutputPictureSize; |
|
1001 iIntermediatePictureSize = iOutputPictureSize; |
|
1002 } |
|
1003 break; |
|
1004 |
|
1005 case EOperationNone: |
|
1006 { |
|
1007 // Operation is not set yet |
|
1008 User::Leave(KErrNotReady); |
|
1009 } |
|
1010 break; |
|
1011 |
|
1012 default: |
|
1013 { |
|
1014 // Operation is not set yet |
|
1015 User::Leave(KErrNotReady); |
|
1016 break; |
|
1017 } |
|
1018 } |
|
1019 |
|
1020 // Set picture sink |
|
1021 iPictureSink = aSink; |
|
1022 iPictureSinkTemp = aSink; |
|
1023 iPictureSinkEnabled = ETrue; |
|
1024 iPictureSinkClientSetting = ETrue; |
|
1025 iCurrentPictureSinkEnabled = ETrue; |
|
1026 iCurrentAsyncPictureSinkEnabled = ETrue; |
|
1027 } |
|
1028 else |
|
1029 { |
|
1030 User::Leave(KErrArgument); |
|
1031 } |
|
1032 } |
|
1033 |
|
1034 |
|
1035 // ----------------------------------------------------------------------------- |
|
1036 // CTRTranscoderImp::UseDirectScreenAccessL |
|
1037 // Requests using of DSA |
|
1038 // (other items were commented in a header). |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // |
|
1041 void CTRTranscoderImp::UseDirectScreenAccessL(TBool /*aUseDSA*/, CFbsScreenDevice& /*aScreenDevice*/, |
|
1042 TTRDisplayOptions& /*aOptions*/) |
|
1043 { |
|
1044 // Not supported yet |
|
1045 User::Leave(KErrNotSupported); |
|
1046 } |
|
1047 |
|
1048 |
|
1049 // ----------------------------------------------------------------------------- |
|
1050 // CTRTranscoderImp::ParseMimeTypeL |
|
1051 // Parses given MIME type |
|
1052 // (other items were commented in a header). |
|
1053 // ----------------------------------------------------------------------------- |
|
1054 // |
|
1055 void CTRTranscoderImp::ParseMimeTypeL(const TDesC8& aMimeType, TBool aInOutMime) |
|
1056 { |
|
1057 TUint maxBitRate = 0; |
|
1058 TInt codecType = 0; |
|
1059 TBuf8<256> shortMimeType; |
|
1060 TBuf8<256> newMimeType; |
|
1061 TInt width = 0; |
|
1062 TUint codecLevel = 0; |
|
1063 |
|
1064 |
|
1065 if (aMimeType == KNullDesC8) |
|
1066 { |
|
1067 User::Leave(KErrArgument); |
|
1068 } |
|
1069 |
|
1070 if ( aMimeType.MatchF( _L8("*video/H263-2000*") ) != KErrNotFound ) |
|
1071 { |
|
1072 // H.263 |
|
1073 codecType = EH263; |
|
1074 shortMimeType = _L8("video/H263-2000"); |
|
1075 newMimeType = shortMimeType; |
|
1076 |
|
1077 if ( aMimeType.MatchF( _L8("*profile*") ) != KErrNotFound ) |
|
1078 { |
|
1079 // Profile info is given, check it |
|
1080 if ( aMimeType.MatchF( _L8("*profile=0*") ) != KErrNotFound ) |
|
1081 { |
|
1082 // Check level info |
|
1083 newMimeType += _L8("; profile=0"); |
|
1084 } |
|
1085 else if ( aMimeType.MatchF( _L8("*profile=3*") ) != KErrNotFound ) |
|
1086 { |
|
1087 // Check level info |
|
1088 newMimeType += _L8("; profile=3"); |
|
1089 } |
|
1090 else |
|
1091 { |
|
1092 // We don't support any other profiles yet |
|
1093 PRINT((_L("CTRTranscoderImp::ParseMimeTypeL(), profile is not supported"))) |
|
1094 User::Leave(KErrNotSupported); |
|
1095 } |
|
1096 } |
|
1097 else |
|
1098 { |
|
1099 // Set defaults for profile=0; |
|
1100 newMimeType += _L8("; profile=0"); |
|
1101 } |
|
1102 |
|
1103 |
|
1104 // Check level info |
|
1105 if ( aMimeType.MatchF( _L8("*level=*") ) != KErrNotFound ) |
|
1106 { |
|
1107 if ( aMimeType.MatchF( _L8("*level=10*") ) != KErrNotFound ) |
|
1108 { |
|
1109 // Set level=10; |
|
1110 maxBitRate = KTRMaxBitRateH263Level10; |
|
1111 codecLevel = KTRH263CodecLevel10; |
|
1112 newMimeType += _L8("; level=10"); |
|
1113 } |
|
1114 else if ( aMimeType.MatchF( _L8("*level=20*") ) != KErrNotFound ) |
|
1115 { |
|
1116 // Set level=20; |
|
1117 maxBitRate = KTRMaxBitRateH263Level20; |
|
1118 codecLevel = KTRH263CodecLevel20; |
|
1119 newMimeType += _L8("; level=20"); |
|
1120 } |
|
1121 else if ( aMimeType.MatchF( _L8("*level=30*") ) != KErrNotFound ) |
|
1122 { |
|
1123 // Set level=30; |
|
1124 maxBitRate = KTRMaxBitRateH263Level30; |
|
1125 codecLevel = KTRH263CodecLevel30; |
|
1126 newMimeType += _L8("; level=30"); |
|
1127 } |
|
1128 else if ( aMimeType.MatchF( _L8("*level=40*") ) != KErrNotFound ) |
|
1129 { |
|
1130 // Set level=40; |
|
1131 maxBitRate = KTRMaxBitRateH263Level40; |
|
1132 codecLevel = KTRH263CodecLevel40; |
|
1133 newMimeType += _L8("; level=40"); |
|
1134 } |
|
1135 else if ( aMimeType.MatchF( _L8("*level=45*") ) != KErrNotFound ) |
|
1136 { |
|
1137 // Set level=45; |
|
1138 maxBitRate = KTRMaxBitRateH263Level45; |
|
1139 codecLevel = KTRH263CodecLevel45; |
|
1140 newMimeType += _L8("; level=45"); |
|
1141 } |
|
1142 else if ( aMimeType.MatchF( _L8("*level=50*") ) != KErrNotFound ) |
|
1143 { |
|
1144 // Set level=50; |
|
1145 maxBitRate = KTRMaxBitRateH263Level50; |
|
1146 codecLevel = KTRH263CodecLevel50; |
|
1147 newMimeType += _L8("; level=50"); |
|
1148 } |
|
1149 else if ( aMimeType.MatchF( _L8("*level=60*") ) != KErrNotFound ) |
|
1150 { |
|
1151 // Set level=60; |
|
1152 maxBitRate = KTRMaxBitRateH263Level60; |
|
1153 codecLevel = KTRH263CodecLevel60; |
|
1154 newMimeType += _L8("; level=60"); |
|
1155 } |
|
1156 else if ( aMimeType.MatchF( _L8("*level=70*") ) != KErrNotFound ) |
|
1157 { |
|
1158 // Set level=70; |
|
1159 maxBitRate = KTRMaxBitRateH263Level70; |
|
1160 codecLevel = KTRH263CodecLevel70; |
|
1161 newMimeType += _L8("; level=70"); |
|
1162 } |
|
1163 else |
|
1164 { |
|
1165 // We don't support any other levels |
|
1166 PRINT((_L("CTRTranscoderImp::ParseMimeTypeL(), level is not supported"))) |
|
1167 User::Leave(KErrNotSupported); |
|
1168 } |
|
1169 } |
|
1170 else |
|
1171 { |
|
1172 // Codec level is not specified, check requested picture size and set mime |
|
1173 if (aInOutMime) |
|
1174 { |
|
1175 width = iInputPictureSize.iWidth; |
|
1176 } |
|
1177 else |
|
1178 { |
|
1179 width = iOutputPictureSize.iWidth; |
|
1180 } |
|
1181 |
|
1182 switch( width ) |
|
1183 { |
|
1184 case KTRSubQCIFWidth: |
|
1185 case KTRQCIFWidth: |
|
1186 { |
|
1187 // Set defaults for level=10; |
|
1188 maxBitRate = KTRMaxBitRateH263Level10; |
|
1189 codecLevel = KTRH263CodecLevel10; |
|
1190 newMimeType += _L8("; level=10"); |
|
1191 break; |
|
1192 } |
|
1193 |
|
1194 case KTRCIFWidth: |
|
1195 { |
|
1196 // Set defaults for level=30; |
|
1197 maxBitRate = KTRMaxBitRateH263Level30; |
|
1198 codecLevel = KTRH263CodecLevel30; |
|
1199 newMimeType += _L8("; level=30"); |
|
1200 break; |
|
1201 } |
|
1202 |
|
1203 case KTRPALWidth: |
|
1204 { |
|
1205 // Set defaults for level=60; |
|
1206 maxBitRate = KTRMaxBitRateH263Level60; |
|
1207 codecLevel = KTRH263CodecLevel60; |
|
1208 newMimeType += _L8("; level=60"); |
|
1209 break; |
|
1210 } |
|
1211 |
|
1212 default: |
|
1213 { |
|
1214 // Set defaults for level=10; |
|
1215 maxBitRate = KTRMaxBitRateH263Level10; |
|
1216 codecLevel = KTRH263CodecLevel10; |
|
1217 newMimeType += _L8("; level=10"); |
|
1218 break; |
|
1219 } |
|
1220 } |
|
1221 } |
|
1222 } |
|
1223 else if ( (aMimeType.MatchF( _L8("*video/H264*") ) != KErrNotFound) ) |
|
1224 { |
|
1225 // H.264 (AVC) |
|
1226 codecType = EH264; |
|
1227 shortMimeType = _L8("video/H264"); |
|
1228 newMimeType = shortMimeType; |
|
1229 |
|
1230 // Check profile-level |
|
1231 if ( aMimeType.MatchF( _L8("*profile-level-id=*") ) != KErrNotFound ) |
|
1232 { |
|
1233 if ( aMimeType.MatchF( _L8("*profile-level-id=42800A*") ) != KErrNotFound ) |
|
1234 { |
|
1235 maxBitRate = KTRMaxBitRateH264Level10; |
|
1236 codecLevel = KTRH264CodecLevel10; |
|
1237 newMimeType += _L8("; profile-level-id=42800A"); // Level 1 |
|
1238 } |
|
1239 else if ( aMimeType.MatchF( _L8("*profile-level-id=42900B*") ) != KErrNotFound ) |
|
1240 { |
|
1241 maxBitRate = KTRMaxBitRateH264Level10b; |
|
1242 codecLevel = KTRH264CodecLevel10b; |
|
1243 newMimeType += _L8("; profile-level-id=42900B"); // Level 1b |
|
1244 } |
|
1245 else if ( aMimeType.MatchF( _L8("*profile-level-id=42800B*") ) != KErrNotFound ) |
|
1246 { |
|
1247 maxBitRate = KTRMaxBitRateH264Level11; |
|
1248 codecLevel = KTRH264CodecLevel11; |
|
1249 newMimeType += _L8("; profile-level-id=42800B"); // Level 1.1 |
|
1250 } |
|
1251 else if ( aMimeType.MatchF( _L8("*profile-level-id=42800C*") ) != KErrNotFound ) |
|
1252 { |
|
1253 maxBitRate = KTRMaxBitRateH264Level12; |
|
1254 codecLevel = KTRH264CodecLevel12; |
|
1255 newMimeType += _L8("; profile-level-id=42800C"); // Level 1.2 |
|
1256 } |
|
1257 else if ( aMimeType.MatchF( _L8("*profile-level-id=42800D*") ) != KErrNotFound ) |
|
1258 { |
|
1259 maxBitRate = KTRMaxBitRateH264Level13; |
|
1260 codecLevel = KTRH264CodecLevel13; |
|
1261 newMimeType += _L8("; profile-level-id=42800D"); // Level 1.3 |
|
1262 } |
|
1263 else if ( aMimeType.MatchF( _L8("*profile-level-id=428014*") ) != KErrNotFound ) |
|
1264 { |
|
1265 maxBitRate = KTRMaxBitRateH264Level20; |
|
1266 codecLevel = KTRH264CodecLevel20; |
|
1267 newMimeType += _L8("; profile-level-id=428014"); // Level 2 |
|
1268 } |
|
1269 //WVGA task |
|
1270 else if ( aMimeType.MatchF( _L8("*profile-level-id=428015*") ) != KErrNotFound ) |
|
1271 { |
|
1272 maxBitRate = KTRMaxBitRateH264Level21; |
|
1273 codecLevel = KTRH264CodecLevel21; |
|
1274 newMimeType += _L8("; profile-level-id=428015"); // Level 2.1 |
|
1275 } |
|
1276 else if ( aMimeType.MatchF( _L8("*profile-level-id=428016*") ) != KErrNotFound ) |
|
1277 { |
|
1278 maxBitRate = KTRMaxBitRateH264Level22; |
|
1279 codecLevel = KTRH264CodecLevel22; |
|
1280 newMimeType += _L8("; profile-level-id=428016"); // Level 2.2 |
|
1281 } |
|
1282 else if ( aMimeType.MatchF( _L8("*profile-level-id=42801E*") ) != KErrNotFound ) |
|
1283 { |
|
1284 maxBitRate = KTRMaxBitRateH264Level30; |
|
1285 codecLevel = KTRH264CodecLevel30; |
|
1286 newMimeType += _L8("; profile-level-id=42801E"); // Level 3 |
|
1287 } |
|
1288 else if ( aMimeType.MatchF( _L8("*profile-level-id=42801F*") ) != KErrNotFound ) |
|
1289 { |
|
1290 maxBitRate = KTRMaxBitRateH264Level31; |
|
1291 codecLevel = KTRH264CodecLevel31; |
|
1292 newMimeType += _L8("; profile-level-id=42801F"); // Level 3.1 |
|
1293 } |
|
1294 else |
|
1295 { |
|
1296 // We don't support any other levels |
|
1297 PRINT((_L("CTRTranscoderImp::ParseMimeTypeL(), profile-level-id is not supported"))) |
|
1298 User::Leave(KErrNotSupported); |
|
1299 } |
|
1300 } |
|
1301 else |
|
1302 { |
|
1303 // profile-level-id is not specified, check requested picture size |
|
1304 if (aInOutMime) |
|
1305 { |
|
1306 width = iInputPictureSize.iWidth; |
|
1307 } |
|
1308 else |
|
1309 { |
|
1310 width = iOutputPictureSize.iWidth; |
|
1311 } |
|
1312 |
|
1313 switch( width ) |
|
1314 { |
|
1315 case KTRSubQCIFWidth: |
|
1316 case KTRQCIFWidth: |
|
1317 { |
|
1318 // Set level 1 |
|
1319 maxBitRate = KTRMaxBitRateH264Level10; |
|
1320 codecLevel = KTRH264CodecLevel10; |
|
1321 newMimeType += _L8("; profile-level-id=42800A"); |
|
1322 break; |
|
1323 } |
|
1324 |
|
1325 case KTRQVGAWidth: |
|
1326 case KTRCIFWidth: |
|
1327 { |
|
1328 // Set level 1.2 |
|
1329 maxBitRate = KTRMaxBitRateH264Level12; |
|
1330 codecLevel = KTRH264CodecLevel12; |
|
1331 newMimeType += _L8("; profile-level-id=42800C"); |
|
1332 break; |
|
1333 } |
|
1334 case KTRWVGAWidth: |
|
1335 { |
|
1336 // Set level 3.1 |
|
1337 maxBitRate = KTRMaxBitRateH264Level31; |
|
1338 codecLevel = KTRH264CodecLevel31; |
|
1339 newMimeType += _L8("; profile-level-id=42801F"); |
|
1340 break; |
|
1341 } |
|
1342 |
|
1343 default: |
|
1344 { |
|
1345 // Set level 1 |
|
1346 maxBitRate = KTRMaxBitRateH264Level10; |
|
1347 codecLevel = KTRH264CodecLevel10; |
|
1348 newMimeType += _L8("; profile-level-id=42800A"); |
|
1349 break; |
|
1350 } |
|
1351 } |
|
1352 } |
|
1353 } |
|
1354 else if ( (aMimeType.MatchF( _L8("*video/mp4v-es*") ) != KErrNotFound) || |
|
1355 (aMimeType.MatchF( _L8("*video/MP4V-ES*") ) != KErrNotFound) ) |
|
1356 { |
|
1357 // MPEG-4 Visual |
|
1358 codecType = EMpeg4; |
|
1359 shortMimeType = _L8("video/mp4v-es"); // Set short mime |
|
1360 newMimeType = shortMimeType; |
|
1361 |
|
1362 // Check profile-level |
|
1363 if ( aMimeType.MatchF( _L8("*profile-level-id=*") ) != KErrNotFound ) |
|
1364 { |
|
1365 if ( aMimeType.MatchF( _L8("*profile-level-id=8*") ) != KErrNotFound ) |
|
1366 { |
|
1367 // Set defaults for profile-level-id=8 |
|
1368 newMimeType += _L8("; profile-level-id=8"); |
|
1369 } |
|
1370 else if( aMimeType.MatchF( _L8("*profile-level-id=1*") ) != KErrNotFound ) |
|
1371 { |
|
1372 // Set profile-level-id=1 |
|
1373 maxBitRate = KTRMaxBitRateMPEG4Level1; |
|
1374 codecLevel = KTRMPEG4CodecLevel1; |
|
1375 newMimeType += _L8("; profile-level-id=1"); |
|
1376 } |
|
1377 else if ( aMimeType.MatchF( _L8("*profile-level-id=2*") ) != KErrNotFound ) |
|
1378 { |
|
1379 // Set profile-level-id=2 |
|
1380 maxBitRate = KTRMaxBitRateMPEG4Level2; |
|
1381 codecLevel = KTRMPEG4CodecLevel2; |
|
1382 newMimeType += _L8("; profile-level-id=2"); |
|
1383 } |
|
1384 else if ( aMimeType.MatchF( _L8("*profile-level-id=3*") ) != KErrNotFound ) |
|
1385 { |
|
1386 // Set profile-level-id=3 |
|
1387 maxBitRate = KTRMaxBitRateMPEG4Level3; |
|
1388 codecLevel = KTRMPEG4CodecLevel3; |
|
1389 newMimeType += _L8("; profile-level-id=3"); |
|
1390 } |
|
1391 else if ( aMimeType.MatchF( _L8("*profile-level-id=9*") ) != KErrNotFound ) |
|
1392 { |
|
1393 // Set profile-level-id=9 |
|
1394 maxBitRate = KTRMaxBitRateMPEG4Level0b; |
|
1395 codecLevel = KTRMPEG4CodecLevel0b; |
|
1396 newMimeType += _L8("; profile-level-id=9"); |
|
1397 } |
|
1398 else if ( aMimeType.MatchF( _L8("*profile-level-id=4*") ) != KErrNotFound ) |
|
1399 { |
|
1400 // Set profile-level-id=4 |
|
1401 maxBitRate = KTRMaxBitRateMPEG4Level4a; |
|
1402 codecLevel = KTRMPEG4CodecLevel4a; |
|
1403 newMimeType += _L8("; profile-level-id=4"); |
|
1404 } |
|
1405 else |
|
1406 { |
|
1407 // We don't support any other levels |
|
1408 PRINT((_L("CTRTranscoderImp::ParseMimeTypeL(), profile-level-id is not supported"))) |
|
1409 User::Leave(KErrNotSupported); |
|
1410 } |
|
1411 } |
|
1412 else |
|
1413 { |
|
1414 // profile-level-id is not specified, check requested picture size |
|
1415 // Set defaults for profile-level-id=8 |
|
1416 if (aInOutMime) |
|
1417 { |
|
1418 width = iInputPictureSize.iWidth; |
|
1419 } |
|
1420 else |
|
1421 { |
|
1422 width = iOutputPictureSize.iWidth; |
|
1423 } |
|
1424 |
|
1425 switch( width ) |
|
1426 { |
|
1427 case KTRSubQCIFWidth: |
|
1428 case KTRQCIFWidth: |
|
1429 { |
|
1430 // Set profile-level-id=0 |
|
1431 codecLevel = KTRMPEG4CodecLevel0; |
|
1432 maxBitRate = KTRMaxBitRateMPEG4Level0; |
|
1433 newMimeType += _L8("; profile-level-id=8"); |
|
1434 break; |
|
1435 } |
|
1436 |
|
1437 case KTRQVGAWidth: |
|
1438 case KTRCIFWidth: |
|
1439 { |
|
1440 // Set profile-level-id=3 |
|
1441 maxBitRate = KTRMaxBitRateMPEG4Level3; |
|
1442 codecLevel = KTRMPEG4CodecLevel3; |
|
1443 newMimeType += _L8("; profile-level-id=3"); |
|
1444 break; |
|
1445 } |
|
1446 |
|
1447 case KTRVGAWidth: |
|
1448 { |
|
1449 // Set profile-level-id=4 (4a) |
|
1450 maxBitRate = KTRMaxBitRateMPEG4Level4a; |
|
1451 codecLevel = KTRMPEG4CodecLevel4a; |
|
1452 newMimeType += _L8("; profile-level-id=4"); |
|
1453 break; |
|
1454 } |
|
1455 |
|
1456 default: |
|
1457 { |
|
1458 // Set profile-level-id=0 |
|
1459 maxBitRate = KTRMaxBitRateMPEG4Level0; |
|
1460 codecLevel = KTRMPEG4CodecLevel0; |
|
1461 newMimeType += _L8("; profile-level-id=8"); |
|
1462 break; |
|
1463 } |
|
1464 } |
|
1465 } |
|
1466 } |
|
1467 else |
|
1468 { |
|
1469 PRINT((_L("CTRTranscoderImp::ParseMimeL(), there is curently no support for this type"))) |
|
1470 User::Leave(KErrNotSupported); |
|
1471 } |
|
1472 |
|
1473 if (aInOutMime) |
|
1474 { |
|
1475 // Mime type was set for Input format |
|
1476 iInputCodecLevel = codecLevel; |
|
1477 iInputCodec = codecType; |
|
1478 iInputMaxBitRate = maxBitRate; |
|
1479 |
|
1480 iInputMimeType = newMimeType; |
|
1481 iInputShortMimeType = shortMimeType; |
|
1482 } |
|
1483 else |
|
1484 { |
|
1485 // Mime type was set for Output format |
|
1486 iOutputCodecLevel = codecLevel; |
|
1487 iOutputCodec = codecType; |
|
1488 iOutputMaxBitRate = maxBitRate; |
|
1489 |
|
1490 iOutputMimeType = newMimeType; |
|
1491 iOutputShortMimeType = shortMimeType; |
|
1492 } |
|
1493 } |
|
1494 |
|
1495 |
|
1496 // ----------------------------------------------------------------------------- |
|
1497 // CTRTranscoderImp::IsValid |
|
1498 // Checks whether the size is valid |
|
1499 // (other items were commented in a header). |
|
1500 // ----------------------------------------------------------------------------- |
|
1501 // |
|
1502 TBool CTRTranscoderImp::IsValid(TSize& aSize) |
|
1503 { |
|
1504 TBool valid = EFalse; |
|
1505 |
|
1506 switch(aSize.iWidth) |
|
1507 { |
|
1508 case KTRSubQCIFWidth: |
|
1509 { |
|
1510 if (aSize.iHeight == KTRSubQCIFHeight) |
|
1511 { |
|
1512 valid = ETrue; |
|
1513 } |
|
1514 break; |
|
1515 } |
|
1516 |
|
1517 case KTRQCIFWidth: |
|
1518 { |
|
1519 if (aSize.iHeight == KTRQCIFHeight) |
|
1520 { |
|
1521 valid = ETrue; |
|
1522 } |
|
1523 break; |
|
1524 } |
|
1525 |
|
1526 case KTRCIFWidth: |
|
1527 { |
|
1528 if (aSize.iHeight == KTRCIFHeight) |
|
1529 { |
|
1530 valid = ETrue; |
|
1531 } |
|
1532 break; |
|
1533 } |
|
1534 |
|
1535 case KTRQVGAWidth: |
|
1536 { |
|
1537 if (aSize.iHeight == KTRQVGAHeight) |
|
1538 { |
|
1539 valid = ETrue; |
|
1540 } |
|
1541 break; |
|
1542 } |
|
1543 |
|
1544 case KTRVGAWidth: |
|
1545 { |
|
1546 if (aSize.iHeight == KTRVGAHeight || aSize.iHeight == KTRVGA16By9Height) |
|
1547 { |
|
1548 valid = ETrue; |
|
1549 } |
|
1550 break; |
|
1551 } |
|
1552 case KTRWVGAWidth: |
|
1553 { |
|
1554 if (aSize.iHeight == KTRWVGAHeight) |
|
1555 { |
|
1556 valid = ETrue; |
|
1557 } |
|
1558 break; |
|
1559 } |
|
1560 |
|
1561 case KTR4CIFWidth: |
|
1562 { |
|
1563 if (aSize.iHeight == KTR4CIFHeight) |
|
1564 { |
|
1565 valid = ETrue; |
|
1566 } |
|
1567 break; |
|
1568 } |
|
1569 |
|
1570 case KTRPALWidth: |
|
1571 { |
|
1572 if ( (aSize.iHeight == KTRPAL2Height) || (aSize.iHeight == KTRPAL1Height) ) |
|
1573 { |
|
1574 valid = ETrue; |
|
1575 } |
|
1576 break; |
|
1577 } |
|
1578 |
|
1579 default: |
|
1580 { |
|
1581 valid = EFalse; |
|
1582 } |
|
1583 } |
|
1584 |
|
1585 return valid; |
|
1586 } |
|
1587 |
|
1588 |
|
1589 |
|
1590 // ----------------------------------------------------------------------------- |
|
1591 // CTRTranscoderImp::GetVideoBitRateL |
|
1592 // Gets video bitrate |
|
1593 // (other items were commented in a header). |
|
1594 // ----------------------------------------------------------------------------- |
|
1595 // |
|
1596 TUint CTRTranscoderImp::GetVideoBitRateL() |
|
1597 { |
|
1598 if (iVideoEncoderClient) |
|
1599 { |
|
1600 return iVideoEncoderClient->GetVideoBitRateL(); |
|
1601 } |
|
1602 |
|
1603 // Otherwise return 0, in case if it's called before initializing or in different operating mode |
|
1604 // e.g. (without encoding) |
|
1605 return 0; |
|
1606 } |
|
1607 |
|
1608 |
|
1609 // ----------------------------------------------------------------------------- |
|
1610 // CTRTranscoderImp::GetFrameRateL |
|
1611 // Gets frame rate |
|
1612 // (other items were commented in a header). |
|
1613 // ----------------------------------------------------------------------------- |
|
1614 // |
|
1615 TReal CTRTranscoderImp::GetFrameRateL() |
|
1616 { |
|
1617 if (iVideoEncoderClient) |
|
1618 { |
|
1619 return iVideoEncoderClient->GetFrameRateL(); |
|
1620 } |
|
1621 |
|
1622 // Otherwise return 0, in case if it's called before initializing or in different operating mode |
|
1623 // e.g. (without encoding) |
|
1624 return 0; |
|
1625 } |
|
1626 |
|
1627 |
|
1628 // ----------------------------------------------------------------------------- |
|
1629 // CTRTranscoderImp::GetVideoCodecL |
|
1630 // Gets current video codec in use |
|
1631 // (other items were commented in a header). |
|
1632 // ----------------------------------------------------------------------------- |
|
1633 // |
|
1634 void CTRTranscoderImp::GetVideoCodecL(TDes8& aVideoMimeType) |
|
1635 { |
|
1636 if (iState == ETRNone) |
|
1637 { |
|
1638 aVideoMimeType = KNullDesC8; |
|
1639 } |
|
1640 else |
|
1641 { |
|
1642 aVideoMimeType = iOutputShortMimeType; |
|
1643 } |
|
1644 } |
|
1645 |
|
1646 |
|
1647 // ----------------------------------------------------------------------------- |
|
1648 // CTRTranscoderImp::GetTranscodedPictureSizeL |
|
1649 // Gets output transcoded picture size |
|
1650 // (other items were commented in a header). |
|
1651 // ----------------------------------------------------------------------------- |
|
1652 // |
|
1653 void CTRTranscoderImp::GetTranscodedPictureSizeL(TSize& aSize) |
|
1654 { |
|
1655 aSize = iOutputPictureSize; |
|
1656 } |
|
1657 |
|
1658 |
|
1659 // ----------------------------------------------------------------------------- |
|
1660 // CTRTranscoderImp::InitializeL |
|
1661 // Initializes transcider |
|
1662 // (other items were commented in a header). |
|
1663 // ----------------------------------------------------------------------------- |
|
1664 // |
|
1665 void CTRTranscoderImp::InitializeL() |
|
1666 { |
|
1667 PRINT((_L("CTRTranscoderImp::InitializeL(), In"))) |
|
1668 TInt status = KErrNone; |
|
1669 |
|
1670 |
|
1671 if (iState != ETROpened) |
|
1672 { |
|
1673 PRINT((_L("CTRTranscoderImp::InitializeL(), Transcoder is in wrong state"))) |
|
1674 User::Leave(KErrNotReady); |
|
1675 } |
|
1676 |
|
1677 switch(iMode) |
|
1678 { |
|
1679 case EFullTranscoding: |
|
1680 { |
|
1681 iVideoDecoderClient->InitializeL(); |
|
1682 |
|
1683 // Check encoder client if it supports optimized data transfer |
|
1684 TRAP( status, iVideoEncoderClient->UseDataTransferOptimizationL() ); |
|
1685 if (status == KErrNone) |
|
1686 { |
|
1687 iOptimizedDataTransfer = ETrue; |
|
1688 } |
|
1689 |
|
1690 TRAP(status, iVideoEncoderClient->InitializeL()); |
|
1691 |
|
1692 if (status != KErrNone) |
|
1693 { |
|
1694 iEncoderInitStatus = status; |
|
1695 InitComplete(); |
|
1696 } |
|
1697 |
|
1698 break; |
|
1699 } |
|
1700 |
|
1701 case EDecoding: |
|
1702 { |
|
1703 iEncoderInitStatus = KErrNone; |
|
1704 iVideoDecoderClient->InitializeL(); |
|
1705 break; |
|
1706 } |
|
1707 |
|
1708 case EEncoding: |
|
1709 { |
|
1710 iDecoderInitStatus = KErrNone; |
|
1711 iVideoEncoderClient->InitializeL(); |
|
1712 break; |
|
1713 } |
|
1714 |
|
1715 case EResampling: |
|
1716 { |
|
1717 // Resampler is already created |
|
1718 iState = ETRInitialized; |
|
1719 iObserver.MtroInitializeComplete(KErrNone); |
|
1720 return; |
|
1721 } |
|
1722 |
|
1723 default: |
|
1724 { |
|
1725 // Transcoder is not ready to be initialized |
|
1726 User::Leave(KErrNotReady); |
|
1727 break; |
|
1728 } |
|
1729 } |
|
1730 |
|
1731 PRINT((_L("CTRTranscoderImp::InitializeL(), Out"))) |
|
1732 } |
|
1733 |
|
1734 |
|
1735 // ----------------------------------------------------------------------------- |
|
1736 // CTRTranscoderImp::MtrdvcoEncInitializeComplete |
|
1737 // Encoder initializing is completed with aError |
|
1738 // (other items were commented in a header). |
|
1739 // ----------------------------------------------------------------------------- |
|
1740 // |
|
1741 void CTRTranscoderImp::MtrdvcoEncInitializeComplete(TInt aError) |
|
1742 { |
|
1743 PRINT((_L("CTRTranscoderImp::MtrdvcoEncInitializeComplete(), status[%d]"), aError)) |
|
1744 |
|
1745 if (aError == KErrHardwareNotAvailable) |
|
1746 { |
|
1747 // Encoder needs to be reinitialized |
|
1748 |
|
1749 // Check if encoder client supports optimized data transfer |
|
1750 iOptimizedDataTransfer = EFalse; |
|
1751 TRAPD( status, iVideoEncoderClient->UseDataTransferOptimizationL() ); |
|
1752 if (status == KErrNone) |
|
1753 { |
|
1754 iOptimizedDataTransfer = ETrue; |
|
1755 } |
|
1756 |
|
1757 PRINT((_L("CTRTranscoderImp::MtrdvcoEncInitializeComplete(), Trying to reinitialize encoder"))) |
|
1758 TRAP(status, iVideoEncoderClient->InitializeL()); |
|
1759 |
|
1760 if (status == KErrNone) |
|
1761 { |
|
1762 // Reinitialization done so wait for the next initialize complete call |
|
1763 return; |
|
1764 } |
|
1765 } |
|
1766 |
|
1767 iEncoderInitStatus = aError; |
|
1768 this->InitComplete(); |
|
1769 } |
|
1770 |
|
1771 |
|
1772 // ----------------------------------------------------------------------------- |
|
1773 // CTRTranscoderImp::MtrdvcoDecInitializeComplete |
|
1774 // Decoder initializing is completed with aError |
|
1775 // (other items were commented in a header). |
|
1776 // ----------------------------------------------------------------------------- |
|
1777 // |
|
1778 void CTRTranscoderImp::MtrdvcoDecInitializeComplete(TInt aError) |
|
1779 { |
|
1780 PRINT((_L("CTRTranscoderImp::MtrdvcoDecInitializeComplete(), status[%d]"), aError)) |
|
1781 |
|
1782 if (aError == KErrHardwareNotAvailable) |
|
1783 { |
|
1784 // Decoder needs to be reinitialized |
|
1785 |
|
1786 // Check if decoder supports scaling |
|
1787 iDecodedPictureSize = iInputPictureSize; |
|
1788 |
|
1789 // Set to default |
|
1790 iMaxFramesInProcessing = KTRMaxFramesInProcessingDefault; |
|
1791 |
|
1792 TBool srcWide = iScaler->IsWideAspectRatio(iInputPictureSize); |
|
1793 TBool dstWide = iScaler->IsWideAspectRatio(iOutputPictureSize); |
|
1794 |
|
1795 if (srcWide != dstWide) |
|
1796 { |
|
1797 |
|
1798 PRINT((_L("CTRTranscoderImp::MtrdvcoDecInitializeComplete(), black boxing needed"))) |
|
1799 |
|
1800 // get intermediate resolution from scaler |
|
1801 TSize resolution; |
|
1802 TSize bb = TSize(0,0); |
|
1803 |
|
1804 TBool scale = iScaler->GetIntermediateResolution(iInputPictureSize, iOutputPictureSize, |
|
1805 resolution, bb); |
|
1806 |
|
1807 PRINT((_L("CTRTranscoderImp::MtrdvcoDecInitializeComplete(), int. resolution (%d, %d), scale = %d"), |
|
1808 resolution.iWidth, resolution.iHeight, TInt(scale))) |
|
1809 |
|
1810 if (scale && iVideoDecoderClient->SetDecoderScaling(iInputPictureSize, resolution)) |
|
1811 { |
|
1812 |
|
1813 PRINT((_L("CTRTranscoderImp::MtrdvcoDecInitializeComplete(), decoder scaling supported"))) |
|
1814 |
|
1815 iDecodedPictureSize = resolution; |
|
1816 //iDecodedPictureSize = iOutputPictureSize; |
|
1817 |
|
1818 iMaxFramesInProcessing = KTRMaxFramesInProcessingScaling; |
|
1819 } |
|
1820 } |
|
1821 |
|
1822 else if (iVideoDecoderClient->SetDecoderScaling(iInputPictureSize, iOutputPictureSize)) |
|
1823 { |
|
1824 // Scaling is supported |
|
1825 iDecodedPictureSize = iOutputPictureSize; |
|
1826 |
|
1827 iMaxFramesInProcessing = KTRMaxFramesInProcessingScaling; |
|
1828 } |
|
1829 |
|
1830 PRINT((_L("CTRTranscoderImp::MtrdvcoDecInitializeComplete(), Trying to reinitialize decoder"))) |
|
1831 TRAPD(status, iVideoDecoderClient->InitializeL()); |
|
1832 |
|
1833 if (status == KErrNone) |
|
1834 { |
|
1835 // Reinitialization done so wait for the next initialize complete call |
|
1836 return; |
|
1837 } |
|
1838 } |
|
1839 |
|
1840 iDecoderInitStatus = aError; |
|
1841 this->InitComplete(); |
|
1842 } |
|
1843 |
|
1844 |
|
1845 // ----------------------------------------------------------------------------- |
|
1846 // CTRTranscoderImp::InitComplete |
|
1847 // Checks and reports init status to the client |
|
1848 // (other items were commented in a header). |
|
1849 // ----------------------------------------------------------------------------- |
|
1850 // |
|
1851 void CTRTranscoderImp::InitComplete() |
|
1852 { |
|
1853 TInt status = KErrNone; |
|
1854 |
|
1855 if ( (iEncoderInitStatus != KTRErrNotReady) && (iDecoderInitStatus != KTRErrNotReady) ) |
|
1856 { |
|
1857 // Both were initialized, check statuses |
|
1858 if ( (iEncoderInitStatus == KErrNone) && (iDecoderInitStatus == KErrNone) ) |
|
1859 { |
|
1860 // Both are ok, |
|
1861 // Allocate buffers for intrnal use |
|
1862 TRAP( status, this->AllocateBuffersL() ); |
|
1863 |
|
1864 if (status == KErrNone) |
|
1865 { |
|
1866 iState = ETRInitialized; |
|
1867 } |
|
1868 |
|
1869 // Inform the client |
|
1870 iObserver.MtroInitializeComplete(status); |
|
1871 } |
|
1872 else if (iDecoderInitStatus == KErrNone) |
|
1873 { |
|
1874 // Report encoder init error |
|
1875 iObserver.MtroInitializeComplete(iEncoderInitStatus); |
|
1876 } |
|
1877 else |
|
1878 { |
|
1879 // Report decoder init error |
|
1880 iObserver.MtroInitializeComplete(iDecoderInitStatus); |
|
1881 } |
|
1882 } |
|
1883 } |
|
1884 |
|
1885 |
|
1886 // ----------------------------------------------------------------------------- |
|
1887 // CTRTranscoderImp::StartL |
|
1888 // Starts data processing |
|
1889 // (other items were commented in a header). |
|
1890 // ----------------------------------------------------------------------------- |
|
1891 // |
|
1892 void CTRTranscoderImp::StartL() |
|
1893 { |
|
1894 if ( (iState == ETRInitialized) || (iState == ETRStopped) ) |
|
1895 { |
|
1896 switch(iMode) |
|
1897 { |
|
1898 case EFullTranscoding: |
|
1899 { |
|
1900 // Reset flag here |
|
1901 iAsyncStop = EFalse; |
|
1902 |
|
1903 iVideoDecoderClient->StartL(); |
|
1904 |
|
1905 if (!iBitRateSetting) |
|
1906 { |
|
1907 this->SetVideoBitRateL(iOutputMaxBitRate); |
|
1908 } |
|
1909 |
|
1910 iVideoEncoderClient->StartL(); |
|
1911 } |
|
1912 break; |
|
1913 |
|
1914 case EDecoding: |
|
1915 { |
|
1916 iVideoDecoderClient->StartL(); |
|
1917 } |
|
1918 break; |
|
1919 |
|
1920 case EEncoding: |
|
1921 { |
|
1922 if (!iBitRateSetting) |
|
1923 { |
|
1924 this->SetVideoBitRateL(iOutputMaxBitRate); |
|
1925 } |
|
1926 |
|
1927 iVideoEncoderClient->StartL(); |
|
1928 } |
|
1929 break; |
|
1930 |
|
1931 case EResampling: |
|
1932 { |
|
1933 // Nothing to do |
|
1934 } |
|
1935 break; |
|
1936 |
|
1937 default: |
|
1938 { |
|
1939 // Should never be reached |
|
1940 TRASSERT(0); |
|
1941 } |
|
1942 } |
|
1943 |
|
1944 iState = ETRRunning; |
|
1945 } |
|
1946 else |
|
1947 { |
|
1948 PRINT((_L("CTRTranscoderImp::StartL(), called in wrong state"))) |
|
1949 User::Leave(KErrNotReady); |
|
1950 } |
|
1951 } |
|
1952 |
|
1953 |
|
1954 // ----------------------------------------------------------------------------- |
|
1955 // CTRTranscoderImp::AllocateBuffersL |
|
1956 // Allocates internal buffers |
|
1957 // (other items were commented in a header). |
|
1958 // ----------------------------------------------------------------------------- |
|
1959 // |
|
1960 void CTRTranscoderImp::AllocateBuffersL() |
|
1961 { |
|
1962 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), In"))) |
|
1963 TInt i = 0; |
|
1964 TUint dataBufferSize = 0; |
|
1965 |
|
1966 |
|
1967 // Assume we are using 420 as a middle temporal format |
|
1968 dataBufferSize = iOutputPictureSize.iWidth * iOutputPictureSize.iHeight * 3 / 2; |
|
1969 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), data buffer size[%d]"), dataBufferSize)) |
|
1970 |
|
1971 // Allocate TVideoPicture containers |
|
1972 iVideoPictureArray = new (ELeave) TVideoPicture[ KTRPictureBuffersNumber ]; |
|
1973 |
|
1974 for (i = 0; i < KTRPictureBuffersNumber; i ++) |
|
1975 { |
|
1976 // Reset iRawData ptr |
|
1977 iVideoPictureArray[i].iData.iRawData = NULL; |
|
1978 } |
|
1979 |
|
1980 switch (iMode) |
|
1981 { |
|
1982 case EFullTranscoding: |
|
1983 { |
|
1984 // Allocate TTRVideoPicture containers (since the client requested to provide |
|
1985 // intermediate trancsoded content ) |
|
1986 iTRVideoPictureArray = new (ELeave)TTRVideoPicture[KTRPictureContainersNumber]; |
|
1987 |
|
1988 // Add TR picture containers to the queue |
|
1989 for (i = 0; i < KTRPictureContainersNumber; i ++) |
|
1990 { |
|
1991 iTranscoderTRPictureQueue.AddLast( iTRVideoPictureArray[i] ); |
|
1992 } |
|
1993 |
|
1994 if (iOptimizedDataTransfer) |
|
1995 { |
|
1996 // If optimized data transfer is used, no other allocations required. |
|
1997 return; |
|
1998 } |
|
1999 } |
|
2000 break; |
|
2001 |
|
2002 case EDecoding: |
|
2003 { |
|
2004 if ( iDecodedPictureSize == iOutputPictureSize ) |
|
2005 { |
|
2006 // Resampling and data allocation is not required |
|
2007 return; |
|
2008 } |
|
2009 } |
|
2010 break; |
|
2011 |
|
2012 case EEncoding: |
|
2013 { |
|
2014 if ( iInputPictureSize == iOutputPictureSize ) |
|
2015 { |
|
2016 // Allocation data buffers for iVideoPictureArray is not needed, TVideoPicture |
|
2017 // containers are enough in this case. Initialize the queue |
|
2018 for (i = 0; i < KTRPictureBuffersNumber; i ++) |
|
2019 { |
|
2020 iTranscoderPictureQueue.AddLast( iVideoPictureArray[i] ); |
|
2021 } |
|
2022 |
|
2023 return; |
|
2024 } |
|
2025 } |
|
2026 break; |
|
2027 |
|
2028 case EResampling: |
|
2029 { |
|
2030 // Nothing to do |
|
2031 return; |
|
2032 } |
|
2033 |
|
2034 default: |
|
2035 { |
|
2036 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), Not ready, mode[%d]"), iMode)) |
|
2037 User::Leave(KErrNotReady); |
|
2038 } |
|
2039 break; |
|
2040 } |
|
2041 |
|
2042 // Common part |
|
2043 // Allocate data buffers |
|
2044 iDataArray = new (ELeave) TUint8*[ KTRPictureBuffersNumber ]; |
|
2045 |
|
2046 for ( i = 0; i < KTRPictureBuffersNumber; i ++ ) |
|
2047 { |
|
2048 iDataArray[i] = NULL; |
|
2049 } |
|
2050 |
|
2051 for ( i = 0; i < KTRPictureBuffersNumber; i ++ ) |
|
2052 { |
|
2053 iDataArray[i] = new (ELeave) TUint8[dataBufferSize]; |
|
2054 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), data buffer[%d], [0x%x], allocated"), i, iDataArray[i])) |
|
2055 } |
|
2056 |
|
2057 // Initialize the queue |
|
2058 for ( i = 0; i < KTRPictureBuffersNumber; i ++ ) |
|
2059 { |
|
2060 iVideoPictureArray[i].iData.iRawData = new (ELeave) TPtr8(0, 0, 0); |
|
2061 iVideoPictureArray[i].iData.iRawData->Set(iDataArray[i], dataBufferSize, dataBufferSize); |
|
2062 iVideoPictureArray[i].iData.iDataSize.SetSize(iOutputPictureSize.iWidth, |
|
2063 iOutputPictureSize.iHeight); |
|
2064 iTranscoderPictureQueue.AddLast( iVideoPictureArray[i] ); |
|
2065 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), picture[%d], added to the queue"), i)) |
|
2066 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), picture data[0x%x]"), |
|
2067 iVideoPictureArray[i].iData.iRawData->Ptr() )) |
|
2068 } |
|
2069 |
|
2070 PRINT((_L("CTRTranscoderImp::AllocateBuffersL(), Out"))) |
|
2071 } |
|
2072 |
|
2073 |
|
2074 // ----------------------------------------------------------------------------- |
|
2075 // CTRTranscoderImp::WriteCodedBufferL |
|
2076 // Writes coded buffer to transcoder |
|
2077 // (other items were commented in a header). |
|
2078 // ----------------------------------------------------------------------------- |
|
2079 // |
|
2080 void CTRTranscoderImp::WriteCodedBufferL(CCMRMediaBuffer* aBuffer) |
|
2081 { |
|
2082 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), In"))) |
|
2083 CTREventItem* newEvent = NULL; |
|
2084 |
|
2085 if (!aBuffer) |
|
2086 { |
|
2087 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), Client sends invalid data"))) |
|
2088 User::Leave(KErrArgument); |
|
2089 } |
|
2090 |
|
2091 if (iState == ETRRunning) |
|
2092 { |
|
2093 if (iSetRandomAccessPoint) |
|
2094 { |
|
2095 // Get new item from the eventsrc |
|
2096 if (!iTranscoderEventSrc.IsEmpty()) |
|
2097 { |
|
2098 newEvent = iTranscoderEventSrc.First(); |
|
2099 newEvent->iLink.Deque(); |
|
2100 } |
|
2101 else |
|
2102 { |
|
2103 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), iTranscoderEventSrc queue is empty, abort"))) |
|
2104 iObserver.MtroFatalError(KErrAbort); |
|
2105 return; |
|
2106 } |
|
2107 |
|
2108 if (newEvent) |
|
2109 { |
|
2110 newEvent->iTimestamp = aBuffer->TimeStamp(); |
|
2111 newEvent->iRandomAccessStatus = ETrue; |
|
2112 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), picture[%f] RandomAccess"), I64REAL(aBuffer->TimeStamp().Int64()) )) |
|
2113 } |
|
2114 |
|
2115 iSetRandomAccessPoint = EFalse; |
|
2116 } |
|
2117 |
|
2118 if (iPictureSinkSettingChanged) |
|
2119 { |
|
2120 if (!newEvent) |
|
2121 { |
|
2122 // Get new item from the event src queue |
|
2123 if (!iTranscoderEventSrc.IsEmpty()) |
|
2124 { |
|
2125 newEvent = iTranscoderEventSrc.First(); |
|
2126 newEvent->iLink.Deque(); |
|
2127 } |
|
2128 else |
|
2129 { |
|
2130 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), iTranscoderEventSrc queue is empty, abort"))) |
|
2131 iObserver.MtroFatalError(KErrAbort); |
|
2132 return; |
|
2133 } |
|
2134 } |
|
2135 |
|
2136 if (newEvent) |
|
2137 { |
|
2138 newEvent->iTimestamp = aBuffer->TimeStamp(); |
|
2139 newEvent->iEnablePictureSinkStatus = ETrue; |
|
2140 newEvent->iEnablePictureSinkClientSetting = iPictureSinkClientSetting; |
|
2141 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), picture[%f] PS[%d]"), I64REAL(aBuffer->TimeStamp().Int64()), iPictureSinkClientSetting )) |
|
2142 } |
|
2143 |
|
2144 // Reset change flag |
|
2145 iPictureSinkSettingChanged = EFalse; |
|
2146 } |
|
2147 |
|
2148 // encoder enabled / disabled |
|
2149 if (iEncoderEnabledSettingChanged) |
|
2150 { |
|
2151 if (!newEvent) |
|
2152 { |
|
2153 // Get new item from the eventsrc |
|
2154 if (!iTranscoderEventSrc.IsEmpty()) |
|
2155 { |
|
2156 newEvent = iTranscoderEventSrc.First(); |
|
2157 newEvent->iLink.Deque(); |
|
2158 } |
|
2159 else |
|
2160 { |
|
2161 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), iTranscoderEventSrc queue is empty, abort"))) |
|
2162 iObserver.MtroFatalError(KErrAbort); |
|
2163 return; |
|
2164 } |
|
2165 } |
|
2166 |
|
2167 if (newEvent) |
|
2168 { |
|
2169 newEvent->iTimestamp = aBuffer->TimeStamp(); |
|
2170 newEvent->iEnableEncoderStatus = ETrue; |
|
2171 newEvent->iEnableEncoderClientSetting = iEncoderEnableClientSetting; |
|
2172 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), picture[%f] Enc[%d]"), I64REAL(aBuffer->TimeStamp().Int64()), iEncoderEnableClientSetting )) |
|
2173 } |
|
2174 |
|
2175 // Reset change flag |
|
2176 iEncoderEnabledSettingChanged = EFalse; |
|
2177 } |
|
2178 |
|
2179 if (newEvent) |
|
2180 { |
|
2181 // Put it to transcoder event queue |
|
2182 iTranscoderEventQueue.AddLast(*newEvent); |
|
2183 } |
|
2184 |
|
2185 // Write buffer to DecoderClient |
|
2186 iVideoDecoderClient->WriteCodedBufferL(aBuffer); |
|
2187 } |
|
2188 else |
|
2189 { |
|
2190 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), wrong state"))) |
|
2191 User::Leave(KErrNotReady); |
|
2192 } |
|
2193 |
|
2194 PRINT((_L("CTRTranscoderImp::WriteCodedBufferL(), Out"))) |
|
2195 } |
|
2196 |
|
2197 |
|
2198 // ----------------------------------------------------------------------------- |
|
2199 // CTRTranscoderImp::MtroReturnCodedBuffer |
|
2200 // Returns coded buffer |
|
2201 // (other items were commented in a header). |
|
2202 // ----------------------------------------------------------------------------- |
|
2203 // |
|
2204 void CTRTranscoderImp::MtrdvcoReturnCodedBuffer(CCMRMediaBuffer* aBuffer) |
|
2205 { |
|
2206 iObserver.MtroReturnCodedBuffer(aBuffer); |
|
2207 } |
|
2208 |
|
2209 |
|
2210 // ----------------------------------------------------------------------------- |
|
2211 // CTRTranscoderImp::MtrdvcoNewPicture |
|
2212 // New decoded picture is available |
|
2213 // (other items were commented in a header). |
|
2214 // ----------------------------------------------------------------------------- |
|
2215 // |
|
2216 void CTRTranscoderImp::MtrdvcoNewPicture(TVideoPicture* aDecodedPicture) |
|
2217 { |
|
2218 TInt status = KErrNone; |
|
2219 TVideoPicture* picture = NULL; |
|
2220 CTREventItem* nextEvent = NULL; |
|
2221 MTRVideoPictureSink* pictureSink = iPictureSinkTemp; // |
|
2222 TBool pictureSinkEnabled = iCurrentPictureSinkEnabled; |
|
2223 TBool encoderEnabled = iCurrentEncoderEnabled; |
|
2224 |
|
2225 if (iState == ETRFatalError) |
|
2226 { |
|
2227 // Nothing to do |
|
2228 return; |
|
2229 } |
|
2230 |
|
2231 if (!aDecodedPicture) |
|
2232 { |
|
2233 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), decoded picture is not valid"))) |
|
2234 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2235 return; |
|
2236 } |
|
2237 else if (!aDecodedPicture->iData.iRawData) |
|
2238 { |
|
2239 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), picture raw data is not valid"))) |
|
2240 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2241 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2242 return; |
|
2243 } |
|
2244 |
|
2245 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), decoded picture timestamp [%f]"), I64REAL(aDecodedPicture->iTimestamp.Int64()) )) |
|
2246 |
|
2247 switch(iMode) |
|
2248 { |
|
2249 case EFullTranscoding: |
|
2250 { |
|
2251 if ( !iNewEvent && !iTranscoderEventQueue.IsEmpty() ) |
|
2252 { |
|
2253 // Get new event |
|
2254 iNewEvent = iTranscoderEventQueue.First(); |
|
2255 iNewEvent->iLink.Deque(); |
|
2256 |
|
2257 // Check the next event if there are any |
|
2258 if (!iTranscoderEventQueue.IsEmpty()) |
|
2259 { |
|
2260 nextEvent = iTranscoderEventQueue.First(); |
|
2261 |
|
2262 if (aDecodedPicture->iTimestamp >= nextEvent->iTimestamp) |
|
2263 { |
|
2264 // Should not happen normally, indicate an error |
|
2265 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Previous event was not handled properly, abort data processing"))) |
|
2266 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2267 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2268 return; |
|
2269 } |
|
2270 } |
|
2271 } |
|
2272 |
|
2273 if (iNewEvent) |
|
2274 { |
|
2275 // Check timestamp for this event |
|
2276 if (aDecodedPicture->iTimestamp >= iNewEvent->iTimestamp) |
|
2277 { |
|
2278 // Perform requested client's operation |
|
2279 // 1. PictureSinkStatus |
|
2280 if (iNewEvent->iEnablePictureSinkStatus) |
|
2281 { |
|
2282 pictureSinkEnabled = iNewEvent->iEnablePictureSinkClientSetting; |
|
2283 } |
|
2284 |
|
2285 // 2. EnableEncoderStatus |
|
2286 if (iNewEvent->iEnableEncoderStatus) |
|
2287 { |
|
2288 encoderEnabled = iNewEvent->iEnableEncoderClientSetting; |
|
2289 } |
|
2290 |
|
2291 // 3. Random access |
|
2292 if (iNewEvent->iRandomAccessStatus) |
|
2293 { |
|
2294 iCurrentRandomAccess = iNewEvent->iRandomAccessStatus; |
|
2295 } |
|
2296 |
|
2297 // This event is already handled, it's not new anymore |
|
2298 if (!pictureSinkEnabled && !encoderEnabled) |
|
2299 { |
|
2300 // Picture is returned to decoder, we don't need any actions for that |
|
2301 iNewEvent->Reset(); |
|
2302 iTranscoderEventSrc.AddLast(*iNewEvent); |
|
2303 } |
|
2304 else if (pictureSinkEnabled) |
|
2305 { |
|
2306 if (iIntermediatePictureSize == iDecodedPictureSize) |
|
2307 { |
|
2308 // Picture is sent to the client first, decoded picture is not returned |
|
2309 // to decoder until it's hold by the client. |
|
2310 // No new events are handled here, act according global settings. |
|
2311 iNewEvent->Reset(); |
|
2312 iTranscoderEventSrc.AddLast(*iNewEvent); |
|
2313 } |
|
2314 else |
|
2315 { |
|
2316 // Picture is processed acynchronously first |
|
2317 iTranscoderAsyncEventQueue.AddLast(*iNewEvent); |
|
2318 |
|
2319 // Keep previous current global setting |
|
2320 iCurrentAsyncPictureSinkEnabled = iCurrentPictureSinkEnabled; |
|
2321 iCurrentAsyncEncoderEnabled = iCurrentEncoderEnabled; |
|
2322 } |
|
2323 } |
|
2324 else // encoderEnabled otherwise |
|
2325 { |
|
2326 // Picture is processed acynchronously first |
|
2327 iTranscoderAsyncEventQueue.AddLast(*iNewEvent); |
|
2328 |
|
2329 // Keep previous current global setting |
|
2330 iCurrentAsyncPictureSinkEnabled = iCurrentPictureSinkEnabled; |
|
2331 iCurrentAsyncEncoderEnabled = iCurrentEncoderEnabled; |
|
2332 } |
|
2333 |
|
2334 // Reset new event |
|
2335 iNewEvent = NULL; |
|
2336 |
|
2337 // Update current settings |
|
2338 iCurrentPictureSinkEnabled = pictureSinkEnabled; |
|
2339 iCurrentEncoderEnabled = encoderEnabled; |
|
2340 } |
|
2341 } |
|
2342 |
|
2343 // Settings now defined, act accordingly |
|
2344 if (!pictureSinkEnabled && !encoderEnabled) |
|
2345 { |
|
2346 // Nothing to do with this picture, return it to decoder |
|
2347 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), return picture[%f] to decoder"), I64REAL(aDecodedPicture->iTimestamp.Int64()) )) |
|
2348 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2349 return; |
|
2350 } |
|
2351 |
|
2352 if (pictureSinkEnabled) |
|
2353 { |
|
2354 pictureSink = iPictureSinkTemp; |
|
2355 |
|
2356 if (!pictureSink) |
|
2357 { |
|
2358 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), picture sink was not set, report to client!"))) |
|
2359 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2360 iObserver.MtroFatalError(KErrNotReady); |
|
2361 return; |
|
2362 } |
|
2363 } |
|
2364 else |
|
2365 { |
|
2366 pictureSink = NULL; |
|
2367 } |
|
2368 |
|
2369 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), PS[%d], Enc[%d], RandAcc[%d] for [%f]"), pictureSinkEnabled, encoderEnabled, iCurrentRandomAccess, I64REAL(aDecodedPicture->iTimestamp.Int64()) )) |
|
2370 |
|
2371 if ( pictureSink && (iIntermediatePictureSize == iDecodedPictureSize) ) |
|
2372 { |
|
2373 // Since the client requested to provide initial decoded picture, send |
|
2374 // it first, and only then resample and encode. (See SendPictureToTranscoder) |
|
2375 if (!iTranscoderTRPictureQueue.IsEmpty()) |
|
2376 { |
|
2377 TTRVideoPicture* pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2378 pictureToClient->iLink.Deque(); |
|
2379 pictureToClient->iRawData = aDecodedPicture->iData.iRawData; |
|
2380 pictureToClient->iDataSize = aDecodedPicture->iData.iDataSize; |
|
2381 pictureToClient->iTimestamp = aDecodedPicture->iTimestamp; |
|
2382 |
|
2383 // Store picture until it's returned from the client |
|
2384 iDecodedPicture = aDecodedPicture; |
|
2385 |
|
2386 // Deliver picture to the client |
|
2387 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), send picture to the client via sink"))) |
|
2388 pictureSink->MtroPictureFromTranscoder(pictureToClient); |
|
2389 } |
|
2390 else |
|
2391 { |
|
2392 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), iTranscoderTRPictureQueue is empty, abort operation"))) |
|
2393 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2394 iObserver.MtroFatalError(KErrAbort); |
|
2395 } |
|
2396 |
|
2397 return; |
|
2398 } |
|
2399 |
|
2400 if (iOptimizedDataTransfer) |
|
2401 { |
|
2402 // We need a new picture buffer every time !!! |
|
2403 if ( !iCIPictureBuffersQueue.IsEmpty() ) |
|
2404 { |
|
2405 picture = iCIPictureBuffersQueue.First(); |
|
2406 picture->iLink.Deque(); |
|
2407 } |
|
2408 else |
|
2409 { |
|
2410 TRAP( status, picture = iVideoEncoderClient->GetTargetVideoPictureL() ); |
|
2411 } |
|
2412 |
|
2413 if (status != KErrNone) |
|
2414 { |
|
2415 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), GetTargetVideoPictureL failed [%d]"), status)) |
|
2416 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2417 iObserver.MtroFatalError(status); |
|
2418 return; |
|
2419 } |
|
2420 else if (picture) |
|
2421 { |
|
2422 // Set options for picture |
|
2423 picture->iData.iDataSize = iOutputPictureSize; |
|
2424 |
|
2425 // we don't support resampling for 422, set default for 420 length |
|
2426 // Add check of output data format (422 or 420) in the future and set dataLength properly |
|
2427 TInt length = iOutputPictureSize.iWidth * iOutputPictureSize.iHeight * 3 / 2; |
|
2428 |
|
2429 if ( length > picture->iData.iRawData->MaxLength() ) |
|
2430 { |
|
2431 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), length exceeds CI buffer maxlength[%d, %d]"), length, picture->iData.iRawData->MaxLength() )) |
|
2432 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2433 iObserver.MtroFatalError(KErrGeneral); |
|
2434 return; |
|
2435 } |
|
2436 |
|
2437 // set length |
|
2438 picture->iData.iRawData->SetLength(length); |
|
2439 } |
|
2440 else |
|
2441 { |
|
2442 if (iRealTime) // (picture is not available, act according realtime mode) |
|
2443 { |
|
2444 // Picture buffer is not available from encoder hwdevice |
|
2445 // return decoded picture back, otherwise suspend decoding.. |
|
2446 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Picture buffer is not available through CI, Drop") )) |
|
2447 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2448 return; |
|
2449 } |
|
2450 else |
|
2451 { |
|
2452 // Keep picture and does not return it to DecoderClient before processing |
|
2453 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Picture buffer is not available through CI, store") )) |
|
2454 iWaitNewDecodedPicture = aDecodedPicture; |
|
2455 return; |
|
2456 } |
|
2457 } |
|
2458 } |
|
2459 else |
|
2460 { |
|
2461 if (!iTranscoderPictureQueue.IsEmpty()) |
|
2462 { |
|
2463 picture = iTranscoderPictureQueue.First(); |
|
2464 } |
|
2465 else |
|
2466 { |
|
2467 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), iTranscoderPictureQueue is empty"))) |
|
2468 |
|
2469 if (iRealTime) // (picture is not available, act according realtime mode) |
|
2470 { |
|
2471 // Picture buffer is not available from encoder hwdevice |
|
2472 // return decoded picture back, otherwise suspend decoding.. |
|
2473 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Picture buffer is not available fromEncoder, Drop") )) |
|
2474 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2475 return; |
|
2476 } |
|
2477 else |
|
2478 { |
|
2479 // Keep picture and does not return it to DecoderClient before processing |
|
2480 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Picture buffer is not available fromEncoder, store") )) |
|
2481 iWaitNewDecodedPicture = aDecodedPicture; |
|
2482 return; |
|
2483 } |
|
2484 } |
|
2485 } |
|
2486 |
|
2487 if (picture) |
|
2488 { |
|
2489 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), picture[0x%x], data[0x%x]"), |
|
2490 picture, picture->iData.iRawData->Ptr() )) |
|
2491 |
|
2492 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), decPicture[0x%x], data[0x%x]"), |
|
2493 aDecodedPicture, aDecodedPicture->iData.iRawData->Ptr() )) |
|
2494 |
|
2495 // Resample this picture |
|
2496 TRAP(status, iScaler->SetScalerOptionsL( *(aDecodedPicture->iData.iRawData), *(picture->iData.iRawData), |
|
2497 aDecodedPicture->iData.iDataSize, picture->iData.iDataSize ) ); |
|
2498 if (status != KErrNone) |
|
2499 { |
|
2500 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Set scaler options failed[%d]"), status)) |
|
2501 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2502 iObserver.MtroFatalError(status); |
|
2503 return; |
|
2504 } |
|
2505 |
|
2506 if (!iOptimizedDataTransfer) |
|
2507 { |
|
2508 // Remove picture from transcoder queue |
|
2509 picture->iLink.Deque(); |
|
2510 } |
|
2511 |
|
2512 // Scale |
|
2513 iScaler->Scale(); |
|
2514 picture->iData.iDataFormat = EYuvRawData; |
|
2515 picture->iTimestamp = aDecodedPicture->iTimestamp; |
|
2516 |
|
2517 // Put resampled picture to encoder queue |
|
2518 iEncoderPictureQueue.AddLast(*picture); |
|
2519 |
|
2520 // Make request to process this picture |
|
2521 this->DoRequest(); |
|
2522 |
|
2523 // Return used picture to decoder |
|
2524 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2525 } |
|
2526 else |
|
2527 { |
|
2528 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Transcoder picture queue is empty, skip this buffer"))) |
|
2529 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2530 } |
|
2531 } |
|
2532 break; |
|
2533 |
|
2534 case EDecoding: |
|
2535 { |
|
2536 if (!iPictureSink) |
|
2537 { |
|
2538 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), iPictureSink was not set"))) |
|
2539 iObserver.MtroFatalError(KErrNotReady); |
|
2540 return; |
|
2541 } |
|
2542 |
|
2543 if (aDecodedPicture->iData.iDataSize.iWidth != iDecodedPictureSize.iWidth || |
|
2544 aDecodedPicture->iData.iDataSize.iHeight != iDecodedPictureSize.iHeight ) |
|
2545 { |
|
2546 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), picture size is not valid"))) |
|
2547 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2548 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2549 return; |
|
2550 } |
|
2551 |
|
2552 // Store picture until it's returned from the client |
|
2553 iDecodedPicture = aDecodedPicture; |
|
2554 |
|
2555 if (iDecodedPictureSize == iOutputPictureSize) |
|
2556 { |
|
2557 // Send picture directly to the client |
|
2558 iPicureToClient.iRawData = aDecodedPicture->iData.iRawData; |
|
2559 iPicureToClient.iDataSize = aDecodedPicture->iData.iDataSize; |
|
2560 iPicureToClient.iTimestamp = aDecodedPicture->iTimestamp; |
|
2561 iPictureSink->MtroPictureFromTranscoder(&iPicureToClient); |
|
2562 } |
|
2563 else |
|
2564 { |
|
2565 // Resample this picture to desired size and send to the client |
|
2566 if ( !iTranscoderPictureQueue.IsEmpty() ) |
|
2567 { |
|
2568 iVideoPictureTemp = iTranscoderPictureQueue.First(); |
|
2569 iVideoPictureTemp->iLink.Deque(); |
|
2570 |
|
2571 // Resample this picture |
|
2572 TRAP(status, iScaler->SetScalerOptionsL( *(aDecodedPicture->iData.iRawData), *(iVideoPictureTemp->iData.iRawData), |
|
2573 aDecodedPicture->iData.iDataSize, iVideoPictureTemp->iData.iDataSize ) ); |
|
2574 if (status != KErrNone) |
|
2575 { |
|
2576 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), Set scaler options failed[%d]"), status)) |
|
2577 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2578 iObserver.MtroFatalError(status); |
|
2579 return; |
|
2580 } |
|
2581 |
|
2582 iScaler->Scale(); |
|
2583 iPicureToClient.iRawData = iVideoPictureTemp->iData.iRawData; |
|
2584 iPicureToClient.iDataSize = iVideoPictureTemp->iData.iDataSize; |
|
2585 iPicureToClient.iTimestamp = aDecodedPicture->iTimestamp; |
|
2586 |
|
2587 // Return decoded picture to decoder |
|
2588 iVideoDecoderClient->ReturnPicture(aDecodedPicture); |
|
2589 |
|
2590 // Sent picture to the client |
|
2591 iPictureSink->MtroPictureFromTranscoder(&iPicureToClient); |
|
2592 } |
|
2593 } |
|
2594 } |
|
2595 break; |
|
2596 |
|
2597 default: |
|
2598 { |
|
2599 PRINT((_L("CTRTranscoderImp::MtrdvcoNewPicture(), observer should not be called in this mode"))) |
|
2600 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2601 return; |
|
2602 } |
|
2603 } |
|
2604 } |
|
2605 |
|
2606 |
|
2607 // ----------------------------------------------------------------------------- |
|
2608 // CTRTranscoderImp::DoRequest |
|
2609 // Makes a new request |
|
2610 // (other items were commented in a header). |
|
2611 // ----------------------------------------------------------------------------- |
|
2612 // |
|
2613 void CTRTranscoderImp::DoRequest() |
|
2614 { |
|
2615 if ( !this->IsActive() ) |
|
2616 { |
|
2617 this->SetActive(); |
|
2618 iStat = &iStatus; |
|
2619 User::RequestComplete( iStat, KErrNone ); |
|
2620 } |
|
2621 else |
|
2622 { |
|
2623 PRINT((_L("CTRTranscoderImp::DoRequest(), AO is already active"))) |
|
2624 } |
|
2625 } |
|
2626 |
|
2627 |
|
2628 // ----------------------------------------------------------------------------- |
|
2629 // CTRTranscoderImp::RunL |
|
2630 // CActive's RunL implementation |
|
2631 // (other items were commented in a header). |
|
2632 // ----------------------------------------------------------------------------- |
|
2633 // |
|
2634 void CTRTranscoderImp::RunL() |
|
2635 { |
|
2636 PRINT((_L("CTRTranscoderImp::RunL(), In"))) |
|
2637 TVideoPicture* picture = NULL; |
|
2638 MTRVideoPictureSink* pictureSink = iPictureSinkTemp; |
|
2639 TBool pictureSinkEnabled = iCurrentAsyncPictureSinkEnabled; |
|
2640 TBool encoderEnabled = iCurrentAsyncEncoderEnabled; |
|
2641 TBool randomAccess = EFalse; |
|
2642 |
|
2643 |
|
2644 if ( !iEncoderPictureQueue.IsEmpty() ) |
|
2645 { |
|
2646 switch(iMode) |
|
2647 { |
|
2648 case EFullTranscoding: |
|
2649 { |
|
2650 // Encode all pictures in the queue |
|
2651 TInt count = 0; |
|
2652 |
|
2653 |
|
2654 while ( !iEncoderPictureQueue.IsEmpty() ) |
|
2655 { |
|
2656 PRINT((_L("CTRTranscoderImp::RunL(), count[%d]"), count)) |
|
2657 count ++; |
|
2658 picture = iEncoderPictureQueue.First(); |
|
2659 |
|
2660 // Check event queue |
|
2661 if (!iAsyncEvent && !iTranscoderAsyncEventQueue.IsEmpty()) |
|
2662 { |
|
2663 // Trasnscoder configuration is unknown, handle new event |
|
2664 iAsyncEvent = iTranscoderAsyncEventQueue.First(); |
|
2665 iAsyncEvent->iLink.Deque(); |
|
2666 } |
|
2667 |
|
2668 if (iAsyncEvent) |
|
2669 { |
|
2670 // Check timestamp for this event |
|
2671 if (picture->iTimestamp >= iAsyncEvent->iTimestamp) |
|
2672 { |
|
2673 // Perform requested client's operation |
|
2674 // 1. PictureSinkStatus |
|
2675 if (iAsyncEvent->iEnablePictureSinkStatus) |
|
2676 { |
|
2677 pictureSinkEnabled = iAsyncEvent->iEnablePictureSinkClientSetting; |
|
2678 } |
|
2679 |
|
2680 // 2. EnableEncoderStatus |
|
2681 if (iAsyncEvent->iEnableEncoderStatus) |
|
2682 { |
|
2683 encoderEnabled = iAsyncEvent->iEnableEncoderClientSetting; |
|
2684 } |
|
2685 |
|
2686 // 3. RandomAccess |
|
2687 if (iAsyncEvent->iRandomAccessStatus) |
|
2688 { |
|
2689 randomAccess = iAsyncEvent->iRandomAccessStatus; |
|
2690 } |
|
2691 |
|
2692 // This event is already handled, we don't need it anymore |
|
2693 iAsyncEvent->Reset(); |
|
2694 iTranscoderEventSrc.AddLast(*iAsyncEvent); |
|
2695 iAsyncEvent = NULL; |
|
2696 |
|
2697 // Update current settings |
|
2698 iCurrentAsyncPictureSinkEnabled = pictureSinkEnabled; |
|
2699 iCurrentAsyncEncoderEnabled = encoderEnabled; |
|
2700 iCurrentAsyncRandomAccess = randomAccess; |
|
2701 } |
|
2702 } |
|
2703 // Else: Event queue is empty, act according async global options |
|
2704 |
|
2705 // Settings now defined, act accordingly |
|
2706 PRINT((_L("CTRTranscoderImp::RunL(), PS[%d], Enc[%d], RandAcc[%d] for [%f]"), |
|
2707 pictureSinkEnabled, encoderEnabled, randomAccess, I64REAL(picture->iTimestamp.Int64()) )) |
|
2708 |
|
2709 if (pictureSinkEnabled) |
|
2710 { |
|
2711 if (!pictureSink) |
|
2712 { |
|
2713 PRINT((_L("CTRTranscoderImp::RunL(), Picture sink was not set, time to panic"))) |
|
2714 TRASSERT(0); |
|
2715 } |
|
2716 |
|
2717 // Send decoded picture to the client first, and encode it after returning |
|
2718 if (!iTranscoderTRPictureQueue.IsEmpty()) |
|
2719 { |
|
2720 picture->iLink.Deque(); |
|
2721 |
|
2722 TTRVideoPicture* pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2723 pictureToClient->iLink.Deque(); |
|
2724 pictureToClient->iRawData = picture->iData.iRawData; |
|
2725 pictureToClient->iDataSize = picture->iData.iDataSize; |
|
2726 pictureToClient->iTimestamp = picture->iTimestamp; |
|
2727 |
|
2728 // Keep TVideoPicture container to the iContainerWaitQueue until the picture is returned back. |
|
2729 iContainerWaitQueue.AddLast(*picture); |
|
2730 |
|
2731 // Deliver picture to the client |
|
2732 pictureSink->MtroPictureFromTranscoder(pictureToClient); |
|
2733 // |
|
2734 // return; |
|
2735 } |
|
2736 else |
|
2737 { |
|
2738 PRINT((_L("CTRTranscoderImp::RunL(), iTranscoderTRPictureQueue is empty, abort"))) |
|
2739 iObserver.MtroFatalError(KErrAbort); |
|
2740 return; |
|
2741 } |
|
2742 } |
|
2743 else if (!encoderEnabled) |
|
2744 { |
|
2745 // All picture in this queue must be encoded |
|
2746 PRINT((_L("CTRTranscoderImp::RunL(), All pictures from iEncoderPictureQueue must be encoded, error!"))) |
|
2747 TRASSERT(0); |
|
2748 } |
|
2749 else |
|
2750 { |
|
2751 // Send picture to encoder |
|
2752 picture = iEncoderPictureQueue.First(); |
|
2753 picture->iLink.Deque(); |
|
2754 |
|
2755 if (randomAccess) |
|
2756 { |
|
2757 iVideoEncoderClient->SetRandomAccessPoint(); |
|
2758 randomAccess = EFalse; |
|
2759 } |
|
2760 |
|
2761 iVideoEncoderClient->EncodePictureL(picture); |
|
2762 } |
|
2763 } // END while loop |
|
2764 } |
|
2765 break; |
|
2766 |
|
2767 case EDecoding: |
|
2768 { |
|
2769 // Send decoded picture to the client. |
|
2770 if (!iTranscoderTRPictureQueue.IsEmpty()) |
|
2771 { |
|
2772 picture = iEncoderPictureQueue.First(); |
|
2773 picture->iLink.Deque(); |
|
2774 |
|
2775 // Take Transcoder picture container |
|
2776 TTRVideoPicture* pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2777 pictureToClient->iLink.Deque(); |
|
2778 |
|
2779 pictureToClient->iRawData = picture->iData.iRawData; |
|
2780 pictureToClient->iDataSize = picture->iData.iDataSize; |
|
2781 pictureToClient->iTimestamp = picture->iTimestamp; |
|
2782 |
|
2783 if (iPictureSink) |
|
2784 { |
|
2785 iPictureSink->MtroPictureFromTranscoder(pictureToClient); |
|
2786 } |
|
2787 else |
|
2788 { |
|
2789 // Should not happen |
|
2790 PRINT((_L("CTRTranscoderImp::RunL(), Decoding, PictureSink is not valid"))) |
|
2791 TRASSERT(0); |
|
2792 } |
|
2793 |
|
2794 // Keep TVideoPicture container to the iContainerWaitQueue until the picture is returned back. |
|
2795 iContainerWaitQueue.AddLast(*picture); |
|
2796 } |
|
2797 } |
|
2798 break; |
|
2799 |
|
2800 case EEncoding: |
|
2801 { |
|
2802 // Send picture to video encoder |
|
2803 if ( !iEncoderPictureQueue.IsEmpty() ) |
|
2804 { |
|
2805 picture = iEncoderPictureQueue.First(); |
|
2806 picture->iLink.Deque(); |
|
2807 iVideoEncoderClient->EncodePictureL(picture); |
|
2808 } |
|
2809 } |
|
2810 break; |
|
2811 |
|
2812 case EResampling: |
|
2813 { |
|
2814 PRINT((_L("CTRTranscoderImp::RunL(), should not be called in Resampling mode"))) |
|
2815 TRASSERT(0); |
|
2816 } |
|
2817 break; |
|
2818 |
|
2819 case EOperationNone: |
|
2820 { |
|
2821 User::Leave(KErrNotReady); |
|
2822 } |
|
2823 break; |
|
2824 |
|
2825 default: |
|
2826 { |
|
2827 User::Leave(KErrNotReady); |
|
2828 } |
|
2829 break; |
|
2830 } |
|
2831 } |
|
2832 |
|
2833 PRINT((_L("CTRTranscoderImp::RunL(), Out"))) |
|
2834 } |
|
2835 |
|
2836 |
|
2837 // ----------------------------------------------------------------------------- |
|
2838 // CTRTranscoderImp::DoCancel |
|
2839 // Cancel |
|
2840 // (other items were commented in a header). |
|
2841 // ----------------------------------------------------------------------------- |
|
2842 // |
|
2843 void CTRTranscoderImp::DoCancel() |
|
2844 { |
|
2845 // Nothing to do |
|
2846 } |
|
2847 |
|
2848 |
|
2849 // ----------------------------------------------------------------------------- |
|
2850 // CTRTranscoderImp::RunError |
|
2851 // Handles AO leave |
|
2852 // (other items were commented in a header). |
|
2853 // ----------------------------------------------------------------------------- |
|
2854 // |
|
2855 TInt CTRTranscoderImp::RunError(TInt aError) |
|
2856 { |
|
2857 PRINT((_L("CTRTranscoderImp::RunError(), seems RunL leaved, error[%d]."), aError)) |
|
2858 |
|
2859 iObserver.MtroFatalError(aError); |
|
2860 |
|
2861 return KErrNone; |
|
2862 } |
|
2863 |
|
2864 |
|
2865 // ----------------------------------------------------------------------------- |
|
2866 // CTRTranscoderImp::MtrdvcoEncoderReturnPicture |
|
2867 // Returns picture from encoder |
|
2868 // (other items were commented in a header). |
|
2869 // ----------------------------------------------------------------------------- |
|
2870 // |
|
2871 void CTRTranscoderImp::MtrdvcoEncoderReturnPicture(TVideoPicture* aPicture) |
|
2872 { |
|
2873 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture()"))) |
|
2874 TTRVideoPicture* pictureToClient = NULL; |
|
2875 TInt status = KErrNone; |
|
2876 |
|
2877 |
|
2878 if (!aPicture) |
|
2879 { |
|
2880 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), picture is not valid"))) |
|
2881 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2882 return; |
|
2883 } |
|
2884 else if (!aPicture->iData.iRawData) |
|
2885 { |
|
2886 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), picture raw data is not valid"))) |
|
2887 iObserver.MtroFatalError(KErrAlreadyExists); |
|
2888 return; |
|
2889 } |
|
2890 |
|
2891 switch(iMode) |
|
2892 { |
|
2893 case EFullTranscoding: |
|
2894 { |
|
2895 // if (BuffManCI) { nothing to do, possibly send next picture for encoder, if available } |
|
2896 // Put returned picture to the iTranscoderPictureQueue |
|
2897 if (!iOptimizedDataTransfer) |
|
2898 { |
|
2899 iTranscoderPictureQueue.AddLast(*aPicture); |
|
2900 |
|
2901 // There could be some decoded pictures waiting for processing, check it |
|
2902 this->MtrdvcoNewBuffers(); |
|
2903 } |
|
2904 else |
|
2905 { |
|
2906 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), Nothing to do here, since optimized data transfer in use"))) |
|
2907 return; |
|
2908 } |
|
2909 |
|
2910 if ( !iEncoderPictureQueue.IsEmpty() ) |
|
2911 { |
|
2912 // If there are pictures available in EncoderPicture for processing, initiate data transfer from here |
|
2913 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), some pictures were not processed in iEncoderPictureQueue"))) |
|
2914 TRAP(status, this->RunL()); |
|
2915 |
|
2916 if (status != KErrNone) |
|
2917 { |
|
2918 // Indicate eror status to the client |
|
2919 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), error[%d]"), status)) |
|
2920 iObserver.MtroFatalError(status); |
|
2921 return; |
|
2922 } |
|
2923 } |
|
2924 } |
|
2925 break; |
|
2926 |
|
2927 case EDecoding: |
|
2928 { |
|
2929 // Should not happen |
|
2930 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), Encoder returns picture in Decoding mode"))) |
|
2931 TRASSERT(0); |
|
2932 } |
|
2933 |
|
2934 break; |
|
2935 |
|
2936 case EEncoding: |
|
2937 { |
|
2938 // Put picture to transcoder queue |
|
2939 iTranscoderPictureQueue.AddLast(*aPicture); |
|
2940 |
|
2941 if (iInputPictureSize == iOutputPictureSize) |
|
2942 { |
|
2943 // Find TRPicture container corresponding to picture data & return it to the client; |
|
2944 if ( !iTranscoderTRPictureQueue.IsEmpty() ) |
|
2945 { |
|
2946 pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2947 pictureToClient->iLink.Deque(); |
|
2948 |
|
2949 if (pictureToClient->iRawData == aPicture->iData.iRawData) |
|
2950 { |
|
2951 // Return picture |
|
2952 iPictureSink->MtroPictureFromTranscoder(pictureToClient); |
|
2953 } |
|
2954 else |
|
2955 { |
|
2956 TPtr8 tmp(*pictureToClient->iRawData); |
|
2957 iTranscoderTRPictureQueue.AddLast(*pictureToClient); |
|
2958 |
|
2959 // Encoder returns pictures in different order than they were sent |
|
2960 // Check next picture |
|
2961 pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2962 pictureToClient->iLink.Deque(); |
|
2963 |
|
2964 while (*pictureToClient->iRawData != tmp) |
|
2965 { |
|
2966 if ( pictureToClient->iRawData == aPicture->iData.iRawData ) |
|
2967 { |
|
2968 // Return picture |
|
2969 iPictureSink->MtroPictureFromTranscoder(pictureToClient); |
|
2970 return; |
|
2971 } |
|
2972 else |
|
2973 { |
|
2974 // Put back to the queue this picture and check the next one |
|
2975 iTranscoderTRPictureQueue.AddLast(*pictureToClient); |
|
2976 pictureToClient = iTranscoderTRPictureQueue.First(); |
|
2977 pictureToClient->iLink.Deque(); |
|
2978 } |
|
2979 } |
|
2980 |
|
2981 // The picture has already been removed from the TR picture queue. |
|
2982 // Probably the client thought a frame was skipped and sent a new picture for encoding, |
|
2983 // therefore the client is not expecting us to send anything back => do nothing |
|
2984 |
|
2985 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), Picture already returned, nothing to do"))) |
|
2986 } |
|
2987 } |
|
2988 } |
|
2989 } |
|
2990 break; |
|
2991 |
|
2992 case EResampling: |
|
2993 { |
|
2994 // Should not happen |
|
2995 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), Encoder returns picture in Resampling mode."))) |
|
2996 TRASSERT(0); |
|
2997 } |
|
2998 break; |
|
2999 |
|
3000 default: |
|
3001 { |
|
3002 PRINT((_L("CTRTranscoderImp::MtrdvcoEncoderReturnPicture(), default case"))) |
|
3003 TRASSERT(0); |
|
3004 } |
|
3005 } |
|
3006 } |
|
3007 |
|
3008 |
|
3009 // ----------------------------------------------------------------------------- |
|
3010 // CTRTranscoderImp::SendPictureToTranscoderL |
|
3011 // Receives picture from the client |
|
3012 // (other items were commented in a header). |
|
3013 // ----------------------------------------------------------------------------- |
|
3014 // |
|
3015 void CTRTranscoderImp::SendPictureToTranscoderL(TTRVideoPicture* aPicture) |
|
3016 { |
|
3017 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), In"))) |
|
3018 TVideoPicture* picture = NULL; |
|
3019 TInt status = KErrNone; |
|
3020 TBool encoderEnabled = EFalse; |
|
3021 TBool randomAccess = EFalse; |
|
3022 |
|
3023 if (iState == ETRFatalError) |
|
3024 { |
|
3025 // Nothing to do |
|
3026 return; |
|
3027 } |
|
3028 |
|
3029 if ( (iState != ETRRunning) && (iState != ETRPaused) && |
|
3030 (iState != ETRStopped) && (iMode != EDecoding) ) |
|
3031 { |
|
3032 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), wrong state"))) |
|
3033 User::Leave(KErrNotReady); |
|
3034 } |
|
3035 |
|
3036 if (!aPicture) |
|
3037 { |
|
3038 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Client sends invalid data"))) |
|
3039 User::Leave(KErrArgument); |
|
3040 } |
|
3041 else if (!aPicture->iRawData) |
|
3042 { |
|
3043 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Client sends invalid raw data"))) |
|
3044 User::Leave(KErrArgument); |
|
3045 } |
|
3046 |
|
3047 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), picture timestamp [%f]"), I64REAL(aPicture->iTimestamp.Int64()) )) |
|
3048 |
|
3049 switch(iMode) |
|
3050 { |
|
3051 case EFullTranscoding: |
|
3052 { |
|
3053 if (!iPictureSinkTemp) |
|
3054 { |
|
3055 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Client did not set picture sink! leave"))) |
|
3056 User::Leave(KErrNotReady); |
|
3057 } |
|
3058 |
|
3059 if (iIntermediatePictureSize == iDecodedPictureSize) |
|
3060 { |
|
3061 // Picture path is Decoder->Client->Transcoder |
|
3062 // Decoder does not generate new picture until this one have not been returned |
|
3063 // Act according global settings defined in NewPicture |
|
3064 encoderEnabled = iCurrentEncoderEnabled; |
|
3065 randomAccess = iCurrentRandomAccess; |
|
3066 |
|
3067 // Reset it here |
|
3068 iCurrentRandomAccess = EFalse; |
|
3069 } |
|
3070 else |
|
3071 { |
|
3072 // Picture was processed asynchronously |
|
3073 // Set global async options |
|
3074 encoderEnabled = iCurrentAsyncEncoderEnabled; |
|
3075 randomAccess = iCurrentAsyncRandomAccess; |
|
3076 |
|
3077 // Reset it here |
|
3078 iCurrentAsyncRandomAccess = EFalse; |
|
3079 } |
|
3080 |
|
3081 if (!encoderEnabled) |
|
3082 { |
|
3083 // Put TRPicture container to the queue in any case |
|
3084 iTranscoderTRPictureQueue.AddLast(*aPicture); |
|
3085 |
|
3086 // Nothing to do for this picture, return it to decoder |
|
3087 if (iIntermediatePictureSize == iDecodedPictureSize) |
|
3088 { |
|
3089 if (iDecodedPicture) |
|
3090 { |
|
3091 // Return & reset |
|
3092 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), return picture [%f] to decoder"), I64REAL(iDecodedPicture->iTimestamp.Int64()) )) |
|
3093 TVideoPicture* decodedPicture = iDecodedPicture; |
|
3094 iDecodedPicture = NULL; |
|
3095 iVideoDecoderClient->ReturnPicture(decodedPicture); |
|
3096 } |
|
3097 } |
|
3098 else |
|
3099 { |
|
3100 // If picture was sent to the client asynchronously, nothing to return to decoder |
|
3101 // Picture path is Decoder->Transcoder->client->Transcoder |
|
3102 // Picture was taken from iTranscoderPictureQueue, put it back, since it's not encoded |
|
3103 // Take container for TVideoPicture |
|
3104 if ( !iContainerWaitQueue.IsEmpty() ) |
|
3105 { |
|
3106 // Take container |
|
3107 picture = iContainerWaitQueue.First(); |
|
3108 picture->iLink.Deque(); |
|
3109 picture->iData.iRawData = aPicture->iRawData; |
|
3110 picture->iData.iDataSize = aPicture->iDataSize; |
|
3111 picture->iTimestamp = aPicture->iTimestamp; |
|
3112 |
|
3113 if (!iOptimizedDataTransfer) |
|
3114 { |
|
3115 iTranscoderPictureQueue.AddLast(*picture); |
|
3116 } |
|
3117 else |
|
3118 { |
|
3119 iCIPictureBuffersQueue.AddLast(*picture); |
|
3120 |
|
3121 // Some pictures were not processed yet and wait for processing |
|
3122 this->MtrdvcoNewBuffers(); |
|
3123 } |
|
3124 } |
|
3125 } |
|
3126 |
|
3127 return; |
|
3128 } |
|
3129 |
|
3130 |
|
3131 // Client returns processed picture. (Resample, if needed) and send it to encoder; |
|
3132 if ( /*iPictureSink &&*/ (iIntermediatePictureSize == iDecodedPictureSize) ) |
|
3133 { |
|
3134 // Check input picture size |
|
3135 if ( aPicture->iDataSize != iDecodedPictureSize ) |
|
3136 { |
|
3137 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), The client sets wrong picture size"))) |
|
3138 User::Leave(KErrArgument); |
|
3139 } |
|
3140 |
|
3141 // AA Tuning..(Codecs AOs can be higher priority, so if there are any pictures in iEncoderPictureQueue waiting for processing, send those first) |
|
3142 if ( (iDecodedPictureSize == iOutputPictureSize) && (!iEncoderPictureQueue.IsEmpty()) ) |
|
3143 { |
|
3144 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), some pictures were not processed in iEncoderPictureQueue"))) |
|
3145 this->RunL(); |
|
3146 } |
|
3147 |
|
3148 if (iOptimizedDataTransfer) |
|
3149 { |
|
3150 if ( !iCIPictureBuffersQueue.IsEmpty() ) |
|
3151 { |
|
3152 // Target video picture buffer is already available, use it |
|
3153 picture = iCIPictureBuffersQueue.First(); |
|
3154 picture->iLink.Deque(); |
|
3155 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), picture is already available"))) |
|
3156 } |
|
3157 else |
|
3158 { |
|
3159 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), picture not available, request new;"))) |
|
3160 // Picture was already returned with WritePictureL |
|
3161 TRAP( status, picture = iVideoEncoderClient->GetTargetVideoPictureL() ); |
|
3162 } |
|
3163 |
|
3164 if (status != KErrNone) |
|
3165 { |
|
3166 // return decoded picture to decoder |
|
3167 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), GetTargetVideoPictureL leved with [%d]"), status)) |
|
3168 |
|
3169 if (iDecodedPicture) |
|
3170 { |
|
3171 // Return & reset |
|
3172 TVideoPicture* decodedPicture = iDecodedPicture; |
|
3173 iDecodedPicture = NULL; |
|
3174 iVideoDecoderClient->ReturnPicture(decodedPicture); |
|
3175 } |
|
3176 |
|
3177 // Report the error to the client |
|
3178 iObserver.MtroFatalError(status); |
|
3179 return; |
|
3180 } |
|
3181 else if (picture) |
|
3182 { |
|
3183 // Set options for picture |
|
3184 picture->iData.iDataSize = iOutputPictureSize; |
|
3185 |
|
3186 // we don't support resampling for 422, set default for 420 length |
|
3187 // Add check of output data format (422 or 420) in the future and set dataLength properly |
|
3188 TInt length = iOutputPictureSize.iWidth * iOutputPictureSize.iHeight * 3 / 2; |
|
3189 |
|
3190 if ( length > picture->iData.iRawData->MaxLength() ) |
|
3191 { |
|
3192 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), length exceeds CI buffer maxlength[%d, %d]"), length, picture->iData.iRawData->MaxLength() )) |
|
3193 |
|
3194 if (iDecodedPicture) |
|
3195 { |
|
3196 // Return & reset |
|
3197 TVideoPicture* decodedPicture = iDecodedPicture; |
|
3198 iDecodedPicture = NULL; |
|
3199 iVideoDecoderClient->ReturnPicture(decodedPicture); |
|
3200 } |
|
3201 |
|
3202 iObserver.MtroFatalError(KErrGeneral); |
|
3203 return; |
|
3204 } |
|
3205 |
|
3206 // set length |
|
3207 picture->iData.iRawData->SetLength(length); |
|
3208 } |
|
3209 else |
|
3210 { |
|
3211 if (iRealTime) // (picture is not available, act according realtime mode) |
|
3212 { |
|
3213 // Picture buffer is not available from encoder hwdevice |
|
3214 // return decoded picture back, otherwise suspend decoding.. |
|
3215 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Picture buffer is not available through CI, Drop") )) |
|
3216 |
|
3217 if (iDecodedPicture) |
|
3218 { |
|
3219 iVideoDecoderClient->ReturnPicture(iDecodedPicture); |
|
3220 } |
|
3221 |
|
3222 return; |
|
3223 } |
|
3224 else |
|
3225 { |
|
3226 // Keep picture and does not return it to DecoderClient before processing |
|
3227 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Picture buffer is not available through CI, store") )) |
|
3228 iWaitPictureFromClient = aPicture; |
|
3229 return; |
|
3230 } |
|
3231 } |
|
3232 } |
|
3233 else |
|
3234 { |
|
3235 if ( !iTranscoderPictureQueue.IsEmpty() ) |
|
3236 { |
|
3237 picture = iTranscoderPictureQueue.First(); |
|
3238 } |
|
3239 else |
|
3240 { |
|
3241 // AA (don't report FatalError & wait for newBuffers callback from the encoder) |
|
3242 // return decoded picture to decoder |
|
3243 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), iTranscoderPictureQueue is empty"))) |
|
3244 |
|
3245 if (iRealTime) // (picture is not available, act according realtime mode) |
|
3246 { |
|
3247 // Picture buffer is not available from encoder hwdevice |
|
3248 // return decoded picture back, otherwise suspend decoding.. |
|
3249 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Picture buffer is not available FromEncoder, Drop") )) |
|
3250 |
|
3251 if (iDecodedPicture) |
|
3252 { |
|
3253 iVideoDecoderClient->ReturnPicture(iDecodedPicture); |
|
3254 } |
|
3255 |
|
3256 return; |
|
3257 } |
|
3258 else |
|
3259 { |
|
3260 // Keep picture and does not return it to DecoderClient before processing |
|
3261 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Picture buffer is not available FromEncoder, store") )) |
|
3262 iWaitPictureFromClient = aPicture; |
|
3263 return; |
|
3264 } |
|
3265 } |
|
3266 } |
|
3267 |
|
3268 if (picture) |
|
3269 { |
|
3270 // Returned picture was not resampled. Resample it first. |
|
3271 TRAP(status, iScaler->SetScalerOptionsL( *(aPicture->iRawData), |
|
3272 *(picture->iData.iRawData), |
|
3273 aPicture->iDataSize, |
|
3274 picture->iData.iDataSize ) ); |
|
3275 if (status != KErrNone) |
|
3276 { |
|
3277 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Set scaler options failed[%d]"), status)) |
|
3278 |
|
3279 if (iDecodedPicture) |
|
3280 { |
|
3281 // Return & reset |
|
3282 TVideoPicture* decodedPicture = iDecodedPicture; |
|
3283 iDecodedPicture = NULL; |
|
3284 iVideoDecoderClient->ReturnPicture(decodedPicture); |
|
3285 } |
|
3286 |
|
3287 iTranscoderTRPictureQueue.AddLast(*aPicture); |
|
3288 |
|
3289 // Inform the client with an error |
|
3290 User::Leave(status); |
|
3291 } |
|
3292 |
|
3293 if ( !iOptimizedDataTransfer ) |
|
3294 { |
|
3295 // Remove picture from transcoder queue |
|
3296 picture->iLink.Deque(); |
|
3297 } |
|
3298 |
|
3299 // Scale picture |
|
3300 iScaler->Scale(); |
|
3301 |
|
3302 // Set params |
|
3303 picture->iTimestamp = aPicture->iTimestamp; |
|
3304 } |
|
3305 } |
|
3306 else |
|
3307 { |
|
3308 // Send picture to encoder without resampling |
|
3309 // Take container for TVideoPicture |
|
3310 if ( !iContainerWaitQueue.IsEmpty() ) |
|
3311 { |
|
3312 // Take container |
|
3313 picture = iContainerWaitQueue.First(); |
|
3314 picture->iLink.Deque(); |
|
3315 picture->iData.iRawData = aPicture->iRawData; |
|
3316 picture->iData.iDataSize = aPicture->iDataSize; |
|
3317 picture->iTimestamp = aPicture->iTimestamp; |
|
3318 } |
|
3319 } |
|
3320 |
|
3321 // Put client's container to TRPicture queue |
|
3322 iTranscoderTRPictureQueue.AddLast(*aPicture); |
|
3323 |
|
3324 if (picture) |
|
3325 { |
|
3326 // Encode picture |
|
3327 if (randomAccess) |
|
3328 { |
|
3329 iVideoEncoderClient->SetRandomAccessPoint(); |
|
3330 } |
|
3331 |
|
3332 iVideoEncoderClient->EncodePictureL(picture); |
|
3333 } |
|
3334 |
|
3335 // AA |
|
3336 // return decoded picture here, if there's some available |
|
3337 if (iDecodedPicture) |
|
3338 { |
|
3339 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Return decoded picture now"))) |
|
3340 |
|
3341 // Return & reset |
|
3342 TVideoPicture* decodedPicture = iDecodedPicture; |
|
3343 iDecodedPicture = NULL; |
|
3344 iVideoDecoderClient->ReturnPicture(decodedPicture); |
|
3345 } |
|
3346 } |
|
3347 break; |
|
3348 |
|
3349 case EDecoding: |
|
3350 { |
|
3351 // Client returns decoded picture back. |
|
3352 if (iDecodedPictureSize == iOutputPictureSize) |
|
3353 { |
|
3354 if (iDecodedPicture) |
|
3355 { |
|
3356 iVideoDecoderClient->ReturnPicture(iDecodedPicture); |
|
3357 } |
|
3358 } |
|
3359 else |
|
3360 { |
|
3361 // Put picture back to the queue |
|
3362 iTranscoderPictureQueue.AddLast(*iVideoPictureTemp); |
|
3363 } |
|
3364 } |
|
3365 break; |
|
3366 |
|
3367 case EEncoding: |
|
3368 { |
|
3369 // Check input picture size |
|
3370 if ( aPicture->iDataSize != iInputPictureSize ) |
|
3371 { |
|
3372 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Encoding: The client sets wrong picture size"))) |
|
3373 User::Leave(KErrArgument); |
|
3374 } |
|
3375 |
|
3376 // Client writes new picture to encode. Encode it and return back; |
|
3377 if (!iPictureSink) |
|
3378 { |
|
3379 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), picture sink is not set by the client"))) |
|
3380 User::Leave(KErrNotReady); |
|
3381 } |
|
3382 |
|
3383 if ( !iTranscoderPictureQueue.IsEmpty() ) |
|
3384 { |
|
3385 picture = iTranscoderPictureQueue.First(); |
|
3386 |
|
3387 if (iInputPictureSize != iOutputPictureSize) |
|
3388 { |
|
3389 // Resample this picture first, since picture sizes are different |
|
3390 iScaler->SetScalerOptionsL( *(aPicture->iRawData), *(picture->iData.iRawData), aPicture->iDataSize, |
|
3391 picture->iData.iDataSize ); |
|
3392 |
|
3393 // Scale |
|
3394 iScaler->Scale(); |
|
3395 } |
|
3396 else |
|
3397 { |
|
3398 picture->iData.iDataSize = aPicture->iDataSize; |
|
3399 picture->iData.iRawData = aPicture->iRawData; |
|
3400 } |
|
3401 |
|
3402 picture->iData.iDataFormat = EYuvRawData; |
|
3403 picture->iTimestamp = aPicture->iTimestamp; |
|
3404 |
|
3405 // Remove picture from transcoder queue |
|
3406 picture->iLink.Deque(); |
|
3407 |
|
3408 // Put video picture to encoder queue |
|
3409 iEncoderPictureQueue.AddLast(*picture); |
|
3410 |
|
3411 // Make request to process this picture |
|
3412 this->DoRequest(); |
|
3413 |
|
3414 if (iInputPictureSize != iOutputPictureSize) |
|
3415 { |
|
3416 // Return picture to the client |
|
3417 iPictureSink->MtroPictureFromTranscoder(aPicture); |
|
3418 } |
|
3419 // Add picture to TR queue unless it's already there |
|
3420 else if ( iTranscoderTRPictureQueue.IsEmpty() || |
|
3421 ((iTranscoderTRPictureQueue.First() != aPicture) && |
|
3422 (iTranscoderTRPictureQueue.Last() != aPicture)) ) |
|
3423 { |
|
3424 // Keep aPicture until picture is returned by the encoder |
|
3425 iTranscoderTRPictureQueue.AddLast(*aPicture); |
|
3426 } |
|
3427 } |
|
3428 } |
|
3429 break; |
|
3430 |
|
3431 case EResampling: |
|
3432 { |
|
3433 User::Leave(KErrInUse); |
|
3434 } |
|
3435 break; |
|
3436 |
|
3437 case EOperationNone: |
|
3438 { |
|
3439 User::Leave(KErrNotReady); |
|
3440 } |
|
3441 break; |
|
3442 |
|
3443 default: |
|
3444 { |
|
3445 User::Leave(KErrNotReady); |
|
3446 } |
|
3447 break; |
|
3448 } |
|
3449 |
|
3450 PRINT((_L("CTRTranscoderImp::SendPictureToTranscoderL(), Out"))) |
|
3451 } |
|
3452 |
|
3453 |
|
3454 // ----------------------------------------------------------------------------- |
|
3455 // CTRTranscoderImp::MtrdvcoNewBuffer |
|
3456 // New buffer from the Video encoder is available |
|
3457 // (other items were commented in a header). |
|
3458 // ----------------------------------------------------------------------------- |
|
3459 // |
|
3460 void CTRTranscoderImp::MtrdvcoNewBuffer(CCMRMediaBuffer* aBuffer) |
|
3461 { |
|
3462 if (!aBuffer) |
|
3463 { |
|
3464 // Should never happend |
|
3465 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffer(), EncoderClient sends invalid data, panic"))) |
|
3466 TRASSERT(0); |
|
3467 } |
|
3468 |
|
3469 if (!iMediaSink) |
|
3470 { |
|
3471 // Should never happend at this point |
|
3472 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffer(), invalid media sink, panic"))) |
|
3473 TRASSERT(0); |
|
3474 } |
|
3475 |
|
3476 TRAPD(status, iMediaSink->WriteBufferL(aBuffer)); |
|
3477 if (status != KErrNone) |
|
3478 { |
|
3479 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffer(), WriteBufferL status[%d]"), status)) |
|
3480 iObserver.MtroFatalError(status); |
|
3481 } |
|
3482 } |
|
3483 |
|
3484 |
|
3485 // ----------------------------------------------------------------------------- |
|
3486 // CTRTranscoderImp::ResampleL |
|
3487 // Resamples video picture to new resolution |
|
3488 // (other items were commented in a header). |
|
3489 // ----------------------------------------------------------------------------- |
|
3490 // |
|
3491 void CTRTranscoderImp::ResampleL(TPtr8& aSrc, TPtr8& aTrg) |
|
3492 { |
|
3493 PRINT((_L("CTRTranscoderImp::ResampleL(), In"))) |
|
3494 |
|
3495 if ( (iState != ETRInitialized) && (iState != ETRRunning) ) |
|
3496 { |
|
3497 PRINT((_L("CTRTranscoderImp::ResampleL(), called in wrong state"))) |
|
3498 User::Leave(KErrNotReady); |
|
3499 } |
|
3500 |
|
3501 if (iMode != EResampling) |
|
3502 { |
|
3503 PRINT((_L("CTRTranscoderImp::ResampleL(), supported only in Resampling mode"))) |
|
3504 User::Leave(KErrInUse); |
|
3505 } |
|
3506 |
|
3507 if (iScaler) |
|
3508 { |
|
3509 // SetScaler options |
|
3510 iScaler->SetScalerOptionsL(aSrc, aTrg, iInputPictureSize, iOutputPictureSize); |
|
3511 iScaler->Scale(); |
|
3512 } |
|
3513 else |
|
3514 { |
|
3515 PRINT((_L("CTRTranscoderImp::ResampleL(), scaler is not valid"))) |
|
3516 TRASSERT(0); |
|
3517 } |
|
3518 |
|
3519 PRINT((_L("CTRTranscoderImp::ResampleL(), Out"))) |
|
3520 } |
|
3521 |
|
3522 |
|
3523 // ----------------------------------------------------------------------------- |
|
3524 // CTRTranscoderImp::StopL |
|
3525 // Stops data processing synchronously |
|
3526 // (other items were commented in a header). |
|
3527 // ----------------------------------------------------------------------------- |
|
3528 // |
|
3529 void CTRTranscoderImp::StopL() |
|
3530 { |
|
3531 PRINT((_L("CTRTranscoderImp::StopL(), In"))) |
|
3532 |
|
3533 |
|
3534 if ( (iState != ETRRunning) && (iState != ETRPaused) && (iState != ETRFatalError) ) |
|
3535 { |
|
3536 PRINT((_L("CTRTranscoderImp::StopL(), wrong state, leave"))) |
|
3537 User::Leave(KErrNotReady); |
|
3538 } |
|
3539 |
|
3540 switch(iMode) |
|
3541 { |
|
3542 case EFullTranscoding: |
|
3543 { |
|
3544 // Discard all frames waiting to be sent to encoder |
|
3545 iEncoderPictureQueue.Reset(); |
|
3546 |
|
3547 iVideoDecoderClient->StopL(); |
|
3548 iVideoEncoderClient->StopL(); |
|
3549 iState = ETRStopped; |
|
3550 } |
|
3551 break; |
|
3552 |
|
3553 case EDecoding: |
|
3554 { |
|
3555 iVideoDecoderClient->StopL(); |
|
3556 iState = ETRStopped; |
|
3557 } |
|
3558 break; |
|
3559 |
|
3560 case EEncoding: |
|
3561 { |
|
3562 iVideoEncoderClient->StopL(); |
|
3563 iState = ETRStopped; |
|
3564 } |
|
3565 break; |
|
3566 |
|
3567 case EResampling: |
|
3568 { |
|
3569 iState = ETRStopped; |
|
3570 } |
|
3571 break; |
|
3572 |
|
3573 case EOperationNone: |
|
3574 { |
|
3575 User::Leave(KErrNotReady); |
|
3576 } |
|
3577 break; |
|
3578 |
|
3579 default: |
|
3580 { |
|
3581 } |
|
3582 break; |
|
3583 } |
|
3584 |
|
3585 PRINT((_L("CTRTranscoderImp::StopL(), Out"))) |
|
3586 } |
|
3587 |
|
3588 |
|
3589 // ----------------------------------------------------------------------------- |
|
3590 // CTRTranscoderImp::AsyncStopL |
|
3591 // Stops data processing asynchronously |
|
3592 // (other items were commented in a header). |
|
3593 // ----------------------------------------------------------------------------- |
|
3594 // |
|
3595 void CTRTranscoderImp::AsyncStopL() |
|
3596 { |
|
3597 PRINT((_L("CTRTranscoderImp::AsyncStopL(), Async In"))) |
|
3598 |
|
3599 |
|
3600 if (iState != ETRRunning) |
|
3601 { |
|
3602 PRINT((_L("CTRTranscoderImp::AsyncStopL() Async, wrong state"))) |
|
3603 User::Leave(KErrNotReady); |
|
3604 } |
|
3605 |
|
3606 switch(iMode) |
|
3607 { |
|
3608 case EFullTranscoding: |
|
3609 { |
|
3610 iAsyncStop = ETrue; |
|
3611 iVideoDecoderClient->AsyncStopL(); |
|
3612 } |
|
3613 break; |
|
3614 |
|
3615 case EDecoding: |
|
3616 { |
|
3617 iEncoderStreamEnd = ETrue; |
|
3618 iVideoDecoderClient->AsyncStopL(); |
|
3619 iState = ETRStopped; |
|
3620 } |
|
3621 break; |
|
3622 |
|
3623 case EEncoding: |
|
3624 { |
|
3625 iDecoderStreamEnd = ETrue; |
|
3626 iVideoEncoderClient->AsyncStopL(); |
|
3627 iState = ETRStopped; |
|
3628 } |
|
3629 break; |
|
3630 |
|
3631 case EResampling: |
|
3632 { |
|
3633 // Just complete asyncStop right here |
|
3634 iObserver.MtroAsyncStopComplete(); |
|
3635 iState = ETRStopped; |
|
3636 } |
|
3637 break; |
|
3638 |
|
3639 case EOperationNone: |
|
3640 { |
|
3641 User::Leave(KErrNotReady); |
|
3642 } |
|
3643 break; |
|
3644 |
|
3645 default: |
|
3646 { |
|
3647 User::Leave(KErrNotReady); |
|
3648 } |
|
3649 } |
|
3650 |
|
3651 |
|
3652 PRINT((_L("CTRTranscoderImp::AsyncStopL(), Async Out"))) |
|
3653 } |
|
3654 |
|
3655 |
|
3656 // ----------------------------------------------------------------------------- |
|
3657 // CTRTranscoderImp::MtrdvcoEncStreamEnd |
|
3658 // Informs that last data was processed by encoder |
|
3659 // (other items were commented in a header). |
|
3660 // ----------------------------------------------------------------------------- |
|
3661 // |
|
3662 void CTRTranscoderImp::MtrdvcoEncStreamEnd() |
|
3663 { |
|
3664 PRINT((_L("CTRTranscoderImp::MtrdvcoEncStreamEnd()"))) |
|
3665 iEncoderStreamEnd = ETrue; |
|
3666 |
|
3667 if (iDecoderStreamEnd) |
|
3668 { |
|
3669 PRINT((_L("CTRTranscoderImp::MtrdvcoEncStreamEnd(), MtroAsyncStopComplete"))) |
|
3670 iObserver.MtroAsyncStopComplete(); |
|
3671 } |
|
3672 } |
|
3673 |
|
3674 |
|
3675 // ----------------------------------------------------------------------------- |
|
3676 // CTRTranscoderImp::DecoderStreamEnd |
|
3677 // Informs that last data was processed by decoder |
|
3678 // (other items were commented in a header). |
|
3679 // ----------------------------------------------------------------------------- |
|
3680 // |
|
3681 void CTRTranscoderImp::MtrdvcoDecStreamEnd() |
|
3682 { |
|
3683 PRINT((_L("CTRTranscoderImp::MtrdvcoDecStreamEnd()"))) |
|
3684 TInt status = KErrNone; |
|
3685 iDecoderStreamEnd = ETrue; |
|
3686 |
|
3687 if (iEncoderStreamEnd) |
|
3688 { |
|
3689 PRINT((_L("CTRTranscoderImp::MtrdvcoDecStreamEnd(), MtroAsyncStopComplete"))) |
|
3690 iObserver.MtroAsyncStopComplete(); |
|
3691 return; |
|
3692 } |
|
3693 |
|
3694 if (iAsyncStop) |
|
3695 { |
|
3696 // Call now asyncStop for encoder |
|
3697 TRAP(status, iVideoEncoderClient->AsyncStopL()); |
|
3698 |
|
3699 if (status != KErrNone) |
|
3700 { |
|
3701 // Report error to the client during stop |
|
3702 PRINT((_L("CTRTranscoderImp::MtrdvcoDecStreamEnd(), EncAsyncStop status[%d]"), status)) |
|
3703 iObserver.MtroFatalError(status); |
|
3704 } |
|
3705 |
|
3706 iState = ETRStopped; |
|
3707 } |
|
3708 } |
|
3709 |
|
3710 |
|
3711 // ----------------------------------------------------------------------------- |
|
3712 // CTRTranscoderImp::MtrdvcoRendererReturnPicture |
|
3713 // Receives picture from renderer |
|
3714 // (other items were commented in a header). |
|
3715 // ----------------------------------------------------------------------------- |
|
3716 // |
|
3717 void CTRTranscoderImp::MtrdvcoRendererReturnPicture(TVideoPicture* /*aPicture*/) |
|
3718 { |
|
3719 } |
|
3720 |
|
3721 // ----------------------------------------------------------------------------- |
|
3722 // CTRTranscoderImp::MtrdvcoFatalError |
|
3723 // Reports the fatal error to the client |
|
3724 // (other items were commented in a header). |
|
3725 // ----------------------------------------------------------------------------- |
|
3726 // |
|
3727 void CTRTranscoderImp::MtrdvcoFatalError(TInt aError) |
|
3728 { |
|
3729 PRINT((_L("CTRTranscoderImp::MtrdvcoFatalError(), error[%d]"), aError)) |
|
3730 iFatalError = aError; |
|
3731 iState = ETRFatalError; |
|
3732 iObserver.MtroFatalError(aError); |
|
3733 } |
|
3734 |
|
3735 |
|
3736 // AA (PV requires to use that, otherwise depends on the decoder hwdevice & decoder itself) |
|
3737 // ----------------------------------------------------------------------------- |
|
3738 // CTRTranscoderImp::SetDecoderInitDataL |
|
3739 // Sends init data for decoder |
|
3740 // (other items were commented in a header). |
|
3741 // ----------------------------------------------------------------------------- |
|
3742 // |
|
3743 void CTRTranscoderImp::SetDecoderInitDataL(TPtrC8& /*aInitData*/) |
|
3744 { |
|
3745 // Remove this API in the future; |
|
3746 } |
|
3747 |
|
3748 |
|
3749 // ----------------------------------------------------------------------------- |
|
3750 // CTRTranscoderImp::GetCodingStandardSpecificInitOutputLC |
|
3751 // Retrieve coding options from encoder client |
|
3752 // (other items were commented in a header). |
|
3753 // ----------------------------------------------------------------------------- |
|
3754 // |
|
3755 HBufC8* CTRTranscoderImp::GetCodingStandardSpecificInitOutputLC() |
|
3756 { |
|
3757 if ( iState != ETRInitialized ) |
|
3758 { |
|
3759 PRINT((_L("CTRTranscoderImp::GetCodingStandardSpecificInitOutputLC(), wrong state, leave"))) |
|
3760 User::Leave(KErrNotReady); |
|
3761 } |
|
3762 |
|
3763 if (iVideoEncoderClient) |
|
3764 { |
|
3765 return iVideoEncoderClient->GetCodingStandardSpecificInitOutputLC(); |
|
3766 } |
|
3767 else |
|
3768 { |
|
3769 return NULL; |
|
3770 } |
|
3771 } |
|
3772 |
|
3773 |
|
3774 // ----------------------------------------------------------------------------- |
|
3775 // CTRTranscoderImp::EnablePictureSink |
|
3776 // Enable / Disable picture sink |
|
3777 // (other items were commented in a header). |
|
3778 // ----------------------------------------------------------------------------- |
|
3779 // |
|
3780 void CTRTranscoderImp::EnablePictureSink(TBool aEnable) |
|
3781 { |
|
3782 if (iMode != EFullTranscoding) |
|
3783 { |
|
3784 // nothing to do in other mode |
|
3785 PRINT((_L("CTRTranscoderImp::EnablePictureSink(), nothing to do, wrong mode"))) |
|
3786 return; |
|
3787 } |
|
3788 |
|
3789 if (iPictureSinkClientSetting != aEnable) |
|
3790 { |
|
3791 // Setting was changed |
|
3792 iPictureSinkSettingChanged = ETrue; |
|
3793 PRINT((_L("CTRTranscoderImp::EnablePictureSink(), EnablePictureSink setting changed[%d]"), aEnable)) |
|
3794 } |
|
3795 |
|
3796 iPictureSinkClientSetting = aEnable; |
|
3797 } |
|
3798 |
|
3799 |
|
3800 // ----------------------------------------------------------------------------- |
|
3801 // CTRTranscoderImp::EnableEncoder |
|
3802 // Enable / Disable encoder |
|
3803 // (other items were commented in a header). |
|
3804 // ----------------------------------------------------------------------------- |
|
3805 // |
|
3806 void CTRTranscoderImp::EnableEncoder(TBool aEnable) |
|
3807 { |
|
3808 if (iMode != EFullTranscoding) |
|
3809 { |
|
3810 // nothing to do in other mode |
|
3811 PRINT((_L("CTRTranscoderImp::EnableEncoder(), nothing to do, wrong mode"))) |
|
3812 return; |
|
3813 } |
|
3814 |
|
3815 if (iEncoderEnableClientSetting != aEnable) |
|
3816 { |
|
3817 // Setting was changed |
|
3818 iEncoderEnabledSettingChanged = ETrue; |
|
3819 PRINT((_L("CTRTranscoderImp::EnableEncoder(), EnableEncoder setting changed[%d]"), aEnable)) |
|
3820 } |
|
3821 |
|
3822 iEncoderEnableClientSetting = aEnable; |
|
3823 } |
|
3824 |
|
3825 |
|
3826 // ----------------------------------------------------------------------------- |
|
3827 // CTRTranscoderImp::SetRandomAccessPoint |
|
3828 // Sets random access |
|
3829 // (other items were commented in a header). |
|
3830 // ----------------------------------------------------------------------------- |
|
3831 // |
|
3832 void CTRTranscoderImp::SetRandomAccessPoint() |
|
3833 { |
|
3834 if (iMode != EFullTranscoding) |
|
3835 { |
|
3836 // nothing to do in other mode |
|
3837 PRINT((_L("CTRTranscoderImp::EnableEncoder(), nothing to do, wrong mode"))) |
|
3838 return; |
|
3839 } |
|
3840 |
|
3841 iSetRandomAccessPoint = ETrue; |
|
3842 } |
|
3843 |
|
3844 |
|
3845 // ----------------------------------------------------------------------------- |
|
3846 // CTRTranscoderImp::MtrdvcoNewBuffers |
|
3847 // New buffers from encoder |
|
3848 // (other items were commented in a header). |
|
3849 // ----------------------------------------------------------------------------- |
|
3850 // |
|
3851 void CTRTranscoderImp::MtrdvcoNewBuffers() |
|
3852 { |
|
3853 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffers()"))) |
|
3854 TInt status = KErrNone; |
|
3855 TTRVideoPicture* pictureFromClient = NULL; |
|
3856 TVideoPicture* newDecodedPicture = NULL; |
|
3857 |
|
3858 |
|
3859 if (iRealTime) |
|
3860 { |
|
3861 // Should never be called in normal data flow or realTime mode, ignore this call! |
|
3862 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffers(), return immediately"))) |
|
3863 return; |
|
3864 } |
|
3865 |
|
3866 // Use this call to initiate data transfer if there are available decoded picture waiting for processing |
|
3867 if (iWaitPictureFromClient) |
|
3868 { |
|
3869 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffers(), iWaitPictureFromClient, [0x%x], call SendPictureToTranscoderL()"), iWaitPictureFromClient)) |
|
3870 |
|
3871 // Simulate call from the client since picture was not processed |
|
3872 pictureFromClient = iWaitPictureFromClient; |
|
3873 |
|
3874 // Reset picture, it can be reinitialized in the following call |
|
3875 iWaitPictureFromClient = NULL; |
|
3876 |
|
3877 TRAP( status, this->SendPictureToTranscoderL(pictureFromClient) ); |
|
3878 |
|
3879 if (status != KErrNone) |
|
3880 { |
|
3881 // Report error to the client |
|
3882 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffers(), status[%d]"), status)) |
|
3883 iObserver.MtroFatalError(status); |
|
3884 } |
|
3885 |
|
3886 return; |
|
3887 } |
|
3888 |
|
3889 if (iWaitNewDecodedPicture) |
|
3890 { |
|
3891 PRINT((_L("CTRTranscoderImp::MtrdvcoNewBuffers(), iWaitNewDecodedPicture[0x%x]"), iWaitNewDecodedPicture)) |
|
3892 newDecodedPicture = iWaitNewDecodedPicture; |
|
3893 |
|
3894 // Reset newdecoded picture |
|
3895 iWaitNewDecodedPicture = NULL; |
|
3896 |
|
3897 // Simulate new decoded picture call |
|
3898 this->MtrdvcoNewPicture(newDecodedPicture); |
|
3899 } |
|
3900 } |
|
3901 |
|
3902 // ----------------------------------------------------------------------------- |
|
3903 // CTRTranscoderImp::EstimateTranscodeTimeFactorL |
|
3904 // Returns a time estimate of how long it takes to process one second of the input video |
|
3905 // (other items were commented in a header). |
|
3906 // ----------------------------------------------------------------------------- |
|
3907 // |
|
3908 TReal CTRTranscoderImp::EstimateTranscodeTimeFactorL(const TTRVideoFormat& aInput, const TTRVideoFormat& aOutput) |
|
3909 { |
|
3910 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), In"))) |
|
3911 |
|
3912 if ( iState == ETRNone ) |
|
3913 { |
|
3914 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), Transcoder is in wrong state"))) |
|
3915 User::Leave(KErrNotReady); |
|
3916 } |
|
3917 |
|
3918 // Get frame rate for output / input video |
|
3919 TReal time = 0.0; |
|
3920 TReal encodeFrameRate = GetFrameRateL(); |
|
3921 TReal decodeFrameRate = 0.0; |
|
3922 iObserver.MtroSetInputFrameRate(decodeFrameRate); |
|
3923 |
|
3924 // Use default frames rates if not set |
|
3925 if (encodeFrameRate == 0.0) encodeFrameRate = KTRDefaultSrcRate; |
|
3926 if (decodeFrameRate == 0.0) decodeFrameRate = KTRDefaultSrcRate; |
|
3927 |
|
3928 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), encode frame rate: %.2f"), encodeFrameRate)) |
|
3929 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), decode frame rate: %.2f"), decodeFrameRate)) |
|
3930 |
|
3931 switch(iMode) |
|
3932 { |
|
3933 case EFullTranscoding: |
|
3934 { |
|
3935 // Estimate the time for decoding, encoding and possible resampling |
|
3936 time += iVideoEncoderClient->EstimateEncodeFrameTimeL(aOutput, iOutputCodec) * encodeFrameRate; |
|
3937 time += iVideoDecoderClient->EstimateDecodeFrameTimeL(aInput, iInputCodec) * decodeFrameRate; |
|
3938 time += iScaler->EstimateResampleFrameTime(aInput, aOutput) * decodeFrameRate; |
|
3939 |
|
3940 break; |
|
3941 } |
|
3942 |
|
3943 case EDecoding: |
|
3944 { |
|
3945 // Estimate the time for decoding and possible resampling |
|
3946 time += iVideoDecoderClient->EstimateDecodeFrameTimeL(aInput, iInputCodec) * decodeFrameRate; |
|
3947 time += iScaler->EstimateResampleFrameTime(aInput, aOutput) * decodeFrameRate; |
|
3948 |
|
3949 break; |
|
3950 } |
|
3951 |
|
3952 case EEncoding: |
|
3953 { |
|
3954 // Estimate the time for encoding and possible resampling |
|
3955 time += iVideoEncoderClient->EstimateEncodeFrameTimeL(aOutput, iOutputCodec) * encodeFrameRate; |
|
3956 time += iScaler->EstimateResampleFrameTime(aInput, aOutput) * encodeFrameRate; |
|
3957 |
|
3958 break; |
|
3959 } |
|
3960 |
|
3961 case EResampling: |
|
3962 { |
|
3963 // Estimate the time for resampling |
|
3964 time += iScaler->EstimateResampleFrameTime(aInput, aOutput) * decodeFrameRate; |
|
3965 |
|
3966 break; |
|
3967 } |
|
3968 |
|
3969 default: |
|
3970 { |
|
3971 // Transcoder is not ready |
|
3972 User::Leave(KErrNotReady); |
|
3973 break; |
|
3974 } |
|
3975 } |
|
3976 |
|
3977 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), time factor: %.2f"), time)) |
|
3978 |
|
3979 PRINT((_L("CTRTranscoderImp::EstimateTranscodeTimeFactorL(), Out"))) |
|
3980 |
|
3981 return time; |
|
3982 } |
|
3983 |
|
3984 // ----------------------------------------------------------------------------- |
|
3985 // CTRTranscoderImp::GetMaxFramesInProcessing |
|
3986 // Get max number of frames in processing |
|
3987 // (other items were commented in a header). |
|
3988 // ----------------------------------------------------------------------------- |
|
3989 // |
|
3990 TInt CTRTranscoderImp::GetMaxFramesInProcessing() |
|
3991 { |
|
3992 return iMaxFramesInProcessing; |
|
3993 } |
|
3994 |
|
3995 // ----------------------------------------------------------------------------- |
|
3996 // CTRTranscoderImp::EnablePausing |
|
3997 // Enable / Disable pausing of transcoding if resources are lost |
|
3998 // (other items were commented in a header). |
|
3999 // ----------------------------------------------------------------------------- |
|
4000 // |
|
4001 void CTRTranscoderImp::EnablePausing(TBool aEnable) |
|
4002 { |
|
4003 if (iVideoDecoderClient) |
|
4004 { |
|
4005 iVideoDecoderClient->EnableResourceObserver(aEnable); |
|
4006 } |
|
4007 |
|
4008 if (iVideoEncoderClient) |
|
4009 { |
|
4010 iVideoEncoderClient->EnableResourceObserver(aEnable); |
|
4011 } |
|
4012 |
|
4013 } |
|
4014 |
|
4015 // ----------------------------------------------------------------------------- |
|
4016 // CTRTranscoderImp::::MmvroResourcesLost |
|
4017 // Indicates that a media device has lost its resources |
|
4018 // (other items were commented in a header). |
|
4019 // ----------------------------------------------------------------------------- |
|
4020 // |
|
4021 void CTRTranscoderImp::MtrdvcoResourcesLost(TBool aFromDecoder) |
|
4022 { |
|
4023 PRINT((_L("CTRTranscoderImp::MtrdvcoResourcesLost(), In"))) |
|
4024 |
|
4025 if ( (iState == ETRRunning) || (iState == ETRInitialized) || (iState == ETRStopped) ) |
|
4026 { |
|
4027 iVideoDecoderClient->Pause(); |
|
4028 iState = ETRPaused; |
|
4029 |
|
4030 iDecoderResourceLost = aFromDecoder; |
|
4031 |
|
4032 if (!aFromDecoder) |
|
4033 iVideoEncoderClient->Pause(); |
|
4034 |
|
4035 // Return decoded picture |
|
4036 if (iWaitNewDecodedPicture) |
|
4037 { |
|
4038 iVideoDecoderClient->ReturnPicture(iWaitNewDecodedPicture); |
|
4039 iWaitNewDecodedPicture = NULL; |
|
4040 } |
|
4041 |
|
4042 iObserver.MtroSuspend(); |
|
4043 } |
|
4044 |
|
4045 PRINT((_L("CTRTranscoderImp::MtrdvcoResourcesLost(), Out"))) |
|
4046 } |
|
4047 |
|
4048 |
|
4049 // ----------------------------------------------------------------------------- |
|
4050 // CTRTranscoderImp::::MmvroResourcesRestored |
|
4051 // Indicates that a media device has regained its resources |
|
4052 // (other items were commented in a header). |
|
4053 // ----------------------------------------------------------------------------- |
|
4054 // |
|
4055 void CTRTranscoderImp::MtrdvcoResourcesRestored() |
|
4056 { |
|
4057 PRINT((_L("CTRTranscoderImp::MtrdvcoResourcesRestored(), In"))) |
|
4058 |
|
4059 if ( (iState == ETRPaused) || (iState == ETRInitialized) || (iState == ETRStopped) ) |
|
4060 { |
|
4061 // Clear all events |
|
4062 if( iNewEvent ) |
|
4063 { |
|
4064 iNewEvent->Reset(); |
|
4065 iTranscoderEventSrc.AddLast(*iNewEvent); |
|
4066 iNewEvent = NULL; |
|
4067 } |
|
4068 |
|
4069 while( !iTranscoderEventQueue.IsEmpty() ) |
|
4070 { |
|
4071 // Get new event |
|
4072 iNewEvent = iTranscoderEventQueue.First(); |
|
4073 iNewEvent->iLink.Deque(); |
|
4074 |
|
4075 iNewEvent->Reset(); |
|
4076 iTranscoderEventSrc.AddLast(*iNewEvent); |
|
4077 iNewEvent = NULL; |
|
4078 } |
|
4079 |
|
4080 if( iAsyncEvent ) |
|
4081 { |
|
4082 iAsyncEvent->Reset(); |
|
4083 iTranscoderEventSrc.AddLast(*iAsyncEvent); |
|
4084 iAsyncEvent = NULL; |
|
4085 } |
|
4086 |
|
4087 while( !iTranscoderAsyncEventQueue.IsEmpty() ) |
|
4088 { |
|
4089 // Get new event |
|
4090 iAsyncEvent = iTranscoderAsyncEventQueue.First(); |
|
4091 iAsyncEvent->iLink.Deque(); |
|
4092 |
|
4093 iAsyncEvent->Reset(); |
|
4094 iTranscoderEventSrc.AddLast(*iAsyncEvent); |
|
4095 iAsyncEvent = NULL; |
|
4096 } |
|
4097 |
|
4098 // Force update of PS / EE settings |
|
4099 iPictureSinkSettingChanged = ETrue; |
|
4100 iEncoderEnabledSettingChanged = ETrue; |
|
4101 |
|
4102 TRAPD( error, iVideoDecoderClient->ResumeL() ); |
|
4103 if( error != KErrNone ) { } |
|
4104 |
|
4105 if (!iDecoderResourceLost) |
|
4106 { |
|
4107 iVideoEncoderClient->Resume(); |
|
4108 } |
|
4109 |
|
4110 iState = ETRRunning; |
|
4111 |
|
4112 iObserver.MtroResume(); |
|
4113 } |
|
4114 |
|
4115 PRINT((_L("CTRTranscoderImp::MtrdvcoResourcesRestored(), Out"))) |
|
4116 } |
|
4117 |
|
4118 // End of file |
|