From: Andre Guedes <andre.guedes@intel.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, liam.r.girdwood@intel.com
Subject: [PATCH - AAF PCM plugin 4/7] aaf: Prepare for Capture mode support
Date: Wed, 3 Oct 2018 16:45:44 -0700 [thread overview]
Message-ID: <20181003234547.16839-5-andre.guedes@intel.com> (raw)
In-Reply-To: <20181003234547.16839-1-andre.guedes@intel.com>
The plugin code assumes only Playback mode is supported. This patch
prepares the code to support both Playback and Capture mode. Capture
mode support is implemented by a follow-up patch.
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
---
aaf/pcm_aaf.c | 159 ++++++++++++++++++++++++++++++++++------------------------
1 file changed, 94 insertions(+), 65 deletions(-)
diff --git a/aaf/pcm_aaf.c b/aaf/pcm_aaf.c
index 8f8bcfd..74cda97 100644
--- a/aaf/pcm_aaf.c
+++ b/aaf/pcm_aaf.c
@@ -239,6 +239,7 @@ static int aaf_init_socket(snd_pcm_aaf_t *aaf)
{
int fd, res;
struct ifreq req;
+ snd_pcm_ioplug_t *io = &aaf->io;
fd = socket(AF_PACKET, SOCK_DGRAM|SOCK_NONBLOCK, htons(ETH_P_TSN));
if (fd < 0) {
@@ -260,12 +261,17 @@ static int aaf_init_socket(snd_pcm_aaf_t *aaf)
aaf->sk_addr.sll_ifindex = req.ifr_ifindex;
memcpy(&aaf->sk_addr.sll_addr, aaf->addr, ETH_ALEN);
- res = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &aaf->prio,
- sizeof(aaf->prio));
- if (res < 0) {
- SNDERR("Failed to set socket priority");
- res = -errno;
- goto err;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ res = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &aaf->prio,
+ sizeof(aaf->prio));
+ if (res < 0) {
+ SNDERR("Failed to set socket priority");
+ res = -errno;
+ goto err;
+ }
+ } else {
+ /* TODO: Implement Capture mode support. */
+ return -ENOTSUP;
}
aaf->sk_fd = fd;
@@ -305,46 +311,50 @@ static int aaf_init_pdu(snd_pcm_aaf_t *aaf)
if (!pdu)
return -ENOMEM;
- res = avtp_aaf_pdu_init(pdu);
- if (res < 0)
- goto err;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ res = avtp_aaf_pdu_init(pdu);
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_TV, 1);
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_TV, 1);
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_STREAM_ID, aaf->streamid);
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_STREAM_ID,
+ aaf->streamid);
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_FORMAT,
- alsa_to_avtp_format(io->format));
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_FORMAT,
+ alsa_to_avtp_format(io->format));
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_NSR,
- alsa_to_avtp_rate(io->rate));
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_NSR,
+ alsa_to_avtp_rate(io->rate));
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_CHAN_PER_FRAME,
- io->channels);
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_CHAN_PER_FRAME,
+ io->channels);
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_BIT_DEPTH,
- snd_pcm_format_width(io->format));
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_BIT_DEPTH,
+ snd_pcm_format_width(io->format));
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_STREAM_DATA_LEN,
- payload_size);
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_STREAM_DATA_LEN,
+ payload_size);
+ if (res < 0)
+ goto err;
- res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_SP, AVTP_AAF_PCM_SP_NORMAL);
- if (res < 0)
- goto err;
+ res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_SP,
+ AVTP_AAF_PCM_SP_NORMAL);
+ if (res < 0)
+ goto err;
+ }
aaf->pdu = pdu;
aaf->pdu_size = pdu_size;
@@ -707,7 +717,10 @@ static snd_pcm_sframes_t aaf_pointer(snd_pcm_ioplug_t *io)
static int aaf_poll_descriptors_count(snd_pcm_ioplug_t *io ATTRIBUTE_UNUSED)
{
- return FD_COUNT_PLAYBACK;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK)
+ return FD_COUNT_PLAYBACK;
+ else
+ return -ENOTSUP;
}
static int aaf_poll_descriptors(snd_pcm_ioplug_t *io, struct pollfd *pfd,
@@ -715,11 +728,17 @@ static int aaf_poll_descriptors(snd_pcm_ioplug_t *io, struct pollfd *pfd,
{
snd_pcm_aaf_t *aaf = io->private_data;
- if (space != FD_COUNT_PLAYBACK)
- return -EINVAL;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ if (space != FD_COUNT_PLAYBACK)
+ return -EINVAL;
+
+ pfd[0].fd = aaf->timer_fd;
+ pfd[0].events = POLLIN;
+ } else {
+ /* TODO: Implement Capture mode support. */
+ return -ENOTSUP;
+ }
- pfd[0].fd = aaf->timer_fd;
- pfd[0].events = POLLIN;
return space;
}
@@ -729,15 +748,20 @@ static int aaf_poll_revents(snd_pcm_ioplug_t *io, struct pollfd *pfd,
int res;
snd_pcm_aaf_t *aaf = io->private_data;
- if (nfds != FD_COUNT_PLAYBACK)
- return -EINVAL;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ if (nfds != FD_COUNT_PLAYBACK)
+ return -EINVAL;
- if (pfd[0].revents & POLLIN) {
- res = aaf_mclk_timeout_playback(aaf);
- if (res < 0)
- return res;
+ if (pfd[0].revents & POLLIN) {
+ res = aaf_mclk_timeout_playback(aaf);
+ if (res < 0)
+ return res;
- *revents = POLLIN;
+ *revents = POLLIN;
+ }
+ } else {
+ /* TODO: Implement Capture mode support. */
+ return -ENOTSUP;
}
return 0;
@@ -763,9 +787,14 @@ static int aaf_start(snd_pcm_ioplug_t *io)
int res;
snd_pcm_aaf_t *aaf = io->private_data;
- res = aaf_mclk_start_playback(aaf);
- if (res < 0)
- return res;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ res = aaf_mclk_start_playback(aaf);
+ if (res < 0)
+ return res;
+ } else {
+ /* TODO: Implement Capture mode support. */
+ return -ENOTSUP;
+ }
return 0;
}
@@ -790,12 +819,18 @@ static snd_pcm_sframes_t aaf_transfer(snd_pcm_ioplug_t *io,
int res;
snd_pcm_aaf_t *aaf = io->private_data;
- res = snd_pcm_areas_copy_wrap(aaf->audiobuf_areas,
- (io->appl_ptr % io->buffer_size),
- io->buffer_size, areas, offset, size,
- io->channels, size, io->format);
- if (res < 0)
- return res;
+ if (io->stream == SND_PCM_STREAM_PLAYBACK) {
+ res = snd_pcm_areas_copy_wrap(aaf->audiobuf_areas,
+ (io->appl_ptr % io->buffer_size),
+ io->buffer_size, areas, offset,
+ size, io->channels, size,
+ io->format);
+ if (res < 0)
+ return res;
+ } else {
+ /* TODO: Implement Capture mode support. */
+ return -ENOTSUP;
+ }
return size;
}
@@ -820,12 +855,6 @@ SND_PCM_PLUGIN_DEFINE_FUNC(aaf)
snd_pcm_aaf_t *aaf;
int res;
- /* For now the plugin only supports Playback mode i.e. AAF Talker
- * functionality.
- */
- if (stream != SND_PCM_STREAM_PLAYBACK)
- return -EINVAL;
-
aaf = calloc(1, sizeof(*aaf));
if (!aaf) {
SNDERR("Failed to allocate memory");
--
2.14.4
next prev parent reply other threads:[~2018-10-03 23:46 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-03 23:45 [PATCH - AAF PCM plugin 0/7] Introduce AVTP Audio Format (AAF) plugin Andre Guedes
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 1/7] aaf: Introduce plugin skeleton Andre Guedes
2018-10-10 10:27 ` Takashi Iwai
2018-10-10 21:22 ` Guedes, Andre
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 2/7] aaf: Load configuration parameters Andre Guedes
2018-10-10 10:29 ` Takashi Iwai
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 3/7] aaf: Implement Playback mode support Andre Guedes
2018-10-10 10:34 ` Takashi Iwai
2018-10-10 21:27 ` Guedes, Andre
2018-10-11 7:31 ` Takashi Iwai
2018-10-11 7:45 ` Takashi Sakamoto
2018-10-11 8:00 ` Takashi Iwai
2018-10-11 19:53 ` Guedes, Andre
2018-10-03 23:45 ` Andre Guedes [this message]
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 5/7] aaf: Implement Capture " Andre Guedes
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 6/7] aaf: Implement dump() ioplug callback Andre Guedes
2018-10-03 23:45 ` [PATCH - AAF PCM plugin 7/7] aaf: Add support for direct read/write transfers Andre Guedes
2018-10-10 10:25 ` [PATCH - AAF PCM plugin 0/7] Introduce AVTP Audio Format (AAF) plugin Takashi Iwai
2018-10-10 21:19 ` Guedes, Andre
2018-10-22 16:51 ` Pierre-Louis Bossart
2018-10-23 20:01 ` Guedes, Andre
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=20181003234547.16839-5-andre.guedes@intel.com \
--to=andre.guedes@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=liam.r.girdwood@intel.com \
--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