diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-16 08:49:04 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-16 08:49:04 -0300 |
commit | 85d13c8ef6cb0f70323a77515b59f5a4d2444d3f (patch) | |
tree | 19666bcda7adefb3b1186f2db269d98fac2aa740 /v4l2-apps/util | |
parent | eb80450edef873c9b5d0a839659da0a642e7716a (diff) | |
parent | 7178a759bcb68c7e95477ff7fbfcdfb1631168c5 (diff) | |
download | mediapointer-dvb-s2-85d13c8ef6cb0f70323a77515b59f5a4d2444d3f.tar.gz mediapointer-dvb-s2-85d13c8ef6cb0f70323a77515b59f5a4d2444d3f.tar.bz2 |
merge: http://linuxtv.org/hg/~pb/v4l-dvb/
From: Mauro Carvalho Chehab <mchehab@redhat.com>
Priority: normal
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'v4l2-apps/util')
-rw-r--r-- | v4l2-apps/util/Makefile | 34 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/audioplayback | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/audiorecord | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/cx25821-medusa-decoder.c | 106 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/medusaReadWrite.c | 158 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mencode_av | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mencode_video | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mplay_av | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mplay_cifNTSC | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mplay_cifPAL | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/mplay_video | 1 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/regReadWrite.c | 158 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/setAlsaVolume | 2 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/setvideosetting.c | 187 | ||||
-rw-r--r-- | v4l2-apps/util/cx25821/upstream_app.c | 221 | ||||
-rw-r--r-- | v4l2-apps/util/decode_tm6000.c | 364 | ||||
-rwxr-xr-x | v4l2-apps/util/gen_keytables.pl | 7 | ||||
-rw-r--r-- | v4l2-apps/util/keytable.c | 43 | ||||
-rw-r--r-- | v4l2-apps/util/v4l2-ctl.cpp | 470 | ||||
-rw-r--r-- | v4l2-apps/util/v4l2-sysfs-path.c | 130 | ||||
-rw-r--r-- | v4l2-apps/util/xc3028-firmware/firmware-tool.c | 4 |
21 files changed, 1765 insertions, 127 deletions
diff --git a/v4l2-apps/util/Makefile b/v4l2-apps/util/Makefile index 6f9d1071a..0bee48571 100644 --- a/v4l2-apps/util/Makefile +++ b/v4l2-apps/util/Makefile @@ -1,5 +1,26 @@ # Makefile for linuxtv.org v4l2-apps/util +IR_FILES = "linux/drivers/media/common/ir-keymaps.c \ +linux/drivers/media/dvb/dvb-usb/a800.c \ +linux/drivers/media/dvb/dvb-usb/af9005-remote.c \ +linux/drivers/media/dvb/dvb-usb/af9015.c \ +linux/drivers/media/dvb/dvb-usb/af9015.h \ +linux/drivers/media/dvb/dvb-usb/anysee.c \ +linux/drivers/media/dvb/dvb-usb/cinergyT2-core.c \ +linux/drivers/media/dvb/dvb-usb/cxusb.c \ +linux/drivers/media/dvb/dvb-usb/dib0700_devices.c \ +linux/drivers/media/dvb/dvb-usb/dibusb-common.c \ +linux/drivers/media/dvb/dvb-usb/digitv.c \ +linux/drivers/media/dvb/dvb-usb/dtt200u.c \ +linux/drivers/media/dvb/dvb-usb/dvb-usb-remote.c \ +linux/drivers/media/dvb/dvb-usb/dvb-usb.h \ +linux/drivers/media/dvb/dvb-usb/dw2102.c \ +linux/drivers/media/dvb/dvb-usb/m920x.c \ +linux/drivers/media/dvb/dvb-usb/nova-t-usb2.c \ +linux/drivers/media/dvb/dvb-usb/opera1.c \ +linux/drivers/media/dvb/dvb-usb/vp702x.c \ +linux/drivers/media/dvb/dvb-usb/vp7045.c " + ifeq ($(KERNEL_DIR),) KERNEL_DIR = /usr endif @@ -7,7 +28,7 @@ endif CPPFLAGS += -I../include -D_GNU_SOURCE LDFLAGS += -lm -binaries = v4l2-ctl v4l2-dbg v4l2-compliance ivtv-ctl cx18-ctl v4l2-sysfs-path +binaries = v4l2-ctl v4l2-dbg v4l2-compliance ivtv-ctl cx18-ctl v4l2-sysfs-path decode_tm6000 ifeq ($(prefix),) prefix = /usr @@ -32,6 +53,12 @@ qv4l2: v4l2-dbg: v4l2-dbg.o v4l2-chipids.o $(CXX) $^ -o $@ +../lib/libv4l2.a: ../lib/v4l2_driver.c ../lib/frequencies.c + make -C ../lib libv4l2.a + +decode_tm6000: decode_tm6000.o ../lib/libv4l2.a + + v4l2-dbg.o: v4l2-dbg.h v4l2-dbg-bttv.h v4l2-dbg-em28xx.h v4l2-dbg-saa7134.h v4l2-sysfs-path.o: v4l2-sysfs-path.c ../libv4l2util/v4l2_driver.h @@ -62,8 +89,9 @@ parse.h: $(KERNEL_DIR)/include/linux/input.h @printf "\t{ NULL, 0}\n};\n" >>parse.h keytables: - -mkdir -p keycodes - ./gen_keytables.pl ../../linux/drivers/media/common/ir-keymaps.c + @-mkdir -p keycodes + @echo storing existing keycodes at keycodes/ + @for i in `echo $(IR_FILES)`; do ./gen_keytables.pl ../../$$i; done keytable: keytable.c parse.h keytables diff --git a/v4l2-apps/util/cx25821/audioplayback b/v4l2-apps/util/cx25821/audioplayback new file mode 100644 index 000000000..1b09da915 --- /dev/null +++ b/v4l2-apps/util/cx25821/audioplayback @@ -0,0 +1 @@ +aplay -c 2 -r 48000 -f S16_LE $1 diff --git a/v4l2-apps/util/cx25821/audiorecord b/v4l2-apps/util/cx25821/audiorecord new file mode 100644 index 000000000..ee2c46650 --- /dev/null +++ b/v4l2-apps/util/cx25821/audiorecord @@ -0,0 +1 @@ +arecord -D hw:1,0 -d $2 -c 2 -r 48000 -f S16_LE > $1 diff --git a/v4l2-apps/util/cx25821/cx25821-medusa-decoder.c b/v4l2-apps/util/cx25821/cx25821-medusa-decoder.c new file mode 100644 index 000000000..7bd35ed43 --- /dev/null +++ b/v4l2-apps/util/cx25821/cx25821-medusa-decoder.c @@ -0,0 +1,106 @@ +/*
+ * Driver for the Conexant CX25821 PCIe bridge
+ *
+ * Copyright (C) 2009 Conexant Systems Inc.
+ * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+ +#include "cx25821.h" + + +// Array for GPIO selected bits for a specific decoder. + +enum GPIO_DEF { DECA_SEL = 0, + DECB_SEL, + DECC_SEL, + DECD_SEL, + MON_SEL = 4}; + +enum GPIO_OCTAL_DEF { OCTAL_DECA_SEL = 0, + OCTAL_DECB_SEL, + OCTAL_DECC_SEL, + OCTAL_DECD_SEL, + OCTAL_DECE_SEL, + OCTAL_DECF_SEL, + OCTAL_DECG_SEL, + OCTAL_DECH_SEL, + OCTAL_MON_SEL = 8 }; + + +// Direction bits are at offset 23:16 +#define Set_GPIO_Direction_Bit_To_OUTPUT(Bit) ((1 << Bit) << 16) + +struct medusa_decoder { + int _cur_dec; + unsigned short _num_vdec; +}; + +//////////////////////////////////////////////////////////////////////////////////////// +// Selects Medusa Decoder Channel. +//////////////////////////////////////////////////////////////////////////////////////// +void medusa_decoder_select(struct cx25821_dev *dev, struct medusa_decoder *dec, int decoder) +{ + + if (decoder < DECA_SEL && decoder > MON_SEL ) + return; + + dec->_cur_dec = decoder; + + u32 gpioRegister = cx_read(GP0_IO); + u32 value = (gpioRegister & 0xFFFFFFF0) | dec->_cur_dec; + cx_write( GP0_IO, value ); +} + +//////////////////////////////////////////////////////////////////////////////////////// +// Sets the GPIO pin directions +// Parameters: +// +//////////////////////////////////////////////////////////////////////////////////////// +void medusa_video_set_gpiopin_directions_to_output(struct cx25821_dev *dev, struct medusa_decoder *dec ) +{ + // Here we will make sure that the GPIOs 0-3 are output. keep the rest as is + u32 gpioRegister = cx_read( GP0_IO ); + + // This operation will set the GPIO bits below. + if (dec->_num_vdec == 4) + { + cx_write( GP0_IO, + gpioRegister + | (Set_GPIO_Direction_Bit_To_OUTPUT(DECA_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(DECB_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(DECC_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(DECD_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(MON_SEL)) ); + medusa_decoder_select(dev, dec, MON_SEL); + } + else + { + cx_write( GP0_IO, + gpioRegister + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECA_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECB_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECC_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECD_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECE_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECF_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECG_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_DECH_SEL)) + | (Set_GPIO_Direction_Bit_To_OUTPUT(OCTAL_MON_SEL)) ); + medusa_decoder_select(dev, dec, OCTAL_MON_SEL); + } +} diff --git a/v4l2-apps/util/cx25821/medusaReadWrite.c b/v4l2-apps/util/cx25821/medusaReadWrite.c new file mode 100644 index 000000000..cf4a1a5e6 --- /dev/null +++ b/v4l2-apps/util/cx25821/medusaReadWrite.c @@ -0,0 +1,158 @@ +/* + * Driver for the Conexant CX25821 PCIe bridge + * + * Copyright (C) 2009 Conexant Systems Inc. + * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <string.h> +#include <linux/errno.h> +#include <linux/ioctl.h> + + +#define MEDUSA_READ 910 +#define MEDUSA_WRITE 911 + +typedef struct{ + char *vid_stdname; + int pixel_format; + int cif_resolution_enable; + int cif_width; + int decoder_select; + int command; + int reg_address; + int reg_data; +}downstream_user_struct; + + +void print_usage() +{ + printf("\n*********************************\n"); + printf("Sample Usage: ./medusa d 1 r 0x01\n"); + printf("Sample Usage: ./medusa d 1 w 0x0 0x2\n"); + printf(" d device_id Device ID (1 and above) for MultiCard\n"); + printf(" r Read Medusa register\n"); + printf(" w Write Medusa register\n"); +} + +int main(int argc, char** argv) +{ + unsigned int cmd= 0 ; + int fp; + int i = 1, j = 0, k = 0, len = 0; + int mode = 0; + + int register_addr = 0; + int write_value = 0; + + int device_id = 0, video_id = 11; + char * temp2; + char *device_str[4] = {"/dev/video11", "/dev/video23", "/dev/video35", "/dev/video47"}; + + char mode_temp = 's'; + char *param_temp; + + + if(argc < 5 || (tolower(*(argv[1])) != 'd') ) + { + print_usage(); + return -EINVAL; + } + + sscanf(argv[2], "%d", &device_id ); + i += 2; + + if( device_id <= 0 || device_id > 4 ) + { + print_usage(); + return -EINVAL; + } + + printf("\n********************************* \n"); + + if((fp = open(device_str[device_id-1], O_RDWR)) == -1) + { + printf("Error: cannot open device file %s !\n", device_str[device_id-1]); + return -EINVAL; + } + + printf("Device %s open for IOCTL successfully!\n", device_str[device_id-1]); + + + for( ; i < argc; i++) + { + temp2 = argv[i]; + mode_temp = tolower(temp2[0]); + param_temp = argv[i+1]; + + + switch(mode_temp) + { + case 'r': + { + downstream_user_struct arguments; + + sscanf(param_temp, "%x", ®ister_addr ); + + arguments.reg_address = register_addr; + arguments.command = MEDUSA_READ; + + printf("Read parameters: read register = 0x%x, command = %d \n", arguments.reg_address, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + printf("Reg 0x%x = 0x%x\n", arguments.reg_address, arguments.reg_data); + } + break; + + case 'w': + { + downstream_user_struct arguments; + + sscanf(param_temp, "%x", ®ister_addr ); + sscanf(argv[i+2], "%x", &write_value ); + i++; + + arguments.command = MEDUSA_WRITE; + arguments.reg_address = register_addr; + arguments.reg_data = write_value; + + printf("Write parameters: write register = 0x%x, write_value = 0x%x, command = %d \n", arguments.reg_address, arguments.reg_data, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + default: + printf("Please verify the options are correct!\n"); + break; + } + + i++; + } + + + printf("********************************* \n\n"); + close(fp); + return 0; +} + diff --git a/v4l2-apps/util/cx25821/mencode_av b/v4l2-apps/util/cx25821/mencode_av new file mode 100644 index 000000000..6533cb4d8 --- /dev/null +++ b/v4l2-apps/util/cx25821/mencode_av @@ -0,0 +1 @@ +mencoder tv:// -tv driver=v4l2:input=0:norm=ntsc:width=720:height=480:outfmt=yuy2:device=/dev/video$1:forceaudio:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 buffersize=64 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000:keyint=30 -oac mp3lame -lameopts br=128:cbr:mode=3 -ffourcc divx -o $2
\ No newline at end of file diff --git a/v4l2-apps/util/cx25821/mencode_video b/v4l2-apps/util/cx25821/mencode_video new file mode 100644 index 000000000..9f0c29ebd --- /dev/null +++ b/v4l2-apps/util/cx25821/mencode_video @@ -0,0 +1 @@ +mencoder tv:// -tv driver=v4l2:input=0:norm=ntsc:width=720:height=480:outfmt=yuy2:device=/dev/video$1 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000:keyint=30 -nosound -ffourcc divx -o $2 diff --git a/v4l2-apps/util/cx25821/mplay_av b/v4l2-apps/util/cx25821/mplay_av new file mode 100644 index 000000000..0b11e7af6 --- /dev/null +++ b/v4l2-apps/util/cx25821/mplay_av @@ -0,0 +1 @@ +mplayer -vo x11 -tv driver=v4l2:device=/dev/video$1:input=1:norm=NTSC-M:width=720:height=480:outfmt=yuy2:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:///0 diff --git a/v4l2-apps/util/cx25821/mplay_cifNTSC b/v4l2-apps/util/cx25821/mplay_cifNTSC new file mode 100644 index 000000000..ba3c34ec2 --- /dev/null +++ b/v4l2-apps/util/cx25821/mplay_cifNTSC @@ -0,0 +1 @@ +mplayer -vo x11 -tv driver=v4l2:device=/dev/video$1:input=1:norm=NTSC-M:width=320:height=240:outfmt=yuy2: tv:///0 diff --git a/v4l2-apps/util/cx25821/mplay_cifPAL b/v4l2-apps/util/cx25821/mplay_cifPAL new file mode 100644 index 000000000..2139ffb0a --- /dev/null +++ b/v4l2-apps/util/cx25821/mplay_cifPAL @@ -0,0 +1 @@ +mplayer -vo x11 -tv driver=v4l2:device=/dev/video$1:input=1:norm=PAL-BG:width=352:height=288:outfmt=yuy2: tv:///0 diff --git a/v4l2-apps/util/cx25821/mplay_video b/v4l2-apps/util/cx25821/mplay_video new file mode 100644 index 000000000..7d9567662 --- /dev/null +++ b/v4l2-apps/util/cx25821/mplay_video @@ -0,0 +1 @@ +mplayer -vo x11 -tv driver=v4l2:device=/dev/video$1:input=1:norm=NTSC-M:width=720:height=480:outfmt=yuy2: tv:///0 diff --git a/v4l2-apps/util/cx25821/regReadWrite.c b/v4l2-apps/util/cx25821/regReadWrite.c new file mode 100644 index 000000000..2d506183d --- /dev/null +++ b/v4l2-apps/util/cx25821/regReadWrite.c @@ -0,0 +1,158 @@ +/* + * Driver for the Conexant CX25821 PCIe bridge + * + * Copyright (C) 2009 Conexant Systems Inc. + * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <string.h> +#include <linux/errno.h> +#include <linux/ioctl.h> + + +#define REG_READ 900 +#define REG_WRITE 901 + +typedef struct{ + char *vid_stdname; + int pixel_format; + int cif_resolution_enable; + int cif_width; + int decoder_select; + int command; + int reg_address; + int reg_data; +}downstream_user_struct; + + +void print_usage() +{ + printf("\n*********************************\n"); + printf("Sample Usage: ./reg d 1 r 0x01\n"); + printf("Sample Usage: ./reg d 1 w 0x0 0x2\n"); + printf(" d device_id Device ID (1 and above) for MultiCard\n"); + printf(" r Read Athena register\n"); + printf(" w Write Athena register\n"); +} + +int main(int argc, char** argv) +{ + unsigned int cmd= 0 ; + int fp; + int i = 1, j = 0, k = 0, len = 0; + int mode = 0; + + int register_addr = 0; + int write_value = 0; + + int device_id = 0, video_id = 11; + char * temp2; + char *device_str[4] = {"/dev/video11", "/dev/video23", "/dev/video35", "/dev/video47"}; + + char mode_temp = 's'; + char *param_temp; + + + if(argc < 5 || (tolower(*(argv[1])) != 'd') ) + { + print_usage(); + return -EINVAL; + } + + sscanf(argv[2], "%d", &device_id ); + i += 2; + + if( device_id <= 0 || device_id > 4 ) + { + print_usage(); + return -EINVAL; + } + + printf("\n********************************* \n"); + + if((fp = open(device_str[device_id-1], O_RDWR)) == -1) + { + printf("Error: cannot open device file %s !\n", device_str[device_id-1]); + return -EINVAL; + } + + printf("Device %s open for IOCTL successfully!\n", device_str[device_id-1]); + + + for( ; i < argc; i++) + { + temp2 = argv[i]; + mode_temp = tolower(temp2[0]); + param_temp = argv[i+1]; + + + switch(mode_temp) + { + case 'r': + { + downstream_user_struct arguments; + + sscanf(param_temp, "%x", ®ister_addr ); + + arguments.reg_address = register_addr; + arguments.command = REG_READ; + + printf("Read parameters: read register = 0x%x, command = %d \n", arguments.reg_address, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + printf("Reg 0x%x = 0x%x\n", arguments.reg_address, arguments.reg_data); + } + break; + + case 'w': + { + downstream_user_struct arguments; + + sscanf(param_temp, "%x", ®ister_addr ); + sscanf(argv[i+2], "%x", &write_value ); + i++; + + arguments.command = REG_WRITE; + arguments.reg_address = register_addr; + arguments.reg_data = write_value; + + printf("Write parameters: write register = 0x%x, write_value = 0x%x, command = %d \n", arguments.reg_address, arguments.reg_data, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + default: + printf("Please verify the options are correct!\n"); + break; + } + + i++; + } + + + printf("********************************* \n\n"); + close(fp); + return 0; +} + diff --git a/v4l2-apps/util/cx25821/setAlsaVolume b/v4l2-apps/util/cx25821/setAlsaVolume new file mode 100644 index 000000000..55dd3dc89 --- /dev/null +++ b/v4l2-apps/util/cx25821/setAlsaVolume @@ -0,0 +1,2 @@ +amixer set Master,0 100% unmute +amixer set Capture,0 90% captur diff --git a/v4l2-apps/util/cx25821/setvideosetting.c b/v4l2-apps/util/cx25821/setvideosetting.c new file mode 100644 index 000000000..87e36045d --- /dev/null +++ b/v4l2-apps/util/cx25821/setvideosetting.c @@ -0,0 +1,187 @@ +/* + * Driver for the Conexant CX25821 PCIe bridge + * + * Copyright (C) 2009 Conexant Systems Inc. + * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <string.h> +#include <linux/errno.h> +#include <linux/ioctl.h> + + +#define SET_VIDEO_STD 800 +#define SET_PIXEL_FORMAT 1000 +#define ENABLE_CIF_RESOLUTION 1001 + + +#define PIXEL_FRMT_422 4 +#define PIXEL_FRMT_411 5 +#define PIXEL_FRMT_Y8 6 +#define ALL_DECODERS 752 + +typedef struct { + char *vid_stdname; + int pixel_format; + int cif_resolution_enable; + int cif_width; + int decoder_select; + int command; +} downstream_user_struct; + + +void print_usage() +{ + printf("\n*********************************\n"); + printf("Sample Usage: ./set d 1 standard NTSC format 422 7 resolution 320 7\n"); + printf(" device_id Device ID (1 and above) for MultiCard\n"); + printf(" standard Video Standard (PAL/NTSC)\n"); + printf(" format Output Pixel Format (422 or 411) for specific decoder (e.g. 7)\n"); + printf(" resolution 352/320 for CIF and 720 for D1 resolution for specific decoder (e.g. 7)\n"); +} + +int main(int argc, char** argv) +{ + unsigned int cmd= 0 ; + int fp; + int i = 1, j = 0, k = 0, len = 0; + int mode = 0; + int pixel_format = 0; + int width_input = 0; + int decoder_input = 0; + int device_id = 0, video_id = 11; + char * temp2; + char *device_str[4] = {"/dev/video11", "/dev/video23", "/dev/video35", "/dev/video47"}; + + char mode_temp = 's'; + char *param_temp; + + + if(argc < 3 || (tolower(*(argv[1])) != 'd') ) + { + print_usage(); + return -EINVAL; + } + + sscanf(argv[2], "%d", &device_id ); + i += 2; + + if( device_id <= 0 || device_id > 4 ) + { + print_usage(); + return -EINVAL; + } + + printf("\n********************************* \n"); + + if((fp = open(device_str[device_id-1], O_RDWR)) == -1) + { + printf("Error: cannot open device file %s !\n", device_str[device_id-1]); + return -EINVAL; + } + + printf("Device %s open for IOCTL successfully!\n", device_str[device_id-1]); + + + for( ; i < argc; i++) + { + temp2 = argv[i]; + mode_temp = tolower(temp2[0]); + param_temp = argv[i+1]; + + + switch(mode_temp) + { + case 's': + { + downstream_user_struct arguments; + char * temp = param_temp; + arguments.vid_stdname = (tolower(temp[0]) == 'p') ? "PAL" : "NTSC"; + arguments.command = SET_VIDEO_STD; + + printf("User parameters: vid_stdname = %s, command = %d \n", arguments.vid_stdname, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + case 'f': + { + sscanf(param_temp, "%d", &pixel_format ); + sscanf(argv[i+2], "%d", &decoder_input ); i++; + + if( pixel_format < 411 || pixel_format > 422) + pixel_format = 422; + + if( decoder_input < 0 ) + decoder_input = ALL_DECODERS; + + downstream_user_struct arguments; + arguments.pixel_format = (pixel_format == 411) ? PIXEL_FRMT_411 : PIXEL_FRMT_422; + arguments.decoder_select = decoder_input; + arguments.command = SET_PIXEL_FORMAT; + + printf("User parameters: pixel_format = %d, decoder_input = %d, command = %d \n", arguments.pixel_format, arguments.decoder_select, arguments.command); + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + case 'r': + { + sscanf(param_temp, "%d", &width_input ); + sscanf(argv[i+2], "%d", &decoder_input ); i++; + + if( width_input < 320 || width_input > 352 ) + width_input = 720; + + if( decoder_input < 0 ) + decoder_input = ALL_DECODERS; + + downstream_user_struct arguments; + arguments.cif_resolution_enable = (width_input == 320 || width_input == 352) ? 1 : 0; + arguments.cif_width = width_input; + arguments.decoder_select = decoder_input; + arguments.command = ENABLE_CIF_RESOLUTION; + + printf("User parameters: cif_resolution_enable = %d, decoder_input = %d, command = %d \n", arguments.cif_resolution_enable, arguments.decoder_select, arguments.command); + + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + default: + printf("Please verify the options are correct!\n"); + break; + } + + i++; + } + + + printf("********************************* \n\n"); + close(fp); + return 0; +} diff --git a/v4l2-apps/util/cx25821/upstream_app.c b/v4l2-apps/util/cx25821/upstream_app.c new file mode 100644 index 000000000..97f7b84aa --- /dev/null +++ b/v4l2-apps/util/cx25821/upstream_app.c @@ -0,0 +1,221 @@ +/* + * Driver for the Conexant CX25821 PCIe bridge + * + * Copyright (C) 2009 Conexant Systems Inc. + * Authors <hiep.huynh@conexant.com>, <shu.lin@conexant.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <string.h> +#include <linux/errno.h> +#include <linux/ioctl.h> + +#define VID_UPSTREAM_SRAM_CHANNEL_I 9 +#define VID_UPSTREAM_SRAM_CHANNEL_J 10 +#define AUDIO_UPSTREAM_SRAM_CHANNEL_B 11 +#define PIXEL_FRMT_422 4 +#define PIXEL_FRMT_411 5 +#define UPSTREAM_START_VIDEO 700 +#define UPSTREAM_STOP_VIDEO 701 +#define UPSTREAM_START_AUDIO 702 +#define UPSTREAM_STOP_AUDIO 703 +#define UPSTREAM_DUMP_REGISTERS 702 + + +typedef struct { + char *input_filename; + char *vid_stdname; + int pixel_format; + int channel_select; + int command; +} upstream_user_struct; + +void print_video_usage() +{ + printf("\n************************************************************************ \n"); + printf("Video Sample Usage: ./upstream_app d 1 v /root/filename.yuv NTSC 422 1 start \n"); + printf("Argument 0: ./upstream_app \n"); + printf("Argument 1: Device ID (1 and above)\n"); + printf("Argument 2: v for video\n"); + printf("Argument 3: input file name \n"); + printf("Argument 4: Video Standard \n"); + printf("Argument 5: Pixel Format (Y422 or Y411) \n"); + printf("Argument 6: Upstream Channel Number\n"); + printf("Argument 7: start/stop command\n\n"); +} + +void print_audio_usage() +{ + printf("\n************************************************************************ \n"); + printf("Audio Sample Usage: ./upstream_app d 1 a /root/audio.wav start\n"); + printf("Argument 0: ./upstream_app \n"); + printf("Argument 1: Device ID (1 and above)\n"); + printf("Argument 2: a for audio \n"); + printf("Argument 3: input file name \n"); + printf("Argument 4: start/stop command\n\n"); +} + +int main(int argc, char** argv) +{ + int fp; + unsigned int cmd= 0 ; + int i = 1; + int mode = 0; + int pixel_format = 422; + int channel_select = 1; + int device_id = 0, video_id = 11; + char * temp2; + char *video_device_str[4][2] = {{"/dev/video8", "/dev/video9"}, {"/dev/video20", "/dev/video21"}, + {"/dev/video32", "/dev/video33"}, {"/dev/video44", "/dev/video45"} }; + char *audio_device_str[4] = {"/dev/video10", "/dev/video22", "/dev/video34", "/dev/video46"}; + char mode_temp = 'v'; + + if(argc < 2 || (tolower(*(argv[1])) != 'd') ) + { + print_video_usage(); + print_audio_usage(); + return -EINVAL; + } + else + { + sscanf(argv[2], "%d", &device_id ); + i += 2; + + if( device_id <= 0 || device_id > 4 ) + { + print_video_usage(); + print_audio_usage(); + return -EINVAL; + } + + temp2 = argv[i]; + mode_temp = tolower(temp2[0]); + switch(mode_temp) + { + case 'v': + if( argc < 9 ) + { + print_video_usage(); + return -EINVAL; + } + break; + + case 'a': + if( argc < 6 ) + { + print_audio_usage(); + return -EINVAL; + } + break; + } + } + + if( mode_temp == 'v' || mode_temp == 'a' ) + { + FILE* file_ptr = fopen(argv[4], "r"); + + if( !file_ptr ) + { + printf("\nERROR: %s file does NOT exist!!! \n\n", argv[4]); + return -EINVAL; + } + + fclose(file_ptr); + } + else + { + print_video_usage(); + print_audio_usage(); + return -EINVAL; + } + + printf("\n*************************************************************** \n"); + + switch(mode_temp) + { + case 'v': + { + char * temp = argv[5]; + upstream_user_struct arguments; + arguments.input_filename = argv[4]; + arguments.vid_stdname = (tolower(temp[0]) == 'p') ? "PAL" : "NTSC"; + sscanf(argv[6], "%d", &pixel_format); + sscanf(argv[7], "%d", &channel_select); + arguments.pixel_format = (pixel_format == 422) ? PIXEL_FRMT_422 : PIXEL_FRMT_411; + arguments.channel_select = (channel_select==1) ? VID_UPSTREAM_SRAM_CHANNEL_I : VID_UPSTREAM_SRAM_CHANNEL_J; + temp = argv[8]; + arguments.command = (strcasecmp("STOP", temp) == 0) ? UPSTREAM_STOP_VIDEO : UPSTREAM_START_VIDEO; + + + if( channel_select >= 1 && channel_select <= 2 ) + { + if((fp = open(video_device_str[device_id-1][channel_select-1], O_RDWR)) == -1) + { + printf("Error: cannot open device file %s !\n", video_device_str[device_id-1][channel_select-1]); + return -EINVAL; + } + + printf("Device %s open for IOCTL successfully!\n", video_device_str[device_id-1][channel_select-1]); + printf("UPSTREAM parameters: filename = %s, channel_select(I=1) = %d \n", arguments.input_filename, channel_select); + + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + { + printf("Error: ioctl FAILED!\n"); + } + } + } + break; + + case 'a': + { + char * temp = argv[5]; + upstream_user_struct arguments; + arguments.input_filename = argv[4]; + arguments.vid_stdname = "NTSC"; + arguments.pixel_format = PIXEL_FRMT_422; + arguments.channel_select = AUDIO_UPSTREAM_SRAM_CHANNEL_B; + arguments.command = (strcasecmp("STOP", temp) == 0) ? UPSTREAM_STOP_AUDIO : UPSTREAM_START_AUDIO; + + + if((fp = open(audio_device_str[device_id-1], O_RDWR)) == -1) + { + printf("Error: cannot open device file %s !\n", audio_device_str[device_id-1]); + return -EINVAL; + } + + printf("Device %s open for IOCTL successfully!\n", audio_device_str[device_id-1]); + printf("UPSTREAM parameters: filename = %s, audio channel = %d \n", arguments.input_filename, arguments.channel_select); + + + if((ioctl(fp, arguments.command, (char *) &arguments)) == -1) + printf("Error: ioctl FAILED!\n"); + } + break; + + default: + printf("ERROR: INVALID ioctl command!\n"); + return -EINVAL; + } + + printf("*************************************************************** \n\n"); + close(fp); + return 0; +} diff --git a/v4l2-apps/util/decode_tm6000.c b/v4l2-apps/util/decode_tm6000.c new file mode 100644 index 000000000..d622360d2 --- /dev/null +++ b/v4l2-apps/util/decode_tm6000.c @@ -0,0 +1,364 @@ +/* + decode_tm6000.c - decode multiplexed format from TM5600/TM6000 USB + + Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@infradead.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +#include "../lib/v4l2_driver.h" +#include <stdio.h> +#include <string.h> +#include <argp.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> + +const char *argp_program_version="decode_tm6000 version 0.0.1"; +const char *argp_program_bug_address="Mauro Carvalho Chehab <mchehab@infradead.org>"; +const char doc[]="Decodes tm6000 proprietary format streams"; +const struct argp_option options[] = { + {"verbose", 'v', 0, 0, "enables debug messages", 0}, + {"device", 'd', "DEV", 0, "uses device for reading", 0}, + {"output", 'o', "FILE", 0, "outputs raw stream to a file", 0}, + {"input", 'i', "FILE", 0, "parses a file, instead of a device", 0}, + {"freq", 'f', "Freq", 0, "station frequency, in MHz (default is 193.25)", 0}, + {"nbufs", 'n', "quant",0, "number of video buffers", 0}, + {"audio", 'a', 0, 0, "outputs audio on stdout", 0}, + {"read", 'r', 0, 0, "use read() instead of mmap method", 0}, + { 0, 0, 0, 0, 0, 0 } +}; + +static char outbuf[692224]; +static int debug=0, audio=0, use_mmap=1, nbufs=4; +static float freq_mhz=193.25; +static char *devname="/dev/video0"; +static char *filename=NULL; +static enum { + NORMAL, + INPUT, + OUTPUT +} mode = NORMAL; + +static FILE *fout; + +//const char args_doc[]="ARG1 ARG2"; + +static error_t parse_opt (int key, char *arg, struct argp_state *state) +{ + switch (key) { + case 'a': + audio++; + break; + case 'r': + use_mmap=0; + break; + case 'v': + debug++; + break; + case 'd': + devname=arg; + break; + case 'i': + case 'o': + if (mode!=NORMAL) { + argp_error(state,"You can't use input/output options simultaneously.\n"); + break; + } + if (key=='i') + mode=INPUT; + else + mode=OUTPUT; + + filename=arg; + break; + case 'f': + freq_mhz=atof(arg); + break; + case 'n': + nbufs=atoi(arg); + if (nbufs<2) + nbufs=2; + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = { + .options=options, + .parser=parse_opt, + .args_doc=NULL, + .doc=doc, +}; + +#define TM6000_URB_MSG_LEN 180 +enum { + TM6000_URB_MSG_VIDEO=1, + TM6000_URB_MSG_AUDIO, + TM6000_URB_MSG_VBI, + TM6000_URB_MSG_PTS, + TM6000_URB_MSG_ERR, +}; + +const char *tm6000_msg_type[]= { + "unknown(0)", //0 + "video", //1 + "audio", //2 + "vbi", //3 + "pts", //4 + "err", //5 + "unknown(6)", //6 + "unknown(7)", //7 +}; + +#define dprintf(fmt,arg...) \ + if (debug) fprintf(stderr, fmt, ##arg) + +int recebe_buffer (struct v4l2_buffer *v4l2_buf, struct v4l2_t_buf *buf) +{ + dprintf("Received %d bytes\n",buf->length); +fflush(stdout); + memcpy (outbuf,buf->start,buf->length); + return buf->length; +} + + +int prepare_read (struct v4l2_driver *drv) +{ + struct v4l2_format fmt; + double freq; + int rc; + + memset (drv,0,sizeof(*drv)); + + if (v4l2_open (devname, 1,drv)<0) { + perror ("Error opening dev"); + return -1; + } + + memset (&fmt,0,sizeof(fmt)); + + uint32_t pixelformat=V4L2_PIX_FMT_TM6000; + + if (v4l2_gettryset_fmt_cap (drv,V4L2_SET,&fmt, 720, 480, + pixelformat,V4L2_FIELD_ANY)) { + perror("set_input to tm6000 raw format"); + return -1; + } + + if (freq_mhz) { + freq=freq_mhz * 1000 * 1000; + rc=v4l2_getset_freq (drv,V4L2_SET, &freq); + if (rc<0) + printf ("Cannot set freq to %.3f MHz\n",freq_mhz); + } + + if (use_mmap) { + printf("Preparing for receiving frames on %d buffers...\n",nbufs); + fflush (stdout); + + rc=v4l2_mmap_bufs(drv, nbufs); + if (rc<0) { + printf ("Cannot mmap %d buffers\n",nbufs); + return -1; + } + +// v4l2_stop_streaming(&drv); + rc=v4l2_start_streaming(drv); + if (rc<0) { + printf ("Cannot start streaming\n"); + return -1; + } + } + printf("Waiting for frames...\n"); + + return 0; +} + +int read_stream (struct v4l2_driver *drv, int fd) +{ + if (use_mmap) { + fd_set fds; + struct timeval tv; + int r; + + FD_ZERO (&fds); + FD_SET (fd, &fds); + + /* Timeout. */ + tv.tv_sec = 2; + tv.tv_usec = 0; + + r = select (fd + 1, &fds, NULL, NULL, &tv); + if (-1 == r) { + if (EINTR == errno) { + perror ("select"); + return -errno; + } + } + + if (0 == r) { + fprintf (stderr, "select timeout\n"); + return -errno; + } + + return v4l2_rcvbuf(drv, recebe_buffer); + } else { + int size=read(fd, outbuf, sizeof(outbuf)); + return size; + } + + return 0; +} + +int read_char (struct v4l2_driver *drv, int fd) +{ + static int sizebuf=0; + static unsigned char *p=NULL; + unsigned char c; + + if (sizebuf<=0) { + sizebuf=read_stream(drv,fd); + if (sizebuf<=0) + return -1; + p=(unsigned char *)outbuf; + } + c=*p; + p++; + sizebuf--; + + return c; +} + + +int main (int argc, char*argv[]) +{ + int fd; + unsigned int i; + unsigned char buf[TM6000_URB_MSG_LEN], img[720*2*480]; + unsigned int cmd, cpysize, pktsize, size, field, block, line, pos=0; + unsigned long header=0; + int linesize=720*2,skip=0; + struct v4l2_driver drv; + + argp_parse (&argp, argc, argv, 0, 0, 0); + + if (mode!=INPUT) { + if (prepare_read (&drv)<0) + return -1; + fd=drv.fd; + } else { + /*mode == INPUT */ + + fd=open(filename,O_RDONLY); + if (fd<0) { + perror ("error opening a file for parsing"); + return -1; + } + dprintf("file %s opened for parsing\n",filename); + use_mmap=0; + } + + if (mode==OUTPUT) { + fout=fopen(filename,"w"); + if (!fout) { + perror ("error opening a file to write"); + return -1; + } + dprintf("file %s opened for output\n",filename); + + do { + size=read_stream (&drv,fd); + + if (size<=0) { + close (fd); + return -1; + } + dprintf("writing %d bytes\n",size); + fwrite(outbuf,1, size,fout); +// fflush(fout); + } while (1); + } + + + while (1) { + skip=0; + header=0; + do { + int c; + c=read_char (&drv,fd); + if (c<0) { + perror("read"); + return -1; + } + + header=(header>>8)&0xffffff; + header=header|(c<<24); + skip++; + } while ( (((header>>24)&0xff) != 0x47) ); + + /* split the header fields */ + size = (((header & 0x7e)<<1) -1) * 4; + block = (header>>7) & 0xf; + field = (header>>11) & 0x1; + line = (header>>12) & 0x1ff; + cmd = (header>>21) & 0x7; + + /* Read the remaining buffer */ + for (i=0;i<sizeof(buf);i++) { + int c; + c=read_char (&drv,fd); + if (c<0) { + perror("read"); + return -1; + } + buf[i]=c; + } + + /* FIXME: Mounts the image as field0+field1 + * It should, instead, check if the user selected + * entrelaced or non-entrelaced mode + */ + pos=((line<<1)+field)*linesize+ + block*TM6000_URB_MSG_LEN; + + /* Prints debug info */ + dprintf("0x%08x (skip %d), %s size=%d, line=%d, field=%d, block=%d\n", + (unsigned int)header, skip, + tm6000_msg_type[cmd], + size, line, field, block); + + /* Don't allow to write out of the buffer */ + if (pos+sizeof(buf) > sizeof(img)) + cmd = TM6000_URB_MSG_ERR; + + /* handles each different URB message */ + switch(cmd) { + case TM6000_URB_MSG_VIDEO: + /* Fills video buffer */ + memcpy(buf,&img[pos],sizeof(buf)); + case TM6000_URB_MSG_AUDIO: + if (audio) + fwrite(buf,sizeof(buf),1,stdout); +// case TM6000_URB_MSG_VBI: +// case TM6000_URB_MSG_PTS: + break; + } + } + close(fd); + return 0; +} diff --git a/v4l2-apps/util/gen_keytables.pl b/v4l2-apps/util/gen_keytables.pl index 889516de4..fad4ccfeb 100755 --- a/v4l2-apps/util/gen_keytables.pl +++ b/v4l2-apps/util/gen_keytables.pl @@ -5,9 +5,8 @@ my $keyname=""; my $debug=0; while (<>) { -#IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE] = { - if (m/IR_KEYTAB_TYPE\s+(\w[\w\d_]+)/) { - $keyname = $1; + if (m/struct\s+(dvb_usb_rc_key|ir_scancode)\s+(\w[\w\d_]+)/) { + $keyname = $2; $keyname =~ s/^ir_codes_//; print "Generating keycodes/$keyname\n" if $debug; @@ -15,7 +14,7 @@ while (<>) { next; } if ($keyname ne "") { - if (m/(0x[\d\w]+).*(KEY_[^\s\,]+)/) { + if (m/(0x[\dA-Fa-f]+).*(KEY_[^\s\,\}]+)/) { printf OUT "%s %s\n",$1, $2; next; } diff --git a/v4l2-apps/util/keytable.c b/v4l2-apps/util/keytable.c index 3b922f12b..4283782d0 100644 --- a/v4l2-apps/util/keytable.c +++ b/v4l2-apps/util/keytable.c @@ -1,6 +1,6 @@ /* keytable.c - This program allows checking/replacing keys at IR - Copyright (C) 2006 Mauro Carvalho Chehab <mchehab@infradead.org> + Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@infradead.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ void prtcode (int *codes) for (p=keynames;p->name!=NULL;p++) { if (p->value == (unsigned)codes[1]) { - printf("scancode %d = %s (0x%02x)\n", codes[0], p->name, codes[1]); + printf("scancode 0x%04x = %s (0x%02x)\n", codes[0], p->name, codes[1]); return; } } @@ -55,7 +55,7 @@ int parse_code(char *string) int main (int argc, char *argv[]) { int fd; - unsigned int i; + unsigned int i, j; int codes[2]; if (argc<2 || argc>4) { @@ -104,10 +104,12 @@ int main (int argc, char *argv[]) } /* Clears old table */ - for (i=0;i<256;i++) { - codes[0] = i; - codes[1] = 0; - ioctl(fd, EVIOCSKEYCODE, codes); + for (j = 0; j < 256; j++) { + for (i = 0; i < 256; i++) { + codes[0] = (j << 8) | i; + codes[1] = KEY_RESERVED; + ioctl(fd, EVIOCSKEYCODE, codes); + } } while (fgets(s,sizeof(s),fin)) { @@ -116,14 +118,21 @@ int main (int argc, char *argv[]) perror ("parsing input file scancode"); return -1; } + if (!strcasecmp(scancode, "scancode")) { + scancode = strtok(NULL,"\n\t =:"); + if (!scancode) { + perror ("parsing input file scancode"); + return -1; + } + } - keycode=strtok(NULL,"\n\t "); + keycode=strtok(NULL,"\n\t =:("); if (!keycode) { perror ("parsing input file keycode"); return -1; } - // printf ("parsing %s=%s:",scancode,keycode); + // printf ("parsing %s=%s:", scancode, keycode); value=parse_code(keycode); // printf ("\tvalue=%d\n",value); @@ -136,8 +145,11 @@ int main (int argc, char *argv[]) codes [0] = (unsigned) strtol(scancode, NULL, 0); codes [1] = (unsigned) value; - if(ioctl(fd, EVIOCSKEYCODE, codes)) + // printf("\t%04x=%04x\n",codes[0], codes[1]); + if(ioctl(fd, EVIOCSKEYCODE, codes)) { + fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]); perror ("EVIOCSKEYCODE"); + } if(ioctl(fd, EVIOCGKEYCODE, codes)==0) prtcode(codes); @@ -146,12 +158,13 @@ int main (int argc, char *argv[]) } /* Get scancode table */ - for (i=0;i<256;i++) { - codes[0] = i; - if(ioctl(fd, EVIOCGKEYCODE, codes)==0) - prtcode(codes); + for (j = 0; j < 256; j++) { + for (i = 0; i < 256; i++) { + codes[0] = (j << 8) | i; + if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED) + prtcode(codes); + } } - return 0; } diff --git a/v4l2-apps/util/v4l2-ctl.cpp b/v4l2-apps/util/v4l2-ctl.cpp index 60ebc5474..5b38e37b3 100644 --- a/v4l2-apps/util/v4l2-ctl.cpp +++ b/v4l2-apps/util/v4l2-ctl.cpp @@ -105,6 +105,9 @@ enum Option { OptStreamOn, OptListStandards, OptListFormats, + OptListFormatsExt, + OptListFrameSizes, + OptListFrameIntervals, OptLogStatus, OptVerbose, OptSilent, @@ -148,20 +151,17 @@ static int verbose; static unsigned capabilities; -typedef std::vector<struct v4l2_ext_control> ctrl_list; -static ctrl_list user_ctrls; -static ctrl_list mpeg_ctrls; -static ctrl_list camera_ctrls; +typedef std::map<unsigned, std::vector<struct v4l2_ext_control> > class2ctrls_map; -typedef std::map<std::string, unsigned> ctrl_strmap; -static ctrl_strmap ctrl_str2id; +typedef std::map<std::string, struct v4l2_queryctrl> ctrl_qmap; +static ctrl_qmap ctrl_str2q; typedef std::map<unsigned, std::string> ctrl_idmap; static ctrl_idmap ctrl_id2str; typedef std::list<std::string> ctrl_get_list; static ctrl_get_list get_ctrls; -typedef std::map<std::string,std::string> ctrl_set_map; +typedef std::map<std::string, std::string> ctrl_set_map; static ctrl_set_map set_ctrls; typedef std::vector<std::string> dev_vec; @@ -224,6 +224,9 @@ static struct option long_options[] = { {"streamon", no_argument, 0, OptStreamOn}, {"list-standards", no_argument, 0, OptListStandards}, {"list-formats", no_argument, 0, OptListFormats}, + {"list-formats-ext", no_argument, 0, OptListFormatsExt}, + {"list-framesizes", required_argument, 0, OptListFrameSizes}, + {"list-frameintervals", required_argument, 0, OptListFrameIntervals}, {"get-standard", no_argument, 0, OptGetStandard}, {"set-standard", required_argument, 0, OptSetStandard}, {"get-parm", no_argument, 0, OptGetParm}, @@ -322,6 +325,18 @@ static void usage(void) " set the audio mode of the tuner [VIDIOC_S_TUNER]\n" " Possible values: mono, stereo, lang2, lang1, bilingual\n" " --list-formats display supported video formats [VIDIOC_ENUM_FMT]\n" + " --list-formats-ext display supported video formats including frame sizes\n" + " and intervals\n" + " --list-framesizes=<f>\n" + " list supported framesizes for pixelformat <f>\n" + " [VIDIOC_ENUM_FRAMESIZES]\n" + " pixelformat is either the format index as reported by\n" + " --list-formats, or the fourcc value as a string\n" + " --list-frameintervals=width=<w>,height=<h>,pixelformat=<f>\n" + " list supported frame intervals for pixelformat <f> and\n" + " the given width and height [VIDIOC_ENUM_FRAMEINTERVALS]\n" + " pixelformat is either the format index as reported by\n" + " --list-formats, or the fourcc value as a string\n" " -V, --get-fmt-video\n" " query the video capture format [VIDIOC_G_FMT]\n" " -v, --set-fmt-video=width=<w>,height=<h>,pixelformat=<f>\n" @@ -425,7 +440,9 @@ static void usage(void) " set the sub-carrier modulation [VIDIOC_S_MODULATOR]\n" " <txsubchans> is one of:\n" " mono: Modulate as mono\n" + " mono-rds: Modulate as mono with RDS (radio only)\n" " stereo: Modulate as stereo\n" + " stereo-rds: Modulate as stereo with RDS (radio only)\n" " bilingual: Modulate as bilingual\n" " mono-sap: Modulate as mono with Second Audio Program\n" " stereo-sap: Modulate as stereo with Second Audio Program\n" @@ -581,6 +598,43 @@ static std::string name2var(unsigned char *name) return s; } +static std::string safename(const unsigned char *name) +{ + std::string s; + + while (*name) { + if (*name == '\n') { + s += "\\n"; + } + else if (*name == '\r') { + s += "\\r"; + } + else if (*name == '\f') { + s += "\\f"; + } + else if (*name == '\\') { + s += "\\\\"; + } + else if ((*name & 0x7f) < 0x20) { + char buf[3]; + + sprintf(buf, "%02x", *name); + s += "\\x"; + s += buf; + } + else { + s += *name; + } + name++; + } + return s; +} + +static std::string safename(const char *name) +{ + return safename((const unsigned char *)name); +} + static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl, struct v4l2_ext_control *ctrl, int show_menus) { @@ -600,6 +654,12 @@ static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl, case V4L2_CTRL_TYPE_INTEGER64: printf("%31s (int64): value=%lld", s.c_str(), ctrl->value64); break; + case V4L2_CTRL_TYPE_STRING: + printf("%31s (str) : min=%d max=%d step=%d value='%s'", + s.c_str(), + queryctrl->minimum, queryctrl->maximum, + queryctrl->step, safename(ctrl->string).c_str()); + break; case V4L2_CTRL_TYPE_BOOLEAN: printf("%31s (bool) : default=%d value=%d", s.c_str(), @@ -657,6 +717,11 @@ static int print_control(int fd, struct v4l2_queryctrl &qctrl, int show_menus) ctrls.controls = &ext_ctrl; if (V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_USER && qctrl.id < V4L2_CID_PRIVATE_BASE) { + if (qctrl.type == V4L2_CTRL_TYPE_STRING) { + ext_ctrl.size = qctrl.maximum + 1; + ext_ctrl.string = (char *)malloc(ext_ctrl.size); + ext_ctrl.string[0] = 0; + } if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls)) { printf("error %d getting ext_ctrl %s\n", errno, qctrl.name); @@ -673,6 +738,8 @@ static int print_control(int fd, struct v4l2_queryctrl &qctrl, int show_menus) ext_ctrl.value = ctrl.value; } print_qctrl(fd, &qctrl, &ext_ctrl, show_menus); + if (qctrl.type == V4L2_CTRL_TYPE_STRING) + free(ext_ctrl.string); return 1; } @@ -706,7 +773,7 @@ static void find_controls(int fd) while (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { - ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; @@ -717,14 +784,14 @@ static void find_controls(int fd) qctrl.id = id; if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0 && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { - ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } for (qctrl.id = V4L2_CID_PRIVATE_BASE; ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { - ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } @@ -902,6 +969,72 @@ static void printfmt(const struct v4l2_format &vfmt) } } +static std::string frmtype2s(unsigned type) +{ + static const char *types[] = { + "Unknown", + "Discrete", + "Continuous", + "Stepwise" + }; + + if (type > 3) + type = 0; + return types[type]; +} + +static std::string fract2sec(const struct v4l2_fract &f) +{ + char buf[100]; + + sprintf(buf, "%.3f s", (1.0 * f.numerator) / f.denominator); + return buf; +} + +static std::string fract2fps(const struct v4l2_fract &f) +{ + char buf[100]; + + sprintf(buf, "%.3f fps", (1.0 * f.denominator) / f.numerator); + return buf; +} + +static void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix) +{ + printf("%s\tSize: %s ", prefix, frmtype2s(frmsize.type).c_str()); + if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) { + printf("%dx%d", frmsize.discrete.width, frmsize.discrete.height); + } else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) { + printf("%dx%d - %dx%d with step %d/%d", + frmsize.stepwise.min_width, + frmsize.stepwise.min_height, + frmsize.stepwise.max_width, + frmsize.stepwise.max_height, + frmsize.stepwise.step_width, + frmsize.stepwise.step_height); + } + printf("\n"); +} + +static void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix) +{ + printf("%s\tInterval: %s ", prefix, frmtype2s(frmival.type).c_str()); + if (frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) { + printf("%s (%s)\n", fract2sec(frmival.discrete).c_str(), + fract2fps(frmival.discrete).c_str()); + } else if (frmival.type == V4L2_FRMIVAL_TYPE_STEPWISE) { + printf("%s - %s with step %s\n", + fract2sec(frmival.stepwise.min).c_str(), + fract2sec(frmival.stepwise.max).c_str(), + fract2sec(frmival.stepwise.step).c_str()); + printf("%s\t : ", prefix); + printf("(%s - %s with step %s)\n", + fract2fps(frmival.stepwise.min).c_str(), + fract2fps(frmival.stepwise.max).c_str(), + fract2fps(frmival.stepwise.step).c_str()); + } +} + static void print_video_formats(int fd, enum v4l2_buf_type type) { struct v4l2_fmtdesc fmt; @@ -921,6 +1054,43 @@ static void print_video_formats(int fd, enum v4l2_buf_type type) } } +static void print_video_formats_ext(int fd, enum v4l2_buf_type type) +{ + struct v4l2_fmtdesc fmt; + struct v4l2_frmsizeenum frmsize; + struct v4l2_frmivalenum frmival; + + fmt.index = 0; + fmt.type = type; + while (ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) { + printf("\tIndex : %d\n", fmt.index); + printf("\tType : %s\n", buftype2s(type).c_str()); + printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str()); + if (fmt.flags) + printf(" (compressed)"); + printf("\n"); + printf("\tName : %s\n", fmt.description); + frmsize.pixel_format = fmt.pixelformat; + frmsize.index = 0; + while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) { + print_frmsize(frmsize, "\t"); + if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) { + frmival.index = 0; + frmival.pixel_format = fmt.pixelformat; + frmival.width = frmsize.discrete.width; + frmival.height = frmsize.discrete.height; + while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) >= 0) { + print_frmival(frmival, "\t\t"); + frmival.index++; + } + } + frmsize.index++; + } + printf("\n"); + fmt.index++; + } +} + static char *pts_to_string(char *str, unsigned long pts) { static char buf[256]; @@ -988,6 +1158,8 @@ static std::string txsubchans2s(int txsubchans) s += "bilingual"; if (txsubchans & V4L2_TUNER_SUB_SAP) s += "+sap"; + if (txsubchans & V4L2_TUNER_SUB_RDS) + s += "+rds"; return s; } @@ -1390,6 +1562,17 @@ static enum v4l2_field parse_field(const char *s) return V4L2_FIELD_ANY; } +static __u32 find_pixel_format(int fd, unsigned index) +{ + struct v4l2_fmtdesc fmt; + + fmt.index = index; + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt, "VIDIOC_ENUM_FMT")) + return 0; + return fmt.pixelformat; +} + int main(int argc, char **argv) { char *value, *subs; @@ -1421,12 +1604,15 @@ int main(int argc, char **argv) struct v4l2_format raw_fmt_out; /* set_format/get_format for VBI output */ struct v4l2_format overlay_fmt; /* set_format/get_format video overlay */ struct v4l2_format overlay_fmt_out; /* set_format/get_format video overlay output */ - struct v4l2_tuner tuner; /* set_tuner/get_tuner */ + struct v4l2_tuner tuner; /* set_freq/get_freq */ + struct v4l2_modulator modulator;/* set_freq/get_freq */ struct v4l2_capability vcap; /* list_cap */ struct v4l2_input vin; /* list_inputs */ struct v4l2_output vout; /* list_outputs */ struct v4l2_audio vaudio; /* list audio inputs */ struct v4l2_audioout vaudout; /* audio outputs */ + struct v4l2_frmsizeenum frmsize;/* list frame sizes */ + struct v4l2_frmivalenum frmival;/* list frame intervals */ struct v4l2_rect vcrop; /* crop rect */ struct v4l2_rect vcrop_out; /* crop rect */ struct v4l2_rect vcrop_overlay; /* crop rect */ @@ -1459,11 +1645,14 @@ int main(int argc, char **argv) memset(&overlay_fmt_out, 0, sizeof(overlay_fmt_out)); memset(&raw_fmt_out, 0, sizeof(raw_fmt_out)); memset(&tuner, 0, sizeof(tuner)); + memset(&modulator, 0, sizeof(modulator)); memset(&vcap, 0, sizeof(vcap)); memset(&vin, 0, sizeof(vin)); memset(&vout, 0, sizeof(vout)); memset(&vaudio, 0, sizeof(vaudio)); memset(&vaudout, 0, sizeof(vaudout)); + memset(&frmsize, 0, sizeof(frmsize)); + memset(&frmival, 0, sizeof(frmival)); memset(&vcrop, 0, sizeof(vcrop)); memset(&vcrop_out, 0, sizeof(vcrop_out)); memset(&vcrop_overlay, 0, sizeof(vcrop_overlay)); @@ -1657,6 +1846,41 @@ int main(int argc, char **argv) case OptOverlay: overlay = strtol(optarg, 0L, 0); break; + case OptListFrameSizes: + if (strlen(optarg) == 4) + frmsize.pixel_format = v4l2_fourcc(optarg[0], optarg[1], + optarg[2], optarg[3]); + else + frmsize.pixel_format = strtol(optarg, 0L, 0); + break; + case OptListFrameIntervals: + subs = optarg; + while (*subs != '\0') { + static const char *const subopts[] = { + "width", + "height", + "pixelformat", + NULL + }; + + switch (parse_subopt(&subs, subopts, &value)) { + case 0: + frmival.width = strtol(value, 0L, 0); + break; + case 1: + frmival.height = strtol(value, 0L, 0); + break; + case 2: + if (strlen(value) == 4) + frmival.pixel_format = + v4l2_fourcc(value[0], value[1], + value[2], value[3]); + else + frmival.pixel_format = strtol(value, 0L, 0); + break; + } + } + break; case OptSetCrop: parse_crop(optarg, set_crop, vcrop); break; @@ -1768,6 +1992,10 @@ int main(int argc, char **argv) txsubchans = V4L2_TUNER_SUB_MONO; else if (!strcmp(optarg, "mono-sap")) txsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_SAP; + else if (!strcmp(optarg, "stereo-rds")) + txsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_RDS; + else if (!strcmp(optarg, "mono-rds")) + txsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_RDS; else { fprintf(stderr, "Unknown txsubchans value\n"); usage(); @@ -1916,13 +2144,13 @@ int main(int argc, char **argv) capabilities = vcap.capabilities; find_controls(fd); for (ctrl_get_list::iterator iter = get_ctrls.begin(); iter != get_ctrls.end(); ++iter) { - if (ctrl_str2id.find(*iter) == ctrl_str2id.end()) { + if (ctrl_str2q.find(*iter) == ctrl_str2q.end()) { fprintf(stderr, "unknown control '%s'\n", (*iter).c_str()); exit(1); } } for (ctrl_set_map::iterator iter = set_ctrls.begin(); iter != set_ctrls.end(); ++iter) { - if (ctrl_str2id.find(iter->first) == ctrl_str2id.end()) { + if (ctrl_str2q.find(iter->first) == ctrl_str2q.end()) { fprintf(stderr, "unknown control '%s'\n", iter->first.c_str()); exit(1); } @@ -1978,11 +2206,17 @@ int main(int argc, char **argv) if (options[OptSetFreq]) { double fac = 16; - if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { - fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + if (capabilities & V4L2_CAP_MODULATOR) { + if (doioctl(fd, VIDIOC_G_MODULATOR, &modulator, "VIDIOC_G_MODULATOR") == 0) + fac = (modulator.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + } else { + vf.type = V4L2_TUNER_ANALOG_TV; + if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { + fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + vf.type = tuner.type; + } } vf.tuner = 0; - vf.type = tuner.type; vf.frequency = __u32(freq * fac); if (doioctl(fd, VIDIOC_S_FREQUENCY, &vf, "VIDIOC_S_FREQUENCY") == 0) @@ -2095,13 +2329,8 @@ int main(int argc, char **argv) if (set_fmts & FmtPixelFormat) { in_vfmt.fmt.pix.pixelformat = vfmt.fmt.pix.pixelformat; if (in_vfmt.fmt.pix.pixelformat < 256) { - struct v4l2_fmtdesc fmt; - - fmt.index = in_vfmt.fmt.pix.pixelformat; - fmt.type = in_vfmt.type; - if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt, "VIDIOC_ENUM_FMT")) - goto set_vid_fmt_error; - in_vfmt.fmt.pix.pixelformat = fmt.pixelformat; + in_vfmt.fmt.pix.pixelformat = + find_pixel_format(fd, in_vfmt.fmt.pix.pixelformat); } } if (options[OptSetVideoFormat]) @@ -2245,60 +2474,61 @@ set_vid_fmt_error: if (options[OptSetCtrl] && !set_ctrls.empty()) { struct v4l2_ext_controls ctrls = { 0 }; + class2ctrls_map class2ctrls; for (ctrl_set_map::iterator iter = set_ctrls.begin(); iter != set_ctrls.end(); ++iter) { struct v4l2_ext_control ctrl = { 0 }; - ctrl.id = ctrl_str2id[iter->first]; - ctrl.value = strtol(iter->second.c_str(), NULL, 0); - if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_MPEG) - mpeg_ctrls.push_back(ctrl); - else if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_CAMERA) - camera_ctrls.push_back(ctrl); - else - user_ctrls.push_back(ctrl); - } - for (unsigned i = 0; i < user_ctrls.size(); i++) { - struct v4l2_control ctrl; - - ctrl.id = user_ctrls[i].id; - ctrl.value = user_ctrls[i].value; - if (doioctl(fd, VIDIOC_S_CTRL, &ctrl, "VIDIOC_S_CTRL")) { - fprintf(stderr, "%s: %s\n", - ctrl_id2str[ctrl.id].c_str(), - strerror(errno)); - } - } - if (mpeg_ctrls.size()) { - ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; - ctrls.count = mpeg_ctrls.size(); - ctrls.controls = &mpeg_ctrls[0]; - if (doioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls, "VIDIOC_S_EXT_CTRLS")) { - if (ctrls.error_idx >= ctrls.count) { - fprintf(stderr, "Error setting MPEG controls: %s\n", - strerror(errno)); + ctrl.id = ctrl_str2q[iter->first].id; + if (ctrl_str2q[iter->first].type == V4L2_CTRL_TYPE_STRING) { + unsigned len = iter->second.length(); + unsigned maxlen = ctrl_str2q[iter->first].maximum; + + ctrl.size = maxlen + 1; + ctrl.string = (char *)malloc(ctrl.size); + if (len > maxlen) { + memcpy(ctrl.string, iter->second.c_str(), maxlen); + ctrl.string[maxlen] = 0; } else { - fprintf(stderr, "%s: %s\n", - ctrl_id2str[mpeg_ctrls[ctrls.error_idx].id].c_str(), - strerror(errno)); + strcpy(ctrl.string, iter->second.c_str()); } + } else { + ctrl.value = strtol(iter->second.c_str(), NULL, 0); } + class2ctrls[V4L2_CTRL_ID2CLASS(ctrl.id)].push_back(ctrl); } - if (camera_ctrls.size()) { - ctrls.ctrl_class = V4L2_CTRL_CLASS_CAMERA; - ctrls.count = camera_ctrls.size(); - ctrls.controls = &camera_ctrls[0]; - if (doioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls, "VIDIOC_S_EXT_CTRLS")) { - if (ctrls.error_idx >= ctrls.count) { - fprintf(stderr, "Error setting CAMERA controls: %s\n", - strerror(errno)); + for (class2ctrls_map::iterator iter = class2ctrls.begin(); + iter != class2ctrls.end(); ++iter) { + if (iter->first == V4L2_CTRL_CLASS_USER) { + for (unsigned i = 0; i < iter->second.size(); i++) { + struct v4l2_control ctrl; + + ctrl.id = iter->second[i].id; + ctrl.value = iter->second[i].value; + if (doioctl(fd, VIDIOC_S_CTRL, &ctrl, "VIDIOC_S_CTRL")) { + fprintf(stderr, "%s: %s\n", + ctrl_id2str[ctrl.id].c_str(), + strerror(errno)); + } } - else { - fprintf(stderr, "%s: %s\n", - ctrl_id2str[camera_ctrls[ctrls.error_idx].id].c_str(), - strerror(errno)); + continue; + } + if (iter->second.size()) { + ctrls.ctrl_class = iter->first; + ctrls.count = iter->second.size(); + ctrls.controls = &iter->second[0]; + if (doioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls, "VIDIOC_S_EXT_CTRLS")) { + if (ctrls.error_idx >= ctrls.count) { + fprintf(stderr, "Error setting MPEG controls: %s\n", + strerror(errno)); + } + else { + fprintf(stderr, "%s: %s\n", + ctrl_id2str[iter->second[ctrls.error_idx].id].c_str(), + strerror(errno)); + } } } } @@ -2468,6 +2698,16 @@ set_vid_fmt_error: if (options[OptGetFreq]) { double fac = 16; + if (capabilities & V4L2_CAP_MODULATOR) { + if (doioctl(fd, VIDIOC_G_MODULATOR, &modulator, "VIDIOC_G_MODULATOR") == 0) + fac = (modulator.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + } else { + vf.type = V4L2_TUNER_ANALOG_TV; + if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { + fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + vf.type = tuner.type; + } + } if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; } @@ -2559,49 +2799,46 @@ set_vid_fmt_error: if (options[OptGetCtrl] && !get_ctrls.empty()) { struct v4l2_ext_controls ctrls = { 0 }; + class2ctrls_map class2ctrls; - mpeg_ctrls.clear(); - camera_ctrls.clear(); - user_ctrls.clear(); for (ctrl_get_list::iterator iter = get_ctrls.begin(); iter != get_ctrls.end(); ++iter) { struct v4l2_ext_control ctrl = { 0 }; - ctrl.id = ctrl_str2id[*iter]; - if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_MPEG) - mpeg_ctrls.push_back(ctrl); - else if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_CAMERA) - camera_ctrls.push_back(ctrl); - else - user_ctrls.push_back(ctrl); - } - for (unsigned i = 0; i < user_ctrls.size(); i++) { - struct v4l2_control ctrl; - - ctrl.id = user_ctrls[i].id; - doioctl(fd, VIDIOC_G_CTRL, &ctrl, "VIDIOC_G_CTRL"); - printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); - } - if (mpeg_ctrls.size()) { - ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; - ctrls.count = mpeg_ctrls.size(); - ctrls.controls = &mpeg_ctrls[0]; - doioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls, "VIDIOC_G_EXT_CTRLS"); - for (unsigned i = 0; i < mpeg_ctrls.size(); i++) { - struct v4l2_ext_control ctrl = mpeg_ctrls[i]; - - printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + ctrl.id = ctrl_str2q[*iter].id; + if (ctrl_str2q[*iter].type == V4L2_CTRL_TYPE_STRING) { + ctrl.size = ctrl_str2q[*iter].maximum + 1; + ctrl.string = (char *)malloc(ctrl.size); + ctrl.string[0] = 0; } + class2ctrls[V4L2_CTRL_ID2CLASS(ctrl.id)].push_back(ctrl); } - if (camera_ctrls.size()) { - ctrls.ctrl_class = V4L2_CTRL_CLASS_CAMERA; - ctrls.count = camera_ctrls.size(); - ctrls.controls = &camera_ctrls[0]; - doioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls, "VIDIOC_G_EXT_CTRLS"); - for (unsigned i = 0; i < camera_ctrls.size(); i++) { - struct v4l2_ext_control ctrl = camera_ctrls[i]; - - printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + for (class2ctrls_map::iterator iter = class2ctrls.begin(); + iter != class2ctrls.end(); ++iter) { + if (iter->first == V4L2_CTRL_CLASS_USER) { + for (unsigned i = 0; i < iter->second.size(); i++) { + struct v4l2_control ctrl; + + ctrl.id = iter->second[i].id; + doioctl(fd, VIDIOC_G_CTRL, &ctrl, "VIDIOC_G_CTRL"); + printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + } + continue; + } + if (iter->second.size()) { + ctrls.ctrl_class = iter->first; + ctrls.count = iter->second.size(); + ctrls.controls = &iter->second[0]; + doioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls, "VIDIOC_G_EXT_CTRLS"); + for (unsigned i = 0; i < iter->second.size(); i++) { + struct v4l2_ext_control ctrl = iter->second[i]; + + if (ctrl_str2q[ctrl_id2str[ctrl.id]].type == V4L2_CTRL_TYPE_STRING) + printf("%s: '%s'\n", ctrl_id2str[ctrl.id].c_str(), + safename(ctrl.string).c_str()); + else + printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + } } } } @@ -2771,6 +3008,35 @@ set_vid_fmt_error: print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY); } + if (options[OptListFormatsExt]) { + printf("ioctl: VIDIOC_ENUM_FMT\n"); + print_video_formats_ext(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE); + print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT); + print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY); + } + + if (options[OptListFrameSizes]) { + printf("ioctl: VIDIOC_ENUM_FRAMESIZES\n"); + if (frmsize.pixel_format < 256) + frmsize.pixel_format = find_pixel_format(fd, frmsize.pixel_format); + frmsize.index = 0; + while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) { + print_frmsize(frmsize, ""); + frmsize.index++; + } + } + + if (options[OptListFrameIntervals]) { + printf("ioctl: VIDIOC_ENUM_FRAMEINTERVALS\n"); + if (frmival.pixel_format < 256) + frmival.pixel_format = find_pixel_format(fd, frmival.pixel_format); + frmival.index = 0; + while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) >= 0) { + print_frmival(frmival, ""); + frmival.index++; + } + } + if (options[OptGetSlicedVbiCap]) { struct v4l2_sliced_vbi_cap cap; diff --git a/v4l2-apps/util/v4l2-sysfs-path.c b/v4l2-apps/util/v4l2-sysfs-path.c index e3f3e63e8..4f0817017 100644 --- a/v4l2-apps/util/v4l2-sysfs-path.c +++ b/v4l2-apps/util/v4l2-sysfs-path.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <string.h> #include <dirent.h> +#include <sys/stat.h> #define USB_ID "usb-" #define PCI_ID "PCI:" @@ -135,6 +136,131 @@ err: return NULL; } +char *seek_name(char *path, char *match) +{ + DIR *dir; + struct dirent *entry; + struct stat st; + char *p; + static char name[1024]; + int major, minor; + + dir = opendir(path); + if (!dir) + return NULL; + + strcpy(name, path); + strcat(name, "/"); + p = name + strlen(name); + + entry = readdir(dir); + while (entry) { + if (!strncmp(entry->d_name, match, strlen(match))) { + + strcpy(name, entry->d_name); + closedir(dir); + return name; + } + entry = readdir(dir); + } + closedir(dir); + return NULL; +} + +int get_dev(char *class, int *major, int *minor, char *extra) +{ + char path[1024]; + char *name; + FILE *fp; + + name = strchr(class,':'); + if (!name) + return -1; + *name = 0; + name++; + + *extra = 0; + + if (!strcmp(class, "input")) { + char *event; + + sprintf(path, "/sys/class/%s/%s/", class, name); + event = seek_name(path, "event"); + if (!event) + return -1; + + strcpy(extra, event); + + sprintf(path, "/sys/class/%s/%s/%s/dev", class, name, event); + + } else + sprintf(path, "/sys/class/%s/%s/dev", class, name); + + fp = fopen(path, "r"); + if (!fp) + return -1; + + fscanf(fp, "%d:%d", major, minor); + + return 0; +} + +/* + Examples of subdevs: + sound:audio1 + sound:controlC1 + sound:dsp1 + sound:mixer1 + sound:pcmC1D0c + dvb:dvb0.demux0 + dvb:dvb0.dvr0 + dvb:dvb0.frontend0 + dvb:dvb0.net0 + i2c-adapter:i2c-4 + input:input8 +*/ + +void get_subdevs(char *path) +{ + DIR *dir; + struct dirent *entry; + struct stat st; + char *p, name[1024], extra[20]; + int major, minor; + + dir = opendir(path); + if (!dir) + return; + + strcpy(name, path); + strcat(name, "/"); + p = name + strlen(name); + + printf("Associated devices:\n"); + entry = readdir(dir); + while (entry) { + strcpy(p, entry->d_name); + if ((lstat(name, &st) == 0) && + !S_ISDIR(st.st_mode)) { + char *s = strchr(entry->d_name, ':'); + if (s) { + printf("\t%s", entry->d_name); + if (!get_dev(entry->d_name, &major, &minor, extra)) { + if (*extra) + printf(":%s (dev %d,%d)", + extra, major, minor); + else + printf(" (dev %d,%d)", + major, minor); + } + printf("\n"); + } + } + entry = readdir(dir); + } + closedir(dir); +} + void get_sysfs(char *fname) { struct v4l2_driver drv; @@ -148,9 +274,11 @@ void get_sysfs(char *fname) printf("bus info = %s\n", drv.cap.bus_info); path = obtain_bus_sysfs_path((char *)drv.cap.bus_info); if (path) { - printf("sysfs path = %s\n\n", path); + printf("sysfs path = %s\n", path); + get_subdevs(path); free(path); } + printf("\n"); v4l2_close(&drv); } diff --git a/v4l2-apps/util/xc3028-firmware/firmware-tool.c b/v4l2-apps/util/xc3028-firmware/firmware-tool.c index de1262ceb..43b78df7e 100644 --- a/v4l2-apps/util/xc3028-firmware/firmware-tool.c +++ b/v4l2-apps/util/xc3028-firmware/firmware-tool.c @@ -33,8 +33,8 @@ #include <asm/byteorder.h> #include <asm/types.h> -#include "../../../linux/drivers/media/video/tuner-xc2028-types.h" -#include "../../../linux/include/linux/videodev2.h" +#include "../../../linux/drivers/media/common/tuners/tuner-xc2028-types.h" +#include "linux/videodev2.h" #include "extract_head.h" #include "standards.h" |