mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
* Fixed the iax.conf bandwidth option. This is the root cause of ASTERISK-24150. * Added checks in iax2_request() to ensure that there are actual formats requested for the new channel to prevent any more fracks from issues like ASTERISK-24150. This is a consequence of the iax.conf bandwidth option not working. * Fixed struct iax2_codec_pref.order member size mismatch issue when converting to and from the codec preference order list passed over the wire. In addition the values sent over the wire are now compatible with previous Asterisk versions. * Fixed several issues dealing with the struct iax2_codec_pref members. Off-by-one, array limit errors, and the order/framing members always need to be updated together. * Made iax2_request() setup the channel's native format preference order according to the user's wishes. The new media format strategy needs the order specified earler. * Fixed usage of ast_format_compatibility_bitfield2format(). The function can return NULL if the bitfield was not associated with a function. * Deleted dead code iax2_codec_pref_getsize() and iax2_codec_pref_setsize(). * Made iax2_parse_allow_disallow() and iax2_codec_pref_string() call iax2_codec_pref_to_cap() instead of inlining it. * Made IAX_CAPABILITY_MEDBANDWIDTH, IAX_CAPABILITY_LOWBANDWIDTH, and IAX_CAPABILITY_LOWFREE constants again as they were in Asterisk v1.8. * Renamed prefs to prefs_global so it won't get confused with the local pref versions. * Fixed too small buffer in handle_cli_iax2_show_peer(). * Fixed ast_cli() calls in handle_cli_iax2_show_peer() to output complete lines. * Changed struct create_addr_info.prefs to be struct iax2_codec_pref as an optimization so iax2_request() and iax2_call() do less work. * Fixed a potential deadlock in ast_iax2_new() on an off-nominal path when the pbx could not get started. * Made set_config() setup a local prefs list along side the local capability format bitfield. Once the config is loaded, then the local copies are put into the global versions. * Fix unininialized codec_buf in function_iaxpeer(). ASTERISK-24150 #close Reported by: Scott Griepentrog Review: https://reviewboard.asterisk.org/r/3890/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@420364 65c4cc65-6c06-0410-ace0-fbb531ad65f3
137 lines
3.6 KiB
C
137 lines
3.6 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (C) 2014, Digium, Inc.
|
|
*
|
|
* Joshua Colp <jcolp@digium.com>
|
|
*
|
|
* See http://www.asterisk.org for more information about
|
|
* the Asterisk project. Please do not directly contact
|
|
* any of the maintainers of this project for assistance;
|
|
* the project provides a web site, mailing lists and IRC
|
|
* channels for your use.
|
|
*
|
|
* This program is free software, distributed under the terms of
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
* at the top of the source tree.
|
|
*/
|
|
|
|
/*! \file
|
|
*
|
|
* \brief Media Format Bitfield Compatibility API
|
|
*
|
|
* \author Joshua Colp <jcolp@digium.com>
|
|
*/
|
|
|
|
/*** MODULEINFO
|
|
<support_level>core</support_level>
|
|
***/
|
|
|
|
#include "asterisk.h"
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
#include "asterisk/logger.h"
|
|
#include "asterisk/astobj2.h"
|
|
#include "asterisk/codec.h"
|
|
#include "asterisk/format.h"
|
|
#include "asterisk/format_compatibility.h"
|
|
#include "asterisk/format_cache.h"
|
|
#include "asterisk/format_cap.h"
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "include/format_compatibility.h"
|
|
|
|
uint64_t iax2_format_compatibility_cap2bitfield(const struct ast_format_cap *cap)
|
|
{
|
|
uint64_t bitfield = 0;
|
|
int x;
|
|
|
|
for (x = 0; x < ast_format_cap_count(cap); x++) {
|
|
struct ast_format *format = ast_format_cap_get_format(cap, x);
|
|
|
|
bitfield |= ast_format_compatibility_format2bitfield(format);
|
|
|
|
ao2_ref(format, -1);
|
|
}
|
|
|
|
return bitfield;
|
|
}
|
|
|
|
int iax2_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap)
|
|
{
|
|
int bit;
|
|
|
|
for (bit = 0; bit < 64; ++bit) {
|
|
uint64_t mask = (1ULL << bit);
|
|
|
|
if (mask & bitfield) {
|
|
struct ast_format *format;
|
|
|
|
format = ast_format_compatibility_bitfield2format(mask);
|
|
if (format && ast_format_cap_append(cap, format, 0)) {
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint64_t iax2_format_compatibility_best(uint64_t formats)
|
|
{
|
|
/*
|
|
* This just our opinion, expressed in code. We are
|
|
* asked to choose the best codec to use, given no
|
|
* information.
|
|
*/
|
|
static const uint64_t best[] = {
|
|
/*! Okay, ulaw is used by all telephony equipment, so start with it */
|
|
AST_FORMAT_ULAW,
|
|
/*! Unless of course, you're a silly European, so then prefer ALAW */
|
|
AST_FORMAT_ALAW,
|
|
AST_FORMAT_G719,
|
|
AST_FORMAT_SIREN14,
|
|
AST_FORMAT_SIREN7,
|
|
AST_FORMAT_TESTLAW,
|
|
/*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
|
|
AST_FORMAT_G722,
|
|
/*! Okay, well, signed linear is easy to translate into other stuff */
|
|
AST_FORMAT_SLIN16,
|
|
AST_FORMAT_SLIN,
|
|
/*! G.726 is standard ADPCM, in RFC3551 packing order */
|
|
AST_FORMAT_G726,
|
|
/*! G.726 is standard ADPCM, in AAL2 packing order */
|
|
AST_FORMAT_G726_AAL2,
|
|
/*! ADPCM has great sound quality and is still pretty easy to translate */
|
|
AST_FORMAT_ADPCM,
|
|
/*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
|
|
translate and sounds pretty good */
|
|
AST_FORMAT_GSM,
|
|
/*! iLBC is not too bad */
|
|
AST_FORMAT_ILBC,
|
|
/*! Speex is free, but computationally more expensive than GSM */
|
|
AST_FORMAT_SPEEX16,
|
|
AST_FORMAT_SPEEX,
|
|
/*! Opus */
|
|
AST_FORMAT_OPUS,
|
|
/*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
|
|
to use it */
|
|
AST_FORMAT_LPC10,
|
|
/*! G.729a is faster than 723 and slightly less expensive */
|
|
AST_FORMAT_G729,
|
|
/*! Down to G.723.1 which is proprietary but at least designed for voice */
|
|
AST_FORMAT_G723,
|
|
};
|
|
int idx;
|
|
|
|
/* Find the first preferred codec in the format given */
|
|
for (idx = 0; idx < ARRAY_LEN(best); ++idx) {
|
|
if (formats & best[idx]) {
|
|
return best[idx];
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|