Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: trunk/src/media/audio/win/wavein_input_win.cc

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/media/audio/win/wavein_input_win.h ('k') | trunk/src/media/base/audio_bus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "media/audio/win/audio_manager_win.h" 11 #include "media/audio/win/audio_manager_win.h"
12 #include "media/audio/win/device_enumeration_win.h" 12 #include "media/audio/win/device_enumeration_win.h"
13 #include "media/base/audio_bus.h"
14 13
15 namespace media { 14 namespace media {
16 15
17 // Our sound buffers are allocated once and kept in a linked list using the 16 // Our sound buffers are allocated once and kept in a linked list using the
18 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer. 17 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer.
19 static WAVEHDR* GetNextBuffer(WAVEHDR* current) { 18 static WAVEHDR* GetNextBuffer(WAVEHDR* current) {
20 return reinterpret_cast<WAVEHDR*>(current->dwUser); 19 return reinterpret_cast<WAVEHDR*>(current->dwUser);
21 } 20 }
22 21
23 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( 22 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream(
24 AudioManagerWin* manager, 23 AudioManagerWin* manager, const AudioParameters& params, int num_buffers,
25 const AudioParameters& params,
26 int num_buffers,
27 const std::string& device_id) 24 const std::string& device_id)
28 : state_(kStateEmpty), 25 : state_(kStateEmpty),
29 manager_(manager), 26 manager_(manager),
30 device_id_(device_id), 27 device_id_(device_id),
31 wavein_(NULL), 28 wavein_(NULL),
32 callback_(NULL), 29 callback_(NULL),
33 num_buffers_(num_buffers), 30 num_buffers_(num_buffers),
34 buffer_(NULL), 31 buffer_(NULL),
35 channels_(params.channels()), 32 channels_(params.channels()) {
36 audio_bus_(media::AudioBus::Create(params)) {
37 DCHECK_GT(num_buffers_, 0); 33 DCHECK_GT(num_buffers_, 0);
38 format_.wFormatTag = WAVE_FORMAT_PCM; 34 format_.wFormatTag = WAVE_FORMAT_PCM;
39 format_.nChannels = params.channels() > 2 ? 2 : params.channels(); 35 format_.nChannels = params.channels() > 2 ? 2 : params.channels();
40 format_.nSamplesPerSec = params.sample_rate(); 36 format_.nSamplesPerSec = params.sample_rate();
41 format_.wBitsPerSample = params.bits_per_sample(); 37 format_.wBitsPerSample = params.bits_per_sample();
42 format_.cbSize = 0; 38 format_.cbSize = 0;
43 format_.nBlockAlign = (format_.nChannels * format_.wBitsPerSample) / 8; 39 format_.nBlockAlign = (format_.nChannels * format_.wBitsPerSample) / 8;
44 format_.nAvgBytesPerSec = format_.nBlockAlign * format_.nSamplesPerSec; 40 format_.nAvgBytesPerSec = format_.nBlockAlign * format_.nSamplesPerSec;
45 buffer_size_ = params.frames_per_buffer() * format_.nBlockAlign; 41 buffer_size_ = params.frames_per_buffer() * format_.nBlockAlign;
46 // If we don't have a packet size we use 100ms. 42 // If we don't have a packet size we use 100ms.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (msg == WIM_DATA) { 283 if (msg == WIM_DATA) {
288 // The WIM_DATA message is sent when waveform-audio data is present in 284 // The WIM_DATA message is sent when waveform-audio data is present in
289 // the input buffer and the buffer is being returned to the application. 285 // the input buffer and the buffer is being returned to the application.
290 // The message can be sent when the buffer is full or after the 286 // The message can be sent when the buffer is full or after the
291 // waveInReset function is called. 287 // waveInReset function is called.
292 if (obj->callback_) { 288 if (obj->callback_) {
293 // TODO(henrika): the |volume| parameter is always set to zero since 289 // TODO(henrika): the |volume| parameter is always set to zero since
294 // there is currently no support for controlling the microphone volume 290 // there is currently no support for controlling the microphone volume
295 // level. 291 // level.
296 WAVEHDR* buffer = reinterpret_cast<WAVEHDR*>(param1); 292 WAVEHDR* buffer = reinterpret_cast<WAVEHDR*>(param1);
297 obj->audio_bus_->FromInterleaved(reinterpret_cast<uint8*>(buffer->lpData), 293 obj->callback_->OnData(obj,
298 obj->audio_bus_->frames(), 294 reinterpret_cast<const uint8*>(buffer->lpData),
299 obj->format_.wBitsPerSample / 8); 295 buffer->dwBytesRecorded,
300 obj->callback_->OnData( 296 buffer->dwBytesRecorded,
301 obj, obj->audio_bus_.get(), buffer->dwBytesRecorded, 0.0); 297 0.0);
302 298
303 // Queue the finished buffer back with the audio driver. Since we are 299 // Queue the finished buffer back with the audio driver. Since we are
304 // reusing the same buffers we can get away without calling 300 // reusing the same buffers we can get away without calling
305 // waveInPrepareHeader. 301 // waveInPrepareHeader.
306 obj->QueueNextPacket(buffer); 302 obj->QueueNextPacket(buffer);
307 } else { 303 } else {
308 // Main thread has called Stop() and set |callback_| to NULL and is 304 // Main thread has called Stop() and set |callback_| to NULL and is
309 // now waiting to issue waveInReset which will kill this thread. 305 // now waiting to issue waveInReset which will kill this thread.
310 // We should not call AudioSourceCallback code anymore. 306 // We should not call AudioSourceCallback code anymore.
311 ::SetEvent(obj->stopped_event_); 307 ::SetEvent(obj->stopped_event_);
312 } 308 }
313 } else if (msg == WIM_CLOSE) { 309 } else if (msg == WIM_CLOSE) {
314 // Intentionaly no-op for now. 310 // Intentionaly no-op for now.
315 } else if (msg == WIM_OPEN) { 311 } else if (msg == WIM_OPEN) {
316 // Intentionaly no-op for now. 312 // Intentionaly no-op for now.
317 } 313 }
318 } 314 }
319 315
320 } // namespace media 316 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/media/audio/win/wavein_input_win.h ('k') | trunk/src/media/base/audio_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698