205 // Changed if-statement to asserts. Added also check agains 0 hwframetime |
206 // Changed if-statement to asserts. Added also check agains 0 hwframetime |
206 __ASSERT_ALWAYS( aCInfo.iPtime, User::Leave( KErrArgument ) ); |
207 __ASSERT_ALWAYS( aCInfo.iPtime, User::Leave( KErrArgument ) ); |
207 __ASSERT_ALWAYS( aCInfo.iJitterBufBufferLength, User::Leave( KErrArgument ) ); |
208 __ASSERT_ALWAYS( aCInfo.iJitterBufBufferLength, User::Leave( KErrArgument ) ); |
208 __ASSERT_ALWAYS( aCInfo.iHwFrameTime, User::Leave( KErrArgument ) ); |
209 __ASSERT_ALWAYS( aCInfo.iHwFrameTime, User::Leave( KErrArgument ) ); |
209 |
210 |
210 // Save the original HW frame time because we may need it in case of |
211 if( aCInfo.iJitterBufInactivityTimeOut != iCInfo.iJitterBufInactivityTimeOut |
211 // dynamic G.711 adjustment. |
212 || aCInfo.iJitterBufBufferLength != iCInfo.iJitterBufBufferLength |
212 const TUint8 origHwtime = iCInfo.iHwFrameTime; |
213 || aCInfo.iHwFrameTime != iCInfo.iHwFrameTime |
213 iCInfo = aCInfo; |
214 || aCInfo.iFourCC != iCInfo.iFourCC |
214 iEventHandler = aEventHandler; |
215 || aPlayoutThreshold != iOriginalPlayThreshold / iBufLenMultiplier ) |
215 iEndpointId = aEndpointId; |
216 { |
216 |
217 // Save the original HW frame time because we may need it in case of |
217 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL origHwtime:", origHwtime ) |
218 // dynamic G.711 adjustment. |
218 |
219 const TUint8 origHwtime = iCInfo.iHwFrameTime; |
219 if( iCInfo.iJitterBufInactivityTimeOut ) |
220 iCInfo = aCInfo; |
220 { |
221 iEventHandler = aEventHandler; |
221 if( ( iCInfo.iJitterBufPlayToneFrequency > 0 ) && |
222 iEndpointId = aEndpointId; |
222 ( iCInfo.iJitterBufPlayToneDuration > 0 ) ) |
223 |
223 { |
224 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL origHwtime:", origHwtime ) |
224 iPlayToneInterval = iCInfo.iJitterBufPlayToneTimeout; |
225 |
225 iPlay = ETrue; |
226 if( iCInfo.iJitterBufInactivityTimeOut ) |
226 } |
227 { |
227 } |
228 if( ( iCInfo.iJitterBufPlayToneFrequency > 0 ) && |
228 |
229 ( iCInfo.iJitterBufPlayToneDuration > 0 ) ) |
229 TInt bufLenMultiplier = 1; |
230 { |
230 if ( iCInfo.iFourCC == KMMFFourCCCodeAMR ) |
231 iPlayToneInterval = iCInfo.iJitterBufPlayToneTimeout; |
231 { |
232 iPlay = ETrue; |
232 iFrameSize = KAMRNBFrameSize; |
233 } |
233 iFrameTime = KAMRNBFrameTime; |
234 } |
234 } |
235 |
235 else if ( iCInfo.iFourCC == KMMFFourCCCodeAWB ) |
236 TInt bufLenMultiplier = 1; |
236 { |
237 if ( iCInfo.iFourCC == KMMFFourCCCodeAMR ) |
237 iFrameSize = KAMRWBFrameSize; |
238 { |
238 iFrameTime = KAMRNBFrameTime; |
239 iFrameSize = KAMRNBFrameSize; |
239 iSampleRate = KWbSampleRateInkHz; |
240 iFrameTime = KAMRNBFrameTime; |
240 } |
241 } |
241 else if( iCInfo.iFourCC == KMccFourCCIdG711 ) |
242 else if ( iCInfo.iFourCC == KMMFFourCCCodeAWB ) |
242 { |
243 { |
243 // G.711 is configured dynamically. Take voip headerlength also in to |
244 iFrameSize = KAMRWBFrameSize; |
244 // account. G.711 hwframetime is in milliseconds, so need to multiply. |
245 iFrameTime = KAMRNBFrameTime; |
245 iFrameSize = ( iCInfo.iHwFrameTime * KDefaultSampleRateInkHz ) |
246 iSampleRate = KWbSampleRateInkHz; |
246 + KVoIPHeaderLength; |
247 } |
247 iFrameTime = 0; |
248 else if( iCInfo.iFourCC == KMccFourCCIdG711 ) |
248 |
249 { |
249 // In case of G.711 codec dynamic configuration, we may need to double |
250 // G.711 is configured dynamically. Take voip headerlength also in to |
250 // the jitterbuffer length if HW frame time is changed from 20ms to |
251 // account. G.711 hwframetime is in milliseconds, so need to multiply. |
251 // 10ms. |
252 iFrameSize = ( iCInfo.iHwFrameTime * KDefaultSampleRateInkHz ) |
252 if ( origHwtime ) |
253 + KVoIPHeaderLength; |
253 { |
254 iFrameTime = 0; |
254 bufLenMultiplier = origHwtime / iCInfo.iHwFrameTime; |
255 |
255 if ( !bufLenMultiplier ) |
256 // In case of G.711 codec dynamic configuration, we may need to double |
256 { |
257 // the jitterbuffer length if HW frame time is changed from 20ms to |
257 bufLenMultiplier = 1; |
258 // 10ms. |
258 } |
259 if ( origHwtime ) |
259 } |
260 { |
260 } |
261 bufLenMultiplier = origHwtime / iCInfo.iHwFrameTime; |
261 else if( iCInfo.iFourCC == KMccFourCCIdILBC ) |
262 if ( !bufLenMultiplier ) |
262 { |
263 { |
263 iFrameSize = KILBCFrameSize; |
264 bufLenMultiplier = 1; |
264 iFrameTime = 0; |
265 } |
265 } |
266 } |
266 else if( iCInfo.iFourCC == KMccFourCCIdG729 ) |
267 } |
267 { |
268 else if( iCInfo.iFourCC == KMccFourCCIdILBC ) |
268 iFrameSize = KG729FrameSize; |
269 { |
269 iFrameTime = 0; |
270 iFrameSize = KILBCFrameSize; |
270 // Multiply G.729 also by two... |
271 iFrameTime = 0; |
271 bufLenMultiplier = 2; |
272 } |
272 } |
273 else if( iCInfo.iFourCC == KMccFourCCIdG729 ) |
273 else |
274 { |
274 { |
275 iFrameSize = KG729FrameSize; |
275 __JITTER_BUFFER( "CMccJitterBufferImpl::SetupL KErrNotSupported" ) |
276 iFrameTime = 0; |
276 |
277 // Multiply G.729 also by two... |
277 User::Leave( KErrNotSupported ); |
278 bufLenMultiplier = 2; |
278 } |
279 } |
279 |
280 else |
280 // Delete old buffer & reset it |
281 { |
281 const TInt elems = iBuffer.Count(); |
282 __JITTER_BUFFER( "CMccJitterBufferImpl::SetupL KErrNotSupported" ) |
282 for( TInt i = 0; i < elems; i++ ) |
283 |
283 { |
284 User::Leave( KErrNotSupported ); |
284 delete iBuffer[i].iDataFrame; |
285 } |
285 iBuffer[i].iDataFrame = NULL; |
286 |
286 } |
287 // Save the bufLenMultiplier value, so we can use it later in comparison |
287 |
288 iBufLenMultiplier = bufLenMultiplier; |
288 iBuffer.Reset(); |
289 |
289 |
290 // Delete old buffer & reset it |
290 // Calculate needed elements |
291 const TInt elems = iBuffer.Count(); |
291 TInt bufLen = iCInfo.iJitterBufBufferLength * bufLenMultiplier; |
292 for( TInt i = 0; i < elems; i++ ) |
292 |
293 { |
293 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL G.711 bufLenMultiplier ", |
294 delete iBuffer[i].iDataFrame; |
294 bufLenMultiplier ) |
295 iBuffer[i].iDataFrame = NULL; |
295 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL iBufferLength: ", |
296 } |
296 bufLen ) |
297 |
297 |
298 iBuffer.Reset(); |
298 __ASSERT_ALWAYS( aPlayoutThreshold < bufLen, User::Leave( KErrTooBig ) ); |
299 |
299 |
300 // Calculate needed elements |
300 // if differences between bufferlength and treshold set by client |
301 TInt bufLen = iCInfo.iJitterBufBufferLength * bufLenMultiplier; |
301 // is less than 10, increase bufferlength so the differences is 10 |
302 |
302 // this is to help buffer goes to overflow easily. |
303 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL G.711 bufLenMultiplier ", |
303 // Also possible G.711/729 multiplier needs to be taken care of. |
304 bufLenMultiplier ) |
304 CheckThresholdBufferLength( bufLen, aPlayoutThreshold ); |
305 __JITTER_BUFFER_INT1( "CMccJitterBufferImpl::SetupL iBufferLength: ", |
305 iCurrentPlayThreshold = aPlayoutThreshold * bufLenMultiplier; |
306 bufLen ) |
306 iOriginalPlayThreshold = aPlayoutThreshold * bufLenMultiplier; |
307 |
307 |
308 __ASSERT_ALWAYS( aPlayoutThreshold < bufLen, User::Leave( KErrTooBig ) ); |
308 if( iCnGenerator ) |
309 |
309 { |
310 // if differences between bufferlength and treshold set by client |
310 delete iCnGenerator; |
311 // is less than 10, increase bufferlength so the differences is 10 |
311 iCnGenerator = NULL; |
312 // this is to help buffer goes to overflow easily. |
312 } |
313 // Also possible G.711/729 multiplier needs to be taken care of. |
313 |
314 CheckThresholdBufferLength( bufLen, aPlayoutThreshold ); |
314 iCnGenerator = CMccCnGenerator::NewL( iCInfo.iFourCC, aDevSound ); |
315 iCurrentPlayThreshold = aPlayoutThreshold * bufLenMultiplier; |
315 |
316 iOriginalPlayThreshold = aPlayoutThreshold * bufLenMultiplier; |
316 // Create the elements in the Buffer |
317 |
317 for( TInt k = 0; k < bufLen; k++ ) |
318 if( iCnGenerator ) |
318 { |
319 { |
319 CMMFDataBuffer* buf = CMMFDataBuffer::NewL( iFrameSize ); |
320 delete iCnGenerator; |
320 CleanupStack::PushL( buf ); |
321 iCnGenerator = NULL; |
321 TJitterBufferElement newElement; |
322 } |
322 newElement.iDataFrame = buf; |
323 |
323 newElement.iSequenceNumber = -1; |
324 iCnGenerator = CMccCnGenerator::NewL( iCInfo.iFourCC, aDevSound ); |
324 newElement.iStamp = -1; |
325 |
325 iBuffer.AppendL( newElement ); |
326 // Create the elements in the Buffer |
326 CleanupStack::Pop( buf ); |
327 for( TInt k = 0; k < bufLen; k++ ) |
327 } |
328 { |
328 |
329 CMMFDataBuffer* buf = CMMFDataBuffer::NewL( iFrameSize ); |
329 // Zero the statistic members |
330 CleanupStack::PushL( buf ); |
330 iFramesLost = 0; |
331 TJitterBufferElement newElement; |
331 iFramesReceived = 0; |
332 newElement.iDataFrame = buf; |
332 iNumOfLateFrames = 0; |
333 newElement.iSequenceNumber = -1; |
333 iFramesRemoved = 0; |
334 newElement.iStamp = -1; |
334 iFramesPlayed = 0; |
335 iBuffer.AppendL( newElement ); |
335 iPacketsInBuffer = 0; |
336 CleanupStack::Pop( buf ); |
336 |
337 } |
337 // Calculate the sequence number increment |
338 |
338 iSeqNumIncrement = iSampleRate * iCInfo.iHwFrameTime; |
339 // Zero the statistic members |
|
340 iFramesLost = 0; |
|
341 iFramesReceived = 0; |
|
342 iNumOfLateFrames = 0; |
|
343 iFramesRemoved = 0; |
|
344 iFramesPlayed = 0; |
|
345 iPacketsInBuffer = 0; |
|
346 |
|
347 // Calculate the sequence number increment |
|
348 iSeqNumIncrement = iSampleRate * iCInfo.iHwFrameTime; |
|
349 } |
339 } |
350 } |
340 |
351 |
341 // ----------------------------------------------------------------------------- |
352 // ----------------------------------------------------------------------------- |
342 // CMccJitterBufferImpl::ResetBufferL |
353 // CMccJitterBufferImpl::ResetBufferL |
343 // Reset Jitterbuffer |
354 // Reset Jitterbuffer |