OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 static const int kMinVideoBitrate = 100; | 50 static const int kMinVideoBitrate = 100; |
51 static const int kStartVideoBitrate = 300; | 51 static const int kStartVideoBitrate = 300; |
52 static const int kMaxVideoBitrate = 1000; | 52 static const int kMaxVideoBitrate = 1000; |
53 | 53 |
54 // WebRtc channel id and capture id share the same number space. | 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 | 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. | 56 // renderer for a channel or it is adding a renderer for a capturer. |
57 static const int kViEChannelIdBase = 0; | 57 static const int kViEChannelIdBase = 0; |
58 static const int kViEChannelIdMax = 1000; | 58 static const int kViEChannelIdMax = 1000; |
| 59 static const int kEventTimeoutMs = 10000; |
59 | 60 |
60 // Fake class for mocking out webrtc::VideoDecoder | 61 // Fake class for mocking out webrtc::VideoDecoder |
61 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { | 62 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { |
62 public: | 63 public: |
63 FakeWebRtcVideoDecoder() | 64 FakeWebRtcVideoDecoder() |
64 : num_frames_received_(0) { | 65 : num_frames_received_(0) { |
65 } | 66 } |
66 | 67 |
67 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { | 68 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { |
68 return WEBRTC_VIDEO_CODEC_OK; | 69 return WEBRTC_VIDEO_CODEC_OK; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 private: | 135 private: |
135 std::set<webrtc::VideoCodecType> supported_codec_types_; | 136 std::set<webrtc::VideoCodecType> supported_codec_types_; |
136 std::vector<FakeWebRtcVideoDecoder*> decoders_; | 137 std::vector<FakeWebRtcVideoDecoder*> decoders_; |
137 int num_created_decoders_; | 138 int num_created_decoders_; |
138 }; | 139 }; |
139 | 140 |
140 // Fake class for mocking out webrtc::VideoEnoder | 141 // Fake class for mocking out webrtc::VideoEnoder |
141 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { | 142 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { |
142 public: | 143 public: |
143 FakeWebRtcVideoEncoder() : num_frames_encoded_(0) {} | 144 FakeWebRtcVideoEncoder() |
| 145 : init_encode_event_(false, false), num_frames_encoded_(0) {} |
144 | 146 |
145 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, | 147 virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, |
146 int32_t numberOfCores, | 148 int32_t numberOfCores, |
147 size_t maxPayloadSize) { | 149 size_t maxPayloadSize) { |
148 rtc::CritScope lock(&crit_); | 150 rtc::CritScope lock(&crit_); |
149 codec_settings_ = *codecSettings; | 151 codec_settings_ = *codecSettings; |
| 152 init_encode_event_.Set(); |
150 return WEBRTC_VIDEO_CODEC_OK; | 153 return WEBRTC_VIDEO_CODEC_OK; |
151 } | 154 } |
152 | 155 |
| 156 bool WaitForInitEncode() { return init_encode_event_.Wait(kEventTimeoutMs); } |
| 157 |
153 webrtc::VideoCodec GetCodecSettings() { | 158 webrtc::VideoCodec GetCodecSettings() { |
154 rtc::CritScope lock(&crit_); | 159 rtc::CritScope lock(&crit_); |
155 return codec_settings_; | 160 return codec_settings_; |
156 } | 161 } |
157 | 162 |
158 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, | 163 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, |
159 const webrtc::CodecSpecificInfo* codecSpecificInfo, | 164 const webrtc::CodecSpecificInfo* codecSpecificInfo, |
160 const std::vector<webrtc::FrameType>* frame_types) { | 165 const std::vector<webrtc::FrameType>* frame_types) { |
161 rtc::CritScope lock(&crit_); | 166 rtc::CritScope lock(&crit_); |
162 ++num_frames_encoded_; | 167 ++num_frames_encoded_; |
(...skipping 15 matching lines...) Expand all Loading... |
178 return WEBRTC_VIDEO_CODEC_OK; | 183 return WEBRTC_VIDEO_CODEC_OK; |
179 } | 184 } |
180 | 185 |
181 int GetNumEncodedFrames() { | 186 int GetNumEncodedFrames() { |
182 rtc::CritScope lock(&crit_); | 187 rtc::CritScope lock(&crit_); |
183 return num_frames_encoded_; | 188 return num_frames_encoded_; |
184 } | 189 } |
185 | 190 |
186 private: | 191 private: |
187 rtc::CriticalSection crit_; | 192 rtc::CriticalSection crit_; |
| 193 rtc::Event init_encode_event_; |
188 int num_frames_encoded_ GUARDED_BY(crit_); | 194 int num_frames_encoded_ GUARDED_BY(crit_); |
189 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); | 195 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); |
190 }; | 196 }; |
191 | 197 |
192 // Fake class for mocking out WebRtcVideoEncoderFactory. | 198 // Fake class for mocking out WebRtcVideoEncoderFactory. |
193 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { | 199 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { |
194 public: | 200 public: |
195 FakeWebRtcVideoEncoderFactory() | 201 FakeWebRtcVideoEncoderFactory() |
196 : num_created_encoders_(0), encoders_have_internal_sources_(false) {} | 202 : created_video_encoder_event_(false, false), |
| 203 num_created_encoders_(0), |
| 204 encoders_have_internal_sources_(false) {} |
197 | 205 |
198 virtual webrtc::VideoEncoder* CreateVideoEncoder( | 206 virtual webrtc::VideoEncoder* CreateVideoEncoder( |
199 webrtc::VideoCodecType type) { | 207 webrtc::VideoCodecType type) { |
| 208 rtc::CritScope lock(&crit_); |
200 if (supported_codec_types_.count(type) == 0) { | 209 if (supported_codec_types_.count(type) == 0) { |
201 return NULL; | 210 return NULL; |
202 } | 211 } |
203 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); | 212 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); |
204 encoders_.push_back(encoder); | 213 encoders_.push_back(encoder); |
205 num_created_encoders_++; | 214 num_created_encoders_++; |
| 215 created_video_encoder_event_.Set(); |
206 return encoder; | 216 return encoder; |
207 } | 217 } |
208 | 218 |
| 219 bool WaitForCreatedVideoEncoder() { |
| 220 return created_video_encoder_event_.Wait(kEventTimeoutMs); |
| 221 } |
| 222 |
209 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { | 223 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { |
| 224 rtc::CritScope lock(&crit_); |
210 encoders_.erase( | 225 encoders_.erase( |
211 std::remove(encoders_.begin(), encoders_.end(), encoder), | 226 std::remove(encoders_.begin(), encoders_.end(), encoder), |
212 encoders_.end()); | 227 encoders_.end()); |
213 delete encoder; | 228 delete encoder; |
214 } | 229 } |
215 | 230 |
216 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() | 231 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() |
217 const { | 232 const { |
218 return codecs_; | 233 return codecs_; |
219 } | 234 } |
220 | 235 |
221 virtual bool EncoderTypeHasInternalSource( | 236 virtual bool EncoderTypeHasInternalSource( |
222 webrtc::VideoCodecType type) const override { | 237 webrtc::VideoCodecType type) const override { |
223 return encoders_have_internal_sources_; | 238 return encoders_have_internal_sources_; |
224 } | 239 } |
225 | 240 |
226 void set_encoders_have_internal_sources(bool internal_source) { | 241 void set_encoders_have_internal_sources(bool internal_source) { |
227 encoders_have_internal_sources_ = internal_source; | 242 encoders_have_internal_sources_ = internal_source; |
228 } | 243 } |
229 | 244 |
230 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, | 245 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, |
231 const std::string& name) { | 246 const std::string& name) { |
232 supported_codec_types_.insert(type); | 247 supported_codec_types_.insert(type); |
233 codecs_.push_back( | 248 codecs_.push_back( |
234 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); | 249 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); |
235 } | 250 } |
236 | 251 |
237 int GetNumCreatedEncoders() { | 252 int GetNumCreatedEncoders() { |
| 253 rtc::CritScope lock(&crit_); |
238 return num_created_encoders_; | 254 return num_created_encoders_; |
239 } | 255 } |
240 | 256 |
241 const std::vector<FakeWebRtcVideoEncoder*>& encoders() { | 257 const std::vector<FakeWebRtcVideoEncoder*> encoders() { |
| 258 rtc::CritScope lock(&crit_); |
242 return encoders_; | 259 return encoders_; |
243 } | 260 } |
244 | 261 |
245 private: | 262 private: |
| 263 rtc::CriticalSection crit_; |
| 264 rtc::Event created_video_encoder_event_; |
246 std::set<webrtc::VideoCodecType> supported_codec_types_; | 265 std::set<webrtc::VideoCodecType> supported_codec_types_; |
247 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; | 266 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; |
248 std::vector<FakeWebRtcVideoEncoder*> encoders_; | 267 std::vector<FakeWebRtcVideoEncoder*> encoders_ GUARDED_BY(crit_); |
249 int num_created_encoders_; | 268 int num_created_encoders_ GUARDED_BY(crit_); |
250 bool encoders_have_internal_sources_; | 269 bool encoders_have_internal_sources_; |
251 }; | 270 }; |
252 | 271 |
253 } // namespace cricket | 272 } // namespace cricket |
254 | 273 |
255 #endif // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_ | 274 #endif // TALK_MEDIA_WEBRTC_FAKEWEBRTCVIDEOENGINE_H_ |
OLD | NEW |