summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-07-20 22:06:33 +0000
committerMatthew Jordan <mjordan@digium.com>2014-07-20 22:06:33 +0000
commita2c912e9972c91973ea66902d217746133f96026 (patch)
tree50e01d14ba62950e3f78766d5ba435ba51ca327d /apps
parentb299052e203807c9a2111eb2cd919246d7589cb3 (diff)
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
Diffstat (limited to 'apps')
-rw-r--r--apps/app_agent_pool.c4
-rw-r--r--apps/app_alarmreceiver.c13
-rw-r--r--apps/app_amd.c20
-rw-r--r--apps/app_chanspy.c38
-rw-r--r--apps/app_confbridge.c21
-rw-r--r--apps/app_dictate.c14
-rw-r--r--apps/app_dumpchan.c12
-rw-r--r--apps/app_echo.c5
-rw-r--r--apps/app_fax.c49
-rw-r--r--apps/app_festival.c26
-rw-r--r--apps/app_ices.c14
-rw-r--r--apps/app_jack.c29
-rw-r--r--apps/app_meetme.c43
-rw-r--r--apps/app_milliwatt.c15
-rw-r--r--apps/app_mixmonitor.c10
-rw-r--r--apps/app_mp3.c31
-rw-r--r--apps/app_nbscat.c32
-rw-r--r--apps/app_originate.c25
-rw-r--r--apps/app_record.c13
-rw-r--r--apps/app_sms.c17
-rw-r--r--apps/app_speech_utils.c9
-rw-r--r--apps/app_talkdetect.c16
-rw-r--r--apps/app_test.c17
-rw-r--r--apps/app_voicemail.c29
-rw-r--r--apps/app_waitforsilence.c11
-rw-r--r--apps/confbridge/conf_chan_record.c21
26 files changed, 282 insertions, 252 deletions
diff --git a/apps/app_agent_pool.c b/apps/app_agent_pool.c
index 5095001cf..f531c1613 100644
--- a/apps/app_agent_pool.c
+++ b/apps/app_agent_pool.c
@@ -2136,8 +2136,8 @@ static int agent_login_exec(struct ast_channel *chan, const char *data)
}
ast_verb(2, "Agent '%s' logged in (format %s/%s)\n", agent->username,
- ast_getformatname(ast_channel_readformat(chan)),
- ast_getformatname(ast_channel_writeformat(chan)));
+ ast_format_get_name(ast_channel_readformat(chan)),
+ ast_format_get_name(ast_channel_writeformat(chan)));
ast_channel_lock(chan);
send_agent_login(chan, agent->username);
ast_channel_unlock(chan);
diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c
index 9063e1a60..4f9de364d 100644
--- a/apps/app_alarmreceiver.c
+++ b/apps/app_alarmreceiver.c
@@ -65,6 +65,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/astdb.h"
#include "asterisk/utils.h"
#include "asterisk/indications.h"
+#include "asterisk/format_cache.h"
#define ALMRCV_CONFIG "alarmreceiver.conf"
#define UNKNOWN_FORMAT "UNKNOWN_FORMAT"
@@ -798,19 +799,19 @@ static int alarmreceiver_exec(struct ast_channel *chan, const char *data)
char signalling_type[64] = "";
event_node_t *event_head = NULL;
- if (ast_channel_writeformat(chan)->id != AST_FORMAT_ALAW
- && ast_channel_writeformat(chan)->id != AST_FORMAT_ULAW) {
+ if ((ast_format_cmp(ast_channel_writeformat(chan), ast_format_ulaw) == AST_FORMAT_CMP_NOT_EQUAL) &&
+ (ast_format_cmp(ast_channel_writeformat(chan), ast_format_alaw) == AST_FORMAT_CMP_NOT_EQUAL)) {
ast_verb(4, "AlarmReceiver: Setting write format to Mu-law\n");
- if (ast_set_write_format_by_id(chan,AST_FORMAT_ULAW)) {
+ if (ast_set_write_format(chan, ast_format_ulaw)) {
ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",ast_channel_name(chan));
return -1;
}
}
- if (ast_channel_readformat(chan)->id != AST_FORMAT_ALAW
- && ast_channel_readformat(chan)->id != AST_FORMAT_ULAW) {
+ if ((ast_format_cmp(ast_channel_readformat(chan), ast_format_ulaw) == AST_FORMAT_CMP_NOT_EQUAL) &&
+ (ast_format_cmp(ast_channel_readformat(chan), ast_format_alaw) == AST_FORMAT_CMP_NOT_EQUAL)) {
ast_verb(4, "AlarmReceiver: Setting read format to Mu-law\n");
- if (ast_set_read_format_by_id(chan,AST_FORMAT_ULAW)) {
+ if (ast_set_read_format(chan, ast_format_ulaw)) {
ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",ast_channel_name(chan));
return -1;
}
diff --git a/apps/app_amd.c b/apps/app_amd.c
index d8f26b49b..3dd8cc617 100644
--- a/apps/app_amd.c
+++ b/apps/app_amd.c
@@ -52,6 +52,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="AMD" language="en_US">
@@ -163,7 +164,7 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
struct ast_frame *f = NULL;
struct ast_dsp *silenceDetector = NULL;
int dspsilence = 0, framelength = 0;
- struct ast_format readFormat;
+ RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);
int inInitialSilence = 1;
int inGreeting = 0;
int voiceDuration = 0;
@@ -202,11 +203,10 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
AST_APP_ARG(argMaximumWordLength);
);
- ast_format_clear(&readFormat);
ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan),
S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, "(N/A)"),
S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "(N/A)"),
- ast_getformatname(ast_channel_readformat(chan)));
+ ast_format_get_name(ast_channel_readformat(chan)));
/* Lets parse the arguments. */
if (!ast_strlen_zero(parse)) {
@@ -255,8 +255,8 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold, maximumWordLength);
/* Set read format to signed linear so we get signed linear frames in */
- ast_format_copy(&readFormat, ast_channel_readformat(chan));
- if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0 ) {
+ readFormat = ao2_bump(ast_channel_readformat(chan));
+ if (ast_set_read_format(chan, ast_format_slin) < 0 ) {
ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", ast_channel_name(chan));
pbx_builtin_setvar_helper(chan , "AMDSTATUS", "");
pbx_builtin_setvar_helper(chan , "AMDCAUSE", "");
@@ -289,7 +289,7 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
/* If the total time exceeds the analysis time then give up as we are not too sure */
if (f->frametype == AST_FRAME_VOICE) {
- framelength = (ast_codec_get_samples(f) / DEFAULT_SAMPLES_PER_MS);
+ framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
} else {
framelength = 2 * maxWaitTimeForFrame;
}
@@ -412,7 +412,7 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause);
/* Restore channel read format */
- if (readFormat.id && ast_set_read_format(chan, &readFormat))
+ if (readFormat && ast_set_read_format(chan, readFormat))
ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", ast_channel_name(chan));
/* Free the DSP used to detect silence */
@@ -510,10 +510,10 @@ static int unload_module(void)
*/
static int load_module(void)
{
- if (load_config(0))
+ if (load_config(0) || ast_register_application_xml(app, amd_exec)) {
return AST_MODULE_LOAD_DECLINE;
- if (ast_register_application_xml(app, amd_exec))
- return AST_MODULE_LOAD_FAILURE;
+ }
+
return AST_MODULE_LOAD_SUCCESS;
}
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index 47f755e5f..af69be303 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -57,6 +57,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/autochan.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/json.h"
+#include "asterisk/format_cache.h"
#define AST_NAME_STRLEN 256
#define NUM_SPYGROUPS 128
@@ -451,9 +452,6 @@ static int spy_generate(struct ast_channel *chan, void *data, int len, int sampl
{
struct chanspy_translation_helper *csth = data;
struct ast_frame *f, *cur;
- struct ast_format format_slin;
-
- ast_format_set(&format_slin, AST_FORMAT_SLINEAR, 0);
ast_audiohook_lock(&csth->spy_audiohook);
if (csth->spy_audiohook.status != AST_AUDIOHOOK_STATUS_RUNNING) {
@@ -464,9 +462,9 @@ static int spy_generate(struct ast_channel *chan, void *data, int len, int sampl
if (ast_test_flag(&csth->flags, OPTION_READONLY)) {
/* Option 'o' was set, so don't mix channel audio */
- f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_READ, &format_slin);
+ f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_READ, ast_format_slin);
} else {
- f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, &format_slin);
+ f = ast_audiohook_read_frame(&csth->spy_audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, ast_format_slin);
}
ast_audiohook_unlock(&csth->spy_audiohook);
@@ -1181,7 +1179,7 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
.volume = '#',
.exit = '\0',
};
- struct ast_format oldwf;
+ RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
int volfactor = 0;
int res;
char *mailbox = NULL;
@@ -1194,7 +1192,6 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
char *parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
- ast_format_clear(&oldwf);
if (args.spec && !strcmp(args.spec, "all"))
args.spec = NULL;
@@ -1258,8 +1255,8 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
ast_clear_flag(&flags, AST_FLAGS_ALL);
}
- ast_format_copy(&oldwf, ast_channel_writeformat(chan));
- if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+ oldwf = ao2_bump(ast_channel_writeformat(chan));
+ if (ast_set_write_format(chan, ast_format_slin) < 0) {
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
return -1;
}
@@ -1279,7 +1276,7 @@ static int chanspy_exec(struct ast_channel *chan, const char *data)
if (fd)
close(fd);
- if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
+ if (oldwf && ast_set_write_format(chan, oldwf) < 0)
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
if (ast_test_flag(&flags, OPTION_EXITONHANGUP)) {
@@ -1301,7 +1298,7 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
.volume = '#',
.exit = '\0',
};
- struct ast_format oldwf;
+ RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
int volfactor = 0;
int res;
char *mailbox = NULL;
@@ -1313,7 +1310,6 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
char *parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
- ast_format_clear(&oldwf);
if (!ast_strlen_zero(args.context) && (ptr = strchr(args.context, '@'))) {
exten = args.context;
@@ -1383,8 +1379,8 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
ast_clear_flag(&flags, AST_FLAGS_ALL);
}
- ast_format_copy(&oldwf, ast_channel_writeformat(chan));
- if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+ oldwf = ao2_bump(ast_channel_writeformat(chan));
+ if (ast_set_write_format(chan, ast_format_slin) < 0) {
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
return -1;
}
@@ -1405,7 +1401,7 @@ static int extenspy_exec(struct ast_channel *chan, const char *data)
if (fd)
close(fd);
- if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
+ if (oldwf && ast_set_write_format(chan, oldwf) < 0)
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
return res;
@@ -1420,13 +1416,13 @@ static int dahdiscan_exec(struct ast_channel *chan, const char *data)
.volume = '\0',
.exit = '*',
};
- struct ast_format oldwf;
+ struct ast_format *oldwf;
int res;
char *mygroup = NULL;
/* Coverity - This uninit_use should be ignored since this macro initializes the flags */
ast_clear_flag(&flags, AST_FLAGS_ALL);
- ast_format_clear(&oldwf);
+
if (!ast_strlen_zero(data)) {
mygroup = ast_strdupa(data);
}
@@ -1434,16 +1430,18 @@ static int dahdiscan_exec(struct ast_channel *chan, const char *data)
ast_set_flag(&flags, OPTION_DTMF_CYCLE);
ast_set_flag(&flags, OPTION_DAHDI_SCAN);
- ast_format_copy(&oldwf, ast_channel_writeformat(chan));
- if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+ oldwf = ao2_bump(ast_channel_writeformat(chan));
+ if (ast_set_write_format(chan, ast_format_slin) < 0) {
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+ ao2_cleanup(oldwf);
return -1;
}
res = common_exec(chan, &flags, 0, 0, &user_options, mygroup, NULL, spec, NULL, NULL, NULL, NULL);
- if (oldwf.id && ast_set_write_format(chan, &oldwf) < 0)
+ if (oldwf && ast_set_write_format(chan, oldwf) < 0)
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+ ao2_cleanup(oldwf);
return res;
}
diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index 9a704ac93..445b196d4 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -70,6 +70,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/stasis.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/json.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="ConfBridge" language="en_US">
@@ -676,7 +677,6 @@ static int conf_stop_record_thread(struct confbridge_conference *conference)
static int conf_start_record(struct confbridge_conference *conference)
{
struct ast_format_cap *cap;
- struct ast_format format;
if (conference->record_state != CONF_RECORD_STOP) {
return -1;
@@ -687,16 +687,16 @@ static int conf_start_record(struct confbridge_conference *conference)
return -1;
}
- cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return -1;
}
- ast_format_cap_add(cap, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
+ ast_format_cap_append(cap, ast_format_slin, 0);
conference->record_chan = ast_request("CBRec", cap, NULL, NULL,
conference->name, NULL);
- cap = ast_format_cap_destroy(cap);
+ ao2_ref(cap, -1);
if (!conference->record_chan) {
return -1;
}
@@ -1374,16 +1374,15 @@ static void leave_conference(struct confbridge_user *user)
static int alloc_playback_chan(struct confbridge_conference *conference)
{
struct ast_format_cap *cap;
- struct ast_format format;
- cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap) {
return -1;
}
- ast_format_cap_add(cap, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
+ ast_format_cap_append(cap, ast_format_slin, 0);
conference->playback_chan = ast_request("CBAnn", cap, NULL, NULL,
conference->name, NULL);
- cap = ast_format_cap_destroy(cap);
+ ao2_ref(cap, -1);
if (!conference->playback_chan) {
return -1;
}
@@ -3238,7 +3237,7 @@ void conf_remove_user_waiting(struct confbridge_conference *conference, struct c
static void unregister_channel_tech(struct ast_channel_tech *tech)
{
ast_channel_unregister(tech);
- tech->capabilities = ast_format_cap_destroy(tech->capabilities);
+ ao2_cleanup(tech->capabilities);
}
/*!
@@ -3253,11 +3252,11 @@ static void unregister_channel_tech(struct ast_channel_tech *tech)
*/
static int register_channel_tech(struct ast_channel_tech *tech)
{
- tech->capabilities = ast_format_cap_alloc(0);
+ tech->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!tech->capabilities) {
return -1;
}
- ast_format_cap_add_all(tech->capabilities);
+ ast_format_cap_append_by_type(tech->capabilities, AST_MEDIA_TYPE_UNKNOWN);
if (ast_channel_register(tech)) {
ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",
tech->type, tech->description);
diff --git a/apps/app_dictate.c b/apps/app_dictate.c
index 1820a1f83..8f229f2a9 100644
--- a/apps/app_dictate.c
+++ b/apps/app_dictate.c
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/say.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="Dictate" language="en_US">
@@ -108,8 +109,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
len = 0,
maxlen = 0,
mode = 0;
- struct ast_format oldr;
- ast_format_clear(&oldr);
+ struct ast_format *oldr;
snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
if (!ast_strlen_zero(data)) {
@@ -126,9 +126,10 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
if (args.argc > 1 && args.filename) {
filename = args.filename;
}
- ast_format_copy(&oldr, ast_channel_readformat(chan));
- if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
+ oldr = ao2_bump(ast_channel_readformat(chan));
+ if ((res = ast_set_read_format(chan, ast_format_slin)) < 0) {
ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
+ ao2_cleanup(oldr);
return -1;
}
@@ -335,8 +336,9 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
ast_frfree(f);
}
}
- if (oldr.id) {
- ast_set_read_format(chan, &oldr);
+ if (oldr) {
+ ast_set_read_format(chan, oldr);
+ ao2_ref(oldr, -1);
}
return 0;
}
diff --git a/apps/app_dumpchan.c b/apps/app_dumpchan.c
index 5c5be18af..1794c2565 100644
--- a/apps/app_dumpchan.c
+++ b/apps/app_dumpchan.c
@@ -72,7 +72,7 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
{
long elapsed_seconds = 0;
int hour = 0, min = 0, sec = 0;
- char nf[256];
+ struct ast_str *format_buf = ast_str_alloca(64);
char cgrp[256];
char pgrp[256];
struct ast_str *write_transpath = ast_str_alloca(256);
@@ -143,11 +143,11 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
ast_state2str(ast_channel_state(c)),
ast_channel_state(c),
ast_channel_rings(c),
- ast_getformatname_multiple(nf, sizeof(nf), ast_channel_nativeformats(c)),
- ast_getformatname(ast_channel_writeformat(c)),
- ast_getformatname(ast_channel_readformat(c)),
- ast_getformatname(ast_channel_rawwriteformat(c)),
- ast_getformatname(ast_channel_rawreadformat(c)),
+ ast_format_cap_get_names(ast_channel_nativeformats(c), &format_buf),
+ ast_format_get_name(ast_channel_writeformat(c)),
+ ast_format_get_name(ast_channel_readformat(c)),
+ ast_format_get_name(ast_channel_rawwriteformat(c)),
+ ast_format_get_name(ast_channel_rawreadformat(c)),
ast_channel_writetrans(c) ? "Yes" : "No",
ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
ast_channel_readtrans(c) ? "Yes" : "No",
diff --git a/apps/app_echo.c b/apps/app_echo.c
index df5a914f1..d8b207967 100644
--- a/apps/app_echo.c
+++ b/apps/app_echo.c
@@ -58,11 +58,6 @@ static const char app[] = "Echo";
static int echo_exec(struct ast_channel *chan, const char *data)
{
int res = -1;
- struct ast_format format;
-
- ast_best_codec(ast_channel_nativeformats(chan), &format);
- ast_set_write_format(chan, &format);
- ast_set_read_format(chan, &format);
while (ast_waitfor(chan, -1) > -1) {
struct ast_frame *f = ast_read(chan);
diff --git a/apps/app_fax.c b/apps/app_fax.c
index e23ac431e..ceff38fef 100644
--- a/apps/app_fax.c
+++ b/apps/app_fax.c
@@ -45,6 +45,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="SendFAX" language="en_US" module="app_fax">
@@ -332,9 +333,9 @@ static int fax_generator_generate(struct ast_channel *chan, void *data, int len,
struct ast_frame outf = {
.frametype = AST_FRAME_VOICE,
+ .subclass.format = ast_format_slin,
.src = __FUNCTION__,
};
- ast_format_set(&outf.subclass.format, AST_FORMAT_SLINEAR, 0);
if (samples > MAX_SAMPLES) {
ast_log(LOG_WARNING, "Only generating %d samples, where %d requested\n", MAX_SAMPLES, samples);
@@ -365,8 +366,8 @@ static struct ast_generator generator = {
static int transmit_audio(fax_session *s)
{
int res = -1;
- struct ast_format original_read_fmt;
- struct ast_format original_write_fmt;
+ struct ast_format *original_read_fmt;
+ struct ast_format *original_write_fmt = NULL;
fax_state_t fax;
t30_state_t *t30state;
struct ast_frame *inf = NULL;
@@ -386,9 +387,6 @@ static int transmit_audio(fax_session *s)
*/
};
- ast_format_clear(&original_read_fmt);
- ast_format_clear(&original_write_fmt);
-
/* if in called party mode, try to use T.38 */
if (s->caller_mode == FALSE) {
/* check if we are already in T.38 mode (unlikely), or if we can request
@@ -461,22 +459,18 @@ static int transmit_audio(fax_session *s)
t30state = &fax.t30_state;
#endif
- ast_format_copy(&original_read_fmt, ast_channel_readformat(s->chan));
- if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
- res = ast_set_read_format_by_id(s->chan, AST_FORMAT_SLINEAR);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
- goto done;
- }
+ original_read_fmt = ao2_bump(ast_channel_readformat(s->chan));
+ res = ast_set_read_format(s->chan, ast_format_slin);
+ if (res < 0) {
+ ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
+ goto done;
}
- ast_format_copy(&original_write_fmt, ast_channel_writeformat(s->chan));
- if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
- res = ast_set_write_format_by_id(s->chan, AST_FORMAT_SLINEAR);
- if (res < 0) {
- ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
- goto done;
- }
+ original_write_fmt = ao2_bump(ast_channel_writeformat(s->chan));
+ res = ast_set_write_format(s->chan, ast_format_slin);
+ if (res < 0) {
+ ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
+ goto done;
}
/* Initialize T30 terminal */
@@ -529,12 +523,13 @@ static int transmit_audio(fax_session *s)
break;
}
- ast_debug(10, "frame %d/%u, len=%d\n", inf->frametype, (unsigned int) inf->subclass.format.id, inf->datalen);
+ ast_debug(10, "frame %d/%s, len=%d\n", inf->frametype, ast_format_get_name(inf->subclass.format), inf->datalen);
/* Check the frame type. Format also must be checked because there is a chance
that a frame in old format was already queued before we set channel format
to slinear so it will still be received by ast_read */
- if (inf->frametype == AST_FRAME_VOICE && inf->subclass.format.id == AST_FORMAT_SLINEAR) {
+ if (inf->frametype == AST_FRAME_VOICE &&
+ (ast_format_cmp(inf->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
if (fax_rx(&fax, inf->data.ptr, inf->samples) < 0) {
/* I know fax_rx never returns errors. The check here is for good style only */
ast_log(LOG_WARNING, "fax_rx returned error\n");
@@ -588,14 +583,16 @@ static int transmit_audio(fax_session *s)
fax_release(&fax);
done:
- if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
- if (ast_set_write_format(s->chan, &original_write_fmt) < 0)
+ if (original_write_fmt) {
+ if (ast_set_write_format(s->chan, original_write_fmt) < 0)
ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", ast_channel_name(s->chan));
+ ao2_ref(original_write_fmt, -1);
}
- if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
- if (ast_set_read_format(s->chan, &original_read_fmt) < 0)
+ if (original_read_fmt) {
+ if (ast_set_read_format(s->chan, original_read_fmt) < 0)
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(s->chan));
+ ao2_ref(original_read_fmt, -1);
}
return res;
diff --git a/apps/app_festival.c b/apps/app_festival.c
index 3ccacb195..3626563c6 100644
--- a/apps/app_festival.c
+++ b/apps/app_festival.c
@@ -63,6 +63,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/endian.h"
+#include "asterisk/format_cache.h"
#define FESTIVAL_CONFIG "festival.conf"
#define MAXLEN 180
@@ -177,7 +178,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
int res = 0;
int fds[2];
int needed = 0;
- struct ast_format owriteformat;
+ struct ast_format *owriteformat;
struct ast_frame *f;
struct myframe {
struct ast_frame f;
@@ -187,7 +188,6 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
.f = { 0, },
};
- ast_format_clear(&owriteformat);
if (pipe(fds)) {
ast_log(LOG_WARNING, "Unable to create pipe\n");
return -1;
@@ -199,12 +199,19 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
ast_stopstream(chan);
ast_indicate(chan, -1);
- ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
- res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+ owriteformat = ao2_bump(ast_channel_writeformat(chan));
+ res = ast_set_write_format(chan, ast_format_slin);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+ ao2_cleanup(owriteformat);
return -1;
}
+
+ myf.f.frametype = AST_FRAME_VOICE;
+ myf.f.subclass.format = ast_format_slin;
+ myf.f.offset = AST_FRIENDLY_OFFSET;
+ myf.f.src = __PRETTY_FUNCTION__;
+ myf.f.data.ptr = myf.frdata;
res = send_waveform_to_fd(waveform, length, fds[1]);
if (res >= 0) {
@@ -240,13 +247,8 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
}
res = read(fds[0], myf.frdata, needed);
if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
myf.f.datalen = res;
myf.f.samples = res / 2;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.data.ptr = myf.frdata;
if (ast_write(chan, &myf.f) < 0) {
res = -1;
ast_frfree(f);
@@ -269,8 +271,10 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
close(fds[0]);
close(fds[1]);
- if (!res && owriteformat.id)
- ast_set_write_format(chan, &owriteformat);
+ if (!res && owriteformat)
+ ast_set_write_format(chan, owriteformat);
+ ao2_cleanup(owriteformat);
+
return res;
}
diff --git a/apps/app_ices.c b/apps/app_ices.c
index bdccff43f..3122273c7 100644
--- a/apps/app_ices.c
+++ b/apps/app_ices.c
@@ -48,6 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="ICES" language="en_US">
@@ -115,12 +116,11 @@ static int ices_exec(struct ast_channel *chan, const char *data)
int ms = -1;
int pid = -1;
int flags;
- struct ast_format oreadformat;
+ struct ast_format *oreadformat;
struct ast_frame *f;
char filename[256]="";
char *c;
- ast_format_clear(&oreadformat);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "ICES requires an argument (configfile.xml)\n");
return -1;
@@ -145,12 +145,13 @@ static int ices_exec(struct ast_channel *chan, const char *data)
return -1;
}
- ast_format_copy(&oreadformat, ast_channel_readformat(chan));
- res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+ oreadformat = ao2_bump(ast_channel_readformat(chan));
+ res = ast_set_read_format(chan, ast_format_slin);
if (res < 0) {
close(fds[0]);
close(fds[1]);
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+ ao2_cleanup(oreadformat);
return -1;
}
if (((char *)data)[0] == '/')
@@ -197,8 +198,9 @@ static int ices_exec(struct ast_channel *chan, const char *data)
if (pid > -1)
kill(pid, SIGKILL);
- if (!res && oreadformat.id)
- ast_set_read_format(chan, &oreadformat);
+ if (!res && oreadformat)
+ ast_set_read_format(chan, oreadformat);
+ ao2_cleanup(oreadformat);
return res;
}
diff --git a/apps/app_jack.c b/apps/app_jack.c
index 9c59ceaf4..8adfbc4cb 100644
--- a/apps/app_jack.c
+++ b/apps/app_jack.c
@@ -58,6 +58,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/audiohook.h"
+#include "asterisk/format_cache.h"
#define RESAMPLE_QUALITY 1
@@ -129,7 +130,7 @@ struct jack_data {
jack_port_t *output_port;
jack_ringbuffer_t *input_rb;
jack_ringbuffer_t *output_rb;
- enum ast_format_id audiohook_format_id;
+ struct ast_format *audiohook_format;
unsigned int audiohook_rate;
unsigned int frame_datalen;
void *output_resampler;
@@ -394,7 +395,6 @@ static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
jack_status_t status = 0;
jack_options_t jack_options = JackNullOption;
- struct ast_format format_slin;
unsigned int channel_rate;
unsigned int ringbuffer_size;
@@ -402,19 +402,17 @@ static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
/* Deducing audiohook sample rate from channel format
ATTENTION: Might be problematic, if channel has different sampling than used by audiohook!
*/
- channel_rate = ast_format_rate(ast_channel_readformat(chan));
- jack_data->audiohook_format_id = ast_format_slin_by_rate(channel_rate);
-
- ast_format_set(&format_slin, jack_data->audiohook_format_id, 0);
- jack_data->audiohook_rate = ast_format_rate(&format_slin);
+ channel_rate = ast_format_get_sample_rate(ast_channel_readformat(chan));
+ jack_data->audiohook_format = ast_format_cache_get_slin_by_rate(channel_rate);
+ jack_data->audiohook_rate = ast_format_get_sample_rate(jack_data->audiohook_format);
/* Guessing frame->datalen assuming a ptime of 20ms */
jack_data->frame_datalen = jack_data->audiohook_rate / 50;
ringbuffer_size = jack_data->frame_datalen * RINGBUFFER_FRAME_CAPACITY;
- ast_debug(1, "Audiohook parameters: slin-format:%d, rate:%d, frame-len:%d, ringbuffer_size: %d\n",
- jack_data->audiohook_format_id, jack_data->audiohook_rate, jack_data->frame_datalen, ringbuffer_size);
+ ast_debug(1, "Audiohook parameters: slin-format:%s, rate:%d, frame-len:%d, ringbuffer_size: %d\n",
+ ast_format_get_name(jack_data->audiohook_format), jack_data->audiohook_rate, jack_data->frame_datalen, ringbuffer_size);
if (!ast_strlen_zero(jack_data->client_name)) {
client_name = jack_data->client_name;
@@ -628,12 +626,12 @@ static void handle_jack_audio(struct ast_channel *chan, struct jack_data *jack_d
short buf[jack_data->frame_datalen];
struct ast_frame f = {
.frametype = AST_FRAME_VOICE,
+ .subclass.format = jack_data->audiohook_format,
.src = "JACK",
.data.ptr = buf,
.datalen = sizeof(buf),
.samples = ARRAY_LEN(buf),
};
- ast_format_set(&f.subclass.format, jack_data->audiohook_format_id, 0);
for (;;) {
size_t res, read_len;
@@ -778,12 +776,12 @@ static int jack_exec(struct ast_channel *chan, const char *data)
return -1;
}
- if (ast_set_read_format_by_id(chan, jack_data->audiohook_format_id)) {
+ if (ast_set_read_format(chan, jack_data->audiohook_format)) {
destroy_jack_data(jack_data);
return -1;
}
- if (ast_set_write_format_by_id(chan, jack_data->audiohook_format_id)) {
+ if (ast_set_write_format(chan, jack_data->audiohook_format)) {
destroy_jack_data(jack_data);
return -1;
}
@@ -859,9 +857,10 @@ static int jack_hook_callback(struct ast_audiohook *audiohook, struct ast_channe
jack_data = datastore->data;
- if (frame->subclass.format.id != jack_data->audiohook_format_id) {
- ast_log(LOG_WARNING, "Expected frame in SLINEAR with id %d for the audiohook, but got format %s\n",
- jack_data->audiohook_format_id, ast_getformatname(&frame->subclass.format));
+ if (ast_format_cmp(frame->subclass.format, jack_data->audiohook_format) == AST_FORMAT_CMP_NOT_EQUAL) {
+ ast_log(LOG_WARNING, "Expected frame in %s for the audiohook, but got format %s\n",
+ ast_format_get_name(jack_data->audiohook_format),
+ ast_format_get_name(frame->subclass.format));
ast_channel_unlock(chan);
return 0;
}
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 1a780e6ff..6d0b5ac1b 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -77,6 +77,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/json.h"
+#include "asterisk/format_compatibility.h"
#include "enter.h"
#include "leave.h"
@@ -1606,8 +1607,7 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
struct ast_conference *cnf;
struct dahdi_confinfo dahdic = { 0, };
int confno_int = 0;
- struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- struct ast_format tmp_fmt;
+ struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
AST_LIST_LOCK(&confs);
@@ -1619,7 +1619,7 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
if (cnf || (!make && !dynamic) || !cap_slin)
goto cnfout;
- ast_format_cap_add(cap_slin, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+ ast_format_cap_append(cap_slin, ast_format_slin, 0);
/* Make a new one */
if (!(cnf = ast_calloc(1, sizeof(*cnf))) ||
!(cnf->usercontainer = ao2_container_alloc(1, NULL, user_no_cmp))) {
@@ -1667,8 +1667,8 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
/* Setup a new channel for playback of audio files */
cnf->chan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL);
if (cnf->chan) {
- ast_set_read_format_by_id(cnf->chan, AST_FORMAT_SLINEAR);
- ast_set_write_format_by_id(cnf->chan, AST_FORMAT_SLINEAR);
+ ast_set_read_format(cnf->chan, ast_format_slin);
+ ast_set_write_format(cnf->chan, ast_format_slin);
dahdic.chan = 0;
dahdic.confno = cnf->dahdiconf;
dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -1704,7 +1704,7 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
conf_map[confno_int] = 1;
cnfout:
- cap_slin = ast_format_cap_destroy(cap_slin);
+ ao2_cleanup(cap_slin);
if (cnf)
ast_atomic_fetchadd_int(&cnf->refcount, refcount);
@@ -3089,8 +3089,8 @@ static void meetme_menu_admin_extended(enum menu_modes *menu_mode, int *dtmf,
if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL)))) {
struct dahdi_confinfo dahdic;
- ast_set_read_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
- ast_set_write_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
+ ast_set_read_format(conf->lchan, ast_format_slin);
+ ast_set_write_format(conf->lchan, ast_format_slin);
dahdic.chan = 0;
dahdic.confno = conf->dahdiconf;
dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -3217,13 +3217,12 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
int setusercount = 0;
int confsilence = 0, totalsilence = 0;
char *mailbox, *context;
- struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
- struct ast_format tmpfmt;
+ struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!cap_slin) {
goto conf_run_cleanup;
}
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+ ast_format_cap_append(cap_slin, ast_format_slin, 0);
if (!(user = ao2_alloc(sizeof(*user), NULL))) {
goto conf_run_cleanup;
@@ -3345,8 +3344,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
ast_mutex_lock(&conf->recordthreadlock);
if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) &&
((conf->lchan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL)))) {
- ast_set_read_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
- ast_set_write_format_by_id(conf->lchan, AST_FORMAT_SLINEAR);
+ ast_set_read_format(conf->lchan, ast_format_slin);
+ ast_set_write_format(conf->lchan, ast_format_slin);
dahdic.chan = 0;
dahdic.confno = conf->dahdiconf;
dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
@@ -3572,12 +3571,12 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
ast_indicate(chan, -1);
}
- if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+ if (ast_set_write_format(chan, ast_format_slin) < 0) {
ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", ast_channel_name(chan));
goto outrun;
}
- if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+ if (ast_set_read_format(chan, ast_format_slin) < 0) {
ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", ast_channel_name(chan));
goto outrun;
}
@@ -4131,7 +4130,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
dtmfstr[1] = '\0';
}
- if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
+ if ((f->frametype == AST_FRAME_VOICE) && (ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
if (user->talk.actual) {
ast_frame_adjust_volume(f, user->talk.actual);
}
@@ -4289,7 +4288,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
if (res > 0) {
memset(&fr, 0, sizeof(fr));
fr.frametype = AST_FRAME_VOICE;
- ast_format_set(&fr.subclass.format, AST_FORMAT_SLINEAR, 0);
+ fr.subclass.format = ast_format_slin;
fr.datalen = res;
fr.samples = res / 2;
fr.data.ptr = buf;
@@ -4301,7 +4300,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
)) {
int idx;
for (idx = 0; idx < AST_FRAME_BITS; idx++) {
- if (ast_format_to_old_bitfield(ast_channel_rawwriteformat(chan)) & (1 << idx)) {
+ if (ast_format_compatibility_format2bitfield(ast_channel_rawwriteformat(chan)) & (1 << idx)) {
break;
}
}
@@ -4319,11 +4318,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
mohtempstopped = 1;
}
if (!conf->transpath[idx]) {
- struct ast_format src;
- struct ast_format dst;
- ast_format_set(&src, AST_FORMAT_SLINEAR, 0);
- ast_format_from_old_bitfield(&dst, (1 << idx));
- conf->transpath[idx] = ast_translator_build_path(&dst, &src);
+ conf->transpath[idx] = ast_translator_build_path(ast_channel_rawwriteformat(chan), ast_format_slin);
}
if (conf->transpath[idx]) {
conf->transframe[idx] = ast_translate(conf->transpath[idx], conf->origframe, 0);
@@ -4485,7 +4480,7 @@ bailoutandtrynormal:
conf_run_cleanup:
- cap_slin = ast_format_cap_destroy(cap_slin);
+ ao2_cleanup(cap_slin);
return ret;
}
diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c
index a4adc08c5..a3509581d 100644
--- a/apps/app_milliwatt.c
+++ b/apps/app_milliwatt.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/indications.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="Milliwatt" language="en_US">
@@ -79,13 +80,14 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
{
unsigned char buf[AST_FRIENDLY_OFFSET + 640];
const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0]));
- int i, *indexp = (int *) data;
+ int i, *indexp = (int *) data, res;
struct ast_frame wf = {
.frametype = AST_FRAME_VOICE,
.offset = AST_FRIENDLY_OFFSET,
.src = __FUNCTION__,
};
- ast_format_set(&wf.subclass.format, AST_FORMAT_ULAW, 0);
+
+ wf.subclass.format = ast_format_ulaw;
wf.data.ptr = buf + AST_FRIENDLY_OFFSET;
/* Instead of len, use samples, because channel.c generator_force
@@ -108,7 +110,10 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
*indexp &= 7;
}
- if (ast_write(chan,&wf) < 0) {
+ res = ast_write(chan, &wf);
+ ast_frfree(&wf);
+
+ if (res < 0) {
ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",ast_channel_name(chan),strerror(errno));
return -1;
}
@@ -124,8 +129,8 @@ static struct ast_generator milliwattgen = {
static int old_milliwatt_exec(struct ast_channel *chan)
{
- ast_set_write_format_by_id(chan, AST_FORMAT_ULAW);
- ast_set_read_format_by_id(chan, AST_FORMAT_ULAW);
+ ast_set_write_format(chan, ast_format_ulaw);
+ ast_set_read_format(chan, ast_format_ulaw);
if (ast_channel_state(chan) != AST_STATE_UP) {
ast_answer(chan);
diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index ab1d0bad1..1e7833cea 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -57,6 +57,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/linkedlists.h"
#include "asterisk/test.h"
#include "asterisk/mixmonitor.h"
+#include "asterisk/format_cache.h"
#include "asterisk/beep.h"
/*** DOCUMENTATION
@@ -616,7 +617,7 @@ static void mixmonitor_save_prep(struct mixmonitor *mixmonitor, char *filename,
*errflag = 1;
} else {
struct ast_filestream *tmp = *fs;
- mixmonitor->mixmonitor_ds->samp_rate = MAX(mixmonitor->mixmonitor_ds->samp_rate, ast_format_rate(&tmp->fmt->format));
+ mixmonitor->mixmonitor_ds->samp_rate = MAX(mixmonitor->mixmonitor_ds->samp_rate, ast_format_get_sample_rate(tmp->fmt->format));
}
}
}
@@ -635,7 +636,7 @@ static void *mixmonitor_thread(void *obj)
unsigned int oflags;
int errflag = 0;
- struct ast_format format_slin;
+ struct ast_format *format_slin;
/* Keep callid association before any log messages */
if (mixmonitor->callid) {
@@ -653,11 +654,10 @@ static void *mixmonitor_thread(void *obj)
mixmonitor_save_prep(mixmonitor, mixmonitor->filename_read, fs_read, &oflags, &errflag, &fs_read_ext);
mixmonitor_save_prep(mixmonitor, mixmonitor->filename_write, fs_write, &oflags, &errflag, &fs_write_ext);
- ast_format_set(&format_slin, ast_format_slin_by_rate(mixmonitor->mixmonitor_ds->samp_rate), 0);
+ format_slin = ast_format_cache_get_slin_by_rate(mixmonitor->mixmonitor_ds->samp_rate);
ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
-
/* The audiohook must enter and exit the loop locked */
ast_audiohook_lock(&mixmonitor->audiohook);
while (mixmonitor->audiohook.status == AST_AUDIOHOOK_STATUS_RUNNING && !mixmonitor->mixmonitor_ds->fs_quit) {
@@ -665,7 +665,7 @@ static void *mixmonitor_thread(void *obj)
struct ast_frame *fr_read = NULL;
struct ast_frame *fr_write = NULL;
- if (!(fr = ast_audiohook_read_frame_all(&mixmonitor->audiohook, SAMPLES_PER_FRAME, &format_slin,
+ if (!(fr = ast_audiohook_read_frame_all(&mixmonitor->audiohook, SAMPLES_PER_FRAME, format_slin,
&fr_read, &fr_write))) {
ast_audiohook_trigger_wait(&mixmonitor->audiohook);
diff --git a/apps/app_mp3.c b/apps/app_mp3.c
index 463a91906..7e4e8e490 100644
--- a/apps/app_mp3.c
+++ b/apps/app_mp3.c
@@ -47,6 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
#define MPG_123 "/usr/bin/mpg123"
@@ -143,7 +144,7 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
int fds[2];
int ms = -1;
int pid = -1;
- struct ast_format owriteformat;
+ RAII_VAR(struct ast_format *, owriteformat, NULL, ao2_cleanup);
int timeout = 2000;
struct timeval next;
struct ast_frame *f;
@@ -155,7 +156,6 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
.f = { 0, },
};
- ast_format_clear(&owriteformat);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n");
return -1;
@@ -168,12 +168,21 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
ast_stopstream(chan);
- ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
- res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+ owriteformat = ao2_bump(ast_channel_writeformat(chan));
+ res = ast_set_write_format(chan, ast_format_slin);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
return -1;
}
+
+ myf.f.frametype = AST_FRAME_VOICE;
+ myf.f.subclass.format = ast_format_slin;
+ myf.f.mallocd = 0;
+ myf.f.offset = AST_FRIENDLY_OFFSET;
+ myf.f.src = __PRETTY_FUNCTION__;
+ myf.f.delivery.tv_sec = 0;
+ myf.f.delivery.tv_usec = 0;
+ myf.f.data.ptr = myf.frdata;
res = mp3play(data, fds[1]);
if (!strncasecmp(data, "http://", 7)) {
@@ -191,16 +200,8 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
if (ms <= 0) {
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);
if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
myf.f.datalen = res;
myf.f.samples = res / 2;
- myf.f.mallocd = 0;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.delivery.tv_sec = 0;
- myf.f.delivery.tv_usec = 0;
- myf.f.data.ptr = myf.frdata;
if (ast_write(chan, &myf.f) < 0) {
res = -1;
break;
@@ -241,8 +242,10 @@ static int mp3_exec(struct ast_channel *chan, const char *data)
if (pid > -1)
kill(pid, SIGKILL);
- if (!res && owriteformat.id)
- ast_set_write_format(chan, &owriteformat);
+ if (!res && owriteformat)
+ ast_set_write_format(chan, owriteformat);
+
+ ast_frfree(&myf.f);
return res;
}
diff --git a/apps/app_nbscat.c b/apps/app_nbscat.c
index 8cf02b369..435af8a29 100644
--- a/apps/app_nbscat.c
+++ b/apps/app_nbscat.c
@@ -46,6 +46,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="NBScat" language="en_US">
@@ -115,7 +116,7 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
int fds[2];
int ms = -1;
int pid = -1;
- struct ast_format owriteformat;
+ struct ast_format *owriteformat;
struct timeval next;
struct ast_frame *f;
struct myframe {
@@ -124,7 +125,6 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
short frdata[160];
} myf;
- ast_format_clear(&owriteformat);
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) {
ast_log(LOG_WARNING, "Unable to create socketpair\n");
return -1;
@@ -132,12 +132,22 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
ast_stopstream(chan);
- ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
- res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+ owriteformat = ao2_bump(ast_channel_writeformat(chan));
+ res = ast_set_write_format(chan, ast_format_slin);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+ ao2_cleanup(owriteformat);
return -1;
}
+
+ myf.f.frametype = AST_FRAME_VOICE;
+ myf.f.subclass.format = ast_format_slin;
+ myf.f.mallocd = 0;
+ myf.f.offset = AST_FRIENDLY_OFFSET;
+ myf.f.src = __PRETTY_FUNCTION__;
+ myf.f.delivery.tv_sec = 0;
+ myf.f.delivery.tv_usec = 0;
+ myf.f.data.ptr = myf.frdata;
res = NBScatplay(fds[1]);
/* Wait 1000 ms first */
@@ -152,16 +162,8 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
if (ms <= 0) {
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
if (res > 0) {
- myf.f.frametype = AST_FRAME_VOICE;
- ast_format_set(&myf.f.subclass.format, AST_FORMAT_SLINEAR, 0);
myf.f.datalen = res;
myf.f.samples = res / 2;
- myf.f.mallocd = 0;
- myf.f.offset = AST_FRIENDLY_OFFSET;
- myf.f.src = __PRETTY_FUNCTION__;
- myf.f.delivery.tv_sec = 0;
- myf.f.delivery.tv_usec = 0;
- myf.f.data.ptr = myf.frdata;
if (ast_write(chan, &myf.f) < 0) {
res = -1;
break;
@@ -199,11 +201,13 @@ static int NBScat_exec(struct ast_channel *chan, const char *data)
}
close(fds[0]);
close(fds[1]);
+ ast_frfree(&myf.f);
if (pid > -1)
kill(pid, SIGKILL);
- if (!res && owriteformat.id)
- ast_set_write_format(chan, &owriteformat);
+ if (!res && owriteformat)
+ ast_set_write_format(chan, owriteformat);
+ ao2_cleanup(owriteformat);
return res;
}
diff --git a/apps/app_originate.c b/apps/app_originate.c
index 9fceb0849..15898b240 100644
--- a/apps/app_originate.c
+++ b/apps/app_originate.c
@@ -45,6 +45,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
static const char app_originate[] = "Originate";
@@ -112,22 +113,22 @@ static int originate_exec(struct ast_channel *chan, const char *data)
int outgoing_status = 0;
unsigned int timeout = 30;
static const char default_exten[] = "s";
- struct ast_format tmpfmt;
- struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+ struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
ast_autoservice_start(chan);
if (!cap_slin) {
goto return_cleanup;
}
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR12, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR24, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR32, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR44, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR48, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR96, 0));
- ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR192, 0));
+
+ ast_format_cap_append(cap_slin, ast_format_slin, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin12, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin16, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin24, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin32, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin44, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin48, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin96, 0);
+ ast_format_cap_append(cap_slin, ast_format_slin192, 0);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "Originate() requires arguments\n");
@@ -222,7 +223,7 @@ return_cleanup:
break;
}
}
- cap_slin = ast_format_cap_destroy(cap_slin);
+ ao2_cleanup(cap_slin);
ast_autoservice_stop(chan);
return res;
diff --git a/apps/app_record.c b/apps/app_record.c
index 45f1d8602..4008fc012 100644
--- a/apps/app_record.c
+++ b/apps/app_record.c
@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/app.h"
#include "asterisk/channel.h"
#include "asterisk/dsp.h" /* use dsp routines for silence detection */
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="Record" language="en_US">
@@ -196,7 +197,7 @@ static int record_exec(struct ast_channel *chan, const char *data)
int maxduration = 0; /* max duration of recording in milliseconds */
int gottimeout = 0; /* did we timeout for maxduration exceeded? */
int terminator = '#';
- struct ast_format rfmt;
+ RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
int ioflags;
struct ast_silence_generator *silgen = NULL;
struct ast_flags flags = { 0, };
@@ -209,8 +210,6 @@ static int record_exec(struct ast_channel *chan, const char *data)
int ms;
struct timeval start;
- ast_format_clear(&rfmt);
-
/* The next few lines of code parse out the filename and header from the input string */
if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
ast_log(LOG_WARNING, "Record requires an argument (filename)\n");
@@ -331,8 +330,8 @@ static int record_exec(struct ast_channel *chan, const char *data)
/* The end of beep code. Now the recording starts */
if (silence > 0) {
- ast_format_copy(&rfmt, ast_channel_readformat(chan));
- res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+ rfmt = ao2_bump(ast_channel_readformat(chan));
+ res = ast_set_read_format(chan, ast_format_slin);
if (res < 0) {
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");
@@ -459,8 +458,8 @@ static int record_exec(struct ast_channel *chan, const char *data)
ast_channel_stop_silence_generator(chan, silgen);
out:
- if ((silence > 0) && rfmt.id) {
- res = ast_set_read_format(chan, &rfmt);
+ if ((silence > 0) && rfmt) {
+ res = ast_set_read_format(chan, rfmt);
if (res) {
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(chan));
}
diff --git a/apps/app_sms.c b/apps/app_sms.c
index b7d247818..266f8abdc 100644
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -56,6 +56,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="SMS" language="en_US">
@@ -140,11 +141,11 @@ static const signed short wave[] = {
static unsigned char wavea[80];
typedef unsigned char output_t;
static const output_t *wave_out = wavea; /* outgoing samples */
-#define __OUT_FMT AST_FORMAT_ALAW;
+#define __OUT_FMT ast_format_alaw
#else
typedef signed short output_t;
static const output_t *wave_out = wave; /* outgoing samples */
-#define __OUT_FMT AST_FORMAT_SLINEAR
+#define __OUT_FMT ast_format_slin
#endif
#define OSYNC_BITS 80 /* initial sync bits */
@@ -1599,7 +1600,7 @@ static int sms_generate(struct ast_channel *chan, void *data, int len, int sampl
#define MAXSAMPLES (800)
output_t *buf;
sms_t *h = data;
- int i;
+ int i, res;
if (samples > MAXSAMPLES) {
ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n",
@@ -1610,7 +1611,7 @@ static int sms_generate(struct ast_channel *chan, void *data, int len, int sampl
buf = ast_alloca(len);
f.frametype = AST_FRAME_VOICE;
- ast_format_set(&f.subclass.format, __OUT_FMT, 0);
+ f.subclass.format = __OUT_FMT;
f.datalen = samples * sizeof(*buf);
f.offset = AST_FRIENDLY_OFFSET;
f.mallocd = 0;
@@ -1660,7 +1661,9 @@ static int sms_generate(struct ast_channel *chan, void *data, int len, int sampl
}
}
}
- if (ast_write(chan, &f) < 0) {
+ res = ast_write(chan, &f);
+ ast_frfree(&f);
+ if (res < 0) {
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", ast_channel_name(chan), strerror(errno));
return -1;
}
@@ -2012,9 +2015,9 @@ static int sms_exec(struct ast_channel *chan, const char *data)
sms_messagetx(&h);
}
- res = ast_set_write_format_by_id(chan, __OUT_FMT);
+ res = ast_set_write_format(chan, __OUT_FMT);
if (res >= 0) {
- res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+ res = ast_set_read_format(chan, ast_format_slin);
}
if (res < 0) {
ast_log(LOG_ERROR, "Unable to set to linear mode, giving up\n");
diff --git a/apps/app_speech_utils.c b/apps/app_speech_utils.c
index e9ca63ea9..e52425d6a 100644
--- a/apps/app_speech_utils.c
+++ b/apps/app_speech_utils.c
@@ -672,7 +672,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0;
struct ast_speech *speech = find_speech(chan);
struct ast_frame *f = NULL;
- struct ast_format oldreadformat;
+ RAII_VAR(struct ast_format *, oldreadformat, NULL, ao2_cleanup);
char dtmf[AST_MAX_EXTENSION] = "";
struct timeval start = { 0, 0 }, current;
struct ast_datastore *datastore = NULL;
@@ -688,7 +688,6 @@ static int speech_background(struct ast_channel *chan, const char *data)
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
- ast_format_clear(&oldreadformat);
if (speech == NULL)
return -1;
@@ -704,10 +703,10 @@ static int speech_background(struct ast_channel *chan, const char *data)
}
/* Record old read format */
- ast_format_copy(&oldreadformat, ast_channel_readformat(chan));
+ oldreadformat = ao2_bump(ast_channel_readformat(chan));
/* Change read format to be signed linear */
- if (ast_set_read_format(chan, &speech->format))
+ if (ast_set_read_format(chan, speech->format))
return -1;
if (!ast_strlen_zero(args.soundfile)) {
@@ -912,7 +911,7 @@ static int speech_background(struct ast_channel *chan, const char *data)
ast_channel_datastore_remove(chan, datastore);
} else {
/* Channel is okay so restore read format */
- ast_set_read_format(chan, &oldreadformat);
+ ast_set_read_format(chan, oldreadformat);
}
return 0;
diff --git a/apps/app_talkdetect.c b/apps/app_talkdetect.c
index 5ef80c33c..5ccf2607e 100644
--- a/apps/app_talkdetect.c
+++ b/apps/app_talkdetect.c
@@ -42,6 +42,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/utils.h"
#include "asterisk/dsp.h"
#include "asterisk/app.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="BackgroundDetect" language="en_US">
@@ -91,7 +93,7 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
int analysistime = -1;
int continue_analysis = 1;
int x;
- struct ast_format origrformat;
+ RAII_VAR(struct ast_format *, origrformat, NULL, ao2_cleanup);
struct ast_dsp *dsp = NULL;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(filename);
@@ -101,7 +103,6 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
AST_APP_ARG(analysistime);
);
- ast_format_clear(&origrformat);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
return -1;
@@ -131,8 +132,8 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
}
}
- ast_format_copy(&origrformat, ast_channel_readformat(chan));
- if ((ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR))) {
+ origrformat = ao2_bump(ast_channel_readformat(chan));
+ if ((ast_set_read_format(chan, ast_format_slin))) {
ast_log(LOG_WARNING, "Unable to set read format to linear!\n");
res = -1;
break;
@@ -187,7 +188,8 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
ast_frfree(fr);
break;
}
- } else if ((fr->frametype == AST_FRAME_VOICE) && (fr->subclass.format.id == AST_FORMAT_SLINEAR) && continue_analysis) {
+ } else if ((fr->frametype == AST_FRAME_VOICE) &&
+ (ast_format_cmp(fr->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) && continue_analysis) {
int totalsilence;
int ms;
res = ast_dsp_silence(dsp, fr, &totalsilence);
@@ -233,9 +235,9 @@ static int background_detect_exec(struct ast_channel *chan, const char *data)
} while (0);
if (res > -1) {
- if (origrformat.id && ast_set_read_format(chan, &origrformat)) {
+ if (origrformat && ast_set_read_format(chan, origrformat)) {
ast_log(LOG_WARNING, "Failed to restore read format for %s to %s\n",
- ast_channel_name(chan), ast_getformatname(&origrformat));
+ ast_channel_name(chan), ast_format_get_name(origrformat));
}
}
if (dsp) {
diff --git a/apps/app_test.c b/apps/app_test.c
index 5b7b979e6..54139ba80 100644
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -44,6 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="TestServer" language="en_US">
@@ -91,11 +92,12 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
short *foo;
struct timeval start;
struct ast_frame *f;
- struct ast_format rformat;
+ struct ast_format *rformat;
- ast_format_copy(&rformat, ast_channel_readformat(chan));
- if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
+ rformat = ao2_bump(ast_channel_readformat(chan));
+ if (ast_set_read_format(chan, ast_format_slin)) {
ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
+ ao2_cleanup(rformat);
return -1;
}
start = ast_tvnow();
@@ -111,7 +113,8 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
res = -1;
break;
}
- if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
+ if ((f->frametype == AST_FRAME_VOICE) &&
+ (ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
foo = (short *)f->data.ptr;
for (x=0;x<f->samples;x++) {
noise += abs(foo[x]);
@@ -121,11 +124,13 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
ast_frfree(f);
}
- if (rformat.id) {
- if (ast_set_read_format(chan, &rformat)) {
+ if (rformat) {
+ if (ast_set_read_format(chan, rformat)) {
ast_log(LOG_NOTICE, "Unable to restore original format!\n");
+ ao2_ref(rformat, -1);
return -1;
}
+ ao2_ref(rformat, -1);
}
if (res < 0)
return res;
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 9c8a4b8ad..8a9c0f3ca 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -135,6 +135,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/astobj2.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/test.h"
+#include "asterisk/format_cache.h"
#ifdef ODBC_STORAGE
#include "asterisk/res_odbc.h"
@@ -6112,13 +6113,16 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
if ((recording_fs = ast_readfile(recdata->recording_file, recdata->recording_ext, NULL, 0, 0, VOICEMAIL_DIR_MODE))) {
if (!ast_seekstream(recording_fs, 0, SEEK_END)) {
long framelength = ast_tellstream(recording_fs);
- struct ast_format result = {0,};
+ struct ast_format *result;
/* XXX This use of ast_getformatbyname seems incorrect here. The file extension does not necessarily correspond
* to the name of the format. For instance, if "raw" were passed in, I don't think ast_getformatbyname would
* find the slinear format
*/
- ast_getformatbyname(recdata->recording_ext, &result);
- duration = (int) (framelength / ast_format_rate(&result));
+ result = ast_format_cache_get(recdata->recording_ext);
+ if (result) {
+ duration = (int) (framelength / ast_format_get_sample_rate(result));
+ ao2_ref(result, -1);
+ }
}
}
@@ -14026,7 +14030,7 @@ AST_TEST_DEFINE(test_voicemail_vmsayname)
struct ast_channel *test_channel1 = NULL;
int res = -1;
- struct ast_format_cap *nativeformats;
+ struct ast_format_cap *capabilities;
static const struct ast_channel_tech fake_tech = {
.write = fake_write,
@@ -14051,12 +14055,17 @@ AST_TEST_DEFINE(test_voicemail_vmsayname)
}
/* normally this is done in the channel driver */
- ast_format_set(ast_channel_writeformat(test_channel1), AST_FORMAT_GSM, 0);
- nativeformats = ast_channel_nativeformats(test_channel1);
- ast_format_cap_add(nativeformats, ast_channel_writeformat(test_channel1));
- ast_format_set(ast_channel_rawwriteformat(test_channel1), AST_FORMAT_GSM, 0);
- ast_format_set(ast_channel_readformat(test_channel1), AST_FORMAT_GSM, 0);
- ast_format_set(ast_channel_rawreadformat(test_channel1), AST_FORMAT_GSM, 0);
+ capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!capabilities) {
+ goto exit_vmsayname_test;
+ }
+ ast_format_cap_append(capabilities, ast_format_gsm, 0);
+ ast_channel_nativeformats_set(test_channel1, capabilities);
+ ao2_ref(capabilities, -1);
+ ast_channel_set_writeformat(test_channel1, ast_format_gsm);
+ ast_channel_set_rawwriteformat(test_channel1, ast_format_gsm);
+ ast_channel_set_readformat(test_channel1, ast_format_gsm);
+ ast_channel_set_rawreadformat(test_channel1, ast_format_gsm);
ast_channel_tech_set(test_channel1, &fake_tech);
ast_channel_unlock(test_channel1);
diff --git a/apps/app_waitforsilence.c b/apps/app_waitforsilence.c
index 53870df30..f2111d720 100644
--- a/apps/app_waitforsilence.c
+++ b/apps/app_waitforsilence.c
@@ -51,6 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h"
#include "asterisk/dsp.h"
#include "asterisk/module.h"
+#include "asterisk/format_cache.h"
/*** DOCUMENTATION
<application name="WaitForSilence" language="en_US">
@@ -129,7 +130,7 @@ static char *app_noise = "WaitForNoise";
static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) {
struct ast_frame *f = NULL;
int dsptime = 0;
- struct ast_format rfmt;
+ RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
int res = 0;
struct ast_dsp *sildet; /* silence detector dsp */
time_t now;
@@ -138,8 +139,8 @@ static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart,
int (*ast_dsp_func)(struct ast_dsp*, struct ast_frame*, int*) =
wait_for_silence ? ast_dsp_silence : ast_dsp_noise;
- ast_format_copy(&rfmt, ast_channel_readformat(chan)); /* Set to linear mode */
- if ((res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) < 0) {
+ rfmt = ao2_bump(ast_channel_readformat(chan));
+ if ((res = ast_set_read_format(chan, ast_format_slin)) < 0) {
ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n");
return -1;
}
@@ -199,8 +200,8 @@ static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart,
}
- if (rfmt.id && ast_set_read_format(chan, &rfmt)) {
- ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), ast_channel_name(chan));
+ if (rfmt && ast_set_read_format(chan, rfmt)) {
+ ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_format_get_name(rfmt), ast_channel_name(chan));
}
ast_dsp_free(sildet);
return res;
diff --git a/apps/confbridge/conf_chan_record.c b/apps/confbridge/conf_chan_record.c
index 34de5af3b..0e298e78d 100644
--- a/apps/confbridge/conf_chan_record.c
+++ b/apps/confbridge/conf_chan_record.c
@@ -33,6 +33,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/bridge.h"
+#include "asterisk/format_cache.h"
#include "include/confbridge.h"
/* ------------------------------------------------------------------- */
@@ -56,8 +57,14 @@ static int rec_write(struct ast_channel *ast, struct ast_frame *f)
static struct ast_channel *rec_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
{
struct ast_channel *chan;
- struct ast_format format;
const char *conf_name = data;
+ RAII_VAR(struct ast_format_cap *, capabilities, NULL, ao2_cleanup);
+
+ capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!capabilities) {
+ return NULL;
+ }
+ ast_format_cap_append_by_type(capabilities, AST_MEDIA_TYPE_UNKNOWN);
chan = ast_channel_alloc(1, AST_STATE_UP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"CBRec/conf-%s-uid-%d",
@@ -70,13 +77,13 @@ static struct ast_channel *rec_request(const char *type, struct ast_format_cap *
ast_channel_release(chan);
return NULL;
}
- ast_format_set(&format, AST_FORMAT_SLINEAR, 0);
+
ast_channel_tech_set(chan, conf_record_get_tech());
- ast_format_cap_add_all(ast_channel_nativeformats(chan));
- ast_format_copy(ast_channel_writeformat(chan), &format);
- ast_format_copy(ast_channel_rawwriteformat(chan), &format);
- ast_format_copy(ast_channel_readformat(chan), &format);
- ast_format_copy(ast_channel_rawreadformat(chan), &format);
+ ast_channel_nativeformats_set(chan, capabilities);
+ ast_channel_set_writeformat(chan, ast_format_slin);
+ ast_channel_set_rawwriteformat(chan, ast_format_slin);
+ ast_channel_set_readformat(chan, ast_format_slin);
+ ast_channel_set_rawreadformat(chan, ast_format_slin);
ast_channel_unlock(chan);
return chan;
}