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
1418 AV_PIX_FMT_NONE,1418 AV_PIX_FMT_NONE,
1419};1419};
1420 1420
1421static 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
1421AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options);1439AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options);
1422 1440
1423#if CONFIG_PAL75BARS_FILTER1441#if CONFIG_PAL75BARS_FILTER
@@ -1428,9 +1446,6 @@ static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 4 unmodified lines
1428 int r_w, i, x = 0;1446 int r_w, i, x = 0;
1429 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);1447 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1430 1448
1431 picref->color_range = AVCOL_RANGE_MPEG;
1432 picref->colorspace = AVCOL_SPC_BT470BG;
1433
1434 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);1449 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1435 1450
1436 draw_bar(test, white, x, 0, r_w, test->h, picref);1451 draw_bar(test, white, x, 0, r_w, test->h, picref);
@@ -1461,7 +1476,7 @@ const AVFilter ff_vsrc_pal75bars = { · 24 unmodified lines
1461 .activate = activate,1476 .activate = activate,
1462 .inputs = NULL,1477 .inputs = NULL,
1463 FILTER_OUTPUTS(outputs),1478 FILTER_OUTPUTS(outputs),
1464 FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),1479 FILTER_QUERY_FUNC(smptebars_query_formats),
1465};1480};
1466 1481
1467#endif /* CONFIG_PAL75BARS_FILTER */1482#endif /* CONFIG_PAL75BARS_FILTER */
@@ -1474,9 +1489,6 @@ static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 6 unmodified lines
1474 int r_w, i, x = 0;1489 int r_w, i, x = 0;
1475 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);1490 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1476 1491
1477 picref->color_range = AVCOL_RANGE_MPEG;
1478 picref->colorspace = AVCOL_SPC_BT470BG;
1479
1480 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);1492 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1481 1493
1482 for (i = 0; i < 7; i++) {1494 for (i = 0; i < 7; i++) {
@@ -1505,7 +1517,7 @@ const AVFilter ff_vsrc_pal100bars = { · 22 unmodified lines
1505 .activate = activate,1517 .activate = activate,
1506 .inputs = NULL,1518 .inputs = NULL,
1507 FILTER_OUTPUTS(outputs),1519 FILTER_OUTPUTS(outputs),
1508 FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),1520 FILTER_QUERY_FUNC(smptebars_query_formats),
1509};1521};
1510 1522
1511#endif /* CONFIG_PAL100BARS_FILTER */1523#endif /* CONFIG_PAL100BARS_FILTER */
@@ -1520,8 +1532,6 @@ static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 8 unmodified lines
1520 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;1532 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1521 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);1533 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1522 1534
1523 picref->colorspace = AVCOL_SPC_BT470BG;
1524
1525 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);1535 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1526 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);1536 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1527 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);1537 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
1572 .activate = activate,1582 .activate = activate,
1573 .inputs = NULL,1583 .inputs = NULL,
1574 FILTER_OUTPUTS(outputs),1584 FILTER_OUTPUTS(outputs),
1575 FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),1585 FILTER_QUERY_FUNC(smptebars_query_formats),
1576};1586};
1577 1587
1578#endif /* CONFIG_SMPTEBARS_FILTER */1588#endif /* CONFIG_SMPTEBARS_FILTER */
@@ -1585,8 +1595,6 @@ static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref) · 6 unmodified lines
1585 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;1595 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1586 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);1596 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1587 1597
1588 picref->colorspace = AVCOL_SPC_BT709;
1589
1590 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);1598 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1591 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);1599 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1592 draw_bar(test, gray40, x, 0, d_w, r_h, picref);1600 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
@@ -1675,7 +1683,7 @@ const AVFilter ff_vsrc_smptehdbars = { · 82 unmodified lines
1675 .activate = activate,1683 .activate = activate,
1676 .inputs = NULL,1684 .inputs = NULL,
1677 FILTER_OUTPUTS(outputs),1685 FILTER_OUTPUTS(outputs),
1678 FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts),1686 FILTER_QUERY_FUNC(smptebars_query_formats),
1679};1687};
1680 1688
1681#endif /* CONFIG_SMPTEHDBARS_FILTER */1689#endif /* CONFIG_SMPTEHDBARS_FILTER */
@@ -2138,7 +2146,6 @@ ZONEPLATE_SLICE(16, uint16_t) · 456 unmodified lines
2138static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)2146static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
2139{2147{
2140 TestSourceContext *test = ctx->priv;2148 TestSourceContext *test = ctx->priv;
2141 frame->color_range = AVCOL_RANGE_JPEG;
2142 ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL,2149 ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL,
2143 FFMIN(frame->height, ff_filter_get_nb_threads(ctx)));2150 FFMIN(frame->height, ff_filter_get_nb_threads(ctx)));
2144}2151}
@@ -2194,6 +2201,14 @@ static const enum AVPixelFormat zoneplate_pix_fmts[] = { · 49 unmodified lines
2194 AV_PIX_FMT_NONE,2201 AV_PIX_FMT_NONE,
2195};2202};
2196 2203
2204static 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
2197static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {2212static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {
2198 {2213 {
2199 .name = "default",2214 .name = "default",
@@ -2212,7 +2227,7 @@ const AVFilter ff_vsrc_zoneplate = { · 12 unmodified lines
2212 .activate = activate,2227 .activate = activate,
2213 .inputs = NULL,2228 .inputs = NULL,
2214 FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs),2229 FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs),
2215 FILTER_PIXFMTS_ARRAY(zoneplate_pix_fmts),2230 FILTER_QUERY_FUNC(zoneplate_query_formats),
2216 .flags = AVFILTER_FLAG_SLICE_THREADS,2231 .flags = AVFILTER_FLAG_SLICE_THREADS,
2217 .process_command = ff_filter_process_command,2232 .process_command = ff_filter_process_command,
2218};2233};

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