From 17549435960cf114a5118f837e0a71d6e7e0d4c9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 16 Feb 2025 08:13:35 -0800
Subject: [PATCH] Fixed camera frame acquisition on Windows 7
Fixes https://github.com/libsdl-org/SDL/issues/12210
---
.../SDL_camera_mediafoundation.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/camera/mediafoundation/SDL_camera_mediafoundation.c b/src/camera/mediafoundation/SDL_camera_mediafoundation.c
index b25e76112390a..32c5b446e859e 100644
--- a/src/camera/mediafoundation/SDL_camera_mediafoundation.c
+++ b/src/camera/mediafoundation/SDL_camera_mediafoundation.c
@@ -600,23 +600,18 @@ static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SD
IMF2DBuffer2_Unlock2D(buffer2d2);
}
IMF2DBuffer2_Release(buffer2d2);
- } else if (SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &SDL_IID_IMF2DBuffer, (void **)&buffer2d))) {
+ } else if (frame->format != SDL_PIXELFORMAT_MJPG &&
+ SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &SDL_IID_IMF2DBuffer, (void **)&buffer2d))) {
ret = IMF2DBuffer_Lock2D(buffer2d, &pixels, &pitch);
if (FAILED(ret)) {
result = SDL_CAMERA_FRAME_ERROR;
} else {
- if (frame->format == SDL_PIXELFORMAT_MJPG) {
- // FIXME: How big is this frame?
- const DWORD buflen = 0;
- result = MEDIAFOUNDATION_CopyFrame(frame, pixels, pitch, buflen);
- } else {
- BYTE *bufstart = pixels;
- const DWORD buflen = (SDL_abs((int)pitch) * frame->w) * frame->h;
- if (pitch < 0) { // image rows are reversed.
- bufstart += -pitch * (frame->h - 1);
- }
- result = MEDIAFOUNDATION_CopyFrame(frame, bufstart, pitch, buflen);
+ BYTE *bufstart = pixels;
+ const DWORD buflen = SDL_abs((int)pitch) * frame->h;
+ if (pitch < 0) { // image rows are reversed.
+ bufstart += -pitch * (frame->h - 1);
}
+ result = MEDIAFOUNDATION_CopyFrame(frame, bufstart, pitch, buflen);
IMF2DBuffer_Unlock2D(buffer2d);
}
IMF2DBuffer_Release(buffer2d);