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

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: addressed micro-nit Created 8 years, 10 months 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
« no previous file with comments | « ipc/sync_socket_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } 629 }
630 630
631 // Simple source that uses a SyncSocket to retrieve the audio data 631 // Simple source that uses a SyncSocket to retrieve the audio data
632 // from a potentially remote thread. 632 // from a potentially remote thread.
633 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback { 633 class SyncSocketSource : public AudioOutputStream::AudioSourceCallback {
634 public: 634 public:
635 explicit SyncSocketSource(base::SyncSocket* socket) 635 explicit SyncSocketSource(base::SyncSocket* socket)
636 : socket_(socket) {} 636 : socket_(socket) {}
637 637
638 ~SyncSocketSource() { 638 ~SyncSocketSource() {
639 delete socket_;
640 } 639 }
641 640
642 // AudioSourceCallback::OnMoreData implementation: 641 // AudioSourceCallback::OnMoreData implementation:
643 virtual uint32 OnMoreData(AudioOutputStream* stream, 642 virtual uint32 OnMoreData(AudioOutputStream* stream,
644 uint8* dest, uint32 max_size, 643 uint8* dest, uint32 max_size,
645 AudioBuffersState buffers_state) { 644 AudioBuffersState buffers_state) {
646 socket_->Send(&buffers_state, sizeof(buffers_state)); 645 socket_->Send(&buffers_state, sizeof(buffers_state));
647 uint32 got = socket_->Receive(dest, max_size); 646 uint32 got = socket_->Receive(dest, max_size);
648 return got; 647 return got;
649 } 648 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 708
710 int sample_rate = AudioParameters::kAudioCDSampleRate; 709 int sample_rate = AudioParameters::kAudioCDSampleRate;
711 const uint32 kSamples20ms = sample_rate / 50; 710 const uint32 kSamples20ms = sample_rate / 50;
712 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 711 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
713 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 712 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
714 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); 713 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms));
715 ASSERT_TRUE(NULL != oas); 714 ASSERT_TRUE(NULL != oas);
716 715
717 ASSERT_TRUE(oas->Open()); 716 ASSERT_TRUE(oas->Open());
718 717
719 base::SyncSocket* sockets[2]; 718 base::SyncSocket sockets[2];
720 ASSERT_TRUE(base::SyncSocket::CreatePair(sockets)); 719 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1]));
721 720
722 SyncSocketSource source(sockets[0]); 721 SyncSocketSource source(&sockets[0]);
723 722
724 SyncThreadContext thread_context; 723 SyncThreadContext thread_context;
725 thread_context.sample_rate = sample_rate; 724 thread_context.sample_rate = sample_rate;
726 thread_context.sine_freq = 200.0; 725 thread_context.sine_freq = 200.0;
727 thread_context.packet_size_bytes = kSamples20ms * 2; 726 thread_context.packet_size_bytes = kSamples20ms * 2;
728 thread_context.socket = sockets[1]; 727 thread_context.socket = &sockets[1];
729 728
730 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, 729 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread,
731 &thread_context, 0, NULL); 730 &thread_context, 0, NULL);
732 731
733 oas->Start(&source); 732 oas->Start(&source);
734 733
735 ::WaitForSingleObject(thread, INFINITE); 734 ::WaitForSingleObject(thread, INFINITE);
736 ::CloseHandle(thread); 735 ::CloseHandle(thread);
737 delete sockets[1];
738 736
739 oas->Stop(); 737 oas->Stop();
740 oas->Close(); 738 oas->Close();
741 } 739 }
OLDNEW
« no previous file with comments | « ipc/sync_socket_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698