Changeset 435


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

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

Location:
pjproject/trunk/pjmedia
Files:
4 edited

Legend:

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

    r408 r435  
    4646enum pjmedia_jb_frame_type  
    4747{ 
    48     PJMEDIA_JB_MISSING_FRAME   = 0, /**< No frame because it's missing.     */ 
    49     PJMEDIA_JB_NORMAL_FRAME    = 1, /**< Normal frame is being returned.    */ 
    50     PJMEDIA_JB_ZERO_FRAME      = 2, /**< Zero frame is being returned.      */ 
     48    PJMEDIA_JB_MISSING_FRAME       = 0, /**< No frame because it's missing  */ 
     49    PJMEDIA_JB_NORMAL_FRAME        = 1, /**< Normal frame is being returned */ 
     50    PJMEDIA_JB_ZERO_PREFETCH_FRAME = 2, /**< Zero frame is being returned   
     51                                             because JB is bufferring.      */ 
     52    PJMEDIA_JB_ZERO_EMPTY_FRAME    = 3  /**< Zero frame is being returned 
     53                                             because JB is empty.           */ 
    5154}; 
     55 
     56 
     57/** 
     58 * This structure describes jitter buffer current status. 
     59 */ 
     60struct pjmedia_jb_state 
     61{ 
     62    unsigned    frame_size;         /**< Individual frame size, in bytes.   */ 
     63    unsigned    prefetch;           /**< Current prefetch value, in frames  */ 
     64    unsigned    min_prefetch;       /**< Minimum allowed prefetch, in frms. */ 
     65    unsigned    max_prefetch;       /**< Maximum allowed prefetch, in frms. */ 
     66    unsigned    size;               /**< Current buffer size, in frames.    */ 
     67}; 
     68 
     69 
     70/** 
     71 * @see pjmedia_jb_state 
     72 */ 
     73typedef struct pjmedia_jb_state pjmedia_jb_state; 
    5274 
    5375 
     
    6082 
    6183/** 
    62  * Create the jitter buffer. This function may allocate large chunk of 
    63  * memory to keep the frames in the buffer. 
     84 * Create an adaptive jitter buffer according to the specification. If 
     85 * application wants to have a fixed jitter buffer, it may call 
     86 * #pjmedia_jbuf_set_fixed() after the jitter buffer is created. 
     87 * 
     88 * This function may allocate large chunk of memory to keep the frames in  
     89 * the buffer. 
    6490 * 
    6591 * @param pool          The pool to allocate memory. 
     
    6793 *                      purpose. 
    6894 * @param frame_size    The size of each frame that will be kept in the 
    69  *                      jitter buffer. The value here normaly corresponds 
    70  *                      to the RTP payload size according to the codec 
    71  *                      being used. 
    72  * @param init_delay    Initial jitter buffer delay, in number of frames. 
    73  * @param max_count     Maximum jitter buffer delay, in number of frames. 
     95 *                      jitter buffer, in bytes. This should correspond 
     96 *                      to the minimum frame size supported by the codec. 
     97 *                      For example, a 10ms frame (80 bytes) would be  
     98 *                      recommended for G.711 codec. 
     99 * @param max_count     Maximum number of frames that can be kept in the 
     100 *                      jitter buffer. This effectively means the maximum 
     101 *                      delay that may be introduced by this jitter  
     102 *                      buffer. 
    74103 * @param p_jb          Pointer to receive jitter buffer instance. 
    75104 * 
     
    78107PJ_DECL(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool, 
    79108                                         const pj_str_t *name, 
    80                                          int frame_size,  
    81                                          int init_delay,  
    82                                          int max_count, 
     109                                         unsigned frame_size, 
     110                                         unsigned max_count, 
    83111                                         pjmedia_jbuf **p_jb); 
     112 
     113/** 
     114 * Set the jitter buffer to fixed delay mode. The default behavior 
     115 * is to adapt the delay with actual packet delay. 
     116 * 
     117 * @param jb            The jitter buffer 
     118 * @param prefetch      The fixed delay value, in number of frames. 
     119 * 
     120 * @return              PJ_SUCCESS on success. 
     121 */ 
     122PJ_DECL(pj_status_t) pjmedia_jbuf_set_fixed( pjmedia_jbuf *jb, 
     123                                             unsigned prefetch); 
     124 
     125 
     126/** 
     127 * Set the jitter buffer to adaptive mode. 
     128 * 
     129 * @param jb            The jitter buffer. 
     130 * @param prefetch      The prefetch value to be applied to the jitter 
     131 *                      buffer. 
     132 * @param min_prefetch  The minimum delay that must be applied to each 
     133 *                      incoming packets, in number of frames. The 
     134 *                      default value is zero. 
     135 * @param max_prefetch  The maximum allowable value for prefetch delay, 
     136 *                      in number of frames. The default value is equal 
     137 *                      to the size of the jitter buffer. 
     138 * 
     139 * @return              PJ_SUCCESS on success. 
     140 */ 
     141PJ_DECL(pj_status_t) pjmedia_jbuf_set_adaptive( pjmedia_jbuf *jb, 
     142                                                unsigned prefetch, 
     143                                                unsigned min_prefetch, 
     144                                                unsigned max_prefetch); 
     145 
    84146 
    85147/** 
     
    156218                                             char *p_frm_type); 
    157219 
    158 /** 
    159  * Retrieve the current value of jitter buffer minimum delay, in number 
    160  * of frames. 
    161  * 
    162  * @param jb            The jitter buffer. 
    163  * 
    164  * @return              Number of frames, indicating the minimum delay that  
    165  *                      will be applied by the jitter buffer between frame 
    166  *                      arrival and frame retrieval. 
    167  */ 
    168 PJ_DECL(unsigned)    pjmedia_jbuf_get_min_delay_size(pjmedia_jbuf *jb); 
    169  
    170  
    171 /** 
    172  * Retrieve the current delay value, in number of frames. 
    173  * 
    174  * @param jb            The jitter buffer. 
    175  * 
    176  * @return              Number of frames, indicating the delay between frame 
    177  *                      arrival and frame retrieval. 
    178  */ 
    179 PJ_DECL(unsigned)    pjmedia_jbuf_get_delay(pjmedia_jbuf *jb); 
     220 
     221/** 
     222 * Get jitter buffer state. 
     223 * 
     224 * @param jb            The jitter buffer. 
     225 * @param state         Buffer to receive jitter buffer state. 
     226 * 
     227 * @return              PJ_SUCCESS on success. 
     228 */ 
     229PJ_DECL(pj_status_t) pjmedia_jbuf_get_state( pjmedia_jbuf *jb, 
     230                                             pjmedia_jb_state *state ); 
    180231 
    181232 
  • 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 
  • pjproject/trunk/pjmedia/src/pjmedia/session.c

    r428 r435  
    303303   
    304304 
    305     /* Get local DTMF payload type */ 
    306     si->tx_event_pt = -1; 
     305    /* Get incomming payload type for telephone-events */ 
     306    si->rx_event_pt = -1; 
    307307    for (i=0; i<local_m->attr_count; ++i) { 
    308308        pjmedia_sdp_rtpmap r; 
     
    314314            continue; 
    315315        if (pj_strcmp(&r.enc_name, &ID_TELEPHONE_EVENT) == 0) { 
    316             si->tx_event_pt = pj_strtoul(&r.pt); 
     316            si->rx_event_pt = pj_strtoul(&r.pt); 
    317317            break; 
    318318        } 
    319319    } 
    320320 
    321     /* Get remote DTMF payload type */ 
    322     si->rx_event_pt = -1; 
     321    /* Get outgoing payload type for telephone-events */ 
     322    si->tx_event_pt = -1; 
    323323    for (i=0; i<rem_m->attr_count; ++i) { 
    324324        pjmedia_sdp_rtpmap r; 
     
    330330            continue; 
    331331        if (pj_strcmp(&r.enc_name, &ID_TELEPHONE_EVENT) == 0) { 
    332             si->rx_event_pt = pj_strtoul(&r.pt); 
     332            si->tx_event_pt = pj_strtoul(&r.pt); 
    333333            break; 
    334334        } 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r428 r435  
    175175    pj_mutex_unlock( stream->jb_mutex ); 
    176176 
    177     if (status != PJ_SUCCESS || frame_type == PJMEDIA_JB_ZERO_FRAME || 
    178         frame_type == PJMEDIA_JB_MISSING_FRAME)  
    179     { 
     177    if (status != PJ_SUCCESS || frame_type != PJMEDIA_JB_NORMAL_FRAME) { 
    180178        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
    181179        return PJ_SUCCESS; 
     
    628626 
    629627        } else { 
     628            unsigned ext_seq; 
     629            ext_seq = channel->rtp.seq_ctrl.cycles | pj_ntohs(hdr->seq); 
    630630            status = pjmedia_jbuf_put_frame(stream->jb, payload, payloadlen, 
    631                                             pj_ntohs(hdr->seq)); 
     631                                            ext_seq); 
    632632        } 
    633633        pj_mutex_unlock( stream->jb_mutex ); 
     
    915915    status = pjmedia_jbuf_create(pool, &stream->port.info.name, 
    916916                                 stream->frame_size,  
    917                                  jbuf_init, jbuf_max, 
    918                                  &stream->jb); 
     917                                 jbuf_max, &stream->jb); 
    919918    if (status != PJ_SUCCESS) 
    920919        goto err_cleanup; 
    921920 
     921    /* Set jitter buffer to adaptive */ 
     922    pjmedia_jbuf_set_adaptive( stream->jb, jbuf_init, 1, jbuf_max * 4 / 5); 
    922923 
    923924    /* Create decoder channel: */ 
Note: See TracChangeset for help on using the changeset viewer.