Add feature to detect device's remove/insert events. #30
Loading…
Reference in a new issue
No description provided.
Delete branch "unknown repository"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Add feature to detect device's remove/insert events. When device is inserted, win-dshow can restore camera when received event.
However, to be enable to detect remove/insert, we must success to initialize dshow firstly.
Besides, it seems insert/remove events won't be sent for audio filter.
Motivation and Context
Help win-dshow to restore camera when device is inserted.
How Has This Been Tested?
Tested on Window10 with Legitech C920
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
After merging this PR, we can improve win-dshow to restore camera automatically:
@jp9000 Request your review
This will not be reviewed until some time after v27 is released.
Got it!
Hmm~
will this PR be merged ?
sorry about that, I'll try to get around to it sooner than later, it's just easy for things to slide (especially when they're on repositories other than the main repository)
@PatTheMav @RytoEX
can you help review this PR ? thanks~
Conceptually this looks correct as far as the Win32 APIs are concerned, so I got mostly code style nits.
Might need someone else to debug this on an actual Windows machine with a DirectShow device.
@ -56,0 +92,4 @@break;}}Is it necessary to use
reinterpret_casthere? Wouldstatic_castsuffice?@ -56,0 +106,4 @@if (EC_DEVICE_LOST == eventCode) {if (FLAG_REMOVE_DEVICE == param2) {Warning(L"Device is removed.");callback->OnDeviceRemoved();The array is static and the count never changes, so an
std::arraycould be used, which has asize()method to get the count forWaitForMultipleObjectsand thedata()method to get a raw pointer.@ -56,0 +111,4 @@Info(L"Device is inserted again.");callback->OnDeviceInserted();}}Per Microsoft's documentation states this should use the logic
res - WAIT_OBJECT_0 == <expected array index>.@ -56,0 +115,4 @@eventEx->FreeEventParams(eventCode, param1, param2);if (WAIT_OBJECT_0 == WaitForSingleObject(exitEvt, 0))Needs to use curly braces for all blocks per current code style guidelines. Applies throughout.
@ -56,0 +120,4 @@}return true;}Replace with
constexpr int.@ -56,0 +142,4 @@{::SetEvent(exitEvt);if (msgThread && (msgThread != INVALID_HANDLE_VALUE)) {WaitForSingleObject(msgThread, INFINITE);The idea here is to check whether the exit event was signalled after the current media event and thus make the media event thread exit?
Why is it necessary to use the global scope identifier explicitly here and for other functions like
ResetEventabove?Why use a static class function rather than a free-standing function in an anonymous namespace for this? Also why use
_beginthreadexover theCreateThreadAPI?Use
static_castinstead of C-style casts in C++ code.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.