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_CAPTURER_ADAPTER_H_ | 5 #ifndef REMOTING_PROTOCOL_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_ |
6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_ | 6 #define REMOTING_PROTOCOL_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.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/protocol/video_stream.h" | 18 #include "remoting/protocol/video_stream.h" |
19 #include "third_party/webrtc/media/base/videocapturer.h" | 19 #include "third_party/webrtc/media/base/videocapturer.h" |
20 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 20 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
21 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
(...skipping 14 matching lines...) Expand all Loading... |
39 // to construct a VideoSource as part of the webrtc PeerConnection API. | 39 // to construct a VideoSource as part of the webrtc PeerConnection API. |
40 // WebrtcVideoCapturerAdapter acts as an adapter between webrtc::DesktopCapturer | 40 // WebrtcVideoCapturerAdapter acts as an adapter between webrtc::DesktopCapturer |
41 // and the cricket::VideoCapturer interface, which it implements. It is used | 41 // and the cricket::VideoCapturer interface, which it implements. It is used |
42 // to construct a cricket::VideoSource for a PeerConnection, to capture frames | 42 // to construct a cricket::VideoSource for a PeerConnection, to capture frames |
43 // of the desktop. As indicated in the base implementation, Start() and Stop() | 43 // of the desktop. As indicated in the base implementation, Start() and Stop() |
44 // should be called on the same thread. | 44 // should be called on the same thread. |
45 class WebrtcVideoCapturerAdapter : public cricket::VideoCapturer, | 45 class WebrtcVideoCapturerAdapter : public cricket::VideoCapturer, |
46 public webrtc::DesktopCapturer::Callback { | 46 public webrtc::DesktopCapturer::Callback { |
47 public: | 47 public: |
48 explicit WebrtcVideoCapturerAdapter( | 48 explicit WebrtcVideoCapturerAdapter( |
49 scoped_ptr<webrtc::DesktopCapturer> capturer); | 49 std::unique_ptr<webrtc::DesktopCapturer> capturer); |
50 ~WebrtcVideoCapturerAdapter() override; | 50 ~WebrtcVideoCapturerAdapter() override; |
51 | 51 |
52 void SetSizeCallback(const VideoStream::SizeCallback& size_callback); | 52 void SetSizeCallback(const VideoStream::SizeCallback& size_callback); |
53 bool PauseCapturer(bool pause); | 53 bool PauseCapturer(bool pause); |
54 base::WeakPtr<WebrtcVideoCapturerAdapter> GetWeakPtr(); | 54 base::WeakPtr<WebrtcVideoCapturerAdapter> GetWeakPtr(); |
55 | 55 |
56 // cricket::VideoCapturer implementation. | 56 // cricket::VideoCapturer implementation. |
57 bool GetBestCaptureFormat(const cricket::VideoFormat& desired, | 57 bool GetBestCaptureFormat(const cricket::VideoFormat& desired, |
58 cricket::VideoFormat* best_format) override; | 58 cricket::VideoFormat* best_format) override; |
59 cricket::CaptureState Start( | 59 cricket::CaptureState Start( |
60 const cricket::VideoFormat& capture_format) override; | 60 const cricket::VideoFormat& capture_format) override; |
61 void Stop() override; | 61 void Stop() override; |
62 bool IsRunning() override; | 62 bool IsRunning() override; |
63 bool IsScreencast() const override; | 63 bool IsScreencast() const override; |
64 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; | 64 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; |
65 | 65 |
66 private: | 66 private: |
67 // webrtc::DesktopCapturer::Callback implementation. | 67 // webrtc::DesktopCapturer::Callback implementation. |
68 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | 68 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; |
69 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | 69 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; |
70 | 70 |
71 // Kicks off the next frame capture using |desktop_capturer_|. The captured | 71 // Kicks off the next frame capture using |desktop_capturer_|. The captured |
72 // frame will be passed to OnCaptureCompleted(). | 72 // frame will be passed to OnCaptureCompleted(). |
73 void CaptureNextFrame(); | 73 void CaptureNextFrame(); |
74 | 74 |
75 base::ThreadChecker thread_checker_; | 75 base::ThreadChecker thread_checker_; |
76 | 76 |
77 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer_; | 77 std::unique_ptr<webrtc::DesktopCapturer> desktop_capturer_; |
78 | 78 |
79 VideoStream::SizeCallback size_callback_; | 79 VideoStream::SizeCallback size_callback_; |
80 | 80 |
81 // Timer to call CaptureNextFrame(). | 81 // Timer to call CaptureNextFrame(). |
82 scoped_ptr<base::RepeatingTimer> capture_timer_; | 82 std::unique_ptr<base::RepeatingTimer> capture_timer_; |
83 | 83 |
84 webrtc::DesktopSize frame_size_; | 84 webrtc::DesktopSize frame_size_; |
85 webrtc::DesktopVector frame_dpi_; | 85 webrtc::DesktopVector frame_dpi_; |
86 | 86 |
87 // Video frame is kept between captures to avoid YUV conversion for static | 87 // Video frame is kept between captures to avoid YUV conversion for static |
88 // parts of the screen. | 88 // parts of the screen. |
89 rtc::scoped_refptr<webrtc::I420Buffer> yuv_frame_; | 89 rtc::scoped_refptr<webrtc::I420Buffer> yuv_frame_; |
90 | 90 |
91 bool capture_pending_ = false; | 91 bool capture_pending_ = false; |
92 bool paused_ = false; | 92 bool paused_ = false; |
93 | 93 |
94 base::WeakPtrFactory<WebrtcVideoCapturerAdapter> weak_factory_; | 94 base::WeakPtrFactory<WebrtcVideoCapturerAdapter> weak_factory_; |
95 | 95 |
96 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoCapturerAdapter); | 96 DISALLOW_COPY_AND_ASSIGN(WebrtcVideoCapturerAdapter); |
97 }; | 97 }; |
98 | 98 |
99 } // namespace protocol | 99 } // namespace protocol |
100 } // namespace remoting | 100 } // namespace remoting |
101 | 101 |
102 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_ | 102 #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_ |
OLD | NEW |