[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r301578 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 12 12:32:17 CST 2011


Author: dvossel
Date: Wed Jan 12 12:32:13 2011
New Revision: 301578

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=301578
Log:
updates chan_local for ast_format conversion 

Modified:
    team/dvossel/fixtheworld_phase1_step3/channels/chan_local.c
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c

Modified: team/dvossel/fixtheworld_phase1_step3/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/chan_local.c?view=diff&rev=301578&r1=301577&r2=301578
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/chan_local.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/chan_local.c Wed Jan 12 12:32:13 2011
@@ -88,7 +88,7 @@
 	.target_extra = -1,
 };
 
-static struct ast_channel *local_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
+static struct ast_channel *local_request(const char *type, struct ast_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
 static int local_digit_begin(struct ast_channel *ast, char digit);
 static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
 static int local_call(struct ast_channel *ast, char *dest, int timeout);
@@ -109,7 +109,6 @@
 static const struct ast_channel_tech local_tech = {
 	.type = "Local",
 	.description = tdesc,
-	.capabilities = -1,
 	.requester = local_request,
 	.send_digit_begin = local_digit_begin,
 	.send_digit_end = local_digit_end,
@@ -138,15 +137,15 @@
 
 */
 struct local_pvt {
-	unsigned int flags;                     /*!< Private flags */
-	char context[AST_MAX_CONTEXT];		/*!< Context to call */
-	char exten[AST_MAX_EXTENSION];		/*!< Extension to call */
-	int reqformat;				/*!< Requested format */
-	struct ast_jb_conf jb_conf;		/*!< jitterbuffer configuration for this local channel */
-	struct ast_channel *owner;		/*!< Master Channel - Bridging happens here */
-	struct ast_channel *chan;		/*!< Outbound channel - PBX is run here */
-	struct ast_module_user *u_owner;	/*!< reference to keep the module loaded while in use */
-	struct ast_module_user *u_chan;		/*!< reference to keep the module loaded while in use */
+	unsigned int flags;             /*!< Private flags */
+	char context[AST_MAX_CONTEXT];  /*!< Context to call */
+	char exten[AST_MAX_EXTENSION];  /*!< Extension to call */
+	struct ast_cap *reqcap;         /*!< Requested format capabilities */
+	struct ast_jb_conf jb_conf;     /*!< jitterbuffer configuration for this local channel */
+	struct ast_channel *owner;      /*!< Master Channel - Bridging happens here */
+	struct ast_channel *chan;       /*!< Outbound channel - PBX is run here */
+	struct ast_module_user *u_owner;/*!< reference to keep the module loaded while in use */
+	struct ast_module_user *u_chan; /*!< reference to keep the module loaded while in use */
 };
 
 #define LOCAL_ALREADY_MASQED  (1 << 0) /*!< Already masqueraded */
@@ -955,12 +954,16 @@
 }
 
 /*! \brief Create a call structure */
-static struct local_pvt *local_alloc(const char *data, int format)
+static struct local_pvt *local_alloc(const char *data, struct ast_cap *cap)
 {
 	struct local_pvt *tmp = NULL;
 	char *c = NULL, *opts = NULL;
 
 	if (!(tmp = ao2_alloc(sizeof(*tmp), NULL))) {
+		return NULL;
+	}
+	if (!(tmp->reqcap = ast_cap_copy(cap))) {
+		ao2_ref(tmp, -1);
 		return NULL;
 	}
 
@@ -995,9 +998,6 @@
 		*c++ = '\0';
 
 	ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
-
-	tmp->reqformat = format;
-
 #if 0
 	/* We can't do this check here, because we don't know the CallerID yet, and
 	 * the CallerID could potentially affect what step is actually taken (or
@@ -1019,7 +1019,8 @@
 static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid)
 {
 	struct ast_channel *tmp = NULL, *tmp2 = NULL;
-	int randnum = ast_random() & 0xffff, fmt = 0;
+	int randnum = ast_random() & 0xffff;
+	struct ast_format fmt;
 	const char *t;
 	int ama;
 
@@ -1045,19 +1046,19 @@
 
 	tmp2->tech = tmp->tech = &local_tech;
 
-	tmp->nativeformats = p->reqformat;
-	tmp2->nativeformats = p->reqformat;
+	ast_cap_append(p->reqcap, tmp->nativeformats);
+	ast_cap_append(p->reqcap, tmp2->nativeformats);
 
 	/* Determine our read/write format and set it on each channel */
-	fmt = ast_best_codec(p->reqformat);
-	tmp->writeformat = fmt;
-	tmp2->writeformat = fmt;
-	tmp->rawwriteformat = fmt;
-	tmp2->rawwriteformat = fmt;
-	tmp->readformat = fmt;
-	tmp2->readformat = fmt;
-	tmp->rawreadformat = fmt;
-	tmp2->rawreadformat = fmt;
+	ast_best_codec(p->reqcap, &fmt);
+	ast_format_copy(&fmt, &tmp->writeformat);
+	ast_format_copy(&fmt, &tmp2->writeformat);
+	ast_format_copy(&fmt, &tmp->rawwriteformat);
+	ast_format_copy(&fmt, &tmp2->rawwriteformat);
+	ast_format_copy(&fmt, &tmp->readformat);
+	ast_format_copy(&fmt, &tmp2->readformat);
+	ast_format_copy(&fmt, &tmp->rawreadformat);
+	ast_format_copy(&fmt, &tmp2->rawreadformat);
 
 	tmp->tech_pvt = p;
 	tmp2->tech_pvt = p;
@@ -1079,13 +1080,13 @@
 }
 
 /*! \brief Part of PBX interface */
-static struct ast_channel *local_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
+static struct ast_channel *local_request(const char *type, struct ast_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
 {
 	struct local_pvt *p = NULL;
 	struct ast_channel *chan = NULL;
 
 	/* Allocate a new private structure and then Asterisk channel */
-	if ((p = local_alloc(data, format))) {
+	if ((p = local_alloc(data, cap))) {
 		if (!(chan = local_new(p, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL))) {
 			ao2_unlink(locals, p);
 		}
@@ -1197,7 +1198,14 @@
 /*! \brief Load module into PBX, register channel */
 static int load_module(void)
 {
+	struct ast_channel_tech *tmp = (struct ast_channel_tech *) &local_tech;
+	if (!(tmp->capabilities = ast_cap_alloc())) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	ast_cap_add_all(tmp->capabilities);
+
 	if (!(locals = ao2_container_alloc(BUCKET_SIZE, NULL, locals_cmp_cb))) {
+		ast_cap_destroy(tmp->capabilities);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -1205,6 +1213,7 @@
 	if (ast_channel_register(&local_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
 		ao2_ref(locals, -1);
+		ast_cap_destroy(tmp->capabilities);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	ast_cli_register_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
@@ -1234,6 +1243,7 @@
 	ao2_iterator_destroy(&it);
 	ao2_ref(locals, -1);
 
+	ast_cap_destroy(local_tech.capabilities);
 	return 0;
 }
 

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h?view=diff&rev=301578&r1=301577&r2=301578
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Wed Jan 12 12:32:13 2011
@@ -67,6 +67,10 @@
 void ast_cap_add_all_by_type(struct ast_cap *cap, enum ast_format_type type);
 
 /*!
+ * \brief Add all known formats to the capabilities structure using default format attribute. */
+void ast_cap_add_all(struct ast_cap *cap);
+
+/*!
  * \brief Append the formats in src to dst
  */
 void ast_cap_append(struct ast_cap *src, struct ast_cap *dst);

Modified: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=diff&rev=301578&r1=301577&r2=301578
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Wed Jan 12 12:32:13 2011
@@ -117,6 +117,18 @@
 	}
 }
 
+void ast_cap_add_all(struct ast_cap *cap)
+{
+	int x;
+	size_t f_len = 0;
+	struct ast_format tmp_fmt;
+	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
+
+	for (x = 0; x < f_len; x++) {
+		ast_cap_add(cap, ast_format_set(&tmp_fmt, f_list[x].id, 0));
+	}
+}
+
 void ast_cap_append(struct ast_cap *src, struct ast_cap *dst)
 {
 	struct ast_format tmp_fmt;




More information about the asterisk-commits mailing list