| 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 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/test/test_message_loop.h" | 10 #include "base/test/test_message_loop.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 .WillOnce(Return(0)); | 425 .WillOnce(Return(0)); |
| 426 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle)) | 426 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle)) |
| 427 .WillOnce(Return(0)); | 427 .WillOnce(Return(0)); |
| 428 | 428 |
| 429 // Expect the pre-roll. | 429 // Expect the pre-roll. |
| 430 MockAudioSourceCallback mock_callback; | 430 MockAudioSourceCallback mock_callback; |
| 431 EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle)) | 431 EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle)) |
| 432 .WillRepeatedly(Return(SND_PCM_STATE_RUNNING)); | 432 .WillRepeatedly(Return(SND_PCM_STATE_RUNNING)); |
| 433 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _)) | 433 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _)) |
| 434 .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0))); | 434 .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0))); |
| 435 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) | 435 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0, AudioTimestamp())) |
| 436 .WillRepeatedly(DoAll(ClearBuffer(), Return(kTestFramesPerPacket))); | 436 .WillRepeatedly(DoAll(ClearBuffer(), Return(kTestFramesPerPacket))); |
| 437 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) | 437 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) |
| 438 .WillRepeatedly(Return(kTestFramesPerPacket)); | 438 .WillRepeatedly(Return(kTestFramesPerPacket)); |
| 439 | 439 |
| 440 // Expect scheduling. | 440 // Expect scheduling. |
| 441 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 441 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
| 442 .Times(AtLeast(2)) | 442 .Times(AtLeast(2)) |
| 443 .WillRepeatedly(Return(kTestFramesPerPacket)); | 443 .WillRepeatedly(Return(kTestFramesPerPacket)); |
| 444 | 444 |
| 445 test_stream->Start(&mock_callback); | 445 test_stream->Start(&mock_callback); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 588 |
| 589 MockAudioSourceCallback mock_callback; | 589 MockAudioSourceCallback mock_callback; |
| 590 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 590 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
| 591 .WillOnce(Return(SND_PCM_STATE_RUNNING)); | 591 .WillOnce(Return(SND_PCM_STATE_RUNNING)); |
| 592 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) | 592 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) |
| 593 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(0))); | 593 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(0))); |
| 594 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 594 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
| 595 .WillRepeatedly(Return(0)); // Buffer is full. | 595 .WillRepeatedly(Return(0)); // Buffer is full. |
| 596 | 596 |
| 597 // Return a partially filled packet. | 597 // Return a partially filled packet. |
| 598 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) | 598 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0, AudioTimestamp())) |
| 599 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 599 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
| 600 | 600 |
| 601 bool source_exhausted; | 601 bool source_exhausted; |
| 602 test_stream->set_source_callback(&mock_callback); | 602 test_stream->set_source_callback(&mock_callback); |
| 603 test_stream->packet_size_ = kTestPacketSize; | 603 test_stream->packet_size_ = kTestPacketSize; |
| 604 test_stream->BufferPacket(&source_exhausted); | 604 test_stream->BufferPacket(&source_exhausted); |
| 605 | 605 |
| 606 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 606 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
| 607 EXPECT_FALSE(source_exhausted); | 607 EXPECT_FALSE(source_exhausted); |
| 608 test_stream->Close(); | 608 test_stream->Close(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) { | 611 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) { |
| 612 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); | 612 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); |
| 613 InitBuffer(test_stream); | 613 InitBuffer(test_stream); |
| 614 test_stream->buffer_->Clear(); | 614 test_stream->buffer_->Clear(); |
| 615 | 615 |
| 616 // Simulate where the underrun has occurred right after checking the delay. | 616 // Simulate where the underrun has occurred right after checking the delay. |
| 617 MockAudioSourceCallback mock_callback; | 617 MockAudioSourceCallback mock_callback; |
| 618 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 618 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
| 619 .WillOnce(Return(SND_PCM_STATE_RUNNING)); | 619 .WillOnce(Return(SND_PCM_STATE_RUNNING)); |
| 620 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) | 620 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) |
| 621 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(0))); | 621 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(0))); |
| 622 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 622 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
| 623 .WillRepeatedly(Return(0)); // Buffer is full. | 623 .WillRepeatedly(Return(0)); // Buffer is full. |
| 624 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) | 624 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0, AudioTimestamp())) |
| 625 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 625 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
| 626 | 626 |
| 627 bool source_exhausted; | 627 bool source_exhausted; |
| 628 test_stream->set_source_callback(&mock_callback); | 628 test_stream->set_source_callback(&mock_callback); |
| 629 test_stream->packet_size_ = kTestPacketSize; | 629 test_stream->packet_size_ = kTestPacketSize; |
| 630 test_stream->BufferPacket(&source_exhausted); | 630 test_stream->BufferPacket(&source_exhausted); |
| 631 | 631 |
| 632 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 632 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
| 633 EXPECT_FALSE(source_exhausted); | 633 EXPECT_FALSE(source_exhausted); |
| 634 test_stream->Close(); | 634 test_stream->Close(); |
| 635 } | 635 } |
| 636 | 636 |
| 637 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { | 637 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { |
| 638 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); | 638 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); |
| 639 InitBuffer(test_stream); | 639 InitBuffer(test_stream); |
| 640 test_stream->buffer_->Clear(); | 640 test_stream->buffer_->Clear(); |
| 641 | 641 |
| 642 // If ALSA has underrun then we should assume a delay of zero. | 642 // If ALSA has underrun then we should assume a delay of zero. |
| 643 MockAudioSourceCallback mock_callback; | 643 MockAudioSourceCallback mock_callback; |
| 644 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 644 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
| 645 .WillOnce(Return(SND_PCM_STATE_XRUN)); | 645 .WillOnce(Return(SND_PCM_STATE_XRUN)); |
| 646 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 646 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
| 647 .WillRepeatedly(Return(0)); // Buffer is full. | 647 .WillRepeatedly(Return(0)); // Buffer is full. |
| 648 EXPECT_CALL(mock_callback, OnMoreData(_, 0, 0)) | 648 EXPECT_CALL(mock_callback, OnMoreData(_, 0, 0, AudioTimestamp())) |
| 649 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 649 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
| 650 | 650 |
| 651 bool source_exhausted; | 651 bool source_exhausted; |
| 652 test_stream->set_source_callback(&mock_callback); | 652 test_stream->set_source_callback(&mock_callback); |
| 653 test_stream->packet_size_ = kTestPacketSize; | 653 test_stream->packet_size_ = kTestPacketSize; |
| 654 test_stream->BufferPacket(&source_exhausted); | 654 test_stream->BufferPacket(&source_exhausted); |
| 655 | 655 |
| 656 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 656 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
| 657 EXPECT_FALSE(source_exhausted); | 657 EXPECT_FALSE(source_exhausted); |
| 658 test_stream->Close(); | 658 test_stream->Close(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 858 |
| 859 // TODO(ajwong): Find a way to test whether or not another task has been | 859 // TODO(ajwong): Find a way to test whether or not another task has been |
| 860 // posted so we can verify that the Alsa code will indeed break the task | 860 // posted so we can verify that the Alsa code will indeed break the task |
| 861 // posting loop. | 861 // posting loop. |
| 862 | 862 |
| 863 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); | 863 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); |
| 864 test_stream->Close(); | 864 test_stream->Close(); |
| 865 } | 865 } |
| 866 | 866 |
| 867 } // namespace media | 867 } // namespace media |
| OLD | NEW |