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 <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 static int kInputSamplesPerSecond = 5000; | 58 static int kInputSamplesPerSecond = 5000; |
59 static int kOutputSamplesPerSecond = 10000; | 59 static int kOutputSamplesPerSecond = 10000; |
60 static double kOutputMicrosPerFrame = | 60 static double kOutputMicrosPerFrame = |
61 static_cast<double>(base::Time::kMicrosecondsPerSecond) / | 61 static_cast<double>(base::Time::kMicrosecondsPerSecond) / |
62 kOutputSamplesPerSecond; | 62 kOutputSamplesPerSecond; |
63 | 63 |
64 ACTION_P(EnterPendingDecoderInitStateAction, test) { | 64 ACTION_P(EnterPendingDecoderInitStateAction, test) { |
65 test->EnterPendingDecoderInitState(arg2); | 65 test->EnterPendingDecoderInitState(arg2); |
66 } | 66 } |
67 | 67 |
68 class AudioRendererImplTest : public ::testing::Test { | 68 class AudioRendererImplTest : public ::testing::Test, public RendererClient { |
69 public: | 69 public: |
70 // Give the decoder some non-garbage media properties. | 70 // Give the decoder some non-garbage media properties. |
71 AudioRendererImplTest() | 71 AudioRendererImplTest() |
72 : hardware_config_(AudioParameters(), AudioParameters()), | 72 : hardware_config_(AudioParameters(), AudioParameters()), |
73 tick_clock_(new base::SimpleTestTickClock()), | 73 tick_clock_(new base::SimpleTestTickClock()), |
74 demuxer_stream_(DemuxerStream::AUDIO), | 74 demuxer_stream_(DemuxerStream::AUDIO), |
75 decoder_(new MockAudioDecoder()), | 75 decoder_(new MockAudioDecoder()), |
76 ended_(false) { | 76 ended_(false) { |
77 AudioDecoderConfig audio_config(kCodec, kSampleFormat, kChannelLayout, | 77 AudioDecoderConfig audio_config(kCodec, kSampleFormat, kChannelLayout, |
78 kInputSamplesPerSecond, EmptyExtraData(), | 78 kInputSamplesPerSecond, EmptyExtraData(), |
(...skipping 30 matching lines...) Expand all Loading... |
109 | 109 |
110 virtual ~AudioRendererImplTest() { | 110 virtual ~AudioRendererImplTest() { |
111 SCOPED_TRACE("~AudioRendererImplTest()"); | 111 SCOPED_TRACE("~AudioRendererImplTest()"); |
112 } | 112 } |
113 | 113 |
114 void ExpectUnsupportedAudioDecoder() { | 114 void ExpectUnsupportedAudioDecoder() { |
115 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) | 115 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) |
116 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(false))); | 116 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(false))); |
117 } | 117 } |
118 | 118 |
119 void OnStatistics(const PipelineStatistics& stats) { | 119 // RendererClient implementation. |
| 120 MOCK_METHOD1(OnError, void(PipelineStatus)); |
| 121 void OnEnded() override { |
| 122 CHECK(!ended_); |
| 123 ended_ = true; |
| 124 } |
| 125 void OnStatisticsUpdate(const PipelineStatistics& stats) override { |
120 last_statistics_.audio_memory_usage += stats.audio_memory_usage; | 126 last_statistics_.audio_memory_usage += stats.audio_memory_usage; |
121 } | 127 } |
122 | |
123 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | 128 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
124 MOCK_METHOD1(OnError, void(PipelineStatus)); | |
125 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 129 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
126 | 130 |
127 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { | 131 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { |
128 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 132 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
129 renderer_->Initialize( | 133 renderer_->Initialize(&demuxer_stream_, nullptr, this, pipeline_status_cb); |
130 &demuxer_stream_, pipeline_status_cb, nullptr, | |
131 base::Bind(&AudioRendererImplTest::OnStatistics, | |
132 base::Unretained(this)), | |
133 base::Bind(&AudioRendererImplTest::OnBufferingStateChange, | |
134 base::Unretained(this)), | |
135 base::Bind(&AudioRendererImplTest::OnEnded, base::Unretained(this)), | |
136 base::Bind(&AudioRendererImplTest::OnError, base::Unretained(this)), | |
137 base::Bind(&AudioRendererImplTest::OnWaitingForDecryptionKey, | |
138 base::Unretained(this))); | |
139 } | 134 } |
140 | 135 |
141 void Initialize() { | 136 void Initialize() { |
142 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) | 137 EXPECT_CALL(*decoder_, Initialize(_, _, _, _)) |
143 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(true))); | 138 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(true))); |
144 InitializeWithStatus(PIPELINE_OK); | 139 InitializeWithStatus(PIPELINE_OK); |
145 | 140 |
146 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond)); | 141 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond)); |
147 } | 142 } |
148 | 143 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (buffer.get() && !buffer->end_of_stream()) | 402 if (buffer.get() && !buffer->end_of_stream()) |
408 output_cb_.Run(buffer); | 403 output_cb_.Run(buffer); |
409 base::ResetAndReturn(&decode_cb_).Run(status); | 404 base::ResetAndReturn(&decode_cb_).Run(status); |
410 | 405 |
411 if (!reset_cb_.is_null()) | 406 if (!reset_cb_.is_null()) |
412 base::ResetAndReturn(&reset_cb_).Run(); | 407 base::ResetAndReturn(&reset_cb_).Run(); |
413 | 408 |
414 base::RunLoop().RunUntilIdle(); | 409 base::RunLoop().RunUntilIdle(); |
415 } | 410 } |
416 | 411 |
417 void OnEnded() { | |
418 CHECK(!ended_); | |
419 ended_ = true; | |
420 } | |
421 | |
422 MockDemuxerStream demuxer_stream_; | 412 MockDemuxerStream demuxer_stream_; |
423 MockAudioDecoder* decoder_; | 413 MockAudioDecoder* decoder_; |
424 | 414 |
425 // Used for satisfying reads. | 415 // Used for satisfying reads. |
426 AudioDecoder::OutputCB output_cb_; | 416 AudioDecoder::OutputCB output_cb_; |
427 AudioDecoder::DecodeCB decode_cb_; | 417 AudioDecoder::DecodeCB decode_cb_; |
428 base::Closure reset_cb_; | 418 base::Closure reset_cb_; |
429 std::unique_ptr<AudioTimestampHelper> next_timestamp_; | 419 std::unique_ptr<AudioTimestampHelper> next_timestamp_; |
430 | 420 |
431 // Run during DecodeDecoder() to unblock WaitForPendingRead(). | 421 // Run during DecodeDecoder() to unblock WaitForPendingRead(). |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 // Advance far enough that we shouldn't be clamped to current time (tested | 937 // Advance far enough that we shouldn't be clamped to current time (tested |
948 // already above). | 938 // already above). |
949 tick_clock_->Advance(kOneSecond); | 939 tick_clock_->Advance(kOneSecond); |
950 EXPECT_EQ( | 940 EXPECT_EQ( |
951 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 941 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
952 CurrentMediaWallClockTime(&is_time_moving)); | 942 CurrentMediaWallClockTime(&is_time_moving)); |
953 EXPECT_TRUE(is_time_moving); | 943 EXPECT_TRUE(is_time_moving); |
954 } | 944 } |
955 | 945 |
956 } // namespace media | 946 } // namespace media |
OLD | NEW |