From patchwork Fri Feb 6 16:16:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Cussins X-Patchwork-Id: 5793041 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A638E9F336 for ; Fri, 6 Feb 2015 16:16:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AB1DE201BC for ; Fri, 6 Feb 2015 16:16:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4FF08200D6 for ; Fri, 6 Feb 2015 16:16:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8624126535F; Fri, 6 Feb 2015 17:16:54 +0100 (CET) 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_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 484CA2652DB; Fri, 6 Feb 2015 17:16:21 +0100 (CET) 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 625B12651DC; Fri, 6 Feb 2015 17:16:19 +0100 (CET) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by alsa0.perex.cz (Postfix) with ESMTP id D1C5A2651A4 for ; Fri, 6 Feb 2015 17:16:13 +0100 (CET) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6E7BF20B50 for ; Fri, 6 Feb 2015 11:16:13 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Fri, 06 Feb 2015 11:16:13 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=eml.cc; h= x-sasl-enc:from:to:cc:subject:date:message-id:in-reply-to :references; s=mesmtp; bh=qWmOdRYUP0DjC6wlKK8GOyzjUms=; b=regK/v yaJ12Dm4LGZBNV05oNLu/n4VDQqIyQAUAVoNW7a1hbJ0DBJ99rX4zgEMFP2zs1aH W+EuNDDFkVA3OOVSKHVEZ1nfiWW75fm2UWiAgELfUp8UDoS8F8gmhAYqOXOO9i6F iML+dRnU9+sRDKT0iOqxrdm5OEez31ob+uIHA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:from:to:cc:subject:date :message-id:in-reply-to:references; s=smtpout; bh=qWmOdRYUP0DjC6 wlKK8GOyzjUms=; b=DK7lYXH+Vc84Zg5pnQIyiLEEJ6ZqrSeJcNNK+LWeHU3AWR DxlOyRjne6ZmjLZ1gTSWFCoHj8Wt0mWtgYypV+lMnsl/tGeRrHwXqts3co0a2f4C JsPh9cR7x0qIuoT+TH6jvyyzoGgGo9GzrQ0s5iivRi8P9da6XX4LdKbUNNHDQ= X-Sasl-enc: 7+jfS2jnouVlk98ayHonzQbH+FccPWlrzGGRt1GcGFb9 1423239373 Received: from PC816.linn.co.uk (unknown [195.59.102.251]) by mail.messagingengine.com (Postfix) with ESMTPA id D2BD3C0029A; Fri, 6 Feb 2015 11:16:12 -0500 (EST) From: Tim Cussins To: alsa-devel@alsa-project.org Date: Fri, 6 Feb 2015 16:16:00 +0000 Message-Id: <1423239361-17655-2-git-send-email-timcussins@eml.cc> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423239361-17655-1-git-send-email-timcussins@eml.cc> References: <1423239361-17655-1-git-send-email-timcussins@eml.cc> Cc: Tim Cussins Subject: [alsa-devel] [PATCH v3 alsa-lib 2/3] START_AT ioctl and operations. 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 We introduce a new ioctl, START_AT, and 3 new snd_pcm_fast_ops_t members. The ioctl takes a struct snd_start_at, which holds the required operation, and corresponding arguments (which can be input and output). The START_AT ioctol supports SET, CANCEL, and STATUS operations. STATUS returns the current time. struct snd_start_at packing, ioctl invocation, and unpacking is implemented in pcm_hw.c. Signed-off-by: Tim Cussins diff --git a/include/sound/asound.h b/include/sound/asound.h index 1f23cd6..ab7c05b 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h @@ -420,7 +420,10 @@ struct snd_pcm_status { snd_pcm_state_t suspended_state; /* suspended stream state */ __u32 reserved_alignment; /* must be filled with zero */ struct timespec audio_tstamp; /* from sample counter or wall clock */ - unsigned char reserved[56-sizeof(struct timespec)]; /* must be filled with zero */ + int start_at_pending; + int start_at_clock_type; + struct timespec start_at_start_time; + unsigned char reserved[48-2*(sizeof(struct timespec))]; /* must be filled with zero */ }; struct snd_pcm_mmap_status { @@ -472,6 +475,34 @@ enum { SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, }; +enum { + SNDRV_PCM_STARTAT_OP_SET = 0, + SNDRV_PCM_STARTAT_OP_CANCEL, + SNDRV_PCM_STARTAT_OP_STATUS, + SNDRV_PCM_STARTAT_OP_LAST = SNDRV_PCM_STARTAT_OP_STATUS, +}; + +enum { + SNDRV_PCM_STARTAT_CLOCK_TYPE_GETTIMEOFDAY = 0, + SNDRV_PCM_STARTAT_CLOCK_TYPE_MONOTONIC, + SNDRV_PCM_STARTAT_CLOCK_TYPE_LINK, + SNDRV_PCM_STARTAT_CLOCK_TYPE_LAST = SNDRV_PCM_STARTAT_CLOCK_TYPE_LINK, +}; + +struct snd_start_at { + int op; /* startat operation to be performed */ + union { /* fields for setting a startat timer */ + struct { + int clock_type; /* clock type e.g. SNDRV_PCM_STARTAT_CLOCK_TYPE_GETTIMEOFDAY */ + struct timespec start_time; /* start time */ + } set; + struct { + int clock_type; /* clock type e.g. SNDRV_PCM_STARTAT_CLOCK_TYPE_GETTIMEOFDAY */ + struct timespec current_time; + } status; + } args; +}; + /* channel positions */ enum { SNDRV_CHMAP_UNKNOWN = 0, @@ -550,6 +581,8 @@ enum { #define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern) #define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int) #define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) +#define SNDRV_PCM_IOCTL_START_AT _IOW('A', 0x62, struct snd_start_at) + /***************************************************************************** * * diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index c34b766..07c3a2e 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -620,6 +620,67 @@ static int snd_pcm_hw_start(snd_pcm_t *pcm) return 0; } +static int snd_pcm_hw_start_at(snd_pcm_t *pcm, snd_pcm_startat_clock_type_t clock_type, const snd_htimestamp_t *start_time) +{ + snd_pcm_hw_t *hw = pcm->private_data; + int err; + + struct snd_start_at start_at = { + .op = SNDRV_PCM_STARTAT_OP_SET, + .args.set = { + .clock_type = clock_type, + .start_time = *start_time, + } + }; + + if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START_AT, &start_at) < 0) { + err = -errno; + SYSMSG("SNDRV_PCM_IOCTL_START_AT failed (%i)", err); + return err; + } + return 0; +} + +static int snd_pcm_hw_start_at_abort(snd_pcm_t *pcm) +{ + snd_pcm_hw_t *hw = pcm->private_data; + int err; + + struct snd_start_at start_at = { + .op = SNDRV_PCM_STARTAT_OP_CANCEL, + }; + + if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START_AT, &start_at) < 0) { + err = -errno; + SYSMSG("SNDRV_PCM_IOCTL_START_AT failed (%i)", err); + return err; + } + return 0; +} + +static int snd_pcm_hw_start_at_gettime(snd_pcm_t *pcm, snd_pcm_startat_clock_type_t clock_type, snd_htimestamp_t *current_time) +{ + snd_pcm_hw_t *hw = pcm->private_data; + int err; + + struct snd_start_at start_at = { + .op = SNDRV_PCM_STARTAT_OP_STATUS, + .args.status = { + .clock_type = clock_type, + } + }; + + if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START_AT, &start_at) < 0) { + err = -errno; + SYSMSG("SNDRV_PCM_IOCTL_START_AT failed (%i)", err); + return err; + } + + *current_time = start_at.args.status.current_time; + + return 0; +} + static int snd_pcm_hw_drop(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; @@ -1336,6 +1397,9 @@ static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = { .prepare = snd_pcm_hw_prepare, .reset = snd_pcm_hw_reset, .start = snd_pcm_hw_start, + .start_at = snd_pcm_hw_start_at, + .start_at_abort = snd_pcm_hw_start_at_abort, + .start_at_gettime = snd_pcm_hw_start_at_gettime, .drop = snd_pcm_hw_drop, .drain = snd_pcm_hw_drain, .pause = snd_pcm_hw_pause, diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 394505f..0ea6b61 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -154,6 +154,9 @@ typedef struct { int (*prepare)(snd_pcm_t *pcm); int (*reset)(snd_pcm_t *pcm); int (*start)(snd_pcm_t *pcm); + int (*start_at)(snd_pcm_t *pcm, snd_pcm_startat_clock_type_t clock_type, const snd_htimestamp_t *start_time); + int (*start_at_abort)(snd_pcm_t *pcm); + int (*start_at_gettime)(snd_pcm_t *pcm, snd_pcm_startat_clock_type_t clock_type, snd_htimestamp_t *current_time); int (*drop)(snd_pcm_t *pcm); int (*drain)(snd_pcm_t *pcm); int (*pause)(snd_pcm_t *pcm, int enable);