From c343786a7ac9dc47e8749d8a9e5dc612e230df65 Mon Sep 17 00:00:00 2001 From: Krzysztof Lesiak Date: Mon, 4 Feb 2019 16:11:56 +0100 Subject: [PATCH 1/4] Add new encoder factory so UWP encoder can be used with rtc_use_builtin_sw_codecs=false --- .../winuwp_h264/winuwp_h264_factory.cc | 29 ++++++++++++++++++- third_party/winuwp_h264/winuwp_h264_factory.h | 11 +++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/third_party/winuwp_h264/winuwp_h264_factory.cc b/third_party/winuwp_h264/winuwp_h264_factory.cc index 99714ca21d..f7f0c1ed5a 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.cc +++ b/third_party/winuwp_h264/winuwp_h264_factory.cc @@ -14,7 +14,7 @@ #include "third_party/winuwp_h264/H264Decoder/H264Decoder.h" #include "media/engine/webrtcvideoencoderfactory.h" #include "media/engine/webrtcvideodecoderfactory.h" - +#include "rtc_base/logging.h" namespace webrtc { @@ -61,5 +61,32 @@ namespace webrtc { delete decoder; } + std::vector WinUWPH264EncoderFactoryNew::GetSupportedFormats() + const { + std::vector formats = { SdpVideoFormat("H264") }; + return formats; + } + + VideoEncoderFactory::CodecInfo WinUWPH264EncoderFactoryNew::QueryVideoEncoder( + const SdpVideoFormat& format) const { + CodecInfo info; + //not sure about this. mf does support hw MFTs but doesn't really tell us + //when using sink writer. it's more of a "silent sw fallback if hw not available" thing + info.is_hardware_accelerated = false; + info.has_internal_source = false; + return info; + } + + std::unique_ptr WinUWPH264EncoderFactoryNew::CreateVideoEncoder( + const SdpVideoFormat& format) { + if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName)) { + return std::make_unique(); + } + + RTC_LOG(LS_ERROR) << "Trying to create encoder of unsupported format " + << format.name; + return nullptr; + } + } // namespace webrtc diff --git a/third_party/winuwp_h264/winuwp_h264_factory.h b/third_party/winuwp_h264/winuwp_h264_factory.h index a4e2399c34..4bce48614f 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.h +++ b/third_party/winuwp_h264/winuwp_h264_factory.h @@ -15,6 +15,7 @@ #include "media/engine/webrtcvideoencoderfactory.h" #include "media/engine/webrtcvideodecoderfactory.h" #include "media/base/codec.h" +#include "api/video_codecs/video_encoder_factory.h" namespace webrtc { @@ -34,6 +35,16 @@ class WinUWPH264EncoderFactory : public cricket::WebRtcVideoEncoderFactory { std::vector codecList_; }; +class WinUWPH264EncoderFactoryNew : public VideoEncoderFactory { + public: + std::vector GetSupportedFormats() const override; + + CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override; + + std::unique_ptr CreateVideoEncoder( + const SdpVideoFormat& format) override; +}; + class WinUWPH264DecoderFactory : public cricket::WebRtcVideoDecoderFactory { webrtc::VideoDecoder* CreateVideoDecoder(webrtc::VideoCodecType type) override; From 7389bffce3ced616d830b835335c46c979fd6257 Mon Sep 17 00:00:00 2001 From: Krzysztof Lesiak Date: Mon, 4 Mar 2019 14:04:58 +0100 Subject: [PATCH 2/4] Add h264 profile info to new factory --- third_party/winuwp_h264/winuwp_h264_factory.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/third_party/winuwp_h264/winuwp_h264_factory.cc b/third_party/winuwp_h264/winuwp_h264_factory.cc index f7f0c1ed5a..b509c8179b 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.cc +++ b/third_party/winuwp_h264/winuwp_h264_factory.cc @@ -63,7 +63,15 @@ namespace webrtc { std::vector WinUWPH264EncoderFactoryNew::GetSupportedFormats() const { - std::vector formats = { SdpVideoFormat("H264") }; + std::vector formats = { + SdpVideoFormat(cricket::kH264CodecName, + { + //copy-pasted from h264.cc. + //specifies the h264 profile, in this case baseline. If we omit this, firefox 65 + //rejects the video offer, so we send it like the built-in codec does. + {cricket::kH264FmtpProfileLevelId, "42100b"} + }) + }; return formats; } From 4b3dda6e5b961de36e6145379ba13f78de7ef5ea Mon Sep 17 00:00:00 2001 From: Krzysztof Lesiak Date: Tue, 5 Mar 2019 10:19:48 +0100 Subject: [PATCH 3/4] Add some more sdp params for h264 uwp --- third_party/winuwp_h264/winuwp_h264_factory.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/third_party/winuwp_h264/winuwp_h264_factory.cc b/third_party/winuwp_h264/winuwp_h264_factory.cc index b509c8179b..f12ca55699 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.cc +++ b/third_party/winuwp_h264/winuwp_h264_factory.cc @@ -66,10 +66,16 @@ namespace webrtc { std::vector formats = { SdpVideoFormat(cricket::kH264CodecName, { - //copy-pasted from h264.cc. - //specifies the h264 profile, in this case baseline. If we omit this, firefox 65 - //rejects the video offer, so we send it like the built-in codec does. - {cricket::kH264FmtpProfileLevelId, "42100b"} + //copy-pasted from h264.cc + {cricket::kH264FmtpProfileLevelId, "42100b"}, + {cricket::kH264FmtpLevelAsymmetryAllowed, "1"}, + {cricket::kH264FmtpPacketizationMode, "0"} + }), + SdpVideoFormat(cricket::kH264CodecName, + { + {cricket::kH264FmtpProfileLevelId, "42100b"}, + {cricket::kH264FmtpLevelAsymmetryAllowed, "1"}, + {cricket::kH264FmtpPacketizationMode, "1"} }) }; return formats; From ee98288c17f30e28ed13050a7d1877caf194cd6d Mon Sep 17 00:00:00 2001 From: Krzysztof Lesiak Date: Tue, 2 Apr 2019 11:47:43 +0200 Subject: [PATCH 4/4] Remove old factory, rename new one --- .../winuwp_h264/winuwp_h264_factory.cc | 39 +++---------------- third_party/winuwp_h264/winuwp_h264_factory.h | 18 +-------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/third_party/winuwp_h264/winuwp_h264_factory.cc b/third_party/winuwp_h264/winuwp_h264_factory.cc index f12ca55699..c32674c599 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.cc +++ b/third_party/winuwp_h264/winuwp_h264_factory.cc @@ -18,34 +18,6 @@ namespace webrtc { - WinUWPH264EncoderFactory::WinUWPH264EncoderFactory() { - codecList_ = - std::vector { - cricket::VideoCodec("H264") - }; - } - - webrtc::VideoEncoder* WinUWPH264EncoderFactory::CreateVideoEncoder( - const cricket::VideoCodec& codec) { - if (codec.name == "H264") { - return new WinUWPH264EncoderImpl(); - } else { - return nullptr; - } - } - - const std::vector& - WinUWPH264EncoderFactory::supported_codecs() const { - return codecList_; - } - - void WinUWPH264EncoderFactory::DestroyVideoEncoder( - webrtc::VideoEncoder* encoder) { - encoder->Release(); - delete encoder; - } - - webrtc::VideoDecoder* WinUWPH264DecoderFactory::CreateVideoDecoder( webrtc::VideoCodecType type) { if (type == kVideoCodecH264) { @@ -61,7 +33,7 @@ namespace webrtc { delete decoder; } - std::vector WinUWPH264EncoderFactoryNew::GetSupportedFormats() + std::vector WinUWPH264EncoderFactory::GetSupportedFormats() const { std::vector formats = { SdpVideoFormat(cricket::kH264CodecName, @@ -81,17 +53,16 @@ namespace webrtc { return formats; } - VideoEncoderFactory::CodecInfo WinUWPH264EncoderFactoryNew::QueryVideoEncoder( + VideoEncoderFactory::CodecInfo WinUWPH264EncoderFactory::QueryVideoEncoder( const SdpVideoFormat& format) const { CodecInfo info; - //not sure about this. mf does support hw MFTs but doesn't really tell us - //when using sink writer. it's more of a "silent sw fallback if hw not available" thing - info.is_hardware_accelerated = false; + info.is_hardware_accelerated = true; info.has_internal_source = false; + return info; } - std::unique_ptr WinUWPH264EncoderFactoryNew::CreateVideoEncoder( + std::unique_ptr WinUWPH264EncoderFactory::CreateVideoEncoder( const SdpVideoFormat& format) { if (cricket::CodecNamesEq(format.name, cricket::kH264CodecName)) { return std::make_unique(); diff --git a/third_party/winuwp_h264/winuwp_h264_factory.h b/third_party/winuwp_h264/winuwp_h264_factory.h index 4bce48614f..c0b07c6101 100644 --- a/third_party/winuwp_h264/winuwp_h264_factory.h +++ b/third_party/winuwp_h264/winuwp_h264_factory.h @@ -19,23 +19,7 @@ namespace webrtc { -class WinUWPH264EncoderFactory : public cricket::WebRtcVideoEncoderFactory { - public: - WinUWPH264EncoderFactory(); - - webrtc::VideoEncoder* CreateVideoEncoder(const cricket::VideoCodec& codec) - override; - - const std::vector& supported_codecs() - const override; - - void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override; - - private: - std::vector codecList_; -}; - -class WinUWPH264EncoderFactoryNew : public VideoEncoderFactory { +class WinUWPH264EncoderFactory : public VideoEncoderFactory { public: std::vector GetSupportedFormats() const override;