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