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

Side by Side Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2604403003: Make FakeEncoder and FakeH264Encoder thread safe. (Closed)
Patch Set: Rebase. Created 3 years, 11 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 | « webrtc/video/video_send_stream_tests.cc ('k') | no next file » | 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return frame; 179 return frame;
180 } 180 }
181 181
182 class TestEncoder : public test::FakeEncoder { 182 class TestEncoder : public test::FakeEncoder {
183 public: 183 public:
184 TestEncoder() 184 TestEncoder()
185 : FakeEncoder(Clock::GetRealTimeClock()), 185 : FakeEncoder(Clock::GetRealTimeClock()),
186 continue_encode_event_(false, false) {} 186 continue_encode_event_(false, false) {}
187 187
188 VideoCodec codec_config() { 188 VideoCodec codec_config() {
189 rtc::CritScope lock(&crit_); 189 rtc::CritScope lock(&crit_sect_);
190 return config_; 190 return config_;
191 } 191 }
192 192
193 void BlockNextEncode() { 193 void BlockNextEncode() {
194 rtc::CritScope lock(&crit_); 194 rtc::CritScope lock(&local_crit_sect_);
195 block_next_encode_ = true; 195 block_next_encode_ = true;
196 } 196 }
197 197
198 VideoEncoder::ScalingSettings GetScalingSettings() const override { 198 VideoEncoder::ScalingSettings GetScalingSettings() const override {
199 return VideoEncoder::ScalingSettings(true, 1, 2); 199 return VideoEncoder::ScalingSettings(true, 1, 2);
200 } 200 }
201 201
202 void ContinueEncode() { continue_encode_event_.Set(); } 202 void ContinueEncode() { continue_encode_event_.Set(); }
203 203
204 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, 204 void CheckLastTimeStampsMatch(int64_t ntp_time_ms,
205 uint32_t timestamp) const { 205 uint32_t timestamp) const {
206 rtc::CritScope lock(&crit_); 206 rtc::CritScope lock(&local_crit_sect_);
207 EXPECT_EQ(timestamp_, timestamp); 207 EXPECT_EQ(timestamp_, timestamp);
208 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); 208 EXPECT_EQ(ntp_time_ms_, ntp_time_ms);
209 } 209 }
210 210
211 private: 211 private:
212 int32_t Encode(const VideoFrame& input_image, 212 int32_t Encode(const VideoFrame& input_image,
213 const CodecSpecificInfo* codec_specific_info, 213 const CodecSpecificInfo* codec_specific_info,
214 const std::vector<FrameType>* frame_types) override { 214 const std::vector<FrameType>* frame_types) override {
215 bool block_encode; 215 bool block_encode;
216 { 216 {
217 rtc::CritScope lock(&crit_); 217 rtc::CritScope lock(&local_crit_sect_);
218 EXPECT_GT(input_image.timestamp(), timestamp_); 218 EXPECT_GT(input_image.timestamp(), timestamp_);
219 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); 219 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_);
220 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); 220 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90);
221 221
222 timestamp_ = input_image.timestamp(); 222 timestamp_ = input_image.timestamp();
223 ntp_time_ms_ = input_image.ntp_time_ms(); 223 ntp_time_ms_ = input_image.ntp_time_ms();
224 last_input_width_ = input_image.width(); 224 last_input_width_ = input_image.width();
225 last_input_height_ = input_image.height(); 225 last_input_height_ = input_image.height();
226 block_encode = block_next_encode_; 226 block_encode = block_next_encode_;
227 block_next_encode_ = false; 227 block_next_encode_ = false;
228 } 228 }
229 int32_t result = 229 int32_t result =
230 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); 230 FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
231 if (block_encode) 231 if (block_encode)
232 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs)); 232 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs));
233 return result; 233 return result;
234 } 234 }
235 235
236 rtc::CriticalSection crit_; 236 rtc::CriticalSection local_crit_sect_;
237 bool block_next_encode_ = false; 237 bool block_next_encode_ = false;
238 rtc::Event continue_encode_event_; 238 rtc::Event continue_encode_event_;
239 uint32_t timestamp_ = 0; 239 uint32_t timestamp_ = 0;
240 int64_t ntp_time_ms_ = 0; 240 int64_t ntp_time_ms_ = 0;
241 int last_input_width_ = 0; 241 int last_input_width_ = 0;
242 int last_input_height_ = 0; 242 int last_input_height_ = 0;
243 }; 243 };
244 244
245 class TestSink : public ViEEncoder::EncoderSink { 245 class TestSink : public ViEEncoder::EncoderSink {
246 public: 246 public:
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 vie_encoder_->Stop(); 973 vie_encoder_->Stop();
974 974
975 stats_proxy_.reset(); 975 stats_proxy_.reset();
976 EXPECT_EQ(1, 976 EXPECT_EQ(1,
977 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); 977 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
978 EXPECT_EQ( 978 EXPECT_EQ(
979 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); 979 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
980 } 980 }
981 981
982 } // namespace webrtc 982 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream_tests.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698