[asterisk-commits] qwell: trunk r74164 - in /trunk: include/asterisk/monitor.h res/res_monitor.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 9 15:58:22 CDT 2007


Author: qwell
Date: Mon Jul  9 15:58:22 2007
New Revision: 74164

URL: http://svn.digium.com/view/asterisk?view=rev&rev=74164
Log:
(closes issue #7596)
Reported by: julien23
Patches submitted by: julien23

Add the ability to disable recording the input or output streams in res_monitor.

Modified:
    trunk/include/asterisk/monitor.h
    trunk/res/res_monitor.c

Modified: trunk/include/asterisk/monitor.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/monitor.h?view=diff&rev=74164&r1=74163&r2=74164
==============================================================================
--- trunk/include/asterisk/monitor.h (original)
+++ trunk/include/asterisk/monitor.h Mon Jul  9 15:58:22 2007
@@ -46,7 +46,7 @@
 
 /* Start monitoring a channel */
 int ast_monitor_start(struct ast_channel *chan, const char *format_spec,
-		      const char *fname_base, int need_lock );
+		      const char *fname_base, int need_lock, int stream_action);
 
 /* Stop monitoring a channel */
 int ast_monitor_stop(struct ast_channel *chan, int need_lock);

Modified: trunk/res/res_monitor.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_monitor.c?view=diff&rev=74164&r1=74163&r2=74164
==============================================================================
--- trunk/res/res_monitor.c (original)
+++ trunk/res/res_monitor.c Mon Jul  9 15:58:22 2007
@@ -60,6 +60,11 @@
 	if (needed) \
 		ast_channel_unlock(lock); \
 	} while (0)
+
+/* Streams recording control */
+#define X_REC_IN	1
+#define X_REC_OUT	2
+#define X_JOIN		4
 
 static unsigned long seq = 0;
 
@@ -85,6 +90,10 @@
 "          administrator interface\n"
 "\n"
 "    b   - Don't begin recording unless a call is bridged to another channel\n"
+"\n"
+"    i   - Skip recording of input stream (disables m option)\n"
+"\n"
+"    o   - Skip recording of output stream (disables m option)\n"
 "\nReturns -1 if monitor files can't be opened or if the channel is already\n"
 "monitored, otherwise 0.\n"
 ;
@@ -125,7 +134,7 @@
 
 /* Start monitoring a channel */
 int ast_monitor_start(	struct ast_channel *chan, const char *format_spec,
-		const char *fname_base, int need_lock)
+		const char *fname_base, int need_lock, int stream_action)
 {
 	int res = 0;
 
@@ -184,31 +193,38 @@
 		}
 		
 		/* open files */
-		if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0) {
-			ast_filedelete(monitor->read_filename, NULL);
-		}
-		if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
-						monitor->format, NULL,
-						O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
-			ast_log(LOG_WARNING, "Could not create file %s\n",
-						monitor->read_filename);
-			ast_free(monitor);
-			UNLOCK_IF_NEEDED(chan, need_lock);
-			return -1;
-		}
-		if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
-			ast_filedelete(monitor->write_filename, NULL);
-		}
-		if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
-						monitor->format, NULL,
-						O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
-			ast_log(LOG_WARNING, "Could not create file %s\n",
-						monitor->write_filename);
-			ast_closestream(monitor->read_stream);
-			ast_free(monitor);
-			UNLOCK_IF_NEEDED(chan, need_lock);
-			return -1;
-		}
+		if (stream_action & X_REC_IN) {
+			if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0)
+				ast_filedelete(monitor->read_filename, NULL);
+			if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
+							monitor->format, NULL,
+							O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
+				ast_log(LOG_WARNING, "Could not create file %s\n",
+							monitor->read_filename);
+				ast_free(monitor);
+				UNLOCK_IF_NEEDED(chan, need_lock);
+				return -1;
+			}
+		} else
+			monitor->read_stream = NULL;
+
+		if (stream_action & X_REC_OUT) {
+			if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
+				ast_filedelete(monitor->write_filename, NULL);
+			}
+			if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
+							monitor->format, NULL,
+							O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
+				ast_log(LOG_WARNING, "Could not create file %s\n",
+							monitor->write_filename);
+				ast_closestream(monitor->read_stream);
+				ast_free(monitor);
+				UNLOCK_IF_NEEDED(chan, need_lock);
+				return -1;
+			}
+		} else
+			monitor->write_stream = NULL;
+
 		chan->monitor = monitor;
 		ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
 		/* so we know this call has been monitored in case we need to bill for it or something */
@@ -381,6 +397,7 @@
 	char *delay = NULL;
 	char *urlprefix = NULL;
 	char tmp[256];
+	int stream_action = X_REC_IN | X_REC_OUT;
 	int joinfiles = 0;
 	int waitforbridge = 0;
 	int res = 0;
@@ -397,9 +414,13 @@
 				*options = 0;
 				options++;
 				if (strchr(options, 'm'))
-					joinfiles = 1;
+					stream_action |= X_JOIN;
 				if (strchr(options, 'b'))
 					waitforbridge = 1;
+				if (strchr(options, 'i'))
+					stream_action &= ~X_REC_IN;
+				if (strchr(options, 'o'))
+					stream_action &= ~X_REC_OUT;
 			}
 		}
 		arg = strchr(format,':');
@@ -432,9 +453,16 @@
 		return 0;
 	}
 
-	res = ast_monitor_start(chan, format, fname_base, 1);
+	res = ast_monitor_start(chan, format, fname_base, 1, stream_action);
 	if (res < 0)
 		res = ast_monitor_change_fname(chan, fname_base, 1);
+
+	if (stream_action & X_JOIN) {
+		if ((stream_action & X_REC_IN) && (stream_action & X_REC_OUT))
+			joinfiles = 1;
+		else
+			ast_log(LOG_WARNING, "Won't mix streams unless both input and output streams are recorded\n");
+	}
 	ast_monitor_setjoinfiles(chan, joinfiles);
 
 	return res;
@@ -472,7 +500,7 @@
 	const char *format = astman_get_header(m, "Format");
 	const char *mix = astman_get_header(m, "Mix");
 	char *d;
-	
+
 	if (ast_strlen_zero(name)) {
 		astman_send_error(s, m, "No channel specified");
 		return 0;
@@ -494,8 +522,8 @@
 		if ((d = strchr(fname, '/'))) 
 			*d = '-';
 	}
-	
-	if (ast_monitor_start(c, format, fname, 1)) {
+
+	if (ast_monitor_start(c, format, fname, 1, X_REC_IN | X_REC_OUT)) {
 		if (ast_monitor_change_fname(c, fname, 1)) {
 			astman_send_error(s, m, "Could not start monitoring channel");
 			ast_channel_unlock(c);




More information about the asterisk-commits mailing list