Changeset 457
- Timestamp:
- May 19, 2006 3:58:13 PM (19 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/silencedet.h
r355 r457 37 37 38 38 /** 39 * Suggested or default threshold to be set for fixed silence detection 40 * or as starting threshold for adaptive silence detection. The threshold 41 * has the range from zero to 255. 42 */ 43 #define PJMEDIA_SILENCE_DET_THRESHOLD 4 44 45 46 /** 39 47 * Create voice activity detector with default settings. The default settings 40 * are to perform adaptive silence detection, which adjusts the noise level 41 * dynamically based on current input level. 48 * are set to adaptive silence detection with the default threshold. 42 49 * 43 * @param pool Pool for allocating the structure. 44 * @param p_sd Pointer to receive the silence detector instance. 50 * @param pool Pool for allocating the structure. 51 * @param clock_rate Clock rate. 52 * @param samples_per_frame Number of samples per frame. The clock_rate and 53 * samples_per_frame is only used to calculate the 54 * frame time, from which some timing parameters 55 * are calculated from. 56 * @param p_sd Pointer to receive the silence detector instance. 45 57 * 46 * @return PJ_SUCCESS on success.58 * @return PJ_SUCCESS on success. 47 59 */ 48 60 PJ_DECL(pj_status_t) pjmedia_silence_det_create( pj_pool_t *pool, 61 unsigned clock_rate, 62 unsigned samples_per_frame, 49 63 pjmedia_silence_det **p_sd ); 50 64 51 65 52 66 /** 53 * Set the sd to operate in adaptive mode. 54 * 55 * @param sd The silence detector 56 * @param frame_size Number of samples per frame. 57 * 58 * @return PJ_SUCCESS on success. 59 */ 60 PJ_DECL(pj_status_t) pjmedia_silence_det_set_adaptive( pjmedia_silence_det *sd, 61 unsigned frame_size); 62 63 64 /** 65 * Set the sd to operate in fixed threshold mode. 67 * Set the sd to operate in fixed threshold mode. With fixed threshold mode, 68 * the threshold will not be changed adaptively. 66 69 * 67 70 * @param sd The silence detector 68 * @param frame_size Number of samplse per frame.69 * @param threshold The silencethreshold.71 * @param threshold The silence threshold, or -1 to use default 72 * threshold. 70 73 * 71 74 * @return PJ_SUCCESS on success. 72 75 */ 73 76 PJ_DECL(pj_status_t) pjmedia_silence_det_set_fixed( pjmedia_silence_det *sd, 74 unsigned frame_size, 75 unsigned threshold ); 77 int threshold ); 78 79 /** 80 * Set the sd to operate in adaptive mode. This is the default mode 81 * when the silence detector is created. 82 * 83 * @param sd The silence detector 84 * @param threshold Initial threshold to be set, or -1 to use default 85 * threshold. 86 * 87 * @return PJ_SUCCESS on success. 88 */ 89 PJ_DECL(pj_status_t) pjmedia_silence_det_set_adaptive(pjmedia_silence_det *sd, 90 int threshold); 91 92 /** 93 * Set other silence detector parameters. 94 * 95 * @param sd The silence detector 96 * @param min_silence Minimum duration of silence (in msec) before 97 * silence is reported. If -1 is specified, then 98 * the default value will be used. The default is 99 * 400 msec. 100 * @param min_signal Minimum duration of signal (in msec) before 101 * signal is reported. If -1 is specified, then 102 * the default value will be used. The default is 103 * one frame. 104 * @param recalc_time The interval to recalculate signal and silence 105 * proportion and to readjust the silence threshold 106 * when adaptive silence detection is set. If -1 107 * is specified, then the default value will be used. 108 * The default value is 5000 (msec). 109 * 110 * @return PJ_SUCCESS on success. 111 */ 112 PJ_DECL(pj_status_t) pjmedia_silence_det_set_params( pjmedia_silence_det *sd, 113 int min_silence, 114 int min_signal, 115 int recalc_time); 76 116 77 117 /** -
pjproject/trunk/pjmedia/src/pjmedia-codec/gsm.c
r438 r457 21 21 #include <pjmedia/errno.h> 22 22 #include <pjmedia/endpoint.h> 23 #include <pjmedia/plc.h> 23 24 #include <pjmedia/port.h> 25 #include <pjmedia/silencedet.h> 24 26 #include <pj/assert.h> 25 27 #include <pj/pool.h> … … 69 71 unsigned output_buf_len, 70 72 struct pjmedia_frame *output); 73 static pj_status_t gsm_codec_recover(pjmedia_codec *codec, 74 unsigned output_buf_len, 75 struct pjmedia_frame *output); 71 76 72 77 /* Definition for GSM codec operations. */ … … 78 83 &gsm_codec_parse, 79 84 &gsm_codec_encode, 80 &gsm_codec_decode 85 &gsm_codec_decode, 86 &gsm_codec_recover 81 87 }; 82 88 … … 101 107 } gsm_codec_factory; 102 108 109 103 110 /* GSM codec private data. */ 104 111 struct gsm_data 105 112 { 106 void *encoder; 107 void *decoder; 113 void *encoder; 114 void *decoder; 115 pj_bool_t plc_enabled; 116 pjmedia_plc *plc; 117 pj_bool_t vad_enabled; 118 pjmedia_silence_det *vad; 108 119 }; 109 120 … … 240 251 241 252 attr->setting.frm_per_pkt = 1; 242 243 /* Default all flag bits disabled. */ 253 attr->setting.vad = 1; 254 attr->setting.plc = 1; 255 256 /* Default all other flag bits disabled. */ 244 257 245 258 return PJ_SUCCESS; … … 277 290 pjmedia_codec *codec; 278 291 struct gsm_data *gsm_data; 292 pj_status_t status; 279 293 280 294 PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL); … … 298 312 sizeof(struct gsm_data)); 299 313 codec->codec_data = gsm_data; 314 315 /* Create PLC */ 316 status = pjmedia_plc_create(gsm_codec_factory.pool, 8000, 317 160, 0, &gsm_data->plc); 318 if (status != PJ_SUCCESS) { 319 pj_mutex_unlock(gsm_codec_factory.mutex); 320 return status; 321 } 322 323 /* Create silence detector */ 324 status = pjmedia_silence_det_create(gsm_codec_factory.pool, 325 8000, 160, 326 &gsm_data->vad); 327 if (status != PJ_SUCCESS) { 328 pj_mutex_unlock(gsm_codec_factory.mutex); 329 return status; 330 } 300 331 } 301 332 … … 361 392 if (!gsm_data->decoder) 362 393 return PJMEDIA_CODEC_EFAILED; 394 395 gsm_data->vad_enabled = (attr->setting.vad != 0); 396 gsm_data->plc_enabled = (attr->setting.plc != 0); 363 397 364 398 return PJ_SUCCESS; … … 438 472 return PJMEDIA_CODEC_EPCMTOOSHORT; 439 473 474 /* Detect silence */ 475 if (gsm_data->vad_enabled) { 476 pj_bool_t is_silence; 477 478 is_silence = pjmedia_silence_det_detect(gsm_data->vad, 479 input->buf, 480 input->size / 2, 481 NULL); 482 if (is_silence) { 483 output->type = PJMEDIA_FRAME_TYPE_NONE; 484 output->buf = NULL; 485 output->size = 0; 486 output->timestamp.u64 = input->timestamp.u64; 487 return PJ_SUCCESS; 488 } 489 } 490 491 /* Encode */ 440 492 gsm_encode(gsm_data->encoder, (short*)input->buf, 441 493 (unsigned char*)output->buf); … … 473 525 output->type = PJMEDIA_FRAME_TYPE_AUDIO; 474 526 527 if (gsm_data->plc_enabled) 528 pjmedia_plc_save( gsm_data->plc, output->buf); 529 530 return PJ_SUCCESS; 531 } 532 533 534 /* 535 * Recover lost frame. 536 */ 537 static pj_status_t gsm_codec_recover(pjmedia_codec *codec, 538 unsigned output_buf_len, 539 struct pjmedia_frame *output) 540 { 541 struct gsm_data *gsm_data = codec->codec_data; 542 543 PJ_ASSERT_RETURN(gsm_data->plc_enabled, PJ_EINVALIDOP); 544 545 PJ_ASSERT_RETURN(output_buf_len >= 320, PJMEDIA_CODEC_EPCMTOOSHORT); 546 547 pjmedia_plc_generate(gsm_data->plc, output->buf); 548 output->size = 320; 549 475 550 return PJ_SUCCESS; 476 551 } -
pjproject/trunk/pjmedia/src/pjmedia-codec/speex_codec.c
r438 r457 38 38 #define THIS_FILE "speex_codec.c" 39 39 40 #define DEFAULT_QUALITY 441 #define DEFAULT_COMPLEXITY -140 #define DEFAULT_QUALITY 10 41 #define DEFAULT_COMPLEXITY 10 42 42 43 43 /* Prototypes for Speex factory */ … … 256 256 257 257 /* Somehow quality <=4 is broken in linux. */ 258 if (quality <= 4 ) {259 PJ_LOG( 4,(THIS_FILE, "Adjusting quality to 5 for uwb"));258 if (quality <= 4 && quality >= 0) { 259 PJ_LOG(5,(THIS_FILE, "Adjusting quality to 5 for uwb")); 260 260 spx_factory.speex_param[PARAM_UWB].quality = 5; 261 261 } … … 412 412 attr->setting.lpf =1 ; 413 413 attr->setting.penh =1 ; 414 415 /* Default, set VAD off as it caused voice chip off */ 416 attr->setting.vad = 0; 414 attr->setting.vad = 1; 417 415 418 416 return PJ_SUCCESS; … … 572 570 573 571 /* VAD */ 574 tmp = attr->setting.vad;572 tmp = (attr->setting.vad != 0); 575 573 speex_encoder_ctl(spx->enc, SPEEX_SET_VAD, &tmp); 574 speex_encoder_ctl(spx->enc, SPEEX_SET_DTX, &tmp); 576 575 577 576 /* Complexity */ … … 688 687 pj_int16_t *samp_in; 689 688 unsigned i, samp_count, sz; 689 int tx; 690 690 691 691 spx = (struct spx_private*) codec->codec_data; … … 711 711 712 712 /* Encode the frame */ 713 speex_encode(spx->enc, tmp, &spx->enc_bits); 713 tx = speex_encode(spx->enc, tmp, &spx->enc_bits); 714 715 /* Check if we need not to transmit the frame (DTX) */ 716 if (tx == 0) { 717 output->buf = NULL; 718 output->size = 0; 719 output->timestamp.u64 = input->timestamp.u64; 720 output->type = PJMEDIA_FRAME_TYPE_NONE; 721 return PJ_SUCCESS; 722 } 714 723 715 724 /* Check size. */ -
pjproject/trunk/pjmedia/src/pjmedia/conference.c
r442 r457 229 229 230 230 /* Create and init vad. */ 231 status = pjmedia_silence_det_create( pool, &conf_port->vad); 231 status = pjmedia_silence_det_create( pool, 232 port->info.clock_rate, 233 port->info.samples_per_frame, 234 &conf_port->vad); 232 235 if (status != PJ_SUCCESS) 233 236 return status; 234 237 235 pjmedia_silence_det_set_ adaptive(conf_port->vad, conf->samples_per_frame);238 pjmedia_silence_det_set_fixed(conf_port->vad, 2); 236 239 237 240 /* Save some port's infos, for convenience. */ -
pjproject/trunk/pjmedia/src/pjmedia/g711.c
r438 r457 25 25 #include <pjmedia/port.h> 26 26 #include <pjmedia/plc.h> 27 #include <pjmedia/silencedet.h> 27 28 #include <pj/pool.h> 28 29 #include <pj/string.h> … … 122 123 struct g711_private 123 124 { 124 unsigned pt; 125 pj_bool_t plc_enabled; 126 pjmedia_plc *plc; 125 unsigned pt; 126 pj_bool_t plc_enabled; 127 pjmedia_plc *plc; 128 pj_bool_t vad_enabled; 129 pjmedia_silence_det *vad; 127 130 }; 128 131 … … 251 254 attr->setting.plc = 1; 252 255 253 /* Default all flag bits disabled. */ 256 /* Enable VAD by default. */ 257 attr->setting.vad = 1; 258 259 /* Default all other flag bits disabled. */ 254 260 255 261 return PJ_SUCCESS; … … 303 309 304 310 codec = pj_pool_alloc(g711_factory.pool, sizeof(pjmedia_codec)); 305 codec_priv = pj_pool_ alloc(g711_factory.pool,306 sizeof(struct g711_private));311 codec_priv = pj_pool_zalloc(g711_factory.pool, 312 sizeof(struct g711_private)); 307 313 if (!codec || !codec_priv) { 308 314 pj_mutex_unlock(g711_factory.mutex); … … 321 327 } 322 328 329 /* Create VAD */ 330 status = pjmedia_silence_det_create(g711_factory.pool, 331 8000, 80, 332 &codec_priv->vad); 333 if (status != PJ_SUCCESS) { 334 pj_mutex_unlock(g711_factory.mutex); 335 return status; 336 } 337 323 338 codec->factory = factory; 324 339 codec->op = &g711_op; … … 379 394 priv->pt = attr->info.pt; 380 395 priv->plc_enabled = (attr->setting.plc != 0); 396 priv->vad_enabled = (attr->setting.vad != 0); 381 397 return PJ_SUCCESS; 382 398 } … … 429 445 if (output_buf_len < input->size / 2) 430 446 return PJMEDIA_CODEC_EFRMTOOSHORT; 447 448 /* Detect silence if VAD is enabled */ 449 if (priv->vad_enabled) { 450 pj_bool_t is_silence; 451 452 is_silence = pjmedia_silence_det_detect(priv->vad, input->buf, 453 input->size / 2, NULL); 454 if (is_silence) { 455 output->type = PJMEDIA_FRAME_TYPE_NONE; 456 output->buf = NULL; 457 output->size = 0; 458 output->timestamp.u64 = input->timestamp.u64; 459 return PJ_SUCCESS; 460 } 461 } 431 462 432 463 /* Encode */ -
pjproject/trunk/pjmedia/src/pjmedia/silencedet.c
r229 r457 33 33 34 34 35 35 36 /** 36 37 * This structure holds the silence detector state. … … 39 40 { 40 41 int mode; /**< VAD mode. */ 41 unsigned frame_size; /**< Samples per frame. */ 42 42 unsigned ptime; /**< Frame time, in msec. */ 43 43 44 44 unsigned min_signal_cnt; /**< # of signal frames.before talk burst */ … … 61 61 62 62 PJ_DEF(pj_status_t) pjmedia_silence_det_create( pj_pool_t *pool, 63 unsigned clock_rate, 64 unsigned samples_per_frame, 63 65 pjmedia_silence_det **p_sd) 64 66 { … … 69 71 sd = pj_pool_zalloc(pool, sizeof(struct pjmedia_silence_det)); 70 72 73 sd->ptime = samples_per_frame * 1000 / clock_rate; 74 sd->signal_cnt = 0; 75 sd->silence_cnt = 0; 71 76 sd->weakest_signal = 0xFFFFFFFFUL; 72 77 sd->loudest_silence = 0; 73 sd->signal_cnt = 0; 74 sd->silence_cnt = 0; 75 76 /* Restart in adaptive, silent mode */ 78 79 /* Default settings */ 80 pjmedia_silence_det_set_params(sd, -1, -1, -1); 81 82 /* Restart in fixed, silent mode */ 77 83 sd->in_talk = PJ_FALSE; 78 pjmedia_silence_det_set_adaptive( sd, 160);84 pjmedia_silence_det_set_adaptive( sd, -1 ); 79 85 80 86 *p_sd = sd; … … 82 88 } 83 89 84 PJ_DEF(pj_status_t) pjmedia_silence_det_set_adaptive( pjmedia_silence_det *sd, 85 unsigned frame_size) 86 { 87 PJ_ASSERT_RETURN(sd && frame_size, PJ_EINVAL); 88 89 sd->frame_size = frame_size; 90 PJ_DEF(pj_status_t) pjmedia_silence_det_set_adaptive(pjmedia_silence_det *sd, 91 int threshold) 92 { 93 PJ_ASSERT_RETURN(sd, PJ_EINVAL); 94 95 if (threshold < 0) 96 threshold = PJMEDIA_SILENCE_DET_THRESHOLD; 97 90 98 sd->mode = VAD_MODE_ADAPTIVE; 91 sd->min_signal_cnt = 10; 92 sd->min_silence_cnt = 64; 93 sd->recalc_cnt = 250; 94 sd->cur_threshold = 20; 99 sd->cur_threshold = threshold; 95 100 96 101 return PJ_SUCCESS; … … 98 103 99 104 PJ_DEF(pj_status_t) pjmedia_silence_det_set_fixed( pjmedia_silence_det *sd, 100 unsigned frame_size, 101 unsigned threshold ) 102 { 103 PJ_ASSERT_RETURN(sd && frame_size, PJ_EINVAL); 105 int threshold ) 106 { 107 PJ_ASSERT_RETURN(sd, PJ_EINVAL); 108 109 if (threshold < 0) 110 threshold = PJMEDIA_SILENCE_DET_THRESHOLD; 104 111 105 112 sd->mode = VAD_MODE_FIXED; 106 sd->frame_size = frame_size;107 113 sd->cur_threshold = threshold; 108 114 109 115 return PJ_SUCCESS; 110 116 } 117 118 PJ_DEF(pj_status_t) pjmedia_silence_det_set_params( pjmedia_silence_det *sd, 119 int min_silence, 120 int min_signal, 121 int recalc_time) 122 { 123 PJ_ASSERT_RETURN(sd, PJ_EINVAL); 124 125 if (min_silence == -1) 126 min_silence = 500; 127 if (min_signal < 0) 128 min_signal = sd->ptime; 129 if (recalc_time < 0) 130 recalc_time = 5000; 131 132 sd->min_signal_cnt = min_signal / sd->ptime; 133 sd->min_silence_cnt = min_silence / sd->ptime; 134 sd->recalc_cnt = recalc_time / sd->ptime; 135 136 return PJ_SUCCESS; 137 } 138 111 139 112 140 PJ_DEF(pj_status_t) pjmedia_silence_det_disable( pjmedia_silence_det *sd ) … … 185 213 } 186 214 187 /* For fixed threshold sd, everything is done. */188 if (sd->mode == VAD_MODE_FIXED) {189 return !sd->in_talk;190 }191 192 215 193 216 /* Count the number of silent and signal frames and calculate min/max */ … … 208 231 if ((sd->signal_cnt + sd->silence_cnt) > sd->recalc_cnt) { 209 232 210 /* Adjust silence threshold by looking at the proportions of 211 * signal and silence frames. 212 */ 213 if (sd->signal_cnt >= sd->recalc_cnt) { 214 /* All frames where signal frames. 215 * Increase silence threshold. 216 */ 217 sd->cur_threshold += (sd->weakest_signal - sd->cur_threshold)/4; 218 PJ_LOG(6,(THIS_FILE, "Vad cur_threshold increased to %d", 219 sd->cur_threshold)); 220 } 221 else if (sd->silence_cnt >= sd->recalc_cnt) { 222 /* All frames where silence frames. 223 * Decrease silence threshold. 224 */ 225 sd->cur_threshold = (sd->cur_threshold+sd->loudest_silence)/2+1; 226 PJ_LOG(6,(THIS_FILE, "Vad cur_threshold decreased to %d", 227 sd->cur_threshold)); 228 } 229 else { 233 if (sd->mode == VAD_MODE_ADAPTIVE) { 230 234 pj_bool_t updated = PJ_TRUE; 235 unsigned pct_signal; 236 237 /* Get percentage of signal */ 238 pct_signal = sd->signal_cnt * 100 / 239 (sd->signal_cnt + sd->silence_cnt); 231 240 232 241 /* Adjust according to signal/silence proportions. */ 233 if (sd->signal_cnt > sd->silence_cnt * 2) 242 if (pct_signal > 95) { 243 sd->cur_threshold += (sd->weakest_signal - sd->cur_threshold)/4; 244 } else if (pct_signal < 5) { 245 sd->cur_threshold = (sd->cur_threshold+sd->loudest_silence)/2+1; 246 } else if (pct_signal > 90) { 234 247 sd->cur_threshold++; 235 else if (sd->silence_cnt > sd->signal_cnt* 2)248 } else if (pct_signal < 10) { 236 249 sd->cur_threshold--; 237 else250 } else { 238 251 updated = PJ_FALSE; 252 } 239 253 240 254 if (updated) { 241 PJ_LOG(6,(THIS_FILE, 242 "Vad cur_threshold updated to %d", 255 PJ_LOG(5,(THIS_FILE, "Vad cur_threshold updated to %d", 243 256 sd->cur_threshold)); 244 257 } -
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r452 r457 57 57 void *out_pkt; /**< Output buffer. */ 58 58 pjmedia_rtp_session rtp; /**< RTP session. */ 59 char last_frm_type; /**< Last frame type from jb */60 59 }; 61 60 … … 91 90 pjmedia_codec_param codec_param; /**< Codec param. */ 92 91 unsigned frame_size; /**< Size of encoded base frame.*/ 92 pj_bool_t is_streaming; /**< Currently streaming?. This 93 is used to put RTP marker 94 bit. */ 95 93 96 pj_mutex_t *jb_mutex; 94 97 pjmedia_jbuf *jb; /**< Jitter buffer. */ 98 char jb_last_frm; /**< Last frame type from jb */ 95 99 96 100 pjmedia_rtcp_session rtcp; /**< RTCP for incoming RTP. */ … … 210 214 * the frame. 211 215 */ 212 if (frame_type != channel->last_frm_type) {216 if (frame_type != stream->jb_last_frm) { 213 217 pjmedia_jb_state jb_state; 214 218 … … 244 248 pjmedia_zero_samples(p_out_samp + samples_count, 245 249 samples_required - samples_count); 250 samples_count = samples_required; 246 251 } 247 252 248 channel->last_frm_type= frame_type;253 stream->jb_last_frm = frame_type; 249 254 break; 250 255 … … 277 282 } while (samples_count < samples_required); 278 283 279 if ( channel->last_frm_type!= frame_type) {284 if (stream->jb_last_frm != frame_type) { 280 285 PJ_LOG(5,(stream->port.info.name.ptr, 281 286 "Jitter buffer is bufferring with plc (prefetch=%d)", … … 288 293 pjmedia_zero_samples(p_out_samp + samples_count, 289 294 samples_required - samples_count); 295 samples_count = samples_required; 290 296 PJ_LOG(5,(stream->port.info.name.ptr, 291 297 "Jitter buffer is bufferring (prefetch=%d)..", … … 293 299 } 294 300 295 channel->last_frm_type= frame_type;301 stream->jb_last_frm = frame_type; 296 302 break; 297 303 … … 318 324 } 319 325 320 channel->last_frm_type= frame_type;326 stream->jb_last_frm = frame_type; 321 327 } 322 328 … … 438 444 struct pjmedia_frame frame_out; 439 445 unsigned ts_len; 440 pj_bool_t has_tx;441 446 void *rtphdr; 442 447 int rtphdrlen; 443 pj_ssize_t sent;444 448 445 449 … … 454 458 /* Init frame_out buffer. */ 455 459 frame_out.buf = ((char*)channel->out_pkt) + sizeof(pjmedia_rtp_hdr); 456 457 /* Make compiler happy */458 460 frame_out.size = 0; 461 459 462 460 463 /* If we have DTMF digits in the queue, transmit the digits. … … 463 466 if (stream->tx_dtmf_count) { 464 467 465 has_tx = PJ_TRUE;466 468 create_dtmf_payload(stream, &frame_out); 467 469 … … 475 477 } else if (frame->type != PJMEDIA_FRAME_TYPE_NONE) { 476 478 unsigned ts, samples_per_frame; 477 478 has_tx = PJ_TRUE;479 479 480 480 /* Repeatedly call encode if there are multiple frames to be … … 490 490 unsigned bytes_per_sample, max_size; 491 491 492 /* Nb of bytes in PCM sample */ 492 493 bytes_per_sample = stream->codec_param.info.pcm_bits_per_sample/8; 493 494 495 /* Split original PCM input frame into base frame size */ 494 496 tmp_in_frame.buf = ((char*)frame->buf) + ts * bytes_per_sample; 495 497 tmp_in_frame.size = samples_per_frame * bytes_per_sample; 496 498 tmp_in_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 497 499 500 /* Set output frame position */ 498 501 tmp_out_frame.buf = ((char*)frame_out.buf) + frame_out.size; 499 502 … … 501 504 frame_out.size; 502 505 506 /* Encode! */ 503 507 status = stream->codec->op->encode( stream->codec, &tmp_in_frame, 504 508 max_size, &tmp_out_frame); … … 509 513 } 510 514 515 /* tmp_out_frame.size may be zero for silence frame. */ 511 516 frame_out.size += tmp_out_frame.size; 517 518 /* Stop processing next PCM frame when encode() returns either 519 * CNG frame or NULL frame. 520 */ 521 if (tmp_out_frame.type!=PJMEDIA_FRAME_TYPE_AUDIO || 522 tmp_out_frame.size==0) 523 { 524 break; 525 } 526 512 527 } 513 514 //printf("p"); fflush(stdout);515 528 516 529 /* Encapsulate. */ … … 523 536 524 537 /* Just update RTP session's timestamp. */ 525 has_tx = PJ_FALSE;526 538 status = pjmedia_rtp_encode_rtp( &channel->rtp, 527 539 0, 0, … … 547 559 548 560 /* Do nothing if we have nothing to transmit */ 549 if (!has_tx) 561 if (frame_out.size == 0) { 562 if (stream->is_streaming) { 563 PJ_LOG(5,(stream->port.info.name.ptr,"Starting silence")); 564 stream->is_streaming = PJ_FALSE; 565 } 550 566 return PJ_SUCCESS; 551 552 if (rtphdrlen != sizeof(pjmedia_rtp_hdr)) { 553 /* We don't support RTP with extended header yet. */ 554 PJ_TODO(SUPPORT_SENDING_RTP_WITH_EXTENDED_HEADER); 555 return PJ_SUCCESS; 556 } 557 567 } 568 569 570 /* Copy RTP header to the beginning of packet */ 558 571 pj_memcpy(channel->out_pkt, rtphdr, sizeof(pjmedia_rtp_hdr)); 559 572 560 573 561 /* Send. */ 562 sent = frame_out.size+sizeof(pjmedia_rtp_hdr); 563 574 /* Set RTP marker bit if currently not streaming */ 575 if (stream->is_streaming == PJ_FALSE) { 576 pjmedia_rtp_hdr *rtp = channel->out_pkt; 577 578 rtp->m = 1; 579 PJ_LOG(5,(stream->port.info.name.ptr,"Start talksprut..")); 580 } 581 582 stream->is_streaming = PJ_TRUE; 583 584 /* Send the RTP packet to the transport. */ 564 585 (*stream->transport->op->send_rtp)(stream->transport, 565 channel->out_pkt, sent); 586 channel->out_pkt, 587 frame_out.size + 588 sizeof(pjmedia_rtp_hdr)); 566 589 567 590 -
pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c
r452 r457 398 398 PJ_ASSERT_RETURN(tp && strm && rem_addr && addr_len, PJ_EINVAL); 399 399 400 /* Remote address must be Internet address */401 PJ_ASSERT_RETURN(addr_len == sizeof(pj_sockaddr_in) &&402 ((pj_sockaddr_in*)rem_addr)->sin_family == PJ_AF_INET,403 PJ_EINVAL);404 405 400 /* Must not be "attached" to existing stream */ 406 401 PJ_ASSERT_RETURN(udp->stream == NULL, PJ_EINVALIDOP);
Note: See TracChangeset
for help on using the changeset viewer.