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.
Unified · Split
| @@ -36,6 +36,8 @@ · 35 unmodified lines | |||
| 36 | typedef struct FLACDecContext { | 36 | typedef struct FLACDecContext { |
| 37 | FFRawDemuxerContext rawctx; | 37 | FFRawDemuxerContext rawctx; |
| 38 | int found_seektable; | 38 | int found_seektable; |
| 39 | |||
| 40 | AVCodecContext *parser_dec; | ||
| 39 | } FLACDecContext; | 41 | } FLACDecContext; |
| 40 | 42 | ||
| 41 | static void reset_index_position(int64_t metadata_head_size, AVStream *st) | 43 | 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 | |||
| 269 | static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index, | 271 | static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index, |
| 270 | int64_t *ppos, int64_t pos_limit) | 272 | int64_t *ppos, int64_t pos_limit) |
| 271 | { | 273 | { |
| 274 | FLACDecContext *flac = s->priv_data; | ||
| 272 | FFFormatContext *const si = ffformatcontext(s); | 275 | FFFormatContext *const si = ffformatcontext(s); |
| 273 | AVPacket *const pkt = si->parse_pkt; | 276 | AVPacket *const pkt = si->parse_pkt; |
| 274 | AVStream *st = s->streams[stream_index]; | 277 | 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 | |||
| 285 | } | 288 | } |
| 286 | parser->flags |= PARSER_FLAG_USE_CODEC_TS; | 289 | parser->flags |= PARSER_FLAG_USE_CODEC_TS; |
| 287 | 290 | ||
| 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 | |||
| 288 | for (;;){ | 301 | for (;;){ |
| 289 | uint8_t *data; | 302 | uint8_t *data; |
| 290 | int size; | 303 | int size; |
| @@ -298,7 +311,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde · 7 unmodified lines | |||
| 298 | av_assert1(!pkt->size); | 311 | av_assert1(!pkt->size); |
| 299 | } | 312 | } |
| 300 | } | 313 | } |
| 301 | av_parser_parse2(parser, ffstream(st)->avctx, | 314 | av_parser_parse2(parser, flac->parser_dec, |
| 302 | &data, &size, pkt->data, pkt->size, | 315 | &data, &size, pkt->data, pkt->size, |
| 303 | pkt->pts, pkt->dts, *ppos); | 316 | pkt->pts, pkt->dts, *ppos); |
| 304 | 317 | ||
| @@ -318,6 +331,15 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde · 13 unmodified lines | |||
| 318 | return pts; | 331 | return pts; |
| 319 | } | 332 | } |
| 320 | 333 | ||
| 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 | |||
| 321 | static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { | 343 | static int flac_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { |
| 322 | AVStream *const st = s->streams[0]; | 344 | AVStream *const st = s->streams[0]; |
| 323 | FFStream *const sti = ffstream(st); | 345 | FFStream *const sti = ffstream(st); |
| @@ -347,6 +369,7 @@ const AVInputFormat ff_flac_demuxer = { · 23 unmodified lines | |||
| 347 | .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"), | 369 | .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"), |
| 348 | .read_probe = flac_probe, | 370 | .read_probe = flac_probe, |
| 349 | .read_header = flac_read_header, | 371 | .read_header = flac_read_header, |
| 372 | .read_close = flac_close, | ||
| 350 | .read_packet = ff_raw_read_partial_packet, | 373 | .read_packet = ff_raw_read_partial_packet, |
| 351 | .read_seek = flac_seek, | 374 | .read_seek = flac_seek, |
| 352 | .read_timestamp = flac_read_timestamp, | 375 | .read_timestamp = flac_read_timestamp, |