[x264-devel] [PATCH 30/32] Modify configure to enable selecting bitdepth at build time

Vittorio Giovara vittorio.giovara at gmail.com
Fri Jan 20 15:20:55 CET 2017


Behaviour is changed so that opencl is always disabled unless explicitly
set, which would force 8 bitdepth only.

X264_BIT_DEPTH symbol is dropped as unneeded any more.
---
 Makefile              | 18 +++++++++++++++++-
 common/api.c          |  4 ++++
 configure             | 27 +++++++++++++++++++--------
 filters/video/video.c |  8 ++++++--
 x264.c                | 25 ++++++++++++++++++++-----
 5 files changed, 66 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index 1a74b86..b1844f0 100644
--- a/Makefile
+++ b/Makefile
@@ -106,8 +106,12 @@ ifdef ARCH_X86
 SRCS   += common/x86/mc-c.c common/x86/predict-c.c
 
 OBJASM += $(ASMSRCCOMMON:%.asm=%.o)
+ifneq ($(findstring HAVE_BITDEPTH8, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.asm=8bit/%.o) $(ASMSRC8:%.asm=8bit/%.o)
+endif
+ifneq ($(findstring HAVE_BITDEPTH10, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.asm=10bit/%.o) $(ASMSRC10:%.asm=10bit/%.o)
+endif
 
 $(OBJASM): common/x86/x86inc.asm common/x86/x86util.asm
 OBJCHK += tools/checkasm-a.o
@@ -131,8 +135,12 @@ ASMSRC += common/arm/cpu-a.S common/arm/pixel-a.S common/arm/mc-a.S \
           common/arm/predict-a.S common/arm/bitstream-a.S
 SRCS   += common/arm/mc-c.c common/arm/predict-c.c
 
+ifneq ($(findstring HAVE_BITDEPTH8, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.S=8bit/%.o)
+endif
+ifneq ($(findstring HAVE_BITDEPTH10, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.S=10bit/%.o)
+endif
 
 OBJCHK += tools/checkasm-arm.o
 endif
@@ -153,8 +161,12 @@ SRCS   += common/aarch64/asm-offsets.c \
           common/aarch64/mc-c.c        \
           common/aarch64/predict-c.c
 
+ifneq ($(findstring HAVE_BITDEPTH8, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.S=8bit/%.o)
+endif
+ifneq ($(findstring HAVE_BITDEPTH10, $(CONFIG)),)
 OBJASM += $(ASMSRC:%.S=10bit/%.o)
+endif
 
 OBJCHK += tools/checkasm-aarch64.o
 endif
@@ -199,10 +211,14 @@ OBJS   += $(SRCSCOMMON:%.c=%.o)
 OBJCLI += $(SRCCLI:%.c=%.o)
 OBJSO  += $(SRCSO:%.c=%.o)
 
+ifneq ($(findstring HAVE_BITDEPTH8, $(CONFIG)),)
 OBJS += $(SRCS:%.c=8bit/%.o)
-OBJS += $(SRCS:%.c=10bit/%.o)
 OBJCLI += $(SRCCLIBD:%.c=8bit/%.o)
+endif
+ifneq ($(findstring HAVE_BITDEPTH10, $(CONFIG)),)
+OBJS += $(SRCS:%.c=10bit/%.o)
 OBJCLI += $(SRCCLIBD:%.c=10bit/%.o)
+endif
 
 .PHONY: all default fprofiled clean distclean install install-* uninstall cli lib-* etags
 
diff --git a/common/api.c b/common/api.c
index e461850..8fff5c4 100644
--- a/common/api.c
+++ b/common/api.c
@@ -85,6 +85,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
         return NULL;
 
     if( param->i_bitdepth == 0 || param->i_bitdepth == 8 ) {
+#if HAVE_BITDEPTH8
         api->x264_encoder_reconfig = x264_8_encoder_reconfig;
         api->x264_encoder_parameters = x264_8_encoder_parameters;
         api->x264_encoder_headers = x264_8_encoder_headers;
@@ -96,7 +97,9 @@ x264_t *x264_encoder_open( x264_param_t *param )
         api->x264_encoder_invalidate_reference = x264_8_encoder_invalidate_reference;
 
         api->x264 = x264_8_encoder_open( param );
+#endif
     } else if( param->i_bitdepth == 10 ) {
+#if HAVE_BITDEPTH10
         api->x264_encoder_reconfig = x264_10_encoder_reconfig;
         api->x264_encoder_parameters = x264_10_encoder_parameters;
         api->x264_encoder_headers = x264_10_encoder_headers;
@@ -108,6 +111,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
         api->x264_encoder_invalidate_reference = x264_10_encoder_invalidate_reference;
 
         api->x264 = x264_10_encoder_open( param );
+#endif
     }
 
     if( !api->x264 ) {
diff --git a/configure b/configure
index 722a948..fee9ee9 100755
--- a/configure
+++ b/configure
@@ -25,12 +25,12 @@ Configuration options:
   --system-libx264         use system libx264 instead of internal
   --enable-shared          build shared library
   --enable-static          build static library
-  --disable-opencl         disable OpenCL features
+  --enable-opencl          enable OpenCL features (forces 8bpp)
   --disable-gpl            disable GPL-only features
   --disable-thread         disable multithreaded encoding
   --disable-win32thread    disable win32threads (windows only)
   --disable-interlaced     disable interlaced encoding support
-  --bit-depth=BIT_DEPTH    set output bit depth (8-10) [8]
+  --bit-depth=BIT_DEPTH    set output bit depth (8 or 10) [auto]
   --chroma-format=FORMAT   output chroma format (420, 422, 444, all) [all]
 
 Advanced options:
@@ -351,11 +351,11 @@ debug="no"
 gprof="no"
 strip="no"
 pic="no"
-bit_depth="8"
+bit_depth=0
 chroma_format="all"
 compiler="GNU"
 compiler_style="GNU"
-opencl="yes"
+opencl="no"
 vsx="auto"
 
 CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
@@ -480,6 +480,10 @@ for opt do
         --disable-opencl)
             opencl="no"
             ;;
+        --enable-opencl)
+            opencl="yes"
+            bit_depth=8
+            ;;
         --cross-prefix=*)
             cross_prefix="$optarg"
             ;;
@@ -489,8 +493,8 @@ for opt do
             ;;
         --bit-depth=*)
             bit_depth="$optarg"
-            if [ "$bit_depth" -lt "8" -o "$bit_depth" -gt "10" ]; then
-                echo "Supplied bit depth must be in range [8,10]."
+            if [ "$bit_depth" -ne "0" -a "$bit_depth" -ne "8" -a "$bit_depth" -ne "10" ]; then
+                echo "Supplied bit depth must be 8 or 10."
                 exit 1
             fi
             bit_depth=`expr $bit_depth + 0`
@@ -1244,7 +1248,15 @@ if [ $compiler = ICC -o $compiler = ICL ] ; then
     fi
 fi
 
-if [ "$bit_depth" -gt "8" ]; then
+if [ "$bit_depth" -eq "0" ]; then
+    define HAVE_BITDEPTH8
+    define HAVE_BITDEPTH10
+    bit_depth="8 and 10"
+    opencl="no"
+elif [ "$bit_depth" -eq "8" ]; then
+    define HAVE_BITDEPTH8
+elif [ "$bit_depth" -eq "10" ]; then
+    define HAVE_BITDEPTH10
     opencl="no"
 fi
 
@@ -1281,7 +1293,6 @@ done
 config_chroma_format="X264_CSP_I$chroma_format"
 [ "$config_chroma_format" == "X264_CSP_Iall" ] && config_chroma_format="0"
 cat > x264_config.h << EOF
-#define X264_BIT_DEPTH     $bit_depth
 #define X264_GPL           $x264_gpl
 #define X264_INTERLACED    $x264_interlaced
 #define X264_CHROMA_FORMAT $config_chroma_format
diff --git a/filters/video/video.c b/filters/video/video.c
index b555c43..949e6a8 100644
--- a/filters/video/video.c
+++ b/filters/video/video.c
@@ -46,14 +46,18 @@ void x264_register_vid_filters( void )
 {
     extern cli_vid_filter_t source_filter;
     first_filter = &source_filter;
+#if HAVE_BITDEPTH8
     REGISTER_VFILTER( cache_8 );
+    REGISTER_VFILTER( depth_8 );
+#endif
+#if HAVE_BITDEPTH10
     REGISTER_VFILTER( cache_10 );
+    REGISTER_VFILTER( depth_10 );
+#endif
     REGISTER_VFILTER( crop );
     REGISTER_VFILTER( fix_vfr_pts );
     REGISTER_VFILTER( resize );
     REGISTER_VFILTER( select_every );
-    REGISTER_VFILTER( depth_8 );
-    REGISTER_VFILTER( depth_10 );
 #if HAVE_GPL
 #endif
 }
diff --git a/x264.c b/x264.c
index 376ebbb..92b5a60 100644
--- a/x264.c
+++ b/x264.c
@@ -339,8 +339,8 @@ static void print_version_info( void )
 #else
     printf( "using an unknown compiler\n" );
 #endif
-    printf( "x264 configuration: --bit-depth=%d --chroma-format=%s\n", X264_BIT_DEPTH, chroma_format_names[X264_CHROMA_FORMAT] );
-    printf( "libx264 configuration: --bit-depth=%d --chroma-format=%s\n", x264_bit_depth, chroma_format_names[x264_chroma_format] );
+    printf( "x264 configuration: --chroma-format=%s\n", chroma_format_names[X264_CHROMA_FORMAT] );
+    printf( "libx264 configuration:--chroma-format=%s\n", chroma_format_names[x264_chroma_format] );
     printf( "x264 license: " );
 #if HAVE_GPL
     printf( "GPL version 2 or later\n" );
@@ -491,7 +491,7 @@ static void help( x264_param_t *defaults, int longhelp )
         " .mkv -> Matroska\n"
         " .flv -> Flash Video\n"
         " .mp4 -> MP4 if compiled with GPAC or L-SMASH support (%s)\n"
-        "Output bit depth: %d (configured at compile time)\n"
+        "Output bit depth: %s\n"
         "\n"
         "Options:\n"
         "\n"
@@ -522,7 +522,12 @@ static void help( x264_param_t *defaults, int longhelp )
 #else
         "no",
 #endif
-        x264_bit_depth
+#if HAVE_BITDEPTH8
+        "8 "
+#endif
+#if HAVE_BITDEPTH10
+        "10"
+#endif
       );
     H0( "Example usage:\n" );
     H0( "\n" );
@@ -1637,7 +1642,17 @@ generic_option:
 
     /* init threaded input while the information about the input video is unaltered by filtering */
 #if HAVE_THREAD
-    cli_input_t thread_input = param->i_bitdepth == 8 ? thread_8_input : thread_10_input;
+    cli_input_t thread_input;
+    if (param->i_bitdepth == 8) {
+#if HAVE_BITDEPTH8
+        thread_input = thread_8_input;
+#endif
+    } else {
+#if HAVE_BITDEPTH10
+        thread_input = thread_10_input;
+#endif
+    }
+
     if( info.thread_safe && (b_thread_input || param->i_threads > 1
         || (param->i_threads == X264_THREADS_AUTO && x264_cpu_num_processors() > 1)) )
     {
-- 
2.10.0



More information about the x264-devel mailing list