x264_dev/
sys.rs

1#![allow(non_upper_case_globals)]
2use std::ffi::{CString, c_void};
3use std::os::raw::{c_char, c_int};
4use libc::{size_t, c_float};
5
6// use crate::raw::{
7//     x264_t,
8//     x264_nal_t,
9//     x264_zone_t,
10//     x264_param_t,
11//     x264_level_t,
12//     x264_hrd_t,
13//     x264_sei_payload_t,
14//     x264_sei_t,
15//     x264_image_t,
16//     x264_image_properties_t,
17//     x264_picture_t,
18//     x264_param_t__bindgen_ty_1,
19//     x264_param_t__bindgen_ty_2,
20//     x264_param_t__bindgen_ty_3,
21//     x264_param_t__bindgen_ty_4,
22
23//     x264_direct_pred_names,
24//     x264_motion_est_names,
25//     x264_b_pyramid_names,
26//     x264_overscan_names,
27//     x264_vidformat_names,
28//     x264_fullrange_names,
29//     x264_colorprim_names,
30//     x264_transfer_names,
31//     x264_colmatrix_names,
32//     x264_nal_hrd_names,
33//     x264_avcintra_flavor_names,
34//     x264_levels,
35//     x264_preset_names,
36//     x264_tune_names,
37//     x264_profile_names,
38//     x264_chroma_format,
39// };
40
41
42///////////////////////////////////////////////////////////////////////////////
43// X264 STRUCTS
44///////////////////////////////////////////////////////////////////////////////
45
46/// opaque handler for encoder
47pub type X264T = crate::raw::x264_t;
48
49/// The data within the payload is already NAL-encapsulated; the ref_idc and type
50/// are merely in the struct for easy access by the calling application.
51/// 
52/// All data returned in an x264_nal_t, including the data in p_payload, is no longer
53/// valid after the next call to x264_encoder_encode.  Thus it must be used or copied
54/// before calling x264_encoder_encode or x264_encoder_headers again.
55pub type X264NalT = crate::raw::x264_nal_t;
56
57/// Zones: override ratecontrol or other options for specific sections of the video.
58/// 
59/// See x264_encoder_reconfig() for which options can be changed.
60/// If zones overlap, whichever comes later in the list takes precedence.
61pub type X264ZoneT = crate::raw::x264_zone_t;
62
63pub type X264ParamT = crate::raw::x264_param_t;
64
65pub type X264LevelT = crate::raw::x264_level_t;
66
67pub type X264HrdT = crate::raw::x264_hrd_t;
68
69/// Arbitrary user SEI:
70/// 
71/// Payload size is in bytes and the payload pointer must be valid.
72/// 
73/// Payload types and syntax can be found in Annex D of the H.264 Specification.
74/// SEI payload alignment bits as described in Annex D must be included at the
75/// end of the payload if needed.
76/// The payload should not be NAL-encapsulated.
77/// Payloads are written first in order of input, apart from in the case when HRD
78/// is enabled where payloads are written after the Buffering Period SEI.
79pub type X264SeiPayloadT = crate::raw::x264_sei_payload_t;
80
81pub type X264SeiT = crate::raw::x264_sei_t;
82
83pub type X264ImageT = crate::raw::x264_image_t;
84
85pub type X264ImagePropertiesT = crate::raw::x264_image_properties_t;
86
87pub type X264PictureT = crate::raw::x264_picture_t;
88
89
90///////////////////////////////////////////////////////////////////////////////
91// X264 TYPE-DEFS
92///////////////////////////////////////////////////////////////////////////////
93
94///////////////////////////////////////////////////////////////////////////////
95// X264 CONSTANTS
96///////////////////////////////////////////////////////////////////////////////
97
98///////////////////////////////////////////////////////////////////////////////
99// X264 FUNCTIONS
100///////////////////////////////////////////////////////////////////////////////
101
102pub unsafe fn x264_nal_encode(
103    h: *mut X264T,
104    dst: *mut u8,
105    nal: *mut X264NalT,
106) {
107    crate::raw::x264_nal_encode(
108        h,
109        dst,
110        nal,
111    )
112}
113
114
115/// set one parameter by name.
116/// 
117/// returns 0 on success, or returns one of the following errors.
118/// note: BAD_VALUE occurs only if it can't even parse the value,
119/// numerical range is not checked until x264_encoder_open() or
120/// x264_encoder_reconfig().
121/// value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans.
122pub unsafe fn x264_param_parse(
123    arg1: *mut X264ParamT,
124    name: *const ::std::os::raw::c_char,
125    value: *const ::std::os::raw::c_char,
126) -> ::std::os::raw::c_int {
127    crate::raw::x264_param_parse(
128        arg1,
129        name,
130        value,
131    )
132}
133
134/// Multiple tunings can be used if separated by a delimiter in ",./-+",
135/// however multiple psy tunings cannot be used.
136/// 
137/// film, animation, grain, stillimage, psnr, and ssim are psy tunings.
138///
139/// returns 0 on success, negative on failure (e.g. invalid preset/tune name).
140pub unsafe fn x264_param_default_preset(
141    arg1: *mut X264ParamT,
142    preset: *const ::std::os::raw::c_char,
143    tune: *const ::std::os::raw::c_char,
144) -> ::std::os::raw::c_int {
145    crate::raw::x264_param_default_preset(
146        arg1,
147        preset,
148        tune,
149    )
150}
151
152/// x264_param_apply_fastfirstpass:
153/// If first-pass mode is set (rc.b_stat_read == 0, rc.b_stat_write == 1),
154/// modify the encoder settings to disable options generally not useful on
155/// the first pass.
156pub unsafe fn x264_param_apply_fastfirstpass(arg1: *mut X264ParamT) {
157    crate::raw::x264_param_apply_fastfirstpass(arg1)
158}
159
160
161/// Applies the restrictions of the given profile.
162/// 
163/// Currently available profiles are, from most to least restrictive:
164pub unsafe fn x264_param_apply_profile(
165    arg1: *mut X264ParamT,
166    profile: *const ::std::os::raw::c_char,
167) -> ::std::os::raw::c_int {
168    crate::raw::x264_param_apply_profile(
169        arg1,
170        profile,
171    )
172}
173
174/// initialize an x264_picture_t. 
175/// 
176/// Needs to be done if the calling application
177/// allocates its own x264_picture_t as opposed to using x264_picture_alloc.
178pub unsafe fn x264_picture_init(pic: *mut X264PictureT) {
179    crate::raw::x264_picture_init(pic)
180}
181
182/// alloc data for a picture.
183/// 
184/// You must call x264_picture_clean on it.
185/// returns 0 on success, or -1 on malloc failure or invalid colorspace.
186pub unsafe fn x264_picture_alloc(
187    pic: *mut X264PictureT,
188    i_csp: ::std::os::raw::c_int,
189    i_width: ::std::os::raw::c_int,
190    i_height: ::std::os::raw::c_int,
191) -> ::std::os::raw::c_int {
192    crate::raw::x264_picture_alloc(
193        pic,
194        i_csp,
195        i_width,
196        i_height,
197    )
198}
199
200/// free associated resource for a x264_picture_t allocated with
201/// x264_picture_alloc ONLY
202pub unsafe fn x264_picture_clean(pic: *mut X264PictureT) {
203    crate::raw::x264_picture_clean(pic)
204}
205/// various parameters from x264_param_t are copied.
206/// 
207/// this takes effect immediately, on whichever frame is encoded next;
208/// due to delay, this may not be the next frame passed to encoder_encode.
209/// if the change should apply to some particular frame, use x264_picture_t->param instead.
210/// returns 0 on success, negative on parameter validation error.
211/// not all parameters can be changed; see the actual function for a detailed breakdown.
212///
213/// since not all parameters can be changed, moving from preset to preset may not always
214/// fully copy all relevant parameters, but should still work usably in practice. however,
215/// more so than for other presets, many of the speed shortcuts used in ultrafast cannot be
216/// switched out of; using reconfig to switch between ultrafast and other presets is not
217/// recommended without a more fine-grained breakdown of parameters to take this into account.
218pub unsafe fn x264_encoder_reconfig(
219    arg1: *mut X264T,
220    arg2: *mut X264ParamT,
221) -> ::std::os::raw::c_int {
222    crate::raw::x264_encoder_reconfig(
223        arg1,
224        arg2,
225    )
226}
227
228
229/// copies the current internal set of parameters to the pointer provided
230/// by the caller.
231/// 
232/// useful when the calling application needs to know
233/// how x264_encoder_open has changed the parameters, or the current state
234/// of the encoder after multiple x264_encoder_reconfig calls.
235/// note that the data accessible through pointers in the returned param struct
236/// (e.g. filenames) should not be modified by the calling application.
237pub unsafe fn x264_encoder_parameters(
238    arg1: *mut X264T,
239    arg2: *mut X264ParamT
240) {
241    crate::raw::x264_encoder_parameters(
242        arg1,
243        arg2,
244    )
245}
246
247/// return the SPS and PPS that will be used for the whole stream.
248/// 
249/// *pi_nal is the number of NAL units outputted in pp_nal.
250/// returns the number of bytes in the returned NALs.
251/// returns negative on error.
252/// the payloads of all output NALs are guaranteed to be sequential in memory.
253pub unsafe fn x264_encoder_headers(
254    arg1: *mut X264T,
255    pp_nal: *mut *mut X264NalT,
256    pi_nal: *mut ::std::os::raw::c_int,
257) -> ::std::os::raw::c_int {
258    crate::raw::x264_encoder_headers(
259        arg1,
260        pp_nal,
261        pi_nal,
262    )
263}
264
265/// encode one picture.
266/// 
267/// *pi_nal is the number of NAL units outputted in pp_nal.
268/// returns the number of bytes in the returned NALs.
269/// returns negative on error and zero if no NAL units returned.
270/// the payloads of all output NALs are guaranteed to be sequential in memory.
271pub unsafe fn x264_encoder_encode(
272    arg1: *mut X264T,
273    pp_nal: *mut *mut X264NalT,
274    pi_nal: *mut ::std::os::raw::c_int,
275    pic_in: *mut X264PictureT,
276    pic_out: *mut X264PictureT,
277) -> ::std::os::raw::c_int {
278    crate::raw::x264_encoder_encode(
279        arg1,
280        pp_nal,
281        pi_nal,
282        pic_in,
283        pic_out,
284    )
285}
286
287/// close an encoder handler
288pub unsafe fn x264_encoder_close(arg1: *mut X264T) {
289    crate::raw::x264_encoder_close(arg1)
290}
291
292/// return the number of currently delayed (buffered) frames
293/// this should be used at the end of the stream, to know when you have all the encoded frames.
294pub unsafe fn x264_encoder_delayed_frames(arg1: *mut X264T) -> ::std::os::raw::c_int {
295    crate::raw::x264_encoder_delayed_frames(arg1)
296}
297
298/// return the maximum number of delayed (buffered) frames that can occur with the current
299/// parameters.
300pub unsafe fn x264_encoder_maximum_delayed_frames(arg1: *mut X264T) -> ::std::os::raw::c_int {
301    crate::raw::x264_encoder_maximum_delayed_frames(arg1)
302}
303
304/// If an intra refresh is not in progress, begin one with the next P-frame.
305/// 
306/// If an intra refresh is in progress, begin one as soon as the current one finishes.
307/// Requires that b_intra_refresh be set.
308///
309/// Useful for interactive streaming where the client can tell the server that packet loss has
310/// occurred.  In this case, keyint can be set to an extremely high value so that intra refreshes
311/// only occur when calling x264_encoder_intra_refresh.
312///
313/// In multi-pass encoding, if x264_encoder_intra_refresh is called differently in each pass,
314/// behavior is undefined.
315///
316/// Should not be called during an x264_encoder_encode.
317pub unsafe fn x264_encoder_intra_refresh(arg1: *mut X264T) {
318    crate::raw::x264_encoder_intra_refresh(arg1)
319}
320
321/// An interactive error resilience tool, designed for use in a low-latency one-encoder-few-clients
322/// system.
323/// 
324/// When the client has packet loss or otherwise incorrectly decodes a frame, the encoder
325/// can be told with this command to "forget" the frame and all frames that depend on it, referencing
326/// only frames that occurred before the loss.  This will force a keyframe if no frames are left to
327/// reference after the aforementioned "forgetting".
328///
329/// It is strongly recommended to use a large i_dpb_size in this case, which allows the encoder to
330/// keep around extra, older frames to fall back on in case more recent frames are all invalidated.
331/// Unlike increasing i_frame_reference, this does not increase the number of frames used for motion
332/// estimation and thus has no speed impact.  It is also recommended to set a very large keyframe
333/// interval, so that keyframes are not used except as necessary for error recovery.
334///
335/// x264_encoder_invalidate_reference is not currently compatible with the use of B-frames or intra
336/// refresh.
337///
338/// In multi-pass encoding, if x264_encoder_invalidate_reference is called differently in each pass,
339/// behavior is undefined.
340///
341/// Should not be called during an x264_encoder_encode, but multiple calls can be made simultaneously.
342///
343/// Returns 0 on success, negative on failure. */
344pub unsafe fn x264_encoder_invalidate_reference(
345    arg1: *mut X264T,
346    pts: i64,
347) -> ::std::os::raw::c_int {
348    crate::raw::x264_encoder_invalidate_reference(
349        arg1,
350        pts,
351    )
352}
353
354/// create a new encoder handler, all parameters from x264_param_t are copied
355pub unsafe fn x264_encoder_open(arg1: *mut X264ParamT) -> *mut X264T {
356    crate::raw::x264_encoder_open_157(arg1)
357}
358
359
360