├── .gitignore ├── AUTHORS ├── COPYING ├── COPYING.qtaacenc ├── Makefile ├── audio ├── audio.c ├── audio.h ├── encoders.c ├── encoders.h └── encoders │ ├── enc_amrwb_3gpp.c │ ├── enc_faac.c │ ├── enc_lavc.c │ ├── enc_mp3lame.c │ ├── enc_qtaac.c │ └── enc_raw.c ├── 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 ├── 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 ├── 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 ├── audio │ ├── audio_filters.c │ ├── audio_filters.h │ ├── internal.c │ └── internal.h ├── filters.c ├── filters.h └── video │ ├── cache.c │ ├── crop.c │ ├── depth.c │ ├── fix_vfr_pts.c │ ├── hqdn3d.c │ ├── internal.c │ ├── internal.h │ ├── pad.c │ ├── resize.c │ ├── select_every.c │ ├── source.c │ ├── subtitles.c │ ├── subtitles.h │ ├── vflip.c │ ├── video.c │ ├── video.h │ ├── x86 │ ├── yadif_filter_line.c │ ├── yadif_filter_line.h │ └── yadif_sse_template.c │ ├── yadif.c │ ├── yadif_filter_line.c │ └── yadif_filter_line.h ├── input ├── audio │ ├── avs.c │ ├── lavf.c │ └── lsmash.c ├── avs.c ├── ffms.c ├── input.c ├── input.h ├── lavf.c ├── raw.c ├── thread.c ├── timecode.c └── y4m.c ├── output ├── avi.c ├── 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 └── 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 | checkasm 27 | 28 | *.264 29 | *.h264 30 | *.2pass 31 | *.ffindex 32 | *.avs 33 | *.mkv 34 | *.flv 35 | *.mp4 36 | *.y4m 37 | *.yuv 38 | *.log 39 | *.mbtree 40 | *.temp 41 | *.pyc 42 | 43 | .digress_x264 44 | dataDec.txt 45 | log.dec 46 | common/oclobj.h 47 | x264_lookahead.clbin 48 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /COPYING.qtaacenc: -------------------------------------------------------------------------------- 1 | This software contains the following software: 2 | 3 | ------------------------------------------------------------------- 4 | 5 | Copyright (c) 2010-2011 tmkk 6 | 7 | Permission is hereby granted, free of charge, to any person 8 | obtaining a copy of this software and associated documentation 9 | files (the "Software"), to deal in the Software without 10 | restriction, including without limitation the rights to use, 11 | copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the 13 | Software is furnished to do so, subject to the following 14 | conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | ------------------------------------------------------------------- 29 | -------------------------------------------------------------------------------- /audio/audio.c: -------------------------------------------------------------------------------- 1 | #include "filters/audio/internal.h" 2 | 3 | #include 4 | 5 | hnd_t x264_audio_open_from_file( char *preferred_filter_name, char *path, int trackno ) 6 | { 7 | char *source_name = preferred_filter_name ? preferred_filter_name : "lavf"; 8 | audio_filter_t *source = x264_af_get_filter( source_name ); 9 | 10 | if( !source ) 11 | { 12 | x264_cli_log( "audio", X264_LOG_ERROR, "no decoder / demuxer avilable!\n" ); 13 | return NULL; 14 | } 15 | hnd_t h = NULL; 16 | size_t init_arg_size = strlen( path ) + 10; 17 | char *init_arg = malloc( init_arg_size ); 18 | assert( snprintf( init_arg, init_arg_size, "%s,%d", path, trackno ) < init_arg_size ); 19 | if( source->init( &h, init_arg ) < 0 || !h ) 20 | { 21 | x264_cli_log( "audio", X264_LOG_ERROR, "error initializing source filter!\n" ); 22 | return NULL; 23 | } 24 | free( init_arg ); 25 | return h; 26 | } 27 | -------------------------------------------------------------------------------- /audio/audio.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_AUDIO_H_ 2 | #define AUDIO_AUDIO_H_ 3 | 4 | #include 5 | #include "x264cli.h" 6 | #include "filters/audio/audio_filters.h" 7 | 8 | enum AudioTrack 9 | { 10 | TRACK_ANY = -1, 11 | TRACK_NONE = -2 12 | }; 13 | 14 | hnd_t x264_audio_open_from_file( char *preferred_filter_name, char *path, int trackno ); 15 | 16 | #endif /* AUDIO_AUDIO_H_ */ 17 | -------------------------------------------------------------------------------- /audio/encoders.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_ENCODERS_H_ 2 | #define AUDIO_ENCODERS_H_ 3 | 4 | #include "audio/audio.h" 5 | #include "filters/audio/audio_filters.h" 6 | 7 | typedef struct audio_encoder_t 8 | { 9 | hnd_t (*init)( hnd_t filter_chain, const char *opts ); 10 | audio_info_t *(*get_info)( hnd_t handle ); 11 | audio_packet_t *(*get_next_packet)( hnd_t handle ); 12 | void (*skip_samples)( hnd_t handle, uint64_t samplecount ); 13 | audio_packet_t *(*finish)( hnd_t handle ); 14 | void (*free_packet)( hnd_t handle, audio_packet_t *samples ); 15 | void (*close)( hnd_t handle ); 16 | void (*show_help)( const char * const encoder_name ); 17 | int (*is_valid_encoder)( const char * const encoder_name, void **priv ); 18 | } audio_encoder_t; 19 | 20 | #if HAVE_AUDIO 21 | extern const audio_encoder_t audio_encoder_raw; 22 | #if HAVE_LAVF 23 | extern const audio_encoder_t audio_encoder_lavc; 24 | #endif 25 | #if HAVE_LAME 26 | extern const audio_encoder_t audio_encoder_lame; 27 | #endif 28 | #if HAVE_QT_AAC 29 | extern const audio_encoder_t audio_encoder_qtaac; 30 | #endif 31 | #if HAVE_FAAC 32 | extern const audio_encoder_t audio_encoder_faac; 33 | #endif 34 | #if HAVE_AMRWB_3GPP 35 | extern const audio_encoder_t audio_encoder_amrwb_3gpp; 36 | #endif 37 | 38 | #endif /* HAVE_AUDIO */ 39 | 40 | #define AUDIO_CODEC_COMMON_OPTIONS "codec", "is_vbr", "bitrate", "quality" 41 | 42 | enum audio_encoder_query 43 | { 44 | QUERY_CODEC = 0, 45 | QUERY_ENCODER = 1, 46 | }; 47 | 48 | #define MAX_ARGS 256 49 | 50 | /* the first available encoder on allowed_list is the prefered encoder if encoder is "auto" 51 | * allowed_list = NULL means any valid encoder is allowed 52 | * The 'none' case isn't handled by this function (will return NULL like with any other invalid encoder) 53 | * If the user wants 'none' to be a default, it must be tested outside of this function 54 | * If the user wants to allow any encoder, the default case must be tested outside of this function */ 55 | const audio_encoder_t *x264_select_audio_encoder( const char *name, char* allowed_list[], const char **used_enc ); 56 | const audio_encoder_t *x264_audio_encoder_by_name( const char *name, int mode, const char **used_enc ); 57 | hnd_t x264_audio_encoder_open( const audio_encoder_t *encoder, hnd_t filter_chain, const char *opts ); 58 | hnd_t x264_audio_copy_open( hnd_t handle ); 59 | 60 | const char *x264_audio_encoder_codec_name( hnd_t encoder ); 61 | audio_info_t *x264_audio_encoder_info( hnd_t encoder ); 62 | void x264_audio_encoder_skip_samples( hnd_t encoder, uint64_t samplecount ); 63 | audio_packet_t *x264_audio_encode_frame( hnd_t encoder ); 64 | audio_packet_t *x264_audio_encoder_finish( hnd_t encoder ); 65 | void x264_audio_free_frame( hnd_t encoder, audio_packet_t *frame ); 66 | 67 | void x264_audio_encoder_close( hnd_t encoder ); 68 | void x264_audio_encoder_show_help( int longhelp ); 69 | void x264_audio_encoder_list_codecs( int longhelp ); 70 | void x264_audio_encoder_list_encoders( int longhelp ); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /audio/encoders/enc_raw.c: -------------------------------------------------------------------------------- 1 | #include "audio/encoders.h" 2 | #include "filters/audio/internal.h" 3 | 4 | #include 5 | 6 | typedef struct enc_raw_t 7 | { 8 | audio_info_t info; 9 | int finishing; 10 | hnd_t filter_chain; 11 | int64_t last_sample; 12 | } enc_raw_t; 13 | 14 | static hnd_t init( hnd_t filter_chain, const char *opts ) 15 | { 16 | assert( filter_chain ); 17 | enc_raw_t *h = calloc( 1, sizeof( enc_raw_t ) ); 18 | audio_hnd_t *chain = h->filter_chain = filter_chain; 19 | h->info = chain->info; 20 | 21 | h->info.codec_name = "raw"; 22 | h->info.extradata = NULL; 23 | h->info.extradata_size = 0; 24 | h->info.framelen = h->info.framelen ? h->info.framelen : 1; 25 | h->info.depth = 16; 26 | h->info.chansize = h->info.depth / 8; 27 | h->info.samplesize = h->info.chansize * h->info.channels; 28 | h->info.framesize = h->info.framelen * h->info.samplesize; 29 | h->info.timebase = (timebase_t) { 1, h->info.samplerate }; 30 | 31 | x264_cli_log( "audio", X264_LOG_INFO, "opened raw encoder (%dbits, %dch, %dhz)\n", 32 | h->info.chansize * 8, h->info.channels, h->info.samplerate ); 33 | return h; 34 | } 35 | 36 | static audio_info_t *get_info( hnd_t handle ) 37 | { 38 | assert( handle ); 39 | enc_raw_t *h = handle; 40 | 41 | return &h->info; 42 | } 43 | 44 | static audio_packet_t *get_next_packet( hnd_t handle ) 45 | { 46 | enc_raw_t *h = handle; 47 | if( h->finishing ) 48 | return NULL; 49 | 50 | audio_packet_t *smp = x264_af_get_samples( h->filter_chain, h->last_sample, h->last_sample + h->info.framelen ); 51 | if( !smp ) 52 | return NULL; 53 | 54 | audio_packet_t *out = calloc( 1, sizeof( audio_packet_t ) ); 55 | memcpy( out, smp, sizeof( audio_packet_t ) ); 56 | out->info = h->info; 57 | out->samples = NULL; 58 | out->samplecount = smp->samplecount; 59 | out->data = x264_af_interleave2( SMPFMT_S16, smp->samples, smp->channels, smp->samplecount ); 60 | out->size = smp->samplecount * h->info.samplesize; 61 | out->dts = h->last_sample; 62 | out->info.last_delta = smp->samplecount; 63 | h->last_sample += smp->samplecount; 64 | x264_af_free_packet( smp ); 65 | 66 | return out; 67 | } 68 | 69 | static void skip_samples( hnd_t handle, uint64_t samplecount ) 70 | { 71 | ((enc_raw_t*)handle)->last_sample += samplecount; 72 | } 73 | 74 | static audio_packet_t *finish( hnd_t handle ) 75 | { 76 | ((enc_raw_t*)handle)->finishing = 1; 77 | return NULL; 78 | } 79 | 80 | static void free_packet( hnd_t handle, audio_packet_t *packet ) 81 | { 82 | x264_af_free_packet( packet ); 83 | } 84 | 85 | static void raw_close( hnd_t handle ) 86 | { 87 | free( handle ); 88 | } 89 | 90 | static void raw_help( const char * const codec_name ) 91 | { 92 | printf( " * raw encoder help\n" ); 93 | printf( " Directly pass the decoded PCM samples (in native endian) to muxer.\n" ); 94 | printf( " All audio options except for --acodec and --audiofile are ignored.\n" ); 95 | printf( "\n" ); 96 | } 97 | 98 | const audio_encoder_t audio_encoder_raw = 99 | { 100 | .init = init, 101 | .get_info = get_info, 102 | .get_next_packet = get_next_packet, 103 | .skip_samples = skip_samples, 104 | .finish = finish, 105 | .free_packet = free_packet, 106 | .close = raw_close, 107 | .show_help = raw_help, 108 | .is_valid_encoder = NULL 109 | }; 110 | -------------------------------------------------------------------------------- /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, export=1 52 | .align 2 53 | .if \export == 1 54 | .global EXTERN_ASM\name 55 | ELF .hidden EXTERN_ASM\name 56 | ELF .type EXTERN_ASM\name, %function 57 | .func EXTERN_ASM\name 58 | EXTERN_ASM\name: 59 | .else 60 | ELF .hidden \name 61 | ELF .type \name, %function 62 | .func \name 63 | \name: 64 | .endif 65 | .endm 66 | 67 | .macro movrel rd, val 68 | #if HAVE_ARMV6T2 && !defined(PIC) 69 | movw \rd, #:lower16:\val 70 | movt \rd, #:upper16:\val 71 | #else 72 | ldr \rd, =\val 73 | #endif 74 | .endm 75 | 76 | .macro movconst rd, val 77 | #if HAVE_ARMV6T2 78 | movw \rd, #:lower16:\val 79 | .if \val >> 16 80 | movt \rd, #:upper16:\val 81 | .endif 82 | #else 83 | ldr \rd, =\val 84 | #endif 85 | .endm 86 | 87 | #define GLUE(a, b) a ## b 88 | #define JOIN(a, b) GLUE(a, b) 89 | #define X(s) JOIN(EXTERN_ASM, s) 90 | 91 | #define FENC_STRIDE 16 92 | #define FDEC_STRIDE 32 93 | 94 | .macro HORIZ_ADD dest, a, b 95 | .ifnb \b 96 | vadd.u16 \a, \a, \b 97 | .endif 98 | vpaddl.u16 \a, \a 99 | vpaddl.u32 \dest, \a 100 | .endm 101 | 102 | .macro SUMSUB_AB sum, diff, a, b 103 | vadd.s16 \sum, \a, \b 104 | vsub.s16 \diff, \a, \b 105 | .endm 106 | 107 | .macro SUMSUB_ABCD s1, d1, s2, d2, a, b, c, d 108 | SUMSUB_AB \s1, \d1, \a, \b 109 | SUMSUB_AB \s2, \d2, \c, \d 110 | .endm 111 | 112 | .macro ABS2 a b 113 | vabs.s16 \a, \a 114 | vabs.s16 \b, \b 115 | .endm 116 | 117 | // dist = distance in elements (0 for vertical pass, 1/2 for horizontal passes) 118 | // op = sumsub/amax (sum and diff / maximum of absolutes) 119 | // d1/2 = destination registers 120 | // s1/2 = source registers 121 | .macro HADAMARD dist, op, d1, d2, s1, s2 122 | .if \dist == 1 123 | vtrn.16 \s1, \s2 124 | .else 125 | vtrn.32 \s1, \s2 126 | .endif 127 | .ifc \op, sumsub 128 | SUMSUB_AB \d1, \d2, \s1, \s2 129 | .else 130 | vabs.s16 \s1, \s1 131 | vabs.s16 \s2, \s2 132 | vmax.s16 \d1, \s1, \s2 133 | .endif 134 | .endm 135 | 136 | .macro TRANSPOSE8x8 r0 r1 r2 r3 r4 r5 r6 r7 137 | vtrn.32 \r0, \r4 138 | vtrn.32 \r1, \r5 139 | vtrn.32 \r2, \r6 140 | vtrn.32 \r3, \r7 141 | vtrn.16 \r0, \r2 142 | vtrn.16 \r1, \r3 143 | vtrn.16 \r4, \r6 144 | vtrn.16 \r5, \r7 145 | vtrn.8 \r0, \r1 146 | vtrn.8 \r2, \r3 147 | vtrn.8 \r4, \r5 148 | vtrn.8 \r6, \r7 149 | .endm 150 | 151 | .macro TRANSPOSE4x4 r0 r1 r2 r3 152 | vtrn.16 \r0, \r2 153 | vtrn.16 \r1, \r3 154 | vtrn.8 \r0, \r1 155 | vtrn.8 \r2, \r3 156 | .endm 157 | 158 | .macro TRANSPOSE4x4_16 d0 d1 d2 d3 159 | vtrn.32 \d0, \d2 160 | vtrn.32 \d1, \d3 161 | vtrn.16 \d0, \d1 162 | vtrn.16 \d2, \d3 163 | .endm 164 | -------------------------------------------------------------------------------- /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, export=0 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, export=0 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_PIXELS( int, ssd, neon, ( uint8_t *, intptr_t, uint8_t *, intptr_t, intptr_t ) ) 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_init_arm( int cpu, x264_predict_t pf[12] ) 31 | { 32 | if (!(cpu&X264_CPU_ARMV6)) 33 | return; 34 | 35 | #if !HIGH_BIT_DEPTH 36 | pf[I_PRED_4x4_H] = x264_predict_4x4_h_armv6; 37 | pf[I_PRED_4x4_V] = x264_predict_4x4_v_armv6; 38 | pf[I_PRED_4x4_DC] = x264_predict_4x4_dc_armv6; 39 | pf[I_PRED_4x4_DDR] = x264_predict_4x4_ddr_armv6; 40 | 41 | if (!(cpu&X264_CPU_NEON)) 42 | return; 43 | 44 | pf[I_PRED_4x4_DC_TOP] = x264_predict_4x4_dc_top_neon; 45 | pf[I_PRED_4x4_DDL] = x264_predict_4x4_ddl_neon; 46 | #endif // !HIGH_BIT_DEPTH 47 | } 48 | 49 | void x264_predict_8x8c_init_arm( int cpu, x264_predict_t pf[7] ) 50 | { 51 | if (!(cpu&X264_CPU_NEON)) 52 | return; 53 | 54 | #if !HIGH_BIT_DEPTH 55 | pf[I_PRED_CHROMA_DC] = x264_predict_8x8c_dc_neon; 56 | pf[I_PRED_CHROMA_DC_TOP] = x264_predict_8x8c_dc_top_neon; 57 | pf[I_PRED_CHROMA_DC_LEFT] = x264_predict_8x8c_dc_left_neon; 58 | pf[I_PRED_CHROMA_H] = x264_predict_8x8c_h_neon; 59 | pf[I_PRED_CHROMA_V] = x264_predict_8x8c_v_neon; 60 | pf[I_PRED_CHROMA_P] = x264_predict_8x8c_p_neon; 61 | #endif // !HIGH_BIT_DEPTH 62 | } 63 | 64 | void x264_predict_8x8_init_arm( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ) 65 | { 66 | if (!(cpu&X264_CPU_NEON)) 67 | return; 68 | 69 | #if !HIGH_BIT_DEPTH 70 | pf[I_PRED_8x8_DDL] = x264_predict_8x8_ddl_neon; 71 | pf[I_PRED_8x8_DDR] = x264_predict_8x8_ddr_neon; 72 | pf[I_PRED_8x8_VL] = x264_predict_8x8_vl_neon; 73 | pf[I_PRED_8x8_VR] = x264_predict_8x8_vr_neon; 74 | pf[I_PRED_8x8_DC] = x264_predict_8x8_dc_neon; 75 | pf[I_PRED_8x8_H] = x264_predict_8x8_h_neon; 76 | pf[I_PRED_8x8_HD] = x264_predict_8x8_hd_neon; 77 | pf[I_PRED_8x8_HU] = x264_predict_8x8_hu_neon; 78 | pf[I_PRED_8x8_V] = x264_predict_8x8_v_neon; 79 | #endif // !HIGH_BIT_DEPTH 80 | } 81 | 82 | void x264_predict_16x16_init_arm( int cpu, x264_predict_t pf[7] ) 83 | { 84 | if (!(cpu&X264_CPU_NEON)) 85 | return; 86 | 87 | #if !HIGH_BIT_DEPTH 88 | pf[I_PRED_16x16_DC ] = x264_predict_16x16_dc_neon; 89 | pf[I_PRED_16x16_DC_TOP] = x264_predict_16x16_dc_top_neon; 90 | pf[I_PRED_16x16_DC_LEFT]= x264_predict_16x16_dc_left_neon; 91 | pf[I_PRED_16x16_H ] = x264_predict_16x16_h_neon; 92 | pf[I_PRED_16x16_V ] = x264_predict_16x16_v_neon; 93 | pf[I_PRED_16x16_P ] = x264_predict_16x16_p_neon; 94 | #endif // !HIGH_BIT_DEPTH 95 | } 96 | -------------------------------------------------------------------------------- /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_4x4_dc_armv6( uint8_t *src ); 30 | void x264_predict_4x4_dc_top_neon( uint8_t *src ); 31 | void x264_predict_4x4_v_armv6( 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 | void x264_predict_8x8_init_arm( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ); 62 | void x264_predict_8x8c_init_arm( int cpu, x264_predict_t pf[7] ); 63 | void x264_predict_16x16_init_arm( int cpu, x264_predict_t pf[7] ); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /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 | 41 | int x264_coeff_last4_arm( int16_t * ); 42 | int x264_coeff_last8_arm( int16_t * ); 43 | int x264_coeff_last15_neon( int16_t * ); 44 | int x264_coeff_last16_neon( int16_t * ); 45 | int x264_coeff_last64_neon( int16_t * ); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /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 | typedef struct 35 | { 36 | // pix1 stride = FENC_STRIDE 37 | // pix2 stride = FDEC_STRIDE 38 | // p_dst stride = FDEC_STRIDE 39 | void (*sub4x4_dct) ( dctcoef dct[16], pixel *pix1, pixel *pix2 ); 40 | void (*add4x4_idct) ( pixel *p_dst, dctcoef dct[16] ); 41 | 42 | void (*sub8x8_dct) ( dctcoef dct[4][16], pixel *pix1, pixel *pix2 ); 43 | void (*sub8x8_dct_dc)( dctcoef dct[4], pixel *pix1, pixel *pix2 ); 44 | void (*add8x8_idct) ( pixel *p_dst, dctcoef dct[4][16] ); 45 | void (*add8x8_idct_dc) ( pixel *p_dst, dctcoef dct[4] ); 46 | 47 | void (*sub8x16_dct_dc)( dctcoef dct[8], pixel *pix1, pixel *pix2 ); 48 | 49 | void (*sub16x16_dct) ( dctcoef dct[16][16], pixel *pix1, pixel *pix2 ); 50 | void (*add16x16_idct)( pixel *p_dst, dctcoef dct[16][16] ); 51 | void (*add16x16_idct_dc) ( pixel *p_dst, dctcoef dct[16] ); 52 | 53 | void (*sub8x8_dct8) ( dctcoef dct[64], pixel *pix1, pixel *pix2 ); 54 | void (*add8x8_idct8) ( pixel *p_dst, dctcoef dct[64] ); 55 | 56 | void (*sub16x16_dct8) ( dctcoef dct[4][64], pixel *pix1, pixel *pix2 ); 57 | void (*add16x16_idct8)( pixel *p_dst, dctcoef dct[4][64] ); 58 | 59 | void (*dct4x4dc) ( dctcoef d[16] ); 60 | void (*idct4x4dc)( dctcoef d[16] ); 61 | 62 | void (*dct2x4dc)( dctcoef dct[8], dctcoef dct4x4[8][16] ); 63 | 64 | } x264_dct_function_t; 65 | 66 | typedef struct 67 | { 68 | void (*scan_8x8)( dctcoef level[64], dctcoef dct[64] ); 69 | void (*scan_4x4)( dctcoef level[16], dctcoef dct[16] ); 70 | int (*sub_8x8) ( dctcoef level[64], const pixel *p_src, pixel *p_dst ); 71 | int (*sub_4x4) ( dctcoef level[16], const pixel *p_src, pixel *p_dst ); 72 | int (*sub_4x4ac)( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc ); 73 | void (*interleave_8x8_cavlc)( dctcoef *dst, dctcoef *src, uint8_t *nnz ); 74 | 75 | } x264_zigzag_function_t; 76 | 77 | void x264_dct_init( int cpu, x264_dct_function_t *dctf ); 78 | void x264_dct_init_weights( void ); 79 | void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf_progressive, x264_zigzag_function_t *pf_interlaced ); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /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 | 34 | enum intra_chroma_pred_e 35 | { 36 | I_PRED_CHROMA_DC = 0, 37 | I_PRED_CHROMA_H = 1, 38 | I_PRED_CHROMA_V = 2, 39 | I_PRED_CHROMA_P = 3, 40 | 41 | I_PRED_CHROMA_DC_LEFT = 4, 42 | I_PRED_CHROMA_DC_TOP = 5, 43 | I_PRED_CHROMA_DC_128 = 6 44 | }; 45 | static const uint8_t x264_mb_chroma_pred_mode_fix[7] = 46 | { 47 | I_PRED_CHROMA_DC, I_PRED_CHROMA_H, I_PRED_CHROMA_V, I_PRED_CHROMA_P, 48 | I_PRED_CHROMA_DC, I_PRED_CHROMA_DC,I_PRED_CHROMA_DC 49 | }; 50 | 51 | enum intra16x16_pred_e 52 | { 53 | I_PRED_16x16_V = 0, 54 | I_PRED_16x16_H = 1, 55 | I_PRED_16x16_DC = 2, 56 | I_PRED_16x16_P = 3, 57 | 58 | I_PRED_16x16_DC_LEFT = 4, 59 | I_PRED_16x16_DC_TOP = 5, 60 | I_PRED_16x16_DC_128 = 6, 61 | }; 62 | static const uint8_t x264_mb_pred_mode16x16_fix[7] = 63 | { 64 | I_PRED_16x16_V, I_PRED_16x16_H, I_PRED_16x16_DC, I_PRED_16x16_P, 65 | I_PRED_16x16_DC,I_PRED_16x16_DC,I_PRED_16x16_DC 66 | }; 67 | 68 | enum intra4x4_pred_e 69 | { 70 | I_PRED_4x4_V = 0, 71 | I_PRED_4x4_H = 1, 72 | I_PRED_4x4_DC = 2, 73 | I_PRED_4x4_DDL= 3, 74 | I_PRED_4x4_DDR= 4, 75 | I_PRED_4x4_VR = 5, 76 | I_PRED_4x4_HD = 6, 77 | I_PRED_4x4_VL = 7, 78 | I_PRED_4x4_HU = 8, 79 | 80 | I_PRED_4x4_DC_LEFT = 9, 81 | I_PRED_4x4_DC_TOP = 10, 82 | I_PRED_4x4_DC_128 = 11, 83 | }; 84 | static const int8_t x264_mb_pred_mode4x4_fix[13] = 85 | { 86 | -1, 87 | I_PRED_4x4_V, I_PRED_4x4_H, I_PRED_4x4_DC, 88 | I_PRED_4x4_DDL, I_PRED_4x4_DDR, I_PRED_4x4_VR, 89 | I_PRED_4x4_HD, I_PRED_4x4_VL, I_PRED_4x4_HU, 90 | I_PRED_4x4_DC, I_PRED_4x4_DC, I_PRED_4x4_DC 91 | }; 92 | #define x264_mb_pred_mode4x4_fix(t) x264_mb_pred_mode4x4_fix[(t)+1] 93 | 94 | /* must use the same numbering as intra4x4_pred_e */ 95 | enum intra8x8_pred_e 96 | { 97 | I_PRED_8x8_V = 0, 98 | I_PRED_8x8_H = 1, 99 | I_PRED_8x8_DC = 2, 100 | I_PRED_8x8_DDL= 3, 101 | I_PRED_8x8_DDR= 4, 102 | I_PRED_8x8_VR = 5, 103 | I_PRED_8x8_HD = 6, 104 | I_PRED_8x8_VL = 7, 105 | I_PRED_8x8_HU = 8, 106 | 107 | I_PRED_8x8_DC_LEFT = 9, 108 | I_PRED_8x8_DC_TOP = 10, 109 | I_PRED_8x8_DC_128 = 11, 110 | }; 111 | 112 | void x264_predict_8x8_dc_c ( pixel *src, pixel edge[36] ); 113 | void x264_predict_8x8_h_c ( pixel *src, pixel edge[36] ); 114 | void x264_predict_8x8_v_c ( pixel *src, pixel edge[36] ); 115 | void x264_predict_4x4_dc_c ( pixel *src ); 116 | void x264_predict_4x4_h_c ( pixel *src ); 117 | void x264_predict_4x4_v_c ( pixel *src ); 118 | void x264_predict_16x16_dc_c( pixel *src ); 119 | void x264_predict_16x16_h_c ( pixel *src ); 120 | void x264_predict_16x16_v_c ( pixel *src ); 121 | void x264_predict_16x16_p_c ( pixel *src ); 122 | void x264_predict_8x8c_dc_c ( pixel *src ); 123 | void x264_predict_8x8c_h_c ( pixel *src ); 124 | void x264_predict_8x8c_v_c ( pixel *src ); 125 | void x264_predict_8x8c_p_c ( pixel *src ); 126 | void x264_predict_8x16c_dc_c( pixel *src ); 127 | void x264_predict_8x16c_h_c ( pixel *src ); 128 | void x264_predict_8x16c_v_c ( pixel *src ); 129 | void x264_predict_8x16c_p_c ( pixel *src ); 130 | 131 | void x264_predict_16x16_init ( int cpu, x264_predict_t pf[7] ); 132 | void x264_predict_8x8c_init ( int cpu, x264_predict_t pf[7] ); 133 | void x264_predict_8x16c_init ( int cpu, x264_predict_t pf[7] ); 134 | void x264_predict_4x4_init ( int cpu, x264_predict_t pf[12] ); 135 | void x264_predict_8x8_init ( int cpu, x264_predict8x8_t pf[12], x264_predict_8x8_filter_t *predict_filter ); 136 | 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /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 | #define TRELLIS_PARAMS const int *unquant_mf, const uint8_t *zigzag, int lambda2,\ 61 | int last_nnz, dctcoef *coefs, dctcoef *quant_coefs, dctcoef *dct,\ 62 | uint8_t *cabac_state_sig, uint8_t *cabac_state_last,\ 63 | uint64_t level_state0, uint16_t level_state1 64 | int (*trellis_cabac_4x4)( TRELLIS_PARAMS, int b_ac ); 65 | int (*trellis_cabac_8x8)( TRELLIS_PARAMS, int b_interlaced ); 66 | int (*trellis_cabac_4x4_psy)( TRELLIS_PARAMS, int b_ac, dctcoef *fenc_dct, int psy_trellis ); 67 | int (*trellis_cabac_8x8_psy)( TRELLIS_PARAMS, int b_interlaced, dctcoef *fenc_dct, int psy_trellis ); 68 | int (*trellis_cabac_dc)( TRELLIS_PARAMS, int num_coefs ); 69 | int (*trellis_cabac_chroma_422_dc)( TRELLIS_PARAMS ); 70 | } x264_quant_function_t; 71 | 72 | void x264_quant_init( x264_t *h, int cpu, x264_quant_function_t *pf ); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /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/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 | 32 | #endif 33 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/astrataro/x264_tMod/37160ded01670675ac2d683da3a566499210380a/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_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 | #endif 47 | -------------------------------------------------------------------------------- /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/audio/audio_filters.c: -------------------------------------------------------------------------------- 1 | #include "filters/audio/internal.h" 2 | 3 | #include 4 | 5 | audio_info_t *x264_af_get_info( hnd_t handle ) 6 | { 7 | return &((audio_hnd_t*)handle)->info; 8 | } 9 | 10 | audio_filter_t *x264_af_get_filter( char *name ) 11 | { 12 | #if HAVE_AUDIO 13 | #define CHECK( filter ) \ 14 | extern audio_filter_t audio_filter_##filter; \ 15 | if ( !strcmp( name, audio_filter_##filter.name ) ) \ 16 | return &audio_filter_##filter 17 | #if HAVE_LAVF 18 | CHECK( lavf ); 19 | #endif 20 | #if HAVE_AVS 21 | CHECK( avs ); 22 | #endif 23 | #undef CHECKFLT 24 | #undef CHECK 25 | #endif /* HAVE_AUDIO */ 26 | return NULL; 27 | } 28 | 29 | audio_packet_t *x264_af_get_samples( hnd_t handle, int64_t first_sample, int64_t last_sample ) 30 | { 31 | audio_hnd_t *h = handle; 32 | audio_packet_t *out = h->self->get_samples( h, first_sample, last_sample ); 33 | if( out ) 34 | { 35 | out->owner = h; 36 | return out; 37 | } 38 | return 0; 39 | } 40 | 41 | void x264_af_free_packet( audio_packet_t *pkt ) 42 | { 43 | if( !pkt ) 44 | return; 45 | audio_hnd_t *owner = pkt->owner; 46 | if( owner ) 47 | owner->self->free_packet( owner, pkt ); 48 | else 49 | { 50 | if( pkt->priv ) 51 | free( pkt->priv ); 52 | if( pkt->data ) 53 | free( pkt->data ); 54 | if( pkt->samples && pkt->channels ) 55 | x264_af_free_buffer( pkt->samples, pkt->channels ); 56 | free( pkt ); 57 | } 58 | } 59 | 60 | void x264_af_close( hnd_t chain ) 61 | { 62 | audio_hnd_t *h = chain; 63 | if( h->prev ) 64 | x264_af_close( h->prev ); 65 | h->self->close( h ); 66 | } 67 | -------------------------------------------------------------------------------- /filters/audio/audio_filters.h: -------------------------------------------------------------------------------- 1 | #ifndef FILTERS_AUDIO_AUDIO_FILTERS_H_ 2 | #define FILTERS_AUDIO_AUDIO_FILTERS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "x264cli.h" 8 | #include "filters/filters.h" 9 | 10 | // Ripped from ffmpeg's audioconvert.h 11 | #ifndef AV_CH_FRONT_LEFT 12 | #define AV_CH_FRONT_LEFT 0x00000001 13 | #define AV_CH_FRONT_RIGHT 0x00000002 14 | #define AV_CH_FRONT_CENTER 0x00000004 15 | #define AV_CH_LOW_FREQUENCY 0x00000008 16 | #define AV_CH_BACK_LEFT 0x00000010 17 | #define AV_CH_BACK_RIGHT 0x00000020 18 | #define AV_CH_FRONT_LEFT_OF_CENTER 0x00000040 19 | #define AV_CH_FRONT_RIGHT_OF_CENTER 0x00000080 20 | #define AV_CH_BACK_CENTER 0x00000100 21 | #define AV_CH_SIDE_LEFT 0x00000200 22 | #define AV_CH_SIDE_RIGHT 0x00000400 23 | #define AV_CH_TOP_CENTER 0x00000800 24 | #define AV_CH_TOP_FRONT_LEFT 0x00001000 25 | #define AV_CH_TOP_FRONT_CENTER 0x00002000 26 | #define AV_CH_TOP_FRONT_RIGHT 0x00004000 27 | #define AV_CH_TOP_BACK_LEFT 0x00008000 28 | #define AV_CH_TOP_BACK_CENTER 0x00010000 29 | #define AV_CH_TOP_BACK_RIGHT 0x00020000 30 | #define AV_CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. 31 | #define AV_CH_STEREO_RIGHT 0x40000000 ///< See AV_CH_STEREO_LEFT. 32 | #endif 33 | 34 | enum AudioFlags 35 | { 36 | AUDIO_FLAG_NONE = 0, 37 | AUDIO_FLAG_EOF = 1 38 | }; 39 | 40 | #define INVALID_DTS (INT64_MIN) 41 | 42 | enum extradata_type 43 | { 44 | EXTRADATA_TYPE_LIBAVCODEC = 0, 45 | EXTRADATA_TYPE_LSMASH = 1 46 | }; 47 | 48 | typedef struct timebase_t 49 | { 50 | int64_t num, den; 51 | } timebase_t; 52 | 53 | typedef struct audio_info_t 54 | { 55 | const char *codec_name; 56 | int samplerate; // Sample Rate in Hz 57 | int channels; // How many channels 58 | int64_t chanlayout; // Channel layout (CH_*) 59 | int framelen; // Frame length in samples 60 | size_t framesize; // Frame size in bytes 61 | int chansize; // Bytes per channel per sample (from the encoded audio) 62 | int samplesize; // Bytes per sample (from the encoded audio) 63 | int depth; // Bit depth 64 | timebase_t timebase; 65 | uint8_t *extradata; 66 | int extradata_size; 67 | int extradata_type; 68 | void *opaque; 69 | uint32_t last_delta; 70 | uint32_t priming; 71 | } audio_info_t; 72 | 73 | typedef struct audio_aac_info_t 74 | { 75 | int has_sbr; 76 | } audio_aac_info_t; 77 | 78 | typedef struct audio_dts_info_t 79 | { 80 | lsmash_codec_type_t coding_name; 81 | } audio_dts_info_t; 82 | 83 | typedef struct audio_packet_t { 84 | int64_t dts; 85 | float **samples; 86 | unsigned channels; // could be gotten from info, but is here for convenience since samples depends on it 87 | unsigned samplecount; 88 | uint8_t *data; 89 | int size; 90 | int64_t pos; 91 | enum AudioFlags flags; 92 | hnd_t priv; 93 | hnd_t owner; 94 | audio_info_t info; 95 | } audio_packet_t; 96 | 97 | typedef struct audio_filter_t 98 | { 99 | int (*init)( hnd_t *handle, const char *opts ); 100 | struct audio_packet_t *(*get_samples)( hnd_t handle, int64_t first_sample, int64_t last_sample ); 101 | void (*free_packet)( hnd_t self, struct audio_packet_t *frame ); 102 | void (*close)( hnd_t handle ); 103 | char *name, *longname, *description, *help; 104 | void (*help_callback)( int longhelp ); 105 | } audio_filter_t; 106 | 107 | static inline int64_t x264_convert_timebase( int64_t i, timebase_t from, timebase_t to ) 108 | { 109 | if( !from.den || !to.num ) 110 | return 0; 111 | double j = i; 112 | if( from.den > to.num ) 113 | return (int64_t)( j * from.num * to.den / to.num / from.den ); 114 | return (int64_t)( j * from.num * to.den / from.den / to.num ); 115 | } 116 | 117 | static inline int64_t x264_to_timebase( int64_t i, int64_t scale, timebase_t to ) 118 | { 119 | return x264_convert_timebase( i, (timebase_t){ 1, scale }, to ); 120 | } 121 | 122 | static inline int64_t x264_from_timebase( int64_t i, timebase_t from, int64_t scale ) 123 | { 124 | return x264_convert_timebase( i, from, (timebase_t){ 1, scale } ); 125 | } 126 | 127 | #include "audio/audio.h" 128 | 129 | audio_info_t *x264_af_get_info( hnd_t handle ); 130 | audio_filter_t *x264_af_get_filter( char *name ); 131 | audio_packet_t *x264_af_get_samples( hnd_t handle, int64_t first_sample, int64_t last_sample ); 132 | void x264_af_free_packet( audio_packet_t *pkt ); 133 | void x264_af_close( hnd_t chain ); 134 | 135 | #endif /* AUDIO_H_ */ 136 | -------------------------------------------------------------------------------- /filters/audio/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef FILTERS_AUDIO_INTERNAL_H_ 2 | #define FILTERS_AUDIO_INTERNAL_H_ 3 | 4 | #include "filters/audio/audio_filters.h" 5 | 6 | #define AUDIO_FILTER_COMMON \ 7 | const audio_filter_t *self; \ 8 | audio_info_t info; \ 9 | struct audio_hnd_t *prev; 10 | 11 | #define INIT_FILTER_STRUCT(filterstruct, structname) \ 12 | structname *h; \ 13 | do \ 14 | { \ 15 | h = calloc( 1, sizeof( structname ) ); \ 16 | if( !h ) \ 17 | goto fail; \ 18 | h->self = &filterstruct; \ 19 | h->prev = *handle; \ 20 | if( h->prev ) \ 21 | h->info = h->prev->info; \ 22 | *handle = h; \ 23 | } while( 0 ) 24 | 25 | #define IS_LPCM_CODEC_ID( id ) ((id) >= 0x10000 && (id) < 0x11000) 26 | 27 | // Generic audio handle (used to access fields from AUDIO_FILTER_COMMON) 28 | typedef struct audio_hnd_t 29 | { 30 | AUDIO_FILTER_COMMON 31 | } audio_hnd_t; 32 | 33 | #define AF_LOG( handle, level, ... ) x264_cli_log( ((audio_hnd_t*)handle)->self->name, (level), __VA_ARGS__ ) 34 | 35 | #define AF_LOG_ERR( handle, ... ) AF_LOG( (handle), X264_LOG_ERROR , __VA_ARGS__ ) 36 | #define AF_LOG_WARN( handle, ... ) AF_LOG( (handle), X264_LOG_WARNING, __VA_ARGS__ ) 37 | 38 | enum SampleFmt { 39 | SMPFMT_NONE = -1, 40 | SMPFMT_U8, 41 | SMPFMT_S16, 42 | SMPFMT_S32, 43 | SMPFMT_FLT, 44 | SMPFMT_DBL, 45 | 46 | SMPFMT_U8P, 47 | SMPFMT_S16P, 48 | SMPFMT_S32P, 49 | SMPFMT_FLTP, 50 | SMPFMT_DBLP 51 | }; 52 | 53 | float **x264_af_get_buffer ( unsigned channels, unsigned samplecount ); 54 | int x264_af_resize_buffer( float **buffer, unsigned channels, unsigned samplecount ); 55 | int x264_af_resize_fill_buffer( float **buffer, unsigned out_samplecount, unsigned channels, unsigned in_samplecount, float value ); 56 | void x264_af_free_buffer ( float **buffer, unsigned channels ); 57 | float **x264_af_dup_buffer ( float **buffer, unsigned channels, unsigned samplecount ); 58 | int x264_af_cat_buffer ( float **buf, unsigned bufsamples, float **in, unsigned insamples, unsigned channels ); 59 | 60 | float **x264_af_deinterleave ( float *samples, unsigned channels, unsigned samplecount ); 61 | float *x264_af_interleave ( float **in, unsigned channels, unsigned samplecount ); 62 | 63 | float **x264_af_deinterleave2( uint8_t *samples, enum SampleFmt fmt, unsigned channels, unsigned samplecount ); 64 | uint8_t *x264_af_interleave2 ( enum SampleFmt outfmt, float **in, unsigned channels, unsigned samplecount ); 65 | uint8_t *x264_af_convert ( enum SampleFmt outfmt, uint8_t *in, enum SampleFmt fmt, unsigned channels, unsigned samplecount ); 66 | 67 | uint8_t *x264_af_interleave3 ( enum SampleFmt outfmt, float **in, unsigned channels, unsigned samplecount, int *map ); 68 | 69 | #endif /* FILTERS_AUDIO_INTERNAL_H_ */ 70 | -------------------------------------------------------------------------------- /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/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/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/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/subtitles.h: -------------------------------------------------------------------------------- 1 | enum { 2 | CSRI_F_RGBA = 0, 3 | CSRI_F_ARGB, 4 | CSRI_F_BGRA, 5 | CSRI_F_ABGR, 6 | 7 | CSRI_F_RGB_ = 0x100, 8 | CSRI_F__RGB, 9 | CSRI_F_BGR_, /**< Windows "RGB32" */ 10 | CSRI_F__BGR, 11 | 12 | CSRI_F_RGB = 0x200, 13 | CSRI_F_BGR, /**< Windows "RGB24" */ 14 | 15 | CSRI_F_AYUV = 0x1000, 16 | CSRI_F_YUVA, 17 | CSRI_F_YVUA, 18 | 19 | CSRI_F_YUY2 = 0x1100, 20 | 21 | CSRI_F_YV12A = 0x2011, /**< planar YUV 2x2 + alpha plane */ 22 | CSRI_F_YV12 = 0x2111, /**< planar YUV 2x2 */ 23 | CSRI_F_NV12, 24 | CSRI_F_NV21 25 | }; 26 | 27 | typedef struct { 28 | unsigned pixfmt; 29 | unsigned width; 30 | unsigned height; 31 | } csri_fmt; 32 | 33 | typedef struct { 34 | unsigned pixfmt; 35 | unsigned char *planes[4]; 36 | ptrdiff_t strides[4]; 37 | } csri_frame; 38 | 39 | typedef struct { 40 | const char *name; 41 | const char *specific; 42 | const char *longname; 43 | const char *author; 44 | const char *copyright; 45 | } csri_info; 46 | 47 | typedef union { 48 | int32_t lval; 49 | double dval; 50 | const char *utf8val; 51 | void *otherval; 52 | } csri_vardata; 53 | 54 | typedef struct { 55 | const char *name; 56 | csri_vardata data; 57 | struct csri_openflag *next; 58 | } csri_openflag; 59 | 60 | typedef void* (*csri_open_file_t)(void *renderer, const char *filename, csri_openflag *flags); 61 | typedef int (*csri_add_file_t)(void *inst, const char *filename, csri_openflag *flags); 62 | typedef void (*csri_close_t)(void *inst); 63 | typedef int (*csri_request_fmt_t)(void *inst, const csri_fmt *fmt); 64 | typedef void (*csri_render_t)(void *inst, csri_frame *frame, double time); 65 | 66 | extern csri_render_t csri_render; 67 | #define subtitles_render_frame csri_render 68 | extern csri_close_t csri_close; 69 | #define subtitles_close csri_close 70 | 71 | void* subtitles_new_renderer(const csri_fmt *fmt, uint32_t sarw, uint32_t sarh); 72 | -------------------------------------------------------------------------------- /filters/video/vflip.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * crop.c: vertical flip video filter 3 | ***************************************************************************** 4 | * Copyright (C) 2003-2014 x264 project 5 | * 6 | * Authors: James Darnley 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 | #include "video.h" 28 | #define NAME "vflip" 29 | #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, NAME, __VA_ARGS__ ) 30 | 31 | cli_vid_filter_t vflip_filter; 32 | 33 | typedef struct 34 | { 35 | hnd_t prev_handle; 36 | cli_vid_filter_t prev_filter; 37 | } vflip_handle; 38 | 39 | static void help( int longhelp ) 40 | { 41 | printf( " "NAME" vertically flips the frame\n" ); 42 | } 43 | 44 | static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) 45 | { 46 | vflip_handle *h = calloc( 1, sizeof(vflip_handle) ); 47 | if( !h ) 48 | return -1; 49 | 50 | info->csp ^= X264_CSP_VFLIP; 51 | 52 | h->prev_filter = *filter; 53 | h->prev_handle = *handle; 54 | *handle = h; 55 | *filter = vflip_filter; 56 | 57 | return 0; 58 | } 59 | 60 | static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) 61 | { 62 | vflip_handle *h = handle; 63 | return h->prev_filter.get_frame( h->prev_handle, output, frame ); 64 | } 65 | 66 | static int release_frame( hnd_t handle, cli_pic_t *pic, int frame ) 67 | { 68 | vflip_handle *h = handle; 69 | return h->prev_filter.release_frame( h->prev_handle, pic, frame ); 70 | } 71 | 72 | static void free_filter( hnd_t handle ) 73 | { 74 | vflip_handle *h = handle; 75 | h->prev_filter.free( h->prev_handle ); 76 | free( h ); 77 | } 78 | 79 | cli_vid_filter_t vflip_filter = { NAME, help, init, get_frame, release_frame, free_filter, NULL }; 80 | -------------------------------------------------------------------------------- /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 | #define REGISTER_GPL_VFILTER( name ) \ 46 | if( HAVE_GPL ) REGISTER_VFILTER( name ) 47 | 48 | void x264_register_vid_filters( void ) 49 | { 50 | extern cli_vid_filter_t source_filter; 51 | first_filter = &source_filter; 52 | REGISTER_VFILTER( cache ); 53 | REGISTER_VFILTER( depth ); 54 | REGISTER_VFILTER( fix_vfr_pts ); 55 | 56 | REGISTER_VFILTER( hqdn3d ); 57 | REGISTER_VFILTER( crop ); 58 | REGISTER_VFILTER( pad ); 59 | REGISTER_VFILTER( resize ); 60 | REGISTER_VFILTER( select_every ); 61 | REGISTER_VFILTER( vflip ); 62 | REGISTER_GPL_VFILTER( yadif ); 63 | 64 | #ifdef _WIN32 65 | REGISTER_VFILTER( subtitles ); 66 | #endif 67 | } 68 | 69 | int x264_init_vid_filter( const char *name, hnd_t *handle, cli_vid_filter_t *filter, 70 | video_info_t *info, x264_param_t *param, char *opt_string ) 71 | { 72 | cli_vid_filter_t *filter_i = first_filter; 73 | while( filter_i && strcasecmp( name, filter_i->name ) ) 74 | filter_i = filter_i->next; 75 | FAIL_IF_ERR( !filter_i, "x264", "invalid filter `%s'\n", name ); 76 | if( filter_i->init( handle, filter, info, param, opt_string ) ) 77 | return -1; 78 | 79 | return 0; 80 | } 81 | 82 | void x264_vid_filter_help( int longhelp ) 83 | { 84 | for( cli_vid_filter_t *filter_i = first_filter; filter_i; filter_i = filter_i->next ) 85 | if( filter_i->help ) 86 | filter_i->help( longhelp ); 87 | } 88 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /filters/video/x86/yadif_filter_line.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * yadif_filter_line.c: yadif (yet another deinterlacing filter) 3 | ***************************************************************************** 4 | * Copyright (C) 2006 Michael Niedermayer 5 | * Avisynth port (C) 2007 Alexander G. Balakhnin aka Fizick http://avisynth.org.ru 6 | * x264 port (C) 2013 James Darnley 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 | 23 | void filter_line_mmx2( struct yadif_context *yctx ); 24 | void filter_line_sse2( struct yadif_context *yctx ); 25 | void filter_line_ssse3( struct yadif_context *yctx ); 26 | -------------------------------------------------------------------------------- /filters/video/yadif_filter_line.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * yadif_filter_line.c: yadif (yet another deinterlacing filter) 3 | ***************************************************************************** 4 | * Copyright (C) 2006 Michael Niedermayer 5 | * Avisynth port (C) 2007 Alexander G. Balakhnin aka Fizick http://avisynth.org.ru 6 | * x264 port (C) 2013 James Darnley 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 | 23 | #include "common/common.h" 24 | #include "config.h" 25 | #include "filters/video/yadif_filter_line.h" 26 | #include "x264.h" 27 | 28 | #if HAVE_MMX 29 | # include "x86/yadif_filter_line.h" 30 | #endif 31 | 32 | #define CHECK(j) \ 33 | score = abs( cur[-refs-1+ j] - cur[+refs-1- j] ) \ 34 | + abs( cur[-refs + j] - cur[+refs - j] ) \ 35 | + abs( cur[-refs+1+ j] - cur[+refs+1- j] ); \ 36 | if( score < spatial_score ) \ 37 | { \ 38 | spatial_score = score; \ 39 | spatial_pred = (cur[-refs + j] + cur[+refs - j]) >> 1; 40 | 41 | #define FILTER \ 42 | for( int x = 0; x < w; x++ ) \ 43 | { \ 44 | int score; \ 45 | int c = cur[-refs]; \ 46 | int d = (prev2[0] + next2[0]) >> 1; \ 47 | int e = cur[+refs]; \ 48 | int temporal_diff0 = abs( prev2[0] - next2[0] ); \ 49 | int temporal_diff1 = (abs( prev[-refs] - c ) \ 50 | + abs( prev[+refs] - e )) >> 1; \ 51 | int temporal_diff2 = (abs( next[-refs] - c ) \ 52 | + abs( next[+refs] - e )) >> 1; \ 53 | int diff = X264_MAX3( temporal_diff0>>1, temporal_diff1, temporal_diff2 ); \ 54 | int spatial_pred = (c + e) >> 1; \ 55 | int spatial_score = abs( cur[-refs-1] - cur[+refs-1] ) \ 56 | + abs( c-e ) \ 57 | + abs( cur[-refs+1] - cur[+refs+1] ) \ 58 | - 1; \ 59 | \ 60 | CHECK(-1) CHECK(-2) } } \ 61 | CHECK( 1) CHECK( 2) } } \ 62 | \ 63 | if( yctx->mode < 2 ) \ 64 | { \ 65 | int b = (prev2[-2*refs] + next2[-2*refs]) >> 1; \ 66 | int f = (prev2[+2*refs] + next2[+2*refs]) >> 1; \ 67 | int max = X264_MAX3( d-e, d-c, X264_MIN( b-c, f-e ) ); \ 68 | int min = X264_MIN3( d-e, d-c, X264_MAX( b-c, f-e ) ); \ 69 | diff = X264_MAX3( diff, min, -max ); \ 70 | } \ 71 | \ 72 | if( spatial_pred > d + diff ) \ 73 | spatial_pred = d + diff; \ 74 | else if( spatial_pred < d - diff ) \ 75 | spatial_pred = d - diff; \ 76 | \ 77 | dst[0] = spatial_pred; \ 78 | \ 79 | dst++; \ 80 | cur++; \ 81 | prev++; \ 82 | next++; \ 83 | prev2++; \ 84 | next2++; \ 85 | } 86 | 87 | static void filter_line_c( struct yadif_context *yctx ) 88 | { 89 | int w = yctx->width; 90 | intptr_t refs = yctx->stride; 91 | uint8_t *dst = yctx->output; 92 | const uint8_t *prev = yctx->previous; 93 | const uint8_t *cur = yctx->current; 94 | const uint8_t *next = yctx->next; 95 | const uint8_t *prev2 = yctx->parity ? prev : cur ; 96 | const uint8_t *next2 = yctx->parity ? cur : next; 97 | 98 | FILTER 99 | } 100 | 101 | static void filter_line_c_16bit( struct yadif_context *yctx ) 102 | { 103 | int w = yctx->width; 104 | intptr_t refs = yctx->stride; 105 | uint16_t *dst = (uint16_t *)yctx->output; 106 | const uint16_t *prev = (uint16_t *)yctx->previous; 107 | const uint16_t *cur = (uint16_t *)yctx->current; 108 | const uint16_t *next = (uint16_t *)yctx->next; 109 | const uint16_t *prev2 = yctx->parity ? prev : cur ; 110 | const uint16_t *next2 = yctx->parity ? cur : next; 111 | 112 | FILTER 113 | } 114 | 115 | filter_line_func get_filter_func( unsigned int cpu, int high_depth ) { 116 | filter_line_func ret = filter_line_c; 117 | #if defined ARCH_X86 && defined __GNUC__ && defined HAVE_MMX 118 | if( cpu & X264_CPU_MMXEXT ) 119 | ret = filter_line_mmx2; 120 | if( cpu & (X264_CPU_SSE2|X264_CPU_SSE2_IS_SLOW|X264_CPU_SSE2_IS_FAST) ) 121 | ret = filter_line_sse2; 122 | if( cpu & X264_CPU_SSSE3 ) 123 | ret = filter_line_ssse3; 124 | #endif 125 | if( high_depth ) 126 | ret = filter_line_c_16bit; 127 | return ret; 128 | } 129 | -------------------------------------------------------------------------------- /filters/video/yadif_filter_line.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * yadif_filter_line.h: yadif (yet another deinterlacing filter) 3 | ***************************************************************************** 4 | * Copyright (C) 2006 Michael Niedermayer 5 | * Avisynth port (C) 2007 Alexander G. Balakhnin aka Fizick http://avisynth.org.ru 6 | * x264 port (C) 2013 James Darnley 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 | 23 | #include 24 | 25 | struct yadif_context { 26 | uint8_t *output; 27 | const uint8_t *previous; 28 | const uint8_t *current; 29 | const uint8_t *next; 30 | int mode; 31 | int width; 32 | int stride; 33 | int parity; 34 | }; 35 | 36 | typedef void (*filter_line_func)( struct yadif_context *yctx ); 37 | 38 | filter_line_func get_filter_func( unsigned int cpu, int high_depth ); 39 | -------------------------------------------------------------------------------- /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 | int demuxer_threads; 48 | int b_accurate_fps; 49 | char *lavf_decoder; 50 | } cli_input_opt_t; 51 | 52 | /* properties of the source given by the demuxer */ 53 | typedef struct 54 | { 55 | int colormatrix; 56 | int csp; /* colorspace of the input */ 57 | uint32_t fps_num; 58 | uint32_t fps_den; 59 | int fullrange; /* has 2^bit_depth-1 instead of 219*2^(bit_depth-8) ranges (YUV only) */ 60 | int width; 61 | int height; 62 | int interlaced; 63 | int num_frames; 64 | uint32_t sar_width; 65 | uint32_t sar_height; 66 | int tff; 67 | int thread_safe; /* demuxer is thread_input safe */ 68 | uint32_t timebase_num; 69 | uint32_t timebase_den; 70 | int vfr; 71 | double timebase_convert_multiplier; 72 | } video_info_t; 73 | 74 | /* image data type used by x264cli */ 75 | typedef struct 76 | { 77 | int csp; /* colorspace */ 78 | int width; /* width of the picture */ 79 | int height; /* height of the picture */ 80 | int planes; /* number of planes */ 81 | uint8_t *plane[4]; /* pointers for each plane */ 82 | int stride[4]; /* strides for each plane */ 83 | } cli_image_t; 84 | 85 | typedef struct 86 | { 87 | cli_image_t img; 88 | int64_t pts; /* input pts */ 89 | int64_t duration; /* frame duration - used for vfr */ 90 | void *opaque; /* opaque handle */ 91 | } cli_pic_t; 92 | 93 | typedef struct 94 | { 95 | int (*open_file)( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt ); 96 | int (*picture_alloc)( cli_pic_t *pic, int csp, int width, int height ); 97 | int (*read_frame)( cli_pic_t *pic, hnd_t handle, int i_frame ); 98 | int (*release_frame)( cli_pic_t *pic, hnd_t handle ); 99 | void (*picture_clean)( cli_pic_t *pic ); 100 | int (*close_file)( hnd_t handle ); 101 | hnd_t (*open_audio)( hnd_t handle, int track ); 102 | } cli_input_t; 103 | 104 | extern const cli_input_t raw_input; 105 | extern const cli_input_t y4m_input; 106 | extern const cli_input_t avs_input; 107 | extern cli_input_t thread_input; 108 | extern const cli_input_t lavf_input; 109 | extern const cli_input_t ffms_input; 110 | extern cli_input_t timecode_input; 111 | 112 | extern cli_input_t cli_input; 113 | 114 | /* extended colorspace list that isn't supported by libx264 but by the cli */ 115 | #define X264_CSP_CLI_MAX X264_CSP_MAX /* end of list */ 116 | #define X264_CSP_OTHER 0x4000 /* non x264 colorspace */ 117 | 118 | typedef struct 119 | { 120 | const char *name; 121 | int planes; 122 | float width[4]; 123 | float height[4]; 124 | int mod_width; 125 | int mod_height; 126 | } x264_cli_csp_t; 127 | 128 | extern const x264_cli_csp_t x264_cli_csps[]; 129 | 130 | int x264_cli_csp_is_invalid( int csp ); 131 | int x264_cli_csp_depth_factor( int csp ); 132 | int x264_cli_pic_alloc( cli_pic_t *pic, int csp, int width, int height ); 133 | int x264_cli_pic_alloc_aligned( cli_pic_t *pic, int csp, int width, int height ); 134 | void x264_cli_pic_clean( cli_pic_t *pic ); 135 | uint64_t x264_cli_pic_plane_size( int csp, int width, int height, int plane ); 136 | uint64_t x264_cli_pic_size( int csp, int width, int height ); 137 | const x264_cli_csp_t *x264_cli_get_csp( int csp ); 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /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 | void flv_put_amf_bool( flv_buffer *c, int i ) 87 | { 88 | flv_put_byte( c, AMF_DATA_TYPE_BOOL ); 89 | flv_put_byte( c, !!i ); 90 | } 91 | 92 | /* flv writing functions */ 93 | 94 | flv_buffer *flv_create_writer( const char *filename ) 95 | { 96 | flv_buffer *c = calloc( 1, sizeof(flv_buffer) ); 97 | if( !c ) 98 | return NULL; 99 | 100 | if( !strcmp( filename, "-" ) ) 101 | c->fp = stdout; 102 | else 103 | c->fp = x264_fopen( filename, "wb" ); 104 | if( !c->fp ) 105 | { 106 | free( c ); 107 | return NULL; 108 | } 109 | 110 | return c; 111 | } 112 | 113 | int flv_append_data( flv_buffer *c, uint8_t *data, unsigned size ) 114 | { 115 | unsigned ns = c->d_cur + size; 116 | 117 | if( ns > c->d_max ) 118 | { 119 | void *dp; 120 | unsigned dn = 16; 121 | while( ns > dn ) 122 | dn <<= 1; 123 | 124 | dp = realloc( c->data, dn ); 125 | if( !dp ) 126 | return -1; 127 | 128 | c->data = dp; 129 | c->d_max = dn; 130 | } 131 | 132 | memcpy( c->data + c->d_cur, data, size ); 133 | 134 | c->d_cur = ns; 135 | 136 | return 0; 137 | } 138 | 139 | void flv_rewrite_amf_be24( flv_buffer *c, unsigned length, unsigned start ) 140 | { 141 | *(c->data + start + 0) = length >> 16; 142 | *(c->data + start + 1) = length >> 8; 143 | *(c->data + start + 2) = length >> 0; 144 | } 145 | 146 | int flv_flush_data( flv_buffer *c ) 147 | { 148 | if( !c->d_cur ) 149 | return 0; 150 | 151 | if( fwrite( c->data, c->d_cur, 1, c->fp ) != 1 ) 152 | return -1; 153 | 154 | c->d_total += c->d_cur; 155 | 156 | c->d_cur = 0; 157 | 158 | return 0; 159 | } 160 | -------------------------------------------------------------------------------- /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_RAW = 0 << FLV_AUDIO_CODECID_OFFSET, 83 | FLV_CODECID_ADPCM = 1 << FLV_AUDIO_CODECID_OFFSET, 84 | FLV_CODECID_MP3 = 2 << FLV_AUDIO_CODECID_OFFSET, 85 | FLV_CODECID_PCM = 3 << FLV_AUDIO_CODECID_OFFSET, 86 | FLV_CODECID_AAC = 10 << FLV_AUDIO_CODECID_OFFSET, 87 | }; 88 | 89 | enum 90 | { 91 | FLV_CODECID_H264 = 7, 92 | }; 93 | 94 | enum 95 | { 96 | FLV_FRAME_KEY = 1 << FLV_VIDEO_FRAMETYPE_OFFSET | 7, 97 | FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET | 7, 98 | }; 99 | 100 | typedef enum 101 | { 102 | AMF_DATA_TYPE_NUMBER = 0x00, 103 | AMF_DATA_TYPE_BOOL = 0x01, 104 | AMF_DATA_TYPE_STRING = 0x02, 105 | AMF_DATA_TYPE_OBJECT = 0x03, 106 | AMF_DATA_TYPE_NULL = 0x05, 107 | AMF_DATA_TYPE_UNDEFINED = 0x06, 108 | AMF_DATA_TYPE_REFERENCE = 0x07, 109 | AMF_DATA_TYPE_MIXEDARRAY = 0x08, 110 | AMF_DATA_TYPE_OBJECT_END = 0x09, 111 | AMF_DATA_TYPE_ARRAY = 0x0a, 112 | AMF_DATA_TYPE_DATE = 0x0b, 113 | AMF_DATA_TYPE_LONG_STRING = 0x0c, 114 | AMF_DATA_TYPE_UNSUPPORTED = 0x0d, 115 | } AMFDataType; 116 | 117 | typedef struct flv_buffer 118 | { 119 | uint8_t *data; 120 | unsigned d_cur; 121 | unsigned d_max; 122 | FILE *fp; 123 | uint64_t d_total; 124 | } flv_buffer; 125 | 126 | flv_buffer *flv_create_writer( const char *filename ); 127 | int flv_append_data( flv_buffer *c, uint8_t *data, unsigned size ); 128 | int flv_write_byte( flv_buffer *c, uint8_t *byte ); 129 | int flv_flush_data( flv_buffer *c ); 130 | void flv_rewrite_amf_be24( flv_buffer *c, unsigned length, unsigned start ); 131 | 132 | uint64_t flv_dbl2int( double value ); 133 | void flv_put_byte( flv_buffer *c, uint8_t b ); 134 | void flv_put_be32( flv_buffer *c, uint32_t val ); 135 | void flv_put_be64( flv_buffer *c, uint64_t val ); 136 | void flv_put_be16( flv_buffer *c, uint16_t val ); 137 | void flv_put_be24( flv_buffer *c, uint32_t val ); 138 | void flv_put_tag( flv_buffer *c, const char *tag ); 139 | void flv_put_amf_string( flv_buffer *c, const char *str ); 140 | void flv_put_amf_double( flv_buffer *c, double d ); 141 | void flv_put_amf_bool( flv_buffer *c, int i ); 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /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 | #define MK_MAX_TRACKS 4 36 | 37 | typedef enum { 38 | MK_TRACK_VIDEO = 1, 39 | MK_TRACK_AUDIO = 2 40 | } mk_track_type; 41 | 42 | typedef enum { 43 | MK_LACING_NONE = 0, 44 | MK_LACING_XIPH = 1, 45 | MK_LACING_FIXED = 2, 46 | MK_LACING_EBML = 3 47 | } mk_lacing_type; 48 | 49 | typedef struct { 50 | unsigned width; 51 | unsigned height; 52 | unsigned display_width; 53 | unsigned display_height; 54 | int display_size_units; 55 | int stereo_mode; 56 | } mk_video_info_t; 57 | 58 | typedef struct { 59 | unsigned channels; 60 | unsigned samplerate; 61 | unsigned output_samplerate; 62 | unsigned bit_depth; 63 | } mk_audio_info_t; 64 | 65 | typedef union { 66 | mk_video_info_t v; 67 | mk_audio_info_t a; 68 | } mk_track_info_t; 69 | 70 | typedef struct { 71 | mk_track_type type; 72 | mk_lacing_type lacing; 73 | unsigned id; 74 | const char *codec_id; 75 | void *codec_private; 76 | unsigned codec_private_size; 77 | int64_t default_frame_duration; 78 | mk_track_info_t info; 79 | } mk_track_t; 80 | 81 | typedef struct mk_writer mk_writer; 82 | 83 | mk_writer *mk_create_writer( const char *filename ); 84 | 85 | int mk_write_header( mk_writer *w, const char *writing_app, int64_t timescale, 86 | mk_track_t *tracks, int track_count ); 87 | int mk_start_frame( mk_writer *w ); 88 | int mk_end_frame( mk_writer *w, uint32_t track_id ); 89 | int mk_add_frame_data( mk_writer *w, const void *data, unsigned size ); 90 | int mk_set_frame_flags( mk_writer *w, int64_t timestamp, int keyframe, int skippable, uint32_t track_id ); 91 | int mk_close( mk_writer *w, int64_t *last_delta ); 92 | 93 | /* Supported (or may be supported in the future) audio codecs in x264's matroska muxer. */ 94 | /* We do not care about A_MS/ACM (avi compatible) type codecs. */ 95 | /* For reference, see http://haali.su/mkv/codecs.pdf */ 96 | #if HAVE_AUDIO 97 | #define MK_AUDIO_TAG_AAC "A_AAC" 98 | #define MK_AUDIO_TAG_AC3 "A_AC3" 99 | #define MK_AUDIO_TAG_EAC3 "A_EAC3" 100 | #define MK_AUDIO_TAG_DTS "A_DTS" 101 | #define MK_AUDIO_TAG_FLAC "A_FLAC" 102 | #define MK_AUDIO_TAG_MP1 "A_MPEG/L1" 103 | #define MK_AUDIO_TAG_MP2 "A_MPEG/L2" 104 | #define MK_AUDIO_TAG_MP3 "A_MPEG/L3" 105 | #define MK_AUDIO_TAG_PCM_FLOAT "A_PCM/FLOAT/IEEE" 106 | #define MK_AUDIO_TAG_PCM_LE "A_PCM/INT/LIT" 107 | #define MK_AUDIO_TAG_PCM_BE "A_PCM/INT/BIG" /* Do we need this? */ 108 | #define MK_AUDIO_TAG_MLP "A_MLP" 109 | #define MK_AUDIO_TAG_TRUEHD "A_TRUEHD" 110 | #define MK_AUDIO_TAG_TTA "A_TTA1" 111 | #define MK_AUDIO_TAG_VORBIS "A_VORBIS" 112 | #endif /* HAVE_AUDIO */ 113 | 114 | #endif /* X264_MATROSKA_EBML_H */ 115 | -------------------------------------------------------------------------------- /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 | double display_width; 35 | double display_height; 36 | int use_dts_compress; 37 | int no_sar; 38 | int no_remux; 39 | int fragments; 40 | int mux_mov; 41 | int mux_3gp; 42 | int mux_3g2; 43 | char *chapter; 44 | int add_bom; 45 | char *language; 46 | uint32_t priming; 47 | int no_progress; 48 | } cli_output_opt_t; 49 | 50 | typedef struct 51 | { 52 | int (*open_file)( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt, hnd_t audio_filters, char *audio_encoder, char *audio_parameters ); 53 | int (*set_param)( hnd_t handle, x264_param_t *p_param ); 54 | int (*write_headers)( hnd_t handle, x264_nal_t *p_nal ); 55 | int (*write_frame)( hnd_t handle, uint8_t *p_nal, int i_size, x264_picture_t *p_picture ); 56 | int (*close_file)( hnd_t handle, int64_t largest_pts, int64_t second_largest_pts ); 57 | } cli_output_t; 58 | 59 | extern const cli_output_t raw_output; 60 | extern const cli_output_t mkv_output; 61 | extern const cli_output_t mp4_output; 62 | extern const cli_output_t flv_output; 63 | extern const cli_output_t avi_output; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /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, hnd_t audio_filters, char *audio_enc, char *audio_params ) 30 | { 31 | FAIL_IF_ERR( audio_enc && ( strcmp( audio_enc, "none" ) && strcmp( audio_enc, "auto" ) ), "raw", 32 | "audio is not supported on this muxer\n" ); 33 | 34 | if( !strcmp( psz_filename, "-" ) ) 35 | *p_handle = stdout; 36 | else if( !(*p_handle = x264_fopen( psz_filename, "w+b" )) ) 37 | return -1; 38 | 39 | return 0; 40 | } 41 | 42 | static int set_param( hnd_t handle, x264_param_t *p_param ) 43 | { 44 | return 0; 45 | } 46 | 47 | static int write_headers( hnd_t handle, x264_nal_t *p_nal ) 48 | { 49 | int size = p_nal[0].i_payload + p_nal[1].i_payload + p_nal[2].i_payload; 50 | 51 | if( fwrite( p_nal[0].p_payload, size, 1, (FILE*)handle ) ) 52 | return size; 53 | return -1; 54 | } 55 | 56 | static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_t *p_picture ) 57 | { 58 | if( fwrite( p_nalu, i_size, 1, (FILE*)handle ) ) 59 | return i_size; 60 | return -1; 61 | } 62 | 63 | static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest_pts ) 64 | { 65 | if( !handle || handle == stdout ) 66 | return 0; 67 | 68 | return fclose( (FILE*)handle ); 69 | } 70 | 71 | const cli_output_t raw_output = { open_file, set_param, write_headers, write_frame, close_file }; 72 | 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | [ -n "$1" ] && cd $1 3 | git rev-list HEAD | sort > config.git-hash 4 | LOCAL_VER=`wc -l config.git-hash | awk '{print $1}'` 5 | GIT_HEAD=`git branch --list | grep "*" | awk '{print $2}'` 6 | BIT_DEPTH=`grep "X264_BIT_DEPTH" < x264_config.h | awk '{print $3}'` 7 | CHROMA_FORMATS=`grep "X264_CHROMA_FORMAT" < x264_config.h | awk '{print $3}'` 8 | if [ $CHROMA_FORMATS == "0" ] ; then 9 | CHROMA_FORMATS="all" 10 | elif [ $CHROMA_FORMATS == "X264_CSP_I420" ] ; then 11 | CHROMA_FORMATS="4:2:0" 12 | elif [ $CHROMA_FORMATS == "X264_CSP_I422" ] ; then 13 | CHROMA_FORMATS="4:2:2" 14 | elif [ $CHROMA_FORMATS == "X264_CSP_I444" ] ; then 15 | CHROMA_FORMATS="4:4:4" 16 | fi 17 | BUILD_ARCH=`grep "ARCH=" < config.mak | awk -F= '{print $2}'` 18 | if [ $LOCAL_VER \> 1 ] ; then 19 | PLAIN_VER=`git rev-list porigin/master | sort | join config.git-hash - | wc -l | awk '{print $1}'` 20 | echo "#define X264_REV $PLAIN_VER" 21 | if [ $PLAIN_VER == $LOCAL_VER ] ; then 22 | VER=$PLAIN_VER 23 | else 24 | VER_DIFF=$(($LOCAL_VER-$PLAIN_VER)) 25 | VER="$PLAIN_VER+$VER_DIFF" 26 | fi 27 | echo "#define X264_REV_DIFF $VER_DIFF" 28 | if git status | grep -q "modified:" ; then 29 | VER="${VER}M" 30 | fi 31 | VER="$VER $(git rev-list HEAD -n 1 | cut -c 1-7) $GIT_HEAD [${BIT_DEPTH}-bit@${CHROMA_FORMATS} ${BUILD_ARCH}]" 32 | echo "#define X264_VERSION \" r$VER\"" 33 | else 34 | echo "#define X264_VERSION \"\"" 35 | VER="x [${BIT_DEPTH}-bit@${CHROMA_FORMATS} ${BUILD_ARCH}]" 36 | fi 37 | rm -f config.git-hash 38 | API=`grep '#define X264_BUILD' < x264.h | sed -e 's/.* \([1-9][0-9]*\).*/\1/'` 39 | echo "#define X264_POINTVER \"0.$API.$VER\"" 40 | -------------------------------------------------------------------------------- /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_log_file( char *p_file_name, int i_level, const char *psz_fmt, va_list arg ); 65 | void x264_cli_printf( int i_level, const char *fmt, ... ); 66 | 67 | #ifdef _WIN32 68 | void x264_cli_set_console_title( const char *title ); 69 | int x264_ansi_filename( const char *filename, char *ansi_filename, int size, int create_file ); 70 | #else 71 | #define x264_cli_set_console_title( title ) 72 | #endif 73 | 74 | #define RETURN_IF_ERR( cond, name, ret, ... )\ 75 | if( cond )\ 76 | {\ 77 | x264_cli_log( name, X264_LOG_ERROR, __VA_ARGS__ );\ 78 | return ret;\ 79 | } 80 | 81 | #define FAIL_IF_ERR( cond, name, ... ) RETURN_IF_ERR( cond, name, -1, __VA_ARGS__ ) 82 | 83 | typedef enum 84 | { 85 | RANGE_AUTO = -1, 86 | RANGE_TV, 87 | RANGE_PC 88 | } range_enum; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------