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

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

Issue 1757313002: Initialize/configure video encoders asychronously. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: merge switch blocks Created 4 years, 9 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
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
42 43
43 // Fake class for mocking out webrtc::VideoDecoder 44 // Fake class for mocking out webrtc::VideoDecoder
44 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder { 45 class FakeWebRtcVideoDecoder : public webrtc::VideoDecoder {
45 public: 46 public:
46 FakeWebRtcVideoDecoder() 47 FakeWebRtcVideoDecoder() : num_frames_received_(0) {}
47 : num_frames_received_(0) {
48 }
49 48
50 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) { 49 virtual int32_t InitDecode(const webrtc::VideoCodec*, int32_t) {
51 return WEBRTC_VIDEO_CODEC_OK; 50 return WEBRTC_VIDEO_CODEC_OK;
52 } 51 }
53 52
54 virtual int32_t Decode(const webrtc::EncodedImage&, 53 virtual int32_t Decode(const webrtc::EncodedImage&,
55 bool, 54 bool,
56 const webrtc::RTPFragmentationHeader*, 55 const webrtc::RTPFragmentationHeader*,
57 const webrtc::CodecSpecificInfo*, 56 const webrtc::CodecSpecificInfo*,
58 int64_t) { 57 int64_t) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 113
115 private: 114 private:
116 std::set<webrtc::VideoCodecType> supported_codec_types_; 115 std::set<webrtc::VideoCodecType> supported_codec_types_;
117 std::vector<FakeWebRtcVideoDecoder*> decoders_; 116 std::vector<FakeWebRtcVideoDecoder*> decoders_;
118 int num_created_decoders_; 117 int num_created_decoders_;
119 }; 118 };
120 119
121 // Fake class for mocking out webrtc::VideoEnoder 120 // Fake class for mocking out webrtc::VideoEnoder
122 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder { 121 class FakeWebRtcVideoEncoder : public webrtc::VideoEncoder {
123 public: 122 public:
124 FakeWebRtcVideoEncoder() : num_frames_encoded_(0) {} 123 FakeWebRtcVideoEncoder()
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();
131 return WEBRTC_VIDEO_CODEC_OK; 132 return WEBRTC_VIDEO_CODEC_OK;
132 } 133 }
133 134
135 bool WaitForInitEncode() { return init_encode_event_.Wait(kEventTimeoutMs); }
136
134 webrtc::VideoCodec GetCodecSettings() { 137 webrtc::VideoCodec GetCodecSettings() {
135 rtc::CritScope lock(&crit_); 138 rtc::CritScope lock(&crit_);
136 return codec_settings_; 139 return codec_settings_;
137 } 140 }
138 141
139 virtual int32_t Encode(const webrtc::VideoFrame& inputImage, 142 virtual int32_t Encode(const webrtc::VideoFrame& inputImage,
140 const webrtc::CodecSpecificInfo* codecSpecificInfo, 143 const webrtc::CodecSpecificInfo* codecSpecificInfo,
141 const std::vector<webrtc::FrameType>* frame_types) { 144 const std::vector<webrtc::FrameType>* frame_types) {
142 rtc::CritScope lock(&crit_); 145 rtc::CritScope lock(&crit_);
143 ++num_frames_encoded_; 146 ++num_frames_encoded_;
147 init_encode_event_.Set();
144 return WEBRTC_VIDEO_CODEC_OK; 148 return WEBRTC_VIDEO_CODEC_OK;
145 } 149 }
146 150
147 virtual int32_t RegisterEncodeCompleteCallback( 151 virtual int32_t RegisterEncodeCompleteCallback(
148 webrtc::EncodedImageCallback* callback) { 152 webrtc::EncodedImageCallback* callback) {
149 return WEBRTC_VIDEO_CODEC_OK; 153 return WEBRTC_VIDEO_CODEC_OK;
150 } 154 }
151 155
152 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; } 156 virtual int32_t Release() { return WEBRTC_VIDEO_CODEC_OK; }
153 157
154 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) { 158 virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) {
155 return WEBRTC_VIDEO_CODEC_OK; 159 return WEBRTC_VIDEO_CODEC_OK;
156 } 160 }
157 161
158 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) { 162 virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) {
159 return WEBRTC_VIDEO_CODEC_OK; 163 return WEBRTC_VIDEO_CODEC_OK;
160 } 164 }
161 165
162 int GetNumEncodedFrames() { 166 int GetNumEncodedFrames() {
163 rtc::CritScope lock(&crit_); 167 rtc::CritScope lock(&crit_);
164 return num_frames_encoded_; 168 return num_frames_encoded_;
165 } 169 }
166 170
167 private: 171 private:
168 rtc::CriticalSection crit_; 172 rtc::CriticalSection crit_;
173 rtc::Event init_encode_event_;
169 int num_frames_encoded_ GUARDED_BY(crit_); 174 int num_frames_encoded_ GUARDED_BY(crit_);
170 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_); 175 webrtc::VideoCodec codec_settings_ GUARDED_BY(crit_);
171 }; 176 };
172 177
173 // Fake class for mocking out WebRtcVideoEncoderFactory. 178 // Fake class for mocking out WebRtcVideoEncoderFactory.
174 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory { 179 class FakeWebRtcVideoEncoderFactory : public WebRtcVideoEncoderFactory {
175 public: 180 public:
176 FakeWebRtcVideoEncoderFactory() 181 FakeWebRtcVideoEncoderFactory()
177 : num_created_encoders_(0), encoders_have_internal_sources_(false) {} 182 : created_video_encoder_event_(false, false),
183 num_created_encoders_(0),
184 encoders_have_internal_sources_(false) {}
178 185
179 virtual webrtc::VideoEncoder* CreateVideoEncoder( 186 virtual webrtc::VideoEncoder* CreateVideoEncoder(
180 webrtc::VideoCodecType type) { 187 webrtc::VideoCodecType type) {
188 rtc::CritScope lock(&crit_);
181 if (supported_codec_types_.count(type) == 0) { 189 if (supported_codec_types_.count(type) == 0) {
182 return NULL; 190 return NULL;
183 } 191 }
184 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); 192 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder();
185 encoders_.push_back(encoder); 193 encoders_.push_back(encoder);
186 num_created_encoders_++; 194 num_created_encoders_++;
195 created_video_encoder_event_.Set();
187 return encoder; 196 return encoder;
188 } 197 }
189 198
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
190 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) { 207 virtual void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) {
208 rtc::CritScope lock(&crit_);
191 encoders_.erase( 209 encoders_.erase(
192 std::remove(encoders_.begin(), encoders_.end(), encoder), 210 std::remove(encoders_.begin(), encoders_.end(), encoder),
193 encoders_.end()); 211 encoders_.end());
194 delete encoder; 212 delete encoder;
195 } 213 }
196 214
197 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs() 215 virtual const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs()
198 const { 216 const {
199 return codecs_; 217 return codecs_;
200 } 218 }
201 219
202 virtual bool EncoderTypeHasInternalSource( 220 virtual bool EncoderTypeHasInternalSource(
203 webrtc::VideoCodecType type) const override { 221 webrtc::VideoCodecType type) const override {
204 return encoders_have_internal_sources_; 222 return encoders_have_internal_sources_;
205 } 223 }
206 224
207 void set_encoders_have_internal_sources(bool internal_source) { 225 void set_encoders_have_internal_sources(bool internal_source) {
208 encoders_have_internal_sources_ = internal_source; 226 encoders_have_internal_sources_ = internal_source;
209 } 227 }
210 228
211 void AddSupportedVideoCodecType(webrtc::VideoCodecType type, 229 void AddSupportedVideoCodecType(webrtc::VideoCodecType type,
212 const std::string& name) { 230 const std::string& name) {
213 supported_codec_types_.insert(type); 231 supported_codec_types_.insert(type);
214 codecs_.push_back( 232 codecs_.push_back(
215 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30)); 233 WebRtcVideoEncoderFactory::VideoCodec(type, name, 1280, 720, 30));
216 } 234 }
217 235
218 int GetNumCreatedEncoders() { 236 int GetNumCreatedEncoders() {
237 rtc::CritScope lock(&crit_);
219 return num_created_encoders_; 238 return num_created_encoders_;
220 } 239 }
221 240
222 const std::vector<FakeWebRtcVideoEncoder*>& encoders() { 241 const std::vector<FakeWebRtcVideoEncoder*> encoders() {
242 rtc::CritScope lock(&crit_);
223 return encoders_; 243 return encoders_;
224 } 244 }
225 245
226 private: 246 private:
247 rtc::CriticalSection crit_;
248 rtc::Event created_video_encoder_event_;
227 std::set<webrtc::VideoCodecType> supported_codec_types_; 249 std::set<webrtc::VideoCodecType> supported_codec_types_;
228 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_; 250 std::vector<WebRtcVideoEncoderFactory::VideoCodec> codecs_;
229 std::vector<FakeWebRtcVideoEncoder*> encoders_; 251 std::vector<FakeWebRtcVideoEncoder*> encoders_ GUARDED_BY(crit_);
230 int num_created_encoders_; 252 int num_created_encoders_ GUARDED_BY(crit_);
231 bool encoders_have_internal_sources_; 253 bool encoders_have_internal_sources_;
232 }; 254 };
233 255
234 } // namespace cricket 256 } // namespace cricket
235 257
236 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_ 258 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698