From 9dc5928eb2b7653049b1c405485ca4351df28fbc Mon Sep 17 00:00:00 2001 From: hbos Date: Wed, 3 Feb 2016 05:09:37 -0800 Subject: [PATCH] Ability to disable the effects of |rtc_use_h264| with DisableRtcUseH264. Renamed the WEBRTC_THIRD_PARTY_H264 macro to WEBRTC_USE_H264 to match flag name. The idea is to be able to turn off H264 from chromium with this function because... 1) The Chromium trybots will soon use this flag, we want to temporarily disable H264 from chromium even if flag is set in case something is broken. That way when we are ready to flip the switch the trybots will run our test code then and not after it is already enabled. 2) If feature is launched and we discover major problems we can easily disable H264 and merge with beta/stable. 3) Or, if feature is behind a *runtime* flag, this is how we would control if it is used or not. The idea is to call DisableRtcUseH264 in chromium's PeerConnectionDependencyFactory. BUG=chromium:500605, chromium:468365 NOTRY=True NOPRESUBMIT=True Review URL: https://codereview.webrtc.org/1657273002 Cr-Commit-Position: refs/heads/master@{#11474} --- webrtc/modules/video_coding/BUILD.gn | 2 +- .../modules/video_coding/codecs/h264/h264.cc | 28 +++++++++++++++---- .../video_coding/codecs/h264/h264.gypi | 5 +++- .../video_coding/codecs/h264/include/h264.h | 6 ++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn index 2d9e08d347..5312e05054 100644 --- a/webrtc/modules/video_coding/BUILD.gn +++ b/webrtc/modules/video_coding/BUILD.gn @@ -139,7 +139,7 @@ source_set("webrtc_h264") { ] if (rtc_use_h264) { - defines += [ "WEBRTC_THIRD_PARTY_H264" ] + defines += [ "WEBRTC_USE_H264" ] if (rtc_initialize_ffmpeg) { defines += [ "WEBRTC_INITIALIZE_FFMPEG" ] } diff --git a/webrtc/modules/video_coding/codecs/h264/h264.cc b/webrtc/modules/video_coding/codecs/h264/h264.cc index 6f7316b10a..9fdc4d4623 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264.cc +++ b/webrtc/modules/video_coding/codecs/h264/h264.cc @@ -11,9 +11,9 @@ #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" -#if defined(WEBRTC_THIRD_PARTY_H264) -#include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" +#if defined(WEBRTC_USE_H264) #include "webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.h" +#include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" #endif #if defined(WEBRTC_IOS) #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h" @@ -25,6 +25,20 @@ namespace webrtc { +namespace { + +#if defined(WEBRTC_USE_H264) +bool g_rtc_use_h264 = true; +#endif + +} // namespace + +void DisableRtcUseH264() { +#if defined(WEBRTC_USE_H264) + g_rtc_use_h264 = false; +#endif +} + // We need this file to be C++ only so it will compile properly for all // platforms. In order to write ObjC specific implementations we use private // externs. This function is defined in h264.mm. @@ -39,8 +53,8 @@ bool IsH264CodecSupported() { return true; } #endif -#if defined(WEBRTC_THIRD_PARTY_H264) - return true; +#if defined(WEBRTC_USE_H264) + return g_rtc_use_h264; #else return false; #endif @@ -54,7 +68,8 @@ H264Encoder* H264Encoder::Create() { return new H264VideoToolboxEncoder(); } #endif -#if defined(WEBRTC_THIRD_PARTY_H264) +#if defined(WEBRTC_USE_H264) + RTC_CHECK(g_rtc_use_h264); LOG(LS_INFO) << "Creating H264EncoderImpl."; return new H264EncoderImpl(); #else @@ -75,7 +90,8 @@ H264Decoder* H264Decoder::Create() { return new H264VideoToolboxDecoder(); } #endif -#if defined(WEBRTC_THIRD_PARTY_H264) +#if defined(WEBRTC_USE_H264) + RTC_CHECK(g_rtc_use_h264); LOG(LS_INFO) << "Creating H264DecoderImpl."; return new H264DecoderImpl(); #else diff --git a/webrtc/modules/video_coding/codecs/h264/h264.gypi b/webrtc/modules/video_coding/codecs/h264/h264.gypi index e82b0fd4cd..185c23de16 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264.gypi +++ b/webrtc/modules/video_coding/codecs/h264/h264.gypi @@ -23,9 +23,12 @@ 'h264_objc.mm', ], }], + # TODO(hbos): Consider renaming this flag and the below macro to + # something which helps distinguish OpenH264/FFmpeg from other H264 + # implementations. ['rtc_use_h264==1', { 'defines': [ - 'WEBRTC_THIRD_PARTY_H264', + 'WEBRTC_USE_H264', ], 'conditions': [ ['rtc_initialize_ffmpeg==1', { diff --git a/webrtc/modules/video_coding/codecs/h264/include/h264.h b/webrtc/modules/video_coding/codecs/h264/include/h264.h index 7f0bbf042b..2c404b2cef 100644 --- a/webrtc/modules/video_coding/codecs/h264/include/h264.h +++ b/webrtc/modules/video_coding/codecs/h264/include/h264.h @@ -27,6 +27,12 @@ namespace webrtc { +// Set to disable the H.264 encoder/decoder implementations that are provided if +// |rtc_use_h264| build flag is true (if false, this function does nothing). +// This function should only be called before or during WebRTC initialization +// and is not thread-safe. +void DisableRtcUseH264(); + class H264Encoder : public VideoEncoder { public: static H264Encoder* Create();