upnpframework/upnpcommonui/src/upnpimageplayer.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006 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:  Plays remote images on a renderer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // System
       
    21 #include <aknnotewrappers.h>
       
    22 
       
    23 // upnp stack api
       
    24 #include <upnpobject.h>
       
    25 #include <upnpitem.h>
       
    26 
       
    27 // upnpframework / avcontroller api
       
    28 #include "upnpavcontroller.h"
       
    29 #include "upnpavrenderingsession.h"
       
    30 #include "upnpavdevice.h"
       
    31 
       
    32 // upnpframework / avcontroller helper api
       
    33 #include "upnpitemutility.h"            // ResourceFromItemL
       
    34 
       
    35 // upnpframework / internal api's
       
    36 #include "upnpcdsreselementutility.h"
       
    37 
       
    38 // commonui internal
       
    39 #include "upnpimageplayer.h"
       
    40 #include "upnpdeviceobserver.h"
       
    41 #include <upnpcommonui.rsg>
       
    42 
       
    43 _LIT( KComponentLogfile, "commonui.txt");
       
    44 #include "upnplog.h"
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ============================
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CUpnpAVDevice::CUpnpAVDevice
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CUpnpImagePlayer::CUpnpImagePlayer( MUPnPAVController& aAVControl,
       
    55                                     MUPnPDeviceObserver& aDialog,
       
    56                                     CUPnPCommonUI& aCommonUI ):
       
    57                                     iAVControl(aAVControl),
       
    58                                     iDialog(aDialog),
       
    59                                     iCommonUI(aCommonUI)
       
    60     {    
       
    61     __LOG( "CUpnpImagePlayer::CUpnpImagePlayer" );
       
    62     iImageState = EImageIdle;
       
    63     iFirstStart = ETrue;
       
    64     iAction = CUPnPCommonUI::EUPnPNone;
       
    65     __LOG( "CUpnpImagePlayer::CUpnpImagePlayer end" );
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CUpnpAVDevice::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 void CUpnpImagePlayer::ConstructL()
       
    74     {                        
       
    75     
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CUpnpAVDevice::NewL
       
    80 // Two-phased constructor.
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 CUpnpImagePlayer* CUpnpImagePlayer::NewL( 
       
    84                                     MUPnPAVController& aAVControl,
       
    85                                     MUPnPDeviceObserver& aDialog,
       
    86                                     CUPnPCommonUI& aCommonUI )
       
    87     {
       
    88     __LOG( "CUpnpImagePlayer::NewL" );
       
    89     CUpnpImagePlayer* self = new( ELeave )CUpnpImagePlayer( aAVControl,
       
    90                                                           aDialog,
       
    91                                                           aCommonUI );
       
    92     CleanupStack::PushL(self);
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop( self );
       
    95     __LOG( "CUpnpImagePlayer::NewL end" );
       
    96     return self;
       
    97     }
       
    98 
       
    99 // Destructor
       
   100 CUpnpImagePlayer::~CUpnpImagePlayer()
       
   101     {   
       
   102     __LOG( "CUpnpImagePlayer::~CUpnpImagePlayer" );
       
   103     
       
   104     Stop();
       
   105     delete iUri;
       
   106     __LOG( "CUpnpImagePlayer::~CUpnpImagePlayer end" );
       
   107     }
       
   108 
       
   109 // --------------------------------------------------------------------------
       
   110 // CUpnpAVDevice::SetTargetDeviceL
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 void CUpnpImagePlayer::SetTargetDeviceL( const CUpnpAVDevice& aTargetDevice )
       
   114     {
       
   115     __LOG( "CUpnpImagePlayer::SetTargetDeviceL" );
       
   116     iTargetDevice = &aTargetDevice;  
       
   117     iImageState = EImageIdle;
       
   118     
       
   119     if( iRendSession )
       
   120         {
       
   121         iRendSession->RemoveObserver();
       
   122         iAVControl.StopRenderingSession( *iRendSession );
       
   123         iRendSession = NULL;
       
   124         }
       
   125     iRendSession = &iAVControl.StartRenderingSessionL( *iTargetDevice );
       
   126     iRendSession->SetObserver( *this );
       
   127     
       
   128     __LOG( "CUpnpImagePlayer::SetTargetDeviceL end" );
       
   129     }
       
   130     
       
   131 // --------------------------------------------------------------------------
       
   132 // CUpnpAVDevice::PlayL
       
   133 // --------------------------------------------------------------------------
       
   134 //  
       
   135 void CUpnpImagePlayer::PlayL( const CUpnpObject& aItem )
       
   136     {
       
   137     __LOG( "CUpnpImagePlayer::PlayL" );
       
   138     
       
   139     iAction = CUPnPCommonUI::EUPnPShow;
       
   140     iItem = static_cast<const CUpnpItem*>( &aItem );
       
   141     delete iUri; iUri = NULL;
       
   142 
       
   143     iUri = UPnPItemUtility::ResourceFromItemL( *iItem ).Value().AllocL();
       
   144     
       
   145     if( iImageState == EImageIdle )
       
   146         {
       
   147         if( iFirstStart )
       
   148             {
       
   149             iRendSession->SetURIL( *iUri, *iItem ); //not possible to leave 
       
   150             iImageState = EImageInitialising;
       
   151             delete iUri; iUri = NULL;    
       
   152             }
       
   153         else //stopping previously played item
       
   154             {
       
   155             iRendSession->StopL();
       
   156             iImageState = EImageNext;
       
   157             }
       
   158         }
       
   159     else
       
   160         {
       
   161         iImageState = EImageNext;                
       
   162         }
       
   163 
       
   164     __LOG( "CUpnpImagePlayer::PlayL end" );
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CUpnpAVDevice::Stop
       
   169 // --------------------------------------------------------------------------
       
   170 //  
       
   171 void CUpnpImagePlayer::Stop()
       
   172     {
       
   173     if( iRendSession )
       
   174         {
       
   175         iImageState = EImageIdle;
       
   176         iFirstStart = ETrue;
       
   177         TRAP_IGNORE( iRendSession->StopL() );
       
   178         iRendSession->RemoveObserver();
       
   179         iAVControl.StopRenderingSession( *iRendSession );
       
   180         iRendSession = NULL;      
       
   181         }
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CUpnpAVDevice::InteractOperationComplete
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 void CUpnpImagePlayer::InteractOperationComplete( 
       
   189               TInt aError,
       
   190               TUPnPAVInteractOperation aOperation 
       
   191               )
       
   192     {
       
   193     __LOG2( "CUpnpImagePlayer::InteractOperationComplete: %d, %d",
       
   194         aError, aOperation );
       
   195     TRAP_IGNORE( InteractOperationCompleteL( aError, aOperation ) );
       
   196     }
       
   197 
       
   198 // --------------------------------------------------------------------------
       
   199 // CUpnpAVDevice::InteractOperationCompleteL
       
   200 // --------------------------------------------------------------------------
       
   201 //
       
   202 void CUpnpImagePlayer::InteractOperationCompleteL( 
       
   203               TInt aError,
       
   204               TUPnPAVInteractOperation aOperation 
       
   205               )
       
   206     {
       
   207     iCommonUI.HandleCommonErrorL( aError, NULL );
       
   208     
       
   209     switch( aOperation )
       
   210         {
       
   211         case EUPnPAVPlay:
       
   212             {
       
   213             if( iFirstStart )
       
   214                 {
       
   215                 iFirstStart = EFalse;    
       
   216                 }
       
   217             
       
   218             if( iImageState == EImageNext ) //if still there is a pending item
       
   219                 {                           //stop current showing item
       
   220                 iRendSession->StopL();
       
   221                 }
       
   222             else
       
   223                 {
       
   224                 iImageState = EImageIdle;
       
   225                 }
       
   226             }
       
   227             break;
       
   228         case EUPnPAVStop:
       
   229             {
       
   230             if( iUri && iImageState == EImageNext )
       
   231                 {
       
   232                 iAction = CUPnPCommonUI::EUPnPShow;
       
   233                 iRendSession->SetURIL( *iUri, *iItem );
       
   234                 iImageState = EImageInitialising;
       
   235                 delete iUri; iUri = NULL;    
       
   236                 }
       
   237             }
       
   238             break;
       
   239         }
       
   240     }
       
   241 
       
   242 // --------------------------------------------------------------------------
       
   243 // CUpnpAVDevice::SetURIResult
       
   244 // --------------------------------------------------------------------------
       
   245 //
       
   246 void CUpnpImagePlayer::SetURIResult( TInt aError )
       
   247     {
       
   248     __LOG1( "CUpnpImagePlayer::SetURIResult: %d", aError );
       
   249     
       
   250     TRAP_IGNORE( SetURIResultL( aError ) );
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // CUpnpAVDevice::SetURIResultL
       
   255 // --------------------------------------------------------------------------
       
   256 //   
       
   257 void CUpnpImagePlayer::SetURIResultL( TInt aError )
       
   258     {
       
   259     iCommonUI.GetUpnpAction( iAction );
       
   260     iCommonUI.HandleCommonErrorL( aError, NULL );
       
   261     if( iImageState == EImageNext ) //if there is another pending item
       
   262         {
       
   263         if( iUri )
       
   264             {
       
   265             iRendSession->SetURIL( *iUri, *iItem ); //not possible to leave
       
   266             iImageState = EImageInitialising;
       
   267             delete iUri; iUri = NULL;    
       
   268             }
       
   269         else
       
   270             {
       
   271             iImageState = EImageIdle;
       
   272             iCommonUI.GetUpnpAction( iAction );
       
   273             iCommonUI.HandleCommonErrorL( KErrNotFound, NULL );            
       
   274             }
       
   275         }
       
   276     else //if no pending item
       
   277         {
       
   278         if( KErrNone == aError )
       
   279             {
       
   280             iRendSession->PlayL(); //not possible to leave
       
   281             iImageState = EImageShowing;
       
   282             }
       
   283         else
       
   284             {
       
   285             iImageState = EImageIdle;
       
   286             }
       
   287         }
       
   288     }
       
   289 
       
   290 // --------------------------------------------------------------------------
       
   291 // CUpnpAVDevice::PlayL
       
   292 // --------------------------------------------------------------------------
       
   293 //
       
   294 void CUpnpImagePlayer::MediaRendererDisappeared( 
       
   295                                  TUPnPDeviceDisconnectedReason aReason )
       
   296     {
       
   297     if( aReason == EDisconnected )
       
   298         {
       
   299         iDialog.DeviceDisappeared( KErrSessionClosed );
       
   300         }
       
   301     
       
   302     }
       
   303     
       
   304 // End of File
       
   305