aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/sound/firewire/digi00x/digi00x-stream.c
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2019-06-11 22:21:11 +0900
committerTakashi Iwai <tiwai@suse.de>2019-06-11 16:02:05 +0200
commitae8ffbb26512bbfd3f929e34c85880f620ecb6eb (patch)
treeb8184e703654e1fa10a782893f696e0bd0bb4bf3 /sound/firewire/digi00x/digi00x-stream.c
parentALSA: firewire-digi00x: code refactoring to keep isochronous resources (diff)
downloadwireguard-linux-ae8ffbb26512bbfd3f929e34c85880f620ecb6eb.tar.xz
wireguard-linux-ae8ffbb26512bbfd3f929e34c85880f620ecb6eb.zip
ALSA: firewire-digi00x: reserve/release isochronous resources in pcm.hw_params/hw_free callbacks
Once allocated, isochronous resources are available for packet streaming, even if the streaming is cancelled. For this reason, current implementation handles allocation of the resources and starting packet streaming at the same time. However, this brings complicated procedure to start packet streaming. This commit separates the allocation and starting. The allocation is done in pcm.hw_params callback and available till pcm.hw_free callback. Even if any XRUN occurs, pcm.prepare callback is done to restart packet streaming without releasing/allocating the resources. There are two points to stop packet streaming; in pcm.hw_params and pcm.prepare callbacks. The former point is a case that packet streaming is already started for any MIDI substream then packet streaming is requested with different sampling transfer frequency for any PCM substream. The latter point is cases of any XRUN or packet queueing error. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/firewire/digi00x/digi00x-stream.c')
-rw-r--r--sound/firewire/digi00x/digi00x-stream.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/sound/firewire/digi00x/digi00x-stream.c b/sound/firewire/digi00x/digi00x-stream.c
index 2bddeb3e4bf5..3b903e42d29a 100644
--- a/sound/firewire/digi00x/digi00x-stream.c
+++ b/sound/firewire/digi00x/digi00x-stream.c
@@ -189,13 +189,6 @@ static int begin_session(struct snd_dg00x *dg00x)
return err;
}
-static void release_resources(struct snd_dg00x *dg00x)
-{
- /* Release isochronous resources. */
- fw_iso_resources_free(&dg00x->tx_resources);
- fw_iso_resources_free(&dg00x->rx_resources);
-}
-
static int keep_resources(struct snd_dg00x *dg00x, struct amdtp_stream *stream,
unsigned int rate)
{
@@ -265,45 +258,65 @@ void snd_dg00x_stream_destroy_duplex(struct snd_dg00x *dg00x)
fw_iso_resources_destroy(&dg00x->tx_resources);
}
-int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x, unsigned int rate)
+int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate)
{
unsigned int curr_rate;
- int err = 0;
-
- if (dg00x->substreams_counter == 0)
- goto end;
+ int err;
- /* Check current sampling rate. */
err = snd_dg00x_stream_get_local_rate(dg00x, &curr_rate);
if (err < 0)
- goto error;
+ return err;
if (rate == 0)
rate = curr_rate;
- if (curr_rate != rate ||
- amdtp_streaming_error(&dg00x->tx_stream) ||
- amdtp_streaming_error(&dg00x->rx_stream)) {
+
+ if (dg00x->substreams_counter == 0 || curr_rate != rate) {
finish_session(dg00x);
- release_resources(dg00x);
- }
+ fw_iso_resources_free(&dg00x->tx_resources);
+ fw_iso_resources_free(&dg00x->rx_resources);
- /*
- * No packets are transmitted without receiving packets, reagardless of
- * which source of clock is used.
- */
- if (!amdtp_stream_running(&dg00x->rx_stream)) {
err = snd_dg00x_stream_set_local_rate(dg00x, rate);
if (err < 0)
- goto error;
+ return err;
err = keep_resources(dg00x, &dg00x->rx_stream, rate);
if (err < 0)
- goto error;
+ return err;
err = keep_resources(dg00x, &dg00x->tx_stream, rate);
- if (err < 0)
- goto error;
+ if (err < 0) {
+ fw_iso_resources_free(&dg00x->rx_resources);
+ return err;
+ }
+ }
+
+ return 0;
+}
+void snd_dg00x_stream_release_duplex(struct snd_dg00x *dg00x)
+{
+ if (dg00x->substreams_counter == 0) {
+ fw_iso_resources_free(&dg00x->tx_resources);
+ fw_iso_resources_free(&dg00x->rx_resources);
+ }
+}
+
+int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x)
+{
+ int err = 0;
+
+ if (dg00x->substreams_counter == 0)
+ return 0;
+
+ if (amdtp_streaming_error(&dg00x->tx_stream) ||
+ amdtp_streaming_error(&dg00x->rx_stream))
+ finish_session(dg00x);
+
+ /*
+ * No packets are transmitted without receiving packets, reagardless of
+ * which source of clock is used.
+ */
+ if (!amdtp_stream_running(&dg00x->rx_stream)) {
err = begin_session(dg00x);
if (err < 0)
goto error;
@@ -338,23 +351,18 @@ int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x, unsigned int rate)
goto error;
}
}
-end:
- return err;
+
+ return 0;
error:
finish_session(dg00x);
- release_resources(dg00x);
-
return err;
}
void snd_dg00x_stream_stop_duplex(struct snd_dg00x *dg00x)
{
- if (dg00x->substreams_counter > 0)
- return;
-
- finish_session(dg00x);
- release_resources(dg00x);
+ if (dg00x->substreams_counter == 0)
+ finish_session(dg00x);
}
void snd_dg00x_stream_update_duplex(struct snd_dg00x *dg00x)