]> rtime.felk.cvut.cz Git - frescor/streamer.git/blobdiff - streamer.c
Contract parameters are based on encoding bitrate
[frescor/streamer.git] / streamer.c
index 0a93751f75069a17e63c57a737e84db3014386b8..128a154252e2689c05874b251ef813e89900a7e3 100644 (file)
 #include <frsh.h>
 
 /*temporrary solution to pass network parameters */
-extern long int avformat_frsh_budget, avformat_frsh_period;
+extern long int frsh_rtp_budget, frsh_rtp_period_ms, frsh_rtp_deadline_ms;
 #endif /*CONFIG_STREAMER_WITH_FRSH*/
 
 static const char *sdp_file = "sdp.txt";
 static const char *vdev = "/dev/video0";
 static const char *dst = "127.0.0.1";
 static int dport = 20000;
-static int width = 352;
-static int height = 288;
-int fps = 25;
+static int width = 320;
+static int height = 240;
+static int bitrate = 1000000;
+int fps = 15;
 static const char *impform = "video4linux2";
 AVFormatContext *s, *os;
 
@@ -62,10 +63,8 @@ usage(void)
        printf("  -r <path>      video device [%s]\n", vdev);
        printf("  -m <addr>      destination IP address\n");
        printf("  -i <string>    input video device format [%s]\n", impform);
-      #ifdef CONFIG_STREAMER_WITH_FRSH
-       printf("  -b <number>    network budget\n");
-       printf("  -p <number>    network period for given budget\n");
-      #endif /*CONFIG_STREAMER_WITH_FRSH*/
+       printf("  -p <port>      destination port [%d]\n", dport);
+       printf("  -b <bitrate>   bitrate in b/s [%d]\n", bitrate);
       #ifdef CONFIG_OC_ULUT
        printf("  -l <number>|<domain>=<number>,...\n");
       #endif /*CONFIG_OC_ULUT*/
@@ -77,6 +76,9 @@ static int args_parse(int argc, char *argv[])
 
   while ((v = getopt(argc, argv, "w:h:r:d:m:i:l:b:p:")) >= 0) {
     switch (v) {
+      case 'p':
+        dport = atoi(optarg);
+        break;
       case 'w':
         width = atoi(optarg);
         break;
@@ -86,6 +88,9 @@ static int args_parse(int argc, char *argv[])
       case 'r':
         fps = atoi(optarg);
         break;
+      case 'b':
+       bitrate = atoi(optarg);
+       break;
       case 'd':
         vdev = optarg;
         break;
@@ -99,15 +104,6 @@ static int args_parse(int argc, char *argv[])
        else if(!strcmp(impform, "v4l2"))
          impform = "video4linux2";
         break;
-      #ifdef CONFIG_STREAMER_WITH_FRSH
-      case 'b':
-       udp_budget = atol(optarg);
-       break;
-      case 'p':
-       udp_period = atol(optarg);
-       break;
-      #endif /*CONFIG_STREAMER_WITH_FRSH*/
-
       #ifdef CONFIG_OC_ULUT
       case 'l':
        ul_log_domain_arg2levels(optarg);
@@ -159,6 +155,8 @@ void* streamer_run(void* args)
   int frame = 0;
   int fps_avg = 0;
   struct timespec start, end, d;
+  static unsigned max_size = 0, min_size = -1;
+  static double avg_size = 0;
   clock_gettime(CLOCK_MONOTONIC, &start);
   done = 0;
   while (!(done = streamer_run_done_rq)) {
@@ -183,11 +181,17 @@ void* streamer_run(void* args)
          int fps_now = (1000<<8)/(d.tv_sec*1000+d.tv_nsec/1000000);
          start = end;
          fps_avg += (fps_now - fps_avg) >> 3;
-       
-         printf("%5d: %d fps  opkt size: %d\n",
+
+         if (opkt->size > max_size)
+                 max_size = opkt->size;
+         if (opkt->size < min_size)
+                 min_size = opkt->size;
+         avg_size = avg_size*frame/(frame+1) + (double)opkt->size/(frame+1);
+         printf("%5d: %2d fps  opkt size: %5d b  max=%5u b min=%5u b avg=%5.0f\n",
                 frame,
                 fps_avg>>8,
-                opkt->size);
+                opkt->size, max_size, min_size, avg_size);
+         if (frame % 100 == 0) max_size=0;
          frame++;// = (frame + 1) % fps;
         }
       }
@@ -229,8 +233,9 @@ int main(int argc, char *argv[])
   if (ret) PERROR_AND_EXIT(ret, "frsh_init1");
 
   /* fill default network contract params */
-  avformat_frsh_budget = 50000; 
-  avformat_frsh_period = 500;
+  frsh_rtp_budget = bitrate/8; 
+  frsh_rtp_period_ms = 1000;
+  frsh_rtp_deadline_ms = 1000/fps;
 #endif /*CONFIG_FFMPEG_WITH_FRSH*/
 
   avcodec_register_all();
@@ -255,7 +260,7 @@ int main(int argc, char *argv[])
   os->streams[0]->codec->width = s->streams[0]->codec->width;
   os->streams[0]->codec->height = s->streams[0]->codec->height;
   os->streams[0]->codec->time_base = s->streams[0]->codec->time_base;
-  os->streams[0]->codec->bit_rate = 1000000;
+  os->streams[0]->codec->bit_rate = bitrate;
   codec_connect(s->streams[0]->codec, os->streams[0]->codec);
   out_codec_open(os);
   dump_format(os, 0, os->filename, 1);