Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / audio / win / wavein_input_win.cc
index 0577125..e96a877 100644 (file)
@@ -10,6 +10,7 @@
 #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 {
 
@@ -20,7 +21,9 @@ static WAVEHDR* GetNextBuffer(WAVEHDR* current) {
 }
 
 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),
@@ -29,7 +32,8 @@ PCMWaveInAudioInputStream::PCMWaveInAudioInputStream(
       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();
@@ -158,7 +162,7 @@ void PCMWaveInAudioInputStream::Stop() {
     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_|.
@@ -224,7 +228,8 @@ bool PCMWaveInAudioInputStream::GetAutomaticGainControl() {
 
 void PCMWaveInAudioInputStream::HandleError(MMRESULT error) {
   DLOG(WARNING) << "PCMWaveInAudio error " << error;
-  callback_->OnError(this);
+  if (callback_)
+    callback_->OnError(this);
 }
 
 void PCMWaveInAudioInputStream::QueueNextPacket(WAVEHDR *buffer) {
@@ -289,11 +294,11 @@ void PCMWaveInAudioInputStream::WaveCallback(HWAVEIN hwi, UINT msg,
       // 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
@@ -303,7 +308,7 @@ void PCMWaveInAudioInputStream::WaveCallback(HWAVEIN hwi, UINT msg,
       // 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.