[asterisk-commits] file: branch file/media_formats-apps r407954 - in /team/file/media_formats-ap...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 11 07:22:48 CST 2014


Author: file
Date: Tue Feb 11 07:22:35 2014
New Revision: 407954

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407954
Log:
Import all changes for moving applications to new media formats, and move new implementations into place.

Added:
    team/file/media_formats-apps/include/asterisk/format.h
      - copied, changed from r407953, team/file/media_formats-apps/include/asterisk/format_ng.h
    team/file/media_formats-apps/include/asterisk/format_cap.h
      - copied, changed from r407953, team/file/media_formats-apps/include/asterisk/format_cap_ng.h
    team/file/media_formats-apps/main/format.c
      - copied, changed from r407953, team/file/media_formats-apps/main/format_ng.c
    team/file/media_formats-apps/main/format_cap.c
      - copied, changed from r407953, team/file/media_formats-apps/main/format_cap_ng.c
Removed:
    team/file/media_formats-apps/include/asterisk/format_cap_ng.h
    team/file/media_formats-apps/include/asterisk/format_ng.h
    team/file/media_formats-apps/main/format_cap_ng.c
    team/file/media_formats-apps/main/format_ng.c
Modified:
    team/file/media_formats-apps/apps/app_agent_pool.c
    team/file/media_formats-apps/apps/app_alarmreceiver.c
    team/file/media_formats-apps/apps/app_amd.c
    team/file/media_formats-apps/apps/app_chanspy.c
    team/file/media_formats-apps/apps/app_confbridge.c
    team/file/media_formats-apps/apps/app_dahdibarge.c
    team/file/media_formats-apps/apps/app_dictate.c
    team/file/media_formats-apps/apps/app_dumpchan.c
    team/file/media_formats-apps/apps/app_festival.c
    team/file/media_formats-apps/apps/app_ices.c
    team/file/media_formats-apps/apps/app_meetme.c
    team/file/media_formats-apps/apps/app_milliwatt.c
    team/file/media_formats-apps/apps/app_mixmonitor.c
    team/file/media_formats-apps/apps/app_mp3.c
    team/file/media_formats-apps/apps/app_nbscat.c
    team/file/media_formats-apps/apps/app_originate.c
    team/file/media_formats-apps/apps/app_record.c
    team/file/media_formats-apps/apps/app_sms.c
    team/file/media_formats-apps/apps/app_speech_utils.c
    team/file/media_formats-apps/apps/app_talkdetect.c
    team/file/media_formats-apps/apps/app_test.c
    team/file/media_formats-apps/apps/app_voicemail.c
    team/file/media_formats-apps/apps/app_waitforsilence.c
    team/file/media_formats-apps/apps/confbridge/conf_chan_record.c
    team/file/media_formats-apps/channels/chan_alsa.c
    team/file/media_formats-apps/channels/chan_bridge_media.c
    team/file/media_formats-apps/channels/chan_oss.c
    team/file/media_formats-apps/codecs/codec_adpcm.c
    team/file/media_formats-apps/codecs/ex_adpcm.h
    team/file/media_formats-apps/codecs/ex_alaw.h
    team/file/media_formats-apps/include/asterisk/channel.h
    team/file/media_formats-apps/include/asterisk/codec.h
    team/file/media_formats-apps/include/asterisk/data.h
    team/file/media_formats-apps/include/asterisk/format_cache.h
    team/file/media_formats-apps/include/asterisk/frame.h
    team/file/media_formats-apps/include/asterisk/mod_format.h
    team/file/media_formats-apps/include/asterisk/rtp_engine.h
    team/file/media_formats-apps/include/asterisk/slin.h
    team/file/media_formats-apps/include/asterisk/translate.h
    team/file/media_formats-apps/main/channel.c
    team/file/media_formats-apps/main/channel_internal_api.c
    team/file/media_formats-apps/main/codec.c
    team/file/media_formats-apps/main/format_cache.c
    team/file/media_formats-apps/main/frame.c
    team/file/media_formats-apps/pbx/pbx_spool.c

Modified: team/file/media_formats-apps/apps/app_agent_pool.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_agent_pool.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_agent_pool.c (original)
+++ team/file/media_formats-apps/apps/app_agent_pool.c Tue Feb 11 07:22:35 2014
@@ -2046,8 +2046,8 @@
 	}
 
 	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_channel_readformat(chan)->codec->name,
+		ast_channel_writeformat(chan)->codec->name);
 	ast_channel_lock(chan);
 	send_agent_login(chan, agent->username);
 	ast_channel_unlock(chan);

Modified: team/file/media_formats-apps/apps/app_alarmreceiver.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_alarmreceiver.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_alarmreceiver.c (original)
+++ team/file/media_formats-apps/apps/app_alarmreceiver.c Tue Feb 11 07:22:35 2014
@@ -65,6 +65,7 @@
 #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 @@
 	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;
 		}

Modified: team/file/media_formats-apps/apps/app_amd.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_amd.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_amd.c (original)
+++ team/file/media_formats-apps/apps/app_amd.c Tue Feb 11 07:22:35 2014
@@ -52,6 +52,7 @@
 #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 @@
 	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 @@
 		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_channel_readformat(chan)->codec->name);
 
 	/* Lets parse the arguments. */
 	if (!ast_strlen_zero(parse)) {
@@ -255,8 +255,8 @@
 				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 = ast_format_copy(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 @@
 		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 @@
 	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 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;
 }
 

Modified: team/file/media_formats-apps/apps/app_chanspy.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_chanspy.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_chanspy.c (original)
+++ team/file/media_formats-apps/apps/app_chanspy.c Tue Feb 11 07:22:35 2014
@@ -57,6 +57,7 @@
 #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
@@ -441,9 +442,6 @@
 {
 	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) {
@@ -454,9 +452,9 @@
 
 	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);
@@ -1122,7 +1120,7 @@
 		.volume = '#',
 		.exit = '\0',
 	};
-	struct ast_format oldwf;
+	RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
 	int volfactor = 0;
 	int res;
 	char *mailbox = NULL;
@@ -1135,7 +1133,6 @@
 	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;
@@ -1199,8 +1196,8 @@
 		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 = ast_format_copy(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;
 	}
@@ -1220,7 +1217,7 @@
 	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)) {
@@ -1242,7 +1239,7 @@
 		.volume = '#',
 		.exit = '\0',
 	};
-	struct ast_format oldwf;
+	RAII_VAR(struct ast_format *, oldwf, NULL, ao2_cleanup);
 	int volfactor = 0;
 	int res;
 	char *mailbox = NULL;
@@ -1254,7 +1251,6 @@
 	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;
@@ -1324,8 +1320,8 @@
 		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 = ast_format_copy(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;
 	}
@@ -1346,7 +1342,7 @@
 	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;
@@ -1361,13 +1357,13 @@
 		.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);
 	}
@@ -1375,16 +1371,18 @@
 	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 = ast_format_copy(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;
 }

Modified: team/file/media_formats-apps/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_confbridge.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_confbridge.c (original)
+++ team/file/media_formats-apps/apps/app_confbridge.c Tue Feb 11 07:22:35 2014
@@ -70,6 +70,7 @@
 #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">
@@ -657,7 +658,6 @@
 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;
@@ -668,16 +668,16 @@
 		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_add(cap, ast_format_slin, 0);
 
 	conference->record_chan = ast_request("CBRec", cap, NULL,
 		conference->name, NULL);
-	cap = ast_format_cap_destroy(cap);
+	ao2_ref(cap, -1);
 	if (!conference->record_chan) {
 		return -1;
 	}
@@ -1356,16 +1356,15 @@
 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_add(cap, ast_format_slin, 0);
 	conference->playback_chan = ast_request("CBAnn", cap, NULL,
 		conference->name, NULL);
-	cap = ast_format_cap_destroy(cap);
+	ao2_ref(cap, -1);
 	if (!conference->playback_chan) {
 		return -1;
 	}
@@ -3154,7 +3153,7 @@
 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);
 }
 
 /*!
@@ -3169,11 +3168,11 @@
  */
 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_add_all_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);

Modified: team/file/media_formats-apps/apps/app_dahdibarge.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_dahdibarge.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_dahdibarge.c (original)
+++ team/file/media_formats-apps/apps/app_dahdibarge.c Tue Feb 11 07:22:35 2014
@@ -54,6 +54,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/say.h"
 #include "asterisk/utils.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="DAHDIBarge" language="en_US">
@@ -116,13 +117,13 @@
 	char *buf = __buf + AST_FRIENDLY_OFFSET;
 
 	/* Set it into U-law mode (write) */
-	if (ast_set_write_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
+	if (ast_set_write_format(chan, ast_format_ulaw) < 0) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", ast_channel_name(chan));
 		goto outrun;
 	}
 
 	/* Set it into U-law mode (read) */
-	if (ast_set_read_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
+	if (ast_set_read_format(chan, ast_format_ulaw) < 0) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", ast_channel_name(chan));
 		goto outrun;
 	}
@@ -217,11 +218,11 @@
 				break;
 			} else if (fd != ast_channel_fd(chan, 0)) {
 				if (f->frametype == AST_FRAME_VOICE) {
-					if (f->subclass.format.id == AST_FORMAT_ULAW) {
+					if (ast_format_cmp(f->subclass.format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
 						/* Carefully write */
 						careful_write(fd, f->data.ptr, f->datalen);
 					} else
-						ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", ast_getformatname(&f->subclass.format));
+						ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", f->subclass.format->codec->name);
 				}
 			}
 			ast_frfree(f);
@@ -230,7 +231,7 @@
 			if (res > 0) {
 				memset(&fr, 0, sizeof(fr));
 				fr.frametype = AST_FRAME_VOICE;
-				ast_format_set(&fr.subclass.format, AST_FORMAT_ULAW, 0);
+				fr.subclass.format = ast_format_copy(ast_format_ulaw);
 				fr.datalen = res;
 				fr.samples = res;
 				fr.data.ptr = buf;
@@ -239,6 +240,7 @@
 					ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
 					/* break; */
 				}
+				ast_frfree(&fr);
 			} else 
 				ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
 		}

Modified: team/file/media_formats-apps/apps/app_dictate.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_dictate.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_dictate.c (original)
+++ team/file/media_formats-apps/apps/app_dictate.c Tue Feb 11 07:22:35 2014
@@ -43,6 +43,7 @@
 #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 @@
 		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 @@
 	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 = ast_format_copy(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 @@
 			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;
 }

Modified: team/file/media_formats-apps/apps/app_dumpchan.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_dumpchan.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_dumpchan.c (original)
+++ team/file/media_formats-apps/apps/app_dumpchan.c Tue Feb 11 07:22:35 2014
@@ -144,10 +144,10 @@
 		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_channel_writeformat(c)->codec->name,
+		ast_channel_readformat(c)->codec->name,
+		ast_channel_rawwriteformat(c)->codec->name,
+		ast_channel_rawreadformat(c)->codec->name,
 		ast_channel_writetrans(c) ? "Yes" : "No",
 		ast_translate_path_to_str(ast_channel_writetrans(c), &write_transpath),
 		ast_channel_readtrans(c) ? "Yes" : "No",

Modified: team/file/media_formats-apps/apps/app_festival.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_festival.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_festival.c (original)
+++ team/file/media_formats-apps/apps/app_festival.c Tue Feb 11 07:22:35 2014
@@ -63,6 +63,7 @@
 #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 @@
 	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 @@
 		.f = { 0, },
 	};
 
-	ast_format_clear(&owriteformat);
 	if (pipe(fds)) {
 		ast_log(LOG_WARNING, "Unable to create pipe\n");
 		return -1;
@@ -199,12 +199,19 @@
 	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 = ast_format_copy(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;
-	}
+		ao2_cleanup(owriteformat);
+		return -1;
+	}
+
+	myf.f.frametype = AST_FRAME_VOICE;
+	myf.f.subclass.format = ast_format_copy(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 @@
 				}
 				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 @@
 	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;
 }
 

Modified: team/file/media_formats-apps/apps/app_ices.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_ices.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_ices.c (original)
+++ team/file/media_formats-apps/apps/app_ices.c Tue Feb 11 07:22:35 2014
@@ -48,6 +48,7 @@
 #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 @@
 	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 @@
 		return -1;
 	}
 
-	ast_format_copy(&oreadformat, ast_channel_readformat(chan));
-	res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+	oreadformat = ast_format_copy(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 @@
 
 	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;
 }

Modified: team/file/media_formats-apps/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_meetme.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_meetme.c (original)
+++ team/file/media_formats-apps/apps/app_meetme.c Tue Feb 11 07:22:35 2014
@@ -1613,8 +1613,7 @@
 	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);
 
@@ -1626,7 +1625,7 @@
 	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_add(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))) {
@@ -1674,8 +1673,8 @@
 	/* Setup a new channel for playback of audio files */
 	cnf->chan = ast_request("DAHDI", cap_slin, 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;
@@ -1711,7 +1710,7 @@
 		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);
 
@@ -3093,8 +3092,8 @@
 
 			ast_mutex_lock(&conf->recordthreadlock);
 			if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", cap_slin, 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;
@@ -3219,13 +3218,12 @@
 	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_add(cap_slin, ast_format_slin, 0);
 
 	if (!(user = ao2_alloc(sizeof(*user), NULL))) {
 		goto conf_run_cleanup;
@@ -3347,8 +3345,8 @@
 	ast_mutex_lock(&conf->recordthreadlock);
 	if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) &&
 		((conf->lchan = ast_request("DAHDI", cap_slin, 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;
@@ -3574,12 +3572,12 @@
 		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;
 	}
@@ -4133,7 +4131,7 @@
 					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);
 					}
@@ -4288,7 +4286,7 @@
 				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;
@@ -4300,7 +4298,7 @@
 						 )) {
 						int idx;
 						for (idx = 0; idx < AST_FRAME_BITS; idx++) {
-							if (ast_format_to_old_bitfield(ast_channel_rawwriteformat(chan)) & (1 << idx)) {
+							if (ast_channel_rawwriteformat(chan)->codec->original_id & (1 << idx)) {
 								break;
 							}
 						}
@@ -4315,11 +4313,7 @@
 									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);
@@ -4478,7 +4472,7 @@
 
 
 conf_run_cleanup:
-	cap_slin = ast_format_cap_destroy(cap_slin);
+	ao2_cleanup(cap_slin);
 
 	return ret;
 }

Modified: team/file/media_formats-apps/apps/app_milliwatt.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_milliwatt.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_milliwatt.c (original)
+++ team/file/media_formats-apps/apps/app_milliwatt.c Tue Feb 11 07:22:35 2014
@@ -37,6 +37,7 @@
 #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 @@
 {
 	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_copy(ast_format_ulaw);
 	wf.data.ptr = buf + AST_FRIENDLY_OFFSET;
 
 	/* Instead of len, use samples, because channel.c generator_force
@@ -108,7 +110,10 @@
 		*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 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);

Modified: team/file/media_formats-apps/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_mixmonitor.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_mixmonitor.c (original)
+++ team/file/media_formats-apps/apps/app_mixmonitor.c Tue Feb 11 07:22:35 2014
@@ -57,6 +57,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/test.h"
 #include "asterisk/mixmonitor.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="MixMonitor" language="en_US">
@@ -582,7 +583,7 @@
 				*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, tmp->fmt->format->codec->sample_rate);
 			}
 		}
 	}
@@ -601,7 +602,7 @@
 
 	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) {
@@ -619,10 +620,9 @@
 	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);
@@ -631,7 +631,7 @@
 		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);
 
@@ -711,6 +711,8 @@
 		ast_cond_wait(&mixmonitor->mixmonitor_ds->destruction_condition, &mixmonitor->mixmonitor_ds->lock);
 	}
 	ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
+
+	ao2_ref(format_slin, -1);
 
 	/* kill the audiohook */
 	destroy_monitor_audiohook(mixmonitor);

Modified: team/file/media_formats-apps/apps/app_mp3.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_mp3.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_mp3.c (original)
+++ team/file/media_formats-apps/apps/app_mp3.c Tue Feb 11 07:22:35 2014
@@ -47,6 +47,7 @@
 #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 @@
 	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 @@
 		.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 @@
 	
 	ast_stopstream(chan);
 
-	ast_format_copy(&owriteformat, ast_channel_writeformat(chan));
-	res = ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR);
+	owriteformat = ast_format_copy(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_copy(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 @@
 			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 @@
 	
 	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;
 }

Modified: team/file/media_formats-apps/apps/app_nbscat.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media_formats-apps/apps/app_nbscat.c?view=diff&rev=407954&r1=407953&r2=407954
==============================================================================
--- team/file/media_formats-apps/apps/app_nbscat.c (original)
+++ team/file/media_formats-apps/apps/app_nbscat.c Tue Feb 11 07:22:35 2014
@@ -46,6 +46,7 @@
 #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 @@
 	int fds[2];
 	int ms = -1;
 	int pid = -1;

[... 2066 lines stripped ...]



More information about the asterisk-commits mailing list