|
1 /* |
|
2 * Copyright (c) 2004-2006 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: MCC G.729 CodecInformation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "mmcccodecg729.h" |
|
23 #include "mmccinterfacelogs.h" |
|
24 #include "mccuids.hrh" |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KG729DefaultHwFrameTime( 10 ); |
|
29 |
|
30 |
|
31 // LOCAL CONSTANTS AND MACROS |
|
32 const TUint8 KG729KAPayloadSize = 10; |
|
33 const TUint8 KG729KeepAlivePayload[KG729KAPayloadSize] = |
|
34 { |
|
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
|
36 }; |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMCCCodecG729::CMCCCodecG729 |
|
43 // default constructor |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CMCCCodecG729::CMCCCodecG729() : CMccCodecInformation() |
|
47 { |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CMCCCodecG729::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CMCCCodecG729::ConstructL() |
|
56 { |
|
57 __INTERFACE( "CMCCCodecG729::ConstructL" ) |
|
58 |
|
59 SetSdpName( KG729SdpName ); |
|
60 iKeepAliveData.Copy( KG729KeepAlivePayload ); |
|
61 // setting some default values |
|
62 SetSamplingFreq( KG729SampleRate ); |
|
63 SetBitrate( KG729Bitrate ); |
|
64 EnableVAD( EFalse ); |
|
65 iHwFrameTime = KG729DefaultHwFrameTime; // default 20ms |
|
66 SetMaxPTime( KMaxPtime ); |
|
67 SetPTime( KDefaultPtime ); |
|
68 SetPayloadType( KG729PayloadType ); |
|
69 iCodecMode = ENothing; |
|
70 |
|
71 iFourCC = KMccFourCCIdG729; |
|
72 |
|
73 iPayloadFormatEncoder = KImplUidG729PayloadFormatEncode; |
|
74 iPayloadFormatDecoder = KImplUidG729PayloadFormatDecode; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CMCCCodecG729::NewL |
|
79 // Static constructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CMCCCodecG729* CMCCCodecG729::NewL() |
|
83 { |
|
84 CMCCCodecG729* self = new (ELeave) CMCCCodecG729; |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop( self ); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CMCCCodecG729::~CMCCCodecG729 |
|
93 // Destructor |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CMCCCodecG729::~CMCCCodecG729() |
|
97 { |
|
98 __INTERFACE( "CMCCCodecG729::~CMCCCodecG729" ) |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CMCCCodecG729::EnableVAD |
|
103 // Enable / Disable VAD |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 TInt CMCCCodecG729::EnableVAD( TBool aEnableVAD ) |
|
107 { |
|
108 iEnableVAD = aEnableVAD; |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CMCCCodecG729::SetBitrate |
|
114 // Set Bitrate |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CMCCCodecG729::SetBitrate( TUint aBitrate ) |
|
118 { |
|
119 if( KG729Bitrate != aBitrate ) |
|
120 { |
|
121 return KErrNotSupported; |
|
122 } |
|
123 else |
|
124 { |
|
125 iBitrate = aBitrate; |
|
126 return KErrNone; |
|
127 } |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CMCCCodecG729::SetSamplingFreq |
|
132 // Set Sampling Frequency |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 TInt CMCCCodecG729::SetSamplingFreq( TUint32 aSamplingFreq ) |
|
136 { |
|
137 if ( KG729SampleRate == aSamplingFreq ) |
|
138 { |
|
139 iSamplingFreq = aSamplingFreq; |
|
140 return KErrNone; |
|
141 } |
|
142 else |
|
143 { |
|
144 return KErrNotSupported; |
|
145 } |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMCCCodecG729::SetSdpName |
|
150 // Set SDP Name |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TInt CMCCCodecG729::SetSdpName( const TDesC8& aSdpName ) |
|
154 { |
|
155 if ( !aSdpName.CompareF( KG729SdpName ) ) |
|
156 { |
|
157 iSdpName.Copy( aSdpName ); |
|
158 } |
|
159 else |
|
160 { |
|
161 return KErrNotSupported; |
|
162 } |
|
163 |
|
164 return KErrNone; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CMCCCodecG729::SetPayloadType |
|
169 // Set PayloadType |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CMCCCodecG729::SetPayloadType( TUint8 aPayloadType ) |
|
173 { |
|
174 if ( KG729PayloadType != aPayloadType ) |
|
175 { |
|
176 return KErrNotSupported; |
|
177 } |
|
178 else |
|
179 { |
|
180 iPayloadType = aPayloadType; |
|
181 return KErrNone; |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CMCCCodecG729::SetPTime |
|
187 // Set PacketTime |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CMCCCodecG729::SetPTime( TUint aPTime ) |
|
191 { |
|
192 __INTERFACE_INT2( "CMCCCodecG729::SetPTime [aPTime, iPTime]", |
|
193 aPTime, iPTime ) |
|
194 |
|
195 if ( aPTime && ( KMinPtime <= aPTime ) && |
|
196 ( aPTime <= KMaxPtime ) && |
|
197 ( aPTime <= iMaxPTime ) && |
|
198 !( aPTime % KMinPtime ) ) |
|
199 { |
|
200 iPTime = aPTime; |
|
201 return KErrNone; |
|
202 } |
|
203 else |
|
204 { |
|
205 return KErrArgument; |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CMCCCodecG729::SetMaxPTime |
|
211 // Set Maximum PacketTime |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TInt CMCCCodecG729::SetMaxPTime( TUint aMaxPTime ) |
|
215 { |
|
216 __INTERFACE_INT2( "CMCCCodecG729::SetMaxPTime [aMaxPTime, iMaxPTime]", |
|
217 aMaxPTime, iMaxPTime ) |
|
218 |
|
219 if ( aMaxPTime && ( iPTime <= aMaxPTime ) && |
|
220 ( KMinPtime <= aMaxPTime ) && |
|
221 ( aMaxPTime <= KMaxPtime ) && |
|
222 !( aMaxPTime % KMinPtime ) ) |
|
223 { |
|
224 iMaxPTime = aMaxPTime; |
|
225 return KErrNone; |
|
226 } |
|
227 else |
|
228 { |
|
229 return KErrArgument; |
|
230 } |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CMCCCodecG729::SetCodecMode |
|
235 // Set Codec Mode |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TInt CMCCCodecG729::SetCodecMode( TCodecMode aCodecMode ) |
|
239 { |
|
240 if ( ENothing == aCodecMode ) |
|
241 { |
|
242 iCodecMode = aCodecMode; |
|
243 return KErrNone; |
|
244 } |
|
245 else |
|
246 { |
|
247 return KErrNotSupported; |
|
248 } |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CMCCCodecG729::CloneDefaultsL |
|
253 // Make a default setting clone from this G.729 codec |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 CMccCodecInformation* CMCCCodecG729::CloneDefaultsL() |
|
257 { |
|
258 return CMCCCodecG729::NewL(); |
|
259 }; |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CMCCCodecG729::CloneDetailedL |
|
263 // Make a detailed clone from this G.729 codec |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 CMccCodecInformation* CMCCCodecG729::CloneDetailedL() |
|
267 { |
|
268 CMCCCodecG729* newCodec = CMCCCodecG729::NewL(); |
|
269 CleanupStack::PushL( newCodec ); |
|
270 newCodec->SetBitrate( this->Bitrate() ); |
|
271 newCodec->SetCodecMode( this->CodecMode() ); |
|
272 newCodec->SetMaxPTime( this->MaxPTime() ); |
|
273 newCodec->SetPayloadType( this->PayloadType() ); |
|
274 newCodec->SetPTime( this->PTime() ); |
|
275 newCodec->SetSamplingFreq( this->SamplingFreq() ); |
|
276 newCodec->SetSdpName( this->SdpName() ); |
|
277 newCodec->ParseFmtpAttrL( this->GetFmtpL() ); |
|
278 CleanupStack::Pop( newCodec ); |
|
279 return newCodec; |
|
280 }; |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CMCCCodecG729::RequireSignalling |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 TBool CMCCCodecG729::RequireSignalling( |
|
287 const CMccCodecInformation& aCandidate ) const |
|
288 { |
|
289 __INTERFACE( "CMCCCodecG729::RequireSignalling" ) |
|
290 TBool ret = EFalse; |
|
291 |
|
292 if ( iPTime != aCandidate.PTime() ) |
|
293 { |
|
294 __INTERFACE( "CMCCCodecG729::RequireSignalling, PTime changed" ) |
|
295 ret = ETrue; |
|
296 } |
|
297 |
|
298 if ( iMaxPTime != aCandidate.MaxPTime() ) |
|
299 { |
|
300 __INTERFACE( "CMCCCodecG729::RequireSignalling, MaxPTime changed" ) |
|
301 ret = ETrue; |
|
302 } |
|
303 |
|
304 if ( iPayloadType != aCandidate.PayloadType() ) |
|
305 { |
|
306 __INTERFACE( "CMCCCodecG729::RequireSignalling, PayloadType changed" ) |
|
307 ret = ETrue; |
|
308 } |
|
309 |
|
310 __INTERFACE_INT1( "CMCCCodecG729::RequireSignalling, exit with", ret ) |
|
311 return ret; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CMCCCodecG729::CreateFmtpAttrListL |
|
316 // Builds fmtp line according to current parameters. |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CMCCCodecG729::CreateFmtpAttrListL() |
|
320 { |
|
321 HBufC8* buf = HBufC8::NewLC( KMaxFmtpLen ); |
|
322 TPtr8 bufPtr = buf->Des(); |
|
323 |
|
324 if ( iEnableVAD ) |
|
325 { |
|
326 bufPtr.Append( KAnnexYes ); |
|
327 } |
|
328 else |
|
329 { |
|
330 bufPtr.Append( KAnnexNo ); |
|
331 } |
|
332 |
|
333 // Update iFmtpAttr |
|
334 SetFmtpAttrL( bufPtr, EFalse ); |
|
335 |
|
336 CleanupStack::PopAndDestroy( buf ); |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CMccCodecInformation::ParseFmtpAttrL |
|
341 // Parse the fmtp string, but doesn't update the iFmtpAttr |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 TBool CMCCCodecG729::ParseFmtpAttrL( const TDesC8& aFmtp ) |
|
345 { |
|
346 TBool updated( EFalse ); |
|
347 |
|
348 if ( !aFmtp.CompareF( KAnnexYes ) ) |
|
349 { |
|
350 iEnableVAD = ETrue; |
|
351 updated = ETrue; |
|
352 } |
|
353 else if ( !aFmtp.CompareF( KAnnexNo ) || !aFmtp.Length() ) |
|
354 { |
|
355 iEnableVAD = EFalse; |
|
356 updated = ETrue; |
|
357 } |
|
358 else |
|
359 { |
|
360 User::Leave( KErrArgument ); |
|
361 } |
|
362 |
|
363 return updated; |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CMCCCodecG729::GetFmtpL |
|
368 // Gets the fmtp attribute |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 TDesC8& CMCCCodecG729::GetFmtpL() |
|
372 { |
|
373 __INTERFACE( "CMCCCodecG729::GetFmtpL" ) |
|
374 if ( iFmtpAttr ) |
|
375 { |
|
376 delete iFmtpAttr; |
|
377 iFmtpAttr = NULL; |
|
378 } |
|
379 |
|
380 CreateFmtpAttrListL(); |
|
381 |
|
382 __INTERFACE( "CMccCodecG729::GetFmtpL, exit" ) |
|
383 return *iFmtpAttr; |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CMCCCodecG729::SetAllowedBitrates |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 |
|
391 TInt CMCCCodecG729::SetAllowedBitrates( TUint /*aBitrateMask*/ ) |
|
392 { |
|
393 return KErrNone; |
|
394 } |
|
395 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
396 |
|
397 // End of File |