Most notably, the input hw_device_ctx is not set at init time, so using it was impossible.
Unified · Split
| @@ -389,56 +389,15 @@ static av_cold int init_render_resources(AVFilterContext *avctx) · 388 unmodified lines | ||
| 389 | 389 | static av_cold int ddagrab_init(AVFilterContext *avctx) |
| 390 | 390 | { |
| 391 | 391 | 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; | |
| 428 | 392 | |
| 429 | 393 | 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); | |
| 434 | 396 | |
| 435 | 397 | dda->mouse_x = -1; |
| 436 | 398 | dda->mouse_y = -1; |
| 437 | 399 | |
| 438 | 400 | return 0; |
| 439 | −fail: | |
| 440 | − ddagrab_uninit(avctx); | |
| 441 | − return ret; | |
| 442 | 401 | } |
| 443 | 402 | |
| 444 | 403 | static int create_d3d11_pointer_tex(AVFilterContext *avctx, |
| @@ -710,6 +669,37 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 265 unmodified lines | ||
| 710 | 669 | DdagrabContext *dda = avctx->priv; |
| 711 | 670 | int ret; |
| 712 | 671 | |
| 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 | + | |
| 713 | 703 | ret = probe_output_format(avctx); |
| 714 | 704 | if (ret < 0) |
| 715 | 705 | return ret; |
| @@ -717,6 +707,10 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 1 unmodified line | ||
| 717 | 707 | dda->width -= FFMAX(dda->width - dda->raw_width + dda->offset_x, 0); |
| 718 | 708 | dda->height -= FFMAX(dda->height - dda->raw_height + dda->offset_y, 0); |
| 719 | 709 | |
| 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 | + | |
| 720 | 714 | if (dda->draw_mouse) { |
| 721 | 715 | ret = init_render_resources(avctx); |
| 722 | 716 | if (ret < 0) |