/*! * \brief Stop monitoring channel * \param chan * \param need_lock * Stop the recording, close any open streams, mix in/out channels if required * \return Always 0 */ int AST_OPTIONAL_API_NAME(ast_monitor_stop)(struct ast_channel *chan, int need_lock) { int delfiles = 0; LOCK_IF_NEEDED(chan, need_lock); if (ast_channel_monitor(chan)) { char filename[ FILENAME_MAX ]; if (ast_channel_monitor(chan)->read_stream) { ast_closestream(ast_channel_monitor(chan)->read_stream); } if (ast_channel_monitor(chan)->write_stream) { ast_closestream(ast_channel_monitor(chan)->write_stream); } if (ast_channel_monitor(chan)->filename_changed && !ast_strlen_zero(ast_channel_monitor(chan)->filename_base)) { if (ast_channel_monitor(chan)->read_stream) { if (ast_fileexists(ast_channel_monitor(chan)->read_filename,NULL,NULL) > 0) { snprintf(filename, FILENAME_MAX, "%s-in", ast_channel_monitor(chan)->filename_base); if (ast_fileexists(filename, NULL, NULL) > 0) { ast_filedelete(filename, NULL); } ast_filerename(ast_channel_monitor(chan)->read_filename, filename, ast_channel_monitor(chan)->format); } else { ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->read_filename); } } if (ast_channel_monitor(chan)->write_stream) { if (ast_fileexists(ast_channel_monitor(chan)->write_filename,NULL,NULL) > 0) { snprintf(filename, FILENAME_MAX, "%s-out", ast_channel_monitor(chan)->filename_base); if (ast_fileexists(filename, NULL, NULL) > 0) { ast_filedelete(filename, NULL); } ast_filerename(ast_channel_monitor(chan)->write_filename, filename, ast_channel_monitor(chan)->format); } else { ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->write_filename); } } } if (ast_channel_monitor(chan)->joinfiles && !ast_strlen_zero(ast_channel_monitor(chan)->filename_base)) { char tmp[1024]; char tmp2[1024]; const char *format = !strcasecmp(ast_channel_monitor(chan)->format,"wav49") ? "WAV" : ast_channel_monitor(chan)->format; char *fname_base = ast_channel_monitor(chan)->filename_base; const char *execute, *execute_args; /* at this point, fname_base really is the full path */ /* Set the execute application */ execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC"); if (ast_strlen_zero(execute)) { #ifdef HAVE_SOXMIX execute = "nice -n 19 soxmix"; #else execute = "nice -n 19 sox -m"; #endif format = get_soxmix_format(format); delfiles = 1; } execute_args = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC_ARGS"); if (ast_strlen_zero(execute_args)) { execute_args = ""; } snprintf(tmp, sizeof(tmp), "%s \"%s-in.%s\" \"%s-out.%s\" \"%s.%s\" %s &", execute, fname_base, format, fname_base, format, fname_base, format,execute_args); if (delfiles) { snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s-\"* ) &",tmp, fname_base); /* remove legs when done mixing */ ast_copy_string(tmp, tmp2, sizeof(tmp)); } ast_debug(1,"monitor executing %s\n",tmp); if (ast_safe_system(tmp) == -1) ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp); } ast_free(ast_channel_monitor(chan)->format); ast_free(ast_channel_monitor(chan)); ast_channel_monitor_set(chan, NULL); ast_manager_event(chan, EVENT_FLAG_CALL, "MonitorStop", "Channel: %s\r\n" "Uniqueid: %s\r\n", ast_channel_name(chan), ast_channel_uniqueid(chan) ); pbx_builtin_setvar_helper(chan, "MONITORED", NULL); } pbx_builtin_setvar_helper(chan, "AUTO_MONITOR", NULL); UNLOCK_IF_NEEDED(chan, need_lock); return 0; }
/*! * \brief Stop monitoring channel * \param chan * \param need_lock * Stop the recording, close any open streams, mix in/out channels if required * \return Always 0 */ int ast_monitor_stop(struct ast_channel *chan, int need_lock) { int delfiles = 0; LOCK_IF_NEEDED(chan, need_lock); if (chan->monitor) { char filename[ FILENAME_MAX ]; if (chan->monitor->read_stream) { ast_closestream(chan->monitor->read_stream); } if (chan->monitor->write_stream) { ast_closestream(chan->monitor->write_stream); } if (chan->monitor->filename_changed && !ast_strlen_zero(chan->monitor->filename_base)) { if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) { snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base); if (ast_fileexists(filename, NULL, NULL) > 0) { ast_filedelete(filename, NULL); } ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format); } else { ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename); } if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) { snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base); if (ast_fileexists(filename, NULL, NULL) > 0) { ast_filedelete(filename, NULL); } ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format); } else { ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename); } } if (chan->monitor->joinfiles && !ast_strlen_zero(chan->monitor->filename_base)) { char tmp[1024]; char tmp2[1024]; const char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format; char *name = chan->monitor->filename_base; int directory = strchr(name, '/') ? 1 : 0; const char *dir = directory ? "" : ast_config_AST_MONITOR_DIR; const char *execute, *execute_args; const char *absolute = *name == '/' ? "" : "/"; /* Set the execute application */ execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC"); if (ast_strlen_zero(execute)) { #ifdef HAVE_SOXMIX execute = "nice -n 19 soxmix"; #else execute = "nice -n 19 sox -m"; #endif format = get_soxmix_format(format); delfiles = 1; } execute_args = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC_ARGS"); if (ast_strlen_zero(execute_args)) { execute_args = ""; } snprintf(tmp, sizeof(tmp), "%s \"%s%s%s-in.%s\" \"%s%s%s-out.%s\" \"%s%s%s.%s\" %s &", execute, dir, absolute, name, format, dir, absolute, name, format, dir, absolute, name, format,execute_args); if (delfiles) { snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s%s%s-\"* ) &",tmp, dir, absolute, name); /* remove legs when done mixing */ ast_copy_string(tmp, tmp2, sizeof(tmp)); } ast_debug(1,"monitor executing %s\n",tmp); if (ast_safe_system(tmp) == -1) ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp); } ast_free(chan->monitor->format); ast_free(chan->monitor); chan->monitor = NULL; manager_event(EVENT_FLAG_CALL, "MonitorStop", "Channel: %s\r\n" "Uniqueid: %s\r\n", chan->name, chan->uniqueid ); } UNLOCK_IF_NEEDED(chan, need_lock); return 0; }