Codebase list x264 / 666921f
Update upstream source from tag 'upstream/0.164.3095+gitbaee400' Update to upstream version '0.164.3095+gitbaee400' with Debian dir c750cd97c0d82f4c7a854439c9f1280440dd297d Rico Tzschichholz 1 year, 11 months ago
206 changed file(s) with 1865 addition(s) and 1673 deletion(s). Raw diff Collapse all Expand all
8080
8181 build-debian-amd64:
8282 extends: .build
83 image: registry.videolan.org/x264-debian-unstable:20190404162201
83 image: registry.videolan.org/x264-debian-unstable:20211206140856
8484 tags:
8585 - docker
8686 - amd64
8888
8989 build-debian-aarch64:
9090 extends: .build
91 image: registry.videolan.org/x264-debian-unstable-aarch64:20190716192245
91 image: registry.videolan.org/x264-debian-unstable-aarch64:20211206141032
9292 tags:
9393 - docker
9494 - aarch64
105105 curl -f -o vlc-contrib-${_TRIPLET}-latest.tar.bz2 ${_CONTRIB_URL}${CONTRIB_NAME}
106106 bunzip2 vlc-contrib-${_TRIPLET}-latest.tar.bz2
107107 tar xvf vlc-contrib-${_TRIPLET}-latest.tar
108 sed -i.bak -e "s#@@CONTRIB_PREFIX@@#${LOCAL_INSTALL_DIR}#g" ${PKG_CONFIG_LIBDIR}/*.pc
108 perl -pi -e "s'@@CONTRIB_PREFIX@@'$(sed -e "s/'/\\\\'/g" <<< "${LOCAL_INSTALL_DIR}")'g" ${PKG_CONFIG_LIBDIR}/*.pc
109109 git clone --depth 1 --branch master https://github.com/l-smash/l-smash.git lsmash
110110 cd lsmash
111111 ./configure --prefix="${LOCAL_INSTALL_DIR}" --target-os="${_TRIPLET}" --cross-prefix="${_TRIPLET}-"
125125
126126 .build-llvm-mingw:
127127 extends: .build
128 image: registry.videolan.org/vlc-debian-llvm-mingw:20200703084018
128 image: registry.videolan.org/vlc-debian-llvm-mingw:20211020094514
129129 tags:
130130 - docker
131131 - amd64
153153 curl -f -o vlc-contrib-${_TRIPLET}-latest.tar.bz2 ${_CONTRIB_URL}${CONTRIB_NAME}
154154 bunzip2 vlc-contrib-${_TRIPLET}-latest.tar.bz2
155155 tar xvf vlc-contrib-${_TRIPLET}-latest.tar
156 sed -i.bak -e "s#@@CONTRIB_PREFIX@@#${LOCAL_INSTALL_DIR}#g" ${PKG_CONFIG_LIBDIR}/*.pc
156 perl -pi -e "s'@@CONTRIB_PREFIX@@'$(sed -e "s/'/\\\\'/g" <<< "${LOCAL_INSTALL_DIR}")'g" ${PKG_CONFIG_LIBDIR}/*.pc
157157 git clone --depth 1 --branch master https://github.com/l-smash/l-smash.git lsmash
158158 cd lsmash
159159 ./configure --prefix="${LOCAL_INSTALL_DIR}" --target-os="${_TRIPLET}" --extra-cflags="${_XCFLAGS}" --extra-ldflags="${_XLDFLAGS}"
5757 N: Laurent Aimar
5858 E: fenrir AT videolan DOT org
5959 C: fenrir
60 D: Intial import, former maintainer
60 D: Initial import, former maintainer
6161 D: x86 asm (mmx/mmx2)
6262 S: France
6363
390390 $(INSTALL) x264$(EXE) $(DESTDIR)$(bindir)
391391
392392 install-lib-dev:
393 $(INSTALL) -d $(DESTDIR)$(includedir) $(DESTDIR)$(libdir)/pkgconfig
393 $(INSTALL) -d $(DESTDIR)$(includedir)
394 $(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig
394395 $(INSTALL) -m 644 $(SRCPATH)/x264.h x264_config.h $(DESTDIR)$(includedir)
395396 $(INSTALL) -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
396397
00 /*****************************************************************************
11 * autocomplete: x264cli shell autocomplete
22 *****************************************************************************
3 * Copyright (C) 2018-2021 x264 project
3 * Copyright (C) 2018-2022 x264 project
44 *
55 * Authors: Henrik Gramner <henrik@gramner.com>
66 *
00 /*****************************************************************************
11 * asm-offsets.c: check asm offsets for aarch64
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /*****************************************************************************
11 * asm-offsets.h: asm offsets for aarch64
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /*****************************************************************************
11 * asm.S: AArch64 utility macros
22 *****************************************************************************
3 * Copyright (C) 2008-2021 x264 project
3 * Copyright (C) 2008-2022 x264 project
44 *
55 * Authors: Mans Rullgard <mans@mansr.com>
66 * David Conrad <lessen42@gmail.com>
00 /*****************************************************************************
11 * bitstream-a.S: aarch64 bitstream functions
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /*****************************************************************************
11 * bitstream.h: aarch64 bitstream functions
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * cabac-a.S: aarch64 cabac
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /****************************************************************************
11 * dct-a.S: aarch64 transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * dct.h: aarch64 transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * deblock.S: aarch64 deblocking
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Mans Rullgard <mans@mansr.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * deblock.h: aarch64 deblocking
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * mc.S: aarch64 motion compensation
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * mc-c.c: aarch64 motion compensation
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
209209 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
210210 intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
211211 uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
212 if( (mvy&3) == 3 ) // explict if() to force conditional add
212 if( (mvy&3) == 3 ) // explicit if() to force conditional add
213213 src1 += i_src_stride;
214214
215215 if( qpel_idx & 5 ) /* qpel interpolation needed */
235235 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
236236 intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
237237 uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
238 if( (mvy&3) == 3 ) // explict if() to force conditional add
238 if( (mvy&3) == 3 ) // explicit if() to force conditional add
239239 src1 += i_src_stride;
240240
241241 if( qpel_idx & 5 ) /* qpel interpolation needed */
00 /*****************************************************************************
11 * mc.h: aarch64 motion compensation
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /*****************************************************************************
11 * pixel.S: aarch64 pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * pixel.h: aarch64 pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * predict.S: aarch64 intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Mans Rullgard <mans@mansr.com>
00 /*****************************************************************************
11 * predict.c: aarch64 intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * predict.h: aarch64 intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /****************************************************************************
11 * quant.S: arm quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * quant.h: arm quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * asm.S: arm utility macros
22 *****************************************************************************
3 * Copyright (C) 2008-2021 x264 project
3 * Copyright (C) 2008-2022 x264 project
44 *
55 * Authors: Mans Rullgard <mans@mansr.com>
66 * David Conrad <lessen42@gmail.com>
00 /*****************************************************************************
11 * bitstream-a.S: arm bitstream functions
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Janne Grunau <janne-x264@jannau.net>
66 *
00 /*****************************************************************************
11 * bitstream.h: arm bitstream functions
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * cpu-a.S: arm cpu detection
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /****************************************************************************
11 * dct-a.S: arm transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Martin Storsjo <martin@martin.st>
00 /*****************************************************************************
11 * dct.h: arm transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /*****************************************************************************
11 * deblock.S: arm deblocking
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Mans Rullgard <mans@mansr.com>
66 * Martin Storsjo <martin@martin.st>
00 /*****************************************************************************
11 * deblock.h: arm deblocking
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * mc.S: arm motion compensation
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Mans Rullgard <mans@mansr.com>
00 /*****************************************************************************
11 * mc-c.c: arm motion compensation
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
217217 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
218218 intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
219219 uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
220 if( (mvy&3) == 3 ) // explict if() to force conditional add
220 if( (mvy&3) == 3 ) // explicit if() to force conditional add
221221 src1 += i_src_stride;
222222
223223 if( qpel_idx & 5 ) /* qpel interpolation needed */
243243 int qpel_idx = ((mvy&3)<<2) + (mvx&3);
244244 intptr_t offset = (mvy>>2)*i_src_stride + (mvx>>2);
245245 uint8_t *src1 = src[x264_hpel_ref0[qpel_idx]] + offset;
246 if( (mvy&3) == 3 ) // explict if() to force conditional add
246 if( (mvy&3) == 3 ) // explicit if() to force conditional add
247247 src1 += i_src_stride;
248248
249249 if( qpel_idx & 5 ) /* qpel interpolation needed */
00 /*****************************************************************************
11 * mc.h: arm motion compensation
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /*****************************************************************************
11 * pixel.S: arm pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * pixel.h: arm pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /*****************************************************************************
11 * predict.S: arm intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Mans Rullgard <mans@mansr.com>
00 /*****************************************************************************
11 * predict.c: arm intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /*****************************************************************************
11 * predict.h: arm intra prediction
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /****************************************************************************
11 * quant.S: arm quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 * Janne Grunau <janne-x264@jannau.net>
00 /*****************************************************************************
11 * quant.h: arm quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: David Conrad <lessen42@gmail.com>
66 *
00 /*****************************************************************************
11 * base.c: misc common functions (bit depth independent)
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
3434 #include <sys/mman.h>
3535 #endif
3636
37 #define X264_ISDIGIT(x) isdigit((unsigned char)(x))
38
3739 /****************************************************************************
3840 * x264_reduce_fraction:
3941 ****************************************************************************/
206208 void *ptr[];
207209 } strdup_buffer;
208210
209 #define BUFFER_OFFSET offsetof(strdup_buffer, ptr)
211 #define BUFFER_OFFSET (int)offsetof(strdup_buffer, ptr)
210212 #define BUFFER_DEFAULT_SIZE 16
211213
212214 char *x264_param_strdup( x264_param_t *param, const char *src )
921923 if( 0 );
922924 OPT("asm")
923925 {
924 p->cpu = isdigit(value[0]) ? atoi(value) :
926 p->cpu = X264_ISDIGIT(value[0]) ? (uint32_t)atoi(value) :
925927 !strcasecmp(value, "auto") || atobool(value) ? x264_cpu_detect() : 0;
926928 if( b_error )
927929 {
992994 b_error |= parse_enum( value, x264_avcintra_flavor_names, &p->i_avcintra_flavor );
993995 OPT("sar")
994996 {
995 b_error = ( 2 != sscanf( value, "%d:%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) &&
996 2 != sscanf( value, "%d/%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) );
997 b_error |= ( 2 != sscanf( value, "%d:%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) &&
998 2 != sscanf( value, "%d/%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) );
997999 }
9981000 OPT("overscan")
9991001 b_error |= parse_enum( value, x264_overscan_names, &p->vui.i_overscan );
10101012 OPT("chromaloc")
10111013 {
10121014 p->vui.i_chroma_loc = atoi(value);
1013 b_error = ( p->vui.i_chroma_loc < 0 || p->vui.i_chroma_loc > 5 );
1015 b_error |= ( p->vui.i_chroma_loc < 0 || p->vui.i_chroma_loc > 5 );
10141016 }
10151017 OPT("mastering-display")
10161018 {
10421044 b_error |= parse_enum( value, x264_transfer_names, &p->i_alternative_transfer );
10431045 OPT("fps")
10441046 {
1045 if( sscanf( value, "%u/%u", &p->i_fps_num, &p->i_fps_den ) != 2 )
1047 int64_t i_fps_num;
1048 int64_t i_fps_den;
1049 if( sscanf( value, "%"SCNd64"/%"SCNd64, &i_fps_num, &i_fps_den ) == 2 )
1050 {
1051 p->i_fps_num = i_fps_num;
1052 p->i_fps_den = i_fps_den;
1053 b_error |= i_fps_num < 1 || i_fps_num > UINT32_MAX || i_fps_den < 1 || i_fps_den > UINT32_MAX;
1054 }
1055 else
10461056 {
10471057 double fps = atof(value);
1048 if( fps > 0.0 && fps <= INT_MAX/1000.0 )
1058 if( fps < 0.0005 || fps > INT_MAX )
1059 b_error = 1;
1060 else if( fps <= INT_MAX/1000.0 )
10491061 {
10501062 p->i_fps_num = (int)(fps * 1000.0 + .5);
10511063 p->i_fps_den = 1000;
00 /*****************************************************************************
11 * base.h: misc common functions (bit depth independent)
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
8181 #define MEM_DYN(x, t) (*(t (*)[])(x))
8282 #else
8383 //older versions of gcc prefer casting to structure instead of array
84 #define MEM_FIX(x, t, s) (*(struct { t a[s]; } (*))(x))
84 #define MEM_FIX(x, t, s) (*(struct { t a[s]; } MAY_ALIAS (*))(x))
8585 //let's set an arbitrary large constant size
8686 #define MEM_DYN(x, t) MEM_FIX(x, t, 4096)
8787 #endif
00 /*****************************************************************************
11 * bitstream.c: bitstream writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Fiona Glaser <fiona@x264.com>
9191 {
9292 /* Size doesn't include the size of the header we're writing now. */
9393 int chunk_size = size - 4;
94 orig_dst[0] = chunk_size >> 24;
95 orig_dst[1] = chunk_size >> 16;
96 orig_dst[2] = chunk_size >> 8;
97 orig_dst[3] = chunk_size >> 0;
94 orig_dst[0] = (uint8_t)(chunk_size >> 24);
95 orig_dst[1] = (uint8_t)(chunk_size >> 16);
96 orig_dst[2] = (uint8_t)(chunk_size >> 8);
97 orig_dst[3] = (uint8_t)(chunk_size >> 0);
9898 }
9999
100100 nal->i_payload = size;
00 /*****************************************************************************
11 * bitstream.h: bitstream writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
00 /*****************************************************************************
11 * cabac.c: arithmetic coder
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
8888 cb->p[-1] += carry;
8989 while( bytes_outstanding > 0 )
9090 {
91 *(cb->p++) = carry-1;
91 *(cb->p++) = (uint8_t)(carry-1);
9292 bytes_outstanding--;
9393 }
94 *(cb->p++) = out;
94 *(cb->p++) = (uint8_t)out;
9595 cb->i_bytes_outstanding = 0;
9696 }
9797 }
142142 {
143143 uint32_t v = val + (1<<exp_bits);
144144 int k = 31 - x264_clz( v );
145 uint32_t x = (bypass_lut[k-exp_bits]<<exp_bits) + v;
145 uint32_t x = ((uint32_t)bypass_lut[k-exp_bits]<<exp_bits) + v;
146146 k = 2*k+1-exp_bits;
147147 int i = ((k-1)&7)+1;
148148 do {
00 /*****************************************************************************
11 * cabac.h: arithmetic coder
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * common.c: misc common functions
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * common.h: misc common functions
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * cpu.c: cpu detection
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
2626
2727 #include "base.h"
2828
29 #if HAVE_POSIXTHREAD && SYS_LINUX
29 #if SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD
30 #include <unistd.h>
31 #endif
32 #if SYS_LINUX
33 #ifdef __ANDROID__
34 #include <unistd.h>
35 #else
3036 #include <sched.h>
37 #endif
3138 #endif
3239 #if SYS_BEOS
3340 #include <kernel/OS.h>
3441 #endif
35 #if SYS_MACOSX || SYS_FREEBSD
42 #if SYS_MACOSX || SYS_OPENBSD || SYS_FREEBSD
3643 #include <sys/types.h>
3744 #include <sys/sysctl.h>
3845 #endif
3946 #if SYS_OPENBSD
40 #include <sys/param.h>
41 #include <sys/sysctl.h>
4247 #include <machine/cpu.h>
4348 #endif
4449
300305 #elif HAVE_ALTIVEC
301306
302307 #if SYS_MACOSX || SYS_OPENBSD || SYS_FREEBSD
303 #include <sys/sysctl.h>
308
304309 uint32_t x264_cpu_detect( void )
305310 {
306311 /* Thank you VLC */
00 /*****************************************************************************
11 * cpu.h: cpu detection
22 *****************************************************************************
3 * Copyright (C) 2004-2021 x264 project
3 * Copyright (C) 2004-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 *
00 /*****************************************************************************
11 * dct.c: transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * dct.h: transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2004-2021 x264 project
3 * Copyright (C) 2004-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 *
00 /*****************************************************************************
11 * deblock.c: deblocking
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
101101 tc++;
102102 }
103103
104 delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
104 delta = x264_clip3( (((q0 - p0 ) * 4) + (p1 - q1) + 4) >> 3, -tc, tc );
105105 pix[-1*xstride] = x264_clip_pixel( p0 + delta ); /* p0' */
106106 pix[ 0*xstride] = x264_clip_pixel( q0 - delta ); /* q0' */
107107 }
142142
143143 if( abs( p0 - q0 ) < alpha && abs( p1 - p0 ) < beta && abs( q1 - q0 ) < beta )
144144 {
145 int delta = x264_clip3( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
145 int delta = x264_clip3( (((q0 - p0 ) * 4) + (p1 - q1) + 4) >> 3, -tc, tc );
146146 pix[-1*xstride] = x264_clip_pixel( p0 + delta ); /* p0' */
147147 pix[ 0*xstride] = x264_clip_pixel( q0 - delta ); /* q0' */
148148 }
314314 if( !M32(bS) || !alpha || !beta )
315315 return;
316316
317 tc[0] = (tc0_table(index_a)[bS[0]] << (BIT_DEPTH-8)) + b_chroma;
318 tc[1] = (tc0_table(index_a)[bS[1]] << (BIT_DEPTH-8)) + b_chroma;
319 tc[2] = (tc0_table(index_a)[bS[2]] << (BIT_DEPTH-8)) + b_chroma;
320 tc[3] = (tc0_table(index_a)[bS[3]] << (BIT_DEPTH-8)) + b_chroma;
317 tc[0] = (tc0_table(index_a)[bS[0]] * (1 << (BIT_DEPTH-8))) + b_chroma;
318 tc[1] = (tc0_table(index_a)[bS[1]] * (1 << (BIT_DEPTH-8))) + b_chroma;
319 tc[2] = (tc0_table(index_a)[bS[2]] * (1 << (BIT_DEPTH-8))) + b_chroma;
320 tc[3] = (tc0_table(index_a)[bS[3]] * (1 << (BIT_DEPTH-8))) + b_chroma;
321321
322322 pf_inter( pix, i_stride, alpha, beta, tc );
323323 }
654654 } while( 0 )
655655
656656 if( !transform_8x8 ) FILTER( 0, 1 );
657 FILTER( 0, 2 );
657 FILTER( 0, 2 );
658658 if( !transform_8x8 ) FILTER( 0, 3 );
659659
660660 if( !transform_8x8 ) FILTER( 1, 1 );
661 FILTER( 1, 2 );
661 FILTER( 1, 2 );
662662 if( !transform_8x8 ) FILTER( 1, 3 );
663663
664664 #undef FILTER
00 /*****************************************************************************
11 * frame.c: frame handling
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * frame.h: frame handling
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * macroblock.c: macroblock common functions
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Fiona Glaser <fiona@x264.com>
66 * Laurent Aimar <fenrir@via.ecp.fr>
12481248 if( h->mb.cache.varref[l][index] >= 0 )\
12491249 {\
12501250 h->mb.cache.varref[l][index] >>= 1;\
1251 h->mb.cache.varmv[l][index][1] <<= 1;\
1251 h->mb.cache.varmv[l][index][1] *= 2;\
12521252 h->mb.cache.mvd[l][index][1] <<= 1;\
12531253 }
12541254 MAP_MVS
00 /*****************************************************************************
11 * macroblock.h: macroblock common functions
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
360360 * uses all neighbors, even those that didn't end up using this ref.
361361 * h->mb. need only valid values from other blocks */
362362 #define x264_mb_predict_mv_ref16x16 x264_template(mb_predict_mv_ref16x16)
363 void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t mvc[8][2], int *i_mvc );
363 void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t (*mvc)[2], int *i_mvc );
364364
365365 #define x264_mb_mc x264_template(mb_mc)
366366 void x264_mb_mc( x264_t *h );
394394 static ALWAYS_INLINE uint32_t pack16to32_mask( int a, int b )
395395 {
396396 #if WORDS_BIGENDIAN
397 return (b&0xFFFF) + (a<<16);
398 #else
399 return (a&0xFFFF) + (b<<16);
397 return (b&0xFFFF) + ((uint32_t)a<<16);
398 #else
399 return (a&0xFFFF) + ((uint32_t)b<<16);
400400 #endif
401401 }
402402 static ALWAYS_INLINE uint64_t pack32to64( uint32_t a, uint32_t b )
00 /*****************************************************************************
11 * mc.c: motion compensation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
115115 static void mc_weight( pixel *dst, intptr_t i_dst_stride, pixel *src, intptr_t i_src_stride,
116116 const x264_weight_t *weight, int i_width, int i_height )
117117 {
118 int offset = weight->i_offset << (BIT_DEPTH-8);
118 int offset = weight->i_offset * (1 << (BIT_DEPTH-8));
119119 int scale = weight->i_scale;
120120 int denom = weight->i_denom;
121121 if( denom >= 1 )
422422 int v = pix[0]+pix[1]+pix[2]+pix[3];
423423 for( int x = 0; x < stride-4; x++ )
424424 {
425 sum[x] = v + sum[x-stride];
425 sum[x] = (uint16_t)(v + sum[x-stride]);
426426 v += pix[x+4] - pix[x];
427427 }
428428 }
432432 int v = pix[0]+pix[1]+pix[2]+pix[3]+pix[4]+pix[5]+pix[6]+pix[7];
433433 for( int x = 0; x < stride-8; x++ )
434434 {
435 sum[x] = v + sum[x-stride];
435 sum[x] = (uint16_t)(v + sum[x-stride]);
436436 v += pix[x+8] - pix[x];
437437 }
438438 }
440440 static void integral_init4v( uint16_t *sum8, uint16_t *sum4, intptr_t stride )
441441 {
442442 for( int x = 0; x < stride-8; x++ )
443 sum4[x] = sum8[x+4*stride] - sum8[x];
443 sum4[x] = (uint16_t)(sum8[x+4*stride] - sum8[x]);
444444 for( int x = 0; x < stride-8; x++ )
445 sum8[x] = sum8[x+8*stride] + sum8[x+8*stride+4] - sum8[x] - sum8[x+4];
445 sum8[x] = (uint16_t)(sum8[x+8*stride] + sum8[x+8*stride+4] - sum8[x] - sum8[x+4]);
446446 }
447447
448448 static void integral_init8v( uint16_t *sum8, intptr_t stride )
449449 {
450450 for( int x = 0; x < stride-8; x++ )
451 sum8[x] = sum8[x+8*stride] - sum8[x];
451 sum8[x] = (uint16_t)(sum8[x+8*stride] - sum8[x]);
452452 }
453453
454454 void x264_frame_init_lowres( x264_t *h, x264_frame_t *frame )
549549
550550 int x = mvs[i][0];
551551 int y = mvs[i][1];
552 unsigned mbx = (x>>5)+i;
553 unsigned mby = (y>>5)+mb_y;
552 unsigned mbx = (unsigned)((x>>5)+i);
553 unsigned mby = (unsigned)((y>>5)+mb_y);
554554 unsigned idx0 = mbx + mby * stride;
555555 unsigned idx2 = idx0 + stride;
556556 x &= 31;
00 /*****************************************************************************
11 * mc.h: motion compensation
22 *****************************************************************************
3 * Copyright (C) 2004-2021 x264 project
3 * Copyright (C) 2004-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 *
6060 if( !(lowres_costs[i] & (1 << (list+LOWRES_COST_SHIFT))) )\
6161 continue;\
6262 \
63 unsigned mbx = current[0];\
64 unsigned mby = current[1];\
63 unsigned mbx = (unsigned)current[0];\
64 unsigned mby = (unsigned)current[1];\
6565 unsigned idx0 = mbx + mby * stride;\
6666 unsigned idx2 = idx0 + stride;\
6767 \
00 /*****************************************************************************
11 * dct-c.c: msa transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * dct.h: msa transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * deblock-c.c: msa deblocking
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Neha Rana <neha.rana@imgtec.com>
66 *
00 /*****************************************************************************
11 * deblock.h: msa deblocking
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * macros.h: msa macros
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * mc-c.c: msa motion compensation
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Neha Rana <neha.rana@imgtec.com>
66 *
00 /*****************************************************************************
11 * mc.h: msa motion compensation
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Neha Rana <neha.rana@imgtec.com>
66 *
00 /*****************************************************************************
11 * pixel-c.c: msa pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Mandar Sahastrabuddhe <mandar.sahastrabuddhe@imgtec.com>
66 *
00 /*****************************************************************************
11 * pixel.h: msa pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Mandar Sahastrabuddhe <mandar.sahastrabuddhe@imgtec.com>
66 *
00 /*****************************************************************************
11 * predict-c.c: msa intra prediction
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Mandar Sahastrabuddhe <mandar.sahastrabuddhe@imgtec.com>
66 *
00 /*****************************************************************************
11 * predict.h: msa intra prediction
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * quant-c.c: msa quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * quant.h: msa quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Rishikesh More <rishikesh.more@imgtec.com>
66 *
00 /*****************************************************************************
11 * mvpred.c: motion vector prediction
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
170170 int16_t *mv_b = h->mb.cache.mv[0][X264_SCAN8_0 - 8];
171171
172172 if( i_refa == -2 || i_refb == -2 ||
173 !( i_refa | M32( mv_a ) ) ||
174 !( i_refb | M32( mv_b ) ) )
173 !( (uint32_t)i_refa | M32( mv_a ) ) ||
174 !( (uint32_t)i_refb | M32( mv_b ) ) )
175175 {
176176 M32( mv ) = 0;
177177 }
256256
257257 int i_part_8x8 = i_mb_8x8 + x8 + (ypart>>1) * h->mb.i_b8_stride;
258258 int i_ref1_ref = h->fref[1][0]->ref[0][i_part_8x8];
259 int i_ref = (map_col_to_list0(i_ref1_ref>>preshift) << postshift) + (offset&i_ref1_ref&MB_INTERLACED);
259 int i_ref = (map_col_to_list0(i_ref1_ref>>preshift) * (1 << postshift)) + (offset&i_ref1_ref&MB_INTERLACED);
260260
261261 if( i_ref >= 0 )
262262 {
263263 int dist_scale_factor = h->mb.dist_scale_factor[i_ref][0];
264264 int16_t *mv_col = h->fref[1][0]->mv[0][i_mb_4x4 + 3*x8 + ypart * h->mb.i_b4_stride];
265 int16_t mv_y = (mv_col[1]<<yshift)/2;
265 int16_t mv_y = (mv_col[1] * (1 << yshift)) / 2;
266266 int l0x = ( dist_scale_factor * mv_col[0] + 128 ) >> 8;
267267 int l0y = ( dist_scale_factor * mv_y + 128 ) >> 8;
268268 if( h->param.i_threads > 1 && (l0y > h->mb.mv_max_spel[1] || l0y-mv_y > h->mb.mv_max_spel[1]) )
303303 mv_c = h->mb.cache.mv[i_list][X264_SCAN8_0 - 8 - 1];
304304 }
305305
306 int i_ref = X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
306 int i_ref = (int)X264_MIN3( (unsigned)i_refa, (unsigned)i_refb, (unsigned)i_refc );
307307 if( i_ref < 0 )
308308 {
309309 i_ref = -1;
469469 {
470470 int changed;
471471
472 changed = M32( h->mb.cache.direct_mv[0][0] ) ^ M32( h->mb.cache.mv[0][x264_scan8[0]] );
473 changed |= M32( h->mb.cache.direct_mv[1][0] ) ^ M32( h->mb.cache.mv[1][x264_scan8[0]] );
472 changed = (int)(M32( h->mb.cache.direct_mv[0][0] ) ^ M32( h->mb.cache.mv[0][x264_scan8[0]] ));
473 changed |= (int)(M32( h->mb.cache.direct_mv[1][0] ) ^ M32( h->mb.cache.mv[1][x264_scan8[0]] ));
474474 changed |= h->mb.cache.direct_ref[0][0] ^ h->mb.cache.ref[0][x264_scan8[0]];
475475 changed |= h->mb.cache.direct_ref[1][0] ^ h->mb.cache.ref[1][x264_scan8[0]];
476476 if( !changed && h->mb.i_partition != D_16x16 )
477477 {
478 changed |= M32( h->mb.cache.direct_mv[0][3] ) ^ M32( h->mb.cache.mv[0][x264_scan8[12]] );
479 changed |= M32( h->mb.cache.direct_mv[1][3] ) ^ M32( h->mb.cache.mv[1][x264_scan8[12]] );
478 changed |= (int)(M32( h->mb.cache.direct_mv[0][3] ) ^ M32( h->mb.cache.mv[0][x264_scan8[12]] ));
479 changed |= (int)(M32( h->mb.cache.direct_mv[1][3] ) ^ M32( h->mb.cache.mv[1][x264_scan8[12]] ));
480480 changed |= h->mb.cache.direct_ref[0][3] ^ h->mb.cache.ref[0][x264_scan8[12]];
481481 changed |= h->mb.cache.direct_ref[1][3] ^ h->mb.cache.ref[1][x264_scan8[12]];
482482 }
483483 if( !changed && h->mb.i_partition == D_8x8 )
484484 {
485 changed |= M32( h->mb.cache.direct_mv[0][1] ) ^ M32( h->mb.cache.mv[0][x264_scan8[4]] );
486 changed |= M32( h->mb.cache.direct_mv[1][1] ) ^ M32( h->mb.cache.mv[1][x264_scan8[4]] );
487 changed |= M32( h->mb.cache.direct_mv[0][2] ) ^ M32( h->mb.cache.mv[0][x264_scan8[8]] );
488 changed |= M32( h->mb.cache.direct_mv[1][2] ) ^ M32( h->mb.cache.mv[1][x264_scan8[8]] );
485 changed |= (int)(M32( h->mb.cache.direct_mv[0][1] ) ^ M32( h->mb.cache.mv[0][x264_scan8[4]] ));
486 changed |= (int)(M32( h->mb.cache.direct_mv[1][1] ) ^ M32( h->mb.cache.mv[1][x264_scan8[4]] ));
487 changed |= (int)(M32( h->mb.cache.direct_mv[0][2] ) ^ M32( h->mb.cache.mv[0][x264_scan8[8]] ));
488 changed |= (int)(M32( h->mb.cache.direct_mv[1][2] ) ^ M32( h->mb.cache.mv[1][x264_scan8[8]] ));
489489 changed |= h->mb.cache.direct_ref[0][1] ^ h->mb.cache.ref[0][x264_scan8[4]];
490490 changed |= h->mb.cache.direct_ref[1][1] ^ h->mb.cache.ref[1][x264_scan8[4]];
491491 changed |= h->mb.cache.direct_ref[0][2] ^ h->mb.cache.ref[0][x264_scan8[8]];
515515 }
516516
517517 /* This just improves encoder performance, it's not part of the spec */
518 void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t mvc[9][2], int *i_mvc )
518 void x264_mb_predict_mv_ref16x16( x264_t *h, int i_list, int i_ref, int16_t (*mvc)[2], int *i_mvc )
519519 {
520520 int16_t (*mvr)[2] = h->mb.mvr[i_list][i_ref];
521521 int i = 0;
532532 int shift = 1 + MB_INTERLACED - h->mb.field[xy]; \
533533 int16_t *mvp = h->mb.mvr[i_list][i_ref<<1>>shift][xy]; \
534534 mvc[i][0] = mvp[0]; \
535 mvc[i][1] = mvp[1]<<1>>shift; \
535 mvc[i][1] = mvp[1]*2>>shift; \
536536 i++; \
537537 }
538538
589589 { \
590590 int mb_index = h->mb.i_mb_xy + dx + dy*h->mb.i_mb_stride; \
591591 int scale = (curpoc - refpoc) * l0->inv_ref_poc[MB_INTERLACED&field]; \
592 mvc[i][0] = (l0->mv16x16[mb_index][0]*scale + 128) >> 8; \
593 mvc[i][1] = (l0->mv16x16[mb_index][1]*scale + 128) >> 8; \
592 mvc[i][0] = x264_clip3( (l0->mv16x16[mb_index][0]*scale + 128) >> 8, INT16_MIN, INT16_MAX ); \
593 mvc[i][1] = x264_clip3( (l0->mv16x16[mb_index][1]*scale + 128) >> 8, INT16_MIN, INT16_MAX ); \
594594 i++; \
595595 }
596596
00 /*****************************************************************************
11 * opencl.c: OpenCL initialization and kernel compilation
22 *****************************************************************************
3 * Copyright (C) 2012-2021 x264 project
3 * Copyright (C) 2012-2022 x264 project
44 *
55 * Authors: Steve Borho <sborho@multicorewareinc.com>
66 * Anton Mitrofanov <BugMaster@narod.ru>
00 /*****************************************************************************
11 * opencl.h: OpenCL structures and defines
22 *****************************************************************************
3 * Copyright (C) 2012-2021 x264 project
3 * Copyright (C) 2012-2022 x264 project
44 *
55 * Authors: Steve Borho <sborho@multicorewareinc.com>
66 * Anton Mitrofanov <BugMaster@narod.ru>
00 /*****************************************************************************
11 * osdep.c: platform-specific code
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * osdep.h: platform-specific code
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
288288 #define ALIGNED_8( var ) DECLARE_ALIGNED( var, 8 )
289289 #define ALIGNED_16( var ) DECLARE_ALIGNED( var, 16 )
290290
291 // ARM compiliers don't reliably align stack variables
291 // ARM compilers don't reliably align stack variables
292292 // - EABI requires only 8 byte stack alignment to be maintained
293293 // - gcc can't align stack variables to more even if the stack were to be correctly aligned outside the function
294294 // - armcc can't either, but is nice enough to actually tell you so
495495 }
496496 static ALWAYS_INLINE uint16_t endian_fix16( uint16_t x )
497497 {
498 return (x<<8)|(x>>8);
498 return (uint16_t)((x<<8)|(x>>8));
499499 }
500500 #endif
501501
551551 #define x264_prefetch(x)
552552 #endif
553553
554 #if HAVE_POSIXTHREAD
555 #if SYS_WINDOWS
556 #define x264_lower_thread_priority(p)\
557 {\
558 x264_pthread_t handle = pthread_self();\
559 struct sched_param sp;\
560 int policy = SCHED_OTHER;\
561 pthread_getschedparam( handle, &policy, &sp );\
562 sp.sched_priority -= p;\
563 pthread_setschedparam( handle, policy, &sp );\
564 }
565 #elif SYS_HAIKU
566 #include <OS.h>
567 #define x264_lower_thread_priority(p)\
568 { UNUSED status_t nice_ret = set_thread_priority( find_thread( NULL ), B_LOW_PRIORITY ); }
569 #else
570 #include <unistd.h>
571 #define x264_lower_thread_priority(p) { UNUSED int nice_ret = nice(p); }
572 #endif /* SYS_WINDOWS */
573 #elif HAVE_WIN32THREAD
574 #define x264_lower_thread_priority(p) SetThreadPriority( GetCurrentThread(), X264_MAX( -2, -p ) )
575 #else
576 #define x264_lower_thread_priority(p)
577 #endif
578
579554 #endif /* X264_OSDEP_H */
00 /*****************************************************************************
11 * pixel.c: pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
266266 sum2_t sum = 0;
267267 for( int i = 0; i < 4; i++, pix1 += i_pix1, pix2 += i_pix2 )
268268 {
269 a0 = pix1[0] - pix2[0];
270 a1 = pix1[1] - pix2[1];
269 a0 = (sum2_t)(pix1[0] - pix2[0]);
270 a1 = (sum2_t)(pix1[1] - pix2[1]);
271271 b0 = (a0+a1) + ((a0-a1)<<BITS_PER_SUM);
272 a2 = pix1[2] - pix2[2];
273 a3 = pix1[3] - pix2[3];
272 a2 = (sum2_t)(pix1[2] - pix2[2]);
273 a3 = (sum2_t)(pix1[3] - pix2[3]);
274274 b1 = (a2+a3) + ((a2-a3)<<BITS_PER_SUM);
275275 tmp[i][0] = b0 + b1;
276276 tmp[i][1] = b0 - b1;
291291 sum2_t sum = 0;
292292 for( int i = 0; i < 4; i++, pix1 += i_pix1, pix2 += i_pix2 )
293293 {
294 a0 = (pix1[0] - pix2[0]) + ((sum2_t)(pix1[4] - pix2[4]) << BITS_PER_SUM);
295 a1 = (pix1[1] - pix2[1]) + ((sum2_t)(pix1[5] - pix2[5]) << BITS_PER_SUM);
296 a2 = (pix1[2] - pix2[2]) + ((sum2_t)(pix1[6] - pix2[6]) << BITS_PER_SUM);
297 a3 = (pix1[3] - pix2[3]) + ((sum2_t)(pix1[7] - pix2[7]) << BITS_PER_SUM);
294 a0 = (sum2_t)(pix1[0] - pix2[0]) + ((sum2_t)(pix1[4] - pix2[4]) << BITS_PER_SUM);
295 a1 = (sum2_t)(pix1[1] - pix2[1]) + ((sum2_t)(pix1[5] - pix2[5]) << BITS_PER_SUM);
296 a2 = (sum2_t)(pix1[2] - pix2[2]) + ((sum2_t)(pix1[6] - pix2[6]) << BITS_PER_SUM);
297 a3 = (sum2_t)(pix1[3] - pix2[3]) + ((sum2_t)(pix1[7] - pix2[7]) << BITS_PER_SUM);
298298 HADAMARD4( tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], a0,a1,a2,a3 );
299299 }
300300 for( int i = 0; i < 4; i++ )
335335 sum2_t sum = 0;
336336 for( int i = 0; i < 8; i++, pix1 += i_pix1, pix2 += i_pix2 )
337337 {
338 a0 = pix1[0] - pix2[0];
339 a1 = pix1[1] - pix2[1];
338 a0 = (sum2_t)(pix1[0] - pix2[0]);
339 a1 = (sum2_t)(pix1[1] - pix2[1]);
340340 b0 = (a0+a1) + ((a0-a1)<<BITS_PER_SUM);
341 a2 = pix1[2] - pix2[2];
342 a3 = pix1[3] - pix2[3];
341 a2 = (sum2_t)(pix1[2] - pix2[2]);
342 a3 = (sum2_t)(pix1[3] - pix2[3]);
343343 b1 = (a2+a3) + ((a2-a3)<<BITS_PER_SUM);
344 a4 = pix1[4] - pix2[4];
345 a5 = pix1[5] - pix2[5];
344 a4 = (sum2_t)(pix1[4] - pix2[4]);
345 a5 = (sum2_t)(pix1[5] - pix2[5]);
346346 b2 = (a4+a5) + ((a4-a5)<<BITS_PER_SUM);
347 a6 = pix1[6] - pix2[6];
348 a7 = pix1[7] - pix2[7];
347 a6 = (sum2_t)(pix1[6] - pix2[6]);
348 a7 = (sum2_t)(pix1[7] - pix2[7]);
349349 b3 = (a6+a7) + ((a6-a7)<<BITS_PER_SUM);
350350 HADAMARD4( tmp[i][0], tmp[i][1], tmp[i][2], tmp[i][3], b0,b1,b2,b3 );
351351 }
00 /*****************************************************************************
11 * pixel.c: pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2004-2021 x264 project
3 * Copyright (C) 2004-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
00 /*****************************************************************************
11 * dct.c: ppc transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 * Eric Petit <eric.petit@lapsus.org>
00 /*****************************************************************************
11 * dct.h: ppc transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 * Guillaume Poirier <gpoirier@mplayerhq.hu>
00 /*****************************************************************************
11 * deblock.c: ppc deblocking
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 *
00 /*****************************************************************************
11 * deblock.h: ppc deblocking
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * mc.c: ppc motion compensation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 * Guillaume Poirier <gpoirier@mplayerhq.hu>
00 /*****************************************************************************
11 * mc.h: ppc motion compensation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 *
00 /*****************************************************************************
11 * pixel.c: ppc pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 * Guillaume Poirier <gpoirier@mplayerhq.hu>
12611261 SA8D_1D_ALTIVEC(sa8d0v, sa8d1v, sa8d2v, sa8d3v,
12621262 sa8d4v, sa8d5v, sa8d6v, sa8d7v );
12631263
1264 /* accumulation of the absolute value of all elements of the resulting bloc */
1264 /* accumulation of the absolute value of all elements of the resulting block */
12651265 vec_s16_t abs0v = VEC_ABS(sa8d0v);
12661266 vec_s16_t abs1v = VEC_ABS(sa8d1v);
12671267 vec_s16_t sum01v = vec_add(abs0v, abs1v);
00 /*****************************************************************************
11 * pixel.h: ppc pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 *
00 /*****************************************************************************
11 * ppccommon.h: ppc utility macros
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Eric Petit <eric.petit@lapsus.org>
66 *
00 /*****************************************************************************
11 * predict.c: ppc intra prediction
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 *
00 /*****************************************************************************
11 * predict.h: ppc intra prediction
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 *
00 /*****************************************************************************
11 * quant.c: ppc quantization
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 *
00 /*****************************************************************************
11 * quant.h: ppc quantization
22 *****************************************************************************
3 * Copyright (C) 2007-2021 x264 project
3 * Copyright (C) 2007-2022 x264 project
44 *
55 * Authors: Guillaume Poirier <gpoirier@mplayerhq.hu>
66 *
00 /*****************************************************************************
11 * predict.c: intra prediction
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * predict.h: intra prediction
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * quant.c: quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
4646 #define QUANT_ONE( coef, mf, f ) \
4747 { \
4848 if( (coef) > 0 ) \
49 (coef) = (f + (coef)) * (mf) >> 16; \
49 (coef) = ((f) + (uint32_t)(coef)) * (mf) >> 16; \
5050 else \
51 (coef) = - ((f - (coef)) * (mf) >> 16); \
51 (coef) = -(int32_t)(((f) + (uint32_t)(-coef)) * (mf) >> 16); \
5252 nz |= (coef); \
5353 }
5454
100100 }
101101
102102 #define DEQUANT_SHL( x ) \
103 dct[x] = ( dct[x] * dequant_mf[i_mf][x] ) << i_qbits
103 dct[x] = ( dct[x] * dequant_mf[i_mf][x] ) * (1 << i_qbits)
104104
105105 #define DEQUANT_SHR( x ) \
106106 dct[x] = ( dct[x] * dequant_mf[i_mf][x] + f ) >> (-i_qbits)
00 /*****************************************************************************
11 * quant.h: quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
00 /*****************************************************************************
11 * rectangle.c: rectangle filling
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Fiona Glaser <fiona@x264.com>
66 *
00 /*****************************************************************************
11 * rectangle.h: rectangle filling
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Fiona Glaser <fiona@x264.com>
66 * Loren Merritt <lorenm@u.washington.edu>
2727 static ALWAYS_INLINE void x264_macroblock_cache_rect( void *dst, int w, int h, int s, uint32_t v )
2828 {
2929 uint8_t *d = dst;
30 uint16_t v2 = s == 2 ? v : v * 0x101;
31 uint32_t v4 = s == 4 ? v : s == 2 ? v * 0x10001 : v * 0x1010101;
30 uint16_t v2 = s >= 2 ? v : v * 0x101;
31 uint32_t v4 = s >= 4 ? v : s >= 2 ? v * 0x10001 : v * 0x1010101;
3232 uint64_t v8 = v4 + ((uint64_t)v4 << 32);
3333 s *= 8;
3434
141141 else
142142 x264_macroblock_cache_rect( mvd_cache, width*2, height, 2, mvd );
143143 }
144 static ALWAYS_INLINE void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, uint8_t ref )
144 static ALWAYS_INLINE void x264_macroblock_cache_ref( x264_t *h, int x, int y, int width, int height, int i_list, int8_t ref )
145145 {
146146 void *ref_cache = &h->mb.cache.ref[i_list][X264_SCAN8_0+x+8*y];
147147 if( x264_nonconstant_p( width ) || x264_nonconstant_p( height ) )
148 x264_cache_ref_func_table[width + (height<<1)-3]( ref_cache, ref );
148 x264_cache_ref_func_table[width + (height<<1)-3]( ref_cache, (uint8_t)ref );
149149 else
150 x264_macroblock_cache_rect( ref_cache, width, height, 1, ref );
150 x264_macroblock_cache_rect( ref_cache, width, height, 1, (uint8_t)ref );
151151 }
152152 static ALWAYS_INLINE void x264_macroblock_cache_skip( x264_t *h, int x, int y, int width, int height, int b_skip )
153153 {
00 /*****************************************************************************
11 * set.c: quantization init
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 *
157157 quant8_mf[i_list][q][i] = DIV(def_quant8[q][i] * 16, h->sps->scaling_list[4+i_list][i]);
158158 }
159159 }
160
161 #define MAX_MF X264_MIN( 0xffff, (1 << (25 - BIT_DEPTH)) - 1 )
162
160163 for( int q = 0; q <= QP_MAX_SPEC; q++ )
161164 {
162165 int j;
164167 for( int i = 0; i < 16; i++ )
165168 {
166169 h->unquant4_mf[i_list][q][i] = (1ULL << (q/6 + 15 + 8)) / quant4_mf[i_list][q%6][i];
167 h->quant4_mf[i_list][q][i] = j = SHIFT(quant4_mf[i_list][q%6][i], q/6 - 1);
170 j = SHIFT(quant4_mf[i_list][q%6][i], q/6 - 1);
171 h->quant4_mf[i_list][q][i] = (uint16_t)j;
168172 if( !j )
169173 {
170174 min_qp_err = X264_MIN( min_qp_err, q );
173177 // round to nearest, unless that would cause the deadzone to be negative
174178 h->quant4_bias[i_list][q][i] = X264_MIN( DIV(deadzone[i_list]<<10, j), (1<<15)/j );
175179 h->quant4_bias0[i_list][q][i] = (1<<15)/j;
176 if( j > 0xffff && q > max_qp_err && (i_list == CQM_4IY || i_list == CQM_4PY) )
180 if( j > MAX_MF && q > max_qp_err && (i_list == CQM_4IY || i_list == CQM_4PY) )
177181 max_qp_err = q;
178 if( j > 0xffff && q > max_chroma_qp_err && (i_list == CQM_4IC || i_list == CQM_4PC) )
182 if( j > MAX_MF && q > max_chroma_qp_err && (i_list == CQM_4IC || i_list == CQM_4PC) )
179183 max_chroma_qp_err = q;
180184 }
181185 if( h->param.analyse.b_transform_8x8 )
193197 }
194198 h->quant8_bias[i_list][q][i] = X264_MIN( DIV(deadzone[i_list]<<10, j), (1<<15)/j );
195199 h->quant8_bias0[i_list][q][i] = (1<<15)/j;
196 if( j > 0xffff && q > max_qp_err && (i_list == CQM_8IY || i_list == CQM_8PY) )
200 if( j > MAX_MF && q > max_qp_err && (i_list == CQM_8IY || i_list == CQM_8PY) )
197201 max_qp_err = q;
198 if( j > 0xffff && q > max_chroma_qp_err && (i_list == CQM_8IC || i_list == CQM_8PC) )
202 if( j > MAX_MF && q > max_chroma_qp_err && (i_list == CQM_8IC || i_list == CQM_8PC) )
199203 max_chroma_qp_err = q;
200204 }
201205 }
00 /*****************************************************************************
11 * set.h: quantization init
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
139139 int b_qpprime_y_zero_transform_bypass;
140140 int i_chroma_format_idc;
141141
142 int b_avcintra;
142 int b_avcintra_hd;
143 int b_avcintra_4k;
143144 int i_cqm_preset;
144145 const uint8_t *scaling_list[8]; /* could be 12, but we don't allow separate Cb/Cr lists */
145146
00 /*****************************************************************************
11 * tables.c: const tables
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
242242 x264_cqm_jvt8i, x264_cqm_jvt8p
243243 };
244244
245 // 1080i25_avci50, 1080p25_avci50
245 // 720p_avci50, 1080i_avci50, 1080p_avci50
246246 const uint8_t x264_cqm_avci50_4ic[16] =
247247 {
248248 16,22,28,40,
251251 40,44,48,60
252252 };
253253
254 // 1080p25_avci50, 720p25_avci50, 720p50_avci50
254 // 720p_avci50, 1080p_avci50
255255 const uint8_t x264_cqm_avci50_p_8iy[64] =
256256 {
257257 16,18,19,21,24,27,30,33,
264264 33,78,81,84,87,90,93,96
265265 };
266266
267 // 1080i25_avci50,
267 // 1080i_avci50
268268 const uint8_t x264_cqm_avci50_1080i_8iy[64] =
269269 {
270270 16,18,19,21,27,33,81,87,
277277 30,33,33,78,81,84,87,96
278278 };
279279
280 // 720p25_avci100, 720p50_avci100
280 // 720p_avci100
281281 const uint8_t x264_cqm_avci100_720p_4ic[16] =
282282 {
283283 16,21,27,34,
286286 34,41,46,54
287287 };
288288
289 // 720p25_avci100, 720p50_avci100
289 // 720p_avci100
290290 const uint8_t x264_cqm_avci100_720p_8iy[64] =
291291 {
292292 16,18,19,21,22,24,26,32,
299299 32,32,32,34,34,36,38,42
300300 };
301301
302 // 1080i25_avci100, 1080p25_avci100
302 // 1080i_avci100, 1080p_avci100
303303 const uint8_t x264_cqm_avci100_1080_4ic[16] =
304304 {
305305 16,20,26,32,
308308 32,38,44,50
309309 };
310310
311 // 1080i25_avci100,
311 // 1080i_avci100
312312 const uint8_t x264_cqm_avci100_1080i_8iy[64] =
313313 {
314314 16,19,20,23,24,26,32,42,
321321 22,23,24,26,36,42,59,72
322322 };
323323
324 // 1080p25_avci100,
324 // 1080p_avci100
325325 const uint8_t x264_cqm_avci100_1080p_8iy[64] =
326326 {
327327 16,18,19,20,22,23,24,26,
332332 23,24,26,32,36,42,59,63,
333333 24,26,32,36,42,59,63,68,
334334 26,32,36,42,59,63,68,72
335 };
336
337 // 2160p_avci300
338 const uint8_t x264_cqm_avci300_2160p_4iy[16] =
339 {
340 12,16,19,20,
341 16,19,20,24,
342 19,20,24,33,
343 20,24,33,39
344 };
345
346 // 2160p_avci300
347 const uint8_t x264_cqm_avci300_2160p_4ic[16] =
348 {
349 28,39,56,67,
350 39,56,67,77,
351 56,67,77,104,
352 67,77,104,133
353 };
354
355 // 2160p_avci300
356 const uint8_t x264_cqm_avci300_2160p_8iy[64] =
357 {
358 12,14,16,17,19,20,20,24,
359 14,16,17,19,20,20,24,30,
360 16,17,19,20,20,24,30,42,
361 17,19,20,20,24,30,42,56,
362 19,20,20,24,30,42,56,72,
363 20,20,24,30,42,56,72,76,
364 20,24,30,42,56,72,76,80,
365 24,30,42,56,72,76,80,84
335366 };
336367
337368 /*****************************************************************************
00 /*****************************************************************************
11 * tables.h: const tables
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
6262 extern const uint8_t x264_cqm_avci100_1080_4ic[16];
6363 extern const uint8_t x264_cqm_avci100_1080i_8iy[64];
6464 extern const uint8_t x264_cqm_avci100_1080p_8iy[64];
65 extern const uint8_t x264_cqm_avci300_2160p_4iy[16];
66 extern const uint8_t x264_cqm_avci300_2160p_4ic[16];
67 extern const uint8_t x264_cqm_avci300_2160p_8iy[64];
6568
6669 extern const uint8_t x264_decimate_table4[16];
6770 extern const uint8_t x264_decimate_table8[64];
00 /*****************************************************************************
11 * threadpool.c: thread pooling
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
3636 volatile int exit;
3737 int threads;
3838 x264_pthread_t *thread_handle;
39 void (*init_func)(void *);
40 void *init_arg;
4139
4240 /* requires a synchronized list structure and associated methods,
4341 so use what is already implemented for frames */
4846
4947 REALIGN_STACK static void *threadpool_thread( x264_threadpool_t *pool )
5048 {
51 if( pool->init_func )
52 pool->init_func( pool->init_arg );
53
5449 while( !pool->exit )
5550 {
5651 x264_threadpool_job_t *job = NULL;
7166 return NULL;
7267 }
7368
74 int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
75 void (*init_func)(void *), void *init_arg )
69 int x264_threadpool_init( x264_threadpool_t **p_pool, int threads )
7670 {
7771 if( threads <= 0 )
7872 return -1;
8478 CHECKED_MALLOCZERO( pool, sizeof(x264_threadpool_t) );
8579 *p_pool = pool;
8680
87 pool->init_func = init_func;
88 pool->init_arg = init_arg;
8981 pool->threads = threads;
9082
9183 CHECKED_MALLOC( pool->thread_handle, pool->threads * sizeof(x264_pthread_t) );
00 /*****************************************************************************
11 * threadpool.h: thread pooling
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
2929
3030 #if HAVE_THREAD
3131 #define x264_threadpool_init x264_template(threadpool_init)
32 X264_API int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
33 void (*init_func)(void *), void *init_arg );
32 X264_API int x264_threadpool_init( x264_threadpool_t **p_pool, int threads );
3433 #define x264_threadpool_run x264_template(threadpool_run)
3534 X264_API void x264_threadpool_run( x264_threadpool_t *pool, void *(*func)(void *), void *arg );
3635 #define x264_threadpool_wait x264_template(threadpool_wait)
3837 #define x264_threadpool_delete x264_template(threadpool_delete)
3938 X264_API void x264_threadpool_delete( x264_threadpool_t *pool );
4039 #else
41 #define x264_threadpool_init(p,t,f,a) -1
40 #define x264_threadpool_init(p,t) -1
4241 #define x264_threadpool_run(p,f,a)
4342 #define x264_threadpool_wait(p,a) NULL
4443 #define x264_threadpool_delete(p)
00 /*****************************************************************************
11 * vlc.c : vlc tables
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Fiona Glaser <fiona@x264.com>
3636 {
3737 int mask = level >> 15;
3838 int abs_level = (level^mask)-mask;
39 int i_level_code = abs_level*2-mask-2;
39 int i_level_code = abs_level ? abs_level*2-mask-2 : 0;
4040 int i_next = i_suffix;
4141 vlc_large_t *vlc = &x264_level_token[i_suffix][level+LEVEL_TABLE_SIZE/2];
4242
00 /*****************************************************************************
11 * win32thread.c: windows threading
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 * Pegasys Inc. <http://www.pegasys-inc.com>
00 /*****************************************************************************
11 * win32thread.h: windows threading
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 ;*****************************************************************************
11 ;* bitstream-a.asm: x86 bitstream functions
22 ;*****************************************************************************
3 ;* Copyright (C) 2010-2021 x264 project
3 ;* Copyright (C) 2010-2022 x264 project
44 ;*
55 ;* Authors: Fiona Glaser <fiona@x264.com>
66 ;* Henrik Gramner <henrik@gramner.com>
3333 ;-----------------------------------------------------------------------------
3434 %macro NAL_LOOP 2
3535 %%escape:
36 ; Detect false positive to avoid unneccessary escape loop
36 ; Detect false positive to avoid unnecessary escape loop
3737 xor r3d, r3d
3838 cmp byte [r0+r1-1], 0
3939 setnz r3b
00 /*****************************************************************************
11 * bitstream.h: x86 bitstream functions
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 ;*****************************************************************************
11 ;* cabac-a.asm: x86 cabac
22 ;*****************************************************************************
3 ;* Copyright (C) 2008-2021 x264 project
3 ;* Copyright (C) 2008-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 ;*****************************************************************************
11 ;* const-a.asm: x86 global constants
22 ;*****************************************************************************
3 ;* Copyright (C) 2010-2021 x264 project
3 ;* Copyright (C) 2010-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 ;*****************************************************************************
11 ;* cpu-a.asm: x86 cpu utilities
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 ;* Loren Merritt <lorenm@u.washington.edu>
00 ;*****************************************************************************
11 ;* dct-32.asm: x86_32 transform and zigzag
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Holger Lubitz <holger@lubitz.org>
00 ;*****************************************************************************
11 ;* dct-64.asm: x86_64 transform and zigzag
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Holger Lubitz <holger@lubitz.org>
00 ;*****************************************************************************
11 ;* dct-a.asm: x86 transform and zigzag
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Holger Lubitz <holger@lubitz.org>
66 ;* Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * dct.h: x86 transform and zigzag
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 ;*****************************************************************************
11 ;* deblock-a.asm: x86 deblocking
22 ;*****************************************************************************
3 ;* Copyright (C) 2005-2021 x264 project
3 ;* Copyright (C) 2005-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 /*****************************************************************************
11 * deblock.h: x86 deblocking
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 ;*****************************************************************************
11 ;* mc-a.asm: x86 motion compensation
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 ;*****************************************************************************
11 ;* mc-a2.asm: x86 motion compensation
22 ;*****************************************************************************
3 ;* Copyright (C) 2005-2021 x264 project
3 ;* Copyright (C) 2005-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 /*****************************************************************************
11 * mc-c.c: x86 motion compensation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
498498 else
499499 w->weightfn = h->mc.offsetadd;
500500 for( int i = 0; i < 8; i++ )
501 w->cachea[i] = abs(w->i_offset<<(BIT_DEPTH-8));
501 w->cachea[i] = abs(w->i_offset * (1 << (BIT_DEPTH-8)));
502502 return;
503503 }
504504 w->weightfn = h->mc.weight;
505505 int den1 = 1<<w->i_denom;
506506 int den2 = w->i_scale<<1;
507 int den3 = 1+(w->i_offset<<(BIT_DEPTH-8+1));
507 int den3 = 1+(w->i_offset * (1 << (BIT_DEPTH-8+1)));
508508 for( int i = 0; i < 8; i++ )
509509 {
510510 w->cachea[i] = den1;
536536 return;
537537 }
538538 w->weightfn = h->mc.weight;
539 den1 = w->i_offset << w->i_denom | (w->i_denom ? 1 << (w->i_denom - 1) : 0);
539 den1 = (w->i_offset * (1<<w->i_denom)) | (w->i_denom ? 1 << (w->i_denom - 1) : 0);
540540 for( i = 0; i < 8; i++ )
541541 {
542542 w->cachea[i] = w->i_scale;
00 /*****************************************************************************
11 * mc.h: x86 motion compensation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 ;*****************************************************************************
11 ;* pixel-32.asm: x86_32 pixel metrics
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Laurent Aimar <fenrir@via.ecp.fr>
00 ;*****************************************************************************
11 ;* pixel.asm: x86 pixel metrics
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Holger Lubitz <holger@lubitz.org>
00 /*****************************************************************************
11 * pixel.h: x86 pixel metrics
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 ;*****************************************************************************
11 ;* predict-a.asm: x86 intra prediction
22 ;*****************************************************************************
3 ;* Copyright (C) 2005-2021 x264 project
3 ;* Copyright (C) 2005-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Holger Lubitz <holger@lubitz.org>
00 /*****************************************************************************
11 * predict-c.c: intra prediction
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
6161 int b = ( 5 * H + 32 ) >> 6;\
6262 int c = ( 5 * V + 32 ) >> 6;\
6363 int i00 = a - b * 7 - c * 7 + 16;\
64 /* b*15 + c*15 can overflow: it's easier to just branch away in this rare case
64 /* b*15 + c*15 can overflow: it's easier to just branch away in this rare case\
6565 * than to try to consider it in the asm. */\
6666 if( BIT_DEPTH > 8 && (i00 > 0x7fff || abs(b) > 1092 || abs(c) > 1092) )\
6767 x264_predict_16x16_p_c( src );\
00 /*****************************************************************************
11 * predict.h: x86 intra prediction
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 ;*****************************************************************************
11 ;* quant-a.asm: x86 quantization and level-run
22 ;*****************************************************************************
3 ;* Copyright (C) 2005-2021 x264 project
3 ;* Copyright (C) 2005-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
166166 ABSD m1, m0
167167 paddd m1, %3
168168 pmulld m1, %2
169 psrad m1, 16
169 psrld m1, 16
170170 %else ; !sse4
171171 mova m0, [%1]
172172 ABSD m1, m0
194194 paddd m3, %3
195195 pmulld m2, %2
196196 pmulld m3, %2
197 psrad m2, 16
198 psrad m3, 16
197 psrld m2, 16
198 psrld m3, 16
199199 PSIGND m2, m0
200200 PSIGND m3, m1
201201 mova [%1 ], m2
221221 pmuludq m3, m4
222222 psllq m3, 32
223223 paddd m1, m3
224 psrad m1, 16
224 psrld m1, 16
225225 PSIGND m1, m0
226226 mova [%1], m1
227227 ACCUM por, %5, 1, %4
237237 paddd m3, [%3+mmsize]
238238 pmulld m2, [%2 ]
239239 pmulld m3, [%2+mmsize]
240 psrad m2, 16
241 psrad m3, 16
240 psrld m2, 16
241 psrld m3, 16
242242 PSIGND m2, m0
243243 PSIGND m3, m1
244244 mova [%1 ], m2
00 /*****************************************************************************
11 * quant.h: x86 quantization and level-run
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
00 ;*****************************************************************************
11 ;* sad-a.asm: x86 sad functions
22 ;*****************************************************************************
3 ;* Copyright (C) 2003-2021 x264 project
3 ;* Copyright (C) 2003-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Fiona Glaser <fiona@x264.com>
00 ;*****************************************************************************
11 ;* sad16-a.asm: x86 high depth sad functions
22 ;*****************************************************************************
3 ;* Copyright (C) 2010-2021 x264 project
3 ;* Copyright (C) 2010-2022 x264 project
44 ;*
55 ;* Authors: Oskar Arvidsson <oskar@irock.se>
66 ;* Henrik Gramner <henrik@gramner.com>
00 ;*****************************************************************************
11 ;* trellis-64.asm: x86_64 trellis quantization
22 ;*****************************************************************************
3 ;* Copyright (C) 2012-2021 x264 project
3 ;* Copyright (C) 2012-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;*
157157 %define cost_siglast stack+80
158158 %define level_tree stack+96
159159
160 ; trellis_node_t is layed out differently than C.
160 ; trellis_node_t is laid out differently than C.
161161 ; struct-of-arrays rather than array-of-structs, for simd.
162162 %define nodes_curq r7
163163 %define nodes_prevq r8
00 /*****************************************************************************
11 * util.h: x86 inline asm
22 *****************************************************************************
3 * Copyright (C) 2008-2021 x264 project
3 * Copyright (C) 2008-2022 x264 project
44 *
55 * Authors: Fiona Glaser <fiona@x264.com>
66 * Loren Merritt <lorenm@u.washington.edu>
120120 "m"(pb_2),"m"(pb_32),"m"(pb_33)
121121 :"mm0", "mm1", "mm2"
122122 );
123 return amvd;
123 return (uint16_t)amvd;
124124 }
125125
126126 #define x264_predictor_clip x264_predictor_clip_mmx2
00 ;*****************************************************************************
11 ;* x86inc.asm: x264asm abstraction layer
22 ;*****************************************************************************
3 ;* Copyright (C) 2005-2021 x264 project
3 ;* Copyright (C) 2005-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Henrik Gramner <henrik@gramner.com>
8585 %define mangle(x) x
8686 %endif
8787
88 ; Use VEX-encoding even in non-AVX functions
89 %ifndef FORCE_VEX_ENCODING
90 %define FORCE_VEX_ENCODING 0
91 %endif
92
8893 %macro SECTION_RODATA 0-1 16
8994 %ifidn __OUTPUT_FORMAT__,win32
9095 SECTION .rdata align=%1
237242 %else
238243 mov %1, %2
239244 %endif
245 %endmacro
246
247 ; Repeats an instruction/operation for multiple arguments.
248 ; Example usage: "REPX {psrlw x, 8}, m0, m1, m2, m3"
249 %macro REPX 2-* ; operation, args
250 %xdefine %%f(x) %1
251 %rep %0 - 1
252 %rotate 1
253 %%f(%1)
254 %endrep
240255 %endmacro
241256
242257 %macro PUSH 1
10131028 %endmacro
10141029
10151030 %macro INIT_XMM 0-1+
1016 %assign avx_enabled 0
1031 %assign avx_enabled FORCE_VEX_ENCODING
10171032 %define RESET_MM_PERMUTATION INIT_XMM %1
10181033 %define mmsize 16
10191034 %define mova movdqa
13361351 %1 %6, __src2
13371352 %endif
13381353 %elif %0 >= 9
1339 __instr %6, %7, %8, %9
1354 %if avx_enabled && __sizeofreg >= 16 && %4 == 1
1355 %ifnnum regnumof%7
1356 %if %3
1357 vmovaps %6, %7
1358 %else
1359 vmovdqa %6, %7
1360 %endif
1361 __instr %6, %6, %8, %9
1362 %else
1363 __instr %6, %7, %8, %9
1364 %endif
1365 %else
1366 __instr %6, %7, %8, %9
1367 %endif
13401368 %elif %0 == 8
1341 %if avx_enabled && %5
1369 %if avx_enabled && __sizeofreg >= 16 && %4 == 0
13421370 %xdefine __src1 %7
13431371 %xdefine __src2 %8
1344 %ifnum regnumof%7
1345 %ifnum regnumof%8
1346 %if regnumof%7 < 8 && regnumof%8 >= 8 && regnumof%8 < 16 && sizeof%8 <= 32
1347 ; Most VEX-encoded instructions require an additional byte to encode when
1348 ; src2 is a high register (e.g. m8..15). If the instruction is commutative
1349 ; we can swap src1 and src2 when doing so reduces the instruction length.
1350 %xdefine __src1 %8
1351 %xdefine __src2 %7
1372 %if %5
1373 %ifnum regnumof%7
1374 %ifnum regnumof%8
1375 %if regnumof%7 < 8 && regnumof%8 >= 8 && regnumof%8 < 16 && sizeof%8 <= 32
1376 ; Most VEX-encoded instructions require an additional byte to encode when
1377 ; src2 is a high register (e.g. m8..15). If the instruction is commutative
1378 ; we can swap src1 and src2 when doing so reduces the instruction length.
1379 %xdefine __src1 %8
1380 %xdefine __src2 %7
1381 %endif
13521382 %endif
1383 %elifnum regnumof%8 ; put memory operands in src2 when possible
1384 %xdefine __src1 %8
1385 %xdefine __src2 %7
1386 %else
1387 %assign __emulate_avx 1
13531388 %endif
1354 %endif
1355 __instr %6, __src1, __src2
1389 %elifnnum regnumof%7
1390 ; EVEX allows imm8 shift instructions to be used with memory operands,
1391 ; but VEX does not. This handles those special cases.
1392 %ifnnum %8
1393 %assign __emulate_avx 1
1394 %elif notcpuflag(avx512)
1395 %assign __emulate_avx 1
1396 %endif
1397 %endif
1398 %if __emulate_avx ; a separate load is required
1399 %if %3
1400 vmovaps %6, %7
1401 %else
1402 vmovdqa %6, %7
1403 %endif
1404 __instr %6, %6, %8
1405 %else
1406 __instr %6, __src1, __src2
1407 %endif
13561408 %else
13571409 __instr %6, %7, %8
13581410 %endif
13591411 %elif %0 == 7
1360 %if avx_enabled && %5
1412 %if avx_enabled && __sizeofreg >= 16 && %5
13611413 %xdefine __src1 %6
13621414 %xdefine __src2 %7
13631415 %ifnum regnumof%6
14181470 AVX_INSTR andps, sse, 1, 0, 1
14191471 AVX_INSTR blendpd, sse4, 1, 1, 0
14201472 AVX_INSTR blendps, sse4, 1, 1, 0
1421 AVX_INSTR blendvpd, sse4 ; can't be emulated
1422 AVX_INSTR blendvps, sse4 ; can't be emulated
1473 AVX_INSTR blendvpd, sse4, 1, 1, 0 ; last operand must be xmm0 with legacy encoding
1474 AVX_INSTR blendvps, sse4, 1, 1, 0 ; last operand must be xmm0 with legacy encoding
14231475 AVX_INSTR cmpeqpd, sse2, 1, 0, 1
14241476 AVX_INSTR cmpeqps, sse, 1, 0, 1
14251477 AVX_INSTR cmpeqsd, sse2, 1, 0, 0
15521604 AVX_INSTR pandn, mmx, 0, 0, 0
15531605 AVX_INSTR pavgb, mmx2, 0, 0, 1
15541606 AVX_INSTR pavgw, mmx2, 0, 0, 1
1555 AVX_INSTR pblendvb, sse4 ; can't be emulated
1607 AVX_INSTR pblendvb, sse4, 0, 1, 0 ; last operand must be xmm0 with legacy encoding
15561608 AVX_INSTR pblendw, sse4, 0, 1, 0
15571609 AVX_INSTR pclmulqdq, fnord, 0, 1, 0
15581610 AVX_INSTR pclmulhqhqdq, fnord, 0, 0, 0
00 ;*****************************************************************************
11 ;* x86util.asm: x86 utility macros
22 ;*****************************************************************************
3 ;* Copyright (C) 2008-2021 x264 project
3 ;* Copyright (C) 2008-2022 x264 project
44 ;*
55 ;* Authors: Holger Lubitz <holger@lubitz.org>
66 ;* Loren Merritt <lorenm@u.washington.edu>
920920 fi
921921 fi
922922
923 if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" -o $ARCH = "PARISC" -o $ARCH = "MIPS" -o $ARCH = "AARCH64" \) ] ; then
923 if [ $shared = yes ] ; then
924924 pic="yes"
925925 fi
926926
12981298 avs="no"
12991299 # cygwin can use avisynth if it can use LoadLibrary
13001300 if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
1301 avs="avisynth"
1301 avs="yes"
13021302 define HAVE_AVS
1303 define USE_AVXSYNTH 0
13041303 elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
1305 # AvxSynth currently only supports Linux and OSX
1306 avs="avxsynth"
1304 avs="yes"
13071305 define HAVE_AVS
1308 define USE_AVXSYNTH 1
13091306 AVS_LIBS="-ldl"
13101307 LDFLAGSCLI="$AVS_LIBS $LDFLAGSCLI"
1308 elif [ "$SYS" = "FREEBSD" -o "$SYS" = "OPENBSD" -o "$SYS" = "NETBSD" -o "$SYS" = "HAIKU" ] ; then
1309 avs="yes"
1310 define HAVE_AVS
1311 # dlopen is exported from libc on both *BSD and Haiku
13111312 fi
13121313 fi
13131314
3232 * 16% reset cabac contexts
3333 * 6% deblocking between slices (you don't strictly have to turn this off just for standard compliance, but you do if you want to use slices for decoder multithreading)
3434 * 2% cabac neighbors (cbp, skip, etc)
35 The proportional cost of redundant headers should certainly depend on bitrate (since the header size is constant and everything else depends on bitrate). Deblocking should too (due to varing deblock strength).
35 The proportional cost of redundant headers should certainly depend on bitrate (since the header size is constant and everything else depends on bitrate). Deblocking should too (due to varying deblock strength).
3636 But none of the proportions should depend strongly on the number of slices: some are triggered per slice while some are triggered per macroblock-that's-on-the-edge-of-a-slice, but as long as there's no more than 1 slice per row, the relative frequency of those two conditions is determined solely by the image width.
3737
3838
00 /*****************************************************************************
11 * analyse.c: macroblock analysis
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
13451345 i_maxref = ref;\
13461346 }
13471347
1348 /* early termination: if 16x16 chose ref 0, then evalute no refs older
1348 /* early termination: if 16x16 chose ref 0, then evaluate no refs older
13491349 * than those used by the neighbors */
13501350 if( a->b_early_terminate && (i_maxref > 0 && (a->l0.me16x16.i_ref == 0 || a->l0.me16x16.i_ref == h->mb.ref_blind_dupe) &&
13511351 h->mb.i_mb_type_top > 0 && h->mb.i_mb_type_left[0] > 0) )
21722172 ALIGNED_ARRAY_16( pixel, pix,[2],[8*8] );
21732173 int i_maxref[2] = {h->mb.pic.i_fref[0]-1, h->mb.pic.i_fref[1]-1};
21742174
2175 /* early termination: if 16x16 chose ref 0, then evalute no refs older
2175 /* early termination: if 16x16 chose ref 0, then evaluate no refs older
21762176 * than those used by the neighbors */
21772177 #define CHECK_NEIGHBOUR(i)\
21782178 {\
00 /*****************************************************************************
11 * analyse.h: macroblock analysis
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * api.c: bit depth independent interface
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Vittorio Giovara <vittorio.giovara@gmail.com>
66 * Luca Barbato <lu_zero@gentoo.org>
00 /*****************************************************************************
11 * cabac.c: cabac bitstream writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * cavlc.c: cavlc bitstream writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * encoder.c: top-level encoder functions
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
205205 sh->i_disable_deblocking_filter_idc = param->b_sliced_threads ? 2 : 0;
206206 else
207207 sh->i_disable_deblocking_filter_idc = 1;
208 sh->i_alpha_c0_offset = param->i_deblocking_filter_alphac0 << 1;
209 sh->i_beta_offset = param->i_deblocking_filter_beta << 1;
208 sh->i_alpha_c0_offset = param->i_deblocking_filter_alphac0 * 2;
209 sh->i_beta_offset = param->i_deblocking_filter_beta * 2;
210210 }
211211
212212 static void slice_header_write( bs_t *s, x264_slice_header_t *sh, int i_nal_ref_idc )
410410 filler += 32; // add padding for safety
411411 return bitstream_check_buffer_internal( h, filler, 0, -1 );
412412 }
413
414 #if HAVE_THREAD
415 static void encoder_thread_init( x264_t *h )
416 {
417 if( h->param.i_sync_lookahead )
418 x264_lower_thread_priority( 10 );
419 }
420 #endif
421413
422414 /****************************************************************************
423415 *
716708 return -1;
717709 }
718710
719 int type = h->param.i_avcintra_class == 200 ? 2 :
711 int type = h->param.i_avcintra_class == 480 ? 4 :
712 h->param.i_avcintra_class == 300 ? 3 :
713 h->param.i_avcintra_class == 200 ? 2 :
720714 h->param.i_avcintra_class == 100 ? 1 :
721715 h->param.i_avcintra_class == 50 ? 0 : -1;
722716 if( type < 0 )
724718 x264_log( h, X264_LOG_ERROR, "Invalid AVC-Intra class\n" );
725719 return -1;
726720 }
727
728 /* [50/100/200][res][fps] */
721 else if( type > 2 && h->param.i_avcintra_flavor != X264_AVCINTRA_FLAVOR_SONY )
722 {
723 x264_log( h, X264_LOG_ERROR, "AVC-Intra %d only supported by Sony XAVC flavor\n", h->param.i_avcintra_class );
724 return -1;
725 }
726
727 /* [50/100/200/300/480][res][fps] */
729728 static const struct
730729 {
731730 uint16_t fps_num;
732731 uint16_t fps_den;
733732 uint8_t interlaced;
734733 uint16_t frame_size;
734 const uint8_t *cqm_4iy;
735735 const uint8_t *cqm_4ic;
736736 const uint8_t *cqm_8iy;
737 } avcintra_lut[3][2][7] =
738 {
739 {{{ 60000, 1001, 0, 912, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
740 { 50, 1, 0, 1100, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
741 { 30000, 1001, 0, 912, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
742 { 25, 1, 0, 1100, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
743 { 24000, 1001, 0, 912, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy }},
744 {{ 30000, 1001, 1, 1820, x264_cqm_avci50_4ic, x264_cqm_avci50_1080i_8iy },
745 { 25, 1, 1, 2196, x264_cqm_avci50_4ic, x264_cqm_avci50_1080i_8iy },
746 { 60000, 1001, 0, 1820, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
747 { 30000, 1001, 0, 1820, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
748 { 50, 1, 0, 2196, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
749 { 25, 1, 0, 2196, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
750 { 24000, 1001, 0, 1820, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy }}},
751 {{{ 60000, 1001, 0, 1848, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
752 { 50, 1, 0, 2224, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
753 { 30000, 1001, 0, 1848, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
754 { 25, 1, 0, 2224, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
755 { 24000, 1001, 0, 1848, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy }},
756 {{ 30000, 1001, 1, 3692, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
757 { 25, 1, 1, 4444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
758 { 60000, 1001, 0, 3692, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
759 { 30000, 1001, 0, 3692, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
760 { 50, 1, 0, 4444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
761 { 25, 1, 0, 4444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
762 { 24000, 1001, 0, 3692, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},
763 {{{ 60000, 1001, 0, 3724, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
764 { 50, 1, 0, 4472, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy }},
765 {{ 30000, 1001, 1, 7444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
766 { 25, 1, 1, 8940, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
767 { 60000, 1001, 0, 7444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
768 { 30000, 1001, 0, 7444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
769 { 50, 1, 0, 8940, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
770 { 25, 1, 0, 8940, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
771 { 24000, 1001, 0, 7444, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}}
737 } avcintra_lut[5][2][7] =
738 {
739 {{{ 60000, 1001, 0, 912, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
740 { 50, 1, 0, 1100, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
741 { 30000, 1001, 0, 912, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
742 { 25, 1, 0, 1100, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
743 { 24000, 1001, 0, 912, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy }},
744 {{ 30000, 1001, 1, 1820, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_1080i_8iy },
745 { 25, 1, 1, 2196, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_1080i_8iy },
746 { 60000, 1001, 0, 1820, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
747 { 30000, 1001, 0, 1820, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
748 { 50, 1, 0, 2196, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
749 { 25, 1, 0, 2196, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy },
750 { 24000, 1001, 0, 1820, x264_cqm_jvt4i, x264_cqm_avci50_4ic, x264_cqm_avci50_p_8iy }}},
751 {{{ 60000, 1001, 0, 1848, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
752 { 50, 1, 0, 2224, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
753 { 30000, 1001, 0, 1848, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
754 { 25, 1, 0, 2224, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
755 { 24000, 1001, 0, 1848, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy }},
756 {{ 30000, 1001, 1, 3692, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
757 { 25, 1, 1, 4444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
758 { 60000, 1001, 0, 3692, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
759 { 30000, 1001, 0, 3692, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
760 { 50, 1, 0, 4444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
761 { 25, 1, 0, 4444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
762 { 24000, 1001, 0, 3692, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},
763 {{{ 60000, 1001, 0, 3724, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy },
764 { 50, 1, 0, 4472, x264_cqm_jvt4i, x264_cqm_avci100_720p_4ic, x264_cqm_avci100_720p_8iy }},
765 {{ 30000, 1001, 1, 7444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
766 { 25, 1, 1, 8940, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080i_8iy },
767 { 60000, 1001, 0, 7444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
768 { 30000, 1001, 0, 7444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
769 { 50, 1, 0, 8940, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
770 { 25, 1, 0, 8940, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy },
771 { 24000, 1001, 0, 7444, x264_cqm_jvt4i, x264_cqm_avci100_1080_4ic, x264_cqm_avci100_1080p_8iy }}},
772 {{{ 60000, 1001, 0, 9844, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
773 { 50, 1, 0, 9844, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
774 { 30000, 1001, 0, 9844, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
775 { 25, 1, 0, 9844, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
776 { 24000, 1001, 0, 9844, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy }}},
777 {{{ 60000, 1001, 0, 15700, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
778 { 50, 1, 0, 15700, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
779 { 30000, 1001, 0, 15700, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
780 { 25, 1, 0, 15700, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy },
781 { 24000, 1001, 0, 15700, x264_cqm_avci300_2160p_4iy, x264_cqm_avci300_2160p_4ic, x264_cqm_avci300_2160p_8iy }}}
772782 };
773783
774784 int res = -1;
775785 if( i_csp >= X264_CSP_I420 && i_csp < X264_CSP_I422 && !type )
776786 {
777 if( h->param.i_width == 1440 && h->param.i_height == 1080 ) res = 1;
778 else if( h->param.i_width == 960 && h->param.i_height == 720 ) res = 0;
787 if( h->param.i_width == 1440 && h->param.i_height == 1080 ) res = 1;
788 else if( h->param.i_width == 960 && h->param.i_height == 720 ) res = 0;
779789 }
780790 else if( i_csp >= X264_CSP_I422 && i_csp < X264_CSP_I444 && type )
781791 {
782 if( h->param.i_width == 1920 && h->param.i_height == 1080 ) res = 1;
783 else if( h->param.i_width == 1280 && h->param.i_height == 720 ) res = 0;
792 if( type < 3 )
793 {
794 if( h->param.i_width == 1920 && h->param.i_height == 1080 ) res = 1;
795 else if( h->param.i_width == 2048 && h->param.i_height == 1080 ) res = 1;
796 else if( h->param.i_width == 1280 && h->param.i_height == 720 ) res = 0;
797 }
798 else
799 {
800 if( h->param.i_width == 3840 && h->param.i_height == 2160 ) res = 0;
801 else if( h->param.i_width == 4096 && h->param.i_height == 2160 ) res = 0;
802 }
784803 }
785804 else
786805 {
821840 }
822841 if( i == 7 )
823842 {
824 x264_log( h, X264_LOG_ERROR, "FPS %d/%d%c not compatible with AVC-Intra\n",
825 h->param.i_fps_num, h->param.i_fps_den, PARAM_INTERLACED ? 'i' : 'p' );
843 x264_log( h, X264_LOG_ERROR, "FPS %d/%d%c not compatible with AVC-Intra %d\n",
844 h->param.i_fps_num, h->param.i_fps_den, PARAM_INTERLACED ? 'i' : 'p', h->param.i_avcintra_class );
826845 return -1;
827846 }
828847
842861 h->param.b_pic_struct = 0;
843862 h->param.analyse.b_transform_8x8 = 1;
844863 h->param.analyse.intra = X264_ANALYSE_I8x8;
845 h->param.analyse.i_chroma_qp_offset = res && type ? 3 : 4;
864 h->param.analyse.i_chroma_qp_offset = type > 2 ? -4 : res && type ? 3 : 4;
846865 h->param.b_cabac = !type;
847866 h->param.rc.i_vbv_buffer_size = avcintra_lut[type][res][i].frame_size;
848867 h->param.rc.i_vbv_max_bitrate =
851870 h->param.rc.f_vbv_buffer_init = 1.0;
852871 h->param.rc.b_filler = 1;
853872 h->param.i_cqm_preset = X264_CQM_CUSTOM;
854 memcpy( h->param.cqm_4iy, x264_cqm_jvt4i, sizeof(h->param.cqm_4iy) );
873 memcpy( h->param.cqm_4iy, avcintra_lut[type][res][i].cqm_4iy, sizeof(h->param.cqm_4iy) );
855874 memcpy( h->param.cqm_4ic, avcintra_lut[type][res][i].cqm_4ic, sizeof(h->param.cqm_4ic) );
856875 memcpy( h->param.cqm_8iy, avcintra_lut[type][res][i].cqm_8iy, sizeof(h->param.cqm_8iy) );
857876
15441563 h->i_frame_num = 0;
15451564
15461565 if( h->param.i_avcintra_class )
1547 h->i_idr_pic_id = 5;
1566 h->i_idr_pic_id = h->param.i_avcintra_class > 200 ? 4 : 5;
15481567 else
15491568 h->i_idr_pic_id = 0;
15501569
17151734 CHECKED_MALLOC( h->reconfig_h, sizeof(x264_t) );
17161735
17171736 if( h->param.i_threads > 1 &&
1718 x264_threadpool_init( &h->threadpool, h->param.i_threads, (void*)encoder_thread_init, h ) )
1737 x264_threadpool_init( &h->threadpool, h->param.i_threads ) )
17191738 goto fail;
17201739 if( h->param.i_lookahead_threads > 1 &&
1721 x264_threadpool_init( &h->lookaheadpool, h->param.i_lookahead_threads, NULL, NULL ) )
1740 x264_threadpool_init( &h->lookaheadpool, h->param.i_lookahead_threads ) )
17221741 goto fail;
17231742
17241743 #if HAVE_OPENCL
36643683 int total_len = 256;
36653684 /* Sony XAVC uses an oversized PPS instead of SEI padding */
36663685 if( h->param.i_avcintra_flavor == X264_AVCINTRA_FLAVOR_SONY )
3667 total_len += h->param.i_height == 1080 ? 18*512 : 10*512;
3686 total_len += h->param.i_height >= 1080 ? 18*512 : 10*512;
36683687 h->out.nal[h->out.i_nal-1].i_padding = total_len - h->out.nal[h->out.i_nal-1].i_payload - NALU_OVERHEAD;
36693688 }
36703689 overhead += h->out.nal[h->out.i_nal-1].i_payload + h->out.nal[h->out.i_nal-1].i_padding + NALU_OVERHEAD;
00 /*****************************************************************************
11 * lookahead.c: high-level lookahead functions
22 *****************************************************************************
3 * Copyright (C) 2010-2021 Avail Media and x264 project
3 * Copyright (C) 2010-2022 Avail Media and x264 project
44 *
55 * Authors: Michael Kazmier <mkazmier@availmedia.com>
66 * Alex Giladi <agiladi@availmedia.com>
8888
8989 REALIGN_STACK static void *lookahead_thread( x264_t *h )
9090 {
91 while( !h->lookahead->b_exit_thread )
91 while( 1 )
9292 {
9393 x264_pthread_mutex_lock( &h->lookahead->ifbuf.mutex );
94 if( h->lookahead->b_exit_thread )
95 {
96 x264_pthread_mutex_unlock( &h->lookahead->ifbuf.mutex );
97 break;
98 }
9499 x264_pthread_mutex_lock( &h->lookahead->next.mutex );
95100 int shift = X264_MIN( h->lookahead->next.i_max_size - h->lookahead->next.i_size, h->lookahead->ifbuf.i_size );
96101 lookahead_shift( &h->lookahead->next, &h->lookahead->ifbuf, shift );
00 /*****************************************************************************
11 * macroblock.c: macroblock encoding
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
10431043 if( M32( mvp ) )
10441044 h->mc.mc_chroma( h->mb.pic.p_fdec[1], h->mb.pic.p_fdec[2], FDEC_STRIDE,
10451045 h->mb.pic.p_fref[0][0][4], h->mb.pic.i_stride[1],
1046 mvp[0], mvp[1]<<chroma422, 8, chroma422?16:8 );
1046 mvp[0], mvp[1] * (1<<chroma422), 8, chroma422?16:8 );
10471047 else
10481048 h->mc.load_deinterleave_chroma_fdec( h->mb.pic.p_fdec[1], h->mb.pic.p_fref[0][0][4],
10491049 h->mb.pic.i_stride[1], chroma422?16:8 );
00 /*****************************************************************************
11 * macroblock.h: macroblock encoding
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * me.c: motion estimation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
5757 static void refine_subpel( x264_t *h, x264_me_t *m, int hpel_iters, int qpel_iters, int *p_halfpel_thresh, int b_refine_qpel );
5858
5959 #define BITS_MVD( mx, my )\
60 (p_cost_mvx[(mx)<<2] + p_cost_mvy[(my)<<2])
60 (p_cost_mvx[(mx)*4] + p_cost_mvy[(my)*4])
6161
6262 #define COST_MV( mx, my )\
6363 do\
131131 p_fref_w + (m1x) + (m1y)*stride,\
132132 p_fref_w + (m2x) + (m2y)*stride,\
133133 stride, costs );\
134 costs[0] += p_cost_mvx[(m0x)<<2]; /* no cost_mvy */\
135 costs[1] += p_cost_mvx[(m1x)<<2];\
136 costs[2] += p_cost_mvx[(m2x)<<2];\
134 costs[0] += p_cost_mvx[(m0x)*4]; /* no cost_mvy */\
135 costs[1] += p_cost_mvx[(m1x)*4];\
136 costs[2] += p_cost_mvx[(m2x)*4];\
137137 COPY3_IF_LT( bcost, costs[0], bmx, m0x, bmy, m0y );\
138138 COPY3_IF_LT( bcost, costs[1], bmx, m1x, bmy, m1y );\
139139 COPY3_IF_LT( bcost, costs[2], bmx, m2x, bmy, m2y );\
175175 }
176176
177177 #define FPEL(mv) (((mv)+2)>>2) /* Convert subpel MV to fullpel with rounding... */
178 #define SPEL(mv) ((mv)<<2) /* ... and the reverse. */
178 #define SPEL(mv) ((mv)*4) /* ... and the reverse. */
179179 #define SPELx2(mv) (SPEL(mv)&0xFFFCFFFC) /* for two packed MVs */
180180
181181 void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc, int *p_halfpel_thresh )
200200 int mv_x_max = h->mb.mv_limit_fpel[1][0];
201201 int mv_y_max = h->mb.mv_limit_fpel[1][1];
202202 /* Special version of pack to allow shortcuts in CHECK_MVRANGE */
203 #define pack16to32_mask2(mx,my) ((mx<<16)|(my&0x7FFF))
203 #define pack16to32_mask2(mx,my) (((uint32_t)(mx)<<16)|((uint32_t)(my)&0x7FFF))
204204 uint32_t mv_min = pack16to32_mask2( -mv_x_min, -mv_y_min );
205205 uint32_t mv_max = pack16to32_mask2( mv_x_max, mv_y_max )|0x8000;
206206 uint32_t pmv, bpred_mv = 0;
332332 COPY1_IF_LT( bcost, (costs[3]<<4)+12 );
333333 if( !(bcost&15) )
334334 break;
335 bmx -= (bcost<<28)>>30;
336 bmy -= (bcost<<30)>>30;
335 bmx -= (int32_t)((uint32_t)bcost<<28)>>30;
336 bmy -= (int32_t)((uint32_t)bcost<<30)>>30;
337337 bcost &= ~15;
338338 } while( --i && CHECK_MVRANGE(bmx, bmy) );
339339 bcost >>= 4;
605605 if( dir )
606606 {
607607 bmx = omx + i*(dir>>4);
608 bmy = omy + i*((dir<<28)>>28);
608 bmy = omy + i*((int32_t)((uint32_t)dir<<28)>>28);
609609 }
610610 }
611611 } while( ++i <= i_me_range>>2 );
660660 for( int my = min_y; my <= max_y; my++ )
661661 {
662662 int i;
663 int ycost = p_cost_mvy[my<<2];
663 int ycost = p_cost_mvy[my*4];
664664 if( bsad <= ycost )
665665 continue;
666666 bsad -= ycost;
752752 for( int my = min_y; my <= max_y; my++ )
753753 {
754754 int i;
755 int ycost = p_cost_mvy[my<<2];
755 int ycost = p_cost_mvy[my*4];
756756 if( bcost <= ycost )
757757 continue;
758758 bcost -= ycost;
775775 uint32_t bmv_spel = SPELx2(bmv);
776776 if( h->mb.i_subpel_refine < 3 )
777777 {
778 m->cost_mv = p_cost_mvx[bmx<<2] + p_cost_mvy[bmy<<2];
778 m->cost_mv = p_cost_mvx[bmx*4] + p_cost_mvy[bmy*4];
779779 m->cost = bcost;
780780 /* compute the real cost */
781781 if( bmv == pmv ) m->cost += m->cost_mv;
914914 COPY1_IF_LT( bcost, (costs[3]<<6)+48 );
915915 if( !(bcost&63) )
916916 break;
917 bmx -= (bcost<<26)>>29;
918 bmy -= (bcost<<29)>>29;
917 bmx -= (int32_t)((uint32_t)bcost<<26)>>29;
918 bmy -= (int32_t)((uint32_t)bcost<<29)>>29;
919919 bcost &= ~63;
920920 }
921921 bcost >>= 6;
979979 COPY1_IF_LT( bcost, (costs[1]<<4)+3 );
980980 COPY1_IF_LT( bcost, (costs[2]<<4)+4 );
981981 COPY1_IF_LT( bcost, (costs[3]<<4)+12 );
982 bmx -= (bcost<<28)>>30;
983 bmy -= (bcost<<30)>>30;
982 bmx -= (int32_t)((uint32_t)bcost<<28)>>30;
983 bmy -= (int32_t)((uint32_t)bcost<<30)>>30;
984984 bcost >>= 4;
985985 }
986986
00 /*****************************************************************************
11 * me.h: motion estimation
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * ratecontrol.c: ratecontrol
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Michael Niedermayer <michaelni@gmx.at>
607607 COPY2_IF_GT( max, refcount[i], bestref, i );
608608
609609 /* FIXME: If there are duplicates from frames other than ref0 then it is possible
610 * that the optimal ordering doesnt place every duplicate. */
610 * that the optimal ordering doesn't place every duplicate. */
611611
612612 refcount[bestref] = -1;
613613 h->fref[0][ref] = frames[bestref];
16601660 float b1 = bits_so_far + predict_row_size_to_end( h, y, rc->qpm ) + size_of_other_slices;
16611661 float trust_coeff = x264_clip3f( bits_so_far / slice_size_planned, 0.0, 1.0 );
16621662
1663 /* Don't increase the row QPs until a sufficent amount of the bits of the frame have been processed, in case a flat */
1663 /* Don't increase the row QPs until a sufficient amount of the bits of the frame have been processed, in case a flat */
16641664 /* area at the top of the frame was measured inaccurately. */
16651665 if( trust_coeff < 0.05f )
16661666 qp_max = qp_absolute_max = prev_row_qp;
00 /*****************************************************************************
11 * ratecontrol.h: ratecontrol
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
00 /*****************************************************************************
11 * rdo.c: rate-distortion optimization
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Fiona Glaser <fiona@x264.com>
140140 int dc = h->pixf.sad[size]( fdec, FDEC_STRIDE, (pixel*)x264_zero, 0 ) >> 1;
141141 satd = abs(h->pixf.satd[size]( fdec, FDEC_STRIDE, (pixel*)x264_zero, 0 ) - dc - cached_satd( h, size, x, y ));
142142 }
143 satd = (satd * h->mb.i_psy_rd * h->mb.i_psy_rd_lambda + 128) >> 8;
143 int64_t tmp = ((int64_t)satd * h->mb.i_psy_rd * h->mb.i_psy_rd_lambda + 128) >> 8;
144 satd = X264_MIN( tmp, COST_MAX );
144145 }
145146 return h->pixf.ssd[size](fenc, FENC_STRIDE, fdec, FDEC_STRIDE) + satd;
146147 }
469470
470471 /* Optimize rounding for DC coefficients in DC-only luma 4x4/8x8 blocks. */
471472 int d = sign_coef - ((SIGN(unquant_abs_level, sign_coef) + 8)&~15);
472 uint64_t score = (uint64_t)d*d * coef_weight;
473 uint64_t score = (int64_t)d*d * coef_weight;
473474
474475 /* code the proposed level, and count how much entropy it would take */
475476 if( abs_level )
732733 trellis_level_t level_tree[64*8*2];
733734 int levels_used = 1;
734735 /* init trellis */
735 trellis_node_t nodes[2][8];
736 trellis_node_t nodes[2][8] = {0};
736737 trellis_node_t *nodes_cur = nodes[0];
737738 trellis_node_t *nodes_prev = nodes[1];
738739 trellis_node_t *bnode;
739 for( int j = 1; j < 4; j++ )
740 for( int j = 1; j < 8; j++ )
740741 nodes_cur[j].score = TRELLIS_SCORE_MAX;
741742 nodes_cur[0].score = TRELLIS_SCORE_BIAS;
742743 nodes_cur[0].level_idx = 0;
766767 if( !quant_coefs[i] )\
767768 {\
768769 /* no need to calculate ssd of 0s: it's the same in all nodes.\
769 * no need to modify level_tree for ctx=0: it starts with an infinite loop of 0s.
770 * no need to modify level_tree for ctx=0: it starts with an infinite loop of 0s.\
770771 * subtracting from one score is equivalent to adding to the rest. */\
771772 if( !ctx_hi )\
772773 {\
823824 int predicted_coef = orig_coef - sign_coef;\
824825 int psy_value = abs(unquant_abs_level + SIGN(predicted_coef, sign_coef));\
825826 int psy_weight = coef_weight1[zigzag[i]] * h->mb.i_psy_trellis;\
826 ssd1[k] = (uint64_t)d*d * coef_weight2[zigzag[i]] - psy_weight * psy_value;\
827 int64_t tmp = (int64_t)d*d * coef_weight2[zigzag[i]] - (int64_t)psy_weight * psy_value;\
828 ssd1[k] = (uint64_t)tmp;\
827829 }\
828830 else\
829831 /* FIXME: for i16x16 dc is this weight optimal? */\
830 ssd1[k] = (uint64_t)d*d * (dc?256:coef_weight2[zigzag[i]]);\
832 ssd1[k] = (int64_t)d*d * (dc?256:coef_weight2[zigzag[i]]);\
831833 ssd0[k] = ssd1[k];\
832834 if( !i && !dc && !ctx_hi )\
833835 {\
834836 /* Optimize rounding for DC coefficients in DC-only luma 4x4/8x8 blocks. */\
835837 d = sign_coef - ((SIGN(unquant_abs_level, sign_coef) + 8)&~15);\
836 ssd0[k] = (uint64_t)d*d * coef_weight2[zigzag[i]];\
838 ssd0[k] = (int64_t)d*d * coef_weight2[zigzag[i]];\
837839 }\
838840 }\
839841 \
924926 ALIGNED_ARRAY_16( dctcoef, coefs,[16] );
925927 const uint32_t *coef_weight1 = b_8x8 ? x264_dct8_weight_tab : x264_dct4_weight_tab;
926928 const uint32_t *coef_weight2 = b_8x8 ? x264_dct8_weight2_tab : x264_dct4_weight2_tab;
927 int delta_distortion[16];
929 int64_t delta_distortion[16];
928930 int64_t score = 1ULL<<62;
929931 int i, j;
930932 const int f = 1<<15;
951953
952954 /* Find last non-zero coefficient. */
953955 for( i = end; i >= start; i -= step )
954 if( (unsigned)(dct[zigzag[i]] * (dc?quant_mf[0]>>1:quant_mf[zigzag[i]]) + f-1) >= 2*f )
956 if( abs(dct[zigzag[i]]) * (dc?quant_mf[0]>>1:quant_mf[zigzag[i]]) >= f )
955957 break;
956958
957959 if( i < start )
984986 int unquant0 = (((dc?unquant_mf[0]<<1:unquant_mf[zigzag[j]]) * (nearest_quant-1) + 128) >> 8);
985987 int d1 = abs_coef - unquant1;
986988 int d0 = abs_coef - unquant0;
987 delta_distortion[i] = (d0*d0 - d1*d1) * (dc?256:coef_weight2[zigzag[j]]);
989 delta_distortion[i] = (int64_t)(d0*d0 - d1*d1) * (dc?256:coef_weight2[zigzag[j]]);
988990
989991 /* Psy trellis: bias in favor of higher AC coefficients in the reconstructed frame. */
990992 if( h->mb.i_psy_trellis && j && !dc && !b_chroma )
10221024 while( 1 )
10231025 {
10241026 int64_t iter_score = score;
1025 int iter_distortion_delta = 0;
1027 int64_t iter_distortion_delta = 0;
10261028 int iter_coef = -1;
10271029 int iter_mask = coef_mask;
10281030 int iter_round = round_mask;
10371039 int old_coef = coefs[i];
10381040 int new_coef = quant_coefs[round_change][i];
10391041 int cur_mask = (coef_mask&~(1 << i))|(!!new_coef << i);
1040 int cur_distortion_delta = delta_distortion[i] * (round_change ? -1 : 1);
1042 int64_t cur_distortion_delta = delta_distortion[i] * (round_change ? -1 : 1);
10411043 int64_t cur_score = cur_distortion_delta;
10421044 coefs[i] = new_coef;
10431045
00 /*****************************************************************************
11 * set: header writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
240240 sps->vui.i_log2_max_mv_length_vertical = (int)log2f( X264_MAX( 1, param->analyse.i_mv_range*4-1 ) ) + 1;
241241 }
242242
243 sps->b_avcintra = !!param->i_avcintra_class;
243 sps->b_avcintra_hd = param->i_avcintra_class && param->i_avcintra_class <= 200;
244 sps->b_avcintra_4k = param->i_avcintra_class > 200;
244245 sps->i_cqm_preset = param->i_cqm_preset;
245246 }
246247
324325 bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_chroma_minus8
325326 bs_write1( s, sps->b_qpprime_y_zero_transform_bypass );
326327 /* Exactly match the AVC-Intra bitstream */
327 bs_write1( s, sps->b_avcintra ); // seq_scaling_matrix_present_flag
328 if( sps->b_avcintra )
328 bs_write1( s, sps->b_avcintra_hd ); // seq_scaling_matrix_present_flag
329 if( sps->b_avcintra_hd )
329330 {
330331 scaling_list_write( s, sps, CQM_4IY );
331332 scaling_list_write( s, sps, CQM_4IC );
523524 bs_write1( s, pps->b_constrained_intra_pred );
524525 bs_write1( s, pps->b_redundant_pic_cnt );
525526
526 int b_scaling_list = !sps->b_avcintra && sps->i_cqm_preset != X264_CQM_FLAT;
527 int b_scaling_list = !sps->b_avcintra_hd && sps->i_cqm_preset != X264_CQM_FLAT;
527528 if( pps->b_transform_8x8_mode || b_scaling_list )
528529 {
529530 bs_write1( s, pps->b_transform_8x8_mode );
532533 {
533534 scaling_list_write( s, sps, CQM_4IY );
534535 scaling_list_write( s, sps, CQM_4IC );
535 bs_write1( s, 0 ); // Cr = Cb
536 scaling_list_write( s, sps, CQM_4PY );
537 scaling_list_write( s, sps, CQM_4PC );
538 bs_write1( s, 0 ); // Cr = Cb
536 if( sps->b_avcintra_4k )
537 {
538 scaling_list_write( s, sps, CQM_4IC );
539 bs_write1( s, 0 ); // no inter
540 bs_write1( s, 0 ); // no inter
541 bs_write1( s, 0 ); // no inter
542 }
543 else
544 {
545 bs_write1( s, 0 ); // Cr = Cb
546 scaling_list_write( s, sps, CQM_4PY );
547 scaling_list_write( s, sps, CQM_4PC );
548 bs_write1( s, 0 ); // Cr = Cb
549 }
539550 if( pps->b_transform_8x8_mode )
540551 {
541552 scaling_list_write( s, sps, CQM_8IY+4 );
542 scaling_list_write( s, sps, CQM_8PY+4 );
553 if( sps->b_avcintra_4k )
554 bs_write1( s, 0 ); // no inter
555 else
556 scaling_list_write( s, sps, CQM_8PY+4 );
543557 if( sps->i_chroma_format_idc == CHROMA_444 )
544558 {
545559 scaling_list_write( s, sps, CQM_8IC+4 );
593607
594608 memcpy( payload, uuid, 16 );
595609 sprintf( payload+16, "x264 - core %d%s - H.264/MPEG-4 AVC codec - "
596 "Copy%s 2003-2021 - http://www.videolan.org/x264.html - options: %s",
610 "Copy%s 2003-2022 - http://www.videolan.org/x264.html - options: %s",
597611 X264_BUILD, X264_VERSION, HAVE_GPL?"left":"right", opts );
598612 length = strlen(payload)+1;
599613
850864 return 0;
851865 }
852866
867 #undef ERROR
853868 #define ERROR(...)\
854869 {\
855870 if( verbose )\
00 /*****************************************************************************
11 * set.h: header writing
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * slicetype-cl.c: OpenCL slicetype decision code (lowres lookahead)
22 *****************************************************************************
3 * Copyright (C) 2012-2021 x264 project
3 * Copyright (C) 2012-2022 x264 project
44 *
55 * Authors: Steve Borho <sborho@multicorewareinc.com>
66 *
282282 return 0;
283283 }
284284
285 /* This function was tested emprically on a number of AMD and NV GPUs. Making a
285 /* This function was tested empirically on a number of AMD and NV GPUs. Making a
286286 * function which returns perfect launch dimensions is impossible; some
287287 * applications will have self-tuning code to try many possible variables and
288288 * measure the runtime. Here we simply make an educated guess based on what we
00 /*****************************************************************************
11 * slicetype-cl.h: OpenCL slicetype decision code (lowres lookahead)
22 *****************************************************************************
3 * Copyright (C) 2017-2021 x264 project
3 * Copyright (C) 2017-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * slicetype.c: lookahead analysis
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Fiona Glaser <fiona@x264.com>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * example.c: libx264 API usage example
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 // Avisynth C Interface Version 0.20
11 // Copyright 2003 Kevin Atkinson
2
3 // Copyright 2020 AviSynth+ project
24
35 // This program is free software; you can redistribute it and/or modify
46 // it under the terms of the GNU General Public License as published by
1214 //
1315 // You should have received a copy of the GNU General Public License
1416 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301 USA, or visit
1619 // http://www.gnu.org/copyleft/gpl.html .
1720 //
1821 // As a special exception, I give you permission to link to the
3033 // export plugins, or graphical user interfaces.
3134
3235 // NOTE: this is a partial update of the Avisynth C interface to recognize
33 // new color spaces added in Avisynth 2.60. By no means is this document
34 // completely Avisynth 2.60 compliant.
36 // new color spaces and interface elements added in Avisynth 2.60 and AviSynth+.
37 // This interface is not 100% Avisynth+ CPP interface equivalent.
38
39 // 170103: added new CPU constants (FMA4, AVX512xx)
40 // 171102: define SIZETMOD. do not use yet, experimental. Offsets are size_t instead of int. Affects x64.
41 // 171106: avs_get_row_size calls into avs_get_row_size_p, instead of direct field access
42 // 171106: avs_get_height calls into avs_get_row_size_p, instead of direct field access
43 // 180524: AVSC_EXPORT to dllexport in capi.h for avisynth_c_plugin_init
44 // 180524: avs_is_same_colorspace VideoInfo parameters to const
45 // 181230: Readability: functions regrouped to mix less AVSC_API and AVSC_INLINE, put together Avisynth+ specific stuff
46 // 181230: use #ifndef AVSC_NO_DECLSPEC for AVSC_INLINE functions which are calling API functions
47 // 181230: comments on avs_load_library (helper for loading API entries dynamically into a struct using AVSC_NO_DECLSPEC define)
48 // 181230: define alias AVS_FRAME_ALIGN as FRAME_ALIGN
49 // 181230: remove unused form of avs_get_rowsize and avs_get_height (kept earlier for reference)
50 // 190104: avs_load_library: smart fallback mechanism for Avisynth+ specific functions:
51 // if they are not loadable, they will work in a classic Avisynth compatible mode
52 // Example#1: e.g. avs_is_444 will call the existing avs_is_yv24 instead
53 // Example#2: avs_bits_per_component will return 8 for all colorspaces (Classic Avisynth supports only 8 bits/pixel)
54 // Thus the Avisynth+ specific API functions are safely callable even when connected to classic Avisynth DLL
55 // 202002xx non-Windows friendly additions
56 // 20200305 avs_vsprintf parameter type change: (void *) to va_list
57 // 20200330: (remove test SIZETMOD define for clarity)
58 // 20200513: user must use explicite #define AVS26_FALLBACK_SIMULATION for having fallback helpers in dynamic loaded library section
59 // 20200513: Follow AviSynth+ V8 interface additions
60 // AVS_VideoFrame struct extended with placeholder for frame property pointer
61 // avs_subframe_planar_a
62 // avs_copy_frame_props
63 // avs_get_frame_props_ro, avs_get_frame_props_rw
64 // avs_prop_num_keys, avs_prop_get_key, avs_prop_num_elements, avs_prop_get_type, avs_prop_get_data_size
65 // avs_prop_get_int, avs_prop_get_float, avs_prop_get_data, avs_prop_get_clip, avs_prop_get_frame, avs_prop_get_int_array, avs_prop_get_float_array
66 // avs_prop_set_int, avs_prop_set_float, avs_prop_set_data, avs_prop_set_clip, avs_prop_set_frame, avs_prop_set_int_array, avs_prop_set_float_array
67 // avs_prop_delete_key, avs_clear_map
68 // avs_new_video_frame_p, avs_new_video_frame_p_a
69 // avs_get_env_property (internal system properties), AVS_AEP_xxx (AvsEnvProperty) enums
70 // avs_get_var_try, avs_get_var_bool, avs_get_var_int, avs_get_var_double, avs_get_var_string, avs_get_var_long
71 // avs_pool_allocate, avs_pool_free
72
3573
3674 #ifndef __AVISYNTH_C__
3775 #define __AVISYNTH_C__
76
77 #ifndef AVS_CONFIG_H
78 #define AVS_CONFIG_H
79
80 // Undefine this to get cdecl calling convention
81 #define AVSC_USE_STDCALL 1
82
83 // NOTE TO PLUGIN AUTHORS:
84 // Because AVS_FRAME_ALIGN can be substantially higher than the alignment
85 // a plugin actually needs, plugins should not use AVS_FRAME_ALIGN to check for
86 // alignment. They should always request the exact alignment value they need.
87 // This is to make sure that plugins work over the widest range of AviSynth
88 // builds possible.
89 #define AVS_FRAME_ALIGN 64
90
91 #if defined(_M_AMD64) || defined(__x86_64)
92 # define AVS_X86_64
93 #elif defined(_M_IX86) || defined(__i386__)
94 # define AVS_X86_32
95 // VS2017 introduced _M_ARM64
96 #elif defined(_M_ARM64) || defined(__aarch64__)
97 # define AVS_ARM64
98 #elif defined(_M_ARM) || defined(__arm__)
99 # define AVS_ARM32
100 #elif defined(__PPC64__)
101 # define AVS_PPC64
102 #elif defined(_M_PPC) || defined(__PPC__) || defined(__POWERPC__)
103 # define AVS_PPC32
104 #elif defined(__riscv)
105 # define AVS_RISCV
106 #elif defined(__sparc_v9__)
107 # define AVS_SPARC
108 #endif
109
110 // VC++ LLVM-Clang-cl MinGW-Gnu
111 // AVS_MSVC x x
112 // AVS_MSVC_PURE x
113 // AVS_CLANG x
114 // AVS_GCC x
115
116 #if defined(__clang__)
117 // Check clang first. clang-cl also defines __MSC_VER
118 // We set AVS_MSVC because they are mostly compatible
119 # define AVS_CLANG
120 #if defined(_MSC_VER)
121 # define AVS_MSVC
122 #endif
123 #elif defined(_MSC_VER)
124 # define AVS_MSVC
125 # define AVS_MSVC_PURE
126 #elif defined(__GNUC__)
127 # define AVS_GCC
128 #endif
129
130 #if defined(_WIN32) || defined(__CYGWIN__)
131 # define AVS_WINDOWS
132 #elif defined(__linux__)
133 # define AVS_LINUX
134 # define AVS_POSIX
135 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
136 # define AVS_BSD
137 # define AVS_POSIX
138 #elif defined(__APPLE__)
139 # define AVS_MACOS
140 # define AVS_POSIX
141 #elif defined(__HAIKU__)
142 # define AVS_HAIKU
143 # define AVS_POSIX
144 #endif
145
146 #ifndef AVS_MSVC
147 // GCC and Clang can be used on big endian systems, MSVC can't.
148 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
149 # define AVS_ENDIANNESS "little"
150 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
151 # define AVS_ENDIANNESS "big"
152 # else
153 # define AVS_ENDIANNESS "middle"
154 # endif
155 #else
156 #define AVS_ENDIANNESS "little"
157 #endif
158
159 #endif //AVS_CONFIG_H
160
161 #ifndef AVS_CAPI_H
162 #define AVS_CAPI_H
163
164 #ifdef AVS_POSIX
165 // this is also defined in avs/posix.h
166 #ifndef AVS_HAIKU
167 #define __declspec(x)
168 #endif
169 #endif
38170
39171 #ifdef __cplusplus
40172 # define EXTERN_C extern "C"
42174 # define EXTERN_C
43175 #endif
44176
45 #define AVSC_USE_STDCALL 1
46
47 #ifndef AVSC_USE_STDCALL
48 # define AVSC_CC __cdecl
49 #else
50 # define AVSC_CC __stdcall
51 #endif
177 #ifdef AVS_WINDOWS
178 #ifdef BUILDING_AVSCORE
179 # if defined(AVS_GCC) && defined(AVS_X86_32)
180 # define AVSC_CC
181 # else // MSVC builds and 64-bit GCC
182 # ifndef AVSC_USE_STDCALL
183 # define AVSC_CC __cdecl
184 # else
185 # define AVSC_CC __stdcall
186 # endif
187 # endif
188 #else // needed for programs that talk to AviSynth+
189 # ifndef AVSC_WIN32_GCC32 // see comment below
190 # ifndef AVSC_USE_STDCALL
191 # define AVSC_CC __cdecl
192 # else
193 # define AVSC_CC __stdcall
194 # endif
195 # else
196 # define AVSC_CC
197 # endif
198 #endif
199 # else
200 # define AVSC_CC
201 #endif
202
203 // On 64-bit Windows, there's only one calling convention,
204 // so there is no difference between MSVC and GCC. On 32-bit,
205 // this isn't true. The convention that GCC needs to use to
206 // even build AviSynth+ as 32-bit makes anything that uses
207 // it incompatible with 32-bit MSVC builds of AviSynth+.
208 // The AVSC_WIN32_GCC32 define is meant to provide a user
209 // switchable way to make builds of FFmpeg to test 32-bit
210 // GCC builds of AviSynth+ without having to screw around
211 // with alternate headers, while still default to the usual
212 // situation of using 32-bit MSVC builds of AviSynth+.
213
214 // Hopefully, this situation will eventually be resolved
215 // and a broadly compatible solution will arise so the
216 // same 32-bit FFmpeg build can handle either MSVC or GCC
217 // builds of AviSynth+.
52218
53219 #define AVSC_INLINE static __inline
54220
55 #ifdef AVISYNTH_C_EXPORTS
56 # define AVSC_EXPORT __declspec(dllexport)
221 #ifdef BUILDING_AVSCORE
222 #ifdef AVS_WINDOWS
223 # ifndef AVS_STATIC_LIB
224 # define AVSC_EXPORT __declspec(dllexport)
225 # else
226 # define AVSC_EXPORT
227 # endif
57228 # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
58229 #else
59 # define AVSC_EXPORT __declspec(dllimport)
230 # define AVSC_EXPORT EXTERN_C
231 # define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name
232 #endif
233 #else
234 # define AVSC_EXPORT EXTERN_C __declspec(dllexport)
235 # ifndef AVS_STATIC_LIB
236 # define AVSC_IMPORT __declspec(dllimport)
237 # else
238 # define AVSC_IMPORT
239 # endif
60240 # ifndef AVSC_NO_DECLSPEC
61 # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
241 # define AVSC_API(ret, name) EXTERN_C AVSC_IMPORT ret AVSC_CC name
62242 # else
63243 # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
64244 # endif
65245 #endif
66246
67 typedef unsigned char BYTE;
68 #ifdef __GNUC__
69 typedef long long int INT64;
70 #else
71 typedef __int64 INT64;
72 #endif
73
247 #endif //AVS_CAPI_H
248
249 #ifndef AVS_TYPES_H
250 #define AVS_TYPES_H
251
252 // Define all types necessary for interfacing with avisynth.dll
253 #include <stdint.h>
254
255 // Raster types used by VirtualDub & Avisynth
256 typedef uint8_t BYTE;
257
258 #endif //AVS_TYPES_H
74259
75260 /////////////////////////////////////////////////////////////////////
76261 //
77262 // Constants
78263 //
79264
80 #ifndef __AVISYNTH_6_H__
81 enum { AVISYNTH_INTERFACE_VERSION = 6 };
265 #ifndef __AVISYNTH_9_H__
266 enum {
267 AVISYNTH_INTERFACE_CLASSIC_VERSION = 6,
268 AVISYNTH_INTERFACE_VERSION = 9,
269 AVISYNTHPLUS_INTERFACE_BUGFIX_VERSION = 0 // reset to zero whenever the normal interface version bumps
270 };
82271 #endif
83272
84273 enum {AVS_SAMPLE_INT8 = 1<<0,
104293 AVS_PLANAR_B_ALIGNED=AVS_PLANAR_B|AVS_PLANAR_ALIGNED};
105294
106295 // Colorspace properties.
107 enum {AVS_CS_BGR = 1<<28,
108 AVS_CS_YUV = 1<<29,
109 AVS_CS_INTERLEAVED = 1<<30,
110 AVS_CS_PLANAR = 1<<31,
111
112 AVS_CS_SHIFT_SUB_WIDTH = 0,
113 AVS_CS_SHIFT_SUB_HEIGHT = 8,
114 AVS_CS_SHIFT_SAMPLE_BITS = 16,
115
116 AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
117 AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
118 AVS_CS_SUB_WIDTH_2 = 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
119 AVS_CS_SUB_WIDTH_4 = 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
120
121 AVS_CS_VPLANEFIRST = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
122 AVS_CS_UPLANEFIRST = 1 << 4, // I420
123
124 AVS_CS_SUB_HEIGHT_MASK = 7 << AVS_CS_SHIFT_SUB_HEIGHT,
125 AVS_CS_SUB_HEIGHT_1 = 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
126 AVS_CS_SUB_HEIGHT_2 = 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
127 AVS_CS_SUB_HEIGHT_4 = 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
128
129 AVS_CS_SAMPLE_BITS_MASK = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
130 AVS_CS_SAMPLE_BITS_8 = 0 << AVS_CS_SHIFT_SAMPLE_BITS,
131 AVS_CS_SAMPLE_BITS_16 = 1 << AVS_CS_SHIFT_SAMPLE_BITS,
132 AVS_CS_SAMPLE_BITS_32 = 2 << AVS_CS_SHIFT_SAMPLE_BITS,
133
134 AVS_CS_PLANAR_MASK = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_BGR | AVS_CS_SAMPLE_BITS_MASK | AVS_CS_SUB_HEIGHT_MASK | AVS_CS_SUB_WIDTH_MASK,
135 AVS_CS_PLANAR_FILTER = ~( AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST )};
136
137 // Specific colorformats
296 enum {
297 AVS_CS_YUVA = 1 << 27,
298 AVS_CS_BGR = 1 << 28,
299 AVS_CS_YUV = 1 << 29,
300 AVS_CS_INTERLEAVED = 1 << 30,
301 AVS_CS_PLANAR = 1 << 31,
302
303 AVS_CS_SHIFT_SUB_WIDTH = 0,
304 AVS_CS_SHIFT_SUB_HEIGHT = 8,
305 AVS_CS_SHIFT_SAMPLE_BITS = 16,
306
307 AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
308 AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
309 AVS_CS_SUB_WIDTH_2 = 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
310 AVS_CS_SUB_WIDTH_4 = 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
311
312 AVS_CS_VPLANEFIRST = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
313 AVS_CS_UPLANEFIRST = 1 << 4, // I420
314
315 AVS_CS_SUB_HEIGHT_MASK = 7 << AVS_CS_SHIFT_SUB_HEIGHT,
316 AVS_CS_SUB_HEIGHT_1 = 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
317 AVS_CS_SUB_HEIGHT_2 = 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
318 AVS_CS_SUB_HEIGHT_4 = 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
319
320 AVS_CS_SAMPLE_BITS_MASK = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
321 AVS_CS_SAMPLE_BITS_8 = 0 << AVS_CS_SHIFT_SAMPLE_BITS,
322 AVS_CS_SAMPLE_BITS_10 = 5 << AVS_CS_SHIFT_SAMPLE_BITS,
323 AVS_CS_SAMPLE_BITS_12 = 6 << AVS_CS_SHIFT_SAMPLE_BITS,
324 AVS_CS_SAMPLE_BITS_14 = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
325 AVS_CS_SAMPLE_BITS_16 = 1 << AVS_CS_SHIFT_SAMPLE_BITS,
326 AVS_CS_SAMPLE_BITS_32 = 2 << AVS_CS_SHIFT_SAMPLE_BITS,
327
328 AVS_CS_PLANAR_MASK = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_BGR | AVS_CS_YUVA | AVS_CS_SAMPLE_BITS_MASK | AVS_CS_SUB_HEIGHT_MASK | AVS_CS_SUB_WIDTH_MASK,
329 AVS_CS_PLANAR_FILTER = ~(AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST),
330
331 AVS_CS_RGB_TYPE = 1 << 0,
332 AVS_CS_RGBA_TYPE = 1 << 1,
333
334 AVS_CS_GENERIC_YUV420 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // 4:2:0 planar
335 AVS_CS_GENERIC_YUV422 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // 4:2:2 planar
336 AVS_CS_GENERIC_YUV444 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1, // 4:4:4 planar
337 AVS_CS_GENERIC_Y = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV, // Y only (4:0:0)
338 AVS_CS_GENERIC_RGBP = AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGB_TYPE, // planar RGB
339 AVS_CS_GENERIC_RGBAP = AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGBA_TYPE, // planar RGBA
340 AVS_CS_GENERIC_YUVA420 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // 4:2:0:A planar
341 AVS_CS_GENERIC_YUVA422 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // 4:2:2:A planar
342 AVS_CS_GENERIC_YUVA444 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1 }; // 4:4:4:A planar
343
344
345 // Specific color formats
138346 enum {
139347 AVS_CS_UNKNOWN = 0,
140 AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
141 AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
348 AVS_CS_BGR24 = AVS_CS_RGB_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED,
349 AVS_CS_BGR32 = AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED,
142350 AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
143351 // AVS_CS_YV12 = 1<<3 Reserved
144352 // AVS_CS_I420 = 1<<4 Reserved
145353 AVS_CS_RAW32 = 1<<5 | AVS_CS_INTERLEAVED,
146354
147 AVS_CS_YV24 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1, // YVU 4:4:4 planar
148 AVS_CS_YV16 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:2 planar
149 AVS_CS_YV12 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:0 planar
355 AVS_CS_YV24 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_8, // YUV 4:4:4 planar
356 AVS_CS_YV16 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_8, // YUV 4:2:2 planar
357 AVS_CS_YV12 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_8, // YUV 4:2:0 planar
150358 AVS_CS_I420 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_UPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // YUV 4:2:0 planar
151359 AVS_CS_IYUV = AVS_CS_I420,
152 AVS_CS_YV411 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_4, // YVU 4:1:1 planar
153 AVS_CS_YUV9 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_4 | AVS_CS_SUB_WIDTH_4, // YVU 4:1:0 planar
154 AVS_CS_Y8 = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 // Y 4:0:0 planar
360 AVS_CS_YV411 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_4, // YUV 4:1:1 planar
361 AVS_CS_YUV9 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_4 | AVS_CS_SUB_WIDTH_4, // YUV 4:1:0 planar
362 AVS_CS_Y8 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_8, // Y 4:0:0 planar
363
364 //-------------------------
365 // AVS16: new planar constants go live! Experimental PF 160613
366 // 10-12-14-16 bit + planar RGB + BGR48/64 160725
367 AVS_CS_YUV444P10 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_10, // YUV 4:4:4 10bit samples
368 AVS_CS_YUV422P10 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:2 10bit samples
369 AVS_CS_YUV420P10 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:0 10bit samples
370 AVS_CS_Y10 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_10, // Y 4:0:0 10bit samples
371
372 AVS_CS_YUV444P12 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_12, // YUV 4:4:4 12bit samples
373 AVS_CS_YUV422P12 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:2 12bit samples
374 AVS_CS_YUV420P12 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:0 12bit samples
375 AVS_CS_Y12 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_12, // Y 4:0:0 12bit samples
376
377 AVS_CS_YUV444P14 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_14, // YUV 4:4:4 14bit samples
378 AVS_CS_YUV422P14 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:2 14bit samples
379 AVS_CS_YUV420P14 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:0 14bit samples
380 AVS_CS_Y14 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_14, // Y 4:0:0 14bit samples
381
382 AVS_CS_YUV444P16 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_16, // YUV 4:4:4 16bit samples
383 AVS_CS_YUV422P16 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:2 16bit samples
384 AVS_CS_YUV420P16 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:0 16bit samples
385 AVS_CS_Y16 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_16, // Y 4:0:0 16bit samples
386
387 // 32 bit samples (float)
388 AVS_CS_YUV444PS = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_32, // YUV 4:4:4 32bit samples
389 AVS_CS_YUV422PS = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_32, // YUV 4:2:2 32bit samples
390 AVS_CS_YUV420PS = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_32, // YUV 4:2:0 32bit samples
391 AVS_CS_Y32 = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_32, // Y 4:0:0 32bit samples
392
393 // RGB packed
394 AVS_CS_BGR48 = AVS_CS_RGB_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16, // BGR 3x16 bit
395 AVS_CS_BGR64 = AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16, // BGR 4x16 bit
396 // no packed 32 bit (float) support for these legacy types
397
398 // RGB planar
399 AVS_CS_RGBP = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_8, // Planar RGB 8 bit samples
400 AVS_CS_RGBP10 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_10, // Planar RGB 10bit samples
401 AVS_CS_RGBP12 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_12, // Planar RGB 12bit samples
402 AVS_CS_RGBP14 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_14, // Planar RGB 14bit samples
403 AVS_CS_RGBP16 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_16, // Planar RGB 16bit samples
404 AVS_CS_RGBPS = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_32, // Planar RGB 32bit samples
405
406 // RGBA planar
407 AVS_CS_RGBAP = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_8, // Planar RGBA 8 bit samples
408 AVS_CS_RGBAP10 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_10, // Planar RGBA 10bit samples
409 AVS_CS_RGBAP12 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_12, // Planar RGBA 12bit samples
410 AVS_CS_RGBAP14 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_14, // Planar RGBA 14bit samples
411 AVS_CS_RGBAP16 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_16, // Planar RGBA 16bit samples
412 AVS_CS_RGBAPS = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_32, // Planar RGBA 32bit samples
413
414 // Planar YUVA
415 AVS_CS_YUVA444 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:4:4 8bit samples
416 AVS_CS_YUVA422 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:2:2 8bit samples
417 AVS_CS_YUVA420 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:2:0 8bit samples
418
419 AVS_CS_YUVA444P10 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:4:4 10bit samples
420 AVS_CS_YUVA422P10 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:2 10bit samples
421 AVS_CS_YUVA420P10 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:0 10bit samples
422
423 AVS_CS_YUVA444P12 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:4:4 12bit samples
424 AVS_CS_YUVA422P12 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:2 12bit samples
425 AVS_CS_YUVA420P12 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:0 12bit samples
426
427 AVS_CS_YUVA444P14 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:4:4 14bit samples
428 AVS_CS_YUVA422P14 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:2 14bit samples
429 AVS_CS_YUVA420P14 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:0 14bit samples
430
431 AVS_CS_YUVA444P16 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:4:4 16bit samples
432 AVS_CS_YUVA422P16 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:2 16bit samples
433 AVS_CS_YUVA420P16 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:0 16bit samples
434
435 AVS_CS_YUVA444PS = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:4:4 32bit samples
436 AVS_CS_YUVA422PS = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:2:2 32bit samples
437 AVS_CS_YUVA420PS = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:2:0 32bit samples
438
155439 };
156440
157441 enum {
179463
180464 enum {
181465 // New 2.6 explicitly defined cache hints.
182 AVS_CACHE_NOTHING=10, // Do not cache video.
183 AVS_CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N.
184 AVS_CACHE_GENERIC=12, // LRU cache upto X frames.
185 AVS_CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW.
186
187 AVS_CACHE_GET_POLICY=30, // Get the current policy.
188 AVS_CACHE_GET_WINDOW=31, // Get the current window h_span.
189 AVS_CACHE_GET_RANGE=32, // Get the current generic frame range.
190
191 AVS_CACHE_AUDIO=50, // Explicitly do cache audio, X byte cache.
192 AVS_CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio.
193 AVS_CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache.
194 AVS_CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache.
195
196 AVS_CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy.
197 AVS_CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size.
198
199 AVS_CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N.
200 AVS_CACHE_PREFETCH_GO=101, // Action video prefetches.
201
202 AVS_CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section).
203 AVS_CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start.
204 AVS_CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start.
205 AVS_CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length.
206 AVS_CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section).
207 AVS_CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches.
208
209 AVS_CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode.
210 AVS_CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size.
211 AVS_CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode.
212 AVS_CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size.
213
214 AVS_CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost.
215 AVS_CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only).
216 AVS_CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit).
217 AVS_CACHE_COST_LOW=223, // Child response of light cost. (Fast)
218 AVS_CACHE_COST_MED=224, // Child response of medium cost. (Real time)
219 AVS_CACHE_COST_HI=225, // Child response of heavy cost. (Slow)
220
221 AVS_CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness.
222 AVS_CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default!
223 AVS_CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default!
224 AVS_CACHE_THREAD_SAFE=243, // Allow all threads in any instance.
225 AVS_CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded.
226
227 AVS_CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern.
228 AVS_CACHE_ACCESS_RAND=261, // Filter is access order agnostic.
229 AVS_CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost)
230 AVS_CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost)
231 };
232
233 #define AVS_FRAME_ALIGN 16
466 AVS_CACHE_NOTHING = 10, // Do not cache video.
467 AVS_CACHE_WINDOW = 11, // Hard protect up to X frames within a range of X from the current frame N.
468 AVS_CACHE_GENERIC = 12, // LRU cache up to X frames.
469 AVS_CACHE_FORCE_GENERIC = 13, // LRU cache up to X frames, override any previous CACHE_WINDOW.
470
471 AVS_CACHE_GET_POLICY = 30, // Get the current policy.
472 AVS_CACHE_GET_WINDOW = 31, // Get the current window h_span.
473 AVS_CACHE_GET_RANGE = 32, // Get the current generic frame range.
474
475 AVS_CACHE_AUDIO = 50, // Explicitly do cache audio, X byte cache.
476 AVS_CACHE_AUDIO_NOTHING = 51, // Explicitly do not cache audio.
477 AVS_CACHE_AUDIO_NONE = 52, // Audio cache off (auto mode), X byte initial cache.
478 AVS_CACHE_AUDIO_AUTO = 53, // Audio cache on (auto mode), X byte initial cache.
479
480 AVS_CACHE_GET_AUDIO_POLICY = 70, // Get the current audio policy.
481 AVS_CACHE_GET_AUDIO_SIZE = 71, // Get the current audio cache size.
482
483 AVS_CACHE_PREFETCH_FRAME = 100, // Queue request to prefetch frame N.
484 AVS_CACHE_PREFETCH_GO = 101, // Action video prefetches.
485
486 AVS_CACHE_PREFETCH_AUDIO_BEGIN = 120, // Begin queue request transaction to prefetch audio (take critical section).
487 AVS_CACHE_PREFETCH_AUDIO_STARTLO = 121, // Set low 32 bits of start.
488 AVS_CACHE_PREFETCH_AUDIO_STARTHI = 122, // Set high 32 bits of start.
489 AVS_CACHE_PREFETCH_AUDIO_COUNT = 123, // Set low 32 bits of length.
490 AVS_CACHE_PREFETCH_AUDIO_COMMIT = 124, // Enqueue request transaction to prefetch audio (release critical section).
491 AVS_CACHE_PREFETCH_AUDIO_GO = 125, // Action audio prefetches.
492
493 AVS_CACHE_GETCHILD_CACHE_MODE = 200, // Cache ask Child for desired video cache mode.
494 AVS_CACHE_GETCHILD_CACHE_SIZE = 201, // Cache ask Child for desired video cache size.
495 AVS_CACHE_GETCHILD_AUDIO_MODE = 202, // Cache ask Child for desired audio cache mode.
496 AVS_CACHE_GETCHILD_AUDIO_SIZE = 203, // Cache ask Child for desired audio cache size.
497
498 AVS_CACHE_GETCHILD_COST = 220, // Cache ask Child for estimated processing cost.
499 AVS_CACHE_COST_ZERO = 221, // Child response of zero cost (ptr arithmetic only).
500 AVS_CACHE_COST_UNIT = 222, // Child response of unit cost (less than or equal 1 full frame blit).
501 AVS_CACHE_COST_LOW = 223, // Child response of light cost. (Fast)
502 AVS_CACHE_COST_MED = 224, // Child response of medium cost. (Real time)
503 AVS_CACHE_COST_HI = 225, // Child response of heavy cost. (Slow)
504
505 AVS_CACHE_GETCHILD_THREAD_MODE = 240, // Cache ask Child for thread safety.
506 AVS_CACHE_THREAD_UNSAFE = 241, // Only 1 thread allowed for all instances. 2.5 filters default!
507 AVS_CACHE_THREAD_CLASS = 242, // Only 1 thread allowed for each instance. 2.6 filters default!
508 AVS_CACHE_THREAD_SAFE = 243, // Allow all threads in any instance.
509 AVS_CACHE_THREAD_OWN = 244, // Safe but limit to 1 thread, internally threaded.
510
511 AVS_CACHE_GETCHILD_ACCESS_COST = 260, // Cache ask Child for preferred access pattern.
512 AVS_CACHE_ACCESS_RAND = 261, // Filter is access order agnostic.
513 AVS_CACHE_ACCESS_SEQ0 = 262, // Filter prefers sequential access (low cost)
514 AVS_CACHE_ACCESS_SEQ1 = 263, // Filter needs sequential access (high cost)
515
516 AVS_CACHE_AVSPLUS_CONSTANTS = 500, // Smaller values are reserved for classic Avisynth
517
518 AVS_CACHE_DONT_CACHE_ME = 501, // Filters that don't need caching (eg. trim, cache etc.) should return 1 to this request
519 AVS_CACHE_SET_MIN_CAPACITY = 502,
520 AVS_CACHE_SET_MAX_CAPACITY = 503,
521 AVS_CACHE_GET_MIN_CAPACITY = 504,
522 AVS_CACHE_GET_MAX_CAPACITY = 505,
523 AVS_CACHE_GET_SIZE = 506,
524 AVS_CACHE_GET_REQUESTED_CAP = 507,
525 AVS_CACHE_GET_CAPACITY = 508,
526 AVS_CACHE_GET_MTMODE = 509,
527
528 AVS_CACHE_IS_CACHE_REQ = 510,
529 AVS_CACHE_IS_CACHE_ANS = 511,
530 AVS_CACHE_IS_MTGUARD_REQ = 512,
531 AVS_CACHE_IS_MTGUARD_ANS = 513,
532
533 AVS_CACHE_AVSPLUS_CUDA_CONSTANTS = 600,
534
535 AVS_CACHE_GET_DEV_TYPE = 601, // Device types a filter can return
536 AVS_CACHE_GET_CHILD_DEV_TYPE = 602, // Device types a fitler can receive
537
538 AVS_CACHE_USER_CONSTANTS = 1000 // Smaller values are reserved for the core
539
540 };
541
542
543
544 // enums for frame property functions
545 // AVSPropTypes
546 enum {
547 AVS_PROPTYPE_UNSET = 'u',
548 AVS_PROPTYPE_INT = 'i',
549 AVS_PROPTYPE_FLOAT = 'f',
550 AVS_PROPTYPE_DATA = 's',
551 AVS_PROPTYPE_CLIP = 'c',
552 AVS_PROPTYPE_FRAME = 'v'
553 };
554
555 // AVSGetPropErrors for avs_prop_get_...
556 enum {
557 AVS_GETPROPERROR_UNSET = 1,
558 AVS_GETPROPERROR_TYPE = 2,
559 AVS_GETPROPERROR_INDEX = 4
560 };
561
562 // AVSPropAppendMode for avs_prop_set_...
563 enum {
564 AVS_PROPAPPENDMODE_REPLACE = 0,
565 AVS_PROPAPPENDMODE_APPEND = 1,
566 AVS_PROPAPPENDMODE_TOUCH = 2
567 };
568
569 // AvsEnvProperty for avs_get_env_property
570 enum
571 {
572 AVS_AEP_PHYSICAL_CPUS = 1,
573 AVS_AEP_LOGICAL_CPUS = 2,
574 AVS_AEP_THREADPOOL_THREADS = 3,
575 AVS_AEP_FILTERCHAIN_THREADS = 4,
576 AVS_AEP_THREAD_ID = 5,
577 AVS_AEP_VERSION = 6,
578 AVS_AEP_HOST_SYSTEM_ENDIANNESS = 7,
579 AVS_AEP_INTERFACE_VERSION = 8,
580 AVS_AEP_INTERFACE_BUGFIX = 9,
581
582 // Neo additionals
583 AVS_AEP_NUM_DEVICES = 901,
584 AVS_AEP_FRAME_ALIGN = 902,
585 AVS_AEP_PLANE_ALIGN = 903,
586
587 AVS_AEP_SUPPRESS_THREAD = 921,
588 AVS_AEP_GETFRAME_RECURSIVE = 922
589 };
590
591 // enum AvsAllocType for avs_allocate
592 enum {
593 AVS_ALLOCTYPE_NORMAL_ALLOC = 1,
594 AVS_ALLOCTYPE_POOLED_ALLOC = 2
595 };
596
597 #ifdef BUILDING_AVSCORE
598 AVSValue create_c_video_filter(AVSValue args, void * user_data, IScriptEnvironment * e0);
599
600 struct AVS_ScriptEnvironment {
601 IScriptEnvironment * env;
602 const char * error;
603 AVS_ScriptEnvironment(IScriptEnvironment * e = 0)
604 : env(e), error(0) {}
605 };
606 #endif
234607
235608 typedef struct AVS_Clip AVS_Clip;
236609 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
240613 // AVS_VideoInfo
241614 //
242615
243 // AVS_VideoInfo is layed out identicly to VideoInfo
616 // AVS_VideoInfo is laid out identically to VideoInfo
244617 typedef struct AVS_VideoInfo {
245618 int width, height; // width=0 means no video
246619 unsigned fps_numerator, fps_denominator;
250623
251624 int audio_samples_per_second; // 0 means no audio
252625 int sample_type;
253 INT64 num_audio_samples;
626 int64_t num_audio_samples;
254627 int nchannels;
255628
256 // Imagetype properties
629 // Image type properties
257630
258631 int image_type;
259632 } AVS_VideoInfo;
280653 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
281654 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
282655
283 AVSC_API(int, avs_is_yv24)(const AVS_VideoInfo * p);
284
285 AVSC_API(int, avs_is_yv16)(const AVS_VideoInfo * p);
286
287 AVSC_API(int, avs_is_yv12)(const AVS_VideoInfo * p);
656 AVSC_API(int, avs_is_yv24)(const AVS_VideoInfo * p); // avs+: for generic 444 check, use avs_is_yuv444
657
658 AVSC_API(int, avs_is_yv16)(const AVS_VideoInfo * p); // avs+: for generic 422 check, use avs_is_yuv422
659
660 AVSC_API(int, avs_is_yv12)(const AVS_VideoInfo * p) ; // avs+: for generic 420 check, use avs_is_yuv420
288661
289662 AVSC_API(int, avs_is_yv411)(const AVS_VideoInfo * p);
290663
291 AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p);
664 AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p); // avs+: for generic grayscale, use avs_is_y
292665
293666 #ifdef AVSC_NO_DECLSPEC
294667 AVSC_INLINE int avs_is_yv24(const AVS_VideoInfo * p)
295 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV24 & AVS_CS_PLANAR_FILTER); }
668 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV24 & AVS_CS_PLANAR_FILTER); }
296669
297670 AVSC_INLINE int avs_is_yv16(const AVS_VideoInfo * p)
298 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV16 & AVS_CS_PLANAR_FILTER); }
671 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV16 & AVS_CS_PLANAR_FILTER); }
299672
300673 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
301 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV12 & AVS_CS_PLANAR_FILTER); }
674 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV12 & AVS_CS_PLANAR_FILTER); }
302675
303676 AVSC_INLINE int avs_is_yv411(const AVS_VideoInfo * p)
304677 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV411 & AVS_CS_PLANAR_FILTER); }
305678
306679 AVSC_INLINE int avs_is_y8(const AVS_VideoInfo * p)
307 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_Y8 & AVS_CS_PLANAR_FILTER); }
308 #endif
309
310 #if 1 // AviSynth+ extension
311 AVSC_API(int, avs_is_rgb48)(const AVS_VideoInfo * p);
312
313 AVSC_API(int, avs_is_rgb64)(const AVS_VideoInfo * p);
314
315 AVSC_API(int, avs_is_yuv444p16)(const AVS_VideoInfo * p);
316
317 AVSC_API(int, avs_is_yuv422p16)(const AVS_VideoInfo * p);
318
319 AVSC_API(int, avs_is_yuv420p16)(const AVS_VideoInfo * p);
320
321 AVSC_API(int, avs_is_y16)(const AVS_VideoInfo * p);
322
323 AVSC_API(int, avs_is_yuv444ps)(const AVS_VideoInfo * p);
324
325 AVSC_API(int, avs_is_yuv422ps)(const AVS_VideoInfo * p);
326
327 AVSC_API(int, avs_is_yuv420ps)(const AVS_VideoInfo * p);
328
329 AVSC_API(int, avs_is_y32)(const AVS_VideoInfo * p);
330
331 AVSC_API(int, avs_is_444)(const AVS_VideoInfo * p);
332
333 AVSC_API(int, avs_is_422)(const AVS_VideoInfo * p);
334
335 AVSC_API(int, avs_is_420)(const AVS_VideoInfo * p);
336
337 AVSC_API(int, avs_is_y)(const AVS_VideoInfo * p);
338
339 AVSC_API(int, avs_is_yuva)(const AVS_VideoInfo * p);
340
341 AVSC_API(int, avs_is_planar_rgb)(const AVS_VideoInfo * p);
342
343 AVSC_API(int, avs_is_planar_rgba)(const AVS_VideoInfo * p);
344
345 AVSC_API(int, avs_num_components)(const AVS_VideoInfo * p);
346
347 AVSC_API(int, avs_component_size)(const AVS_VideoInfo * p);
348
349 AVSC_API(int, avs_bits_per_component)(const AVS_VideoInfo * p);
350 #endif
351
680 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_Y8 & AVS_CS_PLANAR_FILTER); }
681 #endif
682
683 AVSC_API(int, avs_get_plane_width_subsampling)(const AVS_VideoInfo * p, int plane);
684
685 AVSC_API(int, avs_get_plane_height_subsampling)(const AVS_VideoInfo * p, int plane);
686
687 AVSC_API(int, avs_bits_per_pixel)(const AVS_VideoInfo * p);
688
689 AVSC_API(int, avs_bytes_from_pixels)(const AVS_VideoInfo * p, int pixels);
690
691 AVSC_API(int, avs_row_size)(const AVS_VideoInfo * p, int plane);
692
693 AVSC_API(int, avs_bmp_size)(const AVS_VideoInfo * vi);
694
695 AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
696
697 // no API for these, inline helper functions
352698 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
353 { return ((p->image_type & property)==property ); }
699 {
700 return ((p->image_type & property) == property);
701 }
354702
355703 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
356 { return !!(p->pixel_type & AVS_CS_PLANAR); }
357
358 AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
704 {
705 return !!(p->pixel_type & AVS_CS_PLANAR);
706 }
359707
360708 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
361 { return !!(p->image_type & AVS_IT_FIELDBASED); }
709 {
710 return !!(p->image_type & AVS_IT_FIELDBASED);
711 }
362712
363713 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
364 { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
714 {
715 return ((p->image_type & AVS_IT_FIELDBASED) && (p->image_type & (AVS_IT_BFF | AVS_IT_TFF)));
716 }
365717
366718 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
367 { return !!(p->image_type & AVS_IT_BFF); }
719 {
720 return !!(p->image_type & AVS_IT_BFF);
721 }
368722
369723 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
370 { return !!(p->image_type & AVS_IT_TFF); }
371
372 AVSC_API(int, avs_get_plane_width_subsampling)(const AVS_VideoInfo * p, int plane);
373
374 AVSC_API(int, avs_get_plane_height_subsampling)(const AVS_VideoInfo * p, int plane);
375
376
377 AVSC_API(int, avs_bits_per_pixel)(const AVS_VideoInfo * p);
378
379 AVSC_API(int, avs_bytes_from_pixels)(const AVS_VideoInfo * p, int pixels);
380
381 AVSC_API(int, avs_row_size_p)(const AVS_VideoInfo * p, int plane);
382
383 #ifndef AVSC_NO_DECLSPEC
384 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p)
385 { return avs_row_size_p(p, 0); }
386 #endif
387
388 AVSC_API(int, avs_bmp_size)(const AVS_VideoInfo * vi);
724 {
725 return !!(p->image_type & AVS_IT_TFF);
726 }
389727
390728 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
391729 { return p->audio_samples_per_second; }
392
393730
394731 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
395732 {
402739 default: return 0;
403740 }
404741 }
742
405743 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
406 { return p->nchannels*avs_bytes_per_channel_sample(p);}
407
408 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
409 { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
410
411 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
412 { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
413
414 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
744 { return p->nchannels*avs_bytes_per_channel_sample(p); }
745
746 AVSC_INLINE int64_t avs_audio_samples_from_frames(const AVS_VideoInfo * p, int64_t frames)
747 { return ((int64_t)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
748
749 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, int64_t samples)
750 { return (int)(samples * (int64_t)p->fps_numerator / (int64_t)p->fps_denominator / (int64_t)p->audio_samples_per_second); }
751
752 AVSC_INLINE int64_t avs_audio_samples_from_bytes(const AVS_VideoInfo * p, int64_t bytes)
415753 { return bytes / avs_bytes_per_audio_sample(p); }
416754
417 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
755 AVSC_INLINE int64_t avs_bytes_from_audio_samples(const AVS_VideoInfo * p, int64_t samples)
418756 { return samples * avs_bytes_per_audio_sample(p); }
419757
420758 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
421759 { return p->nchannels; }
422760
423761 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
424 { return p->sample_type;}
762 { return p->sample_type; }
425763
426764 // useful mutator
765 // Note: these are video format properties, neither frame properties, nor system properties
427766 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
428767 { p->image_type|=property; }
429768
443782 p->fps_denominator = denominator/x;
444783 }
445784
446 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
785 AVSC_INLINE int avs_is_same_colorspace(const AVS_VideoInfo * x, const AVS_VideoInfo * y)
447786 {
448787 return (x->pixel_type == y->pixel_type)
449788 || (avs_is_yv12(x) && avs_is_yv12(y));
450789 }
790
791 // AviSynth+ extensions
792 AVSC_API(int, avs_is_rgb48)(const AVS_VideoInfo * p);
793
794 AVSC_API(int, avs_is_rgb64)(const AVS_VideoInfo * p);
795
796 AVSC_API(int, avs_is_yuv444p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv444
797 AVSC_API(int, avs_is_yuv422p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv422
798 AVSC_API(int, avs_is_yuv420p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv420
799 AVSC_API(int, avs_is_y16)(const AVS_VideoInfo * p); // deprecated, use avs_is_y
800 AVSC_API(int, avs_is_yuv444ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv444
801 AVSC_API(int, avs_is_yuv422ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv422
802 AVSC_API(int, avs_is_yuv420ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv420
803 AVSC_API(int, avs_is_y32)(const AVS_VideoInfo * p); // deprecated, use avs_is_y
804
805 AVSC_API(int, avs_is_444)(const AVS_VideoInfo * p);
806
807 AVSC_API(int, avs_is_422)(const AVS_VideoInfo * p);
808
809 AVSC_API(int, avs_is_420)(const AVS_VideoInfo * p);
810
811 AVSC_API(int, avs_is_y)(const AVS_VideoInfo * p);
812
813 AVSC_API(int, avs_is_yuva)(const AVS_VideoInfo * p);
814
815 AVSC_API(int, avs_is_planar_rgb)(const AVS_VideoInfo * p);
816
817 AVSC_API(int, avs_is_planar_rgba)(const AVS_VideoInfo * p);
818
819 AVSC_API(int, avs_num_components)(const AVS_VideoInfo * p);
820
821 AVSC_API(int, avs_component_size)(const AVS_VideoInfo * p);
822
823 AVSC_API(int, avs_bits_per_component)(const AVS_VideoInfo * p);
824
825 // end of Avisynth+ specific
451826
452827 /////////////////////////////////////////////////////////////////////
453828 //
460835 // to be reused. The instances are deleted when the corresponding AVS
461836 // file is closed.
462837
463 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
838 // AVS_VideoFrameBuffer is laid out identically to VideoFrameBuffer
464839 // DO NOT USE THIS STRUCTURE DIRECTLY
465840 typedef struct AVS_VideoFrameBuffer {
466841 BYTE * data;
470845 volatile long sequence_number;
471846
472847 volatile long refcount;
848
849 void* device; // avs+
473850 } AVS_VideoFrameBuffer;
474851
475852 // VideoFrame holds a "window" into a VideoFrameBuffer.
476853
477 // AVS_VideoFrame is layed out identicly to IVideoFrame
854 // AVS_VideoFrame is laid out identically to IVideoFrame
478855 // DO NOT USE THIS STRUCTURE DIRECTLY
479856 typedef struct AVS_VideoFrame {
480857 volatile long refcount;
481858 AVS_VideoFrameBuffer * vfb;
482 int offset, pitch, row_size, height, offsetU, offsetV, pitchUV; // U&V offsets are from top of picture.
483 int row_sizeUV, heightUV;
859 int offset;
860 int pitch, row_size, height;
861 int offsetU, offsetV;
862 int pitchUV; // U&V offsets are from top of picture.
863 int row_sizeUV, heightUV; // for Planar RGB offsetU, offsetV is for the 2nd and 3rd Plane.
864 // for Planar RGB pitchUV and row_sizeUV = 0, because when no VideoInfo (MakeWriteable)
865 // the decision on existence of UV is checked by zero pitch
866 // AVS+ extension, avisynth.h: class does not break plugins if appended here
867 int offsetA;
868 int pitchA, row_sizeA; // 4th alpha plane support, pitch and row_size is 0 is none
869 void* properties; // frame properties
484870 } AVS_VideoFrame;
485871
486872 // Access functions for AVS_VideoFrame
487873 AVSC_API(int, avs_get_pitch_p)(const AVS_VideoFrame * p, int plane);
488874
875 AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
876
877 AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
878
879 AVSC_API(const BYTE *, avs_get_read_ptr_p)(const AVS_VideoFrame * p, int plane);
880
489881 #ifdef AVSC_NO_DECLSPEC
490 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) {
491 switch (plane) {
492 case AVS_PLANAR_U:
493 case AVS_PLANAR_V:
494 return p->pitchUV;
495 }
496 return p->pitch;
497 }
498 #endif
499
500 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
501 return avs_get_pitch_p(p, 0);}
502
503 AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
504
505 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
506 return p->row_size; }
507
508 AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
509
510 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
511 return p->height;}
512
513 AVSC_API(const BYTE *, avs_get_read_ptr_p)(const AVS_VideoFrame * p, int plane);
514
515 #ifdef AVSC_NO_DECLSPEC
516 AVSC_INLINE const BYTE* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane) {
517 switch (plane) {
518 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
519 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
520 default: return p->vfb->data + p->offset;
521 }
522 }
523 #endif
524
525 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
526 return avs_get_read_ptr_p(p, 0);}
882 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane)
883 {
884 switch (plane) {
885 case AVS_PLANAR_U: case AVS_PLANAR_V:
886 return p->pitchUV;
887 case AVS_PLANAR_A:
888 return p->pitchA;
889 }
890 return p->pitch; // Y, G, B, R
891 }
892
893 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane)
894 {
895 switch (plane) {
896 case AVS_PLANAR_U: case AVS_PLANAR_V:
897 return (p->pitchUV) ? p->row_sizeUV : 0;
898 case AVS_PLANAR_A:
899 return (p->pitchA) ? p->row_sizeA : 0;
900 }
901 return p->row_size;
902 }
903
904 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane)
905 {
906 switch (plane) {
907 case AVS_PLANAR_U: case AVS_PLANAR_V:
908 return (p->pitchUV) ? p->heightUV : 0;
909 case AVS_PLANAR_A:
910 return (p->pitchA) ? p->height : 0;
911 }
912 return p->height; // Y, G, B, R, A
913 }
914
915 AVSC_INLINE const BYTE * avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
916 {
917 switch (plane) { // G is first. Then B,R order like U,V
918 case AVS_PLANAR_U: case AVS_PLANAR_B:
919 return p->vfb->data + p->offsetU;
920 case AVS_PLANAR_V: case AVS_PLANAR_R:
921 return p->vfb->data + p->offsetV;
922 case AVS_PLANAR_A:
923 return p->vfb->data + p->offsetA;
924 }
925 return p->vfb->data + p->offset; // Y, G
926 }
927 #endif
527928
528929 AVSC_API(int, avs_is_writable)(const AVS_VideoFrame * p);
529930
931 // V9
932 AVSC_API(int, avs_is_property_writable)(const AVS_VideoFrame* p);
933
530934 AVSC_API(BYTE *, avs_get_write_ptr_p)(const AVS_VideoFrame * p, int plane);
531
532 #ifndef AVSC_NO_DECLSPEC
533 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p) {
534 return avs_get_write_ptr_p(p, 0);}
535 #endif
536935
537936 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
538937 // makes a shallow copy of a video frame
539938 AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
540939
940 // no API for these, inline helper functions
941 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p)
942 {return avs_get_pitch_p(p, 0);}
943
944 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p)
945 {return avs_get_row_size_p(p, 0);}
946
947 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p)
948 {return avs_get_height_p(p, 0);}
949
950 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p)
951 {return avs_get_read_ptr_p(p, 0);}
952
541953 #ifndef AVSC_NO_DECLSPEC
954 // this inline function is calling an API function
955 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p)
956 {return avs_get_write_ptr_p(p, 0);}
957 #endif
958
959 #ifndef AVSC_NO_DECLSPEC
960 // this inline function is calling an API function
542961 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
543962 {avs_release_video_frame(f);}
963 #endif
964
965 #ifndef AVSC_NO_DECLSPEC
966 // this inline function is calling an API function
544967 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
545968 {return avs_copy_video_frame(f);}
546969 #endif
970
971 // Interface V8: frame properties
972 // AVS_Map is just a placeholder for AVSMap
973 typedef struct AVS_Map {
974 void* data;
975 } AVS_Map;
976
547977
548978 /////////////////////////////////////////////////////////////////////
549979 //
551981 //
552982
553983 // Treat AVS_Value as a fat pointer. That is use avs_copy_value
554 // and avs_release_value appropiaty as you would if AVS_Value was
984 // and avs_release_value appropriately as you would if AVS_Value was
555985 // a pointer.
556986
557987 // To maintain source code compatibility with future versions of the
558988 // avisynth_c API don't use the AVS_Value directly. Use the helper
559989 // functions below.
560990
561 // AVS_Value is layed out identicly to AVSValue
991 // AVS_Value is laid out identically to AVSValue
562992 typedef struct AVS_Value AVS_Value;
563993 struct AVS_Value {
564 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
994 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong, or fu'n'ction
565995 // for some function e'rror
566996 short array_size;
567997 union {
5711001 float floating_pt;
5721002 const char * string;
5731003 const AVS_Value * array;
1004 void * function; // not supported on C interface
1005 #ifdef AVS_X86_64
1006 // if ever, only x64 will support. It breaks struct size on 32 bit
1007 int64_t longlong; // 8 bytes
1008 double double_pt; // 8 bytes
1009 #endif
5741010 } d;
5751011 };
5761012
577 // AVS_Value should be initilized with avs_void.
1013 // AVS_Value should be initialized with avs_void.
5781014 // Should also set to avs_void after the value is released
579 // with avs_copy_value. Consider it the equalvent of setting
1015 // with avs_copy_value. Consider it the equivalent of setting
5801016 // a pointer to NULL
5811017 static const AVS_Value avs_void = {'v'};
5821018
5831019 AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
5841020 AVSC_API(void, avs_release_value)(AVS_Value);
585
1021 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
1022 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
1023
1024
1025 // no API for these, inline helper functions
5861026 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
5871027 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
5881028 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
5911031 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
5921032 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
5931033 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
594
595 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
596 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
5971034
5981035 AVSC_INLINE int avs_as_bool(AVS_Value v)
5991036 { return v.d.boolean; }
6211058 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
6221059 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
6231060 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
624 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
1061 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v; }
6251062 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
6261063 { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
6271064 #ifndef AVSC_NO_DECLSPEC
1065 // this inline function is calling an API function
6281066 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
6291067 { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
6301068 #endif
6311069 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
6321070 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = (short)size; return v; }
1071 // end of inline helper functions
6331072
6341073 /////////////////////////////////////////////////////////////////////
6351074 //
6521091 // return field parity if field_based, else parity of first field in frame
6531092
6541093 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
655 INT64 start, INT64 count);
1094 int64_t start, int64_t count);
6561095 // start and count are in samples
6571096
6581097 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
6721111 AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
6731112 int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
6741113 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
675 INT64 start, INT64 count);
1114 int64_t start, int64_t count);
6761115 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
6771116 int frame_range);
6781117 void (AVSC_CC * free_filter)(AVS_FilterInfo *);
6861125
6871126 // Create a new filter
6881127 // fi is set to point to the AVS_FilterInfo so that you can
689 // modify it once it is initilized.
1128 // modify it once it is initialized.
6901129 // store_child should generally be set to true. If it is not
6911130 // set than ALL methods (the function pointers) must be defined
6921131 // If it is set than you do not need to worry about freeing the child
7171156 AVS_CPUF_SSSE3 = 0x200, // Core 2
7181157 AVS_CPUF_SSE4 = 0x400, // Penryn, Wolfdale, Yorkfield
7191158 AVS_CPUF_SSE4_1 = 0x400,
720 //AVS_CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
1159 AVS_CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
7211160 AVS_CPUF_SSE4_2 = 0x1000, // Nehalem
722 //AVS_CPUF_AVX2 = 0x2000, // Haswell
723 //AVS_CPUF_AVX512 = 0x4000, // Knights Landing
1161 // AVS+
1162 AVS_CPUF_AVX2 = 0x2000, // Haswell
1163 AVS_CPUF_FMA3 = 0x4000,
1164 AVS_CPUF_F16C = 0x8000,
1165 AVS_CPUF_MOVBE = 0x10000, // Big Endian Move
1166 AVS_CPUF_POPCNT = 0x20000,
1167 AVS_CPUF_AES = 0x40000,
1168 AVS_CPUF_FMA4 = 0x80000,
1169
1170 AVS_CPUF_AVX512F = 0x100000, // AVX-512 Foundation.
1171 AVS_CPUF_AVX512DQ = 0x200000, // AVX-512 DQ (Double/Quad granular) Instructions
1172 AVS_CPUF_AVX512PF = 0x400000, // AVX-512 Prefetch
1173 AVS_CPUF_AVX512ER = 0x800000, // AVX-512 Exponential and Reciprocal
1174 AVS_CPUF_AVX512CD = 0x1000000, // AVX-512 Conflict Detection
1175 AVS_CPUF_AVX512BW = 0x2000000, // AVX-512 BW (Byte/Word granular) Instructions
1176 AVS_CPUF_AVX512VL = 0x4000000, // AVX-512 VL (128/256 Vector Length) Extensions
1177 AVS_CPUF_AVX512IFMA = 0x8000000, // AVX-512 IFMA integer 52 bit
1178 AVS_CPUF_AVX512VBMI = 0x10000000 // AVX-512 VBMI
7241179 };
7251180
7261181
7271182 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
7281183
729 AVSC_API(long, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
1184 AVSC_API(int, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
7301185 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
7311186
7321187 AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
7331188 AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
7341189
735 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, void* val);
736 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
1190 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, va_list val);
7371191
7381192 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
7391193 const char * name, const char * params,
7551209 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
7561210 //void avs_pop_context(AVS_ScriptEnvironment *);
7571211
1212 // partially deprecated, from V8 use avs_new_video_frame_p_a (frame property copy)
7581213 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
7591214 const AVS_VideoInfo * vi, int align);
760 // align should be at least 16
761
1215 // align should be at least 16 for classic Avisynth
1216 // Avisynth+: any value, Avs+ ensures a minimum alignment if too small align is provided
1217
1218 // no API for these, inline helper functions
7621219 #ifndef AVSC_NO_DECLSPEC
763 AVSC_INLINE
764 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
1220 // partially deprecated, from V8 use avs_new_video_frame_p (frame property copy)
1221 // this inline function is calling an API function
1222 AVSC_INLINE AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
7651223 const AVS_VideoInfo * vi)
7661224 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
7671225
768 AVSC_INLINE
769 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
1226 // an older compatibility alias
1227 // this inline function is calling an API function
1228 AVSC_INLINE AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
7701229 const AVS_VideoInfo * vi)
7711230 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
7721231 #endif
773
1232 // end of inline helper functions
7741233
7751234 AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
1235
1236 // V9
1237 AVSC_API(int, avs_make_property_writable)(AVS_ScriptEnvironment*, AVS_VideoFrame** pvf);
7761238
7771239 AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
7781240
7811243
7821244 AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
7831245 // The returned video frame must be be released
1246 AVSC_API(AVS_VideoFrame*, avs_subframe_planar)(AVS_ScriptEnvironment*, AVS_VideoFrame* src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV);
1247 // The returned video frame must be be released
1248 // see also avs_subframe_planar_a in interface V8
7841249
7851250 AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
7861251
7981263
7991264 AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
8001265
801
802 AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV);
1266 ///////////////////////////////////////////////////////////////////////////////
1267 //
1268 // Avisynth+ V8 interface elements
1269 //
1270
1271 AVSC_API(AVS_VideoFrame*, avs_subframe_planar_a)(AVS_ScriptEnvironment*, AVS_VideoFrame* src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV, int rel_offsetA);
8031272 // The returned video frame must be be released
8041273
1274 AVSC_API(void, avs_copy_frame_props)(AVS_ScriptEnvironment* p, const AVS_VideoFrame* src, AVS_VideoFrame* dst);
1275 AVSC_API(const AVS_Map*, avs_get_frame_props_ro)(AVS_ScriptEnvironment* p, const AVS_VideoFrame* frame);
1276 AVSC_API(AVS_Map*, avs_get_frame_props_rw)(AVS_ScriptEnvironment* p, AVS_VideoFrame* frame);
1277 AVSC_API(int, avs_prop_num_keys)(AVS_ScriptEnvironment* p, const AVS_Map* map);
1278 AVSC_API(const char*, avs_prop_get_key)(AVS_ScriptEnvironment* p, const AVS_Map* map, int index);
1279 AVSC_API(int, avs_prop_num_elements)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key);
1280
1281 // see AVS_PROPTYPE_... enums
1282 AVSC_API(char, avs_prop_get_type)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key);
1283
1284 // see AVS_GETPROPERROR_... enums
1285 AVSC_API(int64_t, avs_prop_get_int)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1286 AVSC_API(double, avs_prop_get_float)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1287 AVSC_API(const char*, avs_prop_get_data)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1288 AVSC_API(int, avs_prop_get_data_size)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1289 AVSC_API(AVS_Clip*, avs_prop_get_clip)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1290 AVSC_API(const AVS_VideoFrame*, avs_prop_get_frame)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int* error);
1291
1292 AVSC_API(int, avs_prop_delete_key)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key);
1293
1294 // see AVS_PROPAPPENDMODE_... enums
1295 AVSC_API(int, avs_prop_set_int)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, int64_t i, int append);
1296 AVSC_API(int, avs_prop_set_float)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, double d, int append);
1297 AVSC_API(int, avs_prop_set_data)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, const char* d, int length, int append);
1298 AVSC_API(int, avs_prop_set_clip)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, AVS_Clip* clip, int append);
1299 AVSC_API(int, avs_prop_set_frame)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, const AVS_VideoFrame* frame, int append);
1300
1301 AVSC_API(const int64_t*, avs_prop_get_int_array)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int* error);
1302 AVSC_API(const double*, avs_prop_get_float_array)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int* error);
1303 AVSC_API(int, avs_prop_set_int_array)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, const int64_t* i, int size);
1304 AVSC_API(int, avs_prop_set_float_array)(AVS_ScriptEnvironment* p, AVS_Map* map, const char* key, const double* d, int size);
1305
1306 AVSC_API(void, avs_clear_map)(AVS_ScriptEnvironment* p, AVS_Map* map);
1307
1308 // with frame property source
1309 AVSC_API(AVS_VideoFrame*, avs_new_video_frame_p)(AVS_ScriptEnvironment*,
1310 const AVS_VideoInfo* vi, AVS_VideoFrame* propSrc);
1311
1312 // with frame property source
1313 AVSC_API(AVS_VideoFrame*, avs_new_video_frame_p_a)(AVS_ScriptEnvironment*,
1314 const AVS_VideoInfo* vi, AVS_VideoFrame* propSrc, int align);
1315
1316 // Generic query to ask for various system properties, see AVS_AEP_xxx enums
1317 AVSC_API(size_t, avs_get_env_property)(AVS_ScriptEnvironment*, int avs_aep_prop);
1318
1319 // buffer pool, see AVS_ALLOCTYPE enums
1320 AVSC_API(void *, avs_pool_allocate)(AVS_ScriptEnvironment*, size_t nBytes, size_t alignment, int avs_alloc_type);
1321 AVSC_API(void, avs_pool_free)(AVS_ScriptEnvironment*, void *ptr);
1322
1323 // Interface V8
1324 // Returns TRUE (1) and the requested variable. If the method fails, returns 0 (FALSE) and does not touch 'val'.
1325 // The returned AVS_Value *val value must be be released with avs_release_value only on success
1326 // AVS_Value *val is not caller allocated
1327 AVSC_API(int, avs_get_var_try)(AVS_ScriptEnvironment*, const char* name, AVS_Value* val);
1328
1329 // Interface V8
1330 // Return the value of the requested variable.
1331 // If the variable was not found or had the wrong type,
1332 // return the supplied default value.
1333 AVSC_API(int, avs_get_var_bool)(AVS_ScriptEnvironment*, const char* name, int def);
1334 AVSC_API(int, avs_get_var_int)(AVS_ScriptEnvironment*, const char* name, int def);
1335 AVSC_API(double, avs_get_var_double)(AVS_ScriptEnvironment*, const char* name, double def);
1336 AVSC_API(const char*, avs_get_var_string)(AVS_ScriptEnvironment*, const char* name, const char* def);
1337 AVSC_API(int64_t, avs_get_var_long)(AVS_ScriptEnvironment*, const char* name, int64_t def);
1338
1339 #if defined(AVS_WINDOWS)
1340 // The following stuff is only relevant for Windows DLL handling; Linux does it completely differently.
8051341 #ifdef AVSC_NO_DECLSPEC
806 // use LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport)
1342 // This part uses LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport)
1343 // When AVSC_NO_DECLSPEC is defined, you can use avs_load_library to populate API functions into a struct
1344 // AVSC_INLINE functions which call onto an API functions should be treated specially (todo)
1345
8071346 /*
8081347 The following functions needs to have been declared, probably from windows.h
8091348
8101349 void* malloc(size_t)
8111350 void free(void*);
8121351
813 HMODULE LoadLibrary(const char*);
1352 HMODULE LoadLibraryA(const char*);
8141353 void* GetProcAddress(HMODULE, const char*);
8151354 FreeLibrary(HMODULE);
8161355 */
8191358 typedef struct AVS_Library AVS_Library;
8201359
8211360 #define AVSC_DECLARE_FUNC(name) name##_func name
1361
1362 // AVSC_DECLARE_FUNC helps keeping naming convention: type is xxxxx_func, function name is xxxxx
1363 // e.g. "AVSC_DECLARE_FUNC(avs_add_function);"
1364 // is a shortcut for "avs_add_function_func avs_add_function;"
1365
1366 // Note: AVSC_INLINE functions which call into API,
1367 // are guarded by #ifndef AVSC_NO_DECLSPEC
1368 // They should call the appropriate library-> API entry
8221369
8231370 struct AVS_Library {
8241371 HMODULE handle;
8731420 AVSC_DECLARE_FUNC(avs_get_plane_height_subsampling);
8741421 AVSC_DECLARE_FUNC(avs_bits_per_pixel);
8751422 AVSC_DECLARE_FUNC(avs_bytes_from_pixels);
876 AVSC_DECLARE_FUNC(avs_row_size_p);
1423 AVSC_DECLARE_FUNC(avs_row_size);
8771424 AVSC_DECLARE_FUNC(avs_bmp_size);
8781425 AVSC_DECLARE_FUNC(avs_get_pitch_p);
8791426 AVSC_DECLARE_FUNC(avs_get_row_size_p);
8811428 AVSC_DECLARE_FUNC(avs_get_read_ptr_p);
8821429 AVSC_DECLARE_FUNC(avs_is_writable);
8831430 AVSC_DECLARE_FUNC(avs_get_write_ptr_p);
1431
1432 // Avisynth+ specific
1433 // Note: these functions are simulated/use fallback to existing functions
1434 AVSC_DECLARE_FUNC(avs_is_rgb48);
1435 AVSC_DECLARE_FUNC(avs_is_rgb64);
1436 AVSC_DECLARE_FUNC(avs_is_yuv444p16);
1437 AVSC_DECLARE_FUNC(avs_is_yuv422p16);
1438 AVSC_DECLARE_FUNC(avs_is_yuv420p16);
1439 AVSC_DECLARE_FUNC(avs_is_y16);
1440 AVSC_DECLARE_FUNC(avs_is_yuv444ps);
1441 AVSC_DECLARE_FUNC(avs_is_yuv422ps);
1442 AVSC_DECLARE_FUNC(avs_is_yuv420ps);
1443 AVSC_DECLARE_FUNC(avs_is_y32);
1444 AVSC_DECLARE_FUNC(avs_is_444);
1445 AVSC_DECLARE_FUNC(avs_is_422);
1446 AVSC_DECLARE_FUNC(avs_is_420);
1447 AVSC_DECLARE_FUNC(avs_is_y);
1448 AVSC_DECLARE_FUNC(avs_is_yuva);
1449 AVSC_DECLARE_FUNC(avs_is_planar_rgb);
1450 AVSC_DECLARE_FUNC(avs_is_planar_rgba);
1451 AVSC_DECLARE_FUNC(avs_num_components);
1452 AVSC_DECLARE_FUNC(avs_component_size);
1453 AVSC_DECLARE_FUNC(avs_bits_per_component);
1454
1455 ///////////////////////////////////////////////////////////////////////////////
1456 // Avisynth+ new interface elements from interface version 8
1457 // avs_subframe_planar with alpha support
1458 AVSC_DECLARE_FUNC(avs_subframe_planar_a);
1459
1460 // frame properties
1461 AVSC_DECLARE_FUNC(avs_copy_frame_props);
1462 AVSC_DECLARE_FUNC(avs_get_frame_props_ro);
1463 AVSC_DECLARE_FUNC(avs_get_frame_props_rw);
1464 AVSC_DECLARE_FUNC(avs_prop_num_keys);
1465 AVSC_DECLARE_FUNC(avs_prop_get_key);
1466 AVSC_DECLARE_FUNC(avs_prop_num_elements);
1467 AVSC_DECLARE_FUNC(avs_prop_get_type);
1468 AVSC_DECLARE_FUNC(avs_prop_get_int);
1469 AVSC_DECLARE_FUNC(avs_prop_get_float);
1470 AVSC_DECLARE_FUNC(avs_prop_get_data);
1471 AVSC_DECLARE_FUNC(avs_prop_get_data_size);
1472 AVSC_DECLARE_FUNC(avs_prop_get_clip);
1473 AVSC_DECLARE_FUNC(avs_prop_get_frame);
1474 AVSC_DECLARE_FUNC(avs_prop_delete_key);
1475 AVSC_DECLARE_FUNC(avs_prop_set_int);
1476 AVSC_DECLARE_FUNC(avs_prop_set_float);
1477 AVSC_DECLARE_FUNC(avs_prop_set_data);
1478 AVSC_DECLARE_FUNC(avs_prop_set_clip);
1479 AVSC_DECLARE_FUNC(avs_prop_set_frame);
1480
1481 AVSC_DECLARE_FUNC(avs_prop_get_int_array);
1482 AVSC_DECLARE_FUNC(avs_prop_get_float_array);
1483 AVSC_DECLARE_FUNC(avs_prop_set_int_array);
1484 AVSC_DECLARE_FUNC(avs_prop_set_float_array);
1485
1486 AVSC_DECLARE_FUNC(avs_clear_map);
1487
1488 // NewVideoFrame with frame properties
1489 AVSC_DECLARE_FUNC(avs_new_video_frame_p);
1490 AVSC_DECLARE_FUNC(avs_new_video_frame_p_a);
1491
1492 AVSC_DECLARE_FUNC(avs_get_env_property);
1493
1494 AVSC_DECLARE_FUNC(avs_get_var_try);
1495 AVSC_DECLARE_FUNC(avs_get_var_bool);
1496 AVSC_DECLARE_FUNC(avs_get_var_int);
1497 AVSC_DECLARE_FUNC(avs_get_var_double);
1498 AVSC_DECLARE_FUNC(avs_get_var_string);
1499 AVSC_DECLARE_FUNC(avs_get_var_long);
1500
1501 AVSC_DECLARE_FUNC(avs_pool_allocate);
1502 AVSC_DECLARE_FUNC(avs_pool_free);
1503
1504 // V9
1505 AVSC_DECLARE_FUNC(avs_is_property_writable);
1506 AVSC_DECLARE_FUNC(avs_make_property_writable);
8841507 };
8851508
8861509 #undef AVSC_DECLARE_FUNC
8871510
1511 #ifdef AVS26_FALLBACK_SIMULATION
1512 // Helper functions for fallback simulation
1513 // Avisynth+ extensions do not exist in classic Avisynth so they are simulated
1514 AVSC_INLINE int avs_is_xx_fallback_return_false(const AVS_VideoInfo * p)
1515 {
1516 return 0;
1517 }
1518
1519 // Avisynth+ extensions do not exist in classic Avisynth so they are simulated
1520 AVSC_INLINE int avs_num_components_fallback(const AVS_VideoInfo * p)
1521 {
1522 switch (p->pixel_type) {
1523 case AVS_CS_UNKNOWN:
1524 return 0;
1525 case AVS_CS_RAW32:
1526 case AVS_CS_Y8:
1527 return 1;
1528 case AVS_CS_BGR32:
1529 return 4; // not planar but return the count
1530 default:
1531 return 3;
1532 }
1533 }
1534
1535 // Avisynth+ extensions do not exist in classic Avisynth so they are simulated
1536 AVSC_INLINE int avs_component_size_fallback(const AVS_VideoInfo * p)
1537 {
1538 return 1;
1539 }
1540
1541 // Avisynth+ extensions do not exist in classic Avisynth so they are simulated
1542 AVSC_INLINE int avs_bits_per_component_fallback(const AVS_VideoInfo * p)
1543 {
1544 return 8;
1545 }
1546 // End of helper functions for fallback simulation
1547 #endif // AVS26_FALLBACK_SIMULATION
1548
1549 // avs_load_library() allocates an array for API procedure entries
1550 // reads and fills the entries with live procedure addresses.
1551 // AVSC_INLINE helpers which are calling into API procedures are not treated here (todo)
8881552
8891553 AVSC_INLINE AVS_Library * avs_load_library() {
8901554 AVS_Library *library = (AVS_Library *)malloc(sizeof(AVS_Library));
8911555 if (library == NULL)
8921556 return NULL;
893 library->handle = LoadLibrary("avisynth");
1557 library->handle = LoadLibraryA("avisynth");
8941558 if (library->handle == NULL)
8951559 goto fail;
8961560
9011565 if (library->name == NULL)\
9021566 goto fail;\
9031567 }
1568
1569 #ifdef AVS26_FALLBACK_SIMULATION
1570 // When an API function is not loadable, let's try a replacement
1571 // Missing Avisynth+ functions will be substituted with classic Avisynth compatible methods
1572 /*
1573 Avisynth+ When method is missing (classic Avisynth)
1574 avs_is_rgb48 constant false
1575 avs_is_rgb64 constant false
1576 avs_is_444 avs_is_yv24
1577 avs_is_422 avs_is_yv16
1578 avs_is_420 avs_is_yv12
1579 avs_is_y avs_is_y8
1580 avs_is_yuva constant false
1581 avs_is_planar_rgb constant false
1582 avs_is_planar_rgba constant false
1583 avs_num_components special: avs_num_components_fake Y8:1 RGB32:4 else 3
1584 avs_component_size constant 1 (1 bytes/component)
1585 avs_bits_per_component constant 8 (8 bits/component)
1586 */
1587
1588 // try to load an alternative function
1589 #define AVSC_LOAD_FUNC_FALLBACK(name,name2) {\
1590 library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name));\
1591 if (library->name == NULL)\
1592 library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name2));\
1593 if (library->name == NULL)\
1594 goto fail;\
1595 }
1596
1597 // try to assign a replacement function
1598 #define AVSC_LOAD_FUNC_FALLBACK_SIMULATED(name,name2) {\
1599 library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name));\
1600 if (library->name == NULL)\
1601 library->name = name2;\
1602 if (library->name == NULL)\
1603 goto fail;\
1604 }
1605 #endif // AVS26_FALLBACK_SIMULATION
9041606
9051607 AVSC_LOAD_FUNC(avs_add_function);
9061608 AVSC_LOAD_FUNC(avs_at_exit);
9241626 AVSC_LOAD_FUNC(avs_make_writable);
9251627 AVSC_LOAD_FUNC(avs_new_c_filter);
9261628 AVSC_LOAD_FUNC(avs_new_video_frame_a);
1629
1630
1631
9271632 AVSC_LOAD_FUNC(avs_release_clip);
9281633 AVSC_LOAD_FUNC(avs_release_value);
9291634 AVSC_LOAD_FUNC(avs_release_video_frame);
9521657 AVSC_LOAD_FUNC(avs_get_plane_height_subsampling);
9531658 AVSC_LOAD_FUNC(avs_bits_per_pixel);
9541659 AVSC_LOAD_FUNC(avs_bytes_from_pixels);
955 AVSC_LOAD_FUNC(avs_row_size_p);
1660 AVSC_LOAD_FUNC(avs_row_size);
9561661 AVSC_LOAD_FUNC(avs_bmp_size);
9571662 AVSC_LOAD_FUNC(avs_get_pitch_p);
9581663 AVSC_LOAD_FUNC(avs_get_row_size_p);
9611666 AVSC_LOAD_FUNC(avs_is_writable);
9621667 AVSC_LOAD_FUNC(avs_get_write_ptr_p);
9631668
1669 // Avisynth+ specific
1670 #ifdef AVS26_FALLBACK_SIMULATION
1671 // replace with fallback fn when does not exist
1672 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_is_rgb48, avs_is_xx_fallback_return_false);
1673 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_is_rgb64, avs_is_xx_fallback_return_false);
1674 AVSC_LOAD_FUNC_FALLBACK(avs_is_444, avs_is_yv24);
1675 AVSC_LOAD_FUNC_FALLBACK(avs_is_422, avs_is_yv16);
1676 AVSC_LOAD_FUNC_FALLBACK(avs_is_420, avs_is_yv12);
1677 AVSC_LOAD_FUNC_FALLBACK(avs_is_y, avs_is_y8);
1678 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_is_yuva, avs_is_xx_fallback_return_false);
1679 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_is_planar_rgb, avs_is_xx_fallback_return_false);
1680 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_is_planar_rgba, avs_is_xx_fallback_return_false);
1681 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_num_components, avs_num_components_fallback);
1682 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_component_size, avs_component_size_fallback);
1683 AVSC_LOAD_FUNC_FALLBACK_SIMULATED(avs_bits_per_component, avs_bits_per_component_fallback);
1684 #else
1685 // Avisynth+ specific
1686 AVSC_LOAD_FUNC(avs_is_rgb48);
1687 AVSC_LOAD_FUNC(avs_is_rgb64);
1688 AVSC_LOAD_FUNC(avs_is_444);
1689 AVSC_LOAD_FUNC(avs_is_422);
1690 AVSC_LOAD_FUNC(avs_is_420);
1691 AVSC_LOAD_FUNC(avs_is_y);
1692 AVSC_LOAD_FUNC(avs_is_yuva);
1693 AVSC_LOAD_FUNC(avs_is_planar_rgb);
1694 AVSC_LOAD_FUNC(avs_is_planar_rgba);
1695 AVSC_LOAD_FUNC(avs_num_components);
1696 AVSC_LOAD_FUNC(avs_component_size);
1697 AVSC_LOAD_FUNC(avs_bits_per_component);
1698 #endif
1699 // Avisynth+ interface V8, no backward compatible simulation
1700 AVSC_LOAD_FUNC(avs_subframe_planar_a);
1701 // frame properties
1702 AVSC_LOAD_FUNC(avs_copy_frame_props);
1703 AVSC_LOAD_FUNC(avs_get_frame_props_ro);
1704 AVSC_LOAD_FUNC(avs_get_frame_props_rw);
1705 AVSC_LOAD_FUNC(avs_prop_num_keys);
1706 AVSC_LOAD_FUNC(avs_prop_get_key);
1707 AVSC_LOAD_FUNC(avs_prop_num_elements);
1708 AVSC_LOAD_FUNC(avs_prop_get_type);
1709 AVSC_LOAD_FUNC(avs_prop_get_int);
1710 AVSC_LOAD_FUNC(avs_prop_get_float);
1711 AVSC_LOAD_FUNC(avs_prop_get_data);
1712 AVSC_LOAD_FUNC(avs_prop_get_data_size);
1713 AVSC_LOAD_FUNC(avs_prop_get_clip);
1714 AVSC_LOAD_FUNC(avs_prop_get_frame);
1715 AVSC_LOAD_FUNC(avs_prop_delete_key);
1716 AVSC_LOAD_FUNC(avs_prop_set_int);
1717 AVSC_LOAD_FUNC(avs_prop_set_float);
1718 AVSC_LOAD_FUNC(avs_prop_set_data);
1719 AVSC_LOAD_FUNC(avs_prop_set_clip);
1720 AVSC_LOAD_FUNC(avs_prop_set_frame);
1721
1722 AVSC_LOAD_FUNC(avs_prop_get_int_array);
1723 AVSC_LOAD_FUNC(avs_prop_get_float_array);
1724 AVSC_LOAD_FUNC(avs_prop_set_int_array);
1725 AVSC_LOAD_FUNC(avs_prop_set_float_array);
1726
1727 AVSC_LOAD_FUNC(avs_clear_map);
1728
1729 // NewVideoFrame with frame properties
1730 AVSC_LOAD_FUNC(avs_new_video_frame_p);
1731 AVSC_LOAD_FUNC(avs_new_video_frame_p_a);
1732
1733 AVSC_LOAD_FUNC(avs_get_env_property);
1734
1735 AVSC_LOAD_FUNC(avs_get_var_try);
1736 AVSC_LOAD_FUNC(avs_get_var_bool);
1737 AVSC_LOAD_FUNC(avs_get_var_int);
1738 AVSC_LOAD_FUNC(avs_get_var_double);
1739 AVSC_LOAD_FUNC(avs_get_var_string);
1740 AVSC_LOAD_FUNC(avs_get_var_long);
1741
1742 AVSC_LOAD_FUNC(avs_pool_allocate);
1743 AVSC_LOAD_FUNC(avs_pool_free);
1744
9641745 #undef __AVSC_STRINGIFY
9651746 #undef AVSC_STRINGIFY
9661747 #undef AVSC_LOAD_FUNC
1748 #undef AVSC_LOAD_FUNC_FALLBACK
1749 #undef AVSC_LOAD_FUNC_FALLBACK_SIMULATED
9671750
9681751 return library;
9691752
9801763 }
9811764 #endif
9821765
983 #endif
1766 #endif // AVS_WINDOWS
1767
1768 #endif
+0
-725
extras/avxsynth_c.h less more
0 // Avisynth C Interface Version 0.20
1 // Copyright 2003 Kevin Atkinson
2
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
16 // http://www.gnu.org/copyleft/gpl.html .
17 //
18 // As a special exception, I give you permission to link to the
19 // Avisynth C interface with independent modules that communicate with
20 // the Avisynth C interface solely through the interfaces defined in
21 // avisynth_c.h, regardless of the license terms of these independent
22 // modules, and to copy and distribute the resulting combined work
23 // under terms of your choice, provided that every copy of the
24 // combined work is accompanied by a complete copy of the source code
25 // of the Avisynth C interface and Avisynth itself (with the version
26 // used to produce the combined work), being distributed under the
27 // terms of the GNU General Public License plus this exception. An
28 // independent module is a module which is not derived from or based
29 // on Avisynth C Interface, such as 3rd-party filters, import and
30 // export plugins, or graphical user interfaces.
31
32 #ifndef __AVXSYNTH_C__
33 #define __AVXSYNTH_C__
34
35 #include <stdarg.h>
36 #include <stdint.h>
37
38 typedef int64_t INT64;
39 #define __stdcall
40 #define __declspec(x)
41
42 #ifdef __cplusplus
43 # define EXTERN_C extern "C"
44 #else
45 # define EXTERN_C
46 #endif
47
48 #define AVSC_USE_STDCALL 1
49
50 #ifndef AVSC_USE_STDCALL
51 # define AVSC_CC __cdecl
52 #else
53 # define AVSC_CC __stdcall
54 #endif
55
56 #define AVSC_INLINE static __inline
57
58 #ifdef AVISYNTH_C_EXPORTS
59 # define AVSC_EXPORT EXTERN_C
60 # define AVSC_API(ret, name) EXTERN_C __declspec(dllexport) ret AVSC_CC name
61 #else
62 # define AVSC_EXPORT EXTERN_C __declspec(dllexport)
63 # ifndef AVSC_NO_DECLSPEC
64 # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name
65 # else
66 # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
67 # endif
68 #endif
69
70
71 /////////////////////////////////////////////////////////////////////
72 //
73 // Constants
74 //
75
76 #ifndef __AVXSYNTH_H__
77 enum { AVISYNTH_INTERFACE_VERSION = 3 };
78 #endif
79
80 enum {AVS_SAMPLE_INT8 = 1<<0,
81 AVS_SAMPLE_INT16 = 1<<1,
82 AVS_SAMPLE_INT24 = 1<<2,
83 AVS_SAMPLE_INT32 = 1<<3,
84 AVS_SAMPLE_FLOAT = 1<<4};
85
86 enum {AVS_PLANAR_Y=1<<0,
87 AVS_PLANAR_U=1<<1,
88 AVS_PLANAR_V=1<<2,
89 AVS_PLANAR_ALIGNED=1<<3,
90 AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
91 AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
92 AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED};
93
94 // Colorspace properties.
95 enum {AVS_CS_BGR = 1<<28,
96 AVS_CS_YUV = 1<<29,
97 AVS_CS_INTERLEAVED = 1<<30,
98 AVS_CS_PLANAR = 1<<31};
99
100 // Specific colorformats
101 enum {
102 AVS_CS_UNKNOWN = 0,
103 AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
104 AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
105 AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
106 AVS_CS_YV12 = 1<<3 | AVS_CS_YUV | AVS_CS_PLANAR, // y-v-u, planar
107 AVS_CS_I420 = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR, // y-u-v, planar
108 AVS_CS_IYUV = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR // same as above
109 };
110
111 enum {
112 AVS_IT_BFF = 1<<0,
113 AVS_IT_TFF = 1<<1,
114 AVS_IT_FIELDBASED = 1<<2};
115
116 enum {
117 AVS_FILTER_TYPE=1,
118 AVS_FILTER_INPUT_COLORSPACE=2,
119 AVS_FILTER_OUTPUT_TYPE=9,
120 AVS_FILTER_NAME=4,
121 AVS_FILTER_AUTHOR=5,
122 AVS_FILTER_VERSION=6,
123 AVS_FILTER_ARGS=7,
124 AVS_FILTER_ARGS_INFO=8,
125 AVS_FILTER_ARGS_DESCRIPTION=10,
126 AVS_FILTER_DESCRIPTION=11};
127
128 enum { //SUBTYPES
129 AVS_FILTER_TYPE_AUDIO=1,
130 AVS_FILTER_TYPE_VIDEO=2,
131 AVS_FILTER_OUTPUT_TYPE_SAME=3,
132 AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
133
134 enum {
135 AVS_CACHE_NOTHING=0,
136 AVS_CACHE_RANGE=1,
137 AVS_CACHE_ALL=2,
138 AVS_CACHE_AUDIO=3,
139 AVS_CACHE_AUDIO_NONE=4,
140 AVS_CACHE_AUDIO_AUTO=5
141 };
142
143 #define AVS_FRAME_ALIGN 16
144
145 typedef struct AVS_Clip AVS_Clip;
146 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
147
148 /////////////////////////////////////////////////////////////////////
149 //
150 // AVS_VideoInfo
151 //
152
153 // AVS_VideoInfo is layed out identicly to VideoInfo
154 typedef struct AVS_VideoInfo {
155 int width, height; // width=0 means no video
156 unsigned fps_numerator, fps_denominator;
157 int num_frames;
158
159 int pixel_type;
160
161 int audio_samples_per_second; // 0 means no audio
162 int sample_type;
163 INT64 num_audio_samples;
164 int nchannels;
165
166 // Imagetype properties
167
168 int image_type;
169 } AVS_VideoInfo;
170
171 // useful functions of the above
172 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
173 { return (p->width!=0); }
174
175 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
176 { return (p->audio_samples_per_second!=0); }
177
178 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
179 { return !!(p->pixel_type&AVS_CS_BGR); }
180
181 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
182 { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
183
184 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
185 { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
186
187 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
188 { return !!(p->pixel_type&AVS_CS_YUV ); }
189
190 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
191 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
192
193 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
194 { return ((p->pixel_type & AVS_CS_YV12) == AVS_CS_YV12)||((p->pixel_type & AVS_CS_I420) == AVS_CS_I420); }
195
196 AVSC_INLINE int avs_is_color_space(const AVS_VideoInfo * p, int c_space)
197 { return ((p->pixel_type & c_space) == c_space); }
198
199 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
200 { return ((p->pixel_type & property)==property ); }
201
202 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
203 { return !!(p->pixel_type & AVS_CS_PLANAR); }
204
205 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
206 { return !!(p->image_type & AVS_IT_FIELDBASED); }
207
208 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
209 { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
210
211 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
212 { return !!(p->image_type & AVS_IT_BFF); }
213
214 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
215 { return !!(p->image_type & AVS_IT_TFF); }
216
217 AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo * p)
218 {
219 switch (p->pixel_type) {
220 case AVS_CS_BGR24: return 24;
221 case AVS_CS_BGR32: return 32;
222 case AVS_CS_YUY2: return 16;
223 case AVS_CS_YV12:
224 case AVS_CS_I420: return 12;
225 default: return 0;
226 }
227 }
228 AVSC_INLINE int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels)
229 { return pixels * (avs_bits_per_pixel(p)>>3); } // Will work on planar images, but will return only luma planes
230
231 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p)
232 { return avs_bytes_from_pixels(p,p->width); } // Also only returns first plane on planar images
233
234 AVSC_INLINE int avs_bmp_size(const AVS_VideoInfo * vi)
235 { if (avs_is_planar(vi)) {int p = vi->height * ((avs_row_size(vi)+3) & ~3); p+=p>>1; return p; } return vi->height * ((avs_row_size(vi)+3) & ~3); }
236
237 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
238 { return p->audio_samples_per_second; }
239
240
241 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
242 {
243 switch (p->sample_type) {
244 case AVS_SAMPLE_INT8: return sizeof(signed char);
245 case AVS_SAMPLE_INT16: return sizeof(signed short);
246 case AVS_SAMPLE_INT24: return 3;
247 case AVS_SAMPLE_INT32: return sizeof(signed int);
248 case AVS_SAMPLE_FLOAT: return sizeof(float);
249 default: return 0;
250 }
251 }
252 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
253 { return p->nchannels*avs_bytes_per_channel_sample(p);}
254
255 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
256 { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
257
258 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
259 { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
260
261 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
262 { return bytes / avs_bytes_per_audio_sample(p); }
263
264 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
265 { return samples * avs_bytes_per_audio_sample(p); }
266
267 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
268 { return p->nchannels; }
269
270 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
271 { return p->sample_type;}
272
273 // useful mutator
274 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
275 { p->image_type|=property; }
276
277 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
278 { p->image_type&=~property; }
279
280 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
281 { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
282
283 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
284 {
285 unsigned x=numerator, y=denominator;
286 while (y) { // find gcd
287 unsigned t = x%y; x = y; y = t;
288 }
289 p->fps_numerator = numerator/x;
290 p->fps_denominator = denominator/x;
291 }
292
293 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
294 {
295 return (x->pixel_type == y->pixel_type)
296 || (avs_is_yv12(x) && avs_is_yv12(y));
297 }
298
299 /////////////////////////////////////////////////////////////////////
300 //
301 // AVS_VideoFrame
302 //
303
304 // VideoFrameBuffer holds information about a memory block which is used
305 // for video data. For efficiency, instances of this class are not deleted
306 // when the refcount reaches zero; instead they're stored in a linked list
307 // to be reused. The instances are deleted when the corresponding AVS
308 // file is closed.
309
310 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
311 // DO NOT USE THIS STRUCTURE DIRECTLY
312 typedef struct AVS_VideoFrameBuffer {
313 unsigned char * data;
314 int data_size;
315 // sequence_number is incremented every time the buffer is changed, so
316 // that stale views can tell they're no longer valid.
317 long sequence_number;
318
319 long refcount;
320 } AVS_VideoFrameBuffer;
321
322 // VideoFrame holds a "window" into a VideoFrameBuffer.
323
324 // AVS_VideoFrame is layed out identicly to IVideoFrame
325 // DO NOT USE THIS STRUCTURE DIRECTLY
326 typedef struct AVS_VideoFrame {
327 int refcount;
328 AVS_VideoFrameBuffer * vfb;
329 int offset, pitch, row_size, height, offsetU, offsetV, pitchUV; // U&V offsets are from top of picture.
330 } AVS_VideoFrame;
331
332 // Access functions for AVS_VideoFrame
333 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
334 return p->pitch;}
335
336 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) {
337 switch (plane) {
338 case AVS_PLANAR_U: case AVS_PLANAR_V: return p->pitchUV;}
339 return p->pitch;}
340
341 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
342 return p->row_size; }
343
344 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane) {
345 int r;
346 switch (plane) {
347 case AVS_PLANAR_U: case AVS_PLANAR_V:
348 if (p->pitchUV) return p->row_size>>1;
349 else return 0;
350 case AVS_PLANAR_U_ALIGNED: case AVS_PLANAR_V_ALIGNED:
351 if (p->pitchUV) {
352 r = ((p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)) )>>1; // Aligned rowsize
353 if (r < p->pitchUV)
354 return r;
355 return p->row_size>>1;
356 } else return 0;
357 case AVS_PLANAR_Y_ALIGNED:
358 r = (p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
359 if (r <= p->pitch)
360 return r;
361 return p->row_size;
362 }
363 return p->row_size;
364 }
365
366 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
367 return p->height;}
368
369 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane) {
370 switch (plane) {
371 case AVS_PLANAR_U: case AVS_PLANAR_V:
372 if (p->pitchUV) return p->height>>1;
373 return 0;
374 }
375 return p->height;}
376
377 AVSC_INLINE const unsigned char* avs_get_read_ptr(const AVS_VideoFrame * p) {
378 return p->vfb->data + p->offset;}
379
380 AVSC_INLINE const unsigned char* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
381 {
382 switch (plane) {
383 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
384 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
385 default: return p->vfb->data + p->offset;}
386 }
387
388 AVSC_INLINE int avs_is_writable(const AVS_VideoFrame * p) {
389 return (p->refcount == 1 && p->vfb->refcount == 1);}
390
391 AVSC_INLINE unsigned char* avs_get_write_ptr(const AVS_VideoFrame * p)
392 {
393 if (avs_is_writable(p)) {
394 ++p->vfb->sequence_number;
395 return p->vfb->data + p->offset;
396 } else
397 return 0;
398 }
399
400 AVSC_INLINE unsigned char* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane)
401 {
402 if (plane==AVS_PLANAR_Y && avs_is_writable(p)) {
403 ++p->vfb->sequence_number;
404 return p->vfb->data + p->offset;
405 } else if (plane==AVS_PLANAR_Y) {
406 return 0;
407 } else {
408 switch (plane) {
409 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
410 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
411 default: return p->vfb->data + p->offset;
412 }
413 }
414 }
415
416 #if defined __cplusplus
417 extern "C"
418 {
419 #endif // __cplusplus
420 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
421 // makes a shallow copy of a video frame
422 AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
423 #if defined __cplusplus
424 }
425 #endif // __cplusplus
426
427 #ifndef AVSC_NO_DECLSPEC
428 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
429 {avs_release_video_frame(f);}
430 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
431 {return avs_copy_video_frame(f);}
432 #endif
433
434 /////////////////////////////////////////////////////////////////////
435 //
436 // AVS_Value
437 //
438
439 // Treat AVS_Value as a fat pointer. That is use avs_copy_value
440 // and avs_release_value appropiaty as you would if AVS_Value was
441 // a pointer.
442
443 // To maintain source code compatibility with future versions of the
444 // avisynth_c API don't use the AVS_Value directly. Use the helper
445 // functions below.
446
447 // AVS_Value is layed out identicly to AVSValue
448 typedef struct AVS_Value AVS_Value;
449 struct AVS_Value {
450 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
451 // for some function e'rror
452 short array_size;
453 union {
454 void * clip; // do not use directly, use avs_take_clip
455 char boolean;
456 int integer;
457 INT64 integer64; // match addition of __int64 to avxplugin.h
458 float floating_pt;
459 const char * string;
460 const AVS_Value * array;
461 } d;
462 };
463
464 // AVS_Value should be initilized with avs_void.
465 // Should also set to avs_void after the value is released
466 // with avs_copy_value. Consider it the equalvent of setting
467 // a pointer to NULL
468 static const AVS_Value avs_void = {'v'};
469
470 AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
471 AVSC_API(void, avs_release_value)(AVS_Value);
472
473 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
474 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
475 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
476 AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
477 AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
478 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
479 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
480 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
481
482 #if defined __cplusplus
483 extern "C"
484 {
485 #endif // __cplusplus
486 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
487 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
488 #if defined __cplusplus
489 }
490 #endif // __cplusplus
491
492 AVSC_INLINE int avs_as_bool(AVS_Value v)
493 { return v.d.boolean; }
494 AVSC_INLINE int avs_as_int(AVS_Value v)
495 { return v.d.integer; }
496 AVSC_INLINE const char * avs_as_string(AVS_Value v)
497 { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
498 AVSC_INLINE double avs_as_float(AVS_Value v)
499 { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
500 AVSC_INLINE const char * avs_as_error(AVS_Value v)
501 { return avs_is_error(v) ? v.d.string : 0; }
502 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
503 { return v.d.array; }
504 AVSC_INLINE int avs_array_size(AVS_Value v)
505 { return avs_is_array(v) ? v.array_size : 1; }
506 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
507 { return avs_is_array(v) ? v.d.array[index] : v; }
508
509 // only use these functions on am AVS_Value that does not already have
510 // an active value. Remember, treat AVS_Value as a fat pointer.
511 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
512 { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
513 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
514 { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
515 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
516 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
517 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
518 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
519 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
520 { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
521 #ifndef AVSC_NO_DECLSPEC
522 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
523 { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
524 #endif
525 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
526 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
527
528 /////////////////////////////////////////////////////////////////////
529 //
530 // AVS_Clip
531 //
532 #if defined __cplusplus
533 extern "C"
534 {
535 #endif // __cplusplus
536 AVSC_API(void, avs_release_clip)(AVS_Clip *);
537 AVSC_API(AVS_Clip *, avs_copy_clip)(AVS_Clip *);
538
539 AVSC_API(const char *, avs_clip_get_error)(AVS_Clip *); // return 0 if no error
540
541 AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
542
543 AVSC_API(int, avs_get_version)(AVS_Clip *);
544
545 AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
546 // The returned video frame must be released with avs_release_video_frame
547
548 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
549 // return field parity if field_based, else parity of first field in frame
550
551 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
552 INT64 start, INT64 count);
553 // start and count are in samples
554
555 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
556 int cachehints, size_t frame_range);
557 #if defined __cplusplus
558 }
559 #endif // __cplusplus
560
561 // This is the callback type used by avs_add_function
562 typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
563 (AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
564
565 typedef struct AVS_FilterInfo AVS_FilterInfo;
566 struct AVS_FilterInfo
567 {
568 // these members should not be modified outside of the AVS_ApplyFunc callback
569 AVS_Clip * child;
570 AVS_VideoInfo vi;
571 AVS_ScriptEnvironment * env;
572 AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
573 int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
574 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
575 INT64 start, INT64 count);
576 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
577 int frame_range);
578 void (AVSC_CC * free_filter)(AVS_FilterInfo *);
579
580 // Should be set when ever there is an error to report.
581 // It is cleared before any of the above methods are called
582 const char * error;
583 // this is to store whatever and may be modified at will
584 void * user_data;
585 };
586
587 // Create a new filter
588 // fi is set to point to the AVS_FilterInfo so that you can
589 // modify it once it is initilized.
590 // store_child should generally be set to true. If it is not
591 // set than ALL methods (the function pointers) must be defined
592 // If it is set than you do not need to worry about freeing the child
593 // clip.
594 #if defined __cplusplus
595 extern "C"
596 {
597 #endif // __cplusplus
598 AVSC_API(AVS_Clip *, avs_new_c_filter)(AVS_ScriptEnvironment * e,
599 AVS_FilterInfo * * fi,
600 AVS_Value child, int store_child);
601 #if defined __cplusplus
602 }
603 #endif // __cplusplus
604
605
606 /////////////////////////////////////////////////////////////////////
607 //
608 // AVS_ScriptEnvironment
609 //
610
611 // For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
612 enum {
613 /* slowest CPU to support extension */
614 AVS_CPU_FORCE = 0x01, // N/A
615 AVS_CPU_FPU = 0x02, // 386/486DX
616 AVS_CPU_MMX = 0x04, // P55C, K6, PII
617 AVS_CPU_INTEGER_SSE = 0x08, // PIII, Athlon
618 AVS_CPU_SSE = 0x10, // PIII, Athlon XP/MP
619 AVS_CPU_SSE2 = 0x20, // PIV, Hammer
620 AVS_CPU_3DNOW = 0x40, // K6-2
621 AVS_CPU_3DNOW_EXT = 0x80, // Athlon
622 AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
623 // which only Hammer will have anyway)
624 };
625
626 #if defined __cplusplus
627 extern "C"
628 {
629 #endif // __cplusplus
630 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
631
632 AVSC_API(long, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
633 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
634
635 AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
636 AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
637
638 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, va_list val);
639 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
640
641 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
642 const char * name, const char * params,
643 AVS_ApplyFunc apply, void * user_data);
644
645 AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
646
647 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
648 AVS_Value args, const char** arg_names);
649 // The returned value must be be released with avs_release_value
650
651 AVSC_API(AVS_Value, avs_get_var)(AVS_ScriptEnvironment *, const char* name);
652 // The returned value must be be released with avs_release_value
653
654 AVSC_API(int, avs_set_var)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
655
656 AVSC_API(int, avs_set_global_var)(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
657
658 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
659 //void avs_pop_context(AVS_ScriptEnvironment *);
660
661 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
662 const AVS_VideoInfo * vi, int align);
663 // align should be at least 16
664 #if defined __cplusplus
665 }
666 #endif // __cplusplus
667
668 #ifndef AVSC_NO_DECLSPEC
669 AVSC_INLINE
670 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
671 const AVS_VideoInfo * vi)
672 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
673
674 AVSC_INLINE
675 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
676 const AVS_VideoInfo * vi)
677 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
678 #endif
679
680 #if defined __cplusplus
681 extern "C"
682 {
683 #endif // __cplusplus
684 AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
685
686 AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, unsigned char* dstp, int dst_pitch, const unsigned char* srcp, int src_pitch, int row_size, int height);
687
688 typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
689 AVSC_API(void, avs_at_exit)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
690
691 AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
692 // The returned video frame must be be released
693
694 AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
695
696 AVSC_API(int, avs_set_working_dir)(AVS_ScriptEnvironment *, const char * newdir);
697
698 // avisynth.dll exports this; it's a way to use it as a library, without
699 // writing an AVS script or without going through AVIFile.
700 AVSC_API(AVS_ScriptEnvironment *, avs_create_script_environment)(int version);
701 #if defined __cplusplus
702 }
703 #endif // __cplusplus
704
705 // this symbol is the entry point for the plugin and must
706 // be defined
707 AVSC_EXPORT
708 const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
709
710
711 #if defined __cplusplus
712 extern "C"
713 {
714 #endif // __cplusplus
715 AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
716
717
718 AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV);
719 // The returned video frame must be be released
720 #if defined __cplusplus
721 }
722 #endif // __cplusplus
723
724 #endif //__AVXSYNTH_C__
00 /*****************************************************************************
11 * intel_dispatcher.h: intel compiler cpu dispatcher override
22 *****************************************************************************
3 * Copyright (C) 2014-2021 x264 project
3 * Copyright (C) 2014-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * filters.c: common filter functions
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Diogo Franco <diogomfranco@gmail.com>
66 * Steven Walters <kemuri9@gmail.com>
00 /*****************************************************************************
11 * filters.h: common filter functions
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Diogo Franco <diogomfranco@gmail.com>
66 * Steven Walters <kemuri9@gmail.com>
00 /*****************************************************************************
11 * cache.c: cache video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * crop.c: crop video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 * James Darnley <james.darnley@gmail.com>
00 /*****************************************************************************
11 * depth.c: bit-depth conversion video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Oskar Arvidsson <oskar@irock.se>
66 *
00 /*****************************************************************************
11 * fix_vfr_pts.c: vfr pts fixing video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * internal.c: video filter utilities
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * internal.h: video filter utilities
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * resize.c: resize video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
127127 flag = SWS_AREA;
128128 else if( !strcasecmp( name, "bicublin" ) )
129129 flag = SWS_BICUBLIN;
130 else if( !strcasecmp( name, "guass" ) )
130 else if( !strcasecmp( name, "gauss" ) )
131131 flag = SWS_GAUSS;
132132 else if( !strcasecmp( name, "sinc" ) )
133133 flag = SWS_SINC;
00 /*****************************************************************************
11 * select_every.c: select-every video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * source.c: source video filter
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * video.c: video filters
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * video.h: video filters
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 *
00 /*****************************************************************************
11 * avs.c: avisynth input
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 * Anton Mitrofanov <BugMaster@narod.ru>
2525
2626 #include "input.h"
2727
28 #if USE_AVXSYNTH
29 #include <dlfcn.h>
30 #if SYS_MACOSX
31 #define avs_open() dlopen( "libavxsynth.dylib", RTLD_NOW )
32 #else
33 #define avs_open() dlopen( "libavxsynth.so", RTLD_NOW )
34 #endif
35 #define avs_close dlclose
36 #define avs_address dlsym
37 #else
28 #if SYS_WINDOWS || SYS_CYGWIN
29 #include <windows.h>
3830 #define avs_open() LoadLibraryW( L"avisynth" )
3931 #define avs_close FreeLibrary
4032 #define avs_address GetProcAddress
33 #else
34 #include <dlfcn.h>
35 #if SYS_MACOSX
36 #define avs_open() dlopen( "libavisynth.dylib", RTLD_NOW )
37 #else
38 #define avs_open() dlopen( "libavisynth.so", RTLD_NOW )
39 #endif
40 #define avs_close dlclose
41 #define avs_address dlsym
4142 #endif
4243
4344 #define AVSC_NO_DECLSPEC
4445 #undef EXTERN_C
45 #if USE_AVXSYNTH
46 #include "extras/avxsynth_c.h"
47 #else
4846 #include "extras/avisynth_c.h"
49 #endif
5047 #define AVSC_DECLARE_FUNC(name) name##_func name
5148
5249 #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "avs", __VA_ARGS__ )
9794 AVSC_DECLARE_FUNC( avs_release_value );
9895 AVSC_DECLARE_FUNC( avs_release_video_frame );
9996 AVSC_DECLARE_FUNC( avs_take_clip );
100 #if !USE_AVXSYNTH
97 AVSC_DECLARE_FUNC( avs_is_yv24 );
98 AVSC_DECLARE_FUNC( avs_is_yv16 );
99 AVSC_DECLARE_FUNC( avs_is_yv12 );
100 AVSC_DECLARE_FUNC( avs_is_yv411 );
101 AVSC_DECLARE_FUNC( avs_is_y8 );
102 AVSC_DECLARE_FUNC( avs_get_pitch_p );
103 AVSC_DECLARE_FUNC( avs_get_read_ptr_p );
101104 // AviSynth+ extension
102105 AVSC_DECLARE_FUNC( avs_is_rgb48 );
103106 AVSC_DECLARE_FUNC( avs_is_rgb64 );
105108 AVSC_DECLARE_FUNC( avs_is_yuv422p16 );
106109 AVSC_DECLARE_FUNC( avs_is_yuv420p16 );
107110 AVSC_DECLARE_FUNC( avs_is_y16 );
108 AVSC_DECLARE_FUNC( avs_is_yuv444ps );
109 AVSC_DECLARE_FUNC( avs_is_yuv422ps );
110 AVSC_DECLARE_FUNC( avs_is_yuv420ps );
111 AVSC_DECLARE_FUNC( avs_is_y32 );
112111 AVSC_DECLARE_FUNC( avs_is_444 );
113112 AVSC_DECLARE_FUNC( avs_is_422 );
114113 AVSC_DECLARE_FUNC( avs_is_420 );
115114 AVSC_DECLARE_FUNC( avs_is_y );
116 AVSC_DECLARE_FUNC( avs_is_yuva );
117 AVSC_DECLARE_FUNC( avs_is_planar_rgb );
118 AVSC_DECLARE_FUNC( avs_is_planar_rgba );
119 AVSC_DECLARE_FUNC( avs_num_components );
120 AVSC_DECLARE_FUNC( avs_component_size );
121 AVSC_DECLARE_FUNC( avs_bits_per_component );
122 #endif
123115 } func;
124116 } avs_hnd_t;
125117
141133 LOAD_AVS_FUNC( avs_release_value, 0 );
142134 LOAD_AVS_FUNC( avs_release_video_frame, 0 );
143135 LOAD_AVS_FUNC( avs_take_clip, 0 );
144 #if !USE_AVXSYNTH
136 LOAD_AVS_FUNC( avs_is_yv24, 1 );
137 LOAD_AVS_FUNC( avs_is_yv16, 1 );
138 LOAD_AVS_FUNC( avs_is_yv12, 1 );
139 LOAD_AVS_FUNC( avs_is_yv411, 1 );
140 LOAD_AVS_FUNC( avs_is_y8, 1 );
141 LOAD_AVS_FUNC( avs_get_pitch_p, 1 );
142 LOAD_AVS_FUNC( avs_get_read_ptr_p, 1 );
145143 // AviSynth+ extension
146144 LOAD_AVS_FUNC( avs_is_rgb48, 1 );
147145 LOAD_AVS_FUNC_ALIAS( avs_is_rgb48, "_avs_is_rgb48@4", 1 );
151149 LOAD_AVS_FUNC( avs_is_yuv422p16, 1 );
152150 LOAD_AVS_FUNC( avs_is_yuv420p16, 1 );
153151 LOAD_AVS_FUNC( avs_is_y16, 1 );
154 LOAD_AVS_FUNC( avs_is_yuv444ps, 1 );
155 LOAD_AVS_FUNC( avs_is_yuv422ps, 1 );
156 LOAD_AVS_FUNC( avs_is_yuv420ps, 1 );
157 LOAD_AVS_FUNC( avs_is_y32, 1 );
158152 LOAD_AVS_FUNC( avs_is_444, 1 );
159153 LOAD_AVS_FUNC( avs_is_422, 1 );
160154 LOAD_AVS_FUNC( avs_is_420, 1 );
161155 LOAD_AVS_FUNC( avs_is_y, 1 );
162 LOAD_AVS_FUNC( avs_is_yuva, 1 );
163 LOAD_AVS_FUNC( avs_is_planar_rgb, 1 );
164 LOAD_AVS_FUNC( avs_is_planar_rgba, 1 );
165 LOAD_AVS_FUNC( avs_num_components, 1 );
166 LOAD_AVS_FUNC( avs_component_size, 1 );
167 LOAD_AVS_FUNC( avs_bits_per_component, 1 );
168 #endif
169156 return 0;
170157 fail:
171158 avs_close( h->library );
173160 return -1;
174161 }
175162
176 /* AvxSynth doesn't have yv24, yv16, yv411, or y8, so disable them. */
177 #if USE_AVXSYNTH
178 #define avs_is_yv24( vi ) (0)
179 #define avs_is_yv16( vi ) (0)
180 #define avs_is_yv411( vi ) (0)
181 #define avs_is_y8( vi ) (0)
182 /* AvxSynth doesn't support AviSynth+ pixel types. */
183 #define AVS_IS_AVISYNTHPLUS (0)
184 #define AVS_IS_420( vi ) (0)
185 #define AVS_IS_422( vi ) (0)
186 #define AVS_IS_444( vi ) (0)
187 #define AVS_IS_RGB48( vi ) (0)
188 #define AVS_IS_RGB64( vi ) (0)
189 #define AVS_IS_YUV420P16( vi ) (0)
190 #define AVS_IS_YUV422P16( vi ) (0)
191 #define AVS_IS_YUV444P16( vi ) (0)
192 #define AVS_IS_Y( vi ) (0)
193 #define AVS_IS_Y16( vi ) (0)
194 #else
163 #define AVS_IS_YV24( vi ) (h->func.avs_is_yv24 ? h->func.avs_is_yv24( vi ) : avs_is_yv24( vi ))
164 #define AVS_IS_YV16( vi ) (h->func.avs_is_yv16 ? h->func.avs_is_yv16( vi ) : avs_is_yv16( vi ))
165 #define AVS_IS_YV12( vi ) (h->func.avs_is_yv12 ? h->func.avs_is_yv12( vi ) : avs_is_yv12( vi ))
166 #define AVS_IS_YV411( vi ) (h->func.avs_is_yv411 ? h->func.avs_is_yv411( vi ) : avs_is_yv411( vi ))
167 #define AVS_IS_Y8( vi ) (h->func.avs_is_y8 ? h->func.avs_is_y8( vi ) : avs_is_y8( vi ))
168 #define AVS_GET_PITCH_P( p, plane ) (h->func.avs_get_pitch_p ? h->func.avs_get_pitch_p( p, plane ) : avs_get_pitch_p( p, plane ))
169 #define AVS_GET_READ_PTR_P( p, plane ) (h->func.avs_get_read_ptr_p ? h->func.avs_get_read_ptr_p( p, plane ) : avs_get_read_ptr_p( p, plane ))
170
195171 #define AVS_IS_AVISYNTHPLUS (h->func.avs_is_420 && h->func.avs_is_422 && h->func.avs_is_444)
196 #define AVS_IS_420( vi ) (h->func.avs_is_420 ? h->func.avs_is_420( vi ) : avs_is_yv12( vi ))
197 #define AVS_IS_422( vi ) (h->func.avs_is_422 ? h->func.avs_is_422( vi ) : avs_is_yv16( vi ))
198 #define AVS_IS_444( vi ) (h->func.avs_is_444 ? h->func.avs_is_444( vi ) : avs_is_yv24( vi ))
172 #define AVS_IS_420( vi ) (h->func.avs_is_420 ? h->func.avs_is_420( vi ) : AVS_IS_YV12( vi ))
173 #define AVS_IS_422( vi ) (h->func.avs_is_422 ? h->func.avs_is_422( vi ) : AVS_IS_YV16( vi ))
174 #define AVS_IS_444( vi ) (h->func.avs_is_444 ? h->func.avs_is_444( vi ) : AVS_IS_YV24( vi ))
199175 #define AVS_IS_RGB48( vi ) (h->func.avs_is_rgb48 && h->func.avs_is_rgb48( vi ))
200176 #define AVS_IS_RGB64( vi ) (h->func.avs_is_rgb64 && h->func.avs_is_rgb64( vi ))
201177 #define AVS_IS_YUV420P16( vi ) (h->func.avs_is_yuv420p16 && h->func.avs_is_yuv420p16( vi ))
202178 #define AVS_IS_YUV422P16( vi ) (h->func.avs_is_yuv422p16 && h->func.avs_is_yuv422p16( vi ))
203179 #define AVS_IS_YUV444P16( vi ) (h->func.avs_is_yuv444p16 && h->func.avs_is_yuv444p16( vi ))
204 #define AVS_IS_Y( vi ) (h->func.avs_is_y ? h->func.avs_is_y( vi ) : avs_is_y8( vi ))
180 #define AVS_IS_Y( vi ) (h->func.avs_is_y ? h->func.avs_is_y( vi ) : AVS_IS_Y8( vi ))
205181 #define AVS_IS_Y16( vi ) (h->func.avs_is_y16 && h->func.avs_is_y16( vi ))
206 #endif
207182
208183 /* generate a filter sequence to try based on the filename extension */
209184 static void avs_build_filter_sequence( char *filename_ext, const char *filter[AVS_MAX_SEQUENCE+1] )
210185 {
211186 int i = 0;
212 #if USE_AVXSYNTH
213 const char *all_purpose[] = { "FFVideoSource", 0 };
214 #else
187 #if SYS_WINDOWS || SYS_CYGWIN
215188 const char *all_purpose[] = { "FFmpegSource2", "DSS2", "DirectShowSource", 0 };
216189 if( !strcasecmp( filename_ext, "avi" ) )
217190 filter[i++] = "AVISource";
219192 filter[i++] = "MPEG2Source";
220193 if( !strcasecmp( filename_ext, "dga" ) )
221194 filter[i++] = "AVCSource";
195 #else
196 const char *all_purpose[] = { "FFVideoSource", 0 };
222197 #endif
223198 for( int j = 0; all_purpose[j] && i < AVS_MAX_SEQUENCE; j++ )
224199 filter[i++] = all_purpose[j];
235210
236211 static float get_avs_version( avs_hnd_t *h )
237212 {
238 /* AvxSynth has its version defined starting at 4.0, even though it's based on
239 AviSynth 2.5.8. This is troublesome for get_avs_version and working around
240 the new colorspaces in 2.6. So if AvxSynth is detected, explicitly define
241 the version as 2.58. */
242 #if USE_AVXSYNTH
243 return 2.58f;
244 #else
245213 FAIL_IF_ERROR( !h->func.avs_function_exists( h->env, "VersionNumber" ), "VersionNumber does not exist\n" );
246214 AVS_Value ver = h->func.avs_invoke( h->env, "VersionNumber", avs_new_value_array( NULL, 0 ), NULL );
247215 FAIL_IF_ERROR( avs_is_error( ver ), "unable to determine avisynth version: %s\n", avs_as_error( ver ) );
249217 float ret = avs_as_float( ver );
250218 h->func.avs_release_value( ver );
251219 return ret;
252 #endif
253220 }
254221
255222 #ifdef _WIN32
501468 info->csp = X264_CSP_BGR | X264_CSP_VFLIP;
502469 else if( AVS_IS_YUV444P16( vi ) )
503470 info->csp = X264_CSP_I444 | X264_CSP_HIGH_DEPTH;
504 else if( avs_is_yv24( vi ) )
471 else if( AVS_IS_YV24( vi ) )
505472 info->csp = X264_CSP_I444;
506473 else if( AVS_IS_YUV422P16( vi ) )
507474 info->csp = X264_CSP_I422 | X264_CSP_HIGH_DEPTH;
508 else if( avs_is_yv16( vi ) )
475 else if( AVS_IS_YV16( vi ) )
509476 info->csp = X264_CSP_I422;
510477 else if( AVS_IS_YUV420P16( vi ) )
511478 info->csp = X264_CSP_I420 | X264_CSP_HIGH_DEPTH;
512 else if( avs_is_yv12( vi ) )
479 else if( AVS_IS_YV12( vi ) )
513480 info->csp = X264_CSP_I420;
514481 else if( AVS_IS_Y16( vi ) )
515482 info->csp = X264_CSP_I400 | X264_CSP_HIGH_DEPTH;
516 else if( avs_is_y8( vi ) )
483 else if( AVS_IS_Y8( vi ) )
517484 info->csp = X264_CSP_I400;
518485 else if( avs_is_yuy2( vi ) )
519486 info->csp = X264_CSP_YUYV;
520487 #if HAVE_SWSCALE
521 else if( avs_is_yv411( vi ) )
488 else if( AVS_IS_YV411( vi ) )
522489 info->csp = AV_PIX_FMT_YUV411P | X264_CSP_OTHER;
523490 #endif
524491 else
562529 for( int i = 0; i < pic->img.planes; i++ )
563530 {
564531 /* explicitly cast away the const attribute to avoid a warning */
565 pic->img.plane[i] = (uint8_t*)avs_get_read_ptr_p( frm, plane[i] );
566 pic->img.stride[i] = avs_get_pitch_p( frm, plane[i] );
532 pic->img.plane[i] = (uint8_t*)AVS_GET_READ_PTR_P( frm, plane[i] );
533 pic->img.stride[i] = AVS_GET_PITCH_P( frm, plane[i] );
567534 }
568535 return 0;
569536 }
00 /*****************************************************************************
11 * ffms.c: ffmpegsource input
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Mike Gurlitz <mike.gurlitz@gmail.com>
66 * Steven Walters <kemuri9@gmail.com>
00 /*****************************************************************************
11 * input.c: common input functions
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
66 * Henrik Gramner <henrik@gramner.com>
00 /*****************************************************************************
11 * input.h: file input
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * lavf.c: libavformat input
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Mike Gurlitz <mike.gurlitz@gmail.com>
66 * Steven Walters <kemuri9@gmail.com>
4040 AVFormatContext *lavf;
4141 AVCodecContext *lavc;
4242 AVFrame *frame;
43 AVPacket *pkt;
4344 int stream_id;
4445 int next_frame;
4546 int vfr_input;
9596 return 0;
9697 }
9798
98 AVPacket pkt;
99 av_init_packet( &pkt );
100 pkt.data = NULL;
101 pkt.size = 0;
99 AVPacket *pkt = h->pkt;
102100
103101 while( i_frame >= h->next_frame )
104102 {
108106 {
109107 if( ret == AVERROR(EAGAIN) )
110108 {
111 while( !(ret = av_read_frame( h->lavf, &pkt )) && pkt.stream_index != h->stream_id )
112 av_packet_unref( &pkt );
109 while( !(ret = av_read_frame( h->lavf, pkt )) && pkt->stream_index != h->stream_id )
110 av_packet_unref( pkt );
113111
114112 if( ret )
115113 ret = avcodec_send_packet( h->lavc, NULL );
116114 else
117115 {
118 ret = avcodec_send_packet( h->lavc, &pkt );
119 av_packet_unref( &pkt );
116 ret = avcodec_send_packet( h->lavc, pkt );
117 av_packet_unref( pkt );
120118 }
121119 }
122120 else if( ret == AVERROR_EOF )
174172 h->frame = av_frame_alloc();
175173 if( !h->frame )
176174 return -1;
175 h->pkt = av_packet_alloc();
176 if( !h->pkt )
177 return -1;
177178
178179 /* if resolution was passed in, place it and colorspace into options. this allows raw video support */
179180 AVDictionary *options = NULL;
263264 lavf_hnd_t *h = handle;
264265 avcodec_free_context( &h->lavc );
265266 avformat_close_input( &h->lavf );
267 av_packet_free( &h->pkt );
266268 av_frame_free( &h->frame );
267269 free( h );
268270 return 0;
00 /*****************************************************************************
11 * raw.c: raw input
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * thread.c: threaded input
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
6262 h->next_args->status = 0;
6363 h->frame_total = info->num_frames;
6464
65 if( x264_threadpool_init( &h->pool, 1, NULL, NULL ) )
65 if( x264_threadpool_init( &h->pool, 1 ) )
6666 return -1;
6767
6868 *p_handle = h;
00 /*****************************************************************************
11 * timecode.c: timecode file input
22 *****************************************************************************
3 * Copyright (C) 2010-2021 x264 project
3 * Copyright (C) 2010-2022 x264 project
44 *
55 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
66 *
9999 double *timecodes = NULL;
100100 double *fpss = NULL;
101101
102 ret = fscanf( tcfile_in, "# timecode format v%d", &tcfv );
103 FAIL_IF_ERROR( ret != 1 || (tcfv != 1 && tcfv != 2), "unsupported timecode format\n" );
102 ret = fgets( buff, sizeof(buff), tcfile_in ) != NULL &&
103 (sscanf( buff, "# timecode format v%d", &tcfv ) == 1 || sscanf( buff, "# timestamp format v%d", &tcfv ) == 1);
104 FAIL_IF_ERROR( !ret || (tcfv != 1 && tcfv != 2), "unsupported timecode format\n" );
104105 #define NO_TIMECODE_LINE (buff[0] == '#' || buff[0] == '\n' || buff[0] == '\r')
105106 if( tcfv == 1 )
106107 {
00 /*****************************************************************************
11 * y4m.c: y4m input
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * flv.c: flv muxer
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Kieran Kunhya <kieran@kunhya.com>
66 *
00 /*****************************************************************************
11 * flv_bytestream.c: flv muxer utilities
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Kieran Kunhya <kieran@kunhya.com>
66 *
00 /*****************************************************************************
11 * flv_bytestream.h: flv muxer utilities
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Kieran Kunhya <kieran@kunhya.com>
66 *
00 /*****************************************************************************
11 * matroska.c: matroska muxer
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Mike Matsnev <mike@haali.su>
66 *
00 /*****************************************************************************
11 * matroska_ebml.c: matroska muxer utilities
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Mike Matsnev <mike@haali.su>
66 *
5959 int64_t cluster_tc_scaled;
6060 int64_t frame_tc, max_frame_tc;
6161
62 char wrote_header, in_frame, keyframe, skippable;
62 int8_t wrote_header, in_frame, keyframe, skippable;
6363 };
6464
6565 static mk_context *mk_create_context( mk_writer *w, mk_context *parent, unsigned id )
110110 c->d_max = dn;
111111 }
112112
113 memcpy( (char*)c->data + c->d_cur, data, size );
113 memcpy( (uint8_t*)c->data + c->d_cur, data, size );
114114
115115 c->d_cur = ns;
116116
119119
120120 static int mk_write_id( mk_context *c, unsigned id )
121121 {
122 unsigned char c_id[4] = { id >> 24, id >> 16, id >> 8, id };
122 uint8_t c_id[4] = { id >> 24, id >> 16, id >> 8, id };
123123
124124 if( c_id[0] )
125125 return mk_append_context_data( c, c_id, 4 );
132132
133133 static int mk_write_size( mk_context *c, unsigned size )
134134 {
135 unsigned char c_size[5] = { 0x08, size >> 24, size >> 16, size >> 8, size };
135 uint8_t c_size[5] = { 0x08, size >> 24, size >> 16, size >> 8, size };
136136
137137 if( size < 0x7f )
138138 {
159159
160160 static int mk_flush_context_id( mk_context *c )
161161 {
162 unsigned char ff = 0xff;
162 uint8_t ff = 0xff;
163163
164164 if( !c->id )
165165 return 0;
248248 return 0;
249249 }
250250
251 static int mk_write_uint( mk_context *c, unsigned id, int64_t ui )
252 {
253 unsigned char c_ui[8] = { ui >> 56, ui >> 48, ui >> 40, ui >> 32, ui >> 24, ui >> 16, ui >> 8, ui };
251 static int mk_write_uint( mk_context *c, unsigned id, uint64_t ui )
252 {
253 uint8_t c_ui[8] = { ui >> 56, ui >> 48, ui >> 40, ui >> 32, ui >> 24, ui >> 16, ui >> 8, ui };
254254 unsigned i = 0;
255255
256256 CHECK( mk_write_id( c, id ) );
266266 union
267267 {
268268 float f;
269 unsigned u;
269 uint32_t u;
270270 } u;
271 unsigned char c_f[4];
271 uint8_t c_f[4];
272272
273273 u.f = f;
274274 c_f[0] = u.u >> 24;
407407 {
408408 int64_t delta;
409409 unsigned fsize;
410 unsigned char c_delta_flags[3];
410 uint8_t c_delta_flags[3];
411411
412412 if( !w->in_frame )
413413 return 0;
434434 CHECK( mk_write_size( w->cluster, fsize + 4 ) ); // Size
435435 CHECK( mk_write_size( w->cluster, 1 ) ); // TrackNumber
436436
437 c_delta_flags[0] = delta >> 8;
438 c_delta_flags[1] = delta;
437 c_delta_flags[0] = (uint8_t)(delta >> 8);
438 c_delta_flags[1] = (uint8_t)delta;
439439 c_delta_flags[2] = (w->keyframe << 7) | w->skippable;
440440 CHECK( mk_append_context_data( w->cluster, c_delta_flags, 3 ) ); // Timecode, Flags
441441 if( w->frame )
00 /*****************************************************************************
11 * matroska_ebml.h: matroska muxer utilities
22 *****************************************************************************
3 * Copyright (C) 2005-2021 x264 project
3 * Copyright (C) 2005-2022 x264 project
44 *
55 * Authors: Mike Matsnev <mike@haali.su>
66 *
00 /*****************************************************************************
11 * mp4.c: mp4 muxer
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * mp4_lsmash.c: mp4 muxer using L-SMASH
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * output.h: x264 file output modules
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * raw.c: raw muxer
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 ;*****************************************************************************
11 ;* checkasm-a.asm: assembly check tool
22 ;*****************************************************************************
3 ;* Copyright (C) 2008-2021 x264 project
3 ;* Copyright (C) 2008-2022 x264 project
44 ;*
55 ;* Authors: Loren Merritt <lorenm@u.washington.edu>
66 ;* Henrik Gramner <henrik@gramner.com>
00 /****************************************************************************
11 * checkasm-aarch64.S: assembly check tool
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Martin Storsjo <martin@martin.st>
66 *
00 /****************************************************************************
11 * checkasm-arm.S: assembly check tool
22 *****************************************************************************
3 * Copyright (C) 2015-2021 x264 project
3 * Copyright (C) 2015-2022 x264 project
44 *
55 * Authors: Martin Storsjo <martin@martin.st>
66 *
00 /*****************************************************************************
11 * checkasm.c: assembly check tool
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
4747 /* pbuf3, pbuf4: point to buf3, buf4, just for type convenience */
4848 static pixel *pbuf3, *pbuf4;
4949
50 #if BIT_DEPTH > 8
51 #define FMT_PIXEL "%04x"
52 #else
53 #define FMT_PIXEL "%02x"
54 #endif
55
56 #define X264_ISDIGIT(x) isdigit((unsigned char)(x))
57
5058 static int quiet = 0;
5159
5260 #define report( name ) { \
141149 {
142150 if( !*sa && !*sb )
143151 return 0;
144 if( isdigit( *sa ) && isdigit( *sb ) && isdigit( sa[1] ) != isdigit( sb[1] ) )
145 return isdigit( sa[1] ) - isdigit( sb[1] );
152 if( X264_ISDIGIT( *sa ) && X264_ISDIGIT( *sb ) && X264_ISDIGIT( sa[1] ) != X264_ISDIGIT( sb[1] ) )
153 return X264_ISDIGIT( sa[1] ) - X264_ISDIGIT( sb[1] );
146154 if( *sa != *sb )
147155 return *sa - *sb;
148156 }
261269 * assembly function through x264_checkasm_call with added dummy arguments which forces all
262270 * real arguments to be passed on the stack and not in registers. For 32-bit argument the
263271 * upper half of the 64-bit register location on the stack will now contain junk. Note that
264 * this is dependant on compiler behaviour and that interrupts etc. at the wrong time may
272 * this is dependent on compiler behaviour and that interrupts etc. at the wrong time may
265273 * overwrite the junk written to the stack so there's no guarantee that it will always
266274 * detect all functions that assumes zero-extension.
267275 */
650658 ok = 0; \
651659 fprintf( stderr, #name" [FAILED]\n" ); \
652660 for( int j=0; j<16; j++ ) \
653 fprintf( stderr, "%02x ", fdec1[(j&3)+(j>>2)*FDEC_STRIDE] ); \
661 fprintf( stderr, FMT_PIXEL" ", fdec1[(j&3)+(j>>2)*FDEC_STRIDE] ); \
654662 fprintf( stderr, "\n" ); \
655663 for( int j=0; j<16; j++ ) \
656 fprintf( stderr, "%02x ", fdec2[(j&3)+(j>>2)*FDEC_STRIDE] ); \
664 fprintf( stderr, FMT_PIXEL" ", fdec2[(j&3)+(j>>2)*FDEC_STRIDE] ); \
657665 fprintf( stderr, "\n" ); \
658666 break; \
659667 } \
710718 for( int j=0; j<8; j++ ) \
711719 { \
712720 for( int k=0; k<8; k++ ) \
713 fprintf( stderr, "%02x ", fdec1[k+j*FDEC_STRIDE] ); \
721 fprintf( stderr, FMT_PIXEL" ", fdec1[k+j*FDEC_STRIDE] ); \
714722 fprintf( stderr, "\n" ); \
715723 } \
716724 fprintf( stderr, "\n" ); \
717725 for( int j=0; j<8; j++ ) \
718726 { \
719727 for( int k=0; k<8; k++ ) \
720 fprintf( stderr, "%02x ", fdec2[k+j*FDEC_STRIDE] ); \
728 fprintf( stderr, FMT_PIXEL" ", fdec2[k+j*FDEC_STRIDE] ); \
721729 fprintf( stderr, "\n" ); \
722730 } \
723731 fprintf( stderr, "\n" ); \
839847 if( mvn_c != mvn_a || memcmp( mvs_c, mvs_a, mvn_c*sizeof(*mvs_c) ) )
840848 {
841849 ok = 0;
842 printf( "thresh: %d\n", thresh );
843 printf( "c%d: ", i&3 );
850 fprintf( stderr, "thresh: %d\n", thresh );
851 fprintf( stderr, "c%d: ", i&3 );
844852 for( int j = 0; j < mvn_c; j++ )
845 printf( "%d ", mvs_c[j] );
846 printf( "\na%d: ", i&3 );
853 fprintf( stderr, "%d ", mvs_c[j] );
854 fprintf( stderr, "\na%d: ", i&3 );
847855 for( int j = 0; j < mvn_a; j++ )
848 printf( "%d ", mvs_a[j] );
849 printf( "\n\n" );
856 fprintf( stderr, "%d ", mvs_a[j] );
857 fprintf( stderr, "\n\n" );
850858 }
851859 }
852860 report( "esa ads:" );
880888 h->param.analyse.i_luma_deadzone[0] = 0;
881889 h->param.analyse.i_luma_deadzone[1] = 0;
882890 h->param.analyse.b_transform_8x8 = 1;
883 for( int i = 0; i < 6; i++ )
891 for( int i = 0; i < 8; i++ )
884892 h->sps->scaling_list[i] = x264_cqm_flat16;
885893 x264_cqm_init( h );
886894 x264_quant_init( h, 0, &qf );
922930 ok = 0; \
923931 fprintf( stderr, #name " [FAILED]\n" ); \
924932 for( int k = 0; k < size; k++ )\
925 printf( "%d ", ((dctcoef*)t1)[k] );\
926 printf("\n");\
933 fprintf( stderr, "%d ", ((dctcoef*)t1)[k] );\
934 fprintf( stderr, "\n" );\
927935 for( int k = 0; k < size; k++ )\
928 printf( "%d ", ((dctcoef*)t2)[k] );\
929 printf("\n");\
936 fprintf( stderr, "%d ", ((dctcoef*)t2)[k] );\
937 fprintf( stderr, "\n" );\
930938 break; \
931939 } \
932940 call_c( dct_c.name, t1, enc, dec ); \
11591167 call_a( zigzag_asm[interlace].name, t2, dct, buf4 ); \
11601168 if( memcmp( t1, t2, size*sizeof(dctcoef) ) || memcmp( buf3, buf4, 10 ) ) \
11611169 { \
1162 ok = 0; printf("%d: %d %d %d %d\n%d %d %d %d\n\n",memcmp( t1, t2, size*sizeof(dctcoef) ),buf3[0], buf3[1], buf3[8], buf3[9], buf4[0], buf4[1], buf4[8], buf4[9]);break;\
1170 ok = 0; \
1171 fprintf( stderr, "%d: %d %d %d %d\n%d %d %d %d\n\n", memcmp( t1, t2, size*sizeof(dctcoef) ), buf3[0], buf3[1], buf3[8], buf3[9], buf4[0], buf4[1], buf4[8], buf4[9] ); \
1172 break; \
11631173 } \
11641174 } \
11651175 }
16671677 ok = 0;
16681678 fprintf( stderr, "hpel filter differs at plane %c line %d\n", "hvc"[i], j );
16691679 for( int k = 0; k < 48; k++ )
1670 printf( "%02x%s", dstc[i][j*64+k], (k+1)&3 ? "" : " " );
1671 printf( "\n" );
1680 fprintf( stderr, FMT_PIXEL"%s", dstc[i][j*64+k], (k+1)&3 ? "" : " " );
1681 fprintf( stderr, "\n" );
16721682 for( int k = 0; k < 48; k++ )
1673 printf( "%02x%s", dsta[i][j*64+k], (k+1)&3 ? "" : " " );
1674 printf( "\n" );
1683 fprintf( stderr, FMT_PIXEL"%s", dsta[i][j*64+k], (k+1)&3 ? "" : " " );
1684 fprintf( stderr, "\n" );
16751685 break;
16761686 }
16771687 report( "hpel filter :" );
16971707 ok = 0;
16981708 fprintf( stderr, "frame_init_lowres differs at plane %d line %d\n", j, i );
16991709 for( int k = 0; k < w; k++ )
1700 printf( "%d ", dstc[j][k+i*stride_lowres] );
1701 printf( "\n" );
1710 fprintf( stderr, "%d ", dstc[j][k+i*stride_lowres] );
1711 fprintf( stderr, "\n" );
17021712 for( int k = 0; k < w; k++ )
1703 printf( "%d ", dsta[j][k+i*stride_lowres] );
1704 printf( "\n" );
1713 fprintf( stderr, "%d ", dsta[j][k+i*stride_lowres] );
1714 fprintf( stderr, "\n" );
17051715 break;
17061716 }
17071717 }
18841894 for( size_t size = 16; size < 512; size += 16 )
18851895 {
18861896 for( size_t i = 0; i < size; i++ )
1887 buf1[i] = rand();
1897 buf1[i] = (uint8_t)rand();
18881898 memset( buf4-1, 0xAA, size + 2 );
18891899 call_c( mc_c.memcpy_aligned, buf3, buf1, size );
18901900 call_a( mc_a.memcpy_aligned, buf4, buf1, size );
20182028 for( int l = 0; l < 4; l++ )
20192029 {
20202030 for( int m = 0; m < 4; m++ )
2021 printf("%d ",bs[j][k][l][m]);
2022 printf("\n");
2031 fprintf( stderr, "%d ",bs[j][k][l][m] );
2032 fprintf( stderr, "\n" );
20232033 }
2024 printf("\n");
2034 fprintf( stderr, "\n" );
20252035 }
20262036 break;
20272037 }
20532063 h->chroma_qp_table = i_chroma_qp_table + 12;
20542064 h->param.analyse.b_transform_8x8 = 1;
20552065
2056 for( int i_cqm = 0; i_cqm < 4; i_cqm++ )
2066 static const uint8_t cqm_test4[16] =
2067 {
2068 6,4,6,4,
2069 4,3,4,3,
2070 6,4,6,4,
2071 4,3,4,3
2072 };
2073 static const uint8_t cqm_test8[64] =
2074 {
2075 3,3,4,3,3,3,4,3,
2076 3,3,4,3,3,3,4,3,
2077 4,4,5,4,4,4,5,4,
2078 3,3,4,3,3,3,4,3,
2079 3,3,4,3,3,3,4,3,
2080 3,3,4,3,3,3,4,3,
2081 4,4,5,4,4,4,5,4,
2082 3,3,4,3,3,3,4,3
2083 };
2084
2085 for( int i_cqm = 0; i_cqm < 6; i_cqm++ )
20572086 {
20582087 if( i_cqm == 0 )
20592088 {
2060 for( int i = 0; i < 6; i++ )
2089 for( int i = 0; i < 8; i++ )
20612090 h->sps->scaling_list[i] = x264_cqm_flat16;
20622091 h->param.i_cqm_preset = h->sps->i_cqm_preset = X264_CQM_FLAT;
20632092 }
20642093 else if( i_cqm == 1 )
20652094 {
2066 for( int i = 0; i < 6; i++ )
2095 for( int i = 0; i < 8; i++ )
20672096 h->sps->scaling_list[i] = x264_cqm_jvt[i];
20682097 h->param.i_cqm_preset = h->sps->i_cqm_preset = X264_CQM_JVT;
20692098 }
2099 else if( i_cqm == 2 )
2100 {
2101 for( int i = 0; i < 4; i++ )
2102 h->sps->scaling_list[i] = cqm_test4;
2103 for( int i = 4; i < 8; i++ )
2104 h->sps->scaling_list[i] = x264_cqm_flat16;
2105 h->param.i_cqm_preset = h->sps->i_cqm_preset = X264_CQM_CUSTOM;
2106 }
2107 else if( i_cqm == 3 )
2108 {
2109 for( int i = 0; i < 4; i++ )
2110 h->sps->scaling_list[i] = x264_cqm_flat16;
2111 for( int i = 4; i < 8; i++ )
2112 h->sps->scaling_list[i] = cqm_test8;
2113 h->param.i_cqm_preset = h->sps->i_cqm_preset = X264_CQM_CUSTOM;
2114 }
20702115 else
20712116 {
20722117 int max_scale = BIT_DEPTH < 10 ? 255 : 228;
2073 if( i_cqm == 2 )
2118 if( i_cqm == 4 )
20742119 for( int i = 0; i < 64; i++ )
20752120 cqm_buf[i] = 10 + rand() % (max_scale - 9);
20762121 else
20772122 for( int i = 0; i < 64; i++ )
20782123 cqm_buf[i] = 1;
2079 for( int i = 0; i < 6; i++ )
2124 for( int i = 0; i < 8; i++ )
20802125 h->sps->scaling_list[i] = cqm_buf;
20812126 h->param.i_cqm_preset = h->sps->i_cqm_preset = X264_CQM_CUSTOM;
20822127 }
20932138 static const int scale1d[8] = {32,31,24,31,32,31,24,31}; \
20942139 for( int i = 0; i < max; i++ ) \
20952140 { \
2096 unsigned int scale = (255*scale1d[(i>>3)&7]*scale1d[i&7])/16; \
2097 dct1[i] = dct2[i] = (j>>(i>>6))&1 ? (rand()%(2*scale+1))-scale : 0; \
2141 int scale = (PIXEL_MAX*scale1d[(i>>3)&7]*scale1d[i&7])/16; \
2142 dct1[i] = dct2[i] = (j>>(i>>6))&1 ? (rand30()%(2*scale+1))-scale : 0; \
20982143 } \
20992144 }
21002145
21032148 static const int scale1d[4] = {4,6,4,6}; \
21042149 for( int i = 0; i < max; i++ ) \
21052150 { \
2106 unsigned int scale = 255*scale1d[(i>>2)&3]*scale1d[i&3]; \
2107 dct1[i] = dct2[i] = (j>>(i>>4))&1 ? (rand()%(2*scale+1))-scale : 0; \
2151 int scale = PIXEL_MAX*scale1d[(i>>2)&3]*scale1d[i&3]; \
2152 dct1[i] = dct2[i] = (j>>(i>>4))&1 ? (rand30()%(2*scale+1))-scale : 0; \
21082153 } \
21092154 }
21102155
23822427 { \
23832428 int nnz = 0; \
23842429 int max = rand() & (size-1); \
2385 memset( dct1, 0, size*sizeof(dctcoef) ); \
2430 memset( dct1, 0, 64*sizeof(dctcoef) ); \
23862431 for( int idx = ac; idx < max; idx++ ) \
23872432 nnz |= dct1[idx] = !(rand()&3) + (!(rand()&15))*rand(); \
23882433 if( !nnz ) \
24162461 x264_run_level_t runlevel_c, runlevel_a; \
24172462 int nnz = 0; \
24182463 int max = rand() & (size-1); \
2419 memset( dct1, 0, size*sizeof(dctcoef) ); \
2464 memset( dct1, 0, 64*sizeof(dctcoef) ); \
24202465 memcpy( &runlevel_a, buf1+i, sizeof(x264_run_level_t) ); \
24212466 memcpy( &runlevel_c, buf1+i, sizeof(x264_run_level_t) ); \
24222467 for( int idx = ac; idx < max; idx++ ) \
25022547 if( ip_c.name == (void *)ip_c.predict_8x8 )\
25032548 {\
25042549 for( int k = -1; k < 16; k++ )\
2505 printf( "%2x ", edge[16+k] );\
2506 printf( "\n" );\
2550 fprintf( stderr, FMT_PIXEL" ", edge[16+k] );\
2551 fprintf( stderr, "\n" );\
25072552 }\
25082553 for( int j = 0; j < h; j++ )\
25092554 {\
25102555 if( ip_c.name == (void *)ip_c.predict_8x8 )\
2511 printf( "%2x ", edge[14-j] );\
2556 fprintf( stderr, FMT_PIXEL" ", edge[14-j] );\
25122557 for( int k = 0; k < w; k++ )\
2513 printf( "%2x ", pbuf4[48+k+j*FDEC_STRIDE] );\
2514 printf( "\n" );\
2558 fprintf( stderr, FMT_PIXEL" ", pbuf4[48+k+j*FDEC_STRIDE] );\
2559 fprintf( stderr, "\n" );\
25152560 }\
2516 printf( "\n" );\
2561 fprintf( stderr, "\n" );\
25172562 for( int j = 0; j < h; j++ )\
25182563 {\
25192564 if( ip_c.name == (void *)ip_c.predict_8x8 )\
2520 printf( " " );\
2565 fprintf( stderr, " " );\
25212566 for( int k = 0; k < w; k++ )\
2522 printf( "%2x ", pbuf3[48+k+j*FDEC_STRIDE] );\
2523 printf( "\n" );\
2567 fprintf( stderr, FMT_PIXEL" ", pbuf3[48+k+j*FDEC_STRIDE] );\
2568 fprintf( stderr, "\n" );\
25242569 }\
25252570 break;\
25262571 }\
27712816 int test_size = i < 10 ? i+1 : rand() & 0x3fff;
27722817 /* Test 8 different probability distributions of zeros */
27732818 for( int j = 0; j < test_size+32; j++ )
2774 input[j] = (rand()&((1 << ((i&7)+1)) - 1)) * rand();
2819 input[j] = (uint8_t)((rand()&((1 << ((i&7)+1)) - 1)) * rand());
27752820 uint8_t *end_c = (uint8_t*)call_c1( bs_c.nal_escape, output1, input, input+test_size );
27762821 uint8_t *end_a = (uint8_t*)call_a1( bs_a.nal_escape, output2, input, input+test_size );
27772822 int size_c = end_c-output1;
27842829 }
27852830 }
27862831 for( int j = 0; j < size+32; j++ )
2787 input[j] = rand();
2832 input[j] = (uint8_t)rand();
27882833 call_c2( bs_c.nal_escape, output1, input, input+size );
27892834 call_a2( bs_a.nal_escape, output2, input, input+size );
27902835 free(input);
29573002 argv++;
29583003 }
29593004
2960 int seed = ( argc > 1 ) ? atoi(argv[1]) : x264_mdate();
3005 unsigned seed = ( argc > 1 ) ? strtoul(argv[1], NULL, 0) : (unsigned)x264_mdate();
29613006 fprintf( stderr, "x264: using random seed %u\n", seed );
29623007 srand( seed );
29633008
138138 args = self.optparse.parse_args()[1] # arguments may require reparsing after pre_dispatch; see test_x264.py
139139
140140 if len(args) == 0:
141 print >>sys.stderr, "error: no comamnd specified\n"
141 print >>sys.stderr, "error: no command specified\n"
142142 self.optparse.print_help()
143143 return
144144
00 #!/bin/sh
11 # Script modified from upstream source for Debian packaging since packaging
22 # won't include .git repository.
3 echo '#define X264_VERSION " r3060 5db6aa6"'
4 echo '#define X264_POINTVER "0.163.3060 5db6aa6"'
3 echo '#define X264_VERSION " r3095 baee400"'
4 echo '#define X264_POINTVER "0.164.3095 baee400"'
00 /*****************************************************************************
11 * x264: top-level x264cli functions
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Loren Merritt <lorenm@u.washington.edu>
66 * Laurent Aimar <fenrir@via.ecp.fr>
139139 /* video filter operation struct */
140140 static cli_vid_filter_t filter;
141141
142 const char * const x264_avcintra_class_names[] = { "50", "100", "200", 0 };
142 const char * const x264_avcintra_class_names[] = { "50", "100", "200", "300", "480", 0 };
143143 const char * const x264_cqm_names[] = { "flat", "jvt", 0 };
144144 const char * const x264_log_level_names[] = { "none", "error", "warning", "info", "debug", 0 };
145145 const char * const x264_partition_names[] = { "p8x8", "p4x4", "b8x8", "i8x8", "i4x4", "none", "all", 0 };
494494 " .mkv -> Matroska\n"
495495 " .flv -> Flash Video\n"
496496 " .mp4 -> MP4 if compiled with GPAC or L-SMASH support (%s)\n"
497 "Output bit depth: %s\n."
497 "Output bit depth: %s\n"
498498 "\n"
499499 "Options:\n"
500500 "\n"
13011301 {
13021302 x264_register_vid_filters();
13031303
1304 /* intialize baseline filters */
1304 /* initialize baseline filters */
13051305 if( x264_init_vid_filter( "source", handle, &filter, info, param, NULL ) ) /* wrap demuxer into a filter */
13061306 return -1;
13071307 if( x264_init_vid_filter( "resize", handle, &filter, info, param, "normcsp" ) ) /* normalize csps to be of a known/supported format */
00 /*****************************************************************************
11 * x264.h: x264 public header
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
4444
4545 #include "x264_config.h"
4646
47 #define X264_BUILD 163
47 #define X264_BUILD 164
4848
4949 #ifdef _WIN32
5050 # define X264_DLL_IMPORT __declspec(dllimport)
520520 int i_sps_id; /* SPS and PPS id number */
521521 int b_vfr_input; /* VFR input. If 1, use timebase and timestamps for ratecontrol purposes.
522522 * If 0, use fps only. */
523 int b_pulldown; /* use explicity set timebase for CFR */
523 int b_pulldown; /* use explicitly set timebase for CFR */
524524 uint32_t i_fps_num;
525525 uint32_t i_fps_den;
526526 uint32_t i_timebase_num; /* Timebase numerator */
00 /*****************************************************************************
11 * x264cli.h: x264cli common
22 *****************************************************************************
3 * Copyright (C) 2003-2021 x264 project
3 * Copyright (C) 2003-2022 x264 project
44 *
55 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
66 * Loren Merritt <lorenm@u.washington.edu>
00 /*****************************************************************************
11 * x264dll: x264 DLLMain for win32
22 *****************************************************************************
3 * Copyright (C) 2009-2021 x264 project
3 * Copyright (C) 2009-2022 x264 project
44 *
55 * Authors: Anton Mitrofanov <BugMaster@narod.ru>
66 *
00 /*****************************************************************************
11 * x264res.rc: windows resource file
22 *****************************************************************************
3 * Copyright (C) 2012-2021 x264 project
3 * Copyright (C) 2012-2022 x264 project
44 *
55 * Authors: Henrik Gramner <henrik@gramner.com>
66 *
6767 #endif
6868 VALUE "FileVersion", X264_POINTVER
6969 VALUE "InternalName", "x264"
70 VALUE "LegalCopyright", "Copyright (C) 2003-2021 x264 project"
70 VALUE "LegalCopyright", "Copyright (C) 2003-2022 x264 project"
7171 #ifdef DLL
7272 VALUE "OriginalFilename", "libx264-" xstr(X264_BUILD) ".dll"
7373 #else