summaryrefslogtreecommitdiff
path: root/formats/format_wav.c
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-09-05 11:05:48 -0400
committerSean Bright <sean.bright@gmail.com>2017-09-05 10:10:36 -0500
commitc3a6c8fd2dc156d2d2636d23af3fdf07ed00c3bd (patch)
tree5c6694034368a561ae60247c518a41c8b60823cb /formats/format_wav.c
parentf556c31aea25e189b1f6dfae0a541e3575a8a9f5 (diff)
formats: Restore previous fread() behavior
Some formats are able to handle short reads while others are not, so restore the previous behavior for the format modules so that we don't have spurious errors when playing back files. ASTERISK-27232 #close Reported by: Jens T. Change-Id: Iab7f52b25a394f277566c8a2a4b15a692280a300
Diffstat (limited to 'formats/format_wav.c')
-rw-r--r--formats/format_wav.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/formats/format_wav.c b/formats/format_wav.c
index ce8a8bf0a..b4e1f34f2 100644
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -369,7 +369,7 @@ static void wav_close(struct ast_filestream *s)
static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
{
- int res;
+ size_t res;
int samples; /* actual samples read */
#if __BYTE_ORDER == __BIG_ENDIAN
int x;
@@ -391,16 +391,11 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
/* ast_debug(1, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, bytes);
- if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
- if (feof(s->f)) {
- if (res) {
- ast_debug(3, "Incomplete frame data at end of %s file "
- "(expected %d bytes, read %d)\n",
- ast_format_get_name(s->fr.subclass.format), s->fr.datalen, res);
- }
- } else {
- ast_log(LOG_ERROR, "Error while reading %s file: %s\n",
- ast_format_get_name(s->fr.subclass.format), strerror(errno));
+ if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) == 0) {
+ if (res) {
+ ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
+ ast_format_get_name(s->fr.subclass.format), s->fr.datalen, res,
+ strerror(errno));
}
return NULL;
}