• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libjingle
3  * Copyright 2004 Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
29 #define TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
30 
31 #include <vector>
32 
33 #include "talk/media/base/testutils.h"
34 #include "talk/media/webrtc/fakewebrtcdeviceinfo.h"
35 #include "talk/media/webrtc/webrtcvideocapturer.h"
36 
37 class FakeWebRtcVcmFactory;
38 
39 // Fake class for mocking out webrtc::VideoCaptureModule.
40 class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule {
41  public:
FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory * factory,int32_t id)42   FakeWebRtcVideoCaptureModule(FakeWebRtcVcmFactory* factory, int32_t id)
43       : factory_(factory),
44         id_(id),
45         callback_(NULL),
46         running_(false),
47         delay_(0) {
48   }
TimeUntilNextProcess()49   int64_t TimeUntilNextProcess() override { return 0; }
Process()50   int32_t Process() override { return 0; }
RegisterCaptureDataCallback(webrtc::VideoCaptureDataCallback & callback)51   void RegisterCaptureDataCallback(
52       webrtc::VideoCaptureDataCallback& callback) override {
53     callback_ = &callback;
54   }
DeRegisterCaptureDataCallback()55   void DeRegisterCaptureDataCallback() override { callback_ = NULL; }
RegisterCaptureCallback(webrtc::VideoCaptureFeedBack & callback)56   void RegisterCaptureCallback(
57       webrtc::VideoCaptureFeedBack& callback) override {
58     // Not implemented.
59   }
DeRegisterCaptureCallback()60   void DeRegisterCaptureCallback() override {
61     // Not implemented.
62   }
SetCaptureDelay(int32_t delay)63   void SetCaptureDelay(int32_t delay) override { delay_ = delay; }
CaptureDelay()64   int32_t CaptureDelay() override { return delay_; }
EnableFrameRateCallback(const bool enable)65   void EnableFrameRateCallback(const bool enable) override {
66     // not implemented
67   }
EnableNoPictureAlarm(const bool enable)68   void EnableNoPictureAlarm(const bool enable) override {
69     // not implemented
70   }
StartCapture(const webrtc::VideoCaptureCapability & cap)71   int32_t StartCapture(const webrtc::VideoCaptureCapability& cap) override {
72     if (running_) return -1;
73     cap_ = cap;
74     running_ = true;
75     return 0;
76   }
StopCapture()77   int32_t StopCapture() override {
78     running_ = false;
79     return 0;
80   }
CurrentDeviceName()81   const char* CurrentDeviceName() const override {
82     return NULL;  // not implemented
83   }
CaptureStarted()84   bool CaptureStarted() override { return running_; }
CaptureSettings(webrtc::VideoCaptureCapability & settings)85   int32_t CaptureSettings(webrtc::VideoCaptureCapability& settings) override {
86     if (!running_) return -1;
87     settings = cap_;
88     return 0;
89   }
90 
SetCaptureRotation(webrtc::VideoRotation rotation)91   int32_t SetCaptureRotation(webrtc::VideoRotation rotation) override {
92     return -1;  // not implemented
93   }
SetApplyRotation(bool enable)94   bool SetApplyRotation(bool enable) override {
95     return false;  // not implemented
96   }
GetApplyRotation()97   bool GetApplyRotation() override {
98     return true;  // Rotation compensation is turned on.
99   }
GetEncodeInterface(const webrtc::VideoCodec & codec)100   VideoCaptureEncodeInterface* GetEncodeInterface(
101       const webrtc::VideoCodec& codec) override {
102     return NULL;  // not implemented
103   }
AddRef()104   int32_t AddRef() const override { return 0; }
Release()105   int32_t Release() const override {
106     delete this;
107     return 0;
108   }
109 
SendFrame(int w,int h)110   bool SendFrame(int w, int h) {
111     if (!running_) return false;
112     webrtc::VideoFrame sample;
113     // Setting stride based on width.
114     if (sample.CreateEmptyFrame(w, h, w, (w + 1) / 2, (w + 1) / 2) < 0) {
115       return false;
116     }
117     if (callback_) {
118       callback_->OnIncomingCapturedFrame(id_, sample);
119     }
120     return true;
121   }
122 
cap()123   const webrtc::VideoCaptureCapability& cap() const {
124     return cap_;
125   }
126 
127  private:
128   // Ref-counted, use Release() instead.
129   ~FakeWebRtcVideoCaptureModule();
130 
131   FakeWebRtcVcmFactory* factory_;
132   int id_;
133   webrtc::VideoCaptureDataCallback* callback_;
134   bool running_;
135   webrtc::VideoCaptureCapability cap_;
136   int delay_;
137 };
138 
139 #endif  // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_
140