History

avfilter/vsrc_testsrc: switch to YUV colorspace negotiation API

Instead of overriding the frame properties in fill_picture(), advertise the supported YUV colorspace and range at format negotiation time. (The correct metadata will now be set automatically by ff_get_video_buffer)

Niklas Haas committed 2 years ago

Commit aa1a1941 parent ce812371 file · +31 −16Browse files

Unified · Split

libavfilter/vsrc_testsrc.c+31−16
@@ -1418,6 +1418,24 @@ static const enum AVPixelFormat smptebars_pix_fmts[] = { · 1417 unmodified lines
14181418 AV_PIX_FMT_NONE,
14191419 };
14201420
1421+static int smptebars_query_formats(AVFilterContext *ctx)
1422+{
1423+ enum AVColorSpace csp;
1424+ int ret;
1425+
1426+ if (!strcmp(ctx->name, "smptehdbars")) {
1427+ csp = AVCOL_SPC_BT709;
1428+ } else {
1429+ csp = AVCOL_SPC_BT470BG;
1430+ }
1431+
1432+ if ((ret = ff_set_common_color_spaces(ctx, ff_make_formats_list_singleton(csp))))
1433+ return ret;
1434+ if ((ret = ff_set_common_color_ranges(ctx, ff_make_formats_list_singleton(AVCOL_RANGE_MPEG))))
1435+ return ret;
1436+ return ff_set_common_formats_from_list(ctx, smptebars_pix_fmts);
1437+}
1438+
14211439 AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options);
14221440
14231441 #if CONFIG_PAL75BARS_FILTER
@@ -1428,9 +1446,6 @@ static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 4 unmodified lines
14281446 int r_w, i, x = 0;
14291447 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
14301448
1431− picref->color_range = AVCOL_RANGE_MPEG;
1432− picref->colorspace = AVCOL_SPC_BT470BG;
1433−
14341449 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
14351450
14361451 draw_bar(test, white, x, 0, r_w, test->h, picref);
@@ -1461,7 +1476,7 @@ const AVFilter ff_vsrc_pal75bars = { · 24 unmodified lines
14611476 .activate = activate,
14621477 .inputs = NULL,
14631478 FILTER_OUTPUTS(outputs),
1464− FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),
1479+ FILTER_QUERY_FUNC(smptebars_query_formats),
14651480 };
14661481
14671482 #endif /* CONFIG_PAL75BARS_FILTER */
@@ -1474,9 +1489,6 @@ static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 6 unmodified lines
14741489 int r_w, i, x = 0;
14751490 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
14761491
1477− picref->color_range = AVCOL_RANGE_MPEG;
1478− picref->colorspace = AVCOL_SPC_BT470BG;
1479−
14801492 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
14811493
14821494 for (i = 0; i < 7; i++) {
@@ -1505,7 +1517,7 @@ const AVFilter ff_vsrc_pal100bars = { · 22 unmodified lines
15051517 .activate = activate,
15061518 .inputs = NULL,
15071519 FILTER_OUTPUTS(outputs),
1508− FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),
1520+ FILTER_QUERY_FUNC(smptebars_query_formats),
15091521 };
15101522
15111523 #endif /* CONFIG_PAL100BARS_FILTER */
@@ -1520,8 +1532,6 @@ static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 8 unmodified lines
15201532 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
15211533 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
15221534
1523− picref->colorspace = AVCOL_SPC_BT470BG;
1524−
15251535 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
15261536 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
15271537 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
@@ -1572,7 +1582,7 @@ const AVFilter ff_vsrc_smptebars = { · 44 unmodified lines
15721582 .activate = activate,
15731583 .inputs = NULL,
15741584 FILTER_OUTPUTS(outputs),
1575− FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),
1585+ FILTER_QUERY_FUNC(smptebars_query_formats),
15761586 };
15771587
15781588 #endif /* CONFIG_SMPTEBARS_FILTER */
@@ -1585,8 +1595,6 @@ static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 6 unmodified lines
15851595 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
15861596 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
15871597
1588− picref->colorspace = AVCOL_SPC_BT709;
1589−
15901598 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
15911599 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
15921600 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
@@ -1675,7 +1683,7 @@ const AVFilter ff_vsrc_smptehdbars = { · 82 unmodified lines
16751683 .activate = activate,
16761684 .inputs = NULL,
16771685 FILTER_OUTPUTS(outputs),
1678− FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),
1686+ FILTER_QUERY_FUNC(smptebars_query_formats),
16791687 };
16801688
16811689 #endif /* CONFIG_SMPTEHDBARS_FILTER */
@@ -2138,7 +2146,6 @@ ZONEPLATE_SLICE(16, uint16_t) · 456 unmodified lines
21382146 static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
21392147 {
21402148 TestSourceContext *test = ctx->priv;
2141− frame->color_range = AVCOL_RANGE_JPEG;
21422149 ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL,
21432150 FFMIN(frame->height, ff_filter_get_nb_threads(ctx)));
21442151 }
@@ -2194,6 +2201,14 @@ static const enum AVPixelFormat zoneplate_pix_fmts[] = { · 49 unmodified lines
21942201 AV_PIX_FMT_NONE,
21952202 };
21962203
2204+static int zoneplate_query_formats(AVFilterContext *ctx)
2205+{
2206+ int ret;
2207+ if ((ret = ff_set_common_color_ranges(ctx, ff_make_formats_list_singleton(AVCOL_RANGE_JPEG))))
2208+ return ret;
2209+ return ff_set_common_formats_from_list(ctx, zoneplate_pix_fmts);
2210+}
2211+
21972212 static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {
21982213 {
21992214 .name = "default",
@@ -2212,7 +2227,7 @@ const AVFilter ff_vsrc_zoneplate = { · 12 unmodified lines
22122227 .activate = activate,
22132228 .inputs = NULL,
22142229 FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs),
2215− FILTER_PIXFMTS_ARRAY(zoneplate_pix_fmts),
2230+ FILTER_QUERY_FUNC(zoneplate_query_formats),
22162231 .flags = AVFILTER_FLAG_SLICE_THREADS,
22172232 .process_command = ff_filter_process_command,
22182233 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t