| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This test generate synthetic data. For audio it's a sinusoid waveform with | 5 // This test generate synthetic data. For audio it's a sinusoid waveform with |
| 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern | 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern |
| 7 // that is shifting by one pixel per frame, each pixels neighbors right and down | 7 // that is shifting by one pixel per frame, each pixels neighbors right and down |
| 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap | 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap |
| 9 // frequently within the image. Visually this will create diagonally color bands | 9 // frequently within the image. Visually this will create diagonally color bands |
| 10 // that moves across the screen | 10 // that moves across the screen |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 void AddExpectedResult(const AudioBus& audio_bus, | 252 void AddExpectedResult(const AudioBus& audio_bus, |
| 253 const base::TimeTicks& playout_time) { | 253 const base::TimeTicks& playout_time) { |
| 254 std::unique_ptr<ExpectedAudioFrame> expected_audio_frame( | 254 std::unique_ptr<ExpectedAudioFrame> expected_audio_frame( |
| 255 new ExpectedAudioFrame()); | 255 new ExpectedAudioFrame()); |
| 256 expected_audio_frame->audio_bus = | 256 expected_audio_frame->audio_bus = |
| 257 AudioBus::Create(audio_bus.channels(), audio_bus.frames()); | 257 AudioBus::Create(audio_bus.channels(), audio_bus.frames()); |
| 258 audio_bus.CopyTo(expected_audio_frame->audio_bus.get()); | 258 audio_bus.CopyTo(expected_audio_frame->audio_bus.get()); |
| 259 expected_audio_frame->playout_time = playout_time; | 259 expected_audio_frame->playout_time = playout_time; |
| 260 expected_frames_.push_back(expected_audio_frame.release()); | 260 expected_frames_.push_back(std::move(expected_audio_frame)); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void IgnoreAudioFrame(std::unique_ptr<AudioBus> audio_bus, | 263 void IgnoreAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
| 264 const base::TimeTicks& playout_time, | 264 const base::TimeTicks& playout_time, |
| 265 bool is_continuous) { | 265 bool is_continuous) { |
| 266 ++num_called_; | 266 ++num_called_; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void CheckAudioFrame(std::unique_ptr<AudioBus> audio_bus, | 269 void CheckAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
| 270 const base::TimeTicks& playout_time, | 270 const base::TimeTicks& playout_time, |
| 271 bool is_continuous) { | 271 bool is_continuous) { |
| 272 ++num_called_; | 272 ++num_called_; |
| 273 | 273 |
| 274 ASSERT_TRUE(audio_bus); | 274 ASSERT_TRUE(audio_bus); |
| 275 ASSERT_FALSE(expected_frames_.empty()); | 275 ASSERT_FALSE(expected_frames_.empty()); |
| 276 const std::unique_ptr<ExpectedAudioFrame> expected_audio_frame( | 276 const std::unique_ptr<ExpectedAudioFrame> expected_audio_frame = |
| 277 expected_frames_.front()); | 277 std::move(expected_frames_.front()); |
| 278 expected_frames_.pop_front(); | 278 expected_frames_.pop_front(); |
| 279 | 279 |
| 280 EXPECT_EQ(audio_bus->channels(), kAudioChannels); | 280 EXPECT_EQ(audio_bus->channels(), kAudioChannels); |
| 281 EXPECT_EQ(audio_bus->frames(), expected_audio_frame->audio_bus->frames()); | 281 EXPECT_EQ(audio_bus->frames(), expected_audio_frame->audio_bus->frames()); |
| 282 for (int ch = 0; ch < audio_bus->channels(); ++ch) { | 282 for (int ch = 0; ch < audio_bus->channels(); ++ch) { |
| 283 EXPECT_NEAR(CountZeroCrossings( | 283 EXPECT_NEAR(CountZeroCrossings( |
| 284 expected_audio_frame->audio_bus->channel(ch), | 284 expected_audio_frame->audio_bus->channel(ch), |
| 285 expected_audio_frame->audio_bus->frames()), | 285 expected_audio_frame->audio_bus->frames()), |
| 286 CountZeroCrossings(audio_bus->channel(ch), | 286 CountZeroCrossings(audio_bus->channel(ch), |
| 287 audio_bus->frames()), | 287 audio_bus->frames()), |
| 288 1); | 288 1); |
| 289 } | 289 } |
| 290 | 290 |
| 291 EXPECT_NEAR( | 291 EXPECT_NEAR( |
| 292 (playout_time - expected_audio_frame->playout_time).InMillisecondsF(), | 292 (playout_time - expected_audio_frame->playout_time).InMillisecondsF(), |
| 293 0.0, | 293 0.0, |
| 294 kMaxAllowedPlayoutErrorMs); | 294 kMaxAllowedPlayoutErrorMs); |
| 295 VLOG_IF(1, !last_playout_time_.is_null()) | 295 VLOG_IF(1, !last_playout_time_.is_null()) |
| 296 << "Audio frame playout time delta (compared to last frame) is " | 296 << "Audio frame playout time delta (compared to last frame) is " |
| 297 << (playout_time - last_playout_time_).InMicroseconds() << " usec."; | 297 << (playout_time - last_playout_time_).InMicroseconds() << " usec."; |
| 298 last_playout_time_ = playout_time; | 298 last_playout_time_ = playout_time; |
| 299 | 299 |
| 300 EXPECT_TRUE(is_continuous); | 300 EXPECT_TRUE(is_continuous); |
| 301 } | 301 } |
| 302 | 302 |
| 303 int number_times_called() const { return num_called_; } | 303 int number_times_called() const { return num_called_; } |
| 304 | 304 |
| 305 protected: | 305 protected: |
| 306 virtual ~TestReceiverAudioCallback() { | 306 virtual ~TestReceiverAudioCallback() { |
| 307 base::STLDeleteElements(&expected_frames_); | |
| 308 } | 307 } |
| 309 | 308 |
| 310 private: | 309 private: |
| 311 friend class base::RefCountedThreadSafe<TestReceiverAudioCallback>; | 310 friend class base::RefCountedThreadSafe<TestReceiverAudioCallback>; |
| 312 | 311 |
| 313 int num_called_; | 312 int num_called_; |
| 314 int expected_sampling_frequency_; | 313 int expected_sampling_frequency_; |
| 315 std::list<ExpectedAudioFrame*> expected_frames_; | 314 std::list<std::unique_ptr<ExpectedAudioFrame>> expected_frames_; |
| 316 base::TimeTicks last_playout_time_; | 315 base::TimeTicks last_playout_time_; |
| 317 }; | 316 }; |
| 318 | 317 |
| 319 // Class that verifies the video frames coming out of the receiver. | 318 // Class that verifies the video frames coming out of the receiver. |
| 320 class TestReceiverVideoCallback | 319 class TestReceiverVideoCallback |
| 321 : public base::RefCountedThreadSafe<TestReceiverVideoCallback> { | 320 : public base::RefCountedThreadSafe<TestReceiverVideoCallback> { |
| 322 public: | 321 public: |
| 323 struct ExpectedVideoFrame { | 322 struct ExpectedVideoFrame { |
| 324 int frame_number; | 323 int frame_number; |
| 325 gfx::Size size; | 324 gfx::Size size; |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 EXPECT_EQ(0u, jump); | 1270 EXPECT_EQ(0u, jump); |
| 1272 jump = i; | 1271 jump = i; |
| 1273 } | 1272 } |
| 1274 } | 1273 } |
| 1275 EXPECT_GT(jump, 49u); | 1274 EXPECT_GT(jump, 49u); |
| 1276 EXPECT_LT(jump, 120u); | 1275 EXPECT_LT(jump, 120u); |
| 1277 } | 1276 } |
| 1278 | 1277 |
| 1279 } // namespace cast | 1278 } // namespace cast |
| 1280 } // namespace media | 1279 } // namespace media |
| OLD | NEW |