[x264-devel] [PATCH 2 of 3] Workarounds for VC12 bugs

Steve Borho steve at borho.org
Wed Mar 19 01:07:31 CET 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1395187158 18000
#      Tue Mar 18 18:59:18 2014 -0500
# Node ID f28423920c0cc81c7bc89c44e34414d5fee8f321
# Parent  3fdb434e2e5d411d04a4e6a753d9393455a955cc
Workarounds for VC12 bugs

In all of these cases, VC12 cannot properly handle non-intrinsic variables being
declared within a code block. ie: ints and longs are ok but it seems uint8_t
or any other typedef'd types can trigger this problem.

diff -r 3fdb434e2e5d -r f28423920c0c common/deblock.c
--- a/common/deblock.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/common/deblock.c	Tue Mar 18 18:59:18 2014 -0500
@@ -600,6 +600,7 @@
  */
 void x264_macroblock_deblock( x264_t *h )
 {
+    uint8_t(*bs)[8][4];
     int a = h->sh.i_alpha_c0_offset - QP_BD_OFFSET;
     int b = h->sh.i_beta_offset - QP_BD_OFFSET;
     int qp_thresh = 15 - X264_MIN( a, b ) - X264_MAX( 0, h->pps->i_chroma_qp_index_offset );
@@ -609,7 +610,7 @@
     if( (h->mb.i_partition == D_16x16 && !h->mb.i_cbp_luma && !intra_cur) || qp <= qp_thresh )
         return;
 
-    uint8_t (*bs)[8][4] = h->mb.cache.deblock_strength;
+    bs = h->mb.cache.deblock_strength;
     if( intra_cur )
     {
         memset( &bs[0][1], 3, 3*4*sizeof(uint8_t) );
diff -r 3fdb434e2e5d -r f28423920c0c common/frame.c
--- a/common/frame.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/common/frame.c	Tue Mar 18 18:59:18 2014 -0500
@@ -541,6 +541,7 @@
         return;
     for( int i = 0; i < frame->i_plane; i++ )
     {
+        pixel *pix;
         int h_shift = i && CHROMA_H_SHIFT;
         int v_shift = i && CHROMA_V_SHIFT;
         int stride = frame->i_stride[i];
@@ -551,7 +552,7 @@
         // buffer: 2 chroma, 3 luma (rounded to 4) because deblocking goes beyond the top of the mb
         if( b_end && !b_start )
             height += 4 >> (v_shift + SLICE_MBAFF);
-        pixel *pix;
+
         int starty = 16*mb_y - 4*!b_start;
         if( SLICE_MBAFF )
         {
diff -r 3fdb434e2e5d -r f28423920c0c common/threadpool.c
--- a/common/threadpool.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/common/threadpool.c	Tue Mar 18 18:59:18 2014 -0500
@@ -75,10 +75,10 @@
 int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
                           void (*init_func)(void *), void *init_arg )
 {
+    x264_threadpool_t *pool;
     if( threads <= 0 )
         return -1;
 
-    x264_threadpool_t *pool;
     CHECKED_MALLOCZERO( pool, sizeof(x264_threadpool_t) );
     *p_pool = pool;
 
diff -r 3fdb434e2e5d -r f28423920c0c common/win32thread.c
--- a/common/win32thread.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/common/win32thread.c	Tue Mar 18 18:59:18 2014 -0500
@@ -156,12 +156,13 @@
 
 int x264_pthread_cond_destroy( x264_pthread_cond_t *cond )
 {
+    x264_win32_cond_t *win32_cond;
     /* native condition variables do not destroy */
     if( thread_control.cond_init )
         return 0;
 
     /* non native condition variables */
-    x264_win32_cond_t *win32_cond = cond->ptr;
+    win32_cond = cond->ptr;
     CloseHandle( win32_cond->semaphore );
     CloseHandle( win32_cond->waiters_done );
     x264_pthread_mutex_destroy( &win32_cond->mtx_broadcast );
@@ -230,11 +231,12 @@
 
 int x264_pthread_cond_wait( x264_pthread_cond_t *cond, x264_pthread_mutex_t *mutex )
 {
+    x264_win32_cond_t *win32_cond;
     if( thread_control.cond_wait )
         return !thread_control.cond_wait( cond, mutex, INFINITE );
 
     /* non native condition variables */
-    x264_win32_cond_t *win32_cond = cond->ptr;
+    win32_cond = cond->ptr;
 
     x264_pthread_mutex_lock( &win32_cond->mtx_broadcast );
     x264_pthread_mutex_lock( &win32_cond->mtx_waiter_count );
diff -r 3fdb434e2e5d -r f28423920c0c encoder/encoder.c
--- a/encoder/encoder.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/encoder/encoder.c	Tue Mar 18 18:59:18 2014 -0500
@@ -1861,6 +1861,7 @@
 {
     if( h0->nal_buffer_size < necessary_size )
     {
+        intptr_t delta;
         necessary_size *= 2;
         uint8_t *buf = x264_malloc( necessary_size );
         if( !buf )
@@ -1868,7 +1869,7 @@
         if( previous_nal_size )
             memcpy( buf, h0->nal_buffer, previous_nal_size );
 
-        intptr_t delta = buf - h0->nal_buffer;
+        delta = buf - h0->nal_buffer;
         for( int i = 0; i < start; i++ )
             h->out.nal[i].p_payload += delta;
 
@@ -1882,6 +1883,7 @@
 
 static int x264_encoder_encapsulate_nals( x264_t *h, int start )
 {
+    uint8_t *nal_buffer;
     x264_t *h0 = h->thread[0];
     int nal_size = 0, previous_nal_size = 0;
 
@@ -1905,7 +1907,7 @@
     if( x264_check_encapsulated_buffer( h, h0, start, previous_nal_size, necessary_size ) )
         return -1;
 
-    uint8_t *nal_buffer = h0->nal_buffer + previous_nal_size;
+    nal_buffer = h0->nal_buffer + previous_nal_size;
 
     for( int i = start; i < h->out.i_nal; i++ )
     {
@@ -2709,11 +2711,12 @@
 
         if( slice_max_size && (!SLICE_MBAFF || (i_mb_y&1)) )
         {
+            uint8_t *end;
             /* Count the skip run, just in case. */
             if( !h->param.b_cabac )
                 total_bits += bs_size_ue_big( i_skip );
             /* Check for escape bytes. */
-            uint8_t *end = h->param.b_cabac ? h->cabac.p : h->out.bs.p;
+            end = h->param.b_cabac ? h->cabac.p : h->out.bs.p;
             for( ; last_emu_check < end - 2; last_emu_check++ )
                 if( last_emu_check[0] == 0 && last_emu_check[1] == 0 && last_emu_check[2] <= 3 )
                 {
diff -r 3fdb434e2e5d -r f28423920c0c encoder/lookahead.c
--- a/encoder/lookahead.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/encoder/lookahead.c	Tue Mar 18 18:59:18 2014 -0500
@@ -125,6 +125,7 @@
 
 int x264_lookahead_init( x264_t *h, int i_slicetype_length )
 {
+    x264_t *look_h;
     x264_lookahead_t *look;
     CHECKED_MALLOCZERO( look, sizeof(x264_lookahead_t) );
     for( int i = 0; i < h->param.i_threads; i++ )
@@ -144,7 +145,7 @@
     if( !h->param.i_sync_lookahead )
         return 0;
 
-    x264_t *look_h = h->thread[h->param.i_threads];
+    look_h = h->thread[h->param.i_threads];
     *look_h = *h;
     if( x264_macroblock_cache_allocate( look_h ) )
         goto fail;
diff -r 3fdb434e2e5d -r f28423920c0c encoder/rdo.c
--- a/encoder/rdo.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/encoder/rdo.c	Tue Mar 18 18:59:18 2014 -0500
@@ -636,6 +636,7 @@
 {
     ALIGNED_ARRAY_N( dctcoef, orig_coefs, [64] );
     ALIGNED_ARRAY_N( dctcoef, quant_coefs, [64] );
+    trellis_level_t level_tree[64*8*2];
     const uint32_t *coef_weight1 = num_coefs == 64 ? x264_dct8_weight_tab : x264_dct4_weight_tab;
     const uint32_t *coef_weight2 = num_coefs == 64 ? x264_dct8_weight2_tab : x264_dct4_weight2_tab;
     const int b_interlaced = MB_INTERLACED;
@@ -717,7 +718,6 @@
     // (# of coefs) * (# of ctx) * (# of levels tried) = 1024
     // we don't need to keep all of those: (# of coefs) * (# of ctx) would be enough,
     // but it takes more time to remove dead states than you gain in reduced memory.
-    trellis_level_t level_tree[64*8*2];
     int levels_used = 1;
     /* init trellis */
     trellis_node_t nodes[2][8];
diff -r 3fdb434e2e5d -r f28423920c0c filters/video/cache.c
--- a/filters/video/cache.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/filters/video/cache.c	Tue Mar 18 18:59:18 2014 -0500
@@ -44,11 +44,12 @@
 
 static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )
 {
+    cache_hnd_t *h;
     intptr_t size = (intptr_t)opt_string;
     /* upon a <= 0 cache request, do nothing */
     if( size <= 0 )
         return 0;
-    cache_hnd_t *h = calloc( 1, sizeof(cache_hnd_t) );
+    h = calloc( 1, sizeof(cache_hnd_t) );
     if( !h )
         return -1;
 
diff -r 3fdb434e2e5d -r f28423920c0c filters/video/fix_vfr_pts.c
--- a/filters/video/fix_vfr_pts.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/filters/video/fix_vfr_pts.c	Tue Mar 18 18:59:18 2014 -0500
@@ -50,10 +50,11 @@
 
 static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )
 {
+    fix_vfr_pts_hnd_t *h;
     /* if the input is not vfr, we don't do anything */
     if( !info->vfr )
         return 0;
-    fix_vfr_pts_hnd_t *h = calloc( 1, sizeof(fix_vfr_pts_hnd_t) );
+    h = calloc( 1, sizeof(fix_vfr_pts_hnd_t) );
     if( !h )
         return -1;
 
diff -r 3fdb434e2e5d -r f28423920c0c input/input.c
--- a/input/input.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/input/input.c	Tue Mar 18 18:59:18 2014 -0500
@@ -55,10 +55,11 @@
 
 uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane )
 {
+    uint64_t size;
     int csp_mask = csp & X264_CSP_MASK;
     if( x264_cli_csp_is_invalid( csp ) || plane < 0 || plane >= x264_cli_csps[csp_mask].planes )
         return 0;
-    uint64_t size = (uint64_t)width * height;
+    size = (uint64_t)width * height;
     size *= x264_cli_csps[csp_mask].width[plane] * x264_cli_csps[csp_mask].height[plane];
     size *= x264_cli_csp_depth_factor( csp );
     return size;
@@ -66,9 +67,10 @@
 
 uint64_t x264_cli_pic_size( int csp, int width, int height )
 {
+    uint64_t size = 0;
     if( x264_cli_csp_is_invalid( csp ) )
         return 0;
-    uint64_t size = 0;
+
     int csp_mask = csp & X264_CSP_MASK;
     for( int i = 0; i < x264_cli_csps[csp_mask].planes; i++ )
         size += x264_cli_pic_plane_size( csp, width, height, i );
diff -r 3fdb434e2e5d -r f28423920c0c input/y4m.c
--- a/input/y4m.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/input/y4m.c	Tue Mar 18 18:59:18 2014 -0500
@@ -64,6 +64,7 @@
 
 static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
 {
+    const x264_cli_csp_t *csp;
     y4m_hnd_t *h = malloc( sizeof(y4m_hnd_t) );
     int i;
     uint32_t n, d;
@@ -199,7 +200,7 @@
     if( h->bit_depth > 8 )
         info->csp |= X264_CSP_HIGH_DEPTH;
 
-    const x264_cli_csp_t *csp = x264_cli_get_csp( info->csp );
+    csp = x264_cli_get_csp( info->csp );
 
     for( i = 0; i < csp->planes; i++ )
     {
diff -r 3fdb434e2e5d -r f28423920c0c output/flv_bytestream.c
--- a/output/flv_bytestream.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/output/flv_bytestream.c	Tue Mar 18 18:59:18 2014 -0500
@@ -28,7 +28,12 @@
 
 uint64_t flv_dbl2int( double value )
 {
-    return (union {double f; uint64_t i;}){value}.i;
+    union {
+        double f;
+        uint64_t i;
+    }obj;
+    obj.i = value;
+    return obj.i;
 }
 
 /* Put functions  */
diff -r 3fdb434e2e5d -r f28423920c0c output/matroska.c
--- a/output/matroska.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/output/matroska.c	Tue Mar 18 18:59:18 2014 -0500
@@ -169,6 +169,7 @@
 
 static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_t *p_picture )
 {
+    int64_t i_stamp;
     mkv_hnd_t *p_mkv = handle;
 
     if( !p_mkv->b_writing_frame )
@@ -181,7 +182,7 @@
     if( mk_add_frame_data( p_mkv->w, p_nalu, i_size ) < 0 )
         return -1;
 
-    int64_t i_stamp = (int64_t)((p_picture->i_pts * 1e9 * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5);
+    i_stamp = (int64_t)((p_picture->i_pts * 1e9 * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5);
 
     p_mkv->b_writing_frame = 0;
 
diff -r 3fdb434e2e5d -r f28423920c0c x264.c
--- a/x264.c	Tue Mar 18 18:49:34 2014 -0500
+++ b/x264.c	Tue Mar 18 18:59:18 2014 -0500
@@ -291,9 +291,10 @@
 
 void x264_cli_printf( int i_level, const char *fmt, ... )
 {
+    va_list arg;
     if( i_level > cli_log_level )
         return;
-    va_list arg;
+
     va_start( arg, fmt );
     x264_vfprintf( stderr, fmt, arg );
     va_end( arg );
@@ -1786,11 +1787,12 @@
 
 static int64_t print_status( int64_t i_start, int64_t i_previous, int i_frame, int i_frame_total, int64_t i_file, x264_param_t *param, int64_t last_ts )
 {
+    int64_t i_elapsed;
     char buf[200];
     int64_t i_time = x264_mdate();
     if( i_previous && i_time - i_previous < UPDATE_INTERVAL )
         return i_previous;
-    int64_t i_elapsed = i_time - i_start;
+    i_elapsed = i_time - i_start;
     double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0;
     double bitrate;
     if( last_ts )


More information about the x264-devel mailing list