| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/sync_socket.h" | 12 #include "base/sync_socket.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
| 15 #include "media/audio/simple_sources.h" | 15 #include "media/audio/simple_sources.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using ::testing::_; | 19 using ::testing::_; |
| 20 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
| 21 using ::testing::DoAll; | 21 using ::testing::DoAll; |
| 22 using ::testing::Field; | 22 using ::testing::Field; |
| 23 using ::testing::InSequence; | 23 using ::testing::InSequence; |
| 24 using ::testing::NiceMock; | 24 using ::testing::NiceMock; |
| 25 using ::testing::NotNull; | 25 using ::testing::NotNull; |
| 26 using ::testing::Return; | 26 using ::testing::Return; |
| 27 | 27 |
| 28 namespace { | 28 static const wchar_t kAudioFile1_16b_m_16K[] |
| 29 | |
| 30 const wchar_t kAudioFile1_16b_m_16K[] | |
| 31 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; | 29 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; |
| 32 | 30 |
| 33 // This class allows to find out if the callbacks are occurring as | 31 // This class allows to find out if the callbacks are occurring as |
| 34 // expected and if any error has been reported. | 32 // expected and if any error has been reported. |
| 35 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { | 33 class TestSourceBasic : public AudioOutputStream::AudioSourceCallback { |
| 36 public: | 34 public: |
| 37 explicit TestSourceBasic() | 35 explicit TestSourceBasic() |
| 38 : callback_count_(0), | 36 : callback_count_(0), |
| 39 had_error_(0) { | 37 had_error_(0) { |
| 40 } | 38 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 62 | 60 |
| 63 void set_error(bool error) { | 61 void set_error(bool error) { |
| 64 had_error_ += error ? 1 : 0; | 62 had_error_ += error ? 1 : 0; |
| 65 } | 63 } |
| 66 | 64 |
| 67 private: | 65 private: |
| 68 int callback_count_; | 66 int callback_count_; |
| 69 int had_error_; | 67 int had_error_; |
| 70 }; | 68 }; |
| 71 | 69 |
| 72 bool IsRunningHeadless() { | 70 static bool IsRunningHeadless() { |
| 73 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0)); | 71 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0)); |
| 74 } | 72 } |
| 75 | 73 |
| 76 } // namespace. | |
| 77 | |
| 78 const int kNumBuffers = 3; | 74 const int kNumBuffers = 3; |
| 79 // Specializes TestSourceBasic to detect that the AudioStream is using | 75 // Specializes TestSourceBasic to detect that the AudioStream is using |
| 80 // triple buffering correctly. | 76 // triple buffering correctly. |
| 81 class TestSourceTripleBuffer : public TestSourceBasic { | 77 class TestSourceTripleBuffer : public TestSourceBasic { |
| 82 public: | 78 public: |
| 83 TestSourceTripleBuffer() { | 79 TestSourceTripleBuffer() { |
| 84 buffer_address_[0] = NULL; | 80 buffer_address_[0] = NULL; |
| 85 buffer_address_[1] = NULL; | 81 buffer_address_[1] = NULL; |
| 86 buffer_address_[2] = NULL; | 82 buffer_address_[2] = NULL; |
| 87 } | 83 } |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 Field(&AudioBuffersState::pending_bytes, 0))) | 607 Field(&AudioBuffersState::pending_bytes, 0))) |
| 612 .Times(AnyNumber()) | 608 .Times(AnyNumber()) |
| 613 .WillRepeatedly(Return(0)); | 609 .WillRepeatedly(Return(0)); |
| 614 | 610 |
| 615 oas->Start(&source); | 611 oas->Start(&source); |
| 616 ::Sleep(500); | 612 ::Sleep(500); |
| 617 oas->Stop(); | 613 oas->Stop(); |
| 618 oas->Close(); | 614 oas->Close(); |
| 619 } | 615 } |
| 620 | 616 |
| 621 namespace { | |
| 622 // Simple source that uses a SyncSocket to retrieve the audio data | 617 // Simple source that uses a SyncSocket to retrieve the audio data |
| 623 // from a potentially remote thread. | 618 // from a potentially remote thread. |
| 624 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { | 619 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { |
| 625 public: | 620 public: |
| 626 explicit SyncSocketSource(base::SyncSocket* socket) | 621 explicit SyncSocketSource(base::SyncSocket* socket) |
| 627 : socket_(socket) {} | 622 : socket_(socket) {} |
| 628 | 623 |
| 629 ~SyncSocketSource() { | 624 ~SyncSocketSource() { |
| 630 delete socket_; | 625 delete socket_; |
| 631 } | 626 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 break; | 671 break; |
| 677 if ((times > 0) && (buffers_state.pending_bytes < 1000)) __debugbreak(); | 672 if ((times > 0) && (buffers_state.pending_bytes < 1000)) __debugbreak(); |
| 678 ctx.socket->Send(&buffer[ix], ctx.packet_size); | 673 ctx.socket->Send(&buffer[ix], ctx.packet_size); |
| 679 ++times; | 674 ++times; |
| 680 } | 675 } |
| 681 | 676 |
| 682 delete buffer; | 677 delete buffer; |
| 683 return 0; | 678 return 0; |
| 684 } | 679 } |
| 685 | 680 |
| 686 } // namespace | |
| 687 | |
| 688 // Test the basic operation of AudioOutputStream used with a SyncSocket. | 681 // Test the basic operation of AudioOutputStream used with a SyncSocket. |
| 689 // The emphasis is to test low-latency with buffers less than 100ms. With | 682 // The emphasis is to test low-latency with buffers less than 100ms. With |
| 690 // the waveout api it seems not possible to go below 50ms. In this test | 683 // the waveout api it seems not possible to go below 50ms. In this test |
| 691 // you should hear a continous 200Hz tone. | 684 // you should hear a continous 200Hz tone. |
| 692 // | 685 // |
| 693 // TODO(cpu): This actually sounds choppy most of the time. Fix it. | 686 // TODO(cpu): This actually sounds choppy most of the time. Fix it. |
| 694 TEST(WinAudioTest, SyncSocketBasic) { | 687 TEST(WinAudioTest, SyncSocketBasic) { |
| 695 if (IsRunningHeadless()) | 688 if (IsRunningHeadless()) |
| 696 return; | 689 return; |
| 697 | 690 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 726 | 719 |
| 727 oas->Start(&source); | 720 oas->Start(&source); |
| 728 | 721 |
| 729 ::WaitForSingleObject(thread, INFINITE); | 722 ::WaitForSingleObject(thread, INFINITE); |
| 730 ::CloseHandle(thread); | 723 ::CloseHandle(thread); |
| 731 delete sockets[1]; | 724 delete sockets[1]; |
| 732 | 725 |
| 733 oas->Stop(); | 726 oas->Stop(); |
| 734 oas->Close(); | 727 oas->Close(); |
| 735 } | 728 } |
| OLD | NEW |