From 4337438d4f7a269ccc85d24a7fbffdfc92777d01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 20 Aug 2020 14:48:00 -0400
Subject: [PATCH] video_mixer: fix setActiveParticipant(nullptr)

setActiveParticipant(nullptr) is the only way for now to set the active
participant to the local video. But the local video is not necessarely
the first one. So, sometimes, setActiveParticipant(nullptr) was choosing
another active participant instead the local one.

Change-Id: I868770beb042977ce5ddd0f2dce00451cac04323
---
 src/media/video/video_mixer.cpp | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/media/video/video_mixer.cpp b/src/media/video/video_mixer.cpp
index e470783b8b..92080854ca 100644
--- a/src/media/video/video_mixer.cpp
+++ b/src/media/video/video_mixer.cpp
@@ -132,7 +132,7 @@ VideoMixer::stopInput()
 void
 VideoMixer::setActiveParticipant(Observable<std::shared_ptr<MediaFrame>>* ob)
 {
-    activeSource_ = ob;
+    activeSource_ = ob ? ob : videoLocal_.get();
     layoutUpdated_ += 1;
 }
 
@@ -157,7 +157,7 @@ VideoMixer::detached(Observable<std::shared_ptr<MediaFrame>>* ob)
             // Handle the case where the current shown source leave the conference
             if (activeSource_ == ob) {
                 currentLayout_ = Layout::GRID;
-                activeSource_ = nullptr;
+                activeSource_ = videoLocal_.get();
             }
             sources_.remove(x);
             layoutUpdated_ += 1;
@@ -219,8 +219,7 @@ VideoMixer::process()
                 return;
 
             if (currentLayout_ != Layout::ONE_BIG or activeSource_ == x->source
-                or (not activeSource_
-                    and not activeFound) /* By default ONE_BIG will show the first source */) {
+                or not activeFound /* By default ONE_BIG will show the first source */) {
                 // make rendered frame temporarily unavailable for update()
                 // to avoid concurrent access.
                 std::unique_ptr<VideoFrame> input;
@@ -231,9 +230,6 @@ VideoMixer::process()
                     wantedIndex = 0;
                     activeFound = true;
                 } else if (currentLayout_ == Layout::ONE_BIG_WITH_SMALL) {
-                    if (!activeSource_ && i == 0) {
-                        activeFound = true;
-                    }
                     if (activeSource_ == x->source) {
                         wantedIndex = 0;
                         activeFound = true;
-- 
GitLab