Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: talk/media/webrtc/fakewebrtcvideoengine.h

Issue 1587193006: Move talk/media to webrtc/media (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased to b647aca12a884a13c1728118586245399b55fa3d (#11493) Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2010 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_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_
29 #define TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_
30
31 #include <map>
32 #include <set>
33 #include <vector>
34
35 #include "talk/media/base/codec.h"
36 #include "talk/media/webrtc/fakewebrtccommon.h"
37 #include "talk/media/webrtc/webrtcvideodecoderfactory.h"
38 #include "talk/media/webrtc/webrtcvideoencoderfactory.h"
39 #include "webrtc/base/basictypes.h"
40 #include "webrtc/base/criticalsection.h"
41 #include "webrtc/base/gunit.h"
42 #include "webrtc/base/stringutils.h"
43 #include "webrtc/base/thread_annotations.h"
44 #include "webrtc/modules/video_coding/include/video_error_codes.h"
45 #include "webrtc/video_decoder.h"
46 #include "webrtc/video_encoder.h"
47
48 namespace cricket {
49
50 static const int kMinVideoBitrate = 100;
51 static const int kStartVideoBitrate = 300;
52 static const int kMaxVideoBitrate = 1000;
53
54 // WebRtc channel id and capture id share the same number space.
55 // This is how AddRenderer(renderId, ...) is able to tell if it is adding a
56 // renderer for a channel or it is adding a renderer for a capturer.
57 static const int kViEChannelIdBase = 0;
58 static const int kViEChannelIdMax = 1000;
59
60 // Fake class for mocking out webrtc::VideoDecoder
61 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder {
62 public:
63 FakeWebRtcVideoDecoder()
64 : num_frames_received_(0) {
65 }
66
67 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) {
68 return WEBRTC_VIDEO_CODEC_OK;
69 }
70
71 virtual int32_t Decode(const webrtc::EncodedImage&,
72 bool,
73 const webrtc::RTPFragmentationHeader*,
74 const webrtc::CodecSpecificInfo*,
75 int64_t) {
76 num_frames_received_++;
77 return WEBRTC_VIDEO_CODEC_OK;
78 }
79
80 virtual int32_t RegisterDecodeCompleteCallback(
81 webrtc::DecodedImageCallback*) {
82 return WEBRTC_VIDEO_CODEC_OK;
83 }
84
85 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; }
86
87 int GetNumFramesReceived() const {
88 return num_frames_received_;
89 }
90
91 private:
92 int num_frames_received_;
93 };
94
95 // Fake class for mocking out WebRtcVideoDecoderFactory.
96 class FakeWebRtcVideoDecoderFactory : public WebRtcVideoDecoderFactory {
97 public:
98 FakeWebRtcVideoDecoderFactory()
99 : num_created_decoders_(0) {
100 }
101
102 virtual webrtc::VideoDecoder* CreateVideoDecoder(
103 webrtc::VideoCodecType type) {
104 if (supported_codec_types_.count(type) == 0) {
105 return NULL;
106 }
107 FakeWebRtcVideoDecoder* decoder = new FakeWebRtcVideoDecoder();
108 decoders_.push_back(decoder);
109 num_created_decoders_++;
110 return decoder;
111 }
112
113 virtual void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) {
114 decoders_.erase(
115 std::remove(decoders_.begin(), decoders_.end(), decoder),
116 decoders_.end());
117 delete decoder;
118 }
119
120 void AddSupportedVideoCodecType(webrtc::VideoCodecType type) {
121 supported_codec_types_.insert(type);
122 }
123
124 int GetNumCreatedDecoders() {
125 return num_created_decoders_;
126 }
127
128 const std::vector<FakeWebRtcVideoDecoder*>& decoders() {
129 return decoders_;
130 }
131
132 private:
133 std::set<webrtc::VideoCodecType> supported_codec_types_;
134 std::vector<FakeWebRtcVideoDecoder*> decoders_;
135 int num_created_decoders_;
136 };
137
138 // Fake class for mocking out webrtc::VideoEnoder
139 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
140 public:
141 FakeWebRtcVideoEncoder() : num_frames_encoded_(0) {}
142
143 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings,
144 int32_t numberOfCores,
145 size_t maxPayloadSize) {
146 rtc::CritScope lock(&crit_);
147 codec_settings_ = *codecSettings;
148 return WEBRTC_VIDEO_CODEC_OK;
149 }
150
151 webrtc::VideoCodec GetCodecSettings() {
152 rtc::CritScope lock(&crit_);
153 return codec_settings_;
154 }
155
156 virtual int32_t Encode(const webrtc::VideoFrame& inputImage,
157 const webrtc::CodecSpecificInfo* codecSpecificInfo,
158 const std::vector<webrtc::FrameType>* frame_types) {
159 rtc::CritScope lock(&crit_);
160 ++num_frames_encoded_;
161 return WEBRTC_VIDEO_CODEC_OK;
162 }
163
164 virtual int32_t RegisterEncodeCompleteCallback(
165 webrtc::EncodedImageCallback* callback) {
166 return WEBRTC_VIDEO_CODEC_OK;
167 }
168
169 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; }
170
171 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) {
172 return WEBRTC_VIDEO_CODEC_OK;
173 }
174
175 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) {
176 return WEBRTC_VIDEO_CODEC_OK;
177 }
178
179 int GetNumEncodedFrames() {
180 rtc::CritScope lock(&crit_);
181 return num_frames_encoded_;
182 }
183
184 private:
185 rtc::CriticalSection crit_;
186 int num_frames_encoded_ GUARDED_BY(crit_);
187 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_);
188 };
189
190 // Fake class for mocking out WebRtcVideoEncoderFactory.
191 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory {
192 public:
193 FakeWebRtcVideoEncoderFactory()
194 : num_created_encoders_(0), encoders_have_internal_sources_(false) {}
195
196 virtual webrtc::VideoEncoder* CreateVideoEncoder(
197 webrtc::VideoCodecType type) {
198 if (supported_codec_types_.count(type) == 0) {
199 return NULL;
200 }
201 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder();
202 encoders_.push_back(encoder);
203 num_created_encoders_++;
204 return encoder;
205 }
206
207 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) {
208 encoders_.erase(
209 std::remove(encoders_.begin(), encoders_.end(), encoder),
210 encoders_.end());
211 delete encoder;
212 }
213
214 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs()
215 const {
216 return codecs_;
217 }
218
219 virtual bool EncoderTypeHasInternalSource(
220 webrtc::VideoCodecType type) const override {
221 return encoders_have_internal_sources_;
222 }
223
224 void set_encoders_have_internal_sources(bool internal_source) {
225 encoders_have_internal_sources_ = internal_source;
226 }
227
228 void AddSupportedVideoCodecType(webrtc::VideoCodecType type,
229 const std::string& name) {
230 supported_codec_types_.insert(type);
231 codecs_.push_back(
232 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30));
233 }
234
235 int GetNumCreatedEncoders() {
236 return num_created_encoders_;
237 }
238
239 const std::vector<FakeWebRtcVideoEncoder*>& encoders() {
240 return encoders_;
241 }
242
243 private:
244 std::set<webrtc::VideoCodecType> supported_codec_types_;
245 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_;
246 std::vector<FakeWebRtcVideoEncoder*> encoders_;
247 int num_created_encoders_;
248 bool encoders_have_internal_sources_;
249 };
250
251 } // namespace cricket
252
253 #endif // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_
OLDNEW
« no previous file with comments | « talk/media/webrtc/fakewebrtcvideocapturemodule.h ('k') | talk/media/webrtc/fakewebrtcvoiceengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698