[FFmpeg-devel] [PATCH 4/4] avcodec: deprecate AVCodecContext properties

Marton Balint cus at passwd.hu
Sun Dec 15 02:02:45 EET 2024


These properties are unreliable because they depend on the frames decoded so
far, users should check directly the presence of the decoded AVFrame side data
or AVFrame flags.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 doc/APIchanges             | 3 +++
 libavcodec/av1dec.c        | 8 ++++++++
 libavcodec/avcodec.c       | 4 ++++
 libavcodec/avcodec.h       | 3 +++
 libavcodec/h2645_sei.c     | 8 ++++++++
 libavcodec/hevc/hevcdec.c  | 8 ++++++++
 libavcodec/jpeg2000dec.c   | 4 ++++
 libavcodec/libdav1d.c      | 8 ++++++++
 libavcodec/mjpegdec.c      | 8 ++++++++
 libavcodec/mpeg12dec.c     | 4 ++++
 libavcodec/pthread_frame.c | 4 ++++
 libavcodec/version.h       | 2 +-
 libavcodec/version_major.h | 1 +
 libavcodec/vp9.c           | 4 ++++
 libavcodec/webp.c          | 4 ++++
 libavformat/dump.c         | 4 ++++
 16 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index bfba0946d3..52850d2cd4 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-12-xx - xxxxxxxxxx - lavc 61.28.100 - frame.h
+  Deprecate AVCodecContext->properties.
+
 2024-12-xx - xxxxxxxxxx - lavc 61.27.100 - frame.h
   Add AV_FRAME_FLAG_LOSSLESS.
 
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index bc4ef63e68..93551d9d7b 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -788,10 +788,14 @@ static int set_context_with_sequence(AVCodecContext *avctx,
         break;
     }
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
     if (seq->film_grain_params_present)
         avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
     else
         avctx->properties &= ~FF_CODEC_PROPERTY_FILM_GRAIN;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (avctx->width != width || avctx->height != height) {
         int ret = ff_set_dimensions(avctx, width, height);
@@ -983,7 +987,11 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame,
             if (ret < 0)
                 return ret;
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
             avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             break;
         }
         default: // ignore unsupported identifiers
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 1fa8704c9d..89001158ca 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -647,12 +647,16 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
         if (encode) {
             av_bprintf(&bprint, ", q=%d-%d", enc->qmin, enc->qmax);
         } else {
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
             if (enc->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS)
                 av_bprintf(&bprint, ", Closed Captions");
             if (enc->properties & FF_CODEC_PROPERTY_FILM_GRAIN)
                 av_bprintf(&bprint, ", Film Grain");
             if (enc->properties & FF_CODEC_PROPERTY_LOSSLESS)
                 av_bprintf(&bprint, ", lossless");
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         }
         break;
     case AVMEDIA_TYPE_AUDIO:
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 77ca8dee1f..cc6317075a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1798,15 +1798,18 @@ typedef struct AVCodecContext {
 #define FF_LEVEL_UNKNOWN -99
 #endif
 
+#if FF_API_CODEC_PROPS
     /**
      * Properties of the stream that gets decoded
      * - encoding: unused
      * - decoding: set by libavcodec
      */
+    attribute_deprecated
     unsigned properties;
 #define FF_CODEC_PROPERTY_LOSSLESS        0x00000001
 #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002
 #define FF_CODEC_PROPERTY_FILM_GRAIN      0x00000004
+#endif
 
     /**
      * Skip loop filtering for selected frames.
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 986d1d250a..d7a5a84790 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -807,7 +807,11 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
         if (!sd)
             av_buffer_unref(&a53->buf_ref);
         a53->buf_ref = NULL;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     }
 
     ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data);
@@ -900,7 +904,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
         else
             fgc->present = fgc->persistence_flag;
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     }
 
 #if CONFIG_HEVC_SEI
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index be35a9de82..8fbfc19ca3 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -403,8 +403,12 @@ static int export_stream_params_from_sei(HEVCContext *s)
 {
     AVCodecContext *avctx = s->avctx;
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
     if (s->sei.common.a53_caption.buf_ref)
         s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (s->sei.common.alternative_transfer.present &&
         av_color_transfer_name(s->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
@@ -412,9 +416,13 @@ static int export_stream_params_from_sei(HEVCContext *s)
         avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
     }
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
     if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
         s->sei.common.aom_film_grain.enable)
         avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     return 0;
 }
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index df13bea815..e5e897a29f 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -542,9 +542,13 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
     /* set integer 9/7 DWT in case of BITEXACT flag */
     if ((s->avctx->flags & AV_CODEC_FLAG_BITEXACT) && (c->transform == FF_DWT97))
         c->transform = FF_DWT97_INT;
+#if FF_API_CODEC_PROPS
     else if (c->transform == FF_DWT53) {
+FF_DISABLE_DEPRECATION_WARNINGS
         s->avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+FF_ENABLE_DEPRECATION_WARNINGS
     }
+#endif
 
     if (c->csty & JPEG2000_CSTY_PREC) {
         int i;
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 546b42e9c6..4d9ac12eb7 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -162,10 +162,14 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
                                     (unsigned)seq->num_units_in_tick,
                                     (unsigned)seq->time_scale);
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
    if (seq->film_grain_present)
        c->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
    else
        c->properties &= ~FF_CODEC_PROPERTY_FILM_GRAIN;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
 
 static av_cold int libdav1d_parse_extradata(AVCodecContext *c)
@@ -532,7 +536,11 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
                 if (res < 0)
                     goto fail;
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
                 c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
                 break;
             }
             default: // ignore unsupported identifiers
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index fefa5e7877..bd1b502e50 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2508,7 +2508,11 @@ redo_for_pal8:
             break;
         case SOF3:
             avctx->profile     = AV_PROFILE_MJPEG_HUFFMAN_LOSSLESS;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
             avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             s->lossless    = 1;
             s->ls          = 0;
             s->progressive = 0;
@@ -2517,7 +2521,11 @@ redo_for_pal8:
             break;
         case SOF48:
             avctx->profile     = AV_PROFILE_MJPEG_JPEG_LS;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
             avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             s->lossless    = 1;
             s->ls          = 1;
             s->progressive = 0;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 208ee28b04..bbcaa71e2e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1919,7 +1919,11 @@ static void mpeg_set_cc_format(AVCodecContext *avctx, enum Mpeg2ClosedCaptionsFo
         av_log(avctx, AV_LOG_DEBUG, "CC: first seen substream is %s format\n", label);
     }
 
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
     avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
 
 static int mpeg_decode_a53_cc(AVCodecContext *avctx,
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 1b1b96623f..b027aa8991 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -365,7 +365,11 @@ static int update_context_from_thread(AVCodecContext *dst, const AVCodecContext
 
         dst->has_b_frames = src->has_b_frames;
         dst->idct_algo    = src->idct_algo;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
         dst->properties   = src->properties;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
         dst->bits_per_coded_sample = src->bits_per_coded_sample;
         dst->sample_aspect_ratio   = src->sample_aspect_ratio;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 735c8b813c..87b7284a95 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  27
+#define LIBAVCODEC_VERSION_MINOR  28
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h
index 86f4218b65..35df5eb779 100644
--- a/libavcodec/version_major.h
+++ b/libavcodec/version_major.h
@@ -49,6 +49,7 @@
 #define FF_API_VDPAU_ALLOC_GET_SET (LIBAVCODEC_VERSION_MAJOR < 62)
 #define FF_API_QUALITY_FACTOR      (LIBAVCODEC_VERSION_MAJOR < 62)
 #define FF_API_V408_CODECID        (LIBAVCODEC_VERSION_MAJOR < 62)
+#define FF_API_CODEC_PROPS         (LIBAVCODEC_VERSION_MAJOR < 63)
 
 // reminder to remove the OMX encoder on next major bump
 #define FF_CODEC_OMX               (LIBAVCODEC_VERSION_MAJOR < 62)
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index b4b6fd933d..712938065e 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -682,8 +682,12 @@ static int decode_frame_header(AVCodecContext *avctx,
     s->s.h.uvac_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
     s->s.h.lossless    = s->s.h.yac_qi == 0 && s->s.h.ydc_qdelta == 0 &&
                        s->s.h.uvdc_qdelta == 0 && s->s.h.uvac_qdelta == 0;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
     if (s->s.h.lossless)
         avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     /* segmentation header info */
     if ((s->s.h.segmentation.enabled = get_bits1(&s->gb))) {
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index a965e50ac4..9f83b518ad 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1407,7 +1407,11 @@ static int webp_decode_frame(AVCodecContext *avctx, AVFrame *p,
                                                 chunk_size, 0);
                 if (ret < 0)
                     return ret;
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
                 avctx->properties |= FF_CODEC_PROPERTY_LOSSLESS;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             }
             bytestream2_skip(&gb, chunk_size);
             break;
diff --git a/libavformat/dump.c b/libavformat/dump.c
index b7125a652f..4eb0ff803d 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -620,7 +620,11 @@ static void dump_stream_format(const AVFormatContext *ic, int i,
 
     // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
     if (sti->avctx) {
+#if FF_API_CODEC_PROPS
+FF_DISABLE_DEPRECATION_WARNINGS
         avctx->properties   = sti->avctx->properties;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         avctx->codec        = sti->avctx->codec;
         avctx->qmin         = sti->avctx->qmin;
         avctx->qmax         = sti->avctx->qmax;
-- 
2.43.0



More information about the ffmpeg-devel mailing list