Chromium Code Reviews| 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_CODEC_WEBRTC_VIDEO_ENCODER_H_ | |
| 6 #define REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/synchronization/lock.h" | |
| 12 #include "third_party/webrtc/media/engine/webrtcvideoencoderfactory.h" | |
| 13 #include "third_party/webrtc/modules/video_coding/include/video_codec_interface. h" | |
| 14 | |
| 15 namespace remoting { | |
| 16 | |
| 17 // This is the interface between the WebRtc engine and the external encoder | |
| 18 // provided by remoting. WebRtc provides feedback on network bandwidth, latency | |
| 19 // & RTT and in turn remoting passes encoded frames as they get encoded | |
| 20 // through the capture pipeline. | |
|
Sergey Ulanov
2016/03/31 22:06:19
So if I understand correctly this class doesn't re
Irfan
2016/04/05 21:23:27
Done.
| |
| 21 class WebRtcVideoEncoder : public webrtc::VideoEncoder { | |
| 22 public: | |
| 23 enum State { kUninitialized = 0, kInitialized }; | |
| 24 explicit WebRtcVideoEncoder(webrtc::VideoCodecType codec); | |
| 25 ~WebRtcVideoEncoder() override; | |
| 26 | |
| 27 // webrtc::VideoEncoder overrides | |
| 28 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, | |
| 29 int32_t number_of_cores, | |
| 30 size_t max_payload_size) override; | |
| 31 int32_t RegisterEncodeCompleteCallback( | |
| 32 webrtc::EncodedImageCallback* callback) override; | |
| 33 int32_t Release() override; | |
| 34 int32_t Encode(const webrtc::VideoFrame& frame, | |
| 35 const webrtc::CodecSpecificInfo* codec_specific_info, | |
| 36 const std::vector<webrtc::FrameType>* frame_types) override; | |
| 37 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | |
| 38 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; | |
| 39 | |
| 40 int SendEncodedFrame(int64_t capture_timestamp_ms, | |
|
Sergey Ulanov
2016/03/31 22:06:19
Maybe use VideoPacket to pass the frame instead of
Irfan
2016/04/05 21:23:27
Done.
| |
| 41 uint8_t* buffer, | |
| 42 size_t buffer_size, | |
| 43 int width, | |
| 44 int height, | |
| 45 bool key_frame); | |
| 46 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); | |
| 47 | |
| 48 private: | |
| 49 // Protects |encoded_callback_| and |state_|. | |
| 50 mutable base::Lock lock_; | |
|
Sergey Ulanov
2016/03/31 22:06:18
I don't think you need to mark in mutable.
Irfan
2016/04/05 21:23:27
Done.
| |
| 51 State state_; | |
| 52 webrtc::EncodedImageCallback* encoded_callback_; | |
| 53 | |
| 54 base::Closure key_frame_request_; | |
| 55 webrtc::VideoCodecType video_codec_type_; | |
| 56 uint32_t target_bitrate_; | |
| 57 }; | |
| 58 | |
| 59 // This is the external encoder factory implementation that is passed to | |
| 60 // WebRTC at the time of creation of peer connection. The external encoder | |
| 61 // factory primarily manages creation and destruction of encoder. | |
| 62 class WebRtcVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory { | |
| 63 public: | |
| 64 WebRtcVideoEncoderFactory(); | |
| 65 ~WebRtcVideoEncoderFactory() override; | |
| 66 | |
| 67 webrtc::VideoEncoder* CreateVideoEncoder( | |
| 68 webrtc::VideoCodecType type) override; | |
| 69 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& codecs() | |
| 70 const override; | |
| 71 | |
| 72 // Returns true to directly provide encoded frames to webrtc | |
| 73 bool EncoderTypeHasInternalSource(webrtc::VideoCodecType type) const override; | |
| 74 void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override; | |
| 75 | |
| 76 int SendEncodedFrame(int64_t capture_timestamp_ms, | |
| 77 uint8_t* buffer, | |
| 78 size_t buffer_size, | |
| 79 int width, | |
| 80 int height, | |
| 81 bool key_frame); | |
| 82 | |
| 83 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); | |
| 84 | |
| 85 private: | |
| 86 base::Closure key_frame_request_; | |
| 87 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> codecs_; | |
| 88 std::vector<WebRtcVideoEncoder*> encoders_; | |
| 89 }; | |
| 90 | |
| 91 } // namespace remoting | |
| 92 | |
| 93 #endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_H_ | |
| OLD | NEW |