\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
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) {
&& 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;
}
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)