OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_VIDEO_STREAM_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ |
6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "base/timer/timer.h" | |
18 #include "remoting/codec/webrtc_video_encoder.h" | 17 #include "remoting/codec/webrtc_video_encoder.h" |
19 #include "remoting/protocol/host_video_stats_dispatcher.h" | 18 #include "remoting/protocol/host_video_stats_dispatcher.h" |
20 #include "remoting/protocol/video_stream.h" | 19 #include "remoting/protocol/video_stream.h" |
21 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 20 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 class MediaStreamInterface; | 23 class MediaStreamInterface; |
25 class PeerConnectionInterface; | 24 class PeerConnectionInterface; |
26 class PeerConnectionFactoryInterface; | 25 class PeerConnectionFactoryInterface; |
27 class VideoTrackInterface; | 26 class VideoTrackInterface; |
28 } // namespace webrtc | 27 } // namespace webrtc |
29 | 28 |
30 namespace remoting { | 29 namespace remoting { |
31 namespace protocol { | 30 namespace protocol { |
32 | 31 |
33 class HostVideoStatsDispatcher; | 32 class HostVideoStatsDispatcher; |
| 33 class WebrtcFrameScheduler; |
| 34 class WebrtcTransport; |
34 class WebrtcVideoCapturerAdapter; | 35 class WebrtcVideoCapturerAdapter; |
35 class WebrtcTransport; | |
36 | 36 |
37 class WebrtcVideoStream : public VideoStream, | 37 class WebrtcVideoStream : public VideoStream, |
38 public webrtc::DesktopCapturer::Callback, | 38 public webrtc::DesktopCapturer::Callback, |
39 public HostVideoStatsDispatcher::EventHandler { | 39 public HostVideoStatsDispatcher::EventHandler { |
40 public: | 40 public: |
41 WebrtcVideoStream(); | 41 WebrtcVideoStream(); |
42 ~WebrtcVideoStream() override; | 42 ~WebrtcVideoStream() override; |
43 | 43 |
44 bool Start(std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer, | 44 bool Start(std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer, |
45 WebrtcTransport* webrtc_transport, | 45 WebrtcTransport* webrtc_transport, |
(...skipping 11 matching lines...) Expand all Loading... |
57 struct EncodedFrameWithTimestamps; | 57 struct EncodedFrameWithTimestamps; |
58 | 58 |
59 // webrtc::DesktopCapturer::Callback interface. | 59 // webrtc::DesktopCapturer::Callback interface. |
60 void OnCaptureResult(webrtc::DesktopCapturer::Result result, | 60 void OnCaptureResult(webrtc::DesktopCapturer::Result result, |
61 std::unique_ptr<webrtc::DesktopFrame> frame) override; | 61 std::unique_ptr<webrtc::DesktopFrame> frame) override; |
62 | 62 |
63 // HostVideoStatsDispatcher::EventHandler interface. | 63 // HostVideoStatsDispatcher::EventHandler interface. |
64 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; | 64 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; |
65 void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override; | 65 void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override; |
66 | 66 |
67 // Starts |capture_timer_|. | 67 // Called by the |scheduler_|. |
68 void StartCaptureTimer(); | |
69 | |
70 // Called by |capture_timer_|. | |
71 void CaptureNextFrame(); | 68 void CaptureNextFrame(); |
72 | 69 |
73 // Task running on the encoder thread to encode the |frame|. | 70 // Task running on the encoder thread to encode the |frame|. |
74 static EncodedFrameWithTimestamps EncodeFrame( | 71 static EncodedFrameWithTimestamps EncodeFrame( |
75 WebrtcVideoEncoder* encoder, | 72 WebrtcVideoEncoder* encoder, |
76 std::unique_ptr<webrtc::DesktopFrame> frame, | 73 std::unique_ptr<webrtc::DesktopFrame> frame, |
77 WebrtcVideoEncoder::FrameParams params, | 74 WebrtcVideoEncoder::FrameParams params, |
78 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps); | 75 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps); |
79 void OnFrameEncoded(EncodedFrameWithTimestamps frame); | 76 void OnFrameEncoded(EncodedFrameWithTimestamps frame); |
80 | 77 |
81 void SetKeyFrameRequest(); | 78 void SetKeyFrameRequest(); |
82 bool ClearAndGetKeyFrameRequest(); | |
83 void SetTargetBitrate(int bitrate); | 79 void SetTargetBitrate(int bitrate); |
84 | 80 |
85 // Capturer used to capture the screen. | 81 // Capturer used to capture the screen. |
86 std::unique_ptr<webrtc::DesktopCapturer> capturer_; | 82 std::unique_ptr<webrtc::DesktopCapturer> capturer_; |
87 // Used to send across encoded frames. | 83 // Used to send across encoded frames. |
88 WebrtcTransport* webrtc_transport_ = nullptr; | 84 WebrtcTransport* webrtc_transport_ = nullptr; |
89 // Task runner used to run |encoder_|. | 85 // Task runner used to run |encoder_|. |
90 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 86 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
91 // Used to encode captured frames. Always accessed on the encode thread. | 87 // Used to encode captured frames. Always accessed on the encode thread. |
92 std::unique_ptr<WebrtcVideoEncoder> encoder_; | 88 std::unique_ptr<WebrtcVideoEncoder> encoder_; |
93 | 89 |
94 scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 90 scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
95 scoped_refptr<webrtc::MediaStreamInterface> stream_; | 91 scoped_refptr<webrtc::MediaStreamInterface> stream_; |
96 | 92 |
97 HostVideoStatsDispatcher video_stats_dispatcher_; | 93 HostVideoStatsDispatcher video_stats_dispatcher_; |
98 | 94 |
99 // Timestamps for the frame to be captured next. | 95 // Timestamps for the frame to be captured next. |
100 std::unique_ptr<FrameTimestamps> next_frame_timestamps_; | 96 std::unique_ptr<FrameTimestamps> next_frame_timestamps_; |
101 | 97 |
102 // Timestamps for the frame that's being captured. | 98 // Timestamps for the frame that's being captured. |
103 std::unique_ptr<FrameTimestamps> captured_frame_timestamps_; | 99 std::unique_ptr<FrameTimestamps> captured_frame_timestamps_; |
104 | 100 |
105 bool key_frame_request_ = false; | 101 std::unique_ptr<WebrtcFrameScheduler> scheduler_; |
106 uint32_t target_bitrate_kbps_ = 1000; // Initial bitrate. | |
107 | 102 |
108 bool received_first_frame_request_ = false; | 103 bool received_first_frame_request_ = false; |
109 | 104 |
110 bool capture_pending_ = false; | |
111 bool encode_pending_ = false; | |
112 | |
113 // Last time capture was started. | |
114 base::TimeTicks last_capture_started_ticks_; | |
115 | |
116 webrtc::DesktopSize frame_size_; | 105 webrtc::DesktopSize frame_size_; |
117 webrtc::DesktopVector frame_dpi_; | 106 webrtc::DesktopVector frame_dpi_; |
118 Observer* observer_ = nullptr; | 107 Observer* observer_ = nullptr; |
119 | 108 |
120 base::RepeatingTimer capture_timer_; | |
121 | |
122 base::ThreadChecker thread_checker_; | 109 base::ThreadChecker thread_checker_; |
123 | 110 |
124 base::WeakPtrFactory<WebrtcVideoStream> weak_factory_; | 111 base::WeakPtrFactory<WebrtcVideoStream> weak_factory_; |
125 | 112 |
126 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoStream); | 113 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoStream); |
127 }; | 114 }; |
128 | 115 |
129 } // namespace protocol | 116 } // namespace protocol |
130 } // namespace remoting | 117 } // namespace remoting |
131 | 118 |
132 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ | 119 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ |
OLD | NEW |