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

Side by Side Diff: media/audio/mac/audio_output_mac.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review ready. Created 8 years, 4 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
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/mac/audio_output_mac.h" 5 #include "media/audio/mac/audio_output_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 packet_size_(params.GetBytesPerBuffer()), 46 packet_size_(params.GetBytesPerBuffer()),
47 silence_bytes_(0), 47 silence_bytes_(0),
48 volume_(1), 48 volume_(1),
49 pending_bytes_(0), 49 pending_bytes_(0),
50 num_source_channels_(params.channels()), 50 num_source_channels_(params.channels()),
51 source_layout_(params.channel_layout()), 51 source_layout_(params.channel_layout()),
52 num_core_channels_(0), 52 num_core_channels_(0),
53 should_swizzle_(false), 53 should_swizzle_(false),
54 should_down_mix_(false), 54 should_down_mix_(false),
55 stopped_event_(true /* manual reset */, false /* initial state */), 55 stopped_event_(true /* manual reset */, false /* initial state */),
56 num_buffers_left_(kNumBuffers) { 56 num_buffers_left_(kNumBuffers),
57 audio_bus_(AudioBus::Create(params)) {
57 // We must have a manager. 58 // We must have a manager.
58 DCHECK(manager_); 59 DCHECK(manager_);
59 // A frame is one sample across all channels. In interleaved audio the per 60 // A frame is one sample across all channels. In interleaved audio the per
60 // frame fields identify the set of n |channels|. In uncompressed audio, a 61 // frame fields identify the set of n |channels|. In uncompressed audio, a
61 // packet is always one frame. 62 // packet is always one frame.
62 format_.mSampleRate = params.sample_rate(); 63 format_.mSampleRate = params.sample_rate();
63 format_.mFormatID = kAudioFormatLinearPCM; 64 format_.mFormatID = kAudioFormatLinearPCM;
64 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked; 65 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked;
65 format_.mBitsPerChannel = params.bits_per_sample(); 66 format_.mBitsPerChannel = params.bits_per_sample();
66 format_.mChannelsPerFrame = params.channels(); 67 format_.mChannelsPerFrame = params.channels();
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // Should never touch audio_stream after signaling as it 403 // Should never touch audio_stream after signaling as it
403 // can be deleted at any moment. 404 // can be deleted at any moment.
404 audio_stream->stopped_event_.Signal(); 405 audio_stream->stopped_event_.Signal();
405 } 406 }
406 return; 407 return;
407 } 408 }
408 409
409 // Adjust the number of pending bytes by subtracting the amount played. 410 // Adjust the number of pending bytes by subtracting the amount played.
410 if (!static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer) 411 if (!static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer)
411 audio_stream->pending_bytes_ -= buffer->mAudioDataByteSize; 412 audio_stream->pending_bytes_ -= buffer->mAudioDataByteSize;
413 uint32 filled = 0;
412 uint32 capacity = buffer->mAudioDataBytesCapacity; 414 uint32 capacity = buffer->mAudioDataBytesCapacity;
413 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. 415 {
414 uint32 filled = source->OnMoreData( 416 // Since RenderCallback may be reentrant, we need to ensure the AudioBus
415 reinterpret_cast<uint8*>(buffer->mAudioData), capacity, 417 // we're sharing is safe for this instance. OnMoreData() offers no
416 AudioBuffersState(audio_stream->pending_bytes_, 0)); 418 // guarantee of thread safety as well.
419 base::AutoLock lock(audio_stream->audio_bus_lock_);
Chris Rogers 2012/08/24 20:20:26 Are you sure this is right? If this function is r
DaleCurtis 2012/08/24 23:53:12 That indicates that a lock shouldn't be held acros
420
Chris Rogers 2012/08/24 20:20:26 You use "audio_stream->audio_bus_" three times bel
DaleCurtis 2012/08/24 23:53:12 Done. Presumably PCMQueueOutAudioOutputStream won'
421 DCHECK_EQ(audio_stream->audio_bus_->frames() *
422 audio_stream->format_.mBytesPerFrame, capacity);
423 // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState.
424 int frames_filled = source->OnMoreData(
425 audio_stream->audio_bus_.get(),
426 AudioBuffersState(audio_stream->pending_bytes_, 0));
427 filled = frames_filled * audio_stream->format_.mBytesPerFrame;
428 audio_stream->audio_bus_->ToInterleaved(
429 frames_filled, audio_stream->format_.mBitsPerChannel / 8,
430 buffer->mAudioData);
431 }
417 432
418 // In order to keep the callback running, we need to provide a positive amount 433 // In order to keep the callback running, we need to provide a positive amount
419 // of data to the audio queue. To simulate the behavior of Windows, we write 434 // of data to the audio queue. To simulate the behavior of Windows, we write
420 // a buffer of silence. 435 // a buffer of silence.
421 if (!filled) { 436 if (!filled) {
422 CHECK(audio_stream->silence_bytes_ <= static_cast<int>(capacity)); 437 CHECK(audio_stream->silence_bytes_ <= static_cast<int>(capacity));
423 filled = audio_stream->silence_bytes_; 438 filled = audio_stream->silence_bytes_;
424 439
425 // Assume unsigned audio. 440 // Assume unsigned audio.
426 int silence_value = 128; 441 int silence_value = 128;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 source_ = source; 546 source_ = source;
532 } 547 }
533 548
534 AudioOutputStream::AudioSourceCallback* 549 AudioOutputStream::AudioSourceCallback*
535 PCMQueueOutAudioOutputStream::GetSource() { 550 PCMQueueOutAudioOutputStream::GetSource() {
536 base::AutoLock lock(source_lock_); 551 base::AutoLock lock(source_lock_);
537 return source_; 552 return source_;
538 } 553 }
539 554
540 } // namespace media 555 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698