Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • videolan/x264
  • EwoutH/x264
  • gramner/x264
  • BugMaster/x264
  • MaskRay/x264
  • thresh/x264
  • tpm/x264
  • wolfired/x264
  • ifb/x264
  • robinstorm/x264
  • ltnokiago/x264
  • janne/x264
  • Kromjunya/x264
  • trisnaayu0596/x264
  • felipegarcia1402/x264
  • coder2004/x264
  • philou/x264
  • walagnatalia/x264
  • DonDiego/x264
  • JHammler/x264
  • qyot27/x264
  • dwbuiten/x264
  • Kagami/x264
  • andriy-andreyev/x264
  • gxw/x264
  • trofi/x264
  • kierank/x264
  • aureliendavid/x264
  • galad/x264
  • roommini/x264
  • ocrete/x264
  • mstorsjo/x264
  • yinsj0116/x264
  • mamonet/x264
  • 1div0/x264
  • ko1265/x264
  • sergiomb2/x264
  • xutongda/x264
  • wenzhiwu/x264
  • arrowd/x264
  • FranceBB/x264
  • ziemek99/x264
  • longervision/x264
  • xopok/x264
  • jbk/x264
  • szatmary/x264
  • pekdon/x264
  • Jiangguyu/x264
  • jrtc27/x264
  • kankanol1/x264
  • gxwLite/x264
  • brad/x264
  • Gc6026/x264
  • jdek/x264
  • appcrash/x264
  • tguillem/x264
  • As/x264
  • wevian/x264
  • wangluls/x264
  • RellikJaeger/x264
  • hum/x264
  • rogerhardiman/x264
  • jankowalski12611/x264
  • zhijie1996/x264
  • yinshiyou/x264
  • Freed-Wu/x264
  • yajcoca/x264
  • bUd/x264
  • chienvannguyen2020/x264
  • nurbinakhatun386/x264
  • Siberiawind/x-264-meson
  • HecaiYuan/x264
  • david.chen/x264
  • Ytsejam76/x264
  • robUx4/x264
  • zhaoshiz/x-264-arm64ec
  • yintong.ustc/x-264-bd-ventana
  • nekobasu/x264
  • Courmisch/x264
  • BD-qjy/x264
  • quink/x264
  • markos/x264
  • pranavk/x264
  • robxnano/x264
84 results
Show changes
......@@ -30,14 +30,14 @@ typedef struct x264_threadpool_t x264_threadpool_t;
#if HAVE_THREAD
#define x264_threadpool_init x264_template(threadpool_init)
int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
void (*init_func)(void *), void *init_arg );
X264_API int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
void (*init_func)(void *), void *init_arg );
#define x264_threadpool_run x264_template(threadpool_run)
void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg );
X264_API void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg );
#define x264_threadpool_wait x264_template(threadpool_wait)
void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg );
X264_API void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg );
#define x264_threadpool_delete x264_template(threadpool_delete)
void x264_threadpool_delete( x264_threadpool_t *pool );
X264_API void x264_threadpool_delete( x264_threadpool_t *pool );
#else
#define x264_threadpool_init(p,t,f,a) -1
#define x264_threadpool_run(p,f,a)
......
......@@ -78,33 +78,7 @@ cglobal cpu_sfence
sfence
ret
%if ARCH_X86_64
;-----------------------------------------------------------------------------
; intptr_t stack_align( void (*func)(void*), ... ); (up to 5 args)
;-----------------------------------------------------------------------------
cvisible stack_align
mov rax, r0mp
mov r0, r1mp
mov r1, r2mp
mov r2, r3mp
mov r3, r4mp
mov r4, r5mp
push rbp
mov rbp, rsp
%if WIN64
sub rsp, 40 ; shadow space + r4
%endif
and rsp, ~(STACK_ALIGNMENT-1)
%if WIN64
mov [rsp+32], r4
%endif
call rax
leave
ret
%else
%if ARCH_X86_64 == 0
;-----------------------------------------------------------------------------
; int cpu_cpuid_test( void )
; return 0 if unsupported
......@@ -130,24 +104,4 @@ cglobal cpu_cpuid_test
pop ebx
popfd
ret
cvisible stack_align
push ebp
mov ebp, esp
sub esp, 20
and esp, ~(STACK_ALIGNMENT-1)
mov r0, [ebp+12]
mov r1, [ebp+16]
mov r2, [ebp+20]
mov [esp+ 0], r0
mov [esp+ 4], r1
mov [esp+ 8], r2
mov r0, [ebp+24]
mov r1, [ebp+28]
mov [esp+12], r0
mov [esp+16], r1
call [ebp+ 8]
leave
ret
%endif
......@@ -128,7 +128,7 @@ cl_ldflags() {
}
cc_check() {
if [ -z "$3" ]; then
if [ -z "$3$4" ]; then
if [ -z "$1$2" ]; then
log_check "whether $CC works"
elif [ -z "$1" ]; then
......@@ -138,7 +138,11 @@ cc_check() {
fi
elif [ -z "$1" ]; then
if [ -z "$2" ]; then
log_check "whether $CC supports $3"
if [ -z "$3" ]; then
log_check "whether $CC supports $4"
else
log_check "whether $CC supports $3"
fi
else
log_check "whether $CC supports $3 with $2"
fi
......@@ -149,11 +153,14 @@ cc_check() {
for arg in $1; do
echo "#include <$arg>" >> conftest.c
done
if [ -n "$4" ]; then
echo "$4" >> conftest.c
fi
echo "int main (void) { $3 return 0; }" >> conftest.c
if [ $compiler_style = MS ]; then
cc_cmd="$CC conftest.c $(cc_cflags $CFLAGS $CHECK_CFLAGS $2) -link $(cl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
cc_cmd="$CC conftest.c $(cc_cflags $CFLAGS $CFLAGSCLI $CHECK_CFLAGS $2) -link $(cl_ldflags $2 $LDFLAGSCLI $LDFLAGS)"
else
cc_cmd="$CC conftest.c $CFLAGS $CHECK_CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
cc_cmd="$CC conftest.c $CFLAGS $CFLAGSCLI $CHECK_CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest"
fi
if $cc_cmd >conftest.log 2>&1; then
res=$?
......@@ -380,6 +387,8 @@ opencl="yes"
vsx="auto"
CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
CFLAGSSO="$CFLAGSSO"
CFLAGSCLI="$CFLAGSCLI"
LDFLAGS="$LDFLAGS"
LDFLAGSCLI="$LDFLAGSCLI"
ASFLAGS="$ASFLAGS -I. -I\$(SRCPATH)"
......@@ -394,7 +403,7 @@ NL="
"
# list of all preprocessor HAVE values we can define
CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON AARCH64 BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
MSA MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10"
......@@ -611,6 +620,15 @@ if [ $compiler = GNU ]; then
if cc_check '' -Werror=unknown-warning-option ; then
CHECK_CFLAGS="$CHECK_CFLAGS -Werror=unknown-warning-option"
fi
if cc_check '' -Werror=unknown-attributes ; then
CHECK_CFLAGS="$CHECK_CFLAGS -Werror=unknown-attributes"
fi
if cc_check '' -Werror=attributes ; then
CHECK_CFLAGS="$CHECK_CFLAGS -Werror=attributes"
fi
if cc_check '' -Werror=ignored-attributes ; then
CHECK_CFLAGS="$CHECK_CFLAGS -Werror=ignored-attributes"
fi
fi
libm=""
......@@ -886,34 +904,36 @@ if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o
pic="yes"
fi
if [ $compiler = GNU -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
if cc_check '' -mpreferred-stack-boundary=6 ; then
CFLAGS="$CFLAGS -mpreferred-stack-boundary=6"
stack_alignment=64
elif cc_check '' -mstack-alignment=64 ; then
CFLAGS="$CFLAGS -mstack-alignment=64"
stack_alignment=64
elif [ $stack_alignment -lt 16 ] ; then
if cc_check '' -mpreferred-stack-boundary=4 ; then
CFLAGS="$CFLAGS -mpreferred-stack-boundary=4"
stack_alignment=16
elif cc_check '' -mstack-alignment=16 ; then
CFLAGS="$CFLAGS -mstack-alignment=16"
stack_alignment=16
if cc_check '' '' '' '__attribute__((force_align_arg_pointer))' ; then
if [ $compiler = GNU -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
if cc_check '' -mpreferred-stack-boundary=6 ; then
CFLAGS="$CFLAGS -mpreferred-stack-boundary=6"
stack_alignment=64
elif cc_check '' -mstack-alignment=64 ; then
CFLAGS="$CFLAGS -mstack-alignment=64"
stack_alignment=64
elif [ $stack_alignment -lt 16 ] ; then
if cc_check '' -mpreferred-stack-boundary=4 ; then
CFLAGS="$CFLAGS -mpreferred-stack-boundary=4"
stack_alignment=16
elif cc_check '' -mstack-alignment=16 ; then
CFLAGS="$CFLAGS -mstack-alignment=16"
stack_alignment=16
fi
fi
fi
elif [ $compiler = ICC -a $ARCH = X86 ]; then
# icc on linux has various degrees of mod16 stack support
if [ $SYS = LINUX ]; then
# >= 12 defaults to a mod16 stack
if cpp_check "" "" "__INTEL_COMPILER >= 1200" ; then
stack_alignment=16
# 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
elif cpp_check "" "" "__INTEL_COMPILER >= 1100" ; then
CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
stack_alignment=16
elif [ $compiler = ICC -a $ARCH = X86 ]; then
# icc on linux has various degrees of mod16 stack support
if [ $SYS = LINUX ]; then
# >= 12 defaults to a mod16 stack
if cpp_check "" "" "__INTEL_COMPILER >= 1200" ; then
stack_alignment=16
# 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so.
elif cpp_check "" "" "__INTEL_COMPILER >= 1100" ; then
CFLAGS="$CFLAGS -falign-stack=assume-16-byte"
stack_alignment=16
fi
# < 11 is completely incapable of keeping a mod16 stack
fi
# < 11 is completely incapable of keeping a mod16 stack
fi
fi
......@@ -951,8 +971,10 @@ fi
if [ $asm = auto -a $ARCH = AARCH64 ] ; then
if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM64)' ; then
define HAVE_AARCH64
define HAVE_NEON
elif cc_check '' '' '__asm__("cmeq v0.8h, v0.8h, #0");' ; then
define HAVE_AARCH64
define HAVE_NEON
ASFLAGS="$ASFLAGS -c"
else
......@@ -1007,6 +1029,7 @@ if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
[ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
if pkg_check x264 ; then
X264_LIBS="$($PKGCONFIG --libs x264)"
X264_CFLAGS="$($PKGCONFIG --cflags x264)"
X264_INCLUDE_DIR="${X264_INCLUDE_DIR-$($PKGCONFIG --variable=includedir x264)}"
configure_system_override "$X264_INCLUDE_DIR" || die "Detection of system libx264 configuration failed"
else
......@@ -1308,6 +1331,10 @@ if cc_check '' -Wmaybe-uninitialized ; then
CFLAGS="-Wno-maybe-uninitialized $CFLAGS"
fi
if [ $compiler = GNU ] && cc_check '' -fvisibility=hidden ; then
CFLAGS="$CFLAGS -fvisibility=hidden"
fi
if [ $compiler = ICC -o $compiler = ICL ] ; then
if cc_check 'extras/intel_dispatcher.h' '' 'x264_intel_dispatcher_override();' ; then
define HAVE_INTEL_DISPATCHER
......@@ -1365,12 +1392,22 @@ EOF
${SRCPATH}/version.sh >> x264_config.h
if [ "$shared" = "yes" ]; then
CFLAGSSO="$CFLAGSSO -DX264_API_EXPORTS"
fi
if [ "$cli_libx264" = "system" ] ; then
if [ "$shared" = "yes" ]; then
CLI_LIBX264='$(SONAME)'
if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
CLI_LIBX264='$(IMPLIBNAME)'
else
CLI_LIBX264='$(SONAME)'
fi
CFLAGSCLI="$CFLAGSCLI -DX264_API_IMPORTS"
else
CLI_LIBX264=
LDFLAGSCLI="$X264_LIBS $LDFLAGSCLI"
CFLAGSCLI="$CFLAGSCLI $X264_CFLAGS"
cc_check 'stdint.h x264.h' '' 'x264_encoder_open(0);' || die "System libx264 can't be used for compilation of this version"
fi
else
......@@ -1409,7 +1446,11 @@ else # gcc/icc
LIBX264=libx264.a
[ -n "$RC" ] && RCFLAGS="$RCFLAGS -I. -o "
fi
[ $compiler != GNU ] && CFLAGS="$(cc_cflags $CFLAGS)"
if [ $compiler != GNU ]; then
CFLAGS="$(cc_cflags $CFLAGS)"
CFLAGSSO="$(cc_cflags $CFLAGSSO)"
CFLAGSCLI="$(cc_cflags $CFLAGSCLI)"
fi
if [ $compiler = ICC -o $compiler = ICL ]; then
# icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
[ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
......@@ -1448,13 +1489,17 @@ SYS_ARCH=$ARCH
SYS=$SYS
CC=$CC
CFLAGS=$CFLAGS
CFLAGSSO=$CFLAGSSO
CFLAGSCLI=$CFLAGSCLI
COMPILER=$compiler
COMPILER_STYLE=$compiler_style
DEPMM=$DEPMM
DEPMT=$DEPMT
LD=$LD
LDFLAGS=$LDFLAGS
LDFLAGSCLI=$LDFLAGSCLI
LIBX264=$LIBX264
CLI_LIBX264=$CLI_LIBX264
AR=$AR
RANLIB=$RANLIB
STRIP=$STRIP
......@@ -1490,14 +1535,7 @@ if [ "$shared" = "yes" ]; then
echo "SONAME=libx264-$API.dll" >> config.mak
if [ $compiler_style = MS ]; then
echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
# GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations
# MSVC link does not act similarly, so it is required to make an export definition out of x264.h and use it at link time
echo "SOFLAGS=-dll -def:x264.def -implib:\$(IMPLIBNAME) $SOFLAGS" >> config.mak
echo "EXPORTS" > x264.def
# export API functions
grep "^\(int\|void\|x264_t\).*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264.*\)(.*/\1/;s/open/open_$API/g" >> x264.def
# export API variables/data. must be flagged with the DATA keyword
grep "extern.*x264" ${SRCPATH}/x264.h | sed -e "s/.*\(x264\w*\)\W.*/\1 DATA/;" >> x264.def
echo "SOFLAGS=-dll -implib:\$(IMPLIBNAME) $SOFLAGS" >> config.mak
else
echo 'IMPLIBNAME=libx264.dll.a' >> config.mak
echo "SOFLAGS=-shared -Wl,--out-implib,\$(IMPLIBNAME) $SOFLAGS" >> config.mak
......@@ -1524,9 +1562,6 @@ if [ "$static" = "yes" ]; then
echo 'install: install-lib-static' >> config.mak
fi
echo "LDFLAGSCLI = $LDFLAGSCLI" >> config.mak
echo "CLI_LIBX264 = $CLI_LIBX264" >> config.mak
cat > x264.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
......@@ -1538,7 +1573,7 @@ Description: H.264 (MPEG4 AVC) encoder library
Version: $(grep POINTVER < x264_config.h | sed -e 's/.* "//; s/".*//; s/ .*//')
Libs: -L$libdir -lx264 $([ "$shared" = "yes" ] || echo $libpthread $libm $libdl)
Libs.private: $([ "$shared" = "yes" ] && echo $libpthread $libm $libdl)
Cflags: -I$includedir
Cflags: -I$includedir $([ "$shared" = "yes" ] && echo "-DX264_API_IMPORTS")
EOF
filters="crop select_every"
......
......@@ -73,7 +73,7 @@ typedef struct x264_api_t
int (*encoder_invalidate_reference)( x264_t *, int64_t pts );
} x264_api_t;
static x264_api_t *encoder_open( x264_param_t *param )
REALIGN_STACK x264_t *x264_encoder_open( x264_param_t *param )
{
x264_api_t *api = calloc( 1, sizeof( x264_api_t ) );
if( !api )
......@@ -118,82 +118,77 @@ static x264_api_t *encoder_open( x264_param_t *param )
return NULL;
}
return api;
}
x264_t *x264_encoder_open( x264_param_t *param )
{
/* x264_t is opaque */
return (x264_t *)x264_stack_align( encoder_open, param );
return (x264_t *)api;
}
void x264_encoder_close( x264_t *h )
REALIGN_STACK void x264_encoder_close( x264_t *h )
{
x264_api_t *api = (x264_api_t *)h;
x264_stack_align( api->encoder_close, api->x264 );
api->encoder_close( api->x264 );
free( api );
}
void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
REALIGN_STACK void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
{
x264_api_t *api = (x264_api_t *)h;
x264_stack_align( api->nal_encode, api->x264, dst, nal );
api->nal_encode( api->x264, dst, nal );
}
int x264_encoder_reconfig( x264_t *h, x264_param_t *param)
REALIGN_STACK int x264_encoder_reconfig( x264_t *h, x264_param_t *param)
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_reconfig, api->x264, param );
return api->encoder_reconfig( api->x264, param );
}
void x264_encoder_parameters( x264_t *h, x264_param_t *param )
REALIGN_STACK void x264_encoder_parameters( x264_t *h, x264_param_t *param )
{
x264_api_t *api = (x264_api_t *)h;
x264_stack_align( api->encoder_parameters, api->x264, param );
api->encoder_parameters( api->x264, param );
}
int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
REALIGN_STACK int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_headers, api->x264, pp_nal, pi_nal );
return api->encoder_headers( api->x264, pp_nal, pi_nal );
}
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 )
REALIGN_STACK 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 )
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_encode, api->x264, pp_nal, pi_nal, pic_in, pic_out );
return api->encoder_encode( api->x264, pp_nal, pi_nal, pic_in, pic_out );
}
int x264_encoder_delayed_frames( x264_t *h )
REALIGN_STACK int x264_encoder_delayed_frames( x264_t *h )
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_delayed_frames, api->x264 );
return api->encoder_delayed_frames( api->x264 );
}
int x264_encoder_maximum_delayed_frames( x264_t *h )
REALIGN_STACK int x264_encoder_maximum_delayed_frames( x264_t *h )
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_maximum_delayed_frames, api->x264 );
return api->encoder_maximum_delayed_frames( api->x264 );
}
void x264_encoder_intra_refresh( x264_t *h )
REALIGN_STACK void x264_encoder_intra_refresh( x264_t *h )
{
x264_api_t *api = (x264_api_t *)h;
x264_stack_align( api->encoder_intra_refresh, api->x264 );
api->encoder_intra_refresh( api->x264 );
}
int x264_encoder_invalidate_reference( x264_t *h, int64_t pts )
REALIGN_STACK int x264_encoder_invalidate_reference( x264_t *h, int64_t pts )
{
x264_api_t *api = (x264_api_t *)h;
return x264_stack_align( api->encoder_invalidate_reference, api->x264, pts );
return api->encoder_invalidate_reference( api->x264, pts );
}
......@@ -370,6 +370,8 @@ static int bitstream_check_buffer_internal( x264_t *h, int size, int b_cabac, in
if( (b_cabac && (h->cabac.p_end - h->cabac.p < size)) ||
(h->out.bs.p_end - h->out.bs.p < size) )
{
if( size > INT_MAX - h->out.i_bitstream )
return -1;
int buf_size = h->out.i_bitstream + size;
uint8_t *buf = x264_malloc( buf_size );
if( !buf )
......@@ -470,7 +472,9 @@ static int validate_parameters( x264_t *h, int b_open )
}
#endif
if( h->param.i_width <= 0 || h->param.i_height <= 0 )
#define MAX_RESOLUTION 16384
if( h->param.i_width <= 0 || h->param.i_height <= 0 ||
h->param.i_width > MAX_RESOLUTION || h->param.i_height > MAX_RESOLUTION )
{
x264_log( h, X264_LOG_ERROR, "invalid width x height (%dx%d)\n",
h->param.i_width, h->param.i_height );
......@@ -862,8 +866,8 @@ static int validate_parameters( x264_t *h, int b_open )
h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, -1, QP_MAX );
h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
h->param.rc.f_ip_factor = x264_clip3f( h->param.rc.f_ip_factor, 0.01, 10.0 );
h->param.rc.f_pb_factor = x264_clip3f( h->param.rc.f_pb_factor, 0.01, 10.0 );
if( h->param.rc.i_rc_method == X264_RC_CRF )
{
h->param.rc.i_qp_constant = h->param.rc.f_rf_constant + QP_BD_OFFSET;
......@@ -1647,9 +1651,13 @@ x264_t *x264_encoder_open( x264_param_t *param )
}
h->out.i_nal = 0;
h->out.i_bitstream = X264_MAX( 1000000, h->param.i_width * h->param.i_height * 4
* ( h->param.rc.i_rc_method == X264_RC_ABR ? pow( 0.95, h->param.rc.i_qp_min )
: pow( 0.95, h->param.rc.i_qp_constant ) * X264_MAX( 1, h->param.rc.f_ip_factor )));
h->out.i_bitstream = x264_clip3f(
h->param.i_width * h->param.i_height * 4
* ( h->param.rc.i_rc_method == X264_RC_ABR
? pow( 0.95, h->param.rc.i_qp_min )
: pow( 0.95, h->param.rc.i_qp_constant ) * X264_MAX( 1, h->param.rc.f_ip_factor ) ),
1000000, INT_MAX/3
);
h->nal_buffer_size = h->out.i_bitstream * 3/2 + 4 + 64; /* +4 for startcode, +64 for nal_escape assembly padding */
CHECKED_MALLOC( h->nal_buffer, h->nal_buffer_size );
......@@ -1940,11 +1948,13 @@ static int nal_end( x264_t *h )
}
static int check_encapsulated_buffer( x264_t *h, x264_t *h0, int start,
int previous_nal_size, int necessary_size )
int64_t previous_nal_size, int64_t necessary_size )
{
if( h0->nal_buffer_size < necessary_size )
{
necessary_size *= 2;
if( necessary_size > INT_MAX )
return -1;
uint8_t *buf = x264_malloc( necessary_size );
if( !buf )
return -1;
......@@ -1966,12 +1976,14 @@ static int check_encapsulated_buffer( x264_t *h, x264_t *h0, int start,
static int encoder_encapsulate_nals( x264_t *h, int start )
{
x264_t *h0 = h->thread[0];
int nal_size = 0, previous_nal_size = 0;
int64_t nal_size = 0, previous_nal_size = 0;
if( h->param.nalu_process )
{
for( int i = start; i < h->out.i_nal; i++ )
nal_size += h->out.nal[i].i_payload;
if( nal_size > INT_MAX )
return -1;
return nal_size;
}
......@@ -1982,7 +1994,7 @@ static int encoder_encapsulate_nals( x264_t *h, int start )
nal_size += h->out.nal[i].i_payload;
/* Worst-case NAL unit escaping: reallocate the buffer if it's too small. */
int necessary_size = previous_nal_size + nal_size * 3/2 + h->out.i_nal * 4 + 4 + 64;
int64_t necessary_size = previous_nal_size + nal_size * 3/2 + h->out.i_nal * 4 + 4 + 64;
for( int i = start; i < h->out.i_nal; i++ )
necessary_size += h->out.nal[i].i_padding;
if( check_encapsulated_buffer( h, h0, start, previous_nal_size, necessary_size ) )
......@@ -3879,7 +3891,7 @@ static int encoder_frame_end( x264_t *h, x264_t *thread_current,
* We don't know the size of the last slice until encapsulation so we add filler to the encapsulated NAL */
if( h->param.i_avcintra_class )
{
if( check_encapsulated_buffer( h, h->thread[0], h->out.i_nal, frame_size, frame_size + filler ) < 0 )
if( check_encapsulated_buffer( h, h->thread[0], h->out.i_nal, frame_size, (int64_t)frame_size + filler ) < 0 )
return -1;
x264_nal_t *nal = &h->out.nal[h->out.i_nal-1];
......
......@@ -87,7 +87,7 @@ static void lookahead_slicetype_decide( x264_t *h )
x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex );
}
static void *lookahead_thread_internal( x264_t *h )
REALIGN_STACK static void *lookahead_thread( x264_t *h )
{
while( !h->lookahead->b_exit_thread )
{
......@@ -122,10 +122,6 @@ static void *lookahead_thread_internal( x264_t *h )
return NULL;
}
static void *lookahead_thread( x264_t *h )
{
return (void*)x264_stack_align( lookahead_thread_internal, h );
}
#endif
int x264_lookahead_init( x264_t *h, int i_slicetype_length )
......
......@@ -713,8 +713,9 @@ void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init )
rc->vbv_max_rate = vbv_max_bitrate;
rc->buffer_size = vbv_buffer_size;
rc->single_frame_vbv = rc->buffer_rate * 1.1 > rc->buffer_size;
rc->cbr_decay = 1.0 - rc->buffer_rate / rc->buffer_size
* 0.5 * X264_MAX(0, 1.5 - rc->buffer_rate * rc->fps / rc->bitrate);
if( rc->b_abr && h->param.rc.i_rc_method == X264_RC_ABR )
rc->cbr_decay = 1.0 - rc->buffer_rate / rc->buffer_size
* 0.5 * X264_MAX(0, 1.5 - rc->buffer_rate * rc->fps / rc->bitrate);
if( h->param.rc.i_rc_method == X264_RC_CRF && h->param.rc.f_rf_constant_max )
{
rc->rate_factor_max_increment = h->param.rc.f_rf_constant_max - h->param.rc.f_rf_constant;
......
......@@ -483,6 +483,10 @@ static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x2
int src_pix_fmt_inv = convert_csp_to_pix_fmt( info->csp ^ X264_CSP_HIGH_DEPTH );
int dst_pix_fmt_inv = convert_csp_to_pix_fmt( h->dst_csp ^ X264_CSP_HIGH_DEPTH );
FAIL_IF_ERROR( h->dst.width <= 0 || h->dst.height <= 0 ||
h->dst.width > MAX_RESOLUTION || h->dst.height > MAX_RESOLUTION,
"invalid width x height (%dx%d)\n", h->dst.width, h->dst.height );
/* confirm swscale can support this conversion */
FAIL_IF_ERROR( src_pix_fmt == AV_PIX_FMT_NONE && src_pix_fmt_inv != AV_PIX_FMT_NONE,
"input colorspace %s with bit depth %d is not supported\n", av_get_pix_fmt_name( src_pix_fmt_inv ),
......
......@@ -65,22 +65,22 @@ int x264_cli_csp_depth_factor( int csp )
return (csp & X264_CSP_HIGH_DEPTH) ? 2 : 1;
}
uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane )
int64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane )
{
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;
int64_t size = (int64_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;
}
uint64_t x264_cli_pic_size( int csp, int width, int height )
int64_t x264_cli_pic_size( int csp, int width, int height )
{
if( x264_cli_csp_is_invalid( csp ) )
return 0;
uint64_t size = 0;
int64_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 );
......@@ -107,7 +107,7 @@ static int cli_pic_init_internal( cli_pic_t *pic, int csp, int width, int height
if( alloc )
{
size_t size = (size_t)(height * x264_cli_csps[csp_mask].height[i]) * stride;
int64_t size = (int64_t)(height * x264_cli_csps[csp_mask].height[i]) * stride;
pic->img.plane[i] = x264_malloc( size );
if( !pic->img.plane[i] )
return -1;
......@@ -182,11 +182,13 @@ int x264_cli_mmap_init( cli_mmap_t *h, FILE *fh )
* in segfaults. We have to pad the buffer size as a workaround to avoid that. */
#define MMAP_PADDING 64
void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size )
void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, int64_t size )
{
#if defined(_WIN32) || HAVE_MMAP
uint8_t *base;
int align = offset & h->align_mask;
if( size < 0 || size > (SIZE_MAX - MMAP_PADDING - align) )
return NULL;
offset -= align;
size += align;
#ifdef _WIN32
......@@ -196,10 +198,10 @@ void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size )
{
/* It's not possible to do the POSIX mmap() remapping trick on Windows, so if the padding crosses a
* page boundary past the end of the file we have to copy the entire frame into a padded buffer. */
if( (base = MapViewOfFile( h->map_handle, FILE_MAP_READ, offset >> 32, offset, size )) )
if( (base = MapViewOfFile( h->map_handle, FILE_MAP_READ, (uint64_t)offset >> 32, offset, size )) )
{
uint8_t *buf = NULL;
HANDLE anon_map = CreateFileMappingW( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, padded_size, NULL );
HANDLE anon_map = CreateFileMappingW( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, (uint64_t)padded_size >> 32, padded_size, NULL );
if( anon_map )
{
if( (buf = MapViewOfFile( anon_map, FILE_MAP_WRITE, 0, 0, 0 )) )
......@@ -213,7 +215,7 @@ void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size )
return buf;
}
}
else if( (base = MapViewOfFile( h->map_handle, FILE_MAP_READ, offset >> 32, offset, padded_size )) )
else if( (base = MapViewOfFile( h->map_handle, FILE_MAP_READ, (uint64_t)offset >> 32, offset, padded_size )) )
{
/* PrefetchVirtualMemory() is only available on Windows 8 and newer. */
if( h->prefetch_virtual_memory )
......@@ -249,13 +251,15 @@ void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size )
return NULL;
}
int x264_cli_munmap( cli_mmap_t *h, void *addr, size_t size )
int x264_cli_munmap( cli_mmap_t *h, void *addr, int64_t size )
{
#if defined(_WIN32) || HAVE_MMAP
void *base = (void*)((intptr_t)addr & ~h->align_mask);
#ifdef _WIN32
return !UnmapViewOfFile( base );
#else
if( size < 0 || size > (SIZE_MAX - MMAP_PADDING - ((intptr_t)addr - (intptr_t)base)) )
return -1;
return munmap( base, size + MMAP_PADDING + (intptr_t)addr - (intptr_t)base );
#endif
#endif
......
......@@ -132,8 +132,8 @@ int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height );
int x264_cli_pic_alloc_aligned( cli_pic_t *pic, int csp, int width, int height );
int x264_cli_pic_init_noalloc( cli_pic_t *pic, int csp, int width, int height );
void x264_cli_pic_clean( cli_pic_t *pic );
uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane );
uint64_t x264_cli_pic_size( int csp, int width, int height );
int64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane );
int64_t x264_cli_pic_size( int csp, int width, int height );
const x264_cli_csp_t *x264_cli_get_csp( int csp );
typedef struct
......@@ -151,8 +151,8 @@ typedef struct
} cli_mmap_t;
int x264_cli_mmap_init( cli_mmap_t *h, FILE *fh );
void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size );
int x264_cli_munmap( cli_mmap_t *h, void *addr, size_t size );
void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, int64_t size );
int x264_cli_munmap( cli_mmap_t *h, void *addr, int64_t size );
void x264_cli_mmap_close( cli_mmap_t *h );
#endif
......@@ -33,8 +33,8 @@ typedef struct
{
FILE *fh;
int next_frame;
uint64_t plane_size[4];
uint64_t frame_size;
int64_t plane_size[4];
int64_t frame_size;
int bit_depth;
cli_mmap_t mmap;
int use_mmap;
......@@ -96,7 +96,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
if( x264_is_regular_file( h->fh ) )
{
fseek( h->fh, 0, SEEK_END );
uint64_t size = ftell( h->fh );
int64_t size = ftell( h->fh );
fseek( h->fh, 0, SEEK_SET );
info->num_frames = size / h->frame_size;
FAIL_IF_ERROR( !info->num_frames, "empty input file\n" );
......@@ -129,9 +129,9 @@ static int read_frame_internal( cli_pic_t *pic, raw_hnd_t *h, int bit_depth_uc )
/* upconvert non 16bit high depth planes to 16bit using the same
* algorithm as used in the depth filter. */
uint16_t *plane = (uint16_t*)pic->img.plane[i];
uint64_t pixel_count = h->plane_size[i];
int64_t pixel_count = h->plane_size[i];
int lshift = 16 - h->bit_depth;
for( uint64_t j = 0; j < pixel_count; j++ )
for( int64_t j = 0; j < pixel_count; j++ )
plane[j] = plane[j] << lshift;
}
}
......
......@@ -105,7 +105,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
#define NO_TIMECODE_LINE (buff[0] == '#' || buff[0] == '\n' || buff[0] == '\r')
if( tcfv == 1 )
{
uint64_t file_pos;
int64_t file_pos;
double assume_fps, seq_fps;
int start, end = -1;
int prev_start = -1, prev_end = -1;
......@@ -221,7 +221,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
}
else /* tcfv == 2 */
{
uint64_t file_pos = ftell( tcfile_in );
int64_t file_pos = ftell( tcfile_in );
h->stored_pts_num = 0;
while( fgets( buff, sizeof(buff), tcfile_in ) != NULL )
......
......@@ -34,8 +34,8 @@ typedef struct
int next_frame;
int seq_header_len;
int frame_header_len;
uint64_t frame_size;
uint64_t plane_size[3];
int64_t frame_size;
int64_t plane_size[3];
int bit_depth;
cli_mmap_t mmap;
int use_mmap;
......@@ -213,7 +213,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
if( x264_is_regular_file( h->fh ) )
{
uint64_t init_pos = ftell( h->fh );
int64_t init_pos = ftell( h->fh );
/* Find out the length of the frame header */
int len = 1;
......@@ -224,7 +224,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
h->frame_size += len;
fseek( h->fh, 0, SEEK_END );
uint64_t i_size = ftell( h->fh );
int64_t i_size = ftell( h->fh );
fseek( h->fh, init_pos, SEEK_SET );
info->num_frames = (i_size - h->seq_header_len) / h->frame_size;
FAIL_IF_ERROR( !info->num_frames, "empty input file\n" );
......@@ -285,9 +285,9 @@ static int read_frame_internal( cli_pic_t *pic, y4m_hnd_t *h, int bit_depth_uc )
/* upconvert non 16bit high depth planes to 16bit using the same
* algorithm as used in the depth filter. */
uint16_t *plane = (uint16_t*)pic->img.plane[i];
uint64_t pixel_count = h->plane_size[i];
int64_t pixel_count = h->plane_size[i];
int lshift = 16 - h->bit_depth;
for( uint64_t j = 0; j < pixel_count; j++ )
for( int64_t j = 0; j < pixel_count; j++ )
plane[j] = plane[j] << lshift;
}
}
......
......@@ -332,7 +332,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
if( x264_is_regular_file( c->fp ) && total_duration > 0 )
{
double framerate;
uint64_t filesize = ftell( c->fp );
int64_t filesize = ftell( c->fp );
if( p_flv->i_framerate_pos )
{
......@@ -342,7 +342,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
CHECK( rewrite_amf_double( c->fp, p_flv->i_duration_pos, total_duration ) );
CHECK( rewrite_amf_double( c->fp, p_flv->i_filesize_pos, filesize ) );
CHECK( rewrite_amf_double( c->fp, p_flv->i_bitrate_pos, filesize * 8 / ( total_duration * 1000 ) ) );
CHECK( rewrite_amf_double( c->fp, p_flv->i_bitrate_pos, filesize * 8.0 / ( total_duration * 1000 ) ) );
}
ret = 0;
......
......@@ -175,7 +175,7 @@ static void print_bench(void)
if( k < j )
continue;
printf( "%s_%s%s: %"PRId64"\n", benchs[i].name,
#if HAVE_MMX
#if ARCH_X86 || ARCH_X86_64
b->cpu&X264_CPU_AVX512 ? "avx512" :
b->cpu&X264_CPU_AVX2 ? "avx2" :
b->cpu&X264_CPU_BMI2 ? "bmi2" :
......@@ -206,7 +206,7 @@ static void print_bench(void)
b->cpu&X264_CPU_MSA ? "msa" :
#endif
"c",
#if HAVE_MMX
#if ARCH_X86 || ARCH_X86_64
b->cpu&X264_CPU_CACHELINE_32 ? "_c32" :
b->cpu&X264_CPU_SLOW_ATOM && b->cpu&X264_CPU_CACHELINE_64 ? "_c64_atom" :
b->cpu&X264_CPU_CACHELINE_64 ? "_c64" :
......@@ -229,7 +229,7 @@ static void print_bench(void)
static void (*simd_warmup_func)( void ) = NULL;
#define simd_warmup() do { if( simd_warmup_func ) simd_warmup_func(); } while( 0 )
#if ARCH_X86 || ARCH_X86_64
#if HAVE_MMX
int x264_stack_pagealign( int (*func)(), int align );
void x264_checkasm_warmup_avx( void );
void x264_checkasm_warmup_avx512( void );
......@@ -241,11 +241,11 @@ intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... );
#define x264_stack_pagealign( func, align ) func()
#endif
#if ARCH_AARCH64
#if HAVE_AARCH64
intptr_t x264_checkasm_call( intptr_t (*func)(), int *ok, ... );
#endif
#if ARCH_ARM
#if HAVE_ARMV6
intptr_t x264_checkasm_call_neon( intptr_t (*func)(), int *ok, ... );
intptr_t x264_checkasm_call_noneon( intptr_t (*func)(), int *ok, ... );
intptr_t (*x264_checkasm_call)( intptr_t (*func)(), int *ok, ... ) = x264_checkasm_call_noneon;
......@@ -253,7 +253,7 @@ intptr_t (*x264_checkasm_call)( intptr_t (*func)(), int *ok, ... ) = x264_checka
#define call_c1(func,...) func(__VA_ARGS__)
#if ARCH_X86_64
#if HAVE_MMX && ARCH_X86_64
/* Evil hack: detect incorrect assumptions that 32-bit ints are zero-extended to 64-bit.
* This is done by clobbering the stack with junk around the stack pointer and calling the
* assembly function through x264_checkasm_call with added dummy arguments which forces all
......@@ -269,19 +269,19 @@ void x264_checkasm_stack_clobber( uint64_t clobber, ... );
x264_checkasm_stack_clobber( r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r ); /* max_args+6 */ \
simd_warmup(); \
x264_checkasm_call(( intptr_t(*)())func, &ok, 0, 0, 0, 0, __VA_ARGS__ ); })
#elif ARCH_AARCH64 && !defined(__APPLE__)
#elif HAVE_AARCH64 && !defined(__APPLE__)
void x264_checkasm_stack_clobber( uint64_t clobber, ... );
#define call_a1(func,...) ({ \
uint64_t r = (rand() & 0xffff) * 0x0001000100010001ULL; \
x264_checkasm_stack_clobber( r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r ); /* max_args+8 */ \
x264_checkasm_call(( intptr_t(*)())func, &ok, 0, 0, 0, 0, 0, 0, __VA_ARGS__ ); })
#elif ARCH_X86 || ARCH_ARM
#elif HAVE_MMX || HAVE_ARMV6
#define call_a1(func,...) x264_checkasm_call( (intptr_t(*)())func, &ok, __VA_ARGS__ )
#else
#define call_a1 call_c1
#endif
#if ARCH_ARM
#if HAVE_ARMV6
#define call_a1_64(func,...) ((uint64_t (*)(intptr_t(*)(), int*, ...))x264_checkasm_call)( (intptr_t(*)())func, &ok, __VA_ARGS__ )
#else
#define call_a1_64 call_a1
......@@ -2601,7 +2601,7 @@ static void run_cabac_terminal_##cpu( x264_t *h, uint8_t *dst )\
DECL_CABAC(c)
#if HAVE_MMX
DECL_CABAC(asm)
#elif defined(ARCH_AARCH64)
#elif HAVE_AARCH64
DECL_CABAC(asm)
#else
#define run_cabac_decision_asm run_cabac_decision_c
......@@ -2807,7 +2807,7 @@ static int check_all_flags( void )
int ret = 0;
int cpu0 = 0, cpu1 = 0;
uint32_t cpu_detect = x264_cpu_detect();
#if ARCH_X86 || ARCH_X86_64
#if HAVE_MMX
if( cpu_detect & X264_CPU_AVX512 )
simd_warmup_func = x264_checkasm_warmup_avx512;
else if( cpu_detect & X264_CPU_AVX )
......@@ -2815,7 +2815,7 @@ static int check_all_flags( void )
#endif
simd_warmup();
#if HAVE_MMX
#if ARCH_X86 || ARCH_X86_64
if( cpu_detect & X264_CPU_MMX2 )
{
ret |= add_flags( &cpu0, &cpu1, X264_CPU_MMX | X264_CPU_MMX2, "MMX" );
......@@ -2914,7 +2914,7 @@ static int check_all_flags( void )
return ret;
}
static int main_internal( int argc, char **argv )
REALIGN_STACK int main( int argc, char **argv )
{
#ifdef _WIN32
/* Disable the Windows Error Reporting dialog */
......@@ -2973,8 +2973,3 @@ static int main_internal( int argc, char **argv )
print_bench();
return 0;
}
int main( int argc, char **argv )
{
return x264_stack_align( main_internal, argc, argv );
}
......@@ -373,7 +373,7 @@ static void print_version_info( void )
#endif
}
static int main_internal( int argc, char **argv )
REALIGN_STACK int main( int argc, char **argv )
{
if( argc == 4 && !strcmp( argv[1], "--autocomplete" ) )
return x264_cli_autocomplete( argv[2], argv[3] );
......@@ -428,11 +428,6 @@ static int main_internal( int argc, char **argv )
return ret;
}
int main( int argc, char **argv )
{
return x264_stack_align( main_internal, argc, argv );
}
static char const *strtable_lookup( const char * const table[], int idx )
{
int i = 0; while( table[i] ) i++;
......@@ -1672,6 +1667,10 @@ generic_option:
info.height, info.interlaced ? 'i' : 'p', info.sar_width, info.sar_height,
info.fps_num, info.fps_den, info.vfr ? 'v' : 'c' );
FAIL_IF_ERROR( info.width <= 0 || info.height <= 0 ||
info.width > MAX_RESOLUTION || info.height > MAX_RESOLUTION,
"invalid width x height (%dx%d)\n", info.width, info.height );
if( tcfile_name )
{
FAIL_IF_ERROR( b_user_fps, "--fps + --tcfile-in is incompatible.\n" );
......
......@@ -45,7 +45,20 @@ extern "C" {
#include "x264_config.h"
#define X264_BUILD 157
#define X264_BUILD 159
#ifdef _WIN32
# define X264_DLL_IMPORT __declspec(dllimport)
# define X264_DLL_EXPORT __declspec(dllexport)
#else
# if defined(__GNUC__) && (__GNUC__ >= 4)
# define X264_DLL_IMPORT
# define X264_DLL_EXPORT __attribute__((visibility("default")))
# else
# define X264_DLL_IMPORT
# define X264_DLL_EXPORT
# endif
#endif
/* Application developers planning to link against a shared library version of
* libx264 from a Microsoft Visual Studio or similar development environment
......@@ -53,9 +66,13 @@ extern "C" {
* This clause does not apply to MinGW, similar development environments, or non
* Windows platforms. */
#ifdef X264_API_IMPORTS
#define X264_API __declspec(dllimport)
# define X264_API X264_DLL_IMPORT
#else
#define X264_API
# ifdef X264_API_EXPORTS
# define X264_API X264_DLL_EXPORT
# else
# define X264_API
# endif
#endif
/* x264_t:
......@@ -568,7 +585,7 @@ typedef struct x264_param_t
void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque );
} x264_param_t;
void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
X264_API void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
/****************************************************************************
* H.264 level restriction information
......@@ -600,7 +617,7 @@ X264_API extern const x264_level_t x264_levels[];
/* x264_param_default:
* fill x264_param_t with default values and do CPU detection */
void x264_param_default( x264_param_t * );
X264_API void x264_param_default( x264_param_t * );
/* x264_param_parse:
* set one parameter by name.
......@@ -611,7 +628,7 @@ void x264_param_default( x264_param_t * );
* value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. */
#define X264_PARAM_BAD_NAME (-1)
#define X264_PARAM_BAD_VALUE (-2)
int x264_param_parse( x264_param_t *, const char *name, const char *value );
X264_API int x264_param_parse( x264_param_t *, const char *name, const char *value );
/****************************************************************************
* Advanced parameter handling functions
......@@ -655,13 +672,13 @@ static const char * const x264_tune_names[] = { "film", "animation", "grain", "s
* film, animation, grain, stillimage, psnr, and ssim are psy tunings.
*
* returns 0 on success, negative on failure (e.g. invalid preset/tune name). */
int x264_param_default_preset( x264_param_t *, const char *preset, const char *tune );
X264_API int x264_param_default_preset( x264_param_t *, const char *preset, const char *tune );
/* x264_param_apply_fastfirstpass:
* If first-pass mode is set (rc.b_stat_read == 0, rc.b_stat_write == 1),
* modify the encoder settings to disable options generally not useful on
* the first pass. */
void x264_param_apply_fastfirstpass( x264_param_t * );
X264_API void x264_param_apply_fastfirstpass( x264_param_t * );
/* x264_param_apply_profile:
* Applies the restrictions of the given profile.
......@@ -676,7 +693,7 @@ static const char * const x264_profile_names[] = { "baseline", "main", "high", "
* decrease them.
*
* returns 0 on success, negative on failure (e.g. invalid profile name). */
int x264_param_apply_profile( x264_param_t *, const char *profile );
X264_API int x264_param_apply_profile( x264_param_t *, const char *profile );
/****************************************************************************
* Picture structures and functions
......@@ -846,17 +863,17 @@ typedef struct x264_picture_t
/* x264_picture_init:
* initialize an x264_picture_t. Needs to be done if the calling application
* allocates its own x264_picture_t as opposed to using x264_picture_alloc. */
void x264_picture_init( x264_picture_t *pic );
X264_API void x264_picture_init( x264_picture_t *pic );
/* x264_picture_alloc:
* alloc data for a picture. You must call x264_picture_clean on it.
* returns 0 on success, or -1 on malloc failure or invalid colorspace. */
int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height );
X264_API int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height );
/* x264_picture_clean:
* free associated resource for a x264_picture_t allocated with
* x264_picture_alloc ONLY */
void x264_picture_clean( x264_picture_t *pic );
X264_API void x264_picture_clean( x264_picture_t *pic );
/****************************************************************************
* Encoder functions
......@@ -871,7 +888,7 @@ void x264_picture_clean( x264_picture_t *pic );
/* x264_encoder_open:
* create a new encoder handler, all parameters from x264_param_t are copied */
x264_t *x264_encoder_open( x264_param_t * );
X264_API x264_t *x264_encoder_open( x264_param_t * );
/* x264_encoder_reconfig:
* various parameters from x264_param_t are copied.
......@@ -886,7 +903,7 @@ x264_t *x264_encoder_open( x264_param_t * );
* more so than for other presets, many of the speed shortcuts used in ultrafast cannot be
* switched out of; using reconfig to switch between ultrafast and other presets is not
* recommended without a more fine-grained breakdown of parameters to take this into account. */
int x264_encoder_reconfig( x264_t *, x264_param_t * );
X264_API int x264_encoder_reconfig( x264_t *, x264_param_t * );
/* x264_encoder_parameters:
* copies the current internal set of parameters to the pointer provided
* by the caller. useful when the calling application needs to know
......@@ -894,32 +911,32 @@ int x264_encoder_reconfig( x264_t *, x264_param_t * );
* of the encoder after multiple x264_encoder_reconfig calls.
* note that the data accessible through pointers in the returned param struct
* (e.g. filenames) should not be modified by the calling application. */
void x264_encoder_parameters( x264_t *, x264_param_t * );
X264_API void x264_encoder_parameters( x264_t *, x264_param_t * );
/* x264_encoder_headers:
* return the SPS and PPS that will be used for the whole stream.
* *pi_nal is the number of NAL units outputted in pp_nal.
* returns the number of bytes in the returned NALs.
* returns negative on error.
* the payloads of all output NALs are guaranteed to be sequential in memory. */
int x264_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
X264_API int x264_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
/* x264_encoder_encode:
* encode one picture.
* *pi_nal is the number of NAL units outputted in pp_nal.
* returns the number of bytes in the returned NALs.
* returns negative on error and zero if no NAL units returned.
* the payloads of all output NALs are guaranteed to be sequential in memory. */
int x264_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
X264_API int x264_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
/* x264_encoder_close:
* close an encoder handler */
void x264_encoder_close( x264_t * );
X264_API void x264_encoder_close( x264_t * );
/* x264_encoder_delayed_frames:
* return the number of currently delayed (buffered) frames
* this should be used at the end of the stream, to know when you have all the encoded frames. */
int x264_encoder_delayed_frames( x264_t * );
X264_API int x264_encoder_delayed_frames( x264_t * );
/* x264_encoder_maximum_delayed_frames( x264_t * ):
* return the maximum number of delayed (buffered) frames that can occur with the current
* parameters. */
int x264_encoder_maximum_delayed_frames( x264_t * );
X264_API int x264_encoder_maximum_delayed_frames( x264_t * );
/* x264_encoder_intra_refresh:
* If an intra refresh is not in progress, begin one with the next P-frame.
* If an intra refresh is in progress, begin one as soon as the current one finishes.
......@@ -933,7 +950,7 @@ int x264_encoder_maximum_delayed_frames( x264_t * );
* behavior is undefined.
*
* Should not be called during an x264_encoder_encode. */
void x264_encoder_intra_refresh( x264_t * );
X264_API void x264_encoder_intra_refresh( x264_t * );
/* x264_encoder_invalidate_reference:
* An interactive error resilience tool, designed for use in a low-latency one-encoder-few-clients
* system. When the client has packet loss or otherwise incorrectly decodes a frame, the encoder
......@@ -956,7 +973,7 @@ void x264_encoder_intra_refresh( x264_t * );
* Should not be called during an x264_encoder_encode, but multiple calls can be made simultaneously.
*
* Returns 0 on success, negative on failure. */
int x264_encoder_invalidate_reference( x264_t *, int64_t pts );
X264_API int x264_encoder_invalidate_reference( x264_t *, int64_t pts );
#ifdef __cplusplus
}
......
......@@ -32,6 +32,8 @@
/* In microseconds */
#define UPDATE_INTERVAL 250000
#define MAX_RESOLUTION 16384
typedef void *hnd_t;
extern const char * const x264_avcintra_class_names[];
......