aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-02 15:41:20 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-07 00:41:45 +0200
commit7001ff74ba7fb5035f412a8be17d97b165f0ac5f (patch)
treead75b7f777ec672c834ce1860ec25afbe455e43b /libavformat
parent5869407da2657900ebf7419a4dff85b309e2363e (diff)
downloadffmpeg-7001ff74ba7fb5035f412a8be17d97b165f0ac5f.tar.gz
avformat/aviobuf: Add ffio_init_(read|write)_context()
Most users of ffio_init_context() simply want to wrap a buffer into an AVIOContext; they do not provide function pointers at all. Therefore this commit adds shortcuts for these two common operations. This also allows to accept const data when reading (i.e. the const is now cast away at a central place in ffio_init_read_context() instead of at several callers). This also allows to constify the data in ff_text_init_buf(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/aacdec.c2
-rw-r--r--libavformat/asfenc.c6
-rw-r--r--libavformat/av1.c2
-rw-r--r--libavformat/av1dec.c3
-rw-r--r--libavformat/avio_internal.h9
-rw-r--r--libavformat/aviobuf.c10
-rw-r--r--libavformat/hls.c2
-rw-r--r--libavformat/id3v2.c5
-rw-r--r--libavformat/matroskadec.c12
-rw-r--r--libavformat/mmst.c4
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/mpegts.c18
-rw-r--r--libavformat/mpjpegdec.c2
-rw-r--r--libavformat/oggenc.c2
-rw-r--r--libavformat/rdt.c5
-rw-r--r--libavformat/rtpdec_asf.c2
-rw-r--r--libavformat/rtpdec_qt.c2
-rw-r--r--libavformat/rtsp.c2
-rw-r--r--libavformat/sapdec.c3
-rw-r--r--libavformat/subtitles.c4
-rw-r--r--libavformat/subtitles.h2
-rw-r--r--libavformat/vividas.c10
22 files changed, 59 insertions, 50 deletions
diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c
index a476640904..41c9a36239 100644
--- a/libavformat/aacdec.c
+++ b/libavformat/aacdec.c
@@ -146,7 +146,7 @@ static int handle_id3(AVFormatContext *s, AVPacket *pkt)
return ret;
}
- ffio_init_context(&pb, pkt->data, pkt->size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, pkt->data, pkt->size);
ff_id3v2_read_dict(&pb.pub, &metadata, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
if ((ret = ff_id3v2_parse_priv_dict(&metadata, id3v2_extra_meta)) < 0)
goto error;
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 244c7e7a27..2f2d9b1bab 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -773,8 +773,7 @@ static int asf_write_header(AVFormatContext *s)
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
asf->packet_timestamp_end = -1;
- ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
- NULL, NULL, NULL, NULL);
+ ffio_init_write_context(&asf->pb, asf->packet_buf, s->packet_size);
if (s->avoid_negative_ts < 0)
s->avoid_negative_ts = 1;
@@ -866,8 +865,7 @@ static void flush_packet(AVFormatContext *s)
asf->packet_nb_payloads = 0;
asf->packet_timestamp_start = -1;
asf->packet_timestamp_end = -1;
- ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
- NULL, NULL, NULL, NULL);
+ ffio_init_write_context(&asf->pb, asf->packet_buf, s->packet_size);
}
static void put_payload_header(AVFormatContext *s, ASFStream *stream,
diff --git a/libavformat/av1.c b/libavformat/av1.c
index 4455ec0504..cb86e66d09 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -107,7 +107,7 @@ int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out,
if (!buf)
return AVERROR(ENOMEM);
- ffio_init_context(&pb, buf, len, 1, NULL, NULL, NULL, NULL);
+ ffio_init_write_context(&pb, buf, len);
ret = av1_filter_obus(&pb.pub, in, *size, NULL);
av_assert1(ret == len);
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 2883b320a1..8a06445958 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -167,8 +167,7 @@ static int annexb_probe(const AVProbeData *p)
int seq = 0;
int ret, type, cnt = 0;
- ffio_init_context(&ctx, p->buf, p->buf_size, 0,
- NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&ctx, p->buf, p->buf_size);
ret = leb(pb, &temporal_unit_size, 1);
if (ret < 0)
diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 1f5e3d474b..57796ade03 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -93,6 +93,15 @@ void ffio_init_context(FFIOContext *s,
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
int64_t (*seek)(void *opaque, int64_t offset, int whence));
+/**
+ * Wrap a buffer in an AVIOContext for reading.
+ */
+void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size);
+
+/**
+ * Wrap a buffer in an AVIOContext for writing.
+ */
+void ffio_init_write_context(FFIOContext *s, uint8_t *buffer, int buffer_size);
/**
* Read size bytes from AVIOContext, returning a pointer.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 4ad734a3c3..029a9e966b 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -127,6 +127,16 @@ void ffio_init_context(FFIOContext *ctx,
ctx->short_seek_get = NULL;
}
+void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
+{
+ ffio_init_context(s, (unsigned char*)buffer, buffer_size, 0, NULL, NULL, NULL, NULL);
+}
+
+void ffio_init_write_context(FFIOContext *s, uint8_t *buffer, int buffer_size)
+{
+ ffio_init_context(s, buffer, buffer_size, 1, NULL, NULL, NULL, NULL);
+}
+
AVIOContext *avio_alloc_context(
unsigned char *buffer,
int buffer_size,
diff --git a/libavformat/hls.c b/libavformat/hls.c
index c625e30291..276e4ee333 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1265,7 +1265,7 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf,
if (pls->id3_buf) {
/* Now parse all the ID3 tags */
FFIOContext id3ioctx;
- ffio_init_context(&id3ioctx, pls->id3_buf, id3_buf_pos, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&id3ioctx, pls->id3_buf, id3_buf_pos);
handle_id3(&id3ioctx.pub, pls);
}
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 69193933e0..d83716dcf4 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -1001,8 +1001,7 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata,
t++;
}
- ffio_init_context(&pb_local, buffer, b - buffer, 0, NULL, NULL, NULL,
- NULL);
+ ffio_init_read_context(&pb_local, buffer, b - buffer);
tlen = b - buffer;
pbx = &pb_local.pub; // read from sync buffer
}
@@ -1038,7 +1037,7 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata,
av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", err);
goto seek;
}
- ffio_init_context(&pb_local, uncompressed_buffer, dlen, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb_local, uncompressed_buffer, dlen);
tlen = dlen;
pbx = &pb_local.pub; // read from sync buffer
}
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 638e07c13d..941c0bcdc9 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2599,9 +2599,8 @@ static int mka_parse_audio_codec(MatroskaTrack *track, AVCodecParameters *par,
if (!strcmp(track->codec_id, "A_MS/ACM") &&
track->codec_priv.size >= 14) {
FFIOContext b;
- ffio_init_context(&b, track->codec_priv.data,
- track->codec_priv.size,
- 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&b, track->codec_priv.data,
+ track->codec_priv.size);
ret = ff_get_wav_header(s, &b.pub, par,
track->codec_priv.size, 0);
if (ret < 0)
@@ -2887,9 +2886,8 @@ static int mkv_parse_video_codec(MatroskaTrack *track, AVCodecParameters *par,
if (track->codec_priv.size >= 86) {
FFIOContext b;
unsigned bit_depth = AV_RB16(track->codec_priv.data + 82);
- ffio_init_context(&b, track->codec_priv.data,
- track->codec_priv.size,
- 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&b, track->codec_priv.data,
+ track->codec_priv.size);
if (ff_get_qtpalette(codec_id, &b.pub, track->palette)) {
bit_depth &= 0x1F;
track->has_palette = 1;
@@ -4057,7 +4055,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf
av_assert1(buf);
- ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, data, size);
if ((n = ebml_read_num(matroska, &pb.pub, 8, &num, 1)) < 0)
return n;
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index 20b04b12aa..d7f71304e5 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -157,8 +157,8 @@ static int mms_put_utf16(MMSContext *mms, const uint8_t *src)
FFIOContext bic;
int size = mms->write_out_ptr - mms->out_buffer;
int len;
- ffio_init_context(&bic, mms->write_out_ptr,
- sizeof(mms->out_buffer) - size, 1, NULL, NULL, NULL, NULL);
+ ffio_init_write_context(&bic, mms->write_out_ptr,
+ sizeof(mms->out_buffer) - size);
len = avio_put_str16le(&bic.pub, src);
if (len < 0)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index be9975f297..aa1d9e4ccc 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5727,7 +5727,7 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
ret = AVERROR_INVALIDDATA;
if (uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
goto free_and_return;
- ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&ctx, moov_data, moov_len);
ctx.pub.seekable = AVIO_SEEKABLE_NORMAL;
atom.type = MKTAG('m','o','o','v');
atom.size = moov_len;
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 8fd1524a8a..d825bf0b5d 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1471,8 +1471,7 @@ static int init_MP4DescrParseContext(MP4DescrParseContext *d, AVFormatContext *s
if (size > (1 << 30))
return AVERROR_INVALIDDATA;
- ffio_init_context(&d->pb, (unsigned char *)buf, size,
- 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&d->pb, buf, size);
d->s = s;
d->level = 0;
@@ -1743,9 +1742,8 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section,
pes->sl = mp4_descr[i].sl;
- ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
- mp4_descr[i].dec_config_descr_len, 0,
- NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, mp4_descr[i].dec_config_descr,
+ mp4_descr[i].dec_config_descr_len);
ff_mp4_read_dec_config_descr(s, st, &pb.pub);
if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
st->codecpar->extradata_size > 0)
@@ -1853,9 +1851,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
if (mp4_descr[i].dec_config_descr_len &&
mp4_descr[i].es_id == desc_es_id) {
FFIOContext pb;
- ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
- mp4_descr[i].dec_config_descr_len, 0,
- NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, mp4_descr[i].dec_config_descr,
+ mp4_descr[i].dec_config_descr_len);
ff_mp4_read_dec_config_descr(fc, st, &pb.pub);
if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
st->codecpar->extradata_size > 0) {
@@ -1875,9 +1872,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
sti->request_probe > 0) &&
mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) {
FFIOContext pb;
- ffio_init_context(&pb, mp4_descr->dec_config_descr,
- mp4_descr->dec_config_descr_len, 0,
- NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, mp4_descr->dec_config_descr,
+ mp4_descr->dec_config_descr_len);
ff_mp4_read_dec_config_descr(fc, st, &pb.pub);
if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
st->codecpar->extradata_size > 0) {
diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c
index 559a375d8d..f1d2d34689 100644
--- a/libavformat/mpjpegdec.c
+++ b/libavformat/mpjpegdec.c
@@ -120,7 +120,7 @@ static int mpjpeg_read_probe(const AVProbeData *p)
if (p->buf_size < 2 || p->buf[0] != '-' || p->buf[1] != '-')
return 0;
- ffio_init_context(&pb, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, p->buf, p->buf_size);
ret = (parse_multipart_header(&pb.pub, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0;
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index 2e582d0754..c669aea25a 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -292,7 +292,7 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact,
if (!p)
return NULL;
- ffio_init_context(&pb, p + offset, size - offset, 1, NULL, NULL, NULL, NULL);
+ ffio_init_write_context(&pb, p + offset, size - offset);
ff_vorbiscomment_write(&pb.pub, *m, vendor, chapters, nb_chapters);
if (framing_bit)
avio_w8(&pb.pub, 1);
diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index 2fa3c2d266..b9b02a371f 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -152,8 +152,7 @@ rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
*/
if (!rdt->mlti_data)
return -1;
- ffio_init_context(&pb0, rdt->mlti_data, rdt->mlti_data_size, 0,
- NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb0, rdt->mlti_data, rdt->mlti_data_size);
tag = avio_rl32(pb);
if (tag == MKTAG('M', 'L', 'T', 'I')) {
int num, chunk_nr;
@@ -302,7 +301,7 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
FFIOContext pb;
int pos, rmflags;
- ffio_init_context(&pb, (uint8_t *)buf, len, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, buf, len);
rmflags = (flags & RTP_FLAG_KEY) ? 2 : 0;
res = ff_rm_parse_packet(rdt->rmctx, &pb.pub, st, rdt->rmst[st->index],
len, pkt, &seq, rmflags, *timestamp);
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index 72ead6975a..20ca8295f9 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -210,7 +210,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
av_freep(&asf->buf);
- ffio_init_context(pb0, (uint8_t *)buf, len, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(pb0, buf, len);
while (avio_tell(pb) + 4 < len) {
int start_off = avio_tell(pb);
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index 495a3ec14e..b71055f8b8 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -85,7 +85,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
ret = init_get_bits(&gb, buf, len << 3);
if (ret < 0)
return ret;
- ffio_init_context(&pb0, (uint8_t*)buf, len, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb0, buf, len);
if (len < 4)
return AVERROR_INVALIDDATA;
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index cfafb4be80..c4f78f97b0 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2610,7 +2610,7 @@ static int rtp_read_header(AVFormatContext *s)
goto fail_nobuf;
avcodec_parameters_free(&par);
- ffio_init_context(&pb, sdp.str, sdp.len, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb, sdp.str, sdp.len);
s->pb = &pb.pub;
/* if sdp_read_header() fails then following ff_network_close() cancels out */
diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
index fd0e662433..59141448f4 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -148,8 +148,7 @@ static int sap_read_header(AVFormatContext *s)
}
av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp);
- ffio_init_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL,
- NULL, NULL);
+ ffio_init_read_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp));
infmt = av_find_input_format("sdp");
if (!infmt)
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 6c221e4b29..3413763c7b 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -49,9 +49,9 @@ void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
"UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
}
-void ff_text_init_buf(FFTextReader *r, void *buf, size_t size)
+void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size)
{
- ffio_init_context(&r->buf_pb, buf, size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&r->buf_pb, buf, size);
ff_text_init_avio(NULL, r, &r->buf_pb.pub);
}
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index f6688b71d7..f4993fe20d 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -68,7 +68,7 @@ void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb);
* @param buf buffer to read from (referenced as long as FFTextReader is in use)
* @param size size of buf
*/
-void ff_text_init_buf(FFTextReader *r, void *buf, size_t size);
+void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size);
/**
* Return the byte position of the next byte returned by ff_text_r8(). For
diff --git a/libavformat/vividas.c b/libavformat/vividas.c
index ed4e573df8..2f47d65c7c 100644
--- a/libavformat/vividas.c
+++ b/libavformat/vividas.c
@@ -277,7 +277,8 @@ static uint8_t *read_sb_block(AVIOContext *src, unsigned *size,
return buf;
}
-static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, int size)
+static int track_header(VividasDemuxContext *viv, AVFormatContext *s,
+ const uint8_t *buf, int size)
{
int i, j, ret;
int64_t off;
@@ -286,7 +287,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *
FFIOContext pb0;
AVIOContext *const pb = &pb0.pub;
- ffio_init_context(&pb0, buf, size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb0, buf, size);
ffio_read_varlen(pb); // track_header_len
avio_r8(pb); // '1'
@@ -432,7 +433,8 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *
return 0;
}
-static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
+static int track_index(VividasDemuxContext *viv, AVFormatContext *s,
+ const uint8_t *buf, unsigned size)
{
int64_t off;
int64_t poff;
@@ -443,7 +445,7 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu
int64_t filesize = avio_size(s->pb);
uint64_t n_sb_blocks_tmp;
- ffio_init_context(&pb0, buf, size, 0, NULL, NULL, NULL, NULL);
+ ffio_init_read_context(&pb0, buf, size);
ffio_read_varlen(pb); // track_index_len
avio_r8(pb); // 'c'