[svn-commits] file: branch group/media_formats r407401 - /team/group/media_formats/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 5 07:26:19 CST 2014


Author: file
Date: Wed Feb  5 07:26:17 2014
New Revision: 407401

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407401
Log:
Move chan_alsa over to the new format API.

This gives you a good idea of how much format stuff is being reused. The only thing
that is created here is a format capabilities structure which contains the cached
signed linear format.

Modified:
    team/group/media_formats/channels/chan_alsa.c

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=407401&r1=407400&r2=407401
==============================================================================
--- team/group/media_formats/channels/chan_alsa.c (original)
+++ team/group/media_formats/channels/chan_alsa.c Wed Feb  5 07:26:17 2014
@@ -63,6 +63,7 @@
 #include "asterisk/musiconhold.h"
 #include "asterisk/poll-compat.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/format_cache.h"
 
 /*! Global jitterbuffer configuration - by default, jb is disabled
  *  \note Values shown here match the defaults shown in alsa.conf.sample */
@@ -140,6 +141,9 @@
 static int autoanswer = 1;
 static int mute = 0;
 static int noaudiocapture = 0;
+
+/* Signed linear format that is used by all channels and frames */
+static struct ast_format *slin_format;
 
 static struct ast_channel *alsa_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause);
 static int alsa_digit(struct ast_channel *c, char digit, unsigned int duration);
@@ -511,7 +515,7 @@
 		}
 
 		f.frametype = AST_FRAME_VOICE;
-		ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR, 0);
+		f.subclass.format = ao2_bump(slin_format);
 		f.samples = FRAME_SIZE;
 		f.datalen = FRAME_SIZE * 2;
 		f.data.ptr = buf;
@@ -585,9 +589,9 @@
 
 	ast_channel_tech_set(tmp, &alsa_tech);
 	ast_channel_set_fd(tmp, 0, readdev);
-	ast_format_set(ast_channel_readformat(tmp), AST_FORMAT_SLINEAR, 0);
-	ast_format_set(ast_channel_writeformat(tmp), AST_FORMAT_SLINEAR, 0);
-	ast_format_cap_add(ast_channel_nativeformats(tmp), ast_channel_writeformat(tmp));
+	ast_channel_set_readformat(tmp, slin_format);
+	ast_channel_set_writeformat(tmp, slin_format);
+	ast_channel_nativeformats_set(tmp, alsa_tech.capabilities);
 
 	ast_channel_tech_pvt_set(tmp, p);
 	if (!ast_strlen_zero(p->context))
@@ -616,13 +620,10 @@
 
 static struct ast_channel *alsa_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause)
 {
-	struct ast_format tmpfmt;
 	char buf[256];
 	struct ast_channel *tmp = NULL;
 
-	ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0);
-
-	if (!(ast_format_cap_iscompatible(cap, &tmpfmt))) {
+	if (!ast_format_cap_iscompatible_format(cap, slin_format)) {
 		ast_log(LOG_NOTICE, "Asked to get a channel of format '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
 		return NULL;
 	}
@@ -959,12 +960,17 @@
 	struct ast_config *cfg;
 	struct ast_variable *v;
 	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;
+	}
 
 	if (!(alsa_tech.capabilities = ast_format_cap_alloc(0))) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	ast_format_cap_add(alsa_tech.capabilities, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0));
+	ast_format_cap_add(alsa_tech.capabilities, slin_format, 0);
 
 	/* Copy the default jb config over global_jbconf */
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
@@ -1042,7 +1048,12 @@
 	if (alsa.owner)
 		return -1;
 
-	alsa_tech.capabilities = ast_format_cap_destroy(alsa_tech.capabilities);
+	ao2_cleanup(alsa_tech.capabilities);
+	alsa_tech.capabilities = NULL;
+
+	ao2_cleanup(slin_format);
+	slin_format = NULL;
+
 	return 0;
 }
 




More information about the svn-commits mailing list