From patchwork Wed Oct 3 23:45:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guedes, Andre" X-Patchwork-Id: 10625401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44FB21515 for ; Wed, 3 Oct 2018 23:47:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3198F2906E for ; Wed, 3 Oct 2018 23:47:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25F952907B; Wed, 3 Oct 2018 23:47:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DD532906E for ; Wed, 3 Oct 2018 23:47:31 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 896422678FD; Thu, 4 Oct 2018 01:47:04 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 65A0D2678BE; Thu, 4 Oct 2018 01:46:56 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by alsa0.perex.cz (Postfix) with ESMTP id 5D706267845 for ; Thu, 4 Oct 2018 01:46:52 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Oct 2018 16:46:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,338,1534834800"; d="scan'208";a="269308276" Received: from aguedesl-mobl1.jf.intel.com ([10.24.14.71]) by fmsmga006.fm.intel.com with ESMTP; 03 Oct 2018 16:46:43 -0700 From: Andre Guedes To: alsa-devel@alsa-project.org Date: Wed, 3 Oct 2018 16:45:44 -0700 Message-Id: <20181003234547.16839-5-andre.guedes@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181003234547.16839-1-andre.guedes@intel.com> References: <20181003234547.16839-1-andre.guedes@intel.com> Cc: tiwai@suse.de, liam.r.girdwood@intel.com Subject: [alsa-devel] [PATCH - AAF PCM plugin 4/7] aaf: Prepare for Capture mode support X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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");