Changeset 435 for pjproject/trunk
- Timestamp:
- May 11, 2006 2:22:01 PM (19 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/jbuf.h
r408 r435 46 46 enum pjmedia_jb_frame_type 47 47 { 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. */ 51 54 }; 55 56 57 /** 58 * This structure describes jitter buffer current status. 59 */ 60 struct 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 */ 73 typedef struct pjmedia_jb_state pjmedia_jb_state; 52 74 53 75 … … 60 82 61 83 /** 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. 64 90 * 65 91 * @param pool The pool to allocate memory. … … 67 93 * purpose. 68 94 * @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. 74 103 * @param p_jb Pointer to receive jitter buffer instance. 75 104 * … … 78 107 PJ_DECL(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool, 79 108 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, 83 111 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 */ 122 PJ_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 */ 141 PJ_DECL(pj_status_t) pjmedia_jbuf_set_adaptive( pjmedia_jbuf *jb, 142 unsigned prefetch, 143 unsigned min_prefetch, 144 unsigned max_prefetch); 145 84 146 85 147 /** … … 156 218 char *p_frm_type); 157 219 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 */ 229 PJ_DECL(pj_status_t) pjmedia_jbuf_get_state( pjmedia_jbuf *jb, 230 pjmedia_jb_state *state ); 180 231 181 232 -
pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
r411 r435 65 65 // (at the beginning of the framelist->flist_buffer operation) 66 66 int jb_prefetch_cnt; // prefetch counter 67 int jb_min_prefetch; // Minimum allowable prefetch 68 int jb_max_prefetch; // Maximum allowable prefetch 67 69 int jb_status; // status is 'init' until the first 'put' operation 68 70 … … 138 140 framelist->flist_head * framelist->flist_frame_size, 139 141 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; 141 144 142 145 framelist->flist_origin++; … … 182 185 step1*framelist->flist_frame_size); 183 186 pj_memset(framelist->flist_frame_type+framelist->flist_head, 184 0,187 PJMEDIA_JB_MISSING_FRAME, 185 188 step1*sizeof(framelist->flist_frame_type[0])); 186 189 … … 190 193 step2*framelist->flist_frame_size); 191 194 pj_memset(framelist->flist_frame_type, 192 0,195 PJMEDIA_JB_MISSING_FRAME, 193 196 step2*sizeof(framelist->flist_frame_type[0])); 194 197 } … … 264 267 PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool, 265 268 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, 269 271 pjmedia_jbuf **p_jb) 270 272 { … … 285 287 jb->jb_last_jitter = 0; 286 288 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); 288 290 jb->jb_prefetch_cnt = 0; 291 jb->jb_min_prefetch = 0; 292 jb->jb_max_prefetch = max_count*4/5; 289 293 jb->jb_stable_hist = 0; 290 294 jb->jb_status = JB_STATUS_INITIALIZING; … … 293 297 294 298 *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 */ 308 PJ_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 */ 324 PJ_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 295 340 return PJ_SUCCESS; 296 341 } … … 337 382 338 383 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; 340 386 341 387 jb->jb_stable_hist = 0; … … 358 404 jb->jb_prefetch = PJ_MIN(jb->jb_last_jitter, 359 405 (int)(jb->jb_max_count*4/5)); 406 if (jb->jb_prefetch > jb->jb_max_prefetch) 407 jb->jb_prefetch = jb->jb_max_prefetch; 360 408 jb->jb_stable_hist = 0; 361 409 jb->jb_max_hist_jitter = 0; … … 432 480 } 433 481 482 /* 483 * Get frame from jitter buffer. 484 */ 434 485 PJ_DEF(pj_status_t) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb, 435 486 void *frame, … … 446 497 } 447 498 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 */ 451 503 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 453 509 return PJ_SUCCESS; 454 510 } 455 511 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 */ 456 524 if (ftype == PJMEDIA_JB_NORMAL_FRAME) { 457 525 *p_frame_type = PJMEDIA_JB_NORMAL_FRAME; … … 463 531 } 464 532 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 */ 536 PJ_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 303 303 304 304 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; 307 307 for (i=0; i<local_m->attr_count; ++i) { 308 308 pjmedia_sdp_rtpmap r; … … 314 314 continue; 315 315 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); 317 317 break; 318 318 } 319 319 } 320 320 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; 323 323 for (i=0; i<rem_m->attr_count; ++i) { 324 324 pjmedia_sdp_rtpmap r; … … 330 330 continue; 331 331 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); 333 333 break; 334 334 } -
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r428 r435 175 175 pj_mutex_unlock( stream->jb_mutex ); 176 176 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) { 180 178 frame->type = PJMEDIA_FRAME_TYPE_NONE; 181 179 return PJ_SUCCESS; … … 628 626 629 627 } else { 628 unsigned ext_seq; 629 ext_seq = channel->rtp.seq_ctrl.cycles | pj_ntohs(hdr->seq); 630 630 status = pjmedia_jbuf_put_frame(stream->jb, payload, payloadlen, 631 pj_ntohs(hdr->seq));631 ext_seq); 632 632 } 633 633 pj_mutex_unlock( stream->jb_mutex ); … … 915 915 status = pjmedia_jbuf_create(pool, &stream->port.info.name, 916 916 stream->frame_size, 917 jbuf_init, jbuf_max, 918 &stream->jb); 917 jbuf_max, &stream->jb); 919 918 if (status != PJ_SUCCESS) 920 919 goto err_cleanup; 921 920 921 /* Set jitter buffer to adaptive */ 922 pjmedia_jbuf_set_adaptive( stream->jb, jbuf_init, 1, jbuf_max * 4 / 5); 922 923 923 924 /* Create decoder channel: */
Note: See TracChangeset
for help on using the changeset viewer.