From: Matthew Jordan Date: Fri, 11 Nov 2011 20:42:56 +0000 (+0000) Subject: Video format was treated as audio when removed from the file playback scheduler X-Git-Tag: 1.8.9.0-rc1~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3bf126033603ee88bbf3443142c69fa553e95c1;p=thirdparty%2Fasterisk.git Video format was treated as audio when removed from the file playback scheduler This patch fixes the format type check in ast_closestream and filestream_destructor. Previously a comparison operator was used, but since audio formats are no longer contiguous (and AST_FORMAT_AUDIO_MASK includes formats that have a value greater than the video formats), a bitwise AND operation is used instead. Duplicated code was also moved to filestream_close. (closes issue ASTERISK-18682) Reported by: Aldo Bedrij Tested by: Matt Jordan Review: https://reviewboard.asterisk.org/r/1580/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@344823 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/file.c b/main/file.c index b114f8b298..d432bdc755 100644 --- a/main/file.c +++ b/main/file.c @@ -289,23 +289,33 @@ static int exts_compare(const char *exts, const char *type) return 0; } -static void filestream_destructor(void *arg) +/*! \internal \brief Close the file stream by canceling any pending read / write callbacks */ +static void filestream_close(struct ast_filestream *f) { - struct ast_filestream *f = arg; - int status; - int pid = -1; - /* Stop a running stream if there is one */ if (f->owner) { - if (f->fmt->format < AST_FORMAT_AUDIO_MASK) { + if (f->fmt->format & AST_FORMAT_AUDIO_MASK) { f->owner->stream = NULL; AST_SCHED_DEL(f->owner->sched, f->owner->streamid); ast_settimeout(f->owner, 0, NULL, NULL); - } else { + } else if (f->fmt->format & AST_FORMAT_VIDEO_MASK) { f->owner->vstream = NULL; AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid); + } else { + ast_log(AST_LOG_WARNING, "Unable to schedule deletion of filestream with unsupported type %s\n", f->fmt->name); } } +} + +static void filestream_destructor(void *arg) +{ + struct ast_filestream *f = arg; + int status; + int pid = -1; + + /* Stop a running stream if there is one */ + filestream_close(f); + /* destroy the translator on exit */ if (f->trans) ast_translator_free_path(f->trans); @@ -893,22 +903,10 @@ int ast_stream_rewind(struct ast_filestream *fs, off_t ms) int ast_closestream(struct ast_filestream *f) { /* This used to destroy the filestream, but it now just decrements a refcount. - * We need to force the stream to quit queuing frames now, because we might + * We close the stream in order to quit queuing frames now, because we might * change the writeformat, which could result in a subsequent write error, if * the format is different. */ - - /* Stop a running stream if there is one */ - if (f->owner) { - if (f->fmt->format < AST_FORMAT_AUDIO_MASK) { - f->owner->stream = NULL; - AST_SCHED_DEL(f->owner->sched, f->owner->streamid); - ast_settimeout(f->owner, 0, NULL, NULL); - } else { - f->owner->vstream = NULL; - AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid); - } - } - + filestream_close(f); ao2_ref(f, -1); return 0; }