From 45bfe8b838275235412777dd430206d9a24eb3ee Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 4 Aug 2021 16:52:07 +0200 Subject: avformat/avio: Move internal AVIOContext fields to avio_internal.h Currently AVIOContext's private fields are all over AVIOContext. This commit moves them into a new structure in avio_internal.h instead. Said structure contains the public AVIOContext as its first element in order to avoid having to allocate a separate AVIOContextInternal which is costly for those use cases where one just wants to access an already existing buffer via the AVIOContext-API. For these cases ffio_init_context() can't fail and always returned zero, which was typically not checked. Therefore it has been made to not return anything. Signed-off-by: Andreas Rheinhardt --- libavformat/rtpdec_qt.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'libavformat/rtpdec_qt.c') diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c index 492a1b6715..6723cd1bb0 100644 --- a/libavformat/rtpdec_qt.c +++ b/libavformat/rtpdec_qt.c @@ -54,7 +54,8 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, uint32_t *timestamp, const uint8_t *buf, int len, uint16_t seq, int flags) { - AVIOContext pb; + FFIOContext pb0; + AVIOContext *const pb = &pb0.pub; GetBitContext gb; int packing_scheme, has_payload_desc, has_packet_info, alen, has_marker_bit = flags & RTP_FLAG_MARKER, @@ -82,7 +83,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, * http://developer.apple.com/quicktime/icefloe/dispatch026.html */ init_get_bits(&gb, buf, len << 3); - ffio_init_context(&pb, (uint8_t*)buf, len, 0, NULL, NULL, NULL, NULL); + ffio_init_context(&pb0, (uint8_t*)buf, len, 0, NULL, NULL, NULL, NULL); if (len < 4) return AVERROR_INVALIDDATA; @@ -114,22 +115,22 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, skip_bits(&gb, 12); // reserved data_len = get_bits(&gb, 16); - avio_seek(&pb, pos + 4, SEEK_SET); - tag = avio_rl32(&pb); + avio_seek(pb, pos + 4, SEEK_SET); + tag = avio_rl32(pb); if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && tag != MKTAG('v','i','d','e')) || (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && tag != MKTAG('s','o','u','n'))) return AVERROR_INVALIDDATA; - avpriv_set_pts_info(st, 32, 1, avio_rb32(&pb)); + avpriv_set_pts_info(st, 32, 1, avio_rb32(pb)); if (pos + data_len > len) return AVERROR_INVALIDDATA; /* TLVs */ - while (avio_tell(&pb) + 4 < pos + data_len) { - int tlv_len = avio_rb16(&pb); - tag = avio_rl16(&pb); - if (avio_tell(&pb) + tlv_len > pos + data_len) + while (avio_tell(pb) + 4 < pos + data_len) { + int tlv_len = avio_rb16(pb); + tag = avio_rl16(pb); + if (avio_tell(pb) + tlv_len > pos + data_len) return AVERROR_INVALIDDATA; #define MKTAG16(a,b) MKTAG(a,b,0,0) @@ -151,7 +152,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, /* ff_mov_read_stsd_entries updates stream s->nb_streams-1, * so set it temporarily to indicate which stream to update. */ s->nb_streams = st->index + 1; - ff_mov_read_stsd_entries(mc, &pb, 1); + ff_mov_read_stsd_entries(mc, pb, 1); qt->bytes_per_frame = msc->bytes_per_frame; av_free(msc); av_free(mc); @@ -160,22 +161,22 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, break; } default: - avio_skip(&pb, tlv_len); + avio_skip(pb, tlv_len); break; } } /* 32-bit alignment */ - avio_skip(&pb, ((avio_tell(&pb) + 3) & ~3) - avio_tell(&pb)); + avio_skip(pb, ((avio_tell(pb) + 3) & ~3) - avio_tell(pb)); } else - avio_seek(&pb, 4, SEEK_SET); + avio_seek(pb, 4, SEEK_SET); if (has_packet_info) { avpriv_request_sample(s, "RTP-X-QT with packet-specific info"); return AVERROR_PATCHWELCOME; } - alen = len - avio_tell(&pb); + alen = len - avio_tell(pb); if (alen <= 0) return AVERROR_INVALIDDATA; @@ -197,7 +198,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, qt->pkt->size = 0; qt->timestamp = *timestamp; } - memcpy(qt->pkt->data + qt->pkt->size, buf + avio_tell(&pb), alen); + memcpy(qt->pkt->data + qt->pkt->size, buf + avio_tell(pb), alen); qt->pkt->size += alen; if (has_marker_bit) { int ret = av_packet_from_data(pkt, qt->pkt->data, qt->pkt->size); @@ -220,7 +221,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, qt->remaining = (alen / qt->bytes_per_frame) - 1; if ((ret = av_new_packet(pkt, qt->bytes_per_frame)) < 0) return ret; - memcpy(pkt->data, buf + avio_tell(&pb), qt->bytes_per_frame); + memcpy(pkt->data, buf + avio_tell(pb), qt->bytes_per_frame); pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0; pkt->stream_index = st->index; if (qt->remaining > 0) { @@ -232,7 +233,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, } qt->pkt->size = qt->remaining * qt->bytes_per_frame; memcpy(qt->pkt->data, - buf + avio_tell(&pb) + qt->bytes_per_frame, + buf + avio_tell(pb) + qt->bytes_per_frame, qt->remaining * qt->bytes_per_frame); qt->pkt->flags = pkt->flags; return 1; -- cgit v1.2.3