History

avfilter/vsrc_ddagrab: move most of init to config_props

Most notably, the input hw_device_ctx is not set at init time, so using it was impossible.

Timo Rothenpieler committed 4 years ago

Commit cbb53bf1 parent fbf87a41 file · +37 −43Browse files

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

Unified · Split

libavfilter/vsrc_ddagrab.c+37−43
@@ -389,56 +389,15 @@ static av_cold int init_render_resources(AVFilterContext *avctx) · 388 unmodified lines
389389 static av_cold int ddagrab_init(AVFilterContext *avctx)
390390 {
391391 DdagrabContext *dda = avctx->priv;
392− int ret = 0;
393−
394− if (avctx->hw_device_ctx) {
395− dda->device_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
396−
397− if (dda->device_ctx->type != AV_HWDEVICE_TYPE_D3D11VA) {
398− av_log(avctx, AV_LOG_ERROR, "Non-D3D11VA input hw_device_ctx\n");
399− return AVERROR(EINVAL);
400− }
401−
402− dda->device_ref = av_buffer_ref(avctx->hw_device_ctx);
403− if (!dda->device_ref)
404− return AVERROR(ENOMEM);
405−
406− av_log(avctx, AV_LOG_VERBOSE, "Using provided hw_device_ctx\n");
407− } else {
408− ret = av_hwdevice_ctx_create(&dda->device_ref, AV_HWDEVICE_TYPE_D3D11VA, NULL, NULL, 0);
409− if (ret < 0) {
410− av_log(avctx, AV_LOG_ERROR, "Failed to create D3D11VA device.\n");
411− return ret;
412− }
413−
414− dda->device_ctx = (AVHWDeviceContext*)dda->device_ref->data;
415−
416− av_log(avctx, AV_LOG_VERBOSE, "Created internal hw_device_ctx\n");
417− }
418−
419− dda->device_hwctx = (AVD3D11VADeviceContext*)dda->device_ctx->hwctx;
420−
421− ret = init_dxgi_dda(avctx);
422− if (ret < 0)
423− goto fail;
424−
425− dda->time_base = av_inv_q(dda->framerate);
426− dda->time_frame = av_gettime_relative() / av_q2d(dda->time_base);
427− dda->time_timeout = av_rescale_q(1, dda->time_base, (AVRational) { 1, 1000 }) / 2;
428392
429393 dda->last_frame = av_frame_alloc();
430− if (!dda->last_frame) {
431− ret = AVERROR(ENOMEM);
432− goto fail;
433− }
394+ if (!dda->last_frame)
395+ return AVERROR(ENOMEM);
434396
435397 dda->mouse_x = -1;
436398 dda->mouse_y = -1;
437399
438400 return 0;
439−fail:
440− ddagrab_uninit(avctx);
441− return ret;
442401 }
443402
444403 static int create_d3d11_pointer_tex(AVFilterContext *avctx,
@@ -710,6 +669,37 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 265 unmodified lines
710669 DdagrabContext *dda = avctx->priv;
711670 int ret;
712671
672+ if (avctx->hw_device_ctx) {
673+ dda->device_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
674+
675+ if (dda->device_ctx->type != AV_HWDEVICE_TYPE_D3D11VA) {
676+ av_log(avctx, AV_LOG_ERROR, "Non-D3D11VA input hw_device_ctx\n");
677+ return AVERROR(EINVAL);
678+ }
679+
680+ dda->device_ref = av_buffer_ref(avctx->hw_device_ctx);
681+ if (!dda->device_ref)
682+ return AVERROR(ENOMEM);
683+
684+ av_log(avctx, AV_LOG_VERBOSE, "Using provided hw_device_ctx\n");
685+ } else {
686+ ret = av_hwdevice_ctx_create(&dda->device_ref, AV_HWDEVICE_TYPE_D3D11VA, NULL, NULL, 0);
687+ if (ret < 0) {
688+ av_log(avctx, AV_LOG_ERROR, "Failed to create D3D11VA device.\n");
689+ return ret;
690+ }
691+
692+ dda->device_ctx = (AVHWDeviceContext*)dda->device_ref->data;
693+
694+ av_log(avctx, AV_LOG_VERBOSE, "Created internal hw_device_ctx\n");
695+ }
696+
697+ dda->device_hwctx = (AVD3D11VADeviceContext*)dda->device_ctx->hwctx;
698+
699+ ret = init_dxgi_dda(avctx);
700+ if (ret < 0)
701+ return ret;
702+
713703 ret = probe_output_format(avctx);
714704 if (ret < 0)
715705 return ret;
@@ -717,6 +707,10 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 1 unmodified line
717707 dda->width -= FFMAX(dda->width - dda->raw_width + dda->offset_x, 0);
718708 dda->height -= FFMAX(dda->height - dda->raw_height + dda->offset_y, 0);
719709
710+ dda->time_base = av_inv_q(dda->framerate);
711+ dda->time_frame = av_gettime_relative() / av_q2d(dda->time_base);
712+ dda->time_timeout = av_rescale_q(1, dda->time_base, (AVRational) { 1, 1000 }) / 2;
713+
720714 if (dda->draw_mouse) {
721715 ret = init_render_resources(avctx);
722716 if (ret < 0)

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