| 1 |
/* |
| 2 |
* Copyright © 2011 Red Hat, Inc. |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, distribute, and sell this software |
| 5 |
* and its documentation for any purpose is hereby granted without |
| 6 |
* fee, provided that the above copyright notice appear in all copies |
| 7 |
* and that both that copyright notice and this permission notice |
| 8 |
* appear in supporting documentation, and that the name of Red Hat |
| 9 |
* not be used in advertising or publicity pertaining to distribution |
| 10 |
* of the software without specific, written prior permission. Red |
| 11 |
* Hat makes no representations about the suitability of this software |
| 12 |
* for any purpose. It is provided "as is" without express or implied |
| 13 |
* warranty. |
| 14 |
* |
| 15 |
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 16 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN |
| 17 |
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 18 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
| 19 |
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
| 20 |
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 |
* |
| 23 |
* Author: |
| 24 |
* Mauro Carvalho Chehab |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "../libmedia_dev/get_media_devices.h" |
| 28 |
#include <stdio.h> |
| 29 |
#include <argp.h> |
| 30 |
|
| 31 |
const char *argp_program_version = "v4l2-sysfs-path version " V4L_UTILS_VERSION; |
| 32 |
const char *argp_program_bug_address = "Mauro Carvalho Chehab <[email protected]>"; |
| 33 |
|
| 34 |
static const struct argp_option options[] = { |
| 35 |
{"device", 'd', 0, 0, "use alternative device show mode", 0}, |
| 36 |
{ 0, 0, 0, 0, 0, 0 } |
| 37 |
}; |
| 38 |
|
| 39 |
static int device_mode = 0; |
| 40 |
|
| 41 |
static error_t parse_opt(int k, char *arg, struct argp_state *state) |
| 42 |
{ |
| 43 |
switch (k) { |
| 44 |
case 'd': |
| 45 |
device_mode++; |
| 46 |
break; |
| 47 |
default: |
| 48 |
return ARGP_ERR_UNKNOWN; |
| 49 |
} |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
static struct argp argp = { |
| 54 |
.options = options, |
| 55 |
.parser = parse_opt, |
| 56 |
}; |
| 57 |
|
| 58 |
static void print_all_associated_devices(void *md, const char *vid, |
| 59 |
const enum device_type type) |
| 60 |
{ |
| 61 |
const char *devname = NULL; |
| 62 |
int first = 1; |
| 63 |
|
| 64 |
do { |
| 65 |
devname = get_associated_device(md, devname, type, |
| 66 |
vid, MEDIA_V4L_VIDEO); |
| 67 |
if (devname) { |
| 68 |
if (first) { |
| 69 |
printf("\t%s: ", media_device_type(type)); |
| 70 |
first = 0; |
| 71 |
} |
| 72 |
|
| 73 |
printf("%s ", devname); |
| 74 |
} |
| 75 |
} while (devname); |
| 76 |
if (!first) |
| 77 |
printf("\n"); |
| 78 |
} |
| 79 |
|
| 80 |
static void print_all_alsa_independent_playback(void *md) |
| 81 |
{ |
| 82 |
const char *devname = NULL; |
| 83 |
int first = 1; |
| 84 |
|
| 85 |
do { |
| 86 |
devname = get_not_associated_device(md, devname, MEDIA_SND_OUT, |
| 87 |
MEDIA_V4L_VIDEO); |
| 88 |
if (devname) { |
| 89 |
if (first) { |
| 90 |
printf("Alsa playback device(s): "); |
| 91 |
first = 0; |
| 92 |
} |
| 93 |
|
| 94 |
printf("%s ", devname); |
| 95 |
} |
| 96 |
} while (devname); |
| 97 |
if (!first) |
| 98 |
printf("\n"); |
| 99 |
} |
| 100 |
|
| 101 |
int main(int argc, char *argv[]) |
| 102 |
{ |
| 103 |
void *md; |
| 104 |
const char *vid; |
| 105 |
int i; |
| 106 |
|
| 107 |
argp_parse(&argp, argc, argv, 0, 0, 0); |
| 108 |
|
| 109 |
md = discover_media_devices(); |
| 110 |
|
| 111 |
if (device_mode) { |
| 112 |
display_media_devices(md); |
| 113 |
} else { |
| 114 |
vid = NULL; |
| 115 |
do { |
| 116 |
vid = get_associated_device(md, vid, MEDIA_V4L_VIDEO, |
| 117 |
NULL, NONE); |
| 118 |
if (!vid) |
| 119 |
break; |
| 120 |
printf("Video device: %s\n", vid); |
| 121 |
|
| 122 |
for (i = 0; i <= MEDIA_SND_HW; i++) |
| 123 |
print_all_associated_devices(md, vid, i); |
| 124 |
} while (vid); |
| 125 |
|
| 126 |
print_all_alsa_independent_playback(md); |
| 127 |
} |
| 128 |
|
| 129 |
free_media_devices(md); |
| 130 |
|
| 131 |
return 0; |
| 132 |
} |