]> rtime.felk.cvut.cz Git - frescor/streamer.git/blobdiff - streamer.c
Updated list of used libraries for omkized version of FFmpeg.
[frescor/streamer.git] / streamer.c
index 2774a7a0344f40d4e85bb42d2c69653d190b4cab..b11021213624facf83bdc7093cdd5f459a44ab89 100644 (file)
@@ -1,22 +1,68 @@
-#include "libavformat/avformat.h"
-#include "libavdevice/avdevice.h"
+/*
+ *  Copyright (c) 2008 Luca Abeni
+ *
+ *  This is free software; see GPL.txt
+ */
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <libavformat/avformat.h>
+#include <libavdevice/avdevice.h>
+#include <libswscale/swscale.h>
 
 #include "input.h"
 #include "output.h"
 #include "codec.h"
 #include "rt.h"
 
-static void sdp_print(AVFormatContext *s)
+static const char *sdp_file = "sdp.txt";
+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;
+int fps = 25;
+
+static void sdp_print(AVFormatContext *s, const char *fname)
 {
     char sdp[2048];
     FILE *f;
 
-    f = fopen("sdp.txt", "w");
+    f = fopen(fname, "w");
     avf_sdp_create(&s, 1, sdp, sizeof(sdp));
     fprintf(f, "%s\n", sdp);
     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 +73,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");
 
@@ -46,7 +94,7 @@ int main(int argc, char *argv[])
   codec_connect(s->streams[0]->codec, os->streams[0]->codec);
   out_codec_open(os);
   dump_format(os, 0, os->filename, 1);
-  sdp_print(os);
+  sdp_print(os, sdp_file);
   done = 0;
   while (!done) {
     AVPacket *pkt;
@@ -58,7 +106,7 @@ int main(int argc, char *argv[])
       AVPacket *opkt;
 
       pkt->pts += s->streams[pkt->stream_index]->start_time;
-      rt_job_start(pkt->pts);
+      //rt_job_start(pkt->pts);
       f = pkt_decode(s, pkt);
       if (f) {
         opkt = pkt_encode(os, f);
@@ -66,7 +114,7 @@ int main(int argc, char *argv[])
           pkt_send(os, opkt);
         }
       }
-      rt_job_end();
+      //rt_job_end();
       av_free_packet(pkt);
     }
   }