]> rtime.felk.cvut.cz Git - frescor/streamer.git/commitdiff
Display FPS and increase bitrate
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 27 Nov 2009 18:08:31 +0000 (19:08 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 27 Nov 2009 18:08:31 +0000 (19:08 +0100)
streamer.c

index ee77884582e479cef4d6a6ed74d3b35e7b7cf431..0a93751f75069a17e63c57a737e84db3014386b8 100644 (file)
@@ -126,10 +126,40 @@ static int args_parse(int argc, char *argv[])
 
 int streamer_run_done_rq;
 
+int
+timespec_subtract (struct timespec *result,
+                  struct timespec *x,
+                  struct timespec *y)
+{
+  /* Perform the carry for the later subtraction by updating Y. */
+  if (x->tv_nsec < y->tv_nsec) {
+    int num_sec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
+    y->tv_nsec -= 1000000000 * num_sec;
+    y->tv_sec += num_sec;
+  }
+  if (x->tv_nsec - y->tv_nsec > 1000000000) {
+    int num_sec = (x->tv_nsec - y->tv_nsec) / 1000000000;
+    y->tv_nsec += 1000000000 * num_sec;
+    y->tv_sec -= num_sec;
+  }
+
+  /* Compute the time remaining to wait.
+     `tv_nsec' is certainly positive. */
+  result->tv_sec = x->tv_sec - y->tv_sec;
+  result->tv_nsec = x->tv_nsec - y->tv_nsec;
+
+  /* Return 1 if result is negative. */
+  return x->tv_sec < y->tv_sec;
+}
+
+
 void* streamer_run(void* args)
 {
   int done;
-
+  int frame = 0;
+  int fps_avg = 0;
+  struct timespec start, end, d;
+  clock_gettime(CLOCK_MONOTONIC, &start);
   done = 0;
   while (!(done = streamer_run_done_rq)) {
     AVPacket *pkt;
@@ -147,7 +177,18 @@ void* streamer_run(void* args)
         opkt = pkt_encode(os, f);
         if (opkt) {
           pkt_send(os, opkt);
-         printf("opkt size: %d\n", opkt->size);
+
+         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;
+       
+         printf("%5d: %d fps  opkt size: %d\n",
+                frame,
+                fps_avg>>8,
+                opkt->size);
+         frame++;// = (frame + 1) % fps;
         }
       }
       //rt_job_end();
@@ -214,7 +255,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 = 300000;
+  os->streams[0]->codec->bit_rate = 1000000;
   codec_connect(s->streams[0]->codec, os->streams[0]->codec);
   out_codec_open(os);
   dump_format(os, 0, os->filename, 1);