]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
formats: Restore previous fread() behavior
authorSean Bright <sean.bright@gmail.com>
Tue, 5 Sep 2017 15:05:48 +0000 (11:05 -0400)
committerSean Bright <sean.bright@gmail.com>
Tue, 5 Sep 2017 15:05:48 +0000 (11:05 -0400)
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

15 files changed:
formats/format_g719.c
formats/format_g723.c
formats/format_g726.c
formats/format_g729.c
formats/format_gsm.c
formats/format_h263.c
formats/format_h264.c
formats/format_ilbc.c
formats/format_pcm.c
formats/format_siren14.c
formats/format_siren7.c
formats/format_sln.c
formats/format_vox.c
formats/format_wav.c
formats/format_wav_gsm.c

index 667858587fc8827d0953ea4156f97af6e399d703..e27822df7d2e5d8f67a1e79c4bc9bfdc2ba24b4a 100644 (file)
@@ -42,20 +42,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *g719read(struct ast_filestream *s, int *whennext)
 {
-       int res;
-       /* Send a frame from the file to the appropriate channel */
+       size_t res;
 
+       /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        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) {
+                       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;
        }
index 11821246cc967ab1ce8c248afbe4b5d4f86f2392..9b770336dcfd11e78d7c248ea2edd633d27dfef5 100644 (file)
@@ -42,7 +42,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
 {
        unsigned short size;
-       int res;
+       size_t res;
        int delay;
        /* Read the delay for the next packet, and schedule again if necessary */
        /* XXX is this ignored ? */
@@ -67,15 +67,10 @@ static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
        /* Read the data into the buffer */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, size);
        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) {
+                       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;
        }
index 94623f441e84e59b6c4b04d58bd5b7d6653f7112..50b558ec41c548b2a897371c130afc594b3d8397 100644 (file)
@@ -119,22 +119,17 @@ static int g726_16_rewrite(struct ast_filestream *s, const char *comment)
 
 static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
        struct g726_desc *fs = (struct g726_desc *)s->_private;
 
        /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
        s->fr.samples = 8 * FRAME_TIME;
        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) {
+                       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;
        }
index 8436446594d1396b4ffb5777674464d99997943f..35c68bd0c4c414818ea6cf087a7b0a1f922eff38 100644 (file)
@@ -48,20 +48,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
+
        /* Send a frame from the file to the appropriate channel */
        s->fr.samples = G729A_SAMPLES;
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        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 && res != 10) /* XXX what for ? */ {
+                       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;
        }
index cfc9452ef2c4ba9c7ed2700acd239f08d8aed07e..783d9553e6224c71447b20ec32f8f229ebee860e 100644 (file)
@@ -55,19 +55,14 @@ static const char gsm_silence[] = /* 33 */
 
 static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
 
        AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
        if ((res = fread(s->fr.data.ptr, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) {
-               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), GSM_FRAME_SIZE, 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) {
+                       ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
+                                       ast_format_get_name(s->fr.subclass.format), GSM_FRAME_SIZE, res,
+                                       strerror(errno));
                }
                return NULL;
        }
index 5d59972dee08e88d101ec6a7e13b8514451e807e..be8e1df7a0b6d88f2e76e41a7d88a1ce27918be2 100644 (file)
@@ -69,7 +69,7 @@ static int h263_open(struct ast_filestream *s)
 
 static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
        uint32_t mark;
        unsigned short len;
        unsigned int ts;
@@ -87,15 +87,10 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
        }
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
        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) {
+                       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;
        }
index f8906f423783a077552691dc3668326580b6b1a3..30604004e8413b47fb5b1a095987da85fa156cd2 100644 (file)
@@ -61,7 +61,7 @@ static int h264_open(struct ast_filestream *s)
 
 static struct ast_frame *h264_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
        int mark = 0;
        unsigned short len;
        unsigned int ts;
@@ -79,15 +79,10 @@ static struct ast_frame *h264_read(struct ast_filestream *s, int *whennext)
        }
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
        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) {
+                       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;
        }
index 6e06ef335e57dd52b34468212d194f71a924ce05..d4fbe96e7c694da6f5741beb13c27d00a514a326 100644 (file)
@@ -47,19 +47,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
+
        /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, ILBC_BUF_SIZE);
        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) {
+                       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;
        }
index bd7cf777647a87f36cf8786c15111cabb47b311b..7b0648234414e6295f00f3b0c845876d240cccad 100644 (file)
@@ -80,21 +80,15 @@ static int pcma_rewrite(struct ast_filestream *s, const char *comment)
 
 static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
-       
-       /* Send a frame from the file to the appropriate channel */
+       size_t res;
 
+       /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
-       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)) < 1) {
+               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;
        }
index 5aaa1f130098d838a3ec39ef9d68c3b0b55771b0..3e42bef9a794e1b918e76abd2cf12801a9323933 100644 (file)
@@ -42,20 +42,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *siren14read(struct ast_filestream *s, int *whennext)
 {
-       int res;
-       /* Send a frame from the file to the appropriate channel */
+       size_t res;
 
+       /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        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) {
+                       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;
        }
index 87e1372b3857cf735012d84b3c2f90e3bb900c4a..f1bde0012d34c7108c8c2770678ee0484d5be7ec 100644 (file)
@@ -42,20 +42,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *siren7read(struct ast_filestream *s, int *whennext)
 {
-       int res;
-       /* Send a frame from the file to the appropriate channel */
+       size_t res;
 
+       /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
        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) {
+                       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;
        }
index 2f4cc57ea6c3cc6bf80ca95451cdc09d85c89c66..48bad8ae71b6539ca1c87763ce336f2b8b2fd211 100644 (file)
@@ -36,20 +36,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *generic_read(struct ast_filestream *s, int *whennext, unsigned int buf_size)
 {
-       int res;
-       /* Send a frame from the file to the appropriate channel */
+       size_t res;
 
+       /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, buf_size);
-       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)) < 1) {
+               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;
        }
index 26d4169e1c9f3ce7480ec343c873c9752bd49061..813dabf21107113546e526bbeb5c6cc369f729ea 100644 (file)
@@ -42,20 +42,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
 {
-       int res;
+       size_t res;
 
        /* Send a frame from the file to the appropriate channel */
        AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
-       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)) < 1) {
+               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;
        }
index 2903992ab1d8d20678ef536192c7d3f267c382ae..cead61c5b71a7df8aa48a41986fbcce336f3a59d 100644 (file)
@@ -371,7 +371,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;
@@ -393,16 +393,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;
        }
index 2f80a9a46784219053e19fa45bfd8996ffff50d9..423dfe48ab0ec735ab592c299827b81bad283a3f 100644 (file)
@@ -421,18 +421,13 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
        } else {
                /* read and convert */
                unsigned char msdata[MSGSM_FRAME_SIZE];
-               int res;
-               
+               size_t res;
+
                if ((res = fread(msdata, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
-                       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), MSGSM_FRAME_SIZE, 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 && res != 1) {
+                               ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
+                                               ast_format_get_name(s->fr.subclass.format), MSGSM_FRAME_SIZE, res,
+                                               strerror(errno));
                        }
                        return NULL;
                }