]> rtime.felk.cvut.cz Git - frescor/demo.git/blobdiff - src/recorder/ffmpeg.c
recorder: Decrease CPU budget
[frescor/demo.git] / src / recorder / ffmpeg.c
index ba6a68f82b7f45f71413d960c2fa11f2d3c9f102..d5b0c7f2d9793be5fd38e4b852e6b39ae248fd1f 100644 (file)
@@ -180,6 +180,7 @@ static int64_t rec_timestamp = 0;
 static int64_t input_ts_offset = 0;
 static int file_overwrite = 0;
 static int o_direct = 0;
+static const char *contract_label = "recorder";
 static int metadata_count;
 static AVMetadataTag *metadata;
 static int do_benchmark = 0;
@@ -1590,6 +1591,7 @@ timespec_subtract (struct timespec *result,
 
 #ifdef CONFIG_FFMPEG_WITH_FRSH
 frsh_vres_id_t disk_vres;
+frsh_contract_t cpu_contract;
 frsh_contract_t disk_contract;
 #endif
 
@@ -1614,8 +1616,10 @@ print_timing(void)
               f, 1/ifi, 1/ifi_avg, 1/sqrt(ifi_var));
 
 #ifdef CONFIG_FFMPEG_WITH_FRSH
-       if (renegotiate == f)
+       if (renegotiate == f) {
                frsh_contract_renegotiate_sync(&disk_contract, disk_vres);
+               frsh_contract_renegotiate_sync(&disk_contract, disk_vres);
+       }
 #endif
 out:
        start = end;
@@ -2891,6 +2895,11 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
     return codec->id;
 }
 
+static void opt_contract_label(const char *label)
+{
+    contract_label = label;
+}
+
 static void opt_input_file(const char *filename)
 {
     AVFormatContext *ic;
@@ -3898,6 +3907,7 @@ static const OptionDef options[] = {
     { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
     { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
+    { "contract_label", HAS_ARG, {(void*)opt_contract_label}, "contract label", "label" },
     { "direct", OPT_BOOL, {(void*)&o_direct}, "write to output file using direct I/O (O_DIRECT)" },
     { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" },
     { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" },
@@ -4038,17 +4048,14 @@ int frsh_stuff()
     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;
 
     frsh_rel_time_t disk_budget, disk_period;
 
-    int ret, terror;
+    int ret;
 
-    PXW(frsh_init());
     cpu_budget = fosa_msec_to_rel_time(5);
-    cpu_period = fosa_msec_to_rel_time(1000/50);
+    cpu_period = fosa_msec_to_rel_time(1000/30);
 
 #if 1
 #define DISK_THROUGHPUT 20277LLU /* units??? probably MB/s */
@@ -4070,7 +4077,7 @@ int frsh_stuff()
                                         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, FRSH_CPU_ID_DEFAULT, "recorder");
+                                              FRSH_RT_PROCESSOR, FRSH_CPU_ID_DEFAULT, contract_label);
     if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
 
     ret = frsh_contract_negotiate(&cpu_contract, &cpu_vres);
@@ -4088,7 +4095,8 @@ int frsh_stuff()
                                         FRSH_CT_REGULAR);
     if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
     ret = frsh_contract_set_resource_and_label(&disk_contract, 
-                                              FRSH_RT_DISK, 0, output_files[0]->filename);
+                                              FRSH_RT_DISK, 0, strstr(output_files[0]->filename, "://") == NULL ?
+                                              output_files[0]->filename : input_files[0]->filename);
     if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
 
     ret = frsh_contract_negotiate(&disk_contract, &disk_vres);
@@ -4143,6 +4151,14 @@ int main(int argc, char **argv)
 
     show_banner();
 
+#if CONFIG_FFMPEG_WITH_FRSH
+    {
+       int terror;
+       PXW(frsh_init());
+       printf("FRSH initialized\n");
+    }
+#endif
+
     /* parse options */
     parse_options(argc, argv, options, opt_output_file);