Index: webrtc/media/engine/webrtcvideoengine.cc |
diff --git a/webrtc/media/engine/webrtcvideoengine.cc b/webrtc/media/engine/webrtcvideoengine.cc |
index 40f3694a1a39ae23bf2be4b00bdc9bb8845c495b..80166c9684a67bf40e9e92db79392b78d03cf5d2 100644 |
--- a/webrtc/media/engine/webrtcvideoengine.cc |
+++ b/webrtc/media/engine/webrtcvideoengine.cc |
@@ -18,7 +18,9 @@ |
#include "webrtc/api/video/i420_buffer.h" |
#include "webrtc/api/video_codecs/video_decoder.h" |
+#include "webrtc/api/video_codecs/video_decoder_factory.h" |
#include "webrtc/api/video_codecs/video_encoder.h" |
+#include "webrtc/api/video_codecs/video_encoder_factory.h" |
#include "webrtc/call/call.h" |
#include "webrtc/common_video/h264/profile_level_id.h" |
#include "webrtc/media/engine/constants.h" |
@@ -86,8 +88,8 @@ std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs( |
// Wraps cricket::WebRtcVideoEncoderFactory* into common EncoderFactoryAdapter |
// interface. |
-// TODO(magjed): Add wrapper class for future webrtc::VideoEncoderFactory |
-// interface, https://bugs.chromium.org/p/webrtc/issues/detail?id=7925. |
+// TODO(magjed): Remove once WebRtcVideoEncoderFactory* is deprecated and |
+// webrtc:7925 is fixed. |
class CricketEncoderFactoryAdapter : public EncoderFactoryAdapter { |
public: |
explicit CricketEncoderFactoryAdapter( |
@@ -130,6 +132,57 @@ class CricketDecoderFactoryAdapter : public DecoderFactoryAdapter { |
WebRtcVideoDecoderFactory* const external_decoder_factory_; |
}; |
+// Wraps webrtc::VideoEncoderFactory into common EncoderFactoryAdapter |
+// interface. |
+class WebRtcEncoderFactoryAdapter : public EncoderFactoryAdapter { |
+ public: |
+ explicit WebRtcEncoderFactoryAdapter( |
+ std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory) |
+ : encoder_factory_(std::move(encoder_factory)) {} |
+ |
+ private: |
+ AllocatedEncoder CreateVideoEncoder( |
+ const VideoCodec& codec, |
+ bool is_conference_mode_screenshare) const override { |
+ if (!encoder_factory_) |
+ return AllocatedEncoder(); |
+ const webrtc::VideoEncoderFactory::CodecInfo info = |
+ encoder_factory_->QueryVideoEncoder(codec); |
+ return AllocatedEncoder(encoder_factory_->CreateVideoEncoder(codec), |
+ info.is_hardware_accelerated, |
+ info.has_internal_source); |
+ } |
+ |
+ std::vector<VideoCodec> GetSupportedCodecs() const override { |
+ return encoder_factory_ ? AssignPayloadTypesAndAddAssociatedRtxCodecs( |
+ encoder_factory_->GetSupportedCodecs()) |
+ : std::vector<VideoCodec>(); |
+ } |
+ |
+ private: |
stefan-webrtc
2017/09/06 12:40:42
No need for private here and at line 143, right? S
magjed_webrtc
2017/09/10 15:27:49
Ops, thanks.
|
+ std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_; |
+}; |
+ |
+// Wraps webrtc::VideoDecoderFactory into common DecoderFactoryAdapter |
+// interface. |
+class WebRtcDecoderFactoryAdapter : public DecoderFactoryAdapter { |
+ public: |
+ explicit WebRtcDecoderFactoryAdapter( |
+ std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory) |
+ : decoder_factory_(std::move(decoder_factory)) {} |
+ |
+ private: |
+ std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( |
+ const VideoCodec& codec, |
+ const VideoDecoderParams& decoder_params) const override { |
+ return decoder_factory_ ? decoder_factory_->CreateVideoDecoder(codec) |
+ : nullptr; |
+ } |
+ |
+ private: |
+ std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory_; |
+}; |
+ |
// If this field trial is enabled, we will enable sending FlexFEC and disable |
// sending ULPFEC whenever the former has been negotiated in the SDPs. |
bool IsFlexfecFieldTrialEnabled() { |
@@ -401,6 +454,16 @@ WebRtcVideoEngine::WebRtcVideoEngine( |
LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; |
} |
+WebRtcVideoEngine::WebRtcVideoEngine( |
+ std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory, |
+ std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory) |
+ : decoder_factory_( |
+ new WebRtcDecoderFactoryAdapter(std::move(video_decoder_factory))), |
+ encoder_factory_( |
+ new WebRtcEncoderFactoryAdapter(std::move(video_encoder_factory))) { |
+ LOG(LS_INFO) << "WebRtcVideoEngine::WebRtcVideoEngine()"; |
+} |
+ |
WebRtcVideoEngine::~WebRtcVideoEngine() { |
LOG(LS_INFO) << "WebRtcVideoEngine::~WebRtcVideoEngine"; |
} |