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