summaryrefslogtreecommitdiffstats
path: root/core.h
blob: d9b1382a2074cf425eb3b4c02648ce7690d9508e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: GPL-2.0
/*
 * ALSA Virtual Soundcard
 *
 * core.h - System-level header for virtual ALSA card
 *
 * Copyright (C) 2010-2018 Fiberdyne Systems Pty Ltd
 */

#ifndef __AVIRT_CORE_H__
#define __AVIRT_CORE_H__

#include <sound/pcm.h>
#include <linux/configfs.h>

#define MAX_STREAMS 16
#define MAX_NAME_LEN 80

/**
 * AVIRT Audio Path configure function type
 * Each Audio Path registers this at avirt_audiopath_register time.
 * It is then called by the core once AVIRT has been configured
 */
typedef int (*avirt_audiopath_configure)(struct config_group *stream_group,
					 unsigned int stream_count);

/**
 * AVIRT Audio Path info
 */
struct avirt_audiopath {
	const char *uid; /* Unique identifier */
	const char *name; /* Pretty name */
	unsigned int version[3]; /* Version - Major.Minor.Ext */
	const struct snd_pcm_hardware *hw; /* ALSA PCM HW conf */
	const struct snd_pcm_ops *pcm_ops; /* ALSA PCM op table */
	avirt_audiopath_configure configure; /* Configure callback function */

	void *context;
};

/*
 * Audio stream configuration
 */
struct avirt_stream {
	char name[MAX_NAME_LEN]; /* Stream name */
	char map[MAX_NAME_LEN]; /* Stream Audio Path mapping */
	unsigned int channels; /* Stream channel count */
	unsigned int device; /* Stream PCM device no. */
	unsigned int direction; /* Stream direction */
	struct config_item item; /* configfs item reference */
};

/**
 * AVIRT core info
 */
struct avirt_coreinfo {
	unsigned int version[3];
};

/**
 * avirt_audiopath_register - register Audio Path with ALSA virtual driver
 * @audiopath: Audio Path to be registered
 * @core: ALSA virtual driver core info
 * @return: 0 on success or error code otherwise
 */
int avirt_audiopath_register(struct avirt_audiopath *audiopath,
			     struct avirt_coreinfo **coreinfo);

/**
 * avirt_audiopath_deregister - deregister Audio Path with ALSA virtual driver
 * @audiopath: Audio Path to be deregistered
 * @return: 0 on success or error code otherwise
 */
int avirt_audiopath_deregister(struct avirt_audiopath *audiopath);

/**
 * avirt_audiopath_get - retrieves the Audio Path by it's UID
 * @uid: Unique ID for the Audio Path
 * @return: Corresponding Audio Path
 */
struct avirt_audiopath *avirt_audiopath_get(const char *uid);

/**
 * avirt_stream_count - get the stream count for the given direction
 * @direction: The direction to get the stream count for
 * @return: The stream count
 */
int avirt_stream_count(unsigned int direction);

/**
 * avirt_stream_from_config_item - Convert a config_item to an avirt_stream
 * @item: The config_item to convert from
 * @return: The item's avirt_stream if successful, NULL otherwise
 */
static inline struct avirt_stream *
	avirt_stream_from_config_item(struct config_item *item)
{
	return item ? container_of(item, struct avirt_stream, item) : NULL;
}

/**
 * avirt_pcm_period_elapsed - PCM buffer complete callback
 * @substream: pointer to ALSA PCM substream
 *
 * This should be called from a child Audio Path once it has finished processing
 * the PCM buffer
 */
void avirt_pcm_period_elapsed(struct snd_pcm_substream *substream);

#endif // __AVIRT_CORE_H__