Changeset 3841 for pjproject/trunk/pjmedia/src/pjmedia/delaybuf.c
- Timestamp:
- Oct 24, 2011 9:28:13 AM (12 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk
- Property svn:mergeinfo changed
-
pjproject/trunk/pjmedia/src/pjmedia/delaybuf.c
r3664 r3841 101 101 PJ_ASSERT_RETURN(pool && samples_per_frame && clock_rate && channel_count && 102 102 p_b, PJ_EINVAL); 103 PJ_ASSERT_RETURN(options==0, PJ_EINVAL);104 105 PJ_UNUSED_ARG(options);106 103 107 104 if (!name) { … … 128 125 return status; 129 126 130 /* Create WSOLA */ 131 status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 132 PJMEDIA_WSOLA_NO_FADING, &b->wsola); 133 if (status != PJ_SUCCESS) 134 return status; 127 if (!(options & PJMEDIA_DELAY_BUF_SIMPLE_FIFO)) { 128 /* Create WSOLA */ 129 status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 130 PJMEDIA_WSOLA_NO_FADING, &b->wsola); 131 if (status != PJ_SUCCESS) 132 return status; 133 PJ_LOG(5, (b->obj_name, "Using delay buffer with WSOLA.")); 134 } else { 135 PJ_LOG(5, (b->obj_name, "Using simple FIFO delay buffer.")); 136 } 135 137 136 138 /* Finally, create mutex */ … … 149 151 PJ_DEF(pj_status_t) pjmedia_delay_buf_destroy(pjmedia_delay_buf *b) 150 152 { 151 pj_status_t status ;153 pj_status_t status = PJ_SUCCESS; 152 154 153 155 PJ_ASSERT_RETURN(b, PJ_EINVAL); … … 155 157 pj_lock_acquire(b->lock); 156 158 157 status = pjmedia_wsola_destroy(b->wsola); 158 if (status == PJ_SUCCESS) 159 b->wsola = NULL; 159 if (b->wsola) { 160 status = pjmedia_wsola_destroy(b->wsola); 161 if (status == PJ_SUCCESS) 162 b->wsola = NULL; 163 } 160 164 161 165 pj_lock_release(b->lock); … … 266 270 pj_lock_acquire(b->lock); 267 271 268 update(b, OP_PUT); 272 if (b->wsola) { 273 update(b, OP_PUT); 269 274 270 status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 271 if (status != PJ_SUCCESS) { 272 pj_lock_release(b->lock); 273 return status; 275 status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 276 if (status != PJ_SUCCESS) { 277 pj_lock_release(b->lock); 278 return status; 279 } 274 280 } 275 281 … … 279 285 { 280 286 unsigned erase_cnt; 281 282 /* shrink one frame or just the diff? */ 283 //erase_cnt = b->samples_per_frame; 284 erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) + 285 b->samples_per_frame - b->max_cnt; 286 287 shrink_buffer(b, erase_cnt); 287 288 if (b->wsola) { 289 /* shrink one frame or just the diff? */ 290 //erase_cnt = b->samples_per_frame; 291 erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) + 292 b->samples_per_frame - b->max_cnt; 293 294 shrink_buffer(b, erase_cnt); 295 } 288 296 289 297 /* Check if shrinking failed or erased count is less than requested, … … 299 307 pjmedia_circ_buf_adv_read_ptr(b->circ_buf, erase_cnt); 300 308 301 PJ_LOG(4,(b->obj_name," Shrinking failed or insufficient, dropping"302 " %d eldest samples, buf_cnt=%d", erase_cnt, 303 309 PJ_LOG(4,(b->obj_name,"%sDropping %d eldest samples, buf_cnt=%d", 310 (b->wsola? "Shrinking failed or insufficient. ": ""), 311 erase_cnt, pjmedia_circ_buf_get_len(b->circ_buf))); 304 312 } 305 313 } … … 314 322 pj_int16_t frame[]) 315 323 { 316 pj_status_t status ;324 pj_status_t status = PJ_SUCCESS; 317 325 318 326 PJ_ASSERT_RETURN(b && frame, PJ_EINVAL); … … 320 328 pj_lock_acquire(b->lock); 321 329 322 update(b, OP_GET); 330 if (b->wsola) 331 update(b, OP_GET); 323 332 324 333 /* Starvation checking */ … … 328 337 pjmedia_circ_buf_get_len(b->circ_buf))); 329 338 330 status = pjmedia_wsola_generate(b->wsola, frame); 331 332 if (status == PJ_SUCCESS) { 333 TRACE__((b->obj_name,"Successfully generate 1 frame")); 334 if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 335 pj_lock_release(b->lock); 336 return PJ_SUCCESS; 337 } 338 339 /* Put generated frame into buffer */ 340 pjmedia_circ_buf_write(b->circ_buf, frame, b->samples_per_frame); 341 342 } else { 339 if (b->wsola) { 340 status = pjmedia_wsola_generate(b->wsola, frame); 341 342 if (status == PJ_SUCCESS) { 343 TRACE__((b->obj_name,"Successfully generate 1 frame")); 344 if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 345 pj_lock_release(b->lock); 346 return PJ_SUCCESS; 347 } 348 349 /* Put generated frame into buffer */ 350 pjmedia_circ_buf_write(b->circ_buf, frame, 351 b->samples_per_frame); 352 } 353 } 354 355 if (!b->wsola || status != PJ_SUCCESS) { 343 356 unsigned buf_len = pjmedia_circ_buf_get_len(b->circ_buf); 344 357 345 358 /* Give all what delay buffer has, then pad with zeroes */ 346 PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d", 347 status)); 359 if (b->wsola) 360 PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d", 361 status)); 348 362 349 363 pjmedia_circ_buf_read(b->circ_buf, frame, buf_len); … … 380 394 381 395 /* Reset WSOLA */ 382 pjmedia_wsola_reset(b->wsola, 0); 396 if (b->wsola) 397 pjmedia_wsola_reset(b->wsola, 0); 383 398 384 399 pj_lock_release(b->lock);
Note: See TracChangeset
for help on using the changeset viewer.