-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new algorithm to allocate better bandwidth in Single PC (#1296)
- Loading branch information
Showing
13 changed files
with
729 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
erizo/src/erizo/bandwidth/BandwidthDistributionAlgorithm.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ERIZO_SRC_ERIZO_BANDWIDTH_BANDWIDTHDISTRIBUTIONALGORITHM_H_ | ||
#define ERIZO_SRC_ERIZO_BANDWIDTH_BANDWIDTHDISTRIBUTIONALGORITHM_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
namespace erizo { | ||
|
||
class MediaStream; | ||
class Transport; | ||
|
||
class BandwidthDistributionAlgorithm { | ||
public: | ||
BandwidthDistributionAlgorithm() {} | ||
virtual ~BandwidthDistributionAlgorithm() {} | ||
virtual void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams, | ||
Transport *transport) = 0; | ||
}; | ||
|
||
} // namespace erizo | ||
|
||
#endif // ERIZO_SRC_ERIZO_BANDWIDTH_BANDWIDTHDISTRIBUTIONALGORITHM_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* MaxVideoBWDistributor.cpp | ||
*/ | ||
|
||
#include <algorithm> | ||
|
||
#include "MaxVideoBWDistributor.h" | ||
#include "MediaStream.h" | ||
#include "Transport.h" | ||
#include "rtp/RtpUtils.h" | ||
|
||
namespace erizo { | ||
|
||
void MaxVideoBWDistributor::distribute(uint32_t remb, uint32_t ssrc, | ||
std::vector<std::shared_ptr<MediaStream>> streams, Transport *transport) { | ||
std::sort(streams.begin(), streams.end(), | ||
[](const std::shared_ptr<MediaStream> &i, const std::shared_ptr<MediaStream> &j) { | ||
return i->getMaxVideoBW() < j->getMaxVideoBW(); | ||
}); | ||
|
||
uint8_t remaining_streams = streams.size(); | ||
uint32_t remaining_bitrate = remb; | ||
std::for_each(streams.begin(), streams.end(), | ||
[&remaining_bitrate, &remaining_streams, transport, ssrc](const std::shared_ptr<MediaStream> &stream) { | ||
uint32_t max_bitrate = stream->getMaxVideoBW(); | ||
uint32_t remaining_avg_bitrate = remaining_bitrate / remaining_streams; | ||
uint32_t bitrate = std::min(max_bitrate, remaining_avg_bitrate); | ||
auto generated_remb = RtpUtils::createREMB(ssrc, {stream->getVideoSinkSSRC()}, bitrate); | ||
stream->onTransportData(generated_remb, transport); | ||
remaining_bitrate -= bitrate; | ||
remaining_streams--; | ||
}); | ||
} | ||
|
||
} // namespace erizo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef ERIZO_SRC_ERIZO_BANDWIDTH_MAXVIDEOBWDISTRIBUTOR_H_ | ||
#define ERIZO_SRC_ERIZO_BANDWIDTH_MAXVIDEOBWDISTRIBUTOR_H_ | ||
|
||
#include "bandwidth/BandwidthDistributionAlgorithm.h" | ||
|
||
namespace erizo { | ||
|
||
class MaxVideoBWDistributor : public BandwidthDistributionAlgorithm { | ||
public: | ||
MaxVideoBWDistributor() {} | ||
virtual ~MaxVideoBWDistributor() {} | ||
void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams, | ||
Transport *transport) override; | ||
}; | ||
|
||
} // namespace erizo | ||
|
||
#endif // ERIZO_SRC_ERIZO_BANDWIDTH_MAXVIDEOBWDISTRIBUTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* TargetVideoBWDistributor.cpp | ||
*/ | ||
|
||
#include <algorithm> | ||
|
||
#include "TargetVideoBWDistributor.h" | ||
#include "MediaStream.h" | ||
#include "Transport.h" | ||
#include "rtp/RtpUtils.h" | ||
|
||
namespace erizo { | ||
|
||
void TargetVideoBWDistributor::distribute(uint32_t remb, uint32_t ssrc, | ||
std::vector<std::shared_ptr<MediaStream>> streams, Transport *transport) { | ||
std::sort(streams.begin(), streams.end(), | ||
[this](const std::shared_ptr<MediaStream> &i, const std::shared_ptr<MediaStream> &j) { | ||
return getTargetVideoBW(i) < getTargetVideoBW(j); | ||
}); | ||
uint8_t remaining_streams = streams.size(); | ||
uint32_t remaining_bitrate = remb; | ||
std::for_each(streams.begin(), streams.end(), | ||
[&remaining_bitrate, &remaining_streams, transport, ssrc, this](const std::shared_ptr<MediaStream> &stream) { | ||
uint32_t max_bitrate = stream->getMaxVideoBW(); | ||
|
||
uint32_t target_bitrate = getTargetVideoBW(stream); | ||
|
||
uint32_t remaining_avg_bitrate = remaining_bitrate / remaining_streams; | ||
uint32_t bitrate = std::min(target_bitrate, remaining_avg_bitrate); | ||
uint32_t remb = std::min(max_bitrate, remaining_avg_bitrate); | ||
auto generated_remb = RtpUtils::createREMB(ssrc, {stream->getVideoSinkSSRC()}, remb); | ||
stream->onTransportData(generated_remb, transport); | ||
|
||
remaining_bitrate -= bitrate; | ||
remaining_streams--; | ||
}); | ||
} | ||
|
||
uint32_t TargetVideoBWDistributor::getTargetVideoBW(const std::shared_ptr<MediaStream> &stream) { | ||
bool slide_show_mode = stream->isSlideShowModeEnabled(); | ||
bool is_simulcast = stream->isSimulcast(); | ||
uint32_t bitrate_sent = stream->getBitrateSent(); | ||
uint32_t max_bitrate = stream->getMaxVideoBW(); | ||
|
||
uint32_t target_bitrate = max_bitrate; | ||
if (is_simulcast) { | ||
target_bitrate = std::min(stream->getBitrateFromMaxQualityLayer(), max_bitrate); | ||
} | ||
if (slide_show_mode) { | ||
target_bitrate = std::min(bitrate_sent, max_bitrate); | ||
} | ||
return target_bitrate; | ||
} | ||
|
||
} // namespace erizo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ERIZO_SRC_ERIZO_BANDWIDTH_TARGETVIDEOBWDISTRIBUTOR_H_ | ||
#define ERIZO_SRC_ERIZO_BANDWIDTH_TARGETVIDEOBWDISTRIBUTOR_H_ | ||
|
||
#include "bandwidth/BandwidthDistributionAlgorithm.h" | ||
|
||
namespace erizo { | ||
|
||
class MediaStream; | ||
|
||
class TargetVideoBWDistributor : public BandwidthDistributionAlgorithm { | ||
public: | ||
TargetVideoBWDistributor() {} | ||
virtual ~TargetVideoBWDistributor() {} | ||
void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams, | ||
Transport *transport) override; | ||
private: | ||
uint32_t getTargetVideoBW(const std::shared_ptr<MediaStream> &stream); | ||
}; | ||
|
||
} // namespace erizo | ||
|
||
#endif // ERIZO_SRC_ERIZO_BANDWIDTH_TARGETVIDEOBWDISTRIBUTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.