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