- Timestamp:
- May 14, 2006 6:23:34 PM (19 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/jbuf.h
r438 r442 112 112 * delay that may be introduced by this jitter 113 113 * buffer. 114 * @param ptime Indication of frame duration, used to calculate 115 * the interval between jitter recalculation. 114 116 * @param p_jb Pointer to receive jitter buffer instance. 115 117 * … … 119 121 const pj_str_t *name, 120 122 unsigned frame_size, 123 unsigned ptime, 121 124 unsigned max_count, 122 125 pjmedia_jbuf **p_jb); -
pjproject/trunk/pjmedia/src/pjmedia/conference.c
r426 r442 1096 1096 * transmit NULL frame. 1097 1097 */ 1098 /* note: 1099 * the "cport->sources==0" checking will cause discontinuous 1100 * transmission for RTP stream. 1101 */ 1098 1102 if (cport->tx_setting == PJMEDIA_PORT_MUTE || cport->sources==0) { 1099 1103 … … 1125 1129 buf = (pj_int16_t*)cport->mix_buf; 1126 1130 1127 if (cport->tx_adj_level != NORMAL_LEVEL ) {1131 if (cport->tx_adj_level != NORMAL_LEVEL && cport->sources) { 1128 1132 1129 1133 unsigned adj_level = cport->tx_adj_level; … … 1169 1173 * indication of the signal level of the port. 1170 1174 */ 1171 if (cport->need_tx_level ) {1175 if (cport->need_tx_level && cport->sources) { 1172 1176 pj_uint32_t level; 1173 1177 -
pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
r438 r442 51 51 jb_framelist jb_framelist; 52 52 pj_size_t jb_frame_size; // frame size 53 unsigned jb_frame_ptime; // frame duration. 53 54 pj_size_t jb_max_count; // max frames in the jitter framelist->flist_buffer 54 55 … … 81 82 82 83 84 /* Enabling this would log the jitter buffer state about once per 85 * second. 86 */ 87 #if 0 88 # define TRACE__(args) PJ_LOG(4,args) 89 #else 90 # define TRACE__(args) 91 #endif 92 83 93 84 94 static pj_status_t jb_framelist_init( pj_pool_t *pool, … … 268 278 const pj_str_t *name, 269 279 unsigned frame_size, 280 unsigned ptime, 270 281 unsigned max_count, 271 282 pjmedia_jbuf **p_jb) … … 282 293 pj_strdup_with_null(pool, &jb->name, name); 283 294 jb->jb_frame_size = frame_size; 295 jb->jb_frame_ptime = ptime; 284 296 jb->jb_last_seq_no = -1; 285 297 jb->jb_level = 0; … … 368 380 static void jbuf_calculate_jitter(pjmedia_jbuf *jb) 369 381 { 370 enum { STABLE_HISTORY_LIMIT = (100*2) }; 382 unsigned stable_history_limit; 383 384 stable_history_limit = 1000 / jb->jb_frame_ptime; 371 385 372 386 jb->jb_last_jitter = PJ_ABS(jb->jb_level-jb->jb_last_level); … … 377 391 if (jb->jb_last_jitter < jb->jb_prefetch) { 378 392 jb->jb_stable_hist += jb->jb_last_jitter; 379 if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) {393 if (jb->jb_stable_hist > (int)stable_history_limit) { 380 394 int seq_diff = (jb->jb_prefetch - jb->jb_max_hist_jitter)/3; 381 395 if (seq_diff<1) seq_diff = 1; … … 388 402 jb->jb_max_hist_jitter = 0; 389 403 390 if (jb->jb_op_count >= STABLE_HISTORY_LIMIT*2 && 404 TRACE__((THIS_FILE,"jb updated(1), prefetch=%d, size=%d", 405 jb->jb_prefetch, jb_framelist_size(&jb->jb_framelist))); 406 407 /* These code is used to shorten the delay in the jitter buffer. 408 409 if (jb->jb_op_count >= stable_history_limit*2 && 391 410 (int)jb_framelist_size(&jb->jb_framelist) > jb->jb_prefetch+2) 392 411 { … … 399 418 jb->jb_op_count = 0; 400 419 } 420 */ 401 421 402 422 } … … 409 429 jb->jb_max_hist_jitter = 0; 410 430 411 if (jb->jb_op_count >= STABLE_HISTORY_LIMIT * 2) { 431 TRACE__((THIS_FILE,"jb updated(2), prefetch=%d, size=%d", 432 jb->jb_prefetch, jb_framelist_size(&jb->jb_framelist))); 433 434 /* These code is used to shorten the delay in the jitter buffer 435 when the current size is larger than the prefetch. But it does 436 not really work when the stream supports multiple frames, since 437 the size may grow only temporarily. 438 439 if (jb->jb_op_count >= stable_history_limit * 2) { 412 440 if ((int)jb_framelist_size(&jb->jb_framelist) > jb->jb_prefetch+2) 413 441 { … … 422 450 jb->jb_op_count = 0; 423 451 } 452 */ 424 453 } 425 454 } -
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r440 r442 41 41 #define TRC_(expr) PJ_LOG(5,expr) 42 42 43 #define BYTES_PER_SAMPLE 2 44 43 45 /** 44 46 * Media channel. … … 55 57 void *out_pkt; /**< Output buffer. */ 56 58 pjmedia_rtp_session rtp; /**< RTP session. */ 59 char last_frm_type; /**< Last frame type from jb */ 57 60 }; 58 61 … … 153 156 pjmedia_stream *stream = port->user_data; 154 157 pjmedia_channel *channel = stream->dec; 155 156 pj_status_t status;157 158 unsigned samples_count, samples_per_frame, samples_required; 158 159 pj_int16_t *p_out_samp; 160 pj_status_t status; 161 159 162 160 163 /* Return no frame is channel is paused */ … … 181 184 samples_count += samples_per_frame) 182 185 { 183 186 char frame_type; 184 187 185 188 /* Get frame from jitter buffer. */ … … 199 202 frame_out.size, 200 203 &frame_out); 204 201 205 } else { 202 206 status = -1; … … 207 211 pjmedia_zero_samples(p_out_samp + samples_count, 208 212 samples_required - samples_count); 213 PJ_LOG(5,(stream->port.info.name.ptr, "Frame lost!")); 214 215 } else { 216 PJ_LOG(5,(stream->port.info.name.ptr, 217 "Lost frame recovered")); 209 218 } 210 219 211 220 } else if (frame_type == PJMEDIA_JB_ZERO_EMPTY_FRAME) { 212 221 213 /* Jitter buffer is empty, zero the remaining samples and break 214 * the loop. 222 /* Jitter buffer is empty. If this is the first "empty" state, 223 * activate PLC to smoothen the fade-out, otherwise zero 224 * the frame. 215 225 */ 216 pjmedia_zero_samples(p_out_samp + samples_count, 217 samples_required - samples_count); 226 if (frame_type != channel->last_frm_type) { 227 pjmedia_jb_state jb_state; 228 229 /* Activate PLC to smoothen the missing frame */ 230 if (stream->codec->op->recover && 231 stream->codec_param.setting.plc) 232 { 233 pjmedia_frame frame_out; 234 235 do { 236 frame_out.buf = p_out_samp + samples_count; 237 frame_out.size = frame->size - samples_count*2; 238 status = (*stream->codec->op->recover)(stream->codec, 239 frame_out.size, 240 &frame_out); 241 if (status != PJ_SUCCESS) 242 break; 243 samples_count += samples_per_frame; 244 245 } while (samples_count < samples_required); 246 247 } 248 249 /* Report the state of jitter buffer */ 250 pjmedia_jbuf_get_state(stream->jb, &jb_state); 251 PJ_LOG(5,(stream->port.info.name.ptr, 252 "Jitter buffer empty (prefetch=%d)", 253 jb_state.prefetch)); 254 255 } 256 257 if (samples_count < samples_required) { 258 pjmedia_zero_samples(p_out_samp + samples_count, 259 samples_required - samples_count); 260 } 261 262 channel->last_frm_type = frame_type; 218 263 break; 219 264 220 265 } else if (frame_type != PJMEDIA_JB_NORMAL_FRAME) { 266 267 pjmedia_jb_state jb_state; 221 268 222 269 /* It can only be PJMEDIA_JB_ZERO_PREFETCH frame */ 223 270 pj_assert(frame_type == PJMEDIA_JB_ZERO_PREFETCH_FRAME); 224 271 225 /* Zero frame returned. We should zero the PCM buffer then.. */ 226 pjmedia_zero_samples(p_out_samp + samples_count, 227 samples_per_frame); 272 /* Get the state of jitter buffer */ 273 pjmedia_jbuf_get_state(stream->jb, &jb_state); 274 275 /* Always activate PLC when it's available.. */ 276 if (stream->codec->op->recover && 277 stream->codec_param.setting.plc) 278 { 279 pjmedia_frame frame_out; 280 281 do { 282 frame_out.buf = p_out_samp + samples_count; 283 frame_out.size = frame->size - samples_count*2; 284 status = (*stream->codec->op->recover)(stream->codec, 285 frame_out.size, 286 &frame_out); 287 if (status != PJ_SUCCESS) 288 break; 289 samples_count += samples_per_frame; 290 291 } while (samples_count < samples_required); 292 293 PJ_LOG(5,(stream->port.info.name.ptr, 294 "Jitter buffer is bufferring with plc (prefetch=%d)", 295 jb_state.prefetch)); 296 297 } 298 299 if (samples_count < samples_required) { 300 pjmedia_zero_samples(p_out_samp + samples_count, 301 samples_required - samples_count); 302 PJ_LOG(5,(stream->port.info.name.ptr, 303 "Jitter buffer is bufferring (prefetch=%d)..", 304 jb_state.prefetch)); 305 } 306 307 channel->last_frm_type = frame_type; 308 break; 228 309 229 310 } else { … … 237 318 238 319 frame_out.buf = p_out_samp + samples_count; 239 frame_out.size = frame->size - samples_count* 2;320 frame_out.size = frame->size - samples_count*BYTES_PER_SAMPLE; 240 321 status = stream->codec->op->decode( stream->codec, &frame_in, 241 322 frame_out.size, &frame_out); … … 248 329 } 249 330 } 331 332 channel->last_frm_type = frame_type; 250 333 } 251 334 … … 262 345 } else { 263 346 frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 264 frame->size = samples_count * 2;347 frame->size = samples_count * BYTES_PER_SAMPLE; 265 348 frame->timestamp.u64 = 0; 266 349 } … … 498 581 499 582 pj_memcpy(channel->out_pkt, rtphdr, sizeof(pjmedia_rtp_hdr)); 583 500 584 501 585 /* Send. */ … … 1030 1114 jb_max = info->jb_max; 1031 1115 else 1032 jb_max = 240 / (stream->port.info.samples_per_frame * 1000 / 1033 info->fmt.clock_rate); 1116 jb_max = 360 / stream->codec_param.info.frm_ptime; 1034 1117 1035 1118 if (info->jb_min_pre >= 0) 1036 1119 jb_min_pre = info->jb_min_pre; 1037 1120 else 1038 jb_min_pre = 0;1121 jb_min_pre = 60 / stream->codec_param.info.frm_ptime; 1039 1122 1040 1123 if (info->jb_max_pre > 0) 1041 1124 jb_max_pre = info->jb_max_pre; 1042 1125 else 1043 jb_max_pre = jb_max * 4 / 5;1126 jb_max_pre = 240 / stream->codec_param.info.frm_ptime; 1044 1127 1045 1128 if (info->jb_init >= 0) 1046 1129 jb_init = info->jb_init; 1047 1130 else 1048 jb_init = jb_min_pre;1131 jb_init = (jb_min_pre + jb_max_pre) / 2; 1049 1132 1050 1133 … … 1052 1135 status = pjmedia_jbuf_create(pool, &stream->port.info.name, 1053 1136 stream->frame_size, 1137 stream->codec_param.info.frm_ptime, 1054 1138 jb_max, &stream->jb); 1055 1139 if (status != PJ_SUCCESS) -
pjproject/trunk/pjsip-apps/src/samples/siprtp_report.c
r437 r442 60 60 61 61 /* Print duration */ 62 if (inv->state >= PJSIP_INV_STATE_CONFIRMED ) {62 if (inv->state >= PJSIP_INV_STATE_CONFIRMED && call->connect_time) { 63 63 64 64 PJ_TIME_VAL_SUB(now, call->connect_time);
Note: See TracChangeset
for help on using the changeset viewer.