tsrc/consoleplayer/player/src/externalplayer.cpp
changeset 35 b0f0be18af85
equal deleted inserted replaced
32:106971a9964d 35:b0f0be18af85
       
     1 /*
       
     2  * Copyright (c) 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:
       
    15  * Source file for the main class of the external player executable.
       
    16  * 
       
    17  */
       
    18 
       
    19 #include "externalplayer.h"
       
    20 #include "mmfplayerwindow.h"
       
    21 #include "testappbase.h"
       
    22 
       
    23 // This is the implementation for the external player executable.
       
    24 
       
    25 class CExternalPlayerExe : public CActive
       
    26     {
       
    27 public:
       
    28     
       
    29     static void ExecuteL()
       
    30         {
       
    31         CExternalPlayerExe* self = new(ELeave) CExternalPlayerExe;
       
    32         CleanupStack::PushL( self );
       
    33         self->MainL();
       
    34         CleanupStack::PopAndDestroy( self );    
       
    35         }
       
    36     
       
    37 private:
       
    38     
       
    39     CExternalPlayerExe() : CActive( EPriorityStandard )
       
    40         {
       
    41         CActiveScheduler::Add( this );
       
    42         }
       
    43     
       
    44     ~CExternalPlayerExe()
       
    45         {
       
    46         Cancel();
       
    47         iMsgQueue.Close();
       
    48         iChunk.Close();
       
    49         delete iVideoPlayer;
       
    50         delete iWindowGroup;
       
    51         delete iScreenDevice;
       
    52         iWs.Close();
       
    53         iFs.Close();
       
    54         }
       
    55     
       
    56     void MainL()
       
    57         {
       
    58         TInt err = KErrNone;
       
    59                 
       
    60         User::LeaveIfError( iFs.Connect() );        
       
    61         
       
    62         User::LeaveIfError( iWs.Connect() );    
       
    63         
       
    64         iScreenDevice = new(ELeave) CWsScreenDevice( iWs );
       
    65         User::LeaveIfError( iScreenDevice->Construct() );
       
    66 
       
    67         TBuf<200> commandLine;
       
    68         User::CommandLine( commandLine );
       
    69 
       
    70         TInt startIndex = commandLine.Find(KMsgQueuePrefix);
       
    71         
       
    72         if( startIndex < 0 )
       
    73             {
       
    74             err = startIndex;
       
    75             }
       
    76         else
       
    77             {
       
    78             TPtrC msgQueueName = commandLine.Right( commandLine.Length() - startIndex - KMsgQueuePrefix().Length());
       
    79             err = iMsgQueue.CreateGlobal( msgQueueName, 3 );
       
    80 
       
    81             if( err == KErrNone )
       
    82                 {
       
    83                 TBuf<80> chunkName;
       
    84                 chunkName.Copy( msgQueueName );
       
    85                 chunkName.Append( _L("_chunk") );
       
    86                 err = iChunk.CreateGlobal( chunkName, 2048, 2048 );  // 2K chunk        
       
    87                 }            
       
    88             }
       
    89         
       
    90         RProcess::Rendezvous( err );
       
    91         
       
    92         if( err == KErrNone )
       
    93             {
       
    94             SetActive();
       
    95             iMsgQueue.NotifyDataAvailable( iStatus );
       
    96         
       
    97             CActiveScheduler::Start();
       
    98             }
       
    99         }
       
   100     
       
   101     // inherited from CActive
       
   102     
       
   103     void RunL()
       
   104         {        
       
   105         if( iStatus == KErrNone )
       
   106             {
       
   107             TInt err = KErrNone;
       
   108         
       
   109             TExternalPlayerCommands msg;
       
   110             iMsgQueue.Receive( msg );
       
   111             
       
   112             RDebug::Printf( "EXTERNALPLAYER RunL() msg=%i", msg );
       
   113     
       
   114             switch( msg )
       
   115                 {
       
   116                 case EExternalPlayer_StartPlayback:
       
   117                     {
       
   118                     TStartPlayback* chunk = (TStartPlayback*)iChunk.Base();
       
   119                     
       
   120                     TPtrC8 filename( chunk->name, chunk->length );
       
   121                     iLocation.Copy( filename ); 
       
   122                     iLocationIsFilename = chunk->locationIsFilename;
       
   123                     
       
   124                     iWindowTopRight.iX  = chunk->x;
       
   125                     iWindowTopRight.iY  = chunk->y;
       
   126                     iWindowSize.iWidth  = chunk->width;
       
   127                     iWindowSize.iHeight = chunk->height;
       
   128                     
       
   129                     iWindowGroup = new RWindowGroup( iWs );
       
   130                     err = iWindowGroup->ConstructChildApp( chunk->idOfParentWindowGroup,  
       
   131                                                            KNullWsHandle, 
       
   132                                                            false );
       
   133                     ASSERT( err == KErrNone );   
       
   134                     
       
   135                     TStartPlaybackReturn* chunkReturn = (TStartPlaybackReturn*)iChunk.Base();
       
   136                     
       
   137                     chunkReturn->windowGroupId = iWindowGroup->Identifier();
       
   138                     
       
   139                     iVideoPlayer = CMmfPlayerWindow::NewL( iFs, 
       
   140                                                            iWs, 
       
   141                                                            *iScreenDevice, 
       
   142                                                            *iWindowGroup,
       
   143                                                            iWindowTopRight,
       
   144                                                            iWindowSize,
       
   145                                                            true,  // transparent
       
   146                                                            KRgbTransparent,
       
   147                                                            true );
       
   148                     
       
   149                     if( iLocationIsFilename )
       
   150                         {
       
   151                         iVideoPlayer->StartWithFilenameL( iLocation, CPlayerWindow::EBestFit);
       
   152                         }
       
   153                     else
       
   154                         {
       
   155                         iVideoPlayer->StartWithUrlL( iLocation, CPlayerWindow::EBestFit);                
       
   156                         }
       
   157                     
       
   158                     RDebug::Printf( "EXTERNALPLAYER player started" );
       
   159                     break;
       
   160                     }
       
   161                 case EExternalPlayer_ExecuteOperation:
       
   162                     {
       
   163                     TExecuteOperation* chunk = (TExecuteOperation*)iChunk.Base();
       
   164                     err = iVideoPlayer->ExecuteOperation(chunk->operation );
       
   165                     break;
       
   166                     }
       
   167                 case EExternalPlayer_MoveWindow:
       
   168                     {
       
   169                     TMoveWindow* chunk = (TMoveWindow*)iChunk.Base();
       
   170                     iVideoPlayer->MoveWindow( TPoint(chunk->centerX, chunk->centerY) );
       
   171                     break;
       
   172                     }
       
   173                 case EExternalPlayer_Shutdown:
       
   174                     {
       
   175                     RDebug::Printf( "EXTERNALPLAYER player stopped" );
       
   176                     
       
   177                     CActiveScheduler::Stop();
       
   178                     break;
       
   179                     }
       
   180                 }
       
   181             
       
   182             RProcess::Rendezvous( err );
       
   183             
       
   184             SetActive();
       
   185             iMsgQueue.NotifyDataAvailable( iStatus );
       
   186             }
       
   187         }
       
   188     
       
   189     void DoCancel()
       
   190         {
       
   191         iMsgQueue.CancelDataAvailable();
       
   192         }    
       
   193     
       
   194     RFs                                iFs;
       
   195     RWsSession                         iWs;
       
   196     CWsScreenDevice*                   iScreenDevice; 
       
   197     RWindowGroup*                      iWindowGroup;
       
   198     CPlayerWindow*                     iVideoPlayer;
       
   199     RMsgQueue<TExternalPlayerCommands> iMsgQueue;
       
   200     RChunk                             iChunk;
       
   201     TFileName                          iLocation;
       
   202     bool                               iLocationIsFilename;
       
   203     TPoint                             iWindowTopRight;
       
   204     TSize                              iWindowSize;
       
   205     
       
   206     };
       
   207 
       
   208 GLDEF_C TInt E32Main()
       
   209     {
       
   210     __UHEAP_MARK;
       
   211     
       
   212     CActiveScheduler* scheduler = new CActiveScheduler;
       
   213     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   214     if( scheduler != NULL && cleanup != NULL )
       
   215     {
       
   216         CActiveScheduler::Install( scheduler );
       
   217         TRAP_IGNORE( CExternalPlayerExe::ExecuteL() );
       
   218     }
       
   219     delete cleanup;
       
   220     delete scheduler;
       
   221     __UHEAP_MARKEND;
       
   222     return 0;
       
   223     }
       
   224