summaryrefslogtreecommitdiff
path: root/include/asterisk/rtp_engine.h
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-07-23 19:24:04 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-08-19 17:09:58 -0500
commit1a549ed134b45c757d8d1cd5d0c66df4285a9150 (patch)
tree7bbf5ab302f79b574d7807f5f99311357e42a5ae /include/asterisk/rtp_engine.h
parentaacb46b56ae684d8f5d8affab31d9c45b149e733 (diff)
rtp_engine.c: Initial split of payload types into rx and tx mappings.
There are numerous problems with the current implementation of the RTP payload type mapping in Asterisk. It uses only one mapping structure to associate payload types to codecs. The single mapping is overkill if all of the payload type values are well known values. Dynamic payload type mappings do not work as well with the single mapping because RFC3264 allows each side of the link to negotiate different dynamic mappings for what they want to receive. Not only could you have the same codec mapped for sending and receiving on different payload types you could wind up with the same payload type mapped to different codecs for each direction. 1) An independent payload type mapping is needed for sending and receiving. 2) The receive mapping needs to keep track of previous mappings because of the slack to when negotiation happens and current packets in flight using the old mapping arrive. 3) The transmit mapping only needs to keep track of the current negotiated values since we are sending the packets and know when the switchover takes place. * Needed to create ast_rtp_codecs_payload_code_tx() and make some callers use the new function because ast_rtp_codecs_payload_code() was used for mappings in both directions. * Needed to create ast_rtp_codecs_payloads_xover() for cases where we need to pass preferred codec mappings to the peer channel for early media bridging or when we need to prefer the offered mapping that RFC3264 says we SHOULD use. * ast_rtp_codecs_payloads_xover() and ast_rtp_codecs_payload_code_tx() are the only new public functions created. All the others were only used for the tx or rx mapping direction so the function doxygen now reflects which direction the function operates. * chan_mgcp.c: Removed call to ast_rtp_codecs_payloads_clear() as doing that makes no sense when processing an incoming SDP. We would be wiping out any mappings that we set for the possible outgoing SDP we sent earlier. ASTERISK-25166 Reported by: Kevin Harwell ASTERISK-17410 Reported by: Boris Fox Change-Id: Iaf6c227bca68cb7c414cf2fd4108a8ac98bd45ac
Diffstat (limited to 'include/asterisk/rtp_engine.h')
-rw-r--r--include/asterisk/rtp_engine.h72
1 files changed, 51 insertions, 21 deletions
diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index d6a9be574..a52567a13 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -251,6 +251,8 @@ struct ast_rtp_payload_type {
int rtp_code;
/*! Actual payload number */
int payload;
+ /*! TRUE if this is the primary mapping to the format. */
+ unsigned int primary_mapping:1;
};
/* Common RTCP report types */
@@ -577,16 +579,18 @@ struct ast_rtp_engine {
/*! Structure that represents codec and packetization information */
struct ast_rtp_codecs {
- /*! Payloads present */
- AST_VECTOR(, struct ast_rtp_payload_type *) payloads;
- /*! The framing for this media session */
- unsigned int framing;
/*! RW lock that protects elements in this structure */
ast_rwlock_t codecs_lock;
+ /*! Rx payload type mapping exceptions */
+ AST_VECTOR(, struct ast_rtp_payload_type *) payload_mapping_rx;
+ /*! Tx payload type mapping */
+ AST_VECTOR(, struct ast_rtp_payload_type *) payload_mapping_tx;
+ /*! The framing for this media session */
+ unsigned int framing;
};
#define AST_RTP_CODECS_NULL_INIT \
- { .payloads = { 0, }, .framing = 0, .codecs_lock = AST_RWLOCK_INIT_VALUE, }
+ { .codecs_lock = AST_RWLOCK_INIT_VALUE, .payload_mapping_rx = { 0, }, .payload_mapping_tx = { 0, }, .framing = 0, }
/*! Structure that represents the glue that binds an RTP instance to a channel */
struct ast_rtp_glue {
@@ -1192,7 +1196,7 @@ int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs);
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs);
/*!
- * \brief Clear payload information from an RTP instance
+ * \brief Clear rx and tx payload mapping information from an RTP instance
*
* \param codecs The codecs structure that payloads will be cleared from
* \param instance Optionally the instance that the codecs structure belongs to
@@ -1230,7 +1234,19 @@ void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp
void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
/*!
- * \brief Record payload information that was seen in an m= SDP line
+ * \brief Crossover copy the tx payload mapping of src to the rx payload mapping of dest.
+ * \since 14.0.0
+ *
+ * \param src The source codecs structure
+ * \param dest The destination codecs structure that the values from src will be copied to
+ * \param instance Optionally the instance that the dst codecs structure belongs to
+ *
+ * \return Nothing
+ */
+void ast_rtp_codecs_payloads_xover(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Record tx payload type information that was seen in an m= SDP line
*
* \param codecs The codecs structure to muck with
* \param instance Optionally the instance that the codecs structure belongs to
@@ -1249,7 +1265,7 @@ void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_cod
void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
/*!
- * \brief Record payload information that was seen in an a=rtpmap: SDP line
+ * \brief Record tx payload type information that was seen in an a=rtpmap: SDP line
*
* \param codecs The codecs structure to muck with
* \param instance Optionally the instance that the codecs structure belongs to
@@ -1275,7 +1291,7 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as
int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimetype, char *mimesubtype, enum ast_rtp_options options);
/*!
- * \brief Set payload type to a known MIME media type for a codec with a specific sample rate
+ * \brief Set tx payload type to a known MIME media type for a codec with a specific sample rate
*
* \param codecs RTP structure to modify
* \param instance Optionally the instance that the codecs structure belongs to
@@ -1300,7 +1316,7 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs,
unsigned int sample_rate);
/*!
- * \brief Remove payload information
+ * \brief Remove tx payload type mapped information
*
* \param codecs The codecs structure to muck with
* \param instance Optionally the instance that the codecs structure belongs to
@@ -1319,7 +1335,7 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs,
void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
/*!
- * \brief Retrieve payload information by payload
+ * \brief Retrieve rx payload mapped information by payload type
*
* \param codecs Codecs structure to look in
* \param payload Numerical payload to look up
@@ -1342,10 +1358,10 @@ void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp
struct ast_rtp_payload_type *ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload);
/*!
- * \brief Update the format associated with a payload in a codecs structure
+ * \brief Update the format associated with a tx payload type in a codecs structure
*
* \param codecs Codecs structure to operate on
- * \param payload Numerical payload to look up
+ * \param payload Numerical payload type to look up
* \param format The format to replace the existing one
*
* \retval 0 success
@@ -1356,10 +1372,10 @@ struct ast_rtp_payload_type *ast_rtp_codecs_get_payload(struct ast_rtp_codecs *c
int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int payload, struct ast_format *format);
/*!
- * \brief Retrieve the actual ast_format stored on the codecs structure for a specific payload
+ * \brief Retrieve the actual ast_format stored on the codecs structure for a specific tx payload type
*
* \param codecs Codecs structure to look in
- * \param payload Numerical payload to look up
+ * \param payload Numerical payload type to look up
*
* \retval pointer to format structure on success
* \retval NULL on failure
@@ -1428,14 +1444,15 @@ unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format
void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats);
/*!
- * \brief Retrieve a payload based on whether it is an Asterisk format and the code
+ * \brief Retrieve a rx mapped payload type based on whether it is an Asterisk format and the code
*
* \param codecs Codecs structure to look in
* \param asterisk_format Non-zero if the given Asterisk format is present
* \param format Asterisk format to look for
* \param code The format to look for
*
- * \retval Numerical payload
+ * \retval Numerical payload type
+ * \retval -1 if not found.
*
* Example usage:
*
@@ -1450,12 +1467,26 @@ void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_fo
int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code);
/*!
- * \brief Search for a payload code in the ast_rtp_codecs structure
+ * \brief Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code
+ * \since 14.0.0
*
* \param codecs Codecs structure to look in
+ * \param asterisk_format Non-zero if the given Asterisk format is present
+ * \param format Asterisk format to look for
* \param code The format to look for
*
- * \retval Numerical payload or -1 if unable to find payload in codecs
+ * \retval Numerical payload type
+ * \retval -1 if not found.
+ */
+int ast_rtp_codecs_payload_code_tx(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code);
+
+/*!
+ * \brief Search for the tx payload type in the ast_rtp_codecs structure
+ *
+ * \param codecs Codecs structure to look in
+ * \param payload The payload type format to look for
+ *
+ * \retval Numerical payload type or -1 if unable to find payload in codecs
*
* Example usage:
*
@@ -1464,9 +1495,8 @@ int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_form
* \endcode
*
* This looks for the numerical payload for ULAW in the codecs structure.
- *
*/
-int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int code);
+int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload);
/*!
* \brief Retrieve mime subtype information on a payload