summaryrefslogtreecommitdiffstats
path: root/audio_hw.c
blob: 30d89316585d4f5ca9f4474e48436eb43affd8ff (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
 * 
 * This is based on Galaxy Nexus audio.primary.tuna implementation:
 * Copyright 2011, The Android Open-Source Project
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define LOG_TAG "audio_hw"

#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/time.h>

#include <cutils/log.h>

#include "audio_hw.h"

/*
 * Functions
 */

static uint32_t audio_hw_get_supported_devices(const struct audio_hw_device *dev)
{
	LOGD("%s(%p)", __func__, dev);

	int supported_output_devices = AUDIO_DEVICE_OUT_EARPIECE |
		AUDIO_DEVICE_OUT_SPEAKER |
		AUDIO_DEVICE_OUT_WIRED_HEADSET |
		AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
		AUDIO_DEVICE_OUT_AUX_DIGITAL |
		AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
		AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
		AUDIO_DEVICE_OUT_ALL_SCO |
		AUDIO_DEVICE_OUT_DEFAULT;

	int supported_input_devices = AUDIO_DEVICE_IN_COMMUNICATION |
		AUDIO_DEVICE_IN_AMBIENT |
		AUDIO_DEVICE_IN_BUILTIN_MIC |
		AUDIO_DEVICE_IN_WIRED_HEADSET |
		AUDIO_DEVICE_IN_AUX_DIGITAL |
		AUDIO_DEVICE_IN_BACK_MIC |
		AUDIO_DEVICE_IN_ALL_SCO |
		AUDIO_DEVICE_IN_DEFAULT;

	return supported_output_devices | supported_input_devices;
}

static int audio_hw_init_check(const struct audio_hw_device *dev)
{
	LOGD("%s(%p)", __func__, dev);

	if(dev != NULL)
		return 0;
	else
		return  -EINVAL;
}

static int audio_hw_set_voice_volume(struct audio_hw_device *dev, float volume)
{
	LOGD("%s(%p, %f)", __func__, dev, volume);

	return -ENOSYS;
}

static int audio_hw_set_master_volume(struct audio_hw_device *dev, float volume)
{
	LOGD("%s(%p, %f)", __func__, dev, volume);

	return -ENOSYS;
}

static int audio_hw_set_mode(struct audio_hw_device *dev, int mode)
{
	LOGD("%s(%p, %d)", __func__, dev, mode);

	return 0;
}

static int audio_hw_set_mic_mute(struct audio_hw_device *dev, bool state)
{
	LOGD("%s(%p, %d)", __func__, dev, state);

	return -ENOSYS;
}

static int audio_hw_get_mic_mute(const struct audio_hw_device *dev, bool *state)
{
	LOGD("%s(%p, %p)", __func__, dev, state);

	return -ENOSYS;
}

static int audio_hw_set_parameters(struct audio_hw_device *dev,
	const char *kvpairs)
{
	LOGD("%s(%p, %s)", __func__, dev, kvpairs);

	return -ENOSYS;
}

static char *audio_hw_get_parameters(const struct audio_hw_device *dev,
	const char *keys)
{
	LOGD("%s(%p, %s)", __func__, dev, keys);

	return NULL;
}

static size_t audio_hw_get_input_buffer_size(const struct audio_hw_device *dev,
	uint32_t sample_rate, int format, int channel_count)
{
	LOGD("%s(%p, %d, %d, %d)", __func__, dev, sample_rate, format, channel_count);

	return 320;
}

static int audio_hw_dump(const audio_hw_device_t *device, int fd)
{
	LOGD("%s(%p, %d)", __func__, device, fd);

	return 0;
}

/*
 * Interface
 */

int audio_hw_close(hw_device_t *device)
{
	LOGD("%s(%p)", __func__, device);

	if(device != NULL)
		free(device);

	return 0;
}

int audio_hw_open(const hw_module_t *module, const char *name,
	hw_device_t **device)
{
	struct tinyalsa_audio_device *tinyalsa_audio_device;
	struct audio_hw_device *dev;

	LOGD("%s(%p, %s, %p)", __func__, module, name, device);

	if(strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
		return -EINVAL;

	tinyalsa_audio_device = calloc(1, sizeof(struct tinyalsa_audio_device));
	if(tinyalsa_audio_device == NULL)
		return -ENOMEM;

	dev = &(tinyalsa_audio_device->device);

	dev->common.tag = HARDWARE_DEVICE_TAG;
	dev->common.version = 0;
	dev->common.module = (struct hw_module_t *) module;
	dev->common.close = audio_hw_close;

	dev->get_supported_devices = audio_hw_get_supported_devices;
	dev->init_check = audio_hw_init_check;
	dev->set_voice_volume = audio_hw_set_voice_volume;
	dev->set_master_volume = audio_hw_set_master_volume;
	dev->set_mode = audio_hw_set_mode;
	dev->set_mic_mute = audio_hw_set_mic_mute;
	dev->get_mic_mute = audio_hw_get_mic_mute;
	dev->set_parameters = audio_hw_set_parameters;
	dev->get_parameters = audio_hw_get_parameters;
	dev->get_input_buffer_size = audio_hw_get_input_buffer_size;

	dev->open_output_stream = audio_hw_open_output_stream;
	dev->close_output_stream = audio_hw_close_output_stream;

	dev->open_input_stream = audio_hw_open_input_stream;
	dev->close_input_stream = audio_hw_close_input_stream;

	dev->dump = audio_hw_dump;

	*device = &(dev->common);

	return 0;
}

struct hw_module_methods_t audio_hw_module_methods = {
	.open = audio_hw_open,
};

struct audio_module HAL_MODULE_INFO_SYM = {
	.common = {
		.tag = HARDWARE_MODULE_TAG,
		.version_major = 1,
		.version_minor = 0,
		.id = AUDIO_HARDWARE_MODULE_ID,
		.name = "TinyALSA-Audio",
		.author = "Paul Kocialkowski",
		.methods = &audio_hw_module_methods,
	},
};