Changeset 457 for pjproject/trunk/pjmedia/src/pjmedia/stream.c
- Timestamp:
- May 19, 2006 3:58:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.