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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "media/audio/alsa/alsa_output.h" | 6 #include "media/audio/alsa/alsa_output.h" |
7 #include "media/audio/alsa/alsa_wrapper.h" | 7 #include "media/audio/alsa/alsa_wrapper.h" |
8 #include "media/audio/alsa/audio_manager_alsa.h" | 8 #include "media/audio/alsa/audio_manager_alsa.h" |
9 #include "media/audio/fake_audio_log_factory.h" | 9 #include "media/audio/fake_audio_log_factory.h" |
10 #include "media/audio/mock_audio_source_callback.h" | 10 #include "media/audio/mock_audio_source_callback.h" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 .WillOnce(Return(0)); | 415 .WillOnce(Return(0)); |
416 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle)) | 416 EXPECT_CALL(mock_alsa_wrapper_, PcmPrepare(kFakeHandle)) |
417 .WillOnce(Return(0)); | 417 .WillOnce(Return(0)); |
418 | 418 |
419 // Expect the pre-roll. | 419 // Expect the pre-roll. |
420 MockAudioSourceCallback mock_callback; | 420 MockAudioSourceCallback mock_callback; |
421 EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle)) | 421 EXPECT_CALL(mock_alsa_wrapper_, PcmState(kFakeHandle)) |
422 .WillRepeatedly(Return(SND_PCM_STATE_RUNNING)); | 422 .WillRepeatedly(Return(SND_PCM_STATE_RUNNING)); |
423 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _)) | 423 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(kFakeHandle, _)) |
424 .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0))); | 424 .WillRepeatedly(DoAll(SetArgumentPointee<1>(0), Return(0))); |
425 EXPECT_CALL(mock_callback, OnMoreData(_, _)) | 425 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) |
426 .WillRepeatedly(DoAll(ClearBuffer(), Return(kTestFramesPerPacket))); | 426 .WillRepeatedly(DoAll(ClearBuffer(), Return(kTestFramesPerPacket))); |
427 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) | 427 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) |
428 .WillRepeatedly(Return(kTestFramesPerPacket)); | 428 .WillRepeatedly(Return(kTestFramesPerPacket)); |
429 | 429 |
430 // Expect scheduling. | 430 // Expect scheduling. |
431 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 431 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
432 .Times(AtLeast(2)) | 432 .Times(AtLeast(2)) |
433 .WillRepeatedly(Return(kTestFramesPerPacket)); | 433 .WillRepeatedly(Return(kTestFramesPerPacket)); |
434 | 434 |
435 test_stream->Start(&mock_callback); | 435 test_stream->Start(&mock_callback); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 578 |
579 MockAudioSourceCallback mock_callback; | 579 MockAudioSourceCallback mock_callback; |
580 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 580 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
581 .WillOnce(Return(SND_PCM_STATE_RUNNING)); | 581 .WillOnce(Return(SND_PCM_STATE_RUNNING)); |
582 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) | 582 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) |
583 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(0))); | 583 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(0))); |
584 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 584 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
585 .WillRepeatedly(Return(0)); // Buffer is full. | 585 .WillRepeatedly(Return(0)); // Buffer is full. |
586 | 586 |
587 // Return a partially filled packet. | 587 // Return a partially filled packet. |
588 EXPECT_CALL(mock_callback, OnMoreData(_, _)) | 588 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) |
589 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 589 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
590 | 590 |
591 bool source_exhausted; | 591 bool source_exhausted; |
592 test_stream->set_source_callback(&mock_callback); | 592 test_stream->set_source_callback(&mock_callback); |
593 test_stream->packet_size_ = kTestPacketSize; | 593 test_stream->packet_size_ = kTestPacketSize; |
594 test_stream->BufferPacket(&source_exhausted); | 594 test_stream->BufferPacket(&source_exhausted); |
595 | 595 |
596 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 596 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
597 EXPECT_FALSE(source_exhausted); | 597 EXPECT_FALSE(source_exhausted); |
598 test_stream->Close(); | 598 test_stream->Close(); |
599 } | 599 } |
600 | 600 |
601 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) { | 601 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Negative) { |
602 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); | 602 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); |
603 InitBuffer(test_stream); | 603 InitBuffer(test_stream); |
604 test_stream->buffer_->Clear(); | 604 test_stream->buffer_->Clear(); |
605 | 605 |
606 // Simulate where the underrun has occurred right after checking the delay. | 606 // Simulate where the underrun has occurred right after checking the delay. |
607 MockAudioSourceCallback mock_callback; | 607 MockAudioSourceCallback mock_callback; |
608 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 608 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
609 .WillOnce(Return(SND_PCM_STATE_RUNNING)); | 609 .WillOnce(Return(SND_PCM_STATE_RUNNING)); |
610 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) | 610 EXPECT_CALL(mock_alsa_wrapper_, PcmDelay(_, _)) |
611 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(0))); | 611 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(0))); |
612 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 612 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
613 .WillRepeatedly(Return(0)); // Buffer is full. | 613 .WillRepeatedly(Return(0)); // Buffer is full. |
614 EXPECT_CALL(mock_callback, OnMoreData(_, _)) | 614 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0)) |
615 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 615 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
616 | 616 |
617 bool source_exhausted; | 617 bool source_exhausted; |
618 test_stream->set_source_callback(&mock_callback); | 618 test_stream->set_source_callback(&mock_callback); |
619 test_stream->packet_size_ = kTestPacketSize; | 619 test_stream->packet_size_ = kTestPacketSize; |
620 test_stream->BufferPacket(&source_exhausted); | 620 test_stream->BufferPacket(&source_exhausted); |
621 | 621 |
622 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 622 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
623 EXPECT_FALSE(source_exhausted); | 623 EXPECT_FALSE(source_exhausted); |
624 test_stream->Close(); | 624 test_stream->Close(); |
625 } | 625 } |
626 | 626 |
627 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { | 627 TEST_F(AlsaPcmOutputStreamTest, BufferPacket_Underrun) { |
628 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); | 628 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); |
629 InitBuffer(test_stream); | 629 InitBuffer(test_stream); |
630 test_stream->buffer_->Clear(); | 630 test_stream->buffer_->Clear(); |
631 | 631 |
632 // If ALSA has underrun then we should assume a delay of zero. | 632 // If ALSA has underrun then we should assume a delay of zero. |
633 MockAudioSourceCallback mock_callback; | 633 MockAudioSourceCallback mock_callback; |
634 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) | 634 EXPECT_CALL(mock_alsa_wrapper_, PcmState(_)) |
635 .WillOnce(Return(SND_PCM_STATE_XRUN)); | 635 .WillOnce(Return(SND_PCM_STATE_XRUN)); |
636 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) | 636 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(_)) |
637 .WillRepeatedly(Return(0)); // Buffer is full. | 637 .WillRepeatedly(Return(0)); // Buffer is full. |
638 EXPECT_CALL(mock_callback, OnMoreData(_, 0)) | 638 EXPECT_CALL(mock_callback, OnMoreData(_, 0, 0)) |
639 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); | 639 .WillOnce(DoAll(ClearBuffer(), Return(kTestFramesPerPacket / 2))); |
640 | 640 |
641 bool source_exhausted; | 641 bool source_exhausted; |
642 test_stream->set_source_callback(&mock_callback); | 642 test_stream->set_source_callback(&mock_callback); |
643 test_stream->packet_size_ = kTestPacketSize; | 643 test_stream->packet_size_ = kTestPacketSize; |
644 test_stream->BufferPacket(&source_exhausted); | 644 test_stream->BufferPacket(&source_exhausted); |
645 | 645 |
646 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); | 646 EXPECT_EQ(kTestPacketSize / 2, test_stream->buffer_->forward_bytes()); |
647 EXPECT_FALSE(source_exhausted); | 647 EXPECT_FALSE(source_exhausted); |
648 test_stream->Close(); | 648 test_stream->Close(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 848 |
849 // TODO(ajwong): Find a way to test whether or not another task has been | 849 // TODO(ajwong): Find a way to test whether or not another task has been |
850 // posted so we can verify that the Alsa code will indeed break the task | 850 // posted so we can verify that the Alsa code will indeed break the task |
851 // posting loop. | 851 // posting loop. |
852 | 852 |
853 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); | 853 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); |
854 test_stream->Close(); | 854 test_stream->Close(); |
855 } | 855 } |
856 | 856 |
857 } // namespace media | 857 } // namespace media |
OLD | NEW |