1 /******************************************************************************
5 * Audio driver for EasyCAP USB2.0 Video Capture Device DC60 *
8 ******************************************************************************/
11 * Copyright (C) 2010 R.M. Thomas <rmthomas@sciolus.org>
14 * This is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * The software is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this software; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /*****************************************************************************/
32 #include "easycap_sound.h"
34 #if defined(EASYCAP_NEEDS_ALSA)
35 /*--------------------------------------------------------------------------*/
37 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE
39 /*--------------------------------------------------------------------------*/
40 static const struct snd_pcm_hardware alsa_hardware = {
41 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
43 SNDRV_PCM_INFO_INTERLEAVED |
44 SNDRV_PCM_INFO_MMAP_VALID,
45 .formats = SNDRV_PCM_FMTBIT_S16_LE,
46 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000,
51 .buffer_bytes_max = PAGE_SIZE * PAGES_PER_AUDIO_FRAGMENT *
53 .period_bytes_min = PAGE_SIZE * PAGES_PER_AUDIO_FRAGMENT,
54 .period_bytes_max = PAGE_SIZE * PAGES_PER_AUDIO_FRAGMENT * 2,
55 .periods_min = AUDIO_FRAGMENT_MANY,
56 .periods_max = AUDIO_FRAGMENT_MANY * 2,
59 static struct snd_pcm_ops easycap_alsa_pcm_ops = {
60 .open = easycap_alsa_open,
61 .close = easycap_alsa_close,
62 .ioctl = snd_pcm_lib_ioctl,
63 .hw_params = easycap_alsa_hw_params,
64 .hw_free = easycap_alsa_hw_free,
65 .prepare = easycap_alsa_prepare,
66 .ack = easycap_alsa_ack,
67 .trigger = easycap_alsa_trigger,
68 .pointer = easycap_alsa_pointer,
69 .page = easycap_alsa_page,
72 /*****************************************************************************/
73 /*---------------------------------------------------------------------------*/
75 * THE FUNCTION snd_card_create() HAS THIS_MODULE AS AN ARGUMENT. THIS
76 * MEANS MODULE easycap. BEWARE.
78 /*---------------------------------------------------------------------------*/
80 easycap_alsa_probe(struct easycap *peasycap)
83 struct snd_card *psnd_card;
84 struct snd_pcm *psnd_pcm;
86 if (NULL == peasycap) {
87 SAY("ERROR: peasycap is NULL\n");
90 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
91 SAY("ERROR: bad peasycap\n");
94 if (0 > peasycap->minor) {
95 SAY("ERROR: no minor\n");
99 peasycap->alsa_hardware = alsa_hardware;
100 if (true == peasycap->microphone) {
101 peasycap->alsa_hardware.rates = SNDRV_PCM_RATE_32000;
102 peasycap->alsa_hardware.rate_min = 32000;
103 peasycap->alsa_hardware.rate_max = 32000;
105 peasycap->alsa_hardware.rates = SNDRV_PCM_RATE_48000;
106 peasycap->alsa_hardware.rate_min = 48000;
107 peasycap->alsa_hardware.rate_max = 48000;
110 if (0 != snd_card_create(SNDRV_DEFAULT_IDX1, "easycap_alsa",
113 SAY("ERROR: Cannot do ALSA snd_card_create()\n");
117 sprintf(&psnd_card->id[0], "EasyALSA%i", peasycap->minor);
118 strcpy(&psnd_card->driver[0], EASYCAP_DRIVER_DESCRIPTION);
119 strcpy(&psnd_card->shortname[0], "easycap_alsa");
120 sprintf(&psnd_card->longname[0], "%s", &psnd_card->shortname[0]);
122 psnd_card->dev = &peasycap->pusb_device->dev;
123 psnd_card->private_data = peasycap;
124 peasycap->psnd_card = psnd_card;
126 rc = snd_pcm_new(psnd_card, "easycap_pcm", 0, 0, 1, &psnd_pcm);
128 SAM("ERROR: Cannot do ALSA snd_pcm_new()\n");
129 snd_card_free(psnd_card);
133 snd_pcm_set_ops(psnd_pcm, SNDRV_PCM_STREAM_CAPTURE,
134 &easycap_alsa_pcm_ops);
135 psnd_pcm->info_flags = 0;
136 strcpy(&psnd_pcm->name[0], &psnd_card->id[0]);
137 psnd_pcm->private_data = peasycap;
138 peasycap->psnd_pcm = psnd_pcm;
139 peasycap->psubstream = (struct snd_pcm_substream *)NULL;
141 rc = snd_card_register(psnd_card);
143 SAM("ERROR: Cannot do ALSA snd_card_register()\n");
144 snd_card_free(psnd_card);
148 SAM("registered %s\n", &psnd_card->id[0]);
152 /*****************************************************************************/
153 /*---------------------------------------------------------------------------*/
155 * ON COMPLETION OF AN AUDIO URB ITS DATA IS COPIED TO THE DAM BUFFER
156 * PROVIDED peasycap->audio_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
157 * IT IS RESUBMITTED PROVIDED peasycap->audio_isoc_streaming IS NOT ZERO.
159 /*---------------------------------------------------------------------------*/
161 easycap_alsa_complete(struct urb *purb)
163 struct easycap *peasycap;
164 struct snd_pcm_substream *pss;
165 struct snd_pcm_runtime *prt;
166 int dma_bytes, fragment_bytes;
170 int i, j, more, much, rc;
171 #if defined(UPSAMPLE)
173 __s16 oldaudio, newaudio, delta;
179 SAY("ERROR: purb is NULL\n");
182 peasycap = purb->context;
183 if (NULL == peasycap) {
184 SAY("ERROR: peasycap is NULL\n");
187 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
188 SAY("ERROR: bad peasycap\n");
192 if (peasycap->audio_idle) {
193 JOM(16, "%i=audio_idle %i=audio_isoc_streaming\n",
194 peasycap->audio_idle, peasycap->audio_isoc_streaming);
195 if (peasycap->audio_isoc_streaming)
198 /*---------------------------------------------------------------------------*/
199 pss = peasycap->psubstream;
205 dma_bytes = (int)prt->dma_bytes;
208 fragment_bytes = 4 * ((int)prt->period_size);
209 if (0 == fragment_bytes)
211 /* -------------------------------------------------------------------------*/
213 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
214 JOM(16, "urb status -ESHUTDOWN or -ENOENT\n");
217 SAM("ERROR: non-zero urb status:\n");
218 switch (purb->status) {
220 SAM("-EINPROGRESS\n");
252 SAM("-EOPNOTSUPP\n");
255 case -EPFNOSUPPORT: {
256 SAM("-EPFNOSUPPORT\n");
259 case -EAFNOSUPPORT: {
260 SAM("-EAFNOSUPPORT\n");
264 SAM("-EADDRINUSE\n");
267 case -EADDRNOTAVAIL: {
268 SAM("-EADDRNOTAVAIL\n");
292 SAM("-ECONNRESET\n");
300 SAM("unknown error: %i\n", purb->status);
306 /*---------------------------------------------------------------------------*/
308 * PROCEED HERE WHEN NO ERROR
310 /*---------------------------------------------------------------------------*/
312 #if defined(UPSAMPLE)
313 oldaudio = peasycap->oldaudio;
316 for (i = 0; i < purb->number_of_packets; i++) {
317 switch (purb->iso_frame_desc[i].status) {
326 SAM("-EINPROGRESS\n");
378 SAM("-ECONNRESET\n");
394 SAM("unknown error: %i\n", purb->iso_frame_desc[i].status);
398 if (!purb->iso_frame_desc[i].status) {
399 more = purb->iso_frame_desc[i].actual_length;
401 peasycap->audio_mt++;
403 if (peasycap->audio_mt) {
404 JOM(12, "%4i empty audio urb frames\n",
406 peasycap->audio_mt = 0;
409 p1 = (__u8 *)(purb->transfer_buffer +
410 purb->iso_frame_desc[i].offset);
412 /*---------------------------------------------------------------------------*/
414 * COPY more BYTES FROM ISOC BUFFER TO THE DMA BUFFER,
415 * CONVERTING 8-BIT MONO TO 16-BIT SIGNED LITTLE-ENDIAN SAMPLES IF NECESSARY
417 /*---------------------------------------------------------------------------*/
420 SAM("MISTAKE: more is negative\n");
423 much = dma_bytes - peasycap->dma_fill;
425 SAM("MISTAKE: much is negative\n");
429 peasycap->dma_fill = 0;
430 peasycap->dma_next = fragment_bytes;
431 JOM(8, "wrapped dma buffer\n");
433 if (false == peasycap->microphone) {
436 memcpy(prt->dma_area +
442 #if defined(UPSAMPLE)
444 JOM(8, "MISTAKE? much"
445 " is not divisible by 16\n");
450 p2 = (__u8 *)(prt->dma_area +
453 for (j = 0; j < (much/16); j++) {
454 newaudio = ((int) *p1) - 128;
458 delta = (newaudio - oldaudio)
460 s16 = oldaudio + delta;
462 for (k = 0; k < 4; k++) {
463 *p2 = (0x00FF & s16);
464 *(p2 + 1) = (0xFF00 &
467 *p2 = (0x00FF & s16);
468 *(p2 + 1) = (0xFF00 &
478 if (much > (2 * more))
480 p2 = (__u8 *)(prt->dma_area +
483 for (j = 0; j < (much / 2); j++) {
484 s16 = ((int) *p1) - 128;
487 *p2 = (0x00FF & s16);
488 *(p2 + 1) = (0xFF00 & s16) >>
495 peasycap->dma_fill += much;
496 if (peasycap->dma_fill >= peasycap->dma_next) {
497 isfragment = peasycap->dma_fill /
499 if (0 > isfragment) {
500 SAM("MISTAKE: isfragment is "
504 peasycap->dma_read = (isfragment
505 - 1) * fragment_bytes;
506 peasycap->dma_next = (isfragment
507 + 1) * fragment_bytes;
508 if (dma_bytes < peasycap->dma_next) {
512 if (0 <= peasycap->dma_read) {
513 JOM(8, "snd_pcm_period_elap"
517 snd_pcm_period_elapsed(pss);
523 JOM(12, "discarding audio samples because "
524 "%i=purb->iso_frame_desc[i].status\n",
525 purb->iso_frame_desc[i].status);
528 #if defined(UPSAMPLE)
529 peasycap->oldaudio = oldaudio;
533 /*---------------------------------------------------------------------------*/
537 /*---------------------------------------------------------------------------*/
539 if (peasycap->audio_isoc_streaming) {
540 rc = usb_submit_urb(purb, GFP_ATOMIC);
542 if ((-ENODEV != rc) && (-ENOENT != rc)) {
543 SAM("ERROR: while %i=audio_idle, "
544 "usb_submit_urb() failed "
545 "with rc:\n", peasycap->audio_idle);
588 SAM("unknown error: %i\n", rc);
592 if (0 < peasycap->audio_isoc_streaming)
593 (peasycap->audio_isoc_streaming)--;
598 /*****************************************************************************/
600 easycap_alsa_open(struct snd_pcm_substream *pss)
602 struct snd_pcm *psnd_pcm;
603 struct snd_card *psnd_card;
604 struct easycap *peasycap;
608 SAY("ERROR: pss is NULL\n");
612 if (NULL == psnd_pcm) {
613 SAY("ERROR: psnd_pcm is NULL\n");
616 psnd_card = psnd_pcm->card;
617 if (NULL == psnd_card) {
618 SAY("ERROR: psnd_card is NULL\n");
622 peasycap = psnd_card->private_data;
623 if (NULL == peasycap) {
624 SAY("ERROR: peasycap is NULL\n");
627 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
628 SAY("ERROR: bad peasycap\n");
631 if (peasycap->psnd_card != psnd_card) {
632 SAM("ERROR: bad peasycap->psnd_card\n");
635 if (NULL != peasycap->psubstream) {
636 SAM("ERROR: bad peasycap->psubstream\n");
639 pss->private_data = peasycap;
640 peasycap->psubstream = pss;
641 pss->runtime->hw = peasycap->alsa_hardware;
642 pss->runtime->private_data = peasycap;
643 pss->private_data = peasycap;
645 if (0 != easycap_sound_setup(peasycap)) {
646 JOM(4, "ending unsuccessfully\n");
649 JOM(4, "ending successfully\n");
652 /*****************************************************************************/
654 easycap_alsa_close(struct snd_pcm_substream *pss)
656 struct easycap *peasycap;
660 SAY("ERROR: pss is NULL\n");
663 peasycap = snd_pcm_substream_chip(pss);
664 if (NULL == peasycap) {
665 SAY("ERROR: peasycap is NULL\n");
668 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
669 SAY("ERROR: bad peasycap\n");
672 pss->private_data = NULL;
673 peasycap->psubstream = (struct snd_pcm_substream *)NULL;
674 JOT(4, "ending successfully\n");
677 /*****************************************************************************/
679 easycap_alsa_hw_params(struct snd_pcm_substream *pss,
680 struct snd_pcm_hw_params *phw)
684 JOT(4, "%i\n", (params_buffer_bytes(phw)));
686 SAY("ERROR: pss is NULL\n");
689 rc = easycap_alsa_vmalloc(pss, params_buffer_bytes(phw));
694 /*****************************************************************************/
696 easycap_alsa_vmalloc(struct snd_pcm_substream *pss, size_t sz)
698 struct snd_pcm_runtime *prt;
702 SAY("ERROR: pss is NULL\n");
707 SAY("ERROR: substream.runtime is NULL\n");
711 if (prt->dma_bytes > sz)
713 vfree(prt->dma_area);
715 prt->dma_area = vmalloc(sz);
716 if (NULL == prt->dma_area)
721 /*****************************************************************************/
723 easycap_alsa_hw_free(struct snd_pcm_substream *pss)
725 struct snd_pcm_runtime *prt;
729 SAY("ERROR: pss is NULL\n");
734 SAY("ERROR: substream.runtime is NULL\n");
737 if (NULL != prt->dma_area) {
738 JOT(8, "0x%08lX=prt->dma_area\n", (unsigned long int)prt->dma_area);
739 vfree(prt->dma_area);
740 prt->dma_area = NULL;
742 JOT(8, "dma_area already freed\n");
745 /*****************************************************************************/
747 easycap_alsa_prepare(struct snd_pcm_substream *pss)
749 struct easycap *peasycap;
750 struct snd_pcm_runtime *prt;
754 SAY("ERROR: pss is NULL\n");
758 peasycap = snd_pcm_substream_chip(pss);
759 if (NULL == peasycap) {
760 SAY("ERROR: peasycap is NULL\n");
763 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
764 SAY("ERROR: bad peasycap\n");
768 JOM(16, "ALSA decides %8i Hz=rate\n", (int)pss->runtime->rate);
769 JOM(16, "ALSA decides %8i =period_size\n", (int)pss->runtime->period_size);
770 JOM(16, "ALSA decides %8i =periods\n", (int)pss->runtime->periods);
771 JOM(16, "ALSA decides %8i =buffer_size\n", (int)pss->runtime->buffer_size);
772 JOM(16, "ALSA decides %8i =dma_bytes\n", (int)pss->runtime->dma_bytes);
773 JOM(16, "ALSA decides %8i =boundary\n", (int)pss->runtime->boundary);
774 JOM(16, "ALSA decides %8i =period_step\n", (int)pss->runtime->period_step);
775 JOM(16, "ALSA decides %8i =sample_bits\n", (int)pss->runtime->sample_bits);
776 JOM(16, "ALSA decides %8i =frame_bits\n", (int)pss->runtime->frame_bits);
777 JOM(16, "ALSA decides %8i =min_align\n", (int)pss->runtime->min_align);
778 JOM(12, "ALSA decides %8i =hw_ptr_base\n", (int)pss->runtime->hw_ptr_base);
779 JOM(12, "ALSA decides %8i =hw_ptr_interrupt\n",
780 (int)pss->runtime->hw_ptr_interrupt);
781 if (prt->dma_bytes != 4 * ((int)prt->period_size) * ((int)prt->periods)) {
782 SAY("MISTAKE: unexpected ALSA parameters\n");
787 /*****************************************************************************/
789 easycap_alsa_ack(struct snd_pcm_substream *pss)
793 /*****************************************************************************/
795 easycap_alsa_trigger(struct snd_pcm_substream *pss, int cmd)
797 struct easycap *peasycap;
800 JOT(4, "%i=cmd cf %i=START %i=STOP\n", cmd, SNDRV_PCM_TRIGGER_START,
801 SNDRV_PCM_TRIGGER_STOP);
803 SAY("ERROR: pss is NULL\n");
806 peasycap = snd_pcm_substream_chip(pss);
807 if (NULL == peasycap) {
808 SAY("ERROR: peasycap is NULL\n");
811 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
812 SAY("ERROR: bad peasycap\n");
817 case SNDRV_PCM_TRIGGER_START: {
818 peasycap->audio_idle = 0;
821 case SNDRV_PCM_TRIGGER_STOP: {
822 peasycap->audio_idle = 1;
830 /*****************************************************************************/
832 easycap_alsa_pointer(struct snd_pcm_substream *pss)
834 struct easycap *peasycap;
835 snd_pcm_uframes_t offset;
839 SAY("ERROR: pss is NULL\n");
842 peasycap = snd_pcm_substream_chip(pss);
843 if (NULL == peasycap) {
844 SAY("ERROR: peasycap is NULL\n");
847 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
848 SAY("ERROR: bad peasycap\n");
851 if ((0 != peasycap->audio_eof) || (0 != peasycap->audio_idle)) {
852 JOM(8, "returning -EIO because "
853 "%i=audio_idle %i=audio_eof\n",
854 peasycap->audio_idle, peasycap->audio_eof);
857 /*---------------------------------------------------------------------------*/
858 if (0 > peasycap->dma_read) {
859 JOM(8, "returning -EBUSY\n");
862 offset = ((snd_pcm_uframes_t)peasycap->dma_read)/4;
863 JOM(8, "ALSA decides %8i =hw_ptr_base\n", (int)pss->runtime->hw_ptr_base);
864 JOM(8, "ALSA decides %8i =hw_ptr_interrupt\n",
865 (int)pss->runtime->hw_ptr_interrupt);
866 JOM(8, "%7i=offset %7i=dma_read %7i=dma_next\n",
867 (int)offset, peasycap->dma_read, peasycap->dma_next);
870 /*****************************************************************************/
872 easycap_alsa_page(struct snd_pcm_substream *pss, unsigned long offset)
874 return vmalloc_to_page(pss->runtime->dma_area + offset);
876 /*****************************************************************************/
878 #else /*!EASYCAP_NEEDS_ALSA*/
880 /*****************************************************************************/
881 /**************************** **************************/
882 /**************************** Open Sound System **************************/
883 /**************************** **************************/
884 /*****************************************************************************/
885 /*--------------------------------------------------------------------------*/
887 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE
889 /*--------------------------------------------------------------------------*/
890 const struct file_operations easyoss_fops = {
891 .owner = THIS_MODULE,
892 .open = easyoss_open,
893 .release = easyoss_release,
894 #if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
895 .unlocked_ioctl = easyoss_ioctl_noinode,
897 .ioctl = easyoss_ioctl,
898 #endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
899 .read = easyoss_read,
902 struct usb_class_driver easyoss_class = {
903 .name = "usb/easyoss%d",
904 .fops = &easyoss_fops,
905 .minor_base = USB_SKEL_MINOR_BASE,
907 /*****************************************************************************/
908 /*---------------------------------------------------------------------------*/
910 * ON COMPLETION OF AN AUDIO URB ITS DATA IS COPIED TO THE AUDIO BUFFERS
911 * PROVIDED peasycap->audio_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
912 * IT IS RESUBMITTED PROVIDED peasycap->audio_isoc_streaming IS NOT ZERO.
914 /*---------------------------------------------------------------------------*/
916 easyoss_complete(struct urb *purb)
918 struct easycap *peasycap;
919 struct data_buffer *paudio_buffer;
922 int i, j, more, much, leap, rc;
923 #if defined(UPSAMPLE)
925 __s16 oldaudio, newaudio, delta;
931 SAY("ERROR: purb is NULL\n");
934 peasycap = purb->context;
935 if (NULL == peasycap) {
936 SAY("ERROR: peasycap is NULL\n");
939 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
940 SAY("ERROR: bad peasycap\n");
944 if (peasycap->audio_idle) {
945 JOM(16, "%i=audio_idle %i=audio_isoc_streaming\n",
946 peasycap->audio_idle, peasycap->audio_isoc_streaming);
947 if (peasycap->audio_isoc_streaming) {
948 rc = usb_submit_urb(purb, GFP_ATOMIC);
950 if (-ENODEV != rc && -ENOENT != rc) {
951 SAM("ERROR: while %i=audio_idle, "
952 "usb_submit_urb() failed with rc:\n",
953 peasycap->audio_idle);
996 SAM("unknown error: %i\n", rc);
1004 /*---------------------------------------------------------------------------*/
1006 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
1007 JOM(16, "urb status -ESHUTDOWN or -ENOENT\n");
1010 SAM("ERROR: non-zero urb status:\n");
1011 switch (purb->status) {
1012 case -EINPROGRESS: {
1013 SAM("-EINPROGRESS\n");
1025 SAM("-EOVERFLOW\n");
1037 SAM("-ETIMEDOUT\n");
1045 SAM("-EOPNOTSUPP\n");
1048 case -EPFNOSUPPORT: {
1049 SAM("-EPFNOSUPPORT\n");
1052 case -EAFNOSUPPORT: {
1053 SAM("-EAFNOSUPPORT\n");
1057 SAM("-EADDRINUSE\n");
1060 case -EADDRNOTAVAIL: {
1061 SAM("-EADDRNOTAVAIL\n");
1077 SAM("-ESHUTDOWN\n");
1085 SAM("-ECONNRESET\n");
1097 SAM("unknown error: %i\n", purb->status);
1103 /*---------------------------------------------------------------------------*/
1105 * PROCEED HERE WHEN NO ERROR
1107 /*---------------------------------------------------------------------------*/
1108 #if defined(UPSAMPLE)
1109 oldaudio = peasycap->oldaudio;
1112 for (i = 0; i < purb->number_of_packets; i++) {
1113 switch (purb->iso_frame_desc[i].status) {
1125 case -EINPROGRESS: {
1126 SAM("-EINPROGRESS\n");
1142 SAM("-ETIMEDOUT\n");
1158 SAM("-EOVERFLOW\n");
1162 SAM("-EREMOTEIO\n");
1174 SAM("-ECONNRESET\n");
1182 SAM("-ESHUTDOWN\n");
1190 SAM("unknown error: %i\n", purb->iso_frame_desc[i].status);
1194 if (!purb->iso_frame_desc[i].status) {
1195 more = purb->iso_frame_desc[i].actual_length;
1197 #if defined(TESTTONE)
1199 more = purb->iso_frame_desc[i].length;
1203 peasycap->audio_mt++;
1205 if (peasycap->audio_mt) {
1206 JOM(12, "%4i empty audio urb frames\n",
1207 peasycap->audio_mt);
1208 peasycap->audio_mt = 0;
1211 p1 = (__u8 *)(purb->transfer_buffer +
1212 purb->iso_frame_desc[i].offset);
1217 /*---------------------------------------------------------------------------*/
1219 * COPY more BYTES FROM ISOC BUFFER TO AUDIO BUFFER,
1220 * CONVERTING 8-BIT MONO TO 16-BIT SIGNED LITTLE-ENDIAN SAMPLES IF NECESSARY
1222 /*---------------------------------------------------------------------------*/
1225 SAM("MISTAKE: more is negative\n");
1228 if (peasycap->audio_buffer_page_many <=
1229 peasycap->audio_fill) {
1231 "peasycap->audio_fill\n");
1235 paudio_buffer = &peasycap->audio_buffer
1236 [peasycap->audio_fill];
1237 if (PAGE_SIZE < (paudio_buffer->pto -
1238 paudio_buffer->pgo)) {
1239 SAM("ERROR: bad paudio_buffer->pto\n");
1242 if (PAGE_SIZE == (paudio_buffer->pto -
1243 paudio_buffer->pgo)) {
1245 #if defined(TESTTONE)
1246 easyoss_testtone(peasycap,
1247 peasycap->audio_fill);
1250 paudio_buffer->pto =
1252 (peasycap->audio_fill)++;
1254 audio_buffer_page_many <=
1255 peasycap->audio_fill)
1256 peasycap->audio_fill = 0;
1258 JOM(8, "bumped peasycap->"
1259 "audio_fill to %i\n",
1260 peasycap->audio_fill);
1262 paudio_buffer = &peasycap->
1264 [peasycap->audio_fill];
1265 paudio_buffer->pto =
1268 if (!(peasycap->audio_fill %
1270 audio_pages_per_fragment)) {
1271 JOM(12, "wakeup call on wq_"
1272 "audio, %i=frag reading %i"
1274 (peasycap->audio_read /
1276 audio_pages_per_fragment),
1277 (peasycap->audio_fill /
1279 audio_pages_per_fragment));
1280 wake_up_interruptible
1281 (&(peasycap->wq_audio));
1285 much = PAGE_SIZE - (int)(paudio_buffer->pto -
1286 paudio_buffer->pgo);
1288 if (false == peasycap->microphone) {
1292 memcpy(paudio_buffer->pto, p1, much);
1296 #if defined(UPSAMPLE)
1298 JOM(8, "MISTAKE? much"
1299 " is not divisible by 16\n");
1304 p2 = (__u8 *)paudio_buffer->pto;
1306 for (j = 0; j < (much/16); j++) {
1307 newaudio = ((int) *p1) - 128;
1311 delta = (newaudio - oldaudio)
1313 s16 = oldaudio + delta;
1315 for (k = 0; k < 4; k++) {
1316 *p2 = (0x00FF & s16);
1317 *(p2 + 1) = (0xFF00 &
1320 *p2 = (0x00FF & s16);
1321 *(p2 + 1) = (0xFF00 &
1332 if (much > (2 * more))
1334 p2 = (__u8 *)paudio_buffer->pto;
1336 for (j = 0; j < (much / 2); j++) {
1337 s16 = ((int) *p1) - 128;
1340 *p2 = (0x00FF & s16);
1341 *(p2 + 1) = (0xFF00 & s16) >>
1348 (paudio_buffer->pto) += much;
1352 JOM(12, "discarding audio samples because "
1353 "%i=purb->iso_frame_desc[i].status\n",
1354 purb->iso_frame_desc[i].status);
1357 #if defined(UPSAMPLE)
1358 peasycap->oldaudio = oldaudio;
1362 /*---------------------------------------------------------------------------*/
1366 /*---------------------------------------------------------------------------*/
1368 if (peasycap->audio_isoc_streaming) {
1369 rc = usb_submit_urb(purb, GFP_ATOMIC);
1371 if (-ENODEV != rc && -ENOENT != rc) {
1372 SAM("ERROR: while %i=audio_idle, "
1373 "usb_submit_urb() failed "
1374 "with rc:\n", peasycap->audio_idle);
1417 SAM("unknown error: %i\n", rc);
1425 /*****************************************************************************/
1426 /*---------------------------------------------------------------------------*/
1428 * THE AUDIO URBS ARE SUBMITTED AT THIS EARLY STAGE SO THAT IT IS POSSIBLE TO
1429 * STREAM FROM /dev/easyoss1 WITH SIMPLE PROGRAMS SUCH AS cat WHICH DO NOT
1430 * HAVE AN IOCTL INTERFACE.
1432 /*---------------------------------------------------------------------------*/
1434 easyoss_open(struct inode *inode, struct file *file)
1436 struct usb_interface *pusb_interface;
1437 struct easycap *peasycap;
1439 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
1440 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
1441 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
1442 struct v4l2_device *pv4l2_device;
1443 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
1444 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
1445 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
1449 subminor = iminor(inode);
1451 pusb_interface = usb_find_interface(&easycap_usb_driver, subminor);
1452 if (NULL == pusb_interface) {
1453 SAY("ERROR: pusb_interface is NULL\n");
1454 SAY("ending unsuccessfully\n");
1457 peasycap = usb_get_intfdata(pusb_interface);
1458 if (NULL == peasycap) {
1459 SAY("ERROR: peasycap is NULL\n");
1460 SAY("ending unsuccessfully\n");
1463 /*---------------------------------------------------------------------------*/
1464 #if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
1466 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
1468 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
1469 /*---------------------------------------------------------------------------*/
1471 * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS
1472 * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(),
1473 * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE.
1474 * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED.
1476 /*---------------------------------------------------------------------------*/
1477 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1478 pv4l2_device = usb_get_intfdata(pusb_interface);
1479 if ((struct v4l2_device *)NULL == pv4l2_device) {
1480 SAY("ERROR: pv4l2_device is NULL\n");
1483 peasycap = (struct easycap *)
1484 container_of(pv4l2_device, struct easycap, v4l2_device);
1486 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
1488 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
1489 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
1490 /*---------------------------------------------------------------------------*/
1491 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1492 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
1495 /*---------------------------------------------------------------------------*/
1497 file->private_data = peasycap;
1499 if (0 != easycap_sound_setup(peasycap)) {
1505 /*****************************************************************************/
1507 easyoss_release(struct inode *inode, struct file *file)
1509 struct easycap *peasycap;
1513 peasycap = file->private_data;
1514 if (NULL == peasycap) {
1515 SAY("ERROR: peasycap is NULL.\n");
1518 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1519 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
1522 if (0 != kill_audio_urbs(peasycap)) {
1523 SAM("ERROR: kill_audio_urbs() failed\n");
1526 JOM(4, "ending successfully\n");
1529 /*****************************************************************************/
1531 easyoss_read(struct file *file, char __user *puserspacebuffer,
1532 size_t kount, loff_t *poff)
1534 struct timeval timeval;
1535 long long int above, below, mean;
1536 struct signed_div_result sdr;
1538 long int kount1, more, rc, l0, lm;
1540 struct easycap *peasycap;
1541 struct data_buffer *pdata_buffer;
1544 /*---------------------------------------------------------------------------*/
1546 * DO A BLOCKING READ TO TRANSFER DATA TO USER SPACE.
1548 ******************************************************************************
1549 ***** N.B. IF THIS FUNCTION RETURNS 0, NOTHING IS SEEN IN USER SPACE. ******
1550 ***** THIS CONDITION SIGNIFIES END-OF-FILE. ******
1551 ******************************************************************************
1553 /*---------------------------------------------------------------------------*/
1555 JOT(8, "%5i=kount %5i=*poff\n", (int)kount, (int)(*poff));
1558 SAY("ERROR: file is NULL\n");
1559 return -ERESTARTSYS;
1561 peasycap = file->private_data;
1562 if (NULL == peasycap) {
1563 SAY("ERROR in easyoss_read(): peasycap is NULL\n");
1566 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1567 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
1570 if (NULL == peasycap->pusb_device) {
1571 SAY("ERROR: peasycap->pusb_device is NULL\n");
1574 kd = isdongle(peasycap);
1575 if (0 <= kd && DONGLE_MANY > kd) {
1576 if (mutex_lock_interruptible(&(easycapdc60_dongle[kd].mutex_audio))) {
1578 "cannot lock easycapdc60_dongle[%i].mutex_audio\n", kd);
1579 return -ERESTARTSYS;
1581 JOM(4, "locked easycapdc60_dongle[%i].mutex_audio\n", kd);
1582 /*---------------------------------------------------------------------------*/
1584 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER peasycap,
1585 * IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
1586 * IF NECESSARY, BAIL OUT.
1588 /*---------------------------------------------------------------------------*/
1589 if (kd != isdongle(peasycap))
1590 return -ERESTARTSYS;
1592 SAY("ERROR: file is NULL\n");
1593 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1594 return -ERESTARTSYS;
1596 peasycap = file->private_data;
1597 if (NULL == peasycap) {
1598 SAY("ERROR: peasycap is NULL\n");
1599 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1600 return -ERESTARTSYS;
1602 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1603 SAY("ERROR: bad peasycap: 0x%08lX\n",
1604 (unsigned long int) peasycap);
1605 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1606 return -ERESTARTSYS;
1608 if (NULL == peasycap->pusb_device) {
1609 SAM("ERROR: peasycap->pusb_device is NULL\n");
1610 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1611 return -ERESTARTSYS;
1614 /*---------------------------------------------------------------------------*/
1616 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap BEFORE THE
1617 * ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL HAVE FAILED. BAIL OUT.
1619 /*---------------------------------------------------------------------------*/
1620 return -ERESTARTSYS;
1622 /*---------------------------------------------------------------------------*/
1623 if (file->f_flags & O_NONBLOCK)
1624 JOT(16, "NONBLOCK kount=%i, *poff=%i\n", (int)kount, (int)(*poff));
1626 JOT(8, "BLOCKING kount=%i, *poff=%i\n", (int)kount, (int)(*poff));
1628 if ((0 > peasycap->audio_read) ||
1629 (peasycap->audio_buffer_page_many <= peasycap->audio_read)) {
1630 SAM("ERROR: peasycap->audio_read out of range\n");
1631 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1634 pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
1635 if ((struct data_buffer *)NULL == pdata_buffer) {
1636 SAM("ERROR: pdata_buffer is NULL\n");
1637 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1640 JOM(12, "before wait, %i=frag read %i=frag fill\n",
1641 (peasycap->audio_read / peasycap->audio_pages_per_fragment),
1642 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
1643 fragment = (peasycap->audio_read / peasycap->audio_pages_per_fragment);
1644 while ((fragment == (peasycap->audio_fill /
1645 peasycap->audio_pages_per_fragment)) ||
1646 (0 == (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo)))) {
1647 if (file->f_flags & O_NONBLOCK) {
1648 JOM(16, "returning -EAGAIN as instructed\n");
1649 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1652 rc = wait_event_interruptible(peasycap->wq_audio,
1653 (peasycap->audio_idle || peasycap->audio_eof ||
1654 ((fragment != (peasycap->audio_fill /
1655 peasycap->audio_pages_per_fragment)) &&
1656 (0 < (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo))))));
1658 SAM("aborted by signal\n");
1659 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1660 return -ERESTARTSYS;
1662 if (peasycap->audio_eof) {
1663 JOM(8, "returning 0 because %i=audio_eof\n",
1664 peasycap->audio_eof);
1665 kill_audio_urbs(peasycap);
1666 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1669 if (peasycap->audio_idle) {
1670 JOM(16, "returning 0 because %i=audio_idle\n",
1671 peasycap->audio_idle);
1672 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1675 if (!peasycap->audio_isoc_streaming) {
1676 JOM(16, "returning 0 because audio urbs not streaming\n");
1677 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1681 JOM(12, "after wait, %i=frag read %i=frag fill\n",
1682 (peasycap->audio_read / peasycap->audio_pages_per_fragment),
1683 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
1685 fragment = (peasycap->audio_read / peasycap->audio_pages_per_fragment);
1686 while (fragment == (peasycap->audio_read /
1687 peasycap->audio_pages_per_fragment)) {
1688 if (NULL == pdata_buffer->pgo) {
1689 SAM("ERROR: pdata_buffer->pgo is NULL\n");
1690 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1693 if (NULL == pdata_buffer->pto) {
1694 SAM("ERROR: pdata_buffer->pto is NULL\n");
1695 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1698 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
1700 SAM("MISTAKE: kount1 is negative\n");
1701 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1702 return -ERESTARTSYS;
1705 (peasycap->audio_read)++;
1706 if (peasycap->audio_buffer_page_many <= peasycap->audio_read)
1707 peasycap->audio_read = 0;
1708 JOM(12, "bumped peasycap->audio_read to %i\n",
1709 peasycap->audio_read);
1711 if (fragment != (peasycap->audio_read /
1712 peasycap->audio_pages_per_fragment))
1715 if ((0 > peasycap->audio_read) ||
1716 (peasycap->audio_buffer_page_many <=
1717 peasycap->audio_read)) {
1718 SAM("ERROR: peasycap->audio_read out of range\n");
1719 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1722 pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
1723 if ((struct data_buffer *)NULL == pdata_buffer) {
1724 SAM("ERROR: pdata_buffer is NULL\n");
1725 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1728 if (NULL == pdata_buffer->pgo) {
1729 SAM("ERROR: pdata_buffer->pgo is NULL\n");
1730 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1733 if (NULL == pdata_buffer->pto) {
1734 SAM("ERROR: pdata_buffer->pto is NULL\n");
1735 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1738 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
1740 JOM(12, "ready to send %li bytes\n", (long int) kount1);
1741 JOM(12, "still to send %li bytes\n", (long int) kount);
1745 JOM(12, "agreed to send %li bytes from page %i\n",
1746 more, peasycap->audio_read);
1750 /*---------------------------------------------------------------------------*/
1752 * ACCUMULATE DYNAMIC-RANGE INFORMATION
1754 /*---------------------------------------------------------------------------*/
1755 p0 = (unsigned char *)pdata_buffer->pgo; l0 = 0; lm = more/2;
1757 SUMMER(p0, &peasycap->audio_sample, &peasycap->audio_niveau,
1758 &peasycap->audio_square); l0++; p0 += 2;
1760 /*---------------------------------------------------------------------------*/
1761 rc = copy_to_user(puserspacebuffer, pdata_buffer->pto, more);
1763 SAM("ERROR: copy_to_user() returned %li\n", rc);
1764 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1767 *poff += (loff_t)more;
1768 szret += (size_t)more;
1769 pdata_buffer->pto += more;
1770 puserspacebuffer += more;
1771 kount -= (size_t)more;
1773 JOM(12, "after read, %i=frag read %i=frag fill\n",
1774 (peasycap->audio_read / peasycap->audio_pages_per_fragment),
1775 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
1777 SAM("MISTAKE: %li=kount %li=szret\n",
1778 (long int)kount, (long int)szret);
1780 /*---------------------------------------------------------------------------*/
1782 * CALCULATE DYNAMIC RANGE FOR (VAPOURWARE) AUTOMATIC VOLUME CONTROL
1784 /*---------------------------------------------------------------------------*/
1785 if (peasycap->audio_sample) {
1786 below = peasycap->audio_sample;
1787 above = peasycap->audio_square;
1788 sdr = signed_div(above, below);
1789 above = sdr.quotient;
1790 mean = peasycap->audio_niveau;
1791 sdr = signed_div(mean, peasycap->audio_sample);
1793 JOM(8, "%8lli=mean %8lli=meansquare after %lli samples, =>\n",
1794 sdr.quotient, above, peasycap->audio_sample);
1796 sdr = signed_div(above, 32768);
1797 JOM(8, "audio dynamic range is roughly %lli\n", sdr.quotient);
1799 /*---------------------------------------------------------------------------*/
1801 * UPDATE THE AUDIO CLOCK
1803 /*---------------------------------------------------------------------------*/
1804 do_gettimeofday(&timeval);
1805 if (!peasycap->timeval1.tv_sec) {
1806 peasycap->audio_bytes = 0;
1807 peasycap->timeval3 = timeval;
1808 peasycap->timeval1 = peasycap->timeval3;
1809 sdr.quotient = 192000;
1811 peasycap->audio_bytes += (long long int) szret;
1812 below = ((long long int)(1000000)) *
1813 ((long long int)(timeval.tv_sec -
1814 peasycap->timeval3.tv_sec)) +
1815 (long long int)(timeval.tv_usec - peasycap->timeval3.tv_usec);
1816 above = 1000000 * ((long long int) peasycap->audio_bytes);
1819 sdr = signed_div(above, below);
1821 sdr.quotient = 192000;
1823 JOM(8, "audio streaming at %lli bytes/second\n", sdr.quotient);
1824 peasycap->dnbydt = sdr.quotient;
1826 mutex_unlock(&easycapdc60_dongle[kd].mutex_audio);
1827 JOM(4, "unlocked easycapdc60_dongle[%i].mutex_audio\n", kd);
1828 JOM(8, "returning %li\n", (long int)szret);
1831 /*****************************************************************************/
1833 #endif /*!EASYCAP_NEEDS_ALSA*/
1835 /*****************************************************************************/
1836 /*****************************************************************************/
1837 /*****************************************************************************/
1838 /*****************************************************************************/
1839 /*****************************************************************************/
1840 /*****************************************************************************/
1841 /*---------------------------------------------------------------------------*/
1843 * COMMON AUDIO INITIALIZATION
1845 /*---------------------------------------------------------------------------*/
1847 easycap_sound_setup(struct easycap *peasycap)
1851 JOM(4, "starting initialization\n");
1853 if (NULL == peasycap) {
1854 SAY("ERROR: peasycap is NULL.\n");
1857 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1858 SAM("ERROR: peasycap->pusb_device is NULL\n");
1861 JOM(16, "0x%08lX=peasycap->pusb_device\n", (long int)peasycap->pusb_device);
1863 rc = audio_setup(peasycap);
1864 JOM(8, "audio_setup() returned %i\n", rc);
1866 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1867 SAM("ERROR: peasycap->pusb_device has become NULL\n");
1870 /*---------------------------------------------------------------------------*/
1871 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1872 SAM("ERROR: peasycap->pusb_device has become NULL\n");
1875 rc = usb_set_interface(peasycap->pusb_device, peasycap->audio_interface,
1876 peasycap->audio_altsetting_on);
1877 JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", peasycap->audio_interface,
1878 peasycap->audio_altsetting_on, rc);
1880 rc = wakeup_device(peasycap->pusb_device);
1881 JOM(8, "wakeup_device() returned %i\n", rc);
1883 peasycap->audio_eof = 0;
1884 peasycap->audio_idle = 0;
1886 peasycap->timeval1.tv_sec = 0;
1887 peasycap->timeval1.tv_usec = 0;
1889 submit_audio_urbs(peasycap);
1891 JOM(4, "finished initialization\n");
1894 /*****************************************************************************/
1895 /*---------------------------------------------------------------------------*/
1897 * SUBMIT ALL AUDIO URBS.
1899 /*---------------------------------------------------------------------------*/
1901 submit_audio_urbs(struct easycap *peasycap)
1903 struct data_urb *pdata_urb;
1905 struct list_head *plist_head;
1906 int j, isbad, nospc, m, rc;
1909 if (NULL == peasycap) {
1910 SAY("ERROR: peasycap is NULL\n");
1913 if ((struct list_head *)NULL == peasycap->purb_audio_head) {
1914 SAM("ERROR: peasycap->urb_audio_head uninitialized\n");
1917 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1918 SAM("ERROR: peasycap->pusb_device is NULL\n");
1921 if (!peasycap->audio_isoc_streaming) {
1922 JOM(4, "initial submission of all audio urbs\n");
1923 rc = usb_set_interface(peasycap->pusb_device,
1924 peasycap->audio_interface,
1925 peasycap->audio_altsetting_on);
1926 JOM(8, "usb_set_interface(.,%i,%i) returned %i\n",
1927 peasycap->audio_interface,
1928 peasycap->audio_altsetting_on, rc);
1930 isbad = 0; nospc = 0; m = 0;
1931 list_for_each(plist_head, (peasycap->purb_audio_head)) {
1932 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
1933 if (NULL != pdata_urb) {
1934 purb = pdata_urb->purb;
1936 isbuf = pdata_urb->isbuf;
1939 purb->dev = peasycap->pusb_device;
1941 usb_rcvisocpipe(peasycap->pusb_device,
1942 peasycap->audio_endpointnumber);
1943 purb->transfer_flags = URB_ISO_ASAP;
1944 purb->transfer_buffer =
1945 peasycap->audio_isoc_buffer[isbuf].pgo;
1946 purb->transfer_buffer_length =
1947 peasycap->audio_isoc_buffer_size;
1948 #if defined(EASYCAP_NEEDS_ALSA)
1949 purb->complete = easycap_alsa_complete;
1951 purb->complete = easyoss_complete;
1952 #endif /*EASYCAP_NEEDS_ALSA*/
1953 purb->context = peasycap;
1954 purb->start_frame = 0;
1955 purb->number_of_packets =
1956 peasycap->audio_isoc_framesperdesc;
1957 for (j = 0; j < peasycap->
1958 audio_isoc_framesperdesc;
1960 purb->iso_frame_desc[j].offset = j *
1962 audio_isoc_maxframesize;
1963 purb->iso_frame_desc[j].length =
1965 audio_isoc_maxframesize;
1968 rc = usb_submit_urb(purb, GFP_KERNEL);
1971 SAM("ERROR: usb_submit_urb() failed"
1972 " for urb with rc:\n");
2019 SAM("unknown error: %i\n", rc);
2034 SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
2035 SAM("..... possibly inadequate USB bandwidth\n");
2036 peasycap->audio_eof = 1;
2039 JOM(4, "attempting cleanup instead of submitting\n");
2040 list_for_each(plist_head, (peasycap->purb_audio_head)) {
2041 pdata_urb = list_entry(plist_head, struct data_urb,
2043 if (NULL != pdata_urb) {
2044 purb = pdata_urb->purb;
2049 peasycap->audio_isoc_streaming = 0;
2051 peasycap->audio_isoc_streaming = m;
2052 JOM(4, "submitted %i audio urbs\n", m);
2055 JOM(4, "already streaming audio urbs\n");
2059 /*****************************************************************************/
2060 /*---------------------------------------------------------------------------*/
2062 * KILL ALL AUDIO URBS.
2064 /*---------------------------------------------------------------------------*/
2066 kill_audio_urbs(struct easycap *peasycap)
2069 struct list_head *plist_head;
2070 struct data_urb *pdata_urb;
2072 if (NULL == peasycap) {
2073 SAY("ERROR: peasycap is NULL\n");
2076 if (peasycap->audio_isoc_streaming) {
2077 if ((struct list_head *)NULL != peasycap->purb_audio_head) {
2078 peasycap->audio_isoc_streaming = 0;
2079 JOM(4, "killing audio urbs\n");
2081 list_for_each(plist_head, (peasycap->purb_audio_head)) {
2082 pdata_urb = list_entry(plist_head, struct data_urb,
2084 if ((struct data_urb *)NULL != pdata_urb) {
2085 if ((struct urb *)NULL != pdata_urb->purb) {
2086 usb_kill_urb(pdata_urb->purb);
2091 JOM(4, "%i audio urbs killed\n", m);
2093 SAM("ERROR: peasycap->purb_audio_head is NULL\n");
2097 JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n",
2098 peasycap->audio_isoc_streaming);
2102 /*****************************************************************************/