Skip to content

Commit

Permalink
Fix a race condition in VAAPI CSC to YUV420P
Browse files Browse the repository at this point in the history
Signed-off-by: nyanmisaka <nst799610810@gmail.com>
  • Loading branch information
nyanmisaka committed Jan 19, 2025
1 parent 53c3cdd commit dfb0988
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Index: FFmpeg/libavutil/hwcontext_vaapi.c
===================================================================
--- FFmpeg.orig/libavutil/hwcontext_vaapi.c
+++ FFmpeg/libavutil/hwcontext_vaapi.c
@@ -72,6 +72,7 @@ typedef struct VAAPIDevicePriv {
typedef struct VAAPISurfaceFormat {
enum AVPixelFormat pix_fmt;
VAImageFormat image_format;
+ unsigned int fourcc;
} VAAPISurfaceFormat;

typedef struct VAAPIDeviceContext {
@@ -221,15 +222,21 @@ static int vaapi_get_image_format(AVHWDe
VAImageFormat **image_format)
{
VAAPIDeviceContext *ctx = hwdev->hwctx;
+ const VAAPIFormatDescriptor *desc;
int i;

+ desc = vaapi_format_from_pix_fmt(pix_fmt);
+ if (!desc || !image_format)
+ goto fail;
+
for (i = 0; i < ctx->nb_formats; i++) {
- if (ctx->formats[i].pix_fmt == pix_fmt) {
- if (image_format)
- *image_format = &ctx->formats[i].image_format;
+ if (ctx->formats[i].fourcc == desc->fourcc) {
+ *image_format = &ctx->formats[i].image_format;
return 0;
}
}
+
+fail:
return AVERROR(ENOSYS);
}

@@ -446,6 +453,7 @@ static int vaapi_device_init(AVHWDeviceC
av_log(hwdev, AV_LOG_DEBUG, "Format %#x -> %s.\n",
fourcc, av_get_pix_fmt_name(pix_fmt));
ctx->formats[ctx->nb_formats].pix_fmt = pix_fmt;
+ ctx->formats[ctx->nb_formats].fourcc = fourcc;
ctx->formats[ctx->nb_formats].image_format = image_list[i];
++ctx->nb_formats;
}
@@ -1022,12 +1030,6 @@ static int vaapi_map_to_memory(AVHWFrame
{
int err;

- if (dst->format != AV_PIX_FMT_NONE) {
- err = vaapi_get_image_format(hwfc->device_ctx, dst->format, NULL);
- if (err < 0)
- return err;
- }
-
err = vaapi_map_frame(hwfc, dst, src, flags);
if (err)
return err;
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@
0081-backport-av1-videotoolbox.patch
0082-fix-ass-incorrect-null-copy.patch
0083-default-to-input-timebase-for-streamcopy.patch
0084-fix-a-race-condition-in-vaapi-csc-to-yuv420p.patch

0 comments on commit dfb0988

Please sign in to comment.