mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
(closes issue #7596)
Reported by: julien23 Patches submitted by: julien23 Add the ability to disable recording the input or output streams in res_monitor. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@74164 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -46,7 +46,7 @@ struct ast_channel_monitor {
|
|||||||
|
|
||||||
/* Start monitoring a channel */
|
/* Start monitoring a channel */
|
||||||
int ast_monitor_start(struct ast_channel *chan, const char *format_spec,
|
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 */
|
/* Stop monitoring a channel */
|
||||||
int ast_monitor_stop(struct ast_channel *chan, int need_lock);
|
int ast_monitor_stop(struct ast_channel *chan, int need_lock);
|
||||||
|
@@ -61,6 +61,11 @@ AST_MUTEX_DEFINE_STATIC(monitorlock);
|
|||||||
ast_channel_unlock(lock); \
|
ast_channel_unlock(lock); \
|
||||||
} while (0)
|
} 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 unsigned long seq = 0;
|
||||||
|
|
||||||
static char *monitor_synopsis = "Monitor a channel";
|
static char *monitor_synopsis = "Monitor a channel";
|
||||||
@@ -85,6 +90,10 @@ static char *monitor_descrip = "Monitor([file_format[:urlbase]|[fname_base]|[opt
|
|||||||
" administrator interface\n"
|
" administrator interface\n"
|
||||||
"\n"
|
"\n"
|
||||||
" b - Don't begin recording unless a call is bridged to another channel\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"
|
"\nReturns -1 if monitor files can't be opened or if the channel is already\n"
|
||||||
"monitored, otherwise 0.\n"
|
"monitored, otherwise 0.\n"
|
||||||
;
|
;
|
||||||
@@ -125,7 +134,7 @@ static int ast_monitor_set_state(struct ast_channel *chan, int state)
|
|||||||
|
|
||||||
/* Start monitoring a channel */
|
/* Start monitoring a channel */
|
||||||
int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
|
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;
|
int res = 0;
|
||||||
|
|
||||||
@@ -184,31 +193,38 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* open files */
|
/* open files */
|
||||||
if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0) {
|
if (stream_action & X_REC_IN) {
|
||||||
ast_filedelete(monitor->read_filename, NULL);
|
if (ast_fileexists(monitor->read_filename, NULL, NULL) > 0)
|
||||||
}
|
ast_filedelete(monitor->read_filename, NULL);
|
||||||
if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
|
if (!(monitor->read_stream = ast_writefile(monitor->read_filename,
|
||||||
monitor->format, NULL,
|
monitor->format, NULL,
|
||||||
O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
|
O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
|
||||||
ast_log(LOG_WARNING, "Could not create file %s\n",
|
ast_log(LOG_WARNING, "Could not create file %s\n",
|
||||||
monitor->read_filename);
|
monitor->read_filename);
|
||||||
ast_free(monitor);
|
ast_free(monitor);
|
||||||
UNLOCK_IF_NEEDED(chan, need_lock);
|
UNLOCK_IF_NEEDED(chan, need_lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
|
} else
|
||||||
ast_filedelete(monitor->write_filename, NULL);
|
monitor->read_stream = NULL;
|
||||||
}
|
|
||||||
if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
|
if (stream_action & X_REC_OUT) {
|
||||||
monitor->format, NULL,
|
if (ast_fileexists(monitor->write_filename, NULL, NULL) > 0) {
|
||||||
O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
|
ast_filedelete(monitor->write_filename, NULL);
|
||||||
ast_log(LOG_WARNING, "Could not create file %s\n",
|
}
|
||||||
monitor->write_filename);
|
if (!(monitor->write_stream = ast_writefile(monitor->write_filename,
|
||||||
ast_closestream(monitor->read_stream);
|
monitor->format, NULL,
|
||||||
ast_free(monitor);
|
O_CREAT|O_TRUNC|O_WRONLY, 0, AST_FILE_MODE))) {
|
||||||
UNLOCK_IF_NEEDED(chan, need_lock);
|
ast_log(LOG_WARNING, "Could not create file %s\n",
|
||||||
return -1;
|
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;
|
chan->monitor = monitor;
|
||||||
ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
|
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 */
|
/* so we know this call has been monitored in case we need to bill for it or something */
|
||||||
@@ -381,6 +397,7 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
|
|||||||
char *delay = NULL;
|
char *delay = NULL;
|
||||||
char *urlprefix = NULL;
|
char *urlprefix = NULL;
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
|
int stream_action = X_REC_IN | X_REC_OUT;
|
||||||
int joinfiles = 0;
|
int joinfiles = 0;
|
||||||
int waitforbridge = 0;
|
int waitforbridge = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -397,9 +414,13 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
|
|||||||
*options = 0;
|
*options = 0;
|
||||||
options++;
|
options++;
|
||||||
if (strchr(options, 'm'))
|
if (strchr(options, 'm'))
|
||||||
joinfiles = 1;
|
stream_action |= X_JOIN;
|
||||||
if (strchr(options, 'b'))
|
if (strchr(options, 'b'))
|
||||||
waitforbridge = 1;
|
waitforbridge = 1;
|
||||||
|
if (strchr(options, 'i'))
|
||||||
|
stream_action &= ~X_REC_IN;
|
||||||
|
if (strchr(options, 'o'))
|
||||||
|
stream_action &= ~X_REC_OUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arg = strchr(format,':');
|
arg = strchr(format,':');
|
||||||
@@ -432,9 +453,16 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
|
|||||||
return 0;
|
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)
|
if (res < 0)
|
||||||
res = ast_monitor_change_fname(chan, fname_base, 1);
|
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);
|
ast_monitor_setjoinfiles(chan, joinfiles);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -472,7 +500,7 @@ static int start_monitor_action(struct mansession *s, const struct message *m)
|
|||||||
const char *format = astman_get_header(m, "Format");
|
const char *format = astman_get_header(m, "Format");
|
||||||
const char *mix = astman_get_header(m, "Mix");
|
const char *mix = astman_get_header(m, "Mix");
|
||||||
char *d;
|
char *d;
|
||||||
|
|
||||||
if (ast_strlen_zero(name)) {
|
if (ast_strlen_zero(name)) {
|
||||||
astman_send_error(s, m, "No channel specified");
|
astman_send_error(s, m, "No channel specified");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -494,8 +522,8 @@ static int start_monitor_action(struct mansession *s, const struct message *m)
|
|||||||
if ((d = strchr(fname, '/')))
|
if ((d = strchr(fname, '/')))
|
||||||
*d = '-';
|
*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)) {
|
if (ast_monitor_change_fname(c, fname, 1)) {
|
||||||
astman_send_error(s, m, "Could not start monitoring channel");
|
astman_send_error(s, m, "Could not start monitoring channel");
|
||||||
ast_channel_unlock(c);
|
ast_channel_unlock(c);
|
||||||
|
Reference in New Issue
Block a user