OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_HOST_CAST_VIDEO_CAPTURER_ADAPTER_H_ | |
6 #define REMOTING_HOST_CAST_VIDEO_CAPTURER_ADAPTER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "base/timer/timer.h" | |
14 #include "third_party/libjingle/source/talk/media/base/videocapturer.h" | |
15 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | |
16 | |
17 namespace base { | |
18 class SingleThreadTaskRunner; | |
19 } // namespace base | |
20 | |
21 namespace webrtc { | |
22 class DesktopFrame; | |
23 } // namespace webrtc | |
24 | |
25 namespace remoting { | |
26 | |
27 // This class controls the capture of video frames from the desktop and is used | |
28 // to construct a VideoSource as part of the webrtc PeerConnection API. | |
29 // CastVideoCapturerAdapter acts as an adapter between webrtc::DesktopCapturer | |
30 // and the cricket::VideoCapturer interface, which it implements. It is used | |
31 // to construct a cricket::VideoSource for a PeerConnection, to capture frames | |
32 // of the desktop. As indicated in the base implementation, Start() and Stop() | |
33 // should be called on the same thread. | |
34 class CastVideoCapturerAdapter : public cricket::VideoCapturer, | |
35 public webrtc::DesktopCapturer::Callback { | |
36 public: | |
37 explicit CastVideoCapturerAdapter( | |
38 scoped_ptr<webrtc::DesktopCapturer> capturer); | |
39 | |
40 ~CastVideoCapturerAdapter() override; | |
41 | |
42 // webrtc::DesktopCapturer::Callback implementation. | |
43 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; | |
44 // Converts |frame| to a cricket::CapturedFrame and emits that via | |
45 // SignalFrameCaptured for the base::VideoCapturer implementation to process. | |
46 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; | |
47 | |
48 // cricket::VideoCapturer implementation. | |
49 bool GetBestCaptureFormat(const cricket::VideoFormat& desired, | |
50 cricket::VideoFormat* best_format) override; | |
51 cricket::CaptureState Start( | |
52 const cricket::VideoFormat& capture_format) override; | |
53 bool Pause(bool pause) override; | |
54 void Stop() override; | |
55 bool IsRunning() override; | |
56 bool IsScreencast() const override; | |
57 bool GetPreferredFourccs(std::vector<uint32>* fourccs) override; | |
58 | |
59 private: | |
60 // Kicks off the next frame capture using |desktop_capturer_|. | |
61 // The captured frame will be passed to OnCaptureCompleted(). | |
62 void CaptureNextFrame(); | |
63 | |
64 // |thread_checker_| is bound to the peer connection worker thread. | |
65 base::ThreadChecker thread_checker_; | |
66 | |
67 // Used to capture frames. | |
68 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer_; | |
69 | |
70 // Used to schedule periodic screen captures. | |
71 scoped_ptr<base::RepeatingTimer> capture_timer_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(CastVideoCapturerAdapter); | |
74 }; | |
75 | |
76 } // namespace remoting | |
77 | |
78 #endif // REMOTING_HOST_CAST_VIDEO_CAPTURER_ADAPTER_H_ | |
79 | |
OLD | NEW |