From 3df31d224fe8f645bb862d2635ab7cd7f6f93e85 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Mon, 10 May 2021 17:31:42 -0400
Subject: [PATCH] conference: fix audio only call for conference

Change-Id: I4ac35628dff7e8c5a686a184e00228cd2c61a134
---
 src/sip/sipcall.cpp | 46 ++++++++++++++++++++++++++++++++++++++++-----
 src/sip/sipcall.h   | 11 ++---------
 2 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp
index 141d296ff8..771db4c2e1 100644
--- a/src/sip/sipcall.cpp
+++ b/src/sip/sipcall.cpp
@@ -1593,8 +1593,6 @@ SIPCall::initMediaStreams(const std::vector<MediaAttribute>& mediaAttrList)
                  stream.mediaAttribute_->toString(true).c_str());
     }
 
-    assert(rtpStreams_.size() == mediaAttrList.size());
-
     JAMI_DBG("[call:%s] Created %lu Media streams", getCallId().c_str(), rtpStreams_.size());
 
     return rtpStreams_.size();
@@ -2318,10 +2316,20 @@ SIPCall::enterConference(const std::string& confId)
         JAMI_ERR("Unknown conference [%s]", confId.c_str());
         return;
     }
-    auto const& videoRtp = getVideoRtp();
-    if (videoRtp)
-        videoRtp->enterConference(conf.get());
+
+    auto videoRtp = getVideoRtp();
+    if (not videoRtp) {
+        // In conference, we need to have a video RTP session even
+        // if it's an audio only call
+        videoRtp = addDummyVideoRtpSession();
+        if (not videoRtp) {
+            throw std::runtime_error("Failed to create dummy RTP video session");
+        }
+    }
+
+    videoRtp->enterConference(conf.get());
 #endif
+
 #ifdef ENABLE_PLUGIN
     clearCallAVStreams();
 #endif
@@ -2340,6 +2348,34 @@ SIPCall::exitConference()
 #endif
 }
 
+std::shared_ptr<Observable<std::shared_ptr<MediaFrame>>>
+SIPCall::getReceiveVideoFrameActiveWriter()
+{
+#ifdef ENABLE_VIDEO
+    auto videoRtp = getVideoRtp();
+    if (videoRtp)
+        return videoRtp->getReceiveVideoFrameActiveWriter();
+#endif
+
+    return {};
+}
+
+std::shared_ptr<video::VideoRtpSession>
+SIPCall::addDummyVideoRtpSession()
+{
+#ifdef ENABLE_VIDEO
+    MediaAttribute mediaAttr(MediaType::MEDIA_VIDEO, true, true, false, "", "dummy video session");
+    addMediaStream(mediaAttr);
+    auto& stream = rtpStreams_.back();
+    createRtpSession(stream);
+    if (stream.rtpSession_) {
+        return std::dynamic_pointer_cast<video::VideoRtpSession>(stream.rtpSession_);
+    }
+#endif
+
+    return {};
+}
+
 std::shared_ptr<AudioRtpSession>
 SIPCall::getAudioRtp() const
 {
diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h
index a475a8a55c..b0a77b7f70 100644
--- a/src/sip/sipcall.h
+++ b/src/sip/sipcall.h
@@ -151,15 +151,7 @@ public:
     void enterConference(const std::string& confId) override;
     void exitConference() override;
     std::shared_ptr<Observable<std::shared_ptr<MediaFrame>>> getReceiveVideoFrameActiveWriter()
-        override
-    {
-        auto const& videoRtp = getVideoRtp();
-        if (videoRtp)
-            return videoRtp->getReceiveVideoFrameActiveWriter();
-
-        return nullptr;
-    }
-
+        override;
     bool hasVideo() const override;
     bool isAudioMuted() const override;
     bool isVideoMuted() const override;
@@ -257,6 +249,7 @@ public:
      * Returns a pointer to the VideoRtp object
      */
     std::shared_ptr<video::VideoRtpSession> getVideoRtp() const;
+    std::shared_ptr<video::VideoRtpSession> addDummyVideoRtpSession();
 #endif
 
     void setSecure(bool sec);
-- 
GitLab