[FFmpeg-cvslog] avformat: Use ffio_read_size where appropriate
Andreas Rheinhardt
git at videolan.org
Sat Aug 7 00:02:07 EEST 2021
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Aug 6 22:47:22 2021 +0200| [d1ac6456369fecdc99044e69bb22130bbedc0558] | committer: Andreas Rheinhardt
avformat: Use ffio_read_size where appropriate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d1ac6456369fecdc99044e69bb22130bbedc0558
---
libavformat/aaxdec.c | 10 ++++------
libavformat/act.c | 9 +++------
libavformat/kvag.c | 5 ++---
libavformat/nuv.c | 7 ++++---
libavformat/pva.c | 7 ++++---
libavformat/riffdec.c | 6 +++---
libavformat/utils.c | 6 +++---
libavformat/wavdec.c | 8 ++++----
8 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index ea0f2af1c9..b08ee036ed 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -21,6 +21,7 @@
#include "libavutil/intreadwrite.h"
#include "avformat.h"
+#include "avio_internal.h"
#include "internal.h"
typedef struct AAXColumn {
@@ -215,12 +216,9 @@ static int aax_read_header(AVFormatContext *s)
if (ret64 < 0)
return ret;
- ret = avio_read(pb, a->string_table, a->strings_size);
- if (ret != a->strings_size) {
- if (ret < 0)
- return ret;
- return AVERROR(EIO);
- }
+ ret = ffio_read_size(pb, a->string_table, a->strings_size);
+ if (ret < 0)
+ return ret;
for (int c = 0; c < a->columns; c++) {
int64_t data_offset = 0;
diff --git a/libavformat/act.c b/libavformat/act.c
index 5688952a31..a369157647 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
+#include "avio_internal.h"
#include "riff.h"
#include "internal.h"
#include "libavcodec/get_bits.h"
@@ -126,12 +127,10 @@ static int read_packet(AVFormatContext *s,
if(s->streams[0]->codecpar->sample_rate==4400 && !ctx->second_packet)
{
- ret = avio_read(pb, ctx->audio_buffer, frame_size);
+ ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
if(ret<0)
return ret;
- if(ret!=frame_size)
- return AVERROR(EIO);
pkt->data[0]=ctx->audio_buffer[11];
pkt->data[1]=ctx->audio_buffer[0];
@@ -165,12 +164,10 @@ static int read_packet(AVFormatContext *s,
}
else // 8000 Hz
{
- ret = avio_read(pb, ctx->audio_buffer, frame_size);
+ ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
if(ret<0)
return ret;
- if(ret!=frame_size)
- return AVERROR(EIO);
pkt->data[0]=ctx->audio_buffer[5];
pkt->data[1]=ctx->audio_buffer[0];
diff --git a/libavformat/kvag.c b/libavformat/kvag.c
index 0be253fb3c..a277c28128 100644
--- a/libavformat/kvag.c
+++ b/libavformat/kvag.c
@@ -22,6 +22,7 @@
#include "libavutil/channel_layout.h"
#include "avformat.h"
+#include "avio_internal.h"
#include "internal.h"
#include "rawenc.h"
#include "libavutil/intreadwrite.h"
@@ -57,10 +58,8 @@ static int kvag_read_header(AVFormatContext *s)
if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
- if ((ret = avio_read(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
+ if ((ret = ffio_read_size(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
return ret;
- else if (ret != KVAG_HEADER_SIZE)
- return AVERROR(EIO);
hdr.magic = AV_RL32(buf + 0);
hdr.data_size = AV_RL32(buf + 4);
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index 1d25d3b125..73521ec8e4 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "avformat.h"
+#include "avio_internal.h"
#include "internal.h"
#include "riff.h"
@@ -258,9 +259,9 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt)
int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0;
uint64_t pos = avio_tell(pb);
- ret = avio_read(pb, hdr, HDRSIZE);
- if (ret < HDRSIZE)
- return ret < 0 ? ret : AVERROR(EIO);
+ ret = ffio_read_size(pb, hdr, HDRSIZE);
+ if (ret < 0)
+ return ret;
frametype = hdr[0];
size = PKTSIZE(AV_RL32(&hdr[8]));
diff --git a/libavformat/pva.c b/libavformat/pva.c
index ff30746bcb..aecd049c03 100644
--- a/libavformat/pva.c
+++ b/libavformat/pva.c
@@ -20,6 +20,7 @@
*/
#include "avformat.h"
+#include "avio_internal.h"
#include "internal.h"
#include "mpeg.h"
@@ -147,9 +148,9 @@ recover:
goto recover;
}
- ret = avio_read(pb, pes_header_data, pes_header_data_length);
- if (ret != pes_header_data_length)
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ ret = ffio_read_size(pb, pes_header_data, pes_header_data_length);
+ if (ret < 0)
+ return ret;
length -= 9 + pes_header_data_length;
pes_packet_length -= 3 + pes_header_data_length;
diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 444b9fc00d..bd32e59837 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -32,10 +32,10 @@ int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
{
int ret;
av_assert0(sizeof(*g) == 16); //compiler will optimize this out
- ret = avio_read(s, *g, sizeof(*g));
- if (ret < (int)sizeof(*g)) {
+ ret = ffio_read_size(s, *g, sizeof(*g));
+ if (ret < 0) {
memset(*g, 0, sizeof(*g));
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ return ret;
}
return 0;
}
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 60d7364018..5754fc1537 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3285,12 +3285,12 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb
int ret = ff_alloc_extradata(par, size);
if (ret < 0)
return ret;
- ret = avio_read(pb, par->extradata, size);
- if (ret != size) {
+ ret = ffio_read_size(pb, par->extradata, size);
+ if (ret < 0) {
av_freep(&par->extradata);
par->extradata_size = 0;
av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size);
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ return ret;
}
return ret;
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 5992ef4bcf..30c9ac37f8 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -241,8 +241,8 @@ static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
int ret;
av_assert0(length < sizeof(temp));
- if ((ret = avio_read(s->pb, temp, length)) != length)
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ if ((ret = ffio_read_size(s->pb, temp, length)) < 0)
+ return ret;
temp[length] = 0;
@@ -311,9 +311,9 @@ static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
if (!(coding_history = av_malloc(size + 1)))
return AVERROR(ENOMEM);
- if ((ret = avio_read(s->pb, coding_history, size)) != size) {
+ if ((ret = ffio_read_size(s->pb, coding_history, size)) < 0) {
av_free(coding_history);
- return ret < 0 ? ret : AVERROR_INVALIDDATA;
+ return ret;
}
coding_history[size] = 0;
More information about the ffmpeg-cvslog
mailing list