summaryrefslogtreecommitdiff
path: root/live.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-10-03 14:29:01 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-10-05 12:20:52 +0200
commit7030a194c84e1fad43ade86674a1e57381d825d1 (patch)
tree5f5a18de3887ae27c475e0ce8ef105c35eef5a1d /live.c
parent5a31825953e74c5ff0831b7322d65805248455b2 (diff)
live: Locate the video output device node automatically
Iterate through the omap_vout video nodes and use the one with the lowest minor as the video output device. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'live.c')
-rw-r--r--live.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/live.c b/live.c
index bd97036..c102893 100644
--- a/live.c
+++ b/live.c
@@ -21,6 +21,7 @@
*/
#define _BSD_SOURCE
+#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
@@ -36,7 +37,9 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
+#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <linux/fb.h>
#include <linux/spi/spidev.h>
@@ -235,6 +238,53 @@ static struct video_out_operations vo_ops = {
.unwatch_fd = events_unwatch_fd,
};
+static const char *video_out_find(void)
+{
+ unsigned int video_idx = 256;
+ static char devname[14];
+ struct stat devstat;
+ struct dirent *ent;
+ char *end;
+ DIR *dir;
+ int ret;
+
+ dir = opendir("/sys/bus/platform/devices/omap_vout/video4linux");
+ if (dir == NULL)
+ return NULL;
+
+ while ((ent = readdir(dir)) != NULL) {
+ unsigned int idx;
+
+ if (strncmp(ent->d_name, "video", 5))
+ continue;
+
+ idx = strtoul(ent->d_name + 5, &end, 10);
+ if (*end != '\0')
+ continue;
+
+ if (idx < video_idx)
+ video_idx = idx;
+ }
+
+ closedir(dir);
+
+ if (video_idx == 256)
+ return NULL;
+
+ sprintf(devname, "/dev/video%u", video_idx);
+ ret = stat(devname, &devstat);
+ if (ret < 0)
+ return NULL;
+
+ /* Sanity check: udev might have reordered the device nodes.
+ * Make sure the major/minor match. We should really use libudev.
+ */
+ if (major(devstat.st_rdev) != 81 || minor(devstat.st_rdev) != video_idx)
+ return NULL;
+
+ return devname;
+}
+
/* -----------------------------------------------------------------------------
* Frame buffer
*/
@@ -320,6 +370,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
unsigned int count = 0;
struct v4l2_rect rect;
int exit_code = EXIT_FAILURE;
+ const char *vo_devname;
float fps;
int ret;
int c;
@@ -373,7 +424,13 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
view_format.code, view_format.width, view_format.height);
/* Initialize video output. */
- vo = vo_init(VIDEOOUT_DEVICE, &vo_ops, rect.width, rect.height);
+ vo_devname = video_out_find();
+ if (vo_devname == NULL) {
+ printf("error: unable to find video output device\n");
+ goto cleanup;
+ }
+
+ vo = vo_init(vo_devname, &vo_ops, rect.width, rect.height);
if (vo == NULL) {
printf("error: unable to initialize video output\n");
goto cleanup;