alsa-utils: axfer: rewrite aplay, adding 'timer-based scheduling' option
A message that is not in the archive (sent off-list or not yet received): [email protected]
alsa-project/alsa-utils pull request #3 was opened from takaswie:
Hi,
This patchset is an updated version of my previous RFCv3, and for merging to upstream.
[alsa-devel] [RFCv3][PATCH 00/39] axfer: rewrite aplay, adding 'timer-based scheduling' option
http://mailman.alsa-project.org/pipermail/alsa-devel/2017-October/125961.html
As I noted in RFCv3, some patches are dropped in this patchset, due to some technical issues. In detail, please refer to RFCv3.
Changes from RFCv3:
- rename scheduling option to 'sched-model'
- improve waiter implementation and add support for select(2)
- categorize supported options as common and backend-dependent
- release alsa-lib configuration space at the end of runtime
- valgrind test and fix some memory leaks
- add 'frame-cache' internal interface to share implementation by several backends.
- add 'libffado' backend just for technical preview (linkage of this library brings problems. Please refet to patch comment.)
I apologize but in this time I don't prepare any help document and manuals as well as RFCv3. Let me put them to a part of task for this development period.
Regards
Takashi Sakamoto (35):
axfer: add an entry point for this command
axfer: add a sub-command to print list of PCMs/devices
axfer: add a common interface to handle a file with audio-specific
data format
axfer: add support for a container of Microsoft/IBM RIFF/Wave format
axfer: add support for a container of Sparc AU format
axfer: add support for a container of Creative Tech. voice format
axfer: add support for a container of raw data
axfer: add unit test for container interface
axfer: add a common interface to align data frames on different layout
axfer: add support for a mapper for single target
axfer: add support for a mapper for multiple target
axfer: add a unit test for mapper interface
axfer: add a common interface to transfer data frames
axfer: add a parser for command-line options
axfer: add support to transfer data frames by alsa-lib PCM APIs
axfer: add support for blocking data transmission operation of
alsa-lib PCM API
axfer: add a sub-command to transfer data frames
axfer: add informative output and an option to suppress it
axfer: add an option to dump available hardware parameters
axfer: add options related to duration and obsolete '--max-file-size'
option
axfer: add an option to finish transmission at XRUN
axfer: add support for non-blocking operation
axfer: add support for MMAP PCM operation
axfer: add an option to suppress event waiting
axfer: add options for buffer arrangement
axfer: add options for software parameters of PCM substream
axfer: add options for plugins in alsa-lib
axfer: add a common interface of waiter for I/O event notification
axfer: add an option for waiter type
axfer: add an implementation of waiter for poll(2)
axfer: add an implementation of waiter for select(2)
axfer: add an implementation of waiter for epoll(7)
axfer: add support for timer-based scheduling model with MMAP
operation
axfer: obsolete some unimplemented options
axfer: add support for libffado transmission backend
``` Makefile.am | 2 +- axfer/Makefile.am | 62 +++ axfer/container-au.c | 203 +++++++ axfer/container-raw.c | 66 +++ axfer/container-riff-wave.c | 575 +++++++++++++++++++ axfer/container-voc.c | 833 +++++++++++++++++++++++++++ axfer/container.c | 457 +++++++++++++++ axfer/container.h | 126 +++++ axfer/frame-cache.c | 111 ++++ axfer/frame-cache.h | 47 ++ axfer/main.c | 229 ++++++++ axfer/mapper-multiple.c | 259 +++++++++ axfer/mapper-single.c | 191 +++++++ axfer/mapper.c | 150 +++++ axfer/mapper.h | 87 +++ axfer/misc.h | 19 + axfer/subcmd-list.c | 234 ++++++++ axfer/subcmd-transfer.c | 467 ++++++++++++++++ axfer/subcmd.h | 18 + axfer/test/Makefile.am | 31 ++ axfer/test/container-test.c | 299 ++++++++++ axfer/test/generator.c | 260 +++++++++ axfer/test/generator.h | 47 ++ axfer/test/mapper-test.c | 491 ++++++++++++++++ axfer/waiter-epoll.c | 107 ++++ axfer/waiter-poll.c | 45 ++ axfer/waiter-select.c | 100 ++++ axfer/waiter.c | 104 ++++ axfer/waiter.h | 61 ++ axfer/xfer-libasound-irq-mmap.c | 282 ++++++++++ axfer/xfer-libasound-irq-rw.c | 427 ++++++++++++++ axfer/xfer-libasound-timer-mmap.c | 455 +++++++++++++++ axfer/xfer-libasound.c | 898 ++++++++++++++++++++++++++++++ axfer/xfer-libasound.h | 92 +++ axfer/xfer-libffado.c | 555 ++++++++++++++++++ axfer/xfer-options.c | 589 ++++++++++++++++++++ axfer/xfer.c | 254 +++++++++ axfer/xfer.h | 115 ++++ configure.ac | 15 +- 39 files changed, 9361 insertions(+), 2 deletions(-) create mode 100644 axfer/Makefile.am create mode 100644 axfer/container-au.c create mode 100644 axfer/container-raw.c create mode 100644 axfer/container-riff-wave.c create mode 100644 axfer/container-voc.c create mode 100644 axfer/container.c create mode 100644 axfer/container.h create mode 100644 axfer/frame-cache.c create mode 100644 axfer/frame-cache.h create mode 100644 axfer/main.c create mode 100644 axfer/mapper-multiple.c create mode 100644 axfer/mapper-single.c create mode 100644 axfer/mapper.c create mode 100644 axfer/mapper.h create mode 100644 axfer/misc.h create mode 100644 axfer/subcmd-list.c create mode 100644 axfer/subcmd-transfer.c create mode 100644 axfer/subcmd.h create mode 100644 axfer/test/Makefile.am create mode 100644 axfer/test/container-test.c create mode 100644 axfer/test/generator.c create mode 100644 axfer/test/generator.h create mode 100644 axfer/test/mapper-test.c create mode 100644 axfer/waiter-epoll.c create mode 100644 axfer/waiter-poll.c create mode 100644 axfer/waiter-select.c create mode 100644 axfer/waiter.c create mode 100644 axfer/waiter.h create mode 100644 axfer/xfer-libasound-irq-mmap.c create mode 100644 axfer/xfer-libasound-irq-rw.c create mode 100644 axfer/xfer-libasound-timer-mmap.c create mode 100644 axfer/xfer-libasound.c create mode 100644 axfer/xfer-libasound.h create mode 100644 axfer/xfer-libffado.c create mode 100644 axfer/xfer-options.c create mode 100644 axfer/xfer.c create mode 100644 axfer/xfer.h ```
Request URL : https://github.com/alsa-project/alsa-utils/pull/3
Patch URL : https://github.com/alsa-project/alsa-utils/pull/3.patch
Repository URL: https://github.com/alsa-project/alsa-utils
PATCH 1/35 axfer: add an entry point for this command
This commit adds a new command, 'axfer' ('ALSA transfer'), to transfer data frames described in asound.h. This command is intended to replace current aplay. The most of features and command line parameters come from aplay as much as possible, while it has more better feature and code to maintain.
This commit adds an entry point for this command. Current option system of aplay is still available, while this command has a sub-command system like commands in iproute2.
Currently, two sub-commands are supported; 'list' and 'transfer'. The 'list' sub-command has the same effect as '-l' and '-L' options of aplay. The 'transfer' sub-command has the same effect as the main feature of aplay. For the sub-command system, an option for stream direction is required; '-P' for playback and '-C' for capture. If you create symbolic links to this binary for aplay/arecord, please execute:
$ ln -s axfer aplay $ ln -s axfer arecord
Actual code for each sub-command will be implemented in later commits.
--- Makefile.am | 2 +- axfer/Makefile.am | 23 ++++++ axfer/main.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++ axfer/misc.h | 16 ++++ axfer/subcmd.h | 14 ++++ configure.ac | 2 +- 6 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 axfer/Makefile.am create mode 100644 axfer/main.c create mode 100644 axfer/misc.h create mode 100644 axfer/subcmd.h
Makefile.am +1 -1
@@ -14,7 +14,7 @@ if ALSACONF SUBDIRS += alsaconf endif if HAVE_PCM -SUBDIRS += aplay iecset speaker-test +SUBDIRS += aplay iecset speaker-test axfer if ALSALOOP SUBDIRS += alsaloop endif
axfer/Makefile.am new file +23 -0
@@ -0,0 +1,23 @@ +bin_PROGRAMS = \ + axfer + +# To include headers for gettext and version. +AM_CPPFLAGS = \ + -I$(top_srcdir)/include + +# Unit tests. +SUBDIRS = + +LIBRT = @LIBRT@ +LDADD = \ + $(LIBINTL) \ + $(LIBRT) + +noinst_HEADERS = \ + misc.h \ + subcmd.h + +axfer_SOURCES = \ + misc.h \ + subcmd.h \ + main.c
axfer/main.c new file +193 -0
193 lines not on this page · raw message
axfer/misc.h new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// misc.h - a header file for miscellaneous tools. +// +// Copyright (c) 2018 Takashi Sakamoto <[email protected]> +// +// Licensed under the terms of the GNU General Public License, version 2. + +#ifndef __ALSA_UTILS_AXFER_MISC__H_ +#define __ALSA_UTILS_AXFER_MISC__H_ + +#include <gettext.h> + +#define ARRAY_SIZE (array) (sizeof(array)/sizeof(array[0])) + +#endif
axfer/subcmd.h new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// subcmd.h - a header for each sub-commands. +// +// Copyright (c) 2018 Takashi Sakamoto <[email protected]> +// +// Licensed under the terms of the GNU General Public License, version 2. + +#ifndef __ALSA_UTILS_AXFER_SUBCMD__H_ +#define __ALSA_UTILS_AXFER_SUBCMD__H_ + +#include <alsa/asoundlib.h> + +#endif
configure.ac +1 -1
@@ -430,4 +430,4 @@ AC_OUTPUT(Makefile alsactl/Makefile alsactl/init/Makefile \ utils/alsa-utils.spec seq/Makefile seq/aconnect/Makefile \ seq/aplaymidi/Makefile seq/aseqdump/Makefile seq/aseqnet/Makefile \ speaker-test/Makefile speaker-test/samples/Makefile \ - alsaloop/Makefile alsa-info/Makefile) + alsaloop/Makefile alsa-info/Makefile axfer/Makefile)
Signature · 1 line
2.19.1
PATCH 2/35 axfer: add a sub-command to print list of PCMs/devices
Original aplay implementation has a feature to output two types of list; devices and PCMs. The list of devices is a result to query sound card and pcm component structured maintained in kernel land. The list of PCMs is a result to parse runtime configuration files in alsa-lib. Entries in the former list is corresponding to ALSA PCM character device ('/dev/snd/pcm%uC%uD[p|c]'), while entries in the latter list includes some 'virtual' instances in application runtime.
This commit adds an implementation for the above functionality. This is executed by taking 'list' sub-command. A 'device' option has the same effect as '--list-devices' and '-L' of aplay. A 'pcm' option has the same effect as '--list-pcms' and '-l' of aplay. In both cases, an additional option is required for stream direction. Below is examples of new command system for this sub-command.
$ axfer list device -C (= arecord --list-devices) $ axfer list pcm -P (= aplay -l)
--- axfer/Makefile.am | 3 +- axfer/main.c | 2 +- axfer/subcmd-list.c | 234 ++++++++++++++++++++++++++++++++++++++++++++ axfer/subcmd.h | 2 + 4 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 axfer/subcmd-list.c
axfer/Makefile.am +2 -1
@@ -20,4 +20,5 @@ noinst_HEADERS = \ axfer_SOURCES = \ misc.h \ subcmd.h \ - main.c + main.c \ + subcmd-list.c
axfer/main.c +1 -1
@@ -181,7 +181,7 @@ int main(int argc, char *const *argv)if (subcmd ==SUBCMD_TRANSFER )printf ("execute 'transfer' subcmd.\n" );else if (subcmd ==SUBCMD_LIST ) -printf ("execute 'list' subcmd.\n" ); + err =subcmd_list (argc, argv, direction);else if (subcmd ==SUBCMD_VERSION )print_version (argv[0 ]);else
axfer/subcmd-list.c new file +234 -0
234 lines not on this page · raw message
axfer/subcmd.h +2 -0
@@ -11,4 +11,6 @@#include <alsa/asoundlib.h> +int subcmd_list (int argc,char *const *argv,snd_pcm_stream_t direction); +#endif
Signature · 1 line
2.19.1
PATCH 3/35 axfer: add a common interface to handle a file with audio-specific data format
In reply to Takashi SakamotoCurrent aplay supports several types of data format for file; Microsoft/IBM RIFF/Wave (.wav), Sparc AU (.au) and Creative Tech. voice (.voc). These formats were designed to handle audio-related data with interleaved frame alignment.
This commit adds a common interface to handle the file format, named as 'container' module. This includes several functions to build/parse the format data from any file descriptors. Furthermore, this includes several helper functions for implementations of each builder/parser.
--- axfer/Makefile.am | 7 +- axfer/container.c | 423 ++++++++++++++++++++++++++++++++++++++++++++++ axfer/container.h | 110 ++++++++++++ 3 files changed, 538 insertions(+), 2 deletions(-) create mode 100644 axfer/container.c create mode 100644 axfer/container.h
axfer/Makefile.am +5 -2
@@ -15,10 +15,13 @@ LDADD = \ noinst_HEADERS = \ misc.h \ - subcmd.h + subcmd.h \ + container.h axfer_SOURCES = \ misc.h \ subcmd.h \ main.c \ - subcmd-list.c + subcmd-list.c \ + container.h \ + container.c
axfer/container.c new file +423 -0
423 lines not on this page · raw message
axfer/container.h new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 4/35 axfer: add support for a container of Microsoft/IBM RIFF/Wave format
In reply to Takashi SakamotoThis commit adds support for data of Microsoft/IBM RIFF/Wave format. In this data format, values in each of field are encoded in both bit/little byte order but inner a file the same order is used. Magic bytes in the beginning of data indicated which byte order is used for the file.
--- axfer/Makefile.am | 3 +- axfer/container-riff-wave.c | 575 ++++++++++++++++++++++++++++++++++++ axfer/container.c | 9 +- axfer/container.h | 4 + 4 files changed, 586 insertions(+), 5 deletions(-) create mode 100644 axfer/container-riff-wave.c
axfer/Makefile.am +2 -1
@@ -24,4 +24,5 @@ axfer_SOURCES = \ main.c \ subcmd-list.c \ container.h \ - container.c + container.c \ + container-riff-wave.c
axfer/container-riff-wave.c new file +575 -0
575 lines not on this page · raw message
axfer/container.c +5 -4
@@ -20,13 +20,14 @@ static const char *const cntr_type_labels[] = { };static const char *const cntr_format_labels[] = { - [CONTAINER_FORMAT_COUNT ] ="" , + [CONTAINER_FORMAT_RIFF_WAVE ] ="riff/wave" , };static const char *const suffixes[] = { - [CONTAINER_FORMAT_COUNT ] ="" , + [CONTAINER_FORMAT_RIFF_WAVE ] =".wav" , }; +const char *const container_suffix_from_format (enum container_format format) {return suffixes[format];
@@ -140,7 +141,7 @@ int container_parser_init(struct container_context *cntr, const char *const path, unsigned int verbose) {const struct container_parser *parsers[] = { -NULL , + [CONTAINER_FORMAT_RIFF_WAVE ] = &container_parser_riff_wave, };const struct container_parser *parser;unsigned int size;
@@ -214,7 +215,7 @@ int container_builder_init(struct container_context *cntr, unsigned int verbose) {const struct container_builder *builders[] = { -NULL , + [CONTAINER_FORMAT_RIFF_WAVE ] = &container_builder_riff_wave, };const struct container_builder *builder;int err;
axfer/container.h +4 -0
@@ -25,6 +25,7 @@ enum container_type { };enum container_format { +CONTAINER_FORMAT_RIFF_WAVE =0 ,CONTAINER_FORMAT_COUNT , };
@@ -107,4 +108,7 @@ int container_recursive_write(struct container_context *cntr, void *buf, unsigned int byte_count);int container_seek_offset (struct container_context *cntr,off64_t offset); +extern const struct container_parser container_parser_riff_wave; +extern const struct container_builder container_builder_riff_wave; +#endif
Signature · 1 line
2.19.1
PATCH 5/35 axfer: add support for a container of Sparc AU format
In reply to Takashi SakamotoThis commit adds support for data of Sparc AU format. In this data format, values in each of field are encoded in big-endian byte order and available formats of data sample are restricted in big-endian byte order.
--- axfer/Makefile.am | 3 +- axfer/container-au.c | 203 +++++++++++++++++++++++++++++++++++++++++++ axfer/container.c | 6 +- axfer/container.h | 4 + 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 axfer/container-au.c
axfer/Makefile.am +2 -1
@@ -25,4 +25,5 @@ axfer_SOURCES = \ subcmd-list.c \ container.h \ container.c \ - container-riff-wave.c + container-riff-wave.c \ + container-au.c
axfer/container-au.c new file +203 -0
203 lines not on this page · raw message
axfer/container.c +5 -1
@@ -21,10 +21,12 @@ static const char *const cntr_type_labels[] = {static const char *const cntr_format_labels[] = { [CONTAINER_FORMAT_RIFF_WAVE ] ="riff/wave" , + [CONTAINER_FORMAT_AU ] ="au" , };static const char *const suffixes[] = { - [CONTAINER_FORMAT_RIFF_WAVE ] =".wav" , + [CONTAINER_FORMAT_RIFF_WAVE ] =".wav" , + [CONTAINER_FORMAT_AU ] =".au" , };
@@ -142,6 +144,7 @@ int container_parser_init(struct container_context *cntr, {const struct container_parser *parsers[] = { [CONTAINER_FORMAT_RIFF_WAVE ] = &container_parser_riff_wave, + [CONTAINER_FORMAT_AU ] = &container_parser_au, };const struct container_parser *parser;unsigned int size;
@@ -216,6 +219,7 @@ int container_builder_init(struct container_context *cntr, {const struct container_builder *builders[] = { [CONTAINER_FORMAT_RIFF_WAVE ] = &container_builder_riff_wave, + [CONTAINER_FORMAT_AU ] = &container_builder_au, };const struct container_builder *builder;int err;
axfer/container.h +4 -0
@@ -26,6 +26,7 @@ enum container_type {enum container_format {CONTAINER_FORMAT_RIFF_WAVE =0 , +CONTAINER_FORMAT_AU ,CONTAINER_FORMAT_COUNT , };
@@ -111,4 +112,7 @@ int container_seek_offset(struct container_context *cntr, off64_t offset);extern const struct container_parser container_parser_riff_wave;extern const struct container_builder container_builder_riff_wave; +extern const struct container_parser container_parser_au; +extern const struct container_builder container_builder_au; +#endif
Signature · 1 line
2.19.1
PATCH 6/35 axfer: add support for a container of Creative Tech. voice format
In reply to Takashi SakamotoThis commit adds support for data of Creative Tech. voice format. In this data format, values in each of field are represented in little-endian byte order and available formats of data sample are restricted in little-endian byte order.
In version 1.10 of this format, sampling rate is represented with reciprocal number of the rate, thus we cannot calculate original sampling rate precisely just from its header. For example at 44.1kHz, file header includes 233 (=256-1,000,000/44,100), but we cannot recover the value just from the code (43478.2...). For my convenience, this commit adds a pre-computed table and lookup major rates from the table.
Additionally, this format can includes several blocks with different sample format. When handling this type of file, we need to start/stop substream for each of the block, while this brings complicated code. This type of format is enough ancient and presently quite minor. This commit takes a compromise and handles a first sample block only.
--- axfer/Makefile.am | 3 +- axfer/container-voc.c | 833 ++++++++++++++++++++++++++++++++++++++++++ axfer/container.c | 4 + axfer/container.h | 4 + 4 files changed, 843 insertions(+), 1 deletion(-) create mode 100644 axfer/container-voc.c
axfer/Makefile.am +2 -1
@@ -26,4 +26,5 @@ axfer_SOURCES = \ container.h \ container.c \ container-riff-wave.c \ - container-au.c + container-au.c \ + container-voc.c
axfer/container-voc.c new file +833 -0
833 lines not on this page · raw message
axfer/container.c +4 -0
@@ -22,11 +22,13 @@ static const char *const cntr_type_labels[] = {static const char *const cntr_format_labels[] = { [CONTAINER_FORMAT_RIFF_WAVE ] ="riff/wave" , [CONTAINER_FORMAT_AU ] ="au" , + [CONTAINER_FORMAT_VOC ] ="voc" , };static const char *const suffixes[] = { [CONTAINER_FORMAT_RIFF_WAVE ] =".wav" , [CONTAINER_FORMAT_AU ] =".au" , + [CONTAINER_FORMAT_VOC ] =".voc" , };
@@ -145,6 +147,7 @@ int container_parser_init(struct container_context *cntr,const struct container_parser *parsers[] = { [CONTAINER_FORMAT_RIFF_WAVE ] = &container_parser_riff_wave, [CONTAINER_FORMAT_AU ] = &container_parser_au, + [CONTAINER_FORMAT_VOC ] = &container_parser_voc, };const struct container_parser *parser;unsigned int size;
@@ -220,6 +223,7 @@ int container_builder_init(struct container_context *cntr,const struct container_builder *builders[] = { [CONTAINER_FORMAT_RIFF_WAVE ] = &container_builder_riff_wave, [CONTAINER_FORMAT_AU ] = &container_builder_au, + [CONTAINER_FORMAT_VOC ] = &container_builder_voc, };const struct container_builder *builder;int err;
axfer/container.h +4 -0
@@ -27,6 +27,7 @@ enum container_type {enum container_format {CONTAINER_FORMAT_RIFF_WAVE =0 ,CONTAINER_FORMAT_AU , +CONTAINER_FORMAT_VOC ,CONTAINER_FORMAT_COUNT , };
@@ -115,4 +116,7 @@ extern const struct container_builder container_builder_riff_wave;extern const struct container_parser container_parser_au;extern const struct container_builder container_builder_au; +extern const struct container_parser container_parser_voc; +extern const struct container_builder container_builder_voc; +#endif
Signature · 1 line
2.19.1
PATCH 7/35 axfer: add support for a container of raw data
In reply to Takashi SakamotoThis commit adds support for raw data without any headers/chunks/blocks. A parser of container cannot recognize format of sample without supplemental information.
Additionally, it includes no magic bytes. A parser of container should process first several bytes as a part of PCM frames, instead of magic bytes.
--- axfer/Makefile.am | 3 +- axfer/container-raw.c | 66 +++++++++++++++++++++++++++++++++++++++++++ axfer/container.c | 37 ++++++++++++++++++++---- axfer/container.h | 4 +++ 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 axfer/container-raw.c
axfer/Makefile.am +2 -1
@@ -27,4 +27,5 @@ axfer_SOURCES = \ container.c \ container-riff-wave.c \ container-au.c \ - container-voc.c + container-voc.c \ + container-raw.c
axfer/container-raw.c new file +66 -0
66 lines not on this page · raw message
axfer/container.c +31 -6
@@ -23,15 +23,16 @@ static const char *const cntr_format_labels[] = { [CONTAINER_FORMAT_RIFF_WAVE] = "riff/wave", [CONTAINER_FORMAT_AU] = "au", [CONTAINER_FORMAT_VOC] = "voc", + [CONTAINER_FORMAT_RAW] = "raw", };static const char *const suffixes[] = { [CONTAINER_FORMAT_RIFF_WAVE ] =".wav" , [CONTAINER_FORMAT_AU ] =".au" , [CONTAINER_FORMAT_VOC ] =".voc" , + [CONTAINER_FORMAT_RAW ] ="" , }; -const char *const container_suffix_from_format (enum container_format format) {return suffixes[format];
@@ -108,7 +109,7 @@ enum container_format container_format_from_path(const char *path) }// Unsupported. -return CONTAINER_FORMAT_COUNT ; +return CONTAINER_FORMAT_RAW ; }int container_seek_offset (struct container_context *cntr,off64_t offset)
@@ -196,7 +197,7 @@ int container_parser_init(struct container_context *cntr,// Unless detected, use raw container. if (i ==ARRAY_SIZE (parsers)) -return -EINVAL ; + parser = &container_parser_raw;// Allocate private data for the parser. if (parser->private_size >0 ) {
@@ -224,6 +225,7 @@ int container_builder_init(struct container_context *cntr, [CONTAINER_FORMAT_RIFF_WAVE] = &container_builder_riff_wave, [CONTAINER_FORMAT_AU] = &container_builder_au, [CONTAINER_FORMAT_VOC] = &container_builder_voc, + [CONTAINER_FORMAT_RAW] = &container_builder_raw, };const struct container_builder *builder;int err;
@@ -302,6 +304,16 @@ int container_context_pre_process(struct container_context *cntr,return 0 ; } +if (cntr->format ==CONTAINER_FORMAT_RAW ) { +if (*format ==SND_PCM_FORMAT_UNKNOWN || + *samples_per_frame ==0 || *frames_per_second ==0 ) { +fprintf (stderr, +"Any file format is not detected. Need to " +"indicate all of sample format, channels and " +"rate explicitly.\n" ); +return -EINVAL ; + } + }assert (*format >=SND_PCM_FORMAT_S8 );assert (*format <=SND_PCM_FORMAT_LAST );assert (*samples_per_frame >0 );
@@ -348,6 +360,7 @@ int container_context_process_frames(struct container_context *cntr,char *buf = frame_buffer;unsigned int bytes_per_frame;unsigned int byte_count; +unsigned int target_byte_count;int err;assert (cntr);
@@ -356,7 +369,19 @@ int container_context_process_frames(struct container_context *cntr,assert (frame_count); bytes_per_frame = cntr->bytes_per_sample * cntr->samples_per_frame; - byte_count = *frame_count * bytes_per_frame; + target_byte_count = *frame_count * bytes_per_frame; + +// A parser of cotainers already read first 4 bytes to detect format +// of container, however they includes PCM frames when any format was +// undetected. Surely to write out them. + byte_count = target_byte_count; +if (cntr->format ==CONTAINER_FORMAT_RAW && + cntr->type ==CONTAINER_TYPE_PARSER && !cntr->magic_handled) { +memcpy (buf, cntr->magic,sizeof (cntr->magic)); + buf +=sizeof (cntr->magic); + byte_count -=sizeof (cntr->magic); + cntr->magic_handled = true; + }// Each container has limitation for its volume for sample data. if (cntr->handled_byte_count > cntr->max_size - byte_count)
@@ -370,11 +395,11 @@ int container_context_process_frames(struct container_context *cntr,return err; } - cntr->handled_byte_count += byte_count; + cntr->handled_byte_count += target_byte_count;if (cntr->handled_byte_count == cntr->max_size) cntr->eof = true; - *frame_count = byte_count / bytes_per_frame; + *frame_count = target_byte_count / bytes_per_frame;return 0 ; }
axfer/container.h +4 -0
@@ -28,6 +28,7 @@ enum container_format {CONTAINER_FORMAT_RIFF_WAVE =0 ,CONTAINER_FORMAT_AU ,CONTAINER_FORMAT_VOC , +CONTAINER_FORMAT_RAW , CONTAINER_FORMAT_COUNT, };
@@ -119,4 +120,7 @@ extern const struct container_builder container_builder_au;extern const struct container_parser container_parser_voc;extern const struct container_builder container_builder_voc; +const struct container_parser container_parser_raw; +const struct container_builder container_builder_raw; +#endif
Signature · 1 line
2.19.1
PATCH 8/35 axfer: add unit test for container interface
In reply to Takashi SakamotoIn former commits, container module gets supports of parser/builder for several types of file format. This commit adds a unit test for them. This includes positive test cases only. The test cases actually generate I/O to file systems for many test cases. It takes a long time to finish.
--- axfer/Makefile.am | 3 +- axfer/test/Makefile.am | 15 ++ axfer/test/container-test.c | 299 ++++++++++++++++++++++++++++++++++++ axfer/test/generator.c | 260 +++++++++++++++++++++++++++++++ axfer/test/generator.h | 47 ++++++ configure.ac | 3 +- 6 files changed, 625 insertions(+), 2 deletions(-) create mode 100644 axfer/test/Makefile.am create mode 100644 axfer/test/container-test.c create mode 100644 axfer/test/generator.c create mode 100644 axfer/test/generator.h
axfer/Makefile.am +2 -1
@@ -6,7 +6,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/include # Unit tests. -SUBDIRS = +SUBDIRS = \ + test LIBRT = @LIBRT@ LDADD = \
axfer/test/Makefile.am new file +15 -0
@@ -0,0 +1,15 @@ +TESTS = \ + container-test + +check_PROGRAMS = \ + container-test + +container_test_SOURCES = \ + ../container.h \ + ../container.c \ + ../container-riff-wave.c \ + ../container-au.c \ + ../container-voc.c \ + ../container-raw.c \ + generator.c \ + container-test.c
axfer/test/container-test.c new file +299 -0
299 lines not on this page · raw message
axfer/test/generator.c new file +260 -0
260 lines not on this page · raw message
axfer/test/generator.h new file +47 -0
47 lines not on this page · raw message
configure.ac +2 -1
@@ -430,4 +430,5 @@ AC_OUTPUT(Makefile alsactl/Makefile alsactl/init/Makefile \ utils/alsa-utils.spec seq/Makefile seq/aconnect/Makefile \ seq/aplaymidi/Makefile seq/aseqdump/Makefile seq/aseqnet/Makefile \ speaker-test/Makefile speaker-test/samples/Makefile \ - alsaloop/Makefile alsa-info/Makefile axfer/Makefile) + alsaloop/Makefile alsa-info/Makefile \ + axfer/Makefile axfer/test/Makefile)
Signature · 1 line
2.19.1
PATCH 9/35 axfer: add a common interface to align data frames on different layout
In reply to Takashi SakamotoIn current aplay, several files can be handled as source of data frames for playback, or destination of captured data frames by an option '--separate-channels' (-I).
On the other hand, in ALSA PCM kernel/user interface, several types of buffer are used to communicate between application/hardware;
- mapped page frame for data frames with interleaved alignment
- mapped page frame for data frames with non-interleaved alignment
- buffer in user space for data frames with interleaved alignment
- a list of buffer in user space for data frames with non-interleaved alignment
This commit adds a common interface, named as 'mapper' to convert frame alignment between these two sides. This interface includes two types; 'muxer' and 'demuxer'. The 'muxer' is for playback direction, to construct playback buffer with PCM frames from several files. The 'demuxer' is for capture direction, to split PCM frames from capture buffer to each of file. Unlike multimedia containers such as MPEG 2/4 Systems, the 'muxer' and 'demuxer' are for playback/capture buffer, not for file contents.
--- axfer/Makefile.am | 7 ++- axfer/mapper.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ axfer/mapper.h | 79 +++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 axfer/mapper.c create mode 100644 axfer/mapper.h
axfer/Makefile.am +5 -2
@@ -17,7 +17,8 @@ LDADD = \ noinst_HEADERS = \ misc.h \ subcmd.h \ - container.h + container.h \ + mapper.h axfer_SOURCES = \ misc.h \
@@ -29,4 +30,6 @@ axfer_SOURCES = \ container-riff-wave.c \ container-au.c \ container-voc.c \ - container-raw.c + container-raw.c \ + mapper.h \ + mapper.c
axfer/mapper.c new file +125 -0
125 lines not on this page · raw message
axfer/mapper.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 10/35 axfer: add support for a mapper for single target
In reply to Takashi SakamotoIn usual use case of aplay, single file is used to playback or capture data frames.
This commit adds support of single type mapper for this use case. All of supported file format can include data frame with interleaved alignment, thus this mapper have a functionality to convert from several types of data frame alignment to interleaved alignment or vise versa. When handling non-interleaved buffer, a caller should use an array of buffer for each of channels with non-interleaved data frames.
--- axfer/Makefile.am | 3 +- axfer/mapper-single.c | 191 ++++++++++++++++++++++++++++++++++++++++++ axfer/mapper.c | 14 +++- axfer/mapper.h | 4 + 4 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 axfer/mapper-single.c
axfer/Makefile.am +2 -1
@@ -32,4 +32,5 @@ axfer_SOURCES = \ container-voc.c \ container-raw.c \ mapper.h \ - mapper.c + mapper.c \ + mapper-single.c
axfer/mapper-single.c new file +191 -0
191 lines not on this page · raw message
axfer/mapper.c +13 -1
@@ -18,7 +18,7 @@ static const char *const mapper_type_labels[] = { };static const char *const mapper_target_labels[] = { - [MAPPER_TARGET_COUNT ] ="" , + [MAPPER_TARGET_SINGLE ] ="single" , }; int mapper_context_init(struct mapper_context *mapper,
@@ -35,6 +35,18 @@ int mapper_context_init(struct mapper_context *mapper,memset (mapper,0 ,sizeof (*mapper)); +if (type ==MAPPER_TYPE_MUXER ) { +if (cntr_count ==1 ) { + data = &mapper_muxer_single; + mapper->target =MAPPER_TARGET_SINGLE ; + } + }else { +if (cntr_count ==1 ) { + data = &mapper_demuxer_single; + mapper->target =MAPPER_TARGET_SINGLE ; + } + } + mapper->ops = &data->ops; mapper->type = type;
axfer/mapper.h +4 -0
@@ -19,6 +19,7 @@ enum mapper_type { };enum mapper_target { +MAPPER_TARGET_SINGLE =0 ,MAPPER_TARGET_COUNT , };
@@ -76,4 +77,7 @@ struct mapper_data { unsigned int private_size; }; +extern const struct mapper_data mapper_muxer_single; +extern const struct mapper_data mapper_demuxer_single; +#endif
Signature · 1 line
2.19.1
PATCH 11/35 axfer: add support for a mapper for multiple target
In reply to Takashi SakamotoThis commit adds support of mapper for 'multiple' target. This handles several files via 'container' functions, and constructs data frame buffer for playback, or splits data frames from data frame buffer for capture. When playback source files includes data frames with several channels, the first channel is used to construct buffer. For capture direction, each of channel of data frame is stored in one file, thus the file includes one channel of data frame. When handling non-interleaved buffer, a caller should use an array of buffer for each of channels with non-interleaved data frames.
--- axfer/Makefile.am | 3 +- axfer/mapper-multiple.c | 259 ++++++++++++++++++++++++++++++++++++++++ axfer/mapper.c | 13 ++ axfer/mapper.h | 4 + 4 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 axfer/mapper-multiple.c
axfer/Makefile.am +2 -1
@@ -33,4 +33,5 @@ axfer_SOURCES = \ container-raw.c \ mapper.h \ mapper.c \ - mapper-single.c + mapper-single.c \ + mapper-multiple.c
axfer/mapper-multiple.c new file +259 -0
259 lines not on this page · raw message
axfer/mapper.c +13 -0
@@ -19,6 +19,7 @@ static const char *const mapper_type_labels[] = {static const char *const mapper_target_labels[] = { [MAPPER_TARGET_SINGLE ] ="single" , + [MAPPER_TARGET_MULTIPLE ] ="multiple" , }; int mapper_context_init(struct mapper_context *mapper,
@@ -39,11 +40,17 @@ int mapper_context_init(struct mapper_context *mapper,if (cntr_count ==1 ) { data = &mapper_muxer_single; mapper->target =MAPPER_TARGET_SINGLE ; + }else { + data = &mapper_muxer_multiple; + mapper->target =MAPPER_TARGET_MULTIPLE ; } }else {if (cntr_count ==1 ) { data = &mapper_demuxer_single; mapper->target =MAPPER_TARGET_SINGLE ; + }else { + data = &mapper_demuxer_multiple; + mapper->target =MAPPER_TARGET_MULTIPLE ; } }
@@ -77,6 +84,12 @@ int mapper_context_pre_process(struct mapper_context *mapper,assert (samples_per_frame >0 );assert (cntrs); +// The purpose of multiple target is to mux/demux each channels to/from +// containers. +if (mapper->target ==MAPPER_TARGET_MULTIPLE && + samples_per_frame != mapper->cntr_count) +return -EINVAL ; + mapper->access = access; mapper->bytes_per_sample = bytes_per_sample; mapper->samples_per_frame = samples_per_frame;
axfer/mapper.h +4 -0
@@ -20,6 +20,7 @@ enum mapper_type {enum mapper_target {MAPPER_TARGET_SINGLE =0 , +MAPPER_TARGET_MULTIPLE ,MAPPER_TARGET_COUNT , };
@@ -80,4 +81,7 @@ struct mapper_data {extern const struct mapper_data mapper_muxer_single;extern const struct mapper_data mapper_demuxer_single; +extern const struct mapper_data mapper_muxer_multiple; +extern const struct mapper_data mapper_demuxer_multiple; +#endif
Signature · 1 line
2.19.1
PATCH 12/35 axfer: add a unit test for mapper interface
In reply to Takashi SakamotoIn former commits, mapper module gets supports of muxer/demuxer for single/multiple targets for playback source or capture destination. This commit adds a unit test for them. This includes positive test cases only. The test cases actually generate I/O to file systems for many test cases. It takes a bit long time to finish.
--- axfer/test/Makefile.am | 20 +- axfer/test/mapper-test.c | 491 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 axfer/test/mapper-test.c
axfer/test/Makefile.am +18 -2
@@ -1,8 +1,10 @@ TESTS = \ - container-test + container-test \ + mapper-test check_PROGRAMS = \ - container-test + container-test \ + mapper-test container_test_SOURCES = \ ../container.h \
@@ -13,3 +15,17 @@ container_test_SOURCES = \ ../container-raw.c \ generator.c \ container-test.c + +mapper_test_SOURCES = \ + ../container.h \ + ../container.c \ + ../container-riff-wave.c \ + ../container-au.c \ + ../container-voc.c \ + ../container-raw.c \ + ../mapper.h \ + ../mapper.c \ + ../mapper-single.c \ + ../mapper-multiple.c \ + generator.c \ + mapper-test.c
axfer/test/mapper-test.c new file +491 -0
491 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 13/35 axfer: add a common interface to transfer data frames
In reply to Takashi SakamotoALSA has PCM interface to transfer data frames. In userspace, there're some implementation to utilize this interface to produce application programming interface; alsa-lib (libasound) and tinyalsa. However, it's possible to use the interface with raw I/O operations.
This commit adds an common interface to transfer data frames for this program, named as 'xfer'. This internal interface is designed for users to select several backend for data transmission. This includes some functions expected to be called by main program just for data transmission. In an aspect to maintain PCM substream, suspend feature is required to handle a pair of SIGTSTP/SIGCONT UNIX signals.
--- axfer/Makefile.am | 7 +- axfer/xfer.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++ axfer/xfer.h | 80 ++++++++++++++++++++++ 3 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 axfer/xfer.c create mode 100644 axfer/xfer.h
axfer/Makefile.am +5 -2
@@ -18,7 +18,8 @@ noinst_HEADERS = \ misc.h \ subcmd.h \ container.h \ - mapper.h + mapper.h \ + xfer.h axfer_SOURCES = \ misc.h \
@@ -34,4 +35,6 @@ axfer_SOURCES = \ mapper.h \ mapper.c \ mapper-single.c \ - mapper-multiple.c + mapper-multiple.c \ + xfer.h \ + xfer.c
axfer/xfer.c new file +170 -0
170 lines not on this page · raw message
axfer/xfer.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 14/35 axfer: add a parser for command-line options
In reply to Takashi SakamotoIn aplay, many command-line options are supported. Some of them have dependency or conflicts. Furthemore, some of them are just for runtime configuration of alsa-lib(libasound), and some options can be used by several xfer backends commonly; e.g. options for file name, sample format and sampling rate.
This commit adds a parser for the common options below.
* --help (-h)
* Just output 'help' string (not written yet).
* --verbose (-v)
* For verbose output, including information about xfer, mapper and container.
* --format (-f): string. format literals or one of ['cd'|'cdr'|'dat']
* For sample format supported by ALSA PCM interface. Special format can be used. For playback, this is auto-detected according to actual file format.
* --channels (-c)
* For the number of samples included in one data frame. For playback, this is auto-detected according to actual file format, except for 'raw' format. This option can conflict to above format option.
* --rate (-r)
* For the number of data frames transferred in one second. For playback, this is auto-detected according to actual file format, except for 'raw' format. This option can conflict to format option above.
* --file-type (-f): string. one of ['wav'|'au'|'voc'|'raw']
* For format of files of given paths. For playback, this is optional because the format is auto-detected. For capture, this is optional too because the format is decided according to suffix of given path. Anyway, this option is used for cases to fail to detect or decide.
* --separate-channels (-I)
* When using several files as source or destination for transmission of data frame, this option can be used with several file paths.
When '--separate-channels' option is used, users can give several file paths to source/destination of data transmission, else they can give single file path for the purpose. When multiple files are handled by this option, for playback, data frames in first channel is used to construct buffer for data transmission with multi channel. For capture, data frames in each channel of buffer are written to each of given path. Furthermore, when a single path is given for capture, file paths are auto-generated according to available number of channels. For example, 'name.wav' is given for 2 channels capture, 'name-0.wav' and 'name-1.wav' are generated. In a case of no suffix, 'name-0' and 'name-1' are generated.
--- axfer/Makefile.am | 3 +- axfer/main.c | 36 +++ axfer/misc.h | 3 + axfer/xfer-options.c | 535 +++++++++++++++++++++++++++++++++++++++++++ axfer/xfer.c | 78 +++++++ axfer/xfer.h | 19 ++ 6 files changed, 673 insertions(+), 1 deletion(-) create mode 100644 axfer/xfer-options.c
axfer/Makefile.am +2 -1
@@ -37,4 +37,5 @@ axfer_SOURCES = \ mapper-single.c \ mapper-multiple.c \ xfer.h \ - xfer.c + xfer.c \ + xfer-options.c
axfer/main.c +36 -0
@@ -24,6 +24,42 @@ enum subcmds { SUBCMD_VERSION, }; +char *arg_duplicate_string (const char *str,int *err) +{ +char *ptr; + +// For safe. +if (strlen (str) >1024 ) { + *err = -EINVAL ; +return NULL ; + } + + ptr =strdup (str); +if (ptr ==NULL ) + *err = -ENOMEM ; + +return ptr; +} + +long arg_parse_decimal_num (const char *str,int *err) +{ +long val; +char *endptr; + + errno =0 ; + val =strtol (str, &endptr,0 ); +if (errno >0 ) { + *err = -errno; +return 0 ; + } +if (*endptr !='\0' ) { + *err = -EINVAL ; +return 0 ; + } + +return val; +} +static void print_version (const char *const cmdname) {printf ("%s: version %s\n" , cmdname,SND_UTIL_VERSION_STR );
axfer/misc.h +3 -0
@@ -13,4 +13,7 @@#define ARRAY_SIZE (array) (sizeof(array)/sizeof(array[0])) +char *arg_duplicate_string (const char *str,int *err); +long arg_parse_decimal_num (const char *str,int *err); +#endif
axfer/xfer-options.c new file +535 -0
535 lines not on this page · raw message
axfer/xfer.c +78 -0
107 lines not on this page · raw message
axfer/xfer.h +19 -0
@@ -26,7 +26,20 @@ struct xfer_context {const struct xfer_ops *ops;void *private_data; +char *sample_format_literal; +char *cntr_format_literal;unsigned int verbose; +unsigned int frames_per_second; +unsigned int samples_per_frame; + bool help:1; + bool multiple_cntrs:1; // For mapper. + +snd_pcm_format_t sample_format; + +// For containers. +char **paths; +unsigned int path_count; +enum container_format cntr_format; };enum xfer_type xfer_type_from_label (const char *label);
@@ -47,6 +60,12 @@ int xfer_context_process_frames(struct xfer_context *xfer,void xfer_context_pause (struct xfer_context *xfer,bool enable);void xfer_context_post_process (struct xfer_context *xfer); +struct xfer_data ; +int xfer_options_parse_args (struct xfer_context *xfer, +const struct xfer_data *data,int argc, +char *const *argv); +int xfer_options_fixup_paths (struct xfer_context *xfer); +// For internal use in 'xfer' module. struct xfer_ops {
Signature · 1 line
2.19.1
PATCH 15/35 axfer: add support to transfer data frames by alsa-lib PCM APIs
In reply to Takashi SakamotoThis commit adds support fo alsa-lib PCM API as a backend of 'xfer' module. In a set of alsa-lib PCM API, there're two ways to handle data frames; by calling ioctl(2) with some specific commands with buffer in user space, or copying data frames on mapped page frames. To support both ways, this commit adds an operation structure as abstraction.
--- axfer/Makefile.am | 7 +- axfer/xfer-libasound.c | 415 +++++++++++++++++++++++++++++++++++++++++ axfer/xfer-libasound.h | 46 +++++ axfer/xfer.c | 4 +- axfer/xfer.h | 3 +- 5 files changed, 470 insertions(+), 5 deletions(-) create mode 100644 axfer/xfer-libasound.c create mode 100644 axfer/xfer-libasound.h
axfer/Makefile.am +5 -2
@@ -19,7 +19,8 @@ noinst_HEADERS = \ subcmd.h \ container.h \ mapper.h \ - xfer.h + xfer.h \ + xfer-libasound.h axfer_SOURCES = \ misc.h \
@@ -38,4 +39,6 @@ axfer_SOURCES = \ mapper-multiple.c \ xfer.h \ xfer.c \ - xfer-options.c + xfer-options.c \ + xfer-libasound.h \ + xfer-libasound.c
axfer/xfer-libasound.c new file +415 -0
415 lines not on this page · raw message
axfer/xfer-libasound.h new file +46 -0
46 lines not on this page · raw message
axfer/xfer.c +2 -2
@@ -12,7 +12,7 @@#include <stdio.h> static const char *const xfer_type_labels[] = { - [XFER_TYPE_COUNT ] ="" , + [XFER_TYPE_LIBASOUND ] ="libasound" , };enum xfer_type xfer_type_from_label (const char *label)
@@ -34,7 +34,7 @@ int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,enum xfer_type type;const struct xfer_data *data; } *entry, entries[] = { - {XFER_TYPE_COUNT, NULL}, + {XFER_TYPE_LIBASOUND, &xfer_libasound}, };int i;int err;
axfer/xfer.h +2 -1
@@ -15,6 +15,7 @@enum xfer_type {XFER_TYPE_UNSUPPORTED =-1 , +XFER_TYPE_LIBASOUND =0 ,XFER_TYPE_COUNT , };
@@ -94,6 +95,6 @@ struct xfer_data { unsigned int private_size; }; -extern const struct xfer_data xfer_alsa; +extern const struct xfer_data xfer_libasound;#endif
Signature · 1 line
2.19.1
PATCH 16/35 axfer: add support for blocking data transmission operation of alsa-lib PCM API
In reply to Takashi SakamotoIn alsa-lib PCM API, snd_pcm_read[i|n]() and snd_pcm_write[i|n]() are used to transfer data frames from/to hardware. When a handler is not opened with specific flags, these functions perform blocking operation; i.e. the function call doesn't return till all of request number of data frames are actually handled, or call is interrupted by Unix signals, or PCM substeam corrupts due to hardware reasons.
This commit adds support for this type of data transmission. For cases that requested data frames are not processed by container interface, this commit adds internal cache mechanism to handle rest of data frames in next timing.
--- axfer/Makefile.am | 8 +- axfer/frame-cache.c | 111 ++++++++++++ axfer/frame-cache.h | 47 ++++++ axfer/xfer-libasound-irq-rw.c | 307 ++++++++++++++++++++++++++++++++++ axfer/xfer-libasound.c | 6 + axfer/xfer-libasound.h | 2 + 6 files changed, 479 insertions(+), 2 deletions(-) create mode 100644 axfer/frame-cache.c create mode 100644 axfer/frame-cache.h create mode 100644 axfer/xfer-libasound-irq-rw.c
axfer/Makefile.am +6 -2
@@ -20,7 +20,8 @@ noinst_HEADERS = \ container.h \ mapper.h \ xfer.h \ - xfer-libasound.h + xfer-libasound.h \ + frame-cache.h axfer_SOURCES = \ misc.h \
@@ -41,4 +42,7 @@ axfer_SOURCES = \ xfer.c \ xfer-options.c \ xfer-libasound.h \ - xfer-libasound.c + xfer-libasound.c \ + frame-cache.h \ + frame-cache.c \ + xfer-libasound-irq-rw.c
axfer/frame-cache.c new file +111 -0
111 lines not on this page · raw message
axfer/frame-cache.h new file +47 -0
47 lines not on this page · raw message
axfer/xfer-libasound-irq-rw.c new file +307 -0
307 lines not on this page · raw message
axfer/xfer-libasound.c +6 -0
@@ -251,6 +251,12 @@ static int xfer_libasound_pre_process(struct xfer_context *xfer,return err;// Assign I/O operation. +if (*access ==SND_PCM_ACCESS_RW_INTERLEAVED || + *access ==SND_PCM_ACCESS_RW_NONINTERLEAVED ) { + state->ops = &xfer_libasound_irq_rw_ops; + }else { +return -ENXIO ; + }if (state->ops->private_size >0 ) { state->private_data =malloc (state->ops->private_size);if (state->private_data ==NULL )
axfer/xfer-libasound.h +2 -0
@@ -43,4 +43,6 @@ struct xfer_libasound_ops { unsigned int private_size; }; +extern const struct xfer_libasound_ops xfer_libasound_irq_rw_ops; +#endif
Signature · 1 line
2.19.1
PATCH 17/35 axfer: add a sub-command to transfer data frames
In reply to Takashi SakamotoIn current aplay, default action is to transfer data frames from/to devices. This commit adds support for this functionality.
Event loop is included in an added file. In the loop, the number of handled data frames is manipulated by an appropriate way. As a result, users can stop data transmission frames by frame.
Unlike aplay, when catching SIGSTP, this application performs to suspend PCM substream. When catching SIGCONT, it performs to resume the PCM substream. The aim of this design is to avoid XRUN state of the PCM substream. If users/developers need to any XRUN-recovery test, it's better to work for the other ways.
Below lines are examples to execute:
$ axfer transfer -P -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer -C -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 +- axfer/main.c | 2 +- axfer/subcmd-transfer.c | 438 ++++++++++++++++++++++++++++++++++++++++ axfer/subcmd.h | 2 + 4 files changed, 443 insertions(+), 2 deletions(-) create mode 100644 axfer/subcmd-transfer.c
axfer/Makefile.am +2 -1
@@ -45,4 +45,5 @@ axfer_SOURCES = \ xfer-libasound.c \ frame-cache.h \ frame-cache.c \ - xfer-libasound-irq-rw.c + xfer-libasound-irq-rw.c \ + subcmd-transfer.c
axfer/main.c +1 -1
@@ -215,7 +215,7 @@ int main(int argc, char *const *argv)decide_subcmd (argc, argv, &subcmd);if (subcmd ==SUBCMD_TRANSFER ) -printf ("execute 'transfer' subcmd.\n" ); + err =subcmd_transfer (argc, argv, direction);else if (subcmd ==SUBCMD_LIST ) err =subcmd_list (argc, argv, direction);else if (subcmd ==SUBCMD_VERSION )
axfer/subcmd-transfer.c new file +438 -0
438 lines not on this page · raw message
axfer/subcmd.h +2 -0
@@ -13,4 +13,6 @@int subcmd_list (int argc,char *const *argv,snd_pcm_stream_t direction); +int subcmd_transfer (int argc,char *const *argv,snd_pcm_stream_t direction); +#endif
Signature · 1 line
2.19.1
PATCH 18/35 axfer: add informative output and an option to suppress it
In reply to Takashi SakamotoIn current aplay, some informative output is available as a default. This can be suppressed by a quiet option. This commit adds support for it.
An original aplay implementation has no effect of this option in a case to handle multiple files. However, in a point of usability, this commit support this case.
--- axfer/subcmd-transfer.c | 27 +++++++++++++++++++++++++++ axfer/xfer-options.c | 5 ++++- axfer/xfer.h | 1 + 3 files changed, 32 insertions(+), 1 deletion(-)
axfer/subcmd-transfer.c +27 -0
@@ -340,6 +340,21 @@ static int context_process_frames(struct context *ctx,int i;int err =0 ; +if (!ctx->xfer.quiet) { +fprintf (stderr, +"%s: Format '%s', Rate %u Hz, Channels " , +snd_pcm_stream_name (direction), +snd_pcm_format_description (ctx->xfer.sample_format), + ctx->xfer.frames_per_second); +if (ctx->xfer.samples_per_frame ==1 ) +fprintf (stderr,"'monaural'" ); +else if (ctx->xfer.samples_per_frame ==2 ) +fprintf (stderr,"'Stereo'" ); +else +fprintf (stderr,"%u" , ctx->xfer.samples_per_frame); +fprintf (stderr,"\n" ); + } + *actual_frame_count =0 ;while (!ctx->interrupted) {struct container_context *cntr;
@@ -370,6 +385,18 @@ static int context_process_frames(struct context *ctx,break ; } +if (!ctx->xfer.quiet) { +fprintf (stderr, +"%s: Expected %lu frames, Actual %lu frames\n" , +snd_pcm_stream_name (direction), expected_frame_count, + *actual_frame_count); +if (ctx->interrupted) { +fprintf (stderr,"Aborted by signal: %s\n" , +strsignal (ctx->signal)); +return 0 ; + } + } +return err; }
axfer/xfer-options.c +4 -1
@@ -227,7 +227,7 @@ int xfer_options_parse_args(struct xfer_context *xfer, const struct xfer_data *data, int argc, char *const *argv) { - static const char *short_opts = "CPhvf:c:r:t:I"; + static const char *short_opts = "CPhvqf:c:r:t:I"; static const struct option long_opts[] = { // For generic purposes. {"capture", 0, 0, 'C'},
@@ -235,6 +235,7 @@ int xfer_options_parse_args(struct xfer_context *xfer, {"xfer-type", 1, 0, OPT_XFER_TYPE}, {"help", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, + {"quiet", 0, 0, 'q'},// For transfer backend. {"format", 1, 0, 'f'}, {"channels", 1, 0, 'c'},
@@ -289,6 +290,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, xfer->help = true; else if (key == 'v') ++xfer->verbose; + else if (key == 'q') + xfer->quiet = true; else if (key == 'f') xfer->sample_format_literal =arg_duplicate_string (optarg, &err); else if (key == 'c')
axfer/xfer.h +1 -0
@@ -33,6 +33,7 @@ struct xfer_context {unsigned int frames_per_second;unsigned int samples_per_frame; bool help:1; + bool quiet:1; bool multiple_cntrs:1; // For mapper.snd_pcm_format_t sample_format;
Signature · 1 line
2.19.1
PATCH 19/35 axfer: add an option to dump available hardware parameters
In reply to Takashi SakamotoIn ALSA PCM interface, before configuring hardware actually, applications can request available set of hardware parameters for runtime of PCM substream. The set of parameters are represented and delivered by a structure.
In alsa-lib PCM API, the above design is abstracted by a series of snd_pcm_hw_params_xxx() functions. An actual layout of the structure is hidden from applications by an opaque pointer.
In aplay, '--dump-hw-params' option is for this purpose. With this option, the command output available set of the hardware parameters.
This commit adds support for the option. Unlike aplay, this commit takes this program to finish after dumping the parameters for simplicity of usage.
I note that all of combinations in the set are not necessarily available when the PCM substream includes dependencies of parameters described by constraints and rules.
--- axfer/subcmd-transfer.c | 2 +- axfer/xfer-libasound.c | 9 +++++++++ axfer/xfer-options.c | 5 +++++ axfer/xfer.h | 1 + 4 files changed, 16 insertions(+), 1 deletion(-)
axfer/subcmd-transfer.c +1 -1
@@ -447,7 +447,7 @@ int subcmd_transfer(int argc, char *const *argv, snd_pcm_stream_t direction) err =context_init (&ctx, direction, argc, argv);if (err <0 ) goto end; -if (ctx.xfer.help) +if (ctx.xfer.help || ctx.xfer.dump_hw_params) goto end; err =context_pre_process (&ctx, direction, &expected_frame_count);
axfer/xfer-libasound.c +9 -0
@@ -99,6 +99,15 @@ static int open_handle(struct xfer_context *xfer)// TODO: Applying NO_PERIOD_WAKEUP should be done here. +if (xfer->dump_hw_params) { +logging (state,"Available HW Params of node: %s\n" , +snd_pcm_name (state->handle)); +snd_pcm_hw_params_dump (state->hw_params, state->log); +// TODO: there're more parameters which are not dumped by +// alsa-lib. +return 0 ; + } +return set_access_hw_param (state); }
axfer/xfer-options.c +5 -0
@@ -16,6 +16,7 @@enum no_short_opts {// 128 or later belong to non us-ascii character set. OPT_XFER_TYPE =128 , +OPT_DUMP_HW_PARAMS , }; static int allocate_paths(struct xfer_context *xfer, char *const *paths,
@@ -244,6 +245,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, {"file-type", 1, 0, 't'},// For mapper. {"separate-channels", 0, 0, 'I'}, +// For debugging. + {"dump-hw-params", 0, 0, OPT_DUMP_HW_PARAMS}, };char *s_opts;struct option *l_opts;
@@ -302,6 +305,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, xfer->cntr_format_literal =arg_duplicate_string (optarg, &err); else if (key == 'I') xfer->multiple_cntrs = true; + else if (key == OPT_DUMP_HW_PARAMS) + xfer->dump_hw_params = true; else if (key == '?') return -EINVAL; else {
axfer/xfer.h +1 -0
@@ -34,6 +34,7 @@ struct xfer_context {unsigned int samples_per_frame; bool help:1; bool quiet:1; + bool dump_hw_params:1; bool multiple_cntrs:1; // For mapper.snd_pcm_format_t sample_format;
Signature · 1 line
2.19.1
PATCH 20/35 axfer: add options related to duration and obsolete '--max-file-size' option
In reply to Takashi SakamotoIn aplay, some options are available to stop data transmission by frame unit. This commit adds support for the options below:
* --duration (-d)
* For duration seconds. The number of data frames transferred in this
* runtime is calculated by this value and sampling rate.
* --samples (-s)
* For the number of data frames to handle in this runtime.
An original aplay has a similar option; '--max-file-time'. This option is used for capture data transmission to switch file to write data frame up to maximum number of frames which container format supports, instead of terminating. However, this may brings complicated file handling to this program. To reduce maintaining cost, this option is obsoleted. Additionally, a handler for SIGUSR1 Unix signal has similar feature to switch the file. For the same reason, the handler is also obsoleted.
--- axfer/subcmd-transfer.c | 2 ++ axfer/xfer-options.c | 38 ++++++++++++++++++++++++++++++++++++-- axfer/xfer.h | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-)
axfer/subcmd-transfer.c +2 -0
@@ -327,6 +327,8 @@ static int context_pre_process(struct context *ctx, snd_pcm_stream_t direction,if (err <0 )return err; +xfer_options_calculate_duration (&ctx->xfer, total_frame_count); +return 0 ; }
axfer/xfer-options.c +36 -2
@@ -17,6 +17,8 @@ enum no_short_opts {// 128 or later belong to non us-ascii character set. OPT_XFER_TYPE =128 ,OPT_DUMP_HW_PARAMS , +// Obsoleted. + OPT_MAX_FILE_TIME, }; static int allocate_paths(struct xfer_context *xfer, char *const *paths,
@@ -228,7 +230,7 @@ int xfer_options_parse_args(struct xfer_context *xfer, const struct xfer_data *data, int argc, char *const *argv) { - static const char *short_opts = "CPhvqf:c:r:t:I"; + static const char *short_opts = "CPhvqd:s:f:c:r:t:I"; static const struct option long_opts[] = { // For generic purposes. {"capture", 0, 0, 'C'},
@@ -237,6 +239,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, {"help", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {"quiet", 0, 0, 'q'}, + {"duration", 1, 0, 'd'}, + {"samples", 1, 0, 's'},// For transfer backend. {"format", 1, 0, 'f'}, {"channels", 1, 0, 'c'},
@@ -247,6 +251,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, {"separate-channels", 0, 0, 'I'},// For debugging. {"dump-hw-params", 0, 0, OPT_DUMP_HW_PARAMS}, +// Obsoleted. + {"max-file-time", 1, 0, OPT_MAX_FILE_TIME}, };char *s_opts;struct option *l_opts;
@@ -295,6 +301,10 @@ int xfer_options_parse_args(struct xfer_context *xfer, ++xfer->verbose; else if (key == 'q') xfer->quiet = true; + else if (key == 'd') + xfer->duration_seconds =arg_parse_decimal_num (optarg, &err); + else if (key == 's') + xfer->duration_frames =arg_parse_decimal_num (optarg, &err); else if (key == 'f') xfer->sample_format_literal =arg_duplicate_string (optarg, &err); else if (key == 'c')
@@ -309,7 +319,13 @@ int xfer_options_parse_args(struct xfer_context *xfer, xfer->dump_hw_params = true; else if (key == '?') return -EINVAL; - else { + else if (key == OPT_MAX_FILE_TIME) { +fprintf (stderr, +"An option '--%s' is obsoleted and has no " +"effect.\n" , + l_opts[l_index].name); + err = -EINVAL ; + } else { err = xfer->ops->parse_opt (xfer, key, optarg);if (err <0 && err != -ENXIO )break ;
@@ -326,6 +342,24 @@ int xfer_options_parse_args(struct xfer_context *xfer,return validate_options (xfer); } +void xfer_options_calculate_duration (struct xfer_context *xfer, +uint64_t *total_frame_count) +{ +uint64_t frame_count; + +if (xfer->duration_seconds >0 ) { + frame_count = xfer->duration_seconds * xfer->frames_per_second; +if (frame_count < *total_frame_count) + *total_frame_count = frame_count; + } + +if (xfer->duration_frames >0 ) { + frame_count = xfer->duration_frames; +if (frame_count < *total_frame_count) + *total_frame_count = frame_count; + } +} +static const char *const allowed_duplication[] = {"/dev/null" ,"/dev/zero" ,
axfer/xfer.h +4 -0
@@ -30,6 +30,8 @@ struct xfer_context {char *sample_format_literal;char *cntr_format_literal;unsigned int verbose; +unsigned int duration_seconds; +unsigned int duration_frames;unsigned int frames_per_second;unsigned int samples_per_frame; bool help:1;
@@ -68,6 +70,8 @@ int xfer_options_parse_args(struct xfer_context *xfer, const struct xfer_data *data, int argc, char *const *argv);int xfer_options_fixup_paths (struct xfer_context *xfer); +void xfer_options_calculate_duration (struct xfer_context *xfer, +uint64_t *total_frame_count);// For internal use in 'xfer' module.
Signature · 1 line
2.19.1
PATCH 21/35 axfer: add an option to finish transmission at XRUN
In reply to Takashi SakamotoIn aplay, '--fatal-errors' option has an effect to give up recovery of PCM substream from XRUN state. This commit adds support for this option.
In original implementation, this option brings program abort. This seems to generate core dump of process VMA. However, typically, XRUN comes from timing mismatch between hardware and application, therefore core dump has less helpful. This commit finishes this program in usual way with this option at XRUN.
--- axfer/xfer-libasound.c | 11 ++++++++++- axfer/xfer-libasound.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-)
axfer/xfer-libasound.c +10 -1
@@ -9,9 +9,16 @@#include "xfer-libasound.h" #include "misc.h" +enum no_short_opts { +// 200 or later belong to non us-ascii character set. +OPT_FATAL_ERRORS =200 , +}; +#define S_OPTS "D:"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, +// For debugging. + {"fatal-errors" ,0 ,0 ,OPT_FATAL_ERRORS }, }; static int xfer_libasound_init(struct xfer_context *xfer,
@@ -39,6 +46,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key,if (key =='D' ) state->node_literal =arg_duplicate_string (optarg, &err); +else if (key ==OPT_FATAL_ERRORS ) + state->finish_at_xrun = true;else err = -ENXIO ;
@@ -305,7 +314,7 @@ static int xfer_libasound_process_frames(struct xfer_context *xfer,if (err <0 ) {if (err == -EAGAIN )return err; -if (err == -EPIPE ) { +if (err == -EPIPE && !state->finish_at_xrun) {// Recover the stream and continue processing // immediately. In this program -EPIPE comes from // libasound implementation instead of file I/O.
axfer/xfer-libasound.h +2 -0
@@ -29,6 +29,8 @@ struct libasound_state {bool verbose;char *node_literal; + + bool finish_at_xrun:1; };// For internal use in 'libasound' module.
Signature · 1 line
2.19.1
PATCH 22/35 axfer: add support for non-blocking operation
In reply to Takashi SakamotoIn alsa-lib PCM API, snd_pcm_read[i|n]() and snd_pcm_write[i|n] can be used with non-blocking mode. This is available when SND_PCM_NONBLOCK is used as 'mode' argument for a call of snd_pcm_open().
This commit adds support this type of operation. To reduce CPU usage, this commit uses 'snd_pcm_wait()' to wait for event notification.
Below lines are examples to execute:
$ axfer transfer -N -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer -N -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/xfer-libasound-irq-rw.c | 102 ++++++++++++++++++++++++++++++++-- axfer/xfer-libasound.c | 16 +++++- axfer/xfer-libasound.h | 1 + 3 files changed, 113 insertions(+), 6 deletions(-)
axfer/xfer-libasound-irq-rw.c +98 -4
@@ -117,6 +117,51 @@ error:return err; } +static int r_process_frames_nonblocking (struct libasound_state *state, +snd_pcm_state_t status, +unsigned int *frame_count, +struct mapper_context *mapper, +struct container_context *cntrs) +{ +snd_pcm_sframes_t avail; +snd_pcm_uframes_t avail_count; +int err =0 ; + +if (status !=SND_PCM_STATE_RUNNING ) { + err =snd_pcm_start (state->handle); +if (err <0 ) + goto error; + } + +// Wait for hardware IRQ when no available space. + err =snd_pcm_wait (state->handle,-1 ); +if (err <0 ) + goto error; + +// Check available space on the buffer. + avail =snd_pcm_avail (state->handle); +if (avail <0 ) { + err = avail; + goto error; + } + avail_count = (snd_pcm_uframes_t )avail; + +if (avail_count ==0 ) { +// Let's go to a next iteration. + err =0 ; + goto error; + } + + err =read_frames (state, frame_count, avail_count, mapper, cntrs); +if (err <0 ) + goto error; + +return 0 ; +error: + *frame_count =0 ; +return err; +} + static int write_frames(struct libasound_state *state, unsigned int *frame_count, unsigned int avail_count, struct mapper_context *mapper,
@@ -231,6 +276,48 @@ error:return err; } +static int w_process_frames_nonblocking (struct libasound_state *state, +snd_pcm_state_t status, +unsigned int *frame_count, +struct mapper_context *mapper, +struct container_context *cntrs) +{ +snd_pcm_sframes_t avail; +unsigned int avail_count; +int err; + +// Wait for hardware IRQ when no left space. + err =snd_pcm_wait (state->handle,-1 ); +if (err <0 ) + goto error; + +// Check available space on the buffer. + avail =snd_pcm_avail (state->handle); +if (avail <0 ) { + err = avail; + goto error; + } + avail_count = (unsigned int )avail; + +if (avail_count ==0 ) { +// Let's go to a next iteration. + err =0 ; + goto error; + } + + err =write_frames (state, frame_count, avail_count, mapper, cntrs); +if (err <0 ) + goto error; + +// NOTE: The substream starts automatically when the accumulated number +// of queued data frame exceeds start_threshold. + +return 0 ; +error: + *frame_count =0 ; +return err; +} +static int irq_rw_pre_process (struct libasound_state *state) {struct rw_closure *closure = state->private_data;
@@ -267,10 +354,17 @@ static int irq_rw_pre_process(struct libasound_state *state)if (err <0 )return err; -if (snd_pcm_stream (state->handle) ==SND_PCM_STREAM_CAPTURE ) - closure->process_frames = r_process_frames_blocking; -else - closure->process_frames = w_process_frames_blocking; +if (snd_pcm_stream (state->handle) ==SND_PCM_STREAM_CAPTURE ) { +if (state->nonblock) + closure->process_frames = r_process_frames_nonblocking; +else + closure->process_frames = r_process_frames_blocking; + }else { +if (state->nonblock) + closure->process_frames = w_process_frames_nonblocking; +else + closure->process_frames = w_process_frames_blocking; + }return 0 ; }
axfer/xfer-libasound.c +14 -2
@@ -14,9 +14,10 @@ enum no_short_opts { OPT_FATAL_ERRORS = 200, }; -#define S_OPTS "D:" +#define S_OPTS "D:N"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, + {"nonblock" ,0 ,0 ,'N' },// For debugging. {"fatal-errors" ,0 ,0 ,OPT_FATAL_ERRORS }, };
@@ -46,6 +47,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key,if (key =='D' ) state->node_literal =arg_duplicate_string (optarg, &err); +else if (key =='N' ) + state->nonblock = true;else if (key ==OPT_FATAL_ERRORS ) state->finish_at_xrun = true;else
@@ -91,10 +94,14 @@ static int set_access_hw_param(struct libasound_state *state)static int open_handle (struct xfer_context *xfer) {struct libasound_state *state = xfer->private_data; +int mode =0 ;int err; +if (state->nonblock) + mode |=SND_PCM_NONBLOCK ; + err =snd_pcm_open (&state->handle, state->node_literal, xfer->direction, -0 ); + mode);if (err <0 ) { logging(state, "Fail to open libasound PCM node for %s: %s\n", snd_pcm_stream_name(xfer->direction),
@@ -378,7 +385,12 @@ static void xfer_libasound_post_process(struct xfer_context *xfer)logging (state,"snd_pcm_drop(): %s\n" ,snd_strerror (err)); }else { +// TODO: this is a bug in kernel land. +if (state->nonblock) +snd_pcm_nonblock (state->handle,0 ); err =snd_pcm_drain (state->handle); +if (state->nonblock) +snd_pcm_nonblock (state->handle,1 );if (err <0 )logging (state,"snd_pcm_drain(): %s\n" ,snd_strerror (err));
axfer/xfer-libasound.h +1 -0
@@ -31,6 +31,7 @@ struct libasound_state {char *node_literal; bool finish_at_xrun:1; + bool nonblock:1; };// For internal use in 'libasound' module.
Signature · 1 line
2.19.1
PATCH 23/35 axfer: add support for MMAP PCM operation
In reply to Takashi SakamotoIn alsa-lib PCM API, data frames can be handled in mapped page frame, instead of calling any system calls.
This commit support for this type of operation. To reduce CPU usage, this commit uses 'snd_pcm_wait()' to wait for event notification.
Below lines are examples to execute:
$ axfer transfer -M -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer -M -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 +- axfer/xfer-libasound-irq-mmap.c | 268 ++++++++++++++++++++++++++++++++ axfer/xfer-libasound.c | 27 +++- axfer/xfer-libasound.h | 4 + 4 files changed, 298 insertions(+), 4 deletions(-) create mode 100644 axfer/xfer-libasound-irq-mmap.c
axfer/Makefile.am +2 -1
@@ -46,4 +46,5 @@ axfer_SOURCES = \ frame-cache.h \ frame-cache.c \ xfer-libasound-irq-rw.c \ - subcmd-transfer.c + subcmd-transfer.c \ + xfer-libasound-irq-mmap.c
axfer/xfer-libasound-irq-mmap.c new file +268 -0
268 lines not on this page · raw message
axfer/xfer-libasound.c +24 -3
@@ -14,10 +14,11 @@ enum no_short_opts { OPT_FATAL_ERRORS = 200, }; -#define S_OPTS "D:N" +#define S_OPTS "D:NM"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, {"nonblock" ,0 ,0 ,'N' }, + {"mmap" ,0 ,0 ,'M' },// For debugging. {"fatal-errors" ,0 ,0 ,OPT_FATAL_ERRORS }, };
@@ -49,6 +50,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->node_literal =arg_duplicate_string (optarg, &err); else if (key == 'N') state->nonblock = true; + else if (key == 'M') + state->mmap = true; else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; else
@@ -70,6 +73,13 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer)return -ENOMEM ; } +if (state->mmap && state->nonblock) { +fprintf (stderr, +"An option for mmap operation should not be used with " +"nonblocking option.\n" ); +return -EINVAL ; + } +return err; }
@@ -82,8 +92,13 @@ static int set_access_hw_param(struct libasound_state *state)if (err <0 )return err;snd_pcm_access_mask_none (mask); -snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_RW_INTERLEAVED ); -snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_RW_NONINTERLEAVED ); +if (state->mmap) { +snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_MMAP_INTERLEAVED ); +snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_MMAP_NONINTERLEAVED ); + }else { +snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_RW_INTERLEAVED ); +snd_pcm_access_mask_set (mask,SND_PCM_ACCESS_RW_NONINTERLEAVED ); + } err =snd_pcm_hw_params_set_access_mask (state->handle, state->hw_params, mask);snd_pcm_access_mask_free (mask);
@@ -279,6 +294,12 @@ static int xfer_libasound_pre_process(struct xfer_context *xfer,if (*access ==SND_PCM_ACCESS_RW_INTERLEAVED || *access ==SND_PCM_ACCESS_RW_NONINTERLEAVED ) { state->ops = &xfer_libasound_irq_rw_ops; + }else if (*access ==SND_PCM_ACCESS_MMAP_INTERLEAVED || + *access ==SND_PCM_ACCESS_MMAP_NONINTERLEAVED ) { +if (snd_pcm_stream (state->handle) ==SND_PCM_STREAM_CAPTURE ) + state->ops = &xfer_libasound_irq_mmap_r_ops; +else + state->ops = &xfer_libasound_irq_mmap_w_ops; }else {return -ENXIO ; }
axfer/xfer-libasound.h +4 -0
@@ -32,6 +32,7 @@ struct libasound_state { bool finish_at_xrun:1; bool nonblock:1; + bool mmap:1; };// For internal use in 'libasound' module.
@@ -48,4 +49,7 @@ struct xfer_libasound_ops {extern const struct xfer_libasound_ops xfer_libasound_irq_rw_ops; +extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_r_ops; +extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_w_ops; +#endif
Signature · 1 line
2.19.1
PATCH 24/35 axfer: add an option to suppress event waiting
In reply to Takashi SakamotoIn aplay, '--test-nowait' is used to suppress calls of snd_pcm_wait() when I/O operations return -EAGAIN or process truncated number of data frames. This seems to be for debugging purpose. In this program, this option is equivalent to suppress event waiting.
This commit adds support for this option.
--- axfer/xfer-libasound-irq-mmap.c | 10 ++++++---- axfer/xfer-libasound-irq-rw.c | 20 ++++++++++++-------- axfer/xfer-libasound.c | 16 ++++++++++++++++ axfer/xfer-libasound.h | 3 +++ 4 files changed, 37 insertions(+), 12 deletions(-)
axfer/xfer-libasound-irq-mmap.c +6 -4
@@ -81,10 +81,12 @@ static int irq_mmap_process_frames(struct libasound_state *state,snd_pcm_sframes_t consumed_count;int err; -// Wait for hardware IRQ when no avail space in buffer. - err =snd_pcm_wait (state->handle,-1 ); -if (err <0 ) -return err; +if (state->use_waiter) { +// Wait for hardware IRQ when no avail space in buffer. + err =snd_pcm_wait (state->handle,-1 ); +if (err <0 ) +return err; + }// Sync cache in user space to data in kernel space to calculate avail // frames according to the latest positions on PCM buffer.
axfer/xfer-libasound-irq-rw.c +12 -8
@@ -133,10 +133,12 @@ static int r_process_frames_nonblocking(struct libasound_state *state, goto error; } -// Wait for hardware IRQ when no available space. - err =snd_pcm_wait (state->handle,-1 ); -if (err <0 ) - goto error; +if (state->use_waiter) { +// Wait for hardware IRQ when no available space. + err =snd_pcm_wait (state->handle,-1 ); +if (err <0 ) + goto error; + }// Check available space on the buffer. avail =snd_pcm_avail (state->handle);
@@ -286,10 +288,12 @@ static int w_process_frames_nonblocking(struct libasound_state *state,unsigned int avail_count;int err; -// Wait for hardware IRQ when no left space. - err =snd_pcm_wait (state->handle,-1 ); -if (err <0 ) - goto error; +if (state->use_waiter) { +// Wait for hardware IRQ when no left space. + err =snd_pcm_wait (state->handle,-1 ); +if (err <0 ) + goto error; + }// Check available space on the buffer. avail =snd_pcm_avail (state->handle);
axfer/xfer-libasound.c +16 -0
@@ -12,6 +12,7 @@enum no_short_opts {// 200 or later belong to non us-ascii character set. OPT_FATAL_ERRORS =200 , +OPT_TEST_NOWAIT , };#define S_OPTS "D:NM"
@@ -21,6 +22,7 @@ static const struct option l_opts[] = { {"mmap", 0, 0, 'M'},// For debugging. {"fatal-errors", 0, 0, OPT_FATAL_ERRORS}, + {"test-nowait", 0, 0, OPT_TEST_NOWAIT}, }; static int xfer_libasound_init(struct xfer_context *xfer,
@@ -54,6 +56,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->mmap = true; else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; + else if (key == OPT_TEST_NOWAIT) + state->test_nowait = true; else err = -ENXIO ;
@@ -80,6 +84,15 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer)return -EINVAL ; } +if (state->test_nowait) { +if (!state->nonblock && !state->mmap) { +fprintf (stderr, +"An option for nowait test should be used with " +"nonblock or mmap options.\n" ); +return -EINVAL ; + } + } +return err; }
@@ -124,6 +137,9 @@ static int open_handle(struct xfer_context *xfer)return err; } +if ((state->nonblock || state->mmap) && !state->test_nowait) + state->use_waiter = true; + err =snd_pcm_hw_params_any (state->handle, state->hw_params);if (err <0 )return err;
axfer/xfer-libasound.h +3 -0
@@ -33,6 +33,9 @@ struct libasound_state { bool finish_at_xrun:1; bool nonblock:1; bool mmap:1; + bool test_nowait:1; + + bool use_waiter:1; };// For internal use in 'libasound' module.
Signature · 1 line
2.19.1
PATCH 25/35 axfer: add options for buffer arrangement
In reply to Takashi SakamotoIn ALSA PCM interface, two parameters are used for size of intermediate buffer for data frames; period size and buffer size. Actual effects of these sizes differs depending on hardware, but basically the size of period is used for intervals of hardware interrupts and the size of buffer is used to maintain the intermediate buffer as ring buffer. These parameters can be configured as a part of hardware parameters by data frame unit or micro second. PCM API in alsa-lib also includes helper functions to configure them by the two units.
This commit adds support for options to the parameters by both units. When no options are given, default values are applied according to current aplay; available maximum size of buffer up to 500msec, a quarter of the size of buffer for period size. However, these calculation should be reconsidered somehow.
--- axfer/xfer-libasound.c | 122 +++++++++++++++++++++++++++++++++++++++-- axfer/xfer-libasound.h | 5 ++ axfer/xfer-options.c | 2 + 3 files changed, 125 insertions(+), 4 deletions(-)
axfer/xfer-libasound.c +118 -4
@@ -11,15 +11,21 @@enum no_short_opts {// 200 or later belong to non us-ascii character set. -OPT_FATAL_ERRORS =200 , +OPT_PERIOD_SIZE =200 , +OPT_BUFFER_SIZE , +OPT_FATAL_ERRORS ,OPT_TEST_NOWAIT , }; -#define S_OPTS "D:NM" +#define S_OPTS "D:NMF:B:"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, {"nonblock" ,0 ,0 ,'N' }, {"mmap" ,0 ,0 ,'M' }, + {"period-time" ,1 ,0 ,'F' }, + {"buffer-time" ,1 ,0 ,'B' }, + {"period-size" ,1 ,0 ,OPT_PERIOD_SIZE }, + {"buffer-size" ,1 ,0 ,OPT_BUFFER_SIZE },// For debugging. {"fatal-errors" ,0 ,0 ,OPT_FATAL_ERRORS }, {"test-nowait" ,0 ,0 ,OPT_TEST_NOWAIT },
@@ -54,6 +60,14 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->nonblock = true; else if (key == 'M') state->mmap = true; + else if (key == 'F') + state->msec_per_period =arg_parse_decimal_num (optarg, &err); + else if (key == 'B') + state->msec_per_buffer =arg_parse_decimal_num (optarg, &err); + else if (key == OPT_PERIOD_SIZE) + state->frames_per_period = arg_parse_decimal_num(optarg, &err); + else if (key == OPT_BUFFER_SIZE) + state->frames_per_buffer = arg_parse_decimal_num(optarg, &err); else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; else if (key == OPT_TEST_NOWAIT)
@@ -93,6 +107,20 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer) } } +if (state->msec_per_period >0 && state->msec_per_buffer >0 ) { +if (state->msec_per_period > state->msec_per_buffer) { + state->msec_per_period = state->msec_per_buffer; + state->msec_per_buffer =0 ; + } + } + +if (state->frames_per_period >0 && state->frames_per_buffer >0 ) { +if (state->frames_per_period > state->frames_per_buffer) { + state->frames_per_period = state->frames_per_buffer; + state->frames_per_buffer =0 ; + } + } +return err; }
@@ -161,7 +189,11 @@ static int open_handle(struct xfer_context *xfer)static int configure_hw_params (struct libasound_state *state,snd_pcm_format_t format,unsigned int samples_per_frame, -unsigned int frames_per_second) +unsigned int frames_per_second, +unsigned int msec_per_period, +unsigned int msec_per_buffer, +snd_pcm_uframes_t frames_per_period, +snd_pcm_uframes_t frames_per_buffer) {int err;
@@ -232,6 +264,84 @@ static int configure_hw_params(struct libasound_state *state,return err; } +// Keep one of 'frames_per_buffer' and 'msec_per_buffer'. +if (frames_per_buffer ==0 ) { +if (msec_per_buffer ==0 ) { + err =snd_pcm_hw_params_get_buffer_time_max ( + state->hw_params, &msec_per_buffer,NULL ); +if (err <0 ) { +logging (state, +"The maximum msec per buffer is not " +"available.\n" ); +return err; + } +if (msec_per_buffer >500000 ) + msec_per_buffer =500000 ; + } + }else if (msec_per_buffer >0 ) { +uint64_t msec; + + msec =1000000 * frames_per_buffer / frames_per_second; +if (msec < msec_per_buffer) + msec_per_buffer =0 ; + } + +// Keep one of 'frames_per_period' and 'msec_per_period'. +if (frames_per_period ==0 ) { +if (msec_per_period ==0 ) { +if (msec_per_buffer >0 ) + msec_per_period = msec_per_buffer /4 ; +else + frames_per_period = frames_per_buffer /4 ; + } + }else if (msec_per_period >0 ) { +uint64_t msec; + + msec =1000000 * frames_per_period / frames_per_second; +if (msec < msec_per_period) + msec_per_period =0 ; + } + +if (msec_per_period) { + err =snd_pcm_hw_params_set_period_time_near (state->handle, + state->hw_params, &msec_per_period,NULL ); +if (err <0 ) { +logging (state, +"Fail to configure period time: %u msec\n" , + msec_per_period); +return err; + } + }else { + err =snd_pcm_hw_params_set_period_size_near (state->handle, + state->hw_params, &frames_per_period,NULL ); +if (err <0 ) { +logging (state, +"Fail to configure period size: %lu frames\n" , + frames_per_period); +return err; + } + } + +if (msec_per_buffer) { + err =snd_pcm_hw_params_set_buffer_time_near (state->handle, + state->hw_params, &msec_per_buffer,NULL ); +if (err <0 ) { +logging (state, +"Fail to configure buffer time: %u msec\n" , + msec_per_buffer); +return err; + } + }else { + err =snd_pcm_hw_params_set_buffer_size_near (state->handle, + state->hw_params, &frames_per_buffer); +if (err <0 ) { +logging (state, +"Fail to configure buffer size: %lu frames\n" , + frames_per_buffer); +return err; + } + } +return snd_pcm_hw_params (state->handle, state->hw_params); }
@@ -287,7 +397,11 @@ static int xfer_libasound_pre_process(struct xfer_context *xfer,return -ENXIO ; err =configure_hw_params (state, *format, *samples_per_frame, - *frames_per_second); + *frames_per_second, + state->msec_per_period, + state->msec_per_buffer, + state->frames_per_period, + state->frames_per_buffer);if (err <0 ) {logging (state,"Current hardware parameters:\n" );snd_pcm_hw_params_dump (state->hw_params, state->log);
axfer/xfer-libasound.h +5 -0
@@ -30,6 +30,11 @@ struct libasound_state {char *node_literal; +unsigned int msec_per_period; +unsigned int msec_per_buffer; +unsigned int frames_per_period; +unsigned int frames_per_buffer; + bool finish_at_xrun:1; bool nonblock:1; bool mmap:1;
axfer/xfer-options.c +2 -0
@@ -17,6 +17,8 @@ enum no_short_opts {// 128 or later belong to non us-ascii character set. OPT_XFER_TYPE =128 ,OPT_DUMP_HW_PARAMS , +OPT_PERIOD_SIZE , +OPT_BUFFER_SIZE ,// Obsoleted. OPT_MAX_FILE_TIME, };
Signature · 1 line
2.19.1
PATCH 26/35 axfer: add options for software parameters of PCM substream
In reply to Takashi SakamotoIn ALSA PCM interface, some parameters are used to configure runtime of PCM substream independently of actual hardware. These parameters are mainly used to decide the detailed timing to start/stop PCM substream and release I/O blocking state of application. These parameters are represented and delivered by a structure.
In alsa-lib PCM API, the structure is hidden from userspace applications. The applications can set/get actual parameters by helper functions.
In aplay, three of the parameters are configurable. This commit adds support for them. When no options are given, default values are used.
--- axfer/xfer-libasound.c | 86 ++++++++++++++++++++++++++++++++++++++++-- axfer/xfer-libasound.h | 4 ++ 2 files changed, 87 insertions(+), 3 deletions(-)
axfer/xfer-libasound.c +83 -3
@@ -17,7 +17,7 @@ enum no_short_opts { OPT_TEST_NOWAIT, }; -#define S_OPTS "D:NMF:B:" +#define S_OPTS "D:NMF:B:A:R:T:"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, {"nonblock" ,0 ,0 ,'N' },
@@ -26,6 +26,9 @@ static const struct option l_opts[] = { {"buffer-time", 1, 0, 'B'}, {"period-size", 1, 0, OPT_PERIOD_SIZE}, {"buffer-size", 1, 0, OPT_BUFFER_SIZE}, + {"avail-min", 1, 0, 'A'}, + {"start-delay", 1, 0, 'R'}, + {"stop-delay", 1, 0, 'T'},// For debugging. {"fatal-errors", 0, 0, OPT_FATAL_ERRORS}, {"test-nowait", 0, 0, OPT_TEST_NOWAIT},
@@ -68,6 +71,12 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->frames_per_period =arg_parse_decimal_num (optarg, &err); else if (key == OPT_BUFFER_SIZE) state->frames_per_buffer = arg_parse_decimal_num(optarg, &err); + else if (key == 'A') + state->msec_for_avail_min =arg_parse_decimal_num (optarg, &err); + else if (key == 'R') + state->msec_for_start_threshold =arg_parse_decimal_num (optarg, &err); + else if (key == 'T') + state->msec_for_stop_threshold =arg_parse_decimal_num (optarg, &err); else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; else if (key == OPT_TEST_NOWAIT)
@@ -377,8 +386,76 @@ static int retrieve_actual_hw_params(snd_pcm_hw_params_t *hw_params,static int configure_sw_params (struct libasound_state *state,unsigned int frames_per_second, -unsigned int frames_per_buffer) +unsigned int frames_per_buffer, +unsigned int msec_for_avail_min, +unsigned int msec_for_start_threshold, +unsigned int msec_for_stop_threshold) { +snd_pcm_uframes_t frame_count; +int err; + +if (msec_for_avail_min >0 ) { + frame_count = msec_for_avail_min * frames_per_second /1000000 ; +if (frame_count ==0 || frame_count > frames_per_buffer) { +logging (state, +"The msec for 'avail_min' is too %s: %u " +"msec (%lu frames at %u).\n" , + frame_count ==0 ?"small" :"large" , + msec_for_avail_min, frame_count, + frames_per_second); +return -EINVAL ; + } + err =snd_pcm_sw_params_set_avail_min (state->handle, + state->sw_params, frame_count); +if (err <0 ) { +logging (state, +"Fail to configure 'avail-min'.\n" ); +return -EINVAL ; + } + } + +if (msec_for_start_threshold >0 ) { + frame_count = msec_for_start_threshold * frames_per_second / +1000000 ; +if (frame_count ==0 || frame_count > frames_per_buffer) { +logging (state, +"The msec for 'start-delay' is too %s: %u " +"msec (%lu frames at %u).\n" , + frame_count ==0 ?"small" :"large" , + msec_for_start_threshold, frame_count, + frames_per_second); +return -EINVAL ; + } + err =snd_pcm_sw_params_set_start_threshold (state->handle, + state->sw_params, frame_count); +if (err <0 ) { +logging (state, +"Fail to configure 'start-delay'.\n" ); +return -EINVAL ; + } + } + +if (msec_for_stop_threshold >0 ) { + frame_count = msec_for_stop_threshold * frames_per_second / +1000000 ; +if (frame_count ==0 || frame_count > frames_per_buffer) { +logging (state, +"The msec for 'stop-delay' is too %s: %u " +"msec (%lu frames at %u).\n" , + frame_count ==0 ?"small" :"large" , + msec_for_stop_threshold, frame_count, + frames_per_second); +return -EINVAL ; + } + err =snd_pcm_sw_params_set_stop_threshold (state->handle, + state->sw_params, frame_count); +if (err <0 ) { +logging (state, +"Fail to configure 'stop-delay'.\n" ); +return -EINVAL ; + } + } +return snd_pcm_sw_params (state->handle, state->sw_params); }
@@ -444,7 +521,10 @@ static int xfer_libasound_pre_process(struct xfer_context *xfer,return err; err =configure_sw_params (state, *frames_per_second, - *frames_per_buffer); + *frames_per_buffer, + state->msec_for_avail_min, + state->msec_for_start_threshold, + state->msec_for_stop_threshold);if (err <0 ) {logging (state,"Current software parameters:\n" );snd_pcm_sw_params_dump (state->sw_params, state->log);
axfer/xfer-libasound.h +4 -0
@@ -35,6 +35,10 @@ struct libasound_state {unsigned int frames_per_period;unsigned int frames_per_buffer; +unsigned int msec_for_avail_min; +unsigned int msec_for_start_threshold; +unsigned int msec_for_stop_threshold; + bool finish_at_xrun:1; bool nonblock:1; bool mmap:1;
Signature · 1 line
2.19.1
PATCH 27/35 axfer: add options for plugins in alsa-lib
In reply to Takashi SakamotoAs of 2017, two userspace library implementations are known; alsa-lib and tinyalsa. The latter is simple I/O library to use ALSA PCM interface. On the other hand, alsa-lib is more complicated than it. This is because it's designed to add features to transmission of data frames; e.g. sample resampling. To achieve this, alsa-lib has its configuration space and plugin system.
In aplay, some options are implemented as a flag for the plugins in alsa-lib. The flag is given to snd_pcm_open(). This commit adds support for the flags.
--- axfer/xfer-libasound.c | 25 +++++++++++++++++++++++++ axfer/xfer-libasound.h | 4 ++++ 2 files changed, 29 insertions(+)
axfer/xfer-libasound.c +25 -0
@@ -13,6 +13,10 @@ enum no_short_opts {// 200 or later belong to non us-ascii character set. OPT_PERIOD_SIZE =200 ,OPT_BUFFER_SIZE , +OPT_DISABLE_RESAMPLE , +OPT_DISABLE_CHANNELS , +OPT_DISABLE_FORMAT , +OPT_DISABLE_SOFTVOL ,OPT_FATAL_ERRORS , OPT_TEST_NOWAIT, };
@@ -29,6 +33,11 @@ static const struct option l_opts[] = { {"avail-min", 1, 0, 'A'}, {"start-delay", 1, 0, 'R'}, {"stop-delay", 1, 0, 'T'}, +// For plugins in alsa-lib. + {"disable-resample", 0, 0, OPT_DISABLE_RESAMPLE}, + {"disable-channels", 0, 0, OPT_DISABLE_CHANNELS}, + {"disable-format", 0, 0, OPT_DISABLE_FORMAT}, + {"disable-softvol", 0, 0, OPT_DISABLE_SOFTVOL},// For debugging. {"fatal-errors", 0, 0, OPT_FATAL_ERRORS}, {"test-nowait", 0, 0, OPT_TEST_NOWAIT},
@@ -77,6 +86,14 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->msec_for_start_threshold =arg_parse_decimal_num (optarg, &err); else if (key == 'T') state->msec_for_stop_threshold =arg_parse_decimal_num (optarg, &err); + else if (key == OPT_DISABLE_RESAMPLE) + state->no_auto_resample = true; + else if (key == OPT_DISABLE_CHANNELS) + state->no_auto_channels = true; + else if (key == OPT_DISABLE_FORMAT) + state->no_auto_format = true; + else if (key == OPT_DISABLE_SOFTVOL) + state->no_softvol = true; else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; else if (key == OPT_TEST_NOWAIT)
@@ -164,6 +181,14 @@ static int open_handle(struct xfer_context *xfer)if (state->nonblock) mode |=SND_PCM_NONBLOCK ; +if (state->no_auto_resample) + mode |=SND_PCM_NO_AUTO_RESAMPLE ; +if (state->no_auto_channels) + mode |=SND_PCM_NO_AUTO_CHANNELS ; +if (state->no_auto_format) + mode |=SND_PCM_NO_AUTO_FORMAT ; +if (state->no_softvol) + mode |=SND_PCM_NO_SOFTVOL ; err =snd_pcm_open (&state->handle, state->node_literal, xfer->direction, mode);
axfer/xfer-libasound.h +4 -0
@@ -43,6 +43,10 @@ struct libasound_state { bool nonblock:1; bool mmap:1; bool test_nowait:1; + bool no_auto_resample:1; + bool no_auto_channels:1; + bool no_auto_format:1; + bool no_softvol:1; bool use_waiter:1; };
Signature · 1 line
2.19.1
PATCH 28/35 axfer: add a common interface of waiter for I/O event notification
In reply to Takashi SakamotoThere're several types of system calls for multiplexed I/O. They're used to receive notifications of I/O events. Typically, userspace applications call them against file descriptor to yield CPU. When I/O is enabled on any of the descriptors, a task of the application is rescheduled, then the application execute I/O calls.
This commit adds a common interface for this type of system calls, named as 'waiter'. This is expected to be used with non-blocking file operation and operations on mapped page frame.
--- axfer/Makefile.am | 5 +- axfer/waiter.c | 99 +++++++++++++++++++++++++++++++++ axfer/waiter.h | 54 ++++++++++++++++++ axfer/xfer-libasound-irq-mmap.c | 14 ++++- axfer/xfer-libasound-irq-rw.c | 26 ++++++++- axfer/xfer-libasound.c | 76 +++++++++++++++++++++++++ axfer/xfer-libasound.h | 7 +++ 7 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 axfer/waiter.c create mode 100644 axfer/waiter.h
axfer/Makefile.am +4 -1
@@ -22,6 +22,7 @@ noinst_HEADERS = \ xfer.h \ xfer-libasound.h \ frame-cache.h + waiter.h axfer_SOURCES = \ misc.h \
@@ -47,4 +48,6 @@ axfer_SOURCES = \ frame-cache.c \ xfer-libasound-irq-rw.c \ subcmd-transfer.c \ - xfer-libasound-irq-mmap.c + xfer-libasound-irq-mmap.c \ + waiter.h \ + waiter.c
axfer/waiter.c new file +99 -0
99 lines not on this page · raw message
axfer/waiter.h new file +54 -0
54 lines not on this page · raw message
axfer/xfer-libasound-irq-mmap.c +13 -1
@@ -82,10 +82,22 @@ static int irq_mmap_process_frames(struct libasound_state *state,int err;if (state->use_waiter) { +unsigned short revents; +// Wait for hardware IRQ when no avail space in buffer. - err =snd_pcm_wait (state->handle,-1 ); + err =xfer_libasound_wait_event (state,-1 , &revents);if (err <0 )return err; +if (revents &POLLERR ) { +// TODO: error reporting? +return -EIO ; + } +if (!(revents & (POLLIN |POLLOUT ))) +return -EAGAIN ; + +// When rescheduled, current position of data transmission was +// queried to actual hardware by a handler of IRQ. No need to +// perform it; e.g. ioctl(2) with SNDRV_PCM_IOCTL_HWSYNC. }// Sync cache in user space to data in kernel space to calculate avail
axfer/xfer-libasound-irq-rw.c +24 -2
@@ -134,10 +134,21 @@ static int r_process_frames_nonblocking(struct libasound_state *state, }if (state->use_waiter) { +unsigned short revents; +// Wait for hardware IRQ when no available space. - err =snd_pcm_wait (state->handle,-1 ); + err =xfer_libasound_wait_event (state,-1 , &revents);if (err <0 ) goto error; +if (revents &POLLERR ) { +// TODO: error reporting. + err = -EIO ; + goto error; + } +if (!(revents &POLLIN )) { + err = -EAGAIN ; + goto error; + } }// Check available space on the buffer.
@@ -289,10 +300,21 @@ static int w_process_frames_nonblocking(struct libasound_state *state,int err;if (state->use_waiter) { +unsigned short revents; +// Wait for hardware IRQ when no left space. - err =snd_pcm_wait (state->handle,-1 ); + err =xfer_libasound_wait_event (state,-1 , &revents);if (err <0 ) goto error; +if (revents &POLLERR ) { +// TODO: error reporting. + err = -EIO ; + goto error; + } +if (!(revents &POLLOUT )) { + err = -EAGAIN ; + goto error; + } }// Check available space on the buffer.
axfer/xfer-libasound.c +76 -0
94 lines not on this page · raw message
axfer/xfer-libasound.h +7 -0
@@ -10,6 +10,7 @@#define __ALSA_UTILS_AXFER_XFER_LIBASOUND__H_#include "xfer.h" +#include "waiter.h" #define logging (state, ...) \ snd_output_printf(state->log, __VA_ARGS__)
@@ -49,6 +50,9 @@ struct libasound_state { bool no_softvol:1; bool use_waiter:1; + +enum waiter_type waiter_type; +struct waiter_context *waiter; };// For internal use in 'libasound' module.
@@ -63,6 +67,9 @@ struct xfer_libasound_ops {unsigned int private_size; }; +int xfer_libasound_wait_event (struct libasound_state *state,int timeout_msec, +unsigned short *revents); +extern const struct xfer_libasound_ops xfer_libasound_irq_rw_ops;extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_r_ops;
Signature · 1 line
2.19.1
PATCH 29/35 axfer: add an option for waiter type
In reply to Takashi SakamotoThis commit is an integration to add an option for users to choose waiter type. Users give the type to value to '--waiter-type' ('-w') option to choose it. Currently, 'snd_pcm_wait()' is just supported as a default. This alsa-lib API is implemented with a call of poll(2).
--- axfer/xfer-libasound.c | 26 +++++++++++++++++++++++++- axfer/xfer-libasound.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-)
axfer/xfer-libasound.c +25 -1
@@ -13,6 +13,7 @@ enum no_short_opts {// 200 or later belong to non us-ascii character set. OPT_PERIOD_SIZE =200 ,OPT_BUFFER_SIZE , +OPT_WAITER_TYPE ,OPT_DISABLE_RESAMPLE ,OPT_DISABLE_CHANNELS , OPT_DISABLE_FORMAT,
@@ -33,6 +34,7 @@ static const struct option l_opts[] = { {"avail-min", 1, 0, 'A'}, {"start-delay", 1, 0, 'R'}, {"stop-delay", 1, 0, 'T'}, + {"waiter-type", 1, 0, OPT_WAITER_TYPE},// For plugins in alsa-lib. {"disable-resample", 0, 0, OPT_DISABLE_RESAMPLE}, {"disable-channels", 0, 0, OPT_DISABLE_CHANNELS},
@@ -86,6 +88,8 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->msec_for_start_threshold =arg_parse_decimal_num (optarg, &err); else if (key == 'T') state->msec_for_stop_threshold =arg_parse_decimal_num (optarg, &err); + else if (key == OPT_WAITER_TYPE) + state->waiter_type_literal = arg_duplicate_string(optarg, &err); else if (key == OPT_DISABLE_RESAMPLE) state->no_auto_resample = true; else if (key == OPT_DISABLE_CHANNELS)
@@ -147,6 +151,25 @@ int xfer_libasound_validate_opts(struct xfer_context *xfer) } } +if (state->waiter_type_literal !=NULL ) { +if (state->test_nowait) { +fprintf (stderr, +"An option for waiter type should not be " +"used with nowait test option.\n" ); +return -EINVAL ; + } +if (!state->nonblock && !state->mmap) { +fprintf (stderr, +"An option for waiter type should be used " +"with nonblock or mmap options.\n" ); +return -EINVAL ; + } + state->waiter_type = +waiter_type_from_label (state->waiter_type_literal); + }else { + state->waiter_type =WAITER_TYPE_DEFAULT ; + } +return err; }
@@ -201,7 +224,6 @@ static int open_handle(struct xfer_context *xfer)if ((state->nonblock || state->mmap) && !state->test_nowait) state->use_waiter = true; - state->waiter_type =WAITER_TYPE_DEFAULT ; err =snd_pcm_hw_params_any (state->handle, state->hw_params);if (err <0 )
@@ -751,7 +773,9 @@ static void xfer_libasound_destroy(struct xfer_context *xfer)struct libasound_state *state = xfer->private_data;free (state->node_literal); +free (state->waiter_type_literal); state->node_literal =NULL ; + state->waiter_type_literal =NULL ;if (state->hw_params)snd_pcm_hw_params_free (state->hw_params);
axfer/xfer-libasound.h +1 -0
@@ -30,6 +30,7 @@ struct libasound_state {bool verbose;char *node_literal; +char *waiter_type_literal;unsigned int msec_per_period;unsigned int msec_per_buffer;
Signature · 1 line
2.19.1
PATCH 30/35 axfer: add an implementation of waiter for poll(2)
In reply to Takashi SakamotoThis commit adds support of waiter for poll(2) system call.
Below lines are examples to use this option:
$ axfer transfer --waiter-type=poll -M -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer --waiter-type=poll -M -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 ++- axfer/waiter-poll.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ axfer/waiter.c | 3 ++- axfer/waiter.h | 3 +++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 axfer/waiter-poll.c
axfer/Makefile.am +2 -1
@@ -50,4 +50,5 @@ axfer_SOURCES = \ subcmd-transfer.c \ xfer-libasound-irq-mmap.c \ waiter.h \ - waiter.c + waiter.c \ + waiter-poll.c
axfer/waiter-poll.c new file +45 -0
45 lines not on this page · raw message
axfer/waiter.c +2 -1
@@ -16,6 +16,7 @@static const char *const waiter_type_labels[] = { [WAITER_TYPE_DEFAULT ] ="default" , + [WAITER_TYPE_POLL ] ="poll" , };enum waiter_type waiter_type_from_label (const char *label)
@@ -42,7 +43,7 @@ int waiter_context_init(struct waiter_context *waiter,enum waiter_type type;const struct waiter_data *waiter; } entries[] = { - {WAITER_TYPE_COUNT, NULL}, + {WAITER_TYPE_POLL, &waiter_poll}, }; int i;
axfer/waiter.h +3 -0
@@ -13,6 +13,7 @@enum waiter_type {WAITER_TYPE_DEFAULT =0 , +WAITER_TYPE_POLL ,WAITER_TYPE_COUNT , };
@@ -51,4 +52,6 @@ struct waiter_data { unsigned int private_size; }; +extern const struct waiter_data waiter_poll; +#endif
Signature · 1 line
2.19.1
PATCH 31/35 axfer: add an implementation of waiter for select(2)
In reply to Takashi SakamotoThis commit adds support of waiter for select(2) system call.
Below lines are examples to use this option:
$ axfer transfer --waiter-type=select -M -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer --waiter-type=select -M -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 +- axfer/waiter-select.c | 100 ++++++++++++++++++++++++++++++++++++++++++ axfer/waiter.c | 2 + axfer/waiter.h | 2 + 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 axfer/waiter-select.c
axfer/Makefile.am +2 -1
@@ -51,4 +51,5 @@ axfer_SOURCES = \ xfer-libasound-irq-mmap.c \ waiter.h \ waiter.c \ - waiter-poll.c + waiter-poll.c \ + waiter-select.c
axfer/waiter-select.c new file +100 -0
100 lines not on this page · raw message
axfer/waiter.c +2 -0
@@ -17,6 +17,7 @@static const char *const waiter_type_labels[] = { [WAITER_TYPE_DEFAULT ] ="default" , [WAITER_TYPE_POLL ] ="poll" , + [WAITER_TYPE_SELECT ] ="select" , };enum waiter_type waiter_type_from_label (const char *label)
@@ -44,6 +45,7 @@ int waiter_context_init(struct waiter_context *waiter,const struct waiter_data *waiter; } entries[] = { {WAITER_TYPE_POLL, &waiter_poll}, + {WAITER_TYPE_SELECT, &waiter_select}, }; int i;
axfer/waiter.h +2 -0
@@ -14,6 +14,7 @@enum waiter_type {WAITER_TYPE_DEFAULT =0 ,WAITER_TYPE_POLL , +WAITER_TYPE_SELECT ,WAITER_TYPE_COUNT , };
@@ -53,5 +54,6 @@ struct waiter_data { };extern const struct waiter_data waiter_poll; +extern const struct waiter_data waiter_select;#endif
Signature · 1 line
2.19.1
PATCH 32/35 axfer: add an implementation of waiter for epoll(7)
In reply to Takashi SakamotoThis commit adds support of waiter for Linux specific epoll(7) system call. For portability to the other Unix-like systems such as xBSD, modification of Makefile.am may be required for conditional build, but this commit includes no changes for it.
Below lines are examples to use this option:
$ axfer transfer --waiter-type=epoll -M -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer --waiter-type=epoll -M -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 +- axfer/waiter-epoll.c | 107 +++++++++++++++++++++++++++++++++++++++++++ axfer/waiter.c | 2 + axfer/waiter.h | 2 + 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 axfer/waiter-epoll.c
axfer/Makefile.am +2 -1
@@ -52,4 +52,5 @@ axfer_SOURCES = \ waiter.h \ waiter.c \ waiter-poll.c \ - waiter-select.c + waiter-select.c \ + waiter-epoll.c
axfer/waiter-epoll.c new file +107 -0
107 lines not on this page · raw message
axfer/waiter.c +2 -0
@@ -18,6 +18,7 @@ static const char *const waiter_type_labels[] = { [WAITER_TYPE_DEFAULT] = "default", [WAITER_TYPE_POLL] = "poll", [WAITER_TYPE_SELECT] = "select", + [WAITER_TYPE_EPOLL] = "epoll", };enum waiter_type waiter_type_from_label (const char *label)
@@ -46,6 +47,7 @@ int waiter_context_init(struct waiter_context *waiter, } entries[] = { {WAITER_TYPE_POLL, &waiter_poll}, {WAITER_TYPE_SELECT, &waiter_select}, + {WAITER_TYPE_EPOLL, &waiter_epoll}, }; int i;
axfer/waiter.h +2 -0
@@ -15,6 +15,7 @@ enum waiter_type {WAITER_TYPE_DEFAULT =0 ,WAITER_TYPE_POLL ,WAITER_TYPE_SELECT , +WAITER_TYPE_EPOLL , WAITER_TYPE_COUNT, };
@@ -55,5 +56,6 @@ struct waiter_data {extern const struct waiter_data waiter_poll;extern const struct waiter_data waiter_select; +extern const struct waiter_data waiter_epoll;#endif
Signature · 1 line
2.19.1
PATCH 33/35 axfer: add support for timer-based scheduling model with MMAP operation
In reply to Takashi SakamotoIn 2010, ALSA PCM interface got an flag of hardware parameters to suppress periodical interrupts, according to a request from PulseAudio developer.
In typical PCM operation for usual hardware, PCM drivers configure the hardware to generate the periodical interrupts to notify that the same amount of data frames as a period of PCM buffer is actually transferred via serial sound interface. The flag can suppress this if the driver support it.
There's some merits of this configuration:
- No interrupt context run for PCM substream. The PCM substream is handled in any process context only. No need to care of race conditions between interrupt/process contexts. This is good for developers of drivers and applications.
- CPU time is not used for handlers on the interrupt context. The CPU time can be dedicated for the other tasks. This is good in a point of Time Sharing System.
- Hardware is not configured to generate interrupts. This is good in a point of reduction of overall power consumption.
Disabling period interrupt is used for 'Timer-based scheduling' to consume data frames on PCM buffer independently of interrupt context. As noted, no interrupt context runs for PCM substream, thus any blocking operation is not released. Furthermore, system calls for multiplexed I/O is not also released without timeout.
In this scheduling model, applications need to care of available space on PCM buffer by lapse of time, typically by yielding CPU and wait for rescheduling. For the yielding, timeout is calculated for preferable amount of PCM frames to process. This is an additional merit for applications, like sound servers. when an I/O thread of the server wait for the timeout, the other threads can process data frames for server clients. Furthermore, with usage of rewinding/forwarding, applications can achieve low latency between transmission position and handling position even if they uses large size of PCM buffers.
But the timeout should be calculated with enough care of hardware capabilities. To disable period interrupt, used hardware should satisfy some requirements for data transmission:
1. Even if drivers don't handle interrupts to queue next data transmission, hardware voluntarily perform the data transmission when needed (typically by requesting DMA automatically).
2. hardware has a capability to report current position of data transmission with enough accuracy against the data transmission. developers refer this as 'granularity'. If hardware can always reports updated position after the data transmission finishes, the granularity equals to the size of period of PCM buffer.
3. a fine size of data transmission in one time. This size is decided depending on configuration of hardware or DMA controller, but for efficiency it may not be one byte. Thus some amount of data frame is transferred by one data transmission. Developers refer this as 'burst-ness'.
The timeout should be calculated according to the item 2 and 3, however in current ALSA PCM interface supplemental information is not delivered from drivers to applications. Although at present userspace applications should be written by a speculative way for this point, there's few problems because there're a few hardware which satisfy the above items. However, when more drivers supports this feature, the problem may largely be exposed and bothers application developers.
This commit adds an option to use 'timer-based scheduling' for data transmission. This commit adds '--sched-model' option, and the scheduling mode is enabled when 'timer' is assigned to the option by equal sign.
Although there's some TODOs, you can see the scheduling mode in this simple program, like:
$ axfer transfer --sched-model=timer -P -d 2 -D hw:0,3 /dev/urandom -f dat -vvv $ axfer transfer --sched-model=timer -C -d 2 -D hw:1,0 /dev/null -r 48000 -vvv
--- axfer/Makefile.am | 3 +- axfer/xfer-libasound-timer-mmap.c | 455 ++++++++++++++++++++++++++++++ axfer/xfer-libasound.c | 108 ++++++- axfer/xfer-libasound.h | 13 + 4 files changed, 564 insertions(+), 15 deletions(-) create mode 100644 axfer/xfer-libasound-timer-mmap.c
axfer/Makefile.am +2 -1
@@ -53,4 +53,5 @@ axfer_SOURCES = \ waiter.c \ waiter-poll.c \ waiter-select.c \ - waiter-epoll.c + waiter-epoll.c \ + xfer-libasound-timer-mmap.c
axfer/xfer-libasound-timer-mmap.c new file +455 -0
455 lines not on this page · raw message
axfer/xfer-libasound.c +94 -14
196 lines not on this page · raw message
axfer/xfer-libasound.h +13 -0
@@ -15,6 +15,12 @@#define logging (state, ...) \ snd_output_printf(state->log, __VA_ARGS__) +enum sched_model { +SCHED_MODEL_IRQ =0 , +SCHED_MODEL_TIMER , +SCHED_MODEL_COUNT , +}; +struct xfer_libasound_ops ;struct libasound_state {
@@ -31,6 +37,7 @@ struct libasound_state {char *node_literal;char *waiter_type_literal; +char *sched_model_literal;unsigned int msec_per_period;unsigned int msec_per_buffer;
@@ -54,6 +61,9 @@ struct libasound_state {enum waiter_type waiter_type;struct waiter_context *waiter; + +// For scheduling type. +enum sched_model sched_model; };// For internal use in 'libasound' module.
@@ -76,4 +86,7 @@ extern const struct xfer_libasound_ops xfer_libasound_irq_rw_ops;extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_r_ops;extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_w_ops; +extern const struct xfer_libasound_ops xfer_libasound_timer_mmap_w_ops; +extern const struct xfer_libasound_ops xfer_libasound_timer_mmap_r_ops; +#endif
Signature · 1 line
2.19.1
PATCH 34/35 axfer: obsolete some unimplemented options
In reply to Takashi SakamotoAlthogh many options are actually supported by aplay, some of them are not enough good in practical points. For example, '--test-position' option is meaningless for some use cases. Furthermore, due to practical reasons, some options are not implemented well; e.g. vumeter.
This commit marks such options as 'obsoleted'.
--- axfer/xfer-libasound.c | 13 ++++++++++++- axfer/xfer-options.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-)
axfer/xfer-libasound.c +12 -1
@@ -26,9 +26,12 @@ enum no_short_opts {OPT_DISABLE_SOFTVOL ,OPT_FATAL_ERRORS ,OPT_TEST_NOWAIT , +// Obsoleted. +OPT_TEST_POSITION , + OPT_TEST_COEF, }; -#define S_OPTS "D:NMF:B:A:R:T:" +#define S_OPTS "D:NMF:B:A:R:T:m:"static const struct option l_opts[] = { {"device" ,1 ,0 ,'D' }, {"nonblock", 0, 0, 'N'},
@@ -50,6 +53,10 @@ static const struct option l_opts[] = {// For debugging. {"fatal-errors", 0, 0, OPT_FATAL_ERRORS}, {"test-nowait", 0, 0, OPT_TEST_NOWAIT}, +// Obsoleted. + {"chmap", 1, 0, 'm'}, + {"test-position", 0, 0, OPT_TEST_POSITION}, + {"test-coef", 1, 0, OPT_TEST_COEF}, }; static int xfer_libasound_init(struct xfer_context *xfer,
@@ -107,6 +114,10 @@ static int xfer_libasound_parse_opt(struct xfer_context *xfer, int key, state->no_auto_format = true; else if (key == OPT_DISABLE_SOFTVOL) state->no_softvol = true; + else if (key == 'm' || + key == OPT_TEST_POSITION || + key == OPT_TEST_COEF) + err = -EINVAL ; else if (key == OPT_FATAL_ERRORS) state->finish_at_xrun = true; else if (key == OPT_TEST_NOWAIT)
axfer/xfer-options.c +12 -2
@@ -21,6 +21,8 @@ enum no_short_opts {OPT_BUFFER_SIZE ,// Obsoleted. OPT_MAX_FILE_TIME , +OPT_USE_STRFTIME , + OPT_PROCESS_ID_FILE, }; static int allocate_paths(struct xfer_context *xfer, char *const *paths,
@@ -232,7 +234,7 @@ int xfer_options_parse_args(struct xfer_context *xfer, const struct xfer_data *data, int argc, char *const *argv) { - static const char *short_opts = "CPhvqd:s:f:c:r:t:I"; + static const char *short_opts = "CPhvqd:s:f:c:r:t:IV:i"; static const struct option long_opts[] = { // For generic purposes. {"capture", 0, 0, 'C'},
@@ -255,6 +257,10 @@ int xfer_options_parse_args(struct xfer_context *xfer, {"dump-hw-params", 0, 0, OPT_DUMP_HW_PARAMS},// Obsoleted. {"max-file-time", 1, 0, OPT_MAX_FILE_TIME}, + {"use-strftime", 0, 0, OPT_USE_STRFTIME}, + {"process-id-file", 1, 0, OPT_PROCESS_ID_FILE}, + {"vumeter", 1, 0, 'V'}, + {"interactive", 0, 0, 'i'}, };char *s_opts;struct option *l_opts;
@@ -321,7 +327,11 @@ int xfer_options_parse_args(struct xfer_context *xfer, xfer->dump_hw_params = true; else if (key == '?') return -EINVAL; - else if (key == OPT_MAX_FILE_TIME) { + else if (key == OPT_MAX_FILE_TIME || + key == OPT_USE_STRFTIME || + key == OPT_PROCESS_ID_FILE || + key == 'V' || + key == 'i') { fprintf(stderr, "An option '--%s' is obsoleted and has no " "effect.\n",
Signature · 1 line
2.19.1
PATCH 35/35 axfer: add support for libffado transmission backend
In reply to Takashi SakamotoAt present, axfer is designed to use several types of backend for transmission of data frames. This commit is an implementation example of the backend.
Libffado is a userspace library for transmission of data frames according to protocols similar to IEC 61883-1/6. This library handles audio and music units on IEEE 1394 bus.
Unfortunately, this library executes ctor/dtor of instances for some objects in startup/finish routines of C runtime. As a result, it outputs some superfluous messages even if the backend is not actually used. Furthermore, this library brings memory leak internally. Therefore, it's not practical to build this backend for generic purposes. Although the backend implementation works fine, this commit is just for technical preview.
--- axfer/Makefile.am | 5 + axfer/xfer-libffado.c | 555 ++++++++++++++++++++++++++++++++++++++++++ axfer/xfer.c | 6 + axfer/xfer.h | 9 + configure.ac | 12 + 5 files changed, 587 insertions(+) create mode 100644 axfer/xfer-libffado.c
axfer/Makefile.am +5 -0
@@ -55,3 +55,8 @@ axfer_SOURCES = \ waiter-select.c \ waiter-epoll.c \ xfer-libasound-timer-mmap.c + +if HAVE_FFADO +axfer_SOURCES += xfer-libffado.c +LDADD += -lffado +endif
axfer/xfer-libffado.c new file +555 -0
555 lines not on this page · raw message
axfer/xfer.c +6 -0
@@ -13,6 +13,9 @@static const char *const xfer_type_labels[] = { [XFER_TYPE_LIBASOUND ] ="libasound" , +#if WITH_FFADO + [XFER_TYPE_LIBFFADO ] ="libffado" , +#endif };enum xfer_type xfer_type_from_label (const char *label)
@@ -35,6 +38,9 @@ int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,const struct xfer_data *data; } *entry, entries[] = { {XFER_TYPE_LIBASOUND, &xfer_libasound}, +#if WITH_FFADO + {XFER_TYPE_LIBFFADO, &xfer_libffado}, +#endif };int i;int err;
axfer/xfer.h +9 -0
@@ -13,9 +13,14 @@#include <getopt.h> +#include "aconfig.h" +enum xfer_type {XFER_TYPE_UNSUPPORTED =-1 ,XFER_TYPE_LIBASOUND =0 , +#if WITH_FFADO +XFER_TYPE_LIBFFADO , +#endif XFER_TYPE_COUNT , };
@@ -103,4 +108,8 @@ struct xfer_data {extern const struct xfer_data xfer_libasound; +#if WITH_FFADO +extern const struct xfer_data xfer_libffado; +#endif +#endif
configure.ac +12 -0
@@ -50,6 +50,17 @@ if test "$HAVE_SEQ_CLIENT_INFO_GET_PID" = "yes" ; then AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_PID], 1, [alsa-lib supports snd_seq_client_info_get_pid]) fi +# +# NOTE: The library 'libffado' (at least v2.4.1) executes ctor/dtor of instances +# for some objects in startup/finish routines of C runtime. As a result, it +# outputs some superfluos messages. Furthermore, it brings much memory leak +# internally. Totally, libffado support is not recommended at all in usual +# purposes except for technical preview. +# +AC_CHECK_LIB([ffado], [ffado_streaming_init], [have_ffado="yes"], [have_ffado="no"]) +AS_IF([test x"$have_ffado" = xyes], + [AC_DEFINE([WITH_FFADO], [1], [Define if FFADO library is available])]) + AM_CONDITIONAL(HAVE_PCM, test "$have_pcm" = "yes") AM_CONDITIONAL(HAVE_MIXER, test "$have_mixer" = "yes") AM_CONDITIONAL(HAVE_RAWMIDI, test "$have_rawmidi" = "yes")
@@ -57,6 +68,7 @@ AM_CONDITIONAL(HAVE_SEQ, test "$have_seq" = "yes") AM_CONDITIONAL(HAVE_UCM, test "$have_ucm" = "yes") AM_CONDITIONAL(HAVE_TOPOLOGY, test "$have_topology" = "yes") AM_CONDITIONAL(HAVE_SAMPLERATE, test "$have_samplerate" = "yes") +AM_CONDITIONAL(HAVE_FFADO, test "$have_ffado" = "yes") dnl Use tinyalsa alsabat_backend_tiny=
Signature · 1 line
2.19.1
Re: [PATCH 01/35] axfer: add an entry point for this command
In reply to Takashi SakamotoQuoted 16 lines · Takashi Sakamoto
This commit adds a new command, 'axfer' ('ALSA transfer'), to transfer data frames described in
asound.h. This command is intended to replace current aplay. The most of features and command line parameters come from aplay as much as possible, while it has more better feature and code to maintain.This commit adds an entry point for this command. Current option system of aplay is still available, while this command has a sub-command system like commands in iproute2.
Currently, two sub-commands are supported; 'list' and 'transfer'. The 'list' sub-command has the same effect as '-l' and '-L' options of aplay. The 'transfer' sub-command has the same effect as the main feature of aplay. For the sub-command system, an option for stream direction is required; '-P' for playback and '-C' for capture. If you create symbolic links to this binary for aplay/arecord, please execute:
Quoted 6 lines
$ ln -s axfer aplay $ ln -s axfer arecordActual code for each sub-command will be implemented in later commits.
Signed-off-by Takashi Sakamoto <[email protected]>
Although all patches have been merged, below are a few suggestions:
- Please make help working. It took some time for me until figuring out the fact that the direction option is mandatory, for example.
- The input/output from/to a terminal can be checked via isatty(). That allows us to see garbages by a mistakenly started command.
- A man page. (I thought Debian mandates it?)
In anyway, thanks for your hard work!
Takashi
Re: [PATCH 01/35] axfer: add an entry point for this command
Hi,
Quoted 25 lines · Takashi Iwai
Quoted 16 lines · Takashi Sakamoto
This commit adds a new command, 'axfer' ('ALSA transfer'), to transfer data frames described in
asound.h. This command is intended to replace current aplay. The most of features and command line parameters come from aplay as much as possible, while it has more better feature and code to maintain.This commit adds an entry point for this command. Current option system of aplay is still available, while this command has a sub-command system like commands in iproute2.
Currently, two sub-commands are supported; 'list' and 'transfer'. The 'list' sub-command has the same effect as '-l' and '-L' options of aplay. The 'transfer' sub-command has the same effect as the main feature of aplay. For the sub-command system, an option for stream direction is required; '-P' for playback and '-C' for capture. If you create symbolic links to this binary for aplay/arecord, please execute:
Quoted 6 lines
$ ln -s axfer aplay $ ln -s axfer arecordActual code for each sub-command will be implemented in later commits.
Signed-off-by Takashi Sakamoto <[email protected]>
Quoted 7 lines
Although all patches have been merged, below are a few suggestions:
- Please make help working. It took some time for me until figuring out the fact that the direction option is mandatory, for example.
- The input/output from/to a terminal can be checked via
isatty(). That allows us to see garbages by a mistakenly started command.
If my understanding is correct, usage of 'isatty(3)' can return error in a case that users just run 'axfer transfer -P (-)'. In current implementation, axfer continues to call of 'read(2)' and receive '-EAGAIN' till receiving teminate signals.
Quoted 1 line
- A man page. (I thought Debian mandates it?)
I have a plan to write help/man in this development period, within this year.
Quoted 1 line
In anyway, thanks for your hard work!
Yep. I'm a bit exhausted from this tough work, and need refresh time. Anyway, thank you for applying this PR.
Regards
Takashi Sakamoto
Re: [PATCH 01/35] axfer: add an entry point for this command
Quoted 32 lines · Takashi Sakamoto
Hi,
Quoted 27 lines · Takashi Iwai
Quoted 16 lines · Takashi Sakamoto
This commit adds a new command, 'axfer' ('ALSA transfer'), to transfer data frames described in
asound.h. This command is intended to replace current aplay. The most of features and command line parameters come from aplay as much as possible, while it has more better feature and code to maintain.This commit adds an entry point for this command. Current option system of aplay is still available, while this command has a sub-command system like commands in iproute2.
Currently, two sub-commands are supported; 'list' and 'transfer'. The 'list' sub-command has the same effect as '-l' and '-L' options of aplay. The 'transfer' sub-command has the same effect as the main feature of aplay. For the sub-command system, an option for stream direction is required; '-P' for playback and '-C' for capture. If you create symbolic links to this binary for aplay/arecord, please execute:
Quoted 6 lines
$ ln -s axfer aplay $ ln -s axfer arecordActual code for each sub-command will be implemented in later commits.
Signed-off-by Takashi Sakamoto <[email protected]>Although all patches have been merged, below are a few suggestions:
Quoted 8 lines
Quoted 5 lines
- Please make help working. It took some time for me until figuring out the fact that the direction option is mandatory, for example.
- The input/output from/to a terminal can be checked via
isatty(). That allows us to see garbages by a mistakenly started command.If my understanding is correct, usage of 'isatty(3)' can return error in a case that users just run 'axfer transfer -P (-)'.
Right.
Quoted 3 lines
In current
implementation, axfer continues to call of 'read(2)' and receive '-EAGAIN' till receiving teminate signals.
The playback isn't too bad (although I don't see any useful scenario, either). The worse is the capture that prints junk texts that sometimes mandates the terminal reset.
Quoted 4 lines
Quoted 1 line
- A man page. (I thought Debian mandates it?)
I have a plan to write help/man in this development period, within this year.
Not only children cheer for a Christmas gift, yeah :)
thanks,
Takashi
Quoted 10 lines
Quoted 1 line
In anyway, thanks for your hard work!
Yep. I'm a bit exhausted from this tough work, and need refresh time. Anyway, thank you for applying this PR.
Regards
Takashi Sakamoto