mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-05-09 12:42:33 -05:00
Add helper to keep sources active
To be used for e.g. the video condition / game capture condition, which can only get the relevant information while a given source is "active". A source can become active if it is not part of the currently selected scene.
This commit is contained in:
parent
4f3d9e3a00
commit
c7140f7c9f
|
|
@ -162,4 +162,47 @@ bool IsMediaSource(obs_source_t *source)
|
|||
return (flags & OBS_SOURCE_CONTROLLABLE_MEDIA) != 0;
|
||||
}
|
||||
|
||||
SourceActiveKeeper::~SourceActiveKeeper()
|
||||
{
|
||||
ReleaseRef();
|
||||
}
|
||||
|
||||
void SourceActiveKeeper::SetActive(bool active)
|
||||
{
|
||||
if (_active == active) {
|
||||
return;
|
||||
}
|
||||
_active = active;
|
||||
if (_active) {
|
||||
AcquireRef();
|
||||
} else {
|
||||
ReleaseRef();
|
||||
}
|
||||
}
|
||||
|
||||
void SourceActiveKeeper::SetSource(obs_source_t *source)
|
||||
{
|
||||
if (_source == source) {
|
||||
return;
|
||||
}
|
||||
ReleaseRef();
|
||||
_source = source;
|
||||
AcquireRef();
|
||||
}
|
||||
|
||||
void SourceActiveKeeper::AcquireRef()
|
||||
{
|
||||
if (_active && _source) {
|
||||
obs_source_inc_active(_source);
|
||||
}
|
||||
}
|
||||
|
||||
void SourceActiveKeeper::ReleaseRef()
|
||||
{
|
||||
if (_active && _source) {
|
||||
obs_source_dec_active(_source);
|
||||
_source = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
|
|
|||
|
|
@ -20,4 +20,25 @@ EXPORT OBSWeakSource GetWeakFilterByQString(OBSWeakSource source,
|
|||
EXPORT int GetSceneItemCount(const OBSWeakSource &);
|
||||
EXPORT bool IsMediaSource(obs_source_t *source);
|
||||
|
||||
// RAII helper that keeps an OBS source active (via obs_source_inc_active /
|
||||
// obs_source_dec_active) for as long as the keeper is enabled.
|
||||
class EXPORT SourceActiveKeeper {
|
||||
public:
|
||||
SourceActiveKeeper() = default;
|
||||
~SourceActiveKeeper();
|
||||
|
||||
SourceActiveKeeper(const SourceActiveKeeper &) = delete;
|
||||
SourceActiveKeeper &operator=(const SourceActiveKeeper &) = delete;
|
||||
|
||||
void SetActive(bool active);
|
||||
void SetSource(obs_source_t *source);
|
||||
|
||||
private:
|
||||
void AcquireRef();
|
||||
void ReleaseRef();
|
||||
|
||||
OBSSource _source;
|
||||
bool _active = false;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user