mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was fast but had a few limitations. 1. Asterisk was limited in how many formats it could handle. 2. Formats, being a bit field, could not include any attribute information. A format was strictly its type, e.g., "this is ulaw". This was changed in Asterisk 10 (see https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for notes on that work) which led to the creation of the ast_format structure. This structure allowed Asterisk to handle attributes and bundle information with a format. Additionally, ast_format_cap was created to act as a container for multiple formats that, together, formed the capability of some entity. Another mechanism was added to allow logic to be registered which performed format attribute negotiation. Everywhere throughout the codebase Asterisk was changed to use this strategy. Unfortunately, in software, there is no free lunch. These new capabilities came at a cost. Performance analysis and profiling showed that we spend an inordinate amount of time comparing, copying, and generally manipulating formats and their related structures. Basic prototyping has shown that a reasonably large performance improvement could be made in this area. This patch is the result of that project, which overhauled the media format architecture and its usage in Asterisk to improve performance. Generally, the new philosophy for handling formats is as follows: * The ast_format structure is reference counted. This removed a large amount of the memory allocations and copying that was done in prior versions. * In order to prevent race conditions while keeping things performant, the ast_format structure is immutable by convention and lock-free. Violate this tenet at your peril! * Because formats are reference counted, codecs are also reference counted. The Asterisk core generally provides built-in codecs and caches the ast_format structures created to represent them. Generally, to prevent inordinate amounts of module reference bumping, codecs and formats can be added at run-time but cannot be removed. * All compatibility with the bit field representation of codecs/formats has been moved to a compatibility API. The primary user of this representation is chan_iax2, which must continue to maintain its bit-field usage of formats for interoperability concerns. * When a format is negotiated with attributes, or when a format cannot be represented by one of the cached formats, a new format object is created or cloned from an existing format. That format may have the same codec underlying it, but is a different format than a version of the format with different attributes or without attributes. * While formats are reference counted objects, the reference count maintained on the format should be manipulated with care. Formats are generally cached and will persist for the lifetime of Asterisk and do not explicitly need to have their lifetime modified. An exception to this is when the user of a format does not know where the format came from *and* the user may outlive the provider of the format. This occurs, for example, when a format is read from a channel: the channel may have a format with attributes (hence, non-cached) and the user of the format may last longer than the channel (if the reference to the channel is released prior to the format's reference). For more information on this work, see the API design notes: https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite Finally, this work was the culmination of a large number of developer's efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the work in the Asterisk core, chan_sip, and was an invaluable resource in peer reviews throughout this project. There were a substantial number of patches contributed during this work; the following issues/patch names simply reflect some of the work (and will cause the release scripts to give attribution to the individuals who work on them). Reviews: https://reviewboard.asterisk.org/r/3814 https://reviewboard.asterisk.org/r/3808 https://reviewboard.asterisk.org/r/3805 https://reviewboard.asterisk.org/r/3803 https://reviewboard.asterisk.org/r/3801 https://reviewboard.asterisk.org/r/3798 https://reviewboard.asterisk.org/r/3800 https://reviewboard.asterisk.org/r/3794 https://reviewboard.asterisk.org/r/3793 https://reviewboard.asterisk.org/r/3792 https://reviewboard.asterisk.org/r/3791 https://reviewboard.asterisk.org/r/3790 https://reviewboard.asterisk.org/r/3789 https://reviewboard.asterisk.org/r/3788 https://reviewboard.asterisk.org/r/3787 https://reviewboard.asterisk.org/r/3786 https://reviewboard.asterisk.org/r/3784 https://reviewboard.asterisk.org/r/3783 https://reviewboard.asterisk.org/r/3778 https://reviewboard.asterisk.org/r/3774 https://reviewboard.asterisk.org/r/3775 https://reviewboard.asterisk.org/r/3772 https://reviewboard.asterisk.org/r/3761 https://reviewboard.asterisk.org/r/3754 https://reviewboard.asterisk.org/r/3753 https://reviewboard.asterisk.org/r/3751 https://reviewboard.asterisk.org/r/3750 https://reviewboard.asterisk.org/r/3748 https://reviewboard.asterisk.org/r/3747 https://reviewboard.asterisk.org/r/3746 https://reviewboard.asterisk.org/r/3742 https://reviewboard.asterisk.org/r/3740 https://reviewboard.asterisk.org/r/3739 https://reviewboard.asterisk.org/r/3738 https://reviewboard.asterisk.org/r/3737 https://reviewboard.asterisk.org/r/3736 https://reviewboard.asterisk.org/r/3734 https://reviewboard.asterisk.org/r/3722 https://reviewboard.asterisk.org/r/3713 https://reviewboard.asterisk.org/r/3703 https://reviewboard.asterisk.org/r/3689 https://reviewboard.asterisk.org/r/3687 https://reviewboard.asterisk.org/r/3674 https://reviewboard.asterisk.org/r/3671 https://reviewboard.asterisk.org/r/3667 https://reviewboard.asterisk.org/r/3665 https://reviewboard.asterisk.org/r/3625 https://reviewboard.asterisk.org/r/3602 https://reviewboard.asterisk.org/r/3519 https://reviewboard.asterisk.org/r/3518 https://reviewboard.asterisk.org/r/3516 https://reviewboard.asterisk.org/r/3515 https://reviewboard.asterisk.org/r/3512 https://reviewboard.asterisk.org/r/3506 https://reviewboard.asterisk.org/r/3413 https://reviewboard.asterisk.org/r/3410 https://reviewboard.asterisk.org/r/3387 https://reviewboard.asterisk.org/r/3388 https://reviewboard.asterisk.org/r/3389 https://reviewboard.asterisk.org/r/3390 https://reviewboard.asterisk.org/r/3321 https://reviewboard.asterisk.org/r/3320 https://reviewboard.asterisk.org/r/3319 https://reviewboard.asterisk.org/r/3318 https://reviewboard.asterisk.org/r/3266 https://reviewboard.asterisk.org/r/3265 https://reviewboard.asterisk.org/r/3234 https://reviewboard.asterisk.org/r/3178 ASTERISK-23114 #close Reported by: mjordan media_formats_translation_core.diff uploaded by kharwell (License 6464) rb3506.diff uploaded by mjordan (License 6283) media_format_app_file.diff uploaded by kharwell (License 6464) misc-2.diff uploaded by file (License 5000) chan_mild-3.diff uploaded by file (License 5000) chan_obscure.diff uploaded by file (License 5000) jingle.diff uploaded by file (License 5000) funcs.diff uploaded by file (License 5000) formats.diff uploaded by file (License 5000) core.diff uploaded by file (License 5000) bridges.diff uploaded by file (License 5000) mf-codecs-2.diff uploaded by file (License 5000) mf-app_fax.diff uploaded by file (License 5000) mf-apps-3.diff uploaded by file (License 5000) media-formats-3.diff uploaded by file (License 5000) ASTERISK-23715 rb3713.patch uploaded by coreyfarrell (License 5909) rb3689.patch uploaded by mjordan (License 6283) ASTERISK-23957 rb3722.patch uploaded by mjordan (License 6283) mf-attributes-3.diff uploaded by file (License 5000) ASTERISK-23958 Tested by: jrose rb3822.patch uploaded by coreyfarrell (License 5909) rb3800.patch uploaded by jrose (License 6182) chan_sip.diff uploaded by mjordan (License 6283) rb3747.patch uploaded by jrose (License 6182) ASTERISK-23959 #close Tested by: sgriepentrog, mjordan, coreyfarrell sip_cleanup.diff uploaded by opticron (License 6273) chan_sip_caps.diff uploaded by mjordan (License 6283) rb3751.patch uploaded by coreyfarrell (License 5909) chan_sip-3.diff uploaded by file (License 5000) ASTERISK-23960 #close Tested by: opticron direct_media.diff uploaded by opticron (License 6273) pjsip-direct-media.diff uploaded by file (License 5000) format_cap_remove.diff uploaded by opticron (License 6273) media_format_fixes.diff uploaded by opticron (License 6273) chan_pjsip-2.diff uploaded by file (License 5000) ASTERISK-23966 #close Tested by: rmudgett rb3803.patch uploaded by rmudgetti (License 5621) chan_dahdi.diff uploaded by file (License 5000) ASTERISK-24064 #close Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose rb3814.patch uploaded by rmudgett (License 5621) moh_cleanup.diff uploaded by opticron (License 6273) bridge_leak.diff uploaded by opticron (License 6273) translate.diff uploaded by file (License 5000) rb3795.patch uploaded by rmudgett (License 5621) tls_fix.diff uploaded by mjordan (License 6283) fax-mf-fix-2.diff uploaded by file (License 5000) rtp_transfer_stuff uploaded by mjordan (License 6283) rb3787.patch uploaded by rmudgett (License 5621) media-formats-explicit-translate-format-3.diff uploaded by file (License 5000) format_cache_case_fix.diff uploaded by opticron (License 6273) rb3774.patch uploaded by rmudgett (License 5621) rb3775.patch uploaded by rmudgett (License 5621) rtp_engine_fix.diff uploaded by opticron (License 6273) rtp_crash_fix.diff uploaded by opticron (License 6273) rb3753.patch uploaded by mjordan (License 6283) rb3750.patch uploaded by mjordan (License 6283) rb3748.patch uploaded by rmudgett (License 5621) media_format_fixes.diff uploaded by opticron (License 6273) rb3740.patch uploaded by mjordan (License 6283) rb3739.patch uploaded by mjordan (License 6283) rb3734.patch uploaded by mjordan (License 6283) rb3689.patch uploaded by mjordan (License 6283) rb3674.patch uploaded by coreyfarrell (License 5909) rb3671.patch uploaded by coreyfarrell (License 5909) rb3667.patch uploaded by coreyfarrell (License 5909) rb3665.patch uploaded by mjordan (License 6283) rb3625.patch uploaded by coreyfarrell (License 5909) rb3602.patch uploaded by coreyfarrell (License 5909) format_compatibility-2.diff uploaded by file (License 5000) core.diff uploaded by file (License 5000) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -77,6 +77,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "asterisk/abstract_jb.h"
|
||||
#include "asterisk/xmpp.h"
|
||||
#include "asterisk/stasis_channels.h"
|
||||
#include "asterisk/format_cache.h"
|
||||
|
||||
/*** DOCUMENTATION
|
||||
<configInfo name="chan_motif" language="en_US">
|
||||
@@ -286,7 +287,6 @@ struct jingle_endpoint {
|
||||
iksrule *rule; /*!< Active matching rule */
|
||||
unsigned int maxicecandidates; /*!< Maximum number of ICE candidates we will offer */
|
||||
unsigned int maxpayloads; /*!< Maximum number of payloads we will offer */
|
||||
struct ast_codec_pref prefs; /*!< Codec preferences */
|
||||
struct ast_format_cap *cap; /*!< Formats to use */
|
||||
ast_group_t callgroup; /*!< Call group */
|
||||
ast_group_t pickupgroup; /*!< Pickup group */
|
||||
@@ -309,7 +309,6 @@ struct jingle_session {
|
||||
char remote_original[XMPP_MAX_JIDLEN];/*!< Identifier of the original remote party (remote may have changed due to redirect) */
|
||||
char remote[XMPP_MAX_JIDLEN]; /*!< Identifier of the remote party */
|
||||
iksrule *rule; /*!< Session matching rule */
|
||||
struct ast_codec_pref prefs; /*!< Codec preferences */
|
||||
struct ast_channel *owner; /*!< Master Channel */
|
||||
struct ast_rtp_instance *rtp; /*!< RTP audio session */
|
||||
struct ast_rtp_instance *vrtp; /*!< RTP video session */
|
||||
@@ -454,8 +453,7 @@ static void jingle_endpoint_destructor(void *obj)
|
||||
ast_xmpp_client_unref(endpoint->connection);
|
||||
}
|
||||
|
||||
ast_format_cap_destroy(endpoint->cap);
|
||||
|
||||
ao2_cleanup(endpoint->cap);
|
||||
ao2_ref(endpoint->state, -1);
|
||||
|
||||
ast_string_field_free_memory(endpoint);
|
||||
@@ -519,7 +517,7 @@ static void *jingle_endpoint_alloc(const char *cat)
|
||||
|
||||
ast_string_field_set(endpoint, name, cat);
|
||||
|
||||
endpoint->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
|
||||
endpoint->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
||||
endpoint->transport = JINGLE_TRANSPORT_ICE_UDP;
|
||||
|
||||
return endpoint;
|
||||
@@ -583,9 +581,9 @@ static void jingle_session_destructor(void *obj)
|
||||
ast_rtp_instance_destroy(session->vrtp);
|
||||
}
|
||||
|
||||
ast_format_cap_destroy(session->cap);
|
||||
ast_format_cap_destroy(session->jointcap);
|
||||
ast_format_cap_destroy(session->peercap);
|
||||
ao2_cleanup(session->cap);
|
||||
ao2_cleanup(session->jointcap);
|
||||
ao2_cleanup(session->peercap);
|
||||
|
||||
if (session->callid) {
|
||||
ast_callid_unref(session->callid);
|
||||
@@ -681,7 +679,7 @@ static void jingle_enable_video(struct jingle_session *session)
|
||||
}
|
||||
|
||||
/* If there are no configured video codecs do not turn video support on, it just won't work */
|
||||
if (!ast_format_cap_has_type(session->cap, AST_FORMAT_TYPE_VIDEO)) {
|
||||
if (!ast_format_cap_has_type(session->cap, AST_MEDIA_TYPE_VIDEO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -695,8 +693,8 @@ static void jingle_enable_video(struct jingle_session *session)
|
||||
ast_rtp_instance_set_channel_id(session->vrtp, ast_channel_uniqueid(session->owner));
|
||||
ast_channel_set_fd(session->owner, 2, ast_rtp_instance_fd(session->vrtp, 0));
|
||||
ast_channel_set_fd(session->owner, 3, ast_rtp_instance_fd(session->vrtp, 1));
|
||||
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->vrtp), session->vrtp, &session->prefs);
|
||||
|
||||
ast_rtp_codecs_set_framing(ast_rtp_instance_get_codecs(session->vrtp),
|
||||
ast_format_cap_get_framing(session->cap));
|
||||
if (session->transport == JINGLE_TRANSPORT_GOOGLE_V2 && (ice = ast_rtp_instance_get_ice(session->vrtp))) {
|
||||
ice->stop(session->vrtp);
|
||||
}
|
||||
@@ -741,15 +739,15 @@ static struct jingle_session *jingle_alloc(struct jingle_endpoint *endpoint, con
|
||||
session->connection = endpoint->connection;
|
||||
session->transport = endpoint->transport;
|
||||
|
||||
if (!(session->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
|
||||
!(session->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
|
||||
!(session->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK)) ||
|
||||
if (!(session->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
|
||||
!(session->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
|
||||
!(session->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
|
||||
!session->callid) {
|
||||
ao2_ref(session, -1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ast_format_cap_copy(session->cap, endpoint->cap);
|
||||
ast_format_cap_append_from_cap(session->cap, endpoint->cap, AST_MEDIA_TYPE_UNKNOWN);
|
||||
|
||||
/* While we rely on res_xmpp for communication we still need a temporary ast_sockaddr to tell the RTP engine
|
||||
* that we want IPv4 */
|
||||
@@ -763,8 +761,6 @@ static struct jingle_session *jingle_alloc(struct jingle_endpoint *endpoint, con
|
||||
ast_rtp_instance_set_prop(session->rtp, AST_RTP_PROPERTY_RTCP, 1);
|
||||
ast_rtp_instance_set_prop(session->rtp, AST_RTP_PROPERTY_DTMF, 1);
|
||||
|
||||
memcpy(&session->prefs, &endpoint->prefs, sizeof(session->prefs));
|
||||
|
||||
session->maxicecandidates = endpoint->maxicecandidates;
|
||||
session->maxpayloads = endpoint->maxpayloads;
|
||||
|
||||
@@ -776,13 +772,20 @@ static struct ast_channel *jingle_new(struct jingle_endpoint *endpoint, struct j
|
||||
{
|
||||
struct ast_channel *chan;
|
||||
const char *str = S_OR(title, session->remote);
|
||||
struct ast_format tmpfmt;
|
||||
struct ast_format_cap *caps;
|
||||
struct ast_format *tmpfmt;
|
||||
|
||||
if (ast_format_cap_is_empty(session->cap)) {
|
||||
if (!ast_format_cap_count(session->cap)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
||||
if (!caps) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(chan = ast_channel_alloc(1, state, S_OR(title, ""), S_OR(cid_name, ""), "", "", "", assignedids, requestor, 0, "Motif/%s-%04lx", str, (unsigned long)(ast_random() & 0xffff)))) {
|
||||
ao2_ref(caps, -1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -794,15 +797,17 @@ static struct ast_channel *jingle_new(struct jingle_endpoint *endpoint, struct j
|
||||
|
||||
ast_channel_callid_set(chan, session->callid);
|
||||
|
||||
ast_format_cap_copy(ast_channel_nativeformats(chan), session->cap);
|
||||
ast_codec_choose(&session->prefs, session->cap, 1, &tmpfmt);
|
||||
ast_format_cap_append_from_cap(caps, session->cap, AST_MEDIA_TYPE_UNKNOWN);
|
||||
ast_channel_nativeformats_set(chan, caps);
|
||||
ao2_ref(caps, -1);
|
||||
|
||||
if (session->rtp) {
|
||||
struct ast_rtp_engine_ice *ice;
|
||||
|
||||
ast_channel_set_fd(chan, 0, ast_rtp_instance_fd(session->rtp, 0));
|
||||
ast_channel_set_fd(chan, 1, ast_rtp_instance_fd(session->rtp, 1));
|
||||
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->rtp), session->rtp, &session->prefs);
|
||||
ast_rtp_codecs_set_framing(ast_rtp_instance_get_codecs(session->rtp),
|
||||
ast_format_cap_get_framing(session->cap));
|
||||
|
||||
if (((session->transport == JINGLE_TRANSPORT_GOOGLE_V2) ||
|
||||
(session->transport == JINGLE_TRANSPORT_GOOGLE_V1)) &&
|
||||
@@ -818,11 +823,12 @@ static struct ast_channel *jingle_new(struct jingle_endpoint *endpoint, struct j
|
||||
|
||||
ast_channel_adsicpe_set(chan, AST_ADSI_UNAVAILABLE);
|
||||
|
||||
ast_best_codec(ast_channel_nativeformats(chan), &tmpfmt);
|
||||
ast_format_copy(ast_channel_writeformat(chan), &tmpfmt);
|
||||
ast_format_copy(ast_channel_rawwriteformat(chan), &tmpfmt);
|
||||
ast_format_copy(ast_channel_readformat(chan), &tmpfmt);
|
||||
ast_format_copy(ast_channel_rawreadformat(chan), &tmpfmt);
|
||||
tmpfmt = ast_format_cap_get_format(session->cap, 0);
|
||||
ast_channel_set_writeformat(chan, tmpfmt);
|
||||
ast_channel_set_rawwriteformat(chan, tmpfmt);
|
||||
ast_channel_set_readformat(chan, tmpfmt);
|
||||
ast_channel_set_rawreadformat(chan, tmpfmt);
|
||||
ao2_ref(tmpfmt, -1);
|
||||
|
||||
ao2_lock(endpoint);
|
||||
|
||||
@@ -1300,30 +1306,24 @@ static void jingle_send_transport_info(struct jingle_session *session, const cha
|
||||
}
|
||||
|
||||
/*! \brief Internal helper function which adds payloads to a description */
|
||||
static int jingle_add_payloads_to_description(struct jingle_session *session, struct ast_rtp_instance *rtp, iks *description, iks **payloads, enum ast_format_type type)
|
||||
static int jingle_add_payloads_to_description(struct jingle_session *session, struct ast_rtp_instance *rtp, iks *description, iks **payloads, enum ast_media_type type)
|
||||
{
|
||||
struct ast_format format;
|
||||
int x = 0, i = 0, res = 0;
|
||||
|
||||
for (x = 0; (x < AST_CODEC_PREF_SIZE) && (i < (session->maxpayloads - 2)); x++) {
|
||||
for (x = 0; (x < ast_format_cap_count(session->jointcap)) && (i < (session->maxpayloads - 2)); x++) {
|
||||
struct ast_format *format = ast_format_cap_get_format(session->jointcap, x);
|
||||
int rtp_code;
|
||||
iks *payload;
|
||||
char tmp[32];
|
||||
|
||||
if (!ast_codec_pref_index(&session->prefs, x, &format)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (AST_FORMAT_GET_TYPE(format.id) != type) {
|
||||
if (ast_format_get_type(format) != type) {
|
||||
ao2_ref(format, -1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ast_format_cap_iscompatible(session->jointcap, &format)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(rtp), 1, &format, 0)) == -1) ||
|
||||
if (((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(rtp), 1, format, 0)) == -1) ||
|
||||
(!(payload = iks_new("payload-type")))) {
|
||||
ao2_ref(format, -1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1333,17 +1333,18 @@ static int jingle_add_payloads_to_description(struct jingle_session *session, st
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%d", rtp_code);
|
||||
iks_insert_attrib(payload, "id", tmp);
|
||||
iks_insert_attrib(payload, "name", ast_rtp_lookup_mime_subtype2(1, &format, 0, 0));
|
||||
iks_insert_attrib(payload, "name", ast_rtp_lookup_mime_subtype2(1, format, 0, 0));
|
||||
iks_insert_attrib(payload, "channels", "1");
|
||||
|
||||
if ((format.id == AST_FORMAT_G722) && ((session->transport == JINGLE_TRANSPORT_GOOGLE_V1) || (session->transport == JINGLE_TRANSPORT_GOOGLE_V2))) {
|
||||
if ((ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) &&
|
||||
((session->transport == JINGLE_TRANSPORT_GOOGLE_V1) || (session->transport == JINGLE_TRANSPORT_GOOGLE_V2))) {
|
||||
iks_insert_attrib(payload, "clockrate", "16000");
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%u", ast_rtp_lookup_sample_rate2(1, &format, 0));
|
||||
snprintf(tmp, sizeof(tmp), "%u", ast_rtp_lookup_sample_rate2(1, format, 0));
|
||||
iks_insert_attrib(payload, "clockrate", tmp);
|
||||
}
|
||||
|
||||
if ((type == AST_FORMAT_TYPE_VIDEO) && (session->transport == JINGLE_TRANSPORT_GOOGLE_V2)) {
|
||||
if ((type == AST_MEDIA_TYPE_VIDEO) && (session->transport == JINGLE_TRANSPORT_GOOGLE_V2)) {
|
||||
iks *parameter;
|
||||
|
||||
/* Google requires these parameters to be set, but alas we can not give accurate values so use some safe defaults */
|
||||
@@ -1366,9 +1367,11 @@ static int jingle_add_payloads_to_description(struct jingle_session *session, st
|
||||
|
||||
iks_insert_node(description, payload);
|
||||
payloads[i++] = payload;
|
||||
|
||||
ao2_ref(format, -1);
|
||||
}
|
||||
/* If this is for audio and there is room for RFC2833 add it in */
|
||||
if ((type == AST_FORMAT_TYPE_AUDIO) && (i < session->maxpayloads)) {
|
||||
if ((type == AST_MEDIA_TYPE_AUDIO) && (i < session->maxpayloads)) {
|
||||
iks *payload;
|
||||
|
||||
if ((payload = iks_new("payload-type"))) {
|
||||
@@ -1390,7 +1393,7 @@ static int jingle_add_payloads_to_description(struct jingle_session *session, st
|
||||
|
||||
/*! \brief Helper function which adds content to a description */
|
||||
static int jingle_add_content(struct jingle_session *session, iks *jingle, iks *content, iks *description, iks *transport,
|
||||
const char *name, enum ast_format_type type, struct ast_rtp_instance *rtp, iks **payloads)
|
||||
const char *name, enum ast_media_type type, struct ast_rtp_instance *rtp, iks **payloads)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
@@ -1400,9 +1403,9 @@ static int jingle_add_content(struct jingle_session *session, iks *jingle, iks *
|
||||
iks_insert_node(jingle, content);
|
||||
|
||||
iks_insert_attrib(description, "xmlns", JINGLE_RTP_NS);
|
||||
if (type == AST_FORMAT_TYPE_AUDIO) {
|
||||
if (type == AST_MEDIA_TYPE_AUDIO) {
|
||||
iks_insert_attrib(description, "media", "audio");
|
||||
} else if (type == AST_FORMAT_TYPE_VIDEO) {
|
||||
} else if (type == AST_MEDIA_TYPE_VIDEO) {
|
||||
iks_insert_attrib(description, "media", "video");
|
||||
} else {
|
||||
return -1;
|
||||
@@ -1469,7 +1472,7 @@ static void jingle_send_session_action(struct jingle_session *session, const cha
|
||||
if (session->rtp && (audio = iks_new("content")) && (audio_description = iks_new("description")) &&
|
||||
(audio_transport = iks_new("transport"))) {
|
||||
res = jingle_add_content(session, jingle, audio, audio_description, audio_transport, session->audio_name,
|
||||
AST_FORMAT_TYPE_AUDIO, session->rtp, audio_payloads);
|
||||
AST_MEDIA_TYPE_AUDIO, session->rtp, audio_payloads);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Failed to allocate audio content stanzas for session '%s', hanging up\n", session->sid);
|
||||
res = -1;
|
||||
@@ -1479,7 +1482,7 @@ static void jingle_send_session_action(struct jingle_session *session, const cha
|
||||
if ((video = iks_new("content")) && (video_description = iks_new("description")) &&
|
||||
(video_transport = iks_new("transport"))) {
|
||||
res = jingle_add_content(session, jingle, video, video_description, video_transport, session->video_name,
|
||||
AST_FORMAT_TYPE_VIDEO, session->vrtp, video_payloads);
|
||||
AST_MEDIA_TYPE_VIDEO, session->vrtp, video_payloads);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Failed to allocate video content stanzas for session '%s', hanging up\n", session->sid);
|
||||
res = -1;
|
||||
@@ -1668,17 +1671,24 @@ static struct ast_frame *jingle_read(struct ast_channel *ast)
|
||||
}
|
||||
|
||||
if (frame && frame->frametype == AST_FRAME_VOICE &&
|
||||
!ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format)) {
|
||||
if (!ast_format_cap_iscompatible(session->jointcap, &frame->subclass.format)) {
|
||||
ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), frame->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
|
||||
if (ast_format_cap_iscompatible_format(session->jointcap, frame->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
|
||||
ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n",
|
||||
ast_getformatname(&frame->subclass.format), ast_channel_name(ast));
|
||||
ast_format_get_name(frame->subclass.format), ast_channel_name(ast));
|
||||
ast_frfree(frame);
|
||||
frame = &ast_null_frame;
|
||||
} else {
|
||||
struct ast_format_cap *caps;
|
||||
|
||||
ast_debug(1, "Oooh, format changed to %s\n",
|
||||
ast_getformatname(&frame->subclass.format));
|
||||
ast_format_cap_remove_bytype(ast_channel_nativeformats(ast), AST_FORMAT_TYPE_AUDIO);
|
||||
ast_format_cap_add(ast_channel_nativeformats(ast), &frame->subclass.format);
|
||||
ast_format_get_name(frame->subclass.format));
|
||||
|
||||
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
||||
if (caps) {
|
||||
ast_format_cap_append(caps, frame->subclass.format, 0);
|
||||
ast_channel_nativeformats_set(ast, caps);
|
||||
ao2_ref(caps, -1);
|
||||
}
|
||||
ast_set_read_format(ast, ast_channel_readformat(ast));
|
||||
ast_set_write_format(ast, ast_channel_writeformat(ast));
|
||||
}
|
||||
@@ -1692,17 +1702,18 @@ static int jingle_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||
{
|
||||
struct jingle_session *session = ast_channel_tech_pvt(ast);
|
||||
int res = 0;
|
||||
char buf[256];
|
||||
|
||||
switch (frame->frametype) {
|
||||
case AST_FRAME_VOICE:
|
||||
if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
|
||||
if (ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), frame->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
|
||||
struct ast_str *codec_buf = ast_str_alloca(64);
|
||||
|
||||
ast_log(LOG_WARNING,
|
||||
"Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
|
||||
ast_getformatname(&frame->subclass.format),
|
||||
ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
|
||||
ast_getformatname(ast_channel_readformat(ast)),
|
||||
ast_getformatname(ast_channel_writeformat(ast)));
|
||||
ast_format_get_name(frame->subclass.format),
|
||||
ast_format_cap_get_names(ast_channel_nativeformats(ast), &codec_buf),
|
||||
ast_format_get_name(ast_channel_readformat(ast)),
|
||||
ast_format_get_name(ast_channel_writeformat(ast)));
|
||||
return 0;
|
||||
}
|
||||
if (session && session->rtp) {
|
||||
@@ -1845,7 +1856,7 @@ static int jingle_call(struct ast_channel *ast, const char *dest, int timeout)
|
||||
ast_setstate(ast, AST_STATE_RING);
|
||||
|
||||
/* Since we have no idea of the remote capabilities use ours for now */
|
||||
ast_format_cap_copy(session->jointcap, session->cap);
|
||||
ast_format_cap_append_from_cap(session->jointcap, session->cap, AST_MEDIA_TYPE_UNKNOWN);
|
||||
|
||||
/* We set up a hook so we can know when our session-initiate message was accepted or rejected */
|
||||
session->rule = iks_filter_add_rule(session->connection->filter, jingle_outgoing_hook, session,
|
||||
@@ -1908,7 +1919,7 @@ static struct ast_channel *jingle_request(const char *type, struct ast_format_ca
|
||||
);
|
||||
|
||||
/* We require at a minimum one audio format to be requested */
|
||||
if (!ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO)) {
|
||||
if (!ast_format_cap_has_type(cap, AST_MEDIA_TYPE_AUDIO)) {
|
||||
ast_log(LOG_ERROR, "Motif channel driver requires an audio format when dialing a destination\n");
|
||||
*cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
|
||||
return NULL;
|
||||
@@ -2001,7 +2012,7 @@ static struct ast_channel *jingle_request(const char *type, struct ast_format_ca
|
||||
}
|
||||
|
||||
/* If video was requested try to enable it on the session */
|
||||
if (ast_format_cap_has_type(cap, AST_FORMAT_TYPE_VIDEO)) {
|
||||
if (ast_format_cap_has_type(cap, AST_MEDIA_TYPE_VIDEO)) {
|
||||
jingle_enable_video(session);
|
||||
}
|
||||
|
||||
@@ -2043,8 +2054,8 @@ static int jingle_interpret_description(struct jingle_session *session, iks *des
|
||||
ast_string_field_set(session, audio_name, name);
|
||||
}
|
||||
*rtp = session->rtp;
|
||||
ast_format_cap_remove_bytype(session->peercap, AST_FORMAT_TYPE_AUDIO);
|
||||
ast_format_cap_remove_bytype(session->jointcap, AST_FORMAT_TYPE_AUDIO);
|
||||
ast_format_cap_remove_by_type(session->peercap, AST_MEDIA_TYPE_AUDIO);
|
||||
ast_format_cap_remove_by_type(session->jointcap, AST_MEDIA_TYPE_AUDIO);
|
||||
} else if (!strcasecmp(media, "video")) {
|
||||
if (!ast_strlen_zero(name)) {
|
||||
ast_string_field_set(session, video_name, name);
|
||||
@@ -2060,8 +2071,8 @@ static int jingle_interpret_description(struct jingle_session *session, iks *des
|
||||
return -1;
|
||||
}
|
||||
|
||||
ast_format_cap_remove_bytype(session->peercap, AST_FORMAT_TYPE_VIDEO);
|
||||
ast_format_cap_remove_bytype(session->jointcap, AST_FORMAT_TYPE_VIDEO);
|
||||
ast_format_cap_remove_by_type(session->peercap, AST_MEDIA_TYPE_VIDEO);
|
||||
ast_format_cap_remove_by_type(session->jointcap, AST_MEDIA_TYPE_VIDEO);
|
||||
} else {
|
||||
/* Unknown media type */
|
||||
jingle_queue_hangup_with_cause(session, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
|
||||
@@ -2082,8 +2093,6 @@ static int jingle_interpret_description(struct jingle_session *session, iks *des
|
||||
int rtp_id, rtp_clockrate;
|
||||
|
||||
if (!ast_strlen_zero(id) && !ast_strlen_zero(name) && (sscanf(id, "%30d", &rtp_id) == 1)) {
|
||||
ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, rtp_id);
|
||||
|
||||
if (!ast_strlen_zero(clockrate) && (sscanf(clockrate, "%30d", &rtp_clockrate) == 1)) {
|
||||
ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, rtp_id, media, name, 0, rtp_clockrate);
|
||||
} else {
|
||||
@@ -2093,9 +2102,9 @@ static int jingle_interpret_description(struct jingle_session *session, iks *des
|
||||
}
|
||||
|
||||
ast_rtp_codecs_payload_formats(&codecs, session->peercap, &othercapability);
|
||||
ast_format_cap_joint_append(session->cap, session->peercap, session->jointcap);
|
||||
ast_format_cap_get_compatible(session->cap, session->peercap, session->jointcap);
|
||||
|
||||
if (ast_format_cap_is_empty(session->jointcap)) {
|
||||
if (!ast_format_cap_count(session->jointcap)) {
|
||||
/* We have no compatible codecs, so terminate the session appropriately */
|
||||
jingle_queue_hangup_with_cause(session, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
|
||||
ast_rtp_codecs_payloads_destroy(&codecs);
|
||||
@@ -2355,12 +2364,20 @@ static int jingle_interpret_content(struct jingle_session *session, ikspak *pak)
|
||||
}
|
||||
|
||||
if ((chan = jingle_session_lock_full(session))) {
|
||||
struct ast_format fmt;
|
||||
struct ast_format_cap *caps;
|
||||
struct ast_format *fmt;
|
||||
|
||||
ast_format_cap_copy(ast_channel_nativeformats(chan), session->jointcap);
|
||||
ast_codec_choose(&session->prefs, session->jointcap, 1, &fmt);
|
||||
ast_set_read_format(chan, &fmt);
|
||||
ast_set_write_format(chan, &fmt);
|
||||
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
||||
if (caps) {
|
||||
ast_format_cap_append_from_cap(caps, session->jointcap, AST_MEDIA_TYPE_UNKNOWN);
|
||||
ast_channel_nativeformats_set(chan, caps);
|
||||
ao2_ref(caps, -1);
|
||||
}
|
||||
|
||||
fmt = ast_format_cap_get_format(session->jointcap, 0);
|
||||
ast_set_read_format(chan, fmt);
|
||||
ast_set_write_format(chan, fmt);
|
||||
ao2_ref(fmt, -1);
|
||||
|
||||
ast_channel_unlock(chan);
|
||||
ast_channel_unref(chan);
|
||||
@@ -2710,7 +2727,7 @@ static int custom_transport_handler(const struct aco_option *opt, struct ast_var
|
||||
*/
|
||||
static int load_module(void)
|
||||
{
|
||||
if (!(jingle_tech.capabilities = ast_format_cap_alloc(0))) {
|
||||
if (!(jingle_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
|
||||
return AST_MODULE_LOAD_DECLINE;
|
||||
}
|
||||
|
||||
@@ -2726,8 +2743,8 @@ static int load_module(void)
|
||||
aco_option_register(&cfg_info, "musicclass", ACO_EXACT, endpoint_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct jingle_endpoint, musicclass));
|
||||
aco_option_register(&cfg_info, "parkinglot", ACO_EXACT, endpoint_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct jingle_endpoint, parkinglot));
|
||||
aco_option_register(&cfg_info, "accountcode", ACO_EXACT, endpoint_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct jingle_endpoint, accountcode));
|
||||
aco_option_register(&cfg_info, "allow", ACO_EXACT, endpoint_options, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct jingle_endpoint, prefs, cap));
|
||||
aco_option_register(&cfg_info, "disallow", ACO_EXACT, endpoint_options, "all", OPT_CODEC_T, 0, FLDSET(struct jingle_endpoint, prefs, cap));
|
||||
aco_option_register(&cfg_info, "allow", ACO_EXACT, endpoint_options, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct jingle_endpoint, cap));
|
||||
aco_option_register(&cfg_info, "disallow", ACO_EXACT, endpoint_options, "all", OPT_CODEC_T, 0, FLDSET(struct jingle_endpoint, cap));
|
||||
aco_option_register_custom(&cfg_info, "connection", ACO_EXACT, endpoint_options, NULL, custom_connection_handler, 0);
|
||||
aco_option_register_custom(&cfg_info, "transport", ACO_EXACT, endpoint_options, NULL, custom_transport_handler, 0);
|
||||
aco_option_register(&cfg_info, "maxicecandidates", ACO_EXACT, endpoint_options, DEFAULT_MAX_ICE_CANDIDATES, OPT_UINT_T, PARSE_DEFAULT,
|
||||
@@ -2735,9 +2752,10 @@ static int load_module(void)
|
||||
aco_option_register(&cfg_info, "maxpayloads", ACO_EXACT, endpoint_options, DEFAULT_MAX_PAYLOADS, OPT_UINT_T, PARSE_DEFAULT,
|
||||
FLDSET(struct jingle_endpoint, maxpayloads), DEFAULT_MAX_PAYLOADS);
|
||||
|
||||
ast_format_cap_add_all_by_type(jingle_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
|
||||
ast_format_cap_append_by_type(jingle_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
|
||||
|
||||
if (aco_process_config(&cfg_info, 0)) {
|
||||
ao2_ref(jingle_tech.capabilities, -1);
|
||||
ast_log(LOG_ERROR, "Unable to read config file motif.conf. Module loaded but not running.\n");
|
||||
aco_info_destroy(&cfg_info);
|
||||
return AST_MODULE_LOAD_DECLINE;
|
||||
@@ -2763,6 +2781,7 @@ static int load_module(void)
|
||||
return 0;
|
||||
|
||||
end:
|
||||
ao2_cleanup(jingle_tech.capabilities);
|
||||
ast_rtp_glue_unregister(&jingle_rtp_glue);
|
||||
|
||||
if (sched) {
|
||||
@@ -2784,7 +2803,7 @@ static int reload(void)
|
||||
static int unload_module(void)
|
||||
{
|
||||
ast_channel_unregister(&jingle_tech);
|
||||
ast_format_cap_destroy(jingle_tech.capabilities);
|
||||
ao2_cleanup(jingle_tech.capabilities);
|
||||
jingle_tech.capabilities = NULL;
|
||||
ast_rtp_glue_unregister(&jingle_rtp_glue);
|
||||
ast_sched_context_destroy(sched);
|
||||
|
Reference in New Issue
Block a user