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

Unified Diff: media/audio/mac/audio_low_latency_input_mac.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/mac/audio_low_latency_input_mac.cc
diff --git a/media/audio/mac/audio_low_latency_input_mac.cc b/media/audio/mac/audio_low_latency_input_mac.cc
index cddf4300d3d61bf449a1cf9ebcc9725dc813233d..f86f2a50e4f4ae4d3a66efc581dd0f5896ddb505 100644
--- a/media/audio/mac/audio_low_latency_input_mac.cc
+++ b/media/audio/mac/audio_low_latency_input_mac.cc
@@ -250,7 +250,6 @@ AUAudioInputStream::AUAudioInputStream(
sink_(nullptr),
audio_unit_(0),
input_device_id_(audio_device_id),
- hardware_latency_frames_(0),
number_of_channels_in_frame_(0),
fifo_(input_params.channels(),
number_of_frames_,
@@ -517,7 +516,7 @@ bool AUAudioInputStream::Open() {
}
// The hardware latency is fixed and will not change during the call.
- hardware_latency_frames_ = GetHardwareLatency();
+ hardware_latency_ = GetHardwareLatency();
// The master channel is 0, Left and right are channels 1 and 2.
// And the master channel is not counted in |number_of_channels_in_frame_|.
@@ -960,7 +959,8 @@ OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames,
number_of_frames_provided_ = number_of_frames;
// Update the capture latency.
- double capture_latency_frames = GetCaptureLatency(time_stamp);
+ base::TimeDelta capture_latency = GetCaptureLatency(time_stamp);
+ base::TimeDelta delay_timestamp = base::TimeTicks::Now();
// The AGC volume level is updated once every second on a separate thread.
// Note that, |volume| is also updated each time SetVolume() is called
@@ -970,8 +970,6 @@ OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames,
AudioBuffer& buffer = io_data->mBuffers[0];
uint8_t* audio_data = reinterpret_cast<uint8_t*>(buffer.mData);
- uint32_t capture_delay_bytes = static_cast<uint32_t>(
- (capture_latency_frames + 0.5) * format_.mBytesPerFrame);
DCHECK(audio_data);
if (!audio_data)
return kAudioUnitErr_InvalidElement;
@@ -1003,7 +1001,8 @@ OSStatus AUAudioInputStream::Provide(UInt32 number_of_frames,
// Compensate the audio delay caused by the FIFO.
capture_delay_bytes += fifo_.GetAvailableFrames() * format_.mBytesPerFrame;
o1ka 2017/02/10 13:28:50 Hmm.. does it really compile? :)
DaleCurtis 2017/02/11 01:43:13 Like I said, not done yet :)
- sink_->OnData(this, audio_bus, capture_delay_bytes, normalized_volume);
+ sink_->OnData(this, audio_bus, capture_latency, delay_timestamp,
o1ka 2017/02/10 13:28:50 Shouldn't we adjust latency and timestamp values t
+ normalized_volume);
}
return noErr;
@@ -1113,10 +1112,10 @@ int AUAudioInputStream::HardwareSampleRate() {
return static_cast<int>(nominal_sample_rate);
}
-double AUAudioInputStream::GetHardwareLatency() {
+base::TimeDelta AUAudioInputStream::GetHardwareLatency() {
if (!audio_unit_ || input_device_id_ == kAudioObjectUnknown) {
DLOG(WARNING) << "Audio unit object is NULL or device ID is unknown";
- return 0.0;
+ return base::TimeDelta();
}
// Get audio unit latency.
@@ -1138,23 +1137,24 @@ double AUAudioInputStream::GetHardwareLatency() {
nullptr, &size, &device_latency_frames);
DLOG_IF(WARNING, result != noErr) << "Could not get audio device latency.";
- return static_cast<double>((audio_unit_latency_sec * format_.mSampleRate) +
- device_latency_frames);
+ return base::TimeDelta::FromSecondsD(
+ audio_unit_latency_sec +
+ device_latency_frames / static_cast<double>(format_.mSampleRate));
}
-double AUAudioInputStream::GetCaptureLatency(
+base::TimeDelta AUAudioInputStream::GetCaptureLatency(
const AudioTimeStamp* input_time_stamp) {
// Get the delay between between the actual recording instant and the time
// when the data packet is provided as a callback.
UInt64 capture_time_ns =
AudioConvertHostTimeToNanos(input_time_stamp->mHostTime);
UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
- double delay_frames = static_cast<double>(1e-9 * (now_ns - capture_time_ns) *
- format_.mSampleRate);
// Total latency is composed by the dynamic latency and the fixed
// hardware latency.
- return (delay_frames + hardware_latency_frames_);
+ return hardware_latency_ +
+ base::TimeDelta::FromMicroseconds((now_ns - capture_time_ns) /
+ kNanosecondsPerMicrosecond);
}
int AUAudioInputStream::GetNumberOfChannelsFromStream() {

Powered by Google App Engine
This is Rietveld 408576698