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; } | 30 int64_t TimeUntilNextProcess() override { return 0; } |
33 void Process() override {} | 31 void Process() override {} |
34 void RegisterCaptureDataCallback( | 32 void RegisterCaptureDataCallback( |
35 webrtc::VideoCaptureDataCallback& callback) override { | 33 rtc::VideoSinkInterface<webrtc::VideoFrame>* callback) override { |
36 callback_ = &callback; | 34 callback_ = callback; |
37 } | 35 } |
38 void DeRegisterCaptureDataCallback() override { callback_ = NULL; } | 36 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 { | 37 int32_t StartCapture(const webrtc::VideoCaptureCapability& cap) override { |
55 if (running_) return -1; | 38 if (running_) return -1; |
56 cap_ = cap; | 39 cap_ = cap; |
57 running_ = true; | 40 running_ = true; |
58 return 0; | 41 return 0; |
59 } | 42 } |
60 int32_t StopCapture() override { | 43 int32_t StopCapture() override { |
61 running_ = false; | 44 running_ = false; |
62 return 0; | 45 return 0; |
63 } | 46 } |
64 const char* CurrentDeviceName() const override { | 47 const char* CurrentDeviceName() const override { |
65 return NULL; // not implemented | 48 return NULL; // not implemented |
66 } | 49 } |
67 bool CaptureStarted() override { return running_; } | 50 bool CaptureStarted() override { return running_; } |
68 int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override { | 51 int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override { |
69 if (!running_) return -1; | 52 if (!running_) return -1; |
70 settings = cap_; | 53 settings = cap_; |
71 return 0; | 54 return 0; |
72 } | 55 } |
73 | 56 |
74 int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override { | 57 int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override { |
75 return -1; // not implemented | 58 return -1; // not implemented |
76 } | 59 } |
77 bool SetApplyRotation(bool enable) override { | 60 bool SetApplyRotation(bool enable) override { |
78 return true; // ignored | 61 return true; // ignored |
79 } | 62 } |
80 bool GetApplyRotation() override { | 63 bool GetApplyRotation() override { |
81 return true; // Rotation compensation is turned on. | 64 return true; // Rotation compensation is turned on. |
82 } | 65 } |
83 VideoCaptureEncodeInterface* GetEncodeInterface( | |
84 const webrtc::VideoCodec& codec) override { | |
85 return NULL; // not implemented | |
86 } | |
87 | |
88 void SendFrame(int w, int h) { | 66 void SendFrame(int w, int h) { |
89 if (!running_) return; | 67 if (!running_) return; |
90 | 68 |
91 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 69 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
92 new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); | 70 new rtc::RefCountedObject<webrtc::I420Buffer>(w, h); |
93 // Initialize memory to satisfy DrMemory tests. See | 71 // Initialize memory to satisfy DrMemory tests. See |
94 // https://bugs.chromium.org/p/libyuv/issues/detail?id=377 | 72 // https://bugs.chromium.org/p/libyuv/issues/detail?id=377 |
95 buffer->InitializeData(); | 73 buffer->InitializeData(); |
96 if (callback_) { | 74 if (callback_) { |
97 callback_->OnIncomingCapturedFrame( | 75 callback_->OnFrame( |
98 id_, | |
99 webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 76 webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
100 } | 77 } |
101 } | 78 } |
102 | 79 |
103 const webrtc::VideoCaptureCapability& cap() const { | 80 const webrtc::VideoCaptureCapability& cap() const { |
104 return cap_; | 81 return cap_; |
105 } | 82 } |
106 | 83 |
107 private: | 84 private: |
108 FakeWebRtcVcmFactory* factory_; | 85 FakeWebRtcVcmFactory* factory_; |
109 int id_; | 86 rtc::VideoSinkInterface<webrtc::VideoFrame>* callback_; |
110 webrtc::VideoCaptureDataCallback* callback_; | |
111 bool running_; | 87 bool running_; |
112 webrtc::VideoCaptureCapability cap_; | 88 webrtc::VideoCaptureCapability cap_; |
113 int delay_; | |
114 }; | 89 }; |
115 | 90 |
116 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ | 91 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ |
OLD | NEW |