LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File fix-x264-multibitdepth.patch of Package ffmpeg (Project home:smarty12:kodi:next)

From 89f704cabab446afc8ba6ecea76714a51b1df32b Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Mon, 25 Dec 2017 19:40:42 -0300
Subject: [PATCH] avcodec/libx264: use the pixfmt descriptor to check for high
 bit depths

The x264_bit_depth constant has been removed in newer x264 builds.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libx264.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e2455e18dec..2d36c5e5666 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -272,6 +272,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                       int *got_packet)
 {
     X264Context *x4 = ctx->priv_data;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(ctx->pix_fmt);
     x264_nal_t *nal;
     int nnal, i, ret;
     x264_picture_t pic_out = {0};
@@ -279,7 +280,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
 
     x264_picture_init( &x4->pic );
     x4->pic.img.i_csp   = x4->params.i_csp;
-    if (x264_bit_depth > 8)
+    if (desc->comp[0].depth > 8)
         x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
     x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
 
From 2a111c99a60fdf4fe5eea2b073901630190c6c93 Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Mon, 25 Dec 2017 19:41:09 -0300
Subject: [PATCH] avcodec/libx264: fix compilation with x264 builds >= 153

x264 now supports multibitdepth builds, with a slightly changed API to
request bitdepth during initialization.

Reviewed-by: Ricardo Constantino <wiiaboo@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libx264.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2d36c5e5666..754383e080d 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -724,6 +724,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
     x4->params.i_width          = avctx->width;
     x4->params.i_height         = avctx->height;
+#if X264_BUILD >= 153
+    x4->params.i_bitdepth       = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
+#endif
     av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
     x4->params.vui.i_sar_width  = sw;
     x4->params.vui.i_sar_height = sh;
@@ -837,6 +840,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
     return 0;
 }
 
+static const enum AVPixelFormat pix_fmts[] = {
+    AV_PIX_FMT_YUV420P,
+    AV_PIX_FMT_YUVJ420P,
+    AV_PIX_FMT_YUV422P,
+    AV_PIX_FMT_YUVJ422P,
+    AV_PIX_FMT_YUV444P,
+    AV_PIX_FMT_YUVJ444P,
+    AV_PIX_FMT_YUV420P10,
+    AV_PIX_FMT_YUV422P10,
+    AV_PIX_FMT_YUV444P10,
+    AV_PIX_FMT_NV12,
+    AV_PIX_FMT_NV16,
+    AV_PIX_FMT_NV20,
+#ifdef X264_CSP_NV21
+    AV_PIX_FMT_NV21,
+#endif
+    AV_PIX_FMT_NONE
+};
 static const enum AVPixelFormat pix_fmts_8bit[] = {
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_YUVJ420P,
@@ -874,12 +895,14 @@ static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
 
 static av_cold void X264_init_static(AVCodec *codec)
 {
-    if (x264_bit_depth == 8)
+    if (X264_BIT_DEPTH == 8)
         codec->pix_fmts = pix_fmts_8bit;
-    else if (x264_bit_depth == 9)
+    else if (X264_BIT_DEPTH == 9)
         codec->pix_fmts = pix_fmts_9bit;
-    else if (x264_bit_depth == 10)
+    else if (X264_BIT_DEPTH == 10)
         codec->pix_fmts = pix_fmts_10bit;
+    else /* X264_BIT_DEPTH == 0 */
+        codec->pix_fmts = pix_fmts;
 }
 
 #define OFFSET(x) offsetof(X264Context, x)
From 7e60c74329353db28db00552028bc88cd2a52346 Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Tue, 26 Dec 2017 19:40:27 -0300
Subject: [PATCH] avcodec/libx264: set supported pix_fmts at runtime rather
 than build time

This partially reverts a change in behavior introduced in 2a111c99a60fdf4fe5eea2b073901630190c6c93.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libx264.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 754383e080d..0e714f16152 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -895,14 +895,16 @@ static const enum AVPixelFormat pix_fmts_8bit_rgb[] = {
 
 static av_cold void X264_init_static(AVCodec *codec)
 {
-    if (X264_BIT_DEPTH == 8)
+#if X264_BUILD < 153
+    if (x264_bit_depth == 8)
         codec->pix_fmts = pix_fmts_8bit;
-    else if (X264_BIT_DEPTH == 9)
+    else if (x264_bit_depth == 9)
         codec->pix_fmts = pix_fmts_9bit;
-    else if (X264_BIT_DEPTH == 10)
+    else if (x264_bit_depth == 10)
         codec->pix_fmts = pix_fmts_10bit;
-    else /* X264_BIT_DEPTH == 0 */
-        codec->pix_fmts = pix_fmts;
+#else
+    codec->pix_fmts = pix_fmts;
+#endif
 }
 
 #define OFFSET(x) offsetof(X264Context, x)
From c6558e8840fbb2386bf8742e4d68dd6e067d262e Mon Sep 17 00:00:00 2001
From: Luca Barbato <lu_zero@gentoo.org>
Date: Tue, 26 Dec 2017 12:32:42 +0100
Subject: [PATCH] x264: Support version 153

It has native simultaneus 8 and 10 bit support.
---
 libavcodec/libx264.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 0e714f16152..12379ff7636 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -272,7 +272,6 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                       int *got_packet)
 {
     X264Context *x4 = ctx->priv_data;
-    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(ctx->pix_fmt);
     x264_nal_t *nal;
     int nnal, i, ret;
     x264_picture_t pic_out = {0};
@@ -280,7 +279,11 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
 
     x264_picture_init( &x4->pic );
     x4->pic.img.i_csp   = x4->params.i_csp;
-    if (desc->comp[0].depth > 8)
+#if X264_BUILD >= 153
+    if (x4->params.i_bitdepth > 8)
+#else
+    if (x264_bit_depth > 8)
+#endif
         x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
     x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
 
@@ -491,6 +494,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
     x4->params.p_log_private        = avctx;
     x4->params.i_log_level          = X264_LOG_DEBUG;
     x4->params.i_csp                = convert_pix_fmt(avctx->pix_fmt);
+#if X264_BUILD >= 153
+    x4->params.i_bitdepth           = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
+#endif
 
     PARSE_X264_OPT("weightp", wpredp);
 
@@ -724,9 +730,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
     x4->params.i_width          = avctx->width;
     x4->params.i_height         = avctx->height;
-#if X264_BUILD >= 153
-    x4->params.i_bitdepth       = av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;
-#endif
     av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
     x4->params.vui.i_sar_width  = sw;
     x4->params.vui.i_sar_height = sh;
@@ -840,25 +843,33 @@ FF_ENABLE_DEPRECATION_WARNINGS
     return 0;
 }
 
-static const enum AVPixelFormat pix_fmts[] = {
+static const enum AVPixelFormat pix_fmts_8bit[] = {
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_YUVJ420P,
     AV_PIX_FMT_YUV422P,
     AV_PIX_FMT_YUVJ422P,
     AV_PIX_FMT_YUV444P,
     AV_PIX_FMT_YUVJ444P,
-    AV_PIX_FMT_YUV420P10,
-    AV_PIX_FMT_YUV422P10,
-    AV_PIX_FMT_YUV444P10,
     AV_PIX_FMT_NV12,
     AV_PIX_FMT_NV16,
-    AV_PIX_FMT_NV20,
 #ifdef X264_CSP_NV21
     AV_PIX_FMT_NV21,
 #endif
     AV_PIX_FMT_NONE
 };
-static const enum AVPixelFormat pix_fmts_8bit[] = {
+static const enum AVPixelFormat pix_fmts_9bit[] = {
+    AV_PIX_FMT_YUV420P9,
+    AV_PIX_FMT_YUV444P9,
+    AV_PIX_FMT_NONE
+};
+static const enum AVPixelFormat pix_fmts_10bit[] = {
+    AV_PIX_FMT_YUV420P10,
+    AV_PIX_FMT_YUV422P10,
+    AV_PIX_FMT_YUV444P10,
+    AV_PIX_FMT_NV20,
+    AV_PIX_FMT_NONE
+};
+static const enum AVPixelFormat pix_fmts_all[] = {
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_YUVJ420P,
     AV_PIX_FMT_YUV422P,
@@ -870,14 +881,6 @@ static const enum AVPixelFormat pix_fmts_8bit[] = {
 #ifdef X264_CSP_NV21
     AV_PIX_FMT_NV21,
 #endif
-    AV_PIX_FMT_NONE
-};
-static const enum AVPixelFormat pix_fmts_9bit[] = {
-    AV_PIX_FMT_YUV420P9,
-    AV_PIX_FMT_YUV444P9,
-    AV_PIX_FMT_NONE
-};
-static const enum AVPixelFormat pix_fmts_10bit[] = {
     AV_PIX_FMT_YUV420P10,
     AV_PIX_FMT_YUV422P10,
     AV_PIX_FMT_YUV444P10,
@@ -903,7 +906,7 @@ static av_cold void X264_init_static(AVCodec *codec)
     else if (x264_bit_depth == 10)
         codec->pix_fmts = pix_fmts_10bit;
 #else
-    codec->pix_fmts = pix_fmts;
+    codec->pix_fmts = pix_fmts_all;
 #endif
 }