[x264-devel] [PATCH 25/29] x264cli: Duplicate depth and cache filters

Vittorio Giovara vittorio.giovara at gmail.com
Thu Feb 2 10:05:37 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        |  8 +++++++-
 filters/video/depth.c        | 21 ++++++++++++++-------
 filters/video/select_every.c |  4 +++-
 filters/video/video.c        |  6 ++++--
 x264.c                       |  7 ++++---
 6 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index b23fdd9..4b076ae 100644
--- a/Makefile
+++ b/Makefile
@@ -29,8 +29,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 =
 SRCSOCL =
@@ -191,7 +193,9 @@ OBJCLI += $(SRCCLI:%.c=%.o)
 OBJSO  += $(SRCSO:%.c=%.o)
 
 OBJS += $(SRCS:%.c=8bit/%.o) $(SRCSOCL:%.c=8bit/%.o)
+OBJCLI += $(SRCCLIBD:%.c=8bit/%.o)
 OBJS += $(SRCS:%.c=10bit/%.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 17acb3d..9170d6d 100644
--- a/filters/video/cache.c
+++ b/filters/video/cache.c
@@ -27,7 +27,13 @@
 #include "internal.h"
 #include "common/common.h"
 
-#define NAME "cache"
+#define cache_filter x264_glue3(cache, BIT_DEPTH, filter)
+#if BIT_DEPTH == 8
+#define NAME "cache_8"
+#else
+#define NAME "cache_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 2e09fe4..515a951 100644
--- a/filters/video/depth.c
+++ b/filters/video/depth.c
@@ -26,7 +26,14 @@
 #include "common/common.h"
 
 #include "video.h"
-#define NAME "depth"
+
+#define depth_filter x264_glue3(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 +83,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 +146,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 +226,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 dab2771..a3f9827 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 799eddf..9e45b75 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( depth_8 );
+    REGISTER_VFILTER( cache_10 );
+    REGISTER_VFILTER( depth_10 );
     REGISTER_VFILTER( crop );
     REGISTER_VFILTER( fix_vfr_pts );
     REGISTER_VFILTER( resize );
     REGISTER_VFILTER( select_every );
-    REGISTER_VFILTER( depth );
 #if HAVE_GPL
 #endif
 }
diff --git a/x264.c b/x264.c
index 82b6a4f..1112340 100644
--- a/x264.c
+++ b/x264.c
@@ -1319,10 +1319,11 @@ static int init_vid_filters( char *sequence, hnd_t *handle, video_info_t *info,
     if( x264_init_vid_filter( "resize", handle, &filter, info, param, NULL ) )
         return -1;
 
-    char args[20];
-    sprintf( args, "bit_depth=%d", X264_BIT_DEPTH );
+    char args[20], name[20];
+    sprintf( args, "bit_depth=%d", param->i_bitdepth );
+    sprintf( name, "depth_%d", param->i_bitdepth );
 
-    if( x264_init_vid_filter( "depth", handle, &filter, info, param, args ) )
+    if( x264_init_vid_filter( name, handle, &filter, info, param, args ) )
         return -1;
 
     return 0;
-- 
2.10.0



More information about the x264-devel mailing list