multimediacommscontroller/mmccinterface/src/mmcccodecred.cpp
changeset 0 1bce908db942
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:    MCC Redundancy CodecInformation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "mmcccodecred.h"
       
    23 #include "mccuids.hrh"
       
    24 #include "mmccinterfacelogs.h"
       
    25 #include "mccinternalcodecs.h"
       
    26 
       
    27 
       
    28 // ============================= LOCAL FUNCTIONS ===============================
       
    29 
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMccCodecRed::CMccCodecRed
       
    35 // default constructor
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMccCodecRed::CMccCodecRed() : CMccCodecInformation()
       
    39     {
       
    40     
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CMccCodecRed::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CMccCodecRed::ConstructL()
       
    49     {
       
    50     iSdpName.Copy( KRedSdpName );
       
    51 
       
    52     iFmtpAttr = HBufC8::NewL( 1 );
       
    53     TPtr8 ptr = iFmtpAttr->Des();
       
    54     ptr.Append( KNullDesC );
       
    55     
       
    56     SetSamplingFreq( KRedSamplingFreq );
       
    57     EnableVAD( EFalse );
       
    58     SetMaxPTime( KRedMaxPTime ); // recommended "limit" 200ms
       
    59     SetPTime( KRedPTime ); // default 20ms 
       
    60     SetPayloadType( KDefaultRedPT );  
       
    61     
       
    62     iFourCC = KMccFourCCIdRed;
       
    63     iCodecMode = ENothing;
       
    64     
       
    65     iPayloadFormatEncoder = KImplUidRedPayloadFormatEncode;
       
    66     iPayloadFormatDecoder = KImplUidRedPayloadFormatDecode;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CMccCodecRed::NewLC
       
    71 // Static constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMccCodecRed* CMccCodecRed::NewL()
       
    75     {
       
    76     CMccCodecRed* self = new (ELeave) CMccCodecRed;
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self ); 
       
    80     return self;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CMccCodecRed::~CMccCodecRed
       
    85 // Destructor
       
    86 // -----------------------------------------------------------------------------   
       
    87 //
       
    88 CMccCodecRed::~CMccCodecRed()
       
    89     {
       
    90     iRedPayloads.Reset();
       
    91     iRedPayloads.Close();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMccCodecRed::RequireSignalling
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TBool CMccCodecRed::RequireSignalling(
       
    99     const CMccCodecInformation& aCandidate ) const      
       
   100     {
       
   101     __INTERFACE( "CMccCodecRed::RequireSignalling" )
       
   102     
       
   103     const CMccCodecRed& candidate = static_cast<const CMccCodecRed&>( aCandidate );
       
   104     
       
   105     TBool ret = EFalse;
       
   106     
       
   107     if ( iPTime != candidate.PTime() )
       
   108         {
       
   109         __INTERFACE( "CMccCodecRed::RequireSignalling, PTime changed" )
       
   110         ret = ETrue;
       
   111         }
       
   112         
       
   113     if ( iMaxPTime != candidate.MaxPTime() )
       
   114         {
       
   115         __INTERFACE( "CMccCodecRed::RequireSignalling, MaxPTime changed" )
       
   116         ret = ETrue;
       
   117         }
       
   118         
       
   119     if ( iPayloadType != candidate.PayloadType() )
       
   120         {
       
   121         __INTERFACE( "CMccCodecRed::RequireSignalling, PayloadType changed" )
       
   122         ret = ETrue;
       
   123         }
       
   124 
       
   125     if ( iCodecMode != candidate.CodecMode() )
       
   126         {
       
   127         __INTERFACE( "CMccCodecRed::RequireSignalling, CodecMode changed" )
       
   128         ret = ETrue;
       
   129         }     
       
   130     
       
   131     const RArray<TUint>& candidatePayloads = candidate.RedPayloads();    
       
   132     
       
   133     if ( candidatePayloads.Count() != iRedPayloads.Count() )
       
   134         {
       
   135         __INTERFACE( "CMccCodecRed::RequireSignalling, RedPayloads changed" )
       
   136         ret = ETrue;
       
   137         }
       
   138     else
       
   139         {
       
   140         for ( TInt i = 0; i < candidatePayloads.Count(); i++ )
       
   141             {
       
   142             if ( candidatePayloads[ i ] != iRedPayloads[ i ] )
       
   143                 {
       
   144                 __INTERFACE( "CMccCodecRed::RequireSignalling, RedPayload changed" )
       
   145                 ret = ETrue;
       
   146                 }
       
   147             }
       
   148         }
       
   149         
       
   150     __INTERFACE_INT1( "CMccCodecRed::RequireSignalling, exit with", ret )
       
   151     return ret;          
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CMccCodecRed::SetBitrate
       
   156 // Sets the bitrate used with Redundacy codec.
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TInt CMccCodecRed::SetBitrate( TUint aBitrate )
       
   160     {
       
   161     iBitrate = aBitrate;
       
   162     return KErrNone;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CMccCodecRed::SetSamplingFreq
       
   167 // Sets the sampling frequency. 
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 TInt CMccCodecRed::SetSamplingFreq( TUint32 aSamplingFreq )
       
   171     {
       
   172     iSamplingFreq = aSamplingFreq;
       
   173     return KErrNone;
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CMccCodecRed::SetSdpName
       
   178 // Sets the SDP name
       
   179 // -----------------------------------------------------------------------------
       
   180 TInt CMccCodecRed::SetSdpName( const TDesC8& aSdpName )
       
   181     {
       
   182     if ( !aSdpName.CompareF( KRedSdpName ) )
       
   183         {
       
   184         iSdpName.Copy( aSdpName );
       
   185         }
       
   186     else 
       
   187         {
       
   188         return KErrNotSupported;
       
   189         }
       
   190     
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CMccCodecRed::PayloadType
       
   196 // Sets the payload type
       
   197 // -----------------------------------------------------------------------------
       
   198 TInt CMccCodecRed::SetPayloadType( TUint8 aPayloadType )
       
   199     {
       
   200     if ( aPayloadType < KMinDynamicPT ||
       
   201          aPayloadType > KMaxPayloadType ) 
       
   202         {
       
   203         return KErrNotSupported;
       
   204         }
       
   205     else 
       
   206         {
       
   207         iPayloadType = aPayloadType;
       
   208         return KErrNone;
       
   209         }
       
   210     }
       
   211     
       
   212 // -----------------------------------------------------------------------------
       
   213 // CMccCodecRed::SetCodecMode
       
   214 // Sets the codec mode
       
   215 // -----------------------------------------------------------------------------
       
   216 TInt CMccCodecRed::SetCodecMode( TCodecMode aCodecMode )
       
   217     {
       
   218     if ( ENothing == aCodecMode )
       
   219         {
       
   220         iCodecMode = aCodecMode;
       
   221         return KErrNone;
       
   222         }
       
   223     else
       
   224         {
       
   225         return KErrNotSupported;
       
   226         }
       
   227     }
       
   228      
       
   229 // -----------------------------------------------------------------------------
       
   230 // CMccCodecRed::EnableVAD
       
   231 // 
       
   232 // -----------------------------------------------------------------------------
       
   233 TInt CMccCodecRed::EnableVAD( TBool aEnableVAD ) 
       
   234     {
       
   235     iEnableVAD = aEnableVAD;        
       
   236     return KErrNone;
       
   237     }
       
   238     
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CMccCodecRed::SetPTime
       
   242 //
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TInt CMccCodecRed::SetPTime( TUint aPTime )
       
   246     {
       
   247     if ( aPTime && ( KMinPtime <= aPTime ) &&  ( aPTime <= KMaxPtime ) && 
       
   248         (( aPTime % KMinPtime )  == 0 ))
       
   249         {
       
   250         iPTime = aPTime;
       
   251         return KErrNone;    
       
   252         }
       
   253     else
       
   254         {
       
   255         return KErrNotSupported;
       
   256         }
       
   257     }
       
   258     
       
   259 // -----------------------------------------------------------------------------
       
   260 // CMccCodecRed::SetMaxPTime
       
   261 //
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 TInt CMccCodecRed::SetMaxPTime( TUint aMaxPTime )
       
   265     {
       
   266     if ( aMaxPTime && ( iPTime <= aMaxPTime )&& ( KMinPtime <= aMaxPTime ) && 
       
   267         ( aMaxPTime <= KMaxPtime ) && (( aMaxPTime % KMinPtime )  == 0 ) )
       
   268         {
       
   269         iMaxPTime = aMaxPTime;
       
   270         return KErrNone;    
       
   271         }
       
   272     else
       
   273         {
       
   274         return KErrNotSupported;
       
   275         }
       
   276     }
       
   277     
       
   278 // -----------------------------------------------------------------------------
       
   279 // CMccCodecInformation::ParseFmtpAttr
       
   280 // Parses the fmtp attribute
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TBool CMccCodecRed::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   284     {
       
   285     // Parse codecs used for primary and secondary etc. codecs from the 
       
   286     // fmtp attribute
       
   287     // example fmtp attribute:
       
   288     // a=fmtp:99 0/103 
       
   289     // 99 is the redundancy format payload type
       
   290     // 0 is the primary codecs payload type
       
   291     // 103 is the secondary codecs payload type
       
   292     
       
   293     // NOTE: currently redundancy is allowed only for single payload type
       
   294     
       
   295     TBool updated( EFalse );
       
   296     
       
   297     TInt nextIndex = 0;
       
   298     TInt prevIndex = 0;
       
   299     TUint8 prevPayloadFormat = KMccPayloadTypeMax;
       
   300     HBufC8* modifyBuf = HBufC8::NewLC( aFmtp.Length() );
       
   301     TPtr8 pFmtpValue( modifyBuf->Des() );
       
   302     pFmtpValue = aFmtp;
       
   303     
       
   304     if( aFmtp.Length() > 0 )
       
   305         {   
       
   306         // Search for all the slashes and convert number strings between them
       
   307         // to integers    
       
   308         TBool found = ETrue;
       
   309         while( EFalse != found )
       
   310             {     
       
   311             pFmtpValue = modifyBuf->Mid( nextIndex );
       
   312             nextIndex = pFmtpValue.Locate( KCharSlash );          
       
   313             if( ( KErrNotFound == nextIndex ) ) 
       
   314                 {
       
   315                 found = EFalse;
       
   316                 if( 0 != pFmtpValue.Length() )
       
   317                     {
       
   318                     nextIndex = pFmtpValue.Length(); // Handle last payload value      
       
   319                     }
       
   320                 }
       
   321             if( 0 != pFmtpValue.Length() )
       
   322                 {
       
   323                 TLex8 lex = pFmtpValue.Mid( prevIndex, (nextIndex - prevIndex) );
       
   324                 TUint8 payloadFormat;
       
   325                 TInt err = lex.Val( payloadFormat, EDecimal );
       
   326                 if( KErrNone == err )
       
   327                     {
       
   328                     if ( prevPayloadFormat != KMccPayloadTypeMax &&
       
   329                          prevPayloadFormat != payloadFormat )
       
   330                          {
       
   331                          iRedPayloads.Reset();
       
   332                          User::Leave( KErrNotSupported );
       
   333                          }
       
   334                                      
       
   335                     iRedPayloads.AppendL( static_cast<TUint>( payloadFormat ) );  
       
   336                     updated = ETrue;  
       
   337                     prevPayloadFormat = payloadFormat;  
       
   338                     }
       
   339                     
       
   340                 nextIndex++;         
       
   341                 prevIndex = 0;
       
   342                 }
       
   343             }
       
   344         }
       
   345     
       
   346     CleanupStack::PopAndDestroy( modifyBuf );
       
   347     
       
   348     return updated;
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CMccCodecRed::SetAllowedBitrates
       
   353 // -----------------------------------------------------------------------------
       
   354 // 
       
   355 TInt CMccCodecRed::SetAllowedBitrates( TUint /*aBitrateMask*/ )
       
   356     {
       
   357     return KErrNone;           
       
   358     }
       
   359         
       
   360 // -----------------------------------------------------------------------------
       
   361 // CMccCodecRed::SetRedCodecs
       
   362 // Set the payload types used in redundancy
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CMccCodecRed::SetRedPayloadsL( RArray<TUint>& aRedPayloads )
       
   366     {
       
   367     iRedPayloads.Reset();
       
   368     TInt i;
       
   369     for( i = 0; i < aRedPayloads.Count(); i++ )
       
   370         {
       
   371         iRedPayloads.AppendL( aRedPayloads[ i ] );  
       
   372         }
       
   373     
       
   374     // Convert parsed payload formats back to string and set
       
   375     // the iFmtpAttr variable
       
   376     const TInt KCharsPerPayload( 4 );
       
   377     delete iFmtpAttr;
       
   378     iFmtpAttr = NULL;
       
   379     iFmtpAttr = HBufC8::NewL( iRedPayloads.Count() * KCharsPerPayload );
       
   380     
       
   381     TPtr8 descPtr = iFmtpAttr->Des();
       
   382     for( i = 0; i < iRedPayloads.Count(); i++ )
       
   383         {
       
   384         descPtr.AppendNum( static_cast<TUint64>( iRedPayloads[i] ), EDecimal );
       
   385         descPtr.Append( KCharSlash );       
       
   386         }   
       
   387     
       
   388     // Remove the last slash character
       
   389     descPtr.SetLength( descPtr.Length() - 1 );  
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CMccCodecRed::RedPayloadsL
       
   394 // Fills array with red payload type values
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 void CMccCodecRed::RedPayloadsL( RArray<TUint>& aRedPayloads ) const
       
   398     {
       
   399     for ( TInt i = 0; i < iRedPayloads.Count(); i++ )
       
   400         {
       
   401         aRedPayloads.AppendL( iRedPayloads[ i ] );
       
   402         }
       
   403     }
       
   404     
       
   405 // -----------------------------------------------------------------------------
       
   406 // CMccCodecInformation::RedPayloads
       
   407 // Return the reference to the redundancy codecs array
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 const RArray<TUint>& CMccCodecRed::RedPayloads() const
       
   411     {
       
   412     return iRedPayloads;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CMccCodecRed::CloneDefaultsL
       
   417 // Make a default setting clone from this Redundancy codec
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 CMccCodecInformation* CMccCodecRed::CloneDefaultsL()
       
   421     {
       
   422     return CMccCodecRed::NewL();
       
   423     }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CMCCAMRCodec::CloneDetailedL
       
   427 // Make a detailed clone from this Redundancy codec
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 CMccCodecInformation* CMccCodecRed::CloneDetailedL()
       
   431     {
       
   432     CMccCodecRed* newCodec = CMccCodecRed::NewL();
       
   433     CleanupStack::PushL( newCodec );   
       
   434     newCodec->SetBitrate( this->Bitrate() );
       
   435     newCodec->SetCodecMode( this->CodecMode() );
       
   436     newCodec->SetMaxPTime( this->MaxPTime() );
       
   437     newCodec->SetPayloadType( this->PayloadType() );
       
   438     newCodec->SetPTime( this->PTime() );
       
   439     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   440     newCodec->SetSdpName( this->SdpName() );
       
   441     newCodec->ParseFmtpAttrL( this->GetFmtpL() );
       
   442     CleanupStack::Pop( newCodec );       
       
   443     return newCodec;
       
   444     }
       
   445     
       
   446 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   447 
       
   448 
       
   449 //  End of File