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.
This commit is contained in:
wm4 2015-07-03 19:02:58 +02:00
parent d4ab91f016
commit ae3e151b27
1 changed files with 7 additions and 5 deletions

View File

@ -222,14 +222,16 @@ bool ca_asbd_equals(const AudioStreamBasicDescription *a,
const AudioStreamBasicDescription *b) const AudioStreamBasicDescription *b)
{ {
int flags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat | 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) && return (a->mFormatFlags & flags) == (b->mFormatFlags & flags) &&
a->mBitsPerChannel == b->mBitsPerChannel && a->mBitsPerChannel == b->mBitsPerChannel &&
ca_normalize_formatid(a->mFormatID) == ca_normalize_formatid(a->mFormatID) ==
ca_normalize_formatid(b->mFormatID) && ca_normalize_formatid(b->mFormatID) &&
a->mBytesPerPacket == b->mBytesPerPacket && (spdif || a->mBytesPerPacket == b->mBytesPerPacket) &&
a->mChannelsPerFrame == b->mChannelsPerFrame && (spdif || a->mChannelsPerFrame == b->mChannelsPerFrame) &&
a->mSampleRate == b->mSampleRate; 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++) { for (int fmt = 1; fmt < AF_FORMAT_COUNT; fmt++) {
AudioStreamBasicDescription mp_asbd = {0}; 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)) if (ca_asbd_equals(&mp_asbd, asbd))
return fmt; return af_fmt_is_spdif(fmt) ? AF_FORMAT_S_AC3 : fmt;
} }
return 0; return 0;
} }