OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 static const int kMinVideoBitrate = 100; | 33 static const int kMinVideoBitrate = 100; |
34 static const int kStartVideoBitrate = 300; | 34 static const int kStartVideoBitrate = 300; |
35 static const int kMaxVideoBitrate = 1000; | 35 static const int kMaxVideoBitrate = 1000; |
36 | 36 |
37 // WebRtc channel id and capture id share the same number space. | 37 // WebRtc channel id and capture id share the same number space. |
38 // This is how AddRenderer(renderId, ...) is able to tell if it is adding a | 38 // This is how AddRenderer(renderId, ...) is able to tell if it is adding a |
39 // renderer for a channel or it is adding a renderer for a capturer. | 39 // renderer for a channel or it is adding a renderer for a capturer. |
40 static const int kViEChannelIdBase = 0; | 40 static const int kViEChannelIdBase = 0; |
41 static const int kViEChannelIdMax = 1000; | 41 static const int kViEChannelIdMax = 1000; |
42 static const int kEventTimeoutMs = 10000; | |
43 | 42 |
44 // Fake class for mocking out webrtc::VideoDecoder | 43 // Fake class for mocking out webrtc::VideoDecoder |
45 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { | 44 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { |
46 public: | 45 public: |
47 FakeWebRtcVideoDecoder() : num_frames_received_(0) {} | 46 FakeWebRtcVideoDecoder() |
| 47 : num_frames_received_(0) { |
| 48 } |
48 | 49 |
49 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { | 50 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { |
50 return WEBRTC_VIDEO_CODEC_OK; | 51 return WEBRTC_VIDEO_CODEC_OK; |
51 } | 52 } |
52 | 53 |
53 virtual int32_t Decode(const webrtc::EncodedImage&, | 54 virtual int32_t Decode(const webrtc::EncodedImage&, |
54 bool, | 55 bool, |
55 const webrtc::RTPFragmentationHeader*, | 56 const webrtc::RTPFragmentationHeader*, |
56 const webrtc::CodecSpecificInfo*, | 57 const webrtc::CodecSpecificInfo*, |
57 int64_t) { | 58 int64_t) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 114 |
114 private: | 115 private: |
115 std::set<webrtc::VideoCodecType> supported_codec_types_; | 116 std::set<webrtc::VideoCodecType> supported_codec_types_; |
116 std::vector<FakeWebRtcVideoDecoder*> decoders_; | 117 std::vector<FakeWebRtcVideoDecoder*> decoders_; |
117 int num_created_decoders_; | 118 int num_created_decoders_; |
118 }; | 119 }; |
119 | 120 |
120 // Fake class for mocking out webrtc::VideoEnoder | 121 // Fake class for mocking out webrtc::VideoEnoder |
121 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { | 122 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { |
122 public: | 123 public: |
123 FakeWebRtcVideoEncoder() | 124 FakeWebRtcVideoEncoder() : num_frames_encoded_(0) {} |
124 : init_encode_event_(false, false), num_frames_encoded_(0) {} | |
125 | 125 |
126 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, | 126 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, |
127 int32_t numberOfCores, | 127 int32_t numberOfCores, |
128 size_t maxPayloadSize) { | 128 size_t maxPayloadSize) { |
129 rtc::CritScope lock(&crit_); | 129 rtc::CritScope lock(&crit_); |
130 codec_settings_ = *codecSettings; | 130 codec_settings_ = *codecSettings; |
131 init_encode_event_.Set(); | |
132 return WEBRTC_VIDEO_CODEC_OK; | 131 return WEBRTC_VIDEO_CODEC_OK; |
133 } | 132 } |
134 | 133 |
135 bool WaitForInitEncode() { return init_encode_event_.Wait(kEventTimeoutMs); } | |
136 | |
137 webrtc::VideoCodec GetCodecSettings() { | 134 webrtc::VideoCodec GetCodecSettings() { |
138 rtc::CritScope lock(&crit_); | 135 rtc::CritScope lock(&crit_); |
139 return codec_settings_; | 136 return codec_settings_; |
140 } | 137 } |
141 | 138 |
142 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, | 139 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, |
143 const webrtc::CodecSpecificInfo* codecSpecificInfo, | 140 const webrtc::CodecSpecificInfo* codecSpecificInfo, |
144 const std::vector<webrtc::FrameType>* frame_types) { | 141 const std::vector<webrtc::FrameType>* frame_types) { |
145 rtc::CritScope lock(&crit_); | 142 rtc::CritScope lock(&crit_); |
146 ++num_frames_encoded_; | 143 ++num_frames_encoded_; |
147 init_encode_event_.Set(); | |
148 return WEBRTC_VIDEO_CODEC_OK; | 144 return WEBRTC_VIDEO_CODEC_OK; |
149 } | 145 } |
150 | 146 |
151 virtual int32_t RegisterEncodeCompleteCallback( | 147 virtual int32_t RegisterEncodeCompleteCallback( |
152 webrtc::EncodedImageCallback* callback) { | 148 webrtc::EncodedImageCallback* callback) { |
153 return WEBRTC_VIDEO_CODEC_OK; | 149 return WEBRTC_VIDEO_CODEC_OK; |
154 } | 150 } |
155 | 151 |
156 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; } | 152 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; } |
157 | 153 |
158 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) { | 154 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) { |
159 return WEBRTC_VIDEO_CODEC_OK; | 155 return WEBRTC_VIDEO_CODEC_OK; |
160 } | 156 } |
161 | 157 |
162 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) { | 158 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) { |
163 return WEBRTC_VIDEO_CODEC_OK; | 159 return WEBRTC_VIDEO_CODEC_OK; |
164 } | 160 } |
165 | 161 |
166 int GetNumEncodedFrames() { | 162 int GetNumEncodedFrames() { |
167 rtc::CritScope lock(&crit_); | 163 rtc::CritScope lock(&crit_); |
168 return num_frames_encoded_; | 164 return num_frames_encoded_; |
169 } | 165 } |
170 | 166 |
171 private: | 167 private: |
172 rtc::CriticalSection crit_; | 168 rtc::CriticalSection crit_; |
173 rtc::Event init_encode_event_; | |
174 int num_frames_encoded_ GUARDED_BY(crit_); | 169 int num_frames_encoded_ GUARDED_BY(crit_); |
175 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); | 170 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); |
176 }; | 171 }; |
177 | 172 |
178 // Fake class for mocking out WebRtcVideoEncoderFactory. | 173 // Fake class for mocking out WebRtcVideoEncoderFactory. |
179 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { | 174 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { |
180 public: | 175 public: |
181 FakeWebRtcVideoEncoderFactory() | 176 FakeWebRtcVideoEncoderFactory() |
182 : created_video_encoder_event_(false, false), | 177 : num_created_encoders_(0), encoders_have_internal_sources_(false) {} |
183 num_created_encoders_(0), | |
184 encoders_have_internal_sources_(false) {} | |
185 | 178 |
186 virtual webrtc::VideoEncoder* CreateVideoEncoder( | 179 virtual webrtc::VideoEncoder* CreateVideoEncoder( |
187 webrtc::VideoCodecType type) { | 180 webrtc::VideoCodecType type) { |
188 rtc::CritScope lock(&crit_); | |
189 if (supported_codec_types_.count(type) == 0) { | 181 if (supported_codec_types_.count(type) == 0) { |
190 return NULL; | 182 return NULL; |
191 } | 183 } |
192 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); | 184 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); |
193 encoders_.push_back(encoder); | 185 encoders_.push_back(encoder); |
194 num_created_encoders_++; | 186 num_created_encoders_++; |
195 created_video_encoder_event_.Set(); | |
196 return encoder; | 187 return encoder; |
197 } | 188 } |
198 | 189 |
199 bool WaitForCreatedVideoEncoders(int num_encoders) { | |
200 while (created_video_encoder_event_.Wait(kEventTimeoutMs)) { | |
201 if (GetNumCreatedEncoders() >= num_encoders) | |
202 return true; | |
203 } | |
204 return false; | |
205 } | |
206 | |
207 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { | 190 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { |
208 rtc::CritScope lock(&crit_); | |
209 encoders_.erase( | 191 encoders_.erase( |
210 std::remove(encoders_.begin(), encoders_.end(), encoder), | 192 std::remove(encoders_.begin(), encoders_.end(), encoder), |
211 encoders_.end()); | 193 encoders_.end()); |
212 delete encoder; | 194 delete encoder; |
213 } | 195 } |
214 | 196 |
215 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() | 197 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() |
216 const { | 198 const { |
217 return codecs_; | 199 return codecs_; |
218 } | 200 } |
219 | 201 |
220 virtual bool EncoderTypeHasInternalSource( | 202 virtual bool EncoderTypeHasInternalSource( |
221 webrtc::VideoCodecType type) const override { | 203 webrtc::VideoCodecType type) const override { |
222 return encoders_have_internal_sources_; | 204 return encoders_have_internal_sources_; |
223 } | 205 } |
224 | 206 |
225 void set_encoders_have_internal_sources(bool internal_source) { | 207 void set_encoders_have_internal_sources(bool internal_source) { |
226 encoders_have_internal_sources_ = internal_source; | 208 encoders_have_internal_sources_ = internal_source; |
227 } | 209 } |
228 | 210 |
229 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, | 211 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, |
230 const std::string& name) { | 212 const std::string& name) { |
231 supported_codec_types_.insert(type); | 213 supported_codec_types_.insert(type); |
232 codecs_.push_back( | 214 codecs_.push_back( |
233 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); | 215 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); |
234 } | 216 } |
235 | 217 |
236 int GetNumCreatedEncoders() { | 218 int GetNumCreatedEncoders() { |
237 rtc::CritScope lock(&crit_); | |
238 return num_created_encoders_; | 219 return num_created_encoders_; |
239 } | 220 } |
240 | 221 |
241 const std::vector<FakeWebRtcVideoEncoder*> encoders() { | 222 const std::vector<FakeWebRtcVideoEncoder*>& encoders() { |
242 rtc::CritScope lock(&crit_); | |
243 return encoders_; | 223 return encoders_; |
244 } | 224 } |
245 | 225 |
246 private: | 226 private: |
247 rtc::CriticalSection crit_; | |
248 rtc::Event created_video_encoder_event_; | |
249 std::set<webrtc::VideoCodecType> supported_codec_types_; | 227 std::set<webrtc::VideoCodecType> supported_codec_types_; |
250 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; | 228 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; |
251 std::vector<FakeWebRtcVideoEncoder*> encoders_ GUARDED_BY(crit_); | 229 std::vector<FakeWebRtcVideoEncoder*> encoders_; |
252 int num_created_encoders_ GUARDED_BY(crit_); | 230 int num_created_encoders_; |
253 bool encoders_have_internal_sources_; | 231 bool encoders_have_internal_sources_; |
254 }; | 232 }; |
255 | 233 |
256 } // namespace cricket | 234 } // namespace cricket |
257 | 235 |
258 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_ | 236 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_ |
OLD | NEW |