/work/x264/common/frame.c
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * frame.c: frame handling |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2003-2025 x264 project |
5 | | * |
6 | | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
7 | | * Loren Merritt <lorenm@u.washington.edu> |
8 | | * Fiona Glaser <fiona@x264.com> |
9 | | * |
10 | | * This program is free software; you can redistribute it and/or modify |
11 | | * it under the terms of the GNU General Public License as published by |
12 | | * the Free Software Foundation; either version 2 of the License, or |
13 | | * (at your option) any later version. |
14 | | * |
15 | | * This program is distributed in the hope that it will be useful, |
16 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | * GNU General Public License for more details. |
19 | | * |
20 | | * You should have received a copy of the GNU General Public License |
21 | | * along with this program; if not, write to the Free Software |
22 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
23 | | * |
24 | | * This program is also available under a commercial proprietary license. |
25 | | * For more information, contact us at licensing@x264.com. |
26 | | *****************************************************************************/ |
27 | | |
28 | | #include "common.h" |
29 | | |
30 | | static int align_stride( int x, int align, int disalign ) |
31 | 2.14k | { |
32 | 2.14k | x = ALIGN( x, align ); |
33 | 2.14k | if( !(x&(disalign-1)) ) |
34 | 0 | x += align; |
35 | 2.14k | return x; |
36 | 2.14k | } |
37 | | |
38 | | static int align_plane_size( int x, int disalign ) |
39 | 2.48k | { |
40 | 2.48k | if( !(x&(disalign-1)) ) |
41 | 1.07k | x += X264_MAX( 128, NATIVE_ALIGN ) / SIZEOF_PIXEL; |
42 | 2.48k | return x; |
43 | 2.48k | } |
44 | | |
45 | | static int frame_internal_csp( int external_csp ) |
46 | 1.24k | { |
47 | 1.24k | int csp = external_csp & X264_CSP_MASK; |
48 | 1.24k | if( csp == X264_CSP_I400 ) |
49 | 0 | return X264_CSP_I400; |
50 | 1.24k | if( csp >= X264_CSP_I420 && csp < X264_CSP_I422 ) |
51 | 1.24k | return X264_CSP_NV12; |
52 | 0 | if( csp >= X264_CSP_I422 && csp < X264_CSP_I444 ) |
53 | 0 | return X264_CSP_NV16; |
54 | 0 | if( csp >= X264_CSP_I444 && csp <= X264_CSP_RGB ) |
55 | 0 | return X264_CSP_I444; |
56 | 0 | return X264_CSP_NONE; |
57 | 0 | } |
58 | | |
59 | | static x264_frame_t *frame_new( x264_t *h, int b_fdec ) |
60 | 1.07k | { |
61 | 1.07k | x264_frame_t *frame; |
62 | 1.07k | int i_csp = frame_internal_csp( h->param.i_csp ); |
63 | 1.07k | int i_mb_count = h->mb.i_mb_count; |
64 | 1.07k | int i_stride, i_width, i_lines, luma_plane_count; |
65 | 1.07k | int i_padv = PADV << PARAM_INTERLACED; |
66 | 1.07k | int align = NATIVE_ALIGN / SIZEOF_PIXEL; |
67 | 1.07k | #if ARCH_X86 || ARCH_X86_64 |
68 | 1.07k | if( h->param.cpu&X264_CPU_CACHELINE_64 || h->param.cpu&X264_CPU_AVX512 ) |
69 | 0 | align = 64 / SIZEOF_PIXEL; |
70 | 1.07k | else if( h->param.cpu&X264_CPU_CACHELINE_32 || h->param.cpu&X264_CPU_AVX ) |
71 | 0 | align = 32 / SIZEOF_PIXEL; |
72 | 1.07k | else |
73 | 1.07k | align = 16 / SIZEOF_PIXEL; |
74 | 1.07k | #endif |
75 | | #if ARCH_PPC |
76 | | int disalign = (1<<9) / SIZEOF_PIXEL; |
77 | | #else |
78 | 1.07k | int disalign = (1<<10) / SIZEOF_PIXEL; |
79 | 1.07k | #endif |
80 | | |
81 | 1.07k | CHECKED_MALLOCZERO( frame, sizeof(x264_frame_t) ); |
82 | 1.07k | PREALLOC_INIT |
83 | | |
84 | | /* allocate frame data (+64 for extra data for me) */ |
85 | 1.07k | i_width = h->mb.i_mb_width*16; |
86 | 1.07k | i_lines = h->mb.i_mb_height*16; |
87 | 1.07k | i_stride = align_stride( i_width + PADH2, align, disalign ); |
88 | | |
89 | 1.07k | if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 ) |
90 | 1.07k | { |
91 | 1.07k | luma_plane_count = 1; |
92 | 1.07k | frame->i_plane = 2; |
93 | 3.21k | for( int i = 0; i < 2; i++ ) |
94 | 2.14k | { |
95 | 2.14k | frame->i_width[i] = i_width >> i; |
96 | 2.14k | frame->i_lines[i] = i_lines >> (i && i_csp == X264_CSP_NV12); |
97 | 2.14k | frame->i_stride[i] = i_stride; |
98 | 2.14k | } |
99 | 1.07k | } |
100 | 0 | else if( i_csp == X264_CSP_I444 ) |
101 | 0 | { |
102 | 0 | luma_plane_count = 3; |
103 | 0 | frame->i_plane = 3; |
104 | 0 | for( int i = 0; i < 3; i++ ) |
105 | 0 | { |
106 | 0 | frame->i_width[i] = i_width; |
107 | 0 | frame->i_lines[i] = i_lines; |
108 | 0 | frame->i_stride[i] = i_stride; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | else if( i_csp == X264_CSP_I400 ) |
112 | 0 | { |
113 | 0 | luma_plane_count = 1; |
114 | 0 | frame->i_plane = 1; |
115 | 0 | frame->i_width[0] = i_width; |
116 | 0 | frame->i_lines[0] = i_lines; |
117 | 0 | frame->i_stride[0] = i_stride; |
118 | 0 | } |
119 | 0 | else |
120 | 0 | goto fail; |
121 | | |
122 | 1.07k | frame->i_csp = i_csp; |
123 | 1.07k | frame->i_width_lowres = frame->i_width[0]/2; |
124 | 1.07k | frame->i_lines_lowres = frame->i_lines[0]/2; |
125 | 1.07k | frame->i_stride_lowres = align_stride( frame->i_width_lowres + PADH2, align, disalign<<1 ); |
126 | | |
127 | 5.43k | for( int i = 0; i < h->param.i_bframe + 2; i++ ) |
128 | 24.1k | for( int j = 0; j < h->param.i_bframe + 2; j++ ) |
129 | 19.8k | PREALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) ); |
130 | | |
131 | 1.07k | frame->i_poc = -1; |
132 | 1.07k | frame->i_type = X264_TYPE_AUTO; |
133 | 1.07k | frame->i_qpplus1 = X264_QP_AUTO; |
134 | 1.07k | frame->i_pts = -1; |
135 | 1.07k | frame->i_frame = -1; |
136 | 1.07k | frame->i_frame_num = -1; |
137 | 1.07k | frame->i_lines_completed = -1; |
138 | 1.07k | frame->b_fdec = b_fdec; |
139 | 1.07k | frame->i_pic_struct = PIC_STRUCT_AUTO; |
140 | 1.07k | frame->i_field_cnt = -1; |
141 | 1.07k | frame->i_duration = |
142 | 1.07k | frame->i_cpb_duration = |
143 | 1.07k | frame->i_dpb_output_delay = |
144 | 1.07k | frame->i_cpb_delay = 0; |
145 | 1.07k | frame->i_coded_fields_lookahead = |
146 | 1.07k | frame->i_cpb_delay_lookahead = -1; |
147 | | |
148 | 1.07k | frame->orig = frame; |
149 | | |
150 | 1.07k | if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 ) |
151 | 1.07k | { |
152 | 1.07k | int chroma_padv = i_padv >> (i_csp == X264_CSP_NV12); |
153 | 1.07k | int chroma_plane_size = (frame->i_stride[1] * (frame->i_lines[1] + 2*chroma_padv)); |
154 | 1.07k | PREALLOC( frame->buffer[1], chroma_plane_size * SIZEOF_PIXEL ); |
155 | 1.07k | if( PARAM_INTERLACED ) |
156 | 0 | PREALLOC( frame->buffer_fld[1], chroma_plane_size * SIZEOF_PIXEL ); |
157 | 1.07k | } |
158 | | |
159 | | /* all 4 luma planes allocated together, since the cacheline split code |
160 | | * requires them to be in-phase wrt cacheline alignment. */ |
161 | | |
162 | 2.14k | for( int p = 0; p < luma_plane_count; p++ ) |
163 | 1.07k | { |
164 | 1.07k | int64_t luma_plane_size = align_plane_size( frame->i_stride[p] * (frame->i_lines[p] + 2*i_padv), disalign ); |
165 | 1.07k | if( h->param.analyse.i_subpel_refine && b_fdec ) |
166 | 903 | luma_plane_size *= 4; |
167 | | |
168 | | /* FIXME: Don't allocate both buffers in non-adaptive MBAFF. */ |
169 | 1.07k | PREALLOC( frame->buffer[p], luma_plane_size * SIZEOF_PIXEL ); |
170 | 1.07k | if( PARAM_INTERLACED ) |
171 | 0 | PREALLOC( frame->buffer_fld[p], luma_plane_size * SIZEOF_PIXEL ); |
172 | 1.07k | } |
173 | | |
174 | 1.07k | frame->b_duplicate = 0; |
175 | | |
176 | 1.07k | if( b_fdec ) /* fdec frame */ |
177 | 903 | { |
178 | 903 | PREALLOC( frame->mb_type, i_mb_count * sizeof(int8_t) ); |
179 | 903 | PREALLOC( frame->mb_partition, i_mb_count * sizeof(uint8_t) ); |
180 | 903 | PREALLOC( frame->mv[0], 2*16 * i_mb_count * sizeof(int16_t) ); |
181 | 903 | PREALLOC( frame->mv16x16, 2*(i_mb_count+1) * sizeof(int16_t) ); |
182 | 903 | PREALLOC( frame->ref[0], 4 * i_mb_count * sizeof(int8_t) ); |
183 | 903 | if( h->param.i_bframe ) |
184 | 623 | { |
185 | 623 | PREALLOC( frame->mv[1], 2*16 * i_mb_count * sizeof(int16_t) ); |
186 | 623 | PREALLOC( frame->ref[1], 4 * i_mb_count * sizeof(int8_t) ); |
187 | 623 | } |
188 | 280 | else |
189 | 280 | { |
190 | 280 | frame->mv[1] = NULL; |
191 | 280 | frame->ref[1] = NULL; |
192 | 280 | } |
193 | 903 | PREALLOC( frame->i_row_bits, i_lines/16 * sizeof(int) ); |
194 | 903 | PREALLOC( frame->f_row_qp, i_lines/16 * sizeof(float) ); |
195 | 903 | PREALLOC( frame->f_row_qscale, i_lines/16 * sizeof(float) ); |
196 | 903 | if( h->param.analyse.i_me_method >= X264_ME_ESA ) |
197 | 0 | PREALLOC( frame->buffer[3], frame->i_stride[0] * (frame->i_lines[0] + 2*i_padv) * sizeof(uint16_t) << h->frames.b_have_sub8x8_esa ); |
198 | 903 | if( PARAM_INTERLACED ) |
199 | 0 | PREALLOC( frame->field, i_mb_count * sizeof(uint8_t) ); |
200 | 903 | if( h->param.analyse.b_mb_info ) |
201 | 0 | PREALLOC( frame->effective_qp, i_mb_count * sizeof(uint8_t) ); |
202 | 903 | } |
203 | 169 | else /* fenc frame */ |
204 | 169 | { |
205 | 169 | if( h->frames.b_have_lowres ) |
206 | 169 | { |
207 | 169 | int64_t luma_plane_size = align_plane_size( frame->i_stride_lowres * (frame->i_lines[0]/2 + 2*PADV), disalign ); |
208 | | |
209 | 169 | PREALLOC( frame->buffer_lowres, 4 * luma_plane_size * SIZEOF_PIXEL ); |
210 | | |
211 | 454 | for( int j = 0; j <= !!h->param.i_bframe; j++ ) |
212 | 1.26k | for( int i = 0; i <= h->param.i_bframe; i++ ) |
213 | 981 | { |
214 | 981 | PREALLOC( frame->lowres_mvs[j][i], 2*i_mb_count*sizeof(int16_t) ); |
215 | 981 | PREALLOC( frame->lowres_mv_costs[j][i], i_mb_count*sizeof(int) ); |
216 | 981 | } |
217 | 169 | PREALLOC( frame->i_propagate_cost, i_mb_count * sizeof(uint16_t) ); |
218 | 855 | for( int j = 0; j <= h->param.i_bframe+1; j++ ) |
219 | 3.79k | for( int i = 0; i <= h->param.i_bframe+1; i++ ) |
220 | 3.11k | PREALLOC( frame->lowres_costs[j][i], i_mb_count * sizeof(uint16_t) ); |
221 | 169 | } |
222 | 169 | if( h->param.rc.i_aq_mode ) |
223 | 116 | { |
224 | 116 | PREALLOC( frame->f_qp_offset, i_mb_count * sizeof(float) ); |
225 | 116 | PREALLOC( frame->f_qp_offset_aq, i_mb_count * sizeof(float) ); |
226 | 116 | if( h->frames.b_have_lowres ) |
227 | 116 | PREALLOC( frame->i_inv_qscale_factor, i_mb_count * sizeof(uint16_t) ); |
228 | 116 | } |
229 | | |
230 | | /* mbtree asm can overread the input buffers, make sure we don't read outside of allocated memory. */ |
231 | 169 | if( h->frames.b_have_lowres ) |
232 | 169 | prealloc_size += NATIVE_ALIGN; |
233 | 169 | } |
234 | | |
235 | 1.07k | PREALLOC_END( frame->base ); |
236 | | |
237 | 1.07k | if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 ) |
238 | 1.07k | { |
239 | 1.07k | int chroma_padv = i_padv >> (i_csp == X264_CSP_NV12); |
240 | 1.07k | frame->plane[1] = frame->buffer[1] + frame->i_stride[1] * chroma_padv + PADH_ALIGN; |
241 | 1.07k | if( PARAM_INTERLACED ) |
242 | 0 | frame->plane_fld[1] = frame->buffer_fld[1] + frame->i_stride[1] * chroma_padv + PADH_ALIGN; |
243 | 1.07k | } |
244 | | |
245 | 2.14k | for( int p = 0; p < luma_plane_count; p++ ) |
246 | 1.07k | { |
247 | 1.07k | int64_t luma_plane_size = align_plane_size( frame->i_stride[p] * (frame->i_lines[p] + 2*i_padv), disalign ); |
248 | 1.07k | if( h->param.analyse.i_subpel_refine && b_fdec ) |
249 | 903 | { |
250 | 4.51k | for( int i = 0; i < 4; i++ ) |
251 | 3.61k | { |
252 | 3.61k | frame->filtered[p][i] = frame->buffer[p] + i*luma_plane_size + frame->i_stride[p] * i_padv + PADH_ALIGN; |
253 | 3.61k | if( PARAM_INTERLACED ) |
254 | 0 | frame->filtered_fld[p][i] = frame->buffer_fld[p] + i*luma_plane_size + frame->i_stride[p] * i_padv + PADH_ALIGN; |
255 | 3.61k | } |
256 | 903 | frame->plane[p] = frame->filtered[p][0]; |
257 | 903 | frame->plane_fld[p] = frame->filtered_fld[p][0]; |
258 | 903 | } |
259 | 169 | else |
260 | 169 | { |
261 | 169 | frame->filtered[p][0] = frame->plane[p] = frame->buffer[p] + frame->i_stride[p] * i_padv + PADH_ALIGN; |
262 | 169 | if( PARAM_INTERLACED ) |
263 | 0 | frame->filtered_fld[p][0] = frame->plane_fld[p] = frame->buffer_fld[p] + frame->i_stride[p] * i_padv + PADH_ALIGN; |
264 | 169 | } |
265 | 1.07k | } |
266 | | |
267 | 1.07k | if( b_fdec ) |
268 | 903 | { |
269 | 903 | M32( frame->mv16x16[0] ) = 0; |
270 | 903 | frame->mv16x16++; |
271 | | |
272 | 903 | if( h->param.analyse.i_me_method >= X264_ME_ESA ) |
273 | 0 | frame->integral = (uint16_t*)frame->buffer[3] + frame->i_stride[0] * i_padv + PADH_ALIGN; |
274 | 903 | } |
275 | 169 | else |
276 | 169 | { |
277 | 169 | if( h->frames.b_have_lowres ) |
278 | 169 | { |
279 | 169 | int64_t luma_plane_size = align_plane_size( frame->i_stride_lowres * (frame->i_lines[0]/2 + 2*PADV), disalign ); |
280 | 845 | for( int i = 0; i < 4; i++ ) |
281 | 676 | frame->lowres[i] = frame->buffer_lowres + frame->i_stride_lowres * PADV + PADH_ALIGN + i * luma_plane_size; |
282 | | |
283 | 454 | for( int j = 0; j <= !!h->param.i_bframe; j++ ) |
284 | 1.26k | for( int i = 0; i <= h->param.i_bframe; i++ ) |
285 | 981 | memset( frame->lowres_mvs[j][i], 0, 2*i_mb_count*sizeof(int16_t) ); |
286 | | |
287 | 169 | frame->i_intra_cost = frame->lowres_costs[0][0]; |
288 | 169 | memset( frame->i_intra_cost, -1, i_mb_count * sizeof(uint16_t) ); |
289 | | |
290 | 169 | if( h->param.rc.i_aq_mode ) |
291 | | /* shouldn't really be initialized, just silences a valgrind false-positive in x264_mbtree_propagate_cost_sse2 */ |
292 | 116 | memset( frame->i_inv_qscale_factor, 0, i_mb_count * sizeof(uint16_t) ); |
293 | 169 | } |
294 | 169 | } |
295 | | |
296 | 1.07k | if( x264_pthread_mutex_init( &frame->mutex, NULL ) ) |
297 | 0 | goto fail; |
298 | 1.07k | if( x264_pthread_cond_init( &frame->cv, NULL ) ) |
299 | 0 | goto fail; |
300 | | |
301 | 1.07k | #if HAVE_OPENCL |
302 | 1.07k | frame->opencl.ocl = h->opencl.ocl; |
303 | 1.07k | #endif |
304 | | |
305 | 1.07k | return frame; |
306 | | |
307 | 0 | fail: |
308 | 0 | x264_free( frame ); |
309 | 0 | return NULL; |
310 | 1.07k | } |
311 | | |
312 | | void x264_frame_delete( x264_frame_t *frame ) |
313 | 1.07k | { |
314 | | /* Duplicate frames are blank copies of real frames (including pointers), |
315 | | * so freeing those pointers would cause a double free later. */ |
316 | 1.07k | if( !frame->b_duplicate ) |
317 | 1.07k | { |
318 | 1.07k | x264_free( frame->base ); |
319 | | |
320 | 1.07k | if( frame->param && frame->param->param_free ) |
321 | 0 | { |
322 | 0 | x264_param_cleanup( frame->param ); |
323 | 0 | frame->param->param_free( frame->param ); |
324 | 0 | } |
325 | 1.07k | if( frame->mb_info_free ) |
326 | 0 | frame->mb_info_free( frame->mb_info ); |
327 | 1.07k | if( frame->extra_sei.sei_free ) |
328 | 0 | { |
329 | 0 | for( int i = 0; i < frame->extra_sei.num_payloads; i++ ) |
330 | 0 | frame->extra_sei.sei_free( frame->extra_sei.payloads[i].payload ); |
331 | 0 | frame->extra_sei.sei_free( frame->extra_sei.payloads ); |
332 | 0 | } |
333 | 1.07k | x264_pthread_mutex_destroy( &frame->mutex ); |
334 | 1.07k | x264_pthread_cond_destroy( &frame->cv ); |
335 | | #if HAVE_OPENCL |
336 | 1.07k | x264_opencl_frame_delete( frame ); |
337 | | #endif |
338 | 1.07k | } |
339 | 1.07k | x264_free( frame ); |
340 | 1.07k | } Line | Count | Source | 313 | 1.07k | { | 314 | | /* Duplicate frames are blank copies of real frames (including pointers), | 315 | | * so freeing those pointers would cause a double free later. */ | 316 | 1.07k | if( !frame->b_duplicate ) | 317 | 1.07k | { | 318 | 1.07k | x264_free( frame->base ); | 319 | | | 320 | 1.07k | if( frame->param && frame->param->param_free ) | 321 | 0 | { | 322 | 0 | x264_param_cleanup( frame->param ); | 323 | 0 | frame->param->param_free( frame->param ); | 324 | 0 | } | 325 | 1.07k | if( frame->mb_info_free ) | 326 | 0 | frame->mb_info_free( frame->mb_info ); | 327 | 1.07k | if( frame->extra_sei.sei_free ) | 328 | 0 | { | 329 | 0 | for( int i = 0; i < frame->extra_sei.num_payloads; i++ ) | 330 | 0 | frame->extra_sei.sei_free( frame->extra_sei.payloads[i].payload ); | 331 | 0 | frame->extra_sei.sei_free( frame->extra_sei.payloads ); | 332 | 0 | } | 333 | 1.07k | x264_pthread_mutex_destroy( &frame->mutex ); | 334 | 1.07k | x264_pthread_cond_destroy( &frame->cv ); | 335 | 1.07k | #if HAVE_OPENCL | 336 | 1.07k | x264_opencl_frame_delete( frame ); | 337 | 1.07k | #endif | 338 | 1.07k | } | 339 | 1.07k | x264_free( frame ); | 340 | 1.07k | } |
Unexecuted instantiation: x264_10_frame_delete |
341 | | |
342 | | static int get_plane_ptr( x264_t *h, x264_picture_t *src, uint8_t **pix, int *stride, int plane, int xshift, int yshift ) |
343 | 507 | { |
344 | 507 | int width = h->param.i_width >> xshift; |
345 | 507 | int height = h->param.i_height >> yshift; |
346 | 507 | *pix = src->img.plane[plane]; |
347 | 507 | *stride = src->img.i_stride[plane]; |
348 | 507 | if( src->img.i_csp & X264_CSP_VFLIP ) |
349 | 0 | { |
350 | 0 | *pix += (height-1) * *stride; |
351 | 0 | *stride = -*stride; |
352 | 0 | } |
353 | 507 | if( width > abs(*stride) ) |
354 | 0 | { |
355 | 0 | x264_log( h, X264_LOG_ERROR, "Input picture width (%d) is greater than stride (%d)\n", width, *stride ); |
356 | 0 | return -1; |
357 | 0 | } |
358 | 507 | return 0; |
359 | 507 | } |
360 | | |
361 | 676 | #define get_plane_ptr(...) do { if( get_plane_ptr(__VA_ARGS__) < 0 ) return -1; } while( 0 ) |
362 | | |
363 | | int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src ) |
364 | 169 | { |
365 | 169 | int i_csp = src->img.i_csp & X264_CSP_MASK; |
366 | 169 | if( dst->i_csp != frame_internal_csp( i_csp ) ) |
367 | 0 | { |
368 | 0 | x264_log( h, X264_LOG_ERROR, "Invalid input colorspace\n" ); |
369 | 0 | return -1; |
370 | 0 | } |
371 | | |
372 | | #if HIGH_BIT_DEPTH |
373 | 0 | if( !(src->img.i_csp & X264_CSP_HIGH_DEPTH) ) |
374 | 0 | { |
375 | 0 | x264_log( h, X264_LOG_ERROR, "This build of x264 requires high depth input. Rebuild to support 8-bit input.\n" ); |
376 | 0 | return -1; |
377 | 0 | } |
378 | | #else |
379 | 169 | if( src->img.i_csp & X264_CSP_HIGH_DEPTH ) |
380 | 0 | { |
381 | 0 | x264_log( h, X264_LOG_ERROR, "This build of x264 requires 8-bit input. Rebuild to support high depth input.\n" ); |
382 | 0 | return -1; |
383 | 0 | } |
384 | 169 | #endif |
385 | | |
386 | 169 | if( BIT_DEPTH != 10 && i_csp == X264_CSP_V210 ) |
387 | 0 | { |
388 | 0 | x264_log( h, X264_LOG_ERROR, "v210 input is only compatible with bit-depth of 10 bits\n" ); |
389 | 0 | return -1; |
390 | 0 | } |
391 | | |
392 | 169 | if( src->i_type < X264_TYPE_AUTO || src->i_type > X264_TYPE_KEYFRAME ) |
393 | 0 | { |
394 | 0 | x264_log( h, X264_LOG_WARNING, "forced frame type (%d) at %d is unknown\n", src->i_type, h->frames.i_input ); |
395 | 0 | dst->i_forced_type = X264_TYPE_AUTO; |
396 | 0 | } |
397 | 169 | else |
398 | 169 | dst->i_forced_type = src->i_type; |
399 | | |
400 | 169 | dst->i_type = dst->i_forced_type; |
401 | 169 | dst->i_qpplus1 = src->i_qpplus1; |
402 | 169 | dst->i_pts = dst->i_reordered_pts = src->i_pts; |
403 | 169 | dst->param = src->param; |
404 | 169 | dst->i_pic_struct = src->i_pic_struct; |
405 | 169 | dst->extra_sei = src->extra_sei; |
406 | 169 | dst->opaque = src->opaque; |
407 | 169 | dst->mb_info = h->param.analyse.b_mb_info ? src->prop.mb_info : NULL; |
408 | 169 | dst->mb_info_free = h->param.analyse.b_mb_info ? src->prop.mb_info_free : NULL; |
409 | | |
410 | 169 | uint8_t *pix[3]; |
411 | 169 | int stride[3]; |
412 | 169 | if( i_csp == X264_CSP_YUYV || i_csp == X264_CSP_UYVY ) |
413 | 0 | { |
414 | 0 | int p = i_csp == X264_CSP_UYVY; |
415 | 0 | h->mc.plane_copy_deinterleave_yuyv( dst->plane[p], dst->i_stride[p], dst->plane[p^1], dst->i_stride[p^1], |
416 | 0 | (pixel*)src->img.plane[0], src->img.i_stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); |
417 | 0 | } |
418 | 169 | else if( i_csp == X264_CSP_V210 ) |
419 | 0 | { |
420 | 0 | stride[0] = src->img.i_stride[0]; |
421 | 0 | pix[0] = src->img.plane[0]; |
422 | |
|
423 | 0 | h->mc.plane_copy_deinterleave_v210( dst->plane[0], dst->i_stride[0], |
424 | 0 | dst->plane[1], dst->i_stride[1], |
425 | 0 | (uint32_t *)pix[0], stride[0]/(int)sizeof(uint32_t), h->param.i_width, h->param.i_height ); |
426 | 0 | } |
427 | 169 | else if( i_csp >= X264_CSP_BGR ) |
428 | 0 | { |
429 | 0 | stride[0] = src->img.i_stride[0]; |
430 | 0 | pix[0] = src->img.plane[0]; |
431 | 0 | if( src->img.i_csp & X264_CSP_VFLIP ) |
432 | 0 | { |
433 | 0 | pix[0] += (h->param.i_height-1) * stride[0]; |
434 | 0 | stride[0] = -stride[0]; |
435 | 0 | } |
436 | 0 | int b = i_csp==X264_CSP_RGB; |
437 | 0 | h->mc.plane_copy_deinterleave_rgb( dst->plane[1+b], dst->i_stride[1+b], |
438 | 0 | dst->plane[0], dst->i_stride[0], |
439 | 0 | dst->plane[2-b], dst->i_stride[2-b], |
440 | 0 | (pixel*)pix[0], stride[0]/SIZEOF_PIXEL, i_csp==X264_CSP_BGRA ? 4 : 3, h->param.i_width, h->param.i_height ); |
441 | 0 | } |
442 | 169 | else |
443 | 169 | { |
444 | 169 | int v_shift = CHROMA_V_SHIFT; |
445 | 169 | get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 ); |
446 | 169 | h->mc.plane_copy( dst->plane[0], dst->i_stride[0], (pixel*)pix[0], |
447 | 169 | stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); |
448 | 169 | if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 ) |
449 | 0 | { |
450 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], 1, 0, v_shift ); |
451 | 0 | h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], |
452 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height>>v_shift ); |
453 | 0 | } |
454 | 169 | else if( i_csp == X264_CSP_NV21 ) |
455 | 0 | { |
456 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], 1, 0, v_shift ); |
457 | 0 | h->mc.plane_copy_swap( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], |
458 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width>>1, h->param.i_height>>v_shift ); |
459 | 0 | } |
460 | 169 | else if( i_csp == X264_CSP_I420 || i_csp == X264_CSP_I422 || i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16 ) |
461 | 169 | { |
462 | 169 | int uv_swap = i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16; |
463 | 169 | get_plane_ptr( h, src, &pix[1], &stride[1], uv_swap ? 2 : 1, 1, v_shift ); |
464 | 169 | get_plane_ptr( h, src, &pix[2], &stride[2], uv_swap ? 1 : 2, 1, v_shift ); |
465 | 169 | h->mc.plane_copy_interleave( dst->plane[1], dst->i_stride[1], |
466 | 169 | (pixel*)pix[1], stride[1]/SIZEOF_PIXEL, |
467 | 169 | (pixel*)pix[2], stride[2]/SIZEOF_PIXEL, |
468 | 169 | h->param.i_width>>1, h->param.i_height>>v_shift ); |
469 | 169 | } |
470 | 0 | else if( i_csp == X264_CSP_I444 || i_csp == X264_CSP_YV24 ) |
471 | 0 | { |
472 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], i_csp==X264_CSP_I444 ? 1 : 2, 0, 0 ); |
473 | 0 | get_plane_ptr( h, src, &pix[2], &stride[2], i_csp==X264_CSP_I444 ? 2 : 1, 0, 0 ); |
474 | 0 | h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], |
475 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); |
476 | 0 | h->mc.plane_copy( dst->plane[2], dst->i_stride[2], (pixel*)pix[2], |
477 | 0 | stride[2]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); |
478 | 0 | } |
479 | 169 | } |
480 | 169 | return 0; |
481 | 169 | } x264_8_frame_copy_picture Line | Count | Source | 364 | 169 | { | 365 | 169 | int i_csp = src->img.i_csp & X264_CSP_MASK; | 366 | 169 | if( dst->i_csp != frame_internal_csp( i_csp ) ) | 367 | 0 | { | 368 | 0 | x264_log( h, X264_LOG_ERROR, "Invalid input colorspace\n" ); | 369 | 0 | return -1; | 370 | 0 | } | 371 | | | 372 | | #if HIGH_BIT_DEPTH | 373 | | if( !(src->img.i_csp & X264_CSP_HIGH_DEPTH) ) | 374 | | { | 375 | | x264_log( h, X264_LOG_ERROR, "This build of x264 requires high depth input. Rebuild to support 8-bit input.\n" ); | 376 | | return -1; | 377 | | } | 378 | | #else | 379 | 169 | if( src->img.i_csp & X264_CSP_HIGH_DEPTH ) | 380 | 0 | { | 381 | 0 | x264_log( h, X264_LOG_ERROR, "This build of x264 requires 8-bit input. Rebuild to support high depth input.\n" ); | 382 | 0 | return -1; | 383 | 0 | } | 384 | 169 | #endif | 385 | | | 386 | 169 | if( BIT_DEPTH != 10 && i_csp == X264_CSP_V210 ) | 387 | 0 | { | 388 | 0 | x264_log( h, X264_LOG_ERROR, "v210 input is only compatible with bit-depth of 10 bits\n" ); | 389 | 0 | return -1; | 390 | 0 | } | 391 | | | 392 | 169 | if( src->i_type < X264_TYPE_AUTO || src->i_type > X264_TYPE_KEYFRAME ) | 393 | 0 | { | 394 | 0 | x264_log( h, X264_LOG_WARNING, "forced frame type (%d) at %d is unknown\n", src->i_type, h->frames.i_input ); | 395 | 0 | dst->i_forced_type = X264_TYPE_AUTO; | 396 | 0 | } | 397 | 169 | else | 398 | 169 | dst->i_forced_type = src->i_type; | 399 | | | 400 | 169 | dst->i_type = dst->i_forced_type; | 401 | 169 | dst->i_qpplus1 = src->i_qpplus1; | 402 | 169 | dst->i_pts = dst->i_reordered_pts = src->i_pts; | 403 | 169 | dst->param = src->param; | 404 | 169 | dst->i_pic_struct = src->i_pic_struct; | 405 | 169 | dst->extra_sei = src->extra_sei; | 406 | 169 | dst->opaque = src->opaque; | 407 | 169 | dst->mb_info = h->param.analyse.b_mb_info ? src->prop.mb_info : NULL; | 408 | 169 | dst->mb_info_free = h->param.analyse.b_mb_info ? src->prop.mb_info_free : NULL; | 409 | | | 410 | 169 | uint8_t *pix[3]; | 411 | 169 | int stride[3]; | 412 | 169 | if( i_csp == X264_CSP_YUYV || i_csp == X264_CSP_UYVY ) | 413 | 0 | { | 414 | 0 | int p = i_csp == X264_CSP_UYVY; | 415 | 0 | h->mc.plane_copy_deinterleave_yuyv( dst->plane[p], dst->i_stride[p], dst->plane[p^1], dst->i_stride[p^1], | 416 | 0 | (pixel*)src->img.plane[0], src->img.i_stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); | 417 | 0 | } | 418 | 169 | else if( i_csp == X264_CSP_V210 ) | 419 | 0 | { | 420 | 0 | stride[0] = src->img.i_stride[0]; | 421 | 0 | pix[0] = src->img.plane[0]; | 422 | |
| 423 | 0 | h->mc.plane_copy_deinterleave_v210( dst->plane[0], dst->i_stride[0], | 424 | 0 | dst->plane[1], dst->i_stride[1], | 425 | 0 | (uint32_t *)pix[0], stride[0]/(int)sizeof(uint32_t), h->param.i_width, h->param.i_height ); | 426 | 0 | } | 427 | 169 | else if( i_csp >= X264_CSP_BGR ) | 428 | 0 | { | 429 | 0 | stride[0] = src->img.i_stride[0]; | 430 | 0 | pix[0] = src->img.plane[0]; | 431 | 0 | if( src->img.i_csp & X264_CSP_VFLIP ) | 432 | 0 | { | 433 | 0 | pix[0] += (h->param.i_height-1) * stride[0]; | 434 | 0 | stride[0] = -stride[0]; | 435 | 0 | } | 436 | 0 | int b = i_csp==X264_CSP_RGB; | 437 | 0 | h->mc.plane_copy_deinterleave_rgb( dst->plane[1+b], dst->i_stride[1+b], | 438 | 0 | dst->plane[0], dst->i_stride[0], | 439 | 0 | dst->plane[2-b], dst->i_stride[2-b], | 440 | 0 | (pixel*)pix[0], stride[0]/SIZEOF_PIXEL, i_csp==X264_CSP_BGRA ? 4 : 3, h->param.i_width, h->param.i_height ); | 441 | 0 | } | 442 | 169 | else | 443 | 169 | { | 444 | 169 | int v_shift = CHROMA_V_SHIFT; | 445 | 169 | get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 ); | 446 | 169 | h->mc.plane_copy( dst->plane[0], dst->i_stride[0], (pixel*)pix[0], | 447 | 169 | stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); | 448 | 169 | if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 ) | 449 | 0 | { | 450 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], 1, 0, v_shift ); | 451 | 0 | h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], | 452 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height>>v_shift ); | 453 | 0 | } | 454 | 169 | else if( i_csp == X264_CSP_NV21 ) | 455 | 0 | { | 456 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], 1, 0, v_shift ); | 457 | 0 | h->mc.plane_copy_swap( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], | 458 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width>>1, h->param.i_height>>v_shift ); | 459 | 0 | } | 460 | 169 | else if( i_csp == X264_CSP_I420 || i_csp == X264_CSP_I422 || i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16 ) | 461 | 169 | { | 462 | 169 | int uv_swap = i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16; | 463 | 169 | get_plane_ptr( h, src, &pix[1], &stride[1], uv_swap ? 2 : 1, 1, v_shift ); | 464 | 169 | get_plane_ptr( h, src, &pix[2], &stride[2], uv_swap ? 1 : 2, 1, v_shift ); | 465 | 169 | h->mc.plane_copy_interleave( dst->plane[1], dst->i_stride[1], | 466 | 169 | (pixel*)pix[1], stride[1]/SIZEOF_PIXEL, | 467 | 169 | (pixel*)pix[2], stride[2]/SIZEOF_PIXEL, | 468 | 169 | h->param.i_width>>1, h->param.i_height>>v_shift ); | 469 | 169 | } | 470 | 0 | else if( i_csp == X264_CSP_I444 || i_csp == X264_CSP_YV24 ) | 471 | 0 | { | 472 | 0 | get_plane_ptr( h, src, &pix[1], &stride[1], i_csp==X264_CSP_I444 ? 1 : 2, 0, 0 ); | 473 | 0 | get_plane_ptr( h, src, &pix[2], &stride[2], i_csp==X264_CSP_I444 ? 2 : 1, 0, 0 ); | 474 | 0 | h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1], | 475 | 0 | stride[1]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); | 476 | 0 | h->mc.plane_copy( dst->plane[2], dst->i_stride[2], (pixel*)pix[2], | 477 | 0 | stride[2]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height ); | 478 | 0 | } | 479 | 169 | } | 480 | 169 | return 0; | 481 | 169 | } |
Unexecuted instantiation: x264_10_frame_copy_picture |
482 | | |
483 | | static ALWAYS_INLINE void pixel_memset( pixel *dst, pixel *src, int len, int size ) |
484 | 446k | { |
485 | 446k | uint8_t *dstp = (uint8_t*)dst; |
486 | 446k | uint32_t v1 = *src; |
487 | 446k | uint32_t v2 = size == 1 ? v1 + (v1 << 8) : M16( src ); |
488 | 446k | uint32_t v4 = size <= 2 ? v2 + (v2 << 16) : M32( src ); |
489 | 446k | int i = 0; |
490 | 446k | len *= size; |
491 | | |
492 | | /* Align the input pointer if it isn't already */ |
493 | 446k | if( (intptr_t)dstp & (WORD_SIZE - 1) ) |
494 | 128k | { |
495 | 128k | if( size <= 2 && ((intptr_t)dstp & 3) ) |
496 | 23.2k | { |
497 | 23.2k | if( size == 1 && ((intptr_t)dstp & 1) ) |
498 | 0 | dstp[i++] = v1; |
499 | 23.2k | if( (intptr_t)dstp & 2 ) |
500 | 23.2k | { |
501 | 23.2k | M16( dstp+i ) = v2; |
502 | 23.2k | i += 2; |
503 | 23.2k | } |
504 | 23.2k | } |
505 | 128k | if( WORD_SIZE == 8 && (intptr_t)dstp & 4 ) |
506 | 116k | { |
507 | 116k | M32( dstp+i ) = v4; |
508 | 116k | i += 4; |
509 | 116k | } |
510 | 128k | } |
511 | | |
512 | | /* Main copy loop */ |
513 | 446k | if( WORD_SIZE == 8 ) |
514 | 446k | { |
515 | 446k | uint64_t v8 = v4 + ((uint64_t)v4<<32); |
516 | 1.91M | for( ; i < len - 7; i+=8 ) |
517 | 1.46M | M64( dstp+i ) = v8; |
518 | 446k | } |
519 | 561k | for( ; i < len - 3; i+=4 ) |
520 | 115k | M32( dstp+i ) = v4; |
521 | | |
522 | | /* Finish up the last few bytes */ |
523 | 446k | if( size <= 2 ) |
524 | 446k | { |
525 | 446k | if( i < len - 1 ) |
526 | 0 | { |
527 | 0 | M16( dstp+i ) = v2; |
528 | 0 | i += 2; |
529 | 0 | } |
530 | 446k | if( size == 1 && i != len ) |
531 | 4.61k | dstp[i] = v1; |
532 | 446k | } |
533 | 446k | } |
534 | | |
535 | | static ALWAYS_INLINE void plane_expand_border( pixel *pix, int i_stride, int i_width, int i_height, int i_padh, int i_padv, int b_pad_top, int b_pad_bottom, int b_chroma ) |
536 | 10.1k | { |
537 | 992k | #define PPIXEL(x, y) ( pix + (x) + (y)*i_stride ) |
538 | 216k | for( int y = 0; y < i_height; y++ ) |
539 | 206k | { |
540 | | /* left band */ |
541 | 206k | pixel_memset( PPIXEL(-i_padh, y), PPIXEL(0, y), i_padh>>b_chroma, SIZEOF_PIXEL<<b_chroma ); |
542 | | /* right band */ |
543 | 206k | pixel_memset( PPIXEL(i_width, y), PPIXEL(i_width-1-b_chroma, y), i_padh>>b_chroma, SIZEOF_PIXEL<<b_chroma ); |
544 | 206k | } |
545 | | /* upper band */ |
546 | 10.1k | if( b_pad_top ) |
547 | 43.4k | for( int y = 0; y < i_padv; y++ ) |
548 | 41.9k | memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), (i_width+2*i_padh) * SIZEOF_PIXEL ); |
549 | | /* lower band */ |
550 | 10.1k | if( b_pad_bottom ) |
551 | 43.4k | for( int y = 0; y < i_padv; y++ ) |
552 | 41.9k | memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), (i_width+2*i_padh) * SIZEOF_PIXEL ); |
553 | 10.1k | #undef PPIXEL |
554 | 10.1k | } |
555 | | |
556 | | void x264_frame_expand_border( x264_t *h, x264_frame_t *frame, int mb_y ) |
557 | 1.89k | { |
558 | 1.89k | int pad_top = mb_y == 0; |
559 | 1.89k | int pad_bot = mb_y == h->mb.i_mb_height - (1 << SLICE_MBAFF); |
560 | 1.89k | int b_start = mb_y == h->i_threadslice_start; |
561 | 1.89k | int b_end = mb_y == h->i_threadslice_end - (1 << SLICE_MBAFF); |
562 | 1.89k | if( mb_y & SLICE_MBAFF ) |
563 | 0 | return; |
564 | 5.68k | for( int i = 0; i < frame->i_plane; i++ ) |
565 | 3.79k | { |
566 | 3.79k | int h_shift = i && CHROMA_H_SHIFT; |
567 | 3.79k | int v_shift = i && CHROMA_V_SHIFT; |
568 | 3.79k | int stride = frame->i_stride[i]; |
569 | 3.79k | int width = 16*h->mb.i_mb_width; |
570 | 3.79k | int height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF : 16) >> v_shift; |
571 | 3.79k | int padh = PADH; |
572 | 3.79k | int padv = PADV >> v_shift; |
573 | | // buffer: 2 chroma, 3 luma (rounded to 4) because deblocking goes beyond the top of the mb |
574 | 3.79k | if( b_end && !b_start ) |
575 | 338 | height += 4 >> (v_shift + SLICE_MBAFF); |
576 | 3.79k | pixel *pix; |
577 | 3.79k | int starty = 16*mb_y - 4*!b_start; |
578 | 3.79k | if( SLICE_MBAFF ) |
579 | 0 | { |
580 | | // border samples for each field are extended separately |
581 | 0 | pix = frame->plane_fld[i] + (starty*stride >> v_shift); |
582 | 0 | plane_expand_border( pix, stride*2, width, height, padh, padv, pad_top, pad_bot, h_shift ); |
583 | 0 | plane_expand_border( pix+stride, stride*2, width, height, padh, padv, pad_top, pad_bot, h_shift ); |
584 | |
|
585 | 0 | height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) : 32) >> v_shift; |
586 | 0 | if( b_end && !b_start ) |
587 | 0 | height += 4 >> v_shift; |
588 | 0 | pix = frame->plane[i] + (starty*stride >> v_shift); |
589 | 0 | plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift ); |
590 | 0 | } |
591 | 3.79k | else |
592 | 3.79k | { |
593 | 3.79k | pix = frame->plane[i] + (starty*stride >> v_shift); |
594 | 3.79k | plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift ); |
595 | 3.79k | } |
596 | 3.79k | } |
597 | 1.89k | } x264_8_frame_expand_border Line | Count | Source | 557 | 1.89k | { | 558 | 1.89k | int pad_top = mb_y == 0; | 559 | 1.89k | int pad_bot = mb_y == h->mb.i_mb_height - (1 << SLICE_MBAFF); | 560 | 1.89k | int b_start = mb_y == h->i_threadslice_start; | 561 | 1.89k | int b_end = mb_y == h->i_threadslice_end - (1 << SLICE_MBAFF); | 562 | 1.89k | if( mb_y & SLICE_MBAFF ) | 563 | 0 | return; | 564 | 5.68k | for( int i = 0; i < frame->i_plane; i++ ) | 565 | 3.79k | { | 566 | 3.79k | int h_shift = i && CHROMA_H_SHIFT; | 567 | 3.79k | int v_shift = i && CHROMA_V_SHIFT; | 568 | 3.79k | int stride = frame->i_stride[i]; | 569 | 3.79k | int width = 16*h->mb.i_mb_width; | 570 | 3.79k | int height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF : 16) >> v_shift; | 571 | 3.79k | int padh = PADH; | 572 | 3.79k | int padv = PADV >> v_shift; | 573 | | // buffer: 2 chroma, 3 luma (rounded to 4) because deblocking goes beyond the top of the mb | 574 | 3.79k | if( b_end && !b_start ) | 575 | 338 | height += 4 >> (v_shift + SLICE_MBAFF); | 576 | 3.79k | pixel *pix; | 577 | 3.79k | int starty = 16*mb_y - 4*!b_start; | 578 | 3.79k | if( SLICE_MBAFF ) | 579 | 0 | { | 580 | | // border samples for each field are extended separately | 581 | 0 | pix = frame->plane_fld[i] + (starty*stride >> v_shift); | 582 | 0 | plane_expand_border( pix, stride*2, width, height, padh, padv, pad_top, pad_bot, h_shift ); | 583 | 0 | plane_expand_border( pix+stride, stride*2, width, height, padh, padv, pad_top, pad_bot, h_shift ); | 584 | |
| 585 | 0 | height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) : 32) >> v_shift; | 586 | 0 | if( b_end && !b_start ) | 587 | 0 | height += 4 >> v_shift; | 588 | 0 | pix = frame->plane[i] + (starty*stride >> v_shift); | 589 | 0 | plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift ); | 590 | 0 | } | 591 | 3.79k | else | 592 | 3.79k | { | 593 | 3.79k | pix = frame->plane[i] + (starty*stride >> v_shift); | 594 | 3.79k | plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift ); | 595 | 3.79k | } | 596 | 3.79k | } | 597 | 1.89k | } |
Unexecuted instantiation: x264_10_frame_expand_border |
598 | | |
599 | | void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame, int mb_y, int b_end ) |
600 | 1.89k | { |
601 | | /* during filtering, 8 extra pixels were filtered on each edge, |
602 | | * but up to 3 of the horizontal ones may be wrong. |
603 | | we want to expand border from the last filtered pixel */ |
604 | 1.89k | int b_start = !mb_y; |
605 | 1.89k | int width = 16*h->mb.i_mb_width + 8; |
606 | 1.89k | int height = b_end ? (16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF) + 16 : 16; |
607 | 1.89k | int padh = PADH - 4; |
608 | 1.89k | int padv = PADV - 8; |
609 | 3.79k | for( int p = 0; p < (CHROMA444 ? 3 : 1); p++ ) |
610 | 7.58k | for( int i = 1; i < 4; i++ ) |
611 | 5.68k | { |
612 | 5.68k | int stride = frame->i_stride[p]; |
613 | | // buffer: 8 luma, to match the hpel filter |
614 | 5.68k | pixel *pix; |
615 | 5.68k | if( SLICE_MBAFF ) |
616 | 0 | { |
617 | 0 | pix = frame->filtered_fld[p][i] + (16*mb_y - 16) * stride - 4; |
618 | 0 | plane_expand_border( pix, stride*2, width, height, padh, padv, b_start, b_end, 0 ); |
619 | 0 | plane_expand_border( pix+stride, stride*2, width, height, padh, padv, b_start, b_end, 0 ); |
620 | 0 | } |
621 | | |
622 | 5.68k | pix = frame->filtered[p][i] + (16*mb_y - 8) * stride - 4; |
623 | 5.68k | plane_expand_border( pix, stride, width, height << SLICE_MBAFF, padh, padv, b_start, b_end, 0 ); |
624 | 5.68k | } |
625 | 1.89k | } x264_8_frame_expand_border_filtered Line | Count | Source | 600 | 1.89k | { | 601 | | /* during filtering, 8 extra pixels were filtered on each edge, | 602 | | * but up to 3 of the horizontal ones may be wrong. | 603 | | we want to expand border from the last filtered pixel */ | 604 | 1.89k | int b_start = !mb_y; | 605 | 1.89k | int width = 16*h->mb.i_mb_width + 8; | 606 | 1.89k | int height = b_end ? (16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF) + 16 : 16; | 607 | 1.89k | int padh = PADH - 4; | 608 | 1.89k | int padv = PADV - 8; | 609 | 3.79k | for( int p = 0; p < (CHROMA444 ? 3 : 1); p++ ) | 610 | 7.58k | for( int i = 1; i < 4; i++ ) | 611 | 5.68k | { | 612 | 5.68k | int stride = frame->i_stride[p]; | 613 | | // buffer: 8 luma, to match the hpel filter | 614 | 5.68k | pixel *pix; | 615 | 5.68k | if( SLICE_MBAFF ) | 616 | 0 | { | 617 | 0 | pix = frame->filtered_fld[p][i] + (16*mb_y - 16) * stride - 4; | 618 | 0 | plane_expand_border( pix, stride*2, width, height, padh, padv, b_start, b_end, 0 ); | 619 | 0 | plane_expand_border( pix+stride, stride*2, width, height, padh, padv, b_start, b_end, 0 ); | 620 | 0 | } | 621 | | | 622 | 5.68k | pix = frame->filtered[p][i] + (16*mb_y - 8) * stride - 4; | 623 | 5.68k | plane_expand_border( pix, stride, width, height << SLICE_MBAFF, padh, padv, b_start, b_end, 0 ); | 624 | 5.68k | } | 625 | 1.89k | } |
Unexecuted instantiation: x264_10_frame_expand_border_filtered |
626 | | |
627 | | void x264_frame_expand_border_lowres( x264_frame_t *frame ) |
628 | 169 | { |
629 | 845 | for( int i = 0; i < 4; i++ ) |
630 | 676 | plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_width_lowres, frame->i_lines_lowres, PADH, PADV, 1, 1, 0 ); |
631 | 169 | } x264_8_frame_expand_border_lowres Line | Count | Source | 628 | 169 | { | 629 | 845 | for( int i = 0; i < 4; i++ ) | 630 | 676 | plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_width_lowres, frame->i_lines_lowres, PADH, PADV, 1, 1, 0 ); | 631 | 169 | } |
Unexecuted instantiation: x264_10_frame_expand_border_lowres |
632 | | |
633 | | void x264_frame_expand_border_chroma( x264_t *h, x264_frame_t *frame, int plane ) |
634 | 0 | { |
635 | 0 | int v_shift = CHROMA_V_SHIFT; |
636 | 0 | plane_expand_border( frame->plane[plane], frame->i_stride[plane], 16*h->mb.i_mb_width, 16*h->mb.i_mb_height>>v_shift, |
637 | 0 | PADH, PADV>>v_shift, 1, 1, CHROMA_H_SHIFT ); |
638 | 0 | } Unexecuted instantiation: x264_8_frame_expand_border_chroma Unexecuted instantiation: x264_10_frame_expand_border_chroma |
639 | | |
640 | | void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame ) |
641 | 151 | { |
642 | 453 | for( int i = 0; i < frame->i_plane; i++ ) |
643 | 302 | { |
644 | 302 | int i_width = h->param.i_width; |
645 | 302 | int h_shift = i && CHROMA_H_SHIFT; |
646 | 302 | int v_shift = i && CHROMA_V_SHIFT; |
647 | 302 | int i_height = h->param.i_height >> v_shift; |
648 | 302 | int i_padx = (h->mb.i_mb_width * 16 - h->param.i_width); |
649 | 302 | int i_pady = (h->mb.i_mb_height * 16 - h->param.i_height) >> v_shift; |
650 | | |
651 | 302 | if( i_padx ) |
652 | 254 | { |
653 | 34.2k | for( int y = 0; y < i_height; y++ ) |
654 | 33.9k | pixel_memset( &frame->plane[i][y*frame->i_stride[i] + i_width], |
655 | 33.9k | &frame->plane[i][y*frame->i_stride[i] + i_width - 1-h_shift], |
656 | 33.9k | i_padx>>h_shift, SIZEOF_PIXEL<<h_shift ); |
657 | 254 | } |
658 | 302 | if( i_pady ) |
659 | 244 | { |
660 | 1.72k | for( int y = i_height; y < i_height + i_pady; y++ ) |
661 | 1.47k | memcpy( &frame->plane[i][y*frame->i_stride[i]], |
662 | 1.47k | &frame->plane[i][(i_height-(~y&PARAM_INTERLACED)-1)*frame->i_stride[i]], |
663 | 1.47k | (i_width + i_padx) * SIZEOF_PIXEL ); |
664 | 244 | } |
665 | 302 | } |
666 | 151 | } x264_8_frame_expand_border_mod16 Line | Count | Source | 641 | 151 | { | 642 | 453 | for( int i = 0; i < frame->i_plane; i++ ) | 643 | 302 | { | 644 | 302 | int i_width = h->param.i_width; | 645 | 302 | int h_shift = i && CHROMA_H_SHIFT; | 646 | 302 | int v_shift = i && CHROMA_V_SHIFT; | 647 | 302 | int i_height = h->param.i_height >> v_shift; | 648 | 302 | int i_padx = (h->mb.i_mb_width * 16 - h->param.i_width); | 649 | 302 | int i_pady = (h->mb.i_mb_height * 16 - h->param.i_height) >> v_shift; | 650 | | | 651 | 302 | if( i_padx ) | 652 | 254 | { | 653 | 34.2k | for( int y = 0; y < i_height; y++ ) | 654 | 33.9k | pixel_memset( &frame->plane[i][y*frame->i_stride[i] + i_width], | 655 | 33.9k | &frame->plane[i][y*frame->i_stride[i] + i_width - 1-h_shift], | 656 | 33.9k | i_padx>>h_shift, SIZEOF_PIXEL<<h_shift ); | 657 | 254 | } | 658 | 302 | if( i_pady ) | 659 | 244 | { | 660 | 1.72k | for( int y = i_height; y < i_height + i_pady; y++ ) | 661 | 1.47k | memcpy( &frame->plane[i][y*frame->i_stride[i]], | 662 | 1.47k | &frame->plane[i][(i_height-(~y&PARAM_INTERLACED)-1)*frame->i_stride[i]], | 663 | 1.47k | (i_width + i_padx) * SIZEOF_PIXEL ); | 664 | 244 | } | 665 | 302 | } | 666 | 151 | } |
Unexecuted instantiation: x264_10_frame_expand_border_mod16 |
667 | | |
668 | | void x264_expand_border_mbpair( x264_t *h, int mb_x, int mb_y ) |
669 | 0 | { |
670 | 0 | for( int i = 0; i < h->fenc->i_plane; i++ ) |
671 | 0 | { |
672 | 0 | int v_shift = i && CHROMA_V_SHIFT; |
673 | 0 | int stride = h->fenc->i_stride[i]; |
674 | 0 | int height = h->param.i_height >> v_shift; |
675 | 0 | int pady = (h->mb.i_mb_height * 16 - h->param.i_height) >> v_shift; |
676 | 0 | pixel *fenc = h->fenc->plane[i] + 16*mb_x; |
677 | 0 | for( int y = height; y < height + pady; y++ ) |
678 | 0 | memcpy( fenc + y*stride, fenc + (height-1)*stride, 16*SIZEOF_PIXEL ); |
679 | 0 | } |
680 | 0 | } Unexecuted instantiation: x264_8_expand_border_mbpair Unexecuted instantiation: x264_10_expand_border_mbpair |
681 | | |
682 | | /* threading */ |
683 | | void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed ) |
684 | 1.89k | { |
685 | 1.89k | x264_pthread_mutex_lock( &frame->mutex ); |
686 | 1.89k | frame->i_lines_completed = i_lines_completed; |
687 | 1.89k | x264_pthread_cond_broadcast( &frame->cv ); |
688 | 1.89k | x264_pthread_mutex_unlock( &frame->mutex ); |
689 | 1.89k | } x264_8_frame_cond_broadcast Line | Count | Source | 684 | 1.89k | { | 685 | 1.89k | x264_pthread_mutex_lock( &frame->mutex ); | 686 | 1.89k | frame->i_lines_completed = i_lines_completed; | 687 | 1.89k | x264_pthread_cond_broadcast( &frame->cv ); | 688 | 1.89k | x264_pthread_mutex_unlock( &frame->mutex ); | 689 | 1.89k | } |
Unexecuted instantiation: x264_10_frame_cond_broadcast |
690 | | |
691 | | int x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed ) |
692 | 0 | { |
693 | 0 | int completed; |
694 | 0 | x264_pthread_mutex_lock( &frame->mutex ); |
695 | 0 | while( (completed = frame->i_lines_completed) < i_lines_completed && i_lines_completed >= 0 ) |
696 | 0 | x264_pthread_cond_wait( &frame->cv, &frame->mutex ); |
697 | 0 | x264_pthread_mutex_unlock( &frame->mutex ); |
698 | 0 | return completed; |
699 | 0 | } Unexecuted instantiation: x264_8_frame_cond_wait Unexecuted instantiation: x264_10_frame_cond_wait |
700 | | |
701 | | void x264_threadslice_cond_broadcast( x264_t *h, int pass ) |
702 | 0 | { |
703 | 0 | x264_pthread_mutex_lock( &h->mutex ); |
704 | 0 | h->i_threadslice_pass = pass; |
705 | 0 | if( pass > 0 ) |
706 | 0 | x264_pthread_cond_broadcast( &h->cv ); |
707 | 0 | x264_pthread_mutex_unlock( &h->mutex ); |
708 | 0 | } Unexecuted instantiation: x264_8_threadslice_cond_broadcast Unexecuted instantiation: x264_10_threadslice_cond_broadcast |
709 | | |
710 | | void x264_threadslice_cond_wait( x264_t *h, int pass ) |
711 | 0 | { |
712 | 0 | x264_pthread_mutex_lock( &h->mutex ); |
713 | 0 | while( h->i_threadslice_pass < pass ) |
714 | 0 | x264_pthread_cond_wait( &h->cv, &h->mutex ); |
715 | 0 | x264_pthread_mutex_unlock( &h->mutex ); |
716 | 0 | } Unexecuted instantiation: x264_8_threadslice_cond_wait Unexecuted instantiation: x264_10_threadslice_cond_wait |
717 | | |
718 | | int x264_frame_new_slice( x264_t *h, x264_frame_t *frame ) |
719 | 0 | { |
720 | 0 | if( h->param.i_slice_count_max ) |
721 | 0 | { |
722 | 0 | int slice_count; |
723 | 0 | if( h->param.b_sliced_threads ) |
724 | 0 | slice_count = x264_pthread_fetch_and_add( &frame->i_slice_count, 1, &frame->mutex ); |
725 | 0 | else |
726 | 0 | slice_count = frame->i_slice_count++; |
727 | 0 | if( slice_count >= h->param.i_slice_count_max ) |
728 | 0 | return -1; |
729 | 0 | } |
730 | 0 | return 0; |
731 | 0 | } Unexecuted instantiation: x264_8_frame_new_slice Unexecuted instantiation: x264_10_frame_new_slice |
732 | | |
733 | | /* list operators */ |
734 | | |
735 | | void x264_frame_push( x264_frame_t **list, x264_frame_t *frame ) |
736 | 1.24k | { |
737 | 1.24k | int i = 0; |
738 | 2.97k | while( list[i] ) i++; |
739 | 1.24k | list[i] = frame; |
740 | 1.24k | } Line | Count | Source | 736 | 1.24k | { | 737 | 1.24k | int i = 0; | 738 | 2.97k | while( list[i] ) i++; | 739 | 1.24k | list[i] = frame; | 740 | 1.24k | } |
Unexecuted instantiation: x264_10_frame_push |
741 | | |
742 | | x264_frame_t *x264_frame_pop( x264_frame_t **list ) |
743 | 169 | { |
744 | 169 | x264_frame_t *frame; |
745 | 169 | int i = 0; |
746 | 169 | assert( list[0] ); |
747 | 313 | while( list[i+1] ) i++; |
748 | 169 | frame = list[i]; |
749 | 169 | list[i] = NULL; |
750 | 169 | return frame; |
751 | 169 | } Line | Count | Source | 743 | 169 | { | 744 | 169 | x264_frame_t *frame; | 745 | 169 | int i = 0; | 746 | 169 | assert( list[0] ); | 747 | 313 | while( list[i+1] ) i++; | 748 | 169 | frame = list[i]; | 749 | | list[i] = NULL; | 750 | 169 | return frame; | 751 | 169 | } |
Unexecuted instantiation: x264_10_frame_pop |
752 | | |
753 | | void x264_frame_unshift( x264_frame_t **list, x264_frame_t *frame ) |
754 | 0 | { |
755 | 0 | int i = 0; |
756 | 0 | while( list[i] ) i++; |
757 | 0 | while( i-- ) |
758 | 0 | list[i+1] = list[i]; |
759 | 0 | list[0] = frame; |
760 | 0 | } Unexecuted instantiation: x264_8_frame_unshift Unexecuted instantiation: x264_10_frame_unshift |
761 | | |
762 | | x264_frame_t *x264_frame_shift( x264_frame_t **list ) |
763 | 1.01k | { |
764 | 1.01k | x264_frame_t *frame = list[0]; |
765 | 1.01k | int i; |
766 | 2.02k | for( i = 0; list[i]; i++ ) |
767 | 1.01k | list[i] = list[i+1]; |
768 | 1.01k | assert(frame); |
769 | 1.01k | return frame; |
770 | 1.01k | } Line | Count | Source | 763 | 1.01k | { | 764 | 1.01k | x264_frame_t *frame = list[0]; | 765 | 1.01k | int i; | 766 | 2.02k | for( i = 0; list[i]; i++ ) | 767 | 1.01k | list[i] = list[i+1]; | 768 | 1.01k | assert(frame); | 769 | 1.01k | return frame; | 770 | 1.01k | } |
Unexecuted instantiation: x264_10_frame_shift |
771 | | |
772 | | void x264_frame_push_unused( x264_t *h, x264_frame_t *frame ) |
773 | 1.57k | { |
774 | 1.57k | assert( frame->i_reference_count > 0 ); |
775 | 1.57k | frame->i_reference_count--; |
776 | 1.57k | if( frame->i_reference_count == 0 ) |
777 | 1.07k | x264_frame_push( h->frames.unused[frame->b_fdec], frame ); |
778 | 1.57k | } Line | Count | Source | 773 | 1.57k | { | 774 | 1.57k | assert( frame->i_reference_count > 0 ); | 775 | 1.57k | frame->i_reference_count--; | 776 | 1.57k | if( frame->i_reference_count == 0 ) | 777 | 1.07k | x264_frame_push( h->frames.unused[frame->b_fdec], frame ); | 778 | 1.57k | } |
Unexecuted instantiation: x264_10_frame_push_unused |
779 | | |
780 | | x264_frame_t *x264_frame_pop_unused( x264_t *h, int b_fdec ) |
781 | 1.24k | { |
782 | 1.24k | x264_frame_t *frame; |
783 | 1.24k | if( h->frames.unused[b_fdec][0] ) |
784 | 169 | frame = x264_frame_pop( h->frames.unused[b_fdec] ); |
785 | 1.07k | else |
786 | 1.07k | frame = frame_new( h, b_fdec ); |
787 | 1.24k | if( !frame ) |
788 | 0 | return NULL; |
789 | 1.24k | frame->b_last_minigop_bframe = 0; |
790 | 1.24k | frame->i_reference_count = 1; |
791 | 1.24k | frame->b_intra_calculated = 0; |
792 | 1.24k | frame->b_scenecut = 1; |
793 | 1.24k | frame->b_keyframe = 0; |
794 | 1.24k | frame->b_corrupt = 0; |
795 | 1.24k | frame->i_slice_count = h->param.b_sliced_threads ? h->param.i_threads : 1; |
796 | | |
797 | 1.24k | memset( frame->weight, 0, sizeof(frame->weight) ); |
798 | 1.24k | memset( frame->f_weighted_cost_delta, 0, sizeof(frame->f_weighted_cost_delta) ); |
799 | | |
800 | 1.24k | return frame; |
801 | 1.24k | } Line | Count | Source | 781 | 1.24k | { | 782 | 1.24k | x264_frame_t *frame; | 783 | 1.24k | if( h->frames.unused[b_fdec][0] ) | 784 | 169 | frame = x264_frame_pop( h->frames.unused[b_fdec] ); | 785 | 1.07k | else | 786 | 1.07k | frame = frame_new( h, b_fdec ); | 787 | 1.24k | if( !frame ) | 788 | 0 | return NULL; | 789 | 1.24k | frame->b_last_minigop_bframe = 0; | 790 | 1.24k | frame->i_reference_count = 1; | 791 | 1.24k | frame->b_intra_calculated = 0; | 792 | 1.24k | frame->b_scenecut = 1; | 793 | 1.24k | frame->b_keyframe = 0; | 794 | 1.24k | frame->b_corrupt = 0; | 795 | 1.24k | frame->i_slice_count = h->param.b_sliced_threads ? h->param.i_threads : 1; | 796 | | | 797 | 1.24k | memset( frame->weight, 0, sizeof(frame->weight) ); | 798 | 1.24k | memset( frame->f_weighted_cost_delta, 0, sizeof(frame->f_weighted_cost_delta) ); | 799 | | | 800 | 1.24k | return frame; | 801 | 1.24k | } |
Unexecuted instantiation: x264_10_frame_pop_unused |
802 | | |
803 | | void x264_frame_push_blank_unused( x264_t *h, x264_frame_t *frame ) |
804 | 0 | { |
805 | 0 | assert( frame->i_reference_count > 0 ); |
806 | 0 | frame->i_reference_count--; |
807 | 0 | if( frame->i_reference_count == 0 ) |
808 | 0 | x264_frame_push( h->frames.blank_unused, frame ); |
809 | 0 | } Unexecuted instantiation: x264_8_frame_push_blank_unused Unexecuted instantiation: x264_10_frame_push_blank_unused |
810 | | |
811 | | x264_frame_t *x264_frame_pop_blank_unused( x264_t *h ) |
812 | 0 | { |
813 | 0 | x264_frame_t *frame; |
814 | 0 | if( h->frames.blank_unused[0] ) |
815 | 0 | frame = x264_frame_pop( h->frames.blank_unused ); |
816 | 0 | else |
817 | 0 | frame = x264_malloc( sizeof(x264_frame_t) ); |
818 | 0 | if( !frame ) |
819 | 0 | return NULL; |
820 | 0 | frame->b_duplicate = 1; |
821 | 0 | frame->i_reference_count = 1; |
822 | 0 | return frame; |
823 | 0 | } Unexecuted instantiation: x264_8_frame_pop_blank_unused Unexecuted instantiation: x264_10_frame_pop_blank_unused |
824 | | |
825 | | void x264_weight_scale_plane( x264_t *h, pixel *dst, intptr_t i_dst_stride, pixel *src, intptr_t i_src_stride, |
826 | | int i_width, int i_height, x264_weight_t *w ) |
827 | 0 | { |
828 | | /* Weight horizontal strips of height 16. This was found to be the optimal height |
829 | | * in terms of the cache loads. */ |
830 | 0 | while( i_height > 0 ) |
831 | 0 | { |
832 | 0 | int x; |
833 | 0 | for( x = 0; x < i_width-8; x += 16 ) |
834 | 0 | w->weightfn[16>>2]( dst+x, i_dst_stride, src+x, i_src_stride, w, X264_MIN( i_height, 16 ) ); |
835 | 0 | if( x < i_width ) |
836 | 0 | w->weightfn[ 8>>2]( dst+x, i_dst_stride, src+x, i_src_stride, w, X264_MIN( i_height, 16 ) ); |
837 | 0 | i_height -= 16; |
838 | 0 | dst += 16 * i_dst_stride; |
839 | 0 | src += 16 * i_src_stride; |
840 | 0 | } |
841 | 0 | } Unexecuted instantiation: x264_8_weight_scale_plane Unexecuted instantiation: x264_10_weight_scale_plane |
842 | | |
843 | | void x264_frame_delete_list( x264_frame_t **list ) |
844 | 1.69k | { |
845 | 1.69k | int i = 0; |
846 | 1.69k | if( !list ) |
847 | 0 | return; |
848 | 2.59k | while( list[i] ) |
849 | 903 | x264_frame_delete( list[i++] ); |
850 | 1.69k | x264_free( list ); |
851 | 1.69k | } Line | Count | Source | 844 | 1.69k | { | 845 | 1.69k | int i = 0; | 846 | 1.69k | if( !list ) | 847 | 0 | return; | 848 | 2.59k | while( list[i] ) | 849 | 903 | x264_frame_delete( list[i++] ); | 850 | 1.69k | x264_free( list ); | 851 | 1.69k | } |
Unexecuted instantiation: x264_10_frame_delete_list |
852 | | |
853 | | int x264_sync_frame_list_init( x264_sync_frame_list_t *slist, int max_size ) |
854 | 1.01k | { |
855 | 1.01k | if( max_size < 0 ) |
856 | 0 | return -1; |
857 | 1.01k | slist->i_max_size = max_size; |
858 | 1.01k | slist->i_size = 0; |
859 | 1.01k | CHECKED_MALLOCZERO( slist->list, (max_size+1) * sizeof(x264_frame_t*) ); |
860 | 1.01k | if( x264_pthread_mutex_init( &slist->mutex, NULL ) || |
861 | 1.01k | x264_pthread_cond_init( &slist->cv_fill, NULL ) || |
862 | 1.01k | x264_pthread_cond_init( &slist->cv_empty, NULL ) ) |
863 | 0 | return -1; |
864 | 1.01k | return 0; |
865 | 0 | fail: |
866 | 0 | return -1; |
867 | 1.01k | } x264_8_sync_frame_list_init Line | Count | Source | 854 | 1.01k | { | 855 | 1.01k | if( max_size < 0 ) | 856 | 0 | return -1; | 857 | 1.01k | slist->i_max_size = max_size; | 858 | 1.01k | slist->i_size = 0; | 859 | 1.01k | CHECKED_MALLOCZERO( slist->list, (max_size+1) * sizeof(x264_frame_t*) ); | 860 | 1.01k | if( x264_pthread_mutex_init( &slist->mutex, NULL ) || | 861 | 1.01k | x264_pthread_cond_init( &slist->cv_fill, NULL ) || | 862 | 1.01k | x264_pthread_cond_init( &slist->cv_empty, NULL ) ) | 863 | 0 | return -1; | 864 | 1.01k | return 0; | 865 | 0 | fail: | 866 | 0 | return -1; | 867 | 1.01k | } |
Unexecuted instantiation: x264_10_sync_frame_list_init |
868 | | |
869 | | void x264_sync_frame_list_delete( x264_sync_frame_list_t *slist ) |
870 | 1.01k | { |
871 | 1.01k | x264_pthread_mutex_destroy( &slist->mutex ); |
872 | 1.01k | x264_pthread_cond_destroy( &slist->cv_fill ); |
873 | 1.01k | x264_pthread_cond_destroy( &slist->cv_empty ); |
874 | 1.01k | x264_frame_delete_list( slist->list ); |
875 | 1.01k | } x264_8_sync_frame_list_delete Line | Count | Source | 870 | 1.01k | { | 871 | 1.01k | x264_pthread_mutex_destroy( &slist->mutex ); | 872 | 1.01k | x264_pthread_cond_destroy( &slist->cv_fill ); | 873 | 1.01k | x264_pthread_cond_destroy( &slist->cv_empty ); | 874 | 1.01k | x264_frame_delete_list( slist->list ); | 875 | 1.01k | } |
Unexecuted instantiation: x264_10_sync_frame_list_delete |
876 | | |
877 | | void x264_sync_frame_list_push( x264_sync_frame_list_t *slist, x264_frame_t *frame ) |
878 | 1.57k | { |
879 | 1.57k | x264_pthread_mutex_lock( &slist->mutex ); |
880 | 1.57k | while( slist->i_size == slist->i_max_size ) |
881 | 0 | x264_pthread_cond_wait( &slist->cv_empty, &slist->mutex ); |
882 | 1.57k | slist->list[ slist->i_size++ ] = frame; |
883 | 1.57k | x264_pthread_mutex_unlock( &slist->mutex ); |
884 | 1.57k | x264_pthread_cond_broadcast( &slist->cv_fill ); |
885 | 1.57k | } x264_8_sync_frame_list_push Line | Count | Source | 878 | 1.57k | { | 879 | 1.57k | x264_pthread_mutex_lock( &slist->mutex ); | 880 | 1.57k | while( slist->i_size == slist->i_max_size ) | 881 | 0 | x264_pthread_cond_wait( &slist->cv_empty, &slist->mutex ); | 882 | 1.57k | slist->list[ slist->i_size++ ] = frame; | 883 | 1.57k | x264_pthread_mutex_unlock( &slist->mutex ); | 884 | 1.57k | x264_pthread_cond_broadcast( &slist->cv_fill ); | 885 | 1.57k | } |
Unexecuted instantiation: x264_10_sync_frame_list_push |
886 | | |
887 | | x264_frame_t *x264_sync_frame_list_pop( x264_sync_frame_list_t *slist ) |
888 | 169 | { |
889 | 169 | x264_frame_t *frame; |
890 | 169 | x264_pthread_mutex_lock( &slist->mutex ); |
891 | 169 | while( !slist->i_size ) |
892 | 0 | x264_pthread_cond_wait( &slist->cv_fill, &slist->mutex ); |
893 | 169 | frame = slist->list[ --slist->i_size ]; |
894 | 169 | slist->list[ slist->i_size ] = NULL; |
895 | 169 | x264_pthread_cond_broadcast( &slist->cv_empty ); |
896 | 169 | x264_pthread_mutex_unlock( &slist->mutex ); |
897 | 169 | return frame; |
898 | 169 | } x264_8_sync_frame_list_pop Line | Count | Source | 888 | 169 | { | 889 | 169 | x264_frame_t *frame; | 890 | 169 | x264_pthread_mutex_lock( &slist->mutex ); | 891 | 169 | while( !slist->i_size ) | 892 | 0 | x264_pthread_cond_wait( &slist->cv_fill, &slist->mutex ); | 893 | 169 | frame = slist->list[ --slist->i_size ]; | 894 | 169 | slist->list[ slist->i_size ] = NULL; | 895 | 169 | x264_pthread_cond_broadcast( &slist->cv_empty ); | 896 | 169 | x264_pthread_mutex_unlock( &slist->mutex ); | 897 | 169 | return frame; | 898 | 169 | } |
Unexecuted instantiation: x264_10_sync_frame_list_pop |