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" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
17 #include "media/base/audio_buffer_converter.h" | 18 #include "media/base/audio_buffer_converter.h" |
18 #include "media/base/audio_splicer.h" | 19 #include "media/base/audio_splicer.h" |
19 #include "media/base/fake_audio_renderer_sink.h" | 20 #include "media/base/fake_audio_renderer_sink.h" |
20 #include "media/base/gmock_callback_support.h" | 21 #include "media/base/gmock_callback_support.h" |
21 #include "media/base/media_util.h" | 22 #include "media/base/media_util.h" |
22 #include "media/base/mock_filters.h" | 23 #include "media/base/mock_filters.h" |
23 #include "media/base/test_helpers.h" | 24 #include "media/base/test_helpers.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 267 |
267 void DeliverEndOfStream() { | 268 void DeliverEndOfStream() { |
268 DCHECK(!decode_cb_.is_null()); | 269 DCHECK(!decode_cb_.is_null()); |
269 | 270 |
270 // Return EOS buffer to trigger EOS frame. | 271 // Return EOS buffer to trigger EOS frame. |
271 EXPECT_CALL(demuxer_stream_, Read(_)) | 272 EXPECT_CALL(demuxer_stream_, Read(_)) |
272 .WillOnce(RunCallback<0>(DemuxerStream::kOk, | 273 .WillOnce(RunCallback<0>(DemuxerStream::kOk, |
273 DecoderBuffer::CreateEOSBuffer())); | 274 DecoderBuffer::CreateEOSBuffer())); |
274 | 275 |
275 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read(). | 276 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read(). |
276 message_loop_.PostTask( | 277 message_loop_.task_runner()->PostTask( |
277 FROM_HERE, | 278 FROM_HERE, |
278 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); | 279 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); |
279 | 280 |
280 WaitForPendingRead(); | 281 WaitForPendingRead(); |
281 | 282 |
282 message_loop_.PostTask( | 283 message_loop_.task_runner()->PostTask( |
283 FROM_HERE, | 284 FROM_HERE, |
284 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); | 285 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); |
285 | 286 |
286 base::RunLoop().RunUntilIdle(); | 287 base::RunLoop().RunUntilIdle(); |
287 EXPECT_EQ(last_statistics_.audio_memory_usage, | 288 EXPECT_EQ(last_statistics_.audio_memory_usage, |
288 renderer_->algorithm_->GetMemoryUsage()); | 289 renderer_->algorithm_->GetMemoryUsage()); |
289 } | 290 } |
290 | 291 |
291 // Delivers frames until |renderer_|'s internal buffer is full and no longer | 292 // Delivers frames until |renderer_|'s internal buffer is full and no longer |
292 // has pending reads. | 293 // has pending reads. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 std::unique_ptr<AudioRendererImpl> renderer_; | 370 std::unique_ptr<AudioRendererImpl> renderer_; |
370 scoped_refptr<FakeAudioRendererSink> sink_; | 371 scoped_refptr<FakeAudioRendererSink> sink_; |
371 base::SimpleTestTickClock* tick_clock_; | 372 base::SimpleTestTickClock* tick_clock_; |
372 PipelineStatistics last_statistics_; | 373 PipelineStatistics last_statistics_; |
373 | 374 |
374 private: | 375 private: |
375 void DecodeDecoder(const scoped_refptr<DecoderBuffer>& buffer, | 376 void DecodeDecoder(const scoped_refptr<DecoderBuffer>& buffer, |
376 const AudioDecoder::DecodeCB& decode_cb) { | 377 const AudioDecoder::DecodeCB& decode_cb) { |
377 // TODO(scherkus): Make this a DCHECK after threading semantics are fixed. | 378 // TODO(scherkus): Make this a DCHECK after threading semantics are fixed. |
378 if (base::MessageLoop::current() != &message_loop_) { | 379 if (base::MessageLoop::current() != &message_loop_) { |
379 message_loop_.PostTask(FROM_HERE, base::Bind( | 380 message_loop_.task_runner()->PostTask( |
380 &AudioRendererImplTest::DecodeDecoder, | 381 FROM_HERE, base::Bind(&AudioRendererImplTest::DecodeDecoder, |
381 base::Unretained(this), buffer, decode_cb)); | 382 base::Unretained(this), buffer, decode_cb)); |
382 return; | 383 return; |
383 } | 384 } |
384 | 385 |
385 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not permitted"; | 386 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not permitted"; |
386 decode_cb_ = decode_cb; | 387 decode_cb_ = decode_cb; |
387 | 388 |
388 // Wake up WaitForPendingRead() if needed. | 389 // Wake up WaitForPendingRead() if needed. |
389 if (!wait_for_pending_decode_cb_.is_null()) | 390 if (!wait_for_pending_decode_cb_.is_null()) |
390 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run(); | 391 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run(); |
391 } | 392 } |
392 | 393 |
393 void ResetDecoder(const base::Closure& reset_cb) { | 394 void ResetDecoder(const base::Closure& reset_cb) { |
394 if (!decode_cb_.is_null()) { | 395 if (!decode_cb_.is_null()) { |
395 // |reset_cb| will be called in DeliverBuffer(), after the decoder is | 396 // |reset_cb| will be called in DeliverBuffer(), after the decoder is |
396 // flushed. | 397 // flushed. |
397 reset_cb_ = reset_cb; | 398 reset_cb_ = reset_cb; |
398 return; | 399 return; |
399 } | 400 } |
400 | 401 |
401 message_loop_.PostTask(FROM_HERE, reset_cb); | 402 message_loop_.task_runner()->PostTask(FROM_HERE, reset_cb); |
402 } | 403 } |
403 | 404 |
404 void DeliverBuffer(DecodeStatus status, | 405 void DeliverBuffer(DecodeStatus status, |
405 const scoped_refptr<AudioBuffer>& buffer) { | 406 const scoped_refptr<AudioBuffer>& buffer) { |
406 CHECK(!decode_cb_.is_null()); | 407 CHECK(!decode_cb_.is_null()); |
407 | 408 |
408 if (buffer.get() && !buffer->end_of_stream()) | 409 if (buffer.get() && !buffer->end_of_stream()) |
409 output_cb_.Run(buffer); | 410 output_cb_.Run(buffer); |
410 base::ResetAndReturn(&decode_cb_).Run(status); | 411 base::ResetAndReturn(&decode_cb_).Run(status); |
411 | 412 |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 // Advance far enough that we shouldn't be clamped to current time (tested | 980 // Advance far enough that we shouldn't be clamped to current time (tested |
980 // already above). | 981 // already above). |
981 tick_clock_->Advance(kOneSecond); | 982 tick_clock_->Advance(kOneSecond); |
982 EXPECT_EQ( | 983 EXPECT_EQ( |
983 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), | 984 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), |
984 CurrentMediaWallClockTime(&is_time_moving)); | 985 CurrentMediaWallClockTime(&is_time_moving)); |
985 EXPECT_TRUE(is_time_moving); | 986 EXPECT_TRUE(is_time_moving); |
986 } | 987 } |
987 | 988 |
988 } // namespace media | 989 } // namespace media |
OLD | NEW |