/* * Callback for completed capture URB. */ static void audio_in_callback(struct urb *urb) { int i, index, length = 0, shutdown = 0; unsigned long flags; struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context; line6pcm->in.last_frame = urb->start_frame; /* find index of URB */ for (index = 0; index < line6pcm->line6->iso_buffers; ++index) if (urb == line6pcm->in.urbs[index]) break; spin_lock_irqsave(&line6pcm->in.lock, flags); for (i = 0; i < LINE6_ISO_PACKETS; ++i) { char *fbuf; int fsize; struct usb_iso_packet_descriptor *fin = &urb->iso_frame_desc[i]; if (fin->status == -EXDEV) { shutdown = 1; break; } fbuf = urb->transfer_buffer + fin->offset; fsize = fin->actual_length; if (fsize > line6pcm->max_packet_size_in) { dev_err(line6pcm->line6->ifcdev, "driver and/or device bug: packet too large (%d > %d)\n", fsize, line6pcm->max_packet_size_in); } length += fsize; BUILD_BUG_ON_MSG(LINE6_ISO_PACKETS != 1, "The following code assumes LINE6_ISO_PACKETS == 1"); /* TODO: * Also, if iso_buffers != 2, the prev frame is almost random at * playback side. * This needs to be redesigned. It should be "stable", but we may * experience sync problems on such high-speed configs. */ line6pcm->prev_fbuf = fbuf; line6pcm->prev_fsize = fsize / (line6pcm->properties->bytes_per_channel * line6pcm->properties->capture_hw.channels_max); if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) && test_bit(LINE6_STREAM_PCM, &line6pcm->in.running) && fsize > 0) line6_capture_copy(line6pcm, fbuf, fsize); } clear_bit(index, &line6pcm->in.active_urbs); if (test_and_clear_bit(index, &line6pcm->in.unlink_urbs)) shutdown = 1; if (!shutdown) { submit_audio_in_urb(line6pcm); if (!test_bit(LINE6_STREAM_IMPULSE, &line6pcm->in.running) && test_bit(LINE6_STREAM_PCM, &line6pcm->in.running)) line6_capture_check_period(line6pcm, length); } spin_unlock_irqrestore(&line6pcm->in.lock, flags); }
/* * Callback for completed capture URB. */ static void audio_in_callback(struct urb *urb) { int i, index, length = 0, shutdown = 0; unsigned long flags; struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context; line6pcm->last_frame_in = urb->start_frame; /* find index of URB */ for (index = 0; index < LINE6_ISO_BUFFERS; ++index) if (urb == line6pcm->urb_audio_in[index]) break; spin_lock_irqsave(&line6pcm->lock_audio_in, flags); for (i = 0; i < LINE6_ISO_PACKETS; ++i) { char *fbuf; int fsize; struct usb_iso_packet_descriptor *fin = &urb->iso_frame_desc[i]; if (fin->status == -EXDEV) { shutdown = 1; break; } fbuf = urb->transfer_buffer + fin->offset; fsize = fin->actual_length; if (fsize > line6pcm->max_packet_size) { dev_err(line6pcm->line6->ifcdev, "driver and/or device bug: packet too large (%d > %d)\n", fsize, line6pcm->max_packet_size); } length += fsize; /* the following assumes LINE6_ISO_PACKETS == 1: */ line6pcm->prev_fbuf = fbuf; line6pcm->prev_fsize = fsize; #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE)) #endif if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM, &line6pcm->flags) && (fsize > 0)) line6_capture_copy(line6pcm, fbuf, fsize); } clear_bit(index, &line6pcm->active_urb_in); if (test_and_clear_bit(index, &line6pcm->unlink_urb_in)) shutdown = 1; spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags); if (!shutdown) { submit_audio_in_urb(line6pcm); #ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE if (!(line6pcm->flags & LINE6_BITS_PCM_IMPULSE)) #endif if (test_bit(LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM, &line6pcm->flags)) line6_capture_check_period(line6pcm, length); } }