]> rtime.felk.cvut.cz Git - frescor/streamer.git/commitdiff
Make some parameters configurable
authorLuca <luca@luca.(none)>
Fri, 26 Dec 2008 14:56:12 +0000 (15:56 +0100)
committerLuca <luca@luca.(none)>
Fri, 26 Dec 2008 14:56:12 +0000 (15:56 +0100)
input.c
input.h
streamer.c

diff --git a/input.c b/input.c
index 02a8b20113759775546d30a18eaf89cec866abb8..11e6027cfb23e8ae90dbe872455a2849dae0bda3 100644 (file)
--- a/input.c
+++ b/input.c
@@ -30,7 +30,7 @@ static void time_base_convert(AVPacket *pkt, AVStream *st)
   }
 }
 
-AVFormatContext *open_input_stream(const char *fname)
+AVFormatContext *open_input_stream(const char *fname, int w, int h, int fps)
 {
     AVFormatContext *s;
     AVInputFormat *fmt;
@@ -39,10 +39,10 @@ AVFormatContext *open_input_stream(const char *fname)
 
     memset(&param, 0, sizeof(AVFormatParameters));
     /* FIXME: Set these!!! */
-    param.width  = 352;
-    param.height = 288;
+    param.width  = w;
+    param.height = h;
     param.pix_fmt = PIX_FMT_YUV420P;
-    param.time_base.den = 25;
+    param.time_base.den = fps;
     param.time_base.num = 1;
     fmt = av_find_input_format("video4linux2");
     res = av_open_input_file(&s, fname, fmt, 0, &param);
diff --git a/input.h b/input.h
index 7fa7b9c8bbdbfe7fdf00f9515a83834a7b47cc4b..6a806837ac80a5db318f53b95cc62ed3bcbf6752 100644 (file)
--- a/input.h
+++ b/input.h
@@ -1,3 +1,3 @@
-AVFormatContext *open_input_stream(const char *fname);
+AVFormatContext *open_input_stream(const char *fname, int w, int h, int fps);
 void close_input_stream(AVFormatContext *s);
 AVPacket *read_input_packet(AVFormatContext *s);
index 2774a7a0344f40d4e85bb42d2c69653d190b4cab..38e46b9bc4c8e8ed3b7d6bcd51919f8eabfa492b 100644 (file)
@@ -1,3 +1,6 @@
+#include <unistd.h>
+#include <stdlib.h>
+
 #include "libavformat/avformat.h"
 #include "libavdevice/avdevice.h"
 
@@ -6,6 +9,13 @@
 #include "codec.h"
 #include "rt.h"
 
+static const char *vdev = "/dev/video0";
+static const char *dst = "224.10.20.30";
+static int dport = 20000;
+static int width = 352;
+static int height = 288;
+static int fps = 25;
+
 static void sdp_print(AVFormatContext *s)
 {
     char sdp[2048];
@@ -17,6 +27,35 @@ static void sdp_print(AVFormatContext *s)
     fclose(f);
 }
 
+static int args_parse(int argc, char *argv[])
+{
+  int v;
+
+  while ((v = getopt(argc, argv, "w:h:r:d:")) >= 0) {
+    switch (v) {
+      case 'w':
+        width = atoi(optarg);
+        break;
+      case 'h':
+        height = atoi(optarg);
+        break;
+      case 'r':
+        fps = atoi(optarg);
+        break;
+      case 'd':
+        vdev = optarg;
+        break;
+      case 'm':
+        dst = optarg;
+        break;
+      default: /* ’?’ */
+        fprintf(stderr, "%s: illegal option %c\n", argv[0], v);
+        exit(-1);
+    }
+  }
+
+  return 0;
+}
 
 int main(int argc, char *argv[])
 {
@@ -27,14 +66,16 @@ int main(int argc, char *argv[])
   av_register_all();
   avdevice_register_all();
 
-  s = open_input_stream(argv[1]);
+  args_parse(argc, argv);
+
+  s = open_input_stream(vdev, width, height, fps);
   if (s == NULL) {
-    fprintf(stderr, "Cannot open input file %s\n", argv[1]);
+    fprintf(stderr, "Cannot open input file %s\n", vdev);
 
     return -1;
   }
   codec_open(s);
-  os = open_output_stream("224.10.20.30", 20000, CODEC_TYPE_VIDEO);
+  os = open_output_stream(dst, dport, CODEC_TYPE_VIDEO);
   if (os == NULL) {
     fprintf(stderr, "Cannot open output stream\n");