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;
static char *monitor_synopsis = "Monitor a channel";
" 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"
;
/* 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;
}
/* 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 */
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;
*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,':');
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;
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;
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);