| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ | 11 #ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ |
| 12 #define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ | 12 #define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ |
| 13 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "webrtc/media/base/testutils.h" | 16 #include "webrtc/media/base/testutils.h" |
| 17 #include "webrtc/media/engine/webrtcvideocapturer.h" | 17 #include "webrtc/media/engine/webrtcvideocapturer.h" |
| 18 | 18 |
| 19 class FakeWebRtcVcmFactory; | 19 class FakeWebRtcVcmFactory; |
| 20 | 20 |
| 21 // Fake class for mocking out webrtc::VideoCaptureModule. | 21 // Fake class for mocking out webrtc::VideoCaptureModule. |
| 22 class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule { | 22 class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule { |
| 23 public: | 23 public: |
| 24 FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory* factory, int32_t id) | 24 FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory* factory) |
| 25 : factory_(factory), | 25 : factory_(factory), |
| 26 id_(id), | |
| 27 callback_(NULL), | 26 callback_(NULL), |
| 28 running_(false), | 27 running_(false) { |
| 29 delay_(0) { | |
| 30 } | 28 } |
| 31 ~FakeWebRtcVideoCaptureModule(); | 29 ~FakeWebRtcVideoCaptureModule(); |
| 32 int64_t TimeUntilNextProcess() override { return 0; } | |
| 33 void Process() override {} | |
| 34 void RegisterCaptureDataCallback( | 30 void RegisterCaptureDataCallback( |
| 35 webrtc::VideoCaptureDataCallback& callback) override { | 31 rtc::VideoSinkInterface<webrtc::VideoFrame>* callback) override { |
| 36 callback_ = &callback; | 32 callback_ = callback; |
| 37 } | 33 } |
| 38 void DeRegisterCaptureDataCallback() override { callback_ = NULL; } | 34 void DeRegisterCaptureDataCallback() override { callback_ = NULL; } |
| 39 void RegisterCaptureCallback( | |
| 40 webrtc::VideoCaptureFeedBack& callback) override { | |
| 41 // Not implemented. | |
| 42 } | |
| 43 void DeRegisterCaptureCallback() override { | |
| 44 // Not implemented. | |
| 45 } | |
| 46 void SetCaptureDelay(int32_t delay) override { delay_ = delay; } | |
| 47 int32_t CaptureDelay() override { return delay_; } | |
| 48 void EnableFrameRateCallback(const bool enable) override { | |
| 49 // not implemented | |
| 50 } | |
| 51 void EnableNoPictureAlarm(const bool enable) override { | |
| 52 // not implemented | |
| 53 } | |
| 54 int32_t StartCapture(const webrtc::VideoCaptureCapability& cap) override { | 35 int32_t StartCapture(const webrtc::VideoCaptureCapability& cap) override { |
| 55 if (running_) return -1; | 36 if (running_) return -1; |
| 56 cap_ = cap; | 37 cap_ = cap; |
| 57 running_ = true; | 38 running_ = true; |
| 58 return 0; | 39 return 0; |
| 59 } | 40 } |
| 60 int32_t StopCapture() override { | 41 int32_t StopCapture() override { |
| 61 running_ = false; | 42 running_ = false; |
| 62 return 0; | 43 return 0; |
| 63 } | 44 } |
| 64 const char* CurrentDeviceName() const override { | 45 const char* CurrentDeviceName() const override { |
| 65 return NULL; // not implemented | 46 return NULL; // not implemented |
| 66 } | 47 } |
| 67 bool CaptureStarted() override { return running_; } | 48 bool CaptureStarted() override { return running_; } |
| 68 int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override { | 49 int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override { |
| 69 if (!running_) return -1; | 50 if (!running_) return -1; |
| 70 settings = cap_; | 51 settings = cap_; |
| 71 return 0; | 52 return 0; |
| 72 } | 53 } |
| 73 | 54 |
| 74 int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override { | 55 int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override { |
| 75 return -1; // not implemented | 56 return -1; // not implemented |
| 76 } | 57 } |
| 77 bool SetApplyRotation(bool enable) override { | 58 bool SetApplyRotation(bool enable) override { |
| 78 return true; // ignored | 59 return true; // ignored |
| 79 } | 60 } |
| 80 bool GetApplyRotation() override { | 61 bool GetApplyRotation() override { |
| 81 return true; // Rotation compensation is turned on. | 62 return true; // Rotation compensation is turned on. |
| 82 } | 63 } |
| 83 VideoCaptureEncodeInterface* GetEncodeInterface( | |
| 84 const webrtc::VideoCodec& codec) override { | |
| 85 return NULL; // not implemented | |
| 86 } | |
| 87 | |
| 88 void SendFrame(int w, int h) { | 64 void SendFrame(int w, int h) { |
| 89 if (!running_) return; | 65 if (!running_) return; |
| 90 | 66 |
| 91 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 67 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 92 new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); | 68 new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); |
| 93 // Initialize memory to satisfy DrMemory tests. See | 69 // Initialize memory to satisfy DrMemory tests. See |
| 94 // https://bugs.chromium.org/p/libyuv/issues/detail?id=377 | 70 // https://bugs.chromium.org/p/libyuv/issues/detail?id=377 |
| 95 buffer->InitializeData(); | 71 buffer->InitializeData(); |
| 96 if (callback_) { | 72 if (callback_) { |
| 97 callback_->OnIncomingCapturedFrame( | 73 callback_->OnFrame( |
| 98 id_, | |
| 99 webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 74 webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
| 100 } | 75 } |
| 101 } | 76 } |
| 102 | 77 |
| 103 const webrtc::VideoCaptureCapability& cap() const { | 78 const webrtc::VideoCaptureCapability& cap() const { |
| 104 return cap_; | 79 return cap_; |
| 105 } | 80 } |
| 106 | 81 |
| 107 private: | 82 private: |
| 108 FakeWebRtcVcmFactory* factory_; | 83 FakeWebRtcVcmFactory* factory_; |
| 109 int id_; | 84 rtc::VideoSinkInterface<webrtc::VideoFrame>* callback_; |
| 110 webrtc::VideoCaptureDataCallback* callback_; | |
| 111 bool running_; | 85 bool running_; |
| 112 webrtc::VideoCaptureCapability cap_; | 86 webrtc::VideoCaptureCapability cap_; |
| 113 int delay_; | |
| 114 }; | 87 }; |
| 115 | 88 |
| 116 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ | 89 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ |
| OLD | NEW |