OLD | NEW |
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/video_decoder_factory.h" |
16 #include "webrtc/api/video_codecs/video_encoder.h" | 17 #include "webrtc/api/video_codecs/video_encoder.h" |
| 18 #include "webrtc/api/video_codecs/video_encoder_factory.h" |
17 #include "webrtc/call/flexfec_receive_stream.h" | 19 #include "webrtc/call/flexfec_receive_stream.h" |
18 #include "webrtc/common_video/h264/profile_level_id.h" | 20 #include "webrtc/common_video/h264/profile_level_id.h" |
19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
20 #include "webrtc/media/base/mediaconstants.h" | 22 #include "webrtc/media/base/mediaconstants.h" |
21 #include "webrtc/media/base/rtputils.h" | 23 #include "webrtc/media/base/rtputils.h" |
22 #include "webrtc/media/base/testutils.h" | 24 #include "webrtc/media/base/testutils.h" |
23 #include "webrtc/media/base/videoengine_unittest.h" | 25 #include "webrtc/media/base/videoengine_unittest.h" |
24 #include "webrtc/media/engine/constants.h" | 26 #include "webrtc/media/engine/constants.h" |
25 #include "webrtc/media/engine/fakewebrtccall.h" | 27 #include "webrtc/media/engine/fakewebrtccall.h" |
26 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 28 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
27 #include "webrtc/media/engine/simulcast.h" | 29 #include "webrtc/media/engine/simulcast.h" |
28 #include "webrtc/media/engine/webrtcvideoengine.h" | 30 #include "webrtc/media/engine/webrtcvideoengine.h" |
29 #include "webrtc/media/engine/webrtcvoiceengine.h" | 31 #include "webrtc/media/engine/webrtcvoiceengine.h" |
30 #include "webrtc/rtc_base/arraysize.h" | 32 #include "webrtc/rtc_base/arraysize.h" |
31 #include "webrtc/rtc_base/gunit.h" | 33 #include "webrtc/rtc_base/gunit.h" |
32 #include "webrtc/rtc_base/stringutils.h" | 34 #include "webrtc/rtc_base/stringutils.h" |
33 #include "webrtc/test/field_trial.h" | 35 #include "webrtc/test/field_trial.h" |
| 36 #include "webrtc/test/gmock.h" |
34 | 37 |
35 using webrtc::RtpExtension; | 38 using webrtc::RtpExtension; |
36 | 39 |
37 namespace { | 40 namespace { |
38 static const int kDefaultQpMax = 56; | 41 static const int kDefaultQpMax = 56; |
39 | 42 |
40 static const uint8_t kRedRtxPayloadType = 125; | 43 static const uint8_t kRedRtxPayloadType = 125; |
41 | 44 |
42 static const uint32_t kSsrcs1[] = {1}; | 45 static const uint32_t kSsrcs1[] = {1}; |
43 static const uint32_t kSsrcs3[] = {1, 2, 3}; | 46 static const uint32_t kSsrcs3[] = {1, 2, 3}; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 VideoMediaChannel* SetUpForExternalDecoderFactory( | 163 VideoMediaChannel* SetUpForExternalDecoderFactory( |
161 const std::vector<VideoCodec>& codecs); | 164 const std::vector<VideoCodec>& codecs); |
162 | 165 |
163 void TestExtendedEncoderOveruse(bool use_external_encoder); | 166 void TestExtendedEncoderOveruse(bool use_external_encoder); |
164 | 167 |
165 webrtc::test::ScopedFieldTrials override_field_trials_; | 168 webrtc::test::ScopedFieldTrials override_field_trials_; |
166 webrtc::RtcEventLogNullImpl event_log_; | 169 webrtc::RtcEventLogNullImpl event_log_; |
167 // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly | 170 // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly |
168 // initialized when the constructor is called. | 171 // initialized when the constructor is called. |
169 std::unique_ptr<webrtc::Call> call_; | 172 std::unique_ptr<webrtc::Call> call_; |
| 173 // TODO(magjed): Update all tests to use new video codec factories once the |
| 174 // old factories are deprecated, |
| 175 // https://bugs.chromium.org/p/webrtc/issues/detail?id=7925. |
170 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_; | 176 cricket::FakeWebRtcVideoEncoderFactory encoder_factory_; |
171 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_; | 177 cricket::FakeWebRtcVideoDecoderFactory decoder_factory_; |
172 WebRtcVideoEngine engine_; | 178 WebRtcVideoEngine engine_; |
173 VideoCodec default_codec_; | 179 VideoCodec default_codec_; |
174 std::map<int, int> default_apt_rtx_types_; | 180 std::map<int, int> default_apt_rtx_types_; |
175 }; | 181 }; |
176 | 182 |
177 TEST_F(WebRtcVideoEngineTest, AnnouncesVp9AccordingToBuildFlags) { | 183 TEST_F(WebRtcVideoEngineTest, AnnouncesVp9AccordingToBuildFlags) { |
178 bool claims_vp9_support = false; | 184 bool claims_vp9_support = false; |
179 for (const cricket::VideoCodec& codec : engine_.codecs()) { | 185 for (const cricket::VideoCodec& codec : engine_.codecs()) { |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 codecs.push_back(GetEngineCodec("H264")); | 821 codecs.push_back(GetEngineCodec("H264")); |
816 | 822 |
817 std::unique_ptr<VideoMediaChannel> channel( | 823 std::unique_ptr<VideoMediaChannel> channel( |
818 SetUpForExternalDecoderFactory(codecs)); | 824 SetUpForExternalDecoderFactory(codecs)); |
819 | 825 |
820 EXPECT_TRUE( | 826 EXPECT_TRUE( |
821 channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); | 827 channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
822 ASSERT_EQ(1u, decoder_factory_.decoders().size()); | 828 ASSERT_EQ(1u, decoder_factory_.decoders().size()); |
823 } | 829 } |
824 | 830 |
| 831 class MockVideoEncoderFactory : public webrtc::VideoEncoderFactory { |
| 832 public: |
| 833 MOCK_CONST_METHOD0(GetSupportedCodecs, std::vector<VideoCodec>()); |
| 834 MOCK_CONST_METHOD1(QueryVideoEncoder, CodecInfo(const VideoCodec&)); |
| 835 |
| 836 // We need to proxy to a return type that is copyable. |
| 837 std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder( |
| 838 const cricket::VideoCodec& codec) { |
| 839 return std::unique_ptr<webrtc::VideoEncoder>( |
| 840 CreateVideoEncoderProxy(codec)); |
| 841 } |
| 842 MOCK_METHOD1(CreateVideoEncoderProxy, |
| 843 webrtc::VideoEncoder*(const VideoCodec&)); |
| 844 |
| 845 MOCK_METHOD0(Die, void()); |
| 846 ~MockVideoEncoderFactory() { Die(); } |
| 847 }; |
| 848 |
| 849 class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory { |
| 850 public: |
| 851 MOCK_CONST_METHOD0(GetSupportedCodecs, std::vector<VideoCodec>()); |
| 852 |
| 853 // We need to proxy to a return type that is copyable. |
| 854 std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( |
| 855 const cricket::VideoCodec& codec) { |
| 856 return std::unique_ptr<webrtc::VideoDecoder>( |
| 857 CreateVideoDecoderProxy(codec)); |
| 858 } |
| 859 MOCK_METHOD1(CreateVideoDecoderProxy, |
| 860 webrtc::VideoDecoder*(const VideoCodec&)); |
| 861 |
| 862 MOCK_METHOD0(Die, void()); |
| 863 ~MockVideoDecoderFactory() { Die(); } |
| 864 }; |
| 865 |
| 866 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullFactories) { |
| 867 std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory; |
| 868 std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory; |
| 869 WebRtcVideoEngine engine(std::move(encoder_factory), |
| 870 std::move(decoder_factory)); |
| 871 EXPECT_EQ(0u, engine.codecs().size()); |
| 872 } |
| 873 |
| 874 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, EmptyFactories) { |
| 875 // |engine| take ownership of the factories. |
| 876 MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory(); |
| 877 MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory(); |
| 878 WebRtcVideoEngine engine( |
| 879 (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 880 (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 881 EXPECT_CALL(*encoder_factory, GetSupportedCodecs()); |
| 882 EXPECT_EQ(0u, engine.codecs().size()); |
| 883 EXPECT_CALL(*encoder_factory, Die()); |
| 884 EXPECT_CALL(*decoder_factory, Die()); |
| 885 } |
| 886 |
| 887 // Test full behavior in the video engine when video codec factories of the new |
| 888 // type are injected supporting the single codec Vp8. Check the returned codecs |
| 889 // from the engine and that we will create a Vp8 encoder and decoder using the |
| 890 // new factories. |
| 891 TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, Vp8) { |
| 892 // |engine| take ownership of the factories. |
| 893 MockVideoEncoderFactory* encoder_factory = new MockVideoEncoderFactory(); |
| 894 MockVideoDecoderFactory* decoder_factory = new MockVideoDecoderFactory(); |
| 895 WebRtcVideoEngine engine( |
| 896 (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 897 (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 898 const VideoCodec vp8_codec("VP8"); |
| 899 const std::vector<VideoCodec> supported_codecs = {vp8_codec}; |
| 900 EXPECT_CALL(*encoder_factory, GetSupportedCodecs()) |
| 901 .WillRepeatedly(testing::Return(supported_codecs)); |
| 902 |
| 903 // Verify the codecs from the engine. |
| 904 const std::vector<VideoCodec> engine_codecs = engine.codecs(); |
| 905 // Verify an RTX codec has been added correctly. |
| 906 EXPECT_EQ(2u, engine_codecs.size()); |
| 907 EXPECT_EQ("VP8", engine_codecs.at(0).name); |
| 908 EXPECT_EQ("rtx", engine_codecs.at(1).name); |
| 909 int associated_payload_type; |
| 910 EXPECT_TRUE(engine_codecs.at(1).GetParam( |
| 911 cricket::kCodecParamAssociatedPayloadType, &associated_payload_type)); |
| 912 EXPECT_EQ(engine_codecs.at(0).id, associated_payload_type); |
| 913 // Verify default parameters has been added to the VP8 codec. |
| 914 VerifyCodecHasDefaultFeedbackParams(engine_codecs.at(0)); |
| 915 |
| 916 // Mock encoder creation. |engine| take ownership of the encoder. |
| 917 webrtc::VideoEncoderFactory::CodecInfo codec_info; |
| 918 codec_info.is_hardware_accelerated = false; |
| 919 codec_info.has_internal_source = false; |
| 920 EXPECT_CALL(*encoder_factory, QueryVideoEncoder(engine_codecs.at(0))) |
| 921 .WillRepeatedly(testing::Return(codec_info)); |
| 922 FakeWebRtcVideoEncoder* const encoder = new FakeWebRtcVideoEncoder(); |
| 923 EXPECT_CALL(*encoder_factory, CreateVideoEncoderProxy(engine_codecs.at(0))) |
| 924 .WillOnce(testing::Return(encoder)); |
| 925 |
| 926 // Mock decoder creation. |engine| take ownership of the decoder. |
| 927 FakeWebRtcVideoDecoder* const decoder = new FakeWebRtcVideoDecoder(); |
| 928 EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(engine_codecs.at(0))) |
| 929 .WillOnce(testing::Return(decoder)); |
| 930 |
| 931 // Create a call. |
| 932 webrtc::RtcEventLogNullImpl event_log; |
| 933 std::unique_ptr<webrtc::Call> call( |
| 934 webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
| 935 |
| 936 // Create send channel. |
| 937 const int send_ssrc = 123; |
| 938 std::unique_ptr<VideoMediaChannel> send_channel( |
| 939 engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 940 cricket::VideoSendParameters send_parameters; |
| 941 send_parameters.codecs.push_back(engine_codecs.at(0)); |
| 942 EXPECT_TRUE(send_channel->SetSendParameters(send_parameters)); |
| 943 send_channel->OnReadyToSend(true); |
| 944 EXPECT_TRUE( |
| 945 send_channel->AddSendStream(StreamParams::CreateLegacy(send_ssrc))); |
| 946 EXPECT_TRUE(send_channel->SetSend(true)); |
| 947 |
| 948 // Create recv channel. |
| 949 const int recv_ssrc = 321; |
| 950 std::unique_ptr<VideoMediaChannel> recv_channel( |
| 951 engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 952 cricket::VideoRecvParameters recv_parameters; |
| 953 recv_parameters.codecs.push_back(engine_codecs.at(0)); |
| 954 EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters)); |
| 955 EXPECT_TRUE(recv_channel->AddRecvStream( |
| 956 cricket::StreamParams::CreateLegacy(recv_ssrc))); |
| 957 |
| 958 // Remove streams previously added to free the encoder and decoder instance. |
| 959 EXPECT_CALL(*encoder_factory, Die()); |
| 960 EXPECT_CALL(*decoder_factory, Die()); |
| 961 EXPECT_TRUE(send_channel->RemoveSendStream(send_ssrc)); |
| 962 EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc)); |
| 963 } |
| 964 |
825 class WebRtcVideoChannelBaseTest | 965 class WebRtcVideoChannelBaseTest |
826 : public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> { | 966 : public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> { |
827 protected: | 967 protected: |
828 typedef VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> Base; | 968 typedef VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> Base; |
829 | 969 |
830 cricket::VideoCodec GetEngineCodec(const std::string& name) { | 970 cricket::VideoCodec GetEngineCodec(const std::string& name) { |
831 for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { | 971 for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { |
832 if (CodecNamesEq(name, engine_codec.name)) | 972 if (CodecNamesEq(name, engine_codec.name)) |
833 return engine_codec; | 973 return engine_codec; |
834 } | 974 } |
(...skipping 3770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4605 | 4745 |
4606 TEST_F(WebRtcVideoChannelSimulcastTest, | 4746 TEST_F(WebRtcVideoChannelSimulcastTest, |
4607 NoSimulcastScreenshareWithoutConference) { | 4747 NoSimulcastScreenshareWithoutConference) { |
4608 webrtc::test::ScopedFieldTrials override_field_trials_( | 4748 webrtc::test::ScopedFieldTrials override_field_trials_( |
4609 "WebRTC-SimulcastScreenshare/Enabled/"); | 4749 "WebRTC-SimulcastScreenshare/Enabled/"); |
4610 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, | 4750 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
4611 false); | 4751 false); |
4612 } | 4752 } |
4613 | 4753 |
4614 } // namespace cricket | 4754 } // namespace cricket |
OLD | NEW |