multimediacommsengine/mmceshared/src/mcecomvideocodec.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mcecomvideocodec.h"
       
    22 
       
    23 #include "mceserial.h"
       
    24 #include "mceevents.h"
       
    25 
       
    26 #include "mcecomrtpsource.h"
       
    27 #include "mcertpsource.h"
       
    28 
       
    29 #ifdef MCE_COMMON_SERVER_SIDE
       
    30 
       
    31 #include <mmcccodecinformation.h>
       
    32 #include "mcesrvstream.h"
       
    33 #include "mcesrvsource.h"
       
    34 
       
    35 
       
    36 #endif//MCE_COMMON_SERVER_SIDE
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40     
       
    41 // -----------------------------------------------------------------------------
       
    42 // CMceComVideoCodec::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CMceComVideoCodec* CMceComVideoCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    46     {
       
    47     CMceComVideoCodec* self = NewLC( aSdpName );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMceComVideoCodec::NewLC
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMceComVideoCodec* CMceComVideoCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    58     {
       
    59     CMceComVideoCodec* self = new (ELeave) CMceComVideoCodec();
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL( aSdpName );
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMceComVideoCodec::~CMceComAMRCodec
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMceComVideoCodec::~CMceComVideoCodec()
       
    71     {
       
    72     delete iConfigKey;
       
    73     }
       
    74     
       
    75 // -----------------------------------------------------------------------------
       
    76 // CMceComVideoCodec::CMceComVideoCodec
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CMceComVideoCodec::CMceComVideoCodec()
       
    80     :CMceComCodec(),
       
    81      iFrameRate( 0 ),
       
    82      iMaxBitRate( 0 ),
       
    83      iAllowedResolutions( 0 ),
       
    84      iResolutionWidth( 0 ),
       
    85      iResolutionHeight( 0 ),
       
    86      iAllowedFrameRates( 0 ),
       
    87      iClockRate( 0 ),
       
    88      iReceiveFrameRate( 0 ),
       
    89      iEncodingDecodingDevice( KNullUid )
       
    90     {
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMceComVideoCodec::ConstructL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CMceComVideoCodec* CMceComVideoCodec::CloneL()
       
    99     {
       
   100     CMceComVideoCodec* copy = new (ELeave) CMceComVideoCodec();
       
   101     CleanupStack::PushL( copy );
       
   102     copy->ConstructL( *this );
       
   103     CleanupStack::Pop( copy );
       
   104     return copy;
       
   105     
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CMceComVideoCodec::ConstructL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CMceComVideoCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   114     {
       
   115     CMceComCodec::ConstructL( aSdpName );
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CMceComVideoCodec::ConstructL
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CMceComVideoCodec::ConstructL( CMceComVideoCodec& aCodec )
       
   124     {
       
   125     CMceComCodec::ConstructL( aCodec );
       
   126     
       
   127     iFrameRate = aCodec.iFrameRate;
       
   128     iMaxBitRate = aCodec.iMaxBitRate;
       
   129     iAllowedResolutions = aCodec.iAllowedResolutions;
       
   130     iResolutionWidth = aCodec.iResolutionWidth;
       
   131     iResolutionHeight = aCodec.iResolutionHeight;
       
   132     iAllowedFrameRates = aCodec.iAllowedFrameRates;
       
   133     iClockRate = aCodec.iClockRate;
       
   134     iReceiveFrameRate = aCodec.iReceiveFrameRate;
       
   135     
       
   136     SetConfigKeyL( aCodec.iConfigKey );
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CMceComVideoCodec::InternalizeFlatL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CMceComVideoCodec::InternalizeFlatL( RReadStream& aReadStream )
       
   145     {
       
   146     CMceComCodec::InternalizeFlatL( aReadStream );
       
   147 
       
   148     iFrameRate = aReadStream.ReadReal64L();
       
   149     iMaxBitRate = aReadStream.ReadUint32L();
       
   150     iAllowedResolutions = aReadStream.ReadUint32L();
       
   151     iResolutionWidth = aReadStream.ReadInt32L();
       
   152     iResolutionHeight = aReadStream.ReadInt32L();
       
   153     iAllowedFrameRates = aReadStream.ReadUint32L();
       
   154     iClockRate = aReadStream.ReadUint32L();
       
   155     iReceiveFrameRate = aReadStream.ReadReal64L();
       
   156     
       
   157     MceSerial::DecodeL( iConfigKey, aReadStream );
       
   158     
       
   159     iEncodingDecodingDevice.iUid = aReadStream.ReadUint32L();
       
   160     }
       
   161     
       
   162 // -----------------------------------------------------------------------------
       
   163 // CMceComVideoCodec::ExternalizeFlatL
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CMceComVideoCodec::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   167     {
       
   168     CMceComCodec::ExternalizeFlatL( aWriteStream );
       
   169     
       
   170     aWriteStream.WriteReal64L( iFrameRate );
       
   171     aWriteStream.WriteUint32L( iMaxBitRate );
       
   172     aWriteStream.WriteUint32L( iAllowedResolutions );
       
   173     aWriteStream.WriteInt32L( iResolutionWidth );
       
   174     aWriteStream.WriteInt32L( iResolutionHeight );
       
   175     aWriteStream.WriteUint32L( iAllowedFrameRates );
       
   176     aWriteStream.WriteUint32L( iClockRate );
       
   177     aWriteStream.WriteReal64L( iReceiveFrameRate );
       
   178     
       
   179     MceSerial::EncodeL( iConfigKey, aWriteStream );
       
   180     
       
   181     aWriteStream.WriteUint32L( iEncodingDecodingDevice.iUid );
       
   182     }
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CMceComVideoCodec::UpdateL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CMceComVideoCodec::UpdateL( CMceComCodec& aCodec )
       
   192     {
       
   193     CMceComCodec::UpdateL( aCodec );
       
   194 
       
   195     CMceComVideoCodec& codec = static_cast<CMceComVideoCodec&>( aCodec );
       
   196 
       
   197     iMaxBitRate = codec.iMaxBitRate;
       
   198     iAllowedResolutions = codec.iAllowedResolutions;
       
   199     iAllowedFrameRates = codec.iAllowedFrameRates;
       
   200     
       
   201     if ( IS_RECEIVESTREAM( iStream ) )
       
   202         {
       
   203         iFrameRate = codec.iFrameRate;
       
   204         iResolutionWidth = codec.iResolutionWidth;
       
   205         iResolutionHeight = codec.iResolutionHeight;
       
   206         iClockRate = codec.iClockRate;
       
   207         }
       
   208     else
       
   209         {       
       
   210         SetConfigKeyL( codec.iConfigKey );
       
   211         }
       
   212         
       
   213     iEncodingDecodingDevice = codec.iEncodingDecodingDevice;
       
   214     }
       
   215 
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CMceComVideoCodec::Factory
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TMceComVideoCodecFactory CMceComVideoCodec::Factory()
       
   222     {
       
   223     return TMceComVideoCodecFactory();
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CMceComVideoCodec::SetMaxBitrate
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TInt CMceComVideoCodec::SetMaxBitrate( TUint aMaxBitrate )
       
   231     {
       
   232     if ( aMaxBitrate )
       
   233         {
       
   234         iMaxBitRate = aMaxBitrate;
       
   235         return KErrNone;
       
   236         }
       
   237     else
       
   238         {
       
   239         return KErrArgument;
       
   240         }
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CMceComVideoCodec::GetMaxBitRate
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TUint CMceComVideoCodec::GetMaxBitRate()
       
   248     {
       
   249     return iMaxBitRate > 0 ? iMaxBitRate : iBitrate;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CMceComVideoCodec::CompareSdpIndex
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TInt CMceComVideoCodec::CompareSdpIndex( 
       
   257     const CMceComVideoCodec& aIndex1, 
       
   258     const CMceComVideoCodec& aIndex2 )
       
   259     {
       
   260     // NOTE: if zero (equals) is returned from here, order is strangely anyway
       
   261     // changed. Returning positive value if indexes are equal is for avoiding
       
   262     // this quirk.
       
   263 
       
   264     if ( aIndex1.iCodecSdpIndex >= aIndex2.iCodecSdpIndex )
       
   265         {
       
   266         return (1);
       
   267         }
       
   268     else if ( aIndex1.iCodecSdpIndex < aIndex2.iCodecSdpIndex )
       
   269         {
       
   270         return (-1);
       
   271         }
       
   272     else
       
   273         {
       
   274         return (0);
       
   275         } 
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CMceComVideoCodec::SetConfigKeyL
       
   280 // -----------------------------------------------------------------------------
       
   281 //                                 
       
   282 TBool CMceComVideoCodec::SetConfigKeyL( HBufC8* aConfigKey )
       
   283     {
       
   284     TBool updated( EFalse );
       
   285     if ( IsConfigKeyValid( aConfigKey ) )
       
   286         {
       
   287         // Set key only if none exists or new key differs from existing one
       
   288         if ( !iConfigKey || ( iConfigKey->Compare( *aConfigKey ) != 0 ) )
       
   289             { 
       
   290             HBufC8* configKey = aConfigKey->AllocL();
       
   291             delete iConfigKey;
       
   292             iConfigKey = configKey;
       
   293             updated = ETrue;
       
   294             }
       
   295         }
       
   296     return updated;
       
   297     }
       
   298 
       
   299 
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CMceComVideoCodec::IsConfigKeyValid
       
   303 // -----------------------------------------------------------------------------
       
   304 // 
       
   305 TBool CMceComVideoCodec::IsConfigKeyValid() const
       
   306     {
       
   307     return IsConfigKeyValid( iConfigKey );
       
   308     }
       
   309     
       
   310 // -----------------------------------------------------------------------------
       
   311 // CMceComVideoCodec::IsConfigKeyValid
       
   312 // -----------------------------------------------------------------------------
       
   313 //    
       
   314 TBool CMceComVideoCodec::IsConfigKeyValid( HBufC8* aConfigKey )
       
   315     {
       
   316     return ( aConfigKey && aConfigKey->Length() > 0 );
       
   317     }
       
   318     
       
   319 #ifdef MCE_COMMON_SERVER_SIDE
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CMceComVideoCodec::operator=
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 /*lint -e1539 */
       
   326 
       
   327 CMceComCodec& CMceComVideoCodec::operator=( CMccCodecInformation& aMccCodec )
       
   328     {
       
   329 
       
   330 	iPayloadType = aMccCodec.PayloadType();
       
   331 	iBitrate = aMccCodec.Bitrate();
       
   332 	iAllowedBitrates = aMccCodec.AllowedBitrates();
       
   333 	iCodecMode = aMccCodec.CodecMode();
       
   334 	iFourCC = aMccCodec.FourCC();
       
   335 	iFrameSize = aMccCodec.FrameSize();
       
   336 
       
   337     iFrameRate = aMccCodec.Framerate();
       
   338     iMaxBitRate = aMccCodec.MaxBitrate();
       
   339     iResolutionWidth = aMccCodec.FrameWidth();
       
   340     iResolutionHeight = aMccCodec.FrameHeight();
       
   341     iClockRate = aMccCodec.SamplingFreq();
       
   342     
       
   343     HBufC8* configKey = NULL;
       
   344     TRAPD( err, configKey = aMccCodec.ConfigKeyL() );
       
   345     if ( !err )
       
   346     	{
       
   347     	TRAP_IGNORE( SetConfigKeyL( configKey ) )	
       
   348     	}
       
   349     delete configKey;
       
   350     iEncodingDecodingDevice = aMccCodec.PreferredEncodingDecodingDevice();
       
   351 
       
   352     return *this;
       
   353     
       
   354     }
       
   355 
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CMceComVideoCodec::DoMccDecodeL
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CMceComVideoCodec::DoMccDecodeL( CMccCodecInformation& aMccCodec )
       
   362     {
       
   363     // copy values, which are not explicitely in SDP, from mcc codec
       
   364 	iClockRate = aMccCodec.SamplingFreq();
       
   365     iResolutionWidth = aMccCodec.FrameWidth();
       
   366     iResolutionHeight = aMccCodec.FrameHeight();
       
   367     iMaxBitRate = aMccCodec.MaxBitrate();
       
   368     HBufC8* configKey = aMccCodec.ConfigKeyL();
       
   369     CleanupStack::PushL( configKey );
       
   370     SetConfigKeyL( configKey );
       
   371     CleanupStack::PopAndDestroy( configKey );
       
   372     iEncodingDecodingDevice = aMccCodec.PreferredEncodingDecodingDevice();	
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // CMceComVideoCodec::DoMccEncodeL
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CMceComVideoCodec::DoMccEncodeL( CMccCodecInformation& aMccCodec,
       
   380                                       CMceSrvStream& aStream )
       
   381     {
       
   382     User::LeaveIfError( aMccCodec.SetSamplingFreq( iClockRate ) );
       
   383     User::LeaveIfError( aMccCodec.SetFrameWidth( iResolutionWidth ) );
       
   384     User::LeaveIfError( aMccCodec.SetFrameHeight( iResolutionHeight ) );
       
   385 	User::LeaveIfError( aMccCodec.SetMaxBitrate( iMaxBitRate ) );
       
   386     User::LeaveIfError( aMccCodec.SetAverageBitrate( iBitrate ) );
       
   387     User::LeaveIfError( aMccCodec.SetFramerate( iFrameRate ) );
       
   388     if ( IsConfigKeyValid() )
       
   389         {
       
   390         aMccCodec.SetConfigKeyL( *iConfigKey );
       
   391         }
       
   392     if ( aStream.Source().Data().iType == KMceRTPSource )
       
   393         {
       
   394         
       
   395 		CMceComRtpSource& rtpSource = 
       
   396 		    static_cast<CMceComRtpSource&> ( aStream.Source().Data() );
       
   397 	    
       
   398     	User::LeaveIfError( 
       
   399     	    aMccCodec.SetJitterBufInactivityTimeOut( rtpSource.iInactivityTimer ) );
       
   400     	User::LeaveIfError( 
       
   401     	    aMccCodec.SetJitterBufThreshold( rtpSource.iBufferTreshold ) );
       
   402     	User::LeaveIfError( 
       
   403     	    aMccCodec.SetJitterBufBufferLength( rtpSource.iBufferLength ) );
       
   404         }
       
   405     aMccCodec.SetPreferredEncodingDecodingDevice(iEncodingDecodingDevice);
       
   406     }
       
   407 
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CMceComVideoCodec::DoMccValidateL
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 CMceComCodec* CMceComVideoCodec::DoMccValidateL( CMccCodecInformation& aMccCodec,
       
   414                                          CMceSrvStream& aStream,
       
   415                                          TMceNegotiationRole aRole )
       
   416     {	
       
   417     // TBD: validate frame width and height
       
   418     // Explicitly call default implementation of DoMccValidateL in base class
       
   419     // to enable the check for codecMode
       
   420     return CMceComCodec::DoMccValidateL( aMccCodec, aStream, aRole );
       
   421     }
       
   422     
       
   423 // -----------------------------------------------------------------------------
       
   424 // CMceComAudioCodec::DoMccRequireSignalling
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TInt CMceComVideoCodec::DoMccRequireSignalling( 
       
   428     const CMceSrvStream& aStream,
       
   429     const CMccCodecInformation& aMccCurentCodec, 
       
   430     const CMccCodecInformation& aMccUpdateCodec ) const
       
   431     {
       
   432     TInt action = KMceNoSignalling;
       
   433 
       
   434     if ( aStream.StreamType() == CMceComMediaStream::EReceiveStream ||
       
   435          aStream.StreamType() == CMceComMediaStream::EReceiveOnlyStream )
       
   436         {
       
   437         if ( aMccCurentCodec.Framerate() != aMccUpdateCodec.Framerate() )
       
   438             {
       
   439             action = KMceRequiresSignalling;
       
   440             }
       
   441         }
       
   442     
       
   443     if ( aMccCurentCodec.FrameWidth() != aMccUpdateCodec.FrameWidth() ||
       
   444          aMccCurentCodec.FrameHeight() != aMccUpdateCodec.FrameHeight() )
       
   445         {
       
   446         action = KMceRequiresSignalling;
       
   447         }
       
   448         
       
   449     return action;
       
   450     
       
   451     }
       
   452     
       
   453 // -----------------------------------------------------------------------------
       
   454 // CMceComVideoCodec::DoMccAdjustL
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CMceComVideoCodec::DoMccAdjustL( CMccCodecInformation& aMccCodec,
       
   458                                       CMceSrvStream& aStream )
       
   459     {
       
   460 	if( aStream.Data().iStreamType == CMceComMediaStream::ESendStream ||
       
   461         aStream.Data().iStreamType == CMceComMediaStream::ESendOnlyStream )
       
   462 		{
       
   463 		User::LeaveIfError( aMccCodec.SetFramerate( iFrameRate ) );
       
   464 		User::LeaveIfError( aMccCodec.SetAverageBitrate( iBitrate ) );
       
   465 		}
       
   466     User::LeaveIfError( aMccCodec.SetFrameWidth( iResolutionWidth ) );
       
   467     User::LeaveIfError( aMccCodec.SetFrameHeight( iResolutionHeight ) );
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CMceComVideoCodec::DoSetDefaultFmtpAttributeL
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CMceComVideoCodec::DoSetDefaultFmtpAttributeL()
       
   475     {
       
   476     // NOP
       
   477     }
       
   478         
       
   479 #endif// MCE_COMMON_SERVER_SIDE
       
   480