multimediacommsengine/tsrc/mccstub/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     return CMccCodecInformation::RequireSignalling( aCandidate );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CMccCodecRed::SetBitrate
       
   106 // Sets the bitrate used with Redundacy codec.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt CMccCodecRed::SetBitrate( TUint aBitrate )
       
   110     {
       
   111     iBitrate = aBitrate;
       
   112     return KErrNone;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CMccCodecRed::SetSamplingFreq
       
   117 // Sets the sampling frequency. 
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt CMccCodecRed::SetSamplingFreq( TUint32 aSamplingFreq )
       
   121     {
       
   122     iSamplingFreq = aSamplingFreq;
       
   123     return KErrNone;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CMccCodecRed::SetSdpName
       
   128 // Sets the SDP name
       
   129 // -----------------------------------------------------------------------------
       
   130 TInt CMccCodecRed::SetSdpName( const TDesC8& aSdpName )
       
   131     {
       
   132     if ( !aSdpName.CompareF( KRedSdpName ) )
       
   133         {
       
   134         iSdpName.Copy( aSdpName );
       
   135         }
       
   136     else 
       
   137         {
       
   138         return KErrNotSupported;
       
   139         }
       
   140     
       
   141     return KErrNone;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMccCodecRed::PayloadType
       
   146 // Sets the payload type
       
   147 // -----------------------------------------------------------------------------
       
   148 TInt CMccCodecRed::SetPayloadType( TUint8 aPayloadType )
       
   149     {
       
   150     if ( aPayloadType < KMinDynamicPT ||
       
   151          aPayloadType > KMaxPayloadType ) 
       
   152         {
       
   153         return KErrNotSupported;
       
   154         }
       
   155     else 
       
   156         {
       
   157         iPayloadType = aPayloadType;
       
   158         return KErrNone;
       
   159         }
       
   160     }
       
   161     
       
   162 // -----------------------------------------------------------------------------
       
   163 // CMccCodecRed::SetCodecMode
       
   164 // Sets the codec mode
       
   165 // -----------------------------------------------------------------------------
       
   166 TInt CMccCodecRed::SetCodecMode( TCodecMode aCodecMode )
       
   167     {
       
   168     if ( ENothing == aCodecMode )
       
   169         {
       
   170         iCodecMode = aCodecMode;
       
   171         return KErrNone;
       
   172         }
       
   173     else
       
   174         {
       
   175         return KErrNotSupported;
       
   176         }
       
   177     }
       
   178      
       
   179 // -----------------------------------------------------------------------------
       
   180 // CMccCodecRed::EnableVAD
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 TInt CMccCodecRed::EnableVAD( TBool aEnableVAD ) 
       
   184     {
       
   185     iEnableVAD = aEnableVAD;        
       
   186     return KErrNone;
       
   187     }
       
   188     
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CMccCodecRed::SetPTime
       
   192 //
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CMccCodecRed::SetPTime( TUint aPTime )
       
   196     {
       
   197     if ( aPTime && ( KMinPtime <= aPTime ) &&  ( aPTime <= KMaxPtime ) && 
       
   198         (( aPTime % KMinPtime )  == 0 ))
       
   199         {
       
   200         iPTime = aPTime;
       
   201         return KErrNone;    
       
   202         }
       
   203     else
       
   204         {
       
   205         return KErrNotSupported;
       
   206         }
       
   207     }
       
   208     
       
   209 // -----------------------------------------------------------------------------
       
   210 // CMccCodecRed::SetMaxPTime
       
   211 //
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CMccCodecRed::SetMaxPTime( TUint aMaxPTime )
       
   215     {
       
   216     if ( aMaxPTime && ( iPTime <= aMaxPTime )&& ( KMinPtime <= aMaxPTime ) && 
       
   217         ( aMaxPTime <= KMaxPtime ) && (( aMaxPTime % KMinPtime )  == 0 ) )
       
   218         {
       
   219         iMaxPTime = aMaxPTime;
       
   220         return KErrNone;    
       
   221         }
       
   222     else
       
   223         {
       
   224         return KErrNotSupported;
       
   225         }
       
   226     }
       
   227     
       
   228 // -----------------------------------------------------------------------------
       
   229 // CMccCodecInformation::ParseFmtpAttr
       
   230 // Parses the fmtp attribute
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TBool CMccCodecRed::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   234     {
       
   235     // Parse codecs used for primary and secondary etc. codecs from the 
       
   236     // fmtp attribute
       
   237     // example fmtp attribute:
       
   238     // a=fmtp:99 0/103 
       
   239     // 99 is the redundancy format payload type
       
   240     // 0 is the primary codecs payload type
       
   241     // 103 is the secondary codecs payload type
       
   242     
       
   243     // NOTE: currently redundancy is allowed only for single payload type
       
   244     
       
   245     TBool updated( EFalse );
       
   246     
       
   247     TInt nextIndex = 0;
       
   248     TInt prevIndex = 0;
       
   249     TUint8 prevPayloadFormat = KMccPayloadTypeMax;
       
   250     HBufC8* modifyBuf = HBufC8::NewLC( aFmtp.Length() );
       
   251     TPtr8 pFmtpValue( modifyBuf->Des() );
       
   252     pFmtpValue = aFmtp;
       
   253     
       
   254     if( aFmtp.Length() > 0 )
       
   255         {   
       
   256         // Search for all the slashes and convert number strings between them
       
   257         // to integers    
       
   258         TBool found = ETrue;
       
   259         while( EFalse != found )
       
   260             {     
       
   261             pFmtpValue = modifyBuf->Mid( nextIndex );
       
   262             nextIndex = pFmtpValue.Locate( KCharSlash );          
       
   263             if( ( KErrNotFound == nextIndex ) ) 
       
   264                 {
       
   265                 found = EFalse;
       
   266                 if( 0 != pFmtpValue.Length() )
       
   267                     {
       
   268                     nextIndex = pFmtpValue.Length(); // Handle last payload value      
       
   269                     }
       
   270                 }
       
   271             if( 0 != pFmtpValue.Length() )
       
   272                 {
       
   273                 TLex8 lex = pFmtpValue.Mid( prevIndex, (nextIndex - prevIndex) );
       
   274                 TUint8 payloadFormat;
       
   275                 TInt err = lex.Val( payloadFormat, EDecimal );
       
   276                 if( KErrNone == err )
       
   277                     {
       
   278                     if ( prevPayloadFormat != KMccPayloadTypeMax &&
       
   279                          prevPayloadFormat != payloadFormat )
       
   280                          {
       
   281                          iRedPayloads.Reset();
       
   282                          User::Leave( KErrNotSupported );
       
   283                          }
       
   284                                      
       
   285                     iRedPayloads.AppendL( static_cast<TUint>( payloadFormat ) );  
       
   286                     updated = ETrue;  
       
   287                     prevPayloadFormat = payloadFormat;  
       
   288                     }
       
   289                     
       
   290                 nextIndex++;         
       
   291                 prevIndex = 0;
       
   292                 }
       
   293             }
       
   294         }
       
   295     
       
   296     CleanupStack::PopAndDestroy( modifyBuf );
       
   297     
       
   298     return updated;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CMccCodecRed::SetAllowedBitrates
       
   303 // -----------------------------------------------------------------------------
       
   304 // 
       
   305 TInt CMccCodecRed::SetAllowedBitrates( TUint /*aBitrateMask*/ )
       
   306     {
       
   307     return KErrNone;           
       
   308     }
       
   309         
       
   310 // -----------------------------------------------------------------------------
       
   311 // CMccCodecRed::SetRedCodecs
       
   312 // Set the payload types used in redundancy
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CMccCodecRed::SetRedPayloadsL( RArray<TUint>& aRedPayloads )
       
   316     {
       
   317     iRedPayloads.Reset();
       
   318     TInt i;
       
   319     for( i = 0; i < aRedPayloads.Count(); i++ )
       
   320         {
       
   321         iRedPayloads.AppendL( aRedPayloads[ i ] );  
       
   322         }
       
   323     
       
   324     // Convert parsed payload formats back to string and set
       
   325     // the iFmtpAttr variable
       
   326     const TInt KCharsPerPayload( 4 );
       
   327     delete iFmtpAttr;
       
   328     iFmtpAttr = NULL;
       
   329     iFmtpAttr = HBufC8::NewL( iRedPayloads.Count() * KCharsPerPayload );
       
   330     
       
   331     TPtr8 descPtr = iFmtpAttr->Des();
       
   332     for( i = 0; i < iRedPayloads.Count(); i++ )
       
   333         {
       
   334         descPtr.AppendNum( static_cast<TUint64>( iRedPayloads[i] ), EDecimal );
       
   335         descPtr.Append( KCharSlash );       
       
   336         }   
       
   337     
       
   338     // Remove the last slash character
       
   339     descPtr.SetLength( descPtr.Length() - 1 );  
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CMccCodecRed::RedPayloadsL
       
   344 // Fills array with red payload type values
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CMccCodecRed::RedPayloadsL( RArray<TUint>& aRedPayloads ) const
       
   348     {
       
   349     for ( TInt i = 0; i < iRedPayloads.Count(); i++ )
       
   350         {
       
   351         aRedPayloads.AppendL( iRedPayloads[ i ] );
       
   352         }
       
   353     }
       
   354     
       
   355 // -----------------------------------------------------------------------------
       
   356 // CMccCodecInformation::RedPayloads
       
   357 // Return the reference to the redundancy codecs array
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 const RArray<TUint>& CMccCodecRed::RedPayloads() const
       
   361     {
       
   362     return iRedPayloads;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CMccCodecRed::CloneDefaultsL
       
   367 // Make a default setting clone from this Redundancy codec
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 CMccCodecInformation* CMccCodecRed::CloneDefaultsL()
       
   371     {
       
   372     return CMccCodecRed::NewL();
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // CMCCAMRCodec::CloneDetailedL
       
   377 // Make a detailed clone from this Redundancy codec
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 CMccCodecInformation* CMccCodecRed::CloneDetailedL()
       
   381     {
       
   382     CMccCodecRed* newCodec = CMccCodecRed::NewL();
       
   383     CleanupStack::PushL( newCodec );   
       
   384     newCodec->SetBitrate( this->Bitrate() );
       
   385     newCodec->SetCodecMode( this->CodecMode() );
       
   386     newCodec->SetMaxPTime( this->MaxPTime() );
       
   387     newCodec->SetPayloadType( this->PayloadType() );
       
   388     newCodec->SetPTime( this->PTime() );
       
   389     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   390     newCodec->SetSdpName( this->SdpName() );
       
   391     newCodec->ParseFmtpAttrL( this->GetFmtpL() );
       
   392     CleanupStack::Pop( newCodec );       
       
   393     return newCodec;
       
   394     }
       
   395     
       
   396 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   397 
       
   398 
       
   399 //  End of File