| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |