| 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_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ |
| 6 #define REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 void Stop(); | 40 void Stop(); |
| 41 | 41 |
| 42 void Pause(bool pause); | 42 void Pause(bool pause); |
| 43 | 43 |
| 44 void SetSizeCallback(const VideoStream::SizeCallback& size_callback); | 44 void SetSizeCallback(const VideoStream::SizeCallback& size_callback); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 // webrtc::DesktopCapturer::Callback interface. | 47 // webrtc::DesktopCapturer::Callback interface. |
| 48 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | 48 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; |
| 49 | 49 |
| 50 // Callback for CaptureScheduler. | 50 // Starts |capture_timer_|. |
| 51 void StartCaptureTimer(); |
| 52 |
| 53 // Called by |capture_timer_|. |
| 51 void CaptureNextFrame(); | 54 void CaptureNextFrame(); |
| 52 | 55 |
| 53 // Task running on the encoder thread to encode the |frame|. | 56 // Task running on the encoder thread to encode the |frame|. |
| 54 static std::unique_ptr<VideoPacket> EncodeFrame( | 57 static std::unique_ptr<VideoPacket> EncodeFrame( |
| 55 VideoEncoder* encoder, | 58 VideoEncoder* encoder, |
| 56 std::unique_ptr<webrtc::DesktopFrame> frame, | 59 std::unique_ptr<webrtc::DesktopFrame> frame, |
| 57 uint32_t target_bitrate, | 60 uint32_t target_bitrate, |
| 58 bool key_frame_request, | 61 bool key_frame_request, |
| 59 int64_t capture_time_ms); | 62 int64_t capture_time_ms); |
| 60 void OnFrameEncoded(std::unique_ptr<VideoPacket> packet); | 63 void OnFrameEncoded(std::unique_ptr<VideoPacket> packet); |
| 61 | 64 |
| 62 void SetKeyFrameRequest(); | 65 void SetKeyFrameRequest(); |
| 63 bool ClearAndGetKeyFrameRequest(); | 66 bool ClearAndGetKeyFrameRequest(); |
| 64 void SetTargetBitrate(int bitrate); | 67 void SetTargetBitrate(int bitrate); |
| 65 | 68 |
| 66 // Protects |key_frame_request_| and |target_bitrate_kbps_|. | 69 // Protects |key_frame_request_| and |target_bitrate_kbps_|. |
| 67 base::Lock lock_; | 70 base::Lock lock_; |
| 68 bool key_frame_request_ = false; | 71 bool key_frame_request_ = false; |
| 69 uint32_t target_bitrate_kbps_; | 72 uint32_t target_bitrate_kbps_; |
| 70 int last_quantizer_; | 73 int last_quantizer_; |
| 71 | 74 |
| 75 bool received_first_frame_request_ = false; |
| 76 |
| 72 bool capture_pending_ = false; | 77 bool capture_pending_ = false; |
| 73 bool encode_pending_ = false; | 78 bool encode_pending_ = false; |
| 74 | 79 |
| 75 // Last time capture was completed. | 80 // Last time capture was completed. |
| 76 base::TimeTicks last_capture_completed_ticks_; | 81 base::TimeTicks last_capture_completed_ticks_; |
| 77 // Last time capture was started. | 82 // Last time capture was started. |
| 78 base::TimeTicks last_capture_started_ticks_; | 83 base::TimeTicks last_capture_started_ticks_; |
| 79 | 84 |
| 80 webrtc::DesktopSize frame_size_; | 85 webrtc::DesktopSize frame_size_; |
| 81 webrtc::DesktopVector frame_dpi_; | 86 webrtc::DesktopVector frame_dpi_; |
| 82 VideoStream::SizeCallback size_callback_; | 87 VideoStream::SizeCallback size_callback_; |
| 83 | 88 |
| 89 // Main task runner. |
| 90 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 91 |
| 84 // Task runner used to run |encoder_|. | 92 // Task runner used to run |encoder_|. |
| 85 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 86 base::CancelableTaskTracker task_tracker_; | 94 base::CancelableTaskTracker task_tracker_; |
| 87 | 95 |
| 88 // Capturer used to capture the screen. | 96 // Capturer used to capture the screen. |
| 89 std::unique_ptr<webrtc::DesktopCapturer> capturer_; | 97 std::unique_ptr<webrtc::DesktopCapturer> capturer_; |
| 90 | 98 |
| 91 std::unique_ptr<base::RepeatingTimer> capture_timer_; | 99 std::unique_ptr<base::RepeatingTimer> capture_timer_; |
| 92 | 100 |
| 93 // Used to send across encoded frames. | 101 // Used to send across encoded frames. |
| 94 WebrtcTransport* webrtc_transport_; | 102 WebrtcTransport* webrtc_transport_; |
| 95 | 103 |
| 96 // Used to encode captured frames. Always accessed on the encode thread. | 104 // Used to encode captured frames. Always accessed on the encode thread. |
| 97 std::unique_ptr<VideoEncoder> encoder_; | 105 std::unique_ptr<VideoEncoder> encoder_; |
| 98 | 106 |
| 99 base::ThreadChecker thread_checker_; | 107 base::ThreadChecker thread_checker_; |
| 100 | 108 |
| 101 base::WeakPtrFactory<WebRtcFrameScheduler> weak_factory_; | 109 base::WeakPtrFactory<WebRtcFrameScheduler> weak_factory_; |
| 102 | 110 |
| 103 DISALLOW_COPY_AND_ASSIGN(WebRtcFrameScheduler); | 111 DISALLOW_COPY_AND_ASSIGN(WebRtcFrameScheduler); |
| 104 }; | 112 }; |
| 105 | 113 |
| 106 } // namespace protocol | 114 } // namespace protocol |
| 107 } // namespace remoting | 115 } // namespace remoting |
| 108 | 116 |
| 109 #endif // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | 117 #endif // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ |
| OLD | NEW |