| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <mmsystem.h> | 8 #include <mmsystem.h> |
| 9 #pragma comment(lib, "winmm.lib") | 9 #pragma comment(lib, "winmm.lib") |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_util.h" | 14 #include "media/audio/audio_util.h" |
| 15 #include "media/audio/win/audio_manager_win.h" | 15 #include "media/audio/win/audio_manager_win.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Our sound buffers are allocated once and kept in a linked list using the | 19 // Our sound buffers are allocated once and kept in a linked list using the |
| 20 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer. | 20 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer. |
| 21 WAVEHDR* GetNextBuffer(WAVEHDR* current) { | 21 WAVEHDR* GetNextBuffer(WAVEHDR* current) { |
| 22 return reinterpret_cast<WAVEHDR*>(current->dwUser); | 22 return reinterpret_cast<WAVEHDR*>(current->dwUser); |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( | 27 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( |
| 28 AudioManagerWin* manager, AudioParameters params, int num_buffers, | 28 AudioManagerWin* manager, AudioParameters params, int num_buffers, |
| 29 uint32 samples_per_packet, UINT device_id) | 29 UINT device_id) |
| 30 : state_(kStateEmpty), | 30 : state_(kStateEmpty), |
| 31 manager_(manager), | 31 manager_(manager), |
| 32 device_id_(device_id), | 32 device_id_(device_id), |
| 33 wavein_(NULL), | 33 wavein_(NULL), |
| 34 callback_(NULL), | 34 callback_(NULL), |
| 35 num_buffers_(num_buffers), | 35 num_buffers_(num_buffers), |
| 36 buffer_(NULL), | 36 buffer_(NULL), |
| 37 channels_(params.channels) { | 37 channels_(params.channels) { |
| 38 format_.wFormatTag = WAVE_FORMAT_PCM; | 38 format_.wFormatTag = WAVE_FORMAT_PCM; |
| 39 format_.nChannels = params.channels > 2 ? 2 : params.channels; | 39 format_.nChannels = params.channels > 2 ? 2 : params.channels; |
| 40 format_.nSamplesPerSec = params.sample_rate; | 40 format_.nSamplesPerSec = params.sample_rate; |
| 41 format_.wBitsPerSample = params.bits_per_sample; | 41 format_.wBitsPerSample = params.bits_per_sample; |
| 42 format_.cbSize = 0; | 42 format_.cbSize = 0; |
| 43 format_.nBlockAlign = (format_.nChannels * format_.wBitsPerSample) / 8; | 43 format_.nBlockAlign = (format_.nChannels * format_.wBitsPerSample) / 8; |
| 44 format_.nAvgBytesPerSec = format_.nBlockAlign * format_.nSamplesPerSec; | 44 format_.nAvgBytesPerSec = format_.nBlockAlign * format_.nSamplesPerSec; |
| 45 buffer_size_ = samples_per_packet * format_.nBlockAlign; | 45 buffer_size_ = params.samples_per_packet * format_.nBlockAlign; |
| 46 // If we don't have a packet size we use 100ms. | 46 // If we don't have a packet size we use 100ms. |
| 47 if (!buffer_size_) | 47 if (!buffer_size_) |
| 48 buffer_size_ = format_.nAvgBytesPerSec / 10; | 48 buffer_size_ = format_.nAvgBytesPerSec / 10; |
| 49 // The event is auto-reset. | 49 // The event is auto-reset. |
| 50 stopped_event_.Set(::CreateEventW(NULL, FALSE, FALSE, NULL)); | 50 stopped_event_.Set(::CreateEventW(NULL, FALSE, FALSE, NULL)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 PCMWaveInAudioInputStream::~PCMWaveInAudioInputStream() { | 53 PCMWaveInAudioInputStream::~PCMWaveInAudioInputStream() { |
| 54 DCHECK(NULL == wavein_); | 54 DCHECK(NULL == wavein_); |
| 55 } | 55 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // waveInPrepareHeader. | 207 // waveInPrepareHeader. |
| 208 obj->QueueNextPacket(buffer); | 208 obj->QueueNextPacket(buffer); |
| 209 } | 209 } |
| 210 } else if (msg == WIM_CLOSE) { | 210 } else if (msg == WIM_CLOSE) { |
| 211 // We can be closed before calling Start, so it is possible to have a | 211 // We can be closed before calling Start, so it is possible to have a |
| 212 // null callback at this point. | 212 // null callback at this point. |
| 213 if (obj->callback_) | 213 if (obj->callback_) |
| 214 obj->callback_->OnClose(obj); | 214 obj->callback_->OnClose(obj); |
| 215 } | 215 } |
| 216 } | 216 } |
| OLD | NEW |