<div dir="auto">Unsubscribe</div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 2, 2017 1:08 AM,  <<a href="mailto:x264-devel-request@videolan.org">x264-devel-request@videolan.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send x264-devel mailing list submissions to<br>
        <a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mailman.videolan.org/listinfo/x264-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x264-devel</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:x264-devel-request@videolan.org">x264-devel-request@videolan.<wbr>org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:x264-devel-owner@videolan.org">x264-devel-owner@videolan.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of x264-devel digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. [PATCH 15/29] Adjust headers to make x264cli      independent of<br>
      common.h (Vittorio Giovara)<br>
   2. [PATCH 16/29] Add API to set bitdepth at runtime<br>
      (Vittorio Giovara)<br>
   3. [PATCH 17/29] Templatize the public API (Vittorio Giovara)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Thu,  2 Feb 2017 10:05:27 +0100<br>
From: Vittorio Giovara <<a href="mailto:vittorio.giovara@gmail.com">vittorio.giovara@gmail.com</a>><br>
To: <a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br>
Subject: [x264-devel] [PATCH 15/29] Adjust headers to make x264cli<br>
        independent of common.h<br>
Message-ID: <<a href="mailto:20170202090541.22994-16-vittorio.giovara@gmail.com">20170202090541.22994-16-<wbr>vittorio.giovara@gmail.com</a>><br>
<br>
---<br>
 filters/filters.c            |  2 ++<br>
 filters/video/cache.c        |  2 ++<br>
 filters/video/depth.c        |  2 ++<br>
 filters/video/fix_vfr_pts.c  |  1 +<br>
 filters/video/resize.c       |  2 ++<br>
 filters/video/select_every.c |  2 ++<br>
 input/input.c                |  1 +<br>
 input/input.h                |  5 +++++<br>
 input/lavf.c                 |  2 ++<br>
 input/thread.c               |  2 ++<br>
 input/timecode.c             |  3 +++<br>
 input/y4m.c                  |  2 ++<br>
 output/flv.c                 |  3 +++<br>
 output/flv_bytestream.c      |  1 +<br>
 output/flv_bytestream.h      |  2 ++<br>
 output/matroska_ebml.c       |  3 +++<br>
 output/mp4_lsmash.c          |  1 +<br>
 output/raw.c                 |  1 +<br>
 x264.c                       | 10 +++++++++-<br>
 x264cli.h                    |  5 ++++-<br>
 20 files changed, 50 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/filters/filters.c b/filters/filters.c<br>
index 9212a3e..9479cd1 100644<br>
--- a/filters/filters.c<br>
+++ b/filters/filters.c<br>
@@ -26,6 +26,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "filters.h"<br>
+#include <assert.h><br>
+<br>
 #define RETURN_IF_ERROR( cond, ... ) RETURN_IF_ERR( cond, "options", NULL, __VA_ARGS__ )<br>
<br>
 char **x264_split_options( const char *opt_str, const char * const *options )<br>
diff --git a/filters/video/cache.c b/filters/video/cache.c<br>
index 552e1b4..17acb3d 100644<br>
--- a/filters/video/cache.c<br>
+++ b/filters/video/cache.c<br>
@@ -25,6 +25,8 @@<br>
<br>
 #include "video.h"<br>
 #include "internal.h"<br>
+#include "common/common.h"<br>
+<br>
 #define NAME "cache"<br>
 #define LAST_FRAME (h->first_frame + h->cur_size - 1)<br>
<br>
diff --git a/filters/video/depth.c b/filters/video/depth.c<br>
index 72eb288..2e09fe4 100644<br>
--- a/filters/video/depth.c<br>
+++ b/filters/video/depth.c<br>
@@ -23,6 +23,8 @@<br>
  * For more information, contact us at <a href="mailto:licensing@x264.com">licensing@x264.com</a>.<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
+#include "common/common.h"<br>
+<br>
 #include "video.h"<br>
 #define NAME "depth"<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ )<br>
diff --git a/filters/video/fix_vfr_pts.c b/filters/video/fix_vfr_pts.c<br>
index e7e9346..0eaf566 100644<br>
--- a/filters/video/fix_vfr_pts.c<br>
+++ b/filters/video/fix_vfr_pts.c<br>
@@ -25,6 +25,7 @@<br>
<br>
 #include "video.h"<br>
 #include "internal.h"<br>
+#include "common/mathematics.h"<br>
<br>
 /* This filter calculates and store the frame's duration to the frame data<br>
  * (if it is not already calculated when the frame arrives to this point)<br>
diff --git a/filters/video/resize.c b/filters/video/resize.c<br>
index 4e95f31..2a1c82d 100644<br>
--- a/filters/video/resize.c<br>
+++ b/filters/video/resize.c<br>
@@ -24,6 +24,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "video.h"<br>
+#include "common/mathematics.h"<br>
+<br>
 #define NAME "resize"<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ )<br>
<br>
diff --git a/filters/video/select_every.c b/filters/video/select_every.c<br>
index f5b6750..dab2771 100644<br>
--- a/filters/video/select_every.c<br>
+++ b/filters/video/select_every.c<br>
@@ -24,6 +24,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "video.h"<br>
+#include "common/mathematics.h"<br>
+<br>
 #define NAME "select_every"<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ )<br>
<br>
diff --git a/input/input.c b/input/input.c<br>
index faadd4d..84a014c 100644<br>
--- a/input/input.c<br>
+++ b/input/input.c<br>
@@ -25,6 +25,7 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "input.h"<br>
+#include "common/mem.h"<br>
<br>
 #ifdef _WIN32<br>
 #include <io.h><br>
diff --git a/input/input.h b/input/input.h<br>
index a66752d..084c3e3 100644<br>
--- a/input/input.h<br>
+++ b/input/input.h<br>
@@ -28,8 +28,13 @@<br>
 #ifndef X264_INPUT_H<br>
 #define X264_INPUT_H<br>
<br>
+#include <stdio.h><br>
+<br>
+#include "config.h"<br>
 #include "x264cli.h"<br>
<br>
+#include "common/osdep.h"<br>
+<br>
 #ifdef _WIN32<br>
 #include <windows.h><br>
 #endif<br>
diff --git a/input/lavf.c b/input/lavf.c<br>
index c0024a5..5067a3e 100644<br>
--- a/input/lavf.c<br>
+++ b/input/lavf.c<br>
@@ -25,6 +25,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "input.h"<br>
+#include "common/mathematics.h"<br>
+<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "lavf", __VA_ARGS__ )<br>
 #undef DECLARE_ALIGNED<br>
 #include <libavformat/avformat.h><br>
diff --git a/input/thread.c b/input/thread.c<br>
index 3d83bfa..d9622b7 100644<br>
--- a/input/thread.c<br>
+++ b/input/thread.c<br>
@@ -25,6 +25,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "input.h"<br>
+#include "common/threadpool.h"<br>
+#include "common/mathematics.h"<br>
<br>
 typedef struct<br>
 {<br>
diff --git a/input/timecode.c b/input/timecode.c<br>
index 25f924c..d1fbfe3 100644<br>
--- a/input/timecode.c<br>
+++ b/input/timecode.c<br>
@@ -24,6 +24,9 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "input.h"<br>
+#include <math.h><br>
+#include <inttypes.h><br>
+<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "timecode", __VA_ARGS__ )<br>
<br>
 typedef struct<br>
diff --git a/input/y4m.c b/input/y4m.c<br>
index 8948f68..901faaa 100644<br>
--- a/input/y4m.c<br>
+++ b/input/y4m.c<br>
@@ -25,6 +25,8 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "input.h"<br>
+#include "common/mathematics.h"<br>
+<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "y4m", __VA_ARGS__ )<br>
<br>
 typedef struct<br>
diff --git a/output/flv.c b/output/flv.c<br>
index dfe4d48..63ecbdd 100644<br>
--- a/output/flv.c<br>
+++ b/output/flv.c<br>
@@ -23,8 +23,11 @@<br>
  * For more information, contact us at <a href="mailto:licensing@x264.com">licensing@x264.com</a>.<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
+#include <inttypes.h><br>
+<br>
 #include "output.h"<br>
 #include "flv_bytestream.h"<br>
+#include "common/osdep.h"<br>
<br>
 #define CHECK(x)\<br>
 do {\<br>
diff --git a/output/flv_bytestream.c b/output/flv_bytestream.c<br>
index b57a63c..c18f38c 100644<br>
--- a/output/flv_bytestream.c<br>
+++ b/output/flv_bytestream.c<br>
@@ -25,6 +25,7 @@<br>
<br>
 #include "output.h"<br>
 #include "flv_bytestream.h"<br>
+#include "common/osdep.h"<br>
<br>
 uint64_t flv_dbl2int( double value )<br>
 {<br>
diff --git a/output/flv_bytestream.h b/output/flv_bytestream.h<br>
index af22b09..5da5696 100644<br>
--- a/output/flv_bytestream.h<br>
+++ b/output/flv_bytestream.h<br>
@@ -26,6 +26,8 @@<br>
 #ifndef X264_FLV_BYTESTREAM_H<br>
 #define X264_FLV_BYTESTREAM_H<br>
<br>
+#include <stdio.h><br>
+<br>
 /* offsets for packed values */<br>
 #define FLV_AUDIO_SAMPLESSIZE_OFFSET 1<br>
 #define FLV_AUDIO_SAMPLERATE_OFFSET  2<br>
diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c<br>
index b92a23e..0fb47ca 100644<br>
--- a/output/matroska_ebml.c<br>
+++ b/output/matroska_ebml.c<br>
@@ -23,8 +23,11 @@<br>
  * For more information, contact us at <a href="mailto:licensing@x264.com">licensing@x264.com</a>.<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
+#include <stdlib.h><br>
+<br>
 #include "output.h"<br>
 #include "matroska_ebml.h"<br>
+#include "common/osdep.h"<br>
<br>
 #define CLSIZE 1048576<br>
 #define CHECK(x)\<br>
diff --git a/output/mp4_lsmash.c b/output/mp4_lsmash.c<br>
index 30bded0..b8af7a3 100644<br>
--- a/output/mp4_lsmash.c<br>
+++ b/output/mp4_lsmash.c<br>
@@ -29,6 +29,7 @@<br>
<br>
 #include "output.h"<br>
 #include <lsmash.h><br>
+#include "common/osdep.h"<br>
<br>
 #define H264_NALU_LENGTH_SIZE 4<br>
<br>
diff --git a/output/raw.c b/output/raw.c<br>
index 47e3353..02bfc20 100644<br>
--- a/output/raw.c<br>
+++ b/output/raw.c<br>
@@ -25,6 +25,7 @@<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
 #include "output.h"<br>
+#include "common/osdep.h"<br>
<br>
 static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt )<br>
 {<br>
diff --git a/x264.c b/x264.c<br>
index 016047a..15f0020 100644<br>
--- a/x264.c<br>
+++ b/x264.c<br>
@@ -39,11 +39,19 @@<br>
<br>
 #include <signal.h><br>
 #include <getopt.h><br>
-#include "common/common.h"<br>
 #include "x264cli.h"<br>
 #include "input/input.h"<br>
 #include "output/output.h"<br>
 #include "filters/filters.h"<br>
+#include "common/cpu.h"<br>
+#include "common/osdep.h"<br>
+#include "common/mathematics.h"<br>
+<br>
+#define MAX_BIT_DEPTH 10<br>
+#define QP_BD_OFFSET (6*(MAX_BIT_DEPTH-8))<br>
+#define QP_MAX_SPEC (51+QP_BD_OFFSET)<br>
+#define QP_MAX (QP_MAX_SPEC+18)<br>
+#define QP_MAX_MAX (51+2*6+18)<br>
<br>
 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "x264", __VA_ARGS__ )<br>
<br>
diff --git a/x264cli.h b/x264cli.h<br>
index 9b5d31e..6ae500e 100644<br>
--- a/x264cli.h<br>
+++ b/x264cli.h<br>
@@ -27,7 +27,10 @@<br>
 #ifndef X264_CLI_H<br>
 #define X264_CLI_H<br>
<br>
-#include "common/common.h"<br>
+#include <stdint.h><br>
+#include <stdlib.h><br>
+#include <string.h><br>
+#include "x264.h"<br>
<br>
 /* In microseconds */<br>
 #define UPDATE_INTERVAL 250000<br>
--<br>
2.10.0<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Thu,  2 Feb 2017 10:05:28 +0100<br>
From: Vittorio Giovara <<a href="mailto:vittorio.giovara@gmail.com">vittorio.giovara@gmail.com</a>><br>
To: <a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br>
Subject: [x264-devel] [PATCH 16/29] Add API to set bitdepth at runtime<br>
Message-ID: <<a href="mailto:20170202090541.22994-17-vittorio.giovara@gmail.com">20170202090541.22994-17-<wbr>vittorio.giovara@gmail.com</a>><br>
<br>
Replace the constant symbol where needed.<br>
---<br>
 common/frame.c    | 16 +---------------<br>
 common/param.c    | 11 +++++------<br>
 common/set.h      |  1 +<br>
 encoder/encoder.c |  6 +++---<br>
 encoder/set.c     |  7 ++++---<br>
 x264.h            |  1 +<br>
 6 files changed, 15 insertions(+), 27 deletions(-)<br>
<br>
diff --git a/common/frame.c b/common/frame.c<br>
index e0b85b8..42af602 100644<br>
--- a/common/frame.c<br>
+++ b/common/frame.c<br>
@@ -370,21 +370,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )<br>
         return -1;<br>
     }<br>
<br>
-#if HIGH_BIT_DEPTH<br>
-    if( !(src->img.i_csp & X264_CSP_HIGH_DEPTH) )<br>
-    {<br>
-        x264_log( h, X264_LOG_ERROR, "This build of x264 requires high depth input. Rebuild to support 8-bit input.\n" );<br>
-        return -1;<br>
-    }<br>
-#else<br>
-    if( src->img.i_csp & X264_CSP_HIGH_DEPTH )<br>
-    {<br>
-        x264_log( h, X264_LOG_ERROR, "This build of x264 requires 8-bit input. Rebuild to support high depth input.\n" );<br>
-        return -1;<br>
-    }<br>
-#endif<br>
-<br>
-    if( BIT_DEPTH != 10 && i_csp == X264_CSP_V210 )<br>
+    if( h->param.i_bitdepth != 10 && i_csp == X264_CSP_V210 )<br>
     {<br>
         x264_log( h, X264_LOG_ERROR, "v210 input is only compatible with bit-depth of 10 bits\n" );<br>
         return -1;<br>
diff --git a/common/param.c b/common/param.c<br>
index 1c35d5e..fb536e8 100644<br>
--- a/common/param.c<br>
+++ b/common/param.c<br>
@@ -24,8 +24,6 @@<br>
  * For more information, contact us at <a href="mailto:licensing@x264.com">licensing@x264.com</a>.<br>
  ******************************<wbr>******************************<wbr>*****************/<br>
<br>
-#include "common.h"<br>
-<br>
 #include <ctype.h><br>
 #include "osdep.h"<br>
 #include "x264.h"<br>
@@ -449,6 +447,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )<br>
     if( !profile )<br>
         return 0;<br>
<br>
+    const int qp_bd_offset = 6 * (param->i_bitdepth-8);<br>
     int p = profile_string_to_int( profile );<br>
     if( p < 0 )<br>
     {<br>
@@ -456,7 +455,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )<br>
         return -1;<br>
     }<br>
     if( p < PROFILE_HIGH444_PREDICTIVE && ((param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant <= 0) ||<br>
-        (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + QP_BD_OFFSET) <= 0)) )<br>
+        (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + qp_bd_offset) <= 0)) )<br>
     {<br>
         x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );<br>
         return -1;<br>
@@ -471,9 +470,9 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )<br>
         x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support 4:2:2\n", profile );<br>
         return -1;<br>
     }<br>
-    if( p < PROFILE_HIGH10 && BIT_DEPTH > 8 )<br>
+    if( p < PROFILE_HIGH10 && param->i_bitdepth > 8 )<br>
     {<br>
-        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, BIT_DEPTH );<br>
+        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, param->i_bitdepth );<br>
         return -1;<br>
     }<br>
<br>
@@ -1081,7 +1080,7 @@ char *x264_param2string( x264_param_t *p, int b_res )<br>
         s += sprintf( s, "%dx%d ", p->i_width, p->i_height );<br>
         s += sprintf( s, "fps=%u/%u ", p->i_fps_num, p->i_fps_den );<br>
         s += sprintf( s, "timebase=%u/%u ", p->i_timebase_num, p->i_timebase_den );<br>
-        s += sprintf( s, "bitdepth=%d ", BIT_DEPTH );<br>
+        s += sprintf( s, "bitdepth=%d ", p->i_bitdepth );<br>
     }<br>
<br>
     if( p->b_opencl )<br>
diff --git a/common/set.h b/common/set.h<br>
index 5760f33..c28b902 100644<br>
--- a/common/set.h<br>
+++ b/common/set.h<br>
@@ -157,6 +157,7 @@ typedef struct<br>
<br>
     int b_qpprime_y_zero_transform_<wbr>bypass;<br>
     int i_chroma_format_idc;<br>
+    int i_bitdepth;<br>
<br>
 } x264_sps_t;<br>
<br>
diff --git a/encoder/encoder.c b/encoder/encoder.c<br>
index 935f137..cc6217a 100644<br>
--- a/encoder/encoder.c<br>
+++ b/encoder/encoder.c<br>
@@ -3795,9 +3795,9 @@ static int encoder_frame_end( x264_t *h, x264_t *thread_current,<br>
     pic_out->opaque = h->fenc->opaque;<br>
<br>
     pic_out->img.i_csp = h->fdec->i_csp;<br>
-#if HIGH_BIT_DEPTH<br>
-    pic_out->img.i_csp |= X264_CSP_HIGH_DEPTH;<br>
-#endif<br>
+    if( h->param.i_bitdepth > 8 )<br>
+        pic_out->img.i_csp |= X264_CSP_HIGH_DEPTH;<br>
+<br>
     pic_out->img.i_plane = h->fdec->i_plane;<br>
     for( int i = 0; i < pic_out->img.i_plane; i++ )<br>
     {<br>
diff --git a/encoder/set.c b/encoder/set.c<br>
index 07cb4c4..51b91f8 100644<br>
--- a/encoder/set.c<br>
+++ b/encoder/set.c<br>
@@ -107,13 +107,14 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )<br>
     sps->i_mb_height= ( param->i_height + 15 ) / 16;<br>
     sps->i_chroma_format_idc = csp >= X264_CSP_I444 ? CHROMA_444 :<br>
                                csp >= X264_CSP_I422 ? CHROMA_422 : CHROMA_420;<br>
+    sps->i_bitdepth = param->i_bitdepth;<br>
<br>
     sps->b_qpprime_y_zero_<wbr>transform_bypass = param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant == 0;<br>
     if( sps->b_qpprime_y_zero_<wbr>transform_bypass || sps->i_chroma_format_idc == CHROMA_444 )<br>
         sps->i_profile_idc  = PROFILE_HIGH444_PREDICTIVE;<br>
     else if( sps->i_chroma_format_idc == CHROMA_422 )<br>
         sps->i_profile_idc  = PROFILE_HIGH422;<br>
-    else if( BIT_DEPTH > 8 )<br>
+    else if( param->i_bitdepth > 8 )<br>
         sps->i_profile_idc  = PROFILE_HIGH10;<br>
     else if( param->analyse.b_transform_8x8 || param->i_cqm_preset != X264_CQM_FLAT )<br>
         sps->i_profile_idc  = PROFILE_HIGH;<br>
@@ -287,8 +288,8 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )<br>
         bs_write_ue( s, sps->i_chroma_format_idc );<br>
         if( sps->i_chroma_format_idc == CHROMA_444 )<br>
             bs_write1( s, 0 ); // separate_colour_plane_flag<br>
-        bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_luma_minus8<br>
-        bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_chroma_minus8<br>
+        bs_write_ue( s, sps->i_bitdepth-8 ); // bit_depth_luma_minus8<br>
+        bs_write_ue( s, sps->i_bitdepth-8 ); // bit_depth_chroma_minus8<br>
         bs_write1( s, sps->b_qpprime_y_zero_<wbr>transform_bypass );<br>
         bs_write1( s, 0 ); // seq_scaling_matrix_present_<wbr>flag<br>
     }<br>
diff --git a/x264.h b/x264.h<br>
index b73e479..72ea253 100644<br>
--- a/x264.h<br>
+++ b/x264.h<br>
@@ -293,6 +293,7 @@ typedef struct x264_param_t<br>
     int         i_width;<br>
     int         i_height;<br>
     int         i_csp;         /* CSP of encoded bitstream */<br>
+    int         i_bitdepth;<br>
     int         i_level_idc;<br>
     int         i_frame_total; /* number of frames to encode if known, else 0 */<br>
<br>
--<br>
2.10.0<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Thu,  2 Feb 2017 10:05:29 +0100<br>
From: Vittorio Giovara <<a href="mailto:vittorio.giovara@gmail.com">vittorio.giovara@gmail.com</a>><br>
To: <a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br>
Subject: [x264-devel] [PATCH 17/29] Templatize the public API<br>
Message-ID: <<a href="mailto:20170202090541.22994-18-vittorio.giovara@gmail.com">20170202090541.22994-18-<wbr>vittorio.giovara@gmail.com</a>><br>
<br>
Include an implementation file to wrap the appropriate calls. The<br>
current API calls are renamed according to the compiled bitdepth value.<br>
This file allocates an internal structure and calls the main API entry points.<br>
<br>
In upcoming commits more functions will be renamed and this file will<br>
support and  use the correct function depending on bitdepth value set at<br>
runtime.<br>
---<br>
 Makefile          |   2 +-<br>
 common/api.c      | 165 ++++++++++++++++++++++++++++++<wbr>++++++++++++++++++++++++<br>
 common/common.h   |  15 +++++<br>
 common/osdep.h    |   5 ++<br>
 encoder/encoder.c |   3 +<br>
 5 files changed, 189 insertions(+), 1 deletion(-)<br>
 create mode 100644 common/api.c<br>
<br>
diff --git a/Makefile b/Makefile<br>
index f039fcc..d93ce95 100644<br>
--- a/Makefile<br>
+++ b/Makefile<br>
@@ -19,7 +19,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \<br>
        common/set.c common/quant.c common/deblock.c common/vlc.c \<br>
        common/mvpred.c common/bitstream.c \<br>
        common/log.c common/mem.c common/picture.c common/mathematics.c \<br>
-       common/param.c common/tables.c \<br>
+       common/param.c common/tables.c common/api.c \<br>
        encoder/analyse.c encoder/me.c encoder/ratecontrol.c \<br>
        encoder/set.c encoder/macroblock.c encoder/cabac.c \<br>
        encoder/cavlc.c encoder/encoder.c encoder/lookahead.c<br>
diff --git a/common/api.c b/common/api.c<br>
new file mode 100644<br>
index 0000000..4a08d1e<br>
--- /dev/null<br>
+++ b/common/api.c<br>
@@ -0,0 +1,165 @@<br>
+/****************************<wbr>******************************<wbr>*******************<br>
+ * api.c: bitdepth-independent interface<br>
+ ******************************<wbr>******************************<wbr>*****************<br>
+ * Copyright (C) 2003-2017 x264 project<br>
+ *<br>
+ * Authors: Vittorio Giovara <<a href="mailto:vittorio.giovara@gmail.com">vittorio.giovara@gmail.com</a>><br>
+ *          Luca Barbato <<a href="mailto:lu_zero@gentoo.org">lu_zero@gentoo.org</a>><br>
+ *<br>
+ * This program is free software; you can redistribute it and/or modify<br>
+ * it under the terms of the GNU General Public License as published by<br>
+ * the Free Software Foundation; either version 2 of the License, or<br>
+ * (at your option) any later version.<br>
+ *<br>
+ * This program is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
+ * GNU General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU General Public License<br>
+ * along with this program; if not, write to the Free Software<br>
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.<br>
+ *<br>
+ * This program is also available under a commercial proprietary license.<br>
+ * For more information, contact us at <a href="mailto:licensing@x264.com">licensing@x264.com</a>.<br>
+ ******************************<wbr>******************************<wbr>*****************/<br>
+<br>
+#include <stdint.h><br>
+#include <stdlib.h><br>
+<br>
+#include "x264.h"<br>
+<br>
+x264_t *x264_8_encoder_open( x264_param_t * );<br>
+void x264_8_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );<br>
+int  x264_8_encoder_reconfig( x264_t *, x264_param_t * );<br>
+void x264_8_encoder_parameters( x264_t *, x264_param_t * );<br>
+int  x264_8_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );<br>
+int  x264_8_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );<br>
+void x264_8_encoder_close( x264_t * );<br>
+int  x264_8_encoder_delayed_frames( x264_t * );<br>
+int  x264_8_encoder_maximum_<wbr>delayed_frames( x264_t *h );<br>
+void x264_8_encoder_intra_refresh( x264_t * );<br>
+int  x264_8_encoder_invalidate_<wbr>reference( x264_t *, int64_t pts );<br>
+<br>
+typedef struct x264_api_t {<br>
+    /* Internal reference to x264_t data */<br>
+    void *x264;<br>
+<br>
+    /* API entry points */<br>
+    void (*x264_nal_encode) ( x264_t *h, uint8_t *dst, x264_nal_t *nal );<br>
+    int  (*x264_encoder_reconfig) ( x264_t *, x264_param_t * );<br>
+    void (*x264_encoder_parameters) ( x264_t *, x264_param_t * );<br>
+    int  (*x264_encoder_headers) ( x264_t *, x264_nal_t **pp_nal, int *pi_nal );<br>
+    int  (*x264_encoder_encode) ( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );<br>
+    void (*x264_encoder_close) ( x264_t * );<br>
+    int  (*x264_encoder_delayed_frames) ( x264_t * );<br>
+    int  (*x264_encoder_maximum_<wbr>delayed_frames) ( x264_t *h );<br>
+    void (*x264_encoder_intra_refresh) ( x264_t * );<br>
+    int  (*x264_encoder_invalidate_<wbr>reference) ( x264_t *, int64_t pts );<br>
+} x264_api_t;<br>
+<br>
+x264_t *x264_encoder_open( x264_param_t *param )<br>
+{<br>
+    x264_api_t *api;<br>
+<br>
+    api = calloc( 1, sizeof(x264_api_t) );<br>
+    if( !api )<br>
+        return NULL;<br>
+<br>
+    if( param->i_bitdepth == 0 || param->i_bitdepth == 8 ) {<br>
+        api->x264_encoder_reconfig = x264_8_encoder_reconfig;<br>
+        api->x264_encoder_parameters = x264_8_encoder_parameters;<br>
+        api->x264_encoder_headers = x264_8_encoder_headers;<br>
+        api->x264_encoder_encode = x264_8_encoder_encode;<br>
+        api->x264_encoder_close = x264_8_encoder_close;<br>
+        api->x264_encoder_delayed_<wbr>frames = x264_8_encoder_delayed_frames;<br>
+        api->x264_encoder_maximum_<wbr>delayed_frames = x264_8_encoder_maximum_<wbr>delayed_frames;<br>
+        api->x264_encoder_intra_<wbr>refresh = x264_8_encoder_intra_refresh;<br>
+        api->x264_encoder_invalidate_<wbr>reference = x264_8_encoder_invalidate_<wbr>reference;<br>
+<br>
+        api->x264 = x264_8_encoder_open( param );<br>
+    } else if( param->i_bitdepth == 10 ) {<br>
+        x264_log_internal( NULL, "Not yet implemented\n");<br>
+    }<br>
+<br>
+    if( !api->x264 ) {<br>
+        x264_encoder_close( (x264_t *) api );<br>
+        return NULL;<br>
+    }<br>
+<br>
+    /* x264_t is opaque */<br>
+    return (x264_t *) api;<br>
+}<br>
+<br>
+void x264_encoder_close( x264_t *h )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    if( api->x264_encoder_close && api->x264 )<br>
+        api->x264_encoder_close( api->x264 );<br>
+<br>
+    free( h );<br>
+}<br>
+<br>
+void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    api->x264_nal_encode( api->x264, dst, nal );<br>
+}<br>
+<br>
+int x264_encoder_reconfig( x264_t *h, x264_param_t *param)<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_reconfig( api->x264, param );<br>
+}<br>
+<br>
+void x264_encoder_parameters( x264_t *h, x264_param_t *param )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    api->x264_encoder_parameters( api->x264, param );<br>
+}<br>
+<br>
+int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_headers( api->x264, pp_nal, pi_nal );<br>
+}<br>
+<br>
+int x264_encoder_encode( x264_t *h, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_encode( api->x264, pp_nal, pi_nal, pic_in, pic_out );<br>
+}<br>
+<br>
+int x264_encoder_delayed_frames( x264_t *h )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_delayed_<wbr>frames( api->x264 );<br>
+}<br>
+<br>
+int x264_encoder_maximum_delayed_<wbr>frames( x264_t *h )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_maximum_<wbr>delayed_frames( api->x264 );<br>
+}<br>
+<br>
+void x264_encoder_intra_refresh( x264_t *h )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    api->x264_encoder_intra_<wbr>refresh( api->x264 );<br>
+}<br>
+<br>
+int x264_encoder_invalidate_<wbr>reference( x264_t *h, int64_t pts )<br>
+{<br>
+    x264_api_t *api = (x264_api_t *)h;<br>
+<br>
+    return api->x264_encoder_invalidate_<wbr>reference( api->x264, pts );<br>
+}<br>
diff --git a/common/common.h b/common/common.h<br>
index db5c47b..dd9f136 100644<br>
--- a/common/common.h<br>
+++ b/common/common.h<br>
@@ -117,6 +117,21 @@ do {\<br>
 #include <assert.h><br>
 #include <limits.h><br>
<br>
+/****************************<wbr>******************************<wbr>******************<br>
+ * API Templates<br>
+ ******************************<wbr>******************************<wbr>****************/<br>
+#define x264_encoder_open x264_template(encoder_open)<br>
+#define x264_nal_encode x264_template(nal_encode)<br>
+#define x264_encoder_reconfig x264_template(encoder_<wbr>reconfig)<br>
+#define x264_encoder_parameters x264_template(encoder_<wbr>parameters)<br>
+#define x264_encoder_headers x264_template(encoder_headers)<br>
+#define x264_encoder_encode x264_template(encoder_encode)<br>
+#define x264_encoder_close x264_template(encoder_close)<br>
+#define x264_encoder_delayed_frames x264_template(encoder_delayed_<wbr>frames)<br>
+#define x264_encoder_maximum_delayed_<wbr>frames x264_template(encoder_maximum_<wbr>delayed_frames)<br>
+#define x264_encoder_intra_refresh x264_template(encoder_intra_<wbr>refresh)<br>
+#define x264_encoder_invalidate_<wbr>reference x264_template(encoder_<wbr>invalidate_reference)<br>
+<br>
 #if HAVE_INTERLACED<br>
 #   define MB_INTERLACED h->mb.b_interlaced<br>
 #   define SLICE_MBAFF h->sh.b_mbaff<br>
diff --git a/common/osdep.h b/common/osdep.h<br>
index 9544401..9a6978a 100644<br>
--- a/common/osdep.h<br>
+++ b/common/osdep.h<br>
@@ -103,6 +103,11 @@ int x264_is_pipe( const char *path );<br>
 #define x264_is_pipe(x) 0<br>
 #endif<br>
<br>
+/* Macros for templating function calls according to bitdepth */<br>
+#define x264_glue3_expand(x,y,z) x##_##y##_##z<br>
+#define x264_glue3(x,y,z) x264_glue3_expand(x,y,z)<br>
+#define x264_template(w) x264_glue3(x264,BIT_DEPTH,w)<br>
+<br>
 #ifdef _MSC_VER<br>
 #define DECLARE_ALIGNED( var, n ) __declspec(align(n)) var<br>
 #else<br>
diff --git a/encoder/encoder.c b/encoder/encoder.c<br>
index cc6217a..7edd671 100644<br>
--- a/encoder/encoder.c<br>
+++ b/encoder/encoder.c<br>
@@ -40,6 +40,9 @@<br>
<br>
 #define bs_write_ue bs_write_ue_big<br>
<br>
+// forward declaration need for template usage<br>
+void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );<br>
+<br>
 static int encoder_frame_end( x264_t *h, x264_t *thread_current,<br>
                               x264_nal_t **pp_nal, int *pi_nal,<br>
                               x264_picture_t *pic_out );<br>
--<br>
2.10.0<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
x264-devel mailing list<br>
<a href="mailto:x264-devel@videolan.org">x264-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x264-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x264-devel</a><br>
<br>
<br>
------------------------------<br>
<br>
End of x264-devel Digest, Vol 117, Issue 8<br>
******************************<wbr>************<br>
</blockquote></div></div>