Commit 3d58760f authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: usb-audio: Unify the code for the next packet size calculation



There are two places calculating the next packet size for the playback
stream in the exactly same way.  Provide the single helper for this
purpose and use it from both places gracefully.

Tested-by: default avatarKeith Milner <kamilner@superlative.org>
Tested-by: default avatarDylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-32-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 6aa719d1
...@@ -121,13 +121,13 @@ int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep) ...@@ -121,13 +121,13 @@ int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep)
} }
/* /*
* For streaming based on information derived from sync endpoints, * Return the number of samples to be sent in the next packet
* prepare_outbound_urb_sizes() will call slave_next_packet_size() to * for streaming based on information derived from sync endpoints
* determine the number of samples to be sent in the next packet.
* *
* For implicit feedback, slave_next_packet_size() is unused. * This won't be used for implicit feedback which takes the packet size
* returned from the sync source
*/ */
int snd_usb_endpoint_slave_next_packet_size(struct snd_usb_endpoint *ep) static int slave_next_packet_size(struct snd_usb_endpoint *ep)
{ {
unsigned long flags; unsigned long flags;
int ret; int ret;
...@@ -145,11 +145,10 @@ int snd_usb_endpoint_slave_next_packet_size(struct snd_usb_endpoint *ep) ...@@ -145,11 +145,10 @@ int snd_usb_endpoint_slave_next_packet_size(struct snd_usb_endpoint *ep)
} }
/* /*
* For adaptive and synchronous endpoints, prepare_outbound_urb_sizes() * Return the number of samples to be sent in the next packet
* will call next_packet_size() to determine the number of samples to be * for adaptive and synchronous endpoints
* sent in the next packet.
*/ */
int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep) static int next_packet_size(struct snd_usb_endpoint *ep)
{ {
int ret; int ret;
...@@ -167,6 +166,21 @@ int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep) ...@@ -167,6 +166,21 @@ int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep)
return ret; return ret;
} }
/*
* snd_usb_endpoint_next_packet_size: Return the number of samples to be sent
* in the next packet
*/
int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep,
struct snd_urb_ctx *ctx, int idx)
{
if (ctx->packet_size[idx])
return ctx->packet_size[idx];
else if (ep->sync_master)
return slave_next_packet_size(ep);
else
return next_packet_size(ep);
}
static void call_retire_callback(struct snd_usb_endpoint *ep, static void call_retire_callback(struct snd_usb_endpoint *ep,
struct urb *urb) struct urb *urb)
{ {
...@@ -223,13 +237,7 @@ static void prepare_silent_urb(struct snd_usb_endpoint *ep, ...@@ -223,13 +237,7 @@ static void prepare_silent_urb(struct snd_usb_endpoint *ep,
unsigned int length; unsigned int length;
int counts; int counts;
if (ctx->packet_size[i]) counts = snd_usb_endpoint_next_packet_size(ep, ctx, i);
counts = ctx->packet_size[i];
else if (ep->sync_master)
counts = snd_usb_endpoint_slave_next_packet_size(ep);
else
counts = snd_usb_endpoint_next_packet_size(ep);
length = counts * ep->stride; /* number of silent bytes */ length = counts * ep->stride; /* number of silent bytes */
offset = offs * ep->stride + extra * i; offset = offs * ep->stride + extra * i;
urb->iso_frame_desc[i].offset = offset; urb->iso_frame_desc[i].offset = offset;
......
...@@ -45,7 +45,7 @@ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep); ...@@ -45,7 +45,7 @@ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep);
void snd_usb_endpoint_free(struct snd_usb_endpoint *ep); void snd_usb_endpoint_free(struct snd_usb_endpoint *ep);
int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep); int snd_usb_endpoint_implicit_feedback_sink(struct snd_usb_endpoint *ep);
int snd_usb_endpoint_slave_next_packet_size(struct snd_usb_endpoint *ep); int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep,
int snd_usb_endpoint_next_packet_size(struct snd_usb_endpoint *ep); struct snd_urb_ctx *ctx, int idx);
#endif /* __USBAUDIO_ENDPOINT_H */ #endif /* __USBAUDIO_ENDPOINT_H */
...@@ -1512,13 +1512,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, ...@@ -1512,13 +1512,7 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
spin_lock_irqsave(&subs->lock, flags); spin_lock_irqsave(&subs->lock, flags);
subs->frame_limit += ep->max_urb_frames; subs->frame_limit += ep->max_urb_frames;
for (i = 0; i < ctx->packets; i++) { for (i = 0; i < ctx->packets; i++) {
if (ctx->packet_size[i]) counts = snd_usb_endpoint_next_packet_size(ep, ctx, i);
counts = ctx->packet_size[i];
else if (ep->sync_master)
counts = snd_usb_endpoint_slave_next_packet_size(ep);
else
counts = snd_usb_endpoint_next_packet_size(ep);
/* set up descriptor */ /* set up descriptor */
urb->iso_frame_desc[i].offset = frames * ep->stride; urb->iso_frame_desc[i].offset = frames * ep->stride;
urb->iso_frame_desc[i].length = counts * ep->stride; urb->iso_frame_desc[i].length = counts * ep->stride;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment