v4l2-sysfs-path: Show devices ordered by the video node number
authorMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 19:49:57 +0000 (16:49 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 19:50:25 +0000 (16:50 -0300)
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 <mchehab@redhat.com>
utils/v4l2-sysfs-path/v4l2-sysfs-path.c

index 3ba446d..8ad0bda 100644 (file)
 #include "../libmedia_dev/get_media_devices.h"
 #include <stdio.h>
 
+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);