summaryrefslogtreecommitdiffstats
path: root/audio_ril_interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio_ril_interface.c')
-rw-r--r--audio_ril_interface.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/audio_ril_interface.c b/audio_ril_interface.c
new file mode 100644
index 0000000..d3a8658
--- /dev/null
+++ b/audio_ril_interface.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * 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 RIL Interface"
+
+#include <stdlib.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <dlfcn.h>
+#include <sys/time.h>
+
+#include <cutils/log.h>
+
+#define EFFECT_UUID_NULL EFFECT_UUID_NULL_RIL
+#define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_RIL
+#include "audio_hw.h"
+
+#include "include/audio_ril_interface.h"
+#include "audio_ril_interface.h"
+
+int audio_ril_interface_set_mic_mute(struct tinyalsa_audio_ril_interface *ril_interface, bool state)
+{
+ int rc;
+
+ if(ril_interface == NULL)
+ return -1;
+
+ LOGD("%s(%d)", __func__, state);
+
+ if(ril_interface->interface->mic_mute == NULL)
+ return -1;
+
+ rc = ril_interface->interface->mic_mute(ril_interface->interface->pdata, (int) state);
+ if(rc < 0) {
+ LOGE("Failed to set RIL interface mic mute");
+ return -1;
+ }
+
+ return 0;
+}
+
+int audio_ril_interface_set_voice_volume(struct tinyalsa_audio_ril_interface *ril_interface,
+ audio_devices_t device, float volume)
+{
+ int rc;
+
+ if(ril_interface == NULL)
+ return -1;
+
+ LOGD("%s(%d, %f)", __func__, device, volume);
+
+ if(ril_interface->interface->voice_volume == NULL)
+ return -1;
+
+ rc = ril_interface->interface->voice_volume(ril_interface->interface->pdata, device, volume);
+ if(rc < 0) {
+ LOGE("Failed to set RIL interface voice volume");
+ return -1;
+ }
+
+ return 0;
+}
+
+int audio_ril_interface_set_route(struct tinyalsa_audio_ril_interface *ril_interface, audio_devices_t device)
+{
+ int rc;
+
+ if(ril_interface == NULL)
+ return -1;
+
+ LOGD("%s(%d)", __func__, device);
+
+ ril_interface->device_current = device;
+
+ if(ril_interface->interface->route == NULL)
+ return -1;
+
+ rc = ril_interface->interface->route(ril_interface->interface->pdata, device);
+ if(rc < 0) {
+ LOGE("Failed to set RIL interface route");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Interface
+ */
+
+void audio_ril_interface_close(struct audio_hw_device *dev,
+ struct tinyalsa_audio_ril_interface *ril_interface)
+{
+ void (*audio_ril_interface_close)(struct audio_ril_interface *interface);
+
+ struct tinyalsa_audio_device *tinyalsa_audio_device;
+
+ LOGD("%s(%p)", __func__, ril_interface);
+
+ if(ril_interface->dl_handle != NULL) {
+ audio_ril_interface_close = (void (*)(struct audio_ril_interface *interface))
+ dlsym(ril_interface->dl_handle, "audio_ril_interface_close");
+
+ if(audio_ril_interface_close == NULL) {
+ LOGE("Unable to get close function from: %s", AUDIO_RIL_INTERFACE_LIB);
+ } else {
+ audio_ril_interface_close(ril_interface->interface);
+ }
+
+ dlclose(ril_interface->dl_handle);
+ ril_interface->dl_handle = NULL;
+ }
+
+ if(ril_interface != NULL)
+ free(ril_interface);
+
+ if(dev == NULL)
+ return;
+
+ tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
+
+ tinyalsa_audio_device->ril_interface = NULL;
+}
+
+int audio_ril_interface_open(struct audio_hw_device *dev, audio_devices_t device,
+ struct tinyalsa_audio_ril_interface **ril_interface)
+{
+ struct audio_ril_interface *(*audio_ril_interface_open)(void);
+
+ struct tinyalsa_audio_device *tinyalsa_audio_device;
+ struct tinyalsa_audio_ril_interface *tinyalsa_audio_ril_interface;
+ struct audio_ril_interface *interface;
+ void *dl_handle;
+ int rc;
+
+ LOGD("%s(%p, %d, %p)", __func__, dev, device, ril_interface);
+
+ if(dev == NULL || ril_interface == NULL)
+ return -EINVAL;
+
+ tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
+ tinyalsa_audio_ril_interface = calloc(1, sizeof(struct tinyalsa_audio_ril_interface));
+
+ if(tinyalsa_audio_ril_interface == NULL)
+ return -ENOMEM;
+
+ tinyalsa_audio_ril_interface->device = tinyalsa_audio_device;
+ tinyalsa_audio_device->ril_interface = tinyalsa_audio_ril_interface;
+
+ dl_handle = dlopen(AUDIO_RIL_INTERFACE_LIB, RTLD_NOW);
+ if(dl_handle == NULL) {
+ LOGE("Unable to dlopen lib: %s", AUDIO_RIL_INTERFACE_LIB);
+ goto error_interface;
+ }
+
+ audio_ril_interface_open = (struct audio_ril_interface *(*)(void))
+ dlsym(dl_handle, "audio_ril_interface_open");
+ if(audio_ril_interface_open == NULL) {
+ LOGE("Unable to get open function from: %s", AUDIO_RIL_INTERFACE_LIB);
+ goto error_interface;
+ }
+
+ interface = audio_ril_interface_open();
+ if(interface == NULL) {
+ LOGE("Unable to open audio ril interface");
+ goto error_interface;
+ }
+
+ tinyalsa_audio_ril_interface->interface = interface;
+ tinyalsa_audio_ril_interface->dl_handle = dl_handle;
+
+ if(device) {
+ tinyalsa_audio_ril_interface->device_current = device;
+ audio_ril_interface_set_route(tinyalsa_audio_ril_interface, device);
+ }
+
+ *ril_interface = tinyalsa_audio_ril_interface;
+
+ return 0;
+
+error_interface:
+ *ril_interface = NULL;
+ free(tinyalsa_audio_ril_interface);
+ tinyalsa_audio_device->ril_interface = NULL;
+
+ if(dl_handle != NULL)
+ dlclose(dl_handle);
+
+ return -1;
+}