Skip to content

Commit 2f690ea

Browse files
shai-almogclaude
andcommitted
Windows camera: enable advanced video processing (YUY2/NV12 -> RGB32)
VM testing on a real webcam revealed the source reader was delivering 2-bpp frames (YUY2, the common webcam format: 640x480 -> 614400 bytes), not RGB32 (1228800), because SetCurrentMediaType(RGB32) is silently ignored unless the reader's video processor is enabled. The width*height*4 size check then rejected every frame, so the preview/session captured nothing. Create both source readers (the continuous session and the legacy capturePhoto) with MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING=TRUE so the reader inserts a converter to RGB32. Verified on the Windows ARM64 VM: the worker-thread session now delivers full 640x480 RGB32 frames (polled via cameraSessionLatestFrame), and the generic-peer PrintWindow capture returns real pixels. CI runners have no camera, so this path is only exercisable on a real machine. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ee380e0 commit 2f690ea

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Ports/WindowsPort/nativeSources/cn1_windows_camera.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ JAVA_OBJECT com_codename1_impl_windows_WindowsNative_cameraCaptureFrame___int_1A
113113
}
114114

115115
ComPtr<IMFSourceReader> reader;
116-
if (FAILED(MFCreateSourceReaderFromMediaSource(source.Get(), NULL, &reader))) {
116+
// Enable advanced video processing so a YUY2/NV12 webcam (the common case) is
117+
// converted to RGB32; without it the RGB32 request below is ignored and frames
118+
// come back 2-bpp, failing the size check (verified on a real YUY2 webcam).
119+
ComPtr<IMFAttributes> readerAttr;
120+
MFCreateAttributes(&readerAttr, 1);
121+
readerAttr->SetUINT32(MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, TRUE);
122+
if (FAILED(MFCreateSourceReaderFromMediaSource(source.Get(), readerAttr.Get(), &reader))) {
117123
source->Shutdown();
118124
return JAVA_NULL;
119125
}
@@ -237,7 +243,13 @@ static bool cn1CameraOpenReader(int deviceIndex, ComPtr<IMFMediaSource>& source,
237243
for (UINT32 i = 0; i < count; i++) { if (devices[i]) devices[i]->Release(); }
238244
CoTaskMemFree(devices);
239245
if (FAILED(hr) || !source) return false;
240-
if (FAILED(MFCreateSourceReaderFromMediaSource(source.Get(), NULL, &reader))) {
246+
// Enable the reader's video processor so a YUY2/NV12 webcam (the common case)
247+
// is converted to RGB32; without it SetCurrentMediaType(RGB32) fails and frames
248+
// arrive in the native 2-bpp format, failing the width*height*4 size check.
249+
ComPtr<IMFAttributes> rattr;
250+
MFCreateAttributes(&rattr, 1);
251+
rattr->SetUINT32(MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, TRUE);
252+
if (FAILED(MFCreateSourceReaderFromMediaSource(source.Get(), rattr.Get(), &reader))) {
241253
source->Shutdown();
242254
return false;
243255
}

0 commit comments

Comments
 (0)