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

Side by Side Diff: media/audio/win/waveout_output_win.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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 | « media/audio/win/waveout_output_win.h ('k') | 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/waveout_output_win.h" 5 #include "media/audio/win/waveout_output_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
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 : state_(PCMA_BRAND_NEW), 83 : state_(PCMA_BRAND_NEW),
84 manager_(manager), 84 manager_(manager),
85 device_id_(device_id), 85 device_id_(device_id),
86 waveout_(NULL), 86 waveout_(NULL),
87 callback_(NULL), 87 callback_(NULL),
88 num_buffers_(num_buffers), 88 num_buffers_(num_buffers),
89 buffer_size_(params.GetBytesPerBuffer()), 89 buffer_size_(params.GetBytesPerBuffer()),
90 volume_(1), 90 volume_(1),
91 channels_(params.channels()), 91 channels_(params.channels()),
92 pending_bytes_(0), 92 pending_bytes_(0),
93 waiting_handle_(NULL) { 93 waiting_handle_(NULL),
94 audio_bus_(AudioBus::Create(params)) {
94 format_.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; 95 format_.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
95 format_.Format.nChannels = params.channels(); 96 format_.Format.nChannels = params.channels();
96 format_.Format.nSamplesPerSec = params.sample_rate(); 97 format_.Format.nSamplesPerSec = params.sample_rate();
97 format_.Format.wBitsPerSample = params.bits_per_sample(); 98 format_.Format.wBitsPerSample = params.bits_per_sample();
98 format_.Format.cbSize = sizeof(format_) - sizeof(WAVEFORMATEX); 99 format_.Format.cbSize = sizeof(format_) - sizeof(WAVEFORMATEX);
99 // The next are computed from above. 100 // The next are computed from above.
100 format_.Format.nBlockAlign = (format_.Format.nChannels * 101 format_.Format.nBlockAlign = (format_.Format.nChannels *
101 format_.Format.wBitsPerSample) / 8; 102 format_.Format.wBitsPerSample) / 8;
102 format_.Format.nAvgBytesPerSec = format_.Format.nBlockAlign * 103 format_.Format.nAvgBytesPerSec = format_.Format.nBlockAlign *
103 format_.Format.nSamplesPerSec; 104 format_.Format.nSamplesPerSec;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 335
335 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) { 336 void PCMWaveOutAudioOutputStream::QueueNextPacket(WAVEHDR *buffer) {
336 // Call the source which will fill our buffer with pleasant sounds and 337 // Call the source which will fill our buffer with pleasant sounds and
337 // return to us how many bytes were used. 338 // return to us how many bytes were used.
338 // If we are down sampling to a smaller number of channels, we need to 339 // If we are down sampling to a smaller number of channels, we need to
339 // scale up the amount of pending bytes. 340 // scale up the amount of pending bytes.
340 // TODO(fbarchard): Handle used 0 by queueing more. 341 // TODO(fbarchard): Handle used 0 by queueing more.
341 uint32 scaled_pending_bytes = pending_bytes_ * channels_ / 342 uint32 scaled_pending_bytes = pending_bytes_ * channels_ /
342 format_.Format.nChannels; 343 format_.Format.nChannels;
343 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. 344 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState.
344 uint32 used = callback_->OnMoreData( 345 int frames_filled = callback_->OnMoreData(
345 reinterpret_cast<uint8*>(buffer->lpData), buffer_size_, 346 audio_bus_.get(), AudioBuffersState(scaled_pending_bytes, 0));
346 AudioBuffersState(scaled_pending_bytes, 0)); 347 uint32 used = frames_filled * audio_bus_->channels() *
348 format_.Format.wBitsPerSample / 8;
349
347 if (used <= buffer_size_) { 350 if (used <= buffer_size_) {
351 // Note: If this ever changes to output raw float the data must be clipped
352 // and sanitized since it may come from an untrusted source such as NaCl.
353 audio_bus_->ToInterleaved(
354 frames_filled, format_.Format.wBitsPerSample / 8, buffer->lpData);
355
348 buffer->dwBufferLength = used * format_.Format.nChannels / channels_; 356 buffer->dwBufferLength = used * format_.Format.nChannels / channels_;
349 if (channels_ > 2 && format_.Format.nChannels == 2) { 357 if (channels_ > 2 && format_.Format.nChannels == 2) {
350 media::FoldChannels(buffer->lpData, used, 358 media::FoldChannels(buffer->lpData, used,
351 channels_, format_.Format.wBitsPerSample >> 3, 359 channels_, format_.Format.wBitsPerSample >> 3,
352 volume_); 360 volume_);
353 } else { 361 } else {
354 media::AdjustVolume(buffer->lpData, used, 362 media::AdjustVolume(buffer->lpData, used,
355 format_.Format.nChannels, 363 format_.Format.nChannels,
356 format_.Format.wBitsPerSample >> 3, 364 format_.Format.wBitsPerSample >> 3,
357 volume_); 365 volume_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 buffer, 412 buffer,
405 sizeof(WAVEHDR)); 413 sizeof(WAVEHDR));
406 if (result != MMSYSERR_NOERROR) 414 if (result != MMSYSERR_NOERROR)
407 stream->HandleError(result); 415 stream->HandleError(result);
408 stream->pending_bytes_ += buffer->dwBufferLength; 416 stream->pending_bytes_ += buffer->dwBufferLength;
409 } 417 }
410 } 418 }
411 } 419 }
412 420
413 } // namespace media 421 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/waveout_output_win.h ('k') | media/base/audio_bus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698