2018-11-13 07:41:25 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// xfer.h - a header for receiver/transmiter of data frames.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
|
|
|
|
//
|
|
|
|
// Licensed under the terms of the GNU General Public License, version 2.
|
|
|
|
|
|
|
|
#ifndef __ALSA_UTILS_AXFER_XFER__H_
|
|
|
|
#define __ALSA_UTILS_AXFER_XFER__H_
|
|
|
|
|
|
|
|
#include "mapper.h"
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2018-11-13 07:41:47 +01:00
|
|
|
#include "aconfig.h"
|
|
|
|
|
2018-11-13 07:41:25 +01:00
|
|
|
enum xfer_type {
|
|
|
|
XFER_TYPE_UNSUPPORTED = -1,
|
2018-11-13 07:41:27 +01:00
|
|
|
XFER_TYPE_LIBASOUND = 0,
|
2018-11-13 07:41:47 +01:00
|
|
|
#if WITH_FFADO
|
|
|
|
XFER_TYPE_LIBFFADO,
|
|
|
|
#endif
|
2018-11-13 07:41:25 +01:00
|
|
|
XFER_TYPE_COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xfer_ops;
|
|
|
|
|
|
|
|
struct xfer_context {
|
|
|
|
snd_pcm_stream_t direction;
|
|
|
|
enum xfer_type type;
|
|
|
|
const struct xfer_ops *ops;
|
|
|
|
void *private_data;
|
|
|
|
|
axfer: add a parser for command-line options
In 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.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:26 +01:00
|
|
|
char *sample_format_literal;
|
|
|
|
char *cntr_format_literal;
|
2018-11-13 07:41:25 +01:00
|
|
|
unsigned int verbose;
|
2018-11-13 07:41:32 +01:00
|
|
|
unsigned int duration_seconds;
|
|
|
|
unsigned int duration_frames;
|
axfer: add a parser for command-line options
In 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.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:26 +01:00
|
|
|
unsigned int frames_per_second;
|
|
|
|
unsigned int samples_per_frame;
|
|
|
|
bool help:1;
|
2018-11-13 07:41:30 +01:00
|
|
|
bool quiet:1;
|
2018-11-13 07:41:31 +01:00
|
|
|
bool dump_hw_params:1;
|
axfer: add a parser for command-line options
In 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.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:26 +01:00
|
|
|
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;
|
2018-11-13 07:41:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum xfer_type xfer_type_from_label(const char *label);
|
2018-12-07 10:41:02 +01:00
|
|
|
const char *xfer_label_from_type(enum xfer_type type);
|
2018-11-13 07:41:25 +01:00
|
|
|
|
|
|
|
int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,
|
|
|
|
snd_pcm_stream_t direction, int argc, char *const *argv);
|
|
|
|
void xfer_context_destroy(struct xfer_context *xfer);
|
|
|
|
int xfer_context_pre_process(struct xfer_context *xfer,
|
|
|
|
snd_pcm_format_t *format,
|
|
|
|
unsigned int *samples_per_frame,
|
|
|
|
unsigned int *frames_per_second,
|
|
|
|
snd_pcm_access_t *access,
|
|
|
|
snd_pcm_uframes_t *frames_per_buffer);
|
|
|
|
int xfer_context_process_frames(struct xfer_context *xfer,
|
|
|
|
struct mapper_context *mapper,
|
|
|
|
struct container_context *cntrs,
|
|
|
|
unsigned int *frame_count);
|
|
|
|
void xfer_context_pause(struct xfer_context *xfer, bool enable);
|
|
|
|
void xfer_context_post_process(struct xfer_context *xfer);
|
axfer: add a parser for command-line options
In 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.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-11-13 07:41:26 +01:00
|
|
|
|
|
|
|
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);
|
2018-11-13 07:41:32 +01:00
|
|
|
void xfer_options_calculate_duration(struct xfer_context *xfer,
|
|
|
|
uint64_t *total_frame_count);
|
2018-11-13 07:41:25 +01:00
|
|
|
|
|
|
|
// For internal use in 'xfer' module.
|
|
|
|
|
|
|
|
struct xfer_ops {
|
|
|
|
int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction);
|
|
|
|
int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg);
|
|
|
|
int (*validate_opts)(struct xfer_context *xfer);
|
|
|
|
int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format,
|
|
|
|
unsigned int *samples_per_frame,
|
|
|
|
unsigned int *frames_per_second,
|
|
|
|
snd_pcm_access_t *access,
|
|
|
|
snd_pcm_uframes_t *frames_per_buffer);
|
|
|
|
int (*process_frames)(struct xfer_context *xfer,
|
|
|
|
unsigned int *frame_count,
|
|
|
|
struct mapper_context *mapper,
|
|
|
|
struct container_context *cntrs);
|
|
|
|
void (*post_process)(struct xfer_context *xfer);
|
|
|
|
void (*destroy)(struct xfer_context *xfer);
|
|
|
|
void (*pause)(struct xfer_context *xfer, bool enable);
|
2018-12-07 10:41:02 +01:00
|
|
|
void (*help)(struct xfer_context *xfer);
|
2018-11-13 07:41:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct xfer_data {
|
|
|
|
const char *s_opts;
|
|
|
|
const struct option *l_opts;
|
|
|
|
unsigned int l_opts_count;
|
|
|
|
struct xfer_ops ops;
|
|
|
|
unsigned int private_size;
|
|
|
|
};
|
|
|
|
|
2018-11-13 07:41:27 +01:00
|
|
|
extern const struct xfer_data xfer_libasound;
|
2018-11-13 07:41:25 +01:00
|
|
|
|
2018-11-13 07:41:47 +01:00
|
|
|
#if WITH_FFADO
|
|
|
|
extern const struct xfer_data xfer_libffado;
|
|
|
|
#endif
|
|
|
|
|
2018-11-13 07:41:25 +01:00
|
|
|
#endif
|