OSDN Git Service

axfer: add a common interface to transfer data frames
[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         unsigned int verbose;
30 };
31
32 enum xfer_type xfer_type_from_label(const char *label);
33
34 int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,
35                       snd_pcm_stream_t direction, int argc, char *const *argv);
36 void xfer_context_destroy(struct xfer_context *xfer);
37 int xfer_context_pre_process(struct xfer_context *xfer,
38                              snd_pcm_format_t *format,
39                              unsigned int *samples_per_frame,
40                              unsigned int *frames_per_second,
41                              snd_pcm_access_t *access,
42                              snd_pcm_uframes_t *frames_per_buffer);
43 int xfer_context_process_frames(struct xfer_context *xfer,
44                                 struct mapper_context *mapper,
45                                 struct container_context *cntrs,
46                                 unsigned int *frame_count);
47 void xfer_context_pause(struct xfer_context *xfer, bool enable);
48 void xfer_context_post_process(struct xfer_context *xfer);
49
50 // For internal use in 'xfer' module.
51
52 struct xfer_ops {
53         int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction);
54         int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg);
55         int (*validate_opts)(struct xfer_context *xfer);
56         int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format,
57                            unsigned int *samples_per_frame,
58                            unsigned int *frames_per_second,
59                            snd_pcm_access_t *access,
60                            snd_pcm_uframes_t *frames_per_buffer);
61         int (*process_frames)(struct xfer_context *xfer,
62                               unsigned int *frame_count,
63                               struct mapper_context *mapper,
64                               struct container_context *cntrs);
65         void (*post_process)(struct xfer_context *xfer);
66         void (*destroy)(struct xfer_context *xfer);
67         void (*pause)(struct xfer_context *xfer, bool enable);
68 };
69
70 struct xfer_data {
71         const char *s_opts;
72         const struct option *l_opts;
73         unsigned int l_opts_count;
74         struct xfer_ops ops;
75         unsigned int private_size;
76 };
77
78 extern const struct xfer_data xfer_alsa;
79
80 #endif