-
Notifications
You must be signed in to change notification settings - Fork 137
Fix Windows DirectShow: Add virtual camera support and friendly names #657
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
base: master
Are you sure you want to change the base?
Conversation
Fix three critical issues in Windows DirectShow camera driver:
1. Single-frame capture bug - streaming stopped after first frame
2. No virtual camera support - OBS Virtual Camera didn't work
3. Unfriendly device names - showed DirectShow paths instead of camera names
Changes:
- Remove Null Renderer connection to enable continuous frame delivery
- Auto-detect NV12 and YUY2 formats based on buffer size
- Convert both formats to I420 (4:2:0) for consistency
- Use IPropertyBag FriendlyName property for readable camera names
(e.g., "OBS Virtual Camera" instead of "@device_sw_{...}\{...}")
- Fix memory leak in Open() if listResolution fails
- Optimize NV12 conversion with loop unrolling
- Add channel buffer to reduce frame drops
- Add oleaut32 library dependency for VARIANT functions
Tested on:
- Windows 10/11
- OBS Virtual Camera (NV12 format) - now works
- Physical webcams (YUY2 format) - continue working
- Device enumeration shows friendly names
- Sustained 30+ FPS streaming
Files modified:
- pkg/driver/camera/camera_windows.cpp
- pkg/driver/camera/camera_windows.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #657 +/- ##
=======================================
Coverage 42.52% 42.52%
=======================================
Files 84 84
Lines 5703 5703
=======================================
Hits 2425 2425
Misses 3130 3130
Partials 148 148 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Thank you for fixing windows code!
(Most of the active developers don't use windows)
| memset(&mediaType, 0, sizeof(mediaType)); | ||
| mediaType.majortype = MEDIATYPE_Video; | ||
| mediaType.subtype = MEDIASUBTYPE_YUY2; | ||
| // Accept any format by leaving subtype as zeros (equivalent to GUID_NULL) |
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.
Is it possible that an incompatible format is chosen?
| // FIX: Don't connect to null renderer | ||
| // Null renderer causes DirectShow to pause after one frame |
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 thought output pins should be terminated by connecting to null renderer when I wrote this long ago. (I'm not familiar with windows API)
If it's not necessary, please remove the code instead of commenting out.
| fprintf(stderr, "Unexpected buffer size: %d (expected NV12=%d or YUY2=%d)\n", | ||
| len, expectedNV12, expectedYUY2); | ||
| return S_OK; |
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 the whole program should fail instead of ignoring the data if an incompatible format is selected.
Partially addresses #95 - Adds NV12 format support and fixes continuous frame delivery
Problem
The current Windows DirectShow implementation has three critical issues:
Solution
This PR fixes all three issues:
Testing
Tested on Windows 10/11 with:
Before/After
Device names:
Streaming:
Files Modified
pkg/driver/camera/camera_windows.cpp(~90 lines changed)pkg/driver/camera/camera_windows.go(~25 lines changed)Breaking Changes
None - 100% backward compatible
Notes
This patch was developed with Claude AI assistance through extensive testing and iteration. I'm not a C programmer, so please review carefully. Happy to address any feedback!
Co-authored-by: Claude AI https://claude.ai