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

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

Issue 193095: Pause for <video> should have immediate effect on audio (Closed)
Patch Set: style Created 11 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 | « chrome/browser/renderer_host/audio_renderer_host.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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 #pragma comment(lib, "winmm.lib") 7 #pragma comment(lib, "winmm.lib")
8 8
9 #include "media/audio/win/waveout_output_win.h" 9 #include "media/audio/win/waveout_output_win.h"
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 136
137 // Initially we ask the source to fill up both audio buffers. If we don't do 137 // Initially we ask the source to fill up both audio buffers. If we don't do
138 // this then we would always get the driver callback when it is about to run 138 // this then we would always get the driver callback when it is about to run
139 // samples and that would leave too little time to react. 139 // samples and that would leave too little time to react.
140 void PCMWaveOutAudioOutputStream::Start(AudioSourceCallback* callback) { 140 void PCMWaveOutAudioOutputStream::Start(AudioSourceCallback* callback) {
141 if (state_ != PCMA_READY) 141 if (state_ != PCMA_READY)
142 return; 142 return;
143 callback_ = callback; 143 callback_ = callback;
144 state_ = PCMA_PLAYING; 144 state_ = PCMA_PLAYING;
145 pending_bytes_ = 0;
145 WAVEHDR* buffer = buffer_; 146 WAVEHDR* buffer = buffer_;
146 for (int ix = 0; ix != kNumBuffers; ++ix) { 147 for (int ix = 0; ix != kNumBuffers; ++ix) {
147 QueueNextPacket(buffer); // Read more data. 148 QueueNextPacket(buffer); // Read more data.
148 pending_bytes_ += buffer->dwBufferLength; 149 pending_bytes_ += buffer->dwBufferLength;
149 buffer = GetNextBuffer(buffer); 150 buffer = GetNextBuffer(buffer);
150 } 151 }
151 buffer = buffer_; 152 buffer = buffer_;
152 MMRESULT result = ::waveOutPause(waveout_); 153 MMRESULT result = ::waveOutPause(waveout_);
153 if (result != MMSYSERR_NOERROR) { 154 if (result != MMSYSERR_NOERROR) {
154 HandleError(result); 155 HandleError(result);
(...skipping 10 matching lines...) Expand all
165 buffer = GetNextBuffer(buffer); 166 buffer = GetNextBuffer(buffer);
166 } 167 }
167 result = ::waveOutRestart(waveout_); 168 result = ::waveOutRestart(waveout_);
168 if (result != MMSYSERR_NOERROR) { 169 if (result != MMSYSERR_NOERROR) {
169 HandleError(result); 170 HandleError(result);
170 return; 171 return;
171 } 172 }
172 } 173 }
173 174
174 // Stopping is tricky. First, no buffer should be locked by the audio driver 175 // Stopping is tricky. First, no buffer should be locked by the audio driver
175 // or else the waveOutReset will deadlock and secondly, the callback should not 176 // or else the waveOutReset() will deadlock and secondly, the callback should
176 // be inside the AudioSource's OnMoreData because waveOutReset() forcefully 177 // not be inside the AudioSource's OnMoreData because waveOutReset() forcefully
177 // kills the callback thread. 178 // kills the callback thread.
178 void PCMWaveOutAudioOutputStream::Stop() { 179 void PCMWaveOutAudioOutputStream::Stop() {
179 if (state_ != PCMA_PLAYING) 180 if (state_ != PCMA_PLAYING)
180 return; 181 return;
181 state_ = PCMA_STOPPING; 182 state_ = PCMA_STOPPING;
182 // Wait for the callback to finish, it will signal us when ready to be reset. 183 // Wait for the callback to finish, it will signal us when ready to be reset.
183 if (WAIT_OBJECT_0 != ::WaitForSingleObject(stopped_event_, INFINITE)) { 184 if (WAIT_OBJECT_0 != ::WaitForSingleObject(stopped_event_, INFINITE)) {
184 HandleError(::GetLastError()); 185 HandleError(::GetLastError());
185 return; 186 return;
186 } 187 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 303
303 obj->pending_bytes_ += buffer->dwBufferLength; 304 obj->pending_bytes_ += buffer->dwBufferLength;
304 305
305 } else if (msg == WOM_CLOSE) { 306 } else if (msg == WOM_CLOSE) {
306 // We can be closed before calling Start, so it is possible to have a 307 // We can be closed before calling Start, so it is possible to have a
307 // null callback at this point. 308 // null callback at this point.
308 if (obj->callback_) 309 if (obj->callback_)
309 obj->callback_->OnClose(obj); 310 obj->callback_->OnClose(obj);
310 } 311 }
311 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/audio_renderer_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698