[asterisk-commits] file: branch group/media_formats-reviewed-trunk r418613 - in /team/group/medi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 14 17:32:16 CDT 2014


Author: file
Date: Mon Jul 14 17:32:12 2014
New Revision: 418613

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418613
Log:
codec_resample / translate: Allow translators to provide an explicit output format and fix double unref of format.

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

Modified:
    team/group/media_formats-reviewed-trunk/codecs/codec_resample.c
    team/group/media_formats-reviewed-trunk/main/translate.c

Modified: team/group/media_formats-reviewed-trunk/codecs/codec_resample.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/codecs/codec_resample.c?view=diff&rev=418613&r1=418612&r2=418613
==============================================================================
--- team/group/media_formats-reviewed-trunk/codecs/codec_resample.c (original)
+++ team/group/media_formats-reviewed-trunk/codecs/codec_resample.c Mon Jul 14 17:32:12 2014
@@ -107,7 +107,6 @@
 {
 	SpeexResamplerState *resamp_pvt = pvt->pvt;
 
-	ao2_cleanup(pvt->f.subclass.format);
 	speex_resampler_destroy(resamp_pvt);
 }
 

Modified: team/group/media_formats-reviewed-trunk/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/main/translate.c?view=diff&rev=418613&r1=418612&r2=418613
==============================================================================
--- team/group/media_formats-reviewed-trunk/main/translate.c (original)
+++ team/group/media_formats-reviewed-trunk/main/translate.c Mon Jul 14 17:32:12 2014
@@ -289,6 +289,18 @@
  * wrappers around the translator routines.
  */
 
+static void destroy(struct ast_trans_pvt *pvt)
+{
+	struct ast_translator *t = pvt->t;
+
+	if (t->destroy) {
+		t->destroy(pvt);
+	}
+	ao2_cleanup(pvt->f.subclass.format);
+	ast_free(pvt);
+	ast_module_unref(t->module);
+}
+
 /*!
  * \brief Allocate the descriptor, required outbuf space,
  * and possibly desc.
@@ -296,7 +308,6 @@
 static struct ast_trans_pvt *newpvt(struct ast_translator *t)
 {
 	struct ast_trans_pvt *pvt;
-	struct ast_format *dst_format = NULL;
 	int len;
 	char *ofs;
 
@@ -320,48 +331,49 @@
 	if (t->buf_size) {/* finally buffer and header */
 		pvt->outbuf.c = ofs + AST_FRIENDLY_OFFSET;
 	}
+
+	ast_module_ref(t->module);
+
 	/* call local init routine, if present */
 	if (t->newpvt && t->newpvt(pvt)) {
 		ast_free(pvt);
+		ast_module_unref(t->module);
 		return NULL;
 	}
 
-	if (!ast_strlen_zero(pvt->t->format)) {
-		dst_format = ast_format_cache_get(pvt->t->format);
-	}
-
-	if (!dst_format) {
-		struct ast_codec *codec = ast_codec_get(t->dst_codec.name,
-			t->dst_codec.type, t->dst_codec.sample_rate);
-		if (!codec) {
-			ast_log(LOG_ERROR, "Unable to get destination codec\n");
-			ast_free(pvt);
-			return NULL;
-		}
-		dst_format = ast_format_create(codec);
-		ao2_ref(codec, -1);
-	}
-
-	pvt->f.subclass.format = dst_format;
+	/* Setup normal static translation frame. */
 	pvt->f.frametype = AST_FRAME_VOICE;
 	pvt->f.mallocd = 0;
 	pvt->f.offset = AST_FRIENDLY_OFFSET;
 	pvt->f.src = pvt->t->name;
 	pvt->f.data.ptr = pvt->outbuf.c;
 
-	ast_module_ref(t->module);
+	/* if the translator has not provided a format find one in the cache or create one */
+	if (!pvt->f.subclass.format) {
+		if (!ast_strlen_zero(pvt->t->format)) {
+			pvt->f.subclass.format = ast_format_cache_get(pvt->t->format);
+		}
+
+		if (!pvt->f.subclass.format) {
+			struct ast_codec *codec = ast_codec_get(t->dst_codec.name,
+				t->dst_codec.type, t->dst_codec.sample_rate);
+			if (!codec) {
+				ast_log(LOG_ERROR, "Unable to get destination codec\n");
+				destroy(pvt);
+				return NULL;
+			}
+			pvt->f.subclass.format = ast_format_create(codec);
+			ao2_ref(codec, -1);
+		}
+
+		if (!pvt->f.subclass.format) {
+			ast_log(LOG_ERROR, "Unable to create format\n");
+			destroy(pvt);
+			return NULL;
+		}
+	}
+
 	return pvt;
-}
-
-static void destroy(struct ast_trans_pvt *pvt)
-{
-	struct ast_translator *t = pvt->t;
-
-	if (t->destroy)
-		t->destroy(pvt);
-	ao2_cleanup(pvt->f.subclass.format);
-	ast_free(pvt);
-	ast_module_unref(t->module);
 }
 
 /*! \brief framein wrapper, deals with bound checks.  */




More information about the asterisk-commits mailing list