diff --git a/src/modules/Makefile_imfos.mk b/src/modules/Makefile_imfos.mk index afa8b538f..4388fd285 100755 --- a/src/modules/Makefile_imfos.mk +++ b/src/modules/Makefile_imfos.mk @@ -11,12 +11,14 @@ src_modules_imfos_module_la_LIBADD = $(MOD_LIBS) @IMFOS_LIBS@ src_modules_imfos_module_la_CPPFLAGS = $(MOD_CPPFLAGS) @IMFOS_CFLAGS@ src_modules_imfos_module_la_LDFLAGS = $(MOD_LDFLAGS) src_modules_imfos_module_la_SOURCES = src/modules/imfos/e_mod_main.h \ - src/modules/imfos/e_mod_main.c \ - src/modules/imfos/e_mod_config.c \ - src/modules/imfos/imfos_v4l.c \ - src/modules/imfos/imfos_v4l.h \ - src/modules/imfos/imfos_face.cpp \ - src/modules/imfos/imfos_face.h + src/modules/imfos/e_mod_main.c \ + src/modules/imfos/e_mod_config.c \ + src/modules/imfos/imfos_devices.c \ + src/modules/imfos/imfos_devices.h \ + src/modules/imfos/imfos_v4l.c \ + src/modules/imfos/imfos_v4l.h \ + src/modules/imfos/imfos_face.cpp \ + src/modules/imfos/imfos_face.h PHONIES += imfos install-imfos imfos: $(imfospkg_LTLIBRARIES) $(imfos_DATA) diff --git a/src/modules/imfos/e_mod_config.c b/src/modules/imfos/e_mod_config.c index dfd4a4146..00bf04def 100755 --- a/src/modules/imfos/e_mod_config.c +++ b/src/modules/imfos/e_mod_config.c @@ -1,14 +1,27 @@ #include +#include #include "e_mod_main.h" +#include "imfos_devices.h" +typedef struct _Imfos_Config_Panel +{ + Evas_Object *main; + Evas_Object *current; + Imfos_Device *dev; + Imfos_Device *config; + +} Imfos_Config_Panel; + +static void _v4l_create(void); +static void _device_create(void); static void *_create_data(E_Config_Dialog *cfd); static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); static void _fill_data(E_Config_Dialog_Data *cfdata); static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); static int _apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -Imfos_Config *imfos_config = NULL; - +Imfos_Config_Panel *_tmp_cfg = NULL; +static Evas_Object *_imfos_cam_widget = NULL; int flipped = EINA_FALSE; @@ -39,12 +52,17 @@ e_mod_config_imfos(Evas_Object *parent, const char *params EINA_UNUSED) static void * _create_data(E_Config_Dialog *cfd) { + _tmp_cfg = calloc(1, sizeof(Imfos_Config_Panel)); return NULL; } static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { + free(_tmp_cfg->config); + free(_tmp_cfg); + _tmp_cfg = NULL; + _imfos_cam_widget = NULL; } static void @@ -52,18 +70,162 @@ _fill_data(E_Config_Dialog_Data *cfdata) { } +static void +_imfos_device_changed(void *data) +{ + Imfos_Device *dev; + + dev = data; + if (_tmp_cfg->dev) + imfos_devices_cancel(_tmp_cfg->dev); + _tmp_cfg->dev = dev; + _tmp_cfg->config = malloc(sizeof(Imfos_Device)); + /* Warning just a copy ! */ + memcpy(_tmp_cfg->config, dev, sizeof(Imfos_Device)); + if (_tmp_cfg->current) + evas_object_del(_tmp_cfg->current); + _tmp_cfg->current = e_widget_list_add(evas_object_evas_get(_tmp_cfg->main), 0, 0); + e_widget_list_object_append(_tmp_cfg->main, _tmp_cfg->current, 1, 0, 0.5); + _device_create(); + printf ("sel %s\n", dev->name); + +} + +static void +_imfos_cam_widget_delete(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + Imfos_Device *dev; + + dev = data; + printf("deleting cam widget\n"); + + dev->param.v4l.cam = NULL; + imfos_devices_cancel(dev); +} + +static void +_fill_devices(Evas *evas, Evas_Object *list) +{ + const Eina_List *devices, *l; + Imfos_Device *dev; + char buf[1024]; + Evas_Object *o; + + EINA_LIST_FOREACH(imfos_config->devices, l, dev) + { + snprintf(buf, sizeof(buf), "%s(%s)", dev->name, dev->dev_name); + e_widget_ilist_append(list, NULL, buf, _imfos_device_changed, dev, NULL); + printf("dev %s(%s)\n", dev->name, dev->dev_name); + } + e_widget_ilist_selected_set(list, 1); + _imfos_device_changed(eina_list_data_get(imfos_config->devices)); +} + +static void +_v4l_create(void) +{ + Evas_Object *o; + Evas *evas; + Evas_Object *list; + + + list = _tmp_cfg->current; + evas = evas_object_evas_get(_tmp_cfg->current); + + printf("V4l panel\n"); + o = evas_object_image_filled_add(evas); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_min_set(o, 320, 240); + e_widget_list_object_append(list, o, 1, 1, 0.5); + _tmp_cfg->dev->param.v4l.cam = o; +// if (_tmp_cfg->config->enabled) +// imfos_devices_run(_tmp_cfg->dev); + evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, _imfos_cam_widget_delete, _tmp_cfg->dev); + + o = e_widget_check_add(evas, "Flip camera", &flipped); + e_widget_list_object_append(list, o, 1, 0, 0.5); + + o = e_widget_check_add(evas, "Set as the fallback", &flipped); + e_widget_list_object_append(list, o, 1, 0, 0.5); +} + +static void +_device_create(void) +{ + Evas_Object *o; + Evas *evas; + Evas_Object *list; + char buf[4096]; + + list = _tmp_cfg->current; + evas = evas_object_evas_get(_tmp_cfg->current); + + printf("Device Create\n"); + o = e_widget_check_add(evas, "Enabled", + (int *)&_tmp_cfg->config->enabled); + e_widget_list_object_append(list, o, 1, 0, 0.0); + snprintf(buf, sizeof(buf), "Name : %s", _tmp_cfg->config->name); + o = e_widget_label_add(evas, buf); + e_widget_list_object_append(list, o, 1, 0, 0.0); + snprintf(buf, sizeof(buf), "System path : %s", _tmp_cfg->config->syspath); + o = e_widget_label_add(evas, buf); + e_widget_list_object_append(list, o, 1, 0, 0.0); + snprintf(buf, sizeof(buf), "Device path : %s", _tmp_cfg->config->dev_name); + o = e_widget_label_add(evas, buf); + e_widget_list_object_append(list, o, 1, 0, 0.0); + o = e_widget_check_add(evas, "Lock the device path", + (int *)&_tmp_cfg->config->dev_name_locked); + e_widget_list_object_append(list, o, 1, 0, 0.0); + _v4l_create(); + o = e_widget_slider_add(evas, 1, 0, "Priority : %d", -100.0, 100.0, 5.0, 50, + NULL, &_tmp_cfg->config->priority, 110); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "async", (int *)&_tmp_cfg->config->async); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "Timeout", (int *)&_tmp_cfg->config->timeout_enabled); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_slider_add(evas, 1, 0, "Timeout (%2.0f)", 0.0, 64580.0, 5.0, 0, + NULL, &_tmp_cfg->config->timeout, 110); + e_widget_list_object_append(list, o, 1, 0, 0.5); +// o = e_widget_radio_group_new((int*) &(_tmp_cfg->config->powersave_min_state)); +// e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "Force the login when detected", + (int*)&_tmp_cfg->config->auto_login); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "Force the logoff when missmatch", + (int*)&_tmp_cfg->config->auto_logout); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "Report the screensaver when detected", + (int*)&_tmp_cfg->config->auto_screen_on); + e_widget_list_object_append(list, o, 1, 0, 0.5); + o = e_widget_check_add(evas, "Enable the screensaver when missmatch", + (int*)&_tmp_cfg->config->auto_screen_off); + e_widget_list_object_append(list, o, 1, 0, 0.5); + + + /* + powersave_min_state + */ + +} + + static Evas_Object * _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) { - Evas_Object *list, *o; + Evas_Object *list, *list_cam, *devices_list, *o; - list = e_widget_list_add(evas, 0, 0); + _tmp_cfg->main = e_widget_list_add(evas, 0, 1); - o = e_widget_check_add(evas, "Flip camera", &flipped); + o = e_widget_ilist_add(evas, 0, 0, NULL); + e_widget_ilist_multi_select_set(o, EINA_FALSE); + evas_object_size_hint_min_set(o, 160, 240); + e_widget_list_object_append(_tmp_cfg->main, o, 1, 0, 0.5); + evas_object_show(o); - e_widget_list_object_append(list, o, 1, 0, 0.5); - - return list; + _fill_devices(evas, o); + return _tmp_cfg->main; } static int diff --git a/src/modules/imfos/e_mod_main.c b/src/modules/imfos/e_mod_main.c index 18749707d..fdfba1cdd 100755 --- a/src/modules/imfos/e_mod_main.c +++ b/src/modules/imfos/e_mod_main.c @@ -1,61 +1,113 @@ -#include #include "e_mod_main.h" #include "e_mod_config.h" #include "imfos_v4l.h" +#include "imfos_devices.h" #define IMFOS_TIMEOUT 10 -static E_Config_DD *_imfos_conf = NULL; +static E_Config_DD *_conf_edd = NULL; +static E_Config_DD *_conf_edd_device = NULL; +static Ecore_Timer *_imfos_timer = NULL; -static Imfos_Config *_imfos_config = NULL; -static E_Config_DD *_imfos_config_edd = NULL; +Imfos_Config *imfos_config = NULL; +static E_Config_DD *imfos_config_edd = NULL; EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Imfos" }; static void _e_mod_imfos(void); +static Eina_Bool _run(void *); static Eina_Bool _run(void *data EINA_UNUSED) { - _e_mod_imfos(); -} - -static void -_e_mod_imfos(void) -{ - Imfos_V4l_Conf *conf; - - conf = calloc(1, sizeof(Imfos_V4l_Conf)); - conf->timeout = IMFOS_TIMEOUT; - imfos_v4l_run(conf); +// imfos_v4l_run(imfos_config); } EAPI void * e_modapi_init(E_Module *m) { printf("Loading ...\n"); + _conf_edd = E_CONFIG_DD_NEW("Config", Imfos_Config); + _conf_edd_device = E_CONFIG_DD_NEW("Device", Imfos_Device); +#undef T +#undef D +#define T Imfos_Device +#define D _conf_edd_device + E_CONFIG_VAL(D, T, enabled, INT); + E_CONFIG_VAL(D, T, name, STR); + E_CONFIG_VAL(D, T, dev_name, STR); + E_CONFIG_VAL(D, T, dev_name_locked, INT); + E_CONFIG_VAL(D, T, capacities, INT); + E_CONFIG_VAL(D, T, powersave_min_state, INT); + E_CONFIG_VAL(D, T, priority, INT); + E_CONFIG_VAL(D, T, async, INT); + E_CONFIG_VAL(D, T, timeout, INT); + E_CONFIG_VAL(D, T, auto_screen_on, INT); + E_CONFIG_VAL(D, T, auto_screen_off, INT); + E_CONFIG_VAL(D, T, auto_logout, INT); + E_CONFIG_VAL(D, T, auto_login, INT); + E_CONFIG_VAL(D, T, catch_time_average, INT); + E_CONFIG_VAL(D, T, catch_count, INT); + E_CONFIG_VAL(D, T, param.v4l.flip, INT); + E_CONFIG_VAL(D, T, param.v4l.init_time_average, INT); + E_CONFIG_VAL(D, T, param.wifi.ssid, STR); + E_CONFIG_VAL(D, T, param.bluetooth.id, STR); +#undef T +#undef D +#define T Imfos_Config +#define D _conf_edd + E_CONFIG_VAL(D, T, config_version, UINT); + E_CONFIG_LIST(D, T, devices, _conf_edd_device); + imfos_config = e_config_domain_load("module.imfos", _conf_edd); + if ((!imfos_config) + || (imfos_config->config_version != IMFOS_CONFIG_VERSION)) + E_FREE(imfos_config); + if (!imfos_config) + { + imfos_config = calloc(1, sizeof(Imfos_Config)); + imfos_config->config_version = IMFOS_CONFIG_VERSION; + } + /* + E_CONFIG_LIMIT(imfos_config->poll_interval, 1, 3600); + E_CONFIG_LIMIT(imfos_config->poll_interval_max, 1, 3600); + E_CONFIG_LIMIT(imfos_config->poll_interval_powersave, 1, 3600); + */ + imfos_devices_init(); imfos_v4l_init(); - _imfos_config_edd = E_CONFIG_DD_NEW("Config", Imfos_Config); - E_CONFIG_VAL(_imfos_config_edd, Imfos_Config, orient, INT); - e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL, "preferences-advanced"); - e_configure_registry_item_add("advanced/imfos", 20, "Imfos", NULL, "preference-imfos", e_mod_config_imfos); - ecore_timer_add(50.0, _run, NULL); + + e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL, + "preferences-advanced"); + e_configure_registry_item_add("advanced/imfos", 20, "Imfos", NULL, + "preference-imfos", e_mod_config_imfos); + e_config_domain_save("module.imfos", _conf_edd, imfos_config); + +// _imfos_timer = ecore_timer_add(50.0, _run, NULL); + return m; } EAPI int e_modapi_shutdown(E_Module *m EINA_UNUSED) { - E_CONFIG_DD_FREE(_imfos_config_edd); - free(_imfos_config); + e_configure_registry_item_del("advanced/imfos"); + e_configure_registry_category_del("advanced"); + + ecore_timer_del(_imfos_timer); + + E_CONFIG_DD_FREE(_conf_edd); + E_CONFIG_DD_FREE(_conf_edd_device); + free(imfos_config); imfos_v4l_shutdown(); + imfos_devices_shutdown(); + return 1; } EAPI int e_modapi_save(E_Module *m EINA_UNUSED) { + e_config_domain_save("module.imfos", _conf_edd, imfos_config); return 1; } diff --git a/src/modules/imfos/e_mod_main.h b/src/modules/imfos/e_mod_main.h index a673b4001..2bcc75cbf 100755 --- a/src/modules/imfos/e_mod_main.h +++ b/src/modules/imfos/e_mod_main.h @@ -1,6 +1,11 @@ #ifndef _E_MOD_MAIN_H #define _E_MOD_MAIN_H +#include +#include "imfos_devices.h" + +#define IMFOS_CONFIG_VERSION 1 + #ifdef _cplusplus extern "C++" #endif @@ -22,13 +27,9 @@ typedef enum _Imfos_Orient Imfos_Orient; struct _Imfos_Config { - Imfos_Orient orient; - //E_Config_Dialog *cfd; -}; - -struct _Config_Item { - Imfos_Orient orient; - const char *path; + unsigned int config_version; + Eina_List *devices; + E_Config_Dialog *cfd; }; extern Imfos_Config *imfos_config; diff --git a/src/modules/imfos/imfos_devices.c b/src/modules/imfos/imfos_devices.c new file mode 100644 index 000000000..5f7b46052 --- /dev/null +++ b/src/modules/imfos/imfos_devices.c @@ -0,0 +1,290 @@ +#include "e_mod_main.h" +#include "imfos_devices.h" +#include "imfos_v4l.h" +#include + +static Imfos_Device *_imfos_devices_add(const char *syspath, int type); +static void _imfos_devices_del(Imfos_Device *dev); +static void _imfos_devices_eeze_events(const char *syspath, Eeze_Udev_Event ev, void *data, Eeze_Udev_Watch *watch); + +static Eina_List *_delayed_jobs = NULL; +static Eeze_Udev_Watch *_eeze_watcher = NULL; + + +static Imfos_Device * +_imfos_devices_new(const char *syspath) +{ + Imfos_Device *dev; + + dev = calloc(1, sizeof(Imfos_Device)); + dev->syspath = eina_stringshare_ref(syspath); + dev->name = eeze_udev_syspath_get_sysattr(syspath, "name"); + dev->dev_name = eeze_udev_syspath_get_property(syspath, "DEVNAME"); + printf("New device %s(%s)\n", dev->name, dev->dev_name); + return dev; +} + + +static void +_imfos_devices_del(Imfos_Device *dev) +{ + eina_stringshare_del(dev->syspath); + eina_stringshare_del(dev->name); + eina_stringshare_del(dev->dev_name); + free(dev); +} + +static Eina_Bool +_imfos_devices_check_capabilities(const char *syspath, const char *dev_name) +{ + /* TODO check capacities */ + return EINA_TRUE; +} + +static Imfos_Device * +_imfos_devices_add(const char *syspath, int type) +{ + Eina_List *l; + Imfos_Device *dev; + const char *name; + const char *dev_name; + + name = eeze_udev_syspath_get_sysattr(syspath, "name"); + dev_name = eeze_udev_syspath_get_property(syspath, "DEVNAME"); + printf("New device %s(%s) know(%d)\n", name, dev_name, eina_list_count(imfos_config->devices)); + + EINA_LIST_FOREACH(imfos_config->devices, l, dev) + { + if (dev->name == name) + { + printf("Found by name %s\n"); + break; + } + } + if (dev) + { + printf("Updating device %s\n", name); + dev->syspath = eina_stringshare_ref(syspath); + dev->dev_name = dev_name; + dev->type = type; + eina_stringshare_del(name); + } + else + { + if (_imfos_devices_check_capabilities(syspath, dev_name)) + { + printf("First time\n"); + dev = calloc(1, sizeof(Imfos_Device)); + dev->syspath = eina_stringshare_ref(syspath); + dev->name = name; + dev->type = type; + dev->dev_name = dev_name; + imfos_config->devices = + eina_list_append(imfos_config->devices, dev); + } + else + { + eina_stringshare_del(name); + eina_stringshare_del(dev_name); + } + } + return dev; +} + +static void +_imfos_device_remove(Imfos_Device *dev) +{ + eina_stringshare_del(dev->syspath); + dev->syspath = NULL; + if (!dev->dev_name_locked) + { + eina_stringshare_del(dev->dev_name); + dev->dev_name = NULL; + } + if (dev->thread) ecore_thread_cancel(dev->thread); +} + +static void +_imfos_devices_eeze_events(const char *syspath, Eeze_Udev_Event ev, + void *data EINA_UNUSED, + Eeze_Udev_Watch *watch EINA_UNUSED) +{ + Imfos_Device *dev; + Eina_List *l; + + if (ev == EEZE_UDEV_EVENT_ADD) + { + dev = _imfos_devices_add(syspath, EEZE_UDEV_TYPE_V4L); + } + else if (ev == EEZE_UDEV_EVENT_REMOVE) + { + EINA_LIST_FOREACH(imfos_config->devices, l, dev) + { + if (dev->syspath == syspath) + { + _imfos_device_remove(dev); + break; + } + } + } +} + + +void +imfos_devices_init(void) +{ + Eina_List *devices; + const char *syspath; + + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); + EINA_LIST_FREE(devices, syspath) + { + _imfos_devices_add(syspath, EEZE_UDEV_TYPE_V4L); + eina_stringshare_del(syspath); + } + /* + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL); + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL); + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL); + */ + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL); + EINA_LIST_FREE(devices, syspath) + { + _imfos_devices_add(syspath, EEZE_UDEV_TYPE_BLUETOOTH); + eina_stringshare_del(syspath); + } + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL); + EINA_LIST_FREE(devices, syspath) + { + _imfos_devices_add(syspath, EEZE_UDEV_TYPE_DRIVE_REMOVABLE); + eina_stringshare_del(syspath); + } + + devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); + _eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, + (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), + _imfos_devices_eeze_events, NULL); +} + +void +imfos_devices_shutdown(void) +{ + Imfos_Device *dev; + eeze_udev_watch_del(_eeze_watcher); +} + + +Eina_Bool +imfos_devices_timeout(Imfos_Device *dev) +{ + double loop_time; + + if (dev->timeout > 0) + { + loop_time = ecore_time_get() - dev->time_start; + if (loop_time > dev->timeout) + { + printf("timeout\n"); + return EINA_TRUE; + } + } + + return ecore_thread_check(dev->thread); +} + +static void +_imfos_devices_thread_run(void *data, Ecore_Thread *thread) +{ + Imfos_Device *dev; + + dev = data; + + dev->catched = EINA_FALSE; + dev->time_start = ecore_time_get(); + imfos_v4l_run(dev); + +} + +static void +_imfos_device_run(void) +{ + Eina_List *l; + Imfos_Device *dev; + + EINA_LIST_FOREACH(_delayed_jobs, l, dev) + { + if (!dev->thread) + { + imfos_devices_run(dev); + _delayed_jobs = eina_list_remove_list(_delayed_jobs, l); + break; + } + } +} + + +static void +_imfos_devices_thread_clean(void *data, Ecore_Thread *thread) +{ + Imfos_Device *dev; + double catch_time; + + dev = data; + + printf("Imfos thread End\n"); + if (dev->catched) + { + catch_time = dev->time_start - ecore_time_get(); + dev->catch_time_average = + ((dev->catch_time_average * dev->catch_count) + catch_time) + / (dev->catch_count + 1); + ++dev->catch_count; + } + + imfos_v4l_clean(dev); + dev->thread = NULL; + + _imfos_device_run(); +} + + + +static void +_imfos_devices_thread_cancel(void *data, Ecore_Thread *thread) +{ + printf("Imfos thread cancel\n"); +} + +Eina_Bool +imfos_devices_run(Imfos_Device *dev) +{ + Ecore_Thread *thread; + + + if (dev->thread) + { + ecore_thread_cancel(dev->thread); + if (!dev->async) + { + _delayed_jobs = eina_list_append(_delayed_jobs, dev); + return EINA_TRUE; + } + } + dev->thread = ecore_thread_run(_imfos_devices_thread_run, + _imfos_devices_thread_clean, + _imfos_devices_thread_clean, + dev); + + return EINA_FALSE; +} + +Eina_Bool +imfos_devices_cancel(Imfos_Device *dev) +{ + if (dev->thread) + { + ecore_thread_cancel(dev->thread); + return EINA_TRUE; + } + return EINA_FALSE; +} diff --git a/src/modules/imfos/imfos_devices.h b/src/modules/imfos/imfos_devices.h new file mode 100644 index 000000000..6fe524de8 --- /dev/null +++ b/src/modules/imfos/imfos_devices.h @@ -0,0 +1,60 @@ +#ifndef IMFOS_DEVICES_H_ +#define IMFOS_DEVICES_H_ + +#include + +typedef struct _Imfos_Device +{ + const char *syspath; + const char *name; + const char *dev_name; + int type; + Ecore_Thread *thread; + int capacities; + int poll_interval; + int powersave_min_state; + int priority; + int timeout; + double time_start; + double last_catch; + int catch_count; + int catch_time_average; + Eina_Bool init_time_fixed; + Eina_Bool catched; + Eina_Bool async; + Eina_Bool auto_screen_on; + Eina_Bool auto_screen_off; + Eina_Bool auto_logout; + Eina_Bool auto_login; + Eina_Bool timeout_enabled; + Eina_Bool found; + Eina_Bool enabled; + Eina_Bool dev_name_locked; + struct + { + struct + { + Evas_Object *cam; + Eina_Bool flip; + int init_time; + int init_time_average; + } v4l; + struct + { + const char *ssid; + } wifi; + struct + { + const char *id; + } bluetooth; + } param; +} Imfos_Device; + +void imfos_devices_init(void); +void imfos_devices_shutdown(void); +Eina_Bool imfos_devices_run(Imfos_Device *dev); +Eina_Bool imfos_devices_cancel(Imfos_Device *dev); +Eina_Bool imfos_devices_timeout(Imfos_Device *dev); + + +#endif /* IMFOS_DEVICES_H_ */ diff --git a/src/modules/imfos/imfos_v4l.c b/src/modules/imfos/imfos_v4l.c index e53e1f814..6a63b516a 100755 --- a/src/modules/imfos/imfos_v4l.c +++ b/src/modules/imfos/imfos_v4l.c @@ -10,26 +10,30 @@ #include #include +#include +#include +#include "e_mod_main.h" + #include #include #include "imfos_v4l.h" -#include "imfos_face.h" +//#include "imfos_face.h" #include #define CLEAR(x) memset(&(x), 0, sizeof(x)) static int _imfos_xioctl(int fh, int request, void *arg); +static Eina_Bool _imfos_v4l_image_transform(Evas_Object *cam, void *data, size_t size); static void _imfos_v4l_takeshot(void *data, Ecore_Thread *thread); static void _imfos_v4l_end(void *data, Ecore_Thread *thread); static void _imfos_v4l_cancel(void *data, Ecore_Thread *thread); -static const char *_imfos_v4l_path = NULL; -static Ecore_Thread *_imfos_v4l_thread = NULL; +static Ecore_Animator *_imfos_v4l_anim = NULL; static int _width; static int _height; static int _size; -//static void *_img = NULL; +static void *_img = NULL; static void *_img_y = NULL; static int _2126[256]; static int _7152[256]; @@ -60,44 +64,72 @@ _imfos_xioctl(int fh, int request, void *arg) } static Eina_Bool -_imfos_v4l_image_transform(void *data, size_t size) +_imfos_v4l_frame_anim(void *data) +{ + _imfos_v4l_anim = NULL; + evas_object_image_pixels_dirty_set(data, 1); + return EINA_FALSE; +} + +static Eina_Bool +_imfos_v4l_image_transform(Evas_Object *cam, void *data, size_t size) { unsigned char *b, *cb, *cyb; size_t i; unsigned int percent; percent = 0; - /* - if (!_img) - _img = malloc(_width * _height * 4); - */ - if (!_img_y) + if (cam) + { + if (!_img) + { + evas_object_image_pixels_get_callback_set(cam, NULL, NULL); + evas_object_image_alpha_set(cam, 0); + + evas_object_image_colorspace_set(cam, EVAS_COLORSPACE_ARGB8888); + evas_object_image_size_set(cam, _width, _height); + _img = evas_object_image_data_get(cam, 1); + } + } + + if (!_img_y) _img_y = malloc(_width * _height); b = data; -// cb = _img; + cb = _img; cyb = _img_y; for (i = 0; i < size; i += 3) { - /* - cb[3] = 255; - cb[2] = b[0]; - cb[1] = b[1]; - cb[0] = b[2]; - */ *cyb = (char)((_2126[b[2]] + _7152[b[1]] + _0722[b[0]]) >> 8); if (*cyb > 16) ++percent; - //cb += 4; + if (cam) + { + cb[3] = 255; + cb[2] = b[0]; + cb[1] = b[1]; + cb[0] = b[2]; + cb += 4; + } b += 3; cyb += 1; } - printf("percent %d%%\n", (percent * 100)/ (_width * _height)); + + if (cam) + { + if (!_imfos_v4l_anim) + _imfos_v4l_anim = ecore_animator_add(_imfos_v4l_frame_anim, cam); + evas_object_image_data_set(cam, _img); + evas_object_image_data_update_add(cam, 0, 0, _width, _height); + evas_object_image_pixels_dirty_set(cam, 0); + } + +// printf("percent %d%%\n", (percent * 100)/ (_width * _height)); return (percent > (size / 10)); } -static void -_imfos_v4l_takeshot(void *data, Ecore_Thread *thread) +void +imfos_v4l_run(Imfos_Device *conf) { struct v4l2_format fmt; struct v4l2_buffer buf; @@ -107,7 +139,6 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread) struct timeval tv; int r, fd = -1; unsigned int i, n_buffers; - char *dev_name = "/dev/video0"; char out_name[256]; FILE *fout; struct buffer *buffers; @@ -116,15 +147,11 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread) double loop_time_start; double loop_time_cur; double loop_time_avg = 0.0; - Imfos_V4l_Conf *conf; - - conf = data; - time_start = ecore_time_get(); stop = EINA_FALSE; - fprintf(stderr, "imfos thread\n"); + fprintf(stderr, "imfos thread %s\n", conf->dev_name); - fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); + fd = v4l2_open(conf->dev_name, O_RDWR | O_NONBLOCK, 0); if (fd < 0) { perror("Cannot open device"); return; @@ -178,6 +205,13 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread) printf("Warning: driver is sending image at %dx%d\n", fmt.fmt.pix.width, fmt.fmt.pix.height); + if (conf->param.v4l.cam) + { + printf("Sizing object %d %d\n", _width, _height); + evas_object_image_colorspace_set(conf->param.v4l.cam, EVAS_COLORSPACE_ARGB8888); + evas_object_image_size_set(conf->param.v4l.cam, _width, _height); + } + CLEAR(req); req.count = 2; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -217,7 +251,7 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread) _imfos_xioctl(fd, VIDIOC_STREAMON, &type); for (i = 0; ; ++i) { loop_time_start = ecore_time_get(); - fprintf(stderr, "try %d\n", i); + //fprintf(stderr, "try %d\n", i); do { FD_ZERO(&fds); FD_SET(fd, &fds); @@ -238,40 +272,36 @@ _imfos_v4l_takeshot(void *data, Ecore_Thread *thread) buf.memory = V4L2_MEMORY_MMAP; _imfos_xioctl(fd, VIDIOC_DQBUF, &buf); - - /* check image is right */ - /* - _imfos_v4l_image_check(buffers[buf.index].start, - buf.bytesused); - */ _width = fmt.fmt.pix.width; _height = fmt.fmt.pix.height; _size = buf.bytesused; - //_img = buffers[buf.index].start; - printf("copy %d %d %d - %d\n", buf.bytesused, - _width * _height * 2, _width, _height); +// printf("copy %d %d %d - %d\n", buf.bytesused, +// _width * _height * 2, _width, _height); - if (_imfos_v4l_image_transform(buffers[buf.index].start, buf.bytesused)) + if (_imfos_v4l_image_transform(conf->param.v4l.cam, buffers[buf.index].start, + buf.bytesused)) { + /* if (imfos_face_search(_img_y, _width, _height, 0)) { stop = EINA_TRUE; - fprintf(stderr, "Found your fucking head guy\n"); + e_screensaver_notidle(); + fprintf(stderr, "I saw you !\n"); } + */ } _imfos_xioctl(fd, VIDIOC_QBUF, &buf); + /* fprintf(stderr, "imfos %.8f %.8f\n", ecore_time_get() - time_start, loop_time_avg); + */ if (stop) break; - loop_time_cur = ecore_time_get() - loop_time_start; - if (loop_time_cur > loop_time_avg) - loop_time_avg = loop_time_cur; - if ((ecore_time_get() - time_start + loop_time_avg) > conf->timeout) - break; + if (imfos_devices_timeout(conf)) + break; } - if (stop) - e_screensaver_notidle(); + // if (stop) + // e_screensaver_notidle(); v4l_close: type = V4L2_BUF_TYPE_VIDEO_CAPTURE; _imfos_xioctl(fd, VIDIOC_STREAMOFF, &type); @@ -281,30 +311,22 @@ v4l_close: fprintf(stderr, "v4l close %d\n", stop); } -static void -_imfos_v4l_end(void *data, Ecore_Thread *thread) +void +imfos_v4l_clean(Imfos_Device *conf) { fprintf(stderr, "v4l end\n"); - free(data); - /* - if (data) { - evas_object_image_colorspace_set(data, EVAS_COLORSPACE_ARGB8888); - //evas_object_image_colorspace_set(data, EVAS_COLORSPACE_GRY8); - evas_object_image_size_set(data, _width, _height); - evas_object_image_data_set(data, _img); - //evas_object_image_data_set(data, _img_y); - } - */ - - - /* - free(_img); - _img = NULL; - */ + if (_imfos_v4l_anim) + ecore_animator_del(_imfos_v4l_anim); + _imfos_v4l_anim = NULL; + if (conf->param.v4l.cam) + { + evas_object_image_size_set(conf->param.v4l.cam, 1, 1); + evas_object_image_data_set(conf->param.v4l.cam, NULL); + } free(_img_y); _img_y = NULL; - _imfos_v4l_thread = NULL; + _img = NULL; } static void @@ -314,13 +336,11 @@ _imfos_v4l_cancel(void *data, Ecore_Thread *thread) } - void imfos_v4l_init(void) { unsigned int i; - /* list webcams */ - _imfos_v4l_path = eina_stringshare_add("/dev/video0"); + for (i = 0; i < 256; i++) { _2126[i] = 0.2116 * 256 * i; @@ -332,15 +352,4 @@ imfos_v4l_init(void) void imfos_v4l_shutdown(void) { - eina_stringshare_del(_imfos_v4l_path); -} - -void -imfos_v4l_run(Imfos_V4l_Conf *conf) -{ - fprintf(stderr, "v4l run\n"); - _imfos_v4l_thread = ecore_thread_run(_imfos_v4l_takeshot, - _imfos_v4l_end, - _imfos_v4l_cancel, - conf); } diff --git a/src/modules/imfos/imfos_v4l.h b/src/modules/imfos/imfos_v4l.h index b06fc0cfc..289d85562 100755 --- a/src/modules/imfos/imfos_v4l.h +++ b/src/modules/imfos/imfos_v4l.h @@ -1,15 +1,11 @@ #ifndef IMFOS_V4L_H_ #define IMFOS_V4L_H_ -#include "imfos_face.h" -typedef struct Imfos_V4l_Conf_ -{ - double timeout; - Eina_Bool invert : 1; -} Imfos_V4l_Conf; +#include "e_mod_main.h" void imfos_v4l_init(void); void imfos_v4l_shutdown(void); -void imfos_v4l_run(Imfos_V4l_Conf *conf); +void imfos_v4l_run(Imfos_Device *dev); +void imfos_v4l_clean(Imfos_Device *dev); #endif /* IMFOS_V4L_H_ */