[svn-commits] dlee: branch dlee/record-controls r395285 - /team/dlee/record-controls/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 24 14:09:50 CDT 2013


Author: dlee
Date: Wed Jul 24 14:09:49 2013
New Revision: 395285

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395285
Log:
Mute slin frames.

Modified:
    team/dlee/record-controls/main/app.c

Modified: team/dlee/record-controls/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/main/app.c?view=diff&rev=395285&r1=395284&r2=395285
==============================================================================
--- team/dlee/record-controls/main/app.c (original)
+++ team/dlee/record-controls/main/app.c Wed Jul 24 14:09:49 2013
@@ -1149,12 +1149,28 @@
 	struct ast_frame *silence;
 	size_t size;
 	size_t datalen;
+	size_t samples = 0;
+	struct ast_frame *next;
 
 	if (!orig) {
 		return NULL;
 	}
 
-	datalen = sizeof(short) * orig->samples;
+	if (orig->subclass.format.id != AST_FORMAT_SLINEAR) {
+		ast_log(LOG_WARNING, "Attempting to silence non-slin frame\n");
+		return NULL;
+	}
+
+	for (next = AST_LIST_NEXT(orig, frame_list);
+		 orig;
+		 orig = next, next = orig ? AST_LIST_NEXT(orig, frame_list) : NULL) {
+		samples += orig->samples;
+	}
+
+	ast_verb(4, "Silencing %zd samples\n", samples);
+
+
+	datalen = sizeof(short) * samples;
 	size = sizeof(*silence) + datalen;
 	silence = ast_calloc(1, size);
 	if (!silence) {
@@ -1164,12 +1180,18 @@
 	silence->mallocd = AST_MALLOCD_HDR;
 	silence->frametype = AST_FRAME_VOICE;
 	silence->data.ptr = (void *)(silence + 1);
-	silence->samples = orig->samples;
+	silence->samples = samples;
 	silence->datalen = datalen;
 
 	ast_format_set(&silence->subclass.format, AST_FORMAT_SLINEAR, 0);
 
 	return silence;
+}
+
+static int set_read_to_slin(struct ast_channel *chan, struct ast_format *orig_format)
+{
+	ast_format_copy(orig_format, ast_channel_readformat(chan));
+	return ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
 }
 
 static int global_silence_threshold = 128;
@@ -1302,8 +1324,7 @@
 			return -1;
 		}
 		ast_dsp_set_threshold(sildet, silencethreshold);
-		ast_format_copy(&rfmt, ast_channel_readformat(chan));
-		res = ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR);
+		res = set_read_to_slin(chan, &rfmt);
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
 			ast_dsp_free(sildet);
@@ -1445,6 +1466,18 @@
 					muted = !muted;
 					ast_verb(3, "Message %smuted by control\n",
 						muted ? "" : "un");
+					/* We can only silence slin frames, so
+					 * set the mode, if we haven't already
+					 * for sildet
+					 */
+					if (muted && !rfmt.id) {
+						ast_verb(3, "Setting read format to linear mode\n");
+						res = set_read_to_slin(chan, &rfmt);
+						if (res < 0) {
+							ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
+							running = 0;
+						}
+					}
 					break;
 				}
 			}




More information about the svn-commits mailing list