Skip to content

Commit aecc3e6

Browse files
authored
MEDIA-2252: fix removing neighbours (finos#353)
1 parent 8538421 commit aecc3e6

File tree

5 files changed

+123
-6
lines changed

5 files changed

+123
-6
lines changed

Diff for: api/EndpointDescription.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct EndpointDescription
1515
utils::Optional<api::Video> video;
1616
utils::Optional<api::Data> data;
1717

18-
std::vector<std::string> neighbours; // group(s) that should not be heard
18+
utils::Optional<std::vector<std::string>> neighbours; // group(s) that should not be heard
1919
};
2020

2121
} // namespace api

Diff for: api/Parser.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ EndpointDescription parsePatchEndpoint(const nlohmann::json& data, const std::st
422422

423423
if (data.find("neighbours") != data.end())
424424
{
425+
std::vector<std::string> neighbours;
425426
for (auto& group : requiredJsonArray(data["neighbours"], "groups"))
426427
{
427-
endpointDescription.neighbours.push_back(group);
428+
neighbours.push_back(group);
428429
}
430+
endpointDescription.neighbours.set(neighbours);
429431
}
430432
return endpointDescription;
431433
}

Diff for: bridge/endpointActions/ConferenceActions.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,12 @@ void configureAudioEndpoint(const api::EndpointDescription& endpointDescription,
533533
remoteSsrc.set(audio.ssrcs.front());
534534
}
535535

536-
auto neighbours = convertGroupIds(endpointDescription.neighbours);
536+
std::vector<uint32_t> neighbours;
537+
if (endpointDescription.neighbours.isSet())
538+
{
539+
neighbours = convertGroupIds(endpointDescription.neighbours.get());
540+
}
541+
537542
if (!mixer.configureAudioStream(endpointId, rtpMap, remoteSsrc, neighbours))
538543
{
539544
throw httpd::RequestErrorException(httpd::StatusCode::BAD_REQUEST,
@@ -836,7 +841,7 @@ httpd::Response reconfigureEndpoint(ActionContext* context,
836841

837842
const bool isAudioSet = endpointDescription.audio.isSet();
838843
const bool isVideoSet = endpointDescription.video.isSet();
839-
const bool isNeighboursSet = !endpointDescription.neighbours.empty();
844+
const bool isNeighboursSet = endpointDescription.neighbours.isSet();
840845

841846
if (isAudioSet && !mixer->isAudioStreamConfigured(endpointId))
842847
{
@@ -874,7 +879,7 @@ httpd::Response reconfigureEndpoint(ActionContext* context,
874879

875880
if (isNeighboursSet)
876881
{
877-
auto neighbours = convertGroupIds(endpointDescription.neighbours);
882+
auto neighbours = convertGroupIds(endpointDescription.neighbours.get());
878883
if (!mixer->reconfigureAudioStreamNeighbours(endpointId, neighbours))
879884
{
880885
throw httpd::RequestErrorException(httpd::StatusCode::INTERNAL_SERVER_ERROR,

Diff for: bridge/engine/EngineMixerAudio.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ void EngineMixer::reconfigureNeighbours(const transport::RtcTransport& transport
181181
if (neighbourIt != _neighbourMemberships.end())
182182
{
183183
auto& neighbourList = neighbourIt->second.memberships;
184+
neighbourList.clear();
184185
for (auto& it : engineAudioStream->neighbours)
185186
{
186187
neighbourList.push_back(it.first);

Diff for: test/integration/ConfIntegrationTest.cpp

+110-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,116 @@ TEST_F(IntegrationTest, neighbours)
723723
});
724724
}
725725

726-
TEST_F(IntegrationTest, dynamicNeighbours)
726+
TEST_F(IntegrationTest, dynamicNeighbours_removeNeighbours)
727+
{
728+
runTestInThread(expectedTestThreadCount(1), [this]() {
729+
_config.readFromString(_defaultSmbConfig);
730+
731+
initBridge(_config);
732+
const auto baseUrl = "http://127.0.0.1:8080";
733+
734+
GroupCall<SfuClient<Channel>> group(_httpd,
735+
_instanceCounter,
736+
*_mainPoolAllocator,
737+
_audioAllocator,
738+
*_clientTransportFactory,
739+
*_publicTransportFactory,
740+
*_sslDtls,
741+
4);
742+
743+
Conference conf(_httpd);
744+
745+
ScopedFinalize finalize(std::bind(&IntegrationTest::finalizeSimulation, this));
746+
startSimulation();
747+
748+
group.startConference(conf, baseUrl);
749+
750+
std::string neighbours[] = {"gid1"};
751+
752+
CallConfigBuilder cfgBuilder(conf.getId());
753+
cfgBuilder.url(baseUrl).withOpus().withVideo();
754+
755+
CallConfigBuilder cfgNeighbours(cfgBuilder);
756+
cfgNeighbours.neighbours(utils::Span<std::string>(neighbours));
757+
758+
group.clients[0]->initiateCall(cfgBuilder.build());
759+
group.clients[1]->joinCall(cfgNeighbours.build());
760+
group.clients[2]->joinCall(cfgNeighbours.build());
761+
group.clients[3]->joinCall(cfgNeighbours.mixed().build());
762+
763+
// 600, 1300, 2100, 3200
764+
ASSERT_TRUE(group.connectAll(utils::Time::sec * _clientsConnectionTimeout));
765+
766+
nlohmann::json responseBody;
767+
const auto conferenceId = conf.getId();
768+
769+
for (int i = 1; i < 4; i++)
770+
{
771+
auto endpointId = group.clients[i]->getEndpointId();
772+
773+
nlohmann::json body = {{"action", "reconfigure"}};
774+
body["neighbours"] = {{"groups", nlohmann::json::array()}};
775+
776+
auto neighboursSet = emulator::awaitResponse<HttpPutRequest>(_httpd,
777+
std::string(baseUrl) + "/conferences/" + conferenceId + "/" + endpointId,
778+
body.dump(),
779+
1.5 * utils::Time::sec,
780+
responseBody);
781+
EXPECT_TRUE(neighboursSet);
782+
}
783+
784+
make5secCallWithDefaultAudioProfile(group);
785+
786+
auto statsSuccess = emulator::awaitResponse<HttpGetRequest>(_httpd,
787+
std::string(baseUrl) + "/stats",
788+
1500 * utils::Time::ms,
789+
responseBody);
790+
EXPECT_TRUE(statsSuccess);
791+
792+
auto confRequest = emulator::awaitResponse<HttpGetRequest>(_httpd,
793+
std::string(baseUrl) + "/conferences",
794+
1500 * utils::Time::ms,
795+
responseBody);
796+
EXPECT_TRUE(confRequest);
797+
798+
group.stopTransports();
799+
800+
group.awaitPendingJobs(utils::Time::sec * 4);
801+
finalizeSimulation();
802+
803+
const size_t chMixed[] = {0, 0, 0, 3};
804+
AudioAnalysisData results[4];
805+
for (size_t id = 0; id < 4; ++id)
806+
{
807+
results[id] = analyzeRecording<SfuClient<Channel>>(group.clients[id].get(), 5, true, chMixed[id]);
808+
809+
std::unordered_map<uint32_t, transport::ReportSummary> transportSummary;
810+
std::string clientName = "client_" + std::to_string(id);
811+
group.clients[id]->getReportSummary(transportSummary);
812+
logTransportSummary(clientName.c_str(), transportSummary);
813+
814+
logVideoSent(clientName.c_str(), *group.clients[id]);
815+
logVideoReceive(clientName.c_str(), *group.clients[id]);
816+
}
817+
818+
EXPECT_EQ(results[0].audioSsrcCount, 3u);
819+
EXPECT_EQ(results[1].audioSsrcCount, 3u);
820+
EXPECT_EQ(results[2].audioSsrcCount, 3u);
821+
EXPECT_EQ(results[3].audioSsrcCount, 1u);
822+
823+
EXPECT_EQ(results[0].dominantFrequencies.size(), 3);
824+
EXPECT_EQ(results[1].dominantFrequencies.size(), 3);
825+
EXPECT_EQ(results[2].dominantFrequencies.size(), 3);
826+
EXPECT_EQ(results[3].dominantFrequencies.size(), 3);
827+
828+
if (results[3].dominantFrequencies.size() > 0)
829+
{
830+
EXPECT_NEAR(results[3].dominantFrequencies[0], 600.0, 50.0);
831+
}
832+
});
833+
}
834+
835+
TEST_F(IntegrationTest, dynamicNeighbours_addNeighbours)
727836
{
728837
runTestInThread(expectedTestThreadCount(1), [this]() {
729838
_config.readFromString(_defaultSmbConfig);

0 commit comments

Comments
 (0)