- Timestamp:
- Sep 20, 2007 1:19:03 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/pjproject-0.5-stable/pjmedia/src/pjmedia/stream.c
r1047 r1447 63 63 { 64 64 int event; 65 pj_uint32_t start_ts;65 pj_uint32_t duration; 66 66 }; 67 67 … … 167 167 static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) 168 168 { 169 pjmedia_stream *stream = port->port_data.pdata;169 pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 170 170 pjmedia_channel *channel = stream->dec; 171 171 unsigned samples_count, samples_per_frame, samples_required; … … 192 192 stream->codec_param.info.channel_cnt / 193 193 1000; 194 p_out_samp = frame->buf;194 p_out_samp = (pj_int16_t*) frame->buf; 195 195 196 196 for (samples_count=0; samples_count < samples_required; … … 374 374 */ 375 375 static void create_dtmf_payload(pjmedia_stream *stream, 376 struct pjmedia_frame *frame_out) 376 struct pjmedia_frame *frame_out, 377 int *first, int *last) 377 378 { 378 379 pjmedia_rtp_dtmf_event *event; 379 380 struct dtmf *digit = &stream->tx_dtmf_buf[0]; 380 unsigned duration;381 381 pj_uint32_t cur_ts; 382 382 383 383 pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4); 384 384 385 event = frame_out->buf; 385 *first = *last = 0; 386 387 event = (pjmedia_rtp_dtmf_event*) frame_out->buf; 386 388 cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts); 387 duration = cur_ts - digit->start_ts; 389 390 if (digit->duration == 0) { 391 PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 392 digitmap[digit->event])); 393 *first = 1; 394 } 395 396 digit->duration += stream->port.info.samples_per_frame; 388 397 389 398 event->event = (pj_uint8_t)digit->event; 390 399 event->e_vol = 10; 391 event->duration = pj_htons((pj_uint16_t)duration); 392 393 if (duration >= PJMEDIA_DTMF_DURATION) { 400 event->duration = pj_htons((pj_uint16_t)digit->duration); 401 402 403 if (digit->duration >= PJMEDIA_DTMF_DURATION) { 404 394 405 event->e_vol |= 0x80; 406 *last = 1; 395 407 396 408 /* Prepare next digit. */ 397 409 pj_mutex_lock(stream->jb_mutex); 410 398 411 pj_array_erase(stream->tx_dtmf_buf, sizeof(stream->tx_dtmf_buf[0]), 399 412 stream->tx_dtmf_count, 0); 400 413 --stream->tx_dtmf_count; 401 414 402 stream->tx_dtmf_buf[0].start_ts = cur_ts;403 415 pj_mutex_unlock(stream->jb_mutex); 404 405 if (stream->tx_dtmf_count) { 406 PJ_LOG(5,(stream->port.info.name.ptr, 407 "Sending DTMF digit id %c", 408 digitmap[stream->tx_dtmf_buf[0].event])); 409 } 410 411 } else if (duration == 0) { 412 PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 413 digitmap[digit->event])); 414 } 415 416 } 416 417 417 418 frame_out->size = 4; … … 439 440 } else if (timestamp - stream->rtcp_last_tx >= stream->rtcp_interval) { 440 441 441 pjmedia_rtcp_pkt*rtcp_pkt;442 void *rtcp_pkt; 442 443 int len; 443 444 … … 515 516 const pjmedia_frame *frame ) 516 517 { 517 pjmedia_stream *stream = port->port_data.pdata;518 pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 518 519 pjmedia_channel *channel = stream->enc; 519 520 pj_status_t status = 0; … … 522 523 void *rtphdr; 523 524 int rtphdrlen; 524 525 int inc_timestamp = 0; 525 526 526 527 /* Don't do anything if stream is paused */ … … 551 552 */ 552 553 if (stream->tx_dtmf_count) { 553 554 create_dtmf_payload(stream, &frame_out); 555 556 /* Encapsulate. */ 554 int first=0, last=0; 555 556 create_dtmf_payload(stream, &frame_out, &first, &last); 557 558 /* Encapsulate into RTP packet. Note that: 559 * - RTP marker should be set on the beginning of a new event 560 * - RTP timestamp is constant for the same packet. 561 */ 557 562 status = pjmedia_rtp_encode_rtp( &channel->rtp, 558 stream->tx_event_pt, 0,559 frame_out.size, ts_len,563 stream->tx_event_pt, first, 564 frame_out.size, (first?ts_len:0), 560 565 (const void**)&rtphdr, 561 566 &rtphdrlen); 567 568 if (last) { 569 /* This is the last packet for the event. 570 * Increment the RTP timestamp of the RTP session, for next 571 * RTP packets. 572 */ 573 inc_timestamp = PJMEDIA_DTMF_DURATION - ts_len; 574 } 562 575 563 576 } else if (frame->type != PJMEDIA_FRAME_TYPE_NONE) { … … 663 676 pj_memcpy(channel->out_pkt, rtphdr, sizeof(pjmedia_rtp_hdr)); 664 677 678 /* Special case for DTMF: timestamp remains constant for 679 * the same event, and is only updated after a complete event 680 * has been transmitted. 681 */ 682 if (inc_timestamp) { 683 pjmedia_rtp_encode_rtp( &channel->rtp, stream->tx_event_pt, 0, 684 0, inc_timestamp, NULL, NULL); 685 } 665 686 666 687 /* Set RTP marker bit if currently not streaming */ 667 688 if (stream->is_streaming == PJ_FALSE) { 668 pjmedia_rtp_hdr *rtp = channel->out_pkt;689 pjmedia_rtp_hdr *rtp = (pjmedia_rtp_hdr*) channel->out_pkt; 669 690 670 691 rtp->m = 1; … … 698 719 const pjmedia_frame *frame ) 699 720 { 700 pjmedia_stream *stream = port->port_data.pdata;721 pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; 701 722 pjmedia_frame tmp_zero_frame; 702 723 unsigned samples_per_frame; … … 831 852 const void *payload, unsigned payloadlen) 832 853 { 833 const pjmedia_rtp_dtmf_event *event =payload;854 pjmedia_rtp_dtmf_event *event = (pjmedia_rtp_dtmf_event*) payload; 834 855 835 856 /* Check compiler packing. */ … … 903 924 904 925 { 905 pjmedia_stream *stream = data;926 pjmedia_stream *stream = (pjmedia_stream*) data; 906 927 pjmedia_channel *channel = stream->dec; 907 928 const pjmedia_rtp_hdr *hdr; … … 919 940 920 941 /* Ignore keep-alive packets */ 921 if (bytes_read < sizeof(pjmedia_rtp_hdr))942 if (bytes_read < (pj_ssize_t) sizeof(pjmedia_rtp_hdr)) 922 943 return; 923 944 … … 1053 1074 pj_ssize_t bytes_read) 1054 1075 { 1055 pjmedia_stream *stream = data;1076 pjmedia_stream *stream = (pjmedia_stream*) data; 1056 1077 1057 1078 /* Check for errors */ … … 1081 1102 /* Allocate memory for channel descriptor */ 1082 1103 1083 channel = pj_pool_zalloc(pool, sizeof(pjmedia_channel));1104 channel = (pjmedia_channel*) pj_pool_zalloc(pool, sizeof(pjmedia_channel)); 1084 1105 PJ_ASSERT_RETURN(channel != NULL, PJ_ENOMEM); 1085 1106 … … 1147 1168 /* Allocate the media stream: */ 1148 1169 1149 stream = pj_pool_zalloc(pool, sizeof(pjmedia_stream));1170 stream = (pjmedia_stream*) pj_pool_zalloc(pool, sizeof(pjmedia_stream)); 1150 1171 PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM); 1151 1172 1152 1173 /* Init stream/port name */ 1153 name.ptr = pj_pool_alloc(pool, M);1174 name.ptr = (char*) pj_pool_alloc(pool, M); 1154 1175 name.slen = pj_ansi_snprintf(name.ptr, M, "strm%p", stream); 1155 1176 … … 1263 1284 /* Allocate buffer */ 1264 1285 stream->enc_buf_size = stream->port.info.clock_rate * ptime / 1000; 1265 stream->enc_buf = pj_pool_alloc(pool, stream->enc_buf_size * 2); 1286 stream->enc_buf = (pj_int16_t*) 1287 pj_pool_alloc(pool, stream->enc_buf_size * 2); 1266 1288 1267 1289 } else { … … 1536 1558 1537 1559 if (stream->tx_dtmf_count+digit_char->slen >= 1538 PJ_ARRAY_SIZE(stream->tx_dtmf_buf))1560 (long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) 1539 1561 { 1540 1562 status = PJ_ETOOMANY; … … 1572 1594 1573 1595 stream->tx_dtmf_buf[stream->tx_dtmf_count+i].event = pt; 1596 stream->tx_dtmf_buf[stream->tx_dtmf_count+i].duration = 0; 1574 1597 } 1575 1598 … … 1577 1600 goto on_return; 1578 1601 1579 /* Init start_ts and end_ts only for the first digit.1580 * Subsequent digits are initialized on the fly.1581 */1582 if (stream->tx_dtmf_count ==0) {1583 pj_uint32_t start_ts;1584 1585 start_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts);1586 stream->tx_dtmf_buf[0].start_ts = start_ts;1587 }1588 1589 1602 /* Increment digit count only if all digits are valid. */ 1590 1603 stream->tx_dtmf_count += digit_char->slen; 1591 1592 1604 } 1593 1605 … … 1646 1658 * Set callback to be called upon receiving DTMF digits. 1647 1659 */ 1648 PJ_DEF(pj_status_t) 1649 pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 1660 PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 1650 1661 void (*cb)(pjmedia_stream*, 1651 1662 void *user_data,
Note: See TracChangeset
for help on using the changeset viewer.