Ticket #464: jbuf.patch

File jbuf.patch, 4.1 KB (added by nanang, 16 years ago)
  • pjmedia/include/pjmedia/jbuf.h

     
    235235                                      void *frame,  
    236236                                      char *p_frm_type); 
    237237 
     238/** 
     239 * Get a frame from the jitter buffer. The jitter buffer will return the 
     240 * oldest frame from it's buffer, when it is available. 
     241 * 
     242 * @param jb            The jitter buffer. 
     243 * @param frame         Buffer to receive the payload from the jitter buffer. 
     244 *                      @see pjmedia_jbuf_get_frame().     
     245 * @param size          Pointer to receive frame size. 
     246 * @param p_frm_type    Pointer to receive frame type. 
     247 *                      @see pjmedia_jbuf_get_frame().     
     248 */ 
     249PJ_DECL(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,  
     250                                      void *frame,  
     251                                      pj_size_t *size,  
     252                                      char *p_frm_type); 
    238253 
     254 
    239255/** 
    240256 * Get jitter buffer current state/settings. 
    241257 * 
  • pjmedia/src/pjmedia/jbuf.c

     
    3434{ 
    3535    char        *flist_buffer; 
    3636    int         *flist_frame_type; 
     37    pj_size_t   *flist_content_len; 
    3738    unsigned     flist_frame_size; 
    3839    unsigned     flist_max_count; 
    3940    unsigned     flist_empty; 
     
    109110        pj_pool_zalloc(pool, sizeof(framelist->flist_frame_type[0]) *  
    110111                                framelist->flist_max_count); 
    111112 
     113    framelist->flist_content_len = (pj_size_t*) 
     114        pj_pool_zalloc(pool, sizeof(framelist->flist_content_len[0]) *  
     115                                framelist->flist_max_count); 
     116 
    112117    framelist->flist_empty = 1; 
    113118 
    114119    return PJ_SUCCESS; 
     
    134139 
    135140 
    136141static pj_bool_t jb_framelist_get(jb_framelist_t *framelist, 
    137                                   void *frame, 
     142                                  void *frame, pj_size_t *size, 
    138143                                  pjmedia_jb_frame_type *p_type)  
    139144{ 
    140145    if (!framelist->flist_empty) { 
     
    144149                  framelist->flist_frame_size); 
    145150        *p_type = (pjmedia_jb_frame_type)  
    146151                  framelist->flist_frame_type[framelist->flist_head]; 
     152        *size   = framelist->flist_content_len[framelist->flist_head]; 
    147153 
    148154        pj_bzero(framelist->flist_buffer +  
    149155                    framelist->flist_head * framelist->flist_frame_size, 
    150156                  framelist->flist_frame_size); 
    151157        framelist->flist_frame_type[framelist->flist_head] =  
    152158            PJMEDIA_JB_MISSING_FRAME; 
     159        framelist->flist_content_len[framelist->flist_head] = 0; 
    153160 
    154161        framelist->flist_origin++; 
    155162        framelist->flist_head = (framelist->flist_head + 1 ) %  
     
    194201        pj_memset(framelist->flist_frame_type+framelist->flist_head, 
    195202                  PJMEDIA_JB_MISSING_FRAME, 
    196203                  step1*sizeof(framelist->flist_frame_type[0])); 
     204        pj_bzero(framelist->flist_content_len+framelist->flist_head, 
     205                  step1*sizeof(framelist->flist_content_len[0])); 
    197206 
    198207        if (step2) { 
    199208            pj_bzero( framelist->flist_buffer, 
     
    201210            pj_memset(framelist->flist_frame_type, 
    202211                      PJMEDIA_JB_MISSING_FRAME, 
    203212                      step2*sizeof(framelist->flist_frame_type[0])); 
     213            pj_bzero (framelist->flist_content_len, 
     214                      step2*sizeof(framelist->flist_content_len[0])); 
    204215        } 
    205216 
    206217        // update pointers 
     
    257268              frame, frame_size); 
    258269 
    259270    framelist->flist_frame_type[where] = PJMEDIA_JB_NORMAL_FRAME; 
     271    framelist->flist_content_len[where] = frame_size; 
    260272 
    261273    return PJ_TRUE; 
    262274} 
     
    510522                                     void *frame,  
    511523                                     char *p_frame_type) 
    512524{ 
     525    pj_size_t size; 
     526 
     527    pjmedia_jbuf_get_frame2(jb, frame, &size, p_frame_type); 
     528} 
     529 
     530/* 
     531 * Get frame from jitter buffer. 
     532 */ 
     533PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,  
     534                                     void *frame,  
     535                                     pj_size_t *size, 
     536                                     char *p_frame_type) 
     537{ 
    513538    pjmedia_jb_frame_type ftype; 
    514539 
    515540    jb->jb_level--; 
     
    530555        else 
    531556            *p_frame_type = PJMEDIA_JB_ZERO_PREFETCH_FRAME; 
    532557 
     558        *size = 0; 
     559 
    533560        return; 
    534561    } 
    535562 
    536563    /* Retrieve a frame from frame list */ 
    537     if (jb_framelist_get(&jb->jb_framelist,frame,&ftype) == PJ_FALSE) { 
     564    if (jb_framelist_get(&jb->jb_framelist,frame,size,&ftype) == PJ_FALSE) { 
    538565        /* Can't return frame because jitter buffer is empty! */ 
    539566        pj_bzero(frame, jb->jb_frame_size); 
    540567        *p_frame_type = PJMEDIA_JB_ZERO_EMPTY_FRAME; 
     568        *size = 0; 
    541569 
    542570        return; 
    543571    }