multimediacommscontroller/mmccmsrpsourcesink/src/mccmsrpsource.cpp
branchrcs
changeset 49 64c62431ac08
child 50 1d8943dd8be6
equal deleted inserted replaced
44:fb024d5e35fa 49:64c62431ac08
       
     1 /*
       
     2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Provides a comfort noise generator class
       
    15 *
       
    16 */
       
    17 
       
    18         
       
    19 // INCLUDE FILES
       
    20 #include "mccmsrpsource.h"
       
    21 #include "mmccinterfacedef.h"
       
    22 #include "mccmsrpsourcesinklogs.h"
       
    23 #include "mccinternalevents.h"
       
    24 #include "mccinternaldef.h"
       
    25 #include "rtpheader.h"
       
    26 #include "formatstatemachine.h"
       
    27 
       
    28 
       
    29 // ============================= LOCAL FUNCTIONS ===============================
       
    30 
       
    31 void CMccMsrpSource::IncomingMessage( HBufC8* aMessageContent, TInt aStatus )
       
    32     {
       
    33     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::IncomingMessage" )
       
    34     __MSRPSOURCESINK_CONTROLL_INT1( "Status : %d    ----- ", aStatus)
       
    35     
       
    36 	TRAP_IGNORE(PlayoutMsrpPacketL(aMessageContent));
       
    37     }
       
    38     
       
    39 void CMccMsrpSource::IncomingReport( TInt aStatus, TInt aRangeStart,
       
    40                                            TInt aRangeEnd, TInt aTotal )
       
    41     {
       
    42     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::IncomingReport" )
       
    43     __MSRPSOURCESINK_CONTROLL("\nReport has been received!\n");
       
    44     __MSRPSOURCESINK_CONTROLL_INT1("Status      :", aStatus);
       
    45     __MSRPSOURCESINK_CONTROLL_INT1("Range start :", aRangeStart);
       
    46     __MSRPSOURCESINK_CONTROLL_INT1("Range end   :", aRangeEnd);
       
    47     __MSRPSOURCESINK_CONTROLL_INT1("Total       :", aTotal);
       
    48     }
       
    49     
       
    50 void CMccMsrpSource::SendResult( TInt aStatus, const TDesC8& aMessageid )
       
    51     {
       
    52     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SendResult" )
       
    53     __MSRPSOURCESINK_CONTROLL("\nResult of send... ");
       
    54     __MSRPSOURCESINK_CONTROLL_INT1("Status :", aStatus);
       
    55     
       
    56     __MSRPSOURCESINK_CONTROLL_INT1("Message ID :", aMessageid);
       
    57     }
       
    58     
       
    59 void CMccMsrpSource::ListenPortFailure( TInt aStatus )
       
    60     {
       
    61     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::ListenPortFailure" )
       
    62     __MSRPSOURCESINK_CONTROLL("\nListen port failure. ");
       
    63     __MSRPSOURCESINK_CONTROLL_INT1("Status :", aStatus);
       
    64     //CActiveScheduler::Stop();
       
    65     }
       
    66 
       
    67 
       
    68 
       
    69 // ============================ MEMBER FUNCTIONS ===============================
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CMccMsrpSource::NewSourceL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 MDataSource* CMccMsrpSource::NewSourceL( TUid /*aImplementationUid*/, 
       
    76                                          const TDesC8& /*aInitData*/ )
       
    77     {
       
    78     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::NewSourceL" )
       
    79     
       
    80     CMccMsrpSource* self = new ( ELeave ) CMccMsrpSource();
       
    81     return static_cast<MDataSource*>( self );
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CMccMsrpSource::ConstructSourceL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CMccMsrpSource::ConstructSourceL( const TDesC8& /*aInitData*/ )
       
    89     {    	
       
    90     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::ConstructSourceL" )
       
    91     }
       
    92 	    
       
    93 // -----------------------------------------------------------------------------
       
    94 // Constructor.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CMccMsrpSource::CMccMsrpSource() : CMccDataSource( KMccMsrpSourceUid )
       
    98     {
       
    99     }
       
   100         
       
   101 // -----------------------------------------------------------------------------
       
   102 // Destructor.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CMccMsrpSource::~CMccMsrpSource()
       
   106     {   
       
   107     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::~CMccMsrpSource" )
       
   108     
       
   109     iFillBufferRequester = NULL;
       
   110 
       
   111     iBufferToBeFilled = NULL;
       
   112     iConsumer = NULL;
       
   113     }
       
   114 
       
   115 	
       
   116 // -----------------------------------------------------------------------------
       
   117 // CMccMsrpSource::SourcePrimeL()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CMccMsrpSource::SourcePrimeL()
       
   121 	{
       
   122     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourcePrimeL" )
       
   123     
       
   124     SendStreamEventToClient( KMccStreamPrepared );
       
   125 	}
       
   126 	    
       
   127 // -----------------------------------------------------------------------------
       
   128 // CMccMsrpSource::PlayL()
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CMccMsrpSource::SourcePlayL()
       
   132     {
       
   133     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourcePlayL" )
       
   134     
       
   135     if ( iPaused )
       
   136         {
       
   137         SendStreamEventToClient( KMccStreamResumed );
       
   138         }
       
   139     else
       
   140         {
       
   141     	SendStreamEventToClient( KMccStreamStarted );	
       
   142         }
       
   143 		
       
   144     iPaused = EFalse;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CMccMsrpSource::PauseL()
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CMccMsrpSource::SourcePauseL()
       
   152     {
       
   153     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourcePauseL" )
       
   154     
       
   155     iPaused = ETrue;
       
   156     
       
   157     SendStreamEventToClient( KMccStreamPaused );
       
   158 	}
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CMccMsrpSource::StopL()
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CMccMsrpSource::SourceStopL()
       
   165     {
       
   166     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourceStopL" )
       
   167     
       
   168     SendStreamEventToClient( KMccStreamStopped );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMccMsrpSource::SourceDataTypeCode()
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TFourCC CMccMsrpSource::SourceDataTypeCode( TMediaId /*aMediaId*/ )
       
   176 	{
       
   177 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourceDataTypeCode" )
       
   178 	
       
   179 	return iFourCC;
       
   180 	}
       
   181 	
       
   182 // -----------------------------------------------------------------------------
       
   183 // CMccMsrpSource::SetSourceDataTypeCode()
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 TInt CMccMsrpSource::SetSourceDataTypeCode( TFourCC aCodec, 
       
   187                             TMediaId /*aMediaId*/ )
       
   188 	{
       
   189 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SetSourceDataTypeCode" )
       
   190 	
       
   191 	iFourCC = aCodec;
       
   192 	return KErrNone;
       
   193 	}	
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMccMsrpSource::BufferEmptiedL()
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMccMsrpSource::BufferEmptiedL( CMMFBuffer* /*aBuffer*/ )
       
   200 	{
       
   201     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::BufferEmptiedL" )
       
   202     
       
   203    	User::Leave( KErrNotSupported );
       
   204 	}
       
   205 	
       
   206 // -----------------------------------------------------------------------------
       
   207 // CMccMsrpSource::CanCreateSourceBuffer()
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 TBool CMccMsrpSource::CanCreateSourceBuffer()
       
   211 	{
       
   212 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::CanCreateSourceBuffer" )
       
   213 
       
   214     return EFalse;
       
   215 	}	
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CMccMsrpSource::CreateSourceBufferL()
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 CMMFBuffer* CMccMsrpSource::CreateSourceBufferL( 
       
   222 	TMediaId /*aMediaId*/, 
       
   223     TBool& /*aReference*/ )
       
   224 	{
       
   225 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::CreateSourceBufferL" )
       
   226 
       
   227    	User::Leave( KErrNotSupported );
       
   228 	
       
   229 	return NULL;	
       
   230 	}
       
   231 	
       
   232 // -----------------------------------------------------------------------------
       
   233 // CMccMsrpSource::SourceThreadLogon()
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 TInt CMccMsrpSource::SourceThreadLogon( MAsyncEventHandler& aEventHandler )
       
   237 	{
       
   238 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourceThreadLogon" )
       
   239 	
       
   240 	iAsyncEventHandler = &aEventHandler;
       
   241 	
       
   242     return KErrNone;
       
   243 	}
       
   244 	
       
   245 // -----------------------------------------------------------------------------
       
   246 // CMccMsrpSource::SourceThreadLogoff()
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CMccMsrpSource::SourceThreadLogoff()
       
   250 	{
       
   251     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SourceThreadLogoff" )
       
   252     
       
   253     iAsyncEventHandler = NULL;
       
   254 	}
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CMccMsrpSource::FillBufferL()
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CMccMsrpSource::FillBufferL( 
       
   261 	CMMFBuffer* aBuffer,
       
   262     MDataSink* aConsumer,
       
   263     TMediaId /*aMediaId*/ )
       
   264 	{
       
   265 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::FillBufferL" )
       
   266 	iBufferToBeFilled = static_cast<CMMFDataBuffer*>( aBuffer );
       
   267 	iConsumer = aConsumer;
       
   268 	}	
       
   269                   
       
   270 // -----------------------------------------------------------------------------
       
   271 // CMccMsrpSource::NegotiateSourceL()
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CMccMsrpSource::NegotiateSourceL( MDataSink& aDataSink )
       
   275 	{
       
   276     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::NegotiateSourceL" )
       
   277 	iFillBufferRequester = &aDataSink;
       
   278 	}
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CMccMsrpSource::SendStreamEventToClient
       
   282 // -----------------------------------------------------------------------------
       
   283 //	
       
   284 void CMccMsrpSource::SendStreamEventToClient( 
       
   285     TMccEventType aEventType, 
       
   286     TInt aError )
       
   287 	{
       
   288 	__MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::SendStreamEventToClient" )
       
   289 	
       
   290 	if ( iAsyncEventHandler )
       
   291 	    {
       
   292         TMccEvent event( 0, 
       
   293                          0, 
       
   294                          0, 
       
   295                          MCC_ENDPOINT_ID( static_cast<MDataSource*>( this ) ), 
       
   296                          KMccEventCategoryStream, 
       
   297                          aEventType, 
       
   298                          aError, 
       
   299                          KNullDesC8 );
       
   300                      
       
   301         TMccInternalEvent internalEvent( KMccMsrpSourceUid, 
       
   302 		                                 EMccInternalEventNone,
       
   303 		                                 event );
       
   304 		                         
       
   305 		iAsyncEventHandler->SendEventToClient( internalEvent );
       
   306 	    }
       
   307 	}
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CMccMsrpSource::DataReceivedL
       
   311 // -----------------------------------------------------------------------------
       
   312 //	
       
   313 void CMccMsrpSource::DataReceivedL( const TDesC8& aData )
       
   314     {
       
   315     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSource::DataReceivedL" )
       
   316     if ( iBufferToBeFilled && iConsumer )
       
   317         {
       
   318         CMMFDataBuffer* buffer = static_cast<CMMFDataBuffer*>(iBufferToBeFilled);
       
   319 
       
   320         if (buffer->Data().MaxLength() >= aData.Length())
       
   321             {            
       
   322             buffer->Data().Copy( aData );
       
   323             iConsumer->BufferFilledL( iBufferToBeFilled );
       
   324         	iBufferToBeFilled = 0;
       
   325         	iConsumer = 0;
       
   326       		}      		
       
   327         }
       
   328     }
       
   329 
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CMccMsrpSink::BufferFilledL
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CMccMsrpSource::SetSessionParamsL( const TMccMsrpSessionParams& aParams )
       
   336     {
       
   337     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSink::SetSessionParamsL IN" )
       
   338     
       
   339     User::LeaveIfNull( aParams.iMsrp );
       
   340     User::LeaveIfNull( aParams.iMsrpSession );
       
   341     
       
   342     iMsrp = aParams.iMsrp;
       
   343     iMsrpSession = aParams.iMsrpSession;
       
   344 //    iMsrpObserver = aParams.iMsrpObserver;
       
   345     
       
   346 //    iMsrpObserver->RegisterDataObserver(*this);  
       
   347     
       
   348     __MSRPSOURCESINK_CONTROLL( "CMccMsrpSink::SetSessionParamsL OUT" )
       
   349     }
       
   350 
       
   351 // End of file
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CMccRtpDataSource::PlayoutRtpPacketL
       
   355 // Pass filled buffer to the data sink of RTP data source.
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 void CMccMsrpSource::PlayoutMsrpPacketL( HBufC8* aMessageContent )
       
   359     {
       
   360     __MSRPSOURCESINK_CONTROLL( "CMccRtpDataSource::PlayoutRtpPacketL" )
       
   361     __ASSERT_ALWAYS( iBufferToBeFilled, User::Leave( KErrNotReady ) );
       
   362     __ASSERT_ALWAYS( iFillBufferRequester, User::Leave( KErrNotReady ) );
       
   363     
       
   364     iBufferToBeFilled->Data().Copy( *aMessageContent );
       
   365     
       
   366     CPayloadFormatRead* sink = static_cast<CPayloadFormatRead*>( iFillBufferRequester );
       
   367     User::LeaveIfNull( sink );
       
   368     
       
   369     TRtpRecvHeader aHeaderInfo;
       
   370     sink->DataBufferFilledL( iBufferToBeFilled, aHeaderInfo );
       
   371     
       
   372     delete aMessageContent;
       
   373     }