webrtc_m130/media/engine/simulcast_encoder_adapter_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1205 lines
48 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
#include <array>
#include <memory>
#include <vector>
#include "absl/memory/memory.h"
#include "api/test/create_simulcast_test_fixture.h"
#include "api/test/simulcast_test_fixture.h"
#include "api/test/video/function_video_decoder_factory.h"
#include "api/test/video/function_video_encoder_factory.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "common_video/include/video_frame_buffer.h"
#include "media/base/media_constants.h"
#include "media/engine/internal_encoder_factory.h"
#include "media/engine/simulcast_encoder_adapter.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/simulcast_test_fixture_impl.h"
#include "test/gmock.h"
#include "test/gtest.h"
using ::testing::_;
using ::testing::Return;
using EncoderInfo = webrtc::VideoEncoder::EncoderInfo;
using FramerateFractions =
absl::InlinedVector<uint8_t, webrtc::kMaxTemporalStreams>;
namespace webrtc {
namespace test {
namespace {
constexpr int kDefaultWidth = 1280;
constexpr int kDefaultHeight = 720;
std::unique_ptr<SimulcastTestFixture> CreateSpecificSimulcastTestFixture(
VideoEncoderFactory* internal_encoder_factory) {
std::unique_ptr<VideoEncoderFactory> encoder_factory =
absl::make_unique<FunctionVideoEncoderFactory>(
[internal_encoder_factory]() {
return absl::make_unique<SimulcastEncoderAdapter>(
internal_encoder_factory,
SdpVideoFormat(cricket::kVp8CodecName));
});
std::unique_ptr<VideoDecoderFactory> decoder_factory =
absl::make_unique<FunctionVideoDecoderFactory>(
[]() { return VP8Decoder::Create(); });
return CreateSimulcastTestFixture(std::move(encoder_factory),
std::move(decoder_factory),
SdpVideoFormat(cricket::kVp8CodecName));
}
} // namespace
TEST(SimulcastEncoderAdapterSimulcastTest, TestKeyFrameRequestsOnAllStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestKeyFrameRequestsOnAllStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestPaddingAllStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestPaddingAllStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestPaddingTwoStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestPaddingTwoStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestPaddingTwoStreamsOneMaxedOut) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestPaddingTwoStreamsOneMaxedOut();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestPaddingOneStream) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestPaddingOneStream();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestPaddingOneStreamTwoMaxedOut) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestPaddingOneStreamTwoMaxedOut();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestSendAllStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestSendAllStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestDisablingStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestDisablingStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestActiveStreams) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestActiveStreams();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestSwitchingToOneStream) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestSwitchingToOneStream();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestSwitchingToOneOddStream) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestSwitchingToOneOddStream();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestStrideEncodeDecode) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestStrideEncodeDecode();
}
TEST(SimulcastEncoderAdapterSimulcastTest,
TestSpatioTemporalLayers333PatternEncoder) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestSpatioTemporalLayers333PatternEncoder();
}
TEST(SimulcastEncoderAdapterSimulcastTest,
TestSpatioTemporalLayers321PatternEncoder) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestSpatioTemporalLayers321PatternEncoder();
}
TEST(SimulcastEncoderAdapterSimulcastTest, TestDecodeWidthHeightSet) {
InternalEncoderFactory internal_encoder_factory;
auto fixture = CreateSpecificSimulcastTestFixture(&internal_encoder_factory);
fixture->TestDecodeWidthHeightSet();
}
class MockVideoEncoder;
class MockVideoEncoderFactory : public VideoEncoderFactory {
public:
std::vector<SdpVideoFormat> GetSupportedFormats() const override;
std::unique_ptr<VideoEncoder> CreateVideoEncoder(
const SdpVideoFormat& format) override;
Revert "Replace VideoEncoderFactory::QueryVideoEncoder with VideoEncoder::GetEncoderInfo" This reverts commit cdc5eb0de179dcc866ef770ea303879c64466879. Reason for revert: Causes wrong CPU adaptation to be used for some HW codecs since GetEncoderInfo() is polled before InitEncode(). Original change's description: > Replace VideoEncoderFactory::QueryVideoEncoder with VideoEncoder::GetEncoderInfo > > Make implementation of VideoEncoderFactory::QueryVideoEncoder optional > until it is removed downstream and remove all implementations of it. > > Bug: webrtc:10065 > Change-Id: Ibb1f9612234e536651ce53f05ee048a5d172a41f > Reviewed-on: https://webrtc-review.googlesource.com/c/113065 > Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org> > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > Reviewed-by: Per Kjellander <perkj@webrtc.org> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > Reviewed-by: Kári Helgason <kthelgason@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#25924} TBR=brandtr@webrtc.org,sakal@webrtc.org,kthelgason@webrtc.org,sprang@webrtc.org,srte@webrtc.org,perkj@webrtc.org,mirtad@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10065 Change-Id: Idaa452e1d8c1c58cdb4ec69b88fce9042589cc3c Reviewed-on: https://webrtc-review.googlesource.com/c/113800 Reviewed-by: Mirta Dvornicic <mirtad@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25943}
2018-12-10 09:47:34 +00:00
CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override;
const std::vector<MockVideoEncoder*>& encoders() const;
void SetEncoderNames(const std::vector<const char*>& encoder_names);
void set_init_encode_return_value(int32_t value);
void DestroyVideoEncoder(VideoEncoder* encoder);
private:
int32_t init_encode_return_value_ = 0;
std::vector<MockVideoEncoder*> encoders_;
std::vector<const char*> encoder_names_;
};
class MockVideoEncoder : public VideoEncoder {
public:
explicit MockVideoEncoder(MockVideoEncoderFactory* factory)
: factory_(factory),
scaling_settings_(VideoEncoder::ScalingSettings::kOff),
callback_(nullptr) {}
// TODO(nisse): Valid overrides commented out, because the gmock
// methods don't use any override declarations, and we want to avoid
// warnings from -Winconsistent-missing-override. See
// http://crbug.com/428099.
int32_t InitEncode(const VideoCodec* codecSettings,
int32_t numberOfCores,
size_t maxPayloadSize) /* override */ {
codec_ = *codecSettings;
return init_encode_return_value_;
}
MOCK_METHOD2(
Encode,
int32_t(const VideoFrame& inputImage,
const std::vector<VideoFrameType>* frame_types) /* override */);
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) /* override */ {
callback_ = callback;
return 0;
}
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
MOCK_METHOD0(Release, int32_t());
void SetRates(const RateControlParameters& parameters) {
last_set_rates_ = parameters;
}
EncoderInfo GetEncoderInfo() const override {
EncoderInfo info;
info.supports_native_handle = supports_native_handle_;
info.implementation_name = implementation_name_;
info.scaling_settings = scaling_settings_;
info.has_trusted_rate_controller = has_trusted_rate_controller_;
info.is_hardware_accelerated = is_hardware_accelerated_;
info.has_internal_source = has_internal_source_;
info.fps_allocation[0] = fps_allocation_;
return info;
}
virtual ~MockVideoEncoder() { factory_->DestroyVideoEncoder(this); }
const VideoCodec& codec() const { return codec_; }
void SendEncodedImage(int width, int height) {
// Sends a fake image of the given width/height.
EncodedImage image;
image._encodedWidth = width;
image._encodedHeight = height;
CodecSpecificInfo codec_specific_info;
codec_specific_info.codecType = webrtc::kVideoCodecVP8;
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
callback_->OnEncodedImage(image, &codec_specific_info, nullptr);
}
void set_supports_native_handle(bool enabled) {
supports_native_handle_ = enabled;
}
void set_implementation_name(const std::string& name) {
implementation_name_ = name;
}
void set_init_encode_return_value(int32_t value) {
init_encode_return_value_ = value;
}
void set_scaling_settings(const VideoEncoder::ScalingSettings& settings) {
scaling_settings_ = settings;
}
void set_has_trusted_rate_controller(bool trusted) {
has_trusted_rate_controller_ = trusted;
}
void set_is_hardware_accelerated(bool is_hardware_accelerated) {
is_hardware_accelerated_ = is_hardware_accelerated;
}
void set_has_internal_source(bool has_internal_source) {
has_internal_source_ = has_internal_source;
}
void set_fps_allocation(const FramerateFractions& fps_allocation) {
fps_allocation_ = fps_allocation;
}
RateControlParameters last_set_rates() const { return last_set_rates_; }
private:
MockVideoEncoderFactory* const factory_;
bool supports_native_handle_ = false;
std::string implementation_name_ = "unknown";
VideoEncoder::ScalingSettings scaling_settings_;
bool has_trusted_rate_controller_ = false;
bool is_hardware_accelerated_ = false;
bool has_internal_source_ = false;
int32_t init_encode_return_value_ = 0;
VideoEncoder::RateControlParameters last_set_rates_;
FramerateFractions fps_allocation_;
VideoCodec codec_;
EncodedImageCallback* callback_;
};
std::vector<SdpVideoFormat> MockVideoEncoderFactory::GetSupportedFormats()
const {
std::vector<SdpVideoFormat> formats = {SdpVideoFormat("VP8")};
return formats;
}
std::unique_ptr<VideoEncoder> MockVideoEncoderFactory::CreateVideoEncoder(
const SdpVideoFormat& format) {
std::unique_ptr<MockVideoEncoder> encoder(
new ::testing::NiceMock<MockVideoEncoder>(this));
encoder->set_init_encode_return_value(init_encode_return_value_);
const char* encoder_name = encoder_names_.empty()
? "codec_implementation_name"
: encoder_names_[encoders_.size()];
encoder->set_implementation_name(encoder_name);
encoders_.push_back(encoder.get());
return encoder;
}
void MockVideoEncoderFactory::DestroyVideoEncoder(VideoEncoder* encoder) {
for (size_t i = 0; i < encoders_.size(); ++i) {
if (encoders_[i] == encoder) {
encoders_.erase(encoders_.begin() + i);
break;
}
}
}
Revert "Replace VideoEncoderFactory::QueryVideoEncoder with VideoEncoder::GetEncoderInfo" This reverts commit cdc5eb0de179dcc866ef770ea303879c64466879. Reason for revert: Causes wrong CPU adaptation to be used for some HW codecs since GetEncoderInfo() is polled before InitEncode(). Original change's description: > Replace VideoEncoderFactory::QueryVideoEncoder with VideoEncoder::GetEncoderInfo > > Make implementation of VideoEncoderFactory::QueryVideoEncoder optional > until it is removed downstream and remove all implementations of it. > > Bug: webrtc:10065 > Change-Id: Ibb1f9612234e536651ce53f05ee048a5d172a41f > Reviewed-on: https://webrtc-review.googlesource.com/c/113065 > Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org> > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > Reviewed-by: Per Kjellander <perkj@webrtc.org> > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > Reviewed-by: Kári Helgason <kthelgason@webrtc.org> > Reviewed-by: Erik Språng <sprang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#25924} TBR=brandtr@webrtc.org,sakal@webrtc.org,kthelgason@webrtc.org,sprang@webrtc.org,srte@webrtc.org,perkj@webrtc.org,mirtad@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10065 Change-Id: Idaa452e1d8c1c58cdb4ec69b88fce9042589cc3c Reviewed-on: https://webrtc-review.googlesource.com/c/113800 Reviewed-by: Mirta Dvornicic <mirtad@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25943}
2018-12-10 09:47:34 +00:00
VideoEncoderFactory::CodecInfo MockVideoEncoderFactory::QueryVideoEncoder(
const SdpVideoFormat& format) const {
return CodecInfo();
}
const std::vector<MockVideoEncoder*>& MockVideoEncoderFactory::encoders()
const {
return encoders_;
}
void MockVideoEncoderFactory::SetEncoderNames(
const std::vector<const char*>& encoder_names) {
encoder_names_ = encoder_names;
}
void MockVideoEncoderFactory::set_init_encode_return_value(int32_t value) {
init_encode_return_value_ = value;
}
class TestSimulcastEncoderAdapterFakeHelper {
public:
TestSimulcastEncoderAdapterFakeHelper()
: factory_(new MockVideoEncoderFactory()) {}
// Can only be called once as the SimulcastEncoderAdapter will take the
// ownership of |factory_|.
VideoEncoder* CreateMockEncoderAdapter() {
return new SimulcastEncoderAdapter(factory_.get(), SdpVideoFormat("VP8"));
}
MockVideoEncoderFactory* factory() { return factory_.get(); }
private:
std::unique_ptr<MockVideoEncoderFactory> factory_;
};
static const int kTestTemporalLayerProfile[3] = {3, 2, 1};
class TestSimulcastEncoderAdapterFake : public ::testing::Test,
public EncodedImageCallback {
public:
TestSimulcastEncoderAdapterFake()
: helper_(new TestSimulcastEncoderAdapterFakeHelper()),
adapter_(helper_->CreateMockEncoderAdapter()),
last_encoded_image_width_(-1),
last_encoded_image_height_(-1),
last_encoded_image_simulcast_index_(-1) {}
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
virtual ~TestSimulcastEncoderAdapterFake() {
if (adapter_) {
adapter_->Release();
}
}
Result OnEncodedImage(const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) override {
last_encoded_image_width_ = encoded_image._encodedWidth;
last_encoded_image_height_ = encoded_image._encodedHeight;
last_encoded_image_simulcast_index_ =
encoded_image.SpatialIndex().value_or(-1);
return Result(Result::OK, encoded_image.Timestamp());
}
bool GetLastEncodedImageInfo(int* out_width,
int* out_height,
int* out_simulcast_index) {
if (last_encoded_image_width_ == -1) {
return false;
}
*out_width = last_encoded_image_width_;
*out_height = last_encoded_image_height_;
*out_simulcast_index = last_encoded_image_simulcast_index_;
return true;
}
void SetupCodec() {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
}
void VerifyCodec(const VideoCodec& ref, int stream_index) {
const VideoCodec& target =
helper_->factory()->encoders()[stream_index]->codec();
EXPECT_EQ(ref.codecType, target.codecType);
EXPECT_EQ(ref.plType, target.plType);
EXPECT_EQ(ref.width, target.width);
EXPECT_EQ(ref.height, target.height);
EXPECT_EQ(ref.startBitrate, target.startBitrate);
EXPECT_EQ(ref.maxBitrate, target.maxBitrate);
EXPECT_EQ(ref.minBitrate, target.minBitrate);
EXPECT_EQ(ref.maxFramerate, target.maxFramerate);
EXPECT_EQ(ref.VP8().complexity, target.VP8().complexity);
EXPECT_EQ(ref.VP8().numberOfTemporalLayers,
target.VP8().numberOfTemporalLayers);
EXPECT_EQ(ref.VP8().denoisingOn, target.VP8().denoisingOn);
EXPECT_EQ(ref.VP8().automaticResizeOn, target.VP8().automaticResizeOn);
EXPECT_EQ(ref.VP8().frameDroppingOn, target.VP8().frameDroppingOn);
EXPECT_EQ(ref.VP8().keyFrameInterval, target.VP8().keyFrameInterval);
EXPECT_EQ(ref.qpMax, target.qpMax);
EXPECT_EQ(0, target.numberOfSimulcastStreams);
EXPECT_EQ(ref.mode, target.mode);
// No need to compare simulcastStream as numberOfSimulcastStreams should
// always be 0.
}
void InitRefCodec(int stream_index,
VideoCodec* ref_codec,
bool reverse_layer_order = false) {
*ref_codec = codec_;
ref_codec->VP8()->numberOfTemporalLayers =
kTestTemporalLayerProfile[reverse_layer_order ? 2 - stream_index
: stream_index];
ref_codec->width = codec_.simulcastStream[stream_index].width;
ref_codec->height = codec_.simulcastStream[stream_index].height;
ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate;
ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate;
ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax;
}
void VerifyCodecSettings() {
EXPECT_EQ(3u, helper_->factory()->encoders().size());
VideoCodec ref_codec;
// stream 0, the lowest resolution stream.
InitRefCodec(0, &ref_codec);
ref_codec.qpMax = 45;
ref_codec.VP8()->complexity =
webrtc::VideoCodecComplexity::kComplexityHigher;
ref_codec.VP8()->denoisingOn = false;
ref_codec.startBitrate = 100; // Should equal to the target bitrate.
VerifyCodec(ref_codec, 0);
// stream 1
InitRefCodec(1, &ref_codec);
ref_codec.VP8()->denoisingOn = false;
// The start bitrate (300kbit) minus what we have for the lower layers
// (100kbit).
ref_codec.startBitrate = 200;
VerifyCodec(ref_codec, 1);
// stream 2, the biggest resolution stream.
InitRefCodec(2, &ref_codec);
// We don't have enough bits to send this, so the adapter should have
// configured it to use the min bitrate for this layer (600kbit) but turn
// off sending.
ref_codec.startBitrate = 600;
VerifyCodec(ref_codec, 2);
}
protected:
std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_;
std::unique_ptr<VideoEncoder> adapter_;
VideoCodec codec_;
int last_encoded_image_width_;
int last_encoded_image_height_;
int last_encoded_image_simulcast_index_;
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
};
TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) {
SetupCodec();
VerifyCodecSettings();
}
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
TEST_F(TestSimulcastEncoderAdapterFake, ReleaseWithoutInitEncode) {
EXPECT_EQ(0, adapter_->Release());
}
TEST_F(TestSimulcastEncoderAdapterFake, Reinit) {
SetupCodec();
EXPECT_EQ(0, adapter_->Release());
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
}
TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
SetupCodec();
// Set bitrates so that we send all layers.
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(1200, 30), 30.0));
// At this point, the simulcast encoder adapter should have 3 streams: HD,
// quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
// resolutions, to test that the adapter forwards on the correct resolution
// and simulcast index values, going only off the encoder that generates the
// image.
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
ASSERT_EQ(3u, encoders.size());
encoders[0]->SendEncodedImage(1152, 704);
int width;
int height;
int simulcast_index;
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(1152, width);
EXPECT_EQ(704, height);
EXPECT_EQ(0, simulcast_index);
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
encoders[1]->SendEncodedImage(300, 620);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(300, width);
EXPECT_EQ(620, height);
EXPECT_EQ(1, simulcast_index);
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
encoders[2]->SendEncodedImage(120, 240);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(120, width);
EXPECT_EQ(240, height);
EXPECT_EQ(2, simulcast_index);
}
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
// This test verifies that the underlying encoders are reused, when the adapter
// is reinited with different number of simulcast streams. It further checks
// that the allocated encoders are reused in the same order as before, starting
// with the lowest stream.
TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
// Set up common settings for three streams.
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
adapter_->RegisterEncodeCompleteCallback(this);
const uint32_t target_bitrate =
1000 * (codec_.simulcastStream[0].targetBitrate +
codec_.simulcastStream[1].targetBitrate +
codec_.simulcastStream[2].minBitrate);
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
// Input data.
rtc::scoped_refptr<VideoFrameBuffer> buffer(I420Buffer::Create(1280, 720));
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(buffer)
.set_timestamp_rtp(100)
.set_timestamp_ms(1000)
.set_rotation(kVideoRotation_180)
.build();
std::vector<VideoFrameType> frame_types;
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
// Encode with three streams.
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
VerifyCodecSettings();
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
std::vector<MockVideoEncoder*> original_encoders =
helper_->factory()->encoders();
ASSERT_EQ(3u, original_encoders.size());
EXPECT_CALL(*original_encoders[0], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[1], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[2], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
frame_types.resize(3, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
EXPECT_CALL(*original_encoders[0], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[1], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[2], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_EQ(0, adapter_->Release());
// Encode with two streams.
codec_.width /= 2;
codec_.height /= 2;
codec_.numberOfSimulcastStreams = 2;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
std::vector<MockVideoEncoder*> new_encoders = helper_->factory()->encoders();
ASSERT_EQ(2u, new_encoders.size());
ASSERT_EQ(original_encoders[0], new_encoders[0]);
EXPECT_CALL(*original_encoders[0], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
ASSERT_EQ(original_encoders[1], new_encoders[1]);
EXPECT_CALL(*original_encoders[1], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
frame_types.resize(2, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
EXPECT_CALL(*original_encoders[0], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[1], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_EQ(0, adapter_->Release());
// Encode with single stream.
codec_.width /= 2;
codec_.height /= 2;
codec_.numberOfSimulcastStreams = 1;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
new_encoders = helper_->factory()->encoders();
ASSERT_EQ(1u, new_encoders.size());
ASSERT_EQ(original_encoders[0], new_encoders[0]);
EXPECT_CALL(*original_encoders[0], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
frame_types.resize(1, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
EXPECT_CALL(*original_encoders[0], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_EQ(0, adapter_->Release());
// Encode with three streams, again.
codec_.width *= 4;
codec_.height *= 4;
codec_.numberOfSimulcastStreams = 3;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(target_bitrate, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
new_encoders = helper_->factory()->encoders();
ASSERT_EQ(3u, new_encoders.size());
// The first encoder is reused.
ASSERT_EQ(original_encoders[0], new_encoders[0]);
EXPECT_CALL(*original_encoders[0], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
// The second and third encoders are new.
EXPECT_CALL(*new_encoders[1], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*new_encoders[2], Encode(_, _))
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
frame_types.resize(3, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
EXPECT_CALL(*original_encoders[0], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*new_encoders[1], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*new_encoders[2], Release())
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_EQ(0, adapter_->Release());
}
TEST_F(TestSimulcastEncoderAdapterFake, DoesNotLeakEncoders) {
SetupCodec();
VerifyCodecSettings();
EXPECT_EQ(3u, helper_->factory()->encoders().size());
// The adapter should destroy all encoders it has allocated. Since
// |helper_->factory()| is owned by |adapter_|, however, we need to rely on
// lsan to find leaks here.
EXPECT_EQ(0, adapter_->Release());
adapter_.reset();
}
// This test verifies that an adapter reinit with the same codec settings as
// before does not change the underlying encoder codec settings.
TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderEncoderSettings) {
SetupCodec();
VerifyCodecSettings();
// Capture current codec settings.
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
ASSERT_EQ(3u, encoders.size());
std::array<VideoCodec, 3> codecs_before;
for (int i = 0; i < 3; ++i) {
codecs_before[i] = encoders[i]->codec();
}
// Reinitialize and verify that the new codec settings are the same.
EXPECT_EQ(0, adapter_->Release());
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
for (int i = 0; i < 3; ++i) {
const VideoCodec& codec_before = codecs_before[i];
const VideoCodec& codec_after = encoders[i]->codec();
// webrtc::VideoCodec does not implement operator==.
EXPECT_EQ(codec_before.codecType, codec_after.codecType);
EXPECT_EQ(codec_before.plType, codec_after.plType);
EXPECT_EQ(codec_before.width, codec_after.width);
EXPECT_EQ(codec_before.height, codec_after.height);
EXPECT_EQ(codec_before.startBitrate, codec_after.startBitrate);
EXPECT_EQ(codec_before.maxBitrate, codec_after.maxBitrate);
EXPECT_EQ(codec_before.minBitrate, codec_after.minBitrate);
EXPECT_EQ(codec_before.maxFramerate, codec_after.maxFramerate);
EXPECT_EQ(codec_before.qpMax, codec_after.qpMax);
EXPECT_EQ(codec_before.numberOfSimulcastStreams,
codec_after.numberOfSimulcastStreams);
EXPECT_EQ(codec_before.mode, codec_after.mode);
EXPECT_EQ(codec_before.expect_encode_from_texture,
codec_after.expect_encode_from_texture);
}
}
// This test is similar to the one above, except that it tests the simulcastIdx
// from the CodecSpecificInfo that is connected to an encoded frame. The
// PayloadRouter demuxes the incoming encoded frames on different RTP modules
// using the simulcastIdx, so it's important that there is no corresponding
// encoder reordering in between adapter reinits as this would lead to PictureID
// discontinuities.
TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
SetupCodec();
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(1200, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
VerifyCodecSettings();
// Send frames on all streams.
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
ASSERT_EQ(3u, encoders.size());
encoders[0]->SendEncodedImage(1152, 704);
int width;
int height;
int simulcast_index;
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(0, simulcast_index);
encoders[1]->SendEncodedImage(300, 620);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(1, simulcast_index);
encoders[2]->SendEncodedImage(120, 240);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(2, simulcast_index);
// Reinitialize.
EXPECT_EQ(0, adapter_->Release());
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(1200, 30), 30.0));
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
// Verify that the same encoder sends out frames on the same simulcast index.
encoders[0]->SendEncodedImage(1152, 704);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(0, simulcast_index);
encoders[1]->SendEncodedImage(300, 620);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(1, simulcast_index);
encoders[2]->SendEncodedImage(120, 240);
EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
EXPECT_EQ(2, simulcast_index);
}
TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 1;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
ASSERT_EQ(1u, helper_->factory()->encoders().size());
helper_->factory()->encoders()[0]->set_supports_native_handle(true);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().supports_native_handle);
helper_->factory()->encoders()[0]->set_supports_native_handle(false);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().supports_native_handle);
}
TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.minBitrate = 50;
codec_.numberOfSimulcastStreams = 1;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
// Above min should be respected.
VideoBitrateAllocation target_bitrate =
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30);
adapter_->SetRates(VideoEncoder::RateControlParameters(target_bitrate, 30.0));
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
EXPECT_EQ(target_bitrate,
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
// Below min but non-zero should be replaced with the min bitrate.
VideoBitrateAllocation too_low_bitrate =
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30);
adapter_->SetRates(
VideoEncoder::RateControlParameters(too_low_bitrate, 30.0));
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
EXPECT_EQ(target_bitrate,
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
// Zero should be passed on as is, since it means "pause".
adapter_->SetRates(
VideoEncoder::RateControlParameters(VideoBitrateAllocation(), 30.0));
EXPECT_EQ(VideoBitrateAllocation(),
helper_->factory()->encoders()[0]->last_set_rates().bitrate);
}
TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) {
EXPECT_EQ("SimulcastEncoderAdapter",
adapter_->GetEncoderInfo().implementation_name);
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
std::vector<const char*> encoder_names;
encoder_names.push_back("codec1");
encoder_names.push_back("codec2");
encoder_names.push_back("codec3");
helper_->factory()->SetEncoderNames(encoder_names);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_EQ("SimulcastEncoderAdapter (codec1, codec2, codec3)",
adapter_->GetEncoderInfo().implementation_name);
// Single streams should not expose "SimulcastEncoderAdapter" in name.
Reland of use allocated encoders in SimulcastEncoderAdapter. (patchset #1 id:1 of https://codereview.webrtc.org/2893003002/ ) Reason for reland: Chrome encoder implementation fixed. Original issue's description: > Revert of Reuse allocated encoders in SimulcastEncoderAdapter. (patchset #15 id:320001 of https://codereview.webrtc.org/2830793005/ ) > > Reason for revert: > Breaks Chrome tests. > > Original issue's description: > > Reuse allocated encoders in SimulcastEncoderAdapter. > > > > Prior to this change, the SimulcastEncoderAdapter would destroy and create > > encoders whenever it is being reinitialized. After this change, the > > SimulcastEncoderAdapter will cache the already allocated encoders, and reuse > > them after reinitialization. > > > > This change will help in reducing the number of PictureID "jumps" that have > > been seen around encoder reinitialization. > > > > TESTED=AppRTCMobile, Chrome desktop, and internal app, with forced encoder reinits every 30 frames and https://codereview.webrtc.org/2833493003/ applied. > > BUG=webrtc:7475 > > > > Review-Url: https://codereview.webrtc.org/2830793005 > > Cr-Commit-Position: refs/heads/master@{#18215} > > Committed: https://chromium.googlesource.com/external/webrtc/+/0b8bfb9d98b7a2011d80bcdf3f430bc040370dad > > TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:7475 > > Review-Url: https://codereview.webrtc.org/2893003002 > Cr-Commit-Position: refs/heads/master@{#18216} > Committed: https://chromium.googlesource.com/external/webrtc/+/56e119e2e8b30d2d41c55c3a7983b077a5262718 TBR=stefan@webrtc.org,noahric@chromium.org,glaznev@webrtc.org,sprang@webrtc.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=webrtc:7475 Review-Url: https://codereview.webrtc.org/2901493002 Cr-Commit-Position: refs/heads/master@{#18228}
2017-05-23 03:32:16 -07:00
EXPECT_EQ(0, adapter_->Release());
codec_.numberOfSimulcastStreams = 1;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
ASSERT_EQ(1u, helper_->factory()->encoders().size());
EXPECT_EQ("codec1", adapter_->GetEncoderInfo().implementation_name);
}
TEST_F(TestSimulcastEncoderAdapterFake,
SupportsNativeHandleForMultipleStreams) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
ASSERT_EQ(3u, helper_->factory()->encoders().size());
for (MockVideoEncoder* encoder : helper_->factory()->encoders())
encoder->set_supports_native_handle(true);
// If one encoder doesn't support it, then overall support is disabled.
helper_->factory()->encoders()[0]->set_supports_native_handle(false);
EXPECT_FALSE(adapter_->GetEncoderInfo().supports_native_handle);
// Once all do, then the adapter claims support.
helper_->factory()->encoders()[0]->set_supports_native_handle(true);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().supports_native_handle);
}
// TODO(nisse): Reuse definition in webrtc/test/fake_texture_handle.h.
class FakeNativeBufferNoI420 : public VideoFrameBuffer {
public:
FakeNativeBufferNoI420(int width, int height)
: width_(width), height_(height) {}
Revert "Revert "Update video_coding/codecs to new VideoFrameBuffer interface"" This reverts commit 88f94fa36aa61f7904d30251205c544ada2c4301. Chromium code has been updated. Original change's description: > Revert "Update video_coding/codecs to new VideoFrameBuffer interface" > > This reverts commit 20ebf4ede803cd4f628ef9378700f60b72f2eab0. > > Reason for revert: > > Suspect of breaking FYI bots. > See https://build.chromium.org/p/chromium.webrtc.fyi/builders/Win7%20Tester/builds/9036 and others. > > Sample logs: > Backtrace: > [5024:1036:0607/173649.857:FATAL:webrtc_video_frame_adapter.cc(98)] Check failed: false. > Backtrace: > base::debug::StackTrace::StackTrace [0x02D04A37+55] > base::debug::StackTrace::StackTrace [0x02CCBB8A+10] > content::WebRtcVideoFrameAdapter::NativeToI420Buffer [0x0508AD71+305] > webrtc::VideoFrameBuffer::ToI420 [0x0230BF67+39] > webrtc::H264EncoderImpl::Encode [0x057E8D0B+267] > webrtc::VCMGenericEncoder::Encode [0x057E0E34+333] > webrtc::vcm::VideoSender::AddVideoFrame [0x057DED9B+796] > webrtc::ViEEncoder::EncodeVideoFrame [0x057C00F6+884] > webrtc::ViEEncoder::EncodeTask::Run [0x057C12D7+215] > rtc::TaskQueue::PostTask [0x03EE5CFB+194] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDCAA5+31] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDEE86+22] > base::debug::TaskAnnotator::RunTask [0x02D08289+409] > base::MessageLoop::RunTask [0x02C8CEC1+1233] > base::MessageLoop::DoWork [0x02C8C1AD+765] > base::MessagePumpDefault::Run [0x02D0A20B+219] > base::MessageLoop::Run [0x02C8C9DB+107] > base::RunLoop::Run [0x02C89583+147] > base::Thread::Run [0x02CBEFCD+173] > base::Thread::ThreadMain [0x02CBFADE+622] > base::PlatformThread::Sleep [0x02C9E1A2+290] > BaseThreadInitThunk [0x75C3338A+18] > RtlInitializeExceptionChain [0x773A9902+99] > RtlInitializeExceptionChain [0x773A98D5+54] > > Original change's description: > > Update video_coding/codecs to new VideoFrameBuffer interface > > > > This is a follow-up cleanup for CL > > https://codereview.webrtc.org/2847383002/. > > > > Bug: webrtc:7632 > > Change-Id: I47861d779968f2fee94db9c017102a8e87e67fb7 > > Reviewed-on: https://chromium-review.googlesource.com/524163 > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#18477} > > TBR=magjed@webrtc.org,nisse@webrtc.org,brandtr@webrtc.org > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7632 > > Change-Id: I3b73fc7d16ff19ceba196e964dcb36a36510912c > Reviewed-on: https://chromium-review.googlesource.com/527793 > Reviewed-by: Guido Urdaneta <guidou@chromium.org> > Commit-Queue: Guido Urdaneta <guidou@chromium.org> > Cr-Commit-Position: refs/heads/master@{#18489} TBR=tterriberry@mozilla.com,mflodman@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,guidou@chromium.org,nisse@webrtc.org,brandtr@webrtc.org,webrtc-reviews@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. No-Presubmit: true Bug: webrtc:7632 Change-Id: I0962a704e8a9939d4364ce9069c863c9951654c9 Reviewed-on: https://chromium-review.googlesource.com/530684 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18527}
2017-06-10 17:03:37 +00:00
Type type() const override { return Type::kNative; }
int width() const override { return width_; }
int height() const override { return height_; }
rtc::scoped_refptr<I420BufferInterface> ToI420() override {
RTC_NOTREACHED();
return nullptr;
}
Revert "Revert "Update video_coding/codecs to new VideoFrameBuffer interface"" This reverts commit 88f94fa36aa61f7904d30251205c544ada2c4301. Chromium code has been updated. Original change's description: > Revert "Update video_coding/codecs to new VideoFrameBuffer interface" > > This reverts commit 20ebf4ede803cd4f628ef9378700f60b72f2eab0. > > Reason for revert: > > Suspect of breaking FYI bots. > See https://build.chromium.org/p/chromium.webrtc.fyi/builders/Win7%20Tester/builds/9036 and others. > > Sample logs: > Backtrace: > [5024:1036:0607/173649.857:FATAL:webrtc_video_frame_adapter.cc(98)] Check failed: false. > Backtrace: > base::debug::StackTrace::StackTrace [0x02D04A37+55] > base::debug::StackTrace::StackTrace [0x02CCBB8A+10] > content::WebRtcVideoFrameAdapter::NativeToI420Buffer [0x0508AD71+305] > webrtc::VideoFrameBuffer::ToI420 [0x0230BF67+39] > webrtc::H264EncoderImpl::Encode [0x057E8D0B+267] > webrtc::VCMGenericEncoder::Encode [0x057E0E34+333] > webrtc::vcm::VideoSender::AddVideoFrame [0x057DED9B+796] > webrtc::ViEEncoder::EncodeVideoFrame [0x057C00F6+884] > webrtc::ViEEncoder::EncodeTask::Run [0x057C12D7+215] > rtc::TaskQueue::PostTask [0x03EE5CFB+194] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDCAA5+31] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDEE86+22] > base::debug::TaskAnnotator::RunTask [0x02D08289+409] > base::MessageLoop::RunTask [0x02C8CEC1+1233] > base::MessageLoop::DoWork [0x02C8C1AD+765] > base::MessagePumpDefault::Run [0x02D0A20B+219] > base::MessageLoop::Run [0x02C8C9DB+107] > base::RunLoop::Run [0x02C89583+147] > base::Thread::Run [0x02CBEFCD+173] > base::Thread::ThreadMain [0x02CBFADE+622] > base::PlatformThread::Sleep [0x02C9E1A2+290] > BaseThreadInitThunk [0x75C3338A+18] > RtlInitializeExceptionChain [0x773A9902+99] > RtlInitializeExceptionChain [0x773A98D5+54] > > Original change's description: > > Update video_coding/codecs to new VideoFrameBuffer interface > > > > This is a follow-up cleanup for CL > > https://codereview.webrtc.org/2847383002/. > > > > Bug: webrtc:7632 > > Change-Id: I47861d779968f2fee94db9c017102a8e87e67fb7 > > Reviewed-on: https://chromium-review.googlesource.com/524163 > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#18477} > > TBR=magjed@webrtc.org,nisse@webrtc.org,brandtr@webrtc.org > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7632 > > Change-Id: I3b73fc7d16ff19ceba196e964dcb36a36510912c > Reviewed-on: https://chromium-review.googlesource.com/527793 > Reviewed-by: Guido Urdaneta <guidou@chromium.org> > Commit-Queue: Guido Urdaneta <guidou@chromium.org> > Cr-Commit-Position: refs/heads/master@{#18489} TBR=tterriberry@mozilla.com,mflodman@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,guidou@chromium.org,nisse@webrtc.org,brandtr@webrtc.org,webrtc-reviews@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. No-Presubmit: true Bug: webrtc:7632 Change-Id: I0962a704e8a9939d4364ce9069c863c9951654c9 Reviewed-on: https://chromium-review.googlesource.com/530684 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18527}
2017-06-10 17:03:37 +00:00
private:
const int width_;
const int height_;
};
TEST_F(TestSimulcastEncoderAdapterFake,
NativeHandleForwardingForMultipleStreams) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
// High start bitrate, so all streams are enabled.
codec_.startBitrate = 3000;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
ASSERT_EQ(3u, helper_->factory()->encoders().size());
for (MockVideoEncoder* encoder : helper_->factory()->encoders())
encoder->set_supports_native_handle(true);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().supports_native_handle);
rtc::scoped_refptr<VideoFrameBuffer> buffer(
new rtc::RefCountedObject<FakeNativeBufferNoI420>(1280, 720));
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(buffer)
.set_timestamp_rtp(100)
.set_timestamp_ms(1000)
.set_rotation(kVideoRotation_180)
.build();
// Expect calls with the given video frame verbatim, since it's a texture
// frame and can't otherwise be modified/resized.
for (MockVideoEncoder* encoder : helper_->factory()->encoders())
EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _)).Times(1);
std::vector<VideoFrameType> frame_types(3, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
}
TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
ASSERT_EQ(3u, helper_->factory()->encoders().size());
// Tell the 2nd encoder to request software fallback.
EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _))
.WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE));
// Send a fake frame and assert the return is software fallback.
Revert "Revert "Update video_coding/codecs to new VideoFrameBuffer interface"" This reverts commit 88f94fa36aa61f7904d30251205c544ada2c4301. Chromium code has been updated. Original change's description: > Revert "Update video_coding/codecs to new VideoFrameBuffer interface" > > This reverts commit 20ebf4ede803cd4f628ef9378700f60b72f2eab0. > > Reason for revert: > > Suspect of breaking FYI bots. > See https://build.chromium.org/p/chromium.webrtc.fyi/builders/Win7%20Tester/builds/9036 and others. > > Sample logs: > Backtrace: > [5024:1036:0607/173649.857:FATAL:webrtc_video_frame_adapter.cc(98)] Check failed: false. > Backtrace: > base::debug::StackTrace::StackTrace [0x02D04A37+55] > base::debug::StackTrace::StackTrace [0x02CCBB8A+10] > content::WebRtcVideoFrameAdapter::NativeToI420Buffer [0x0508AD71+305] > webrtc::VideoFrameBuffer::ToI420 [0x0230BF67+39] > webrtc::H264EncoderImpl::Encode [0x057E8D0B+267] > webrtc::VCMGenericEncoder::Encode [0x057E0E34+333] > webrtc::vcm::VideoSender::AddVideoFrame [0x057DED9B+796] > webrtc::ViEEncoder::EncodeVideoFrame [0x057C00F6+884] > webrtc::ViEEncoder::EncodeTask::Run [0x057C12D7+215] > rtc::TaskQueue::PostTask [0x03EE5CFB+194] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDCAA5+31] > base::internal::Invoker<base::internal::BindState<enum extensions::`anonymous namespace'::VerificationResult (__cdecl*)(std::unique_ptr<extensions::NetworkingCastPrivateDelegate::Credentials,std::default_delete<extensions::NetworkingCastPrivateDelegate::C [0x02DDEE86+22] > base::debug::TaskAnnotator::RunTask [0x02D08289+409] > base::MessageLoop::RunTask [0x02C8CEC1+1233] > base::MessageLoop::DoWork [0x02C8C1AD+765] > base::MessagePumpDefault::Run [0x02D0A20B+219] > base::MessageLoop::Run [0x02C8C9DB+107] > base::RunLoop::Run [0x02C89583+147] > base::Thread::Run [0x02CBEFCD+173] > base::Thread::ThreadMain [0x02CBFADE+622] > base::PlatformThread::Sleep [0x02C9E1A2+290] > BaseThreadInitThunk [0x75C3338A+18] > RtlInitializeExceptionChain [0x773A9902+99] > RtlInitializeExceptionChain [0x773A98D5+54] > > Original change's description: > > Update video_coding/codecs to new VideoFrameBuffer interface > > > > This is a follow-up cleanup for CL > > https://codereview.webrtc.org/2847383002/. > > > > Bug: webrtc:7632 > > Change-Id: I47861d779968f2fee94db9c017102a8e87e67fb7 > > Reviewed-on: https://chromium-review.googlesource.com/524163 > > Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#18477} > > TBR=magjed@webrtc.org,nisse@webrtc.org,brandtr@webrtc.org > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7632 > > Change-Id: I3b73fc7d16ff19ceba196e964dcb36a36510912c > Reviewed-on: https://chromium-review.googlesource.com/527793 > Reviewed-by: Guido Urdaneta <guidou@chromium.org> > Commit-Queue: Guido Urdaneta <guidou@chromium.org> > Cr-Commit-Position: refs/heads/master@{#18489} TBR=tterriberry@mozilla.com,mflodman@webrtc.org,magjed@webrtc.org,stefan@webrtc.org,guidou@chromium.org,nisse@webrtc.org,brandtr@webrtc.org,webrtc-reviews@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. No-Presubmit: true Bug: webrtc:7632 Change-Id: I0962a704e8a9939d4364ce9069c863c9951654c9 Reviewed-on: https://chromium-review.googlesource.com/530684 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18527}
2017-06-10 17:03:37 +00:00
rtc::scoped_refptr<I420Buffer> input_buffer =
I420Buffer::Create(kDefaultWidth, kDefaultHeight);
input_buffer->InitializeData();
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(input_buffer)
.set_timestamp_rtp(0)
.set_timestamp_us(0)
.set_rotation(kVideoRotation_0)
.build();
std::vector<VideoFrameType> frame_types(3, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
adapter_->Encode(input_frame, &frame_types));
}
TEST_F(TestSimulcastEncoderAdapterFake, TestInitFailureCleansUpEncoders) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
helper_->factory()->set_init_encode_return_value(
WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(helper_->factory()->encoders().empty());
}
TEST_F(TestSimulcastEncoderAdapterFake, DoesNotAlterMaxQpForScreenshare) {
const int kHighMaxQp = 56;
const int kLowMaxQp = 46;
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
codec_.simulcastStream[0].qpMax = kHighMaxQp;
codec_.mode = VideoCodecMode::kScreensharing;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_EQ(3u, helper_->factory()->encoders().size());
// Just check the lowest stream, which is the one that where the adapter
// might alter the max qp setting.
VideoCodec ref_codec;
InitRefCodec(0, &ref_codec);
ref_codec.qpMax = kHighMaxQp;
ref_codec.VP8()->complexity = webrtc::VideoCodecComplexity::kComplexityHigher;
ref_codec.VP8()->denoisingOn = false;
ref_codec.startBitrate = 100; // Should equal to the target bitrate.
VerifyCodec(ref_codec, 0);
// Change the max qp and try again.
codec_.simulcastStream[0].qpMax = kLowMaxQp;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_EQ(3u, helper_->factory()->encoders().size());
ref_codec.qpMax = kLowMaxQp;
VerifyCodec(ref_codec, 0);
}
TEST_F(TestSimulcastEncoderAdapterFake,
DoesNotAlterMaxQpForScreenshareReversedLayer) {
const int kHighMaxQp = 56;
const int kLowMaxQp = 46;
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8, true /* reverse_layer_order */);
codec_.numberOfSimulcastStreams = 3;
codec_.simulcastStream[2].qpMax = kHighMaxQp;
codec_.mode = VideoCodecMode::kScreensharing;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_EQ(3u, helper_->factory()->encoders().size());
// Just check the lowest stream, which is the one that where the adapter
// might alter the max qp setting.
VideoCodec ref_codec;
InitRefCodec(2, &ref_codec, true /* reverse_layer_order */);
ref_codec.qpMax = kHighMaxQp;
ref_codec.VP8()->complexity = webrtc::VideoCodecComplexity::kComplexityHigher;
ref_codec.VP8()->denoisingOn = false;
ref_codec.startBitrate = 100; // Should equal to the target bitrate.
VerifyCodec(ref_codec, 2);
// Change the max qp and try again.
codec_.simulcastStream[2].qpMax = kLowMaxQp;
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_EQ(3u, helper_->factory()->encoders().size());
ref_codec.qpMax = kLowMaxQp;
VerifyCodec(ref_codec, 2);
}
TEST_F(TestSimulcastEncoderAdapterFake, ActivatesCorrectStreamsInInitEncode) {
// Set up common settings for three streams.
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
adapter_->RegisterEncodeCompleteCallback(this);
// Only enough start bitrate for the lowest stream.
ASSERT_EQ(3u, codec_.numberOfSimulcastStreams);
codec_.startBitrate = codec_.simulcastStream[0].targetBitrate +
codec_.simulcastStream[1].minBitrate - 1;
// Input data.
rtc::scoped_refptr<VideoFrameBuffer> buffer(I420Buffer::Create(1280, 720));
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(buffer)
.set_timestamp_rtp(100)
.set_timestamp_ms(1000)
.set_rotation(kVideoRotation_180)
.build();
// Encode with three streams.
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
std::vector<MockVideoEncoder*> original_encoders =
helper_->factory()->encoders();
ASSERT_EQ(3u, original_encoders.size());
// Only first encoder will be active and called.
EXPECT_CALL(*original_encoders[0], Encode(_, _))
.WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
EXPECT_CALL(*original_encoders[1], Encode(_, _)).Times(0);
EXPECT_CALL(*original_encoders[2], Encode(_, _)).Times(0);
std::vector<VideoFrameType> frame_types;
frame_types.resize(3, VideoFrameType::kVideoFrameKey);
EXPECT_EQ(0, adapter_->Encode(input_frame, &frame_types));
}
TEST_F(TestSimulcastEncoderAdapterFake, TrustedRateControl) {
// Set up common settings for three streams.
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
adapter_->RegisterEncodeCompleteCallback(this);
// Only enough start bitrate for the lowest stream.
ASSERT_EQ(3u, codec_.numberOfSimulcastStreams);
codec_.startBitrate = codec_.simulcastStream[0].targetBitrate +
codec_.simulcastStream[1].minBitrate - 1;
// Input data.
rtc::scoped_refptr<VideoFrameBuffer> buffer(I420Buffer::Create(1280, 720));
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(buffer)
.set_timestamp_rtp(100)
.set_timestamp_ms(1000)
.set_rotation(kVideoRotation_180)
.build();
// No encoder trusted, so simulcast adapter should not be either.
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().has_trusted_rate_controller);
// Encode with three streams.
std::vector<MockVideoEncoder*> original_encoders =
helper_->factory()->encoders();
// All encoders are trusted, so simulcast adapter should be too.
original_encoders[0]->set_has_trusted_rate_controller(true);
original_encoders[1]->set_has_trusted_rate_controller(true);
original_encoders[2]->set_has_trusted_rate_controller(true);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().has_trusted_rate_controller);
// One encoder not trusted, so simulcast adapter should not be either.
original_encoders[2]->set_has_trusted_rate_controller(false);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().has_trusted_rate_controller);
// No encoder trusted, so simulcast adapter should not be either.
original_encoders[0]->set_has_trusted_rate_controller(false);
original_encoders[1]->set_has_trusted_rate_controller(false);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().has_trusted_rate_controller);
}
TEST_F(TestSimulcastEncoderAdapterFake, ReportsHardwareAccelerated) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
adapter_->RegisterEncodeCompleteCallback(this);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
ASSERT_EQ(3u, helper_->factory()->encoders().size());
// None of the encoders uses HW support, so simulcast adapter reports false.
for (MockVideoEncoder* encoder : helper_->factory()->encoders()) {
encoder->set_is_hardware_accelerated(false);
}
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().is_hardware_accelerated);
// One encoder uses HW support, so simulcast adapter reports true.
helper_->factory()->encoders()[2]->set_is_hardware_accelerated(true);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().is_hardware_accelerated);
}
TEST_F(TestSimulcastEncoderAdapterFake, ReportsInternalSource) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
adapter_->RegisterEncodeCompleteCallback(this);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
ASSERT_EQ(3u, helper_->factory()->encoders().size());
// All encoders have internal source, simulcast adapter reports true.
for (MockVideoEncoder* encoder : helper_->factory()->encoders()) {
encoder->set_has_internal_source(true);
}
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_TRUE(adapter_->GetEncoderInfo().has_internal_source);
// One encoder does not have internal source, simulcast adapter reports false.
helper_->factory()->encoders()[2]->set_has_internal_source(false);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_FALSE(adapter_->GetEncoderInfo().has_internal_source);
}
TEST_F(TestSimulcastEncoderAdapterFake, ReportsFpsAllocation) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
adapter_->RegisterEncodeCompleteCallback(this);
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
ASSERT_EQ(3u, helper_->factory()->encoders().size());
// Combination of three different supported mode:
// Simulcast stream 0 has undefined fps behavior.
// Simulcast stream 1 has three temporal layers.
// Simulcast stream 2 has 1 temporal layer.
FramerateFractions expected_fps_allocation[kMaxSpatialLayers];
expected_fps_allocation[1].push_back(EncoderInfo::kMaxFramerateFraction / 4);
expected_fps_allocation[1].push_back(EncoderInfo::kMaxFramerateFraction / 2);
expected_fps_allocation[1].push_back(EncoderInfo::kMaxFramerateFraction);
expected_fps_allocation[2].push_back(EncoderInfo::kMaxFramerateFraction);
// All encoders have internal source, simulcast adapter reports true.
for (size_t i = 0; i < codec_.numberOfSimulcastStreams; ++i) {
MockVideoEncoder* encoder = helper_->factory()->encoders()[i];
encoder->set_fps_allocation(expected_fps_allocation[i]);
}
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
EXPECT_THAT(adapter_->GetEncoderInfo().fps_allocation,
::testing::ElementsAreArray(expected_fps_allocation));
}
TEST_F(TestSimulcastEncoderAdapterFake, SetRateDistributesBandwithAllocation) {
SimulcastTestFixtureImpl::DefaultSettings(
&codec_, static_cast<const int*>(kTestTemporalLayerProfile),
kVideoCodecVP8);
codec_.numberOfSimulcastStreams = 3;
const DataRate target_bitrate =
DataRate::kbps(codec_.simulcastStream[0].targetBitrate +
codec_.simulcastStream[1].targetBitrate +
codec_.simulcastStream[2].minBitrate);
const DataRate bandwidth_allocation = target_bitrate + DataRate::kbps(600);
rate_allocator_.reset(new SimulcastRateAllocator(codec_));
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
adapter_->RegisterEncodeCompleteCallback(this);
// Set bitrates so that we send all layers.
adapter_->SetRates(VideoEncoder::RateControlParameters(
rate_allocator_->GetAllocation(target_bitrate.bps(), 30), 30.0,
bandwidth_allocation));
std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
ASSERT_EQ(3u, encoders.size());
for (size_t i = 0; i < 3; ++i) {
const uint32_t layer_bitrate_bps =
(i < static_cast<size_t>(codec_.numberOfSimulcastStreams) - 1
? codec_.simulcastStream[i].targetBitrate
: codec_.simulcastStream[i].minBitrate) *
1000;
EXPECT_EQ(layer_bitrate_bps,
encoders[i]->last_set_rates().bitrate.get_sum_bps())
<< i;
EXPECT_EQ(
(layer_bitrate_bps * bandwidth_allocation.bps()) / target_bitrate.bps(),
encoders[i]->last_set_rates().bandwidth_allocation.bps())
<< i;
}
}
} // namespace test
} // namespace webrtc