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 |
|
110 iVideoUtil = CVideoPlayerUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceNone, iWsSession, *iScreen, *iWindow, temp, temp); |
|
111 |
|
112 iTimeOut = CSconTimeOut::NewL( *this ); |
|
113 |
|
114 TRACE_FUNC_EXIT; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSConVideoParser::OpenFileL( const RFs& aFs, const TDesC& aFileName ) |
|
119 // Opens video file |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CSConVideoParser::OpenFileL( const RFs& aFs, const TDesC& aFileName ) |
|
123 { |
|
124 TRACE_FUNC_ENTRY; |
|
125 |
|
126 iVideoUtilReady = EFalse; |
|
127 iVideoClipReady = EFalse; |
|
128 iVideoUtilErr = KErrNone; |
|
129 iVideoClipErr = KErrNone; |
|
130 |
|
131 delete iThumbnail; |
|
132 iThumbnail = NULL; |
|
133 delete iVideoMimeType; |
|
134 iVideoMimeType=NULL; |
|
135 delete iAudioMimeType; |
|
136 iAudioMimeType=NULL; |
|
137 |
|
138 if ( iVideoClip ) |
|
139 { |
|
140 iVideoClip->CancelThumb(); |
|
141 delete iVideoClip; |
|
142 iVideoClip = NULL; |
|
143 } |
|
144 if ( iVideoUtil ) |
|
145 { |
|
146 iVideoUtil->Close(); |
|
147 } |
|
148 |
|
149 TBool fileExist = BaflUtils::FileExists( aFs, aFileName ); |
|
150 if ( !fileExist ) |
|
151 { |
|
152 User::Leave( KErrNotFound ); |
|
153 } |
|
154 iAsyncStopCalled = EFalse; |
|
155 iVideoClip = CTNEVideoClipInfo::NewL( aFileName, *this ); |
|
156 |
|
157 iVideoUtil->OpenFileL( aFileName ); |
|
158 |
|
159 LOGGER_WRITE("Start timeout"); |
|
160 iTimeOut->Start( KRequestTimeOut ); |
|
161 |
|
162 LOGGER_WRITE("iWait.Start()"); |
|
163 iWait.Start(); |
|
164 |
|
165 TRACE_FUNC_EXIT; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CSConVideoParser::Thumbnail() |
|
170 // returns video thumbnail in jpg format |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 const TDesC8& CSConVideoParser::Thumbnail() const |
|
174 { |
|
175 TRACE_FUNC; |
|
176 if ( !iThumbnail ) |
|
177 { |
|
178 return KNullDesC8; |
|
179 } |
|
180 return *iThumbnail; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CSConVideoParser::VideoFrameRateL() |
|
185 // returns video frame rate |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 TReal32 CSConVideoParser::VideoFrameRateL() const |
|
189 { |
|
190 TRACE_FUNC; |
|
191 if ( !iVideoUtil ) |
|
192 { |
|
193 User::Leave( KErrNotReady ); |
|
194 } |
|
195 return iVideoUtil->VideoFrameRateL(); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CSConVideoParser::VideoFrameSizeL() |
|
200 // returns video frame size |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CSConVideoParser::VideoFrameSizeL(TSize& aSize) const |
|
204 { |
|
205 TRACE_FUNC; |
|
206 if ( !iVideoUtil ) |
|
207 { |
|
208 User::Leave( KErrNotReady ); |
|
209 } |
|
210 return iVideoUtil->VideoFrameSizeL( aSize ); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CSConVideoParser::VideoFormatMimeTypeL() |
|
215 // returns video format |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 const TDesC8& CSConVideoParser::VideoFormatMimeTypeL() const |
|
219 { |
|
220 TRACE_FUNC; |
|
221 if ( !iVideoUtil ) |
|
222 { |
|
223 User::Leave( KErrNotReady ); |
|
224 } |
|
225 return iVideoUtil->VideoFormatMimeType(); |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CSConVideoParser::VideoBitRateL() |
|
230 // returns videostream bitrate |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TInt CSConVideoParser::VideoBitRateL() const |
|
234 { |
|
235 TRACE_FUNC; |
|
236 if ( !iVideoUtil ) |
|
237 { |
|
238 User::Leave( KErrNotReady ); |
|
239 } |
|
240 return iVideoUtil->VideoBitRateL(); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CSConVideoParser::AudioBitRateL() |
|
245 // returns audiostream bitrate |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TInt CSConVideoParser::AudioBitRateL() const |
|
249 { |
|
250 TRACE_FUNC; |
|
251 if ( !iVideoUtil ) |
|
252 { |
|
253 User::Leave( KErrNotReady ); |
|
254 } |
|
255 return iVideoUtil->AudioBitRateL(); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CSConVideoParser::DurationL() |
|
260 // returns video duration in milliseconds |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 TInt CSConVideoParser::DurationL() const |
|
264 { |
|
265 TRACE_FUNC; |
|
266 if ( !iVideoUtil ) |
|
267 { |
|
268 User::Leave( KErrNotReady ); |
|
269 } |
|
270 return iVideoUtil->DurationL().Int64()/1000; |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CSConVideoParser::VideoMimeTypeL() |
|
275 // returns video mime type |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 const TDesC& CSConVideoParser::VideoMimeTypeL() |
|
279 { |
|
280 TRACE_FUNC; |
|
281 if ( !iVideoUtil ) |
|
282 { |
|
283 User::Leave( KErrNotReady ); |
|
284 } |
|
285 delete iVideoMimeType; |
|
286 iVideoMimeType = NULL; |
|
287 |
|
288 TInt metadataEntries = iVideoUtil->NumberOfMetaDataEntriesL(); |
|
289 LOGGER_WRITE_1( "metadataEntries: %d", metadataEntries); |
|
290 |
|
291 for (TInt i=0; i < metadataEntries ; i++) |
|
292 { |
|
293 CMMFMetaDataEntry* entry = iVideoUtil->MetaDataEntryL(i); |
|
294 CleanupStack::PushL( entry ); |
|
295 if ( entry->Name().Compare( KMimeType ) == 0 ) |
|
296 { |
|
297 if ( entry->Value().MatchF( KMimeTypeVideo ) == 0 ) |
|
298 { |
|
299 LOGGER_WRITE_1( "video mimetype found: %S", &entry->Value()); |
|
300 iVideoMimeType = HBufC::NewL(entry->Value().Length()); |
|
301 TPtr videoMimeTypePtr = iVideoMimeType->Des(); |
|
302 videoMimeTypePtr.Copy( entry->Value() ); |
|
303 CleanupStack::PopAndDestroy( entry ); |
|
304 return *iVideoMimeType; |
|
305 } |
|
306 } |
|
307 CleanupStack::PopAndDestroy( entry ); |
|
308 } |
|
309 return KNullDesC; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CSConVideoParser::AudioMimeTypeL() |
|
314 // returns audio mime type |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 const TDesC& CSConVideoParser::AudioMimeTypeL() |
|
318 { |
|
319 TRACE_FUNC; |
|
320 if ( !iVideoUtil ) |
|
321 { |
|
322 User::Leave( KErrNotReady ); |
|
323 } |
|
324 delete iAudioMimeType; |
|
325 iAudioMimeType = NULL; |
|
326 TInt metadataEntries = iVideoUtil->NumberOfMetaDataEntriesL(); |
|
327 LOGGER_WRITE_1( "metadataEntries: %d", metadataEntries); |
|
328 |
|
329 for (TInt i=0; i < metadataEntries ; i++) |
|
330 { |
|
331 CMMFMetaDataEntry* entry = iVideoUtil->MetaDataEntryL(i); |
|
332 CleanupStack::PushL( entry ); |
|
333 |
|
334 if ( entry->Name().Compare( KMimeType ) == 0 ) |
|
335 { |
|
336 if ( entry->Value().MatchF( KMimeTypeAudio ) == 0 ) |
|
337 { |
|
338 LOGGER_WRITE_1( "video mimetype found: %S", &entry->Value()); |
|
339 iAudioMimeType = HBufC::NewL(entry->Value().Length()); |
|
340 TPtr audioMimeTypePtr = iAudioMimeType->Des(); |
|
341 audioMimeTypePtr.Copy( entry->Value() ); |
|
342 CleanupStack::PopAndDestroy( entry ); |
|
343 return *iAudioMimeType; |
|
344 } |
|
345 } |
|
346 CleanupStack::PopAndDestroy( entry ); |
|
347 } |
|
348 return KNullDesC; |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CSConVideoParser::MvpuoOpenComplete( TInt aError ) |
|
353 // MVideoPlayerUtilityObserver implementation |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 void CSConVideoParser::MvpuoOpenComplete( TInt aError ) |
|
357 { |
|
358 TRACE_FUNC_ENTRY; |
|
359 if ( iVideoUtilReady ) |
|
360 { |
|
361 // already timeout |
|
362 LOGGER_WRITE("Already timeout"); |
|
363 return; |
|
364 } |
|
365 LOGGER_WRITE_1( "aError: %d", aError ); |
|
366 if ( aError == KErrNone ) |
|
367 { |
|
368 iVideoUtil->Prepare(); |
|
369 } |
|
370 else |
|
371 { |
|
372 iVideoUtilReady = ETrue; |
|
373 iVideoUtilErr = aError; |
|
374 } |
|
375 |
|
376 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
377 { |
|
378 iAsyncStopCalled = ETrue; |
|
379 iTimeOut->Cancel(); |
|
380 LOGGER_WRITE("AsyncStop"); |
|
381 iWait.AsyncStop(); |
|
382 } |
|
383 TRACE_FUNC_EXIT; |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CSConVideoParser::MvpuoPrepareComplete( TInt aError ) |
|
388 // MVideoPlayerUtilityObserver implementation |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 void CSConVideoParser::MvpuoPrepareComplete( TInt aError ) |
|
392 { |
|
393 TRACE_FUNC_ENTRY; |
|
394 if ( iVideoUtilReady ) |
|
395 { |
|
396 // already timeout |
|
397 LOGGER_WRITE("Already timeout"); |
|
398 return; |
|
399 } |
|
400 LOGGER_WRITE_1( "aError: %d", aError ); |
|
401 |
|
402 iVideoUtilReady = ETrue; |
|
403 iVideoUtilErr = aError; |
|
404 |
|
405 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
406 { |
|
407 iAsyncStopCalled = ETrue; |
|
408 iTimeOut->Cancel(); |
|
409 LOGGER_WRITE("AsyncStop"); |
|
410 iWait.AsyncStop(); |
|
411 } |
|
412 TRACE_FUNC_EXIT; |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CSConVideoParser::MvpuoFrameReady() |
|
417 // MVideoPlayerUtilityObserver implementation |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 void CSConVideoParser::MvpuoFrameReady( CFbsBitmap& /*aFrame*/,TInt /*aError*/ ) |
|
421 { |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CSConVideoParser::MvpuoPlayComplete() |
|
426 // MVideoPlayerUtilityObserver implementation |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CSConVideoParser::MvpuoPlayComplete( TInt /*aError*/ ) |
|
430 { |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CSConVideoParser::MvpuoEvent() |
|
435 // MVideoPlayerUtilityObserver implementation |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 void CSConVideoParser::MvpuoEvent( const TMMFEvent& /*aEvent*/ ) |
|
439 { |
|
440 } |
|
441 |
|
442 // ----------------------------------------------------------------------------- |
|
443 // CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError) |
|
444 // MTNEVideoClipInfoObserver implementation |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 void CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError) |
|
448 { |
|
449 TRACE_FUNC_ENTRY; |
|
450 if ( iVideoClipReady ) |
|
451 { |
|
452 // already timeout |
|
453 LOGGER_WRITE("Already timeout"); |
|
454 return; |
|
455 } |
|
456 LOGGER_WRITE_1("aError: %d", aError); |
|
457 if ( aError == KErrNone ) |
|
458 { |
|
459 TSize resolution(320,240); |
|
460 TRAPD( err, aInfo.GetThumbL(*this,KBestThumbIndex, &resolution ) ); |
|
461 |
|
462 if ( err ) |
|
463 { |
|
464 LOGGER_WRITE_1("aInfo.GetThumbL err: %d", err); |
|
465 iVideoClipReady = ETrue; |
|
466 iVideoClipErr = err; |
|
467 } |
|
468 } |
|
469 else |
|
470 { |
|
471 iVideoClipReady = ETrue; |
|
472 iVideoClipErr = aError; |
|
473 } |
|
474 |
|
475 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
476 { |
|
477 iAsyncStopCalled = ETrue; |
|
478 iTimeOut->Cancel(); |
|
479 LOGGER_WRITE("AsyncStop"); |
|
480 iWait.AsyncStop(); |
|
481 } |
|
482 TRACE_FUNC_EXIT; |
|
483 } |
|
484 |
|
485 // ----------------------------------------------------------------------------- |
|
486 // CSConVideoParser::NotifyVideoClipThumbCompleted() |
|
487 // MTNEVideoClipInfoObserver implementation |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 void CSConVideoParser::NotifyVideoClipThumbCompleted(CTNEVideoClipInfo& /*aInfo*/, |
|
491 TInt aError, |
|
492 CFbsBitmap* aThumb) |
|
493 { |
|
494 TRACE_FUNC_ENTRY; |
|
495 if ( iVideoClipReady ) |
|
496 { |
|
497 // already timeout |
|
498 LOGGER_WRITE("Already timeout"); |
|
499 delete aThumb; |
|
500 return; |
|
501 } |
|
502 LOGGER_WRITE_1("aError: %d", aError); |
|
503 if ( aError == KErrNone) |
|
504 { |
|
505 delete iThumbnail; |
|
506 iThumbnail = NULL; |
|
507 LOGGER_WRITE("create CImageEncoder"); |
|
508 CImageEncoder* encoder = NULL; |
|
509 TRAPD( err, encoder = CImageEncoder::DataNewL( iThumbnail, KImageEncoderMimeType, CImageEncoder::EOptionAlwaysThread ) ); |
|
510 LOGGER_WRITE_1("err: %d", err ); |
|
511 if ( err == KErrNone ) |
|
512 { |
|
513 LOGGER_WRITE("Start Convert"); |
|
514 TRequestStatus status; |
|
515 encoder->Convert( &status, *aThumb, NULL ); |
|
516 |
|
517 User::WaitForRequest( status ); |
|
518 LOGGER_WRITE_1("Convert status: %d", status.Int()); |
|
519 LOGGER_WRITE_1("buf Length: %d", iThumbnail->Length()); |
|
520 err = status.Int(); |
|
521 } |
|
522 delete encoder; |
|
523 } |
|
524 delete aThumb; |
|
525 iVideoClipReady = ETrue; |
|
526 iVideoClipErr = aError; |
|
527 |
|
528 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
529 { |
|
530 iAsyncStopCalled = ETrue; |
|
531 iTimeOut->Cancel(); |
|
532 LOGGER_WRITE("AsyncStop"); |
|
533 iWait.AsyncStop(); |
|
534 } |
|
535 |
|
536 TRACE_FUNC_EXIT; |
|
537 } |
|
538 |
|
539 // ----------------------------------------------------------------------------- |
|
540 // CSConVideoParser::TimeOut() |
|
541 // Called when timeout has occured, cancels videoclip generation |
|
542 // ----------------------------------------------------------------------------- |
|
543 // |
|
544 void CSConVideoParser::TimeOut() |
|
545 { |
|
546 TRACE_FUNC_ENTRY; |
|
547 if ( !iVideoClipReady ) |
|
548 { |
|
549 iVideoClip->CancelThumb(); |
|
550 LOGGER_WRITE("videoclip cancelled"); |
|
551 iVideoClipReady = ETrue; |
|
552 iVideoClipErr = KErrCancel; |
|
553 } |
|
554 |
|
555 if ( !iVideoUtilReady ) |
|
556 { |
|
557 LOGGER_WRITE("videoUtil cancelled"); |
|
558 iVideoUtilReady = ETrue; |
|
559 iVideoUtilErr = KErrCancel; |
|
560 } |
|
561 |
|
562 if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled ) |
|
563 { |
|
564 LOGGER_WRITE("AsyncStop"); |
|
565 iAsyncStopCalled = ETrue; |
|
566 iWait.AsyncStop(); |
|
567 } |
|
568 TRACE_FUNC_EXIT; |
|
569 } |
|