Skip to content

Commit 51e9124

Browse files
committed
swscale/graph: expose ff_sws_graph_add_pass
So we can move pass-adding business logic outside of graph.c.
1 parent f297ebf commit 51e9124

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

libswscale/graph.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ static int pass_alloc_output(SwsPass *pass)
4444
pass->num_slices * pass->slice_h, pass->format, 64);
4545
}
4646

47-
/* slice_align should be a power of two, or 0 to disable slice threading */
48-
static SwsPass *pass_add(SwsGraph *graph, void *priv, enum AVPixelFormat fmt,
49-
int w, int h, SwsPass *input, int slice_align,
50-
sws_filter_run_t run)
47+
SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt,
48+
int width, int height, SwsPass *input,
49+
int align, void *priv, sws_filter_run_t run)
5150
{
5251
int ret;
5352
SwsPass *pass = av_mallocz(sizeof(*pass));
@@ -58,8 +57,8 @@ static SwsPass *pass_add(SwsGraph *graph, void *priv, enum AVPixelFormat fmt,
5857
pass->run = run;
5958
pass->priv = priv;
6059
pass->format = fmt;
61-
pass->width = w;
62-
pass->height = h;
60+
pass->width = width;
61+
pass->height = height;
6362
pass->input = input;
6463
pass->output.fmt = AV_PIX_FMT_NONE;
6564

@@ -69,12 +68,12 @@ static SwsPass *pass_add(SwsGraph *graph, void *priv, enum AVPixelFormat fmt,
6968
return NULL;
7069
}
7170

72-
if (!slice_align) {
71+
if (!align) {
7372
pass->slice_h = pass->height;
7473
pass->num_slices = 1;
7574
} else {
7675
pass->slice_h = (pass->height + graph->num_threads - 1) / graph->num_threads;
77-
pass->slice_h = FFALIGN(pass->slice_h, slice_align);
76+
pass->slice_h = FFALIGN(pass->slice_h, align);
7877
pass->num_slices = (pass->height + pass->slice_h - 1) / pass->slice_h;
7978
}
8079

@@ -84,12 +83,11 @@ static SwsPass *pass_add(SwsGraph *graph, void *priv, enum AVPixelFormat fmt,
8483
return pass;
8584
}
8685

87-
/* Wrapper around pass_add that chains a pass "in-place" */
88-
static int pass_append(SwsGraph *graph, void *priv, enum AVPixelFormat fmt,
89-
int w, int h, SwsPass **pass, int slice_align,
90-
sws_filter_run_t run)
86+
/* Wrapper around ff_sws_graph_add_pass() that chains a pass "in-place" */
87+
static int pass_append(SwsGraph *graph, enum AVPixelFormat fmt, int w, int h,
88+
SwsPass **pass, int align, void *priv, sws_filter_run_t run)
9189
{
92-
SwsPass *new = pass_add(graph, priv, fmt, w, h, *pass, slice_align, run);
90+
SwsPass *new = ff_sws_graph_add_pass(graph, fmt, w, h, *pass, align, priv, run);
9391
if (!new)
9492
return AVERROR(ENOMEM);
9593
*pass = new;
@@ -325,19 +323,19 @@ static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws,
325323
align = 0; /* disable slice threading */
326324

327325
if (c->src0Alpha && !c->dst0Alpha && isALPHA(sws->dst_format)) {
328-
ret = pass_append(graph, c, AV_PIX_FMT_RGBA, src_w, src_h, &input, 1, run_rgb0);
326+
ret = pass_append(graph, AV_PIX_FMT_RGBA, src_w, src_h, &input, 1, c, run_rgb0);
329327
if (ret < 0)
330328
return ret;
331329
}
332330

333331
if (c->srcXYZ && !(c->dstXYZ && unscaled)) {
334-
ret = pass_append(graph, c, AV_PIX_FMT_RGB48, src_w, src_h, &input, 1, run_xyz2rgb);
332+
ret = pass_append(graph, AV_PIX_FMT_RGB48, src_w, src_h, &input, 1, c, run_xyz2rgb);
335333
if (ret < 0)
336334
return ret;
337335
}
338336

339-
pass = pass_add(graph, sws, sws->dst_format, dst_w, dst_h, input, align,
340-
c->convert_unscaled ? run_legacy_unscaled : run_legacy_swscale);
337+
pass = ff_sws_graph_add_pass(graph, sws->dst_format, dst_w, dst_h, input, align, sws,
338+
c->convert_unscaled ? run_legacy_unscaled : run_legacy_swscale);
341339
if (!pass)
342340
return AVERROR(ENOMEM);
343341
pass->setup = setup_legacy_swscale;
@@ -387,7 +385,7 @@ static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws,
387385
}
388386

389387
if (c->dstXYZ && !(c->srcXYZ && unscaled)) {
390-
ret = pass_append(graph, c, AV_PIX_FMT_RGB48, dst_w, dst_h, &pass, 1, run_rgb2xyz);
388+
ret = pass_append(graph, AV_PIX_FMT_RGB48, dst_w, dst_h, &pass, 1, c, run_rgb2xyz);
391389
if (ret < 0)
392390
return ret;
393391
}
@@ -548,8 +546,8 @@ static int adapt_colors(SwsGraph *graph, SwsFormat src, SwsFormat dst,
548546
return ret;
549547
}
550548

551-
pass = pass_add(graph, lut, fmt_out, src.width, src.height,
552-
input, 1, run_lut3d);
549+
pass = ff_sws_graph_add_pass(graph, fmt_out, src.width, src.height,
550+
input, 1, lut, run_lut3d);
553551
if (!pass) {
554552
ff_sws_lut3d_free(&lut);
555553
return AVERROR(ENOMEM);
@@ -589,7 +587,8 @@ static int init_passes(SwsGraph *graph)
589587
graph->noop = 1;
590588

591589
/* Add threaded memcpy pass */
592-
pass = pass_add(graph, NULL, dst.format, dst.width, dst.height, pass, 1, run_copy);
590+
pass = ff_sws_graph_add_pass(graph, dst.format, dst.width, dst.height,
591+
pass, 1, NULL, run_copy);
593592
if (!pass)
594593
return AVERROR(ENOMEM);
595594
}

libswscale/graph.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ typedef struct SwsGraph {
128128
int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src,
129129
int field, SwsGraph **out_graph);
130130

131+
132+
/**
133+
* Allocate and add a new pass to the filter graph.
134+
*
135+
* @param graph Filter graph to add the pass to.
136+
* @param fmt Pixel format of the output image.
137+
* @param w Width of the output image.
138+
* @param h Height of the output image.
139+
* @param input Previous pass to read from, or NULL for the input image.
140+
* @param align Minimum slice alignment for this pass, or 0 for no threading.
141+
* @param priv Private state for the filter run function.
142+
* @param run Filter function to run.
143+
* @return The newly created pass, or NULL on error.
144+
*/
145+
SwsPass *ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt,
146+
int width, int height, SwsPass *input,
147+
int align, void *priv, sws_filter_run_t run);
148+
131149
/**
132150
* Uninitialize any state associate with this filter graph and free it.
133151
*/

0 commit comments

Comments
 (0)