summaryrefslogtreecommitdiffstats
path: root/audio_hw.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio_hw.c')
-rw-r--r--audio_hw.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/audio_hw.c b/audio_hw.c
new file mode 100644
index 0000000..5e18a0b
--- /dev/null
+++ b/audio_hw.c
@@ -0,0 +1,198 @@
+/*
+ * 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"
+
+/*
+ * Output
+ */
+
+#include "audio_out.c"
+
+/*
+ * Input
+ */
+
+#include "audio_in.c"
+
+/*
+ * Functions
+ */
+
+static uint32_t audio_hw_get_supported_devices(const struct audio_hw_device *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)
+{
+ if(dev != NULL)
+ return 0;
+ else
+ return -EINVAL;
+}
+
+static int audio_hw_set_voice_volume(struct audio_hw_device *dev, float volume)
+{
+ return -ENOSYS;
+}
+
+static int audio_hw_set_master_volume(struct audio_hw_device *dev, float volume)
+{
+ return -ENOSYS;
+}
+
+static int audio_hw_set_mode(struct audio_hw_device *dev, int mode)
+{
+ return 0;
+}
+
+static int audio_hw_set_mic_mute(struct audio_hw_device *dev, bool state)
+{
+ return -ENOSYS;
+}
+
+static int audio_hw_get_mic_mute(const struct audio_hw_device *dev, bool *state)
+{
+ return -ENOSYS;
+}
+
+static int audio_hw_set_parameters(struct audio_hw_device *dev,
+ const char *kvpairs)
+{
+ return -ENOSYS;
+}
+
+static char * audio_hw_get_parameters(const struct audio_hw_device *dev,
+ const char *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)
+{
+ return 320;
+}
+
+static int audio_hw_dump(const audio_hw_device_t *device, int fd)
+{
+ return 0;
+}
+
+/*
+ * Interface
+ */
+
+int audio_hw_close(hw_device_t *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;
+
+ 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,
+ },
+};