OSDN Git Service

axfer: add a parser for command-line options
[android-x86/external-alsa-utils.git] / axfer / xfer.h
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // xfer.h - a header for receiver/transmiter of data frames.
4 //
5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 //
7 // Licensed under the terms of the GNU General Public License, version 2.
8
9 #ifndef __ALSA_UTILS_AXFER_XFER__H_
10 #define __ALSA_UTILS_AXFER_XFER__H_
11
12 #include "mapper.h"
13
14 #include <getopt.h>
15
16 enum xfer_type {
17         XFER_TYPE_UNSUPPORTED = -1,
18         XFER_TYPE_COUNT,
19 };
20
21 struct xfer_ops;
22
23 struct xfer_context {
24         snd_pcm_stream_t direction;
25         enum xfer_type type;
26         const struct xfer_ops *ops;
27         void *private_data;
28
29         char *sample_format_literal;
30         char *cntr_format_literal;
31         unsigned int verbose;
32         unsigned int frames_per_second;
33         unsigned int samples_per_frame;
34         bool help:1;
35         bool multiple_cntrs:1;  // For mapper.
36
37         snd_pcm_format_t sample_format;
38
39         // For containers.
40         char **paths;
41         unsigned int path_count;
42         enum container_format cntr_format;
43 };
44
45 enum xfer_type xfer_type_from_label(const char *label);
46
47 int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,
48                       snd_pcm_stream_t direction, int argc, char *const *argv);
49 void xfer_context_destroy(struct xfer_context *xfer);
50 int xfer_context_pre_process(struct xfer_context *xfer,
51                              snd_pcm_format_t *format,
52                              unsigned int *samples_per_frame,
53                              unsigned int *frames_per_second,
54                              snd_pcm_access_t *access,
55                              snd_pcm_uframes_t *frames_per_buffer);
56 int xfer_context_process_frames(struct xfer_context *xfer,
57                                 struct mapper_context *mapper,
58                                 struct container_context *cntrs,
59                                 unsigned int *frame_count);
60 void xfer_context_pause(struct xfer_context *xfer, bool enable);
61 void xfer_context_post_process(struct xfer_context *xfer);
62
63 struct xfer_data;
64 int xfer_options_parse_args(struct xfer_context *xfer,
65                             const struct xfer_data *data, int argc,
66                             char *const *argv);
67 int xfer_options_fixup_paths(struct xfer_context *xfer);
68
69 // For internal use in 'xfer' module.
70
71 struct xfer_ops {
72         int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction);
73         int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg);
74         int (*validate_opts)(struct xfer_context *xfer);
75         int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format,
76                            unsigned int *samples_per_frame,
77                            unsigned int *frames_per_second,
78                            snd_pcm_access_t *access,
79                            snd_pcm_uframes_t *frames_per_buffer);
80         int (*process_frames)(struct xfer_context *xfer,
81                               unsigned int *frame_count,
82                               struct mapper_context *mapper,
83                               struct container_context *cntrs);
84         void (*post_process)(struct xfer_context *xfer);
85         void (*destroy)(struct xfer_context *xfer);
86         void (*pause)(struct xfer_context *xfer, bool enable);
87 };
88
89 struct xfer_data {
90         const char *s_opts;
91         const struct option *l_opts;
92         unsigned int l_opts_count;
93         struct xfer_ops ops;
94         unsigned int private_size;
95 };
96
97 extern const struct xfer_data xfer_alsa;
98
99 #endif