-
Notifications
You must be signed in to change notification settings - Fork 1.5k
filter: add scale_d3d11 support for MF encoders #7115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dashsantosh-mcw
wants to merge
1
commit into
HandBrake:master
Choose a base branch
from
dashsantosh-mcw:vpblt-rebased
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c | ||
index 9831f530c1..dac659ea9a 100644 | ||
--- a/libavutil/hwcontext_d3d11va.c | ||
+++ b/libavutil/hwcontext_d3d11va.c | ||
@@ -85,6 +85,9 @@ typedef struct D3D11VAFramesContext { | ||
int nb_surfaces; | ||
int nb_surfaces_used; | ||
|
||
+ int max_retries; | ||
+ int retries; | ||
+ | ||
DXGI_FORMAT format; | ||
|
||
ID3D11Texture2D *staging_texture; | ||
@@ -260,8 +263,10 @@ static AVBufferRef *d3d11va_pool_alloc(void *opaque, size_t size) | ||
ID3D11Texture2D_GetDesc(hwctx->texture, &texDesc); | ||
|
||
if (s->nb_surfaces_used >= texDesc.ArraySize) { | ||
- av_log(ctx, AV_LOG_ERROR, "Static surface pool size exceeded.\n"); | ||
- return NULL; | ||
+ if (s->retries >= s->max_retries) { | ||
+ av_log(ctx, AV_LOG_ERROR, "Static surface pool size exceeded.\n"); | ||
+ } | ||
+ return NULL; | ||
} | ||
|
||
ID3D11Texture2D_AddRef(hwctx->texture); | ||
@@ -343,20 +348,34 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) | ||
static int d3d11va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) | ||
{ | ||
AVD3D11FrameDescriptor *desc; | ||
+ D3D11VAFramesContext *s = ctx->hwctx; | ||
+ s->retries = 0; | ||
+ s->max_retries = 50; | ||
|
||
- frame->buf[0] = av_buffer_pool_get(ctx->pool); | ||
- if (!frame->buf[0]) | ||
- return AVERROR(ENOMEM); | ||
- | ||
- desc = (AVD3D11FrameDescriptor *)frame->buf[0]->data; | ||
- | ||
- frame->data[0] = (uint8_t *)desc->texture; | ||
- frame->data[1] = (uint8_t *)desc->index; | ||
- frame->format = AV_PIX_FMT_D3D11; | ||
- frame->width = ctx->width; | ||
- frame->height = ctx->height; | ||
+ /** | ||
+ * Loop until a buffer becomes available from the pool. | ||
+ * In a full hardware pipeline, all buffers may be temporarily in use by | ||
+ * other modules (encoder/filter/decoder). Rather than immediately failing | ||
+ * with ENOMEM, we wait for a buffer to be released back to the pool, which | ||
+ * maintains pipeline flow and prevents unnecessary allocation failures | ||
+ * during normal operation. | ||
+ */ | ||
+ while (s->retries < s->max_retries) { | ||
+ frame->buf[0] = av_buffer_pool_get(ctx->pool); | ||
+ if (frame->buf[0]) { | ||
+ desc = (AVD3D11FrameDescriptor *)frame->buf[0]->data; | ||
+ frame->data[0] = (uint8_t *)desc->texture; | ||
+ frame->data[1] = (uint8_t *)desc->index; | ||
+ frame->format = AV_PIX_FMT_D3D11; | ||
+ frame->width = ctx->width; | ||
+ frame->height = ctx->height; | ||
+ return 0; | ||
+ } | ||
|
||
- return 0; | ||
+ av_usleep(1000); | ||
+ } | ||
+ | ||
+ return AVERROR(ENOMEM); | ||
} | ||
|
||
static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can scale_d3d11 convert from one color range to another? If not the output will not be correct if the source color range is not the same as the output one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, scale_d3d11 does not handle color range conversion. Would it be okay to disable the full hardware pipeline in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some seriously broken video out there that can change the color range mid-stream, so in those cases it would still break, but yes we can disable it for now.