audio: Initialize the radio voice session
authorChristopher N. Hesse <raymanfx@gmail.com>
Thu, 2 Feb 2017 19:48:56 +0000 (20:48 +0100)
committerChristopher N. Hesse <raymanfx@gmail.com>
Fri, 10 Feb 2017 20:31:20 +0000 (20:31 +0000)
This just allocates the structre and creates the RIL connection. This is
per audio_device structure to make sure we to not run into issues with
audioserver threading.

Change-Id: I42e1b7ae57579f39c5f76566ef5b67d4e2c13e3f

audio/Android.mk
audio/audio_hw.c
audio/audio_hw.h
audio/voice.c [new file with mode: 0644]
audio/voice.h [new file with mode: 0644]

index 8b3061311913189e28cce621e4d6cac6f87d019b..87266f3b690e36cac64c42933ea58c84a935b0c1 100644 (file)
@@ -23,7 +23,8 @@ LOCAL_ARM_MODE := arm
 LOCAL_SRC_FILES := \
        audio_hw.c \
        compress_offload.c \
-       ril_interface.c
+       ril_interface.c \
+       voice.c
 
 # TODO: remove resampler if possible when AudioFlinger supports downsampling from 48 to 8
 LOCAL_SHARED_LIBRARIES := \
index 59cc0f4c597273738e36926b9537c9580fbe69f5..97acd48fc22c9d691010d31f2a9b19bc9bec5859 100644 (file)
@@ -48,6 +48,7 @@
 #include <audio_effects/effect_ns.h>
 #include "audio_hw.h"
 #include "compress_offload.h"
+#include "voice.h"
 
 #include "sound/compress_params.h"
 
@@ -4184,10 +4185,12 @@ static int adev_dump(const audio_hw_device_t *device, int fd)
 static int adev_close(hw_device_t *device)
 {
     struct audio_device *adev = (struct audio_device *)device;
+    voice_session_deinit(adev->voice.session);
     audio_device_ref_count--;
     free(adev->snd_dev_ref_cnt);
     free_mixer_list(adev);
     free(device);
+
     return 0;
 }
 
@@ -4318,6 +4321,16 @@ static int adev_open(const hw_module_t *module, const char *name,
         }
     }
 
+    adev->voice.session = voice_session_init();
+    if (adev->voice.session == NULL) {
+        ALOGE("%s: Failed to initialize voice session data", __func__);
+
+        free(adev->snd_dev_ref_cnt);
+        free(adev);
+
+        *device = NULL;
+        return -EINVAL;
+    }
 
     *device = &adev->device.common;
 
index ab50ef74e5784ee5644777af7b4c8c5f3c5187a6..96635ecbc4df04c7db7ac6db406735a12d157efe 100644 (file)
@@ -373,6 +373,7 @@ struct voice_data {
     bool  in_call;
     float volume;
     bool  bluetooth_nrec;
+    void  *session;
 };
 
 struct audio_device {
diff --git a/audio/voice.c b/audio/voice.c
new file mode 100644 (file)
index 0000000..57fcc60
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 Christopher N. Hesse <raymanfx@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_hw_voice"
+#define LOG_NDEBUG 0
+/*#define VERY_VERY_VERBOSE_LOGGING*/
+#ifdef VERY_VERY_VERBOSE_LOGGING
+#define ALOGVV ALOGV
+#else
+#define ALOGVV(a...) do { } while(0)
+#endif
+
+#include <stdlib.h>
+#include <pthread.h>
+
+#include "audio_hw.h"
+#include "voice.h"
+
+struct voice_session *voice_session_init(void)
+{
+    struct voice_session *session;
+    int ret;
+
+    session = calloc(1, sizeof(struct voice_session));
+    if (session == NULL) {
+        return NULL;
+    }
+
+    /* Do this as the last step so we do not have to close it on error */
+    ret = ril_open(&session->ril);
+    if (ret != 0) {
+        free(session);
+        return NULL;
+    }
+
+    return session;
+}
+
+void voice_session_deinit(struct voice_session *session)
+{
+    ril_close(&session->ril);
+    free(session);
+}
diff --git a/audio/voice.h b/audio/voice.h
new file mode 100644 (file)
index 0000000..40bd1b1
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 Christopher N. Hesse <raymanfx@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VOICE_CALL_H
+#define VOICE_CALL_H
+
+#include "ril_interface.h"
+
+struct voice_session {
+    struct ril_handle ril;
+
+    struct pcm *pcm_voice_rx;
+    struct pcm *pcm_voice_tx;
+
+    bool wb_amr;
+    bool two_mic_control;
+    bool two_mic_disabled;
+
+    /* from uc_info */
+    audio_devices_t out_device;
+};
+
+struct voice_session *voice_session_init(void);
+void voice_session_deinit(struct voice_session *s);
+
+#endif /* VOICE_CALL_H */