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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Callback for CaptureScheduler. |
51 void CaptureNextFrame(); | 51 void CaptureNextFrame(); |
52 | 52 |
53 // Task running on the encoder thread to encode the |frame|. | 53 // Task running on the encoder thread to encode the |frame|. |
54 static std::unique_ptr<VideoPacket> EncodeFrame( | 54 static std::unique_ptr<VideoPacket> EncodeFrame( |
55 VideoEncoder* encoder, | 55 VideoEncoder* encoder, |
56 std::unique_ptr<webrtc::DesktopFrame> frame, | 56 std::unique_ptr<webrtc::DesktopFrame> frame, |
57 bool key_frame_request); | 57 uint32_t target_bitrate, |
| 58 bool key_frame_request, |
| 59 int64_t capture_time_ms); |
58 void OnFrameEncoded(std::unique_ptr<VideoPacket> packet); | 60 void OnFrameEncoded(std::unique_ptr<VideoPacket> packet); |
59 | 61 |
60 void SetKeyFrameRequest(); | 62 void SetKeyFrameRequest(); |
61 bool ClearAndGetKeyFrameRequest(); | 63 bool ClearAndGetKeyFrameRequest(); |
| 64 void SetTargetBitrate(int bitrate); |
62 | 65 |
63 // Protects |key_frame_request_|. | 66 // Protects |key_frame_request_| and |target_bitrate_kbps_|. |
64 base::Lock lock_; | 67 base::Lock lock_; |
65 bool key_frame_request_ = false; | 68 bool key_frame_request_ = false; |
| 69 uint32_t target_bitrate_kbps_; |
| 70 int last_quantizer_; |
66 | 71 |
67 bool capture_pending_ = false; | 72 bool capture_pending_ = false; |
68 bool encode_pending_ = false; | 73 bool encode_pending_ = false; |
69 | 74 |
| 75 // Last time capture was completed. |
| 76 base::TimeTicks last_capture_completed_ticks_; |
| 77 // Last time capture was started. |
| 78 base::TimeTicks last_capture_started_ticks_; |
| 79 |
70 webrtc::DesktopSize frame_size_; | 80 webrtc::DesktopSize frame_size_; |
71 webrtc::DesktopVector frame_dpi_; | 81 webrtc::DesktopVector frame_dpi_; |
72 VideoStream::SizeCallback size_callback_; | 82 VideoStream::SizeCallback size_callback_; |
73 | 83 |
74 // Task runner used to run |encoder_|. | 84 // Task runner used to run |encoder_|. |
75 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 85 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
76 base::CancelableTaskTracker task_tracker_; | 86 base::CancelableTaskTracker task_tracker_; |
77 | 87 |
78 // Capturer used to capture the screen. | 88 // Capturer used to capture the screen. |
79 std::unique_ptr<webrtc::DesktopCapturer> capturer_; | 89 std::unique_ptr<webrtc::DesktopCapturer> capturer_; |
80 | 90 |
81 std::unique_ptr<base::RepeatingTimer> capture_timer_; | 91 std::unique_ptr<base::RepeatingTimer> capture_timer_; |
82 | 92 |
83 // Used to send across encoded frames. | 93 // Used to send across encoded frames. |
84 WebrtcTransport* webrtc_transport_; | 94 WebrtcTransport* webrtc_transport_; |
85 | 95 |
86 // Used to encode captured frames. Always accessed on the encode thread. | 96 // Used to encode captured frames. Always accessed on the encode thread. |
87 std::unique_ptr<VideoEncoder> encoder_; | 97 std::unique_ptr<VideoEncoder> encoder_; |
88 | 98 |
89 base::ThreadChecker thread_checker_; | 99 base::ThreadChecker thread_checker_; |
90 base::TimeTicks last_capture_ticks_; | |
91 | 100 |
92 base::WeakPtrFactory<WebRtcFrameScheduler> weak_factory_; | 101 base::WeakPtrFactory<WebRtcFrameScheduler> weak_factory_; |
93 | 102 |
94 DISALLOW_COPY_AND_ASSIGN(WebRtcFrameScheduler); | 103 DISALLOW_COPY_AND_ASSIGN(WebRtcFrameScheduler); |
95 }; | 104 }; |
96 | 105 |
97 } // namespace protocol | 106 } // namespace protocol |
98 } // namespace remoting | 107 } // namespace remoting |
99 | 108 |
100 #endif // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ | 109 #endif // REMOTING_PROTOCOL_WEBRTC_FRAME_SCHEDULER_H_ |
OLD | NEW |