diff options
| author | Bruno Morais <brunosmmm@gmail.com> | 2019-06-06 16:54:11 +0200 | 
|---|---|---|
| committer | Lars-Dominik Braun <lars@6xq.net> | 2019-06-06 16:54:11 +0200 | 
| commit | da7daddf453601a86c9b94c8c31da1fe4c76e89b (patch) | |
| tree | 56006f75a4aca8a3ea47e1227d25ab4ff9f34326 /src/player.c | |
| parent | 4594810abea6fa50643c0923a9ee9075e59922ce (diff) | |
| download | pianobar-da7daddf453601a86c9b94c8c31da1fe4c76e89b.tar.gz pianobar-da7daddf453601a86c9b94c8c31da1fe4c76e89b.tar.bz2 pianobar-da7daddf453601a86c9b94c8c31da1fe4c76e89b.zip | |
Allow writing audio to a named pipe (fifo) instead of live device
Fixes #684
Diffstat (limited to 'src/player.c')
| -rw-r--r-- | src/player.c | 30 | 
1 files changed, 26 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; | 
