Player: support exu as source

master
Daniel Zaoui 5 years ago
parent 5555a38c1e
commit 1086aa6885
  1. 176
      src/bin/player.c

@ -26,16 +26,19 @@
typedef enum
{
DEST_UNKNOWN,
DEST_DIR,
DEST_EXU
} Dest_Type;
FTYPE_UNKNOWN,
FTYPE_DIR,
FTYPE_REC = FTYPE_DIR,
FTYPE_EXU
} File_Type;
static Dest_Type _dest_type = DEST_UNKNOWN;
static File_Type _dest_type = FTYPE_UNKNOWN;
static const char *_dest = NULL;
static Exactness_Unit *_dest_unit = NULL;
static const char *_rec_filename = NULL;
static File_Type _src_type = FTYPE_UNKNOWN;
static const char *_src_filename = NULL;
static Exactness_Unit *_src_unit = NULL;
static const char *_test_name = NULL;
static int _verbose = 0;
@ -44,7 +47,6 @@ static Evas *(*_evas_new)(void) = NULL;
static int _ignore_evas_creation = 0;
static Eina_List *_evas_list = NULL;
static Lists_st *_events_list = NULL;
static Eina_List *_cur_event_list = NULL;
static unsigned int _last_event_time = 0;
@ -78,7 +80,7 @@ _shot_do(Evas *e)
ecore_evas_geometry_get(ee_orig, NULL, NULL, &w, &h);
if ((w < 1) || (h < 1)) return;
if (_dest_type == DEST_DIR)
if (_dest_type == FTYPE_DIR)
{
int dir_name_len;
char *filename;
@ -108,7 +110,7 @@ _shot_do(Evas *e)
free(filename);
ecore_evas_free(ee);
}
else if (_dest_type == DEST_EXU)
else if (_dest_type == FTYPE_EXU)
{
Exactness_Image *ex_img = malloc(sizeof(*ex_img));
ex_img->w = w;
@ -117,7 +119,7 @@ _shot_do(Evas *e)
ex_img->pixels = malloc(ex_img->pixels_count);
memcpy(ex_img->pixels, pixels, ex_img->pixels_count);
_dest_unit->imgs = eina_list_append(_dest_unit->imgs, ex_img);
_printf(1, "Shot taken (in .exu).\n");
_printf(1, "Shot taken (in %s).\n", _dest);
}
}
@ -333,7 +335,7 @@ _feed_event(void *data EINA_UNUSED)
_printf(2, "%s take shot timestamp=<%u> t->n_evas=<%d>\n", __func__, t->timestamp, t->n_evas);
if (rect) evas_object_color_set(rect, 0, 0, 255, 255);
_cur_shot_id++;
if (_dest_type != DEST_UNKNOWN && e) _shot_do(e);
if (_dest_type != FTYPE_UNKNOWN && e) _shot_do(e);
break;
}
default: /* All non-input events are not handeled */
@ -369,37 +371,61 @@ _feed_event(void *data EINA_UNUSED)
}
static Eina_Bool
_rec_open()
_src_open()
{
unsigned int first_tm = 0;
double diff_time = 0; /* Time to wait before feeding the first event */
_printf(2, "<%s> rec file is <%s>\n", __func__, _rec_filename);
_events_list = read_events(_rec_filename, NULL);
if (_events_list)
_printf(2, "<%s> Source file is <%s>\n", __func__, _src_filename);
if (_src_type == FTYPE_EXU)
{
_cur_event_list = _events_list->variant_list;
Variant_st *v = eina_list_data_get(_cur_event_list);
/* Calculate the time to wait before feeding the first event */
unsigned int current_event_time = evt_time_get(0, v);
if (current_event_time > _events_list->first_timestamp)
diff_time = (current_event_time - _events_list->first_timestamp) / 1000.0;
_printf(2, "%s first_time_stamp=<%u> current_event_time=<%u>\n", __func__, _events_list->first_timestamp, current_event_time);
if (diff_time)
Eet_File *file = eet_open(_src_filename, EET_FILE_MODE_READ);
if (!file)
{
fprintf(stderr, "Impossible to extract EET from %s\n", _src_filename);
return EINA_FALSE;
}
_src_unit = eet_data_read(file, unit_desc_make(), CACHE_FILE_ENTRY);
eet_close(file);
}
else if (_src_type == FTYPE_REC)
{
_src_unit = calloc(1, sizeof(*_src_unit));
Lists_st *events_list = read_events(_src_filename, NULL);
if (!events_list)
{
_printf(2, " Waiting <%f>\n", diff_time);
ecore_timer_add(diff_time, _feed_event, NULL);
free(_src_unit);
_src_unit = NULL;
}
else
{
_feed_event(NULL);
_src_unit->events = events_list->variant_list;
first_tm = events_list->first_timestamp;
}
}
if (!_src_unit) return EINA_FALSE;
_cur_event_list = _src_unit->events;
Variant_st *v = eina_list_data_get(_cur_event_list);
/* Calculate the time to wait before feeding the first event */
unsigned int current_event_time = evt_time_get(0, v);
if (current_event_time > first_tm)
diff_time = (current_event_time - first_tm) / 1000.0;
_printf(2, "%s first_time_stamp=<%u> current_event_time=<%u>\n", __func__, first_tm, current_event_time);
if (diff_time)
{
_printf(2, " Waiting <%f>\n", diff_time);
ecore_timer_add(diff_time, _feed_event, NULL);
}
else
{
_feed_event(NULL);
}
return EINA_TRUE;
}
static Eina_Bool
static int
_prg_invoke(const char *full_path, int argc, char **argv)
{
Eina_Value *ret__;
@ -413,7 +439,7 @@ _prg_invoke(const char *full_path, int argc, char **argv)
{
fprintf(stderr, "Failed loading %s.\n", full_path);
if (h) eina_module_free(h);
return EINA_FALSE;
return 1;
}
efl_main = eina_module_symbol_get(h, "efl_main");
elm_main = eina_module_symbol_get(h, "elm_main");
@ -423,34 +449,38 @@ _prg_invoke(const char *full_path, int argc, char **argv)
{
fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
eina_module_free(h);
return EINA_FALSE;
return 1;
}
_rec_open();
if (efl_main)
{
elm_init(argc, argv);
efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
ret__ = efl_loop_begin(efl_main_loop_get());
real__ = efl_loop_exit_code_process(ret__);
elm_shutdown();
}
else if (elm_main)
{
elm_init(argc, argv);
real__ = elm_main(argc, argv);
elm_shutdown();
}
else if (c_main)
{
real__ = c_main(argc, argv);
}
else
if (_src_open())
{
fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
eina_module_free(h);
real__ = 1;
if (efl_main)
{
elm_init(argc, argv);
efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
ret__ = efl_loop_begin(efl_main_loop_get());
real__ = efl_loop_exit_code_process(ret__);
elm_shutdown();
}
else if (elm_main)
{
elm_init(argc, argv);
real__ = elm_main(argc, argv);
elm_shutdown();
}
else if (c_main)
{
real__ = c_main(argc, argv);
}
else
{
fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
eina_module_free(h);
real__ = 1;
}
}
else real__ = 1;
return real__;
}
@ -541,6 +571,7 @@ int main(int argc, char **argv)
const char *engine = "buffer";
eina_init();
eet_init();
opterr = 0;
for (int opt; (opt = getopt(argc, argv, "+so:vt:h")) != -1;)
@ -558,7 +589,7 @@ int main(int argc, char **argv)
_dest = eina_stringshare_add(optarg);
if (!strcmp(_dest + strlen(_dest) - 4,".exu"))
{
_dest_type = DEST_EXU;
_dest_type = FTYPE_EXU;
if (!_mkdir(_dest, EINA_TRUE))
{
fprintf(stderr, "Path for %s cannot be created\n", _dest);
@ -567,7 +598,7 @@ int main(int argc, char **argv)
}
else
{
_dest_type = DEST_DIR;
_dest_type = FTYPE_DIR;
if (!_mkdir(_dest, EINA_FALSE))
{
fprintf(stderr, "Directory %s cannot be created\n", _dest);
@ -578,17 +609,22 @@ int main(int argc, char **argv)
}
case 't':
{
_rec_filename = eina_stringshare_add(optarg);
if (_dest_type == DEST_UNKNOWN)
_src_filename = eina_stringshare_add(optarg);
if (!strcmp(_src_filename + strlen(_src_filename) - 4,".exu"))
{
if (!strcmp(_rec_filename + strlen(_rec_filename) - 4,".exu"))
_src_type = FTYPE_EXU;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = DEST_EXU;
_dest_type = FTYPE_EXU;
_dest = "./output.exu";
}
else if (!strcmp(_rec_filename + strlen(_rec_filename) - 4,".rec"))
}
else if (!strcmp(_src_filename + strlen(_src_filename) - 4,".rec"))
{
_src_type = FTYPE_REC;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = DEST_DIR;
_dest_type = FTYPE_DIR;
_dest = ".";
}
}
@ -618,21 +654,21 @@ int main(int argc, char **argv)
fprintf(stderr, "no program specified\nUse -h for more information\n");
goto end;
}
if (!_rec_filename)
if (!_src_filename)
{
fprintf(stderr, "no test file specified\n");
goto end;
}
else
{
char *slash = strrchr(_rec_filename, '/');
char *slash = strrchr(_src_filename, '/');
if (slash) _test_name = strdup(slash + 1);
else _test_name = strdup(_rec_filename);
else _test_name = strdup(_src_filename);
char *dot = strrchr(_test_name, '.');
if (dot) *dot = '\0';
}
if (_dest_type == DEST_EXU)
if (_dest_type == FTYPE_EXU)
{
_dest_unit = calloc(1, sizeof(*_dest_unit));
}
@ -655,19 +691,19 @@ int main(int argc, char **argv)
_printf(1, "\n");
ecore_evas_callback_new_set(_my_evas_new);
_prg_invoke(_prg_full_path_guess(argv[0]), argc - optind, argv);
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - optind, argv);
if (_dest_unit)
{
_dest_unit->events = _events_list->variant_list;
_dest_unit->events = _src_unit->events;
Eet_Data_Descriptor *unit_edd = unit_desc_make();
Eet_File *file = eet_open(_dest, EET_FILE_MODE_WRITE);
eet_data_write(file, unit_edd, CACHE_FILE_ENTRY, _dest_unit, EINA_TRUE);
eet_close(file);
}
pret = 0;
end:
eet_shutdown();
eina_shutdown();
return pret;
}

Loading…
Cancel
Save