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 10/20] ALSA: firewire-lib: use packet descriptor for IR context
Date: Mon, 22 Jul 2019 12:37:00 +0900	[thread overview]
Message-ID: <20190722033710.28107-11-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20190722033710.28107-1-o-takashi@sakamocchi.jp>

This commit uses packet descriptor to parse headers of IR context and
parse timing information for sequence transferred by target device.

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

diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index 463c7a340a45..68502a8864b9 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -602,6 +602,8 @@ static int check_cip_header(struct amdtp_stream *s, const __be32 *buf,
 		return -EIO;
 	}
 
+	*data_block_counter = dbc;
+
 	*syt = cip_header[1] & CIP_SYT_MASK;
 
 	return 0;
@@ -676,6 +678,48 @@ static inline u32 compute_it_cycle(const __be32 ctx_header_tstamp)
 	return increment_cycle_count(cycle, QUEUE_LENGTH);
 }
 
+static int generate_device_pkt_descs(struct amdtp_stream *s,
+				     struct pkt_desc *descs,
+				     const __be32 *ctx_header,
+				     unsigned int packets)
+{
+	unsigned int dbc = s->data_block_counter;
+	int i;
+	int err;
+
+	for (i = 0; i < packets; ++i) {
+		struct pkt_desc *desc = descs + i;
+		unsigned int index = (s->packet_index + i) % QUEUE_LENGTH;
+		unsigned int cycle;
+		unsigned int payload_length;
+		unsigned int data_blocks;
+		unsigned int syt;
+
+		cycle = compute_cycle_count(ctx_header[1]);
+
+		err = parse_ir_ctx_header(s, cycle, ctx_header, &payload_length,
+					  &data_blocks, &dbc, &syt, i);
+		if (err < 0)
+			return err;
+
+		desc->cycle = cycle;
+		desc->syt = syt;
+		desc->data_blocks = data_blocks;
+		desc->data_block_counter = dbc;
+		desc->ctx_payload = s->buffer.packets[index].buffer;
+
+		if (!(s->flags & CIP_DBC_IS_END_EVENT))
+			dbc = (dbc + desc->data_blocks) & 0xff;
+
+		ctx_header +=
+			s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header);
+	}
+
+	s->data_block_counter = dbc;
+
+	return 0;
+}
+
 static void generate_ideal_pkt_descs(struct amdtp_stream *s,
 				     struct pkt_desc *descs,
 				     const __be32 *ctx_header,
@@ -770,8 +814,10 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp,
 			       void *private_data)
 {
 	struct amdtp_stream *s = private_data;
-	unsigned int i, packets;
+	unsigned int packets;
 	__be32 *ctx_header = header;
+	int i;
+	int err;
 
 	if (s->packet_index < 0)
 		return;
@@ -779,50 +825,34 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp,
 	// The number of packets in buffer.
 	packets = header_length / s->ctx_data.tx.ctx_header_size;
 
+	err = generate_device_pkt_descs(s, s->pkt_descs, ctx_header, packets);
+	if (err < 0) {
+		if (err != -EAGAIN) {
+			cancel_stream(s);
+			return;
+		}
+	}
+
 	for (i = 0; i < packets; i++) {
-		u32 cycle;
-		unsigned int payload_length;
-		unsigned int data_blocks;
-		unsigned int dbc;
-		unsigned int syt;
-		__be32 *buffer;
+		const struct pkt_desc *desc = s->pkt_descs;
 		unsigned int pcm_frames = 0;
 		struct fw_iso_packet params = {0};
 		struct snd_pcm_substream *pcm;
-		int err;
-
-		cycle = compute_cycle_count(ctx_header[1]);
-		dbc = s->data_block_counter;
-		err = parse_ir_ctx_header(s, cycle, ctx_header, &payload_length,
-					  &data_blocks, &dbc, &syt, i);
-		if (err < 0 && err != -EAGAIN)
-			break;
 
 		if (err >= 0) {
-			buffer = s->buffer.packets[s->packet_index].buffer;
-			pcm_frames = s->process_data_blocks(s, buffer,
-							    data_blocks, dbc);
-
-			if (!(s->flags & CIP_DBC_IS_END_EVENT))
-				dbc = (dbc + data_blocks) & 0xff;
+			pcm_frames = s->process_data_blocks(s,
+					desc->ctx_payload, desc->data_blocks,
+					desc->data_block_counter);
 		}
 
-		s->data_block_counter = dbc;
-
-		if (queue_in_packet(s, &params) < 0)
-			break;
+		if (queue_in_packet(s, &params) < 0) {
+			cancel_stream(s);
+			return;
+		}
 
 		pcm = READ_ONCE(s->pcm);
 		if (pcm && pcm_frames > 0)
 			update_pcm_pointers(s, pcm, pcm_frames);
-
-		ctx_header += s->ctx_data.tx.ctx_header_size / sizeof(*ctx_header);
-	}
-
-	/* Queueing error or detecting invalid payload. */
-	if (i < packets) {
-		cancel_stream(s);
-		return;
 	}
 
 	fw_iso_context_queue_flush(s->context);
-- 
2.20.1

  parent reply	other threads:[~2019-07-22  3:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22  3:36 [PATCH 00/20] ALSA: firewire-lib: use packet descriptor to represent sequence of packet Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 01/20] ALSA: firewire-lib: obsolete ctx_data.tx.first_dbc with CIP_UNALIGHED_DBC flag Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 02/20] ALSA: firewire-lib: pass data block count as an argument to tracepoints event Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 03/20] ALSA: firewire-lib: pass data block counter to data block processing layer Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 04/20] ALSA: firewire-lib: operate data block counter in top level of processing for IT context Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 05/20] ALSA: firewire-lib: operate data block counter in top level of processing for IR context Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 06/20] ALSA: firewire-lib: add syt_override member for some protocols Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 07/20] ALSA: firewire-lib: pass no syt information to data block processing layer Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 08/20] ALSA: firewire-lib: add list of packet descriptor Takashi Sakamoto
2019-07-22  3:36 ` [PATCH 09/20] ALSA: firewire-lib: use packet descriptor for IT context Takashi Sakamoto
2019-07-22  3:37 ` Takashi Sakamoto [this message]
2019-07-22  3:37 ` [PATCH 11/20] ALSA: firewire-lib: code refactoring to process PCM substream Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 12/20] ALSA: firewire-lib: code refactoring to process context payloads Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 13/20] ALSA: firewire-lib: pass packet descriptor to data block processing layer Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 14/20] ALSA: firewire-lib: code refactoring for AM824 " Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 15/20] ALSA: firewire-digi00x: code refactoring for DOT " Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 16/20] ALSA: firewire-tascam: code refactoring for TASCAM " Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 17/20] ALSA: firewire-motu: code refactoring for MOTU " Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 18/20] ALSA: fireface: code refactoring for FF " Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 19/20] ALSA: firewire-lib: process payload of isoc context according to packet descriptors Takashi Sakamoto
2019-07-22  3:37 ` [PATCH 20/20] ALSA: firewire-motu: more code refactoring for MOTU data block processing layer Takashi Sakamoto
2019-07-22 14:12 ` [PATCH 00/20] ALSA: firewire-lib: use packet descriptor to represent sequence of packet 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=20190722033710.28107-11-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.