[asterisk-commits] file: branch group/media_formats r408263 - /team/group/media_formats/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 17 06:15:42 CST 2014


Author: file
Date: Mon Feb 17 06:15:40 2014
New Revision: 408263

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

Modified:
    team/group/media_formats/res/res_stasis.c
    team/group/media_formats/res/res_stasis_snoop.c

Modified: team/group/media_formats/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_stasis.c?view=diff&rev=408263&r1=408262&r2=408263
==============================================================================
--- team/group/media_formats/res/res_stasis.c (original)
+++ team/group/media_formats/res/res_stasis.c Mon Feb 17 06:15:40 2014
@@ -70,6 +70,7 @@
 #include "asterisk/causes.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/bridge_after.h"
+#include "asterisk/format_cache.h"
 
 /*! Time to wait for a frame in the application */
 #define MAX_WAIT_MS 200
@@ -431,15 +432,14 @@
 /*! Request a bridge MOH channel */
 static struct ast_channel *prepare_bridge_moh_channel(void)
 {
-	RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
-	struct ast_format format;
-
-	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
+	RAII_VAR(struct ast_format_cap *, cap, NULL, ao2_cleanup);
+
+	cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	if (!cap) {
 		return NULL;
 	}
 
-	ast_format_cap_add(cap, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(cap, ast_format_slin, 0);
 
 	return ast_request("Announcer", cap, NULL, "ARI_MOH", NULL);
 }

Modified: team/group/media_formats/res/res_stasis_snoop.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/res/res_stasis_snoop.c?view=diff&rev=408263&r1=408262&r2=408263
==============================================================================
--- team/group/media_formats/res/res_stasis_snoop.c (original)
+++ team/group/media_formats/res/res_stasis_snoop.c Mon Feb 17 06:15:40 2014
@@ -40,6 +40,7 @@
 #include "asterisk/timing.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/json.h"
+#include "asterisk/format_cache.h"
 
 /*! \brief The interval (in milliseconds) that the Snoop timer is triggered, also controls length of audio within frames */
 #define SNOOP_INTERVAL 20
@@ -58,7 +59,7 @@
 	/*! \brief Number of samples to be read in when spying */
 	unsigned int spy_samples;
 	/*! \brief Format in use by the spy audiohook */
-	struct ast_format spy_format;
+	struct ast_format *spy_format;
 	/*! \brief Audiohook used to whisper on the channel */
 	struct ast_audiohook whisper;
 	/*! \brief Direction for whispering */
@@ -94,6 +95,8 @@
 
 	ast_free(snoop->app);
 
+	ao2_cleanup(snoop->spy_format);
+
 	ast_channel_cleanup(snoop->chan);
 }
 
@@ -179,7 +182,7 @@
 	/* Only get audio from the spy audiohook if it is active */
 	if (snoop->spy_active) {
 		ast_audiohook_lock(&snoop->spy);
-		frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, &snoop->spy_format);
+		frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, snoop->spy_format);
 		ast_audiohook_unlock(&snoop->spy);
 	}
 
@@ -278,10 +281,10 @@
 static void snoop_determine_format(struct ast_channel *chan, struct stasis_app_snoop *snoop)
 {
 	SCOPED_CHANNELLOCK(lock, chan);
-	unsigned int rate = MAX(ast_format_rate(ast_channel_rawwriteformat(chan)),
-		ast_format_rate(ast_channel_rawreadformat(chan)));
-
-	ast_format_set(&snoop->spy_format, ast_format_slin_by_rate(rate), 0);
+	unsigned int rate = MAX(ast_channel_rawwriteformat(chan)->codec->sample_rate,
+		ast_channel_rawreadformat(chan)->codec->sample_rate);
+
+	snoop->spy_format = ast_format_cache_get_slin_by_rate(rate);
 }
 
 struct ast_channel *stasis_app_control_snoop(struct ast_channel *chan,
@@ -289,6 +292,7 @@
 	const char *app, const char *app_args)
 {
 	RAII_VAR(struct stasis_app_snoop *, snoop, NULL, ao2_cleanup);
+	struct ast_format_cap *caps;
 	pthread_t thread;
 
 	if (spy == STASIS_SNOOP_DIRECTION_NONE &&
@@ -340,11 +344,18 @@
 	ast_channel_set_fd(snoop->chan, 0, ast_timer_fd(snoop->timer));
 
 	/* The format on the Snoop channel will be this signed linear format, and it will never change */
-	ast_format_cap_set(ast_channel_nativeformats(snoop->chan), &snoop->spy_format);
-	ast_format_copy(ast_channel_writeformat(snoop->chan), &snoop->spy_format);
-	ast_format_copy(ast_channel_rawwriteformat(snoop->chan), &snoop->spy_format);
-	ast_format_copy(ast_channel_readformat(snoop->chan), &snoop->spy_format);
-	ast_format_copy(ast_channel_rawreadformat(snoop->chan), &snoop->spy_format);
+	caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		return NULL;
+	}
+	ast_format_cap_add(caps, snoop->spy_format, 0);
+	ast_channel_nativeformats_set(snoop->chan, caps);
+	ao2_ref(caps, -1);
+
+	ast_channel_set_writeformat(snoop->chan, snoop->spy_format);
+	ast_channel_set_rawwriteformat(snoop->chan, snoop->spy_format);
+	ast_channel_set_readformat(snoop->chan, snoop->spy_format);
+	ast_channel_set_rawreadformat(snoop->chan, snoop->spy_format);
 
 	ast_channel_unlock(snoop->chan);
 
@@ -354,7 +365,7 @@
 			return NULL;
 		}
 
-		snoop->spy_samples = ast_format_rate(&snoop->spy_format) / (1000 / SNOOP_INTERVAL);
+		snoop->spy_samples = snoop->spy_format->codec->sample_rate / (1000 / SNOOP_INTERVAL);
 		snoop->spy_active = 1;
 	}
 




More information about the asterisk-commits mailing list