[x264-devel] [PATCH 27/32] x264cli: Duplicate depth and cache filters

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


This filters heavily depend on bit depth size, so they need to be
duplicated for each value. This means having to rename these filters,
and adjust the callers to use the right version.

Remove any X264_BIT_DEPTH use from the depth filter, and always use the
passed BIT_DEPTH symbol to always use the correct size.
---
 Makefile                     |  8 ++++++--
 filters/video/cache.c        | 10 ++++++++--
 filters/video/depth.c        | 20 +++++++++++++-------
 filters/video/select_every.c |  4 +++-
 filters/video/video.c        |  6 ++++--
 5 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 908599c..07da1b4 100644
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,10 @@ SRCCLI = x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
          output/raw.c output/matroska.c output/matroska_ebml.c \
          output/flv.c output/flv_bytestream.c filters/filters.c \
          filters/video/video.c filters/video/source.c filters/video/internal.c \
-         filters/video/resize.c filters/video/cache.c filters/video/fix_vfr_pts.c \
-         filters/video/select_every.c filters/video/crop.c filters/video/depth.c
+         filters/video/resize.c filters/video/fix_vfr_pts.c \
+         filters/video/select_every.c filters/video/crop.c
+
+SRCCLIBD = filters/video/depth.c filters/video/cache.c
 
 SRCSO =
 
@@ -199,6 +201,8 @@ OBJSO  += $(SRCSO:%.c=%.o)
 
 OBJS += $(SRCS:%.c=8bit/%.o)
 OBJS += $(SRCS:%.c=10bit/%.o)
+OBJCLI += $(SRCCLIBD:%.c=8bit/%.o)
+OBJCLI += $(SRCCLIBD:%.c=10bit/%.o)
 
 .PHONY: all default fprofiled clean distclean install install-* uninstall cli lib-* etags
 
diff --git a/filters/video/cache.c b/filters/video/cache.c
index 21bfba6..d585345 100644
--- a/filters/video/cache.c
+++ b/filters/video/cache.c
@@ -23,11 +23,17 @@
  * For more information, contact us at licensing at x264.com.
  *****************************************************************************/
 
+#include "common/common.h"
+
 #include "video.h"
 #include "internal.h"
-#include "common/common.h"
 
-#define NAME "cache"
+#define cache_filter x264_glue(cache_, BIT_DEPTH, _filter)
+#if BIT_DEPTH == 8
+#define NAME "depth_8"
+#else
+#define NAME "depth_10"
+#endif
 #define LAST_FRAME (h->first_frame + h->cur_size - 1)
 
 typedef struct
diff --git a/filters/video/depth.c b/filters/video/depth.c
index 4af1bf8..76b4f55 100644
--- a/filters/video/depth.c
+++ b/filters/video/depth.c
@@ -26,7 +26,13 @@
 #include "common/common.h"
 
 #include "video.h"
-#define NAME "depth"
+
+#define depth_filter x264_glue(depth_, BIT_DEPTH, _filter)
+#if BIT_DEPTH == 8
+#define NAME "depth_8"
+#else
+#define NAME "depth_10"
+#endif
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ )
 
 cli_vid_filter_t depth_filter;
@@ -76,10 +82,10 @@ static int csp_num_interleaved( int csp, int plane )
 static void dither_plane_##pitch( pixel *dst, int dst_stride, uint16_t *src, int src_stride, \
                                   int width, int height, int16_t *errors ) \
 { \
-    const int lshift = 16-X264_BIT_DEPTH; \
-    const int rshift = 16-X264_BIT_DEPTH+2; \
-    const int half = 1 << (16-X264_BIT_DEPTH+1); \
-    const int pixel_max = (1 << X264_BIT_DEPTH)-1; \
+    const int lshift = 16-BIT_DEPTH; \
+    const int rshift = 16-BIT_DEPTH+2; \
+    const int half = 1 << (16-BIT_DEPTH+1); \
+    const int pixel_max = (1 << BIT_DEPTH)-1; \
     memset( errors, 0, (width+1) * sizeof(int16_t) ); \
     for( int y = 0; y < height; y++, src += src_stride, dst += dst_stride ) \
     { \
@@ -139,7 +145,7 @@ static void dither_image( cli_image_t *out, cli_image_t *img, int16_t *error_buf
 static void scale_image( cli_image_t *output, cli_image_t *img )
 {
     int csp_mask = img->csp & X264_CSP_MASK;
-    const int shift = X264_BIT_DEPTH - 8;
+    const int shift = BIT_DEPTH - 8;
     for( int i = 0; i < img->planes; i++ )
     {
         uint8_t *src = img->plane[i];
@@ -219,7 +225,7 @@ static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info,
             ret = 1;
     }
 
-    FAIL_IF_ERROR( bit_depth != X264_BIT_DEPTH, "this build supports only bit depth %d\n", X264_BIT_DEPTH );
+    FAIL_IF_ERROR( bit_depth != BIT_DEPTH, "this filter supports only bit depth %d\n", BIT_DEPTH );
     FAIL_IF_ERROR( ret, "unsupported bit depth conversion.\n" );
 
     /* only add the filter to the chain if it's needed */
diff --git a/filters/video/select_every.c b/filters/video/select_every.c
index 9e84358..ed7dab7 100644
--- a/filters/video/select_every.c
+++ b/filters/video/select_every.c
@@ -97,7 +97,9 @@ static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x2
          if( max_rewind == h->step_size )
              break;
     }
-    if( x264_init_vid_filter( "cache", handle, filter, info, param, (void*)max_rewind ) )
+    char name[20];
+    sprintf( name, "cache_%d", param->i_bitdepth );
+    if( x264_init_vid_filter( name, handle, filter, info, param, (void*)max_rewind ) )
         return -1;
 
     /* done initing, overwrite properties */
diff --git a/filters/video/video.c b/filters/video/video.c
index 0879f31..b555c43 100644
--- a/filters/video/video.c
+++ b/filters/video/video.c
@@ -46,12 +46,14 @@ void x264_register_vid_filters( void )
 {
     extern cli_vid_filter_t source_filter;
     first_filter = &source_filter;
-    REGISTER_VFILTER( cache );
+    REGISTER_VFILTER( cache_8 );
+    REGISTER_VFILTER( cache_10 );
     REGISTER_VFILTER( crop );
     REGISTER_VFILTER( fix_vfr_pts );
     REGISTER_VFILTER( resize );
     REGISTER_VFILTER( select_every );
-    REGISTER_VFILTER( depth );
+    REGISTER_VFILTER( depth_8 );
+    REGISTER_VFILTER( depth_10 );
 #if HAVE_GPL
 #endif
 }
-- 
2.10.0



More information about the x264-devel mailing list