2 * Copyright (C) 2024 Niklas Haas
4 * This file is part of FFmpeg.
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.
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.
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
21#ifndef SWSCALE_GRAPH_H
22#define SWSCALE_GRAPH_H
36 return (plane == 1 || plane == 2) ?
desc->log2_chroma_h : 0;
43 * Output `h` lines of filtered data. `out` and `in` point to the
44 * start of the image buffer for this pass.
50 * Function to run from the main thread before processing any lines.
56 * Represents an output buffer for a filter pass. During filter graph
57 * construction, these merely hold the metadata. Allocation of the underlying
58 * storage is deferred until after all filter passes are settled.
66 /* Optional allocation hints for optimal performance */
71 * Map of planes which are directly copied from the pass input. These
72 * may be promoted from a memcpy to a refcopy.
74 * Each entry maps the output index to the corresponding input plane
75 * index, or -1 for no copythrough.
81 * Represents a single filter pass in the scaling graph. Each filter will
82 * read from some previous pass's output, and write to a buffer associated
83 * with the pass (or into the final output image).
89 * Filter main execution function. Called from multiple threads, with
90 * the granularity dictated by `slice_h`. Individual slices sent to `run`
91 * are always equal to (or smaller than, for the last slice) `slice_h`.
96 int lines;
/* pass dispatch size */
101 * Filter input. This pass's output will be resolved to form this pass's.
102 * input. If NULL, the original input image is used.
107 * Filter output buffer. This struct is always allocated.
112 * Called once from the main thread before running the filter. Optional.
113 * Returns 0 or a negative error code.
118 * Optional private state and associated free() function.
125 * Align `width` to the optimal size for `pass`.
130 * Filter graph, which represents a 'baked' pixel format conversion.
136 bool incomplete;
/* set during init() if formats had to be inferred */
137 bool noop;
/* set during init() if the graph is a no-op */
143 * Map of planes which directly copied from the input. These may be
144 * promoted from a memcpy to a refcopy. This requires special handling
147 * Each entry maps the output index to the corresponding input plane
148 * index, or -1 for no copythrough.
152 /** Sorted sequence of filter passes to apply */
157 * Cached copy of the public options that were used to construct this
158 * SwsGraph. Used only to detect when the graph needs to be reinitialized.
163 * Currently active format and processing parameters.
168 * 3DLUT state used for gamut/tone mapping. (Optional)
173 * Temporary execution state inside ff_sws_graph_run(); used to pass
174 * data to worker threads.
184 * Allocate an empty SwsGraph. Returns NULL on failure.
189 * Initialize the filter graph for a given pair of formats. Returns 0 or a
197 * Allocate and add a new pass to the filter graph. Takes over ownership of
198 * `priv`, even on failure.
200 * @param graph Filter graph to add the pass to.
201 * @param fmt Pixel format of the output image.
202 * @param w Width of the output image.
203 * @param h Height of the output image.
204 * @param input Previous pass to read from, or NULL for the input image.
205 * @param lines Override the number of lines processed for this pass. (Optional)
206 * @param align Minimum slice alignment for this pass, or 0 for no threading.
207 * @param run Filter function to run.
208 * @param setup Optional setup function to run from the main thread.
209 * @param priv Private state for the filter run function.
210 * @param free Function to free the private state.
211 * @param out_pass The newly added pass will be written here on success.
212 * @return 0 or a negative error code
216 int lines,
int align,
218 void *priv,
void (*free)(
void *priv),
222 * Link the output buffers to a different pass, rather than allocating
223 * new image buffers. This allows reusing the same buffer for multiple passes,
224 * e.g. in the case of in-place passes or partial passes that modify different
227 * Any existing buffer on `dst` will be ignored/unref'd.
232 * Remove all passes added since the given index.
237 * Uninitialize any state associate with this filter graph and free it.
242 * Update dynamic per-frame HDR metadata without requiring a full reinit.
247 * Wrapper around ff_sws_graph_init() that reuses the existing graph if the
248 * format is compatible. This will also update dynamic per-frame metadata.
250 * Must also be called after changing any of the fields in `ctx`, or else they
251 * will have no effect.
257 * Dispatch the filter graph on a single field of the given frames. Internally
262#endif /* SWSCALE_GRAPH_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static AVFormatContext * ctx
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
refcounted data buffer API
void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color)
Update dynamic per-frame HDR metadata without requiring a full reinit.
int ff_sws_graph_init(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src)
Initialize the filter graph for a given pair of formats.
void(* SwsPassFunc)(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
void ff_sws_pass_link_output(SwsPass *dst, const SwsPass *src)
Link the output buffers to a different pass, rather than allocating new image buffers.
int(* SwsPassSetup)(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
Function to run from the main thread before processing any lines.
void ff_sws_graph_rollback(SwsGraph *graph, int since_idx)
Remove all passes added since the given index.
int ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, int width, int height, SwsPass *input, int lines, int align, SwsPassFunc run, SwsPassSetup setup, void *priv, void(*free)(void *priv), SwsPass **out_pass)
Allocate and add a new pass to the filter graph.
int ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst, const AVFrame *src)
Dispatch the filter graph on a single field of the given frames.
SwsGraph * ff_sws_graph_alloc(void)
Allocate an empty SwsGraph.
int ff_sws_pass_aligned_width(const SwsPass *pass, int width)
Align width to the optimal size for pass.
int ff_sws_graph_reinit(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src)
Wrapper around ff_sws_graph_init() that reuses the existing graph if the format is compatible.
static av_always_inline av_const int ff_fmt_vshift(enum AVPixelFormat fmt, int plane)
void ff_sws_graph_free(SwsGraph **graph)
Uninitialize any state associate with this filter graph and free it.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
struct AVSliceThread AVSliceThread
A reference to a data buffer.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Main external API structure.
Represents a view into a single field of frame data.
Filter graph, which represents a 'baked' pixel format conversion.
SwsPass ** passes
Sorted sequence of filter passes to apply.
SwsFormat src
Currently active format and processing parameters.
SwsContext opts_copy
Cached copy of the public options that were used to construct this SwsGraph.
SwsLut3D * lut3d
3DLUT state used for gamut/tone mapping.
AVBufferRef * hw_frames_ref
int plane_copy[4]
Map of planes which directly copied from the input.
AVSliceThread * slicethread
struct SwsGraph::@252226332054334034101247363262236031041275151254 exec
Temporary execution state inside ff_sws_graph_run(); used to pass data to worker threads.
Append a set of operations for applying a gamut/tone mapping 3D LUT to the pixels.
Represents an output buffer for a filter pass.
int plane_copy[4]
Map of planes which are directly copied from the pass input.
Represents a single filter pass in the scaling graph.
SwsPass * input
Filter input.
enum AVPixelFormat format
SwsPassFunc run
Filter main execution function.
SwsPassBuffer * output
Filter output buffer.
void(* free)(void *priv)
Optional private state and associated free() function.
SwsPassSetup setup
Called once from the main thread before running the filter.