| 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" | 17 #include "base/timer/timer.h" |
| 18 #include "remoting/codec/video_encoder.h" | 18 #include "remoting/codec/webrtc_video_encoder.h" |
| 19 #include "remoting/protocol/host_video_stats_dispatcher.h" | 19 #include "remoting/protocol/host_video_stats_dispatcher.h" |
| 20 #include "remoting/protocol/video_stream.h" | 20 #include "remoting/protocol/video_stream.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 class MediaStreamInterface; | 24 class MediaStreamInterface; |
| 25 class PeerConnectionInterface; | 25 class PeerConnectionInterface; |
| 26 class PeerConnectionFactoryInterface; | 26 class PeerConnectionFactoryInterface; |
| 27 class VideoTrackInterface; | 27 class VideoTrackInterface; |
| 28 } // namespace webrtc | 28 } // namespace webrtc |
| 29 | 29 |
| 30 namespace remoting { | 30 namespace remoting { |
| 31 namespace protocol { | 31 namespace protocol { |
| 32 | 32 |
| 33 class HostVideoStatsDispatcher; | 33 class HostVideoStatsDispatcher; |
| 34 class WebrtcVideoCapturerAdapter; | 34 class WebrtcVideoCapturerAdapter; |
| 35 class WebrtcTransport; | 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( | 44 bool Start(std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer, |
| 45 std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer, | 45 WebrtcTransport* webrtc_transport, |
| 46 WebrtcTransport* webrtc_transport, | 46 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner); |
| 47 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | |
| 48 std::unique_ptr<VideoEncoder> video_encoder); | |
| 49 | 47 |
| 50 // VideoStream interface. | 48 // VideoStream interface. |
| 51 void Pause(bool pause) override; | 49 void Pause(bool pause) override; |
| 52 void OnInputEventReceived(int64_t event_timestamp) override; | 50 void OnInputEventReceived(int64_t event_timestamp) override; |
| 53 void SetLosslessEncode(bool want_lossless) override; | 51 void SetLosslessEncode(bool want_lossless) override; |
| 54 void SetLosslessColor(bool want_lossless) override; | 52 void SetLosslessColor(bool want_lossless) override; |
| 55 void SetObserver(Observer* observer) override; | 53 void SetObserver(Observer* observer) override; |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 struct FrameTimestamps; | 56 struct FrameTimestamps; |
| 59 struct EncodedFrameWithTimestamps; | 57 struct EncodedFrameWithTimestamps; |
| 60 | 58 |
| 61 // webrtc::DesktopCapturer::Callback interface. | 59 // webrtc::DesktopCapturer::Callback interface. |
| 62 void OnCaptureResult(webrtc::DesktopCapturer::Result result, | 60 void OnCaptureResult(webrtc::DesktopCapturer::Result result, |
| 63 std::unique_ptr<webrtc::DesktopFrame> frame) override; | 61 std::unique_ptr<webrtc::DesktopFrame> frame) override; |
| 64 | 62 |
| 65 // HostVideoStatsDispatcher::EventHandler interface. | 63 // HostVideoStatsDispatcher::EventHandler interface. |
| 66 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; | 64 void OnChannelInitialized(ChannelDispatcherBase* channel_dispatcher) override; |
| 67 void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override; | 65 void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) override; |
| 68 | 66 |
| 69 // Starts |capture_timer_|. | 67 // Starts |capture_timer_|. |
| 70 void StartCaptureTimer(); | 68 void StartCaptureTimer(); |
| 71 | 69 |
| 72 // Called by |capture_timer_|. | 70 // Called by |capture_timer_|. |
| 73 void CaptureNextFrame(); | 71 void CaptureNextFrame(); |
| 74 | 72 |
| 75 // Task running on the encoder thread to encode the |frame|. | 73 // Task running on the encoder thread to encode the |frame|. |
| 76 static EncodedFrameWithTimestamps EncodeFrame( | 74 static EncodedFrameWithTimestamps EncodeFrame( |
| 77 VideoEncoder* encoder, | 75 WebrtcVideoEncoder* encoder, |
| 78 std::unique_ptr<webrtc::DesktopFrame> frame, | 76 std::unique_ptr<webrtc::DesktopFrame> frame, |
| 79 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps, | 77 WebrtcVideoEncoder::FrameParams params, |
| 80 uint32_t target_bitrate_kbps, | 78 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps); |
| 81 bool key_frame_request); | |
| 82 void OnFrameEncoded(EncodedFrameWithTimestamps frame); | 79 void OnFrameEncoded(EncodedFrameWithTimestamps frame); |
| 83 | 80 |
| 84 void SetKeyFrameRequest(); | 81 void SetKeyFrameRequest(); |
| 85 bool ClearAndGetKeyFrameRequest(); | 82 bool ClearAndGetKeyFrameRequest(); |
| 86 void SetTargetBitrate(int bitrate); | 83 void SetTargetBitrate(int bitrate); |
| 87 | 84 |
| 88 // Capturer used to capture the screen. | 85 // Capturer used to capture the screen. |
| 89 std::unique_ptr<webrtc::DesktopCapturer> capturer_; | 86 std::unique_ptr<webrtc::DesktopCapturer> capturer_; |
| 90 // Used to send across encoded frames. | 87 // Used to send across encoded frames. |
| 91 WebrtcTransport* webrtc_transport_ = nullptr; | 88 WebrtcTransport* webrtc_transport_ = nullptr; |
| 92 // Task runner used to run |encoder_|. | 89 // Task runner used to run |encoder_|. |
| 93 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 90 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 94 // Used to encode captured frames. Always accessed on the encode thread. | 91 // Used to encode captured frames. Always accessed on the encode thread. |
| 95 std::unique_ptr<VideoEncoder> encoder_; | 92 std::unique_ptr<WebrtcVideoEncoder> encoder_; |
| 96 | 93 |
| 97 scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 94 scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 98 scoped_refptr<webrtc::MediaStreamInterface> stream_; | 95 scoped_refptr<webrtc::MediaStreamInterface> stream_; |
| 99 | 96 |
| 100 HostVideoStatsDispatcher video_stats_dispatcher_; | 97 HostVideoStatsDispatcher video_stats_dispatcher_; |
| 101 | 98 |
| 102 // Timestamps for the frame to be captured next. | 99 // Timestamps for the frame to be captured next. |
| 103 std::unique_ptr<FrameTimestamps> next_frame_timestamps_; | 100 std::unique_ptr<FrameTimestamps> next_frame_timestamps_; |
| 104 | 101 |
| 105 // Timestamps for the frame that's being captured. | 102 // Timestamps for the frame that's being captured. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 126 | 123 |
| 127 base::WeakPtrFactory<WebrtcVideoStream> weak_factory_; | 124 base::WeakPtrFactory<WebrtcVideoStream> weak_factory_; |
| 128 | 125 |
| 129 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoStream); | 126 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoStream); |
| 130 }; | 127 }; |
| 131 | 128 |
| 132 } // namespace protocol | 129 } // namespace protocol |
| 133 } // namespace remoting | 130 } // namespace remoting |
| 134 | 131 |
| 135 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ | 132 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_STREAM_H_ |
| OLD | NEW |