OLD | NEW |
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 "media/audio/win/wavein_input_win.h" | 5 #include "media/audio/win/wavein_input_win.h" |
6 | 6 |
7 #pragma comment(lib, "winmm.lib") | 7 #pragma comment(lib, "winmm.lib") |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 SetupBuffers(); | 80 SetupBuffers(); |
81 state_ = kStateReady; | 81 state_ = kStateReady; |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void PCMWaveInAudioInputStream::SetupBuffers() { | 85 void PCMWaveInAudioInputStream::SetupBuffers() { |
86 WAVEHDR* last = NULL; | 86 WAVEHDR* last = NULL; |
87 WAVEHDR* first = NULL; | 87 WAVEHDR* first = NULL; |
88 for (int ix = 0; ix != num_buffers_; ++ix) { | 88 for (int ix = 0; ix != num_buffers_; ++ix) { |
89 uint32 sz = sizeof(WAVEHDR) + buffer_size_; | 89 uint32_t sz = sizeof(WAVEHDR) + buffer_size_; |
90 buffer_ = reinterpret_cast<WAVEHDR*>(new char[sz]); | 90 buffer_ = reinterpret_cast<WAVEHDR*>(new char[sz]); |
91 buffer_->lpData = reinterpret_cast<char*>(buffer_) + sizeof(WAVEHDR); | 91 buffer_->lpData = reinterpret_cast<char*>(buffer_) + sizeof(WAVEHDR); |
92 buffer_->dwBufferLength = buffer_size_; | 92 buffer_->dwBufferLength = buffer_size_; |
93 buffer_->dwBytesRecorded = 0; | 93 buffer_->dwBytesRecorded = 0; |
94 buffer_->dwUser = reinterpret_cast<DWORD_PTR>(last); | 94 buffer_->dwUser = reinterpret_cast<DWORD_PTR>(last); |
95 buffer_->dwFlags = WHDR_DONE; | 95 buffer_->dwFlags = WHDR_DONE; |
96 buffer_->dwLoops = 0; | 96 buffer_->dwLoops = 0; |
97 if (ix == 0) | 97 if (ix == 0) |
98 first = buffer_; | 98 first = buffer_; |
99 last = buffer_; | 99 last = buffer_; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 if (msg == WIM_DATA) { | 293 if (msg == WIM_DATA) { |
294 // The WIM_DATA message is sent when waveform-audio data is present in | 294 // The WIM_DATA message is sent when waveform-audio data is present in |
295 // the input buffer and the buffer is being returned to the application. | 295 // the input buffer and the buffer is being returned to the application. |
296 // The message can be sent when the buffer is full or after the | 296 // The message can be sent when the buffer is full or after the |
297 // waveInReset function is called. | 297 // waveInReset function is called. |
298 if (obj->callback_) { | 298 if (obj->callback_) { |
299 // TODO(henrika): the |volume| parameter is always set to zero since | 299 // TODO(henrika): the |volume| parameter is always set to zero since |
300 // there is currently no support for controlling the microphone volume | 300 // there is currently no support for controlling the microphone volume |
301 // level. | 301 // level. |
302 WAVEHDR* buffer = reinterpret_cast<WAVEHDR*>(param1); | 302 WAVEHDR* buffer = reinterpret_cast<WAVEHDR*>(param1); |
303 obj->audio_bus_->FromInterleaved(reinterpret_cast<uint8*>(buffer->lpData), | 303 obj->audio_bus_->FromInterleaved( |
304 obj->audio_bus_->frames(), | 304 reinterpret_cast<uint8_t*>(buffer->lpData), obj->audio_bus_->frames(), |
305 obj->format_.wBitsPerSample / 8); | 305 obj->format_.wBitsPerSample / 8); |
306 obj->callback_->OnData( | 306 obj->callback_->OnData( |
307 obj, obj->audio_bus_.get(), buffer->dwBytesRecorded, 0.0); | 307 obj, obj->audio_bus_.get(), buffer->dwBytesRecorded, 0.0); |
308 | 308 |
309 // Queue the finished buffer back with the audio driver. Since we are | 309 // Queue the finished buffer back with the audio driver. Since we are |
310 // reusing the same buffers we can get away without calling | 310 // reusing the same buffers we can get away without calling |
311 // waveInPrepareHeader. | 311 // waveInPrepareHeader. |
312 obj->QueueNextPacket(buffer); | 312 obj->QueueNextPacket(buffer); |
313 } else { | 313 } else { |
314 // Main thread has called Stop() and set |callback_| to NULL and is | 314 // Main thread has called Stop() and set |callback_| to NULL and is |
315 // now waiting to issue waveInReset which will kill this thread. | 315 // now waiting to issue waveInReset which will kill this thread. |
316 // We should not call AudioSourceCallback code anymore. | 316 // We should not call AudioSourceCallback code anymore. |
317 ::SetEvent(obj->stopped_event_.Get()); | 317 ::SetEvent(obj->stopped_event_.Get()); |
318 } | 318 } |
319 } else if (msg == WIM_CLOSE) { | 319 } else if (msg == WIM_CLOSE) { |
320 // Intentionaly no-op for now. | 320 // Intentionaly no-op for now. |
321 } else if (msg == WIM_OPEN) { | 321 } else if (msg == WIM_OPEN) { |
322 // Intentionaly no-op for now. | 322 // Intentionaly no-op for now. |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 } // namespace media | 326 } // namespace media |
OLD | NEW |