2006-04-03 21:00:13 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_channel.h -- Media Channel Interface
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file switch_rtp.h
|
|
|
|
* @brief RTP
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SWITCH_RTP_H
|
|
|
|
#define SWITCH_RTP_H
|
|
|
|
|
2006-04-28 20:04:08 +00:00
|
|
|
BEGIN_EXTERN_C
|
2006-04-03 21:00:13 +00:00
|
|
|
|
2006-04-06 19:50:53 +00:00
|
|
|
#define SWITCH_RTP_MAX_BUF_LEN 16384
|
2006-04-03 21:00:13 +00:00
|
|
|
|
2006-04-06 03:15:41 +00:00
|
|
|
///\defgroup rtp RTP (RealTime Transport Protocol)
|
2006-04-06 02:47:11 +00:00
|
|
|
///\ingroup core1
|
|
|
|
///\{
|
2006-04-29 01:00:52 +00:00
|
|
|
typedef void (*switch_rtp_invalid_handler)(switch_rtp_t *rtp_session,
|
2006-04-04 02:28:11 +00:00
|
|
|
switch_socket_t *sock,
|
2006-04-03 21:00:13 +00:00
|
|
|
void *data,
|
2006-04-04 04:46:49 +00:00
|
|
|
switch_size_t datalen,
|
2006-04-04 02:28:11 +00:00
|
|
|
switch_sockaddr_t *from_addr);
|
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Initilize the RTP System
|
|
|
|
\param pool the memory pool to use for long term allocations
|
|
|
|
\note Generally called by the core_init
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Request a new port to be used for media
|
|
|
|
\return the new port to use
|
|
|
|
*/
|
2006-04-05 20:17:22 +00:00
|
|
|
SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(void);
|
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
2006-04-06 20:56:29 +00:00
|
|
|
\brief create a new RTP session handle
|
|
|
|
\param new_rtp_session a poiter to aim at the new session
|
|
|
|
\param payload the IANA payload number
|
2006-04-07 17:32:14 +00:00
|
|
|
\param packet_size the default packet_size
|
|
|
|
\param ms_per_packet time in microseconds per packet
|
2006-04-06 20:56:29 +00:00
|
|
|
\param flags flags to control behaviour
|
2006-04-11 21:26:37 +00:00
|
|
|
\param crypto_key optional crypto key
|
2006-04-06 20:56:29 +00:00
|
|
|
\param err a pointer to resolve error messages
|
|
|
|
\param pool a memory pool to use for the session
|
|
|
|
\return the new RTP session or NULL on failure
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status)switch_rtp_create(switch_rtp_t **new_rtp_session,
|
2006-04-18 16:50:34 +00:00
|
|
|
switch_payload_t payload,
|
2006-04-09 00:10:13 +00:00
|
|
|
uint32_t packet_size,
|
2006-04-07 17:32:14 +00:00
|
|
|
uint32_t ms_per_packet,
|
|
|
|
switch_rtp_flag_t flags,
|
2006-04-10 16:11:24 +00:00
|
|
|
char *crypto_key,
|
2006-04-07 17:32:14 +00:00
|
|
|
const char **err,
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_memory_pool_t *pool);
|
2006-04-06 20:56:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief prepare a new RTP session handle and fully initilize it
|
|
|
|
\param rx_host the local address
|
2006-04-06 02:47:11 +00:00
|
|
|
\param rx_port the local port
|
2006-04-06 20:56:29 +00:00
|
|
|
\param tx_host the remote address
|
2006-04-06 02:47:11 +00:00
|
|
|
\param tx_port the remote port
|
2006-04-06 03:28:23 +00:00
|
|
|
\param payload the IANA payload number
|
2006-04-07 17:32:14 +00:00
|
|
|
\param packet_size the default packet_size
|
|
|
|
\param ms_per_packet time in microseconds per packet
|
2006-04-06 02:47:11 +00:00
|
|
|
\param flags flags to control behaviour
|
2006-04-11 21:26:37 +00:00
|
|
|
\param crypto_key optional crypto key
|
2006-04-06 02:47:11 +00:00
|
|
|
\param err a pointer to resolve error messages
|
|
|
|
\param pool a memory pool to use for the session
|
|
|
|
\return the new RTP session or NULL on failure
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_rtp_t *)switch_rtp_new(char *rx_host,
|
2006-04-06 20:56:29 +00:00
|
|
|
switch_port_t rx_port,
|
|
|
|
char *tx_host,
|
|
|
|
switch_port_t tx_port,
|
2006-04-18 16:50:34 +00:00
|
|
|
switch_payload_t payload,
|
2006-04-09 00:10:13 +00:00
|
|
|
uint32_t packet_size,
|
2006-04-07 17:32:14 +00:00
|
|
|
uint32_t ms_per_packet,
|
2006-04-06 20:56:29 +00:00
|
|
|
switch_rtp_flag_t flags,
|
2006-04-10 16:11:24 +00:00
|
|
|
char *crypto_key,
|
2006-04-06 20:56:29 +00:00
|
|
|
const char **err,
|
2006-04-29 01:00:52 +00:00
|
|
|
switch_memory_pool_t *pool);
|
2006-04-06 20:56:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Assign a remote address to the RTP session
|
|
|
|
\param rtp_session an RTP session to assign the remote address to
|
|
|
|
\param host the ip or fqhn of the remote address
|
|
|
|
\param port the remote port
|
|
|
|
\param err pointer for error messages
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_set_remote_address(switch_rtp_t *rtp_session, char *host, switch_port_t port, const char **err);
|
2006-04-06 20:56:29 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Assign a local address to the RTP session
|
|
|
|
\param rtp_session an RTP session to assign the local address to
|
|
|
|
\param host the ip or fqhn of the local address
|
|
|
|
\param port the local port
|
|
|
|
\param err pointer for error messages
|
|
|
|
\note this call also binds the RTP session's socket to the new address
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_set_local_address(switch_rtp_t *rtp_session, char *host, switch_port_t port, const char **err);
|
2006-04-06 20:56:29 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Kill the socket on an existing RTP session
|
|
|
|
\param rtp_session an RTP session to kill the socket of
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session);
|
2006-04-03 21:00:13 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Destroy an RTP session
|
|
|
|
\param rtp_session an RTP session to destroy
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Acvite ICE on an RTP session
|
|
|
|
\return SWITCH_STATUS_SUCCESS
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
2006-04-17 18:25:43 +00:00
|
|
|
/*!
|
|
|
|
\brief Set an RTP Flag
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\param flags the flags to set
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags);
|
2006-04-17 18:25:43 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Test an RTP Flag
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\param flags the flags to test
|
|
|
|
\return TRUE or FALSE
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(uint8_t) switch_rtp_test_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags);
|
2006-04-17 18:25:43 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Clear an RTP Flag
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\param flags the flags to clear
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags);
|
2006-04-17 18:25:43 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Retrieve the socket from an existing RTP session
|
|
|
|
\param rtp_session the RTP session to retrieve the socket from
|
|
|
|
\return the socket from the RTP session
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_socket_t *)switch_rtp_get_rtp_socket(switch_rtp_t *rtp_session);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
2006-04-07 17:32:14 +00:00
|
|
|
/*!
|
|
|
|
\brief Set the default packet size for a given RTP session
|
|
|
|
\param rtp_session the RTP session to set the packet size on
|
|
|
|
\param packet_size the new default packet size
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_set_default_packet_size(switch_rtp_t *rtp_session, uint16_t packet_size);
|
2006-04-07 17:32:14 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get the default packet size for a given RTP session
|
|
|
|
\param rtp_session the RTP session to get the packet size from
|
|
|
|
\return the default packet_size of the RTP session
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(uint32_t) switch_rtp_get_default_packet_size(switch_rtp_t *rtp_session);
|
2006-04-07 17:32:14 +00:00
|
|
|
|
2006-04-06 21:08:30 +00:00
|
|
|
/*!
|
|
|
|
\brief Set the default payload number for a given RTP session
|
|
|
|
\param rtp_session the RTP session to set the payload number on
|
|
|
|
\param payload the new default payload number
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_set_default_payload(switch_rtp_t *rtp_session, switch_payload_t payload);
|
2006-04-06 21:08:30 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get the default payload number for a given RTP session
|
|
|
|
\param rtp_session the RTP session to get the payload number from
|
|
|
|
\return the default payload of the RTP session
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(uint32_t) switch_rtp_get_default_payload(switch_rtp_t *rtp_session);
|
2006-04-06 21:08:30 +00:00
|
|
|
|
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Set a callback function to execute when an invalid RTP packet is encountered
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\param on_invalid the function to set
|
|
|
|
\return
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp_t *rtp_session, switch_rtp_invalid_handler on_invalid);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Read data from a given RTP session
|
|
|
|
\param rtp_session the RTP session to read from
|
|
|
|
\param data the data to read
|
2006-04-10 18:28:46 +00:00
|
|
|
\param datalen a pointer to the datalen
|
2006-04-06 03:28:23 +00:00
|
|
|
\param payload_type the IANA payload of the packet
|
2006-04-06 19:50:53 +00:00
|
|
|
\param flags flags
|
2006-04-06 02:47:11 +00:00
|
|
|
\return the number of bytes read
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag *flags);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\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
|
2006-04-10 18:28:46 +00:00
|
|
|
\param datalen a pointer to the datalen
|
2006-04-06 03:28:23 +00:00
|
|
|
\param payload_type the IANA payload of the packet
|
2006-04-06 20:59:25 +00:00
|
|
|
\param flags flags
|
2006-04-06 02:47:11 +00:00
|
|
|
\return the number of bytes read
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session, void **data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag *flags);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
2006-04-18 00:24:52 +00:00
|
|
|
/*!
|
|
|
|
\brief Read data from a given RTP session without copying
|
|
|
|
\param rtp_session the RTP session to read from
|
|
|
|
\param frame a frame to populate with information
|
|
|
|
\return the number of bytes read
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame *frame);
|
2006-04-18 00:24:52 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Write data to a given RTP session
|
|
|
|
\param rtp_session the RTP session to write to
|
|
|
|
\param data data to write
|
|
|
|
\param datalen the size of the data
|
|
|
|
\param ts then number of bytes to increment the timestamp by
|
2006-04-18 00:24:52 +00:00
|
|
|
\param flags frame flags
|
2006-04-06 02:47:11 +00:00
|
|
|
\return the number of bytes written
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint32_t ts, switch_frame_flag *flags);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
2006-04-21 22:31:08 +00:00
|
|
|
/*!
|
|
|
|
\brief Enable VAD on an RTP Session
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\param session the core session associated with the RTP session
|
|
|
|
\param codec the codec the channel is currenty using
|
|
|
|
\param flags flags for control
|
|
|
|
\return SWITCH_STAUTS_SUCCESS on success
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session *session, switch_codec *codec, switch_vad_flag_t flags);
|
2006-04-21 22:31:08 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Disable VAD on an RTP Session
|
|
|
|
\param rtp_session the RTP session
|
|
|
|
\return SWITCH_STAUTS_SUCCESS on success
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_rtp_disable_vad(switch_rtp_t *rtp_session);
|
2006-04-21 22:31:08 +00:00
|
|
|
|
2006-04-18 16:20:47 +00:00
|
|
|
/*!
|
|
|
|
\brief Write data to a given RTP session
|
|
|
|
\param rtp_session the RTP session to write to
|
|
|
|
\param frame the frame to write
|
|
|
|
\param ts then number of bytes to increment the timestamp by
|
|
|
|
\return the number of bytes written
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame *frame, uint32_t ts);
|
2006-04-18 16:20:47 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\brief Write data with a specified payload and sequence number to a given RTP session
|
|
|
|
\param rtp_session the RTP session to write to
|
|
|
|
\param data data to write
|
|
|
|
\param datalen the size of the data
|
2006-04-24 16:19:11 +00:00
|
|
|
\param m set mark bit or not
|
2006-04-06 03:28:23 +00:00
|
|
|
\param payload the IANA payload number
|
2006-04-06 02:47:11 +00:00
|
|
|
\param ts then number of bytes to increment the timestamp by
|
|
|
|
\param mseq the specific sequence number to use
|
2006-04-18 00:24:52 +00:00
|
|
|
\param flags frame flags
|
2006-04-06 02:47:11 +00:00
|
|
|
\return the number of bytes written
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session, void *data, uint16_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, uint16_t mseq, switch_frame_flag *flags);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Retrieve the SSRC from a given RTP session
|
|
|
|
\param rtp_session the RTP session to retrieve from
|
|
|
|
\return the SSRC
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(uint32_t) switch_rtp_get_ssrc(switch_rtp_t *rtp_session);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Associate an arbitrary data pointer with and RTP session
|
|
|
|
\param rtp_session the RTP session to assign the pointer to
|
|
|
|
\param private_data the private data to assign
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void) switch_rtp_set_private(switch_rtp_t *rtp_session, void *private_data);
|
2006-04-06 02:47:11 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Retrieve the private data from a given RTP session
|
|
|
|
\param rtp_session the RTP session to retrieve the data from
|
|
|
|
\return the pointer to the private data
|
|
|
|
*/
|
2006-04-29 01:00:52 +00:00
|
|
|
SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp_t *rtp_session);
|
2006-04-03 21:00:13 +00:00
|
|
|
|
2006-04-06 02:47:11 +00:00
|
|
|
/*!
|
|
|
|
\}
|
|
|
|
*/
|
|
|
|
|
2006-04-28 20:04:08 +00:00
|
|
|
END_EXTERN_C
|
2006-04-03 21:00:13 +00:00
|
|
|
|
|
|
|
#endif
|