|
1 /* |
|
2 * Copyright (c) 2008 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 "mceamrcodec.h" |
|
22 #include "mcecomamrcodec.h" |
|
23 |
|
24 #ifdef MCE_COMMON_SERVER_SIDE |
|
25 |
|
26 #include <mmcccodecinformation.h> |
|
27 |
|
28 _LIT8( KDefaultAmrFmtp, "octet-align=0; mode-set=0,1,2,3,4,5,6,7" ); |
|
29 |
|
30 #endif//MCE_COMMON_SERVER_SIDE |
|
31 |
|
32 const TUint KMceAmrFrameTime( 20 ); |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CMceComAMRCodec::NewL |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CMceComAMRCodec* CMceComAMRCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
42 { |
|
43 CMceComAMRCodec* self = NewLC( aSdpName ); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CMceComAMRCodec::NewLC |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CMceComAMRCodec* CMceComAMRCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
54 { |
|
55 CMceComAMRCodec* self = new (ELeave) CMceComAMRCodec(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aSdpName ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CMceComAMRCodec::~CMceComAMRCodec |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CMceComAMRCodec::~CMceComAMRCodec() |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CMceComAMRCodec::CMceComAMRCodec |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CMceComAMRCodec::CMceComAMRCodec() |
|
76 : CMceComAudioCodec() |
|
77 { |
|
78 iFourCC = 0; |
|
79 iEnableVAD = EFalse; |
|
80 iSamplingFreq = KMceAmrNbSamplingFreq; |
|
81 iPTime = KMceDefaultPtime; |
|
82 iMaxPTime = KMceDefaultMaxPtime; |
|
83 iBitrate = KMceAmrNbBitrate122; |
|
84 iAllowedBitrates = KMceAllowedAmrNbBitrate475| |
|
85 KMceAllowedAmrNbBitrate515| |
|
86 KMceAllowedAmrNbBitrate590| |
|
87 KMceAllowedAmrNbBitrate670| |
|
88 KMceAllowedAmrNbBitrate740| |
|
89 KMceAllowedAmrNbBitrate795| |
|
90 KMceAllowedAmrNbBitrate102| |
|
91 KMceAllowedAmrNbBitrate122; |
|
92 |
|
93 const TUint8 KMceDefaultAmrPayloadType = 96; |
|
94 iPayloadType = KMceDefaultAmrPayloadType; |
|
95 iCodecMode = EMceBandwidthEfficient; |
|
96 iFrameSize = KMceAmrFrameTime; |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CMceComAMRCodec::CloneL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CMceComAudioCodec* CMceComAMRCodec::CloneL() |
|
106 { |
|
107 CMceComAMRCodec* copy = new (ELeave) CMceComAMRCodec(); |
|
108 CleanupStack::PushL( copy ); |
|
109 copy->ConstructL( *this ); |
|
110 CleanupStack::Pop( copy ); |
|
111 return copy; |
|
112 |
|
113 } |
|
114 |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CMceComAMRCodec::ConstructL |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CMceComAMRCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
121 { |
|
122 CMceComAudioCodec::ConstructL( aSdpName ); |
|
123 |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CMceComAMRCodec::ConstructL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CMceComAMRCodec::ConstructL( CMceComAMRCodec& aCodec ) |
|
132 { |
|
133 CMceComAudioCodec::ConstructL( aCodec ); |
|
134 } |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CMceComAMRCodec::SetBitrate |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CMceComAMRCodec::SetBitrate( TUint aBitrate ) |
|
142 { |
|
143 TBool isValid = ETrue; |
|
144 |
|
145 switch ( aBitrate ) |
|
146 { |
|
147 case KMceAmrNbBitrate475: |
|
148 case KMceAmrNbBitrate515: |
|
149 case KMceAmrNbBitrate590: |
|
150 case KMceAmrNbBitrate670: |
|
151 case KMceAmrNbBitrate740: |
|
152 case KMceAmrNbBitrate795: |
|
153 case KMceAmrNbBitrate102: |
|
154 case KMceAmrNbBitrate122: |
|
155 { |
|
156 if ( aBitrate > GetMaxBitRate() ) |
|
157 { |
|
158 isValid = EFalse; |
|
159 } |
|
160 break; |
|
161 } |
|
162 default: |
|
163 isValid = EFalse; |
|
164 break; |
|
165 } |
|
166 |
|
167 if ( isValid ) |
|
168 { |
|
169 return CMceComCodec::SetBitrate( aBitrate ); |
|
170 } |
|
171 else |
|
172 { |
|
173 return KErrNotSupported; |
|
174 } |
|
175 |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CMceComAMRCodec::SetAllowedBitrates |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CMceComAMRCodec::SetAllowedBitrates( TUint aBitrates ) |
|
183 { |
|
184 TInt error = KErrNone; |
|
185 |
|
186 //Confirm that the bitrate mask is valid |
|
187 //I.e. after all the valid bitrates are set to zero the value should be zero |
|
188 if ( !aBitrates || |
|
189 ( aBitrates >> 12 ) > 0 ) |
|
190 { |
|
191 error = KErrArgument; |
|
192 } |
|
193 else |
|
194 { |
|
195 CMceComCodec::SetAllowedBitrates( KMceAllowedAmrNbBitrateAll ); |
|
196 iAllowedBitrates &= aBitrates; |
|
197 TUint maxBitrate = GetMaxBitRate(); |
|
198 if ( iBitrate > maxBitrate ) |
|
199 { |
|
200 error = CMceComCodec::SetBitrate( maxBitrate ); |
|
201 } |
|
202 |
|
203 // Update also other amr codec information stored inside |
|
204 // allowed bitrates mask |
|
205 const TUint KMceOtherInfoMask = 0x0F00; |
|
206 iAllowedBitrates |= ( aBitrates & KMceOtherInfoMask ); |
|
207 } |
|
208 |
|
209 return error; |
|
210 |
|
211 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CMceComAMRCodec::SetCodecMode |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TInt CMceComAMRCodec::SetCodecMode( TUint aCodecMode ) |
|
219 { |
|
220 if ( EMceBandwidthEfficient == aCodecMode || EMceOctetAligned == aCodecMode ) |
|
221 { |
|
222 iCodecMode = aCodecMode; |
|
223 return KErrNone; |
|
224 } |
|
225 else |
|
226 { |
|
227 return KErrNotSupported; |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMceComAMRCodec::SetPayloadType |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CMceComAMRCodec::SetPayloadType( TUint8 aPayloadType ) |
|
237 { |
|
238 if ( KMinDynPayloadType <= aPayloadType ) |
|
239 { |
|
240 return CMceComCodec::SetPayloadType( aPayloadType ); |
|
241 } |
|
242 else |
|
243 { |
|
244 return KErrNotSupported; |
|
245 } |
|
246 } |
|
247 |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CMceComAMRCodec::GetMaxBitRate |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TUint CMceComAMRCodec::GetMaxBitRate() |
|
254 { |
|
255 if( iAllowedBitrates & KMceAllowedAmrNbBitrate122 ) |
|
256 { |
|
257 return KMceAmrNbBitrate122; |
|
258 } |
|
259 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate102 ) |
|
260 { |
|
261 return KMceAmrNbBitrate102; |
|
262 } |
|
263 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate795 ) |
|
264 { |
|
265 return KMceAmrNbBitrate795; |
|
266 } |
|
267 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate740 ) |
|
268 { |
|
269 return KMceAmrNbBitrate740; |
|
270 } |
|
271 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate670 ) |
|
272 { |
|
273 return KMceAmrNbBitrate670; |
|
274 } |
|
275 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate590 ) |
|
276 { |
|
277 return KMceAmrNbBitrate590; |
|
278 } |
|
279 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate515 ) |
|
280 { |
|
281 return KMceAmrNbBitrate515; |
|
282 } |
|
283 else if( iAllowedBitrates & KMceAllowedAmrNbBitrate475 ) |
|
284 { |
|
285 return KMceAmrNbBitrate475; |
|
286 } |
|
287 else |
|
288 { |
|
289 return 0; |
|
290 } |
|
291 } |
|
292 |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CMceComAMRCodec::ResolveAllowedBitrates |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 TInt CMceComAMRCodec::ResolveAllowedBitrates( |
|
299 TUint aBitrate, TUint& aAllowedBitrates ) |
|
300 { |
|
301 TInt retVal( KErrNone ); |
|
302 |
|
303 if ( aBitrate <= KMceAmrNbBitrate475 ) |
|
304 { |
|
305 aAllowedBitrates = KMceAllowedAmrNbBitrate475; |
|
306 } |
|
307 else if ( aBitrate <= KMceAmrNbBitrate515 ) |
|
308 { |
|
309 aAllowedBitrates = KMceAllowedAmrNbBitrate515; |
|
310 } |
|
311 else if ( aBitrate <= KMceAmrNbBitrate590 ) |
|
312 { |
|
313 aAllowedBitrates = KMceAllowedAmrNbBitrate590; |
|
314 } |
|
315 else if ( aBitrate <= KMceAmrNbBitrate670 ) |
|
316 { |
|
317 aAllowedBitrates = KMceAllowedAmrNbBitrate670; |
|
318 } |
|
319 else if ( aBitrate <= KMceAmrNbBitrate740 ) |
|
320 { |
|
321 aAllowedBitrates = KMceAllowedAmrNbBitrate740; |
|
322 } |
|
323 else if ( aBitrate <= KMceAmrNbBitrate795 ) |
|
324 { |
|
325 aAllowedBitrates = KMceAllowedAmrNbBitrate795; |
|
326 } |
|
327 else if ( aBitrate <= KMceAmrNbBitrate102 ) |
|
328 { |
|
329 aAllowedBitrates = KMceAllowedAmrNbBitrate102; |
|
330 } |
|
331 else if ( aBitrate <= KMceAmrNbBitrate122 ) |
|
332 { |
|
333 aAllowedBitrates = KMceAllowedAmrNbBitrateAll; |
|
334 } |
|
335 else |
|
336 { |
|
337 retVal = KErrNotSupported; |
|
338 } |
|
339 |
|
340 return retVal; |
|
341 } |
|
342 |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CMceComAMRCodec::SetSamplingFreq |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TInt CMceComAMRCodec::SetSamplingFreq( TUint aSamplingFreq ) |
|
349 { |
|
350 if ( KMceAmrNbSamplingFreq == aSamplingFreq || |
|
351 KMceAmrWbSamplingFreq == aSamplingFreq ) |
|
352 { |
|
353 iSamplingFreq = aSamplingFreq; |
|
354 return KErrNone; |
|
355 } |
|
356 else |
|
357 { |
|
358 return KErrNotSupported; |
|
359 } |
|
360 } |
|
361 |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CMceComAMRCodec::SetPTime |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CMceComAMRCodec::SetPTime( TUint aPTime ) |
|
368 { |
|
369 if ( ( aPTime % KMceAmrFrameTime ) == 0 ) |
|
370 { |
|
371 return CMceComAudioCodec::SetPTime( aPTime ); |
|
372 } |
|
373 else |
|
374 { |
|
375 return KErrNotSupported; |
|
376 } |
|
377 } |
|
378 |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CMceComAudioCodec::SetMaxPTime |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TInt CMceComAMRCodec::SetMaxPTime( TUint aMaxPTime ) |
|
385 { |
|
386 if ( ( aMaxPTime % KMceAmrFrameTime ) == 0 ) |
|
387 { |
|
388 return CMceComAudioCodec::SetMaxPTime( aMaxPTime ); |
|
389 } |
|
390 else |
|
391 { |
|
392 return KErrNotSupported; |
|
393 } |
|
394 } |
|
395 |
|
396 |
|
397 #ifdef MCE_COMMON_SERVER_SIDE |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CMceComAMRCodec::DoMccValidateL |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 CMceComCodec* CMceComAMRCodec::DoMccValidateL( CMccCodecInformation& aMccCodec, |
|
404 CMceSrvStream& /*aStream*/, |
|
405 TMceNegotiationRole aRole ) |
|
406 { |
|
407 //if answerer mcc codec represents the received offer and codec the answer |
|
408 //if offerer codec represents the sent offer and mcc codec the answer |
|
409 |
|
410 // Bitrates field contains also additional information, mask it away |
|
411 TUint mccBitrates = ( aMccCodec.AllowedBitrates() & KMceAllowedAmrNbBitrateAll ); |
|
412 TUint mceBitrates = ( iAllowedBitrates & KMceAllowedAmrNbBitrateAll ); |
|
413 |
|
414 TBool notValid = aRole == EMceRoleAnswerer ? |
|
415 ( mceBitrates && mccBitrates == 0 || |
|
416 mceBitrates > mccBitrates ) : |
|
417 ( mceBitrates && mccBitrates == 0 || |
|
418 mceBitrates < mccBitrates ); |
|
419 |
|
420 User::LeaveIfError( notValid ? KErrNotSupported : KErrNone ); |
|
421 if ( aMccCodec.CodecMode() != (TCodecMode)iCodecMode ) |
|
422 { |
|
423 // codec-mode was different, fail. |
|
424 User::Leave(KErrNotSupported); |
|
425 } |
|
426 return NULL; |
|
427 } |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // CMceComAMRCodec::DoSetDefaultFmtpAttributeL |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 void CMceComAMRCodec::DoSetDefaultFmtpAttributeL() |
|
434 { |
|
435 SetFmtpAttributeL( KDefaultAmrFmtp ); |
|
436 } |
|
437 |
|
438 #endif |
|
439 |
|
440 // End of File |