├── .gitignore ├── AUTHORS ├── COPYING ├── Makefile ├── common ├── arm │ ├── asm.S │ ├── cpu-a.S │ ├── dct-a.S │ ├── dct.h │ ├── deblock-a.S │ ├── mc-a.S │ ├── mc-c.c │ ├── mc.h │ ├── pixel-a.S │ ├── pixel.h │ ├── predict-a.S │ ├── predict-c.c │ ├── predict.h │ ├── quant-a.S │ └── quant.h ├── bitstream.c ├── bitstream.h ├── cabac.c ├── cabac.h ├── common.c ├── common.h ├── cpu.c ├── cpu.h ├── dct.c ├── dct.h ├── deblock.c ├── frame.c ├── frame.h ├── macroblock.c ├── macroblock.h ├── mc.c ├── mc.h ├── mpeg2vlc.c ├── mvpred.c ├── opencl.c ├── opencl.h ├── opencl │ ├── bidir.cl │ ├── downscale.cl │ ├── intra.cl │ ├── motionsearch.cl │ ├── subpel.cl │ ├── weightp.cl │ └── x264-cl.h ├── osdep.c ├── osdep.h ├── pixel.c ├── pixel.h ├── ppc │ ├── dct.c │ ├── dct.h │ ├── deblock.c │ ├── mc.c │ ├── mc.h │ ├── pixel.c │ ├── pixel.h │ ├── ppccommon.h │ ├── predict.c │ ├── predict.h │ ├── quant.c │ └── quant.h ├── predict.c ├── predict.h ├── quant.c ├── quant.h ├── rectangle.c ├── rectangle.h ├── set.c ├── set.h ├── sparc │ ├── pixel.asm │ └── pixel.h ├── threadpool.c ├── threadpool.h ├── vlc.c ├── win32thread.c ├── win32thread.h └── x86 │ ├── bitstream-a.asm │ ├── cabac-a.asm │ ├── const-a.asm │ ├── cpu-a.asm │ ├── dct-32.asm │ ├── dct-64.asm │ ├── dct-a.asm │ ├── dct.h │ ├── deblock-a.asm │ ├── mc-a.asm │ ├── mc-a2.asm │ ├── mc-c.c │ ├── mc.h │ ├── pixel-32.asm │ ├── pixel-a.asm │ ├── pixel.h │ ├── predict-a.asm │ ├── predict-c.c │ ├── predict.h │ ├── quant-a.asm │ ├── quant.h │ ├── sad-a.asm │ ├── sad16-a.asm │ ├── trellis-64.asm │ ├── util.h │ ├── x86inc.asm │ └── x86util.asm ├── config.guess ├── config.sub ├── configure ├── doc ├── ratecontrol.txt ├── regression_test.txt ├── standards.txt ├── threads.txt └── vui.txt ├── encoder ├── analyse.c ├── analyse.h ├── cabac.c ├── cavlc.c ├── encoder.c ├── lookahead.c ├── macroblock.c ├── macroblock.h ├── me.c ├── me.h ├── mpeg2vlc.c ├── ratecontrol.c ├── ratecontrol.h ├── rdo.c ├── set.c ├── set.h ├── slicetype-cl.c └── slicetype.c ├── extras ├── avisynth_c.h ├── avxsynth_c.h ├── cl.h ├── cl_platform.h ├── gas-preprocessor.pl ├── getopt.c ├── getopt.h ├── inttypes.h ├── stdint.h └── windowsPorts │ ├── basicDataTypeConversions.h │ └── windows2linux.h ├── filters ├── filters.c ├── filters.h └── video │ ├── cache.c │ ├── crop.c │ ├── depth.c │ ├── fix_vfr_pts.c │ ├── internal.c │ ├── internal.h │ ├── resize.c │ ├── select_every.c │ ├── source.c │ ├── video.c │ └── video.h ├── input ├── avs.c ├── ffms.c ├── input.c ├── input.h ├── lavf.c ├── raw.c ├── thread.c ├── timecode.c └── y4m.c ├── output ├── flv.c ├── flv_bytestream.c ├── flv_bytestream.h ├── matroska.c ├── matroska_ebml.c ├── matroska_ebml.h ├── mp4.c ├── mp4_lsmash.c ├── output.h └── raw.c ├── tools ├── checkasm-a.asm ├── checkasm.c ├── cltostr.pl ├── countquant_x264.pl ├── digress │ ├── __init__.py │ ├── cli.py │ ├── comparers.py │ ├── constants.py │ ├── errors.py │ ├── scm │ │ ├── __init__.py │ │ ├── dummy.py │ │ └── git.py │ └── testing.py ├── q_matrix_jvt.cfg ├── q_matrix_mpeg2.cfg └── test_x264.py ├── version.sh ├── x264.c ├── x264.h ├── x264cli.h ├── x264dll.c └── x264res.rc /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.a 3 | *.diff 4 | *.orig 5 | *.rej 6 | *.dll* 7 | *.exe 8 | *.def 9 | *.lib 10 | *.pdb 11 | *.mo 12 | *.o 13 | *.patch 14 | *.pc 15 | *.pot 16 | *.so* 17 | *.dylib 18 | .*.swp 19 | .depend 20 | .DS_Store 21 | config.h 22 | config.mak 23 | config.log 24 | x264_config.h 25 | x264 26 | x262 27 | checkasm 28 | 29 | *.264 30 | *.h264 31 | *.2pass 32 | *.ffindex 33 | *.avs 34 | *.mkv 35 | *.flv 36 | *.mp4 37 | *.y4m 38 | *.yuv 39 | *.log 40 | *.mbtree 41 | *.temp 42 | *.pyc 43 | 44 | .digress_x264 45 | dataDec.txt 46 | log.dec 47 | common/oclobj.h 48 | x264_lookahead.clbin 49 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Contributors to x264 2 | # 3 | # The format of this file was inspired by the Linux kernel CREDITS file. 4 | # Authors are listed alphabetically. 5 | # 6 | # The fields are: name (N), email (E), web-address (W), CVS account login (C), 7 | # PGP key ID and fingerprint (P), description (D), and snail-mail address (S). 8 | 9 | N: Alex Izvorski 10 | E: aizvorski AT gmail DOT com 11 | D: x86 asm (sse2) 12 | 13 | N: Alex Wright 14 | E: alexw0885 AT gmail DOT com 15 | D: Motion estimation (subpel and mixed refs) 16 | D: B-RDO 17 | 18 | N: bobololo 19 | D: Avisynth input 20 | D: MP4 muxing 21 | 22 | N: Christian Heine 23 | E: sennindemokrit AT gmx DOT net 24 | D: x86 asm 25 | 26 | N: David Wolstencroft 27 | D: Altivec optimizations 28 | 29 | N: Eric Petit 30 | E: eric.petit AT lapsus DOT org 31 | C: titer 32 | D: Altivec asm 33 | D: BeOS and MacOS X ports. 34 | S: France 35 | 36 | N: Gabriel Bouvigne 37 | E: bouvigne AT mp3-tech DOT org 38 | D: 2pass VBV 39 | 40 | N: Guillaume Poirier 41 | E: gpoirier CHEZ mplayerhq POINT hu 42 | D: Altivec optimizations 43 | S: Brittany, France 44 | 45 | N: Henrik Gramner 46 | E: henrik AT gramner DOT com 47 | D: 4:2:2 chroma subsampling, x86 asm, Windows improvements, bugfixes 48 | S: Sweden 49 | 50 | N: Jason Garrett-Glaser 51 | E: darkshikari AT gmail DOT com 52 | D: x86 asm, 1pass VBV, adaptive quantization, inline asm 53 | D: various speed optimizations, bugfixes 54 | S: USA 55 | 56 | N: Laurent Aimar 57 | E: fenrir AT via.ecp DOT fr 58 | C: fenrir 59 | D: Intial import, former maintainer 60 | D: x86 asm (mmx/mmx2) 61 | S: France 62 | 63 | N: Loren Merritt 64 | E: lorenm AT u.washington DOT edu 65 | C: pengvado 66 | D: maintainer 67 | D: All areas of encoder analysis and algorithms 68 | D: Motion estimation, rate control, macroblock & frame decisions, RDO, etc. 69 | D: Multithreading 70 | D: x86 and x86_64 asm (mmx/mmx2/sse2) 71 | S: USA 72 | 73 | N: Mans Rullgard 74 | E: mru AT inprovide DOT com 75 | C: mru 76 | D: Rate control 77 | S: Southampton, UK 78 | 79 | N: Michael Niedermayer 80 | E: michaelni AT gmx DOT at 81 | D: Rate control 82 | 83 | N: Mike Matsnev 84 | E: mike AT po DOT cs DOT msu DOT su 85 | D: Matroska muxing 86 | 87 | N: Min Chen 88 | E: chenm001 AT 163 DOT com 89 | C: chenm001 90 | D: Win32/VC 6.0 port 91 | D: gcc asm to nasm conversion 92 | S: China 93 | 94 | N: Phil Jensen 95 | E: philj AT csufresno DOT edu 96 | D: SPARC asm 97 | 98 | N: Radek Czyz 99 | E: radoslaw AT syskin DOT cjb DOT net 100 | D: Cached motion compensation 101 | 102 | -------------------------------------------------------------------------------- /common/arm/asm.S: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * asm.S: arm utility macros 3 | ***************************************************************************** 4 | * Copyright (C) 2008-2014 x264 project 5 | * 6 | * Authors: Mans Rullgard 7 | * David Conrad 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #include "config.h" 28 | 29 | .syntax unified 30 | 31 | #ifdef PREFIX 32 | # define EXTERN_ASM _ 33 | #else 34 | # define EXTERN_ASM 35 | #endif 36 | 37 | #ifdef __ELF__ 38 | # define ELF 39 | #else 40 | # define ELF @ 41 | #endif 42 | 43 | .macro require8, val=1 44 | ELF .eabi_attribute 24, \val 45 | .endm 46 | 47 | .macro preserve8, val=1 48 | ELF .eabi_attribute 25, \val 49 | .endm 50 | 51 | .macro function name 52 | .global EXTERN_ASM\name 53 | .align 2 54 | EXTERN_ASM\name: 55 | ELF .hidden \name 56 | ELF .type \name, %function 57 | .func \name 58 | \name: 59 | .endm 60 | 61 | .macro movrel rd, val 62 | #if HAVE_ARMV6T2 && !defined(PIC) 63 | movw \rd, #:lower16:\val 64 | movt \rd, #:upper16:\val 65 | #else 66 | ldr \rd, =\val 67 | #endif 68 | .endm 69 | 70 | .macro movconst rd, val 71 | #if HAVE_ARMV6T2 72 | movw \rd, #:lower16:\val 73 | .if \val >> 16 74 | movt \rd, #:upper16:\val 75 | .endif 76 | #else 77 | ldr \rd, =\val 78 | #endif 79 | .endm 80 | 81 | #define FENC_STRIDE 16 82 | #define FDEC_STRIDE 32 83 | 84 | .macro HORIZ_ADD dest, a, b 85 | .ifnb \b 86 | vadd.u16 \a, \a, \b 87 | .endif 88 | vpaddl.u16 \a, \a 89 | vpaddl.u32 \dest, \a 90 | .endm 91 | 92 | .macro SUMSUB_AB sum, diff, a, b 93 | vadd.s16 \sum, \a, \b 94 | vsub.s16 \diff, \a, \b 95 | .endm 96 | 97 | .macro SUMSUB_ABCD s1, d1, s2, d2, a, b, c, d 98 | SUMSUB_AB \s1, \d1, \a, \b 99 | SUMSUB_AB \s2, \d2, \c, \d 100 | .endm 101 | 102 | .macro ABS2 a b 103 | vabs.s16 \a, \a 104 | vabs.s16 \b, \b 105 | .endm 106 | 107 | // dist = distance in elements (0 for vertical pass, 1/2 for horizontal passes) 108 | // op = sumsub/amax (sum and diff / maximum of absolutes) 109 | // d1/2 = destination registers 110 | // s1/2 = source registers 111 | .macro HADAMARD dist, op, d1, d2, s1, s2 112 | .if \dist == 1 113 | vtrn.16 \s1, \s2 114 | .else 115 | vtrn.32 \s1, \s2 116 | .endif 117 | .ifc \op, sumsub 118 | SUMSUB_AB \d1, \d2, \s1, \s2 119 | .else 120 | vabs.s16 \s1, \s1 121 | vabs.s16 \s2, \s2 122 | vmax.s16 \d1, \s1, \s2 123 | .endif 124 | .endm 125 | 126 | .macro TRANSPOSE8x8 r0 r1 r2 r3 r4 r5 r6 r7 127 | vtrn.32 \r0, \r4 128 | vtrn.32 \r1, \r5 129 | vtrn.32 \r2, \r6 130 | vtrn.32 \r3, \r7 131 | vtrn.16 \r0, \r2 132 | vtrn.16 \r1, \r3 133 | vtrn.16 \r4, \r6 134 | vtrn.16 \r5, \r7 135 | vtrn.8 \r0, \r1 136 | vtrn.8 \r2, \r3 137 | vtrn.8 \r4, \r5 138 | vtrn.8 \r6, \r7 139 | .endm 140 | 141 | .macro TRANSPOSE4x4 r0 r1 r2 r3 142 | vtrn.16 \r0, \r2 143 | vtrn.16 \r1, \r3 144 | vtrn.8 \r0, \r1 145 | vtrn.8 \r2, \r3 146 | .endm 147 | 148 | .macro TRANSPOSE4x4_16 d0 d1 d2 d3 149 | vtrn.32 \d0, \d2 150 | vtrn.32 \d1, \d3 151 | vtrn.16 \d0, \d1 152 | vtrn.16 \d2, \d3 153 | .endm 154 | -------------------------------------------------------------------------------- /common/arm/cpu-a.S: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * cpu-a.S: arm cpu detection 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "asm.S" 27 | 28 | .fpu neon 29 | .align 2 30 | 31 | // done in gas because .fpu neon overrides the refusal to assemble 32 | // instructions the selected -march/-mcpu doesn't support 33 | function x264_cpu_neon_test 34 | vadd.i16 q0, q0, q0 35 | bx lr 36 | .endfunc 37 | 38 | // return: 0 on success 39 | // 1 if counters were already enabled 40 | // 9 if lo-res counters were already enabled 41 | function x264_cpu_enable_armv7_counter 42 | mrc p15, 0, r2, c9, c12, 0 // read PMNC 43 | ands r0, r2, #1 44 | andne r0, r2, #9 45 | 46 | orr r2, r2, #1 // enable counters 47 | bic r2, r2, #8 // full resolution 48 | mcreq p15, 0, r2, c9, c12, 0 // write PMNC 49 | mov r2, #1 << 31 // enable cycle counter 50 | mcr p15, 0, r2, c9, c12, 1 // write CNTENS 51 | bx lr 52 | .endfunc 53 | 54 | function x264_cpu_disable_armv7_counter 55 | mrc p15, 0, r0, c9, c12, 0 // read PMNC 56 | bic r0, r0, #1 // disable counters 57 | mcr p15, 0, r0, c9, c12, 0 // write PMNC 58 | bx lr 59 | .endfunc 60 | 61 | 62 | .macro READ_TIME r 63 | mrc p15, 0, \r, c9, c13, 0 64 | .endm 65 | 66 | // return: 0 if transfers neon -> arm transfers take more than 10 cycles 67 | // nonzero otherwise 68 | function x264_cpu_fast_neon_mrc_test 69 | // check for user access to performance counters 70 | mrc p15, 0, r0, c9, c14, 0 71 | cmp r0, #0 72 | bxeq lr 73 | 74 | push {r4-r6,lr} 75 | bl x264_cpu_enable_armv7_counter 76 | ands r1, r0, #8 77 | mov r3, #0 78 | mov ip, #4 79 | mov r6, #4 80 | moveq r5, #1 81 | movne r5, #64 82 | 83 | average_loop: 84 | mov r4, r5 85 | READ_TIME r1 86 | 1: subs r4, r4, #1 87 | .rept 8 88 | vmov.u32 lr, d0[0] 89 | add lr, lr, lr 90 | .endr 91 | bgt 1b 92 | READ_TIME r2 93 | 94 | subs r6, r6, #1 95 | sub r2, r2, r1 96 | cmpgt r2, #30 << 3 // assume context switch if it took over 30 cycles 97 | addle r3, r3, r2 98 | subsle ip, ip, #1 99 | bgt average_loop 100 | 101 | // disable counters if we enabled them 102 | ands r0, r0, #1 103 | bleq x264_cpu_disable_armv7_counter 104 | 105 | lsr r0, r3, #5 106 | cmp r0, #10 107 | movgt r0, #0 108 | pop {r4-r6,pc} 109 | .endfunc 110 | -------------------------------------------------------------------------------- /common/arm/dct.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * dct.h: arm transform and zigzag 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_ARM_DCT_H 27 | #define X264_ARM_DCT_H 28 | 29 | void x264_dct4x4dc_neon( int16_t d[16] ); 30 | void x264_idct4x4dc_neon( int16_t d[16] ); 31 | 32 | void x264_sub4x4_dct_neon( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 ); 33 | void x264_sub8x8_dct_neon( int16_t dct[4][16], uint8_t *pix1, uint8_t *pix2 ); 34 | void x264_sub16x16_dct_neon( int16_t dct[16][16], uint8_t *pix1, uint8_t *pix2 ); 35 | 36 | void x264_add4x4_idct_neon( uint8_t *p_dst, int16_t dct[16] ); 37 | void x264_add8x8_idct_neon( uint8_t *p_dst, int16_t dct[4][16] ); 38 | void x264_add16x16_idct_neon( uint8_t *p_dst, int16_t dct[16][16] ); 39 | 40 | void x264_add8x8_idct_dc_neon( uint8_t *p_dst, int16_t dct[4] ); 41 | void x264_add16x16_idct_dc_neon( uint8_t *p_dst, int16_t dct[16] ); 42 | void x264_sub8x8_dct_dc_neon( int16_t dct[4], uint8_t *pix1, uint8_t *pix2 ); 43 | 44 | void x264_sub8x8_dct8_neon( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 ); 45 | void x264_sub16x16_dct8_neon( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 ); 46 | 47 | void x264_add8x8_idct8_neon( uint8_t *p_dst, int16_t dct[64] ); 48 | void x264_add16x16_idct8_neon( uint8_t *p_dst, int16_t dct[4][64] ); 49 | 50 | void x264_zigzag_scan_4x4_frame_neon( int16_t level[16], int16_t dct[16] ); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /common/arm/mc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * mc.h: arm motion compensation 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_ARM_MC_H 27 | #define X264_ARM_MC_H 28 | 29 | void x264_mc_init_arm( int cpu, x264_mc_functions_t *pf ); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /common/arm/pixel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * pixel.h: arm pixel metrics 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_ARM_PIXEL_H 27 | #define X264_ARM_PIXEL_H 28 | 29 | #define DECL_PIXELS( ret, name, suffix, args ) \ 30 | ret x264_pixel_##name##_16x16_##suffix args;\ 31 | ret x264_pixel_##name##_16x8_##suffix args;\ 32 | ret x264_pixel_##name##_8x16_##suffix args;\ 33 | ret x264_pixel_##name##_8x8_##suffix args;\ 34 | ret x264_pixel_##name##_8x4_##suffix args;\ 35 | ret x264_pixel_##name##_4x8_##suffix args;\ 36 | ret x264_pixel_##name##_4x4_##suffix args;\ 37 | 38 | #define DECL_X1( name, suffix ) \ 39 | DECL_PIXELS( int, name, suffix, ( uint8_t *, int, uint8_t *, int ) ) 40 | 41 | #define DECL_X4( name, suffix ) \ 42 | DECL_PIXELS( void, name##_x3, suffix, ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, intptr_t, int * ) )\ 43 | DECL_PIXELS( void, name##_x4, suffix, ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, intptr_t, int * ) ) 44 | 45 | int x264_pixel_sad_4x4_armv6( uint8_t *, intptr_t, uint8_t *, intptr_t ); 46 | int x264_pixel_sad_4x8_armv6( uint8_t *, intptr_t, uint8_t *, intptr_t ); 47 | 48 | DECL_X1( sad, neon ) 49 | DECL_X1( sad_aligned, neon ) 50 | DECL_X1( sad_aligned, neon_dual ) 51 | DECL_X4( sad, neon ) 52 | DECL_X1( satd, neon ) 53 | DECL_X1( ssd, neon ) 54 | 55 | int x264_pixel_sa8d_8x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t ); 56 | int x264_pixel_sa8d_16x16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t ); 57 | 58 | uint64_t x264_pixel_var_8x8_neon ( uint8_t *, intptr_t ); 59 | uint64_t x264_pixel_var_8x16_neon ( uint8_t *, intptr_t ); 60 | uint64_t x264_pixel_var_16x16_neon( uint8_t *, intptr_t ); 61 | int x264_pixel_var2_8x8_neon ( uint8_t *, intptr_t, uint8_t *, intptr_t, int * ); 62 | int x264_pixel_var2_8x16_neon( uint8_t *, intptr_t, uint8_t *, intptr_t, int * ); 63 | 64 | uint64_t x264_pixel_hadamard_ac_8x8_neon ( uint8_t *, intptr_t ); 65 | uint64_t x264_pixel_hadamard_ac_8x16_neon ( uint8_t *, intptr_t ); 66 | uint64_t x264_pixel_hadamard_ac_16x8_neon ( uint8_t *, intptr_t ); 67 | uint64_t x264_pixel_hadamard_ac_16x16_neon( uint8_t *, intptr_t ); 68 | 69 | void x264_pixel_ssim_4x4x2_core_neon( const uint8_t *, intptr_t, 70 | const uint8_t *, intptr_t, 71 | int sums[2][4] ); 72 | float x264_pixel_ssim_end4_neon( int sum0[5][4], int sum1[5][4], int width ); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /common/arm/predict-c.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * predict.c: arm intra prediction 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "common/common.h" 27 | #include "predict.h" 28 | #include "pixel.h" 29 | 30 | void x264_predict_4x4_dc_armv6( uint8_t *src ); 31 | void x264_predict_4x4_dc_top_neon( uint8_t *src ); 32 | void x264_predict_4x4_h_armv6( uint8_t *src ); 33 | void x264_predict_4x4_ddr_armv6( uint8_t *src ); 34 | void x264_predict_4x4_ddl_neon( uint8_t *src ); 35 | 36 | void x264_predict_8x8c_dc_neon( uint8_t *src ); 37 | void x264_predict_8x8c_dc_top_neon( uint8_t *src ); 38 | void x264_predict_8x8c_dc_left_neon( uint8_t *src ); 39 | void x264_predict_8x8c_h_neon( uint8_t *src ); 40 | void x264_predict_8x8c_v_neon( uint8_t *src ); 41 | void x264_predict_8x8c_p_neon( uint8_t *src ); 42 | 43 | void x264_predict_8x8_dc_neon( uint8_t *src, uint8_t edge[36] ); 44 | void x264_predict_8x8_ddl_neon( uint8_t *src, uint8_t edge[36] ); 45 | void x264_predict_8x8_ddr_neon( uint8_t *src, uint8_t edge[36] ); 46 | void x264_predict_8x8_vl_neon( uint8_t *src, uint8_t edge[36] ); 47 | void x264_predict_8x8_vr_neon( uint8_t *src, uint8_t edge[36] ); 48 | void x264_predict_8x8_v_neon( uint8_t *src, uint8_t edge[36] ); 49 | void x264_predict_8x8_h_neon( uint8_t *src, uint8_t edge[36] ); 50 | void x264_predict_8x8_hd_neon( uint8_t *src, uint8_t edge[36] ); 51 | void x264_predict_8x8_hu_neon( uint8_t *src, uint8_t edge[36] ); 52 | 53 | void x264_predict_16x16_dc_neon( uint8_t *src ); 54 | void x264_predict_16x16_dc_top_neon( uint8_t *src ); 55 | void x264_predict_16x16_dc_left_neon( uint8_t *src ); 56 | void x264_predict_16x16_h_neon( uint8_t *src ); 57 | void x264_predict_16x16_v_neon( uint8_t *src ); 58 | void x264_predict_16x16_p_neon( uint8_t *src ); 59 | 60 | void x264_predict_4x4_init_arm( int cpu, x264_predict_t pf[12] ) 61 | { 62 | if (!(cpu&X264_CPU_ARMV6)) 63 | return; 64 | 65 | #if !HIGH_BIT_DEPTH 66 | pf[I_PRED_4x4_H] = x264_predict_4x4_h_armv6; 67 | pf[I_PRED_4x4_DC] = x264_predict_4x4_dc_armv6; 68 | pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_armv6; 69 | 70 | if (!(cpu&X264_CPU_NEON)) 71 | return; 72 | 73 | pf[I_PRED_4x4_DC_TOP] = x264_predict_4x4_dc_top_neon; 74 | pf[I_PRED_4x4_DDL] = x264_predict_4x4_ddl_neon; 75 | #endif // !HIGH_BIT_DEPTH 76 | } 77 | 78 | void x264_predict_8x8c_init_arm( int cpu, x264_predict_t pf[7] ) 79 | { 80 | if (!(cpu&X264_CPU_NEON)) 81 | return; 82 | 83 | #if !HIGH_BIT_DEPTH 84 | pf[I_PRED_CHROMA_DC] = x264_predict_8x8c_dc_neon; 85 | pf[I_PRED_CHROMA_DC_TOP] = x264_predict_8x8c_dc_top_neon; 86 | pf[I_PRED_CHROMA_DC_LEFT] = x264_predict_8x8c_dc_left_neon; 87 | pf[I_PRED_CHROMA_H] = x264_predict_8x8c_h_neon; 88 | pf[I_PRED_CHROMA_V] = x264_predict_8x8c_v_neon; 89 | pf[I_PRED_CHROMA_P] = x264_predict_8x8c_p_neon; 90 | #endif // !HIGH_BIT_DEPTH 91 | } 92 | 93 | void x264_predict_8x8_init_arm( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ) 94 | { 95 | if (!(cpu&X264_CPU_NEON)) 96 | return; 97 | 98 | #if !HIGH_BIT_DEPTH 99 | pf[I_PRED_8x8_DDL] = x264_predict_8x8_ddl_neon; 100 | pf[I_PRED_8x8_DDR] = x264_predict_8x8_ddr_neon; 101 | pf[I_PRED_8x8_VL] = x264_predict_8x8_vl_neon; 102 | pf[I_PRED_8x8_VR] = x264_predict_8x8_vr_neon; 103 | pf[I_PRED_8x8_DC] = x264_predict_8x8_dc_neon; 104 | pf[I_PRED_8x8_H] = x264_predict_8x8_h_neon; 105 | pf[I_PRED_8x8_HD] = x264_predict_8x8_hd_neon; 106 | pf[I_PRED_8x8_HU] = x264_predict_8x8_hu_neon; 107 | pf[I_PRED_8x8_V] = x264_predict_8x8_v_neon; 108 | #endif // !HIGH_BIT_DEPTH 109 | } 110 | 111 | void x264_predict_16x16_init_arm( int cpu, x264_predict_t pf[7] ) 112 | { 113 | if (!(cpu&X264_CPU_NEON)) 114 | return; 115 | 116 | #if !HIGH_BIT_DEPTH 117 | pf[I_PRED_16x16_DC ] = x264_predict_16x16_dc_neon; 118 | pf[I_PRED_16x16_DC_TOP] = x264_predict_16x16_dc_top_neon; 119 | pf[I_PRED_16x16_DC_LEFT]= x264_predict_16x16_dc_left_neon; 120 | pf[I_PRED_16x16_H ] = x264_predict_16x16_h_neon; 121 | pf[I_PRED_16x16_V ] = x264_predict_16x16_v_neon; 122 | pf[I_PRED_16x16_P ] = x264_predict_16x16_p_neon; 123 | #endif // !HIGH_BIT_DEPTH 124 | } 125 | -------------------------------------------------------------------------------- /common/arm/predict.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * predict.h: arm intra prediction 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_ARM_PREDICT_H 27 | #define X264_ARM_PREDICT_H 28 | 29 | void x264_predict_8x8_v_neon( pixel *src, pixel edge[36] ); 30 | void x264_predict_8x8_h_neon( pixel *src, pixel edge[36] ); 31 | void x264_predict_8x8_dc_neon( pixel *src, pixel edge[36] ); 32 | void x264_predict_8x8c_dc_neon( pixel *src ); 33 | void x264_predict_8x8c_h_neon( pixel *src ); 34 | void x264_predict_8x8c_v_neon( pixel *src ); 35 | void x264_predict_16x16_v_neon( pixel *src ); 36 | void x264_predict_16x16_h_neon( pixel *src ); 37 | void x264_predict_16x16_dc_neon( pixel *src ); 38 | 39 | void x264_predict_4x4_init_arm( int cpu, x264_predict_t pf[12] ); 40 | void x264_predict_8x8_init_arm( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ); 41 | void x264_predict_8x8c_init_arm( int cpu, x264_predict_t pf[7] ); 42 | void x264_predict_16x16_init_arm( int cpu, x264_predict_t pf[7] ); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /common/arm/quant.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * quant.h: arm quantization and level-run 3 | ***************************************************************************** 4 | * Copyright (C) 2005-2014 x264 project 5 | * 6 | * Authors: David Conrad 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_ARM_QUANT_H 27 | #define X264_ARM_QUANT_H 28 | 29 | int x264_quant_2x2_dc_armv6( int16_t dct[4], int mf, int bias ); 30 | 31 | int x264_quant_2x2_dc_neon( int16_t dct[4], int mf, int bias ); 32 | int x264_quant_4x4_dc_neon( int16_t dct[16], int mf, int bias ); 33 | int x264_quant_4x4_neon( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] ); 34 | int x264_quant_4x4x4_neon( int16_t dct[4][16], uint16_t mf[16], uint16_t bias[16] ); 35 | int x264_quant_8x8_neon( int16_t dct[64], uint16_t mf[64], uint16_t bias[64] ); 36 | 37 | void x264_dequant_4x4_dc_neon( int16_t dct[16], int dequant_mf[6][16], int i_qp ); 38 | void x264_dequant_4x4_neon( int16_t dct[16], int dequant_mf[6][16], int i_qp ); 39 | void x264_dequant_8x8_neon( int16_t dct[64], int dequant_mf[6][64], int i_qp ); 40 | void x264_dequant_mpeg2_inter_neon( dctcoef dct[64], int dequant_mf[64] ); 41 | void x264_dequant_mpeg2_intra_neon( dctcoef dct[64], int dequant_mf[64], int precision ); 42 | 43 | int x264_coeff_last4_arm( int16_t * ); 44 | int x264_coeff_last15_neon( int16_t * ); 45 | int x264_coeff_last16_neon( int16_t * ); 46 | int x264_coeff_last64_neon( int16_t * ); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /common/cabac.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * cabac.h: arithmetic coder 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_CABAC_H 28 | #define X264_CABAC_H 29 | 30 | typedef struct 31 | { 32 | /* state */ 33 | int i_low; 34 | int i_range; 35 | 36 | /* bit stream */ 37 | int i_queue; //stored with an offset of -8 for faster asm 38 | int i_bytes_outstanding; 39 | 40 | uint8_t *p_start; 41 | uint8_t *p; 42 | uint8_t *p_end; 43 | 44 | /* aligned for memcpy_aligned starting here */ 45 | ALIGNED_16( int f8_bits_encoded ); // only if using x264_cabac_size_decision() 46 | 47 | /* context */ 48 | uint8_t state[1024]; 49 | 50 | /* for 16-byte alignment */ 51 | uint8_t padding[12]; 52 | } x264_cabac_t; 53 | 54 | extern const uint8_t x264_cabac_transition[128][2]; 55 | extern const uint16_t x264_cabac_entropy[128]; 56 | 57 | /* init the contexts given i_slice_type, the quantif and the model */ 58 | void x264_cabac_context_init( x264_t *h, x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model ); 59 | 60 | void x264_cabac_encode_init_core( x264_cabac_t *cb ); 61 | void x264_cabac_encode_init ( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end ); 62 | void x264_cabac_encode_decision_c( x264_cabac_t *cb, int i_ctx, int b ); 63 | void x264_cabac_encode_decision_asm( x264_cabac_t *cb, int i_ctx, int b ); 64 | void x264_cabac_encode_bypass_c( x264_cabac_t *cb, int b ); 65 | void x264_cabac_encode_bypass_asm( x264_cabac_t *cb, int b ); 66 | void x264_cabac_encode_terminal_c( x264_cabac_t *cb ); 67 | void x264_cabac_encode_terminal_asm( x264_cabac_t *cb ); 68 | void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val ); 69 | void x264_cabac_encode_flush( x264_t *h, x264_cabac_t *cb ); 70 | 71 | #if HAVE_MMX 72 | #define x264_cabac_encode_decision x264_cabac_encode_decision_asm 73 | #define x264_cabac_encode_bypass x264_cabac_encode_bypass_asm 74 | #define x264_cabac_encode_terminal x264_cabac_encode_terminal_asm 75 | #else 76 | #define x264_cabac_encode_decision x264_cabac_encode_decision_c 77 | #define x264_cabac_encode_bypass x264_cabac_encode_bypass_c 78 | #define x264_cabac_encode_terminal x264_cabac_encode_terminal_c 79 | #endif 80 | #define x264_cabac_encode_decision_noup x264_cabac_encode_decision 81 | 82 | static ALWAYS_INLINE int x264_cabac_pos( x264_cabac_t *cb ) 83 | { 84 | return (cb->p - cb->p_start + cb->i_bytes_outstanding) * 8 + cb->i_queue; 85 | } 86 | 87 | /* internal only. these don't write the bitstream, just calculate bit cost: */ 88 | 89 | static ALWAYS_INLINE void x264_cabac_size_decision( x264_cabac_t *cb, long i_ctx, long b ) 90 | { 91 | int i_state = cb->state[i_ctx]; 92 | cb->state[i_ctx] = x264_cabac_transition[i_state][b]; 93 | cb->f8_bits_encoded += x264_cabac_entropy[i_state^b]; 94 | } 95 | 96 | static ALWAYS_INLINE int x264_cabac_size_decision2( uint8_t *state, long b ) 97 | { 98 | int i_state = *state; 99 | *state = x264_cabac_transition[i_state][b]; 100 | return x264_cabac_entropy[i_state^b]; 101 | } 102 | 103 | static ALWAYS_INLINE void x264_cabac_size_decision_noup( x264_cabac_t *cb, long i_ctx, long b ) 104 | { 105 | int i_state = cb->state[i_ctx]; 106 | cb->f8_bits_encoded += x264_cabac_entropy[i_state^b]; 107 | } 108 | 109 | static ALWAYS_INLINE int x264_cabac_size_decision_noup2( uint8_t *state, long b ) 110 | { 111 | return x264_cabac_entropy[*state^b]; 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /common/cpu.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * cpu.h: cpu detection 3 | ***************************************************************************** 4 | * Copyright (C) 2004-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_CPU_H 27 | #define X264_CPU_H 28 | 29 | uint32_t x264_cpu_detect( void ); 30 | int x264_cpu_num_processors( void ); 31 | void x264_cpu_emms( void ); 32 | void x264_cpu_sfence( void ); 33 | #if HAVE_MMX 34 | /* There is no way to forbid the compiler from using float instructions 35 | * before the emms so miscompilation could theoretically occur in the 36 | * unlikely event that the compiler reorders emms and float instructions. */ 37 | #if HAVE_X86_INLINE_ASM 38 | /* Clobbering memory makes the compiler less likely to reorder code. */ 39 | #define x264_emms() asm volatile( "emms":::"memory","st","st(1)","st(2)", \ 40 | "st(3)","st(4)","st(5)","st(6)","st(7)" ) 41 | #else 42 | #define x264_emms() x264_cpu_emms() 43 | #endif 44 | #else 45 | #define x264_emms() 46 | #endif 47 | #define x264_sfence x264_cpu_sfence 48 | void x264_safe_intel_cpu_indicator_init( void ); 49 | 50 | /* kludge: 51 | * gcc can't give variables any greater alignment than the stack frame has. 52 | * We need 32 byte alignment for AVX2, so here we make sure that the stack is 53 | * aligned to 32 bytes. 54 | * gcc 4.2 introduced __attribute__((force_align_arg_pointer)) to fix this 55 | * problem, but I don't want to require such a new version. 56 | * aligning to 32 bytes only works if the compiler supports keeping that 57 | * alignment between functions (osdep.h handles manual alignment of arrays 58 | * if it doesn't). 59 | */ 60 | #if (ARCH_X86 || STACK_ALIGNMENT > 16) && HAVE_MMX 61 | intptr_t x264_stack_align( void (*func)(), ... ); 62 | #define x264_stack_align(func,...) x264_stack_align((void (*)())func, __VA_ARGS__) 63 | #else 64 | #define x264_stack_align(func,...) func(__VA_ARGS__) 65 | #endif 66 | 67 | typedef struct 68 | { 69 | const char name[16]; 70 | uint32_t flags; 71 | } x264_cpu_name_t; 72 | extern const x264_cpu_name_t x264_cpu_names[]; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /common/dct.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * dct.h: transform and zigzag 3 | ***************************************************************************** 4 | * Copyright (C) 2004-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_DCT_H 27 | #define X264_DCT_H 28 | 29 | extern const uint32_t x264_dct4_weight_tab[16]; 30 | extern const uint32_t x264_dct8_weight_tab[64]; 31 | extern const uint32_t x264_dct4_weight2_tab[16]; 32 | extern const uint32_t x264_dct8_weight2_tab[64]; 33 | 34 | extern const uint32_t x264_mpeg2_weight_tab[64]; 35 | extern const uint32_t x264_mpeg2_weight2_tab[64]; 36 | 37 | typedef struct 38 | { 39 | // pix1 stride = FENC_STRIDE 40 | // pix2 stride = FDEC_STRIDE 41 | // p_dst stride = FDEC_STRIDE 42 | void (*sub4x4_dct) ( dctcoef dct[16], pixel *pix1, pixel *pix2 ); 43 | void (*add4x4_idct) ( pixel *p_dst, dctcoef dct[16] ); 44 | 45 | void (*sub8x8_dct) ( dctcoef dct[4][16], pixel *pix1, pixel *pix2 ); 46 | void (*sub8x8_dct_dc)( dctcoef dct[4], pixel *pix1, pixel *pix2 ); 47 | void (*add8x8_idct) ( pixel *p_dst, dctcoef dct[4][16] ); 48 | void (*add8x8_idct_dc) ( pixel *p_dst, dctcoef dct[4] ); 49 | 50 | void (*sub8x16_dct_dc)( dctcoef dct[8], pixel *pix1, pixel *pix2 ); 51 | 52 | void (*sub16x16_dct) ( dctcoef dct[16][16], pixel *pix1, pixel *pix2 ); 53 | void (*add16x16_idct)( pixel *p_dst, dctcoef dct[16][16] ); 54 | void (*add16x16_idct_dc) ( pixel *p_dst, dctcoef dct[16] ); 55 | 56 | void (*sub8x8_dct8) ( dctcoef dct[64], pixel *pix1, pixel *pix2 ); 57 | void (*add8x8_idct8) ( pixel *p_dst, dctcoef dct[64] ); 58 | 59 | void (*sub16x16_dct8) ( dctcoef dct[4][64], pixel *pix1, pixel *pix2 ); 60 | void (*add16x16_idct8)( pixel *p_dst, dctcoef dct[4][64] ); 61 | 62 | void (*dct4x4dc) ( dctcoef d[16] ); 63 | void (*idct4x4dc)( dctcoef d[16] ); 64 | 65 | void (*dct2x4dc)( dctcoef dct[8], dctcoef dct4x4[8][16] ); 66 | 67 | } x264_dct_function_t; 68 | 69 | typedef struct 70 | { 71 | void (*scan_8x8)( dctcoef level[64], dctcoef dct[64] ); 72 | void (*scan_4x4)( dctcoef level[16], dctcoef dct[16] ); 73 | int (*sub_8x8) ( dctcoef level[64], const pixel *p_src, pixel *p_dst ); 74 | int (*sub_4x4) ( dctcoef level[16], const pixel *p_src, pixel *p_dst ); 75 | int (*sub_4x4ac)( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc ); 76 | void (*interleave_8x8_cavlc)( dctcoef *dst, dctcoef *src, uint8_t *nnz ); 77 | 78 | } x264_zigzag_function_t; 79 | 80 | void x264_dct_init( int cpu, x264_dct_function_t *dctf, int b_mpeg2 ); 81 | void x264_dct_init_weights( void ); 82 | void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf_progressive, x264_zigzag_function_t *pf_interlaced, int b_mpeg2 ); 83 | void zigzag_scan_8x8_cqm( uint8_t level[64], const uint8_t dct[64] ); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /common/opencl/downscale.cl: -------------------------------------------------------------------------------- 1 | /* 2 | * downscale lowres luma: full-res buffer to down scale image, and to packed hpel image 3 | * 4 | * -- 5 | * 6 | * fenc_img is an output image (area of memory referenced through a texture 7 | * cache). A read of any pixel location (x,y) returns four pixel values: 8 | * 9 | * val.s0 = P(x,y) 10 | * val.s1 = P(x+1,y) 11 | * val.s2 = P(x+2,y) 12 | * val.s3 = P(x+3,y) 13 | * 14 | * This is a 4x replication of the lowres pixels, a trade-off between memory 15 | * size and read latency. 16 | * 17 | * -- 18 | * 19 | * hpel_planes is an output image that contains the four HPEL planes used for 20 | * subpel refinement. A read of any pixel location (x,y) returns a UInt32 with 21 | * the four planar values C | V | H | F 22 | * 23 | * launch dimensions: [lowres-width, lowres-height] 24 | */ 25 | kernel void downscale_hpel( const global pixel *fenc, 26 | write_only image2d_t fenc_img, 27 | write_only image2d_t hpel_planes, 28 | int stride ) 29 | { 30 | int x = get_global_id( 0 ); 31 | int y = get_global_id( 1 ); 32 | uint4 values; 33 | 34 | fenc += y * stride * 2; 35 | const global pixel *src1 = fenc + stride; 36 | const global pixel *src2 = (y == get_global_size( 1 )-1) ? src1 : src1 + stride; 37 | int2 pos = (int2)(x, y); 38 | pixel right, left; 39 | 40 | right = rhadd( fenc[x*2], src1[x*2] ); 41 | left = rhadd( fenc[x*2+1], src1[x*2+1] ); 42 | values.s0 = rhadd( right, left ); // F 43 | 44 | right = rhadd( fenc[2*x+1], src1[2*x+1] ); 45 | left = rhadd( fenc[2*x+2], src1[2*x+2] ); 46 | values.s1 = rhadd( right, left ); // H 47 | 48 | right = rhadd( src1[2*x], src2[2*x] ); 49 | left = rhadd( src1[2*x+1], src2[2*x+1] ); 50 | values.s2 = rhadd( right, left ); // V 51 | 52 | right = rhadd( src1[2*x+1], src2[2*x+1] ); 53 | left = rhadd( src1[2*x+2], src2[2*x+2] ); 54 | values.s3 = rhadd( right, left ); // C 55 | 56 | uint4 val = (uint4) ((values.s3 & 0xff) << 24) | ((values.s2 & 0xff) << 16) | ((values.s1 & 0xff) << 8) | (values.s0 & 0xff); 57 | write_imageui( hpel_planes, pos, val ); 58 | 59 | x = select( x, x+1, x+1 < get_global_size( 0 ) ); 60 | right = rhadd( fenc[x*2], src1[x*2] ); 61 | left = rhadd( fenc[x*2+1], src1[x*2+1] ); 62 | values.s1 = rhadd( right, left ); 63 | 64 | x = select( x, x+1, x+1 < get_global_size( 0 ) ); 65 | right = rhadd( fenc[x*2], src1[x*2] ); 66 | left = rhadd( fenc[x*2+1], src1[x*2+1] ); 67 | values.s2 = rhadd( right, left ); 68 | 69 | x = select( x, x+1, x+1 < get_global_size( 0 ) ); 70 | right = rhadd( fenc[x*2], src1[x*2] ); 71 | left = rhadd( fenc[x*2+1], src1[x*2+1] ); 72 | values.s3 = rhadd( right, left ); 73 | 74 | write_imageui( fenc_img, pos, values ); 75 | } 76 | 77 | /* 78 | * downscale lowres hierarchical motion search image, copy from one image to 79 | * another decimated image. This kernel is called iteratively to generate all 80 | * of the downscales. 81 | * 82 | * launch dimensions: [lower_res width, lower_res height] 83 | */ 84 | kernel void downscale1( read_only image2d_t higher_res, write_only image2d_t lower_res ) 85 | { 86 | int x = get_global_id( 0 ); 87 | int y = get_global_id( 1 ); 88 | int2 pos = (int2)(x, y); 89 | int gs = get_global_size( 0 ); 90 | uint4 top, bot, values; 91 | top = read_imageui( higher_res, sampler, (int2)(x*2, 2*y) ); 92 | bot = read_imageui( higher_res, sampler, (int2)(x*2, 2*y+1) ); 93 | values.s0 = rhadd( rhadd( top.s0, bot.s0 ), rhadd( top.s1, bot.s1 ) ); 94 | 95 | /* these select statements appear redundant, and they should be, but tests break when 96 | * they are not here. I believe this was caused by a driver bug 97 | */ 98 | values.s1 = select( values.s0, rhadd( rhadd( top.s2, bot.s2 ), rhadd( top.s3, bot.s3 ) ), ( x + 1 < gs) ); 99 | top = read_imageui( higher_res, sampler, (int2)(x*2+4, 2*y) ); 100 | bot = read_imageui( higher_res, sampler, (int2)(x*2+4, 2*y+1) ); 101 | values.s2 = select( values.s1, rhadd( rhadd( top.s0, bot.s0 ), rhadd( top.s1, bot.s1 ) ), ( x + 2 < gs ) ); 102 | values.s3 = select( values.s2, rhadd( rhadd( top.s2, bot.s2 ), rhadd( top.s3, bot.s3 ) ), ( x + 3 < gs ) ); 103 | write_imageui( lower_res, pos, (uint4)(values) ); 104 | } 105 | 106 | /* 107 | * Second copy of downscale kernel, no differences. This is a (no perf loss) 108 | * workaround for a scheduling bug in current Tahiti drivers. This bug has 109 | * theoretically been fixed in the July 2012 driver release from AMD. 110 | */ 111 | kernel void downscale2( read_only image2d_t higher_res, write_only image2d_t lower_res ) 112 | { 113 | int x = get_global_id( 0 ); 114 | int y = get_global_id( 1 ); 115 | int2 pos = (int2)(x, y); 116 | int gs = get_global_size( 0 ); 117 | uint4 top, bot, values; 118 | top = read_imageui( higher_res, sampler, (int2)(x*2, 2*y) ); 119 | bot = read_imageui( higher_res, sampler, (int2)(x*2, 2*y+1) ); 120 | values.s0 = rhadd( rhadd( top.s0, bot.s0 ), rhadd( top.s1, bot.s1 ) ); 121 | 122 | // see comment in above function copy 123 | values.s1 = select( values.s0, rhadd( rhadd( top.s2, bot.s2 ), rhadd( top.s3, bot.s3 ) ), ( x + 1 < gs) ); 124 | top = read_imageui( higher_res, sampler, (int2)(x*2+4, 2*y) ); 125 | bot = read_imageui( higher_res, sampler, (int2)(x*2+4, 2*y+1) ); 126 | values.s2 = select( values.s1, rhadd( rhadd( top.s0, bot.s0 ), rhadd( top.s1, bot.s1 ) ), ( x + 2 < gs ) ); 127 | values.s3 = select( values.s2, rhadd( rhadd( top.s2, bot.s2 ), rhadd( top.s3, bot.s3 ) ), ( x + 3 < gs ) ); 128 | write_imageui( lower_res, pos, (uint4)(values) ); 129 | } 130 | 131 | /* OpenCL 1.2 finally added a memset command, but we're not targeting 1.2 */ 132 | kernel void memset_int16( global int16_t *buf, int16_t value ) 133 | { 134 | buf[get_global_id( 0 )] = value; 135 | } 136 | -------------------------------------------------------------------------------- /common/opencl/weightp.cl: -------------------------------------------------------------------------------- 1 | /* Weightp filter a downscaled image into a temporary output buffer. 2 | * This kernel is launched once for each scale. 3 | * 4 | * Launch dimensions: width x height (in pixels) 5 | */ 6 | kernel void weightp_scaled_images( read_only image2d_t in_plane, 7 | write_only image2d_t out_plane, 8 | uint offset, 9 | uint scale, 10 | uint denom ) 11 | { 12 | int gx = get_global_id( 0 ); 13 | int gy = get_global_id( 1 ); 14 | uint4 input_val; 15 | uint4 output_val; 16 | 17 | input_val = read_imageui( in_plane, sampler, (int2)(gx, gy)); 18 | output_val = (uint4)(offset) + ( ( ((uint4)(scale)) * input_val ) >> ((uint4)(denom)) ); 19 | write_imageui( out_plane, (int2)(gx, gy), output_val ); 20 | } 21 | 22 | /* Weightp filter for the half-pel interpolated image 23 | * 24 | * Launch dimensions: width x height (in pixels) 25 | */ 26 | kernel void weightp_hpel( read_only image2d_t in_plane, 27 | write_only image2d_t out_plane, 28 | uint offset, 29 | uint scale, 30 | uint denom ) 31 | { 32 | int gx = get_global_id( 0 ); 33 | int gy = get_global_id( 1 ); 34 | uint input_val; 35 | uint output_val; 36 | 37 | input_val = read_imageui( in_plane, sampler, (int2)(gx, gy)).s0; 38 | //Unpack 39 | uint4 temp; 40 | temp.s0 = input_val & 0x00ff; temp.s1 = (input_val >> 8) & 0x00ff; 41 | temp.s2 = (input_val >> 16) & 0x00ff; temp.s3 = (input_val >> 24) & 0x00ff; 42 | 43 | temp = (uint4)(offset) + ( ( ((uint4)(scale)) * temp ) >> ((uint4)(denom)) ); 44 | 45 | //Pack 46 | output_val = temp.s0 | (temp.s1 << 8) | (temp.s2 << 16) | (temp.s3 << 24); 47 | write_imageui( out_plane, (int2)(gx, gy), output_val ); 48 | } 49 | -------------------------------------------------------------------------------- /common/opencl/x264-cl.h: -------------------------------------------------------------------------------- 1 | #pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable 2 | 3 | constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; 4 | 5 | /* 7.18.1.1 Exact-width integer types */ 6 | typedef signed char int8_t; 7 | typedef unsigned char uint8_t; 8 | typedef short int16_t; 9 | typedef unsigned short uint16_t; 10 | typedef int int32_t; 11 | typedef unsigned uint32_t; 12 | 13 | typedef uint8_t pixel; 14 | typedef uint16_t sum_t; 15 | typedef uint32_t sum2_t; 16 | 17 | #define LOWRES_COST_MASK ((1<<14)-1) 18 | #define LOWRES_COST_SHIFT 14 19 | #define COST_MAX (1<<28) 20 | 21 | #define PIXEL_MAX 255 22 | #define BITS_PER_SUM (8 * sizeof(sum_t)) 23 | 24 | /* Constants for offsets into frame statistics buffer */ 25 | #define COST_EST 0 26 | #define COST_EST_AQ 1 27 | #define INTRA_MBS 2 28 | 29 | #define COPY2_IF_LT( x, y, a, b )\ 30 | if((y)<(x))\ 31 | {\ 32 | (x) = (y);\ 33 | (a) = (b);\ 34 | } 35 | 36 | constant int2 dia_offs[4] = 37 | { 38 | {0, -1}, {-1, 0}, {1, 0}, {0, 1}, 39 | }; 40 | 41 | inline pixel x264_clip_pixel( int x ) 42 | { 43 | return (pixel) clamp( x, (int) 0, (int) PIXEL_MAX ); 44 | } 45 | 46 | inline int2 x264_median_mv( short2 a, short2 b, short2 c ) 47 | { 48 | short2 t1 = min(a, b); 49 | short2 t2 = min(max(a, b), c); 50 | return convert_int2(max(t1, t2)); 51 | } 52 | 53 | inline sum2_t abs2( sum2_t a ) 54 | { 55 | sum2_t s = ((a >> (BITS_PER_SUM - 1)) & (((sum2_t)1 << BITS_PER_SUM) + 1)) * ((sum_t)-1); 56 | return (a + s) ^ s; 57 | } 58 | 59 | #define HADAMARD4( d0, d1, d2, d3, s0, s1, s2, s3 ) {\ 60 | sum2_t t0 = s0 + s1;\ 61 | sum2_t t1 = s0 - s1;\ 62 | sum2_t t2 = s2 + s3;\ 63 | sum2_t t3 = s2 - s3;\ 64 | d0 = t0 + t2;\ 65 | d2 = t0 - t2;\ 66 | d1 = t1 + t3;\ 67 | d3 = t1 - t3;\ 68 | } 69 | 70 | #define HADAMARD4V( d0, d1, d2, d3, s0, s1, s2, s3 ) {\ 71 | int2 t0 = s0 + s1;\ 72 | int2 t1 = s0 - s1;\ 73 | int2 t2 = s2 + s3;\ 74 | int2 t3 = s2 - s3;\ 75 | d0 = t0 + t2;\ 76 | d2 = t0 - t2;\ 77 | d1 = t1 + t3;\ 78 | d3 = t1 - t3;\ 79 | } 80 | 81 | #define SATD_C_8x4_Q( name, q1, q2 )\ 82 | int name( q1 pixel *pix1, int i_pix1, q2 pixel *pix2, int i_pix2 )\ 83 | {\ 84 | sum2_t tmp[4][4];\ 85 | sum2_t a0, a1, a2, a3;\ 86 | sum2_t sum = 0;\ 87 | for( int i = 0; i < 4; i++, pix1 += i_pix1, pix2 += i_pix2 )\ 88 | {\ 89 | a0 = (pix1[0] - pix2[0]) + ((sum2_t)(pix1[4] - pix2[4]) << BITS_PER_SUM);\ 90 | a1 = (pix1[1] - pix2[1]) + ((sum2_t)(pix1[5] - pix2[5]) << BITS_PER_SUM);\ 91 | a2 = (pix1[2] - pix2[2]) + ((sum2_t)(pix1[6] - pix2[6]) << BITS_PER_SUM);\ 92 | a3 = (pix1[3] - pix2[3]) + ((sum2_t)(pix1[7] - pix2[7]) << BITS_PER_SUM);\ 93 | HADAMARD4( tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], a0, a1, a2, a3 );\ 94 | }\ 95 | for( int i = 0; i < 4; i++ )\ 96 | {\ 97 | HADAMARD4( a0, a1, a2, a3, tmp[0][i], tmp[1][i], tmp[2][i], tmp[3][i] );\ 98 | sum += abs2( a0 ) + abs2( a1 ) + abs2( a2 ) + abs2( a3 );\ 99 | }\ 100 | return (((sum_t)sum) + (sum>>BITS_PER_SUM)) >> 1;\ 101 | } 102 | 103 | /* 104 | * Utility function to perform a parallel sum reduction of an array of integers 105 | */ 106 | int parallel_sum( int value, int x, volatile local int *array ) 107 | { 108 | array[x] = value; 109 | barrier( CLK_LOCAL_MEM_FENCE ); 110 | 111 | int dim = get_local_size( 0 ); 112 | 113 | while( dim > 1 ) 114 | { 115 | dim >>= 1; 116 | 117 | if( x < dim ) 118 | array[x] += array[x + dim]; 119 | 120 | if( dim > 32 ) 121 | barrier( CLK_LOCAL_MEM_FENCE ); 122 | } 123 | 124 | return array[0]; 125 | } 126 | 127 | int mv_cost( uint2 mvd ) 128 | { 129 | float2 mvdf = (float2)(mvd.x, mvd.y) + 1.0f; 130 | float2 cost = round( log2(mvdf) * 2.0f + 0.718f + (float2)(!!mvd.x, !!mvd.y) ); 131 | return (int) (cost.x + cost.y); 132 | } 133 | -------------------------------------------------------------------------------- /common/ppc/dct.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * dct.h: ppc transform and zigzag 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Eric Petit 7 | * Guillaume Poirier 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_PPC_DCT_H 28 | #define X264_PPC_DCT_H 29 | 30 | void x264_sub4x4_dct_altivec( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 ); 31 | void x264_sub8x8_dct_altivec( int16_t dct[4][16], uint8_t *pix1, uint8_t *pix2 ); 32 | void x264_sub16x16_dct_altivec( int16_t dct[16][16], uint8_t *pix1, uint8_t *pix2 ); 33 | 34 | void x264_add4x4_idct_altivec( uint8_t *p_dst, int16_t dct[16] ); 35 | void x264_add8x8_idct_altivec( uint8_t *p_dst, int16_t dct[4][16] ); 36 | void x264_add16x16_idct_altivec( uint8_t *p_dst, int16_t dct[16][16] ); 37 | 38 | void x264_sub8x8_dct8_altivec( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 ); 39 | void x264_sub16x16_dct8_altivec( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 ); 40 | 41 | void x264_add8x8_idct8_altivec( uint8_t *dst, int16_t dct[64] ); 42 | void x264_add16x16_idct8_altivec( uint8_t *dst, int16_t dct[4][64] ); 43 | 44 | void x264_zigzag_scan_4x4_frame_altivec( int16_t level[16], int16_t dct[16] ); 45 | void x264_zigzag_scan_4x4_field_altivec( int16_t level[16], int16_t dct[16] ); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /common/ppc/mc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * mc.h: ppc motion compensation 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Eric Petit 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_PPC_MC_H 27 | #define X264_PPC_MC_H 28 | 29 | void x264_mc_altivec_init( x264_mc_functions_t *pf ); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /common/ppc/pixel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * pixel.h: ppc pixel metrics 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Eric Petit 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_PPC_PIXEL_H 27 | #define X264_PPC_PIXEL_H 28 | 29 | void x264_pixel_altivec_init( x264_pixel_function_t *pixf ); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /common/ppc/predict.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * predict.h: ppc intra prediction 3 | ***************************************************************************** 4 | * Copyright (C) 2007-2014 x264 project 5 | * 6 | * Authors: Guillaume Poirier 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_PPC_PREDICT_H 27 | #define X264_PPC_PREDICT_H 28 | 29 | void x264_predict_16x16_init_altivec ( x264_predict_t pf[7] ); 30 | void x264_predict_8x8c_init_altivec( x264_predict_t pf[7] ); 31 | 32 | #endif /* X264_PPC_PREDICT_H */ 33 | -------------------------------------------------------------------------------- /common/ppc/quant.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * quant.c: ppc quantization 3 | ***************************************************************************** 4 | * Copyright (C) 2007-2014 x264 project 5 | * 6 | * Authors: Guillaume Poirier 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_PPC_QUANT_H 27 | #define X264_PPC_QUANT_H 28 | 29 | int x264_quant_4x4_altivec( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] ); 30 | int x264_quant_8x8_altivec( int16_t dct[64], uint16_t mf[64], uint16_t bias[64] ); 31 | 32 | int x264_quant_4x4_dc_altivec( int16_t dct[16], int mf, int bias ); 33 | int x264_quant_2x2_dc_altivec( int16_t dct[4], int mf, int bias ); 34 | 35 | void x264_dequant_4x4_altivec( int16_t dct[16], int dequant_mf[6][16], int i_qp ); 36 | void x264_dequant_8x8_altivec( int16_t dct[64], int dequant_mf[6][64], int i_qp ); 37 | #endif 38 | -------------------------------------------------------------------------------- /common/predict.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * predict.h: intra prediction 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_PREDICT_H 28 | #define X264_PREDICT_H 29 | 30 | typedef void (*x264_predict_t)( pixel *src ); 31 | typedef void (*x264_predict8x8_t)( pixel *src, pixel edge[36] ); 32 | typedef void (*x264_predict_8x8_filter_t) ( pixel *src, pixel edge[36], int i_neighbor, int i_filters ); 33 | typedef void (*x264_predict_mpeg2_t)( pixel* src, int predicted_dc ); 34 | 35 | enum intra_chroma_pred_e 36 | { 37 | I_PRED_CHROMA_DC = 0, 38 | I_PRED_CHROMA_H = 1, 39 | I_PRED_CHROMA_V = 2, 40 | I_PRED_CHROMA_P = 3, 41 | 42 | I_PRED_CHROMA_DC_LEFT = 4, 43 | I_PRED_CHROMA_DC_TOP = 5, 44 | I_PRED_CHROMA_DC_128 = 6 45 | }; 46 | static const uint8_t x264_mb_chroma_pred_mode_fix[7] = 47 | { 48 | I_PRED_CHROMA_DC, I_PRED_CHROMA_H, I_PRED_CHROMA_V, I_PRED_CHROMA_P, 49 | I_PRED_CHROMA_DC, I_PRED_CHROMA_DC,I_PRED_CHROMA_DC 50 | }; 51 | 52 | enum intra16x16_pred_e 53 | { 54 | I_PRED_16x16_V = 0, 55 | I_PRED_16x16_H = 1, 56 | I_PRED_16x16_DC = 2, 57 | I_PRED_16x16_P = 3, 58 | 59 | I_PRED_16x16_DC_LEFT = 4, 60 | I_PRED_16x16_DC_TOP = 5, 61 | I_PRED_16x16_DC_128 = 6, 62 | }; 63 | static const uint8_t x264_mb_pred_mode16x16_fix[7] = 64 | { 65 | I_PRED_16x16_V, I_PRED_16x16_H, I_PRED_16x16_DC, I_PRED_16x16_P, 66 | I_PRED_16x16_DC,I_PRED_16x16_DC,I_PRED_16x16_DC 67 | }; 68 | 69 | enum intra4x4_pred_e 70 | { 71 | I_PRED_4x4_V = 0, 72 | I_PRED_4x4_H = 1, 73 | I_PRED_4x4_DC = 2, 74 | I_PRED_4x4_DDL= 3, 75 | I_PRED_4x4_DDR= 4, 76 | I_PRED_4x4_VR = 5, 77 | I_PRED_4x4_HD = 6, 78 | I_PRED_4x4_VL = 7, 79 | I_PRED_4x4_HU = 8, 80 | 81 | I_PRED_4x4_DC_LEFT = 9, 82 | I_PRED_4x4_DC_TOP = 10, 83 | I_PRED_4x4_DC_128 = 11, 84 | }; 85 | static const int8_t x264_mb_pred_mode4x4_fix[13] = 86 | { 87 | -1, 88 | I_PRED_4x4_V, I_PRED_4x4_H, I_PRED_4x4_DC, 89 | I_PRED_4x4_DDL, I_PRED_4x4_DDR, I_PRED_4x4_VR, 90 | I_PRED_4x4_HD, I_PRED_4x4_VL, I_PRED_4x4_HU, 91 | I_PRED_4x4_DC, I_PRED_4x4_DC, I_PRED_4x4_DC 92 | }; 93 | #define x264_mb_pred_mode4x4_fix(t) x264_mb_pred_mode4x4_fix[(t)+1] 94 | 95 | /* must use the same numbering as intra4x4_pred_e */ 96 | enum intra8x8_pred_e 97 | { 98 | I_PRED_8x8_V = 0, 99 | I_PRED_8x8_H = 1, 100 | I_PRED_8x8_DC = 2, 101 | I_PRED_8x8_DDL= 3, 102 | I_PRED_8x8_DDR= 4, 103 | I_PRED_8x8_VR = 5, 104 | I_PRED_8x8_HD = 6, 105 | I_PRED_8x8_VL = 7, 106 | I_PRED_8x8_HU = 8, 107 | 108 | I_PRED_8x8_DC_LEFT = 9, 109 | I_PRED_8x8_DC_TOP = 10, 110 | I_PRED_8x8_DC_128 = 11, 111 | }; 112 | 113 | void x264_predict_8x8_dc_c ( pixel *src, pixel edge[36] ); 114 | void x264_predict_8x8_h_c ( pixel *src, pixel edge[36] ); 115 | void x264_predict_8x8_v_c ( pixel *src, pixel edge[36] ); 116 | void x264_predict_4x4_dc_c ( pixel *src ); 117 | void x264_predict_4x4_h_c ( pixel *src ); 118 | void x264_predict_4x4_v_c ( pixel *src ); 119 | void x264_predict_16x16_dc_c( pixel *src ); 120 | void x264_predict_16x16_h_c ( pixel *src ); 121 | void x264_predict_16x16_v_c ( pixel *src ); 122 | void x264_predict_16x16_p_c ( pixel *src ); 123 | void x264_predict_8x8c_dc_c ( pixel *src ); 124 | void x264_predict_8x8c_h_c ( pixel *src ); 125 | void x264_predict_8x8c_v_c ( pixel *src ); 126 | void x264_predict_8x8c_p_c ( pixel *src ); 127 | void x264_predict_8x16c_dc_c( pixel *src ); 128 | void x264_predict_8x16c_h_c ( pixel *src ); 129 | void x264_predict_8x16c_v_c ( pixel *src ); 130 | void x264_predict_8x16c_p_c ( pixel *src ); 131 | 132 | void x264_predict_16x16_init ( int cpu, x264_predict_t pf[7] ); 133 | void x264_predict_8x8c_init ( int cpu, x264_predict_t pf[7] ); 134 | void x264_predict_8x16c_init ( int cpu, x264_predict_t pf[7] ); 135 | void x264_predict_4x4_init ( int cpu, x264_predict_t pf[12] ); 136 | void x264_predict_8x8_init ( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ); 137 | 138 | /* MPEG-2 */ 139 | void x264_predict_8x8_mpeg2_init( int cpu, x264_predict_mpeg2_t *pf ); 140 | void x264_reset_intra_dc_mpeg2( x264_t *h ); 141 | void x264_reset_mv_predictor_mpeg2( x264_t *h ); 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /common/quant.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * quant.h: quantization and level-run 3 | ***************************************************************************** 4 | * Copyright (C) 2005-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Jason Garrett-Glaser 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_QUANT_H 28 | #define X264_QUANT_H 29 | 30 | typedef struct 31 | { 32 | int (*quant_8x8) ( dctcoef dct[64], udctcoef mf[64], udctcoef bias[64] ); 33 | int (*quant_4x4) ( dctcoef dct[16], udctcoef mf[16], udctcoef bias[16] ); 34 | int (*quant_4x4x4)( dctcoef dct[4][16], udctcoef mf[16], udctcoef bias[16] ); 35 | int (*quant_4x4_dc)( dctcoef dct[16], int mf, int bias ); 36 | int (*quant_2x2_dc)( dctcoef dct[4], int mf, int bias ); 37 | 38 | void (*dequant_8x8)( dctcoef dct[64], int dequant_mf[6][64], int i_qp ); 39 | void (*dequant_4x4)( dctcoef dct[16], int dequant_mf[6][16], int i_qp ); 40 | void (*dequant_4x4_dc)( dctcoef dct[16], int dequant_mf[6][16], int i_qp ); 41 | 42 | void (*idct_dequant_2x4_dc)( dctcoef dct[8], dctcoef dct4x4[8][16], int dequant_mf[6][16], int i_qp ); 43 | void (*idct_dequant_2x4_dconly)( dctcoef dct[8], int dequant_mf[6][16], int i_qp ); 44 | 45 | int (*optimize_chroma_2x2_dc)( dctcoef dct[4], int dequant_mf ); 46 | int (*optimize_chroma_2x4_dc)( dctcoef dct[8], int dequant_mf ); 47 | 48 | void (*denoise_dct)( dctcoef *dct, uint32_t *sum, udctcoef *offset, int size ); 49 | 50 | int (*decimate_score15)( dctcoef *dct ); 51 | int (*decimate_score16)( dctcoef *dct ); 52 | int (*decimate_score64)( dctcoef *dct ); 53 | int (*coeff_last[14])( dctcoef *dct ); 54 | int (*coeff_last4)( dctcoef *dct ); 55 | int (*coeff_last8)( dctcoef *dct ); 56 | int (*coeff_level_run[13])( dctcoef *dct, x264_run_level_t *runlevel ); 57 | int (*coeff_level_run4)( dctcoef *dct, x264_run_level_t *runlevel ); 58 | int (*coeff_level_run8)( dctcoef *dct, x264_run_level_t *runlevel ); 59 | 60 | void (*dequant_mpeg2_intra)( dctcoef dct[64], int dequant_mf[64], int precision ); 61 | void (*dequant_mpeg2_inter)( dctcoef dct[64], int dequant_mf[64] ); 62 | 63 | #define TRELLIS_PARAMS const int *unquant_mf, const uint8_t *zigzag, int lambda2,\ 64 | int last_nnz, dctcoef *coefs, dctcoef *quant_coefs, dctcoef *dct,\ 65 | uint8_t *cabac_state_sig, uint8_t *cabac_state_last,\ 66 | uint64_t level_state0, uint16_t level_state1 67 | int (*trellis_cabac_4x4)( TRELLIS_PARAMS, int b_ac ); 68 | int (*trellis_cabac_8x8)( TRELLIS_PARAMS, int b_interlaced ); 69 | int (*trellis_cabac_4x4_psy)( TRELLIS_PARAMS, int b_ac, dctcoef *fenc_dct, int psy_trellis ); 70 | int (*trellis_cabac_8x8_psy)( TRELLIS_PARAMS, int b_interlaced, dctcoef *fenc_dct, int psy_trellis ); 71 | int (*trellis_cabac_dc)( TRELLIS_PARAMS, int num_coefs ); 72 | int (*trellis_cabac_chroma_422_dc)( TRELLIS_PARAMS ); 73 | } x264_quant_function_t; 74 | 75 | void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /common/rectangle.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * rectangle.c: rectangle filling 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Jason Garrett-Glaser 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "common.h" 27 | 28 | #define CACHE_FUNC(name,size,width,height)\ 29 | static void x264_macroblock_cache_##name##_##width##_##height( void *target, uint32_t val )\ 30 | {\ 31 | x264_macroblock_cache_rect( target, width*size, height, size, val );\ 32 | } 33 | 34 | #define CACHE_FUNCS(name,size)\ 35 | CACHE_FUNC(name,size,4,4)\ 36 | CACHE_FUNC(name,size,2,4)\ 37 | CACHE_FUNC(name,size,4,2)\ 38 | CACHE_FUNC(name,size,2,2)\ 39 | CACHE_FUNC(name,size,2,1)\ 40 | CACHE_FUNC(name,size,1,2)\ 41 | CACHE_FUNC(name,size,1,1)\ 42 | void (*x264_cache_##name##_func_table[10])(void *, uint32_t) =\ 43 | {\ 44 | x264_macroblock_cache_##name##_1_1,\ 45 | x264_macroblock_cache_##name##_2_1,\ 46 | x264_macroblock_cache_##name##_1_2,\ 47 | x264_macroblock_cache_##name##_2_2,\ 48 | NULL,\ 49 | x264_macroblock_cache_##name##_4_2,\ 50 | NULL,\ 51 | x264_macroblock_cache_##name##_2_4,\ 52 | NULL,\ 53 | x264_macroblock_cache_##name##_4_4\ 54 | };\ 55 | 56 | CACHE_FUNCS(mv, 4) 57 | CACHE_FUNCS(mvd, 2) 58 | CACHE_FUNCS(ref, 1) 59 | -------------------------------------------------------------------------------- /common/sparc/pixel.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * pixel.h: sparc pixel metrics 3 | ***************************************************************************** 4 | * Copyright (C) 2005-2014 x264 project 5 | * 6 | * Authors: Phil Jensen 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_SPARC_PIXEL_H 27 | #define X264_SPARC_PIXEL_H 28 | 29 | int x264_pixel_sad_8x8_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t ); 30 | int x264_pixel_sad_8x16_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t ); 31 | int x264_pixel_sad_16x8_vis ( uint8_t *, intptr_t, uint8_t *, intptr_t ); 32 | int x264_pixel_sad_16x16_vis( uint8_t *, intptr_t, uint8_t *, intptr_t ); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /common/threadpool.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * threadpool.h: thread pooling 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_THREADPOOL_H 27 | #define X264_THREADPOOL_H 28 | 29 | typedef struct x264_threadpool_t x264_threadpool_t; 30 | 31 | #if HAVE_THREAD 32 | int x264_threadpool_init( x264_threadpool_t **p_pool, int threads, 33 | void (*init_func)(void *), void *init_arg ); 34 | void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg ); 35 | void *x264_threadpool_wait( x264_threadpool_t *pool, void *arg ); 36 | void x264_threadpool_delete( x264_threadpool_t *pool ); 37 | #else 38 | #define x264_threadpool_init(p,t,f,a) -1 39 | #define x264_threadpool_run(p,f,a) 40 | #define x264_threadpool_wait(p,a) NULL 41 | #define x264_threadpool_delete(p) 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /common/win32thread.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * win32thread.h: windows threading 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_WIN32THREAD_H 27 | #define X264_WIN32THREAD_H 28 | 29 | #include 30 | /* the following macro is used within x264 */ 31 | #undef ERROR 32 | 33 | typedef struct 34 | { 35 | void *handle; 36 | void *(*func)( void* arg ); 37 | void *arg; 38 | void **p_ret; 39 | void *ret; 40 | } x264_pthread_t; 41 | #define x264_pthread_attr_t int 42 | 43 | /* the conditional variable api for windows 6.0+ uses critical sections and not mutexes */ 44 | typedef CRITICAL_SECTION x264_pthread_mutex_t; 45 | #define X264_PTHREAD_MUTEX_INITIALIZER {0} 46 | #define x264_pthread_mutexattr_t int 47 | 48 | /* This is the CONDITIONAL_VARIABLE typedef for using Window's native conditional variables on kernels 6.0+. 49 | * MinGW does not currently have this typedef. */ 50 | typedef struct 51 | { 52 | void *ptr; 53 | } x264_pthread_cond_t; 54 | #define x264_pthread_condattr_t int 55 | 56 | int x264_pthread_create( x264_pthread_t *thread, const x264_pthread_attr_t *attr, 57 | void *(*start_routine)( void* ), void *arg ); 58 | int x264_pthread_join( x264_pthread_t thread, void **value_ptr ); 59 | 60 | int x264_pthread_mutex_init( x264_pthread_mutex_t *mutex, const x264_pthread_mutexattr_t *attr ); 61 | int x264_pthread_mutex_destroy( x264_pthread_mutex_t *mutex ); 62 | int x264_pthread_mutex_lock( x264_pthread_mutex_t *mutex ); 63 | int x264_pthread_mutex_unlock( x264_pthread_mutex_t *mutex ); 64 | 65 | int x264_pthread_cond_init( x264_pthread_cond_t *cond, const x264_pthread_condattr_t *attr ); 66 | int x264_pthread_cond_destroy( x264_pthread_cond_t *cond ); 67 | int x264_pthread_cond_broadcast( x264_pthread_cond_t *cond ); 68 | int x264_pthread_cond_wait( x264_pthread_cond_t *cond, x264_pthread_mutex_t *mutex ); 69 | int x264_pthread_cond_signal( x264_pthread_cond_t *cond ); 70 | 71 | #define x264_pthread_attr_init(a) 0 72 | #define x264_pthread_attr_destroy(a) 0 73 | 74 | int x264_win32_threading_init( void ); 75 | void x264_win32_threading_destroy( void ); 76 | 77 | int x264_pthread_num_processors_np( void ); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /common/x86/bitstream-a.asm: -------------------------------------------------------------------------------- 1 | ;***************************************************************************** 2 | ;* bitstream-a.asm: x86 bitstream functions 3 | ;***************************************************************************** 4 | ;* Copyright (C) 2010-2014 x264 project 5 | ;* 6 | ;* Authors: Jason Garrett-Glaser 7 | ;* Henrik Gramner 8 | ;* 9 | ;* This program is free software; you can redistribute it and/or modify 10 | ;* it under the terms of the GNU General Public License as published by 11 | ;* the Free Software Foundation; either version 2 of the License, or 12 | ;* (at your option) any later version. 13 | ;* 14 | ;* This program is distributed in the hope that it will be useful, 15 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;* GNU General Public License for more details. 18 | ;* 19 | ;* You should have received a copy of the GNU General Public License 20 | ;* along with this program; if not, write to the Free Software 21 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | ;* 23 | ;* This program is also available under a commercial proprietary license. 24 | ;* For more information, contact us at licensing@x264.com. 25 | ;***************************************************************************** 26 | 27 | %include "x86inc.asm" 28 | %include "x86util.asm" 29 | 30 | SECTION .text 31 | 32 | ;----------------------------------------------------------------------------- 33 | ; uint8_t *x264_nal_escape( uint8_t *dst, uint8_t *src, uint8_t *end ) 34 | ;----------------------------------------------------------------------------- 35 | %macro NAL_LOOP 2 36 | %%escape: 37 | ; Detect false positive to avoid unneccessary escape loop 38 | xor r3d, r3d 39 | cmp byte [r0+r1-1], 0 40 | setnz r3b 41 | xor k3, k4 42 | jnz .escape 43 | jmp %%continue 44 | ALIGN 16 45 | %1: 46 | mova [r0+r1+mmsize], m1 47 | pcmpeqb m1, m0 48 | mova [r0+r1], m2 49 | pcmpeqb m2, m0 50 | pmovmskb r3d, m1 51 | %2 m1, [r1+r2+3*mmsize] 52 | pmovmskb r4d, m2 53 | %2 m2, [r1+r2+2*mmsize] 54 | shl k3, mmsize 55 | or k3, k4 56 | lea k4, [2*r3+1] 57 | and k4, k3 58 | jnz %%escape 59 | %%continue: 60 | add r1, 2*mmsize 61 | jl %1 62 | %endmacro 63 | 64 | %macro NAL_ESCAPE 0 65 | %if mmsize == 32 66 | %xdefine k3 r3 67 | %xdefine k4 r4 68 | %else 69 | %xdefine k3 r3d 70 | %xdefine k4 r4d 71 | %endif 72 | 73 | cglobal nal_escape, 3,5 74 | movzx r3d, byte [r1] 75 | sub r1, r2 ; r1 = offset of current src pointer from end of src 76 | pxor m0, m0 77 | mov [r0], r3b 78 | sub r0, r1 ; r0 = projected end of dst, assuming no more escapes 79 | or r3d, 0xffffff00 ; ignore data before src 80 | 81 | ; Start off by jumping into the escape loop in case there's an escape at the start. 82 | ; And do a few more in scalar until dst is aligned. 83 | jmp .escape_loop 84 | 85 | %if mmsize == 16 86 | NAL_LOOP .loop_aligned, mova 87 | jmp .ret 88 | %endif 89 | NAL_LOOP .loop_unaligned, movu 90 | .ret: 91 | movifnidn rax, r0 92 | RET 93 | 94 | .escape: 95 | ; Skip bytes that are known to be valid 96 | and k4, k3 97 | tzcnt k4, k4 98 | xor r3d, r3d ; the last two bytes are known to be zero 99 | add r1, r4 100 | .escape_loop: 101 | inc r1 102 | jge .ret 103 | movzx r4d, byte [r1+r2] 104 | shl r3d, 8 105 | or r3d, r4d 106 | test r3d, 0xfffffc ; if the last two bytes are 0 and the current byte is <=3 107 | jz .add_escape_byte 108 | .escaped: 109 | lea r4d, [r0+r1] 110 | mov [r0+r1], r3b 111 | test r4d, mmsize-1 ; Do SIMD when dst is aligned 112 | jnz .escape_loop 113 | movu m1, [r1+r2+mmsize] 114 | movu m2, [r1+r2] 115 | %if mmsize == 16 116 | lea r4d, [r1+r2] 117 | test r4d, mmsize-1 118 | jz .loop_aligned 119 | %endif 120 | jmp .loop_unaligned 121 | 122 | .add_escape_byte: 123 | mov byte [r0+r1], 3 124 | inc r0 125 | or r3d, 0x0300 126 | jmp .escaped 127 | %endmacro 128 | 129 | INIT_MMX mmx2 130 | NAL_ESCAPE 131 | INIT_XMM sse2 132 | NAL_ESCAPE 133 | %if ARCH_X86_64 134 | INIT_YMM avx2 135 | NAL_ESCAPE 136 | %endif 137 | -------------------------------------------------------------------------------- /common/x86/const-a.asm: -------------------------------------------------------------------------------- 1 | ;***************************************************************************** 2 | ;* const-a.asm: x86 global constants 3 | ;***************************************************************************** 4 | ;* Copyright (C) 2010-2014 x264 project 5 | ;* 6 | ;* Authors: Loren Merritt 7 | ;* Jason Garrett-Glaser 8 | ;* 9 | ;* This program is free software; you can redistribute it and/or modify 10 | ;* it under the terms of the GNU General Public License as published by 11 | ;* the Free Software Foundation; either version 2 of the License, or 12 | ;* (at your option) any later version. 13 | ;* 14 | ;* This program is distributed in the hope that it will be useful, 15 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;* GNU General Public License for more details. 18 | ;* 19 | ;* You should have received a copy of the GNU General Public License 20 | ;* along with this program; if not, write to the Free Software 21 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | ;* 23 | ;* This program is also available under a commercial proprietary license. 24 | ;* For more information, contact us at licensing@x264.com. 25 | ;***************************************************************************** 26 | 27 | %include "x86inc.asm" 28 | 29 | SECTION_RODATA 32 30 | 31 | const pb_1, times 32 db 1 32 | const hsub_mul, times 16 db 1, -1 33 | const pw_1, times 16 dw 1 34 | const pw_16, times 16 dw 16 35 | const pw_32, times 16 dw 32 36 | const pw_512, times 16 dw 512 37 | const pw_00ff, times 16 dw 0x00ff 38 | const pw_pixel_max,times 16 dw ((1 << BIT_DEPTH)-1) 39 | const pw_0to15, dw 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 40 | const pd_1, times 8 dd 1 41 | const deinterleave_shufd, dd 0,4,1,5,2,6,3,7 42 | const pb_unpackbd1, times 2 db 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3 43 | const pb_unpackbd2, times 2 db 4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7 44 | 45 | const pb_01, times 8 db 0,1 46 | const pb_0, times 16 db 0 47 | const pb_a1, times 16 db 0xa1 48 | const pb_3, times 16 db 3 49 | const pb_shuf8x8c, db 0,0,0,0,2,2,2,2,4,4,4,4,6,6,6,6 50 | 51 | const pw_2, times 8 dw 2 52 | const pw_m2, times 8 dw -2 53 | const pw_4, times 8 dw 4 54 | const pw_8, times 8 dw 8 55 | const pw_64, times 8 dw 64 56 | const pw_256, times 8 dw 256 57 | const pw_32_0, times 4 dw 32, 58 | times 4 dw 0 59 | const pw_8000, times 8 dw 0x8000 60 | const pw_3fff, times 8 dw 0x3fff 61 | const pw_ppppmmmm, dw 1,1,1,1,-1,-1,-1,-1 62 | const pw_ppmmppmm, dw 1,1,-1,-1,1,1,-1,-1 63 | const pw_pmpmpmpm, dw 1,-1,1,-1,1,-1,1,-1 64 | const pw_pmmpzzzz, dw 1,-1,-1,1,0,0,0,0 65 | 66 | const pd_32, times 4 dd 32 67 | const pd_1024, times 4 dd 1024 68 | const pd_ffff, times 4 dd 0xffff 69 | const pw_ff00, times 8 dw 0xff00 70 | 71 | const popcnt_table 72 | %assign x 0 73 | %rep 256 74 | ; population count 75 | db ((x>>0)&1)+((x>>1)&1)+((x>>2)&1)+((x>>3)&1)+((x>>4)&1)+((x>>5)&1)+((x>>6)&1)+((x>>7)&1) 76 | %assign x x+1 77 | %endrep 78 | 79 | const sw_64, dd 64 80 | -------------------------------------------------------------------------------- /common/x86/cpu-a.asm: -------------------------------------------------------------------------------- 1 | ;***************************************************************************** 2 | ;* cpu-a.asm: x86 cpu utilities 3 | ;***************************************************************************** 4 | ;* Copyright (C) 2003-2014 x264 project 5 | ;* 6 | ;* Authors: Laurent Aimar 7 | ;* Loren Merritt 8 | ;* Jason Garrett-Glaser 9 | ;* 10 | ;* This program is free software; you can redistribute it and/or modify 11 | ;* it under the terms of the GNU General Public License as published by 12 | ;* the Free Software Foundation; either version 2 of the License, or 13 | ;* (at your option) any later version. 14 | ;* 15 | ;* This program is distributed in the hope that it will be useful, 16 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | ;* GNU General Public License for more details. 19 | ;* 20 | ;* You should have received a copy of the GNU General Public License 21 | ;* along with this program; if not, write to the Free Software 22 | ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 23 | ;* 24 | ;* This program is also available under a commercial proprietary license. 25 | ;* For more information, contact us at licensing@x264.com. 26 | ;***************************************************************************** 27 | 28 | %include "x86inc.asm" 29 | 30 | SECTION .text 31 | 32 | ;----------------------------------------------------------------------------- 33 | ; void cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx ) 34 | ;----------------------------------------------------------------------------- 35 | cglobal cpu_cpuid, 5,7 36 | push rbx 37 | push r4 38 | push r3 39 | push r2 40 | push r1 41 | mov eax, r0d 42 | xor ecx, ecx 43 | cpuid 44 | pop r4 45 | mov [r4], eax 46 | pop r4 47 | mov [r4], ebx 48 | pop r4 49 | mov [r4], ecx 50 | pop r4 51 | mov [r4], edx 52 | pop rbx 53 | RET 54 | 55 | ;----------------------------------------------------------------------------- 56 | ; void cpu_xgetbv( int op, int *eax, int *edx ) 57 | ;----------------------------------------------------------------------------- 58 | cglobal cpu_xgetbv, 3,7 59 | push r2 60 | push r1 61 | mov ecx, r0d 62 | xgetbv 63 | pop r4 64 | mov [r4], eax 65 | pop r4 66 | mov [r4], edx 67 | RET 68 | 69 | %if ARCH_X86_64 70 | 71 | ;----------------------------------------------------------------------------- 72 | ; void stack_align( void (*func)(void*), void *arg ); 73 | ;----------------------------------------------------------------------------- 74 | cglobal stack_align 75 | push rbp 76 | mov rbp, rsp 77 | %if WIN64 78 | sub rsp, 32 ; shadow space 79 | %endif 80 | and rsp, ~31 81 | mov rax, r0 82 | mov r0, r1 83 | mov r1, r2 84 | mov r2, r3 85 | call rax 86 | leave 87 | ret 88 | 89 | %else 90 | 91 | ;----------------------------------------------------------------------------- 92 | ; int cpu_cpuid_test( void ) 93 | ; return 0 if unsupported 94 | ;----------------------------------------------------------------------------- 95 | cglobal cpu_cpuid_test 96 | pushfd 97 | push ebx 98 | push ebp 99 | push esi 100 | push edi 101 | pushfd 102 | pop eax 103 | mov ebx, eax 104 | xor eax, 0x200000 105 | push eax 106 | popfd 107 | pushfd 108 | pop eax 109 | xor eax, ebx 110 | pop edi 111 | pop esi 112 | pop ebp 113 | pop ebx 114 | popfd 115 | ret 116 | 117 | cglobal stack_align 118 | push ebp 119 | mov ebp, esp 120 | sub esp, 12 121 | and esp, ~31 122 | mov ecx, [ebp+8] 123 | mov edx, [ebp+12] 124 | mov [esp], edx 125 | mov edx, [ebp+16] 126 | mov [esp+4], edx 127 | mov edx, [ebp+20] 128 | mov [esp+8], edx 129 | call ecx 130 | leave 131 | ret 132 | 133 | %endif 134 | 135 | ;----------------------------------------------------------------------------- 136 | ; void cpu_emms( void ) 137 | ;----------------------------------------------------------------------------- 138 | cglobal cpu_emms 139 | emms 140 | ret 141 | 142 | ;----------------------------------------------------------------------------- 143 | ; void cpu_sfence( void ) 144 | ;----------------------------------------------------------------------------- 145 | cglobal cpu_sfence 146 | sfence 147 | ret 148 | 149 | cextern intel_cpu_indicator_init 150 | 151 | ;----------------------------------------------------------------------------- 152 | ; void safe_intel_cpu_indicator_init( void ); 153 | ;----------------------------------------------------------------------------- 154 | cglobal safe_intel_cpu_indicator_init 155 | push r0 156 | push r1 157 | push r2 158 | push r3 159 | push r4 160 | push r5 161 | push r6 162 | %if ARCH_X86_64 163 | push r7 164 | push r8 165 | push r9 166 | push r10 167 | push r11 168 | push r12 169 | push r13 170 | push r14 171 | %endif 172 | push rbp 173 | mov rbp, rsp 174 | %if WIN64 175 | sub rsp, 32 ; shadow space 176 | %endif 177 | and rsp, ~31 178 | call intel_cpu_indicator_init 179 | leave 180 | %if ARCH_X86_64 181 | pop r14 182 | pop r13 183 | pop r12 184 | pop r11 185 | pop r10 186 | pop r9 187 | pop r8 188 | pop r7 189 | %endif 190 | pop r6 191 | pop r5 192 | pop r4 193 | pop r3 194 | pop r2 195 | pop r1 196 | pop r0 197 | ret 198 | -------------------------------------------------------------------------------- /common/x86/mc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * mc.h: x86 motion compensation 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_I386_MC_H 28 | #define X264_I386_MC_H 29 | 30 | void x264_mc_init_mmx( int cpu, x264_mc_functions_t *pf ); 31 | void x264_mc_init_mmx_mpeg2( int cpu, x264_mc_functions_t *pf ); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /doc/ratecontrol.txt: -------------------------------------------------------------------------------- 1 | A qualitative overview of x264's ratecontrol methods 2 | By Loren Merritt 3 | 4 | Historical note: 5 | This document is outdated, but a significant part of it is still accurate. Here are some important ways ratecontrol has changed since the authoring of this document: 6 | - By default, MB-tree is used instead of qcomp for weighting frame quality based on complexity. MB-tree is effectively a generalization of qcomp to the macroblock level. MB-tree also replaces the constant offsets for B-frame quantizers. The legacy algorithm is still available for low-latency applications. 7 | - Adaptive quantization is now used to distribute quality among each frame; frames are no longer constant quantizer, even if MB-tree is off. 8 | - VBV runs per-row rather than per-frame to improve accuracy. 9 | 10 | x264's ratecontrol is based on libavcodec's, and is mostly empirical. But I can retroactively propose the following theoretical points which underlie most of the algorithms: 11 | 12 | - You want the movie to be somewhere approaching constant quality. However, constant quality does not mean constant PSNR nor constant QP. Details are less noticeable in high-complexity or high-motion scenes, so you can get away with somewhat higher QP for the same perceived quality. 13 | - On the other hand, you get more quality per bit if you spend those bits in scenes where motion compensation works well: A given artifact may stick around several seconds in a low-motion scene, and you only have to fix it in one frame to improve the quality of the whole scene. 14 | - Both of the above are correlated with the number of bits it takes to encode a frame at a given QP. 15 | - Given one encoding of a frame, we can predict the number of bits needed to encode it at a different QP. This prediction gets less accurate if the QPs are far apart. 16 | - The importance of a frame depends on the number of other frames that are predicted from it. Hence I-frames get reduced QP depending on the number and complexity of following inter-frames, disposable B-frames get higher QP than P-frames, and referenced B-frames are between P-frames and disposable B-frames. 17 | 18 | 19 | The modes: 20 | 21 | 2pass: 22 | Given some data about each frame of a 1st pass (e.g. generated by 1pass ABR, below), we try to choose QPs to maximize quality while matching a specified total size. This is separated into 3 parts: 23 | (1) Before starting the 2nd pass, select the relative number of bits to allocate between frames. This pays no attention to the total size of the encode. The default formula, empirically selected to balance between the 1st 2 theoretical points, is "complexity ** 0.6", where complexity is defined to be the bit size of the frame at a constant QP (estimated from the 1st pass). 24 | (2) Scale the results of (1) to fill the requested total size. Optional: Impose VBV limitations. Due to nonlinearities in the frame size predictor and in VBV, this is an iterative process. 25 | (3) Now start encoding. After each frame, update future QPs to compensate for mispredictions in size. If the 2nd pass is consistently off from the predicted size (usually because we use slower compression options than the 1st pass), then we multiply all future frames' qscales by the reciprocal of the error. Additionally, there is a short-term compensation to prevent us from deviating too far from the desired size near the beginning (when we don't have much data for the global compensation) and near the end (when global doesn't have time to react). 26 | 27 | 1pass, average bitrate: 28 | The goal is the same as in 2pass, but here we don't have the benefit of a previous encode, so all ratecontrol must be done during the encode. 29 | (1) This is the same as in 2pass, except that instead of estimating complexity from a previous encode, we run a fast motion estimation algo over a half-resolution version of the frame, and use the SATD residuals (these are also used in the decision between P- and B-frames). Also, we don't know the size or complexity of the following GOP, so I-frame bonus is based on the past. 30 | (2) We don't know the complexities of future frames, so we can only scale based on the past. The scaling factor is chosen to be the one that would have resulted in the desired bitrate if it had been applied to all frames so far. 31 | (3) Overflow compensation is the same as in 2pass. By tuning the strength of compensation, you can get anywhere from near the quality of 2pass (but unpredictable size, like +- 10%) to reasonably strict filesize but lower quality. 32 | 33 | 1pass, constant bitrate (VBV compliant): 34 | (1) Same as ABR. 35 | (2) Scaling factor is based on a local average (dependent on VBV buffer size) instead of all past frames. 36 | (3) Overflow compensation is stricter, and has an additional term to hard limit the QPs if the VBV is near empty. Note that no hard limit is done for a full VBV, so CBR may use somewhat less than the requested bitrate. Note also that if a frame violates VBV constraints despite the best efforts of prediction, it is not re-encoded. 37 | 38 | 1pass, constant ratefactor: 39 | (1) Same as ABR. 40 | (2) The scaling factor is a constant based on the --crf argument. 41 | (3) No overflow compensation is done. 42 | 43 | constant quantizer: 44 | QPs are simply based on frame type. 45 | -------------------------------------------------------------------------------- /doc/regression_test.txt: -------------------------------------------------------------------------------- 1 | Here is one test method which checks that the encoder's 2 | view of decoded pictures in the same as the decoder's view. 3 | This ensures that there is no distortion besides what is 4 | inherently caused by compression. 5 | 6 | # Install and compile x264 : 7 | git clone git://git.videolan.org/x264.git x264 8 | cd x264 9 | ./configure 10 | make 11 | cd .. 12 | 13 | # Install and compile JM reference decoder : 14 | wget http://iphome.hhi.de/suehring/tml/download/jm17.2.zip 15 | unzip jm17.2.zip 16 | cd JM 17 | sh unixprep.sh 18 | cd ldecod 19 | make 20 | cd ../.. 21 | 22 | ./x264/x264 input.yuv --dump-yuv fdec.yuv -o output.h264 23 | ./JM/bin/ldecod.exe -i output.h264 -o ref.yuv 24 | diff ref.yuv fdec.yuv 25 | -------------------------------------------------------------------------------- /doc/standards.txt: -------------------------------------------------------------------------------- 1 | x264 is written in C. The particular variant of C is: intersection of C99 and gcc>=3.4. 2 | checkasm is written in gcc, with no attempt at compatibility with anything else. 3 | 4 | We make the following additional assumptions which are true of real systems but not guaranteed by C99: 5 | * Two's complement. 6 | * Signed right-shifts are sign-extended. 7 | * int is 32-bit or larger. 8 | 9 | x86-specific assumptions: 10 | * The stack is 16-byte aligned. We align it on entry to libx264 and on entry to any thread, but the compiler must preserve alignment after that. 11 | * We call emms before any float operation and before returning from libx264, not after each mmx operation. So bad things could happen if the compiler inserts float operations where they aren't expected. 12 | -------------------------------------------------------------------------------- /doc/threads.txt: -------------------------------------------------------------------------------- 1 | Historical notes: 2 | Slice-based threads was the original threading model of x264. It was replaced with frame-based threads in r607. This document was originally written at that time. Slice-based threading was brought back (as an optional mode) in r1364 for low-latency encoding. Furthermore, frame-based threading was modified significantly in r1246, with the addition of threaded lookahead. 3 | 4 | Old threading method: slice-based 5 | application calls x264 6 | x264 runs B-adapt and ratecontrol (serial) 7 | split frame into several slices, and spawn a thread for each slice 8 | wait until all threads are done 9 | deblock and hpel filter (serial) 10 | return to application 11 | In x264cli, there is one additional thread to decode the input. 12 | 13 | New threading method: frame-based 14 | application calls x264 15 | x264 requests a frame from lookahead, which runs B-adapt and ratecontrol parallel to the current thread, separated by a buffer of size sync-lookahead 16 | spawn a thread for this frame 17 | thread runs encode, deblock, hpel filter 18 | meanwhile x264 waits for the oldest thread to finish 19 | return to application, but the rest of the threads continue running in the background 20 | No additional threads are needed to decode the input, unless decoding is slower than slice+deblock+hpel, in which case an additional input thread would allow decoding in parallel. 21 | 22 | Penalties for slice-based threading: 23 | Each slice adds some bitrate (or equivalently reduces quality), for a variety of reasons: the slice header costs some bits, cabac contexts are reset, mvs and intra samples can't be predicted across the slice boundary. 24 | In CBR mode, multiple slices encode simultaneously, thus increasing the maximum misprediction possible with VBV. 25 | Some parts of the encoder are serial, so it doesn't scale well with lots of cpus. 26 | 27 | Some numbers on penalties for slicing: 28 | Tested at 720p with 45 slices (one per mb row) to maximize the total cost for easy measurement. Averaged over 4 movies at crf20 and crf30. Total cost: +30% bitrate at constant psnr. 29 | I enabled the various components of slicing one at a time, and measured the portion of that cost they contribute: 30 | * 34% intra prediction 31 | * 25% redundant slice headers, nal headers, and rounding to whole bytes 32 | * 16% mv prediction 33 | * 16% reset cabac contexts 34 | * 6% deblocking between slices (you don't strictly have to turn this off just for standard compliance, but you do if you want to use slices for decoder multithreading) 35 | * 2% cabac neighbors (cbp, skip, etc) 36 | The proportional cost of redundant headers should certainly depend on bitrate (since the header size is constant and everything else depends on bitrate). Deblocking should too (due to varing deblock strength). 37 | But none of the proportions should depend strongly on the number of slices: some are triggered per slice while some are triggered per macroblock-that's-on-the-edge-of-a-slice, but as long as there's no more than 1 slice per row, the relative frequency of those two conditions is determined solely by the image width. 38 | 39 | 40 | Penalties for frame-base threading: 41 | To allow encoding of multiple frames in parallel, we have to ensure that any given macroblock uses motion vectors only from pieces of the reference frames that have been encoded already. This is usually not noticeable, but can matter for very fast upward motion. 42 | We have to commit to one frame type before starting on the frame. Thus scenecut detection must run during the lowres pre-motion-estimation along with B-adapt, which makes it faster but less accurate than re-encoding the whole frame. 43 | Ratecontrol gets delayed feedback, since it has to plan frame N before frame N-1 finishes. 44 | 45 | Benchmarks: 46 | cpu: 8core Nehalem (2x E5520) 2.27GHz, hyperthreading disabled 47 | kernel: linux 2.6.34.7, 64-bit 48 | x264: r1732 b20059aa 49 | input: http://media.xiph.org/video/derf/y4m/1080p/park_joy_1080p.y4m 50 | 51 | NOTE: the "thread count" listed below does not count the lookahead thread, only encoding threads. This is why for "veryfast", the speedup for 2 and 3 threads exceeds the logical limit. 52 | 53 | threads speedup psnr 54 | slice frame slice frame 55 | x264 --preset veryfast --tune psnr --crf 30 56 | 1: 1.00x 1.00x +0.000 +0.000 57 | 2: 1.41x 2.29x -0.005 -0.002 58 | 3: 1.70x 3.65x -0.035 +0.000 59 | 4: 1.96x 3.97x -0.029 -0.001 60 | 5: 2.10x 3.98x -0.047 -0.002 61 | 6: 2.29x 3.97x -0.060 +0.001 62 | 7: 2.36x 3.98x -0.057 -0.001 63 | 8: 2.43x 3.98x -0.067 -0.001 64 | 9: 3.96x +0.000 65 | 10: 3.99x +0.000 66 | 11: 4.00x +0.001 67 | 12: 4.00x +0.001 68 | 69 | x264 --preset medium --tune psnr --crf 30 70 | 1: 1.00x 1.00x +0.000 +0.000 71 | 2: 1.54x 1.59x -0.002 -0.003 72 | 3: 2.01x 2.81x -0.005 +0.000 73 | 4: 2.51x 3.11x -0.009 +0.000 74 | 5: 2.89x 4.20x -0.012 -0.000 75 | 6: 3.27x 4.50x -0.016 -0.000 76 | 7: 3.58x 5.45x -0.019 -0.002 77 | 8: 3.79x 5.76x -0.015 -0.002 78 | 9: 6.49x -0.000 79 | 10: 6.64x -0.000 80 | 11: 6.94x +0.000 81 | 12: 6.96x +0.000 82 | 83 | x264 --preset slower --tune psnr --crf 30 84 | 1: 1.00x 1.00x +0.000 +0.000 85 | 2: 1.54x 1.83x +0.000 +0.002 86 | 3: 1.98x 2.21x -0.006 +0.002 87 | 4: 2.50x 2.61x -0.011 +0.002 88 | 5: 2.93x 3.94x -0.018 +0.003 89 | 6: 3.45x 4.19x -0.024 +0.001 90 | 7: 3.84x 4.52x -0.028 -0.001 91 | 8: 4.13x 5.04x -0.026 -0.001 92 | 9: 6.15x +0.001 93 | 10: 6.24x +0.001 94 | 11: 6.55x -0.001 95 | 12: 6.89x -0.001 96 | -------------------------------------------------------------------------------- /encoder/analyse.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * analyse.h: macroblock analysis 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_ANALYSE_H 28 | #define X264_ANALYSE_H 29 | 30 | float *x264_analyse_prepare_costs( x264_t *h ); 31 | int x264_analyse_init_costs( x264_t *h, float *logs, int qp ); 32 | void x264_analyse_free_costs( x264_t *h ); 33 | void x264_analyse_weight_frame( x264_t *h, int end ); 34 | void x264_macroblock_analyse( x264_t *h ); 35 | void x264_slicetype_decide( x264_t *h ); 36 | 37 | void x264_slicetype_analyse( x264_t *h, int intra_minigop ); 38 | 39 | int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w ); 40 | 41 | int x264_lookahead_init( x264_t *h, int i_slicetype_length ); 42 | int x264_lookahead_is_empty( x264_t *h ); 43 | void x264_lookahead_put_frame( x264_t *h, x264_frame_t *frame ); 44 | void x264_lookahead_get_frames( x264_t *h ); 45 | void x264_lookahead_delete( x264_t *h ); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /encoder/me.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * me.h: motion estimation 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_ME_H 28 | #define X264_ME_H 29 | 30 | #define COST_MAX (1<<28) 31 | #define COST_MAX64 (1ULL<<60) 32 | 33 | typedef struct 34 | { 35 | /* aligning the first member is a gcc hack to force the struct to be 36 | * 16 byte aligned, as well as force sizeof(struct) to be a multiple of 16 */ 37 | /* input */ 38 | ALIGNED_16( int i_pixel ); /* PIXEL_WxH */ 39 | uint16_t *p_cost_mv; /* lambda * nbits for each possible mv */ 40 | int i_ref_cost; 41 | int i_ref; 42 | const x264_weight_t *weight; 43 | 44 | pixel *p_fref[12]; 45 | pixel *p_fref_w; 46 | pixel *p_fenc[3]; 47 | uint16_t *integral; 48 | int i_stride[3]; 49 | 50 | ALIGNED_4( int16_t mvp[2] ); 51 | 52 | /* output */ 53 | int cost_mv; /* lambda * nbits for the chosen mv */ 54 | int cost; /* satd + lambda * nbits */ 55 | ALIGNED_4( int16_t mv[2] ); 56 | } ALIGNED_16( x264_me_t ); 57 | 58 | typedef struct 59 | { 60 | int sad; 61 | int16_t mv[2]; 62 | } mvsad_t; 63 | 64 | void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc, int *p_fullpel_thresh ); 65 | #define x264_me_search( h, m, mvc, i_mvc )\ 66 | x264_me_search_ref( h, m, mvc, i_mvc, NULL ) 67 | 68 | void x264_me_refine_qpel( x264_t *h, x264_me_t *m ); 69 | void x264_me_refine_qpel_refdupe( x264_t *h, x264_me_t *m, int *p_halfpel_thresh ); 70 | void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int i_list ); 71 | void x264_me_refine_bidir_rd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight, int i8, int i_lambda2 ); 72 | void x264_me_refine_bidir_satd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight ); 73 | uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i8, int i_pixel ); 74 | 75 | extern uint16_t *x264_cost_mv_fpel[QP_MAX+1][4]; 76 | 77 | #define COPY1_IF_LT(x,y)\ 78 | if((y)<(x))\ 79 | (x)=(y); 80 | 81 | #define COPY2_IF_LT(x,y,a,b)\ 82 | if((y)<(x))\ 83 | {\ 84 | (x)=(y);\ 85 | (a)=(b);\ 86 | } 87 | 88 | #define COPY3_IF_LT(x,y,a,b,c,d)\ 89 | if((y)<(x))\ 90 | {\ 91 | (x)=(y);\ 92 | (a)=(b);\ 93 | (c)=(d);\ 94 | } 95 | 96 | #define COPY4_IF_LT(x,y,a,b,c,d,e,f)\ 97 | if((y)<(x))\ 98 | {\ 99 | (x)=(y);\ 100 | (a)=(b);\ 101 | (c)=(d);\ 102 | (e)=(f);\ 103 | } 104 | 105 | #define COPY2_IF_GT(x,y,a,b)\ 106 | if((y)>(x))\ 107 | {\ 108 | (x)=(y);\ 109 | (a)=(b);\ 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /encoder/ratecontrol.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kierank/x262/bb887aa4c0a4da955524aa220b62998c3b50504e/encoder/ratecontrol.c -------------------------------------------------------------------------------- /encoder/ratecontrol.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * ratecontrol.h: ratecontrol 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Loren Merritt 7 | * Laurent Aimar 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_RATECONTROL_H 28 | #define X264_RATECONTROL_H 29 | 30 | /* Completely arbitrary. Ratecontrol lowers relative quality at higher framerates 31 | * and the reverse at lower framerates; this serves as the center of the curve. 32 | * Halve all the values for frame-packed 3D to compensate for the "doubled" 33 | * framerate. */ 34 | #define BASE_FRAME_DURATION (0.04f / ((h->param.i_frame_packing == 5)+1)) 35 | 36 | /* Arbitrary limitations as a sanity check. */ 37 | #define MAX_FRAME_DURATION (1.00f / ((h->param.i_frame_packing == 5)+1)) 38 | #define MIN_FRAME_DURATION (0.01f / ((h->param.i_frame_packing == 5)+1)) 39 | 40 | #define CLIP_DURATION(f) x264_clip3f(f,MIN_FRAME_DURATION,MAX_FRAME_DURATION) 41 | 42 | int x264_ratecontrol_new ( x264_t * ); 43 | void x264_ratecontrol_delete( x264_t * ); 44 | 45 | void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init ); 46 | int x264_encoder_reconfig_apply( x264_t *h, x264_param_t *param ); 47 | 48 | void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_offsets ); 49 | int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame, float *quant_offsets ); 50 | int x264_reference_build_list_optimal( x264_t *h ); 51 | void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next ); 52 | void x264_ratecontrol_start( x264_t *, int i_force_qp, int overhead ); 53 | int x264_ratecontrol_slice_type( x264_t *, int i_frame ); 54 | void x264_ratecontrol_set_weights( x264_t *h, x264_frame_t *frm ); 55 | int x264_ratecontrol_mb( x264_t *, int bits ); 56 | int x264_ratecontrol_qp( x264_t * ); 57 | int x264_ratecontrol_mb_qp( x264_t *h ); 58 | int x264_ratecontrol_end( x264_t *, int bits, int *filler ); 59 | void x264_ratecontrol_summary( x264_t * ); 60 | void x264_ratecontrol_set_estimated_size( x264_t *, int bits ); 61 | int x264_ratecontrol_get_estimated_size( x264_t const *); 62 | int x264_rc_analyse_slice( x264_t *h ); 63 | int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w ); 64 | void x264_threads_distribute_ratecontrol( x264_t *h ); 65 | void x264_threads_merge_ratecontrol( x264_t *h ); 66 | void x264_hrd_fullness( x264_t *h ); 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /encoder/set.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * set.h: header writing 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_ENCODER_SET_H 28 | #define X264_ENCODER_SET_H 29 | 30 | void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ); 31 | void x264_sps_write( bs_t *s, x264_sps_t *sps ); 32 | void x264_pps_init( x264_t *h, x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps ); 33 | void x264_pps_write( bs_t *s, x264_sps_t *sps, x264_pps_t *pps ); 34 | void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt ); 35 | int x264_sei_version_write( x264_t *h, bs_t *s ); 36 | int x264_validate_levels( x264_t *h, int verbose ); 37 | void x264_sei_buffering_period_write( x264_t *h, bs_t *s ); 38 | void x264_sei_pic_timing_write( x264_t *h, bs_t *s ); 39 | void x264_sei_dec_ref_pic_marking_write( x264_t *h, bs_t *s ); 40 | void x264_sei_frame_packing_write( x264_t *h, bs_t *s ); 41 | int x264_sei_avcintra_umid_write( x264_t *h, bs_t *s ); 42 | int x264_sei_avcintra_vanc_write( x264_t *h, bs_t *s, int len ); 43 | void x264_sei_write( bs_t *s, uint8_t *payload, int payload_size, int payload_type ); 44 | void x264_filler_write( x264_t *h, bs_t *s, int filler ); 45 | 46 | /* MPEG-2 */ 47 | void x264_seq_header_write_mpeg2( x264_t *h, bs_t *s ); 48 | void x264_seq_extension_write_mpeg2( x264_t *h, bs_t *s ); 49 | void x264_seq_disp_extension_write_mpeg2( x264_t *h, bs_t *s ); 50 | void x264_gop_header_write_mpeg2( x264_t *h, bs_t *s ); 51 | void x264_pic_header_write_mpeg2( x264_t *h, bs_t *s ); 52 | void x264_pic_coding_extension_write_mpeg2( x264_t *h, bs_t *s ); 53 | void x264_quant_matrix_extension_write_mpeg2( x264_t *h, bs_t *s ); 54 | void x264_pic_display_extension_write_mpeg2( x264_t *h, bs_t *s ); 55 | void x264_user_data_write_mpeg2( bs_t *s, uint8_t *payload, int payload_size ); 56 | 57 | extern const x264_fps_mpeg2_t x264_allowed_fps_mpeg2[14]; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /extras/windowsPorts/basicDataTypeConversions.h: -------------------------------------------------------------------------------- 1 | #ifndef __DATA_TYPE_CONVERSIONS_H__ 2 | #define __DATA_TYPE_CONVERSIONS_H__ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | namespace avxsynth { 9 | #endif // __cplusplus 10 | 11 | typedef int64_t __int64; 12 | typedef int32_t __int32; 13 | #ifdef __cplusplus 14 | typedef bool BOOL; 15 | #else 16 | typedef uint32_t BOOL; 17 | #endif // __cplusplus 18 | typedef void* HMODULE; 19 | typedef void* LPVOID; 20 | typedef void* PVOID; 21 | typedef PVOID HANDLE; 22 | typedef HANDLE HWND; 23 | typedef HANDLE HINSTANCE; 24 | typedef void* HDC; 25 | typedef void* HBITMAP; 26 | typedef void* HICON; 27 | typedef void* HFONT; 28 | typedef void* HGDIOBJ; 29 | typedef void* HBRUSH; 30 | typedef void* HMMIO; 31 | typedef void* HACMSTREAM; 32 | typedef void* HACMDRIVER; 33 | typedef void* HIC; 34 | typedef void* HACMOBJ; 35 | typedef HACMSTREAM* LPHACMSTREAM; 36 | typedef void* HACMDRIVERID; 37 | typedef void* LPHACMDRIVER; 38 | typedef unsigned char BYTE; 39 | typedef BYTE* LPBYTE; 40 | typedef char TCHAR; 41 | typedef TCHAR* LPTSTR; 42 | typedef const TCHAR* LPCTSTR; 43 | typedef char* LPSTR; 44 | typedef LPSTR LPOLESTR; 45 | typedef const char* LPCSTR; 46 | typedef LPCSTR LPCOLESTR; 47 | typedef wchar_t WCHAR; 48 | typedef unsigned short WORD; 49 | typedef unsigned int UINT; 50 | typedef UINT MMRESULT; 51 | typedef uint32_t DWORD; 52 | typedef DWORD COLORREF; 53 | typedef DWORD FOURCC; 54 | typedef DWORD HRESULT; 55 | typedef DWORD* LPDWORD; 56 | typedef DWORD* DWORD_PTR; 57 | typedef int32_t LONG; 58 | typedef int32_t* LONG_PTR; 59 | typedef LONG_PTR LRESULT; 60 | typedef uint32_t ULONG; 61 | typedef uint32_t* ULONG_PTR; 62 | //typedef __int64_t intptr_t; 63 | typedef uint64_t _fsize_t; 64 | 65 | 66 | // 67 | // Structures 68 | // 69 | 70 | typedef struct _GUID { 71 | DWORD Data1; 72 | WORD Data2; 73 | WORD Data3; 74 | BYTE Data4[8]; 75 | } GUID; 76 | 77 | typedef GUID REFIID; 78 | typedef GUID CLSID; 79 | typedef CLSID* LPCLSID; 80 | typedef GUID IID; 81 | 82 | #ifdef __cplusplus 83 | }; // namespace avxsynth 84 | #endif // __cplusplus 85 | #endif // __DATA_TYPE_CONVERSIONS_H__ 86 | -------------------------------------------------------------------------------- /extras/windowsPorts/windows2linux.h: -------------------------------------------------------------------------------- 1 | #ifndef __WINDOWS2LINUX_H__ 2 | #define __WINDOWS2LINUX_H__ 3 | 4 | /* 5 | * LINUX SPECIFIC DEFINITIONS 6 | */ 7 | // 8 | // Data types conversions 9 | // 10 | #include 11 | #include 12 | #include "basicDataTypeConversions.h" 13 | 14 | #ifdef __cplusplus 15 | namespace avxsynth { 16 | #endif // __cplusplus 17 | // 18 | // purposefully define the following MSFT definitions 19 | // to mean nothing (as they do not mean anything on Linux) 20 | // 21 | #define __stdcall 22 | #define __cdecl 23 | #define noreturn 24 | #define __declspec(x) 25 | #define STDAPI extern "C" HRESULT 26 | #define STDMETHODIMP HRESULT __stdcall 27 | #define STDMETHODIMP_(x) x __stdcall 28 | 29 | #define STDMETHOD(x) virtual HRESULT x 30 | #define STDMETHOD_(a, x) virtual a x 31 | 32 | #ifndef TRUE 33 | #define TRUE true 34 | #endif 35 | 36 | #ifndef FALSE 37 | #define FALSE false 38 | #endif 39 | 40 | #define S_OK (0x00000000) 41 | #define S_FALSE (0x00000001) 42 | #define E_NOINTERFACE (0X80004002) 43 | #define E_POINTER (0x80004003) 44 | #define E_FAIL (0x80004005) 45 | #define E_OUTOFMEMORY (0x8007000E) 46 | 47 | #define INVALID_HANDLE_VALUE ((HANDLE)((LONG_PTR)-1)) 48 | #define FAILED(hr) ((hr) & 0x80000000) 49 | #define SUCCEEDED(hr) (!FAILED(hr)) 50 | 51 | 52 | // 53 | // Functions 54 | // 55 | #define MAKEDWORD(a,b,c,d) ((a << 24) | (b << 16) | (c << 8) | (d)) 56 | #define MAKEWORD(a,b) ((a << 8) | (b)) 57 | 58 | #define lstrlen strlen 59 | #define lstrcpy strcpy 60 | #define lstrcmpi strcasecmp 61 | #define _stricmp strcasecmp 62 | #define InterlockedIncrement(x) __sync_fetch_and_add((x), 1) 63 | #define InterlockedDecrement(x) __sync_fetch_and_sub((x), 1) 64 | // Windows uses (new, old) ordering but GCC has (old, new) 65 | #define InterlockedCompareExchange(x,y,z) __sync_val_compare_and_swap(x,z,y) 66 | 67 | #define UInt32x32To64(a, b) ( (uint64_t) ( ((uint64_t)((uint32_t)(a))) * ((uint32_t)(b)) ) ) 68 | #define Int64ShrlMod32(a, b) ( (uint64_t) ( (uint64_t)(a) >> (b) ) ) 69 | #define Int32x32To64(a, b) ((__int64)(((__int64)((long)(a))) * ((long)(b)))) 70 | 71 | #define MulDiv(nNumber, nNumerator, nDenominator) (int32_t) (((int64_t) (nNumber) * (int64_t) (nNumerator) + (int64_t) ((nDenominator)/2)) / (int64_t) (nDenominator)) 72 | 73 | #ifdef __cplusplus 74 | }; // namespace avxsynth 75 | #endif // __cplusplus 76 | 77 | #endif // __WINDOWS2LINUX_H__ 78 | -------------------------------------------------------------------------------- /filters/filters.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * filters.h: common filter functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Diogo Franco 7 | * Steven Walters 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_FILTERS_H 28 | #define X264_FILTERS_H 29 | 30 | #include "x264cli.h" 31 | #include "filters/video/video.h" 32 | 33 | char **x264_split_string( char *string, char *sep, int limit ); 34 | void x264_free_string_array( char **array ); 35 | 36 | char **x264_split_options( const char *opt_str, const char *options[] ); 37 | char *x264_get_option( const char *name, char **split_options ); 38 | int x264_otob( char *str, int def ); // option to bool 39 | double x264_otof( char *str, double def ); // option to float/double 40 | int x264_otoi( char *str, int def ); // option to int 41 | char *x264_otos( char *str, char *def ); // option to string 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /filters/video/cache.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * cache.c: cache video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "video.h" 27 | #include "internal.h" 28 | #define NAME "cache" 29 | #define LAST_FRAME (h->first_frame + h->cur_size - 1) 30 | 31 | typedef struct 32 | { 33 | hnd_t prev_hnd; 34 | cli_vid_filter_t prev_filter; 35 | 36 | int max_size; 37 | int first_frame; /* first cached frame */ 38 | cli_pic_t **cache; 39 | int cur_size; 40 | int eof; /* frame beyond end of the file */ 41 | } cache_hnd_t; 42 | 43 | cli_vid_filter_t cache_filter; 44 | 45 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 46 | { 47 | intptr_t size = (intptr_t)opt_string; 48 | /* upon a <= 0 cache request, do nothing */ 49 | if( size <= 0 ) 50 | return 0; 51 | cache_hnd_t *h = calloc( 1, sizeof(cache_hnd_t) ); 52 | if( !h ) 53 | return -1; 54 | 55 | h->max_size = size; 56 | h->cache = malloc( (h->max_size+1) * sizeof(cli_pic_t*) ); 57 | if( !h->cache ) 58 | return -1; 59 | 60 | for( int i = 0; i < h->max_size; i++ ) 61 | { 62 | h->cache[i] = malloc( sizeof(cli_pic_t) ); 63 | if( !h->cache[i] || x264_cli_pic_alloc( h->cache[i], info->csp, info->width, info->height ) ) 64 | return -1; 65 | } 66 | h->cache[h->max_size] = NULL; /* require null terminator for list methods */ 67 | 68 | h->prev_filter = *filter; 69 | h->prev_hnd = *handle; 70 | *handle = h; 71 | *filter = cache_filter; 72 | 73 | return 0; 74 | } 75 | 76 | static void fill_cache( cache_hnd_t *h, int frame ) 77 | { 78 | /* shift frames out of the cache as the frame request is beyond the filled cache */ 79 | int shift = frame - LAST_FRAME; 80 | /* no frames to shift or no frames left to read */ 81 | if( shift <= 0 || h->eof ) 82 | return; 83 | /* the next frames to read are either 84 | * A) starting at the end of the current cache, or 85 | * B) starting at a new frame that has the end of the cache at the desired frame 86 | * and proceeding to fill the entire cache */ 87 | int cur_frame = X264_MAX( h->first_frame + h->cur_size, frame - h->max_size + 1 ); 88 | /* the new starting point is either 89 | * A) the current one shifted the number of frames entering/leaving the cache, or 90 | * B) at a new frame that has the end of the cache at the desired frame. */ 91 | h->first_frame = X264_MIN( h->first_frame + shift, cur_frame ); 92 | h->cur_size = X264_MAX( h->cur_size - shift, 0 ); 93 | while( h->cur_size < h->max_size ) 94 | { 95 | cli_pic_t temp; 96 | /* the old front frame is going to shift off, overwrite it with the new frame */ 97 | cli_pic_t *cache = h->cache[0]; 98 | if( h->prev_filter.get_frame( h->prev_hnd, &temp, cur_frame ) || 99 | x264_cli_pic_copy( cache, &temp ) || 100 | h->prev_filter.release_frame( h->prev_hnd, &temp, cur_frame ) ) 101 | { 102 | h->eof = cur_frame; 103 | return; 104 | } 105 | /* the read was successful, shift the frame off the front to the end */ 106 | x264_frame_push( (void*)h->cache, x264_frame_shift( (void*)h->cache ) ); 107 | cur_frame++; 108 | h->cur_size++; 109 | } 110 | } 111 | 112 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 113 | { 114 | cache_hnd_t *h = handle; 115 | FAIL_IF_ERR( frame < h->first_frame, NAME, "frame %d is before first cached frame %d \n", frame, h->first_frame ); 116 | fill_cache( h, frame ); 117 | if( frame > LAST_FRAME ) /* eof */ 118 | return -1; 119 | int idx = frame - (h->eof ? h->eof - h->max_size : h->first_frame); 120 | *output = *h->cache[idx]; 121 | return 0; 122 | } 123 | 124 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 125 | { 126 | /* the parent filter's frame has already been released so do nothing here */ 127 | return 0; 128 | } 129 | 130 | static void free_filter( hnd_t handle ) 131 | { 132 | cache_hnd_t *h = handle; 133 | h->prev_filter.free( h->prev_hnd ); 134 | for( int i = 0; i < h->max_size; i++ ) 135 | { 136 | x264_cli_pic_clean( h->cache[i] ); 137 | free( h->cache[i] ); 138 | } 139 | free( h->cache ); 140 | free( h ); 141 | } 142 | 143 | cli_vid_filter_t cache_filter = { NAME, NULL, init, get_frame, release_frame, free_filter, NULL }; 144 | -------------------------------------------------------------------------------- /filters/video/crop.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * crop.c: crop video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * James Darnley 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #include "video.h" 28 | #define NAME "crop" 29 | #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ ) 30 | 31 | cli_vid_filter_t crop_filter; 32 | 33 | typedef struct 34 | { 35 | hnd_t prev_hnd; 36 | cli_vid_filter_t prev_filter; 37 | 38 | int dims[4]; /* left, top, width, height */ 39 | const x264_cli_csp_t *csp; 40 | } crop_hnd_t; 41 | 42 | static void help( int longhelp ) 43 | { 44 | printf( " "NAME":left,top,right,bottom\n" ); 45 | if( !longhelp ) 46 | return; 47 | printf( " removes pixels from the edges of the frame\n" ); 48 | } 49 | 50 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 51 | { 52 | FAIL_IF_ERROR( x264_cli_csp_is_invalid( info->csp ), "invalid csp %d\n", info->csp ) 53 | crop_hnd_t *h = calloc( 1, sizeof(crop_hnd_t) ); 54 | if( !h ) 55 | return -1; 56 | 57 | h->csp = x264_cli_get_csp( info->csp ); 58 | static const char *optlist[] = { "left", "top", "right", "bottom", NULL }; 59 | char **opts = x264_split_options( opt_string, optlist ); 60 | if( !opts ) 61 | return -1; 62 | 63 | for( int i = 0; i < 4; i++ ) 64 | { 65 | char *opt = x264_get_option( optlist[i], opts ); 66 | FAIL_IF_ERROR( !opt, "%s crop value not specified\n", optlist[i] ) 67 | h->dims[i] = x264_otoi( opt, -1 ); 68 | FAIL_IF_ERROR( h->dims[i] < 0, "%s crop value `%s' is less than 0\n", optlist[i], opt ) 69 | int dim_mod = i&1 ? (h->csp->mod_height << info->interlaced) : h->csp->mod_width; 70 | FAIL_IF_ERROR( h->dims[i] % dim_mod, "%s crop value `%s' is not a multiple of %d\n", optlist[i], opt, dim_mod ) 71 | } 72 | x264_free_string_array( opts ); 73 | h->dims[2] = info->width - h->dims[0] - h->dims[2]; 74 | h->dims[3] = info->height - h->dims[1] - h->dims[3]; 75 | FAIL_IF_ERROR( h->dims[2] <= 0 || h->dims[3] <= 0, "invalid output resolution %dx%d\n", h->dims[2], h->dims[3] ) 76 | 77 | if( info->width != h->dims[2] || info->height != h->dims[3] ) 78 | x264_cli_log( NAME, X264_LOG_INFO, "cropping to %dx%d\n", h->dims[2], h->dims[3] ); 79 | else 80 | { 81 | /* do nothing as the user supplied 0s for all the values */ 82 | free( h ); 83 | return 0; 84 | } 85 | /* done initializing, overwrite values */ 86 | info->width = h->dims[2]; 87 | info->height = h->dims[3]; 88 | 89 | h->prev_filter = *filter; 90 | h->prev_hnd = *handle; 91 | *handle = h; 92 | *filter = crop_filter; 93 | 94 | return 0; 95 | } 96 | 97 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 98 | { 99 | crop_hnd_t *h = handle; 100 | if( h->prev_filter.get_frame( h->prev_hnd, output, frame ) ) 101 | return -1; 102 | output->img.width = h->dims[2]; 103 | output->img.height = h->dims[3]; 104 | /* shift the plane pointers down 'top' rows and right 'left' columns. */ 105 | for( int i = 0; i < output->img.planes; i++ ) 106 | { 107 | intptr_t offset = output->img.stride[i] * h->dims[1] * h->csp->height[i]; 108 | offset += h->dims[0] * h->csp->width[i] * x264_cli_csp_depth_factor( output->img.csp ); 109 | output->img.plane[i] += offset; 110 | } 111 | return 0; 112 | } 113 | 114 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 115 | { 116 | crop_hnd_t *h = handle; 117 | /* NO filter should ever have a dependent release based on the plane pointers, 118 | * so avoid unnecessary unshifting */ 119 | return h->prev_filter.release_frame( h->prev_hnd, pic, frame ); 120 | } 121 | 122 | static void free_filter( hnd_t handle ) 123 | { 124 | crop_hnd_t *h = handle; 125 | h->prev_filter.free( h->prev_hnd ); 126 | free( h ); 127 | } 128 | 129 | cli_vid_filter_t crop_filter = { NAME, help, init, get_frame, release_frame, free_filter, NULL }; 130 | -------------------------------------------------------------------------------- /filters/video/fix_vfr_pts.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * fix_vfr_pts.c: vfr pts fixing video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "video.h" 27 | #include "internal.h" 28 | 29 | /* This filter calculates and store the frame's duration to the frame data 30 | * (if it is not already calculated when the frame arrives to this point) 31 | * so it can be used by filters that will need to reconstruct pts due to 32 | * out-of-order frame requests */ 33 | 34 | typedef struct 35 | { 36 | hnd_t prev_hnd; 37 | cli_vid_filter_t prev_filter; 38 | 39 | /* we need 1 buffer picture and 1 place holder */ 40 | cli_pic_t buffer; 41 | cli_pic_t holder; 42 | int buffer_allocated; 43 | int holder_frame; 44 | int holder_ret; 45 | int64_t pts; 46 | int64_t last_duration; 47 | } fix_vfr_pts_hnd_t; 48 | 49 | cli_vid_filter_t fix_vfr_pts_filter; 50 | 51 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 52 | { 53 | /* if the input is not vfr, we don't do anything */ 54 | if( !info->vfr ) 55 | return 0; 56 | fix_vfr_pts_hnd_t *h = calloc( 1, sizeof(fix_vfr_pts_hnd_t) ); 57 | if( !h ) 58 | return -1; 59 | 60 | h->holder_frame = -1; 61 | h->prev_hnd = *handle; 62 | h->prev_filter = *filter; 63 | *handle = h; 64 | *filter = fix_vfr_pts_filter; 65 | 66 | return 0; 67 | } 68 | 69 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 70 | { 71 | fix_vfr_pts_hnd_t *h = handle; 72 | /* if we want the holder picture and it errored, return the error. */ 73 | if( frame == h->holder_frame ) 74 | { 75 | if( h->holder_ret ) 76 | return h->holder_ret; 77 | } 78 | else 79 | { 80 | /* if we have a holder frame and we don't want it, release the frame */ 81 | if( h->holder_frame > 0 && h->holder_frame < frame && h->prev_filter.release_frame( h->prev_hnd, &h->holder, h->holder_frame ) ) 82 | return -1; 83 | h->holder_frame = -1; 84 | if( h->prev_filter.get_frame( h->prev_hnd, &h->holder, frame ) ) 85 | return -1; 86 | } 87 | 88 | /* if the frame's duration is not set already, read the next frame to set it. */ 89 | if( !h->holder.duration ) 90 | { 91 | /* allocate a buffer picture if we didn't already */ 92 | if( !h->buffer_allocated ) 93 | { 94 | if( x264_cli_pic_alloc( &h->buffer, h->holder.img.csp, h->holder.img.width, h->holder.img.height ) ) 95 | return -1; 96 | h->buffer_allocated = 1; 97 | } 98 | h->holder_frame = frame+1; 99 | /* copy the current frame to the buffer, release it, and then read in the next frame to the placeholder */ 100 | if( x264_cli_pic_copy( &h->buffer, &h->holder ) || h->prev_filter.release_frame( h->prev_hnd, &h->holder, frame ) ) 101 | return -1; 102 | h->holder_ret = h->prev_filter.get_frame( h->prev_hnd, &h->holder, h->holder_frame ); 103 | /* suppress non-monotonic pts warnings by setting the duration to be at least 1 */ 104 | if( !h->holder_ret ) 105 | h->last_duration = X264_MAX( h->holder.pts - h->buffer.pts, 1 ); 106 | h->buffer.duration = h->last_duration; 107 | *output = h->buffer; 108 | } 109 | else 110 | *output = h->holder; 111 | 112 | output->pts = h->pts; 113 | h->pts += output->duration; 114 | 115 | return 0; 116 | } 117 | 118 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 119 | { 120 | fix_vfr_pts_hnd_t *h = handle; 121 | /* if the frame is the buffered one, it's already been released */ 122 | if( frame == (h->holder_frame - 1) ) 123 | return 0; 124 | return h->prev_filter.release_frame( h->prev_hnd, pic, frame ); 125 | } 126 | 127 | static void free_filter( hnd_t handle ) 128 | { 129 | fix_vfr_pts_hnd_t *h = handle; 130 | h->prev_filter.free( h->prev_hnd ); 131 | if( h->buffer_allocated ) 132 | x264_cli_pic_clean( &h->buffer ); 133 | free( h ); 134 | } 135 | 136 | cli_vid_filter_t fix_vfr_pts_filter = { "fix_vfr_pts", NULL, init, get_frame, release_frame, free_filter, NULL }; 137 | -------------------------------------------------------------------------------- /filters/video/internal.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * internal.c: video filter utilities 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "internal.h" 27 | #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "x264", __VA_ARGS__ ) 28 | 29 | void x264_cli_plane_copy( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int w, int h ) 30 | { 31 | while( h-- ) 32 | { 33 | memcpy( dst, src, w ); 34 | dst += i_dst; 35 | src += i_src; 36 | } 37 | } 38 | 39 | int x264_cli_pic_copy( cli_pic_t *out, cli_pic_t *in ) 40 | { 41 | int csp = in->img.csp & X264_CSP_MASK; 42 | FAIL_IF_ERROR( x264_cli_csp_is_invalid( in->img.csp ), "invalid colorspace arg %d\n", in->img.csp ) 43 | FAIL_IF_ERROR( in->img.csp != out->img.csp || in->img.height != out->img.height 44 | || in->img.width != out->img.width, "incompatible frame properties\n" ); 45 | /* copy data */ 46 | out->duration = in->duration; 47 | out->pts = in->pts; 48 | out->opaque = in->opaque; 49 | 50 | for( int i = 0; i < out->img.planes; i++ ) 51 | { 52 | int height = in->img.height * x264_cli_csps[csp].height[i]; 53 | int width = in->img.width * x264_cli_csps[csp].width[i]; 54 | width *= x264_cli_csp_depth_factor( in->img.csp ); 55 | x264_cli_plane_copy( out->img.plane[i], out->img.stride[i], in->img.plane[i], 56 | in->img.stride[i], width, height ); 57 | } 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /filters/video/internal.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * internal.h: video filter utilities 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_FILTER_VIDEO_INTERNAL_H 27 | #define X264_FILTER_VIDEO_INTERNAL_H 28 | #include "video.h" 29 | 30 | void x264_cli_plane_copy( uint8_t *dst, int i_dst, uint8_t *src, int i_src, int w, int h ); 31 | int x264_cli_pic_copy( cli_pic_t *out, cli_pic_t *in ); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /filters/video/select_every.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * select_every.c: select-every video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "video.h" 27 | #define NAME "select_every" 28 | #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ ) 29 | 30 | #define MAX_PATTERN_SIZE 100 /* arbitrary */ 31 | 32 | typedef struct 33 | { 34 | hnd_t prev_hnd; 35 | cli_vid_filter_t prev_filter; 36 | 37 | int *pattern; 38 | int pattern_len; 39 | int step_size; 40 | int vfr; 41 | int64_t pts; 42 | } selvry_hnd_t; 43 | 44 | cli_vid_filter_t select_every_filter; 45 | 46 | static void help( int longhelp ) 47 | { 48 | printf( " "NAME":step,offset1[,...]\n" ); 49 | if( !longhelp ) 50 | return; 51 | printf( " apply a selection pattern to input frames\n" 52 | " step: the number of frames in the pattern\n" 53 | " offsets: the offset into the step to select a frame\n" 54 | " see: http://avisynth.org/mediawiki/Select#SelectEvery\n" ); 55 | } 56 | 57 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 58 | { 59 | selvry_hnd_t *h = malloc( sizeof(selvry_hnd_t) ); 60 | if( !h ) 61 | return -1; 62 | h->pattern_len = 0; 63 | h->step_size = 0; 64 | int offsets[MAX_PATTERN_SIZE]; 65 | for( char *tok, *p = opt_string; (tok = strtok( p, "," )); p = NULL ) 66 | { 67 | int val = x264_otoi( tok, -1 ); 68 | if( p ) 69 | { 70 | FAIL_IF_ERROR( val <= 0, "invalid step `%s'\n", tok ) 71 | h->step_size = val; 72 | continue; 73 | } 74 | FAIL_IF_ERROR( val < 0 || val >= h->step_size, "invalid offset `%s'\n", tok ) 75 | FAIL_IF_ERROR( h->pattern_len >= MAX_PATTERN_SIZE, "max pattern size %d reached\n", MAX_PATTERN_SIZE ) 76 | offsets[h->pattern_len++] = val; 77 | } 78 | FAIL_IF_ERROR( !h->step_size, "no step size provided\n" ) 79 | FAIL_IF_ERROR( !h->pattern_len, "no offsets supplied\n" ) 80 | 81 | h->pattern = malloc( h->pattern_len * sizeof(int) ); 82 | if( !h->pattern ) 83 | return -1; 84 | memcpy( h->pattern, offsets, h->pattern_len * sizeof(int) ); 85 | 86 | /* determine required cache size to maintain pattern. */ 87 | intptr_t max_rewind = 0; 88 | int min = h->step_size; 89 | for( int i = h->pattern_len-1; i >= 0; i-- ) 90 | { 91 | min = X264_MIN( min, offsets[i] ); 92 | if( i ) 93 | max_rewind = X264_MAX( max_rewind, offsets[i-1] - min + 1 ); 94 | /* reached maximum rewind size */ 95 | if( max_rewind == h->step_size ) 96 | break; 97 | } 98 | if( x264_init_vid_filter( "cache", handle, filter, info, param, (void*)max_rewind ) ) 99 | return -1; 100 | 101 | /* done initing, overwrite properties */ 102 | if( h->step_size != h->pattern_len ) 103 | { 104 | info->num_frames = (uint64_t)info->num_frames * h->pattern_len / h->step_size; 105 | info->fps_den *= h->step_size; 106 | info->fps_num *= h->pattern_len; 107 | x264_reduce_fraction( &info->fps_num, &info->fps_den ); 108 | if( info->vfr ) 109 | { 110 | info->timebase_den *= h->pattern_len; 111 | info->timebase_num *= h->step_size; 112 | x264_reduce_fraction( &info->timebase_num, &info->timebase_den ); 113 | } 114 | } 115 | 116 | h->pts = 0; 117 | h->vfr = info->vfr; 118 | h->prev_filter = *filter; 119 | h->prev_hnd = *handle; 120 | *filter = select_every_filter; 121 | *handle = h; 122 | 123 | return 0; 124 | } 125 | 126 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 127 | { 128 | selvry_hnd_t *h = handle; 129 | int pat_frame = h->pattern[frame % h->pattern_len] + frame / h->pattern_len * h->step_size; 130 | if( h->prev_filter.get_frame( h->prev_hnd, output, pat_frame ) ) 131 | return -1; 132 | if( h->vfr ) 133 | { 134 | output->pts = h->pts; 135 | h->pts += output->duration; 136 | } 137 | return 0; 138 | } 139 | 140 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 141 | { 142 | selvry_hnd_t *h = handle; 143 | int pat_frame = h->pattern[frame % h->pattern_len] + frame / h->pattern_len * h->step_size; 144 | return h->prev_filter.release_frame( h->prev_hnd, pic, pat_frame ); 145 | } 146 | 147 | static void free_filter( hnd_t handle ) 148 | { 149 | selvry_hnd_t *h = handle; 150 | h->prev_filter.free( h->prev_hnd ); 151 | free( h->pattern ); 152 | free( h ); 153 | } 154 | 155 | cli_vid_filter_t select_every_filter = { NAME, help, init, get_frame, release_frame, free_filter, NULL }; 156 | -------------------------------------------------------------------------------- /filters/video/source.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * source.c: source video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "video.h" 27 | 28 | /* This filter converts the demuxer API into the filtering API for video frames. 29 | * Backseeking is prohibited here as not all demuxers are capable of doing so. */ 30 | 31 | typedef struct 32 | { 33 | cli_pic_t pic; 34 | hnd_t hin; 35 | int cur_frame; 36 | } source_hnd_t; 37 | 38 | cli_vid_filter_t source_filter; 39 | 40 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 41 | { 42 | source_hnd_t *h = calloc( 1, sizeof(source_hnd_t) ); 43 | if( !h ) 44 | return -1; 45 | h->cur_frame = -1; 46 | 47 | if( cli_input.picture_alloc( &h->pic, info->csp, info->width, info->height ) ) 48 | return -1; 49 | 50 | h->hin = *handle; 51 | *handle = h; 52 | *filter = source_filter; 53 | 54 | return 0; 55 | } 56 | 57 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 58 | { 59 | source_hnd_t *h = handle; 60 | /* do not allow requesting of frames from before the current position */ 61 | if( frame <= h->cur_frame || cli_input.read_frame( &h->pic, h->hin, frame ) ) 62 | return -1; 63 | h->cur_frame = frame; 64 | *output = h->pic; 65 | return 0; 66 | } 67 | 68 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 69 | { 70 | source_hnd_t *h = handle; 71 | if( cli_input.release_frame && cli_input.release_frame( &h->pic, h->hin ) ) 72 | return -1; 73 | return 0; 74 | } 75 | 76 | static void free_filter( hnd_t handle ) 77 | { 78 | source_hnd_t *h = handle; 79 | cli_input.picture_clean( &h->pic ); 80 | cli_input.close_file( h->hin ); 81 | free( h ); 82 | } 83 | 84 | cli_vid_filter_t source_filter = { "source", NULL, init, get_frame, release_frame, free_filter, NULL }; 85 | -------------------------------------------------------------------------------- /filters/video/video.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * video.c: video filters 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "video.h" 27 | 28 | static cli_vid_filter_t *first_filter = NULL; 29 | 30 | static void register_vid_filter( cli_vid_filter_t *new_filter ) 31 | { 32 | cli_vid_filter_t *filter_i = first_filter; 33 | while( filter_i->next ) 34 | filter_i = filter_i->next; 35 | filter_i->next = new_filter; 36 | new_filter->next = NULL; 37 | } 38 | 39 | #define REGISTER_VFILTER(name)\ 40 | {\ 41 | extern cli_vid_filter_t name##_filter;\ 42 | register_vid_filter( &name##_filter );\ 43 | } 44 | 45 | void x264_register_vid_filters( void ) 46 | { 47 | extern cli_vid_filter_t source_filter; 48 | first_filter = &source_filter; 49 | REGISTER_VFILTER( cache ); 50 | REGISTER_VFILTER( crop ); 51 | REGISTER_VFILTER( fix_vfr_pts ); 52 | REGISTER_VFILTER( resize ); 53 | REGISTER_VFILTER( select_every ); 54 | REGISTER_VFILTER( depth ); 55 | #if HAVE_GPL 56 | #endif 57 | } 58 | 59 | int x264_init_vid_filter( const char *name, hnd_t *handle, cli_vid_filter_t *filter, 60 | video_info_t *info, x264_param_t *param, char *opt_string ) 61 | { 62 | cli_vid_filter_t *filter_i = first_filter; 63 | while( filter_i && strcasecmp( name, filter_i->name ) ) 64 | filter_i = filter_i->next; 65 | FAIL_IF_ERR( !filter_i, "x264", "invalid filter `%s'\n", name ); 66 | if( filter_i->init( handle, filter, info, param, opt_string ) ) 67 | return -1; 68 | 69 | return 0; 70 | } 71 | 72 | void x264_vid_filter_help( int longhelp ) 73 | { 74 | for( cli_vid_filter_t *filter_i = first_filter; filter_i; filter_i = filter_i->next ) 75 | if( filter_i->help ) 76 | filter_i->help( longhelp ); 77 | } 78 | -------------------------------------------------------------------------------- /filters/video/video.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * video.h: video filters 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_FILTER_VIDEO_H 27 | #define X264_FILTER_VIDEO_H 28 | 29 | #include "input/input.h" 30 | #include "filters/filters.h" 31 | 32 | typedef struct cli_vid_filter_t cli_vid_filter_t; 33 | 34 | struct cli_vid_filter_t 35 | { 36 | /* name of the filter */ 37 | const char *name; 38 | /* help: a short message on what the filter does and how to use it. 39 | * this should only be implemented by filters directly accessible by the user */ 40 | void (*help)( int longhelp ); 41 | /* init: initializes the filter given the input clip properties and parameter to adjust them as necessary 42 | * with the given options provided by the user. 43 | * returns 0 on success, nonzero on error. */ 44 | int (*init)( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ); 45 | /* get_frame: given the storage for the output frame and desired frame number, generate the frame accordingly. 46 | * the image data returned by get_frame should be treated as const and not be altered. 47 | * returns 0 on success, nonzero on error. */ 48 | int (*get_frame)( hnd_t handle, cli_pic_t *output, int frame ); 49 | /* release_frame: frame is done being used and is signaled for cleanup. 50 | * returns 0 on succeess, nonzero on error. */ 51 | int (*release_frame)( hnd_t handle, cli_pic_t *pic, int frame ); 52 | /* free: run filter cleanup procedures. */ 53 | void (*free)( hnd_t handle ); 54 | /* next registered filter, unused by filters themselves */ 55 | cli_vid_filter_t *next; 56 | }; 57 | 58 | void x264_register_vid_filters( void ); 59 | void x264_vid_filter_help( int longhelp ); 60 | int x264_init_vid_filter( const char *name, hnd_t *handle, cli_vid_filter_t *filter, 61 | video_info_t *info, x264_param_t *param, char *opt_string ); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /input/input.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * input.c: common input functions 3 | ***************************************************************************** 4 | * Copyright (C) 2010-2014 x264 project 5 | * 6 | * Authors: Steven Walters 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "input.h" 27 | 28 | const x264_cli_csp_t x264_cli_csps[] = { 29 | [X264_CSP_I420] = { "i420", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 }, 30 | [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 }, 31 | [X264_CSP_I444] = { "i444", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 }, 32 | [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 }, 33 | [X264_CSP_YV16] = { "yv16", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 }, 34 | [X264_CSP_YV24] = { "yv24", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 }, 35 | [X264_CSP_NV12] = { "nv12", 2, { 1, 1 }, { 1, .5 }, 2, 2 }, 36 | [X264_CSP_NV16] = { "nv16", 2, { 1, 1 }, { 1, 1 }, 2, 1 }, 37 | [X264_CSP_BGR] = { "bgr", 1, { 3 }, { 1 }, 1, 1 }, 38 | [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, 1, 1 }, 39 | [X264_CSP_RGB] = { "rgb", 1, { 3 }, { 1 }, 1, 1 }, 40 | }; 41 | 42 | int x264_cli_csp_is_invalid( int csp ) 43 | { 44 | int csp_mask = csp & X264_CSP_MASK; 45 | return csp_mask <= X264_CSP_NONE || csp_mask >= X264_CSP_CLI_MAX || 46 | csp_mask == X264_CSP_V210 || csp & X264_CSP_OTHER; 47 | } 48 | 49 | int x264_cli_csp_depth_factor( int csp ) 50 | { 51 | if( x264_cli_csp_is_invalid( csp ) ) 52 | return 0; 53 | return (csp & X264_CSP_HIGH_DEPTH) ? 2 : 1; 54 | } 55 | 56 | uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane ) 57 | { 58 | int csp_mask = csp & X264_CSP_MASK; 59 | if( x264_cli_csp_is_invalid( csp ) || plane < 0 || plane >= x264_cli_csps[csp_mask].planes ) 60 | return 0; 61 | uint64_t size = (uint64_t)width * height; 62 | size *= x264_cli_csps[csp_mask].width[plane] * x264_cli_csps[csp_mask].height[plane]; 63 | size *= x264_cli_csp_depth_factor( csp ); 64 | return size; 65 | } 66 | 67 | uint64_t x264_cli_pic_size( int csp, int width, int height ) 68 | { 69 | if( x264_cli_csp_is_invalid( csp ) ) 70 | return 0; 71 | uint64_t size = 0; 72 | int csp_mask = csp & X264_CSP_MASK; 73 | for( int i = 0; i < x264_cli_csps[csp_mask].planes; i++ ) 74 | size += x264_cli_pic_plane_size( csp, width, height, i ); 75 | return size; 76 | } 77 | 78 | static int x264_cli_pic_alloc_internal( cli_pic_t *pic, int csp, int width, int height, int align ) 79 | { 80 | memset( pic, 0, sizeof(cli_pic_t) ); 81 | int csp_mask = csp & X264_CSP_MASK; 82 | if( x264_cli_csp_is_invalid( csp ) ) 83 | pic->img.planes = 0; 84 | else 85 | pic->img.planes = x264_cli_csps[csp_mask].planes; 86 | pic->img.csp = csp; 87 | pic->img.width = width; 88 | pic->img.height = height; 89 | for( int i = 0; i < pic->img.planes; i++ ) 90 | { 91 | int stride = width * x264_cli_csps[csp_mask].width[i]; 92 | stride *= x264_cli_csp_depth_factor( csp ); 93 | stride = ALIGN( stride, align ); 94 | uint64_t size = (uint64_t)(height * x264_cli_csps[csp_mask].height[i]) * stride; 95 | pic->img.plane[i] = x264_malloc( size ); 96 | if( !pic->img.plane[i] ) 97 | return -1; 98 | pic->img.stride[i] = stride; 99 | } 100 | 101 | return 0; 102 | } 103 | 104 | int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ) 105 | { 106 | return x264_cli_pic_alloc_internal( pic, csp, width, height, 1 ); 107 | } 108 | 109 | int x264_cli_pic_alloc_aligned( cli_pic_t *pic, int csp, int width, int height ) 110 | { 111 | return x264_cli_pic_alloc_internal( pic, csp, width, height, NATIVE_ALIGN ); 112 | } 113 | 114 | void x264_cli_pic_clean( cli_pic_t *pic ) 115 | { 116 | for( int i = 0; i < pic->img.planes; i++ ) 117 | x264_free( pic->img.plane[i] ); 118 | memset( pic, 0, sizeof(cli_pic_t) ); 119 | } 120 | 121 | const x264_cli_csp_t *x264_cli_get_csp( int csp ) 122 | { 123 | if( x264_cli_csp_is_invalid( csp ) ) 124 | return NULL; 125 | return x264_cli_csps + (csp&X264_CSP_MASK); 126 | } 127 | -------------------------------------------------------------------------------- /input/input.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * input.h: file input 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * Steven Walters 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 23 | * 24 | * This program is also available under a commercial proprietary license. 25 | * For more information, contact us at licensing@x264.com. 26 | *****************************************************************************/ 27 | 28 | #ifndef X264_INPUT_H 29 | #define X264_INPUT_H 30 | 31 | #include "x264cli.h" 32 | 33 | /* options that are used by only some demuxers */ 34 | typedef struct 35 | { 36 | char *index_file; 37 | char *format; 38 | char *resolution; 39 | char *colorspace; 40 | int bit_depth; 41 | char *timebase; 42 | int seek; 43 | int progress; 44 | int output_csp; /* convert to this csp, if applicable */ 45 | int output_range; /* user desired output range */ 46 | int input_range; /* user override input range */ 47 | } cli_input_opt_t; 48 | 49 | /* properties of the source given by the demuxer */ 50 | typedef struct 51 | { 52 | int csp; /* colorspace of the input */ 53 | uint32_t fps_num; 54 | uint32_t fps_den; 55 | int fullrange; /* has 2^bit_depth-1 instead of 219*2^(bit_depth-8) ranges (YUV only) */ 56 | int width; 57 | int height; 58 | int interlaced; 59 | int num_frames; 60 | uint32_t sar_width; 61 | uint32_t sar_height; 62 | int tff; 63 | int thread_safe; /* demuxer is thread_input safe */ 64 | uint32_t timebase_num; 65 | uint32_t timebase_den; 66 | int vfr; 67 | } video_info_t; 68 | 69 | /* image data type used by x264cli */ 70 | typedef struct 71 | { 72 | int csp; /* colorspace */ 73 | int width; /* width of the picture */ 74 | int height; /* height of the picture */ 75 | int planes; /* number of planes */ 76 | uint8_t *plane[4]; /* pointers for each plane */ 77 | int stride[4]; /* strides for each plane */ 78 | } cli_image_t; 79 | 80 | typedef struct 81 | { 82 | cli_image_t img; 83 | int64_t pts; /* input pts */ 84 | int64_t duration; /* frame duration - used for vfr */ 85 | void *opaque; /* opaque handle */ 86 | } cli_pic_t; 87 | 88 | typedef struct 89 | { 90 | int (*open_file)( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt ); 91 | int (*picture_alloc)( cli_pic_t *pic, int csp, int width, int height ); 92 | int (*read_frame)( cli_pic_t *pic, hnd_t handle, int i_frame ); 93 | int (*release_frame)( cli_pic_t *pic, hnd_t handle ); 94 | void (*picture_clean)( cli_pic_t *pic ); 95 | int (*close_file)( hnd_t handle ); 96 | } cli_input_t; 97 | 98 | extern const cli_input_t raw_input; 99 | extern const cli_input_t y4m_input; 100 | extern const cli_input_t avs_input; 101 | extern cli_input_t thread_input; 102 | extern const cli_input_t lavf_input; 103 | extern const cli_input_t ffms_input; 104 | extern cli_input_t timecode_input; 105 | 106 | extern cli_input_t cli_input; 107 | 108 | /* extended colorspace list that isn't supported by libx264 but by the cli */ 109 | #define X264_CSP_CLI_MAX X264_CSP_MAX /* end of list */ 110 | #define X264_CSP_OTHER 0x4000 /* non x264 colorspace */ 111 | 112 | typedef struct 113 | { 114 | const char *name; 115 | int planes; 116 | float width[4]; 117 | float height[4]; 118 | int mod_width; 119 | int mod_height; 120 | } x264_cli_csp_t; 121 | 122 | extern const x264_cli_csp_t x264_cli_csps[]; 123 | 124 | int x264_cli_csp_is_invalid( int csp ); 125 | int x264_cli_csp_depth_factor( int csp ); 126 | int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ); 127 | int x264_cli_pic_alloc_aligned( cli_pic_t *pic, int csp, int width, int height ); 128 | void x264_cli_pic_clean( cli_pic_t *pic ); 129 | uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane ); 130 | uint64_t x264_cli_pic_size( int csp, int width, int height ); 131 | const x264_cli_csp_t *x264_cli_get_csp( int csp ); 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /input/thread.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * thread.c: threaded input 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #include "input.h" 28 | 29 | typedef struct 30 | { 31 | cli_input_t input; 32 | hnd_t p_handle; 33 | cli_pic_t pic; 34 | x264_threadpool_t *pool; 35 | int next_frame; 36 | int frame_total; 37 | struct thread_input_arg_t *next_args; 38 | } thread_hnd_t; 39 | 40 | typedef struct thread_input_arg_t 41 | { 42 | thread_hnd_t *h; 43 | cli_pic_t *pic; 44 | int i_frame; 45 | int status; 46 | } thread_input_arg_t; 47 | 48 | static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt ) 49 | { 50 | thread_hnd_t *h = malloc( sizeof(thread_hnd_t) ); 51 | FAIL_IF_ERR( !h || cli_input.picture_alloc( &h->pic, info->csp, info->width, info->height ), 52 | "x264", "malloc failed\n" ) 53 | h->input = cli_input; 54 | h->p_handle = *p_handle; 55 | h->next_frame = -1; 56 | h->next_args = malloc( sizeof(thread_input_arg_t) ); 57 | if( !h->next_args ) 58 | return -1; 59 | h->next_args->h = h; 60 | h->next_args->status = 0; 61 | h->frame_total = info->num_frames; 62 | thread_input.picture_alloc = h->input.picture_alloc; 63 | thread_input.picture_clean = h->input.picture_clean; 64 | 65 | if( x264_threadpool_init( &h->pool, 1, NULL, NULL ) ) 66 | return -1; 67 | 68 | *p_handle = h; 69 | return 0; 70 | } 71 | 72 | static void read_frame_thread_int( thread_input_arg_t *i ) 73 | { 74 | i->status = i->h->input.read_frame( i->pic, i->h->p_handle, i->i_frame ); 75 | } 76 | 77 | static int read_frame( cli_pic_t *p_pic, hnd_t handle, int i_frame ) 78 | { 79 | thread_hnd_t *h = handle; 80 | int ret = 0; 81 | 82 | if( h->next_frame >= 0 ) 83 | { 84 | x264_threadpool_wait( h->pool, h->next_args ); 85 | ret |= h->next_args->status; 86 | } 87 | 88 | if( h->next_frame == i_frame ) 89 | XCHG( cli_pic_t, *p_pic, h->pic ); 90 | else 91 | ret |= h->input.read_frame( p_pic, h->p_handle, i_frame ); 92 | 93 | if( !h->frame_total || i_frame+1 < h->frame_total ) 94 | { 95 | h->next_frame = 96 | h->next_args->i_frame = i_frame+1; 97 | h->next_args->pic = &h->pic; 98 | x264_threadpool_run( h->pool, (void*)read_frame_thread_int, h->next_args ); 99 | } 100 | else 101 | h->next_frame = -1; 102 | 103 | return ret; 104 | } 105 | 106 | static int release_frame( cli_pic_t *pic, hnd_t handle ) 107 | { 108 | thread_hnd_t *h = handle; 109 | if( h->input.release_frame ) 110 | return h->input.release_frame( pic, h->p_handle ); 111 | return 0; 112 | } 113 | 114 | static int close_file( hnd_t handle ) 115 | { 116 | thread_hnd_t *h = handle; 117 | x264_threadpool_delete( h->pool ); 118 | h->input.close_file( h->p_handle ); 119 | h->input.picture_clean( &h->pic ); 120 | free( h->next_args ); 121 | free( h ); 122 | return 0; 123 | } 124 | 125 | cli_input_t thread_input = { open_file, NULL, read_frame, release_frame, NULL, close_file }; 126 | -------------------------------------------------------------------------------- /output/flv_bytestream.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * flv_bytestream.c: flv muxer utilities 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "output.h" 27 | #include "flv_bytestream.h" 28 | 29 | uint64_t flv_dbl2int( double value ) 30 | { 31 | return (union {double f; uint64_t i;}){value}.i; 32 | } 33 | 34 | /* Put functions */ 35 | 36 | void flv_put_byte( flv_buffer *c, uint8_t b ) 37 | { 38 | flv_append_data( c, &b, 1 ); 39 | } 40 | 41 | void flv_put_be32( flv_buffer *c, uint32_t val ) 42 | { 43 | flv_put_byte( c, val >> 24 ); 44 | flv_put_byte( c, val >> 16 ); 45 | flv_put_byte( c, val >> 8 ); 46 | flv_put_byte( c, val ); 47 | } 48 | 49 | void flv_put_be64( flv_buffer *c, uint64_t val ) 50 | { 51 | flv_put_be32( c, val >> 32 ); 52 | flv_put_be32( c, val ); 53 | } 54 | 55 | void flv_put_be16( flv_buffer *c, uint16_t val ) 56 | { 57 | flv_put_byte( c, val >> 8 ); 58 | flv_put_byte( c, val ); 59 | } 60 | 61 | void flv_put_be24( flv_buffer *c, uint32_t val ) 62 | { 63 | flv_put_be16( c, val >> 8 ); 64 | flv_put_byte( c, val ); 65 | } 66 | 67 | void flv_put_tag( flv_buffer *c, const char *tag ) 68 | { 69 | while( *tag ) 70 | flv_put_byte( c, *tag++ ); 71 | } 72 | 73 | void flv_put_amf_string( flv_buffer *c, const char *str ) 74 | { 75 | uint16_t len = strlen( str ); 76 | flv_put_be16( c, len ); 77 | flv_append_data( c, (uint8_t*)str, len ); 78 | } 79 | 80 | void flv_put_amf_double( flv_buffer *c, double d ) 81 | { 82 | flv_put_byte( c, AMF_DATA_TYPE_NUMBER ); 83 | flv_put_be64( c, flv_dbl2int( d ) ); 84 | } 85 | 86 | /* flv writing functions */ 87 | 88 | flv_buffer *flv_create_writer( const char *filename ) 89 | { 90 | flv_buffer *c = calloc( 1, sizeof(flv_buffer) ); 91 | if( !c ) 92 | return NULL; 93 | 94 | if( !strcmp( filename, "-" ) ) 95 | c->fp = stdout; 96 | else 97 | c->fp = x264_fopen( filename, "wb" ); 98 | if( !c->fp ) 99 | { 100 | free( c ); 101 | return NULL; 102 | } 103 | 104 | return c; 105 | } 106 | 107 | int flv_append_data( flv_buffer *c, uint8_t *data, unsigned size ) 108 | { 109 | unsigned ns = c->d_cur + size; 110 | 111 | if( ns > c->d_max ) 112 | { 113 | void *dp; 114 | unsigned dn = 16; 115 | while( ns > dn ) 116 | dn <<= 1; 117 | 118 | dp = realloc( c->data, dn ); 119 | if( !dp ) 120 | return -1; 121 | 122 | c->data = dp; 123 | c->d_max = dn; 124 | } 125 | 126 | memcpy( c->data + c->d_cur, data, size ); 127 | 128 | c->d_cur = ns; 129 | 130 | return 0; 131 | } 132 | 133 | void flv_rewrite_amf_be24( flv_buffer *c, unsigned length, unsigned start ) 134 | { 135 | *(c->data + start + 0) = length >> 16; 136 | *(c->data + start + 1) = length >> 8; 137 | *(c->data + start + 2) = length >> 0; 138 | } 139 | 140 | int flv_flush_data( flv_buffer *c ) 141 | { 142 | if( !c->d_cur ) 143 | return 0; 144 | 145 | if( fwrite( c->data, c->d_cur, 1, c->fp ) != 1 ) 146 | return -1; 147 | 148 | c->d_total += c->d_cur; 149 | 150 | c->d_cur = 0; 151 | 152 | return 0; 153 | } 154 | -------------------------------------------------------------------------------- /output/flv_bytestream.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * flv_bytestream.h: flv muxer utilities 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: Kieran Kunhya 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_FLV_BYTESTREAM_H 27 | #define X264_FLV_BYTESTREAM_H 28 | 29 | /* offsets for packed values */ 30 | #define FLV_AUDIO_SAMPLESSIZE_OFFSET 1 31 | #define FLV_AUDIO_SAMPLERATE_OFFSET 2 32 | #define FLV_AUDIO_CODECID_OFFSET 4 33 | 34 | #define FLV_VIDEO_FRAMETYPE_OFFSET 4 35 | 36 | /* bitmasks to isolate specific values */ 37 | #define FLV_AUDIO_CHANNEL_MASK 0x01 38 | #define FLV_AUDIO_SAMPLESIZE_MASK 0x02 39 | #define FLV_AUDIO_SAMPLERATE_MASK 0x0c 40 | #define FLV_AUDIO_CODECID_MASK 0xf0 41 | 42 | #define FLV_VIDEO_CODECID_MASK 0x0f 43 | #define FLV_VIDEO_FRAMETYPE_MASK 0xf0 44 | 45 | #define AMF_END_OF_OBJECT 0x09 46 | 47 | enum 48 | { 49 | FLV_HEADER_FLAG_HASVIDEO = 1, 50 | FLV_HEADER_FLAG_HASAUDIO = 4, 51 | }; 52 | 53 | enum 54 | { 55 | FLV_TAG_TYPE_AUDIO = 0x08, 56 | FLV_TAG_TYPE_VIDEO = 0x09, 57 | FLV_TAG_TYPE_META = 0x12, 58 | }; 59 | 60 | enum 61 | { 62 | FLV_MONO = 0, 63 | FLV_STEREO = 1, 64 | }; 65 | 66 | enum 67 | { 68 | FLV_SAMPLESSIZE_8BIT = 0, 69 | FLV_SAMPLESSIZE_16BIT = 1 << FLV_AUDIO_SAMPLESSIZE_OFFSET, 70 | }; 71 | 72 | enum 73 | { 74 | FLV_SAMPLERATE_SPECIAL = 0, /**< signifies 5512Hz and 8000Hz in the case of NELLYMOSER */ 75 | FLV_SAMPLERATE_11025HZ = 1 << FLV_AUDIO_SAMPLERATE_OFFSET, 76 | FLV_SAMPLERATE_22050HZ = 2 << FLV_AUDIO_SAMPLERATE_OFFSET, 77 | FLV_SAMPLERATE_44100HZ = 3 << FLV_AUDIO_SAMPLERATE_OFFSET, 78 | }; 79 | 80 | enum 81 | { 82 | FLV_CODECID_MP3 = 2 << FLV_AUDIO_CODECID_OFFSET, 83 | FLV_CODECID_AAC = 10<< FLV_AUDIO_CODECID_OFFSET, 84 | }; 85 | 86 | enum 87 | { 88 | FLV_CODECID_H264 = 7, 89 | }; 90 | 91 | enum 92 | { 93 | FLV_FRAME_KEY = 1 << FLV_VIDEO_FRAMETYPE_OFFSET | 7, 94 | FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET | 7, 95 | }; 96 | 97 | typedef enum 98 | { 99 | AMF_DATA_TYPE_NUMBER = 0x00, 100 | AMF_DATA_TYPE_BOOL = 0x01, 101 | AMF_DATA_TYPE_STRING = 0x02, 102 | AMF_DATA_TYPE_OBJECT = 0x03, 103 | AMF_DATA_TYPE_NULL = 0x05, 104 | AMF_DATA_TYPE_UNDEFINED = 0x06, 105 | AMF_DATA_TYPE_REFERENCE = 0x07, 106 | AMF_DATA_TYPE_MIXEDARRAY = 0x08, 107 | AMF_DATA_TYPE_OBJECT_END = 0x09, 108 | AMF_DATA_TYPE_ARRAY = 0x0a, 109 | AMF_DATA_TYPE_DATE = 0x0b, 110 | AMF_DATA_TYPE_LONG_STRING = 0x0c, 111 | AMF_DATA_TYPE_UNSUPPORTED = 0x0d, 112 | } AMFDataType; 113 | 114 | typedef struct flv_buffer 115 | { 116 | uint8_t *data; 117 | unsigned d_cur; 118 | unsigned d_max; 119 | FILE *fp; 120 | uint64_t d_total; 121 | } flv_buffer; 122 | 123 | flv_buffer *flv_create_writer( const char *filename ); 124 | int flv_append_data( flv_buffer *c, uint8_t *data, unsigned size ); 125 | int flv_write_byte( flv_buffer *c, uint8_t *byte ); 126 | int flv_flush_data( flv_buffer *c ); 127 | void flv_rewrite_amf_be24( flv_buffer *c, unsigned length, unsigned start ); 128 | 129 | uint64_t flv_dbl2int( double value ); 130 | void flv_put_byte( flv_buffer *c, uint8_t b ); 131 | void flv_put_be32( flv_buffer *c, uint32_t val ); 132 | void flv_put_be64( flv_buffer *c, uint64_t val ); 133 | void flv_put_be16( flv_buffer *c, uint16_t val ); 134 | void flv_put_be24( flv_buffer *c, uint32_t val ); 135 | void flv_put_tag( flv_buffer *c, const char *tag ); 136 | void flv_put_amf_string( flv_buffer *c, const char *str ); 137 | void flv_put_amf_double( flv_buffer *c, double d ); 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /output/matroska_ebml.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * matroska_ebml.h: matroska muxer utilities 3 | ***************************************************************************** 4 | * Copyright (C) 2005-2014 x264 project 5 | * 6 | * Authors: Mike Matsnev 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #ifndef X264_MATROSKA_EBML_H 27 | #define X264_MATROSKA_EBML_H 28 | 29 | /* Matroska display size units from the spec */ 30 | #define DS_PIXELS 0 31 | #define DS_CM 1 32 | #define DS_INCHES 2 33 | #define DS_ASPECT_RATIO 3 34 | 35 | typedef struct mk_writer mk_writer; 36 | 37 | mk_writer *mk_create_writer( const char *filename ); 38 | 39 | int mk_write_header( mk_writer *w, const char *writing_app, 40 | const char *codec_id, 41 | const void *codec_private, unsigned codec_private_size, 42 | int64_t default_frame_duration, 43 | int64_t timescale, 44 | unsigned width, unsigned height, 45 | unsigned d_width, unsigned d_height, int display_size_units, int stereo_mode ); 46 | 47 | int mk_start_frame( mk_writer *w ); 48 | int mk_add_frame_data( mk_writer *w, const void *data, unsigned size ); 49 | int mk_set_frame_flags( mk_writer *w, int64_t timestamp, int keyframe, int skippable ); 50 | int mk_close( mk_writer *w, int64_t last_delta ); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /output/output.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * output.h: x264 file output modules 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_OUTPUT_H 28 | #define X264_OUTPUT_H 29 | 30 | #include "x264cli.h" 31 | 32 | typedef struct 33 | { 34 | int use_dts_compress; 35 | } cli_output_opt_t; 36 | 37 | typedef struct 38 | { 39 | int (*open_file)( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ); 40 | int (*set_param)( hnd_t handle, x264_param_t *p_param ); 41 | int (*write_headers)( hnd_t handle, x264_nal_t *p_nal ); 42 | int (*write_frame)( hnd_t handle, uint8_t *p_nal, int i_size, x264_picture_t *p_picture ); 43 | int (*close_file)( hnd_t handle, int64_t largest_pts, int64_t second_largest_pts ); 44 | } cli_output_t; 45 | 46 | extern const cli_output_t raw_output; 47 | extern const cli_output_t mkv_output; 48 | extern const cli_output_t mp4_output; 49 | extern const cli_output_t flv_output; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /output/raw.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * raw.c: raw muxer 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #include "output.h" 28 | 29 | static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) 30 | { 31 | if( !strcmp( psz_filename, "-" ) ) 32 | *p_handle = stdout; 33 | else if( !(*p_handle = x264_fopen( psz_filename, "w+b" )) ) 34 | return -1; 35 | 36 | return 0; 37 | } 38 | 39 | static int set_param( hnd_t handle, x264_param_t *p_param ) 40 | { 41 | return 0; 42 | } 43 | 44 | static int write_headers( hnd_t handle, x264_nal_t *p_nal ) 45 | { 46 | int size = p_nal[0].i_payload + p_nal[1].i_payload + p_nal[2].i_payload; 47 | 48 | if( fwrite( p_nal[0].p_payload, size, 1, (FILE*)handle ) ) 49 | return size; 50 | return -1; 51 | } 52 | 53 | static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_t *p_picture ) 54 | { 55 | if( fwrite( p_nalu, i_size, 1, (FILE*)handle ) ) 56 | return i_size; 57 | return -1; 58 | } 59 | 60 | static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest_pts ) 61 | { 62 | if( !handle || handle == stdout ) 63 | return 0; 64 | 65 | return fclose( (FILE*)handle ); 66 | } 67 | 68 | const cli_output_t raw_output = { open_file, set_param, write_headers, write_frame, close_file }; 69 | 70 | -------------------------------------------------------------------------------- /tools/cltostr.pl: -------------------------------------------------------------------------------- 1 | # Perl script used for compiling OpenCL src into x264 binary 2 | # 3 | # Copyright (C) 2013-2014 x264 project 4 | # Authors: Steve Borho 5 | 6 | use Digest::MD5 qw(md5_hex); 7 | 8 | # xxd takes a VAR, which will be the variable name 9 | # and BYTES, a string of bytes to beencoded. 10 | sub xxd 11 | { 12 | my %args = @_; 13 | my $var = $args{VAR}; 14 | my $bytes = $args{BYTES}; 15 | my @hexbytes; 16 | my @bytes = split //, $$bytes; 17 | foreach $b (@bytes) 18 | { 19 | push @hexbytes, sprintf("0x%02X", ord($b)); 20 | } 21 | 22 | # Format 'em nice and pretty-like. 23 | print 'static const char ' . $var . '[] = {' . "\n"; 24 | my $count = 0; 25 | foreach my $h (@hexbytes) 26 | { 27 | print "$h, "; 28 | $count++; 29 | if ($count == 16) 30 | { 31 | print "\n"; 32 | $count = 0; 33 | } 34 | } 35 | print "\n0x00 };\n\n"; 36 | 37 | return; 38 | } 39 | 40 | if (@ARGV < 1) 41 | { 42 | printf "%s: VARNAME ", $0 . "\n"; 43 | exit(-1); 44 | } 45 | 46 | 47 | my @lines; 48 | while() 49 | { 50 | s/^\s+//; # trim leading whitespace 51 | if (/^\/\//) 52 | { 53 | next; # skip the line if it starts with '//' 54 | } 55 | push @lines, $_; 56 | } 57 | 58 | my $lines = join '', @lines; 59 | xxd(VAR => @ARGV[0], BYTES => \$lines); 60 | 61 | my $hash = md5_hex($lines); 62 | @hash = ( $hash =~ m/../g ); 63 | 64 | 65 | xxd(VAR => @ARGV[0] . "_hash", BYTES => \$hash); 66 | -------------------------------------------------------------------------------- /tools/countquant_x264.pl: -------------------------------------------------------------------------------- 1 | #!/bin/env perl 2 | # countquant_x264.pl: displays statistics from x264 multipass logfiles 3 | # by Loren Merritt, 2005-4-5 4 | 5 | @size{I,P,B} = 6 | @n{I,P,B} = (0)x3; 7 | 8 | sub proc_file { 9 | my $fh = shift; 10 | while(<$fh>) { 11 | /type:(.) q:(\d+\.\d+) tex:(\d+) mv:(\d+) misc:(\d+)/ or next; 12 | $type = uc $1; 13 | $n{$type} ++; 14 | $q[int($2+.5)] ++; 15 | $avgq += $2; 16 | $avgq{$type} += $2; 17 | my $bytes = ($3+$4+$5)/8; 18 | $size{$type} += $bytes; 19 | } 20 | $size = $size{I} + $size{P} + $size{B}; 21 | $n = $n{I} + $n{P} + $n{B}; 22 | $n or die "unrecognized input\n"; 23 | } 24 | 25 | if(@ARGV) { 26 | foreach(@ARGV) { 27 | open $fh, "<", $_ or die "can't open '$_': $!"; 28 | proc_file($fh); 29 | } 30 | } else { 31 | proc_file(STDIN); 32 | } 33 | 34 | for(0..51) { 35 | $q[$_] or next; 36 | printf "q%2d: %6d %4.1f%%\n", $_, $q[$_], 100*$q[$_]/$n; 37 | } 38 | print "\n"; 39 | $digits = int(log($n+1)/log(10))+2; 40 | printf "All: %${digits}d %s avgQP:%5.2f avgBytes:%5d\n", 41 | $n, $n==$n{I}?" ":"", $avgq/$n, $size/$n; 42 | foreach(qw(I P B S)) { 43 | $n{$_} or next; 44 | printf "%s: %${digits}d (%4.1f%%) avgQP:%5.2f avgBytes:%5d\n", 45 | $_, $n{$_}, 100*$n{$_}/$n, $avgq{$_}/$n{$_}, $size{$_}/$n{$_}; 46 | } 47 | print "\n"; 48 | printf "total size: $size B = %.2f KiB = %.2f MiB\n", 49 | $size/2**10, $size/2**20; 50 | print "bitrate: ", join("\n = ", 51 | map sprintf("%.2f kbps @ %s fps", $_*$size*8/1000/$n, $_), 52 | 23.976, 25, 29.97), "\n"; 53 | -------------------------------------------------------------------------------- /tools/digress/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Automated regression/unit testing suite. 3 | """ 4 | 5 | __version__ = '0.2' 6 | 7 | def digress(fixture): 8 | """ 9 | Command-line helper for Digress. 10 | """ 11 | from digress.cli import Dispatcher 12 | Dispatcher(fixture).dispatch() 13 | -------------------------------------------------------------------------------- /tools/digress/cli.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digress's CLI interface. 3 | """ 4 | 5 | import inspect 6 | import sys 7 | from optparse import OptionParser 8 | 9 | import textwrap 10 | 11 | from types import MethodType 12 | 13 | from digress import __version__ as version 14 | 15 | def dispatchable(func): 16 | """ 17 | Mark a method as dispatchable. 18 | """ 19 | func.digress_dispatchable = True 20 | return func 21 | 22 | class Dispatcher(object): 23 | """ 24 | Dispatcher for CLI commands. 25 | """ 26 | def __init__(self, fixture): 27 | self.fixture = fixture 28 | fixture.dispatcher = self 29 | 30 | def _monkey_print_help(self, optparse, *args, **kwargs): 31 | # monkey patches OptionParser._print_help 32 | OptionParser.print_help(optparse, *args, **kwargs) 33 | 34 | print >>sys.stderr, "\nAvailable commands:" 35 | 36 | maxlen = max([ len(command_name) for command_name in self.commands ]) 37 | 38 | descwidth = 80 - maxlen - 4 39 | 40 | for command_name, command_meth in self.commands.iteritems(): 41 | print >>sys.stderr, " %s %s\n" % ( 42 | command_name.ljust(maxlen + 1), 43 | ("\n" + (maxlen + 4) * " ").join( 44 | textwrap.wrap(" ".join(filter( 45 | None, 46 | command_meth.__doc__.strip().replace("\n", " ").split(" ") 47 | )), 48 | descwidth 49 | ) 50 | ) 51 | ) 52 | 53 | def _enable_flush(self): 54 | self.fixture.flush_before = True 55 | 56 | def _populate_parser(self): 57 | self.commands = self._get_commands() 58 | 59 | self.optparse = OptionParser( 60 | usage = "usage: %prog [options] command [args]", 61 | description = "Digress CLI frontend for %s." % self.fixture.__class__.__name__, 62 | version = "Digress %s" % version 63 | ) 64 | 65 | self.optparse.print_help = MethodType(self._monkey_print_help, self.optparse, OptionParser) 66 | 67 | self.optparse.add_option( 68 | "-f", 69 | "--flush", 70 | action="callback", 71 | callback=lambda option, opt, value, parser: self._enable_flush(), 72 | help="flush existing data for a revision before testing" 73 | ) 74 | 75 | self.optparse.add_option( 76 | "-c", 77 | "--cases", 78 | metavar="FOO,BAR", 79 | action="callback", 80 | dest="cases", 81 | type=str, 82 | callback=lambda option, opt, value, parser: self._select_cases(*value.split(",")), 83 | help="test cases to run, run with command list to see full list" 84 | ) 85 | 86 | def _select_cases(self, *cases): 87 | self.fixture.cases = filter(lambda case: case.__name__ in cases, self.fixture.cases) 88 | 89 | def _get_commands(self): 90 | commands = {} 91 | 92 | for name, member in inspect.getmembers(self.fixture): 93 | if hasattr(member, "digress_dispatchable"): 94 | commands[name] = member 95 | 96 | return commands 97 | 98 | def _run_command(self, name, *args): 99 | if name not in self.commands: 100 | print >>sys.stderr, "error: %s is not a valid command\n" % name 101 | self.optparse.print_help() 102 | return 103 | 104 | command = self.commands[name] 105 | 106 | argspec = inspect.getargspec(command) 107 | 108 | max_arg_len = len(argspec.args) - 1 109 | min_arg_len = max_arg_len - ((argspec.defaults is not None) and len(argspec.defaults) or 0) 110 | 111 | if len(args) < min_arg_len: 112 | print >>sys.stderr, "error: %s takes at least %d arguments\n" % ( 113 | name, 114 | min_arg_len 115 | ) 116 | print >>sys.stderr, "%s\n" % command.__doc__ 117 | self.optparse.print_help() 118 | return 119 | 120 | if len(args) > max_arg_len: 121 | print >>sys.stderr, "error: %s takes at most %d arguments\n" % ( 122 | name, 123 | max_arg_len 124 | ) 125 | print >>sys.stderr, "%s\n" % command.__doc__ 126 | self.optparse.print_help() 127 | return 128 | 129 | command(*args) 130 | 131 | def pre_dispatch(self): 132 | pass 133 | 134 | def dispatch(self): 135 | self._populate_parser() 136 | 137 | self.optparse.parse_args() 138 | self.pre_dispatch() 139 | args = self.optparse.parse_args()[1] # arguments may require reparsing after pre_dispatch; see test_x264.py 140 | 141 | if len(args) == 0: 142 | print >>sys.stderr, "error: no comamnd specified\n" 143 | self.optparse.print_help() 144 | return 145 | 146 | command = args[0] 147 | addenda = args[1:] 148 | 149 | self._run_command(command, *addenda) 150 | -------------------------------------------------------------------------------- /tools/digress/comparers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digress comparers. 3 | """ 4 | 5 | from digress.errors import ComparisonError 6 | 7 | import os 8 | from itertools import imap, izip 9 | 10 | def compare_direct(value_a, value_b): 11 | if value_a != value_b: 12 | raise ComparisonError("%s is not %s" % (value_a, value_b)) 13 | 14 | def compare_pass(value_a, value_b): 15 | """ 16 | Always true, as long as the test is passed. 17 | """ 18 | 19 | def compare_tolerance(tolerance): 20 | def _compare_tolerance(value_a, value_b): 21 | if abs(value_a - value_b) > tolerance: 22 | raise ComparisonError("%s is not %s (tolerance: %s)" % ( 23 | value_a, 24 | value_b, 25 | tolerance 26 | )) 27 | return _compare_tolerance 28 | 29 | def compare_files(file_a, file_b): 30 | size_a = os.path.getsize(file_a) 31 | size_b = os.path.getsize(file_b) 32 | 33 | print file_a, file_b 34 | 35 | if size_a != size_b: 36 | raise ComparisonError("%s is not the same size as %s" % ( 37 | file_a, 38 | file_b 39 | )) 40 | 41 | BUFFER_SIZE = 8196 42 | 43 | offset = 0 44 | 45 | with open(file_a) as f_a: 46 | with open(file_b) as f_b: 47 | for chunk_a, chunk_b in izip( 48 | imap( 49 | lambda i: f_a.read(BUFFER_SIZE), 50 | xrange(size_a // BUFFER_SIZE + 1) 51 | ), 52 | imap( 53 | lambda i: f_b.read(BUFFER_SIZE), 54 | xrange(size_b // BUFFER_SIZE + 1) 55 | ) 56 | ): 57 | chunk_size = len(chunk_a) 58 | 59 | if chunk_a != chunk_b: 60 | for i in xrange(chunk_size): 61 | if chunk_a[i] != chunk_b[i]: 62 | raise ComparisonError("%s differs from %s at offset %d" % ( 63 | file_a, 64 | file_b, 65 | offset + i 66 | )) 67 | 68 | offset += chunk_size 69 | -------------------------------------------------------------------------------- /tools/digress/constants.py: -------------------------------------------------------------------------------- 1 | """ 2 | All of Digress's constants. 3 | """ 4 | 5 | TEST_PASS = 0 6 | TEST_FAIL = 1 7 | TEST_DISABLED = 2 8 | TEST_SKIPPED = 3 9 | 10 | CASE_PASS = 0 11 | CASE_FAIL = 1 12 | 13 | FIXTURE_PASS = 0 14 | FIXTURE_FAIL = 1 15 | -------------------------------------------------------------------------------- /tools/digress/errors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Digress errors. 3 | """ 4 | 5 | class DigressError(Exception): 6 | """ 7 | Digress error base class. 8 | """ 9 | 10 | class NoSuchTestError(DigressError): 11 | """ 12 | Raised when no such test exists. 13 | """ 14 | 15 | class DisabledTestError(DigressError): 16 | """ 17 | Test is disabled. 18 | """ 19 | 20 | class SkippedTestError(DigressError): 21 | """ 22 | Test is marked as skipped. 23 | """ 24 | 25 | class DisabledCaseError(DigressError): 26 | """ 27 | Case is marked as disabled. 28 | """ 29 | 30 | class SkippedCaseError(DigressError): 31 | """ 32 | Case is marked as skipped. 33 | """ 34 | 35 | class FailedTestError(DigressError): 36 | """ 37 | Test failed. 38 | """ 39 | 40 | class ComparisonError(DigressError): 41 | """ 42 | Comparison failed. 43 | """ 44 | 45 | class IncomparableError(DigressError): 46 | """ 47 | Values cannot be compared. 48 | """ 49 | 50 | class AlreadyRunError(DigressError): 51 | """ 52 | Test/case has already been run. 53 | """ 54 | 55 | class SCMError(DigressError): 56 | """ 57 | Error occurred in SCM. 58 | """ 59 | def __init__(self, message): 60 | self.message = message.replace("\n", " ") 61 | 62 | def __str__(self): 63 | return self.message 64 | -------------------------------------------------------------------------------- /tools/digress/scm/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Source control backends for Digress. 3 | """ 4 | -------------------------------------------------------------------------------- /tools/digress/scm/dummy.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dummy SCM backend for Digress. 3 | """ 4 | 5 | from random import random 6 | 7 | def checkout(revision): 8 | """ 9 | Checkout a revision. 10 | """ 11 | pass 12 | 13 | def current_rev(): 14 | """ 15 | Get the current revision 16 | """ 17 | return str(random()) 18 | 19 | def revisions(rev_a, rev_b): 20 | """ 21 | Get a list of revisions from one to another. 22 | """ 23 | pass 24 | 25 | def stash(): 26 | """ 27 | Stash the repository. 28 | """ 29 | pass 30 | 31 | def unstash(): 32 | """ 33 | Unstash the repository. 34 | """ 35 | pass 36 | 37 | def bisect(command, revision): 38 | """ 39 | Perform a bisection. 40 | """ 41 | raise NotImplementedError("dummy SCM backend does not support bisection") 42 | -------------------------------------------------------------------------------- /tools/digress/scm/git.py: -------------------------------------------------------------------------------- 1 | """ 2 | Git SCM backend for Digress. 3 | """ 4 | 5 | from subprocess import Popen, PIPE, STDOUT 6 | import re 7 | 8 | from digress.errors import SCMError 9 | 10 | GIT_BRANCH_EXPR = re.compile("[*] (.*)") 11 | 12 | def checkout(revision): 13 | """ 14 | Checkout a revision from git. 15 | """ 16 | proc = Popen([ 17 | "git", 18 | "checkout", 19 | "-f", 20 | revision 21 | ], stdout=PIPE, stderr=STDOUT) 22 | 23 | output = proc.communicate()[0].strip() 24 | if proc.returncode != 0: 25 | raise SCMError("checkout error: %s" % output) 26 | 27 | def rev_parse(ref): 28 | proc = Popen([ 29 | "git", 30 | "rev-parse", 31 | ref 32 | ], stdout=PIPE, stderr=STDOUT) 33 | 34 | output = proc.communicate()[0].strip() 35 | if proc.returncode != 0: 36 | raise SCMError("rev-parse error: %s" % output) 37 | return output 38 | 39 | def current_rev(): 40 | """ 41 | Get the current revision. 42 | """ 43 | return rev_parse("HEAD") 44 | 45 | def current_branch(): 46 | """ 47 | Get the current branch. 48 | """ 49 | proc = Popen([ 50 | "git", 51 | "branch", 52 | "--no-color" 53 | ], stdout=PIPE, stderr=STDOUT) 54 | 55 | output = proc.communicate()[0].strip() 56 | if proc.returncode != 0: 57 | raise SCMError("branch error: %s" % output) 58 | branch_name = GIT_BRANCH_EXPR.findall(output)[0] 59 | return branch_name != "(no branch)" and branch_name or None 60 | 61 | def revisions(rev_a, rev_b): 62 | """ 63 | Get a list of revisions from one to another. 64 | """ 65 | proc = Popen([ 66 | "git", 67 | "log", 68 | "--format=%H", ("%s...%s" % (rev_a, rev_b)) 69 | ], stdout=PIPE, stderr=STDOUT) 70 | 71 | output = proc.communicate()[0].strip() 72 | if proc.returncode != 0: 73 | raise SCMError("log error: %s" % output) 74 | return output.split("\n") 75 | 76 | def stash(): 77 | """ 78 | Stash the repository. 79 | """ 80 | proc = Popen([ 81 | "git", 82 | "stash", 83 | "save", 84 | "--keep-index" 85 | ], stdout=PIPE, stderr=STDOUT) 86 | 87 | output = proc.communicate()[0].strip() 88 | if proc.returncode != 0: 89 | raise SCMError("stash error: %s" % output) 90 | 91 | def unstash(): 92 | """ 93 | Unstash the repository. 94 | """ 95 | proc = Popen(["git", "stash", "pop"], stdout=PIPE, stderr=STDOUT) 96 | proc.communicate() 97 | 98 | def bisect(*args): 99 | """ 100 | Perform a bisection. 101 | """ 102 | proc = Popen((["git", "bisect"] + list(args)), stdout=PIPE, stderr=STDOUT) 103 | output = proc.communicate()[0] 104 | if proc.returncode != 0: 105 | raise SCMError("bisect error: %s" % output) 106 | return output 107 | 108 | def dirty(): 109 | """ 110 | Check if the working tree is dirty. 111 | """ 112 | proc = Popen(["git", "status"], stdout=PIPE, stderr=STDOUT) 113 | output = proc.communicate()[0].strip() 114 | if proc.returncode != 0: 115 | raise SCMError("status error: %s" % output) 116 | if "modified:" in output: 117 | return True 118 | else: 119 | return False 120 | -------------------------------------------------------------------------------- /tools/q_matrix_jvt.cfg: -------------------------------------------------------------------------------- 1 | # This an example configuration file for initializing the quantization matrix. 2 | # Altogether 6 matrices for 4x4 blocks and 2 matrix for 8x8 blocks. 3 | # The values range from 1 to 255. 4 | # If first value of matrix is equal to 0, default values ("JVT") will be used 5 | # for that matrix. 6 | # If a matrix is completely omitted, it will be filled with 16s. 7 | # 8 | # Note: JM expects CHROMAU and CHROMAV to be specified separately, whereas 9 | # x264 forces them to use the same matrix. If U and V are specified to have 10 | # different matrices, only the first is used. 11 | #################################################################################### 12 | 13 | INTRA4X4_LUMA = 14 | 6,13,20,28, 15 | 13,20,28,32, 16 | 20,28,32,37, 17 | 28,32,37,42 18 | 19 | INTRA4X4_CHROMAU = 20 | 6,13,20,28, 21 | 13,20,28,32, 22 | 20,28,32,37, 23 | 28,32,37,42 24 | 25 | INTRA4X4_CHROMAV = 26 | 6,13,20,28, 27 | 13,20,28,32, 28 | 20,28,32,37, 29 | 28,32,37,42 30 | 31 | INTER4X4_LUMA = 32 | 10,14,20,24, 33 | 14,20,24,27, 34 | 20,24,27,30, 35 | 24,27,30,34 36 | 37 | INTER4X4_CHROMAU = 38 | 10,14,20,24, 39 | 14,20,24,27, 40 | 20,24,27,30, 41 | 24,27,30,34 42 | 43 | INTER4X4_CHROMAV = 44 | 10,14,20,24, 45 | 14,20,24,27, 46 | 20,24,27,30, 47 | 24,27,30,34 48 | 49 | INTRA8X8_LUMA = 50 | 6,10,13,16,18,23,25,27, 51 | 10,11,16,18,23,25,27,29, 52 | 13,16,18,23,25,27,29,31, 53 | 16,18,23,25,27,29,31,33, 54 | 18,23,25,27,29,31,33,36, 55 | 23,25,27,29,31,33,36,38, 56 | 25,27,29,31,33,36,38,40, 57 | 27,29,31,33,36,38,40,42 58 | 59 | INTER8X8_LUMA = 60 | 9,13,15,17,19,21,22,24, 61 | 13,13,17,19,21,22,24,25, 62 | 15,17,19,21,22,24,25,27, 63 | 17,19,21,22,24,25,27,28, 64 | 19,21,22,24,25,27,28,30, 65 | 21,22,24,25,27,28,30,32, 66 | 22,24,25,27,28,30,32,33, 67 | 24,25,27,28,30,32,33,35 68 | 69 | -------------------------------------------------------------------------------- /tools/q_matrix_mpeg2.cfg: -------------------------------------------------------------------------------- 1 | # This an example configuration file for initializing the quantization matrix. 2 | # Altogether 4 matrices for 8x8 blocks: INTRA_LUMA, INTER_LUMA, 3 | # INTRA_CHROMA, INTER_CHROMA 4 | # Allowed values range from 4 to 255. 5 | # If first value of a luma matrix is equal to 0, default MPEG values ("FLAT") will 6 | # be used for that matrix. If first value of a chroma matrix is equal to 0, 7 | # that chroma matrix will be set to equal the corresponding luma matrix. 8 | # If a matrix is completely omitted, it will be filled with 16s. 9 | # 10 | # Note: The two chroma matrices are only used in 4:2:2. 11 | # The first value for an intra matrix must be 8 (see 6.3.11). It will be ignored in 12 | # favor of intra_dc_precision anyway. 13 | #################################################################################### 14 | 15 | INTRA_LUMA = 0 16 | 17 | INTER_LUMA = 18 | 16,17,18,19,20,21,22,23, 19 | 17,18,19,20,21,22,23,24, 20 | 18,19,20,21,22,23,24,25, 21 | 19,20,21,22,23,24,26,27, 22 | 20,21,22,23,25,26,27,28, 23 | 21,22,23,24,26,27,28,30, 24 | 22,23,24,26,27,28,30,31, 25 | 23,24,25,27,28,30,31,33 26 | 27 | INTRA_CHROMA = 0 28 | 29 | INTER_CHROMA = 0 30 | -------------------------------------------------------------------------------- /version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | [ -n "$1" ] && cd $1 3 | 4 | git_version() { 5 | trap 'rm -f config.git-hash' EXIT 6 | git rev-list HEAD | sort > config.git-hash 7 | LOCALVER=`wc -l config.git-hash | awk '{print $1}'` 8 | if [ $LOCALVER \> 1 ] ; then 9 | VER=`git rev-list origin/master | sort | join config.git-hash - | wc -l | awk '{print $1}'` 10 | VER_DIFF=$(($LOCALVER-$VER)) 11 | echo "#define X264_REV $VER" 12 | echo "#define X264_REV_DIFF $VER_DIFF" 13 | if [ $VER_DIFF != 0 ] ; then 14 | VER="$VER+$VER_DIFF" 15 | fi 16 | if git status | grep -q "modified:" ; then 17 | VER="${VER}M" 18 | fi 19 | VER="$VER $(git rev-list HEAD -n 1 | cut -c 1-7)" 20 | VERSION=" r$VER" 21 | fi 22 | } 23 | 24 | VER="x" 25 | VERSION="" 26 | [ -d .git ] && (type git >/dev/null 2>&1) && git_version 27 | echo "#define X264_VERSION \"$VERSION\"" 28 | API=`grep '#define X264_BUILD' < x264.h | sed -e 's/.* \([1-9][0-9]*\).*/\1/'` 29 | echo "#define X264_POINTVER \"0.$API.$VER\"" 30 | -------------------------------------------------------------------------------- /x264cli.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * x264cli.h: x264cli common 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: Laurent Aimar 7 | * Loren Merritt 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 22 | * 23 | * This program is also available under a commercial proprietary license. 24 | * For more information, contact us at licensing@x264.com. 25 | *****************************************************************************/ 26 | 27 | #ifndef X264_CLI_H 28 | #define X264_CLI_H 29 | 30 | #include "common/common.h" 31 | 32 | /* In microseconds */ 33 | #define UPDATE_INTERVAL 250000 34 | 35 | typedef void *hnd_t; 36 | 37 | static inline uint64_t gcd( uint64_t a, uint64_t b ) 38 | { 39 | while( 1 ) 40 | { 41 | int64_t c = a % b; 42 | if( !c ) 43 | return b; 44 | a = b; 45 | b = c; 46 | } 47 | } 48 | 49 | static inline uint64_t lcm( uint64_t a, uint64_t b ) 50 | { 51 | return ( a / gcd( a, b ) ) * b; 52 | } 53 | 54 | static inline char *get_filename_extension( char *filename ) 55 | { 56 | char *ext = filename + strlen( filename ); 57 | while( *ext != '.' && ext > filename ) 58 | ext--; 59 | ext += *ext == '.'; 60 | return ext; 61 | } 62 | 63 | void x264_cli_log( const char *name, int i_level, const char *fmt, ... ); 64 | void x264_cli_printf( int i_level, const char *fmt, ... ); 65 | 66 | #ifdef _WIN32 67 | void x264_cli_set_console_title( const char *title ); 68 | int x264_ansi_filename( const char *filename, char *ansi_filename, int size, int create_file ); 69 | #else 70 | #define x264_cli_set_console_title( title ) 71 | #endif 72 | 73 | #define RETURN_IF_ERR( cond, name, ret, ... )\ 74 | if( cond )\ 75 | {\ 76 | x264_cli_log( name, X264_LOG_ERROR, __VA_ARGS__ );\ 77 | return ret;\ 78 | } 79 | 80 | #define FAIL_IF_ERR( cond, name, ... ) RETURN_IF_ERR( cond, name, -1, __VA_ARGS__ ) 81 | 82 | typedef enum 83 | { 84 | RANGE_AUTO = -1, 85 | RANGE_TV, 86 | RANGE_PC 87 | } range_enum; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /x264dll.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * x264dll: x264 DLLMain for win32 3 | ***************************************************************************** 4 | * Copyright (C) 2009-2014 x264 project 5 | * 6 | * Authors: Anton Mitrofanov 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include "common/common.h" 27 | #include 28 | 29 | /* Callback for our DLL so we can initialize pthread */ 30 | BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) 31 | { 32 | #if PTW32_STATIC_LIB 33 | switch( fdwReason ) 34 | { 35 | case DLL_PROCESS_ATTACH: 36 | pthread_win32_process_attach_np(); 37 | 38 | case DLL_THREAD_ATTACH: 39 | pthread_win32_thread_attach_np(); 40 | break; 41 | 42 | case DLL_THREAD_DETACH: 43 | pthread_win32_thread_detach_np(); 44 | break; 45 | 46 | case DLL_PROCESS_DETACH: 47 | pthread_win32_thread_detach_np(); 48 | pthread_win32_process_detach_np(); 49 | break; 50 | } 51 | #endif 52 | 53 | return TRUE; 54 | } 55 | -------------------------------------------------------------------------------- /x264res.rc: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * x264res.rc: windows resource file 3 | ***************************************************************************** 4 | * Copyright (C) 2012-2014 x264 project 5 | * 6 | * Authors: Henrik Gramner 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. 21 | * 22 | * This program is also available under a commercial proprietary license. 23 | * For more information, contact us at licensing@x264.com. 24 | *****************************************************************************/ 25 | 26 | #include 27 | #include 28 | #include "x264.h" 29 | 30 | #ifndef X264_REV 31 | #define X264_REV 0 32 | #define X264_REV_DIFF 0 33 | #endif 34 | 35 | #define str(s) #s 36 | #define xstr(s) str(s) 37 | 38 | VS_VERSION_INFO VERSIONINFO 39 | FILEVERSION 0, X264_BUILD, X264_REV, X264_REV_DIFF 40 | PRODUCTVERSION 0, X264_BUILD, X264_REV, X264_REV_DIFF 41 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 42 | FILEFLAGS 0 43 | FILEOS VOS_NT_WINDOWS32 /* Identical for x86-64 */ 44 | #ifdef DLL 45 | FILETYPE VFT_DLL 46 | #else 47 | FILETYPE VFT_APP 48 | #endif 49 | FILESUBTYPE VFT2_UNKNOWN 50 | BEGIN 51 | BLOCK "StringFileInfo" 52 | BEGIN 53 | BLOCK "040904B0" 54 | BEGIN 55 | VALUE "CompanyName", "x264 project" 56 | #ifdef DLL 57 | VALUE "FileDescription", "H.264 (MPEG-4 AVC) encoder library" 58 | #else 59 | VALUE "FileDescription", "H.264 (MPEG-4 AVC) encoder" 60 | #endif 61 | VALUE "FileVersion", X264_POINTVER 62 | VALUE "InternalName", "x264" 63 | VALUE "LegalCopyright", "Copyright (C) 2003-2014 x264 project" 64 | #ifdef DLL 65 | VALUE "OriginalFilename", "libx264-" xstr(X264_BUILD) ".dll" 66 | #else 67 | VALUE "OriginalFilename", "x264.exe" 68 | #endif 69 | VALUE "ProductName", "x264" 70 | VALUE "ProductVersion", X264_POINTVER 71 | END 72 | END 73 | 74 | BLOCK "VarFileInfo" 75 | BEGIN 76 | VALUE "Translation", 0x0409, 0x04B0 /* U.S. English (Unicode) */ 77 | END 78 | END 79 | --------------------------------------------------------------------------------