Skip to content
Snippets Groups Projects
Unverified Commit 40ee25ff authored by Sébastien Blin's avatar Sébastien Blin
Browse files

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
parent ea97002a
No related branches found
No related tags found
No related merge requests found
...@@ -699,6 +699,7 @@ std::shared_ptr<video::VideoInput> ...@@ -699,6 +699,7 @@ std::shared_ptr<video::VideoInput>
getVideoInput(const std::string& id, video::VideoInputMode inputMode) getVideoInput(const std::string& id, video::VideoInputMode inputMode)
{ {
auto& vmgr = Manager::instance().getVideoManager(); auto& vmgr = Manager::instance().getVideoManager();
std::lock_guard<std::mutex> lk(vmgr.videoMutex);
auto it = vmgr.videoInputs.find(id); auto it = vmgr.videoInputs.find(id);
if (it != vmgr.videoInputs.end()) { if (it != vmgr.videoInputs.end()) {
if (auto input = it->second.lock()) { if (auto input = it->second.lock()) {
......
...@@ -56,6 +56,7 @@ public: ...@@ -56,6 +56,7 @@ public:
std::map<std::string, std::weak_ptr<AudioInput>, std::less<>> audioInputs; std::map<std::string, std::weak_ptr<AudioInput>, std::less<>> audioInputs;
std::map<std::string, std::weak_ptr<video::VideoInput>, std::less<>> videoInputs; std::map<std::string, std::weak_ptr<video::VideoInput>, std::less<>> videoInputs;
std::mutex audioMutex; std::mutex audioMutex;
std::mutex videoMutex;
bool hasRunningPlayers(); bool hasRunningPlayers();
std::shared_ptr<video::VideoInput> getVideoInput(std::string_view id) const std::shared_ptr<video::VideoInput> getVideoInput(std::string_view id) const
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment