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