FFmpeg
Loading...
Searching...
No Matches
graph.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/cpu.h"
#include "libavutil/error.h"
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/refstruct.h"
#include "libavutil/slicethread.h"
#include "libswscale/swscale.h"
#include "libswscale/format.h"
#include "cms.h"
#include "lut3d.h"
#include "swscale_internal.h"
#include "graph.h"
#include "ops.h"
#include "ops_dispatch.h"

Go to the source code of this file.

Functions

int ff_sws_pass_aligned_width (const SwsPass *pass, int width)
 Align width to the optimal size for pass.
 
static int frame_alloc_planes_ref (AVFrame *dst, const AVFrame *src, const int plane_copy[4])
 
static int pass_alloc_output (SwsPass *pass)
 
static void free_buffer (AVRefStructOpaque opaque, void *obj)
 
static void pass_free (SwsPass *pass)
 
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_cb)(void *priv), SwsPass **out_pass)
 Allocate and add a new pass to the filter graph.
 
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.
 
static void frame_shift (const SwsFrame *f, const int y, uint8_t *data[4])
 
static void run_copy (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void run_rgb0 (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void run_xyz2rgb (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void run_rgb2xyz (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void free_legacy_swscale (void *priv)
 
static int setup_legacy_swscale (const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
 
static SwsContextslice_ctx (const SwsPass *pass, int y)
 
static void run_legacy_unscaled (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void run_legacy_swscale (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void run_legacy_lut3d (const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
 
static void legacy_chr_pos (SwsGraph *graph, int *chr_pos, int override, int *warned)
 
static int init_legacy_subpass (SwsGraph *graph, SwsContext *sws, SwsPass *input, SwsPass **output)
 
static int add_legacy_3dlut_pass (SwsGraph *graph, const SwsFormat *src, SwsPass *input, SwsPass **output)
 
static int add_legacy_sws_pass (SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
 
static int add_ops_convert_pass (SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
 
static bool prefer_ops_backend (SwsContext *ctx, const SwsFormat *src, const SwsFormat *dst)
 
static int add_convert_pass (SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
 
static int generate_3dlut (SwsGraph *graph, SwsFormat *src, SwsFormat *dst)
 
static int init_passes (SwsGraph *graph)
 
static int sws_graph_worker (void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
 
SwsGraphff_sws_graph_alloc (void)
 Allocate an empty SwsGraph.
 
static void graph_uninit (SwsGraph *graph)
 
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 ff_sws_graph_rollback (SwsGraph *graph, int since_idx)
 Remove all passes added since the given index.
 
void ff_sws_graph_free (SwsGraph **pgraph)
 Uninitialize any state associate with this filter graph and free it.
 
static int opts_equal (const SwsContext *c1, const SwsContext *c2)
 
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.
 
void ff_sws_graph_update_metadata (SwsGraph *graph, const SwsColor *color)
 Update dynamic per-frame HDR metadata without requiring a full reinit.
 
static void get_field (SwsGraph *graph, const SwsFormat *fmt, const AVFrame *avframe, SwsFrame *frame)
 
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.
 

Function Documentation

◆ ff_sws_pass_aligned_width()

int ff_sws_pass_aligned_width ( const SwsPass * pass,
int width )

Align width to the optimal size for pass.

Definition at line 46 of file graph.c.

Referenced by sws_frame_setup().

◆ frame_alloc_planes_ref()

static int frame_alloc_planes_ref ( AVFrame * dst,
const AVFrame * src,
const int plane_copy[4] )
static

Definition at line 58 of file graph.c.

Referenced by pass_alloc_output().

◆ pass_alloc_output()

static int pass_alloc_output ( SwsPass * pass)
static

Definition at line 130 of file graph.c.

Referenced by ff_sws_graph_init().

◆ free_buffer()

static void free_buffer ( AVRefStructOpaque opaque,
void * obj )
static

Definition at line 177 of file graph.c.

◆ pass_free()

static void pass_free ( SwsPass * pass)
static

Definition at line 183 of file graph.c.

Referenced by ff_sws_graph_add_pass(), ff_sws_graph_rollback(), and graph_uninit().

◆ ff_sws_graph_add_pass()

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.

Takes over ownership of priv, even on failure.

Parameters
graphFilter graph to add the pass to.
fmtPixel format of the output image.
wWidth of the output image.
hHeight of the output image.
inputPrevious pass to read from, or NULL for the input image.
linesOverride the number of lines processed for this pass. (Optional)
alignMinimum slice alignment for this pass, or 0 for no threading.
runFilter function to run.
setupOptional setup function to run from the main thread.
privPrivate state for the filter run function.
freeFunction to free the private state.
out_passThe newly added pass will be written here on success.
Returns
0 or a negative error code

Definition at line 191 of file graph.c.

Referenced by add_legacy_3dlut_pass(), compile_single(), init_legacy_subpass(), and init_passes().

◆ ff_sws_pass_link_output()

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.

This allows reusing the same buffer for multiple passes, e.g. in the case of in-place passes or partial passes that modify different planes.

Any existing buffer on dst will be ignored/unref'd.

Definition at line 249 of file graph.c.

Referenced by compile_single().

◆ frame_shift()

static void frame_shift ( const SwsFrame * f,
const int y,
uint8_t * data[4] )
static

Definition at line 272 of file graph.c.

Referenced by run_copy(), run_legacy_lut3d(), run_legacy_swscale(), and run_legacy_unscaled().

◆ run_copy()

static void run_copy ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 282 of file graph.c.

Referenced by init_passes(), and palette_subblock_data().

◆ run_rgb0()

static void run_rgb0 ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 308 of file graph.c.

Referenced by init_legacy_subpass().

◆ run_xyz2rgb()

static void run_xyz2rgb ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 329 of file graph.c.

Referenced by init_legacy_subpass().

◆ run_rgb2xyz()

static void run_rgb2xyz ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 338 of file graph.c.

Referenced by init_legacy_subpass().

◆ free_legacy_swscale()

static void free_legacy_swscale ( void * priv)
static

Definition at line 353 of file graph.c.

Referenced by init_legacy_subpass().

◆ setup_legacy_swscale()

static int setup_legacy_swscale ( const SwsFrame * out,
const SwsFrame * in,
const SwsPass * pass )
static

Definition at line 359 of file graph.c.

Referenced by init_legacy_subpass().

◆ slice_ctx()

static SwsContext * slice_ctx ( const SwsPass * pass,
int y )
inlinestatic

Definition at line 375 of file graph.c.

Referenced by run_legacy_swscale(), and run_legacy_unscaled().

◆ run_legacy_unscaled()

static void run_legacy_unscaled ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 394 of file graph.c.

Referenced by init_legacy_subpass().

◆ run_legacy_swscale()

static void run_legacy_swscale ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 406 of file graph.c.

Referenced by init_legacy_subpass().

◆ run_legacy_lut3d()

static void run_legacy_lut3d ( const SwsFrame * out,
const SwsFrame * in,
int y,
int h,
const SwsPass * pass )
static

Definition at line 418 of file graph.c.

Referenced by add_legacy_3dlut_pass().

◆ legacy_chr_pos()

static void legacy_chr_pos ( SwsGraph * graph,
int * chr_pos,
int override,
int * warned )
static

Definition at line 430 of file graph.c.

Referenced by add_legacy_sws_pass().

◆ init_legacy_subpass()

static int init_legacy_subpass ( SwsGraph * graph,
SwsContext * sws,
SwsPass * input,
SwsPass ** output )
static

For slice threading, we need to create sub contexts, similar to how swscale normally handles it internally. The most important difference is that we handle cascaded contexts before threaded contexts; whereas context_init_threaded() does it the other way around.

Definition at line 446 of file graph.c.

Referenced by add_legacy_sws_pass(), and init_legacy_subpass().

◆ add_legacy_3dlut_pass()

static int add_legacy_3dlut_pass ( SwsGraph * graph,
const SwsFormat * src,
SwsPass * input,
SwsPass ** output )
static

Definition at line 663 of file graph.c.

Referenced by add_legacy_sws_pass().

◆ add_legacy_sws_pass()

static int add_legacy_sws_pass ( SwsGraph * graph,
const SwsFormat * src,
const SwsFormat * dst,
const SwsLut3D * lut3d,
SwsPass * input,
SwsPass ** output )
static

Definition at line 560 of file graph.c.

Referenced by add_convert_pass(), add_legacy_3dlut_pass(), and add_legacy_sws_pass().

◆ add_ops_convert_pass()

static int add_ops_convert_pass ( SwsGraph * graph,
const SwsFormat * src,
const SwsFormat * dst,
const SwsLut3D * lut3d,
SwsPass * input,
SwsPass ** output )
static

Definition at line 694 of file graph.c.

Referenced by add_convert_pass().

◆ prefer_ops_backend()

static bool prefer_ops_backend ( SwsContext * ctx,
const SwsFormat * src,
const SwsFormat * dst )
static

Definition at line 727 of file graph.c.

Referenced by add_convert_pass().

◆ add_convert_pass()

static int add_convert_pass ( SwsGraph * graph,
const SwsFormat * src,
const SwsFormat * dst,
const SwsLut3D * lut3d,
SwsPass * input,
SwsPass ** output )
static

Definition at line 736 of file graph.c.

Referenced by init_passes().

◆ generate_3dlut()

static int generate_3dlut ( SwsGraph * graph,
SwsFormat * src,
SwsFormat * dst )
static

Grayspace does not really have primaries, so just force the use of the equivalent other primary set to avoid a conversion. Technically, this does affect the weights used for the Grayscale conversion, but in practise, that should give the expected results more often than not.

Definition at line 760 of file graph.c.

Referenced by init_passes().

◆ init_passes()

static int init_passes ( SwsGraph * graph)
static

Definition at line 800 of file graph.c.

Referenced by ff_sws_graph_init().

◆ sws_graph_worker()

static int sws_graph_worker ( void * priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads )
static

Definition at line 854 of file graph.c.

Referenced by ff_sws_graph_init().

◆ ff_sws_graph_alloc()

SwsGraph * ff_sws_graph_alloc ( void )

Allocate an empty SwsGraph.

Returns NULL on failure.

Definition at line 866 of file graph.c.

Referenced by main(), main(), sws_frame_setup(), and sws_uops_macros_gen().

◆ graph_uninit()

static void graph_uninit ( SwsGraph * graph)
static

Definition at line 871 of file graph.c.

Referenced by ff_sws_graph_free(), ff_sws_graph_init(), and ff_sws_graph_reinit().

◆ ff_sws_graph_init()

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.

Returns 0 or a negative error.

Definition at line 884 of file graph.c.

Referenced by ff_sws_graph_reinit().

◆ ff_sws_graph_rollback()

void ff_sws_graph_rollback ( SwsGraph * graph,
int since_idx )

Remove all passes added since the given index.

Definition at line 935 of file graph.c.

Referenced by ff_sws_compile_pass().

◆ ff_sws_graph_free()

void ff_sws_graph_free ( SwsGraph ** pgraph)

Uninitialize any state associate with this filter graph and free it.

Definition at line 942 of file graph.c.

Referenced by main(), main(), sws_frame_setup(), sws_freeContext(), and sws_uops_macros_gen().

◆ opts_equal()

static int opts_equal ( const SwsContext * c1,
const SwsContext * c2 )
static

Definition at line 954 of file graph.c.

Referenced by ff_sws_graph_reinit().

◆ ff_sws_graph_reinit()

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.

This will also update dynamic per-frame metadata.

Must also be called after changing any of the fields in ctx, or else they will have no effect.

Definition at line 973 of file graph.c.

Referenced by sws_frame_setup().

◆ ff_sws_graph_update_metadata()

void ff_sws_graph_update_metadata ( SwsGraph * graph,
const SwsColor * color )

Update dynamic per-frame HDR metadata without requiring a full reinit.

Definition at line 987 of file graph.c.

Referenced by ff_sws_graph_reinit().

◆ get_field()

static void get_field ( SwsGraph * graph,
const SwsFormat * fmt,
const AVFrame * avframe,
SwsFrame * frame )
static

Definition at line 998 of file graph.c.

Referenced by ff_sws_graph_run().

◆ ff_sws_graph_run()

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.

Internally threaded.

Definition at line 1026 of file graph.c.

Referenced by sws_scale_frame().