diff --git a/veejay-current/plugin-packs/lvdasciiart/plugins/lvd_aa.c b/veejay-current/plugin-packs/lvdasciiart/plugins/lvd_aa.c index 84310765..9d7d497f 100644 --- a/veejay-current/plugin-packs/lvdasciiart/plugins/lvd_aa.c +++ b/veejay-current/plugin-packs/lvdasciiart/plugins/lvd_aa.c @@ -616,8 +616,8 @@ int init_instance( livido_port_t *my_instance ) aa->aa_flags = 0; aa->buf[0] = (uint8_t*) livido_malloc (sizeof(uint8_t) * RUP8(w * h * 3 ) ); - aa->buf[1] = aa->buf[0] + RUP8(w*h); - aa->buf[2] = aa->buf[1] + RUP8(w*h); + aa->buf[1] = aa->buf[0] + w*h; + aa->buf[2] = aa->buf[1] + w*h; livido_property_set( my_instance, "PLUGIN_private", LIVIDO_ATOM_TYPE_VOIDPTR,1, &aa); diff --git a/veejay-current/plugin-packs/lvdcrop/plugins/lvd_crop.c b/veejay-current/plugin-packs/lvdcrop/plugins/lvd_crop.c index 868d0dd0..39c227c9 100644 --- a/veejay-current/plugin-packs/lvdcrop/plugins/lvd_crop.c +++ b/veejay-current/plugin-packs/lvdcrop/plugins/lvd_crop.c @@ -43,8 +43,8 @@ int init_instance( livido_port_t *my_instance ) return LIVIDO_ERROR_MEMORY_ALLOCATION; } - c->buf[1] = c->buf[0] + RUP8(w*h); - c->buf[2] = c->buf[1] + RUP8(w*h); + c->buf[1] = c->buf[0] + (w*h); + c->buf[2] = c->buf[1] + (w*h); c->w = -1; c->h = -1; diff --git a/veejay-current/plugin-packs/lvdcrop/plugins/lvd_cropscale.c b/veejay-current/plugin-packs/lvdcrop/plugins/lvd_cropscale.c index 29dcf524..e0d427bb 100644 --- a/veejay-current/plugin-packs/lvdcrop/plugins/lvd_cropscale.c +++ b/veejay-current/plugin-packs/lvdcrop/plugins/lvd_cropscale.c @@ -46,8 +46,8 @@ int init_instance( livido_port_t *my_instance ) return LIVIDO_ERROR_MEMORY_ALLOCATION;\ } - c->buf[1] = c->buf[0] + RUP8(w*h); - c->buf[2] = c->buf[1] + RUP8(w*h); + c->buf[1] = c->buf[0] + (w*h); + c->buf[2] = c->buf[1] + (w*h); c->flags = SWS_FAST_BILINEAR; c->w = -1; diff --git a/veejay-current/veejay-core/configure.ac b/veejay-current/veejay-core/configure.ac index 1715d014..23b9b941 100644 --- a/veejay-current/veejay-core/configure.ac +++ b/veejay-current/veejay-core/configure.ac @@ -105,6 +105,11 @@ AC_CHECK_SIZEOF([long int]) AC_CHECK_SIZEOF([size_t]) AC_CHECK_SIZEOF([float]) + +AC_TYPE_OFF_T +AC_CHECK_TYPE(ptrdiff_t, long) +AC_TYPE_SIZE_T + AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE(HAVE_POSIX_TIMERS,[1],[Set to 1 if clock_gettime and POSIX timers are available])]) @@ -134,6 +139,7 @@ case "${host_os}" in AC_DEFINE(HAVE_DARWIN,1,[MAC OS X Darwin]) dnl OS-X/Darwin needs no-cpp-precomp CFLAGS="$CFLAGS -no-cpp-precomp" + OP_CFLAGS="$OP_CFLAGS -no-cpp-precomp" have_darwin=true LIBM_LIBS="" ;; @@ -155,7 +161,7 @@ fi AC_MSG_CHECKING(whether to compile in debugging information) debugCFLAGS="" if test "x$enable_debug" = "xyes" ; then - debugCFLAGS="-g" + debugCFLAGS="-g -Wall" CFLAGS="$CFLAGS $debugCFLAGS" AC_MSG_RESULT([yes]) else @@ -219,8 +225,7 @@ have_arm=false have_armv7a=false OP_CFLAGS="" -VJE_CFLAGS="" -SUBSAMPLE_CFLAGS="" +LZO_EXTRA_CFLAGS="-DMINILZO_HAVE_CONFIG_H" AC_MSG_CHECKING([Architecture]) case $host_cpu in @@ -228,13 +233,8 @@ case $host_cpu in AC_DEFINE(HAVE_X86CPU,1, [Compiling for x86 architecture CPU]) AC_DEFINE(ARCH_X86,1,[Compiling for x86 architecture]) have_x86cpu=true - PROGRAM_NOPIC="-fno-PIC" - - if test "x$enable_debug" != "xyes" ; then - CFLAGS="$CFLAGS -O3 -ftree-vectorize -ffast-math -fopenmp" - fi - + OP_CFLAGS="-O3 -ffast-math" AC_MSG_RESULT([x86]) ;; x86_64*|k8-*) @@ -242,10 +242,7 @@ case $host_cpu in AC_DEFINE(ARCH_X86_64,1, [Compiling for x86-64 architecture CPU]) have_x86cpu=true have_x86_64cpu=true - if test "x$enable_debug" != "xyes" ; then - CFLAGS="$CFLAGS -O3 -ffast-math -ftree-vectorize -m64 -fPIC -DPIC -fopenmp" - fi - + OP_CFLAGS="$OP_CFLAGS -O3 -ftree-vectorize -ffast-math -fopenmp -m64" AC_MSG_RESULT([x86_64]) ;; powerpc | powerpc64) @@ -256,14 +253,12 @@ case $host_cpu in case $host in *-apple-darwin*) PROGRAM_NOPIC="-mdynamic-no-pic" # dynamic-no-pic is an Apple gcc option -dnl CFLAGS="$CFLAGS -no-cpp-precomp" - ;; *) PROGRAM_NOPIC="" ;; esac - CFLAGS="$CFLAGS -O3" + OP_CFLAGS="$OP_CFLAGS -O3" AC_MSG_RESULT([powerpc]) ;; mips | mipsel) @@ -276,7 +271,7 @@ dnl CFLAGS="$CFLAGS -no-cpp-precomp" ]])], [have_ps2=true], [have_ps2=false]) - + OP_CFLAGS="$OP_CFLAGS -O3 -ffast-math" AC_MSG_RESULT([mips]) AC_MSG_CHECKING([if we are compiling on playstation2 hardware]) @@ -286,24 +281,19 @@ dnl CFLAGS="$CFLAGS -no-cpp-precomp" else AC_MSG_RESULT(no) fi - - CFLAGS="$CFLAGS -O3" - ;; aarch64* |arm) AC_DEFINE(HAVE_ARM,1,[Compiling for ARM CPU]) - if test "x$enable_debug" != "xyes" ; then - CFLAGS="$CFLAGS -O3 -ftree-vectorize -m64 -fPIC -DPIC -fopenmp" - fi + OP_CFLAGS="$OP_CFLAGS -m64 -fPIC -DPIC" have_arm=true + OP_CFLAGS="$OP_CFLAGS -O3 -m64 -fPIC -DPIC" AC_MSG_RESULT([arm]) ;; arm7* ) AC_DEFINE(HAVE_ARM,1,[Compiling for ARM CPU]) AC_DEFINE(HAVE_ARMV7A,1,[Compiling for ARM7L CPU]) - if test "x$enable_debug" != "xyes" ; then - CFLAGS="$CFLAGS -O3 -ftree-vectorize -m64 -fPIC -DPIC -fopenmp" - fi + OP_CFLAGS="$OP_CFLAGS -O3 -m64 -fPIC -DPIC" + have_arm=true have_armv7a=true AC_MSG_RESULT([arm7]) @@ -314,16 +304,10 @@ dnl If you get here, you can change AC_MSG_ERROR to AC_MSG_RESULT dnl and uncomment setting the CFLAGS below to have it compile anyway on your system AC_MSG_ERROR([unknown, good luck]) -dnl OP_CFLAGS="$USER_CFLAGS" -dnl SUBSAMPLE_CFLAGS="$USER_CFLAGS" -dnl VJE_CFLAGS="$USER_CFLAGS" -dnl CFLAGS="$USER_CFLAGS" ;; esac -CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES" - if test x$host_alias != x; then dnl Cross compiling AC_MSG_CHECKING(sub-architecture settings) @@ -341,7 +325,7 @@ else TMP=`$srcdir/cpuinfo.sh` ARCHFLAGS=`cat veejay.arch` else - ARCHFLAGS="-mtune=$arch_target" + ARCHFLAGS="-mtune=$arch_target" fi AC_MSG_RESULT($ARCHFLAGS) fi @@ -359,24 +343,13 @@ then if test $ac_cv_flag_neon = yes ; then AC_DEFINE(HAVE_ARM_NEON,1,[Compiling in NEON support]) - USER_CFLAGS="-mfpu=neon -ftree-vectorize -mvectorize-with-neon-quad $USER_CFLAGS" + OP_CFLAGS="$OP_CFLAGS -mfpu=neon -mvectorize-with-neon-quad" FASTARM_CFLAGS="$ARCHFLAGS -march=armv7-a -mthumb -mimplicit-it=always -mthumb-interwork -DCONFIG_THUMB" else - USER_CFLAGS="-march=native -ftree-vectorize $USER_CFLAGS" + OP_CFLAGS="$OP_CFLAGS -march=native" FASTARM_CFLAGS="$ARCHFLAGS" fi - if test "x$enable_debug" != "xyes" ; then - USER_CFLAGS="$USER_CFLAGS -O3 -fno-stack-protector" - else - USER_CFLAGS="$USER_CFLAGS -g -Wall" - fi - - OP_CFLAGS="$USER_CFLAGS" - SUBSAMPLE_CFLAGS="$USER_CFLAGS" - VJE_CFLAGS="$USER_CFLAGS" - CFLAGS="$USER_CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES" - AC_SUBST(FASTARM_CFLAGS) fi @@ -394,21 +367,10 @@ then AC_DEFINE(HAVE_ARM_ASIMD, 1,[Compiling in ASIMD support]) fi - if test "x$enable_debug" != "xyes" ; then - USER_CFLAGS="$USER_CFLAGS -O3 -fno-stack-protector" - else - USER_CFLAGS="$USER_CFLAGS -g -Wall" - fi - - OP_CFLAGS="$USER_CFLAGS" - SUBSAMPLE_CFLAGS="$USER_CFLAGS" - VJE_CFLAGS="$USER_CFLAGS" - CFLAGS="$USER_CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES" AC_SUBST(FASTARM_CFLAGS) fi - dnl This flag is used for PROGRAMS not SHARED LIBRARIES. PIC code is required dnl for shared libraries but is slower than non-pic code. Compute bound dnl programs such as yuvdenoise and y4mspatialfilter can use this flag by @@ -501,7 +463,7 @@ then AC_DEFINE(HAVE_ASM_SSE4_2,1,[Compiling in SSE4_2 support]) AC_DEFINE(HAVE_SSE4_2,1,[Compiling in SSE4_2 support]) have_asm_sse4_2=true - CFLAGS="$CFLAGS -msse4.2" + OP_CFLAGS="$OP_CFLAGS -msse4.2" fi @@ -759,9 +721,10 @@ dnl We do this last as it can screw up library detection etc... CFLAGS="$ARCHFLAGS $CFLAGS" CXXFLAGS="$ARCHFLAGS $CXXFLAGS" -OP_CFLAGS="$VJE_CFLAGS" + AC_SUBST(OP_CFLAGS) +AC_SUBST(LZO_EXTRA_CFLAGS) if test "x${GCC}" != "xyes" ; then enable_compile_warnings=no @@ -790,14 +753,9 @@ fi if test "x$cflags_set" != "xyes" ; then if test "x$enable_debug" = "xyes" ; then CFLAGS="$debugCFLAGS $warnCFLAGS $CFLAGS" - VJE_CFLAGS="$debugCFLAGS $warnCFLAGS $VJE_CFLAGS" - OP_CFLAGS="$debugCFLAGS $warnCFLAGS $OP_CFLAGS" - SUBSAMPLE_CFLAGS="$debugCFLAGS $warnCFLAGS $SUBSAMPLE_CFLAGS" + OP_CFLAGS="" else CFLAGS="$CFLAGS $warnCFLAGS" - VJE_CFLAGS="$debugCFLAGS $VJE_CFLAGS" - OP_CFLAGS="$debugCFLAGS $OP_CFLAGS" - SUBSAMPLE_CFLAGS="$debugCFLAGS $SUBSAMPLE_CFLAGS" fi CXXFLAGS="$CXXFLAGS $warnCXXFLAGS" cflags_set=yes @@ -857,7 +815,9 @@ AC_DEFINE(VERSION, ${VERSION}) AC_MSG_NOTICE([]) AC_MSG_NOTICE([ Veejay-Core ${VERSION} build configuration :]) AC_MSG_NOTICE([]) -AC_MSG_NOTICE([ Compiler flags: $CFLAGS]) +AC_MSG_NOTICE([ Compiler flags: ]) +AC_MSG_NOTICE([ CFLAGS=$CFLAGS ]) +AC_MSG_NOTICE([ OP_CFLAGS=$OP_CFLAGS ]) AC_MSG_NOTICE([ architecture: $arch_target]) AC_MSG_NOTICE([]) AC_MSG_NOTICE([ Architecture: ${host_cpu} ]) diff --git a/veejay-current/veejay-core/libvjmem/memcpy.c b/veejay-current/veejay-core/libvjmem/memcpy.c index 576ba577..1e78302f 100644 --- a/veejay-current/veejay-core/libvjmem/memcpy.c +++ b/veejay-current/veejay-core/libvjmem/memcpy.c @@ -169,6 +169,10 @@ #define FIND_BEST_MAX_ITERATIONS 100 + +#define is_aligned__(PTR,LEN) \ + (((uintptr_t)(const void*)(PTR)) % (LEN) == 0 ) + static int selected_best_memcpy = 1; static int selected_best_memset = 1; @@ -286,7 +290,7 @@ static __inline__ void * __memcpy(void * to, const void * from, size_t n) #ifdef HAVE_ASM_AVX #define AVX_MMREG_SIZE 32 #endif -#ifdef HAVE_ASM_SSE +#if defined(HAVE_ASM_SSE) || defined(HAVE_ASM_SSE2) || defined(__SSE4_1__) #define SSE_MMREG_SIZE 16 #endif #ifdef HAVE_ASM_MMX @@ -336,8 +340,6 @@ static __inline__ void * __memcpy(void * to, const void * from, size_t n) #define EMMS "emms" //#endif -#define is_aligned__(PTR,LEN) \ - (((uintptr_t)(const void*)(PTR)) % (LEN) == 0 ) char *veejay_strncpy( char *dest, const char *src, size_t n ) @@ -586,6 +588,11 @@ static void *sse41_memcpy(void *to, const void *from, size_t len) { void *retval = to; if (len >= 128) { + if(!is_aligned__(from,SSE_MMREG_SIZE)) { + memcpy( to,from,len); + return to; + } + register uintptr_t delta; /* Align destination to SSE_MMREG_SIZE -boundary */ delta = ((uintptr_t)to) & (SSE_MMREG_SIZE - 1); @@ -643,6 +650,11 @@ static void *sse42_memcpy(void *to, const void *from, size_t len) { void *retval = to; if (len >= 128) { + if(!is_aligned__(from,SSE_MMREG_SIZE)) { + memcpy( to,from,len); + return to; + } + register uintptr_t delta; /* Align destination to SSE_MMREG_SIZE -boundary */ delta = ((uintptr_t)to) & (SSE_MMREG_SIZE - 1); @@ -704,14 +716,17 @@ static void *sse42_memcpy(void *to, const void *from, size_t len) { * http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss5.4 */ - -/* for veejay, moving 128 bytes a time makes a difference */ static void *sse2_memcpy(void * to, const void * from, size_t len) { void *retval = to; if(len >= 128) { + if(!is_aligned__(from,SSE_MMREG_SIZE)) { + memcpy( to,from,len); + return to; + } + register uintptr_t delta; /* Align destination to SSE_MMREG_SIZE -boundary */ delta = ((uintptr_t)to)&(SSE_MMREG_SIZE-1); @@ -839,10 +854,10 @@ static void *sse_memcpy2(void * to, const void * from, size_t len) if(len >= 128) { - /* if(!is_aligned__(from,SSE_MMREG_SIZE)) { + if(!is_aligned__(from,SSE_MMREG_SIZE)) { memcpy( to,from,len); return to; - } */ + } register uintptr_t delta; @@ -857,7 +872,7 @@ static void *sse_memcpy2(void * to, const void * from, size_t len) i = len >> 7; /* len/128 */ len&=127; - for(; i>0; i--) + for(; i>1; i--) { __asm__ __volatile__ ( "movups (%0), %%xmm0\n" @@ -880,6 +895,18 @@ static void *sse_memcpy2(void * to, const void * from, size_t len) from = ((const unsigned char *)from) + 128; to = ((unsigned char *)to) + 128; } + + if (len >= SSE_MMREG_SIZE) { + __asm__ __volatile__ ( + "movups (%0), %%xmm0\n" + "movntps %%xmm0, (%1)\n" + :: "r" (from), "r" (to) : "memory"); + from = ((const unsigned char *)from) + 16; + to = ((unsigned char *)to) + 16; + } + if (len) { + memcpy(to, from, len); + } /* since movntq is weakly-ordered, a "sfence" * is needed to become ordered again. */ __asm__ __volatile__ ("sfence":::"memory"); @@ -1939,6 +1966,10 @@ static void fast_memset(void * to, int val, size_t len) #ifdef HAVE_ARM_ASIMD void memset_asimd(void *dst, uint8_t val, size_t len) { + + if( len == 0 || ptr == dst ) + return dst; + uint8x16_t value = vdupq_n_u8(val); uint8_t *dst_bytes = (uint8_t *)dst; size_t num_blocks = len / 16; @@ -1954,6 +1985,10 @@ void memset_asimd(void *dst, uint8_t val, size_t len) { } } void memset_asimd_v2(void *dst, uint8_t val, size_t len) { + + if( len == 0 || ptr == dst ) + return dst; + uint8x16_t value = vdupq_n_u8(val); uint8_t *dst_bytes = (uint8_t *)dst; size_t num_blocks = len / 16; @@ -1980,6 +2015,9 @@ void memset_asimd_v2(void *dst, uint8_t val, size_t len) { } } void memset_asimd_v4(void *dst, uint8_t val, size_t len) { + if( len == 0 || ptr == dst ) + return dst; + uint8x16_t v = vdupq_n_u8(val); size_t multiple_of_16 = len & ~0xF; @@ -1994,6 +2032,10 @@ void memset_asimd_v4(void *dst, uint8_t val, size_t len) { } void memset_asimd_64(uint8_t *dst, uint8_t value, size_t size) { + + if( size == 0 || ptr == dst ) + return dst; + uint8x16_t value_v = vdupq_n_u8(value); size_t num_blocks = size / 64; @@ -2031,6 +2073,9 @@ void memset_asimd_64(uint8_t *dst, uint8_t value, size_t size) { } void memset_asimd_32(uint8_t *dst, uint8_t value, size_t size) { + if( size == 0 || dst == NULL ) + return dst; + uint8x16_t value_v = vdupq_n_u8(value); size_t num_blocks = size / 32; @@ -2066,6 +2111,10 @@ void memset_asimd_32(uint8_t *dst, uint8_t value, size_t size) { #endif void *memset_64(void *ptr, int value, size_t num) { + + if( num == 0 || ptr == NULL ) + return ptr; + uint8_t *dest = (uint8_t *)ptr; uint8_t byte_value = (uint8_t)value; size_t num_bytes = num; @@ -2264,6 +2313,27 @@ static int set_user_selected_memset() return 0; } +static void mem_fill_block(uint8_t *dst, size_t len) { + int i; + for( i = 0; i < len ; i ++ ) { + dst[i] = i % 255; + } +} + +static int mem_verify( uint8_t *source, uint8_t *good, size_t len) { + if( memcmp(source,good,len) == 0 ) + return 1; + return 0; +} + +static int mem_validate( uint8_t *buffer, uint8_t *validation_buffer, size_t len, int index) { + if(!mem_verify(buffer, validation_buffer, len ) ) { + veejay_msg(0,"Function failed test, skip"); + return 0; + } + return 1; +} + void find_best_memcpy() { int best = set_user_selected_memcpy(); @@ -2271,29 +2341,40 @@ void find_best_memcpy() goto set_best_memcpy_method; double t; - char *buf1, *buf2; + uint8_t *buf1, *buf2, *validbuf; int i, k; int bufsize = 10 * 1048576; - if (!(buf1 = (char*) malloc( bufsize * sizeof(char)))) + if (!(buf1 = (uint8_t*) malloc( bufsize * sizeof(uint8_t)))) return; - if (!(buf2 = (char*) malloc( bufsize * sizeof(char)))) { + if (!(buf2 = (uint8_t*) malloc( bufsize * sizeof(uint8_t)))) { free( buf1 ); return; } + if (!(validbuf = (uint8_t*) malloc( bufsize * sizeof(uint8_t)))) { + free( buf1 ); + free( buf2 ); + return; + } + int cpu_flags = av_get_cpu_flags(); - veejay_msg(VEEJAY_MSG_INFO, "Finding best memcpy ... (copy %ld blocks of %2.2f Mb)",FIND_BEST_MAX_ITERATIONS, bufsize / 1048576.0f ); + veejay_msg(VEEJAY_MSG_INFO, "Finding best memcpy ... (copy %ld blocks of %2.2f Mb)",FIND_BEST_MAX_ITERATIONS, bufsize / 1048576.0f ); memset(buf1,0, bufsize); memset(buf2,0, bufsize); - + /* make sure buffers are present on physical memory */ memcpy( buf1, buf2, bufsize); memcpy( buf2, buf1, bufsize ); + /* fill */ + mem_fill_block(buf1, bufsize); + memset(buf2, 0, bufsize); + mem_fill_block(validbuf, bufsize); + for( i = 1; memcpy_method[i].name; i ++ ) { if( memcpy_method[i].cpu_require && !(cpu_flags & memcpy_method[i].cpu_require ) ) { @@ -2303,9 +2384,14 @@ void find_best_memcpy() t = get_time(); for( k = 0; k < FIND_BEST_MAX_ITERATIONS; k ++ ) { - memcpy_method[i].function( buf1,buf2, bufsize ); + memcpy_method[i].function( buf2,buf1, bufsize ); } t = get_time() - t; + + if(!mem_verify(buf2,validbuf, bufsize)) { + t = 0; + } + memcpy_method[i].t = t; } @@ -2324,6 +2410,7 @@ void find_best_memcpy() free( buf1 ); free( buf2 ); + free( validbuf ); set_best_memcpy_method: if (best) { diff --git a/veejay-current/veejay-core/libvjmem/vj-x86.c b/veejay-current/veejay-core/libvjmem/vj-x86.c index 8935a33d..4a184c91 100644 --- a/veejay-current/veejay-core/libvjmem/vj-x86.c +++ b/veejay-current/veejay-core/libvjmem/vj-x86.c @@ -32,9 +32,22 @@ extern void find_best_memset(void); extern void yuyv_plane_init(); extern void benchmark_tasks(int n_tasks, long n_frames, int w, int h); extern void init_parallel_tasks(int n_tasks); -static int MEM_ALIGNMENT_SIZE = 0; + extern int CACHE_LINE_SIZE = 64; +#if defined(HAVE_ASM_SSE) || defined(HAVE_ASM_SSE2) || defined(__SSE4_2__) || defined(__SSE4_1__) +#define MEM_ALIGNMENT_SIZE 16 +#elif defined (HAVE_ASM_AVX2) +#define MEM_ALIGNMENT_SIZE 64 +#elif defined (HAVE_ASM_AVX) +#define MEM_ALIGNMENT_SIZE 32 +#elif defined (__ARM_ARCH_7A__) +#define MEM_ALIGNMENT_SIZE 8 +#elif defined (__ARM_ARCH_8A__ ) +#define MEM_ALIGNMENT_SIZE 16 +#else +#define MEM_ALIGNMENT_SIZE 8 +#endif static int has_cpuid(void) { @@ -138,8 +151,6 @@ void vj_mem_init(void) CACHE_LINE_SIZE = get_cache_line_size(); #endif - if(MEM_ALIGNMENT_SIZE == 0) - MEM_ALIGNMENT_SIZE = getpagesize(); #if defined (HAVE_ASM_MMX) || defined (HAVE_ASM_SSE) yuyv_plane_init(); @@ -277,7 +288,7 @@ void *vj_simple_pool_alloc( void *ptr, size_t s ) if( s > pool->len || (pool->cur + s) > pool->len ) { return NULL; } - uint8_t *addr = (uint8_t*) pool->addr + RUP8(pool->cur); + uint8_t *addr = (uint8_t*) pool->addr + (pool->cur); pool->cur += RUP8(s); diff --git a/veejay-current/veejay-core/libvjmsg/vj-common.c b/veejay-current/veejay-core/libvjmsg/vj-common.c index 60b303c5..ce9a95c3 100644 --- a/veejay-current/veejay-core/libvjmsg/vj-common.c +++ b/veejay-current/veejay-core/libvjmsg/vj-common.c @@ -159,10 +159,16 @@ void veejay_print_backtrace() s = backtrace( space, 100 ); strings = backtrace_symbols(space,s); + if(strings == NULL ) { + veejay_msg(VEEJAY_MSG_ERROR, "Unable to get backtrace"); + return; + } - for( i = 0; i < s ; i ++ ) + for( i = 0; i < s ; i ++ ) { veejay_msg(VEEJAY_MSG_ERROR, "%s", strings[i] ); - + } + + free(strings); } #endif diff --git a/veejay-current/veejay-core/libyuv/yuvconv.c b/veejay-current/veejay-core/libyuv/yuvconv.c index 606ac303..46ede97a 100644 --- a/veejay-current/veejay-core/libyuv/yuvconv.c +++ b/veejay-current/veejay-core/libyuv/yuvconv.c @@ -35,6 +35,9 @@ #ifdef HAVE_ARM #include #endif +#ifdef STRICT_CHECKING +#include +#endif #define Y4M_CHROMA_420JPEG 0 /* 4:2:0, H/V centered, for JPEG/MPEG-1 */ #define Y4M_CHROMA_420MPEG2 1 /* 4:2:0, H cosited, for MPEG-2 */ @@ -1428,9 +1431,35 @@ void yuv_convert_and_scale_grey(void *sws , VJFrame *src, VJFrame *dst) sws_scale( s->sws,(const uint8_t * const*) src->data, src_stride, 0, src->height,(uint8_t * const*) dst->data, dst_stride ); } + +#ifdef STRICT_CHECKING +static size_t get_alignment(void* ptr) { + uintptr_t address = (uintptr_t)ptr; + size_t alignment = 1; + + // Keep shifting the alignment to the left until the lowest bit is 1 + while ((address & 1) == 0) { + alignment <<= 1; + address >>= 1; + } + + return alignment; +} + +static int is_aligned( char *msg, void *ptr, size_t alignment ) { + uintptr_t address = (uintptr_t)ptr; + + int isa = (address % alignment) == 0; + if(!isa) { + veejay_msg(VEEJAY_MSG_ERROR, "%s is not aligned to %d bytes. it's current alignment is %d bytes", msg, alignment, get_alignment(ptr) ); + } +} +#endif + void yuv_convert_and_scale_packed(void *sws , VJFrame *src, VJFrame *dst) { vj_sws *s = (vj_sws*) sws; + const int src_stride[3] = { src->width,src->uv_width,src->uv_width }; const int dst_stride[3] = { dst->width * 2,0,0 }; @@ -1474,23 +1503,18 @@ const char *yuv_get_scaler_name(int id) return NULL; } -void yuv422to420planar( uint8_t *src[3], uint8_t *dst[3], int w, int h ) -{ - unsigned int x,y,k=0; - const int hei = h >> 1; - const int wid = w >> 1; - uint8_t *u = dst[1]; - uint8_t *v = dst[2]; - uint8_t *a = src[1]; - uint8_t *b = src[2]; - for( y = 0 ; y < hei; y ++ ) { - for( x= 0; x < wid ; x ++ ) { - u[k] = a[ (y<<1) * wid + x ]; //@ drop left chroma - v[k] = b[ (y<<1) * wid + x ]; - k++; - } - } + +void yuv422to420planar(uint8_t *src[3], uint8_t *dst[3], int len ) { + + const int half = len / 2; + int i; + for( i = 0; i < half; i ++ ) { + dst[1][i] = ( src[1][2 * i] + src[1][2 * i + 1]) / 2; + dst[2][i] = ( src[2][2 * i] + src[2][2 * i + 1]) / 2; + } + } + #if !defined(HAVE_ASM_MMX) && !defined(HAVE_ARM) void yuv420to422planar( uint8_t *src[3], uint8_t *dst[3], int w, int h ) { @@ -1510,6 +1534,7 @@ void yuv420to422planar( uint8_t *src[3], uint8_t *dst[3], int w, int h ) u[k + wid ] = a[y*wid+x]; v[k] = b[ y * wid + x]; v[k + wid ] = b[y * wid + x ]; + k += 2; } } } @@ -1676,10 +1701,10 @@ static void yuy_scale_pixels_from_yuv_job( void *arg) } } -void yuv_scale_pixels_from_yuv( uint8_t *src[3], uint8_t *dst[3], int len ) +void yuv_scale_pixels_from_yuv( uint8_t *src[3], uint8_t *dst[3], int len, int uv_len ) { if(vj_task_available() ) { - int strides[4] = { len, len/2,len/2, 0 }; + int strides[4] = { len, uv_len,uv_len, 0 }; vj_task_run( src,dst,NULL, strides, 3, (performer_job_routine) &yuy_scale_pixels_from_yuv_job ); } else { diff --git a/veejay-current/veejay-core/libyuv/yuvconv.h b/veejay-current/veejay-core/libyuv/yuvconv.h index ab157a61..401655b5 100644 --- a/veejay-current/veejay-core/libyuv/yuvconv.h +++ b/veejay-current/veejay-core/libyuv/yuvconv.h @@ -125,9 +125,9 @@ void yuv_fx_context_process( void *ctx, VJFrame *src, VJFrame *dst ); void yuv_fx_context_destroy( void *ctx ); void yuv420to422planar( uint8_t *src[3], uint8_t *dst[3], int w, int h ); -void yuv422to420planar( uint8_t *src[3], uint8_t *dst[3], int w, int h ); +void yuv422to420planar( uint8_t *src[3], uint8_t *dst[3], int len ); -void yuv_scale_pixels_from_yuv( uint8_t *src[3], uint8_t *dst[3], int len ); +void yuv_scale_pixels_from_yuv( uint8_t *src[3], uint8_t *dst[3], int len, int uv_len ); void yuv_scale_pixels_from_y( uint8_t *plane, int len ); void yuv_scale_pixels_from_uv( uint8_t *plane, int len ); diff --git a/veejay-current/veejay-core/thirdparty/liblzo/Makefile.am b/veejay-current/veejay-core/thirdparty/liblzo/Makefile.am index 3212799c..4a39624c 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/Makefile.am +++ b/veejay-current/veejay-core/thirdparty/liblzo/Makefile.am @@ -1,6 +1,6 @@ # Makefile for veejay MAINTAINERCLEANFILES = Makefile.in -AM_CFLAGS = $(OP_CFLAGS) +AM_CFLAGS = $(LZO_EXTRA_CFLAGS) AM_CPPFLAGS = -I$(top_srcdir) -I$(includedir) \ -I$(top_srcdir)/thirdparty \ diff --git a/veejay-current/veejay-core/thirdparty/liblzo/lzo.c b/veejay-current/veejay-core/thirdparty/liblzo/lzo.c index 2b71ec5e..4f1ff78d 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/lzo.c +++ b/veejay-current/veejay-core/thirdparty/liblzo/lzo.c @@ -1,6 +1,6 @@ /* veejay - Linux VeeJay * (C) 2002-2013 Niels Elburg - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,10 +28,23 @@ #include #include +#ifdef HAVE_ARM_ASIMD +#include +#include +#endif +#if defined (__SSE2__) || defined(__SSE4_2__) || defined(_SSE4_1__) +#include +#endif +#include + typedef struct { - lzo_byte *wrkmem; - uint8_t *tmp[3]; + lzo_align_t *wrkmem; + int pixfmt; + void *scaler; + VJFrame *out_frame; + VJFrame *in_frame; + uint8_t *compr_buff[3]; } lzot; void lzo_free( void *lzo ) @@ -39,32 +52,26 @@ void lzo_free( void *lzo ) lzot *l = (lzot*) lzo; if(l) { - if(l->wrkmem) - free(l->wrkmem); - if(l->tmp[0]) - free(l->tmp[0]); + if( l->compr_buff[0] ) { + free(l->compr_buff[0]); + } + if( l->in_frame ) { + if( l->in_frame->data[0] ) + free(l->in_frame->data[0] ); + free(l->in_frame); + } + if( l->out_frame ) { + free(l->out_frame); + } + if( l->scaler ) { + yuv_free_swscaler(l->scaler); + } free(l); } l = NULL; } -/* -void lzo_print_buf( uint8_t *buf, int len ) -{ - int i; - printf("------ %p, %d\n", buf, len ); - printf("line : "); - for( i = 1; i < 32; i ++ ) { - printf(". "); - } - printf("\n"); - for(i = 0; i < len ; i ++ ) { - if( (i%32) == 0 ) - printf("\nline %04d: ",i); - printf("%02x", buf[i] ); - } - printf("\n"); -} -static int lzo_verify_compression(uint8_t *in, int in_len, uint8_t *out , lzo_uint *out_lenptr, uint8_t *wrkmem) + +static int lzo_verify_compression(uint8_t *in, int in_len, uint8_t *out , lzo_uint *out_lenptr, lzo_align_t *wrkmem) { lzo_uint out_len = 0; int r = lzo1x_1_compress( in, in_len, out, &out_len, wrkmem ); @@ -95,215 +102,301 @@ static int lzo_verify_compression(uint8_t *in, int in_len, uint8_t *out , lzo_ui return 0; } -*/ + +#define RUP16(num)(((num)+16)&~16) #define LZO_ALIGN_SIZE(size) \ ( ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ) * sizeof(lzo_align_t) #define RUP8(num)(((num)+8)&~8) -void *lzo_new( ) + +void *lzo_new( int pixfmt, int width, int height, int is_decoder ) { lzot *l = (lzot*) vj_calloc(sizeof(lzot)); if (lzo_init() != LZO_E_OK) { - veejay_msg(VEEJAY_MSG_ERROR, "LZO Unable to initialize. Could be buggy compiler?"); + veejay_msg(VEEJAY_MSG_ERROR, "LZO: Failed to initialize. Buggy compiler?"); free( l ); return NULL; } - l->wrkmem = (lzo_bytep) - vj_calloc( RUP8(2 * LZO_ALIGN_SIZE( LZO1X_1_MEM_COMPRESS )) ); + l->out_frame = yuv_yuv_template( NULL,NULL,NULL, width, height, pixfmt ); + l->pixfmt = pixfmt; - if(l->wrkmem == NULL ) - { - veejay_msg(VEEJAY_MSG_ERROR, "LZO Cannot allocate work memory for LZO1X_1"); - if(l) free(l); - return NULL; - } + veejay_msg(VEEJAY_MSG_DEBUG, "LZO: alignment size is %zu", LZO_ALIGN_SIZE(1) ); + if(!is_decoder) { -/* - uint8_t in[16384]; - uint8_t out[16834]; - - veejay_memset( in, 1, sizeof(in) ); - veejay_memset( out, 0, sizeof(out)); - - lzo_bytep inp = (lzo_bytep) &in[0]; - lzo_bytep outp = (lzo_bytep) &out[0]; - - lzo_uint out_len = 0; - int lzo_verify_compression_result = lzo_verify_compression( inp, sizeof(in), outp, &out_len, l->wrkmem ); - - if( lzo_verify_compression_result == 1 ) { - int i; - for( i = 0; i < sizeof(in); i ++ ) { - if( in[i] != 1 ) //decompression back into 'in' - veejay_msg(VEEJAY_MSG_ERROR, "LZO verify error at byte pos %d", i ); - + l->wrkmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); + if(l->wrkmem == NULL ) + { + veejay_msg(VEEJAY_MSG_ERROR, "LZO Cannot allocate work memory for LZO1X_1"); + free(l->out_frame); + free(l); + return NULL; } - veejay_msg(VEEJAY_MSG_DEBUG, "LZO verified compression algorithms successfully"); - } - */ + l->compr_buff[0] = malloc(LZO_ALIGN_SIZE(l->out_frame->len + l->out_frame->uv_len + l->out_frame->uv_len)) ; + l->compr_buff[1] = l->compr_buff[0] + l->out_frame->len; + l->compr_buff[2] = l->compr_buff[1] + l->out_frame->uv_len; - veejay_msg(VEEJAY_MSG_DEBUG,"LZO real-time data compression library (v%s, %s) enabled", + uint8_t in[16384]; + uint8_t out[16834]; + + veejay_memset( in, 128, sizeof(in) ); + veejay_memset( out, 0, sizeof(out)); + + lzo_bytep inp = (lzo_bytep) &in[0]; + lzo_bytep outp = (lzo_bytep) &out[0]; + + lzo_uint out_len = 0; + int lzo_verify_compression_result = lzo_verify_compression( inp, sizeof(in), outp, &out_len, l->wrkmem ); + if( lzo_verify_compression_result == 1 ) { + int i; + for( i = 0; i < sizeof(in); i ++ ) { + if( in[i] != 128 ) //decompression back into 'in' + { + veejay_msg(VEEJAY_MSG_ERROR, "LZO: Failed to verify compression algorithm"); + free(l->compr_buff[0]); + free(l->out_frame); + free(l->wrkmem); + free(l); + return NULL; + } + } + veejay_msg(VEEJAY_MSG_DEBUG, "LZO: Verified compression algorithm successfully"); + } + + veejay_msg(VEEJAY_MSG_DEBUG,"LZO real-time data compression library (v%s, %s) enabled", lzo_version_string(), lzo_version_date()); - l->tmp[0] = NULL; - l->tmp[1] = NULL; - l->tmp[2] = NULL; + free(l->wrkmem); + } + return (void*) l; } +static void long2str(unsigned char *dst, uint32_t n) +{ + dst[0] = (n )&0xff; + dst[1] = (n>> 8)&0xff; + dst[2] = (n>>16)&0xff; + dst[3] = (n>>24)&0xff; +} + static uint32_t str2ulong(unsigned char *str) { return ( str[0] | (str[1]<<8) | (str[2]<<16) | (str[3]<<24) ); } -long lzo_compress( void *lzo, uint8_t *src, uint8_t *plane, unsigned int *size, int ilen ) +static lzo_uint lzo_compress( void *lzo, uint8_t *src, uint8_t *plane, lzo_uint *size, int ilen ) { lzo_uint src_len = ilen; lzot *l = (lzot*) lzo; lzo_bytep dst = plane; - lzo_voidp wrkmem = l->wrkmem; - int r = lzo1x_1_compress( src, src_len, dst, (lzo_uint*) size, wrkmem ); - if( r != LZO_E_OK || r < 0 ) + + l->wrkmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); + if(l->wrkmem == NULL ) { - veejay_msg(0, "LZO Compression error: %d", r ); + veejay_msg(VEEJAY_MSG_ERROR, "LZO Cannot allocate work memory for LZO1X_1"); return 0; } - long res = (long) (*size); + lzo_voidp wrkmem = l->wrkmem; + int r = lzo1x_1_compress( src, src_len, dst, size, wrkmem ); + if( *size > src_len ) { + veejay_msg(VEEJAY_MSG_ERROR, "LZO plane is not compressible"); + free(l->wrkmem); + return 0; + } + + if( r != LZO_E_OK || r < 0 ) + { + veejay_msg(0, "LZO compression error: %d", r ); + free(l->wrkmem); + return 0; + } + + lzo_uint res = (*size); + + free(l->wrkmem); + return res; } -long lzo_decompress_el( void *lzo, uint8_t *linbuf, int linbuf_len, uint8_t *dst[3], int uv_len) -{ - unsigned int i; - lzo_uint len[3] = { 0,0,0}; - unsigned int sum = 0; - lzot *l = (lzot*) lzo; - lzo_uint result_len = 0; - lzo_uint offset = 12; - - len[0] = str2ulong( linbuf ); - len[1] = str2ulong( linbuf+4 ); - len[2] = str2ulong( linbuf+8 ); - - if(len[0] == 0 && len[1] == 0 ) { - veejay_msg(VEEJAY_MSG_ERROR, "Error in MLZO header", linbuf ); - return -1; - } - - for( i = 0; i < 3; i ++ ) - { - if( len[i] <= 0 ) { - continue; - } - - const lzo_bytep src = (lzo_bytep) (linbuf+offset); - - int r = lzo1x_decompress( src, len[i], dst[i], &result_len, l->wrkmem ); - if( r != LZO_E_OK || r < 0 ) - return 0; - sum += result_len; - offset += len[i]; - - result_len = 0; - } - - return (long)sum; +static void lzo_frame_copy( lzot *l, uint8_t *data[4], const int len, const int uv_len) { + + memcpy( l->compr_buff[0], data[0], len ); + memcpy( l->compr_buff[1], data[1], uv_len); + memcpy( l->compr_buff[2], data[2], uv_len ); + } -long lzo_decompress( void *lzo, uint8_t *linbuf, int linbuf_len, uint8_t *dst[3], int uv_len, - uint32_t stride1, uint32_t stride2, uint32_t stride3 ) -{ - unsigned int i; - lzo_uint len[3] = { 0,0,0}; - unsigned int mode = 0; - unsigned int sum = 0; - lzot *l = (lzot*) lzo; - lzo_uint result_len = 0; - lzo_uint offset = 16; - - len[0] = str2ulong( linbuf ); - len[1] = str2ulong( linbuf+4 ); - len[2] = str2ulong( linbuf+8 ); - mode = str2ulong( linbuf+12 ); - if( len[0] != stride1 || len[1] != stride2 || len[2] != stride3 ) { - veejay_msg(0, "LZO received corrupted packet"); +static lzo_uint LZO_HEADER_LEN = 16; +long lzo_compress_frame( void *lzo, VJFrame *frame, uint8_t *alt_data[4], uint8_t *dst ) { + lzot *l = (lzot*) lzo; + + lzo_uint s1=0,s2=0,s3=0,pf= frame->format; + lzo_uint *size1 = &s1, *size2=&s2,*size3=&s3; + lzo_uint res; + lzo_uint pos = LZO_HEADER_LEN; + + lzo_frame_copy( l, alt_data, frame->len, frame->uv_len ); + + uint8_t *compressed_data = dst + pos; + +/* res = lzo_compress( l, data[0], compressed_data, size1, frame->len); + if( res == 0 ) + { + veejay_msg(0,"LZO: unable to compress Y plane"); + return 0; + } + pos += res; + + res = lzo_compress( l, data[1], compressed_data + pos, size2 , frame->uv_len ); + if( res == 0 ) + { + veejay_msg(0,"LZO: unable to compress U plane"); + return 0; + } + pos += res; + + res = lzo_compress( l, data[2], compressed_data + pos, size3 , frame->uv_len ); + if( res == 0 ) + { + veejay_msg(0,"LZO: unable to compress V plane"); return 0; } - len[0] = stride1; - len[1] = stride2; - len[2] = stride3; + pos += res; +*/ + res = lzo_compress( l, l->compr_buff[0], compressed_data, size1, frame->len + frame->uv_len + frame->uv_len); + pos += res; - if(len[1] ==0 && len[2] == 0 ) - mode = 1; + long2str( dst, pf ); // store pixfmt + long2str( dst + 4, s1 ); // store compressed length + long2str( dst + 8, s2 ); + long2str( dst + 12, s3 ); + + /*veejay_msg(VEEJAY_MSG_DEBUG, "LZO block size: %zu, data size: %zu,%zu,%zu = %zu, offsets=%zu,%zu,%zu ", + pos, s1, s2, s3, s1 + s2 + s3, + LZO_HEADER_LEN, + LZO_HEADER_LEN + s1, + LZO_HEADER_LEN + s1 + s2 );*/ - for( i = 0; i < 3; i ++ ) - { - if( len[i] <= 0 ) - continue; - - // const lzo_bytep src = (lzo_bytep) (linbuf+offset); - - int r = lzo1x_decompress( linbuf+offset, len[i], dst[i], &result_len, l->wrkmem ); - if( r != LZO_E_OK ) - return 0; - sum += result_len; - offset += len[i]; - - result_len = 0; - } - - if(mode == 1) { - veejay_memset( dst[1], 128, uv_len ); - veejay_memset( dst[2], 128, uv_len ); - } - - return (long)sum; + return pos; } -long lzo_decompress420into422( void *lzo, uint8_t *linbuf, int linbuf_len, uint8_t *dst[3], int w, int h ) +static lzo_uint lzo_decompress_plane(lzot *l, uint8_t *linbuf, lzo_uint linbuf_len, int is_direct,uint8_t *dest, lzo_uint expected_length) { + lzo_uint result_len; + + const lzo_bytep src = (lzo_bytep) (linbuf); + int r = -1; + + if(is_direct) + { + r = lzo1x_decompress( src, linbuf_len, dest, &result_len, l->wrkmem ); + } + else + { + r = lzo1x_decompress( src, linbuf_len, l->in_frame->data[0], &result_len, l->wrkmem ); + } + + if( r != LZO_E_OK || r < 0 ) { + veejay_msg( VEEJAY_MSG_ERROR, "LZO decompression error %d (%d expanded into %d , missing %d)", r, linbuf_len, result_len, + expected_length - result_len); + return 0; + } + + return result_len; +} + +long lzo_decompress_el( void *lzo, uint8_t *linbuf, int linbuf_len, uint8_t *dst[4], int width, int height, int pixfmt) { - int i; - lzo_uint len[3] = { 0,0,0}; - int sum = 0; + lzo_uint len[4] = { 0,0,0,0}; + lzo_uint expected_length = 0; + unsigned int sum = 0; lzot *l = (lzot*) lzo; lzo_uint result_len = 0; - lzo_uint offset = 0; - - len[0] = str2ulong( linbuf ); - len[1] = str2ulong( linbuf+4 ); - len[2] = str2ulong( linbuf+8 ); + lzo_uint offset = LZO_HEADER_LEN; + unsigned int is_direct = 0; - if( l->tmp[0] == NULL ) { - l->tmp[0] = vj_malloc(sizeof(uint8_t) * w * h * 2); // will do - l->tmp[1] = l->tmp[0] + ( w * h ); - l->tmp[2] = l->tmp[1] + ( (w>>1) * (h>>1)); + len[0] = str2ulong( linbuf ); //pixel format + len[1] = str2ulong( linbuf+4 ); // length of first plane + len[2] = str2ulong( linbuf+8 ); // length of second plane + len[3] = str2ulong( linbuf+12 );// length of third plane + + + if( len[1] + len[2] + len[3] > linbuf_len || len[1] + len[2] + len[3] <= 0 ) { + veejay_msg(VEEJAY_MSG_ERROR, "LZO: Invalid length data in MLZO header"); + return -1; + } + + if( 1 == 1 && width == l->out_frame->width && height == l->out_frame->height && + pixfmt == l->out_frame->format ) { + is_direct = 1; } - for( i = 0; i < 3; i ++ ) - { - if( len[i] <= 0 ) - continue; - const lzo_bytep src = (lzo_bytep) (linbuf+offset); - int r = lzo1x_decompress( src, len[i], l->tmp[i], &result_len, l->wrkmem ); - if( r != LZO_E_OK ) + if( l->in_frame == NULL ) { + l->in_frame = yuv_yuv_template( NULL,NULL,NULL, width, height, pixfmt ); + if(l->in_frame == NULL) { return 0; - sum += result_len; - offset += len[i]; + } } - vj_frame_copy1( l->tmp[0], dst[0], w*h); - yuv420to422planar( l->tmp, dst, w, h ); - + expected_length = l->in_frame->len + l->in_frame->uv_len + l->in_frame->uv_len; - return (long)sum; + if(!is_direct) { + if(!l->in_frame->data[0]) { + l->in_frame->data[0] = vj_malloc(expected_length); + if(l->in_frame->data[0] == NULL) { + return 0; + } + l->in_frame->data[1] = l->in_frame->data[0] + l->in_frame->len; + l->in_frame->data[2] = l->in_frame->data[1] + l->in_frame->uv_len; + } + l->in_frame->format = len[0]; + + if(l->scaler == NULL) { + sws_template tmpl; + tmpl.flags = 1; + l->scaler = yuv_init_swscaler( l->in_frame,l->out_frame, &tmpl, yuv_sws_get_cpu_flags()); + if(l->scaler == NULL) { + return 0; + } + veejay_msg(VEEJAY_MSG_DEBUG, "[MLZO] Using libswscale for target resolution/pixelformat" ); + } + + l->out_frame->data[0] = dst[0]; + l->out_frame->data[1] = dst[1]; + l->out_frame->data[2] = dst[2]; + } + + l->wrkmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); + if(l->wrkmem == NULL ) + { + veejay_msg(VEEJAY_MSG_ERROR, "LZO Cannot allocate work memory for LZO1X_1"); + return 0; + } + + result_len = lzo_decompress_plane(l, linbuf + offset, len[1] + len[2] + len[3], is_direct, dst[0], expected_length); + sum += result_len; + + if(!is_direct) { + yuv_convert_and_scale( l->scaler, l->in_frame, l->out_frame); + } + + /*veejay_msg(VEEJAY_MSG_DEBUG, "LZO block size: %zu, data size: %d, hdr: pixfmt=%zu Y=%zu, U=%zu, V=%zu offset=%zu,%zu,%zu", + result_len, linbuf_len, len[0],len[1],len[2],len[3], + offset, + offset + len[1] , + offset + len[1] + len[2] );*/ + + free(l->wrkmem); + + return (long) result_len; } + diff --git a/veejay-current/veejay-core/thirdparty/liblzo/lzo.h b/veejay-current/veejay-core/thirdparty/liblzo/lzo.h index a9bb5020..434f3751 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/lzo.h +++ b/veejay-current/veejay-core/thirdparty/liblzo/lzo.h @@ -19,13 +19,10 @@ #ifndef LZOH #define LZOH - -void *lzo_new( ); +#define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long)) +void *lzo_new( int pf, int wid, int hei, int is_decoder ); void lzo_print_buf( uint8_t *buf, int len ); void lzo_free( void *lzo ); -long lzo_compress( void *lzo, uint8_t *src, uint8_t *plane, unsigned int *size, int ilen ); -long lzo_decompress420into422( void *lzo, uint8_t *linbuf, int linbuf_len, uint8_t *dst[3], int w, int h ); -long lzo_decompress_el( void *lzo, uint8_t *linbuf, int linbuf_len,uint8_t *dst[3], int uv_len); -long lzo_decompress( void *lzo, uint8_t *linbuf, int linbuf_len,uint8_t *dst[3], int uv_len, uint32_t s1, uint32_t s2, uint32_t s3 ); - +long lzo_decompress_el( void *lzo, uint8_t *linbuf, int linbuf_len,uint8_t *dst[4], int width, int height, int pixfmt); +long lzo_compress_frame( void *lzo, VJFrame *frame, uint8_t *src[4], uint8_t *dst ); #endif diff --git a/veejay-current/veejay-core/thirdparty/liblzo/lzoconf.h b/veejay-current/veejay-core/thirdparty/liblzo/lzoconf.h index 64ef2793..f9a8bdbe 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/lzoconf.h +++ b/veejay-current/veejay-core/thirdparty/liblzo/lzoconf.h @@ -2,7 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -29,9 +29,9 @@ #ifndef __LZOCONF_H_INCLUDED #define __LZOCONF_H_INCLUDED 1 -#define LZO_VERSION 0x2090 -#define LZO_VERSION_STRING "2.09" -#define LZO_VERSION_DATE "Feb 04 2015" +#define LZO_VERSION 0x20a0 /* 2.10 */ +#define LZO_VERSION_STRING "2.10" +#define LZO_VERSION_DATE "Mar 01 2017" /* internal Autoconf configuration file - only used when building LZO */ #if defined(LZO_HAVE_CONFIG_H) diff --git a/veejay-current/veejay-core/thirdparty/liblzo/lzodefs.h b/veejay-current/veejay-core/thirdparty/liblzo/lzodefs.h index 1535c1e2..c3e2bcf5 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/lzodefs.h +++ b/veejay-current/veejay-core/thirdparty/liblzo/lzodefs.h @@ -2,7 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -40,6 +40,33 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif +#if 0 +#elif !defined(__LZO_LANG_OVERRIDE) +#if (defined(__clang__) || defined(__GNUC__)) && defined(__ASSEMBLER__) +# if (__ASSEMBLER__+0) <= 0 +# error "__ASSEMBLER__" +# else +# define LZO_LANG_ASSEMBLER 1 +# endif +#elif defined(__cplusplus) +# if (__cplusplus+0) <= 0 +# error "__cplusplus" +# elif (__cplusplus < 199711L) +# define LZO_LANG_CXX 1 +# elif defined(_MSC_VER) && defined(_MSVC_LANG) && (_MSVC_LANG+0 >= 201402L) && 1 +# define LZO_LANG_CXX _MSVC_LANG +# else +# define LZO_LANG_CXX __cplusplus +# endif +# define LZO_LANG_CPLUSPLUS LZO_LANG_CXX +#else +# if defined(__STDC_VERSION__) && (__STDC_VERSION__+0 >= 199409L) +# define LZO_LANG_C __STDC_VERSION__ +# else +# define LZO_LANG_C 1 +# endif +#endif +#endif #if !defined(LZO_CFG_NO_DISABLE_WUNDEF) #if defined(__ARMCC_VERSION) # pragma diag_suppress 193 @@ -135,10 +162,12 @@ # endif #endif #endif -#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +#if (UINT_MAX == LZO_0xffffL) +#if defined(_MSC_VER) && defined(M_I86HM) # define ptrdiff_t long # define _PTRDIFF_T_DEFINED 1 #endif +#endif #if (UINT_MAX == LZO_0xffffL) # undef __LZO_RENAME_A # undef __LZO_RENAME_B @@ -287,7 +316,7 @@ #define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) #define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-((b)!=0))) - (o)) << 1) + (o)*((b)!=0)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -538,6 +567,12 @@ # define LZO_CC_ARMCC __ARMCC_VERSION # define LZO_INFO_CC "ARM C Compiler" # define LZO_INFO_CCVER __VERSION__ +#elif defined(__clang__) && defined(__c2__) && defined(__c2_version__) && defined(_MSC_VER) +# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) +# define LZO_CC_CLANG_C2 _MSC_VER +# define LZO_CC_CLANG_VENDOR_MICROSOFT 1 +# define LZO_INFO_CC "clang/c2" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__c2_version__) #elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) # define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) @@ -549,8 +584,18 @@ # elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif -# define LZO_INFO_CC "clang" -# define LZO_INFO_CCVER __VERSION__ +# if defined(__APPLE_CC__) +# define LZO_CC_CLANG_VENDOR_APPLE 1 +# define LZO_INFO_CC "clang/apple" +# else +# define LZO_CC_CLANG_VENDOR_LLVM 1 +# define LZO_INFO_CC "clang" +# endif +# if defined(__clang_version__) +# define LZO_INFO_CCVER __clang_version__ +# else +# define LZO_INFO_CCVER __VERSION__ +# endif #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) @@ -770,7 +815,7 @@ #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) +#elif defined(__aarch64__) || defined(_M_ARM64) # define LZO_ARCH_ARM64 1 # define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) @@ -860,6 +905,15 @@ #elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) # define LZO_ARCH_POWERPC 1 # define LZO_INFO_ARCH "powerpc" +#elif defined(__powerpc64__) || defined(__powerpc64) || defined(__ppc64__) || defined(__PPC64__) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__powerpc64le__) || defined(__powerpc64le) || defined(__ppc64le__) || defined(__PPC64LE__) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__riscv) +# define LZO_ARCH_RISCV 1 +# define LZO_INFO_ARCH "riscv" #elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) # define LZO_ARCH_S390 1 # define LZO_INFO_ARCH "s390" @@ -896,17 +950,21 @@ #endif #if !defined(LZO_ARCH_ARM_THUMB2) #if (LZO_ARCH_ARM) -# if defined(__ARM_ARCH_ISA_THUMB) -# if ((__ARM_ARCH_ISA_THUMB)+0 >= 2) -# define LZO_ARCH_ARM_THUMB2 1 -# endif -# elif 1 && defined(__thumb2__) -# define LZO_ARCH_ARM_THUMB2 1 -# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) -# define LZO_ARCH_ARM_THUMB2 1 +# if defined(__thumb__) || defined(__thumb) || defined(_M_THUMB) +# if defined(__thumb2__) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(_MSC_VER) && defined(_M_THUMB) && ((_M_THUMB)+0 >= 7) +# define LZO_ARCH_ARM_THUMB2 1 +# endif # endif #endif #endif +#if (LZO_ARCH_ARM_THUMB2) +# undef LZO_INFO_ARCH +# define LZO_INFO_ARCH "arm_thumb2" +#endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) # error "FIXME - missing define for CPU architecture" #endif @@ -1110,7 +1168,7 @@ # error "unexpected configuration - check your compiler defines" # endif #endif -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) @@ -1133,7 +1191,7 @@ extern "C" { #else # error "FIXME - implement LZO_MM_AHSHIFT" #endif -#ifdef __cplusplus +#if defined(__cplusplus) } #endif #endif @@ -1219,7 +1277,6 @@ extern "C" { # define __lzo_gnuc_extension__ __extension__ #elif (LZO_CC_IBMC >= 600) # define __lzo_gnuc_extension__ __extension__ -#else #endif #endif #if !defined(__lzo_gnuc_extension__) @@ -1265,7 +1322,7 @@ extern "C" { #endif #endif #if !defined(lzo_has_extension) -# define lzo_has_extension 0 +# define lzo_has_extension(x) 0 #endif #if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) @@ -1412,6 +1469,9 @@ extern "C" { # define LZO_UNUSED(var) ((void) &var) # endif #endif +#if !defined(LZO_UNUSED_RESULT) +# define LZO_UNUSED_RESULT(var) LZO_UNUSED(var) +#endif #if !defined(LZO_UNUSED_FUNC) # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) # define LZO_UNUSED_FUNC(func) ((void) func) @@ -1830,6 +1890,7 @@ extern "C" { #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG && LZO_CC_CLANG_C2) #elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) @@ -1942,11 +2003,16 @@ extern "C" { # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} # endif #endif +#if (LZO_LANG_ASSEMBLER) +# undef LZO_COMPILE_TIME_ASSERT_HEADER +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) /*empty*/ +#else LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) #if defined(__cplusplus) extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } #endif LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) +#endif #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) @@ -2021,6 +2087,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) #endif #endif #endif +#define LZO_SIZEOF_CHAR 1 #ifndef LZO_SIZEOF_SHORT #if defined(SIZEOF_SHORT) # define LZO_SIZEOF_SHORT (SIZEOF_SHORT) @@ -2219,12 +2286,12 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) # define LZO_WORDSIZE 8 #elif (LZO_ARCH_AMD64) # define LZO_WORDSIZE 8 +#elif (LZO_ARCH_ARM64) +# define LZO_WORDSIZE 8 #elif (LZO_ARCH_AVR) # define LZO_WORDSIZE 1 #elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_WORDSIZE 4 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) # define LZO_WORDSIZE 4 # else # define LZO_WORDSIZE 2 @@ -2267,11 +2334,15 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) # define LZO_SIZEOF_VOID_P 2 #elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_SIZEOF_VOID_P 4 +# if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) + LZO_COMPILE_TIME_ASSERT_HEADER(LZO_WORDSIZE == 4) +# if defined(__NORMAL_MODE__) +# define LZO_SIZEOF_VOID_P 2 +# else +# define LZO_SIZEOF_VOID_P 4 +# endif # else + LZO_COMPILE_TIME_ASSERT_HEADER(LZO_WORDSIZE == 2) # define LZO_SIZEOF_VOID_P 2 # endif # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) @@ -2361,7 +2432,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) # define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430 || LZO_ARCH_RISCV) # define LZO_ABI_LITTLE_ENDIAN 1 #elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) # define LZO_ABI_BIG_ENDIAN 1 @@ -2381,6 +2452,8 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) # define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(_MSC_VER) && defined(_WIN32) +# define LZO_ABI_LITTLE_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) # if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) # error "unexpected configuration - check your compiler defines" @@ -2396,6 +2469,8 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) # define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(_MSC_VER) && defined(_WIN32) +# define LZO_ABI_LITTLE_ENDIAN 1 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) @@ -2437,6 +2512,12 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_IP32L64 1 # define LZO_INFO_ABI_PM "ip32l64" #endif +#if (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_VOID_P == 4 && LZO_WORDSIZE == 8) +# define LZO_ABI_IP32W64 1 +# ifndef LZO_INFO_ABI_PM +# define LZO_INFO_ABI_PM "ip32w64" +# endif +#endif #if 0 #elif !defined(__LZO_LIBC_OVERRIDE) #if (LZO_LIBC_NAKED) @@ -2539,6 +2620,13 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # ifndef LZO_OPT_UNALIGNED32 # define LZO_OPT_UNALIGNED32 1 # endif +# elif 1 && defined(__ARM_ARCH) && ((__ARM_ARCH)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 7) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 @@ -2553,6 +2641,13 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # ifndef LZO_OPT_UNALIGNED32 # define LZO_OPT_UNALIGNED32 1 # endif +# elif 1 && defined(_MSC_VER) && defined(_M_ARM) && ((_M_ARM)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # endif #elif (LZO_ARCH_ARM64) # ifndef LZO_OPT_UNALIGNED16 @@ -2598,7 +2693,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #elif (LZO_ARCH_POWERPC) # define LZO_OPT_PREFER_PREINC 1 # define LZO_OPT_PREFER_PREDEC 1 -# if (LZO_ABI_BIG_ENDIAN) +# if (LZO_ABI_BIG_ENDIAN) || (LZO_WORDSIZE == 8) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 # endif @@ -2611,6 +2706,19 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # endif # endif # endif +#elif (LZO_ARCH_RISCV) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif +# endif #elif (LZO_ARCH_S390) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 @@ -2721,18 +2829,23 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #define LZO_TYPEOF_CHAR_P 129u #if !defined(lzo_llong_t) #if (LZO_SIZEOF_LONG_LONG+0 > 0) -__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# if !(LZO_LANG_ASSEMBLER) + __lzo_gnuc_extension__ typedef long long lzo_llong_t__; + __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# endif # define lzo_llong_t lzo_llong_t__ # define lzo_ullong_t lzo_ullong_t__ #endif #endif #if !defined(lzo_int16e_t) -#if (LZO_SIZEOF_LONG == 2) +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) && (LZO_SIZEOF_SHORT != 2) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T +#endif +#if (LZO_SIZEOF_LONG == 2) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) # define lzo_int16e_t long # define lzo_uint16e_t unsigned long # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_LONG -#elif (LZO_SIZEOF_INT == 2) +#elif (LZO_SIZEOF_INT == 2) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) # define lzo_int16e_t int # define lzo_uint16e_t unsigned int # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_INT @@ -2741,8 +2854,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define lzo_uint16e_t unsigned short int # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_SHORT #elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); +# endif # define lzo_int16e_t lzo_int16e_hi_t__ # define lzo_uint16e_t lzo_uint16e_hi_t__ # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___MODE_HI @@ -2759,7 +2874,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) #endif #if !defined(lzo_int32e_t) -#if (LZO_SIZEOF_LONG == 4) +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T == LZO_TYPEOF_INT) && (LZO_SIZEOF_INT != 4) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T +#endif +#if (LZO_SIZEOF_LONG == 4) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T == LZO_TYPEOF_INT) # define lzo_int32e_t long int # define lzo_uint32e_t unsigned long int # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG @@ -2776,14 +2894,18 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define lzo_uint32e_t lzo_ullong_t # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG_LONG #elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# endif # define lzo_int32e_t lzo_int32e_si_t__ # define lzo_uint32e_t lzo_uint32e_si_t__ # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI #elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# endif # define lzo_int32e_t lzo_int32e_si_t__ # define lzo_uint32e_t lzo_uint32e_si_t__ # define LZO_INT32_C(c) (c##LL) @@ -2803,19 +2925,25 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; #endif #if !defined(lzo_int64e_t) #if (LZO_SIZEOF___INT64 == 8) -# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -# define LZO_CFG_TYPE_PREFER___INT64 1 +# if (LZO_CC_BORLANDC) && !defined(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T) +# define LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T LZO_TYPEOF___INT64 # endif #endif +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF_LONG_LONG) && (LZO_SIZEOF_LONG_LONG != 8) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T +#endif +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) && (LZO_SIZEOF___INT64 != 8) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T +#endif #if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) # define lzo_int64e_t int # define lzo_uint64e_t unsigned int # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_INT -#elif (LZO_SIZEOF_LONG == 8) +#elif (LZO_SIZEOF_LONG == 8) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF_LONG_LONG) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) # define lzo_int64e_t long int # define lzo_uint64e_t unsigned long int # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG -#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) +#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) # define lzo_int64e_t lzo_llong_t # define lzo_uint64e_t lzo_ullong_t # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG_LONG @@ -2918,15 +3046,19 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; #if !defined(lzo_intptr_t) #if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) # define __LZO_INTPTR_T_IS_POINTER 1 +# if !(LZO_LANG_ASSEMBLER) typedef char * lzo_intptr_t; typedef char * lzo_uintptr_t; +# endif # define lzo_intptr_t lzo_intptr_t # define lzo_uintptr_t lzo_uintptr_t # define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P # define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_CHAR_P #elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) +# if !(LZO_LANG_ASSEMBLER) typedef __w64 int lzo_intptr_t; typedef __w64 unsigned int lzo_uintptr_t; +# endif # define lzo_intptr_t lzo_intptr_t # define lzo_uintptr_t lzo_uintptr_t # define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT @@ -2993,8 +3125,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define LZO_TYPEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T #elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) #if 0 +# if !(LZO_LANG_ASSEMBLER) typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); +# endif # define lzo_word_t lzo_word_t # define lzo_sword_t lzo_sword_t # define LZO_SIZEOF_LZO_WORD_T 16 diff --git a/veejay-current/veejay-core/thirdparty/liblzo/minilzo.c b/veejay-current/veejay-core/thirdparty/liblzo/minilzo.c index 801f5300..ca14520e 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/minilzo.c +++ b/veejay-current/veejay-core/thirdparty/liblzo/minilzo.c @@ -1,8 +1,26 @@ +/** + * (C) 2007-22 - ntop.org and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not see see + * + */ + /* minilzo.c -- mini subset of the LZO real-time data compression library This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -60,6 +78,33 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif +#if 0 +#elif !defined(__LZO_LANG_OVERRIDE) +#if (defined(__clang__) || defined(__GNUC__)) && defined(__ASSEMBLER__) +# if (__ASSEMBLER__+0) <= 0 +# error "__ASSEMBLER__" +# else +# define LZO_LANG_ASSEMBLER 1 +# endif +#elif defined(__cplusplus) +# if (__cplusplus+0) <= 0 +# error "__cplusplus" +# elif (__cplusplus < 199711L) +# define LZO_LANG_CXX 1 +# elif defined(_MSC_VER) && defined(_MSVC_LANG) && (_MSVC_LANG+0 >= 201402L) && 1 +# define LZO_LANG_CXX _MSVC_LANG +# else +# define LZO_LANG_CXX __cplusplus +# endif +# define LZO_LANG_CPLUSPLUS LZO_LANG_CXX +#else +# if defined(__STDC_VERSION__) && (__STDC_VERSION__+0 >= 199409L) +# define LZO_LANG_C __STDC_VERSION__ +# else +# define LZO_LANG_C 1 +# endif +#endif +#endif #if !defined(LZO_CFG_NO_DISABLE_WUNDEF) #if defined(__ARMCC_VERSION) # pragma diag_suppress 193 @@ -155,10 +200,12 @@ # endif #endif #endif -#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) +#if (UINT_MAX == LZO_0xffffL) +#if defined(_MSC_VER) && defined(M_I86HM) # define ptrdiff_t long # define _PTRDIFF_T_DEFINED 1 #endif +#endif #if (UINT_MAX == LZO_0xffffL) # undef __LZO_RENAME_A # undef __LZO_RENAME_B @@ -307,7 +354,7 @@ #define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) #define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-((b)!=0))) - (o)) << 1) + (o)*((b)!=0)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -558,6 +605,12 @@ # define LZO_CC_ARMCC __ARMCC_VERSION # define LZO_INFO_CC "ARM C Compiler" # define LZO_INFO_CCVER __VERSION__ +#elif defined(__clang__) && defined(__c2__) && defined(__c2_version__) && defined(_MSC_VER) +# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) +# define LZO_CC_CLANG_C2 _MSC_VER +# define LZO_CC_CLANG_VENDOR_MICROSOFT 1 +# define LZO_INFO_CC "clang/c2" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__c2_version__) #elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) # define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) @@ -569,8 +622,18 @@ # elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif -# define LZO_INFO_CC "clang" -# define LZO_INFO_CCVER __VERSION__ +# if defined(__APPLE_CC__) +# define LZO_CC_CLANG_VENDOR_APPLE 1 +# define LZO_INFO_CC "clang/apple" +# else +# define LZO_CC_CLANG_VENDOR_LLVM 1 +# define LZO_INFO_CC "clang" +# endif +# if defined(__clang_version__) +# define LZO_INFO_CCVER __clang_version__ +# else +# define LZO_INFO_CCVER __VERSION__ +# endif #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) # define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) @@ -790,7 +853,7 @@ #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) +#elif defined(__aarch64__) || defined(_M_ARM64) # define LZO_ARCH_ARM64 1 # define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) @@ -880,6 +943,15 @@ #elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) # define LZO_ARCH_POWERPC 1 # define LZO_INFO_ARCH "powerpc" +#elif defined(__powerpc64__) || defined(__powerpc64) || defined(__ppc64__) || defined(__PPC64__) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__powerpc64le__) || defined(__powerpc64le) || defined(__ppc64le__) || defined(__PPC64LE__) +# define LZO_ARCH_POWERPC 1 +# define LZO_INFO_ARCH "powerpc" +#elif defined(__riscv) +# define LZO_ARCH_RISCV 1 +# define LZO_INFO_ARCH "riscv" #elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) # define LZO_ARCH_S390 1 # define LZO_INFO_ARCH "s390" @@ -916,17 +988,21 @@ #endif #if !defined(LZO_ARCH_ARM_THUMB2) #if (LZO_ARCH_ARM) -# if defined(__ARM_ARCH_ISA_THUMB) -# if ((__ARM_ARCH_ISA_THUMB)+0 >= 2) -# define LZO_ARCH_ARM_THUMB2 1 -# endif -# elif 1 && defined(__thumb2__) -# define LZO_ARCH_ARM_THUMB2 1 -# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) -# define LZO_ARCH_ARM_THUMB2 1 +# if defined(__thumb__) || defined(__thumb) || defined(_M_THUMB) +# if defined(__thumb2__) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(_MSC_VER) && defined(_M_THUMB) && ((_M_THUMB)+0 >= 7) +# define LZO_ARCH_ARM_THUMB2 1 +# endif # endif #endif #endif +#if (LZO_ARCH_ARM_THUMB2) +# undef LZO_INFO_ARCH +# define LZO_INFO_ARCH "arm_thumb2" +#endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) # error "FIXME - missing define for CPU architecture" #endif @@ -1130,7 +1206,7 @@ # error "unexpected configuration - check your compiler defines" # endif #endif -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) @@ -1153,7 +1229,7 @@ extern "C" { #else # error "FIXME - implement LZO_MM_AHSHIFT" #endif -#ifdef __cplusplus +#if defined(__cplusplus) } #endif #endif @@ -1239,7 +1315,6 @@ extern "C" { # define __lzo_gnuc_extension__ __extension__ #elif (LZO_CC_IBMC >= 600) # define __lzo_gnuc_extension__ __extension__ -#else #endif #endif #if !defined(__lzo_gnuc_extension__) @@ -1285,7 +1360,7 @@ extern "C" { #endif #endif #if !defined(lzo_has_extension) -# define lzo_has_extension 0 +# define lzo_has_extension(x) 0 #endif #if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) @@ -1432,6 +1507,9 @@ extern "C" { # define LZO_UNUSED(var) ((void) &var) # endif #endif +#if !defined(LZO_UNUSED_RESULT) +# define LZO_UNUSED_RESULT(var) LZO_UNUSED(var) +#endif #if !defined(LZO_UNUSED_FUNC) # if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) # define LZO_UNUSED_FUNC(func) ((void) func) @@ -1850,6 +1928,7 @@ extern "C" { #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_CLANG && LZO_CC_CLANG_C2) #elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) @@ -1962,11 +2041,16 @@ extern "C" { # define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} # endif #endif +#if (LZO_LANG_ASSEMBLER) +# undef LZO_COMPILE_TIME_ASSERT_HEADER +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) /*empty*/ +#else LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) #if defined(__cplusplus) extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } #endif LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) +#endif #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) @@ -2041,6 +2125,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) #endif #endif #endif +#define LZO_SIZEOF_CHAR 1 #ifndef LZO_SIZEOF_SHORT #if defined(SIZEOF_SHORT) # define LZO_SIZEOF_SHORT (SIZEOF_SHORT) @@ -2239,12 +2324,12 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) # define LZO_WORDSIZE 8 #elif (LZO_ARCH_AMD64) # define LZO_WORDSIZE 8 +#elif (LZO_ARCH_ARM64) +# define LZO_WORDSIZE 8 #elif (LZO_ARCH_AVR) # define LZO_WORDSIZE 1 #elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_WORDSIZE 4 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) # define LZO_WORDSIZE 4 # else # define LZO_WORDSIZE 2 @@ -2287,11 +2372,15 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) # define LZO_SIZEOF_VOID_P 2 #elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define LZO_SIZEOF_VOID_P 4 +# if defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) + LZO_COMPILE_TIME_ASSERT_HEADER(LZO_WORDSIZE == 4) +# if defined(__NORMAL_MODE__) +# define LZO_SIZEOF_VOID_P 2 +# else +# define LZO_SIZEOF_VOID_P 4 +# endif # else + LZO_COMPILE_TIME_ASSERT_HEADER(LZO_WORDSIZE == 2) # define LZO_SIZEOF_VOID_P 2 # endif # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) @@ -2381,7 +2470,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) # define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430 || LZO_ARCH_RISCV) # define LZO_ABI_LITTLE_ENDIAN 1 #elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) # define LZO_ABI_BIG_ENDIAN 1 @@ -2401,6 +2490,8 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) # define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(_MSC_VER) && defined(_WIN32) +# define LZO_ABI_LITTLE_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) # if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) # error "unexpected configuration - check your compiler defines" @@ -2416,6 +2507,8 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) # define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(_MSC_VER) && defined(_WIN32) +# define LZO_ABI_LITTLE_ENDIAN 1 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) # define LZO_ABI_BIG_ENDIAN 1 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) @@ -2457,6 +2550,12 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # define LZO_ABI_IP32L64 1 # define LZO_INFO_ABI_PM "ip32l64" #endif +#if (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_VOID_P == 4 && LZO_WORDSIZE == 8) +# define LZO_ABI_IP32W64 1 +# ifndef LZO_INFO_ABI_PM +# define LZO_INFO_ABI_PM "ip32w64" +# endif +#endif #if 0 #elif !defined(__LZO_LIBC_OVERRIDE) #if (LZO_LIBC_NAKED) @@ -2559,6 +2658,13 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # ifndef LZO_OPT_UNALIGNED32 # define LZO_OPT_UNALIGNED32 1 # endif +# elif 1 && defined(__ARM_ARCH) && ((__ARM_ARCH)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 7) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 @@ -2573,6 +2679,13 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # ifndef LZO_OPT_UNALIGNED32 # define LZO_OPT_UNALIGNED32 1 # endif +# elif 1 && defined(_MSC_VER) && defined(_M_ARM) && ((_M_ARM)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # endif #elif (LZO_ARCH_ARM64) # ifndef LZO_OPT_UNALIGNED16 @@ -2618,7 +2731,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #elif (LZO_ARCH_POWERPC) # define LZO_OPT_PREFER_PREINC 1 # define LZO_OPT_PREFER_PREDEC 1 -# if (LZO_ABI_BIG_ENDIAN) +# if (LZO_ABI_BIG_ENDIAN) || (LZO_WORDSIZE == 8) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 # endif @@ -2631,6 +2744,19 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) # endif # endif # endif +#elif (LZO_ARCH_RISCV) +# define LZO_OPT_AVOID_UINT_INDEX 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif +# endif #elif (LZO_ARCH_S390) # ifndef LZO_OPT_UNALIGNED16 # define LZO_OPT_UNALIGNED16 1 @@ -2741,18 +2867,23 @@ LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) #define LZO_TYPEOF_CHAR_P 129u #if !defined(lzo_llong_t) #if (LZO_SIZEOF_LONG_LONG+0 > 0) -__lzo_gnuc_extension__ typedef long long lzo_llong_t__; -__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# if !(LZO_LANG_ASSEMBLER) + __lzo_gnuc_extension__ typedef long long lzo_llong_t__; + __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# endif # define lzo_llong_t lzo_llong_t__ # define lzo_ullong_t lzo_ullong_t__ #endif #endif #if !defined(lzo_int16e_t) -#if (LZO_SIZEOF_LONG == 2) +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) && (LZO_SIZEOF_SHORT != 2) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T +#endif +#if (LZO_SIZEOF_LONG == 2) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) # define lzo_int16e_t long # define lzo_uint16e_t unsigned long # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_LONG -#elif (LZO_SIZEOF_INT == 2) +#elif (LZO_SIZEOF_INT == 2) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT16E_T == LZO_TYPEOF_SHORT) # define lzo_int16e_t int # define lzo_uint16e_t unsigned int # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_INT @@ -2761,8 +2892,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define lzo_uint16e_t unsigned short int # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_SHORT #elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); +# endif # define lzo_int16e_t lzo_int16e_hi_t__ # define lzo_uint16e_t lzo_uint16e_hi_t__ # define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___MODE_HI @@ -2779,7 +2912,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) #endif #if !defined(lzo_int32e_t) -#if (LZO_SIZEOF_LONG == 4) +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T == LZO_TYPEOF_INT) && (LZO_SIZEOF_INT != 4) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T +#endif +#if (LZO_SIZEOF_LONG == 4) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT32E_T == LZO_TYPEOF_INT) # define lzo_int32e_t long int # define lzo_uint32e_t unsigned long int # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG @@ -2796,14 +2932,18 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define lzo_uint32e_t lzo_ullong_t # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG_LONG #elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# endif # define lzo_int32e_t lzo_int32e_si_t__ # define lzo_uint32e_t lzo_uint32e_si_t__ # define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI #elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) +# if !(LZO_LANG_ASSEMBLER) typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# endif # define lzo_int32e_t lzo_int32e_si_t__ # define lzo_uint32e_t lzo_uint32e_si_t__ # define LZO_INT32_C(c) (c##LL) @@ -2823,19 +2963,25 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; #endif #if !defined(lzo_int64e_t) #if (LZO_SIZEOF___INT64 == 8) -# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) -# define LZO_CFG_TYPE_PREFER___INT64 1 +# if (LZO_CC_BORLANDC) && !defined(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T) +# define LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T LZO_TYPEOF___INT64 # endif #endif +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF_LONG_LONG) && (LZO_SIZEOF_LONG_LONG != 8) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T +#endif +#if (LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) && (LZO_SIZEOF___INT64 != 8) +# undef LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T +#endif #if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) # define lzo_int64e_t int # define lzo_uint64e_t unsigned int # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_INT -#elif (LZO_SIZEOF_LONG == 8) +#elif (LZO_SIZEOF_LONG == 8) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF_LONG_LONG) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) # define lzo_int64e_t long int # define lzo_uint64e_t unsigned long int # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG -#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) +#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_PREFER_TYPEOF_ACC_INT64E_T == LZO_TYPEOF___INT64) # define lzo_int64e_t lzo_llong_t # define lzo_uint64e_t lzo_ullong_t # define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG_LONG @@ -2938,15 +3084,19 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; #if !defined(lzo_intptr_t) #if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) # define __LZO_INTPTR_T_IS_POINTER 1 +# if !(LZO_LANG_ASSEMBLER) typedef char * lzo_intptr_t; typedef char * lzo_uintptr_t; +# endif # define lzo_intptr_t lzo_intptr_t # define lzo_uintptr_t lzo_uintptr_t # define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P # define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_CHAR_P #elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) +# if !(LZO_LANG_ASSEMBLER) typedef __w64 int lzo_intptr_t; typedef __w64 unsigned int lzo_uintptr_t; +# endif # define lzo_intptr_t lzo_intptr_t # define lzo_uintptr_t lzo_uintptr_t # define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT @@ -3013,8 +3163,10 @@ __lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; # define LZO_TYPEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T #elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) #if 0 +# if !(LZO_LANG_ASSEMBLER) typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); +# endif # define lzo_word_t lzo_word_t # define lzo_sword_t lzo_sword_t # define LZO_SIZEOF_LZO_WORD_T 16 @@ -3156,7 +3308,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #undef LZO_HAVE_CONFIG_H #include "minilzo.h" -#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2090) +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x20a0) # error "version mismatch in miniLZO source files" #endif @@ -3194,7 +3346,7 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast6 #endif #endif -#if !defined(__LZOCONF_H_INCLUDED) || (LZO_VERSION+0 != 0x2090) +#if !defined(__LZOCONF_H_INCLUDED) || (LZO_VERSION+0 != 0x20a0) # error "version mismatch" #endif @@ -4088,7 +4240,7 @@ static const char lzo_copyright_[] = #else "\r\n\n" "LZO data compression library.\n" - "$Copyright: LZO Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer\n" + "$Copyright: LZO Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\n" "\n" "http://www.oberhumer.com $\n\n" "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" @@ -6204,6 +6356,7 @@ match_next: eof_found: *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); @@ -6228,4 +6381,4 @@ lookbehind_overrun: #endif -/***** End of minilzo.c *****/ +/***** End of minilzo.c *****/ \ No newline at end of file diff --git a/veejay-current/veejay-core/thirdparty/liblzo/minilzo.h b/veejay-current/veejay-core/thirdparty/liblzo/minilzo.h index e5adc6ed..c1c22975 100644 --- a/veejay-current/veejay-core/thirdparty/liblzo/minilzo.h +++ b/veejay-current/veejay-core/thirdparty/liblzo/minilzo.h @@ -2,7 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -35,7 +35,7 @@ #ifndef __MINILZO_H_INCLUDED #define __MINILZO_H_INCLUDED 1 -#define MINILZO_VERSION 0x2090 +#define MINILZO_VERSION 0x20a0 /* 2.10 */ #if defined(__LZOCONF_H_INCLUDED) # error "you cannot use both LZO and miniLZO" diff --git a/veejay-current/veejay-core/veejaycore/Makefile.am b/veejay-current/veejay-core/veejaycore/Makefile.am index 78c52a4c..2a7cbf34 100644 --- a/veejay-current/veejay-core/veejaycore/Makefile.am +++ b/veejay-current/veejay-core/veejaycore/Makefile.am @@ -18,7 +18,7 @@ AM_CPPFLAGS += -I /usr/X11R6/include \ $(LIBAVFORMAT_CFLAGS) $(LIBAVCODEC_CFLAGS) $(LIBAVUTIL_CFLAGS) $(LIBSWSCALE_CFLAGS) $(GLIB_CFLAGS) \ $(PTHREAD_CFLAGS) -pkginclude_HEADERS = core.h vj-task.h defs.h avhelper.h avcommon.h vims.h +pkginclude_HEADERS = core.h vj-task.h defs.h av.h avhelper.h avcommon.h vims.h VEEJAYCORE_LIB_FILE = libveejaycore.la diff --git a/veejay-current/veejay-core/veejaycore/av.h b/veejay-current/veejay-core/veejaycore/av.h index d25d89d3..673a962e 100755 --- a/veejay-current/veejay-core/veejaycore/av.h +++ b/veejay-current/veejay-core/veejaycore/av.h @@ -87,6 +87,10 @@ extern void av_frame_unref(AVFrame *ptr) __attribute((weak)); #define CODEC_ID_HUFFYUV AV_CODEC_ID_HUFFYUV #endif +#ifndef CODEC_ID_FFVHUFF +#define CODEC_ID_FFVHUFF AV_CODEC_ID_FFVHUFF +#endif + #ifndef CODEC_ID_CYUV #define CODEC_ID_CYUV AV_CODEC_ID_CYUV #endif diff --git a/veejay-current/veejay-core/veejaycore/avhelper.h b/veejay-current/veejay-core/veejaycore/avhelper.h index fdf739e4..11655c4d 100644 --- a/veejay-current/veejay-core/veejaycore/avhelper.h +++ b/veejay-current/veejay-core/veejaycore/avhelper.h @@ -20,6 +20,8 @@ #ifndef AVHELPER_H #define AVHELPER_H +#include + #define CODEC_ID_YUV420 999 #define CODEC_ID_YUV422 998 #define CODEC_ID_YUV422F 997 @@ -42,7 +44,9 @@ void avhelper_close_decoder( void *ptr ); int avhelper_decode_video( void *ptr, uint8_t *data, int len); -void avhelper_rescale_video(void *ptr, uint8_t *dst[4]); +int avhelper_rescale_video(void *ptr, uint8_t *dst[4]); + +int avhelper_decode_video_direct( void *ptr, uint8_t *data, int len, uint8_t *dst[4], int pf, int w, int h ); void *avhelper_get_decoder( const char *filename, int dst_pixfmt, int dst_width, int dst_height ); @@ -50,13 +54,15 @@ void *avhelper_get_stream_decoder( const char *filename, int dst_pixfmt, int dst VJFrame *avhelper_get_decoded_video(void *ptr); +int avhelper_decode_video3( AVCodecContext *avctx, AVFrame *frame, int *got_picture,AVPacket *pkt); + void avhelper_free_context(AVCodecContext **avctx); void avhelper_frame_unref(AVFrame *ptr); void *avhelper_get_mjpeg_decoder(VJFrame *output_info); -int avhelper_get_frame( void *decoder, int *got_picture ); +void avhelper_free_packet(AVPacket *pkt); VJFrame *avhelper_get_input_frame( void *ptr ); diff --git a/veejay-current/veejay-server/configure.ac b/veejay-current/veejay-server/configure.ac index 3d44be2f..0788cc85 100644 --- a/veejay-current/veejay-server/configure.ac +++ b/veejay-current/veejay-server/configure.ac @@ -282,7 +282,7 @@ case $host_cpu in have_x86cpu=true have_x86_64cpu=true if test "x$enable_debug" != "xyes" ; then - VJE_CFLAGS="-O3 -ffast-math -ftree-vectorize -m64 -fPIC -DPIC" + VJE_CFLAGS="-ffast-math -m64 -fPIC -DPIC" SUBSAMPLE_CFLAGS="-m64 -fPIC -DPIC -ftree-vectorize" else VJE_CFLAGS="-O3 -ftree-vectorize -fopt-info-vec-optimized -m64 -fPIC -DPIC -g" diff --git a/veejay-current/veejay-server/libel/av.h b/veejay-current/veejay-server/libel/av.h index d25d89d3..94bddde1 100755 --- a/veejay-current/veejay-server/libel/av.h +++ b/veejay-current/veejay-server/libel/av.h @@ -87,6 +87,10 @@ extern void av_frame_unref(AVFrame *ptr) __attribute((weak)); #define CODEC_ID_HUFFYUV AV_CODEC_ID_HUFFYUV #endif +#ifndef CODEC_ID_FFVHUFF +#define CODEC_ID_HUFFYUV AV_CODEC_ID_FFVHUFF +#endif + #ifndef CODEC_ID_CYUV #define CODEC_ID_CYUV AV_CODEC_ID_CYUV #endif diff --git a/veejay-current/veejay-server/libel/avhelper.c b/veejay-current/veejay-server/libel/avhelper.c index 96f215a5..871e6d24 100644 --- a/veejay-current/veejay-server/libel/avhelper.c +++ b/veejay-current/veejay-server/libel/avhelper.c @@ -35,8 +35,9 @@ #include #include #include +#include #include -#include +#include #include static struct @@ -47,23 +48,20 @@ static struct { { "vj20", CODEC_ID_YUV420F }, { "vj22", CODEC_ID_YUV422F }, - { "mjpg" ,CODEC_ID_MJPEG }, + { "mjpg" ,CODEC_ID_MJPEG }, { "mjpb", CODEC_ID_MJPEGB }, { "i420", CODEC_ID_YUV420 }, - { "i422", CODEC_ID_YUV422 }, + { "i422", CODEC_ID_YUV422 }, { "dmb1", CODEC_ID_MJPEG }, { "jpeg", CODEC_ID_MJPEG }, { "mjpa", CODEC_ID_MJPEG }, - { "mjpb", CODEC_ID_MJPEG }, - { "jfif", CODEC_ID_MJPEG }, { "jfif", CODEC_ID_MJPEG }, { "png", CODEC_ID_PNG }, { "mpng", CODEC_ID_PNG }, -#if LIBAVCODEC_BUILD > 4680 +#if LIBAVCODEC_VERSION_MAJOR > 46 && LIBAVCODEC_VERSION_MINOR > 80 { "sp5x", CODEC_ID_SP5X }, #endif { "jpgl", CODEC_ID_MJPEG }, - { "jpgl", CODEC_ID_MJPEG }, { "ljpg", CODEC_ID_LJPEG }, { "dvsd", CODEC_ID_DVVIDEO }, { "dvcp", CODEC_ID_DVVIDEO }, @@ -72,7 +70,6 @@ static struct { "dvp", CODEC_ID_DVVIDEO }, { "yuv", CODEC_ID_YUV420 }, { "iyuv", CODEC_ID_YUV420 }, - { "i420", CODEC_ID_YUV420 }, { "yv16", CODEC_ID_YUV422 }, { "yv12", CODEC_ID_YUV420 }, { "mlzo", CODEC_ID_YUVLZO }, @@ -87,17 +84,33 @@ static struct { NULL , 0, }, }; +//from gst-ffmpeg, round up a number +#define GEN_MASK(x) ((1<<(x))-1) +#define ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x)) +#define ROUND_UP_2(x) ROUND_UP_X (x, 1) +#define ROUND_UP_4(x) ROUND_UP_X (x, 2) +#define ROUND_UP_8(x) ROUND_UP_X (x, 3) +#define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x)) +#define RUP8(num)(((num)+8)&~8) #define MAX_PACKETS 5 typedef struct { +#if LIBAVCODEC_VERSION_MAJOR < 60 AVPacket packets[MAX_PACKETS]; +#else + AVPacket *packets[MAX_PACKETS]; +#endif AVFrame *frames[2]; int frameinfo[2]; AVCodec *codec; AVCodecContext *codec_ctx; AVFormatContext *avformat_ctx; +#if LIBAVCODEC_VERSION_MAJOR >= 60 + AVPacket *packet; + AVFrame *frame; +#endif int frame_index; int pixfmt; int codec_id; @@ -227,6 +240,9 @@ int avhelper_get_codec_by_key( int key ) } hnode_t *node = hash_lookup( fourccTable,(const void*) k); + if( node == NULL ) { + return -1; + } fourcc_node *fourcc = hnode_get(node); if(fourcc) { return fourcc->codec_id; @@ -248,7 +264,16 @@ void *avhelper_get_codec( void *ptr ) return e->codec; } -#if LIBAVCODEC_BUILD > 5400 +void avhelper_codec_close( AVCodecContext *ctx ) { +#if LIBAVCODEC_VERSION_MAJOR >= 60 + avcodec_free_context(&ctx); +#else + avcodec_close(ctx); +#endif +} + + +#if LIBAVCODEC_VERSION_MAJOR > 54 && LIBAVCODEC_VERSION_MAJOR < 60 static int avcodec_decode_video( AVCodecContext *avctx, AVFrame *picture, int *got_picture, uint8_t *data, int pktsize ) { AVPacket pkt; veejay_memset( &pkt, 0, sizeof(AVPacket)); @@ -256,13 +281,54 @@ static int avcodec_decode_video( AVCodecContext *avctx, AVFrame *picture, int *g pkt.size = pktsize; return avcodec_decode_video2( avctx, picture, got_picture, &pkt ); } +#else +static int avcodec_decode_video( AVPacket *pkt, AVCodecContext *avctx, AVFrame *picture, int *got_picture, uint8_t *data, int pktsize ) { + pkt->data = data; + pkt->size = pktsize; + + int ret = avcodec_send_packet( avctx, pkt ); + if( ret < 0 ) { + veejay_msg(0, "Error submitting a packet to the decoder"); + return ret; + } + + ret = avcodec_receive_frame( avctx, picture ); + if( ret < 0 ) { + if( ret == AVERROR_EOF ) { + veejay_msg(VEEJAY_MSG_WARNING, "There is no output"); + *got_picture = 0; + return ret; + } + } + + *got_picture = 1; + + av_packet_unref(pkt); + + return ret; +} #endif +int avhelper_decode_video3( AVCodecContext *avctx, AVFrame *frame, int *got_picture, AVPacket *pkt ) { +#if LIBAVCODEC_VERSION_MAJOR < 60 + return avcodec_decode_video(avctx,frame,got_picture,pkt->data,pkt->size); +#else + return avcodec_decode_video(pkt, avctx,frame,got_picture,pkt->data,pkt->size); +#endif +} + + void avhelper_frame_unref(AVFrame *ptr) { #if (LIBAVCODEC_VERSION_MAJOR > 55 && LIBAVCODEC_VERSION_MINOR > 40) || (LIBAVCODEC_VERSION_MAJOR == 56 && LIBAVCODEC_VERSION_MINOR > 0) av_frame_unref( ptr ); #endif + +#if LIBAVCODEC_VERSION_MAJOR >= 60 + //av_frame_free(&ptr); +#endif + + } void avhelper_free_context(AVCodecContext **avctx) @@ -277,15 +343,25 @@ void avhelper_free_context(AVCodecContext **avctx) } static void avhelper_close_input_file( AVFormatContext *s ) { -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 avformat_close_input(&s); #else av_close_input_file(s); #endif } +void avhelper_free_packet(AVPacket *pkt) { +#if LIBAVCODEC_VERSION_MAJOR < 60 + av_free_packet( pkt ); +#else + av_packet_unref( pkt ); +#endif +} + + void *avhelper_get_mjpeg_decoder(VJFrame *output) { el_decoder_t *x = (el_decoder_t*) vj_calloc( sizeof( el_decoder_t )); + int j; if(!x) { return NULL; } @@ -296,14 +372,17 @@ void *avhelper_get_mjpeg_decoder(VJFrame *output) { return NULL; } -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 x->codec_ctx = avcodec_alloc_context3(x->codec); int n_threads = avhelper_set_num_decoders(); - - if( n_threads > 0 ) { - x->codec_ctx->thread_count = n_threads; + if (x->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) { x->codec_ctx->thread_type = FF_THREAD_FRAME; + x->codec_ctx->thread_count = n_threads; + } + else if (x->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) { + x->codec_ctx->thread_type = FF_THREAD_SLICE; + x->codec_ctx->thread_count = n_threads; } //AVDictionary *options = NULL; @@ -322,7 +401,11 @@ void *avhelper_get_mjpeg_decoder(VJFrame *output) { x->frames[0] = avhelper_alloc_frame(); x->frames[1] = avhelper_alloc_frame(); - +#if LIBAVCODEC_VERSION_MAJOR >= 60 + for(j = 0; j < MAX_PACKETS; j ++ ) { + x->packets[j] = av_packet_alloc(); + } +#endif x->output = yuv_yuv_template( NULL,NULL,NULL, output->width, output->height, alpha_fmt_to_yuv(output->format) ); //av_dict_free(&options); @@ -359,14 +442,26 @@ double avhelper_get_spvf( void *decoder ) { int avhelper_recv_frame_packet( void *decoder ) { el_decoder_t *x = (el_decoder_t*) decoder; - +#if LIBAVCODEC_VERSION_MAJOR < 60 veejay_memset( &(x->packets[x->write_index]), 0 , sizeof(AVPacket)); +#else +#endif + +#if LIBAVCODEC_VERSION_MAJOR < 60 int ret = av_read_frame(x->avformat_ctx, &(x->packets[x->write_index]) ); +#else + int ret = av_read_frame(x->avformat_ctx, x->packets[x->write_index] ); +#endif if( ret == OK ) { +#if LIBAVCODEC_VERSION_MAJOR < 60 if( x->packets[ x->write_index ].stream_index != x->video_stream_id ) { - av_free_packet( &(x->packets[x->write_index]) ); + avhelper_free_packet( &(x->packets[x->write_index]) ); +#else + if( x->packets[ x->write_index ]->stream_index != x->video_stream_id ) { + avhelper_free_packet( x->packets[x->write_index] ); +#endif return 2; // discarded } @@ -377,12 +472,15 @@ int avhelper_recv_frame_packet( void *decoder ) return -1; // error } -int avhelper_decode_video_buffer( void *ptr, uint8_t *data, int len ) +int avhelper_decode_video_buffer( void *ptr, uint8_t *data, int len ) //FIXME callers { int got_picture = 0; el_decoder_t * e = (el_decoder_t*) ptr; - +#if LIBAVCODEC_VERSION_MAJOR < 60 avcodec_decode_video( e->codec_ctx, e->frames[e->frame_index], &got_picture, data, len ); +#else + avcodec_decode_video( e->packets[e->frame_index], e->codec_ctx, e->frames[e->frame_index], &got_picture, data, len ); +#endif //avhelper_frame_unref(e->frames[e->frame_index]); @@ -405,16 +503,25 @@ int avhelper_recv_decode( void *decoder, int *got_picture ) while(1) { // only decode video +#if LIBAVCODEC_VERSION_MAJOR < 60 if( x->packets[ x->read_index ].stream_index != x->video_stream_id ) break; - - // poor man 'double buffering'; when the decode is successful, decode next frame into its own buffer and increment frame_index. + // poor man 'double buffering'; when the decode is successful, decode next frame into its own buffer and increment frame_index. // this function, is the only function, that may manipulate frame_index, as it is used together with avhelper_get_decoded_video // other functions in this source file, assume an index of 0 result = avcodec_decode_video( x->codec_ctx, x->frames[x->frame_index], &gp, x->packets[ x->read_index ].data, x->packets[ x->read_index ].size ); //avhelper_frame_unref(x->frames[x->frame_index]); - - av_free_packet( &(x->packets[x->write_index]) ); + avhelper_free_packet( &(x->packets[x->write_index]) ); +#else + if( x->packets[ x->read_index ]->stream_index != x->video_stream_id ) + break; + // poor man 'double buffering'; when the decode is successful, decode next frame into its own buffer and increment frame_index. + // this function, is the only function, that may manipulate frame_index, as it is used together with avhelper_get_decoded_video + // other functions in this source file, assume an index of 0 + result = avcodec_decode_video( x->packets[x->read_index], x->codec_ctx, x->frames[x->frame_index], &gp, x->packets[ x->read_index ]->data, x->packets[ x->read_index ]->size ); + //avhelper_frame_unref(x->frames[x->frame_index]); + avhelper_free_packet( x->packets[x->write_index]); +#endif x->read_index = (x->read_index + 1) % MAX_PACKETS; @@ -423,7 +530,7 @@ int avhelper_recv_decode( void *decoder, int *got_picture ) } *got_picture = gp; - if(gp) { + if(gp) { //FIXME callers and finish decode to increment frame x->frameinfo[x->frame_index] = 1; /* we have a full picture at this index */ x->frame_index = (x->frame_index + 1) % 2; /* use next available buffer */ x->frameinfo[x->frame_index] = 0; @@ -432,44 +539,15 @@ int avhelper_recv_decode( void *decoder, int *got_picture ) return result; } - -int avhelper_get_frame( void *decoder, int *got_picture ) -{ - el_decoder_t *x = (el_decoder_t*) decoder; - - veejay_memset( &(x->packets[0]), 0, sizeof(AVPacket)); - - int gp = 0; - int result = 0; - while(1) { - int ret = av_read_frame(x->avformat_ctx, &(x->packets[0])); - if( ret < 0 ) - break; - - if ( x->packets[0].stream_index == x->video_stream_id ) { - result = avcodec_decode_video( x->codec_ctx,x->frames[x->frame_index],&gp, x->packets[0].data, x->packets[0].size ); - avhelper_frame_unref(x->frames[x->frame_index]); - } - - av_free_packet( &(x->packets[0]) ); - - if( gp ) - break; - } - - *got_picture = gp; - - return result; -} - static inline void *avhelper_get_decoder_intra( const char *filename, int dst_pixfmt, int dst_width, int dst_height, int force_intra_frame_only ) { char errbuf[512]; el_decoder_t *x = (el_decoder_t*) vj_calloc( sizeof( el_decoder_t )); + int ret; if(!x) { return NULL; } -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 int err = avformat_open_input( &(x->avformat_ctx), filename, NULL, NULL ); #else int err = av_open_input_file( &(x->avformat_ctx),filename,NULL,0,NULL ); @@ -477,20 +555,19 @@ static inline void *avhelper_get_decoder_intra( const char *filename, int dst_pi if(err < 0 ) { av_strerror( err, errbuf, sizeof(errbuf)); - veejay_msg(VEEJAY_MSG_DEBUG, "Error opening %s: %s", filename,errbuf ); + veejay_msg(VEEJAY_MSG_ERROR, "Error opening %s: %s", filename,errbuf ); free(x); return NULL; } -#if LIBAVCODEC_BUILD > 5400 - /* avformat_find_stream_info leaks memory */ +#if LIBAVCODEC_VERSION_MAJOR > 54 err = avformat_find_stream_info( x->avformat_ctx, NULL ); #else err = av_find_stream_info( x->avformat_ctx ); #endif if( err < 0 ) { av_strerror( err, errbuf, sizeof(errbuf)); - veejay_msg(VEEJAY_MSG_DEBUG, "%s: %s" ,filename,errbuf ); + veejay_msg(VEEJAY_MSG_ERROR, "Error getting stream info from %s: %s" ,filename,errbuf ); } if(err < 0 ) { @@ -498,11 +575,12 @@ static inline void *avhelper_get_decoder_intra( const char *filename, int dst_pi free(x); return NULL; } - + +#if LIBAVCODEC_VERSION_MAJOR < 60 unsigned int i,j; unsigned int n = x->avformat_ctx->nb_streams; - x->video_stream_id = -1; + x->video_stream_id = -1; for( i = 0; i < n; i ++ ) { @@ -521,10 +599,13 @@ static inline void *avhelper_get_decoder_intra( const char *filename, int dst_pi sup_codec = 1; goto further; } + veejay_msg(VEEJAY_MSG_DEBUG, "%s = %d", _supported_codecs[j].name, sup_codec); } } further: if( !sup_codec ) { + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: Not a supported codec %d", + x->avformat_ctx->streams[i]->codec->codec_id); avhelper_close_input_file( x->avformat_ctx ); free(x); return NULL; @@ -533,6 +614,7 @@ further: x->codec = avcodec_find_decoder( x->avformat_ctx->streams[i]->codec->codec_id ); if(x->codec == NULL ) { + veejay_msg(VEEJAY_MSG_ERROR,"FFmpeg: Unable to find decoder" ); avhelper_close_input_file( x->avformat_ctx ); free(x); return NULL; @@ -546,68 +628,197 @@ further: } if( x->video_stream_id == -1 ) { - veejay_msg(VEEJAY_MSG_DEBUG, "FFmpeg: No video streams found"); + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: No video streams found"); avhelper_close_input_file( x->avformat_ctx ); free(x); return NULL; } x->codec_ctx = x->avformat_ctx->streams[x->video_stream_id]->codec; +#else + int stream_index; + AVStream *st; int j; + + ret = av_find_best_stream(x->avformat_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); + if (ret < 0) { + veejay_msg(VEEJAY_MSG_ERROR, "Could not find %s stream in input file '%s'\n", + av_get_media_type_string(AVMEDIA_TYPE_VIDEO), filename); + avhelper_close_input_file( x->avformat_ctx ); + free(x); + return NULL; + } else { + stream_index = ret; + st = x->avformat_ctx->streams[stream_index]; + + int sup_codec = !force_intra_frame_only; + if( force_intra_frame_only ) { + for( j = 0; _supported_codecs[j].name != NULL; j ++ ) { + if( st->codecpar->codec_id == _supported_codecs[j].id ) { + sup_codec = 1; + break; + } + } + + if( !sup_codec ) { + if(st->codecpar->codec_id == 0) + veejay_msg(VEEJAY_MSG_DEBUG, "Continue, file is not recognized by ffmpeg (codec not found)"); + veejay_msg(VEEJAY_MSG_DEBUG, "The codec %d is not supportedr ", st->codecpar->codec_id); + avhelper_close_input_file( x->avformat_ctx ); + free(x); + return NULL; + } + } + + /* find decoder for the stream */ + x->codec = avcodec_find_decoder(st->codecpar->codec_id); + if (!x->codec) { + veejay_msg(VEEJAY_MSG_ERROR, "Failed to find %s codec\n", + av_get_media_type_string(AVMEDIA_TYPE_VIDEO)); + avhelper_close_input_file( x->avformat_ctx ); + free(x); + return NULL; + } + + x->video_stream_id = stream_index; + } +#endif int wid = dst_width; int hei = dst_height; +#if LIBAVCODEC_VERSION_MAJOR < 60 if( wid == -1 && hei == -1 ) { wid = x->codec_ctx->width; hei = x->codec_ctx->height; } - -#if LIBAVCODEC_BUILD > 5400 - - int n_threads = avhelper_set_num_decoders(); - - if( n_threads > 0 ) { - x->codec_ctx->thread_count = n_threads; - x->codec_ctx->thread_type = FF_THREAD_FRAME; - } - - //AVDictionary *options = NULL; - //av_dict_set(&options, "hwaccel", "auto", 0); - - if ( avcodec_open2( x->codec_ctx, x->codec, NULL ) < 0 ) #else - if ( avcodec_open( x->codec_ctx, x->codec ) < 0 ) -#endif - { + AVCodecContext *dec_ctx = avcodec_alloc_context3(x->codec); + if(!dec_ctx) { + veejay_msg(VEEJAY_MSG_ERROR, "Failed to allocate the codec context"); + avhelper_codec_close(dec_ctx); avhelper_close_input_file( x->avformat_ctx ); free(x); - //av_dict_free(&options); return NULL; } + /* Copy codec parameters from input stream to output codec context */ + if ((ret = avcodec_parameters_to_context(dec_ctx, st->codecpar)) < 0) { + veejay_msg(VEEJAY_MSG_ERROR, "Failed to copy %s codec parameters to decoder context"); + avhelper_codec_close(dec_ctx); + avhelper_close_input_file( x->avformat_ctx ); + free(x); + return NULL; + } + if( wid == -1 && hei == -1 ) { + wid = dec_ctx->width; + hei = dec_ctx->height; + } +#endif + +#if LIBAVCODECBUILD > 5400 + int n_threads = avhelper_set_num_decoders(); + + if (x->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) { + x->codec_ctx->thread_type = FF_THREAD_FRAME; + x->codec_ctx->thread_count = n_threads; + } + else if (x->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) { + x->codec_ctx->thread_type = FF_THREAD_SLICE; + x->codec_ctx->thread_count = n_threads; + } + +#endif + +#if LIBAVCODEC_VERSION_MAJOR >= 60 + /* Init the decoders */ + if ((ret = avcodec_open2(dec_ctx, x->codec, NULL)) < 0) +#endif +#if LIBAVCODEC_VERSION_MAJOR > 54 && LIBAVCODEC_VERSION_MAJOR < 60 + if ((ret = avcodec_open2( x->codec_ctx, x->codec, NULL )) < 0 ) +#endif +#if LIBAVCODEC_VERSION_MAJOR < 54 + if ((ret = avcodec_open( x->codec_ctx, x->codec )) < 0 ) +#endif + { + veejay_msg(VEEJAY_MSG_ERROR, " FFmpeg: Unable to open codec"); + avhelper_close_input_file( x->avformat_ctx ); + free(x); + return NULL; + } + +#if LIBAVCODEC_VERSION_MAJOR >= 60 + x->codec_ctx = dec_ctx; + for(j = 0; j < MAX_PACKETS; j ++ ) { + x->packets[j] = av_packet_alloc(); + } + +#endif + + int got_picture = 0; + +#if LIBAVCODEC_VERSION_MAJOR < 60 veejay_memset( &(x->packets[0]), 0, sizeof(AVPacket)); AVFrame *f = avhelper_alloc_frame(); x->output = yuv_yuv_template( NULL,NULL,NULL, wid, hei, dst_pixfmt ); x->spvf = ( (double) x->codec_ctx->framerate.den ) / ( (double) x->codec_ctx->framerate.num); - - int got_picture = 0; + while(1) { - int ret = av_read_frame(x->avformat_ctx, &(x->packets[0])); - if( ret < 0 ) + int ret = av_read_frame(x->avformat_ctx, &(x->packets[0])); + if( ret < 0 ) { + av_strerror( err, errbuf, sizeof(errbuf)); + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: read error: %s", errbuf); break; + } if ( x->packets[0].stream_index == x->video_stream_id ) { - avcodec_decode_video( x->codec_ctx,f,&got_picture, x->packets[0].data, x->packets[0].size ); + ret = avcodec_decode_video( x->codec_ctx,f,&got_picture, x->packets[0].data, x->packets[0].size ); + avhelper_frame_unref( f ); + if( ret < 0 ) { + av_strerror( err, errbuf, sizeof(errbuf)); + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: decode error: %s", errbuf); + } } - av_free_packet( &(x->packets[0]) ); + avhelper_free_packet( &(x->packets[0]) ); if( got_picture ) break; } av_free(f); - //av_dict_free(&options); +#else + AVFrame *f = avhelper_alloc_frame(); + x->output = yuv_yuv_template( NULL,NULL,NULL, wid, hei, dst_pixfmt ); + x->spvf = ( (double) x->codec_ctx->framerate.den ) / ( (double) x->codec_ctx->framerate.num); + + while(1) { + int ret = av_read_frame(x->avformat_ctx, x->packets[0]); + if( ret < 0 ) { + av_strerror( err, errbuf, sizeof(errbuf)); + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: read error: %s", errbuf); + break; + } + + if ( x->packets[0]->stream_index == x->video_stream_id ) { + ret = avcodec_decode_video( x->packets[0], x->codec_ctx,f,&got_picture, x->packets[0]->data, x->packets[0]->size ); + + avhelper_frame_unref( f ); + if( ret < 0 ) { + av_strerror( err, errbuf, sizeof(errbuf)); + veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: decode error: %s", errbuf); + } + } + + avhelper_free_packet( x->packets[0] ); + + if( got_picture ) + break; + } + av_packet_free( &(x->packets[0])); + av_free(f); +#endif + + if(!got_picture) { veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: Unable to get whole picture from %s", filename ); @@ -624,7 +835,7 @@ further: x->frames[1] = avhelper_alloc_frame(); x->input = yuv_yuv_template( NULL,NULL,NULL, x->codec_ctx->width,x->codec_ctx->height, x->pixfmt ); - //avhelper_hwaccel(x->codec_ctx); + return (void*) x; } @@ -645,11 +856,17 @@ void *avhelper_alloc_frame() void avhelper_close_decoder( void *ptr ) { el_decoder_t *e = (el_decoder_t*) ptr; - avcodec_close( e->codec_ctx ); + avhelper_codec_close( e->codec_ctx ); +#if LIBAVCODEC_VERSION_MAJOR < 60 for( int i = 0; i < MAX_PACKETS ; i ++ ) { - av_free_packet( &(e->packets[i]) ); + avhelper_free_packet( &(e->packets[i]) ); } +#else + for( int i = 0; i < MAX_PACKETS ; i ++ ) { + av_packet_free( &(e->packets[i]) ); + } +#endif if(e->avformat_ctx) { avhelper_close_input_file( e->avformat_ctx ); @@ -663,14 +880,23 @@ void avhelper_close_decoder( void *ptr ) if(e->frames[1]->data[0]) avhelper_frame_unref(e->frames[1]); + if(e->input) free(e->input); if(e->output) free(e->output); +#if LIBAVCODEC_VERSION_MAJOR >= 60 + av_frame_free( &(e->frames[0]) ); + av_frame_free( &(e->frames[1]) ); + + av_frame_free( &(e->frame) ); + av_packet_free( &(e->packet)); +#else if(e->frames[0]) av_free(e->frames[0]); if(e->frames[1]) av_free(e->frames[1]); +#endif free(e); } @@ -686,19 +912,63 @@ VJFrame *avhelper_get_output_frame( void *ptr) return e->output; } -int avhelper_decode_video( void *ptr, uint8_t *data, int len ) +int avhelper_decode_video_direct( void *ptr, uint8_t *data, int len, uint8_t *dst[4], int pf, int w, int h ) { + el_decoder_t *e = (el_decoder_t*) ptr; +#if LIBAVCODEC_VERSION_MAJOR >= 60 + if(e->packets[0] == NULL) { + for( int i = 0; i < MAX_PACKETS; i ++ ) { + e->packets[i] = av_packet_alloc(); + } + } +#endif + + int ret = avhelper_decode_video(ptr, data, len ); + if( ret < 0 ) { + return ret; + } + return avhelper_rescale_video(ptr, dst ); +} + +void avhelper_decode_finish( void *ptr ) +{ + el_decoder_t * e = (el_decoder_t*) ptr; + + +#if LIBAVCODEC_VERSION_MAJOR >= 60 + av_frame_unref( e->frames[e->frame_index] ); +#endif + + e->frameinfo[e->frame_index] = 1; + e->frame_index = (e->frame_index +1) %2; + e->frameinfo[e->frame_index] = 0; + +} + +int avhelper_decode_video( void *ptr, uint8_t *data, int len ) //FIXME: decoding with ffmpeg 4 crashes because of bad packet / frame (data) handling { int got_picture = 0; el_decoder_t * e = (el_decoder_t*) ptr; - +#if LIBAVCODEC_VERSION_MAJOR < 60 int result = avcodec_decode_video( e->codec_ctx, e->frames[e->frame_index], &got_picture, data, len ); - - if(!got_picture || result <= 0) { - e->frameinfo[e->frame_index] = 1; - e->frame_index = (e->frame_index +1) %2; - e->frameinfo[e->frame_index] = 0; +#else + int result = avcodec_decode_video( e->packets[0], e->codec_ctx, e->frames[e->frame_index], &got_picture, data, len ); +#endif + + if(!got_picture || result < 0) { +//#if LIBAVCODEC_BUILD >= 6000 +// av_frame_unref( e->frames[e->frame_index] ); +//#endif return 0; } + +/* + e->frameinfo[e->frame_index] = 1; + e->frame_index = (e->frame_index +1) %2; + e->frameinfo[e->frame_index] = 0; +*/ +//#if LIBAVCODEC_BUILD >= 6000 +// av_frame_unref( e->frames[e->frame_index] ); +//#endif return 1; } @@ -726,7 +996,7 @@ VJFrame *avhelper_get_decoded_video(void *ptr) { return e->input; } -void avhelper_rescale_video(void *ptr, uint8_t *dst[3]) +int avhelper_rescale_video(void *ptr, uint8_t *dst[4]) { el_decoder_t * e = (el_decoder_t*) ptr; @@ -745,7 +1015,7 @@ void avhelper_rescale_video(void *ptr, uint8_t *dst[3]) e->input->width,e->input->height,e->input->format,e->input->data[0],e->input->data[1],e->input->data[2], e->output->width,e->output->height,e->output->format,e->output->data[0],e->output->data[1],e->output->data[2]); - return; + return 0; } } @@ -759,4 +1029,6 @@ void avhelper_rescale_video(void *ptr, uint8_t *dst[3]) e->output->data[2] = dst[2]; yuv_convert_any3( e->scaler, e->input, e->frames[e->frame_index]->linesize, e->output); + + return 1; } diff --git a/veejay-current/veejay-server/libel/lav_io.c b/veejay-current/veejay-server/libel/lav_io.c index b2704fcf..b3ae0fd7 100644 --- a/veejay-current/veejay-server/libel/lav_io.c +++ b/veejay-current/veejay-server/libel/lav_io.c @@ -175,29 +175,8 @@ int lav_query_APP_length(char format) int lav_query_polarity(char format) { - /* Quicktime needs TOP_FIRST, for AVI we have the choice */ - switch(format) { - /* case 'b': // todo: must implement polarity for DV? - return LAV_NOT_INTERLACED; - - case 'a': return LAV_INTER_TOP_FIRST; - case 'A': return LAV_INTER_BOTTOM_FIRST; - case 'D': return LAV_NOT_INTERLACED; //divx - case 'Y': return LAV_NOT_INTERLACED; // planar yuv 4:2:0 (yv12) - case 'P': return LAV_NOT_INTERLACED; // planar yuv 4:2:2 (yv16) - case 'V': return LAV_NOT_INTERLACED; // planar yuv 4:2:0 (yv12) - case 'v': return LAV_NOT_INTERLACED; // planar yuv 4:2:2 (yv16) - - case 'M': return LAV_NOT_INTERLACED; // mpeg4 , - case 'd': return LAV_INTER_BOTTOM_FIRST; // DV, interlaced - case 'j': return LAV_INTER_TOP_FIRST; - case 'q': return LAV_INTER_TOP_FIRST; - case 'L': return LAV_NOT_INTERLACED; - case 'l': return LAV_NOT_INTERLACED; - case 'm': return LAV_INTER_TOP_FIRST; - case 'x': return LAV_NOT_INTERLACED; // picture is always not interlaced*/ default: return LAV_NOT_INTERLACED; } } @@ -226,7 +205,6 @@ lav_file_t *lav_open_output_file(char *filename, char format, lav_fd->interlacing = interlaced ? lav_query_polarity(format):LAV_NOT_INTERLACED; lav_fd->has_audio = (asize>0 && achans>0); lav_fd->bps = (asize*achans+7)/8; - lav_fd->is_MJPG = 1; lav_fd->MJPG_chroma = _lav_io_default_chroma; char fourcc[16]; @@ -241,6 +219,10 @@ lav_file_t *lav_open_output_file(char *filename, char format, veejay_msg(VEEJAY_MSG_DEBUG, "\tWriting output file in AVI MJPEG"); sprintf(fourcc, "MJPG" ); break; + case 'H': + veejay_msg(VEEJAY_MSG_DEBUG,"\tWriting output file in AVI HFYU"); + sprintf(fourcc, "HFYU"); + break; case 'c': veejay_msg(VEEJAY_MSG_DEBUG, "\tWriting output file in AVI MJPEG-b"); sprintf(fourcc, "MJPB" ); @@ -373,7 +355,9 @@ int lav_close(lav_file_t *lav_file) break; #endif case 'x': +#ifdef USE_GDK_PIXBUF vj_picture_cleanup( lav_file->picture ); +#endif ret = 1; break; #ifdef HAVE_LIBQUICKTIME @@ -414,6 +398,7 @@ long lav_bytes_remain( lav_file_t *lav_file ) case 'L': case 'l': case 'd': + case 'H': return AVI_bytes_remain( lav_file->avi_fd ); default: return -1; @@ -451,6 +436,7 @@ int lav_write_frame(lav_file_t *lav_file, uint8_t *buff, long size, long count) case 'L': case 'l': case 'd': + case 'H': if(n==0) { res = AVI_write_frame( lav_file->avi_fd, buff, size ); } @@ -660,11 +646,6 @@ void lav_video_clipaspect(lav_file_t *lav_file, int *sar_w, int *sar_h) return; } -int lav_video_is_MJPG(lav_file_t *lav_file) -{ - return lav_file->is_MJPG; -} - int lav_video_MJPG_chroma(lav_file_t *lav_file) { return lav_file->MJPG_chroma; @@ -678,6 +659,7 @@ int lav_video_compressor_type(lav_file_t *lav_file) #define FOURCC_DV "dvsd" #define FOURCC_PIC "pict" #define FOURCC_LZO "mlzo" +#define FOURCC_HUFFYUV "hfyu" const char *lav_video_compressor(lav_file_t *lav_file) { @@ -702,6 +684,7 @@ const char *lav_video_compressor(lav_file_t *lav_file) if(lav_file->format == 'q' || lav_file->format == 'Q') return quicktime_video_compressor(lav_file->qt_fd,0); #endif + return AVI_video_compressor(lav_file->avi_fd); } @@ -853,13 +836,14 @@ int lav_read_frame(lav_file_t *lav_file, uint8_t *vidbuf) #endif int kf = 1; int ret = (AVI_read_frame(lav_file->avi_fd,vidbuf,&kf)); -/* + +#ifdef STRICT_CHECKING if(!kf) { -// veejay_msg(0, "Requested frame is not a keyframe"); + veejay_msg(VEEJAY_MSG_DEBUG, "Requested frame is not a keyframe"); return ret; } -*/ +#endif return ret; } @@ -1009,7 +993,6 @@ lav_file_t *lav_open_input_file(char *filename, long mmap_size) lav_fd->sar_h = 0; lav_fd->has_audio = 0; lav_fd->bps = 0; - lav_fd->is_MJPG = 0; lav_fd->MJPG_chroma = CHROMAUNKNOWN; lav_fd->mmap_size = mmap_size; @@ -1255,8 +1238,7 @@ lav_file_t *lav_open_input_file(char *filename, long mmap_size) } if (strncasecmp(video_comp,"yv16",4)==0 || - strncasecmp(video_comp,"i422",4)==0 || - strncasecmp(video_comp,"hfyu",4)==0) + strncasecmp(video_comp,"i422",4)==0) { lav_fd->MJPG_chroma = CHROMA422; lav_fd->format = 'P'; @@ -1264,6 +1246,14 @@ lav_file_t *lav_open_input_file(char *filename, long mmap_size) return lav_fd; } + if (strncasecmp(video_comp,"hfyu",4)==0) + { + lav_fd->MJPG_chroma = CHROMA422; + lav_fd->format = 'H'; + lav_fd->interlacing = LAV_NOT_INTERLACED; + return lav_fd; + } + if( strncasecmp( video_comp, "mlzo", 4 ) == 0 ) { lav_fd->MJPG_chroma = CHROMA422; @@ -1318,7 +1308,6 @@ lav_file_t *lav_open_input_file(char *filename, long mmap_size) { lav_fd->MJPG_chroma = CHROMA420; lav_fd->interlacing = LAV_INTER_UNKNOWN; - lav_fd->is_MJPG = 1; if ( lav_set_video_position(lav_fd,0) < 0 ) goto ERREXIT; lav_fd->MJPG_chroma = CHROMAUNKNOWN; lav_fd->interlacing = LAV_INTER_UNKNOWN; @@ -1326,7 +1315,7 @@ lav_file_t *lav_open_input_file(char *filename, long mmap_size) } ierr = ERROR_FORMAT; - veejay_msg(VEEJAY_MSG_ERROR, "Unrecognized format '%s'", video_comp); + veejay_msg(VEEJAY_MSG_ERROR, "Unrecognized format '%s' in %s", video_comp, filename); ERREXIT: lav_close(lav_fd); @@ -1371,6 +1360,7 @@ const char *lav_strerror(void) case 'P': case 'L': case 'D': + case 'H': return AVI_strerror(); default: /* No or unknown video format */ diff --git a/veejay-current/veejay-server/libel/lav_io.h b/veejay-current/veejay-server/libel/lav_io.h index 3881969f..6bdcedae 100644 --- a/veejay-current/veejay-server/libel/lav_io.h +++ b/veejay-current/veejay-server/libel/lav_io.h @@ -70,7 +70,6 @@ typedef struct int sar_h; /* "clip aspect ratio" height */ int has_audio; int bps; - int is_MJPG; int MJPG_chroma; long mmap_size; int bogus_len; @@ -94,7 +93,6 @@ int lav_video_height(lav_file_t *lav_file); double lav_frame_rate(lav_file_t *lav_file); int lav_video_interlacing(lav_file_t *lav_file); void lav_video_clipaspect(lav_file_t *lav_file, int *sar_w, int *sar_h); -int lav_video_is_MJPG(lav_file_t *lav_file); int lav_is_DV(lav_file_t *lav_file); int lav_video_MJPG_chroma(lav_file_t *lav_file); const char *lav_video_compressor(lav_file_t *lav_file); diff --git a/veejay-current/veejay-server/libel/vj-avcodec.c b/veejay-current/veejay-server/libel/vj-avcodec.c index cca34a57..ca420eca 100644 --- a/veejay-current/veejay-server/libel/vj-avcodec.c +++ b/veejay-current/veejay-server/libel/vj-avcodec.c @@ -18,6 +18,7 @@ */ #include #include +#include #include #include #include @@ -36,9 +37,12 @@ #include #include #include -#include +#include #include #include +#ifdef STRICT_CHECKING +#include +#endif //from gst-ffmpeg, round up a number #define GEN_MASK(x) ((1<<(x))-1) @@ -51,6 +55,7 @@ static int out_pixel_format = FMT_422F; + static char* vj_avcodec_get_codec_name(int codec_id ) { char name[64]; @@ -98,12 +103,95 @@ uint8_t *vj_avcodec_get_buf( vj_encoder *av ) return av->data[0]; } +int vj_avcodec_get_buf_size( vj_encoder *av ) +{ + return av->out_frame->len + av->out_frame->uv_len + av->out_frame->uv_len; +} + static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filename) { vj_encoder *e = (vj_encoder*) vj_calloc(sizeof(vj_encoder)); + char errbuf[512]; + if(!e) return NULL; - int pf = get_ffmpeg_pixfmt( out_pixel_format ); + int selected_out_pixfmt = out_pixel_format; + int chroma_val = -1; + + switch( id ) { + case 997: + selected_out_pixfmt = FMT_422F; + break; + case 996: + selected_out_pixfmt = FMT_420F; + break; + case 995: + selected_out_pixfmt = FMT_422; + chroma_val = Y4M_CHROMA_422; + break; + case 994: + selected_out_pixfmt = FMT_420; + chroma_val = (out_pixel_format == FMT_422F || out_pixel_format == FMT_420F ? Y4M_CHROMA_420JPEG : Y4M_CHROMA_420MPEG2); + break; + case 999: + selected_out_pixfmt = FMT_420; + break; + case 998: + selected_out_pixfmt = FMT_422; + break; + case CODEC_ID_HUFFYUV: + selected_out_pixfmt = FMT_422; + break; + default: + break; + } + + int pf = get_ffmpeg_pixfmt( selected_out_pixfmt ); + + e->out_frame = yuv_yuv_template( NULL,NULL,NULL, frame->width, frame->height, pf ); + e->in_frame = (VJFrame*) vj_malloc(sizeof(VJFrame)); + veejay_memcpy( e->in_frame, frame, sizeof(VJFrame)); + + e->data[0] = (uint8_t*) vj_malloc(RUP8(e->out_frame->len * 4)); + e->data[1] = e->data[0] + e->out_frame->len; + e->data[2] = e->data[1] + e->out_frame->len; + e->data[3] = NULL; + + e->out_frame->data[0] = e->data[0]; + e->out_frame->data[1] = e->data[1]; + e->out_frame->data[2] = e->data[2]; + + e->in_frame->data[0] = NULL; + e->in_frame->data[1] = NULL; + e->in_frame->data[2] = NULL; + e->in_frame->data[3] = NULL; + + veejay_memset( e->data[0], 0, e->out_frame->len); + veejay_memset( e->data[1], 128, e->out_frame->uv_len); + veejay_memset( e->data[2], 128, e->out_frame->uv_len ); + + + // strip any A* + e->in_frame->format = vj_to_pixfmt( out_pixel_format ); + e->in_frame->stride[3] = 0; + + veejay_msg(VEEJAY_MSG_DEBUG, "Selected output pixel format: %s (internal out fmt %d, chroma %d). Source is %s", yuv_get_pixfmt_description(pf), selected_out_pixfmt, chroma_val, + yuv_get_pixfmt_description(e->in_frame->format)); + + + if( id > 900 ) { + sws_template tmpl; + tmpl.flags = 1; + e->scaler = yuv_init_swscaler( e->in_frame,e->out_frame, &tmpl, yuv_sws_get_cpu_flags()); + if(e->scaler == NULL) { + veejay_msg(VEEJAY_MSG_ERROR, "Failed to initialize scaler context"); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + free(e); + return NULL; + } + } #ifdef SUPPORT_READ_DV2 if( id == CODEC_ID_DVVIDEO ) @@ -111,6 +199,10 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam if(!is_dv_resolution(frame->width, frame->height )) { veejay_msg(VEEJAY_MSG_ERROR,"\tSource video is not in DV resolution"); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + free(e); return NULL; } else @@ -120,35 +212,40 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam } else { #endif - e->data[0] = (uint8_t*) vj_calloc(sizeof(uint8_t) * RUP8(frame->len + frame->uv_len + frame->uv_len) ); - e->data[1] = e->data[0] + frame->len; - e->data[2] = e->data[1] + frame->uv_len; - e->data[3] = NULL; + #ifdef SUPPORT_READ_DV2 } #endif if( id == 900 ) { - e->lzo = lzo_new(); + e->lzo = lzo_new(frame->format, frame->width, frame->height, 0 ); } if( id == 995 || id == 994) { - e->y4m = vj_yuv4mpeg_alloc(frame->width,frame->height,frame->fps, out_pixel_format ); + e->y4m = vj_yuv4mpeg_alloc(frame->width,frame->height,frame->fps, selected_out_pixfmt ); if( !e->y4m) { veejay_msg(0, "Error while trying to setup Y4M stream, abort"); - return NULL; - } + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + yuv_free_swscaler(e->scaler); - int chroma_val = Y4M_CHROMA_422; - if( id == 994 ) { - chroma_val = Y4M_CHROMA_420MPEG2; + free(e); + + return NULL; } if( vj_yuv_stream_start_write( e->y4m, frame,filename,chroma_val )== -1 ) { veejay_msg(0, "Unable to write header to YUV4MPEG stream"); vj_yuv4mpeg_free( e->y4m ); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + yuv_free_swscaler(e->scaler); + + free(e); return NULL; } } @@ -164,7 +261,11 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam { char *descr = vj_avcodec_get_codec_name(id); veejay_msg(VEEJAY_MSG_ERROR, "Unable to find encoder '%s'", descr ); - free(descr); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + free(e); + return NULL; } #ifdef __FALLBACK_LIBDV } @@ -178,7 +279,7 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam if(id != CODEC_ID_DVVIDEO ) { #endif -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 e->context = avcodec_alloc_context3(e->codec); #else e->context = avcodec_alloc_context(); @@ -186,11 +287,34 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam e->context->bit_rate = 2750 * 1024; e->context->width = frame->width; e->context->height = frame->height; -#if LIBAVCODEC_BUILD > 5010 + +#if LIBAVCODEC_VERSION_MAJOR >= 50 e->context->time_base = (AVRational) { 1, frame->fps }; #else e->context->frame_rate = frame->fps; e->context->frame_rate_base = 1; +#endif +#if LIBAVCODEC_VERSION_MAJOR >= 60 + e->packet = av_packet_alloc(); + e->frame = av_frame_alloc(); + e->frame->format = get_ffmpeg_pixfmt( selected_out_pixfmt ); + e->frame->width = frame->width; + e->frame->height = frame->height; + + int av_ret = av_frame_get_buffer(e->frame, 0); + if( av_ret < 0 ) { + veejay_msg(VEEJAY_MSG_ERROR, "Unable to allocate buffers for encoder"); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + av_packet_free(&(e->packet)); + av_frame_free(&(e->frame)); + free(e); + + return av_ret; + } + + e->context->framerate = (AVRational) { 1, frame->fps }; #endif e->context->sample_aspect_ratio.den = 1; e->context->sample_aspect_ratio.num = 1; @@ -201,35 +325,56 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam e->context->flags = CODEC_FLAG_QSCALE; e->context->gop_size = 0; e->context->workaround_bugs = FF_BUG_AUTODETECT; +#if LIBAVCODEC_VERSION_MAJOR < 60 e->context->prediction_method = 0; +#endif e->context->dct_algo = FF_DCT_AUTO; - e->context->pix_fmt = get_ffmpeg_pixfmt( out_pixel_format ); - pf = e->context->pix_fmt; + e->context->pix_fmt = pf; + //pf = e->context->pix_fmt; char *descr = vj_avcodec_get_codec_name( id ); -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 int n_threads = avhelper_set_num_decoders(); - if( n_threads > 0 ) { - e->context->thread_count = n_threads; + if (e->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) { e->context->thread_type = FF_THREAD_FRAME; + e->context->thread_count = n_threads; + } + else if (e->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) { + e->context->thread_type = FF_THREAD_SLICE; + e->context->thread_count = n_threads; } - if ( avcodec_open2( e->context, e->codec, NULL ) ) + int ret = avcodec_open2( e->context, e->codec, NULL ); #else - if ( avcodec_open( e->context, e->codec ) < 0 ) + int ( avcodec_open( e->context, e->codec ) < 0 ); #endif - { - veejay_msg(VEEJAY_MSG_ERROR, "Unable to open codec '%s'" , descr ); + if( ret < 0 ) { + av_strerror( ret, errbuf, sizeof(errbuf)); + veejay_msg(VEEJAY_MSG_ERROR, "Unable to open codec '%s': %s" , descr, errbuf ); avhelper_free_context( &(e->context) ); - if(e) free(e); + free(e->out_frame); + free(e->in_frame); + free(e->data[0]); + free(e); if(descr) free(descr); return NULL; } else { - veejay_msg(VEEJAY_MSG_DEBUG, "\tOpened codec %s", descr ); + veejay_msg(VEEJAY_MSG_DEBUG, "\tOpened codec %s [in pixfmt=%d]", descr, e->context->pix_fmt ); + if(e->context->color_range == AVCOL_RANGE_JPEG ) { + veejay_msg(VEEJAY_MSG_INFO, "color range is jpeg"); + } + if(e->context->color_range == AVCOL_RANGE_UNSPECIFIED) { + veejay_msg(VEEJAY_MSG_WARNING, "Color range not specified" ); + } + + if(e->context->color_range == AVCOL_RANGE_MPEG ) { + veejay_msg(VEEJAY_MSG_INFO, "color range is mpeg"); + } + free(descr); } #ifdef __FALLBACK_LIBDV @@ -237,15 +382,14 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam #endif } - e->width = frame->width; - e->height = frame->height; + e->width = e->out_frame->width; + e->height = e->out_frame->height; e->encoder_id = id; - e->shift_y = frame->shift_v; - e->shift_x = frame->shift_h; - e->len = frame->len; - e->uv_len = frame->uv_len; - e->out_fmt = pixfmt_to_vj( pf ); - e->format = pf; + e->shift_y = e->out_frame->shift_v; + e->shift_x = e->out_frame->shift_h; + e->len = e->out_frame->len; + e->uv_len = e->out_frame->uv_len; + return e; } void vj_avcodec_close_encoder( vj_encoder *av ) @@ -265,8 +409,16 @@ void vj_avcodec_close_encoder( vj_encoder *av ) if(av->dv) vj_dv_free_encoder( (vj_dv_encoder*) av->dv ); #endif + if(av->scaler) + yuv_free_swscaler(av->scaler); + + if(av->out_frame) + free(av->out_frame); + if(av->in_frame) + free(av->in_frame); if(av->y4m) vj_yuv4mpeg_free( (vj_yuv*) av->y4m ); + free(av); } av = NULL; @@ -314,8 +466,9 @@ char vj_avcodec_find_lav( int encoder ) switch( encoder) { case ENCODER_MJPEG: - case ENCODER_HUFFYUV: return 'a'; + case ENCODER_HUFFYUV: + return 'H'; case ENCODER_QUICKTIME_MJPEG: return 'q'; case ENCODER_DVVIDEO: @@ -391,7 +544,17 @@ int vj_avcodec_stop( void *encoder , int fmt) return 1; } +#if LIBAVCODEC_MAJOR >= 60 + +#endif + vj_avcodec_close_encoder( env ); + +#if LIBAVCODEC_MAJOR >= 60 + av_packet_free( &(env->packet) ); + av_frame_free( &(env->frame) ); +#endif + encoder = NULL; return 1; } @@ -420,19 +583,26 @@ int vj_avcodec_init( int pixel_format, int verbose) { out_pixel_format = pixel_format; - av_log_set_level( AV_LOG_QUIET); - char *av_log_setting = getenv("VEEJAY_AV_LOG"); if(av_log_setting != NULL) { int level = atoi(av_log_setting); veejay_msg(VEEJAY_MSG_DEBUG, "ffmpeg/libav log level set to %d", level); av_log_set_level(level); } + else { + veejay_msg(VEEJAY_MSG_DEBUG, "ffmpeg/libav log level not set (use VEEJAY_AV_LOG=level)"); + av_log_set_level( AV_LOG_QUIET); + } -#if LIBAVCODEC_BUILD < 5400 + veejay_msg(VEEJAY_MSG_INFO, "ffmpeg/libav library version %d.%d.%d", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO); + +#if LIBAVCODEC_VERSION_MAJOR < 54 avcodec_register_all(); + #else +#if LIBAVCODEC_VERSION_MAJOR < 60 av_register_all(); +#endif #endif return 1; } @@ -442,152 +612,102 @@ int vj_avcodec_free() return 1; } -static void long2str(unsigned char *dst, int32_t n) -{ - dst[0] = (n )&0xff; - dst[1] = (n>> 8)&0xff; - dst[2] = (n>>16)&0xff; - dst[3] = (n>>24)&0xff; -} - -static int vj_avcodec_lzo( vj_encoder *av, uint8_t *src[3], uint8_t *dst , int buf_len ) -{ - uint8_t *dstI = dst + (3 * 4); - uint32_t s1,s2,s3; - uint32_t *size1 = &s1, *size2=&s2,*size3=&s3; - int32_t res; - int32_t sum = 0; - - res = lzo_compress( av->lzo, src[0], dstI, size1 , av->len); - if( res == 0 ) - { - veejay_msg(0,"\tunable to compress Y plane"); - return 0; - } - - long2str( dst, res ); - sum += res; - - res = lzo_compress( av->lzo, src[1], dstI + sum, size2 , av->uv_len ); - if( res == 0 ) - { - veejay_msg(0,"\tunable to compress U plane"); - return 0; - } - - long2str( dst + 4, res ); - sum += res; - - res = lzo_compress( av->lzo, src[2], dstI + sum, size3 , av->uv_len ); - if( res == 0 ) - { - veejay_msg(0,"\tunable to compress V plane"); - return 0; - } - - sum += res; - long2str( dst + 8, res ); - - return (sum + 12); -} -static int vj_avcodec_copy_frame( vj_encoder *av, uint8_t *src[4], uint8_t *dst, int in_fmt ) +static int vj_avcodec_copy_frame( vj_encoder *av, uint8_t *src[4], uint8_t *dst) { if(!av) { - veejay_msg(VEEJAY_MSG_ERROR, "No encoder !!"); + veejay_msg(VEEJAY_MSG_ERROR, "The encoder is not initialized"); return 0; } - if( av->encoder_id == 999 ) - { - uint8_t *dest[4] = { dst, dst + (av->len), dst + (av->len + av->len/4),NULL }; - vj_frame_copy1(src[0], dest[0], av->len ); - yuv422to420planar( src,dest, av->width,av->height ); + VJFrame *A = av->in_frame; + VJFrame *B = av->out_frame; - if(in_fmt == FMT_422F ) - { - yuv_scale_pixels_from_y( dest[0], av->len ); - yuv_scale_pixels_from_uv( dest[1], av->len/2 ); - } + //setup pointers + A->data[0] = src[0]; + A->data[1] = src[1]; + A->data[2] = src[2]; + A->data[3] = NULL; + + B->data[0] = dst; + B->data[1] = dst + B->len; + B->data[2] = dst + B->len + B->uv_len; + B->data[3] = NULL; - return ( av->len + (av->len/2) ); - } - if( av->encoder_id == 996 ) - { - uint8_t *dest[4] = { dst, dst + (av->len), dst + (av->len + av->len/4),NULL }; - vj_frame_copy1( src[0], dest[0], av->len ); - yuv422to420planar( src,dest, av->width,av->height ); - - if(in_fmt == FMT_422 ) - { - yuv_scale_pixels_from_ycbcr( dest[0], 16.0f,235.0f, av->len ); - yuv_scale_pixels_from_ycbcr( dest[1], 16.0f,240.0f, av->len/2 ); - } - - return ( av->len + (av->len/2) ); - } - - - if( av->encoder_id == 998 ) - { - uint8_t *dest[4] = { dst, dst + (av->len), dst + (av->len + av->uv_len), NULL }; - int strides[4] = { av->len, av->uv_len, av->uv_len, 0 }; - vj_frame_copy( src, dest, strides ); - - if(in_fmt == FMT_422F ) - { - yuv_scale_pixels_from_y( dest[0], av->len ); - yuv_scale_pixels_from_uv( dest[1], av->uv_len * 2 ); - } - - return ( av->len + av->len ); - } - - if( av->encoder_id == 997 ) - { - uint8_t *dest[4] = { dst, dst + (av->len), dst + (av->len + av->uv_len), NULL }; - int strides[4] = { av->len, av->uv_len,av->uv_len, 0 }; - vj_frame_copy( src, dest, strides ); - - if(in_fmt == FMT_422 ) - { - yuv_scale_pixels_from_ycbcr( dest[0], 16.0f,235.0f, av->len ); - yuv_scale_pixels_from_ycbcr( dest[1], 16.0f,240.0f, av->uv_len * 2 ); - } - - return ( av->len + av->len ); - } - - veejay_msg(VEEJAY_MSG_DEBUG, "Unknown encoder select: %d", av->encoder_id); - - return 0; + yuv_convert_and_scale( av->scaler, A, B); + + return (B->len + B->uv_len + B->uv_len); } -static int vj_avcodec_encode_video( AVCodecContext *ctx, uint8_t *buf, int len, AVFrame *frame ) +static int vj_avcodec_encode_video( AVPacket *pkt, AVCodecContext *ctx, uint8_t *buf, int len, AVFrame *frame ) { +#if LIBAVCODEC_VERSION_MAJOR < 60 if( avcodec_encode_video2) { - AVPacket pkt; - veejay_memset(&pkt,0,sizeof(pkt)); + char errbuf[512]; int got_packet_ptr = 0; - pkt.data = buf; - pkt.size = len; + pkt->data = buf; + pkt->size = len; - int res = avcodec_encode_video2( ctx, &pkt, frame, &got_packet_ptr); + int res = avcodec_encode_video2( ctx, pkt, frame, &got_packet_ptr); + if( res < 0) { + av_strerror( res, errbuf, sizeof(errbuf)); + veejay_msg(0, "Unable to encode frame: %s", errbuf); + return -1; + } if( res == 0 ) { - return pkt.size; + veejay_msg(VEEJAY_MSG_DEBUG, "Encoded frame to %d bytes", pkt->size); + return pkt->size; } - if( res == -1) { - veejay_msg(0, "Unable to encode frame"); - } - - return 0; + return -1; } else if( avcodec_encode_video ) { return avcodec_encode_video(ctx,buf,len,frame); } +#else + + int ret = av_frame_make_writable(frame); + if(ret < 0) { + veejay_msg(VEEJAY_MSG_ERROR, "Unable to make buffer writable"); + return -1; + } + + ret = avcodec_send_frame( ctx, frame ); + if( ret < 0 ) { + veejay_msg(0, "Error sending frame to decoder: %s", av_err2str(ret)); + return -1; + } + + pkt->data = buf; + pkt->size = len; + + while (ret >= 0) + { + ret = avcodec_receive_packet(ctx, pkt); + + if (ret == AVERROR(EAGAIN) || ret == 0) { // need new input, we are ready + ret = pkt->size; + break; + } + if (ret < 0) { + break; + } + } + + av_packet_unref(pkt); +/* if( ret > 0 ) { + char name[256]; + sprintf(name, "frame-%d.jpg", ret); + FILE *f = fopen( name, "wb"); + fwrite( buf, ret, 1, f); + fclose(f); + } */ + + return ret; + +#endif return -1; } @@ -598,22 +718,23 @@ int vj_avcodec_encode_frame(void *encoder, long nframe,int format, uint8_t *src vj_encoder *av = (vj_encoder*) encoder; if(format == ENCODER_LZO ) - return vj_avcodec_lzo( encoder, src, buf, buf_len ); - - if(format == ENCODER_YUV420 || format == ENCODER_YUV422 || format == ENCODER_YUV422F || format == ENCODER_YUV420F) // no compression, just copy - return vj_avcodec_copy_frame( encoder,src, buf, in_fmt ); + return lzo_compress_frame( av->lzo, av->in_frame,src, buf ); + + if(format == ENCODER_YUV420 || format == ENCODER_YUV422 || format == ENCODER_YUV422F || format == ENCODER_YUV420F) + return vj_avcodec_copy_frame( encoder,src, buf ); if(format == ENCODER_YUV4MPEG || format == ENCODER_YUV4MPEG420 ) { - if( in_fmt == FMT_422 ) { - vj_yuv_put_frame( av->y4m, src ); - return ( av->width * av->height ) * 2; - } else { - yuv_scale_pixels_from_yuv( src,av->data,av->width*av->height); - vj_yuv_put_frame(av->y4m, av->data ); - return ( av->width * av->height ) * 2; - } + if( in_fmt == FMT_422 ) { + vj_yuv_put_frame( av->y4m, src ); + return ( av->width * av->height ) * 2; + } else { + yuv_scale_pixels_from_yuv( src,av->data,av->len, av->uv_len); + vj_yuv_put_frame(av->y4m, av->data ); + return ( av->width * av->height ) * 2; + } } + #ifdef __FALLBACK_LIBDV if(format == ENCODER_DVVIDEO || format == ENCODER_QUICKTIME_DV ) { @@ -621,6 +742,7 @@ int vj_avcodec_encode_frame(void *encoder, long nframe,int format, uint8_t *src return vj_dv_encode_frame( dv,src ); } #endif +#if LIBAVCODEC_VERSION_MAJOR < 60 AVFrame pict; int stride,w2,stride2; veejay_memset( &pict, 0, sizeof(pict)); @@ -630,15 +752,40 @@ int vj_avcodec_encode_frame(void *encoder, long nframe,int format, uint8_t *src pict.data[0] = src[0]; pict.data[1] = src[1]; pict.data[2] = src[2]; - pict.format = av->format; - stride = ROUND_UP_4( av->width ); - w2 = DIV_ROUND_UP_X(av->width, av->shift_x); - stride2 = ROUND_UP_4( w2 ); - pict.linesize[0] = stride; - pict.linesize[1] = stride2; - pict.linesize[2] = stride2; - pict.width = av->width; - pict.height = av->height; - return vj_avcodec_encode_video( av->context, buf, buf_len, &pict ); + pict.format = av->out_frame->format; + + pict.linesize[0] = ROUND_UP_4( av->out_frame->width ); + pict.linesize[1] = ROUND_UP_4( av->out_frame->uv_width ); + pict.linesize[2] = ROUND_UP_4( av->out_frame->uv_width ); + + + pict.width = av->out_frame->width; + pict.height = av->out_frame->height; + + AVPacket pkt; + veejay_memset(&pkt,0,sizeof(pkt)); + + return vj_avcodec_encode_video( &pkt, av->context, buf, buf_len, &pict ); +#else + av->frame->pts = (int64_t) nframe; + av->frame->quality = FF_QP2LAMBDA * 3.0; + + av->frame->data[0] = src[0]; + av->frame->data[1] = src[1]; + av->frame->data[2] = src[2]; + + av->frame->linesize[0] = ROUND_UP_4( av->out_frame->width ); + av->frame->linesize[1] = ROUND_UP_4( av->out_frame->uv_width ); + av->frame->linesize[2] = ROUND_UP_4( av->out_frame->uv_width ); + + //av->frame->quality = 1; + //av->frame->key_frame = 1; + av->frame->pict_type = AV_PICTURE_TYPE_I; + + //av->frame->quality = 1; + int ret = vj_avcodec_encode_video( av->packet, av->context, buf, buf_len, av->frame ); + + return ret; +#endif } diff --git a/veejay-current/veejay-server/libel/vj-avcodec.h b/veejay-current/veejay-server/libel/vj-avcodec.h index d12539fb..5ae388f7 100644 --- a/veejay-current/veejay-server/libel/vj-avcodec.h +++ b/veejay-current/veejay-server/libel/vj-avcodec.h @@ -43,9 +43,10 @@ typedef struct { AVCodec *codec; AVCodec *audiocodec; -// AVFrame *frame; + AVFrame *frame; AVCodecContext *context; - int out_fmt; + AVPacket *packet; + //int out_fmt; int uv_len; int len; int sub_sample; @@ -53,19 +54,23 @@ typedef struct int encoder_id; int width; int height; - int format; + //int format; uint8_t *data[4]; void *lzo; int shift_y; int shift_x; void *dv; void *y4m; + VJFrame *out_frame; + VJFrame *in_frame; + void *scaler; } vj_encoder; int vj_avcodec_init(int pix, int verbose); char vj_avcodec_find_lav(int format); int vj_avcodec_encode_frame(void *encoder,long nframe, int format, uint8_t *src[4], uint8_t *dst, int dst_len, int pixel_format); uint8_t *vj_avcodec_get_buf( vj_encoder *av ); +int vj_avcodec_get_buf_size( vj_encoder *av ); const char *vj_avcodec_get_encoder_name(int encoder); int vj_avcodec_free(); void vj_libav_ffmpeg_version(); @@ -91,7 +96,4 @@ int vj_avcodec_stop( void *encoder , int fmt); void vj_avcodec_close_encoder( vj_encoder *av ); - -void yuv_scale_pixels_from_yuv_copy( uint8_t *plane, uint8_t *dst, float min, float max, int len ); - #endif diff --git a/veejay-current/veejay-server/libel/vj-el.c b/veejay-current/veejay-server/libel/vj-el.c index 2f4fb21f..ddb962f6 100644 --- a/veejay-current/veejay-server/libel/vj-el.c +++ b/veejay-current/veejay-server/libel/vj-el.c @@ -73,6 +73,8 @@ #define CODEC_ID_YUV420F 996 #define CODEC_ID_YUVLZO 900 #define DUMMY_FRAMES 2 +#define RUP16(num)(((num)+16)&~16) + static struct { @@ -113,10 +115,8 @@ typedef struct AVCodec *codec; AVFrame *frame; AVCodecContext *context; - uint8_t *tmp_buffer; - uint8_t *deinterlace_buffer[3]; - VJFrame *img; - int fmt; + uint8_t *tmp_buffer; + int fmt; int ref; #ifdef SUPPORT_READ_DV2 vj_dv_decoder *dv_decoder; @@ -162,8 +162,6 @@ static void _el_free_decoder( vj_decoder *d ) { if(d->tmp_buffer) free( d->tmp_buffer ); - if(d->deinterlace_buffer[0]) - free(d->deinterlace_buffer[0]); #ifdef SUPPORT_READ_DV2 if( d->dv_decoder ) { vj_dv_free_decoder( d->dv_decoder ); @@ -172,10 +170,6 @@ static void _el_free_decoder( vj_decoder *d ) if(d->frame) { av_free(d->frame); } - - if(d->img) - free(d->img); - if( d->lzo_decoder ) lzo_free(d->lzo_decoder); @@ -183,7 +177,6 @@ static void _el_free_decoder( vj_decoder *d ) } d = NULL; } -#define LARGE_NUM (256*256*256*64) static int el_pixel_format_org = 1; static int el_pixel_format_ = 1; @@ -308,10 +301,9 @@ int vj_el_cache_size() static vj_decoder *_el_new_decoder( void *ctx, int id , int width, int height, float fps, int pixel_format, int out_fmt, long max_frame_size) { - vj_decoder *d = (vj_decoder*) vj_calloc(sizeof(vj_decoder)); - if(!d) + vj_decoder *d = (vj_decoder*) vj_calloc(sizeof(vj_decoder)); + if(!d) return NULL; - #ifdef SUPPORT_READ_DV2 if( id == CODEC_ID_DVVIDEO ) d->dv_decoder = vj_dv_decoder_init(1, width, height, out_fmt ); @@ -319,7 +311,7 @@ static vj_decoder *_el_new_decoder( void *ctx, int id , int width, int height, f if( id == CODEC_ID_YUVLZO ) { - d->lzo_decoder = lzo_new(); + d->lzo_decoder = lzo_new( el_pixel_format_, el_width_, el_height_ , 1); } else if ( id == CODEC_ID_YUV422 || id == CODEC_ID_YUV420 || id == CODEC_ID_YUV420F || id == CODEC_ID_YUV422F ) { @@ -329,15 +321,16 @@ static vj_decoder *_el_new_decoder( void *ctx, int id , int width, int height, f d->codec = avhelper_get_codec(ctx); d->context = avhelper_get_codec_ctx(ctx); d->frame = avhelper_alloc_frame(); - d->img = (VJFrame*) vj_calloc(sizeof(VJFrame)); - d->img->width = width; - d->img->height = height; } - size_t safe_max_frame_size = (max_frame_size < GREMLIN_GUARDIAN) ? 128 * 1024: RUP8(max_frame_size); + + size_t safe_max_frame_size = RUP8( AV_INPUT_BUFFER_PADDING_SIZE + max_frame_size + GREMLIN_GUARDIAN ); + + veejay_msg(VEEJAY_MSG_DEBUG, "Decoder buffer is %d bytes" , safe_max_frame_size); + d->tmp_buffer = (uint8_t*) vj_malloc( sizeof(uint8_t) * safe_max_frame_size ); - d->fmt = id; + d->fmt = id; return d; } @@ -437,7 +430,9 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de return -1; } +#ifdef USE_GDK_PIXBUF if( !elfd->picture ) +#endif el->ctx[n] = avhelper_get_decoder( filename, out_format, width, height ); if( el->ctx[n] == NULL ) { @@ -651,8 +646,15 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de } if( el->decoders[n] == NULL ) { - long max_frame_size = get_max_frame_size( el->lav_fd[n] ); + decoder_id = el->lav_fd[n]->codec_id; + + long max_frame_size = (el->video_width * el->video_height * 4); + if( decoder_id < 900 && decoder_id != AV_CODEC_ID_HUFFYUV ) + max_frame_size = get_max_frame_size( el->lav_fd[n] ); + + max_frame_size = RUP16( max_frame_size ); + el->decoders[n] = _el_new_decoder( el->ctx[n], decoder_id, el->video_width, el->video_height, el->video_fps, el->pixfmt[ n ],el_pixel_format_, max_frame_size ); if( el->decoders[n] == NULL ) { @@ -794,10 +796,7 @@ int vj_el_get_video_frame(editlist *el, long nframe, uint8_t *dst[4]) if(el->cache) in_cache = get_cached_frame( el->cache, nframe, &res, &in_pix_fmt ); - int decoder_id = lav_video_compressor_type( el->lav_fd[N_EL_FILE(n)] ); - - if(! in_cache ) { @@ -841,7 +840,7 @@ int vj_el_get_video_frame(editlist *el, long nframe, uint8_t *dst[4]) uint8_t *in[3] = { NULL,NULL,NULL }; int strides[4] = { el_out_->len, el_out_->uv_len, el_out_->uv_len ,0}; uint8_t *dataplanes[4] = { data , data + el_out_->len, data + el_out_->len + el_out_->uv_len,0 }; - switch( decoder_id ) + switch( decoder_id ) //FIXME: use swscaler ? { case CODEC_ID_YUV420: vj_frame_copy1( data,dst[0], el_out_->len ); @@ -884,22 +883,16 @@ int vj_el_get_video_frame(editlist *el, long nframe, uint8_t *dst[4]) return 1; break; case CODEC_ID_YUVLZO: - if( ( in_pix_fmt == PIX_FMT_YUVJ420P || in_pix_fmt == PIX_FMT_YUV420P ) ) { - inter = lzo_decompress420into422(d->lzo_decoder, data,res,dst, el->video_width,el->video_height ); - } - else { - inter = lzo_decompress_el( d->lzo_decoder, data,res, dst,el->video_width*el->video_height); - } - - return inter; - + return lzo_decompress_el( d->lzo_decoder, data,res, dst, el_width_, el_height_, el_pixel_format_); break; default: - if( avhelper_decode_video( el->ctx[ N_EL_FILE(n) ], data, res ) ) { - avhelper_rescale_video( el->ctx[N_EL_FILE(n) ], dst ); - return 1; - } + int ret = avhelper_decode_video_direct( el->ctx[ N_EL_FILE(n) ], data, res, dst, el_pixel_format_,el_width_,el_height_ ); + + avhelper_decode_finish( el->ctx[ N_EL_FILE(n)] ); + + return ret; + break; } @@ -918,7 +911,7 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt) return -1; } - int decoder_id = lav_video_compressor_type( lav ); + int decoder_id = lav_video_compressor_type( lav ); if( decoder_id < 0 ) { @@ -960,6 +953,7 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt) if(!d) { + veejay_msg(0, "Failed to initialize decoder"); return -1; } @@ -976,6 +970,9 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt) int ret = -1; switch( decoder_id ) { + case CODEC_ID_HUFFYUV: + ret = PIX_FMT_YUV422P; + break; case CODEC_ID_YUV420F: ret = PIX_FMT_YUVJ420P; break; diff --git a/veejay-current/veejay-server/libplugger/frei0r-loader.c b/veejay-current/veejay-server/libplugger/frei0r-loader.c index 885359d2..23e057d8 100644 --- a/veejay-current/veejay-server/libplugger/frei0r-loader.c +++ b/veejay-current/veejay-server/libplugger/frei0r-loader.c @@ -938,7 +938,7 @@ void *frei0r_plug_init( void *plugin , int w, int h, int pf, int read_plug_cfg ) } fr->out = yuv_yuv_template(bufx, bufx+RUP8(w*h), bufx+RUP8(w*h*2), w,h,pf ); - fr->out->data[3] = bufx + RUP8(fr->out->len + fr->out->uv_len + fr->out->uv_len); + fr->out->data[3] = bufx + (fr->out->len + fr->out->uv_len + fr->out->uv_len); if( out_scaler__ == NULL ) { out_scaler__ = yuv_init_swscaler( fr->in[0],fr->out,&templ,yuv_sws_get_cpu_flags()); // rgb -> yuv diff --git a/veejay-current/veejay-server/libsamplerec/samplerecord.c b/veejay-current/veejay-server/libsamplerec/samplerecord.c index 524dd3c9..829af21b 100644 --- a/veejay-current/veejay-server/libsamplerec/samplerecord.c +++ b/veejay-current/veejay-server/libsamplerec/samplerecord.c @@ -172,7 +172,7 @@ static int sample_start_encoder(sample_info *si, VJFrame *frame, editlist *el, i case ENCODER_DVVIDEO: si->encoder_max_size = ( frame->height == 480 ? 120000: 144000); break; default: - si->encoder_max_size = 8 * ( 16 * 65535 ); + si->encoder_max_size = vj_avcodec_get_buf_size( si->encoder ); break; } @@ -273,19 +273,24 @@ int sample_record_frame(int s1, uint8_t *buffer[4], uint8_t *abuff, int audio_si buf_len = vj_avcodec_encode_frame(si->encoder, nframe, si->encoder_format, buffer, vj_avcodec_get_buf(si->encoder), si->encoder_max_size, pix_fmt); - if(buf_len <= 0) + if(buf_len < 0) { - veejay_msg(VEEJAY_MSG_ERROR, "Unable to encode frame"); return -1; } + + if(buf_len == 0) { + return (sample_continue_record(s1)); + } + + // si->rec_total_bytes += buf_len; //@ if writing to AVI/QT if( si->encoder_file != NULL ) { - if(lav_write_frame( (lav_file_t*) si->encoder_file,vj_avcodec_get_buf(si->encoder),buf_len,1)) + if(lav_write_frame( (lav_file_t*) si->encoder_file,vj_avcodec_get_buf(si->encoder),buf_len,1) < 0) { veejay_msg(VEEJAY_MSG_ERROR, "%s", lav_strerror()); if( si->encoder_frames_recorded > 1 ) { diff --git a/veejay-current/veejay-server/libstream/v4l2utils.c b/veejay-current/veejay-server/libstream/v4l2utils.c index a7ae8c96..43117c0c 100644 --- a/veejay-current/veejay-server/libstream/v4l2utils.c +++ b/veejay-current/veejay-server/libstream/v4l2utils.c @@ -77,7 +77,7 @@ #include #include #include -#include +#include #include #include #define RUP8(num)(((num)+8)&~8) @@ -576,7 +576,7 @@ static int v4l2_setup_avcodec_capture( v4l2info *v, int wid, int hei, int codec_ return 0; } -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 v->c = avcodec_alloc_context3( v->codec ); #else v->c = avcodec_alloc_context(); @@ -590,17 +590,23 @@ static int v4l2_setup_avcodec_capture( v4l2info *v, int wid, int hei, int codec_ v->picture->data[1] = vj_malloc( sizeof(uint8_t) * RUP8(wid * hei + wid)); v->picture->data[2] = vj_malloc( sizeof(uint8_t) * RUP8(wid * hei + wid)); +#if LIBAVCODEC_VERSION_MAJOR < 60 if( v->codec->capabilities & CODEC_CAP_TRUNCATED) v->c->flags |= CODEC_FLAG_TRUNCATED; +#endif -#if LIBAVCODEC_BUILD > 5400 +#if LIBAVCODEC_VERSION_MAJOR > 54 - int n_threads = avhelper_set_num_decoders(); + int n_threads = avhelper_set_num_decoders(); - if( n_threads > 0 ) { - v->c->thread_count = n_threads; - v->c->thread_type = FF_THREAD_FRAME; - } + if (v->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) { + v->c->thread_type = FF_THREAD_FRAME; + v->c->thread_count = n_threads; + } + else if (v->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) { + v->c->thread_type = FF_THREAD_SLICE; + v->c->thread_count = n_threads; + } if( avcodec_open2( v->c, v->codec, NULL ) < 0 ) #else @@ -1283,12 +1289,14 @@ static int v4l2_pull_frame_intern( v4l2info *v ) v4l2_set_output_pointers( v,src ); if( v->is_jpeg ) { + + AVPacket pkt; memset( &pkt, 0, sizeof(AVPacket)); pkt.data = src; pkt.size = length; - int res = avcodec_decode_video2( + int res = avhelper_decode_video3( v->c, v->picture, &got_picture, @@ -1401,7 +1409,8 @@ int v4l2_pull_frame(void *vv,VJFrame *dst) pkt.data = src; pkt.size = length; - int res = avcodec_decode_video2( + + int res = avhelper_decode_video3( v->c, v->picture, &got_picture, diff --git a/veejay-current/veejay-server/libstream/vj-net.c b/veejay-current/veejay-server/libstream/vj-net.c index 71ad545b..3a3a90bc 100644 --- a/veejay-current/veejay-server/libstream/vj-net.c +++ b/veejay-current/veejay-server/libstream/vj-net.c @@ -256,8 +256,9 @@ static void *mcast_reader_thread(void *data) { vj_tag *tag = (vj_tag*) data; threaded_t *t = tag->priv; + const int len = vj_tag_get_width() * vj_tag_get_height() * 4; const int padded = 256; - int max_len = padded + RUP8( 1920 * 1080 * 3 ); + const int max_len = padded + len; for( ;; ) { int error = 0; diff --git a/veejay-current/veejay-server/libstream/vj-tag.c b/veejay-current/veejay-server/libstream/vj-tag.c index 13adaa63..e44a6475 100644 --- a/veejay-current/veejay-server/libstream/vj-tag.c +++ b/veejay-current/veejay-server/libstream/vj-tag.c @@ -1835,7 +1835,7 @@ static int vj_tag_start_encoder(vj_tag *tag, int format, long nframes) case ENCODER_LZO: tag->encoder_max_size = tmp * 3; break; default: - tag->encoder_max_size = ( 4 * 65535 ); + tag->encoder_max_size = vj_avcodec_get_buf_size(tag->encoder); break; } @@ -3090,8 +3090,13 @@ int vj_tag_record_frame(int t1, uint8_t *buffer[4], uint8_t *abuff, int audio_si return -1; } + if( ret == 0 ) { + veejay_msg(VEEJAY_MSG_DEBUG, "Failed to encode frame %ld", nframe ); + return (vj_tag_continue_record(t1)); + } + if(tag->encoder_file ) { - if(lav_write_frame(tag->encoder_file, vj_avcodec_get_buf(tag->encoder), ret,1)) + if(lav_write_frame(tag->encoder_file, vj_avcodec_get_buf(tag->encoder), ret,1) < 0) { veejay_msg(VEEJAY_MSG_ERROR, "%s", lav_strerror()); if( tag->encoder_frames_recorded > 1 ) { diff --git a/veejay-current/veejay-server/libvje/effects/average.c b/veejay-current/veejay-server/libvje/effects/average.c index b9651633..d8f63c9e 100644 --- a/veejay-current/veejay-server/libvje/effects/average.c +++ b/veejay-current/veejay-server/libvje/effects/average.c @@ -66,8 +66,8 @@ void *average_malloc(int width, int height) free(a); return NULL; } - a->running_sum[1] = a->running_sum[0] + RUP8(width*height); - a->running_sum[2] = a->running_sum[1] + RUP8(width*height); + a->running_sum[1] = a->running_sum[0] + (width*height); + a->running_sum[2] = a->running_sum[1] + (width*height); a->frame_count = 1; return (void*) a; } diff --git a/veejay-current/veejay-server/libvje/effects/bathroom.c b/veejay-current/veejay-server/libvje/effects/bathroom.c index cf4dfb2e..14288323 100644 --- a/veejay-current/veejay-server/libvje/effects/bathroom.c +++ b/veejay-current/veejay-server/libvje/effects/bathroom.c @@ -86,9 +86,9 @@ void *bathroom_malloc(int width, int height) return NULL; } - b->bathroom_frame[1] = b->bathroom_frame[0] + RUP8(width*height); - b->bathroom_frame[2] = b->bathroom_frame[1] + RUP8(width*height); - b->bathroom_frame[3] = b->bathroom_frame[2] + RUP8(width*height); + b->bathroom_frame[1] = b->bathroom_frame[0] + (width*height); + b->bathroom_frame[2] = b->bathroom_frame[1] + (width*height); + b->bathroom_frame[3] = b->bathroom_frame[2] + (width*height); return (void*) b; } diff --git a/veejay-current/veejay-server/libvje/effects/bgpush.c b/veejay-current/veejay-server/libvje/effects/bgpush.c index 7f286012..8c0c0c6b 100644 --- a/veejay-current/veejay-server/libvje/effects/bgpush.c +++ b/veejay-current/veejay-server/libvje/effects/bgpush.c @@ -52,9 +52,9 @@ void *bgpush_malloc(int w, int h) b->frame_data = (uint8_t*) vj_malloc( RUP8(w*h*4) ); b->frame_ptr[0] = b->frame_data; - b->frame_ptr[1] = b->frame_ptr[0] + RUP8(w*h); - b->frame_ptr[2] = b->frame_ptr[1] + RUP8(w*h); - b->frame_ptr[3] = b->frame_ptr[2] + RUP8(w*h); + b->frame_ptr[1] = b->frame_ptr[0] + (w*h); + b->frame_ptr[2] = b->frame_ptr[1] + (w*h); + b->frame_ptr[3] = b->frame_ptr[2] + (w*h); veejay_memset( b->frame_ptr[0], 0, w * h ); veejay_memset( b->frame_ptr[1], 128, w * h ); diff --git a/veejay-current/veejay-server/libvje/effects/bgsubtract.c b/veejay-current/veejay-server/libvje/effects/bgsubtract.c index 0c4d5509..2ab51379 100644 --- a/veejay-current/veejay-server/libvje/effects/bgsubtract.c +++ b/veejay-current/veejay-server/libvje/effects/bgsubtract.c @@ -89,9 +89,9 @@ void *bgsubtract_malloc(int width, int height) } b->bg_frame__[0] = b->static_bg__; - b->bg_frame__[1] = b->bg_frame__[0] + RUP8(width*height); - b->bg_frame__[2] = b->bg_frame__[1] + RUP8(width*height); - b->bg_frame__[3] = b->bg_frame__[2] + RUP8(width*height); + b->bg_frame__[1] = b->bg_frame__[0] + (width*height); + b->bg_frame__[2] = b->bg_frame__[1] + (width*height); + b->bg_frame__[3] = b->bg_frame__[2] + (width*height); const char *hist = getenv( "VEEJAY_BG_AUTO_HISTOGRAM_EQ" ); if( hist ) { diff --git a/veejay-current/veejay-server/libvje/effects/bgsubtractgauss.c b/veejay-current/veejay-server/libvje/effects/bgsubtractgauss.c index 86d716f8..2c931d9b 100644 --- a/veejay-current/veejay-server/libvje/effects/bgsubtractgauss.c +++ b/veejay-current/veejay-server/libvje/effects/bgsubtractgauss.c @@ -120,12 +120,12 @@ void *bgsubtractgauss_malloc(int width, int height) } b->static_bg_frame__[0] = b->static_bg__; - b->static_bg_frame__[1] = b->static_bg_frame__[0] + RUP8(width*height); - b->static_bg_frame__[2] = b->static_bg_frame__[1] + RUP8(width*height); - b->static_bg_frame__[3] = b->static_bg_frame__[2] + RUP8(width*height); + b->static_bg_frame__[1] = b->static_bg_frame__[0] + (width*height); + b->static_bg_frame__[2] = b->static_bg_frame__[1] + (width*height); + b->static_bg_frame__[3] = b->static_bg_frame__[2] + (width*height); - veejay_memset( b->static_bg_frame__[1], 128, RUP8(width*height)); - veejay_memset( b->static_bg_frame__[2], 128, RUP8(width*height)); + veejay_memset( b->static_bg_frame__[1], 128, (width*height)); + veejay_memset( b->static_bg_frame__[2], 128, (width*height)); b->fg_frame__ = (uint8_t*) vj_calloc( RUP8(width*height*2) ); if(!b->fg_frame__ ) { diff --git a/veejay-current/veejay-server/libvje/effects/bloom.c b/veejay-current/veejay-server/libvje/effects/bloom.c index 9bddbd97..d8d94345 100644 --- a/veejay-current/veejay-server/libvje/effects/bloom.c +++ b/veejay-current/veejay-server/libvje/effects/bloom.c @@ -111,12 +111,12 @@ void bloom_apply(void *ptr, VJFrame *frame, int *args) { int height = frame->height; uint8_t *L = frame->data[0]; uint8_t *B = b->bloom_buf; - uint8_t *B1h = B + RUP8(len); - uint8_t *B1v = B1h + RUP8(len); - uint8_t *B2h = B1v + RUP8(len); - uint8_t *B2v = B2h + RUP8(len); - uint8_t *B3h = B2v + RUP8(len); - uint8_t *B3v = B3h + RUP8(len); + uint8_t *B1h = B + len; + uint8_t *B1v = B1h + len; + uint8_t *B2h = B1v + len; + uint8_t *B2v = B2h + len; + uint8_t *B3h = B2v + len; + uint8_t *B3v = B3h + len; for( int i = 0; i < len; i ++ ) { if( L[i] > threshold ) diff --git a/veejay-current/veejay-server/libvje/effects/complexsync.c b/veejay-current/veejay-server/libvje/effects/complexsync.c index 78043c7a..93459315 100644 --- a/veejay-current/veejay-server/libvje/effects/complexsync.c +++ b/veejay-current/veejay-server/libvje/effects/complexsync.c @@ -73,11 +73,11 @@ void *complexsync_malloc(int width, int height) return NULL; } - c->c_outofsync_buffer[1] = c->c_outofsync_buffer[0] + RUP8(width*height); - c->c_outofsync_buffer[2] = c->c_outofsync_buffer[1] + RUP8(width*height); + c->c_outofsync_buffer[1] = c->c_outofsync_buffer[0] + (width*height); + c->c_outofsync_buffer[2] = c->c_outofsync_buffer[1] + (width*height); - vj_frame_clear1( c->c_outofsync_buffer[0] , pixel_Y_lo_ , RUP8(width*height)); - vj_frame_clear1( c->c_outofsync_buffer[1] , 128, RUP8(width*height*2) ); + vj_frame_clear1( c->c_outofsync_buffer[0] , pixel_Y_lo_ , (width*height)); + vj_frame_clear1( c->c_outofsync_buffer[1] , 128, (width*height*2) ); return (void*) c; } diff --git a/veejay-current/veejay-server/libvje/effects/contourextract.c b/veejay-current/veejay-server/libvje/effects/contourextract.c index 3be1f5fc..ee533f65 100644 --- a/veejay-current/veejay-server/libvje/effects/contourextract.c +++ b/veejay-current/veejay-server/libvje/effects/contourextract.c @@ -137,7 +137,7 @@ int contourextract_malloc(void **d, int width, int height) my->bitmap = (uint8_t*) vj_calloc( sizeof(uint8_t) * RUP8( width * height )); if(static_bg == NULL) - static_bg = (uint8_t*) vj_calloc( sizeof(uint8_t) * RUP8( width * height) + RUP8(width*2)); + static_bg = (uint8_t*) vj_calloc( sizeof(uint8_t) * RUP8( (width * height + (width*2)) ) ); if(dt_map == NULL ) dt_map = (uint32_t*) vj_calloc( sizeof(uint32_t) * RUP8( width * height )); diff --git a/veejay-current/veejay-server/libvje/effects/diffmap.c b/veejay-current/veejay-server/libvje/effects/diffmap.c index 973a4286..1fe52a98 100644 --- a/veejay-current/veejay-server/libvje/effects/diffmap.c +++ b/veejay-current/veejay-server/libvje/effects/diffmap.c @@ -60,7 +60,7 @@ void *differencemap_malloc(int w, int h ) return NULL; } - d->binary_img = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8(w*h*2) + RUP8(w*2) ); + d->binary_img = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8( (w*h*2) + (w*2)) ); if(!d->binary_img) { free(d); return NULL; diff --git a/veejay-current/veejay-server/libvje/effects/distort.c b/veejay-current/veejay-server/libvje/effects/distort.c index 3884ed81..f830fe66 100644 --- a/veejay-current/veejay-server/libvje/effects/distort.c +++ b/veejay-current/veejay-server/libvje/effects/distort.c @@ -113,12 +113,12 @@ void *distortion_malloc(int w, int h) return NULL; } - d->plasma_buf[1] = d->plasma_buf[0] + RUP8(w*h); - d->plasma_buf[2] = d->plasma_buf[1] + RUP8(w*h); + d->plasma_buf[1] = d->plasma_buf[0] + (w*h); + d->plasma_buf[2] = d->plasma_buf[1] + (w*h); - veejay_memset( d->plasma_buf[0], 0, RUP8(w*h)); - veejay_memset( d->plasma_buf[1], 128,RUP8(w*h)); - veejay_memset( d->plasma_buf[2], 128,RUP8(w*h)); + veejay_memset( d->plasma_buf[0], 0, (w*h)); + veejay_memset( d->plasma_buf[1], 128,(w*h)); + veejay_memset( d->plasma_buf[2], 128,(w*h)); int i; float rad; diff --git a/veejay-current/veejay-server/libvje/effects/lumamask.c b/veejay-current/veejay-server/libvje/effects/lumamask.c index 9d0b2a7c..671e27e2 100644 --- a/veejay-current/veejay-server/libvje/effects/lumamask.c +++ b/veejay-current/veejay-server/libvje/effects/lumamask.c @@ -92,13 +92,13 @@ void *lumamask_malloc(int width, int height) veejay_memset( l->buf[0], pixel_Y_lo_, width * height ); - l->buf[1] = l->buf[0] + RUP8(width *height); + l->buf[1] = l->buf[0] + (width *height); veejay_memset( l->buf[1], 128, width * height ); - l->buf[2] = l->buf[1] + RUP8(width *height); + l->buf[2] = l->buf[1] + (width *height); veejay_memset( l->buf[2], 128, width * height ); - l->buf[3] = l->buf[2] + RUP8(width *height); + l->buf[3] = l->buf[2] + (width *height); veejay_memset( l->buf[3], 0, width * height ); return (void*) l; diff --git a/veejay-current/veejay-server/libvje/effects/magicmirror.c b/veejay-current/veejay-server/libvje/effects/magicmirror.c index 0a598266..66c8c147 100644 --- a/veejay-current/veejay-server/libvje/effects/magicmirror.c +++ b/veejay-current/veejay-server/libvje/effects/magicmirror.c @@ -91,9 +91,9 @@ void *magicmirror_malloc(int w, int h) return NULL; } - m->magicmirrorbuf[1] = m->magicmirrorbuf[0] + RUP8(w*h); - m->magicmirrorbuf[2] = m->magicmirrorbuf[1] + RUP8(w*h); - m->magicmirrorbuf[3] = m->magicmirrorbuf[2] + RUP8(w*h); + m->magicmirrorbuf[1] = m->magicmirrorbuf[0] + (w*h); + m->magicmirrorbuf[2] = m->magicmirrorbuf[1] + (w*h); + m->magicmirrorbuf[3] = m->magicmirrorbuf[2] + (w*h); m->funhouse_x = (double*)vj_calloc(sizeof(double) * w ); if(!m->funhouse_x) { diff --git a/veejay-current/veejay-server/libvje/effects/maskstop.c b/veejay-current/veejay-server/libvje/effects/maskstop.c index 404f9e96..24723a2e 100644 --- a/veejay-current/veejay-server/libvje/effects/maskstop.c +++ b/veejay-current/veejay-server/libvje/effects/maskstop.c @@ -80,14 +80,14 @@ void *maskstop_malloc(int width, int height) } for( i = 1; i < 6; i ++ ) - v->vvmaskstop_buffer[i] = v->vvmaskstop_buffer[(i-1)] + RUP8(width * height); + v->vvmaskstop_buffer[i] = v->vvmaskstop_buffer[(i-1)] + (width * height); - veejay_memset( v->vvmaskstop_buffer[1], 128, RUP8(width*height)); - veejay_memset( v->vvmaskstop_buffer[2], 128, RUP8(width*height)); - veejay_memset( v->vvmaskstop_buffer[4], 128, RUP8(width*height)); - veejay_memset( v->vvmaskstop_buffer[5], 128, RUP8(width*height)); - veejay_memset( v->vvmaskstop_buffer[0], pixel_Y_lo_, RUP8(width*height)); - veejay_memset( v->vvmaskstop_buffer[3], pixel_Y_lo_, RUP8(width*height)); + veejay_memset( v->vvmaskstop_buffer[1], 128, (width*height)); + veejay_memset( v->vvmaskstop_buffer[2], 128, (width*height)); + veejay_memset( v->vvmaskstop_buffer[4], 128, (width*height)); + veejay_memset( v->vvmaskstop_buffer[5], 128, (width*height)); + veejay_memset( v->vvmaskstop_buffer[0], pixel_Y_lo_, (width*height)); + veejay_memset( v->vvmaskstop_buffer[3], pixel_Y_lo_, (width*height)); v->frq_frame = 256; v->frq_mask = 256; diff --git a/veejay-current/veejay-server/libvje/effects/median.c b/veejay-current/veejay-server/libvje/effects/median.c index cbe0c3bf..73e719e1 100644 --- a/veejay-current/veejay-server/libvje/effects/median.c +++ b/veejay-current/veejay-server/libvje/effects/median.c @@ -75,8 +75,8 @@ void *medianfilter_malloc(int w, int h) free(m); return NULL; } - m->buffer[1] = m->buffer[0] + RUP8(w * h); - m->buffer[2] = m->buffer[1] + RUP8(w * h); + m->buffer[1] = m->buffer[0] + (w * h); + m->buffer[2] = m->buffer[1] + (w * h); return (void*) m; } diff --git a/veejay-current/veejay-server/libvje/effects/motionblur.c b/veejay-current/veejay-server/libvje/effects/motionblur.c index b98fa8c1..564eccd7 100644 --- a/veejay-current/veejay-server/libvje/effects/motionblur.c +++ b/veejay-current/veejay-server/libvje/effects/motionblur.c @@ -58,8 +58,8 @@ void *motionblur_malloc(int width, int height) free(m); return NULL; } - m->previous_frame[1] = m->previous_frame[0] + RUP8(width*height); - m->previous_frame[2] = m->previous_frame[1] + RUP8(width*height); + m->previous_frame[1] = m->previous_frame[0] + (width*height); + m->previous_frame[2] = m->previous_frame[1] + (width*height); return (void*) m; } diff --git a/veejay-current/veejay-server/libvje/effects/motionmap.c b/veejay-current/veejay-server/libvje/effects/motionmap.c index 2206c921..409606ee 100644 --- a/veejay-current/veejay-server/libvje/effects/motionmap.c +++ b/veejay-current/veejay-server/libvje/effects/motionmap.c @@ -424,7 +424,7 @@ void motionmap_apply( void *ptr, VJFrame *frame, int *args ) mm->activity_decay = act_decay; } - motionmap_calc_diff( (const uint8_t*) mm->bg_image, mm->prev_img, (const uint8_t*) frame->data[0], mm->diff_img, mm->diff_img + RUP8(len), mm->binary_img, len, threshold ); + motionmap_calc_diff( (const uint8_t*) mm->bg_image, mm->prev_img, (const uint8_t*) frame->data[0], mm->diff_img, mm->diff_img + len, mm->binary_img, len, threshold ); if( draw ) { diff --git a/veejay-current/veejay-server/libvje/effects/neighbours.c b/veejay-current/veejay-server/libvje/effects/neighbours.c index b0fbccba..5afb3a12 100644 --- a/veejay-current/veejay-server/libvje/effects/neighbours.c +++ b/veejay-current/veejay-server/libvje/effects/neighbours.c @@ -76,7 +76,7 @@ void *neighbours_malloc(int w, int h ) return NULL; } - n->tmp_buf[1] = n->tmp_buf[0] + RUP8(w*h); + n->tmp_buf[1] = n->tmp_buf[0] + (w*h); n->chromacity[0] = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8(w * h *2)); if(!n->chromacity[0]) { @@ -85,7 +85,7 @@ void *neighbours_malloc(int w, int h ) return NULL; } - n->chromacity[1] = n->chromacity[0] + RUP8(w*h); + n->chromacity[1] = n->chromacity[0] + (w*h); return (void*) n; } diff --git a/veejay-current/veejay-server/libvje/effects/neighbours2.c b/veejay-current/veejay-server/libvje/effects/neighbours2.c index 6cdcbe6c..33ac09c0 100644 --- a/veejay-current/veejay-server/libvje/effects/neighbours2.c +++ b/veejay-current/veejay-server/libvje/effects/neighbours2.c @@ -74,7 +74,7 @@ void *neighbours2_malloc(int w, int h ) return NULL; } - n->tmp_buf[1] = n->tmp_buf[0] + RUP8(w*h); + n->tmp_buf[1] = n->tmp_buf[0] + (w*h); n->chromacity[0] = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8(w * h *2)); if(!n->chromacity[0]) { free(n->tmp_buf[0]); @@ -82,7 +82,7 @@ void *neighbours2_malloc(int w, int h ) return NULL; } - n->chromacity[1] = n->chromacity[0] + RUP8(w*h); + n->chromacity[1] = n->chromacity[0] + (w*h); return (void*) n; } diff --git a/veejay-current/veejay-server/libvje/effects/neighbours3.c b/veejay-current/veejay-server/libvje/effects/neighbours3.c index 9d7c6747..767fc072 100644 --- a/veejay-current/veejay-server/libvje/effects/neighbours3.c +++ b/veejay-current/veejay-server/libvje/effects/neighbours3.c @@ -74,7 +74,7 @@ void *neighbours3_malloc(int w, int h ) return NULL; } - n->tmp_buf[1] = n->tmp_buf[0] + RUP8(w*h); + n->tmp_buf[1] = n->tmp_buf[0] + (w*h); n->chromacity[0] = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8(w * h *2)); if(!n->chromacity[0]) { diff --git a/veejay-current/veejay-server/libvje/effects/neighbours4.c b/veejay-current/veejay-server/libvje/effects/neighbours4.c index 0ae1c078..8b5be6ae 100644 --- a/veejay-current/veejay-server/libvje/effects/neighbours4.c +++ b/veejay-current/veejay-server/libvje/effects/neighbours4.c @@ -91,7 +91,7 @@ void *neighbours4_malloc(int w, int h ) return NULL; } - n->tmp_buf[1] = n->tmp_buf[0] + RUP8(w*h); + n->tmp_buf[1] = n->tmp_buf[0] + (w*h); n->chromacity[0] = (uint8_t*) vj_malloc(sizeof(uint8_t) * RUP8(w * h *2)); if(!n->chromacity[0]) { diff --git a/veejay-current/veejay-server/libvje/effects/nervous.c b/veejay-current/veejay-server/libvje/effects/nervous.c index 41f09123..fc6240a4 100644 --- a/veejay-current/veejay-server/libvje/effects/nervous.c +++ b/veejay-current/veejay-server/libvje/effects/nervous.c @@ -69,9 +69,9 @@ void *nervous_malloc(int w, int h ) return NULL; } - n->nervous_buf[1] = n->nervous_buf[0] + RUP8(w*h*N_MAX); - n->nervous_buf[2] = n->nervous_buf[1] + RUP8(w*h*N_MAX); - n->nervous_buf[3] = n->nervous_buf[2] + RUP8(w*h*N_MAX); + n->nervous_buf[1] = n->nervous_buf[0] + (w*h*N_MAX); + n->nervous_buf[2] = n->nervous_buf[1] + (w*h*N_MAX); + n->nervous_buf[3] = n->nervous_buf[2] + (w*h*N_MAX); n->frames_elapsed = 0; vj_frame_clear1( n->nervous_buf[0], 0, (w*h) * N_MAX ); diff --git a/veejay-current/veejay-server/libvje/effects/pencilsketch2.c b/veejay-current/veejay-server/libvje/effects/pencilsketch2.c index 144a9bbb..c61a8eb3 100644 --- a/veejay-current/veejay-server/libvje/effects/pencilsketch2.c +++ b/veejay-current/veejay-server/libvje/effects/pencilsketch2.c @@ -98,8 +98,8 @@ void *pencilsketch2_malloc(int w, int h) { return NULL; } - p->pencilhblur = p->pencilbuf + RUP8(w*h); - p->pencilvblur = p->pencilhblur + RUP8(w*h); + p->pencilhblur = p->pencilbuf + (w*h); + p->pencilvblur = p->pencilhblur + (w*h); p->histogram_ = veejay_histogram_new(); if(!p->histogram_) { diff --git a/veejay-current/veejay-server/libvje/effects/perspective.c b/veejay-current/veejay-server/libvje/effects/perspective.c index 27fbb017..bdb857e2 100644 --- a/veejay-current/veejay-server/libvje/effects/perspective.c +++ b/veejay-current/veejay-server/libvje/effects/perspective.c @@ -84,8 +84,8 @@ void *perspective_malloc(int width, int height) return NULL; } - p->perspective_private_[1] = p->perspective_private_[0] + RUP8( width * height + width ); - p->perspective_private_[2] = p->perspective_private_[1] + RUP8( width * height + width ); + p->perspective_private_[1] = p->perspective_private_[0] + ( width * height + width ); + p->perspective_private_[2] = p->perspective_private_[1] + ( width * height + width ); return (void*) p; } diff --git a/veejay-current/veejay-server/libvje/effects/radialblur.c b/veejay-current/veejay-server/libvje/effects/radialblur.c index bfe58df6..295f90d4 100644 --- a/veejay-current/veejay-server/libvje/effects/radialblur.c +++ b/veejay-current/veejay-server/libvje/effects/radialblur.c @@ -88,8 +88,8 @@ void *radialblur_malloc(int w, int h) return NULL; } - r->radial_src[1] = r->radial_src[0] + RUP8(w*h); - r->radial_src[2] = r->radial_src[1] + RUP8(w*h); + r->radial_src[1] = r->radial_src[0] + (w*h); + r->radial_src[2] = r->radial_src[1] + (w*h); return (void*) r; } diff --git a/veejay-current/veejay-server/libvje/effects/rotozoom.c b/veejay-current/veejay-server/libvje/effects/rotozoom.c index 01175453..894f9c6d 100644 --- a/veejay-current/veejay-server/libvje/effects/rotozoom.c +++ b/veejay-current/veejay-server/libvje/effects/rotozoom.c @@ -81,8 +81,8 @@ void *rotozoom_malloc(int width, int height) return NULL; } - r->rotobuffer[1] = r->rotobuffer[0] + RUP8(width * height); - r->rotobuffer[2] = r->rotobuffer[1] + RUP8(width * height); + r->rotobuffer[1] = r->rotobuffer[0] + (width * height); + r->rotobuffer[2] = r->rotobuffer[1] + (width * height); int j; for (j = 0; j < 9; j++) { diff --git a/veejay-current/veejay-server/libvje/effects/sinoids.c b/veejay-current/veejay-server/libvje/effects/sinoids.c index daa0c9e8..5364d218 100644 --- a/veejay-current/veejay-server/libvje/effects/sinoids.c +++ b/veejay-current/veejay-server/libvje/effects/sinoids.c @@ -83,8 +83,8 @@ void *sinoids_malloc(int width, int height) return NULL; } - s->sinoid_frame[1] = s->sinoid_frame[0] + RUP8(width*height); - s->sinoid_frame[2] = s->sinoid_frame[1] + RUP8(width*height); + s->sinoid_frame[1] = s->sinoid_frame[0] + (width*height); + s->sinoid_frame[2] = s->sinoid_frame[1] + (width*height); for(i=0; i < width; i++ ) { s->sinoids_X[i] = (int) ( sin( ((double)i/(double)width) * 2 * 3.1415926) * 1); diff --git a/veejay-current/veejay-server/libvje/effects/slice.c b/veejay-current/veejay-server/libvje/effects/slice.c index cbeee0e8..d57cdd22 100644 --- a/veejay-current/veejay-server/libvje/effects/slice.c +++ b/veejay-current/veejay-server/libvje/effects/slice.c @@ -70,9 +70,9 @@ void *slice_malloc(int width, int height) free(s); return NULL; } - s->slice_frame[1] = s->slice_frame[0] + RUP8(width * height); - s->slice_frame[2] = s->slice_frame[1] + RUP8(width * height); - s->slice_frame[3] = s->slice_frame[2] + RUP8(width * height); + s->slice_frame[1] = s->slice_frame[0] + (width * height); + s->slice_frame[2] = s->slice_frame[1] + (width * height); + s->slice_frame[3] = s->slice_frame[2] + (width * height); s->slice_xshift = (int*) vj_malloc(sizeof(int) * height); if(!s->slice_xshift) { free(s->slice_frame[0]); diff --git a/veejay-current/veejay-server/libvje/effects/split.c b/veejay-current/veejay-server/libvje/effects/split.c index eaa1258c..0266c5df 100644 --- a/veejay-current/veejay-server/libvje/effects/split.c +++ b/veejay-current/veejay-server/libvje/effects/split.c @@ -61,8 +61,8 @@ void *split_malloc(int width, int height) return NULL; } - s->split_buf[1] = s->split_buf[0] + RUP8(width*height); - s->split_buf[2] = s->split_buf[1] + RUP8(width*height); + s->split_buf[1] = s->split_buf[0] + (width*height); + s->split_buf[2] = s->split_buf[1] + (width*height); return (void*)s; } diff --git a/veejay-current/veejay-server/libvje/effects/swirl.c b/veejay-current/veejay-server/libvje/effects/swirl.c index 1286810b..2b368936 100644 --- a/veejay-current/veejay-server/libvje/effects/swirl.c +++ b/veejay-current/veejay-server/libvje/effects/swirl.c @@ -66,8 +66,8 @@ void *swirl_malloc(int w, int h) swirl_free(s); return NULL; } - s->buf[1] = s->buf[0] + RUP8(w*h); - s->buf[2] = s->buf[1] + RUP8(w*h); + s->buf[1] = s->buf[0] + (w*h); + s->buf[2] = s->buf[1] + (w*h); s->polar_map = (double*) vj_calloc(sizeof(double) * RUP8(w * h) ); if(!s->polar_map) { diff --git a/veejay-current/veejay-server/libvje/effects/timedistort.c b/veejay-current/veejay-server/libvje/effects/timedistort.c index c749efc2..99135eeb 100644 --- a/veejay-current/veejay-server/libvje/effects/timedistort.c +++ b/veejay-current/veejay-server/libvje/effects/timedistort.c @@ -78,7 +78,7 @@ void *timedistort_malloc( int w, int h ) return NULL; } - td->nonmap = vj_calloc( (RUP8(2 * w * h) + RUP8(2 * w)) * sizeof(uint8_t)); + td->nonmap = vj_calloc( (RUP8(2 * w * h + (2 * w))) * sizeof(uint8_t)); if(!td->nonmap) { free(td); return NULL; @@ -90,12 +90,12 @@ void *timedistort_malloc( int w, int h ) free(td); return NULL; } - td->planes[1] = td->planes[0] + RUP8(PLANES * w * h ); - td->planes[2] = td->planes[1] + RUP8(PLANES * w * h ); + td->planes[1] = td->planes[0] + (PLANES * w * h ); + td->planes[2] = td->planes[1] + (PLANES * w * h ); - veejay_memset( td->planes[0],0, RUP8(PLANES * w * h )); - veejay_memset( td->planes[1],128,RUP8(PLANES * w * h )); - veejay_memset( td->planes[2],128,RUP8(PLANES * w * h )); + veejay_memset( td->planes[0],0, (PLANES * w * h )); + veejay_memset( td->planes[1],128,(PLANES * w * h )); + veejay_memset( td->planes[2],128,(PLANES * w * h )); td->have_bg = 0; td->n__ = 0; diff --git a/veejay-current/veejay-server/libvje/effects/zoom.c b/veejay-current/veejay-server/libvje/effects/zoom.c index 3b3f1ed8..cae886e1 100644 --- a/veejay-current/veejay-server/libvje/effects/zoom.c +++ b/veejay-current/veejay-server/libvje/effects/zoom.c @@ -79,9 +79,9 @@ void *zoom_malloc(int width, int height) if(!z) return NULL; z->zoom_private_[0] = (uint8_t*) vj_malloc( sizeof(uint8_t) * RUP8( width * height + width ) * 4 ); - z->zoom_private_[1] = z->zoom_private_[0] + RUP8(width * height + width); - z->zoom_private_[2] = z->zoom_private_[1] + RUP8(width * height + width); - z->zoom_private_[3] = z->zoom_private_[2] + RUP8(width * height + width); + z->zoom_private_[1] = z->zoom_private_[0] + (width * height + width); + z->zoom_private_[2] = z->zoom_private_[1] + (width * height + width); + z->zoom_private_[3] = z->zoom_private_[2] + (width * height + width); return (void*) z; } diff --git a/veejay-current/veejay-server/libvje/libvje.c b/veejay-current/veejay-server/libvje/libvje.c index 9130a13e..4b8eecd1 100644 --- a/veejay-current/veejay-server/libvje/libvje.c +++ b/veejay-current/veejay-server/libvje/libvje.c @@ -287,8 +287,8 @@ void vje_set_bg(VJFrame *bg) veejay_memcpy(vj_fx_bg, bg, sizeof(VJFrame)); vj_fx_bg->data[0] = (uint8_t*) vj_malloc( sizeof(uint8_t) * RUP8( bg->len * 3 ) ); // enough space to hold 4:4:4 - vj_fx_bg->data[1] = vj_fx_bg->data[0] + RUP8(bg->len); - vj_fx_bg->data[2] = vj_fx_bg->data[1] + RUP8(bg->len); + vj_fx_bg->data[1] = vj_fx_bg->data[0] + bg->len; + vj_fx_bg->data[2] = vj_fx_bg->data[1] + bg->len; vj_fx_bg->data[3] = NULL; veejay_memcpy( vj_fx_bg->data[0], bg->data[0], bg->len ); diff --git a/veejay-current/veejay-server/livido-plugins/lvd_stroboscope.c b/veejay-current/veejay-server/livido-plugins/lvd_stroboscope.c index d56e793e..aff38c9d 100644 --- a/veejay-current/veejay-server/livido-plugins/lvd_stroboscope.c +++ b/veejay-current/veejay-server/livido-plugins/lvd_stroboscope.c @@ -40,8 +40,8 @@ int init_instance( livido_port_t *my_instance ) } hb->planes[0] = hb->buffer; - hb->planes[1] = hb->planes[0] + RUP8(w*h); - hb->planes[2] = hb->planes[1] + RUP8(w*h); + hb->planes[1] = hb->planes[0] + (w*h); + hb->planes[2] = hb->planes[1] + (w*h); hb->current = 0; livido_property_set( my_instance, "PLUGIN_private", LIVIDO_ATOM_TYPE_VOIDPTR,1, &hb); diff --git a/veejay-current/veejay-server/thirdparty/libresample/resample2.c b/veejay-current/veejay-server/thirdparty/libresample/resample2.c index 5ba98248..b5480648 100644 --- a/veejay-current/veejay-server/thirdparty/libresample/resample2.c +++ b/veejay-current/veejay-server/thirdparty/libresample/resample2.c @@ -200,7 +200,7 @@ void *vj_av_resample_init(int out_rate, int in_rate, int filter_size, int phase_ c->linear= linear; c->filter_length= FFMAX((int)ceil(filter_size/factor), 1); - c->filter_bank= av_mallocz_array(c->filter_length, (phase_count+1)*sizeof(FELEM)); + c->filter_bank= av_calloc(c->filter_length, (phase_count+1)*sizeof(FELEM)); if (!c->filter_bank) goto error; if (build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<current_frame_num); } + veejay_event_handle(info); + + settings->currently_processed_entry = settings->buffer_entry[settings->currently_processed_frame]; @@ -2413,7 +2416,7 @@ static void veejay_playback_cycle(veejay_t * info) goto FINISH; } - veejay_event_handle(info); +// veejay_event_handle(info); frame = bs.frame; diff --git a/veejay-current/veejay-server/veejay/vj-composite.c b/veejay-current/veejay-server/veejay/vj-composite.c index f50a87e4..05e58c91 100644 --- a/veejay-current/veejay-server/veejay/vj-composite.c +++ b/veejay-current/veejay-server/veejay/vj-composite.c @@ -122,8 +122,8 @@ void *composite_init( int pw, int ph, int iw, int ih, char *homedir, int sample_ } c->proj_plane[0] = (uint8_t*) vj_calloc( RUP8( pw * ph * 3) + RUP8(pw * 3) * sizeof(uint8_t)); - c->proj_plane[1] = c->proj_plane[0] + RUP8(pw * ph) + RUP8(pw); - c->proj_plane[2] = c->proj_plane[1] + RUP8(pw * ph) + RUP8(pw); + c->proj_plane[1] = c->proj_plane[0] + (pw * ph) + (pw); + c->proj_plane[2] = c->proj_plane[1] + (pw * ph) + (pw); viewport_set_marker( c->vp1, 1 ); sws_template sws_templ; @@ -153,8 +153,8 @@ void *composite_init( int pw, int ph, int iw, int ih, char *homedir, int sample_ if( strncasecmp( gf_instr, "1", 1 ) == 0 ) { c->has_mirror_plane = 1; c->mirror_plane[0] = (uint8_t*) vj_calloc( RUP8( iw * ih * 3) + RUP8(iw * 3) * sizeof(uint8_t)); - c->mirror_plane[1] = c->mirror_plane[0] + RUP8(iw * ih) + RUP8(iw); - c->mirror_plane[2] = c->mirror_plane[1] + RUP8(iw * ih) + RUP8(iw); + c->mirror_plane[1] = c->mirror_plane[0] + (iw * ih) + (iw); + c->mirror_plane[2] = c->mirror_plane[1] + (iw * ih) + (iw); c->mirror_row_start = 0; c->mirror_row_end = 0; } diff --git a/veejay-current/veejay-server/veejay/vj-event.c b/veejay-current/veejay-server/veejay/vj-event.c index 07e5d06b..3b6ff710 100644 --- a/veejay-current/veejay-server/veejay/vj-event.c +++ b/veejay-current/veejay-server/veejay/vj-event.c @@ -160,7 +160,7 @@ static char *get_print_buf(int size) { int s = size; if( s<= 0) s = SEND_BUF; - char *res = (char*) vj_calloc(sizeof(char) * s ); + char *res = (char*) vj_calloc(sizeof(char) * RUP8(s) ); return res; } @@ -1523,28 +1523,32 @@ void vj_event_commit_bundle( veejay_t *v, int key_num, int key_mod) int vj_event_single_fire(void *ptr , SDL_Event event, int pressed) { SDL_KeyboardEvent *key = &event.key; - SDL_Keymod mod = key->keysym.mod; veejay_t *v = (veejay_t*) ptr; int vims_mod = 0; + vj_keyboard_event *ev = NULL; - if( (mod & KMOD_LSHIFT) || (mod & KMOD_RSHIFT )) // could use direct KMOD_SHIFT ? - vims_mod |= VIMS_MOD_SHIFT; - if( (mod & KMOD_LALT) || (mod & KMOD_ALT) ) // ONLY LEFT SHIFT !!! - vims_mod |= VIMS_MOD_ALT; - if( (mod & KMOD_CTRL) || (mod & KMOD_CTRL) ) // Both CTRL (but not explicit l & r) - vims_mod |= VIMS_MOD_CTRL; - if( (mod & KMOD_CAPS) ) { - vims_mod = VIMS_MOD_CAPSLOCK; // FIXME change to |= or not ??? - } + if( event.type == SDL_KEYDOWN || event.type == SDL_KEYUP ) { + SDL_Keymod mod = key->keysym.mod; + + if( (mod & KMOD_LSHIFT) || (mod & KMOD_RSHIFT )) // could use direct KMOD_SHIFT ? + vims_mod |= VIMS_MOD_SHIFT; + if( (mod & KMOD_LALT) || (mod & KMOD_ALT) ) // ONLY LEFT SHIFT !!! + vims_mod |= VIMS_MOD_ALT; + if( (mod & KMOD_CTRL) || (mod & KMOD_CTRL) ) // Both CTRL (but not explicit l & r) + vims_mod |= VIMS_MOD_CTRL; + if( (mod & KMOD_CAPS) ) { + vims_mod = VIMS_MOD_CAPSLOCK; // FIXME change to |= or not ??? + } - int vims_key = key->keysym.scancode; - int index = vims_mod * SDL_NUM_SCANCODES + vims_key; + int vims_key = key->keysym.scancode; + int index = vims_mod * SDL_NUM_SCANCODES + vims_key; - vj_keyboard_event *ev = get_keyboard_event( index ); + ev = get_keyboard_event( index ); - veejay_msg(VEEJAY_MSG_DEBUG, + veejay_msg(VEEJAY_MSG_DEBUG, "VIMS modifier: %d (SDL modifier %d/%x), Key %d, VIMS event %p", vims_mod, mod,mod, vims_key, ev ); + } if(!ev ) { @@ -2190,7 +2194,7 @@ static void vj_event_init_keyboard_defaults() void vj_event_init(void *ptr) { - veejay_t *v = (veejay_t*) ptr; + veejay_t *v = (veejay_t*) ptr; int i; #ifdef HAVE_SDL veejay_memset( keyboard_event_map_, 0, sizeof(keyboard_event_map_)); @@ -8625,7 +8629,6 @@ void vj_event_send_generator_list( void *ptr, const char format[], va_list ap int i; char *s_print_buf = get_print_buf(6 + (total * 128)); veejay_t *v = (veejay_t*) ptr; - if( s_print_buf == NULL ) { SEND_MSG(v, "00000" ); } diff --git a/veejay-current/veejay-server/veejay/vj-perform.c b/veejay-current/veejay-server/veejay/vj-perform.c index eeec792f..660fbbc9 100644 --- a/veejay-current/veejay-server/veejay/vj-perform.c +++ b/veejay-current/veejay-server/veejay/vj-perform.c @@ -754,8 +754,8 @@ static int vj_perform_record_buffer_init(veejay_t *info) if(!region) return 0; g->offline_frame->data[0] = region; - g->offline_frame->data[1] = region + RUP8( g->offline_frame->len ); - g->offline_frame->data[2] = region + RUP8( g->offline_frame->len + g->offline_frame->uv_len ); + g->offline_frame->data[1] = region + ( g->offline_frame->len ); + g->offline_frame->data[2] = region + ( g->offline_frame->len + g->offline_frame->uv_len ); veejay_memset( g->offline_frame->data[0] , pixel_Y_lo_, g->offline_frame->len ); veejay_memset( g->offline_frame->data[1], 128, g->offline_frame->uv_len ); @@ -1347,7 +1347,7 @@ static int vj_perform_compress_primary_frame_s2(veejay_t *info,VJFrame *frame ) ENCODER_MJPEG, frame->data, vj_avcodec_get_buf(g->encoder_), - 8 * 16 * 65535, + vj_avcodec_get_buf_size(g->encoder_), frame->format); } diff --git a/veejay-current/veejay-server/veejay/vj-sdl.c b/veejay-current/veejay-server/veejay/vj-sdl.c index 68dd1cf9..99376abd 100644 --- a/veejay-current/veejay-server/veejay/vj-sdl.c +++ b/veejay-current/veejay-server/veejay/vj-sdl.c @@ -41,6 +41,7 @@ #include #define RUP8(num)(((num)+8)&~8) +#define RUP16(num)(((num)+16)&~16) typedef struct vj_sdl_t { SDL_Window *screen; @@ -92,7 +93,7 @@ void *vj_sdl_allocate(VJFrame *frame, int use_key, int use_mouse, int show_curso vjsdl->src_frame = (void*) src; vjsdl->dst_frame = (void*) dst; - vjsdl->pixels = (uint8_t*) vj_calloc(sizeof(uint8_t) * RUP8( frame->len * 2 ) ); + vjsdl->pixels = (uint8_t*) vj_calloc(sizeof(uint8_t) * RUP16( frame->len * 2 ) ); return (void*) vjsdl; }