From patchwork Tue May 21 13:32:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10953951 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 EB1731708 for ; Tue, 21 May 2019 14:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAD11289CC for ; Tue, 21 May 2019 14:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF517289CB; Tue, 21 May 2019 14:42:29 +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 886A4289F0 for ; Tue, 21 May 2019 14:42:28 +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 6921A1657; Tue, 21 May 2019 15:46:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6921A1657 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558446429; bh=Q9w2o+qCouNS/g9J789xYYk+LoUhlnWaeeASp5YEooY=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=SoVFPY4qsiAVWUiqWc6hY0ikXKoW8j5PVvFmoehL4n/wh4WrjvtsNqgpHGQWb7uYS UHW5ZgA8VUk+py5ZE+wpcGjPgSEeadNJMQi+zYBoTQx2ALiZk6G2QuMnclFuO0rpwU dvFtla3i7IBw+mDw1lejtojlYKn/oOt2gePn3YnU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 76738F89670; Tue, 21 May 2019 15:46:18 +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 76361F89723; Tue, 21 May 2019 15:43:06 +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 5DF82F89674; Tue, 21 May 2019 15:32:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5DF82F89674 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 263C63C00D1; Tue, 21 May 2019 15:32:58 +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 Q_DFrGFa2gVk; Tue, 21 May 2019 15:32: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 8A93B3C005E; Tue, 21 May 2019 15:32: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; Tue, 21 May 2019 15:32:47 +0200 From: Adam Miartus To: Date: Tue, 21 May 2019 15:32:47 +0200 Message-ID: <1558445567-11480-1-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - alsa-lib 1/4] pcm_file: add support for infile reading in non interleaved 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 add helper function to copy input file data to buffer mapped by areas, in case of an error, do not fill the areas, allowing device read buffer to be provided to api caller previously unused rbuf variable is reused for this purpose Signed-off-by: Adam Miartus Reviewed-by: Timo Wischer diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 3a19cef..3c68265 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -77,6 +77,7 @@ typedef struct { snd_pcm_uframes_t appl_ptr; snd_pcm_uframes_t file_ptr_bytes; snd_pcm_uframes_t wbuf_size; + snd_pcm_uframes_t rbuf_size; size_t wbuf_size_bytes; size_t wbuf_used_bytes; char *wbuf; @@ -266,6 +267,39 @@ static int snd_pcm_file_open_output_file(snd_pcm_file_t *file) return 0; } +/* fill areas with data from input file, return bytes red */ +static int snd_pcm_file_areas_read_infile(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]; + ssize_t bytes; + + if (file->ifd < 0) + return -EBADF; + + if (file->rbuf == NULL) + return -ENOMEM; + + if (file->rbuf_size < frames) { + SYSERR("requested more frames than pcm buffer"); + return -ENOMEM; + } + + bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm, frames)); + if (bytes < 0) { + SYSERR("read from file failed, error: %d", bytes); + return bytes; + } + + snd_pcm_areas_from_buf(pcm, areas_if, file->rbuf); + snd_pcm_areas_copy(areas, offset, areas_if, 0, pcm->channels, snd_pcm_bytes_to_frames(pcm, bytes), pcm->format); + + return bytes; +} + static void setup_wav_header(snd_pcm_t *pcm, struct wav_fmt *fmt) { fmt->fmt = TO_LE16(0x01); @@ -568,19 +602,19 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm { snd_pcm_file_t *file = pcm->private_data; snd_pcm_channel_area_t areas[pcm->channels]; - snd_pcm_sframes_t n; + snd_pcm_sframes_t frames; - if (file->ifd >= 0) { - SNDERR("DEBUG: Noninterleaved read not yet implemented.\n"); - return 0; /* TODO: Noninterleaved read */ - } + __snd_pcm_lock(pcm); + frames = _snd_pcm_readn(file->gen.slave, bufs, size); + if (frames <= 0) + return frames; - n = _snd_pcm_readn(file->gen.slave, bufs, size); - if (n > 0) { - snd_pcm_areas_from_bufs(pcm, areas, bufs); - snd_pcm_file_add_frames(pcm, areas, 0, n); - } - return n; + snd_pcm_areas_from_bufs(pcm, areas, bufs); + snd_pcm_file_areas_read_infile(pcm, areas, 0, frames); + snd_pcm_file_add_frames(pcm, areas, 0, frames); + + __snd_pcm_unlock(pcm); + return frames; } static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm, @@ -609,9 +643,11 @@ static int snd_pcm_file_hw_free(snd_pcm_t *pcm) free(file->wbuf); free(file->wbuf_areas); free(file->final_fname); + free(file->rbuf); file->wbuf = NULL; file->wbuf_areas = NULL; file->final_fname = NULL; + file->rbuf = NULL; return snd_pcm_hw_free(file->gen.slave); } @@ -638,6 +674,15 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) snd_pcm_file_hw_free(pcm); return -ENOMEM; } + assert(!file->rbuf); + file->rbuf_size = slave->buffer_size; + file->rbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->rbuf_size); + file->rbuf_used_bytes = 0; + file->rbuf = malloc(file->rbuf_size_bytes); + if (file->rbuf == NULL) { + snd_pcm_file_hw_free(pcm); + return -ENOMEM; + } file->appl_ptr = file->file_ptr_bytes = 0; for (channel = 0; channel < slave->channels; ++channel) { snd_pcm_channel_area_t *a = &file->wbuf_areas[channel]; From patchwork Tue May 21 13:33:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10954361 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 C71841395 for ; Tue, 21 May 2019 17:27:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAAF2289E8 for ; Tue, 21 May 2019 17:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EC8728A9B; Tue, 21 May 2019 17:27:29 +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 B05FB289E8 for ; Tue, 21 May 2019 17:27:28 +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 B66671666; Tue, 21 May 2019 15:47:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B66671666 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558446501; bh=ENKUMhqWBJEN7KUMgP1Xpb9Kz5mgtZHUhsKOzlTDq8I=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=keMuGEE08jF68T1cphvgrU/JKMVknnPLExsZU8b3fxMgsOEbwlBowjZppnj+srUbd EtU4AuOdAYSQ624raoUf289NYmuDYvAOQqCBZwXwE48n1PMdPhX6nWqDmfFu5aEjJp npgSQa2PTe1lFgJFwRS97vvnezdLhMRIPznkE+0A= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D61B4F89709; Tue, 21 May 2019 15:47:30 +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 27F5CF89725; Tue, 21 May 2019 15:43:22 +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 40BBFF89633; Tue, 21 May 2019 15:33:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 40BBFF89633 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 087C83C00D1; Tue, 21 May 2019 15:33:16 +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 7cm6mPv_1nqS; Tue, 21 May 2019 15:33:09 +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 6F4E13C005E; Tue, 21 May 2019 15:33:09 +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; Tue, 21 May 2019 15:33:09 +0200 From: Adam Miartus To: Date: Tue, 21 May 2019 15:33:08 +0200 Message-ID: <1558445588-11524-1-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - alsa-lib 2/4] pcm_file: use snd_pcm_file_areas_read_infile for readi 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 use previously introduced helper function, this commit unifies behavior of readi and readn corner case behavior of readi is changed by this commit, previously, in case 0 bytes were red from file (EOF), frames = 0 was returned, signaling api user as if no data was red from slave, after the patch, amount of frames red from slave with data red from slave stored in buffer is returned when EOF is reached Signed-off-by: Adam Miartus Reviewed-by: Timo Wischer diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 3c68265..dcaa41d 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -579,22 +579,21 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc { snd_pcm_file_t *file = pcm->private_data; snd_pcm_channel_area_t areas[pcm->channels]; - snd_pcm_sframes_t n; + snd_pcm_sframes_t frames; + + __snd_pcm_lock(pcm); + + frames = _snd_pcm_readi(file->gen.slave, buffer, size); + if (frames <= 0) + return frames; - n = _snd_pcm_readi(file->gen.slave, buffer, size); - if (n <= 0) - return n; - if (file->ifd >= 0) { - __snd_pcm_lock(pcm); - n = read(file->ifd, buffer, n * pcm->frame_bits / 8); - __snd_pcm_unlock(pcm); - if (n < 0) - return n; - n = n * 8 / pcm->frame_bits; - } snd_pcm_areas_from_buf(pcm, areas, buffer); - snd_pcm_file_add_frames(pcm, areas, 0, n); - return n; + snd_pcm_file_areas_read_infile(pcm, areas, 0, frames); + snd_pcm_file_add_frames(pcm, areas, 0, frames); + + __snd_pcm_unlock(pcm); + + return frames; } /* locking */ From patchwork Tue May 21 13:33:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10954363 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 240C176 for ; Tue, 21 May 2019 17:27:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07261289E8 for ; Tue, 21 May 2019 17:27:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED67228A9B; Tue, 21 May 2019 17:27:29 +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 B065E28A53 for ; Tue, 21 May 2019 17:27:28 +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 9EF13165F; Tue, 21 May 2019 15:47:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9EF13165F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558446516; bh=UvlP2PHae3MEzUYZtK6BX1w6Hau33RNR284PMfmF1A0=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=coyL98YBmdzb1a5UMwm1yVFu8C5DjROTi4jjNYM0iy4bLFcvlShoZ/OXX97qTlR1P m7JfWVArEAmCYnfr96z99HEqHxMBxP60c78CYiD1kgOe2V1u/xQ7FGUtg+XTUN55Hq wdAft13HwuTYYUm3j9TZisTCyMrrsBxtDKJeWHqs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E2D13F89707; Tue, 21 May 2019 15:47:39 +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 3A9D4F89674; Tue, 21 May 2019 15:43:43 +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 5F82CF89670; Tue, 21 May 2019 15:33:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5F82CF89670 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 17B0A3C00D1; Tue, 21 May 2019 15:33:37 +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 M8ck9O0ZNIB6; Tue, 21 May 2019 15:33:30 +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 35A333C005E; Tue, 21 May 2019 15:33:30 +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; Tue, 21 May 2019 15:33:29 +0200 From: Adam Miartus To: Date: Tue, 21 May 2019 15:33:29 +0200 Message-ID: <1558445609-11567-1-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - alsa-lib 3/4] 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 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_dmix.c b/src/pcm/pcm_dmix.c index 274726e..96049e0 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -990,6 +990,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dmix_fast_ops = { .poll_descriptors = snd_pcm_direct_poll_descriptors, .poll_descriptors_count = NULL, .poll_revents = snd_pcm_dmix_poll_revents, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index b75809c..328ef83 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -667,6 +667,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dshare_fast_ops = { .poll_descriptors = snd_pcm_direct_poll_descriptors, .poll_descriptors_count = NULL, .poll_revents = snd_pcm_direct_poll_revents, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c index 58b1e53..5b9d9f5 100644 --- a/src/pcm/pcm_dsnoop.c +++ b/src/pcm/pcm_dsnoop.c @@ -544,6 +544,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dsnoop_fast_ops = { .poll_descriptors = snd_pcm_direct_poll_descriptors, .poll_descriptors_count = NULL, .poll_revents = snd_pcm_direct_poll_revents, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index dcaa41d..10d227b 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -773,6 +773,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 = NULL, }; /** diff --git a/src/pcm/pcm_generic.h b/src/pcm/pcm_generic.h index dfbe21a..683e60b 100644 --- a/src/pcm/pcm_generic.h +++ b/src/pcm/pcm_generic.h @@ -161,4 +161,3 @@ snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm); snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm); int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map); int snd_pcm_generic_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail); - diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c index 4416d36..14396fa 100644 --- a/src/pcm/pcm_hooks.c +++ b/src/pcm/pcm_hooks.c @@ -200,6 +200,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hooks_fast_ops = { .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_generic_poll_revents, .may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 91370a8..8ee1d69 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1481,6 +1481,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = { .poll_descriptors = NULL, .poll_descriptors_count = NULL, .poll_revents = NULL, + .mmap_begin = NULL, }; static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops_timer = { @@ -1512,6 +1513,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops_timer = { .poll_descriptors = snd_pcm_hw_poll_descriptors, .poll_descriptors_count = snd_pcm_hw_poll_descriptors_count, .poll_revents = snd_pcm_hw_poll_revents, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index a437ca3..3e19499 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -940,6 +940,7 @@ static const snd_pcm_fast_ops_t snd_pcm_ioplug_fast_ops = { .poll_descriptors_count = snd_pcm_ioplug_poll_descriptors_count, .poll_descriptors = snd_pcm_ioplug_poll_descriptors, .poll_revents = snd_pcm_ioplug_poll_revents, + .mmap_begin = NULL, }; #endif /* !DOC_HIDDEN */ 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 { diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c index 20b4187..28bb578 100644 --- a/src/pcm/pcm_meter.c +++ b/src/pcm/pcm_meter.c @@ -548,6 +548,7 @@ static const snd_pcm_fast_ops_t snd_pcm_meter_fast_ops = { .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_generic_poll_revents, .may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_mmap_emul.c b/src/pcm/pcm_mmap_emul.c index 009cebb..6fa5fe6 100644 --- a/src/pcm/pcm_mmap_emul.c +++ b/src/pcm/pcm_mmap_emul.c @@ -401,6 +401,7 @@ static const snd_pcm_fast_ops_t snd_pcm_mmap_emul_fast_ops = { .poll_descriptors_count = snd_pcm_generic_poll_descriptors_count, .poll_revents = snd_pcm_generic_poll_revents, .may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min, + .mmap_begin = NULL, }; #ifndef DOC_HIDDEN diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 53c414d..069d224 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -1042,6 +1042,7 @@ static const snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = { .poll_descriptors = snd_pcm_multi_poll_descriptors, .poll_revents = snd_pcm_multi_poll_revents, .may_wait_for_avail_min = snd_pcm_multi_may_wait_for_avail_min, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c index 1d81548..e6fa049 100644 --- a/src/pcm/pcm_null.c +++ b/src/pcm/pcm_null.c @@ -361,6 +361,7 @@ static const snd_pcm_fast_ops_t snd_pcm_null_fast_ops = { .avail_update = snd_pcm_null_avail_update, .mmap_commit = snd_pcm_null_mmap_commit, .htimestamp = snd_pcm_generic_real_htimestamp, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c index ea60eb9..0714d2c 100644 --- a/src/pcm/pcm_plugin.c +++ b/src/pcm/pcm_plugin.c @@ -646,6 +646,7 @@ const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops = { .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_generic_poll_revents, .may_wait_for_avail_min = snd_pcm_plugin_may_wait_for_avail_min, + .mmap_begin = NULL, }; #endif diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 5dc8a92..f29739b 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -1217,6 +1217,7 @@ static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = { .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_rate_poll_revents, .may_wait_for_avail_min = snd_pcm_plugin_may_wait_for_avail_min, + .mmap_begin = NULL, }; static const snd_pcm_ops_t snd_pcm_rate_ops = { diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index 5a540c4..b803a82 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -1346,6 +1346,7 @@ static const snd_pcm_fast_ops_t snd_pcm_share_fast_ops = { .avail_update = snd_pcm_share_avail_update, .htimestamp = snd_pcm_share_htimestamp, .mmap_commit = snd_pcm_share_mmap_commit, + .mmap_begin = NULL, }; /** diff --git a/src/pcm/pcm_shm.c b/src/pcm/pcm_shm.c index 26a27a5..a18720f 100644 --- a/src/pcm/pcm_shm.c +++ b/src/pcm/pcm_shm.c @@ -629,6 +629,7 @@ static const snd_pcm_fast_ops_t snd_pcm_shm_fast_ops = { .avail_update = snd_pcm_shm_avail_update, .mmap_commit = snd_pcm_shm_mmap_commit, .htimestamp = snd_pcm_shm_htimestamp, + .mmap_begin = NULL, }; static int make_local_socket(const char *filename) From patchwork Tue May 21 13:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Miartus X-Patchwork-Id: 10954365 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 5669576 for ; Tue, 21 May 2019 17:27:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37F6828A53 for ; Tue, 21 May 2019 17:27:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C4B528A85; Tue, 21 May 2019 17:27:31 +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 B601828A80 for ; Tue, 21 May 2019 17:27:28 +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 29B291681; Tue, 21 May 2019 15:48:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 29B291681 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558446556; bh=g5IPFzrVrxvOYlDdh+tIxiQuce2s+Fn97wKAGxB0V7o=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=mNHVSfYmTxrPnaNpE5Dq1B8G6US6FSYAbBVrziP/8QlGswQ3xCkRVkaEkffQO7dF1 PSeiiH2h/UjpqQZPeTVh8Z4/029Ql9h7T5ZSqazMppjR2U72QvHusmXbDZW/RHCJG0 k3GhrrUKqYMW5aRfxZX25kZyvtRnP3Ri9irRRmz4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E3BD5F89730; Tue, 21 May 2019 15:47:50 +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 2BBF2F89670; Tue, 21 May 2019 15:44:04 +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 E6F37F89709; Tue, 21 May 2019 15:33:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E6F37F89709 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id B5DF23C00D1; Tue, 21 May 2019 15:33:57 +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 igySFf_GHeXl; Tue, 21 May 2019 15:33:51 +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 31F023C005E; Tue, 21 May 2019 15:33:51 +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; Tue, 21 May 2019 15:33:50 +0200 From: Adam Miartus To: Date: Tue, 21 May 2019 15:33:50 +0200 Message-ID: <1558445630-11610-1-git-send-email-amiartus@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.164] Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - alsa-lib 4/4] 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 diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 10d227b..7d3439a 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 @@ -626,6 +627,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); @@ -636,6 +639,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; @@ -662,6 +691,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) { @@ -773,7 +803,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 = NULL, + .mmap_begin = snd_pcm_file_mmap_begin, }; /**