|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : SdpRtpmapValue.cpp |
|
15 // Part of : SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include "SdpRtpmapValue.h" |
|
23 #include "SdpUtil.h" |
|
24 #include "SdpCodecErr.h" |
|
25 #include "SdpCodecConstants.h" |
|
26 #include "_sdpdefs.h" |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // TSdpRtpmapValue::TSdpRtpmapValue |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C TSdpRtpmapValue::TSdpRtpmapValue( |
|
37 const TPtrC8& aEncodingName, |
|
38 const TPtrC8& aClockrate, |
|
39 const TPtrC8& aEncodingParameters ) : |
|
40 iEncName( aEncodingName ), |
|
41 iClockrate( aClockrate ), |
|
42 iEncParams( aEncodingParameters ) |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // TSdpRtpmapValue::DecodeL |
|
48 // Decodes string and puts it into parts |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C TSdpRtpmapValue TSdpRtpmapValue::DecodeL( |
|
52 const TDesC8& aText ) |
|
53 { |
|
54 __ASSERT_ALWAYS(aText.Length() > 0 && |
|
55 aText.Locate( KSlashChar ) != KErrNotFound, |
|
56 User::Leave(KErrSdpCodecMediaAttributeField)); |
|
57 |
|
58 TInt length( aText.Length() ); |
|
59 if ( aText[length - 1] == KLFChar ) |
|
60 { |
|
61 if ( length > 1 && aText[length - 2] == KCRChar ) |
|
62 { |
|
63 length--; |
|
64 } |
|
65 length--; |
|
66 } |
|
67 TPtrC8 restValue( aText.Left( length ) ); |
|
68 |
|
69 __ASSERT_ALWAYS(SdpUtil::IsByteString(restValue), |
|
70 User::Leave(KErrSdpCodecMediaAttributeField)); |
|
71 |
|
72 TInt pos = restValue.Locate( KSlashChar ); |
|
73 |
|
74 // <encoding name> |
|
75 TPtrC8 encName( restValue.Left( pos ) ); |
|
76 |
|
77 restValue.Set( restValue.Right( restValue.Length() - pos - 1 ) ); |
|
78 pos = restValue.Locate( KSlashChar ); |
|
79 |
|
80 // <clock rate> <encoding parameters> |
|
81 TPtrC8 encParam( KNullDesC8 ); |
|
82 TPtrC8 clockRate( KNullDesC8 ); |
|
83 |
|
84 if ( pos == KErrNotFound ) |
|
85 { |
|
86 clockRate.Set( restValue ); |
|
87 |
|
88 __ASSERT_ALWAYS( clockRate.Length() > 0 && encParam.Length() == 0, |
|
89 User::Leave( KErrSdpCodecMediaAttributeField ) ); |
|
90 } |
|
91 else |
|
92 { |
|
93 clockRate.Set( restValue.Left( pos ) ); |
|
94 encParam.Set( restValue.Right( restValue.Length() - pos - 1 ) ); |
|
95 |
|
96 __ASSERT_ALWAYS( clockRate.Length() > 0 && encParam.Length() > 0, |
|
97 User::Leave( KErrSdpCodecMediaAttributeField ) ); |
|
98 } |
|
99 |
|
100 return TSdpRtpmapValue( encName, clockRate, encParam ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // TSdpRtpmapValue::EncodeL |
|
105 // Encodes a string into valid output string format |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C HBufC8* TSdpRtpmapValue::EncodeL() const |
|
109 { |
|
110 TUint length = iEncName.Length() + iClockrate.Length() + 2; |
|
111 |
|
112 if (iEncParams.Length() > 0) |
|
113 { |
|
114 length += iEncParams.Length() + 1; |
|
115 } |
|
116 |
|
117 HBufC8* returnValue = HBufC8::NewL(length); |
|
118 |
|
119 TPtr8 retValPtr(returnValue->Des()); |
|
120 retValPtr.Append(iEncName); |
|
121 retValPtr.Append(KSlashStr); |
|
122 retValPtr.Append(iClockrate); |
|
123 |
|
124 if (iEncParams.Length() > 0) |
|
125 { |
|
126 retValPtr.Append(KSlashStr); |
|
127 retValPtr.Append(iEncParams); |
|
128 } |
|
129 |
|
130 return returnValue; |
|
131 } |