#include "media/audio/audio_io.h"
#include "media/audio/win/audio_manager_win.h"
#include "media/audio/win/device_enumeration_win.h"
+#include "media/base/audio_bus.h"
namespace media {
}
PCMWaveInAudioInputStream::PCMWaveInAudioInputStream(
- AudioManagerWin* manager, const AudioParameters& params, int num_buffers,
+ AudioManagerWin* manager,
+ const AudioParameters& params,
+ int num_buffers,
const std::string& device_id)
: state_(kStateEmpty),
manager_(manager),
callback_(NULL),
num_buffers_(num_buffers),
buffer_(NULL),
- channels_(params.channels()) {
+ channels_(params.channels()),
+ audio_bus_(media::AudioBus::Create(params)) {
DCHECK_GT(num_buffers_, 0);
format_.wFormatTag = WAVE_FORMAT_PCM;
format_.nChannels = params.channels() > 2 ? 2 : params.channels();
return;
// Wait for the callback to finish, it will signal us when ready to be reset.
- DWORD wait = ::WaitForSingleObject(stopped_event_, INFINITE);
+ DWORD wait = ::WaitForSingleObject(stopped_event_.Get(), INFINITE);
DCHECK_EQ(wait, WAIT_OBJECT_0);
// Stop input and reset the current position to zero for |wavein_|.
void PCMWaveInAudioInputStream::HandleError(MMRESULT error) {
DLOG(WARNING) << "PCMWaveInAudio error " << error;
- callback_->OnError(this);
+ if (callback_)
+ callback_->OnError(this);
}
void PCMWaveInAudioInputStream::QueueNextPacket(WAVEHDR *buffer) {
// there is currently no support for controlling the microphone volume
// level.
WAVEHDR* buffer = reinterpret_cast<WAVEHDR*>(param1);
- obj->callback_->OnData(obj,
- reinterpret_cast<const uint8*>(buffer->lpData),
- buffer->dwBytesRecorded,
- buffer->dwBytesRecorded,
- 0.0);
+ obj->audio_bus_->FromInterleaved(reinterpret_cast<uint8*>(buffer->lpData),
+ obj->audio_bus_->frames(),
+ obj->format_.wBitsPerSample / 8);
+ obj->callback_->OnData(
+ obj, obj->audio_bus_.get(), buffer->dwBytesRecorded, 0.0);
// Queue the finished buffer back with the audio driver. Since we are
// reusing the same buffers we can get away without calling
// Main thread has called Stop() and set |callback_| to NULL and is
// now waiting to issue waveInReset which will kill this thread.
// We should not call AudioSourceCallback code anymore.
- ::SetEvent(obj->stopped_event_);
+ ::SetEvent(obj->stopped_event_.Get());
}
} else if (msg == WIM_CLOSE) {
// Intentionaly no-op for now.