summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2020-07-16 15:28:56 +0100
committerAlastair Poole <netstar@gmail.com>2020-07-16 15:28:56 +0100
commit110e3ddc843603ba3ac769c85b2647b15affdccf (patch)
tree3c68ce7baad39ad9ef6b39c1cc5b1dc4698d6e29
parentb68be5f36b11e280857b1e23ce90f679ca7b8a5f (diff)
video: work on linux
-rw-r--r--cam.c69
-rw-r--r--vid.c13
2 files changed, 51 insertions, 31 deletions
diff --git a/cam.c b/cam.c
index 447db13..569859d 100644
--- a/cam.c
+++ b/cam.c
@@ -10,7 +10,11 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
-#include <sys/videoio.h>
+#if defined(__linux__)
+# include <linux/videodev2.h>
+#else
+# include <sys/videoio.h>
+#endif
#include <termios.h>
#include <Eina.h>
@@ -89,36 +93,36 @@ YUV422toBGRA(unsigned char *buf, char *rgb, unsigned int w, unsigned int h)
static void
save_photo(const char *data, unsigned int w, unsigned int h)
{
- Ecore_Evas *ee;
- Evas *evas;
- Evas_Object *o;
- struct tm *info;
- time_t rawtime;
- char buf[256];
- char filename[4096];
- struct timespec ts;
-
- time(&rawtime);
- info = localtime(&rawtime);
- strftime(buf, sizeof(buf), "%F-%T", info);
- clock_gettime(CLOCK_REALTIME, &ts);
- snprintf(filename, sizeof(filename), "images/%s:%ld.jpg", buf, ts.tv_nsec);
-
- ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
- evas = ecore_evas_get(ee);
- o = evas_object_image_filled_add(evas);
- evas_object_image_size_set(o, w, h);
- evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_data_set(o, (void *)data);
- evas_object_resize(o, w, h);
- evas_object_move(o, 0, 0);
- evas_object_image_save(o, filename, NULL, NULL);
- evas_object_del(o);
- ecore_evas_free(ee);
+ Ecore_Evas *ee;
+ Evas *evas;
+ Evas_Object *o;
+ struct tm *info;
+ time_t rawtime;
+ char buf[256];
+ char filename[4096];
+ struct timespec ts;
+
+ time(&rawtime);
+ info = localtime(&rawtime);
+ strftime(buf, sizeof(buf), "%F-%T", info);
+ clock_gettime(CLOCK_REALTIME, &ts);
+ snprintf(filename, sizeof(filename), "images/%s:%ld.jpg", buf, ts.tv_nsec);
+
+ ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);
+ evas = ecore_evas_get(ee);
+ o = evas_object_image_filled_add(evas);
+ evas_object_image_size_set(o, w, h);
+ evas_object_image_colorspace_set(o, EVAS_COLORSPACE_ARGB8888);
+ evas_object_image_data_set(o, (void *)data);
+ evas_object_resize(o, w, h);
+ evas_object_move(o, 0, 0);
+ evas_object_image_save(o, filename, NULL, NULL);
+ evas_object_del(o);
+ ecore_evas_free(ee);
}
typedef struct {
- char *start;
+ char *start;
uint32_t length;
} buffer_t;
@@ -163,7 +167,12 @@ mmap_camera(int fd, int w, int h)
borked("mmap");
}
}
-
+#if defined(__linux__)
+ if (ioctl(fd, VIDIOC_QBUF, &buf)) {
+ fprintf(stderr, "VIDIOC_QBUF\n");
+ exit(1);
+ }
+#else
for (i = 0; i < req.count; i++) {
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -174,7 +183,7 @@ mmap_camera(int fd, int w, int h)
borked("VIDIOC_QBUF");
}
}
-
+#endif
if (ioctl(fd, VIDIOC_STREAMON, &type) == -1) {
borked("VIDIOC_STREAMON");
}
diff --git a/vid.c b/vid.c
index 5b690d4..2b8b41c 100644
--- a/vid.c
+++ b/vid.c
@@ -10,7 +10,11 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
-#include <sys/videoio.h>
+#if defined(__linux__)
+# include <linux/videodev2.h>
+#else
+# include <sys/videoio.h>
+#endif
#include <Eina.h>
#include <Ecore.h>
@@ -245,6 +249,12 @@ mmap_camera(Cam *cam)
ecore_thread_feedback(cam->thread, cam);
count++;
+#if defined(__linux__)
+ if (ioctl(fd, VIDIOC_QBUF, &buf)) {
+ fprintf(stderr, "VIDIOC_QBUF\n");
+ exit(1);
+ }
+#else
for (i = 0; i < req.count; i++) {
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -256,6 +266,7 @@ mmap_camera(Cam *cam)
exit(1);
}
}
+#endif
if (ecore_thread_check(cam->thread)) break;
}