Skip to content

Commit

Permalink
MEDIA-3445: Reduce memory consumption for audio only conferences (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoMDomingues authored Feb 19, 2025
1 parent 5e4d3a5 commit c9e037a
Show file tree
Hide file tree
Showing 58 changed files with 1,224 additions and 364 deletions.
3 changes: 1 addition & 2 deletions .cppcheck-suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ uninitStructMember:external/http.h
selfInitialization:bridge/AudioStream.h
selfInitialization:bridge/DataStream.h
selfInitialization:bridge/VideoStream.h
uninitvar:test/bridge/MixerTest.cpp:88
nullPointer:test/utils/LogSpamTest.cpp:125
uninitvar:test/bridge/MixerTest.cpp:89
uninitvar:test/bridge/MixerTest.cpp:89
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ set(TEST_FILES
test/codec/AudioProcessingTest.cpp
test/concurrency/MpscTest.cpp
test/concurrency/MpmcMapTest.cpp
test/concurrency/MpmcQueueTest.cpp
test/concurrency/LockFreeListTest.cpp
test/bwe/MatrixTests.cpp
test/bwe/RateControllerTest.cpp
Expand All @@ -626,6 +627,7 @@ set(TEST_FILES
test/codec/H264HeaderTest.cpp
test/codec/Vp8HeaderTest.cpp
test/bridge/ActiveMediaListTest.cpp
test/bridge/ApiRequestHandlerTest.cpp
test/bridge/BarbellMessagesTest.cpp
test/rtp/RtcpFeedbackTest.cpp
test/bridge/PacketCacheTest.cpp
Expand Down
1 change: 1 addition & 0 deletions api/AllocateConference.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct AllocateConference
{
utils::Optional<uint32_t> lastN;
bool useGlobalPort = true;
bool enableVideo = true;
bridge::VideoCodecSpec videoCodecs = bridge::VideoCodecSpec::makeVp8();
};

Expand Down
46 changes: 25 additions & 21 deletions api/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,35 +291,39 @@ nlohmann::json generateAllocateBarbellResponse(const BarbellDescription& channel
responseJson["audio"] = audioJson;

const auto& video = channelsDescription.video;
nlohmann::json videoJson;

videoJson["streams"] = nlohmann::json::array();
for (const auto& stream : video.streams)
if (!video.streams.empty())
{
nlohmann::json streamJson;
streamJson["sources"] = nlohmann::json::array();
for (const auto level : stream.sources)
nlohmann::json videoJson;
videoJson["streams"] = nlohmann::json::array();

for (const auto& stream : video.streams)
{
nlohmann::json sourceJson;
sourceJson["main"] = level.main;
if (level.feedback != 0)
nlohmann::json streamJson;
streamJson["sources"] = nlohmann::json::array();
for (const auto level : stream.sources)
{
sourceJson["feedback"] = level.feedback;
nlohmann::json sourceJson;
sourceJson["main"] = level.main;
if (level.feedback != 0)
{
sourceJson["feedback"] = level.feedback;
}
streamJson["sources"].push_back(sourceJson);
}
streamJson["sources"].push_back(sourceJson);
}
streamJson["content"] = stream.content;
videoJson["streams"].push_back(streamJson);
streamJson["content"] = stream.content;
videoJson["streams"].push_back(streamJson);

videoJson["payload-types"] = nlohmann::json::array();
for (const auto& payloadType : video.payloadTypes)
{
videoJson["payload-types"].push_back(generatePayloadType(payloadType));
}
videoJson["payload-types"] = nlohmann::json::array();
for (const auto& payloadType : video.payloadTypes)
{
videoJson["payload-types"].push_back(generatePayloadType(payloadType));
}

videoJson["rtp-hdrexts"] = generateRtpHeaderExtensions(video.rtpHeaderExtensions);
videoJson["rtp-hdrexts"] = generateRtpHeaderExtensions(video.rtpHeaderExtensions);
}

responseJson["video"] = videoJson;
responseJson["video"] = std::move(videoJson);
}

const auto& data = channelsDescription.data;
Expand Down
5 changes: 3 additions & 2 deletions api/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ AllocateConference parseAllocateConference(const nlohmann::json& data)
}
}
setIfExistsOrDefault(allocateConference.useGlobalPort, data, "global-port", true);
setIfExistsOrDefault(allocateConference.enableVideo, data, "enable-video", true);
auto it = data.find("video-codecs");
if (it != data.end())
{
Expand Down Expand Up @@ -624,7 +625,7 @@ BarbellDescription parsePatchBarbell(const nlohmann::json& data, const std::stri
}
}

barbellDescription.audio = audioChannel;
barbellDescription.audio = std::move(audioChannel);
}

if (data.find("video") != data.end())
Expand Down Expand Up @@ -660,7 +661,7 @@ BarbellDescription parsePatchBarbell(const nlohmann::json& data, const std::stri
videoStream.content = stream["content"];
}

barbellDescription.video = videoChannel;
barbellDescription.video = std::move(videoChannel);
}

const auto& dataJson = getJsonFieldOrThrow(data, "data");
Expand Down
13 changes: 8 additions & 5 deletions bridge/LegacyApiRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,12 @@ httpd::Response LegacyApiRequestHandler::createConference(const httpd::Request&
}

const auto lastNItr = requestBodyJson.find("last-n");
auto mixer = lastNItr != requestBodyJson.end() && lastNItr->is_number() && lastNItr->get<int32_t>() > 0
? _mixerManager.create(lastNItr->get<uint32_t>(), true)
: _mixerManager.create(true);
const auto optionalLastN =
lastNItr != requestBodyJson.end() && lastNItr->is_number() && lastNItr->get<int32_t>() > 0
? utils::Optional<uint32_t>(lastNItr->get<uint32_t>())
: utils::NullOpt;

auto mixer = _mixerManager.create(optionalLastN, true, true);

if (!mixer)
{
Expand Down Expand Up @@ -968,7 +971,7 @@ bool LegacyApiRequestHandler::allocateChannel(const std::string& contentName,

if (useBundling)
{
mixer.addBundleTransportIfNeeded(endpointId, iceRole.get());
mixer.addBundleTransportIfNeeded(endpointId, iceRole.get(), true);
if (contentType == ContentType::Audio)
{
if (!mixer.addBundledAudioStream(channelId, endpointId, channel.getMediaMode()))
Expand Down Expand Up @@ -1072,7 +1075,7 @@ bool LegacyApiRequestHandler::allocateSctpConnection(const std::string& conferen
{
iceRole.set(ice::IceRole::CONTROLLING);
}
mixer.addBundleTransportIfNeeded(endpointId, iceRole.get());
mixer.addBundleTransportIfNeeded(endpointId, iceRole.get(), true);
mixer.addBundledDataStream(streamId, endpointId);

uint32_t totalSleepTimeMs = 0;
Expand Down
Loading

0 comments on commit c9e037a

Please sign in to comment.