upnpframework/upnpcommand/src/upnpshowtask.cpp
branchnew development branch with rendering state machine and other goodies
changeset 38 5360b7ddc251
parent 0 7f85d04be362
equal deleted inserted replaced
32:3785f754ee62 38:5360b7ddc251
     1 /*
     1 /*
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2009 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".
    30 #include "upnpconstantdefs.h"           // KFilterCommon, KClassVideo
    30 #include "upnpconstantdefs.h"           // KFilterCommon, KClassVideo
    31 #include "upnpitemresolver.h"           // MUPnPItemResolver
    31 #include "upnpitemresolver.h"           // MUPnPItemResolver
    32 #include "upnpitemresolverobserver.h"   // MUPnPItemResolverObserver
    32 #include "upnpitemresolverobserver.h"   // MUPnPItemResolverObserver
    33 #include "upnpitemresolverfactory.h"    // UPnPItemResolverFactory
    33 #include "upnpitemresolverfactory.h"    // UPnPItemResolverFactory
    34 #include "upnpitemutility.h"            // UPnPItemUtility::BelongsToClass
    34 #include "upnpitemutility.h"            // UPnPItemUtility::BelongsToClass
       
    35 #include <upnpstring.h>                 // UpnpString::ToUnicodeL
    35 
    36 
    36 // upnpframework / commonui
    37 // upnpframework / commonui
    37 #include "upnpcommonui.h"
    38 #include "upnpcommonui.h"
    38 
    39 
    39 // command internal
    40 // command internal
    42 #include "upnptaskresourceallocator.h"  // CUpnpTaskResourceAllocator
    43 #include "upnptaskresourceallocator.h"  // CUpnpTaskResourceAllocator
    43 #include "upnpimagerenderingengine.h"   // CUpnpImageRenderingEngine
    44 #include "upnpimagerenderingengine.h"   // CUpnpImageRenderingEngine
    44 #include "upnpshowtask.h"
    45 #include "upnpshowtask.h"
    45 #include "upnpcommand.h"
    46 #include "upnpcommand.h"
    46 #include "upnpnotehandler.h"            // CUpnpNoteHandler
    47 #include "upnpnotehandler.h"            // CUpnpNoteHandler
       
    48 #include "upnpavdevice.h"
    47 
    49 
    48 _LIT( KComponentLogfile, "upnpcommand.log");
    50 _LIT( KComponentLogfile, "upnpcommand.log");
    49 #include "upnplog.h"
    51 #include "upnplog.h"
    50 
    52 
    51 
    53 
    73 //
    75 //
    74 CUpnpShowTask::CUpnpShowTask()
    76 CUpnpShowTask::CUpnpShowTask()
    75     {
    77     {
    76     __LOG( "[UpnpCommand]\t CUpnpShowTask::Constructor" );
    78     __LOG( "[UpnpCommand]\t CUpnpShowTask::Constructor" );
    77 
    79 
    78     // Initialise member variables
       
    79     iCommonUI = NULL;
       
    80     iPlayingVideo = EFalse;
       
    81     iRenderingSession = NULL;
       
    82     iVideoRenderingSession = NULL;
       
    83     iResourceAllocator = NULL;
       
    84     iRenderingEngine = NULL;
       
    85     }
    80     }
    86 
    81 
    87 // --------------------------------------------------------------------------
    82 // --------------------------------------------------------------------------
    88 // Destructor.
    83 // Destructor.
    89 // --------------------------------------------------------------------------
    84 // --------------------------------------------------------------------------
   101 //
    96 //
   102 void CUpnpShowTask::Cleanup()
    97 void CUpnpShowTask::Cleanup()
   103     {
    98     {
   104     __LOG( "[UpnpCommand]\t CUpnpShowTask::Cleanup" );
    99     __LOG( "[UpnpCommand]\t CUpnpShowTask::Cleanup" );
   105 
   100 
   106     if ( iRenderingEngine )
   101 	delete iRenderingEngine;
   107         {
   102 	iRenderingEngine = NULL;
   108         delete iRenderingEngine;
       
   109         iRenderingEngine = NULL;
       
   110         }       
       
   111         
   103         
   112     // delete the resource allocator
   104     // delete the resource allocator
   113     // Local mediaserver and AVController resources will be freed.
   105     // Local mediaserver and AVController resources will be freed.
   114     delete iResourceAllocator;
   106     delete iResourceAllocator;
   115     iResourceAllocator = NULL;
   107     iResourceAllocator = NULL;
   138 
   130 
   139     // create the resource allocator
   131     // create the resource allocator
   140     iResourceAllocator = CUpnpTaskResourceAllocator::NewL(
   132     iResourceAllocator = CUpnpTaskResourceAllocator::NewL(
   141         *iCommonUI,
   133         *iCommonUI,
   142         CUpnpTaskResourceAllocator::EResourceAvController |
   134         CUpnpTaskResourceAllocator::EResourceAvController |
   143         CUpnpTaskResourceAllocator::EResourceLocalMediaServer |
   135         /*CUpnpTaskResourceAllocator::EResourceLocalMediaServer |*/
   144         CUpnpTaskResourceAllocator::EResourceSelectImageRenderer );
   136         CUpnpTaskResourceAllocator::EResourceSelectImageRenderer );
   145         
   137         
   146     iShowPlaybackFailedNote = ETrue;
   138     iShowPlaybackFailedNote = ETrue;
   147     }
   139     }
   148 
   140 
   183 //
   175 //
   184 void CUpnpShowTask::ExecuteL()
   176 void CUpnpShowTask::ExecuteL()
   185     {
   177     {
   186     __LOG( "[UpnpCommand]\t CUpnpShowTask::ExecuteL" );
   178     __LOG( "[UpnpCommand]\t CUpnpShowTask::ExecuteL" );
   187     // assert that required resources exist
   179     // assert that required resources exist
   188     __ASSERTD( iRenderingEngine, __FILE__, __LINE__ );
   180     __ASSERT( iRenderingEngine, __FILE__, __LINE__ );
   189 
   181 
   190 
   182 
   191     if( iPlayingVideo )
   183     if( iPlayingVideo )
   192         {
   184         {
   193         // if videoplayerdlg is active, we cannot start rendering new file
   185         // if videoplayerdlg is active, we cannot start rendering new file
   207 // CUpnpShowTask::GetMedia
   199 // CUpnpShowTask::GetMedia
   208 // provide media to be played back
   200 // provide media to be played back
   209 // --------------------------------------------------------------------------
   201 // --------------------------------------------------------------------------
   210 MUPnPItemResolver* CUpnpShowTask::GetMedia()
   202 MUPnPItemResolver* CUpnpShowTask::GetMedia()
   211     {
   203     {
   212     __ASSERTD( FilePipe(), __FILE__, __LINE__ );
   204     __ASSERT( FilePipe(), __FILE__, __LINE__ );
       
   205 
       
   206     __LOG1( "[UpnpCommand]\t CUpnpShowTask::GetMedia cnt %d", 
       
   207         FilePipe()->Count() );
   213 
   208 
   214     MUPnPItemResolver* resolver = 0;
   209     MUPnPItemResolver* resolver = 0;
   215 
   210 
   216     if ( FilePipe()->Count() > 0 )
   211     if ( FilePipe()->Count() > 0 )
   217         {
   212         {
   253         // - so that we do not have to rewrite the resolving code in
   248         // - so that we do not have to rewrite the resolving code in
   254         //   another place, it already exists in image rendering engine.
   249         //   another place, it already exists in image rendering engine.
   255         aError = PlayVideo( *aItem );
   250         aError = PlayVideo( *aItem );
   256         }
   251         }
   257 
   252 
       
   253     // disconnect and renderer busy messages are handled in EngineShutdown
       
   254     // other errors are handled here
   258     if ( aError != KErrDisconnected )
   255     if ( aError != KErrDisconnected )
   259         {
   256         {
   260         // disconnect message is handled in EngineShutdown
       
   261         // other errors are handled here
       
   262         if ( aError == KErrNotSupported || aError == KErrPermissionDenied )
   257         if ( aError == KErrNotSupported || aError == KErrPermissionDenied )
   263             {
   258             {
       
   259             // protected file
   264             TRAP_IGNORE( NoteHandler()->ShowDrmNoteL() );
   260             TRAP_IGNORE( NoteHandler()->ShowDrmNoteL() );
   265             }
   261             }
   266         else if( aError != KErrNone && iShowPlaybackFailedNote )
   262         else if( aError != KErrNone && iShowPlaybackFailedNote )
   267             {
   263             {
       
   264             // unknown error -> show general note
   268             // note is shown only once per session
   265             // note is shown only once per session
   269             TRAP_IGNORE( NoteHandler()->ShowPlaybackFailedNoteL() );
   266             TRAP_IGNORE( NoteHandler()->ShowPlaybackFailedNoteL() );
   270             iShowPlaybackFailedNote = EFalse;
   267             iShowPlaybackFailedNote = EFalse;
   271             }
   268             }
   272             
   269             
   273         // inform observer
   270         // inform observer
   274         CommandEvent( UpnpCommand::EEventComplete, aError );
   271         CommandEvent( UpnpCommand::EEventComplete, aError );
   275         }
   272         }
   276         __LOG1( "[UpnpCommand]\t CUpnpShowTask::RenderAck end, resp=%d", aError );
   273     
       
   274     __LOG1( "[UpnpCommand]\t RenderAck end, resp=%d", aError );
       
   275 
   277     return aError;
   276     return aError;
   278     }
   277     }
   279 
   278 
   280 // --------------------------------------------------------------------------
   279 // --------------------------------------------------------------------------
   281 // CUpnpShowTask::EngineShutdown
   280 // CUpnpShowTask::EngineShutdown
   282 // Callback from image rendering engine.
   281 // Callback from image rendering engine.
   283 // --------------------------------------------------------------------------
   282 // --------------------------------------------------------------------------
   284 void CUpnpShowTask::EngineShutdown(
   283 void CUpnpShowTask::EngineShutdown(
   285     TInt aError )
   284     TInt aError )
   286     {
   285     {
   287     __ASSERTD( iRenderingEngine, __FILE__, __LINE__ );
       
   288     
       
   289     if ( iPlayingVideo )
   286     if ( iPlayingVideo )
   290         {
   287         {
   291         __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)\
   288         __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)\
   292 while video playing",
   289 while video playing",
   293             aError );
   290             aError );
   298         __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)",
   295         __LOG1( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown(%d)",
   299             aError );
   296             aError );
   300             
   297             
   301         if( aError == KErrDisconnected )
   298         if( aError == KErrDisconnected )
   302             {
   299             {
       
   300             __ASSERTD( iRenderingEngine, __FILE__, __LINE__ );
       
   301             
   303             // check from rendering engine if wlan is active
   302             // check from rendering engine if wlan is active
   304             // note shown only in device disappeared cases
   303             // note shown only in device disappeared cases
   305             if( iRenderingEngine->IsWlanActive() )
   304             if( iRenderingEngine->IsWlanActive() )
   306                 {
   305                 {
   307                 TRAP_IGNORE( NoteHandler()->ShowConnectionLostNoteL() );
   306                 TRAP_IGNORE( NoteHandler()->ShowConnectionLostNoteL() );
   308                 }
   307                 }
   309             }
   308             }
       
   309         else if( aError == KErrInUse )
       
   310             {
       
   311             // renderer is used by another controlpointš
       
   312             if ( iRenderingSession )
       
   313                 {
       
   314                 TRAP_IGNORE( HBufC* rendererName = UpnpString::ToUnicodeL( 
       
   315                                 iRenderingSession->Device().FriendlyName() );
       
   316                     CleanupStack::PushL( rendererName );
       
   317                     iRenderingSession->Device().FriendlyName();
       
   318                     NoteHandler()->ShowRendererInUseNoteL(*rendererName);
       
   319                     CleanupStack::PopAndDestroy( rendererName );
       
   320                     );
       
   321                 }
       
   322             }  
   310             
   323             
   311             
   324             
   312         // Inform the observer
   325         // Inform the observer
   313         __ASSERTD( TaskHandler(), __FILE__, __LINE__ );
   326         __ASSERT( TaskHandler(), __FILE__, __LINE__ );
   314 
   327 
   315         CommandEvent( UpnpCommand::EEventComplete, aError);
   328         CommandEvent( UpnpCommand::EEventComplete, aError, ETrue );
   316         }
   329         }
   317     __LOG( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown END" );
   330     __LOG( "[UpnpCommand]\t CUpnpShowTask::EngineShutdown END" );
   318     }
   331     }
   319 
   332 
   320 
   333