[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step2 r299311 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 20 23:35:09 UTC 2010


Author: dvossel
Date: Mon Dec 20 17:35:05 2010
New Revision: 299311

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299311
Log:
Definition of the translation cost table

Modified:
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c
    team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c
    team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h
    team/dvossel/fixtheworld_phase1_step2/main/translate.c

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c?view=diff&rev=299311&r1=299310&r2=299311
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_adpcm.c Mon Dec 20 17:35:05 2010
@@ -288,6 +288,7 @@
 	.name = "adpcmtolin",
 	.srcfmt = AST_FORMAT_ADPCM,
 	.dstfmt = AST_FORMAT_SLINEAR,
+	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.framein = adpcmtolin_framein,
 	.sample = adpcm_sample,
 	.desc_size = sizeof(struct adpcm_decoder_pvt),
@@ -299,6 +300,7 @@
 	.name = "lintoadpcm",
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_ADPCM,
+	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.framein = lintoadpcm_framein,
 	.frameout = lintoadpcm_frameout,
 	.sample = slin8_sample,

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c?view=diff&rev=299311&r1=299310&r2=299311
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_alaw.c Mon Dec 20 17:35:05 2010
@@ -75,6 +75,7 @@
 	.name = "alawtolin",
 	.srcfmt = AST_FORMAT_ALAW,
 	.dstfmt = AST_FORMAT_SLINEAR,
+	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.framein = alawtolin_framein,
 	.sample = alaw_sample,
 	.buffer_samples = BUFFER_SAMPLES,
@@ -85,6 +86,7 @@
 	"lintoalaw",
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_ALAW,
+	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.framein = lintoalaw_framein,
 	.sample = slin8_sample,
 	.buffer_samples = BUFFER_SAMPLES,

Modified: team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c?view=diff&rev=299311&r1=299310&r2=299311
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/codecs/codec_speex.c Mon Dec 20 17:35:05 2010
@@ -332,6 +332,7 @@
 	.name = "speextolin", 
 	.srcfmt = AST_FORMAT_SPEEX,
 	.dstfmt =  AST_FORMAT_SLINEAR,
+	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.newpvt = speextolin_new,
 	.framein = speextolin_framein,
 	.destroy = speextolin_destroy,
@@ -346,6 +347,7 @@
 	.name = "lintospeex", 
 	.srcfmt = AST_FORMAT_SLINEAR,
 	.dstfmt = AST_FORMAT_SPEEX,
+	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.newpvt = lintospeex_new,
 	.framein = lintospeex_framein,
 	.frameout = lintospeex_frameout,
@@ -360,6 +362,7 @@
 	.name = "speexwbtolin16", 
 	.srcfmt = AST_FORMAT_SPEEX16,
 	.dstfmt =  AST_FORMAT_SLINEAR16,
+	.cost = AST_TRANS_COST_LY_LL_ORIGSAMP,
 	.newpvt = speexwbtolin16_new,
 	.framein = speextolin_framein,
 	.destroy = speextolin_destroy,
@@ -374,6 +377,7 @@
 	.name = "lin16tospeexwb", 
 	.srcfmt = AST_FORMAT_SLINEAR16,
 	.dstfmt = AST_FORMAT_SPEEX16,
+	.cost = AST_TRANS_COST_LL_LY_ORIGSAMP,
 	.newpvt = lin16tospeexwb_new,
 	.framein = lintospeex_framein,
 	.frameout = lintospeex_frameout,

Modified: team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h?view=diff&rev=299311&r1=299310&r2=299311
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step2/include/asterisk/translate.h Mon Dec 20 17:35:05 2010
@@ -40,6 +40,46 @@
 
 struct ast_trans_pvt;	/* declared below */
 
+/*! Translator Cost Table
+ *  The defined values in this table must be used to
+ *  set the translator's cost value. */
+enum ast_trans_cost_table {
+
+	/* Lossless Source Translation Costs */
+
+	/*! [lossless -> lossless] original sampling */
+	AST_TRANS_COST_LL_LL_ORIGSAMP = 400000,
+	/*! [lossless -> lossy]    original sampling */
+	AST_TRANS_COST_LL_LY_ORIGSAMP = 600000,
+
+	/*! [lossless -> lossless] up sample */
+	AST_TRANS_COST_LL_LL_UPSAMP   = 800000,
+	/*! [lossless -> lossy]    up sample */
+	AST_TRANS_COST_LL_LY_UPSAMP   = 825000,
+
+	/*! [lossless -> lossless] down sample */
+	AST_TRANS_COST_LL_LL_DOWNSAMP = 850000,
+	/*! [lossless -> lossy]    down sample */
+	AST_TRANS_COST_LL_LY_DOWNSAMP = 875000,
+
+	/* Lossy Source Translation Costs */
+
+	/*! [lossy -> lossless]    original sampling */
+	AST_TRANS_COST_LY_LL_ORIGSAMP = 900000,
+	/*! [lossy -> lossy]       original sampling */
+	AST_TRANS_COST_LY_LY_ORIGSAMP = 915000,
+
+	/*! [lossy -> lossless]    up sample */
+	AST_TRANS_COST_LY_LL_UPSAMP   = 930000,
+	/*! [lossy -> lossy]       up sample */
+	AST_TRANS_COST_LY_LY_UPSAMP   = 945000,
+
+	/*! [lossy -> lossless]    down sample */
+	AST_TRANS_COST_LY_LL_DOWNSAMP = 960000,
+	/*! [lossy -> lossy]       down sample */
+	AST_TRANS_COST_LY_LY_DOWNSAMP = 975000,
+};
+
 /*! \brief
  * Descriptor of a translator. 
  *
@@ -74,6 +114,8 @@
 	                                        *   converted to index during registration) */
 	format_t dstfmt;                       /*!< Destination format (note: bit position,
 	                                        *   converted to index during registration) */
+	int cost;                               /*!< Cost value associated with this translator based
+	                                        *   on translation cost table*/
 
 	int (*newpvt)(struct ast_trans_pvt *); /*!< initialize private data 
                                             *   associated with the translator */
@@ -109,7 +151,6 @@
 
 	struct ast_module *module;             /*!< opaque reference to the parent module */
 
-	int cost;                              /*!< Cost in milliseconds for encoding/decoding 1 second of sound */
 	int active;                            /*!< Whether this translator should be used or not */
 	AST_LIST_ENTRY(ast_translator) list;   /*!< link field */
 };

Modified: team/dvossel/fixtheworld_phase1_step2/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/main/translate.c?view=diff&rev=299311&r1=299310&r2=299311
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Mon Dec 20 17:35:05 2010
@@ -75,6 +75,9 @@
  * this structure.
  */
 static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
+
+
+static int generate_cost_val(format_t src, format_t dst);
 
 /*! \todo
  * TODO: sample frames for each supported input format.
@@ -800,6 +803,9 @@
 
 	t->module = mod;
 
+	if (!t->cost) {
+		t->cost = generate_cost_val(t->srcfmt, t->dstfmt);
+	}
 	t->srcfmt = powerof(t->srcfmt);
 	t->dstfmt = powerof(t->dstfmt);
 	t->active = 1;
@@ -1096,3 +1102,61 @@
 
 	return res;
 }
+
+/*!
+ * \internal
+ *
+ * \brief If no cost value was pre set by the translator.  An attempt is made to
+ * automatically generate that cost value from the cost table based on our src and
+ * dst formats.
+ *
+ * \note This function allows older translators built before the translation cost
+ * changed away from computational time to continue to be registered correctly.
+ *
+ * \note This function is safe to use on any formats that used to be defined in the
+ * first 32 bits of the old bit field codec representation.
+ */
+static int generate_cost_val(format_t src, format_t dst)
+{
+	int src_rate = ast_format_rate(src);
+	int src_ll = 0;
+	int dst_rate = ast_format_rate(dst);
+	int dst_ll = 0;
+
+	if ((src == AST_FORMAT_SLINEAR) || (src == AST_FORMAT_SLINEAR16)) {
+		src_ll = 1;
+	}
+	if ((dst == AST_FORMAT_SLINEAR) || (dst == AST_FORMAT_SLINEAR16)) {
+		dst_ll = 1;
+	}
+
+	if (src_ll) {
+		if (dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LL_LL_ORIGSAMP;
+		} else if (!dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LL_LY_ORIGSAMP;
+		} else if (dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LL_LL_UPSAMP;
+		} else if (!dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LL_LY_UPSAMP;
+		} else if (dst_ll && (src_rate > dst_rate)) {
+			return AST_TRANS_COST_LL_LL_DOWNSAMP;
+		} else {
+			return AST_TRANS_COST_LL_LY_DOWNSAMP;
+		}
+	} else {
+		if (dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LY_LL_ORIGSAMP;
+		} else if (!dst_ll && (src_rate == dst_rate)) {
+			return AST_TRANS_COST_LY_LY_ORIGSAMP;
+		} else if (dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LY_LL_UPSAMP;
+		} else if (!dst_ll && (src_rate < dst_rate)) {
+			return AST_TRANS_COST_LY_LY_UPSAMP;
+		} else if (dst_ll && (src_rate > dst_rate)) {
+			return AST_TRANS_COST_LY_LL_DOWNSAMP;
+		} else {
+			return AST_TRANS_COST_LY_LY_DOWNSAMP;
+		}
+	}
+}




More information about the asterisk-commits mailing list