diff mbox series

[FFmpeg-devel,2/4] avcodec/libx264: Don't use init_static_data for newer versions

Message ID 20210225140505.1249855-2-andreas.rheinhardt@gmail.com
State Accepted
Commit f9b5cef1d3cdb361893c88f6b626ef767fe6cee4
Headers show
Series [FFmpeg-devel,1/4] avformat/wavenc: Improve unsupported codec error messages
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 25, 2021, 2:05 p.m. UTC
x264 versions >= 153 can support multiple bitdepths; they also don't
export x264_bit_depth any more. The actual check whether a bitdepth
is supported is therefore performed at runtime in x264_encoder_open.
Ergo it is unnecessary to use init_static_data for these versions:
One can already set ff_libx264_encoder.pix_fmts to the value that
X264_init_static always sets it to.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
The actual aim is of course to enable to make ff_libx264_encoder const
after the next major bump if a new libx264 version is used. I am
currently working on this.

 libavcodec/libx264.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt Feb. 27, 2021, 7:45 a.m. UTC | #1
Andreas Rheinhardt:
> x264 versions >= 153 can support multiple bitdepths; they also don't
> export x264_bit_depth any more. The actual check whether a bitdepth
> is supported is therefore performed at runtime in x264_encoder_open.
> Ergo it is unnecessary to use init_static_data for these versions:
> One can already set ff_libx264_encoder.pix_fmts to the value that
> X264_init_static always sets it to.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> The actual aim is of course to enable to make ff_libx264_encoder const
> after the next major bump if a new libx264 version is used. I am
> currently working on this.
> 
>  libavcodec/libx264.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index ca7cc3a540..212ed7d015 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1051,19 +1051,17 @@ static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
>  };
>  #endif
>  
> +#if X264_BUILD < 153
>  static av_cold void X264_init_static(AVCodec *codec)
>  {
> -#if X264_BUILD < 153
>      if (x264_bit_depth == 8)
>          codec->pix_fmts = pix_fmts_8bit;
>      else if (x264_bit_depth == 9)
>          codec->pix_fmts = pix_fmts_9bit;
>      else if (x264_bit_depth == 10)
>          codec->pix_fmts = pix_fmts_10bit;
> -#else
> -    codec->pix_fmts = pix_fmts_all;
> -#endif
>  }
> +#endif
>  
>  #define OFFSET(x) offsetof(X264Context, x)
>  #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> @@ -1208,7 +1206,11 @@ AVCodec ff_libx264_encoder = {
>                          AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
>      .priv_class       = &x264_class,
>      .defaults         = x264_defaults,
> +#if X264_BUILD < 153
>      .init_static_data = X264_init_static,
> +#else
> +    .pix_fmts         = pix_fmts_all,
> +#endif
>  #if X264_BUILD >= 158
>      .caps_internal    = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
>  #else
> 
Will apply the remaining two patches of this patchset tomorrow unless
there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index ca7cc3a540..212ed7d015 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1051,19 +1051,17 @@  static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
 };
 #endif
 
+#if X264_BUILD < 153
 static av_cold void X264_init_static(AVCodec *codec)
 {
-#if X264_BUILD < 153
     if (x264_bit_depth == 8)
         codec->pix_fmts = pix_fmts_8bit;
     else if (x264_bit_depth == 9)
         codec->pix_fmts = pix_fmts_9bit;
     else if (x264_bit_depth == 10)
         codec->pix_fmts = pix_fmts_10bit;
-#else
-    codec->pix_fmts = pix_fmts_all;
-#endif
 }
+#endif
 
 #define OFFSET(x) offsetof(X264Context, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
@@ -1208,7 +1206,11 @@  AVCodec ff_libx264_encoder = {
                         AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_class       = &x264_class,
     .defaults         = x264_defaults,
+#if X264_BUILD < 153
     .init_static_data = X264_init_static,
+#else
+    .pix_fmts         = pix_fmts_all,
+#endif
 #if X264_BUILD >= 158
     .caps_internal    = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 #else