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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 17 08:16:51 CST 2014


Author: file
Date: Mon Feb 17 08:16:47 2014
New Revision: 408268

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

Modified:
    team/group/media_formats/include/asterisk/audiohook.h
    team/group/media_formats/include/asterisk/bridge_channel.h
    team/group/media_formats/main/app.c
    team/group/media_formats/main/audiohook.c
    team/group/media_formats/main/bridge.c
    team/group/media_formats/main/bridge_basic.c
    team/group/media_formats/main/bridge_channel.c
    team/group/media_formats/main/callerid.c
    team/group/media_formats/main/ccss.c

Modified: team/group/media_formats/include/asterisk/audiohook.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/audiohook.h?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/include/asterisk/audiohook.h (original)
+++ team/group/media_formats/include/asterisk/audiohook.h Mon Feb 17 08:16:47 2014
@@ -109,7 +109,7 @@
 	struct ast_slinfactory write_factory;                  /*!< Factory where frames written to the channel will go through */
 	struct timeval read_time;                              /*!< Last time read factory was fed */
 	struct timeval write_time;                             /*!< Last time write factory was fed */
-	struct ast_format format;                              /*!< Format translation path is setup as */
+	struct ast_format *format;                             /*!< Format translation path is setup as */
 	struct ast_trans_pvt *trans_pvt;                       /*!< Translation path for reading frames */
 	ast_audiohook_manipulate_callback manipulate_callback; /*!< Manipulation callback */
 	struct ast_audiohook_options options;                  /*!< Applicable options */

Modified: team/group/media_formats/include/asterisk/bridge_channel.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/bridge_channel.h?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/include/asterisk/bridge_channel.h (original)
+++ team/group/media_formats/include/asterisk/bridge_channel.h Mon Feb 17 08:16:47 2014
@@ -133,9 +133,9 @@
 	 *  optimizing based upon talk detection. */
 	struct ast_bridge_tech_optimizations tech_args;
 	/*! Copy of read format used by chan before join */
-	struct ast_format read_format;
+	struct ast_format *read_format;
 	/*! Copy of write format used by chan before join */
-	struct ast_format write_format;
+	struct ast_format *write_format;
 	/*! Call ID associated with bridge channel */
 	struct ast_callid *callid;
 	/*! A clone of the roles living on chan when the bridge channel joins the bridge. This may require some opacification */

Modified: team/group/media_formats/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/app.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/app.c (original)
+++ team/group/media_formats/main/app.c Mon Feb 17 08:16:47 2014
@@ -70,6 +70,7 @@
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/json.h"
+#include "asterisk/format_cache.h"
 
 #define MWI_TOPIC_BUCKETS 57
 
@@ -765,16 +766,18 @@
 	int fd;
 	int autoclose;
 	int allowoverride;
-	struct ast_format origwfmt;
+	struct ast_format *origwfmt;
 };
 
 static void linear_release(struct ast_channel *chan, void *params)
 {
 	struct linear_state *ls = params;
 
-	if (ls->origwfmt.id && ast_set_write_format(chan, &ls->origwfmt)) {
-		ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", ast_channel_name(chan), ls->origwfmt.id);
-	}
+	if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n", ast_channel_name(chan),
+			ls->origwfmt->codec->name);
+	}
+	ao2_cleanup(ls->origwfmt);
 
 	if (ls->autoclose) {
 		close(ls->fd);
@@ -789,12 +792,11 @@
 	struct linear_state *ls = data;
 	struct ast_frame f = {
 		.frametype = AST_FRAME_VOICE,
+		.subclass.format = ast_format_slin,
 		.data.ptr = buf + AST_FRIENDLY_OFFSET / 2,
 		.offset = AST_FRIENDLY_OFFSET,
 	};
 	int res;
-
-	ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR, 0);
 
 	len = samples * 2;
 	if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
@@ -828,10 +830,11 @@
 		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
 	}
 
-	ast_format_copy(&ls->origwfmt, ast_channel_writeformat(chan));
-
-	if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
+	ls->origwfmt = ast_format_copy(ast_channel_writeformat(chan));
+
+	if (ast_set_write_format(chan, ast_format_slin)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", ast_channel_name(chan));
+		ao2_cleanup(ls->origwfmt);
 		ast_free(ls);
 		ls = params = NULL;
 	}
@@ -1107,7 +1110,7 @@
 		return NULL;
 	}
 
-	if (orig->subclass.format.id != AST_FORMAT_SLINEAR) {
+	if (ast_format_cmp(orig->subclass.format, ast_format_slin) != AST_FORMAT_CMP_EQUAL) {
 		ast_log(LOG_WARNING, "Attempting to silence non-slin frame\n");
 		return NULL;
 	}
@@ -1129,12 +1132,11 @@
 	}
 
 	silence->mallocd = AST_MALLOCD_HDR;
+	silence->subclass.format = ast_format_copy(ast_format_slin);
 	silence->frametype = AST_FRAME_VOICE;
 	silence->data.ptr = (void *)(silence + 1);
 	silence->samples = samples;
 	silence->datalen = datalen;
-
-	ast_format_set(&silence->subclass.format, AST_FORMAT_SLINEAR, 0);
 
 	return silence;
 }
@@ -1149,13 +1151,13 @@
  * \return 0 on success.
  * \return -1 on error.
  */
-static int set_read_to_slin(struct ast_channel *chan, struct ast_format *orig_format)
-{
-	if (!chan || !orig_format) {
+static int set_read_to_slin(struct ast_channel *chan, struct ast_format **orig_format)
+{
+	if (!chan) {
 		return -1;
 	}
-	ast_format_copy(orig_format, ast_channel_readformat(chan));
-	return ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+	*orig_format = ast_format_copy(ast_channel_readformat(chan));
+	return ast_set_read_format(chan, ast_format_slin);
 }
 
 static int global_silence_threshold = 128;
@@ -1197,7 +1199,7 @@
 	int totalsilence = 0;
 	int dspsilence = 0;
 	int olddspsilence = 0;
-	struct ast_format rfmt;
+	struct ast_format *rfmt = NULL;
 	struct ast_silence_generator *silgen = NULL;
 	char prependfile[PATH_MAX];
 	int ioflags;	/* IO flags for writing output file */
@@ -1216,7 +1218,6 @@
 		break;
 	}
 
-	ast_format_clear(&rfmt);
 	if (silencethreshold < 0) {
 		silencethreshold = global_silence_threshold;
 	}
@@ -1441,7 +1442,7 @@
 					 * set the mode, if we haven't already
 					 * for sildet
 					 */
-					if (muted && !rfmt.id) {
+					if (muted && !rfmt) {
 						ast_verb(3, "Setting read format to linear mode\n");
 						res = set_read_to_slin(chan, &rfmt);
 						if (res < 0) {
@@ -1561,9 +1562,10 @@
 			ast_filedelete(prependfile, sfmt[x]);
 		}
 	}
-	if (rfmt.id && ast_set_read_format(chan, &rfmt)) {
-		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), ast_channel_name(chan));
-	}
+	if (rfmt && ast_set_read_format(chan, rfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", rfmt->codec->name, ast_channel_name(chan));
+	}
+	ao2_cleanup(rfmt);
 	if ((outmsg == 2) && (!skip_confirmation_sound)) {
 		ast_stream_and_wait(chan, "auth-thankyou", "");
 	}

Modified: team/group/media_formats/main/audiohook.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/audiohook.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/audiohook.c (original)
+++ team/group/media_formats/main/audiohook.c Mon Feb 17 08:16:47 2014
@@ -41,13 +41,14 @@
 #include "asterisk/slinfactory.h"
 #include "asterisk/frame.h"
 #include "asterisk/translate.h"
+#include "asterisk/format_cache.h"
 
 #define AST_AUDIOHOOK_SYNC_TOLERANCE 100 /*!< Tolerance in milliseconds for audiohooks synchronization */
 #define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE 100 /*!< When small queue is enabled, this is the maximum amount of audio that can remain queued at a time. */
 
 struct ast_audiohook_translate {
 	struct ast_trans_pvt *trans_pvt;
-	struct ast_format format;
+	struct ast_format *format;
 };
 
 struct ast_audiohook_list {
@@ -67,7 +68,7 @@
 
 static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
 {
-	struct ast_format slin;
+	struct ast_format *slin;
 
 	if (audiohook->hook_internal_samp_rate == rate) {
 		return 0;
@@ -75,7 +76,8 @@
 
 	audiohook->hook_internal_samp_rate = rate;
 
-	ast_format_set(&slin, ast_format_slin_by_rate(rate), 0);
+	slin = ast_format_cache_get_slin_by_rate(rate);
+
 	/* Setup the factories that are needed for this audiohook type */
 	switch (audiohook->type) {
 	case AST_AUDIOHOOK_TYPE_SPY:
@@ -84,12 +86,15 @@
 			ast_slinfactory_destroy(&audiohook->read_factory);
 			ast_slinfactory_destroy(&audiohook->write_factory);
 		}
-		ast_slinfactory_init_with_format(&audiohook->read_factory, &slin);
-		ast_slinfactory_init_with_format(&audiohook->write_factory, &slin);
+		ast_slinfactory_init_with_format(&audiohook->read_factory, slin);
+		ast_slinfactory_init_with_format(&audiohook->write_factory, slin);
 		break;
 	default:
 		break;
 	}
+
+	ao2_ref(slin, -1);
+
 	return 0;
 }
 
@@ -143,6 +148,8 @@
 	if (audiohook->trans_pvt)
 		ast_translator_free_path(audiohook->trans_pvt);
 
+	ao2_cleanup(audiohook->format);
+
 	/* Lock and trigger be gone! */
 	ast_cond_destroy(&audiohook->trigger);
 	ast_mutex_destroy(&audiohook->lock);
@@ -220,25 +227,33 @@
 	short buf[samples];
 	struct ast_frame frame = {
 		.frametype = AST_FRAME_VOICE,
+		.subclass.format = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate),
 		.data.ptr = buf,
 		.datalen = sizeof(buf),
 		.samples = samples,
 	};
-	ast_format_set(&frame.subclass.format, ast_format_slin_by_rate(audiohook->hook_internal_samp_rate), 0);
+	struct ast_frame *out;
 
 	/* Ensure the factory is able to give us the samples we want */
-	if (samples > ast_slinfactory_available(factory))
+	if (samples > ast_slinfactory_available(factory)) {
+		ao2_ref(frame.subclass.format, -1);
 		return NULL;
+	}
 
 	/* Read data in from factory */
-	if (!ast_slinfactory_read(factory, buf, samples))
+	if (!ast_slinfactory_read(factory, buf, samples)) {
+		ao2_ref(frame.subclass.format, -1);
 		return NULL;
+	}
 
 	/* If a volume adjustment needs to be applied apply it */
 	if (vol)
 		ast_frame_adjust_volume(&frame, vol);
 
-	return ast_frdup(&frame);
+	out = ast_frdup(&frame);
+	ao2_ref(frame.subclass.format, -1);
+
+	return out;
 }
 
 static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
@@ -251,7 +266,7 @@
 		.datalen = sizeof(buf1),
 		.samples = samples,
 	};
-	ast_format_set(&frame.subclass.format, ast_format_slin_by_rate(audiohook->hook_internal_samp_rate), 0);
+	struct ast_frame *out;
 
 	/* Make sure both factories have the required samples */
 	usable_read = (ast_slinfactory_available(&audiohook->read_factory) >= samples ? 1 : 0);
@@ -341,24 +356,29 @@
 	/* Make the final buffer part of the frame, so it gets duplicated fine */
 	frame.data.ptr = final_buf;
 
+	frame.subclass.format = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate);
+
 	/* Yahoo, a combined copy of the audio! */
-	return ast_frdup(&frame);
+	out = ast_frdup(&frame);
+	ao2_ref(frame.subclass.format, -1);
+
+	return out;
 }
 
 static struct ast_frame *audiohook_read_frame_helper(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format, struct ast_frame **read_reference, struct ast_frame **write_reference)
 {
 	struct ast_frame *read_frame = NULL, *final_frame = NULL;
-	struct ast_format tmp_fmt;
+	struct ast_format *slin;
 	int samples_converted;
 
 	/* the number of samples requested is based on the format they are requesting.  Inorder
 	 * to process this correctly samples must be converted to our internal sample rate */
-	if (audiohook->hook_internal_samp_rate == ast_format_rate(format)) {
+	if (audiohook->hook_internal_samp_rate == format->codec->sample_rate) {
 		samples_converted = samples;
-	} else if (audiohook->hook_internal_samp_rate > ast_format_rate(format)) {
-		samples_converted = samples * (audiohook->hook_internal_samp_rate / (float) ast_format_rate(format));
+	} else if (audiohook->hook_internal_samp_rate > format->codec->sample_rate) {
+		samples_converted = samples * (audiohook->hook_internal_samp_rate / (float) format->codec->sample_rate);
 	} else {
-		samples_converted = samples * (ast_format_rate(format) / (float) audiohook->hook_internal_samp_rate);
+		samples_converted = samples * (format->codec->sample_rate / (float) audiohook->hook_internal_samp_rate);
 	}
 
 	if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ?
@@ -367,27 +387,33 @@
 		return NULL;
 	}
 
+	slin = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate);
+
 	/* If they don't want signed linear back out, we'll have to send it through the translation path */
-	if (format->id != ast_format_slin_by_rate(audiohook->hook_internal_samp_rate)) {
+	if (ast_format_cmp(format, slin) != AST_FORMAT_CMP_EQUAL) {
 		/* Rebuild translation path if different format then previously */
-		if (ast_format_cmp(format, &audiohook->format) == AST_FORMAT_CMP_NOT_EQUAL) {
+		if (ast_format_cmp(format, audiohook->format) == AST_FORMAT_CMP_NOT_EQUAL) {
 			if (audiohook->trans_pvt) {
 				ast_translator_free_path(audiohook->trans_pvt);
 				audiohook->trans_pvt = NULL;
 			}
 
 			/* Setup new translation path for this format... if we fail we can't very well return signed linear so free the frame and return nothing */
-			if (!(audiohook->trans_pvt = ast_translator_build_path(format, ast_format_set(&tmp_fmt, ast_format_slin_by_rate(audiohook->hook_internal_samp_rate), 0)))) {
+			if (!(audiohook->trans_pvt = ast_translator_build_path(format, slin))) {
 				ast_frfree(read_frame);
+				ao2_ref(slin, -1);
 				return NULL;
 			}
-			ast_format_copy(&audiohook->format, format);
+			ao2_ref(audiohook->format, -1);
+			audiohook->format = ast_format_copy(format);
 		}
 		/* Convert to requested format, and allow the read in frame to be freed */
 		final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1);
 	} else {
 		final_frame = read_frame;
 	}
+
+	ao2_ref(slin, -1);
 
 	return final_frame;
 }
@@ -699,8 +725,7 @@
 	struct ast_audiohook_translate *in_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ?
 		&audiohook_list->in_translate[0] : &audiohook_list->in_translate[1]);
 	struct ast_frame *new_frame = frame;
-	struct ast_format tmp_fmt;
-	enum ast_format_id slin_id;
+	struct ast_format *slin;
 
 	/* If we are capable of maintaining doing samplerates other that 8khz, update
 	 * the internal audiohook_list's rate and higher samplerate audio arrives. By
@@ -708,24 +733,29 @@
 	 * as the are written and read from. */
 	if (audiohook_list->native_slin_compatible) {
 		audiohook_list->list_internal_samp_rate =
-			MAX(ast_format_rate(&frame->subclass.format), audiohook_list->list_internal_samp_rate);
-	}
-
-	slin_id = ast_format_slin_by_rate(audiohook_list->list_internal_samp_rate);
-
-	if (frame->subclass.format.id == slin_id) {
+			MAX(frame->subclass.format->codec->sample_rate, audiohook_list->list_internal_samp_rate);
+	}
+
+	slin = ast_format_cache_get_slin_by_rate(audiohook_list->list_internal_samp_rate);
+	if (ast_format_cmp(frame->subclass.format, slin) == AST_FORMAT_CMP_EQUAL) {
+		ao2_ref(slin, -1);
 		return new_frame;
 	}
 
-	if (ast_format_cmp(&frame->subclass.format, &in_translate->format) == AST_FORMAT_CMP_NOT_EQUAL) {
+	if (ast_format_cmp(frame->subclass.format, in_translate->format) == AST_FORMAT_CMP_NOT_EQUAL) {
 		if (in_translate->trans_pvt) {
 			ast_translator_free_path(in_translate->trans_pvt);
 		}
-		if (!(in_translate->trans_pvt = ast_translator_build_path(ast_format_set(&tmp_fmt, slin_id, 0), &frame->subclass.format))) {
+		if (!(in_translate->trans_pvt = ast_translator_build_path(slin, frame->subclass.format))) {
+			ao2_ref(slin, -1);
 			return NULL;
 		}
-		ast_format_copy(&in_translate->format, &frame->subclass.format);
-	}
+		ao2_ref(in_translate->format, -1);
+		in_translate->format = ast_format_copy(frame->subclass.format);
+	}
+
+	ao2_ref(slin, -1);
+
 	if (!(new_frame = ast_translate(in_translate->trans_pvt, frame, 0))) {
 		return NULL;
 	}
@@ -738,16 +768,17 @@
 {
 	struct ast_audiohook_translate *out_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->out_translate[0] : &audiohook_list->out_translate[1]);
 	struct ast_frame *outframe = NULL;
-	if (ast_format_cmp(&slin_frame->subclass.format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
+	if (ast_format_cmp(slin_frame->subclass.format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
 		/* rebuild translators if necessary */
-		if (ast_format_cmp(&out_translate->format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
+		if (ast_format_cmp(out_translate->format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
 			if (out_translate->trans_pvt) {
 				ast_translator_free_path(out_translate->trans_pvt);
 			}
-			if (!(out_translate->trans_pvt = ast_translator_build_path(outformat, &slin_frame->subclass.format))) {
+			if (!(out_translate->trans_pvt = ast_translator_build_path(outformat, slin_frame->subclass.format))) {
 				return NULL;
 			}
-			ast_format_copy(&out_translate->format, outformat);
+			ao2_ref(out_translate->format, -1);
+			out_translate->format = ast_format_copy(outformat);
 		}
 		/* translate back to the format the frame came in as. */
 		if (!(outframe = ast_translate(out_translate->trans_pvt, slin_frame, 0))) {
@@ -872,7 +903,7 @@
 
 	/* ---Part_3: Decide what to do with the end_frame (whether to transcode or not) */
 	if (middle_frame_manipulated) {
-		if (!(end_frame = audiohook_list_translate_to_native(audiohook_list, direction, middle_frame, &start_frame->subclass.format))) {
+		if (!(end_frame = audiohook_list_translate_to_native(audiohook_list, direction, middle_frame, start_frame->subclass.format))) {
 			/* translation failed, so just pass back the input frame */
 			end_frame = start_frame;
 		}

Modified: team/group/media_formats/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/bridge.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/bridge.c (original)
+++ team/group/media_formats/main/bridge.c Mon Feb 17 08:16:47 2014
@@ -925,61 +925,61 @@
 
 static int bridge_make_compatible(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 {
-	struct ast_format read_format;
-	struct ast_format write_format;
-	struct ast_format best_format;
+	struct ast_format *read_format;
+	struct ast_format *write_format;
+	struct ast_format *best_format;
 	char codec_buf[512];
 
-	ast_format_copy(&read_format, ast_channel_readformat(bridge_channel->chan));
-	ast_format_copy(&write_format, ast_channel_writeformat(bridge_channel->chan));
+	read_format = ast_channel_readformat(bridge_channel->chan);
+	write_format = ast_channel_writeformat(bridge_channel->chan);
 
 	/* Are the formats currently in use something this bridge can handle? */
-	if (!ast_format_cap_iscompatible(bridge->technology->format_capabilities, ast_channel_readformat(bridge_channel->chan))) {
-		ast_best_codec(bridge->technology->format_capabilities, &best_format);
+	if (!ast_format_cap_iscompatible_format(bridge->technology->format_capabilities, read_format)) {
+		best_format = ast_format_cap_get_format(bridge->technology->format_capabilities, 0);
 
 		/* Read format is a no go... */
 		ast_debug(1, "Bridge technology %s wants to read any of formats %s but channel has %s\n",
 			bridge->technology->name,
 			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
-			ast_getformatname(&read_format));
+			read_format->codec->name);
 
 		/* Switch read format to the best one chosen */
-		if (ast_set_read_format(bridge_channel->chan, &best_format)) {
+		if (ast_set_read_format(bridge_channel->chan, best_format)) {
 			ast_log(LOG_WARNING, "Failed to set channel %s to read format %s\n",
-				ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
+				ast_channel_name(bridge_channel->chan), best_format->codec->name);
 			return -1;
 		}
 		ast_debug(1, "Bridge %s put channel %s into read format %s\n",
 			bridge->uniqueid, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&best_format));
+			best_format->codec->name);
 	} else {
 		ast_debug(1, "Bridge %s is happy that channel %s already has read format %s\n",
 			bridge->uniqueid, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&read_format));
-	}
-
-	if (!ast_format_cap_iscompatible(bridge->technology->format_capabilities, &write_format)) {
-		ast_best_codec(bridge->technology->format_capabilities, &best_format);
+			read_format->codec->name);
+	}
+
+	if (!ast_format_cap_iscompatible_format(bridge->technology->format_capabilities, write_format)) {
+		best_format = ast_format_cap_get_format(bridge->technology->format_capabilities, 0);
 
 		/* Write format is a no go... */
 		ast_debug(1, "Bridge technology %s wants to write any of formats %s but channel has %s\n",
 			bridge->technology->name,
 			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
-			ast_getformatname(&write_format));
+			write_format->codec->name);
 
 		/* Switch write format to the best one chosen */
-		if (ast_set_write_format(bridge_channel->chan, &best_format)) {
+		if (ast_set_write_format(bridge_channel->chan, best_format)) {
 			ast_log(LOG_WARNING, "Failed to set channel %s to write format %s\n",
-				ast_channel_name(bridge_channel->chan), ast_getformatname(&best_format));
+				ast_channel_name(bridge_channel->chan), best_format->codec->name);
 			return -1;
 		}
 		ast_debug(1, "Bridge %s put channel %s into write format %s\n",
 			bridge->uniqueid, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&best_format));
+			best_format->codec->name);
 	} else {
 		ast_debug(1, "Bridge %s is happy that channel %s already has write format %s\n",
 			bridge->uniqueid, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&write_format));
+			write_format->codec->name);
 	}
 
 	return 0;
@@ -3458,7 +3458,7 @@
 	struct ast_bridge_video_talker_src_data *data;
 
 	/* If the channel doesn't support video, we don't care about it */
-	if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO)) {
+	if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_MEDIA_TYPE_VIDEO)) {
 		return;
 	}
 

Modified: team/group/media_formats/main/bridge_basic.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/bridge_basic.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/bridge_basic.c (original)
+++ team/group/media_formats/main/bridge_basic.c Mon Feb 17 08:16:47 2014
@@ -46,6 +46,7 @@
 #include "asterisk/dial.h"
 #include "asterisk/stasis_bridges.h"
 #include "asterisk/features.h"
+#include "asterisk/format_cache.h"
 
 #define NORMAL_FLAGS	(AST_BRIDGE_FLAG_DISSOLVE_HANGUP | AST_BRIDGE_FLAG_DISSOLVE_EMPTY \
 			| AST_BRIDGE_FLAG_SMART)
@@ -2218,14 +2219,13 @@
 
 static int recalling_enter(struct attended_transfer_properties *props)
 {
-	RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
-	struct ast_format fmt;
+	RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
 
 	if (!cap) {
 		return -1;
 	}
 
-	ast_format_cap_add(cap, ast_format_set(&fmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 
 	/* When we dial the transfer target, since we are communicating
 	 * with a local channel, we can place the local channel in a bridge
@@ -2346,8 +2346,7 @@
 
 static int retransfer_enter(struct attended_transfer_properties *props)
 {
-	RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK), ast_format_cap_destroy);
-	struct ast_format fmt;
+	RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
 	char destination[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
 	int cause;
 
@@ -2357,7 +2356,7 @@
 
 	snprintf(destination, sizeof(destination), "%s@%s", props->exten, props->context);
 
-	ast_format_cap_add(cap, ast_format_set(&fmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 
 	/* Get a channel that is the destination we wish to call */
 	props->recall_target = ast_request("Local", cap, NULL, destination, &cause);

Modified: team/group/media_formats/main/bridge_channel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/bridge_channel.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/bridge_channel.c (original)
+++ team/group/media_formats/main/bridge_channel.c Mon Feb 17 08:16:47 2014
@@ -184,24 +184,24 @@
 void ast_bridge_channel_restore_formats(struct ast_bridge_channel *bridge_channel)
 {
 	/* Restore original formats of the channel as they came in */
-	if (ast_format_cmp(ast_channel_readformat(bridge_channel->chan), &bridge_channel->read_format) == AST_FORMAT_CMP_NOT_EQUAL) {
+	if (ast_format_cmp(ast_channel_readformat(bridge_channel->chan), bridge_channel->read_format) == AST_FORMAT_CMP_NOT_EQUAL) {
 		ast_debug(1, "Bridge is returning %p(%s) to read format %s\n",
 			bridge_channel, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&bridge_channel->read_format));
-		if (ast_set_read_format(bridge_channel->chan, &bridge_channel->read_format)) {
+			bridge_channel->read_format->codec->name);
+		if (ast_set_read_format(bridge_channel->chan, bridge_channel->read_format)) {
 			ast_debug(1, "Bridge failed to return %p(%s) to read format %s\n",
 				bridge_channel, ast_channel_name(bridge_channel->chan),
-				ast_getformatname(&bridge_channel->read_format));
-		}
-	}
-	if (ast_format_cmp(ast_channel_writeformat(bridge_channel->chan), &bridge_channel->write_format) == AST_FORMAT_CMP_NOT_EQUAL) {
+				bridge_channel->read_format->codec->name);
+		}
+	}
+	if (ast_format_cmp(ast_channel_writeformat(bridge_channel->chan), bridge_channel->write_format) == AST_FORMAT_CMP_NOT_EQUAL) {
 		ast_debug(1, "Bridge is returning %p(%s) to write format %s\n",
 			bridge_channel, ast_channel_name(bridge_channel->chan),
-			ast_getformatname(&bridge_channel->write_format));
-		if (ast_set_write_format(bridge_channel->chan, &bridge_channel->write_format)) {
+			bridge_channel->write_format->codec->name);
+		if (ast_set_write_format(bridge_channel->chan, bridge_channel->write_format)) {
 			ast_debug(1, "Bridge failed to return %p(%s) to write format %s\n",
 				bridge_channel, ast_channel_name(bridge_channel->chan),
-				ast_getformatname(&bridge_channel->write_format));
+				bridge_channel->write_format->codec->name);
 		}
 	}
 }
@@ -1969,8 +1969,8 @@
 {
 	int res = 0;
 
-	ast_format_copy(&bridge_channel->read_format, ast_channel_readformat(bridge_channel->chan));
-	ast_format_copy(&bridge_channel->write_format, ast_channel_writeformat(bridge_channel->chan));
+	bridge_channel->read_format = ast_format_copy(ast_channel_readformat(bridge_channel->chan));
+	bridge_channel->write_format = ast_format_copy(ast_channel_writeformat(bridge_channel->chan));
 
 	ast_debug(1, "Bridge %s: %p(%s) is joining\n",
 		bridge_channel->bridge->uniqueid,
@@ -2211,6 +2211,9 @@
 	pipe_close(bridge_channel->alert_pipe);
 
 	ast_cond_destroy(&bridge_channel->cond);
+
+	ao2_cleanup(bridge_channel->write_format);
+	ao2_cleanup(bridge_channel->read_format);
 }
 
 struct ast_bridge_channel *bridge_channel_internal_alloc(struct ast_bridge *bridge)

Modified: team/group/media_formats/main/callerid.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/callerid.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/callerid.c (original)
+++ team/group/media_formats/main/callerid.c Mon Feb 17 08:16:47 2014
@@ -42,6 +42,7 @@
 #include "asterisk/callerid.h"
 #include "asterisk/fskmodem.h"
 #include "asterisk/utils.h"
+#include "asterisk/format_cache.h"
 
 struct callerid_state {
 	fsk_data fskd;

Modified: team/group/media_formats/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/ccss.c?view=diff&rev=408268&r1=408267&r2=408268
==============================================================================
--- team/group/media_formats/main/ccss.c (original)
+++ team/group/media_formats/main/ccss.c Mon Feb 17 08:16:47 2014
@@ -52,6 +52,7 @@
 #include "asterisk/manager.h"
 #include "asterisk/causes.h"
 #include "asterisk/stasis_system.h"
+#include "asterisk/format_cache.h"
 
 /*** DOCUMENTATION
 	<application name="CallCompletionRequest" language="en_US">
@@ -2814,8 +2815,7 @@
 	const char *callback_macro = ast_get_cc_callback_macro(agent->cc_params);
 	const char *callback_sub = ast_get_cc_callback_sub(agent->cc_params);
 	unsigned int recall_timer = ast_get_cc_recall_timer(agent->cc_params) * 1000;
-	struct ast_format tmp_fmt;
-	struct ast_format_cap *tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	struct ast_format_cap *tmp_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 
 	if (!tmp_cap) {
 		return NULL;
@@ -2826,17 +2826,17 @@
 		*target++ = '\0';
 	}
 
-	ast_format_cap_add(tmp_cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(tmp_cap, ast_format_slin, 0);
 	if (!(chan = ast_request_and_dial(tech, tmp_cap, NULL, target, recall_timer, &reason, generic_pvt->cid_num, generic_pvt->cid_name))) {
 		/* Hmm, no channel. Sucks for you, bud.
 		 */
 		ast_log_dynamic_level(cc_logger_level, "Core %d: Failed to call back %s for reason %d\n",
 				agent->core_id, agent->device_name, reason);
 		ast_cc_failed(agent->core_id, "Failed to call back device %s/%s", tech, target);
-		ast_format_cap_destroy(tmp_cap);
+		ao2_ref(tmp_cap, -1);
 		return NULL;
 	}
-	ast_format_cap_destroy(tmp_cap);
+	ao2_ref(tmp_cap, -1);
 	
 	/* We have a channel. It's time now to set up the datastore of recalled CC interfaces.
 	 * This will be a common task for all recall functions. If it were possible, I'd have




More information about the svn-commits mailing list