|
|
@ -93,7 +93,7 @@ static const char *mixmonitor_spy_type = "MixMonitor";
|
|
|
|
|
|
|
|
|
|
|
|
struct mixmonitor {
|
|
|
|
struct mixmonitor {
|
|
|
|
struct ast_channel_spy spy;
|
|
|
|
struct ast_channel_spy spy;
|
|
|
|
struct ast_filestream *fs;
|
|
|
|
char *filename;
|
|
|
|
char *post_process;
|
|
|
|
char *post_process;
|
|
|
|
char *name;
|
|
|
|
char *name;
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int flags;
|
|
|
@ -146,7 +146,10 @@ static void *mixmonitor_thread(void *obj)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct mixmonitor *mixmonitor = obj;
|
|
|
|
struct mixmonitor *mixmonitor = obj;
|
|
|
|
struct ast_frame *f = NULL;
|
|
|
|
struct ast_frame *f = NULL;
|
|
|
|
|
|
|
|
struct ast_filestream *fs = NULL;
|
|
|
|
|
|
|
|
unsigned int oflags;
|
|
|
|
|
|
|
|
char *ext;
|
|
|
|
|
|
|
|
int errflag = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (option_verbose > 1)
|
|
|
|
if (option_verbose > 1)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_2 "Begin MixMonitor Recording %s\n", mixmonitor->name);
|
|
|
|
ast_verbose(VERBOSE_PREFIX_2 "Begin MixMonitor Recording %s\n", mixmonitor->name);
|
|
|
@ -174,8 +177,27 @@ static void *mixmonitor_thread(void *obj)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
for (; f; f = next) {
|
|
|
|
for (; f; f = next) {
|
|
|
|
next = AST_LIST_NEXT(f, frame_list);
|
|
|
|
next = AST_LIST_NEXT(f, frame_list);
|
|
|
|
if (write)
|
|
|
|
if (write && errflag == 0) {
|
|
|
|
ast_writestream(mixmonitor->fs, f);
|
|
|
|
if (!fs) {
|
|
|
|
|
|
|
|
/* Determine creation flags and filename plus extension for filestream */
|
|
|
|
|
|
|
|
oflags = O_CREAT | O_WRONLY;
|
|
|
|
|
|
|
|
oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ext = strrchr(mixmonitor->filename, '.')))
|
|
|
|
|
|
|
|
*(ext++) = '\0';
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
ext = "raw";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Move onto actually creating the filestream */
|
|
|
|
|
|
|
|
if (!(fs = ast_writefile(mixmonitor->filename, ext, NULL, oflags, 0, 0644))) {
|
|
|
|
|
|
|
|
ast_log(LOG_ERROR, "Cannot open %s.%s\n", mixmonitor->filename, ext);
|
|
|
|
|
|
|
|
errflag = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fs)
|
|
|
|
|
|
|
|
ast_writestream(fs, f);
|
|
|
|
|
|
|
|
}
|
|
|
|
ast_frame_free(f, 0);
|
|
|
|
ast_frame_free(f, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,7 +216,8 @@ static void *mixmonitor_thread(void *obj)
|
|
|
|
ast_safe_system(mixmonitor->post_process);
|
|
|
|
ast_safe_system(mixmonitor->post_process);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ast_closestream(mixmonitor->fs);
|
|
|
|
if (fs)
|
|
|
|
|
|
|
|
ast_closestream(fs);
|
|
|
|
|
|
|
|
|
|
|
|
free(mixmonitor);
|
|
|
|
free(mixmonitor);
|
|
|
|
|
|
|
|
|
|
|
@ -208,12 +231,10 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_t thread;
|
|
|
|
pthread_t thread;
|
|
|
|
struct mixmonitor *mixmonitor;
|
|
|
|
struct mixmonitor *mixmonitor;
|
|
|
|
char *file_name, *ext;
|
|
|
|
|
|
|
|
char postprocess2[1024] = "";
|
|
|
|
char postprocess2[1024] = "";
|
|
|
|
unsigned int oflags;
|
|
|
|
|
|
|
|
size_t len;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
|
|
|
|
len = sizeof(*mixmonitor) + strlen(chan->name) + 1;
|
|
|
|
len = sizeof(*mixmonitor) + strlen(chan->name) + strlen(filename) + 2;
|
|
|
|
|
|
|
|
|
|
|
|
/* If a post process system command is given attach it to the structure */
|
|
|
|
/* If a post process system command is given attach it to the structure */
|
|
|
|
if (!ast_strlen_zero(post_process)) {
|
|
|
|
if (!ast_strlen_zero(post_process)) {
|
|
|
@ -245,23 +266,8 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
|
|
|
|
strcpy(mixmonitor->post_process, postprocess2);
|
|
|
|
strcpy(mixmonitor->post_process, postprocess2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Determine creation flags and filename plus extension for filestream */
|
|
|
|
mixmonitor->filename = (char *) mixmonitor + sizeof(*mixmonitor) + strlen(chan->name) + 1;
|
|
|
|
oflags = O_CREAT | O_WRONLY;
|
|
|
|
strcpy(mixmonitor->filename, filename);
|
|
|
|
oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
|
|
|
|
|
|
|
|
file_name = ast_strdupa(filename);
|
|
|
|
|
|
|
|
if ((ext = strrchr(file_name, '.'))) {
|
|
|
|
|
|
|
|
*(ext++) = '\0';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ext = "raw";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Move onto actually creating the filestream */
|
|
|
|
|
|
|
|
mixmonitor->fs = ast_writefile(file_name, ext, NULL, oflags, 0, 0644);
|
|
|
|
|
|
|
|
if (!mixmonitor->fs) {
|
|
|
|
|
|
|
|
ast_log(LOG_ERROR, "Cannot open %s.%s\n", file_name, ext);
|
|
|
|
|
|
|
|
free(mixmonitor);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup the actual spy before creating our thread */
|
|
|
|
/* Setup the actual spy before creating our thread */
|
|
|
|
ast_set_flag(&mixmonitor->spy, CHANSPY_FORMAT_AUDIO);
|
|
|
|
ast_set_flag(&mixmonitor->spy, CHANSPY_FORMAT_AUDIO);
|
|
|
@ -285,7 +291,6 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
|
|
|
|
mixmonitor->spy.type, chan->name);
|
|
|
|
mixmonitor->spy.type, chan->name);
|
|
|
|
/* Since we couldn't add ourselves - bail out! */
|
|
|
|
/* Since we couldn't add ourselves - bail out! */
|
|
|
|
ast_mutex_destroy(&mixmonitor->spy.lock);
|
|
|
|
ast_mutex_destroy(&mixmonitor->spy.lock);
|
|
|
|
ast_closestream(mixmonitor->fs);
|
|
|
|
|
|
|
|
free(mixmonitor);
|
|
|
|
free(mixmonitor);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|