diff options
Diffstat (limited to 'pjmedia/src/pjmedia/stream.c')
-rw-r--r-- | pjmedia/src/pjmedia/stream.c | 298 |
1 files changed, 148 insertions, 150 deletions
diff --git a/pjmedia/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c index d051dc43..7ecb6388 100644 --- a/pjmedia/src/pjmedia/stream.c +++ b/pjmedia/src/pjmedia/stream.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <pjmedia/stream.h> #include <pjmedia/errno.h> @@ -184,16 +184,16 @@ struct pjmedia_stream * This happens for example with G.722 and MPEG audio codecs. */ pj_bool_t has_g722_mpeg_bug; - /**< Flag to specify whether - normalization process + /**< Flag to specify whether + normalization process is needed */ unsigned rtp_tx_ts_len_per_pkt; /**< Normalized ts length per packet - transmitted according to + transmitted according to 'erroneous' definition */ unsigned rtp_rx_ts_len_per_frame; /**< Normalized ts length per frame - received according to + received according to 'erroneous' definition */ unsigned rtp_rx_last_cnt;/**< Nb of frames in last pkt */ unsigned rtp_rx_check_cnt; @@ -202,11 +202,11 @@ struct pjmedia_stream #endif #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) - pj_uint32_t rtcp_xr_last_tx; /**< RTCP XR tx time + pj_uint32_t rtcp_xr_last_tx; /**< RTCP XR tx time in timestamp. */ pj_uint32_t rtcp_xr_interval; /**< Interval, in timestamp. */ - pj_sockaddr rtcp_xr_dest; /**< Additional remote RTCP XR - dest. If sin_family is + pj_sockaddr rtcp_xr_dest; /**< Additional remote RTCP XR + dest. If sin_family is zero, it will be ignored*/ unsigned rtcp_xr_dest_len; /**< Length of RTCP XR dest address */ @@ -230,8 +230,8 @@ struct pjmedia_stream /* RFC 2833 digit */ -static const char digitmap[16] = { '0', '1', '2', '3', - '4', '5', '6', '7', +static const char digitmap[16] = { '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '*', '#', 'A', 'B', 'C', 'D'}; @@ -284,7 +284,7 @@ PJ_INLINE(int) trace_jb_print_timestamp(char **buf, pj_ssize_t len) return 0; } -PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, +PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, char **buf, pj_ssize_t len) { char *p = *buf; @@ -459,7 +459,7 @@ static void send_keep_alive_packet(pjmedia_stream *stream) pkt_len); #else - + PJ_UNUSED_ARG(stream); #endif @@ -497,12 +497,12 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) samples_required = PJMEDIA_PIA_SPF(&stream->port.info); samples_per_frame = stream->codec_param.info.frm_ptime * stream->codec_param.info.clock_rate * - stream->codec_param.info.channel_cnt / + stream->codec_param.info.channel_cnt / 1000; p_out_samp = (pj_int16_t*) frame->buf; - for (samples_count=0; samples_count < samples_required; - samples_count += samples_per_frame) + for (samples_count=0; samples_count < samples_required; + samples_count += samples_per_frame) { char frame_type; pj_size_t frame_size; @@ -517,11 +517,11 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) #endif if (frame_type == PJMEDIA_JB_MISSING_FRAME) { - + /* Activate PLC */ - if (stream->codec->op->recover && + if (stream->codec->op->recover && stream->codec_param.setting.plc && - stream->plc_cnt < stream->max_plc_cnt) + stream->plc_cnt < stream->max_plc_cnt) { pjmedia_frame frame_out; @@ -560,16 +560,16 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) /* Jitter buffer is empty. If this is the first "empty" state, * activate PLC to smoothen the fade-out, otherwise zero - * the frame. + * the frame. */ //Using this "if" will only invoke PLC for the first packet //lost and not the subsequent ones. //if (frame_type != stream->jb_last_frm) { if (1) { /* Activate PLC to smoothen the missing frame */ - if (stream->codec->op->recover && + if (stream->codec->op->recover && stream->codec_param.setting.plc && - stream->plc_cnt < stream->max_plc_cnt) + stream->plc_cnt < stream->max_plc_cnt) { pjmedia_frame frame_out; @@ -589,7 +589,7 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) stream->plc_cnt < stream->max_plc_cnt); with_plc = ", plc invoked"; - } + } } if (samples_count < samples_required) { @@ -603,8 +603,8 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) /* Report changing frame type event */ pjmedia_jbuf_get_state(stream->jb, &jb_state); - PJ_LOG(5,(stream->port.info.name.ptr, - "Jitter buffer empty (prefetch=%d)%s", + PJ_LOG(5,(stream->port.info.name.ptr, + "Jitter buffer empty (prefetch=%d)%s", jb_state.prefetch, with_plc)); stream->jb_last_frm = frame_type; @@ -622,9 +622,9 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) pj_assert(frame_type == PJMEDIA_JB_ZERO_PREFETCH_FRAME); /* Always activate PLC when it's available.. */ - if (stream->codec->op->recover && + if (stream->codec->op->recover && stream->codec_param.setting.plc && - stream->plc_cnt < stream->max_plc_cnt) + stream->plc_cnt < stream->max_plc_cnt) { pjmedia_frame frame_out; @@ -644,7 +644,7 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) stream->plc_cnt < stream->max_plc_cnt); with_plc = ", plc invoked"; - } + } if (samples_count < samples_required) { pjmedia_zero_samples(p_out_samp + samples_count, @@ -657,8 +657,8 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) /* Report changing frame type event */ pjmedia_jbuf_get_state(stream->jb, &jb_state); - PJ_LOG(5,(stream->port.info.name.ptr, - "Jitter buffer is bufferring (prefetch=%d)%s", + PJ_LOG(5,(stream->port.info.name.ptr, + "Jitter buffer is bufferring (prefetch=%d)%s", jb_state.prefetch, with_plc)); stream->jb_last_frm = frame_type; @@ -683,19 +683,19 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame) frame_out.buf = p_out_samp + samples_count; frame_out.size = frame->size - samples_count*BYTES_PER_SAMPLE; status = pjmedia_codec_decode( stream->codec, &frame_in, - (unsigned)frame_out.size, + (unsigned)frame_out.size, &frame_out); if (status != 0) { - LOGERR_((port->info.name.ptr, "codec decode() error", + LOGERR_((port->info.name.ptr, "codec decode() error", status)); - pjmedia_zero_samples(p_out_samp + samples_count, + pjmedia_zero_samples(p_out_samp + samples_count, samples_per_frame); } if (stream->jb_last_frm != frame_type) { /* Report changing frame type event */ - PJ_LOG(5,(stream->port.info.name.ptr, + PJ_LOG(5,(stream->port.info.name.ptr, "Jitter buffer starts returning normal frames " "(after %d empty/lost)", stream->jb_last_frm_cnt, stream->jb_last_frm)); @@ -752,7 +752,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) samples_required = PJMEDIA_PIA_SPF(&stream->port.info); samples_per_frame = stream->codec_param.info.frm_ptime * stream->codec_param.info.clock_rate * - stream->codec_param.info.channel_cnt / + stream->codec_param.info.channel_cnt / 1000; pj_bzero(f, sizeof(pjmedia_frame_ext)); @@ -773,7 +773,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) #if TRACE_JB trace_jb_get(stream, frame_type, frame_size); #endif - + /* Unlock jitter buffer mutex. */ pj_mutex_unlock( stream->jb_mutex ); @@ -790,7 +790,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) status = pjmedia_codec_decode( stream->codec, &frame_in, 0, frame); if (status != PJ_SUCCESS) { - LOGERR_((port->info.name.ptr, "codec decode() error", + LOGERR_((port->info.name.ptr, "codec decode() error", status)); pjmedia_frame_ext_append_subframe(f, NULL, 0, (pj_uint16_t)samples_per_frame); @@ -798,7 +798,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) if (stream->jb_last_frm != frame_type) { /* Report changing frame type event */ - PJ_LOG(5,(stream->port.info.name.ptr, + PJ_LOG(5,(stream->port.info.name.ptr, "Jitter buffer starts returning normal frames " "(after %d empty/lost)", stream->jb_last_frm_cnt, stream->jb_last_frm)); @@ -816,7 +816,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) if (stream->codec->op->recover) { status = pjmedia_codec_recover(stream->codec, 0, frame); } - + /* No PLC or PLC failed */ if (!stream->codec->op->recover || status != PJ_SUCCESS) { pjmedia_frame_ext_append_subframe(f, NULL, 0, @@ -839,8 +839,8 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) /* Report changing frame type event */ pjmedia_jbuf_get_state(stream->jb, &jb_state); - PJ_LOG(5,(stream->port.info.name.ptr, - "Jitter buffer empty (prefetch=%d)", + PJ_LOG(5,(stream->port.info.name.ptr, + "Jitter buffer empty (prefetch=%d)", jb_state.prefetch)); stream->jb_last_frm = frame_type; @@ -858,7 +858,7 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) /* Report changing frame type event */ pjmedia_jbuf_get_state(stream->jb, &jb_state); - PJ_LOG(5,(stream->port.info.name.ptr, + PJ_LOG(5,(stream->port.info.name.ptr, "Jitter buffer is bufferring (prefetch=%d)", jb_state.prefetch)); @@ -878,23 +878,21 @@ static pj_status_t get_frame_ext( pjmedia_port *port, pjmedia_frame *frame) /* * Transmit DTMF */ -static void create_dtmf_payload(pjmedia_stream *stream, +static void create_dtmf_payload(pjmedia_stream *stream, struct pjmedia_frame *frame_out, int forced_last, int *first, int *last) { pjmedia_rtp_dtmf_event *event; struct dtmf *digit = &stream->tx_dtmf_buf[0]; - pj_uint32_t cur_ts; pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4); *first = *last = 0; event = (pjmedia_rtp_dtmf_event*) frame_out->buf; - cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts); if (digit->duration == 0) { - PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", + PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", digitmap[digit->event])); *first = 1; } @@ -987,14 +985,14 @@ static pj_status_t send_rtcp(pjmedia_stream *stream, /* Update RTCP XR with current JB states */ pjmedia_jbuf_get_state(stream->jb, &jb_state); - + i = jb_state.avg_delay; - status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_JB_NOM, i); pj_assert(status == PJ_SUCCESS); i = jb_state.max_delay; - status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_JB_MAX, i); pj_assert(status == PJ_SUCCESS); @@ -1007,9 +1005,9 @@ static pj_status_t send_rtcp(pjmedia_stream *stream, /* Send the RTCP XR to third-party destination if specified */ if (stream->rtcp_xr_dest_len) { - pjmedia_transport_send_rtcp2(stream->transport, + pjmedia_transport_send_rtcp2(stream->transport, &stream->rtcp_xr_dest, - stream->rtcp_xr_dest_len, + stream->rtcp_xr_dest_len, xr_pkt, xr_len); } @@ -1049,13 +1047,13 @@ static pj_status_t send_rtcp(pjmedia_stream *stream, */ static void check_tx_rtcp(pjmedia_stream *stream, pj_uint32_t timestamp) { - /* Note that timestamp may represent local or remote timestamp, + /* Note that timestamp may represent local or remote timestamp, * depending on whether this function is called from put_frame() * or get_frame(). */ if (stream->rtcp_last_tx == 0) { - + stream->rtcp_last_tx = timestamp; } else if (timestamp - stream->rtcp_last_tx >= stream->rtcp_interval) { @@ -1066,7 +1064,7 @@ static void check_tx_rtcp(pjmedia_stream *stream, pj_uint32_t timestamp) if (stream->rtcp.xr_enabled) { if (stream->rtcp_xr_last_tx == 0) { stream->rtcp_xr_last_tx = timestamp; - } else if (timestamp - stream->rtcp_xr_last_tx >= + } else if (timestamp - stream->rtcp_xr_last_tx >= stream->rtcp_xr_interval) { with_xr = PJ_TRUE; @@ -1130,7 +1128,7 @@ static void rebuffer(pjmedia_stream *stream, } /* How many samples are needed */ - count = stream->codec_param.info.enc_ptime * + count = stream->codec_param.info.enc_ptime * PJMEDIA_PIA_SRATE(&stream->port.info) / 1000; /* See if we have enough samples */ @@ -1153,7 +1151,7 @@ static void rebuffer(pjmedia_stream *stream, /** * put_frame_imp() */ -static pj_status_t put_frame_imp( pjmedia_port *port, +static pj_status_t put_frame_imp( pjmedia_port *port, pjmedia_frame *frame ) { pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; @@ -1174,7 +1172,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, { pj_uint32_t dtx_duration; - dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, + dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, &frame->timestamp); if (dtx_duration > PJMEDIA_STREAM_KA_INTERVAL * PJMEDIA_PIA_SRATE(&stream->port.info)) @@ -1193,7 +1191,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, /* Number of samples in the frame */ if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) - ts_len = ((unsigned)frame->size >> 1) / + ts_len = ((unsigned)frame->size >> 1) / stream->codec_param.info.channel_cnt; else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) ts_len = PJMEDIA_PIA_SPF(&stream->port.info) / @@ -1205,7 +1203,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, stream->tx_duration += ts_len; #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0) - /* Handle special case for audio codec with RTP timestamp inconsistence + /* Handle special case for audio codec with RTP timestamp inconsistence * e.g: G722, MPEG audio. */ if (stream->has_g722_mpeg_bug) @@ -1224,7 +1222,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, samples_per_frame = stream->enc_samples_per_pkt; - /* If we have DTMF digits in the queue, transmit the digits. + /* If we have DTMF digits in the queue, transmit the digits. * Otherwise encode the PCM buffer. */ if (stream->tx_dtmf_count) { @@ -1234,17 +1232,17 @@ static pj_status_t put_frame_imp( pjmedia_port *port, /* Encapsulate into RTP packet. Note that: * - RTP marker should be set on the beginning of a new event - * - RTP timestamp is constant for the same packet. + * - RTP timestamp is constant for the same packet. */ - status = pjmedia_rtp_encode_rtp( &channel->rtp, - stream->tx_event_pt, first, + status = pjmedia_rtp_encode_rtp( &channel->rtp, + stream->tx_event_pt, first, (int)frame_out.size, - (first ? rtp_ts_len : 0), - (const void**)&rtphdr, + (first ? rtp_ts_len : 0), + (const void**)&rtphdr, &rtphdrlen); if (last) { - /* This is the last packet for the event. + /* This is the last packet for the event. * Increment the RTP timestamp of the RTP session, for next * RTP packets. */ @@ -1271,7 +1269,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, stream->codec_param.info.frm_ptime * stream->codec_param.info.channel_cnt * stream->codec_param.info.clock_rate/1000 < - PJ_ARRAY_SIZE(zero_frame)) + PJ_ARRAY_SIZE(zero_frame)) { pjmedia_frame silence_frame; @@ -1282,23 +1280,23 @@ static pj_status_t put_frame_imp( pjmedia_port *port, stream->codec_param.info.clock_rate / 1000; silence_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; silence_frame.timestamp.u32.lo = pj_ntohl(stream->enc->rtp.out_hdr.ts); - + /* Encode! */ status = pjmedia_codec_encode( stream->codec, &silence_frame, - channel->out_pkt_size - + channel->out_pkt_size - sizeof(pjmedia_rtp_hdr), &frame_out); if (status != PJ_SUCCESS) { - LOGERR_((stream->port.info.name.ptr, + LOGERR_((stream->port.info.name.ptr, "Codec encode() error", status)); return status; } /* Encapsulate. */ - status = pjmedia_rtp_encode_rtp( &channel->rtp, - channel->pt, 0, - (int)frame_out.size, rtp_ts_len, - (const void**)&rtphdr, + status = pjmedia_rtp_encode_rtp( &channel->rtp, + channel->pt, 0, + (int)frame_out.size, rtp_ts_len, + (const void**)&rtphdr, &rtphdrlen); @@ -1308,41 +1306,41 @@ static pj_status_t put_frame_imp( pjmedia_port *port, (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED)) { /* Encode! */ - status = pjmedia_codec_encode( stream->codec, frame, - channel->out_pkt_size - + status = pjmedia_codec_encode( stream->codec, frame, + channel->out_pkt_size - sizeof(pjmedia_rtp_hdr), &frame_out); if (status != PJ_SUCCESS) { - LOGERR_((stream->port.info.name.ptr, + LOGERR_((stream->port.info.name.ptr, "Codec encode() error", status)); return status; } /* Encapsulate. */ - status = pjmedia_rtp_encode_rtp( &channel->rtp, - channel->pt, 0, - (int)frame_out.size, rtp_ts_len, - (const void**)&rtphdr, + status = pjmedia_rtp_encode_rtp( &channel->rtp, + channel->pt, 0, + (int)frame_out.size, rtp_ts_len, + (const void**)&rtphdr, &rtphdrlen); } else { /* Just update RTP session's timestamp. */ - status = pjmedia_rtp_encode_rtp( &channel->rtp, - 0, 0, - 0, rtp_ts_len, - (const void**)&rtphdr, + status = pjmedia_rtp_encode_rtp( &channel->rtp, + 0, 0, + 0, rtp_ts_len, + (const void**)&rtphdr, &rtphdrlen); } if (status != PJ_SUCCESS) { - LOGERR_((stream->port.info.name.ptr, + LOGERR_((stream->port.info.name.ptr, "RTP encode_rtp() error", status)); return status; } - /* Check if now is the time to transmit RTCP SR/RR report. + /* Check if now is the time to transmit RTCP SR/RR report. * We only do this when stream direction is not "decoding only", because * when it is, check_tx_rtcp() will be handled by get_frame(). */ @@ -1413,7 +1411,7 @@ static pj_status_t put_frame_imp( pjmedia_port *port, * to transmit. This function encodes the PCM frame, pack it into * RTP packet, and transmit to peer. */ -static pj_status_t put_frame( pjmedia_port *port, +static pj_status_t put_frame( pjmedia_port *port, pjmedia_frame *frame ) { pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata; @@ -1461,7 +1459,7 @@ static pj_status_t put_frame( pjmedia_port *port, * after transmitting for VAD_SUSPEND_SEC seconds. */ if (stream->vad_enabled != stream->codec_param.setting.vad && - (stream->tx_duration - stream->ts_vad_disabled) > + (stream->tx_duration - stream->ts_vad_disabled) > PJMEDIA_PIA_SRATE(&stream->port.info) * PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000) { @@ -1478,7 +1476,7 @@ static pj_status_t put_frame( pjmedia_port *port, pjmedia_frame tmp_rebuffer_frame; pj_status_t status = PJ_SUCCESS; - /* Copy original frame to temporary frame since we need + /* Copy original frame to temporary frame since we need * to modify it. */ pj_memcpy(&tmp_rebuffer_frame, frame, sizeof(pjmedia_frame)); @@ -1545,7 +1543,7 @@ static void dump_bin(const char *buf, unsigned len) /* * Handle incoming DTMF digits. */ -static void handle_incoming_dtmf( pjmedia_stream *stream, +static void handle_incoming_dtmf( pjmedia_stream *stream, const void *payload, unsigned payloadlen) { pjmedia_rtp_dtmf_event *event = (pjmedia_rtp_dtmf_event*) payload; @@ -1571,7 +1569,7 @@ static void handle_incoming_dtmf( pjmedia_stream *stream, /* Ignore unknown event. */ if (event->event > 15) { - PJ_LOG(5,(stream->port.info.name.ptr, + PJ_LOG(5,(stream->port.info.name.ptr, "Ignored RTP pkt with bad DTMF event %d", event->event)); return; @@ -1590,7 +1588,7 @@ static void handle_incoming_dtmf( pjmedia_stream *stream, */ if (stream->dtmf_cb) { - stream->dtmf_cb(stream, stream->dtmf_cb_user_data, + stream->dtmf_cb(stream, stream->dtmf_cb_user_data, digitmap[event->event]); } else { @@ -1600,7 +1598,7 @@ static void handle_incoming_dtmf( pjmedia_stream *stream, pj_mutex_lock(stream->jb_mutex); if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { /* DTMF digits overflow. Discard the oldest digit. */ - pj_array_erase(stream->rx_dtmf_buf, + pj_array_erase(stream->rx_dtmf_buf, sizeof(stream->rx_dtmf_buf[0]), stream->rx_dtmf_count, 0); --stream->rx_dtmf_count; @@ -1613,9 +1611,9 @@ static void handle_incoming_dtmf( pjmedia_stream *stream, /* * This callback is called by stream transport on receipt of packets - * in the RTP socket. + * in the RTP socket. */ -static void on_rx_rtp( void *data, +static void on_rx_rtp( void *data, void *pkt, pj_ssize_t bytes_read) @@ -1631,7 +1629,7 @@ static void on_rx_rtp( void *data, /* Check for errors */ if (bytes_read < 0) { - LOGERR_((stream->port.info.name.ptr, "RTP recv() error", + LOGERR_((stream->port.info.name.ptr, "RTP recv() error", (pj_status_t)-bytes_read)); return; } @@ -1659,9 +1657,9 @@ static void on_rx_rtp( void *data, pjmedia_rtp_session_update2(&channel->rtp, hdr, &seq_st, hdr->pt != stream->rx_event_pt); if (seq_st.status.value) { - TRC_ ((stream->port.info.name.ptr, + TRC_ ((stream->port.info.name.ptr, "RTP status: badpt=%d, badssrc=%d, dup=%d, " - "outorder=%d, probation=%d, restart=%d", + "outorder=%d, probation=%d, restart=%d", seq_st.status.flag.badpt, seq_st.status.flag.badssrc, seq_st.status.flag.dup, @@ -1736,8 +1734,8 @@ static void on_rx_rtp( void *data, status = pjmedia_codec_parse(stream->codec, (void*)payload, payloadlen, &ts, &count, frames); if (status != PJ_SUCCESS) { - LOGERR_((stream->port.info.name.ptr, - "Codec parse() error", + LOGERR_((stream->port.info.name.ptr, + "Codec parse() error", status)); count = 0; } @@ -1745,17 +1743,17 @@ static void on_rx_rtp( void *data, #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0) /* This code is used to learn the samples per frame value that is put * by remote endpoint, for codecs with inconsistent clock rate such - * as G.722 or MPEG audio. We need to learn the samples per frame + * as G.722 or MPEG audio. We need to learn the samples per frame * value as it is used as divider when inserting frames into the * jitter buffer. */ if (stream->has_g722_mpeg_bug) { if (stream->rtp_rx_check_cnt) { - /* Make sure the detection performed only on two consecutive + /* Make sure the detection performed only on two consecutive * packets with valid RTP sequence and no wrapped timestamp. */ - if (seq_st.diff == 1 && stream->rtp_rx_last_ts && - ts.u64 > stream->rtp_rx_last_ts && + if (seq_st.diff == 1 && stream->rtp_rx_last_ts && + ts.u64 > stream->rtp_rx_last_ts && stream->rtp_rx_last_cnt > 0) { unsigned peer_frm_ts_diff; @@ -1767,8 +1765,8 @@ static void on_rx_rtp( void *data, PJMEDIA_PIA_CCNT(&stream->port.info); /* Get remote frame timestamp span */ - peer_frm_ts_diff = - ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / + peer_frm_ts_diff = + ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / stream->rtp_rx_last_cnt; /* Possibilities remote's samples per frame for G.722 @@ -1777,7 +1775,7 @@ static void on_rx_rtp( void *data, * of silence frames. */ if (stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 && - (peer_frm_ts_diff == frm_ts_span || + (peer_frm_ts_diff == frm_ts_span || peer_frm_ts_diff == (frm_ts_span>>1))) { if (peer_frm_ts_diff < stream->rtp_rx_ts_len_per_frame) @@ -1789,9 +1787,9 @@ static void on_rx_rtp( void *data, if (--stream->rtp_rx_check_cnt == 0) { PJ_LOG(4, (THIS_FILE, "G722 codec used, remote" - " samples per frame detected = %d", + " samples per frame detected = %d", stream->rtp_rx_ts_len_per_frame)); - + /* Reset jitter buffer once detection done */ pjmedia_jbuf_reset(stream->jb); } @@ -1810,12 +1808,12 @@ static void on_rx_rtp( void *data, } } else { - ts_span = stream->codec_param.info.frm_ptime * + ts_span = stream->codec_param.info.frm_ptime * stream->codec_param.info.clock_rate / 1000; } #else - ts_span = stream->codec_param.info.frm_ptime * + ts_span = stream->codec_param.info.frm_ptime * stream->codec_param.info.clock_rate / 1000; #endif @@ -1841,7 +1839,7 @@ static void on_rx_rtp( void *data, /* Check if now is the time to transmit RTCP SR/RR report. - * We only do this when stream direction is "decoding only", + * We only do this when stream direction is "decoding only", * because otherwise check_tx_rtcp() will be handled by put_frame() */ if (stream->dir == PJMEDIA_DIR_DECODING) { @@ -1849,7 +1847,7 @@ static void on_rx_rtp( void *data, } if (status != 0) { - LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", + LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", status)); pkt_discarded = PJ_TRUE; goto on_return; @@ -1879,17 +1877,17 @@ on_return: /* * This callback is called by stream transport on receipt of packets - * in the RTCP socket. + * in the RTCP socket. */ static void on_rx_rtcp( void *data, - void *pkt, + void *pkt, pj_ssize_t bytes_read) { pjmedia_stream *stream = (pjmedia_stream*) data; /* Check for errors */ if (bytes_read < 0) { - LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", + LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", (pj_status_t)-bytes_read)); return; } @@ -1910,7 +1908,7 @@ static pj_status_t create_channel( pj_pool_t *pool, { pjmedia_channel *channel; pj_status_t status; - + /* Allocate memory for channel descriptor */ channel = PJ_POOL_ZALLOC_T(pool, pjmedia_channel); @@ -1923,13 +1921,13 @@ static pj_status_t create_channel( pj_pool_t *pool, channel->paused = 1; channel->pt = pt; - + /* Allocate buffer for outgoing packet. */ if (param->type == PJMEDIA_TYPE_AUDIO) { - channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + - stream->codec_param.info.max_bps * - PJMEDIA_MAX_FRAME_DURATION_MS / + channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + + stream->codec_param.info.max_bps * + PJMEDIA_MAX_FRAME_DURATION_MS / 8 / 1000; if (channel->out_pkt_size > PJMEDIA_MAX_MTU - PJMEDIA_STREAM_RESV_PAYLOAD_LEN) @@ -2077,8 +2075,8 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, if (info->param) stream->codec_param = *info->param; else { - status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, - &info->fmt, + status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, + &info->fmt, &stream->codec_param); if (status != PJ_SUCCESS) goto err_cleanup; @@ -2136,7 +2134,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* If encoder and decoder's ptime are asymmetric, then we need to * create buffer on the encoder side. This could happen for example - * with iLBC + * with iLBC */ if (stream->codec_param.info.enc_ptime!=0 && stream->codec_param.info.enc_ptime!=stream->codec_param.info.frm_ptime) @@ -2184,7 +2182,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, if (stream->codec_param.info.max_rx_frame_size > 0) { stream->frame_size = stream->codec_param.info.max_rx_frame_size; } else { - stream->frame_size = stream->codec_param.info.max_bps * + stream->frame_size = stream->codec_param.info.max_bps * stream->codec_param.info.frm_ptime / 8 / 1000; if ((stream->codec_param.info.max_bps * stream->codec_param.info.frm_ptime) % 8000 != 0) @@ -2217,7 +2215,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* Init jitter buffer parameters: */ if (info->jb_max >= stream->codec_param.info.frm_ptime) - jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / + jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / stream->codec_param.info.frm_ptime; else jb_max = 500 / stream->codec_param.info.frm_ptime; @@ -2242,7 +2240,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* Create jitter buffer */ status = pjmedia_jbuf_create(pool, &stream->port.info.name, - stream->frame_size, + stream->frame_size, stream->codec_param.info.frm_ptime, jb_max, &stream->jb); if (status != PJ_SUCCESS) @@ -2254,7 +2252,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* Create decoder channel: */ - status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, + status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, info->rx_pt, info, &stream->dec); if (status != PJ_SUCCESS) goto err_cleanup; @@ -2262,7 +2260,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* Create encoder channel: */ - status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, + status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, info->tx_pt, info, &stream->enc); if (status != PJ_SUCCESS) goto err_cleanup; @@ -2315,9 +2313,9 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, stream->out_rtcp_pkt = pj_pool_alloc(pool, stream->out_rtcp_pkt_size); /* Only attach transport when stream is ready. */ - status = pjmedia_transport_attach(tp, stream, &info->rem_addr, - &info->rem_rtcp, - pj_sockaddr_get_len(&info->rem_addr), + status = pjmedia_transport_attach(tp, stream, &info->rem_addr, + &info->rem_rtcp, + pj_sockaddr_get_len(&info->rem_addr), &on_rx_rtp, &on_rx_rtcp); if (status != PJ_SUCCESS) goto err_cleanup; @@ -2335,8 +2333,8 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, if (info->rtcp_xr_interval != 0) stream->rtcp_xr_interval = info->rtcp_xr_interval; else - stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + - (pj_rand() % 8000)) * + stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + + (pj_rand() % 8000)) * info->fmt.clock_rate / 1000; /* Additional third-party RTCP XR destination */ @@ -2348,19 +2346,19 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, /* jitter buffer adaptive info */ i = PJMEDIA_RTCP_XR_JB_ADAPTIVE; - pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_CONF_JBA, i); /* Jitter buffer aggressiveness info (estimated) */ i = 7; - pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_CONF_JBR, i); /* Jitter buffer absolute maximum delay */ i = jb_max * stream->codec_param.info.frm_ptime; - pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_JB_ABS_MAX, i); @@ -2373,7 +2371,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, #else i = PJMEDIA_RTCP_XR_PLC_DIS; #endif - pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, + pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, PJMEDIA_RTCP_XR_INFO_CONF_PLC, i); } @@ -2395,13 +2393,13 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt, char trace_name[PJ_MAXPATH]; pj_ssize_t len; - pj_ansi_snprintf(trace_name, sizeof(trace_name), + pj_ansi_snprintf(trace_name, sizeof(trace_name), TRACE_JB_PATH_PREFIX "%s.csv", stream->port.info.name.ptr); status = pj_file_open(pool, trace_name, PJ_O_WRONLY, &stream->trace_jb_fd); if (status != PJ_SUCCESS) { stream->trace_jb_fd = TRACE_JB_INVALID_FD; - PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", + PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", trace_name)); } else { stream->trace_jb_buf = (char*)pj_pool_alloc(pool, PJ_LOG_MAX_SIZE); @@ -2489,7 +2487,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_destroy( pjmedia_stream *stream ) } } - /* Detach from transport + /* Detach from transport * MUST NOT hold stream mutex while detaching from transport, as * it may cause deadlock. See ticket #460 for the details. */ @@ -2512,7 +2510,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_destroy( pjmedia_stream *stream ) } /* Free mutex */ - + if (stream->jb_mutex) { pj_mutex_destroy(stream->jb_mutex); stream->jb_mutex = NULL; @@ -2723,9 +2721,9 @@ PJ_DEF(pj_status_t) pjmedia_stream_dial_dtmf( pjmedia_stream *stream, if (stream->tx_event_pt < 0) { return PJMEDIA_RTP_EREMNORFC2833; } - + pj_mutex_lock(stream->jb_mutex); - + if (stream->tx_dtmf_count+digit_char->slen >= (long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) { @@ -2734,7 +2732,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_dial_dtmf( pjmedia_stream *stream, int i; /* convert ASCII digits into payload type first, to make sure - * that all digits are valid. + * that all digits are valid. */ for (i=0; i<digit_char->slen; ++i) { unsigned pt; @@ -2743,7 +2741,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_dial_dtmf( pjmedia_stream *stream, if (dig >= '0' && dig <= '9') { pt = dig - '0'; - } + } else if (dig >= 'a' && dig <= 'd') { pt = dig - 'a' + 12; @@ -2829,9 +2827,9 @@ PJ_DEF(pj_status_t) pjmedia_stream_get_dtmf( pjmedia_stream *stream, * Set callback to be called upon receiving DTMF digits. */ PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, - void (*cb)(pjmedia_stream*, - void *user_data, - int digit), + void (*cb)(pjmedia_stream*, + void *user_data, + int digit), void *user_data) { PJ_ASSERT_RETURN(stream, PJ_EINVAL); |