staging/easycap: Make code re-entrant

In order to allow multiple EasyCAP dongles to operate simultaneously
without mutual interference all static variables have been eliminated
except for a persistent inventory of plugged-in dongles at module level.

Signed-off-by: Mike Thomas <rmthomas@sciolus.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Mike Thomas 2010-11-07 19:58:55 +00:00 committed by Greg Kroah-Hartman
parent ce36cedab3
commit e68703cfe8
7 changed files with 1377 additions and 1192 deletions

View file

@ -121,7 +121,7 @@
#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
#define USB_SKEL_MINOR_BASE 192
#define VIDEO_DEVICE_MANY 8
#define DONGLE_MANY 8
/*---------------------------------------------------------------------------*/
/*
@ -264,6 +264,17 @@ struct v4l2_format v4l2_format;
*/
/*---------------------------------------------------------------------------*/
struct easycap {
int isdongle;
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
struct video_device video_device;
#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
struct v4l2_device v4l2_device;
#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
unsigned int audio_pages_per_fragment;
unsigned int audio_bytes_per_fragment;
unsigned int audio_buffer_page_many;
@ -276,12 +287,6 @@ __s16 oldaudio;
int ilk;
bool microphone;
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
struct video_device *pvideo_device;
#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
struct usb_device *pusb_device;
struct usb_interface *pusb_interface;
@ -306,7 +311,10 @@ int merit[180];
struct timeval timeval0;
struct timeval timeval1;
struct timeval timeval2;
struct timeval timeval3;
struct timeval timeval6;
struct timeval timeval7;
struct timeval timeval8;
long long int dnbydt;
int video_interface;
@ -332,6 +340,13 @@ struct data_buffer \
struct list_head urb_video_head;
struct list_head *purb_video_head;
__u8 cache[8];
__u8 *pcache;
int video_mt;
int audio_mt;
long long audio_bytes;
__u32 isequence;
int vma_many;
/*---------------------------------------------------------------------------*/
@ -530,6 +545,7 @@ int set2to93(struct usb_device *);
int regset(struct usb_device *, __u16, __u16);
int regget(struct usb_device *, __u16, void *);
int isdongle(struct easycap *);
/*---------------------------------------------------------------------------*/
struct signed_div_result {
long long int quotient;
@ -557,20 +573,39 @@ unsigned long long int remainder;
} \
} while (0)
/*---------------------------------------------------------------------------*/
/*
* MACROS SAM(...) AND JOM(...) ALLOW DIAGNOSTIC OUTPUT TO BE TAGGED WITH
* THE IDENTITY OF THE DONGLE TO WHICH IT APPLIES, BUT IF INVOKED WHEN THE
* POINTER peasycap IS INVALID AN Oops IS LIKELY, AND ITS CAUSE MAY NOT BE
* IMMEDIATELY OBVIOUS FROM A CASUAL READING OF THE SOURCE CODE. BEWARE.
*/
/*---------------------------------------------------------------------------*/
#define SAY(format, args...) do { \
printk(KERN_DEBUG "easycap: %s: " format, __func__, ##args); \
printk(KERN_DEBUG "easycap:: %s: " \
format, __func__, ##args); \
} while (0)
#define SAM(format, args...) do { \
printk(KERN_DEBUG "easycap::%i%s: " \
format, peasycap->isdongle, __func__, ##args);\
} while (0)
#if defined(EASYCAP_DEBUG)
#define JOT(n, format, args...) do { \
if (n <= debug) { \
printk(KERN_DEBUG "easycap: %s: " format, __func__, ##args); \
printk(KERN_DEBUG "easycap:: %s: " \
format, __func__, ##args);\
} \
} while (0)
#define JOM(n, format, args...) do { \
if (n <= debug) { \
printk(KERN_DEBUG "easycap::%i%s: " \
format, peasycap->isdongle, __func__, ##args);\
} \
} while (0)
#else
#define JOT(n, format, args...) do {} while (0)
#define JOM(n, format, args...) do {} while (0)
#endif /*EASYCAP_DEBUG*/
#define MICROSECONDS(X, Y) \

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* *
* debug.h *
* easycap_debug.h *
* *
*****************************************************************************/
/*

File diff suppressed because it is too large Load diff

View file

@ -783,6 +783,12 @@ return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
(int)50000);
}
/*****************************************************************************/
int
audio_setup(struct easycap *peasycap)
{
struct usb_device *pusb_device;
unsigned char buffer[1];
int rc, id1, id2;
/*---------------------------------------------------------------------------*/
/*
* IMPORTANT:
@ -791,20 +797,12 @@ return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
* TO ENABLE AUDIO THE VALUE 0x0200 MUST BE SENT.
*/
/*---------------------------------------------------------------------------*/
int
audio_setup(struct easycap *peasycap)
{
struct usb_device *pusb_device;
static __u8 request = 0x01;
static __u8 requesttype = \
const __u8 request = 0x01;
const __u8 requesttype = \
(__u8)(USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE);
static __u16 value_unmute = 0x0200;
static __u16 index = 0x0301;
static unsigned char buffer[1];
static __u16 length = 1;
int rc, id1, id2;
const __u16 value_unmute = 0x0200;
const __u16 index = 0x0301;
const __u16 length = 1;
if (NULL == peasycap)
return -EFAULT;

File diff suppressed because it is too large Load diff

View file

@ -43,10 +43,8 @@
void
easysnd_complete(struct urb *purb)
{
static int mt;
struct easycap *peasycap;
struct data_buffer *paudio_buffer;
char errbuf[16];
__u8 *p1, *p2;
__s16 s16;
int i, j, more, much, leap, rc;
@ -68,46 +66,55 @@ if (NULL == peasycap) {
}
much = 0;
if (peasycap->audio_idle) {
JOT(16, "%i=audio_idle %i=audio_isoc_streaming\n", \
JOM(16, "%i=audio_idle %i=audio_isoc_streaming\n", \
peasycap->audio_idle, peasycap->audio_isoc_streaming);
if (peasycap->audio_isoc_streaming) {
rc = usb_submit_urb(purb, GFP_ATOMIC);
if (0 != rc) {
SAY("ERROR: while %i=audio_idle, " \
if (-ENODEV != rc)
SAM("ERROR: while %i=audio_idle, " \
"usb_submit_urb() failed with rc:\n", \
peasycap->audio_idle);
switch (rc) {
case -ENOMEM: {
SAY("ENOMEM\n"); break;
SAM("-ENOMEM\n");
break;
}
case -ENODEV: {
SAY("ENODEV\n"); break;
break;
}
case -ENXIO: {
SAY("ENXIO\n"); break;
SAM("-ENXIO\n");
break;
}
case -EINVAL: {
SAY("EINVAL\n"); break;
SAM("-EINVAL\n");
break;
}
case -EAGAIN: {
SAY("EAGAIN\n"); break;
SAM("-EAGAIN\n");
break;
}
case -EFBIG: {
SAY("EFBIG\n"); break;
SAM("-EFBIG\n");
break;
}
case -EPIPE: {
SAY("EPIPE\n"); break;
SAM("-EPIPE\n");
break;
}
case -EMSGSIZE: {
SAY("EMSGSIZE\n"); break;
SAM("-EMSGSIZE\n");
break;
}
case -ENOSPC: {
SAY("ENOSPC\n"); break;
SAM("-ENOSPC\n");
break;
}
default: {
SAY("0x%08X\n", rc); break;
SAM("unknown error: 0x%08X\n", rc);
break;
}
}
}
@ -116,74 +123,95 @@ return;
}
/*---------------------------------------------------------------------------*/
if (purb->status) {
if (-ESHUTDOWN == purb->status) {
JOT(16, "immediate return because -ESHUTDOWN=purb->status\n");
if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
JOM(16, "urb status -ESHUTDOWN or -ENOENT\n");
return;
}
SAY("ERROR: non-zero urb status:\n");
SAM("ERROR: non-zero urb status:\n");
switch (purb->status) {
case -EINPROGRESS: {
SAY("-EINPROGRESS\n"); break;
SAM("-EINPROGRESS\n");
break;
}
case -ENOSR: {
SAY("-ENOSR\n"); break;
SAM("-ENOSR\n");
break;
}
case -EPIPE: {
SAY("-EPIPE\n"); break;
SAM("-EPIPE\n");
break;
}
case -EOVERFLOW: {
SAY("-EOVERFLOW\n"); break;
SAM("-EOVERFLOW\n");
break;
}
case -EPROTO: {
SAY("-EPROTO\n"); break;
SAM("-EPROTO\n");
break;
}
case -EILSEQ: {
SAY("-EILSEQ\n"); break;
SAM("-EILSEQ\n");
break;
}
case -ETIMEDOUT: {
SAY("-ETIMEDOUT\n"); break;
SAM("-ETIMEDOUT\n");
break;
}
case -EMSGSIZE: {
SAY("-EMSGSIZE\n"); break;
SAM("-EMSGSIZE\n");
break;
}
case -EOPNOTSUPP: {
SAY("-EOPNOTSUPP\n"); break;
SAM("-EOPNOTSUPP\n");
break;
}
case -EPFNOSUPPORT: {
SAY("-EPFNOSUPPORT\n"); break;
SAM("-EPFNOSUPPORT\n");
break;
}
case -EAFNOSUPPORT: {
SAY("-EAFNOSUPPORT\n"); break;
SAM("-EAFNOSUPPORT\n");
break;
}
case -EADDRINUSE: {
SAY("-EADDRINUSE\n"); break;
SAM("-EADDRINUSE\n");
break;
}
case -EADDRNOTAVAIL: {
SAY("-EADDRNOTAVAIL\n"); break;
SAM("-EADDRNOTAVAIL\n");
break;
}
case -ENOBUFS: {
SAY("-ENOBUFS\n"); break;
SAM("-ENOBUFS\n");
break;
}
case -EISCONN: {
SAY("-EISCONN\n"); break;
SAM("-EISCONN\n");
break;
}
case -ENOTCONN: {
SAY("-ENOTCONN\n"); break;
SAM("-ENOTCONN\n");
break;
}
case -ESHUTDOWN: {
SAY("-ESHUTDOWN\n"); break;
SAM("-ESHUTDOWN\n");
break;
}
case -ENOENT: {
SAY("-ENOENT\n"); break;
SAM("-ENOENT\n");
break;
}
case -ECONNRESET: {
SAY("-ECONNRESET\n"); break;
SAM("-ECONNRESET\n");
break;
}
case -ENOSPC: {
SAY("ENOSPC\n"); break;
SAM("ENOSPC\n");
break;
}
default: {
SAY("unknown error code 0x%08X\n", purb->status); break;
SAM("unknown error code 0x%08X\n", purb->status);
break;
}
}
/*---------------------------------------------------------------------------*/
@ -196,35 +224,43 @@ if (purb->status) {
if (peasycap->audio_isoc_streaming) {
rc = usb_submit_urb(purb, GFP_ATOMIC);
if (0 != rc) {
SAY("ERROR: while %i=audio_idle, usb_submit_urb() "
SAM("ERROR: while %i=audio_idle, usb_submit_urb() "
"failed with rc:\n", peasycap->audio_idle);
switch (rc) {
case -ENOMEM: {
SAY("ENOMEM\n"); break;
SAM("-ENOMEM\n");
break;
}
case -ENODEV: {
SAY("ENODEV\n"); break;
SAM("-ENODEV\n");
break;
}
case -ENXIO: {
SAY("ENXIO\n"); break;
SAM("-ENXIO\n");
break;
}
case -EINVAL: {
SAY("EINVAL\n"); break;
SAM("-EINVAL\n");
break;
}
case -EAGAIN: {
SAY("EAGAIN\n"); break;
SAM("-EAGAIN\n");
break;
}
case -EFBIG: {
SAY("EFBIG\n"); break;
SAM("-EFBIG\n");
break;
}
case -EPIPE: {
SAY("EPIPE\n"); break;
SAM("-EPIPE\n");
break;
}
case -EMSGSIZE: {
SAY("EMSGSIZE\n"); break;
SAM("-EMSGSIZE\n");
break;
}
default: {
SAY("0x%08X\n", rc); break;
SAM("0x%08X\n", rc); break;
}
}
}
@ -243,73 +279,81 @@ oldaudio = peasycap->oldaudio;
for (i = 0; i < purb->number_of_packets; i++) {
switch (purb->iso_frame_desc[i].status) {
case 0: {
strcpy(&errbuf[0], "OK"); break;
break;
}
case -ENOENT: {
strcpy(&errbuf[0], "-ENOENT"); break;
SAM("-ENOENT\n");
break;
}
case -EINPROGRESS: {
strcpy(&errbuf[0], "-EINPROGRESS"); break;
SAM("-EINPROGRESS\n");
break;
}
case -EPROTO: {
strcpy(&errbuf[0], "-EPROTO"); break;
SAM("-EPROTO\n");
break;
}
case -EILSEQ: {
strcpy(&errbuf[0], "-EILSEQ"); break;
SAM("-EILSEQ\n");
break;
}
case -ETIME: {
strcpy(&errbuf[0], "-ETIME"); break;
SAM("-ETIME\n");
break;
}
case -ETIMEDOUT: {
strcpy(&errbuf[0], "-ETIMEDOUT"); break;
SAM("-ETIMEDOUT\n");
break;
}
case -EPIPE: {
strcpy(&errbuf[0], "-EPIPE"); break;
SAM("-EPIPE\n");
break;
}
case -ECOMM: {
strcpy(&errbuf[0], "-ECOMM"); break;
SAM("-ECOMM\n");
break;
}
case -ENOSR: {
strcpy(&errbuf[0], "-ENOSR"); break;
SAM("-ENOSR\n");
break;
}
case -EOVERFLOW: {
strcpy(&errbuf[0], "-EOVERFLOW"); break;
SAM("-EOVERFLOW\n");
break;
}
case -EREMOTEIO: {
strcpy(&errbuf[0], "-EREMOTEIO"); break;
SAM("-EREMOTEIO\n");
break;
}
case -ENODEV: {
strcpy(&errbuf[0], "-ENODEV"); break;
SAM("-ENODEV\n");
break;
}
case -EXDEV: {
strcpy(&errbuf[0], "-EXDEV"); break;
SAM("-EXDEV\n");
break;
}
case -EINVAL: {
strcpy(&errbuf[0], "-EINVAL"); break;
SAM("-EINVAL\n");
break;
}
case -ECONNRESET: {
strcpy(&errbuf[0], "-ECONNRESET"); break;
SAM("-ECONNRESET\n");
break;
}
case -ENOSPC: {
strcpy(&errbuf[0], "-ENOSPC"); break;
SAM("-ENOSPC\n");
break;
}
case -ESHUTDOWN: {
strcpy(&errbuf[0], "-ESHUTDOWN"); break;
SAM("-ESHUTDOWN\n");
break;
}
default: {
strcpy(&errbuf[0], "UNKNOWN"); break;
SAM("unknown error:0x%08X\n", purb->iso_frame_desc[i].status);
break;
}
}
if ((!purb->iso_frame_desc[i].status) && 0) {
JOT(16, "frame[%2i]: %i=status{=%16s} " \
"%5i=actual " \
"%5i=length " \
"%3i=offset\n", \
i, purb->iso_frame_desc[i].status, &errbuf[0],
purb->iso_frame_desc[i].actual_length,
purb->iso_frame_desc[i].length,
purb->iso_frame_desc[i].offset);
}
if (!purb->iso_frame_desc[i].status) {
more = purb->iso_frame_desc[i].actual_length;
@ -319,11 +363,12 @@ for (i = 0; i < purb->number_of_packets; i++) {
#endif
if (!more)
mt++;
peasycap->audio_mt++;
else {
if (mt) {
JOT(16, "%4i empty audio urb frames\n", mt);
mt = 0;
if (peasycap->audio_mt) {
JOM(16, "%4i empty audio urb frames\n", \
peasycap->audio_mt);
peasycap->audio_mt = 0;
}
p1 = (__u8 *)(purb->transfer_buffer + \
@ -340,13 +385,13 @@ for (i = 0; i < purb->number_of_packets; i++) {
/*---------------------------------------------------------------------------*/
while (more) {
if (0 > more) {
SAY("easysnd_complete: MISTAKE: " \
SAM("easysnd_complete: MISTAKE: " \
"more is negative\n");
return;
}
if (peasycap->audio_buffer_page_many <= \
peasycap->audio_fill) {
SAY("ERROR: bad " \
SAM("ERROR: bad " \
"peasycap->audio_fill\n");
return;
}
@ -355,7 +400,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
[peasycap->audio_fill];
if (PAGE_SIZE < (paudio_buffer->pto - \
paudio_buffer->pgo)) {
SAY("ERROR: bad paudio_buffer->pto\n");
SAM("ERROR: bad paudio_buffer->pto\n");
return;
}
if (PAGE_SIZE == (paudio_buffer->pto - \
@ -374,7 +419,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
peasycap->audio_fill)
peasycap->audio_fill = 0;
JOT(12, "bumped peasycap->" \
JOM(12, "bumped peasycap->" \
"audio_fill to %i\n", \
peasycap->audio_fill);
@ -387,7 +432,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
if (!(peasycap->audio_fill % \
peasycap->\
audio_pages_per_fragment)) {
JOT(12, "wakeup call on wq_" \
JOM(12, "wakeup call on wq_" \
"audio, %i=frag reading %i" \
"=fragment fill\n", \
(peasycap->audio_read / \
@ -414,7 +459,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
} else {
#if defined(UPSAMPLE)
if (much % 16)
JOT(8, "MISTAKE? much" \
JOM(8, "MISTAKE? much" \
" is not divisible by 16\n");
if (much > (16 * \
more))
@ -468,7 +513,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
}
}
} else {
JOT(12, "discarding audio samples because " \
JOM(12, "discarding audio samples because " \
"%i=purb->iso_frame_desc[i].status\n", \
purb->iso_frame_desc[i].status);
}
@ -486,38 +531,50 @@ peasycap->oldaudio = oldaudio;
if (peasycap->audio_isoc_streaming) {
rc = usb_submit_urb(purb, GFP_ATOMIC);
if (0 != rc) {
SAY("ERROR: while %i=audio_idle, usb_submit_urb() failed " \
if (-ENODEV != rc) {
SAM("ERROR: while %i=audio_idle, " \
"usb_submit_urb() failed " \
"with rc:\n", peasycap->audio_idle);
}
switch (rc) {
case -ENOMEM: {
SAY("ENOMEM\n"); break;
SAM("-ENOMEM\n");
break;
}
case -ENODEV: {
SAY("ENODEV\n"); break;
break;
}
case -ENXIO: {
SAY("ENXIO\n"); break;
SAM("-ENXIO\n");
break;
}
case -EINVAL: {
SAY("EINVAL\n"); break;
SAM("-EINVAL\n");
break;
}
case -EAGAIN: {
SAY("EAGAIN\n"); break;
SAM("-EAGAIN\n");
break;
}
case -EFBIG: {
SAY("EFBIG\n"); break;
SAM("-EFBIG\n");
break;
}
case -EPIPE: {
SAY("EPIPE\n"); break;
SAM("-EPIPE\n");
break;
}
case -EMSGSIZE: {
SAY("EMSGSIZE\n"); break;
SAM("-EMSGSIZE\n");
break;
}
case -ENOSPC: {
SAY("ENOSPC\n"); break;
SAM("-ENOSPC\n");
break;
}
default: {
SAY("0x%08X\n", rc); break;
SAM("unknown error: 0x%08X\n", rc);
break;
}
}
}
@ -529,8 +586,7 @@ return;
/*
* THE AUDIO URBS ARE SUBMITTED AT THIS EARLY STAGE SO THAT IT IS POSSIBLE TO
* STREAM FROM /dev/easysnd1 WITH SIMPLE PROGRAMS SUCH AS cat WHICH DO NOT
* HAVE AN IOCTL INTERFACE. THE VIDEO URBS, BY CONTRAST, MUST BE SUBMITTED
* MUCH LATER: SEE COMMENTS IN FILE easycap_main.c.
* HAVE AN IOCTL INTERFACE.
*/
/*---------------------------------------------------------------------------*/
int
@ -540,7 +596,7 @@ struct usb_interface *pusb_interface;
struct easycap *peasycap;
int subminor, rc;
JOT(4, "begins.\n");
JOT(4, "begins\n");
subminor = iminor(inode);
@ -561,56 +617,54 @@ file->private_data = peasycap;
/*---------------------------------------------------------------------------*/
/*
* INITIALIZATION.
* INITIALIZATION
*/
/*---------------------------------------------------------------------------*/
JOT(4, "starting initialization\n");
JOM(4, "starting initialization\n");
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device is NULL\n");
SAM("ERROR: peasycap->pusb_device is NULL\n");
return -EFAULT;
} else {
JOT(16, "0x%08lX=peasycap->pusb_device\n", \
(long int)peasycap->pusb_device);
}
JOM(16, "0x%08lX=peasycap->pusb_device\n", (long int)peasycap->pusb_device);
rc = audio_setup(peasycap);
if (0 <= rc)
JOT(8, "audio_setup() returned %i\n", rc);
JOM(8, "audio_setup() returned %i\n", rc);
else
JOT(8, "easysnd open(): ERROR: audio_setup() returned %i\n", rc);
JOM(8, "easysnd open(): ERROR: audio_setup() returned %i\n", rc);
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device has become NULL\n");
SAM("ERROR: peasycap->pusb_device has become NULL\n");
return -EFAULT;
}
rc = adjust_volume(peasycap, -8192);
if (0 != rc) {
SAY("ERROR: adjust_volume(default) returned %i\n", rc);
SAM("ERROR: adjust_volume(default) returned %i\n", rc);
return -EFAULT;
}
/*---------------------------------------------------------------------------*/
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device has become NULL\n");
SAM("ERROR: peasycap->pusb_device has become NULL\n");
return -EFAULT;
}
rc = usb_set_interface(peasycap->pusb_device, peasycap->audio_interface, \
peasycap->audio_altsetting_on);
JOT(8, "usb_set_interface(.,%i,%i) returned %i\n", peasycap->audio_interface, \
JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", peasycap->audio_interface, \
peasycap->audio_altsetting_on, rc);
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device has become NULL\n");
SAM("ERROR: peasycap->pusb_device has become NULL\n");
return -EFAULT;
}
rc = wakeup_device(peasycap->pusb_device);
if (0 == rc)
JOT(8, "wakeup_device() returned %i\n", rc);
JOM(8, "wakeup_device() returned %i\n", rc);
else
JOT(8, "easysnd open(): ERROR: wakeup_device() returned %i\n", rc);
JOM(8, "easysnd open(): ERROR: wakeup_device() returned %i\n", rc);
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device has become NULL\n");
SAM("ERROR: peasycap->pusb_device has become NULL\n");
return -EFAULT;
}
submit_audio_urbs(peasycap);
@ -619,7 +673,7 @@ peasycap->audio_idle = 0;
peasycap->timeval1.tv_sec = 0;
peasycap->timeval1.tv_usec = 0;
JOT(4, "finished initialization\n");
JOM(4, "finished initialization\n");
return 0;
}
/*****************************************************************************/
@ -636,10 +690,10 @@ if (NULL == peasycap) {
return -EFAULT;
}
if (0 != kill_audio_urbs(peasycap)) {
SAY("ERROR: kill_audio_urbs() failed\n");
SAM("ERROR: kill_audio_urbs() failed\n");
return -EFAULT;
}
JOT(4, "ending successfully\n");
JOM(4, "ending successfully\n");
return 0;
}
/*****************************************************************************/
@ -648,8 +702,7 @@ easysnd_read(struct file *file, char __user *puserspacebuffer, \
size_t kount, loff_t *poff)
{
struct timeval timeval;
static struct timeval timeval1;
static long long int audio_bytes, above, below, mean;
long long int above, below, mean;
struct signed_div_result sdr;
unsigned char *p0;
long int kount1, more, rc, l0, lm;
@ -679,15 +732,15 @@ if (NULL == peasycap) {
/*---------------------------------------------------------------------------*/
if ((0 > peasycap->audio_read) || \
(peasycap->audio_buffer_page_many <= peasycap->audio_read)) {
SAY("ERROR: peasycap->audio_read out of range\n");
SAM("ERROR: peasycap->audio_read out of range\n");
return -EFAULT;
}
pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
if ((struct data_buffer *)NULL == pdata_buffer) {
SAY("ERROR: pdata_buffer is NULL\n");
SAM("ERROR: pdata_buffer is NULL\n");
return -EFAULT;
}
JOT(12, "before wait, %i=frag read %i=frag fill\n", \
JOM(12, "before wait, %i=frag read %i=frag fill\n", \
(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);
@ -695,7 +748,7 @@ 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");
JOM(16, "returning -EAGAIN as instructed\n");
return -EAGAIN;
}
rc = wait_event_interruptible(peasycap->wq_audio, \
@ -704,50 +757,50 @@ while ((fragment == (peasycap->audio_fill / \
peasycap->audio_pages_per_fragment)) && \
(0 < (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo))))));
if (0 != rc) {
SAY("aborted by signal\n");
SAM("aborted by signal\n");
return -ERESTARTSYS;
}
if (peasycap->audio_eof) {
JOT(8, "returning 0 because %i=audio_eof\n", \
JOM(8, "returning 0 because %i=audio_eof\n", \
peasycap->audio_eof);
kill_audio_urbs(peasycap);
msleep(500);
return 0;
}
if (peasycap->audio_idle) {
JOT(16, "returning 0 because %i=audio_idle\n", \
JOM(16, "returning 0 because %i=audio_idle\n", \
peasycap->audio_idle);
return 0;
}
if (!peasycap->audio_isoc_streaming) {
JOT(16, "returning 0 because audio urbs not streaming\n");
JOM(16, "returning 0 because audio urbs not streaming\n");
return 0;
}
}
JOT(12, "after wait, %i=frag read %i=frag fill\n", \
JOM(12, "after wait, %i=frag read %i=frag fill\n", \
(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 / \
peasycap->audio_pages_per_fragment)) {
if (NULL == pdata_buffer->pgo) {
SAY("ERROR: pdata_buffer->pgo is NULL\n");
SAM("ERROR: pdata_buffer->pgo is NULL\n");
return -EFAULT;
}
if (NULL == pdata_buffer->pto) {
SAY("ERROR: pdata_buffer->pto is NULL\n");
SAM("ERROR: pdata_buffer->pto is NULL\n");
return -EFAULT;
}
kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
if (0 > kount1) {
SAY("easysnd_read: MISTAKE: kount1 is negative\n");
SAM("easysnd_read: MISTAKE: kount1 is negative\n");
return -ERESTARTSYS;
}
if (!kount1) {
(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", \
JOM(12, "bumped peasycap->audio_read to %i\n", \
peasycap->audio_read);
if (fragment != (peasycap->audio_read / \
@ -757,30 +810,30 @@ while (fragment == (peasycap->audio_read / \
if ((0 > peasycap->audio_read) || \
(peasycap->audio_buffer_page_many <= \
peasycap->audio_read)) {
SAY("ERROR: peasycap->audio_read out of range\n");
SAM("ERROR: peasycap->audio_read out of range\n");
return -EFAULT;
}
pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
if ((struct data_buffer *)NULL == pdata_buffer) {
SAY("ERROR: pdata_buffer is NULL\n");
SAM("ERROR: pdata_buffer is NULL\n");
return -EFAULT;
}
if (NULL == pdata_buffer->pgo) {
SAY("ERROR: pdata_buffer->pgo is NULL\n");
SAM("ERROR: pdata_buffer->pgo is NULL\n");
return -EFAULT;
}
if (NULL == pdata_buffer->pto) {
SAY("ERROR: pdata_buffer->pto is NULL\n");
SAM("ERROR: pdata_buffer->pto is NULL\n");
return -EFAULT;
}
kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
}
JOT(12, "ready to send %li bytes\n", (long int) kount1);
JOT(12, "still to send %li bytes\n", (long int) kount);
JOM(12, "ready to send %li bytes\n", (long int) kount1);
JOM(12, "still to send %li bytes\n", (long int) kount);
more = kount1;
if (more > kount)
more = kount;
JOT(12, "agreed to send %li bytes from page %i\n", \
JOM(12, "agreed to send %li bytes from page %i\n", \
more, peasycap->audio_read);
if (!more)
break;
@ -798,7 +851,7 @@ while (fragment == (peasycap->audio_read / \
/*---------------------------------------------------------------------------*/
rc = copy_to_user(puserspacebuffer, pdata_buffer->pto, more);
if (0 != rc) {
SAY("ERROR: copy_to_user() returned %li\n", rc);
SAM("ERROR: copy_to_user() returned %li\n", rc);
return -EFAULT;
}
*poff += (loff_t)more;
@ -807,11 +860,11 @@ while (fragment == (peasycap->audio_read / \
puserspacebuffer += more;
kount -= (size_t)more;
}
JOT(12, "after read, %i=frag read %i=frag fill\n", \
JOM(12, "after read, %i=frag read %i=frag fill\n", \
(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", \
SAM("MISTAKE: %li=kount %li=szret\n", \
(long int)kount, (long int)szret);
}
/*---------------------------------------------------------------------------*/
@ -827,11 +880,11 @@ if (peasycap->audio_sample) {
mean = peasycap->audio_niveau;
sdr = signed_div(mean, peasycap->audio_sample);
JOT(8, "%8lli=mean %8lli=meansquare after %lli samples, =>\n", \
JOM(8, "%8lli=mean %8lli=meansquare after %lli samples, =>\n", \
sdr.quotient, above, peasycap->audio_sample);
sdr = signed_div(above, 32768);
JOT(8, "audio dynamic range is roughly %lli\n", sdr.quotient);
JOM(8, "audio dynamic range is roughly %lli\n", sdr.quotient);
}
/*---------------------------------------------------------------------------*/
/*
@ -840,26 +893,27 @@ if (peasycap->audio_sample) {
/*---------------------------------------------------------------------------*/
do_gettimeofday(&timeval);
if (!peasycap->timeval1.tv_sec) {
audio_bytes = 0;
timeval1 = timeval;
peasycap->timeval1 = timeval1;
peasycap->audio_bytes = 0;
peasycap->timeval3 = timeval;
peasycap->timeval1 = peasycap->timeval3;
sdr.quotient = 192000;
} else {
audio_bytes += (long long int) szret;
peasycap->audio_bytes += (long long int) szret;
below = ((long long int)(1000000)) * \
((long long int)(timeval.tv_sec - timeval1.tv_sec)) + \
(long long int)(timeval.tv_usec - timeval1.tv_usec);
above = 1000000 * ((long long int) audio_bytes);
((long long int)(timeval.tv_sec - \
peasycap->timeval3.tv_sec)) + \
(long long int)(timeval.tv_usec - peasycap->timeval3.tv_usec);
above = 1000000 * ((long long int) peasycap->audio_bytes);
if (below)
sdr = signed_div(above, below);
else
sdr.quotient = 192000;
}
JOT(8, "audio streaming at %lli bytes/second\n", sdr.quotient);
JOM(8, "audio streaming at %lli bytes/second\n", sdr.quotient);
peasycap->dnbydt = sdr.quotient;
JOT(8, "returning %li\n", (long int)szret);
JOM(8, "returning %li\n", (long int)szret);
return szret;
}
/*****************************************************************************/
@ -874,27 +928,31 @@ submit_audio_urbs(struct easycap *peasycap)
struct data_urb *pdata_urb;
struct urb *purb;
struct list_head *plist_head;
int j, isbad, m, rc;
int j, isbad, nospc, m, rc;
int isbuf;
if (NULL == peasycap) {
SAY("ERROR: peasycap is NULL\n");
return -EFAULT;
}
if ((struct list_head *)NULL == peasycap->purb_audio_head) {
SAY("ERROR: peasycap->urb_audio_head uninitialized\n");
SAM("ERROR: peasycap->urb_audio_head uninitialized\n");
return -EFAULT;
}
if ((struct usb_device *)NULL == peasycap->pusb_device) {
SAY("ERROR: peasycap->pusb_device is NULL\n");
SAM("ERROR: peasycap->pusb_device is NULL\n");
return -EFAULT;
}
if (!peasycap->audio_isoc_streaming) {
JOT(4, "initial submission of all audio urbs\n");
JOM(4, "initial submission of all audio urbs\n");
rc = usb_set_interface(peasycap->pusb_device,
peasycap->audio_interface, \
peasycap->audio_altsetting_on);
JOT(8, "usb_set_interface(.,%i,%i) returned %i\n", \
JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", \
peasycap->audio_interface, \
peasycap->audio_altsetting_on, rc);
isbad = 0; m = 0;
isbad = 0; nospc = 0; m = 0;
list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb, list_head);
if (NULL != pdata_urb) {
@ -931,39 +989,49 @@ if (!peasycap->audio_isoc_streaming) {
rc = usb_submit_urb(purb, GFP_KERNEL);
if (0 != rc) {
isbad++;
SAY("ERROR: usb_submit_urb() failed" \
SAM("ERROR: usb_submit_urb() failed" \
" for urb with rc:\n");
switch (rc) {
case -ENOMEM: {
SAY("ENOMEM\n"); break;
SAM("-ENOMEM\n");
break;
}
case -ENODEV: {
SAY("ENODEV\n"); break;
SAM("-ENODEV\n");
break;
}
case -ENXIO: {
SAY("ENXIO\n"); break;
SAM("-ENXIO\n");
break;
}
case -EINVAL: {
SAY("EINVAL\n"); break;
SAM("-EINVAL\n");
break;
}
case -EAGAIN: {
SAY("EAGAIN\n"); break;
SAM("-EAGAIN\n");
break;
}
case -EFBIG: {
SAY("EFBIG\n"); break;
SAM("-EFBIG\n");
break;
}
case -EPIPE: {
SAY("EPIPE\n"); break;
SAM("-EPIPE\n");
break;
}
case -EMSGSIZE: {
SAY("EMSGSIZE\n"); break;
SAM("-EMSGSIZE\n");
break;
}
case -ENOSPC: {
SAY("ENOSPC\n"); break;
nospc++;
break;
}
default: {
SAY("unknown error code %i\n",\
rc); break;
SAM("unknown error code %i\n",\
rc);
break;
}
}
} else {
@ -976,8 +1044,13 @@ if (!peasycap->audio_isoc_streaming) {
isbad++;
}
}
if (nospc) {
SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
SAM("..... possibly inadequate USB bandwidth\n");
peasycap->audio_eof = 1;
}
if (isbad) {
JOT(4, "attempting cleanup instead of submitting\n");
JOM(4, "attempting cleanup instead of submitting\n");
list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb, \
list_head);
@ -990,10 +1063,10 @@ if (!peasycap->audio_isoc_streaming) {
peasycap->audio_isoc_streaming = 0;
} else {
peasycap->audio_isoc_streaming = 1;
JOT(4, "submitted %i audio urbs\n", m);
JOM(4, "submitted %i audio urbs\n", m);
}
} else
JOT(4, "already streaming audio urbs\n");
JOM(4, "already streaming audio urbs\n");
return 0;
}
@ -1010,10 +1083,14 @@ int m;
struct list_head *plist_head;
struct data_urb *pdata_urb;
if (NULL == peasycap) {
SAY("ERROR: peasycap is NULL\n");
return -EFAULT;
}
if (peasycap->audio_isoc_streaming) {
if ((struct list_head *)NULL != peasycap->purb_audio_head) {
peasycap->audio_isoc_streaming = 0;
JOT(4, "killing audio urbs\n");
JOM(4, "killing audio urbs\n");
m = 0;
list_for_each(plist_head, (peasycap->purb_audio_head)) {
pdata_urb = list_entry(plist_head, struct data_urb,
@ -1025,13 +1102,13 @@ if (peasycap->audio_isoc_streaming) {
}
}
}
JOT(4, "%i audio urbs killed\n", m);
JOM(4, "%i audio urbs killed\n", m);
} else {
SAY("ERROR: peasycap->purb_audio_head is NULL\n");
SAM("ERROR: peasycap->purb_audio_head is NULL\n");
return -EFAULT;
}
} else {
JOT(8, "%i=audio_isoc_streaming, no audio urbs killed\n", \
JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n", \
peasycap->audio_isoc_streaming);
}
return 0;

View file

@ -157,7 +157,7 @@ for (i1 = 0; i1 <= last; i1++)
printf("%6i, ", i2); printf("%6i\n};\n", i2);
}
}
return(0);
return 0;
}
-----------------------------------------------------------------------------*/
int tones[2048] = {