diff mbox series

[FFmpeg-devel,1/2] decode: add ff_decode_skip_samples function

Message ID NknnrNO--3-9@lynne.ee
State New
Headers show
Series [FFmpeg-devel,1/2] decode: add ff_decode_skip_samples function | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Lynne Dec. 4, 2023, 7:51 a.m. UTC
This is a convenience function, which is required to be called by decoders
needing to skip samples every time.
It automatically creates and increments side data.

This function is a simplified version of an earlier patch. It is only
able to add additional delay, rather than insert or override any.
diff mbox series

Patch

From 3045ac286538641076ce4547cda677c3b159877f Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Mon, 30 Oct 2023 05:38:17 +0100
Subject: [PATCH 1/2] decode: add ff_decode_skip_samples function

This is a convenience function, which is required to be called by decoders
needing to skip samples every time.
It automatically creates and increments side data.

This function is a simplified version of an earlier patch. It is only
able to add additional delay, rather than insert or override any.
---
 libavcodec/decode.c | 17 +++++++++++++++++
 libavcodec/decode.h |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 2cfb3fcf97..450d63d947 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -299,6 +299,23 @@  static int64_t guess_correct_pts(AVCodecContext *ctx,
     return pts;
 }
 
+int ff_decode_skip_samples(AVCodecContext *avctx, AVFrame *frame, uint32_t skip)
+{
+    uint32_t val = 0;
+    AVFrameSideData *side = av_frame_get_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
+    if (!side) {
+        side = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
+        if (!side)
+            return AVERROR(ENOMEM);
+    }
+
+    val += AV_RL32(side->data);
+    val += skip;
+    AV_WL32(side->data, val);
+
+    return 0;
+}
+
 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
 {
     AVCodecInternal *avci = avctx->internal;
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index daf1a67444..c83476208c 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -155,4 +155,12 @@  int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_pr
 const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
                                                enum AVPacketSideDataType type);
 
+/**
+ * Skip samples in an AVFrame.
+ *
+ * @param skip amount of samples to skip unconditionally
+ */
+int ff_decode_skip_samples(AVCodecContext *avctx, AVFrame *frame,
+                           uint32_t skip);
+
 #endif /* AVCODEC_DECODE_H */
-- 
2.43.0