diff options
author | Joshua Colp <jcolp@digium.com> | 2017-09-06 09:10:54 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-09-06 09:10:54 -0500 |
commit | c5bc2558d7c44b7da9b62705cbe028447cdd098b (patch) | |
tree | 0e12876f681383e78dcbbf98fe6f6ae289590676 | |
parent | dd201746fa525acc83d57b5ae7a928272fc35e5a (diff) | |
parent | c0cce277a36827f24e2464295176086888772025 (diff) |
Merge "formats: Restore previous fread() behavior" into 14
-rw-r--r-- | formats/format_g719.c | 17 | ||||
-rw-r--r-- | formats/format_g723.c | 15 | ||||
-rw-r--r-- | formats/format_g726.c | 15 | ||||
-rw-r--r-- | formats/format_g729.c | 16 | ||||
-rw-r--r-- | formats/format_gsm.c | 15 | ||||
-rw-r--r-- | formats/format_h263.c | 15 | ||||
-rw-r--r-- | formats/format_h264.c | 15 | ||||
-rw-r--r-- | formats/format_ilbc.c | 16 | ||||
-rw-r--r-- | formats/format_pcm.c | 20 | ||||
-rw-r--r-- | formats/format_siren14.c | 17 | ||||
-rw-r--r-- | formats/format_siren7.c | 17 | ||||
-rw-r--r-- | formats/format_sln.c | 19 | ||||
-rw-r--r-- | formats/format_vox.c | 17 | ||||
-rw-r--r-- | formats/format_wav.c | 17 | ||||
-rw-r--r-- | formats/format_wav_gsm.c | 17 |
15 files changed, 87 insertions, 161 deletions
diff --git a/formats/format_g719.c b/formats/format_g719.c index bc374ee45..a8e7b12d4 100644 --- a/formats/format_g719.c +++ b/formats/format_g719.c @@ -42,20 +42,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_g723.c b/formats/format_g723.c index 22e39927a..023e38bae 100644 --- a/formats/format_g723.c +++ b/formats/format_g723.c @@ -42,7 +42,7 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_g726.c b/formats/format_g726.c index 4d5a91a8f..45f0ad939 100644 --- a/formats/format_g726.c +++ b/formats/format_g726.c @@ -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; } diff --git a/formats/format_g729.c b/formats/format_g729.c index 48fee3a23..7d6d1cff0 100644 --- a/formats/format_g729.c +++ b/formats/format_g729.c @@ -48,20 +48,16 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 7e7c54da3..30b12f1a7 100644 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -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; } diff --git a/formats/format_h263.c b/formats/format_h263.c index a3ca93346..e56cbe99a 100644 --- a/formats/format_h263.c +++ b/formats/format_h263.c @@ -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; } diff --git a/formats/format_h264.c b/formats/format_h264.c index b89e8ec81..47477926d 100644 --- a/formats/format_h264.c +++ b/formats/format_h264.c @@ -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; } diff --git a/formats/format_ilbc.c b/formats/format_ilbc.c index 3103611c0..42a28d8d8 100644 --- a/formats/format_ilbc.c +++ b/formats/format_ilbc.c @@ -47,19 +47,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_pcm.c b/formats/format_pcm.c index 705a03530..c12ef6b1a 100644 --- a/formats/format_pcm.c +++ b/formats/format_pcm.c @@ -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; } diff --git a/formats/format_siren14.c b/formats/format_siren14.c index 15cbe4cfd..62c6cb2de 100644 --- a/formats/format_siren14.c +++ b/formats/format_siren14.c @@ -42,20 +42,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_siren7.c b/formats/format_siren7.c index ff0bca3b4..3dd4d5ea8 100644 --- a/formats/format_siren7.c +++ b/formats/format_siren7.c @@ -42,20 +42,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_sln.c b/formats/format_sln.c index f68becb0f..e73916e18 100644 --- a/formats/format_sln.c +++ b/formats/format_sln.c @@ -36,20 +36,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_vox.c b/formats/format_vox.c index fc840530f..0775f8556 100644 --- a/formats/format_vox.c +++ b/formats/format_vox.c @@ -42,20 +42,15 @@ ASTERISK_REGISTER_FILE() 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; } diff --git a/formats/format_wav.c b/formats/format_wav.c index 85a22ed8a..fcdaf39e3 100644 --- a/formats/format_wav.c +++ b/formats/format_wav.c @@ -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; } diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c index e480179dd..3bdeab9e1 100644 --- a/formats/format_wav_gsm.c +++ b/formats/format_wav_gsm.c @@ -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; } |