Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(977)

Side by Side Diff: remoting/protocol/webrtc_video_encoder.h

Issue 1908203002: Adapt encoder behavior to target bitrate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved webrtc encoder to its own file Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_H_
6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_ENCODER_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 // This is the interface between the WebRtc engine and the external encoder
20 // provided by remoting. WebRtc provides feedback on network bandwidth, latency
21 // & RTT and in turn remoting passes encoded frames as they get encoded
22 // through the capture pipeline.
23 class WebRtcVideoEncoder : public webrtc::VideoEncoder {
24 public:
25 enum State { kUninitialized = 0, kInitialized };
26 explicit WebRtcVideoEncoder(webrtc::VideoCodecType codec);
27 ~WebRtcVideoEncoder() override;
28
29 // webrtc::VideoEncoder overrides
30 int32_t InitEncode(const webrtc::VideoCodec* codec_settings,
31 int32_t number_of_cores,
32 size_t max_payload_size) override;
33 int32_t RegisterEncodeCompleteCallback(
34 webrtc::EncodedImageCallback* callback) override;
35 int32_t Release() override;
36 int32_t Encode(const webrtc::VideoFrame& frame,
37 const webrtc::CodecSpecificInfo* codec_specific_info,
38 const std::vector<webrtc::FrameType>* frame_types) override;
39 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
40 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override;
41
42 int SendEncodedFrame(int64_t capture_timestamp_ms,
43 std::unique_ptr<VideoPacket> pkt);
44 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request);
45
46 private:
47 // Protects |encoded_callback_|, |key_frame_request_| and |state_|.
48 base::Lock lock_;
49 State state_;
50 webrtc::EncodedImageCallback* encoded_callback_;
51
52 base::Closure key_frame_request_;
53 webrtc::VideoCodecType video_codec_type_;
54 uint32_t target_bitrate_;
55 };
56
57 // This is the external encoder factory implementation that is passed to
58 // WebRTC at the time of creation of peer connection. The external encoder
59 // factory primarily manages creation and destruction of encoder.
60 class WebRtcVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory {
61 public:
62 WebRtcVideoEncoderFactory();
63 ~WebRtcVideoEncoderFactory() override;
64
65 webrtc::VideoEncoder* CreateVideoEncoder(
66 webrtc::VideoCodecType type) override;
67 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& codecs()
68 const override;
69
70 // Returns true to directly provide encoded frames to webrtc
71 bool EncoderTypeHasInternalSource(webrtc::VideoCodecType type) const override;
72 void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override;
73
74 int SendEncodedFrame(int64_t capture_timestamp_ms,
75 std::unique_ptr<VideoPacket> pkt);
76
77 void SetKeyFrameRequestCallback(const base::Closure& key_frame_request);
78
79 private:
80 // Protects |key_frame_request_|.
81 base::Lock lock_;
82 base::Closure key_frame_request_;
83 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec> codecs_;
84 std::vector<std::unique_ptr<WebRtcVideoEncoder>> encoders_;
85 };
86
87 } // namespace remoting
88
89 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698