From 6f64b069a1c95a15b744d4044ad3d8032147439f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 21 Jul 2022 14:14:44 -0400
Subject: [PATCH] conference: sendConfInfo without camera

The video mixer was only initialized if the host got a camera or
if calls got some video. Now, the conf infos are sent if all calls
are audio only and if the host has no camera.

Change-Id: I69c9e773134b6ab4aab3e9462128ea841a09539e
---
 src/conference.cpp              |  7 +++----
 src/media/video/video_mixer.cpp |  6 +++---
 src/media/video/video_mixer.h   | 17 +++++++++--------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/conference.cpp b/src/conference.cpp
index 87d4303d08..b6d6812871 100644
--- a/src/conference.cpp
+++ b/src/conference.cpp
@@ -91,10 +91,9 @@ Conference::Conference(const std::shared_ptr<Account>& account)
         return attr.type_ == MediaType::MEDIA_VIDEO;
     });
     // We are done if the video is disabled.
-    if (not videoEnabled_ || itVideo == hostSources_.end())
-        return;
-
-    videoMixer_ = std::make_shared<video::VideoMixer>(id_, itVideo->sourceUri_);
+    auto hasVideo = videoEnabled_ && itVideo != hostSources_.end();
+    auto source = hasVideo ? itVideo->sourceUri_ : "";
+    videoMixer_ = std::make_shared<video::VideoMixer>(id_, source, hasVideo);
     videoMixer_->setOnSourcesUpdated([this](std::vector<video::SourceInfo>&& infos) {
         runOnMainThread([w = weak(), infos = std::move(infos)] {
             auto shared = w.lock();
diff --git a/src/media/video/video_mixer.cpp b/src/media/video/video_mixer.cpp
index 76f3b16583..78f47c1005 100644
--- a/src/media/video/video_mixer.cpp
+++ b/src/media/video/video_mixer.cpp
@@ -81,14 +81,14 @@ private:
 static constexpr const auto MIXER_FRAMERATE = 30;
 static constexpr const auto FRAME_DURATION = std::chrono::duration<double>(1. / MIXER_FRAMERATE);
 
-VideoMixer::VideoMixer(const std::string& id, const std::string& localInput)
+VideoMixer::VideoMixer(const std::string& id, const std::string& localInput, bool attachHost)
     : VideoGenerator::VideoGenerator()
     , id_(id)
     , sink_(Manager::instance().createSinkClient(id, true))
     , loop_([] { return true; }, std::bind(&VideoMixer::process, this), [] {})
 {
     // Local video camera is the main participant
-    if (not localInput.empty()) {
+    if (not localInput.empty() && attachHost) {
         auto videoInput = getVideoInput(localInput);
         localInputs_.emplace_back(videoInput);
         attachVideo(videoInput.get(),
@@ -300,7 +300,7 @@ VideoMixer::process()
         int i = 0;
         bool activeFound = false;
         bool needsUpdate = layoutUpdated_ > 0;
-        bool successfullyRendered = false;
+        bool successfullyRendered = audioOnlySources_.size() != 0 && sources_.size() == 0;
         std::vector<SourceInfo> sourcesInfo;
         sourcesInfo.reserve(sources_.size() + audioOnlySources_.size());
         // add all audioonlysources
diff --git a/src/media/video/video_mixer.h b/src/media/video/video_mixer.h
index 9dcbce8be4..57e73713e7 100644
--- a/src/media/video/video_mixer.h
+++ b/src/media/video/video_mixer.h
@@ -37,7 +37,8 @@ namespace video {
 
 class SinkClient;
 
-struct StreamInfo {
+struct StreamInfo
+{
     std::string callId;
     std::string streamId;
 };
@@ -60,7 +61,7 @@ enum class Layout { GRID, ONE_BIG_WITH_SMALL, ONE_BIG };
 class VideoMixer : public VideoGenerator, public VideoFramePassiveReader
 {
 public:
-    VideoMixer(const std::string& id, const std::string& localInput = {});
+    VideoMixer(const std::string& id, const std::string& localInput = {}, bool attachHost = true);
     ~VideoMixer();
 
     void setParameters(int width, int height, AVPixelFormat format = AV_PIX_FMT_YUV422P);
@@ -93,10 +94,7 @@ public:
         updateLayout();
     }
 
-    bool verifyActive(const std::string& id)
-    {
-        return activeStream_ == id;
-    }
+    bool verifyActive(const std::string& id) { return activeStream_ == id; }
 
     void setVideoLayout(Layout newLayout)
     {
@@ -112,7 +110,8 @@ public:
 
     MediaStream getStream(const std::string& name) const;
 
-    std::shared_ptr<VideoFrameActiveWriter> getVideoLocal() const {
+    std::shared_ptr<VideoFrameActiveWriter> getVideoLocal() const
+    {
         if (!localInputs_.empty())
             return *localInputs_.begin();
         return {};
@@ -139,7 +138,9 @@ public:
         }
     }
 
-    void attachVideo(Observable<std::shared_ptr<MediaFrame>>* frame, const std::string& callId, const std::string& streamId);
+    void attachVideo(Observable<std::shared_ptr<MediaFrame>>* frame,
+                     const std::string& callId,
+                     const std::string& streamId);
     void detachVideo(Observable<std::shared_ptr<MediaFrame>>* frame);
 
     StreamInfo streamInfo(Observable<std::shared_ptr<MediaFrame>>* frame) const
-- 
GitLab