All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 12/19] ALSA: oxfw: set packet parameter according to current configuration
Date: Wed, 12 Jun 2019 17:44:15 +0900	[thread overview]
Message-ID: <20190612084422.5344-13-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20190612084422.5344-1-o-takashi@sakamocchi.jp>

After a call of pcm.hw_params, the state of target device is expected
for applications. This commit retrieves the state and start packet
streaming.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/oxfw/oxfw-stream.c | 48 +++++++++++++++----------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 34ff673e6ff8..1691fdc1a575 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -112,51 +112,51 @@ static void stop_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
 		cmp_connection_break(&oxfw->in_conn);
 }
 
-static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream,
-			unsigned int rate, unsigned int pcm_channels)
+static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
 {
 	u8 **formats;
+	enum avc_general_plug_dir dir;
 	struct cmp_connection *conn;
 	struct snd_oxfw_stream_formation formation;
-	unsigned int i, midi_ports;
+	int i;
 	int err;
 
 	if (stream == &oxfw->rx_stream) {
+		dir = AVC_GENERAL_PLUG_DIR_IN;
 		formats = oxfw->rx_stream_formats;
 		conn = &oxfw->in_conn;
 	} else {
+		dir = AVC_GENERAL_PLUG_DIR_OUT;
 		formats = oxfw->tx_stream_formats;
 		conn = &oxfw->out_conn;
 	}
 
-	/* Get stream format */
+	err = snd_oxfw_stream_get_current_formation(oxfw, dir, &formation);
+	if (err < 0)
+		return err;
+
 	for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
+		struct snd_oxfw_stream_formation fmt;
+
 		if (formats[i] == NULL)
 			break;
 
-		err = snd_oxfw_stream_parse_format(formats[i], &formation);
+		err = snd_oxfw_stream_parse_format(formats[i], &fmt);
 		if (err < 0)
-			goto end;
-		if (rate != formation.rate)
-			continue;
-		if (pcm_channels == 0 ||  pcm_channels == formation.pcm)
+			return err;
+		if (fmt.rate == formation.rate && fmt.pcm == formation.pcm &&
+		    fmt.midi == formation.midi)
 			break;
 	}
-	if (i == SND_OXFW_STREAM_FORMAT_ENTRIES) {
-		err = -EINVAL;
-		goto end;
-	}
+	if (i == SND_OXFW_STREAM_FORMAT_ENTRIES)
+		return -EINVAL;
 
-	pcm_channels = formation.pcm;
-	midi_ports = formation.midi * 8;
+	// The stream should have one pcm channels at least.
+	if (formation.pcm == 0)
+		return -EINVAL;
 
-	/* The stream should have one pcm channels at least */
-	if (pcm_channels == 0) {
-		err = -EINVAL;
-		goto end;
-	}
-	err = amdtp_am824_set_parameters(stream, rate, pcm_channels, midi_ports,
-					 false);
+	err = amdtp_am824_set_parameters(stream, formation.rate, formation.pcm,
+					 formation.midi * 8, false);
 	if (err < 0)
 		goto end;
 
@@ -316,7 +316,7 @@ int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
 		/* Start opposite stream if needed. */
 		if (opposite && !amdtp_stream_running(opposite) &&
 		    (opposite_substreams > 0)) {
-			err = start_stream(oxfw, opposite, rate, 0);
+			err = start_stream(oxfw, opposite);
 			if (err < 0) {
 				dev_err(&oxfw->unit->device,
 					"fail to restart stream: %d\n", err);
@@ -327,7 +327,7 @@ int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
 
 	/* Start requested stream. */
 	if (!amdtp_stream_running(stream)) {
-		err = start_stream(oxfw, stream, rate, pcm_channels);
+		err = start_stream(oxfw, stream);
 		if (err < 0)
 			dev_err(&oxfw->unit->device,
 				"fail to start stream: %d\n", err);
-- 
2.20.1

  parent reply	other threads:[~2019-06-12  8:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-12  8:44 [PATCH 00/19] ALSA: bebob/fireworks/oxfw: code refactoring toward rework for reservation of isochronous resources Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 01/19] ALSA: bebob: configure sampling transfer frequency in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 02/19] ALSA: bebob: don't set XRUN in stop streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 03/19] ALSA: bebob: obsolete useless member of private structure Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 04/19] ALSA: bebob: code refactoring to initialize/destroy stream data Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 05/19] ALSA: fireworks: unify substream counter Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 06/19] ALSA: fireworks: code refactoring for rawmidi.open/close Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 07/19] ALSA: fireworks: code refactoring for pcm.hw_params/hw_free Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 08/19] ALSA: fireworks: configure sampling transfer frequency in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 09/19] ALSA: fireworks: configure stream parameters " Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 10/19] ALSA: fireworks: don't set XRUN in stop streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 11/19] ALSA: oxfw: code refactoring for stop condition of packet streaming Takashi Sakamoto
2019-06-12  8:44 ` Takashi Sakamoto [this message]
2019-06-12  8:44 ` [PATCH 13/19] ALSA: oxfw: start duplex streams if supported Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 14/19] ALSA: oxfw: break packet streaming at bus-reset handler Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 15/19] ALSA: oxfw: expand stop procedure for packet streaming Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 16/19] ALSA: oxfw: rename helper functions for duplex streams Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 17/19] ALSA: oxfw: unify substreams counter Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 18/19] ALSA: oxfw: configure packet format in pcm.hw_params callback Takashi Sakamoto
2019-06-12  8:44 ` [PATCH 19/19] ALSA: oxfw: configure stream parameter " Takashi Sakamoto
2019-06-12 13:30 ` [PATCH 00/19] ALSA: bebob/fireworks/oxfw: code refactoring toward rework for reservation of isochronous resources Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190612084422.5344-13-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.