diff options
author | wm4 <wm4@nowhere> | 2014-10-23 17:36:14 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-10-23 18:06:17 +0200 |
commit | 809fbc6fc1e862ab2dfcfcceeb65d7382d8b51e9 (patch) | |
tree | 7fee28c219bafdb99f43f115c3bd39696719ead6 /audio/out | |
parent | 626dcf17724c2aae028d1fbe0363e63501861376 (diff) | |
download | mpv-809fbc6fc1e862ab2dfcfcceeb65d7382d8b51e9.tar.bz2 mpv-809fbc6fc1e862ab2dfcfcceeb65d7382d8b51e9.tar.xz |
ao_alsa: move parameter append code to a function
Why not. (I thought I needed this, but my other experiments failed. So
this is merely a minor cleanup.)
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao_alsa.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index fb3cef75d4..0d078d17fe 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -293,6 +293,32 @@ static int map_iec958_srate(int srate) } } +// ALSA device strings can have parameters. They are usually appended to the +// device name. Since there can be various forms, and we (sometimes) want to +// append them to unknown device strings, which possibly already include params. +static char *append_params(void *ta_parent, const char *device, const char *p) +{ + if (!p || !p[0]) + return talloc_strdup(ta_parent, device); + + int len = strlen(device); + char *end = strchr(device, ':'); + if (!end) { + /* no existing parameters: add it behind device name */ + return talloc_asprintf(ta_parent, "%s:%s", device, p); + } else if (end[1] == '\0') { + /* ":" but no parameters */ + return talloc_asprintf(ta_parent, "%s%s", device, p); + } else if (end[1] == '{' && device[len - 1] == '}') { + /* parameters in config syntax: add it inside the { } block */ + return talloc_asprintf(ta_parent, "%.*s %s}", len - 1, device, p); + } else { + /* a simple list of parameters: add it at the end of the list */ + return talloc_asprintf(ta_parent, "%s,%s", device, p); + } + abort(); +} + static int try_open_device(struct ao *ao, const char *device, int open_mode) { struct priv *p = ao->priv; @@ -305,22 +331,7 @@ static int try_open_device(struct ao *ao, const char *device, int open_mode) IEC958_AES0_NONAUDIO | IEC958_AES0_PRO_EMPHASIS_NONE, IEC958_AES1_CON_ORIGINAL | IEC958_AES1_CON_PCM_CODER, map_iec958_srate(ao->samplerate)); - const char *ac3_device = device; - int len = strlen(device); - char *end = strchr(device, ':'); - if (!end) { - /* no existing parameters: add it behind device name */ - ac3_device = talloc_asprintf(tmp, "%s:%s", device, params); - } else if (end[1] == '\0') { - /* ":" but no parameters */ - ac3_device = talloc_asprintf(tmp, "%s%s", device, params); - } else if (end[1] == '{' && device[len - 1] == '}') { - /* parameters in config syntax: add it inside the { } block */ - ac3_device = talloc_asprintf(tmp, "%.*s %s}", len - 1, device, params); - } else { - /* a simple list of parameters: add it at the end of the list */ - ac3_device = talloc_asprintf(tmp, "%s,%s", device, params); - } + const char *ac3_device = append_params(tmp, device, params); int err = snd_pcm_open (&p->alsa, ac3_device, SND_PCM_STREAM_PLAYBACK, open_mode); talloc_free(tmp); |