]> rtime.felk.cvut.cz Git - frescor/streamer.git/commitdiff
Add support for cpu contracts.
authorMartin Molnar <molnam1@fel.cvut.cz>
Wed, 27 May 2009 10:52:49 +0000 (12:52 +0200)
committerMartin <molnam1@fel.cvut.cz>
Wed, 27 May 2009 10:52:49 +0000 (12:52 +0200)
Signed-off-by: Martin <molnam1@fel.cvut.cz>
streamer.c

index a7e4119d1eb580703fed2567191cdefb32c9abf0..eb8adde59b6c2a1d06fa686fda07c2917806f0bd 100644 (file)
@@ -36,6 +36,7 @@ static int width = 352;
 static int height = 288;
 int fps = 25;
 static const char *impform = "video4linux2";
+AVFormatContext *s, *os;
 
 static void sdp_print(AVFormatContext *s, const char *fname)
 {
@@ -107,16 +108,49 @@ static int args_parse(int argc, char *argv[])
   return 0;
 }
 
+void* streamer_run(void* args)
+{
+  int done;
+
+  done = 0;
+  while (!done) {
+    AVPacket *pkt;
+    pkt = read_input_packet(s);
+    if (pkt == NULL) {
+      done = 1;
+    } else {
+      AVFrame *f;
+      AVPacket *opkt;
+
+      pkt->pts += s->streams[pkt->stream_index]->start_time;
+      //rt_job_start(pkt->pts);
+      f = pkt_decode(s, pkt);
+      if (f) {
+        opkt = pkt_encode(os, f);
+        if (opkt) {
+          pkt_send(os, opkt);
+        }
+      }
+      //rt_job_end();
+      av_free_packet(pkt);
+    }
+  }
+
+  return NULL;
+}
+
 int main(int argc, char *argv[])
 {
-  AVFormatContext *s, *os;
-  int done, ret;
+
+  //long int cpu_budget, cpu_period;
+  int ret;
 
 #ifdef CONFIG_STREAMER_WITH_FRSH
   ret = frsh_init();
   if (ret) PERROR_AND_EXIT(ret, "frsh_init1");
 #endif /*CONFIG_STREAMER_WITH_FRSH*/
-
+  
+  /* fill contract params */
   udp_budget = 50000; 
   udp_period = 500;
   
@@ -146,29 +180,51 @@ int main(int argc, char *argv[])
   out_codec_open(os);
   dump_format(os, 0, os->filename, 1);
   sdp_print(os, sdp_file);
-  done = 0;
-  while (!done) {
-    AVPacket *pkt;
-    pkt = read_input_packet(s);
-    if (pkt == NULL) {
-      done = 1;
-    } else {
-      AVFrame *f;
-      AVPacket *opkt;
 
-      pkt->pts += s->streams[pkt->stream_index]->start_time;
-      //rt_job_start(pkt->pts);
-      f = pkt_decode(s, pkt);
-      if (f) {
-        opkt = pkt_encode(os, f);
-        if (opkt) {
-          pkt_send(os, opkt);
-        }
-      }
-      //rt_job_end();
-      av_free_packet(pkt);
-    }
-  }
+#ifdef 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);
+  /* Contract negotiation for CPU */
+  ret = frsh_contract_init(&cpu_contract);
+  if (ret) PERROR_AND_EXIT(ret, "CPU:frsh_contract_init");
+  ret = frsh_contract_set_basic_params(&cpu_contract,
+                                            &cpu_budget,
+                                            &cpu_period,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       ret = frsh_contract_set_resource_and_label(&cpu_contract, 
+                       FRSH_RT_PROCESSOR, 0,"aqcpu_cont");
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+       ret = frsh_contract_negotiate(&cpu_contract, &cpu_vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+       printf("Aqcpu vres negotiated\n");
+
+       pthread_attr_init(&frsh_attr);
+       ret = frsh_thread_create_and_bind(cpu_vres, &thread, &frsh_attr, 
+                               streamer_run, (void*) NULL);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_thread_create_and_bind");
+       
+       pthread_join(thread.pthread_id, (void**) NULL); 
+#else
+       pthread_attr_t attr;
+       pthread_t streamer_th;
+
+       pthread_attr_init(&attr);
+
+       ret = pthread_create(&streamer_th, &attr, streamer_run, (void*) NULL);
+       if (ret) 
+                       printf("Failed to create streamer thread\n.");
+       pthread_join(streamer_th, (void**) NULL);
+#endif
 
   return 0;
 }