Changeset 2317


Ignore:
Timestamp:
Sep 24, 2008 5:27:46 PM (15 years ago)
Author:
nanang
Message:

Ticket #638: Reenable prefetch buffering via initial prefetch setting (set 0 to disable, otherwise to enable).

Location:
pjproject/trunk/pjmedia
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/jbuf.h

    r2039 r2317  
    150150 * 
    151151 * @param jb            The jitter buffer. 
    152  * @param prefetch      The prefetch value to be applied to the jitter 
    153  *                      buffer. 
     152 * @param prefetch      The initial prefetch value to be applied to the 
     153 *                      jitter buffer. Setting this to other than 0 will 
     154 *                      activate prefetch buffering, a jitter buffer feature 
     155 *                      that each time it gets empty, it won't return a  
     156 *                      normal frame until its size reaches the number 
     157 *                      specified here. 
    154158 * @param min_prefetch  The minimum delay that must be applied to each 
    155  *                      incoming packets, in number of frames. The 
    156  *                      default value is zero. 
     159 *                      incoming packets, in number of frames. 
    157160 * @param max_prefetch  The maximum allowable value for prefetch delay, 
    158  *                      in number of frames. The default value is equal 
    159  *                      to the size of the jitter buffer. 
     161 *                      in number of frames. 
    160162 * 
    161163 * @return              PJ_SUCCESS on success. 
  • pjproject/trunk/pjmedia/src/pjmedia/jbuf.c

    r2310 r2317  
    3333#define SAFE_SHRINKING_DIFF     1 
    3434#define MIN_SHRINK_GAP_MSEC     200 
    35 #define USE_PREFETCH_BUFFERING  0 
    3635 
    3736typedef struct jb_framelist_t 
     
    6766                                          // (at the beginning of the framelist->flist_buffer operation) 
    6867    int             jb_prefetch_cnt;      // prefetch counter 
     68    int             jb_def_prefetch;      // Default prefetch 
    6969    int             jb_min_prefetch;      // Minimum allowable prefetch 
    7070    int             jb_max_prefetch;      // Maximum allowable prefetch 
     
    7979#define JB_STATUS_INITIALIZING  0 
    8080#define JB_STATUS_PROCESSING    1 
     81#define JB_STATUS_PREFETCHING   2 
    8182 
    8283/* Enabling this would log the jitter buffer state about once per  
     
    344345 
    345346    jb->jb_min_prefetch = jb->jb_max_prefetch =  
    346         jb->jb_prefetch = prefetch; 
     347        jb->jb_prefetch = jb->jb_def_prefetch = prefetch; 
    347348 
    348349    return PJ_SUCCESS; 
     
    365366                     PJ_EINVAL); 
    366367 
    367     jb->jb_prefetch = prefetch; 
     368    jb->jb_prefetch = jb->jb_def_prefetch = prefetch; 
    368369    jb->jb_min_prefetch = min_prefetch; 
    369370    jb->jb_max_prefetch = max_prefetch; 
     
    423424            if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) { 
    424425                 
     426                diff = (jb->jb_prefetch - jb->jb_max_hist_level) / 3; 
     427 
     428                if (diff < 1) 
     429                    diff = 1; 
     430 
    425431                /* Update max_hist_level. */ 
    426432                jb->jb_max_hist_level = jb->jb_prefetch; 
    427  
    428                 diff = (jb->jb_prefetch - jb->jb_max_hist_level) / 3; 
    429  
    430                 if (diff < 1) 
    431                     diff = 1; 
    432433 
    433434                jb->jb_prefetch -= diff; 
     
    542543        } 
    543544 
    544         if (jb->jb_prefetch_cnt < jb->jb_prefetch)       
     545        if (jb->jb_prefetch_cnt < jb->jb_prefetch) { 
    545546            jb->jb_prefetch_cnt += seq_diff; 
     547             
     548            TRACE__((jb->name.ptr, "PUT prefetch_cnt=%d/%d",  
     549                     jb->jb_prefetch_cnt, jb->jb_prefetch)); 
     550 
     551            if (jb->jb_status == JB_STATUS_PREFETCHING &&  
     552                jb->jb_prefetch_cnt >= jb->jb_prefetch) 
     553            { 
     554                int diff, cur_size; 
     555 
     556                cur_size = jb_framelist_size(&jb->jb_framelist); 
     557                jb->jb_status = JB_STATUS_PROCESSING; 
     558            } 
     559        } 
     560 
     561 
    546562 
    547563        if (discarded) 
     
    583599    jbuf_update(jb, JB_OP_GET); 
    584600 
    585 #if USE_PREFETCH_BUFFERING 
    586  
    587601    if (jb_framelist_size(&jb->jb_framelist) == 0) { 
    588602        jb->jb_prefetch_cnt = 0; 
    589     } 
    590  
    591     if ((jb->jb_prefetch_cnt < jb->jb_prefetch)) { 
     603        if (jb->jb_def_prefetch) 
     604            jb->jb_status = JB_STATUS_PREFETCHING; 
     605    } 
     606 
     607    if (jb->jb_status == JB_STATUS_PREFETCHING &&  
     608        jb->jb_prefetch_cnt < jb->jb_prefetch) 
     609    { 
    592610        /* Can't return frame because jitter buffer is filling up 
    593611         * minimum prefetch. 
     
    602620            *size = 0; 
    603621 
     622        TRACE__((jb->name.ptr, "GET prefetch_cnt=%d/%d", 
     623                 jb->jb_prefetch_cnt, jb->jb_prefetch)); 
    604624        return; 
    605625    } 
    606  
    607 #endif 
    608626 
    609627    /* Retrieve a frame from frame list */ 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r2310 r2317  
    16701670        jb_max = 500 / stream->codec_param.info.frm_ptime; 
    16711671 
    1672     if (info->jb_min_pre >= 0) 
     1672    if (info->jb_min_pre > 0) 
    16731673        jb_min_pre = info->jb_min_pre; 
    16741674    else 
     
    16821682        jb_max_pre = jb_max * 4 / 5; 
    16831683 
    1684     if (info->jb_init >= 0) 
     1684    if (info->jb_init > 0) 
    16851685        jb_init = info->jb_init; 
    16861686    else 
    16871687        //jb_init = (jb_min_pre + jb_max_pre) / 2; 
    1688         jb_init = jb_min_pre; 
     1688        jb_init = 0; 
    16891689 
    16901690 
Note: See TracChangeset for help on using the changeset viewer.