connectivitymodules/SeCon/services/pcd/src/sconvideoparser.cpp
changeset 37 74081e1a0272
parent 20 e1de7d03f843
child 36 9ba7f05d28a5
equal deleted inserted replaced
22:1a3f0bca12c6 37:74081e1a0272
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 _LIT( KMimeType, "MimeType" );
    25 _LIT( KMimeType, "MimeType" );
    26 _LIT8( KImageEncoderMimeType, "image/jpeg" );
    26 _LIT8( KImageEncoderMimeType, "image/jpeg" );
    27 _LIT( KMimeTypeAudio, "audio/*" );
    27 _LIT( KMimeTypeAudio, "audio/*" );
    28 _LIT( KMimeTypeVideo, "video/*" );
    28 _LIT( KMimeTypeVideo, "video/*" );
    29 
    29 
    30 const TInt KVideoClipTimeout( 10000000 ); // 10 sec.
    30 const TInt KRequestTimeOut( 20000000 ); // 20 sec.
    31 
    31 
    32 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    33 // CSConVideoParser::CSConVideoParser()
    33 // CSConVideoParser::CSConVideoParser()
    34 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    35 //
    35 //
    55     if ( iVideoUtil )
    55     if ( iVideoUtil )
    56         {
    56         {
    57         iVideoUtil->Close();
    57         iVideoUtil->Close();
    58         }
    58         }
    59     delete iVideoUtil;
    59     delete iVideoUtil;
       
    60     
       
    61     if ( iWindow )
       
    62         {
       
    63         iWindow->Close();
       
    64         }
       
    65     delete iWindow;
       
    66     iRootWindow.Close();
    60     delete iScreen;
    67     delete iScreen;
    61     iWsSession.Close();
    68     iWsSession.Close();
    62     
    69     
    63     delete iThumbnail;
    70     delete iThumbnail;
    64     delete iVideoMimeType;
    71     delete iVideoMimeType;
    88     TRACE_FUNC_ENTRY;
    95     TRACE_FUNC_ENTRY;
    89     
    96     
    90     User::LeaveIfError( iWsSession.Connect() );
    97     User::LeaveIfError( iWsSession.Connect() );
    91     
    98     
    92     iScreen = new(ELeave) CWsScreenDevice( iWsSession );
    99     iScreen = new(ELeave) CWsScreenDevice( iWsSession );
    93     iScreen->Construct();
   100     User::LeaveIfError( iScreen->Construct() );
    94     
   101     
    95     RWindowGroup wg( iWsSession );
   102     iRootWindow = RWindowGroup(iWsSession);
    96     User::LeaveIfError( wg.Construct(reinterpret_cast<TUint32>(&wg), EFalse) );
   103     User::LeaveIfError( iRootWindow.Construct(reinterpret_cast<TUint32>(&iWsSession), EFalse) );
    97     CleanupClosePushL( wg );
   104     
    98     
   105     iWindow = new(ELeave) RWindow( iWsSession );
    99     CWindowGc* gc;
   106     User::LeaveIfError( iWindow->Construct(iRootWindow, reinterpret_cast<TUint32>(&iRootWindow) + 1) );
   100     User::LeaveIfError( iScreen->CreateContext(gc) );
       
   101     CleanupStack::PushL(gc);
       
   102     
       
   103     RWindow window( iWsSession );
       
   104     User::LeaveIfError( window.Construct(wg, reinterpret_cast<TUint32>(&wg) + 1) );
       
   105     CleanupClosePushL( window );
       
   106     
   107     
   107     TRect temp(0,0,320,240); // dummy parameter
   108     TRect temp(0,0,320,240); // dummy parameter
   108     iVideoUtil = CVideoPlayerUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceNone, iWsSession, *(iScreen), window, temp, temp);
   109     iVideoUtil = CVideoPlayerUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceNone, iWsSession, *iScreen, *iWindow, temp, temp);
   109     
       
   110     CleanupStack::PopAndDestroy( &window );
       
   111     CleanupStack::PopAndDestroy( gc );
       
   112     CleanupStack::PopAndDestroy( &wg );
       
   113     
   110     
   114     iTimeOut = CSconTimeOut::NewL( *this );
   111     iTimeOut = CSconTimeOut::NewL( *this );
   115     
   112     
   116     TRACE_FUNC_EXIT;
   113     TRACE_FUNC_EXIT;
   117     }
   114     }
   151     TBool fileExist = BaflUtils::FileExists( aFs, aFileName );
   148     TBool fileExist = BaflUtils::FileExists( aFs, aFileName );
   152     if ( !fileExist )
   149     if ( !fileExist )
   153         {
   150         {
   154         User::Leave( KErrNotFound );
   151         User::Leave( KErrNotFound );
   155         }
   152         }
   156     
   153     iAsyncStopCalled = EFalse;
   157     iVideoClip = CTNEVideoClipInfo::NewL( aFileName, *this );
   154     iVideoClip = CTNEVideoClipInfo::NewL( aFileName, *this );
   158     
   155     
   159     iVideoUtil->OpenFileL( aFileName );
   156     iVideoUtil->OpenFileL( aFileName );
   160     
   157     
       
   158     LOGGER_WRITE("Start timeout");
       
   159     iTimeOut->Start( KRequestTimeOut );
   161     
   160     
   162     LOGGER_WRITE("iWait.Start()");
   161     LOGGER_WRITE("iWait.Start()");
   163     iWait.Start();
   162     iWait.Start();
   164     
   163     
   165     TRACE_FUNC_EXIT;
   164     TRACE_FUNC_EXIT;
   354 // -----------------------------------------------------------------------------
   353 // -----------------------------------------------------------------------------
   355 //
   354 //
   356 void CSConVideoParser::MvpuoOpenComplete( TInt aError )
   355 void CSConVideoParser::MvpuoOpenComplete( TInt aError )
   357     {
   356     {
   358     TRACE_FUNC_ENTRY;
   357     TRACE_FUNC_ENTRY;
       
   358     if ( iVideoUtilReady )
       
   359         {
       
   360         // already timeout
       
   361         LOGGER_WRITE("Already timeout");
       
   362         return;
       
   363         }
   359     LOGGER_WRITE_1( "aError: %d", aError );
   364     LOGGER_WRITE_1( "aError: %d", aError );
   360     if ( aError == KErrNone )
   365     if ( aError == KErrNone )
   361         {
   366         {
   362         iVideoUtil->Prepare();
   367         iVideoUtil->Prepare();
   363         }
   368         }
   365         {
   370         {
   366         iVideoUtilReady = ETrue;
   371         iVideoUtilReady = ETrue;
   367         iVideoUtilErr = aError;
   372         iVideoUtilErr = aError;
   368         }
   373         }
   369     
   374     
   370     if ( iVideoUtilReady && iVideoClipReady )
   375     if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled )
   371         {
   376         {
       
   377         iAsyncStopCalled = ETrue;
       
   378         iTimeOut->Cancel();
   372         LOGGER_WRITE("AsyncStop");
   379         LOGGER_WRITE("AsyncStop");
   373         iWait.AsyncStop();
   380         iWait.AsyncStop();
   374         }
   381         }
   375     TRACE_FUNC_EXIT;
   382     TRACE_FUNC_EXIT;
   376     }
   383     }
   381 // -----------------------------------------------------------------------------
   388 // -----------------------------------------------------------------------------
   382 //
   389 //
   383 void CSConVideoParser::MvpuoPrepareComplete( TInt aError )
   390 void CSConVideoParser::MvpuoPrepareComplete( TInt aError )
   384     {
   391     {
   385     TRACE_FUNC_ENTRY;
   392     TRACE_FUNC_ENTRY;
       
   393     if ( iVideoUtilReady )
       
   394         {
       
   395         // already timeout
       
   396         LOGGER_WRITE("Already timeout");
       
   397         return;
       
   398         }
   386     LOGGER_WRITE_1( "aError: %d", aError );
   399     LOGGER_WRITE_1( "aError: %d", aError );
   387     
   400     
   388     iVideoUtilReady = ETrue;
   401     iVideoUtilReady = ETrue;
   389     iVideoUtilErr = aError;
   402     iVideoUtilErr = aError;
   390     
   403     
   391     if ( iVideoUtilReady && iVideoClipReady )
   404     if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled )
   392         {
   405         {
       
   406         iAsyncStopCalled = ETrue;
       
   407         iTimeOut->Cancel();
   393         LOGGER_WRITE("AsyncStop");
   408         LOGGER_WRITE("AsyncStop");
   394         iWait.AsyncStop();
   409         iWait.AsyncStop();
   395         }
   410         }
   396     TRACE_FUNC_EXIT;
   411     TRACE_FUNC_EXIT;
   397     }
   412     }
   429 // -----------------------------------------------------------------------------
   444 // -----------------------------------------------------------------------------
   430 //
   445 //
   431 void CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError)
   446 void CSConVideoParser::NotifyVideoClipInfoReady(CTNEVideoClipInfo& aInfo, TInt aError)
   432     {
   447     {
   433     TRACE_FUNC_ENTRY;
   448     TRACE_FUNC_ENTRY;
       
   449     if ( iVideoClipReady )
       
   450         {
       
   451         // already timeout
       
   452         LOGGER_WRITE("Already timeout");
       
   453         return;
       
   454         }
   434     LOGGER_WRITE_1("aError: %d", aError);
   455     LOGGER_WRITE_1("aError: %d", aError);
   435     if ( aError == KErrNone )
   456     if ( aError == KErrNone )
   436         {
   457         {
   437         TSize resolution(320,240);
   458         TSize resolution(320,240);
   438         TRAPD( err, aInfo.GetThumbL(*this,KBestThumbIndex, &resolution ) );
   459         TRAPD( err, aInfo.GetThumbL(*this,KBestThumbIndex, &resolution ) );
   441             {
   462             {
   442             LOGGER_WRITE_1("aInfo.GetThumbL err: %d", err);
   463             LOGGER_WRITE_1("aInfo.GetThumbL err: %d", err);
   443             iVideoClipReady = ETrue;
   464             iVideoClipReady = ETrue;
   444             iVideoClipErr = err;
   465             iVideoClipErr = err;
   445             }
   466             }
   446         else
       
   447             {
       
   448             LOGGER_WRITE("Start timeout");
       
   449             iTimeOut->Start( KVideoClipTimeout );
       
   450             }
       
   451         }
   467         }
   452     else
   468     else
   453         {
   469         {
   454         iVideoClipReady = ETrue;
   470         iVideoClipReady = ETrue;
   455         iVideoClipErr = aError;
   471         iVideoClipErr = aError;
   456         }
   472         }
   457     
   473     
   458     if ( iVideoUtilReady && iVideoClipReady )
   474     if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled )
   459         {
   475         {
       
   476         iAsyncStopCalled = ETrue;
       
   477         iTimeOut->Cancel();
   460         LOGGER_WRITE("AsyncStop");
   478         LOGGER_WRITE("AsyncStop");
   461         iWait.AsyncStop();
   479         iWait.AsyncStop();
   462         }
   480         }
   463     TRACE_FUNC_EXIT;
   481     TRACE_FUNC_EXIT;
   464     }
   482     }
   471 void CSConVideoParser::NotifyVideoClipThumbCompleted(CTNEVideoClipInfo& /*aInfo*/, 
   489 void CSConVideoParser::NotifyVideoClipThumbCompleted(CTNEVideoClipInfo& /*aInfo*/, 
   472         TInt aError, 
   490         TInt aError, 
   473         CFbsBitmap* aThumb)
   491         CFbsBitmap* aThumb)
   474     {
   492     {
   475     TRACE_FUNC_ENTRY;
   493     TRACE_FUNC_ENTRY;
       
   494     if ( iVideoClipReady )
       
   495         {
       
   496         // already timeout
       
   497         LOGGER_WRITE("Already timeout");
       
   498         delete aThumb;
       
   499         return;
       
   500         }
   476     LOGGER_WRITE_1("aError: %d", aError);
   501     LOGGER_WRITE_1("aError: %d", aError);
   477     iTimeOut->Cancel();
       
   478     if ( aError == KErrNone)
   502     if ( aError == KErrNone)
   479         {
   503         {
   480         delete iThumbnail;
   504         delete iThumbnail;
   481         iThumbnail = NULL;
   505         iThumbnail = NULL;
   482         LOGGER_WRITE("create CImageEncoder");
   506         LOGGER_WRITE("create CImageEncoder");
   498         }
   522         }
   499     delete aThumb;
   523     delete aThumb;
   500     iVideoClipReady = ETrue;
   524     iVideoClipReady = ETrue;
   501     iVideoClipErr = aError;
   525     iVideoClipErr = aError;
   502     
   526     
   503     if ( iVideoUtilReady && iVideoClipReady )
   527     if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled )
   504         {
   528         {
       
   529         iAsyncStopCalled = ETrue;
       
   530         iTimeOut->Cancel();
   505         LOGGER_WRITE("AsyncStop");
   531         LOGGER_WRITE("AsyncStop");
   506         iWait.AsyncStop();
   532         iWait.AsyncStop();
   507         }
   533         }
   508     
   534     
   509     TRACE_FUNC_EXIT;
   535     TRACE_FUNC_EXIT;
   523         LOGGER_WRITE("videoclip cancelled");
   549         LOGGER_WRITE("videoclip cancelled");
   524         iVideoClipReady = ETrue;
   550         iVideoClipReady = ETrue;
   525         iVideoClipErr = KErrCancel;
   551         iVideoClipErr = KErrCancel;
   526         }
   552         }
   527     
   553     
   528     if ( iVideoUtilReady && iVideoClipReady )
   554     if ( !iVideoUtilReady )
       
   555         {
       
   556         LOGGER_WRITE("videoUtil cancelled");
       
   557         iVideoUtilReady = ETrue;
       
   558         iVideoUtilErr = KErrCancel;
       
   559         }
       
   560     
       
   561     if ( iVideoUtilReady && iVideoClipReady && !iAsyncStopCalled )
   529         {
   562         {
   530         LOGGER_WRITE("AsyncStop");
   563         LOGGER_WRITE("AsyncStop");
       
   564         iAsyncStopCalled = ETrue;
   531         iWait.AsyncStop();
   565         iWait.AsyncStop();
   532         }
   566         }
   533     TRACE_FUNC_EXIT;
   567     TRACE_FUNC_EXIT;
   534     }
   568     }