From 33a09bfcae7410a02eee922118353b94c089cc29 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sat, 28 May 2011 16:49:57 -0300 Subject: [PATCH] v4l2-sysfs-path: Show devices ordered by the video node number Instead of calling the default print function, it implements its own logic that will print all devices video ordered, plus the audio playback devices. The output will be something like: Video device: video0 vbi: vbi0 dvb frontend: dvb0.frontend0 dvb demux: dvb0.demux0 dvb dvr: dvb0.dvr0 dvb net: dvb0.net0 sound card: hw:2 pcm capture: hw:2,0 mixer: hw:2 Video device: video1 sound card: hw:1 pcm capture: hw:1,0 mixer: hw:1 Alsa playback device(s): hw:0,0 hw:0,1 Signed-off-by: Mauro Carvalho Chehab --- utils/v4l2-sysfs-path/v4l2-sysfs-path.c | 65 +++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/utils/v4l2-sysfs-path/v4l2-sysfs-path.c b/utils/v4l2-sysfs-path/v4l2-sysfs-path.c index 3ba446d..8ad0bda 100644 --- a/utils/v4l2-sysfs-path/v4l2-sysfs-path.c +++ b/utils/v4l2-sysfs-path/v4l2-sysfs-path.c @@ -27,21 +27,70 @@ #include "../libmedia_dev/get_media_devices.h" #include +static void print_all_associated_devices(void *md, char *vid, + enum device_type type) +{ + char *devname = NULL; + int first = 1; + + do { + devname = get_associated_device(md, devname, type, + vid, V4L_VIDEO); + if (devname) { + if (first) { + printf("\t%s: ", media_device_type(type)); + first = 0; + } + + printf("%s ", devname); + } + } while (devname); + if (!first) + printf("\n"); +} + +static void print_all_alsa_independent_playback(void *md) +{ + char *devname = NULL; + int first = 1; + + do { + devname = get_not_associated_device(md, devname, + SND_OUT, V4L_VIDEO); + if (devname) { + if (first) { + printf("Alsa playback device(s): "); + first = 0; + } + + printf("%s ", devname); + } + } while (devname); + if (!first) + printf("\n"); +} + int main(void) { void *md; - char *alsa; + char *vid, *alsa; + int i; md = discover_media_devices(); - display_media_devices(md); - alsa = get_associated_device(md, NULL, SND_CAP, "video0", V4L_VIDEO); - if (alsa) - printf("Alsa device associated with video0 capture: %s\n", alsa); + vid = NULL; + do { + vid = get_associated_device(md, vid, V4L_VIDEO, + NULL, NONE); + if (!vid) + break; + printf("Video device: %s\n", vid); + + for (i = 0; i <= SND_HW; i++) + print_all_associated_devices(md, vid, i); + } while (vid); - alsa = get_not_associated_device(md, NULL, SND_OUT, V4L_VIDEO); - if (alsa) - printf("Alsa output device: %s\n", alsa); + print_all_alsa_independent_playback(md); free_media_devices(md); -- 2.7.4