History

avfilter/vsrc_ddagrab: make output format user configurable

Timo Rothenpieler committed 4 years ago

Commit 38595eb1 parent f0abd072 files · +44 −1Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vsrc_ddagrab.c+28−1
@@ -97,6 +97,7 @@ typedef struct DdagrabContext { · 96 unmodified lines
9797 int height;
9898 int offset_x;
9999 int offset_y;
100+ int out_fmt;
100101 } DdagrabContext;
101102
102103 #define OFFSET(x) offsetof(DdagrabContext, x)
@@ -108,6 +109,12 @@ static const AVOption ddagrab_options[] = { · 5 unmodified lines
108109 { "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
109110 { "offset_x", "capture area x offset", OFFSET(offset_x), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
110111 { "offset_y", "capture area y offset", OFFSET(offset_y), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
112+ { "output_fmt", "desired output format", OFFSET(out_fmt), AV_OPT_TYPE_INT, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
113+ { "auto", "let dda pick its preferred format", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, INT_MAX, FLAGS, "output_fmt" },
114+ { "8bit", "only output default 8 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
115+ { "bgra", "only output 8 Bit BGRA", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
116+ { "10bit", "only output default 10 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
117+ { "x2bgr10", "only output 10 Bit X2BGR10", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
111118 { NULL }
112119 };
113120
@@ -208,6 +215,16 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 94 unmodified lines
208215 DXGI_FORMAT_R10G10B10A2_UNORM,
209216 DXGI_FORMAT_B8G8R8A8_UNORM
210217 };
218+ int nb_formats = FF_ARRAY_ELEMS(formats);
219+
220+ if(dda->out_fmt == DXGI_FORMAT_B8G8R8A8_UNORM) {
221+ formats[0] = DXGI_FORMAT_B8G8R8A8_UNORM;
222+ nb_formats = 1;
223+ } else if (dda->out_fmt) {
224+ formats[0] = dda->out_fmt;
225+ formats[1] = DXGI_FORMAT_B8G8R8A8_UNORM;
226+ nb_formats = 2;
227+ }
211228
212229 IDXGIOutput_Release(dxgi_output);
213230 dxgi_output = NULL;
@@ -219,7 +236,7 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 5 unmodified lines
219236 hr = IDXGIOutput5_DuplicateOutput1(dxgi_output5,
220237 (IUnknown*)dda->device_hwctx->device,
221238 0,
222− FF_ARRAY_ELEMS(formats),
239+ nb_formats,
223240 formats,
224241 &dda->dxgi_outdupl);
225242 IDXGIOutput5_Release(dxgi_output5);
@@ -242,6 +259,11 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 16 unmodified lines
242259 #else
243260 {
244261 #endif
262+ if (dda->out_fmt && dda->out_fmt != DXGI_FORMAT_B8G8R8A8_UNORM) {
263+ av_log(avctx, AV_LOG_ERROR, "Only 8 bit output supported with legacy API\n");
264+ return AVERROR(ENOTSUP);
265+ }
266+
245267 hr = IDXGIOutput_QueryInterface(dxgi_output, &IID_IDXGIOutput1, (void**)&dxgi_output1);
246268 IDXGIOutput_Release(dxgi_output);
247269 dxgi_output = NULL;
@@ -704,6 +726,11 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 456 unmodified lines
704726 if (ret < 0)
705727 return ret;
706728
729+ if (dda->out_fmt && dda->raw_format != dda->out_fmt) {
730+ av_log(avctx, AV_LOG_ERROR, "Requested output format unavailable.\n");
731+ return AVERROR(ENOTSUP);
732+ }
733+
707734 dda->width -= FFMAX(dda->width - dda->raw_width + dda->offset_x, 0);
708735 dda->height -= FFMAX(dda->height - dda->raw_height + dda->offset_y, 0);
709736

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