replace common qcom sources with samsung ones

This commit is contained in:
SaschaNes
2025-08-12 22:13:00 +02:00
parent ba24dcded9
commit 6f7753de11
5682 changed files with 2450203 additions and 103634 deletions

View File

@@ -0,0 +1,366 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
*
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef _BLUETOOTH_H_
#define _BLUETOOTH_H_
#include "Device.h"
#include <tinyalsa/asoundlib.h>
#include <bt_intf.h>
#include <bt_ble.h>
#include <vector>
#include <mutex>
#include <system/audio.h>
#include "Session.h"
#include "SecProductFeature_BLUETOOTH.h"
#define DISALLOW_COPY_AND_ASSIGN(name) \
name(const name &); \
name &operator=(const name &)
enum A2DP_STATE {
A2DP_STATE_CONNECTED,
A2DP_STATE_STARTED,
A2DP_STATE_STOPPED,
A2DP_STATE_DISCONNECTED,
};
#define SPEECH_MODE_INVALID 0xFFFF
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
#define BINAURAL_RECORDING_LATENCY 185
#define BT_MIX_LATENCY 185
#endif
enum A2DP_ROLE {
SOURCE = 0,
SINK,
};
#define TO_AIR 0
#define FROM_AIR 1
enum streamMapDir {
STREAM_MAP_IN = 1 << 0,
STREAM_MAP_OUT = 1 << 1,
};
typedef enum {
SESSION_UNKNOWN,
/** A2DP legacy that AVDTP media is encoded by Bluetooth Stack */
A2DP_SOFTWARE_ENCODING_DATAPATH,
/** The encoding of AVDTP media is done by HW and there is control only */
A2DP_HARDWARE_OFFLOAD_DATAPATH,
/** Used when encoded by Bluetooth Stack and streaming to Hearing Aid */
HEARING_AID_SOFTWARE_ENCODING_DATAPATH,
/** Used when encoded by Bluetooth Stack and streaming to LE Audio device */
LE_AUDIO_SOFTWARE_ENCODING_DATAPATH,
/** Used when decoded by Bluetooth Stack and streaming to audio framework */
LE_AUDIO_SOFTWARE_DECODED_DATAPATH,
/** Encoding is done by HW an there is control only */
LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH,
/** Decoding is done by HW an there is control only */
LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH,
/** SW Encoding for LE Audio Broadcast */
LE_AUDIO_BROADCAST_SOFTWARE_ENCODING_DATAPATH,
/** HW Encoding for LE Audio Broadcast */
LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH,
}tSESSION_TYPE;
typedef enum {
CTRL_ACK_SUCCESS,
CTRL_ACK_UNSUPPORTED,
CTRL_ACK_FAILURE,
CTRL_ACK_PENDING,
CTRL_ACK_INCALL_FAILURE,
CTRL_ACK_DISCONNECT_IN_PROGRESS,
CTRL_SKT_DISCONNECTED,
CTRL_ACK_UNKNOWN,
CTRL_ACK_RECONFIGURATION,
};
typedef void (*bt_audio_pre_init_t)(void);
typedef int (*audio_source_open_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_source_close_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_source_start_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_source_stop_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_source_suspend_api_t)(tSESSION_TYPE session_type);
typedef void (*audio_source_handoff_triggered_t)(void);
typedef void (*clear_source_a2dpsuspend_flag_t)(void);
typedef void * (*audio_get_enc_config_api_t)(tSESSION_TYPE session_type, uint8_t *multicast_status,
uint8_t *num_dev, audio_format_t *codec_format);
typedef int (*audio_source_check_a2dp_ready_api_t)(tSESSION_TYPE session_type);
typedef bool (*audio_is_tws_mono_mode_enable_t)(void);
typedef int (*audio_sink_start_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_sink_stop_api_t)(tSESSION_TYPE session_type);
typedef void * (*audio_get_dec_config_t)(audio_format_t *codec_format);
typedef void * (*audio_sink_session_setup_complete_t)(uint64_t system_latency);
typedef int (*audio_sink_check_a2dp_ready_t)(void);
typedef uint16_t (*audio_sink_get_a2dp_latency_api_t)(tSESSION_TYPE session_type);
typedef bool (*audio_is_scrambling_enabled_t)(void);
typedef int (*audio_sink_suspend_api_t)(tSESSION_TYPE session_type);
typedef void (*btoffload_update_metadata_api_t)(tSESSION_TYPE session_type, void* metadata);
typedef int (*audio_sink_open_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_sink_close_api_t)(tSESSION_TYPE session_type);
typedef int (*audio_source_get_supported_latency_modes_api_t)(tSESSION_TYPE session_type, size_t *num_modes, size_t max_latency_modes, uint32_t *modes);
typedef int (*audio_source_set_latency_mode_api_t)(tSESSION_TYPE session_type, uint32_t mode);
typedef int (*audio_source_open_t)(void);
typedef int (*audio_source_close_t)(void);
typedef int (*audio_source_start_t)(void);
typedef int (*audio_source_stop_t)(void);
typedef int (*audio_source_suspend_t)(void);
typedef void* (*audio_get_enc_config_t)(uint8_t* multicast_status,
uint8_t* num_dev, audio_format_t* codec_format);
typedef int (*audio_source_check_a2dp_ready_t)(void);
typedef int (*audio_sink_start_t)(void);
typedef int (*audio_sink_stop_t)(void);
typedef uint16_t(*audio_sink_get_a2dp_latency_t)(void);
typedef int (*audio_sink_suspend_t)(void);
typedef int (*audio_sink_open_t)(void);
typedef int (*audio_sink_close_t)(void);
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
//typedef void (tbit_rate_cback)(uint32_t bitrate);
typedef void (*audio_get_dynamic_bitrate_t)(void (*bitrate_cback)(uint32_t bitrate));
//typedef void (tpeer_mtu_cback)(int mtu);
typedef void (*audio_get_peer_mtu_t)(void (*peer_mtu_cback)(uint32_t mtu));
#endif
// Abstract base class
class Bluetooth : public Device
{
protected:
Bluetooth(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
codec_type codecType;
struct pal_media_config codecConfig;
codec_format_t codecFormat;
void *codecInfo;
void *pluginHandler;
bt_codec_t *pluginCodec;
bool isAbrEnabled;
bool isConfigured;
bool isLC3MonoModeOn;
bool isTwsMonoModeOn;
bool isScramblingEnabled;
bool isDummySink;
struct pcm *fbPcm;
std::vector<int> fbpcmDevIds;
std::shared_ptr<Bluetooth> fbDev;
int abrRefCnt;
std::mutex mAbrMutex;
int totalActiveSessionRequests;
codec_version_t codecVersion;
#if defined(SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD) && !defined(QCA_OFFLOAD)
void set_a2dp_suspend(int a2dp_suspend);
#endif
int32_t getPCMId();
int checkAndUpdateCustomPayload(uint8_t **paramData, size_t *paramSize);
int getPluginPayload(void **handle, bt_codec_t **btCodec,
bt_enc_payload_t **out_buf,
codec_type codecType);
int configureCOPModule(int32_t pcmId, const char *backendName, uint32_t tagId, uint32_t streamMapDir, bool isFbpayload);
int configureRATModule(int32_t pcmId, const char *backendName, uint32_t tagId, bool isFbpayload);
int configurePCMConverterModule(int32_t pcmId, const char *backendName, uint32_t tagId, bool isFbpayload);
int configureGraphModules();
int configureNrecParameters(bool isNrecEnabled);
int updateDeviceMetadata();
void updateDeviceAttributes();
bool isPlaceholderEncoder();
void startAbr();
void stopAbr();
int32_t configureSlimbusClockSrc(void);
public:
int getCodecConfig(struct pal_media_config *config) override;
virtual ~Bluetooth();
};
class BtA2dp : public Bluetooth
{
protected:
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objTx;
static std::shared_ptr<Device> objBleRx;
static std::shared_ptr<Device> objBleTx;
static std::shared_ptr<Device> objBleBroadcastRx;
BtA2dp(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
pal_param_bta2dp_t param_bt_a2dp;
private:
/* BT IPC related members */
static void *bt_lib_source_handle;
static bt_audio_pre_init_t bt_audio_pre_init;
static audio_source_open_api_t audio_source_open_api;
static audio_source_close_api_t audio_source_close_api;
static audio_source_start_api_t audio_source_start_api;
static audio_source_stop_api_t audio_source_stop_api;
static audio_source_suspend_api_t audio_source_suspend_api;
static audio_source_handoff_triggered_t audio_source_handoff_triggered;
static clear_source_a2dpsuspend_flag_t clear_source_a2dpsuspend_flag;
static audio_get_enc_config_api_t audio_get_enc_config_api;
static audio_source_check_a2dp_ready_api_t audio_source_check_a2dp_ready_api;
static audio_is_tws_mono_mode_enable_t audio_is_tws_mono_mode_enable;
static audio_sink_get_a2dp_latency_api_t audio_sink_get_a2dp_latency_api;
static void *bt_lib_sink_handle;
static audio_sink_start_api_t audio_sink_start_api;
static audio_sink_stop_api_t audio_sink_stop_api;
static audio_get_dec_config_t audio_get_dec_config;
static audio_sink_session_setup_complete_t audio_sink_session_setup_complete;
static audio_sink_check_a2dp_ready_t audio_sink_check_a2dp_ready;
static audio_is_scrambling_enabled_t audio_is_scrambling_enabled;
static audio_sink_suspend_api_t audio_sink_suspend_api;
static btoffload_update_metadata_api_t btoffload_update_metadata_api;
static audio_sink_open_api_t audio_sink_open_api;
static audio_sink_close_api_t audio_sink_close_api;
static audio_source_get_supported_latency_modes_api_t audio_source_get_supported_latency_modes_api;
static audio_source_set_latency_mode_api_t audio_source_set_latency_mode_api;
static audio_source_open_t audio_source_open;
static audio_source_close_t audio_source_close;
static audio_source_start_t audio_source_start;
static audio_source_stop_t audio_source_stop;
static audio_source_suspend_t audio_source_suspend;
static audio_get_enc_config_t audio_get_enc_config;
static audio_source_check_a2dp_ready_t audio_source_check_a2dp_ready;
static audio_sink_get_a2dp_latency_t audio_sink_get_a2dp_latency;
static audio_sink_start_t audio_sink_start;
static audio_sink_stop_t audio_sink_stop;
static audio_sink_suspend_t audio_sink_suspend;
static audio_sink_open_t audio_sink_open;
static audio_sink_close_t audio_sink_close;
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
static audio_get_dynamic_bitrate_t audio_get_dynamic_bitrate;
static audio_get_peer_mtu_t audio_get_peer_mtu;
#endif
/* member variables */
uint8_t a2dpRole; // source or sink
enum A2DP_STATE a2dpState;
bool isA2dpOffloadSupported;
uint32_t a2dpLatencyMode;
uint32_t codecLatency;
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
uint32_t delay_report;
bool use_offload_hal;
audio_source_t audio_source;
#ifdef QCA_OFFLOAD
bool game_mode;
#endif
#endif
uint32_t getLatency(uint32_t slatency);
int startPlayback();
int stopPlayback();
int startCapture();
int stopCapture();
/* common member funtions */
void init_a2dp_source();
void open_a2dp_source();
int close_audio_source();
tSESSION_TYPE get_session_type();
void init_a2dp_sink();
void open_a2dp_sink();
int close_audio_sink();
bool a2dp_send_sink_setup_complete(void);
using Bluetooth::init;
void init();
public:
int start();
int stop();
bool isDeviceReady() override;
int32_t setDeviceParameter(uint32_t param_id, void *param) override;
int32_t getDeviceParameter(uint32_t param_id, void **param) override;
static std::shared_ptr<Device> getObject(pal_device_id_t id);
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
bool is_a2dp_offload();
enum A2DP_STATE getA2dpState();
codec_format_t getCodecFormat();
#ifdef QCA_OFFLOAD
void setGameMode(bool gameMode);
#endif
#endif
virtual ~BtA2dp();
DISALLOW_COPY_AND_ASSIGN(BtA2dp);
int32_t checkDeviceStatus();
};
class BtSco : public Bluetooth
{
protected:
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objTx;
BtSco(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
static bool isScoOn;
static bool isWbSpeechEnabled;
static int swbSpeechMode;
static bool isSwbLc3Enabled;
static audio_lc3_codec_cfg_t lc3CodecInfo;
static bool isNrecEnabled;
int startSwb();
// SS_BT_HFP - H_127 : RVP
#ifdef SEC_AUDIO_BLUETOOTH
static int rvpMode;
int startRvp();
#endif
// SS_BT_HFP - H_127 end
public:
int start();
int stop();
bool isDeviceReady() override;
int32_t setDeviceParameter(uint32_t param_id, void *param) override;
void convertCodecInfo(audio_lc3_codec_cfg_t &lc3CodecInfo, btsco_lc3_cfg_t &lc3Cfg);
void updateSampleRate(uint32_t *sampleRate);
bool isScoNbWbActive() override;
static std::shared_ptr<Device> getObject(pal_device_id_t id);
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
virtual ~BtSco();
DISALLOW_COPY_AND_ASSIGN(BtSco);
};
#endif /* _BLUETOOTH_H_ */

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DEVICE_H
#define DEVICE_H
#include <iostream>
#include <map>
#include <mutex>
#include <memory>
#include "PalApi.h"
#include "PalDefs.h"
#include <string.h>
#include "PalCommon.h"
#include "Device.h"
#include "PalAudioRoute.h"
#define DEVICE_NAME_MAX_SIZE 128
#define DUMP_DEV_ATTR 0
class Stream;
class ResourceManager;
class Device
{
protected:
std::shared_ptr<Device> devObj;
std::mutex mDeviceMutex;
std::string mPALDeviceName;
struct pal_device deviceAttr;
std::shared_ptr<ResourceManager> rm;
int deviceCount = 0;
int deviceStartStopCount = 0;
struct audio_route *audioRoute = NULL; //getAudioRoute() from RM and store
struct mixer *virtualMixerHandle = NULL; //getVirtualAudioMixer() from RM and store
struct mixer *hwMixerHandle = NULL; //getHwAudioMixer() from RM and store
char mSndDeviceName[DEVICE_NAME_MAX_SIZE] = {0};
void *customPayload;
size_t customPayloadSize;
std::string UpdatedSndName;
uint32_t mCurrentPriority;
//device atrributues per stream are stored by priority in a map
std::multimap<uint32_t, std::pair<Stream *, struct pal_device *>> mStreamDevAttr;
uint32_t mSampleRate = 0;
uint32_t mBitWidth = 0;
Device(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
Device();
int32_t configureDeviceClockSrc(char const *mixerStrClockSrc, const uint32_t clockSrc);
public:
virtual int init(pal_param_device_connection_t device_conn);
virtual int deinit(pal_param_device_connection_t device_conn);
virtual int getDefaultConfig(pal_param_device_capability_t capability);
int open();
virtual int close();
virtual int start();
int start_l();
virtual int stop();
int stop_l();
int prepare();
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
int getSndDeviceId();
int getDeviceCount() { return deviceCount; }
std::string getPALDeviceName();
int setDeviceAttributes(struct pal_device &dattr);
virtual int getDeviceAttributes(struct pal_device *dattr,
Stream* streamHandle = NULL);
virtual int getCodecConfig(struct pal_media_config *config);
static std::shared_ptr<Device> getObject(pal_device_id_t dev_id);
int updateCustomPayload(void *payload, size_t size);
int freeCustomPayload(uint8_t **payload, size_t *payloadSize);
void* getCustomPayload();
size_t getCustomPayloadSize();
virtual int32_t setDeviceParameter(uint32_t param_id, void *param);
virtual int32_t setParameter(uint32_t param_id, void *param);
virtual int32_t getDeviceParameter(uint32_t param_id, void **param);
virtual int32_t getParameter(uint32_t param_id, void **param);
virtual bool isDeviceReady() { return true;}
virtual bool isScoNbWbActive() { return false;}
void setSndName (std::string snd_name) { UpdatedSndName = snd_name;}
void clearSndName () { UpdatedSndName.clear();}
virtual ~Device();
void getCurrentSndDevName(char *name);
void setSampleRate(uint32_t sr){mSampleRate = sr;};
void setBitWidth(uint32_t bw) {mBitWidth = bw;};
void lockDeviceMutex() { mDeviceMutex.lock(); };
void unlockDeviceMutex() { mDeviceMutex.unlock(); };
bool compareStreamDevAttr(const struct pal_device *inDevAttr,
const struct pal_device_info *inDevInfo,
struct pal_device *curDevAttr,
const struct pal_device_info *curDevInfo);
int insertStreamDeviceAttr(struct pal_device *deviceAttr,
Stream* streamHandle);
void removeStreamDeviceAttr(Stream* streamHandle);
int getTopPriorityDeviceAttr(struct pal_device *deviceAttr, uint32_t *streamPrio);
static int32_t initHdrRoutine(const char *hdr_custom_key);
#ifdef SEC_AUDIO_ADD_FOR_DEBUG
virtual void dump(int fd) { return; }
#endif
};
#endif //DEVICE_H

View File

@@ -0,0 +1,160 @@
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
*
* Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*
*/
#ifndef DISPLAYPORT_H
#define DISPLAYPORT_H
#include "Device.h"
#include "PalAudioRoute.h"
#include "PalDefs.h"
#include "ResourceManager.h"
#ifdef FEATURE_IPQ_OPENWRT
#include <audio.h>
#else
#include <system/audio.h>
#endif
#include <media_fmt_api_basic.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
/* HDMI EDID Information */
#define BIT(nr) (1UL << (nr))
#define MAX_EDID_BLOCKS 10
#define MAX_SHORT_AUDIO_DESC_CNT 30
#define MIN_AUDIO_DESC_LENGTH 3
#define MIN_SPKR_ALLOCATION_DATA_LENGTH 3
#define MAX_CHANNELS_SUPPORTED 8
#define MAX_DISPLAY_DEVICES 3
#define MAX_FRAME_BUFFER_NAME_SIZE 80
#define MAX_CHAR_PER_INT 13
#define MAX_HDMI_CHANNEL_CNT 8
#define EXT_DISPLAY_PLUG_STATUS_NOTIFY_ENABLE 0x30
#define EXT_DISPLAY_PLUG_STATUS_NOTIFY_CONNECT 0x01
#define EXT_DISPLAY_PLUG_STATUS_NOTIFY_DISCONNECT 0x00
typedef enum edidAudioFormatId {
LPCM = 1,
AC3,
MPEG1,
MP3,
MPEG2_MULTI_CHANNEL,
AAC,
DTS,
ATRAC,
SACD,
DOLBY_DIGITAL_PLUS,
DTS_HD,
MAT,
DST,
WMA_PRO
} edidAudioFormatId;
typedef struct edidAudioBlockInfo {
edidAudioFormatId formatId;
int samplingFreqBitmask;
int bitsPerSampleBitmask;
int channels;
} edidAudioBlockInfo;
typedef struct edidAudioInfo {
int audioBlocks;
unsigned char speakerAllocation[MIN_SPKR_ALLOCATION_DATA_LENGTH];
edidAudioBlockInfo audioBlocksArray[MAX_EDID_BLOCKS];
char channelMap[MAX_CHANNELS_SUPPORTED];
int channelAllocation;
unsigned int channelMask;
} edidAudioInfo;
class DisplayPort : public Device
{
uint32_t dp_controller;
uint32_t dp_stream;
protected:
int configureDpEndpoint();
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objRx1;
static std::shared_ptr<Device> objTx;
DisplayPort(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
int start();
int init(pal_param_device_connection_t device_conn);
int deinit(pal_param_device_connection_t device_conn);
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject(pal_device_id_t id);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static int32_t checkAndUpdateBitWidth(uint32_t *bitWidth);
static int32_t checkAndUpdateSampleRate(uint32_t *sampleRate);
static bool isDisplayPortEnabled ();
void resetEdidInfo();
static int32_t getDisplayPortCtlIndex(int controller, int stream);
static int32_t setExtDisplayDevice(struct audio_mixer *mixer, int controller, int stream);
static int32_t getExtDispType(struct audio_mixer *mixer, int controller, int stream);
static int getEdidInfo(struct audio_mixer *mixer, int controller, int stream);
static void cacheEdid(struct audio_mixer *mixer, int controller, int stream);
static const char * edidFormatToStr(unsigned char format);
static bool isSampleRateSupported(unsigned char srByte, int samplingRate);
static unsigned char getEdidBpsByte(unsigned char byte, unsigned char format);
static bool isSupportedBps(unsigned char bpsByte, int bps);
static int getHighestEdidSF(unsigned char byte);
static void updateChannelMap(edidAudioInfo* info);
static void dumpSpeakerAllocation(edidAudioInfo* info);
static void updateChannelAllocation(edidAudioInfo* info);
static void updateChannelMapLpass(edidAudioInfo* info);
static void retrieveChannelMapLpass(int ca, uint8_t *ch_map, int ch_map_size);
static void updateChannelMask(edidAudioInfo* info);
static void dumpEdidData(edidAudioInfo *info);
static bool getSinkCaps(edidAudioInfo* info, char *edidData);
static int getDeviceChannelAllocation(int num_channels);
bool isSupportedSR(edidAudioInfo* info, int sr);
int getMaxChannel();
bool isSupportedBps(edidAudioInfo* info, int bps);
int getHighestSupportedSR();
int getHighestSupportedBps();
int updateSysfsNode(const char *path, const char *data, size_t len);
int getExtDispSysfsNodeIndex(int ext_disp_type);
int updateExtDispSysfsNode(int node_value, int controller, int stream);
int updateAudioAckState(int node_value, int controller, int stream);
int getDeviceAttributes (struct pal_device *dattr,
Stream* streamHandle = NULL) override;
};
#endif //DISPLAYPORT_H

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef DUMMY_DEV_H
#define DUMMY_DEV_H
#include "Device.h"
class DummyDev : public Device
{
protected:
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objTx;
DummyDev(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject(pal_device_id_t id);
virtual ~DummyDev();
};
#endif //DUMMY_DEV_H

View File

@@ -0,0 +1,62 @@
/* * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ECREFDEVICE_H
#define ECREFDEVICE_H
#include "Device.h"
#include <vector>
class ECRefDevice : public Device
{
protected:
static std::shared_ptr<Device> obj;
ECRefDevice(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
struct pal_device mDeviceAttr;
std::shared_ptr<ResourceManager> rm;
struct pal_media_config codecConfig;
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject();
static int32_t isSampleRateSupported(int32_t sampleRate);
static int32_t isChannelSupported(int32_t numChannels);
static int32_t isBitWidthSupported(int32_t bitWidth);
static void checkAndUpdateBitWidth(uint32_t *bitWidth);
static void checkAndUpdateSampleRate(uint32_t *sampleRate);
int start();
virtual ~ECRefDevice();
};
#endif //ECREFDEVICE_H

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EXTEC_H
#define EXTEC_H
#include "Device.h"
#include "PalAudioRoute.h"
class ExtEC : public Device
{
protected:
static std::shared_ptr<Device> obj;
ExtEC(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
ExtEC();
virtual ~ExtEC();
};
#endif //SPEAKER_H

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EXTMODEM_H
#define EXTMODEM_H
#include "Device.h"
class ExtModem : public Device
{
protected:
static std::shared_ptr<Device> obj;
ExtModem(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject();
virtual ~ExtModem();
};
#endif //EXTMODEM_H

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EXTMODEM_MIC_H
#define EXTMODEM_MIC_H
#include "Device.h"
class ExtModemMic : public Device
{
protected:
static std::shared_ptr<Device> obj;
ExtModemMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
virtual ~ExtModemMic();
static std::shared_ptr<Device> getObject();
};
#endif //EXTMODEM_MIC_H

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FM_DEVICE_H
#define FM_DEVICE_H
#include "Device.h"
#include "PalAudioRoute.h"
class FMDevice : public Device
{
protected:
static std::shared_ptr<Device> obj;
FMDevice(struct pal_device *device, std::shared_ptr<ResourceManager> rm) : Device(device, rm) {};
public:
static std::shared_ptr<Device> getInstance(struct pal_device*, std::shared_ptr<ResourceManager>);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject() {return obj;}
FMDevice() = default;
virtual ~FMDevice() = default;
};
#endif //FM_DEVICE_H

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HANDSET_H
#define HANDSET_H
#include "Device.h"
class Handset : public Device
{
protected:
static std::shared_ptr<Device> obj;
Handset(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
virtual ~Handset();
};
#endif //HANDSET_H

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HANDSETMIC_H
#define HANDSETMIC_H
#include "Device.h"
class HandsetMic : public Device
{
protected:
static std::shared_ptr<Device> obj;
HandsetMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
virtual ~HandsetMic();
};
#endif //HANDSETMIC_H

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HANDSET_VA_MIC_H
#define HANDSET_VA_MIC_H
#include "Device.h"
#include "PalAudioRoute.h"
class HandsetVaMic : public Device {
protected:
static std::shared_ptr<Device> obj;
HandsetVaMic(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
virtual ~HandsetVaMic(void);
};
#endif //HANDSET_VA_MIC_H

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HapticsDev_H
#define HapticsDev_H
#include "Device.h"
#ifdef SEC_AUDIO_SUPPORT_HAPTIC_PLAYBACK
#include "SecPalDefs.h"
#endif
class HapticsDev : public Device
{
protected:
static std::shared_ptr<Device> obj;
HapticsDev(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
virtual ~HapticsDev();
#ifdef SEC_AUDIO_SUPPORT_HAPTIC_PLAYBACK
int start();
int32_t setParameter(uint32_t param_id, void *param) override;
private:
void setHapticSource(haptic_source_t source);
haptic_source_t hapticSource;
#endif
};
#endif //HapticsDev_H

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HAPTICSDEV_PROT
#define HAPTICSDEV_PROT
#include "HapticsDev.h"
#include "wsa_haptics_vi_api.h"
#include "rx_haptics_api.h"
#include <tinyalsa/asoundlib.h>
#include <mutex>
#include <condition_variable>
#include <thread>
#include<vector>
#include "apm_api.h"
#include "SpeakerProtection.h"
class HapticsDev;
typedef enum haptics_dev_prot_cal_state {
HAPTICS_DEV_NOT_CALIBRATED, /* HapticsDev not calibrated */
HAPTICS_DEV_CALIBRATED, /* HapticsDev calibrated */
HAPTICS_DEV_CALIB_IN_PROGRESS, /* HapticsDev calibration in progress */
}haptics_dev_prot_cal_state;
typedef enum haptics_dev_prot_proc_state {
HAPTICS_DEV_PROCESSING_IN_IDLE, /* Processing mode in idle state */
HAPTICS_DEV_PROCESSING_IN_PROGRESS, /* Processing mode in running state */
} haptics_dev_prot_proc_state;
enum {
HAPTICS_DEV_RIGHT, /* Right HapticsDev */
HAPTICS_DEV_LEFT, /* Left HapticsDev */
};
struct haptics_vi_cal_param {
int32_t Re_ohm_Cal_q24 = 0; // cal & ftm
int32_t Fres_Hz_Cal_q20 = 0; // cal & ftm
int32_t Bl_q24 = 0; // cal & ftm
int32_t Rms_KgSec_q24 = 0; // cal & ftm
int32_t Blq_ftm_q24 = 0; // ftm
int32_t Le_mH_ftm_q24 = 0; // ftm
};
class HapticsDevProtection : public HapticsDev
{
protected :
bool hapticsdevProtEnable;
bool threadExit;
bool triggerCal;
int minIdleTime;
static haptics_dev_prot_cal_state hapticsDevCalState;
haptics_dev_prot_proc_state hapticsDevProcessingState;
int *devTempList;
static bool isHapDevInUse;
static std::atomic<bool> calThrdCreated;
static std::atomic<bool> ftmThrdCreated;
static bool isDynamicCalTriggered;
static struct timespec devLastTimeUsed;
static struct mixer *virtMixer;
static struct mixer *hwMixer;
static struct pcm *rxPcm;
static struct pcm *txPcm;
static int numberOfChannels;
static bool mDspCallbackRcvd;
static haptics_vi_cal_param cbCalData[HAPTICS_MAX_OUT_CHAN];
struct pal_device mDeviceAttr;
std::vector<int> pcmDevIdTx;
static int calibrationCallbackStatus;
static int numberOfRequest;
static struct pal_device_info vi_device;
private :
public:
static std::thread mCalThread;
static std::condition_variable cv;
static std::mutex cvMutex;
std::mutex deviceMutex;
static std::mutex calibrationMutex;
void HapticsDevCalibrationThread();
void HapticsDevFTMThread();
int getDevTemperature(int haptics_dev_pos);
void HapticsDevCalibrateWait();
int HapticsDevStartCalibration(int32_t operation_mode);
void HapticsDevProtectionInit();
void HapticsDevProtectionDeinit();
void getHapticsDevTemperatureList();
static void HapticsDevProtSetDevStatus(bool enable);
static int setConfig(int type, int tag, int tagValue, int devId, const char *aif);
bool isHapticsDevInUse(unsigned long *sec);
HapticsDevProtection(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~HapticsDevProtection();
int32_t start();
int32_t stop();
int32_t setParameter(uint32_t param_id, void *param) override;
int32_t getParameter(uint32_t param_id, void **param) override;
int32_t HapticsDevProtProcessingMode(bool flag);
int HapticsDevProtectionDynamicCal();
int HapticsDevProtectionFTM();
void updateHPcustomPayload();
static void handleHPCallback (uint64_t hdl, uint32_t event_id, void *event_data,
uint32_t event_size);
int getCpsDevNumber(std::string mixer);
// int32_t getCalibrationData(void **param);
int32_t getFTMParameter(void **param);
int32_t getAndsetPersistentParameter(bool flag);
void disconnectFeandBe(std::vector<int> pcmDevIds, std::string backEndName);
};
class HapticsDevFeedback : public HapticsDev
{
protected :
struct pal_device mDeviceAttr;
static std::shared_ptr<Device> obj;
static int numDevice;
public :
int32_t start();
int32_t stop();
HapticsDevFeedback(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~HapticsDevFeedback();
void updateVIcustomPayload();
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
};
#endif

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HEADPHONE_H
#define HEADPHONE_H
#include "Device.h"
#include "PalAudioRoute.h"
class Headphone : public Device
{
protected:
static std::shared_ptr<Device> obj;
Headphone(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static int32_t checkAndUpdateBitWidth(uint32_t *bitWidth);
static int32_t checkAndUpdateSampleRate(uint32_t *sampleRate);
static std::shared_ptr<Device> getObject(pal_device_id_t id);
virtual ~Headphone();
};
#endif //HEADPHONE_H

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HEADSETMIC_H
#define HEADSETMIC_H
#include "Device.h"
class HeadsetMic : public Device
{
protected:
static std::shared_ptr<Device> obj;
HeadsetMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static int32_t checkAndUpdateBitWidth(uint32_t *bitWidth);
static int32_t checkAndUpdateSampleRate(uint32_t *sampleRate);
static std::shared_ptr<Device> getObject();
virtual ~HeadsetMic();
};
#endif //HEADSETMIC_H

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HEADSET_VA_MIC_H
#define HEADSET_VA_MIC_H
#include "Device.h"
#include "PalAudioRoute.h"
class HeadsetVaMic : public Device {
protected:
static std::shared_ptr<Device> obj;
HeadsetVaMic(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
~HeadsetVaMic(void);
};
#endif //HANDSET_VA_MIC_H

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef RTPROXY_H
#define RTPROXY_H
#include "Device.h"
#include "PalAudioRoute.h"
class RTProxyIn : public Device
{
static std::shared_ptr<Device> objPlay;
static std::shared_ptr<Device> objRecord;
std::shared_ptr<ResourceManager> rm;
protected:
RTProxyIn(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getObject(pal_device_id_t id);
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
int start();
virtual ~RTProxyIn();
};
class RTProxyOut : public Device
{
static std::shared_ptr<Device> objPlay;
static std::shared_ptr<Device> objRecord;
std::shared_ptr<ResourceManager> rm;
protected:
RTProxyOut(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
virtual ~RTProxyOut();
static std::shared_ptr<Device> getObject(pal_device_id_t id);
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
int start();
};
#endif //SPEAKER_H

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SPEAKER_H
#define SPEAKER_H
#include "Device.h"
#include "PalAudioRoute.h"
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
#include "SecPalDefs.h"
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW
class Speaker : public Device
{
protected:
static std::shared_ptr<Device> obj;
Speaker(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
static std::shared_ptr<Device> getObject();
int close();
Speaker();
virtual ~Speaker();
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
int32_t setParameter(uint32_t param_id, void *param) override;
private:
pal_device_speaker_mute curMuteStatus;
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW
};
#endif //SPEAKER_H

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SPEAKERMIC_H
#define SPEAKERMIC_H
#include "Device.h"
#include "Device.h"
class SpeakerMic : public Device
{
protected:
static std::shared_ptr<Device> obj;
SpeakerMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(uint32_t sampleRate);
static int32_t isChannelSupported(uint32_t numChannels);
static int32_t isBitWidthSupported(uint32_t bitWidth);
virtual ~SpeakerMic();
static std::shared_ptr<Device> getObject();
};
#endif //SPEAKERMIC_H

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 2020, 2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SPEAKER_PROT
#define SPEAKER_PROT
#include "Device.h"
#include "sp_vi.h"
#include "sp_rx.h"
#include "cps_data_router.h"
#include <tinyalsa/asoundlib.h>
#include <mutex>
#include <condition_variable>
#include <thread>
#include<vector>
#include "apm_api.h"
class Device;
#define LPASS_WR_CMD_REG_PHY_ADDR 0x6B14020
#define LPASS_RD_CMD_REG_PHY_ADDR 0x6B14024
#define LPASS_RD_FIFO_REG_PHY_ADDR 0x6B14040
#define CPS_WSA_VBATT_REG_ADDR 0x0003429
#define CPS_WSA_TEMP_REG_ADDR 0x0003422
#define CPS_WSA_VBATT_LOWER_THRESHOLD_1 168
#define CPS_WSA_VBATT_LOWER_THRESHOLD_2 148
typedef enum speaker_prot_cal_state {
SPKR_NOT_CALIBRATED, /* Speaker not calibrated */
SPKR_CALIBRATED, /* Speaker calibrated */
SPKR_CALIB_IN_PROGRESS, /* Speaker calibration in progress */
}spkr_prot_cal_state;
typedef enum speaker_prot_proc_state {
SPKR_PROCESSING_IN_IDLE, /* Processing mode in idle state */
SPKR_PROCESSING_IN_PROGRESS, /* Processing mode in running state */
}spkr_prot_proc_state;
enum {
SPKR_RIGHT, /* Right Speaker */
SPKR_LEFT, /* Left Speaker */
};
/* enum that indicates speaker condition. */
enum {
SPKR_OK = 0,
SPKR_CLOSE = 1,
SPKR_OPEN = 2,
SPKR_DC = 3,
SPKR_OVERTEMP = 4,
};
enum {
UNLINKED = 0,
LINK1 = 1,
LINK2 = 2,
};
struct agmMetaData {
uint8_t *buf;
uint32_t size;
agmMetaData(uint8_t *b, uint32_t s)
:buf(b),size(s) {}
};
class SpeakerProtection : public Device
{
protected :
bool spkrProtEnable;
bool threadExit;
bool triggerCal;
int minIdleTime;
static speaker_prot_cal_state spkrCalState;
spkr_prot_proc_state spkrProcessingState;
int *spkerTempList;
static bool isSpkrInUse;
static bool calThrdCreated;
static bool isDynamicCalTriggered;
static struct timespec spkrLastTimeUsed;
static struct mixer *virtMixer;
static struct mixer *hwMixer;
static struct pcm *rxPcm;
static struct pcm *txPcm;
static struct pcm *cpsPcm;
static int numberOfChannels;
static bool mDspCallbackRcvd;
static param_id_sp_th_vi_calib_res_per_spkr_cfg_param_t *callback_data;
struct pal_device mDeviceAttr;
std::vector<int> pcmDevIdTx;
std::vector<int> pcmDevIdCPS;
static int calibrationCallbackStatus;
static int numberOfRequest;
static struct pal_device_info vi_device;
static struct pal_device_info cps_device;
private :
public:
static std::thread mCalThread;
static std::condition_variable cv;
static std::mutex cvMutex;
std::mutex deviceMutex;
static std::mutex calibrationMutex;
void spkrCalibrationThread();
int getSpeakerTemperature(int spkr_pos);
void spkrCalibrateWait();
int spkrStartCalibration();
void speakerProtectionInit();
void speakerProtectionDeinit();
void getSpeakerTemperatureList();
static void spkrProtSetSpkrStatus(bool enable);
static int setConfig(int type, int tag, int tagValue, int devId, const char *aif);
bool isSpeakerInUse(unsigned long *sec);
SpeakerProtection(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~SpeakerProtection();
int32_t start();
int32_t stop();
int32_t setParameter(uint32_t param_id, void *param) override;
int32_t getParameter(uint32_t param_id, void **param) override;
int32_t spkrProtProcessingMode(bool flag);
int speakerProtectionDynamicCal();
void updateSPcustomPayload();
static int32_t spkrProtSetR0T0Value(vi_r0t0_cfg_t r0t0Array[]);
static void handleSPCallback (uint64_t hdl, uint32_t event_id, void *event_data,
uint32_t event_size);
void updateCpsCustomPayload(int miid);
int getCpsDevNumber(std::string mixer);
int32_t getCalibrationData(void **param);
int32_t getFTMParameter(void **param);
void disconnectFeandBe(std::vector<int> pcmDevIds, std::string backEndName);
};
class SpeakerFeedback : public Device
{
protected :
struct pal_device mDeviceAttr;
static std::shared_ptr<Device> obj;
static int numSpeaker;
public :
int32_t start();
int32_t stop();
SpeakerFeedback(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~SpeakerFeedback();
void updateVIcustomPayload();
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject();
};
#endif

View File

@@ -0,0 +1,170 @@
#include "Device.h"
#include "sp_vi.h"
#include "sp_rx.h"
#include <tinyalsa/asoundlib.h>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <vector>
#include "apm_api.h"
#ifdef SEC_AUDIO_COMMON
#include "SecPalDefs.h"
#endif
#ifdef ENABLE_TFA98XX_SUPPORT
//#define PAL_PARAM_ID_SET_TFADSP_RUN_CAL 3000
#define PAL_PARAM_ID_SET_TFADSP_SURF_TEMP 0x1000B941
#define PAL_PARAM_ID_GET_TFADSP_BLACKBOX_DATA 0x1000B942
#define PAL_PARAM_ID_GET_TFADSP_CAL_STATUS 0x1000B943
#define PAL_PARAM_ID_GET_TFADSP_CAL_DATA 0x1000B944
#define PAL_PARAM_ID_GET_TFADSP_CAL_TEMP 0x1000B945
#define PAL_PARAM_ID_GET_TFADSP_SPK_TEMP 0x1000B946
#ifndef SEC_AUDIO_COMMON
#define PAL_PARAM_ID_SPEAKER_AMP_TEMPERATURE_RCV 3001
#define PAL_PARAM_ID_SPEAKER_AMP_TEMPERATURE_SPK 3002
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_SAVE_RESET 3003
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_SAVE 3004
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_START 3005
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_STOP 3006
typedef struct pal_param_amp_ssrm {
int temperature;
} pal_param_amp_ssrm_t;
#define NUM_OF_SPEAKER 2
#define NUM_OF_BIGDATA_ITEM 5 /* max_temp temp_over max_excu excu_over keep_max_temp */
typedef struct pal_param_amp_bigdata {
int value[NUM_OF_SPEAKER * NUM_OF_BIGDATA_ITEM];
} pal_param_amp_bigdata_t;
enum bigdata_ids{
MAX_TEMP_L, MAX_TEMP_R,
TEMP_OVER_L, TEMP_OVER_R,
MAX_EXCU_L, MAX_EXCU_R,
EXCU_OVER_L, EXCU_OVER_R,
KEEP_MAX_TEMP_L, KEEP_MAX_TEMP_R,
};
#endif
#define TFADSP_ACTIVATION_THREAD
#define TFADSP_LIVEDATA_LOGGING
class Device;
class SpeakerFeedbackTFA;
class SpeakerProtectionTFA : public Device
{
protected :
bool active_state;
struct pal_device mDeviceAttr;
#ifdef SET_IPCID_MIXER_CTL
static struct mixer *virtMixer;
static struct mixer *hwMixer;
struct mixer_ctl *ipc_id_mctl;
#endif
private :
std::thread ssrm_thread;
std::mutex ssrm_mutex;
//std::mutex cal_mutex;
std::mutex ipc_mutex;
std::condition_variable ssrm_wait_cond;
bool exit_ssrm_thread;
bool activate_tfadsp_thread_running;
uint32_t ssrm_timer_cnt;
uint32_t cal_suc_p; // 1 or 0
uint32_t cal_suc_s; // 1 or 0
uint32_t cal_val_p; // mOhm
uint32_t cal_val_s; // mOhm
int32_t cal_temp; // degree, board temperature during calibration
uint32_t cal_status;
uint32_t tfadsp_rx_miid;
int32_t surft_left;
int32_t surft_right;
int32_t rcv_temp;
int32_t spk_temp;
int32_t active_spk_dev_count;
bool bigdata_read;
uint32_t tfadsp_state;
bool debug_mode;
bool skip_activate_tfadsp;
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
pal_device_speaker_mute curMuteStatus;
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW
#ifdef TFADSP_LIVEDATA_LOGGING
bool livedata_logging_thread_running;
#endif
public:
pal_param_amp_ssrm_t amp_ssrm;
pal_param_amp_bigdata_t tfa_bigdata;
pal_param_amp_bigdata_t tfa_bigdata_param;
static std::mutex cal_mutex;
static std::condition_variable cal_wait_cond;
SpeakerProtectionTFA(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~SpeakerProtectionTFA();
int32_t start();
int32_t stop();
int32_t setParameter(uint32_t param_id, void *param) override;
int32_t getParameter(uint32_t param_id, void **param) override;
#ifdef SEC_AUDIO_ADD_FOR_DEBUG
void dump(int fd) override;
#endif
int32_t tfa_dsp_get_miid(const char *controlName, mixer_ctl **mixer_ctrl);
int32_t tfa_dsp_msg_write(uint32_t param_id, const uint8_t *buffer, int len);
int32_t tfa_dsp_msg_read(uint8_t *buffer, int len);
int32_t tfa_dsp_read_state(uint8_t *buffer, int len, uint32_t param_id);
int32_t tfa_dsp_read_lib_version();
static void SSRM_Thread(SpeakerProtectionTFA& inst);
void Calibration_Thread();
void Activate_Tfadsp_Thread();
int32_t read_tfa_power_state(uint32_t dev);
int32_t activate_tfadsp();
int32_t store_blackbox_data();
int32_t set_default_spkt_data(uint32_t channel);
int32_t reset_blackbox_data();
int32_t run_calibration();
uint32_t get_calibration_status();
int32_t get_re25c(uint32_t *mOhm_P, uint32_t *mOhm_S);
int32_t get_cal_temp();
int32_t get_rdc(uint32_t *mOhm_P, uint32_t *mOhm_S);
void get_temp(int32_t *temp_l, int32_t *temp_r);
void set_sknt_control();
void get_spkt_data();
void load_cal_file();
void print_bigdata();
void handle_debug_command(int32_t debug_command);
#ifdef SET_IPCID_MIXER_CTL
int32_t get_miid_pcmid_sc(uint32_t *miid, uint32_t *pcm_dev);
#endif
#ifdef TFADSP_LIVEDATA_LOGGING
void Livedata_Logging_Thread();
#endif
};
class SpeakerFeedbackTFA : public Device
{
protected :
struct pal_device mDeviceAttr;
static std::shared_ptr<Device> obj;
public :
int32_t start();
int32_t stop();
SpeakerFeedbackTFA(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~SpeakerFeedbackTFA();
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject();
};
#endif

View File

@@ -0,0 +1,199 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TISPEAKER_PROT
#define TISPEAKER_PROT
#include "Device.h"
#include "sp_vi.h"
#include "sp_rx.h"
#include <tinyalsa/asoundlib.h>
#include <mutex>
#include <condition_variable>
#include <thread>
#include<vector>
#include "apm_api.h"
class Device;
#define TI_SMARTPA
#ifdef ENABLE_TAS_SPK_PROT
#include "SecPalDefs.h"
#define MAX_TEMP_VAL_CHECK 119
#define LIB_VERSION_INDEX 2
#define ACDB_INFO_INDEX 7
#ifndef SEC_AUDIO_COMMON
#define PAL_PARAM_ID_SEPAKER_AMP_RUN_CAL 3000
#define PAL_PARAM_ID_SPEAKER_AMP_TEMPERATURE_RCV 3001
#define PAL_PARAM_ID_SPEAKER_AMP_TEMPERATURE_SPK 3002
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_SAVE_RESET 3003
#define PAL_PARAM_ID_SPEAKER_AMP_BIGDATA_SAVE 3004
#define NUM_OF_SPEAKER 2
enum bigdata_ids{
MAX_TEMP_L,
MAX_TEMP_R,
TEMP_OVER_L,
TEMP_OVER_R,
MAX_EXCU_L,
MAX_EXCU_R,
EXCU_OVER_L,
EXCU_OVER_R,
KEEP_MAX_TEMP_L, /*do not reset*/
KEEP_MAX_TEMP_R, /*do not reset*/
MAX_BIGDATA,
};
typedef struct pal_param_amp_bigdata {
int value[MAX_BIGDATA];
} pal_param_amp_bigdata_t;
typedef struct pal_param_amp_ssrm {
int temperature;
} pal_param_amp_ssrm_t;
#endif
/* reset the entity of the index before keeping */
#define NUM_BIGDATA_TO_CLEAR KEEP_MAX_TEMP_L
typedef struct {
int Excursion_Max; //2.x
int Temperature_Max; //No Q
int Excursion_over_count; //No Q
int Temprature_over_count; //No Q
/* additional params */
int current_excursion; //2.x
int max_excursion_perDuration; //2.x
int current_temperature; //No Q
int max_temperature_perDuration; //No Q
} tismartpa_exc_temp_stats;
typedef struct {
uint32_t silenceCount;
uint32_t totalSilenceCount;
} pal_param_amp_silence_stats;
typedef enum tisa_calib_data_type {
INT,
FLOAT,
STRING,
HEX
} tisa_calib_data_type_t;
typedef struct
{
int num_ch;
int r0_q19[2];
int t0[2];
} spCalibData;
class SpeakerProtectionTI : public Device
{
private :
int getParameterFromDSP(void **param);
int32_t setParamstoDSP(void* param);
public:
int32_t getMixerControl(struct mixer_ctl **ctl, unsigned *miid,
char *mixer_str);
protected :
static bool isSpkrInUse;
static struct timespec spkrLastTimeUsed;
static struct mixer *virtMixer;
static struct mixer *hwMixer;
static struct pcm *rxPcm;
static struct pcm *txPcm;
static int numberOfChannels;
struct pal_device mDeviceAttr;
std::vector<int> pcmDevIdTx;
static int numberOfRequest;
static struct pal_device_info vi_device;
static pal_param_amp_bigdata_t bigdata;
static pal_param_amp_bigdata_t bigdataRef;
static pal_param_amp_ssrm_t ssrm;
static pal_param_amp_silence_stats silencestat[NUM_OF_SPEAKER];
static std::string mLibVersion;
static std::string mParamVersion;
private :
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
static pal_device_speaker_mute curMuteStatus;
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW
public:
std::mutex deviceMutex;
std::mutex calMutex;
std::mutex setgetMutex;
void spkrCalibrationThread();
void speakerProtectionInit();
void speakerProtectionDeinit();
static void spkrProtSetSpkrStatus(bool enable);
static int setConfig(int type, int tag, int tagValue, int devId, const char *aif);
static void handleTISADSPEvent(uint64_t hdl, uint32_t event_id, void *event_data,
uint32_t event_size);
SpeakerProtectionTI(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
~SpeakerProtectionTI();
int32_t start();
int32_t stop();
int32_t setParameter(uint32_t param_id, void *param) override;
int32_t getParameter(uint32_t param_id, void **param) override;
#ifdef SEC_AUDIO_ADD_FOR_DEBUG
void dump(int fd) override;
#endif
int32_t spkrProtProcessingMode(bool flag);
void updateSPcustomPayload(int param_id, void *spConfig);
void disconnectFeandBe(std::vector<int> pcmDevIds, std::string backEndName);
int32_t runTICalibration();
int get_data_from_file(const char* fname, tisa_calib_data_type_t dtype, void* pdata);
int save_data_to_file(const char* fname, tisa_calib_data_type_t dtype, void *pdata);
int get_calib_data(spCalibData *ptical);
void smartpa_get_bigdata();
int32_t smartpa_get_temp(void *param, int ch_idx);
void printBigdata(int ch_idx);
void printLibVersion(int ch_idx);
void printACDBInfo(int ch_idx);
};
#endif // ENABLE_TAS_SPK_PROT
#endif //TISPEAKER_PROT

View File

@@ -0,0 +1,243 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef USB_H
#define USB_H
#include "Device.h"
#include "ResourceManager.h"
#include "PalAudioRoute.h"
#include "SessionAlsaUtils.h"
#include <tinyalsa/asoundlib.h>
#include <vector>
#include <system/audio.h>
#include <map>
#ifdef SEC_AUDIO_COMMON
#include "SecPalDefs.h"
#endif
#define USB_BUFF_SIZE 4096
#define CHANNEL_NUMBER_STR "Channels: "
#define PLAYBACK_PROFILE_STR "Playback:"
#define CAPTURE_PROFILE_STR "Capture:"
#define DATA_PACKET_INTERVAL_STR "Data packet interval:"
#define USB_SIDETONE_GAIN_STR "usb_sidetone_gain"
// Supported sample rates for USB
#define USBID_SIZE 16
/* support positional and index masks to 8ch */
#define MAX_SUPPORTED_CHANNEL_MASKS 8
#define MAX_HIFI_CHANNEL_COUNT 8
#define MIN_CHANNEL_COUNT 1
#define DEFAULT_CHANNEL_COUNT 2
#define MAX_SAMPLE_RATE_SIZE 15
#define DEFAULT_SERVICE_INTERVAL_US 0
#define USB_IN_JACK_SUFFIX "Input Jack"
#define USB_OUT_JACK_SUFFIX "Output Jack"
#ifdef SEC_AUDIO_USB_GAIN_CONTROL
#define MAX_PATH_LEN 128
#define GAIN_XML_PATH "/vendor/etc/mixer_usb_"
// Define all IDs for samsung usb headset
#define SEC_VID 0x04e8
#define SEC_GRAY_HEADPHONE_PID 0xa04b
#define SEC_GRAY_HEADSET_PID 0xa04c
#endif
typedef enum usb_usecase_type{
USB_CAPTURE = 0,
USB_PLAYBACK,
} usb_usecase_type_t;
// one card supports multiple devices
class USBDeviceConfig {
protected:
unsigned int bit_width_;
unsigned int channels_;
std::vector <unsigned int> rates_;
unsigned long service_interval_us_;
usb_usecase_type_t type_;
unsigned int supported_sample_rates_mask_[2] = {0};
bool jack_status_ = true;
public:
void setBitWidth(unsigned int bit_width);
unsigned int getBitWidth();
void setChannels(unsigned int channels);
unsigned int getChannels();
void setType(usb_usecase_type_t type);
unsigned int getType();
void setInterval(unsigned long interval);
unsigned long getInterval();
unsigned int getDefaultRate();
int getSampleRates(int type, char *rates_str);
bool isRateSupported(int requested_rate);
int getBestRate(int requested_rate, int candidate_rate, unsigned int *best_rate);
void usb_find_sample_rate_candidate(int base, int requested_rate,
int cur_rate, int candidate_rate, unsigned int *best_rate);
int updateBestChInfo(struct pal_channel_info *requested_ch_info,
struct pal_channel_info *best);
int getServiceInterval(const char *interval_str_start);
static const unsigned int supported_sample_rates_[MAX_SAMPLE_RATE_SIZE];
void setJackStatus(bool jack_status);
bool getJackStatus();
unsigned int getSRMask(usb_usecase_type_t type) {return supported_sample_rates_mask_[type];} ;
};
class USBCardConfig {
protected:
struct pal_usb_device_address address_;
int endian_;
std::multimap<uint32_t, std::shared_ptr<USBDeviceConfig>> format_list_map;
std::vector <std::shared_ptr<USBDeviceConfig>> usb_device_config_list_;
unsigned int usb_supported_sample_rates_mask_[2] = {0};
void dumpCapabilities(char* read_buf, int type);
#ifdef SEC_AUDIO_ADD_FOR_DEBUG
void saveUSBCapability(char *read_buf);
#endif
public:
USBCardConfig(struct pal_usb_device_address address);
bool isConfigCached(struct pal_usb_device_address addr);
void setEndian(int endian);
int getCapability(usb_usecase_type_t type, struct pal_usb_device_address addr);
int getMaxBitWidth(bool is_playback);
int getMaxChannels(bool is_playback);
unsigned int getFormatByBitWidth(int bitwidth);
void readSupportedFormat(bool is_playback, uint32_t *format);
void readSupportedSampleRate(bool is_playback, uint32_t *sample_rate);
void readSupportedChannelMask(bool is_playback, uint32_t *channel);
int readSupportedConfig(dynamic_media_config_t *config, bool is_playback, int usb_card);
#ifdef SEC_AUDIO_SUPPORT_UHQ
int readBestConfig(struct pal_media_config *config,
struct pal_stream_attributes *sattr,
bool is_playback, struct pal_device_info *devinfo,
pal_uhqa_state uhqa_state);
#else
int readBestConfig(struct pal_media_config *config,
struct pal_stream_attributes *sattr,
bool is_playback, struct pal_device_info *devinfo,
bool uhqa);
#endif
unsigned int getMax(unsigned int a, unsigned int b);
unsigned int getMin(unsigned int a, unsigned int b);
static const unsigned int out_chn_mask_[MAX_SUPPORTED_CHANNEL_MASKS];
static const unsigned int in_chn_mask_[MAX_SUPPORTED_CHANNEL_MASKS];
bool isCaptureProfileSupported();
bool readDefaultJackStatus(bool is_playback);
bool getJackConnectionStatus (int usb_card, const char* suffix);
#ifdef SEC_AUDIO_USB_GAIN_CONTROL
void getUSBVidPid(struct pal_usb_device_address addr);
#endif
};
class USB : public Device
{
protected:
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objTx;
std::vector <std::shared_ptr<USBCardConfig>> usb_card_config_list_;
int configureUsb();
USB(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
static int usb_vendor_id_ckv_;
#ifdef SEC_AUDIO_FMRADIO
bool fm_enabled;
#endif
public:
int start();
int init(pal_param_device_connection_t device_conn);
int deinit(pal_param_device_connection_t device_conn);
int getDefaultConfig(pal_param_device_capability_t capability);
void setVendorIdCkv(struct pal_usb_device_address addr);
static int getVendorIdCkv();
static bool isUsbConnected(struct pal_usb_device_address addr);
static bool isUsbAlive(int card);
int selectBestConfig(struct pal_device *dattr,
struct pal_stream_attributes *sattr,
bool is_playback, struct pal_device_info *devinfo);
#ifdef SEC_AUDIO_USB_GAIN_CONTROL
int setUSBAudioGain();
void USBAudioGainLoadXml(struct pal_usb_device_address addr);
void USBAudioGainControl(struct pal_usb_device_address addr, pal_device_id_t deviceId);
#endif
#ifdef SEC_AUDIO_FMRADIO
void setFmUsbEnable(bool enable) { fm_enabled = enable; };
bool isFmUsbEnabled() { return fm_enabled; };
int32_t setParameter(uint32_t param_id, void *param) override;
#endif
#ifdef SEC_AUDIO_ADD_FOR_DEBUG
void dump(int fd);
#endif
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static int32_t isSampleRateSupported(unsigned int sampleRate);
static int32_t isChannelSupported(unsigned int numChannels);
static int32_t isBitWidthSupported(unsigned int bitWidth);
static int32_t checkAndUpdateBitWidth(unsigned int *bitWidth);
static int32_t checkAndUpdateSampleRate(unsigned int *sampleRate);
static bool isUSBOutDevice(pal_device_id_t);
static std::shared_ptr<Device> getObject(pal_device_id_t id);
~USB();
};
#endif //USB_H

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ULTRASOUNDDEVICE_H
#define ULTRASOUNDDEVICE_H
#include "Device.h"
//Ultrasound_device(RX)
class UltrasoundDevice : public Device
{
protected:
static std::shared_ptr<Device> objRx;
static std::shared_ptr<Device> objTx;
UltrasoundDevice(struct pal_device *device, std::shared_ptr<ResourceManager> Rm);
public:
static std::shared_ptr<Device> getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm);
static std::shared_ptr<Device> getObject(pal_device_id_t id);
virtual ~UltrasoundDevice();
};
#endif //ULTRASOUNDDEVICE_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#define LOG_TAG "PAL: DummyDev"
#include "DummyDev.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
#include "PayloadBuilder.h"
#include "Stream.h"
#include "Session.h"
std::shared_ptr<Device> DummyDev::objRx = nullptr;
std::shared_ptr<Device> DummyDev::objTx = nullptr;
std::shared_ptr<Device> DummyDev::getObject(pal_device_id_t id)
{
if (id == PAL_DEVICE_OUT_DUMMY)
return objRx;
else
return objTx;
}
std::shared_ptr<Device> DummyDev::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (device->id == PAL_DEVICE_OUT_DUMMY) {
if (!objRx) {
PAL_INFO(LOG_TAG, "creating instance for %d", device->id);
std::shared_ptr<Device> sp(new DummyDev(device, Rm));
objRx = sp;
}
return objRx;
} else {
if (!objTx) {
PAL_INFO(LOG_TAG, "creating instance for %d", device->id);
std::shared_ptr<Device> sp(new DummyDev(device, Rm));
objTx = sp;
}
return objTx;
}
}
DummyDev::DummyDev(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
DummyDev::~DummyDev()
{
}

View File

@@ -0,0 +1,181 @@
/* * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: ECRefDevice"
#include "ECRefDevice.h"
#include "ResourceManager.h"
#include "Device.h"
#include "PayloadBuilder.h"
#include "Stream.h"
#include "Session.h"
#include "kvh2xml.h"
#include <vector>
std::shared_ptr<Device> ECRefDevice::obj = nullptr;
std::shared_ptr<Device> ECRefDevice::getObject()
{
return obj;
}
std::shared_ptr<Device> ECRefDevice::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new ECRefDevice(device, Rm));
obj = sp;
}
return obj;
}
ECRefDevice::ECRefDevice(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
rm = Rm;
memset(&mDeviceAttr, 0, sizeof(struct pal_device));
memcpy(&mDeviceAttr, device, sizeof(struct pal_device));
}
ECRefDevice::~ECRefDevice()
{
}
int32_t ECRefDevice::isSampleRateSupported(int32_t sampleRate)
{
int32_t rc = 0;
if(sampleRate != SAMPLINGRATE_48K) {
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
}
return rc;
}
int32_t ECRefDevice::isChannelSupported(int32_t numChannels)
{
int32_t rc = 0;
if(numChannels != CHANNELS_1){
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
}
return rc;
}
int32_t ECRefDevice::isBitWidthSupported(int32_t bitWidth)
{
int32_t rc = 0;
if (bitWidth != BITWIDTH_16){
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
}
return rc;
}
void ECRefDevice::checkAndUpdateBitWidth(uint32_t *bitWidth)
{
if (*bitWidth != BITWIDTH_16){
*bitWidth = BITWIDTH_16;
PAL_DBG(LOG_TAG, "bit width not supported, setting to default 16 bit");
}
}
void ECRefDevice::checkAndUpdateSampleRate(uint32_t *sampleRate)
{
if(*sampleRate != SAMPLINGRATE_48K) {
*sampleRate = SAMPLINGRATE_48K;
PAL_ERR(LOG_TAG, "sample rate not supported, setting to default 48k");
}
}
int ECRefDevice::start()
{
int status = 0;
Stream *stream = NULL;
Session *session = NULL;
std::vector<Stream*> activestreams;
std::shared_ptr<PayloadBuilder> builder = std::make_shared<PayloadBuilder>();
std::string backEndName;
uint8_t* paramData = NULL;
size_t paramSize = 0;
uint32_t ratMiid = 0;
codecConfig.sample_rate = SAMPLINGRATE_48K;
codecConfig.bit_width = BITWIDTH_16;
codecConfig.ch_info.channels = CHANNELS_1;
if (customPayload)
free(customPayload);
customPayload = NULL;
customPayloadSize = 0;
rm->getBackendName(mDeviceAttr.id, backEndName);
status = rm->getActiveStream_l(activestreams, getObject());
if ((0 != status) || (activestreams.size() == 0)) {
PAL_ERR(LOG_TAG, "no active stream available");
status = -EINVAL;
goto error;
}
stream = static_cast<Stream *>(activestreams[0]);
stream->getAssociatedSession(&session);
/* RAT Module Configuration */
status = session->getMIID(backEndName.c_str(), RAT_RENDER, &ratMiid);
if (status) {
PAL_ERR(LOG_TAG, "Failed to get tag info %x, status = %d",
RAT_RENDER, status);
goto error;
}
builder->payloadRATConfig(&paramData, &paramSize, ratMiid, &codecConfig);
if (paramSize) {
updateCustomPayload(paramData, paramSize);
free(paramData);
paramData = NULL;
paramSize = 0;
} else {
status = -EINVAL;
PAL_ERR(LOG_TAG, "Invalid RAT module param size");
goto error;
}
status = Device::start();
error:
PAL_DBG(LOG_TAG, "Exit");
return status;
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: ExtEC"
#include "ExtEC.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> ExtEC::obj = nullptr;
std::shared_ptr<Device> ExtEC::getObject()
{
return obj;
}
std::shared_ptr<Device> ExtEC::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new ExtEC(device, Rm));
obj = sp;
}
return obj;
}
ExtEC::ExtEC(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
ExtEC::ExtEC()
{
}
ExtEC::~ExtEC()
{
}
int32_t ExtEC::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t ExtEC::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t ExtEC::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: ExtModem"
#include "ExtModem.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> ExtModem::obj = nullptr;
std::shared_ptr<Device> ExtModem::getObject()
{
return obj;
}
std::shared_ptr<Device> ExtModem::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new ExtModem(device, Rm));
obj = sp;
}
return obj;
}
ExtModem::ExtModem(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
ExtModem::~ExtModem()
{
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: ExtModemMic"
#include "ExtModemMic.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> ExtModemMic::obj = nullptr;
std::shared_ptr<Device> ExtModemMic::getObject()
{
return obj;
}
std::shared_ptr<Device> ExtModemMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new ExtModemMic(device, Rm));
obj = sp;
}
return obj;
}
ExtModemMic::ExtModemMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
ExtModemMic::~ExtModemMic()
{
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: FMDevice"
#include "ResourceManager.h"
#include "FMDevice.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> FMDevice::obj = nullptr;
std::shared_ptr<Device> FMDevice::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj){
std::shared_ptr<Device> sp(new FMDevice(device, Rm));
obj = sp;
}
return obj;
}
int32_t FMDevice::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t FMDevice::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
case CHANNELS_8:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t FMDevice::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: Handset"
#include "Handset.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
#include "SpeakerProtection.h"
std::shared_ptr<Device> Handset::obj = nullptr;
std::shared_ptr<Device> Handset::getObject()
{
return obj;
}
std::shared_ptr<Device> Handset::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
if (ResourceManager::isHandsetProtectionEnabled &&
ResourceManager::isSpeakerProtectionEnabled) {
std::shared_ptr<Device> sp(new SpeakerProtection(device, Rm));
obj = sp;
} else {
std::shared_ptr<Device> sp(new Handset(device, Rm));
obj = sp;
}
}
return obj;
}
Handset::Handset(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
Handset::~Handset()
{
}
int32_t Handset::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t Handset::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t Handset::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: HandsetMic"
#include "HandsetMic.h"
#include <tinyalsa/asoundlib.h>
#include "PalAudioRoute.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> HandsetMic::obj = nullptr;
std::shared_ptr<Device> HandsetMic::getObject()
{
return obj;
}
std::shared_ptr<Device> HandsetMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new HandsetMic(device, Rm));
obj = sp;
}
return obj;
}
HandsetMic::HandsetMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
HandsetMic::~HandsetMic()
{
}
int32_t HandsetMic::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {\
//check what all need to be added
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t HandsetMic::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
//check what all needed
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t HandsetMic::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: HandsetVaMic"
#include "HandsetVaMic.h"
#include <tinyalsa/asoundlib.h>
#include "PalAudioRoute.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> HandsetVaMic::obj = nullptr;
std::shared_ptr<Device> HandsetVaMic::getObject()
{
return obj;
}
std::shared_ptr<Device> HandsetVaMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new HandsetVaMic(device, Rm));
obj = sp;
}
return obj;
}
HandsetVaMic::HandsetVaMic(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
HandsetVaMic::~HandsetVaMic(void)
{
}
int32_t HandsetVaMic::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {\
//check what all need to be added
case SAMPLINGRATE_16K:
case SAMPLINGRATE_48K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t HandsetVaMic::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
//check what all needed
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t HandsetVaMic::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,207 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: HapticsDev"
#include "HapticsDev.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
#include "HapticsDevProtection.h"
std::shared_ptr<Device> HapticsDev::obj = nullptr;
std::shared_ptr<Device> HapticsDev::getObject()
{
return obj;
}
std::shared_ptr<Device> HapticsDev::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
if (ResourceManager::isHapticsProtectionEnabled &&
ResourceManager::isHapticsthroughWSA) {
std::shared_ptr<Device> sp(new HapticsDevProtection(device, Rm));
obj = sp;
} else {
std::shared_ptr<Device> sp(new HapticsDev(device, Rm));
obj = sp;
}
}
return obj;
}
HapticsDev::HapticsDev(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
#ifdef SEC_AUDIO_SUPPORT_HAPTIC_PLAYBACK
rm = Rm;
hapticSource = HAPTIC_SOURCE_ACH;
#endif
}
HapticsDev::~HapticsDev()
{
}
int32_t HapticsDev::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t HapticsDev::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t HapticsDev::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}
#ifdef SEC_AUDIO_SUPPORT_HAPTIC_PLAYBACK
int HapticsDev::start()
{
// in Device::open(), mixer control "Haptics Source" is set to ach by the path "haptics-dev"
// so if haptic source is a2h, set mixer control to a2h again.
if (hapticSource == HAPTIC_SOURCE_A2H) {
setHapticSource(hapticSource);
}
return Device::start();
}
int32_t HapticsDev::setParameter(uint32_t param_id, void *param)
{
pal_param_haptic_source_t* param_haptic_source = (pal_param_haptic_source_t *)param;
hapticSource = param_haptic_source->haptic_source;
std::shared_ptr<Device> dev = nullptr;
std::vector<Stream*> activestreams;
dev = Device::getInstance(&deviceAttr, rm);
int status = rm->getActiveStream_l(activestreams, dev);
if ((0 != status) || (activestreams.size() == 0)) {
PAL_VERBOSE(LOG_TAG, "no active stream available");
} else {
// if haptic device is active, set mixer control to switch haptic source
setHapticSource(hapticSource);
}
return 0;
}
void HapticsDev::setHapticSource(haptic_source_t source)
{
int ret = 0;
struct mixer *mixer = NULL;
struct mixer_ctl *ctl = NULL;
char mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = "Haptics Source";
ret = rm->getHwAudioMixer(&mixer);
if (ret) {
PAL_ERR(LOG_TAG," mixer error");
goto exit;
}
ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
if (!ctl) {
PAL_ERR(LOG_TAG, "Could not get ctl for mixer cmd - %s", mixer_ctl_name);
goto exit;
}
PAL_DBG(LOG_TAG, "Setting mixer control: Haptics Source, value: %d", (int)source);
mixer_ctl_set_value(ctl, 0, (int)source);
exit:
return;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,160 @@
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: Headphone"
#include "Headphone.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> Headphone::obj = nullptr;
std::shared_ptr<Device> Headphone::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new Headphone(device, Rm));
obj = sp;
}
return obj;
}
std::shared_ptr<Device> Headphone::getObject(pal_device_id_t id)
{
if (obj) {
if (obj->getSndDeviceId() == id)
return obj;
}
return NULL;
}
Headphone::Headphone(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
Headphone::~Headphone()
{
PAL_ERR(LOG_TAG, "dtor called");
}
int32_t Headphone::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %d", sampleRate);
if (sampleRate % SAMPLINGRATE_44K == 0)
return rc;
switch (sampleRate) {
case SAMPLINGRATE_44K:
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
case SAMPLINGRATE_192K:
case SAMPLINGRATE_384K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
//TBD why do these channels have to be supported, headphones support only 1/2?
int32_t Headphone::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
case CHANNELS_2:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t Headphone::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}
int32_t Headphone::checkAndUpdateBitWidth(uint32_t *bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", *bitWidth);
switch (*bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
*bitWidth = BITWIDTH_16;
PAL_DBG(LOG_TAG, "bit width not supported, setting to default 16 bit");
break;
}
return rc;
}
int32_t Headphone::checkAndUpdateSampleRate(uint32_t *sampleRate)
{
int32_t rc = 0;
if ((*sampleRate % SAMPLINGRATE_44K == 0) &&
(NATIVE_AUDIO_MODE_MULTIPLE_MIX_IN_DSP == ResourceManager::getNativeAudioSupport())) {
PAL_DBG(LOG_TAG, "napb: setting sampling rate to %d", *sampleRate);
} else if (*sampleRate <= SAMPLINGRATE_48K)
*sampleRate = SAMPLINGRATE_48K;
else if (*sampleRate > SAMPLINGRATE_48K && *sampleRate <= SAMPLINGRATE_96K)
*sampleRate = SAMPLINGRATE_96K;
else if (*sampleRate > SAMPLINGRATE_96K && *sampleRate <= SAMPLINGRATE_192K)
*sampleRate = SAMPLINGRATE_192K;
else if (*sampleRate > SAMPLINGRATE_192K && *sampleRate <= SAMPLINGRATE_384K)
*sampleRate = SAMPLINGRATE_384K;
PAL_DBG(LOG_TAG, "sampleRate %d", *sampleRate);
return rc;
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: HeadsetMic"
#include "HeadsetMic.h"
#include <tinyalsa/asoundlib.h>
#include "PalAudioRoute.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> HeadsetMic::obj = nullptr;
std::shared_ptr<Device> HeadsetMic::getObject()
{
return obj;
}
std::shared_ptr<Device> HeadsetMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new HeadsetMic(device, Rm));
obj = sp;
}
return obj;
}
HeadsetMic::HeadsetMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
HeadsetMic::~HeadsetMic()
{
}
int32_t HeadsetMic::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {\
//check what all need to be added
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t HeadsetMic::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t HeadsetMic::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}
int32_t HeadsetMic::checkAndUpdateBitWidth(uint32_t *bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", *bitWidth);
switch (*bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
*bitWidth = BITWIDTH_16;
PAL_DBG(LOG_TAG, "bit width not supported, setting to default 16 bit");
break;
}
return rc;
}
int32_t HeadsetMic::checkAndUpdateSampleRate(uint32_t *sampleRate)
{
int32_t rc = 0;
/* TODO: support native 44.1 later */
if (*sampleRate < SAMPLINGRATE_48K)
*sampleRate = SAMPLINGRATE_48K;
else if (*sampleRate > SAMPLINGRATE_48K && *sampleRate < SAMPLINGRATE_96K)
*sampleRate = SAMPLINGRATE_96K;
else if (*sampleRate > SAMPLINGRATE_96K && *sampleRate < SAMPLINGRATE_192K)
*sampleRate = SAMPLINGRATE_192K;
else if (*sampleRate > SAMPLINGRATE_192K && *sampleRate < SAMPLINGRATE_384K)
*sampleRate = SAMPLINGRATE_384K;
PAL_DBG(LOG_TAG, "sampleRate %d", *sampleRate);
return rc;
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: HeadsetVaMic"
#include "HeadsetVaMic.h"
#include <tinyalsa/asoundlib.h>
#include "PalAudioRoute.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> HeadsetVaMic::obj = nullptr;
std::shared_ptr<Device> HeadsetVaMic::getObject()
{
return obj;
}
std::shared_ptr<Device> HeadsetVaMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new HeadsetVaMic(device, Rm));
obj = sp;
}
return obj;
}
HeadsetVaMic::HeadsetVaMic(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
HeadsetVaMic::~HeadsetVaMic(void)
{
}
int32_t HeadsetVaMic::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {\
//check what all need to be added
case SAMPLINGRATE_16K:
case SAMPLINGRATE_48K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t HeadsetVaMic::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
//check what all needed
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t HeadsetVaMic::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

View File

@@ -0,0 +1,270 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#define LOG_TAG "PAL: RTProxy"
#define LOG_TAG_OUT "PAL: RTProxyOut"
#include "RTProxy.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
#include "PayloadBuilder.h"
#include "Stream.h"
#include "Session.h"
RTProxyIn::RTProxyIn(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
rm = Rm;
setDeviceAttributes(*device);
}
RTProxyIn::~RTProxyIn()
{
}
int32_t RTProxyIn::isSampleRateSupported(uint32_t sampleRate)
{
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
/* Proxy supports all sample rates, accept by default */
return 0;
}
int32_t RTProxyIn::isChannelSupported(uint32_t numChannels)
{
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
/* Proxy supports all channels, accept by default */
return 0;
}
int32_t RTProxyIn::isBitWidthSupported(uint32_t bitWidth)
{
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
/* Proxy supports all bitwidths, accept by default */
return 0;
}
std::shared_ptr<Device> RTProxyIn::objPlay = nullptr;
std::shared_ptr<Device> RTProxyIn::objRecord = nullptr;
std::shared_ptr<Device> RTProxyIn::getObject(pal_device_id_t id)
{
std::shared_ptr<Device> obj = nullptr;
if (id == PAL_DEVICE_IN_TELEPHONY_RX ||
id == PAL_DEVICE_IN_PROXY) {
obj = objPlay;
}
if (id == PAL_DEVICE_IN_RECORD_PROXY) {
obj = objRecord;
}
return obj;
}
std::shared_ptr<Device> RTProxyIn::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
std::shared_ptr<Device> obj = nullptr;
if (device->id == PAL_DEVICE_IN_TELEPHONY_RX ||
device->id == PAL_DEVICE_IN_PROXY) {
if (!objPlay) {
std::shared_ptr<Device> sp(new RTProxyIn(device, Rm));
objPlay = sp;
}
obj = objPlay;
}
if (device->id == PAL_DEVICE_IN_RECORD_PROXY) {
if (!objRecord) {
std::shared_ptr<Device> sp(new RTProxyIn(device, Rm));
objRecord = sp;
}
obj = objRecord;
}
return obj;
}
int RTProxyIn::start() {
int status = 0;
uint8_t* paramData = NULL;
size_t paramSize = 0;
uint32_t ratMiid = 0;
//struct pal_media_config config;
Stream *stream = NULL;
Session *session = NULL;
std::vector<Stream*> activestreams;
std::shared_ptr<Device> dev = nullptr;
std::string backEndName;
PayloadBuilder* builder = new PayloadBuilder();
if (customPayload)
free(customPayload);
customPayload = NULL;
customPayloadSize = 0;
mDeviceMutex.lock();
if (0 < deviceStartStopCount) {
goto start;
}
rm->getBackendName(deviceAttr.id, backEndName);
dev = getInstance(&deviceAttr, rm);
status = rm->getActiveStream_l(activestreams, dev);
if ((0 != status) || (activestreams.size() == 0)) {
PAL_ERR(LOG_TAG, "no active stream available");
status = -EINVAL;
goto error;
}
stream = static_cast<Stream *>(activestreams[0]);
stream->getAssociatedSession(&session);
status = session->getMIID(backEndName.c_str(), RAT_RENDER, &ratMiid);
if (status) {
PAL_INFO(LOG_TAG,
"Failed to get tag info %x Skipping RAT Configuration Setup, status = %d",
RAT_RENDER, status);
//status = -EINVAL;
status = 0;
goto start;
}
builder->payloadRATConfig(&paramData, &paramSize, ratMiid, &deviceAttr.config);
if (dev && paramSize) {
dev->updateCustomPayload(paramData, paramSize);
if (paramData)
free(paramData);
paramData = NULL;
paramSize = 0;
} else {
status = -EINVAL;
PAL_ERR(LOG_TAG, "Invalid RAT module param size");
goto error;
}
start:
status = Device::start_l();
error:
mDeviceMutex.unlock();
if (builder) {
delete builder;
builder = NULL;
}
return status;
}
std::shared_ptr<Device> RTProxyOut::objPlay = nullptr;
std::shared_ptr<Device> RTProxyOut::objRecord = nullptr;
RTProxyOut::RTProxyOut(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
rm = Rm;
setDeviceAttributes(*device);
}
std::shared_ptr<Device> RTProxyOut::getObject(pal_device_id_t id)
{
std::shared_ptr<Device> obj = nullptr;
if (id == PAL_DEVICE_OUT_HEARING_AID ||
id == PAL_DEVICE_OUT_PROXY) {
obj = objPlay;
}
if (id == PAL_DEVICE_OUT_RECORD_PROXY) {
obj = objRecord;
}
return obj;
}
std::shared_ptr<Device> RTProxyOut::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
std::shared_ptr<Device> obj = nullptr;
if (device->id == PAL_DEVICE_OUT_HEARING_AID ||
device->id == PAL_DEVICE_OUT_PROXY) {
if (!objPlay) {
std::shared_ptr<Device> sp(new RTProxyOut(device, Rm));
objPlay = sp;
}
obj = objPlay;
}
if (device->id == PAL_DEVICE_OUT_RECORD_PROXY) {
if (!objRecord) {
std::shared_ptr<Device> sp(new RTProxyOut(device, Rm));
objRecord = sp;
}
obj = objRecord;
}
return obj;
}
int32_t RTProxyOut::isSampleRateSupported(uint32_t sampleRate)
{
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
/* Proxy supports all sample rates, accept by default */
return 0;
}
int32_t RTProxyOut::isChannelSupported(uint32_t numChannels)
{
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
/* Proxy supports all channels, accept by default */
return 0;
}
int32_t RTProxyOut::isBitWidthSupported(uint32_t bitWidth)
{
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
/* Proxy supports all bitwidths, accept by default */
return 0;
}
int RTProxyOut::start() {
if (customPayload)
free(customPayload);
customPayload = NULL;
customPayloadSize = 0;
return Device::start();
}
RTProxyOut::~RTProxyOut()
{
}

View File

@@ -0,0 +1,201 @@
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: Speaker"
#include "Speaker.h"
#include "ResourceManager.h"
#include "SpeakerProtection.h"
#include "Device.h"
#include "kvh2xml.h"
#ifdef ENABLE_TFA98XX_SUPPORT
#include "SpeakerProtectionTFA.h"
#elif ENABLE_TAS_SPK_PROT
#include "SpeakerProtectionTI.h"
#endif
std::shared_ptr<Device> Speaker::obj = nullptr;
std::shared_ptr<Device> Speaker::getObject()
{
return obj;
}
std::shared_ptr<Device> Speaker::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
if (ResourceManager::isSpeakerProtectionEnabled) {
std::shared_ptr<Device> sp(new SpeakerProtection(device, Rm));
obj = sp;
}
else {
#ifdef ENABLE_TFA98XX_SUPPORT
std::shared_ptr<Device> sp(new SpeakerProtectionTFA(device, Rm));
#elif ENABLE_TAS_SPK_PROT
std::shared_ptr<Device> sp(new SpeakerProtectionTI(device, Rm));
#else
std::shared_ptr<Device> sp(new Speaker(device, Rm));
#endif
obj = sp;
}
}
return obj;
}
Speaker::Speaker(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
rm = Rm;
curMuteStatus = PAL_DEVICE_SPEAKER_UNMUTE;
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW
}
Speaker::Speaker()
{
}
Speaker::~Speaker()
{
}
int32_t Speaker::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t Speaker::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
case CHANNELS_8:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t Speaker::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}
int Speaker::close()
{
int status = 0;
status = Device::close();
if (status == 0 && deviceCount == 0) {
std::shared_ptr<ResourceManager> Rm = nullptr;
Rm = ResourceManager::getInstance();
if (Rm && Rm->isChargeConcurrencyEnabled && Rm->getChargerOnlineState() &&
Rm->getConcurrentBoostState()) {
status = Rm->chargerListenerSetBoostState(false, CONCURRENCY_PB_STOPS);
if (0 != status)
PAL_ERR(LOG_TAG, "Failed to notify PMIC: %d", status);
} else {
PAL_DBG(LOG_TAG, "Concurrent State unchanged, ignore notifying");
}
}
return status;
}
#if defined(SEC_AUDIO_DUAL_SPEAKER) || defined(SEC_AUDIO_SCREEN_MIRRORING) // { SUPPORT_VOIP_VIA_SMART_VIEW
int32_t Speaker::setParameter(uint32_t param_id, void *param)
{
int ret = 0;
PAL_DBG(LOG_TAG, " Enter.");
struct audio_route *audioRoute = NULL;
ret = rm->getAudioRoute(&audioRoute);
if (0 != ret) {
PAL_ERR(LOG_TAG, "Failed to get the audio_route address status %d", ret);
return 0;
}
pal_param_speaker_status_t* param_speaker_status = (pal_param_speaker_status_t *)param;
if (curMuteStatus == PAL_DEVICE_SPEAKER_MUTE) { // current : full mute
if (param_speaker_status->mute_status == PAL_DEVICE_SPEAKER_UNMUTE) {
disableDevice(audioRoute, "amp-mute");
curMuteStatus = PAL_DEVICE_SPEAKER_UNMUTE; // full mute -> full unmute
}
} else { // current : full unmute, upper mute, upper unmute
if (param_speaker_status->mute_status == PAL_DEVICE_SPEAKER_MUTE) {
if (curMuteStatus == PAL_DEVICE_UPPER_SPEAKER_MUTE) {
disableDevice(audioRoute, "upper-spk-amp-mute");
}
enableDevice(audioRoute, "amp-mute");
curMuteStatus = PAL_DEVICE_SPEAKER_MUTE; // upper mute or full unmute -> full mute
} else if (param_speaker_status->mute_status == PAL_DEVICE_UPPER_SPEAKER_MUTE) {
enableDevice(audioRoute, "upper-spk-amp-mute");
curMuteStatus = PAL_DEVICE_UPPER_SPEAKER_MUTE; // full unmute -> upper mute
} else if (param_speaker_status->mute_status == PAL_DEVICE_UPPER_SPEAKER_UNMUTE) {
disableDevice(audioRoute, "upper-spk-amp-mute");
curMuteStatus = PAL_DEVICE_SPEAKER_UNMUTE; // upper mute -> full unmute
}
}
return 0;
}
#endif // } SUPPORT_VOIP_VIA_SMART_VIEW

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: SpeakerMic"
#include "SpeakerMic.h"
#include <tinyalsa/asoundlib.h>
#include "PalAudioRoute.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> SpeakerMic::obj = nullptr;
std::shared_ptr<Device> SpeakerMic::getObject()
{
return obj;
}
std::shared_ptr<Device> SpeakerMic::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (!obj) {
std::shared_ptr<Device> sp(new SpeakerMic(device, Rm));
obj = sp;
}
return obj;
}
SpeakerMic::SpeakerMic(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
SpeakerMic::~SpeakerMic()
{
}
int32_t SpeakerMic::isSampleRateSupported(uint32_t sampleRate)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "sampleRate %u", sampleRate);
switch (sampleRate) {
case SAMPLINGRATE_48K:
case SAMPLINGRATE_96K:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "sample rate not supported rc %d", rc);
break;
}
return rc;
}
int32_t SpeakerMic::isChannelSupported(uint32_t numChannels)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "numChannels %u", numChannels);
switch (numChannels) {
case CHANNELS_1:
case CHANNELS_2:
case CHANNELS_3:
case CHANNELS_4:
case CHANNELS_8:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "channels not supported rc %d", rc);
break;
}
return rc;
}
int32_t SpeakerMic::isBitWidthSupported(uint32_t bitWidth)
{
int32_t rc = 0;
PAL_DBG(LOG_TAG, "bitWidth %u", bitWidth);
switch (bitWidth) {
case BITWIDTH_16:
case BITWIDTH_24:
case BITWIDTH_32:
break;
default:
rc = -EINVAL;
PAL_ERR(LOG_TAG, "bit width not supported rc %d", rc);
break;
}
return rc;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_TAG "PAL: UltrasoundDevice"
#include "UltrasoundDevice.h"
#include "ResourceManager.h"
#include "Device.h"
#include "kvh2xml.h"
std::shared_ptr<Device> UltrasoundDevice::objRx = nullptr;
std::shared_ptr<Device> UltrasoundDevice::objTx = nullptr;
std::shared_ptr<Device> UltrasoundDevice::getObject(pal_device_id_t id)
{
if (id == PAL_DEVICE_OUT_ULTRASOUND ||
id == PAL_DEVICE_OUT_ULTRASOUND_DEDICATED)
return objRx;
else
return objTx;
}
std::shared_ptr<Device> UltrasoundDevice::getInstance(struct pal_device *device,
std::shared_ptr<ResourceManager> Rm)
{
if (device->id == PAL_DEVICE_OUT_ULTRASOUND ||
device->id == PAL_DEVICE_OUT_ULTRASOUND_DEDICATED) {
if (!objRx) {
PAL_INFO(LOG_TAG, "%s creating instance for %d\n", __func__, device->id);
std::shared_ptr<Device> sp(new UltrasoundDevice(device, Rm));
objRx = sp;
}
return objRx;
} else {
if (!objTx) {
PAL_INFO(LOG_TAG, "%s creating instance for %d\n", __func__, device->id);
std::shared_ptr<Device> sp(new UltrasoundDevice(device, Rm));
objTx = sp;
}
return objTx;
}
}
UltrasoundDevice::UltrasoundDevice(struct pal_device *device, std::shared_ptr<ResourceManager> Rm) :
Device(device, Rm)
{
}
UltrasoundDevice::~UltrasoundDevice()
{
}