13 #define X264_MIN(a, b) ((a) < (b) ? (a) : (b))
14 #define X264_MAX(a, b) ((a) > (b) ? (a) : (b))
15 #define X264_MIN3(a, b, c) X264_MIN((a), X264_MIN((b), (c)))
16 #define X264_MAX3(a, b, c) X264_MAX((a), X264_MAX((b), (c)))
17 #define X264_MIN4(a, b, c, d) X264_MIN((a), X264_MIN3((b), (c), (d)))
18 #define X264_MAX4(a, b, c, d) X264_MAX((a), X264_MAX3((b), (c), (d)))
19 #define XCHG(type, a, b) \
25 #define IS_DISPOSABLE(type) (type == X264_TYPE_B)
26 #define FIX8(f) ((int)(f * (1 << 8) + .5))
27 #define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1))
29 #define CHECKED_MALLOC(var, size) \
31 var = x264_malloc(size); \
35 #define CHECKED_MALLOCZERO(var, size) \
37 CHECKED_MALLOC(var, size); \
38 memset(var, 0, size); \
41 #define X264_BFRAME_MAX 4
42 #define X264_REF_MAX 4
43 #define X264_THREAD_MAX 4
44 #define X264_LOOKAHEAD_THREAD_MAX 2
45 #define X264_LOOKAHEAD_MAX 5
46 #define QP_BD_OFFSET (6 * (BIT_DEPTH - 8))
47 #define QP_MAX_SPEC (51 + QP_BD_OFFSET)
48 #define QP_MAX (QP_MAX_SPEC + 18)
49 #define QP_MAX_MAX (51 + 2 * 6 + 18)
50 #define PIXEL_MAX ((1 << BIT_DEPTH) - 1)
52 #define X264_LOOKAHEAD_QP (12 + QP_BD_OFFSET)
53 #define SPEC_QP(x) X264_MIN((x), QP_MAX_SPEC)
57 #define X264_THREAD_HEIGHT 24
64 #define X264_WEIGHTP_FAKE (-1)
66 #define NALU_OVERHEAD 5
67 #define FILLER_OVERHEAD (NALU_OVERHEAD + 1)
81 #define MB_INTERLACED h->mb.b_interlaced
82 #define SLICE_MBAFF h->sh.b_mbaff
83 #define PARAM_INTERLACED h->param.b_interlaced
85 #define MB_INTERLACED 0
87 #define PARAM_INTERLACED 0
91 #define CHROMA_H_SHIFT (CHROMA_FORMAT == CHROMA_420 || CHROMA_FORMAT == CHROMA_422)
92 #define CHROMA_V_SHIFT (CHROMA_FORMAT == CHROMA_420)
94 #define CHROMA_FORMAT h->sps->i_chroma_format_idc
95 #define CHROMA_H_SHIFT h->mb.chroma_h_shift
96 #define CHROMA_V_SHIFT h->mb.chroma_v_shift
99 #define CHROMA_SIZE(s) ((s) >> (CHROMA_H_SHIFT + CHROMA_V_SHIFT))
100 #define FRAME_SIZE(s) ((s) + 2 * CHROMA_SIZE(s))
131 #define M16(src) (((x264_union16_t *)(src))->i)
132 #define M32(src) (((x264_union32_t *)(src))->i)
133 #define M64(src) (((x264_union64_t *)(src))->i)
134 #define M128(src) (((x264_union128_t *)(src))->i)
135 #define M128_ZERO ((x264_uint128_t){{0, 0}})
136 #define CP16(dst, src) M16(dst) = M16(src)
137 #define CP32(dst, src) M32(dst) = M32(src)
138 #define CP64(dst, src) M64(dst) = M64(src)
139 #define CP128(dst, src) M128(dst) = M128(src)
142 typedef uint16_t pixel;
143 typedef uint64_t pixel4;
144 typedef int32_t dctcoef;
145 typedef uint32_t udctcoef;
147 #define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL)
148 #define MPIXEL_X4(src) M64(src)
150 typedef uint8_t pixel;
151 typedef uint32_t pixel4;
152 typedef int16_t dctcoef;
153 typedef uint16_t udctcoef;
155 #define PIXEL_SPLAT_X4(x) ((x)*0x01010101U)
156 #define MPIXEL_X4(src) M32(src)
159 #define BIT_DEPTH X264_BIT_DEPTH
161 #define CPPIXEL_X4(dst, src) MPIXEL_X4(dst) = MPIXEL_X4(src)
163 #define X264_SCAN8_LUMA_SIZE (5 * 8)
164 #define X264_SCAN8_SIZE (X264_SCAN8_LUMA_SIZE * 3)
165 #define X264_SCAN8_0 (4 + 1 * 8)
195 static const uint8_t x264_scan8[16 * 3 + 3] =
198 4 + 1 * 8, 5 + 1 * 8, 4 + 2 * 8, 5 + 2 * 8,
199 6 + 1 * 8, 7 + 1 * 8, 6 + 2 * 8, 7 + 2 * 8,
200 4 + 3 * 8, 5 + 3 * 8, 4 + 4 * 8, 5 + 4 * 8,
201 6 + 3 * 8, 7 + 3 * 8, 6 + 4 * 8, 7 + 4 * 8,
203 4 + 6 * 8, 5 + 6 * 8, 4 + 7 * 8, 5 + 7 * 8,
204 6 + 6 * 8, 7 + 6 * 8, 6 + 7 * 8, 7 + 7 * 8,
205 4 + 8 * 8, 5 + 8 * 8, 4 + 9 * 8, 5 + 9 * 8,
206 6 + 8 * 8, 7 + 8 * 8, 6 + 9 * 8, 7 + 9 * 8,
208 4 + 11 * 8, 5 + 11 * 8, 4 + 12 * 8, 5 + 12 * 8,
209 6 + 11 * 8, 7 + 11 * 8, 6 + 12 * 8, 7 + 12 * 8,
210 4 + 13 * 8, 5 + 13 * 8, 4 + 14 * 8, 5 + 14 * 8,
211 6 + 13 * 8, 7 + 13 * 8, 6 + 14 * 8, 7 + 14 * 8,
212 0 + 0 * 8, 0 + 5 * 8, 0 + 10 * 8};
215 #include "bitstream.h"
230 void *x264_malloc(
int);
231 void x264_free(
void *);
238 void x264_log(
x264_t *h,
int i_level,
const char *psz_fmt, ...);
240 void x264_cavlc_init(
x264_t *h);
241 void x264_cabac_init(
x264_t *h);
243 static ALWAYS_INLINE pixel x264_clip_pixel(
int x) {
244 return ((x & ~PIXEL_MAX) ? (-x) >> 31 & PIXEL_MAX : x);
247 static ALWAYS_INLINE
int x264_clip3(
int v,
int i_min,
int i_max) {
248 return ((v < i_min) ? i_min : (v > i_max) ? i_max
252 static ALWAYS_INLINE
double x264_clip3f(
double v,
double f_min,
double f_max) {
253 return ((v < f_min) ? f_min : (v > f_max) ? f_max
257 #if defined(__TI_COMPILER_VERSION__) && HAVE_TIC6X
258 static ALWAYS_INLINE
void x264_median_mv(int16_t *dst, int16_t *a, int16_t *b, int16_t *c) {
264 mvd = _min2(mva, mvb);
265 mva = _max2(mva, mvb);
266 mvd = _max2(mvd, mvc);
267 mvd = _min2(mvd, mva);
271 static ALWAYS_INLINE
int x264_median(
int a,
int b,
int c) {
272 int t = (a - b) & ((a - b) >> 31);
275 b -= (b - c) & ((b - c) >> 31);
276 b += (a - b) & ((a - b) >> 31);
280 static ALWAYS_INLINE
void x264_median_mv(int16_t *dst, int16_t *a, int16_t *b, int16_t *c) {
281 dst[0] = x264_median(a[0], b[0], c[0]);
282 dst[1] = x264_median(a[1], b[1], c[1]);
286 #if defined(__TI_COMPILER_VERSION__) && HAVE_TIC6X
287 static void ALWAYS_INLINE x264_predictor_roundclip(int16_t (*dst)[2], int16_t (*mvc)[2],
int i_mvc,
int mv_x_min,
int mv_x_max,
int mv_y_min,
int mv_y_max) {
288 int mv_min = _spack2(mv_y_min, mv_x_min);
289 int mv_max = _spack2(mv_y_max, mv_x_max);
290 int k_2 = 0x00020002;
293 for (i = 0; i < i_mvc; i++) {
297 mv = _max2(mv, mv_min);
298 mv = _min2(mv, mv_max);
303 static void ALWAYS_INLINE x264_predictor_roundclip(int16_t (*dst)[2], int16_t (*mvc)[2],
int i_mvc,
int mv_x_min,
int mv_x_max,
int mv_y_min,
int mv_y_max) {
305 for (i = 0; i < i_mvc; i++) {
306 int mx = (mvc[i][0] + 2) >> 2;
307 int my = (mvc[i][1] + 2) >> 2;
308 dst[i][0] = x264_clip3(mx, mv_x_min, mv_x_max);
309 dst[i][1] = x264_clip3(my, mv_y_min, mv_y_max);
314 extern const float x264_log2_lut[128];
315 extern const float x264_log2_lz_lut[32];
317 static ALWAYS_INLINE
float x264_log2(uint32_t x) {
318 int lz = x264_clz(x);
319 return x264_log2_lut[(x << lz >> 24) & 0x7f] + x264_log2_lz_lut[lz];
328 static const char slice_type_to_char[] = {
'P',
'B',
'I'};
331 enum sei_payload_type_e {
332 SEI_BUFFERING_PERIOD = 0,
334 SEI_PAN_SCAN_RECT = 2,
336 SEI_USER_DATA_REGISTERED = 4,
337 SEI_USER_DATA_UNREGISTERED = 5,
338 SEI_RECOVERY_POINT = 6,
339 SEI_DEC_REF_PIC_MARKING = 7,
340 SEI_FRAME_PACKING = 45,
375 int i_delta_poc_bottom;
378 int i_redundant_pic_cnt;
381 int b_direct_spatial_mv_pred;
384 int b_num_ref_idx_override;
386 int i_num_ref_idx_l0_active;
388 int i_num_ref_idx_l1_active;
391 int b_ref_pic_list_reordering[2];
396 } ref_pic_list_order[2][X264_REF_MAX];
403 int i_mmco_remove_from_end;
404 int i_mmco_command_count;
407 int i_difference_of_pic_nums;
409 } mmco[X264_REF_MAX];
413 int i_cabac_init_idc;
444 int i_disable_deblocking_filter_idc;
445 int i_alpha_c0_offset;
450 volatile uint8_t b_exit_thread;
451 uint8_t b_thread_active;
452 uint8_t b_analyse_keyframe;
454 int i_slicetype_length;
456 x264_pthread_t thread_handle;
466 uint8_t nnz_chroma[4];
485 int i_mb_count_8x8dct[2];
486 int i_mb_count_ref[2][X264_REF_MAX * 2];
487 int i_mb_partition[17];
489 int i_mb_pred_mode[4][13];
492 int i_direct_score[2];
503 x264_t *thread[X264_THREAD_MAX + 1];
504 x264_t *lookahead_thread[X264_LOOKAHEAD_THREAD_MAX];
508 int i_threadslice_start;
509 int i_threadslice_end;
510 int i_threadslice_pass;
516 int i_nals_allocated;
519 uint8_t *p_bitstream;
539 int64_t i_disp_fields;
540 int i_disp_fields_last_frame;
541 int64_t i_prev_duration;
542 int64_t i_coded_fields;
545 int64_t i_coded_fields_lookahead;
546 int64_t i_cpb_delay_lookahead;
548 int64_t i_cpb_delay_pir_offset;
549 int64_t i_cpb_delay_pir_offset_next;
551 int b_queued_intra_refresh;
552 int64_t i_last_idr_pts;
558 int (*dequant4_mf[4])[16];
560 udctcoef (*quant4_mf[4])[16];
561 udctcoef (*quant4_bias[4])[16];
568 uint16_t *cost_mv[QP_MAX + 1];
574 const uint8_t *chroma_qp_table;
605 int i_poc_last_open_gop;
616 int64_t i_bframe_delay_time;
618 int64_t i_prev_reordered_pts[2];
619 int64_t i_largest_pts;
620 int64_t i_second_largest_pts;
627 int b_have_sub8x8_esa;
640 int b_ref_reorder[2];
643 int initial_cpb_removal_delay;
644 int initial_cpb_removal_delay_offset;
645 int64_t i_reordered_pts_delay;
705 int b_noise_reduction;
711 int b_adaptive_mbaff;
722 int mv_miny_spel_row[3];
723 int mv_maxy_spel_row[3];
727 int mv_miny_fpel_row[3];
728 int mv_maxy_fpel_row[3];
731 unsigned int i_neighbour;
745 unsigned int i_neighbour8[4];
763 unsigned int i_neighbour4[16];
764 unsigned int i_neighbour_intra;
765 unsigned int i_neighbour_frame;
767 int i_mb_type_left[2];
768 int i_mb_type_topleft;
769 int i_mb_type_topright;
774 int i_mb_topright_xy;
779 int i_mb_top_mbpair_xy;
780 int topleft_partition;
782 int field_decoding_flag;
793 int8_t (*intra4x4_pred_mode)[8];
795 uint8_t (*non_zero_count)[16 * 3];
796 int8_t *chroma_pred_mode;
798 uint8_t (*mvd[2])[8][2];
800 int16_t (*mvr[2][X264_REF_MAX * 2])[2];
802 int8_t *mb_transform_size;
803 uint16_t *slice_table;
808 pixel *p_weight_buf[X264_REF_MAX];
830 ALIGNED_4(uint8_t i_sub_partition[4]);
861 int i_intra16x16_pred_mode;
862 int i_chroma_pred_mode;
883 #define FENC_STRIDE 16
884 #define FDEC_STRIDE 32
891 uint32_t i4x4_nnz_buf[4];
897 pixel *p_fenc_plane[3];
917 pixel *p_fref[2][X264_REF_MAX * 2][12];
918 pixel *p_fref_w[X264_REF_MAX * 2];
928 ALIGNED_8(int8_t intra4x4_pred_mode[X264_SCAN8_LUMA_SIZE]);
931 ALIGNED_16(uint8_t non_zero_count[X264_SCAN8_SIZE]);
934 ALIGNED_4(int8_t ref[2][X264_SCAN8_LUMA_SIZE]);
937 ALIGNED_16(int16_t mv[2][X264_SCAN8_LUMA_SIZE][2]);
938 ALIGNED_8(uint8_t mvd[2][X264_SCAN8_LUMA_SIZE][2]);
941 ALIGNED_4(int8_t skip[X264_SCAN8_LUMA_SIZE]);
943 ALIGNED_4(int16_t direct_mv[2][4][2]);
944 ALIGNED_4(int8_t direct_ref[2][4]);
945 int direct_partition;
946 ALIGNED_4(int16_t pskip_mv[2]);
949 int i_neighbour_transform_size;
950 int i_neighbour_skip;
957 int16_t topright_mv[2][3][2];
958 int8_t topright_ref[2][3];
961 uint8_t (*deblock_strength)[8][4];
971 int b_direct_auto_read;
972 int b_direct_auto_write;
975 int16_t dist_scale_factor_buf[2][2][X264_REF_MAX * 2][4];
976 int16_t (*dist_scale_factor)[4];
977 int8_t bipred_weight_buf[2][2][X264_REF_MAX * 2][4];
978 int8_t (*bipred_weight)[4];
980 #define map_col_to_list0(col) h->mb.map_col_to_list0[(col) + 2]
981 int8_t map_col_to_list0[X264_REF_MAX + 2];
983 int8_t deblock_ref_table[X264_REF_MAX * 2 + 2];
984 #define deblock_ref_table(x) h->mb.deblock_ref_table[(x) + 2]
999 int i_frame_count[3];
1000 int64_t i_frame_size[3];
1001 double f_frame_qp[3];
1002 int i_consecutive_bframes[X264_BFRAME_MAX + 1];
1006 double f_ssd_global[3];
1007 double f_psnr_average[3];
1008 double f_psnr_mean_y[3];
1009 double f_psnr_mean_u[3];
1010 double f_psnr_mean_v[3];
1011 double f_ssim_mean_y[3];
1012 double f_frame_duration[3];
1024 int64_t i_mb_count[3][19];
1039 int64_t i_mb_partition[2][17];
1040 int64_t i_mb_count_8x8dct[2];
1048 int64_t i_mb_count_ref[2][2][X264_REF_MAX * 2];
1058 int64_t i_mb_cbp[6];
1067 int64_t i_mb_pred_mode[4][13];
1068 int64_t i_mb_field[3];
1072 int i_direct_score[2];
1074 int i_direct_frames[2];
1081 udctcoef (*nr_offset)[64];
1082 uint32_t (*nr_residual_sum)[64];
1085 ALIGNED_16(udctcoef nr_offset_denoise[4][64]);
1086 ALIGNED_16(uint32_t nr_residual_sum_buf[2][4][64]);
1087 uint32_t nr_count_buf[2][4];
1089 uint8_t luma2chroma_pixel[7];
1092 void *scratch_buffer;
1093 void *scratch_buffer2;
1094 pixel *intra_border_backup[5][3];
1097 uint8_t (*deblock_strength[2])[2][8][4];
1100 x264_predict_t predict_16x16[4 + 3];
1101 x264_predict_t predict_4x4[9 + 3];
1102 x264_predict_t predict_chroma[4 + 3];
1103 x264_predict_t predict_8x8c[4 + 3];
1116 #include "macroblock.h"
1118 #include "rectangle.h"
Definition: bitstream.h:22
Definition: bitstream.h:46
Definition: ratecontrol.c:83