Reland "Use the factory instead of using the builtin code path in VideoCodecInitializer"

Compared the original CL: https://webrtc-review.googlesource.com/c/src/+/94782

This new CL added backward compatible functions to WebRtcMediaEngineFactory so that internal projects will not be broken.

Because of that, now we can revert all the changes to SDK and PeerConnection and do it in following CLs. This makes this CL cleaner.

One temporary disadvantage of this is the media engine now need to take a dependency onto builtin video bitrate factory, but practically it just moved code around and should not result in a large binary size change. We can remove this dependency later if needed.

Bug: webrtc:9513
Change-Id: I38708762ff365e4ca05974b99fac71edc739a756
Reviewed-on: https://webrtc-review.googlesource.com/c/109040
Commit-Queue: Jiawei Ou <ouj@fb.com>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25574}
This commit is contained in:
Jiawei Ou
2018-11-08 10:02:56 -08:00
committed by Commit Bot
parent 0393c64af1
commit c2ebe21ba9
42 changed files with 388 additions and 121 deletions

View File

@ -9,12 +9,13 @@
*/
#include "modules/video_coding/include/video_codec_initializer.h"
#include "api/video/video_bitrate_allocator.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "api/video_codecs/create_vp8_temporal_layers.h"
#include "api/video_codecs/video_encoder.h"
#include "api/video_codecs/vp8_temporal_layers.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
#include "rtc_base/checks.h"
#include "rtc_base/refcountedobject.h"
#include "test/gtest.h"
@ -75,12 +76,13 @@ class VideoCodecInitializerTest : public ::testing::Test {
bool InitializeCodec() {
codec_out_ = VideoCodec();
bitrate_allocator_out_.reset();
temporal_layers_.clear();
if (!VideoCodecInitializer::SetupCodec(config_, streams_, &codec_out_,
&bitrate_allocator_out_)) {
if (!VideoCodecInitializer::SetupCodec(config_, streams_, &codec_out_)) {
return false;
}
bitrate_allocator_ = CreateBuiltinVideoBitrateAllocatorFactory()
->CreateVideoBitrateAllocator(codec_out_);
RTC_CHECK(bitrate_allocator_);
if (codec_out_.codecType == VideoCodecType::kVideoCodecMultiplex)
return true;
@ -126,7 +128,7 @@ class VideoCodecInitializerTest : public ::testing::Test {
// Output.
VideoCodec codec_out_;
std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_out_;
std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_;
std::vector<std::unique_ptr<Vp8TemporalLayers>> temporal_layers_;
};
@ -135,9 +137,8 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8Screenshare) {
streams_.push_back(DefaultStream());
EXPECT_TRUE(InitializeCodec());
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(kDefaultTargetBitrateBps,
kDefaultFrameRate);
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
kDefaultTargetBitrateBps, kDefaultFrameRate);
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
EXPECT_EQ(kDefaultTargetBitrateBps, bitrate_allocation.get_sum_bps());
@ -150,9 +151,8 @@ TEST_F(VideoCodecInitializerTest, SingleStreamVp8ScreenshareInactive) {
streams_.push_back(inactive_stream);
EXPECT_TRUE(InitializeCodec());
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(kDefaultTargetBitrateBps,
kDefaultFrameRate);
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
kDefaultTargetBitrateBps, kDefaultFrameRate);
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
EXPECT_EQ(0U, bitrate_allocation.get_sum_bps());
@ -165,9 +165,8 @@ TEST_F(VideoCodecInitializerTest, TemporalLayeredVp8Screenshare) {
EXPECT_EQ(1u, codec_out_.numberOfSimulcastStreams);
EXPECT_EQ(2u, codec_out_.VP8()->numberOfTemporalLayers);
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(kScreenshareCodecTargetBitrateBps,
kScreenshareDefaultFramerate);
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
kScreenshareCodecTargetBitrateBps, kScreenshareDefaultFramerate);
EXPECT_EQ(kScreenshareCodecTargetBitrateBps,
bitrate_allocation.get_sum_bps());
EXPECT_EQ(kScreenshareTl0BitrateBps, bitrate_allocation.GetBitrate(0, 0));
@ -185,9 +184,8 @@ TEST_F(VideoCodecInitializerTest, SimulcastVp8Screenshare) {
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
const uint32_t max_bitrate_bps =
streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps;
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(max_bitrate_bps,
kScreenshareDefaultFramerate);
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
max_bitrate_bps, kScreenshareDefaultFramerate);
EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps());
EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps),
bitrate_allocation.GetSpatialLayerSum(0));
@ -210,9 +208,8 @@ TEST_F(VideoCodecInitializerTest, SimulcastVp8ScreenshareInactive) {
EXPECT_EQ(1u, codec_out_.VP8()->numberOfTemporalLayers);
const uint32_t target_bitrate =
streams_[0].target_bitrate_bps + streams_[1].target_bitrate_bps;
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(target_bitrate,
kScreenshareDefaultFramerate);
VideoBitrateAllocation bitrate_allocation = bitrate_allocator_->GetAllocation(
target_bitrate, kScreenshareDefaultFramerate);
EXPECT_EQ(static_cast<uint32_t>(streams_[0].max_bitrate_bps),
bitrate_allocation.get_sum_bps());
EXPECT_EQ(static_cast<uint32_t>(streams_[0].max_bitrate_bps),
@ -235,7 +232,7 @@ TEST_F(VideoCodecInitializerTest, HighFpsSimulcastVp8Screenshare) {
const uint32_t max_bitrate_bps =
streams_[0].target_bitrate_bps + streams_[1].max_bitrate_bps;
VideoBitrateAllocation bitrate_allocation =
bitrate_allocator_out_->GetAllocation(max_bitrate_bps, kDefaultFrameRate);
bitrate_allocator_->GetAllocation(max_bitrate_bps, kDefaultFrameRate);
EXPECT_EQ(max_bitrate_bps, bitrate_allocation.get_sum_bps());
EXPECT_EQ(static_cast<uint32_t>(streams_[0].target_bitrate_bps),
bitrate_allocation.GetSpatialLayerSum(0));