| 1 |
#include "v4l2-ctl.h" |
| 2 |
|
| 3 |
static struct v4l2_audio vaudio; /* list audio inputs */ |
| 4 |
static struct v4l2_audioout vaudout; /* audio outputs */ |
| 5 |
static int input; /* set_input/get_input */ |
| 6 |
static int output; /* set_output/get_output */ |
| 7 |
|
| 8 |
void io_usage() |
| 9 |
{ |
| 10 |
printf("\nInput/Output options:\n" |
| 11 |
" -I, --get-input query the video input [VIDIOC_G_INPUT]\n" |
| 12 |
" -i, --set-input <num>\n" |
| 13 |
" set the video input to <num> [VIDIOC_S_INPUT]\n" |
| 14 |
" -N, --list-outputs display video outputs [VIDIOC_ENUMOUTPUT]\n" |
| 15 |
" -n, --list-inputs display video inputs [VIDIOC_ENUMINPUT]\n" |
| 16 |
" -O, --get-output query the video output [VIDIOC_G_OUTPUT]\n" |
| 17 |
" -o, --set-output <num>\n" |
| 18 |
" set the video output to <num> [VIDIOC_S_OUTPUT]\n" |
| 19 |
" --set-audio-output <num>\n" |
| 20 |
" set the audio output to <num> [VIDIOC_S_AUDOUT]\n" |
| 21 |
" --get-audio-input query the audio input [VIDIOC_G_AUDIO]\n" |
| 22 |
" --set-audio-input <num>\n" |
| 23 |
" set the audio input to <num> [VIDIOC_S_AUDIO]\n" |
| 24 |
" --get-audio-output query the audio output [VIDIOC_G_AUDOUT]\n" |
| 25 |
" --set-audio-output <num>\n" |
| 26 |
" set the audio output to <num> [VIDIOC_S_AUDOUT]\n" |
| 27 |
" --list-audio-outputs\n" |
| 28 |
" display audio outputs [VIDIOC_ENUMAUDOUT]\n" |
| 29 |
" --list-audio-inputs\n" |
| 30 |
" display audio inputs [VIDIOC_ENUMAUDIO]\n" |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
static const char *inputtype2s(__u32 type) |
| 35 |
{ |
| 36 |
switch (type) { |
| 37 |
case V4L2_INPUT_TYPE_TUNER: |
| 38 |
return "Tuner"; |
| 39 |
case V4L2_INPUT_TYPE_CAMERA: |
| 40 |
return "Camera"; |
| 41 |
case V4L2_INPUT_TYPE_TOUCH: |
| 42 |
return "Touch"; |
| 43 |
default: |
| 44 |
return "Unknown"; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
static const char *outputtype2s(__u32 type) |
| 49 |
{ |
| 50 |
switch (type) { |
| 51 |
case V4L2_OUTPUT_TYPE_MODULATOR: |
| 52 |
return "Modulator"; |
| 53 |
case V4L2_OUTPUT_TYPE_ANALOG: |
| 54 |
return "Analog"; |
| 55 |
case V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY: |
| 56 |
return "Analog VGA Overlay"; |
| 57 |
default: |
| 58 |
return "Unknown"; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void io_cmd(int ch, char *optarg) |
| 63 |
{ |
| 64 |
switch (ch) { |
| 65 |
case OptSetInput: |
| 66 |
input = strtol(optarg, nullptr, 0); |
| 67 |
break; |
| 68 |
case OptSetOutput: |
| 69 |
output = strtol(optarg, nullptr, 0); |
| 70 |
break; |
| 71 |
case OptSetAudioInput: |
| 72 |
vaudio.index = strtoul(optarg, nullptr, 0); |
| 73 |
break; |
| 74 |
case OptSetAudioOutput: |
| 75 |
vaudout.index = strtoul(optarg, nullptr, 0); |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
void io_set(cv4l_fd &_fd) |
| 81 |
{ |
| 82 |
int fd = _fd.g_fd(); |
| 83 |
|
| 84 |
if (options[OptSetInput]) { |
| 85 |
if (doioctl(fd, VIDIOC_S_INPUT, &input) == 0) { |
| 86 |
struct v4l2_input vin; |
| 87 |
|
| 88 |
printf("Video input set to %d", input); |
| 89 |
vin.index = input; |
| 90 |
if (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) |
| 91 |
printf(" (%s: %s, %s)", vin.name, |
| 92 |
inputtype2s(vin.type), |
| 93 |
in_status2s(vin.status).c_str()); |
| 94 |
printf("\n"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if (options[OptSetOutput]) { |
| 99 |
if (doioctl(fd, VIDIOC_S_OUTPUT, &output) == 0) |
| 100 |
printf("Output set to %d\n", output); |
| 101 |
} |
| 102 |
|
| 103 |
if (options[OptSetAudioInput]) { |
| 104 |
if (doioctl(fd, VIDIOC_S_AUDIO, &vaudio) == 0) |
| 105 |
printf("Audio input set to %d\n", vaudio.index); |
| 106 |
} |
| 107 |
|
| 108 |
if (options[OptSetAudioOutput]) { |
| 109 |
if (doioctl(fd, VIDIOC_S_AUDOUT, &vaudout) == 0) |
| 110 |
printf("Audio output set to %d\n", vaudout.index); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
void io_get(cv4l_fd &_fd) |
| 115 |
{ |
| 116 |
int fd = _fd.g_fd(); |
| 117 |
|
| 118 |
if (options[OptGetInput]) { |
| 119 |
if (doioctl(fd, VIDIOC_G_INPUT, &input) == 0) { |
| 120 |
struct v4l2_input vin; |
| 121 |
|
| 122 |
printf("Video input : %d", input); |
| 123 |
vin.index = input; |
| 124 |
if (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) |
| 125 |
printf(" (%s: %s)", vin.name, in_status2s(vin.status).c_str()); |
| 126 |
printf("\n"); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
if (options[OptGetOutput]) { |
| 131 |
if (doioctl(fd, VIDIOC_G_OUTPUT, &output) == 0) { |
| 132 |
struct v4l2_output vout; |
| 133 |
|
| 134 |
printf("Video output: %d", output); |
| 135 |
vout.index = output; |
| 136 |
if (test_ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) { |
| 137 |
printf(" (%s)", vout.name); |
| 138 |
} |
| 139 |
printf("\n"); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
if (options[OptGetAudioInput]) { |
| 144 |
if (doioctl(fd, VIDIOC_G_AUDIO, &vaudio) == 0) |
| 145 |
printf("Audio input : %d (%s)\n", vaudio.index, vaudio.name); |
| 146 |
} |
| 147 |
|
| 148 |
if (options[OptGetAudioOutput]) { |
| 149 |
if (doioctl(fd, VIDIOC_G_AUDOUT, &vaudout) == 0) |
| 150 |
printf("Audio output: %d (%s)\n", vaudout.index, vaudout.name); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
void io_list(cv4l_fd &_fd) |
| 155 |
{ |
| 156 |
int fd = _fd.g_fd(); |
| 157 |
|
| 158 |
if (options[OptListInputs]) { |
| 159 |
struct v4l2_input vin; |
| 160 |
|
| 161 |
vin.index = 0; |
| 162 |
printf("ioctl: VIDIOC_ENUMINPUT\n"); |
| 163 |
while (test_ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) { |
| 164 |
if (vin.index) |
| 165 |
printf("\n"); |
| 166 |
printf("\tInput : %d\n", vin.index); |
| 167 |
printf("\tName : %s\n", vin.name); |
| 168 |
printf("\tType : 0x%08X (%s)\n", vin.type, inputtype2s(vin.type)); |
| 169 |
printf("\tAudioset : 0x%08X\n", vin.audioset); |
| 170 |
printf("\tTuner : 0x%08X\n", vin.tuner); |
| 171 |
printf("\tStandard : 0x%016llX (%s)\n", static_cast<unsigned long long>(vin.std), |
| 172 |
std2s(vin.std).c_str()); |
| 173 |
printf("\tStatus : 0x%08X (%s)\n", vin.status, in_status2s(vin.status).c_str()); |
| 174 |
printf("\tCapabilities: 0x%08X (%s)\n", vin.capabilities, input_cap2s(vin.capabilities).c_str()); |
| 175 |
vin.index++; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
if (options[OptListOutputs]) { |
| 180 |
struct v4l2_output vout; |
| 181 |
|
| 182 |
vout.index = 0; |
| 183 |
printf("ioctl: VIDIOC_ENUMOUTPUT\n"); |
| 184 |
while (test_ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) { |
| 185 |
if (vout.index) |
| 186 |
printf("\n"); |
| 187 |
printf("\tOutput : %d\n", vout.index); |
| 188 |
printf("\tName : %s\n", vout.name); |
| 189 |
printf("\tType : 0x%08X (%s)\n", vout.type, outputtype2s(vout.type)); |
| 190 |
printf("\tAudioset : 0x%08X\n", vout.audioset); |
| 191 |
printf("\tStandard : 0x%016llX (%s)\n", static_cast<unsigned long long>(vout.std), |
| 192 |
std2s(vout.std).c_str()); |
| 193 |
printf("\tCapabilities: 0x%08X (%s)\n", vout.capabilities, output_cap2s(vout.capabilities).c_str()); |
| 194 |
vout.index++; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if (options[OptListAudioInputs]) { |
| 199 |
struct v4l2_audio vaudio; /* list audio inputs */ |
| 200 |
vaudio.index = 0; |
| 201 |
printf("ioctl: VIDIOC_ENUMAUDIO\n"); |
| 202 |
while (test_ioctl(fd, VIDIOC_ENUMAUDIO, &vaudio) >= 0) { |
| 203 |
if (vaudio.index) |
| 204 |
printf("\n"); |
| 205 |
printf("\tInput : %d\n", vaudio.index); |
| 206 |
printf("\tName : %s\n", vaudio.name); |
| 207 |
vaudio.index++; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
if (options[OptListAudioOutputs]) { |
| 212 |
struct v4l2_audioout vaudio; /* list audio outputs */ |
| 213 |
vaudio.index = 0; |
| 214 |
printf("ioctl: VIDIOC_ENUMAUDOUT\n"); |
| 215 |
while (test_ioctl(fd, VIDIOC_ENUMAUDOUT, &vaudio) >= 0) { |
| 216 |
if (vaudio.index) |
| 217 |
printf("\n"); |
| 218 |
printf("\tOutput : %d\n", vaudio.index); |
| 219 |
printf("\tName : %s\n", vaudio.name); |
| 220 |
vaudio.index++; |
| 221 |
} |
| 222 |
} |
| 223 |
} |