Coverage Report

Created: 2026-05-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.08k
{
32
2.08k
    x = ALIGN( x, align );
33
2.08k
    if( !(x&(disalign-1)) )
34
0
        x += align;
35
2.08k
    return x;
36
2.08k
}
37
38
static int align_plane_size( int x, int disalign )
39
2.42k
{
40
2.42k
    if( !(x&(disalign-1)) )
41
1.01k
        x += X264_MAX( 128, NATIVE_ALIGN ) / SIZEOF_PIXEL;
42
2.42k
    return x;
43
2.42k
}
44
45
static int frame_internal_csp( int external_csp )
46
1.21k
{
47
1.21k
    int csp = external_csp & X264_CSP_MASK;
48
1.21k
    if( csp == X264_CSP_I400 )
49
0
        return X264_CSP_I400;
50
1.21k
    if( csp >= X264_CSP_I420 && csp < X264_CSP_I422 )
51
1.21k
        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.04k
{
61
1.04k
    x264_frame_t *frame;
62
1.04k
    int i_csp = frame_internal_csp( h->param.i_csp );
63
1.04k
    int i_mb_count = h->mb.i_mb_count;
64
1.04k
    int i_stride, i_width, i_lines, luma_plane_count;
65
1.04k
    int i_padv = PADV << PARAM_INTERLACED;
66
1.04k
    int align = NATIVE_ALIGN / SIZEOF_PIXEL;
67
1.04k
#if ARCH_X86 || ARCH_X86_64
68
1.04k
    if( h->param.cpu&X264_CPU_CACHELINE_64 || h->param.cpu&X264_CPU_AVX512 )
69
0
        align = 64 / SIZEOF_PIXEL;
70
1.04k
    else if( h->param.cpu&X264_CPU_CACHELINE_32 || h->param.cpu&X264_CPU_AVX )
71
0
        align = 32 / SIZEOF_PIXEL;
72
1.04k
    else
73
1.04k
        align = 16 / SIZEOF_PIXEL;
74
1.04k
#endif
75
#if ARCH_PPC
76
    int disalign = (1<<9) / SIZEOF_PIXEL;
77
#else
78
1.04k
    int disalign = (1<<10) / SIZEOF_PIXEL;
79
1.04k
#endif
80
81
1.04k
    CHECKED_MALLOCZERO( frame, sizeof(x264_frame_t) );
82
1.04k
    PREALLOC_INIT
83
84
    /* allocate frame data (+64 for extra data for me) */
85
1.04k
    i_width  = h->mb.i_mb_width*16;
86
1.04k
    i_lines  = h->mb.i_mb_height*16;
87
1.04k
    i_stride = align_stride( i_width + PADH2, align, disalign );
88
89
1.04k
    if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 )
90
1.04k
    {
91
1.04k
        luma_plane_count = 1;
92
1.04k
        frame->i_plane = 2;
93
3.13k
        for( int i = 0; i < 2; i++ )
94
2.08k
        {
95
2.08k
            frame->i_width[i] = i_width >> i;
96
2.08k
            frame->i_lines[i] = i_lines >> (i && i_csp == X264_CSP_NV12);
97
2.08k
            frame->i_stride[i] = i_stride;
98
2.08k
        }
99
1.04k
    }
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.04k
    frame->i_csp = i_csp;
123
1.04k
    frame->i_width_lowres = frame->i_width[0]/2;
124
1.04k
    frame->i_lines_lowres = frame->i_lines[0]/2;
125
1.04k
    frame->i_stride_lowres = align_stride( frame->i_width_lowres + PADH2, align, disalign<<1 );
126
127
5.33k
    for( int i = 0; i < h->param.i_bframe + 2; i++ )
128
23.8k
        for( int j = 0; j < h->param.i_bframe + 2; j++ )
129
19.5k
            PREALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) );
130
131
1.04k
    frame->i_poc = -1;
132
1.04k
    frame->i_type = X264_TYPE_AUTO;
133
1.04k
    frame->i_qpplus1 = X264_QP_AUTO;
134
1.04k
    frame->i_pts = -1;
135
1.04k
    frame->i_frame = -1;
136
1.04k
    frame->i_frame_num = -1;
137
1.04k
    frame->i_lines_completed = -1;
138
1.04k
    frame->b_fdec = b_fdec;
139
1.04k
    frame->i_pic_struct = PIC_STRUCT_AUTO;
140
1.04k
    frame->i_field_cnt = -1;
141
1.04k
    frame->i_duration =
142
1.04k
    frame->i_cpb_duration =
143
1.04k
    frame->i_dpb_output_delay =
144
1.04k
    frame->i_cpb_delay = 0;
145
1.04k
    frame->i_coded_fields_lookahead =
146
1.04k
    frame->i_cpb_delay_lookahead = -1;
147
148
1.04k
    frame->orig = frame;
149
150
1.04k
    if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 )
151
1.04k
    {
152
1.04k
        int chroma_padv = i_padv >> (i_csp == X264_CSP_NV12);
153
1.04k
        int chroma_plane_size = (frame->i_stride[1] * (frame->i_lines[1] + 2*chroma_padv));
154
1.04k
        PREALLOC( frame->buffer[1], chroma_plane_size * SIZEOF_PIXEL );
155
1.04k
        if( PARAM_INTERLACED )
156
0
            PREALLOC( frame->buffer_fld[1], chroma_plane_size * SIZEOF_PIXEL );
157
1.04k
    }
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.08k
    for( int p = 0; p < luma_plane_count; p++ )
163
1.04k
    {
164
1.04k
        int64_t luma_plane_size = align_plane_size( frame->i_stride[p] * (frame->i_lines[p] + 2*i_padv), disalign );
165
1.04k
        if( h->param.analyse.i_subpel_refine && b_fdec )
166
877
            luma_plane_size *= 4;
167
168
        /* FIXME: Don't allocate both buffers in non-adaptive MBAFF. */
169
1.04k
        PREALLOC( frame->buffer[p], luma_plane_size * SIZEOF_PIXEL );
170
1.04k
        if( PARAM_INTERLACED )
171
0
            PREALLOC( frame->buffer_fld[p], luma_plane_size * SIZEOF_PIXEL );
172
1.04k
    }
173
174
1.04k
    frame->b_duplicate = 0;
175
176
1.04k
    if( b_fdec ) /* fdec frame */
177
877
    {
178
877
        PREALLOC( frame->mb_type, i_mb_count * sizeof(int8_t) );
179
877
        PREALLOC( frame->mb_partition, i_mb_count * sizeof(uint8_t) );
180
877
        PREALLOC( frame->mv[0], 2*16 * i_mb_count * sizeof(int16_t) );
181
877
        PREALLOC( frame->mv16x16, 2*(i_mb_count+1) * sizeof(int16_t) );
182
877
        PREALLOC( frame->ref[0], 4 * i_mb_count * sizeof(int8_t) );
183
877
        if( h->param.i_bframe )
184
616
        {
185
616
            PREALLOC( frame->mv[1], 2*16 * i_mb_count * sizeof(int16_t) );
186
616
            PREALLOC( frame->ref[1], 4 * i_mb_count * sizeof(int8_t) );
187
616
        }
188
261
        else
189
261
        {
190
261
            frame->mv[1]  = NULL;
191
261
            frame->ref[1] = NULL;
192
261
        }
193
877
        PREALLOC( frame->i_row_bits, i_lines/16 * sizeof(int) );
194
877
        PREALLOC( frame->f_row_qp, i_lines/16 * sizeof(float) );
195
877
        PREALLOC( frame->f_row_qscale, i_lines/16 * sizeof(float) );
196
877
        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
877
        if( PARAM_INTERLACED )
199
0
            PREALLOC( frame->field, i_mb_count * sizeof(uint8_t) );
200
877
        if( h->param.analyse.b_mb_info )
201
0
            PREALLOC( frame->effective_qp, i_mb_count * sizeof(uint8_t) );
202
877
    }
203
167
    else /* fenc frame */
204
167
    {
205
167
        if( h->frames.b_have_lowres )
206
167
        {
207
167
            int64_t luma_plane_size = align_plane_size( frame->i_stride_lowres * (frame->i_lines[0]/2 + 2*PADV), disalign );
208
209
167
            PREALLOC( frame->buffer_lowres, 4 * luma_plane_size * SIZEOF_PIXEL );
210
211
451
            for( int j = 0; j <= !!h->param.i_bframe; j++ )
212
1.27k
                for( int i = 0; i <= h->param.i_bframe; i++ )
213
986
                {
214
986
                    PREALLOC( frame->lowres_mvs[j][i], 2*i_mb_count*sizeof(int16_t) );
215
986
                    PREALLOC( frame->lowres_mv_costs[j][i], i_mb_count*sizeof(int) );
216
986
                }
217
167
            PREALLOC( frame->i_propagate_cost, i_mb_count * sizeof(uint16_t) );
218
852
            for( int j = 0; j <= h->param.i_bframe+1; j++ )
219
3.81k
                for( int i = 0; i <= h->param.i_bframe+1; i++ )
220
3.12k
                    PREALLOC( frame->lowres_costs[j][i], i_mb_count * sizeof(uint16_t) );
221
167
        }
222
167
        if( h->param.rc.i_aq_mode )
223
117
        {
224
117
            PREALLOC( frame->f_qp_offset, i_mb_count * sizeof(float) );
225
117
            PREALLOC( frame->f_qp_offset_aq, i_mb_count * sizeof(float) );
226
117
            if( h->frames.b_have_lowres )
227
117
                PREALLOC( frame->i_inv_qscale_factor, i_mb_count * sizeof(uint16_t) );
228
117
        }
229
230
        /* mbtree asm can overread the input buffers, make sure we don't read outside of allocated memory. */
231
167
        if( h->frames.b_have_lowres )
232
167
            prealloc_size += NATIVE_ALIGN;
233
167
    }
234
235
1.04k
    PREALLOC_END( frame->base );
236
237
1.04k
    if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 )
238
1.04k
    {
239
1.04k
        int chroma_padv = i_padv >> (i_csp == X264_CSP_NV12);
240
1.04k
        frame->plane[1] = frame->buffer[1] + frame->i_stride[1] * chroma_padv + PADH_ALIGN;
241
1.04k
        if( PARAM_INTERLACED )
242
0
            frame->plane_fld[1] = frame->buffer_fld[1] + frame->i_stride[1] * chroma_padv + PADH_ALIGN;
243
1.04k
    }
244
245
2.08k
    for( int p = 0; p < luma_plane_count; p++ )
246
1.04k
    {
247
1.04k
        int64_t luma_plane_size = align_plane_size( frame->i_stride[p] * (frame->i_lines[p] + 2*i_padv), disalign );
248
1.04k
        if( h->param.analyse.i_subpel_refine && b_fdec )
249
877
        {
250
4.38k
            for( int i = 0; i < 4; i++ )
251
3.50k
            {
252
3.50k
                frame->filtered[p][i] = frame->buffer[p] + i*luma_plane_size + frame->i_stride[p] * i_padv + PADH_ALIGN;
253
3.50k
                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.50k
            }
256
877
            frame->plane[p] = frame->filtered[p][0];
257
877
            frame->plane_fld[p] = frame->filtered_fld[p][0];
258
877
        }
259
167
        else
260
167
        {
261
167
            frame->filtered[p][0] = frame->plane[p] = frame->buffer[p] + frame->i_stride[p] * i_padv + PADH_ALIGN;
262
167
            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
167
        }
265
1.04k
    }
266
267
1.04k
    if( b_fdec )
268
877
    {
269
877
        M32( frame->mv16x16[0] ) = 0;
270
877
        frame->mv16x16++;
271
272
877
        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
877
    }
275
167
    else
276
167
    {
277
167
        if( h->frames.b_have_lowres )
278
167
        {
279
167
            int64_t luma_plane_size = align_plane_size( frame->i_stride_lowres * (frame->i_lines[0]/2 + 2*PADV), disalign );
280
835
            for( int i = 0; i < 4; i++ )
281
668
                frame->lowres[i] = frame->buffer_lowres + frame->i_stride_lowres * PADV + PADH_ALIGN + i * luma_plane_size;
282
283
451
            for( int j = 0; j <= !!h->param.i_bframe; j++ )
284
1.27k
                for( int i = 0; i <= h->param.i_bframe; i++ )
285
986
                    memset( frame->lowres_mvs[j][i], 0, 2*i_mb_count*sizeof(int16_t) );
286
287
167
            frame->i_intra_cost = frame->lowres_costs[0][0];
288
167
            memset( frame->i_intra_cost, -1, i_mb_count * sizeof(uint16_t) );
289
290
167
            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
117
                memset( frame->i_inv_qscale_factor, 0, i_mb_count * sizeof(uint16_t) );
293
167
        }
294
167
    }
295
296
1.04k
    if( x264_pthread_mutex_init( &frame->mutex, NULL ) )
297
0
        goto fail;
298
1.04k
    if( x264_pthread_cond_init( &frame->cv, NULL ) )
299
0
        goto fail;
300
301
1.04k
#if HAVE_OPENCL
302
1.04k
    frame->opencl.ocl = h->opencl.ocl;
303
1.04k
#endif
304
305
1.04k
    return frame;
306
307
0
fail:
308
0
    x264_free( frame );
309
0
    return NULL;
310
1.04k
}
311
312
void x264_frame_delete( x264_frame_t *frame )
313
1.04k
{
314
    /* Duplicate frames are blank copies of real frames (including pointers),
315
     * so freeing those pointers would cause a double free later. */
316
1.04k
    if( !frame->b_duplicate )
317
1.04k
    {
318
1.04k
        x264_free( frame->base );
319
320
1.04k
        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.04k
        if( frame->mb_info_free )
326
0
            frame->mb_info_free( frame->mb_info );
327
1.04k
        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.04k
        x264_pthread_mutex_destroy( &frame->mutex );
334
1.04k
        x264_pthread_cond_destroy( &frame->cv );
335
#if HAVE_OPENCL
336
1.04k
        x264_opencl_frame_delete( frame );
337
#endif
338
1.04k
    }
339
1.04k
    x264_free( frame );
340
1.04k
}
x264_8_frame_delete
Line
Count
Source
313
1.04k
{
314
    /* Duplicate frames are blank copies of real frames (including pointers),
315
     * so freeing those pointers would cause a double free later. */
316
1.04k
    if( !frame->b_duplicate )
317
1.04k
    {
318
1.04k
        x264_free( frame->base );
319
320
1.04k
        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.04k
        if( frame->mb_info_free )
326
0
            frame->mb_info_free( frame->mb_info );
327
1.04k
        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.04k
        x264_pthread_mutex_destroy( &frame->mutex );
334
1.04k
        x264_pthread_cond_destroy( &frame->cv );
335
1.04k
#if HAVE_OPENCL
336
1.04k
        x264_opencl_frame_delete( frame );
337
1.04k
#endif
338
1.04k
    }
339
1.04k
    x264_free( frame );
340
1.04k
}
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
501
{
344
501
    int width = h->param.i_width >> xshift;
345
501
    int height = h->param.i_height >> yshift;
346
501
    *pix = src->img.plane[plane];
347
501
    *stride = src->img.i_stride[plane];
348
501
    if( src->img.i_csp & X264_CSP_VFLIP )
349
0
    {
350
0
        *pix += (height-1) * *stride;
351
0
        *stride = -*stride;
352
0
    }
353
501
    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
501
    return 0;
359
501
}
360
361
668
#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
167
{
365
167
    int i_csp = src->img.i_csp & X264_CSP_MASK;
366
167
    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
167
    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
167
#endif
385
386
167
    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
167
    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
167
    else
398
167
        dst->i_forced_type = src->i_type;
399
400
167
    dst->i_type     = dst->i_forced_type;
401
167
    dst->i_qpplus1  = src->i_qpplus1;
402
167
    dst->i_pts      = dst->i_reordered_pts = src->i_pts;
403
167
    dst->param      = src->param;
404
167
    dst->i_pic_struct = src->i_pic_struct;
405
167
    dst->extra_sei  = src->extra_sei;
406
167
    dst->opaque     = src->opaque;
407
167
    dst->mb_info    = h->param.analyse.b_mb_info ? src->prop.mb_info : NULL;
408
167
    dst->mb_info_free = h->param.analyse.b_mb_info ? src->prop.mb_info_free : NULL;
409
410
167
    uint8_t *pix[3];
411
167
    int stride[3];
412
167
    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
167
    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
167
    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
167
    else
443
167
    {
444
167
        int v_shift = CHROMA_V_SHIFT;
445
167
        get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 );
446
167
        h->mc.plane_copy( dst->plane[0], dst->i_stride[0], (pixel*)pix[0],
447
167
                          stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height );
448
167
        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
167
        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
167
        else if( i_csp == X264_CSP_I420 || i_csp == X264_CSP_I422 || i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16 )
461
167
        {
462
167
            int uv_swap = i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16;
463
167
            get_plane_ptr( h, src, &pix[1], &stride[1], uv_swap ? 2 : 1, 1, v_shift );
464
167
            get_plane_ptr( h, src, &pix[2], &stride[2], uv_swap ? 1 : 2, 1, v_shift );
465
167
            h->mc.plane_copy_interleave( dst->plane[1], dst->i_stride[1],
466
167
                                         (pixel*)pix[1], stride[1]/SIZEOF_PIXEL,
467
167
                                         (pixel*)pix[2], stride[2]/SIZEOF_PIXEL,
468
167
                                         h->param.i_width>>1, h->param.i_height>>v_shift );
469
167
        }
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
167
    }
480
167
    return 0;
481
167
}
x264_8_frame_copy_picture
Line
Count
Source
364
167
{
365
167
    int i_csp = src->img.i_csp & X264_CSP_MASK;
366
167
    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
167
    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
167
#endif
385
386
167
    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
167
    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
167
    else
398
167
        dst->i_forced_type = src->i_type;
399
400
167
    dst->i_type     = dst->i_forced_type;
401
167
    dst->i_qpplus1  = src->i_qpplus1;
402
167
    dst->i_pts      = dst->i_reordered_pts = src->i_pts;
403
167
    dst->param      = src->param;
404
167
    dst->i_pic_struct = src->i_pic_struct;
405
167
    dst->extra_sei  = src->extra_sei;
406
167
    dst->opaque     = src->opaque;
407
167
    dst->mb_info    = h->param.analyse.b_mb_info ? src->prop.mb_info : NULL;
408
167
    dst->mb_info_free = h->param.analyse.b_mb_info ? src->prop.mb_info_free : NULL;
409
410
167
    uint8_t *pix[3];
411
167
    int stride[3];
412
167
    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
167
    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
167
    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
167
    else
443
167
    {
444
167
        int v_shift = CHROMA_V_SHIFT;
445
167
        get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 );
446
167
        h->mc.plane_copy( dst->plane[0], dst->i_stride[0], (pixel*)pix[0],
447
167
                          stride[0]/SIZEOF_PIXEL, h->param.i_width, h->param.i_height );
448
167
        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
167
        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
167
        else if( i_csp == X264_CSP_I420 || i_csp == X264_CSP_I422 || i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16 )
461
167
        {
462
167
            int uv_swap = i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16;
463
167
            get_plane_ptr( h, src, &pix[1], &stride[1], uv_swap ? 2 : 1, 1, v_shift );
464
167
            get_plane_ptr( h, src, &pix[2], &stride[2], uv_swap ? 1 : 2, 1, v_shift );
465
167
            h->mc.plane_copy_interleave( dst->plane[1], dst->i_stride[1],
466
167
                                         (pixel*)pix[1], stride[1]/SIZEOF_PIXEL,
467
167
                                         (pixel*)pix[2], stride[2]/SIZEOF_PIXEL,
468
167
                                         h->param.i_width>>1, h->param.i_height>>v_shift );
469
167
        }
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
167
    }
480
167
    return 0;
481
167
}
Unexecuted instantiation: x264_10_frame_copy_picture
482
483
static ALWAYS_INLINE void pixel_memset( pixel *dst, pixel *src, int len, int size )
484
434k
{
485
434k
    uint8_t *dstp = (uint8_t*)dst;
486
434k
    uint32_t v1 = *src;
487
434k
    uint32_t v2 = size == 1 ? v1 + (v1 <<  8) : M16( src );
488
434k
    uint32_t v4 = size <= 2 ? v2 + (v2 << 16) : M32( src );
489
434k
    int i = 0;
490
434k
    len *= size;
491
492
    /* Align the input pointer if it isn't already */
493
434k
    if( (intptr_t)dstp & (WORD_SIZE - 1) )
494
126k
    {
495
126k
        if( size <= 2 && ((intptr_t)dstp & 3) )
496
21.2k
        {
497
21.2k
            if( size == 1 && ((intptr_t)dstp & 1) )
498
0
                dstp[i++] = v1;
499
21.2k
            if( (intptr_t)dstp & 2 )
500
21.2k
            {
501
21.2k
                M16( dstp+i ) = v2;
502
21.2k
                i += 2;
503
21.2k
            }
504
21.2k
        }
505
126k
        if( WORD_SIZE == 8 && (intptr_t)dstp & 4 )
506
114k
        {
507
114k
            M32( dstp+i ) = v4;
508
114k
            i += 4;
509
114k
        }
510
126k
    }
511
512
    /* Main copy loop */
513
434k
    if( WORD_SIZE == 8 )
514
434k
    {
515
434k
        uint64_t v8 = v4 + ((uint64_t)v4<<32);
516
1.86M
        for( ; i < len - 7; i+=8 )
517
1.43M
            M64( dstp+i ) = v8;
518
434k
    }
519
545k
    for( ; i < len - 3; i+=4 )
520
111k
        M32( dstp+i ) = v4;
521
522
    /* Finish up the last few bytes */
523
434k
    if( size <= 2 )
524
434k
    {
525
434k
        if( i < len - 1 )
526
0
        {
527
0
            M16( dstp+i ) = v2;
528
0
            i += 2;
529
0
        }
530
434k
        if( size == 1 && i != len )
531
4.52k
            dstp[i] = v1;
532
434k
    }
533
434k
}
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
9.90k
{
537
970k
#define PPIXEL(x, y) ( pix + (x) + (y)*i_stride )
538
211k
    for( int y = 0; y < i_height; y++ )
539
201k
    {
540
        /* left band */
541
201k
        pixel_memset( PPIXEL(-i_padh, y), PPIXEL(0, y), i_padh>>b_chroma, SIZEOF_PIXEL<<b_chroma );
542
        /* right band */
543
201k
        pixel_memset( PPIXEL(i_width, y), PPIXEL(i_width-1-b_chroma, y), i_padh>>b_chroma, SIZEOF_PIXEL<<b_chroma );
544
201k
    }
545
    /* upper band */
546
9.90k
    if( b_pad_top )
547
42.9k
        for( int y = 0; y < i_padv; y++ )
548
41.4k
            memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), (i_width+2*i_padh) * SIZEOF_PIXEL );
549
    /* lower band */
550
9.90k
    if( b_pad_bottom )
551
42.9k
        for( int y = 0; y < i_padv; y++ )
552
41.4k
            memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), (i_width+2*i_padh) * SIZEOF_PIXEL );
553
9.90k
#undef PPIXEL
554
9.90k
}
555
556
void x264_frame_expand_border( x264_t *h, x264_frame_t *frame, int mb_y )
557
1.84k
{
558
1.84k
    int pad_top = mb_y == 0;
559
1.84k
    int pad_bot = mb_y == h->mb.i_mb_height - (1 << SLICE_MBAFF);
560
1.84k
    int b_start = mb_y == h->i_threadslice_start;
561
1.84k
    int b_end   = mb_y == h->i_threadslice_end - (1 << SLICE_MBAFF);
562
1.84k
    if( mb_y & SLICE_MBAFF )
563
0
        return;
564
5.54k
    for( int i = 0; i < frame->i_plane; i++ )
565
3.69k
    {
566
3.69k
        int h_shift = i && CHROMA_H_SHIFT;
567
3.69k
        int v_shift = i && CHROMA_V_SHIFT;
568
3.69k
        int stride = frame->i_stride[i];
569
3.69k
        int width = 16*h->mb.i_mb_width;
570
3.69k
        int height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF : 16) >> v_shift;
571
3.69k
        int padh = PADH;
572
3.69k
        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.69k
        if( b_end && !b_start )
575
334
            height += 4 >> (v_shift + SLICE_MBAFF);
576
3.69k
        pixel *pix;
577
3.69k
        int starty = 16*mb_y - 4*!b_start;
578
3.69k
        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.69k
        else
592
3.69k
        {
593
3.69k
            pix = frame->plane[i] + (starty*stride >> v_shift);
594
3.69k
            plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift );
595
3.69k
        }
596
3.69k
    }
597
1.84k
}
x264_8_frame_expand_border
Line
Count
Source
557
1.84k
{
558
1.84k
    int pad_top = mb_y == 0;
559
1.84k
    int pad_bot = mb_y == h->mb.i_mb_height - (1 << SLICE_MBAFF);
560
1.84k
    int b_start = mb_y == h->i_threadslice_start;
561
1.84k
    int b_end   = mb_y == h->i_threadslice_end - (1 << SLICE_MBAFF);
562
1.84k
    if( mb_y & SLICE_MBAFF )
563
0
        return;
564
5.54k
    for( int i = 0; i < frame->i_plane; i++ )
565
3.69k
    {
566
3.69k
        int h_shift = i && CHROMA_H_SHIFT;
567
3.69k
        int v_shift = i && CHROMA_V_SHIFT;
568
3.69k
        int stride = frame->i_stride[i];
569
3.69k
        int width = 16*h->mb.i_mb_width;
570
3.69k
        int height = (pad_bot ? 16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF : 16) >> v_shift;
571
3.69k
        int padh = PADH;
572
3.69k
        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.69k
        if( b_end && !b_start )
575
334
            height += 4 >> (v_shift + SLICE_MBAFF);
576
3.69k
        pixel *pix;
577
3.69k
        int starty = 16*mb_y - 4*!b_start;
578
3.69k
        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.69k
        else
592
3.69k
        {
593
3.69k
            pix = frame->plane[i] + (starty*stride >> v_shift);
594
3.69k
            plane_expand_border( pix, stride, width, height, padh, padv, pad_top, pad_bot, h_shift );
595
3.69k
        }
596
3.69k
    }
597
1.84k
}
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.84k
{
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.84k
    int b_start = !mb_y;
605
1.84k
    int width = 16*h->mb.i_mb_width + 8;
606
1.84k
    int height = b_end ? (16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF) + 16 : 16;
607
1.84k
    int padh = PADH - 4;
608
1.84k
    int padv = PADV - 8;
609
3.69k
    for( int p = 0; p < (CHROMA444 ? 3 : 1); p++ )
610
7.38k
        for( int i = 1; i < 4; i++ )
611
5.54k
        {
612
5.54k
            int stride = frame->i_stride[p];
613
            // buffer: 8 luma, to match the hpel filter
614
5.54k
            pixel *pix;
615
5.54k
            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.54k
            pix = frame->filtered[p][i] + (16*mb_y - 8) * stride - 4;
623
5.54k
            plane_expand_border( pix, stride, width, height << SLICE_MBAFF, padh, padv, b_start, b_end, 0 );
624
5.54k
        }
625
1.84k
}
x264_8_frame_expand_border_filtered
Line
Count
Source
600
1.84k
{
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.84k
    int b_start = !mb_y;
605
1.84k
    int width = 16*h->mb.i_mb_width + 8;
606
1.84k
    int height = b_end ? (16*(h->mb.i_mb_height - mb_y) >> SLICE_MBAFF) + 16 : 16;
607
1.84k
    int padh = PADH - 4;
608
1.84k
    int padv = PADV - 8;
609
3.69k
    for( int p = 0; p < (CHROMA444 ? 3 : 1); p++ )
610
7.38k
        for( int i = 1; i < 4; i++ )
611
5.54k
        {
612
5.54k
            int stride = frame->i_stride[p];
613
            // buffer: 8 luma, to match the hpel filter
614
5.54k
            pixel *pix;
615
5.54k
            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.54k
            pix = frame->filtered[p][i] + (16*mb_y - 8) * stride - 4;
623
5.54k
            plane_expand_border( pix, stride, width, height << SLICE_MBAFF, padh, padv, b_start, b_end, 0 );
624
5.54k
        }
625
1.84k
}
Unexecuted instantiation: x264_10_frame_expand_border_filtered
626
627
void x264_frame_expand_border_lowres( x264_frame_t *frame )
628
167
{
629
835
    for( int i = 0; i < 4; i++ )
630
668
        plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_width_lowres, frame->i_lines_lowres, PADH, PADV, 1, 1, 0 );
631
167
}
x264_8_frame_expand_border_lowres
Line
Count
Source
628
167
{
629
835
    for( int i = 0; i < 4; i++ )
630
668
        plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_width_lowres, frame->i_lines_lowres, PADH, PADV, 1, 1, 0 );
631
167
}
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
147
{
642
441
    for( int i = 0; i < frame->i_plane; i++ )
643
294
    {
644
294
        int i_width = h->param.i_width;
645
294
        int h_shift = i && CHROMA_H_SHIFT;
646
294
        int v_shift = i && CHROMA_V_SHIFT;
647
294
        int i_height = h->param.i_height >> v_shift;
648
294
        int i_padx = (h->mb.i_mb_width * 16 - h->param.i_width);
649
294
        int i_pady = (h->mb.i_mb_height * 16 - h->param.i_height) >> v_shift;
650
651
294
        if( i_padx )
652
244
        {
653
32.7k
            for( int y = 0; y < i_height; y++ )
654
32.5k
                pixel_memset( &frame->plane[i][y*frame->i_stride[i] + i_width],
655
32.5k
                              &frame->plane[i][y*frame->i_stride[i] + i_width - 1-h_shift],
656
32.5k
                              i_padx>>h_shift, SIZEOF_PIXEL<<h_shift );
657
244
        }
658
294
        if( i_pady )
659
236
        {
660
1.55k
            for( int y = i_height; y < i_height + i_pady; y++ )
661
1.31k
                memcpy( &frame->plane[i][y*frame->i_stride[i]],
662
1.31k
                        &frame->plane[i][(i_height-(~y&PARAM_INTERLACED)-1)*frame->i_stride[i]],
663
1.31k
                        (i_width + i_padx) * SIZEOF_PIXEL );
664
236
        }
665
294
    }
666
147
}
x264_8_frame_expand_border_mod16
Line
Count
Source
641
147
{
642
441
    for( int i = 0; i < frame->i_plane; i++ )
643
294
    {
644
294
        int i_width = h->param.i_width;
645
294
        int h_shift = i && CHROMA_H_SHIFT;
646
294
        int v_shift = i && CHROMA_V_SHIFT;
647
294
        int i_height = h->param.i_height >> v_shift;
648
294
        int i_padx = (h->mb.i_mb_width * 16 - h->param.i_width);
649
294
        int i_pady = (h->mb.i_mb_height * 16 - h->param.i_height) >> v_shift;
650
651
294
        if( i_padx )
652
244
        {
653
32.7k
            for( int y = 0; y < i_height; y++ )
654
32.5k
                pixel_memset( &frame->plane[i][y*frame->i_stride[i] + i_width],
655
32.5k
                              &frame->plane[i][y*frame->i_stride[i] + i_width - 1-h_shift],
656
32.5k
                              i_padx>>h_shift, SIZEOF_PIXEL<<h_shift );
657
244
        }
658
294
        if( i_pady )
659
236
        {
660
1.55k
            for( int y = i_height; y < i_height + i_pady; y++ )
661
1.31k
                memcpy( &frame->plane[i][y*frame->i_stride[i]],
662
1.31k
                        &frame->plane[i][(i_height-(~y&PARAM_INTERLACED)-1)*frame->i_stride[i]],
663
1.31k
                        (i_width + i_padx) * SIZEOF_PIXEL );
664
236
        }
665
294
    }
666
147
}
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.84k
{
685
1.84k
    x264_pthread_mutex_lock( &frame->mutex );
686
1.84k
    frame->i_lines_completed = i_lines_completed;
687
1.84k
    x264_pthread_cond_broadcast( &frame->cv );
688
1.84k
    x264_pthread_mutex_unlock( &frame->mutex );
689
1.84k
}
x264_8_frame_cond_broadcast
Line
Count
Source
684
1.84k
{
685
1.84k
    x264_pthread_mutex_lock( &frame->mutex );
686
1.84k
    frame->i_lines_completed = i_lines_completed;
687
1.84k
    x264_pthread_cond_broadcast( &frame->cv );
688
1.84k
    x264_pthread_mutex_unlock( &frame->mutex );
689
1.84k
}
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.21k
{
737
1.21k
    int i = 0;
738
2.87k
    while( list[i] ) i++;
739
1.21k
    list[i] = frame;
740
1.21k
}
x264_8_frame_push
Line
Count
Source
736
1.21k
{
737
1.21k
    int i = 0;
738
2.87k
    while( list[i] ) i++;
739
1.21k
    list[i] = frame;
740
1.21k
}
Unexecuted instantiation: x264_10_frame_push
741
742
x264_frame_t *x264_frame_pop( x264_frame_t **list )
743
167
{
744
167
    x264_frame_t *frame;
745
167
    int i = 0;
746
167
    assert( list[0] );
747
309
    while( list[i+1] ) i++;
748
167
    frame = list[i];
749
167
    list[i] = NULL;
750
167
    return frame;
751
167
}
x264_8_frame_pop
Line
Count
Source
743
167
{
744
167
    x264_frame_t *frame;
745
167
    int i = 0;
746
167
    assert( list[0] );
747
309
    while( list[i+1] ) i++;
748
167
    frame = list[i];
749
    list[i] = NULL;
750
167
    return frame;
751
167
}
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.00k
{
764
1.00k
    x264_frame_t *frame = list[0];
765
1.00k
    int i;
766
2.00k
    for( i = 0; list[i]; i++ )
767
1.00k
        list[i] = list[i+1];
768
1.00k
    assert(frame);
769
1.00k
    return frame;
770
1.00k
}
x264_8_frame_shift
Line
Count
Source
763
1.00k
{
764
1.00k
    x264_frame_t *frame = list[0];
765
1.00k
    int i;
766
2.00k
    for( i = 0; list[i]; i++ )
767
1.00k
        list[i] = list[i+1];
768
1.00k
    assert(frame);
769
1.00k
    return frame;
770
1.00k
}
Unexecuted instantiation: x264_10_frame_shift
771
772
void x264_frame_push_unused( x264_t *h, x264_frame_t *frame )
773
1.54k
{
774
1.54k
    assert( frame->i_reference_count > 0 );
775
1.54k
    frame->i_reference_count--;
776
1.54k
    if( frame->i_reference_count == 0 )
777
1.04k
        x264_frame_push( h->frames.unused[frame->b_fdec], frame );
778
1.54k
}
x264_8_frame_push_unused
Line
Count
Source
773
1.54k
{
774
1.54k
    assert( frame->i_reference_count > 0 );
775
1.54k
    frame->i_reference_count--;
776
1.54k
    if( frame->i_reference_count == 0 )
777
1.04k
        x264_frame_push( h->frames.unused[frame->b_fdec], frame );
778
1.54k
}
Unexecuted instantiation: x264_10_frame_push_unused
779
780
x264_frame_t *x264_frame_pop_unused( x264_t *h, int b_fdec )
781
1.21k
{
782
1.21k
    x264_frame_t *frame;
783
1.21k
    if( h->frames.unused[b_fdec][0] )
784
167
        frame = x264_frame_pop( h->frames.unused[b_fdec] );
785
1.04k
    else
786
1.04k
        frame = frame_new( h, b_fdec );
787
1.21k
    if( !frame )
788
0
        return NULL;
789
1.21k
    frame->b_last_minigop_bframe = 0;
790
1.21k
    frame->i_reference_count = 1;
791
1.21k
    frame->b_intra_calculated = 0;
792
1.21k
    frame->b_scenecut = 1;
793
1.21k
    frame->b_keyframe = 0;
794
1.21k
    frame->b_corrupt = 0;
795
1.21k
    frame->i_slice_count = h->param.b_sliced_threads ? h->param.i_threads : 1;
796
797
1.21k
    memset( frame->weight, 0, sizeof(frame->weight) );
798
1.21k
    memset( frame->f_weighted_cost_delta, 0, sizeof(frame->f_weighted_cost_delta) );
799
800
1.21k
    return frame;
801
1.21k
}
x264_8_frame_pop_unused
Line
Count
Source
781
1.21k
{
782
1.21k
    x264_frame_t *frame;
783
1.21k
    if( h->frames.unused[b_fdec][0] )
784
167
        frame = x264_frame_pop( h->frames.unused[b_fdec] );
785
1.04k
    else
786
1.04k
        frame = frame_new( h, b_fdec );
787
1.21k
    if( !frame )
788
0
        return NULL;
789
1.21k
    frame->b_last_minigop_bframe = 0;
790
1.21k
    frame->i_reference_count = 1;
791
1.21k
    frame->b_intra_calculated = 0;
792
1.21k
    frame->b_scenecut = 1;
793
1.21k
    frame->b_keyframe = 0;
794
1.21k
    frame->b_corrupt = 0;
795
1.21k
    frame->i_slice_count = h->param.b_sliced_threads ? h->param.i_threads : 1;
796
797
1.21k
    memset( frame->weight, 0, sizeof(frame->weight) );
798
1.21k
    memset( frame->f_weighted_cost_delta, 0, sizeof(frame->f_weighted_cost_delta) );
799
800
1.21k
    return frame;
801
1.21k
}
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.67k
{
845
1.67k
    int i = 0;
846
1.67k
    if( !list )
847
0
        return;
848
2.54k
    while( list[i] )
849
877
        x264_frame_delete( list[i++] );
850
1.67k
    x264_free( list );
851
1.67k
}
x264_8_frame_delete_list
Line
Count
Source
844
1.67k
{
845
1.67k
    int i = 0;
846
1.67k
    if( !list )
847
0
        return;
848
2.54k
    while( list[i] )
849
877
        x264_frame_delete( list[i++] );
850
1.67k
    x264_free( list );
851
1.67k
}
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.00k
{
855
1.00k
    if( max_size < 0 )
856
0
        return -1;
857
1.00k
    slist->i_max_size = max_size;
858
1.00k
    slist->i_size = 0;
859
1.00k
    CHECKED_MALLOCZERO( slist->list, (max_size+1) * sizeof(x264_frame_t*) );
860
1.00k
    if( x264_pthread_mutex_init( &slist->mutex, NULL ) ||
861
1.00k
        x264_pthread_cond_init( &slist->cv_fill, NULL ) ||
862
1.00k
        x264_pthread_cond_init( &slist->cv_empty, NULL ) )
863
0
        return -1;
864
1.00k
    return 0;
865
0
fail:
866
0
    return -1;
867
1.00k
}
x264_8_sync_frame_list_init
Line
Count
Source
854
1.00k
{
855
1.00k
    if( max_size < 0 )
856
0
        return -1;
857
1.00k
    slist->i_max_size = max_size;
858
1.00k
    slist->i_size = 0;
859
1.00k
    CHECKED_MALLOCZERO( slist->list, (max_size+1) * sizeof(x264_frame_t*) );
860
1.00k
    if( x264_pthread_mutex_init( &slist->mutex, NULL ) ||
861
1.00k
        x264_pthread_cond_init( &slist->cv_fill, NULL ) ||
862
1.00k
        x264_pthread_cond_init( &slist->cv_empty, NULL ) )
863
0
        return -1;
864
1.00k
    return 0;
865
0
fail:
866
0
    return -1;
867
1.00k
}
Unexecuted instantiation: x264_10_sync_frame_list_init
868
869
void x264_sync_frame_list_delete( x264_sync_frame_list_t *slist )
870
1.00k
{
871
1.00k
    x264_pthread_mutex_destroy( &slist->mutex );
872
1.00k
    x264_pthread_cond_destroy( &slist->cv_fill );
873
1.00k
    x264_pthread_cond_destroy( &slist->cv_empty );
874
1.00k
    x264_frame_delete_list( slist->list );
875
1.00k
}
x264_8_sync_frame_list_delete
Line
Count
Source
870
1.00k
{
871
1.00k
    x264_pthread_mutex_destroy( &slist->mutex );
872
1.00k
    x264_pthread_cond_destroy( &slist->cv_fill );
873
1.00k
    x264_pthread_cond_destroy( &slist->cv_empty );
874
1.00k
    x264_frame_delete_list( slist->list );
875
1.00k
}
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.54k
{
879
1.54k
    x264_pthread_mutex_lock( &slist->mutex );
880
1.54k
    while( slist->i_size == slist->i_max_size )
881
0
        x264_pthread_cond_wait( &slist->cv_empty, &slist->mutex );
882
1.54k
    slist->list[ slist->i_size++ ] = frame;
883
1.54k
    x264_pthread_mutex_unlock( &slist->mutex );
884
1.54k
    x264_pthread_cond_broadcast( &slist->cv_fill );
885
1.54k
}
x264_8_sync_frame_list_push
Line
Count
Source
878
1.54k
{
879
1.54k
    x264_pthread_mutex_lock( &slist->mutex );
880
1.54k
    while( slist->i_size == slist->i_max_size )
881
0
        x264_pthread_cond_wait( &slist->cv_empty, &slist->mutex );
882
1.54k
    slist->list[ slist->i_size++ ] = frame;
883
1.54k
    x264_pthread_mutex_unlock( &slist->mutex );
884
1.54k
    x264_pthread_cond_broadcast( &slist->cv_fill );
885
1.54k
}
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
167
{
889
167
    x264_frame_t *frame;
890
167
    x264_pthread_mutex_lock( &slist->mutex );
891
167
    while( !slist->i_size )
892
0
        x264_pthread_cond_wait( &slist->cv_fill, &slist->mutex );
893
167
    frame = slist->list[ --slist->i_size ];
894
167
    slist->list[ slist->i_size ] = NULL;
895
167
    x264_pthread_cond_broadcast( &slist->cv_empty );
896
167
    x264_pthread_mutex_unlock( &slist->mutex );
897
167
    return frame;
898
167
}
x264_8_sync_frame_list_pop
Line
Count
Source
888
167
{
889
167
    x264_frame_t *frame;
890
167
    x264_pthread_mutex_lock( &slist->mutex );
891
167
    while( !slist->i_size )
892
0
        x264_pthread_cond_wait( &slist->cv_fill, &slist->mutex );
893
167
    frame = slist->list[ --slist->i_size ];
894
167
    slist->list[ slist->i_size ] = NULL;
895
167
    x264_pthread_cond_broadcast( &slist->cv_empty );
896
167
    x264_pthread_mutex_unlock( &slist->mutex );
897
167
    return frame;
898
167
}
Unexecuted instantiation: x264_10_sync_frame_list_pop