multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesdpcodec.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 
       
    24 #include <sdpdocument.h>
       
    25 
       
    26 #include <sdpcodecstringconstants.h>
       
    27 #include <sdpcodecstringpool.h>
       
    28 #include <sdpmediafield.h>
       
    29 #include <sdpattributefield.h>
       
    30 #include <sdprtpmapvalue.h>
       
    31 #include <sdpfmtattributefield.h>
       
    32 #include <mmcccodecinformation.h>
       
    33 
       
    34 #include "mcesdpcodec.h"
       
    35 #include "mcecomcodec.h"
       
    36 #include "mcemmlogs.h"
       
    37 
       
    38 
       
    39 const TChar KMceRealPoint = '.';
       
    40 
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CMceSdpCodec::CMceSdpCodec
       
    46 // -----------------------------------------------------------------------------
       
    47 CMceSdpCodec::CMceSdpCodec( RStringF aMedia )
       
    48     : iMedia( aMedia )
       
    49     {
       
    50     }
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMceSdpCodec::~CMceSdpCodec
       
    55 // -----------------------------------------------------------------------------
       
    56 CMceSdpCodec::~CMceSdpCodec()
       
    57     {
       
    58     iMedia.Close();
       
    59     delete iCapabilities;
       
    60     iStringTable = NULL;
       
    61     iCapabilitiesPT.Close();
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CMceSdpCodec::ConstructL
       
    66 // ---------------------------------------------------------
       
    67 void CMceSdpCodec::ConstructL()
       
    68     {
       
    69 
       
    70     iStringPool = SdpCodecStringPool::StringPoolL();
       
    71     iStringTable = &SdpCodecStringPool::StringTableL();
       
    72     
       
    73     iCapabilities = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
    74     iCapabilitiesPT.Reset();
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMceSdpCodec::Media
       
    79 // -----------------------------------------------------------------------------
       
    80 RStringF CMceSdpCodec::Media()
       
    81     {
       
    82     return iMedia;
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMceSdpCodec::Decodes
       
    88 // -----------------------------------------------------------------------------
       
    89 TBool CMceSdpCodec::Decodes( const CSdpMediaField& aMedia ) const
       
    90     {
       
    91     return iMedia == aMedia.Media();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMceSdpCodec::AddCapabilityL
       
    96 // -----------------------------------------------------------------------------
       
    97 void CMceSdpCodec::AddCapabilityL( const TDesC8& aCapability )
       
    98     {
       
    99     iCapabilities->AppendL( aCapability );
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CMceSdpCodec::AddCapabilityPayloadTypeL
       
   104 // -----------------------------------------------------------------------------
       
   105 void CMceSdpCodec::AddCapabilityPayloadTypeL( const TUint aPayloadType )
       
   106     {
       
   107     iCapabilitiesPT.AppendL(aPayloadType);
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CMceSdpCodec::IsSupported
       
   112 // -----------------------------------------------------------------------------
       
   113 TBool CMceSdpCodec::IsSupported( const TDesC8& aCapability ) const
       
   114     {
       
   115     TBool isSupported = EFalse;
       
   116     TInt index = 0;
       
   117     
       
   118     while( !isSupported && index < iCapabilities->Count() )
       
   119         {
       
   120         isSupported = !aCapability.CompareF( iCapabilities->MdcaPoint( index ++ ) );
       
   121         }
       
   122     
       
   123     return isSupported;
       
   124     
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CMceSdpCodec::IsPayloadTypeSupported
       
   129 // -----------------------------------------------------------------------------
       
   130 TBool CMceSdpCodec::IsPayloadTypeSupported( const TDesC8& aCapability, const TUint aPayloadType ) const
       
   131     {
       
   132     TBool isSupported = EFalse;
       
   133     TInt index = 0;
       
   134     
       
   135     while( !isSupported && index < iCapabilities->Count() )
       
   136         {
       
   137         if ( !aCapability.CompareF( iCapabilities->MdcaPoint( index ) ) &&  index < iCapabilitiesPT.Count())
       
   138         	{
       
   139         	if (iCapabilitiesPT [ index ] >= KMinDynamicPT || iCapabilitiesPT [ index ] == aPayloadType)
       
   140         		{
       
   141         		isSupported = ETrue;
       
   142         		}
       
   143         	}
       
   144         index ++;
       
   145         }
       
   146     
       
   147     return isSupported;
       
   148     
       
   149 }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CMceSdpCodec::Direction
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TInt CMceSdpCodec::Direction( 
       
   156     CSdpMediaField& aMedia, 
       
   157     RPointerArray<CSdpAttributeField>& aSessionAttributes ) const
       
   158     {
       
   159     
       
   160     TInt direction = KErrNotFound;
       
   161     TInt index = 0;
       
   162     
       
   163     // look for the direction attribute, go through all attribute fields.
       
   164     while( direction == KErrNotFound && index < aSessionAttributes.Count() )
       
   165         {
       
   166         RStringF attribute = aSessionAttributes[index++]->Attribute();
       
   167         
       
   168         if ( attribute == SDP_STRING( SdpCodecStringConstants::EAttributeSendonly ) ||
       
   169              attribute == SDP_STRING( SdpCodecStringConstants::EAttributeRecvonly ) ||
       
   170              attribute == SDP_STRING( SdpCodecStringConstants::EAttributeInactive ) ||
       
   171              attribute == SDP_STRING( SdpCodecStringConstants::EAttributeSendrecv ) )
       
   172             {
       
   173             // downlink
       
   174             direction = attribute.Index( *iStringTable );
       
   175             }
       
   176         }
       
   177         
       
   178     if ( direction == KErrNotFound )
       
   179         {
       
   180         index = 0;
       
   181         
       
   182         RPointerArray<CSdpAttributeField>& attrfields = aMedia.AttributeFields();
       
   183         // look for the direction attribute, go through all attribute fields. if not
       
   184         // found then use the default sendrcv
       
   185         while( direction == KErrNotFound && index < attrfields.Count() )
       
   186             {
       
   187     
       
   188             RStringF attribute = attrfields[index++]->Attribute();
       
   189             if ( attribute == SDP_STRING( SdpCodecStringConstants::EAttributeSendonly ) ||
       
   190                  attribute == SDP_STRING( SdpCodecStringConstants::EAttributeRecvonly ) ||
       
   191                  attribute == SDP_STRING( SdpCodecStringConstants::EAttributeInactive ) ||
       
   192                  attribute == SDP_STRING( SdpCodecStringConstants::EAttributeSendrecv ) )
       
   193                 {
       
   194                 // downlink
       
   195                 direction = attribute.Index( *iStringTable );
       
   196                 }
       
   197             
       
   198             }
       
   199         }
       
   200          
       
   201     return direction;
       
   202     
       
   203     }
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMceSdpCodec::PrepareForEncodeL
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CMceSdpCodec::PrepareForEncodeL( CMceComMediaStream& /*aStream*/,
       
   213                                            CSdpMediaField& aMediaLine )
       
   214     {
       
   215     __ASSERT_ALWAYS( aMediaLine.IsValid(),
       
   216                      User::Leave( KErrArgument ) );
       
   217     CleanAttributes( aMediaLine );
       
   218     if( aMediaLine.Key() )
       
   219     	{
       
   220     	aMediaLine.SetKey(NULL);
       
   221     	}
       
   222     }
       
   223 
       
   224 
       
   225     
       
   226 // -----------------------------------------------------------------------------
       
   227 // CMceSdpCodec::EncodeRtpMapFieldsL
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 CSdpFmtAttributeField* CMceSdpCodec::EncodeRtpMapFieldsL( 
       
   231     const TUint8 aPayloadType,
       
   232     const TDesC8& aEncodingName,
       
   233     const TUint aClockRate,
       
   234     const TDesC8& aEncodingParam ) const
       
   235     {
       
   236     MCEMM_DEBUG("CMceSdpCodec::EncodeRtpMapFieldsL(), Entry ");
       
   237     
       
   238     MCE_DEFINE_DECSTR( clockrate, aClockRate );
       
   239     MCE_DEFINE_DECSTR( payload, aPayloadType );
       
   240     RStringF rtpmapStr = SDP_STRING( SdpCodecStringConstants::EAttributeRtpmap );
       
   241                 
       
   242     TSdpRtpmapValue rtpmapValue( aEncodingName, 
       
   243                                  clockrate, 
       
   244                                  aEncodingParam );                              
       
   245     
       
   246     HBufC8* rtpmapBuf = rtpmapValue.EncodeL();
       
   247     CleanupStack::PushL( rtpmapBuf );
       
   248 
       
   249     
       
   250     CSdpFmtAttributeField* rtpmapAttribute = 
       
   251         CSdpFmtAttributeField::NewL( rtpmapStr, payload, *rtpmapBuf );
       
   252     CleanupStack::PopAndDestroy( rtpmapBuf ); 
       
   253     
       
   254     MCEMM_DEBUG("CMceSdpCodec::EncodeRtpMapFieldsL(), Exit ");
       
   255     
       
   256     return rtpmapAttribute;
       
   257     }
       
   258 
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CMceSdpCodec::FindAttribute
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 CSdpAttributeField* CMceSdpCodec::FindAttribute( TInt aAttribute, 
       
   265                                                  CSdpMediaField& aMediaLine ) const
       
   266     {
       
   267     CSdpAttributeField* attributeField = NULL;
       
   268     RPointerArray<CSdpAttributeField>& attributeFields = 
       
   269                                                 aMediaLine.AttributeFields();
       
   270     TInt index = 0;
       
   271     while( !attributeField && index < attributeFields.Count() )
       
   272         {
       
   273         attributeField = attributeFields[ index++ ];
       
   274         RStringF attribute = attributeField->Attribute();
       
   275         attributeField = 
       
   276             attribute == SDP_STRING( aAttribute ) ? attributeField : NULL;
       
   277         }
       
   278 
       
   279     return attributeField;
       
   280         
       
   281     }
       
   282 
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CMceSdpCodec::ConvertDesToUintL
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 TUint CMceSdpCodec::ConvertDesToUintL( const TDesC8& aConv )
       
   289     {
       
   290     TUint covertedUint = 0;
       
   291     TLex8 lexConv( aConv );
       
   292     User::LeaveIfError ( lexConv.Val( covertedUint, EDecimal ) );
       
   293     return covertedUint;
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CMceSdpCodec::ConvertDesToIntL
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 TInt CMceSdpCodec::ConvertDesToIntL( const TDesC8& aConv )
       
   301     {
       
   302     TInt covertedInt = 0;
       
   303     TLex8 lexConv( aConv );
       
   304     User::LeaveIfError ( lexConv.Val( covertedInt ) );
       
   305     return covertedInt;
       
   306     }
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CMceSdpCodec::ConvertTRealToDesLC
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 HBufC8* CMceSdpCodec::ConvertTRealToDesLC( const TReal& aConv )
       
   314     {
       
   315     const TInt KMceMaxTRealLen = 20;
       
   316     HBufC8* buf  = HBufC8::NewLC( KMceMaxTRealLen );
       
   317     TPtr8 ptr = buf->Des();
       
   318     TRealFormat format;
       
   319     format.iType = KRealFormatGeneral;
       
   320     format.iWidth = KMceMaxTRealLen;
       
   321     format.iPoint = KMceRealPoint;
       
   322     ptr.Num( aConv, format );
       
   323     return buf;
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CMceSdpCodec::ConvertDesToReal
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TReal CMceSdpCodec::ConvertDesToRealL( const TDesC8& aConv )
       
   331     {
       
   332     TReal val;
       
   333     TLex8 lexer( aConv );
       
   334     User::LeaveIfError( lexer.Val( val, KMceRealPoint ) );
       
   335     return val;
       
   336     }
       
   337 
       
   338