Changeset 205 for pjproject/trunk/pjmedia/src/pjmedia/stream.c
- Timestamp:
- Feb 21, 2006 12:11:18 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r188 r205 53 53 pj_bool_t paused; /**< Paused?. */ 54 54 pj_snd_stream_info snd_info; /**< Sound stream param. */ 55 pj_snd_stream *snd_stream; /**< Sound stream. */55 //pj_snd_stream *snd_stream; /**< Sound stream. */ 56 56 unsigned in_pkt_size; /**< Size of input buffer. */ 57 57 void *in_pkt; /**< Input buffer. */ … … 73 73 struct pjmedia_stream 74 74 { 75 pjmedia_port port; /**< Port interface. */ 75 76 pjmedia_channel *enc; /**< Encoding channel. */ 76 77 pjmedia_channel *dec; /**< Decoding channel. */ … … 103 104 * needs to feed the player with some frames. 104 105 */ 105 static pj_status_t play_callback(/* in */ void *user_data, 106 /* in */ pj_uint32_t timestamp, 107 /* out */ void *frame, 108 /*inout*/ unsigned size) 109 { 110 pjmedia_channel *channel = user_data; 111 pjmedia_stream *stream = channel->stream; 106 static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) 107 { 108 pjmedia_stream *stream = port->user_data; 109 pjmedia_channel *channel = stream->dec; 110 112 111 char frame_type; 113 112 pj_status_t status; 114 113 struct pjmedia_frame frame_in, frame_out; 115 114 116 PJ_UNUSED_ARG(timestamp);117 118 115 /* Do nothing if we're quitting. */ 119 if (stream->quit_flag) 120 return -1; 116 if (stream->quit_flag) { 117 frame->type = PJMEDIA_FRAME_TYPE_NONE; 118 return PJ_SUCCESS; 119 } 121 120 122 121 /* Lock jitter buffer mutex */ … … 133 132 frame_type == PJMEDIA_JB_MISSING_FRAME) 134 133 { 135 pj_memset(frame, 0, size);136 return 0;134 frame->type = PJMEDIA_FRAME_TYPE_NONE; 135 return PJ_SUCCESS; 137 136 } 138 137 … … 148 147 TRACE_((THIS_FILE, "decode() has return error status %d", status)); 149 148 150 pj_memset(frame, 0, size);151 return 0;149 frame->type = PJMEDIA_FRAME_TYPE_NONE; 150 return PJ_SUCCESS; 152 151 } 153 152 154 153 /* Put in sound buffer. */ 155 if (frame_out.size > size) {154 if (frame_out.size > frame->size) { 156 155 TRACE_((THIS_FILE, "Sound playout buffer truncated %d bytes", 157 frame_out.size - size)); 158 frame_out.size = size; 159 } 160 161 pj_memcpy(frame, frame_out.buf, size); 162 163 return 0; 156 frame_out.size - frame->size)); 157 frame_out.size = frame->size; 158 } 159 160 frame->type = PJMEDIA_FRAME_TYPE_AUDIO; 161 frame->size = frame_out.size; 162 frame->timestamp.u64 = 0; 163 pj_memcpy(frame->buf, frame_out.buf, frame_out.size); 164 165 return PJ_SUCCESS; 164 166 } 165 167 … … 172 174 * send it to remote. 173 175 */ 174 static pj_status_t rec_callback( /* in */ void *user_data, 175 /* in */ pj_uint32_t timestamp, 176 /* in */ const void *frame, 177 /* in */ unsigned size) 178 { 179 pjmedia_channel *channel = user_data; 180 pjmedia_stream *stream = channel->stream; 176 static pj_status_t put_frame( pjmedia_port *port, 177 const pjmedia_frame *frame ) 178 { 179 pjmedia_stream *stream = port->user_data; 180 pjmedia_channel *channel = stream->enc; 181 181 pj_status_t status = 0; 182 struct pjmedia_frame frame_ in, frame_out;182 struct pjmedia_frame frame_out; 183 183 int ts_len; 184 184 void *rtphdr; … … 187 187 188 188 189 PJ_UNUSED_ARG(timestamp);190 191 189 /* Check if stream is quitting. */ 192 190 if (stream->quit_flag) … … 194 192 195 193 /* Encode. */ 196 frame_in.type = PJMEDIA_TYPE_AUDIO;197 frame_in.buf = (void*)frame;198 frame_in.size = size;199 194 frame_out.buf = ((char*)channel->out_pkt) + sizeof(pjmedia_rtp_hdr); 200 status = stream->codec->op->encode( stream->codec, &frame_in,195 status = stream->codec->op->encode( stream->codec, frame, 201 196 channel->out_pkt_size - sizeof(pjmedia_rtp_hdr), 202 197 &frame_out); … … 208 203 209 204 /* Encapsulate. */ 210 ts_len = size / (channel->snd_info.bits_per_sample / 8);205 ts_len = frame->size / (channel->snd_info.bits_per_sample / 8); 211 206 status = pjmedia_rtp_encode_rtp( &channel->rtp, 212 207 channel->pt, 0, … … 239 234 stream->stat.enc.bytes += frame_out.size+sizeof(pjmedia_rtp_hdr); 240 235 241 return 0;236 return PJ_SUCCESS; 242 237 } 243 238 … … 426 421 init_snd_param(&channel->snd_info, codec_param); 427 422 423 /* 428 424 if (dir == PJMEDIA_DIR_ENCODING) 429 425 channel->snd_stream = pj_snd_open_recorder(-1, &channel->snd_info, … … 435 431 if (!channel->snd_stream) 436 432 return -1; 437 433 */ 438 434 439 435 /* Done. */ … … 463 459 stream = pj_pool_zalloc(pool, sizeof(pjmedia_stream)); 464 460 PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 461 462 /* Init port. */ 463 stream->port.info.name = pj_str("stream"); 464 stream->port.info.signature = ('S'<<3 | 'T'<<2 | 'R'<<1 | 'M'); 465 stream->port.info.type = PJMEDIA_TYPE_AUDIO; 466 stream->port.info.has_info = 1; 467 stream->port.info.need_info = 0; 468 stream->port.info.pt = info->fmt.pt; 469 pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name); 470 stream->port.info.sample_rate = info->fmt.sample_rate; 471 stream->port.user_data = stream; 472 stream->port.put_frame = &put_frame; 473 stream->port.get_frame = &get_frame; 465 474 466 475 … … 495 504 goto err_cleanup; 496 505 506 /* Set additional info. */ 507 stream->port.info.bits_per_sample = 0; 508 stream->port.info.samples_per_frame = info->fmt.sample_rate*codec_param.ptime/1000; 509 stream->port.info.bytes_per_frame = codec_param.avg_bps/8 * codec_param.ptime/1000; 510 497 511 498 512 /* Open the codec: */ … … 576 590 /* Close encoding sound stream. */ 577 591 592 /* 578 593 if (stream->enc && stream->enc->snd_stream) { 579 594 … … 583 598 584 599 } 600 */ 585 601 586 602 /* Close decoding sound stream. */ 587 603 604 /* 588 605 if (stream->dec && stream->dec->snd_stream) { 589 606 … … 593 610 594 611 } 612 */ 595 613 596 614 /* Wait for jitter buffer thread to quit: */ … … 623 641 624 642 /* 643 * Get the port interface. 644 */ 645 PJ_DEF(pj_status_t) pjmedia_stream_get_port( pjmedia_stream *stream, 646 pjmedia_port **p_port ) 647 { 648 *p_port = &stream->port; 649 return PJ_SUCCESS; 650 } 651 652 653 /* 625 654 * Start stream. 626 655 */ … … 632 661 if (stream->enc && (stream->dir & PJMEDIA_DIR_ENCODING)) { 633 662 stream->enc->paused = 0; 634 pj_snd_stream_start(stream->enc->snd_stream);663 //pj_snd_stream_start(stream->enc->snd_stream); 635 664 } 636 665 637 666 if (stream->dec && (stream->dir & PJMEDIA_DIR_DECODING)) { 638 667 stream->dec->paused = 0; 639 pj_snd_stream_start(stream->dec->snd_stream);668 //pj_snd_stream_start(stream->dec->snd_stream); 640 669 } 641 670
Note: See TracChangeset
for help on using the changeset viewer.