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 void RegisterCaptureDataCallback( 63 webrtc::VideoCaptureDataCallback& callback) { 64 callback_ = &callback; 65 } 66 virtual void DeRegisterCaptureDataCallback() { callback_ = NULL; } 67 virtual void RegisterCaptureCallback(webrtc::VideoCaptureFeedBack& callback) { 68 // Not implemented. 69 } 70 virtual void DeRegisterCaptureCallback() { 71 // Not implemented. 72 } 73 virtual void SetCaptureDelay(int32_t delay) { delay_ = delay; } 74 virtual int32_t CaptureDelay() { return delay_; } 75 virtual void EnableFrameRateCallback(const bool enable) { 76 // not implemented 77 } 78 virtual void EnableNoPictureAlarm(const bool enable) { 79 // not implemented 80 } 81 virtual int32_t StartCapture( 82 const webrtc::VideoCaptureCapability& cap) { 83 if (running_) return -1; 84 cap_ = cap; 85 running_ = true; 86 return 0; 87 } 88 virtual int32_t StopCapture() { 89 running_ = false; 90 return 0; 91 } 92 virtual const char* CurrentDeviceName() const { 93 return NULL; // not implemented 94 } 95 virtual bool CaptureStarted() { 96 return running_; 97 } 98 virtual int32_t CaptureSettings( 99 webrtc::VideoCaptureCapability& settings) { 100 if (!running_) return -1; 101 settings = cap_; 102 return 0; 103 } 104 105 virtual int32_t SetCaptureRotation( 106 webrtc::VideoCaptureRotation rotation) { 107 return -1; // not implemented 108 } 109 virtual VideoCaptureEncodeInterface* GetEncodeInterface( 110 const webrtc::VideoCodec& codec) { 111 return NULL; // not implemented 112 } 113 virtual int32_t AddRef() { 114 return 0; 115 } 116 virtual int32_t Release() { 117 delete this; 118 return 0; 119 } 120 121 bool SendFrame(int w, int h) { 122 if (!running_) return false; 123 webrtc::I420VideoFrame sample; 124 // Setting stride based on width. 125 if (sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2) < 0) { 126 return false; 127 } 128 if (callback_) { 129 callback_->OnIncomingCapturedFrame(id_, sample); 130 } 131 return true; 132 } 133 134 const webrtc::VideoCaptureCapability& cap() const { 135 return cap_; 136 } 137 138 private: 139 // Ref-counted, use Release() instead. 140 ~FakeWebRtcVideoCaptureModule(); 141 142 FakeWebRtcVcmFactory* factory_; 143 int id_; 144 webrtc::VideoCaptureDataCallback* callback_; 145 bool running_; 146 webrtc::VideoCaptureCapability cap_; 147 int delay_; 148 }; 149 150 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_ 151