Staging: easycap: Replace some global variables
authorMike Thomas <rmthomas@sciolus.org>
Sun, 11 Jul 2010 09:51:13 +0000 (10:51 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 22 Jul 2010 18:08:01 +0000 (11:08 -0700)
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>
drivers/staging/easycap/easycap.h
drivers/staging/easycap/easycap_ioctl.c
drivers/staging/easycap/easycap_ioctl.h
drivers/staging/easycap/easycap_main.c
drivers/staging/easycap/easycap_settings.c
drivers/staging/easycap/easycap_sound.c
drivers/staging/easycap/easycap_sound.h

index 83ae2fb6db7c36eed1821d367f8c7dca869ed408..ce8b16f1b1fe25813a53fb1bb2c174d08b74e360 100644 (file)
 #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
  */
@@ -206,6 +265,16 @@ int isbuf;
 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
@@ -213,6 +282,16 @@ int length;
  */
 /*---------------------------------------------------------------------------*/
 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;
@@ -377,16 +456,6 @@ long long int audio_square;
 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
  */
@@ -501,65 +570,6 @@ long long int quotient;
 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
  */
index f71cd9eaeb6b733ecfe7407a86a386ab9c335c97..5853bba4dfcaa9d6830d7d2953461c626dbc8382 100644 (file)
@@ -42,7 +42,7 @@
 /*---------------------------------------------------------------------------*/
 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;
@@ -1447,7 +1447,7 @@ case VIDIOC_ENUMSTD: {
        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");
 
@@ -1479,11 +1479,12 @@ case VIDIOC_ENUMSTD: {
        }
        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;
@@ -1493,7 +1494,7 @@ case VIDIOC_ENUMSTD: {
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 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");
 
@@ -2094,7 +2095,7 @@ case SNDCTL_DSP_GETBLKSIZE: {
        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;
@@ -2104,7 +2105,7 @@ case SNDCTL_DSP_GETISPACE: {
 
        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;
index 7cab0943d9136d92fdf43620d16c247e3bef61c8..210cd627235fac358bed0c0acd0bc36b81a26205 100644 (file)
@@ -26,4 +26,3 @@
 /*****************************************************************************/
 extern struct easycap_format easycap_format[];
 extern struct v4l2_queryctrl easycap_control[];
-extern unsigned int audio_bytes_per_fragment;
index 18259df3fe7d21e5241af7ba2be377b618de4d1c..b817c97cc9f11a576f573799987f0105470d8964 100644 (file)
 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
@@ -86,7 +82,7 @@ struct usb_class_driver easycap_class = {
 /*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,
@@ -770,7 +766,7 @@ JOT(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \
 /*---------------------------------------------------------------------------*/
 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;
@@ -3865,12 +3861,12 @@ case 2: {
                        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", \
@@ -3878,17 +3874,19 @@ case 2: {
                        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;
 
@@ -3946,9 +3944,10 @@ case 2: {
        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 {
index 1e4eb23885e36e2dc21c7070c24987bcbdfca50b..38d94051241d1ef7bd2f6811861c6c1351aabcd8 100644 (file)
@@ -35,7 +35,7 @@
  *                         1 => 30 fps
  */
 /*---------------------------------------------------------------------------*/
-struct easycap_standard easycap_standard[] = {
+const struct easycap_standard easycap_standard[] = {
 {
 .mask = 0x000F & PAL_BGHIN ,
 .v4l2_standard = {
index 532c4105738ac65926a9a1dc0746181231415b7b..2bf32e1987b923f563e20239c7812702a135f86e 100644 (file)
@@ -327,7 +327,7 @@ for (i = 0;  i < purb->number_of_packets; i++) {
                                                        "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");
@@ -352,7 +352,8 @@ for (i = 0;  i < purb->number_of_packets; i++) {
                                        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;
 
@@ -367,13 +368,16 @@ for (i = 0;  i < purb->number_of_packets; i++) {
                                                        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));
@@ -611,7 +615,7 @@ if (NULL == peasycap) {
 }
 /*---------------------------------------------------------------------------*/
 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;
 }
@@ -621,10 +625,11 @@ if ((struct data_buffer *)NULL == pdata_buffer) {
        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");
@@ -633,7 +638,7 @@ while ((fragment == (peasycap->audio_fill / audio_pages_per_fragment)) || \
        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");
@@ -657,10 +662,11 @@ while ((fragment == (peasycap->audio_fill / audio_pages_per_fragment)) || \
        }
 }
 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;
@@ -676,17 +682,18 @@ while (fragment == (peasycap->audio_read / audio_pages_per_fragment)) {
        }
        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;
                }
@@ -738,8 +745,8 @@ while (fragment == (peasycap->audio_read / audio_pages_per_fragment)) {
        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);
index a6e2a9d22319c9135562acb3f2d893706cb0936c..491273969023e28cd800d4355fb3772ec5a09b11 100644 (file)
@@ -26,5 +26,3 @@
 /*****************************************************************************/
 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;