[svn-commits] file: branch group/media_formats r408003 - in /team/group/media_formats: incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Feb 13 10:49:41 CST 2014


Author: file
Date: Thu Feb 13 10:49:35 2014
New Revision: 408003

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408003
Log:
These modules fall like dominos... dominos...

Modified:
    team/group/media_formats/include/asterisk/callerid.h
    team/group/media_formats/res/ari/resource_bridges.c
    team/group/media_formats/res/ari/resource_channels.c
    team/group/media_formats/res/ari/resource_sounds.c
    team/group/media_formats/res/res_adsi.c
    team/group/media_formats/res/res_agi.c
    team/group/media_formats/res/res_calendar.c
    team/group/media_formats/res/res_clioriginate.c

Modified: team/group/media_formats/include/asterisk/callerid.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/callerid.h?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/include/asterisk/callerid.h (original)
+++ team/group/media_formats/include/asterisk/callerid.h Thu Feb 13 10:49:35 2014
@@ -75,8 +75,8 @@
 /*! MWI MDMF format -- generate name, callerid, date and MWI fields */
 #define CID_MWI_TYPE_MDMF_FULL	0x02
 
-#define AST_LIN2X(a) ((codec->id == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
-#define AST_XLAW(a) ((codec->id == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))
+#define AST_LIN2X(a) ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
+#define AST_XLAW(a) ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (AST_ALAW(a)) : (AST_MULAW(a)))
 
 
 struct callerid_state;

Modified: team/group/media_formats/res/ari/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/ari/resource_bridges.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/ari/resource_bridges.c (original)
+++ team/group/media_formats/res/ari/resource_bridges.c Thu Feb 13 10:49:35 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/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/ari/resource_channels.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/ari/resource_channels.c (original)
+++ team/group/media_formats/res/ari/resource_channels.c Thu Feb 13 10:49:35 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/res/ari/resource_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/ari/resource_sounds.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/ari/resource_sounds.c (original)
+++ team/group/media_formats/res/ari/resource_sounds.c Thu Feb 13 10:49:35 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, format->codec->name)) {
+			ao2_ref(format, -1);
 			continue;
 		}
 
 		lang_format_pair = ast_json_pack("{s: s, s: s}",
 			"language", language,
-			"format", format_name);
+			"format", format->codec->name);
 		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/res/res_adsi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_adsi.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/res_adsi.c (original)
+++ team/group/media_formats/res/res_adsi.c Thu Feb 13 10:49:35 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,7 +155,12 @@
 {
 	/* 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 */
@@ -169,9 +175,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 +205,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 +216,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 +246,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 +307,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 +394,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 +422,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", writeformat->codec->name);
 			}
 		}
 		return -1;
@@ -454,11 +453,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/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_agi.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/res_agi.c (original)
+++ team/group/media_formats/res/res_agi.c Thu Feb 13 10:49:35 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),
+				readformat->codec->name);
+		}
+	}
+	ao2_ref(readformat, -1);
 	return res;
 }
 

Modified: team/group/media_formats/res/res_calendar.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_calendar.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/res_calendar.c (original)
+++ team/group/media_formats/res/res_calendar.c Thu Feb 13 10:49:35 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/res/res_clioriginate.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_clioriginate.c?view=diff&rev=408003&r1=408002&r2=408003
==============================================================================
--- team/group/media_formats/res/res_clioriginate.c (original)
+++ team/group/media_formats/res/res_clioriginate.c Thu Feb 13 10:49:35 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;
 }




More information about the svn-commits mailing list