From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 07/10] ALSA: firewire-lib: code refactoring for data block calculation
Date: Fri, 8 May 2020 13:36:32 +0900 [thread overview]
Message-ID: <20200508043635.349339-8-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20200508043635.349339-1-o-takashi@sakamocchi.jp>
When calculating the number of data blocks per packet, some states are
stored in AMDTP stream structure. This is inconvenient when reuse the
calculation from non-stream structure.
This commit applies refactoring to helper function for the calculation
so that the function doesn't touch AMDTP stream structure.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
sound/firewire/amdtp-stream.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c
index 9041510cb6aa..efd1f2a40cf1 100644
--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -339,25 +339,26 @@ void amdtp_stream_pcm_prepare(struct amdtp_stream *s)
}
EXPORT_SYMBOL(amdtp_stream_pcm_prepare);
-static unsigned int calculate_data_blocks(struct amdtp_stream *s,
- unsigned int syt)
+static unsigned int calculate_data_blocks(unsigned int *data_block_state,
+ bool is_blocking, bool is_no_info,
+ unsigned int syt_interval, enum cip_sfc sfc)
{
- unsigned int phase, data_blocks;
+ unsigned int data_blocks;
/* Blocking mode. */
- if (s->flags & CIP_BLOCKING) {
+ if (is_blocking) {
/* This module generate empty packet for 'no data'. */
- if (syt == CIP_SYT_NO_INFO)
+ if (is_no_info)
data_blocks = 0;
else
- data_blocks = s->syt_interval;
+ data_blocks = syt_interval;
/* Non-blocking mode. */
} else {
- if (!cip_sfc_is_base_44100(s->sfc)) {
+ if (!cip_sfc_is_base_44100(sfc)) {
// Sample_rate / 8000 is an integer, and precomputed.
- data_blocks = s->ctx_data.rx.data_block_state;
+ data_blocks = *data_block_state;
} else {
- phase = s->ctx_data.rx.data_block_state;
+ unsigned int phase = *data_block_state;
/*
* This calculates the number of data blocks per packet so that
@@ -367,16 +368,16 @@ static unsigned int calculate_data_blocks(struct amdtp_stream *s,
* as possible in the sequence (to prevent underruns of the
* device's buffer).
*/
- if (s->sfc == CIP_SFC_44100)
+ if (sfc == CIP_SFC_44100)
/* 6 6 5 6 5 6 5 ... */
data_blocks = 5 + ((phase & 1) ^
(phase == 0 || phase >= 40));
else
/* 12 11 11 11 11 ... or 23 22 22 22 22 ... */
- data_blocks = 11 * (s->sfc >> 1) + (phase == 0);
- if (++phase >= (80 >> (s->sfc >> 1)))
+ data_blocks = 11 * (sfc >> 1) + (phase == 0);
+ if (++phase >= (80 >> (sfc >> 1)))
phase = 0;
- s->ctx_data.rx.data_block_state = phase;
+ *data_block_state = phase;
}
}
@@ -769,7 +770,11 @@ static void generate_ideal_pkt_descs(struct amdtp_stream *s,
} else {
desc->syt = syt_offset;
}
- desc->data_blocks = calculate_data_blocks(s, desc->syt);
+ desc->data_blocks =
+ calculate_data_blocks(&s->ctx_data.rx.data_block_state,
+ !!(s->flags & CIP_BLOCKING),
+ desc->syt == CIP_SYT_NO_INFO,
+ s->syt_interval, s->sfc);
if (s->flags & CIP_DBC_IS_END_EVENT)
dbc = (dbc + desc->data_blocks) & 0xff;
--
2.25.1
next prev parent reply other threads:[~2020-05-08 4:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-08 4:36 [PATCH 00/10] ALSA: firewire-lib: pool sequence of syt offset and data blocks in AMDTP domain structure Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 01/10] ALSA: firewire-lib: fix invalid assignment to union data for directional parameter Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 02/10] ALSA: firewire-lib: use macro for maximum value of second in 1394 OHCI isoc descriptor Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 03/10] ALSA: firewire-lib: add reference to domain structure from stream structure Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 04/10] ALSA: firewire-lib: code refactoring for parameters of packet queue and IRQ timing Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 05/10] ALSA: firewire-lib: code refactoring for syt computation Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 06/10] ALSA: firewire-lib: code refactoring for syt offset calculation Takashi Sakamoto
2020-05-08 4:36 ` Takashi Sakamoto [this message]
2020-05-08 4:36 ` [PATCH 08/10] ALSA: firewire-lib: add cache for packet sequence to AMDTP domain structure Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 09/10] ALSA: firewire-lib: pool ideal sequence of syt offset and data block Takashi Sakamoto
2020-05-08 4:36 ` [PATCH 10/10] ALSA: firewire-lib: use sequence of syt offset and data block on pool in AMDTP domain Takashi Sakamoto
2020-05-08 7:48 ` [PATCH 00/10] ALSA: firewire-lib: pool sequence of syt offset and data blocks in AMDTP domain structure Takashi Iwai
2020-10-11 8:16 [PATCH 07/10] ALSA: firewire-lib: code refactoring for data block calculation MICHAEL Mosier
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=20200508043635.349339-8-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).