Changeset 6043


Ignore:
Timestamp:
Jul 25, 2019 3:00:33 AM (3 years ago)
Author:
nanang
Message:

Fix #2215:

  • Reset jitter buffer after Opus ptime decreased.
  • Updated jitter buffer framelist sequence restart detection, also added some tracing logs.
Location:
pjproject/trunk/pjmedia/src/pjmedia
Files:
2 edited

Legend:

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

    r5887 r6043  
    4545 */ 
    4646#define INIT_CYCLE              10 
     47 
     48 
     49/* Maximum frame index in JB framelist (estimated). 
     50 * As index is calculated as (RTP-timestamp/timestamp-span), the maximum index 
     51 * usually ranging from MAXUINT32/9000 (10 fps video at 90kHz) to MAXUINT32/80 
     52 * (10 ms audio at 8000Hz), lets take the 'lowest'. 
     53 */ 
     54#define MAX_FRAME_INDEX         (0xFFFFFFFF/9000) 
    4755 
    4856 
     
    471479    PJ_ASSERT_RETURN(frame_size <= framelist->frame_size, PJ_EINVAL); 
    472480 
    473     /* too late or sequence restart */ 
    474     if (index < framelist->origin) { 
     481    /* get distance of this frame to the first frame in the buffer */ 
     482    distance = index - framelist->origin; 
     483 
     484    /* too late or sequence restart or far jump */ 
     485    if (distance < 0) { 
    475486        if (framelist->origin - index < MAX_MISORDER) { 
    476487            /* too late */ 
     488            TRACE__((THIS_FILE,"Put frame #%d: too late (distance=%d)", 
     489                               index, distance)); 
    477490            return PJ_ETOOSMALL; 
     491        } else if (framelist->origin + framelist->size >= MAX_FRAME_INDEX) { 
     492            /* sequence restart */ 
     493            TRACE__((THIS_FILE,"Put frame #%d: sequence restart (distance=%d, " 
     494                               "orig=%d, size=%d)", 
     495                               index, distance, framelist->origin, 
     496                               framelist->size)); 
     497            framelist->origin = index - framelist->size; 
     498            distance = framelist->size; 
    478499        } else { 
    479             /* sequence restart */ 
    480             framelist->origin = index - framelist->size; 
     500            /* jump too far, reset the buffer */ 
     501            TRACE__((THIS_FILE,"Put frame #%d: far jump (distance=%d)", 
     502                               index, distance)); 
     503            jb_framelist_reset(framelist); 
     504            framelist->origin = index; 
     505            distance = 0; 
    481506        } 
    482507    } 
     
    485510    if (framelist->size == 0) { 
    486511        pj_assert(framelist->discarded_num == 0); 
     512        TRACE__((THIS_FILE,"Put frame #%d: origin reset (from %d) as JB empty", 
     513                           index, framelist->origin)); 
    487514        framelist->origin = index; 
    488     } 
    489  
    490     /* get distance of this frame to the first frame in the buffer */ 
    491     distance = index - framelist->origin; 
     515        distance = 0; 
     516    } 
    492517 
    493518    /* far jump, the distance is greater than buffer capacity */ 
     
    495520        if (distance > MAX_DROPOUT) { 
    496521            /* jump too far, reset the buffer */ 
     522            TRACE__((THIS_FILE,"Put frame #%d: far jump (distance=%d)", 
     523                               index, distance)); 
    497524            jb_framelist_reset(framelist); 
    498525            framelist->origin = index; 
     
    500527        } else { 
    501528            /* otherwise, reject the frame */ 
     529            TRACE__((THIS_FILE,"Put frame #%d: rejected due to JB full", 
     530                               index)); 
    502531            return PJ_ETOOMANY; 
    503532        } 
     
    508537 
    509538    /* if the slot is occupied, it must be duplicated frame, ignore it. */ 
    510     if (framelist->frame_type[pos] != PJMEDIA_JB_MISSING_FRAME) 
     539    if (framelist->frame_type[pos] != PJMEDIA_JB_MISSING_FRAME) { 
     540        TRACE__((THIS_FILE,"Put frame #%d maybe a duplicate, ignored", index)); 
    511541        return PJ_EEXISTS; 
     542    } 
    512543 
    513544    /* put the frame into the slot */ 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r6005 r6043  
    19621962            stream->dec_ptime = (pj_uint16_t)dec_ptime; 
    19631963            pjmedia_jbuf_set_ptime(stream->jb, stream->dec_ptime); 
     1964 
     1965            /* Reset jitter buffer after ptime changed */ 
     1966            pjmedia_jbuf_reset(stream->jb); 
    19641967        } 
    19651968 
Note: See TracChangeset for help on using the changeset viewer.