|
1 /* |
|
2 * Copyright (c) 2005 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 "mceilbccodec.h" |
|
22 #include "mcecomilbccodec.h" |
|
23 |
|
24 #ifdef MCE_COMMON_SERVER_SIDE |
|
25 |
|
26 #include <mmcccodecinformation.h> |
|
27 #include "mcesrvstream.h" |
|
28 #include "mcesrvsource.h" |
|
29 |
|
30 #endif//MCE_COMMON_SERVER_SIDE |
|
31 |
|
32 // Frame Size |
|
33 const TUint KMceiLBCMode20FrameSize = 20; |
|
34 const TUint KMceiLBCMode30FrameSize = 30; |
|
35 |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CMceComiLBCCodec::NewL |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CMceComiLBCCodec* CMceComiLBCCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
44 { |
|
45 CMceComiLBCCodec* self = NewLC( aSdpName ); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CMceComiLBCCodec::NewLC |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CMceComiLBCCodec* CMceComiLBCCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
56 { |
|
57 CMceComiLBCCodec* self = new (ELeave) CMceComiLBCCodec(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL( aSdpName ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CMceComiLBCCodec::~CMceComiLBCCodec |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CMceComiLBCCodec::~CMceComiLBCCodec() |
|
69 { |
|
70 } |
|
71 |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CMceComiLBCCodec::CMceComiLBCCodec |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CMceComiLBCCodec::CMceComiLBCCodec() |
|
78 : CMceComAudioCodec() |
|
79 { |
|
80 iFourCC = 0; |
|
81 iEnableVAD = EFalse; |
|
82 iSamplingFreq = KMceiLBCSamplingFreq; |
|
83 iBitrate = KMceiLBCLevel30Bitrate; |
|
84 iPTime = KMceiLBCDefaultPtime30; |
|
85 iMaxPTime = KMceiLBCDefaultMaxPtime; |
|
86 iAllowedBitrates = KMceAllowediLBCBitrate20| |
|
87 KMceAllowediLBCBitrate30; |
|
88 iPayloadType = KMceDefaultiLBCPayloadType; |
|
89 iCodecMode = KiLBCodecMode; |
|
90 iFrameSize = KMceiLBCMode30FrameSize; |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CMceComiLBCCodec::ConstructL |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMceComAudioCodec* CMceComiLBCCodec::CloneL() |
|
99 { |
|
100 CMceComiLBCCodec* copy = new (ELeave) CMceComiLBCCodec(); |
|
101 CleanupStack::PushL( copy ); |
|
102 copy->ConstructL( *this ); |
|
103 CleanupStack::Pop( copy ); |
|
104 return copy; |
|
105 |
|
106 } |
|
107 |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CMceComiLBCCodec::ConstructL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CMceComiLBCCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName ) |
|
114 { |
|
115 CMceComAudioCodec::ConstructL( aSdpName ); |
|
116 } |
|
117 |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CMceComiLBCCodec::ConstructL |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CMceComiLBCCodec::ConstructL( CMceComiLBCCodec& aCodec ) |
|
124 { |
|
125 CMceComAudioCodec::ConstructL( aCodec ); |
|
126 } |
|
127 |
|
128 |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CMceComiLBCCodec::SetBitrate |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CMceComiLBCCodec::SetBitrate( TUint aBitrate ) |
|
135 { |
|
136 TBool isValid = ETrue; |
|
137 |
|
138 switch ( aBitrate ) |
|
139 { |
|
140 case KMceiLBCLevel20Bitrate: |
|
141 case KMceiLBCLevel30Bitrate: |
|
142 { |
|
143 if ( aBitrate > GetMaxBitRate() ) |
|
144 { |
|
145 isValid = EFalse; |
|
146 } |
|
147 break; |
|
148 } |
|
149 default: |
|
150 isValid = EFalse; |
|
151 break; |
|
152 } |
|
153 |
|
154 if ( isValid ) |
|
155 { |
|
156 return CMceComCodec::SetBitrate( aBitrate ); |
|
157 } |
|
158 else |
|
159 { |
|
160 return KErrNotSupported; |
|
161 } |
|
162 |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CMceComiLBCCodec::SetAllowedBitrates |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 |
|
172 TInt CMceComiLBCCodec::SetAllowedBitrates( TUint aBitrates ) |
|
173 { |
|
174 TInt error = KErrNone; |
|
175 |
|
176 if ( !aBitrates || |
|
177 ( aBitrates >> 8 ) > 0 ) |
|
178 { |
|
179 error = KErrArgument; |
|
180 } |
|
181 else |
|
182 { |
|
183 CMceComCodec::SetAllowedBitrates( KMceAllowediLBCBitrateAll ); |
|
184 iAllowedBitrates &= aBitrates; |
|
185 TUint maxBitrate = GetMaxBitRate(); |
|
186 if ( iBitrate > maxBitrate ) |
|
187 { |
|
188 error = CMceComCodec::SetBitrate( maxBitrate ); |
|
189 } |
|
190 } |
|
191 |
|
192 return error; |
|
193 |
|
194 } |
|
195 |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CMceComiLBCCodec::SetCodecMode |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CMceComiLBCCodec::SetCodecMode( TUint aCodecMode ) |
|
202 { |
|
203 if ( KiLBCodecMode == aCodecMode ) |
|
204 { |
|
205 iCodecMode = aCodecMode; |
|
206 return KErrNone; |
|
207 } |
|
208 else |
|
209 { |
|
210 return KErrNotSupported; |
|
211 } |
|
212 } |
|
213 |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CMceComiLBCCodec::SetPayloadType |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CMceComiLBCCodec::SetPayloadType( TUint8 aPayloadType ) |
|
220 { |
|
221 if ( KMinDynPayloadType <= aPayloadType ) |
|
222 { |
|
223 return CMceComCodec::SetPayloadType( aPayloadType ); |
|
224 } |
|
225 else |
|
226 { |
|
227 return KErrNotSupported; |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMceComiLBCCodec::GetMaxBitRate |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TUint CMceComiLBCCodec::GetMaxBitRate() |
|
237 { |
|
238 if( iAllowedBitrates & KMceAllowediLBCBitrate20 ) |
|
239 { |
|
240 return KMceiLBCLevel20Bitrate; |
|
241 } |
|
242 else if( iAllowedBitrates & KMceAllowediLBCBitrate30 ) |
|
243 { |
|
244 return KMceiLBCLevel30Bitrate; |
|
245 } |
|
246 else |
|
247 { |
|
248 return 0; |
|
249 } |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CMceComiLBCCodec::SetPTime |
|
254 // Just basic validity checks can be done here. Valid configuration cannot be |
|
255 // assured at method level. Client is responsible for setting ptime, maxptime |
|
256 // and bitrate so that they are aligned with each other. |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CMceComiLBCCodec::SetPTime( TUint aPTime ) |
|
260 { |
|
261 if ( ( aPTime % KMceiLBCMode20FrameSize ) == 0 || |
|
262 ( aPTime % KMceiLBCMode30FrameSize ) == 0 ) |
|
263 { |
|
264 return CMceComAudioCodec::SetPTime( aPTime ); |
|
265 } |
|
266 else |
|
267 { |
|
268 return KErrNotSupported; |
|
269 } |
|
270 } |
|
271 |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CMceComiLBCCodec::SetMaxPTime |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CMceComiLBCCodec::SetMaxPTime( TUint aMaxPTime ) |
|
278 { |
|
279 if ( ( aMaxPTime % KMceiLBCMode20FrameSize ) == 0 || |
|
280 ( aMaxPTime % KMceiLBCMode30FrameSize ) == 0 ) |
|
281 { |
|
282 return CMceComAudioCodec::SetMaxPTime( aMaxPTime ); |
|
283 } |
|
284 else |
|
285 { |
|
286 return KErrNotSupported; |
|
287 } |
|
288 } |
|
289 |
|
290 |
|
291 #ifdef MCE_COMMON_SERVER_SIDE |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CMceComiLBCCodec::DoMccEncodeL |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CMceComiLBCCodec::DoMccEncodeL( CMccCodecInformation& aMccCodec, |
|
298 CMceSrvStream& aStream ) |
|
299 { |
|
300 CMceComAudioCodec::DoMccEncodeL( aMccCodec, aStream ); |
|
301 |
|
302 // iLBC codec may ignore ptime setting if it fights against codec mode, |
|
303 // update MCE ptime to be one which is really used |
|
304 iPTime = aMccCodec.PTime(); |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CMceComiLBCCodec::DoMccValidateL |
|
309 // iLBC requires that both direction streams are in same mode. |
|
310 // Role answerer: mcccodec represents the received offer and codec the answer. |
|
311 // Role offerer: codec represents the sent offer and mcccodec the answer. |
|
312 // Do not allow bitrate upgrade when answering. |
|
313 // Ignore bitrate upgrade when offering. |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 CMceComCodec* CMceComiLBCCodec::DoMccValidateL( CMccCodecInformation& aMccCodec, |
|
317 CMceSrvStream& aStream, |
|
318 TMceNegotiationRole aRole ) |
|
319 { |
|
320 CMceComAudioCodec::DoMccValidateL( aMccCodec, aStream, aRole ); |
|
321 |
|
322 TBool notValid = ( aRole == EMceRoleAnswerer && aMccCodec.Bitrate() < iBitrate ); |
|
323 User::LeaveIfError( notValid ? KErrNotSupported : KErrNone ); |
|
324 |
|
325 CMceComCodec* bidirectional = NULL; |
|
326 |
|
327 CMceComCodec& codec = aStream.Codec(); |
|
328 if ( codec.Stream()->BoundStream() ) |
|
329 { |
|
330 CMceComCodec* boundCodec = |
|
331 codec.Stream()->BoundStreamL().FindCodecL( codec ); |
|
332 |
|
333 bidirectional = |
|
334 ( boundCodec && boundCodec->iBitrate != aMccCodec.Bitrate() ) ? boundCodec : NULL; |
|
335 |
|
336 if ( bidirectional ) |
|
337 { |
|
338 if ( aRole == EMceRoleOfferer ) |
|
339 { |
|
340 if ( bidirectional->iBitrate < aMccCodec.Bitrate() ) |
|
341 { |
|
342 // Ignoring bitrate upgrade |
|
343 __ASSERT_ALWAYS( bidirectional->iFmtpAttr, User::Leave( KErrNotReady ) ); |
|
344 SetFmtpAttributeL( *bidirectional->iFmtpAttr ); |
|
345 aMccCodec.SetFmtpAttrL( *bidirectional->iFmtpAttr ); |
|
346 } |
|
347 else |
|
348 { |
|
349 // Bitrate downgrade, NOP |
|
350 } |
|
351 } |
|
352 else |
|
353 { |
|
354 __ASSERT_ALWAYS( iFmtpAttr, User::Leave( KErrNotReady ) ); |
|
355 bidirectional->SetFmtpAttributeL( *iFmtpAttr ); |
|
356 } |
|
357 } |
|
358 } |
|
359 |
|
360 return bidirectional; |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CMceComiLBCCodec::DoMccAdjustL |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 void CMceComiLBCCodec::DoMccAdjustL( CMccCodecInformation& aMccCodec, |
|
368 CMceSrvStream& aStream ) |
|
369 { |
|
370 CMceComAudioCodec::DoMccAdjustL( aMccCodec, aStream ); |
|
371 |
|
372 // iLBC codec may ignore ptime setting if it fights against codec mode, |
|
373 // update MCE ptime to be one which is really used |
|
374 iPTime = aMccCodec.PTime(); |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CMceComiLBCCodec::DoSetDefaultFmtpAttributeL |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 void CMceComiLBCCodec::DoSetDefaultFmtpAttributeL() |
|
382 { |
|
383 SetFmtpAttributeL( KNullDesC8 ); |
|
384 } |
|
385 |
|
386 #endif |
|
387 |
|
388 // End of File |
|
389 |