1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_CAPTURE_RESULT_DESKTOP_CAPTURER_WRAPPER_H_ 12 #define MODULES_DESKTOP_CAPTURE_CAPTURE_RESULT_DESKTOP_CAPTURER_WRAPPER_H_ 13 14 #include <memory> 15 16 #include "modules/desktop_capture/desktop_capturer.h" 17 #include "modules/desktop_capture/desktop_capturer_wrapper.h" 18 #include "modules/desktop_capture/desktop_frame.h" 19 20 namespace webrtc { 21 22 // A DesktopCapturerWrapper implementation to capture the result of 23 // |base_capturer|. Derived classes are expected to provide a ResultObserver 24 // implementation to observe the DesktopFrame returned by |base_capturer_|. 25 class CaptureResultDesktopCapturerWrapper : public DesktopCapturerWrapper, 26 public DesktopCapturer::Callback { 27 public: 28 using Callback = DesktopCapturer::Callback; 29 30 // Provides a way to let derived classes or clients to modify the result 31 // returned by |base_capturer_|. 32 class ResultObserver { 33 public: 34 ResultObserver(); 35 virtual ~ResultObserver(); 36 37 virtual void Observe(Result* result, 38 std::unique_ptr<DesktopFrame>* frame) = 0; 39 }; 40 41 // |observer| must outlive this instance and can be |this|. |observer| is 42 // guaranteed to be executed only after the constructor and before the 43 // destructor. 44 CaptureResultDesktopCapturerWrapper( 45 std::unique_ptr<DesktopCapturer> base_capturer, 46 ResultObserver* observer); 47 48 ~CaptureResultDesktopCapturerWrapper() override; 49 50 // DesktopCapturer implementations. 51 void Start(Callback* callback) final; 52 53 private: 54 // DesktopCapturer::Callback implementation. 55 void OnCaptureResult(Result result, 56 std::unique_ptr<DesktopFrame> frame) final; 57 58 ResultObserver* const observer_; 59 Callback* callback_ = nullptr; 60 }; 61 62 } // namespace webrtc 63 64 #endif // MODULES_DESKTOP_CAPTURE_CAPTURE_RESULT_DESKTOP_CAPTURER_WRAPPER_H_ 65