From patchwork Thu May 23 13:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10957595 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 E611A76 for ; Thu, 23 May 2019 13:02:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBBDA28415 for ; Thu, 23 May 2019 13:02:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C03C628438; Thu, 23 May 2019 13:02:53 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 16E7228415 for ; Thu, 23 May 2019 13:02:53 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C215A1680; Thu, 23 May 2019 15:02:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C215A1680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558616570; bh=9cUZN/Ipxmwi0RewW70Rw+Aop3gXfwvi7eZ+5r3UY+8=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uLNwAkgDY9EHwOG6Ba4D3YH/NobRK8faQA3DZXTVUlUdbXWTEOALHYkpRDvAGfqfk 1xfNAztaSHuaDNKwN4MVJOVcYWMUWgsYeYUyoTstlk4iVFdD3wetobYC+cVfgpGnDZ sacyG4Kv8MQnzUrFmnRRhub0Xnl9fF/Hg0yUHnxY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E3EDFF80C0F; Thu, 23 May 2019 15:01:07 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 18CFCF89709; Thu, 23 May 2019 15:01:03 +0200 (CEST) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 57C97F89670; Thu, 23 May 2019 15:00:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 57C97F89670 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 9A1B53C005E; Thu, 23 May 2019 15:00:55 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wu7e33ndPn3H; Thu, 23 May 2019 15:00:48 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id CE6D53C00D1; Thu, 23 May 2019 15:00:48 +0200 (CEST) Received: from vmlxhi-082.adit-jv.com (10.72.93.164) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 15:00:48 +0200 From: Adam Miartus To: Date: Thu, 23 May 2019 15:00:39 +0200 Message-ID: <1558616440-21044-2-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558616440-21044-1-git-send-email-amiartus@de.adit-jv.com> References: <1558616440-21044-1-git-send-email-amiartus@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 1/2] pcm: add mmap_begin callback to snd_pcm_fast_ops_t api X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP main motivation for adding the callback is to use it to enable operation on mmaped buffer before user access for pcm_file plugin support for MMAP read access with masking by data from input file is not implemented for pcm_file plugin, by adding this callback implementing such feature can be done by rewriting next continuous portion of buffer on each mmap_begin call plugins like softvol use pcm_plugin interface and overwrite the buffer by looping around it in avail_update callback, this patch hopes to simplify the task by adding new api callback, removing the need for rewriting pcm_file (to use pcm_plugin callbacks) and careful checking when looping around whole mmaped buffer Signed-off-by: Adam Miartus Reviewed-by: Timo Wischer --- src/pcm/pcm.c | 6 ++++++ src/pcm/pcm_local.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 3a71d79..323926e 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -7129,7 +7129,13 @@ int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t f; snd_pcm_uframes_t avail; const snd_pcm_channel_area_t *xareas; + assert(pcm && areas && offset && frames); + + if (pcm->fast_ops->mmap_begin) + return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames); + + /* fallback for plugins that do not specify new callback */ xareas = snd_pcm_mmap_areas(pcm); if (xareas == NULL) return -EBADFD; diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index d52229d..d5726eb 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -184,6 +184,7 @@ typedef struct { int (*poll_descriptors)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space); /* locked */ int (*poll_revents)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents); /* locked */ int (*may_wait_for_avail_min)(snd_pcm_t *pcm, snd_pcm_uframes_t avail); + int (*mmap_begin)(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames); /* locked */ } snd_pcm_fast_ops_t; struct _snd_pcm { From patchwork Thu May 23 13:00:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10957597 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 131DF76 for ; Thu, 23 May 2019 13:03:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC0ED2851E for ; Thu, 23 May 2019 13:03:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E003E2850F; Thu, 23 May 2019 13:03:39 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 320252850F for ; Thu, 23 May 2019 13:03:39 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 4AD501664; Thu, 23 May 2019 15:02:47 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4AD501664 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558616617; bh=nsEP7FHZS8bI6oNA8yvRdNtW4LDepiK31KIGRSoKImc=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ruZ6EaznHDinnS5RR5hC7PAc4o6U7crB2CNivb96tuidYQ+lMBoEHmeDkJNo2DsBc 6/KNQ9PFVcKQ0gdIjfMglMIA1HhB3snfAOg1W2ZS8ysHuPbeE9tw73NJg+dmSYMtWL tnuGSQPSXBW3gKaerUkGimtwOHniLdB2iAmm0ehM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 754B1F8972D; Thu, 23 May 2019 15:01:11 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 809A7F89725; Thu, 23 May 2019 15:01:07 +0200 (CEST) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DC9F0F80C0F; Thu, 23 May 2019 15:01:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DC9F0F80C0F Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id AE8533C005E; Thu, 23 May 2019 15:01:01 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9ZRrz5wLgsF6; Thu, 23 May 2019 15:00:55 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 489473C00DD; Thu, 23 May 2019 15:00:49 +0200 (CEST) Received: from vmlxhi-082.adit-jv.com (10.72.93.164) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 15:00:48 +0200 From: Adam Miartus To: Date: Thu, 23 May 2019 15:00:40 +0200 Message-ID: <1558616440-21044-3-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558616440-21044-1-git-send-email-amiartus@de.adit-jv.com> References: <1558616440-21044-1-git-send-email-amiartus@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 2/2] pcm_file: add infile read support for mmap mode X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP mmap_begin callback is used to copy data from input file to mmaped buffer guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten buffer is overwritten with input file data only in case of stream capture Signed-off-by: Adam Miartus Reviewed-by: Timo Wischer --- src/pcm/pcm_file.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 8e2c70b..52cc10a 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -88,6 +88,7 @@ typedef struct { size_t buffer_bytes; struct wav_fmt wav_header; size_t filelen; + char ifmmap_overwritten; } snd_pcm_file_t; #if __BYTE_ORDER == __LITTLE_ENDIAN @@ -630,6 +631,8 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas; snd_pcm_sframes_t result; + file->ifmmap_overwritten = 0; + result = snd_pcm_mmap_begin(file->gen.slave, &areas, &ofs, &siz); if (result >= 0) { assert(ofs == offset && siz == size); @@ -640,6 +643,32 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm, return result; } +static int snd_pcm_file_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, + snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames) +{ + snd_pcm_file_t *file = pcm->private_data; + snd_pcm_channel_area_t areas_if[pcm->channels]; + snd_pcm_uframes_t frames_if; + void *buffer = NULL; + int result; + + result = snd_pcm_mmap_begin(file->gen.slave, areas, offset, frames); + if (result < 0) + return result; + + if (pcm->stream != SND_PCM_STREAM_CAPTURE) + return result; + + /* user may run mmap_begin without mmap_commit multiple times in row */ + if (file->ifmmap_overwritten) + return result; + file->ifmmap_overwritten = 1; + + snd_pcm_file_areas_read_infile(pcm, *areas, *offset, *frames); + + return result; +} + static int snd_pcm_file_hw_free(snd_pcm_t *pcm) { snd_pcm_file_t *file = pcm->private_data; @@ -666,6 +695,7 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) file->wbuf_size = slave->buffer_size * 2; file->wbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->wbuf_size); file->wbuf_used_bytes = 0; + file->ifmmap_overwritten = 0; assert(!file->wbuf); file->wbuf = malloc(file->wbuf_size_bytes); if (file->wbuf == NULL) { @@ -777,6 +807,7 @@ static const snd_pcm_fast_ops_t snd_pcm_file_fast_ops = { .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_generic_poll_revents, .htimestamp = snd_pcm_generic_htimestamp, + .mmap_begin = snd_pcm_file_mmap_begin, }; /**