| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_PROTOCOL_WEBRTC_VIDEO_ENCODER_FACTORY_H_ | |
| 6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_ENCODER_FACTORY_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/synchronization/lock.h" | |
| 13 #include "remoting/proto/video.pb.h" | |
| 14 #include "third_party/webrtc/media/engine/webrtcvideoencoderfactory.h" | |
| 15 #include "third_party/webrtc/modules/video_coding/include/video_codec_interface.
h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 | |
| 19 using TargetBitrateCallback = base::Callback<void(int)>; | |
| 20 | |
| 21 // This is the interface between the Webrtc engine and the external encoder | |
| 22 // provided by remoting. Webrtc provides feedback on network bandwidth, latency | |
| 23 // & RTT and in turn remoting passes encoded frames as they get encoded | |
| 24 // through the capture pipeline. | |
| 25 class WebrtcVideoEncoder : public webrtc::VideoEncoder { | |
| 26 public: | |
| 27 enum State { kUninitialized = 0, kInitialized }; | |
| 28 explicit WebrtcVideoEncoder(webrtc::VideoCodecType codec); | |
| 29 ~WebrtcVideoEncoder() override; | |
| 30 | |
| 31 // webrtc::VideoEncoder overrides | |
| 32 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, | |
| 33 int32_t number_of_cores, | |
| 34 size_t max_payload_size) override; | |
| 35 int32_t RegisterEncodeCompleteCallback( | |
| 36 webrtc::EncodedImageCallback* callback) override; | |
| 37 int32_t Release() override; | |
| 38 int32_t Encode(const webrtc::VideoFrame& frame, | |
| 39 const webrtc::CodecSpecificInfo* codec_specific_info, | |
| 40 const std::vector<webrtc::FrameType>* frame_types) override; | |
| 41 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | |
| 42 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; | |
| 43 | |
| 44 webrtc::EncodedImageCallback::Result SendEncodedFrame( | |
| 45 std::unique_ptr<VideoPacket> packet, | |
| 46 base::TimeTicks capture_time); | |
| 47 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); | |
| 48 void SetTargetBitrateCallback(const TargetBitrateCallback& target_bitrate_cb); | |
| 49 | |
| 50 private: | |
| 51 // Protects |encoded_callback_|, |key_frame_request_|, | |
| 52 // |target_bitrate_cb_| and |state_|. | |
| 53 base::Lock lock_; | |
| 54 State state_; | |
| 55 webrtc::EncodedImageCallback* encoded_callback_; | |
| 56 | |
| 57 base::Closure key_frame_request_; | |
| 58 TargetBitrateCallback target_bitrate_cb_; | |
| 59 webrtc::VideoCodecType video_codec_type_; | |
| 60 }; | |
| 61 | |
| 62 // This is the external encoder factory implementation that is passed to | |
| 63 // WebRTC at the time of creation of peer connection. The external encoder | |
| 64 // factory primarily manages creation and destruction of encoder. | |
| 65 class WebrtcVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory { | |
| 66 public: | |
| 67 WebrtcVideoEncoderFactory(); | |
| 68 ~WebrtcVideoEncoderFactory() override; | |
| 69 | |
| 70 webrtc::VideoEncoder* CreateVideoEncoder( | |
| 71 webrtc::VideoCodecType type) override; | |
| 72 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& codecs() | |
| 73 const override; | |
| 74 | |
| 75 // Returns true to directly provide encoded frames to webrtc | |
| 76 bool EncoderTypeHasInternalSource(webrtc::VideoCodecType type) const override; | |
| 77 void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override; | |
| 78 | |
| 79 webrtc::EncodedImageCallback::Result SendEncodedFrame( | |
| 80 std::unique_ptr<VideoPacket> packet, | |
| 81 base::TimeTicks capture_time); | |
| 82 | |
| 83 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); | |
| 84 void SetTargetBitrateCallback(const TargetBitrateCallback& target_bitrate_cb); | |
| 85 | |
| 86 private: | |
| 87 // Protects |key_frame_request_| and |target_bitrate_cb_|. | |
| 88 base::Lock lock_; | |
| 89 base::Closure key_frame_request_; | |
| 90 TargetBitrateCallback target_bitrate_cb_; | |
| 91 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> codecs_; | |
| 92 std::vector<std::unique_ptr<WebrtcVideoEncoder>> encoders_; | |
| 93 }; | |
| 94 | |
| 95 } // namespace remoting | |
| 96 | |
| 97 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_ENCODER_FACTORY_H_ | |
| OLD | NEW |