x264-dsp
frame.h
1 /*****************************************************************************
2  * frame.h: frame handling
3  *****************************************************************************/
4 
5 #ifndef X264_FRAME_H
6 #define X264_FRAME_H
7 
8 /* number of pixels past the edge of the frame, for motion estimation/compensation */
9 #define PADH 32 /* padding of horizontal */
10 #define PADV 32 /* padding of vertical */
11 
12 typedef struct x264_frame {
13  int i_poc; /* picture order count */
14  int i_delta_poc[2];
15  int i_type; /* current frame type. IDR/I/P/B */
16  int i_qpplus1; /* current frame QP plus one */
17  int64_t i_pts; /* present timestamp */
18  int64_t i_dts; /* decode timestamp */
19  int64_t i_reordered_pts;
20  int64_t i_duration; /* in SPS time_scale units (i.e 2 * timebase units) used for vfr */
21  float f_duration; /* in seconds */
22  int64_t i_cpb_duration;
23  int64_t i_cpb_delay; /* in SPS time_scale units (i.e 2 * timebase units) */
24  int64_t i_dpb_output_delay;
25  x264_param_t *param;
26 
27  int i_frame; /* Presentation frame number */
28  int i_coded; /* Coded frame number */
29  int64_t i_field_cnt; /* Presentation field count */
30  int i_frame_num; /* 7.4.3 frame_num */
31  int b_kept_as_ref; /* Kept as reference flag. Set 1 if (i_nal_ref_idc != NAL_PRIORITY_DISPOSABLE && h->param.i_keyint_max > 1) */
32  int i_pic_struct;
33  int b_keyframe; /* key frame flag */
34  uint8_t b_fdec; /* whether uses as a decoded frame or as a encoding frame */
35  uint8_t b_last_minigop_bframe; /* this frame is the last b in a sequence of bframes */
36  uint8_t i_bframes; /* number of bframes following this nonb in coded order */
37  float f_qp_avg_rc; /* QPs as decided by ratecontrol */
38  float f_qp_avg_aq; /* QPs as decided by AQ in addition to ratecontrol */
39  float f_crf_avg; /* Average effective CRF for this frame */
40  int i_poc_l0ref0; /* poc of first refframe in L0, used to check if direct temporal is possible */
41 
42  /* YUV buffer */
43  int i_csp; /* color space. default: i420 */
44  /********************************************************
45  * plane count. *
46  * for I420/I422, set i_plane = 2. *
47  * one for luma, the other for chroma (uv interleaved) *
48  * for I444, set i_plane = 3. *
49  ********************************************************/
50  int i_plane;
51  /* stride of luma/chroma in pixel. luma = chroma = width + 2 * PADH
52  * e.g. (1280 + 2 * 32) = 1344 for 720P */
53  int i_stride[3];
54  /* width of luma/chroma in pixel.
55  * e.g. [0]:1280, [1]:640 for 720P */
56  int i_width[3];
57  /* lines of luma/chroma in pixel.
58  * e.g. [0]:720, [1]:360 for 720P */
59  int i_lines[3];
60  /* stride for low resolution (half-size). width / 2 + 2 * PADH
61  * e.g. (1280 / 2 + 2 * 32) = 704 for 720P */
62  int i_stride_lowres;
63  /* width for low resolution (half-size).
64  * e.g. 1280 / 2 = 640 for 720P */
65  int i_width_lowres;
66  /* lines for low resolution (half-size).
67  * e.g. 720 / 2 = 360 for 720P */
68  int i_lines_lowres;
69 
70  pixel *plane[3]; /* plane[0]: luma, plane[1]: chroma (uv interleaved) */
71  pixel *filtered[3][4]; /* plane[0], H, V, HV of all luma plane */
72  pixel *lowres[4]; /* half-size copy of input frame: Orig, H, V, HV */
73  /*uint16_t *integral;*/ /* integral plane data. used only in ESA */
74 
75  /**********************************************************************************************
76  * for unrestricted mv we allocate more data than needed allocated data are stored in buffer. *
77  * *
78  * luma (full and 1/2 pixel) chroma (uv interleaved) *
79  * buffer[0] => ************************** buffer[1] => ************************** *
80  * * 32 * * 16 * *
81  * plane[0] => * => YYYYYYYYYYYYYYYY * plane[1] => * => UVUVUVUVUVUVUVUV * *
82  * filtered[0][0] * YYYYYYYYYYYYYYYY * * 32 UVUVUVUVUVUVUVUV 32 * *
83  * * 32 YYYYYYYYYYYYYYYY 32 * * 16 * *
84  * * YYYYYYYYYYYYYYYY * ************************** *
85  * * 32 * *
86  * ************************** *
87  * ************************** *
88  * * 32 * *
89  * filtered[0][1] => * => YYYYYYYYYYYYYYYY * *
90  * * YYYYYYYYYYYYYYYY * *
91  * (1/2 H) * 32 YYYYYYYYYYYYYYYY 32 * *
92  * * YYYYYYYYYYYYYYYY * *
93  * * 32 * *
94  * ************************** *
95  * ************************** *
96  * * 32 * *
97  * filtered[0][2] => * => YYYYYYYYYYYYYYYY * *
98  * * YYYYYYYYYYYYYYYY * *
99  * (1/2 V) * 32 YYYYYYYYYYYYYYYY 32 * *
100  * * YYYYYYYYYYYYYYYY * *
101  * * 32 * *
102  * ************************** *
103  * ************************** *
104  * * 32 * *
105  * filtered[0][3] => * => YYYYYYYYYYYYYYYY * *
106  * * YYYYYYYYYYYYYYYY * *
107  * (1/2 HV) * 32 YYYYYYYYYYYYYYYY 32 * *
108  * * YYYYYYYYYYYYYYYY * *
109  * * 32 * *
110  * ************************** *
111  * *
112  **********************************************************************************************/
113  pixel *buffer[4];
114  /* buffer for half-resolution */
115  pixel *buffer_lowres[4];
116 
117  /* weighted frame */
118  x264_weight_t weight[X264_REF_MAX][3]; /* [ref_index][plane] */
119  pixel *weighted[X264_REF_MAX]; /* plane[0] weighted of the reference frames */
120  int b_duplicate; /* whether frame is a blank copy of real frame (including pointers) */
121  struct x264_frame *orig;
122 
123  /* motion data, used only for reconstruction frame (fdec) */
124  int8_t *mb_type; /* mb type table for all mbs of current frame */
125  uint8_t *mb_partition; /* mb partition table for all mbs of current frame */
126  int16_t (*mv[2])[2]; /* motion vectors for all mbs of current frame */
127  int16_t (*mv16x16)[2];
128  int16_t (*lowres_mvs[2][X264_BFRAME_MAX + 1])[2];
129  uint8_t *field;
130  uint8_t *effective_qp; /* effective qp table for all mbs of current frame. used only when x264_param_t.analyse.b_mb_info enabled */
131 
132  /* Stored as (lists_used << LOWRES_COST_SHIFT) + (cost).
133  * Doesn't need special addressing for intra cost because
134  * lists_used is guaranteed to be zero in that cast. */
135  /*
136  uint16_t (*lowres_costs[X264_BFRAME_MAX+2][X264_BFRAME_MAX+2]);
137  #define LOWRES_COST_MASK ((1<<14)-1)
138  #define LOWRES_COST_SHIFT 14
139  */
140 
141  int *lowres_mv_costs[2][X264_BFRAME_MAX + 1];
142  int8_t *ref[2]; /* reference frames of list 0/1 for all mbs of current frame */
143  int i_ref[2];
144  int ref_poc[2][X264_REF_MAX];
145  int16_t inv_ref_poc[2]; // inverse values of ref0 poc to avoid divisions in temporal MV prediction
146 
147  /* for adaptive B-frame decision.
148  * contains the SATD cost of the lowres frame encoded in various modes.
149  */
150  int i_cost_est[X264_BFRAME_MAX + 2][X264_BFRAME_MAX + 2];
151  int i_cost_est_aq[X264_BFRAME_MAX + 2][X264_BFRAME_MAX + 2];
152  int i_satd; /* the i_cost_est of the selected frame type */
153  int i_intra_mbs[X264_BFRAME_MAX + 2];
154  int *i_row_satds[X264_BFRAME_MAX + 2][X264_BFRAME_MAX + 2];
155  int *i_row_satd;
156  int *i_row_bits; /* accumulated encoded mb bits for each row */
157  float *f_row_qp;
158  float *f_row_qscale;
159  float *f_qp_offset; /* qp offset for each mb. values are depending on ac energy of each mb and AQ strength. */
160  float *f_qp_offset_aq; /* qp offset for each mb. values are depending on ac energy of each mb and AQ strength. */
161  int b_intra_calculated;
162  uint32_t i_pixel_sum[3]; /* sum of pixel value for y/u/v */
163  uint64_t i_pixel_ssd[3]; /* sum of squared pixel value for y/u/v */
164 
165  /* hrd */
166  x264_hrd_t hrd_timing;
167 
168  /* vbv */
169  uint8_t i_planned_type[X264_LOOKAHEAD_MAX + 1];
170  int i_planned_satd[X264_LOOKAHEAD_MAX + 1];
171  double f_planned_cpb_duration[X264_LOOKAHEAD_MAX + 1];
172  int64_t i_coded_fields_lookahead;
173  int64_t i_cpb_delay_lookahead;
174 
175  /* threading */
176  int i_lines_completed; /* in pixels */
177  int i_lines_weighted; /* FIXME: this only supports weighting of one reference frame */
178  int i_reference_count; /* number of threads using this frame (not necessarily the number of pointers) */
179 
180  /* periodic intra refresh */
181  float f_pir_position;
182  int i_pir_start_col;
183  int i_pir_end_col;
184  int i_frames_since_pir;
185 
186  /* interactive encoder control */
187  int b_corrupt;
188 
189  /* user data */
190  void *opaque;
191 
192  /* user frame properties. see comment of x264_image_properties_t from x264.h */
193  uint8_t *mb_info; /* copy from x264_picture_t.prop.mb_info */
194  void (*mb_info_free)(void *); /* copy from x264_picture_t.prop.mb_info_free */
195 } x264_frame_t;
196 
197 /* synchronized frame list */
198 typedef struct
199 {
200  x264_frame_t **list;
201  int i_max_size;
202  int i_size;
204 
205 typedef void (*x264_deblock_inter_t)(pixel *pix, intptr_t stride, int alpha, int beta, int8_t *tc0);
206 typedef void (*x264_deblock_intra_t)(pixel *pix, intptr_t stride, int alpha, int beta);
207 typedef struct
208 {
209  x264_deblock_inter_t deblock_luma[2];
210  x264_deblock_inter_t deblock_chroma[2];
211  x264_deblock_intra_t deblock_luma_intra[2];
212  x264_deblock_intra_t deblock_chroma_intra[2];
213  void (*deblock_strength)(uint8_t nnz[X264_SCAN8_SIZE], int8_t ref[2][X264_SCAN8_LUMA_SIZE],
214  int16_t mv[2][X264_SCAN8_LUMA_SIZE][2], uint8_t bs[2][8][4]);
216 
217 void x264_frame_delete(x264_frame_t *frame);
218 
219 int x264_frame_copy_picture(x264_t *h, x264_frame_t *dst, x264_picture_t *src);
220 
221 void x264_frame_expand_border(x264_t *h, x264_frame_t *frame, int mb_y);
222 void x264_frame_expand_border_filtered(x264_t *h, x264_frame_t *frame, int mb_y, int b_end);
223 void x264_frame_expand_border_lowres(x264_frame_t *frame);
224 void x264_frame_expand_border_mod16(x264_t *h, x264_frame_t *frame);
225 
226 void x264_frame_deblock_row(x264_t *h, int mb_y);
227 
228 void x264_frame_filter(x264_t *h, x264_frame_t *frame, int mb_y, int b_end);
229 void x264_frame_init_lowres(x264_t *h, x264_frame_t *frame);
230 
231 void x264_deblock_init(int cpu, x264_deblock_function_t *pf);
232 
233 void x264_frame_push(x264_frame_t **list, x264_frame_t *frame);
234 x264_frame_t *x264_frame_pop(x264_frame_t **list);
235 void x264_frame_unshift(x264_frame_t **list, x264_frame_t *frame);
236 x264_frame_t *x264_frame_shift(x264_frame_t **list);
237 void x264_frame_push_unused(x264_t *h, x264_frame_t *frame);
238 void x264_frame_push_blank_unused(x264_t *h, x264_frame_t *frame);
239 x264_frame_t *x264_frame_pop_blank_unused(x264_t *h);
240 x264_frame_t *x264_frame_pop_unused(x264_t *h, int b_fdec);
241 void x264_frame_delete_list(x264_frame_t **list);
242 
243 int x264_sync_frame_list_init(x264_sync_frame_list_t *slist, int nelem);
244 void x264_sync_frame_list_delete(x264_sync_frame_list_t *slist);
245 void x264_sync_frame_list_push(x264_sync_frame_list_t *slist, x264_frame_t *frame);
246 x264_frame_t *x264_sync_frame_list_pop(x264_sync_frame_list_t *slist);
247 
248 #endif
Definition: frame.h:208
Definition: frame.h:12
Definition: x264.h:771
Definition: x264.h:187
Definition: x264.h:844
Definition: frame.h:199
Definition: common.h:499
Definition: mc.h:10