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

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

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