2 // Copyright 2004 Google Inc.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
7 // 1. Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // 3. The name of the author may not be used to endorse or promote products
13 // derived from this software without specific prior written permission.
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
27 #define TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
31 #include "talk/media/base/testutils.h"
32 #include "talk/media/webrtc/fakewebrtcdeviceinfo.h"
33 #include "talk/media/webrtc/webrtcvideocapturer.h"
35 class FakeWebRtcVcmFactory;
37 // Fake class for mocking out webrtc::VideoCaptureModule.
38 class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule {
40 FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory* factory, int32_t id)
47 virtual int32_t Version(char* version,
48 uint32_t& remaining_buffer_in_bytes,
49 uint32_t& position) const {
52 virtual int32_t TimeUntilNextProcess() {
55 virtual int32_t Process() {
58 virtual int32_t ChangeUniqueId(const int32_t id) {
62 #if defined(USE_WEBRTC_DEV_BRANCH)
63 virtual void RegisterCaptureDataCallback(
64 webrtc::VideoCaptureDataCallback& callback) {
65 callback_ = &callback;
67 virtual void DeRegisterCaptureDataCallback() { callback_ = NULL; }
68 virtual void RegisterCaptureCallback(webrtc::VideoCaptureFeedBack& callback) {
71 virtual void DeRegisterCaptureCallback() {
74 virtual void SetCaptureDelay(int32_t delay) { delay_ = delay; }
75 virtual int32_t CaptureDelay() { return delay_; }
76 virtual void EnableFrameRateCallback(const bool enable) {
79 virtual void EnableNoPictureAlarm(const bool enable) {
83 virtual int32_t RegisterCaptureDataCallback(
84 webrtc::VideoCaptureDataCallback& callback) {
85 callback_ = &callback;
88 virtual int32_t DeRegisterCaptureDataCallback() {
92 virtual int32_t RegisterCaptureCallback(
93 webrtc::VideoCaptureFeedBack& callback) {
94 return -1; // not implemented
96 virtual int32_t DeRegisterCaptureCallback() {
99 virtual int32_t SetCaptureDelay(int32_t delay) {
103 virtual int32_t CaptureDelay() {
106 virtual int32_t EnableFrameRateCallback(const bool enable) {
107 return -1; // not implemented
109 virtual int32_t EnableNoPictureAlarm(const bool enable) {
110 return -1; // not implemented
113 virtual int32_t StartCapture(
114 const webrtc::VideoCaptureCapability& cap) {
115 if (running_) return -1;
120 virtual int32_t StopCapture() {
124 virtual const char* CurrentDeviceName() const {
125 return NULL; // not implemented
127 virtual bool CaptureStarted() {
130 virtual int32_t CaptureSettings(
131 webrtc::VideoCaptureCapability& settings) {
132 if (!running_) return -1;
137 virtual int32_t SetCaptureRotation(
138 webrtc::VideoCaptureRotation rotation) {
139 return -1; // not implemented
141 virtual VideoCaptureEncodeInterface* GetEncodeInterface(
142 const webrtc::VideoCodec& codec) {
143 return NULL; // not implemented
145 virtual int32_t AddRef() {
148 virtual int32_t Release() {
153 bool SendFrame(int w, int h) {
154 if (!running_) return false;
155 webrtc::I420VideoFrame sample;
156 // Setting stride based on width.
157 if (sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2) < 0) {
161 callback_->OnIncomingCapturedFrame(id_, sample);
166 const webrtc::VideoCaptureCapability& cap() const {
171 // Ref-counted, use Release() instead.
172 ~FakeWebRtcVideoCaptureModule();
174 FakeWebRtcVcmFactory* factory_;
176 webrtc::VideoCaptureDataCallback* callback_;
178 webrtc::VideoCaptureCapability cap_;
182 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_