Initial contribution of the Adaptation Documentation.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License
"Eclipse Public License v1.0" which accompanies this distribution,
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
Nokia Corporation - initial contribution.
Contributors:
-->
<!DOCTYPE concept
PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D" xml:lang="en"><title>Example
Showing the use of the SDP Codec API</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>The following sections explain how to create an SDP description with the
required fields. </p>
<ul>
<li id="GUID-F95C20F4-0A32-588F-A5A4-25C8C0F1D687"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-5184D372-53E1-5872-9DC0-63E004232D6D">Creating an SDP description</xref> </p> </li>
<li id="GUID-ADA89366-B0CD-5520-A6A1-392525042085"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-CD67F58C-5059-50DA-B275-CC07EC5E93EF">Creating a CSdpDocument object</xref> </p> </li>
<li id="GUID-ADF16F11-C606-55C8-9E3C-4BCC420342D7"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-35A2A9E8-8AE4-55EA-9DE3-C6F056A3B497">Defining the session name field for the SDP description</xref> </p> </li>
<li id="GUID-AAEAAB91-98EB-5A6C-AA18-DA850BED70EB"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-6D04653E-711E-53B3-8DC6-9A35EDE98173">Creating an instance of the Origin field class</xref> </p> </li>
<li id="GUID-EFFDBB7F-CF7A-593C-826A-480DBF6D13AB"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-63EE5D34-4AD2-5FC5-8D4C-E4DDEBE4D546">Fetching the network type and the address type</xref> </p> </li>
<li id="GUID-58CDD2CF-CCF2-52B2-8C0A-134508FC14EA"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-4CE0F919-97DC-5A4B-81B1-44953792609A">Creating and setting the connection field into the sdpDocument</xref> </p> </li>
<li id="GUID-B54A2924-3AAC-5E1B-9A0B-145A532E9306"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-0C8C6767-7D0D-5211-88A1-E07FABFC2EDB">Defining the session part attribute and direction-attribute</xref> </p> </li>
<li id="GUID-D35AFF85-8E2D-5352-BE58-E755F3FF7D53"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-7835F2BC-6D44-58D7-A662-72B636F31154">Creating the first media field</xref> </p> </li>
<li id="GUID-86DD7BAC-9C2B-5A23-8B7B-8A1FE7047CC6"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-D991055C-4847-5A92-BA72-18917231C00E">Creating the second media field</xref> </p> </li>
<li id="GUID-00D37100-7CB9-5A7A-874A-325B89E59A8F"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-F8B6AE3F-DD42-5318-9184-C7DE92B7068A">Assigning the media fields to the CSdpDocument object</xref> </p> </li>
<li id="GUID-1785FB44-679F-5C03-8B5B-44A2F5B979D0"><p> <xref href="GUID-6F40A921-83A9-5268-A9A6-80750CD5823D.dita#GUID-6F40A921-83A9-5268-A9A6-80750CD5823D/GUID-8F23A065-184D-5725-86FC-AC5909B401BB">Deleting the sdpDocument and closing the SdpCodecStringPool</xref> </p> </li>
</ul>
<section id="GUID-5184D372-53E1-5872-9DC0-63E004232D6D"><title> Creating an
SDP description</title> <ol id="GUID-9274DB5E-2266-5CBC-94BE-A140D1AA5B8E">
<li id="GUID-1D695593-6D60-5FB6-9D2B-EAF58D9D1451"><p>Open the String Pool </p> </li>
<li id="GUID-DF565227-6809-578B-9C75-A5D06DF9DC02"><p>Access the predefined
SDP constants in the string table </p> </li>
<li id="GUID-44F46943-DCBA-5E12-B68D-A19DBF6DBBF7"><p>Close the String Pool
after you finish with the SDP description </p> </li>
</ol> <codeblock id="GUID-AC697A6F-FA2A-5B00-8004-DDCCEB82ADE1" xml:space="preserve">SdpCodecStringPool::OpenL();
RStringPool pool = SdpCodecStringPool::StringPoolL();
</codeblock> </section>
<section id="GUID-CD67F58C-5059-50DA-B275-CC07EC5E93EF"><title> Creating a
CSdpDocument object</title> <p>The following code snippet shows how to create
the <xref href="GUID-FF6D4EAD-3AAE-3843-8A9C-7C92426FC29F.dita"><apiname>CSdpDocument</apiname></xref> object. This includes all SDP fields in
the structural format: </p> <codeblock id="GUID-6A6F8797-0DB3-5FA3-9AEC-F688B998755B" xml:space="preserve">CSdpDocument* sdpDocument = CSdpDocument::NewLC();</codeblock> </section>
<section id="GUID-35A2A9E8-8AE4-55EA-9DE3-C6F056A3B497"><title>Defining the
session name field for the SDP description</title> <p>The following code snippet
shows how to define the session name field for the SDP description: </p> <codeblock id="GUID-14984CDB-2868-5857-9E47-96E280524E2A" xml:space="preserve">sdpDocument->SetSessionNameL(_L8("SipSession"));</codeblock> </section>
<section id="GUID-6D04653E-711E-53B3-8DC6-9A35EDE98173"><title>Creating an
instance of the Origin field class </title> <p>The following code snippet
shows how to create an instance of the Origin field class and set into the
SDP description: </p> <codeblock id="GUID-BB71093E-DA1F-5BE8-A7A1-7D1BD51AC2AC" xml:space="preserve">TInt64 sessionId( TUint( 2890844526 ) );
TInt64 sessionVersion( TUint( 2890842807 ) );
TInetAddr address;
const TUint32 KInetAddr = INET_ADDR(10,47,16,5);
address.SetAddress( KInetAddr );
CSdpOriginField* originfield = CSdpOriginField::NewL(_L8("username"), sessionId, sessionversion, address);
sdpDocument->SetOriginField(originfield);
</codeblock> </section>
<section id="GUID-63EE5D34-4AD2-5FC5-8D4C-E4DDEBE4D546"><title>Fetching the
network type and the address type</title><p>The following code snippet shows
how to fetch the predefined network type and the address type for the connection
field from the String Pool:</p><codeblock xml:space="preserve">RStringF netType = pool.StringF( SdpCodecStringConstants::ENetType, SdpCodecStringConstants::Table );RStringF addressTypeIP4 = pool.StringF( SdpCodecStringConstants::EAddressTypeIP4, SdpCodecStringConstants::Table );
</codeblock> </section>
<section id="GUID-4CE0F919-97DC-5A4B-81B1-44953792609A"><title>Creating
and setting the connection field into the sdpDocument</title> <p>The following
code snippet shows how to create the connection field and set the SDP parameters
of the SIP message into the SDP description: </p> <codeblock id="GUID-C95DB654-C03B-5FAA-B21A-AD7AC7E45117" xml:space="preserve">_LIT8( KAddress, "10.47.16.5" );
CSdpConnectionField* connectionfield = CSdpConnectionField::NewL( netType, addressTypeIP4, KAddress );
sdpDocument->SetConnectionField(connectionfield);
</codeblock> </section>
<section id="GUID-0C8C6767-7D0D-5211-88A1-E07FABFC2EDB"><title>Defining the
session part attribute and direction-attribute</title> <p>The following code
snippet shows how to define the session part attribute for the SDP description.
The direction-attribute is not one of the predefined attributes in the string
table, it must be defined dynamically to the String Pool. </p> <codeblock id="GUID-83943165-3D45-5D50-B4D8-B6F3471CF623" xml:space="preserve">_LIT8(KSDPAttributeDirectionBoth,"both");
RStringF modifier = pool.OpenFStringL(_L8("direction"));
CleanupClosePushL(modifier);
CSdpAttributeField* attrField = CSdpAttributeField::NewL(modifier, KSDPAttributeDirectionBoth);
User::LeaveIfError((sdpDocument->AttributeFields()).Append(attrField));
CleanupStack::PopAndDestroy();
</codeblock> </section>
<section id="GUID-7835F2BC-6D44-58D7-A662-72B636F31154"><title> Creating the
first media field</title> <p>The following code snippet shows how to create
the first media field: </p> <codeblock id="GUID-5EC0673E-BE80-522E-BD8C-1A258BCF25E3" xml:space="preserve">RStringF mediaVideo = pool.StringF( SdpCodecStringConstants::EMediaVideo, SdpCodecStringPool::StringTableL());
RStringF protocol = pool.StringF(SdpCodecStringConstants::EProtocolRtpAvp, SdpCodecStringPool::StringTableL());
CSdpMediaField* media1 = CSdpMediaField::NewLC(mediaVideo, 49152, protocol, _L8("96"));
</codeblock> <p>Add the sendonly attribute (“a=sendonly”) to the first media
field: </p> <codeblock id="GUID-30DCBB1C-E76A-5BBA-B8CE-CA34EDE86C51" xml:space="preserve">RStringF sendonlyAttr = iPool.StringF( SdpCodecStringConstants:: EAttributeSendonly, SdpCodecStringPool::StringTableL() );
CSdpAttributeField* attr1 = CSdpAttributeField::NewLC(sendonlyAttr, _L8(""));
User::LeaveIfError((media1->AttributeFields()).Append(attr1));
CleanupStack::Pop(); //attr1
</codeblock> <p>Add the rtpmap attribute (“a=rtpmap:96 H263-2000/90000”) to
the first media field and then add the rtpmap specific attribute (“a=ptime:15”): </p> <codeblock id="GUID-73BD605A-7C81-50A2-988C-17ABA6B0641B" xml:space="preserve">_LIT8( KEncodingName, "H263-2000" );
_LIT8( KClockRate, "90000" );
_LIT8( KEncodingParam, "" );
TSdpRtpmapValue rtpmapValue( KEncodingName(), KClockRate(), KEncodingParam() );
HBufC8* rtpmapBuf = rtpmapValue.EncodeL();
CleanupStack::PushL(rtpmapBuf);
RStringF rtpmapStr = pool.StringF( SdpCodecStringConstants::EAttributeRtpmap, SdpCodecStringPool::StringTableL() );
CSdpFmtAttributeField* rtpmapAttribute = CSdpFmtAttributeField::NewLC(rtpmapStr, _L8("96"), *rtpmapBuf);
User::LeaveIfError(media1->FormatAttributeFields().Append (rtpmapAttribute));
CleanupStack::Pop(); // rtpmapAttribute
CleanupStack::PopAndDestroy(); // rtpmapBuf
// add a rtpmap specific attribute
RStringF ptimeAttrStr = iPool.StringF( SdpCodecStringConstants:: EAttributePtime, SdpCodecStringPool::StringTableL() );
CSdpAttributeField* ptimeAttr = CSdpAttributeField::NewLC(ptimeAttrStr, _L8("15"));
ptimeAttr->AssignTo(*(media1->FormatAttributeFields())[0]);
User::LeaveIfError(media1->AttributeFields().Append(ptimeAttr));
CleanupStack::Pop(); //ptimeAttr
</codeblock> </section>
<section id="GUID-D991055C-4847-5A92-BA72-18917231C00E"><title>Creating the
second media field</title> <p>The following code snippet shows how to create
the second media field: </p> <codeblock id="GUID-9B5EAFE9-66DD-57A7-8AD3-78233430ED53" xml:space="preserve">RStringF mediaAudio = pool.StringF( SdpCodecStringConstants:: EMediaAudio, SdpCodecStringPool::StringTableL());
CSdpMediaField* media2 = CSdpMediaField::NewLC(mediaAudio, 57344, protocol, _L8("97"));
</codeblock> <p>Create the sendonly attribute for the second media field: </p> <codeblock id="GUID-2561B0AD-A8DA-56B0-84E2-833A22F9BE4E" xml:space="preserve">CSdpAttributeField* attr2 = CSdpAttributeField::NewLC(sendonlyAttr,
_L8(""));
User::LeaveIfError((media2->AttributeFields()).Append(attr2));
CleanupStack::Pop();
</codeblock> <p>Create the rtpmap attribute (“a=rtpmap:97 AMR/8000”) for the
second media field: </p> <codeblock id="GUID-18186488-A9C8-5B7A-B3FF-5424C1C4DBD9" xml:space="preserve">_LIT8( KEncodingName1, "AMR" );
_LIT8( KClockRate1, "8000" );
TSdpRtpmapValue rtpmapValue1( KEncodingName1(), KClockRate1(), KEncodingParam() );
HBufC8* rtpmapBuf1 = rtpmapValue1.EncodeL();
CleanupStack::PushL(rtpmapBuf1);
CSdpFmtAttributeField* rtpmapAttribute1 = CSdpFmtAttributeField::NewLC(rtpmapStr, _L8("97"), *rtpmapBuf1);
User::LeaveIfError(media2->FormatAttributeFields().Append (rtpmapAttribute1));
CleanupStack::Pop(); // rtpmapAttribute1
CleanupStack::PopAndDestroy(); //rtpmapBuf1
</codeblock> </section>
<section id="GUID-F8B6AE3F-DD42-5318-9184-C7DE92B7068A"><title>Assigning the
media fields to the CSdpDocument object </title> <p>The following code snippet
shows how to assign the media fields to the <xref href="GUID-FF6D4EAD-3AAE-3843-8A9C-7C92426FC29F.dita"><apiname>CSdpDocument</apiname></xref> object
and then remove the buffers from the cleanup stack: </p> <codeblock id="GUID-44BD57DA-85CD-554A-8801-86F7F47A7D41" xml:space="preserve">User::LeaveIfError(doc->MediaFields().Append(media1));
User::LeaveIfError(doc->MediaFields().Append(media2));
CleanupStack::Pop(); //media2
CleanupStack::Pop(); //media1
</codeblock> </section>
<section id="GUID-8F23A065-184D-5725-86FC-AC5909B401BB"><title>Deleting the
sdpDocument and closing the SdpCodecStringPool</title> <p>To close the String
Pool the <xref href="GUID-FF6D4EAD-3AAE-3843-8A9C-7C92426FC29F.dita"><apiname>CSdpDocument</apiname></xref> object must be removed and deleted
from the cleanup stack. The following code snippet shows how to remove and
delete the <xref href="GUID-FF6D4EAD-3AAE-3843-8A9C-7C92426FC29F.dita"><apiname>CSdpDocument</apiname></xref> object from the cleanup stack and
close the String Pool: </p> <codeblock id="GUID-2037F164-73C9-5DC0-95BF-F05E778BF4E1" xml:space="preserve">CleanupStack::PopAndDestroy(); //sdpDocument
SdpCodecStringPool::Close();
</codeblock> <p>The SDP description created in the preceding example has the
following fields: </p> <codeblock id="GUID-EC361C3C-02D4-5130-AD1B-4C12F1985A06" xml:space="preserve">v=0
o=username 2890844526 2890842807 IN IP4 10.47.16.5
s=SipSession
c=IN IP4 10.47.16.5
t=0 0
a=direction:both
m=video 49152 RTP/AVP 96
a=sendonly
a=rtpmap:96 H263-2000/90000
m=audio 57344 RTP/AVP 97
a=sendonly
a=rtpmap:97 AMR/8000
</codeblock> </section>
</conbody></concept>