diff --git a/src/conference.cpp b/src/conference.cpp index 0da4466d4f50b5939f46a702ddc673bd06e2e710..2f5697a6b2818a7a4b8a4684d53e52f910986c10 100644 --- a/src/conference.cpp +++ b/src/conference.cpp @@ -109,6 +109,10 @@ Conference::Conference() isModeratorMuted, isModerator}); } + if (auto videoMixer = shared->getVideoMixer()) { + newInfo.h = videoMixer->getHeight(); + newInfo.w = videoMixer->getWidth(); + } lk.unlock(); // Handle participants not present in the video mixer for (const auto& subCall : subCalls) { @@ -369,11 +373,13 @@ ConfInfo::toVectorMapStringString() const std::string ConfInfo::toString() const { - Json::Value jsonArray = {}; + Json::Value val = {}; for (const auto& info : *this) { - jsonArray.append(info.toJson()); + val["p"].append(info.toJson()); } - return Json::writeString(Json::StreamWriterBuilder {}, jsonArray); + val["w"] = w; + val["h"] = h; + return Json::writeString(Json::StreamWriterBuilder {}, val); } void @@ -977,17 +983,19 @@ Conference::muteLocalHost(bool is_muted, const std::string& mediaType) } void -Conference::resizeRemoteParticipant(const std::string& peerURI, ParticipantInfo& remoteCell) +Conference::resizeRemoteParticipants(ConfInfo& confInfo, std::string_view peerURI) { - int remoteFrameHeight {0}; - int remoteFrameWidth {0}; - ParticipantInfo localCell; + int remoteFrameHeight = confInfo.h; + int remoteFrameWidth = confInfo.w; - // get the size of the remote frame - if (auto call = std::dynamic_pointer_cast<SIPCall>( - getCallFromPeerID(string_remove_suffix(peerURI, '@')))) { - remoteFrameHeight = call->getVideoRtp().getVideoReceive()->getHeight(); - remoteFrameWidth = call->getVideoRtp().getVideoReceive()->getWidth(); + if (remoteFrameHeight == 0 or remoteFrameWidth == 0) { + // get the size of the remote frame from receiveThread + // if the one from confInfo is empty + if (auto call = std::dynamic_pointer_cast<SIPCall>( + getCallFromPeerID(string_remove_suffix(peerURI, '@')))) { + remoteFrameHeight = call->getVideoRtp().getVideoReceive()->getHeight(); + remoteFrameWidth = call->getVideoRtp().getVideoReceive()->getWidth(); + } } if (remoteFrameHeight == 0 or remoteFrameWidth == 0) { @@ -996,6 +1004,7 @@ Conference::resizeRemoteParticipant(const std::string& peerURI, ParticipantInfo& } // get the size of the local frame + ParticipantInfo localCell; for (const auto& p : confInfo_) { if (p.uri == peerURI) { localCell = p; @@ -1003,23 +1012,16 @@ Conference::resizeRemoteParticipant(const std::string& peerURI, ParticipantInfo& } } - const float zoomX = (float) remoteFrameWidth / localCell.w; - const float zoomY = (float) remoteFrameHeight / localCell.h; + // Do the resize for each remote participant + for (auto& remoteCell : confInfo) { + const float zoomX = (float) remoteFrameWidth / localCell.w; + const float zoomY = (float) remoteFrameHeight / localCell.h; - remoteCell.x = remoteCell.x / zoomX + localCell.x; - remoteCell.y = remoteCell.y / zoomY + localCell.y; - remoteCell.w = remoteCell.w / zoomX; - remoteCell.h = remoteCell.h / zoomY; -} - -std::string -Conference::confInfo2str(const ConfInfo& confInfo) -{ - Json::Value jsonArray = {}; - for (const auto& info : confInfo) { - jsonArray.append(info.toJson()); + remoteCell.x = remoteCell.x / zoomX + localCell.x; + remoteCell.y = remoteCell.y / zoomY + localCell.y; + remoteCell.w = remoteCell.w / zoomX; + remoteCell.h = remoteCell.h / zoomY; } - return Json::writeString(Json::StreamWriterBuilder {}, jsonArray); } void @@ -1031,9 +1033,7 @@ Conference::mergeConfInfo(ConfInfo& newInfo, const std::string& peerURI) return; } - for (auto& partInfo : newInfo) { - resizeRemoteParticipant(peerURI, partInfo); - } + resizeRemoteParticipants(newInfo, peerURI); bool updateNeeded = false; auto it = remoteHosts_.find(peerURI); diff --git a/src/conference.h b/src/conference.h index a063bfa7050df2fa80b1fdd0426d269e5a7ee2c8..6c3bdaab45c162e0921083538e539f1dd1518d52 100644 --- a/src/conference.h +++ b/src/conference.h @@ -135,6 +135,9 @@ struct ConfInfo : public std::vector<ParticipantInfo> friend bool operator==(const ConfInfo& c1, const ConfInfo& c2) { + if (c1.h != c2.h or c1.w != c2.w) + return false; + for (auto& p1 : c1) { auto it = std::find_if(c2.begin(), c2.end(), [p1](const ParticipantInfo& p2) { return p1 == p2; @@ -289,7 +292,6 @@ public: void updateMuted(); void muteLocalHost(bool is_muted, const std::string& mediaType); bool isRemoteParticipant(const std::string& uri); - void resizeRemoteParticipant(const std::string& peerURI, ParticipantInfo& remoteCell); void mergeConfInfo(ConfInfo& newInfo, const std::string& peerURI); private: @@ -338,7 +340,7 @@ private: bool localModAdded_ {false}; std::map<std::string, ConfInfo> remoteHosts_; - std::string confInfo2str(const ConfInfo& confInfo); + void resizeRemoteParticipants(ConfInfo& confInfo, std::string_view peerURI); std::string_view findHostforRemoteParticipant(std::string_view uri); std::shared_ptr<Call> getCallFromPeerID(std::string_view peerID);