Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: media/audio/win/audio_output_win_unittest.cc

Issue 8965053: Implement support for a cancelable SyncSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using a single event for file operations on Windows. Some comment improvements. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
OLDNEW
« base/sync_socket_posix.cc ('K') | « media/audio/win/audio_low_latency_output_win_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698