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

Side by Side Diff: remoting/codec/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: Created 4 years, 8 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 2013 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_VIDEO_ENCODER_VPX_H_
6 #define REMOTING_CODEC_VIDEO_ENCODER_VPX_H_ 6 #define REMOTING_CODEC_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 class VideoEncoderVpx : public VideoEncoder {
28 public: 29 public:
29 // Create encoder for the specified protocol. 30 // Create encoder for the specified protocol.
30 static std::unique_ptr<VideoEncoderVpx> CreateForVP8(); 31 static std::unique_ptr<VideoEncoderVpx> CreateForVP8();
31 static std::unique_ptr<VideoEncoderVpx> CreateForVP9(); 32 static std::unique_ptr<VideoEncoderVpx> CreateForVP9();
32 33
33 ~VideoEncoderVpx() override; 34 ~VideoEncoderVpx() override;
34 35
35 void SetTickClockForTests(base::TickClock* tick_clock); 36 void SetTickClockForTests(base::TickClock* tick_clock);
36 37
37 // VideoEncoder interface. 38 // VideoEncoder interface.
38 void SetLosslessEncode(bool want_lossless) override; 39 void SetLosslessEncode(bool want_lossless) override;
39 void SetLosslessColor(bool want_lossless) override; 40 void SetLosslessColor(bool want_lossless) override;
40 std::unique_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame, 41 std::unique_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame,
41 uint32_t flags) override; 42 uint32_t flags) override;
43 void UpdateTargetBitrate(uint32_t bitrate) override;
42 44
43 private: 45 private:
44 explicit VideoEncoderVpx(bool use_vp9); 46 explicit VideoEncoderVpx(bool use_vp9);
45 47
46 // (Re)Configures this instance to encode frames of the specified |size|, 48 // (Re)Configures this instance to encode frames of the specified |size|,
47 // with the configured lossless color & encoding modes. 49 // with the configured lossless color & encoding modes.
48 void Configure(const webrtc::DesktopSize& size); 50 void Configure(const webrtc::DesktopSize& size);
49 51
50 // Prepares |image_| for encoding. Writes updated rectangles into 52 // Prepares |image_| for encoding. Writes updated rectangles into
51 // |updated_region|. 53 // |updated_region|.
(...skipping 12 matching lines...) Expand all
64 const bool use_vp9_; 66 const bool use_vp9_;
65 67
66 // Options controlling VP9 encode quantization and color space. 68 // Options controlling VP9 encode quantization and color space.
67 // These are always off (false) for VP8. 69 // These are always off (false) for VP8.
68 bool lossless_encode_ = false; 70 bool lossless_encode_ = false;
69 bool lossless_color_ = false; 71 bool lossless_color_ = false;
70 72
71 // Holds the initialized & configured codec. 73 // Holds the initialized & configured codec.
72 ScopedVpxCodec codec_; 74 ScopedVpxCodec codec_;
73 75
76 vpx_codec_enc_cfg_t config_;
77 uint32_t target_bitrate_kbps_;
78
74 // Used to generate zero-based frame timestamps. 79 // Used to generate zero-based frame timestamps.
75 base::TimeTicks timestamp_base_; 80 base::TimeTicks timestamp_base_;
76 81
77 // VPX image and buffer to hold the actual YUV planes. 82 // VPX image and buffer to hold the actual YUV planes.
78 std::unique_ptr<vpx_image_t> image_; 83 std::unique_ptr<vpx_image_t> image_;
79 std::unique_ptr<uint8_t[]> image_buffer_; 84 std::unique_ptr<uint8_t[]> image_buffer_;
80 85
81 // Active map used to optimize out processing of un-changed macroblocks. 86 // Active map used to optimize out processing of un-changed macroblocks.
82 std::unique_ptr<uint8_t[]> active_map_; 87 std::unique_ptr<uint8_t[]> active_map_;
83 webrtc::DesktopSize active_map_size_; 88 webrtc::DesktopSize active_map_size_;
84 89
85 // True if the codec wants unchanged frames to finish topping-off with. 90 // True if the codec wants unchanged frames to finish topping-off with.
86 bool encode_unchanged_frame_; 91 bool encode_unchanged_frame_;
87 92
88 // Used to help initialize VideoPackets from DesktopFrames. 93 // Used to help initialize VideoPackets from DesktopFrames.
89 VideoEncoderHelper helper_; 94 VideoEncoderHelper helper_;
90 95
91 base::DefaultTickClock default_tick_clock_; 96 base::DefaultTickClock default_tick_clock_;
92 base::TickClock* clock_; 97 base::TickClock* clock_;
93 98
94 DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx); 99 DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx);
95 }; 100 };
96 101
97 } // namespace remoting 102 } // namespace remoting
98 103
99 #endif // REMOTING_CODEC_VIDEO_ENCODER_VPX_H_ 104 #endif // REMOTING_CODEC_VIDEO_ENCODER_VPX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698