Allow sources to know when it is being previewed #11898
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A preview state is added to the OBS API to allow sources to determine if they are in the current preview scene or not. The new preview state APIs work similiar to the existing activate/deactivate/show/hide APIs where a callback is optionally provided to notify the source of changes in state. Building on this new preview state, toggling of visibility of a source in the preview scene will change the preview state and notify the source immediately.
The changes consist of three parts:
This PR contains 5 commits:
The big part of this PR is seperating the show_refs count from the activate_refs. To do this a new SHOW_VIEW enum was added to the AUX_VIEW and MAIN_VIEW enums. This allows callers (specifically projectors or multiview) to only inc/dec show_refs and not change activate or preview ref counts.
Motivation and Context
Currently a source can know when it is being shown and when it is active on the main "program" scene. In the case of studio mode, a source may be also be shown in the current preview scene. When a source is in the current program scene, it is considered 'shown' and 'active' by OBS. If it is only in preview scene, it is just 'shown'. Also, when a source is shown as part of a scene in Multiview or on a projector, the source will also have a state of 'shown'. This causes a problem when a source needs to implement a tally. A tally is traditionally a red (active) or green (preview) light on the camera to give the camera operator or video subject indication as to if the camera is live/on program (red) or being previewed (green), or not being used (no light). This means the condition: shown AND not active is not indicative of being in the current preview scene.
So the basic issue is that show state is used for projection/multiview and when a source is in the current program scene. This PR fixes this problem by introducing a preview state.
This issue has been documented by a DistroAV (formerly obs-ndi) user, complaining that his tally light on his NDI camera flashes red/green/red/green/... when it is in the current program scene and not in preview. DistroAV/DistroAV#687
The issue can also be witnessed in NDI Studio Monitor when viewing the source when it is in the current program scene in OBS, but not in the current preview scene. A red and a green bar appears at the top of the video. Also, a green bar appears when the NDI source is being projected or in multiview, and not in the current preview scene.
There is also a OBS API feature request for this here:
https://ideas.obsproject.com/posts/1271/add-obs_source_inpreview-to-sdk
Finally a long time problem of the Multi-view causing all NDI sources to show as in
preview, is here: DistroAV/DistroAV#318
Type of change
API considerations
Since the show/hide API is used by sources to know if OBS is using the source in any way, we cannot change the meaning of show/hide, without breaking the API. With this change, new APIs were added so the source can simply and accurately determine if a source is being previewed and immediately react to changes the user makes to the source state.
Exactly mirroring the activate/deactivate APIs, this PR adds the following APIs:
Testing
To test, I modified DistroAV to use the new preview APIs. I then created 3 Test Pattern sources in NDI Tools. I then opened Studio Monitor on each Test Pattern Source, and turned on Tally display. I created a collection of 3 scenes as shown in the table below, along with results of the testing.
The table shows the tally after each step for each source. Sometimes the tally is red and green.
To aid in testing by reviewers of this PR, I created a Lua script that creates an OBS source called "Tally Test". The script will log when any of the 6 callbacks are called: activate, deactivate, preview, depreview, show and hide. Pleae find the Lua script here:
testtally.txt
Finally, the tests were done in Normal (non Studio) mode with no Preview scene and all callbacks were called correctly.
Checklist: