| OLD | NEW |
| 1 // Copyright (c) 2011 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" |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 } | 624 } |
| 625 | 625 |
| 626 // Simple source that uses a SyncSocket to retrieve the audio data | 626 // Simple source that uses a SyncSocket to retrieve the audio data |
| 627 // from a potentially remote thread. | 627 // from a potentially remote thread. |
| 628 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { | 628 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { |
| 629 public: | 629 public: |
| 630 explicit SyncSocketSource(base::SyncSocket* socket) | 630 explicit SyncSocketSource(base::SyncSocket* socket) |
| 631 : socket_(socket) {} | 631 : socket_(socket) {} |
| 632 | 632 |
| 633 ~SyncSocketSource() { | 633 ~SyncSocketSource() { |
| 634 delete socket_; | |
| 635 } | 634 } |
| 636 | 635 |
| 637 // AudioSourceCallback::OnMoreData implementation: | 636 // AudioSourceCallback::OnMoreData implementation: |
| 638 virtual uint32 OnMoreData(AudioOutputStream* stream, | 637 virtual uint32 OnMoreData(AudioOutputStream* stream, |
| 639 uint8* dest, uint32 max_size, | 638 uint8* dest, uint32 max_size, |
| 640 AudioBuffersState buffers_state) { | 639 AudioBuffersState buffers_state) { |
| 641 socket_->Send(&buffers_state, sizeof(buffers_state)); | 640 socket_->Send(&buffers_state, sizeof(buffers_state)); |
| 642 uint32 got = socket_->Receive(dest, max_size); | 641 uint32 got = socket_->Receive(dest, max_size); |
| 643 return got; | 642 return got; |
| 644 } | 643 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 704 |
| 706 int sample_rate = AudioParameters::kAudioCDSampleRate; | 705 int sample_rate = AudioParameters::kAudioCDSampleRate; |
| 707 const uint32 kSamples20ms = sample_rate / 50; | 706 const uint32 kSamples20ms = sample_rate / 50; |
| 708 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 707 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 709 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 708 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, |
| 710 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); | 709 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); |
| 711 ASSERT_TRUE(NULL != oas); | 710 ASSERT_TRUE(NULL != oas); |
| 712 | 711 |
| 713 ASSERT_TRUE(oas->Open()); | 712 ASSERT_TRUE(oas->Open()); |
| 714 | 713 |
| 715 base::SyncSocket* sockets[2]; | 714 base::SyncSocket sockets[2]; |
| 716 ASSERT_TRUE(base::SyncSocket::CreatePair(sockets)); | 715 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); |
| 717 | 716 |
| 718 SyncSocketSource source(sockets[0]); | 717 SyncSocketSource source(&sockets[0]); |
| 719 | 718 |
| 720 SyncThreadContext thread_context; | 719 SyncThreadContext thread_context; |
| 721 thread_context.sample_rate = sample_rate; | 720 thread_context.sample_rate = sample_rate; |
| 722 thread_context.sine_freq = 200.0; | 721 thread_context.sine_freq = 200.0; |
| 723 thread_context.packet_size_bytes = kSamples20ms * 2; | 722 thread_context.packet_size_bytes = kSamples20ms * 2; |
| 724 thread_context.socket = sockets[1]; | 723 thread_context.socket = &sockets[1]; |
| 725 | 724 |
| 726 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, | 725 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, |
| 727 &thread_context, 0, NULL); | 726 &thread_context, 0, NULL); |
| 728 | 727 |
| 729 oas->Start(&source); | 728 oas->Start(&source); |
| 730 | 729 |
| 731 ::WaitForSingleObject(thread, INFINITE); | 730 ::WaitForSingleObject(thread, INFINITE); |
| 732 ::CloseHandle(thread); | 731 ::CloseHandle(thread); |
| 733 delete sockets[1]; | |
| 734 | 732 |
| 735 oas->Stop(); | 733 oas->Stop(); |
| 736 oas->Close(); | 734 oas->Close(); |
| 737 } | 735 } |
| OLD | NEW |