From: Martin Molnar Date: Wed, 27 May 2009 10:52:49 +0000 (+0200) Subject: Add support for cpu contracts. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/streamer.git/commitdiff_plain/219e11f0082c7d91abafa983a6679d1ee0e58708 Add support for cpu contracts. Signed-off-by: Martin --- diff --git a/streamer.c b/streamer.c index a7e4119..eb8adde 100644 --- a/streamer.c +++ b/streamer.c @@ -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; }