[svn-commits] file: branch group/media_formats-reviewed r413301 - in /team/group/media_form...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 5 06:16:09 CDT 2014


Author: file
Date: Mon May  5 06:15:49 2014
New Revision: 413301

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413301
Log:
Move parts of the core (smoother, abstract jitterbuffer, bridge, callerid) over.

Review: https://reviewboard.asterisk.org/r/3518/

Modified:
    team/group/media_formats-reviewed/include/asterisk/smoother.h
    team/group/media_formats-reviewed/main/abstract_jb.c
    team/group/media_formats-reviewed/main/audiohook.c
    team/group/media_formats-reviewed/main/bridge.c
    team/group/media_formats-reviewed/main/bridge_basic.c
    team/group/media_formats-reviewed/main/bridge_channel.c
    team/group/media_formats-reviewed/main/callerid.c
    team/group/media_formats-reviewed/main/ccss.c
    team/group/media_formats-reviewed/main/smoother.c

Modified: team/group/media_formats-reviewed/include/asterisk/smoother.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/include/asterisk/smoother.h?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/include/asterisk/smoother.h (original)
+++ team/group/media_formats-reviewed/include/asterisk/smoother.h Mon May  5 06:15:49 2014
@@ -29,12 +29,7 @@
 extern "C" {
 #endif
 
-#include <sys/time.h>
-
-#include "asterisk/format_pref.h"
-#include "asterisk/format.h"
 #include "asterisk/endian.h"
-#include "asterisk/linkedlists.h"
 
 #define AST_SMOOTHER_FLAG_G729		(1 << 0)
 #define AST_SMOOTHER_FLAG_BE		(1 << 1)
@@ -56,6 +51,8 @@
 - Also see ast_smoother_test_flag(), ast_smoother_set_flags(), ast_smoother_get_flags(), ast_smoother_reset()
 */
 struct ast_smoother;
+
+struct ast_frame;
 
 struct ast_smoother *ast_smoother_new(int bytes);
 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);

Modified: team/group/media_formats-reviewed/main/abstract_jb.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/abstract_jb.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/abstract_jb.c (original)
+++ team/group/media_formats-reviewed/main/abstract_jb.c Mon May  5 06:15:49 2014
@@ -360,7 +360,7 @@
 	}
 
 	while (now >= jb->next) {
-		interpolation_len = ast_codec_interp_len(&jb->last_format);
+		interpolation_len = ast_format_get_default_ms(jb->last_format);
 
 		res = jbimpl->get(jbobj, &f, now, interpolation_len);
 
@@ -371,13 +371,14 @@
 		case AST_JB_IMPL_DROP:
 			jb_framelog("\tJB_GET {now=%ld}: %s frame with ts=%ld and len=%ld\n",
 				now, jb_get_actions[res], f->ts, f->len);
-			ast_format_copy(&jb->last_format, &f->subclass.format);
+			ao2_ref(jb->last_format, -1);
+			jb->last_format = ast_format_copy(f->subclass.format);
 			ast_frfree(f);
 			break;
 		case AST_JB_IMPL_INTERP:
 			/* interpolate a frame */
 			f = &finterp;
-			ast_format_copy(&f->subclass.format, &jb->last_format);
+			f->subclass.format = jb->last_format;
 			f->samples  = interpolation_len * 8;
 			f->src  = "JB interpolation";
 			f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000));
@@ -437,7 +438,7 @@
 	jb->next = jbimpl->next(jbobj);
 
 	/* Init last format for a first time. */
-	ast_format_copy(&jb->last_format, &frr->subclass.format);
+	jb->last_format = ast_format_copy(frr->subclass.format);
 
 	/* Create a frame log file */
 	if (ast_test_flag(jbconf, AST_JB_LOG)) {
@@ -501,6 +502,8 @@
 		fclose(jb->logfile);
 		jb->logfile = NULL;
 	}
+
+	ao2_cleanup(jb->last_format);
 
 	if (ast_test_flag(jb, JB_CREATED)) {
 		/* Remove and free all frames still queued in jb */
@@ -820,7 +823,7 @@
 	const struct ast_jb_impl *jb_impl;
 	struct ast_jb_conf jb_conf;
 	struct timeval start_tv;
-	struct ast_format last_format;
+	struct ast_format *last_format;
 	struct ast_timer *timer;
 	int timer_interval; /* ms between deliveries */
 	int timer_fd;
@@ -842,6 +845,7 @@
 		framedata->jb_impl->destroy(framedata->jb_obj);
 		framedata->jb_obj = NULL;
 	}
+	ao2_cleanup(framedata->last_format);
 	ast_free(framedata);
 }
 
@@ -909,7 +913,7 @@
 		}
 
 		jbframe = ast_frisolate(frame);
-		ast_format_copy(&framedata->last_format, &frame->subclass.format);
+		framedata->last_format = ast_format_copy(frame->subclass.format);
 
 		if (frame->len && (frame->len != framedata->timer_interval)) {
 			framedata->timer_interval = frame->len;
@@ -959,12 +963,12 @@
 			frame = &ast_null_frame;
 			break;
 		case AST_JB_IMPL_INTERP:
-			if (framedata->last_format.id) {
+			if (framedata->last_format) {
 				struct ast_frame tmp = { 0, };
 				tmp.frametype = AST_FRAME_VOICE;
-				ast_format_copy(&tmp.subclass.format, &framedata->last_format);
+				tmp.subclass.format = framedata->last_format;
 				/* example: 8000hz / (1000 / 20ms) = 160 samples */
-				tmp.samples = ast_format_rate(&framedata->last_format) / (1000 / framedata->timer_interval);
+				tmp.samples = ast_format_get_sample_rate(framedata->last_format) / (1000 / framedata->timer_interval);
 				tmp.delivery = ast_tvadd(framedata->start_tv, ast_samp2tv(next, 1000));
 				tmp.offset = AST_FRIENDLY_OFFSET;
 				tmp.src  = "func_jitterbuffer interpolation";

Modified: team/group/media_formats-reviewed/main/audiohook.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/audiohook.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/audiohook.c (original)
+++ team/group/media_formats-reviewed/main/audiohook.c Mon May  5 06:15:49 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 == ast_format_get_sample_rate(format)) {
 		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 > ast_format_get_sample_rate(format)) {
+		samples_converted = samples * (audiohook->hook_internal_samp_rate / (float) ast_format_get_sample_rate(format));
 	} else {
-		samples_converted = samples * (ast_format_rate(format) / (float) audiohook->hook_internal_samp_rate);
+		samples_converted = samples * (ast_format_get_sample_rate(format) / (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(ast_format_get_sample_rate(frame->subclass.format), 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-reviewed/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/bridge.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/bridge.c (original)
+++ team/group/media_formats-reviewed/main/bridge.c Mon May  5 06:15:49 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));
+			ast_format_get_name(read_format));
 
 		/* 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), ast_format_get_name(best_format));
 			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));
+			ast_format_get_name(best_format));
 	} 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);
+			ast_format_get_name(read_format));
+	}
+
+	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));
+			ast_format_get_name(write_format));
 
 		/* 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), ast_format_get_name(best_format));
 			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));
+			ast_format_get_name(best_format));
 	} 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));
+			ast_format_get_name(write_format));
 	}
 
 	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-reviewed/main/bridge_basic.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/bridge_basic.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/bridge_basic.c (original)
+++ team/group/media_formats-reviewed/main/bridge_basic.c Mon May  5 06:15:49 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-reviewed/main/bridge_channel.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/bridge_channel.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/bridge_channel.c (original)
+++ team/group/media_formats-reviewed/main/bridge_channel.c Mon May  5 06:15:49 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)) {
+			ast_format_get_name(bridge_channel->read_format));
+		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) {
+				ast_format_get_name(bridge_channel->read_format));
+		}
+	}
+	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)) {
+			ast_format_get_name(bridge_channel->write_format));
+		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));
+				ast_format_get_name(bridge_channel->write_format));
 		}
 	}
 }
@@ -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-reviewed/main/callerid.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/callerid.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/callerid.c (original)
+++ team/group/media_formats-reviewed/main/callerid.c Mon May  5 06:15:49 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-reviewed/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/ccss.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/ccss.c (original)
+++ team/group/media_formats-reviewed/main/ccss.c Mon May  5 06:15:49 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

Modified: team/group/media_formats-reviewed/main/smoother.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/smoother.c?view=diff&rev=413301&r1=413300&r2=413301
==============================================================================
--- team/group/media_formats-reviewed/main/smoother.c (original)
+++ team/group/media_formats-reviewed/main/smoother.c Mon May  5 06:15:49 2014
@@ -32,24 +32,19 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/_private.h"
-#include "asterisk/lock.h"
 #include "asterisk/frame.h"
-#include "asterisk/channel.h"
-#include "asterisk/cli.h"
-#include "asterisk/term.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/time.h"
 #include "asterisk/utils.h"
-#include "asterisk/threadstorage.h"
-#include "asterisk/linkedlists.h"
-#include "asterisk/translate.h"
-#include "asterisk/dsp.h"
-#include "asterisk/file.h"
+#include "asterisk/format.h"
+#include "asterisk/codec.h"
 #include "asterisk/smoother.h"
 
 #define SMOOTHER_SIZE 8000
 
 struct ast_smoother {
 	int size;
-	struct ast_format format;
+	struct ast_format *format;
 	int flags;
 	float samplesperbyte;
 	unsigned int opt_needs_swap:1;
@@ -85,6 +80,7 @@
 
 void ast_smoother_reset(struct ast_smoother *s, int bytes)
 {
+	ao2_cleanup(s->format);
 	memset(s, 0, sizeof(*s));
 	s->size = bytes;
 }
@@ -116,7 +112,7 @@
 	struct ast_smoother *s;
 	if (size < 1)
 		return NULL;
-	if ((s = ast_malloc(sizeof(*s))))
+	if ((s = ast_calloc(1, sizeof(*s))))
 		ast_smoother_reset(s, size);
 	return s;
 }
@@ -142,12 +138,12 @@
 		ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
 		return -1;
 	}
-	if (!s->format.id) {
-		ast_format_copy(&s->format, &f->subclass.format);
+	if (!s->format) {
+		s->format = ast_format_copy(f->subclass.format);
 		s->samplesperbyte = (float)f->samples / (float)f->datalen;
-	} else if (ast_format_cmp(&s->format, &f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
+	} else if (ast_format_cmp(s->format, f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
 		ast_log(LOG_WARNING, "Smoother was working on %s format frames, now trying to feed %s?\n",
-			ast_getformatname(&s->format), ast_getformatname(&f->subclass.format));
+			ast_format_get_name(s->format), ast_format_get_name(f->subclass.format));
 		return -1;
 	}
 	if (s->len + f->datalen > SMOOTHER_SIZE) {
@@ -198,7 +194,7 @@
 		len = s->len;
 	/* Make frame */
 	s->f.frametype = AST_FRAME_VOICE;
-	ast_format_copy(&s->f.subclass.format, &s->format);
+	s->f.subclass.format = s->format;
 	s->f.data.ptr = s->framedata + AST_FRIENDLY_OFFSET;
 	s->f.offset = AST_FRIENDLY_OFFSET;
 	s->f.datalen = len;
@@ -215,7 +211,8 @@
 		memmove(s->data, s->data + len, s->len);
 		if (!ast_tvzero(s->delivery)) {
 			/* If we have delivery time, increment it, otherwise, leave it at 0 */
-			s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_format_rate(&s->format)));
+			s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples,
+				ast_format_get_sample_rate(s->format)));
 		}
 	}
 	/* Return frame */
@@ -224,6 +221,7 @@
 
 void ast_smoother_free(struct ast_smoother *s)
 {
+	ao2_cleanup(s->format);
 	ast_free(s);
 }
 




More information about the svn-commits mailing list