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