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

Side by Side Diff: trunk/src/media/audio/mac/audio_low_latency_input_mac.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
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_low_latency_input_mac.h" 5 #include "media/audio/mac/audio_low_latency_input_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/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/mac_logging.h" 11 #include "base/mac/mac_logging.h"
12 #include "media/audio/mac/audio_manager_mac.h" 12 #include "media/audio/mac/audio_manager_mac.h"
13 #include "media/base/audio_bus.h"
14 #include "media/base/data_buffer.h" 13 #include "media/base/data_buffer.h"
15 14
16 namespace media { 15 namespace media {
17 16
18 static std::ostream& operator<<(std::ostream& os, 17 static std::ostream& operator<<(std::ostream& os,
19 const AudioStreamBasicDescription& format) { 18 const AudioStreamBasicDescription& format) {
20 os << "sample rate : " << format.mSampleRate << std::endl 19 os << "sample rate : " << format.mSampleRate << std::endl
21 << "format ID : " << format.mFormatID << std::endl 20 << "format ID : " << format.mFormatID << std::endl
22 << "format flags : " << format.mFormatFlags << std::endl 21 << "format flags : " << format.mFormatFlags << std::endl
23 << "bytes per packet : " << format.mBytesPerPacket << std::endl 22 << "bytes per packet : " << format.mBytesPerPacket << std::endl
24 << "frames per packet : " << format.mFramesPerPacket << std::endl 23 << "frames per packet : " << format.mFramesPerPacket << std::endl
25 << "bytes per frame : " << format.mBytesPerFrame << std::endl 24 << "bytes per frame : " << format.mBytesPerFrame << std::endl
26 << "channels per frame: " << format.mChannelsPerFrame << std::endl 25 << "channels per frame: " << format.mChannelsPerFrame << std::endl
27 << "bits per channel : " << format.mBitsPerChannel; 26 << "bits per channel : " << format.mBitsPerChannel;
28 return os; 27 return os;
29 } 28 }
30 29
31 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit" 30 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit"
32 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html 31 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
33 // for more details and background regarding this implementation. 32 // for more details and background regarding this implementation.
34 33
35 AUAudioInputStream::AUAudioInputStream(AudioManagerMac* manager, 34 AUAudioInputStream::AUAudioInputStream(
36 const AudioParameters& input_params, 35 AudioManagerMac* manager,
37 const AudioParameters& output_params, 36 const AudioParameters& input_params,
38 AudioDeviceID audio_device_id) 37 const AudioParameters& output_params,
38 AudioDeviceID audio_device_id)
39 : manager_(manager), 39 : manager_(manager),
40 sink_(NULL), 40 sink_(NULL),
41 audio_unit_(0), 41 audio_unit_(0),
42 input_device_id_(audio_device_id), 42 input_device_id_(audio_device_id),
43 started_(false), 43 started_(false),
44 hardware_latency_frames_(0), 44 hardware_latency_frames_(0),
45 fifo_delay_bytes_(0), 45 fifo_delay_bytes_(0),
46 number_of_channels_in_frame_(0), 46 number_of_channels_in_frame_(0) {
47 audio_bus_(media::AudioBus::Create(input_params)) {
48 DCHECK(manager_); 47 DCHECK(manager_);
49 48
50 // Set up the desired (output) format specified by the client. 49 // Set up the desired (output) format specified by the client.
51 format_.mSampleRate = input_params.sample_rate(); 50 format_.mSampleRate = input_params.sample_rate();
52 format_.mFormatID = kAudioFormatLinearPCM; 51 format_.mFormatID = kAudioFormatLinearPCM;
53 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | 52 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked |
54 kLinearPCMFormatFlagIsSignedInteger; 53 kLinearPCMFormatFlagIsSignedInteger;
55 format_.mBitsPerChannel = input_params.bits_per_sample(); 54 format_.mBitsPerChannel = input_params.bits_per_sample();
56 format_.mChannelsPerFrame = input_params.channels(); 55 format_.mChannelsPerFrame = input_params.channels();
57 format_.mFramesPerPacket = 1; // uncompressed audio 56 format_.mFramesPerPacket = 1; // uncompressed audio
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Accumulate captured audio in FIFO until we can match the output size 535 // Accumulate captured audio in FIFO until we can match the output size
537 // requested by the client. 536 // requested by the client.
538 fifo_->Append(audio_data, buffer.mDataByteSize); 537 fifo_->Append(audio_data, buffer.mDataByteSize);
539 538
540 // Deliver recorded data to the client as soon as the FIFO contains a 539 // Deliver recorded data to the client as soon as the FIFO contains a
541 // sufficient amount. 540 // sufficient amount.
542 if (fifo_->forward_bytes() >= requested_size_bytes_) { 541 if (fifo_->forward_bytes() >= requested_size_bytes_) {
543 // Read from FIFO into temporary data buffer. 542 // Read from FIFO into temporary data buffer.
544 fifo_->Read(data_->writable_data(), requested_size_bytes_); 543 fifo_->Read(data_->writable_data(), requested_size_bytes_);
545 544
546 // Copy captured (and interleaved) data into deinterleaved audio bus.
547 audio_bus_->FromInterleaved(
548 data_->data(), audio_bus_->frames(), format_.mBitsPerChannel / 8);
549
550 // Deliver data packet, delay estimation and volume level to the user. 545 // Deliver data packet, delay estimation and volume level to the user.
551 sink_->OnData( 546 sink_->OnData(this,
552 this, audio_bus_.get(), capture_delay_bytes, normalized_volume); 547 data_->data(),
548 requested_size_bytes_,
549 capture_delay_bytes,
550 normalized_volume);
553 } 551 }
554 552
555 return noErr; 553 return noErr;
556 } 554 }
557 555
558 int AUAudioInputStream::HardwareSampleRate() { 556 int AUAudioInputStream::HardwareSampleRate() {
559 // Determine the default input device's sample-rate. 557 // Determine the default input device's sample-rate.
560 AudioDeviceID device_id = kAudioObjectUnknown; 558 AudioDeviceID device_id = kAudioObjectUnknown;
561 UInt32 info_size = sizeof(device_id); 559 UInt32 info_size = sizeof(device_id);
562 560
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 kAudioDevicePropertyScopeInput, 682 kAudioDevicePropertyScopeInput,
685 static_cast<UInt32>(channel) 683 static_cast<UInt32>(channel)
686 }; 684 };
687 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, 685 OSStatus result = AudioObjectIsPropertySettable(input_device_id_,
688 &property_address, 686 &property_address,
689 &is_settable); 687 &is_settable);
690 return (result == noErr) ? is_settable : false; 688 return (result == noErr) ? is_settable : false;
691 } 689 }
692 690
693 } // namespace media 691 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698