Chromium Code Reviews| Index: remoting/codec/webrtc_video_encoder.h |
| diff --git a/remoting/codec/webrtc_video_encoder.h b/remoting/codec/webrtc_video_encoder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e7fb6d8462c190518ef9da760f172e3e976a5b3 |
| --- /dev/null |
| +++ b/remoting/codec/webrtc_video_encoder.h |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_H_ |
| +#define REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/synchronization/lock.h" |
| +#include "third_party/webrtc/media/engine/webrtcvideoencoderfactory.h" |
| +#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h" |
| + |
| +namespace remoting { |
| + |
| +// This is the interface between the WebRtc engine and the external encoder |
| +// provided by remoting. WebRtc provides feedback on network bandwidth, latency |
| +// & RTT and in turn remoting passes encoded frames as they get encoded |
| +// 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.
|
| +class WebRtcVideoEncoder : public webrtc::VideoEncoder { |
| + public: |
| + enum State { kUninitialized = 0, kInitialized }; |
| + explicit WebRtcVideoEncoder(webrtc::VideoCodecType codec); |
| + ~WebRtcVideoEncoder() override; |
| + |
| + // webrtc::VideoEncoder overrides |
| + int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
| + int32_t number_of_cores, |
| + size_t max_payload_size) override; |
| + int32_t RegisterEncodeCompleteCallback( |
| + webrtc::EncodedImageCallback* callback) override; |
| + int32_t Release() override; |
| + int32_t Encode(const webrtc::VideoFrame& frame, |
| + const webrtc::CodecSpecificInfo* codec_specific_info, |
| + const std::vector<webrtc::FrameType>* frame_types) override; |
| + int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
| + int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; |
| + |
| + 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.
|
| + uint8_t* buffer, |
| + size_t buffer_size, |
| + int width, |
| + int height, |
| + bool key_frame); |
| + void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); |
| + |
| + private: |
| + // Protects |encoded_callback_| and |state_|. |
| + 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.
|
| + State state_; |
| + webrtc::EncodedImageCallback* encoded_callback_; |
| + |
| + base::Closure key_frame_request_; |
| + webrtc::VideoCodecType video_codec_type_; |
| + uint32_t target_bitrate_; |
| +}; |
| + |
| +// This is the external encoder factory implementation that is passed to |
| +// WebRTC at the time of creation of peer connection. The external encoder |
| +// factory primarily manages creation and destruction of encoder. |
| +class WebRtcVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory { |
| + public: |
| + WebRtcVideoEncoderFactory(); |
| + ~WebRtcVideoEncoderFactory() override; |
| + |
| + webrtc::VideoEncoder* CreateVideoEncoder( |
| + webrtc::VideoCodecType type) override; |
| + const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& codecs() |
| + const override; |
| + |
| + // Returns true to directly provide encoded frames to webrtc |
| + bool EncoderTypeHasInternalSource(webrtc::VideoCodecType type) const override; |
| + void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override; |
| + |
| + int SendEncodedFrame(int64_t capture_timestamp_ms, |
| + uint8_t* buffer, |
| + size_t buffer_size, |
| + int width, |
| + int height, |
| + bool key_frame); |
| + |
| + void SetKeyFrameRequestCallback(const base::Closure& key_frame_request); |
| + |
| + private: |
| + base::Closure key_frame_request_; |
| + std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> codecs_; |
| + std::vector<WebRtcVideoEncoder*> encoders_; |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_H_ |