diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/player.c | 30 | ||||
-rw-r--r-- | src/settings.c | 5 | ||||
-rw-r--r-- | src/settings.h | 1 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/player.c b/src/player.c index 848d58b..d73b718 100644 --- a/src/player.c +++ b/src/player.c @@ -38,9 +38,11 @@ THE SOFTWARE. #include <string.h> #include <math.h> #include <stdint.h> +#include <fcntl.h> #include <limits.h> #include <assert.h> #include <arpa/inet.h> +#include <sys/stat.h> #include <libavcodec/avcodec.h> #include <libavutil/avutil.h> @@ -340,10 +342,30 @@ static bool openDevice (player_t * const player) { aoFmt.rate = getSampleRate (player); aoFmt.byte_format = AO_FMT_NATIVE; - int driver = ao_default_driver_id (); - if ((player->aoDev = ao_open_live (driver, &aoFmt, NULL)) == NULL) { - BarUiMsg (player->settings, MSG_ERR, "Cannot open audio device.\n"); - return false; + int driver = -1; + if (player->settings->audioPipe) { + // using audio pipe + struct stat st; + if (stat (player->settings->audioPipe, &st)) { + BarUiMsg (player->settings, MSG_ERR, "Cannot stat audio pipe file.\n"); + return false; + } + if (!S_ISFIFO (st.st_mode)) { + BarUiMsg (player->settings, MSG_ERR, "File is not a pipe, error.\n"); + return false; + } + driver = ao_driver_id ("raw"); + if ((player->aoDev = ao_open_file(driver, player->settings->audioPipe, 1, &aoFmt, NULL)) == NULL) { + BarUiMsg (player->settings, MSG_ERR, "Cannot open audio pipe file.\n"); + return false; + } + } else { + // use driver from libao configuration + driver = ao_default_driver_id (); + if ((player->aoDev = ao_open_live (driver, &aoFmt, NULL)) == NULL) { + BarUiMsg (player->settings, MSG_ERR, "Cannot open audio device.\n"); + return false; + } } return true; diff --git a/src/settings.c b/src/settings.c index bcb5dfc..7518177 100644 --- a/src/settings.c +++ b/src/settings.c @@ -125,6 +125,7 @@ void BarSettingsDestroy (BarSettings_t *settings) { free (settings->npStationFormat); free (settings->listSongFormat); free (settings->fifo); + free (settings->audioPipe); free (settings->rpcHost); free (settings->rpcTlsPort); free (settings->partnerUser); @@ -182,6 +183,7 @@ void BarSettingsRead (BarSettings_t *settings) { settings->inkey = strdup ("R=U!LH$O2B#"); settings->outkey = strdup ("6#26FRL$ZWD"); settings->fifo = BarGetXdgConfigDir (PACKAGE "/ctl"); + settings->audioPipe = NULL; assert (settings->fifo != NULL); settings->sampleRate = 0; /* default to stream sample rate */ @@ -390,6 +392,9 @@ void BarSettingsRead (BarSettings_t *settings) { } else if (streq ("fifo", key)) { free (settings->fifo); settings->fifo = BarSettingsExpandTilde (val, userhome); + } else if (streq ("audio_pipe", key)) { + free (settings->audioPipe); + settings->audioPipe = BarSettingsExpandTilde (val, userhome); } else if (streq ("autoselect", key)) { settings->autoselect = atoi (val); } else if (streq ("sample_rate", key)) { diff --git a/src/settings.h b/src/settings.h index a4264a2..1a9b256 100644 --- a/src/settings.h +++ b/src/settings.h @@ -103,6 +103,7 @@ typedef struct { char *listSongFormat; char *fifo; char *rpcHost, *rpcTlsPort, *partnerUser, *partnerPassword, *device, *inkey, *outkey, *caBundle; + char *audioPipe; char keys[BAR_KS_COUNT]; int sampleRate; BarMsgFormatStr_t msgFormat[MSG_COUNT]; |