Commit 93e74211 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Use stream id to get stream latency for first stream.

The previous change 973509d4, which
added querying of stream latency, incorrectly uses the device id
for querying the stream latency.

We must instead, first query the list of stream ids and query the
latency of a given stream. While there may be multiple streams,
we can't do anything with that information; e.g., to handle that
case we would need to attempt to synchronize all streams to the
highest latency. Apple instead recommends just taking the latency
of the first stream since that will cover the majority of cases.

BUG=783282
TEST=none

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I98b65b1fa7030f63abbb6d96c7540352d1bb896b
Reviewed-on: https://chromium-review.googlesource.com/802194Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520988}
parent 0cc89df1
......@@ -1108,13 +1108,39 @@ base::TimeDelta AudioManagerMac::GetHardwareLatency(
OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
<< "Could not get audio device latency.";
property_address.mSelector = kAudioStreamPropertyLatency;
// Retrieve stream ids and take the stream latency from the first stream.
// There may be multiple streams with different latencies, but since we're
// likely using this delay information for a/v sync we must choose one of
// them; Apple recommends just taking the first entry.
//
// TODO(dalecurtis): Refactor all these "get data size" + "get data" calls
// into a common utility function that just returns a std::unique_ptr.
UInt32 stream_latency_frames = 0;
size = sizeof(stream_latency_frames);
result = AudioObjectGetPropertyData(device_id, &property_address, 0, nullptr,
&size, &stream_latency_frames);
OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
<< "Could not get stream latency.";
property_address.mSelector = kAudioDevicePropertyStreams;
result = AudioObjectGetPropertyDataSize(device_id, &property_address, 0,
nullptr, &size);
if (result == noErr && size >= sizeof(AudioStreamID)) {
std::unique_ptr<uint8_t[]> stream_id_storage(new uint8_t[size]);
AudioStreamID* stream_ids =
reinterpret_cast<AudioStreamID*>(stream_id_storage.get());
result = AudioObjectGetPropertyData(device_id, &property_address, 0,
nullptr, &size, stream_ids);
if (result == noErr) {
property_address.mSelector = kAudioStreamPropertyLatency;
size = sizeof(stream_latency_frames);
result =
AudioObjectGetPropertyData(stream_ids[0], &property_address, 0,
nullptr, &size, &stream_latency_frames);
OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
<< "Could not get stream latency for stream #0.";
} else {
OSSTATUS_DLOG(WARNING, result)
<< "Could not get audio device stream ids.";
}
} else {
OSSTATUS_DLOG_IF(WARNING, result != noErr, result)
<< "Could not get audio device stream ids size.";
}
return base::TimeDelta::FromSecondsD(audio_unit_latency_sec) +
AudioTimestampHelper::FramesToTime(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment