raphael: Convert amplifier to blueprint

dlopen audio.primary instead of linking against it to avoid soong
namespace hell.

Change-Id: Ic9d420864cb5a6f1018210a84f0f3e6636550caa
This commit is contained in:
Michael Bestas
2025-01-16 10:37:32 +02:00
committed by Joey
parent 980d7febe9
commit bd0b1b7941
3 changed files with 71 additions and 50 deletions

36
tfa98xx/Android.bp Normal file
View File

@@ -0,0 +1,36 @@
//
// SPDX-FileCopyrightText: 2020-2025 The LineageOS Project
// SPDX-License-Identifier: Apache-2.0
//
cc_library_shared {
name: "audio_amplifier.msmnile",
relative_install_path: "hw",
vendor: true,
owner: "qti",
srcs: [
"tfa98xx_feedback.c",
],
include_dirs: [
"external/tinyalsa/include",
"external/tinycompress/include",
"hardware/qcom-caf/sm8150/audio/hal",
"hardware/qcom-caf/sm8150/audio/hal/audio_extn",
"hardware/qcom-caf/sm8150/audio/hal/msm8974",
"system/media/audio_route/include",
"system/media/audio_utils/include",
],
header_libs: [
"libhardware_headers",
"qti_kernel_headers",
],
shared_libs: [
"libdl",
"liblog",
"libtinyalsa",
],
}

View File

@@ -1,42 +0,0 @@
#
# Copyright 2020-2021 The LineageOS 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.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := audio_amplifier.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := tfa98xx_feedback.c
LOCAL_VENDOR_MODULE := true
LOCAL_C_INCLUDES := \
$(call include-path-for, audio-route) \
$(call include-path-for, audio-utils) \
$(call project-path-for, qcom-audio)/hal/audio_extn \
$(call project-path-for, qcom-audio)/hal/msm8974 \
external/tinycompress/include
LOCAL_HEADER_LIBRARIES := \
generated_kernel_headers \
libhardware_headers
LOCAL_SHARED_LIBRARIES := \
audio.primary.$(TARGET_BOARD_PLATFORM) \
liblog \
libtinyalsa
include $(BUILD_SHARED_LIBRARY)

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The CyanogenMod Open Source Project
* Copyright (C) 2020-2021 The LineageOS Project
* Copyright (C) 2020-2025 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,10 @@
#define LOG_TAG "audio_amplifier_tfa98xx"
#include <dlfcn.h>
#include <log/log.h>
#include <system/audio.h>
#include "audio_hw.h"
#include "platform.h"
#include "platform_api.h"
@@ -40,6 +41,12 @@ typedef struct amp_device {
struct audio_device* adev;
struct audio_usecase* usecase_tx;
struct pcm* tfa98xx_out;
typeof(enable_snd_device)* enable_snd_device;
typeof(enable_audio_route)* enable_audio_route;
typeof(disable_snd_device)* disable_snd_device;
typeof(disable_audio_route)* disable_audio_route;
typeof(platform_get_pcm_device_id)* platform_get_pcm_device_id;
typeof(get_usecase_from_list)* get_usecase_from_list;
} tfa_t;
static tfa_t* tfa_dev = NULL;
@@ -84,10 +91,11 @@ static int amp_set_feedback(amplifier_device_t* device, void* adev, uint32_t snd
list_init(&tfa_dev->usecase_tx->device_list);
list_add_head(&tfa_dev->adev->usecase_list, &tfa_dev->usecase_tx->list);
enable_snd_device(tfa_dev->adev, tfa_dev->usecase_tx->in_snd_device);
enable_audio_route(tfa_dev->adev, tfa_dev->usecase_tx);
tfa_dev->enable_snd_device(tfa_dev->adev, tfa_dev->usecase_tx->in_snd_device);
tfa_dev->enable_audio_route(tfa_dev->adev, tfa_dev->usecase_tx);
pcm_dev_tx_id = platform_get_pcm_device_id(tfa_dev->usecase_tx->id, tfa_dev->usecase_tx->type);
pcm_dev_tx_id =
tfa_dev->platform_get_pcm_device_id(tfa_dev->usecase_tx->id, tfa_dev->usecase_tx->type);
ALOGD("pcm_dev_tx_id = %d", pcm_dev_tx_id);
if (pcm_dev_tx_id < 0) {
ALOGE("%d: Invalid pcm device for usecase (%d)", __LINE__, tfa_dev->usecase_tx->id);
@@ -120,12 +128,12 @@ disable:
pcm_close(tfa_dev->tfa98xx_out);
tfa_dev->tfa98xx_out = NULL;
}
tfa_dev->usecase_tx = get_usecase_from_list(tfa_dev->adev, tfa_dev->usecase_tx->id);
tfa_dev->usecase_tx = tfa_dev->get_usecase_from_list(tfa_dev->adev, tfa_dev->usecase_tx->id);
if (tfa_dev->usecase_tx) {
ALOGD("%s: Disabling tfa98xx feedback", __func__);
list_remove(&tfa_dev->usecase_tx->list);
disable_snd_device(tfa_dev->adev, tfa_dev->usecase_tx->in_snd_device);
disable_audio_route(tfa_dev->adev, tfa_dev->usecase_tx);
tfa_dev->disable_snd_device(tfa_dev->adev, tfa_dev->usecase_tx->in_snd_device);
tfa_dev->disable_audio_route(tfa_dev->adev, tfa_dev->usecase_tx);
free(tfa_dev->usecase_tx);
}
return rc;
@@ -158,6 +166,25 @@ static int amp_module_open(const hw_module_t* module, const char* name, hw_devic
tfa_dev->amp_dev.set_feedback = amp_set_feedback;
#define LOAD_AHAL_SYMBOL(symbol) \
do { \
tfa_dev->symbol = dlsym(RTLD_NEXT, #symbol); \
if (tfa_dev->symbol == NULL) { \
ALOGW("%s: %s not found (%s)", __func__, #symbol, dlerror()); \
free(tfa_dev); \
return -ENODEV; \
} \
} while (0)
LOAD_AHAL_SYMBOL(enable_snd_device);
LOAD_AHAL_SYMBOL(enable_audio_route);
LOAD_AHAL_SYMBOL(disable_snd_device);
LOAD_AHAL_SYMBOL(disable_audio_route);
LOAD_AHAL_SYMBOL(platform_get_pcm_device_id);
LOAD_AHAL_SYMBOL(get_usecase_from_list);
#undef LOAD_AHAL_SYMBOL
*device = (hw_device_t*)tfa_dev;
return 0;