346 lines
16 KiB
C++
346 lines
16 KiB
C++
/* Copyright Statement:
|
|
*
|
|
* This software/firmware and related documentation ("MediaTek Software") are
|
|
* protected under relevant copyright laws. The information contained herein is
|
|
* confidential and proprietary to MediaTek Inc. and/or its licensors. Without
|
|
* the prior written permission of MediaTek inc. and/or its licensors, any
|
|
* reproduction, modification, use or disclosure of MediaTek Software, and
|
|
* information contained herein, in whole or in part, shall be strictly
|
|
* prohibited.
|
|
*
|
|
* MediaTek Inc. (C) 2010. All rights reserved.
|
|
*
|
|
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
|
|
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
|
|
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
|
|
* ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
|
|
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
|
|
* NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
|
|
* RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
|
|
* INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
|
|
* TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
|
|
* RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
|
|
* OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
|
|
* SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
|
|
* RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
|
|
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
|
|
* ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
|
|
* RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
|
|
* MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
|
|
* CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
|
|
*
|
|
* The following software/firmware and/or related documentation ("MediaTek
|
|
* Software") have been modified by MediaTek Inc. All revisions are subject to
|
|
* any receiver's applicable license agreements with MediaTek Inc.
|
|
*/
|
|
|
|
#ifndef ANDROID_AUDIO_UTILITY_MTK_H
|
|
#define ANDROID_AUDIO_UTILITY_MTK_H
|
|
|
|
#include <utils/threads.h>
|
|
#include <hardware/audio.h>
|
|
#include <utils/Vector.h>
|
|
#include <system/audio_config.h>
|
|
|
|
//#include <media/AudioParameter.h>
|
|
//#include "../../../../protect-bsp/frameworks/av/media/libeffects/loudness/MtkEffectLoudness.h"
|
|
static const effect_uuid_t SL_IID_MTKLOUDNESS_ = { 0x1486d4c0, 0x8757, 0x11e0, 0xb091, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
|
|
const effect_uuid_t * const SL_IID_MTKLOUDNESS = &SL_IID_MTKLOUDNESS_;
|
|
|
|
namespace android {
|
|
|
|
class AudioDump
|
|
{
|
|
public:
|
|
enum PROP_AUDIO_DUMP {
|
|
PROP_AUDIO_DUMP_WRITER = 0,
|
|
PROP_AUDIO_DUMP_TRACK,
|
|
PROP_AUDIO_DUMP_OFFLOAD,
|
|
PROP_AUDIO_DUMP_RESAMPLER,
|
|
PROP_AUDIO_DUMP_MIXER,
|
|
PROP_AUDIO_DUMP_RECORD,
|
|
PROP_AUDIO_DUMP_EFFECT,
|
|
PROP_AUDIO_DUMP_DRC,
|
|
PROP_AUDIO_DUMP_LOG,
|
|
PROP_AUDIO_DUMP_AAUDIO,
|
|
PROP_AUDIO_DUMP_MAXNUM
|
|
};
|
|
static void dump(const char * path, void * buffer, int count);
|
|
static void threadDump(const char * path, void * buffer, int count, audio_format_t format,
|
|
uint32_t sampleRate, uint32_t channelCount);
|
|
static bool getProperty(AudioDump::PROP_AUDIO_DUMP index);
|
|
static bool getPropertyLegacy(AudioDump::PROP_AUDIO_DUMP index);
|
|
static int checkPath(const char * path);
|
|
static unsigned long getDumpSize(const char * path);
|
|
static void updateKeys(int key);
|
|
static void updateKeysLegacy(int key);
|
|
static bool checkIfNeedToDump(audio_format_t format);
|
|
|
|
// For audio dump debug
|
|
static const char * const keyAudioDumpWriter;
|
|
static const char * const keyAudioDumpTrack;
|
|
static const char * const keyAudioDumpOffload;
|
|
static const char * const keyAudioDumpResampler;
|
|
static const char * const keyAudioDumpMixer;
|
|
static const char * const keyAudioDumpRecord;
|
|
static const char * const keyAudioDumpEffect;
|
|
static const char * const keyAudioDumpDrc;
|
|
static const char * const keyAudioDumpLog;
|
|
static const char * const keyAudioDumpAAudio;
|
|
|
|
static const char *audioDumpPropertyStr[];
|
|
|
|
static const char * const keyAudioDumpLegacyWriter;
|
|
static const char * const keyAudioDumpLegacyTrack;
|
|
static const char * const keyAudioDumpLegacyOffload;
|
|
static const char * const keyAudioDumpLegacyResampler;
|
|
static const char * const keyAudioDumpLegacyMixer;
|
|
static const char * const keyAudioDumpLegacyRecord;
|
|
static const char * const keyAudioDumpLegacyEffect;
|
|
static const char * const keyAudioDumpLegacyDrc;
|
|
static const char * const keyAudioDumpLegacyLog;
|
|
static const char * const keyAudioDumpLegacyAAudio;
|
|
|
|
static const char *audioDumpLegacyPropertyStr[];
|
|
|
|
private:
|
|
static void pushBufferInfo(const char * path, void * buffer, int count,
|
|
audio_format_t format, uint32_t sampleRate, uint32_t channelCount);
|
|
|
|
private:
|
|
AudioDump(AudioDump &);
|
|
AudioDump & operator =(AudioDump&);
|
|
};
|
|
|
|
class HwFSync{
|
|
public:
|
|
HwFSync();
|
|
~HwFSync();
|
|
void setFsync();
|
|
bool underflow();
|
|
void reset();
|
|
static void callback(int signal);
|
|
private:
|
|
HwFSync(HwFSync &);
|
|
HwFSync & operator = (HwFSync&);
|
|
int mFd;
|
|
struct sigaction action;
|
|
static bool mUnderflow;
|
|
};
|
|
|
|
class FeatureOption
|
|
{
|
|
public:
|
|
static void getValues();
|
|
static void getBleValues();
|
|
|
|
static bool MTK_AUDIOMIXER_ENABLE_DRC;
|
|
static int MTK_ENABLE_STEREO_SPEAKER;
|
|
static bool MTK_USB_PHONECALL;
|
|
static bool MTK_TTY_SUPPORT;
|
|
static bool MTK_HIFIAUDIO_SUPPORT;
|
|
static bool MTK_BESLOUDNESS_ENABLE;
|
|
static bool MTK_AUDIO_GAIN_TABLE;
|
|
static bool MTK_AUDIO_GAIN_NVRAM ;
|
|
static bool MTK_FM_ENABLE ;
|
|
static bool MTK_AURISYS_FRAMEWORK_SUPPORT;
|
|
static bool MTK_BT_HEARING_AID_SUPPORT;
|
|
static bool MTK_BT_HEARING_AID_USING_AOSP_FMW;
|
|
static bool MTK_TC10_FEATURE;
|
|
static bool MTK_TC10_IN_HOUSE;
|
|
static bool MTK_AUDIO_A2DP_LATENCY_IMPROVE;
|
|
static bool MTK_MUSIC_ROUTE_TO_BTSCO_DURING_BTSCO_ON;
|
|
static bool MTK_BLE_PHONECALL;
|
|
static bool MTK_CRS_FEATURE;
|
|
static bool MTK_USING_VENDOR_S;
|
|
static bool MTK_USING_VENDOR_T;
|
|
static bool MTK_SPATIALIZER_SUPPORT_STEREO;
|
|
static bool MTK_MBRAIN_MODE;
|
|
static bool MTK_SPATIALIZER_LATENCY_LOG;
|
|
|
|
private:
|
|
static const char * const foName_MTK_BESLOUDNESS_RUN_WITH_HAL;
|
|
static const char * const foName_MTK_BESLOUDNESS_SUPPORT;
|
|
static const char * const foName_MTK_AUDIO_NUMBER_OF_SPEAKER;
|
|
static const char * const foName_MTK_AUDIO_HIERARCHICAL_PARAM_SUPPORT;
|
|
static const char * const foName_MTK_AUDIO_FM_DRIVER_DISABLE;
|
|
static const char * const foName_MTK_HIFIAUDIO_SUPPORT;
|
|
static const char * const foName_MTK_AURISYS_FRAMEWORK_SUPPORT;
|
|
static const char * const foName_MTK_USB_PHONECALL;
|
|
static const char * const foName_MTK_TTY_SUPPORT;
|
|
static const char * const foName_MTK_BT_HEARING_AID_SUPPORT;
|
|
static const char * const foName_MTK_BT_HEARING_AID_USING_AOSP_FMW;
|
|
static const char * const foName_MTK_TC10_FEATURE;
|
|
static const char * const foName_MTK_TC10_IN_HOUSE;
|
|
static const char * const foName_MTK_AUDIO_A2DP_LATENCY_IMPROVE;
|
|
static const char * const foName_MTK_MUSIC_ROUTE_TO_BTSCO_DURING_BTSCO_ON;
|
|
static const char * const foName_MTK_BLE_PHONECALL;
|
|
};
|
|
|
|
//MTK80721 FIX CR: ALPS00355888
|
|
extern "C"{
|
|
void setCPU_MIN_Freq(const char *pfreq);
|
|
}
|
|
|
|
class AudioUtilThread : public Thread {
|
|
public:
|
|
enum BATTERY_EVENT {
|
|
BATTERY_NOTE_START_AUDIO = 0,
|
|
BATTERY_NOTE_STOP_AUDIO
|
|
};
|
|
|
|
AudioUtilThread() {}
|
|
virtual ~AudioUtilThread() {}
|
|
|
|
void exit();
|
|
|
|
void BatteryStateRegister(BATTERY_EVENT event, uint32_t uid);
|
|
void BatteryStateNotify();
|
|
|
|
private:
|
|
typedef struct BatteryNote {
|
|
BATTERY_EVENT event;
|
|
uint32_t uid;
|
|
} BatteryNote;
|
|
|
|
virtual bool threadLoop();
|
|
|
|
Mutex mLock;
|
|
Condition mWaitWorkCV;
|
|
|
|
Mutex mBatteryStateVectorLock;
|
|
Vector<AudioUtilThread::BatteryNote> mBatteryStateVector;
|
|
};
|
|
|
|
|
|
#define MTK_LEAUDIO_MODE_OFF "off"
|
|
#define MTK_LEAUDIO_MODE_UMS "ums"
|
|
#define MTK_LEAUDIO_MODE_CGUMS "ums-cg"
|
|
|
|
static inline std::string MTK_audio_get_audio_policy_config_file() {
|
|
static constexpr const char *apmXmlConfigFileName = "audio_policy_configuration.xml";
|
|
static constexpr const char *apmA2dpOffloadDisabledXmlConfigFileName =
|
|
"audio_policy_configuration_a2dp_offload_disabled.xml";
|
|
static constexpr const char *apmBluetoothLegacyHalXmlConfigFileName =
|
|
"audio_policy_configuration_bluetooth_legacy_hal.xml";
|
|
static constexpr const char *apmA2dpOffloadDisabledCgEnabledXmlConfigFileName =
|
|
"audio_policy_configuration_a2dp_offload_disabled_cg_enabled.xml";
|
|
static constexpr const char *apmA2dpOffloadEnableCgEnabledXmlConfigFileName =
|
|
"audio_policy_configuration_a2dp_offload_enable_cg_enable.xml";
|
|
static constexpr const char *apmA2dpOffloadDisabledCgEnabledBmsEnableXmlConfigFileName =
|
|
"audio_policy_configuration_a2dp_offload_disabled_cg_enabled_bms_enable.xml";
|
|
static constexpr const char *apmA2dpOffloadEnableCgEnabledBmsEnableXmlConfigFileName =
|
|
"audio_policy_configuration_a2dp_offload_enable_cg_enable_bms_enable.xml";
|
|
std::string audioPolicyXmlConfigFile;
|
|
char bluetooth_le_mode[PROPERTY_VALUE_MAX] = { 0 };
|
|
property_get("persist.vendor.bluetooth.leaudio_mode", bluetooth_le_mode, MTK_LEAUDIO_MODE_OFF);
|
|
ALOGD("%s bluetooth_le_mode %s, a2dp offload enabled %d", __func__, bluetooth_le_mode, !property_get_bool("persist.bluetooth.a2dp_offload.disabled", false));
|
|
//support BMS for S vendor project
|
|
int API_LEVEL = property_get_int32("ro.vndk.version", 0);
|
|
bool vendor_s = (API_LEVEL == __ANDROID_API_S__);
|
|
// First try alternative files if needed
|
|
if (property_get_bool("ro.bluetooth.a2dp_offload.supported", false)) {
|
|
ALOGD("%s ro.bluetooth.a2dp_offload.supported true", __func__);
|
|
if (property_get_bool("persist.bluetooth.bluetooth_audio_hal.disabled", false) &&
|
|
property_get_bool("persist.bluetooth.a2dp_offload.disabled", false)) {
|
|
// Both BluetoothAudio@2.0 and BluetoothA2dp@1.0 (Offload) are disabled, and uses
|
|
// the legacy hardware module for A2DP and hearing aid.
|
|
//not support cg/ums when using legacy bluetooth legacy hal
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmBluetoothLegacyHalXmlConfigFileName);
|
|
ALOGD("%s %d %s", __func__, __LINE__, apmBluetoothLegacyHalXmlConfigFileName);
|
|
} else if (!property_get_bool("persist.bluetooth.a2dp_offload.disabled", false)) {
|
|
// A2DP offload enabled
|
|
ALOGD("%s %d a2dp offload enabled",__func__, __LINE__);
|
|
if(strncmp(bluetooth_le_mode, MTK_LEAUDIO_MODE_CGUMS, strlen(MTK_LEAUDIO_MODE_CGUMS)) == 0) {
|
|
//support BMS for S vendor project
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadEnableCgEnabledBmsEnableXmlConfigFileName);
|
|
if (vendor_s && (!audioPolicyXmlConfigFile.empty())) {
|
|
ALOGD("%s %d a2dp offload, cg-ums offload, BMS for S vendor %s ", __func__, __LINE__,
|
|
apmA2dpOffloadEnableCgEnabledBmsEnableXmlConfigFileName);
|
|
} else {
|
|
//a2dp offload, ums-cg mode.
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadEnableCgEnabledXmlConfigFileName);
|
|
ALOGD("%s %d a2dp offload, cg-ums offload %s ", __func__, __LINE__,
|
|
apmA2dpOffloadEnableCgEnabledXmlConfigFileName);
|
|
}
|
|
} else {
|
|
//a2dp non offload, ums non offload
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmXmlConfigFileName);
|
|
ALOGD("%s %d a2dp non-offload, ums non offload %s", __func__, __LINE__, apmXmlConfigFileName);
|
|
}
|
|
} else if (property_get_bool("persist.bluetooth.a2dp_offload.disabled", false)) {
|
|
ALOGD("%s %d a2dp offload disable",__func__, __LINE__);
|
|
if(strncmp(bluetooth_le_mode, MTK_LEAUDIO_MODE_CGUMS, strlen(MTK_LEAUDIO_MODE_CGUMS)) == 0) {
|
|
//support BMS for S vendor project
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledCgEnabledBmsEnableXmlConfigFileName);
|
|
if (vendor_s && (!audioPolicyXmlConfigFile.empty())) {
|
|
ALOGD("%s %d a2dp non offload , cg-ums offload , BMS for S vendor %s ", __func__, __LINE__,
|
|
apmA2dpOffloadDisabledCgEnabledBmsEnableXmlConfigFileName);
|
|
} else {
|
|
//a2dp non offload, ums-cg mode.
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledCgEnabledXmlConfigFileName);
|
|
ALOGD("%s %d a2dp non offload , cg-ums offload %s ", __func__, __LINE__,
|
|
apmA2dpOffloadDisabledCgEnabledXmlConfigFileName);
|
|
}
|
|
} else {
|
|
//a2dp non offload, ums non offload
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledXmlConfigFileName);
|
|
ALOGD("%s %d a2dp non-offload, ums non offload %s", __func__, __LINE__,
|
|
apmA2dpOffloadDisabledXmlConfigFileName);
|
|
}
|
|
}
|
|
} else if (property_get_bool("persist.bluetooth.bluetooth_audio_hal.disabled", false)) { //ro.bluetooth.a2dp_offload.supported == ture
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmBluetoothLegacyHalXmlConfigFileName);
|
|
ALOGD("%s %d %s", __func__, __LINE__, apmBluetoothLegacyHalXmlConfigFileName);
|
|
} else {
|
|
// disable a2dp offload
|
|
ALOGD("%s %d disable a2dp offload", __func__, __LINE__);
|
|
if(strncmp(bluetooth_le_mode, MTK_LEAUDIO_MODE_CGUMS, strlen(MTK_LEAUDIO_MODE_CGUMS)) == 0) {
|
|
//support BMS for S vendor project
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledCgEnabledBmsEnableXmlConfigFileName);
|
|
if (vendor_s && (!audioPolicyXmlConfigFile.empty())) {
|
|
ALOGD("%s %d a2dp non offload, ums offload, cg offload, BMS for S vendor %s", __func__, __LINE__,
|
|
apmA2dpOffloadDisabledCgEnabledBmsEnableXmlConfigFileName);
|
|
} else {
|
|
// a2dp offload disable and cg enable
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledCgEnabledXmlConfigFileName);
|
|
ALOGD("%s %d a2dp non offload, ums offload, cg offload %s", __func__, __LINE__,
|
|
apmA2dpOffloadDisabledCgEnabledXmlConfigFileName);
|
|
}
|
|
} else if (strncmp(bluetooth_le_mode, MTK_LEAUDIO_MODE_UMS, strlen(MTK_LEAUDIO_MODE_UMS)) == 0) {
|
|
audioPolicyXmlConfigFile = audio_find_readable_configuration_file(
|
|
apmA2dpOffloadDisabledXmlConfigFileName);
|
|
ALOGD("%s %d a2dp non offloadb, ums non offload %s ", __func__, __LINE__, apmA2dpOffloadDisabledXmlConfigFileName);
|
|
}
|
|
}
|
|
|
|
ALOGD_IF(audioPolicyXmlConfigFile.empty()," %s, %d, a2dp offload, ums non-offload, use %s", __func__,__LINE__,apmXmlConfigFileName);
|
|
return audioPolicyXmlConfigFile.empty() ?
|
|
audio_find_readable_configuration_file(apmXmlConfigFileName) : audioPolicyXmlConfigFile;
|
|
}
|
|
|
|
// ALPS07884508: ultra game mode
|
|
void initWhiteList();
|
|
bool checkWhiteList(const char* scenarioName, const char* packageName);
|
|
static inline bool audio_is_channel_mask_stereo_spatialized(audio_channel_mask_t channelMask) {
|
|
return audio_channel_mask_get_representation(channelMask)
|
|
== AUDIO_CHANNEL_REPRESENTATION_POSITION
|
|
&& (channelMask & AUDIO_CHANNEL_OUT_STEREO) == AUDIO_CHANNEL_OUT_STEREO;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|