History

lavf/flacdec: stop accessing FFStream.avctx

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.

Anton Khirnov committed 2 years ago

Commit 88ba2201 parent 0d54ae41 file · +24 −1Browse files

Unified · Split

libavformat/flacdec.c+24−1
@@ -36,6 +36,8 @@ · 35 unmodified lines
3636 typedef struct FLACDecContext {
3737 FFRawDemuxerContext rawctx;
3838 int found_seektable;
39+
40+ AVCodecContext *parser_dec;
3941 } FLACDecContext;
4042
4143 static void reset_index_position(int64_t metadata_head_size, AVStream *st)
@@ -269,6 +271,7 @@ static int flac_probe(const AVProbeData *p) · 227 unmodified lines
269271 static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index,
270272 int64_t *ppos, int64_t pos_limit)
271273 {
274+ FLACDecContext *flac = s->priv_data;
272275 FFFormatContext *const si = ffformatcontext(s);
273276 AVPacket *const pkt = si->parse_pkt;
274277 AVStream *st = s->streams[stream_index];
@@ -285,6 +288,16 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde · 10 unmodified lines
285288 }
286289 parser->flags |= PARSER_FLAG_USE_CODEC_TS;
287290
291+ if (!flac->parser_dec) {
292+ flac->parser_dec = avcodec_alloc_context3(NULL);
293+ if (!flac->parser_dec)
294+ return AV_NOPTS_VALUE;
295+
296+ ret = avcodec_parameters_to_context(flac->parser_dec, st->codecpar);
297+ if (ret < 0)
298+ return ret;
299+ }
300+
288301 for (;;){
289302 uint8_t *data;
290303 int size;
@@ -298,7 +311,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde · 7 unmodified lines
298311 av_assert1(!pkt->size);
299312 }
300313 }
301− av_parser_parse2(parser, ffstream(st)->avctx,
314+ av_parser_parse2(parser, flac->parser_dec,
302315 &data, &size, pkt->data, pkt->size,
303316 pkt->pts, pkt->dts, *ppos);
304317
@@ -318,6 +331,15 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde · 13 unmodified lines
318331 return pts;
319332 }
320333
334+static int flac_close(AVFormatContext *s)
335+{
336+ FLACDecContext *flac = s->priv_data;
337+
338+ avcodec_free_context(&flac->parser_dec);
339+
340+ return 0;
341+}
342+
321343 static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
322344 AVStream *const st = s->streams[0];
323345 FFStream *const sti = ffstream(st);
@@ -347,6 +369,7 @@ const AVInputFormat ff_flac_demuxer = { · 23 unmodified lines
347369 .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"),
348370 .read_probe = flac_probe,
349371 .read_header = flac_read_header,
372+ .read_close = flac_close,
350373 .read_packet = ff_raw_read_partial_packet,
351374 .read_seek = flac_seek,
352375 .read_timestamp = flac_read_timestamp,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t