Add feature to detect device's remove/insert events. #30

Open
walker-WSH wants to merge 2 commits from unknown repository into master
walker-WSH commented 2021-04-28 01:05:37 -05:00 (Migrated from github.com)

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:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
<!--- Please fill out the following template, which will help other contributors review your Pull Request. --> <!--- Make sure you’ve read the contribution guidelines here: https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst --> ### Description <!--- Describe your changes in detail. --> <!--- If this change includes UI elements, please include screenshots. --> 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 <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open GitHub Issue, or implements feature request --> <!--- from the Ideas page, please link to the issue here. --> Help win-dshow to restore camera when device is inserted. ### How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment (hardware, OS version, etc.),--> <!--- and the tests you ran, including how it may affect other areas of code. --> Tested on Window10 with Legitech C920 ### Types of changes New feature (non-breaking change which adds functionality) ### Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] My code has been run through [clang-format](https://github.com/obsproject/obs-studio/blob/master/.clang-format). - [x] I have read the [**contributing** document](https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst). - [x] My code is not on the master branch. - [x] The code has been tested. - [x] All commit messages are properly formatted and commits squashed where appropriate. - [x] I have included updates to all appropriate documentation.
walker-WSH commented 2021-04-28 01:13:10 -05:00 (Migrated from github.com)

After merging this PR, we can improve win-dshow to restore camera automatically:

1619590349

After merging this PR, we can improve win-dshow to restore camera automatically: ![1619590349](https://user-images.githubusercontent.com/18413354/116355031-daa15b80-a82b-11eb-9059-fec933771828.png)
walker-WSH commented 2021-05-06 21:12:23 -05:00 (Migrated from github.com)

@jp9000 Request your review

@jp9000 Request your review
dodgepong commented 2021-05-06 23:29:16 -05:00 (Migrated from github.com)

This will not be reviewed until some time after v27 is released.

This will not be reviewed until some time after v27 is released.
walker-WSH commented 2021-05-07 03:02:06 -05:00 (Migrated from github.com)

This will not be reviewed until some time after v27 is released.

Got it!

> This will not be reviewed until some time after v27 is released. Got it!
walker-WSH commented 2022-01-13 03:59:13 -06:00 (Migrated from github.com)

Hmm~
will this PR be merged ?

Hmm~ will this PR be merged ?
jp9000 commented 2022-01-18 04:40:29 -06:00 (Migrated from github.com)

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)

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)
walker-WSH commented 2024-06-04 03:43:03 -05:00 (Migrated from github.com)

@PatTheMav @RytoEX
can you help review this PR ? thanks~

@PatTheMav @RytoEX can you help review this PR ? thanks~
PatTheMav (Migrated from github.com) requested changes 2026-08-27 10:22:56 -05:00
PatTheMav (Migrated from github.com) left a comment

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.

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;
}
}
PatTheMav (Migrated from github.com) commented 2026-08-27 10:21:57 -05:00

Is it necessary to use reinterpret_cast here? Would static_cast suffice?

Is it necessary to use `reinterpret_cast` here? Would `static_cast` suffice?
@ -56,0 +106,4 @@
if (EC_DEVICE_LOST == eventCode) {
if (FLAG_REMOVE_DEVICE == param2) {
Warning(L"Device is removed.");
callback->OnDeviceRemoved();
PatTheMav (Migrated from github.com) commented 2026-08-27 10:15:36 -05:00

The array is static and the count never changes, so an std::array could be used, which has a size() method to get the count for WaitForMultipleObjects and the data() method to get a raw pointer.

The array is static and the count never changes, so an `std::array` could be used, which has a `size()` method to get the count for `WaitForMultipleObjects` and the `data()` method to get a raw pointer.
@ -56,0 +111,4 @@
Info(L"Device is inserted again.");
callback->OnDeviceInserted();
}
}
PatTheMav (Migrated from github.com) commented 2026-08-27 10:16:11 -05:00

Per Microsoft's documentation states this should use the logic res - WAIT_OBJECT_0 == <expected array index>.

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))
PatTheMav (Migrated from github.com) commented 2026-08-27 10:16:46 -05:00
		if (!ReadAllEvents()) {
			break;
		}

Needs to use curly braces for all blocks per current code style guidelines. Applies throughout.

```suggestion if (!ReadAllEvents()) { break; } ``` Needs to use curly braces for all blocks per current code style guidelines. Applies throughout.
@ -56,0 +120,4 @@
}
return true;
}
PatTheMav (Migrated from github.com) commented 2026-08-27 10:17:02 -05:00

Replace with constexpr int.

Replace with `constexpr int`.
@ -56,0 +142,4 @@
{
::SetEvent(exitEvt);
if (msgThread && (msgThread != INVALID_HANDLE_VALUE)) {
WaitForSingleObject(msgThread, INFINITE);
PatTheMav (Migrated from github.com) commented 2026-08-27 10:18:54 -05:00

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?

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?
PatTheMav (Migrated from github.com) commented 2026-08-27 10:20:29 -05:00

Why is it necessary to use the global scope identifier explicitly here and for other functions like ResetEvent above?

Why is it necessary to use the global scope identifier explicitly here and for other functions like `ResetEvent` above?
PatTheMav (Migrated from github.com) commented 2026-08-27 10:12:26 -05:00
	HANDLE mediaEvent;
```suggestion HANDLE mediaEvent; ```
PatTheMav (Migrated from github.com) commented 2026-08-27 10:12:38 -05:00
	HANDLE exitEvent;
```suggestion HANDLE exitEvent; ```
PatTheMav (Migrated from github.com) commented 2026-08-27 10:12:51 -05:00
	HANDLE mediaEventThread;
```suggestion HANDLE mediaEventThread; ```
PatTheMav (Migrated from github.com) commented 2026-08-27 10:13:55 -05:00

Why use a static class function rather than a free-standing function in an anonymous namespace for this? Also why use _beginthreadex over the CreateThread API?

Why use a static class function rather than a free-standing function in an anonymous namespace for this? Also why use `_beginthreadex` over the `CreateThread` API?
PatTheMav (Migrated from github.com) commented 2026-08-27 10:21:12 -05:00
		hr = graph->QueryInterface(IID_IMediaEventEx, static_cast<void **>(&event));

Use static_cast instead of C-style casts in C++ code.

```suggestion hr = graph->QueryInterface(IID_IMediaEventEx, static_cast<void **>(&event)); ``` Use `static_cast` instead of C-style casts in C++ code.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'unknown repository:unknown repository'
git switch 'unknown repository'

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.

git switch 'master'
git merge --no-ff 'unknown repository'
git switch 'unknown repository'
git rebase 'master'
git switch 'master'
git merge --ff-only 'unknown repository'
git switch 'unknown repository'
git rebase 'master'
git switch 'master'
git merge --no-ff 'unknown repository'
git switch 'master'
git merge --squash 'unknown repository'
git switch 'master'
git merge --ff-only 'unknown repository'
git switch 'master'
git merge 'unknown repository'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-obsproject/libdshowcapture!30
No description provided.