multimediacommsengine/mmcecli/src/mceavccodec.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mceavccodec.h"
       
    22 #include "mcecomavccodec.h"
       
    23 #include "mcevideostream.h"
       
    24 
       
    25 
       
    26 #define _FLAT_DATA static_cast<CMceComAvcCodec*>( iFlatData )
       
    27 #define FLAT_DATA( data ) _FLAT_DATA->data
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CMceAvcCodec::~CMceAvcCodec
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CMceAvcCodec::~CMceAvcCodec()
       
    36     {
       
    37     }
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CMceAvcCodec::NewL
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CMceAvcCodec* CMceAvcCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    45     {
       
    46     CMceAvcCodec* self = NewLC( aSdpName );
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMceAvcCodec::NewL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CMceAvcCodec* CMceAvcCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    57     {
       
    58     CMceAvcCodec* self = new (ELeave) CMceAvcCodec();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL( aSdpName );
       
    61     return self;
       
    62     }
       
    63 
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMceAvcCodec::SetBitrate
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C TInt CMceAvcCodec::SetBitrate( TUint aBitrate )
       
    70     {
       
    71     if ( aBitrate != Bitrate() )
       
    72         {
       
    73         TInt ret = _FLAT_DATA->SetBitrate( aBitrate );
       
    74         if ( ret == KErrNone )
       
    75             {
       
    76             CMceVideoStream* stream = static_cast< CMceVideoStream* >( iStream );
       
    77             if ( stream && stream->BoundStream() )
       
    78                 {
       
    79                 // Find the same codec in bound stream, and set bitrate also to that.
       
    80                 CMceCodec* codec = stream->Bound()->FindCodec( *this );
       
    81                 if ( codec )
       
    82                     {
       
    83                     ret = codec->SetBitrate( aBitrate );
       
    84                     }
       
    85                 }                
       
    86             }
       
    87         return ret;
       
    88         }
       
    89     else
       
    90         {
       
    91         // Avoid looping, go here if already set
       
    92         return KErrNone;
       
    93         }
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CMceAvcCodec::SetAllowedBitrates
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C TInt CMceAvcCodec::SetAllowedBitrates(TUint aBitrates)
       
   102     {
       
   103     if ( aBitrates != AllowedBitrates() )
       
   104         {
       
   105         TInt ret = _FLAT_DATA->SetAllowedBitrates( aBitrates );
       
   106         if ( ret == KErrNone )
       
   107             {
       
   108             CMceVideoStream* stream = static_cast< CMceVideoStream* >( iStream );
       
   109             if ( stream && stream->BoundStream() )
       
   110                 {
       
   111                 // Find the same codec in bound stream, and set bitrates also to that.
       
   112                 CMceCodec* codec = stream->Bound()->FindCodec( *this );
       
   113                 if ( codec )
       
   114                     {
       
   115                     ret = codec->SetAllowedBitrates( aBitrates );
       
   116                     }
       
   117                 }
       
   118             }
       
   119         return ret;
       
   120         }
       
   121     else
       
   122         {
       
   123         // Avoid looping, go here if already set
       
   124         return KErrNone;
       
   125         }
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMceAvcCodec::SetCodecMode
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C TInt CMceAvcCodec::SetCodecMode( TUint aCodecMode )
       
   134     {
       
   135     TInt ret( KErrNone );
       
   136     if ( aCodecMode != KMceAvcModeSingleNal &&
       
   137          aCodecMode != KMceAvcModeNonInterleaved )
       
   138         {
       
   139         ret = KErrNotSupported;
       
   140         }
       
   141     else if ( aCodecMode != CodecMode() )
       
   142         {
       
   143         FLAT_DATA( iCodecMode ) = aCodecMode;
       
   144         CMceVideoStream* stream = static_cast< CMceVideoStream* >( iStream );
       
   145         if ( stream && stream->BoundStream() )
       
   146             {
       
   147             // Find the same codec in bound stream, and set mode also to that.
       
   148             CMceCodec* codec = stream->Bound()->FindCodec( *this );
       
   149             if ( codec )
       
   150                 {
       
   151                 ret = codec->SetCodecMode( aCodecMode );
       
   152                 }
       
   153             }
       
   154         }
       
   155     else
       
   156         {
       
   157         // Avoid looping, go here if already set
       
   158         }
       
   159         
       
   160     return ret;
       
   161     }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CMceAvcCodec::SetPayloadType
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C TInt CMceAvcCodec::SetPayloadType(TUint8 aPayloadType)
       
   169     {
       
   170     return _FLAT_DATA->SetPayloadType( aPayloadType );
       
   171     }        
       
   172 
       
   173     
       
   174 // -----------------------------------------------------------------------------
       
   175 // CMceAvcCodec::CloneL
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C CMceVideoCodec* CMceAvcCodec::CloneL() const
       
   179     {
       
   180     CMceAvcCodec* clone = CMceAvcCodec::NewLC( FLAT_DATA( iSdpName ) );
       
   181     
       
   182     CMceComAvcCodec* cloneFlatData = 
       
   183             static_cast<CMceComAvcCodec*>(clone->iFlatData);
       
   184             
       
   185 	cloneFlatData->iID = FLAT_DATA( iID );
       
   186     cloneFlatData->SetFmtpAttributeL( *(FLAT_DATA( iFmtpAttr )) );
       
   187     cloneFlatData->iPayloadType = FLAT_DATA( iPayloadType );
       
   188     
       
   189 	cloneFlatData->iBitrate = FLAT_DATA( iBitrate );
       
   190 	cloneFlatData->iAllowedBitrates = FLAT_DATA( iAllowedBitrates );
       
   191     cloneFlatData->iCodecMode = FLAT_DATA( iCodecMode );
       
   192 	cloneFlatData->iFourCC = FLAT_DATA( iFourCC );
       
   193 	cloneFlatData->iFrameSize = FLAT_DATA( iFrameSize );
       
   194 	
       
   195 	cloneFlatData->iFrameRate = FLAT_DATA( iFrameRate );
       
   196 	cloneFlatData->iMaxBitRate = FLAT_DATA( iMaxBitRate );	
       
   197 	cloneFlatData->iAllowedResolutions = FLAT_DATA( iAllowedResolutions );	
       
   198 	cloneFlatData->iResolutionWidth = FLAT_DATA( iResolutionWidth );	
       
   199 	cloneFlatData->iResolutionHeight = FLAT_DATA( iResolutionHeight );	
       
   200 	cloneFlatData->iAllowedFrameRates = FLAT_DATA( iAllowedFrameRates );	
       
   201 	cloneFlatData->iClockRate = FLAT_DATA( iClockRate );
       
   202 	
       
   203 	cloneFlatData->iPacketizationMode = FLAT_DATA( iPacketizationMode );
       
   204 	cloneFlatData->iAllowedPacketizationModes = 
       
   205 	    FLAT_DATA( iAllowedPacketizationModes );
       
   206 	
       
   207 	CleanupStack::Pop( clone );
       
   208     return clone;
       
   209     }
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CMceAvcCodec::
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C void CMceAvcCodec::SetMaxBitrateL( TUint aMaxBitrate )
       
   217     {
       
   218     User::LeaveIfError( _FLAT_DATA->SetMaxBitrate( aMaxBitrate ) );
       
   219     }
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CMceAvcCodec::
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C void CMceAvcCodec::SetAllowedResolutionsL( TUint aResolutions )
       
   227     {
       
   228     FLAT_DATA( iAllowedResolutions ) = aResolutions;
       
   229     }
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CMceAvcCodec::
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 EXPORT_C void CMceAvcCodec::SetResolutionL( TSize aResolution )
       
   237     {
       
   238     FLAT_DATA( iResolutionWidth ) = aResolution.iWidth;
       
   239     FLAT_DATA( iResolutionHeight ) = aResolution.iHeight;
       
   240     }
       
   241 
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CMceAvcCodec::
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 EXPORT_C void CMceAvcCodec::SetAllowedFrameRatesL( TUint aFrameRates )
       
   248     {
       
   249     FLAT_DATA( iAllowedFrameRates ) = aFrameRates;
       
   250     }
       
   251 
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CMceAvcCodec::
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 EXPORT_C void CMceAvcCodec::SetFrameRateL( TReal aFrameRate )
       
   258     {
       
   259     FLAT_DATA( iFrameRate ) = aFrameRate;
       
   260     }
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMceAvcCodec::SetPreferredEncodingDecodingDeviceL
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CMceAvcCodec::SetPreferredEncodingDecodingDeviceL( 
       
   268     TUid aEncodingDecodingDevice )
       
   269     {
       
   270     FLAT_DATA( iEncodingDecodingDevice ) = aEncodingDecodingDevice;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CMceAvcCodec::SetConfigKeyL
       
   275 // -----------------------------------------------------------------------------
       
   276 //        
       
   277 EXPORT_C void CMceAvcCodec::SetConfigKeyL( const TDesC8& aConfigKey )
       
   278     {
       
   279     HBufC8* configKey = aConfigKey.AllocLC();
       
   280     _FLAT_DATA->SetConfigKeyL( configKey );
       
   281     CleanupStack::PopAndDestroy( configKey );
       
   282     
       
   283     }
       
   284     
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CMceAvcCodec::SetSdpNameL
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CMceAvcCodec::SetSdpNameL( const TDesC8& aSdpName )
       
   291     {
       
   292     __ASSERT_ALWAYS( aSdpName.Length() <= KMceMaxSdpNameLength, 
       
   293                      User::Leave( KErrArgument ) );
       
   294     FLAT_DATA( iSdpName ).Copy( aSdpName );
       
   295     }
       
   296         
       
   297 // -----------------------------------------------------------------------------
       
   298 // CMceAvcCodec::CMceAvcCodec
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 CMceAvcCodec::CMceAvcCodec()
       
   302     :CMceVideoCodec()
       
   303     {
       
   304     }
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CMceAvcCodec::ConstructL
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CMceAvcCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   312     {
       
   313     CMceComVideoCodec* codec = CMceComAvcCodec::NewLC( aSdpName );
       
   314     CMceVideoCodec::ConstructL( codec );
       
   315 
       
   316     CleanupStack::Pop( codec );
       
   317     }
       
   318 
       
   319 
       
   320 
       
   321