alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Vinod Koul <vinod.koul@intel.com>
Cc: Jeeja KP <jeeja.kp@intel.com>,
	alsa-devel@alsa-project.org, broonie@opensource.wolfsonmicro.com,
	liam.r.girdwood@intel.com
Subject: Re: [RFC] compress: add support for gapless playback
Date: Wed, 06 Feb 2013 15:11:02 +0100	[thread overview]
Message-ID: <s5hk3ql8rd5.wl%tiwai@suse.de> (raw)
In-Reply-To: <1360074085-562-1-git-send-email-vinod.koul@intel.com>

At Tue,  5 Feb 2013 06:21:25 -0800,
Vinod Koul wrote:
> 
> From: Jeeja KP <jeeja.kp@intel.com>
> 
> this add new API for sound compress to support gapless playback.
> As noted in Documentation change, we add API to send metadata of encoder and
> padding delay to DSP. Also add API for indicating EOF and switching to
> subsequent track

I can understand that the metadata is somehow handled in DSP for
seamless switching, but the operation with partial drain is a bit
unclear.  How is the operation flow?  Does it drain until which point?
In your patch, the runtime state is changed to SETUP after the partial
drain, so the app is requested to give START again?


thanks,

Takashi


> 
> Also bump the compress API version
> 
> Signed-off-by: Jeeja KP <jeeja.kp@intel.com>
> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
> ---
>  Documentation/sound/alsa/compress_offload.txt |   22 +++++++++++
>  include/sound/compress_driver.h               |    2 +
>  include/uapi/sound/compress_offload.h         |   18 ++++++++-
>  sound/core/compress_offload.c                 |   51 +++++++++++++++++++++++++
>  4 files changed, 92 insertions(+), 1 deletions(-)
> 
> diff --git a/Documentation/sound/alsa/compress_offload.txt b/Documentation/sound/alsa/compress_offload.txt
> index 90e9b3a..071c4b6 100644
> --- a/Documentation/sound/alsa/compress_offload.txt
> +++ b/Documentation/sound/alsa/compress_offload.txt
> @@ -145,6 +145,28 @@ Modifications include:
>  - Addition of encoding options when required (derived from OpenMAX IL)
>  - Addition of rateControlSupported (missing in OpenMAX AL)
>  
> +Gapless Playback
> +================
> +When playing thru an album, the decoders have the ability to skip the encoder
> +delay and padding and directly move from one track content to another. The end
> +user can perceive this as gapless playback as we dont have silence while
> +switching from one track to another
> +
> +The decoder needs to know the encoder delay and encoder padding. So we need to
> +pass this to DSP. Also DSP and userspace needs to switch from one track to
> +another and start using data for second track.
> +
> +The main additions are:
> +
> +- set_metadata
> +This routine sets the encoder delay and encoder padding. This can be used by
> +decoder to strip the silence
> +
> +- partial drain
> +This is called when end of file is reached. The userspace can inform DSP that
> +EOF is reached and now DSP can start skipping padding delay. Also next write
> +data would belong to next track
> +
>  Not supported:
>  
>  - Support for VoIP/circuit-switched calls is not the target of this
> diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
> index f2912ab..42d6d7c 100644
> --- a/include/sound/compress_driver.h
> +++ b/include/sound/compress_driver.h
> @@ -110,6 +110,8 @@ struct snd_compr_ops {
>  			struct snd_compr_params *params);
>  	int (*get_params)(struct snd_compr_stream *stream,
>  			struct snd_codec *params);
> +	int (*set_metadata)(struct snd_compr_stream *stream,
> +			struct snd_compr_metadata *metadata);
>  	int (*trigger)(struct snd_compr_stream *stream, int cmd);
>  	int (*pointer)(struct snd_compr_stream *stream,
>  			struct snd_compr_tstamp *tstamp);
> diff --git a/include/uapi/sound/compress_offload.h b/include/uapi/sound/compress_offload.h
> index 05341a4..65ca2f1 100644
> --- a/include/uapi/sound/compress_offload.h
> +++ b/include/uapi/sound/compress_offload.h
> @@ -30,7 +30,7 @@
>  #include <sound/compress_params.h>
>  
>  
> -#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 0)
> +#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 1)
>  /**
>   * struct snd_compressed_buffer: compressed buffer
>   * @fragment_size: size of buffer fragment in bytes
> @@ -122,6 +122,18 @@ struct snd_compr_codec_caps {
>  };
>  
>  /**
> + * struct snd_compr_metadata: compressed stream metadata
> + * @encoder_delay: no of samples inserted by the encoder at the beginning
> + * of the track
> + * @encoder_padding: no of samples appended by the encoder at the end
> + * of the track
> + */
> +struct snd_compr_metadata {
> +	 __u32 encoder_delay;
> +	 __u32 encoder_padding;
> +};
> +
> +/**
>   * compress path ioctl definitions
>   * SNDRV_COMPRESS_GET_CAPS: Query capability of DSP
>   * SNDRV_COMPRESS_GET_CODEC_CAPS: Query capability of a codec
> @@ -145,6 +157,8 @@ struct snd_compr_codec_caps {
>  						struct snd_compr_codec_caps)
>  #define SNDRV_COMPRESS_SET_PARAMS	_IOW('C', 0x12, struct snd_compr_params)
>  #define SNDRV_COMPRESS_GET_PARAMS	_IOR('C', 0x13, struct snd_codec)
> +#define SNDRV_COMPRESS_SET_METADATA	_IOW('C', 0x14,\
> +						 struct snd_compr_metadata)
>  #define SNDRV_COMPRESS_TSTAMP		_IOR('C', 0x20, struct snd_compr_tstamp)
>  #define SNDRV_COMPRESS_AVAIL		_IOR('C', 0x21, struct snd_compr_avail)
>  #define SNDRV_COMPRESS_PAUSE		_IO('C', 0x30)
> @@ -152,10 +166,12 @@ struct snd_compr_codec_caps {
>  #define SNDRV_COMPRESS_START		_IO('C', 0x32)
>  #define SNDRV_COMPRESS_STOP		_IO('C', 0x33)
>  #define SNDRV_COMPRESS_DRAIN		_IO('C', 0x34)
> +#define SNDRV_COMPRESS_PARTIAL_DRAIN	_IO('C', 0x35)
>  /*
>   * TODO
>   * 1. add mmap support
>   *
>   */
>  #define SND_COMPR_TRIGGER_DRAIN 7 /*FIXME move this to pcm.h */
> +#define SND_COMPR_TRIGGER_PARTIAL_DRAIN 8
>  #endif
> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
> index ad11dc9..2928971 100644
> --- a/sound/core/compress_offload.c
> +++ b/sound/core/compress_offload.c
> @@ -514,6 +514,37 @@ out:
>  	return retval;
>  }
>  
> +static int
> +snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg)
> +{
> +	struct snd_compr_metadata *metadata;
> +	int retval;
> +
> +	if (!stream->ops->set_metadata)
> +		return -ENXIO;
> +	/*
> +	* we should allow parameter change only when stream has been
> +	* opened not in other cases
> +	*/
> +	metadata = kmalloc(sizeof(*metadata), GFP_KERNEL);
> +	if (!metadata)
> +		return -ENOMEM;
> +	if (copy_from_user(metadata, (void __user *)arg,
> +				sizeof(*metadata))) {
> +		retval = -EFAULT;
> +		goto out;
> +	}
> +
> +	pr_debug("metadata encoder delay=%x encoder padding=%x\n",
> +			 metadata->encoder_delay,  metadata->encoder_padding);
> +
> +	retval = stream->ops->set_metadata(stream, metadata);
> +
> +out:
> +	kfree(metadata);
> +	return retval;
> +}
> +
>  static inline int
>  snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg)
>  {
> @@ -594,6 +625,20 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
>  	return retval;
>  }
>  
> +static int snd_compr_partial_drain(struct snd_compr_stream *stream)
> +{
> +	int retval;
> +	if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
> +			stream->runtime->state == SNDRV_PCM_STATE_SETUP)
> +		return -EPERM;
> +	retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN);
> +	if (retval)
> +		pr_err("Partial drain returned failure\n");
> +	else
> +		stream->runtime->state = SNDRV_PCM_STATE_SETUP;
> +	return retval;
> +}
> +
>  static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>  {
>  	struct snd_compr_file *data = f->private_data;
> @@ -623,6 +668,9 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>  	case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS):
>  		retval = snd_compr_get_params(stream, arg);
>  		break;
> +	case _IOC_NR(SNDRV_COMPRESS_SET_METADATA):
> +		retval = snd_compr_set_metadata(stream, arg);
> +		break;
>  	case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
>  		retval = snd_compr_tstamp(stream, arg);
>  		break;
> @@ -644,6 +692,9 @@ static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>  	case _IOC_NR(SNDRV_COMPRESS_DRAIN):
>  		retval = snd_compr_drain(stream);
>  		break;
> +	case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN):
> +		retval = snd_compr_partial_drain(stream);
> +		break;
>  	}
>  	mutex_unlock(&stream->device->lock);
>  	return retval;
> -- 
> 1.7.0.4
> 

  parent reply	other threads:[~2013-02-06 14:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-05 14:21 [RFC] compress: add support for gapless playback Vinod Koul
2013-02-06  2:44 ` Pierre-Louis Bossart
2013-02-06  7:54   ` Vinod Koul
2013-02-06 13:32     ` Mark Brown
2013-02-06 13:56       ` Vinod Koul
2013-02-06 13:59       ` Pierre-Louis Bossart
2013-02-06 14:00         ` Vinod Koul
2013-02-06 14:14   ` Takashi Iwai
2013-02-06 14:02     ` Vinod Koul
2013-02-06 14:33       ` Takashi Iwai
2013-02-06 14:11 ` Takashi Iwai [this message]
2013-02-06 14:09   ` Vinod Koul
2013-02-06 14:48     ` Takashi Iwai
2013-02-06 14:31       ` Vinod Koul
     [not found] ` <37A133201056E44A80888420ECA881BF1093DC5F68@EXCMB2.wolfsonmicro.main>
     [not found]   ` <20130207011518.GA30348@opensource.wolfsonmicro.com>
2013-02-07  2:18     ` Vinod Koul
2013-02-07  8:49       ` Takashi Iwai
2013-02-07 16:34         ` Vinod Koul
     [not found]         ` <20130207113738.GA15824@opensource.wolfsonmicro.com>
2013-02-07 11:49           ` Takashi Iwai
2013-02-07 16:51           ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hk3ql8rd5.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=jeeja.kp@intel.com \
    --cc=liam.r.girdwood@intel.com \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).