From de056318cf3681419e4f7c41b432eba4bb2e5d75 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Thu, 7 Mar 2013 15:05:46 +0100 Subject: Audio-RIL-Interface Change-Id: Ic395193d5921ab84895763fe48664dc3b9b3978d Signed-off-by: Paul Kocialkowski --- audio-ril-interface/Android.mk | 35 +++ audio-ril-interface/audio-ril-interface.c | 200 +++++++++++++++++ audio/ril_interface.h | 2 +- device.mk | 4 +- samsung-ril-client/Android.mk | 18 -- samsung-ril-client/samsung-ril-client.c | 360 ------------------------------ 6 files changed, 238 insertions(+), 381 deletions(-) create mode 100644 audio-ril-interface/Android.mk create mode 100644 audio-ril-interface/audio-ril-interface.c delete mode 100644 samsung-ril-client/Android.mk delete mode 100644 samsung-ril-client/samsung-ril-client.c diff --git a/audio-ril-interface/Android.mk b/audio-ril-interface/Android.mk new file mode 100644 index 0000000..5848bd6 --- /dev/null +++ b/audio-ril-interface/Android.mk @@ -0,0 +1,35 @@ +# +# Copyright (C) 2013 Paul Kocialkowski +# +# 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 . +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := audio-ril-interface.c + +LOCAL_C_INCLUDES := \ + hardware/ril/samsung-ril/include \ + hardware/ril/samsung-ril/srs-client/include \ + device/samsung/p5100/audio/ + +LOCAL_SHARED_LIBRARIES := liblog libcutils libsrs-client +LOCAL_PRELINK_MODULE := false + +LOCAL_MODULE := libaudio-ril-interface +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) diff --git a/audio-ril-interface/audio-ril-interface.c b/audio-ril-interface/audio-ril-interface.c new file mode 100644 index 0000000..ea53a2d --- /dev/null +++ b/audio-ril-interface/audio-ril-interface.c @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2013 Paul Kocialkowski + * + * 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 . + */ + +#include + +#define LOG_TAG "Audio-RIL-Interface" +#include + +#include + +#include +#include + +void *OpenClient_RILD(void) +{ + struct srs_client *client = NULL; + + LOGE("%s()", __func__); + + signal(SIGPIPE, SIG_IGN); + + srs_client_create(&client); + + return (void *) client; +} + +int Connect_RILD(void *data) +{ + struct srs_client *client; + int rc; + + LOGE("%s(%p)", __func__, data); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + rc = srs_client_open(client); + if (rc < 0) { + LOGE("%s: Failed to open SRS client", __func__); + return RIL_CLIENT_ERR_CONNECT; + } + + rc = srs_client_ping(client); + if (rc < 0) { + LOGE("%s: Failed to ping SRS client", __func__); + return RIL_CLIENT_ERR_UNKNOWN; + } + + return RIL_CLIENT_ERR_SUCCESS; +} + +int Disconnect_RILD(void *data) +{ + struct srs_client *client; + int rc; + + LOGE("%s(%p)", __func__, data); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + rc = srs_client_close(client); + if (rc < 0) { + LOGE("%s: Failed to close SRS client", __func__); + return RIL_CLIENT_ERR_INVAL; + } + + return RIL_CLIENT_ERR_SUCCESS; +} + +int CloseClient_RILD(void *data) +{ + struct srs_client *client; + int rc; + + LOGE("%s(%p)", __func__, data); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + srs_client_destroy(client); + + return RIL_CLIENT_ERR_SUCCESS; +} + +int isConnected_RILD(void *data) +{ + struct srs_client *client; + int rc; + + LOGE("%s(%p)", __func__, data); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + rc = srs_client_ping(client); + if (rc < 0) { + LOGE("%s: Failed to ping SRS client", __func__); + return 0; + } + + return 1; +} + +int SetCallVolume(void *data, enum ril_sound_type type, int level) +{ + struct srs_client *client; + struct srs_snd_call_volume call_volume; + int rc; + + LOGE("%s(%p, %d, %d)", __func__, data, type, level); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + call_volume.type = (enum srs_snd_type) type; + call_volume.volume = level; + + rc = srs_client_send(client, SRS_SND_SET_CALL_VOLUME, &call_volume, sizeof(call_volume)); + if (rc < 0) + return RIL_CLIENT_ERR_UNKNOWN; + + return RIL_CLIENT_ERR_SUCCESS; +} + + +int SetCallAudioPath(void *data, enum ril_audio_path path) +{ + struct srs_client *client; + struct srs_snd_call_audio_path call_audio_path; + int rc; + + LOGE("%s(%p, %d)", __func__, data, path); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + call_audio_path.path = path; + + rc = srs_client_send(client, SRS_SND_SET_CALL_AUDIO_PATH, &call_audio_path, sizeof(call_audio_path)); + if (rc < 0) + return RIL_CLIENT_ERR_UNKNOWN; + + return RIL_CLIENT_ERR_SUCCESS; +} + +int SetCallClockSync(void *data, enum ril_clock_state condition) +{ + struct srs_client *client; + struct srs_snd_call_clock_sync call_clock_sync; + int rc; + + LOGE("%s(%p, %d)", __func__, data, condition); + + if (data == NULL) + return RIL_CLIENT_ERR_INVAL; + + client = (struct srs_client *) data; + + call_clock_sync.sync = condition; + + rc = srs_client_send(client, SRS_SND_SET_CALL_CLOCK_SYNC, &call_clock_sync, sizeof(call_clock_sync)); + if (rc < 0) + return RIL_CLIENT_ERR_UNKNOWN; + + return RIL_CLIENT_ERR_SUCCESS; +} + +int RegisterUnsolicitedHandler(void *data, int command, void *callback) +{ + LOGE("%s(%p, %d, %p)", __func__, data, command, callback); + + return RIL_CLIENT_ERR_SUCCESS; +} diff --git a/audio/ril_interface.h b/audio/ril_interface.h index d4d5792..76e25d8 100755 --- a/audio/ril_interface.h +++ b/audio/ril_interface.h @@ -17,7 +17,7 @@ #ifndef RIL_INTERFACE_H #define RIL_INTERFACE_H -#define RIL_CLIENT_LIBPATH "libsamsung-ril-client.so" +#define RIL_CLIENT_LIBPATH "libaudio-ril-interface.so" #define RIL_CLIENT_ERR_SUCCESS 0 #define RIL_CLIENT_ERR_AGAIN 1 diff --git a/device.mk b/device.mk index 30891d4..a77028b 100644 --- a/device.mk +++ b/device.mk @@ -43,7 +43,8 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ audio.primary.tuna \ audio.a2dp.default \ - libaudioutils + libaudioutils \ + libaudio-ril-interface PRODUCT_PACKAGES += \ tuna_hdcp_keys @@ -85,7 +86,6 @@ PRODUCT_PACKAGES += \ # RIL PRODUCT_PACKAGES += \ libsamsung-ril \ - libsamsung-ril-client \ ipc-modemctrl # Live Wallpapers diff --git a/samsung-ril-client/Android.mk b/samsung-ril-client/Android.mk deleted file mode 100644 index 4132aeb..0000000 --- a/samsung-ril-client/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libsamsung-ril-client -LOCAL_MODULE_TAGS := optional - -LOCAL_SRC_FILES := samsung-ril-client.c - -LOCAL_SHARED_LIBRARIES := liblog libcutils -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES) -LOCAL_C_INCLUDES := $(LOCAL_PATH) -LOCAL_C_INCLUDES += hardware/ril/samsung-ril/include \ - device/samsung/tuna/audio/ - -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) diff --git a/samsung-ril-client/samsung-ril-client.c b/samsung-ril-client/samsung-ril-client.c deleted file mode 100644 index 102af87..0000000 --- a/samsung-ril-client/samsung-ril-client.c +++ /dev/null @@ -1,360 +0,0 @@ -/** - * Samsung RIL Client (Samsung RIL Socket Client-side implementation) - * - * Copyright (C) 2011 Paul Kocialkowski - * - * samsung-ril-client 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. - * - * samsung-ril-client 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 samsung-ril-client. If not, see . - * - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define LOG_TAG "SRS-Client" -#include - -#include -#include - -/* - * Structures - */ - -struct srs_client { - int fd; -}; - -/* - * SRS transport - */ - -int srs_send_message(struct srs_client *client, struct srs_message *message) -{ - struct srs_header header; - void *data; - int client_fd = client->fd; - fd_set fds; - int rc; - - if(client_fd < 0) - return -1; - - header.length = message->data_len + sizeof(header); - header.group = SRS_GROUP(message->command); - header.index = SRS_INDEX(message->command); - - data = malloc(header.length); - memset(data, 0, header.length); - - memcpy(data, &header, sizeof(header)); - memcpy((void *) (data + sizeof(header)), message->data, message->data_len); - - FD_ZERO(&fds); - FD_SET(client_fd, &fds); - - // We can't rely on select RC - select(client_fd + 1, NULL, &fds, NULL, NULL); - - rc = write(client_fd, data, header.length); - - free(data); - - return rc; -} - -int srs_send(struct srs_client *client, unsigned short command, void *data, int data_len) -{ - struct srs_message message; - int rc; - - LOGE("%s", __func__); - - message.command = command; - message.data = data; - message.data_len = data_len; - - rc = srs_send_message(client, &message); - - return rc; -} - -int srs_recv_timed(struct srs_client *client, struct srs_message *message, long sec, long usec) -{ - void *raw_data = malloc(SRS_DATA_MAX_SIZE); - struct srs_header *header; - int rc; - - int client_fd = client->fd; - - if(client_fd < 0) - return -1; - - struct timeval timeout; - fd_set fds; - - FD_ZERO(&fds); - FD_SET(client_fd, &fds); - - timeout.tv_sec = sec; - timeout.tv_usec = usec; - - select(client_fd + 1, &fds, NULL, NULL, &timeout); - - rc = read(client_fd, raw_data, SRS_DATA_MAX_SIZE); - if(rc < sizeof(struct srs_header)) { - return -1; - } - - header = raw_data; - - message->command = SRS_COMMAND(header); - message->data_len = header->length - sizeof(struct srs_header); - message->data = malloc(message->data_len); - - memcpy(message->data, raw_data + sizeof(struct srs_header), message->data_len); - - free(raw_data); - - return 0; -} - -int srs_recv(struct srs_client *client, struct srs_message *message) -{ - return srs_recv_timed(client, message, 0, 0); -} - -int srs_ping(struct srs_client *client) -{ - int caffe_w = SRS_CONTROL_CAFFE; - int caffe_r = 0; - int rc = 0; - - struct srs_message message; - - rc = srs_send(client, SRS_CONTROL_PING, &caffe_w, sizeof(caffe_w)); - - if(rc < 0) { - return -1; - } - - rc = srs_recv_timed(client, &message, 0, 300); - - if(rc < 0) { - return -1; - } - - if(message.data == NULL) - return -1; - - caffe_r = *((int *) message.data); - - if(caffe_r == SRS_CONTROL_CAFFE) { - LOGD("Caffe is ready!"); - rc = 0; - } else { - LOGE("Caffe went wrong!"); - rc = -1; - } - - free(message.data); - return rc; -} - -/* - * Interface - */ - -void *OpenClient_RILD(void) -{ - struct srs_client *client = NULL; - - LOGE("%s", __func__); - - signal(SIGPIPE, SIG_IGN); - - client = calloc(1, sizeof(struct srs_client)); - client->fd = -1; - - return (void *) client; -} - -int Connect_RILD(void *data) -{ - struct srs_client *client = (struct srs_client *) data; - int t = 0; - int fd = -1; - int rc; - - LOGE("%s", __func__); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - -socket_connect: - while(t < 5) { - fd = socket_local_client(SRS_SOCKET_NAME, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); - - if(fd > 0) - break; - - LOGE("Socket creation to RIL failed: trying another time"); - - t++; - usleep(300); - } - - if(fd < 0) { - LOGE("Socket creation to RIL failed too many times"); - return RIL_CLIENT_ERR_CONNECT; - } - - client->fd = fd; - - LOGE("Socket creation done, sending ping"); - - rc = srs_ping(client); - - if(rc < 0) { - LOGE("Ping failed!"); - goto socket_connect; - } else { - LOGD("Ping went alright"); - } - - return RIL_CLIENT_ERR_SUCCESS; -} - -int Disconnect_RILD(void *data) -{ - struct srs_client *client = (struct srs_client *) data; - - LOGE("%s", __func__); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - if(client->fd > 0) - close(client->fd); - - return RIL_CLIENT_ERR_SUCCESS; -} - -int CloseClient_RILD(void *data) -{ - struct srs_client *client = (struct srs_client *) data; - - LOGE("%s", __func__); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - free(client); - - return RIL_CLIENT_ERR_SUCCESS; -} - -int isConnected_RILD(void *data) -{ - struct srs_client *client = (struct srs_client *) data; - int rc; - - LOGE("%s", __func__); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - if(client->fd < 0) - return 0; - - rc = srs_ping(client); - - if(rc < 0) { - LOGE("Ping failed!"); - close(client->fd); - - return 0; - } else { - LOGD("Ping went alright"); - } - - return 1; -} - -int SetCallVolume(void *data, enum ril_sound_type type, int vol_level) -{ - struct srs_client *client = (struct srs_client *) data; - struct srs_snd_call_volume call_volume; - - LOGD("Asking call volume"); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - call_volume.type = (enum srs_snd_type) type; - call_volume.volume = vol_level; - - srs_send(client, SRS_SND_SET_CALL_VOLUME, (void *) &call_volume, sizeof(call_volume)); - - return RIL_CLIENT_ERR_SUCCESS; -} - - -int SetCallAudioPath(void *data, enum ril_audio_path path) -{ - struct srs_client *client = (struct srs_client *) data; - - LOGD("Asking audio path"); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - srs_send(client, SRS_SND_SET_CALL_AUDIO_PATH, (void *) &path, sizeof(enum srs_snd_path)); - - return RIL_CLIENT_ERR_SUCCESS; -} - -int SetCallClockSync(void *data, enum ril_clock_state condition) -{ - struct srs_client *client = (struct srs_client *) data; - unsigned char clock_data = condition; - - LOGD("Asking clock sync"); - - if(client == NULL) - return RIL_CLIENT_ERR_INVAL; - - srs_send(client, SRS_SND_SET_CALL_CLOCK_SYNC, &clock_data, sizeof(data)); - - return RIL_CLIENT_ERR_SUCCESS; -} - -int RegisterUnsolicitedHandler(void *data, int command, void *callback) -{ - LOGD("Unsolicited handler isn't implemented yet!"); - - return RIL_CLIENT_ERR_SUCCESS; -} -- cgit v1.1