Chromium Code Reviews| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 if (!FindMatchingCodec(codecs_, codec)) | 189 if (!FindMatchingCodec(codecs_, codec)) |
| 190 return nullptr; | 190 return nullptr; |
| 191 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); | 191 FakeWebRtcVideoEncoder* encoder = new FakeWebRtcVideoEncoder(); |
| 192 encoders_.push_back(encoder); | 192 encoders_.push_back(encoder); |
| 193 num_created_encoders_++; | 193 num_created_encoders_++; |
| 194 created_video_encoder_event_.Set(); | 194 created_video_encoder_event_.Set(); |
| 195 return encoder; | 195 return encoder; |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool WaitForCreatedVideoEncoders(int num_encoders) { | 198 bool WaitForCreatedVideoEncoders(int num_encoders) { |
| 199 while (created_video_encoder_event_.Wait(kEventTimeoutMs)) { | 199 int64_t start_offset_ms = rtc::TimeMillis(); |
| 200 int64_t wait_time = kEventTimeoutMs; | |
| 201 do { | |
| 200 if (GetNumCreatedEncoders() >= num_encoders) | 202 if (GetNumCreatedEncoders() >= num_encoders) |
| 201 return true; | 203 return true; |
| 202 } | 204 wait_time = kEventTimeoutMs - (rtc::TimeMillis() - start_offset_ms); |
| 205 } while (wait_time > 0 && created_video_encoder_event_.Wait(wait_time)); | |
|
Taylor Brandstetter
2017/02/23 00:46:49
Why are start_offset_ms/wait_time needed?
sprang_webrtc
2017/02/23 15:10:14
It was racy, so if |num_encoders| reached X before
Taylor Brandstetter
2017/02/24 00:13:55
Ah, I see. I think just changing it to a "do while
| |
| 203 return false; | 206 return false; |
| 204 } | 207 } |
| 205 | 208 |
| 206 void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override { | 209 void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override { |
| 207 rtc::CritScope lock(&crit_); | 210 rtc::CritScope lock(&crit_); |
| 208 encoders_.erase( | 211 encoders_.erase( |
| 209 std::remove(encoders_.begin(), encoders_.end(), encoder), | 212 std::remove(encoders_.begin(), encoders_.end(), encoder), |
| 210 encoders_.end()); | 213 encoders_.end()); |
| 211 delete encoder; | 214 delete encoder; |
| 212 } | 215 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 rtc::Event created_video_encoder_event_; | 254 rtc::Event created_video_encoder_event_; |
| 252 std::vector<cricket::VideoCodec> codecs_; | 255 std::vector<cricket::VideoCodec> codecs_; |
| 253 std::vector<FakeWebRtcVideoEncoder*> encoders_ GUARDED_BY(crit_); | 256 std::vector<FakeWebRtcVideoEncoder*> encoders_ GUARDED_BY(crit_); |
| 254 int num_created_encoders_ GUARDED_BY(crit_); | 257 int num_created_encoders_ GUARDED_BY(crit_); |
| 255 bool encoders_have_internal_sources_; | 258 bool encoders_have_internal_sources_; |
| 256 }; | 259 }; |
| 257 | 260 |
| 258 } // namespace cricket | 261 } // namespace cricket |
| 259 | 262 |
| 260 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_ | 263 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVIDEOENGINE_H_ |
| OLD | NEW |