New members of struct easycap take the place of undesirable global variables.
Signed-off-by: Mike Thomas <rmthomas@sciolus.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
#define USB_EASYCAP_VENDOR_ID 0x05e1
#define USB_EASYCAP_PRODUCT_ID 0x0408
-#define EASYCAP_DRIVER_VERSION "0.8"
+#define EASYCAP_DRIVER_VERSION "0.8.2"
#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
#define USB_SKEL_MINOR_BASE 192
/*---------------------------------------------------------------------------*/
#define AUDIO_FRAGMENT_MANY 32
/*---------------------------------------------------------------------------*/
+/*
+ * IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
+ * ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
+ * THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT
+ * ONLY MUST THE PARAMETER
+ * STANDARD_MANY
+ * BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
+ * NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS
+ * MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
+ * ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE.
+ */
+/*---------------------------------------------------------------------------*/
+#define PAL_BGHIN 0
+#define PAL_Nc 2
+#define SECAM 4
+#define NTSC_N 6
+#define NTSC_N_443 8
+#define NTSC_M 1
+#define NTSC_443 3
+#define NTSC_M_JP 5
+#define PAL_60 7
+#define PAL_M 9
+#define STANDARD_MANY 10
+/*---------------------------------------------------------------------------*/
+/*
+ * ENUMS
+ */
+/*---------------------------------------------------------------------------*/
+enum {
+AT_720x576,
+AT_704x576,
+AT_640x480,
+AT_720x480,
+AT_360x288,
+AT_320x240,
+AT_360x240,
+RESOLUTION_MANY
+};
+enum {
+FMT_UYVY,
+FMT_YUY2,
+FMT_RGB24,
+FMT_RGB32,
+FMT_BGR24,
+FMT_BGR32,
+PIXELFORMAT_MANY
+};
+enum {
+FIELD_NONE,
+FIELD_INTERLACED,
+FIELD_ALTERNATE,
+INTERLACE_MANY
+};
+#define SETTINGS_MANY (STANDARD_MANY * \
+ RESOLUTION_MANY * \
+ 2 * \
+ PIXELFORMAT_MANY * \
+ INTERLACE_MANY)
+/*---------------------------------------------------------------------------*/
/*
* STRUCTURE DEFINITIONS
*/
int length;
};
/*---------------------------------------------------------------------------*/
+struct easycap_standard {
+__u16 mask;
+struct v4l2_standard v4l2_standard;
+};
+struct easycap_format {
+__u16 mask;
+char name[128];
+struct v4l2_format v4l2_format;
+};
+/*---------------------------------------------------------------------------*/
/*
* easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256
* easycap.ilk == 2 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=9
*/
/*---------------------------------------------------------------------------*/
struct easycap {
+unsigned int audio_pages_per_fragment;
+unsigned int audio_bytes_per_fragment;
+unsigned int audio_buffer_page_many;
+
+#define UPSAMPLE
+#if defined(UPSAMPLE)
+__s16 oldaudio;
+#endif /*UPSAMPLE*/
+
+struct easycap_format easycap_format[1 + SETTINGS_MANY];
int ilk;
bool microphone;
struct data_buffer audio_buffer[];
};
/*---------------------------------------------------------------------------*/
-struct easycap_standard {
-__u16 mask;
-struct v4l2_standard v4l2_standard;
-};
-struct easycap_format {
-__u16 mask;
-char name[128];
-struct v4l2_format v4l2_format;
-};
-/*---------------------------------------------------------------------------*/
/*
* VIDEO FUNCTION PROTOTYPES
*/
unsigned long long int remainder;
} signed_div(long long int, long long int);
/*---------------------------------------------------------------------------*/
-/*
- * IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
- * ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
- * THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT
- * ONLY MUST THE PARAMETER
- * STANDARD_MANY
- * BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
- * NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS
- * MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
- * ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE.
- */
-/*---------------------------------------------------------------------------*/
-#define PAL_BGHIN 0
-#define PAL_Nc 2
-#define SECAM 4
-#define NTSC_N 6
-#define NTSC_N_443 8
-#define NTSC_M 1
-#define NTSC_443 3
-#define NTSC_M_JP 5
-#define PAL_60 7
-#define PAL_M 9
-#define STANDARD_MANY 10
-/*---------------------------------------------------------------------------*/
-/*
- * ENUMS
- */
-/*---------------------------------------------------------------------------*/
-enum {
-AT_720x576,
-AT_704x576,
-AT_640x480,
-AT_720x480,
-AT_360x288,
-AT_320x240,
-AT_360x240,
-RESOLUTION_MANY
-};
-enum {
-FMT_UYVY,
-FMT_YUY2,
-FMT_RGB24,
-FMT_RGB32,
-FMT_BGR24,
-FMT_BGR32,
-PIXELFORMAT_MANY
-};
-enum {
-FIELD_NONE,
-FIELD_INTERLACED,
-FIELD_ALTERNATE,
-INTERLACE_MANY
-};
-#define SETTINGS_MANY (STANDARD_MANY * \
- RESOLUTION_MANY * \
- 2 * \
- PIXELFORMAT_MANY * \
- INTERLACE_MANY)
-/*---------------------------------------------------------------------------*/
/*
* MACROS
*/
/*---------------------------------------------------------------------------*/
int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id)
{
-struct easycap_standard *peasycap_standard;
+struct easycap_standard const *peasycap_standard;
__u16 reg, set;
int ir, rc, need;
unsigned int itwas, isnow;
static int last0 = -1, last1 = -1, last2 = -1, last3 = -1;
static struct v4l2_standard v4l2_standard;
static __u32 index;
- static struct easycap_standard *peasycap_standard;
+ static struct easycap_standard const *peasycap_standard;
JOT(8, "VIDIOC_ENUMSTD\n");
}
JOT(8, "%i=index: %s\n", index, \
&(peasycap_standard->v4l2_standard.name[0]));
- peasycap_standard->v4l2_standard.index = index;
+ memcpy(&v4l2_standard, &(peasycap_standard->v4l2_standard), \
+ sizeof(struct v4l2_standard));
+
v4l2_standard.index = index;
- if (0 != copy_to_user((void __user *)arg, \
- &(peasycap_standard->v4l2_standard), \
+ if (0 != copy_to_user((void __user *)arg, &v4l2_standard, \
sizeof(struct v4l2_standard))) {
POUT;
return -EFAULT;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
case VIDIOC_G_STD: {
static v4l2_std_id std_id;
- static struct easycap_standard *peasycap_standard;
+ static struct easycap_standard const *peasycap_standard;
JOT(8, "VIDIOC_G_STD\n");
if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int)))
return -EFAULT;
JOT(8, "........... %i=incoming\n", incoming);
- incoming = audio_bytes_per_fragment;
+ incoming = peasycap->audio_bytes_per_fragment;
if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int)))
return -EFAULT;
break;
JOT(8, "SNDCTL_DSP_GETISPACE\n");
- audio_buf_info.bytes = audio_bytes_per_fragment;
+ audio_buf_info.bytes = peasycap->audio_bytes_per_fragment;
audio_buf_info.fragments = 1;
audio_buf_info.fragsize = 0;
audio_buf_info.fragstotal = 0;
/*****************************************************************************/
extern struct easycap_format easycap_format[];
extern struct v4l2_queryctrl easycap_control[];
-extern unsigned int audio_bytes_per_fragment;
int easycap_debug;
module_param(easycap_debug, int, S_IRUGO | S_IWUSR);
-unsigned int audio_pages_per_fragment;
-unsigned int audio_bytes_per_fragment;
-unsigned int audio_buffer_page_many;
-
/*---------------------------------------------------------------------------*/
/*
* PARAMETERS APPLICABLE TO ENTIRE DRIVER, I.E. BOTH VIDEO AND AUDIO
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
#if defined(EASYCAP_NEEDS_V4L2_FOPS)
-struct v4l2_file_operations v4l2_fops = {
+const struct v4l2_file_operations v4l2_fops = {
.owner = THIS_MODULE,
.open = easycap_open_noinode,
.release = easycap_release_noinode,
/*---------------------------------------------------------------------------*/
JOT(4, "freeing audio buffers.\n");
lost = 0;
-for (k = 0; k < audio_buffer_page_many; k++) {
+for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
free_page((unsigned long)(peasycap->audio_buffer[k].pgo));
peasycap->audio_buffer[k].pgo = (void *)NULL;
peasycap->ilk |= 0x02;
SAY("hardware is FOUR-CVBS\n");
peasycap->microphone = true;
- audio_pages_per_fragment = 2;
+ peasycap->audio_pages_per_fragment = 2;
} else if (256 == peasycap->audio_isoc_maxframesize) {
peasycap->ilk &= ~0x02;
SAY("hardware is CVBS+S-VIDEO\n");
peasycap->microphone = false;
- audio_pages_per_fragment = 4;
+ peasycap->audio_pages_per_fragment = 4;
} else {
SAY("hardware is unidentified:\n");
SAY("%i=audio_isoc_maxframesize\n", \
return -ENOENT;
}
- audio_bytes_per_fragment = audio_pages_per_fragment * \
+ peasycap->audio_bytes_per_fragment = \
+ peasycap->audio_pages_per_fragment * \
PAGE_SIZE ;
- audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
- audio_pages_per_fragment);
+ peasycap->audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
+ peasycap->audio_pages_per_fragment);
JOT(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY);
JOT(4, "%6i=audio_pages_per_fragment\n", \
- audio_pages_per_fragment);
+ peasycap->audio_pages_per_fragment);
JOT(4, "%6i=audio_bytes_per_fragment\n", \
- audio_bytes_per_fragment);
- JOT(4, "%6i=audio_buffer_page_many\n", audio_buffer_page_many);
+ peasycap->audio_bytes_per_fragment);
+ JOT(4, "%6i=audio_buffer_page_many\n", \
+ peasycap->audio_buffer_page_many);
peasycap->audio_isoc_framesperdesc = 128;
peasycap->purb_audio_head = &(peasycap->urb_audio_head);
JOT(4, "allocating an audio buffer\n");
- JOT(4, ".... scattered over %i pages\n", audio_buffer_page_many);
+ JOT(4, ".... scattered over %i pages\n", \
+ peasycap->audio_buffer_page_many);
- for (k = 0; k < audio_buffer_page_many; k++) {
+ for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
SAY("ERROR: attempting to reallocate audio buffers\n");
} else {
* 1 => 30 fps
*/
/*---------------------------------------------------------------------------*/
-struct easycap_standard easycap_standard[] = {
+const struct easycap_standard easycap_standard[] = {
{
.mask = 0x000F & PAL_BGHIN ,
.v4l2_standard = {
"more is negative\n");
return;
}
- if (audio_buffer_page_many <= \
+ if (peasycap->audio_buffer_page_many <= \
peasycap->audio_fill) {
SAY("ERROR: bad " \
"peasycap->audio_fill\n");
paudio_buffer->pto = \
paudio_buffer->pgo;
(peasycap->audio_fill)++;
- if (audio_buffer_page_many <= \
+ if (peasycap->\
+ audio_buffer_page_many <= \
peasycap->audio_fill)
peasycap->audio_fill = 0;
paudio_buffer->pgo;
if (!(peasycap->audio_fill % \
+ peasycap->\
audio_pages_per_fragment)) {
JOT(12, "wakeup call on wq_" \
"audio, %i=frag reading %i" \
"=fragment fill\n", \
(peasycap->audio_read / \
+ peasycap->\
audio_pages_per_fragment), \
(peasycap->audio_fill / \
+ peasycap->\
audio_pages_per_fragment));
wake_up_interruptible\
(&(peasycap->wq_audio));
}
/*---------------------------------------------------------------------------*/
if ((0 > peasycap->audio_read) || \
- (audio_buffer_page_many <= peasycap->audio_read)) {
+ (peasycap->audio_buffer_page_many <= peasycap->audio_read)) {
SAY("ERROR: peasycap->audio_read out of range\n");
return -EFAULT;
}
return -EFAULT;
}
JOT(12, "before wait, %i=frag read %i=frag fill\n", \
- (peasycap->audio_read / audio_pages_per_fragment), \
- (peasycap->audio_fill / audio_pages_per_fragment));
-fragment = (peasycap->audio_read / audio_pages_per_fragment);
-while ((fragment == (peasycap->audio_fill / audio_pages_per_fragment)) || \
+ (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
+ (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
+fragment = (peasycap->audio_read / peasycap->audio_pages_per_fragment);
+while ((fragment == (peasycap->audio_fill / \
+ peasycap->audio_pages_per_fragment)) || \
(0 == (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo)))) {
if (file->f_flags & O_NONBLOCK) {
JOT(16, "returning -EAGAIN as instructed\n");
rc = wait_event_interruptible(peasycap->wq_audio, \
(peasycap->audio_idle || peasycap->audio_eof || \
((fragment != (peasycap->audio_fill / \
- audio_pages_per_fragment)) && \
+ peasycap->audio_pages_per_fragment)) && \
(0 < (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo))))));
if (0 != rc) {
SAY("aborted by signal\n");
}
}
JOT(12, "after wait, %i=frag read %i=frag fill\n", \
- (peasycap->audio_read / audio_pages_per_fragment), \
- (peasycap->audio_fill / audio_pages_per_fragment));
+ (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
+ (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
szret = (size_t)0;
-while (fragment == (peasycap->audio_read / audio_pages_per_fragment)) {
+while (fragment == (peasycap->audio_read / \
+ peasycap->audio_pages_per_fragment)) {
if (NULL == pdata_buffer->pgo) {
SAY("ERROR: pdata_buffer->pgo is NULL\n");
return -EFAULT;
}
if (!kount1) {
(peasycap->audio_read)++;
- if (audio_buffer_page_many <= peasycap->audio_read)
+ if (peasycap->audio_buffer_page_many <= peasycap->audio_read)
peasycap->audio_read = 0;
JOT(12, "bumped peasycap->audio_read to %i\n", \
peasycap->audio_read);
if (fragment != (peasycap->audio_read / \
- audio_pages_per_fragment))
+ peasycap->audio_pages_per_fragment))
break;
if ((0 > peasycap->audio_read) || \
- (audio_buffer_page_many <= peasycap->audio_read)) {
+ (peasycap->audio_buffer_page_many <= \
+ peasycap->audio_read)) {
SAY("ERROR: peasycap->audio_read out of range\n");
return -EFAULT;
}
kount -= (size_t)more;
}
JOT(12, "after read, %i=frag read %i=frag fill\n", \
- (peasycap->audio_read / audio_pages_per_fragment), \
- (peasycap->audio_fill / audio_pages_per_fragment));
+ (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
+ (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
if (kount < 0) {
SAY("MISTAKE: %li=kount %li=szret\n", \
(long int)kount, (long int)szret);
/*****************************************************************************/
extern struct easycap *peasycap;
extern struct usb_driver easycap_usb_driver;
-extern unsigned int audio_buffer_page_many;
-extern unsigned int audio_pages_per_fragment;