From 86a2a4d63a8938593127b6998288e668c250656a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 13 Jul 2021 20:12:37 +0300 Subject: [PATCH] Count unique video senders in limit. --- .../calls/group/calls_group_call.cpp | 26 +++++++++++++++++-- .../calls/group/calls_group_call.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index e13b853d07..9b9e9a5ad4 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -1956,13 +1956,35 @@ void GroupCall::setupMediaDevices() { }, _lifetime); } +int GroupCall::activeVideoSendersCount() const { + auto result = 0; + for (const auto &[endpoint, track] : _activeVideoTracks) { + if (endpoint.type == VideoEndpointType::Camera) { + ++result; + } else { + auto sharesCameraToo = false; + for (const auto &[other, _] : _activeVideoTracks) { + if (other.type == VideoEndpointType::Camera + && other.peer == endpoint.peer) { + sharesCameraToo = true; + break; + } + } + if (!sharesCameraToo) { + ++result; + } + } + } + return result; +} + bool GroupCall::emitShareCameraError() { const auto emitError = [=](Error error) { emitShareCameraError(error); return true; }; if (const auto real = lookupReal() - ; real && _activeVideoTracks.size() >= real->unmutedVideoLimit()) { + ; real && activeVideoSendersCount() >= real->unmutedVideoLimit()) { return emitError(Error::DisabledNoCamera); } else if (!videoIsWorking()) { return emitError(Error::DisabledNoCamera); @@ -1989,7 +2011,7 @@ bool GroupCall::emitShareScreenError() { return true; }; if (const auto real = lookupReal() - ; real && _activeVideoTracks.size() >= real->unmutedVideoLimit()) { + ; real && activeVideoSendersCount() >= real->unmutedVideoLimit()) { return emitError(Error::DisabledNoScreen); } else if (!videoIsWorking()) { return emitError(Error::DisabledNoScreen); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 4d23110c53..a4a06923b0 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -551,6 +551,8 @@ private: void markTrackPaused(const VideoEndpoint &endpoint, bool paused); void markTrackShown(const VideoEndpoint &endpoint, bool shown); + [[nodiscard]] int activeVideoSendersCount() const; + [[nodiscard]] MTPInputGroupCall inputCall() const; const not_null _delegate;