dvrengine/CommonRecordingEngine/src/CCREngine.cpp
branchRCL_3
changeset 23 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
22:826cea16efd9 23:13a33d82ad98
       
     1 /*
       
     2 * Copyright (c) 2007 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 the License "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:    Engine part of the engine. In practice keeps count on*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <pathinfo.h>
       
    22 #include "VideoServiceUtilsConf.hrh" 
       
    23 #include "CCREngine.h"
       
    24 #include "CCRStreamingSession.h"
       
    25 #include "CCRSession.h"
       
    26 #include "CCRClientInformer.h"
       
    27 #include "CCRConnection.h"
       
    28 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    29 #include <ipvideo/CRtpUtil.h>
       
    30 #include <ipvideo/CRtpClipHandler.h>
       
    31 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    32 #include <e32msgqueue.h>
       
    33 #include <ipvideo/CRTypeDefs.h>
       
    34 #include <e32std.h>
       
    35 #include <es_sock.h>
       
    36 #include "videoserviceutilsLogger.h"
       
    37 
       
    38 // CONSTANTS
       
    39 const TUint KCRELoopbackPortStart( 1106 );
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CCREngine::NewL
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CCREngine* CCREngine::NewL( void )
       
    49     {
       
    50     CCREngine* self = new( ELeave ) CCREngine();
       
    51 
       
    52     // Use CleanupClosePushL to make sure the Close function defined in CObject
       
    53     // base class gets called. CObject will delete itself once its reference count
       
    54     // reaches zero. Using CleanupStack::PushL here results in E32USER-CBase panic 33
       
    55     // if there is a leave somewhere in construction
       
    56     CleanupClosePushL( *self );
       
    57 
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CCREngine::CCREngine
       
    65 // C++ default constructor can NOT contain any code, that might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CCREngine::CCREngine( void ) : iLoopbackPort( KCRELoopbackPortStart )
       
    69     {
       
    70     // None
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCREngine::ConstructL
       
    75 // Symbian 2nd phase constructor can leave.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CCREngine::ConstructL()
       
    79     {
       
    80     LOG( "CCREngine::ConstructL()" );
       
    81     
       
    82     // Note, quite high priority
       
    83     iCleanUp = new ( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); 
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCREngine::~CCREngine
       
    88 // Destructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CCREngine::~CCREngine()
       
    92     {
       
    93     LOG( "CCREngine::~CCREngine()" );
       
    94 
       
    95     delete iCleanUp;
       
    96     iSessions.ResetAndDestroy();
       
    97     iSessionsToDelete.Reset(); 
       
    98     delete iConnection;
       
    99 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   100     delete iClipHandler;
       
   101 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   102     iSockServer.Close(); 
       
   103     delete iInformer; 
       
   104     delete iQueueName;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // Method for actual message handling.
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CCREngine::GeneralServiceL( const RMessage2& aMessage )
       
   113     {
       
   114 #if defined( LIVE_TV_RDEBUG_TRACE ) || defined( LIVE_TV_FILE_TRACE )
       
   115     if ( aMessage.Function() != ECRGetPosition )
       
   116         {
       
   117         LOG1( "CCREngine::GeneralService(), aMessage: %d", aMessage.Function() );
       
   118         }
       
   119 #endif // LIVE_TV_RDEBUG_TRACE || LIVE_TV_FILE_TRACE
       
   120 
       
   121     // Verify cababilities
       
   122     VerifyCapabilitiesL( aMessage );
       
   123 
       
   124     // Handle message
       
   125     TInt err( KErrNone );
       
   126     switch( aMessage.Function() )
       
   127         {
       
   128         case ECRSetIap:
       
   129             {
       
   130             TPckgBuf<SCRRtspIapParams> pckg;
       
   131             Read( aMessage, 0, pckg );
       
   132             err = SetConnectionId( pckg() );  
       
   133             aMessage.Complete( err );
       
   134             }
       
   135             break;      
       
   136             
       
   137         case ECRCancelSetIap:
       
   138             aMessage.Complete( CancelSetConnectionId() );
       
   139             break;
       
   140             
       
   141         case ECRPlayRtspUrl:
       
   142             {
       
   143             TPckgBuf<TUint> pckg0( 0 );
       
   144             TPckgBuf<SCRRtspParams> pckg1;
       
   145             Read( aMessage, 1, pckg1 );
       
   146             TRAP( err, pckg0() = PlayRtspUrlL( pckg1() ) );
       
   147             if ( !err )
       
   148                 {
       
   149                 Write( aMessage, 0, pckg0 );
       
   150                 }
       
   151             aMessage.Complete( err );
       
   152             }
       
   153             break;      
       
   154             
       
   155         case ECRPlayDvbhLive:
       
   156             {
       
   157             TPckgBuf<TUint> pckg0( 0 );
       
   158             TPckgBuf<SCRLiveParams> pckg1;
       
   159             Read( aMessage, 1, pckg1 );
       
   160             TRAP( err, pckg0() = PlayDvbhLiveL( pckg1() ) );
       
   161             if ( !err )    
       
   162                 {
       
   163                 Write( aMessage, 0, pckg0 );
       
   164                 }
       
   165             aMessage.Complete( err );
       
   166             }
       
   167             break;      
       
   168             
       
   169         case ECRChangeService:
       
   170             {
       
   171             TPckgBuf<TUint> pckg0( 0 );
       
   172             TPckgBuf<SCRLiveParams> pckg1;
       
   173             Read( aMessage, 0, pckg0 );
       
   174             Read( aMessage, 1, pckg1 );
       
   175             TRAP( err, pckg0() = ChangeDvbhServiceL( pckg0(), pckg1() ) );
       
   176             if ( !err )    
       
   177                 {
       
   178                 Write( aMessage, 0, pckg0 );
       
   179                 }
       
   180             aMessage.Complete( err );
       
   181             }
       
   182             break;
       
   183             
       
   184         case ECRPlayRtpFile:
       
   185             {
       
   186             TPckgBuf<TUint> pckg0( 0 );
       
   187             TPckgBuf<SCRRtpPlayParams> pckg1;
       
   188             Read( aMessage, 1, pckg1 );
       
   189             TRAP( err, pckg0() = PlayRtpFileL( pckg1() ) );
       
   190             if ( !err )
       
   191                 {
       
   192                 Write( aMessage, 0, pckg0 );
       
   193                 }
       
   194             aMessage.Complete( err );
       
   195             }
       
   196             break;      
       
   197             
       
   198         case ECRPlayRtpHandle:
       
   199             {
       
   200             RFile fileHandle;
       
   201             err = fileHandle.AdoptFromClient( aMessage, 1, 2 );
       
   202             if ( !err )
       
   203                 {
       
   204                 TPckgBuf<TUint> pckg( 0 );
       
   205                 TRAP( err, pckg() = PlayRtpFileL( fileHandle ) );
       
   206                 if ( !err )
       
   207                     {
       
   208                     Write( aMessage, 0, pckg );
       
   209                     }
       
   210                 }
       
   211             fileHandle.Close();
       
   212             aMessage.Complete( err );
       
   213             }
       
   214             break;      
       
   215             
       
   216         case ECRRecordCurrentStream:
       
   217             {
       
   218             TPckgBuf<TUint> pckg0( 0 );
       
   219             Read( aMessage, 0, pckg0 );
       
   220             TPckgBuf<SCRRecordParams> pckg1;
       
   221             Read( aMessage, 1, pckg1 );
       
   222             TRAP( err, RecordCurrentStreamL( pckg0(), pckg1() ) );
       
   223             aMessage.Complete( err );
       
   224             }
       
   225             break;
       
   226             
       
   227         case ECRRecordRtspStream:
       
   228             {
       
   229             TPckgBuf<TUint> pckg0( 0 );
       
   230             TPckgBuf<SCRRtspParams> pckg1;
       
   231             Read( aMessage, 1, pckg1 );
       
   232             TPckgBuf<SCRRecordParams> pckg2;
       
   233             Read( aMessage, 2, pckg2 );
       
   234             TRAP( err, pckg0() = RecordRtspStreamL( pckg1(), pckg2() ) );
       
   235             aMessage.Complete( err );
       
   236             }
       
   237             break;
       
   238             
       
   239         case ECRRecordDvbhStream:
       
   240             {
       
   241             TPckgBuf<TUint> pckg0( 0 );
       
   242             TPckgBuf<SCRLiveParams> pckg1;
       
   243             Read( aMessage, 1, pckg1 );
       
   244             TPckgBuf<SCRRecordParams> pckg2;
       
   245             Read( aMessage, 2, pckg2 );
       
   246             TRAP( err, pckg0() = RecordDvbhStreamL( pckg1(), pckg2() ) );
       
   247             aMessage.Complete( err );
       
   248             }
       
   249             break;
       
   250             
       
   251         case ECRPauseRecordStream:
       
   252             {
       
   253             TPckgBuf<TUint> pckg0( 0 );
       
   254             Read( aMessage, 0, pckg0 );
       
   255             TPckgBuf<TBool> pckg1( 0 );
       
   256             Read( aMessage, 1, pckg1 );
       
   257             aMessage.Complete( PauseRecordStream( pckg0(), pckg1() ) );
       
   258             }
       
   259             break;
       
   260             
       
   261         case ECRStopRecordStream:
       
   262             {
       
   263             TPckgBuf<TUint> pckg0( 0 );
       
   264             Read( aMessage, 0, pckg0 );
       
   265             aMessage.Complete( StopRecordStream( pckg0() ) );
       
   266             }
       
   267             break;
       
   268             
       
   269         case ECRStartTimeShift:
       
   270             {
       
   271             TPckgBuf<TUint> pckg0( 0 );
       
   272             TPckgBuf<TUint> pckg1( 0 );
       
   273             Read( aMessage, 1, pckg1 );
       
   274             TRAP( err, pckg0() = StartTimeShiftL( pckg1() ) );
       
   275             if ( !err )
       
   276                 {
       
   277                 Write( aMessage, 0, pckg0 );
       
   278                 }
       
   279             aMessage.Complete( err );
       
   280             }
       
   281             break;
       
   282             
       
   283         case ECRStopTimeShift:
       
   284             {
       
   285             TPckgBuf<TUint> pckg0( 0 );
       
   286             TPckgBuf<TUint> pckg1( 0 );
       
   287             Read( aMessage, 0, pckg0 );
       
   288             Read( aMessage, 1, pckg1 );
       
   289             aMessage.Complete( StopTimeShift( pckg0(), pckg1() ) );
       
   290             }
       
   291             break;
       
   292             
       
   293         case ECRPlayCommand:
       
   294             {
       
   295             TPckgBuf<TUint> pckg0( 0 );
       
   296             Read( aMessage, 0, pckg0 );
       
   297             TPckgBuf<TInt64> pckg1( 0 );
       
   298             Read( aMessage, 1, pckg1 );
       
   299             TPckgBuf<TInt64> pckg2( 0 );
       
   300             Read( aMessage, 2, pckg2 );
       
   301             aMessage.Complete( PlayCommand( pckg0(), pckg1(), pckg2() ) );
       
   302             }
       
   303             break;
       
   304         
       
   305         case ECRPauseCommand:
       
   306             {
       
   307             TPckgBuf<TUint> pckg0( 0 );
       
   308             Read( aMessage, 0, pckg0 );
       
   309             aMessage.Complete( PauseCommand( pckg0() ) );
       
   310             }
       
   311             break;
       
   312         
       
   313         case ECRStopCommand:
       
   314             {
       
   315             TPckgBuf<TUint> pckg0( 0 );
       
   316             Read( aMessage, 0, pckg0 );
       
   317             aMessage.Complete( StopCommand( pckg0() ) );
       
   318             }
       
   319             break;
       
   320         
       
   321         case ECRSetPosition:
       
   322             {
       
   323             TPckgBuf<TUint> pckg0( 0 );
       
   324             Read( aMessage, 0, pckg0 );
       
   325             TPckgBuf<TInt64> pckg1( 0 );
       
   326             Read( aMessage, 1, pckg1 );
       
   327             err = SetPosition( pckg0(), pckg1() );
       
   328             aMessage.Complete( err );
       
   329             }
       
   330             break;
       
   331         
       
   332         case ECRGetPosition:
       
   333             {
       
   334             TPckgBuf<TUint> pckg0( 0 );
       
   335             Read( aMessage, 0, pckg0 );
       
   336             TPckgBuf<TInt64> pckg1( 0 );
       
   337             Read( aMessage, 1, pckg1 );
       
   338             TPckgBuf<TInt64> pckg2( 0 );
       
   339             err = GetPosition( pckg0(), pckg1(), pckg2() );
       
   340             Write( aMessage, 1, pckg1 );
       
   341             Write( aMessage, 2, pckg2 );
       
   342             aMessage.Complete( err );
       
   343             }
       
   344             break;
       
   345             
       
   346         case ECRCloseSession:
       
   347             {
       
   348             TPckgBuf<TUint> pckg0( 0 );
       
   349             Read( aMessage, 0, pckg0 );
       
   350             aMessage.Complete( CloseSession( pckg0() ) );
       
   351             }
       
   352             break;
       
   353         
       
   354         case ECRPlayNullSource:
       
   355             {
       
   356             TPckgBuf<TUint> pckg0( 0 );
       
   357             TRAP( err, pckg0() = PlayNullSourceL() );
       
   358             Write( aMessage, 0, pckg0 );
       
   359             aMessage.Complete( err );
       
   360             }
       
   361             break;     
       
   362         
       
   363         case ECRPlayRtspUrlToNullSink:
       
   364             {
       
   365             TPckgBuf<TUint> pckg0( 0 );
       
   366             TPckgBuf<SCRRtspParams> pckg1;
       
   367             Read( aMessage, 1, pckg1 );
       
   368             TRAP( err, pckg0() = PlayRtspUrlToNullSinkL( pckg1() ) );
       
   369             Write( aMessage, 0, pckg0 );
       
   370             aMessage.Complete( err );
       
   371             }
       
   372             break;     
       
   373         
       
   374         default:
       
   375             aMessage.Complete( KErrNotSupported ); 
       
   376             break; 
       
   377         }
       
   378     }
       
   379     
       
   380 //-----------------------------------------------------------------------------
       
   381 // CCREngine::SessionStop()
       
   382 // So, a session wants to quit. we can't just delete it here as return.
       
   383 // Statement would then take us to deleted instance: put up a cleanup 
       
   384 // CAsyncCallBack and return.
       
   385 //-----------------------------------------------------------------------------
       
   386 //
       
   387 void CCREngine::SessionStop( CCRStreamingSession* aSession )
       
   388     {
       
   389     LOG1( "CCREngine::SessionStop(), Delete count: %d", iSessionsToDelete.Count() );    
       
   390 
       
   391     // InsertInAddressOrder checks for duplicate, if there is already
       
   392     // entry for that session, the array will remain unchanged
       
   393     TRAPD( err, iSessionsToDelete.InsertInAddressOrderL( aSession ) ); 
       
   394     if ( err )
       
   395         {
       
   396         LOG1( "CCREngine::SessionStop(), InsertInAddressOrder leaved: %d", err );      
       
   397         }
       
   398 
       
   399     // If not already active and sessions to delete?
       
   400     if ( !iCleanUp->IsActive() && iSessionsToDelete.Count() ) 
       
   401         {
       
   402         TCallBack cb( SessionStopCallBack, this );
       
   403         iCleanUp->Set( cb );
       
   404         iCleanUp->CallBack();
       
   405         }               
       
   406     }
       
   407     
       
   408 // -----------------------------------------------------------------------------
       
   409 // CCREngine::ConnectionStatusChange
       
   410 //
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 void CCREngine::ConnectionStatusChange(
       
   414     TInt aSessionId,
       
   415     TCRConnectionStatus aStatus,
       
   416     TInt aErr )
       
   417     {
       
   418     LOG3( "CCREngine::ConnectionStatusChange(), aSessionId: %d, aStatus: %d, Error: %d",
       
   419                                                 aSessionId, aStatus, aErr );
       
   420     
       
   421     SCRQueueEntry entry = { ECRMsgQueueConnectionError, KErrNone };
       
   422     entry.iSessionId = aSessionId;
       
   423 
       
   424     switch ( aStatus )
       
   425         {           
       
   426         case ECRConnectionError:
       
   427             {               
       
   428             entry.iMsg = ECRMsgQueueConnectionError;
       
   429             entry.iErr = aErr;
       
   430             }
       
   431             break;
       
   432         
       
   433         case ECRAuthenticationNeeded:
       
   434             {               
       
   435             entry.iMsg = ECRMsgQueueAuthenticationNeeded;
       
   436             entry.iErr = KErrNone;
       
   437             }      
       
   438             break;  
       
   439         
       
   440         case ECRNotEnoughBandwidth:
       
   441             {               
       
   442             entry.iMsg = ECRMsgQueueNotEnoughBandwidth;
       
   443             entry.iErr = KErrNone;
       
   444             }      
       
   445             break;  
       
   446         
       
   447         case ECRNormalEndOfStream:
       
   448             {               
       
   449             entry.iMsg = ECRMsgQueueNormalEndOfStream;
       
   450             entry.iErr = aErr;
       
   451             }
       
   452             break;
       
   453         
       
   454         case ECRAttachCompleted: // fall through
       
   455         case ECRSwitchingToTcp:
       
   456             {               
       
   457             aStatus == ECRAttachCompleted ? 
       
   458                            ( entry.iMsg = ECRMsgQueueAttachCompleted ) :
       
   459                            ( entry.iMsg = ECRMsgQueueSwitchingToTcp );
       
   460             
       
   461             if ( aErr == KErrNone )
       
   462                 {
       
   463                 // Releasing RSocket takes almost 40 seconds so we need 
       
   464                 // to always use different port number, otherwise an  
       
   465                 // "Already in use" error will be occurred.
       
   466                 TTime now;
       
   467                 now.UniversalTime();                  
       
   468                 TInt port = KCRELoopbackPortStart + now.DateTime().Second();   
       
   469                 iLoopbackPort == port ? ( iLoopbackPort = port + 1 ) : 
       
   470                                         ( iLoopbackPort = port );
       
   471 
       
   472                 // Loopback port for VIA
       
   473                 entry.iErr = iLoopbackPort;
       
   474                 }
       
   475             else
       
   476                 {
       
   477                 entry.iErr = aErr;
       
   478                 }
       
   479             }           
       
   480             break;  
       
   481             
       
   482         case ECRStreamIsLiveStream:
       
   483             {
       
   484             entry.iMsg = ECRMsgQueueStreamIsLiveStream; 
       
   485             entry.iErr = aErr; 
       
   486             }
       
   487             break; 
       
   488 
       
   489         case ECRStreamIsRealMedia:
       
   490             {
       
   491             entry.iMsg = ECRMsgQueueStreamIsRealMedia; 
       
   492             entry.iErr = aErr; 
       
   493             }
       
   494             break; 
       
   495 
       
   496         case ECRBearerChanged:
       
   497             {
       
   498             // Nobody is interested about this on the other side...
       
   499             return;         
       
   500             }
       
   501 
       
   502         case ECRTestSinkData:
       
   503             {
       
   504             entry.iMsg = ECRMsgQueueTestSinkData;
       
   505             entry.iErr = aErr;
       
   506             }
       
   507             break;
       
   508 
       
   509         case ECRSdpAvailable:
       
   510             {
       
   511             entry.iMsg = ECRMsgQueueSdpAvailable;
       
   512             entry.iErr = aErr;
       
   513             }
       
   514             break;
       
   515         
       
   516         case ECRReadyToSeek:
       
   517             {
       
   518             entry.iMsg = ECRMsgQueueReadyToSeek; 
       
   519             entry.iErr = aErr; 
       
   520             }
       
   521             break; 
       
   522 
       
   523         case ECRRecordingStarted:
       
   524             {
       
   525             entry.iMsg = ECRMsgQueueRecordingStarted;
       
   526             entry.iErr = aErr;
       
   527             }
       
   528             break;
       
   529         
       
   530         case ECRRecordingPaused:
       
   531             {
       
   532             entry.iMsg = ECRMsgQueueRecordingPaused;
       
   533             entry.iErr = aErr;
       
   534             }
       
   535             break;
       
   536         
       
   537         case ECRRecordingEnded:
       
   538             {
       
   539             entry.iMsg = ECRMsgQueueRecordingEnded;
       
   540             entry.iErr = aErr;
       
   541             }
       
   542             break;
       
   543         
       
   544         default:
       
   545             // None
       
   546             break;
       
   547         }
       
   548     
       
   549     if ( iQueueName && iInformer )
       
   550         {
       
   551         iInformer->SendMessage( iQueueName->Des(), entry ); 
       
   552         }
       
   553     }
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CCREngine::VerifyCapabilitiesL
       
   557 // Checks capabilities of user of DVR API.
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CCREngine::VerifyCapabilitiesL( const RMessage2& aMessage )
       
   561     {
       
   562     if ( !aMessage.HasCapability( ECapabilityNetworkServices, 
       
   563          __PLATSEC_DIAGNOSTIC_STRING( "NetworkServices" ) ) )
       
   564         {
       
   565         LOG( "CCREngine::VerifyRbfCapabilitiesL(), Missing: NetworkServices !" );
       
   566         User::Leave( KErrPermissionDenied );
       
   567 	    }
       
   568     
       
   569     if ( !aMessage.HasCapability( ECapabilityReadUserData,
       
   570          __PLATSEC_DIAGNOSTIC_STRING( "ReadUserData" ) ) )
       
   571 	    {
       
   572         LOG( "CCREngine::VerifyRbfCapabilitiesL(), Missing: ReadUserData !" );
       
   573         User::Leave( KErrPermissionDenied );
       
   574 	    }
       
   575                                  
       
   576     if ( !aMessage.HasCapability( ECapabilityWriteUserData,
       
   577          __PLATSEC_DIAGNOSTIC_STRING( "WriteUserData" ) ) )
       
   578 	    {
       
   579         LOG( "CCREngine::VerifyRbfCapabilitiesL(), Missing: WriteUserData !" );
       
   580         User::Leave( KErrPermissionDenied );
       
   581 	    }
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // CCREngine::SetConnectionId
       
   586 //
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 TInt CCREngine::SetConnectionId( const SCRRtspIapParams& aIap ) 
       
   590     {
       
   591     LOG( "CCREngine::SetConnectionId() in" );
       
   592 
       
   593     TRAPD ( err, CreateConnectionL() ) ;
       
   594     if ( err == KErrNone )
       
   595         {
       
   596         delete iQueueName; iQueueName = NULL;
       
   597         TRAP( err, iQueueName = aIap.iQueueName.AllocL() );
       
   598         if ( err == KErrNone )
       
   599             {
       
   600             iConnection->Attach( aIap.iConnectionId );  
       
   601             }
       
   602         
       
   603         }
       
   604     LOG1( "CCREngine::SetConnectionId() out, err: %d", err );
       
   605     return err;
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CCREngine::CancelSetConnectionId
       
   610 //
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 TInt CCREngine::CancelSetConnectionId() 
       
   614     {
       
   615     LOG( "CCREngine::CancelSetConnectionId() in" );
       
   616     
       
   617     TInt err( KErrNone );
       
   618     if ( iConnection ) 
       
   619         {
       
   620         iSessions.ResetAndDestroy();
       
   621         delete iConnection; iConnection = NULL;
       
   622         iSockServer.Close(); 
       
   623         err = iSockServer.Connect( KESockDefaultMessageSlots * 3 );
       
   624         if ( err == KErrNone ) 
       
   625             {
       
   626             TRAP( err, iConnection = CCRConnection::NewL( iSockServer ) );
       
   627             if ( err == KErrNone && iConnection )
       
   628                 {
       
   629                 err = iConnection->RegisterObserver( this );                    
       
   630                 }
       
   631             }
       
   632         }
       
   633     
       
   634     LOG1( "CCREngine::CancelSetConnectionId() out, err: %d", err );
       
   635     return err; 
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CCREngine::PlayRtspUrlL
       
   640 // Go through stream sessions and try to find if given url is already playing.
       
   641 // If not, create new RTSP session and add sink to it.
       
   642 // -----------------------------------------------------------------------------
       
   643 //
       
   644 TUint CCREngine::PlayRtspUrlL( const SCRRtspParams& aRtspParams ) 
       
   645     {
       
   646     LOG( "CCREngine::PlayRtspUrlL() in" );
       
   647     
       
   648     const TInt sessionIndex( VerifyRtspSessionL( aRtspParams ) );
       
   649     iSessions[sessionIndex]->CreateRtspSinkL( iLoopbackPort );
       
   650     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   651     LOG1( "CCREngine::PlayRtspUrlL() out, sessionChk: %d", sessionChk );
       
   652     return sessionChk;
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CCREngine::PlayDvbhLiveL
       
   657 // Go through stream sessions and try to find if current service is already
       
   658 // If not, create new DVB-H session and add sink to it.
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 TUint CCREngine::PlayDvbhLiveL( const SCRLiveParams& aLiveParams ) 
       
   662     {
       
   663     LOG( "CCREngine::PlayDvbhLiveL() in" );
       
   664 
       
   665     const TInt sessionIndex( VerifyDvbhSessionL( aLiveParams ) );
       
   666     iSessions[sessionIndex]->CreateXpsSinkL();
       
   667     iSessions[sessionIndex]->PostActionL();
       
   668     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   669     LOG1( "CCREngine::PlayDvbhLiveL() out, sessionChk: %d", sessionChk );
       
   670     return sessionChk;
       
   671     }
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 // CCREngine::ChangeDvbhServiceL
       
   675 // Go through stream sessions and try to find if current service is already
       
   676 // If not, create new DVB-H session and add sink to it.
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 TUint CCREngine::ChangeDvbhServiceL(
       
   680     const TUint aSessionChk,
       
   681     const SCRLiveParams& aLiveParams ) 
       
   682     {
       
   683     LOG( "CCREngine::ChangeDvbhServiceL() in" );
       
   684 
       
   685     // Verify exist session
       
   686     const TInt currentSession( VerifySession( aSessionChk ) );
       
   687     User::LeaveIfError( currentSession );
       
   688     
       
   689     // Can't perform if recording or timeshift ongoing
       
   690     if ( iSessions[currentSession]->ClipHandlerUsed() )
       
   691         {
       
   692         User::Leave( KErrInUse );
       
   693         }
       
   694 
       
   695     // New session for new service
       
   696     const TInt sessionIndex( VerifyDvbhSessionL( aLiveParams ) );
       
   697     if ( sessionIndex == currentSession )
       
   698         {
       
   699         // Same service, no actions
       
   700         return aSessionChk;
       
   701         }
       
   702     
       
   703     // Stop sockets of DVB-H source (filters released)
       
   704     User::LeaveIfError( iSessions[currentSession]->StopCommand() );
       
   705     
       
   706     // Transfer ownership of existing XPS sink to a new session
       
   707     User::LeaveIfError( iSessions[currentSession]->TransferSink( 
       
   708         CCRStreamingSession::ECRXpsSinkId, *iSessions[sessionIndex] ) );
       
   709     iSessions[sessionIndex]->PostActionL();
       
   710     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   711     
       
   712     // Delete existing unused session
       
   713     SessionStop( iSessions[currentSession] );
       
   714     LOG1( "CCREngine::ChangeDvbhServiceL() out, sessionChk: %d", sessionChk );
       
   715     return sessionChk;
       
   716     }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CCREngine::PlayRtpFileL
       
   720 //
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 TUint CCREngine::PlayRtpFileL( const SCRRtpPlayParams& aRtpParams ) 
       
   724     {
       
   725     LOG( "CCREngine::PlayRtpFileL() in" );
       
   726 
       
   727     const TInt sessionIndex( VerifyRtpFileSessionL( aRtpParams ) );
       
   728     iSessions[sessionIndex]->CreateXpsSinkL();
       
   729     iSessions[sessionIndex]->PostActionL();
       
   730     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   731     LOG1( "CCREngine::PlayRtpFileL() out, sessionChk: %d", sessionChk );
       
   732     return sessionChk;
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // CCREngine::PlayRtpFileL
       
   737 //
       
   738 // -----------------------------------------------------------------------------
       
   739 //
       
   740 TUint CCREngine::PlayRtpFileL( const RFile& aFileHandle ) 
       
   741     {
       
   742     LOG( "CCREngine::PlayRtpFileL() in, with hadle" );
       
   743 
       
   744     TInt sessionIndex( VerifyRtpFileSessionL( aFileHandle ) );
       
   745     iSessions[sessionIndex]->CreateXpsSinkL();
       
   746     iSessions[sessionIndex]->PostActionL();
       
   747     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   748     LOG1( "CCREngine::PlayRtpFileL() out, sessionChk: %d", sessionChk );
       
   749     return sessionChk;
       
   750     }
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CCREngine::RecordCurrentStreamL
       
   754 //
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 void CCREngine::RecordCurrentStreamL(
       
   758     const TUint aSessionChk,
       
   759     const SCRRecordParams& aRecordParams ) 
       
   760     {
       
   761     LOG1( "CCREngine::StartRecordStreamL() in, aSessionChk: %d", aSessionChk );
       
   762 
       
   763     // Verify session
       
   764     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
   765         
       
   766     // Session exist?
       
   767     if ( sessionIndex > KErrNotFound )
       
   768         {
       
   769         CreateRecordingSinkL( sessionIndex, aRecordParams );
       
   770         iSessions[sessionIndex]->PostActionL();
       
   771         }
       
   772 
       
   773     LOG1( "CCREngine::StartRecordStreamL() out, sessionIndex: %d", sessionIndex );
       
   774     }
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // CCREngine::RecordRtspStreamL
       
   778 //
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 TUint CCREngine::RecordRtspStreamL(
       
   782     const SCRRtspParams& aRtspParams,
       
   783     const SCRRecordParams& aRecordParams ) 
       
   784     {
       
   785     LOG( "CCREngine::RecordRtspStreamL() in" );
       
   786 
       
   787     // Verify session
       
   788     const TInt sessionIndex( VerifyRtspSessionL( aRtspParams ) );
       
   789 
       
   790     // Recording sink
       
   791     CreateRecordingSinkL( sessionIndex, aRecordParams );
       
   792     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   793     LOG1( "CCREngine::RecordRtspStreamL() out, sessionChk: %d", sessionChk );
       
   794     return sessionChk;
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // CCREngine::RecordDvbhStreamL
       
   799 //
       
   800 // -----------------------------------------------------------------------------
       
   801 //
       
   802 TUint CCREngine::RecordDvbhStreamL(
       
   803     const SCRLiveParams& aLiveParams,
       
   804     const SCRRecordParams& aRecordParams ) 
       
   805     {
       
   806     LOG( "CCREngine::RecordDvbhStreamL() in" );
       
   807 
       
   808     // Verify session
       
   809     const TInt sessionIndex( VerifyDvbhSessionL( aLiveParams ) );
       
   810 
       
   811     // Recording sink
       
   812     CreateRecordingSinkL( sessionIndex, aRecordParams );
       
   813     iSessions[sessionIndex]->PostActionL();
       
   814     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
   815     LOG1( "CCREngine::RecordDvbhStreamL() out, sessionChk: %d", sessionChk );
       
   816     return sessionChk;
       
   817     }
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CCREngine::PauseRecordStream
       
   821 //
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 TInt CCREngine::PauseRecordStream( const TUint aSessionChk, const TBool& aStart ) 
       
   825     {
       
   826     LOG2( "CCREngine::PauseRecordStream() in, aSessionChk: %d, aStart: %d", 
       
   827                                               aSessionChk, aStart );
       
   828     // Verify session
       
   829     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
   830         
       
   831     // Session exist?
       
   832     if ( sessionIndex > KErrNotFound )
       
   833         {
       
   834         TInt err( KErrNone );
       
   835         if ( aStart )
       
   836             {
       
   837             // Clip format not known, so all types must try to pause
       
   838             err = iSessions[sessionIndex]->PauseCommand(
       
   839                   CCRStreamingSession::ECRRtpRecSinkId );
       
   840             if ( err == KErrCompletion )
       
   841                 {
       
   842                 err = iSessions[sessionIndex]->PauseCommand(
       
   843                       CCRStreamingSession::ECR3gpRecSinkId );
       
   844                 }
       
   845             
       
   846             ConnectionStatusChange( aSessionChk, ECRRecordingPaused, err );
       
   847             }
       
   848         else
       
   849             {
       
   850             // Clip format not known, so all types must try to pause
       
   851             err = iSessions[sessionIndex]->RestoreCommand(
       
   852                   CCRStreamingSession::ECRRtpRecSinkId );
       
   853             if ( err == KErrCompletion )
       
   854                 {
       
   855                 err = iSessions[sessionIndex]->RestoreCommand(
       
   856                       CCRStreamingSession::ECR3gpRecSinkId );
       
   857                 }
       
   858 
       
   859             ConnectionStatusChange( aSessionChk, ECRRecordingStarted, err );
       
   860             }
       
   861         
       
   862         LOG1( "CCREngine::PauseRecordStream() out, err: %d", err );
       
   863         return err;
       
   864         }
       
   865         
       
   866     LOG1( "CCREngine::PauseRecordStream() out, sessionIndex: %d", sessionIndex );
       
   867     return sessionIndex;    
       
   868     }
       
   869 
       
   870 // -----------------------------------------------------------------------------
       
   871 // CCREngine::StopRecordStream
       
   872 //
       
   873 // -----------------------------------------------------------------------------
       
   874 //
       
   875 TInt CCREngine::StopRecordStream( const TUint aSessionChk ) 
       
   876     {
       
   877     LOG1( "CCREngine::StopRecordStream() in, aSessionChk: %d", aSessionChk );
       
   878     
       
   879     // Verify session
       
   880     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
   881         
       
   882     // Session exist?
       
   883     if ( sessionIndex > KErrNotFound )
       
   884         {
       
   885         // Clip format not known, so all types must try to stop
       
   886         iSessions[sessionIndex]->StopCommand(
       
   887             CCRStreamingSession::ECRRtpRecSinkId );
       
   888         iSessions[sessionIndex]->StopCommand(
       
   889             CCRStreamingSession::ECR3gpRecSinkId );
       
   890         // Possible error(s) ignored
       
   891         }
       
   892         
       
   893     LOG1( "CCREngine::StopRecordStream() out, sessionIndex: %d", sessionIndex );
       
   894     return sessionIndex;    
       
   895     }
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CCREngine::StartTimeShift
       
   899 // Existing stream play will be splitted to two sessions. Existing source will
       
   900 // be directed to recording and existing sink will get new source from playback.
       
   901 // -----------------------------------------------------------------------------
       
   902 //
       
   903 TInt CCREngine::StartTimeShiftL( const TUint aSessionChk ) 
       
   904     {
       
   905     LOG1( "CCREngine::StartTimeShiftL() in, aSessionChk: %d", aSessionChk );
       
   906 
       
   907 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   908 
       
   909     // Verify session
       
   910     const TInt currentSession( VerifySession( aSessionChk ) );
       
   911     User::LeaveIfError( currentSession );
       
   912 
       
   913     // Initial time shift clip name
       
   914     TPath initialName( KDvrTimeShiftFile );
       
   915     initialName.AppendNum( 0 );
       
   916     
       
   917     // RTP clip handler
       
   918     CreateClipHandlerL();
       
   919 
       
   920     // Start recording of stream
       
   921     SCRRecordParams recordParams;
       
   922     recordParams.iFileName.Set( initialName );
       
   923     recordParams.iFormat = ECRRecordTimeShift;
       
   924     iSessions[currentSession]->CreateRtpRecordSinkL( recordParams, iClipHandler );
       
   925     iSessions[currentSession]->PostActionL();
       
   926 
       
   927     // Create new session for time shift clip playback
       
   928     SCRRtpPlayParams params;
       
   929     params.iFileName = initialName;
       
   930     const TInt timeShiftSession( VerifyRtpFileSessionL( params ) );
       
   931     iSessions[timeShiftSession]->PostActionL();
       
   932 
       
   933     // Transfer ownership of existing XPS sink to a new session
       
   934     User::LeaveIfError( iSessions[currentSession]->TransferSink( 
       
   935         CCRStreamingSession::ECRXpsSinkId, *iSessions[timeShiftSession] ) );
       
   936 
       
   937     // Session checksum
       
   938     TUint sessionChk( iSessions[timeShiftSession]->SourceChecksum() );
       
   939     LOG1( "CCREngine::StartTimeShiftL() out, sessionChk: %d", sessionChk );
       
   940     return sessionChk;
       
   941 
       
   942 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   943     ( void )aSessionChk;
       
   944     return KErrNotSupported;
       
   945 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   946     }
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CCREngine::StopTimeShift
       
   950 // Streaming is set back to one session. Streaming orginal source stays and sink
       
   951 // from temporary playback will be moved back to orginal session.
       
   952 // -----------------------------------------------------------------------------
       
   953 //
       
   954 TInt CCREngine::StopTimeShift(
       
   955     const TUint aTimeShiftChk,
       
   956     const TUint aCurrentChk ) 
       
   957     {
       
   958     LOG2( "CCREngine::StopTimeShift() in, aTimeShiftChk: %d, aCurrentChk: %d", 
       
   959                                           aTimeShiftChk, aCurrentChk );
       
   960 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   961 
       
   962     // Verify session
       
   963     int ret( KErrNotFound );
       
   964     const TInt currentSession( VerifySession( aCurrentChk ) );
       
   965     const TInt timeShiftSession( VerifySession( aTimeShiftChk ) );
       
   966         
       
   967     // Session exist?
       
   968     if ( currentSession > KErrNotFound && timeShiftSession > KErrNotFound )
       
   969         {
       
   970         // Stop time shift clip recording
       
   971         iSessions[currentSession]->StopCommand( 
       
   972             CCRStreamingSession::ECR3gpRecSinkId );
       
   973         
       
   974         // Stop time shift clip playback
       
   975         iSessions[timeShiftSession]->StopCommand();
       
   976 
       
   977         // Transfer ownership of existing XPS sink back to the old session
       
   978         ret = iSessions[timeShiftSession]->TransferSink( 
       
   979             CCRStreamingSession::ECRXpsSinkId, *iSessions[currentSession] );
       
   980         
       
   981         // Delete second session
       
   982         SessionStop( iSessions[timeShiftSession] );
       
   983         }
       
   984     
       
   985     // Clip handler not needed any longer
       
   986     DeleteClipHandler( currentSession );
       
   987 
       
   988     LOG1( "CCREngine::StopTimeShift() out, ret: %d", ret );
       
   989     return ret;    
       
   990 
       
   991 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   992     ( void )aTimeShiftChk;
       
   993     ( void )aCurrentChk;
       
   994     return KErrNotSupported;
       
   995 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   996     }
       
   997 
       
   998 // -----------------------------------------------------------------------------
       
   999 // CCREngine::PlayCommand
       
  1000 //
       
  1001 // -----------------------------------------------------------------------------
       
  1002 //
       
  1003 TInt CCREngine::PlayCommand(
       
  1004     const TUint aSessionChk,
       
  1005     const TReal aStartPos,
       
  1006     const TReal aEndPos ) 
       
  1007     {
       
  1008     LOG1( "CCREngine::PlayCommand(), aSessionChk: %d", aSessionChk );
       
  1009 
       
  1010     // Verify session
       
  1011     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1012         
       
  1013     // New session needed?
       
  1014     if ( sessionIndex > KErrNotFound )
       
  1015         {
       
  1016         return iSessions[sessionIndex]->PlayCommand( aStartPos, aEndPos );
       
  1017         }
       
  1018         
       
  1019     return KErrNotReady;
       
  1020     }
       
  1021 
       
  1022 // -----------------------------------------------------------------------------
       
  1023 // CCREngine::PauseCommand
       
  1024 //
       
  1025 // -----------------------------------------------------------------------------
       
  1026 //
       
  1027 TInt CCREngine::PauseCommand( const TUint aSessionChk )
       
  1028     {
       
  1029     LOG1( "CCREngine::PauseCommand(), aSessionChk: %d", aSessionChk );
       
  1030 
       
  1031     // Verify session
       
  1032     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1033         
       
  1034     // New session needed?
       
  1035     if ( sessionIndex > KErrNotFound )
       
  1036         {
       
  1037         return iSessions[sessionIndex]->PauseCommand();
       
  1038         }
       
  1039         
       
  1040     return KErrNotReady;
       
  1041     }
       
  1042 
       
  1043 // -----------------------------------------------------------------------------
       
  1044 // CCREngine::StopCommand
       
  1045 //
       
  1046 // -----------------------------------------------------------------------------
       
  1047 //
       
  1048 TInt CCREngine::StopCommand( const TUint aSessionChk )
       
  1049     {
       
  1050     LOG1( "CCREngine::StopCommand(), aSessionChk: %d", aSessionChk );
       
  1051 
       
  1052     // Verify session
       
  1053     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1054         
       
  1055     // New session needed?
       
  1056     if ( sessionIndex > KErrNotFound )
       
  1057         {
       
  1058         return iSessions[sessionIndex]->StopCommand();
       
  1059         }
       
  1060         
       
  1061     return KErrNotReady;
       
  1062     }
       
  1063 
       
  1064 // -----------------------------------------------------------------------------
       
  1065 // CCREngine::SetPosition
       
  1066 //
       
  1067 // -----------------------------------------------------------------------------
       
  1068 //
       
  1069 TInt CCREngine::SetPosition(
       
  1070     const TUint aSessionChk,
       
  1071     const TInt64 aPosition )
       
  1072     {
       
  1073     LOG1( "CCREngine::SetPosition(), aSessionChk: %d", aSessionChk );
       
  1074 
       
  1075     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1076     if ( sessionIndex > KErrNotFound )
       
  1077         {
       
  1078         return iSessions[sessionIndex]->SetPosition( aPosition );
       
  1079         }
       
  1080    
       
  1081     return KErrNotReady;
       
  1082     }
       
  1083 
       
  1084 // -----------------------------------------------------------------------------
       
  1085 // CCREngine::GetPosition
       
  1086 //
       
  1087 // -----------------------------------------------------------------------------
       
  1088 //
       
  1089 TInt CCREngine::GetPosition(
       
  1090     const TUint aSessionChk,
       
  1091     TInt64& aPosition,
       
  1092     TInt64& aDuration ) 
       
  1093     {
       
  1094     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1095     if ( sessionIndex > KErrNotFound )
       
  1096         {
       
  1097         return iSessions[sessionIndex]->GetPosition( aPosition, aDuration );
       
  1098         }
       
  1099 
       
  1100     return KErrNotReady;
       
  1101     }
       
  1102 
       
  1103 // -----------------------------------------------------------------------------
       
  1104 // CCREngine::CloseSession
       
  1105 //
       
  1106 // -----------------------------------------------------------------------------
       
  1107 //
       
  1108 TInt CCREngine::CloseSession( const TUint aSessionChk )
       
  1109     {
       
  1110     LOG1( "CCREngine::CloseSession(), aSessionChk: %d", aSessionChk );
       
  1111     
       
  1112     // Verify session
       
  1113     const TInt sessionIndex( VerifySession( aSessionChk ) );
       
  1114     if ( sessionIndex > KErrNotFound )
       
  1115         {
       
  1116         SessionStop( iSessions[sessionIndex] );
       
  1117         }
       
  1118     
       
  1119     return KErrNone;
       
  1120     }
       
  1121     
       
  1122 // -----------------------------------------------------------------------------
       
  1123 // CCREngine::PlayNullSourceL
       
  1124 //
       
  1125 // -----------------------------------------------------------------------------
       
  1126 //
       
  1127 TUint CCREngine::PlayNullSourceL() 
       
  1128     {
       
  1129     LOG( "CCREngine::PlayNullSourceL() in" );
       
  1130 
       
  1131     _LIT( KNullSourceClip, "NullSource.rtp" );
       
  1132     TFileName nullSourcePath;
       
  1133 #if ( defined( __WINS__ ) || defined( __WINSCW__ ) )
       
  1134     nullSourcePath = PathInfo::PhoneMemoryRootPath();
       
  1135 #else // __WINS__ || __WINSCW__
       
  1136     nullSourcePath = PathInfo::MemoryCardRootPath();
       
  1137 #endif // __WINS__ || __WINSCW__
       
  1138     nullSourcePath.Append( KNullSourceClip );
       
  1139 
       
  1140     TInt sessionIndex( VerifySession( nullSourcePath ) );
       
  1141     if ( sessionIndex == KErrNotFound )
       
  1142         {
       
  1143         CCRStreamingSession* session = CCRStreamingSession::NewL(
       
  1144                                        iSockServer, iConnection, *this );        
       
  1145         CleanupStack::PushL( session );
       
  1146         User::LeaveIfError( iSessions.Append( session ) );
       
  1147         CleanupStack::Pop( session );
       
  1148 
       
  1149         // Only one source per session
       
  1150         sessionIndex = iSessions.Count() - 1;
       
  1151         iSessions[sessionIndex]->OpenSourceL( nullSourcePath );
       
  1152         }
       
  1153 
       
  1154     iSessions[sessionIndex]->CreateXpsSinkL();
       
  1155     //iSessions[sessionIndex]->CreateNullSinkL();
       
  1156     iSessions[sessionIndex]->PostActionL();
       
  1157     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
  1158     LOG1( "CCREngine::PlayNullSourceL() out, sessionChk: %d", sessionChk );
       
  1159     return sessionChk;
       
  1160     }
       
  1161 
       
  1162 // -----------------------------------------------------------------------------
       
  1163 // CCREngine::PlayRtspUrlToNullSinkL
       
  1164 //
       
  1165 // -----------------------------------------------------------------------------
       
  1166 //
       
  1167 TUint CCREngine::PlayRtspUrlToNullSinkL( const SCRRtspParams& aRtspParams ) 
       
  1168     {
       
  1169     LOG( "CCREngine::PlayRtspUrlToNullSinkL() in" );
       
  1170     
       
  1171     const TInt sessionIndex( VerifyRtspSessionL( aRtspParams ) );
       
  1172     iSessions[sessionIndex]->CreateNullSinkL();
       
  1173     TUint sessionChk( iSessions[sessionIndex]->SourceChecksum() );
       
  1174     LOG1( "CCREngine::PlayRtspUrlToNullSinkL() out, sessionChk: %d", sessionChk );
       
  1175     return sessionChk;
       
  1176     }
       
  1177 
       
  1178 // -----------------------------------------------------------------------------
       
  1179 // CCREngine::CreateConnectionL
       
  1180 // 
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 void CCREngine::CreateConnectionL( void )
       
  1184     {
       
  1185     LOG( "CCREngine::CreateConnectionL() in" );
       
  1186 
       
  1187     if ( iConnection == NULL )
       
  1188         {
       
  1189         User::LeaveIfError( iSockServer.Connect( KESockDefaultMessageSlots * 3 ) );
       
  1190         iConnection = CCRConnection::NewL( iSockServer );
       
  1191         User::LeaveIfError( iConnection->RegisterObserver( this ) );
       
  1192         
       
  1193         // Informer
       
  1194         if ( iInformer == NULL )
       
  1195             {
       
  1196             iInformer = CCRClientInformer::NewL();
       
  1197             }
       
  1198         }
       
  1199     
       
  1200     LOG( "CCREngine::CreateConnectionL() out" );
       
  1201     }
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CCREngine::CreateClipHandlerL
       
  1205 // 
       
  1206 // -----------------------------------------------------------------------------
       
  1207 //
       
  1208 void CCREngine::CreateClipHandlerL( void )
       
  1209     {
       
  1210     LOG1( "CCREngine::CreateClipHandlerL(), iClipHandler: %d", iClipHandler );
       
  1211 
       
  1212 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1213 
       
  1214     if ( !iClipHandler )
       
  1215         {
       
  1216         iClipHandler = CRtpClipHandler::NewL();
       
  1217         }
       
  1218 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1219     }
       
  1220 
       
  1221 // -----------------------------------------------------------------------------
       
  1222 // CCREngine::VerifyRtspSessionL
       
  1223 // Go through stream sessions and try to find if RTSP stream is already playing.
       
  1224 // -----------------------------------------------------------------------------
       
  1225 //
       
  1226 TInt CCREngine::VerifyRtspSessionL( const SCRRtspParams& aRtspParams ) 
       
  1227     {
       
  1228     TInt sessionIndex( VerifySession( aRtspParams.iUrl ) );
       
  1229     
       
  1230     // New session needed?
       
  1231     if ( sessionIndex == KErrNotFound )
       
  1232         {
       
  1233         CCRStreamingSession* session = CCRStreamingSession::NewL(
       
  1234                                        iSockServer, iConnection, *this ); 
       
  1235         CleanupStack::PushL( session );       
       
  1236         User::LeaveIfError( iSessions.Append( session ) );
       
  1237         CleanupStack::Pop( session );
       
  1238 
       
  1239         // Only one source per session
       
  1240         sessionIndex = iSessions.Count() - 1;
       
  1241         iSessions[sessionIndex]->OpenSourceL( aRtspParams, aRtspParams.iUrl );
       
  1242         }
       
  1243     
       
  1244     User::LeaveIfError( sessionIndex );
       
  1245     return sessionIndex;
       
  1246     }
       
  1247 
       
  1248 // -----------------------------------------------------------------------------
       
  1249 // CCREngine::VerifyDvbhSessionL
       
  1250 // Go through stream sessions and try to find if DVB-H live is already playing.
       
  1251 // -----------------------------------------------------------------------------
       
  1252 //
       
  1253 TInt CCREngine::VerifyDvbhSessionL( const SCRLiveParams& aLiveParams ) 
       
  1254     {
       
  1255     // Verify session
       
  1256     HBufC* definition = HBufC::NewLC( aLiveParams.iSdpData.Length() );
       
  1257     definition->Des().Copy( aLiveParams.iSdpData );
       
  1258     TInt sessionIndex( VerifySession( *definition ) );
       
  1259 
       
  1260     // New session needed?
       
  1261     if ( sessionIndex == KErrNotFound )
       
  1262         {
       
  1263         CCRStreamingSession* session = CCRStreamingSession::NewL(
       
  1264                                        iSockServer, iConnection, *this );        
       
  1265         CleanupStack::PushL( session );
       
  1266         User::LeaveIfError( iSessions.Append( session ) );
       
  1267         CleanupStack::Pop( session );
       
  1268         
       
  1269         // Only one source per session
       
  1270         sessionIndex = iSessions.Count() - 1;
       
  1271         iSessions[sessionIndex]->OpenSourceL( aLiveParams, *definition );
       
  1272         }
       
  1273     
       
  1274     CleanupStack::PopAndDestroy( definition );
       
  1275     User::LeaveIfError( sessionIndex );
       
  1276     return sessionIndex;
       
  1277     }
       
  1278 
       
  1279 // -----------------------------------------------------------------------------
       
  1280 // CCREngine::VerifyRtpFileSessionL
       
  1281 // Go through stream sessions and try to find if RTP clip is already playing.
       
  1282 // -----------------------------------------------------------------------------
       
  1283 //
       
  1284 TInt CCREngine::VerifyRtpFileSessionL( const SCRRtpPlayParams& aRtpParams ) 
       
  1285     {
       
  1286 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1287 
       
  1288     // Verify session
       
  1289     TInt sessionIndex( VerifySession( aRtpParams.iFileName ) );
       
  1290         
       
  1291     // New session needed?
       
  1292     if ( sessionIndex == KErrNotFound )
       
  1293         {
       
  1294         
       
  1295         CCRStreamingSession* session = CCRStreamingSession::NewL(
       
  1296                                        iSockServer, iConnection, *this );        
       
  1297         CleanupStack::PushL( session );
       
  1298         User::LeaveIfError( iSessions.Append( session ) );
       
  1299         CleanupStack::Pop( session );
       
  1300 
       
  1301         // RTP clip handler
       
  1302         CreateClipHandlerL();
       
  1303         
       
  1304         // Only one source per session
       
  1305         sessionIndex = iSessions.Count() - 1;
       
  1306         iSessions[sessionIndex]->OpenSourceL( aRtpParams, iClipHandler, 
       
  1307                                               aRtpParams.iFileName );
       
  1308         }
       
  1309 
       
  1310     User::LeaveIfError( sessionIndex );
       
  1311     return sessionIndex;
       
  1312 
       
  1313 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1314     ( void )aRtpParams;
       
  1315     return KErrNotSupported;
       
  1316 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1317     }
       
  1318 
       
  1319 // -----------------------------------------------------------------------------
       
  1320 // CCREngine::VerifyRtpFileSessionL
       
  1321 // Go through stream sessions and try to find if RTP clip is already playing.
       
  1322 // -----------------------------------------------------------------------------
       
  1323 //
       
  1324 TInt CCREngine::VerifyRtpFileSessionL( const RFile& aFileHandle ) 
       
  1325     {
       
  1326 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1327 
       
  1328     TFileName fileName( KNullDesC );
       
  1329     aFileHandle.FullName( fileName );
       
  1330     TInt sessionIndex( VerifySession( fileName ) );
       
  1331         
       
  1332     // New session needed?
       
  1333     if ( sessionIndex == KErrNotFound )
       
  1334         {
       
  1335         CCRStreamingSession* session = CCRStreamingSession::NewL(
       
  1336                                        iSockServer, iConnection, *this );        
       
  1337         CleanupStack::PushL( session );
       
  1338         User::LeaveIfError( iSessions.Append( session ) );
       
  1339         CleanupStack::Pop( session );
       
  1340 
       
  1341         // RTP clip handler
       
  1342         CreateClipHandlerL();
       
  1343         
       
  1344         // Only one source per session
       
  1345         sessionIndex = iSessions.Count() - 1;
       
  1346         iSessions[sessionIndex]->OpenSourceL( aFileHandle, iClipHandler, fileName );
       
  1347         }
       
  1348 
       
  1349     User::LeaveIfError( sessionIndex );
       
  1350     return sessionIndex;
       
  1351 
       
  1352 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1353     ( void )aFileHandle;
       
  1354     return KErrNotSupported;
       
  1355 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1356     }
       
  1357 
       
  1358 // -----------------------------------------------------------------------------
       
  1359 // CCREngine::VerifySession
       
  1360 // Go through stream sessions and try to find stream is already playing.
       
  1361 // -----------------------------------------------------------------------------
       
  1362 //
       
  1363 TInt CCREngine::VerifySession( const TDesC& aName ) 
       
  1364     {
       
  1365     if ( iSessions.Count() > 0 )
       
  1366         {
       
  1367         for ( TInt i( iSessions.Count() - 1 ); i >= 0; i-- )
       
  1368             {
       
  1369             const TUint chksm( iSessions[i]->SourceDefinition( aName ) );
       
  1370             if ( chksm == iSessions[i]->SourceChecksum() )
       
  1371                 {
       
  1372                 return i;
       
  1373                 }
       
  1374             }
       
  1375         }
       
  1376 
       
  1377     return KErrNotFound;
       
  1378     }
       
  1379 
       
  1380 // -----------------------------------------------------------------------------
       
  1381 // CCREngine::VerifySession
       
  1382 // Go through stream sessions and try to find session index from active sessions.
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 TInt CCREngine::VerifySession( const TUint aSessionChk ) 
       
  1386     {
       
  1387     if ( iSessions.Count() > 0 )
       
  1388         {
       
  1389         for ( TInt i( iSessions.Count() - 1 ); i >= 0; i-- )
       
  1390             {
       
  1391             if ( aSessionChk == iSessions[i]->SourceChecksum() )
       
  1392                 {
       
  1393                 return i;
       
  1394                 }
       
  1395             }
       
  1396         }
       
  1397 
       
  1398     return KErrNotFound;
       
  1399     }
       
  1400 
       
  1401 //-----------------------------------------------------------------------------
       
  1402 // CCREngine::CreateRecordingSinkL
       
  1403 //
       
  1404 //-----------------------------------------------------------------------------
       
  1405 //
       
  1406 void CCREngine::CreateRecordingSinkL(
       
  1407     const TInt aSessionIndex,
       
  1408     const SCRRecordParams& aRecordParams )
       
  1409     {
       
  1410     LOG1( "CCREngine::CreateRecordingSinkL(), aSessionIndex: %d", aSessionIndex );
       
  1411     
       
  1412     User::LeaveIfError( aSessionIndex );
       
  1413     switch ( aRecordParams.iFormat )
       
  1414         {
       
  1415 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1416         case ECRRecordFormatRtp:
       
  1417             // RTP clip handler
       
  1418             CreateClipHandlerL();
       
  1419             iSessions[aSessionIndex]->CreateRtpRecordSinkL(
       
  1420                 aRecordParams, iClipHandler );
       
  1421             break;
       
  1422 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1423 
       
  1424         case ECRRecordFormat3gp:
       
  1425             iSessions[aSessionIndex]->Create3gpRecordSinkL( aRecordParams );
       
  1426             break;
       
  1427 
       
  1428         default:
       
  1429             LOG( "CCREngine::CreateRecordingSinkL(), Clip format invalid !");
       
  1430             User::Leave( KErrNotSupported );
       
  1431             break;
       
  1432         }
       
  1433     }
       
  1434 
       
  1435 //-----------------------------------------------------------------------------
       
  1436 // CCREngine::SessionStopCallBack
       
  1437 //
       
  1438 //-----------------------------------------------------------------------------
       
  1439 //
       
  1440 TInt CCREngine::SessionStopCallBack ( TAny* aThis ) 
       
  1441     {
       
  1442     LOG( "CCREngine::SessionStopCallBack()" );
       
  1443     
       
  1444     CCREngine* self = static_cast<CCREngine*>( aThis );
       
  1445     self->DoSessionStop();
       
  1446     return self->iSessionsToDelete.Count(); 
       
  1447     }
       
  1448     
       
  1449 //-----------------------------------------------------------------------------
       
  1450 // CCREngine::DoSessionStop
       
  1451 //
       
  1452 //-----------------------------------------------------------------------------
       
  1453 //
       
  1454 void CCREngine::DoSessionStop( void ) 
       
  1455     {
       
  1456     LOG1( "CCREngine::DoSessionStop() in, iSessionsToDelete.Count = %d", iSessionsToDelete.Count() );
       
  1457     
       
  1458     for ( TInt i( iSessionsToDelete.Count() - 1 ); i >= 0; i-- )
       
  1459         {
       
  1460         for ( TInt j( iSessions.Count() - 1 ); j >= 0; j-- )
       
  1461             {
       
  1462             if ( iSessions[j] == iSessionsToDelete[i] )
       
  1463                 {
       
  1464                 delete iSessions[j];
       
  1465                 iSessions.Remove( j ); 
       
  1466                 }
       
  1467             }
       
  1468         }
       
  1469     
       
  1470     // Supposed to be empty by now
       
  1471     DeleteClipHandler( KErrNotFound );
       
  1472     iSessionsToDelete.Reset();
       
  1473     LOG( "CCREngine::DoSessionStop() out" );
       
  1474     }
       
  1475     
       
  1476 //-----------------------------------------------------------------------------
       
  1477 // CCREngine::DeleteClipHandler
       
  1478 //
       
  1479 //-----------------------------------------------------------------------------
       
  1480 //
       
  1481 void CCREngine::DeleteClipHandler( const TInt aCurrentSessionIndex ) 
       
  1482     {
       
  1483     LOG1( "CCREngine::DeleteClipHandler(), aCurrentSessionIndex: %d",
       
  1484                                            aCurrentSessionIndex );
       
  1485 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1486 
       
  1487     if ( iClipHandler )
       
  1488         {
       
  1489         // Find out clip handler usage
       
  1490         TBool notUsed( ETrue );
       
  1491         for ( TInt i( iSessions.Count() - 1 ); i >= 0; i-- )
       
  1492             {
       
  1493             if ( i != aCurrentSessionIndex && iSessions[i]->ClipHandlerUsed() )
       
  1494                 {
       
  1495                 notUsed = EFalse;
       
  1496                 }
       
  1497             }
       
  1498 
       
  1499         // Clip handler not needed any longer?
       
  1500         if ( notUsed )
       
  1501             {
       
  1502             delete iClipHandler; iClipHandler = NULL;    
       
  1503             LOG( "CCREngine::DeleteClipHandler(), RTP ClipHandler deleted !" );
       
  1504             }
       
  1505         }
       
  1506     
       
  1507 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1508     ( void )aCurrentSessionIndex;
       
  1509 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
  1510     }
       
  1511     
       
  1512 // -----------------------------------------------------------------------------
       
  1513 // CCREngine::Read
       
  1514 // Read from the client thread, if unsuccessful, panic the client.
       
  1515 // -----------------------------------------------------------------------------
       
  1516 //
       
  1517 void CCREngine::Read(
       
  1518     const RMessage2& aMessage, 
       
  1519     const TInt& aParam,
       
  1520     TDes8& aDes ) 
       
  1521     {
       
  1522     TRAPD( err, aMessage.ReadL( aParam, aDes ) );
       
  1523     if ( err )
       
  1524         {
       
  1525         PanicClient( ECRPanicBadDescriptor, aMessage );
       
  1526         }
       
  1527     }
       
  1528 
       
  1529 // -----------------------------------------------------------------------------
       
  1530 // CCREngine::Read
       
  1531 // Read from the client thread, if unsuccessful, panic the client.
       
  1532 // -----------------------------------------------------------------------------
       
  1533 //
       
  1534 void CCREngine::Read(
       
  1535     const RMessage2& aMessage, 
       
  1536     const TInt& aParam,
       
  1537     TDes16& aDes ) 
       
  1538     {
       
  1539     TRAPD( err, aMessage.ReadL( aParam, aDes ) );
       
  1540     if ( err )
       
  1541         {
       
  1542         PanicClient( ECRPanicBadDescriptor, aMessage );
       
  1543         }
       
  1544     }
       
  1545 
       
  1546 // -----------------------------------------------------------------------------
       
  1547 // CCREngine::Write
       
  1548 // Write to the client thread, if unsuccessful, panic the client.
       
  1549 // -----------------------------------------------------------------------------
       
  1550 //
       
  1551 void CCREngine::Write(
       
  1552     const RMessage2& aMessage, 
       
  1553     const TInt& aParam,
       
  1554     const TDesC8& aDes ) 
       
  1555     {
       
  1556     TRAPD( err, aMessage.WriteL( aParam, aDes ) );
       
  1557     if ( err )
       
  1558         {
       
  1559         PanicClient( ECRPanicBadDescriptor, aMessage );
       
  1560         }
       
  1561     }
       
  1562 
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // CCREngine::Write
       
  1565 // Write to the client thread, if unsuccessful, panic the client.
       
  1566 // -----------------------------------------------------------------------------
       
  1567 //
       
  1568 void CCREngine::Write(
       
  1569     const RMessage2& aMessage, 
       
  1570     const TInt& aParam,
       
  1571     const TDesC16& aDes ) 
       
  1572     {
       
  1573     TRAPD( err, aMessage.WriteL( aParam, aDes ) );
       
  1574     if ( err )
       
  1575         {
       
  1576         PanicClient( ECRPanicBadDescriptor, aMessage );
       
  1577         }
       
  1578     }
       
  1579 
       
  1580 // -----------------------------------------------------------------------------
       
  1581 // CCREngine::PanicClient
       
  1582 //
       
  1583 // -----------------------------------------------------------------------------
       
  1584 //
       
  1585 void CCREngine::PanicClient( TInt aPanic, const RMessage2& aMessage )
       
  1586     {
       
  1587     // Panic the client on server side
       
  1588     _LIT( KRbfClientFault, "Common recording engine" );
       
  1589     aMessage.Panic( KRbfClientFault, aPanic );
       
  1590     }   
       
  1591     
       
  1592 //  End of File