|
1 /* |
|
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CSConVideoParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <coedef.h> |
|
20 #include <bautils.h> |
|
21 #include <imageconversion.h> |
|
22 #include "sconvideoparser.h" |
|
23 #include "debug.h" |
|
24 |
|
25 _LIT( KMimeType, "MimeType" ); |
|
26 _LIT8( KImageEncoderMimeType, "image/jpeg" ); |
|
27 _LIT( KMimeTypeAudio, "audio/*" ); |
|
28 _LIT( KMimeTypeVideo, "video/*" ); |
|
29 |
|
30 const TInt KRequestTimeOut( 20000000 ); // 20 sec. |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CSConVideoParser::CSConVideoParser() |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CSConVideoParser::CSConVideoParser() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CSConVideoParser::~CSConVideoParser() |
|
42 // Destructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSConVideoParser::~CSConVideoParser() |
|
46 { |
|
47 TRACE_FUNC_ENTRY; |
|
48 delete iTimeOut; |
|
49 if ( iVideoClip ) |
|
50 { |
|
51 iVideoClip->CancelThumb(); |
|
52 } |
|
53 delete iVideoClip; |
|
54 |
|
55 if ( iVideoUtil ) |
|
56 { |
|
57 iVideoUtil->Close(); |
|
58 } |
|
59 delete iVideoUtil; |
|
60 |
|
61 if ( iWindow ) |
|
62 { |
|
63 iWindow->Close(); |
|
64 } |
|
65 delete iWindow; |
|
66 iRootWindow.Close(); |
|
67 delete iScreen; |
|
68 iWsSession.Close(); |
|
69 |
|
70 delete iThumbnail; |
|
71 delete iVideoMimeType; |
|
72 delete iAudioMimeType; |
|
73 TRACE_FUNC_EXIT; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSConVideoParser::NewLC() |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CSConVideoParser* CSConVideoParser::NewLC() |
|
81 { |
|
82 CSConVideoParser* self = new (ELeave)CSConVideoParser(); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CSConVideoParser::ConstructL() |
|
90 // Constructor |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CSConVideoParser::ConstructL() |
|
94 { |
|
95 TRACE_FUNC_ENTRY; |
|
96 |
|
97 User::LeaveIfError( iWsSession.Connect() ); |
|
98 |
|
99 iScreen = new(ELeave) CWsScreenDevice( iWsSession ); |
|
100 User::LeaveIfError( iScreen->Construct() ); |
|
101 |
|
102 iRootWindow = RWindowGroup(iWsSession); |
|
103 User::LeaveIfError( iRootWindow.Construct(reinterpret_cast<TUint32>(&iWsSession), EFalse) ); |
|
104 |
|
105 iWindow = new(ELeave) RWindow( iWsSession ); |
|
106 User::LeaveIfError( iWindow->Construct(iRootWindow, reinterpret_cast<TUint32>(&iRootWindow) + 1) ); |
|
107 |
|
108 TRect temp(0,0,320,240); // dummy parameter |
|
109 iVideoUtil = CVideoPlayerUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceNone, iWsSession, *iScreen, *iWindow, temp, temp); |
|
110 |
|
111 iTimeOut = CSconTimeOut::NewL( *this ); |
|
112 |
|
113 TRACE_FUNC_EXIT; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CSConVideoParser::OpenFileL( const RFs& aFs, const TDesC& aFileName ) |
|
118 // Opens video file |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CSConVideoParser::OpenFileL( const RFs& aFs, const TDesC& aFileName ) |
|
122 { |
|
123 TRACE_FUNC_ENTRY; |
|
124 |
|
125 iVideoUtilReady = EFalse; |
|
126 iVideoClipReady = EFalse; |
|
127 iVideoUtilErr = KErrNone; |
|
128 iVideoClipErr = KErrNone; |
|
129 |
|
130 delete iThumbnail; |
|
131 iThumbnail = NULL; |
|
132 delete iVideoMimeType; |
|
133 iVideoMimeType=NULL; |
|
134 delete iAudioMimeType; |
|
135 iAudioMimeType=NULL; |
|
136 |
|
137 if ( iVideoClip ) |
|
138 { |
|
139 iVideoClip->CancelThumb(); |
|
140 delete iVideoClip; |
|
141 iVideoClip = NULL; |
|
142 } |
|
143 if ( iVideoUtil ) |
|
144 { |
|
145 iVideoUtil->Close(); |
|
146 } |
|
147 |
|
148 TBool fileExist = BaflUtils::FileExists( aFs, aFileName ); |
|
149 if ( !fileExist ) |
|
150 { |
|
151 User::Leave( KErrNotFound ); |
|
152 } |
|
153 iAsyncStopCalled = EFalse; |
|
154 iVideoClip = CTNEVideoClipInfo::NewL( aFileName, *this ); |
|
155 |
|
156 iVideoUtil->OpenFileL( aFileName ); |
|
157 |
|
158 LOGGER_WRITE("Start timeout"); |
|
159 iTimeOut->Start( KRequestTimeOut ); |
|
160 |
|
161 LOGGER_WRITE("iWait.Start()"); |
|
162 iWait.Start(); |
|
163 |
|
164 TRACE_FUNC_EXIT; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CSConVideoParser::Thumbnail() |
|
169 // returns video thumbnail in jpg format |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 const TDesC8& CSConVideoParser::Thumbnail() const |
|
173 { |
|
174 TRACE_FUNC; |
|
175 if ( !iThumbnail ) |
|
176 { |
|
177 return KNullDesC8; |
|
178 } |
|
179 return *iThumbnail; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CSConVideoParser::VideoFrameRateL() |
|
184 // returns video frame rate |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 TReal32 CSConVideoParser::VideoFrameRateL() const |
|
188 { |
|
189 TRACE_FUNC; |
|
190 if ( !iVideoUtil ) |
|
191 { |
|
192 User::Leave( KErrNotReady ); |
|
193 } |
|
194 return iVideoUtil->VideoFrameRateL(); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CSConVideoParser::VideoFrameSizeL() |
|
199 // returns video frame size |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CSConVideoParser::VideoFrameSizeL(TSize& aSize) const |
|
203 { |
|
204 TRACE_FUNC; |
|
205 if ( !iVideoUtil ) |
|
206 { |
|
207 User::Leave( KErrNotReady ); |
|
208 } |
|
209 return iVideoUtil->VideoFrameSizeL( aSize ); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSConVideoParser::VideoFormatMimeTypeL() |
|
214 // returns video format |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 const TDesC8& CSConVideoParser::VideoFormatMimeTypeL() const |
|
218 { |
|
219 TRACE_FUNC; |
|
220 if ( !iVideoUtil ) |
|
221 { |
|
222 User::Leave( KErrNotReady ); |
|
223 } |
|
224 return iVideoUtil->VideoFormatMimeType(); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CSConVideoParser::VideoBitRateL() |
|
229 // returns videostream bitrate |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TInt CSConVideoParser::VideoBitRateL() const |
|
233 { |
|
234 TRACE_FUNC; |
|
235 if ( !iVideoUtil ) |
|
236 { |
|
237 User::Leave( KErrNotReady ); |
|
238 } |
|
239 return iVideoUtil->VideoBitRateL(); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CSConVideoParser::AudioBitRateL() |
|
244 // returns audiostream bitrate |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 TInt CSConVideoParser::AudioBitRateL() const |
|
248 { |
|
249 TRACE_FUNC; |
|
250 if ( !iVideoUtil ) |
|
251 { |
|
252 User::Leave( KErrNotReady ); |
|
253 } |
|
254 return iVideoUtil->AudioBitRateL(); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CSConVideoParser::DurationL() |
|
259 // returns video duration in milliseconds |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 TInt CSConVideoParser::DurationL() const |
|
263 { |
|
264 TRACE_FUNC; |
|
265 if ( !iVideoUtil ) |
|
266 { |
|
267 User::Leave( KErrNotReady ); |
|
268 } |
|
269 return iVideoUtil->DurationL().Int64()/1000; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSConVideoParser::VideoMimeTypeL() |
|
274 // returns video mime type |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 const TDesC& CSConVideoParser::VideoMimeTypeL() |
|
278 { |
|
279 TRACE_FUNC; |
|
280 if ( !iVideoUtil ) |
|
281 { |
|
282 User::Leave( KErrNotReady ); |
|
283 } |
|
284 delete iVideoMimeType; |
|
285 iVideoMimeType = NULL; |
|
286 |
|
287 TInt metadataEntries = iVideoUtil->NumberOfMetaDataEntriesL(); |
|
288 LOGGER_WRITE_1( "metadataEntries: %d", metadataEntries); |
|
289 |
|
290 for (TInt i=0; i < metadataEntries ; i++) |
|
291 { |
|
292 CMMFMetaDataEntry* entry = iVideoUtil->MetaDataEntryL(i); |
|
293 CleanupStack::PushL( entry ); |
|
294 if ( entry->Name().Compare( KMimeType ) == 0 ) |
|
295 { |
|
296 if ( entry->Value().MatchF( KMimeTypeVideo ) == 0 ) |
|
297 { |
|
298 LOGGER_WRITE_1( "video mimetype found: %S", &entry->Value()); |
|
299 iVideoMimeType = HBufC::NewL(entry->Value().Length()); |
|
300 TPtr videoMimeTypePtr = iVideoMimeType->Des(); |
|
301 videoMimeTypePtr.Copy( entry->Value() ); |
|
302 CleanupStack::PopAndDestroy( entry ); |
|
303 return *iVideoMimeType; |
|
304 } |
|
305 } |
|
306 CleanupStack::PopAndDestroy( entry ); |
|
307 } |
|
308 return KNullDesC; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CSConVideoParser::AudioMimeTypeL() |
|
313 // returns audio mime type |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 const TDesC& CSConVideoParser::AudioMimeTypeL() |
|
317 { |
|
318 TRACE_FUNC; |
|
319 if ( !iVideoUtil ) |
|
320 { |
|
321 User::Leave( KErrNotReady ); |
|
322 } |
|
323 delete iAudioMimeType; |
|
324 iAudioMimeType = NULL; |
|
325 TInt metadataEntries = iVideoUtil->NumberOfMetaDataEntriesL(); |
|
326 LOGGER_WRITE_1( "metadataEntries: %d", metadataEntries); |
|
327 |
|
328 for (TInt i=0; i < metadataEntries ; i++) |
|
329 { |
|
330 CMMFMetaDataEntry* entry = iVideoUtil->MetaDataEntryL(i); |
|
331 CleanupStack::PushL( entry ); |
|
332 |
|
333 if ( entry->Name().Compare( KMimeType ) == 0 ) |
|
334 { |
|
335 if ( entry->Value().MatchF( KMimeTypeAudio ) == 0 ) |
|
336 { |
|
337 LOGGER_WRITE_1( "video mimetype found: %S", &entry->Value()); |
|
338 iAudioMimeType = HBufC::NewL(entry->Value().Length()); |
|
339 TPtr audioMimeTypePtr = iAudioMimeType->Des(); |
|
340 audioMimeTypePtr.Copy( entry->Value() ); |
|
341 CleanupStack::PopAndDestroy( entry ); |
|
342 return *iAudioMimeType; |
|
343 } |
|
344 } |
|
345 CleanupStack::PopAndDestroy( entry ); |
|
346 } |
|
347 return KNullDesC; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CSConVideoParser::MvpuoOpenComplete( TInt aError ) |
|
352 // MVideoPlayerUtilityObserver implementation |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CSConVideoParser::MvpuoOpenComplete( TInt aError ) |
|
356 { |
|
357 TRACE_FUNC_ENTRY; |
|
358 if ( iVideoUtilReady ) |
|
359 { |
|
360 // already timeout |
|
361 LOGGER_WRITE("Already timeout"); |
|
362 return; |
|
363 } |
|
364 LOGGER_WRITE_1( "aError: %d", aError ); |
|
365 if ( aError == KErrNone ) |
|
366 { |
|
367 iVideoUtil->Prepare(); |
|
368 } |
|
369 else |
|
370 { |
|
371 iVideoUtilReady = ETrue; |
|
372 iVideoUtilErr = aError; |
|
373 } |
|
374 |
|
375 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
376 { |
|
377 iAsyncStopCalled = ETrue; |
|
378 iTimeOut->Cancel(); |
|
379 LOGGER_WRITE("AsyncStop"); |
|
380 iWait.AsyncStop(); |
|
381 } |
|
382 TRACE_FUNC_EXIT; |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // CSConVideoParser::MvpuoPrepareComplete( TInt aError ) |
|
387 // MVideoPlayerUtilityObserver implementation |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 void CSConVideoParser::MvpuoPrepareComplete( TInt aError ) |
|
391 { |
|
392 TRACE_FUNC_ENTRY; |
|
393 if ( iVideoUtilReady ) |
|
394 { |
|
395 // already timeout |
|
396 LOGGER_WRITE("Already timeout"); |
|
397 return; |
|
398 } |
|
399 LOGGER_WRITE_1( "aError: %d", aError ); |
|
400 |
|
401 iVideoUtilReady = ETrue; |
|
402 iVideoUtilErr = aError; |
|
403 |
|
404 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
405 { |
|
406 iAsyncStopCalled = ETrue; |
|
407 iTimeOut->Cancel(); |
|
408 LOGGER_WRITE("AsyncStop"); |
|
409 iWait.AsyncStop(); |
|
410 } |
|
411 TRACE_FUNC_EXIT; |
|
412 } |
|
413 |
|
414 // ----------------------------------------------------------------------------- |
|
415 // CSConVideoParser::MvpuoFrameReady() |
|
416 // MVideoPlayerUtilityObserver implementation |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 void CSConVideoParser::MvpuoFrameReady( CFbsBitmap& /*aFrame*/,TInt /*aError*/ ) |
|
420 { |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CSConVideoParser::MvpuoPlayComplete() |
|
425 // MVideoPlayerUtilityObserver implementation |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CSConVideoParser::MvpuoPlayComplete( TInt /*aError*/ ) |
|
429 { |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // CSConVideoParser::MvpuoEvent() |
|
434 // MVideoPlayerUtilityObserver implementation |
|
435 // ----------------------------------------------------------------------------- |
|
436 // |
|
437 void CSConVideoParser::MvpuoEvent( const TMMFEvent& /*aEvent*/ ) |
|
438 { |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError) |
|
443 // MTNEVideoClipInfoObserver implementation |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 void CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError) |
|
447 { |
|
448 TRACE_FUNC_ENTRY; |
|
449 if ( iVideoClipReady ) |
|
450 { |
|
451 // already timeout |
|
452 LOGGER_WRITE("Already timeout"); |
|
453 return; |
|
454 } |
|
455 LOGGER_WRITE_1("aError: %d", aError); |
|
456 if ( aError == KErrNone ) |
|
457 { |
|
458 TSize resolution(320,240); |
|
459 TRAPD( err, aInfo.GetThumbL(*this,KBestThumbIndex, &resolution ) ); |
|
460 |
|
461 if ( err ) |
|
462 { |
|
463 LOGGER_WRITE_1("aInfo.GetThumbL err: %d", err); |
|
464 iVideoClipReady = ETrue; |
|
465 iVideoClipErr = err; |
|
466 } |
|
467 } |
|
468 else |
|
469 { |
|
470 iVideoClipReady = ETrue; |
|
471 iVideoClipErr = aError; |
|
472 } |
|
473 |
|
474 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
475 { |
|
476 iAsyncStopCalled = ETrue; |
|
477 iTimeOut->Cancel(); |
|
478 LOGGER_WRITE("AsyncStop"); |
|
479 iWait.AsyncStop(); |
|
480 } |
|
481 TRACE_FUNC_EXIT; |
|
482 } |
|
483 |
|
484 // ----------------------------------------------------------------------------- |
|
485 // CSConVideoParser::NotifyVideoClipThumbCompleted() |
|
486 // MTNEVideoClipInfoObserver implementation |
|
487 // ----------------------------------------------------------------------------- |
|
488 // |
|
489 void CSConVideoParser::NotifyVideoClipThumbCompleted(CTNEVideoClipInfo& /*aInfo*/, |
|
490 TInt aError, |
|
491 CFbsBitmap* aThumb) |
|
492 { |
|
493 TRACE_FUNC_ENTRY; |
|
494 if ( iVideoClipReady ) |
|
495 { |
|
496 // already timeout |
|
497 LOGGER_WRITE("Already timeout"); |
|
498 delete aThumb; |
|
499 return; |
|
500 } |
|
501 LOGGER_WRITE_1("aError: %d", aError); |
|
502 if ( aError == KErrNone) |
|
503 { |
|
504 delete iThumbnail; |
|
505 iThumbnail = NULL; |
|
506 LOGGER_WRITE("create CImageEncoder"); |
|
507 CImageEncoder* encoder = NULL; |
|
508 TRAPD( err, encoder = CImageEncoder::DataNewL( iThumbnail, KImageEncoderMimeType, CImageEncoder::EOptionAlwaysThread ) ); |
|
509 LOGGER_WRITE_1("err: %d", err ); |
|
510 if ( err == KErrNone ) |
|
511 { |
|
512 LOGGER_WRITE("Start Convert"); |
|
513 TRequestStatus status; |
|
514 encoder->Convert( &status, *aThumb, NULL ); |
|
515 |
|
516 User::WaitForRequest( status ); |
|
517 LOGGER_WRITE_1("Convert status: %d", status.Int()); |
|
518 LOGGER_WRITE_1("buf Length: %d", iThumbnail->Length()); |
|
519 err = status.Int(); |
|
520 } |
|
521 delete encoder; |
|
522 } |
|
523 delete aThumb; |
|
524 iVideoClipReady = ETrue; |
|
525 iVideoClipErr = aError; |
|
526 |
|
527 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
528 { |
|
529 iAsyncStopCalled = ETrue; |
|
530 iTimeOut->Cancel(); |
|
531 LOGGER_WRITE("AsyncStop"); |
|
532 iWait.AsyncStop(); |
|
533 } |
|
534 |
|
535 TRACE_FUNC_EXIT; |
|
536 } |
|
537 |
|
538 // ----------------------------------------------------------------------------- |
|
539 // CSConVideoParser::TimeOut() |
|
540 // Called when timeout has occured, cancels videoclip generation |
|
541 // ----------------------------------------------------------------------------- |
|
542 // |
|
543 void CSConVideoParser::TimeOut() |
|
544 { |
|
545 TRACE_FUNC_ENTRY; |
|
546 if ( !iVideoClipReady ) |
|
547 { |
|
548 iVideoClip->CancelThumb(); |
|
549 LOGGER_WRITE("videoclip cancelled"); |
|
550 iVideoClipReady = ETrue; |
|
551 iVideoClipErr = KErrCancel; |
|
552 } |
|
553 |
|
554 if ( !iVideoUtilReady ) |
|
555 { |
|
556 LOGGER_WRITE("videoUtil cancelled"); |
|
557 iVideoUtilReady = ETrue; |
|
558 iVideoUtilErr = KErrCancel; |
|
559 } |
|
560 |
|
561 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
562 { |
|
563 LOGGER_WRITE("AsyncStop"); |
|
564 iAsyncStopCalled = ETrue; |
|
565 iWait.AsyncStop(); |
|
566 } |
|
567 TRACE_FUNC_EXIT; |
|
568 } |