]> rtime.felk.cvut.cz Git - frescor/streamer.git/commitdiff
Update
authorluca <luca@dhcp124.science.unitn.it>
Fri, 27 Feb 2009 08:36:40 +0000 (09:36 +0100)
committerluca <luca@dhcp124.science.unitn.it>
Fri, 27 Feb 2009 08:36:40 +0000 (09:36 +0100)
rt.c
rt_qosmgr.c

diff --git a/rt.c b/rt.c
index 34f859f5eaaf1ea9791805c98cd73dada4180cd4..1261012c6cdfb9cdb5ce01948d81953540d1f4ed 100644 (file)
--- a/rt.c
+++ b/rt.c
@@ -6,6 +6,11 @@ static uint64_t start_time, start_time1;
 
 void rt_job_start(uint64_t t)
 {
+extern int fps;
+#if 1
+  t += (1000000ul / fps);      /* Hack to work around v4l2vd bug... */
+#endif
+
   start_time = t;
   start_time1 = av_gettime();
 }
index ba2984fb7b1a7fd0049199d4c53ee34739cedf17..fd22298a1a6b48da0cc2d97ef19f7df9cb3a7e33 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include <ffmpeg/avformat.h>
+#include <libavformat/avformat.h>
 
 #define QOS_DEBUG_LEVEL QOS_LEVEL_DEBUG
 #include <linux/aquosa/qos_debug.h>
@@ -8,18 +8,30 @@
 #include <aquosa/percpred_lib.h>
 #include <aquosa/stochdb_lib.h>
 
+extern int fps;
+
 #define SERV_PERIOD 10000lu    /* us */
 #define TASK_PERIOD 40000lu    /* us */
 #define SAMPLE_SZ 3
 #define DISCARDED 1    /* discard 1 out of 3 ==> percentile = 66.66% */
 
 static uint64_t start_time, start_time1;
+static uint64_t thebeginning;
+static int cnt;
 
 void rt_job_start(uint64_t t)
 {
   static int started = 0;
+  struct timespec now, now1;
+  static int64_t delta;
+  int64_t dl;
+
+#if 1
+  t += (1000000ul / fps);      /* Hack to work around v4l2vd bug... */
+#endif
 
   if (! started) {
+    thebeginning = t;
     started = 1;
     qos_log_debug("Initializing qmgr library\n");
     qos_chk_ok_exit(qmgr_init());
@@ -38,19 +50,26 @@ void rt_job_start(uint64_t t)
 
     qos_log_debug("Setting controller\n");
     /* Defaults to null target s.e. */
+    //qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_INVARIANT/*STOCHDB*/));
     qos_chk_ok_exit(qmgr_set_controller(QMGR_CTRL_STOCHDB));
 
     qos_log_debug("Setting controller parameters\n");
     /* Assign task period and granularity */
-    qmgr_set_task_period(TASK_PERIOD);
-    qmgr_set_server_period(SERV_PERIOD);
+    qmgr_set_task_period(1000000 / fps);
+    qmgr_set_server_period(1000000 / fps / 6);
     qmgr_set_max_bandwidth(0.95);
 
     qos_log_debug("Starting control loop");
     qos_chk_ok_exit(qmgr_start());
+    clock_gettime(CLOCK_MONOTONIC, &now);
+    clock_gettime(CLOCK_REALTIME, &now1);
+    delta = (now1.tv_sec - now.tv_sec) * 1000000ll + (now1.tv_nsec - now.tv_nsec) / 1000ll;
   }
-
-  qos_chk_ok_exit(qmgr_begin_cycle());
+  dl = t + (1000000ul / fps);
+  dl -= delta;
+  now.tv_nsec = (dl % 1000000) * 1000;
+  now.tv_sec = dl / 1000000;
+  qmgr_begin_cycle_deadline(&now);
   start_time = t;
   start_time1 = av_gettime();
 }
@@ -58,11 +77,14 @@ void rt_job_start(uint64_t t)
 void rt_job_end(void)
 {
   uint64_t t;
-  qres_time_t sched_err;
+  qres_time_t sched_err, etime;
 
   t = av_gettime();
-  qos_log_debug("%lu %lu %lu\t%lu %lu\n", start_time, start_time1, t, t - start_time, t - start_time1);
-
-  qmgr_end_cycle(&sched_err);
-  qos_log_debug("Ending job: " QRES_TIME_FMT "\n", sched_err);
+  printf("%lu %lu %lu\t%lu %lu\t", start_time, start_time1, t, t - start_time, t - start_time1);
+  if (cnt == 0) printf("0\t");
+  else printf("%lu\t", (start_time - thebeginning) / cnt);
+  cnt++;
+  qmgr_end_cycle(&sched_err, &etime);
+  printf(QRES_TIME_FMT "\n", sched_err);
+  //qos_log_debug("Ending job: " QRES_TIME_FMT "\n", sched_err);
 }