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

Side by Side Diff: webrtc/media/engine/webrtcvideoengine_unittest.cc

Issue 3007073002: Add new video codec factories (Closed)
Patch Set: . 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 unified diff | Download patch
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/api/video_codecs/sdp_video_format.h"
17 #include "webrtc/api/video_codecs/video_decoder_factory.h"
16 #include "webrtc/api/video_codecs/video_encoder.h" 18 #include "webrtc/api/video_codecs/video_encoder.h"
19 #include "webrtc/api/video_codecs/video_encoder_factory.h"
17 #include "webrtc/call/flexfec_receive_stream.h" 20 #include "webrtc/call/flexfec_receive_stream.h"
18 #include "webrtc/common_video/h264/profile_level_id.h" 21 #include "webrtc/common_video/h264/profile_level_id.h"
19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
20 #include "webrtc/media/base/mediaconstants.h" 23 #include "webrtc/media/base/mediaconstants.h"
21 #include "webrtc/media/base/rtputils.h" 24 #include "webrtc/media/base/rtputils.h"
22 #include "webrtc/media/base/testutils.h" 25 #include "webrtc/media/base/testutils.h"
23 #include "webrtc/media/base/videoengine_unittest.h" 26 #include "webrtc/media/base/videoengine_unittest.h"
24 #include "webrtc/media/engine/constants.h" 27 #include "webrtc/media/engine/constants.h"
25 #include "webrtc/media/engine/fakewebrtccall.h" 28 #include "webrtc/media/engine/fakewebrtccall.h"
26 #include "webrtc/media/engine/fakewebrtcvideoengine.h" 29 #include "webrtc/media/engine/fakewebrtcvideoengine.h"
27 #include "webrtc/media/engine/simulcast.h" 30 #include "webrtc/media/engine/simulcast.h"
28 #include "webrtc/media/engine/webrtcvideoengine.h" 31 #include "webrtc/media/engine/webrtcvideoengine.h"
29 #include "webrtc/media/engine/webrtcvoiceengine.h" 32 #include "webrtc/media/engine/webrtcvoiceengine.h"
30 #include "webrtc/rtc_base/arraysize.h" 33 #include "webrtc/rtc_base/arraysize.h"
31 #include "webrtc/rtc_base/gunit.h" 34 #include "webrtc/rtc_base/gunit.h"
32 #include "webrtc/rtc_base/stringutils.h" 35 #include "webrtc/rtc_base/stringutils.h"
33 #include "webrtc/test/field_trial.h" 36 #include "webrtc/test/field_trial.h"
37 #include "webrtc/test/gmock.h"
34 38
35 using webrtc::RtpExtension; 39 using webrtc::RtpExtension;
36 40
37 namespace { 41 namespace {
38 static const int kDefaultQpMax = 56; 42 static const int kDefaultQpMax = 56;
39 43
40 static const uint8_t kRedRtxPayloadType = 125; 44 static const uint8_t kRedRtxPayloadType = 125;
41 45
42 static const uint32_t kSsrcs1[] = {1}; 46 static const uint32_t kSsrcs1[] = {1};
43 static const uint32_t kSsrcs3[] = {1, 2, 3}; 47 static const uint32_t kSsrcs3[] = {1, 2, 3};
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 VideoMediaChannel* SetUpForExternalDecoderFactory( 181 VideoMediaChannel* SetUpForExternalDecoderFactory(
178 const std::vector<VideoCodec>& codecs); 182 const std::vector<VideoCodec>& codecs);
179 183
180 void TestExtendedEncoderOveruse(bool use_external_encoder); 184 void TestExtendedEncoderOveruse(bool use_external_encoder);
181 185
182 webrtc::test::ScopedFieldTrials override_field_trials_; 186 webrtc::test::ScopedFieldTrials override_field_trials_;
183 webrtc::RtcEventLogNullImpl event_log_; 187 webrtc::RtcEventLogNullImpl event_log_;
184 // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly 188 // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly
185 // initialized when the constructor is called. 189 // initialized when the constructor is called.
186 std::unique_ptr<webrtc::Call> call_; 190 std::unique_ptr<webrtc::Call> call_;
191 // TODO(magjed): Update all tests to use new video codec factories once the
192 // old factories are deprecated,
193 // https://bugs.chromium.org/p/webrtc/issues/detail?id=7925.
187 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_; 194 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_;
188 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_; 195 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_;
189 WebRtcVideoEngine engine_; 196 WebRtcVideoEngine engine_;
190 VideoCodec default_codec_; 197 VideoCodec default_codec_;
191 std::map<int, int> default_apt_rtx_types_; 198 std::map<int, int> default_apt_rtx_types_;
192 }; 199 };
193 200
194 TEST_F(WebRtcVideoEngineTest, AnnouncesVp9AccordingToBuildFlags) { 201 TEST_F(WebRtcVideoEngineTest, AnnouncesVp9AccordingToBuildFlags) {
195 bool claims_vp9_support = false; 202 bool claims_vp9_support = false;
196 for (const cricket::VideoCodec& codec : engine_.codecs()) { 203 for (const cricket::VideoCodec& codec : engine_.codecs()) {
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 codecs.push_back(GetEngineCodec("H264")); 839 codecs.push_back(GetEngineCodec("H264"));
833 840
834 std::unique_ptr<VideoMediaChannel> channel( 841 std::unique_ptr<VideoMediaChannel> channel(
835 SetUpForExternalDecoderFactory(codecs)); 842 SetUpForExternalDecoderFactory(codecs));
836 843
837 EXPECT_TRUE( 844 EXPECT_TRUE(
838 channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); 845 channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc)));
839 ASSERT_EQ(1u, decoder_factory_.decoders().size()); 846 ASSERT_EQ(1u, decoder_factory_.decoders().size());
840 } 847 }
841 848
849 class MockVideoEncoderFactory : public webrtc::VideoEncoderFactory {
850 public:
851 MOCK_CONST_METHOD0(GetSupportedFormats,
852 std::vector<webrtc::SdpVideoFormat>());
853 MOCK_CONST_METHOD1(QueryVideoEncoder,
854 CodecInfo(const webrtc::SdpVideoFormat&));
855
856 // We need to proxy to a return type that is copyable.
857 std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder(
858 const webrtc::SdpVideoFormat& format) {
859 return std::unique_ptr<webrtc::VideoEncoder>(
860 CreateVideoEncoderProxy(format));
861 }
862 MOCK_METHOD1(CreateVideoEncoderProxy,
863 webrtc::VideoEncoder*(const webrtc::SdpVideoFormat&));
864
865 MOCK_METHOD0(Die, void());
866 ~MockVideoEncoderFactory() { Die(); }
867 };
868
869 class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory {
870 public:
871 MOCK_CONST_METHOD0(GetSupportedFormats,
872 std::vector<webrtc::SdpVideoFormat>());
873
874 // We need to proxy to a return type that is copyable.
875 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder(
876 const webrtc::SdpVideoFormat& format) {
877 return std::unique_ptr<webrtc::VideoDecoder>(
878 CreateVideoDecoderProxy(format));
879 }
880 MOCK_METHOD1(CreateVideoDecoderProxy,
881 webrtc::VideoDecoder*(const webrtc::SdpVideoFormat&));
882
883 MOCK_METHOD0(Die, void());
884 ~MockVideoDecoderFactory() { Die(); }
885 };
886
887 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullFactories) {
888 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory;
889 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory;
890 WebRtcVideoEngine engine(std::move(encoder_factory),
891 std::move(decoder_factory));
892 EXPECT_EQ(0u, engine.codecs().size());
893 }
894
895 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, EmptyFactories) {
896 // |engine| take ownership of the factories.
897 MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory();
898 MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory();
899 WebRtcVideoEngine engine(
900 (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)),
901 (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory)));
902 EXPECT_CALL(*encoder_factory, GetSupportedFormats());
903 EXPECT_EQ(0u, engine.codecs().size());
904 EXPECT_CALL(*encoder_factory, Die());
905 EXPECT_CALL(*decoder_factory, Die());
906 }
907
908 // Test full behavior in the video engine when video codec factories of the new
909 // type are injected supporting the single codec Vp8. Check the returned codecs
910 // from the engine and that we will create a Vp8 encoder and decoder using the
911 // new factories.
912 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, Vp8) {
913 // |engine| take ownership of the factories.
914 MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory();
915 MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory();
916 WebRtcVideoEngine engine(
917 (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)),
918 (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory)));
919 const webrtc::SdpVideoFormat vp8_format("VP8");
920 const std::vector<webrtc::SdpVideoFormat> supported_formats = {vp8_format};
921 EXPECT_CALL(*encoder_factory, GetSupportedFormats())
922 .WillRepeatedly(testing::Return(supported_formats));
923
924 // Verify the codecs from the engine.
925 const std::vector<VideoCodec> engine_codecs = engine.codecs();
926 // Verify an RTX codec has been added correctly.
927 EXPECT_EQ(2u, engine_codecs.size());
928 EXPECT_EQ("VP8", engine_codecs.at(0).name);
929 EXPECT_EQ("rtx", engine_codecs.at(1).name);
930 int associated_payload_type;
931 EXPECT_TRUE(engine_codecs.at(1).GetParam(
932 cricket::kCodecParamAssociatedPayloadType, &associated_payload_type));
933 EXPECT_EQ(engine_codecs.at(0).id, associated_payload_type);
934 // Verify default parameters has been added to the VP8 codec.
935 VerifyCodecHasDefaultFeedbackParams(engine_codecs.at(0));
936
937 // Mock encoder creation. |engine| take ownership of the encoder.
938 webrtc::VideoEncoderFactory::CodecInfo codec_info;
939 codec_info.is_hardware_accelerated = false;
940 codec_info.has_internal_source = false;
941 const webrtc::SdpVideoFormat format("VP8");
942 EXPECT_CALL(*encoder_factory, QueryVideoEncoder(format))
943 .WillRepeatedly(testing::Return(codec_info));
944 FakeWebRtcVideoEncoder* const encoder = new FakeWebRtcVideoEncoder();
945 EXPECT_CALL(*encoder_factory, CreateVideoEncoderProxy(format))
946 .WillOnce(testing::Return(encoder));
947
948 // Mock decoder creation. |engine| take ownership of the decoder.
949 FakeWebRtcVideoDecoder* const decoder = new FakeWebRtcVideoDecoder();
950 EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(format))
951 .WillOnce(testing::Return(decoder));
952
953 // Create a call.
954 webrtc::RtcEventLogNullImpl event_log;
955 std::unique_ptr<webrtc::Call> call(
956 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
957
958 // Create send channel.
959 const int send_ssrc = 123;
960 std::unique_ptr<VideoMediaChannel> send_channel(
961 engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions()));
962 cricket::VideoSendParameters send_parameters;
963 send_parameters.codecs.push_back(engine_codecs.at(0));
964 EXPECT_TRUE(send_channel->SetSendParameters(send_parameters));
965 send_channel->OnReadyToSend(true);
966 EXPECT_TRUE(
967 send_channel->AddSendStream(StreamParams::CreateLegacy(send_ssrc)));
968 EXPECT_TRUE(send_channel->SetSend(true));
969
970 // Create recv channel.
971 const int recv_ssrc = 321;
972 std::unique_ptr<VideoMediaChannel> recv_channel(
973 engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions()));
974 cricket::VideoRecvParameters recv_parameters;
975 recv_parameters.codecs.push_back(engine_codecs.at(0));
976 EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters));
977 EXPECT_TRUE(recv_channel->AddRecvStream(
978 cricket::StreamParams::CreateLegacy(recv_ssrc)));
979
980 // Remove streams previously added to free the encoder and decoder instance.
981 EXPECT_CALL(*encoder_factory, Die());
982 EXPECT_CALL(*decoder_factory, Die());
983 EXPECT_TRUE(send_channel->RemoveSendStream(send_ssrc));
984 EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc));
985 }
986
842 class WebRtcVideoChannelBaseTest 987 class WebRtcVideoChannelBaseTest
843 : public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> { 988 : public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> {
844 protected: 989 protected:
845 typedef VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> Base; 990 typedef VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> Base;
846 991
847 cricket::VideoCodec GetEngineCodec(const std::string& name) { 992 cricket::VideoCodec GetEngineCodec(const std::string& name) {
848 for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { 993 for (const cricket::VideoCodec& engine_codec : engine_.codecs()) {
849 if (CodecNamesEq(name, engine_codec.name)) 994 if (CodecNamesEq(name, engine_codec.name))
850 return engine_codec; 995 return engine_codec;
851 } 996 }
(...skipping 3781 matching lines...) Expand 10 before | Expand all | Expand 10 after
4633 4778
4634 TEST_F(WebRtcVideoChannelSimulcastTest, 4779 TEST_F(WebRtcVideoChannelSimulcastTest,
4635 NoSimulcastScreenshareWithoutConference) { 4780 NoSimulcastScreenshareWithoutConference) {
4636 webrtc::test::ScopedFieldTrials override_field_trials_( 4781 webrtc::test::ScopedFieldTrials override_field_trials_(
4637 "WebRTC-SimulcastScreenshare/Enabled/"); 4782 "WebRTC-SimulcastScreenshare/Enabled/");
4638 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, 4783 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true,
4639 false); 4784 false);
4640 } 4785 }
4641 4786
4642 } // namespace cricket 4787 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698