Ignore:
Timestamp:
May 11, 2006 2:22:01 PM (17 years ago)
Author:
bennylp
Message:

Fixed bug: incorrect remote and local PT for telephone-events (swapped)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/jbuf.c

    r411 r435  
    6565                                          // (at the beginning of the framelist->flist_buffer operation) 
    6666    int             jb_prefetch_cnt;      // prefetch counter 
     67    int             jb_min_prefetch;      // Minimum allowable prefetch 
     68    int             jb_max_prefetch;      // Maximum allowable prefetch 
    6769    int             jb_status;            // status is 'init' until the first 'put' operation 
    6870 
     
    138140                    framelist->flist_head * framelist->flist_frame_size, 
    139141                  0, framelist->flist_frame_size); 
    140         framelist->flist_frame_type[framelist->flist_head] = 0; 
     142        framelist->flist_frame_type[framelist->flist_head] =  
     143            PJMEDIA_JB_MISSING_FRAME; 
    141144 
    142145        framelist->flist_origin++; 
     
    182185                  step1*framelist->flist_frame_size); 
    183186        pj_memset(framelist->flist_frame_type+framelist->flist_head, 
    184                   0, 
     187                  PJMEDIA_JB_MISSING_FRAME, 
    185188                  step1*sizeof(framelist->flist_frame_type[0])); 
    186189 
     
    190193                      step2*framelist->flist_frame_size); 
    191194            pj_memset(framelist->flist_frame_type, 
    192                       0, 
     195                      PJMEDIA_JB_MISSING_FRAME, 
    193196                      step2*sizeof(framelist->flist_frame_type[0])); 
    194197        } 
     
    264267PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool,  
    265268                                        const pj_str_t *name, 
    266                                         int frame_size,  
    267                                         int initial_prefetch,  
    268                                         int max_count, 
     269                                        unsigned frame_size,  
     270                                        unsigned max_count, 
    269271                                        pjmedia_jbuf **p_jb) 
    270272{ 
     
    285287    jb->jb_last_jitter   = 0; 
    286288    jb->jb_last_op       = JB_OP_INIT; 
    287     jb->jb_prefetch      = PJ_MIN(initial_prefetch, max_count*4/5); 
     289    jb->jb_prefetch      = PJ_MIN(PJMEDIA_JB_DEFAULT_INIT_DELAY,max_count*4/5); 
    288290    jb->jb_prefetch_cnt  = 0; 
     291    jb->jb_min_prefetch  = 0; 
     292    jb->jb_max_prefetch  = max_count*4/5; 
    289293    jb->jb_stable_hist   = 0; 
    290294    jb->jb_status        = JB_STATUS_INITIALIZING; 
     
    293297 
    294298    *p_jb = jb; 
     299    return PJ_SUCCESS; 
     300} 
     301 
     302 
     303/* 
     304 * Set the jitter buffer to fixed delay mode. The default behavior 
     305 * is to adapt the delay with actual packet delay. 
     306 * 
     307 */ 
     308PJ_DEF(pj_status_t) pjmedia_jbuf_set_fixed( pjmedia_jbuf *jb, 
     309                                            unsigned prefetch) 
     310{ 
     311    PJ_ASSERT_RETURN(jb, PJ_EINVAL); 
     312    PJ_ASSERT_RETURN(prefetch <= jb->jb_max_count, PJ_EINVAL); 
     313 
     314    jb->jb_min_prefetch = jb->jb_max_prefetch =  
     315        jb->jb_prefetch = prefetch; 
     316 
     317    return PJ_SUCCESS; 
     318} 
     319 
     320 
     321/* 
     322 * Set the jitter buffer to adaptive mode. 
     323 */ 
     324PJ_DEF(pj_status_t) pjmedia_jbuf_set_adaptive( pjmedia_jbuf *jb, 
     325                                               unsigned prefetch, 
     326                                               unsigned min_prefetch, 
     327                                               unsigned max_prefetch) 
     328{ 
     329    PJ_ASSERT_RETURN(jb, PJ_EINVAL); 
     330    PJ_ASSERT_RETURN(min_prefetch < max_prefetch && 
     331                     prefetch >= min_prefetch && 
     332                     prefetch <= max_prefetch && 
     333                     max_prefetch <= jb->jb_max_count, 
     334                     PJ_EINVAL); 
     335 
     336    jb->jb_prefetch = prefetch; 
     337    jb->jb_min_prefetch = min_prefetch; 
     338    jb->jb_max_prefetch = max_prefetch; 
     339 
    295340    return PJ_SUCCESS; 
    296341} 
     
    337382 
    338383            jb->jb_prefetch -= seq_diff; 
    339             if (jb->jb_prefetch < 1) jb->jb_prefetch = 1; 
     384            if (jb->jb_prefetch < jb->jb_min_prefetch)  
     385                jb->jb_prefetch = jb->jb_min_prefetch; 
    340386 
    341387            jb->jb_stable_hist = 0; 
     
    358404        jb->jb_prefetch = PJ_MIN(jb->jb_last_jitter, 
    359405                                 (int)(jb->jb_max_count*4/5)); 
     406        if (jb->jb_prefetch > jb->jb_max_prefetch) 
     407            jb->jb_prefetch = jb->jb_max_prefetch; 
    360408        jb->jb_stable_hist = 0; 
    361409        jb->jb_max_hist_jitter = 0; 
     
    432480} 
    433481 
     482/* 
     483 * Get frame from jitter buffer. 
     484 */ 
    434485PJ_DEF(pj_status_t) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb,  
    435486                                            void *frame,  
     
    446497    } 
    447498 
    448     if ((jb->jb_prefetch_cnt < jb->jb_prefetch) ||  
    449         jb_framelist_get(&jb->jb_framelist,frame,&ftype) == PJ_FALSE)  
    450     { 
     499    if ((jb->jb_prefetch_cnt < jb->jb_prefetch)) { 
     500        /* Can't return frame because jitter buffer is filling up 
     501         * minimum prefetch. 
     502         */ 
    451503        pj_memset(frame, 0, jb->jb_frame_size); 
    452         *p_frame_type = PJMEDIA_JB_ZERO_FRAME; 
     504        if (jb_framelist_size(&jb->jb_framelist) == 0) 
     505            *p_frame_type = PJMEDIA_JB_ZERO_EMPTY_FRAME; 
     506        else 
     507            *p_frame_type = PJMEDIA_JB_ZERO_PREFETCH_FRAME; 
     508 
    453509        return PJ_SUCCESS; 
    454510    } 
    455511 
     512    /* Retrieve a frame from frame list */ 
     513    if (jb_framelist_get(&jb->jb_framelist,frame,&ftype) == PJ_FALSE) { 
     514        /* Can't return frame because jitter buffer is empty! */ 
     515        pj_memset(frame, 0, jb->jb_frame_size); 
     516        *p_frame_type = PJMEDIA_JB_ZERO_EMPTY_FRAME; 
     517 
     518        return PJ_SUCCESS; 
     519    } 
     520 
     521    /* We've successfully retrieved a frame from the frame list, but 
     522     * the frame could be a blank frame! 
     523     */ 
    456524    if (ftype == PJMEDIA_JB_NORMAL_FRAME) { 
    457525        *p_frame_type   = PJMEDIA_JB_NORMAL_FRAME; 
     
    463531} 
    464532 
    465 PJ_DEF(unsigned) pjmedia_jbuf_get_min_delay_size(pjmedia_jbuf *jb) 
    466 { 
    467     return jb->jb_prefetch; 
    468 } 
    469  
    470 PJ_DEF(unsigned) pjmedia_jbuf_get_delay(pjmedia_jbuf *jb) 
    471 { 
    472     return jb_framelist_size(&jb->jb_framelist); 
    473 } 
    474  
    475  
     533/* 
     534 * Get jitter buffer state. 
     535 */ 
     536PJ_DEF(pj_status_t) pjmedia_jbuf_get_state( pjmedia_jbuf *jb, 
     537                                            pjmedia_jb_state *state ) 
     538{ 
     539    PJ_ASSERT_RETURN(jb && state, PJ_EINVAL); 
     540 
     541    state->frame_size = jb->jb_frame_size; 
     542    state->prefetch = jb->jb_prefetch; 
     543    state->min_prefetch = jb->jb_min_prefetch; 
     544    state->max_prefetch = jb->jb_max_prefetch; 
     545    state->size = jb_framelist_size(&jb->jb_framelist); 
     546 
     547    return PJ_SUCCESS; 
     548} 
     549 
Note: See TracChangeset for help on using the changeset viewer.