From ae3e151b27cdaf561f5cce1f86814501da7401ad Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 3 Jul 2015 19:02:58 +0200 Subject: [PATCH] ao_coreaudio_utils: fix format back-mapping Mapping of spdif formats was imperfect. Since the first format on the list is somehow AAC, it was returned first, which is confusing, because CoreAudio calls all spdif formats AC3. Since the spdif formats have some rather arbitrary, reverse mapping the formats didn"t actually work either. Fix by explicitly ignoring these when spdif is used. Also, don't forget to set the samplerate in ca_asbd_to_mpformat(), or it will work only in some cases. --- audio/out/ao_coreaudio_utils.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index c94cd73483..742dc2d5ff 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -222,14 +222,16 @@ bool ca_asbd_equals(const AudioStreamBasicDescription *a, const AudioStreamBasicDescription *b) { int flags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat | - kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsBigEndian; + kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsBigEndian; + bool spdif = ca_formatid_is_compressed(a->mFormatID) && + ca_formatid_is_compressed(b->mFormatID); return (a->mFormatFlags & flags) == (b->mFormatFlags & flags) && a->mBitsPerChannel == b->mBitsPerChannel && ca_normalize_formatid(a->mFormatID) == ca_normalize_formatid(b->mFormatID) && - a->mBytesPerPacket == b->mBytesPerPacket && - a->mChannelsPerFrame == b->mChannelsPerFrame && + (spdif || a->mBytesPerPacket == b->mBytesPerPacket) && + (spdif || a->mChannelsPerFrame == b->mChannelsPerFrame) && a->mSampleRate == b->mSampleRate; } @@ -238,9 +240,9 @@ int ca_asbd_to_mp_format(const AudioStreamBasicDescription *asbd) { for (int fmt = 1; fmt < AF_FORMAT_COUNT; fmt++) { AudioStreamBasicDescription mp_asbd = {0}; - ca_fill_asbd_raw(&mp_asbd, fmt, 0, asbd->mChannelsPerFrame); + ca_fill_asbd_raw(&mp_asbd, fmt, asbd->mSampleRate, asbd->mChannelsPerFrame); if (ca_asbd_equals(&mp_asbd, asbd)) - return fmt; + return af_fmt_is_spdif(fmt) ? AF_FORMAT_S_AC3 : fmt; } return 0; }