[mythtv] patch for myth_videodev

Daniel Thor Kristjansson danielk at cat.nyu.edu
Wed Feb 18 17:43:10 EST 2004


This patch syncs up with bttv 0.9.12 and adds the couple things needed
to support the pchdtv signal strength call. The only things that could
cause some problems are the signal changes in the bttv 0.9.12
videodev2.h. The only one we use is VIDIOC_S_CTRL, and that doesn't seem
to have been a problem for anyone that has tried this patch.

myth_videodev.h
(for bttv 0.9.12 sync)
 * Adds LINUX_VERSION_CODE ifdefs so you could have a correct view of
   the video_device struct for different kernels. The current version
   assumes you have 2.6.x kernel. It's best never to use this structure
   directly though, as it would create incompatible binaries.
 * Marks obsolete variables and calls that will be removed in 2.7.x
 * Moves video_register_device to be consistent with bttv 0.9.12
 * defines video_device_create_file/video_device_remove_file functions
   for 2.5.x & 2.6.x kernels, also from bttv 0.9.12
 * Adds three cameras VID_HARDWARE_VICAM, VID_HARDWARE_SF16FMR2,
   VID_HARDWARE_W9968CF to hardware defines to sync wioth bttv 0.9.12
(for pchdtv consistency)
 * adds VIDEO_RF_AUX_INPUT define from pchdtv, this is for selecting the
   auxiliary input on the HD-2000 card.
 * adds comment from pchdtv to VIDEO_MODE_ATSC define
 * adds dtv to video unit
 * adds video_signal structure
 * adds VIDIOCGSIGNAL as a read only call (#30)

myth_videodev2.h (everything in this file is a bttv 0.9.12 sync)
 * Put linux/time.h in a __KERNEL__ only ifdef, we will never need this
   included, but it keeps us in sync with bttv 0.9.12
 * Adds v4l2_priority structure, bttv 0.9.12
 * Syncs comment on v4l2_capability, you should now use the pci_name
   macro and not use the pci_dev structure directly to get the slot_name
 * Syncs comment on V4L2_CAP_TUNER with bttv 0.9.12, case
 * Adds V4L2_CAP_RADIO define for radio capable cards.
 * Syncs comment on V4L2_PIX_FMT_WNVA, spelling
 * Adds bttv 0.9.12 MPEG comment to v4l2_compression structure
 * Changes signals
 VIDIOC_OVERLAY  _IOWR -> _IOW
 VIDIOC_S_PARM   _IOW  -> _IOWR
 VIDIOC_S_CTRL   _IOW  -> _IOWR
 VIDIOC_G_AUDIO  _IOWR -> _IOR
 VIDIOC_G_AUDOUT _IOWR -> _IOR
 * Adds signals for backward compatibility
 VIDIOC_OVERLAY_OLD
 VIDIOC_S_PARM_OLD
 VIDIOC_S_CTRL_OLD
 VIDIOC_G_AUDIO_OLD
 VIDIOC_G_AUDOUT_OLD
 * Also adds signals (from bttv 0.9.12)
 VIDIOC_ENUMAUDIO
 VIDIOC_ENUMAUDOUT
 VIDIOC_G_PRIORITY
 VIDIOC_S_PRIORITY
 (within a __KERNEL__ ifdef, it also..)
 * Adds priority handling function definitions
 * Moves Compatibility layer interface functions to sync with bttv


-- 
-- Daniel
  << When truth is outlawed; only outlaws will tell the truth. >> - RLiegh
-------------- next part --------------
Index: libs/libmythtv/videodev2_myth.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videodev2_myth.h,v
retrieving revision 1.2
diff -u -r1.2 videodev2_myth.h
--- libs/libmythtv/videodev2_myth.h	10 Sep 2003 21:44:13 -0000	1.2
+++ libs/libmythtv/videodev2_myth.h	18 Feb 2004 20:04:35 -0000
@@ -13,8 +13,9 @@
  *		Justin Schoeman
  *		et al.
  */
-/* #include <linux/time.h>  */ /* need struct timeval */
-/* #include <asm/types.h>   */
+#ifdef __KERNEL__
+#include <linux/time.h> /* need struct timeval */
+#endif
 
 /*
  *	M I S C E L L A N E O U S
@@ -112,6 +113,14 @@
 	V4L2_COLORSPACE_SRGB          = 8,
 };
 
+enum v4l2_priority {
+	V4L2_PRIORITY_UNSET       = 0,  /* not initialized */
+	V4L2_PRIORITY_BACKGROUND  = 1,
+	V4L2_PRIORITY_INTERACTIVE = 2,
+	V4L2_PRIORITY_RECORD      = 3,
+	V4L2_PRIORITY_DEFAULT     = V4L2_PRIORITY_INTERACTIVE,
+};
+
 struct v4l2_rect {
 	__s32   left;
 	__s32   top;
@@ -131,7 +140,7 @@
 {
 	__u8	driver[16];	/* i.e. "bttv" */
 	__u8	card[32];	/* i.e. "Hauppauge WinTV" */
-	__u8	bus_info[32];	/* "PCI:" + pci_dev->slot_name */
+	__u8	bus_info[32];	/* "PCI:" + pci_name(pci_dev) */
 	__u32   version;        /* should use KERNEL_VERSION() */
 	__u32	capabilities;	/* Device capabilities */
 	__u32	reserved[4];
@@ -145,8 +154,9 @@
 #define V4L2_CAP_VBI_OUTPUT	0x00000020  /* Is a VBI output device */
 #define V4L2_CAP_RDS_CAPTURE	0x00000100  /* RDS data capture */
 
-#define V4L2_CAP_TUNER		0x00010000  /* Has a tuner */
+#define V4L2_CAP_TUNER		0x00010000  /* has a tuner */
 #define V4L2_CAP_AUDIO		0x00020000  /* has audio support */
+#define V4L2_CAP_RADIO		0x00040000  /* is a radio device */
 
 #define V4L2_CAP_READWRITE      0x01000000  /* read/write systemcalls */
 #define V4L2_CAP_ASYNCIO        0x02000000  /* async I/O */
@@ -204,7 +214,7 @@
 #define V4L2_PIX_FMT_MPEG     v4l2_fourcc('M','P','E','G') /* MPEG          */
 
 /*  Vendor-specific formats   */
-#define V4L2_PIX_FMT_WNVA    v4l2_fourcc('W','N','V','A') /* Winnov hw compres */
+#define V4L2_PIX_FMT_WNVA     v4l2_fourcc('W','N','V','A') /* Winnov hw compress */
 
 /*
  *	F O R M A T   E N U M E R A T I O N
@@ -265,6 +275,51 @@
 	__u32	keyframerate;
 	__u32	pframerate;
 	__u32	reserved[5];
+
+/*  what we'll need for MPEG, extracted from some postings on
+    the v4l list (Gert Vervoort, PlasmaJohn).
+
+system stream:
+  - type: elementary stream(ES), packatised elementary stream(s) (PES)
+    program stream(PS), transport stream(TS)
+  - system bitrate
+  - PS packet size (DVD: 2048 bytes, VCD: 2324 bytes)
+  - TS video PID
+  - TS audio PID
+  - TS PCR PID
+  - TS system information tables (PAT, PMT, CAT, NIT and SIT)
+  - (MPEG-1 systems stream vs. MPEG-2 program stream (TS not supported
+    by MPEG-1 systems)
+
+audio:
+  - type: MPEG (+Layer I,II,III), AC-3, LPCM
+  - bitrate
+  - sampling frequency (DVD: 48 Khz, VCD: 44.1 KHz, 32 kHz)
+  - Trick Modes? (ff, rew)
+  - Copyright
+  - Inverse Telecine
+
+video:
+  - picturesize (SIF, 1/2 D1, 2/3 D1, D1) and PAL/NTSC norm can be set
+    through excisting V4L2 controls
+  - noise reduction, parameters encoder specific?
+  - MPEG video version: MPEG-1, MPEG-2
+  - GOP (Group Of Pictures) definition:
+    - N: number of frames per GOP
+    - M: distance between reference (I,P) frames
+    - open/closed GOP
+  - quantiser matrix: inter Q matrix (64 bytes) and intra Q matrix (64 bytes)
+  - quantiser scale: linear or logarithmic
+  - scanning: alternate or zigzag
+  - bitrate mode: CBR (constant bitrate) or VBR (variable bitrate).
+  - target video bitrate for CBR
+  - target video bitrate for VBR
+  - maximum video bitrate for VBR - min. quantiser value for VBR
+  - max. quantiser value for VBR
+  - adaptive quantisation value
+  - return the number of bytes per GOP or bitrate for bitrate monitoring
+
+*/
 };
 #endif
 
@@ -784,22 +839,22 @@
 #define VIDIOC_QUERYBUF		_IOWR ('V',  9, struct v4l2_buffer)
 #define VIDIOC_G_FBUF		_IOR  ('V', 10, struct v4l2_framebuffer)
 #define VIDIOC_S_FBUF		_IOW  ('V', 11, struct v4l2_framebuffer)
-#define VIDIOC_OVERLAY		_IOWR ('V', 14, int)
+#define VIDIOC_OVERLAY		_IOW  ('V', 14, int)
 #define VIDIOC_QBUF		_IOWR ('V', 15, struct v4l2_buffer)
 #define VIDIOC_DQBUF		_IOWR ('V', 17, struct v4l2_buffer)
 #define VIDIOC_STREAMON		_IOW  ('V', 18, int)
 #define VIDIOC_STREAMOFF	_IOW  ('V', 19, int)
 #define VIDIOC_G_PARM		_IOWR ('V', 21, struct v4l2_streamparm)
-#define VIDIOC_S_PARM		_IOW  ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_S_PARM		_IOWR ('V', 22, struct v4l2_streamparm)
 #define VIDIOC_G_STD		_IOR  ('V', 23, v4l2_std_id)
 #define VIDIOC_S_STD		_IOW  ('V', 24, v4l2_std_id)
 #define VIDIOC_ENUMSTD		_IOWR ('V', 25, struct v4l2_standard)
 #define VIDIOC_ENUMINPUT	_IOWR ('V', 26, struct v4l2_input)
 #define VIDIOC_G_CTRL		_IOWR ('V', 27, struct v4l2_control)
-#define VIDIOC_S_CTRL		_IOW  ('V', 28, struct v4l2_control)
+#define VIDIOC_S_CTRL		_IOWR ('V', 28, struct v4l2_control)
 #define VIDIOC_G_TUNER		_IOWR ('V', 29, struct v4l2_tuner)
 #define VIDIOC_S_TUNER		_IOW  ('V', 30, struct v4l2_tuner)
-#define VIDIOC_G_AUDIO		_IOWR ('V', 33, struct v4l2_audio)
+#define VIDIOC_G_AUDIO		_IOR  ('V', 33, struct v4l2_audio)
 #define VIDIOC_S_AUDIO		_IOW  ('V', 34, struct v4l2_audio)
 #define VIDIOC_QUERYCTRL	_IOWR ('V', 36, struct v4l2_queryctrl)
 #define VIDIOC_QUERYMENU	_IOWR ('V', 37, struct v4l2_querymenu)
@@ -808,7 +863,7 @@
 #define VIDIOC_G_OUTPUT		_IOR  ('V', 46, int)
 #define VIDIOC_S_OUTPUT		_IOWR ('V', 47, int)
 #define VIDIOC_ENUMOUTPUT	_IOWR ('V', 48, struct v4l2_output)
-#define VIDIOC_G_AUDOUT		_IOWR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_G_AUDOUT		_IOR  ('V', 49, struct v4l2_audioout)
 #define VIDIOC_S_AUDOUT		_IOW  ('V', 50, struct v4l2_audioout)
 #define VIDIOC_G_MODULATOR	_IOWR ('V', 54, struct v4l2_modulator)
 #define VIDIOC_S_MODULATOR	_IOW  ('V', 55, struct v4l2_modulator)
@@ -821,6 +876,17 @@
 #define VIDIOC_S_JPEGCOMP	_IOW  ('V', 62, struct v4l2_jpegcompression)
 #define VIDIOC_QUERYSTD      	_IOR  ('V', 63, v4l2_std_id)
 #define VIDIOC_TRY_FMT      	_IOWR ('V', 64, struct v4l2_format)
+#define VIDIOC_ENUMAUDIO	_IOWR ('V', 65, struct v4l2_audio)
+#define VIDIOC_ENUMAUDOUT	_IOWR ('V', 66, struct v4l2_audioout)
+#define VIDIOC_G_PRIORITY       _IOR  ('V', 67, enum v4l2_priority)
+#define VIDIOC_S_PRIORITY       _IOW  ('V', 68, enum v4l2_priority)
+
+/* for compatibility, will go away some day */
+#define VIDIOC_OVERLAY_OLD     	_IOWR ('V', 14, int)
+#define VIDIOC_S_PARM_OLD      	_IOW  ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_S_CTRL_OLD      	_IOW  ('V', 28, struct v4l2_control)
+#define VIDIOC_G_AUDIO_OLD     	_IOWR ('V', 33, struct v4l2_audio)
+#define VIDIOC_G_AUDOUT_OLD    	_IOWR ('V', 49, struct v4l2_audioout)
 
 #define BASE_VIDIOC_PRIVATE	192		/* 192-255 are private */
 
@@ -839,17 +905,29 @@
 extern int v4l2_video_std_construct(struct v4l2_standard *vs,
 				    int id, char *name);
 
-/*  Compatibility layer interface  */
-typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
-			   unsigned int cmd, void *arg);
-int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
-			       int cmd, void *arg, v4l2_kioctl driver_ioctl);
+/* prority handling */
+struct v4l2_prio_state {
+	atomic_t prios[4];
+};
+int v4l2_prio_init(struct v4l2_prio_state *global);
+int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
+		     enum v4l2_priority new);
+int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
+enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
 
 /* names for fancy debug output */
 extern char *v4l2_field_names[];
 extern char *v4l2_type_names[];
 extern char *v4l2_ioctl_names[];
 
+/*  Compatibility layer interface  --  v4l1-compat module */
+typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
+			   unsigned int cmd, void *arg);
+int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
+			       int cmd, void *arg, v4l2_kioctl driver_ioctl);
+
 #endif /* __KERNEL__ */
 #endif /* __LINUX_VIDEODEV2_H */
 
Index: libs/libmythtv/videodev_myth.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/videodev_myth.h,v
retrieving revision 1.2
diff -u -r1.2 videodev_myth.h
--- libs/libmythtv/videodev_myth.h	1 Aug 2003 15:00:19 -0000	1.2
+++ libs/libmythtv/videodev_myth.h	18 Feb 2004 20:04:36 -0000
@@ -19,17 +19,31 @@
 #ifdef __KERNEL__
 
 #include <linux/poll.h>
+#include <linux/mm.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69)
 #include <linux/devfs_fs_kernel.h>
+#endif
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
+#include <linux/device.h>
+#endif
 
 struct video_device
 {
-	struct module *owner;
+	/* device info */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+	struct device *dev;
+#endif
      	char name[32];
  	int type;       /* v4l1 */
  	int type2;      /* v4l2 */
 	int hardware;
 	int minor;
 
+	/* device ops + callbacks */
+	struct file_operations *fops;
+	void (*release)(struct video_device *vfd);
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
 	/* old, obsolete interface -- dropped in 2.5.x, don't use it */
 	int (*open)(struct video_device *, int mode);
 	void (*close)(struct video_device *);
@@ -39,29 +53,74 @@
 	int (*ioctl)(struct video_device *, unsigned int , void *);
 	int (*mmap)(struct video_device *, const char *, unsigned long);
 	int (*initialize)(struct video_device *);       
+#endif
 
- 	/* new interface -- we will use file_operations directly
- 	 * like soundcore does. */
- 	struct file_operations *fops;
-	void *priv;		/* Used to be 'private' but that upsets C++ */
-
-	/* for videodev.c intenal usage -- don't touch */
-	int users;
-	struct semaphore lock;
-	devfs_handle_t devfs_handle;
+#if 1 /* to be removed in 2.7.x */
+	/* obsolete -- fops->owner is used instead */
+	struct module *owner;
+	/* dev->driver_data will be used instead some day.
+	 * Use the video_{get|set}_drvdata() helper functions,
+	 * so the switch over will be transparent for you.
+	 * Or use {pci|usb}_{get|set}_drvdata() directly. */
+	void *priv;
+#endif
+
+	/* for videodev.c intenal usage -- please don't touch */
+	int users;                     /* video_exclusive_{open|close} ... */
+	struct semaphore lock;         /* ... helper function uses these   */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69)
+	devfs_handle_t devfs_handle;   /* devfs */
+#else
+	char devfs_name[64];           /* devfs */
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+	struct class_device class_dev; /* sysfs */
+#endif
 };
 
 #define VIDEO_MAJOR	81
-extern int video_register_device(struct video_device *, int type, int nr);
 
 #define VFL_TYPE_GRABBER	0
 #define VFL_TYPE_VBI		1
 #define VFL_TYPE_RADIO		2
 #define VFL_TYPE_VTX		3
 
+extern int video_register_device(struct video_device *, int type, int nr);
 extern void video_unregister_device(struct video_device *);
 extern struct video_device* video_devdata(struct file*);
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
+#define to_video_device(cd) container_of(cd, struct video_device, class_dev)
+static inline void
+video_device_create_file(struct video_device *vfd,
+			 struct class_device_attribute *attr)
+{
+	class_device_create_file(&vfd->class_dev, attr);
+}
+static inline void
+video_device_remove_file(struct video_device *vfd,
+			 struct class_device_attribute *attr)
+{
+	class_device_remove_file(&vfd->class_dev, attr);
+}
+#endif
+
+/* helper functions to alloc / release struct video_device, the
+   later can be used for video_device->release() */
+struct video_device *video_device_alloc(void);
+void video_device_release(struct video_device *vfd);
+
+/* helper functions to access driver private data. */
+static inline void *video_get_drvdata(struct video_device *dev)
+{
+	return dev->priv;
+}
+
+static inline void video_set_drvdata(struct video_device *dev, void *data)
+{
+	dev->priv = data;
+}
+
 extern int video_exclusive_open(struct inode *inode, struct file *file);
 extern int video_exclusive_release(struct inode *inode, struct file *file);
 extern int video_usercopy(struct inode *inode, struct file *file,
@@ -97,6 +156,7 @@
 	int minheight;	/* And height */
 };
 
+#define VIDEO_RF_AUX_INPUT      0x100       /* dtv */
 
 struct video_channel
 {
@@ -131,7 +191,7 @@
 #define VIDEO_MODE_NTSC		1
 #define VIDEO_MODE_SECAM	2
 #define VIDEO_MODE_AUTO		3
-#define VIDEO_MODE_ATSC         4
+#define VIDEO_MODE_ATSC		4       /* dtv */
 	__u16 signal;			/* Signal strength 16bit scale */
 };
 
@@ -260,6 +320,13 @@
 	int	radio;		/* Radio minor */
 	int	audio;		/* Audio minor */
 	int	teletext;	/* Teletext minor */
+	int     dtv;            /* Digital video minor */
+};
+
+struct video_signal
+{
+	int 	strength;	/* signal strength */
+        int 	aux;    	/* aux signal strength */
 };
 
 struct vbi_format {
@@ -332,6 +399,7 @@
 #define VIDIOCSMICROCODE	_IOW('v',27, struct video_code)		/* Load microcode into hardware */
 #define	VIDIOCGVBIFMT		_IOR('v',28, struct vbi_format)		/* Get VBI information */
 #define	VIDIOCSVBIFMT		_IOW('v',29, struct vbi_format)		/* Set VBI information */
+#define	VIDIOCGSIGNAL		_IOR('v',30, struct video_signal)     	/* Get signal strength */
 
 
 #define BASE_VIDIOCPRIVATE	192		/* 192-255 are private */
@@ -404,7 +472,9 @@
 #define VID_HARDWARE_PWC	31	/* Philips webcams */
 #define VID_HARDWARE_MEYE	32	/* Sony Vaio MotionEye cameras */
 #define VID_HARDWARE_CPIA2	33
-
+#define VID_HARDWARE_VICAM	34	/* ViCam, 3Com Homeconnect */
+#define VID_HARDWARE_SF16FMR2	35
+#define VID_HARDWARE_W9968CF	36
 #endif /* __LINUX_VIDEODEV_H */
 
 /*


More information about the mythtv-dev mailing list