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_HOST_DESKTOP_CAPTURER_PROXY_H_ 6 #define REMOTING_HOST_DESKTOP_CAPTURER_PROXY_H_ 7 8 #include <memory> 9 10 #include "base/callback.h" 11 #include "base/macros.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/threading/thread_checker.h" 14 #include "remoting/host/desktop_display_info.h" 15 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" 16 17 namespace base { 18 class SingleThreadTaskRunner; 19 } // namespace base 20 21 namespace webrtc { 22 class DesktopCaptureOptions; 23 } // namespace webrtc 24 25 namespace remoting { 26 27 class ClientSessionControl; 28 29 // DesktopCapturerProxy is responsible for calling webrtc::DesktopCapturer on 30 // the capturer thread and then returning results to the caller's thread. 31 // GetSourceList() and SelectSource() functions are not implemented by this 32 // class, they always return false. 33 class DesktopCapturerProxy : public webrtc::DesktopCapturer { 34 public: 35 explicit DesktopCapturerProxy( 36 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 37 base::WeakPtr<ClientSessionControl> client_session_control); 38 ~DesktopCapturerProxy() override; 39 40 // CreateCapturer() should be used if the capturer needs to be created on the 41 // capturer thread. Alternatively the capturer can be passed to 42 // set_capturer(). 43 void CreateCapturer(const webrtc::DesktopCaptureOptions& options); 44 void set_capturer(std::unique_ptr<webrtc::DesktopCapturer> capturer); 45 46 // webrtc::DesktopCapturer interface. 47 void Start(Callback* callback) override; 48 void SetSharedMemoryFactory(std::unique_ptr<webrtc::SharedMemoryFactory> 49 shared_memory_factory) override; 50 void CaptureFrame() override; 51 bool GetSourceList(SourceList* sources) override; 52 bool SelectSource(SourceId id) override; 53 54 private: 55 class Core; 56 57 void OnFrameCaptured(webrtc::DesktopCapturer::Result result, 58 std::unique_ptr<webrtc::DesktopFrame> frame); 59 60 base::ThreadChecker thread_checker_; 61 62 std::unique_ptr<Core> core_; 63 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 64 webrtc::DesktopCapturer::Callback* callback_; 65 66 // Used to disconnect the client session. 67 // Note: This cannot be used on Windows because the ClientSession is not in 68 // the same process as the DesktopCapturerProxy. 69 base::WeakPtr<ClientSessionControl> client_session_control_; 70 71 // Contains the most recently gathered info about the desktop displays. 72 std::unique_ptr<DesktopDisplayInfo> desktop_display_info_; 73 74 base::WeakPtrFactory<DesktopCapturerProxy> weak_factory_{this}; 75 76 DISALLOW_COPY_AND_ASSIGN(DesktopCapturerProxy); 77 }; 78 79 } // namespace remoting 80 81 #endif // REMOTING_HOST_DESKTOP_CAPTURER_PROXY_H_ 82