summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-10-26 15:55:01 +0100
committerwm4 <wm4@nowhere>2015-10-26 15:55:01 +0100
commit0524907c18e870568809f01cff363055030a4e21 (patch)
treecdc1e1812bc6b97e35b7789ea3009633d226f2c7 /audio
parentc971fefd41f530e7974dd262c22e3b0915f1756a (diff)
downloadmpv-0524907c18e870568809f01cff363055030a4e21.tar.bz2
mpv-0524907c18e870568809f01cff363055030a4e21.tar.xz
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_coreaudio_chmap.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/audio/out/ao_coreaudio_chmap.c b/audio/out/ao_coreaudio_chmap.c
index 1f299cedc2..d5a38d325e 100644
--- a/audio/out/ao_coreaudio_chmap.c
+++ b/audio/out/ao_coreaudio_chmap.c
@@ -235,20 +235,27 @@ coreaudio_error:
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);
-
- struct mp_chmap_sel chmap_sel = {.tmp = ta_ctx};
- struct mp_chmap chmap = {0};
+ struct mp_chmap chmap;
AudioChannelLayout *ml = ca_query_layout(ao, device, ta_ctx);
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);
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)
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 "
"hardware supported ones. Make sure to configure your "
"output device correctly in 'Audio MIDI Setup.app'\n");
- goto coreaudio_error;
+ return false;
}
-
- talloc_free(ta_ctx);
return true;
-
-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;
- }
+ struct mp_chmap_sel chmap_sel = {0};
+ ca_retrieve_layouts(ao, &chmap_sel, device);
- 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;
+ for (int n = 0; n < chmap_sel.num_chmaps; n++) {
+ if (chmap_sel.chmaps[n].num == channel_count) {
+ MP_VERBOSE(ao, "mismatching channels - fallback #%d\n", n);
+ *out_map = chmap_sel.chmaps[n];
+ return;
+ }
}
out_map->num = 0;
-done:
- talloc_free(ta_ctx);
}