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

Side by Side Diff: media/audio/audio_output_device_unittest.cc

Issue 525313002: SyncSocket Transit Descriptor - refactoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits done - Prelanding checks Created 6 years, 3 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
« no previous file with comments | « content/renderer/media/audio_message_filter_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 <vector> 5 #include <vector>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 MOCK_METHOD3(CreateStream, void(AudioOutputIPCDelegate* delegate, 48 MOCK_METHOD3(CreateStream, void(AudioOutputIPCDelegate* delegate,
49 const AudioParameters& params, 49 const AudioParameters& params,
50 int session_id)); 50 int session_id));
51 MOCK_METHOD0(PlayStream, void()); 51 MOCK_METHOD0(PlayStream, void());
52 MOCK_METHOD0(PauseStream, void()); 52 MOCK_METHOD0(PauseStream, void());
53 MOCK_METHOD0(CloseStream, void()); 53 MOCK_METHOD0(CloseStream, void());
54 MOCK_METHOD1(SetVolume, void(double volume)); 54 MOCK_METHOD1(SetVolume, void(double volume));
55 }; 55 };
56 56
57 // Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice.
58 // On Windows this means duplicating the pipe handle so that AudioOutputDevice
59 // can call CloseHandle() (since ownership has been transferred), but on other
60 // platforms, we just copy the same socket handle since AudioOutputDevice on
61 // those platforms won't actually own the socket (FileDescriptor.auto_close is
62 // false).
63 bool DuplicateSocketHandle(SyncSocket::Handle socket_handle,
64 SyncSocket::Handle* copy) {
65 #if defined(OS_WIN)
66 HANDLE process = GetCurrentProcess();
67 ::DuplicateHandle(process, socket_handle, process, copy,
68 0, FALSE, DUPLICATE_SAME_ACCESS);
69 return *copy != NULL;
70 #else
71 *copy = socket_handle;
72 return *copy != -1;
73 #endif
74 }
75
76 ACTION_P2(SendPendingBytes, socket, pending_bytes) { 57 ACTION_P2(SendPendingBytes, socket, pending_bytes) {
77 socket->Send(&pending_bytes, sizeof(pending_bytes)); 58 socket->Send(&pending_bytes, sizeof(pending_bytes));
78 } 59 }
79 60
80 // Used to terminate a loop from a different thread than the loop belongs to. 61 // Used to terminate a loop from a different thread than the loop belongs to.
81 // |loop| should be a MessageLoopProxy. 62 // |loop| should be a MessageLoopProxy.
82 ACTION_P(QuitLoop, loop) { 63 ACTION_P(QuitLoop, loop) {
83 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 64 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
84 } 65 }
85 66
(...skipping 27 matching lines...) Expand all
113 94
114 SharedMemory shared_memory_; 95 SharedMemory shared_memory_;
115 CancelableSyncSocket browser_socket_; 96 CancelableSyncSocket browser_socket_;
116 CancelableSyncSocket renderer_socket_; 97 CancelableSyncSocket renderer_socket_;
117 98
118 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); 99 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest);
119 }; 100 };
120 101
121 int AudioOutputDeviceTest::CalculateMemorySize() { 102 int AudioOutputDeviceTest::CalculateMemorySize() {
122 // Calculate output memory size. 103 // Calculate output memory size.
123 return AudioBus::CalculateMemorySize(default_audio_parameters_); 104 return AudioBus::CalculateMemorySize(default_audio_parameters_);
124 } 105 }
125 106
126 AudioOutputDeviceTest::AudioOutputDeviceTest() { 107 AudioOutputDeviceTest::AudioOutputDeviceTest() {
127 default_audio_parameters_.Reset( 108 default_audio_parameters_.Reset(
128 AudioParameters::AUDIO_PCM_LINEAR, 109 AudioParameters::AUDIO_PCM_LINEAR,
129 CHANNEL_LAYOUT_STEREO, 2, 48000, 16, 1024); 110 CHANNEL_LAYOUT_STEREO, 2, 48000, 16, 1024);
130 111
131 audio_output_ipc_ = new MockAudioOutputIPC(); 112 audio_output_ipc_ = new MockAudioOutputIPC();
132 audio_device_ = new AudioOutputDevice( 113 audio_device_ = new AudioOutputDevice(
133 scoped_ptr<AudioOutputIPC>(audio_output_ipc_), 114 scoped_ptr<AudioOutputIPC>(audio_output_ipc_),
(...skipping 22 matching lines...) Expand all
156 137
157 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); 138 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize));
158 memset(shared_memory_.memory(), 0xff, kMemorySize); 139 memset(shared_memory_.memory(), 0xff, kMemorySize);
159 140
160 ASSERT_TRUE(CancelableSyncSocket::CreatePair(&browser_socket_, 141 ASSERT_TRUE(CancelableSyncSocket::CreatePair(&browser_socket_,
161 &renderer_socket_)); 142 &renderer_socket_));
162 143
163 // Create duplicates of the handles we pass to AudioOutputDevice since 144 // Create duplicates of the handles we pass to AudioOutputDevice since
164 // ownership will be transferred and AudioOutputDevice is responsible for 145 // ownership will be transferred and AudioOutputDevice is responsible for
165 // freeing. 146 // freeing.
166 SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle; 147 SyncSocket::TransitDescriptor audio_device_socket_descriptor;
167 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(), 148 ASSERT_TRUE(renderer_socket_.PrepareTransitDescriptor(
168 &audio_device_socket)); 149 base::GetCurrentProcessHandle(), &audio_device_socket_descriptor));
169 base::SharedMemoryHandle duplicated_memory_handle; 150 base::SharedMemoryHandle duplicated_memory_handle;
170 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), 151 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(),
171 &duplicated_memory_handle)); 152 &duplicated_memory_handle));
172 153
173 audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket, 154 audio_device_->OnStreamCreated(
174 kMemorySize); 155 duplicated_memory_handle,
156 SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize);
175 io_loop_.RunUntilIdle(); 157 io_loop_.RunUntilIdle();
176 } 158 }
177 159
178 void AudioOutputDeviceTest::ExpectRenderCallback() { 160 void AudioOutputDeviceTest::ExpectRenderCallback() {
179 // We should get a 'play' notification when we call OnStreamCreated(). 161 // We should get a 'play' notification when we call OnStreamCreated().
180 // Respond by asking for some audio data. This should ask our callback 162 // Respond by asking for some audio data. This should ask our callback
181 // to provide some audio data that AudioOutputDevice then writes into the 163 // to provide some audio data that AudioOutputDevice then writes into the
182 // shared memory section. 164 // shared memory section.
183 const int kMemorySize = CalculateMemorySize(); 165 const int kMemorySize = CalculateMemorySize();
184 166
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 StartAudioDevice(); 235 StartAudioDevice();
254 ExpectRenderCallback(); 236 ExpectRenderCallback();
255 CreateStream(); 237 CreateStream();
256 WaitUntilRenderCallback(); 238 WaitUntilRenderCallback();
257 StopAudioDevice(); 239 StopAudioDevice();
258 } 240 }
259 241
260 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 242 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
261 243
262 } // namespace media. 244 } // namespace media.
OLDNEW
« no previous file with comments | « content/renderer/media/audio_message_filter_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698