Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Unified Diff: webrtc/media/engine/webrtcvideoengine_unittest.cc

Issue 3007073002: Add new video codec factories (Closed)
Patch Set: Add tests Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/media/engine/webrtcvideoengine_unittest.cc
diff --git a/webrtc/media/engine/webrtcvideoengine_unittest.cc b/webrtc/media/engine/webrtcvideoengine_unittest.cc
index 8be334aa633660113002486941cb6eeb54bee229..2fb802a99fbcb87d12df3dc7b9ae982241c2e0dc 100644
--- a/webrtc/media/engine/webrtcvideoengine_unittest.cc
+++ b/webrtc/media/engine/webrtcvideoengine_unittest.cc
@@ -13,7 +13,9 @@
#include <memory>
#include <vector>
+#include "webrtc/api/video_codecs/video_decoder_factory.h"
#include "webrtc/api/video_codecs/video_encoder.h"
+#include "webrtc/api/video_codecs/video_encoder_factory.h"
#include "webrtc/call/flexfec_receive_stream.h"
#include "webrtc/common_video/h264/profile_level_id.h"
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
@@ -31,6 +33,7 @@
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/stringutils.h"
#include "webrtc/test/field_trial.h"
+#include "webrtc/test/gmock.h"
using webrtc::RtpExtension;
@@ -167,6 +170,9 @@ class WebRtcVideoEngineTest : public ::testing::Test {
// Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly
// initialized when the constructor is called.
std::unique_ptr<webrtc::Call> call_;
+ // TODO(magjed): Update all tests to use new video codec factories once the
+ // old factories are deprecated,
+ // https://bugs.chromium.org/p/webrtc/issues/detail?id=7925.
cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
WebRtcVideoEngine engine_;
@@ -822,6 +828,140 @@ TEST_F(WebRtcVideoEngineTest, RegisterExternalH264DecoderIfSupported) {
ASSERT_EQ(1u, decoder_factory_.decoders().size());
}
+class MockVideoEncoderFactory : public webrtc::VideoEncoderFactory {
+ public:
+ MOCK_CONST_METHOD0(GetSupportedCodecs, std::vector<VideoCodec>());
+ MOCK_CONST_METHOD1(QueryVideoEncoder, CodecInfo(const VideoCodec&));
+
+ // We need to proxy to a return type that is copyable.
+ std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder(
+ const cricket::VideoCodec& codec) {
+ return std::unique_ptr<webrtc::VideoEncoder>(
+ CreateVideoEncoderProxy(codec));
+ }
+ MOCK_METHOD1(CreateVideoEncoderProxy,
+ webrtc::VideoEncoder*(const VideoCodec&));
+
+ MOCK_METHOD0(Die, void());
+ ~MockVideoEncoderFactory() { Die(); }
+};
+
+class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory {
+ public:
+ MOCK_CONST_METHOD0(GetSupportedCodecs, std::vector<VideoCodec>());
+
+ // We need to proxy to a return type that is copyable.
+ std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
+ const cricket::VideoCodec& codec) {
+ return std::unique_ptr<webrtc::VideoDecoder>(
+ CreateVideoDecoderProxy(codec));
+ }
+ MOCK_METHOD1(CreateVideoDecoderProxy,
+ webrtc::VideoDecoder*(const VideoCodec&));
+
+ MOCK_METHOD0(Die, void());
+ ~MockVideoDecoderFactory() { Die(); }
+};
+
+TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullFactories) {
+ std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory;
+ std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory;
+ WebRtcVideoEngine engine(std::move(encoder_factory),
+ std::move(decoder_factory));
+ EXPECT_EQ(0u, engine.codecs().size());
+}
+
+TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, EmptyFactories) {
+ // |engine| take ownership of the factories.
+ MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory();
+ MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory();
+ WebRtcVideoEngine engine(
+ (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)),
+ (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory)));
+ EXPECT_CALL(*encoder_factory, GetSupportedCodecs());
+ EXPECT_EQ(0u, engine.codecs().size());
+ EXPECT_CALL(*encoder_factory, Die());
+ EXPECT_CALL(*decoder_factory, Die());
+}
+
+// Test full behavior in the video engine when video codec factories of the new
+// type are injected supporting the single codec Vp8. Check the returned codecs
+// from the engine and that we will create a Vp8 encoder and decoder using the
+// new factories.
+TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, Vp8) {
+ // |engine| take ownership of the factories.
+ MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory();
+ MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory();
+ WebRtcVideoEngine engine(
+ (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)),
+ (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory)));
+ const VideoCodec vp8_codec("VP8");
+ const std::vector<VideoCodec> supported_codecs = {vp8_codec};
+ EXPECT_CALL(*encoder_factory, GetSupportedCodecs())
+ .WillRepeatedly(testing::Return(supported_codecs));
+
+ // Verify the codecs from the engine.
+ const std::vector<VideoCodec> engine_codecs = engine.codecs();
+ // Verify an RTX codec has been added correctly.
+ EXPECT_EQ(2u, engine_codecs.size());
+ EXPECT_EQ("VP8", engine_codecs.at(0).name);
+ EXPECT_EQ("rtx", engine_codecs.at(1).name);
+ int associated_payload_type;
+ EXPECT_TRUE(engine_codecs.at(1).GetParam(
+ cricket::kCodecParamAssociatedPayloadType, &associated_payload_type));
+ EXPECT_EQ(engine_codecs.at(0).id, associated_payload_type);
+ // Verify default parameters has been added to the VP8 codec.
+ VerifyCodecHasDefaultFeedbackParams(engine_codecs.at(0));
+
+ // Mock encoder creation. |engine| take ownership of the encoder.
+ webrtc::VideoEncoderFactory::CodecInfo codec_info;
+ codec_info.is_hardware_accelerated = false;
+ codec_info.has_internal_source = false;
+ EXPECT_CALL(*encoder_factory, QueryVideoEncoder(engine_codecs.at(0)))
+ .WillRepeatedly(testing::Return(codec_info));
+ FakeWebRtcVideoEncoder* const encoder = new FakeWebRtcVideoEncoder();
+ EXPECT_CALL(*encoder_factory, CreateVideoEncoderProxy(engine_codecs.at(0)))
+ .WillOnce(testing::Return(encoder));
+
+ // Mock decoder creation. |engine| take ownership of the decoder.
+ FakeWebRtcVideoDecoder* const decoder = new FakeWebRtcVideoDecoder();
+ EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(engine_codecs.at(0)))
+ .WillOnce(testing::Return(decoder));
+
+ // Create a call.
+ webrtc::RtcEventLogNullImpl event_log;
+ std::unique_ptr<webrtc::Call> call(
+ webrtc::Call::Create(webrtc::Call::Config(&event_log)));
+
+ // Create send channel.
+ const int send_ssrc = 123;
+ std::unique_ptr<VideoMediaChannel> send_channel(
+ engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions()));
+ cricket::VideoSendParameters send_parameters;
+ send_parameters.codecs.push_back(engine_codecs.at(0));
+ EXPECT_TRUE(send_channel->SetSendParameters(send_parameters));
+ send_channel->OnReadyToSend(true);
+ EXPECT_TRUE(
+ send_channel->AddSendStream(StreamParams::CreateLegacy(send_ssrc)));
+ EXPECT_TRUE(send_channel->SetSend(true));
+
+ // Create recv channel.
+ const int recv_ssrc = 321;
+ std::unique_ptr<VideoMediaChannel> recv_channel(
+ engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions()));
+ cricket::VideoRecvParameters recv_parameters;
+ recv_parameters.codecs.push_back(engine_codecs.at(0));
+ EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters));
+ EXPECT_TRUE(recv_channel->AddRecvStream(
+ cricket::StreamParams::CreateLegacy(recv_ssrc)));
+
+ // Remove streams previously added to free the encoder and decoder instance.
+ EXPECT_CALL(*encoder_factory, Die());
+ EXPECT_CALL(*decoder_factory, Die());
+ EXPECT_TRUE(send_channel->RemoveSendStream(send_ssrc));
+ EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc));
+}
+
class WebRtcVideoChannelBaseTest
: public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> {
protected:
« webrtc/media/engine/webrtcvideoengine.cc ('K') | « webrtc/media/engine/webrtcvideoengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698