From 1587f55dab47bbc929a3ce38e6b722689e1a7ca6 Mon Sep 17 00:00:00 2001 From: dgiardini Date: Thu, 4 Jun 2015 20:07:58 -0300 Subject: [PATCH 1/4] Use "-" as filename for reading from stdin "-" character as filename allow reading from stdin (no /dev/stdin on windows) Add windows compatibility changing stdin to binary mode, avoiding DOS text translations on piped data --- src/sounddecoder.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sounddecoder.c b/src/sounddecoder.c index c2a6282..21fc4fa 100644 --- a/src/sounddecoder.c +++ b/src/sounddecoder.c @@ -80,7 +80,15 @@ int initSoundDecoder(const Sound_Channels _channels, const Sound_Driver _driver, case DRIVER_FILE: strncpy(soundFile, file, MAX_FILENAME_SIZE); soundFile[MAX_FILENAME_SIZE]=0; - fp = fopen(soundFile, "rb"); + if(soundFile[0]=='-'){ + fp=stdin; +#ifdef WIN32 + setmode(fileno(stdin), O_BINARY); // Binary mode +#endif + } + else{ + fp = fopen(soundFile, "rb"); + } if (fp) { buffer_l = 1024; int extra = buffer_l % 5; From 253a31041f59cac48281a0a13ce92f742f06f4e7 Mon Sep 17 00:00:00 2001 From: dgiardini Date: Thu, 4 Jun 2015 20:09:44 -0300 Subject: [PATCH 2/4] Use "-" as filename for reading from stdin --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index f5d60c0..57e5660 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ "-p\tDestination UDP port\n"\ "-a\tAudio driver [" HELP_AUDIO_DRIVERS "]\n" HELP_AUDIO_DEVICE\ "-c\tSound channels [stereo,mono,left,right] (default stereo)\n"\ -"-f\tFull path to 48kHz raw audio file\n"\ +"-f\tFull path to 48kHz raw audio file. Use \"-\" for stdin\n"\ "-l\tLog sound levels to console (stderr)\n"\ "-d\tLog NMEA sentences to console (stderr)\n"\ "-H\tDisplay this help\n" From 4d34c32ec03645fbca48d1f4568c2ac9f5b5b3e1 Mon Sep 17 00:00:00 2001 From: dgiardini Date: Thu, 4 Jun 2015 20:12:55 -0300 Subject: [PATCH 3/4] Update main.c --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 57e5660..27f99ef 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ "-p\tDestination UDP port\n"\ "-a\tAudio driver [" HELP_AUDIO_DRIVERS "]\n" HELP_AUDIO_DEVICE\ "-c\tSound channels [stereo,mono,left,right] (default stereo)\n"\ -"-f\tFull path to 48kHz raw audio file. Use \"-\" for stdin\n"\ +"-f\tFull path to 48kHz raw audio file. Use \"-\" for stdin.\n"\ "-l\tLog sound levels to console (stderr)\n"\ "-d\tLog NMEA sentences to console (stderr)\n"\ "-H\tDisplay this help\n" From 3fa58990e4ced0db3720fc2f5b1bc37e0dc08f35 Mon Sep 17 00:00:00 2001 From: dgiardini Date: Thu, 4 Jun 2015 20:18:51 -0300 Subject: [PATCH 4/4] Use "-" as filename for reading from stdin --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 27f99ef..5f747df 100644 --- a/src/main.c +++ b/src/main.c @@ -62,7 +62,7 @@ "-p\tDestination UDP port\n"\ "-a\tAudio driver [" HELP_AUDIO_DRIVERS "]\n" HELP_AUDIO_DEVICE\ "-c\tSound channels [stereo,mono,left,right] (default stereo)\n"\ -"-f\tFull path to 48kHz raw audio file. Use \"-\" for stdin.\n"\ +"-f\tFull path to 48kHz raw audio file. Use \"-\" for stdin. \n"\ "-l\tLog sound levels to console (stderr)\n"\ "-d\tLog NMEA sentences to console (stderr)\n"\ "-H\tDisplay this help\n"