mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
ao_coreaudio_chmap: minor refactor
Share some code between ca_init_chmap() and ca_get_active_chmap(), which also makes it look slightly nicer. No functional changes, other than the additional log message.
This commit is contained in:
parent
c971fefd41
commit
0524907c18
@ -235,20 +235,27 @@ coreaudio_error:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ca_init_chmap(struct ao *ao, AudioDeviceID device)
|
static void ca_retrieve_layouts(struct ao *ao, struct mp_chmap_sel *s,
|
||||||
|
AudioDeviceID device)
|
||||||
{
|
{
|
||||||
void *ta_ctx = talloc_new(NULL);
|
void *ta_ctx = talloc_new(NULL);
|
||||||
|
struct mp_chmap chmap;
|
||||||
struct mp_chmap_sel chmap_sel = {.tmp = ta_ctx};
|
|
||||||
struct mp_chmap chmap = {0};
|
|
||||||
|
|
||||||
AudioChannelLayout *ml = ca_query_layout(ao, device, ta_ctx);
|
AudioChannelLayout *ml = ca_query_layout(ao, device, ta_ctx);
|
||||||
if (ml && ca_layout_to_mp_chmap(ao, ml, &chmap))
|
if (ml && ca_layout_to_mp_chmap(ao, ml, &chmap))
|
||||||
mp_chmap_sel_add_map(&chmap_sel, &chmap);
|
mp_chmap_sel_add_map(s, &chmap);
|
||||||
|
|
||||||
AudioChannelLayout *sl = ca_query_stereo_layout(ao, device, ta_ctx);
|
AudioChannelLayout *sl = ca_query_stereo_layout(ao, device, ta_ctx);
|
||||||
if (sl && ca_layout_to_mp_chmap(ao, sl, &chmap))
|
if (sl && ca_layout_to_mp_chmap(ao, sl, &chmap))
|
||||||
mp_chmap_sel_add_map(&chmap_sel, &chmap);
|
mp_chmap_sel_add_map(s, &chmap);
|
||||||
|
|
||||||
|
talloc_free(ta_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ca_init_chmap(struct ao *ao, AudioDeviceID device)
|
||||||
|
{
|
||||||
|
struct mp_chmap_sel chmap_sel = {0};
|
||||||
|
ca_retrieve_layouts(ao, &chmap_sel, device);
|
||||||
|
|
||||||
if (!chmap_sel.num_chmaps)
|
if (!chmap_sel.num_chmaps)
|
||||||
mp_chmap_sel_add_map(&chmap_sel, &(struct mp_chmap)MP_CHMAP_INIT_STEREO);
|
mp_chmap_sel_add_map(&chmap_sel, &(struct mp_chmap)MP_CHMAP_INIT_STEREO);
|
||||||
@ -259,39 +266,28 @@ bool ca_init_chmap(struct ao *ao, AudioDeviceID device)
|
|||||||
MP_ERR(ao, "could not select a suitable channel map among the "
|
MP_ERR(ao, "could not select a suitable channel map among the "
|
||||||
"hardware supported ones. Make sure to configure your "
|
"hardware supported ones. Make sure to configure your "
|
||||||
"output device correctly in 'Audio MIDI Setup.app'\n");
|
"output device correctly in 'Audio MIDI Setup.app'\n");
|
||||||
goto coreaudio_error;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free(ta_ctx);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
coreaudio_error:
|
|
||||||
talloc_free(ta_ctx);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count,
|
void ca_get_active_chmap(struct ao *ao, AudioDeviceID device, int channel_count,
|
||||||
struct mp_chmap *out_map)
|
struct mp_chmap *out_map)
|
||||||
{
|
{
|
||||||
void *ta_ctx = talloc_new(NULL);
|
|
||||||
|
|
||||||
// Apparently, we have to guess by looking back at the supported layouts,
|
// Apparently, we have to guess by looking back at the supported layouts,
|
||||||
// and I haven't found a property that retrieves the actual currently
|
// and I haven't found a property that retrieves the actual currently
|
||||||
// active channel layout.
|
// active channel layout.
|
||||||
|
|
||||||
AudioChannelLayout *ml = ca_query_layout(ao, device, ta_ctx);
|
struct mp_chmap_sel chmap_sel = {0};
|
||||||
if (ml && ca_layout_to_mp_chmap(ao, ml, out_map)) {
|
ca_retrieve_layouts(ao, &chmap_sel, device);
|
||||||
if (channel_count == out_map->num)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioChannelLayout *sl = ca_query_stereo_layout(ao, device, ta_ctx);
|
for (int n = 0; n < chmap_sel.num_chmaps; n++) {
|
||||||
if (sl && ca_layout_to_mp_chmap(ao, sl, out_map)) {
|
if (chmap_sel.chmaps[n].num == channel_count) {
|
||||||
if (channel_count == out_map->num)
|
MP_VERBOSE(ao, "mismatching channels - fallback #%d\n", n);
|
||||||
goto done;
|
*out_map = chmap_sel.chmaps[n];
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out_map->num = 0;
|
out_map->num = 0;
|
||||||
done:
|
|
||||||
talloc_free(ta_ctx);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user