Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] lavc/decode: allow using AV_CODEC_FLAG_COPY_OPAQUE for decoding
@ 2023-01-31 11:38 Anton Khirnov
  2023-01-31 11:39 ` [FFmpeg-devel] [PATCH 2/2] lavu/frame: deprecate reordered_opaque Anton Khirnov
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Khirnov @ 2023-01-31 11:38 UTC (permalink / raw)
  To: ffmpeg-devel

Use it to propagate AVPacket.opaque[_ref] to corresponding AVFrame
fields. This is a more convenient alternative to reordered_opaque.
---
 doc/APIchanges        |  3 +++
 libavcodec/avcodec.h  |  9 +++++++++
 libavcodec/decode.c   | 12 ++++++++++--
 libavcodec/decode.h   |  3 ++-
 libavcodec/libdav1d.c | 31 +++++++++++++++++++++++--------
 libavcodec/version.h  |  2 +-
 6 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index bc52a07964..4b3934b82c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil:     2021-04-27
 
 API changes, most recent first:
 
+2023-0x-xx - xxxxxxxxxx - lavc 59.60.100
+  Allow AV_CODEC_FLAG_COPY_OPAQUE to be used with decoders.
+
 2023-01-29 - xxxxxxxxxx - lavc 59.59.100 - avcodec.h
   Add AV_CODEC_FLAG_COPY_OPAQUE and AV_CODEC_FLAG_FRAME_DURATION.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 90b437ccbe..eba9ea73d7 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -242,9 +242,15 @@ typedef struct RcOverride{
  */
 #define AV_CODEC_FLAG_RECON_FRAME     (1 <<  6)
 /**
+ * @par decoding
+ * Request the decoder to propagate each packets AVPacket.opaque and
+ * AVPacket.opaque_ref to its corresponding output AVFrame.
+ *
+ * @par encoding:
  * Request the encoder to propagate each frame's AVFrame.opaque and
  * AVFrame.opaque_ref values to its corresponding output AVPacket.
  *
+ * @par
  * May only be set on encoders that have the
  * @ref AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability flag.
  *
@@ -265,6 +271,9 @@ typedef struct RcOverride{
  * .
  * When an output packet contains multiple frames, the opaque values will be
  * taken from the first of those.
+ *
+ * @note
+ * The converse holds for decoders, with frames and packets switched.
  */
 #define AV_CODEC_FLAG_COPY_OPAQUE     (1 <<  7)
 /**
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0abc88737b..17b398e933 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1291,7 +1291,8 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
     return av_packet_unpack_dictionary(side_metadata, size, frame_md);
 }
 
-int ff_decode_frame_props_from_pkt(AVFrame *frame, const AVPacket *pkt)
+int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
+                                   AVFrame *frame, const AVPacket *pkt)
 {
     static const struct {
         enum AVPacketSideDataType packet;
@@ -1336,6 +1337,13 @@ int ff_decode_frame_props_from_pkt(AVFrame *frame, const AVPacket *pkt)
         frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
     }
 
+    if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
+        int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
+        if (ret < 0)
+            return ret;
+        frame->opaque = pkt->opaque;
+    }
+
     return 0;
 }
 
@@ -1344,7 +1352,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
     const AVPacket *pkt = avctx->internal->last_pkt_props;
 
     if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
-        int ret = ff_decode_frame_props_from_pkt(frame, pkt);
+        int ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt);
         if (ret < 0)
             return ret;
         frame->pkt_size     = (int)(intptr_t)pkt->opaque;
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index 906122b4a7..8430ffbd66 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -72,7 +72,8 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt);
 /**
  * Set various frame properties from the provided packet.
  */
-int ff_decode_frame_props_from_pkt(AVFrame *frame, const AVPacket *pkt);
+int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
+                                   AVFrame *frame, const AVPacket *pkt);
 
 /**
  * Set various frame properties from the codec context / packet data.
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index b43af03732..f7d75f9439 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -288,6 +288,11 @@ static void libdav1d_flush(AVCodecContext *c)
     dav1d_flush(dav1d->c);
 }
 
+typedef struct OpaqueData {
+    void    *pkt_orig_opaque;
+    int64_t  reordered_opaque;
+} OpaqueData;
+
 static void libdav1d_data_free(const uint8_t *data, void *opaque) {
     AVBufferRef *buf = opaque;
 
@@ -307,6 +312,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
     Dav1dData *data = &dav1d->data;
     Dav1dPicture pic = { 0 }, *p = &pic;
     AVPacket *pkt;
+    OpaqueData *od = NULL;
 #if FF_DAV1D_VERSION_AT_LEAST(5,1)
     enum Dav1dEventFlags event_flags = 0;
 #endif
@@ -333,17 +339,19 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
             }
 
             pkt->buf = NULL;
-            pkt->opaque = NULL;
 
-            if (c->reordered_opaque != AV_NOPTS_VALUE) {
-                pkt->opaque = av_memdup(&c->reordered_opaque,
-                                        sizeof(c->reordered_opaque));
-                if (!pkt->opaque) {
+            if (c->reordered_opaque != AV_NOPTS_VALUE ||
+                (pkt->opaque && (c->flags & AV_CODEC_FLAG_COPY_OPAQUE))) {
+                od = av_mallocz(sizeof(*od));
+                if (!od) {
                     av_packet_free(&pkt);
                     dav1d_data_unref(data);
                     return AVERROR(ENOMEM);
                 }
+                od->pkt_orig_opaque  = pkt->opaque;
+                od->reordered_opaque = c->reordered_opaque;
             }
+            pkt->opaque = od;
 
             res = dav1d_data_wrap_user_data(data, (const uint8_t *)pkt,
                                             libdav1d_user_data_free, pkt);
@@ -423,13 +431,20 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
     ff_set_sar(c, frame->sample_aspect_ratio);
 
     pkt = (AVPacket *)p->m.user_data.data;
-    if (pkt->opaque)
-        memcpy(&frame->reordered_opaque, pkt->opaque, sizeof(frame->reordered_opaque));
+    od  = pkt->opaque;
+    if (od && od->reordered_opaque != AV_NOPTS_VALUE)
+        frame->reordered_opaque = od->reordered_opaque;
     else
         frame->reordered_opaque = AV_NOPTS_VALUE;
 
+    // restore the original user opaque value for
+    // ff_decode_frame_props_from_pkt()
+    pkt->opaque = od ? od->pkt_orig_opaque : NULL;
+    av_freep(&od);
+
     // match timestamps and packet size
-    res = ff_decode_frame_props_from_pkt(frame, pkt);
+    res = ff_decode_frame_props_from_pkt(c, frame, pkt);
+    pkt->opaque = NULL;
     if (res < 0)
         goto fail;
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 2ed4ef5547..499c6bb175 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  60
+#define LIBAVCODEC_VERSION_MINOR  61
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] lavu/frame: deprecate reordered_opaque
  2023-01-31 11:38 [FFmpeg-devel] [PATCH 1/2] lavc/decode: allow using AV_CODEC_FLAG_COPY_OPAQUE for decoding Anton Khirnov
@ 2023-01-31 11:39 ` Anton Khirnov
  0 siblings, 0 replies; 2+ messages in thread
From: Anton Khirnov @ 2023-01-31 11:39 UTC (permalink / raw)
  To: ffmpeg-devel

It is only used in libavcodec, where it's been superseded by
AV_CODEC_CAP_COPY_OPAQUE.
---
 libavcodec/avcodec.h                |  5 +++++
 libavcodec/codec.h                  |  6 +++---
 libavcodec/decode.c                 |  4 ++++
 libavcodec/encode.c                 |  4 ++++
 libavcodec/libdav1d.c               | 15 ++++++++++++++-
 libavcodec/librav1e.c               | 10 ++++++++++
 libavcodec/libwebpenc_animencoder.c | 10 ++++++++++
 libavcodec/libx264.c                | 14 ++++++++++++++
 libavcodec/libx265.c                | 17 ++++++++++++++++-
 libavcodec/nvenc.c                  | 10 ++++++++++
 libavcodec/options.c                |  4 ++++
 libavcodec/pthread_frame.c          |  4 ++++
 libavutil/frame.c                   |  4 ++++
 libavutil/frame.h                   |  5 +++++
 libavutil/version.h                 |  1 +
 15 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index eba9ea73d7..755e543fac 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1392,6 +1392,7 @@ typedef struct AVCodecContext {
      */
     int err_recognition;
 
+#if FF_API_REORDERED_OPAQUE
     /**
      * opaque 64-bit number (generally a PTS) that will be reordered and
      * output in AVFrame.reordered_opaque
@@ -1400,8 +1401,12 @@ typedef struct AVCodecContext {
      *             supported by encoders with the
      *             AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
      * - decoding: Set by user.
+     *
+     * @deprecated Use AV_CODEC_FLAG_COPY_OPAQUE instead
      */
+    attribute_deprecated
     int64_t reordered_opaque;
+#endif
 
     /**
      * Hardware accelerator in use
diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index 77a1a3f5a2..67f9120b44 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -169,9 +169,9 @@
 #define AV_CODEC_CAP_HYBRID              (1 << 19)
 
 /**
- * This codec takes the reordered_opaque field from input AVFrames
- * and returns it in the corresponding field in AVCodecContext after
- * encoding.
+ * This encoder can reorder user opaque values from input AVFrames and return
+ * them with corresponding output packets.
+ * @see AV_CODEC_FLAG_COPY_OPAQUE
  */
 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 17b398e933..03ae27ecdf 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1357,7 +1357,11 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
             return ret;
         frame->pkt_size     = (int)(intptr_t)pkt->opaque;
     }
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     frame->reordered_opaque = avctx->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
         frame->color_primaries = avctx->color_primaries;
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index c92beaf8e1..b0a9625ca9 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -193,7 +193,11 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
 int ff_encode_reordered_opaque(AVCodecContext *avctx,
                                AVPacket *pkt, const AVFrame *frame)
 {
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     avctx->reordered_opaque = frame->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
         int ret = av_buffer_replace(&pkt->opaque_ref, frame->opaque_ref);
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index f7d75f9439..2488a709c7 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -290,7 +290,9 @@ static void libdav1d_flush(AVCodecContext *c)
 
 typedef struct OpaqueData {
     void    *pkt_orig_opaque;
+#if FF_API_REORDERED_OPAQUE
     int64_t  reordered_opaque;
+#endif
 } OpaqueData;
 
 static void libdav1d_data_free(const uint8_t *data, void *opaque) {
@@ -340,7 +342,11 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
 
             pkt->buf = NULL;
 
-            if (c->reordered_opaque != AV_NOPTS_VALUE ||
+FF_DISABLE_DEPRECATION_WARNINGS
+            if (
+#if FF_API_REORDERED_OPAQUE
+                c->reordered_opaque != AV_NOPTS_VALUE ||
+#endif
                 (pkt->opaque && (c->flags & AV_CODEC_FLAG_COPY_OPAQUE))) {
                 od = av_mallocz(sizeof(*od));
                 if (!od) {
@@ -349,7 +355,10 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
                     return AVERROR(ENOMEM);
                 }
                 od->pkt_orig_opaque  = pkt->opaque;
+#if FF_API_REORDERED_OPAQUE
                 od->reordered_opaque = c->reordered_opaque;
+#endif
+FF_ENABLE_DEPRECATION_WARNINGS
             }
             pkt->opaque = od;
 
@@ -432,10 +441,14 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
 
     pkt = (AVPacket *)p->m.user_data.data;
     od  = pkt->opaque;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     if (od && od->reordered_opaque != AV_NOPTS_VALUE)
         frame->reordered_opaque = od->reordered_opaque;
     else
         frame->reordered_opaque = AV_NOPTS_VALUE;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     // restore the original user opaque value for
     // ff_decode_frame_props_from_pkt()
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index 00d69328fb..08affabe3e 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -57,7 +57,9 @@ typedef struct librav1eContext {
 typedef struct FrameData {
     int64_t pts;
     int64_t duration;
+#if FF_API_REORDERED_OPAQUE
     int64_t reordered_opaque;
+#endif
 
     void        *frame_opaque;
     AVBufferRef *frame_opaque_ref;
@@ -465,7 +467,11 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
             }
             fd->pts      = frame->pts;
             fd->duration = frame->duration;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
             fd->reordered_opaque = frame->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
             if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
                 fd->frame_opaque = frame->opaque;
@@ -572,7 +578,11 @@ retry:
     fd = rpkt->opaque;
     pkt->pts = pkt->dts = fd->pts;
     pkt->duration = fd->duration;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     avctx->reordered_opaque = fd->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
         pkt->opaque          = fd->frame_opaque;
diff --git a/libavcodec/libwebpenc_animencoder.c b/libavcodec/libwebpenc_animencoder.c
index 440cae1de5..72d704f490 100644
--- a/libavcodec/libwebpenc_animencoder.c
+++ b/libavcodec/libwebpenc_animencoder.c
@@ -39,7 +39,9 @@ typedef struct LibWebPAnimContext {
     int64_t first_frame_pts;  // pts of the first encoded frame.
     int64_t end_pts;          // pts + duration of the last frame
 
+#if FF_API_REORDERED_OPAQUE
     int64_t         reordered_opaque;
+#endif
     void           *first_frame_opaque;
     AVBufferRef    *first_frame_opaque_ref;
 
@@ -90,7 +92,11 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 if (pkt->pts != AV_NOPTS_VALUE && s->end_pts > pkt->pts)
                     pkt->duration = s->end_pts - pkt->pts;
 
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
                 avctx->reordered_opaque = s->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
                 if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
                     pkt->opaque               = s->first_frame_opaque;
                     pkt->opaque_ref           = s->first_frame_opaque_ref;
@@ -128,7 +134,11 @@ static int libwebp_anim_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
         if (!avctx->frame_number) {
             s->first_frame_pts = frame->pts;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
             s->reordered_opaque = frame->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
             if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
                 s->first_frame_opaque = frame->opaque;
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2742fb11a0..f65ac5dacc 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -50,7 +50,9 @@
 #define MB_SIZE 16
 
 typedef struct X264Opaque {
+#if FF_API_REORDERED_OPAQUE
     int64_t reordered_opaque;
+#endif
     int64_t wallclock;
     int64_t duration;
 
@@ -459,7 +461,11 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame,
             goto fail;
     }
 
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     opaque->reordered_opaque = frame->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     opaque->duration         = frame->duration;
     opaque->wallclock = wallclock;
     if (ctx->export_side_data & AV_CODEC_EXPORT_DATA_PRFT)
@@ -612,7 +618,11 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
     out_opaque = pic_out.opaque;
     if (out_opaque >= x4->reordered_opaque &&
         out_opaque < &x4->reordered_opaque[x4->nb_reordered_opaque]) {
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
         ctx->reordered_opaque = out_opaque->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         wallclock = out_opaque->wallclock;
         pkt->duration = out_opaque->duration;
 
@@ -627,7 +637,11 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
         // Unexpected opaque pointer on picture output
         av_log(ctx, AV_LOG_ERROR, "Unexpected opaque pointer; "
                "this is a bug, please report it.\n");
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
         ctx->reordered_opaque = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     }
 
     switch (pic_out.i_type) {
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 6fc189f1b5..6a2600c5e7 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -42,7 +42,9 @@
 #include "sei.h"
 
 typedef struct ReorderedData {
+#if FF_API_REORDERED_OPAQUE
     int64_t reordered_opaque;
+#endif
     int64_t duration;
 
     void        *frame_opaque;
@@ -618,7 +620,11 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         rd = &ctx->rd[rd_idx];
 
         rd->duration         = pic->duration;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
         rd->reordered_opaque = pic->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
             rd->frame_opaque = pic->opaque;
             ret = av_buffer_replace(&rd->frame_opaque_ref, pic->opaque_ref);
@@ -756,7 +762,11 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         int idx = (int)(intptr_t)x265pic_out.userData - 1;
         ReorderedData *rd = &ctx->rd[idx];
 
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->reordered_opaque = rd->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         pkt->duration           = rd->duration;
 
         if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
@@ -766,8 +776,13 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         }
 
         rd_release(ctx, idx);
-    } else
+    }
+#if FF_API_REORDERED_OPAQUE
+    else
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->reordered_opaque = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     *got_packet = 1;
     return 0;
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index ab42dc9690..8a28454042 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -166,7 +166,9 @@ static int nvenc_print_error(AVCodecContext *avctx, NVENCSTATUS err,
 typedef struct FrameData {
     int64_t pts;
     int64_t duration;
+#if FF_API_REORDERED_OPAQUE
     int64_t reordered_opaque;
+#endif
 
     void        *frame_opaque;
     AVBufferRef *frame_opaque_ref;
@@ -2203,7 +2205,11 @@ static void reorder_queue_enqueue(AVFifo *queue, const AVCodecContext *avctx,
 
     fd.pts              = frame->pts;
     fd.duration         = frame->duration;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     fd.reordered_opaque = frame->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     fd.frame_opaque     = frame->opaque;
     fd.frame_opaque_ref = *opaque_ref;
 
@@ -2222,7 +2228,11 @@ static int64_t reorder_queue_dequeue(AVFifo *queue, AVCodecContext *avctx,
         return AV_NOPTS_VALUE;
 
     if (pkt) {
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->reordered_opaque = fd.reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         pkt->duration           = fd.duration;
 
         if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 2e05d29e1e..9090c94e9c 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -124,7 +124,11 @@ static int init_context_defaults(AVCodecContext *s, const AVCodec *codec)
     s->sw_pix_fmt          = AV_PIX_FMT_NONE;
     s->sample_fmt          = AV_SAMPLE_FMT_NONE;
 
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     s->reordered_opaque    = AV_NOPTS_VALUE;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     if(codec && codec2->priv_data_size){
         s->priv_data = av_mallocz(codec2->priv_data_size);
         if (!s->priv_data)
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 62a0b18a8a..ae8d051acd 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -390,7 +390,11 @@ static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
     dst->skip_frame       = src->skip_frame;
 
     dst->frame_number     = src->frame_number;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     dst->reordered_opaque = src->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 #if FF_API_THREAD_SAFE_CALLBACKS
 FF_DISABLE_DEPRECATION_WARNINGS
     dst->thread_safe_callbacks = src->thread_safe_callbacks;
diff --git a/libavutil/frame.c b/libavutil/frame.c
index fa9b11aa54..2d81de8b0d 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -304,7 +304,11 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
     dst->time_base              = src->time_base;
+#if FF_API_REORDERED_OPAQUE
+FF_DISABLE_DEPRECATION_WARNINGS
     dst->reordered_opaque       = src->reordered_opaque;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     dst->quality                = src->quality;
     dst->best_effort_timestamp  = src->best_effort_timestamp;
     dst->coded_picture_number   = src->coded_picture_number;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index bbe909ee2d..911af515f4 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -491,6 +491,7 @@ typedef struct AVFrame {
      */
     int palette_has_changed;
 
+#if FF_API_REORDERED_OPAQUE
     /**
      * reordered opaque 64 bits (generally an integer or a double precision float
      * PTS but can be anything).
@@ -498,8 +499,12 @@ typedef struct AVFrame {
      * that time,
      * the decoder reorders values as needed and sets AVFrame.reordered_opaque
      * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
+     *
+     * @deprecated Use AV_CODEC_FLAG_COPY_OPAQUE instead
      */
+    attribute_deprecated
     int64_t reordered_opaque;
+#endif
 
     /**
      * Sample rate of the audio data.
diff --git a/libavutil/version.h b/libavutil/version.h
index 60f96af5df..43daf8cd5a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -115,6 +115,7 @@
 #define FF_API_OLD_CHANNEL_LAYOUT       (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_FOPEN_UTF8            (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_PKT_DURATION             (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_REORDERED_OPAQUE         (LIBAVUTIL_VERSION_MAJOR < 59)
 
 /**
  * @}
-- 
2.35.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-31 11:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 11:38 [FFmpeg-devel] [PATCH 1/2] lavc/decode: allow using AV_CODEC_FLAG_COPY_OPAQUE for decoding Anton Khirnov
2023-01-31 11:39 ` [FFmpeg-devel] [PATCH 2/2] lavu/frame: deprecate reordered_opaque Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git