summaryrefslogtreecommitdiffstats
path: root/audio_in.c
blob: e416de81c6223ac38d2b41f98716e732c139e027 (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
/*
 * 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 "TinyALSA-Audio Input"

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

#include <cutils/log.h>

#define EFFECT_UUID_NULL EFFECT_UUID_NULL_IN
#define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_IN
#include "audio_hw.h"

/*
 * Functions
 */

static uint32_t audio_in_get_sample_rate(const struct audio_stream *stream)
{
	return 8000;
}

static int audio_in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
	LOGD("%s(%p, %d)", __func__, stream, rate);

	return 0;
}

static size_t audio_in_get_buffer_size(const struct audio_stream *stream)
{
	return 320;
}

static uint32_t audio_in_get_channels(const struct audio_stream *stream)
{
	return AUDIO_CHANNEL_IN_MONO;
}

static int audio_in_get_format(const struct audio_stream *stream)
{
	return AUDIO_FORMAT_PCM_16_BIT;
}

static int audio_in_set_format(struct audio_stream *stream, int format)
{
	LOGD("%s(%p, %d)", __func__, stream, format);

	return 0;
}

static int audio_in_standby(struct audio_stream *stream)
{
	LOGD("%s(%p)", __func__, stream);

	return 0;
}

static int audio_in_dump(const struct audio_stream *stream, int fd)
{
	LOGD("%s(%p, %d)", __func__, stream, fd);

	return 0;
}

static int audio_in_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
	LOGD("%s(%p, %s)", __func__, stream, kvpairs);

	return 0;
}

static char *audio_in_get_parameters(const struct audio_stream *stream,
	const char *keys)
{
	LOGD("%s(%p, %s)", __func__, stream, keys);

	return strdup("");
}

static int audio_in_set_gain(struct audio_stream_in *stream, float gain)
{
	LOGD("%s(%p, %f)", __func__, stream, gain);

	return 0;
}

static ssize_t audio_in_read(struct audio_stream_in *stream,
	void *buffer, size_t bytes)
{
	/* XXX: fake timing for audio input */
	usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
		   audio_in_get_sample_rate(&stream->common));
	return bytes;
}

static uint32_t audio_in_get_input_frames_lost(struct audio_stream_in *stream)
{
	LOGD("%s(%p)", __func__, stream);

	return 0;
}

static int audio_in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
	LOGD("%s(%p, %p)", __func__, stream, effect);

	return 0;
}

static int audio_in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
	LOGD("%s(%p, %p)", __func__, stream, effect);

	return 0;
}

/*
 * Interface
 */

void audio_hw_close_input_stream(struct audio_hw_device *dev,
	struct audio_stream_in *stream)
{
	LOGD("%s(%p)", __func__, stream);

	if(stream != NULL)
		free(stream);
}

int audio_hw_open_input_stream(struct audio_hw_device *dev,
	uint32_t devices, int *format, uint32_t *channels, uint32_t *sample_rate,
	audio_in_acoustics_t acoustics, struct audio_stream_in **stream_in)
{
	struct tinyalsa_audio_device *tinyalsa_audio_device;
	struct tinyalsa_audio_stream_in *tinyalsa_audio_stream_in;
	struct audio_stream_in *stream;

	LOGD("%s(%p, %d, %p, %p, %p, %d, %p)",
		__func__, dev, devices, format, channels, sample_rate, acoustics, stream_in);

	if(dev == NULL)
		return -EINVAL;

	tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
	tinyalsa_audio_stream_in = calloc(1, sizeof(struct tinyalsa_audio_stream_in));

	if(tinyalsa_audio_stream_in == NULL)
		return -ENOMEM;

	tinyalsa_audio_stream_in->dev = tinyalsa_audio_device;
	stream = &(tinyalsa_audio_stream_in->stream);

	stream->common.get_sample_rate = audio_in_get_sample_rate;
	stream->common.set_sample_rate = audio_in_set_sample_rate;
	stream->common.get_buffer_size = audio_in_get_buffer_size;
	stream->common.get_channels = audio_in_get_channels;
	stream->common.get_format = audio_in_get_format;
	stream->common.set_format = audio_in_set_format;
	stream->common.standby = audio_in_standby;
	stream->common.dump = audio_in_dump;
	stream->common.set_parameters = audio_in_set_parameters;
	stream->common.get_parameters = audio_in_get_parameters;
	stream->common.add_audio_effect = audio_in_add_audio_effect;
	stream->common.remove_audio_effect = audio_in_remove_audio_effect;
	stream->set_gain = audio_in_set_gain;
	stream->read = audio_in_read;
	stream->get_input_frames_lost = audio_in_get_input_frames_lost;

	*stream_in = stream;

	return 0;
}