Skip to content

Commit

Permalink
avfilter/vsrc_ddagrab: only use buffer texture if parameters actually…
Browse files Browse the repository at this point in the history
… mismatch
  • Loading branch information
BtbN committed Mar 15, 2024
1 parent 4ce6c74 commit d3a04d4
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions libavfilter/vsrc_ddagrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,29 +709,9 @@ static int next_frame_internal(AVFilterContext *avctx, ID3D11Texture2D **desktop
goto error;
}

if (!frame_info.LastPresentTime.QuadPart || !frame_info.AccumulatedFrames) {
if (need_frame) {
ret = AVERROR(EAGAIN);
goto error;
}

// Unforunately, we can't rely on the desktop_resource's format in this case.
// The API might even return it in with a format that was not in the initial
// list of supported formats, and it can change/flicker randomly.
// To work around this, return an internal copy of the last valid texture we got.
release_resource(&desktop_resource);

// The initial probing should make this impossible.
if (!dda->buffer_texture) {
av_log(avctx, AV_LOG_ERROR, "No buffer texture while operating!\n");
ret = AVERROR_BUG;
goto error;
}

av_log(avctx, AV_LOG_TRACE, "Returning internal buffer for a frame!\n");
ID3D11Texture2D_AddRef(dda->buffer_texture);
*desktop_texture = dda->buffer_texture;
return 0;
if (need_frame && (!frame_info.LastPresentTime.QuadPart || !frame_info.AccumulatedFrames)) {
ret = AVERROR(EAGAIN);
goto error;
}

hr = IDXGIResource_QueryInterface(desktop_resource, &IID_ID3D11Texture2D, (void**)desktop_texture);
Expand Down Expand Up @@ -1147,10 +1127,12 @@ static int ddagrab_request_frame(AVFilterLink *outlink)
ID3D11Texture2D_GetDesc(cur_texture, &desc);
if (desc.Format != dda->raw_format ||
(int)desc.Width != dda->raw_width ||
(int)desc.Height != dda->raw_height) {
av_log(avctx, AV_LOG_ERROR, "Output parameters changed!\n");
ret = AVERROR_OUTPUT_CHANGED;
goto fail;
(int)desc.Height != dda->raw_height)
{
av_log(avctx, AV_LOG_DEBUG, "Output parameters changed, falling back to buffer.\n");
release_resource(&cur_texture);
ID3D11Texture2D_AddRef(dda->buffer_texture);
cur_texture = dda->buffer_texture;
}

frame = ff_get_video_buffer(outlink, dda->width, dda->height);
Expand Down

0 comments on commit d3a04d4

Please sign in to comment.