multimediacommsengine/tsrc/mccstub/src/mmcccodecavc.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 
       
    22 // INCLUDE FILES
       
    23 #include "mmcccodecavc.h"
       
    24 #include "mccuids.hrh"
       
    25 #include "mmccinterfacelogs.h"
       
    26 
       
    27 #include "CMccController_stub.h"
       
    28 #include <delimitedpathsegment8.h>
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 
       
    34 // CONSTANTS
       
    35 const TInt KMaxFmtpAttrLength( 200 );
       
    36 const TInt KAvcDefaultFrameSize( 10000 );
       
    37 const TInt KAvcLevel1Bitrate( 64000 );
       
    38 const TInt KAvcLevel1bBitrate( 128000 );
       
    39 const TInt KAvcLevel11Bitrate( 192000 );
       
    40 const TInt KAvcLevel12Bitrate( 384000 );
       
    41 const TInt KAvcLevel13Bitrate( 768000 );
       
    42 const TInt KAvcLevel2Bitrate( 2000000 );
       
    43 const TInt KAvcDefaultFreq( 90000 );
       
    44 
       
    45 const TInt KAvcProfileLevelIdStrLen = 6;
       
    46 const TInt KAvcProfileLevelIdValLen = 2;
       
    47 const TUint KAvcProfileIopValueShift = 5;
       
    48 const TUint KAvcProfileIopFlagForLevel1b = 0x10;
       
    49 
       
    50 // MACROS
       
    51 
       
    52 // LOCAL CONSTANTS AND MACROS
       
    53 
       
    54 // MODULE DATA STRUCTURES
       
    55 
       
    56 // LOCAL FUNCTION PROTOTYPES
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 
       
    60 // ============================= LOCAL FUNCTIONS ===============================
       
    61 
       
    62 // ============================ MEMBER FUNCTIONS ===============================
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMccCodecAVC::CMccCodecAVC
       
    66 // C++ default constructor can NOT contain any code, that
       
    67 // might leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMccCodecAVC::CMccCodecAVC() : CMccCodecInformation()
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMccCodecAVC::ConstructL
       
    76 // Symbian 2nd phase constructor can leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CMccCodecAVC::ConstructL()
       
    80     {
       
    81     iSdpName.Copy( KAVCSdpName );
       
    82 
       
    83     iBitrateMask = KMccAvcCodecProfileIdBaseline | 
       
    84                    KMccAvcCodecProfileIopConstraintSet | 
       
    85                    KMccAvcBitrateLevel1;
       
    86     
       
    87     iType = KUidMediaTypeVideo; 
       
    88     iFmtpAttr = HBufC8::NewL( KMaxFmtpAttrLength );
       
    89     iFourCC = KMccFourCCIdAVC;
       
    90     iSamplingFreq = KAvcDefaultFreq;
       
    91 
       
    92     iPayloadFormatEncoder = KImplUidAvcPayloadFormatEncode;
       
    93     iPayloadFormatDecoder = 0;
       
    94 
       
    95     SetCodecMode( KAvcFormatModeSingleNal );
       
    96     SetPTime( KAvcPTime );
       
    97     SetPayloadType( KAvcPayloadType );
       
    98     SetFramerate( KAvcFramerate );
       
    99     SetLevelBasedBitrate( KAvcLevel1Bitrate );
       
   100     SetMaxBitrate( KAvcLevel1Bitrate );
       
   101     SetFrameHeight( KAvcFrameHeight );
       
   102     SetFrameWidth( KAvcFrameWidth );
       
   103     iFrameSize = KAvcDefaultFrameSize;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMccCodecAVC::NewL
       
   108 // Two-phased constructor.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CMccCodecAVC* CMccCodecAVC::NewL()
       
   112     {
       
   113     CMccCodecAVC* self = new( ELeave ) CMccCodecAVC;
       
   114     
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL();
       
   117     CleanupStack::Pop( self );
       
   118 
       
   119     return self;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMccCodecAVC::~CMccCodecAVC
       
   124 // 
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CMccCodecAVC::~CMccCodecAVC()
       
   128     {
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CMccCodecAVC::RequireSignalling
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TBool CMccCodecAVC::RequireSignalling(
       
   136     const CMccCodecInformation& aCandidate ) const      
       
   137     {
       
   138     return CMccCodecInformation::RequireSignalling( aCandidate );
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMccCodecAVC::GetFmtpL
       
   143 // Gets the fmtp attribute
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TDesC8& CMccCodecAVC::GetFmtpL()
       
   147     {
       
   148     return CMccCodecInformation::GetFmtpL();
       
   149     }    
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CMccCodecAVC::CreateFmtpAttrListL
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CMccCodecAVC::CreateFmtpAttrListL()
       
   156     {
       
   157     HBufC8* buf = HBufC8::NewLC( KMaxFmtpAttrLength ); 
       
   158     TPtr8 bufPtr = buf->Des();
       
   159     
       
   160     TBool previousParamAdded( EFalse );
       
   161     
       
   162     if ( CreateFmtpProfileLevelId( bufPtr ) )
       
   163         {
       
   164         previousParamAdded = ETrue;
       
   165         }
       
   166 
       
   167     TInt semicolonPos( bufPtr.Length() );
       
   168     
       
   169     if ( CreateFmtpPacketizationMode( bufPtr ) )
       
   170         {
       
   171         // Previous param was added, so we need a semi-colon and a space
       
   172         if ( previousParamAdded )
       
   173             {
       
   174             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
   175             }
       
   176         previousParamAdded = ETrue;
       
   177         }
       
   178     
       
   179     semicolonPos = bufPtr.Length();
       
   180     
       
   181     if ( CreateFmtpSpropParameterSets( bufPtr ) )
       
   182         {
       
   183         // Previous param was added, so we need a semi-colon and a space
       
   184         if ( previousParamAdded )
       
   185             {
       
   186             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
   187             }
       
   188         previousParamAdded = ETrue;
       
   189         }
       
   190         
       
   191     // Update iFmtpAttr
       
   192     SetFmtpAttrL( bufPtr, EFalse );
       
   193     
       
   194     CleanupStack::PopAndDestroy( buf );
       
   195     }
       
   196     
       
   197 // -----------------------------------------------------------------------------
       
   198 // CMccCodecAVC::ParseFmtpAttrL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TBool CMccCodecAVC::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   202     {
       
   203     // These booleans needed in FMTP parsing to handle where parameters
       
   204     // not present in FMTP
       
   205 
       
   206     iProfileLevelIdParamExists = EFalse;
       
   207     iPacketizationModeParamExists = EFalse;
       
   208     
       
   209     //Remove all white space from begining and end,
       
   210     //Convert the content of the descriptor to lower case
       
   211     const TUint8* pointerC = aFmtp.Ptr();
       
   212     TUint8* pointer        = const_cast<TUint8*>( pointerC );
       
   213     TPtr8 descriptor( pointer, aFmtp.Length(), aFmtp.Length() );
       
   214     descriptor.Trim();
       
   215     
       
   216     /*
       
   217     TDelimitedPathSegmentParser8 Parses path segments whose 
       
   218     components are delimited by the ';' character, 
       
   219     as defined in RFC2396.
       
   220     */
       
   221     TDelimitedPathSegmentParser8 parser;
       
   222     parser.Parse( aFmtp );
       
   223     TPtrC8 segment;
       
   224     TBool updated( EFalse );
       
   225     
       
   226     while ( parser.GetNext( segment ) != KErrNotFound )
       
   227         {
       
   228         if ( ParseFmtpSegmentL( segment ) )
       
   229             {
       
   230             updated = ETrue;
       
   231             }
       
   232         }
       
   233     
       
   234     if ( !iProfileLevelIdParamExists )
       
   235         {
       
   236         SetProfileLevelIdL( KMccAvcCodecProfileIdBaselineVal, 
       
   237                             DefaultProfileIopVal(),
       
   238                             KMccAvcCodecProfileLevel1Val );
       
   239         }
       
   240     
       
   241     if ( !iPacketizationModeParamExists )
       
   242         {
       
   243         User::LeaveIfError( SetCodecMode( KAvcFormatModeSingleNal ) );
       
   244         }
       
   245         
       
   246     return updated;
       
   247     }    
       
   248 
       
   249 // -----------------------------------------------------------------------------    
       
   250 // CMccCodecAVC::ParseFmtpSegmentL
       
   251 // Parse and updates the matched param
       
   252 // -----------------------------------------------------------------------------
       
   253 //    
       
   254 TBool CMccCodecAVC::ParseFmtpSegmentL( const TDesC8& aSeg )
       
   255     {
       
   256     TBool update( EFalse );
       
   257     _LIT8( KEqualSign, "=" );
       
   258     
       
   259     // Check for first '=' sign 
       
   260     TInt index = aSeg.Find( KEqualSign );
       
   261     
       
   262     if ( index > 0 )
       
   263         {
       
   264         // Check if match mode-set 
       
   265         if ( aSeg.Left( index ).Match( KMatchProfileLevelId ) != KErrNotFound )
       
   266             {
       
   267             update = ParseFmtpProfileLevelIdL( 
       
   268                             aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   269             iProfileLevelIdParamExists = ETrue;
       
   270             } 
       
   271         else if ( aSeg.Left( index ).Match( KMatchSpropParameterSets ) != KErrNotFound )
       
   272             {
       
   273             update = ParseFmtpSpropParameterSetsL( 
       
   274                             aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   275             }   
       
   276         else if ( aSeg.Left( index ).Match( KMatchPacketizationMode ) != KErrNotFound )
       
   277             {
       
   278             update = ParseFmtpPacketizationModeL( 
       
   279                             aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   280             iPacketizationModeParamExists = ETrue;
       
   281             }
       
   282         else
       
   283             {
       
   284             }
       
   285         }
       
   286   
       
   287     return update;
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CMccCodecAVC::ParseFmtpProfileLevelIdL
       
   292 // -----------------------------------------------------------------------------
       
   293 //    
       
   294 TBool CMccCodecAVC::ParseFmtpProfileLevelIdL( const TDesC8& aProfileLevelId )
       
   295     {
       
   296     // A base16 [6] (hexadecimal) representation of
       
   297     // the following three bytes in the sequence
       
   298     // parameter set NAL unit specified in [1]: 1)
       
   299     // profile_idc, 2) a byte herein referred to as
       
   300     // profile-iop, composed of the values of
       
   301     // constraint_set0_flag, constraint_set1_flag,
       
   302     // constraint_set2_flag, and reserved_zero_5bits
       
   303     // in bit-significance order, starting from the
       
   304     // most significant bit, and 3) level_idc.  Note
       
   305     // that reserved_zero_5bits is required to be
       
   306     // equal to 0 in [1], but other values for it may
       
   307     // be specified in the future by ITU-T or ISO/IEC.
       
   308 
       
   309     __ASSERT_ALWAYS( aProfileLevelId.Length() == KAvcProfileLevelIdStrLen, 
       
   310                      User::Leave( KErrArgument ) );
       
   311     
       
   312     TInt startPos( 0 );
       
   313     TLex8 profileIdLex( aProfileLevelId.Mid( startPos, KAvcProfileLevelIdValLen ) );
       
   314     startPos += KAvcProfileLevelIdValLen;
       
   315     TUint profileId( 0 );
       
   316     User::LeaveIfError( profileIdLex.Val( profileId, EHex ) );
       
   317 
       
   318 
       
   319     TLex8 profileIopLex( aProfileLevelId.Mid( startPos, KAvcProfileLevelIdValLen ) );
       
   320     startPos += KAvcProfileLevelIdValLen;
       
   321     TUint profileIop( 0 );
       
   322     User::LeaveIfError( profileIopLex.Val( profileIop, EHex ) );
       
   323     
       
   324     
       
   325     TLex8 profileLevelLex( aProfileLevelId.Mid( startPos, KAvcProfileLevelIdValLen ) );
       
   326     TUint profileLevel( 0 );
       
   327     User::LeaveIfError( profileLevelLex.Val( profileLevel, EHex ) );
       
   328     
       
   329     SetProfileLevelIdL( profileId, profileIop, profileLevel );
       
   330                   
       
   331     return ETrue;
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CMccCodecAVC::ParseFmtpSpropParameterSetsL
       
   336 // -----------------------------------------------------------------------------
       
   337 //    
       
   338 TBool CMccCodecAVC::ParseFmtpSpropParameterSetsL( const TDesC8& aSpropParameterSets )
       
   339     {
       
   340     const TInt KMccMaxSpropParameterSetLen = 100;
       
   341     __ASSERT_ALWAYS( aSpropParameterSets.Length() > 0 &&
       
   342                      aSpropParameterSets.Length() <= KMccMaxSpropParameterSetLen, 
       
   343                      User::Leave( KErrArgument ) );
       
   344     
       
   345     HBufC8* sprop = aSpropParameterSets.AllocL();
       
   346     delete iConfigKey;
       
   347     iConfigKey = sprop;
       
   348                 
       
   349     return ETrue;
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CMccCodecAVC::ParseFmtpPacketizationModeL
       
   354 // -----------------------------------------------------------------------------
       
   355 //    
       
   356 TBool CMccCodecAVC::ParseFmtpPacketizationModeL( const TDesC8& aPacketizationMode )
       
   357     {
       
   358     // Convert descriptor to integer
       
   359     TLex8 myLex( aPacketizationMode );
       
   360     TInt packetizationMode;
       
   361     User::LeaveIfError( myLex.Val( packetizationMode ) );
       
   362    
       
   363     User::LeaveIfError( SetCodecMode( packetizationMode ) );
       
   364                 
       
   365     return ETrue;
       
   366     }            
       
   367 // -----------------------------------------------------------------------------
       
   368 // CMccCodecAVC::SetBitrate
       
   369 // Sets the bitrate used with AMR codec.
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 TInt CMccCodecAVC::SetBitrate( TUint aBitrate )
       
   373     {
       
   374     if ( aBitrate > 0 && aBitrate <= KAvcLevel2Bitrate )
       
   375         {            
       
   376         iBitrate = aBitrate;
       
   377         iBitrateSet = ETrue;
       
   378         return KErrNone;
       
   379         }
       
   380     else
       
   381         {
       
   382         return KErrNotSupported;
       
   383         }
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CMccCodecAVC::SetSamplingFreq
       
   388 // Sets the sampling frequency. 
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 TInt CMccCodecAVC::SetSamplingFreq( TUint32 /*aSamplingFreq*/ )
       
   392     {
       
   393     return KErrNone;
       
   394     }
       
   395     
       
   396 // -----------------------------------------------------------------------------
       
   397 // CMccCodecAVC::SetSdpName
       
   398 // Sets the SDP name
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 TInt CMccCodecAVC::SetSdpName( const TDesC8& aSdpName )
       
   402     {
       
   403     if ( 0 == aSdpName.CompareF( KAVCSdpName ) )
       
   404         {
       
   405         iSdpName.Copy( aSdpName );
       
   406         }
       
   407     else 
       
   408         {
       
   409         return KErrNotSupported;
       
   410         }
       
   411     
       
   412     return KErrNone;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CMccCodecAVC::PayloadType
       
   417 // Sets the payload type
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 TInt CMccCodecAVC::SetPayloadType( TUint8 aPayloadType )
       
   421     {
       
   422     if ( aPayloadType < KMinDynamicPT ||
       
   423          aPayloadType > KMaxPayloadType ) 
       
   424         {
       
   425         return KErrNotSupported;
       
   426         }
       
   427     else 
       
   428         {
       
   429         iPayloadType = aPayloadType;
       
   430         }
       
   431               
       
   432     return KErrNone;
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CMccCodecAVC::SetCodecMode
       
   437 // Sets the codec mode
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TInt CMccCodecAVC::SetCodecMode( TCodecMode aCodecMode )
       
   441     {
       
   442     if ( KAvcFormatModeSingleNal == aCodecMode || 
       
   443          KAvcFormatModeNonInterleaved == aCodecMode )
       
   444         {
       
   445         iCodecMode = aCodecMode;
       
   446         return KErrNone;
       
   447         }
       
   448     else
       
   449         {
       
   450         return KErrNotSupported;
       
   451         }
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // CMccCodecAVC::SetFmtpAttrL
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 void CMccCodecAVC::SetFmtpAttrL( const TDesC8& /*aFmtp*/, TBool /*parseFmtp*/ )
       
   459     {
       
   460     if ( CMccControllerStub::Stub() && CMccControllerStub::Stub()->iSetFmtpFailure )
       
   461         {
       
   462         User::Leave( KErrNotSupported );
       
   463         }
       
   464     }
       
   465     
       
   466 
       
   467 TInt CMccCodecAVC::SetAllowedBitrates( TUint aBitrateMask )
       
   468     {
       
   469     //Confirm that the bitrate mask is valid
       
   470     //I.e. after all the valid bitrates are set to zero the value should be zero
       
   471     if ( (aBitrateMask >> 16 ) > 0 )
       
   472         {
       
   473         return KErrArgument;
       
   474         }
       
   475     else
       
   476         {
       
   477         SetBitrateMask( KMccAllowedAvcBitrateAll & aBitrateMask );
       
   478         SetBitrateMaskAdditionalInfo( aBitrateMask );
       
   479         
       
   480         SetBitrateFromBitrateMask( iBitrateMask );
       
   481         }
       
   482     
       
   483     return KErrNone;
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CMccCodecAVC::EnableVAD
       
   488 // Enable / Disable VAD
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 TInt CMccCodecAVC::EnableVAD( TBool /*aEnableVAD*/ ) 
       
   492     {
       
   493     return KErrNotSupported;
       
   494     }
       
   495     
       
   496 // -----------------------------------------------------------------------------
       
   497 // CMccCodecAVC::SetPTime
       
   498 // Set PTime
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 TInt CMccCodecAVC::SetPTime( TUint aPTime )
       
   502     {
       
   503     if ( ( aPTime <= 200 ) && (( aPTime % 10 )  == 0 ))
       
   504         {
       
   505         iPTime = aPTime;
       
   506         return KErrNone;    
       
   507         }
       
   508     else
       
   509         {
       
   510         return KErrNotSupported;
       
   511         }
       
   512     }
       
   513     
       
   514 // -----------------------------------------------------------------------------
       
   515 // CMccCodecAVC::SetMaxPTime
       
   516 // Set Max PTime
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 TInt CMccCodecAVC::SetMaxPTime( TUint aMaxPTime )
       
   520     {
       
   521     if ( ( aMaxPTime <= 200 ) && (( aMaxPTime % 10 )  == 0 ))
       
   522         {
       
   523         iMaxPTime = aMaxPTime;
       
   524         return KErrNone;    
       
   525         }
       
   526     else
       
   527         {
       
   528         return KErrNotSupported;
       
   529         }
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CMccCodecAVC::SetConfigKeyL
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CMccCodecAVC::SetConfigKeyL( const TDesC8& aConfigKey )
       
   537     {
       
   538     __ASSERT_ALWAYS( aConfigKey.Length() > 0, User::Leave( KErrArgument ) );
       
   539     
       
   540     HBufC8* key = aConfigKey.AllocL();
       
   541     delete iConfigKey;
       
   542     iConfigKey = key;
       
   543     }
       
   544     
       
   545 // -----------------------------------------------------------------------------
       
   546 // CMccCodecAVC::SetPreferredEncodingDecodingDevice
       
   547 // -----------------------------------------------------------------------------
       
   548 // 
       
   549 void CMccCodecAVC::SetPreferredEncodingDecodingDevice( 
       
   550 											TUid aEncodingDecodingDevice )
       
   551     {
       
   552     __INTERFACE( "CMccCodecAVC::SetPreferredEncodingDecodingDevice" )
       
   553     __INTERFACE_INT1("CMccCodecAVC::SetPreferredEncodingDecodingDevice aEncodingDecodingDevice:",aEncodingDecodingDevice.iUid)
       
   554     iEncodingDecodingDevice = aEncodingDecodingDevice;
       
   555     }
       
   556     
       
   557     
       
   558 // -----------------------------------------------------------------------------
       
   559 // CMccCodecAVC::CloneDefaultsL
       
   560 // Make a default setting clone from this codec
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 CMccCodecInformation* CMccCodecAVC::CloneDefaultsL()
       
   564     {
       
   565     return CMccCodecAVC::NewL();
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CMccCodecAVC::CloneDetailedL
       
   570 // Make a detailed clone from this codec
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 CMccCodecInformation* CMccCodecAVC::CloneDetailedL()
       
   574     {
       
   575     CMccCodecAVC* newCodec = CMccCodecAVC::NewL();
       
   576     CleanupStack::PushL( newCodec );       
       
   577     newCodec->SetBitrate( this->Bitrate() );
       
   578     newCodec->SetCodecMode( this->CodecMode() );
       
   579     newCodec->SetMaxPTime( this->MaxPTime() );
       
   580     newCodec->SetPayloadType( this->PayloadType() );
       
   581     newCodec->SetPTime( this->PTime() );
       
   582     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   583     newCodec->SetSdpName( this->SdpName() );
       
   584     newCodec->ParseFmtpAttrL( this->GetFmtpL() );
       
   585     CleanupStack::Pop( newCodec );   
       
   586     return newCodec;
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CMccCodecAVC:SetBitrateMask
       
   591 // -----------------------------------------------------------------------------
       
   592 // 
       
   593 void CMccCodecAVC::SetBitrateMask( TUint aBitrateMask, TBool aKeepAdditionalInfo )
       
   594     {
       
   595     __INTERFACE_INT1( "CMccCodecAVC::SetBitrateMask, entry mask ", aBitrateMask )      
       
   596     TUint oldBitrateMask = iBitrateMask; 
       
   597     iBitrateMask = aBitrateMask;
       
   598         
       
   599     if ( aKeepAdditionalInfo )
       
   600         {
       
   601         iBitrateMask |= ( oldBitrateMask & KMccAllowedAvcAdditionalInfo );
       
   602         }
       
   603     else
       
   604         {
       
   605         SetBitrateMaskAdditionalInfo( aBitrateMask );
       
   606         }
       
   607         
       
   608     __INTERFACE_INT1( "CMccCodecAVC::SetBitrateMask, exit mask ", iBitrateMask )      
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CMccCodecAVC:SetBitrateMaskAdditionalInfo
       
   613 // -----------------------------------------------------------------------------
       
   614 //    
       
   615 void CMccCodecAVC::SetBitrateMaskAdditionalInfo( TUint aAdditionalInfo )
       
   616     {
       
   617     iBitrateMask |= ( aAdditionalInfo & KMccAllowedAvcAdditionalInfo );
       
   618     }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CMccCodecAVC:SetProfileLevelIdL
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CMccCodecAVC::SetProfileLevelIdL( 
       
   625     TUint aProfileId, TUint aProfileIop, TUint aProfileLevel )
       
   626     {
       
   627     TUint allowedBitrates( 0 );
       
   628     __ASSERT_ALWAYS( aProfileId == KMccAvcCodecProfileIdBaselineVal, 
       
   629                      User::Leave( KErrNotSupported ) );                
       
   630     allowedBitrates |= KMccAvcCodecProfileIdBaseline;                
       
   631                      
       
   632     const TUint KProfileIopValueReservedBitsMask = 0xF;
       
   633     if ( aProfileIop & KProfileIopValueReservedBitsMask )
       
   634         {
       
   635         User::Leave( KErrNotSupported );
       
   636         }
       
   637     TUint profileIop = aProfileIop >> KAvcProfileIopValueShift;
       
   638     
       
   639     __ASSERT_ALWAYS( profileIop == KMccAvcCodecProfileIopConstraintSetVal, 
       
   640                      User::Leave( KErrNotSupported ) );
       
   641     allowedBitrates |= KMccAvcCodecProfileIopConstraintSet;       
       
   642     
       
   643     if ( aProfileLevel == KMccAvcCodecProfileLevel1Val )
       
   644         {
       
   645         allowedBitrates |= KMccAvcBitrateLevel1;
       
   646         }
       
   647     else if ( aProfileLevel == KMccAvcCodecProfileLevel1_1Val )
       
   648         {
       
   649         // Level 1b is differentiated from level 1.1 by iop constraint flag 3
       
   650         if( aProfileIop & KAvcProfileIopFlagForLevel1b )
       
   651             {
       
   652             allowedBitrates |= KMccAvcBitrateLevel1b;
       
   653             }
       
   654         else
       
   655             {
       
   656             allowedBitrates |= KMccAvcBitrateLevel1_1;
       
   657             }
       
   658         }
       
   659     else if ( aProfileLevel == KMccAvcCodecProfileLevel1_2Val )
       
   660         {
       
   661         allowedBitrates |= KMccAvcBitrateLevel1_2;
       
   662         }
       
   663     else if ( aProfileLevel == KMccAvcCodecProfileLevel1_3Val )
       
   664         {
       
   665         allowedBitrates |= KMccAvcBitrateLevel1_3;
       
   666         }
       
   667     else if ( aProfileLevel == KMccAvcCodecProfileLevel2Val )
       
   668         {
       
   669         allowedBitrates |= KMccAvcBitrateLevel2;
       
   670         }
       
   671     else
       
   672         {
       
   673         User::Leave( KErrNotSupported );
       
   674         }
       
   675                      
       
   676     User::LeaveIfError( SetAllowedBitrates( allowedBitrates ) );
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CMccCodecAVC:ProfileLevelIdVals
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 TInt CMccCodecAVC::ProfileLevelIdVals( 
       
   684     TUint& aProfileId, TUint& aProfileIop, TUint& aProfileLevel )
       
   685     {
       
   686     TInt retVal( KErrNone );            
       
   687     if ( iBitrateMask & KMccAvcCodecProfileIdBaseline )
       
   688         {
       
   689         aProfileId = KMccAvcCodecProfileIdBaselineVal;
       
   690         }
       
   691     else
       
   692         {
       
   693         retVal = KErrNotSupported;
       
   694         }
       
   695         
       
   696     if ( iBitrateMask & KMccAvcCodecProfileIopConstraintSet )
       
   697         {
       
   698         aProfileIop = KMccAvcCodecProfileIopConstraintSetVal << KAvcProfileIopValueShift;
       
   699         }
       
   700     else
       
   701         {
       
   702         retVal = KErrNotSupported;
       
   703         }
       
   704         
       
   705     if ( iBitrateMask & KMccAvcBitrateLevel1 )
       
   706         {
       
   707         aProfileLevel = KMccAvcCodecProfileLevel1Val;
       
   708         }
       
   709     else if ( iBitrateMask & KMccAvcBitrateLevel1b )
       
   710         {
       
   711         // Level 1b information is divided to level and iop fields
       
   712         //
       
   713         
       
   714         // Level 1.1
       
   715         aProfileLevel = KMccAvcCodecProfileLevel1_1Val;
       
   716         
       
   717         // And iop constraint_flag 3
       
   718         aProfileIop |= KAvcProfileIopFlagForLevel1b;
       
   719         }
       
   720     else if ( iBitrateMask & KMccAvcBitrateLevel1_1 )
       
   721         {
       
   722         aProfileLevel = KMccAvcCodecProfileLevel1_1Val;
       
   723         }
       
   724     else if ( iBitrateMask & KMccAvcBitrateLevel1_2 )
       
   725         {
       
   726         aProfileLevel = KMccAvcCodecProfileLevel1_2Val;
       
   727         }
       
   728     else if ( iBitrateMask & KMccAvcBitrateLevel1_3 )
       
   729         {
       
   730         aProfileLevel = KMccAvcCodecProfileLevel1_3Val;
       
   731         }
       
   732     else if ( iBitrateMask & KMccAvcBitrateLevel2 )
       
   733         {
       
   734         aProfileLevel = KMccAvcCodecProfileLevel2Val;
       
   735         }
       
   736     else
       
   737         {
       
   738         retVal = KErrNotSupported;
       
   739         }
       
   740     return retVal;
       
   741     }
       
   742     
       
   743 // -----------------------------------------------------------------------------
       
   744 // CMccCodecAVC::SetBitrateFromBitrateMask
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 TInt CMccCodecAVC::SetBitrateFromBitrateMask( TUint aBitrateMask )
       
   748     {
       
   749     TInt ret( KErrNone );
       
   750     if ( aBitrateMask & KMccAvcBitrateLevel1 )
       
   751         {
       
   752         SetMaxBitrate( KAvcLevel1Bitrate );
       
   753         SetLevelBasedBitrate( KAvcLevel1Bitrate );
       
   754         }
       
   755     else if ( aBitrateMask & KMccAvcBitrateLevel1b )
       
   756         {
       
   757         SetMaxBitrate( KAvcLevel1bBitrate );
       
   758         SetLevelBasedBitrate( KAvcLevel1bBitrate );
       
   759         }
       
   760     else if ( aBitrateMask & KMccAvcBitrateLevel1_1 )
       
   761         {
       
   762         SetMaxBitrate( KAvcLevel11Bitrate );
       
   763         SetLevelBasedBitrate( KAvcLevel11Bitrate );
       
   764         }
       
   765     else if ( aBitrateMask & KMccAvcBitrateLevel1_2 )
       
   766         {
       
   767         SetMaxBitrate( KAvcLevel12Bitrate );
       
   768         // Don't use max bitrate as it is way too high
       
   769         SetLevelBasedBitrate( KAvcLevel11Bitrate );
       
   770         }
       
   771     else if ( aBitrateMask & KMccAvcBitrateLevel1_3 )
       
   772         {
       
   773         SetMaxBitrate( KAvcLevel13Bitrate );
       
   774         // Don't use max bitrate as it is way too high
       
   775         SetLevelBasedBitrate( KAvcLevel11Bitrate );
       
   776         }
       
   777     else if ( aBitrateMask & KMccAvcBitrateLevel2 )
       
   778         {
       
   779         SetMaxBitrate( KAvcLevel2Bitrate );
       
   780         // Don't use max bitrate as it is way too high
       
   781         SetLevelBasedBitrate( KAvcLevel11Bitrate );
       
   782         }
       
   783     else
       
   784         {
       
   785         ret = KErrArgument;
       
   786         }
       
   787         
       
   788     return ret;
       
   789     }
       
   790 
       
   791 // -----------------------------------------------------------------------------
       
   792 // CMccCodecAVC::CreateFmtpProfileLevelId
       
   793 // -----------------------------------------------------------------------------
       
   794 //
       
   795 TBool CMccCodecAVC::CreateFmtpProfileLevelId( TDes8& aBuf )
       
   796     {
       
   797     TBool profileLevelIdAdded( EFalse );
       
   798     TUint profileId( 0 );
       
   799     TUint profileIop( 0 );
       
   800     TUint profileLevel( 0 );
       
   801     if ( ProfileLevelIdVals( profileId, profileIop, profileLevel ) == KErrNone )
       
   802         {
       
   803         aBuf.Append( KTxtProfileLevelId );
       
   804         aBuf.AppendNumFixedWidthUC( profileId, EHex, KAvcProfileLevelIdValLen ); 
       
   805         aBuf.AppendNumFixedWidthUC( profileIop, EHex, KAvcProfileLevelIdValLen ); 
       
   806         aBuf.AppendNumFixedWidthUC( profileLevel, EHex, KAvcProfileLevelIdValLen );
       
   807         profileLevelIdAdded = ETrue;
       
   808         }
       
   809     return profileLevelIdAdded;    
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // CMccCodecAVC::CreateFmtpPacketizationMode
       
   814 // -----------------------------------------------------------------------------
       
   815 // 
       
   816 TBool CMccCodecAVC::CreateFmtpPacketizationMode( TDes8& aBuf )
       
   817     {
       
   818     TBool packetizationModeAdded( EFalse );
       
   819     if ( iCodecMode != KAvcFormatModeSingleNal ) 
       
   820         {
       
   821         aBuf.Append( KTxtPacketizationMode );
       
   822         aBuf.AppendNum( iCodecMode );
       
   823         packetizationModeAdded = ETrue;       
       
   824         }
       
   825         
       
   826     return packetizationModeAdded;    
       
   827     }
       
   828     
       
   829 // -----------------------------------------------------------------------------
       
   830 // CMccCodecAVC::CreateFmtpSpropParameterSets
       
   831 // -----------------------------------------------------------------------------
       
   832 // 
       
   833 TBool CMccCodecAVC::CreateFmtpSpropParameterSets( TDes8& aBuf )
       
   834     {
       
   835     TBool spropParameterSetsAdded( EFalse );
       
   836     if ( iConfigKey ) 
       
   837         {
       
   838         aBuf.Append( KTxtSpropParameterSets );
       
   839         aBuf.Append( *iConfigKey );
       
   840         spropParameterSetsAdded = ETrue;       
       
   841         }
       
   842         
       
   843     return spropParameterSetsAdded;    
       
   844     }        
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // CMccCodecAVC::DefaultProfileIopVal
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 TUint CMccCodecAVC::DefaultProfileIopVal()
       
   851     {
       
   852     TUint profileIop = 
       
   853         KMccAvcCodecProfileIopConstraintSetVal << KAvcProfileIopValueShift;
       
   854     return profileIop;
       
   855     }
       
   856     
       
   857 // -----------------------------------------------------------------------------
       
   858 // CMccCodecAVC::SetLevelBasedBitrate
       
   859 // -----------------------------------------------------------------------------
       
   860 //      
       
   861 void CMccCodecAVC::SetLevelBasedBitrate( TUint aBitrate )
       
   862     {
       
   863     // Set level based bitrate only if bitrate value has not been set
       
   864     if ( !iBitrateSet )
       
   865         {
       
   866         iBitrate = aBitrate;
       
   867         }
       
   868     }
       
   869         
       
   870 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   871 
       
   872 //  End of File