From 849b3aeb718671cb1863d4039fb0bc3fffa5fc76 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Fri, 29 Sep 2017 17:54:09 +0200 Subject: [PATCH] Move list of supported H264 codecs from InternalEncoderFactory to h264.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL is a clean-up to prepare for adding more supported codecs for the internal H264 SW codec. Bug: webrtc:8317 Change-Id: If483d05c01c40bbc81cbd1a6aad89961689714ef Reviewed-on: https://webrtc-review.googlesource.com/4940 Reviewed-by: Sami Kalliomäki Reviewed-by: Rasmus Brandt Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#20105} --- media/engine/internalencoderfactory.cc | 26 +++++++--------- modules/video_coding/BUILD.gn | 1 + modules/video_coding/codecs/h264/h264.cc | 30 ++++++++++++++----- .../video_coding/codecs/h264/include/h264.h | 8 +++++ 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/media/engine/internalencoderfactory.cc b/media/engine/internalencoderfactory.cc index 5f7a4ba2c3..e55ca91495 100644 --- a/media/engine/internalencoderfactory.cc +++ b/media/engine/internalencoderfactory.cc @@ -34,24 +34,18 @@ bool IsFlexfecAdvertisedFieldTrialEnabled() { } // namespace InternalEncoderFactory::InternalEncoderFactory() { - supported_codecs_.push_back(cricket::VideoCodec(kVp8CodecName)); + supported_codecs_.push_back(VideoCodec(kVp8CodecName)); if (webrtc::VP9Encoder::IsSupported()) - supported_codecs_.push_back(cricket::VideoCodec(kVp9CodecName)); - if (webrtc::H264Encoder::IsSupported()) { - cricket::VideoCodec codec(kH264CodecName); - // TODO(magjed): Move setting these parameters into webrtc::H264Encoder - // instead. - codec.SetParam(kH264FmtpProfileLevelId, - kH264ProfileLevelConstrainedBaseline); - codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1"); - supported_codecs_.push_back(std::move(codec)); - } + supported_codecs_.push_back(VideoCodec(kVp9CodecName)); - supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName)); - supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName)); + for (const webrtc::SdpVideoFormat& format : webrtc::SupportedH264Codecs()) + supported_codecs_.push_back(VideoCodec(format)); + + supported_codecs_.push_back(VideoCodec(kRedCodecName)); + supported_codecs_.push_back(VideoCodec(kUlpfecCodecName)); if (IsFlexfecAdvertisedFieldTrialEnabled()) { - cricket::VideoCodec flexfec_codec(kFlexfecCodecName); + VideoCodec flexfec_codec(kFlexfecCodecName); // This value is currently arbitrarily set to 10 seconds. (The unit // is microseconds.) This parameter MUST be present in the SDP, but // we never use the actual value anywhere in our code however. @@ -69,7 +63,7 @@ InternalEncoderFactory::~InternalEncoderFactory() {} // WebRtcVideoEncoderFactory implementation. webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder( - const cricket::VideoCodec& codec) { + const VideoCodec& codec) { const webrtc::VideoCodecType codec_type = webrtc::PayloadStringToCodecType(codec.name); switch (codec_type) { @@ -84,7 +78,7 @@ webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder( } } -const std::vector& +const std::vector& InternalEncoderFactory::supported_codecs() const { return supported_codecs_; } diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index 785533ace7..452f0bf445 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -188,6 +188,7 @@ rtc_static_library("webrtc_h264") { defines = [] deps = [ ":video_coding_utility", + "../../api/video_codecs:video_codecs_api", "../../media:rtc_media_base", "../../rtc_base:rtc_base_approved", "../../system_wrappers", diff --git a/modules/video_coding/codecs/h264/h264.cc b/modules/video_coding/codecs/h264/h264.cc index 471ca24984..c24162d890 100644 --- a/modules/video_coding/codecs/h264/h264.cc +++ b/modules/video_coding/codecs/h264/h264.cc @@ -11,6 +11,8 @@ #include "modules/video_coding/codecs/h264/include/h264.h" +#include "api/video_codecs/sdp_video_format.h" + #if defined(WEBRTC_USE_H264) #include "modules/video_coding/codecs/h264/h264_decoder_impl.h" #include "modules/video_coding/codecs/h264/h264_encoder_impl.h" @@ -27,6 +29,15 @@ namespace { bool g_rtc_use_h264 = true; #endif +// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg). +bool IsH264CodecSupported() { +#if defined(WEBRTC_USE_H264) + return g_rtc_use_h264; +#else + return false; +#endif +} + } // namespace void DisableRtcUseH264() { @@ -35,13 +46,18 @@ void DisableRtcUseH264() { #endif } -// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg). -bool IsH264CodecSupported() { -#if defined(WEBRTC_USE_H264) - return g_rtc_use_h264; -#else - return false; -#endif +std::vector SupportedH264Codecs() { + if (!IsH264CodecSupported()) + return std::vector(); + std::vector codecs; + + codecs.push_back(SdpVideoFormat( + cricket::kH264CodecName, {{cricket::kH264FmtpProfileLevelId, + cricket::kH264ProfileLevelConstrainedBaseline}, + {cricket::kH264FmtpLevelAsymmetryAllowed, "1"}, + {cricket::kH264FmtpPacketizationMode, "1"}})); + + return codecs; } H264Encoder* H264Encoder::Create(const cricket::VideoCodec& codec) { diff --git a/modules/video_coding/codecs/h264/include/h264.h b/modules/video_coding/codecs/h264/include/h264.h index d4c8c21613..6c93b34d69 100644 --- a/modules/video_coding/codecs/h264/include/h264.h +++ b/modules/video_coding/codecs/h264/include/h264.h @@ -12,17 +12,25 @@ #ifndef MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_H_ #define MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_H_ +#include + #include "media/base/codec.h" #include "modules/video_coding/include/video_codec_interface.h" namespace webrtc { +struct SdpVideoFormat; + // 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(); +// Returns a vector with all supported internal H264 profiles that we can +// negotiate in SDP, in order of preference. +std::vector SupportedH264Codecs(); + class H264Encoder : public VideoEncoder { public: static H264Encoder* Create(const cricket::VideoCodec& codec);