Changeset 1982
- Timestamp:
- Jun 5, 2008 6:17:38 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/delaybuf.c
r1972 r1982 217 217 b->buf_cnt -= erase_cnt; 218 218 219 PJ_LOG(5,(b->obj_name,"Overflow, %d samples reduced, " 220 "buf_cnt=%d", erase_cnt, b->buf_cnt)); 221 } 222 223 /* Shrinking failed or erased count is less than requested, 224 * delaybuf needs to drop eldest samples, this is bad since the voice 225 * samples may not have smooth transition. 226 */ 227 if (b->buf_cnt + b->samples_per_frame > b->max_cnt) { 228 erase_cnt = b->buf_cnt + b->samples_per_frame - b->max_cnt; 229 230 b->buf_cnt -= erase_cnt; 231 232 /* Shift get_pos forward */ 233 b->get_pos = (b->get_pos + erase_cnt) % b->max_cnt; 234 235 PJ_LOG(4,(b->obj_name,"Shrinking failed or insufficient, dropping" 236 " %d eldest samples, buf_cnt=%d", erase_cnt, b->buf_cnt)); 219 PJ_LOG(5,(b->obj_name,"%d samples reduced, buf_cnt=%d", 220 erase_cnt, b->buf_cnt)); 237 221 } 238 222 } … … 287 271 288 272 shrink_buffer(b, erase_cnt); 289 PJ_LOG( 5,(b->obj_name,"Buffer size adjusted from %d to %d",290 old_buf_cnt, b->buf_cnt));273 PJ_LOG(4,(b->obj_name,"Buffer size adjusted from %d to %d (eff_cnt=%d)", 274 old_buf_cnt, b->buf_cnt, b->eff_cnt)); 291 275 } 292 276 } … … 312 296 if (b->buf_cnt + b->samples_per_frame > b->max_cnt) 313 297 { 298 unsigned erase_cnt; 299 314 300 /* shrink one frame or just the diff? */ 315 // unsignederase_cnt = b->samples_per_frame;316 unsignederase_cnt = b->buf_cnt + b->samples_per_frame - b->max_cnt;301 //erase_cnt = b->samples_per_frame; 302 erase_cnt = b->buf_cnt + b->samples_per_frame - b->max_cnt; 317 303 318 304 shrink_buffer(b, erase_cnt); 305 306 /* Check if shrinking failed or erased count is less than requested, 307 * delaybuf needs to drop eldest samples, this is bad since the voice 308 * samples get rough transition which may produce tick noise. 309 */ 310 if (b->buf_cnt + b->samples_per_frame > b->max_cnt) { 311 erase_cnt = b->buf_cnt + b->samples_per_frame - b->max_cnt; 312 313 b->buf_cnt -= erase_cnt; 314 315 /* Shift get_pos forward */ 316 b->get_pos = (b->get_pos + erase_cnt) % b->max_cnt; 317 318 PJ_LOG(4,(b->obj_name,"Shrinking failed or insufficient, dropping" 319 " %d eldest samples, buf_cnt=%d", erase_cnt, b->buf_cnt)); 320 } 319 321 } 320 322 … … 355 357 if (b->buf_cnt < b->samples_per_frame) { 356 358 357 PJ_LOG( 5,(b->obj_name,"Underflow, buf_cnt=%d, will generate 1 frame",359 PJ_LOG(4,(b->obj_name,"Underflow, buf_cnt=%d, will generate 1 frame", 358 360 b->buf_cnt)); 359 361 … … 385 387 386 388 } else { 387 /* Give all what delay buffer has, then pad zeroes */389 /* Give all what delay buffer has, then pad with zeroes */ 388 390 PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d", 389 391 status)); 390 392 391 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], b->buf_cnt); 393 if (b->get_pos + b->buf_cnt <= b->max_cnt) { 394 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], b->buf_cnt); 395 } else { 396 int remainder = b->get_pos + b->buf_cnt - b->max_cnt; 397 398 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], 399 b->buf_cnt - remainder); 400 pjmedia_copy_samples(&frame[b->buf_cnt - remainder], 401 &b->frame_buf[0], remainder); 402 } 403 392 404 pjmedia_zero_samples(&frame[b->buf_cnt], 393 405 b->samples_per_frame - b->buf_cnt); 394 b->get_pos += b->buf_cnt; 406 407 /* Delay buf is empty */ 408 b->get_pos = b->put_pos = 0; 395 409 b->buf_cnt = 0; 396 397 /* Consistency checking */398 pj_assert(b->get_pos == b->put_pos);399 410 400 411 pj_lock_release(b->lock); … … 404 415 } 405 416 406 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], 407 b->samples_per_frame); 417 if (b->get_pos + b->samples_per_frame <= b->max_cnt) { 418 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], 419 b->samples_per_frame); 420 } else { 421 int remainder = b->get_pos + b->samples_per_frame - b->max_cnt; 422 423 pjmedia_copy_samples(frame, &b->frame_buf[b->get_pos], 424 b->samples_per_frame - remainder); 425 pjmedia_copy_samples(&frame[b->samples_per_frame - remainder], 426 &b->frame_buf[0], 427 remainder); 428 } 408 429 409 430 b->get_pos = (b->get_pos + b->samples_per_frame) % b->max_cnt;
Note: See TracChangeset
for help on using the changeset viewer.