From 8c7398e937bffd6b4d570f68581f73c9f914692c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Wed, 6 Nov 2019 10:37:16 -0500
Subject: [PATCH] manager: allow switchInput on conference

Change-Id: I83e6fe6ff660fb5dc6dc2b834131dcb098d13ade
---
 src/conference.cpp              | 11 ++++++++++-
 src/conference.h                |  6 ++++--
 src/manager.cpp                 | 13 +++++++------
 src/media/video/video_mixer.cpp |  9 +++++++++
 src/media/video/video_mixer.h   |  2 ++
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/conference.cpp b/src/conference.cpp
index e5d519c89d..e9549effe7 100644
--- a/src/conference.cpp
+++ b/src/conference.cpp
@@ -150,10 +150,19 @@ bool Conference::toggleRecording()
     return startRecording;
 }
 
-std::string Conference::getConfID() const {
+const std::string&
+Conference::getConfID() const {
     return id_;
 }
 
+void
+Conference::switchInput(const std::string& input)
+{
+#ifdef ENABLE_VIDEO
+    getVideoMixer()->switchInput(input);
+#endif
+}
+
 #ifdef ENABLE_VIDEO
 std::shared_ptr<video::VideoMixer> Conference::getVideoMixer()
 {
diff --git a/src/conference.h b/src/conference.h
index f4344bb7f4..caebbf7fe5 100644
--- a/src/conference.h
+++ b/src/conference.h
@@ -58,7 +58,7 @@ class Conference : public Recordable {
         /**
          * Return the conference id
          */
-        std::string getConfID() const;
+        const std::string& getConfID() const;
 
         /**
          * Return the current conference state
@@ -104,7 +104,9 @@ class Conference : public Recordable {
         /**
          * Start/stop recording toggle
          */
-        virtual bool toggleRecording();
+        bool toggleRecording() override;
+
+        void switchInput(const std::string& input);
 
 #ifdef ENABLE_VIDEO
         std::shared_ptr<video::VideoMixer> getVideoMixer();
diff --git a/src/manager.cpp b/src/manager.cpp
index 5ec1faa85a..2ed1d8b6dd 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -2236,13 +2236,14 @@ Manager::getCurrentAudioDevicesIndex()
 bool
 Manager::switchInput(const std::string& call_id, const std::string& res)
 {
-    auto call = getCallFromCallID(call_id);
-    if (!call) {
-        JAMI_ERR("Call %s is NULL", call_id.c_str());
-        return false;
+    if (auto conf = getConferenceFromID(call_id)) {
+        conf->switchInput(res);
+        return true;
+    } else if (auto call = getCallFromCallID(call_id)) {
+        call->switchInput(res);
+        return true;
     }
-    call->switchInput(res);
-    return true;
+    return false;
 }
 
 int
diff --git a/src/media/video/video_mixer.cpp b/src/media/video/video_mixer.cpp
index 687fa477c3..b283c847ab 100644
--- a/src/media/video/video_mixer.cpp
+++ b/src/media/video/video_mixer.cpp
@@ -88,6 +88,15 @@ VideoMixer::~VideoMixer()
     loop_.join();
 }
 
+void
+VideoMixer::switchInput(const std::string& input)
+{
+    if (auto local = videoLocal_) {
+        if (auto localInput = std::dynamic_pointer_cast<VideoInput>(local))
+            localInput->switchInput(input);
+    }
+}
+
 void
 VideoMixer::attached(Observable<std::shared_ptr<MediaFrame>>* ob)
 {
diff --git a/src/media/video/video_mixer.h b/src/media/video/video_mixer.h
index db32f777f6..3fd3c8a807 100644
--- a/src/media/video/video_mixer.h
+++ b/src/media/video/video_mixer.h
@@ -54,6 +54,8 @@ public:
     void attached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
     void detached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
 
+    void switchInput(const std::string& input);
+
 private:
     NON_COPYABLE(VideoMixer);
 
-- 
GitLab