diff options
| -rw-r--r-- | live.c | 59 | 
1 files changed, 58 insertions, 1 deletions
| @@ -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; | 
