[asterisk-commits] file: branch 1.2 r51406 -
/branches/1.2/apps/app_mixmonitor.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Jan 22 12:08:53 MST 2007
Author: file
Date: Mon Jan 22 13:08:52 2007
New Revision: 51406
URL: http://svn.digium.com/view/asterisk?view=rev&rev=51406
Log:
Move filestream creation to Mixmonitor loop. This will prevent a blank file from being created if no frames ever pass through to be recorded. (issue #7589 reported by steve_mcneil)
Modified:
branches/1.2/apps/app_mixmonitor.c
Modified: branches/1.2/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_mixmonitor.c?view=diff&rev=51406&r1=51405&r2=51406
==============================================================================
--- branches/1.2/apps/app_mixmonitor.c (original)
+++ branches/1.2/apps/app_mixmonitor.c Mon Jan 22 13:08:52 2007
@@ -80,7 +80,7 @@
struct mixmonitor {
struct ast_channel_spy spy;
- struct ast_filestream *fs;
+ char *filename;
char *post_process;
char *name;
unsigned int flags;
@@ -133,6 +133,11 @@
{
struct mixmonitor *mixmonitor = obj;
struct ast_frame *f = NULL;
+ struct ast_filestream *fs = NULL;
+ unsigned int oflags;
+ char *ext;
+ int errflag = 0;
+
STANDARD_INCREMENT_USECOUNT;
@@ -162,8 +167,27 @@
*/
for (; f; f = next) {
next = f->next;
- if (write)
- ast_writestream(mixmonitor->fs, f);
+ if (write && errflag == 0) {
+ 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_frfree(f);
}
}
@@ -182,7 +206,8 @@
ast_safe_system(mixmonitor->post_process);
}
- ast_closestream(mixmonitor->fs);
+ if (fs)
+ ast_closestream(fs);
free(mixmonitor);
@@ -197,12 +222,10 @@
pthread_attr_t attr;
pthread_t thread;
struct mixmonitor *mixmonitor;
- char *file_name, *ext;
char postprocess2[1024] = "";
- unsigned int oflags;
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 (!ast_strlen_zero(post_process)) {
@@ -235,23 +258,8 @@
strcpy(mixmonitor->post_process, postprocess2);
}
- /* 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;
- 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;
- }
+ mixmonitor->filename = (char *) mixmonitor + sizeof(*mixmonitor) + strlen(chan->name) + 1;
+ strcpy(mixmonitor->filename, filename);
/* Setup the actual spy before creating our thread */
ast_set_flag(&mixmonitor->spy, CHANSPY_FORMAT_AUDIO);
@@ -275,7 +283,6 @@
mixmonitor->spy.type, chan->name);
/* Since we couldn't add ourselves - bail out! */
ast_mutex_destroy(&mixmonitor->spy.lock);
- ast_closestream(mixmonitor->fs);
free(mixmonitor);
return;
}
More information about the asterisk-commits
mailing list