Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/x264/encoder/api.c
Line
Count
Source
1
/*****************************************************************************
2
 * api.c: bit depth independent interface
3
 *****************************************************************************
4
 * Copyright (C) 2003-2025 x264 project
5
 *
6
 * Authors: Vittorio Giovara <vittorio.giovara@gmail.com>
7
 *          Luca Barbato <lu_zero@gentoo.org>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
22
 *
23
 * This program is also available under a commercial proprietary license.
24
 * For more information, contact us at licensing@x264.com.
25
 *****************************************************************************/
26
27
#include "common/base.h"
28
29
/****************************************************************************
30
 * global symbols
31
 ****************************************************************************/
32
const int x264_chroma_format = X264_CHROMA_FORMAT;
33
34
x264_t *x264_8_encoder_open( x264_param_t *, void * );
35
void x264_8_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
36
int  x264_8_encoder_reconfig( x264_t *, x264_param_t * );
37
void x264_8_encoder_parameters( x264_t *, x264_param_t * );
38
int  x264_8_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
39
int  x264_8_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
40
void x264_8_encoder_close( x264_t * );
41
int  x264_8_encoder_delayed_frames( x264_t * );
42
int  x264_8_encoder_maximum_delayed_frames( x264_t * );
43
void x264_8_encoder_intra_refresh( x264_t * );
44
int  x264_8_encoder_invalidate_reference( x264_t *, int64_t pts );
45
46
x264_t *x264_10_encoder_open( x264_param_t *, void * );
47
void x264_10_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
48
int  x264_10_encoder_reconfig( x264_t *, x264_param_t * );
49
void x264_10_encoder_parameters( x264_t *, x264_param_t * );
50
int  x264_10_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
51
int  x264_10_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
52
void x264_10_encoder_close( x264_t * );
53
int  x264_10_encoder_delayed_frames( x264_t * );
54
int  x264_10_encoder_maximum_delayed_frames( x264_t * );
55
void x264_10_encoder_intra_refresh( x264_t * );
56
int  x264_10_encoder_invalidate_reference( x264_t *, int64_t pts );
57
58
typedef struct x264_api_t
59
{
60
    /* Internal reference to x264_t data */
61
    x264_t *x264;
62
63
    /* API entry points */
64
    void (*nal_encode)( x264_t *h, uint8_t *dst, x264_nal_t *nal );
65
    int  (*encoder_reconfig)( x264_t *, x264_param_t * );
66
    void (*encoder_parameters)( x264_t *, x264_param_t * );
67
    int  (*encoder_headers)( x264_t *, x264_nal_t **pp_nal, int *pi_nal );
68
    int  (*encoder_encode)( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );
69
    void (*encoder_close)( x264_t * );
70
    int  (*encoder_delayed_frames)( x264_t * );
71
    int  (*encoder_maximum_delayed_frames)( x264_t * );
72
    void (*encoder_intra_refresh)( x264_t * );
73
    int  (*encoder_invalidate_reference)( x264_t *, int64_t pts );
74
} x264_api_t;
75
76
REALIGN_STACK x264_t *x264_encoder_open( x264_param_t *param )
77
0
{
78
0
    x264_api_t *api = calloc( 1, sizeof( x264_api_t ) );
79
0
    if( !api )
80
0
        return NULL;
81
82
0
#if HAVE_BITDEPTH8
83
0
    if( param->i_bitdepth == 8 )
84
0
    {
85
0
        api->nal_encode = x264_8_nal_encode;
86
0
        api->encoder_reconfig = x264_8_encoder_reconfig;
87
0
        api->encoder_parameters = x264_8_encoder_parameters;
88
0
        api->encoder_headers = x264_8_encoder_headers;
89
0
        api->encoder_encode = x264_8_encoder_encode;
90
0
        api->encoder_close = x264_8_encoder_close;
91
0
        api->encoder_delayed_frames = x264_8_encoder_delayed_frames;
92
0
        api->encoder_maximum_delayed_frames = x264_8_encoder_maximum_delayed_frames;
93
0
        api->encoder_intra_refresh = x264_8_encoder_intra_refresh;
94
0
        api->encoder_invalidate_reference = x264_8_encoder_invalidate_reference;
95
96
0
        api->x264 = x264_8_encoder_open( param, api );
97
0
    }
98
0
    else
99
0
#endif
100
0
#if HAVE_BITDEPTH10
101
0
    if( param->i_bitdepth == 10 )
102
0
    {
103
0
        api->nal_encode = x264_10_nal_encode;
104
0
        api->encoder_reconfig = x264_10_encoder_reconfig;
105
0
        api->encoder_parameters = x264_10_encoder_parameters;
106
0
        api->encoder_headers = x264_10_encoder_headers;
107
0
        api->encoder_encode = x264_10_encoder_encode;
108
0
        api->encoder_close = x264_10_encoder_close;
109
0
        api->encoder_delayed_frames = x264_10_encoder_delayed_frames;
110
0
        api->encoder_maximum_delayed_frames = x264_10_encoder_maximum_delayed_frames;
111
0
        api->encoder_intra_refresh = x264_10_encoder_intra_refresh;
112
0
        api->encoder_invalidate_reference = x264_10_encoder_invalidate_reference;
113
114
0
        api->x264 = x264_10_encoder_open( param, api );
115
0
    }
116
0
    else
117
0
#endif
118
0
        x264_log_internal( X264_LOG_ERROR, "not compiled with %d bit depth support\n", param->i_bitdepth );
119
120
0
    if( !api->x264 )
121
0
    {
122
0
        free( api );
123
0
        return NULL;
124
0
    }
125
126
    /* x264_t is opaque */
127
0
    return (x264_t *)api;
128
0
}
129
130
REALIGN_STACK void x264_encoder_close( x264_t *h )
131
0
{
132
0
    x264_api_t *api = (x264_api_t *)h;
133
134
0
    api->encoder_close( api->x264 );
135
0
    free( api );
136
0
}
137
138
REALIGN_STACK void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal )
139
0
{
140
0
    x264_api_t *api = (x264_api_t *)h;
141
142
0
    api->nal_encode( api->x264, dst, nal );
143
0
}
144
145
REALIGN_STACK int x264_encoder_reconfig( x264_t *h, x264_param_t *param)
146
0
{
147
0
    x264_api_t *api = (x264_api_t *)h;
148
149
0
    return api->encoder_reconfig( api->x264, param );
150
0
}
151
152
REALIGN_STACK void x264_encoder_parameters( x264_t *h, x264_param_t *param )
153
0
{
154
0
    x264_api_t *api = (x264_api_t *)h;
155
156
0
    api->encoder_parameters( api->x264, param );
157
0
}
158
159
REALIGN_STACK int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
160
0
{
161
0
    x264_api_t *api = (x264_api_t *)h;
162
163
0
    return api->encoder_headers( api->x264, pp_nal, pi_nal );
164
0
}
165
166
REALIGN_STACK int x264_encoder_encode( x264_t *h, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out )
167
0
{
168
0
    x264_api_t *api = (x264_api_t *)h;
169
170
0
    return api->encoder_encode( api->x264, pp_nal, pi_nal, pic_in, pic_out );
171
0
}
172
173
REALIGN_STACK int x264_encoder_delayed_frames( x264_t *h )
174
0
{
175
0
    x264_api_t *api = (x264_api_t *)h;
176
177
0
    return api->encoder_delayed_frames( api->x264 );
178
0
}
179
180
REALIGN_STACK int x264_encoder_maximum_delayed_frames( x264_t *h )
181
0
{
182
0
    x264_api_t *api = (x264_api_t *)h;
183
184
0
    return api->encoder_maximum_delayed_frames( api->x264 );
185
0
}
186
187
REALIGN_STACK void x264_encoder_intra_refresh( x264_t *h )
188
0
{
189
0
    x264_api_t *api = (x264_api_t *)h;
190
191
0
    api->encoder_intra_refresh( api->x264 );
192
0
}
193
194
REALIGN_STACK int x264_encoder_invalidate_reference( x264_t *h, int64_t pts )
195
0
{
196
0
    x264_api_t *api = (x264_api_t *)h;
197
198
0
    return api->encoder_invalidate_reference( api->x264, pts );
199
0
}