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

Side by Side Diff: remoting/codec/webrtc_video_encoder_vpx.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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_CODEC_VIDEO_ENCODER_VPX_H_ 5 #ifndef REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_
6 #define REMOTING_CODEC_VIDEO_ENCODER_VPX_H_ 6 #define REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/time/default_tick_clock.h" 12 #include "base/time/default_tick_clock.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "remoting/codec/scoped_vpx_codec.h" 14 #include "remoting/codec/scoped_vpx_codec.h"
15 #include "remoting/codec/video_encoder.h" 15 #include "remoting/codec/video_encoder.h"
16 #include "remoting/codec/video_encoder_helper.h" 16 #include "remoting/codec/video_encoder_helper.h"
17 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
17 18
18 typedef struct vpx_image vpx_image_t; 19 typedef struct vpx_image vpx_image_t;
19 20
20 namespace webrtc { 21 namespace webrtc {
21 class DesktopRegion; 22 class DesktopRegion;
22 class DesktopSize; 23 class DesktopSize;
23 } // namespace webrtc 24 } // namespace webrtc
24 25
25 namespace remoting { 26 namespace remoting {
26 27
27 class VideoEncoderVpx : public VideoEncoder { 28 // This is a copy of VideoEncoderVpx with enhancements to encoder for use
29 // over WebRTC as transport. The original VideoEncoderVpx should be deleted
30 // once the old implementation is no longer in use.
31 class WebRtcVideoEncoderVpx : public VideoEncoder {
28 public: 32 public:
29 // Create encoder for the specified protocol. 33 // Create encoder for the specified protocol.
30 static std::unique_ptr<VideoEncoderVpx> CreateForVP8(); 34 static std::unique_ptr<WebRtcVideoEncoderVpx> CreateForVP8();
31 static std::unique_ptr<VideoEncoderVpx> CreateForVP9(); 35 static std::unique_ptr<WebRtcVideoEncoderVpx> CreateForVP9();
32 36
33 ~VideoEncoderVpx() override; 37 ~WebRtcVideoEncoderVpx() override;
34 38
35 void SetTickClockForTests(base::TickClock* tick_clock); 39 void SetTickClockForTests(base::TickClock* tick_clock);
36 40
37 // VideoEncoder interface. 41 // VideoEncoder interface.
38 void SetLosslessEncode(bool want_lossless) override; 42 void SetLosslessEncode(bool want_lossless) override;
39 void SetLosslessColor(bool want_lossless) override; 43 void SetLosslessColor(bool want_lossless) override;
40 std::unique_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame, 44 std::unique_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame,
41 uint32_t flags) override; 45 uint32_t flags) override;
46 void UpdateTargetBitrate(uint32_t bitrate) override;
42 47
43 private: 48 private:
44 explicit VideoEncoderVpx(bool use_vp9); 49 explicit WebRtcVideoEncoderVpx(bool use_vp9);
45 50
46 // (Re)Configures this instance to encode frames of the specified |size|, 51 // (Re)Configures this instance to encode frames of the specified |size|,
47 // with the configured lossless color & encoding modes. 52 // with the configured lossless color & encoding modes.
48 void Configure(const webrtc::DesktopSize& size); 53 void Configure(const webrtc::DesktopSize& size);
49 54
50 // Prepares |image_| for encoding. Writes updated rectangles into 55 // Prepares |image_| for encoding. Writes updated rectangles into
51 // |updated_region|. 56 // |updated_region|.
52 void PrepareImage(const webrtc::DesktopFrame& frame, 57 void PrepareImage(const webrtc::DesktopFrame& frame,
53 webrtc::DesktopRegion* updated_region); 58 webrtc::DesktopRegion* updated_region);
54 59
55 // Updates the active map according to |updated_region|. Active map is then 60 // Updates the active map according to |updated_region|. Active map is then
56 // given to the encoder to speed up encoding. 61 // given to the encoder to speed up encoding.
57 void SetActiveMapFromRegion(const webrtc::DesktopRegion& updated_region); 62 void SetActiveMapFromRegion(const webrtc::DesktopRegion& updated_region);
58 63
59 // Adds areas changed in the most recent frame to |updated_region|. This 64 // Adds areas changed in the most recent frame to |updated_region|. This
60 // includes both content changes and areas enhanced by cyclic refresh. 65 // includes both content changes and areas enhanced by cyclic refresh.
61 void UpdateRegionFromActiveMap(webrtc::DesktopRegion* updated_region); 66 void UpdateRegionFromActiveMap(webrtc::DesktopRegion* updated_region);
62 67
63 // True if the encoder is for VP9, false for VP8. 68 // True if the encoder is for VP9, false for VP8.
64 const bool use_vp9_; 69 const bool use_vp9_;
65 70
66 // Options controlling VP9 encode quantization and color space. 71 // Options controlling VP9 encode quantization and color space.
67 // These are always off (false) for VP8. 72 // These are always off (false) for VP8.
68 bool lossless_encode_ = false; 73 bool lossless_encode_ = false;
69 bool lossless_color_ = false; 74 bool lossless_color_ = false;
70 75
71 // Holds the initialized & configured codec. 76 // Holds the initialized & configured codec.
72 ScopedVpxCodec codec_; 77 ScopedVpxCodec codec_;
73 78
79 vpx_codec_enc_cfg_t config_;
80 uint32_t target_bitrate_kbps_;
81
74 // Used to generate zero-based frame timestamps. 82 // Used to generate zero-based frame timestamps.
75 base::TimeTicks timestamp_base_; 83 base::TimeTicks timestamp_base_;
76 84
77 // VPX image and buffer to hold the actual YUV planes. 85 // VPX image and buffer to hold the actual YUV planes.
78 std::unique_ptr<vpx_image_t> image_; 86 std::unique_ptr<vpx_image_t> image_;
79 std::unique_ptr<uint8_t[]> image_buffer_; 87 std::unique_ptr<uint8_t[]> image_buffer_;
80 88
81 // Active map used to optimize out processing of un-changed macroblocks. 89 // Active map used to optimize out processing of un-changed macroblocks.
82 std::unique_ptr<uint8_t[]> active_map_; 90 std::unique_ptr<uint8_t[]> active_map_;
83 webrtc::DesktopSize active_map_size_; 91 webrtc::DesktopSize active_map_size_;
84 92
85 // True if the codec wants unchanged frames to finish topping-off with. 93 // True if the codec wants unchanged frames to finish topping-off with.
86 bool encode_unchanged_frame_; 94 bool encode_unchanged_frame_;
87 95
88 // Used to help initialize VideoPackets from DesktopFrames. 96 // Used to help initialize VideoPackets from DesktopFrames.
89 VideoEncoderHelper helper_; 97 VideoEncoderHelper helper_;
90 98
91 base::DefaultTickClock default_tick_clock_; 99 base::DefaultTickClock default_tick_clock_;
92 base::TickClock* clock_; 100 base::TickClock* clock_;
93 101
94 DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx); 102 DISALLOW_COPY_AND_ASSIGN(WebRtcVideoEncoderVpx);
95 }; 103 };
96 104
97 } // namespace remoting 105 } // namespace remoting
98 106
99 #endif // REMOTING_CODEC_VIDEO_ENCODER_VPX_H_ 107 #endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698