dvrengine/CommonRecordingEngine/src/CCRStreamingSession.cpp
changeset 41 d88d70d98bbc
parent 34 814ba97beeb9
child 46 3bc36dbd63c2
equal deleted inserted replaced
34:814ba97beeb9 41:d88d70d98bbc
     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:    Class for streaming session. Owns a source, number of buffers*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "VideoServiceUtilsConf.hrh"
       
    22 #include "CCRStreamingSession.h"
       
    23 #include "CCRRtspSink.h"
       
    24 #include "CCRNullSink.h"
       
    25 #include "CCRPacketBuffer.h"
       
    26 #include <ipvideo/CRTypeDefs.h>
       
    27 #include "CCRRtspPacketSource.h"
       
    28 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    29 #include "CCRXpsSink.h"
       
    30 #include "CCRRtpRecordSink.h"
       
    31 #include "CCRRtpFileSource.h"
       
    32 #include "CCRNullSource.h"
       
    33 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    34 #include "MCRStreamObserver.h"
       
    35 #include "CCRPacketSinkBase.h"
       
    36 #include "CCRConnection.h"
       
    37 #include "CCRengine.h"
       
    38 #include "videoserviceutilsLogger.h"
       
    39 
       
    40 // CONSTANTS
       
    41 const TInt KMaxRtspPackets( 400 );
       
    42 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    43 const TInt KMaxRtpPackets( 500 );
       
    44 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCRStreamingSession::NewL
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 //      
       
    53 CCRStreamingSession* CCRStreamingSession::NewL(
       
    54     RSocketServ& aSockServer,
       
    55     CCRConnection* aConnection,
       
    56     CCREngine& aEngine )
       
    57     {
       
    58     CCRStreamingSession* self = new( ELeave ) CCRStreamingSession(
       
    59                                 aSockServer, aConnection, aEngine );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CCRStreamingSession::CCRStreamingSession
       
    68 //
       
    69 // -----------------------------------------------------------------------------
       
    70 //      
       
    71 CCRStreamingSession::CCRStreamingSession(
       
    72     RSocketServ& aSockServer,
       
    73     CCRConnection* aConnection,
       
    74     CCREngine& aEngine ) 
       
    75   : iSockServer( aSockServer ),
       
    76     iConnection( aConnection ),
       
    77     iEngine( aEngine )
       
    78     {
       
    79     // None
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CCRStreamingSession::ConstructL
       
    84 //
       
    85 // -----------------------------------------------------------------------------
       
    86 //          
       
    87 void CCRStreamingSession::ConstructL()
       
    88     {
       
    89     LOG( "CCRStreamingSession::ConstructL()" );
       
    90 
       
    91     // Note, quite high priority
       
    92     iCleanUp = new ( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ); 
       
    93     }
       
    94     
       
    95 // -----------------------------------------------------------------------------
       
    96 // CCRStreamingSession::~CCREStreamingSession
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //          
       
   100 CCRStreamingSession::~CCRStreamingSession()
       
   101     {
       
   102     LOG( "CCRStreamingSession::~CCRStreamingSession()" );
       
   103     
       
   104     delete iCleanUp;     
       
   105     iSinks.ResetAndDestroy();
       
   106     iSinksToDelete.Reset(); 
       
   107     delete iSource;
       
   108     delete iBuffer;
       
   109     iConnection = NULL;
       
   110     }
       
   111     
       
   112 // -----------------------------------------------------------------------------
       
   113 // CCRStreamingSession::OpenSourceL
       
   114 // Opens RTSP streaming source.
       
   115 // -----------------------------------------------------------------------------
       
   116 //      
       
   117 void CCRStreamingSession::OpenSourceL(
       
   118     const SCRRtspParams& aParams,
       
   119     const TDesC& aSessionDefinition )
       
   120     {
       
   121     LOG( "CCRStreamingSession::OpenSourceL(), RTSP Url" )
       
   122     
       
   123     if ( !iSource && iConnection )
       
   124         {
       
   125         iSourceChecksum = SourceDefinition( aSessionDefinition );
       
   126         iSource = CCRRtspPacketSource::NewL(
       
   127                   aParams, *iConnection, iSockServer, *this, *this );
       
   128         iSource->RegisterConnectionObs( &iEngine );
       
   129         }    
       
   130     }
       
   131     
       
   132 // -----------------------------------------------------------------------------
       
   133 // CCRStreamingSession::OpenSourceL
       
   134 // Opens RTP clip streaming source.
       
   135 // -----------------------------------------------------------------------------
       
   136 //      
       
   137 void CCRStreamingSession::OpenSourceL(
       
   138     const SCRRtpPlayParams& aParams,
       
   139     CRtpClipHandler*& aClipHandler,
       
   140     const TDesC& aSessionDefinition )
       
   141     {
       
   142     LOG( "CCRStreamingSession::OpenSourceL(), RTP clip" )
       
   143 
       
   144 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   145 
       
   146     if ( !iSource )
       
   147         {
       
   148         iSourceChecksum = SourceDefinition( aSessionDefinition );
       
   149         iBuffer = CCRPacketBuffer::NewL( KMaxRtpPackets );
       
   150         iSource = CCRRtpFileSource::NewL( aParams, aClipHandler, *this, *this );
       
   151         iSource->SetBuffer( iBuffer );
       
   152         }
       
   153 
       
   154 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   155     ( void )aParams;
       
   156     ( void )aClipHandler;
       
   157     ( void )aSessionDefinition;
       
   158     User::Leave( KErrNotSupported );
       
   159 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CCRStreamingSession::OpenSourceL
       
   164 // Opens RTP clip streaming source.
       
   165 // -----------------------------------------------------------------------------
       
   166 //      
       
   167 void CCRStreamingSession::OpenSourceL(
       
   168     const RFile& aRtpHandle,
       
   169     CRtpClipHandler*& aClipHandler,
       
   170     const TDesC& aSessionDefinition )
       
   171     {
       
   172     LOG( "CCRStreamingSession::OpenSourceL(), RTP handle" )
       
   173 
       
   174 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   175 
       
   176     if ( !iSource )
       
   177         {
       
   178         iSourceChecksum = SourceDefinition( aSessionDefinition );
       
   179         iBuffer = CCRPacketBuffer::NewL( KMaxRtpPackets );
       
   180         iSource = CCRRtpFileSource::NewL( aRtpHandle, aClipHandler, *this, *this );
       
   181         iSource->SetBuffer( iBuffer );
       
   182         }
       
   183 
       
   184 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   185     ( void )aRtpHandle;
       
   186     ( void )aClipHandler;
       
   187     ( void )aSessionDefinition;
       
   188     User::Leave( KErrNotSupported );
       
   189 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CCRStreamingSession::OpenSourceL
       
   194 // Opens DVB-H live streaming source.
       
   195 // -----------------------------------------------------------------------------
       
   196 //      
       
   197 void CCRStreamingSession::OpenSourceL(
       
   198     const SCRLiveParams& /*aLiveParams*/,
       
   199     const TDesC& /*aSessionDefinition*/ )
       
   200     {
       
   201     LOG( "CCRStreamingSession::OpenSourceL(), DVB-H live" )
       
   202 
       
   203     User::Leave( KErrNotSupported );
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CCRStreamingSession::OpenSourceL
       
   208 // Opens RTP clip as a live streaming source.
       
   209 // -----------------------------------------------------------------------------
       
   210 //      
       
   211 void CCRStreamingSession::OpenSourceL( const TDesC& aSessionDefinition )
       
   212     {
       
   213     LOG( "CCRStreamingSession::OpenSourceL(), Null" )
       
   214 
       
   215 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   216 
       
   217     if ( !iSource )
       
   218         {
       
   219         iSourceChecksum = SourceDefinition( aSessionDefinition );
       
   220         iBuffer = CCRPacketBuffer::NewL( KMaxRtpPackets );
       
   221         iSource = CCRNullSource::NewL( aSessionDefinition, *this, *this );
       
   222         iSource->SetBuffer( iBuffer );
       
   223         }
       
   224 
       
   225 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   226     ( void )aSessionDefinition;
       
   227     User::Leave( KErrNotSupported );
       
   228 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CCRStreamingSession::SourceDefinition
       
   233 //
       
   234 // -----------------------------------------------------------------------------
       
   235 //      
       
   236 TUint CCRStreamingSession::SourceDefinition( const TDesC& aName )
       
   237     {
       
   238     TUint checkSum( 0 );
       
   239     for ( TInt i( aName.Length() - 1 ); i >= 0; i-- )
       
   240         {
       
   241         checkSum += aName[i];
       
   242         }
       
   243     
       
   244 	// And for rtsp packet source do use different id
       
   245 	// if udp is blocked and we're using tcp then.    
       
   246     if ( iSource && iSource->Id() == ECRRtspSourceId &&
       
   247     	 iConnection && 
       
   248     	 iConnection->GetHeuristic ( CCRConnection::EUdpStreamingBlocked ) )
       
   249     	 {
       
   250     	 checkSum++;
       
   251     	 }
       
   252             
       
   253     return checkSum;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CCRStreamingSession::SourceChecksum
       
   258 //
       
   259 // -----------------------------------------------------------------------------
       
   260 //      
       
   261 TUint CCRStreamingSession::SourceChecksum()
       
   262     {
       
   263     return iSourceChecksum;
       
   264     }
       
   265 
       
   266 //-----------------------------------------------------------------------------
       
   267 // CCRStreamingSession::CreateAndSetBufferL
       
   268 //
       
   269 //-----------------------------------------------------------------------------
       
   270 //    
       
   271 void CCRStreamingSession::CreateAndSetBufferL()
       
   272     {
       
   273     if ( iSource && iBuffer == NULL )
       
   274         {
       
   275         iBuffer = CCRPacketBuffer::NewL( KMaxRtspPackets );
       
   276         iSource->SetBuffer( iBuffer );
       
   277         }
       
   278     }
       
   279 
       
   280 //-----------------------------------------------------------------------------
       
   281 // CCRStreamingSession::CreateRtspSinkL
       
   282 //
       
   283 //-----------------------------------------------------------------------------
       
   284 //
       
   285 void CCRStreamingSession::CreateRtspSinkL( const TInt& aLoopbackPort )
       
   286     {
       
   287     LOG( "CCRStreamingSession::CreateRtspSinkL()" )
       
   288 
       
   289     if ( iConnection )
       
   290         {
       
   291         // Only one RTSP sink at the time
       
   292         DeleteSink( ECRRtspSinkId ); 
       
   293         
       
   294         // New sink
       
   295         CCRRtspSink* sink = CCRRtspSink::NewL(
       
   296             *iConnection, iSockServer, ECRRtspSinkId, aLoopbackPort, *this );
       
   297         CleanupStack::PushL( sink );
       
   298         User::LeaveIfError( iSinks.Append( sink ) );
       
   299         CleanupStack::Pop( sink );
       
   300         }
       
   301     }
       
   302 
       
   303 //-----------------------------------------------------------------------------
       
   304 // CCRStreamingSession::CreateXpsSinkL
       
   305 //
       
   306 //-----------------------------------------------------------------------------
       
   307 //    
       
   308 void CCRStreamingSession::CreateXpsSinkL()
       
   309     {
       
   310     LOG( "CCRStreamingSession::CreateXpsSinkL()" )
       
   311 
       
   312 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   313 
       
   314     CCRXpsSink* sink = CCRXpsSink::NewL( ECRXpsSinkId, *this );
       
   315     CleanupStack::PushL( sink );
       
   316     User::LeaveIfError( iSinks.Append( sink ) );
       
   317     CleanupStack::Pop( sink );
       
   318 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   319     User::Leave( KErrNotSupported );
       
   320 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   321     }
       
   322 
       
   323 //-----------------------------------------------------------------------------
       
   324 // CCRStreamingSession::Create3gpRecordSinkL
       
   325 //
       
   326 //-----------------------------------------------------------------------------
       
   327 //    
       
   328 void CCRStreamingSession::Create3gpRecordSinkL(
       
   329     const SCRRecordParams& /*aRecordParams*/ )
       
   330     {
       
   331     LOG( "CCRStreamingSession::Create3gpRecordSinkL()" )
       
   332 
       
   333     User::Leave( KErrNotSupported );
       
   334     /*
       
   335     CCR3gpRecordSink* sink = CCR3gpRecordSink::NewL( ECR3gpRecSinkId, *this );
       
   336     CleanupStack::PushL( sink );
       
   337     User::LeaveIfError( iSinks.Append( sink ) );
       
   338     CleanupStack::Pop( sink );
       
   339     */
       
   340     }
       
   341 
       
   342 //-----------------------------------------------------------------------------
       
   343 // CCRStreamingSession::CreateRtpRecordSinkL
       
   344 //
       
   345 //-----------------------------------------------------------------------------
       
   346 //    
       
   347 void CCRStreamingSession::CreateRtpRecordSinkL(
       
   348     const SCRRecordParams& aRecordParams,
       
   349     CRtpClipHandler*& aClipHandler )
       
   350     {
       
   351     LOG( "CCRStreamingSession::CreateRtpRecordSinkL()" )
       
   352 
       
   353 #ifdef RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   354     // Create record sink
       
   355     CCRRtpRecordSink* sink = CCRRtpRecordSink::NewL( 
       
   356         aRecordParams, ECRRtpRecSinkId, *this, &iEngine, aClipHandler );
       
   357     CleanupStack::PushL( sink );
       
   358     User::LeaveIfError( iSinks.Append( sink ) );
       
   359     CleanupStack::Pop( sink );
       
   360 
       
   361 #else // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   362     ( void )aRecordParams;
       
   363     ( void )aClipHandler;
       
   364     User::Leave( KErrNotSupported );
       
   365 #endif // RD_IPTV_FEA_RTP_CLIP_SUPPORT
       
   366     }
       
   367 
       
   368 //-----------------------------------------------------------------------------
       
   369 // CCRStreamingSession::PostActionL
       
   370 //
       
   371 //-----------------------------------------------------------------------------
       
   372 //    
       
   373 void CCRStreamingSession::PostActionL()
       
   374     {
       
   375     User::LeaveIfNull( iSource );
       
   376     iSource->PostActionL();
       
   377     }
       
   378 
       
   379 //-----------------------------------------------------------------------------
       
   380 // CCRStreamingSession::PlayCommand
       
   381 //
       
   382 //-----------------------------------------------------------------------------
       
   383 //    
       
   384 TInt CCRStreamingSession::PlayCommand(
       
   385     const TReal& aStartPos,
       
   386     const TReal& aEndPos )
       
   387     {
       
   388     if ( iSource )
       
   389         {
       
   390         return iSource->Play( aStartPos, aEndPos );
       
   391         }
       
   392     
       
   393     return KErrCompletion;
       
   394     }
       
   395 
       
   396 //-----------------------------------------------------------------------------
       
   397 // CCRStreamingSession::PauseCommand
       
   398 //
       
   399 //-----------------------------------------------------------------------------
       
   400 //    
       
   401 TInt CCRStreamingSession::PauseCommand()
       
   402     {
       
   403     if ( iSource )
       
   404         {
       
   405         return iSource->Pause();
       
   406         }
       
   407     
       
   408     return KErrCompletion;
       
   409     }
       
   410 
       
   411 //-----------------------------------------------------------------------------
       
   412 // CCRStreamingSession::StopCommand
       
   413 //
       
   414 //-----------------------------------------------------------------------------
       
   415 //    
       
   416 TInt CCRStreamingSession::StopCommand()
       
   417     {
       
   418     if ( iSource && iSinks.Count() >= 1 )
       
   419         {
       
   420         return iSource->Stop();
       
   421         }
       
   422     
       
   423     return KErrCompletion;
       
   424     }
       
   425 
       
   426 //-----------------------------------------------------------------------------
       
   427 // CCRStreamingSession::SetPosition
       
   428 //
       
   429 //-----------------------------------------------------------------------------
       
   430 //    
       
   431 TInt CCRStreamingSession::SetPosition( const TInt64 aPosition )
       
   432     {
       
   433     if ( iSource )
       
   434         {
       
   435         return iSource->SetPosition( aPosition );
       
   436         }
       
   437 
       
   438     return KErrCompletion;
       
   439     }
       
   440 
       
   441 //-----------------------------------------------------------------------------
       
   442 // CCRStreamingSession::GetPosition
       
   443 //
       
   444 //-----------------------------------------------------------------------------
       
   445 //    
       
   446 TInt CCRStreamingSession::GetPosition( TInt64& aPosition, TInt64& aDuration )
       
   447     {
       
   448     if ( iSource )
       
   449         {
       
   450         return iSource->GetPosition( aPosition, aDuration );
       
   451         }
       
   452 
       
   453     return KErrCompletion;
       
   454     }
       
   455 
       
   456 //-----------------------------------------------------------------------------
       
   457 // CCRStreamingSession::PauseCommand
       
   458 //
       
   459 //-----------------------------------------------------------------------------
       
   460 //    
       
   461 TInt CCRStreamingSession::PauseCommand( const TCRSinkId& aSinkId )
       
   462     {
       
   463     // Pauses current sink action
       
   464     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   465         {
       
   466         if ( aSinkId == iSinks[i]->Id() )
       
   467             {
       
   468             return iSinks[i]->Pause();
       
   469             }
       
   470         }
       
   471 
       
   472     return KErrCompletion;
       
   473     }
       
   474     
       
   475 //-----------------------------------------------------------------------------
       
   476 // CCRStreamingSession::RestoreCommand
       
   477 //
       
   478 //-----------------------------------------------------------------------------
       
   479 //    
       
   480 TInt CCRStreamingSession::RestoreCommand( const TCRSinkId& aSinkId )
       
   481     {
       
   482     // Pauses current sink action
       
   483     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   484         {
       
   485         if ( aSinkId == iSinks[i]->Id() )
       
   486             {
       
   487             return iSinks[i]->Restore();
       
   488             }
       
   489         }
       
   490 
       
   491     return KErrCompletion;
       
   492     }
       
   493     
       
   494 //-----------------------------------------------------------------------------
       
   495 // CCRStreamingSession::StopCommand
       
   496 //
       
   497 //-----------------------------------------------------------------------------
       
   498 //    
       
   499 TInt CCRStreamingSession::StopCommand( const TCRSinkId& aSinkId )
       
   500     {
       
   501     // Stop current sink action
       
   502     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   503         {
       
   504         if ( aSinkId == iSinks[i]->Id() )
       
   505             {
       
   506             iSinks[i]->Stop();
       
   507             return KErrNone;
       
   508             }
       
   509         }
       
   510 
       
   511     return KErrCompletion;
       
   512     }
       
   513     
       
   514 //-----------------------------------------------------------------------------
       
   515 // CCRStreamingSession::TransferSink
       
   516 //
       
   517 //-----------------------------------------------------------------------------
       
   518 //    
       
   519 TInt CCRStreamingSession::TransferSink(
       
   520     const TCRSinkId& aSinkId,
       
   521     CCRStreamingSession& aTargetSession )
       
   522     {
       
   523     LOG1( "CCRStreamingSession::TransferSink(), aSinkId: %d", aSinkId );
       
   524     
       
   525     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   526         {
       
   527         if ( iSinks[i]->Id() == aSinkId )
       
   528             {
       
   529             TInt err( aTargetSession.AddNewSink( iSinks[i] ) );
       
   530             if ( !err )
       
   531                 {
       
   532                 iBuffer->RemoveSink( iSinks[i] );
       
   533                 iSinks.Remove( i );
       
   534                 }
       
   535             
       
   536             return err;
       
   537             }
       
   538         }
       
   539 
       
   540     return KErrCompletion;
       
   541     }
       
   542     
       
   543 //-----------------------------------------------------------------------------
       
   544 // CCRStreamingSession::AddNewSink
       
   545 //
       
   546 //-----------------------------------------------------------------------------
       
   547 //    
       
   548 TInt CCRStreamingSession::AddNewSink( CCRPacketSinkBase* aSink )
       
   549     {
       
   550     LOG1( "CCRStreamingSession::AddNewSink(), aSink->Id: %d", aSink->Id() );
       
   551 
       
   552     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   553         {
       
   554         if ( aSink->Id() == iSinks[i]->Id() )
       
   555             {
       
   556             LOG( "CCRStreamingSession::AddNewSink(), Sink already exist !" );
       
   557             return KErrInUse;
       
   558             }
       
   559         }
       
   560 
       
   561     // Add new sink
       
   562     TInt err( iSinks.Append( aSink ) );
       
   563     if ( !err )
       
   564         {
       
   565         err = iBuffer->AddSink( iSinks[iSinks.Count() - 1] );
       
   566         }
       
   567 
       
   568     return err;
       
   569     }
       
   570     
       
   571 //-----------------------------------------------------------------------------
       
   572 // CCRStreamingSession::ClipHandlerUsed
       
   573 //
       
   574 //-----------------------------------------------------------------------------
       
   575 //    
       
   576 TBool CCRStreamingSession::ClipHandlerUsed()
       
   577     {
       
   578     // Used in source
       
   579     if ( iSource && iSource->Id() == ECRRtpSourceId )
       
   580         {
       
   581         return ETrue;
       
   582         }
       
   583     
       
   584     // Used in any Sink
       
   585     for ( TInt i( iSinks.Count() - 1 ); i >= 0; i-- )
       
   586         {
       
   587         if ( iSinks[i]->Id() == ECRRtpRecSinkId )
       
   588             {
       
   589             return ETrue;
       
   590             }
       
   591         }
       
   592     
       
   593     return EFalse;
       
   594     }
       
   595     
       
   596 //-----------------------------------------------------------------------------
       
   597 // CCRStreamingSession::CreateNullSinkL
       
   598 //
       
   599 //-----------------------------------------------------------------------------
       
   600 //
       
   601 void CCRStreamingSession::CreateNullSinkL()
       
   602     {
       
   603     CCRNullSink* sink = CCRNullSink::NewL( ECRNullSinkId, *this );
       
   604     sink->RegisterConnectionObs( &iEngine );
       
   605     CleanupStack::PushL( sink );
       
   606     User::LeaveIfError( iSinks.Append( sink ) );
       
   607     CleanupStack::Pop( sink );
       
   608     }
       
   609 
       
   610 //-----------------------------------------------------------------------------
       
   611 // CCRStreamingSession::InitializeSinks
       
   612 //
       
   613 //-----------------------------------------------------------------------------
       
   614 //    
       
   615 void CCRStreamingSession::InitializeSinks() 
       
   616     {
       
   617     if ( iSource && iBuffer )
       
   618         {
       
   619         TPtrC8 sdp( NULL, 0 );
       
   620         TInt err( iSource->GetSdp( sdp ) );
       
   621         if ( err )
       
   622             {
       
   623             LOG1( "CCRStreamingSession::InitializeSinks(), GetSdp() Failed: %d", err );
       
   624             SourceStop();
       
   625             }
       
   626         else
       
   627             {
       
   628             for ( TInt i( 0 ); i < iSinks.Count(); i++ ) 
       
   629                 {
       
   630                 TRAP( err, iSinks[i]->SetSdpL( sdp ) );
       
   631                 if ( err )
       
   632                     {
       
   633                     LOG1( "CCRStreamingSession::InitializeSinks(), SetSdpL() Failed: %d", err );
       
   634                     SinkStops( iSinks[i]->Id() ); 
       
   635                     return;
       
   636                     }
       
   637             
       
   638                 iSinks[i]->SetBuffer( iBuffer );
       
   639                 err = iBuffer->AddSink( iSinks[i] );
       
   640                 if ( err )
       
   641                     {
       
   642                     LOG1( "CCRStreamingSession::InitializeSinks(), AddSink() Failed: %d", err );
       
   643                     SourceStop();
       
   644                     return;
       
   645                     }
       
   646                 }
       
   647 
       
   648             iEngine.ConnectionStatusChange(
       
   649                 SourceChecksum(), MCRConnectionObserver::ECRSdpAvailable, KErrNone );            
       
   650             }
       
   651         }
       
   652     }    
       
   653 
       
   654 //-----------------------------------------------------------------------------
       
   655 // CCRStreamingSession::SetSeqAndTs()
       
   656 //-----------------------------------------------------------------------------
       
   657 //
       
   658 void CCRStreamingSession::SetSeqAndTs() 
       
   659     {
       
   660     if ( iSource )
       
   661         {
       
   662         TUint audioSeq( 0 );
       
   663         TUint audioTS( 0 );
       
   664         TUint videoSeq( 0 );
       
   665         TUint videoTS( 0 );
       
   666         TReal lowerRange( KRealZero ); 
       
   667         TReal upperRange( KRealMinusOne ); 
       
   668         
       
   669         iSource->GetRange( lowerRange,upperRange ); 
       
   670         iSource->SeqAndTS( audioSeq, audioTS, videoSeq, videoTS );
       
   671 
       
   672         for ( TInt j( 0 ); j < iSinks.Count(); j++ ) 
       
   673             {
       
   674             if ( !( lowerRange == KRealZero && upperRange == KRealMinusOne ) )
       
   675                 {
       
   676                 iSinks[j]->SetRange( lowerRange,upperRange ); 
       
   677                 }
       
   678 
       
   679             iSinks[j]->SetSeqAndTS( audioSeq, audioTS, videoSeq, videoTS );
       
   680             }
       
   681         }
       
   682     }
       
   683 
       
   684 //-----------------------------------------------------------------------------
       
   685 // CCRStreamingSession::SinkStops()
       
   686 // So, a sink wants to quit. we can't just delete it  here as return. Statement
       
   687 // would then take us to deleted instance: put up a cleanup CAsyncCallBack and 
       
   688 // return.
       
   689 //-----------------------------------------------------------------------------
       
   690 //
       
   691 void CCRStreamingSession::SinkStops( const TCRSinkId& aSinkId )
       
   692     {
       
   693     LOG1( "CCRStreamingSession::SinkStops(), aSinkId: %d", aSinkId );
       
   694 
       
   695     // InsertInSignedKeyOrderL checks for duplicate, if there is already
       
   696     // entry for that sink, the array will remain unchanged
       
   697     TRAPD( err, iSinksToDelete.InsertInSignedKeyOrderL( aSinkId ) ); 
       
   698     if ( err )
       
   699         {
       
   700         LOG1( "CCRStreamingSession::SinkStops(), InsertInSignedKeyOrderL leaved %d", err );      
       
   701         }
       
   702 
       
   703     // If not already active and sinks to delete?
       
   704     if ( !iCleanUp->IsActive() && iSinksToDelete.Count() ) 
       
   705         {
       
   706         TCallBack cb( SinkStopCallBack, this );
       
   707         iCleanUp->Set( cb );
       
   708         iCleanUp->CallBack();
       
   709         }               
       
   710     }
       
   711     
       
   712 //-----------------------------------------------------------------------------
       
   713 // CCRStreamingSession::SourceRestore()
       
   714 //-----------------------------------------------------------------------------
       
   715 //
       
   716 void CCRStreamingSession::SourceRestore()
       
   717     {
       
   718     if ( iSource )
       
   719         {
       
   720         iSource->Restore();
       
   721         }
       
   722     }
       
   723 
       
   724 //-----------------------------------------------------------------------------
       
   725 // CCRStreamingSession::SourceStop()
       
   726 //-----------------------------------------------------------------------------
       
   727 //
       
   728 void CCRStreamingSession::SourceStop()
       
   729     {
       
   730     // Session is useless without a source so ask engine to clean it all up
       
   731     iEngine.SessionStop( this );
       
   732     }
       
   733     
       
   734 // -----------------------------------------------------------------------------
       
   735 // CCRStreamingSession::StatusChanged
       
   736 //
       
   737 // -----------------------------------------------------------------------------
       
   738 //      
       
   739 void CCRStreamingSession::StatusChanged(
       
   740     MCRPacketSource::TCRPacketSourceState aStatus )
       
   741     {
       
   742     LOG1( "CCRStreamingSession::StatusChanged(), aStatus: %d", aStatus );
       
   743     
       
   744     switch ( aStatus )
       
   745         {
       
   746         case MCRPacketSource::ERtpStateIdle:
       
   747             break;
       
   748         
       
   749         case MCRPacketSource::ERtpStateSdpAvailable:
       
   750             TRAPD( err, CreateAndSetBufferL() );
       
   751             if ( err )
       
   752                 {
       
   753                 LOG1( "CCRStreamingSession::StatusChanged(), CreateAndSetBuffers leaved: %d", err );
       
   754                 }
       
   755             
       
   756             InitializeSinks();
       
   757             break;
       
   758         
       
   759         case MCRPacketSource::ERtpStateSeqAndTSAvailable:
       
   760             SetSeqAndTs();
       
   761             break;
       
   762         
       
   763         case MCRPacketSource::ERtpStateSetupRepply:
       
   764         case MCRPacketSource::ERtpStatePlaying:
       
   765             {                
       
   766             for ( TInt j( iSinks.Count() - 1 ); j >= 0; j-- )
       
   767                 {
       
   768                 iSinks[j]->StatusChanged( aStatus ) ;
       
   769                 }
       
   770             }
       
   771             break;
       
   772         
       
   773         case MCRPacketSource::ERtpStateClosing:
       
   774             SourceStop();
       
   775             break;
       
   776         
       
   777         default:
       
   778             // None.
       
   779             break;
       
   780         }
       
   781     }
       
   782 
       
   783 //-----------------------------------------------------------------------------
       
   784 // CCRStreamingSession::SinkStopCallBack()
       
   785 //
       
   786 //-----------------------------------------------------------------------------
       
   787 //
       
   788 TInt CCRStreamingSession::SinkStopCallBack( TAny* aThis ) 
       
   789     {
       
   790     CCRStreamingSession* self = static_cast<CCRStreamingSession*>( aThis );    
       
   791     LOG1( "CCRStreamingSession::SinkStopCallBack(), iSinksToDelete count: %d",
       
   792         self->iSinksToDelete.Count() );
       
   793     self->DoSinkStop();
       
   794     return self->iSinksToDelete.Count(); 
       
   795     }
       
   796     
       
   797 //-----------------------------------------------------------------------------
       
   798 // CCRStreamingSession::DoSinkStop()
       
   799 //
       
   800 //-----------------------------------------------------------------------------
       
   801 //
       
   802 void CCRStreamingSession::DoSinkStop( void ) 
       
   803     {
       
   804     LOG( "CCRStreamingSession::DoSinkStop() in" );  
       
   805 
       
   806     for ( TInt i( iSinksToDelete.Count() - 1 ); i >= 0; i-- )
       
   807         {
       
   808         for ( TInt j( iSinks.Count() - 1 ); j >= 0; j-- )
       
   809             {
       
   810             if ( iSinks[j]->Id() == iSinksToDelete[i] )
       
   811                 {
       
   812                 TInt remainingSinks( 0 );
       
   813                 if ( iBuffer ) 
       
   814                     {
       
   815                     // If we never got sdp, we never had a buffer
       
   816                 	remainingSinks = iBuffer->RemoveSink( iSinks[j] );
       
   817                 	}
       
   818                 
       
   819                 if ( remainingSinks < 1 )
       
   820                     {
       
   821                     // No sinks remaing for our buffers, I'm feeling useless
       
   822                     if ( iSource ) 
       
   823                         {
       
   824                         iSource->Stop(); 
       
   825                         }
       
   826                     }
       
   827                 
       
   828                 delete iSinks[j];
       
   829                 iSinks[j] = NULL;
       
   830                 iSinks.Remove( j );
       
   831                 }
       
   832             }
       
   833         }
       
   834 
       
   835     iSinksToDelete.Reset(); 
       
   836     LOG( "CCRStreamingSession::DoSinkStop() out" );
       
   837     }
       
   838 
       
   839 //-----------------------------------------------------------------------------
       
   840 // CCRStreamingSession::DeleteSink
       
   841 //
       
   842 //-----------------------------------------------------------------------------
       
   843 //
       
   844 void CCRStreamingSession::DeleteSink( const TCRSinkId& aSinkId )
       
   845     {
       
   846     for ( TInt i( iSinks.Count() - 1 ); i >= 0 ; i-- ) 
       
   847         {
       
   848         if ( iSinks[i]->Id() == aSinkId )
       
   849             {
       
   850             // Remove sink from buffer
       
   851             if ( iBuffer )
       
   852                 {
       
   853                 iBuffer->RemoveSink( iSinks[i] );
       
   854                 }
       
   855             
       
   856             // Delete sink
       
   857             delete iSinks[i];
       
   858             iSinks[i] = NULL;
       
   859             iSinks.Remove( i );
       
   860             LOG2( "CCRStreamingSession::DeleteSink(), deleted index: %d, aSinkId: %d", i, aSinkId );
       
   861             }
       
   862         }
       
   863     }
       
   864 
       
   865 //  End of File