Codebase list x264 / upstream/0.148.2728+git4d5c8b0
New upstream version 0.148.2728+git4d5c8b0 Rico Tzschichholz 7 years ago
53 changed file(s) with 928 addition(s) and 650 deletion(s). Raw diff Collapse all Expand all
12531253 endfunc
12541254
12551255 function x264_plane_copy_core_neon, export=1
1256 add x8, x4, #15
1257 and x4, x8, #~15
1256 add w8, w4, #15 // 32-bit write clears the upper 32-bit the register
1257 and w4, w8, #~15
1258 // safe use of the full reg since negative width makes no sense
12581259 sub x1, x1, x4
12591260 sub x3, x3, x4
12601261 1:
12701271 subs w8, w8, #32
12711272 ldp q0, q1, [x2], #32
12721273 stp q0, q1, [x0], #32
1274 b.gt 32b
1275 0:
1276 subs w5, w5, #1
1277 add x2, x2, x3
1278 add x0, x0, x1
1279 b.gt 1b
1280
1281 ret
1282 endfunc
1283
1284 function x264_plane_copy_swap_core_neon, export=1
1285 lsl w4, w4, #1
1286 sub x1, x1, x4
1287 sub x3, x3, x4
1288 1:
1289 mov w8, w4
1290 tbz w4, #4, 32f
1291 subs w8, w8, #16
1292 ld1 {v0.16b}, [x2], #16
1293 rev16 v0.16b, v0.16b
1294 st1 {v0.16b}, [x0], #16
1295 b.eq 0f
1296 32:
1297 subs w8, w8, #32
1298 ld1 {v0.16b,v1.16b}, [x2], #32
1299 rev16 v0.16b, v0.16b
1300 rev16 v1.16b, v1.16b
1301 st1 {v0.16b,v1.16b}, [x0], #32
12731302 b.gt 32b
12741303 0:
12751304 subs w5, w5, #1
5050
5151 void x264_plane_copy_core_neon( pixel *dst, intptr_t i_dst,
5252 pixel *src, intptr_t i_src, int w, int h );
53 void x264_plane_copy_swap_core_neon( pixel *dst, intptr_t i_dst,
54 pixel *src, intptr_t i_src, int w, int h );
5355 void x264_plane_copy_deinterleave_neon( pixel *dstu, intptr_t i_dstu,
5456 pixel *dstv, intptr_t i_dstv,
5557 pixel *src, intptr_t i_src, int w, int h );
207209 int height, int16_t *buf );
208210
209211 PLANE_COPY(16, neon)
212 PLANE_COPY_SWAP(16, neon)
210213 PLANE_INTERLEAVE(neon)
211214 #endif // !HIGH_BIT_DEPTH
212215
231234 pf->copy[PIXEL_4x4] = x264_mc_copy_w4_neon;
232235
233236 pf->plane_copy = x264_plane_copy_neon;
237 pf->plane_copy_swap = x264_plane_copy_swap_neon;
234238 pf->plane_copy_deinterleave = x264_plane_copy_deinterleave_neon;
235239 pf->plane_copy_deinterleave_rgb = x264_plane_copy_deinterleave_rgb_neon;
236240 pf->plane_copy_interleave = x264_plane_copy_interleave_neon;
210210 vclt.u8 q13, q4, q14 @ < (alpha >> 2) + 2 if_2
211211 vand q12, q7, q6 @ if_1
212212 vshrn.u16 d28, q12, #4
213 vcmp.f64 d28, #0
214 vmrs APSR_nzcv, FPSCR
213 vmov r2, lr, d28
214 orrs r2, r2, lr
215215 beq 9f
216216
217217 sub sp, sp, #32
324324 .endm
325325
326326 function x264_deblock_v_luma_intra_neon
327 push {lr}
327328 vld1.64 {d0, d1}, [r0,:128], r1
328329 vld1.64 {d2, d3}, [r0,:128], r1
329330 vld1.64 {d4, d5}, [r0,:128], r1
347348 vst1.64 {d4, d5}, [r0,:128]
348349 9:
349350 align_pop_regs
350 bx lr
351 pop {pc}
351352 endfunc
352353
353354 function x264_deblock_h_luma_intra_neon
355 push {lr}
354356 sub r0, r0, #4
355357 vld1.64 {d22}, [r0], r1
356358 vld1.64 {d20}, [r0], r1
396398 vst1.64 {d7}, [r0], r1
397399 9:
398400 align_pop_regs
399 bx lr
401 pop {pc}
400402 endfunc
401403
402404 .macro h264_loop_filter_chroma
220220 }
221221 else if( !strcasecmp( preset, "veryfast" ) )
222222 {
223 param->analyse.i_me_method = X264_ME_HEX;
224223 param->analyse.i_subpel_refine = 2;
225224 param->i_frame_reference = 1;
226225 param->analyse.b_mixed_references = 0;
249248 }
250249 else if( !strcasecmp( preset, "slow" ) )
251250 {
252 param->analyse.i_me_method = X264_ME_UMH;
253251 param->analyse.i_subpel_refine = 8;
254252 param->i_frame_reference = 5;
255 param->i_bframe_adaptive = X264_B_ADAPT_TRELLIS;
256253 param->analyse.i_direct_mv_pred = X264_DIRECT_PRED_AUTO;
254 param->analyse.i_trellis = 2;
257255 param->rc.i_lookahead = 50;
258256 }
259257 else if( !strcasecmp( preset, "slower" ) )
989989 pf_progressive->scan_4x4 = x264_zigzag_scan_4x4_frame_mmx;
990990 if( cpu&X264_CPU_MMX2 )
991991 {
992 pf_interlaced->scan_4x4 = x264_zigzag_scan_4x4_field_mmx2;
993992 pf_interlaced->scan_8x8 = x264_zigzag_scan_8x8_field_mmx2;
994993 pf_progressive->scan_8x8 = x264_zigzag_scan_8x8_frame_mmx2;
995994 }
995 if( cpu&X264_CPU_SSE )
996 pf_interlaced->scan_4x4 = x264_zigzag_scan_4x4_field_sse;
996997 if( cpu&X264_CPU_SSE2_IS_FAST )
997998 pf_progressive->scan_8x8 = x264_zigzag_scan_8x8_frame_sse2;
998999 if( cpu&X264_CPU_SSSE3 )
34293429 x264_mc_weight_w8_msa( p_dst, *p_dst_stride,
34303430 p_dst, *p_dst_stride,
34313431 pWeight, i_h4w );
3432 for( i_cnt = i_h4w; i_cnt < i_height ; i_cnt++ )
3432 for( i_cnt = i_h4w; i_cnt < i_height; i_cnt++ )
34333433 {
34343434 uint64_t temp0;
34353435 v16i8 zero = {0};
36653665 pWeight, i_h4w );
36663666 p_src1 = src1_org + i_h4w * i_src_stride;
36673667
3668 for( i_cnt = i_h4w; i_cnt < i_height ; i_cnt++ )
3668 for( i_cnt = i_h4w; i_cnt < i_height; i_cnt++ )
36693669 {
36703670 uint64_t u_temp0;
36713671 v16i8 zero = {0};
369369 h->mb.i_partition = partition_col[0];
370370 }
371371 }
372 int i_mb_4x4 = b_interlaced ? 4 * (h->mb.i_b4_stride*mb_y + mb_x) : h->mb.i_b4_xy ;
373 int i_mb_8x8 = b_interlaced ? 2 * (h->mb.i_b8_stride*mb_y + mb_x) : h->mb.i_b8_xy ;
372 int i_mb_4x4 = b_interlaced ? 4 * (h->mb.i_b4_stride*mb_y + mb_x) : h->mb.i_b4_xy;
373 int i_mb_8x8 = b_interlaced ? 2 * (h->mb.i_b8_stride*mb_y + mb_x) : h->mb.i_b8_xy;
374374
375375 int8_t *l1ref0 = &h->fref[1][0]->ref[0][i_mb_8x8];
376376 int8_t *l1ref1 = &h->fref[1][0]->ref[1][i_mb_8x8];
248248 static ALWAYS_INLINE int x264_pthread_fetch_and_add( int *val, int add, x264_pthread_mutex_t *mutex )
249249 {
250250 #if HAVE_THREAD
251 #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 0) && ARCH_X86
251 #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 0) && (ARCH_X86 || ARCH_X86_64)
252252 return __sync_fetch_and_add( val, add );
253253 #else
254254 x264_pthread_mutex_lock( mutex );
555555 #if HIGH_BIT_DEPTH
556556 #define x264_predict_8x8c_v_mmx2 x264_predict_8x8c_v_mmx
557557 #define x264_predict_8x16c_v_mmx2 x264_predict_8x16c_v_c
558 #define x264_predict_16x16_dc_mmx2 x264_predict_16x16_dc_c
558559 #define x264_predict_8x8c_v_sse2 x264_predict_8x8c_v_sse
559560 #define x264_predict_8x16c_v_sse2 x264_predict_8x16c_v_sse
560561 #define x264_predict_16x16_v_sse2 x264_predict_16x16_v_sse
883884 INIT8( ssd, _mmx2 );
884885 INIT_ADS( _mmx2 );
885886
886 pixf->ssd_nv12_core = x264_pixel_ssd_nv12_core_mmx2;
887887 pixf->var[PIXEL_16x16] = x264_pixel_var_16x16_mmx2;
888888 pixf->var[PIXEL_8x8] = x264_pixel_var_8x8_mmx2;
889889 #if ARCH_X86
10691069 pixf->var[PIXEL_16x16] = x264_pixel_var_16x16_mmx2;
10701070 pixf->var[PIXEL_8x16] = x264_pixel_var_8x16_mmx2;
10711071 pixf->var[PIXEL_8x8] = x264_pixel_var_8x8_mmx2;
1072 pixf->ssd_nv12_core = x264_pixel_ssd_nv12_core_mmx2;
10731072 #if ARCH_X86
10741073 pixf->sa8d[PIXEL_16x16] = x264_pixel_sa8d_16x16_mmx2;
10751074 pixf->sa8d[PIXEL_8x8] = x264_pixel_sa8d_8x8_mmx2;
18111811 d3 = vec_sub(t1, t3); \
18121812 }
18131813
1814 #ifdef WORDS_BIGENDIAN
1815 #define vec_perm_extend_s16(val, perm) (vec_s16_t)vec_perm(val, zero_u8v, perm)
1816 #else
1817 #define vec_perm_extend_s16(val, perm) (vec_s16_t)vec_perm(zero_u8v, val, perm)
1818 #endif
1819
18141820 #define VEC_LOAD_HIGH( p, num ) \
18151821 vec_u8_t pix8_##num = vec_ld( stride*num, p ); \
1816 vec_s16_t pix16_s##num = (vec_s16_t)vec_perm(pix8_##num, zero_u8v, perm); \
1822 vec_s16_t pix16_s##num = vec_perm_extend_s16( pix8_##num, perm ); \
18171823 vec_s16_t pix16_d##num;
18181824
18191825 static uint64_t pixel_hadamard_ac_altivec( uint8_t *pix, intptr_t stride, const vec_u8_t perm )
7070 vec_u32_t multEvenvA, multOddvA;
7171 vec_u16_t mfvA;
7272 vec_u16_t biasvA;
73 vec_s16_t one = vec_splat_s16(1);;
73 vec_s16_t one = vec_splat_s16(1);
7474 vec_s16_t nz = zero_s16v;
7575
7676 vector bool short mskB;
215215 vec_u32_t multEvenvA, multOddvA;
216216 vec_u16_t mfvA;
217217 vec_u16_t biasvA;
218 vec_s16_t one = vec_splat_s16(1);;
218 vec_s16_t one = vec_splat_s16(1);
219219 vec_s16_t nz = zero_s16v;
220220
221221 vector bool short mskB;
3737 const pw_pixel_max,times 16 dw ((1 << BIT_DEPTH)-1)
3838 const pw_0to15, dw 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
3939 const pd_1, times 8 dd 1
40 const pd_0123, dd 0,1,2,3
41 const pd_4567, dd 4,5,6,7
4042 const deinterleave_shufd, dd 0,4,1,5,2,6,3,7
4143 const pb_unpackbd1, times 2 db 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3
4244 const pb_unpackbd2, times 2 db 4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7
6264 const pw_pmpmpmpm, dw 1,-1,1,-1,1,-1,1,-1
6365 const pw_pmmpzzzz, dw 1,-1,-1,1,0,0,0,0
6466
67 const pd_8, times 4 dd 8
6568 const pd_32, times 4 dd 32
6669 const pd_1024, times 4 dd 1024
6770 const pd_ffff, times 4 dd 0xffff
14621462 ; void zigzag_scan_4x4_field( int32_t level[16], int32_t dct[4][4] )
14631463 ;-----------------------------------------------------------------------------
14641464 INIT_XMM sse2
1465 cglobal zigzag_scan_4x4_field, 2,3
1466 movu m4, [r1+ 8]
1467 pshufd m0, m4, q3102
1465 cglobal zigzag_scan_4x4_field, 2,2
1466 movu m0, [r1+ 8]
1467 pshufd m0, m0, q3102
14681468 mova m1, [r1+32]
14691469 mova m2, [r1+48]
14701470 movu [r0+ 8], m0
14791479 ;-----------------------------------------------------------------------------
14801480 ; void zigzag_scan_4x4_field( int16_t level[16], int16_t dct[4][4] )
14811481 ;-----------------------------------------------------------------------------
1482 ; sse2 is only 1 cycle faster, and ssse3/pshufb is slower on core2
1483 INIT_MMX mmx2
1484 cglobal zigzag_scan_4x4_field, 2,3
1485 pshufw m0, [r1+4], q3102
1486 mova m1, [r1+16]
1487 mova m2, [r1+24]
1488 movu [r0+4], m0
1489 mova [r0+16], m1
1490 mova [r0+24], m2
1491 mov r2d, [r1]
1492 mov [r0], r2d
1493 mov r2d, [r1+12]
1494 mov [r0+12], r2d
1482 INIT_XMM sse
1483 cglobal zigzag_scan_4x4_field, 2,2
1484 mova m0, [r1]
1485 mova m1, [r1+16]
1486 pshufw mm0, [r1+4], q3102
1487 mova [r0], m0
1488 mova [r0+16], m1
1489 movq [r0+4], mm0
14951490 RET
14961491 %endif ; HIGH_BIT_DEPTH
14971492
111111 void x264_zigzag_scan_4x4_frame_sse2 ( int32_t level[16], int32_t dct[16] );
112112 void x264_zigzag_scan_4x4_frame_mmx ( int16_t level[16], int16_t dct[16] );
113113 void x264_zigzag_scan_4x4_field_sse2 ( int32_t level[16], int32_t dct[16] );
114 void x264_zigzag_scan_4x4_field_mmx2 ( int16_t level[16], int16_t dct[16] );
114 void x264_zigzag_scan_4x4_field_sse ( int16_t level[16], int16_t dct[16] );
115115 void x264_zigzag_scan_8x8_field_xop ( int16_t level[64], int16_t dct[64] );
116116 void x264_zigzag_scan_8x8_field_avx ( int32_t level[64], int32_t dct[64] );
117117 void x264_zigzag_scan_8x8_field_sse4 ( int32_t level[64], int32_t dct[64] );
6666 pf_inv256: times 4 dd 0.00390625
6767
6868 pd_16: times 4 dd 16
69 pd_0f: times 4 dd 0xffff
7069
7170 pad10: times 8 dw 10*PIXEL_MAX
7271 pad20: times 8 dw 20*PIXEL_MAX
9392 cextern pw_3fff
9493 cextern pw_pixel_max
9594 cextern pw_0to15
95 cextern pd_8
96 cextern pd_0123
9697 cextern pd_ffff
9798
9899 %macro LOAD_ADD 4
284285 psrad m1, 10
285286 psrad m2, 10
286287 pslld m2, 16
287 pand m1, [pd_0f]
288 pand m1, [pd_ffff]
288289 por m1, m2
289290 CLIPW m1, [pb_0], [pw_pixel_max]
290291 mova [r0+r2], m1
21772178
21782179 %macro MBTREE_PROPAGATE_LIST 0
21792180 ;-----------------------------------------------------------------------------
2180 ; void mbtree_propagate_list_internal( int16_t (*mvs)[2], int *propagate_amount, uint16_t *lowres_costs,
2181 ; void mbtree_propagate_list_internal( int16_t (*mvs)[2], int16_t *propagate_amount, uint16_t *lowres_costs,
21812182 ; int16_t *output, int bipred_weight, int mb_y, int len )
21822183 ;-----------------------------------------------------------------------------
21832184 cglobal mbtree_propagate_list_internal, 4,6,8
22662267 MBTREE_PROPAGATE_LIST
22672268 INIT_XMM avx
22682269 MBTREE_PROPAGATE_LIST
2270
2271 INIT_YMM avx2
2272 cglobal mbtree_propagate_list_internal, 4+2*UNIX64,5+UNIX64,8
2273 mova xm4, [pw_0xc000]
2274 %if UNIX64
2275 shl r4d, 9
2276 shl r5d, 16
2277 movd xm5, r4d
2278 movd xm6, r5d
2279 vpbroadcastw xm5, xm5
2280 vpbroadcastd m6, xm6
2281 %else
2282 vpbroadcastw xm5, r4m
2283 vpbroadcastd m6, r5m
2284 psllw xm5, 9 ; bipred_weight << 9
2285 pslld m6, 16
2286 %endif
2287 mov r4d, r6m
2288 lea r1, [r1+r4*2]
2289 lea r2, [r2+r4*2]
2290 lea r0, [r0+r4*4]
2291 neg r4
2292 por m6, [pd_0123] ; 0 y 1 y 2 y 3 y 4 y 5 y 6 y 7 y
2293 vbroadcasti128 m7, [pw_31]
2294 .loop:
2295 mova xm3, [r1+r4*2]
2296 pand xm0, xm4, [r2+r4*2]
2297 pmulhrsw xm1, xm3, xm5 ; bipred_amount = (propagate_amount * bipred_weight + 32) >> 6
2298 pcmpeqw xm0, xm4
2299 pblendvb xm3, xm3, xm1, xm0 ; (lists_used == 3) ? bipred_amount : propagate_amount
2300 vpermq m3, m3, q1100
2301
2302 movu m0, [r0+r4*4] ; {x, y}
2303 vbroadcasti128 m1, [pd_8]
2304 psraw m2, m0, 5
2305 paddw m2, m6 ; {mbx, mby} = ({x, y} >> 5) + {h->mb.i_mb_x, h->mb.i_mb_y}
2306 paddw m6, m1 ; i_mb_x += 8
2307 mova [r3], m2
2308
2309 mova m1, [pw_32]
2310 pand m0, m7
2311 psubw m1, m0
2312 packuswb m1, m0 ; {32-x, 32-y} {x, y} {32-x, 32-y} {x, y}
2313 psrlw m0, m1, 3
2314 pand m1, [pw_00ff] ; 32-x x 32-x x
2315 pandn m0, m7, m0 ; (32-y y 32-y y) << 5
2316 pshufd m2, m1, q1032
2317 pmullw m1, m0 ; idx0 idx3 idx0 idx3
2318 pmullw m2, m0 ; idx1 idx2 idx1 idx2
2319
2320 pmulhrsw m0, m1, m3 ; (idx0 idx3 idx0 idx3) * propagate_amount + 512 >> 10
2321 pmulhrsw m2, m3 ; (idx1 idx2 idx1 idx2) * propagate_amount + 512 >> 10
2322 psignw m0, m1 ; correct potential overflow in the idx0 input to pmulhrsw
2323 punpcklwd m1, m0, m2 ; idx01weight
2324 punpckhwd m2, m0 ; idx23weight
2325 mova [r3+32], m1
2326 mova [r3+64], m2
2327 add r3, 3*mmsize
2328 add r4, 8
2329 jl .loop
2330 RET
22692331
22702332 %macro MBTREE_FIX8 0
22712333 ;-----------------------------------------------------------------------------
531531
532532 PROPAGATE_LIST(ssse3)
533533 PROPAGATE_LIST(avx)
534 PROPAGATE_LIST(avx2)
534535
535536 void x264_mc_init_mmx( int cpu, x264_mc_functions_t *pf )
536537 {
842843 pf->plane_copy_swap = x264_plane_copy_swap_avx2;
843844 pf->get_ref = get_ref_avx2;
844845 pf->mbtree_propagate_cost = x264_mbtree_propagate_cost_avx2;
846 pf->mbtree_propagate_list = x264_mbtree_propagate_list_avx2;
845847 pf->mbtree_fix8_pack = x264_mbtree_fix8_pack_avx2;
846848 pf->mbtree_fix8_unpack = x264_mbtree_fix8_unpack_avx2;
847849 }
4242 mask_ac4: times 2 dw 0, -1, -1, -1, 0, -1, -1, -1
4343 mask_ac4b: times 2 dw 0, -1, 0, -1, -1, -1, -1, -1
4444 mask_ac8: times 2 dw 0, -1, -1, -1, -1, -1, -1, -1
45 %if HIGH_BIT_DEPTH
46 ssd_nv12_shuf: db 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15
47 %endif
4548 %if BIT_DEPTH == 10
4649 ssim_c1: times 4 dd 6697.7856 ; .01*.01*1023*1023*64
4750 ssim_c2: times 4 dd 3797644.4352 ; .03*.03*1023*1023*64*63
530533 ;
531534 ; 2 * mmsize/32 * (2^32 - 1) / (2^BIT_DEPTH - 1)^2
532535 ;
533 ; For 10-bit MMX this means width >= 16416 and for XMM >= 32832. At sane
534 ; distortion levels it will take much more than that though.
536 ; For 10-bit XMM this means width >= 32832. At sane distortion levels
537 ; it will take much more than that though.
535538 ;-----------------------------------------------------------------------------
536539 %if HIGH_BIT_DEPTH
537540 %macro SSD_NV12 0
540543 FIX_STRIDES r1, r3
541544 add r0, r4
542545 add r2, r4
543 xor r6, r6
546 neg r4
544547 pxor m4, m4
545548 pxor m5, m5
546 pxor m6, m6
549 %if mmsize == 32
550 vbroadcasti128 m6, [ssd_nv12_shuf]
551 %endif
547552 .loopy:
548553 mov r6, r4
549 neg r6
550554 pxor m2, m2
551555 pxor m3, m3
552556 .loopx:
554558 mova m1, [r0+r6+mmsize]
555559 psubw m0, [r2+r6]
556560 psubw m1, [r2+r6+mmsize]
557 PSHUFLW m0, m0, q3120
558 PSHUFLW m1, m1, q3120
559 %if mmsize >= 16
560 pshufhw m0, m0, q3120
561 pshufhw m1, m1, q3120
561 %if mmsize == 32
562 pshufb m0, m6
563 pshufb m1, m6
564 %else
565 SBUTTERFLY wd, 0, 1, 6
562566 %endif
563567 %if cpuflag(xop)
564568 pmadcswd m2, m0, m0, m2
576580 psubd m3, m1
577581 .no_overread:
578582 %endif
579 %if mmsize >= 16 ; using HADDD would remove the mmsize/32 part from the
580 ; equation above, putting the width limit at 8208
581 punpckhdq m0, m2, m6
582 punpckhdq m1, m3, m6
583 punpckldq m2, m6
584 punpckldq m3, m6
585 paddq m3, m2
586 paddq m1, m0
587 paddq m4, m3
588 paddq m4, m1
589 %else ; unfortunately paddq is sse2
590 ; emulate 48 bit precision for mmx2 instead
591 mova m0, m2
592 mova m1, m3
593 punpcklwd m2, m6
594 punpcklwd m3, m6
595 punpckhwd m0, m6
596 punpckhwd m1, m6
597 paddd m3, m2
598 paddd m1, m0
599 paddd m4, m3
600 paddd m5, m1
601 %endif
583 punpckhdq m0, m2, m5 ; using HADDD would remove the mmsize/32 part from the
584 punpckhdq m1, m3, m5 ; equation above, putting the width limit at 8208
585 punpckldq m2, m5
586 punpckldq m3, m5
587 paddq m0, m1
588 paddq m2, m3
589 paddq m4, m0
590 paddq m4, m2
602591 add r0, r1
603592 add r2, r3
604593 dec r5d
605594 jg .loopy
606 mov r3, r6m
607 mov r4, r7m
595 mov r0, r6m
596 mov r1, r7m
608597 %if mmsize == 32
609598 vextracti128 xm0, m4, 1
610599 paddq xm4, xm0
611600 %endif
612 %if mmsize >= 16
613 movq [r3], xm4
614 movhps [r4], xm4
615 %else ; fixup for mmx2
616 SBUTTERFLY dq, 4, 5, 0
617 mova m0, m4
618 psrld m4, 16
619 paddd m5, m4
620 pslld m0, 16
621 SBUTTERFLY dq, 0, 5, 4
622 psrlq m0, 16
623 psrlq m5, 16
624 movq [r3], m0
625 movq [r4], m5
626 %endif
601 movq [r0], xm4
602 movhps [r1], xm4
627603 RET
628604 %endmacro ; SSD_NV12
629 %endif ; HIGH_BIT_DEPTH
630
631 %if HIGH_BIT_DEPTH == 0
605
606 %else ; !HIGH_BIT_DEPTH
632607 ;-----------------------------------------------------------------------------
633608 ; void pixel_ssd_nv12_core( uint8_t *pixuv1, intptr_t stride1, uint8_t *pixuv2, intptr_t stride2,
634609 ; int width, int height, uint64_t *ssd_u, uint64_t *ssd_v )
642617 add r4d, r4d
643618 add r0, r4
644619 add r2, r4
620 neg r4
645621 pxor m3, m3
646622 pxor m4, m4
647623 mova m5, [pw_00ff]
648624 .loopy:
649625 mov r6, r4
650 neg r6
651626 .loopx:
652627 %if mmsize == 32 ; only 16-byte alignment is guaranteed
653628 movu m2, [r0+r6]
685660 add r2, r3
686661 dec r5d
687662 jg .loopy
688 mov r3, r6m
689 mov r4, r7m
690 HADDD m3, m0
691 HADDD m4, m0
692 pxor xm0, xm0
693 punpckldq xm3, xm0
694 punpckldq xm4, xm0
695 movq [r3], xm3
696 movq [r4], xm4
663 mov r0, r6m
664 mov r1, r7m
665 %if cpuflag(ssse3)
666 phaddd m3, m4
667 %else
668 SBUTTERFLY qdq, 3, 4, 0
669 paddd m3, m4
670 %endif
671 %if mmsize == 32
672 vextracti128 xm4, m3, 1
673 paddd xm3, xm4
674 %endif
675 psllq xm4, xm3, 32
676 paddd xm3, xm4
677 psrlq xm3, 32
678 movq [r0], xm3
679 movhps [r1], xm3
697680 RET
698681 %endmacro ; SSD_NV12
699682 %endif ; !HIGH_BIT_DEPTH
700683
701 INIT_MMX mmx2
702 SSD_NV12
703684 INIT_XMM sse2
704685 SSD_NV12
705686 INIT_XMM avx
46134594 ;-----------------------------------------------------------------------------
46144595 %macro SSIM_ITER 1
46154596 %if HIGH_BIT_DEPTH
4616 movdqu m5, [r0+(%1&1)*r1]
4617 movdqu m6, [r2+(%1&1)*r3]
4618 %else
4619 movq m5, [r0+(%1&1)*r1]
4620 movq m6, [r2+(%1&1)*r3]
4621 punpcklbw m5, m0
4622 punpcklbw m6, m0
4597 movu m4, [r0+(%1&1)*r1]
4598 movu m5, [r2+(%1&1)*r3]
4599 %elif cpuflag(avx)
4600 pmovzxbw m4, [r0+(%1&1)*r1]
4601 pmovzxbw m5, [r2+(%1&1)*r3]
4602 %else
4603 movq m4, [r0+(%1&1)*r1]
4604 movq m5, [r2+(%1&1)*r3]
4605 punpcklbw m4, m7
4606 punpcklbw m5, m7
46234607 %endif
46244608 %if %1==1
46254609 lea r0, [r0+r1*2]
46264610 lea r2, [r2+r3*2]
46274611 %endif
4628 %if %1==0
4629 movdqa m1, m5
4630 movdqa m2, m6
4631 %else
4612 %if %1 == 0 && cpuflag(avx)
4613 SWAP 0, 4
4614 SWAP 1, 5
4615 pmaddwd m4, m0, m0
4616 pmaddwd m5, m1, m1
4617 pmaddwd m6, m0, m1
4618 %else
4619 %if %1 == 0
4620 mova m0, m4
4621 mova m1, m5
4622 %else
4623 paddw m0, m4
46324624 paddw m1, m5
4633 paddw m2, m6
4634 %endif
4635 pmaddwd m7, m5, m6
4625 %endif
4626 pmaddwd m6, m4, m5
4627 pmaddwd m4, m4
46364628 pmaddwd m5, m5
4637 pmaddwd m6, m6
4638 ACCUM paddd, 3, 5, %1
4639 ACCUM paddd, 4, 7, %1
4640 paddd m3, m6
4629 %endif
4630 ACCUM paddd, 2, 4, %1
4631 ACCUM paddd, 3, 6, %1
4632 paddd m2, m5
46414633 %endmacro
46424634
46434635 %macro SSIM 0
4644 cglobal pixel_ssim_4x4x2_core, 4,4,8
4636 %if HIGH_BIT_DEPTH
4637 cglobal pixel_ssim_4x4x2_core, 4,4,7
46454638 FIX_STRIDES r1, r3
4646 pxor m0, m0
4639 %else
4640 cglobal pixel_ssim_4x4x2_core, 4,4,7+notcpuflag(avx)
4641 %if notcpuflag(avx)
4642 pxor m7, m7
4643 %endif
4644 %endif
46474645 SSIM_ITER 0
46484646 SSIM_ITER 1
46494647 SSIM_ITER 2
46504648 SSIM_ITER 3
4651 ; PHADDW m1, m2
4652 ; PHADDD m3, m4
4653 movdqa m7, [pw_1]
4654 pshufd m5, m3, q2301
4655 pmaddwd m1, m7
4656 pmaddwd m2, m7
4657 pshufd m6, m4, q2301
4658 packssdw m1, m2
4659 paddd m3, m5
4660 pshufd m1, m1, q3120
4661 paddd m4, m6
4662 pmaddwd m1, m7
4663 punpckhdq m5, m3, m4
4664 punpckldq m3, m4
4665
46664649 %if UNIX64
4667 %define t0 r4
4668 %else
4669 %define t0 rax
4670 mov t0, r4mp
4671 %endif
4672
4673 movq [t0+ 0], m1
4674 movq [t0+ 8], m3
4675 movhps [t0+16], m1
4676 movq [t0+24], m5
4650 DECLARE_REG_TMP 4
4651 %else
4652 DECLARE_REG_TMP 0
4653 mov t0, r4mp
4654 %endif
4655 %if cpuflag(ssse3)
4656 phaddw m0, m1
4657 pmaddwd m0, [pw_1]
4658 phaddd m2, m3
4659 %else
4660 mova m4, [pw_1]
4661 pmaddwd m0, m4
4662 pmaddwd m1, m4
4663 packssdw m0, m1
4664 shufps m1, m2, m3, q2020
4665 shufps m2, m3, q3131
4666 pmaddwd m0, m4
4667 paddd m2, m1
4668 %endif
4669 shufps m1, m0, m2, q2020
4670 shufps m0, m2, q3131
4671 mova [t0], m1
4672 mova [t0+16], m0
46774673 RET
46784674
46794675 ;-----------------------------------------------------------------------------
144144 int x264_intra_sad_x9_8x8_avx ( uint8_t *, uint8_t *, uint8_t *, uint16_t *, uint16_t * );
145145 int x264_intra_sad_x9_8x8_avx2 ( uint8_t *, uint8_t *, uint8_t *, uint16_t *, uint16_t * );
146146
147 void x264_pixel_ssd_nv12_core_mmx2( pixel *pixuv1, intptr_t stride1,
148 pixel *pixuv2, intptr_t stride2, int width,
149 int height, uint64_t *ssd_u, uint64_t *ssd_v );
150147 void x264_pixel_ssd_nv12_core_sse2( pixel *pixuv1, intptr_t stride1,
151148 pixel *pixuv2, intptr_t stride2, int width,
152149 int height, uint64_t *ssd_u, uint64_t *ssd_v );
20912091 %endif
20922092
20932093 ;-----------------------------------------------------------------------------
2094 ; void predict_16x16_dc_core( pixel *src, int i_dc_left )
2095 ;-----------------------------------------------------------------------------
2096 %macro PRED16x16_DC_MMX 2
2097 %if HIGH_BIT_DEPTH
2098 mova m0, [r0 - FDEC_STRIDEB+ 0]
2099 paddw m0, [r0 - FDEC_STRIDEB+ 8]
2100 paddw m0, [r0 - FDEC_STRIDEB+16]
2101 paddw m0, [r0 - FDEC_STRIDEB+24]
2102 HADDW m0, m1
2103 paddw m0, %1
2104 psrlw m0, %2
2105 SPLATW m0, m0
2106 STORE16 m0, m0, m0, m0
2107 %else ; !HIGH_BIT_DEPTH
2108 pxor m0, m0
2109 pxor m1, m1
2110 psadbw m0, [r0 - FDEC_STRIDE]
2111 psadbw m1, [r0 - FDEC_STRIDE + 8]
2112 paddusw m0, m1
2113 paddusw m0, %1
2114 psrlw m0, %2 ; dc
2115 pshufw m0, m0, 0
2116 packuswb m0, m0 ; dc in bytes
2117 STORE16 m0, m0
2118 %endif
2119 %endmacro
2120
2121 INIT_MMX mmx2
2122 cglobal predict_16x16_dc_core, 1,2
2123 %if ARCH_X86_64
2124 movd m6, r1d
2125 PRED16x16_DC_MMX m6, 5
2126 %else
2127 PRED16x16_DC_MMX r1m, 5
2128 %endif
2129 RET
2130
2131 INIT_MMX mmx2
2132 cglobal predict_16x16_dc_top, 1,2
2133 PRED16x16_DC_MMX [pw_8], 4
2134 RET
2135
2136 INIT_MMX mmx2
2137 %if HIGH_BIT_DEPTH
2138 cglobal predict_16x16_dc_left_core, 1,2
2139 movd m0, r1m
2140 SPLATW m0, m0
2141 STORE16 m0, m0, m0, m0
2142 RET
2143 %else ; !HIGH_BIT_DEPTH
2144 cglobal predict_16x16_dc_left_core, 1,1
2145 movd m0, r1m
2146 pshufw m0, m0, 0
2147 packuswb m0, m0
2148 STORE16 m0, m0
2149 RET
2150 %endif
2094 ; void predict_16x16_dc( pixel *src )
2095 ;-----------------------------------------------------------------------------
2096 %if WIN64
2097 DECLARE_REG_TMP 6 ; Reduces code size due to fewer REX prefixes
2098 %else
2099 DECLARE_REG_TMP 3
2100 %endif
2101
2102 INIT_XMM
2103 ; Returns the sum of the left pixels in r1d+r2d
2104 cglobal predict_16x16_dc_left_internal, 0,4
2105 movzx r1d, pixel [r0-SIZEOF_PIXEL]
2106 movzx r2d, pixel [r0+FDEC_STRIDEB-SIZEOF_PIXEL]
2107 %assign i 2*FDEC_STRIDEB
2108 %rep 7
2109 movzx t0d, pixel [r0+i-SIZEOF_PIXEL]
2110 add r1d, t0d
2111 movzx t0d, pixel [r0+i+FDEC_STRIDEB-SIZEOF_PIXEL]
2112 add r2d, t0d
2113 %assign i i+2*FDEC_STRIDEB
2114 %endrep
2115 RET
21512116
21522117 %macro PRED16x16_DC 2
21532118 %if HIGH_BIT_DEPTH
21752140 %endif
21762141 %endmacro
21772142
2178 %macro PREDICT_16x16_DC_CORE 0
2179 cglobal predict_16x16_dc_core, 2,2,4
2180 movd xm3, r1m
2143 %macro PREDICT_16x16_DC 0
2144 cglobal predict_16x16_dc, 1,3
2145 call predict_16x16_dc_left_internal
2146 lea r1d, [r1+r2+16]
2147 movd xm3, r1d
21812148 PRED16x16_DC xm3, 5
21822149 RET
21832150
21852152 PRED16x16_DC [pw_8], 4
21862153 RET
21872154
2188 cglobal predict_16x16_dc_left_core, 1,2
2189 movd xm0, r1m
2155 cglobal predict_16x16_dc_left, 1,3
2156 call predict_16x16_dc_left_internal
2157 lea r1d, [r1+r2+8]
2158 shr r1d, 4
2159 movd xm0, r1d
21902160 SPLATW m0, xm0
21912161 %if HIGH_BIT_DEPTH && mmsize == 16
21922162 STORE16 m0, m0
22002170 %endmacro
22012171
22022172 INIT_XMM sse2
2203 PREDICT_16x16_DC_CORE
2173 PREDICT_16x16_DC
22042174 %if HIGH_BIT_DEPTH
22052175 INIT_YMM avx2
2206 PREDICT_16x16_DC_CORE
2176 PREDICT_16x16_DC
22072177 %else
22082178 INIT_XMM avx2
2209 PREDICT_16x16_DC_CORE
2210 %endif
2179 PREDICT_16x16_DC
2180 %endif
2727 #include "common/common.h"
2828 #include "predict.h"
2929 #include "pixel.h"
30
31 #define PREDICT_16x16_DC(name)\
32 void x264_predict_16x16_dc_##name( pixel *src )\
33 {\
34 uint32_t dc = 16;\
35 for( int i = 0; i < 16; i += 2 )\
36 {\
37 dc += src[-1 + i * FDEC_STRIDE];\
38 dc += src[-1 + (i+1) * FDEC_STRIDE];\
39 }\
40 x264_predict_16x16_dc_core_##name( src, dc );\
41 }
42
43 PREDICT_16x16_DC( mmx2 )
44 PREDICT_16x16_DC( sse2 )
45 PREDICT_16x16_DC( avx2 )
46
47 #define PREDICT_16x16_DC_LEFT(name)\
48 static void x264_predict_16x16_dc_left_##name( pixel *src )\
49 {\
50 uint32_t dc = 8;\
51 for( int i = 0; i < 16; i += 2 )\
52 {\
53 dc += src[-1 + i * FDEC_STRIDE];\
54 dc += src[-1 + (i+1) * FDEC_STRIDE];\
55 }\
56 x264_predict_16x16_dc_left_core_##name( src, dc>>4 );\
57 }
58
59 PREDICT_16x16_DC_LEFT( mmx2 )
60 PREDICT_16x16_DC_LEFT( sse2 )
61 PREDICT_16x16_DC_LEFT( avx2 )
6230
6331 #define PREDICT_P_SUM(j,i)\
6432 H += i * ( src[j+i - FDEC_STRIDE ] - src[j-i - FDEC_STRIDE ] );\
346314 {
347315 if( !(cpu&X264_CPU_MMX2) )
348316 return;
349 pf[I_PRED_16x16_DC] = x264_predict_16x16_dc_mmx2;
350 pf[I_PRED_16x16_DC_TOP] = x264_predict_16x16_dc_top_mmx2;
351 pf[I_PRED_16x16_DC_LEFT] = x264_predict_16x16_dc_left_mmx2;
352317 pf[I_PRED_16x16_V] = x264_predict_16x16_v_mmx2;
353318 pf[I_PRED_16x16_H] = x264_predict_16x16_h_mmx2;
354319 #if HIGH_BIT_DEPTH
3939 void x264_predict_16x16_h_sse2( uint16_t *src );
4040 void x264_predict_16x16_h_ssse3( uint8_t *src );
4141 void x264_predict_16x16_h_avx2( uint16_t *src );
42 void x264_predict_16x16_dc_mmx2( pixel *src );
4342 void x264_predict_16x16_dc_sse2( pixel *src );
44 void x264_predict_16x16_dc_core_mmx2( pixel *src, int i_dc_left );
45 void x264_predict_16x16_dc_core_sse2( pixel *src, int i_dc_left );
46 void x264_predict_16x16_dc_core_avx2( pixel *src, int i_dc_left );
47 void x264_predict_16x16_dc_left_core_mmx2( pixel *src, int i_dc_left );
48 void x264_predict_16x16_dc_left_core_sse2( pixel *src, int i_dc_left );
49 void x264_predict_16x16_dc_left_core_avx2( pixel *src, int i_dc_left );
50 void x264_predict_16x16_dc_top_mmx2( pixel *src );
43 void x264_predict_16x16_dc_avx2( pixel *src );
44 void x264_predict_16x16_dc_left_sse2( pixel *src );
45 void x264_predict_16x16_dc_left_avx2( pixel *src );
5146 void x264_predict_16x16_dc_top_sse2( pixel *src );
5247 void x264_predict_16x16_dc_top_avx2( pixel *src );
5348 void x264_predict_16x16_p_core_mmx2( uint8_t *src, int i00, int b, int c );
5252
5353 SECTION_RODATA
5454
55 pd_8: times 4 dd 8
5655 pd_m16: times 4 dd -16
57 pd_0123: dd 0, 1, 2, 3
58 pd_4567: dd 4, 5, 6, 7
5956 sq_1: dq 1, 0
6057 pq_128: times 2 dq 128
6158 pq_ffffffff: times 2 dq 0xffffffff
6259
60 cextern pd_8
61 cextern pd_0123
62 cextern pd_4567
6363 cextern cabac_entropy
6464 cextern cabac_transition
6565 cextern cabac_size_unary
11 # Attempt to guess a canonical system name.
22 # Copyright 1992-2016 Free Software Foundation, Inc.
33
4 timestamp='2016-04-02'
4 timestamp='2016-10-02'
55
66 # This file is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License as published by
185185 *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
186186 esac
187187 # The Operating System including object format, if it has switched
188 # to ELF recently, or will in the future.
188 # to ELF recently (or will in the future) and ABI.
189189 case "${UNAME_MACHINE_ARCH}" in
190 arm*|earm*|i386|m68k|ns32k|sh3*|sparc|vax)
190 earm*)
191 os=netbsdelf
192 ;;
193 arm*|i386|m68k|ns32k|sh3*|sparc|vax)
191194 eval $set_cc_for_build
192195 if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
193196 | grep -q __ELF__
996999 eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
9971000 test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
9981001 ;;
1002 mips64el:Linux:*:*)
1003 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
1004 exit ;;
9991005 openrisc*:Linux:*:*)
10001006 echo or1k-unknown-linux-${LIBC}
10011007 exit ;;
10271033 exit ;;
10281034 ppcle:Linux:*:*)
10291035 echo powerpcle-unknown-linux-${LIBC}
1036 exit ;;
1037 riscv32:Linux:*:* | riscv64:Linux:*:*)
1038 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
10301039 exit ;;
10311040 s390:Linux:*:* | s390x:Linux:*:*)
10321041 echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
14071416 cat >&2 <<EOF
14081417 $0: unable to guess system type
14091418
1410 This script, last modified $timestamp, has failed to recognize
1411 the operating system you are using. It is advised that you
1412 download the most up to date version of the config scripts from
1419 This script (version $timestamp), has failed to recognize the
1420 operating system you are using. If your script is old, overwrite
1421 config.guess and config.sub with the latest versions from:
14131422
14141423 http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
14151424 and
14161425 http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
14171426
1418 If the version you run ($0) is already up to date, please
1419 send the following data and any information you think might be
1420 pertinent to <config-patches@gnu.org> in order to provide the needed
1421 information to handle your system.
1427 If $0 has already been updated, send the following data and any
1428 information you think might be pertinent to config-patches@gnu.org to
1429 provide the necessary information to handle your system.
14221430
14231431 config.guess timestamp = $timestamp
14241432
11 # Configuration validation subroutine script.
22 # Copyright 1992-2016 Free Software Foundation, Inc.
33
4 timestamp='2016-03-30'
4 timestamp='2016-11-04'
55
66 # This file is free software; you can redistribute it and/or modify it
77 # under the terms of the GNU General Public License as published by
116116 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
117117 linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
118118 knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
119 kopensolaris*-gnu* | \
119 kopensolaris*-gnu* | cloudabi*-eabi* | \
120120 storm-chaos* | os2-emx* | rtmk-nova*)
121121 os=-$maybe_os
122122 basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
300300 | open8 | or1k | or1knd | or32 \
301301 | pdp10 | pdp11 | pj | pjl \
302302 | powerpc | powerpc64 | powerpc64le | powerpcle \
303 | pru \
303304 | pyramid \
304305 | riscv32 | riscv64 \
305306 | rl78 | rx \
427428 | orion-* \
428429 | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
429430 | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
431 | pru-* \
430432 | pyramid-* \
431433 | riscv32-* | riscv64-* \
432434 | rl78-* | romp-* | rs6000-* | rx-* \
642644 basic_machine=m68k-bull
643645 os=-sysv3
644646 ;;
647 e500v[12])
648 basic_machine=powerpc-unknown
649 os=$os"spe"
650 ;;
651 e500v[12]-*)
652 basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
653 os=$os"spe"
654 ;;
645655 ebmon29k)
646656 basic_machine=a29k-amd
647657 os=-ebmon
10211031 ppc-* | ppcbe-*)
10221032 basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
10231033 ;;
1024 ppcle | powerpclittle | ppc-le | powerpc-little)
1034 ppcle | powerpclittle)
10251035 basic_machine=powerpcle-unknown
10261036 ;;
10271037 ppcle-* | powerpclittle-*)
10311041 ;;
10321042 ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
10331043 ;;
1034 ppc64le | powerpc64little | ppc64-le | powerpc64-little)
1044 ppc64le | powerpc64little)
10351045 basic_machine=powerpc64le-unknown
10361046 ;;
10371047 ppc64le-* | powerpc64little-*)
13881398 | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
13891399 | -chorusos* | -chorusrdb* | -cegcc* \
13901400 | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1391 | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
1401 | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
13921402 | -linux-newlib* | -linux-musl* | -linux-uclibc* \
13931403 | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
13941404 | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
13981408 | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
13991409 | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
14001410 | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
1401 | -onefs* | -tirtos*)
1411 | -onefs* | -tirtos* | -phoenix* | -fuchsia*)
14021412 # Remember, each alternative MUST END IN *, to match a version number.
14031413 ;;
14041414 -qnx*)
862862 x264_cabac_encode_bypass( cb, 0 ); // sign
863863 }
864864
865 for( int i = last-1 ; i >= 0; i-- )
865 for( int i = last-1; i >= 0; i-- )
866866 {
867867 if( l[i] )
868868 {
707707 }
708708 for( int p = 0; p < plane_count; p++, i_qp = h->mb.i_chroma_qp )
709709 {
710 for( int i = (p == 0 && h->mb.i_skip_intra) ? 3 : 0 ; i < 4; i++ )
710 for( int i = (p == 0 && h->mb.i_skip_intra) ? 3 : 0; i < 4; i++ )
711711 {
712712 int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]];
713713 x264_mb_encode_i8x8( h, p, i, i_qp, i_mode, NULL, 1 );
732732 }
733733 for( int p = 0; p < plane_count; p++, i_qp = h->mb.i_chroma_qp )
734734 {
735 for( int i = (p == 0 && h->mb.i_skip_intra) ? 15 : 0 ; i < 16; i++ )
735 for( int i = (p == 0 && h->mb.i_skip_intra) ? 15 : 0; i < 16; i++ )
736736 {
737737 pixel *p_dst = &h->mb.pic.p_fdec[p][block_idx_xy_fdec[i]];
738738 int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
785785 x264_reduce_fraction64( &num, &denom );
786786 rc->hrd_multiply_denom = 90000 / num;
787787
788 double bits_required = log2( 90000 / rc->hrd_multiply_denom )
788 double bits_required = log2( num )
789789 + log2( h->sps->vui.i_time_scale )
790790 + log2( h->sps->vui.hrd.i_cpb_size_unscaled );
791791 if( bits_required >= 63 )
136136 sps->i_level_idc = 11;
137137 }
138138 /* Intra profiles */
139 if( param->i_keyint_max == 1 && sps->i_profile_idc > PROFILE_HIGH )
139 if( param->i_keyint_max == 1 && sps->i_profile_idc >= PROFILE_HIGH )
140140 sps->b_constraint_set3 = 1;
141141
142142 sps->vui.i_num_reorder_frames = param->i_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0;
237237
238238 // NOTE: HRD related parts of the SPS are initialised in x264_ratecontrol_init_reconfigurable
239239
240 sps->vui.b_bitstream_restriction = param->i_keyint_max > 1;
240 sps->vui.b_bitstream_restriction = !(sps->b_constraint_set3 && sps->i_profile_idc >= PROFILE_HIGH);
241241 if( sps->vui.b_bitstream_restriction )
242242 {
243243 sps->vui.b_motion_vectors_over_pic_boundaries = 1;
5353 #define AVSC_INLINE static __inline
5454
5555 #ifdef AVISYNTH_C_EXPORTS
56 # define AVSC_EXPORT EXTERN_C
57 # define AVSC_API(ret, name) EXTERN_C __declspec(dllexport) ret AVSC_CC name
56 # define AVSC_EXPORT __declspec(dllexport)
57 # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
5858 #else
59 # define AVSC_EXPORT EXTERN_C __declspec(dllexport)
59 # define AVSC_EXPORT __declspec(dllimport)
6060 # ifndef AVSC_NO_DECLSPEC
61 # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name
61 # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
6262 # else
6363 # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
6464 # endif
7777 // Constants
7878 //
7979
80 #ifndef __AVISYNTH_H__
81 enum { AVISYNTH_INTERFACE_VERSION = 4 };
80 #ifndef __AVISYNTH_6_H__
81 enum { AVISYNTH_INTERFACE_VERSION = 6 };
8282 #endif
8383
8484 enum {AVS_SAMPLE_INT8 = 1<<0,
85 AVS_SAMPLE_INT16 = 1<<1,
85 AVS_SAMPLE_INT16 = 1<<1,
8686 AVS_SAMPLE_INT24 = 1<<2,
8787 AVS_SAMPLE_INT32 = 1<<3,
8888 AVS_SAMPLE_FLOAT = 1<<4};
108108 AVS_CS_YUV = 1<<29,
109109 AVS_CS_INTERLEAVED = 1<<30,
110110 AVS_CS_PLANAR = 1<<31,
111
111
112112 AVS_CS_SHIFT_SUB_WIDTH = 0,
113 AVS_CS_SHIFT_SUB_HEIGHT = 1 << 3,
114 AVS_CS_SHIFT_SAMPLE_BITS = 1 << 4,
113 AVS_CS_SHIFT_SUB_HEIGHT = 8,
114 AVS_CS_SHIFT_SAMPLE_BITS = 16,
115115
116116 AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
117117 AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
178178 AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
179179
180180 enum {
181 AVS_CACHE_NOTHING=0,
182 AVS_CACHE_RANGE=1,
183 AVS_CACHE_ALL=2,
184 AVS_CACHE_AUDIO=3,
185 AVS_CACHE_AUDIO_NONE=4,
186 AVS_CACHE_AUDIO_AUTO=5
181 // 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)
187231 };
188232
189 #define AVS_FRAME_ALIGN 16
233 #define AVS_FRAME_ALIGN 16
190234
191235 typedef struct AVS_Clip AVS_Clip;
192236 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
203247 int num_frames;
204248
205249 int pixel_type;
206
250
207251 int audio_samples_per_second; // 0 means no audio
208252 int sample_type;
209253 INT64 num_audio_samples;
215259 } AVS_VideoInfo;
216260
217261 // useful functions of the above
218 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
262 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
219263 { return (p->width!=0); }
220264
221 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
265 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
222266 { return (p->audio_samples_per_second!=0); }
223267
224 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
268 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
225269 { return !!(p->pixel_type&AVS_CS_BGR); }
226270
227 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
228 { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
229
230 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
231 { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
232
233 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
271 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
272 { return ((p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
273
274 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
275 { return ((p->pixel_type&AVS_CS_BGR32)==AVS_CS_BGR32) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
276
277 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
234278 { return !!(p->pixel_type&AVS_CS_YUV ); }
235279
236 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
237 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
238
280 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
281 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
282
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);
288
289 AVSC_API(int, avs_is_yv411)(const AVS_VideoInfo * p);
290
291 AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p);
292
293 #ifdef AVSC_NO_DECLSPEC
239294 AVSC_INLINE int avs_is_yv24(const AVS_VideoInfo * p)
240295 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV24 & AVS_CS_PLANAR_FILTER); }
241296
242297 AVSC_INLINE int avs_is_yv16(const AVS_VideoInfo * p)
243298 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV16 & AVS_CS_PLANAR_FILTER); }
244299
245 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
300 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
246301 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV12 & AVS_CS_PLANAR_FILTER); }
247302
248303 AVSC_INLINE int avs_is_yv411(const AVS_VideoInfo * p)
249304 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV411 & AVS_CS_PLANAR_FILTER); }
250
305
251306 AVSC_INLINE int avs_is_y8(const AVS_VideoInfo * p)
252307 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_Y8 & AVS_CS_PLANAR_FILTER); }
253
254 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
255 { return ((p->pixel_type & property)==property ); }
256
257 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
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
352 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
353 { return ((p->image_type & property)==property ); }
354
355 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
258356 { return !!(p->pixel_type & AVS_CS_PLANAR); }
259357
260 AVSC_INLINE int avs_is_color_space(const AVS_VideoInfo * p, int c_space)
261 { return avs_is_planar(p) ? ((p->pixel_type & AVS_CS_PLANAR_MASK) == (c_space & AVS_CS_PLANAR_FILTER)) : ((p->pixel_type & c_space) == c_space); }
262
263 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
358 AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
359
360 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
264361 { return !!(p->image_type & AVS_IT_FIELDBASED); }
265362
266 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
363 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
267364 { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
268365
269 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
366 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
270367 { return !!(p->image_type & AVS_IT_BFF); }
271368
272 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
369 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
273370 { return !!(p->image_type & AVS_IT_TFF); }
274371
275 AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo * p)
276 {
277 switch (p->pixel_type) {
278 case AVS_CS_BGR24: return 24;
279 case AVS_CS_BGR32: return 32;
280 case AVS_CS_YUY2: return 16;
281 case AVS_CS_YV12:
282 case AVS_CS_I420: return 12;
283 default: return 0;
284 }
285 }
286 AVSC_INLINE int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels)
287 { return pixels * (avs_bits_per_pixel(p)>>3); } // Will work on planar images, but will return only luma planes
288
289 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p)
290 { return avs_bytes_from_pixels(p,p->width); } // Also only returns first plane on planar images
291
292 AVSC_INLINE int avs_bmp_size(const AVS_VideoInfo * vi)
293 { 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); }
294
295 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
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);
389
390 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
296391 { return p->audio_samples_per_second; }
297392
298393
299 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
394 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
300395 {
301396 switch (p->sample_type) {
302397 case AVS_SAMPLE_INT8: return sizeof(signed char);
307402 default: return 0;
308403 }
309404 }
310 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
405 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
311406 { return p->nchannels*avs_bytes_per_channel_sample(p);}
312407
313 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
408 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
314409 { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
315410
316 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
411 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
317412 { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
318413
319 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
414 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
320415 { return bytes / avs_bytes_per_audio_sample(p); }
321416
322 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
417 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
323418 { return samples * avs_bytes_per_audio_sample(p); }
324419
325 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
420 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
326421 { return p->nchannels; }
327422
328423 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
329424 { return p->sample_type;}
330425
331426 // useful mutator
332 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
427 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
333428 { p->image_type|=property; }
334429
335 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
430 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
336431 { p->image_type&=~property; }
337432
338 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
433 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
339434 { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
340435
341 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
436 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
342437 {
343438 unsigned x=numerator, y=denominator;
344439 while (y) { // find gcd
389484 } AVS_VideoFrame;
390485
391486 // Access functions for AVS_VideoFrame
487 AVSC_API(int, avs_get_pitch_p)(const AVS_VideoFrame * p, int plane);
488
489 #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
392500 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
393 return p->pitch;}
394
395 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) {
396 switch (plane) {
397 case AVS_PLANAR_U: case AVS_PLANAR_V: return p->pitchUV;}
398 return p->pitch;}
501 return avs_get_pitch_p(p, 0);}
502
503 AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
399504
400505 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
401506 return p->row_size; }
402507
403 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane) {
404 int r;
405 switch (plane) {
406 case AVS_PLANAR_U: case AVS_PLANAR_V:
407 if (p->pitchUV) return p->row_sizeUV;
408 else return 0;
409 case AVS_PLANAR_U_ALIGNED: case AVS_PLANAR_V_ALIGNED:
410 if (p->pitchUV) {
411 r = (p->row_sizeUV+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
412 if (r < p->pitchUV)
413 return r;
414 return p->row_sizeUV;
415 } else return 0;
416 case AVS_PLANAR_Y_ALIGNED:
417 r = (p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
418 if (r <= p->pitch)
419 return r;
420 return p->row_size;
421 }
422 return p->row_size;
423 }
508 AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
424509
425510 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
426511 return p->height;}
427512
428 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane) {
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) {
429517 switch (plane) {
430 case AVS_PLANAR_U: case AVS_PLANAR_V:
431 if (p->pitchUV) return p->heightUV;
432 return 0;
433 }
434 return p->height;}
435
436 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
437 return p->vfb->data + p->offset;}
438
439 AVSC_INLINE const BYTE* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
440 {
441 switch (plane) {
442 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
443 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
444 default: return p->vfb->data + p->offset;}
445 }
446
447 AVSC_INLINE int avs_is_writable(const AVS_VideoFrame * p) {
448 return (p->refcount == 1 && p->vfb->refcount == 1);}
449
450 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p)
451 {
452 if (avs_is_writable(p)) {
453 ++p->vfb->sequence_number;
454 return p->vfb->data + p->offset;
455 } else
456 return 0;
457 }
458
459 AVSC_INLINE BYTE* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane)
460 {
461 if (plane==AVS_PLANAR_Y && avs_is_writable(p)) {
462 ++p->vfb->sequence_number;
463 return p->vfb->data + p->offset;
464 } else if (plane==AVS_PLANAR_Y) {
465 return 0;
466 } else {
467 switch (plane) {
468 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
469 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
470 default: return p->vfb->data + p->offset;
471 }
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;
472521 }
473522 }
474
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);}
527
528 AVSC_API(int, avs_is_writable)(const AVS_VideoFrame * p);
529
530 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
475536
476537 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
477538 // makes a shallow copy of a video frame
534595 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
535596 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
536597
537 AVSC_INLINE int avs_as_bool(AVS_Value v)
538 { return v.d.boolean; }
539 AVSC_INLINE int avs_as_int(AVS_Value v)
540 { return v.d.integer; }
541 AVSC_INLINE const char * avs_as_string(AVS_Value v)
598 AVSC_INLINE int avs_as_bool(AVS_Value v)
599 { return v.d.boolean; }
600 AVSC_INLINE int avs_as_int(AVS_Value v)
601 { return v.d.integer; }
602 AVSC_INLINE const char * avs_as_string(AVS_Value v)
542603 { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
543 AVSC_INLINE double avs_as_float(AVS_Value v)
604 AVSC_INLINE double avs_as_float(AVS_Value v)
544605 { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
545 AVSC_INLINE const char * avs_as_error(AVS_Value v)
606 AVSC_INLINE const char * avs_as_error(AVS_Value v)
546607 { return avs_is_error(v) ? v.d.string : 0; }
547608 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
548609 { return v.d.array; }
549 AVSC_INLINE int avs_array_size(AVS_Value v)
610 AVSC_INLINE int avs_array_size(AVS_Value v)
550611 { return avs_is_array(v) ? v.array_size : 1; }
551 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
612 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
552613 { return avs_is_array(v) ? v.d.array[index] : v; }
553614
554615 // only use these functions on an AVS_Value that does not already have
555616 // an active value. Remember, treat AVS_Value as a fat pointer.
556 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
557 { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
558 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
559 { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
560 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
617 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
618 { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
619 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
620 { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
621 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
561622 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
562 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
623 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
563624 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
564 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
625 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
565626 { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
566627 #ifndef AVSC_NO_DECLSPEC
567628 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
568629 { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
569630 #endif
570631 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
571 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
632 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = (short)size; return v; }
572633
573634 /////////////////////////////////////////////////////////////////////
574635 //
583644 AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
584645
585646 AVSC_API(int, avs_get_version)(AVS_Clip *);
586
647
587648 AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
588649 // The returned video frame must be released with avs_release_video_frame
589650
590 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
651 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
591652 // return field parity if field_based, else parity of first field in frame
592653
593 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
594 INT64 start, INT64 count);
654 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
655 INT64 start, INT64 count);
595656 // start and count are in samples
596657
597 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
658 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
598659 int cachehints, int frame_range);
599660
600661 // This is the callback type used by avs_add_function
610671 AVS_ScriptEnvironment * env;
611672 AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
612673 int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
613 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
674 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
614675 INT64 start, INT64 count);
615 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
676 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
616677 int frame_range);
617678 void (AVSC_CC * free_filter)(AVS_FilterInfo *);
618
679
619680 // Should be set when ever there is an error to report.
620681 // It is cleared before any of the above methods are called
621682 const char * error;
640701 //
641702
642703 // For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
643 enum {
704 enum {
644705 /* slowest CPU to support extension */
645706 AVS_CPU_FORCE = 0x01, // N/A
646707 AVS_CPU_FPU = 0x02, // 386/486DX
650711 AVS_CPU_SSE2 = 0x20, // PIV, Hammer
651712 AVS_CPU_3DNOW = 0x40, // K6-2
652713 AVS_CPU_3DNOW_EXT = 0x80, // Athlon
653 AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
714 AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
654715 // which only Hammer will have anyway)
655716 AVS_CPUF_SSE3 = 0x100, // PIV+, K8 Venice
656717 AVS_CPUF_SSSE3 = 0x200, // Core 2
657718 AVS_CPUF_SSE4 = 0x400, // Penryn, Wolfdale, Yorkfield
658719 AVS_CPUF_SSE4_1 = 0x400,
659 AVS_CPUF_SSE4_2 = 0x800, // Nehalem
720 //AVS_CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
721 AVS_CPUF_SSE4_2 = 0x1000, // Nehalem
722 //AVS_CPUF_AVX2 = 0x2000, // Haswell
723 //AVS_CPUF_AVX512 = 0x4000, // Knights Landing
660724 };
725
661726
662727 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
663728
670735 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, void* val);
671736 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
672737
673 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
674 const char * name, const char * params,
738 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
739 const char * name, const char * params,
675740 AVS_ApplyFunc apply, void * user_data);
676741
677742 AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
678743
679 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
744 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
680745 AVS_Value args, const char** arg_names);
681746 // The returned value must be be released with avs_release_value
682747
690755 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
691756 //void avs_pop_context(AVS_ScriptEnvironment *);
692757
693 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
758 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
694759 const AVS_VideoInfo * vi, int align);
695760 // align should be at least 16
696761
697762 #ifndef AVSC_NO_DECLSPEC
698 AVSC_INLINE
699 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
763 AVSC_INLINE
764 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
700765 const AVS_VideoInfo * vi)
701766 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
702767
703 AVSC_INLINE
704 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
768 AVSC_INLINE
769 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
705770 const AVS_VideoInfo * vi)
706771 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
707772 #endif
771836 AVSC_DECLARE_FUNC(avs_function_exists);
772837 AVSC_DECLARE_FUNC(avs_get_audio);
773838 AVSC_DECLARE_FUNC(avs_get_cpu_flags);
774 AVSC_DECLARE_FUNC(avs_get_error);
775839 AVSC_DECLARE_FUNC(avs_get_frame);
776840 AVSC_DECLARE_FUNC(avs_get_parity);
777841 AVSC_DECLARE_FUNC(avs_get_var);
796860 AVSC_DECLARE_FUNC(avs_subframe_planar);
797861 AVSC_DECLARE_FUNC(avs_take_clip);
798862 AVSC_DECLARE_FUNC(avs_vsprintf);
863
864 AVSC_DECLARE_FUNC(avs_get_error);
865 AVSC_DECLARE_FUNC(avs_is_yv24);
866 AVSC_DECLARE_FUNC(avs_is_yv16);
867 AVSC_DECLARE_FUNC(avs_is_yv12);
868 AVSC_DECLARE_FUNC(avs_is_yv411);
869 AVSC_DECLARE_FUNC(avs_is_y8);
870 AVSC_DECLARE_FUNC(avs_is_color_space);
871
872 AVSC_DECLARE_FUNC(avs_get_plane_width_subsampling);
873 AVSC_DECLARE_FUNC(avs_get_plane_height_subsampling);
874 AVSC_DECLARE_FUNC(avs_bits_per_pixel);
875 AVSC_DECLARE_FUNC(avs_bytes_from_pixels);
876 AVSC_DECLARE_FUNC(avs_row_size_p);
877 AVSC_DECLARE_FUNC(avs_bmp_size);
878 AVSC_DECLARE_FUNC(avs_get_pitch_p);
879 AVSC_DECLARE_FUNC(avs_get_row_size_p);
880 AVSC_DECLARE_FUNC(avs_get_height_p);
881 AVSC_DECLARE_FUNC(avs_get_read_ptr_p);
882 AVSC_DECLARE_FUNC(avs_is_writable);
883 AVSC_DECLARE_FUNC(avs_get_write_ptr_p);
799884 };
800885
801886 #undef AVSC_DECLARE_FUNC
830915 AVSC_LOAD_FUNC(avs_function_exists);
831916 AVSC_LOAD_FUNC(avs_get_audio);
832917 AVSC_LOAD_FUNC(avs_get_cpu_flags);
833 AVSC_LOAD_FUNC(avs_get_error);
834918 AVSC_LOAD_FUNC(avs_get_frame);
835919 AVSC_LOAD_FUNC(avs_get_parity);
836920 AVSC_LOAD_FUNC(avs_get_var);
856940 AVSC_LOAD_FUNC(avs_take_clip);
857941 AVSC_LOAD_FUNC(avs_vsprintf);
858942
943 AVSC_LOAD_FUNC(avs_get_error);
944 AVSC_LOAD_FUNC(avs_is_yv24);
945 AVSC_LOAD_FUNC(avs_is_yv16);
946 AVSC_LOAD_FUNC(avs_is_yv12);
947 AVSC_LOAD_FUNC(avs_is_yv411);
948 AVSC_LOAD_FUNC(avs_is_y8);
949 AVSC_LOAD_FUNC(avs_is_color_space);
950
951 AVSC_LOAD_FUNC(avs_get_plane_width_subsampling);
952 AVSC_LOAD_FUNC(avs_get_plane_height_subsampling);
953 AVSC_LOAD_FUNC(avs_bits_per_pixel);
954 AVSC_LOAD_FUNC(avs_bytes_from_pixels);
955 AVSC_LOAD_FUNC(avs_row_size_p);
956 AVSC_LOAD_FUNC(avs_bmp_size);
957 AVSC_LOAD_FUNC(avs_get_pitch_p);
958 AVSC_LOAD_FUNC(avs_get_row_size_p);
959 AVSC_LOAD_FUNC(avs_get_height_p);
960 AVSC_LOAD_FUNC(avs_get_read_ptr_p);
961 AVSC_LOAD_FUNC(avs_is_writable);
962 AVSC_LOAD_FUNC(avs_get_write_ptr_p);
963
859964 #undef __AVSC_STRINGIFY
860965 #undef AVSC_STRINGIFY
861966 #undef AVSC_LOAD_FUNC
4747 while( *option && (strlen( *option ) != length || strncmp( opt, *option, length )) )
4848 option++;
4949
50 RETURN_IF_ERROR( !*option, "Invalid option '%.*s'\n", length, opt )
50 RETURN_IF_ERROR( !*option, "Invalid option '%.*s'\n", length, opt );
5151 found_named = 1;
5252 length += strcspn( opt + length, "," );
5353 }
5454 else
5555 {
56 RETURN_IF_ERROR( opt_count >= options_count, "Too many options given\n" )
57 RETURN_IF_ERROR( found_named, "Ordered option given after named\n" )
56 RETURN_IF_ERROR( opt_count >= options_count, "Too many options given\n" );
57 RETURN_IF_ERROR( found_named, "Ordered option given after named\n" );
5858 size += strlen( options[opt_count] ) + 1;
5959 }
6060 opt_count++;
6464 int offset = 2 * (opt_count+1) * sizeof(char*);
6565 size += offset + (opt - opt_str);
6666 char **opts = calloc( 1, size );
67 RETURN_IF_ERROR( !opts, "malloc failed\n" )
67 RETURN_IF_ERROR( !opts, "malloc failed\n" );
6868
6969 #define insert_opt( src, length )\
7070 do {\
5151 for( int i = 0; i < 4; i++ )
5252 {
5353 char *opt = x264_get_option( optlist[i], opts );
54 FAIL_IF_ERROR( !opt, "%s crop value not specified\n", optlist[i] )
54 FAIL_IF_ERROR( !opt, "%s crop value not specified\n", optlist[i] );
5555 h->dims[i] = x264_otoi( opt, -1 );
56 FAIL_IF_ERROR( h->dims[i] < 0, "%s crop value `%s' is less than 0\n", optlist[i], opt )
56 FAIL_IF_ERROR( h->dims[i] < 0, "%s crop value `%s' is less than 0\n", optlist[i], opt );
5757 int dim_mod = i&1 ? (h->csp->mod_height << info->interlaced) : h->csp->mod_width;
58 FAIL_IF_ERROR( h->dims[i] % dim_mod, "%s crop value `%s' is not a multiple of %d\n", optlist[i], opt, dim_mod )
58 FAIL_IF_ERROR( h->dims[i] % dim_mod, "%s crop value `%s' is not a multiple of %d\n", optlist[i], opt, dim_mod );
5959 }
6060 return 0;
6161 }
6262
6363 static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )
6464 {
65 FAIL_IF_ERROR( x264_cli_csp_is_invalid( info->csp ), "invalid csp %d\n", info->csp )
65 FAIL_IF_ERROR( x264_cli_csp_is_invalid( info->csp ), "invalid csp %d\n", info->csp );
6666 crop_hnd_t *h = calloc( 1, sizeof(crop_hnd_t) );
6767 if( !h )
6868 return -1;
8080
8181 h->dims[2] = info->width - h->dims[0] - h->dims[2];
8282 h->dims[3] = info->height - h->dims[1] - h->dims[3];
83 FAIL_IF_ERROR( h->dims[2] <= 0 || h->dims[3] <= 0, "invalid output resolution %dx%d\n", h->dims[2], h->dims[3] )
83 FAIL_IF_ERROR( h->dims[2] <= 0 || h->dims[3] <= 0, "invalid output resolution %dx%d\n", h->dims[2], h->dims[3] );
8484
8585 if( info->width != h->dims[2] || info->height != h->dims[3] )
8686 x264_cli_log( NAME, X264_LOG_INFO, "cropping to %dx%d\n", h->dims[2], h->dims[3] );
216216 ret = 1;
217217 }
218218
219 FAIL_IF_ERROR( bit_depth != X264_BIT_DEPTH, "this build supports only bit depth %d\n", X264_BIT_DEPTH )
220 FAIL_IF_ERROR( ret, "unsupported bit depth conversion.\n" )
219 FAIL_IF_ERROR( bit_depth != X264_BIT_DEPTH, "this build supports only bit depth %d\n", X264_BIT_DEPTH );
220 FAIL_IF_ERROR( ret, "unsupported bit depth conversion.\n" );
221221
222222 /* only add the filter to the chain if it's needed */
223223 if( change_fmt || bit_depth != 8 * x264_cli_csp_depth_factor( csp ) )
224224 {
225 FAIL_IF_ERROR( !depth_filter_csp_is_supported(csp), "unsupported colorspace.\n" )
225 FAIL_IF_ERROR( !depth_filter_csp_is_supported(csp), "unsupported colorspace.\n" );
226226 depth_hnd_t *h = x264_malloc( sizeof(depth_hnd_t) + (info->width+1)*sizeof(int16_t) );
227227
228228 if( !h )
3838 int x264_cli_pic_copy( cli_pic_t *out, cli_pic_t *in )
3939 {
4040 int csp = in->img.csp & X264_CSP_MASK;
41 FAIL_IF_ERROR( x264_cli_csp_is_invalid( in->img.csp ), "invalid colorspace arg %d\n", in->img.csp )
41 FAIL_IF_ERROR( x264_cli_csp_is_invalid( in->img.csp ), "invalid colorspace arg %d\n", in->img.csp );
4242 FAIL_IF_ERROR( in->img.csp != out->img.csp || in->img.height != out->img.height
4343 || in->img.width != out->img.width, "incompatible frame properties\n" );
4444 /* copy data */
264264 {
265265 FAIL_IF_ERROR( 2 != sscanf( str_sar, "%u:%u", &out_sar_w, &out_sar_h ) &&
266266 2 != sscanf( str_sar, "%u/%u", &out_sar_w, &out_sar_h ),
267 "invalid sar `%s'\n", str_sar )
267 "invalid sar `%s'\n", str_sar );
268268 }
269269 else
270270 out_sar_w = out_sar_h = 1;
274274 if( !strcasecmp( fittobox, "both" ) )
275275 {
276276 FAIL_IF_ERROR( width <= 0 || height <= 0, "invalid box resolution %sx%s\n",
277 x264_otos( str_width, "<unset>" ), x264_otos( str_height, "<unset>" ) )
277 x264_otos( str_width, "<unset>" ), x264_otos( str_height, "<unset>" ) );
278278 }
279279 else if( !strcasecmp( fittobox, "width" ) )
280280 {
281 FAIL_IF_ERROR( width <= 0, "invalid box width `%s'\n", x264_otos( str_width, "<unset>" ) )
281 FAIL_IF_ERROR( width <= 0, "invalid box width `%s'\n", x264_otos( str_width, "<unset>" ) );
282282 height = INT_MAX;
283283 }
284284 else if( !strcasecmp( fittobox, "height" ) )
285285 {
286 FAIL_IF_ERROR( height <= 0, "invalid box height `%s'\n", x264_otos( str_height, "<unset>" ) )
286 FAIL_IF_ERROR( height <= 0, "invalid box height `%s'\n", x264_otos( str_height, "<unset>" ) );
287287 width = INT_MAX;
288288 }
289 else FAIL_IF_ERROR( 1, "invalid fittobox mode `%s'\n", fittobox )
289 else FAIL_IF_ERROR( 1, "invalid fittobox mode `%s'\n", fittobox );
290290
291291 /* maximally fit the new coded resolution to the box */
292292 const x264_cli_csp_t *csp = x264_cli_get_csp( h->dst_csp );
312312 if( str_width || str_height )
313313 {
314314 FAIL_IF_ERROR( width <= 0 || height <= 0, "invalid resolution %sx%s\n",
315 x264_otos( str_width, "<unset>" ), x264_otos( str_height, "<unset>" ) )
315 x264_otos( str_width, "<unset>" ), x264_otos( str_height, "<unset>" ) );
316316 if( !str_sar ) /* res only -> adjust sar */
317317 {
318318 /* new_sar = (new_h * old_w * old_sar_w) / (old_h * new_w * old_sar_h) */
402402 return -1;
403403 h->buffer_allocated = 1;
404404 }
405 FAIL_IF_ERROR( x264_init_sws_context( h ), "swscale init failed\n" )
405 FAIL_IF_ERROR( x264_init_sws_context( h ), "swscale init failed\n" );
406406 return 0;
407407 }
408408
439439 h->variable_input = 1;
440440 h->dst_csp = pick_closest_supported_csp( info->csp );
441441 FAIL_IF_ERROR( h->dst_csp == X264_CSP_NONE,
442 "filter get invalid input pixel format %d (colorspace %d)\n", convert_csp_to_pix_fmt( info->csp ), info->csp )
442 "filter get invalid input pixel format %d (colorspace %d)\n", convert_csp_to_pix_fmt( info->csp ), info->csp );
443443 }
444444 else
445445 {
478478 FAIL_IF_ERROR( src_pix_fmt == AV_PIX_FMT_NONE && src_pix_fmt_inv != AV_PIX_FMT_NONE,
479479 "input colorspace %s with bit depth %d is not supported\n", av_get_pix_fmt_name( src_pix_fmt_inv ),
480480 info->csp & X264_CSP_HIGH_DEPTH ? 16 : 8 );
481 FAIL_IF_ERROR( !sws_isSupportedInput( src_pix_fmt ), "input colorspace %s is not supported\n", av_get_pix_fmt_name( src_pix_fmt ) )
481 FAIL_IF_ERROR( !sws_isSupportedInput( src_pix_fmt ), "input colorspace %s is not supported\n", av_get_pix_fmt_name( src_pix_fmt ) );
482482 FAIL_IF_ERROR( h->dst.pix_fmt == AV_PIX_FMT_NONE && dst_pix_fmt_inv != AV_PIX_FMT_NONE,
483483 "input colorspace %s with bit depth %d is not supported\n", av_get_pix_fmt_name( dst_pix_fmt_inv ),
484484 h->dst_csp & X264_CSP_HIGH_DEPTH ? 16 : 8 );
485 FAIL_IF_ERROR( !sws_isSupportedOutput( h->dst.pix_fmt ), "output colorspace %s is not supported\n", av_get_pix_fmt_name( h->dst.pix_fmt ) )
485 FAIL_IF_ERROR( !sws_isSupportedOutput( h->dst.pix_fmt ), "output colorspace %s is not supported\n", av_get_pix_fmt_name( h->dst.pix_fmt ) );
486486 FAIL_IF_ERROR( h->dst.height != info->height && info->interlaced,
487 "swscale is not compatible with interlaced vertical resizing\n" )
487 "swscale is not compatible with interlaced vertical resizing\n" );
488488 /* confirm that the desired resolution meets the colorspace requirements */
489489 const x264_cli_csp_t *csp = x264_cli_get_csp( h->dst_csp );
490490 FAIL_IF_ERROR( h->dst.width % csp->mod_width || h->dst.height % csp->mod_height,
491 "resolution %dx%d is not compliant with colorspace %s\n", h->dst.width, h->dst.height, csp->name )
491 "resolution %dx%d is not compliant with colorspace %s\n", h->dst.width, h->dst.height, csp->name );
492492
493493 if( h->dst.width != info->width || h->dst.height != info->height )
494494 x264_cli_log( NAME, X264_LOG_INFO, "resizing to %dx%d\n", h->dst.width, h->dst.height );
579579 }
580580
581581 /* pass if nothing needs to be done, otherwise fail */
582 FAIL_IF_ERROR( ret, "not compiled with swscale support\n" )
582 FAIL_IF_ERROR( ret, "not compiled with swscale support\n" );
583583 return 0;
584584 }
585585
6666 int val = x264_otoi( tok, -1 );
6767 if( p )
6868 {
69 FAIL_IF_ERROR( val <= 0, "invalid step `%s'\n", tok )
69 FAIL_IF_ERROR( val <= 0, "invalid step `%s'\n", tok );
7070 h->step_size = val;
7171 continue;
7272 }
73 FAIL_IF_ERROR( val < 0 || val >= h->step_size, "invalid offset `%s'\n", tok )
74 FAIL_IF_ERROR( h->pattern_len >= MAX_PATTERN_SIZE, "max pattern size %d reached\n", MAX_PATTERN_SIZE )
73 FAIL_IF_ERROR( val < 0 || val >= h->step_size, "invalid offset `%s'\n", tok );
74 FAIL_IF_ERROR( h->pattern_len >= MAX_PATTERN_SIZE, "max pattern size %d reached\n", MAX_PATTERN_SIZE );
7575 offsets[h->pattern_len++] = val;
7676 }
77 FAIL_IF_ERROR( !h->step_size, "no step size provided\n" )
78 FAIL_IF_ERROR( !h->pattern_len, "no offsets supplied\n" )
77 FAIL_IF_ERROR( !h->step_size, "no step size provided\n" );
78 FAIL_IF_ERROR( !h->pattern_len, "no offsets supplied\n" );
7979
8080 h->pattern = malloc( h->pattern_len * sizeof(int) );
8181 if( !h->pattern )
33 * Copyright (C) 2009-2016 x264 project
44 *
55 * Authors: Steven Walters <kemuri9@gmail.com>
6 * Anton Mitrofanov <BugMaster@narod.ru>
67 *
78 * This program is free software; you can redistribute it and/or modify
89 * it under the terms of the GNU General Public License as published by
3334 #define avs_close dlclose
3435 #define avs_address dlsym
3536 #else
36 #include <windows.h>
3737 #define avs_open() LoadLibraryW( L"avisynth" )
3838 #define avs_close FreeLibrary
3939 #define avs_address GetProcAddress
5757 #include <libavutil/pixfmt.h>
5858 #endif
5959
60 /* AvxSynth doesn't have yv24, yv16, yv411, or y8, so disable them. */
61 #if USE_AVXSYNTH
62 #define avs_is_yv24( vi ) 0
63 #define avs_is_yv16( vi ) 0
64 #define avs_is_yv411( vi ) 0
65 #define avs_is_y8( vi ) 0
66 #endif
67
6860 /* maximum size of the sequence of filters to try on non script files */
6961 #define AVS_MAX_SEQUENCE 5
7062
7163 #define LOAD_AVS_FUNC(name, continue_on_fail)\
7264 {\
7365 h->func.name = (void*)avs_address( h->library, #name );\
66 if( !continue_on_fail && !h->func.name )\
67 goto fail;\
68 }
69
70 #define LOAD_AVS_FUNC_ALIAS(name, alias, continue_on_fail)\
71 {\
72 if( !h->func.name )\
73 h->func.name = (void*)avs_address( h->library, alias );\
7474 if( !continue_on_fail && !h->func.name )\
7575 goto fail;\
7676 }
9595 AVSC_DECLARE_FUNC( avs_release_value );
9696 AVSC_DECLARE_FUNC( avs_release_video_frame );
9797 AVSC_DECLARE_FUNC( avs_take_clip );
98 #if !USE_AVXSYNTH
99 // AviSynth+ extension
100 AVSC_DECLARE_FUNC( avs_is_rgb48 );
101 AVSC_DECLARE_FUNC( avs_is_rgb64 );
102 AVSC_DECLARE_FUNC( avs_is_yuv444p16 );
103 AVSC_DECLARE_FUNC( avs_is_yuv422p16 );
104 AVSC_DECLARE_FUNC( avs_is_yuv420p16 );
105 AVSC_DECLARE_FUNC( avs_is_y16 );
106 AVSC_DECLARE_FUNC( avs_is_yuv444ps );
107 AVSC_DECLARE_FUNC( avs_is_yuv422ps );
108 AVSC_DECLARE_FUNC( avs_is_yuv420ps );
109 AVSC_DECLARE_FUNC( avs_is_y32 );
110 AVSC_DECLARE_FUNC( avs_is_444 );
111 AVSC_DECLARE_FUNC( avs_is_422 );
112 AVSC_DECLARE_FUNC( avs_is_420 );
113 AVSC_DECLARE_FUNC( avs_is_y );
114 AVSC_DECLARE_FUNC( avs_is_yuva );
115 AVSC_DECLARE_FUNC( avs_is_planar_rgb );
116 AVSC_DECLARE_FUNC( avs_is_planar_rgba );
117 AVSC_DECLARE_FUNC( avs_num_components );
118 AVSC_DECLARE_FUNC( avs_component_size );
119 AVSC_DECLARE_FUNC( avs_bits_per_component );
120 #endif
98121 } func;
99122 } avs_hnd_t;
100123
116139 LOAD_AVS_FUNC( avs_release_value, 0 );
117140 LOAD_AVS_FUNC( avs_release_video_frame, 0 );
118141 LOAD_AVS_FUNC( avs_take_clip, 0 );
142 #if !USE_AVXSYNTH
143 // AviSynth+ extension
144 LOAD_AVS_FUNC( avs_is_rgb48, 1 );
145 LOAD_AVS_FUNC_ALIAS( avs_is_rgb48, "_avs_is_rgb48@4", 1 );
146 LOAD_AVS_FUNC( avs_is_rgb64, 1 );
147 LOAD_AVS_FUNC_ALIAS( avs_is_rgb64, "_avs_is_rgb64@4", 1 );
148 LOAD_AVS_FUNC( avs_is_yuv444p16, 1 );
149 LOAD_AVS_FUNC( avs_is_yuv422p16, 1 );
150 LOAD_AVS_FUNC( avs_is_yuv420p16, 1 );
151 LOAD_AVS_FUNC( avs_is_y16, 1 );
152 LOAD_AVS_FUNC( avs_is_yuv444ps, 1 );
153 LOAD_AVS_FUNC( avs_is_yuv422ps, 1 );
154 LOAD_AVS_FUNC( avs_is_yuv420ps, 1 );
155 LOAD_AVS_FUNC( avs_is_y32, 1 );
156 LOAD_AVS_FUNC( avs_is_444, 1 );
157 LOAD_AVS_FUNC( avs_is_422, 1 );
158 LOAD_AVS_FUNC( avs_is_420, 1 );
159 LOAD_AVS_FUNC( avs_is_y, 1 );
160 LOAD_AVS_FUNC( avs_is_yuva, 1 );
161 LOAD_AVS_FUNC( avs_is_planar_rgb, 1 );
162 LOAD_AVS_FUNC( avs_is_planar_rgba, 1 );
163 LOAD_AVS_FUNC( avs_num_components, 1 );
164 LOAD_AVS_FUNC( avs_component_size, 1 );
165 LOAD_AVS_FUNC( avs_bits_per_component, 1 );
166 #endif
119167 return 0;
120168 fail:
121169 avs_close( h->library );
170 h->library = NULL;
122171 return -1;
123172 }
173
174 /* AvxSynth doesn't have yv24, yv16, yv411, or y8, so disable them. */
175 #if USE_AVXSYNTH
176 #define avs_is_yv24( vi ) (0)
177 #define avs_is_yv16( vi ) (0)
178 #define avs_is_yv411( vi ) (0)
179 #define avs_is_y8( vi ) (0)
180 /* AvxSynth doesn't support AviSynth+ pixel types. */
181 #define AVS_IS_AVISYNTHPLUS (0)
182 #define AVS_IS_420( vi ) (0)
183 #define AVS_IS_422( vi ) (0)
184 #define AVS_IS_444( vi ) (0)
185 #define AVS_IS_RGB48( vi ) (0)
186 #define AVS_IS_RGB64( vi ) (0)
187 #define AVS_IS_YUV420P16( vi ) (0)
188 #define AVS_IS_YUV422P16( vi ) (0)
189 #define AVS_IS_YUV444P16( vi ) (0)
190 #else
191 #define AVS_IS_AVISYNTHPLUS (h->func.avs_is_420 && h->func.avs_is_422 && h->func.avs_is_444)
192 #define AVS_IS_420( vi ) (h->func.avs_is_420 ? h->func.avs_is_420( vi ) : avs_is_yv12( vi ))
193 #define AVS_IS_422( vi ) (h->func.avs_is_422 ? h->func.avs_is_422( vi ) : avs_is_yv16( vi ))
194 #define AVS_IS_444( vi ) (h->func.avs_is_444 ? h->func.avs_is_444( vi ) : avs_is_yv24( vi ))
195 #define AVS_IS_RGB48( vi ) (h->func.avs_is_rgb48 && h->func.avs_is_rgb48( vi ))
196 #define AVS_IS_RGB64( vi ) (h->func.avs_is_rgb64 && h->func.avs_is_rgb64( vi ))
197 #define AVS_IS_YUV420P16( vi ) (h->func.avs_is_yuv420p16 && h->func.avs_is_yuv420p16( vi ))
198 #define AVS_IS_YUV422P16( vi ) (h->func.avs_is_yuv422p16 && h->func.avs_is_yuv422p16( vi ))
199 #define AVS_IS_YUV444P16( vi ) (h->func.avs_is_yuv444p16 && h->func.avs_is_yuv444p16( vi ))
200 #endif
124201
125202 /* generate a filter sequence to try based on the filename extension */
126203 static void avs_build_filter_sequence( char *filename_ext, const char *filter[AVS_MAX_SEQUENCE+1] )
159236 #if USE_AVXSYNTH
160237 return 2.58f;
161238 #else
162 FAIL_IF_ERROR( !h->func.avs_function_exists( h->env, "VersionNumber" ), "VersionNumber does not exist\n" )
239 FAIL_IF_ERROR( !h->func.avs_function_exists( h->env, "VersionNumber" ), "VersionNumber does not exist\n" );
163240 AVS_Value ver = h->func.avs_invoke( h->env, "VersionNumber", avs_new_value_array( NULL, 0 ), NULL );
164 FAIL_IF_ERROR( avs_is_error( ver ), "unable to determine avisynth version: %s\n", avs_as_error( ver ) )
241 FAIL_IF_ERROR( avs_is_error( ver ), "unable to determine avisynth version: %s\n", avs_as_error( ver ) );
165242 FAIL_IF_ERROR( !avs_is_float( ver ), "VersionNumber did not return a float value\n" );
166243 float ret = avs_as_float( ver );
167244 h->func.avs_release_value( ver );
178255 fclose( fh );
179256 FAIL_IF_ERROR( !b_regular, "AVS input is incompatible with non-regular file `%s'\n", psz_filename );
180257
181 avs_hnd_t *h = malloc( sizeof(avs_hnd_t) );
258 avs_hnd_t *h = calloc( 1, sizeof(avs_hnd_t) );
182259 if( !h )
183260 return -1;
184 FAIL_IF_ERROR( x264_avs_load_library( h ), "failed to load avisynth\n" )
261 FAIL_IF_ERROR( x264_avs_load_library( h ), "failed to load avisynth\n" );
185262 h->env = h->func.avs_create_script_environment( AVS_INTERFACE_25 );
186263 if( h->func.avs_get_error )
187264 {
208285 if( !strcasecmp( filename_ext, "avs" ) )
209286 {
210287 res = h->func.avs_invoke( h->env, "Import", arg, NULL );
211 FAIL_IF_ERROR( avs_is_error( res ), "%s\n", avs_as_string( res ) )
288 FAIL_IF_ERROR( avs_is_error( res ), "%s\n", avs_as_string( res ) );
212289 /* check if the user is using a multi-threaded script and apply distributor if necessary.
213290 adapted from avisynth's vfw interface */
214291 AVS_Value mt_test = h->func.avs_invoke( h->env, "GetMTMode", avs_new_value_bool( 0 ), NULL );
248325 }
249326 x264_cli_printf( X264_LOG_INFO, "failed\n" );
250327 }
251 FAIL_IF_ERROR( !filter[i], "unable to find source filter to open `%s'\n", psz_filename )
252 }
253 FAIL_IF_ERROR( !avs_is_clip( res ), "`%s' didn't return a video clip\n", psz_filename )
328 FAIL_IF_ERROR( !filter[i], "unable to find source filter to open `%s'\n", psz_filename );
329 }
330 FAIL_IF_ERROR( !avs_is_clip( res ), "`%s' didn't return a video clip\n", psz_filename );
254331 h->clip = h->func.avs_take_clip( res, h->env );
255332 const AVS_VideoInfo *vi = h->func.avs_get_video_info( h->clip );
256 FAIL_IF_ERROR( !avs_has_video( vi ), "`%s' has no video data\n", psz_filename )
333 FAIL_IF_ERROR( !avs_has_video( vi ), "`%s' has no video data\n", psz_filename );
257334 /* if the clip is made of fields instead of frames, call weave to make them frames */
258335 if( avs_is_field_based( vi ) )
259336 {
260337 x264_cli_log( "avs", X264_LOG_WARNING, "detected fieldbased (separated) input, weaving to frames\n" );
261338 AVS_Value tmp = h->func.avs_invoke( h->env, "Weave", res, NULL );
262 FAIL_IF_ERROR( avs_is_error( tmp ), "couldn't weave fields into frames\n" )
339 FAIL_IF_ERROR( avs_is_error( tmp ), "couldn't weave fields into frames\n" );
263340 res = update_clip( h, &vi, tmp, res );
264341 info->interlaced = 1;
265342 info->tff = avs_is_tff( vi );
267344 #if !HAVE_SWSCALE
268345 /* if swscale is not available, convert the CSP if necessary */
269346 FAIL_IF_ERROR( avs_version < 2.6f && (opt->output_csp == X264_CSP_I422 || opt->output_csp == X264_CSP_I444),
270 "avisynth >= 2.6 is required for i422/i444 output\n" )
271 if( (opt->output_csp == X264_CSP_I420 && !avs_is_yv12( vi )) || (opt->output_csp == X264_CSP_I422 && !avs_is_yv16( vi )) ||
272 (opt->output_csp == X264_CSP_I444 && !avs_is_yv24( vi )) || (opt->output_csp == X264_CSP_RGB && !avs_is_rgb( vi )) )
273 {
274
275 const char *csp = opt->output_csp == X264_CSP_I420 ? "YV12" :
276 opt->output_csp == X264_CSP_I422 ? "YV16" :
277 opt->output_csp == X264_CSP_I444 ? "YV24" : "RGB";
347 "avisynth >= 2.6 is required for i422/i444 output\n" );
348 if( (opt->output_csp == X264_CSP_I420 && !AVS_IS_420( vi )) ||
349 (opt->output_csp == X264_CSP_I422 && !AVS_IS_422( vi )) ||
350 (opt->output_csp == X264_CSP_I444 && !AVS_IS_444( vi )) ||
351 (opt->output_csp == X264_CSP_RGB && !avs_is_rgb( vi )) )
352 {
353 const char *csp;
354 if( AVS_IS_AVISYNTHPLUS )
355 {
356 csp = opt->output_csp == X264_CSP_I420 ? "YUV420" :
357 opt->output_csp == X264_CSP_I422 ? "YUV422" :
358 opt->output_csp == X264_CSP_I444 ? "YUV444" :
359 "RGB";
360 }
361 else
362 {
363 csp = opt->output_csp == X264_CSP_I420 ? "YV12" :
364 opt->output_csp == X264_CSP_I422 ? "YV16" :
365 opt->output_csp == X264_CSP_I444 ? "YV24" :
366 "RGB";
367 }
278368 x264_cli_log( "avs", X264_LOG_WARNING, "converting input clip to %s\n", csp );
279369 FAIL_IF_ERROR( opt->output_csp < X264_CSP_I444 && (vi->width&1),
280 "input clip width not divisible by 2 (%dx%d)\n", vi->width, vi->height )
370 "input clip width not divisible by 2 (%dx%d)\n", vi->width, vi->height );
281371 FAIL_IF_ERROR( opt->output_csp == X264_CSP_I420 && info->interlaced && (vi->height&3),
282 "input clip height not divisible by 4 (%dx%d)\n", vi->width, vi->height )
372 "input clip height not divisible by 4 (%dx%d)\n", vi->width, vi->height );
283373 FAIL_IF_ERROR( (opt->output_csp == X264_CSP_I420 || info->interlaced) && (vi->height&1),
284 "input clip height not divisible by 2 (%dx%d)\n", vi->width, vi->height )
285 char conv_func[14];
374 "input clip height not divisible by 2 (%dx%d)\n", vi->width, vi->height );
375 char conv_func[16];
286376 snprintf( conv_func, sizeof(conv_func), "ConvertTo%s", csp );
287377 char matrix[7] = "";
288378 int arg_count = 2;
302392 arg_arr[1] = avs_new_value_bool( info->interlaced );
303393 arg_arr[2] = avs_new_value_string( matrix );
304394 AVS_Value res2 = h->func.avs_invoke( h->env, conv_func, avs_new_value_array( arg_arr, arg_count ), arg_name );
305 FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert input clip to %s\n", csp )
395 FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert input clip to %s\n", csp );
306396 res = update_clip( h, &vi, res2, res );
307397 }
308398 /* if swscale is not available, change the range if necessary. This only applies to YUV-based CSPs however */
315405 arg_arr[1] = avs_new_value_string( levels );
316406 const char *arg_name[] = { NULL, "levels" };
317407 AVS_Value res2 = h->func.avs_invoke( h->env, "ColorYUV", avs_new_value_array( arg_arr, 2 ), arg_name );
318 FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert range: %s\n", avs_as_error( res2 ) )
408 FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert range: %s\n", avs_as_error( res2 ) );
319409 res = update_clip( h, &vi, res2, res );
320410 // notification that the input range has changed to the desired one
321411 opt->input_range = opt->output_range;
330420 info->fps_den = vi->fps_denominator;
331421 h->num_frames = info->num_frames = vi->num_frames;
332422 info->thread_safe = 1;
333 if( avs_is_rgb32( vi ) )
423 if( AVS_IS_RGB64( vi ) )
424 info->csp = X264_CSP_BGRA | X264_CSP_VFLIP | X264_CSP_HIGH_DEPTH;
425 else if( avs_is_rgb32( vi ) )
334426 info->csp = X264_CSP_BGRA | X264_CSP_VFLIP;
427 else if( AVS_IS_RGB48( vi ) )
428 info->csp = X264_CSP_BGR | X264_CSP_VFLIP | X264_CSP_HIGH_DEPTH;
335429 else if( avs_is_rgb24( vi ) )
336430 info->csp = X264_CSP_BGR | X264_CSP_VFLIP;
431 else if( AVS_IS_YUV444P16( vi ) )
432 info->csp = X264_CSP_I444 | X264_CSP_HIGH_DEPTH;
337433 else if( avs_is_yv24( vi ) )
338434 info->csp = X264_CSP_I444;
435 else if( AVS_IS_YUV422P16( vi ) )
436 info->csp = X264_CSP_I422 | X264_CSP_HIGH_DEPTH;
339437 else if( avs_is_yv16( vi ) )
340438 info->csp = X264_CSP_I422;
439 else if( AVS_IS_YUV420P16( vi ) )
440 info->csp = X264_CSP_I420 | X264_CSP_HIGH_DEPTH;
341441 else if( avs_is_yv12( vi ) )
342442 info->csp = X264_CSP_I420;
343443 #if HAVE_SWSCALE
349449 info->csp = AV_PIX_FMT_GRAY8 | X264_CSP_OTHER;
350450 #endif
351451 else
352 info->csp = X264_CSP_NONE;
452 {
453 AVS_Value pixel_type = h->func.avs_invoke( h->env, "PixelType", res, NULL );
454 const char *pixel_type_name = avs_is_string( pixel_type ) ? avs_as_string( pixel_type ) : "unknown";
455 FAIL_IF_ERROR( 1, "not supported pixel type: %s\n", pixel_type_name );
456 }
353457 info->vfr = 0;
354458
355459 *p_handle = h;
381485 return -1;
382486 AVS_VideoFrame *frm = pic->opaque = h->func.avs_get_frame( h->clip, i_frame );
383487 const char *err = h->func.avs_clip_get_error( h->clip );
384 FAIL_IF_ERROR( err, "%s occurred while reading frame %d\n", err, i_frame )
488 FAIL_IF_ERROR( err, "%s occurred while reading frame %d\n", err, i_frame );
385489 for( int i = 0; i < pic->img.planes; i++ )
386490 {
387491 /* explicitly cast away the const attribute to avoid a warning */
406510 static int close_file( hnd_t handle )
407511 {
408512 avs_hnd_t *h = handle;
409 h->func.avs_release_clip( h->clip );
410 if( h->func.avs_delete_script_environment )
513 if( h->func.avs_release_clip && h->clip )
514 h->func.avs_release_clip( h->clip );
515 if( h->func.avs_delete_script_environment && h->env )
411516 h->func.avs_delete_script_environment( h->env );
412 avs_close( h->library );
517 if( h->library )
518 avs_close( h->library );
413519 free( h );
414520 return 0;
415521 }
3131 #undef DECLARE_ALIGNED
3232 #include <libavcodec/avcodec.h>
3333 #include <libswscale/swscale.h>
34
35 #ifdef _WIN32
36 #include <windows.h>
37 #endif
3834
3935 #define PROGRESS_LENGTH 36
4036
105101 if( !idx )
106102 {
107103 FFMS_Indexer *indexer = FFMS_CreateIndexer( psz_filename, &e );
108 FAIL_IF_ERROR( !indexer, "could not create indexer\n" )
104 FAIL_IF_ERROR( !indexer, "could not create indexer\n" );
109105
110106 if( opt->progress )
111107 FFMS_SetProgressCallback( indexer, update_progress, &h->time );
112108
113109 idx = FFMS_DoIndexing2( indexer, FFMS_IEH_ABORT, &e );
114110 fprintf( stderr, "%*c", PROGRESS_LENGTH+1, '\r' );
115 FAIL_IF_ERROR( !idx, "could not create index\n" )
111 FAIL_IF_ERROR( !idx, "could not create index\n" );
116112
117113 if( opt->index_file && FFMS_WriteIndex( opt->index_file, idx, &e ) )
118114 x264_cli_log( "ffms", X264_LOG_WARNING, "could not write index file\n" );
123119 h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, idx, 1, seekmode, &e );
124120 FFMS_DestroyIndex( idx );
125121
126 FAIL_IF_ERROR( trackno < 0, "could not find video track\n" )
127 FAIL_IF_ERROR( !h->video_source, "could not create video source\n" )
122 FAIL_IF_ERROR( trackno < 0, "could not find video track\n" );
123 FAIL_IF_ERROR( !h->video_source, "could not create video source\n" );
128124
129125 const FFMS_VideoProperties *videop = FFMS_GetVideoProperties( h->video_source );
130126 info->num_frames = h->num_frames = videop->NumFrames;
137133 info->thread_safe = 0;
138134
139135 const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, 0, &e );
140 FAIL_IF_ERROR( !frame, "could not read frame 0\n" )
136 FAIL_IF_ERROR( !frame, "could not read frame 0\n" );
141137
142138 info->fullrange = 0;
143139 info->width = frame->EncodedWidth;
188184 FFMS_ErrorInfo e;
189185 e.BufferSize = 0;
190186 const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, i_frame, &e );
191 FAIL_IF_ERROR( !frame, "could not read frame %d \n", i_frame )
187 FAIL_IF_ERROR( !frame, "could not read frame %d \n", i_frame );
192188
193189 memcpy( pic->img.stride, frame->Linesize, sizeof(pic->img.stride) );
194190 memcpy( pic->img.plane, frame->Data, sizeof(pic->img.plane) );
197193 {
198194 const FFMS_FrameInfo *info = FFMS_GetFrameInfo( h->track, i_frame );
199195 FAIL_IF_ERROR( info->PTS == AV_NOPTS_VALUE, "invalid timestamp. "
200 "Use --force-cfr and specify a framerate with --fps\n" )
196 "Use --force-cfr and specify a framerate with --fps\n" );
201197
202198 pic->pts = info->PTS >> h->reduce_pts;
203199 pic->duration = 0;
2727
2828 #ifdef _WIN32
2929 #include <io.h>
30 #include <windows.h>
3130 #elif HAVE_MMAP
3231 #include <sys/mman.h>
3332 #include <unistd.h>
153152 SYSTEM_INFO si;
154153 GetSystemInfo( &si );
155154 h->align_mask = si.dwAllocationGranularity - 1;
155 h->prefetch_virtual_memory = (void*)GetProcAddress( GetModuleHandleW( L"kernel32.dll" ), "PrefetchVirtualMemory" );
156 h->process_handle = GetCurrentProcess();
156157 h->map_handle = CreateFileMappingW( osfhandle, NULL, PAGE_READONLY, 0, 0, NULL );
157158 return !h->map_handle;
158159 }
172173 size += align;
173174 #ifdef _WIN32
174175 uint8_t *base = MapViewOfFile( h->map_handle, FILE_MAP_READ, offset >> 32, offset, size );
175 /* TODO: Would PrefetchVirtualMemory() (only available on Win8+) be beneficial? */
176176 if( base )
177 {
178 /* PrefetchVirtualMemory() is only available on Windows 8 and newer. */
179 if( h->prefetch_virtual_memory )
180 {
181 struct { void *addr; size_t size; } mem_range = { base, size };
182 h->prefetch_virtual_memory( h->process_handle, 1, &mem_range, 0 );
183 }
177184 return base + align;
185 }
178186 #else
179187 uint8_t *base = mmap( NULL, size, PROT_READ, MAP_PRIVATE, h->fd, offset );
180188 if( base != MAP_FAILED )
2828 #define X264_INPUT_H
2929
3030 #include "x264cli.h"
31
32 #ifdef _WIN32
33 #include <windows.h>
34 #endif
3135
3236 /* options that are used by only some demuxers */
3337 typedef struct
134138 {
135139 int align_mask;
136140 #ifdef _WIN32
137 void *map_handle;
141 BOOL (WINAPI *prefetch_virtual_memory)( HANDLE, ULONG_PTR, PVOID, ULONG );
142 HANDLE process_handle;
143 HANDLE map_handle;
138144 #elif HAVE_MMAP
139145 int fd;
140146 #endif
167167 if( opt->format )
168168 FAIL_IF_ERROR( !(format = av_find_input_format( opt->format )), "unknown file format: %s\n", opt->format );
169169
170 FAIL_IF_ERROR( avformat_open_input( &h->lavf, psz_filename, format, &options ), "could not open input file\n" )
170 FAIL_IF_ERROR( avformat_open_input( &h->lavf, psz_filename, format, &options ), "could not open input file\n" );
171171 if( options )
172172 av_dict_free( &options );
173 FAIL_IF_ERROR( avformat_find_stream_info( h->lavf, NULL ) < 0, "could not find input stream info\n" )
173 FAIL_IF_ERROR( avformat_find_stream_info( h->lavf, NULL ) < 0, "could not find input stream info\n" );
174174
175175 int i = 0;
176176 while( i < h->lavf->nb_streams && h->lavf->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO )
177177 i++;
178 FAIL_IF_ERROR( i == h->lavf->nb_streams, "could not find video stream\n" )
178 FAIL_IF_ERROR( i == h->lavf->nb_streams, "could not find video stream\n" );
179179 h->stream_id = i;
180180 h->next_frame = 0;
181181 AVCodecContext *c = h->lavf->streams[i]->codec;
187187 info->thread_safe = 0;
188188 h->vfr_input = info->vfr;
189189 FAIL_IF_ERROR( avcodec_open2( c, avcodec_find_decoder( c->codec_id ), NULL ),
190 "could not find decoder for video stream\n" )
190 "could not find decoder for video stream\n" );
191191
192192 /* prefetch the first frame and set/confirm flags */
193193 h->first_pic = malloc( sizeof(cli_pic_t) );
194194 FAIL_IF_ERROR( !h->first_pic || lavf_input.picture_alloc( h->first_pic, h, X264_CSP_OTHER, info->width, info->height ),
195 "malloc failed\n" )
196 else if( read_frame_internal( h->first_pic, h, 0, info ) )
195 "malloc failed\n" );
196 if( read_frame_internal( h->first_pic, h, 0, info ) )
197197 return -1;
198198
199199 info->width = c->width;
5353 }
5454 else
5555 sscanf( opt->resolution, "%dx%d", &info->width, &info->height );
56 FAIL_IF_ERROR( !info->width || !info->height, "raw input requires a resolution.\n" )
56 FAIL_IF_ERROR( !info->width || !info->height, "raw input requires a resolution.\n" );
5757 if( opt->colorspace )
5858 {
5959 for( info->csp = X264_CSP_CLI_MAX-1; info->csp > X264_CSP_NONE; info->csp-- )
4848 {
4949 thread_hnd_t *h = malloc( sizeof(thread_hnd_t) );
5050 FAIL_IF_ERR( !h || cli_input.picture_alloc( &h->pic, *p_handle, info->csp, info->width, info->height ),
51 "x264", "malloc failed\n" )
51 "x264", "malloc failed\n" );
5252 h->input = cli_input;
5353 h->p_handle = *p_handle;
5454 h->next_frame = -1;
6060 fps_den = i * h->timebase_num;
6161 fps_num = round( fps_den * fps_sig ) * exponent;
6262 FAIL_IF_ERROR( fps_num > UINT32_MAX, "tcfile fps correction failed.\n"
63 " Specify an appropriate timebase manually or remake tcfile.\n" )
63 " Specify an appropriate timebase manually or remake tcfile.\n" );
6464 if( fabs( ((double)fps_num / fps_den) / exponent - fps_sig ) < DOUBLE_EPSILON )
6565 break;
6666 ++i;
8686 fps_den = round( MKV_TIMEBASE_DEN / fps_sig ) / exponent;
8787 h->timebase_num = fps_den && h->timebase_num ? gcd( h->timebase_num, fps_den ) : fps_den;
8888 FAIL_IF_ERROR( h->timebase_num > UINT32_MAX || !h->timebase_num, "automatic timebase generation failed.\n"
89 " Specify timebase manually.\n" )
89 " Specify timebase manually.\n" );
9090 }
9191 return 0;
9292 }
9999 double *fpss = NULL;
100100
101101 ret = fscanf( tcfile_in, "# timecode format v%d", &tcfv );
102 FAIL_IF_ERROR( ret != 1 || (tcfv != 1 && tcfv != 2), "unsupported timecode format\n" )
102 FAIL_IF_ERROR( ret != 1 || (tcfv != 1 && tcfv != 2), "unsupported timecode format\n" );
103103 #define NO_TIMECODE_LINE (buff[0] == '#' || buff[0] == '\n' || buff[0] == '\r')
104104 if( tcfv == 1 )
105105 {
114114 if( NO_TIMECODE_LINE )
115115 continue;
116116 FAIL_IF_ERROR( sscanf( buff, "assume %lf", &h->assume_fps ) != 1 && sscanf( buff, "Assume %lf", &h->assume_fps ) != 1,
117 "tcfile parsing error: assumed fps not found\n" )
117 "tcfile parsing error: assumed fps not found\n" );
118118 break;
119119 }
120 FAIL_IF_ERROR( h->assume_fps <= 0, "invalid assumed fps %.6f\n", h->assume_fps )
120 FAIL_IF_ERROR( h->assume_fps <= 0, "invalid assumed fps %.6f\n", h->assume_fps );
121121
122122 file_pos = ftell( tcfile_in );
123123 h->stored_pts_num = 0;
130130 continue;
131131 }
132132 ret = sscanf( buff, "%d,%d,%lf", &start, &end, &seq_fps );
133 FAIL_IF_ERROR( ret != 3 && ret != EOF, "invalid input tcfile\n" )
133 FAIL_IF_ERROR( ret != 3 && ret != EOF, "invalid input tcfile\n" );
134134 FAIL_IF_ERROR( start > end || start <= prev_start || end <= prev_end || seq_fps <= 0,
135 "invalid input tcfile at line %d: %s\n", num, buff )
135 "invalid input tcfile at line %d: %s\n", num, buff );
136136 prev_start = start;
137137 prev_end = end;
138138 if( h->auto_timebase_den || h->auto_timebase_num )
233233 h->stored_pts_num++;
234234 }
235235 timecodes_num = h->stored_pts_num;
236 FAIL_IF_ERROR( !timecodes_num, "input tcfile doesn't have any timecodes!\n" )
236 FAIL_IF_ERROR( !timecodes_num, "input tcfile doesn't have any timecodes!\n" );
237237 fseek( tcfile_in, file_pos, SEEK_SET );
238238
239239 timecodes = malloc( timecodes_num * sizeof(double) );
245245 {
246246 ret = sscanf( buff, "%lf", &timecodes[0] );
247247 timecodes[0] *= 1e-3; /* Timecode format v2 is expressed in milliseconds. */
248 FAIL_IF_ERROR( ret != 1, "invalid input tcfile for frame 0\n" )
248 FAIL_IF_ERROR( ret != 1, "invalid input tcfile for frame 0\n" );
249249 for( num = 1; num < timecodes_num && fgets( buff, sizeof(buff), tcfile_in ) != NULL; )
250250 {
251251 if( NO_TIMECODE_LINE )
253253 ret = sscanf( buff, "%lf", &timecodes[num] );
254254 timecodes[num] *= 1e-3; /* Timecode format v2 is expressed in milliseconds. */
255255 FAIL_IF_ERROR( ret != 1 || timecodes[num] <= timecodes[num - 1],
256 "invalid input tcfile for frame %d\n", num )
256 "invalid input tcfile for frame %d\n", num );
257257 ++num;
258258 }
259259 }
260 FAIL_IF_ERROR( num < timecodes_num, "failed to read input tcfile for frame %d", num )
260 FAIL_IF_ERROR( num < timecodes_num, "failed to read input tcfile for frame %d", num );
261261
262262 if( timecodes_num == 1 )
263263 h->timebase_den = info->fps_num;
313313 x264_cli_log( "timecode", X264_LOG_INFO, "automatic timebase generation %"PRIu64"/%"PRIu64"\n", h->timebase_num, h->timebase_den );
314314 }
315315 else FAIL_IF_ERROR( h->timebase_den > UINT32_MAX || !h->timebase_den, "automatic timebase generation failed.\n"
316 " Specify an appropriate timebase manually.\n" )
316 " Specify an appropriate timebase manually.\n" );
317317
318318 h->pts = malloc( h->stored_pts_num * sizeof(int64_t) );
319319 if( !h->pts )
321321 for( num = 0; num < h->stored_pts_num; num++ )
322322 {
323323 h->pts[num] = timecodes[num] * ((double)h->timebase_den / h->timebase_num) + 0.5;
324 FAIL_IF_ERROR( num > 0 && h->pts[num] <= h->pts[num - 1], "invalid timebase or timecode for frame %d\n", num )
324 FAIL_IF_ERROR( num > 0 && h->pts[num] <= h->pts[num - 1], "invalid timebase or timecode for frame %d\n", num );
325325 }
326326
327327 free( timecodes );
343343 int ret = 0;
344344 FILE *tcfile_in;
345345 timecode_hnd_t *h = malloc( sizeof(timecode_hnd_t) );
346 FAIL_IF_ERROR( !h, "malloc failed\n" )
346 FAIL_IF_ERROR( !h, "malloc failed\n" );
347347 h->input = cli_input;
348348 h->p_handle = *p_handle;
349349 h->pts = NULL;
356356 h->timebase_den = 0; /* set later by auto timebase generation */
357357 }
358358 FAIL_IF_ERROR( h->timebase_num > UINT32_MAX || h->timebase_den > UINT32_MAX,
359 "timebase you specified exceeds H.264 maximum\n" )
359 "timebase you specified exceeds H.264 maximum\n" );
360360 }
361361 h->auto_timebase_num = !ret;
362362 h->auto_timebase_den = ret < 2;
366366 h->timebase_den = 0; /* set later by auto timebase generation */
367367
368368 tcfile_in = x264_fopen( psz_filename, "rb" );
369 FAIL_IF_ERROR( !tcfile_in, "can't open `%s'\n", psz_filename )
370 else if( !x264_is_regular_file( tcfile_in ) )
369 FAIL_IF_ERROR( !tcfile_in, "can't open `%s'\n", psz_filename );
370 if( !x264_is_regular_file( tcfile_in ) )
371371 {
372372 x264_cli_log( "timecode", X264_LOG_ERROR, "tcfile input incompatible with non-regular file `%s'\n", psz_filename );
373373 fclose( tcfile_in );
9898 break;
9999 }
100100 }
101 FAIL_IF_ERROR( strncmp( header, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1 ), "bad sequence header magic\n" )
102 FAIL_IF_ERROR( i == MAX_YUV4_HEADER, "bad sequence header length\n" )
101 FAIL_IF_ERROR( strncmp( header, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1 ), "bad sequence header magic\n" );
102 FAIL_IF_ERROR( i == MAX_YUV4_HEADER, "bad sequence header length\n" );
103103
104104 /* Scan properties */
105105 header_end = &header[i+1]; /* Include space */
186186 h->bit_depth = 8;
187187 }
188188
189 FAIL_IF_ERROR( colorspace <= X264_CSP_NONE || colorspace >= X264_CSP_MAX, "colorspace unhandled\n" )
189 FAIL_IF_ERROR( colorspace <= X264_CSP_NONE || colorspace >= X264_CSP_MAX, "colorspace unhandled\n" );
190190 FAIL_IF_ERROR( h->bit_depth < 8 || h->bit_depth > 16, "unsupported bit depth `%d'\n", h->bit_depth );
191191
192192 info->thread_safe = 1;
214214 int len = 1;
215215 while( len <= MAX_FRAME_HEADER && fgetc( h->fh ) != '\n' )
216216 len++;
217 FAIL_IF_ERROR( len > MAX_FRAME_HEADER || len < sizeof(Y4M_FRAME_MAGIC), "bad frame header length\n" )
217 FAIL_IF_ERROR( len > MAX_FRAME_HEADER || len < sizeof(Y4M_FRAME_MAGIC), "bad frame header length\n" );
218218 h->frame_header_len = len;
219219 h->frame_size += len;
220220
251251 * produces y4m files with variable-length frame headers so just error out if that happens. */
252252 while( i <= h->frame_header_len && header[i-1] != '\n' )
253253 i++;
254 FAIL_IF_ERROR( i != h->frame_header_len, "bad frame header length\n" )
254 FAIL_IF_ERROR( i != h->frame_header_len, "bad frame header length\n" );
255255 }
256256 else
257257 {
260260 return -1;
261261 while( i <= MAX_FRAME_HEADER && fgetc( h->fh ) != '\n' )
262262 i++;
263 FAIL_IF_ERROR( i > MAX_FRAME_HEADER, "bad frame header length\n" )
264 }
265 FAIL_IF_ERROR( memcmp( header, Y4M_FRAME_MAGIC, slen ), "bad frame header magic\n" )
263 FAIL_IF_ERROR( i > MAX_FRAME_HEADER, "bad frame header length\n" );
264 }
265 FAIL_IF_ERROR( memcmp( header, Y4M_FRAME_MAGIC, slen ), "bad frame header magic\n" );
266266
267267 for( i = 0; i < pic->img.planes; i++ )
268268 {
244244 {
245245 CHECK( mk_write_id( c, id ) );
246246 CHECK( mk_write_size( c, size ) );
247 CHECK( mk_append_context_data( c, data, size ) ) ;
247 CHECK( mk_append_context_data( c, data, size ) );
248248 return 0;
249249 }
250250
170170 return -1;
171171 int b_regular = x264_is_regular_file( fh );
172172 fclose( fh );
173 FAIL_IF_ERR( !b_regular, "mp4", "MP4 output is incompatible with non-regular file `%s'\n", psz_filename )
173 FAIL_IF_ERR( !b_regular, "mp4", "MP4 output is incompatible with non-regular file `%s'\n", psz_filename );
174174
175175 mp4_hnd_t *p_mp4 = calloc( 1, sizeof(mp4_hnd_t) );
176176 if( !p_mp4 )
179179 #ifdef _WIN32
180180 /* GPAC doesn't support Unicode filenames. */
181181 char ansi_filename[MAX_PATH];
182 FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 1 ), "mp4", "invalid ansi filename\n" )
182 FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 1 ), "mp4", "invalid ansi filename\n" );
183183 p_mp4->p_file = gf_isom_open( ansi_filename, GF_ISOM_OPEN_WRITE, NULL );
184184 #else
185185 p_mp4->p_file = gf_isom_open( psz_filename, GF_ISOM_OPEN_WRITE, NULL );
209209
210210 p_mp4->i_time_res = (uint64_t)p_param->i_timebase_den * p_mp4->i_dts_compress_multiplier;
211211 p_mp4->i_time_inc = (uint64_t)p_param->i_timebase_num * p_mp4->i_dts_compress_multiplier;
212 FAIL_IF_ERR( p_mp4->i_time_res > UINT32_MAX, "mp4", "MP4 media timescale %"PRIu64" exceeds maximum\n", p_mp4->i_time_res )
212 FAIL_IF_ERR( p_mp4->i_time_res > UINT32_MAX, "mp4", "MP4 media timescale %"PRIu64" exceeds maximum\n", p_mp4->i_time_res );
213213
214214 p_mp4->i_track = gf_isom_new_track( p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
215215 p_mp4->i_time_res );
229229 uint64_t dh = p_param->i_height << 16;
230230 double sar = (double)p_param->vui.i_sar_width / p_param->vui.i_sar_height;
231231 if( sar > 1.0 )
232 dw *= sar ;
232 dw *= sar;
233233 else
234234 dh /= sar;
235235 gf_isom_set_pixel_aspect_ratio( p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_param->vui.i_sar_width, p_param->vui.i_sar_height );
4040
4141 /* For close_file() */
4242 #define MP4_LOG_IF_ERR( cond, ... )\
43 if( cond )\
43 do\
4444 {\
45 MP4_LOG_ERROR( __VA_ARGS__ );\
46 }
45 if( cond )\
46 {\
47 MP4_LOG_ERROR( __VA_ARGS__ );\
48 }\
49 } while( 0 )
4750
4851 /* For open_file() */
4952 #define MP4_FAIL_IF_ERR_EX( cond, ... )\
50 if( cond )\
53 do\
5154 {\
52 remove_mp4_hnd( p_mp4 );\
53 MP4_LOG_ERROR( __VA_ARGS__ );\
54 return -1;\
55 }
55 if( cond )\
56 {\
57 remove_mp4_hnd( p_mp4 );\
58 MP4_LOG_ERROR( __VA_ARGS__ );\
59 return -1;\
60 }\
61 } while( 0 )
5662
5763 /*******************/
5864
5555 // max number of args used by any x264 asm function.
5656 #define MAX_ARGS 15
5757
58 #define ARG_STACK ((8*(MAX_ARGS - 6) + 15) & ~15)
58 #define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15)
5959
6060 function x264_checkasm_call, export=1
6161 stp x29, x30, [sp, #-16]!
8686 sub sp, sp, #ARG_STACK
8787 .equ pos, 0
8888 // first two stacked args are copied to x6, x7
89 .rept MAX_ARGS-6
89 .rept MAX_ARGS-8
9090 ldr x9, [x29, #16 + 16 + pos]
9191 str x9, [sp, #pos]
9292 .equ pos, pos + 8
4444 @ max number of args used by any x264 asm function.
4545 #define MAX_ARGS 15
4646
47 #define ARG_STACK 4*(MAX_ARGS - 2)
47 #define ARG_STACK 4*(MAX_ARGS - 4)
48
49 @ align the used stack space to 8 to preserve the stack alignment
50 #define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed)
4851
4952 .macro clobbercheck variant
5053 .equ pushed, 4*10
6366
6467 push {r1}
6568
66 sub sp, sp, #ARG_STACK
69 sub sp, sp, #ARG_STACK_A
6770 .equ pos, 0
68 .rept MAX_ARGS-2
69 ldr r12, [sp, #ARG_STACK + pushed + 8 + pos]
71 .rept MAX_ARGS-4
72 ldr r12, [sp, #ARG_STACK_A + pushed + 8 + pos]
7073 str r12, [sp, #pos]
7174 .equ pos, pos + 4
7275 .endr
7477 mov r12, r0
7578 mov r0, r2
7679 mov r1, r3
77 ldrd r2, r3, [sp, #ARG_STACK + pushed]
80 ldrd r2, r3, [sp, #ARG_STACK_A + pushed]
7881 blx r12
79 add sp, sp, #ARG_STACK
82 add sp, sp, #ARG_STACK_A
8083 pop {r2}
8184
8285 push {r0, r1}
10241024 x264_zigzag_function_t zigzag_ref[2];
10251025 x264_zigzag_function_t zigzag_asm[2];
10261026
1027 ALIGNED_16( dctcoef level1[64] );
1028 ALIGNED_16( dctcoef level2[64] );
1027 ALIGNED_ARRAY_16( dctcoef, level1,[64] );
1028 ALIGNED_ARRAY_16( dctcoef, level2,[64] );
10291029
10301030 #define TEST_ZIGZAG_SCAN( name, t1, t2, dct, size ) \
10311031 if( zigzag_asm[interlace].name != zigzag_ref[interlace].name ) \
22002200 int dmf = h->dequant4_mf[CQM_4IC][qpdc%6][0] << qpdc/6; \
22012201 if( dmf > 32*64 ) \
22022202 continue; \
2203 for( int i = 16; ; i <<= 1 ) \
2203 for( int i = 16;; i <<= 1 ) \
22042204 { \
22052205 int res_c, res_asm; \
22062206 int max = X264_MIN( i, PIXEL_MAX*16 ); \
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 " r2708 86b7198"'
4 echo '#define X264_POINTVER "0.148.2708 86b7198"'
3 echo '#define X264_VERSION " r2728 4d5c8b0"'
4 echo '#define X264_POINTVER "0.148.2728 4d5c8b0"'
354354 cli_opt_t opt = {0};
355355 int ret = 0;
356356
357 FAIL_IF_ERROR( x264_threading_init(), "unable to initialize threading\n" )
357 FAIL_IF_ERROR( x264_threading_init(), "unable to initialize threading\n" );
358358
359359 #ifdef _WIN32
360 FAIL_IF_ERROR( !get_argv_utf8( &argc, &argv ), "unable to convert command line to UTF-8\n" )
360 FAIL_IF_ERROR( !get_argv_utf8( &argc, &argv ), "unable to convert command line to UTF-8\n" );
361361
362362 GetConsoleTitleW( org_console_title, CONSOLE_TITLE_SIZE );
363363 _setmode( _fileno( stdin ), _O_BINARY );
602602 " - medium:\n"
603603 " Default settings apply.\n"
604604 " - slow:\n"
605 " --b-adapt 2 --direct auto --me umh\n"
606 " --rc-lookahead 50 --ref 5 --subme 8\n"
605 " --direct auto --rc-lookahead 50 --ref 5\n"
606 " --subme 8 --trellis 2\n"
607607 " - slower:\n"
608608 " --b-adapt 2 --direct auto --me umh\n"
609609 " --partitions all --rc-lookahead 60\n"
12551255 cli_input = raw_input;
12561256 }
12571257
1258 FAIL_IF_ERROR( !(*p_handle), "could not open input file `%s' via any method!\n", filename )
1258 FAIL_IF_ERROR( !(*p_handle), "could not open input file `%s' via any method!\n", filename );
12591259 }
12601260 strcpy( used_demuxer, module );
12611261
14311431 output_filename = optarg;
14321432 break;
14331433 case OPT_MUXER:
1434 FAIL_IF_ERROR( parse_enum_name( optarg, muxer_names, &muxer ), "Unknown muxer `%s'\n", optarg )
1434 FAIL_IF_ERROR( parse_enum_name( optarg, muxer_names, &muxer ), "Unknown muxer `%s'\n", optarg );
14351435 break;
14361436 case OPT_DEMUXER:
1437 FAIL_IF_ERROR( parse_enum_name( optarg, demuxer_names, &demuxer ), "Unknown demuxer `%s'\n", optarg )
1437 FAIL_IF_ERROR( parse_enum_name( optarg, demuxer_names, &demuxer ), "Unknown demuxer `%s'\n", optarg );
14381438 break;
14391439 case OPT_INDEX:
14401440 input_opt.index_file = optarg;
14411441 break;
14421442 case OPT_QPFILE:
14431443 opt->qpfile = x264_fopen( optarg, "rb" );
1444 FAIL_IF_ERROR( !opt->qpfile, "can't open qpfile `%s'\n", optarg )
1444 FAIL_IF_ERROR( !opt->qpfile, "can't open qpfile `%s'\n", optarg );
14451445 if( !x264_is_regular_file( opt->qpfile ) )
14461446 {
14471447 x264_cli_log( "x264", X264_LOG_ERROR, "qpfile incompatible with non-regular file `%s'\n", optarg );
14921492 break;
14931493 case OPT_TCFILE_OUT:
14941494 opt->tcfile_out = x264_fopen( optarg, "wb" );
1495 FAIL_IF_ERROR( !opt->tcfile_out, "can't open `%s'\n", optarg )
1495 FAIL_IF_ERROR( !opt->tcfile_out, "can't open `%s'\n", optarg );
14961496 break;
14971497 case OPT_TIMEBASE:
14981498 input_opt.timebase = optarg;
14991499 break;
15001500 case OPT_PULLDOWN:
1501 FAIL_IF_ERROR( parse_enum_value( optarg, pulldown_names, &opt->i_pulldown ), "Unknown pulldown `%s'\n", optarg )
1501 FAIL_IF_ERROR( parse_enum_value( optarg, pulldown_names, &opt->i_pulldown ), "Unknown pulldown `%s'\n", optarg );
15021502 break;
15031503 case OPT_VIDEO_FILTER:
15041504 vid_filters = optarg;
15191519 output_opt.use_dts_compress = 1;
15201520 break;
15211521 case OPT_OUTPUT_CSP:
1522 FAIL_IF_ERROR( parse_enum_value( optarg, output_csp_names, &output_csp ), "Unknown output csp `%s'\n", optarg )
1522 FAIL_IF_ERROR( parse_enum_value( optarg, output_csp_names, &output_csp ), "Unknown output csp `%s'\n", optarg );
15231523 // correct the parsed value to the libx264 csp value
15241524 #if X264_CHROMA_FORMAT
15251525 static const uint8_t output_csp_fix[] = { X264_CHROMA_FORMAT, X264_CSP_RGB };
15291529 param->i_csp = output_csp = output_csp_fix[output_csp];
15301530 break;
15311531 case OPT_INPUT_RANGE:
1532 FAIL_IF_ERROR( parse_enum_value( optarg, range_names, &input_opt.input_range ), "Unknown input range `%s'\n", optarg )
1532 FAIL_IF_ERROR( parse_enum_value( optarg, range_names, &input_opt.input_range ), "Unknown input range `%s'\n", optarg );
15331533 input_opt.input_range += RANGE_AUTO;
15341534 break;
15351535 case OPT_RANGE:
15761576
15771577 /* Get the file name */
15781578 FAIL_IF_ERROR( optind > argc - 1 || !output_filename, "No %s file. Run x264 --help for a list of options.\n",
1579 optind > argc - 1 ? "input" : "output" )
1579 optind > argc - 1 ? "input" : "output" );
15801580
15811581 if( select_output( muxer, output_filename, param ) )
15821582 return -1;
1583 FAIL_IF_ERROR( cli_output.open_file( output_filename, &opt->hout, &output_opt ), "could not open output file `%s'\n", output_filename )
1583 FAIL_IF_ERROR( cli_output.open_file( output_filename, &opt->hout, &output_opt ), "could not open output file `%s'\n", output_filename );
15841584
15851585 input_filename = argv[optind++];
15861586 video_info_t info = {0};
16081608 return -1;
16091609
16101610 FAIL_IF_ERROR( !opt->hin && cli_input.open_file( input_filename, &opt->hin, &info, &input_opt ),
1611 "could not open input file `%s'\n", input_filename )
1611 "could not open input file `%s'\n", input_filename );
16121612
16131613 x264_reduce_fraction( &info.sar_width, &info.sar_height );
16141614 x264_reduce_fraction( &info.fps_num, &info.fps_den );
16181618
16191619 if( tcfile_name )
16201620 {
1621 FAIL_IF_ERROR( b_user_fps, "--fps + --tcfile-in is incompatible.\n" )
1622 FAIL_IF_ERROR( timecode_input.open_file( tcfile_name, &opt->hin, &info, &input_opt ), "timecode input failed\n" )
1621 FAIL_IF_ERROR( b_user_fps, "--fps + --tcfile-in is incompatible.\n" );
1622 FAIL_IF_ERROR( timecode_input.open_file( tcfile_name, &opt->hin, &info, &input_opt ), "timecode input failed\n" );
16231623 cli_input = timecode_input;
16241624 }
1625 else FAIL_IF_ERROR( !info.vfr && input_opt.timebase, "--timebase is incompatible with cfr input\n" )
1625 else FAIL_IF_ERROR( !info.vfr && input_opt.timebase, "--timebase is incompatible with cfr input\n" );
16261626
16271627 /* init threaded input while the information about the input video is unaltered by filtering */
16281628 #if HAVE_THREAD
16591659 uint64_t i_user_timebase_num;
16601660 uint64_t i_user_timebase_den;
16611661 int ret = sscanf( input_opt.timebase, "%"SCNu64"/%"SCNu64, &i_user_timebase_num, &i_user_timebase_den );
1662 FAIL_IF_ERROR( !ret, "invalid argument: timebase = %s\n", input_opt.timebase )
1663 else if( ret == 1 )
1662 FAIL_IF_ERROR( !ret, "invalid argument: timebase = %s\n", input_opt.timebase );
1663 if( ret == 1 )
16641664 {
16651665 i_user_timebase_num = info.timebase_num;
16661666 i_user_timebase_den = strtoul( input_opt.timebase, NULL, 10 );
16671667 }
16681668 FAIL_IF_ERROR( i_user_timebase_num > UINT32_MAX || i_user_timebase_den > UINT32_MAX,
1669 "timebase you specified exceeds H.264 maximum\n" )
1669 "timebase you specified exceeds H.264 maximum\n" );
16701670 opt->timebase_convert_multiplier = ((double)i_user_timebase_den / info.timebase_den)
16711671 * ((double)info.timebase_num / i_user_timebase_num);
16721672 info.timebase_num = i_user_timebase_num;
17181718 if( input_opt.output_range == RANGE_AUTO )
17191719 param->vui.b_fullrange = RANGE_PC;
17201720 /* otherwise fail if they specified tv */
1721 FAIL_IF_ERROR( !param->vui.b_fullrange, "RGB must be PC range" )
1721 FAIL_IF_ERROR( !param->vui.b_fullrange, "RGB must be PC range" );
17221722 }
17231723
17241724 /* Automatically reduce reference frame count to match the user's target level
18391839 }
18401840
18411841 #define FAIL_IF_ERROR2( cond, ... )\
1842 if( cond )\
1842 do\
18431843 {\
1844 x264_cli_log( "x264", X264_LOG_ERROR, __VA_ARGS__ );\
1845 retval = -1;\
1846 goto fail;\
1847 }
1844 if( cond )\
1845 {\
1846 x264_cli_log( "x264", X264_LOG_ERROR, __VA_ARGS__ );\
1847 retval = -1;\
1848 goto fail;\
1849 }\
1850 } while( 0 )
18481851
18491852 static int encode( x264_param_t *param, cli_opt_t *opt )
18501853 {
18801883 pulldown = &pulldown_values[opt->i_pulldown];
18811884 param->i_timebase_num = param->i_fps_den;
18821885 FAIL_IF_ERROR2( fmod( param->i_fps_num * pulldown->fps_factor, 1 ),
1883 "unsupported framerate for chosen pulldown\n" )
1886 "unsupported framerate for chosen pulldown\n" );
18841887 param->i_timebase_den = param->i_fps_num * pulldown->fps_factor;
18851888 }
18861889
18951898
18961899 /* ticks/frame = ticks/second / frames/second */
18971900 ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num;
1898 FAIL_IF_ERROR2( ticks_per_frame < 1 && !param->b_vfr_input, "ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame )
1901 FAIL_IF_ERROR2( ticks_per_frame < 1 && !param->b_vfr_input, "ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame );
18991902 ticks_per_frame = X264_MAX( ticks_per_frame, 1 );
19001903
19011904 if( !param->b_repeat_headers )
19041907 x264_nal_t *headers;
19051908 int i_nal;
19061909
1907 FAIL_IF_ERROR2( x264_encoder_headers( h, &headers, &i_nal ) < 0, "x264_encoder_headers failed\n" )
1910 FAIL_IF_ERROR2( x264_encoder_headers( h, &headers, &i_nal ) < 0, "x264_encoder_headers failed\n" );
19081911 FAIL_IF_ERROR2( (i_file = cli_output.write_headers( opt->hout, headers )) < 0, "error writing headers to output file\n" );
19091912 }
19101913
7070 #endif
7171
7272 #define RETURN_IF_ERR( cond, name, ret, ... )\
73 if( cond )\
73 do\
7474 {\
75 x264_cli_log( name, X264_LOG_ERROR, __VA_ARGS__ );\
76 return ret;\
77 }
75 if( cond )\
76 {\
77 x264_cli_log( name, X264_LOG_ERROR, __VA_ARGS__ );\
78 return ret;\
79 }\
80 } while( 0 )
7881
7982 #define FAIL_IF_ERR( cond, name, ... ) RETURN_IF_ERR( cond, name, -1, __VA_ARGS__ )
8083