| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "media/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/test/simple_test_tick_clock.h" | 16 #include "base/test/simple_test_tick_clock.h" |
| 16 #include "media/base/audio_buffer_converter.h" | 17 #include "media/base/audio_buffer_converter.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 while (frames_remaining_in_buffer().value > 0) { | 293 while (frames_remaining_in_buffer().value > 0) { |
| 293 SatisfyPendingRead(InputFrames(256)); | 294 SatisfyPendingRead(InputFrames(256)); |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 // Attempts to consume |requested_frames| frames from |renderer_|'s internal | 298 // Attempts to consume |requested_frames| frames from |renderer_|'s internal |
| 298 // buffer. Returns true if and only if all of |requested_frames| were able | 299 // buffer. Returns true if and only if all of |requested_frames| were able |
| 299 // to be consumed. | 300 // to be consumed. |
| 300 bool ConsumeBufferedData(OutputFrames requested_frames, | 301 bool ConsumeBufferedData(OutputFrames requested_frames, |
| 301 uint32_t delay_frames) { | 302 uint32_t delay_frames) { |
| 302 scoped_ptr<AudioBus> bus = | 303 std::unique_ptr<AudioBus> bus = |
| 303 AudioBus::Create(kChannels, requested_frames.value); | 304 AudioBus::Create(kChannels, requested_frames.value); |
| 304 int frames_read = 0; | 305 int frames_read = 0; |
| 305 EXPECT_TRUE(sink_->Render(bus.get(), delay_frames, &frames_read)); | 306 EXPECT_TRUE(sink_->Render(bus.get(), delay_frames, &frames_read)); |
| 306 return frames_read == requested_frames.value; | 307 return frames_read == requested_frames.value; |
| 307 } | 308 } |
| 308 | 309 |
| 309 bool ConsumeBufferedData(OutputFrames requested_frames) { | 310 bool ConsumeBufferedData(OutputFrames requested_frames) { |
| 310 return ConsumeBufferedData(requested_frames, 0); | 311 return ConsumeBufferedData(requested_frames, 0); |
| 311 } | 312 } |
| 312 | 313 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 357 } |
| 357 | 358 |
| 358 base::TimeDelta CurrentMediaTime() { | 359 base::TimeDelta CurrentMediaTime() { |
| 359 return renderer_->CurrentMediaTime(); | 360 return renderer_->CurrentMediaTime(); |
| 360 } | 361 } |
| 361 | 362 |
| 362 bool ended() const { return ended_; } | 363 bool ended() const { return ended_; } |
| 363 | 364 |
| 364 // Fixture members. | 365 // Fixture members. |
| 365 base::MessageLoop message_loop_; | 366 base::MessageLoop message_loop_; |
| 366 scoped_ptr<AudioRendererImpl> renderer_; | 367 std::unique_ptr<AudioRendererImpl> renderer_; |
| 367 scoped_refptr<FakeAudioRendererSink> sink_; | 368 scoped_refptr<FakeAudioRendererSink> sink_; |
| 368 AudioHardwareConfig hardware_config_; | 369 AudioHardwareConfig hardware_config_; |
| 369 base::SimpleTestTickClock* tick_clock_; | 370 base::SimpleTestTickClock* tick_clock_; |
| 370 PipelineStatistics last_statistics_; | 371 PipelineStatistics last_statistics_; |
| 371 | 372 |
| 372 private: | 373 private: |
| 373 void DecodeDecoder(const scoped_refptr<DecoderBuffer>& buffer, | 374 void DecodeDecoder(const scoped_refptr<DecoderBuffer>& buffer, |
| 374 const AudioDecoder::DecodeCB& decode_cb) { | 375 const AudioDecoder::DecodeCB& decode_cb) { |
| 375 // TODO(scherkus): Make this a DCHECK after threading semantics are fixed. | 376 // TODO(scherkus): Make this a DCHECK after threading semantics are fixed. |
| 376 if (base::MessageLoop::current() != &message_loop_) { | 377 if (base::MessageLoop::current() != &message_loop_) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 ended_ = true; | 419 ended_ = true; |
| 419 } | 420 } |
| 420 | 421 |
| 421 MockDemuxerStream demuxer_stream_; | 422 MockDemuxerStream demuxer_stream_; |
| 422 MockAudioDecoder* decoder_; | 423 MockAudioDecoder* decoder_; |
| 423 | 424 |
| 424 // Used for satisfying reads. | 425 // Used for satisfying reads. |
| 425 AudioDecoder::OutputCB output_cb_; | 426 AudioDecoder::OutputCB output_cb_; |
| 426 AudioDecoder::DecodeCB decode_cb_; | 427 AudioDecoder::DecodeCB decode_cb_; |
| 427 base::Closure reset_cb_; | 428 base::Closure reset_cb_; |
| 428 scoped_ptr<AudioTimestampHelper> next_timestamp_; | 429 std::unique_ptr<AudioTimestampHelper> next_timestamp_; |
| 429 | 430 |
| 430 // Run during DecodeDecoder() to unblock WaitForPendingRead(). | 431 // Run during DecodeDecoder() to unblock WaitForPendingRead(). |
| 431 base::Closure wait_for_pending_decode_cb_; | 432 base::Closure wait_for_pending_decode_cb_; |
| 432 | 433 |
| 433 AudioDecoder::InitCB init_decoder_cb_; | 434 AudioDecoder::InitCB init_decoder_cb_; |
| 434 bool ended_; | 435 bool ended_; |
| 435 | 436 |
| 436 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); | 437 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); |
| 437 }; | 438 }; |
| 438 | 439 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // through the desired output buffer; this allows for maximum test coverage. | 722 // through the desired output buffer; this allows for maximum test coverage. |
| 722 const double kBuffers = 4.5; | 723 const double kBuffers = 4.5; |
| 723 const base::TimeDelta first_timestamp = base::TimeDelta::FromSecondsD( | 724 const base::TimeDelta first_timestamp = base::TimeDelta::FromSecondsD( |
| 724 hardware_config_.GetOutputBufferSize() * kBuffers / | 725 hardware_config_.GetOutputBufferSize() * kBuffers / |
| 725 hardware_config_.GetOutputSampleRate()); | 726 hardware_config_.GetOutputSampleRate()); |
| 726 | 727 |
| 727 Preroll(base::TimeDelta(), first_timestamp, PIPELINE_OK); | 728 Preroll(base::TimeDelta(), first_timestamp, PIPELINE_OK); |
| 728 StartTicking(); | 729 StartTicking(); |
| 729 | 730 |
| 730 // Verify the first few buffers are silent. | 731 // Verify the first few buffers are silent. |
| 731 scoped_ptr<AudioBus> bus = | 732 std::unique_ptr<AudioBus> bus = |
| 732 AudioBus::Create(hardware_config_.GetOutputConfig()); | 733 AudioBus::Create(hardware_config_.GetOutputConfig()); |
| 733 int frames_read = 0; | 734 int frames_read = 0; |
| 734 for (int i = 0; i < std::floor(kBuffers); ++i) { | 735 for (int i = 0; i < std::floor(kBuffers); ++i) { |
| 735 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read)); | 736 EXPECT_TRUE(sink_->Render(bus.get(), 0, &frames_read)); |
| 736 EXPECT_EQ(frames_read, bus->frames()); | 737 EXPECT_EQ(frames_read, bus->frames()); |
| 737 for (int j = 0; j < bus->frames(); ++j) | 738 for (int j = 0; j < bus->frames(); ++j) |
| 738 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[j]); | 739 ASSERT_FLOAT_EQ(0.0f, bus->channel(0)[j]); |
| 739 WaitForPendingRead(); | 740 WaitForPendingRead(); |
| 740 DeliverRemainingAudio(); | 741 DeliverRemainingAudio(); |
| 741 } | 742 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 // Advance far enough that we shouldn't be clamped to current time (tested | 938 // Advance far enough that we shouldn't be clamped to current time (tested |
| 938 // already above). | 939 // already above). |
| 939 tick_clock_->Advance(kOneSecond); | 940 tick_clock_->Advance(kOneSecond); |
| 940 EXPECT_EQ( | 941 EXPECT_EQ( |
| 941 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 942 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
| 942 CurrentMediaWallClockTime(&is_time_moving)); | 943 CurrentMediaWallClockTime(&is_time_moving)); |
| 943 EXPECT_TRUE(is_time_moving); | 944 EXPECT_TRUE(is_time_moving); |
| 944 } | 945 } |
| 945 | 946 |
| 946 } // namespace media | 947 } // namespace media |
| OLD | NEW |