From 1299615838ccb2ae1520ac9724a7f2b7e6c7919c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Sat, 14 May 2016 02:03:18 +0200 Subject: [PATCH] Make sure WebRTC works without libvpx VP9 support. Wires up existing libvpx_build_vp9==0 GYP flag into WebRTC and makes VP9 optional. Change is GYP only for now since libvpx's GN files build VP9 unconditionally. BUG=webrtc:5884 R=kjellander@webrtc.org Review URL: https://codereview.webrtc.org/1970343002 . Cr-Commit-Position: refs/heads/master@{#12741} --- webrtc/build/common.gypi | 6 +++ webrtc/media/engine/webrtcvideoengine2.cc | 4 +- .../engine/webrtcvideoengine2_unittest.cc | 17 ++++++++ webrtc/modules/modules.gyp | 7 +++- .../test/videoprocessor_integrationtest.cc | 3 ++ .../video_coding/codecs/vp9/include/vp9.h | 2 + .../modules/video_coding/codecs/vp9/vp9.gyp | 21 +++++++--- .../video_coding/codecs/vp9/vp9_impl.cc | 8 ++++ .../video_coding/codecs/vp9/vp9_noop.cc | 39 +++++++++++++++++++ webrtc/video/end_to_end_tests.cc | 2 + webrtc/video/full_stack.cc | 4 ++ webrtc/video/video_decoder.cc | 1 + webrtc/video/video_encoder.cc | 1 + webrtc/video/video_send_stream_tests.cc | 4 ++ 14 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 webrtc/modules/video_coding/codecs/vp9/vp9_noop.cc diff --git a/webrtc/build/common.gypi b/webrtc/build/common.gypi index 5335cc8b16..15aa19155f 100644 --- a/webrtc/build/common.gypi +++ b/webrtc/build/common.gypi @@ -102,6 +102,7 @@ 'build_libjpeg%': 1, 'build_libsrtp%': 1, 'build_libvpx%': 1, + 'libvpx_build_vp9%': 1, 'build_libyuv%': 1, 'build_openmax_dl%': 1, 'build_opus%': 1, @@ -447,6 +448,11 @@ 'WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE', ], }], + ['libvpx_build_vp9==0', { + 'defines': [ + 'RTC_DISABLE_VP9', + ], + }], ], # conditions 'direct_dependent_settings': { 'conditions': [ diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc index 00b17c1a9d..332aa89f16 100644 --- a/webrtc/media/engine/webrtcvideoengine2.cc +++ b/webrtc/media/engine/webrtcvideoengine2.cc @@ -29,6 +29,7 @@ #include "webrtc/media/engine/webrtcvoiceengine.h" #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" +#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" #include "webrtc/system_wrappers/include/field_trial.h" #include "webrtc/video_decoder.h" #include "webrtc/video_encoder.h" @@ -159,7 +160,8 @@ bool CodecIsInternallySupported(const std::string& codec_name) { return true; } if (CodecNamesEq(codec_name, kVp9CodecName)) { - return true; + return webrtc::VP9Encoder::IsSupported() && + webrtc::VP9Decoder::IsSupported(); } if (CodecNamesEq(codec_name, kH264CodecName)) { return webrtc::H264Encoder::IsSupported() && diff --git a/webrtc/media/engine/webrtcvideoengine2_unittest.cc b/webrtc/media/engine/webrtcvideoengine2_unittest.cc index b3357d2c61..3b5aec4e9d 100644 --- a/webrtc/media/engine/webrtcvideoengine2_unittest.cc +++ b/webrtc/media/engine/webrtcvideoengine2_unittest.cc @@ -150,6 +150,21 @@ class WebRtcVideoEngine2Test : public ::testing::Test { std::map default_apt_rtx_types_; }; +TEST_F(WebRtcVideoEngine2Test, AnnouncesVp9AccordingToBuildFlags) { + bool claims_vp9_support = false; + for (const cricket::VideoCodec& codec : engine_.codecs()) { + if (codec.name == "VP9") { + claims_vp9_support = true; + break; + } + } +#if defined(RTC_DISABLE_VP9) + EXPECT_FALSE(claims_vp9_support); +#else + EXPECT_TRUE(claims_vp9_support); +#endif // defined(RTC_DISABLE_VP9) +} + TEST_F(WebRtcVideoEngine2Test, DefaultRtxCodecHasAssociatedPayloadTypeSet) { std::vector engine_codecs = engine_.codecs(); for (size_t i = 0; i < engine_codecs.size(); ++i) { @@ -414,6 +429,7 @@ TEST_F(WebRtcVideoEngine2Test, DisablesFullEncoderTimeForNonExternalEncoders) { TestExtendedEncoderOveruse(false); } +#if !defined(RTC_DISABLE_VP9) TEST_F(WebRtcVideoEngine2Test, CanConstructDecoderForVp9EncoderFactory) { cricket::FakeWebRtcVideoEncoderFactory encoder_factory; encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP9, "VP9"); @@ -426,6 +442,7 @@ TEST_F(WebRtcVideoEngine2Test, CanConstructDecoderForVp9EncoderFactory) { EXPECT_TRUE( channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); } +#endif // !defined(RTC_DISABLE_VP9) TEST_F(WebRtcVideoEngine2Test, PropagatesInputFrameTimestamp) { cricket::FakeWebRtcVideoEncoderFactory encoder_factory; diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp index 4a5f456c8f..145f4c04f1 100644 --- a/webrtc/modules/modules.gyp +++ b/webrtc/modules/modules.gyp @@ -63,7 +63,6 @@ '<(webrtc_root)/common.gyp:webrtc_common', '<(webrtc_root)/common_video/common_video.gyp:common_video', '<(webrtc_root)/modules/video_coding/codecs/vp8/vp8.gyp:webrtc_vp8', - '<(webrtc_root)/modules/video_coding/codecs/vp9/vp9.gyp:webrtc_vp9', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/test/metrics.gyp:metrics', '<(webrtc_root)/test/test.gyp:test_support', @@ -363,7 +362,6 @@ 'video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc', 'video_coding/codecs/vp8/simulcast_unittest.cc', 'video_coding/codecs/vp8/simulcast_unittest.h', - 'video_coding/codecs/vp9/screenshare_layers_unittest.cc', 'video_coding/include/mock/mock_vcm_callbacks.h', 'video_coding/decoding_state_unittest.cc', 'video_coding/histogram_unittest.cc', @@ -390,6 +388,11 @@ 'video_processing/test/video_processing_unittest.h', ], 'conditions': [ + ['libvpx_build_vp9==1', { + 'sources': [ + 'video_coding/codecs/vp9/screenshare_layers_unittest.cc', + ], + }], ['enable_bwe_test_logging==1', { 'defines': [ 'BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1' ], }, { diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc index 835a3dc36e..9f361dc626 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc @@ -626,6 +626,7 @@ TEST_F(VideoProcessorIntegrationTest, Process0PercentPacketLossH264) { // Fails on iOS. See webrtc:4755. #if !defined(WEBRTC_IOS) +#if !defined(RTC_DISABLE_VP9) // VP9: Run with no packet loss and fixed bitrate. Quality should be very high. // One key frame (first frame only) in sequence. Setting |key_frame_interval| // to -1 below means no periodic key frames in test. @@ -780,6 +781,8 @@ TEST_F(VideoProcessorIntegrationTest, ProcessNoLossSpatialResizeFrameDropVP9) { // TODO(marpan): Add temporal layer test for VP9, once changes are in // vp9 wrapper for this. +#endif // !defined(RTC_DISABLE_VP9) + // VP8: Run with no packet loss and fixed bitrate. Quality should be very high. // One key frame (first frame only) in sequence. Setting |key_frame_interval| // to -1 below means no periodic key frames in test. diff --git a/webrtc/modules/video_coding/codecs/vp9/include/vp9.h b/webrtc/modules/video_coding/codecs/vp9/include/vp9.h index 3bcbe46b3a..3b726a0cc5 100644 --- a/webrtc/modules/video_coding/codecs/vp9/include/vp9.h +++ b/webrtc/modules/video_coding/codecs/vp9/include/vp9.h @@ -18,6 +18,7 @@ namespace webrtc { class VP9Encoder : public VideoEncoder { public: + static bool IsSupported(); static VP9Encoder* Create(); virtual ~VP9Encoder() {} @@ -25,6 +26,7 @@ class VP9Encoder : public VideoEncoder { class VP9Decoder : public VideoDecoder { public: + static bool IsSupported(); static VP9Decoder* Create(); virtual ~VP9Decoder() {} diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9.gyp b/webrtc/modules/video_coding/codecs/vp9/vp9.gyp index cd5201f8aa..9124e5fad3 100644 --- a/webrtc/modules/video_coding/codecs/vp9/vp9.gyp +++ b/webrtc/modules/video_coding/codecs/vp9/vp9.gyp @@ -20,6 +20,21 @@ '<(libvpx_dir)/libvpx.gyp:libvpx', ], }], + ['libvpx_build_vp9==1', { + 'sources': [ + 'screenshare_layers.cc', + 'screenshare_layers.h', + 'vp9_frame_buffer_pool.cc', + 'vp9_frame_buffer_pool.h', + 'vp9_impl.cc', + 'vp9_impl.h', + ], + }, { + 'sources': [ + 'vp9_noop.cc', + ], + } + ], ], 'dependencies': [ '<(webrtc_root)/common_video/common_video.gyp:common_video', @@ -28,12 +43,6 @@ ], 'sources': [ 'include/vp9.h', - 'screenshare_layers.cc', - 'screenshare_layers.h', - 'vp9_frame_buffer_pool.cc', - 'vp9_frame_buffer_pool.h', - 'vp9_impl.cc', - 'vp9_impl.h', ], }, ], diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc index d5f83c4335..750f7427cd 100644 --- a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -47,6 +47,10 @@ int GetCpuSpeed(int width, int height) { #endif } +bool VP9Encoder::IsSupported() { + return true; +} + VP9Encoder* VP9Encoder::Create() { return new VP9EncoderImpl(); } @@ -823,6 +827,10 @@ const char* VP9EncoderImpl::ImplementationName() const { return "libvpx"; } +bool VP9Decoder::IsSupported() { + return true; +} + VP9Decoder* VP9Decoder::Create() { return new VP9DecoderImpl(); } diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9_noop.cc b/webrtc/modules/video_coding/codecs/vp9/vp9_noop.cc new file mode 100644 index 0000000000..cc37e1adbb --- /dev/null +++ b/webrtc/modules/video_coding/codecs/vp9/vp9_noop.cc @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 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. + * + */ + +#if !defined(RTC_DISABLE_VP9) +#error +#endif // !defined(RTC_DISABLE_VP9) + +#include "webrtc/base/checks.h" +#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" + +namespace webrtc { + +bool VP9Encoder::IsSupported() { + return false; +} + +VP9Encoder* VP9Encoder::Create() { + RTC_NOTREACHED(); + return nullptr; +} + +bool VP9Decoder::IsSupported() { + return false; +} + +VP9Decoder* VP9Decoder::Create() { + RTC_NOTREACHED(); + return nullptr; +} + +} // namespace webrtc diff --git a/webrtc/video/end_to_end_tests.cc b/webrtc/video/end_to_end_tests.cc index 8b2abc8e29..730c96a0de 100644 --- a/webrtc/video/end_to_end_tests.cc +++ b/webrtc/video/end_to_end_tests.cc @@ -333,6 +333,7 @@ TEST_F(EndToEndTest, SendsAndReceivesVP8Rotation90) { RunBaseTest(&test); } +#if !defined(RTC_DISABLE_VP9) TEST_F(EndToEndTest, SendsAndReceivesVP9) { CodecObserver test(500, kVideoRotation_0, "VP9", VideoEncoder::Create(VideoEncoder::kVp9), @@ -346,6 +347,7 @@ TEST_F(EndToEndTest, SendsAndReceivesVP9VideoRotation90) { VP9Decoder::Create()); RunBaseTest(&test); } +#endif // !defined(RTC_DISABLE_VP9) #if defined(WEBRTC_END_TO_END_H264_TESTS) diff --git a/webrtc/video/full_stack.cc b/webrtc/video/full_stack.cc index 8a97ba8a9a..0399ed2ed7 100644 --- a/webrtc/video/full_stack.cc +++ b/webrtc/video/full_stack.cc @@ -56,6 +56,7 @@ class FullStackTest : public VideoQualityTest { // logs // bool // }; +#if !defined(RTC_DISABLE_VP9) TEST_F(FullStackTest, ForemanCifWithoutPacketLossVp9) { ForemanCifWithoutPacketLoss("VP9"); } @@ -63,6 +64,7 @@ TEST_F(FullStackTest, ForemanCifWithoutPacketLossVp9) { TEST_F(FullStackTest, ForemanCifPlr5Vp9) { ForemanCifPlr5("VP9"); } +#endif // !defined(RTC_DISABLE_VP9) TEST_F(FullStackTest, ParisQcifWithoutPacketLoss) { VideoQualityTest::Params paris_qcif = { @@ -200,6 +202,7 @@ TEST_F(FullStackTest, ScreenshareSlidesVP8_2TL_VeryLossyNet) { RunTest(screenshare); } +#if !defined(RTC_DISABLE_VP9) TEST_F(FullStackTest, ScreenshareSlidesVP9_2SL) { VideoQualityTest::Params screenshare = { {1850, 1110, 5, 50000, 200000, 2000000, "VP9", 1, 0, 400000}, @@ -211,4 +214,5 @@ TEST_F(FullStackTest, ScreenshareSlidesVP9_2SL) { {std::vector(), 0, 2, 1}}; RunTest(screenshare); } +#endif // !defined(RTC_DISABLE_VP9) } // namespace webrtc diff --git a/webrtc/video/video_decoder.cc b/webrtc/video/video_decoder.cc index 602799e075..5bf503cd80 100644 --- a/webrtc/video/video_decoder.cc +++ b/webrtc/video/video_decoder.cc @@ -25,6 +25,7 @@ VideoDecoder* VideoDecoder::Create(VideoDecoder::DecoderType codec_type) { case kVp8: return VP8Decoder::Create(); case kVp9: + RTC_DCHECK(VP9Decoder::IsSupported()); return VP9Decoder::Create(); case kUnsupportedCodec: LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; diff --git a/webrtc/video/video_encoder.cc b/webrtc/video/video_encoder.cc index 361f11f587..1534a97fdf 100644 --- a/webrtc/video/video_encoder.cc +++ b/webrtc/video/video_encoder.cc @@ -25,6 +25,7 @@ VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) { case kVp8: return VP8Encoder::Create(); case kVp9: + RTC_DCHECK(VP9Encoder::IsSupported()); return VP9Encoder::Create(); case kUnsupportedCodec: RTC_NOTREACHED(); diff --git a/webrtc/video/video_send_stream_tests.cc b/webrtc/video/video_send_stream_tests.cc index e8aca34c00..095ff4ece3 100644 --- a/webrtc/video/video_send_stream_tests.cc +++ b/webrtc/video/video_send_stream_tests.cc @@ -479,10 +479,12 @@ TEST_F(VideoSendStreamTest, DoesUtilizeRedForVp8WithNackEnabled) { RunBaseTest(&test); } +#if !defined(RTC_DISABLE_VP9) TEST_F(VideoSendStreamTest, DoesUtilizeRedForVp9WithNackEnabled) { FecObserver test(false, true, true, "VP9"); RunBaseTest(&test); } +#endif // !defined(RTC_DISABLE_VP9) void VideoSendStreamTest::TestNackRetransmission( uint32_t retransmit_ssrc, @@ -1886,6 +1888,7 @@ TEST_F(VideoSendStreamTest, ReportsSentResolution) { RunBaseTest(&test); } +#if !defined(RTC_DISABLE_VP9) class Vp9HeaderObserver : public test::SendTest { public: Vp9HeaderObserver() @@ -2293,5 +2296,6 @@ TEST_F(VideoSendStreamTest, Vp9FlexModeRefCount) { RunBaseTest(&test); } +#endif // !defined(RTC_DISABLE_VP9) } // namespace webrtc