|
1 // Copyright (c) 2005-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 : CSdpRtpmapStrategy.cpp |
|
15 // Part of : SIP Client Resolver |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSdpRtpmapStrategy.h" |
|
22 #include "sdpdocument.h" |
|
23 #include "sdpmediafield.h" |
|
24 #include "sdpcodecstringconstants.h" |
|
25 #include "sdpcodecstringpool.h" |
|
26 |
|
27 const TUint KMinDynPayloadType = 96; |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // CSdpRtpmapStrategy::NewLC |
|
31 // ---------------------------------------------------------------------------- |
|
32 // |
|
33 CSdpRtpmapStrategy* CSdpRtpmapStrategy::NewLC( |
|
34 const MSipClients& aSipClients) |
|
35 { |
|
36 CSdpRtpmapStrategy* self = |
|
37 new(ELeave)CSdpRtpmapStrategy(aSipClients); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CSdpRtpmapStrategy::CSdpRtpmapStrategy |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CSdpRtpmapStrategy::CSdpRtpmapStrategy(const MSipClients& aSipClients) |
|
48 : CSdpMLineStrategyBase(aSipClients) |
|
49 { |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CSdpRtpmapStrategy::ConstructL |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 void CSdpRtpmapStrategy::ConstructL() |
|
57 { |
|
58 iApplicationStringF = |
|
59 SdpCodecStringPool::StringPoolL().StringF( |
|
60 SdpCodecStringConstants::EMediaApplication, |
|
61 SdpCodecStringPool::StringTableL()); |
|
62 |
|
63 iRtpAvpStringF = |
|
64 SdpCodecStringPool::StringPoolL().StringF( |
|
65 SdpCodecStringConstants::EProtocolRtpAvp, |
|
66 SdpCodecStringPool::StringTableL()); |
|
67 |
|
68 iRtpmapStringF = |
|
69 SdpCodecStringPool::StringPoolL().StringF( |
|
70 SdpCodecStringConstants::EAttributeRtpmap, |
|
71 SdpCodecStringPool::StringTableL()); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // CSdpRtpmapStrategy::~CSdpRtpmapStrategy |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 CSdpRtpmapStrategy::~CSdpRtpmapStrategy () |
|
79 { |
|
80 iRtpmapStringF.Close(); |
|
81 iRtpAvpStringF.Close(); |
|
82 iApplicationStringF.Close(); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CSdpRtpmapStrategy::IsApplicable |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 TBool CSdpRtpmapStrategy::IsApplicable(CSdpMediaField& aMediaField) |
|
90 { |
|
91 if (aMediaField.Media() != iApplicationStringF && |
|
92 aMediaField.Protocol() == iRtpAvpStringF && |
|
93 aMediaField.FormatAttributeFields().Count() > 0) |
|
94 { |
|
95 return ETrue; |
|
96 } |
|
97 return EFalse; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CSdpRtpmapStrategy::FieldsMatchL |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 TBool CSdpRtpmapStrategy::FieldsMatchL( |
|
105 const CSdpMediaField& aReceivedMedia, |
|
106 const CSdpMediaField& aClientMedia) |
|
107 { |
|
108 if (aReceivedMedia.Media() == aClientMedia.Media() && |
|
109 aReceivedMedia.Protocol() == iRtpAvpStringF && |
|
110 aClientMedia.Protocol() == iRtpAvpStringF) |
|
111 { |
|
112 const RPointerArray<CSdpFmtAttributeField>& clientAttributes = |
|
113 const_cast<CSdpMediaField&>(aClientMedia).FormatAttributeFields(); |
|
114 if (clientAttributes.Count() == 0) |
|
115 { |
|
116 // A client that does not announce any RTPMAPs |
|
117 // is assumed to accept all possible mappings. |
|
118 return ETrue; |
|
119 } |
|
120 |
|
121 if (HasMatchingFormatsL(aReceivedMedia,aClientMedia)) |
|
122 { |
|
123 return ETrue; |
|
124 } |
|
125 |
|
126 const RPointerArray<CSdpFmtAttributeField>& attributes = |
|
127 const_cast<CSdpMediaField&>(aReceivedMedia).FormatAttributeFields(); |
|
128 for (TInt i=0; i < attributes.Count(); i++) |
|
129 { |
|
130 if (HasMatchingRtpmapAttritbute(aClientMedia,*attributes[i])) |
|
131 { |
|
132 return ETrue; |
|
133 } |
|
134 } |
|
135 } |
|
136 return EFalse; |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // CSdpRtpmapStrategy::HasMatchingRtpmapAttritbute |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 TBool CSdpRtpmapStrategy::HasMatchingRtpmapAttritbute( |
|
144 const CSdpMediaField& aMediaField, |
|
145 const CSdpFmtAttributeField& aAttribute) |
|
146 { |
|
147 if (aAttribute.Attribute() != iRtpmapStringF) |
|
148 { |
|
149 return EFalse; |
|
150 } |
|
151 |
|
152 const RPointerArray<CSdpFmtAttributeField>& attributes = |
|
153 const_cast<CSdpMediaField&>(aMediaField).FormatAttributeFields(); |
|
154 |
|
155 for (TInt i=0; i < attributes.Count(); i++) |
|
156 { |
|
157 CSdpFmtAttributeField& attribute = *attributes[i]; |
|
158 if (attribute.Attribute() == iRtpmapStringF && |
|
159 aAttribute.Value().CompareF(attribute.Value()) == 0) |
|
160 { |
|
161 return ETrue; |
|
162 } |
|
163 } |
|
164 |
|
165 return EFalse; |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // CSdpRtpmapStrategy::HasMatchingFormatsL |
|
170 // ---------------------------------------------------------------------------- |
|
171 // |
|
172 TBool CSdpRtpmapStrategy::HasMatchingFormatsL( |
|
173 const CSdpMediaField& aReceivedMedia, |
|
174 const CSdpMediaField& aClientMedia) const |
|
175 { |
|
176 if (aReceivedMedia.Protocol() != iRtpAvpStringF || |
|
177 aClientMedia.Protocol() != iRtpAvpStringF) |
|
178 { |
|
179 return EFalse; |
|
180 } |
|
181 |
|
182 RArray<TUint> formats(ExtractFormatsL(aReceivedMedia.FormatList())); |
|
183 CleanupClosePushL(formats); |
|
184 |
|
185 const RPointerArray<CSdpFmtAttributeField>& clientAttributes = |
|
186 const_cast<CSdpMediaField&>(aClientMedia).FormatAttributeFields(); |
|
187 |
|
188 for (TInt i=0; i < clientAttributes.Count(); i++) |
|
189 { |
|
190 const CSdpFmtAttributeField& clientAttribute = *clientAttributes[i]; |
|
191 if (clientAttribute.Attribute() == iRtpmapStringF) |
|
192 { |
|
193 TLex8 formatLex(clientAttribute.Format()); |
|
194 TUint value = 0; |
|
195 if (formatLex.Val(value) == KErrNone && |
|
196 value < KMinDynPayloadType) |
|
197 { |
|
198 TInt index = 0; |
|
199 TInt err = formats.FindInOrder(value,index); |
|
200 if (err == KErrNone && index >= 0) |
|
201 { |
|
202 CleanupStack::PopAndDestroy(1); // formats |
|
203 return ETrue; |
|
204 } |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 CleanupStack::PopAndDestroy(1); // formats |
|
210 return EFalse; |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CSdpRtpmapStrategy::ExtractFormatsL |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 RArray<TUint> CSdpRtpmapStrategy::ExtractFormatsL( |
|
218 const TDesC8& aFormats) const |
|
219 { |
|
220 RArray<TUint> formats; |
|
221 CleanupClosePushL(formats); |
|
222 TLex8 formatLex(aFormats); |
|
223 formatLex.SkipSpace(); |
|
224 TUint value = 0; |
|
225 while (!formatLex.Eos()) |
|
226 { |
|
227 if (formatLex.Val(value) == KErrNone) |
|
228 { |
|
229 formats.InsertInOrderAllowRepeatsL(value); |
|
230 } |
|
231 else |
|
232 { |
|
233 // Skip the invalid token |
|
234 formatLex.NextToken(); |
|
235 } |
|
236 formatLex.SkipSpace(); |
|
237 } |
|
238 CleanupStack::Pop(&formats); |
|
239 return formats; |
|
240 } |