| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 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 | 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 | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 
| 13 | 13 | 
| 14 #include <memory> | 14 #include <memory> | 
| 15 #include <utility> | 15 #include <utility> | 
| 16 | 16 | 
| 17 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | 17 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | 
| 18 #include "webrtc/modules/desktop_capture/desktop_capture_types.h" |  | 
| 19 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" | 18 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" | 
| 20 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 19 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 
| 21 #include "webrtc/modules/desktop_capture/shared_memory.h" | 20 #include "webrtc/modules/desktop_capture/shared_memory.h" | 
| 22 | 21 | 
| 23 namespace webrtc { | 22 namespace webrtc { | 
| 24 | 23 | 
| 25 // A fake implementation of DesktopCapturer or its derived interfaces to | 24 // A fake implementation of DesktopCapturer or its derived interfaces to | 
| 26 // generate DesktopFrame for testing purpose. | 25 // generate DesktopFrame for testing purpose. | 
| 27 // | 26 // | 
| 28 // Consumers can provide a FrameGenerator instance to generate instances of | 27 // Consumers can provide a FrameGenerator instance to generate instances of | 
| 29 // DesktopFrame to return for each Capture() function call. | 28 // DesktopFrame to return for each Capture() function call. | 
| 30 // If no FrameGenerator provided, FakeDesktopCapturer will always return a | 29 // If no FrameGenerator provided, FakeDesktopCapturer will always return a | 
| 31 // nullptr DesktopFrame. | 30 // nullptr DesktopFrame. | 
| 32 // | 31 // | 
| 33 // Double buffering is guaranteed by the FrameGenerator. FrameGenerator | 32 // Double buffering is guaranteed by the FrameGenerator. FrameGenerator | 
| 34 // implements in desktop_frame_generator.h guarantee double buffering, they | 33 // implements in desktop_frame_generator.h guarantee double buffering, they | 
| 35 // creates a new instance of DesktopFrame each time. | 34 // creates a new instance of DesktopFrame each time. | 
| 36 // | 35 // | 
| 37 // T must be DesktopCapturer or its derived interfaces. | 36 // T must be DesktopCapturer or its derived interfaces. | 
| 38 // | 37 // | 
| 39 // TODO(zijiehe): Remove template T once we merge ScreenCapturer and | 38 // TODO(zijiehe): Remove template T once we merge ScreenCapturer and | 
| 40 // WindowCapturer. | 39 // WindowCapturer. | 
| 41 template <typename T = DesktopCapturer> | 40 template <typename T> | 
| 42 class FakeDesktopCapturer : public T { | 41 class FakeDesktopCapturer : public T { | 
| 43  public: | 42  public: | 
| 44   FakeDesktopCapturer() | 43   FakeDesktopCapturer() | 
| 45       : callback_(nullptr), | 44       : callback_(nullptr), | 
| 46         result_(DesktopCapturer::Result::SUCCESS), | 45         result_(DesktopCapturer::Result::SUCCESS), | 
| 47         generator_(nullptr) {} | 46         generator_(nullptr) {} | 
| 48 | 47 | 
| 49   ~FakeDesktopCapturer() override {} | 48   ~FakeDesktopCapturer() override {} | 
| 50 | 49 | 
| 51   // Decides the result which will be returned in next Capture() callback. | 50   // Decides the result which will be returned in next Capture() callback. | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 77     } | 76     } | 
| 78     callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, | 77     callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, | 
| 79                                nullptr); | 78                                nullptr); | 
| 80   } | 79   } | 
| 81 | 80 | 
| 82   void SetSharedMemoryFactory( | 81   void SetSharedMemoryFactory( | 
| 83       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override { | 82       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override { | 
| 84     shared_memory_factory_ = std::move(shared_memory_factory); | 83     shared_memory_factory_ = std::move(shared_memory_factory); | 
| 85   } | 84   } | 
| 86 | 85 | 
| 87   bool GetSourceList(DesktopCapturer::SourceList* sources) override { |  | 
| 88     sources->push_back({kWindowId, "A-Fake-DesktopCapturer-Window"}); |  | 
| 89     sources->push_back({kScreenId}); |  | 
| 90     return true; |  | 
| 91   } |  | 
| 92 |  | 
| 93   bool SelectSource(DesktopCapturer::SourceId id) override { |  | 
| 94     return id == kWindowId || id == kScreenId || id == kFullDesktopScreenId; |  | 
| 95   } |  | 
| 96 |  | 
| 97  private: | 86  private: | 
| 98   static constexpr DesktopCapturer::SourceId kWindowId = 1378277495; |  | 
| 99   static constexpr DesktopCapturer::SourceId kScreenId = 1378277496; |  | 
| 100 |  | 
| 101   DesktopCapturer::Callback* callback_; | 87   DesktopCapturer::Callback* callback_; | 
| 102   std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | 88   std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | 
| 103   DesktopCapturer::Result result_; | 89   DesktopCapturer::Result result_; | 
| 104   DesktopFrameGenerator* generator_; | 90   DesktopFrameGenerator* generator_; | 
| 105 }; | 91 }; | 
| 106 | 92 | 
| 107 }  // namespace webrtc | 93 }  // namespace webrtc | 
| 108 | 94 | 
| 109 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 95 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 
| OLD | NEW | 
|---|