]> rtime.felk.cvut.cz Git - frescor/streamer.git/blobdiff - streamer.c
Print * for every key frame
[frescor/streamer.git] / streamer.c
index 7ec7f8a35cc8f90dbc05e04308f47efe4447a9d1..ff58d467921f086447da831f66afb45445fbacd8 100644 (file)
@@ -38,7 +38,7 @@ static int dport = 20000;
 static int width = 320;
 static int height = 240;
 static int bitrate = 1000000;
-int fps = 15;
+int fps = 30;
 static const char *impform = "video4linux2";
 AVFormatContext *s, *os;
 
@@ -65,6 +65,7 @@ usage(void)
        printf("  -i <string>    input video device format [%s]\n", impform);
        printf("  -p <port>      destination port [%d]\n", dport);
        printf("  -b <bitrate>   bitrate in b/s [%d]\n", bitrate);
+       printf("  -s <sdp_file>  name of output sdp file [%s]\n", sdp_file);
       #ifdef CONFIG_OC_ULUT
        printf("  -l <number>|<domain>=<number>,...\n");
       #endif /*CONFIG_OC_ULUT*/
@@ -74,8 +75,11 @@ static int args_parse(int argc, char *argv[])
 {
   int v;
 
-  while ((v = getopt(argc, argv, "w:h:r:d:m:i:l:b:p:")) >= 0) {
+  while ((v = getopt(argc, argv, "w:h:r:d:m:i:l:b:p:s:")) >= 0) {
     switch (v) {
+      case 's':
+       sdp_file = optarg;
+       break;
       case 'p':
         dport = atoi(optarg);
         break;
@@ -158,10 +162,18 @@ void* streamer_run(void* args)
   static unsigned max_size = 0, min_size = -1;
   static double avg_size = 0;
   clock_gettime(CLOCK_MONOTONIC, &start);
+  start.tv_sec--;              /* Avoid division by zero */
   done = 0;
   while (!(done = streamer_run_done_rq)) {
     AVPacket *pkt;
     pkt = read_input_packet(s);
+
+    clock_gettime(CLOCK_MONOTONIC, &end);
+    timespec_subtract(&d, &end, &start);
+    start = end;
+    int fps_now = (1000<<16)/(d.tv_sec*1000+d.tv_nsec/1000000);
+    fps_avg += (fps_now - fps_avg) >> 4;
+    
     if (pkt == NULL) {
       done = 1;
     } else {
@@ -172,24 +184,20 @@ void* streamer_run(void* args)
       //rt_job_start(pkt->pts);
       f = pkt_decode(s, pkt);
       if (f) {
+        int keyframe;
         opkt = pkt_encode(os, f);
+       keyframe = os->streams[0]->codec->coded_frame->key_frame;
         if (opkt) {
           pkt_send(os, opkt);
 
-         clock_gettime(CLOCK_MONOTONIC, &end);
-         timespec_subtract(&d, &end, &start);
-         int fps_now = (1000<<8)/(d.tv_sec*1000+d.tv_nsec/1000000);
-         start = end;
-         fps_avg += (fps_now - fps_avg) >> 3;
-
          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,
+         printf("%5d%c: %2d (%4.1f) fps  opkt size: %5d b  max=%5u b min=%5u b avg=%5.0f\n",
+                frame, keyframe ? '*':' ',
+                fps_avg>>16, 1000.0/(d.tv_sec*1000+d.tv_nsec/1000000),
                 opkt->size, max_size, min_size, avg_size);
          if (frame % 100 == 0) max_size=0;
          frame++;// = (frame + 1) % fps;
@@ -266,15 +274,15 @@ int main(int argc, char *argv[])
   dump_format(os, 0, os->filename, 1);
   sdp_print(os, sdp_file);
 
-#if CONFIG_STREAMER_WITH_FRSH && CONFIG_AQUOSA 
+#if CONFIG_FFMPEG_WITH_FRSH && CONFIG_AQUOSA
   frsh_thread_attr_t frsh_attr;
   frsh_thread_id_t thread;
   frsh_vres_id_t cpu_vres;
   frsh_contract_t cpu_contract;
   frsh_rel_time_t cpu_budget, cpu_period;
  
-  cpu_budget = fosa_msec_to_rel_time(50);
-  cpu_period = fosa_msec_to_rel_time(100);
+  cpu_budget = fosa_msec_to_rel_time(10);
+  cpu_period = fosa_msec_to_rel_time(1000/fps);
   /* Contract negotiation for CPU */
   ret = frsh_contract_init(&cpu_contract);
   if (ret) PERROR_AND_EXIT(ret, "CPU:frsh_contract_init");