[FFmpeg-devel] [PATCH] lavc/dv: remove ff_dvvideo_init()

Anton Khirnov anton at khirnov.net
Thu Aug 25 13:10:33 EEST 2022


The function contains only two assignments, setting DVVideoContext.avctx
and AVCodecContext.chroma_sample_location. However, the decoder does not
use the former, and the encoder should not be setting the latter.

Therefore move the first assignment to dvenc and the second to dvdec.
Make the encoder warn if the user-signalled chroma sample location does
not match the supported one, and return an error on higher compliance
levels.
---
 libavcodec/dv.c         | 10 ----------
 libavcodec/dv.h         |  2 --
 libavcodec/dvdec.c      |  4 +++-
 libavcodec/dvenc.c      | 12 +++++++++++-
 tests/ref/lavf/mxf_dv25 |  2 +-
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index e2550c4cc1..9e05aa8927 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -184,13 +184,3 @@ int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
 
     return 0;
 }
-
-av_cold int ff_dvvideo_init(AVCodecContext *avctx)
-{
-    DVVideoContext *s = avctx->priv_data;
-
-    s->avctx = avctx;
-    avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
-
-    return 0;
-}
diff --git a/libavcodec/dv.h b/libavcodec/dv.h
index 331b8e846a..2b082d0140 100644
--- a/libavcodec/dv.h
+++ b/libavcodec/dv.h
@@ -97,8 +97,6 @@ enum dv_pack_type {
 
 int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d);
 
-int ff_dvvideo_init(AVCodecContext *avctx);
-
 static inline int dv_work_pool_size(const AVDVProfile *d)
 {
     int size = d->n_difchan * d->difseg_size * 27;
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index bad8419925..daee2347e6 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -240,6 +240,8 @@ static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
     DVVideoContext *s = avctx->priv_data;
     int i;
 
+    avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
+
     ff_idctdsp_init(&s->idsp, avctx);
 
     for (i = 0; i < 64; i++)
@@ -258,7 +260,7 @@ static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
 
     ff_thread_once(&init_static_once, dv_init_static);
 
-    return ff_dvvideo_init(avctx);
+    return 0;
 }
 
 /* decode AC coefficients */
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 5ba4de3213..b2df976a26 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -55,6 +55,16 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
     PixblockDSPContext pdsp;
     int ret;
 
+    s->avctx = avctx;
+
+    if (avctx->chroma_sample_location != AVCHROMA_LOC_TOPLEFT) {
+        const char *name = av_chroma_location_name(avctx->chroma_sample_location);
+        av_log(avctx, AV_LOG_WARNING, "Only top-left chroma location is supported "
+               "in DV, input value is: %s\n", name ? name : "unknown");
+        if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL)
+            return AVERROR(EINVAL);
+    }
+
     s->sys = av_dv_codec_profile2(avctx->width, avctx->height, avctx->pix_fmt, avctx->time_base);
     if (!s->sys) {
         av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video. "
@@ -91,7 +101,7 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
     }
 #endif
 
-    return ff_dvvideo_init(avctx);
+    return 0;
 }
 
 /* bit budget for AC only in 5 MBs */
diff --git a/tests/ref/lavf/mxf_dv25 b/tests/ref/lavf/mxf_dv25
index 5022f1f62d..95a58906a0 100644
--- a/tests/ref/lavf/mxf_dv25
+++ b/tests/ref/lavf/mxf_dv25
@@ -1,3 +1,3 @@
-3339def72599c79ad5860c6860cc3123 *tests/data/lavf/lavf.mxf_dv25
+59d632e097e6f45c28445b2ab862ffe8 *tests/data/lavf/lavf.mxf_dv25
 3834413 tests/data/lavf/lavf.mxf_dv25
 tests/data/lavf/lavf.mxf_dv25 CRC=0xbdaf7f52
-- 
2.35.1



More information about the ffmpeg-devel mailing list