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