Changeset 4728 for pjproject/trunk/pjmedia/src/pjmedia/stream.c
- Timestamp:
- Feb 4, 2014 10:13:56 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r4613 r4728 1 1 /* $Id$ */ 2 /* 2 /* 3 3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 4 4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> … … 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 #include <pjmedia/stream.h> … … 185 185 */ 186 186 pj_bool_t has_g722_mpeg_bug; 187 /**< Flag to specify whether 188 normalization process 187 /**< Flag to specify whether 188 normalization process 189 189 is needed */ 190 190 unsigned rtp_tx_ts_len_per_pkt; 191 191 /**< Normalized ts length per packet 192 transmitted according to 192 transmitted according to 193 193 'erroneous' definition */ 194 194 unsigned rtp_rx_ts_len_per_frame; 195 195 /**< Normalized ts length per frame 196 received according to 196 received according to 197 197 'erroneous' definition */ 198 198 unsigned rtp_rx_last_cnt;/**< Nb of frames in last pkt */ … … 203 203 204 204 #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) 205 pj_uint32_t rtcp_xr_last_tx; /**< RTCP XR tx time 205 pj_uint32_t rtcp_xr_last_tx; /**< RTCP XR tx time 206 206 in timestamp. */ 207 207 pj_uint32_t rtcp_xr_interval; /**< Interval, in timestamp. */ 208 pj_sockaddr rtcp_xr_dest; /**< Additional remote RTCP XR 209 dest. If sin_family is 208 pj_sockaddr rtcp_xr_dest; /**< Additional remote RTCP XR 209 dest. If sin_family is 210 210 zero, it will be ignored*/ 211 211 unsigned rtcp_xr_dest_len; /**< Length of RTCP XR dest … … 231 231 232 232 /* RFC 2833 digit */ 233 static const char digitmap[16] = { '0', '1', '2', '3', 234 '4', '5', '6', '7', 233 static const char digitmap[16] = { '0', '1', '2', '3', 234 '4', '5', '6', '7', 235 235 '8', '9', '*', '#', 236 236 'A', 'B', 'C', 'D'}; … … 285 285 } 286 286 287 PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, 287 PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, 288 288 char **buf, pj_ssize_t len) 289 289 { … … 460 460 461 461 #else 462 462 463 463 PJ_UNUSED_ARG(stream); 464 464 … … 498 498 samples_per_frame = stream->codec_param.info.frm_ptime * 499 499 stream->codec_param.info.clock_rate * 500 stream->codec_param.info.channel_cnt / 500 stream->codec_param.info.channel_cnt / 501 501 1000; 502 502 p_out_samp = (pj_int16_t*) frame->buf; 503 503 504 for (samples_count=0; samples_count < samples_required; 505 samples_count += samples_per_frame) 504 for (samples_count=0; samples_count < samples_required; 505 samples_count += samples_per_frame) 506 506 { 507 507 char frame_type; … … 518 518 519 519 if (frame_type == PJMEDIA_JB_MISSING_FRAME) { 520 520 521 521 /* Activate PLC */ 522 if (stream->codec->op->recover && 522 if (stream->codec->op->recover && 523 523 stream->codec_param.setting.plc && 524 stream->plc_cnt < stream->max_plc_cnt) 524 stream->plc_cnt < stream->max_plc_cnt) 525 525 { 526 526 pjmedia_frame frame_out; … … 561 561 /* Jitter buffer is empty. If this is the first "empty" state, 562 562 * activate PLC to smoothen the fade-out, otherwise zero 563 * the frame. 563 * the frame. 564 564 */ 565 565 //Using this "if" will only invoke PLC for the first packet … … 568 568 if (1) { 569 569 /* Activate PLC to smoothen the missing frame */ 570 if (stream->codec->op->recover && 570 if (stream->codec->op->recover && 571 571 stream->codec_param.setting.plc && 572 stream->plc_cnt < stream->max_plc_cnt) 572 stream->plc_cnt < stream->max_plc_cnt) 573 573 { 574 574 pjmedia_frame frame_out; … … 590 590 591 591 with_plc = ", plc invoked"; 592 } 592 } 593 593 } 594 594 … … 604 604 /* Report changing frame type event */ 605 605 pjmedia_jbuf_get_state(stream->jb, &jb_state); 606 PJ_LOG(5,(stream->port.info.name.ptr, 607 "Jitter buffer empty (prefetch=%d)%s", 606 PJ_LOG(5,(stream->port.info.name.ptr, 607 "Jitter buffer empty (prefetch=%d)%s", 608 608 jb_state.prefetch, with_plc)); 609 609 … … 623 623 624 624 /* Always activate PLC when it's available.. */ 625 if (stream->codec->op->recover && 625 if (stream->codec->op->recover && 626 626 stream->codec_param.setting.plc && 627 stream->plc_cnt < stream->max_plc_cnt) 627 stream->plc_cnt < stream->max_plc_cnt) 628 628 { 629 629 pjmedia_frame frame_out; … … 645 645 646 646 with_plc = ", plc invoked"; 647 } 647 } 648 648 649 649 if (samples_count < samples_required) { … … 658 658 /* Report changing frame type event */ 659 659 pjmedia_jbuf_get_state(stream->jb, &jb_state); 660 PJ_LOG(5,(stream->port.info.name.ptr, 661 "Jitter buffer is bufferring (prefetch=%d)%s", 660 PJ_LOG(5,(stream->port.info.name.ptr, 661 "Jitter buffer is bufferring (prefetch=%d)%s", 662 662 jb_state.prefetch, with_plc)); 663 663 … … 684 684 frame_out.size = frame->size - samples_count*BYTES_PER_SAMPLE; 685 685 status = pjmedia_codec_decode( stream->codec, &frame_in, 686 (unsigned)frame_out.size, 686 (unsigned)frame_out.size, 687 687 &frame_out); 688 688 if (status != 0) { 689 LOGERR_((port->info.name.ptr, "codec decode() error", 689 LOGERR_((port->info.name.ptr, "codec decode() error", 690 690 status)); 691 691 692 pjmedia_zero_samples(p_out_samp + samples_count, 692 pjmedia_zero_samples(p_out_samp + samples_count, 693 693 samples_per_frame); 694 694 } … … 696 696 if (stream->jb_last_frm != frame_type) { 697 697 /* Report changing frame type event */ 698 PJ_LOG(5,(stream->port.info.name.ptr, 698 PJ_LOG(5,(stream->port.info.name.ptr, 699 699 "Jitter buffer starts returning normal frames " 700 700 "(after %d empty/lost)", … … 753 753 samples_per_frame = stream->codec_param.info.frm_ptime * 754 754 stream->codec_param.info.clock_rate * 755 stream->codec_param.info.channel_cnt / 755 stream->codec_param.info.channel_cnt / 756 756 1000; 757 757 … … 774 774 trace_jb_get(stream, frame_type, frame_size); 775 775 #endif 776 776 777 777 /* Unlock jitter buffer mutex. */ 778 778 pj_mutex_unlock( stream->jb_mutex ); … … 791 791 0, frame); 792 792 if (status != PJ_SUCCESS) { 793 LOGERR_((port->info.name.ptr, "codec decode() error", 793 LOGERR_((port->info.name.ptr, "codec decode() error", 794 794 status)); 795 795 pjmedia_frame_ext_append_subframe(f, NULL, 0, … … 799 799 if (stream->jb_last_frm != frame_type) { 800 800 /* Report changing frame type event */ 801 PJ_LOG(5,(stream->port.info.name.ptr, 801 PJ_LOG(5,(stream->port.info.name.ptr, 802 802 "Jitter buffer starts returning normal frames " 803 803 "(after %d empty/lost)", … … 817 817 status = pjmedia_codec_recover(stream->codec, 0, frame); 818 818 } 819 819 820 820 /* No PLC or PLC failed */ 821 821 if (!stream->codec->op->recover || status != PJ_SUCCESS) { … … 840 840 /* Report changing frame type event */ 841 841 pjmedia_jbuf_get_state(stream->jb, &jb_state); 842 PJ_LOG(5,(stream->port.info.name.ptr, 843 "Jitter buffer empty (prefetch=%d)", 842 PJ_LOG(5,(stream->port.info.name.ptr, 843 "Jitter buffer empty (prefetch=%d)", 844 844 jb_state.prefetch)); 845 845 … … 859 859 /* Report changing frame type event */ 860 860 pjmedia_jbuf_get_state(stream->jb, &jb_state); 861 PJ_LOG(5,(stream->port.info.name.ptr, 861 PJ_LOG(5,(stream->port.info.name.ptr, 862 862 "Jitter buffer is bufferring (prefetch=%d)", 863 863 jb_state.prefetch)); … … 879 879 * Transmit DTMF 880 880 */ 881 static void create_dtmf_payload(pjmedia_stream *stream, 881 static void create_dtmf_payload(pjmedia_stream *stream, 882 882 struct pjmedia_frame *frame_out, 883 883 int forced_last, int *first, int *last) … … 885 885 pjmedia_rtp_dtmf_event *event; 886 886 struct dtmf *digit = &stream->tx_dtmf_buf[0]; 887 pj_uint32_t cur_ts;888 887 889 888 pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4); … … 892 891 893 892 event = (pjmedia_rtp_dtmf_event*) frame_out->buf; 894 cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts);895 893 896 894 if (digit->duration == 0) { 897 PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 895 PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 898 896 digitmap[digit->event])); 899 897 *first = 1; … … 988 986 /* Update RTCP XR with current JB states */ 989 987 pjmedia_jbuf_get_state(stream->jb, &jb_state); 990 988 991 989 i = jb_state.avg_delay; 992 status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 990 status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 993 991 PJMEDIA_RTCP_XR_INFO_JB_NOM, i); 994 992 pj_assert(status == PJ_SUCCESS); 995 993 996 994 i = jb_state.max_delay; 997 status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 995 status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 998 996 PJMEDIA_RTCP_XR_INFO_JB_MAX, i); 999 997 pj_assert(status == PJ_SUCCESS); … … 1008 1006 /* Send the RTCP XR to third-party destination if specified */ 1009 1007 if (stream->rtcp_xr_dest_len) { 1010 pjmedia_transport_send_rtcp2(stream->transport, 1008 pjmedia_transport_send_rtcp2(stream->transport, 1011 1009 &stream->rtcp_xr_dest, 1012 stream->rtcp_xr_dest_len, 1010 stream->rtcp_xr_dest_len, 1013 1011 xr_pkt, xr_len); 1014 1012 } … … 1050 1048 static void check_tx_rtcp(pjmedia_stream *stream, pj_uint32_t timestamp) 1051 1049 { 1052 /* Note that timestamp may represent local or remote timestamp, 1050 /* Note that timestamp may represent local or remote timestamp, 1053 1051 * depending on whether this function is called from put_frame() 1054 1052 * or get_frame(). … … 1056 1054 1057 1055 if (stream->rtcp_last_tx == 0) { 1058 1056 1059 1057 stream->rtcp_last_tx = timestamp; 1060 1058 … … 1067 1065 if (stream->rtcp_xr_last_tx == 0) { 1068 1066 stream->rtcp_xr_last_tx = timestamp; 1069 } else if (timestamp - stream->rtcp_xr_last_tx >= 1067 } else if (timestamp - stream->rtcp_xr_last_tx >= 1070 1068 stream->rtcp_xr_interval) 1071 1069 { … … 1131 1129 1132 1130 /* How many samples are needed */ 1133 count = stream->codec_param.info.enc_ptime * 1131 count = stream->codec_param.info.enc_ptime * 1134 1132 PJMEDIA_PIA_SRATE(&stream->port.info) / 1000; 1135 1133 … … 1154 1152 * put_frame_imp() 1155 1153 */ 1156 static pj_status_t put_frame_imp( pjmedia_port *port, 1154 static pj_status_t put_frame_imp( pjmedia_port *port, 1157 1155 pjmedia_frame *frame ) 1158 1156 { … … 1175 1173 pj_uint32_t dtx_duration; 1176 1174 1177 dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, 1175 dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, 1178 1176 &frame->timestamp); 1179 1177 if (dtx_duration > … … 1194 1192 /* Number of samples in the frame */ 1195 1193 if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) 1196 ts_len = ((unsigned)frame->size >> 1) / 1194 ts_len = ((unsigned)frame->size >> 1) / 1197 1195 stream->codec_param.info.channel_cnt; 1198 1196 else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) … … 1206 1204 1207 1205 #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0) 1208 /* Handle special case for audio codec with RTP timestamp inconsistence 1206 /* Handle special case for audio codec with RTP timestamp inconsistence 1209 1207 * e.g: G722, MPEG audio. 1210 1208 */ … … 1225 1223 1226 1224 1227 /* If we have DTMF digits in the queue, transmit the digits. 1225 /* If we have DTMF digits in the queue, transmit the digits. 1228 1226 * Otherwise encode the PCM buffer. 1229 1227 */ … … 1235 1233 /* Encapsulate into RTP packet. Note that: 1236 1234 * - RTP marker should be set on the beginning of a new event 1237 * - RTP timestamp is constant for the same packet. 1235 * - RTP timestamp is constant for the same packet. 1238 1236 */ 1239 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1240 stream->tx_event_pt, first, 1237 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1238 stream->tx_event_pt, first, 1241 1239 (int)frame_out.size, 1242 (first ? rtp_ts_len : 0), 1243 (const void**)&rtphdr, 1240 (first ? rtp_ts_len : 0), 1241 (const void**)&rtphdr, 1244 1242 &rtphdrlen); 1245 1243 1246 1244 if (last) { 1247 /* This is the last packet for the event. 1245 /* This is the last packet for the event. 1248 1246 * Increment the RTP timestamp of the RTP session, for next 1249 1247 * RTP packets. … … 1272 1270 stream->codec_param.info.channel_cnt * 1273 1271 stream->codec_param.info.clock_rate/1000 < 1274 PJ_ARRAY_SIZE(zero_frame)) 1272 PJ_ARRAY_SIZE(zero_frame)) 1275 1273 { 1276 1274 pjmedia_frame silence_frame; … … 1283 1281 silence_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 1284 1282 silence_frame.timestamp.u32.lo = pj_ntohl(stream->enc->rtp.out_hdr.ts); 1285 1283 1286 1284 /* Encode! */ 1287 1285 status = pjmedia_codec_encode( stream->codec, &silence_frame, 1288 channel->out_pkt_size - 1286 channel->out_pkt_size - 1289 1287 sizeof(pjmedia_rtp_hdr), 1290 1288 &frame_out); 1291 1289 if (status != PJ_SUCCESS) { 1292 LOGERR_((stream->port.info.name.ptr, 1290 LOGERR_((stream->port.info.name.ptr, 1293 1291 "Codec encode() error", status)); 1294 1292 return status; … … 1296 1294 1297 1295 /* Encapsulate. */ 1298 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1299 channel->pt, 0, 1300 (int)frame_out.size, rtp_ts_len, 1301 (const void**)&rtphdr, 1296 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1297 channel->pt, 0, 1298 (int)frame_out.size, rtp_ts_len, 1299 (const void**)&rtphdr, 1302 1300 &rtphdrlen); 1303 1301 … … 1309 1307 { 1310 1308 /* Encode! */ 1311 status = pjmedia_codec_encode( stream->codec, frame, 1312 channel->out_pkt_size - 1309 status = pjmedia_codec_encode( stream->codec, frame, 1310 channel->out_pkt_size - 1313 1311 sizeof(pjmedia_rtp_hdr), 1314 1312 &frame_out); 1315 1313 if (status != PJ_SUCCESS) { 1316 LOGERR_((stream->port.info.name.ptr, 1314 LOGERR_((stream->port.info.name.ptr, 1317 1315 "Codec encode() error", status)); 1318 1316 return status; … … 1320 1318 1321 1319 /* Encapsulate. */ 1322 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1323 channel->pt, 0, 1324 (int)frame_out.size, rtp_ts_len, 1325 (const void**)&rtphdr, 1320 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1321 channel->pt, 0, 1322 (int)frame_out.size, rtp_ts_len, 1323 (const void**)&rtphdr, 1326 1324 &rtphdrlen); 1327 1325 … … 1329 1327 1330 1328 /* Just update RTP session's timestamp. */ 1331 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1332 0, 0, 1333 0, rtp_ts_len, 1334 (const void**)&rtphdr, 1329 status = pjmedia_rtp_encode_rtp( &channel->rtp, 1330 0, 0, 1331 0, rtp_ts_len, 1332 (const void**)&rtphdr, 1335 1333 &rtphdrlen); 1336 1334 … … 1338 1336 1339 1337 if (status != PJ_SUCCESS) { 1340 LOGERR_((stream->port.info.name.ptr, 1338 LOGERR_((stream->port.info.name.ptr, 1341 1339 "RTP encode_rtp() error", status)); 1342 1340 return status; 1343 1341 } 1344 1342 1345 /* Check if now is the time to transmit RTCP SR/RR report. 1343 /* Check if now is the time to transmit RTCP SR/RR report. 1346 1344 * We only do this when stream direction is not "decoding only", because 1347 1345 * when it is, check_tx_rtcp() will be handled by get_frame(). … … 1414 1412 * RTP packet, and transmit to peer. 1415 1413 */ 1416 static pj_status_t put_frame( pjmedia_port *port, 1414 static pj_status_t put_frame( pjmedia_port *port, 1417 1415 pjmedia_frame *frame ) 1418 1416 { … … 1462 1460 */ 1463 1461 if (stream->vad_enabled != stream->codec_param.setting.vad && 1464 (stream->tx_duration - stream->ts_vad_disabled) > 1462 (stream->tx_duration - stream->ts_vad_disabled) > 1465 1463 PJMEDIA_PIA_SRATE(&stream->port.info) * 1466 1464 PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000) … … 1479 1477 pj_status_t status = PJ_SUCCESS; 1480 1478 1481 /* Copy original frame to temporary frame since we need 1479 /* Copy original frame to temporary frame since we need 1482 1480 * to modify it. 1483 1481 */ … … 1546 1544 * Handle incoming DTMF digits. 1547 1545 */ 1548 static void handle_incoming_dtmf( pjmedia_stream *stream, 1546 static void handle_incoming_dtmf( pjmedia_stream *stream, 1549 1547 const void *payload, unsigned payloadlen) 1550 1548 { … … 1572 1570 /* Ignore unknown event. */ 1573 1571 if (event->event > 15) { 1574 PJ_LOG(5,(stream->port.info.name.ptr, 1572 PJ_LOG(5,(stream->port.info.name.ptr, 1575 1573 "Ignored RTP pkt with bad DTMF event %d", 1576 1574 event->event)); … … 1591 1589 if (stream->dtmf_cb) { 1592 1590 1593 stream->dtmf_cb(stream, stream->dtmf_cb_user_data, 1591 stream->dtmf_cb(stream, stream->dtmf_cb_user_data, 1594 1592 digitmap[event->event]); 1595 1593 … … 1601 1599 if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 1602 1600 /* DTMF digits overflow. Discard the oldest digit. */ 1603 pj_array_erase(stream->rx_dtmf_buf, 1601 pj_array_erase(stream->rx_dtmf_buf, 1604 1602 sizeof(stream->rx_dtmf_buf[0]), 1605 1603 stream->rx_dtmf_count, 0); … … 1614 1612 /* 1615 1613 * This callback is called by stream transport on receipt of packets 1616 * in the RTP socket. 1617 */ 1618 static void on_rx_rtp( void *data, 1614 * in the RTP socket. 1615 */ 1616 static void on_rx_rtp( void *data, 1619 1617 void *pkt, 1620 1618 pj_ssize_t bytes_read) … … 1632 1630 /* Check for errors */ 1633 1631 if (bytes_read < 0) { 1634 LOGERR_((stream->port.info.name.ptr, "RTP recv() error", 1632 LOGERR_((stream->port.info.name.ptr, "RTP recv() error", 1635 1633 (pj_status_t)-bytes_read)); 1636 1634 return; … … 1660 1658 hdr->pt != stream->rx_event_pt); 1661 1659 if (seq_st.status.value) { 1662 TRC_ ((stream->port.info.name.ptr, 1660 TRC_ ((stream->port.info.name.ptr, 1663 1661 "RTP status: badpt=%d, badssrc=%d, dup=%d, " 1664 "outorder=%d, probation=%d, restart=%d", 1662 "outorder=%d, probation=%d, restart=%d", 1665 1663 seq_st.status.flag.badpt, 1666 1664 seq_st.status.flag.badssrc, … … 1737 1735 payloadlen, &ts, &count, frames); 1738 1736 if (status != PJ_SUCCESS) { 1739 LOGERR_((stream->port.info.name.ptr, 1740 "Codec parse() error", 1737 LOGERR_((stream->port.info.name.ptr, 1738 "Codec parse() error", 1741 1739 status)); 1742 1740 count = 0; … … 1746 1744 /* This code is used to learn the samples per frame value that is put 1747 1745 * by remote endpoint, for codecs with inconsistent clock rate such 1748 * as G.722 or MPEG audio. We need to learn the samples per frame 1746 * as G.722 or MPEG audio. We need to learn the samples per frame 1749 1747 * value as it is used as divider when inserting frames into the 1750 1748 * jitter buffer. … … 1752 1750 if (stream->has_g722_mpeg_bug) { 1753 1751 if (stream->rtp_rx_check_cnt) { 1754 /* Make sure the detection performed only on two consecutive 1752 /* Make sure the detection performed only on two consecutive 1755 1753 * packets with valid RTP sequence and no wrapped timestamp. 1756 1754 */ 1757 if (seq_st.diff == 1 && stream->rtp_rx_last_ts && 1758 ts.u64 > stream->rtp_rx_last_ts && 1755 if (seq_st.diff == 1 && stream->rtp_rx_last_ts && 1756 ts.u64 > stream->rtp_rx_last_ts && 1759 1757 stream->rtp_rx_last_cnt > 0) 1760 1758 { … … 1768 1766 1769 1767 /* Get remote frame timestamp span */ 1770 peer_frm_ts_diff = 1771 ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / 1768 peer_frm_ts_diff = 1769 ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / 1772 1770 stream->rtp_rx_last_cnt; 1773 1771 … … 1778 1776 */ 1779 1777 if (stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 && 1780 (peer_frm_ts_diff == frm_ts_span || 1778 (peer_frm_ts_diff == frm_ts_span || 1781 1779 peer_frm_ts_diff == (frm_ts_span>>1))) 1782 1780 { … … 1790 1788 if (--stream->rtp_rx_check_cnt == 0) { 1791 1789 PJ_LOG(4, (THIS_FILE, "G722 codec used, remote" 1792 " samples per frame detected = %d", 1790 " samples per frame detected = %d", 1793 1791 stream->rtp_rx_ts_len_per_frame)); 1794 1792 1795 1793 /* Reset jitter buffer once detection done */ 1796 1794 pjmedia_jbuf_reset(stream->jb); … … 1811 1809 1812 1810 } else { 1813 ts_span = stream->codec_param.info.frm_ptime * 1811 ts_span = stream->codec_param.info.frm_ptime * 1814 1812 stream->codec_param.info.clock_rate / 1815 1813 1000; 1816 1814 } 1817 1815 #else 1818 ts_span = stream->codec_param.info.frm_ptime * 1816 ts_span = stream->codec_param.info.frm_ptime * 1819 1817 stream->codec_param.info.clock_rate / 1820 1818 1000; … … 1842 1840 1843 1841 /* Check if now is the time to transmit RTCP SR/RR report. 1844 * We only do this when stream direction is "decoding only", 1842 * We only do this when stream direction is "decoding only", 1845 1843 * because otherwise check_tx_rtcp() will be handled by put_frame() 1846 1844 */ … … 1850 1848 1851 1849 if (status != 0) { 1852 LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", 1850 LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", 1853 1851 status)); 1854 1852 pkt_discarded = PJ_TRUE; … … 1880 1878 /* 1881 1879 * This callback is called by stream transport on receipt of packets 1882 * in the RTCP socket. 1880 * in the RTCP socket. 1883 1881 */ 1884 1882 static void on_rx_rtcp( void *data, 1885 void *pkt, 1883 void *pkt, 1886 1884 pj_ssize_t bytes_read) 1887 1885 { … … 1890 1888 /* Check for errors */ 1891 1889 if (bytes_read < 0) { 1892 LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", 1890 LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", 1893 1891 (pj_status_t)-bytes_read)); 1894 1892 return; … … 1911 1909 pjmedia_channel *channel; 1912 1910 pj_status_t status; 1913 1911 1914 1912 /* Allocate memory for channel descriptor */ 1915 1913 … … 1924 1922 channel->pt = pt; 1925 1923 1926 1924 1927 1925 /* Allocate buffer for outgoing packet. */ 1928 1926 1929 1927 if (param->type == PJMEDIA_TYPE_AUDIO) { 1930 channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 1931 stream->codec_param.info.max_bps * 1932 PJMEDIA_MAX_FRAME_DURATION_MS / 1928 channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 1929 stream->codec_param.info.max_bps * 1930 PJMEDIA_MAX_FRAME_DURATION_MS / 1933 1931 8 / 1000; 1934 1932 if (channel->out_pkt_size > PJMEDIA_MAX_MTU - … … 2078 2076 stream->codec_param = *info->param; 2079 2077 else { 2080 status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, 2081 &info->fmt, 2078 status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, 2079 &info->fmt, 2082 2080 &stream->codec_param); 2083 2081 if (status != PJ_SUCCESS) … … 2137 2135 /* If encoder and decoder's ptime are asymmetric, then we need to 2138 2136 * create buffer on the encoder side. This could happen for example 2139 * with iLBC 2137 * with iLBC 2140 2138 */ 2141 2139 if (stream->codec_param.info.enc_ptime!=0 && … … 2185 2183 stream->frame_size = stream->codec_param.info.max_rx_frame_size; 2186 2184 } else { 2187 stream->frame_size = stream->codec_param.info.max_bps * 2185 stream->frame_size = stream->codec_param.info.max_bps * 2188 2186 stream->codec_param.info.frm_ptime / 8 / 1000; 2189 2187 if ((stream->codec_param.info.max_bps * … … 2218 2216 /* Init jitter buffer parameters: */ 2219 2217 if (info->jb_max >= stream->codec_param.info.frm_ptime) 2220 jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / 2218 jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / 2221 2219 stream->codec_param.info.frm_ptime; 2222 2220 else … … 2243 2241 /* Create jitter buffer */ 2244 2242 status = pjmedia_jbuf_create(pool, &stream->port.info.name, 2245 stream->frame_size, 2243 stream->frame_size, 2246 2244 stream->codec_param.info.frm_ptime, 2247 2245 jb_max, &stream->jb); … … 2255 2253 /* Create decoder channel: */ 2256 2254 2257 status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 2255 status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 2258 2256 info->rx_pt, info, &stream->dec); 2259 2257 if (status != PJ_SUCCESS) … … 2263 2261 /* Create encoder channel: */ 2264 2262 2265 status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 2263 status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 2266 2264 info->tx_pt, info, &stream->enc); 2267 2265 if (status != PJ_SUCCESS) … … 2316 2314 2317 2315 /* Only attach transport when stream is ready. */ 2318 status = pjmedia_transport_attach(tp, stream, &info->rem_addr, 2319 &info->rem_rtcp, 2320 pj_sockaddr_get_len(&info->rem_addr), 2316 status = pjmedia_transport_attach(tp, stream, &info->rem_addr, 2317 &info->rem_rtcp, 2318 pj_sockaddr_get_len(&info->rem_addr), 2321 2319 &on_rx_rtp, &on_rx_rtcp); 2322 2320 if (status != PJ_SUCCESS) … … 2336 2334 stream->rtcp_xr_interval = info->rtcp_xr_interval; 2337 2335 else 2338 stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + 2339 (pj_rand() % 8000)) * 2336 stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + 2337 (pj_rand() % 8000)) * 2340 2338 info->fmt.clock_rate / 1000; 2341 2339 … … 2349 2347 /* jitter buffer adaptive info */ 2350 2348 i = PJMEDIA_RTCP_XR_JB_ADAPTIVE; 2351 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2349 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2352 2350 PJMEDIA_RTCP_XR_INFO_CONF_JBA, 2353 2351 i); … … 2355 2353 /* Jitter buffer aggressiveness info (estimated) */ 2356 2354 i = 7; 2357 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2355 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2358 2356 PJMEDIA_RTCP_XR_INFO_CONF_JBR, 2359 2357 i); … … 2361 2359 /* Jitter buffer absolute maximum delay */ 2362 2360 i = jb_max * stream->codec_param.info.frm_ptime; 2363 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2361 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2364 2362 PJMEDIA_RTCP_XR_INFO_JB_ABS_MAX, 2365 2363 i); … … 2374 2372 i = PJMEDIA_RTCP_XR_PLC_DIS; 2375 2373 #endif 2376 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2374 pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 2377 2375 PJMEDIA_RTCP_XR_INFO_CONF_PLC, 2378 2376 i); … … 2396 2394 pj_ssize_t len; 2397 2395 2398 pj_ansi_snprintf(trace_name, sizeof(trace_name), 2396 pj_ansi_snprintf(trace_name, sizeof(trace_name), 2399 2397 TRACE_JB_PATH_PREFIX "%s.csv", 2400 2398 stream->port.info.name.ptr); … … 2402 2400 if (status != PJ_SUCCESS) { 2403 2401 stream->trace_jb_fd = TRACE_JB_INVALID_FD; 2404 PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", 2402 PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", 2405 2403 trace_name)); 2406 2404 } else { … … 2490 2488 } 2491 2489 2492 /* Detach from transport 2490 /* Detach from transport 2493 2491 * MUST NOT hold stream mutex while detaching from transport, as 2494 2492 * it may cause deadlock. See ticket #460 for the details. … … 2513 2511 2514 2512 /* Free mutex */ 2515 2513 2516 2514 if (stream->jb_mutex) { 2517 2515 pj_mutex_destroy(stream->jb_mutex); … … 2724 2722 return PJMEDIA_RTP_EREMNORFC2833; 2725 2723 } 2726 2724 2727 2725 pj_mutex_lock(stream->jb_mutex); 2728 2726 2729 2727 if (stream->tx_dtmf_count+digit_char->slen >= 2730 2728 (long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) … … 2735 2733 2736 2734 /* convert ASCII digits into payload type first, to make sure 2737 * that all digits are valid. 2735 * that all digits are valid. 2738 2736 */ 2739 2737 for (i=0; i<digit_char->slen; ++i) { … … 2744 2742 { 2745 2743 pt = dig - '0'; 2746 } 2744 } 2747 2745 else if (dig >= 'a' && dig <= 'd') 2748 2746 { … … 2830 2828 */ 2831 2829 PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 2832 void (*cb)(pjmedia_stream*, 2833 void *user_data, 2834 int digit), 2830 void (*cb)(pjmedia_stream*, 2831 void *user_data, 2832 int digit), 2835 2833 void *user_data) 2836 2834 {
Note: See TracChangeset
for help on using the changeset viewer.