avformat/demux: use a stream specific temporary packet for the parser

This will be useful for the next commit.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2026-01-05 23:50:41 -03:00
parent f1dbef3e38
commit 70d84bdd84
4 changed files with 22 additions and 1 deletions

View File

@@ -59,6 +59,8 @@ void ff_free_stream(AVStream **pst)
av_freep(&sti->index_entries);
av_freep(&sti->probe_data.buf);
av_packet_free(&sti->parse_pkt);
av_bsf_free(&sti->extract_extradata.bsf);
if (sti->info) {

View File

@@ -1175,9 +1175,9 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
{
FormatContextInternal *const fci = ff_fc_internal(s);
FFFormatContext *const si = &fci->fc;
AVPacket *out_pkt = si->parse_pkt;
AVStream *st = s->streams[stream_index];
FFStream *const sti = ffstream(st);
AVPacket *out_pkt = sti->parse_pkt;
const AVPacketSideData *sd = NULL;
const uint8_t *data = pkt->data;
uint8_t *extradata = sti->avctx->extradata;

View File

@@ -314,6 +314,21 @@ typedef struct FFStream {
enum AVStreamParseType need_parsing;
struct AVCodecParserContext *parser;
/**
* The generic code uses this as a temporary packet
* to parse packets or for muxing, especially flushing.
* For demuxers, it may also be used for other means
* for short periods that are guaranteed not to overlap
* with calls to av_read_frame() (or ff_read_packet())
* or with each other.
* It may be used by demuxers as a replacement for
* stack packets (unless they call one of the aforementioned
* functions with their own AVFormatContext).
* Every user has to ensure that this packet is blank
* after using it.
*/
AVPacket *parse_pkt;
/**
* Number of frames that have been demuxed during avformat_find_stream_info()
*/

View File

@@ -270,6 +270,10 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
sti->fmtctx = s;
sti->parse_pkt = av_packet_alloc();
if (!sti->parse_pkt)
goto fail;
if (s->iformat) {
sti->avctx = avcodec_alloc_context3(NULL);
if (!sti->avctx)