videomanager: protect double video input creation

getVideoInput is called in two different place:
+ openVideoInput from the client
+ VideoRtpSession::startSender() from the daemon
Nothing is blocking both sides to do it at the same time.
In this case, two VideoInputs can be created, causing the second
one to fail because the device is busy (used by the first one)
and causing weird results (i.e. sometimes the video is not shown).

Change-Id: I23e34a95efe4972fbe111c19f0f0989f5e8ae8a9
This commit is contained in:
Sébastien Blin
2021-12-15 15:36:53 -05:00
parent ea97002a08
commit 40ee25ff8e
2 changed files with 2 additions and 0 deletions

View File

@ -699,6 +699,7 @@ std::shared_ptr<video::VideoInput>
getVideoInput(const std::string& id, video::VideoInputMode inputMode)
{
auto& vmgr = Manager::instance().getVideoManager();
std::lock_guard<std::mutex> lk(vmgr.videoMutex);
auto it = vmgr.videoInputs.find(id);
if (it != vmgr.videoInputs.end()) {
if (auto input = it->second.lock()) {

View File

@ -56,6 +56,7 @@ public:
std::map<std::string, std::weak_ptr<AudioInput>, std::less<>> audioInputs;
std::map<std::string, std::weak_ptr<video::VideoInput>, std::less<>> videoInputs;
std::mutex audioMutex;
std::mutex videoMutex;
bool hasRunningPlayers();
std::shared_ptr<video::VideoInput> getVideoInput(std::string_view id) const
{