forked from lynckia/licode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add layer bitrate calculation handler + Test page (lynckia#790)
- Loading branch information
Showing
10 changed files
with
742 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "rtp/LayerBitrateCalculationHandler.h" | ||
|
||
#include <vector> | ||
|
||
#include "./WebRtcConnection.h" | ||
#include "lib/ClockUtils.h" | ||
|
||
namespace erizo { | ||
|
||
DEFINE_LOGGER(LayerBitrateCalculationHandler, "rtp.LayerBitrateCalculationHandler"); | ||
|
||
LayerBitrateCalculationHandler::LayerBitrateCalculationHandler() : enabled_{true}, | ||
initialized_{false} {} | ||
|
||
void LayerBitrateCalculationHandler::enable() { | ||
enabled_ = true; | ||
} | ||
|
||
void LayerBitrateCalculationHandler::disable() { | ||
enabled_ = false; | ||
} | ||
|
||
void LayerBitrateCalculationHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) { | ||
if (!enabled_ || !initialized_) { | ||
ctx->fireWrite(packet); | ||
return; | ||
} | ||
std::for_each(packet->compatible_spatial_layers.begin(), | ||
packet->compatible_spatial_layers.end(), [this, packet](int &layer_num){ | ||
std::string spatial_layer_name = std::to_string(layer_num); | ||
std::for_each(packet->compatible_temporal_layers.begin(), | ||
packet->compatible_temporal_layers.end(), [this, packet, spatial_layer_name](int &layer_num){ | ||
std::string temporal_layer_name = std::to_string(layer_num); | ||
if (!stats_->getNode()[kQualityLayersStatsKey][spatial_layer_name].hasChild(temporal_layer_name)) { | ||
stats_->getNode()[kQualityLayersStatsKey][spatial_layer_name].insertStat( | ||
temporal_layer_name, MovingIntervalRateStat{kLayerRateStatIntervalSize, | ||
kLayerRateStatIntervals, 8.}); | ||
} else { | ||
stats_->getNode()[kQualityLayersStatsKey][spatial_layer_name][temporal_layer_name]+=packet->length; | ||
} | ||
}); | ||
}); | ||
ctx->fireWrite(packet); | ||
} | ||
|
||
|
||
void LayerBitrateCalculationHandler::notifyUpdate() { | ||
if (initialized_) { | ||
return; | ||
} | ||
|
||
auto pipeline = getContext()->getPipelineShared(); | ||
if (!pipeline) { | ||
return; | ||
} | ||
stats_ = pipeline->getService<Stats>(); | ||
if (!stats_) { | ||
return; | ||
} | ||
initialized_ = true; | ||
} | ||
} // 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,42 @@ | ||
#ifndef ERIZO_SRC_ERIZO_RTP_LAYERBITRATECALCULATIONHANDLER_H_ | ||
#define ERIZO_SRC_ERIZO_RTP_LAYERBITRATECALCULATIONHANDLER_H_ | ||
|
||
|
||
#include "./logger.h" | ||
#include "pipeline/Handler.h" | ||
#include "./Stats.h" | ||
|
||
namespace erizo { | ||
|
||
class WebRtcConnection; | ||
|
||
constexpr duration kLayerRateStatIntervalSize = std::chrono::milliseconds(100); | ||
constexpr uint32_t kLayerRateStatIntervals = 10; | ||
|
||
class LayerBitrateCalculationHandler: public OutboundHandler { | ||
DECLARE_LOGGER(); | ||
|
||
|
||
public: | ||
LayerBitrateCalculationHandler(); | ||
|
||
void enable() override; | ||
void disable() override; | ||
|
||
std::string getName() override { | ||
return "layer_bitrate_calculator"; | ||
} | ||
|
||
void write(Context *ctx, std::shared_ptr<dataPacket> packet) override; | ||
void notifyUpdate() override; | ||
|
||
private: | ||
bool enabled_; | ||
bool initialized_; | ||
std::shared_ptr<Stats> stats_; | ||
const std::string kQualityLayersStatsKey = "qualityLayers"; | ||
}; | ||
} // namespace erizo | ||
|
||
#endif // ERIZO_SRC_ERIZO_RTP_LAYERBITRATECALCULATIONHANDLER_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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
|
||
#include <rtp/LayerBitrateCalculationHandler.h> | ||
|
||
#include "../utils/Mocks.h" | ||
#include "../utils/Tools.h" | ||
#include "../utils/Matchers.h" | ||
|
||
using ::testing::_; | ||
using ::testing::IsNull; | ||
using ::testing::Args; | ||
using ::testing::Return; | ||
using erizo::AUDIO_PACKET; | ||
using erizo::VIDEO_PACKET; | ||
using erizo::Pipeline; | ||
using erizo::LayerBitrateCalculationHandler; | ||
|
||
|
||
class LayerBitrateCalculationHandlerTest : public erizo::HandlerTest { | ||
public: | ||
LayerBitrateCalculationHandlerTest() {} | ||
|
||
protected: | ||
void setHandler() { | ||
layer_bitrate_handler = std::make_shared<LayerBitrateCalculationHandler>(); | ||
pipeline->addBack(layer_bitrate_handler); | ||
} | ||
|
||
std::shared_ptr<LayerBitrateCalculationHandler> layer_bitrate_handler; | ||
}; | ||
|
||
TEST_F(LayerBitrateCalculationHandlerTest, basicBehaviourShouldWritePackets) { | ||
auto packet = erizo::PacketTools::createDataPacket(erizo::kArbitrarySeqNumber, AUDIO_PACKET); | ||
|
||
EXPECT_CALL(*writer.get(), write(_, _)). | ||
With(Args<1>(erizo::RtpHasSequenceNumber(erizo::kArbitrarySeqNumber))).Times(1); | ||
pipeline->write(packet); | ||
} |
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.