From: Roman Bazalevsky <rvb@rvb.name>
Date: Fri, 11 Jul 2014 15:52:32 +0000 (+0400)
Subject: Added stdin source (to use with 'arecord -t raw' command for 16-bit audio)
X-Git-Url: https://git.rvb.name/oss-streamer.git/commitdiff_plain/9567fc9b2dab3b8fb0f9c2115cd5ef9d2ea304cd?ds=sidebyside

Added stdin source (to use with 'arecord -t raw' command for 16-bit audio)
---

diff --git a/oss-streamer b/oss-streamer
index deb0d96..ceabc2e 100755
Binary files a/oss-streamer and b/oss-streamer differ
diff --git a/oss-streamer.c b/oss-streamer.c
index c5702d4..a64a166 100644
--- a/oss-streamer.c
+++ b/oss-streamer.c
@@ -15,7 +15,6 @@
 #include <fcntl.h>
 
 #define SOURCE_VERSION "0.0"
-#define BOUNDARY "arflebarfle"
 
 typedef enum { SNAPSHOT, STREAM } answer_t;
 
@@ -23,7 +22,7 @@ typedef enum { SNAPSHOT, STREAM } answer_t;
 int stop=0, sd;
 int force_delay=0;
 #define BUF_SIZE 4096
-int source_dev;
+FILE *source_dev;
 
 /* signal fresh frames */
 pthread_mutex_t db        = PTHREAD_MUTEX_INITIALIZER;
@@ -97,7 +96,7 @@ void *get_thread( void *arg ) {
 
   while( !stop ) {
     /* grab a frame */
-    if( read(source_dev,rbuffer,BUF_SIZE) < 0 ) {
+    if( fread(rbuffer,1,BUF_SIZE,source_dev) < 0 ) {
       fprintf(stderr, "Error grabbing\n");
       exit(1);
     }
@@ -281,8 +280,12 @@ int main(int argc, char *argv[])
   /* allocate audio datastructure */
 
   /* open video device and prepare data structure */
-  source_dev = open(dev,O_RDONLY);
-  if (source_dev < 0) {
+  if (strcmp(dev,"stdin")==0) {
+    source_dev = stdin;
+  } else {
+    source_dev = fopen(dev,"r");
+  }
+  if (source_dev == NULL) {
     fprintf(stderr, "error opening source device\n");
     exit(1);
   }