summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_coreaudio_utils.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-07-06 17:49:28 +0200
committerwm4 <wm4@nowhere>2015-07-06 17:49:28 +0200
commit7c032bde3e6473902bbda2aea65be4bfb9d68802 (patch)
treeddfe8e980dae575321de8f34ea8d2b332652315b /audio/out/ao_coreaudio_utils.c
parenta56a7f3e8c7dbed38546f3ddedb0e26353f92e25 (diff)
downloadmpv-7c032bde3e6473902bbda2aea65be4bfb9d68802.tar.bz2
mpv-7c032bde3e6473902bbda2aea65be4bfb9d68802.tar.xz
ao_coreaudio: fix device latency, share the code
ao_coreaudio (using AudioUnit) accounted only for part of the latency - move the code in ao_coreaudio_exclusive to utils, and use that for the AudioUnit code. (There's still the question why CoreAudio and AudioUnit require you to jump through hoops this much, but apparently that's how it is.)
Diffstat (limited to 'audio/out/ao_coreaudio_utils.c')
-rw-r--r--audio/out/ao_coreaudio_utils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 2c3a5b4c50..f6463a314a 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -448,6 +448,28 @@ OSStatus ca_enable_mixing(struct ao *ao, AudioDeviceID device, bool changed)
return noErr;
}
+int64_t ca_get_device_latency_us(struct ao *ao, AudioDeviceID device)
+{
+ uint32_t latency_frames = 0;
+ uint32_t latency_properties[] = {
+ kAudioDevicePropertyLatency,
+ kAudioDevicePropertyBufferFrameSize,
+ kAudioDevicePropertySafetyOffset,
+ };
+ for (int n = 0; n < MP_ARRAY_SIZE(latency_properties); n++) {
+ uint32_t temp;
+ OSStatus err = CA_GET_O(device, latency_properties[n], &temp);
+ CHECK_CA_WARN("cannot get device latency");
+ if (err == noErr) {
+ latency_frames += temp;
+ MP_VERBOSE(ao, "Latency property %s: %d frames\n",
+ fourcc_repr(latency_properties[n]), (int)temp);
+ }
+ }
+
+ return ca_frames_to_us(ao, latency_frames);
+}
+
static OSStatus ca_change_format_listener(
AudioObjectID object, uint32_t n_addresses,
const AudioObjectPropertyAddress addresses[],