mirror of
https://github.com/mpv-player/mpv
synced 2025-01-06 07:00:30 +00:00
ao_coreaudio_exclusive: deal with devices return different channel count
If the device returns an unexpected number of channels instead of the requested count on init, don't immediately error out. Instead, look if there's a channel map with the given number of channels. If there isn't, still error out, because we don't want to guess the channel layout.
This commit is contained in:
parent
78112c8582
commit
dda16ee1fb
@ -265,3 +265,28 @@ coreaudio_error:
|
||||
talloc_free(ta_ctx);
|
||||
return false;
|
||||
}
|
||||
|
||||
void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count,
|
||||
struct mp_chmap *out_map)
|
||||
{
|
||||
void *ta_ctx = talloc_new(NULL);
|
||||
|
||||
// Apparently, we have to guess by looking back at the supported layouts,
|
||||
// and I haven't found a property that retrieves the actual currently
|
||||
// active channel layout.
|
||||
|
||||
AudioChannelLayout *ml = ca_query_layout(ao, device, ta_ctx);
|
||||
if (ml && ca_layout_to_mp_chmap(ao, ml, out_map)) {
|
||||
if (channel_count == out_map->num)
|
||||
goto done;
|
||||
}
|
||||
|
||||
AudioChannelLayout *sl = ca_query_stereo_layout(ao, device, ta_ctx);
|
||||
if (sl && ca_layout_to_mp_chmap(ao, sl, out_map)) {
|
||||
if (channel_count == out_map->num)
|
||||
goto done;
|
||||
}
|
||||
|
||||
out_map->num = 0;
|
||||
done: ;
|
||||
}
|
||||
|
@ -20,6 +20,10 @@
|
||||
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
struct mp_chmap;
|
||||
|
||||
bool ca_init_chmap(struct ao *ao, AudioDeviceID device);
|
||||
void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count,
|
||||
struct mp_chmap *out_map);
|
||||
|
||||
#endif
|
||||
|
@ -315,7 +315,10 @@ static int init(struct ao *ao)
|
||||
ao->samplerate = p->stream_asbd.mSampleRate;
|
||||
|
||||
if (ao->channels.num != p->stream_asbd.mChannelsPerFrame) {
|
||||
// We really expect that ca_init_chmap() fixes the layout to the HW's.
|
||||
ca_active_chmap(ao, p->device, p->stream_asbd.mChannelsPerFrame,
|
||||
&ao->channels);
|
||||
}
|
||||
if (!ao->channels.num) {
|
||||
MP_ERR(ao, "number of channels changed, and unknown channel layout!\n");
|
||||
goto coreaudio_error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user