Ignore:
Timestamp:
May 15, 2011 12:54:28 PM (13 years ago)
Author:
ming
Message:

Fixed #1257: Option for using simple FIFO delay buffer in echo canceller.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjmedia/src/pjmedia/delaybuf.c

    r3553 r3567  
    100100    PJ_ASSERT_RETURN(pool && samples_per_frame && clock_rate && channel_count && 
    101101                     p_b, PJ_EINVAL); 
    102     PJ_ASSERT_RETURN(options==0, PJ_EINVAL); 
    103  
    104     PJ_UNUSED_ARG(options); 
    105102 
    106103    if (!name) { 
     
    127124        return status; 
    128125 
    129     /* Create WSOLA */ 
    130     status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 
    131                                   PJMEDIA_WSOLA_NO_FADING, &b->wsola); 
    132     if (status != PJ_SUCCESS) 
    133         return status; 
     126    if (!(options & PJMEDIA_DELAY_BUF_SIMPLE_FIFO)) { 
     127        /* Create WSOLA */ 
     128        status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, 
     129                                      PJMEDIA_WSOLA_NO_FADING, &b->wsola); 
     130        if (status != PJ_SUCCESS) 
     131            return status; 
     132        PJ_LOG(5, (b->obj_name, "Using delay buffer with WSOLA.")); 
     133    } else { 
     134        PJ_LOG(5, (b->obj_name, "Using simple FIFO delay buffer.")); 
     135    } 
    134136 
    135137    /* Finally, create mutex */ 
     
    148150PJ_DEF(pj_status_t) pjmedia_delay_buf_destroy(pjmedia_delay_buf *b) 
    149151{ 
    150     pj_status_t status; 
     152    pj_status_t status = PJ_SUCCESS; 
    151153 
    152154    PJ_ASSERT_RETURN(b, PJ_EINVAL); 
     
    154156    pj_lock_acquire(b->lock); 
    155157 
    156     status = pjmedia_wsola_destroy(b->wsola); 
    157     if (status == PJ_SUCCESS) 
    158         b->wsola = NULL; 
     158    if (b->wsola) { 
     159        status = pjmedia_wsola_destroy(b->wsola); 
     160        if (status == PJ_SUCCESS) 
     161            b->wsola = NULL; 
     162    } 
    159163 
    160164    pj_lock_release(b->lock); 
     
    265269    pj_lock_acquire(b->lock); 
    266270 
    267     update(b, OP_PUT); 
     271    if (b->wsola) { 
     272        update(b, OP_PUT); 
    268273     
    269     status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 
    270     if (status != PJ_SUCCESS) { 
    271         pj_lock_release(b->lock); 
    272         return status; 
     274        status = pjmedia_wsola_save(b->wsola, frame, PJ_FALSE); 
     275        if (status != PJ_SUCCESS) { 
     276            pj_lock_release(b->lock); 
     277            return status; 
     278        } 
    273279    } 
    274280 
     
    278284    { 
    279285        unsigned erase_cnt; 
    280          
    281         /* shrink one frame or just the diff? */ 
    282         //erase_cnt = b->samples_per_frame; 
    283         erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) +  
    284                     b->samples_per_frame - b->max_cnt; 
    285  
    286         shrink_buffer(b, erase_cnt); 
     286 
     287        if (b->wsola) { 
     288            /* shrink one frame or just the diff? */ 
     289            //erase_cnt = b->samples_per_frame; 
     290            erase_cnt = pjmedia_circ_buf_get_len(b->circ_buf) +  
     291                        b->samples_per_frame - b->max_cnt; 
     292 
     293            shrink_buffer(b, erase_cnt); 
     294        } 
    287295 
    288296        /* Check if shrinking failed or erased count is less than requested, 
     
    298306            pjmedia_circ_buf_adv_read_ptr(b->circ_buf, erase_cnt); 
    299307 
    300             PJ_LOG(4,(b->obj_name,"Shrinking failed or insufficient, dropping" 
    301                       " %d eldest samples, buf_cnt=%d", erase_cnt,  
    302                       pjmedia_circ_buf_get_len(b->circ_buf))); 
     308            PJ_LOG(4,(b->obj_name,"%sDropping %d eldest samples, buf_cnt=%d", 
     309                      (b->wsola? "Shrinking failed or insufficient. ": ""), 
     310                      erase_cnt, pjmedia_circ_buf_get_len(b->circ_buf))); 
    303311        } 
    304312    } 
     
    313321                                           pj_int16_t frame[]) 
    314322{ 
    315     pj_status_t status; 
     323    pj_status_t status = PJ_SUCCESS; 
    316324 
    317325    PJ_ASSERT_RETURN(b && frame, PJ_EINVAL); 
     
    319327    pj_lock_acquire(b->lock); 
    320328 
    321     update(b, OP_GET); 
     329    if (b->wsola) 
     330        update(b, OP_GET); 
    322331 
    323332    /* Starvation checking */ 
     
    327336                  pjmedia_circ_buf_get_len(b->circ_buf))); 
    328337 
    329         status = pjmedia_wsola_generate(b->wsola, frame); 
    330  
    331         if (status == PJ_SUCCESS) { 
    332             TRACE__((b->obj_name,"Successfully generate 1 frame")); 
    333             if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 
    334                 pj_lock_release(b->lock); 
    335                 return PJ_SUCCESS; 
    336             } 
    337  
    338             /* Put generated frame into buffer */ 
    339             pjmedia_circ_buf_write(b->circ_buf, frame, b->samples_per_frame); 
    340  
    341         } else { 
     338        if (b->wsola) { 
     339            status = pjmedia_wsola_generate(b->wsola, frame); 
     340 
     341            if (status == PJ_SUCCESS) { 
     342                TRACE__((b->obj_name,"Successfully generate 1 frame")); 
     343                if (pjmedia_circ_buf_get_len(b->circ_buf) == 0) { 
     344                    pj_lock_release(b->lock); 
     345                    return PJ_SUCCESS; 
     346                } 
     347 
     348                /* Put generated frame into buffer */ 
     349                pjmedia_circ_buf_write(b->circ_buf, frame, 
     350                                       b->samples_per_frame); 
     351            } 
     352        } 
     353 
     354        if (!b->wsola || status != PJ_SUCCESS) { 
    342355            unsigned buf_len = pjmedia_circ_buf_get_len(b->circ_buf); 
    343356             
    344357            /* Give all what delay buffer has, then pad with zeroes */ 
    345             PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d",  
    346                       status)); 
     358            if (b->wsola) 
     359                PJ_LOG(4,(b->obj_name,"Error generating frame, status=%d",  
     360                          status)); 
    347361 
    348362            pjmedia_circ_buf_read(b->circ_buf, frame, buf_len); 
     
    379393 
    380394    /* Reset WSOLA */ 
    381     pjmedia_wsola_reset(b->wsola, 0); 
     395    if (b->wsola) 
     396        pjmedia_wsola_reset(b->wsola, 0); 
    382397 
    383398    pj_lock_release(b->lock); 
Note: See TracChangeset for help on using the changeset viewer.