cscore: Add connection strategy to sources (#1252)

By default, sources automatically manage their connection based on whether
any sinks are connected.  This change allows the user to keep a connection
open or force it closed regardless of the number of connected sinks.
This commit is contained in:
Peter Johnson
2018-07-29 21:18:45 -07:00
committed by GitHub
parent 7bd3f9f0bd
commit 0a0d9245e2
12 changed files with 222 additions and 11 deletions

View File

@@ -41,6 +41,15 @@ class SourceImpl : public PropertyContainer {
void SetDescription(const wpi::Twine& description);
wpi::StringRef GetDescription(wpi::SmallVectorImpl<char>& buf) const;
void SetConnectionStrategy(CS_ConnectionStrategy strategy) {
m_strategy = static_cast<int>(strategy);
}
bool IsEnabled() const {
return m_strategy == CS_CONNECTION_KEEP_OPEN ||
(m_strategy == CS_CONNECTION_AUTO_MANAGE && m_numSinksEnabled > 0);
}
// User-visible connection status
void SetConnected(bool connected);
bool IsConnected() const { return m_connected; }
@@ -130,7 +139,6 @@ class SourceImpl : public PropertyContainer {
virtual void NumSinksEnabledChanged() = 0;
std::atomic_int m_numSinks{0};
std::atomic_int m_numSinksEnabled{0};
protected:
// Cached video modes (protected with m_mutex)
@@ -146,6 +154,9 @@ class SourceImpl : public PropertyContainer {
std::string m_name;
std::string m_description;
std::atomic_int m_strategy{CS_CONNECTION_AUTO_MANAGE};
std::atomic_int m_numSinksEnabled{0};
wpi::mutex m_frameMutex;
wpi::condition_variable m_frameCv;