Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / webrtc / fakewebrtcvideocapturemodule.h
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 #if defined(USE_WEBRTC_DEV_BRANCH)
63   virtual void RegisterCaptureDataCallback(
64       webrtc::VideoCaptureDataCallback& callback) {
65     callback_ = &callback;
66   }
67   virtual void DeRegisterCaptureDataCallback() { callback_ = NULL; }
68   virtual void RegisterCaptureCallback(webrtc::VideoCaptureFeedBack& callback) {
69     // Not implemented.
70   }
71   virtual void DeRegisterCaptureCallback() {
72     // Not implemented.
73   }
74   virtual void SetCaptureDelay(int32_t delay) { delay_ = delay; }
75   virtual int32_t CaptureDelay() { return delay_; }
76   virtual void EnableFrameRateCallback(const bool enable) {
77     // not implemented
78   }
79   virtual void EnableNoPictureAlarm(const bool enable) {
80     // not implemented
81   }
82 #else
83   virtual int32_t RegisterCaptureDataCallback(
84       webrtc::VideoCaptureDataCallback& callback) {
85     callback_ = &callback;
86     return 0;
87   }
88   virtual int32_t DeRegisterCaptureDataCallback() {
89     callback_ = NULL;
90     return 0;
91   }
92   virtual int32_t RegisterCaptureCallback(
93       webrtc::VideoCaptureFeedBack& callback) {
94     return -1;  // not implemented
95   }
96   virtual int32_t DeRegisterCaptureCallback() {
97     return 0;
98   }
99   virtual int32_t SetCaptureDelay(int32_t delay) {
100     delay_ = delay;
101     return 0;
102   }
103   virtual int32_t CaptureDelay() {
104     return delay_;
105   }
106   virtual int32_t EnableFrameRateCallback(const bool enable) {
107     return -1;  // not implemented
108   }
109   virtual int32_t EnableNoPictureAlarm(const bool enable) {
110     return -1;  // not implemented
111   }
112 #endif
113   virtual int32_t StartCapture(
114       const webrtc::VideoCaptureCapability& cap) {
115     if (running_) return -1;
116     cap_ = cap;
117     running_ = true;
118     return 0;
119   }
120   virtual int32_t StopCapture() {
121     running_ = false;
122     return 0;
123   }
124   virtual const char* CurrentDeviceName() const {
125     return NULL;  // not implemented
126   }
127   virtual bool CaptureStarted() {
128     return running_;
129   }
130   virtual int32_t CaptureSettings(
131       webrtc::VideoCaptureCapability& settings) {
132     if (!running_) return -1;
133     settings = cap_;
134     return 0;
135   }
136
137   virtual int32_t SetCaptureRotation(
138       webrtc::VideoCaptureRotation rotation) {
139     return -1;  // not implemented
140   }
141   virtual VideoCaptureEncodeInterface* GetEncodeInterface(
142       const webrtc::VideoCodec& codec) {
143     return NULL;  // not implemented
144   }
145   virtual int32_t AddRef() {
146     return 0;
147   }
148   virtual int32_t Release() {
149     delete this;
150     return 0;
151   }
152
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) {
158       return false;
159     }
160     if (callback_) {
161       callback_->OnIncomingCapturedFrame(id_, sample);
162     }
163     return true;
164   }
165
166   const webrtc::VideoCaptureCapability& cap() const {
167     return cap_;
168   }
169
170  private:
171   // Ref-counted, use Release() instead.
172   ~FakeWebRtcVideoCaptureModule();
173
174   FakeWebRtcVcmFactory* factory_;
175   int id_;
176   webrtc::VideoCaptureDataCallback* callback_;
177   bool running_;
178   webrtc::VideoCaptureCapability cap_;
179   int delay_;
180 };
181
182 #endif  // TALK_SESSION_PHONE_FAKEWEBRTCVIDEOCAPTUREMODULE_H_