get_media_devices: add a function to provide an audio output device
authorMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 23 May 2011 09:43:01 +0000 (06:43 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 23 May 2011 09:49:33 +0000 (06:49 -0300)
Provide the first audio output device not related to a v4l device, assuming
that the sound card is a different device. If none found, just get any
output device, even it inside the same board that provides video4linux
interface.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
utils/libv4l2util/get_media_devices.c
utils/libv4l2util/get_media_devices.h
utils/v4l2-sysfs-path/v4l2-sysfs-path.c

index 04822e7a2e484b8811e70d2f3addd9d8bd4b0996..55c4ac6028dcc98a0e0f412e6ff6802c8affd571 100644 (file)
@@ -291,5 +291,37 @@ char *get_first_alsa_cap_device(struct media_devices *md, unsigned int size,
                        return md->node;
        }
 
+       return NULL;
+}
+
+char *get_first_no_video_out_device(struct media_devices *md, unsigned int size)
+{
+       struct media_devices *md_ptr = md;
+       int i, skip = 0;
+       char *prev = "";
+
+       /* Step 1: Find a device without video4linux node */
+       for (i = 0; i < size; i++, md++) {
+               if (md->type == V4L_VIDEO)
+                       skip = 1;
+               else if (strcmp(prev, md->device)) {
+                       prev = md->device;
+                       skip = 0;
+               }
+               if (!skip && md->type == SND_OUT)
+                       return md->node;
+       }
+
+       /*
+        * Step 2: Fallback: Find any alsa out node. Useful if a machine
+        * doesn't have an internal board, but an USB device like the
+        * Sirius webcam also provides an alsa output node
+        */
+       md = md_ptr;
+       for (i = 0; i < size; i++, md++) {
+               if (!skip && md->type == SND_OUT)
+                       return md->node;
+       }
+
        return NULL;
 }
\ No newline at end of file
index 6dc50366dc5b5c056459ac104b57455f9016bc0a..7c35233bd4dcaafc2f4bfc7ad326fa00f7e39352 100644 (file)
@@ -46,3 +46,4 @@ void free_media_devices(struct media_devices *md, unsigned int md_size);
 void display_media_devices(struct media_devices *md, unsigned int size);
 char *get_first_alsa_cap_device(struct media_devices *md, unsigned int size,
                                char *v4l_device);
+char *get_first_no_video_out_device(struct media_devices *md, unsigned int size);
index 1cc4687616f6d361ac42a855592d6ddf060fcb4b..1e27302cc3759d24a8e4e9c86387174e73e5dcb8 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "../libv4l2util/get_media_devices.h"
+#include <stdio.h>
 
 int main(void)
 {
@@ -36,9 +37,12 @@ int main(void)
        display_media_devices(md, size);
 
        alsa = get_first_alsa_cap_device(md, size, "video0");
+       if (alsa)
+               printf("Alsa device associated with video0 capture: %s\n", alsa);
 
+       alsa = get_first_no_video_out_device(md, size);
        if (alsa)
-               printf ("Alsa device associated with video0 capture: %s\n", alsa);
+               printf("Alsa output device: %s\n", alsa);
 
        free_media_devices(md, size);