[svn-commits] file: branch group/media_formats-reviewed r411014 - in /team/group/media_form...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Mar 23 06:48:11 CDT 2014


Author: file
Date: Sun Mar 23 06:47:51 2014
New Revision: 411014

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411014
Log:
Merge resource module changes.

Review: https://reviewboard.asterisk.org/r/3322/

Modified:
    team/group/media_formats-reviewed/res/ari/resource_bridges.c
    team/group/media_formats-reviewed/res/ari/resource_channels.c
    team/group/media_formats-reviewed/res/ari/resource_sounds.c
    team/group/media_formats-reviewed/res/parking/parking_applications.c
    team/group/media_formats-reviewed/res/res_adsi.c
    team/group/media_formats-reviewed/res/res_agi.c
    team/group/media_formats-reviewed/res/res_calendar.c
    team/group/media_formats-reviewed/res/res_clioriginate.c
    team/group/media_formats-reviewed/res/res_fax.c
    team/group/media_formats-reviewed/res/res_fax_spandsp.c
    team/group/media_formats-reviewed/res/res_musiconhold.c
    team/group/media_formats-reviewed/res/res_speech.c
    team/group/media_formats-reviewed/res/res_stasis.c
    team/group/media_formats-reviewed/res/res_stasis_snoop.c

Modified: team/group/media_formats-reviewed/res/ari/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/ari/resource_bridges.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/ari/resource_bridges.c (original)
+++ team/group/media_formats-reviewed/res/ari/resource_bridges.c Sun Mar 23 06:47:51 2014
@@ -44,6 +44,7 @@
 #include "asterisk/format_cap.h"
 #include "asterisk/file.h"
 #include "asterisk/musiconhold.h"
+#include "asterisk/format_cache.h"
 
 /*!
  * \brief Finds a bridge, filling the response with an error, if appropriate.
@@ -300,19 +301,14 @@
 
 static struct ast_channel *prepare_bridge_media_channel(const char *type)
 {
-	RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
-	struct ast_format format;
-
-	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	RAII_VAR(struct ast_format_cap *, cap, NULL, ao2_cleanup);
+
+	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!cap) {
 		return NULL;
 	}
 
-	ast_format_cap_add(cap, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
-
-	if (!cap) {
-		return NULL;
-	}
+	ast_format_cap_add(cap, ast_format_slin, 0);
 
 	return ast_request(type, cap, NULL, "ARI", NULL);
 }

Modified: team/group/media_formats-reviewed/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/ari/resource_channels.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/ari/resource_channels.c (original)
+++ team/group/media_formats-reviewed/res/ari/resource_channels.c Sun Mar 23 06:47:51 2014
@@ -42,6 +42,7 @@
 #include "asterisk/stasis_app_snoop.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/causes.h"
+#include "asterisk/format_cache.h"
 #include "resource_channels.h"
 
 #include <limits.h>
@@ -735,8 +736,7 @@
 	char *cid_name = NULL;
 	int timeout = 30000;
 	RAII_VAR(struct ast_format_cap *, cap,
-		ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
-	struct ast_format tmp_fmt;
+		ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
 
 	char *stuff;
 	struct ast_channel *chan;
@@ -747,7 +747,7 @@
 		ast_ari_response_alloc_failed(response);
 		return;
 	}
-	ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 
 	/* Parse any query parameters out of the body parameter */
 	if (args->variables) {

Modified: team/group/media_formats-reviewed/res/ari/resource_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/ari/resource_sounds.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/ari/resource_sounds.c (original)
+++ team/group/media_formats-reviewed/res/ari/resource_sounds.c Sun Mar 23 06:47:51 2014
@@ -46,8 +46,8 @@
 {
 	char *language = obj;
 	struct lang_format_info *args = arg;
-	struct ast_format format;
-	RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
+	int idx;
+	RAII_VAR(struct ast_format_cap *, cap, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_media_index *, sounds_index, ast_sounds_get_index(), ao2_cleanup);
 
 	if (!sounds_index) {
@@ -59,27 +59,28 @@
 		return CMP_STOP;
 	}
 
-	ast_format_cap_iter_start(cap);
-	while (!ast_format_cap_iter_next(cap, &format)) {
+	for (idx = 0; idx < ast_format_cap_count(cap); idx++) {
+		struct ast_format *format = ast_format_cap_get_format(cap, idx);
 		struct ast_json *lang_format_pair;
-		const char *format_name = ast_getformatname(&format);
 
 		if (!ast_strlen_zero(args->format_filter)
-			&& strcmp(args->format_filter, format_name)) {
+			&& strcmp(args->format_filter, ast_format_get_name(format))) {
+			ao2_ref(format, -1);
 			continue;
 		}
 
 		lang_format_pair = ast_json_pack("{s: s, s: s}",
 			"language", language,
-			"format", format_name);
+			"format", ast_format_get_name(format));
 		if (!lang_format_pair) {
-			ast_format_cap_iter_end(cap);
+			ao2_ref(format, -1);
 			return CMP_STOP;
 		}
 
 		ast_json_array_append(args->format_list, lang_format_pair);
-	}
-	ast_format_cap_iter_end(cap);
+		ao2_ref(format, -1);
+	}
+
 	return 0;
 }
 

Modified: team/group/media_formats-reviewed/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/parking/parking_applications.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/parking/parking_applications.c (original)
+++ team/group/media_formats-reviewed/res/parking/parking_applications.c Sun Mar 23 06:47:51 2014
@@ -37,6 +37,7 @@
 #include "asterisk/app.h"
 #include "asterisk/say.h"
 #include "asterisk/bridge_basic.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="Park" language="en_US">
@@ -687,11 +688,10 @@
 	struct ast_channel *dchan;
 	struct outgoing_helper oh = { 0, };
 	int outstate;
-	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);
 	char buf[13];
 	char *dial_tech;
 	char *cur_announce;
-	struct ast_format tmpfmt;
 
 	dial_tech = strsep(&dial_string, "/");
 	ast_verb(3, "Dial Tech,String: (%s,%s)\n", dial_tech, dial_string);
@@ -700,7 +700,7 @@
 		ast_log(LOG_WARNING, "PARK: Failed to announce park.\n");
 		goto announce_cleanup;
 	}
-	ast_format_cap_add(cap_slin, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap_slin, ast_format_slin, 0);
 
 	snprintf(buf, sizeof(buf), "%d", parkingspace);
 	oh.vars = ast_variable_new("_PARKEDAT", buf, "");
@@ -736,7 +736,7 @@
 	ast_hangup(dchan);
 
 announce_cleanup:
-	cap_slin = ast_format_cap_destroy(cap_slin);
+	ao2_cleanup(cap_slin);
 }
 
 static void park_announce_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)

Modified: team/group/media_formats-reviewed/res/res_adsi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_adsi.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_adsi.c (original)
+++ team/group/media_formats-reviewed/res/res_adsi.c Sun Mar 23 06:47:51 2014
@@ -50,6 +50,7 @@
 #include "asterisk/config.h"
 #include "asterisk/file.h"
 #include "asterisk/adsi.h"
+#include "asterisk/format_cache.h"
 
 #define DEFAULT_ADSI_MAX_RETRIES 3
 
@@ -154,11 +155,13 @@
 {
 	/* Sends carefully on a full duplex channel by using reading for
 	   timing */
-	struct ast_frame *inf, outf;
+	struct ast_frame *inf;
+	struct ast_frame outf = {
+		.frametype = AST_FRAME_VOICE,
+		.subclass.format = ast_format_ulaw,
+		.data.ptr = buf,
+	};
 	int amt;
-
-	/* Zero out our outgoing frame */
-	memset(&outf, 0, sizeof(outf));
 
 	if (remain && *remain) {
 		amt = len;
@@ -169,9 +172,7 @@
 		} else {
 			*remain = *remain - amt;
 		}
-		outf.frametype = AST_FRAME_VOICE;
-		ast_format_set(&outf.subclass.format, AST_FORMAT_ULAW, 0);
-		outf.data.ptr = buf;
+
 		outf.datalen = amt;
 		outf.samples = amt;
 		if (ast_write(chan, &outf)) {
@@ -201,7 +202,7 @@
 			continue;
 		}
 
-		if (inf->subclass.format.id != AST_FORMAT_ULAW) {
+		if (ast_format_cmp(inf->subclass.format, ast_format_ulaw) != AST_FORMAT_CMP_EQUAL) {
 			ast_log(LOG_WARNING, "Channel not in ulaw?\n");
 			ast_frfree(inf);
 			return -1;
@@ -212,9 +213,6 @@
 		} else if (remain) {
 			*remain = inf->datalen - amt;
 		}
-		outf.frametype = AST_FRAME_VOICE;
-		ast_format_set(&outf.subclass.format, AST_FORMAT_ULAW, 0);
-		outf.data.ptr = buf;
 		outf.datalen = amt;
 		outf.samples = amt;
 		if (ast_write(chan, &outf)) {
@@ -245,11 +243,9 @@
 	}
 
 	while (retries < maxretries) {
-		struct ast_format tmpfmt;
 		if (!(ast_channel_adsicpe(chan) & ADSI_FLAG_DATAMODE)) {
 			/* Generate CAS (no SAS) */
-			ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0);
-			ast_gen_cas(buf, 0, 680, &tmpfmt);
+			ast_gen_cas(buf, 0, 680, ast_format_ulaw);
 
 			/* Send CAS */
 			if (adsi_careful_send(chan, buf, 680, NULL)) {
@@ -308,7 +304,7 @@
 		def= ast_channel_defer_dtmf(chan);
 #endif
 		while ((x < 6) && msg[x]) {
-			if ((res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], ast_format_set(&tmpfmt, AST_FORMAT_ULAW,0))) < 0) {
+			if ((res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], ast_format_ulaw)) < 0) {
 				ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, ast_channel_name(chan));
 				return -1;
 			}
@@ -395,11 +391,8 @@
 {
 	unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL };
 	int msglens[5], msgtypes[5], newdatamode = (ast_channel_adsicpe(chan) & ADSI_FLAG_DATAMODE), res, x, waitforswitch = 0;
-	struct ast_format writeformat;
-	struct ast_format readformat;
-
-	ast_format_copy(&writeformat, ast_channel_writeformat(chan));
-	ast_format_copy(&readformat, ast_channel_readformat(chan));
+	RAII_VAR(struct ast_format *, writeformat, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, readformat, NULL, ao2_cleanup);
 
 	for (x = 0; x < msglen; x += (msg[x+1]+2)) {
 		if (msg[x] == ADSI_SWITCH_TO_DATA) {
@@ -426,16 +419,19 @@
 
 	ast_stopstream(chan);
 
-	if (ast_set_write_format_by_id(chan, AST_FORMAT_ULAW)) {
+	writeformat = ast_format_copy(ast_channel_writeformat(chan));
+	readformat = ast_format_copy(ast_channel_readformat(chan));
+
+	if (ast_set_write_format(chan, ast_format_ulaw)) {
 		ast_log(LOG_WARNING, "Unable to set write format to ULAW\n");
 		return -1;
 	}
 
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_ULAW)) {
+	if (ast_set_read_format(chan, ast_format_ulaw)) {
 		ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
-		if (writeformat.id) {
-			if (ast_set_write_format(chan, &writeformat)) {
-				ast_log(LOG_WARNING, "Unable to restore write format to %s\n", ast_getformatname(&writeformat));
+		if (writeformat) {
+			if (ast_set_write_format(chan, writeformat)) {
+				ast_log(LOG_WARNING, "Unable to restore write format to %s\n", ast_format_get_name(writeformat));
 			}
 		}
 		return -1;
@@ -454,11 +450,11 @@
 		ast_channel_adsicpe_set(chan, (ast_channel_adsicpe(chan) & ~ADSI_FLAG_DATAMODE) | newdatamode);
 	}
 
-	if (writeformat.id) {
-		ast_set_write_format(chan, &writeformat);
-	}
-	if (readformat.id) {
-		ast_set_read_format(chan, &readformat);
+	if (writeformat) {
+		ast_set_write_format(chan, writeformat);
+	}
+	if (readformat) {
+		ast_set_read_format(chan, readformat);
 	}
 
 	if (!res) {

Modified: team/group/media_formats-reviewed/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_agi.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_agi.c (original)
+++ team/group/media_formats-reviewed/res/res_agi.c Sun Mar 23 06:47:51 2014
@@ -68,6 +68,7 @@
 #include "asterisk/netsock2.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_message_router.h"
+#include "asterisk/format_cache.h"
 
 #define AST_API_MODULE
 #include "asterisk/agi.h"
@@ -2542,8 +2543,7 @@
 	int silence = 0;                /* amount of silence to allow */
 	int gotsilence = 0;             /* did we timeout for silence? */
 	char *silencestr = NULL;
-	struct ast_format rfmt;
-	ast_format_clear(&rfmt);
+	RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
 
 	/* XXX EAGI FIXME XXX */
 
@@ -2573,8 +2573,8 @@
 	}
 
 	if (silence > 0) {
-		ast_format_copy(&rfmt, ast_channel_readformat(chan));
-		res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+		rfmt = ast_format_copy(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");
 			ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
@@ -2698,7 +2698,7 @@
 	}
 
 	if (silence > 0) {
-		res = ast_set_read_format(chan, &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));
 		ast_dsp_free(sildet);
@@ -3053,7 +3053,6 @@
 static int handle_speechcreate(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
 {
 	struct ast_format_cap *cap;
-	struct ast_format tmpfmt;
 
 	/* If a structure already exists, return an error */
 	if (agi->speech) {
@@ -3061,16 +3060,16 @@
 		return RESULT_SUCCESS;
 	}
 
-	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
+	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return RESULT_FAILURE;
 	}
-	ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 	if ((agi->speech = ast_speech_new(argv[2], cap))) {
 		ast_agi_send(agi->fd, chan, "200 result=1\n");
 	} else {
 		ast_agi_send(agi->fd, chan, "200 result=0\n");
 	}
-	cap = ast_format_cap_destroy(cap);
+	ao2_ref(cap, -1);
 
 	return RESULT_SUCCESS;
 }
@@ -3203,7 +3202,6 @@
 	const char *prompt;
 	char dtmf = 0, tmp[4096] = "", *buf = tmp;
 	int timeout = 0, offset = 0, res = 0, i = 0;
-	struct ast_format old_read_format;
 	long current_offset = 0;
 	const char *reason = NULL;
 	struct ast_frame *fr = NULL;
@@ -3227,8 +3225,7 @@
 		offset = atoi(argv[4]);
 
 	/* We want frames coming in signed linear */
-	ast_format_copy(&old_read_format, ast_channel_readformat(chan));
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
+	if (ast_set_read_format(chan, ast_format_slin)) {
 		ast_agi_send(agi->fd, chan, "200 result=0\n");
 		return RESULT_SUCCESS;
 	}
@@ -4220,23 +4217,26 @@
 static int eagi_exec(struct ast_channel *chan, const char *data)
 {
 	int res;
-	struct ast_format readformat;
+	struct ast_format *readformat;
 
 	if (ast_check_hangup(chan)) {
 		ast_log(LOG_ERROR, "EAGI cannot be run on a dead/hungup channel, please use AGI.\n");
 		return 0;
 	}
-	ast_format_copy(&readformat, ast_channel_readformat(chan));
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
+	readformat = ast_format_copy(ast_channel_readformat(chan));
+	if (ast_set_read_format(chan, ast_format_slin)) {
 		ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", ast_channel_name(chan));
+		ao2_ref(readformat, -1);
 		return -1;
 	}
 	res = agi_exec_full(chan, data, 1, 0);
 	if (!res) {
-		if (ast_set_read_format(chan, &readformat)) {
-			ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", ast_channel_name(chan), ast_getformatname(&readformat));
-		}
-	}
+		if (ast_set_read_format(chan, readformat)) {
+			ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", ast_channel_name(chan),
+				ast_format_get_name(readformat));
+		}
+	}
+	ao2_ref(readformat, -1);
 	return res;
 }
 

Modified: team/group/media_formats-reviewed/res/res_calendar.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_calendar.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_calendar.c (original)
+++ team/group/media_formats-reviewed/res/res_calendar.c Sun Mar 23 06:47:51 2014
@@ -54,6 +54,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/pbx.h"
 #include "asterisk/app.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<function name="CALENDAR_BUSY" language="en_US">
@@ -729,6 +730,7 @@
 	struct ast_variable *itervar;
 	char *tech, *dest;
 	char buf[8];
+	struct ast_format_cap *caps;
 
 	tech = ast_strdupa(event->owner->notify_channel);
 
@@ -759,12 +761,19 @@
 	}
 
 	ast_channel_tech_set(chan, &null_tech);
-	ast_format_set(ast_channel_writeformat(chan), AST_FORMAT_SLINEAR, 0);
-	ast_format_set(ast_channel_readformat(chan), AST_FORMAT_SLINEAR, 0);
-	ast_format_set(ast_channel_rawwriteformat(chan), AST_FORMAT_SLINEAR, 0);
-	ast_format_set(ast_channel_rawreadformat(chan), AST_FORMAT_SLINEAR, 0);
-	/* clear native formats and set to slinear. write format is signlear so just use that to set it */
-	ast_format_cap_set(ast_channel_nativeformats(chan), ast_channel_writeformat(chan));
+	ast_channel_set_writeformat(chan, ast_format_slin);
+	ast_channel_set_readformat(chan, ast_format_slin);
+	ast_channel_set_rawwriteformat(chan, ast_format_slin);
+	ast_channel_set_rawreadformat(chan, ast_format_slin);
+
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_log(LOG_ERROR, "Could not allocate capabilities, notification not being sent!\n");
+		goto notify_cleanup;
+	}
+	ast_format_cap_add(caps, ast_format_slin, 0);
+	ast_channel_nativeformats_set(chan, caps);
+	ao2_ref(caps, -1);
 
 	ast_channel_unlock(chan);
 

Modified: team/group/media_formats-reviewed/res/res_clioriginate.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_clioriginate.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_clioriginate.c (original)
+++ team/group/media_formats-reviewed/res/res_clioriginate.c Sun Mar 23 06:47:51 2014
@@ -38,6 +38,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/utils.h"
 #include "asterisk/frame.h"
+#include "asterisk/format_cache.h"
 
 /*! The timeout for originated calls, in seconds */
 #define TIMEOUT 30
@@ -57,7 +58,6 @@
 	char *chandata;
 	int reason = 0;
 	struct ast_format_cap *cap;
-	struct ast_format tmpfmt;
 
 	if (ast_strlen_zero(app))
 		return CLI_SHOWUSAGE;
@@ -70,12 +70,12 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
+	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return CLI_FAILURE;
 	}
-	ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 	ast_pbx_outgoing_app(chantech, cap, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);
-	cap = ast_format_cap_destroy(cap);
+	ao2_ref(cap, -1);
 
 	return CLI_SUCCESS;
 }
@@ -96,7 +96,6 @@
 	char *context = NULL;
 	int reason = 0;
 	struct ast_format_cap *cap;
-	struct ast_format tmpfmt;
 
 	chandata = ast_strdupa(chan);
 
@@ -115,12 +114,12 @@
 		exten = "s";
 	if (ast_strlen_zero(context))
 		context = "default";
-	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
+	if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return CLI_FAILURE;
 	}
-	ast_format_cap_add(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 	ast_pbx_outgoing_exten(chantech, cap, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL, 0);
-	cap = ast_format_cap_destroy(cap);
+	ao2_ref(cap, -1);
 
 	return CLI_SUCCESS;
 }

Modified: team/group/media_formats-reviewed/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_fax.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_fax.c (original)
+++ team/group/media_formats-reviewed/res/res_fax.c Sun Mar 23 06:47:51 2014
@@ -90,6 +90,7 @@
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/smoother.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="ReceiveFAX" language="en_US" module="res_fax">
@@ -272,10 +273,10 @@
 	/*! \brief a flag to track the state of our negotiation */
 	enum ast_t38_state t38_state;
 	/*! \brief original audio formats */
-	struct ast_format chan_read_format;
-	struct ast_format chan_write_format;
-	struct ast_format peer_read_format;
-	struct ast_format peer_write_format;
+	struct ast_format *chan_read_format;
+	struct ast_format *chan_write_format;
+	struct ast_format *peer_read_format;
+	struct ast_format *peer_write_format;
 };
 
 /*! \brief used for fax detect framehook */
@@ -287,7 +288,7 @@
 	/*! \brief DSP Processor */
 	struct ast_dsp *dsp;
 	/*! \brief original audio formats */
-	struct ast_format orig_format;
+	struct ast_format *orig_format;
 	/*! \brief fax session details */
 	struct ast_fax_session_details *details;
 	/*! \brief mode */
@@ -1361,13 +1362,11 @@
 	struct ast_fax_session *fax = NULL;
 	struct ast_frame *frame = NULL;
 	struct ast_channel *c = chan;
-	struct ast_format orig_write_format;
-	struct ast_format orig_read_format;
+	RAII_VAR(struct ast_format *, orig_write_format, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, orig_read_format, NULL, ao2_cleanup);
 	int remaining_time;
 	struct timeval start;
 
-	ast_format_clear(&orig_write_format);
-	ast_format_clear(&orig_read_format);
 	chancount = 1;
 
 	/* create the FAX session */
@@ -1391,10 +1390,10 @@
 	report_fax_status(chan, details, "Allocating Resources");
 
 	if (details->caps & AST_FAX_TECH_AUDIO) {
-		expected_frametype = AST_FRAME_VOICE;;
-		ast_format_set(&expected_framesubclass.format, AST_FORMAT_SLINEAR, 0);
-		ast_format_copy(&orig_write_format, ast_channel_writeformat(chan));
-		if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+		expected_frametype = AST_FRAME_VOICE;
+		expected_framesubclass.format = ast_format_slin;
+		orig_write_format = ast_format_copy(ast_channel_writeformat(chan));
+		if (ast_set_write_format(chan, ast_format_slin) < 0) {
 			ast_log(LOG_ERROR, "channel '%s' failed to set write format to signed linear'.\n", ast_channel_name(chan));
  			ao2_lock(faxregistry.container);
  			ao2_unlink(faxregistry.container, fax);
@@ -1403,8 +1402,8 @@
 			ast_channel_unlock(chan);
 			return -1;
 		}
-		ast_format_copy(&orig_read_format, ast_channel_readformat(chan));
-		if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) {
+		orig_read_format = ast_format_copy(ast_channel_readformat(chan));
+		if (ast_set_read_format(chan, ast_format_slin) < 0) {
 			ast_log(LOG_ERROR, "channel '%s' failed to set read format to signed linear.\n", ast_channel_name(chan));
  			ao2_lock(faxregistry.container);
  			ao2_unlink(faxregistry.container, fax);
@@ -1593,11 +1592,11 @@
 	 * restore them now
 	 */
 	if (chancount) {
-		if (orig_read_format.id) {
-			ast_set_read_format(chan, &orig_read_format);
-		}
-		if (orig_write_format.id) {
-			ast_set_write_format(chan, &orig_write_format);
+		if (orig_read_format) {
+			ast_set_read_format(chan, orig_read_format);
+		}
+		if (orig_write_format) {
+			ast_set_write_format(chan, orig_write_format);
 		}
 	}
 
@@ -2606,6 +2605,11 @@
 		ao2_ref(gateway->s, -1);
 		gateway->s = NULL;
 	}
+
+	ao2_cleanup(gateway->chan_read_format);
+	ao2_cleanup(gateway->chan_write_format);
+	ao2_cleanup(gateway->peer_read_format);
+	ao2_cleanup(gateway->peer_write_format);
 }
 
 /*! \brief Create a new fax gateway object.
@@ -3057,14 +3061,14 @@
 		set_channel_variables(chan, details);
 
 		if (gateway->bridged) {
-			ast_set_read_format(chan, &gateway->chan_read_format);
-			ast_set_read_format(chan, &gateway->chan_write_format);
+			ast_set_read_format(chan, gateway->chan_read_format);
+			ast_set_read_format(chan, gateway->chan_write_format);
 
 			ast_channel_unlock(chan);
 			peer = ast_channel_bridge_peer(chan);
 			if (peer) {
-				ast_set_read_format(peer, &gateway->peer_read_format);
-				ast_set_read_format(peer, &gateway->peer_write_format);
+				ast_set_read_format(peer, gateway->peer_read_format);
+				ast_set_read_format(peer, gateway->peer_write_format);
 				ast_channel_make_compatible(chan, peer);
 			}
 			ast_channel_lock(chan);
@@ -3109,18 +3113,18 @@
 
 		/* we are bridged, change r/w formats to SLIN for v21 preamble
 		 * detection and T.30 */
-		ast_format_copy(&gateway->chan_read_format, ast_channel_readformat(chan));
-		ast_format_copy(&gateway->chan_write_format, ast_channel_readformat(chan));
-
-		ast_format_copy(&gateway->peer_read_format, ast_channel_readformat(peer));
-		ast_format_copy(&gateway->peer_write_format, ast_channel_readformat(peer));
-
-		ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
-		ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+		gateway->chan_read_format = ast_format_copy(ast_channel_readformat(chan));
+		gateway->chan_write_format = ast_format_copy(ast_channel_readformat(chan));
+
+		gateway->peer_read_format = ast_format_copy(ast_channel_readformat(peer));
+		gateway->peer_write_format = ast_format_copy(ast_channel_readformat(peer));
+
+		ast_set_read_format(chan, ast_format_slin);
+		ast_set_write_format(chan, ast_format_slin);
 
 		ast_channel_unlock(chan);
-		ast_set_read_format_by_id(peer, AST_FORMAT_SLINEAR);
-		ast_set_write_format_by_id(peer, AST_FORMAT_SLINEAR);
+		ast_set_read_format(peer, ast_format_slin);
+		ast_set_write_format(peer, ast_format_slin);
 
 		ast_channel_make_compatible(chan, peer);
 		ast_channel_lock(chan);
@@ -3144,12 +3148,9 @@
 	/* only handle VOICE, MODEM, and CONTROL frames*/
 	switch (f->frametype) {
 	case AST_FRAME_VOICE:
-		switch (f->subclass.format.id) {
-		case AST_FORMAT_SLINEAR:
-		case AST_FORMAT_ALAW:
-		case AST_FORMAT_ULAW:
-			break;
-		default:
+		if ((ast_format_cmp(f->subclass.format, ast_format_slin) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(f->subclass.format, ast_format_alaw) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(f->subclass.format, ast_format_ulaw) != AST_FORMAT_CMP_EQUAL)) {
 			return f;
 		}
 		break;
@@ -3195,7 +3196,7 @@
 	if (gateway->t38_state == T38_STATE_NEGOTIATED) {
 		/* framehooks are called in __ast_read() before frame format
 		 * translation is done, so we need to translate here */
-		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 (ast_channel_readtrans(active) && (f = ast_translate(ast_channel_readtrans(active), f, 1)) == NULL) {
 				f = &ast_null_frame;
 				return f;
@@ -3207,7 +3208,8 @@
 		 * write would fail, or even if a failure would be fatal so for
 		 * now we'll just ignore the return value. */
 		gateway->s->tech->write(gateway->s, f);
-		if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id != AST_FORMAT_SLINEAR) && ast_channel_readtrans(active)) {
+		if ((f->frametype == AST_FRAME_VOICE) && (ast_format_cmp(f->subclass.format, ast_format_slin) != AST_FORMAT_CMP_EQUAL) &&
+			ast_channel_readtrans(active)) {
 			/* Only free the frame if we translated / duplicated it - otherwise,
 			 * let whatever is outside the frame hook do it */
 			ast_frfree(f);
@@ -3218,15 +3220,16 @@
 
 	/* force silence on the line if T.38 negotiation might be taking place */
 	if (gateway->t38_state != T38_STATE_UNAVAILABLE && gateway->t38_state != T38_STATE_REJECTED) {
-		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)) {
 			short silence_buf[f->samples];
 			struct ast_frame silence_frame = {
 				.frametype = AST_FRAME_VOICE,
+				.subclass.format = ast_format_slin,
 				.data.ptr = silence_buf,
 				.samples = f->samples,
 				.datalen = sizeof(silence_buf),
 			};
-			ast_format_set(&silence_frame.subclass.format, AST_FORMAT_SLINEAR, 0);
 			memset(silence_buf, 0, sizeof(silence_buf));
 			return ast_frisolate(&silence_frame);
 		} else {
@@ -3295,6 +3298,7 @@
 		faxdetect->dsp = NULL;
 	}
 	ao2_ref(faxdetect->details, -1);
+	ao2_cleanup(faxdetect->orig_format);
 }
 
 /*! \brief Create a new fax detect object.
@@ -3369,23 +3373,22 @@
 	switch (event) {
 	case AST_FRAMEHOOK_EVENT_ATTACHED:
 		/* Setup format for DSP on ATTACH*/
-		ast_format_copy(&faxdetect->orig_format, ast_channel_readformat(chan));
-		switch (ast_channel_readformat(chan)->id) {
-			case AST_FORMAT_SLINEAR:
-			case AST_FORMAT_ALAW:
-			case AST_FORMAT_ULAW:
-				break;
-			default:
-				if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) {
-					ast_framehook_detach(chan, details->faxdetect_id);
-					details->faxdetect_id = -1;
-					return f;
-				}
-		}
+		faxdetect->orig_format = ast_format_copy(ast_channel_readformat(chan));
+
+		if ((ast_format_cmp(ast_channel_readformat(chan), ast_format_slin) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(ast_channel_readformat(chan), ast_format_alaw) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(ast_channel_readformat(chan), ast_format_ulaw) != AST_FORMAT_CMP_EQUAL)) {
+			if (ast_set_read_format(chan, ast_format_slin)) {
+				ast_framehook_detach(chan, details->faxdetect_id);
+				details->faxdetect_id = -1;
+				return f;
+			}
+		}
+
 		return NULL;
 	case AST_FRAMEHOOK_EVENT_DETACHED:
 		/* restore audio formats when we are detached */
-		ast_set_read_format(chan, &faxdetect->orig_format);
+		ast_set_read_format(chan, faxdetect->orig_format);
 		ast_channel_unlock(chan);
 		peer = ast_channel_bridge_peer(chan);
 		if (peer) {
@@ -3420,13 +3423,10 @@
 			return f;
 		}
 		/* We can only process some formats*/
-		switch (f->subclass.format.id) {
-			case AST_FORMAT_SLINEAR:
-			case AST_FORMAT_ALAW:
-			case AST_FORMAT_ULAW:
-				break;
-			default:
-				return f;
+		if ((ast_format_cmp(f->subclass.format, ast_format_slin) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(f->subclass.format, ast_format_alaw) != AST_FORMAT_CMP_EQUAL) &&
+			(ast_format_cmp(f->subclass.format, ast_format_ulaw) != AST_FORMAT_CMP_EQUAL)) {
+			return f;
 		}
 		break;
 	case AST_FRAME_CONTROL:

Modified: team/group/media_formats-reviewed/res/res_fax_spandsp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_fax_spandsp.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_fax_spandsp.c (original)
+++ team/group/media_formats-reviewed/res/res_fax_spandsp.c Sun Mar 23 06:47:51 2014
@@ -65,6 +65,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/res_fax.h"
 #include "asterisk/channel.h"
+#include "asterisk/format_cache.h"
 
 #define SPANDSP_FAX_SAMPLES 160
 #define SPANDSP_FAX_TIMER_RATE 8000 / SPANDSP_FAX_SAMPLES	/* 50 ticks per second, 20ms, 160 samples per second */
@@ -606,9 +607,9 @@
 	struct ast_frame fax_frame = {
 		.frametype = AST_FRAME_VOICE,
 		.src = "res_fax_spandsp_g711",
+		.subclass.format = ast_format_slin,
 	};
 	struct ast_frame *f = &fax_frame;
-	ast_format_set(&fax_frame.subclass.format, AST_FORMAT_SLINEAR, 0);
 
 	if (ast_timer_ack(p->timer, 1) < 0) {
 		ast_log(LOG_ERROR, "Failed to acknowledge timer for FAX session '%d'\n", s->id);
@@ -718,6 +719,7 @@
 	struct ast_frame *f;
 	struct ast_frame t30_frame = {
 		.frametype = AST_FRAME_VOICE,
+		.subclass.format = ast_format_slin,
 		.src = "res_fax_spandsp_g711",
 		.samples = samples,
 		.flags = AST_FAX_FRFLAG_GATEWAY,
@@ -725,7 +727,6 @@
 
 	AST_FRAME_SET_BUFFER(&t30_frame, buffer, AST_FRIENDLY_OFFSET, t30_frame.samples * sizeof(int16_t));
 
-	ast_format_set(&t30_frame.subclass.format, AST_FORMAT_SLINEAR, 0);
 	if (!(f = ast_frisolate(&t30_frame))) {
 		return p->isdone ? -1 : res;
 	}
@@ -847,7 +848,8 @@
 	/* Process a IFP packet */
 	if ((f->frametype == AST_FRAME_MODEM) && (f->subclass.integer == AST_MODEM_T38)) {
 		return t38_core_rx_ifp_packet(p->t38_core_state, f->data.ptr, f->datalen, f->seqno);
-	} else if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.format.id == AST_FORMAT_SLINEAR)) {
+	} else if ((f->frametype == AST_FRAME_VOICE) &&
+		(ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
 		return t38_gateway_rx(&p->t38_gw_state, f->data.ptr, f->samples);
 	}
 

Modified: team/group/media_formats-reviewed/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/res/res_musiconhold.c?view=diff&rev=411014&r1=411013&r2=411014
==============================================================================
--- team/group/media_formats-reviewed/res/res_musiconhold.c (original)
+++ team/group/media_formats-reviewed/res/res_musiconhold.c Sun Mar 23 06:47:51 2014
@@ -164,8 +164,8 @@
 	/*! Holds a reference to the MOH class. */
 	struct mohclass *class;
 	char name[MAX_MUSICCLASS];
-	struct ast_format origwfmt;
-	struct ast_format mohwfmt;
+	struct ast_format *origwfmt;
+	struct ast_format *mohwfmt;
 	int announcement;
 	int samples;
 	int sample_queue;
@@ -204,7 +204,7 @@
 	int total_files;
 	unsigned int flags;
 	/*! The format from the MOH source, not applicable to "files" mode */
-	struct ast_format format;
+	struct ast_format *format;
 	/*! The pid of the external application delivering MOH */
 	int pid;
 	time_t start;
@@ -222,7 +222,7 @@
 
 struct mohdata {
 	int pipe[2];
-	struct ast_format origwfmt;
+	struct ast_format *origwfmt;
 	struct mohclass *parent;
 	struct ast_frame f;
 	AST_LIST_ENTRY(mohdata) list;
@@ -281,9 +281,11 @@
 	
 	ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
 
-	ast_format_clear(&state->mohwfmt); /* make sure to clear this format before restoring the original format. */
-	if (state->origwfmt.id && ast_set_write_format(chan, &state->origwfmt)) {
-		ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan), ast_getformatname(&state->origwfmt));
+	ao2_ref(state->mohwfmt, -1);
+	state->mohwfmt = NULL; /* make sure to clear this format before restoring the original format */
+	if (state->origwfmt && ast_set_write_format(chan, state->origwfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan),
+			ast_format_get_name(state->origwfmt));
 	}
 
 	state->save_pos = state->pos;
@@ -397,15 +399,16 @@
 	/* In order to prevent a recursive call to this function as a result
 	 * of setting the moh write format back on the channel. Clear
 	 * the moh write format before setting the write format on the channel.*/
-	if (&state->origwfmt.id) {
-		struct ast_format tmp;
-
-		ast_format_copy(&tmp, ast_channel_writeformat(chan));
-		if (state->mohwfmt.id) {
-			ast_format_clear(&state->origwfmt);
-			ast_set_write_format(chan, &state->mohwfmt);
-		}
-		ast_format_copy(&state->origwfmt, &tmp);
+	if (state->origwfmt) {
+		struct ast_format *tmp;
+
+		tmp = ast_format_copy(ast_channel_writeformat(chan));
+		ao2_cleanup(state->origwfmt);
+		state->origwfmt = NULL;
+		if (state->mohwfmt) {
+			ast_set_write_format(chan, state->mohwfmt);
+		}
+		state->origwfmt = tmp;
 	}
 }
 
@@ -429,8 +432,9 @@
 			ast_channel_unlock(chan);
 			state->samples += f->samples;
 			state->sample_queue -= f->samples;
-			if (ast_format_cmp(&f->subclass.format, &state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
-				ast_format_copy(&state->mohwfmt, &f->subclass.format);
+			if (ast_format_cmp(f->subclass.format, state->mohwfmt) == AST_FORMAT_CMP_NOT_EQUAL) {
+				ao2_cleanup(state->mohwfmt);
+				state->mohwfmt = ast_format_copy(f->subclass.format);
 			}
 			res = ast_write(chan, f);
 			ast_frfree(f);
@@ -478,8 +482,8 @@
 	}
 
 	state->class = mohclass_ref(class, "Reffing music class for channel");
-	ast_format_copy(&state->origwfmt, ast_channel_writeformat(chan));
-	ast_format_copy(&state->mohwfmt, ast_channel_writeformat(chan));
+	state->origwfmt = ast_format_copy(ast_channel_writeformat(chan));
+	state->mohwfmt = ast_format_copy(ast_channel_writeformat(chan));
 
 	/* For comparison on restart of MOH (see above) */
 	ast_copy_string(state->name, class->name, sizeof(state->name));
@@ -730,7 +734,7 @@
 		if ((strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir")) && AST_LIST_EMPTY(&class->members))
 			continue;
 		/* Read mp3 audio */
-		len = ast_codec_get_len(&class->format, res);
+		len = ast_format_determine_length(class->format, res);
 
 		if ((res2 = read(class->srcfd, sbuf, len)) != len) {
 			if (!res2) {
@@ -934,7 +938,7 @@
 	fcntl(moh->pipe[1], F_SETFL, flags | O_NONBLOCK);
 
 	moh->f.frametype = AST_FRAME_VOICE;
-	ast_format_copy(&moh->f.subclass.format, &cl->format);
+	moh->f.subclass.format = cl->format;
 	moh->f.offset = AST_FRIENDLY_OFFSET;
 
 	moh->parent = mohclass_ref(cl, "Reffing music class for mohdata parent");
@@ -950,7 +954,7 @@
 {
 	struct mohdata *moh = data;
 	struct mohclass *class = moh->parent;
-	struct ast_format oldwfmt;
+	struct ast_format *oldwfmt;
 
 	ao2_lock(class);
 	AST_LIST_REMOVE(&moh->parent->members, moh, list);	
@@ -959,7 +963,7 @@
 	close(moh->pipe[0]);
 	close(moh->pipe[1]);
 
-	ast_format_copy(&oldwfmt, &moh->origwfmt);
+	oldwfmt = moh->origwfmt;
 
 	moh->parent = class = mohclass_unref(class, "unreffing moh->parent upon deactivation of generator");
 
@@ -972,13 +976,15 @@
 		if (state && state->class) {
 			state->class = mohclass_unref(state->class, "Unreffing channel's music class upon deactivation of generator");
 		}
-		if (oldwfmt.id && ast_set_write_format(chan, &oldwfmt)) {
+		if (oldwfmt && ast_set_write_format(chan, oldwfmt)) {
 			ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n",
-					ast_channel_name(chan), ast_getformatname(&oldwfmt));
+					ast_channel_name(chan), ast_format_get_name(oldwfmt));
 		}
 
 		ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
 	}
+
+	ao2_cleanup(oldwfmt);
 }
 
 static void *moh_alloc(struct ast_channel *chan, void *params)
@@ -1004,9 +1010,10 @@
 	}
 
 	if ((res = mohalloc(class))) {
-		ast_format_copy(&res->origwfmt, ast_channel_writeformat(chan));
-		if (ast_set_write_format(chan, &class->format)) {
-			ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan), ast_codec2str(&class->format));
+		res->origwfmt = ast_format_copy(ast_channel_writeformat(chan));
+		if (ast_set_write_format(chan, class->format)) {
+			ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", ast_channel_name(chan),
+				ast_format_get_name(class->format));
 			moh_release(NULL, res);
 			res = NULL;
 		} else {
@@ -1023,7 +1030,7 @@
 	short buf[1280 + AST_FRIENDLY_OFFSET / 2];
 	int res;
 
-	len = ast_codec_get_len(&moh->parent->format, samples);
+	len = ast_format_determine_length(moh->parent->format, samples);
 
 	if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
 		ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", (int)sizeof(buf), len, ast_channel_name(chan));
@@ -1035,7 +1042,7 @@
 
 	moh->f.datalen = res;
 	moh->f.data.ptr = buf + AST_FRIENDLY_OFFSET / 2;
-	moh->f.samples = ast_codec_get_samples(&moh->f);

[... 288 lines stripped ...]



More information about the svn-commits mailing list