Blame axfer/xfer.h

Packit Service a9274b
// SPDX-License-Identifier: GPL-2.0
Packit Service a9274b
//
Packit Service a9274b
// xfer.h - a header for receiver/transmiter of data frames.
Packit Service a9274b
//
Packit Service a9274b
// Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
Packit Service a9274b
//
Packit Service a9274b
// Licensed under the terms of the GNU General Public License, version 2.
Packit Service a9274b
Packit Service a9274b
#ifndef __ALSA_UTILS_AXFER_XFER__H_
Packit Service a9274b
#define __ALSA_UTILS_AXFER_XFER__H_
Packit Service a9274b
Packit Service a9274b
#include "mapper.h"
Packit Service a9274b
Packit Service a9274b
#include <getopt.h>
Packit Service a9274b
Packit Service a9274b
#include "aconfig.h"
Packit Service a9274b
Packit Service a9274b
enum xfer_type {
Packit Service a9274b
	XFER_TYPE_UNSUPPORTED = -1,
Packit Service a9274b
	XFER_TYPE_LIBASOUND = 0,
Packit Service a9274b
#if WITH_FFADO
Packit Service a9274b
	XFER_TYPE_LIBFFADO,
Packit Service a9274b
#endif
Packit Service a9274b
	XFER_TYPE_COUNT,
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
struct xfer_ops;
Packit Service a9274b
Packit Service a9274b
struct xfer_context {
Packit Service a9274b
	snd_pcm_stream_t direction;
Packit Service a9274b
	enum xfer_type type;
Packit Service a9274b
	const struct xfer_ops *ops;
Packit Service a9274b
	void *private_data;
Packit Service a9274b
Packit Service a9274b
	char *sample_format_literal;
Packit Service a9274b
	char *cntr_format_literal;
Packit Service a9274b
	unsigned int verbose;
Packit Service a9274b
	unsigned int duration_seconds;
Packit Service a9274b
	unsigned int duration_frames;
Packit Service a9274b
	unsigned int frames_per_second;
Packit Service a9274b
	unsigned int samples_per_frame;
Packit Service a9274b
	bool help:1;
Packit Service a9274b
	bool quiet:1;
Packit Service a9274b
	bool dump_hw_params:1;
Packit Service a9274b
	bool multiple_cntrs:1;	// For mapper.
Packit Service a9274b
Packit Service a9274b
	snd_pcm_format_t sample_format;
Packit Service a9274b
Packit Service a9274b
	// For containers.
Packit Service a9274b
	char **paths;
Packit Service a9274b
	unsigned int path_count;
Packit Service a9274b
	enum container_format cntr_format;
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
enum xfer_type xfer_type_from_label(const char *label);
Packit Service a9274b
const char *xfer_label_from_type(enum xfer_type type);
Packit Service a9274b
Packit Service a9274b
int xfer_context_init(struct xfer_context *xfer, enum xfer_type type,
Packit Service a9274b
		      snd_pcm_stream_t direction, int argc, char *const *argv);
Packit Service a9274b
void xfer_context_destroy(struct xfer_context *xfer);
Packit Service a9274b
int xfer_context_pre_process(struct xfer_context *xfer,
Packit Service a9274b
			     snd_pcm_format_t *format,
Packit Service a9274b
			     unsigned int *samples_per_frame,
Packit Service a9274b
			     unsigned int *frames_per_second,
Packit Service a9274b
			     snd_pcm_access_t *access,
Packit Service a9274b
			     snd_pcm_uframes_t *frames_per_buffer);
Packit Service a9274b
int xfer_context_process_frames(struct xfer_context *xfer,
Packit Service a9274b
				struct mapper_context *mapper,
Packit Service a9274b
				struct container_context *cntrs,
Packit Service a9274b
				unsigned int *frame_count);
Packit Service a9274b
void xfer_context_pause(struct xfer_context *xfer, bool enable);
Packit Service a9274b
void xfer_context_post_process(struct xfer_context *xfer);
Packit Service a9274b
Packit Service a9274b
struct xfer_data;
Packit Service a9274b
int xfer_options_parse_args(struct xfer_context *xfer,
Packit Service a9274b
			    const struct xfer_data *data, int argc,
Packit Service a9274b
			    char *const *argv);
Packit Service a9274b
int xfer_options_fixup_paths(struct xfer_context *xfer);
Packit Service a9274b
void xfer_options_calculate_duration(struct xfer_context *xfer,
Packit Service a9274b
				     uint64_t *total_frame_count);
Packit Service a9274b
Packit Service a9274b
// For internal use in 'xfer' module.
Packit Service a9274b
Packit Service a9274b
struct xfer_ops {
Packit Service a9274b
	int (*init)(struct xfer_context *xfer, snd_pcm_stream_t direction);
Packit Service a9274b
	int (*parse_opt)(struct xfer_context *xfer, int key, const char *optarg);
Packit Service a9274b
	int (*validate_opts)(struct xfer_context *xfer);
Packit Service a9274b
	int (*pre_process)(struct xfer_context *xfer, snd_pcm_format_t *format,
Packit Service a9274b
			   unsigned int *samples_per_frame,
Packit Service a9274b
			   unsigned int *frames_per_second,
Packit Service a9274b
			   snd_pcm_access_t *access,
Packit Service a9274b
			   snd_pcm_uframes_t *frames_per_buffer);
Packit Service a9274b
	int (*process_frames)(struct xfer_context *xfer,
Packit Service a9274b
			      unsigned int *frame_count,
Packit Service a9274b
			      struct mapper_context *mapper,
Packit Service a9274b
			      struct container_context *cntrs);
Packit Service a9274b
	void (*post_process)(struct xfer_context *xfer);
Packit Service a9274b
	void (*destroy)(struct xfer_context *xfer);
Packit Service a9274b
	void (*pause)(struct xfer_context *xfer, bool enable);
Packit Service a9274b
	void (*help)(struct xfer_context *xfer);
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
struct xfer_data {
Packit Service a9274b
	const char *s_opts;
Packit Service a9274b
	const struct option *l_opts;
Packit Service a9274b
	unsigned int l_opts_count;
Packit Service a9274b
	struct xfer_ops ops;
Packit Service a9274b
	unsigned int private_size;
Packit Service a9274b
};
Packit Service a9274b
Packit Service a9274b
extern const struct xfer_data xfer_libasound;
Packit Service a9274b
Packit Service a9274b
#if WITH_FFADO
Packit Service a9274b
	extern const struct xfer_data xfer_libffado;
Packit Service a9274b
#endif
Packit Service a9274b
Packit Service a9274b
#endif