ALSA: compress_offload: introduce passthrough operation mode
Subsystems (3)
Jaroslav Kysela
maintainerRFC PATCH 1/1 ALSA: compress_offload: introduce passthrough operation mode
There is a requirement to expose the audio hardware that accelerates various tasks for user space such as sample rate converters, compressed stream decoders, etc.
This is description for the API extension for the compress ALSA API which is able to handle "tasks" that are not bound to real-time operations and allows for the serialization of operations.
For details, refer to "compress-passthrough.rst" document.
Note: This code is RFC (not tested, just to clearify the API requirements). My goal is to add a test (loopback) driver and add a support to tinycompress library in the next step.
--- .../sound/designs/compress-passthrough.rst | 125 +++++++ include/sound/compress_driver.h | 32 ++ include/uapi/sound/compress_offload.h | 44 ++- sound/core/Kconfig | 4 + sound/core/compress_offload.c | 314 +++++++++++++++++- 5 files changed, 511 insertions(+), 8 deletions(-) create mode 100644 Documentation/sound/designs/compress-passthrough.rst
Documentation/sound/designs/compress-passthrough.rst new file +125 -0
@@ -0,0 +1,125 @@ +================================= +ALSA Co-processor Passthrough API +================================= + +Jaroslav Kysela <[email protected]> + + +Overview +======== + +There is a requirement to expose the audio hardware that accelerates various +tasks for user space such as sample rate converters, compressed +stream decoders, etc. + +This is description for the API extension for the compress ALSA API which +is able to handle "tasks" that are not bound to real-time operations +and allows for the serialization of operations. + +Requirements +============ + +The main requirements are: + +- serialization of multiple tasks for user space to allow multiple + operations without user space intervention + +- separate buffers (input + output) for each operation + +- expose buffers using mmap to user space + +- signal user space when the task is finished (standard poll mechanism) + +Design +====== + +A new direction SND_COMPRESS_PASSTHROUGH is introduced to identify +the passthrough API. + +The API extension shares device enumeration and parameters handling from +the main compressed API. All other realtime streaming ioctls are deactivated +and a new set of task related ioctls are introduced. The standard +read/write/mmap I/O operations are not supported in the passtrough device. + +Device ("stream") state handling is reduced to OPEN/SETUP. All other +states are not available for the passthrough mode. + +Data I/O mechanism is using standard dma-buf interface with all advantages +like mmap, standard I/O, buffer sharing etc. One buffer is used for the +input data and second (separate) buffer is used for the ouput data. Each task +have separate I/O buffers. + +For the buffering parameters, the fragments means a limit of allocated tasks +for given device. The fragment_size limits the input buffer size for the given +device. The output buffer size is determined by the driver (may be different +from the input buffer size). + +State Machine +============= + +The passtrough audio stream state machine is described below : + + +----------+ + | | + | OPEN | + | | + +----------+ + | + | + | compr_set_params() + | + v + all passthrough task ops +----------+ + +------------------------------------| | + | | SETUP | + | | + | +----------+ + | | + +------------------------------------------+ + + +Passthrough operations (ioctls) +=============================== + +CREATE +------ +Creates a set of input/output buffers. The input buffer size is +fragment_size. Allocates unique seqno. + +The hardware drivers allocate internal 'struct dma_buf' for both input and +output buffers (using 'dma_buf_export()' function). The anonymous +file descriptors for those buffers are passed to user space. + +FREE +---- +Free a set of input/output buffers. If an task is active, the stop +operation is executed before. If seqno is zero, operation is executed for all +tasks. + +START +----- +Starts (queues) a task. There are two cases of the task start - right after +the task is created. In this case, origin_seqno must be zero. +The second case is for reusing of already finished task. The origin_seqno +must identify the task to be reused. In both cases, a new seqno value +is allocated and returned to user space. + +The prerequisite is that application filled input dma buffer with +new source data and set input_size to pass the real data size to the driver. + +The order of data processing is preserved (first started job must be +finished at first). + +STOP +---- +Stop (dequeues) a task. If seqno is zero, operation is executed for all +tasks. + +STATUS +------ +Obtain the task status (active, finished). Also, the driver will set +the real output data size (valid area in the output buffer). + +Credits +======= +- ...
include/sound/compress_driver.h +32 -0
@@ -19,6 +19,23 @@struct snd_compr_ops ; +/** +* struct snd_compr_task_runtime: task runtime description +* +*/ +struct snd_compr_task_runtime { +struct list_head list; +struct dma_buf *input; +struct dma_buf *output; +__u64 seqno; +__u64 input_size; +__u64 output_size; +bool active; +bool finished; +void *private_value; +}; + +/** * struct snd_compr_runtime: runtime stream description * @state: stream state
@@ -54,6 +71,10 @@ struct snd_compr_runtime {dma_addr_t dma_addr;size_t dma_bytes;struct snd_dma_buffer *dma_buffer_p; + +u32 active_tasks; +u64 task_seqno; +struct list_head tasks; };/**
@@ -132,6 +153,12 @@ struct snd_compr_ops { struct snd_compr_caps *caps);int (*get_codec_caps) (struct snd_compr_stream *stream,struct snd_compr_codec_caps *codec); +#if IS_ENABLED (CONFIG_SND_COMPRESS_PASSTHROUGH ) +int (*task_create) (struct snd_compr_stream *stream,struct snd_compr_task_runtime *task); +int (*task_start) (struct snd_compr_stream *stream,struct snd_compr_task_runtime *task); +int (*task_stop) (struct snd_compr_stream *stream,struct snd_compr_task_runtime *task); +int (*task_free) (struct snd_compr_stream *stream,struct snd_compr_task_runtime *task); +#endif };/**
@@ -242,4 +269,9 @@ int snd_compr_free_pages(struct snd_compr_stream *stream);int snd_compr_stop_error (struct snd_compr_stream *stream,snd_pcm_state_t state); +#if IS_ENABLED (CONFIG_SND_COMPRESS_PASSTHROUGH ) +void snd_compr_task_finished (struct snd_compr_stream *stream, +struct snd_compr_task_runtime *task); +#endif +#endif
include/uapi/sound/compress_offload.h +42 -2
68 lines not on this page · raw message
sound/core/Kconfig +4 -0
@@ -59,6 +59,10 @@ config SND_CORE_TEST config SND_COMPRESS_OFFLOAD tristate +config SND_COMPRESS_PASSTHROUGH + select DMA_BUF + tristate + config SND_JACK bool
sound/core/compress_offload.c +308 -6
399 lines not on this page · raw message
Signature · 1 line
2.45.1
Quoted 14 lines · Jaroslav Kysela
There is a requirement to expose the audio hardware that accelerates various tasks for user space such as sample rate converters, compressed stream decoders, etc.
This is description for the API extension for the compress ALSA API which is able to handle "tasks" that are not bound to real-time operations and allows for the serialization of operations.
For details, refer to "
compress-passthrough.rst" document.Note: This code is RFC (not tested, just to clearify the API requirements). My goal is to add a test (loopback) driver and add a support to tinycompress library in the next step.
Quoted 8 lines
Cc Mark Brown <[email protected]>Cc Shengjiu Wang <[email protected]>Cc Nicolas Dufresne <[email protected]>Cc Amadeusz Sławiński <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Cc Vinod Koul <[email protected]>Signed-off-by Jaroslav Kysela <[email protected]>---
Seems mostly ok to me, some nitpicks below.
Quoted 46 lines
.../sound/designs/compress-passthrough.rst | 125 +++++++ include/sound/compress_driver.h | 32 ++ include/uapi/sound/compress_offload.h | 44 ++- sound/core/Kconfig | 4 + sound/core/compress_offload.c | 314 +++++++++++++++++- 5 files changed, 511 insertions(+), 8 deletions(-)create mode 100644
Documentation/sound/designs/compress-passthrough.rstDocumentation/sound/designs/compress-passthrough.rst new file +32
-0@@ -0,0 +1,125 @@ +================================= +ALSA Co-processor Passthrough API +================================= + +Jaroslav Kysela <[email protected]> + + +Overview +======== + +There is a requirement to expose the audio hardware that accelerates various +tasks for user space such as sample rate converters, compressed +stream decoders, etc. + +This is description for the API extension for the compress ALSA API which +is able to handle "tasks" that are not bound to real-time operations +and allows for the serialization of operations. + +Requirements +============ + +The main requirements are: + +- serialization of multiple tasks for user space to allow multiple + operations without user space intervention + +- separate buffers (input + output) for each operation + +- expose buffers using mmap to user space + +- signal user space when the task is finished (standard poll mechanism) +
Documentation/sound/designs/compress-passthrough.rst line 42
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst new file +10
-0+Design +====== + +A new direction SND_COMPRESS_PASSTHROUGH is introduced to identify +the passthrough API. + +The API extension shares device enumeration and parameters handling from +the main compressed API. All other realtime streaming ioctls are deactivated +and a new set of task related ioctls are introduced. The standard +read/write/mmap I/O operations are not supported in the passtrough device.
passthrough
Documentation/sound/designs/compress-passthrough.rst line 49
Quoted 7 lines
Documentation/sound/designs/compress-passthrough.rst new file +7
-0+ +Device ("stream") state handling is reduced to OPEN/SETUP. All other +states are not available for the passthrough mode. + +Data I/O mechanism is using standard dma-buf interface with all advantages +like mmap, standard I/O, buffer sharing etc. One buffer is used for the +input data and second (separate) buffer is used for the ouput data. Each task
output
Documentation/sound/designs/compress-passthrough.rst line 60
Quoted 11 lines
Documentation/sound/designs/compress-passthrough.rst new file +11
-0+have separate I/O buffers. + +For the buffering parameters, the fragments means a limit of allocated tasks +for given device. The fragment_size limits the input buffer size for the given +device. The output buffer size is determined by the driver (may be different +from the input buffer size). + +State Machine +============= + +The passtrough audio stream state machine is described below :
passthrough
Quoted 25 lines
Documentation/sound/designs/compress-passthrough.rst new file +25
-0+ + +----------+ + | | + | OPEN | + | | + +----------+ + | + | + | compr_set_params() + | + v + all passthrough task ops +----------+ + +------------------------------------| | + | | SETUP | + | | + | +----------+ + | | + +------------------------------------------+ + + +Passthrough operations (ioctls) +=============================== + +CREATE +------
Documentation/sound/designs/compress-passthrough.rst line 95
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst new file +10
-0+Creates a set of input/output buffers. The input buffer size is +fragment_size. Allocates unique seqno. + +The hardware drivers allocate internal 'struct dma_buf' for both input and +output buffers (using 'dma_buf_export()' function). The anonymous +file descriptors for those buffers are passed to user space. + +FREE +---- +Free a set of input/output buffers. If an task is active, the stop
_a_ task?
Quoted 13 lines
Documentation/sound/designs/compress-passthrough.rst new file +13
-0+ +static int snd_compr_task_start(struct snd_compr_stream *stream, struct snd_compr_task *utask) +{ + struct snd_compr_task_runtime *task; + int retval; + + if (utask->origin_seqno > 0) { + task = snd_compr_find_task(stream, utask->seqno); + retval = snd_compr_task_start_prepare(task, utask); + if (retval < 0) + return retval; + task->seqno = utask->seqno = snd_compr_seqno_next(stream); + utask->origin_seqno = 0;
Documentation/sound/designs/compress-passthrough.rst line 118
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst new file +10
-0+ list_move_tail(&task->list, &stream->runtime->tasks); + } else { + task = snd_compr_find_task(stream, utask->seqno); + if (task && task->finished) + return -EBUSY; + retval = snd_compr_task_start_prepare(task, utask); + if (retval < 0) + return retval; + } + retval = stream->ops->task_start(stream, task);
Should probably check somewhere that ops are set properly, or is it this way because they all considered mandatory?
Documentation/sound/designs/compress-passthrough.rst
Quoted 12 lines
Documentation/sound/designs/compress-passthrough.rst new file +12
-0+ +static int snd_compr_task_status(struct snd_compr_stream *stream, + struct snd_compr_task_status *status) +{ + struct snd_compr_task_runtime *task; + + task = snd_compr_find_task(stream, status->seqno); + if (task == NULL) + return -EINVAL; + status->output_size = task->output_size; + status->active = task->active ? 1 : 0; + status->finished = task->finished ? 1 : 0;
Not sure, but access to ->active and ->finished, feels to me like something that may require locking.
Quoted 15 lines · Amadeusz Sławiński
sound/core/compress_offload.c static int snd_compr_partial_drain(struct snd_compr_stream *stream) · line 1183
Quoted 12 lines
sound/core/compress_offload.c +11
-0+static int snd_compr_task_status (struct snd_compr_stream *stream, +struct snd_compr_task_status *status) +{ +struct snd_compr_task_runtime *task; + + task =snd_compr_find_task (stream, status->seqno); +if (task ==NULL ) +return -EINVAL ; + status->output_size = task->output_size; + status->active = task->active ?1 :0 ; + status->finished = task->finished ?1 :0 ;Not sure, but access to ->active and ->finished, feels to me like something that may require locking.
Or better to make it a single state field?
thanks,
Takashi
Jaroslav Kysela
maintainerQuoted 18 lines · Takashi Iwai
Quoted 15 lines · Amadeusz Sławiński
sound/core/compress_offload.c static int snd_compr_partial_drain(struct snd_compr_stream *stream) · line 1183
Quoted 12 lines
sound/core/compress_offload.c +11
-0+static int snd_compr_task_status (struct snd_compr_stream *stream, +struct snd_compr_task_status *status) +{ +struct snd_compr_task_runtime *task; + + task =snd_compr_find_task (stream, status->seqno); +if (task ==NULL ) +return -EINVAL ; + status->output_size = task->output_size; + status->active = task->active ?1 :0 ; + status->finished = task->finished ?1 :0 ;Not sure, but access to ->active and ->finished, feels to me like something that may require locking.
Quoted 1 line
Or better to make it a single state field?
Yes, it's an option. Those states cannot be used simultaneously. Note that the access to the runtime task fields is protected by the stream->device->lock mutex. Unless I overlooked something.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Jaroslav Kysela
maintainerQuoted 6 lines · Amadeusz Sławiński
Documentation/sound/designs/compress-passthrough.rst line 42
Quoted 4 lines
Documentation/sound/designs/compress-passthrough.rst new file +4
-0+The API extension shares device enumeration and parameters handling from +the main compressed API. All other realtime streaming ioctls are deactivated +and a new set of task related ioctls are introduced. The standard +read/write/mmap I/O operations are not supported in the passtrough device.passthrough
Thank you. I fixed those typos in my tree.
Quoted 4 lines
sound/core/compress_offload.c static int snd_compr_partial_drain(struct snd_compr_stream *stream) · line 1097
Quoted 1 line
sound/core/compress_offload.c +1
-0+ retval = stream->ops->task_start (stream, task);Should probably check somewhere that ops are set properly, or is it this way because they all considered mandatory?
Yes, all four callbacks are mandatory for the passthrough mode.
Thank you for your comments,
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Quoted 15 lines · Jaroslav Kysela
There is a requirement to expose the audio hardware that accelerates various tasks for user space such as sample rate converters, compressed stream decoders, etc.
This is description for the API extension for the compress ALSA API which is able to handle "tasks" that are not bound to real-time operations and allows for the serialization of operations.
For details, refer to "
compress-passthrough.rst" document.Note: This code is RFC (not tested, just to clearify the API requirements). My goal is to add a test (loopback) driver and add a support to tinycompress library in the next step.
Quoted 8 lines
Cc Mark Brown <[email protected]>Cc Shengjiu Wang <[email protected]>Cc Nicolas Dufresne <[email protected]>Cc Amadeusz Sławiński <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Cc Vinod Koul <[email protected]>Signed-off-by Jaroslav Kysela <[email protected]>---
(snip)
Through a quick glance, the general idea looks simple enough and straightforward. If this satisfies the needs, we can go in this way.
A few subtle things:
- We might want to have a safe limit for the task creations. An evil user-space can fill up too easily.
- The error checks of memdup_user() are missing.
A caveat is that memdup_user() returns ERR_PTR() instead of NULL. So with the automatic cleanup, you'd need to fiddle with PTR_ERR(no_free_ptr(p)).
- The use of __u64 is rather for uapi headers. The kernel internals can be with straight u64.
- The task list add/removal might need some locks. It looks racy. Also the task runtime returned from snd_compr_find_task() might be freed. Need for some locking or refcounting?
- A linear lookup is OK from performance POV? Maybe enough for small number of tasks.
- Better to have a protocol version check and accept the R/W mode only with the newer version.
thanks,
Takashi
Jaroslav Kysela
maintainerQuoted 27 lines · Takashi Iwai
Quoted 23 lines · Jaroslav Kysela
There is a requirement to expose the audio hardware that accelerates various tasks for user space such as sample rate converters, compressed stream decoders, etc.
This is description for the API extension for the compress ALSA API which is able to handle "tasks" that are not bound to real-time operations and allows for the serialization of operations.
For details, refer to "
compress-passthrough.rst" document.Note: This code is RFC (not tested, just to clearify the API requirements). My goal is to add a test (loopback) driver and add a support to tinycompress library in the next step.
Cc Mark Brown <[email protected]>Cc Shengjiu Wang <[email protected]>Cc Nicolas Dufresne <[email protected]>Cc Amadeusz Sławiński <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Cc Vinod Koul <[email protected]>Signed-off-by Jaroslav Kysela <[email protected]>---
(snip)
Quoted 7 lines
Through a quick glance, the general idea looks simple enough and straightforward. If this satisfies the needs, we can go in this way.
A few subtle things:
- We might want to have a safe limit for the task creations. An evil user-space can fill up too easily.
The limit was proposed in snd_compress_check_input() but not used later (TASK_CREATE ioctl). I will send v2 shortly.
Quoted 4 lines
- The error checks of
memdup_user()are missing.
A caveat is thatmemdup_user()returnsERR_PTR()instead of NULL. So with the automatic cleanup, you'd need to fiddle with PTR_ERR(no_free_ptr(p)).
Thanks.
Quoted 2 lines
- The use of
__u64is rather for uapi headers. The kernel internals can be with straight u64.
Yes, thanks.
Quoted 3 lines
- The task list add/removal might need some locks. It looks racy. Also the task runtime returned from
snd_compr_find_task()might be freed. Need for some locking or refcounting?
All task operations are covered using stream->driver->lock unless I overlooked something.
Quoted 2 lines
- A linear lookup is OK from performance POV? Maybe enough for small number of tasks.
We can improve this later, but I would not expect too many queued tasks. I set the limit to 64 for the first implementation.
Quoted 2 lines
- Better to have a protocol version check and accept the R/W mode only with the newer version.
There is no R/W mode for passthrough direction. An error should be returned. The direction is returned from the driver using SNDRV_COMPRESS_GET_CAPS and also open mode must be O_RDWR so things seem to be separated enough.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Thanks Jaroslav, this is very interesting indeed.
I added a set of comments to clarify the design.
Documentation/sound/designs/compress-passthrough.rst line 13
Quoted 3 lines
Documentation/sound/designs/compress-passthrough.rst new file +3
-0+There is a requirement to expose the audio hardware that accelerates various +tasks for user space such as sample rate converters, compressed +stream decoders, etc.
"passthrough" usually means 'no change to data, filter coefficients not applied' in the audio world.
Documentation/sound/designs/compress-passthrough.rst line 17
Quoted 3 lines
Documentation/sound/designs/compress-passthrough.rst new file +3
-0+This is description for the API extension for the compress ALSA API which +is able to handle "tasks" that are not bound to real-time operations +and allows for the serialization of operations.
not sure what "not bound to real-time operations" means. sample-rate conversion is probably the most dependent on accurate timing :-)
Documentation/sound/designs/compress-passthrough.rst line 29
Quoted 11 lines
Documentation/sound/designs/compress-passthrough.rst new file +11
-0+Requirements +============ + +The main requirements are: + +- serialization of multiple tasks for user space to allow multiple + operations without user space intervention + +- separate buffers (input + output) for each operation + +- expose buffers using mmap to user space
If every buffer is mmap'ed to userspace, what prevents userspace from interfering?
I think userspace would only be involved at the source and sink of the processing chain, no?
Documentation/sound/designs/compress-passthrough.rst line 37
Quoted 7 lines
+- signal user space when the task is finished (standard poll mechanism)
Documentation/sound/designs/compress-passthrough.rst new file +6
-0+ +Design +====== + +A new direction SND_COMPRESS_PASSTHROUGH is introduced to identify +the passthrough API.
not sure what you meant by 'direction', is this a new concept in addition to PLAYBACK and CAPTURE?
edit: this is indeed what the code does, probably the documentation can be clarified to explain why this is needed.
Documentation/sound/designs/compress-passthrough.rst line 42
Quoted 4 lines
Documentation/sound/designs/compress-passthrough.rst new file +4
-0+The API extension shares device enumeration and parameters handling from +the main compressed API. All other realtime streaming ioctls are deactivated +and a new set of task related ioctls are introduced. The standard +read/write/mmap I/O operations are not supported in the passtrough device.
The compress API was geared to encoders/decoders. I am not sure how we would e.g. expose parameters for transcoders (decode-reencode) or even SRCs?
Quoted 36 lines
Documentation/sound/designs/compress-passthrough.rst new file +36
-0+Device ("stream") state handling is reduced to OPEN/SETUP. All other +states are not available for the passthrough mode. + +Data I/O mechanism is using standard dma-buf interface with all advantages +like mmap, standard I/O, buffer sharing etc. One buffer is used for the +input data and second (separate) buffer is used for the ouput data. Each task +have separate I/O buffers. + +For the buffering parameters, the fragments means a limit of allocated tasks +for given device. The fragment_size limits the input buffer size for the given +device. The output buffer size is determined by the driver (may be different +from the input buffer size). + +State Machine +============= + +The passtrough audio stream state machine is described below : + + +----------+ + | | + | OPEN | + | | + +----------+ + | + | + | compr_set_params() + | + v + all passthrough task ops +----------+ + +------------------------------------| | + | | SETUP | + | | + | +----------+ + | | + +------------------------------------------+ +
Documentation/sound/designs/compress-passthrough.rst line 89
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst new file +10
-0+ +Passthrough operations (ioctls) +=============================== + +CREATE +------ +Creates a set of input/output buffers. The input buffer size is +fragment_size. Allocates unique seqno. + +The hardware drivers allocate internal 'struct dma_buf' for both input and
for each input and output buffers?
Quoted 17 lines
Documentation/sound/designs/compress-passthrough.rst new file +17
-0+output buffers (using 'dma_buf_export()' function). The anonymous +file descriptors for those buffers are passed to user space. + +FREE +---- +Free a set of input/output buffers. If an task is active, the stop +operation is executed before. If seqno is zero, operation is executed for all +tasks. + +START +----- +Starts (queues) a task. There are two cases of the task start - right after +the task is created. In this case, origin_seqno must be zero. +The second case is for reusing of already finished task. The origin_seqno +must identify the task to be reused. In both cases, a new seqno value +is allocated and returned to user space. +
Documentation/sound/designs/compress-passthrough.rst line 116
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst new file +10
-0+The prerequisite is that application filled input dma buffer with +new source data and set input_size to pass the real data size to the driver. + +The order of data processing is preserved (first started job must be +finished at first). + +STOP +---- +Stop (dequeues) a task. If seqno is zero, operation is executed for all +tasks.
Don't you need a DRAIN?
for a co-processor API, you would want all the input data to be consumed and the stop happens when all the resulting data is provided in output buffers.
And presumably when the input task is stopped, the state changes are propagated to the next task by the framework? Or is userspace supposed to track each and every task and change their state?
I also wonder if the state for a task should reflect that it's waiting on data on its input, or conversely is blocked because the output buffers were not consumed? Dealing with SRC, encoders or decoders mean that the buffers are going to be used at vastly different rates on input and outputs.
Documentation/sound/designs/compress-passthrough.rst line 121
Quoted 4 lines
Documentation/sound/designs/compress-passthrough.rst new file +4
-0+STATUS +------ +Obtain the task status (active, finished). Also, the driver will set +the real output data size (valid area in the output buffer).
Is this assuming that the entire input buffer has valid data? There could be cases where the buffers are made of variable-length 'frames', it would be interesting to send such partial buffers to hardware. That's always been a problem with the existing compressed API, we couldn't deal with buffers that were partially filled.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jaroslav Kysela
maintainerQuoted 3 lines · Pierre-Louis Bossart
Hi Jaroslav,
did you intend to reply privately?
I don't mind having this thread in public.
I also don't mind, it was just a mistake. Moving to public again. Thanks.
Quoted 31 lines
Couple of additional questions below.
Regards,
-PierreQuoted 12 lines · Jaroslav Kysela
Quoted 10 lines · Pierre-Louis Bossart
Thanks Jaroslav, this is very interesting indeed.
I added a set of comments to clarify the design.Documentation/sound/designs/compress-passthrough.rst line 13
Quoted 4 lines
+There is a requirement to expose the audio hardware that accelerates various
Documentation/sound/designs/compress-passthrough.rst new file +2
-0+tasks for user space such as sample rate converters, compressed +stream decoders, etc."passthrough" usually means 'no change to data, filter coefficients not applied' in the audio world.
Quoted 2 lines
I am open to any better word here. The passthrough means data passing through a hardware as fast as possible in this contents.
I am trying to find a better word.
Quoted 8 lines
Quoted 7 lines
Documentation/sound/designs/compress-passthrough.rst line 17
Quoted 4 lines
+This is description for the API extension for the compress ALSA API which
Documentation/sound/designs/compress-passthrough.rst new file +2
-0+is able to handle "tasks" that are not bound to real-time operations +and allows for the serialization of operations.not sure what "not bound to real-time operations" means. sample-rate conversion is probably the most dependent on accurate timing :-)
Quoted 7 lines
Quoted 4 lines
The meaning is that the data are not queued/processed with a real world timing constraints like standard audio data for standard playback or capture. It's limited just by hardware speed. I would appreciate rewording from a native English speaker, of course.
What happens if one bit of hardware is actually tied to an audio clock? Would it prevent the use of the API?
No, the conversion will be just slow and the hardware driver should probably use a standard PCM for the data output or input. It will be more appropriate.
Quoted 3 lines
I think the only difference with traditional ALSA is that there's no concept of xrun or time, but the hardware can implement the processing however it wants.
There is no restriction for this design, but I think that we have already interfaces for this. This is a proposal for the audio acceleration API.
Quoted 27 lines
Quoted 9 lines
Quoted 9 lines
Documentation/sound/designs/compress-passthrough.rst line 27
Quoted 9 lines
Documentation/sound/designs/compress-passthrough.rst new file +9
-0+Requirements +============ + +The main requirements are: + +- serialization of multiple tasks for user space to allow multiple + operations without user space intervention + +- separate buffers (input + output) for each operationI guess we're talking about a "pipeline" where all the buffers are shared/chained. Mixers and splitters are probably out-of-scope.
But I wonder if the last task could just consume data, or if the first task could just generate data. The former case would be processing that analyzes data and generates a 'score' or an event, and the latter would be some sort of hardware synthesizer.
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
+
+- expose buffers using mmap to user spaceIf every buffer is mmap'ed to userspace, what prevents userspace from interfering?
I think userspace would only be involved at the source and sink of the processing chain, no?
Quoted 7 lines
Quoted 2 lines
We probably talk about same thing. Each task has own buffers which are exposed to user space. The interfering is similar like for any other API.
What I meant if that if userspace is involved in the middle of a chain, then it kind of breaks the idea that the processing is propagated as fast as possible through hardware. I don't really see the point of having intermediate buffers available to userspace.
There are no intermediate buffers in this API just input and output buffers yet. You probably have a bigger picture with the stream/data routing through multiple components. It's not the case (yet). The only advantage of existing dma-buf interface is that we can share those data among more drivers and user space simultaneously. The arbitration must be set elsewhere (and it is not set by this simple API).
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
+The API extension shares device enumeration and parameters handling from
+the main compressed API. All other realtime streaming ioctls are deactivated(quoted diff) +2
-0+and a new set of task related ioctls are introduced. The standard +read/write/mmap I/O operations are not supported in the passtroughdevice.
The compress API was geared to encoders/decoders. I am not sure how we would e.g. expose parameters for transcoders (decode-reencode) or even SRCs?
Quoted 6 lines
Quoted 2 lines
I expect that the struct
snd_codecstructure will be modified (or usage will be clarified) for transcoding.What I meant is that the
snd_codectook a lot of time to agree on, and it was based on standards. I wonder if for a generic API the parameters can be defined at all. It's probably hardware/vendor specific.
My goal is to start with something simple and decoding of the compressed stream to a PCM stream or ASRC use is really simple. Almost all parameters are already available in this structure, it's just about to settle the output buffer format.
Quoted 52 lines
Quoted 37 lines
Quoted 9 lines
Quoted 7 lines
Documentation/sound/designs/compress-passthrough.rst new file +6
-0+CREATE +------ +Creates a set of input/output buffers. The input buffer size is +fragment_size. Allocates unique seqno. + +The hardware drivers allocate internal 'struct dma_buf' for bothinput and
for each input and output buffers?
Yes, for one task you need one input and one output buffer. All tasks are separate (but serialized).
Quoted 6 lines
Documentation/sound/designs/compress-passthrough.rst line 116
Quoted 4 lines
Documentation/sound/designs/compress-passthrough.rst new file +4
-0+STOP +---- +Stop (dequeues) a task. If seqno is zero, operation is executed for all +tasks.Don't you need a DRAIN?
I would expect that transcoding will be fast or the application may use smaller input buffers. We can add drain only when really required.
Quoted 8 lines
for a co-processor API, you would want all the input data to be consumed and the stop happens when all the resulting data is provided in output buffers.
And presumably when the input task is stopped, the state changes are propagated to the next task by the framework? Or is userspace supposed to track each and every task and change their state?
Quoted 5 lines
I also wonder if the state for a task should reflect that it's waiting on data on its input, or conversely is blocked because the output buffers were not consumed? Dealing with SRC, encoders or decoders mean that the buffers are going to be used at vastly different rates on input and outputs.
Quoted 8 lines
I would suggest to study the proposed sources. The allocated buffer sizes may be different from the really used areas. The user space is able to pass lower number of filled bytes than allocated. Also the driver must ensure that the output buffer is large enough to store result for the allocated input buffer size.
The START operation means that user space filled all input bytes for the conversion.
I have a doubt here. Is the intent to fill a bunch of buffers, then wait for the output to be ready?
Or can userspace write additional buffers while the output is being created (similar to what we do for ALSA today).
Quoted 6 lines
Take the SRC for example. userspace provides 1024 samples, gets the converted output. Now userspace provides a second 1024 sample buffer. That second conversion needs to use the history of the first processing. In other words, when a task is finished, it should not reset its internal context, there is a history buffer that should only be cleared if the input is a completely different track or content.
Yes, I would expect that the hardware driver will keep this state until first STOP command is received. STOP will create a discontinuation. Then the conversion will start again when more buffers are queued. User space can stop all tasks together, too.
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines
Documentation/sound/designs/compress-passthrough.rst line 121
Quoted 4 lines
Documentation/sound/designs/compress-passthrough.rst new file +4
-0+STATUS +------ +Obtain the task status (active, finished). Also, the driver will set +the real output data size (valid area in the output buffer).Is this assuming that the entire input buffer has valid data? There could be cases where the buffers are made of variable-length 'frames', it would be interesting to send such partial buffers to hardware. That's always been a problem with the existing compressed API, we couldn't deal with buffers that were partially filled.
Quoted 3 lines
I expect that the initial handshake (params/metadata) should set all parameters for the driver to determine the right (maximal) output buffer size.
Quoted 6 lines
I wasn't talking about max sizes, but really that each buffer passed by userspace might contain different number of valid bytes. In ALSA, all the bytes are assumed to follow each other, we can't tell than the period N has 200 bytes and period N+1 has 106 bytes valid. That would be a great addition if we can lose the concept of 'ring buffer' and instead deal with independent buffers.
The proposed task works with independent buffers which may be reused to queue next data when the output (result) is consumed. The sizes of used areas in those buffers may be different for each task (variable data chunks).
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.