FFmpeg
Loading...
Searching...
No Matches
ops_dispatch.h
Go to the documentation of this file.
1/**
2 * Copyright (C) 2026 Niklas Haas
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef SWSCALE_OPS_DISPATCH_H
22#define SWSCALE_OPS_DISPATCH_H
23
24#include <assert.h>
25
26#include "libavutil/frame.h"
27#include "graph.h"
28#include "uops.h"
29
30/**
31 * Global execution context for all compiled functions.
32 *
33 * Note: This struct is hard-coded in assembly, so do not change the layout
34 * without updating the corresponding assembly definitions.
35 */
36typedef struct SwsOpExec {
37 /* The data pointers point to the first pixel to process */
38 const uint8_t *in[4];
39 uint8_t *out[4];
40
41 /* Separation between lines in bytes */
42 ptrdiff_t in_stride[4];
43 ptrdiff_t out_stride[4];
44
45 /**
46 * Pointer bump, difference between stride and processed line size.
47 *
48 * Assumes that each read kernel increments pointers by the processed
49 * block size, except when using horizontal filtering, in which case
50 * this is always equal to the input stride.
51 */
52 ptrdiff_t in_bump[4];
53 ptrdiff_t out_bump[4];
54
55 /* Extra metadata, may or may not be useful */
56 int32_t width, height; /* Overall output image dimensions */
57 int32_t slice_y, slice_h; /* Start and height of current slice */
58 int32_t block_size_in[4]; /* Size of a block of pixels in bytes */
60
61 /* Subsampling factors for each plane */
62 uint8_t in_sub_y[4], out_sub_y[4];
63 uint8_t in_sub_x[4], out_sub_x[4];
64
65 /**
66 * Line bump; determines how many additional lines to advance (after
67 * incrementing normally to the next line), for each filtered output line.
68 *
69 * Indexed by the line's true y coordinate. If NULL, then the bumps are
70 * effectively all zero. Note that these bumps still need to be
71 * multiplied by the corresponding line stride.
72 */
74
75 /**
76 * Pixel offset map; for horizontal scaling, in bytes. Indexed by the x
77 * coordinate of the output pixel. This is always aligned up to a multiple
78 * of the block size, so implementations may safely over-read up to the
79 * next block boundary.
80 */
82} SwsOpExec;
83
84static_assert(sizeof(SwsOpExec) == 24 * sizeof(void *) +
85 12 * sizeof(int32_t) +
86 16 * sizeof(uint8_t) +
87 2 * sizeof(void *),
88 "SwsOpExec layout mismatch");
89
90/**
91 * Process a given range of pixel blocks.
92 *
93 * Note: `bx_start` and `bx_end` are in units of `SwsCompiledOp.block_size`.
94 */
95typedef void (*SwsOpFunc)(const SwsOpExec *exec, const void *priv,
96 int bx_start, int y_start, int bx_end, int y_end);
97
98#define SWS_DECL_FUNC(NAME) \
99 void NAME(const SwsOpExec *, const void *, int, int, int, int)
100
101typedef struct SwsCompiledOp {
102 /* Function to execute */
103 union {
106 };
107
108 /**
109 * If `opaque` is true, then `func_opaque`, `priv` and `free` are directly
110 * forwarded as `SwsPass.run`, `SwsPass.priv` and `SwsPass.free`
111 * respectively.
112 */
113 bool opaque;
114
115 /* Set by ff_sws_ops_compile(), informative */
116 const struct SwsOpBackend *backend;
117
118 /* Execution parameters for all functions */
119 int slice_align; /* slice height alignment */
120 int cpu_flags; /* active set of CPU flags (informative) */
121
122 /* Execution parameters for non-opaque functions only */
123 int block_size; /* number of pixels processed per iteration */
124 int over_read[4]; /* implementation over-reads input by this many bytes */
125 int over_write[4]; /* implementation over-writes output by this many bytes */
126
127 /* Arbitrary private data */
128 void *priv;
129 void (*free)(void *priv);
131
133
134typedef struct SwsOpBackend {
135 const char *name; /* Descriptive name for this backend */
136 SwsBackend flags; /* Set of SWS_BACKEND_* */
137
138 /**
139 * Compile an operation list to an implementation chain.
140 *
141 * Returns 0 or a negative error code.
142 */
144
145 /**
146 * Alternative to `compile` that takes a list of micro-ops directly.
147 */
149
150 /**
151 * If NONE, backend only supports software frames.
152 * Otherwise, frame hardware format must match hw_format for the backend
153 * to be used.
154 */
157
158/* List of all backends, terminated by NULL */
159extern const SwsOpBackend *const ff_sws_op_backends[];
160
161/**
162 * Attempt to compile a list of operations using a specific backend, or
163 * the best available backend if `backend` is NULL.
164 *
165 * Returns 0 on success, or a negative error code on failure.
166 */
167int ff_sws_ops_compile(SwsContext *ctx, const SwsOpBackend *backend,
168 const SwsOpList *ops, SwsCompiledOp *out);
169
171 /* Automatically optimize the operations when compiling */
173
174 /* Discard the compiled op lists instead of generating passes */
176
177 /* Split off copied/cleared planes into separate subpasses */
179};
180
181/**
182 * Resolves an operation list to a graph pass. The last op must be a write.
183 *
184 * @param backend Force the use of a specific backend (Optional)
185 * @param ops Operations to compile. Ownership passes to this function, and
186 * will be set to NULL, even on failure.
187 * @param flags Set of SwsOpCompileFlags
188 * @param input The input for the compiled passes. (Optional)
189 * @param output The resulting final output pass will be stored here.
190 * Optional if using SWS_OP_FLAG_DRY_RUN.
191 */
192int ff_sws_compile_pass(SwsGraph *graph, const SwsOpBackend *backend,
193 SwsOpList **ops, int flags, SwsPass *input,
194 SwsPass **output);
195
196#endif /* SWSCALE_OPS_DISPATCH_H */
int32_t
#define flags(name, subs,...)
Definition cbs_h264.c:74
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition eamad.c:79
reference-counted frame API
void(* SwsPassFunc)(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
Definition graph.h:46
SwsBackend
Definition swscale.h:110
const SwsOpBackend *const ff_sws_op_backends[]
Definition ops.c:42
void(* SwsOpFunc)(const SwsOpExec *exec, const void *priv, int bx_start, int y_start, int bx_end, int y_end)
Process a given range of pixel blocks.
void ff_sws_compiled_op_unref(SwsCompiledOp *comp)
int ff_sws_ops_compile(SwsContext *ctx, const SwsOpBackend *backend, const SwsOpList *ops, SwsCompiledOp *out)
Attempt to compile a list of operations using a specific backend, or the best available backend if ba...
SwsOpCompileFlags
@ SWS_OP_FLAG_DRY_RUN
@ SWS_OP_FLAG_OPTIMIZE
@ SWS_OP_FLAG_SPLIT_MEMCPY
int ff_sws_compile_pass(SwsGraph *graph, const SwsOpBackend *backend, SwsOpList **ops, int flags, SwsPass *input, SwsPass **output)
Resolves an operation list to a graph pass.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
SwsOpFunc func
bool opaque
If opaque is true, then func_opaque, priv and free are directly forwarded as SwsPass....
SwsPassFunc func_opaque
void(* free)(void *priv)
const struct SwsOpBackend * backend
Main external API structure.
Definition swscale.h:227
Filter graph, which represents a 'baked' pixel format conversion.
Definition graph.h:132
const char * name
int(* compile_uops)(SwsContext *ctx, const SwsUOpList *uops, SwsCompiledOp *out)
Alternative to compile that takes a list of micro-ops directly.
int(* compile)(SwsContext *ctx, const SwsOpList *ops, SwsCompiledOp *out)
Compile an operation list to an implementation chain.
SwsBackend flags
enum AVPixelFormat hw_format
If NONE, backend only supports software frames.
Copyright (C) 2026 Niklas Haas.
int32_t block_size_out[4]
ptrdiff_t out_stride[4]
uint8_t * out[4]
int32_t * in_offset_x
Pixel offset map; for horizontal scaling, in bytes.
const uint8_t * in[4]
int32_t height
int32_t slice_h
ptrdiff_t in_stride[4]
int32_t width
int32_t block_size_in[4]
int32_t slice_y
uint8_t out_sub_y[4]
uint8_t in_sub_x[4]
ptrdiff_t in_bump[4]
Pointer bump, difference between stride and processed line size.
ptrdiff_t out_bump[4]
uint8_t out_sub_x[4]
int32_t * in_bump_y
Line bump; determines how many additional lines to advance (after incrementing normally to the next l...
uint8_t in_sub_y[4]
Helper struct for representing a list of operations.
Definition ops.h:293
Represents a single filter pass in the scaling graph.
Definition graph.h:85
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49