/*****************************************************************************
* common.h: misc common functions
*****************************************************************************
- * Copyright (C) 2003-2013 x264 project
+ * Copyright (C) 2003-2016 x264 project
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Loren Merritt <lorenm@u.washington.edu>
memset( var, 0, size );\
} while( 0 )
+/* Macros for merging multiple allocations into a single large malloc, for improved
+ * use with huge pages. */
+
+/* Needs to be enough to contain any set of buffers that use combined allocations */
+#define PREALLOC_BUF_SIZE 1024
+
+#define PREALLOC_INIT\
+ int prealloc_idx = 0;\
+ size_t prealloc_size = 0;\
+ uint8_t **preallocs[PREALLOC_BUF_SIZE];
+
+#define PREALLOC( var, size )\
+do {\
+ var = (void*)prealloc_size;\
+ preallocs[prealloc_idx++] = (uint8_t**)&var;\
+ prealloc_size += ALIGN(size, NATIVE_ALIGN);\
+} while(0)
+
+#define PREALLOC_END( ptr )\
+do {\
+ CHECKED_MALLOC( ptr, prealloc_size );\
+ while( prealloc_idx-- )\
+ *preallocs[prealloc_idx] += (intptr_t)ptr;\
+} while(0)
+
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
#define X264_BFRAME_MAX 16
#define NALU_OVERHEAD 5 // startcode + NAL type costs 5 bytes per frame
#define FILLER_OVERHEAD (NALU_OVERHEAD+1)
+#define SEI_OVERHEAD (NALU_OVERHEAD - (h->param.b_annexb && !h->param.i_avcintra_class && (h->out.i_nal-1)))
/****************************************************************************
* Includes
#include <assert.h>
#include <limits.h>
-#if HAVE_OPENCL
-#include "opencl.h"
-#endif
-
#if HAVE_INTERLACED
# define MB_INTERLACED h->mb.b_interlaced
# define SLICE_MBAFF h->sh.b_mbaff
};
#include "x264.h"
+#if HAVE_OPENCL
+#include "opencl.h"
+#endif
#include "cabac.h"
#include "bitstream.h"
#include "set.h"
static ALWAYS_INLINE uint16_t x264_cabac_mvd_sum( uint8_t *mvdleft, uint8_t *mvdtop )
{
- int amvd0 = abs(mvdleft[0]) + abs(mvdtop[0]);
- int amvd1 = abs(mvdleft[1]) + abs(mvdtop[1]);
+ int amvd0 = mvdleft[0] + mvdtop[0];
+ int amvd1 = mvdleft[1] + mvdtop[1];
amvd0 = (amvd0 > 2) + (amvd0 > 32);
amvd1 = (amvd1 > 2) + (amvd1 > 32);
return amvd0 + (amvd1<<8);
uint8_t *nal_buffer;
int nal_buffer_size;
+ x264_t *reconfig_h;
+ int reconfig;
+
/**** thread synchronization starts here ****/
/* frame number/poc */
int (*dequant4_mf[4])[16]; /* [4][6][16] */
int (*dequant8_mf[4])[64]; /* [4][6][64] */
/* quantization matrix for trellis, [cqm][qp][coef] */
- int (*unquant4_mf[4])[16]; /* [4][52][16] */
- int (*unquant8_mf[4])[64]; /* [4][52][64] */
+ int (*unquant4_mf[4])[16]; /* [4][QP_MAX_SPEC+1][16] */
+ int (*unquant8_mf[4])[64]; /* [4][QP_MAX_SPEC+1][64] */
/* quantization matrix for deadzone */
- udctcoef (*quant4_mf[4])[16]; /* [4][52][16] */
- udctcoef (*quant8_mf[4])[64]; /* [4][52][64] */
- udctcoef (*quant4_bias[4])[16]; /* [4][52][16] */
- udctcoef (*quant8_bias[4])[64]; /* [4][52][64] */
- udctcoef (*quant4_bias0[4])[16]; /* [4][52][16] */
- udctcoef (*quant8_bias0[4])[64]; /* [4][52][64] */
+ udctcoef (*quant4_mf[4])[16]; /* [4][QP_MAX_SPEC+1][16] */
+ udctcoef (*quant8_mf[4])[64]; /* [4][QP_MAX_SPEC+1][64] */
+ udctcoef (*quant4_bias[4])[16]; /* [4][QP_MAX_SPEC+1][16] */
+ udctcoef (*quant8_bias[4])[64]; /* [4][QP_MAX_SPEC+1][64] */
+ udctcoef (*quant4_bias0[4])[16]; /* [4][QP_MAX_SPEC+1][16] */
+ udctcoef (*quant8_bias0[4])[64]; /* [4][QP_MAX_SPEC+1][64] */
udctcoef (*nr_offset_emergency)[4][64];
/* mv/ref cost arrays. */
* and won't be copied from one thread to another */
/* mb table */
+ uint8_t *base; /* base pointer for all malloced data in this mb */
int8_t *type; /* mb type */
uint8_t *partition; /* mb partition */
int8_t *qp; /* mb qp */
ALIGNED_16( dctcoef fenc_dct4[16][16] );
/* Psy RD SATD/SA8D scores cache */
- ALIGNED_16( uint64_t fenc_hadamard_cache[9] );
- ALIGNED_16( uint32_t fenc_satd_cache[32] );
+ ALIGNED_N( uint64_t fenc_hadamard_cache[9] );
+ ALIGNED_N( uint32_t fenc_satd_cache[32] );
/* pointer over mb of the frame to be compressed */
pixel *p_fenc[3]; /* y,u,v */
/* stats */
struct
{
- /* Current frame stats */
- x264_frame_stat_t frame;
-
/* Cumulated stats */
/* per slice info */
/* num p-frames weighted */
int i_wpred[2];
+ /* Current frame stats */
+ x264_frame_stat_t frame;
} stat;
/* 0 = luma 4x4, 1 = luma 8x8, 2 = chroma 4x4, 3 = chroma 8x8 */
uint32_t (*nr_residual_sum)[64];
uint32_t *nr_count;
- ALIGNED_16( udctcoef nr_offset_denoise[4][64] );
- ALIGNED_16( uint32_t nr_residual_sum_buf[2][4][64] );
+ ALIGNED_N( udctcoef nr_offset_denoise[4][64] );
+ ALIGNED_N( uint32_t nr_residual_sum_buf[2][4][64] );
uint32_t nr_count_buf[2][4];
uint8_t luma2chroma_pixel[7]; /* Subsampled pixel size */
x264_deblock_function_t loopf;
x264_bitstream_function_t bsf;
-#if HAVE_VISUALIZE
- struct visualize_t *visualize;
-#endif
x264_lookahead_t *lookahead;
#if HAVE_OPENCL