From patchwork Thu Apr 24 14:40:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Patrakov X-Patchwork-Id: 4051591 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A18FBFF02 for ; Thu, 24 Apr 2014 14:44:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5416120306 for ; Thu, 24 Apr 2014 14:44:02 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 9587420303 for ; Thu, 24 Apr 2014 14:43:59 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id F383526530E; Thu, 24 Apr 2014 16:43:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id ED2382652B4; Thu, 24 Apr 2014 16:43:46 +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 6D90F2652C2; Thu, 24 Apr 2014 16:43:45 +0200 (CEST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by alsa0.perex.cz (Postfix) with ESMTP id 6774B265272 for ; Thu, 24 Apr 2014 16:43:37 +0200 (CEST) Received: by mail-lb0-f176.google.com with SMTP id 10so2079525lbg.35 for ; Thu, 24 Apr 2014 07:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U2M3Xdt/9clJ4vVv27dTDoZSuFQT9vJYcmOg3frBNgo=; b=tVAcHvUsyc6in8nTzA3KXNz4DLStS9Ter9vLcjfHVM2drAlwYQ02HORzdDfy8vVEfc cD5J+wLY5Ear7ySvdZkxd8gQmxCD/9kxEDnTPPHxkxix5Cs//u49h9drA8Dw4qv3MLy9 i99jJ9dYHIlgI2/9ZzB8/eGFrP0/rvHtK/DVwg3NLZEfADLhF4sc9CsG7tZgP+u72ivI kaNMDOoNGJEuxSGrndIEhFz6hxvHB2uZjmwGzRvlSzGsKYJZcWW6PF8lGfUaJ8C32KJ2 x/f+r4GnT6+LslMCWzOv7ypm5OUd9mL8keM/JjeTSdgwlZMjR+xPb474nSdm+8FuP2Jb rNQg== X-Received: by 10.152.2.99 with SMTP id 3mr1508084lat.51.1398350616905; Thu, 24 Apr 2014 07:43:36 -0700 (PDT) Received: from localhost.localdomain (111279190.convex.ru. [82.193.153.141]) by mx.google.com with ESMTPSA id x5sm4735750lbk.5.2014.04.24.07.43.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Apr 2014 07:43:35 -0700 (PDT) From: "Alexander E. Patrakov" To: alsa-devel@alsa-project.org Date: Thu, 24 Apr 2014 20:40:06 +0600 Message-Id: <1398350406-10347-1-git-send-email-patrakov@gmail.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <5358F356.3020701@canonical.com> References: <5358F356.3020701@canonical.com> Cc: tiwai@suse.de, "Alexander E. Patrakov" Subject: [alsa-devel] [PATCH v2] Fix forward/rewind support in iec958 plugin 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 When forwarding or rewinding, the frame counter was not updated. This could result in corrupted channel status words or misplaced Z-type preamble. Signed-off-by: Alexander E. Patrakov --- v2: As suggested by David Henningsson, patch a copy of snd_pcm_plugin_fast_ops at runtime instead of making all plugin finctions non-static. But, contrary to his proposal, I made fast_ops just a part of struct snd_pcm_iec958, because the needed lifetime is exactly the same. I still have no hardware to test this, and I strongly suspect that the patch is wrong, because nobody else uses dynamic allocation of fast_ops. A potentially suspicious operation would be to place a plug on top of this, because plug copies fast_ops around. However, each time it closes a slave, it also resets fast_ops to something sane, or at least I think so. src/pcm/pcm_iec958.c | 37 ++++++++++++++++++++++++++++++++++++- src/pcm/pcm_plugin.c | 4 ++-- src/pcm/pcm_plugin.h | 6 ++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/pcm/pcm_iec958.c b/src/pcm/pcm_iec958.c index d81b0a1..0c61fc1 100644 --- a/src/pcm/pcm_iec958.c +++ b/src/pcm/pcm_iec958.c @@ -62,6 +62,7 @@ struct snd_pcm_iec958 { unsigned char status[24]; unsigned int byteswap; unsigned char preamble[3]; /* B/M/W or Z/X/Y */ + snd_pcm_fast_ops_t fops; }; enum { PREAMBLE_Z, PREAMBLE_X, PREAMBLE_Y }; @@ -416,6 +417,35 @@ static void snd_pcm_iec958_dump(snd_pcm_t *pcm, snd_output_t *out) snd_pcm_dump(iec->plug.gen.slave, out); } +static snd_pcm_sframes_t snd_pcm_iec958_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames) +{ + unsigned int counter_decrement; + snd_pcm_iec958_t *iec = pcm->private_data; + snd_pcm_sframes_t result = snd_pcm_plugin_rewind(pcm, frames); + if (result <= 0) + return result; + + counter_decrement = result % 192; + iec->counter += 192 - counter_decrement; + iec->counter %= 192; + return result; +} + +static snd_pcm_sframes_t snd_pcm_iec958_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames) + +{ + unsigned int counter_increment; + snd_pcm_iec958_t *iec = pcm->private_data; + snd_pcm_sframes_t result = snd_pcm_plugin_rewind(pcm, frames); + if (result <= 0) + return result; + + counter_increment = result % 192; + iec->counter += counter_increment; + iec->counter %= 192; + return result; +} + static const snd_pcm_ops_t snd_pcm_iec958_ops = { .close = snd_pcm_generic_close, .info = snd_pcm_generic_info, @@ -495,7 +525,12 @@ int snd_pcm_iec958_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo return err; } pcm->ops = &snd_pcm_iec958_ops; - pcm->fast_ops = &snd_pcm_plugin_fast_ops; + + iec->fops = snd_pcm_plugin_fast_ops; + iec->fops.rewind = snd_pcm_iec958_rewind; + iec->fops.forward = snd_pcm_iec958_forward; + pcm->fast_ops = &iec->fops; + pcm->private_data = iec; pcm->poll_fd = slave->poll_fd; pcm->poll_events = slave->poll_events; diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c index 17157e8..4ddf10c 100644 --- a/src/pcm/pcm_plugin.c +++ b/src/pcm/pcm_plugin.c @@ -201,7 +201,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm) return snd_pcm_mmap_hw_avail(pcm); } -static snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames) +snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames) { snd_pcm_plugin_t *plugin = pcm->private_data; snd_pcm_sframes_t n = snd_pcm_mmap_hw_avail(pcm); @@ -229,7 +229,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_forwardable(snd_pcm_t *pcm) return snd_pcm_mmap_avail(pcm); } -static snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames) +snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames) { snd_pcm_plugin_t *plugin = pcm->private_data; snd_pcm_sframes_t n = snd_pcm_mmap_avail(pcm); diff --git a/src/pcm/pcm_plugin.h b/src/pcm/pcm_plugin.h index 7ee7c7f..19e82c3 100644 --- a/src/pcm/pcm_plugin.h +++ b/src/pcm/pcm_plugin.h @@ -58,8 +58,14 @@ typedef struct { snd1_pcm_plugin_undo_read_generic #define snd_pcm_plugin_undo_write_generic \ snd1_pcm_plugin_undo_write_generic +#define snd_pcm_plugin_rewind \ + snd1_pcm_plugin_rewind +#define snd_pcm_plugin_forward \ + snd1_pcm_plugin_forward void snd_pcm_plugin_init(snd_pcm_plugin_t *plugin); +snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames); +snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames); extern const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops;