| OLD | NEW |
| 1 // Copyright 2016 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_WEBRTC_VIDEO_ENCODER_VPX_H_ | 5 #ifndef REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_ |
| 6 #define REMOTING_CODEC_WEBRTC_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/webrtc_video_encoder.h" |
| 16 #include "remoting/codec/video_encoder_helper.h" | |
| 17 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" | 16 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" |
| 18 | 17 |
| 19 typedef struct vpx_image vpx_image_t; | 18 typedef struct vpx_image vpx_image_t; |
| 20 | 19 |
| 21 namespace webrtc { | 20 namespace webrtc { |
| 22 class DesktopRegion; | 21 class DesktopRegion; |
| 23 class DesktopSize; | 22 class DesktopSize; |
| 24 } // namespace webrtc | 23 } // namespace webrtc |
| 25 | 24 |
| 26 namespace remoting { | 25 namespace remoting { |
| 27 | 26 |
| 28 // This is a copy of VideoEncoderVpx with enhancements to encoder for use | 27 // This is a copy of VideoEncoderVpx with enhancements to encoder for use |
| 29 // over WebRTC as transport. The original VideoEncoderVpx should be deleted | 28 // over WebRTC as transport. The original VideoEncoderVpx should be deleted |
| 30 // once the old implementation is no longer in use. | 29 // once the old implementation is no longer in use. |
| 31 class WebrtcVideoEncoderVpx : public VideoEncoder { | 30 class WebrtcVideoEncoderVpx : public WebrtcVideoEncoder { |
| 32 public: | 31 public: |
| 33 // Create encoder for the specified protocol. | 32 // Create encoder for the specified protocol. |
| 34 static std::unique_ptr<WebrtcVideoEncoderVpx> CreateForVP8(); | 33 static std::unique_ptr<WebrtcVideoEncoderVpx> CreateForVP8(); |
| 35 static std::unique_ptr<WebrtcVideoEncoderVpx> CreateForVP9(); | 34 static std::unique_ptr<WebrtcVideoEncoderVpx> CreateForVP9(); |
| 36 | 35 |
| 37 ~WebrtcVideoEncoderVpx() override; | 36 ~WebrtcVideoEncoderVpx() override; |
| 38 | 37 |
| 39 void SetTickClockForTests(base::TickClock* tick_clock); | 38 void SetTickClockForTests(base::TickClock* tick_clock); |
| 40 | 39 |
| 41 // VideoEncoder interface. | 40 void SetLosslessEncode(bool want_lossless); |
| 42 void SetLosslessEncode(bool want_lossless) override; | 41 void SetLosslessColor(bool want_lossless); |
| 43 void SetLosslessColor(bool want_lossless) override; | 42 |
| 44 std::unique_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame, | 43 // WebrtcVideoEncoder interface. |
| 45 uint32_t flags) override; | 44 std::unique_ptr<EncodedFrame> Encode(const webrtc::DesktopFrame& frame, |
| 46 void UpdateTargetBitrate(int bitrate_kbps) override; | 45 const FrameParams& params) override; |
| 47 | 46 |
| 48 private: | 47 private: |
| 49 explicit WebrtcVideoEncoderVpx(bool use_vp9); | 48 explicit WebrtcVideoEncoderVpx(bool use_vp9); |
| 50 | 49 |
| 51 // (Re)Configures this instance to encode frames of the specified |size|, | 50 // (Re)Configures this instance to encode frames of the specified |size|, |
| 52 // with the configured lossless color & encoding modes. | 51 // with the configured lossless color & encoding modes. |
| 53 void Configure(const webrtc::DesktopSize& size); | 52 void Configure(const webrtc::DesktopSize& size); |
| 54 | 53 |
| 54 // Updates target bitrate. |
| 55 void UpdateTargetBitrate(int new_bitrate_kbps); |
| 56 |
| 55 // Prepares |image_| for encoding. Writes updated rectangles into | 57 // Prepares |image_| for encoding. Writes updated rectangles into |
| 56 // |updated_region|. | 58 // |updated_region|. |
| 57 void PrepareImage(const webrtc::DesktopFrame& frame, | 59 void PrepareImage(const webrtc::DesktopFrame& frame, |
| 58 webrtc::DesktopRegion* updated_region); | 60 webrtc::DesktopRegion* updated_region); |
| 59 | 61 |
| 60 // Updates the active map according to |updated_region|. Active map is then | 62 // Updates the active map according to |updated_region|. Active map is then |
| 61 // given to the encoder to speed up encoding. | 63 // given to the encoder to speed up encoding. |
| 62 void SetActiveMapFromRegion(const webrtc::DesktopRegion& updated_region); | 64 void SetActiveMapFromRegion(const webrtc::DesktopRegion& updated_region); |
| 63 | 65 |
| 64 // Adds areas changed in the most recent frame to |updated_region|. This | 66 // Adds areas changed in the most recent frame to |updated_region|. This |
| (...skipping 21 matching lines...) Expand all Loading... |
| 86 std::unique_ptr<vpx_image_t> image_; | 88 std::unique_ptr<vpx_image_t> image_; |
| 87 std::unique_ptr<uint8_t[]> image_buffer_; | 89 std::unique_ptr<uint8_t[]> image_buffer_; |
| 88 | 90 |
| 89 // Active map used to optimize out processing of un-changed macroblocks. | 91 // Active map used to optimize out processing of un-changed macroblocks. |
| 90 std::unique_ptr<uint8_t[]> active_map_; | 92 std::unique_ptr<uint8_t[]> active_map_; |
| 91 webrtc::DesktopSize active_map_size_; | 93 webrtc::DesktopSize active_map_size_; |
| 92 | 94 |
| 93 // True if the codec wants unchanged frames to finish topping-off with. | 95 // True if the codec wants unchanged frames to finish topping-off with. |
| 94 bool encode_unchanged_frame_; | 96 bool encode_unchanged_frame_; |
| 95 | 97 |
| 96 // Used to help initialize VideoPackets from DesktopFrames. | |
| 97 VideoEncoderHelper helper_; | |
| 98 | |
| 99 base::DefaultTickClock default_tick_clock_; | 98 base::DefaultTickClock default_tick_clock_; |
| 100 base::TickClock* clock_; | 99 base::TickClock* clock_; |
| 101 | 100 |
| 102 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoEncoderVpx); | 101 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoEncoderVpx); |
| 103 }; | 102 }; |
| 104 | 103 |
| 105 } // namespace remoting | 104 } // namespace remoting |
| 106 | 105 |
| 107 #endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_ | 106 #endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_VPX_H_ |
| OLD | NEW |