From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: hal, udev and video4linux probers
Date: Sun, 10 May 2009 13:58:47 +0000 [thread overview]
Message-ID: <1241963927.9870.15.camel@poy> (raw)
In-Reply-To: <8ceb98f20905081004l52ac4b95h1c23d9e8ed209e37@mail.gmail.com>
On Sat, 2009-05-09 at 18:19 +0200, Kay Sievers wrote:
> On Sat, May 9, 2009 at 16:54, Filippo Argiolas <fargiolas@gnome.org> wrote:
> > On Sat, May 9, 2009 at 4:24 PM, Filippo Argiolas <fargiolas@gnome.org> wrote:
> >> On Sat, May 9, 2009 at 1:49 PM, Kay Sievers <kay.sievers@vrfy.org> wrote:
> >>> I've committed a merge of both versions.
> >>
> >> Great :)
> >> I still don't see it though in the udev (nor udev-extras) git repositories.
>
> Yeah, seems the master -> public rsync is really slow the last days.
>
> > Now it's ok. I forgot the email in the copyright line, you can put
> > <filippo.argiolas@gmail.com> if you want.
>
> Done.
Here is small hack using libudev, that enumerates all capture-capable
video devices, and listens for new devices connected, or devices going
away.
It builds with:
gcc -Wall -o v4l-monitor v4l-monitor.c -ludev
And prints when started the built-in camera:
$ ./v4l-monitor
UVC Camera (17ef:4807) (/dev/video0)
and while new devices are plugged/unplugged:
UVC Camera (046d:09a4) (/dev/video1) (add)
OV511+ USB Camera (/dev/video2) (add)
UVC Camera (046d:09a4) (/dev/video1) (remove)
OV511+ USB Camera (/dev/video2) (remove)
OV511+ USB Camera (/dev/video1) (add)
UVC Camera (046d:09a4) (/dev/video2) (add)
...
Cheers,
Kay
/*
* enumerate and monitor v4l devices
*
* Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include <syslog.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/select.h>
#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
#include "libudev.h"
int main(int argc, char *argv[])
{
struct udev *udev;
struct udev_monitor *monitor;
struct udev_enumerate *enumerate;
struct udev_list_entry *list_entry;
/* libudev context */
udev = udev_new();
/* connect to event source */
monitor = udev_monitor_new_from_netlink(udev, "udev");
/* install subsytem filter, we will not wake-up for other events */
udev_monitor_filter_add_match_subsystem_devtype(monitor, "video4linux", NULL);
/* listen to events, and buffer them */
udev_monitor_enable_receiving(monitor);
/* prepare a device scan */
enumerate = udev_enumerate_new(udev);
/* filter for video devices */
udev_enumerate_add_match_subsystem(enumerate,"video4linux");
/* filter for capture capable devices */
udev_enumerate_add_match_property(enumerate, "ID_V4L_CAPABILITIES", "*:capture:*");
/* retrieve the list */
udev_enumerate_scan_devices(enumerate);
/* print devices */
udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
struct udev_device *device;
device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
udev_list_entry_get_name(list_entry));
if (device = NULL)
continue;
printf("%s (%s)\n",
udev_device_get_property_value(device, "ID_V4L_PRODUCT"),
udev_device_get_devnode(device));
udev_device_unref(device);
}
udev_enumerate_unref(enumerate);
/* process events */
while (1) {
struct pollfd pfd[2];
struct udev_device *device;
pfd[0].fd = udev_monitor_get_fd(monitor);
pfd[0].events = POLLIN;
pfd[1].fd = STDIN_FILENO;
pfd[1].events = POLLIN;
if (poll(pfd, 2, -1) < 1)
continue;
if (pfd[0].revents & POLLIN) {
const char *cap;
/* get device from event */
device = udev_monitor_receive_device(monitor);
if (device = NULL)
continue;
/* filter capture-capable devices */
cap = udev_device_get_property_value(device, "ID_V4L_CAPABILITIES");
if (cap = NULL || strstr(":capture:", cap) = NULL)
continue;
/* print device */
printf("%s (%s) (%s)\n",
udev_device_get_property_value(device, "ID_V4L_PRODUCT"),
udev_device_get_devnode(device),
udev_device_get_action(device));
udev_device_unref(device);
}
/* exit the loop on console input */
if (pfd[1].revents & POLLIN)
break;
}
udev_monitor_unref(monitor);
udev_unref(udev);
return 0;
}
next prev parent reply other threads:[~2009-05-10 13:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-08 17:04 hal, udev and video4linux probers Filippo Argiolas
2009-05-08 20:06 ` Kay Sievers
2009-05-08 20:25 ` David Zeuthen
2009-05-08 20:38 ` Filippo Argiolas
2009-05-09 11:49 ` Kay Sievers
2009-05-09 14:24 ` Filippo Argiolas
2009-05-09 14:54 ` Filippo Argiolas
2009-05-09 16:19 ` Kay Sievers
2009-05-10 13:58 ` Kay Sievers [this message]
2009-05-10 18:50 ` Filippo Argiolas
2009-05-10 23:59 ` Kay Sievers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1241963927.9870.15.camel@poy \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).