[svn-commits] file: branch group/media_formats r407403 - in /team/group/media_formats: apps...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 5 08:27:11 CST 2014


Author: file
Date: Wed Feb  5 08:27:02 2014
New Revision: 407403

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407403
Log:
More, more, more.

Modified:
    team/group/media_formats/apps/app_agent_pool.c
    team/group/media_formats/apps/app_alarmreceiver.c
    team/group/media_formats/channels/chan_alsa.c
    team/group/media_formats/channels/chan_bridge_media.c
    team/group/media_formats/channels/chan_oss.c
    team/group/media_formats/include/asterisk/format_cap.h
    team/group/media_formats/main/channel.c
    team/group/media_formats/main/channel_internal_api.c
    team/group/media_formats/main/format_cap_ng.c
    team/group/media_formats/main/frame.c
    team/group/media_formats/pbx/pbx_spool.c

Modified: team/group/media_formats/apps/app_agent_pool.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_agent_pool.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/apps/app_agent_pool.c (original)
+++ team/group/media_formats/apps/app_agent_pool.c Wed Feb  5 08:27:02 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/group/media_formats/apps/app_alarmreceiver.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/apps/app_alarmreceiver.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/apps/app_alarmreceiver.c (original)
+++ team/group/media_formats/apps/app_alarmreceiver.c Wed Feb  5 08:27:02 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"
@@ -194,6 +195,9 @@
 /* Misc variables */
 static char event_file[14] = "/event-XXXXXX";
 
+static struct ast_format *ulaw_format;
+static struct ast_format *alaw_format;
+
 /*!
  * \brief Attempt to access a database variable and increment it
  *
@@ -798,19 +802,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), ulaw_format) == AST_FORMAT_CMP_NOT_EQUAL) &&
+		(ast_format_cmp(ast_channel_writeformat(chan), alaw_format) == 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, ulaw_format)) {
 			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), ulaw_format) == AST_FORMAT_CMP_NOT_EQUAL) &&
+		(ast_format_cmp(ast_channel_readformat(chan), alaw_format) == 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, ulaw_format)) {
 			ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",ast_channel_name(chan));
 			return -1;
 		}
@@ -959,6 +963,9 @@
  */
 static int unload_module(void)
 {
+	ao2_ref(ulaw_format, -1);
+	ao2_ref(alaw_format, -1);
+
 	return ast_unregister_application(app);
 }
 
@@ -974,13 +981,30 @@
  */
 static int load_module(void)
 {
+	ulaw_format = ast_format_cache_get("ulaw");
+	if (!ulaw_format) {
+		ast_log(LOG_ERROR, "Expected format 'ulaw' in format cache does not exist\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	alaw_format = ast_format_cache_get("alaw");
+	if (!alaw_format) {
+		ast_log(LOG_ERROR, "Expected format 'alaw' in format cache does not exist\n");
+		ao2_ref(alaw_format, -1);
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	if (load_config(0)) {
 		if (ast_register_application_xml(app, alarmreceiver_exec)) {
+			ao2_ref(ulaw_format, -1);
+			ao2_ref(alaw_format, -1);
 			return AST_MODULE_LOAD_FAILURE;
 		}
 		return AST_MODULE_LOAD_SUCCESS;
 	}
 
+	ao2_ref(ulaw_format, -1);
+	ao2_ref(alaw_format, -1);
 	return AST_MODULE_LOAD_DECLINE;
 }
 

Modified: team/group/media_formats/channels/chan_alsa.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_alsa.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/channels/chan_alsa.c (original)
+++ team/group/media_formats/channels/chan_alsa.c Wed Feb  5 08:27:02 2014
@@ -515,7 +515,7 @@
 		}
 
 		f.frametype = AST_FRAME_VOICE;
-		f.subclass.format = ao2_bump(slin_format);
+		f.subclass.format = ast_format_copy(slin_format);
 		f.samples = FRAME_SIZE;
 		f.datalen = FRAME_SIZE * 2;
 		f.data.ptr = buf;
@@ -967,7 +967,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	if (!(alsa_tech.capabilities = ast_format_cap_alloc(0))) {
+	if (!(alsa_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 	ast_format_cap_add(alsa_tech.capabilities, slin_format, 0);

Modified: team/group/media_formats/channels/chan_bridge_media.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_bridge_media.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/channels/chan_bridge_media.c (original)
+++ team/group/media_formats/channels/chan_bridge_media.c Wed Feb  5 08:27:02 2014
@@ -164,11 +164,13 @@
 static void cleanup_capabilities(void)
 {
 	if (announce_tech.capabilities) {
-		announce_tech.capabilities = ast_format_cap_destroy(announce_tech.capabilities);
+		ao2_ref(announce_tech.capabilities, -1);
+		announce_tech.capabilities = NULL;
 	}
 
 	if (record_tech.capabilities) {
-		record_tech.capabilities = ast_format_cap_destroy(record_tech.capabilities);
+		ao2_ref(record_tech.capabilities, -1);
+		record_tech.capabilities = NULL;
 	}
 }
 
@@ -182,18 +184,18 @@
 
 static int load_module(void)
 {
-	announce_tech.capabilities = ast_format_cap_alloc(0);
+	announce_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!announce_tech.capabilities) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	record_tech.capabilities = ast_format_cap_alloc(0);
+	record_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!record_tech.capabilities) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	ast_format_cap_add_all(announce_tech.capabilities);
-	ast_format_cap_add_all(record_tech.capabilities);
+	ast_format_cap_add_all_by_type(announce_tech.capabilities, AST_MEDIA_TYPE_UNKNOWN);
+	ast_format_cap_add_all_by_type(record_tech.capabilities, AST_MEDIA_TYPE_UNKNOWN);
 
 	if (ast_channel_register(&announce_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",

Modified: team/group/media_formats/channels/chan_oss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_oss.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/channels/chan_oss.c (original)
+++ team/group/media_formats/channels/chan_oss.c Wed Feb  5 08:27:02 2014
@@ -69,6 +69,7 @@
 #include "asterisk/musiconhold.h"
 #include "asterisk/app.h"
 #include "asterisk/bridge.h"
+#include "asterisk/format_cache.h"
 
 #include "console_video.h"
 
@@ -241,6 +242,9 @@
 static char *config = "oss.conf";	/* default config file */
 
 static int oss_debug;
+
+/* Signed linear format that is used by all channels and frames */
+static struct ast_format *slin_format;
 
 /*!
  * \brief descriptor for one of our channels.
@@ -726,7 +730,7 @@
 		return f;
 	/* ok we can build and deliver the frame to the caller */
 	f->frametype = AST_FRAME_VOICE;
-	ast_format_set(&f->subclass.format, AST_FORMAT_SLINEAR, 0);
+	f->subclass.format = ast_format_copy(slin_format);
 	f->samples = FRAME_SIZE;
 	f->datalen = FRAME_SIZE * 2;
 	f->data.ptr = o->oss_read_buf + AST_FRIENDLY_OFFSET;
@@ -804,9 +808,9 @@
 		setformat(o, O_RDWR);
 	ast_channel_set_fd(c, 0, o->sounddev); /* -1 if device closed, override later */
 
-	ast_format_set(ast_channel_readformat(c), AST_FORMAT_SLINEAR, 0);
-	ast_format_set(ast_channel_writeformat(c), AST_FORMAT_SLINEAR, 0);
-	ast_format_cap_add(ast_channel_nativeformats(c), ast_channel_readformat(c));
+	ast_channel_set_readformat(c, slin_format);
+	ast_channel_set_writeformat(c, slin_format);
+	ast_channel_nativeformats_set(c, oss_tech.capabilities);
 
 	/* if the console makes the call, add video to the offer */
 	/* if (state == AST_STATE_RINGING) TODO XXX CONSOLE VIDEO IS DISABLED UNTIL IT GETS A MAINTAINER
@@ -852,7 +856,6 @@
 	);
 	char *parse = ast_strdupa(data);
 	char buf[256];
-	struct ast_format tmpfmt;
 
 	AST_NONSTANDARD_APP_ARGS(args, parse, '/');
 	o = find_desc(args.name);
@@ -863,7 +866,7 @@
 		/* XXX we could default to 'dsp' perhaps ? */
 		return NULL;
 	}
-	if (!(ast_format_cap_iscompatible(cap, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0)))) {
+	if (!ast_format_cap_iscompatible_format(cap, slin_format)) {
 		ast_log(LOG_NOTICE, "Format %s unsupported\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
 		return NULL;
 	}
@@ -1453,7 +1456,12 @@
 	struct ast_config *cfg = NULL;
 	char *ctg = NULL;
 	struct ast_flags config_flags = { 0 };
-	struct ast_format tmpfmt;
+
+	slin_format = ast_format_cache_get("slin");
+	if (!slin_format) {
+		ast_log(LOG_ERROR, "Expected format 'slin' in format cache does not exist\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
@@ -1483,7 +1491,7 @@
 	if (!(oss_tech.capabilities = ast_format_cap_alloc(0))) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
-	ast_format_cap_add(oss_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(oss_tech.capabilities, slin_format, 0);
 
 	/* TODO XXX CONSOLE VIDEO IS DISABLE UNTIL IT HAS A MAINTAINER
 	 * add console_video_formats to oss_tech.capabilities once this occurs. */
@@ -1518,7 +1526,12 @@
 		ast_free(o);
 		o = next;
 	}
-	oss_tech.capabilities = ast_format_cap_destroy(oss_tech.capabilities);
+	ao2_cleanup(oss_tech.capabilities);
+	oss_tech.capabilities = NULL;
+
+	ao2_cleanup(slin_format);
+	slin_format = NULL;
+
 	return 0;
 }
 

Modified: team/group/media_formats/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cap.h?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/include/asterisk/format_cap.h (original)
+++ team/group/media_formats/include/asterisk/format_cap.h Wed Feb  5 08:27:02 2014
@@ -224,4 +224,10 @@
  */
 char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap);
 
+/*! \brief Parse an "allow" or "deny" line in a channel or device configuration
+	and update the capabilities and pref if provided.
+	\return Returns number of errors encountered during parsing
+ */
+int ast_parse_allow_disallow(struct ast_format_cap *cap, const char *list, int allowing);
+
 #endif /* _AST_FORMAT_CAP_H */

Modified: team/group/media_formats/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/channel.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/main/channel.c (original)
+++ team/group/media_formats/main/channel.c Wed Feb  5 08:27:02 2014
@@ -2369,7 +2369,12 @@
 		ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), device_name);
 	}
 
-	ast_channel_nativeformats_set(chan, ast_format_cap_destroy(ast_channel_nativeformats(chan)));
+	ast_channel_set_oldwriteformat(chan, NULL);
+	ast_channel_set_writeformat(chan, NULL);
+	ast_channel_set_rawwriteformat(chan, NULL);
+	ast_channel_set_readformat(chan, NULL);
+	ast_channel_set_rawreadformat(chan, NULL);
+	ast_channel_nativeformats_set(chan, NULL);
 	if (callid) {
 		ast_callid_unref(callid);
 	}

Modified: team/group/media_formats/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/channel_internal_api.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/main/channel_internal_api.c (original)
+++ team/group/media_formats/main/channel_internal_api.c Wed Feb  5 08:27:02 2014
@@ -802,7 +802,7 @@
 }
 struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan)
 {
-	return ao2_bump(chan->nativeformats);
+	return chan->nativeformats;
 }
 void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
 {
@@ -958,23 +958,23 @@
 }
 struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan)
 {
-	return ao_bump(chan->oldwriteformat);
+	return chan->oldwriteformat;
 }
 struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan)
 {
-	return ao2_bump(chan->rawreadformat);
+	return chan->rawreadformat;
 }
 struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan)
 {
-	return ao2_bump(chan->rawwriteformat);
+	return chan->rawwriteformat;
 }
 struct ast_format *ast_channel_readformat(struct ast_channel *chan)
 {
-	return ao2_bump(chan->readformat);
+	return chan->readformat;
 }
 struct ast_format *ast_channel_writeformat(struct ast_channel *chan)
 {
-	return ao2_bump(chan->writeformat);
+	return chan->writeformat;
 }
 struct ast_hangup_handler_list *ast_channel_hangup_handlers(struct ast_channel *chan)
 {

Modified: team/group/media_formats/main/format_cap_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_cap_ng.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/main/format_cap_ng.c (original)
+++ team/group/media_formats/main/format_cap_ng.c Wed Feb  5 08:27:02 2014
@@ -483,4 +483,58 @@
 	}
 
 	return buf;
+}
+
+int ast_parse_allow_disallow(struct ast_format_cap *cap, const char *list, int allowing)
+{
+	int errors = 0, all = 0, iter_allowing;
+	char *parse = NULL, *this = NULL, *psize = NULL;
+
+	parse = ast_strdupa(list);
+	while ((this = strsep(&parse, ","))) {
+		int framems = 0;
+		struct ast_format *format = NULL;
+
+		iter_allowing = allowing;
+		if (*this == '!') {
+			this++;
+			iter_allowing = !allowing;
+		}
+		if ((psize = strrchr(this, ':'))) {
+			*psize++ = '\0';
+			ast_debug(1, "Packetization for codec: %s is %s\n", this, psize);
+			framems = atoi(psize);
+			if (framems < 0) {
+				framems = 0;
+				errors++;
+				ast_log(LOG_WARNING, "Bad packetization value for codec %s\n", this);
+			}
+		}
+		all = strcasecmp(this, "all") ? 0 : 1;
+
+		if (!all && (format = ast_format_cache_get(this))) {
+			ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", iter_allowing ? "allow" : "disallow", this);
+			errors++;
+			continue;
+		}
+
+		if (cap) {
+			if (iter_allowing) {
+				if (all) {
+					ast_format_cap_add_all_by_type(cap, AST_MEDIA_TYPE_UNKNOWN);
+				} else {
+					ast_format_cap_add(cap, format, framems);
+				}
+			} else {
+				if (all) {
+					ast_format_cap_remove_all(cap);
+				} else {
+					ast_format_cap_remove(cap, format);
+				}
+			}
+		}
+
+		ao2_cleanup(format);
+	}
+	return errors;
 }

Modified: team/group/media_formats/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/frame.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/main/frame.c (original)
+++ team/group/media_formats/main/frame.c Wed Feb  5 08:27:02 2014
@@ -117,7 +117,8 @@
 
 static void __frame_free(struct ast_frame *fr, int cache)
 {
-	if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO)) {
+	if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) ||
+		(fr->frametype == AST_FRAME_IMAGE)) {
 		ao2_cleanup(fr->subclass.format);
 	}
 
@@ -307,7 +308,7 @@
 	}
 
 	out->frametype = f->frametype;
-	ast_format_copy(&out->subclass.format, &f->subclass.format);
+	out->subclass.format = ast_format_copy(f->subclass.format);
 	out->datalen = f->datalen;
 	out->samples = f->samples;
 	out->delivery = f->delivery;

Modified: team/group/media_formats/pbx/pbx_spool.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/pbx/pbx_spool.c?view=diff&rev=407403&r1=407402&r2=407403
==============================================================================
--- team/group/media_formats/pbx/pbx_spool.c (original)
+++ team/group/media_formats/pbx/pbx_spool.c Wed Feb  5 08:27:02 2014
@@ -53,6 +53,8 @@
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
 #include "asterisk/options.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cache.h"
 
 /*
  * pbx_spool is similar in spirit to qcall, but with substantially enhanced functionality...
@@ -73,6 +75,8 @@
 
 static char qdir[255];
 static char qdonedir[255];
+
+static struct ast_format *slin_format;
 
 struct outgoing {
 	int retries;                              /*!< Current number of retries */
@@ -108,7 +112,7 @@
 	if (o->vars) {
 		ast_variables_destroy(o->vars);
 	}
-	o->capabilities = ast_format_cap_destroy(o->capabilities);
+	ao2_cleanup(o->capabilities);
 	ast_string_field_free_memory(o);
 	ast_free(o);
 }
@@ -116,7 +120,6 @@
 static struct outgoing *new_outgoing(const char *fn)
 {
 	struct outgoing *o;
-	struct ast_format tmpfmt;
 
 	o = ast_calloc(1, sizeof(*o));
 	if (!o) {
@@ -144,12 +147,12 @@
 		return NULL;
 	}
 
-	o->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	o->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!o->capabilities) {
 		free_outgoing(o);
 		return NULL;
 	}
-	ast_format_cap_add(o->capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(o->capabilities, slin_format, 0);
 
 	return o;
 }
@@ -226,7 +229,7 @@
 				o->maxretries = 0;
 			}
 		} else if (!strcasecmp(buf, "codecs")) {
-			ast_parse_allow_disallow(NULL, o->capabilities, c, 1);
+			ast_parse_allow_disallow(o->capabilities, c, 1);
 		} else if (!strcasecmp(buf, "context")) {
 			ast_string_field_set(o, context, c);
 		} else if (!strcasecmp(buf, "extension")) {
@@ -899,6 +902,12 @@
 	}
 	snprintf(qdonedir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing_done");
 
+	slin_format = ast_format_cache_get("slin");
+	if (!slin_format) {
+		ast_log(LOG_ERROR, "Expected format 'slin' in format cache does not exist\n");
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	if ((ret = ast_pthread_create_detached_background(&thread, NULL, scan_thread, NULL))) {
 		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
 		return AST_MODULE_LOAD_FAILURE;




More information about the svn-commits mailing list