OSDN Git Service

axfer: add support to transfer data frames by alsa-lib PCM APIs
[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_LIBASOUND = 0,
19         XFER_TYPE_COUNT,
20 };
21
22 struct xfer_ops;
23
24 struct xfer_context {
25         snd_pcm_stream_t direction;
26         enum xfer_type type;
27         const struct xfer_ops *ops;
28         void *private_data;
29
30         char *sample_format_literal;
31         char *cntr_format_literal;
32         unsigned int verbose;
33         unsigned int frames_per_second;
34         unsigned int samples_per_frame;
35         bool help:1;
36         bool multiple_cntrs:1;  // For mapper.
37
38         snd_pcm_format_t sample_format;
39
40         // For containers.
41         char **paths;
42         unsigned int path_count;
43         enum container_format cntr_format;
44 };
45
46 enum xfer_type xfer_type_from_label(const char *label);
47
48 int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,
49                       snd_pcm_stream_t direction, int argc, char *const *argv);
50 void xfer_context_destroy(struct xfer_context *xfer);
51 int xfer_context_pre_process(struct xfer_context *xfer,
52                              snd_pcm_format_t *format,
53                              unsigned int *samples_per_frame,
54                              unsigned int *frames_per_second,
55                              snd_pcm_access_t *access,
56                              snd_pcm_uframes_t *frames_per_buffer);
57 int xfer_context_process_frames(struct xfer_context *xfer,
58                                 struct mapper_context *mapper,
59                                 struct container_context *cntrs,
60                                 unsigned int *frame_count);
61 void xfer_context_pause(struct xfer_context *xfer, bool enable);
62 void xfer_context_post_process(struct xfer_context *xfer);
63
64 struct xfer_data;
65 int xfer_options_parse_args(struct xfer_context *xfer,
66                             const struct xfer_data *data, int argc,
67                             char *const *argv);
68 int xfer_options_fixup_paths(struct xfer_context *xfer);
69
70 // For internal use in 'xfer' module.
71
72 struct xfer_ops {
73         int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction);
74         int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg);
75         int (*validate_opts)(struct xfer_context *xfer);
76         int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format,
77                            unsigned int *samples_per_frame,
78                            unsigned int *frames_per_second,
79                            snd_pcm_access_t *access,
80                            snd_pcm_uframes_t *frames_per_buffer);
81         int (*process_frames)(struct xfer_context *xfer,
82                               unsigned int *frame_count,
83                               struct mapper_context *mapper,
84                               struct container_context *cntrs);
85         void (*post_process)(struct xfer_context *xfer);
86         void (*destroy)(struct xfer_context *xfer);
87         void (*pause)(struct xfer_context *xfer, bool enable);
88 };
89
90 struct xfer_data {
91         const char *s_opts;
92         const struct option *l_opts;
93         unsigned int l_opts_count;
94         struct xfer_ops ops;
95         unsigned int private_size;
96 };
97
98 extern const struct xfer_data xfer_libasound;
99
100 #endif