[asterisk-commits] rmudgett: branch rmudgett/iax_fracks r419874 - in /team/rmudgett/iax_fracks: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 31 15:10:54 CDT 2014
Author: rmudgett
Date: Thu Jul 31 15:10:48 2014
New Revision: 419874
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419874
Log:
Initial findings on chan_iax2 for FRACKs.
* Made ast_iax2_new() complain if the given compatibility has no formats
or none of the requested formats are available.
* Fixed off nominal path locking issue in ast_iax2_new().
Modified:
team/rmudgett/iax_fracks/channels/chan_iax2.c
team/rmudgett/iax_fracks/channels/iax2/codec_pref.c
team/rmudgett/iax_fracks/channels/iax2/format_compatibility.c
team/rmudgett/iax_fracks/channels/iax2/include/format_compatibility.h
team/rmudgett/iax_fracks/include/asterisk/format_compatibility.h
team/rmudgett/iax_fracks/main/format_compatibility.c
Modified: team/rmudgett/iax_fracks/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/chan_iax2.c?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/channels/chan_iax2.c (original)
+++ team/rmudgett/iax_fracks/channels/chan_iax2.c Thu Jul 31 15:10:48 2014
@@ -1871,7 +1871,7 @@
{
/* This just our opinion, expressed in code. We are asked to choose
the best codec to use, given no information */
- static const iax2_format prefs[] =
+ static const iax2_format best[] =
{
/*! Okay, ulaw is used by all telephony equipment, so start with it */
AST_FORMAT_ULAW,
@@ -1910,12 +1910,12 @@
/*! Down to G.723.1 which is proprietary but at least designed for voice */
AST_FORMAT_G723,
};
- int x;
+ int idx;
/* Find the first preferred codec in the format given */
- for (x = 0; x < ARRAY_LEN(prefs); x++) {
- if (formats & prefs[x]) {
- return prefs[x];
+ for (idx = 0; idx < ARRAY_LEN(best); ++idx) {
+ if (formats & best[idx]) {
+ return best[idx];
}
}
@@ -4697,9 +4697,12 @@
}
ast_sockaddr_copy(addr, &peer_addr);
- /* use global iax prefs for unknown peer/user */
- /* But move the calling channel's native codec to the top of the preference list */
- memcpy(&ourprefs, &prefs, sizeof(ourprefs));
+ /*
+ * Use The global iax prefs for unknown peer/user.
+ * However, move the calling channel's native codec to
+ * the top of the preference list.
+ */
+ ourprefs = prefs;
if (c) {
int i;
@@ -5893,8 +5896,20 @@
return NULL;
}
+ if (!capability) {
+ ast_log(LOG_WARNING, "No formats specified for call to: IAX2/%s-%d\n",
+ i->host, i->callno);
+ return NULL;
+ }
native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!native) {
+ return NULL;
+ }
+ if (iax2_format_compatibility_bitfield2cap(capability, native)
+ || !ast_format_cap_count(native)) {
+ ast_log(LOG_WARNING, "No requested formats available for call to: IAX2/%s-%d\n",
+ i->host, i->callno);
+ ao2_ref(native, -1);
return NULL;
}
@@ -5910,13 +5925,17 @@
if (!ast_strlen_zero(peer_name)) {
peer = find_peer(peer_name, 1);
if (peer && peer->endpoint) {
- tmp = ast_channel_alloc_with_endpoint(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, peer->endpoint, "IAX2/%s-%d", i->host, i->callno);
+ tmp = ast_channel_alloc_with_endpoint(1, state, i->cid_num, i->cid_name,
+ i->accountcode, i->exten, i->context, assignedids, requestor,
+ i->amaflags, peer->endpoint, "IAX2/%s-%d", i->host, i->callno);
}
ao2_cleanup(peer);
}
if (!tmp) {
- tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, assignedids, requestor, i->amaflags, "IAX2/%s-%d", i->host, i->callno);
+ tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode,
+ i->exten, i->context, assignedids, requestor, i->amaflags, "IAX2/%s-%d",
+ i->host, i->callno);
}
ast_mutex_lock(&iaxsl[callno]);
@@ -5945,9 +5964,8 @@
ast_channel_tech_set(tmp, &iax2_tech);
/* We can support any format by default, until we get restricted */
- iax2_format_compatibility_bitfield2cap(capability, native);
ast_channel_nativeformats_set(tmp, native);
- tmpfmt = ast_format_cap_get_format(ast_channel_nativeformats(tmp), 0);
+ tmpfmt = ast_format_cap_get_format(native, 0);
ast_channel_set_readformat(tmp, tmpfmt);
ast_channel_set_rawreadformat(tmp, tmpfmt);
@@ -6046,8 +6064,10 @@
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
+ /* unlock and relock iaxsl[callno] to preserve locking order */
+ ast_mutex_unlock(&iaxsl[callno]);
ast_hangup(tmp);
- i->owner = NULL;
+ ast_mutex_lock(&iaxsl[callno]);
return NULL;
}
}
@@ -13529,6 +13549,8 @@
ast_sockaddr_parse(&bindaddr, "0.0.0.0:0", 0);
/* Reset global codec prefs */
+/* BUGBUG Use a local prefs list until after config is loaded */
+/* BUGBUG Need to setup the prefs list in with the initial capability setting. */
memset(&prefs, 0 , sizeof(struct iax2_codec_pref));
/* Reset Global Flags */
@@ -13753,6 +13775,7 @@
autokill = 0;
}
} else if (!strcasecmp(v->name, "bandwidth")) {
+/* BUGBUG The bandwidth option needs to update the prefs list as well. */
if (!strcasecmp(v->value, "low")) {
capability = IAX_CAPABILITY_LOWBANDWIDTH;
} else if (!strcasecmp(v->value, "medium")) {
Modified: team/rmudgett/iax_fracks/channels/iax2/codec_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/iax2/codec_pref.c?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/codec_pref.c (original)
+++ team/rmudgett/iax_fracks/channels/iax2/codec_pref.c Thu Jul 31 15:10:48 2014
@@ -47,6 +47,7 @@
static int differential = (int) 'A';
int x;
+/* BUGBUG this function is totally hosed. It has a size mismatch of the objects involved. */
if (right) {
for (x = 0; x < IAX2_CODEC_PREF_SIZE && x < size; x++) {
if (!pref->order[x]) {
@@ -112,7 +113,7 @@
return -1;
}
- /* Convert the preferences into a format cap so that we can read the formst names */
+ /* Convert the preferences into a format cap so that we can read the format names */
for (x = 0; x < IAX2_CODEC_PREF_SIZE; x++) {
uint64_t bitfield = iax2_codec_pref_order_value_to_format_bitfield(pref->order[x]);
if (!bitfield) {
Modified: team/rmudgett/iax_fracks/channels/iax2/format_compatibility.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/iax2/format_compatibility.c?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/format_compatibility.c (original)
+++ team/rmudgett/iax_fracks/channels/iax2/format_compatibility.c Thu Jul 31 15:10:48 2014
@@ -59,13 +59,19 @@
int iax2_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap)
{
- int x;
+ int bit;
- for (x = 0; x < 64; x++) {
- uint64_t tmp = (1ULL << x);
+/* BUGBUG probably should add the codecs in the preference order using iax2_best_codec(). */
+ for (bit = 0; bit < 64; ++bit) {
+ uint64_t mask = (1ULL << bit);
- if ((tmp & bitfield) && ast_format_cap_append(cap, ast_format_compatibility_bitfield2format(tmp), 0)) {
- return -1;
+ if (mask & bitfield) {
+ struct ast_format *format;
+
+ format = ast_format_compatibility_bitfield2format(mask);
+ if (ast_format_cap_append(cap, format, 0)) {
+ return -1;
+ }
}
}
Modified: team/rmudgett/iax_fracks/channels/iax2/include/format_compatibility.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/channels/iax2/include/format_compatibility.h?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/channels/iax2/include/format_compatibility.h (original)
+++ team/rmudgett/iax_fracks/channels/iax2/include/format_compatibility.h Thu Jul 31 15:10:48 2014
@@ -45,8 +45,8 @@
* \param bitfield The bitfield for the media formats
* \param cap Capabilities structure to place formats into
*
- * \retval non-NULL success
- * \retval NULL failure
+ * \retval 0 on success.
+ * \retval -1 on error.
*
* \note If failure occurs the capabilities structure may contain a partial set of formats
*/
Modified: team/rmudgett/iax_fracks/include/asterisk/format_compatibility.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/include/asterisk/format_compatibility.h?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/include/asterisk/format_compatibility.h (original)
+++ team/rmudgett/iax_fracks/include/asterisk/format_compatibility.h Thu Jul 31 15:10:48 2014
@@ -120,7 +120,7 @@
* \param bitfield The bitfield for the media format
*
* \retval non-NULL success
- * \retval NULL failure
+ * \retval NULL failure (The format bitfield value is not supported)
*
* \note The reference count of the returned format is NOT incremented
*/
Modified: team/rmudgett/iax_fracks/main/format_compatibility.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/iax_fracks/main/format_compatibility.c?view=diff&rev=419874&r1=419873&r2=419874
==============================================================================
--- team/rmudgett/iax_fracks/main/format_compatibility.c (original)
+++ team/rmudgett/iax_fracks/main/format_compatibility.c Thu Jul 31 15:10:48 2014
@@ -269,6 +269,6 @@
case AST_FORMAT_T140:
return ast_format_t140_red;
}
- return 0;
+ return NULL;
}
More information about the asterisk-commits
mailing list