Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] lavc: deprecate AV_CODEC_FLAG_DROPCHANGED
Date: Sun,  9 Jul 2023 14:57:46 +0200
Message-ID: <20230709125746.8054-1-anton@khirnov.net> (raw)

This decoding flag makes decoders drop all frames after a parameter
change, but what exactly constitutes a parameter change is not well
defined and will typically depend on the exact use case.
This functionality then does not belong in libavcodec, but rather in
user code
---
 doc/APIchanges             |  3 +++
 libavcodec/avcodec.c       |  2 ++
 libavcodec/avcodec.h       |  7 ++++---
 libavcodec/decode.c        | 11 +++++++++--
 libavcodec/internal.h      |  2 ++
 libavcodec/options_table.h |  2 ++
 libavcodec/version_major.h |  1 +
 7 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0cda51fdee..6217502492 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2023-07-xx - xxxxxxxxxx - lavc 60 - avcodec.h
+  Deprecate AV_CODEC_FLAG_DROPCHANGED without replacement.
+
 2023-07-xx - xxxxxxxxxx - lavu 58.15.100 - video_hint.h
   Add AVVideoHint API.
 
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 8ccc610227..340abe830e 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -456,7 +456,9 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 
         av_bsf_free(&avci->bsf);
 
+#if FF_API_DROPCHANGED
         av_channel_layout_uninit(&avci->initial_ch_layout);
+#endif
 
 #if CONFIG_LCMS2
         ff_icc_context_uninit(&avci->icc);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d17bdc360d..fe41ecc3c9 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -226,11 +226,15 @@ typedef struct RcOverride{
  * Use qpel MC.
  */
 #define AV_CODEC_FLAG_QPEL            (1 <<  4)
+#if FF_API_DROPCHANGED
 /**
  * Don't output frames whose parameters differ from first
  * decoded frame in stream.
+ *
+ * @deprecated callers should implement this functionality in their own code
  */
 #define AV_CODEC_FLAG_DROPCHANGED     (1 <<  5)
+#endif
 /**
  * Request the encoder to output reconstructed frames, i.e.\ frames that would
  * be produced by decoding the encoded bistream. These frames may be retrieved
@@ -2713,9 +2717,6 @@ int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  *                          no more output frames
  * @retval AVERROR(EINVAL)  codec not opened, or it is an encoder without the
  *                          @ref AV_CODEC_FLAG_RECON_FRAME flag enabled
- * @retval AVERROR_INPUT_CHANGED current decoded frame has changed parameters with
- *                          respect to first decoded frame. Applicable when flag
- *                          AV_CODEC_FLAG_DROPCHANGED is set.
  * @retval "other negative error code" legitimate decoding errors
  */
 int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 269633ce10..40eb7679ca 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -740,7 +740,7 @@ fail:
 int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 {
     AVCodecInternal *avci = avctx->internal;
-    int ret, changed;
+    int ret;
 
     if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
         return AVERROR(EINVAL);
@@ -770,6 +770,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+#if FF_API_DROPCHANGED
     if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
 
         if (avctx->frame_num == 1) {
@@ -790,7 +791,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
 
         if (avctx->frame_num > 1) {
-            changed = avci->initial_format != frame->format;
+            int changed = avci->initial_format != frame->format;
 
             switch(avctx->codec_type) {
             case AVMEDIA_TYPE_VIDEO:
@@ -815,6 +816,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
             }
         }
     }
+#endif
     return 0;
 fail:
     av_frame_unref(frame);
@@ -1739,6 +1741,11 @@ int ff_decode_preinit(AVCodecContext *avctx)
     if (ret < 0)
         return ret;
 
+#if FF_API_DROPCHANGED
+    if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED)
+        av_log(avctx, AV_LOG_WARNING, "The dropchanged flag is deprecated.\n");
+#endif
+
     return 0;
 }
 
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 868dd46b48..4dce9f6fbb 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -135,12 +135,14 @@ typedef struct AVCodecInternal {
     AVFrame *buffer_frame;
     int draining_done;
 
+#if FF_API_DROPCHANGED
     /* used when avctx flag AV_CODEC_FLAG_DROPCHANGED is set */
     int changed_frames_dropped;
     int initial_format;
     int initial_width, initial_height;
     int initial_sample_rate;
     AVChannelLayout initial_ch_layout;
+#endif
 
 #if CONFIG_LCMS2
     FFIccContext icc; /* used to read and write embedded ICC profiles */
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index f1a9729c0d..d1244bfc1a 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -72,7 +72,9 @@ static const AVOption avcodec_options[] = {
 {"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
 {"cgop", "closed GOP", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
 {"output_corrupt", "Output even potentially corrupted frames", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_OUTPUT_CORRUPT }, INT_MIN, INT_MAX, V|D, "flags"},
+#if FF_API_DROPCHANGED
 {"drop_changed", "Drop frames whose parameters differ from first decoded frame", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_DROPCHANGED }, INT_MIN, INT_MAX, A|V|D, "flags"},
+#endif
 {"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT}, 0, UINT_MAX, V|A|E|D|S, "flags2"},
 {"fast", "allow non-spec-compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
 {"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h
index 2f5138d079..95c5aec0c5 100644
--- a/libavcodec/version_major.h
+++ b/libavcodec/version_major.h
@@ -48,6 +48,7 @@
 #define FF_API_SLICE_OFFSET        (LIBAVCODEC_VERSION_MAJOR < 61)
 #define FF_API_SUBFRAMES           (LIBAVCODEC_VERSION_MAJOR < 61)
 #define FF_API_TICKS_PER_FRAME     (LIBAVCODEC_VERSION_MAJOR < 61)
+#define FF_API_DROPCHANGED         (LIBAVCODEC_VERSION_MAJOR < 61)
 
 // reminder to remove CrystalHD decoders on next major bump
 #define FF_CODEC_CRYSTAL_HD        (LIBAVCODEC_VERSION_MAJOR < 61)
-- 
2.40.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".

             reply	other threads:[~2023-07-09 12:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 12:57 Anton Khirnov [this message]
2023-07-12 12:42 ` James Almer
2023-07-12 13:14   ` Gyan Doshi
2023-07-12 13:21     ` James Almer
2023-07-12 13:31       ` Gyan Doshi
2023-07-12 13:44         ` Anton Khirnov
2023-07-13 19:20           ` Gyan Doshi
2023-07-13 20:57             ` Anton Khirnov
2023-07-13 10:56 ` Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230709125746.8054-1-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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