From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/4] lavf/flacdec: stop accessing FFStream.avctx
Date: Thu, 1 Feb 2024 09:29:36 +0100
Message-ID: <20240201082938.16687-2-anton@khirnov.net> (raw)
In-Reply-To: <20240201082938.16687-1-anton@khirnov.net>
The demuxer opens an internal parser instance in read_timestamp(), which
requires a codec context. There is no need for it to access the FFStream
one which is used for other purposes, it can allocate its own internal
one.
---
libavformat/flacdec.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index ab9ef052f9..bbb205078a 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -36,6 +36,8 @@
typedef struct FLACDecContext {
FFRawDemuxerContext rawctx;
int found_seektable;
+
+ AVCodecContext *parser_dec;
} FLACDecContext;
static void reset_index_position(int64_t metadata_head_size, AVStream *st)
@@ -269,6 +271,7 @@ static int flac_probe(const AVProbeData *p)
static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
int64_t *ppos, int64_t pos_limit)
{
+ FLACDecContext *flac = s->priv_data;
FFFormatContext *const si = ffformatcontext(s);
AVPacket *const pkt = si->parse_pkt;
AVStream *st = s->streams[stream_index];
@@ -285,6 +288,16 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
}
parser->flags |= PARSER_FLAG_USE_CODEC_TS;
+ if (!flac->parser_dec) {
+ flac->parser_dec = avcodec_alloc_context3(NULL);
+ if (!flac->parser_dec)
+ return AV_NOPTS_VALUE;
+
+ ret = avcodec_parameters_to_context(flac->parser_dec, st->codecpar);
+ if (ret < 0)
+ return ret;
+ }
+
for (;;){
uint8_t *data;
int size;
@@ -298,7 +311,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
av_assert1(!pkt->size);
}
}
- av_parser_parse2(parser, ffstream(st)->avctx,
+ av_parser_parse2(parser, flac->parser_dec,
&data, &size, pkt->data, pkt->size,
pkt->pts, pkt->dts, *ppos);
@@ -318,6 +331,15 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde
return pts;
}
+static int flac_close(AVFormatContext *s)
+{
+ FLACDecContext *flac = s->priv_data;
+
+ avcodec_free_context(&flac->parser_dec);
+
+ return 0;
+}
+
static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
AVStream *const st = s->streams[0];
FFStream *const sti = ffstream(st);
@@ -347,6 +369,7 @@ const AVInputFormat ff_flac_demuxer = {
.long_name = NULL_IF_CONFIG_SMALL("raw FLAC"),
.read_probe = flac_probe,
.read_header = flac_read_header,
+ .read_close = flac_close,
.read_packet = ff_raw_read_partial_packet,
.read_seek = flac_seek,
.read_timestamp = flac_read_timestamp,
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-02-01 8:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 8:29 [FFmpeg-devel] [PATCH 1/4] lavf/mpegts: drop a cargo-culted check Anton Khirnov
2024-02-01 8:29 ` Anton Khirnov [this message]
2024-02-01 8:29 ` [FFmpeg-devel] [PATCH 3/4] lavf/demux: stop calling avcodec_close() Anton Khirnov
2024-02-03 2:35 ` Leo Izen
2024-02-05 16:59 ` Anton Khirnov
2024-02-03 3:13 ` James Almer
2024-02-05 17:03 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-02-01 8:29 ` [FFmpeg-devel] [PATCH 4/4] lavc: deprecate avcodec_close() Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240201082938.16687-2-anton@khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git