Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b6513f8 authored by Jitendra Naruka's avatar Jitendra Naruka Committed by Alexy Joseph
Browse files

hardware/qcom/audio: Integrate Eagle framework for HeadphoneX



Add support to integrate the Eagle framework for HeadphoneX
audio post processing feature 1.1

Change-Id: Ib119c27c359950a6087d5e6ae200dfc1e83b7551
Signed-off-by: default avatarJitendra Naruka <jitendra.naruka@dts.com>
Signed-off-by: default avatarAlexy Joseph <alexyj@codeaurora.org>
parent a8646d9d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -125,6 +125,11 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_COMPRESS_CAPTURE)),true)
    LOCAL_SRC_FILES += audio_extn/compress_capture.c
endif

ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DTS_EAGLE)),true)
    LOCAL_CFLAGS += -DDTS_EAGLE
    LOCAL_SRC_FILES += audio_extn/dts_eagle.c
endif

ifeq ($(strip $(DOLBY_DDP)),true)
    LOCAL_CFLAGS += -DDS1_DOLBY_DDP_ENABLED
    LOCAL_SRC_FILES += audio_extn/dolby.c
+130 −0
Original line number Diff line number Diff line
/*Copyright (C) 2014 The Android Open Source Project
*
* 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.
* This file was modified by DTS, Inc. The portions of the
* code modified by DTS, Inc are copyrighted and
* licensed separately, as follows:
*
*  (C) 2014 DTS, Inc.
*
* 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 "AudioUtil"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <stdlib.h>

#include <cutils/properties.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sound/devdep_params.h>
#include <sound/asound.h>
#include "AudioUtil.h"

#define ROUTE_PATH    "/data/data/dts/route"
#define DEVICE_NODE   "/dev/snd/hwC0D3"

static int32_t mDevices = 0;
static int32_t mCurrDevice = 0;

void create_route_node(void)
{
    char prop[PROPERTY_VALUE_MAX] = "true";
    int fd;
    property_get("use.dts_eagle", prop, "0");
    if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) {
        ALOGV("create_route_node");
        if ((fd=open(ROUTE_PATH, O_RDONLY)) < 0) {
            ALOGV("No File exisit");
        } else {
            ALOGV("A file with the same name exist. Remove it before creating it");
            close(fd);
            remove(ROUTE_PATH);
        }
        if ((fd=creat(ROUTE_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
            ALOGE("opening route node failed returned");
            return;
        }
        chmod(ROUTE_PATH, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH);
        ALOGV("opening route  node successful");
        close(fd);
    }
}

void notify_route_node(int active_device, int devices)
{
    char prop[PROPERTY_VALUE_MAX] = "true";
    char buf[1024];
    int fd;
    if ((mCurrDevice == active_device) &&
        (mDevices == devices)) {
        ALOGV("nothing to update to route node");
        return;
    }
    mDevices = devices;
    mCurrDevice = active_device;
    property_get("use.dts_eagle", prop, "0");
    if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) {
        ALOGV("notify active device : %d all_devices : %d", active_device, devices);
        if ((fd=open(ROUTE_PATH, O_TRUNC|O_WRONLY)) < 0) {
            ALOGV("Write device to route node failed");
        } else {
            ALOGV("Write device to route node successful");
            snprintf(buf, sizeof(buf), "device=%d;all_devices=%d", active_device, devices);
            int n = write(fd, buf, strlen(buf));
            ALOGV("number of bytes written: %d", n);
            close(fd);
        }
        int eaglefd = open(DEVICE_NODE, O_RDWR);
        int32_t params[2] = {active_device, 1 /*is primary device*/};
        if (eaglefd > 0) {
            if(ioctl(eaglefd, DTS_EAGLE_IOCTL_SET_ACTIVE_DEVICE, &params) < 0) {
                ALOGE("DTS_EAGLE (%s): error sending primary device\n", __func__);
            }
            ALOGD("DTS_EAGLE (%s): sent primary device\n", __func__);
            close(eaglefd);
        } else {
            ALOGE("DTS_EAGLE (%s): error opening eagle\n", __func__);
        }
    }
}

void remove_route_node(void)
{
    char prop[PROPERTY_VALUE_MAX] = "true";
    int fd;
    property_get("use.dts_eagle", prop, "0");
    if (!strncmp("true", prop, sizeof("true")) || atoi(prop)) {
        ALOGV("remove_route_node");
        if ((fd=open(ROUTE_PATH, O_RDONLY)) < 0) {
            ALOGV("open route  node failed");
        } else {
            ALOGV("open route node successful");
            ALOGV("Remove the file");
            close(fd);
            remove(ROUTE_PATH);
        }
    }
}
+46 −0
Original line number Diff line number Diff line
/*Copyright (C) 2014 The Android Open Source Project
*
* 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.
* This file was modified by DTS, Inc. The portions of the
* code modified by DTS, Inc are copyrighted and
* licensed separately, as follows:
*
*  (C) 2014 DTS, Inc.
*
* 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 AUDIO_UTIL_H_
#define AUDIO_UTIL_H_

#ifndef DTS_EAGLE
#define create_route_node() (0)
#define notify_route_node(active_device, devices) (0)
#define remove_route_node() (0)
#else
void create_route_node(void);
void notify_route_node(int active_device, int devices);
void remove_route_node(void);
#endif

#endif  //AUDIO_UTIL_H_
+75 −0
Original line number Diff line number Diff line
@@ -15,6 +15,24 @@
 * 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.
 *
 * This file was modified by DTS, Inc. The portions of the
 * code modified by DTS, Inc are copyrighted and
 * licensed separately, as follows:
 *
 * (C) 2014 DTS, Inc.
 *
 * 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_extn"
@@ -40,6 +58,7 @@ struct audio_extn_module {
    bool aanc_enabled;
    bool custom_stereo_enabled;
    uint32_t proxy_channel_num;
    bool hpx_enabled;
};

static struct audio_extn_module aextnmod = {
@@ -47,6 +66,7 @@ static struct audio_extn_module aextnmod = {
    .aanc_enabled = 0,
    .custom_stereo_enabled = 0,
    .proxy_channel_num = 2,
    .hpx_enabled = 0,
};

#define AUDIO_PARAMETER_KEY_ANC        "anc_enabled"
@@ -55,6 +75,7 @@ static struct audio_extn_module aextnmod = {
#define AUDIO_PARAMETER_CUSTOM_STEREO  "stereo_as_dual_mono"
/* Query offload playback instances count */
#define AUDIO_PARAMETER_OFFLOAD_NUM_ACTIVE "offload_num_active"
#define AUDIO_PARAMETER_HPX            "HPX"

#ifndef FM_ENABLED
#define audio_extn_fm_set_parameters(adev, parms) (0)
@@ -108,6 +129,57 @@ void audio_extn_customstereo_set_parameters(struct audio_device *adev,
}
#endif /* CUSTOM_STEREO_ENABLED */

#ifndef DTS_EAGLE
#define audio_extn_hpx_set_parameters(adev, parms)         (0)
#define audio_extn_check_and_set_dts_hpx_state(adev)       (0)
#else
void audio_extn_hpx_set_parameters(struct audio_device *adev,
                                   struct str_parms *parms)
{
    int ret = 0;
    char value[32]={0};
    char prop[PROPERTY_VALUE_MAX] = "false";
    bool hpx_state = false;
    const char *mixer_ctl_name = "Set HPX OnOff";
    struct mixer_ctl *ctl = NULL;
    ALOGV("%s", __func__);

    property_get("use.dts_eagle", prop, "0");
    if (strncmp("true", prop, sizeof("true")))
        return;

    ret = str_parms_get_str(parms, AUDIO_PARAMETER_HPX, value,
                            sizeof(value));
    if (ret >= 0) {
        if (!strncmp("ON", value, sizeof("ON")))
            hpx_state = true;

        if (hpx_state == aextnmod.hpx_enabled)
            return;

        aextnmod.hpx_enabled = hpx_state;
        /* set HPX state on stream pp */
        if (adev->offload_effects_set_hpx_state != NULL)
            adev->offload_effects_set_hpx_state(hpx_state);

        /* set HPX state on device pp */
        ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
        if (ctl)
            mixer_ctl_set_value(ctl, 0, aextnmod.hpx_enabled);
    }
}

void audio_extn_check_and_set_dts_hpx_state(const struct audio_device *adev)
{
    char prop[PROPERTY_VALUE_MAX];
    property_get("use.dts_eagle", prop, "0");
    if (strncmp("true", prop, sizeof("true")))
        return;
    if (adev->offload_effects_set_hpx_state)
        adev->offload_effects_set_hpx_state(aextnmod.hpx_enabled);
}
#endif

#ifndef ANC_HEADSET_ENABLED
#define audio_extn_set_anc_parameters(adev, parms)       (0)
#else
@@ -437,9 +509,11 @@ void audio_extn_set_parameters(struct audio_device *adev,
   audio_extn_sound_trigger_set_parameters(adev, parms);
   audio_extn_listen_set_parameters(adev, parms);
   audio_extn_hfp_set_parameters(adev, parms);
   audio_extn_dts_eagle_set_parameters(adev, parms);
   audio_extn_ddp_set_parameters(adev, parms);
   audio_extn_ds2_set_parameters(adev, parms);
   audio_extn_customstereo_set_parameters(adev, parms);
   audio_extn_hpx_set_parameters(adev, parms);
}

void audio_extn_get_parameters(const struct audio_device *adev,
@@ -450,6 +524,7 @@ void audio_extn_get_parameters(const struct audio_device *adev,
    audio_extn_get_afe_proxy_parameters(query, reply);
    audio_extn_get_fluence_parameters(adev, query, reply);
    get_active_offload_usecases(adev, query, reply);
    audio_extn_dts_eagle_get_parameters(adev, query, reply);

    kv_pairs = str_parms_to_str(reply);
    ALOGD_IF(kv_pairs != NULL, "%s: returns %s", __func__, kv_pairs);
+40 −0
Original line number Diff line number Diff line
@@ -15,6 +15,24 @@
 * 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.
 *
 * This file was modified by DTS, Inc. The portions of the
 * code modified by DTS, Inc are copyrighted and
 * licensed separately, as follows:
 *
 * (C) 2014 DTS, Inc.
 *
 * 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 AUDIO_EXTN_H
@@ -251,6 +269,28 @@ size_t audio_extn_compr_cap_read(struct stream_in *in,
void audio_extn_compr_cap_deinit();
#endif

#ifndef DTS_EAGLE
#define audio_extn_dts_eagle_set_parameters(adev, parms)     (0)
#define audio_extn_dts_eagle_get_parameters(adev, query, reply) (0)
#define audio_extn_dts_eagle_fade(adev, fade_in) (0)
#define audio_extn_dts_create_state_notifier_node(stream_out) (0)
#define audio_extn_dts_notify_playback_state(stream_out, has_video, sample_rate, \
                                    channels, is_playing) (0)
#define audio_extn_dts_remove_state_notifier_node(stream_out) (0)
#define audio_extn_check_and_set_dts_hpx_state(adev)       (0)
#else
void audio_extn_dts_eagle_set_parameters(struct audio_device *adev,
                                         struct str_parms *parms);
int audio_extn_dts_eagle_get_parameters(const struct audio_device *adev,
                  struct str_parms *query, struct str_parms *reply);
int audio_extn_dts_eagle_fade(const struct audio_device *adev, bool fade_in);
void audio_extn_dts_create_state_notifier_node(int stream_out);
void audio_extn_dts_notify_playback_state(int stream_out, int has_video, int sample_rate,
                                  int channels, int is_playing);
void audio_extn_dts_remove_state_notifier_node(int stream_out);
void audio_extn_check_and_set_dts_hpx_state(const struct audio_device *adev);
#endif

#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
void audio_extn_dolby_set_dmid(struct audio_device *adev);
#else
Loading