dvrengine/CommonRecordingEngine/src/CCRNullSink.cpp
branchRCL_3
changeset 47 826cea16efd9
parent 45 798ee5f1972c
child 48 13a33d82ad98
equal deleted inserted replaced
45:798ee5f1972c 47:826cea16efd9
     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 that takes packet from buffer and does not put them*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCRNullSink.h"
       
    22 #include "CCRPacketBuffer.h"
       
    23 #include "CCRStreamingSession.h"
       
    24 #include "CCRTimer.h"
       
    25 #include "MCRConnectionObserver.h"
       
    26 #include "videoserviceutilsLogger.h"
       
    27 
       
    28 // CONSTANTS
       
    29 // None
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CCRNullSink::NewL
       
    35 // Two-phased constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //  
       
    38 CCRNullSink* CCRNullSink::NewL(
       
    39     CCRStreamingSession::TCRSinkId aSinkId,
       
    40     CCRStreamingSession& aOwningSession )
       
    41     {
       
    42     CCRNullSink* self = new( ELeave ) CCRNullSink( aSinkId, aOwningSession );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCRNullSink::CCRNullSink
       
    51 // C++ default constructor can NOT contain any code, that might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //  
       
    54 CCRNullSink::CCRNullSink(
       
    55     CCRStreamingSession::TCRSinkId aSinkId,
       
    56     CCRStreamingSession& aOwningSession )
       
    57   : CCRPacketSinkBase( aOwningSession, aSinkId )
       
    58     {
       
    59     // None
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCRNullSink::ConstructL
       
    64 // 2nd phase. 
       
    65 // -----------------------------------------------------------------------------
       
    66 //  
       
    67 void CCRNullSink::ConstructL()
       
    68     {
       
    69     // None
       
    70     }
       
    71     
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCRNullSink::~CCRNullSink
       
    74 // Destructor.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CCRNullSink::~CCRNullSink()
       
    78     {    
       
    79     delete iSdp; 
       
    80     delete iFlowTimer;
       
    81     iBuffer = NULL; // does not delete and it is right thing.   
       
    82     }
       
    83     
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCRNullSink::SetSdpL
       
    86 // as a side-effect causes parsing of the sdp.
       
    87 // -----------------------------------------------------------------------------
       
    88 //  
       
    89 void CCRNullSink::SetSdpL( const TDesC8& aSdp )
       
    90     {
       
    91     LOG1( "CCRNullSink::SetSdpL(), aSdp len: %d", aSdp.Length() );
       
    92     
       
    93     delete iSdp; iSdp = NULL; 
       
    94     iSdp = aSdp.AllocL();
       
    95     iOwningSession.PlayCommand( KRealZero, KRealMinusOne );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CCRNullSink::NewPacketAvailable
       
   100 //
       
   101 // -----------------------------------------------------------------------------
       
   102 //      
       
   103 void CCRNullSink::NewPacketAvailable()
       
   104     {
       
   105     if ( iBuffer )
       
   106         {
       
   107         TPtr8 packet( NULL, 0 );
       
   108         MCRPacketSource::TCRPacketStreamId streamId;
       
   109         const TInt book( iBuffer->GetStream( iSinkId, streamId ) );
       
   110         iBuffer->GetPacket( book, packet ); 
       
   111         const TUint8* pointer( &packet[2] );
       
   112         TInt seq( BigEndian::Get16( pointer ) );
       
   113         LOG2( "CCRNullSink::NewPacketAvailable(), streamId: %u, seq: %u", 
       
   114                                                   streamId, seq );
       
   115         // Keep buffer size reasonable
       
   116         iBuffer->HandleBufferSize();
       
   117         
       
   118         // Handle flow control
       
   119         if ( !iBuffer->ContinousStream() && !iFlowTimer )
       
   120             {
       
   121             TRAPD( err, iFlowTimer = CCRTimer::NewL( CActive::EPriorityLow, *this ) );
       
   122             if ( !err )
       
   123                 {
       
   124                 if ( iBuffer->PacketsCount( iSinkId ) > KErrNotFound )
       
   125                     {
       
   126                     iFlowTimer->After( 0 );
       
   127                     }
       
   128                 else
       
   129                     {
       
   130                     iFlowTimer->At( 2e6 );
       
   131                     }
       
   132                 }
       
   133             else
       
   134                 {
       
   135                 delete iFlowTimer; iFlowTimer = NULL;
       
   136                 }
       
   137             }
       
   138         }
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CCRNullSink::TimerExpired
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CCRNullSink::TimerExpired( CCRTimer* /*aTimer*/ )
       
   146     {
       
   147     if ( iBuffer->PacketsCount( iSinkId ) > KErrNotFound )
       
   148         {
       
   149         NewPacketAvailable();
       
   150         }
       
   151     else
       
   152         {
       
   153         iOwningSession.SourceRestore();
       
   154         }
       
   155     
       
   156     delete iFlowTimer; iFlowTimer = NULL;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCRNullSink::RegisterConnectionObs
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CCRNullSink::RegisterConnectionObs( MCRConnectionObserver* aObserver )
       
   164     {
       
   165     iObserver = aObserver;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CCRNullSink::StatusChanged
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CCRNullSink::StatusChanged( MCRPacketSource::TCRPacketSourceState aNewState )
       
   173     {
       
   174     if( iObserver )
       
   175         {
       
   176         TCRTestSinkData data = aNewState==MCRPacketSource::ERtpStateIdle ? ECRTestSinkStateIdle :
       
   177                                aNewState==MCRPacketSource::ERtpStateSdpAvailable ? ECRTestSinkStateSdpAvailable :
       
   178                                aNewState==MCRPacketSource::ERtpStateSeqAndTSAvailable ? ECRTestSinkStateSeqAndTSAvailable :
       
   179                                aNewState==MCRPacketSource::ERtpStatePlaying ? ECRTestSinkStatePlaying :
       
   180                                /*aNewState==MCRPacketSource::ERtpStateClosing?*/ ECRTestSinkStateClosing;
       
   181 
       
   182         LOG3( "CCRNullSink::StatusChanged: newState=%d -> ECRTestSinkData, checksum=%d, data=%d",
       
   183               (TInt)aNewState, (TInt)iOwningSession.SourceChecksum(), (TInt)data );
       
   184         iObserver->ConnectionStatusChange( iOwningSession.SourceChecksum(),
       
   185                                            MCRConnectionObserver::ECRTestSinkData,
       
   186                                            (TInt)data );
       
   187         }
       
   188     }
       
   189 
       
   190 
       
   191 //  End of File