diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 4523105b10..55bd3d78c3 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -202,22 +202,23 @@ SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp *rtp_session, swit \brief Read data from a given RTP session \param rtp_session the RTP session to read from \param data the data to read - \param datalen the length of the data + \param datalen a pointer to the datalen \param payload_type the IANA payload of the packet \param flags flags \return the number of bytes read */ -SWITCH_DECLARE(int) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type, switch_frame_flag *flags); +SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags); /*! \brief Read data from a given RTP session without copying \param rtp_session the RTP session to read from \param data a pointer to point directly to the RTP read buffer + \param datalen a pointer to the datalen \param payload_type the IANA payload of the packet \param flags flags \return the number of bytes read */ -SWITCH_DECLARE(int) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type, switch_frame_flag *flags); +SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags); /*! \brief Write data to a given RTP session diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 201db84095..26026f95f9 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -573,8 +573,15 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { payload = -1; tech_pvt->read_frame.flags = 0; - tech_pvt->read_frame.datalen = switch_rtp_zerocopy_read(tech_pvt->rtp_session, &tech_pvt->read_frame.data, &payload, &tech_pvt->read_frame.flags); - + + if (switch_rtp_zerocopy_read(tech_pvt->rtp_session, + &tech_pvt->read_frame.data, + &tech_pvt->read_frame.datalen, + &payload, + &tech_pvt->read_frame.flags) != SWITCH_STATUS_SUCCESS) { + + return SWITCH_STATUS_FALSE; + } /* RFC2833 ... TBD try harder to honor the duration etc.*/ if (payload == 101) { diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index fc32fc0a4a..773bef17be 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -584,9 +584,12 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram && tech_pvt->read_frame.datalen == 0) { now = switch_time_now(); tech_pvt->read_frame.flags = 0; - tech_pvt->read_frame.datalen = switch_rtp_zerocopy_read(tech_pvt->rtp_session, &tech_pvt->read_frame.data, &payload, &tech_pvt->read_frame.flags); - - if (tech_pvt->read_frame.datalen < 0) { + if (switch_rtp_zerocopy_read(tech_pvt->rtp_session, + &tech_pvt->read_frame.data, + &tech_pvt->read_frame.datalen, + &payload, + &tech_pvt->read_frame.flags) != SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_FALSE; } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 26b80cb0c6..8577722349 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -534,29 +534,36 @@ static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_typ return (int)(bytes - rtp_header_len); } -SWITCH_DECLARE(int) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t datalen, int *payload_type, switch_frame_flag *flags) +SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags) { int bytes = rtp_common_read(rtp_session, data, payload_type, flags); if (bytes <= 0) { - return bytes; + *datalen = 0; + return SWITCH_STATUS_GENERR; } + + *datalen = bytes; + memcpy(data, rtp_session->recv_msg.body, bytes); - return bytes; + + return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(int) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, int *payload_type, switch_frame_flag *flags) +SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags) { int bytes = rtp_common_read(rtp_session, data, payload_type, flags); *data = rtp_session->recv_msg.body; if (bytes <= 0) { - return bytes; + *datalen = 0; + return SWITCH_STATUS_GENERR; } - return bytes; + *datalen = bytes; + return SWITCH_STATUS_SUCCESS; } static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint8_t payload)