| 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" | 
|   18 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" |   19 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" | 
|   19 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |   20 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 
|   20 #include "webrtc/modules/desktop_capture/shared_memory.h" |   21 #include "webrtc/modules/desktop_capture/shared_memory.h" | 
|   21  |   22  | 
|   22 namespace webrtc { |   23 namespace webrtc { | 
|   23  |   24  | 
|   24 // A fake implementation of DesktopCapturer or its derived interfaces to |   25 // A fake implementation of DesktopCapturer or its derived interfaces to | 
|   25 // generate DesktopFrame for testing purpose. |   26 // generate DesktopFrame for testing purpose. | 
|   26 // |   27 // | 
|   27 // Consumers can provide a FrameGenerator instance to generate instances of |   28 // Consumers can provide a FrameGenerator instance to generate instances of | 
|   28 // DesktopFrame to return for each Capture() function call. |   29 // DesktopFrame to return for each Capture() function call. | 
|   29 // If no FrameGenerator provided, FakeDesktopCapturer will always return a |   30 // If no FrameGenerator provided, FakeDesktopCapturer will always return a | 
|   30 // nullptr DesktopFrame. |   31 // nullptr DesktopFrame. | 
|   31 // |   32 // | 
|   32 // Double buffering is guaranteed by the FrameGenerator. FrameGenerator |   33 // Double buffering is guaranteed by the FrameGenerator. FrameGenerator | 
|   33 // implements in desktop_frame_generator.h guarantee double buffering, they |   34 // implements in desktop_frame_generator.h guarantee double buffering, they | 
|   34 // creates a new instance of DesktopFrame each time. |   35 // creates a new instance of DesktopFrame each time. | 
|   35 // |   36 // | 
|   36 // T must be DesktopCapturer or its derived interfaces. |   37 // T must be DesktopCapturer or its derived interfaces. | 
|   37 // |   38 // | 
|   38 // TODO(zijiehe): Remove template T once we merge ScreenCapturer and |   39 // TODO(zijiehe): Remove template T once we merge ScreenCapturer and | 
|   39 // WindowCapturer. |   40 // WindowCapturer. | 
|   40 template <typename T> |   41 template <typename T = DesktopCapturer> | 
|   41 class FakeDesktopCapturer : public T { |   42 class FakeDesktopCapturer : public T { | 
|   42  public: |   43  public: | 
|   43   FakeDesktopCapturer() |   44   FakeDesktopCapturer() | 
|   44       : callback_(nullptr), |   45       : callback_(nullptr), | 
|   45         result_(DesktopCapturer::Result::SUCCESS), |   46         result_(DesktopCapturer::Result::SUCCESS), | 
|   46         generator_(nullptr) {} |   47         generator_(nullptr) {} | 
|   47  |   48  | 
|   48   ~FakeDesktopCapturer() override {} |   49   ~FakeDesktopCapturer() override {} | 
|   49  |   50  | 
|   50   // Decides the result which will be returned in next Capture() callback. |   51   // Decides the result which will be returned in next Capture() callback. | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|   76     } |   77     } | 
|   77     callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, |   78     callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, | 
|   78                                nullptr); |   79                                nullptr); | 
|   79   } |   80   } | 
|   80  |   81  | 
|   81   void SetSharedMemoryFactory( |   82   void SetSharedMemoryFactory( | 
|   82       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override { |   83       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override { | 
|   83     shared_memory_factory_ = std::move(shared_memory_factory); |   84     shared_memory_factory_ = std::move(shared_memory_factory); | 
|   84   } |   85   } | 
|   85  |   86  | 
 |   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  | 
|   86  private: |   97  private: | 
 |   98   static constexpr DesktopCapturer::SourceId kWindowId = 1378277495; | 
 |   99   static constexpr DesktopCapturer::SourceId kScreenId = 1378277496; | 
 |  100  | 
|   87   DesktopCapturer::Callback* callback_; |  101   DesktopCapturer::Callback* callback_; | 
|   88   std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; |  102   std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | 
|   89   DesktopCapturer::Result result_; |  103   DesktopCapturer::Result result_; | 
|   90   DesktopFrameGenerator* generator_; |  104   DesktopFrameGenerator* generator_; | 
|   91 }; |  105 }; | 
|   92  |  106  | 
|   93 }  // namespace webrtc |  107 }  // namespace webrtc | 
|   94  |  108  | 
|   95 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ |  109 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ | 
| OLD | NEW |