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 #include "aconfig.h" 17 18 enum xfer_type { 19 XFER_TYPE_UNSUPPORTED = -1, 20 XFER_TYPE_LIBASOUND = 0, 21 #if WITH_FFADO 22 XFER_TYPE_LIBFFADO, 23 #endif 24 XFER_TYPE_COUNT, 25 }; 26 27 struct xfer_ops; 28 29 struct xfer_context { 30 snd_pcm_stream_t direction; 31 enum xfer_type type; 32 const struct xfer_ops *ops; 33 void *private_data; 34 35 char *sample_format_literal; 36 char *cntr_format_literal; 37 unsigned int verbose; 38 unsigned int duration_seconds; 39 unsigned int duration_frames; 40 unsigned int frames_per_second; 41 unsigned int samples_per_frame; 42 bool help:1; 43 bool quiet:1; 44 bool dump_hw_params:1; 45 bool multiple_cntrs:1; // For mapper. 46 47 snd_pcm_format_t sample_format; 48 49 // For containers. 50 char **paths; 51 unsigned int path_count; 52 enum container_format cntr_format; 53 }; 54 55 enum xfer_type xfer_type_from_label(const char *label); 56 const char *xfer_label_from_type(enum xfer_type type); 57 58 int xfer_context_init(struct xfer_context *xfer, enum xfer_type type, 59 snd_pcm_stream_t direction, int argc, char *const *argv); 60 void xfer_context_destroy(struct xfer_context *xfer); 61 int xfer_context_pre_process(struct xfer_context *xfer, 62 snd_pcm_format_t *format, 63 unsigned int *samples_per_frame, 64 unsigned int *frames_per_second, 65 snd_pcm_access_t *access, 66 snd_pcm_uframes_t *frames_per_buffer); 67 int xfer_context_process_frames(struct xfer_context *xfer, 68 struct mapper_context *mapper, 69 struct container_context *cntrs, 70 unsigned int *frame_count); 71 void xfer_context_pause(struct xfer_context *xfer, bool enable); 72 void xfer_context_post_process(struct xfer_context *xfer); 73 74 struct xfer_data; 75 int xfer_options_parse_args(struct xfer_context *xfer, 76 const struct xfer_data *data, int argc, 77 char *const *argv); 78 int xfer_options_fixup_paths(struct xfer_context *xfer); 79 void xfer_options_calculate_duration(struct xfer_context *xfer, 80 uint64_t *total_frame_count); 81 82 // For internal use in 'xfer' module. 83 84 struct xfer_ops { 85 int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction); 86 int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg); 87 int (*validate_opts)(struct xfer_context *xfer); 88 int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format, 89 unsigned int *samples_per_frame, 90 unsigned int *frames_per_second, 91 snd_pcm_access_t *access, 92 snd_pcm_uframes_t *frames_per_buffer); 93 int (*process_frames)(struct xfer_context *xfer, 94 unsigned int *frame_count, 95 struct mapper_context *mapper, 96 struct container_context *cntrs); 97 void (*post_process)(struct xfer_context *xfer); 98 void (*destroy)(struct xfer_context *xfer); 99 void (*pause)(struct xfer_context *xfer, bool enable); 100 void (*help)(struct xfer_context *xfer); 101 }; 102 103 struct xfer_data { 104 const char *s_opts; 105 const struct option *l_opts; 106 unsigned int l_opts_count; 107 struct xfer_ops ops; 108 unsigned int private_size; 109 }; 110 111 extern const struct xfer_data xfer_libasound; 112 113 #if WITH_FFADO 114 extern const struct xfer_data xfer_libffado; 115 #endif 116 117 #endif 118