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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 4 21:17:12 UTC 2011


Author: dvossel
Date: Tue Jan  4 15:17:05 2011
New Revision: 300435

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300435
Log:
all the updates to app.c required to compile with ast_format conversion

Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
    team/dvossel/fixtheworld_phase1_step3/main/app.c
    team/dvossel/fixtheworld_phase1_step3/main/channel.c
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c

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=300435&r1=300434&r2=300435
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Tue Jan  4 15:17:05 2011
@@ -77,6 +77,11 @@
 int ast_cap_remove_byid(struct ast_cap *cap, enum ast_format_id id);
 
 /*!
+ * \brief Remove all format capabilities from capability structure
+ */
+int ast_cap_remove_all(struct ast_cap *cap);
+
+/*!
  * \brief Find if ast_format is within the capabilities of the ast_cap object.
  *
  * retval 1 format is compatible with formats held in ast_cap object.

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h?view=diff&rev=300435&r1=300434&r2=300435
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h Tue Jan  4 15:17:05 2011
@@ -138,10 +138,9 @@
  */
 struct ast_translator {
 	const char name[80];                   /*!< Name of translator */
-	format_t srcfmt;                       /*!< Source format (note: bit position,
-	                                        *   converted to index during registration) */
-	format_t dstfmt;                       /*!< Destination format (note: bit position,
-	                                        *   converted to index during registration) */
+	struct ast_format *src_fmt;            /*!< Source format */
+	struct ast_format *dst_fmt;            /*!< Destination format */
+
 	int table_cost;                        /*!< Cost value associated with this translator based
 	                                        *   on translation cost table. */
 	int comp_cost;                         /*!< Cost value associated with this translator based
@@ -271,11 +270,20 @@
  * \brief Chooses the best translation path
  *
  * Given a list of sources, and a designed destination format, which should
- * I choose? 
- * \return Returns 0 on success, -1 if no path could be found.  
- * \note Modifies dests and srcs in place 
- */
-format_t ast_translator_best_choice(format_t *dsts, format_t *srcs);
+ * I choose?
+ *
+ * \param destination capabilities
+ * \param source capabilities
+ * \param destination format chosen out of destination capabilities
+ * \param source format chosen out of source capabilities
+ * \return Returns 0 on success, -1 if no path could be found.
+ *
+ * \note dst_cap and src_cap are not mondified.
+ */
+int ast_translator_best_choice(struct ast_format *dst_cap,
+	struct ast_cap *src_cap,
+	struct ast_format *dst_fmt_out,
+	struct ast_format *src_fmt_out);
 
 /*! 
  * \brief Builds a translator path
@@ -284,7 +292,7 @@
  * \param source source format
  * \return ast_trans_pvt on success, NULL on failure
  * */
-struct ast_trans_pvt *ast_translator_build_path(format_t dest, format_t source);
+struct ast_trans_pvt *ast_translator_build_path(struct ast_format *dest, struct ast_format *source);
 
 /*!
  * \brief Frees a translator path
@@ -310,12 +318,13 @@
  * \param src source format
  * \return the number of translation steps required, or -1 if no path is available
  */
-unsigned int ast_translate_path_steps(format_t dest, format_t src);
+unsigned int ast_translate_path_steps(struct ast_format *dest, struct ast_format *src);
 
 /*!
  * \brief Mask off unavailable formats from a format bitmask
  * \param dest possible destination formats
  * \param src source formats
+ * \param result capabilities structure to store results in
  * \return the destination formats that are available in the source or translatable
  *
  * The result will include all formats from 'dest' that are either present
@@ -324,7 +333,7 @@
  * \note Only a single audio format and a single video format can be
  * present in 'src', or the function will produce unexpected results.
  */
-format_t ast_translate_available_formats(format_t dest, format_t src);
+void ast_translate_available_formats(struct ast_cap *dest, struct ast_cap *src, struct ast_cap *result);
 
 /*!
  * \brief Puts a string representation of the translation path into outbuf

Modified: team/dvossel/fixtheworld_phase1_step3/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/app.c?view=diff&rev=300435&r1=300434&r2=300435
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/app.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/app.c Tue Jan  4 15:17:05 2011
@@ -470,7 +470,7 @@
 
 	ast_format_copy(&chan->writeformat, &ls->origwfmt);
 
-	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
+	if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
 		ast_free(ls);
 		ls = params = NULL;
@@ -702,7 +702,7 @@
 	int totalsilence = 0;
 	int dspsilence = 0;
 	int olddspsilence = 0;
-	int rfmt = 0;
+	struct ast_format rfmt = { 0, };
 	struct ast_silence_generator *silgen = NULL;
 	char prependfile[80];
 
@@ -776,8 +776,8 @@
 			return -1;
 		}
 		ast_dsp_set_threshold(sildet, silencethreshold);
-		rfmt = chan->readformat;
-		res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
+		ast_format_copy(&chan->readformat, &rfmt);
+		res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
 			ast_dsp_free(sildet);
@@ -966,8 +966,8 @@
 			ast_filedelete(prependfile, sfmt[x]);
 		}
 	}
-	if (rfmt && ast_set_read_format(chan, rfmt)) {
-		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
+	if (rfmt.id && ast_set_read_format(chan, &rfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), chan->name);
 	}
 	if (outmsg == 2) {
 		ast_stream_and_wait(chan, "auth-thankyou", "");

Modified: team/dvossel/fixtheworld_phase1_step3/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/channel.c?view=diff&rev=300435&r1=300434&r2=300435
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/channel.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/channel.c Tue Jan  4 15:17:05 2011
@@ -4937,26 +4937,34 @@
 	return res;
 }
 
-static int set_format(struct ast_channel *chan, format_t fmt, format_t *rawformat, format_t *format,
-		      struct ast_trans_pvt **trans, const int direction)
-{
-	format_t native, native_fmt = ast_best_codec(fmt);
+static int set_format(struct ast_channel *chan,
+	struct ast_cap *cap_set,
+	struct ast_format *rawformat,
+	struct ast_format *format,
+	struct ast_trans_pvt **trans,
+	const int direction)
+{
+	struct ast_cap *cap_native = chan->nativeformats;
+	struct ast_format best_set_fmt;
+	struct ast_format best_native_fmt;
 	int res;
 	char from[200], to[200];
-	
-	/* Make sure we only consider audio */
-	fmt &= AST_FORMAT_AUDIO_MASK;
-	
-	native = chan->nativeformats;
-
-	if (!fmt || !native)	/* No audio requested */
-		return 0;	/* Let's try a call without any sounds (video, text) */
+
+	ast_best_codec(cap_set, &best_set_fmt);
 
 	/* See if the underlying channel driver is capable of performing transcoding for us */
-	if (!ast_channel_setoption(chan, direction ? AST_OPTION_FORMAT_WRITE : AST_OPTION_FORMAT_READ, &native_fmt, sizeof(int*), 0)) {
+	if (!ast_channel_setoption(chan, direction ? AST_OPTION_FORMAT_WRITE : AST_OPTION_FORMAT_READ, &best_set_fmt, sizeof(best_set_fmt), 0)) {
 		ast_debug(1, "Channel driver natively set channel %s to %s format %s\n", chan->name,
-			  direction ? "write" : "read", ast_getformatname(native_fmt));
-		chan->nativeformats = *rawformat = *format = native_fmt;
+			  direction ? "write" : "read", ast_getformatname(best_set_fmt));
+
+		ast_format_copy(&best_set_fmt, format);
+		ast_format_copy(&best_set_fmt, rawformat);
+
+		ast_channel_lock(chan);
+		ast_format_cap_remove_all(chan->nativeformats);
+		ast_format_cap_add(chan->nativeformats, best_set_fmt);
+		ast_channel_unlock(chan);
+
 		if (*trans) {
 			ast_translator_free_path(*trans);
 		}
@@ -4965,39 +4973,44 @@
 	}
 
 	/* Find a translation path from the native format to one of the desired formats */
-	if (!direction)
+	if (!direction) {
 		/* reading */
-		res = ast_translator_best_choice(&fmt, &native);
-	else
+		res = ast_translator_best_choice(&cap_set, &cap_native, &best_set_fmt, &best_native_fmt);
+	} else {
 		/* writing */
-		res = ast_translator_best_choice(&native, &fmt);
+		res = ast_translator_best_choice(&cap_native, &cap_set, &best_native_fmt, &best_set_fmt);
+	}
 
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n",
-			ast_getformatname_multiple(from, sizeof(from), native),
-			ast_getformatname_multiple(to, sizeof(to), fmt));
+			ast_getformatname_multiple(from, sizeof(from), cap_native),
+			ast_getformatname_multiple(to, sizeof(to), cap_set));
 		return -1;
 	}
-	
+
 	/* Now we have a good choice for both. */
 	ast_channel_lock(chan);
 
-	if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) {
+	if ((ast_format_cmp(rawformat, &best_native_fmt) != AST_FORMAT_CMP_NOT_EQUAL) &&
+		(ast_format_cmp(format, &best_set_fmt) != AST_FORMAT_CMP_NOT_EQUAL)
+		((ast_format_cmp(rawformat, format) != AST_FORMAT_CMP_NOT_EQUAL) || (*trans))) {
 		/* the channel is already in these formats, so nothing to do */
 		ast_channel_unlock(chan);
 		return 0;
 	}
 
-	*rawformat = native;
+	ast_format_copy(&best_native_fmt, rawformat);
 	/* User perspective is fmt */
-	*format = fmt;
+	ast_format_copy(&best_set_fmt, format);
+
 	/* Free any read translation we have right now */
 	if (*trans) {
 		ast_translator_free_path(*trans);
 		*trans = NULL;
 	}
+
 	/* Build a translation path from the raw format to the desired format */
-	if (*format == *rawformat) {
+	if (ast_format_cmp(format, rawformat) != AST_FORMAT_CMP_NOT_EQUAL) {
 		/*
 		 * If we were able to swap the native format to the format that
 		 * has been requested, then there is no need to try to build
@@ -5007,29 +5020,122 @@
 	} else {
 		if (!direction) {
 			/* reading */
-			*trans = ast_translator_build_path(*format, *rawformat);
+			*trans = ast_translator_build_path(format, rawformat);
 		} else {
 			/* writing */
-			*trans = ast_translator_build_path(*rawformat, *format);
+			*trans = ast_translator_build_path(rawformat, format);
 		}
 		res = *trans ? 0 : -1;
 	}
 	ast_channel_unlock(chan);
-	ast_debug(1, "Set channel %s to %s format %s\n", chan->name,
-		direction ? "write" : "read", ast_getformatname(fmt));
+
+	ast_debug(1, "Set channel %s to %s format %s\n",
+		chan->name,
+		direction ? "write" : "read",
+		ast_getformatname(&best_set_fmt));
 	return res;
 }
 
-int ast_set_read_format(struct ast_channel *chan, format_t fmt)
-{
-	return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat,
-			  &chan->readtrans, 0);
-}
-
-int ast_set_write_format(struct ast_channel *chan, format_t fmt)
-{
-	return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat,
-			  &chan->writetrans, 1);
+int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
+{
+	struct ast_cap *tmp_cap = ast_cap_alloc();
+	int res;
+	if (!cap) {
+		return -1;
+	}
+	ast_cap_add(cap, format);
+
+	res = set_format(chan,
+		tmp_cap,
+		&chan->rawreadformat,
+		&chan->readformat,
+		&chan->readtrans,
+		0);
+
+	ast_cap_destroy(tmp_cap);
+	return res;
+}
+
+int ast_set_read_format_by_id(struct ast_channel *chan, enum ast_format_id id)
+{
+	struct ast_cap *tmp_cap = ast_cap_alloc();
+	struct ast_format tmp_format;
+	int res;
+	if (!cap) {
+		return -1;
+	}
+	ast_cap_add(cap, ast_format_set(&tmp_format, id, 0));
+
+	res = set_format(chan,
+		tmp_cap,
+		&chan->rawreadformat,
+		&chan->readformat,
+		&chan->readtrans,
+		0);
+
+	ast_cap_destroy(tmp_cap);
+	return res;
+}
+
+int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_cap *formats)
+{
+	return set_format(chan,
+		formats,
+		&chan->rawreadformat,
+		&chan->readformat,
+		&chan->readtrans,
+		0);
+}
+
+int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
+{
+	struct ast_cap *tmp_cap = ast_cap_alloc();
+	int res;
+	if (!cap) {
+		return -1;
+	}
+	ast_cap_add(cap, format);
+
+	res = set_format(chan,
+		tmp_cap,
+		&chan->rawwriteformat,
+		&chan->writeformat,
+		&chan->writetrans,
+		1);
+
+	ast_cap_destroy(tmp_cap);
+	return res;
+}
+
+int ast_set_write_format_by_id(struct ast_channel *chan, enum ast_format_id id)
+{
+	struct ast_cap *tmp_cap = ast_cap_alloc();
+	struct ast_format tmp_format;
+	int res;
+	if (!cap) {
+		return -1;
+	}
+	ast_cap_add(cap, ast_format_set(&tmp_format, id, 0));
+
+	res = set_format(chan,
+		tmp_cap,
+		&chan->rawwriteformat,
+		&chan->writeformat,
+		&chan->writetrans,
+		1);
+
+	ast_cap_destroy(tmp_cap);
+	return res;
+}
+
+int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_cap *formats)
+{
+	return set_format(chan,
+		formats,
+		&chan->rawwriteformat,
+		&chan->writeformat,
+		&chan->writetrans,
+		1);
 }
 
 const char *ast_channel_reason2str(int reason)

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=300435&r1=300434&r2=300435
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Tue Jan  4 15:17:05 2011
@@ -163,6 +163,11 @@
 	}
 
 	return -1;
+}
+
+void ast_cap_remove_all(struct ast_cap *cap)
+{
+	ao2_callback(cap->formats, OBJ_NODATA | OBJ_UNLINK, NULL, NULL);
 }
 
 int ast_cap_iscompatible(struct ast_cap *cap, struct ast_format *format)




More information about the asterisk-commits mailing list