[asterisk-commits] file: branch group/media_formats r407984 - /team/group/media_formats/bridges/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 12 07:12:54 CST 2014


Author: file
Date: Wed Feb 12 07:12:46 2014
New Revision: 407984

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407984
Log:
Move bridge_softmix over.

Modified:
    team/group/media_formats/bridges/bridge_softmix.c

Modified: team/group/media_formats/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/bridges/bridge_softmix.c?view=diff&rev=407984&r1=407983&r2=407984
==============================================================================
--- team/group/media_formats/bridges/bridge_softmix.c (original)
+++ team/group/media_formats/bridges/bridge_softmix.c Wed Feb 12 07:12:46 2014
@@ -163,14 +163,14 @@
 struct softmix_translate_helper_entry {
 	int num_times_requested; /*!< Once this entry is no longer requested, free the trans_pvt
 	                              and re-init if it was usable. */
-	struct ast_format dst_format; /*!< The destination format for this helper */
+	struct ast_format *dst_format; /*!< The destination format for this helper */
 	struct ast_trans_pvt *trans_pvt; /*!< the translator for this slot. */
 	struct ast_frame *out_frame; /*!< The output frame from the last translation */
 	AST_LIST_ENTRY(softmix_translate_helper_entry) entry;
 };
 
 struct softmix_translate_helper {
-	struct ast_format slin_src; /*!< the source format expected for all the translators */
+	struct ast_format *slin_src; /*!< the source format expected for all the translators */
 	AST_LIST_HEAD_NOLOCK(, softmix_translate_helper_entry) entries;
 };
 
@@ -180,12 +180,14 @@
 	if (!(entry = ast_calloc(1, sizeof(*entry)))) {
 		return NULL;
 	}
-	ast_format_copy(&entry->dst_format, dst);
+	entry->dst_format = ast_format_copy(dst);
 	return entry;
 }
 
 static void *softmix_translate_helper_free_entry(struct softmix_translate_helper_entry *entry)
 {
+	ao2_cleanup(entry->dst_format);
+
 	if (entry->trans_pvt) {
 		ast_translator_free_path(entry->trans_pvt);
 	}
@@ -199,12 +201,14 @@
 static void softmix_translate_helper_init(struct softmix_translate_helper *trans_helper, unsigned int sample_rate)
 {
 	memset(trans_helper, 0, sizeof(*trans_helper));
-	ast_format_set(&trans_helper->slin_src, ast_format_slin_by_rate(sample_rate), 0);
+	trans_helper->slin_src = ast_format_cache_get_slin_by_rate(sample_rate);
 }
 
 static void softmix_translate_helper_destroy(struct softmix_translate_helper *trans_helper)
 {
 	struct softmix_translate_helper_entry *entry;
+
+	ao2_cleanup(trans_helper->slin_src);
 
 	while ((entry = AST_LIST_REMOVE_HEAD(&trans_helper->entries, entry))) {
 		softmix_translate_helper_free_entry(entry);
@@ -215,11 +219,12 @@
 {
 	struct softmix_translate_helper_entry *entry;
 
-	ast_format_set(&trans_helper->slin_src, ast_format_slin_by_rate(sample_rate), 0);
+	ao2_cleanup(trans_helper->slin_src);
+	trans_helper->slin_src = ast_format_cache_get_slin_by_rate(sample_rate);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&trans_helper->entries, entry, entry) {
 		if (entry->trans_pvt) {
 			ast_translator_free_path(entry->trans_pvt);
-			if (!(entry->trans_pvt = ast_translator_build_path(&entry->dst_format, &trans_helper->slin_src))) {
+			if (!(entry->trans_pvt = ast_translator_build_path(entry->dst_format, trans_helper->slin_src))) {
 				AST_LIST_REMOVE_CURRENT(entry);
 				entry = softmix_translate_helper_free_entry(entry);
 			}
@@ -274,19 +279,19 @@
 	}
 
 	AST_LIST_TRAVERSE(&trans_helper->entries, entry, entry) {
-		if (ast_format_cmp(&entry->dst_format, raw_write_fmt) == AST_FORMAT_CMP_EQUAL) {
+		if (ast_format_cmp(entry->dst_format, raw_write_fmt) == AST_FORMAT_CMP_EQUAL) {
 			entry->num_times_requested++;
 		} else {
 			continue;
 		}
 		if (!entry->trans_pvt && (entry->num_times_requested > 1)) {
-			entry->trans_pvt = ast_translator_build_path(&entry->dst_format, &trans_helper->slin_src);
+			entry->trans_pvt = ast_translator_build_path(entry->dst_format, trans_helper->slin_src);
 		}
 		if (entry->trans_pvt && !entry->out_frame) {
 			entry->out_frame = ast_translate(entry->trans_pvt, &sc->write_frame, 0);
 		}
 		if (entry->out_frame && (entry->out_frame->datalen < MAX_DATALEN)) {
-			ast_format_copy(&sc->write_frame.subclass.format, &entry->out_frame->subclass.format);
+			sc->write_frame.subclass.format = ast_format_copy(entry->out_frame->subclass.format);
 			memcpy(sc->final_buf, entry->out_frame->data.ptr, entry->out_frame->datalen);
 			sc->write_frame.datalen = entry->out_frame->datalen;
 			sc->write_frame.samples = entry->out_frame->samples;
@@ -316,7 +321,7 @@
 static void set_softmix_bridge_data(int rate, int interval, struct ast_bridge_channel *bridge_channel, int reset)
 {
 	struct softmix_channel *sc = bridge_channel->tech_pvt;
-	unsigned int channel_read_rate = ast_format_rate(ast_channel_rawreadformat(bridge_channel->chan));
+	unsigned int channel_read_rate = ast_channel_rawreadformat(bridge_channel->chan)->codec->sample_rate;
 
 	ast_mutex_lock(&sc->lock);
 	if (reset) {
@@ -325,23 +330,23 @@
 	}
 	/* Setup read/write frame parameters */
 	sc->write_frame.frametype = AST_FRAME_VOICE;
-	ast_format_set(&sc->write_frame.subclass.format, ast_format_slin_by_rate(rate), 0);
+	sc->write_frame.subclass.format = ast_format_cache_get_slin_by_rate(rate);
 	sc->write_frame.data.ptr = sc->final_buf;
 	sc->write_frame.datalen = SOFTMIX_DATALEN(rate, interval);
 	sc->write_frame.samples = SOFTMIX_SAMPLES(rate, interval);
 
 	sc->read_frame.frametype = AST_FRAME_VOICE;
-	ast_format_set(&sc->read_frame.subclass.format, ast_format_slin_by_rate(channel_read_rate), 0);
+	sc->read_frame.subclass.format = ast_format_cache_get_slin_by_rate(channel_read_rate);
 	sc->read_frame.data.ptr = sc->our_buf;
 	sc->read_frame.datalen = SOFTMIX_DATALEN(channel_read_rate, interval);
 	sc->read_frame.samples = SOFTMIX_SAMPLES(channel_read_rate, interval);
 
 	/* Setup smoother */
-	ast_slinfactory_init_with_format(&sc->factory, &sc->write_frame.subclass.format);
+	ast_slinfactory_init_with_format(&sc->factory, sc->write_frame.subclass.format);
 
 	/* set new read and write formats on channel. */
-	ast_set_read_format(bridge_channel->chan, &sc->read_frame.subclass.format);
-	ast_set_write_format(bridge_channel->chan, &sc->write_frame.subclass.format);
+	ast_set_read_format(bridge_channel->chan, sc->read_frame.subclass.format);
+	ast_set_write_format(bridge_channel->chan, sc->write_frame.subclass.format);
 
 	/* set up new DSP.  This is on the read side only right before the read frame enters the smoother.  */
 	sc->dsp = ast_dsp_new_with_rate(channel_read_rate);
@@ -500,7 +505,7 @@
 		ast_mutex_lock(&sc->lock);
 		ast_bridge_update_talker_src_video_mode(bridge, bridge_channel->chan,
 			sc->video_talker.energy_average,
-			ast_format_get_video_mark(&frame->subclass.format));
+			frame->subclass.video.rtp_marker_bit);
 		ast_mutex_unlock(&sc->lock);
 		video_src_priority = ast_bridge_is_video_src(bridge, bridge_channel->chan);
 		if (video_src_priority == 1) {
@@ -575,8 +580,7 @@
 
 	/* If a frame was provided add it to the smoother, unless drop silence is enabled and this frame
 	 * is not determined to be talking. */
-	if (!(bridge_channel->tech_args.drop_silence && !sc->talking) &&
-		(frame->frametype == AST_FRAME_VOICE && ast_format_is_slinear(&frame->subclass.format))) {
+	if (!(bridge_channel->tech_args.drop_silence && !sc->talking)) {
 		ast_slinfactory_feed(&sc->factory, frame);
 	}
 
@@ -677,8 +681,8 @@
 	int channel_native_rate;
 	int i;
 	/* Gather stats about channel sample rates. */
-	channel_native_rate = MAX(ast_format_rate(ast_channel_rawwriteformat(bridge_channel->chan)),
-		ast_format_rate(ast_channel_rawreadformat(bridge_channel->chan)));
+	channel_native_rate = MAX(ast_channel_rawwriteformat(bridge_channel->chan)->codec->sample_rate,
+		ast_channel_rawreadformat(bridge_channel->chan)->codec->sample_rate);
 
 	if (channel_native_rate > stats->highest_supported_rate) {
 		stats->highest_supported_rate = channel_native_rate;
@@ -842,7 +846,7 @@
 	while (!softmix_data->stop && bridge->num_active) {
 		struct ast_bridge_channel *bridge_channel;
 		int timeout = -1;
-		enum ast_format_id cur_slin_id = ast_format_slin_by_rate(softmix_data->internal_rate);
+		struct ast_format *cur_slin = ast_format_cache_get_slin_by_rate(softmix_data->internal_rate);
 		unsigned int softmix_samples = SOFTMIX_SAMPLES(softmix_data->internal_rate, softmix_data->internal_mixing_interval);
 		unsigned int softmix_datalen = SOFTMIX_DATALEN(softmix_data->internal_rate, softmix_data->internal_mixing_interval);
 
@@ -854,12 +858,14 @@
 			ast_log(LOG_WARNING,
 				"Bridge %s: Conference mixing error, requested mixing length greater than mixing buffer.\n",
 				bridge->uniqueid);
+			ao2_ref(cur_slin, -1);
 			goto softmix_cleanup;
 		}
 
 		/* Grow the mixing array buffer as participants are added. */
 		if (mixing_array.max_num_entries < bridge->num_channels
 			&& softmix_mixing_array_grow(&mixing_array, bridge->num_channels + 5)) {
+			ao2_ref(cur_slin, -1);
 			goto softmix_cleanup;
 		}
 
@@ -924,8 +930,8 @@
 			ast_mutex_lock(&sc->lock);
 
 			/* Make SLINEAR write frame from local buffer */
-			if (sc->write_frame.subclass.format.id != cur_slin_id) {
-				ast_format_set(&sc->write_frame.subclass.format, cur_slin_id, 0);
+			if (sc->write_frame.subclass.format != cur_slin) {
+				sc->write_frame.subclass.format = ast_format_copy(cur_slin);
 			}
 			sc->write_frame.datalen = softmix_datalen;
 			sc->write_frame.samples = softmix_samples;
@@ -939,6 +945,8 @@
 			/* A frame is now ready for the channel. */
 			ast_bridge_channel_queue_frame(bridge_channel, &sc->write_frame);
 		}
+
+		ao2_ref(cur_slin, -1);
 
 		update_all_rates = 0;
 		if (!stat_iteration_counter) {
@@ -1141,17 +1149,17 @@
 
 static int unload_module(void)
 {
-	ast_format_cap_destroy(softmix_bridge.format_capabilities);
+	ao2_cleanup(softmix_bridge.format_capabilities);
+	softmix_bridge.format_capabilities = NULL;
 	return ast_bridge_technology_unregister(&softmix_bridge);
 }
 
 static int load_module(void)
 {
-	struct ast_format tmp;
-	if (!(softmix_bridge.format_capabilities = ast_format_cap_alloc(0))) {
+	if (!(softmix_bridge.format_capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	ast_format_cap_add(softmix_bridge.format_capabilities, ast_format_set(&tmp, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(softmix_bridge.format_capabilities, ast_format_slin, 0);
 	return ast_bridge_technology_register(&softmix_bridge);
 }
 




More information about the asterisk-commits mailing list