| 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "media/audio/linux/alsa_output.h" | 7 #include "media/audio/linux/alsa_output.h" |
| 8 #include "media/audio/linux/alsa_wrapper.h" | 8 #include "media/audio/linux/alsa_wrapper.h" |
| 9 #include "media/audio/linux/audio_manager_linux.h" | 9 #include "media/audio/linux/audio_manager_linux.h" |
| 10 #include "media/base/data_buffer.h" | 10 #include "media/base/data_buffer.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // Helper function to malloc the string returned by DeviceNameHint for IOID. | 135 // Helper function to malloc the string returned by DeviceNameHint for IOID. |
| 136 static char* OutputHint(Unused, Unused) { | 136 static char* OutputHint(Unused, Unused) { |
| 137 return strdup("Output"); | 137 return strdup("Output"); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Helper function to initialize |test_stream->buffer_|. Must be called | 140 // Helper function to initialize |test_stream->buffer_|. Must be called |
| 141 // in all tests that use buffer_ without opening the stream. | 141 // in all tests that use buffer_ without opening the stream. |
| 142 void InitBuffer(AlsaPcmOutputStream* test_stream) { | 142 void InitBuffer(AlsaPcmOutputStream* test_stream) { |
| 143 DCHECK(test_stream); | 143 DCHECK(test_stream); |
| 144 packet_ = new media::DataBuffer(kTestPacketSize); | 144 packet_ = new media::DataBuffer(kTestPacketSize); |
| 145 packet_->SetDataSize(kTestPacketSize); | 145 packet_->set_data_size(kTestPacketSize); |
| 146 test_stream->buffer_.reset(new media::SeekableBuffer(0, kTestPacketSize)); | 146 test_stream->buffer_.reset(new media::SeekableBuffer(0, kTestPacketSize)); |
| 147 test_stream->buffer_->Append(packet_.get()); | 147 test_stream->buffer_->Append(packet_.get()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 static const ChannelLayout kTestChannelLayout; | 150 static const ChannelLayout kTestChannelLayout; |
| 151 static const int kTestSampleRate; | 151 static const int kTestSampleRate; |
| 152 static const int kTestBitsPerSample; | 152 static const int kTestBitsPerSample; |
| 153 static const int kTestBytesPerFrame; | 153 static const int kTestBytesPerFrame; |
| 154 static const AudioParameters::Format kTestFormat; | 154 static const AudioParameters::Format kTestFormat; |
| 155 static const char kTestDeviceName[]; | 155 static const char kTestDeviceName[]; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _)) | 484 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _)) |
| 485 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket), | 485 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket), |
| 486 SetArgumentPointee<2>(kTestFramesPerPacket / 2), | 486 SetArgumentPointee<2>(kTestFramesPerPacket / 2), |
| 487 Return(0))); | 487 Return(0))); |
| 488 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); | 488 AlsaPcmOutputStream* test_stream = CreateStream(kTestChannelLayout); |
| 489 ASSERT_TRUE(test_stream->Open()); | 489 ASSERT_TRUE(test_stream->Open()); |
| 490 InitBuffer(test_stream); | 490 InitBuffer(test_stream); |
| 491 test_stream->TransitionTo(AlsaPcmOutputStream::kIsPlaying); | 491 test_stream->TransitionTo(AlsaPcmOutputStream::kIsPlaying); |
| 492 | 492 |
| 493 // Write a little less than half the data. | 493 // Write a little less than half the data. |
| 494 int written = packet_->GetDataSize() / kTestBytesPerFrame / 2 - 1; | 494 int written = packet_->data_size() / kTestBytesPerFrame / 2 - 1; |
| 495 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 495 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
| 496 .WillOnce(Return(written)); | 496 .WillOnce(Return(written)); |
| 497 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, packet_->GetData(), _)) | 497 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, packet_->data(), _)) |
| 498 .WillOnce(Return(written)); | 498 .WillOnce(Return(written)); |
| 499 | 499 |
| 500 test_stream->WritePacket(); | 500 test_stream->WritePacket(); |
| 501 | 501 |
| 502 ASSERT_EQ(test_stream->buffer_->forward_bytes(), | 502 ASSERT_EQ(test_stream->buffer_->forward_bytes(), |
| 503 packet_->GetDataSize() - written * kTestBytesPerFrame); | 503 packet_->data_size() - written * kTestBytesPerFrame); |
| 504 | 504 |
| 505 // Write the rest. | 505 // Write the rest. |
| 506 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 506 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
| 507 .WillOnce(Return(kTestFramesPerPacket - written)); | 507 .WillOnce(Return(kTestFramesPerPacket - written)); |
| 508 EXPECT_CALL(mock_alsa_wrapper_, | 508 EXPECT_CALL(mock_alsa_wrapper_, |
| 509 PcmWritei(kFakeHandle, | 509 PcmWritei(kFakeHandle, |
| 510 packet_->GetData() + written * kTestBytesPerFrame, | 510 packet_->data() + written * kTestBytesPerFrame, |
| 511 _)) | 511 _)) |
| 512 .WillOnce(Return(packet_->GetDataSize() / kTestBytesPerFrame - written)); | 512 .WillOnce(Return(packet_->data_size() / kTestBytesPerFrame - written)); |
| 513 test_stream->WritePacket(); | 513 test_stream->WritePacket(); |
| 514 EXPECT_EQ(0, test_stream->buffer_->forward_bytes()); | 514 EXPECT_EQ(0, test_stream->buffer_->forward_bytes()); |
| 515 | 515 |
| 516 // Now close it and test that everything was released. | 516 // Now close it and test that everything was released. |
| 517 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) | 517 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) |
| 518 .WillOnce(Return(0)); | 518 .WillOnce(Return(0)); |
| 519 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) | 519 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) |
| 520 .WillOnce(Return(kTestDeviceName)); | 520 .WillOnce(Return(kTestDeviceName)); |
| 521 test_stream->Close(); | 521 test_stream->Close(); |
| 522 } | 522 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 541 // continues normally. | 541 // continues normally. |
| 542 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 542 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
| 543 .WillOnce(Return(kTestFramesPerPacket)); | 543 .WillOnce(Return(kTestFramesPerPacket)); |
| 544 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) | 544 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) |
| 545 .WillOnce(Return(-EINTR)); | 545 .WillOnce(Return(-EINTR)); |
| 546 EXPECT_CALL(mock_alsa_wrapper_, PcmRecover(kFakeHandle, _, _)) | 546 EXPECT_CALL(mock_alsa_wrapper_, PcmRecover(kFakeHandle, _, _)) |
| 547 .WillOnce(Return(0)); | 547 .WillOnce(Return(0)); |
| 548 | 548 |
| 549 test_stream->WritePacket(); | 549 test_stream->WritePacket(); |
| 550 | 550 |
| 551 ASSERT_EQ(test_stream->buffer_->forward_bytes(), packet_->GetDataSize()); | 551 ASSERT_EQ(test_stream->buffer_->forward_bytes(), packet_->data_size()); |
| 552 | 552 |
| 553 // Fail the next write, and see that stop_stream_ is set. | 553 // Fail the next write, and see that stop_stream_ is set. |
| 554 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) | 554 EXPECT_CALL(mock_alsa_wrapper_, PcmAvailUpdate(kFakeHandle)) |
| 555 .WillOnce(Return(kTestFramesPerPacket)); | 555 .WillOnce(Return(kTestFramesPerPacket)); |
| 556 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) | 556 EXPECT_CALL(mock_alsa_wrapper_, PcmWritei(kFakeHandle, _, _)) |
| 557 .WillOnce(Return(kTestFailedErrno)); | 557 .WillOnce(Return(kTestFailedErrno)); |
| 558 EXPECT_CALL(mock_alsa_wrapper_, PcmRecover(kFakeHandle, _, _)) | 558 EXPECT_CALL(mock_alsa_wrapper_, PcmRecover(kFakeHandle, _, _)) |
| 559 .WillOnce(Return(kTestFailedErrno)); | 559 .WillOnce(Return(kTestFailedErrno)); |
| 560 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) | 560 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) |
| 561 .WillOnce(Return(kDummyMessage)); | 561 .WillOnce(Return(kDummyMessage)); |
| 562 test_stream->WritePacket(); | 562 test_stream->WritePacket(); |
| 563 EXPECT_EQ(test_stream->buffer_->forward_bytes(), packet_->GetDataSize()); | 563 EXPECT_EQ(test_stream->buffer_->forward_bytes(), packet_->data_size()); |
| 564 EXPECT_TRUE(test_stream->stop_stream_); | 564 EXPECT_TRUE(test_stream->stop_stream_); |
| 565 | 565 |
| 566 // Now close it and test that everything was released. | 566 // Now close it and test that everything was released. |
| 567 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) | 567 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) |
| 568 .WillOnce(Return(0)); | 568 .WillOnce(Return(0)); |
| 569 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) | 569 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) |
| 570 .WillOnce(Return(kTestDeviceName)); | 570 .WillOnce(Return(kTestDeviceName)); |
| 571 test_stream->Close(); | 571 test_stream->Close(); |
| 572 } | 572 } |
| 573 | 573 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 859 |
| 860 // TODO(ajwong): Find a way to test whether or not another task has been | 860 // TODO(ajwong): Find a way to test whether or not another task has been |
| 861 // posted so we can verify that the Alsa code will indeed break the task | 861 // posted so we can verify that the Alsa code will indeed break the task |
| 862 // posting loop. | 862 // posting loop. |
| 863 | 863 |
| 864 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); | 864 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); |
| 865 test_stream->Close(); | 865 test_stream->Close(); |
| 866 } | 866 } |
| 867 | 867 |
| 868 } // namespace media | 868 } // namespace media |
| OLD | NEW |