summaryrefslogtreecommitdiffstats
path: root/audio_out.c
blob: 2ea2db876bdf3ea10dea9ee3f010416605e6d309 (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
/*
 * 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 Output"

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

#include <cutils/log.h>

#define EFFECT_UUID_NULL EFFECT_UUID_NULL_OUT
#define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_OUT
#include "audio_hw.h"

/*
 * Functions
 */

static uint32_t audio_out_get_sample_rate(const struct audio_stream *stream)
{
	return 44100;
}

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

	return 0;
}

static size_t audio_out_get_buffer_size(const struct audio_stream *stream)
{
	return 4096;
}

static uint32_t audio_out_get_channels(const struct audio_stream *stream)
{
	return AUDIO_CHANNEL_OUT_STEREO;
}

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

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

	return 0;
}

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

	return 0;
}

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

	return 0;
}

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

	return 0;
}

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

	return strdup("");
}

static uint32_t audio_out_get_latency(const struct audio_stream_out *stream)
{
	LOGD("%s(%p)", __func__, stream);

	return 0;
}

static int audio_out_set_volume(struct audio_stream_out *stream, float left,
	float right)
{
	LOGD("%s(%p, %f, %f)", __func__, stream, left, right);

	return 0;
}

static ssize_t audio_out_write(struct audio_stream_out *stream,
	const void *buffer, size_t bytes)
{
	/* XXX: fake timing for audio output */
	usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
		   audio_out_get_sample_rate(&stream->common));
	return bytes;
}

static int audio_out_get_render_position(const struct audio_stream_out *stream,
	uint32_t *dsp_frames)
{
	LOGD("%s(%p, %p)", __func__, stream, dsp_frames);

	return -EINVAL;
}

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

	return 0;
}

static int audio_out_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_output_stream(struct audio_hw_device *dev,
	struct audio_stream_out *stream)
{
	LOGD("%s(%p)", __func__, stream);

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

int audio_hw_open_output_stream(struct audio_hw_device *dev,
	uint32_t devices, int *format, uint32_t *channels, uint32_t *sample_rate,
	struct audio_stream_out **stream_out)
{
	struct tinyalsa_audio_device *tinyalsa_audio_device;
	struct tinyalsa_audio_stream_out *tinyalsa_audio_stream_out;
	struct audio_stream_out *stream;

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

	if(dev == NULL)
		return -EINVAL;

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

	if(tinyalsa_audio_stream_out == NULL)
		return -ENOMEM;

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

	stream->common.get_sample_rate = audio_out_get_sample_rate;
	stream->common.set_sample_rate = audio_out_set_sample_rate;
	stream->common.get_buffer_size = audio_out_get_buffer_size;
	stream->common.get_channels = audio_out_get_channels;
	stream->common.get_format = audio_out_get_format;
	stream->common.set_format = audio_out_set_format;
	stream->common.standby = audio_out_standby;
	stream->common.dump = audio_out_dump;
	stream->common.set_parameters = audio_out_set_parameters;
	stream->common.get_parameters = audio_out_get_parameters;
	stream->common.add_audio_effect = audio_out_add_audio_effect;
	stream->common.remove_audio_effect = audio_out_remove_audio_effect;
	stream->get_latency = audio_out_get_latency;
	stream->set_volume = audio_out_set_volume;
	stream->write = audio_out_write;
	stream->get_render_position = audio_out_get_render_position;

	*stream_out = stream;

	return 0;
}