Skip to content

Commit

Permalink
ALSA: line6: Rearrange PCM structure
Browse files Browse the repository at this point in the history
Introduce a new line6_pcm_stream structure and group individual
fields of snd_line6_pcm struct to playback and capture groups.

This patch itself just does rename and nothing else.  More
meaningful cleanups based on these fields shuffling will follow.

Tested-by: Chris Rorvick <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Jan 28, 2015
1 parent ab5cdcb commit ad0119a
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 208 deletions.
64 changes: 32 additions & 32 deletions sound/usb/line6/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
int ret;
struct urb *urb_in;

spin_lock_irqsave(&line6pcm->lock_audio_in, flags);
spin_lock_irqsave(&line6pcm->in.lock, flags);
index =
find_first_zero_bit(&line6pcm->active_urb_in, LINE6_ISO_BUFFERS);
find_first_zero_bit(&line6pcm->in.active_urbs, LINE6_ISO_BUFFERS);

if (index < 0 || index >= LINE6_ISO_BUFFERS) {
spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
spin_unlock_irqrestore(&line6pcm->in.lock, flags);
dev_err(line6pcm->line6->ifcdev, "no free URB found\n");
return -EINVAL;
}

urb_in = line6pcm->urb_audio_in[index];
urb_in = line6pcm->in.urbs[index];
urb_size = 0;

for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
Expand All @@ -51,20 +51,20 @@ static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm)
}

urb_in->transfer_buffer =
line6pcm->buffer_in +
line6pcm->in.buffer +
index * LINE6_ISO_PACKETS * line6pcm->max_packet_size;
urb_in->transfer_buffer_length = urb_size;
urb_in->context = line6pcm;

ret = usb_submit_urb(urb_in, GFP_ATOMIC);

if (ret == 0)
set_bit(index, &line6pcm->active_urb_in);
set_bit(index, &line6pcm->in.active_urbs);
else
dev_err(line6pcm->line6->ifcdev,
"URB in #%d submission failed (%d)\n", index, ret);

spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
spin_unlock_irqrestore(&line6pcm->in.lock, flags);
return 0;
}

Expand Down Expand Up @@ -92,9 +92,9 @@ void line6_unlink_audio_in_urbs(struct snd_line6_pcm *line6pcm)
unsigned int i;

for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
if (test_bit(i, &line6pcm->active_urb_in)) {
if (!test_and_set_bit(i, &line6pcm->unlink_urb_in)) {
struct urb *u = line6pcm->urb_audio_in[i];
if (test_bit(i, &line6pcm->in.active_urbs)) {
if (!test_and_set_bit(i, &line6pcm->in.unlink_urbs)) {
struct urb *u = line6pcm->in.urbs[i];

usb_unlink_urb(u);
}
Expand All @@ -115,7 +115,7 @@ void line6_wait_clear_audio_in_urbs(struct snd_line6_pcm *line6pcm)
do {
alive = 0;
for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
if (test_bit(i, &line6pcm->active_urb_in))
if (test_bit(i, &line6pcm->in.active_urbs))
alive++;
}
if (!alive)
Expand Down Expand Up @@ -150,18 +150,18 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
if (runtime == NULL)
return;

if (line6pcm->pos_in_done + frames > runtime->buffer_size) {
if (line6pcm->in.pos_done + frames > runtime->buffer_size) {
/*
The transferred area goes over buffer boundary,
copy two separate chunks.
*/
int len;

len = runtime->buffer_size - line6pcm->pos_in_done;
len = runtime->buffer_size - line6pcm->in.pos_done;

if (len > 0) {
memcpy(runtime->dma_area +
line6pcm->pos_in_done * bytes_per_frame, fbuf,
line6pcm->in.pos_done * bytes_per_frame, fbuf,
len * bytes_per_frame);
memcpy(runtime->dma_area, fbuf + len * bytes_per_frame,
(frames - len) * bytes_per_frame);
Expand All @@ -173,30 +173,30 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
} else {
/* copy single chunk */
memcpy(runtime->dma_area +
line6pcm->pos_in_done * bytes_per_frame, fbuf, fsize);
line6pcm->in.pos_done * bytes_per_frame, fbuf, fsize);
}

line6pcm->pos_in_done += frames;
if (line6pcm->pos_in_done >= runtime->buffer_size)
line6pcm->pos_in_done -= runtime->buffer_size;
line6pcm->in.pos_done += frames;
if (line6pcm->in.pos_done >= runtime->buffer_size)
line6pcm->in.pos_done -= runtime->buffer_size;
}

void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
{
struct snd_pcm_substream *substream =
get_substream(line6pcm, SNDRV_PCM_STREAM_CAPTURE);

line6pcm->bytes_in += length;
if (line6pcm->bytes_in >= line6pcm->period_in) {
line6pcm->bytes_in %= line6pcm->period_in;
line6pcm->in.bytes += length;
if (line6pcm->in.bytes >= line6pcm->in.period) {
line6pcm->in.bytes %= line6pcm->in.period;
snd_pcm_period_elapsed(substream);
}
}

void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
{
kfree(line6pcm->buffer_in);
line6pcm->buffer_in = NULL;
kfree(line6pcm->in.buffer);
line6pcm->in.buffer = NULL;
}

/*
Expand All @@ -209,14 +209,14 @@ static void audio_in_callback(struct urb *urb)

struct snd_line6_pcm *line6pcm = (struct snd_line6_pcm *)urb->context;

line6pcm->last_frame_in = urb->start_frame;
line6pcm->in.last_frame = urb->start_frame;

/* find index of URB */
for (index = 0; index < LINE6_ISO_BUFFERS; ++index)
if (urb == line6pcm->urb_audio_in[index])
if (urb == line6pcm->in.urbs[index])
break;

spin_lock_irqsave(&line6pcm->lock_audio_in, flags);
spin_lock_irqsave(&line6pcm->in.lock, flags);

for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
char *fbuf;
Expand Down Expand Up @@ -249,12 +249,12 @@ static void audio_in_callback(struct urb *urb)
line6_capture_copy(line6pcm, fbuf, fsize);
}

clear_bit(index, &line6pcm->active_urb_in);
clear_bit(index, &line6pcm->in.active_urbs);

if (test_and_clear_bit(index, &line6pcm->unlink_urb_in))
if (test_and_clear_bit(index, &line6pcm->in.unlink_urbs))
shutdown = 1;

spin_unlock_irqrestore(&line6pcm->lock_audio_in, flags);
spin_unlock_irqrestore(&line6pcm->in.lock, flags);

if (!shutdown) {
submit_audio_in_urb(line6pcm);
Expand Down Expand Up @@ -309,7 +309,7 @@ static int snd_line6_capture_hw_params(struct snd_pcm_substream *substream,
return ret;
}

line6pcm->period_in = params_period_bytes(hw_params);
line6pcm->in.period = params_period_bytes(hw_params);
return 0;
}

Expand Down Expand Up @@ -361,7 +361,7 @@ snd_line6_capture_pointer(struct snd_pcm_substream *substream)
{
struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);

return line6pcm->pos_in_done;
return line6pcm->in.pos_done;
}

/* capture operators */
Expand All @@ -386,7 +386,7 @@ int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm)
struct urb *urb;

/* URB for audio in: */
urb = line6pcm->urb_audio_in[i] =
urb = line6pcm->in.urbs[i] =
usb_alloc_urb(LINE6_ISO_PACKETS, GFP_KERNEL);

if (urb == NULL)
Expand Down
50 changes: 25 additions & 25 deletions sound/usb/line6/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)

if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
/* Invoked multiple times in a row so allocate once only */
if (!line6pcm->buffer_in) {
line6pcm->buffer_in =
if (!line6pcm->in.buffer) {
line6pcm->in.buffer =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_in) {
if (!line6pcm->in.buffer) {
err = -ENOMEM;
goto pcm_acquire_error;
}
Expand All @@ -131,13 +131,13 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
a bug, we therefore report an error if capturing is restarted
too soon.
*/
if (line6pcm->active_urb_in || line6pcm->unlink_urb_in) {
if (line6pcm->in.active_urbs || line6pcm->in.unlink_urbs) {
dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
err = -EBUSY;
goto pcm_acquire_error;
}

line6pcm->count_in = 0;
line6pcm->in.count = 0;
line6pcm->prev_fsize = 0;
err = line6_submit_audio_in_all_urbs(line6pcm);

Expand All @@ -149,11 +149,11 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)

if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) {
/* Invoked multiple times in a row so allocate once only */
if (!line6pcm->buffer_out) {
line6pcm->buffer_out =
if (!line6pcm->out.buffer) {
line6pcm->out.buffer =
kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
line6pcm->max_packet_size, GFP_KERNEL);
if (!line6pcm->buffer_out) {
if (!line6pcm->out.buffer) {
err = -ENOMEM;
goto pcm_acquire_error;
}
Expand All @@ -166,12 +166,12 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
/*
See comment above regarding PCM restart.
*/
if (line6pcm->active_urb_out || line6pcm->unlink_urb_out) {
if (line6pcm->out.active_urbs || line6pcm->out.unlink_urbs) {
dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
return -EBUSY;
}

line6pcm->count_out = 0;
line6pcm->out.count = 0;
err = line6_submit_audio_out_all_urbs(line6pcm);

if (err < 0)
Expand Down Expand Up @@ -331,13 +331,13 @@ static void line6_cleanup_pcm(struct snd_pcm *pcm)
struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);

for (i = 0; i < LINE6_ISO_BUFFERS; i++) {
if (line6pcm->urb_audio_out[i]) {
usb_kill_urb(line6pcm->urb_audio_out[i]);
usb_free_urb(line6pcm->urb_audio_out[i]);
if (line6pcm->out.urbs[i]) {
usb_kill_urb(line6pcm->out.urbs[i]);
usb_free_urb(line6pcm->out.urbs[i]);
}
if (line6pcm->urb_audio_in[i]) {
usb_kill_urb(line6pcm->urb_audio_in[i]);
usb_free_urb(line6pcm->urb_audio_in[i]);
if (line6pcm->in.urbs[i]) {
usb_kill_urb(line6pcm->in.urbs[i]);
usb_free_urb(line6pcm->in.urbs[i]);
}
}
kfree(line6pcm);
Expand Down Expand Up @@ -415,8 +415,8 @@ int line6_init_pcm(struct usb_line6 *line6,
usb_maxpacket(line6->usbdev,
usb_sndisocpipe(line6->usbdev, ep_write), 1));

spin_lock_init(&line6pcm->lock_audio_out);
spin_lock_init(&line6pcm->lock_audio_in);
spin_lock_init(&line6pcm->out.lock);
spin_lock_init(&line6pcm->in.lock);
line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;

line6->line6pcm = line6pcm;
Expand Down Expand Up @@ -464,13 +464,13 @@ int snd_line6_prepare(struct snd_pcm_substream *substream)
}

if (!test_and_set_bit(LINE6_INDEX_PREPARED, &line6pcm->flags)) {
line6pcm->count_out = 0;
line6pcm->pos_out = 0;
line6pcm->pos_out_done = 0;
line6pcm->bytes_out = 0;
line6pcm->count_in = 0;
line6pcm->pos_in_done = 0;
line6pcm->bytes_in = 0;
line6pcm->out.count = 0;
line6pcm->out.pos = 0;
line6pcm->out.pos_done = 0;
line6pcm->out.bytes = 0;
line6pcm->in.count = 0;
line6pcm->in.pos_done = 0;
line6pcm->in.bytes = 0;
}

return 0;
Expand Down
Loading

0 comments on commit ad0119a

Please sign in to comment.