Commit 281400000f for ffmpeg
commit 281400000f4e193c966029573ab1b6ab397d56c5
Author: James Almer <jamrial@gmail.com>
Date: Tue Dec 1 18:01:31 2026 -0300
avformat/matroskadec: flag packets from discardable blocks as disposable
Signed-off-by: James Almer <jamrial@gmail.com>
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 1cad8994c8..0971e54a9b 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -4310,7 +4310,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
MatroskaTrack *track, AVStream *st,
AVBufferRef *buf, uint8_t *data, int pkt_size,
uint64_t timecode, uint64_t lace_duration,
- int64_t pos, int is_keyframe,
+ int64_t pos, int flags,
MatroskaBlockMore *blockmore, int nb_blockmore,
int64_t discard_padding)
{
@@ -4370,7 +4370,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
pkt->data = pkt_data;
pkt->size = pkt_size;
- pkt->flags = is_keyframe;
+ pkt->flags = flags;
pkt->stream_index = st->index;
for (int i = 0; i < nb_blockmore; i++) {
@@ -4429,7 +4429,7 @@ fail:
static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf, uint8_t *data,
int size, int64_t pos, uint64_t cluster_time,
- uint64_t block_duration, int is_keyframe,
+ uint64_t block_duration, int is_keyframe, int is_discardable,
MatroskaBlockMore *blockmore, int nb_blockmore,
int64_t cluster_pos, int64_t discard_padding)
{
@@ -4477,6 +4477,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf
size -= 3;
if (is_keyframe == -1)
is_keyframe = flags & 0x80 ? AV_PKT_FLAG_KEY : 0;
+ if (is_discardable == -1)
+ is_discardable = flags & 0x01 ? AV_PKT_FLAG_DISPOSABLE : 0;
if (cluster_time != (uint64_t) -1 &&
(block_time >= 0 || cluster_time >= -block_time)) {
@@ -4638,7 +4640,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf
} else {
res = matroska_parse_frame(matroska, track, st, buf, out_data,
out_size, timecode, lace_duration,
- pos, is_keyframe,
+ pos, is_keyframe | is_discardable,
blockmore, nb_blockmore,
discard_padding);
if (res)
@@ -4680,11 +4682,14 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
if (res >= 0 && block->bin.size > 0) {
int is_keyframe = block->non_simple ? block->reference.count == 0 : -1;
+ int is_discardable = block->non_simple ?
+ (block->reference.count && !block->reference.el.i) * AV_PKT_FLAG_DISPOSABLE
+ : -1;
res = matroska_parse_block(matroska, block->bin.buf, block->bin.data,
block->bin.size, block->bin.pos,
cluster->timecode, block->duration,
- is_keyframe, block->blockmore.elem,
+ is_keyframe, is_discardable, block->blockmore.elem,
block->blockmore.nb_elem, cluster->pos,
block->discard_padding);
}