Ignore:
Timestamp:
Oct 24, 2011 9:28:13 AM (13 years ago)
Author:
ming
Message:

Re #1395: Backport of PJSIP 1.x branch into PJSIP 2.0 trunk

TODO: ticket #1268 (Option for automatic/manual sending of RTCP SDES/BYE for the stream) for video stream.

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk

  • pjproject/trunk/pjmedia/src/pjmedia/delaybuf.c

    r3664 r3841  
    101101    PJ_ASSERT_RETURN(pool && samples_per_frame && clock_rate && channel_count && 
    102102                     p_b, PJ_EINVAL); 
    103     PJ_ASSERT_RETURN(options==0, PJ_EINVAL); 
    104  
    105     PJ_UNUSED_ARG(options); 
    106103 
    107104    if (!name) { 
     
    128125        return status; 
    129126 
    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    } 
    135137 
    136138    /* Finally, create mutex */ 
     
    149151PJ_DEF(pj_status_t) pjmedia_delay_buf_destroy(pjmedia_delay_buf *b) 
    150152{ 
    151     pj_status_t status; 
     153    pj_status_t status = PJ_SUCCESS; 
    152154 
    153155    PJ_ASSERT_RETURN(b, PJ_EINVAL); 
     
    155157    pj_lock_acquire(b->lock); 
    156158 
    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    } 
    160164 
    161165    pj_lock_release(b->lock); 
     
    266270    pj_lock_acquire(b->lock); 
    267271 
    268     update(b, OP_PUT); 
     272    if (b->wsola) { 
     273        update(b, OP_PUT); 
    269274     
    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        } 
    274280    } 
    275281 
     
    279285    { 
    280286        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        } 
    288296 
    289297        /* Check if shrinking failed or erased count is less than requested, 
     
    299307            pjmedia_circ_buf_adv_read_ptr(b->circ_buf, erase_cnt); 
    300308 
    301             PJ_LOG(4,(b->obj_name,"Shrinking failed or insufficient, dropping" 
    302                       " %d eldest samples, buf_cnt=%d", erase_cnt,  
    303                       pjmedia_circ_buf_get_len(b->circ_buf))); 
     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))); 
    304312        } 
    305313    } 
     
    314322                                           pj_int16_t frame[]) 
    315323{ 
    316     pj_status_t status; 
     324    pj_status_t status = PJ_SUCCESS; 
    317325 
    318326    PJ_ASSERT_RETURN(b && frame, PJ_EINVAL); 
     
    320328    pj_lock_acquire(b->lock); 
    321329 
    322     update(b, OP_GET); 
     330    if (b->wsola) 
     331        update(b, OP_GET); 
    323332 
    324333    /* Starvation checking */ 
     
    328337                  pjmedia_circ_buf_get_len(b->circ_buf))); 
    329338 
    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) { 
    343356            unsigned buf_len = pjmedia_circ_buf_get_len(b->circ_buf); 
    344357             
    345358            /* 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)); 
    348362 
    349363            pjmedia_circ_buf_read(b->circ_buf, frame, buf_len); 
     
    380394 
    381395    /* Reset WSOLA */ 
    382     pjmedia_wsola_reset(b->wsola, 0); 
     396    if (b->wsola) 
     397        pjmedia_wsola_reset(b->wsola, 0); 
    383398 
    384399    pj_lock_release(b->lock); 
Note: See TracChangeset for help on using the changeset viewer.