Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 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 WEBRTC_MODULES_DESKTOP_CAPTURE_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_ | |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | |
| 17 #include "webrtc/modules/desktop_capture/desktop_capture_types.h" | |
| 18 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
| 19 #include "webrtc/modules/desktop_capture/shared_memory.h" | |
| 20 #include "webrtc/base/gtest_prod_util.h" | |
| 21 | |
| 22 namespace webrtc { | |
| 23 | |
| 24 // A DesktopCapturer wrapper owns two DesktopCapturer implementations. If the | |
| 25 // main DesktopCapturer fails, it uses the secondary one instead. Two capturers | |
| 26 // are expected to return same SourceList, and the meaning of each SourceId is | |
| 27 // identical, otherwise FallbackDesktopCapturerWrapper may return frames from | |
| 28 // different sources. | |
| 29 class FallbackDesktopCapturerWrapper final : public DesktopCapturer, | |
| 30 public DesktopCapturer::Callback { | |
| 31 public: | |
| 32 FallbackDesktopCapturerWrapper( | |
| 33 std::unique_ptr<DesktopCapturer> main_capturer, | |
| 34 std::unique_ptr<DesktopCapturer> secondary_capturer); | |
| 35 ~FallbackDesktopCapturerWrapper() override; | |
| 36 | |
| 37 // DesktopCapturer interface. | |
| 38 void Start(DesktopCapturer::Callback* callback) override; | |
| 39 void SetSharedMemoryFactory( | |
| 40 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; | |
| 41 void CaptureFrame() override; | |
| 42 void SetExcludedWindow(WindowId window) override; | |
| 43 bool GetSourceList(SourceList* sources) override; | |
| 44 bool SelectSource(SourceId id) override; | |
| 45 bool FocusOnSelectedSource() override; | |
| 46 | |
| 47 private: | |
| 48 FRIEND_TEST_WEBRTC(SharedMemoryFactoryWrapperTest, CreateShared); | |
| 49 | |
| 50 // Implementation to share a SharedMemoryFactory between DesktopCapturer | |
| 51 // instances. This class is designed for synchronized DesktopCapturer | |
| 52 // implementations only. | |
| 53 class SharedMemoryFactoryWrapper : public SharedMemoryFactory { | |
|
Sergey Ulanov
2017/02/16 19:14:17
Wrapper normally takes ownership of the wrapped ob
Sergey Ulanov
2017/02/16 19:14:18
Just declare the class here and move the definitio
Hzj_jie
2017/02/16 21:31:28
Done.
Hzj_jie
2017/02/16 21:31:28
The reason of putting it here is for test cases: t
| |
| 54 public: | |
| 55 explicit SharedMemoryFactoryWrapper( | |
| 56 std::unique_ptr<SharedMemoryFactory> factory); | |
| 57 ~SharedMemoryFactoryWrapper() override; | |
| 58 | |
| 59 // Creates a SharedMemoryFactory, which should not overlive current | |
| 60 // instance. | |
| 61 std::unique_ptr<SharedMemoryFactory> Wrap() const; | |
| 62 | |
| 63 // Forwards CreateSharedMemory() calls to |shared_factory_|. Users should | |
| 64 // always call this function in one thread. Users should not call this | |
| 65 // function after the SharedMemoryFactoryWrapper which current instance | |
| 66 // wrapped from has been destroyed. | |
| 67 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override; | |
| 68 | |
| 69 private: | |
| 70 explicit SharedMemoryFactoryWrapper(SharedMemoryFactory* factory); | |
| 71 | |
| 72 std::unique_ptr<SharedMemoryFactory> owned_factory_; | |
| 73 SharedMemoryFactory* shared_factory_ = nullptr; | |
| 74 rtc::ThreadChecker thread_checker_; | |
| 75 }; | |
| 76 | |
| 77 // DesktopCapturer::Callback interface. | |
| 78 void OnCaptureResult(Result result, | |
| 79 std::unique_ptr<DesktopFrame> frame) override; | |
| 80 | |
| 81 const std::unique_ptr<DesktopCapturer> main_capturer_; | |
| 82 const std::unique_ptr<DesktopCapturer> secondary_capturer_; | |
| 83 std::unique_ptr<SharedMemoryFactoryWrapper> shared_memory_factory_; | |
| 84 bool main_capturer_permanent_error_ = false; | |
| 85 DesktopCapturer::Callback* callback_ = nullptr; | |
| 86 }; | |
| 87 | |
| 88 } // namespace webrtc | |
| 89 | |
| 90 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_ | |
| OLD | NEW |