[FFmpeg-devel] [PATCH] avcodec/h2645_parse: add a flag to store skipped byte positions
James Almer
jamrial at gmail.com
Tue Sep 17 22:19:16 EEST 2024
This is only used by two out of several modules, so it's a waste of resources
for the rest.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/cbs_h2645.c | 6 ++++--
libavcodec/h2645_parse.c | 10 ++++++----
libavcodec/h2645_parse.h | 1 +
libavcodec/hevc/hevcdec.c | 2 +-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 4abd9e0c2e..75c1d1c4cf 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -725,7 +725,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
err = ff_h2645_packet_split(&priv->read_packet,
frag->data + start, end - start,
ctx->log_ctx, 2, AV_CODEC_ID_VVC,
- H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF);
+ H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING |
+ H2645_FLAG_USE_REF | H2645_FLAG_SKIPPED_BYTES);
if (err < 0) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
"VVCC array %d (%d NAL units of type %d).\n",
@@ -737,7 +738,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
return err;
}
} else {
- int flags = (H2645_FLAG_IS_NALFF * !!priv->mp4) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF;
+ int flags = (H2645_FLAG_IS_NALFF * !!priv->mp4) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF |
+ (H2645_FLAG_SKIPPED_BYTES * (codec_id == AV_CODEC_ID_VVC));
// Annex B, or later MP4 with already-known parameters.
err = ff_h2645_packet_split(&priv->read_packet,
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 7b48fcae17..f8eb301680 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -540,10 +540,12 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
memset(pkt->nals + pkt->nals_allocated, 0, sizeof(*pkt->nals));
nal = &pkt->nals[pkt->nb_nals];
- nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size
- nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos));
- if (!nal->skipped_bytes_pos)
- return AVERROR(ENOMEM);
+ if (flags & H2645_FLAG_SKIPPED_BYTES) {
+ nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size
+ nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos));
+ if (!nal->skipped_bytes_pos)
+ return AVERROR(ENOMEM);
+ }
pkt->nals_allocated = new_size;
}
diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h
index e27ccf7523..975000aeb7 100644
--- a/libavcodec/h2645_parse.h
+++ b/libavcodec/h2645_parse.h
@@ -97,6 +97,7 @@ enum {
H2645_FLAG_IS_NALFF = (1 << 0),
H2645_FLAG_SMALL_PADDING = (1 << 1),
H2645_FLAG_USE_REF = (1 << 2),
+ H2645_FLAG_SKIPPED_BYTES = (1 << 3),
};
/**
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d915d74d22..8e2d52c51a 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3321,7 +3321,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
{
int i, ret = 0;
int eos_at_start = 1;
- int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
+ int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_SKIPPED_BYTES;
s->cur_frame = s->collocated_ref = NULL;
s->last_eos = s->eos;
--
2.46.0
More information about the ffmpeg-devel
mailing list