1 // libjingle 2 // Copyright 2004 Google Inc. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // 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. 14 // 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. 25 26 #ifndef TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ 27 #define TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ 28 29 #include <vector> 30 31 #include "talk/media/base/testutils.h" 32 #include "talk/media/webrtc/fakewebrtcdeviceinfo.h" 33 #include "talk/media/webrtc/webrtcvideocapturer.h" 34 35 class FakeWebRtcVcmFactory; 36 37 // Fake class for mocking out webrtc::VideoCaptureModule. 38 class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule { 39 public: 40 FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory* factory, int32_t id) 41 : factory_(factory), 42 id_(id), 43 callback_(NULL), 44 running_(false), 45 delay_(0) { 46 } 47 virtual int32_t Version(char* version, 48 uint32_t& remaining_buffer_in_bytes, 49 uint32_t& position) const { 50 return 0; 51 } 52 virtual int32_t TimeUntilNextProcess() { 53 return 0; 54 } 55 virtual int32_t Process() { 56 return 0; 57 } 58 virtual int32_t ChangeUniqueId(const int32_t id) { 59 id_ = id; 60 return 0; 61 } 62 virtual int32_t RegisterCaptureDataCallback( 63 webrtc::VideoCaptureDataCallback& callback) { 64 callback_ = &callback; 65 return 0; 66 } 67 virtual int32_t DeRegisterCaptureDataCallback() { 68 callback_ = NULL; 69 return 0; 70 } 71 virtual int32_t RegisterCaptureCallback( 72 webrtc::VideoCaptureFeedBack& callback) { 73 return -1; // not implemented 74 } 75 virtual int32_t DeRegisterCaptureCallback() { 76 return 0; 77 } 78 virtual int32_t StartCapture( 79 const webrtc::VideoCaptureCapability& cap) { 80 if (running_) return -1; 81 cap_ = cap; 82 running_ = true; 83 return 0; 84 } 85 virtual int32_t StopCapture() { 86 running_ = false; 87 return 0; 88 } 89 virtual const char* CurrentDeviceName() const { 90 return NULL; // not implemented 91 } 92 virtual bool CaptureStarted() { 93 return running_; 94 } 95 virtual int32_t CaptureSettings( 96 webrtc::VideoCaptureCapability& settings) { 97 if (!running_) return -1; 98 settings = cap_; 99 return 0; 100 } 101 virtual int32_t SetCaptureDelay(int32_t delay) { 102 delay_ = delay; 103 return 0; 104 } 105 virtual int32_t CaptureDelay() { 106 return delay_; 107 } 108 virtual int32_t SetCaptureRotation( 109 webrtc::VideoCaptureRotation rotation) { 110 return -1; // not implemented 111 } 112 virtual VideoCaptureEncodeInterface* GetEncodeInterface( 113 const webrtc::VideoCodec& codec) { 114 return NULL; // not implemented 115 } 116 virtual int32_t EnableFrameRateCallback(const bool enable) { 117 return -1; // not implemented 118 } 119 virtual int32_t EnableNoPictureAlarm(const bool enable) { 120 return -1; // not implemented 121 } 122 virtual int32_t AddRef() { 123 return 0; 124 } 125 virtual int32_t Release() { 126 delete this; 127 return 0; 128 } 129 130 bool SendFrame(int w, int h) { 131 if (!running_) return false; 132 webrtc::I420VideoFrame sample; 133 // Setting stride based on width. 134 if (sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2) < 0) { 135 return false; 136 } 137 if (callback_) { 138 callback_->OnIncomingCapturedFrame(id_, sample); 139 } 140 return true; 141 } 142 143 const webrtc::VideoCaptureCapability& cap() const { 144 return cap_; 145 } 146 147 private: 148 // Ref-counted, use Release() instead. 149 ~FakeWebRtcVideoCaptureModule(); 150 151 FakeWebRtcVcmFactory* factory_; 152 int id_; 153 webrtc::VideoCaptureDataCallback* callback_; 154 bool running_; 155 webrtc::VideoCaptureCapability cap_; 156 int delay_; 157 }; 158 159 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ 160