aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/imfos/imfos_v4l.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/imfos/imfos_v4l.c')
-rwxr-xr-xsrc/modules/imfos/imfos_v4l.c169
1 files changed, 89 insertions, 80 deletions
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 <linux/videodev2.h>
#include <libv4l2.h>
+#include <Eeze.h>
+#include <e.h>
+#include "e_mod_main.h"
+
#include <Ecore.h>
#include <Evas.h>
#include "imfos_v4l.h"
-#include "imfos_face.h"
+//#include "imfos_face.h"
#include <e.h>
#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);
}