2013-01-18 00:50:22 +00:00
|
|
|
/*
|
2014-03-21 21:51:50 +00:00
|
|
|
* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
|
2013-10-01 22:49:05 +00:00
|
|
|
* Not a contribution.
|
|
|
|
*
|
2013-01-18 00:50:22 +00:00
|
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-05-14 22:27:20 +00:00
|
|
|
#ifndef QCOM_AUDIO_HW_H
|
|
|
|
#define QCOM_AUDIO_HW_H
|
|
|
|
|
|
|
|
#include <cutils/list.h>
|
2013-01-18 00:50:22 +00:00
|
|
|
#include <hardware/audio.h>
|
|
|
|
#include <tinyalsa/asoundlib.h>
|
2013-07-17 22:22:04 +00:00
|
|
|
#include <tinycompress/tinycompress.h>
|
2013-01-18 00:50:22 +00:00
|
|
|
|
|
|
|
#include <audio_route/audio_route.h>
|
2013-10-01 22:49:05 +00:00
|
|
|
#include "voice.h"
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2013-09-13 00:45:53 +00:00
|
|
|
#define VISUALIZER_LIBRARY_PATH "/system/lib/soundfx/libqcomvisualizer.so"
|
2013-11-13 21:31:50 +00:00
|
|
|
#define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/system/lib/soundfx/libqcompostprocbundle.so"
|
2013-09-13 00:45:53 +00:00
|
|
|
|
2014-03-21 21:51:50 +00:00
|
|
|
#define BT_SCO_SAMPLE_RATE "bt-sco-samplerate"
|
|
|
|
#define BT_SCO_WB_SAMPLE_RATE "bt-sco-wb-samplerate"
|
|
|
|
|
2013-05-14 22:27:20 +00:00
|
|
|
/* Flags used to initialize acdb_settings variable that goes to ACDB library */
|
2014-03-27 14:17:56 +00:00
|
|
|
#define NONE_FLAG 0x00000000
|
2014-04-07 19:11:47 +00:00
|
|
|
#define ANC_FLAG 0x00000001
|
2014-03-27 14:17:56 +00:00
|
|
|
#define DMIC_FLAG 0x00000002
|
|
|
|
#define QMIC_FLAG 0x00000004
|
|
|
|
#define TTY_MODE_OFF 0x00000010
|
|
|
|
#define TTY_MODE_FULL 0x00000020
|
|
|
|
#define TTY_MODE_VCO 0x00000040
|
|
|
|
#define TTY_MODE_HCO 0x00000080
|
|
|
|
#define TTY_MODE_CLEAR 0xFFFFFF0F
|
|
|
|
#define FLUENCE_MODE_CLEAR 0xFFFFFFF0
|
2013-05-14 22:27:20 +00:00
|
|
|
|
2013-01-18 00:50:22 +00:00
|
|
|
#define ACDB_DEV_TYPE_OUT 1
|
|
|
|
#define ACDB_DEV_TYPE_IN 2
|
|
|
|
|
2013-05-14 22:27:20 +00:00
|
|
|
#define MAX_SUPPORTED_CHANNEL_MASKS 2
|
2013-10-06 19:52:49 +00:00
|
|
|
#define DEFAULT_HDMI_OUT_CHANNELS 2
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2014-05-11 19:35:52 +00:00
|
|
|
#define SND_CARD_STATE_OFFLINE 0
|
|
|
|
#define SND_CARD_STATE_ONLINE 1
|
2013-05-14 22:27:20 +00:00
|
|
|
typedef int snd_device_t;
|
2013-01-18 00:50:22 +00:00
|
|
|
|
|
|
|
/* These are the supported use cases by the hardware.
|
|
|
|
* Each usecase is mapped to a specific PCM device.
|
|
|
|
* Refer to pcm_device_table[].
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
USECASE_INVALID = -1,
|
|
|
|
/* Playback usecases */
|
|
|
|
USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0,
|
|
|
|
USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
|
|
|
|
USECASE_AUDIO_PLAYBACK_MULTI_CH,
|
2013-07-17 22:22:04 +00:00
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD,
|
2014-04-02 04:03:10 +00:00
|
|
|
#ifdef MULTIPLE_OFFLOAD_ENABLED
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD2,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD3,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD4,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD5,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD6,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD7,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD8,
|
|
|
|
USECASE_AUDIO_PLAYBACK_OFFLOAD9,
|
|
|
|
#endif
|
|
|
|
|
2013-10-06 21:39:35 +00:00
|
|
|
/* FM usecase */
|
|
|
|
USECASE_AUDIO_PLAYBACK_FM,
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2013-11-05 23:57:39 +00:00
|
|
|
/* HFP Use case*/
|
|
|
|
USECASE_AUDIO_HFP_SCO,
|
2013-12-20 21:23:39 +00:00
|
|
|
USECASE_AUDIO_HFP_SCO_WB,
|
2013-11-05 23:57:39 +00:00
|
|
|
|
2013-01-18 00:50:22 +00:00
|
|
|
/* Capture usecases */
|
|
|
|
USECASE_AUDIO_RECORD,
|
2013-10-25 23:26:03 +00:00
|
|
|
USECASE_AUDIO_RECORD_COMPRESS,
|
2013-01-18 00:50:22 +00:00
|
|
|
USECASE_AUDIO_RECORD_LOW_LATENCY,
|
2013-11-01 21:58:16 +00:00
|
|
|
USECASE_AUDIO_RECORD_FM_VIRTUAL,
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
/* Voice usecase */
|
2013-01-18 00:50:22 +00:00
|
|
|
USECASE_VOICE_CALL,
|
|
|
|
|
2013-10-01 22:49:05 +00:00
|
|
|
/* Voice extension usecases */
|
|
|
|
USECASE_VOICE2_CALL,
|
|
|
|
USECASE_VOLTE_CALL,
|
|
|
|
USECASE_QCHAT_CALL,
|
2014-02-13 01:58:59 +00:00
|
|
|
USECASE_VOWLAN_CALL,
|
2013-11-15 23:21:40 +00:00
|
|
|
USECASE_COMPRESS_VOIP_CALL,
|
2013-10-01 22:49:05 +00:00
|
|
|
|
2013-10-17 18:16:13 +00:00
|
|
|
USECASE_INCALL_REC_UPLINK,
|
|
|
|
USECASE_INCALL_REC_DOWNLINK,
|
|
|
|
USECASE_INCALL_REC_UPLINK_AND_DOWNLINK,
|
2013-12-04 00:54:40 +00:00
|
|
|
USECASE_INCALL_REC_UPLINK_COMPRESS,
|
|
|
|
USECASE_INCALL_REC_DOWNLINK_COMPRESS,
|
|
|
|
USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS,
|
2013-10-17 18:16:13 +00:00
|
|
|
|
2013-10-22 23:38:08 +00:00
|
|
|
USECASE_INCALL_MUSIC_UPLINK,
|
|
|
|
USECASE_INCALL_MUSIC_UPLINK2,
|
|
|
|
|
2013-10-28 21:06:03 +00:00
|
|
|
USECASE_AUDIO_SPKR_CALIB_RX,
|
|
|
|
USECASE_AUDIO_SPKR_CALIB_TX,
|
2013-01-18 00:50:22 +00:00
|
|
|
AUDIO_USECASE_MAX
|
|
|
|
} audio_usecase_t;
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tinyAlsa library interprets period size as number of frames
|
|
|
|
* one frame = channel_count * sizeof (pcm sample)
|
|
|
|
* so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
|
|
|
|
* DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
|
|
|
|
* We should take care of returning proper size when AudioFlinger queries for
|
|
|
|
* the buffer size of an input/output stream
|
|
|
|
*/
|
|
|
|
|
2013-07-17 22:22:04 +00:00
|
|
|
enum {
|
|
|
|
OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/
|
|
|
|
OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */
|
|
|
|
OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */
|
|
|
|
OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
OFFLOAD_STATE_IDLE,
|
|
|
|
OFFLOAD_STATE_PLAYING,
|
|
|
|
OFFLOAD_STATE_PAUSED,
|
|
|
|
};
|
|
|
|
|
2014-05-11 19:35:52 +00:00
|
|
|
enum {
|
|
|
|
PCM_ERROR_NONE,
|
|
|
|
PCM_ERROR_EIO,
|
|
|
|
PCM_ERROR_ENETRESET, /* For SSR */
|
|
|
|
};
|
|
|
|
|
2013-07-17 22:22:04 +00:00
|
|
|
struct offload_cmd {
|
|
|
|
struct listnode node;
|
|
|
|
int cmd;
|
|
|
|
int data[];
|
|
|
|
};
|
|
|
|
|
2014-03-10 21:43:05 +00:00
|
|
|
struct stream_app_type_cfg {
|
|
|
|
int sample_rate;
|
|
|
|
int bit_width;
|
|
|
|
int app_type;
|
|
|
|
};
|
|
|
|
|
2013-01-18 00:50:22 +00:00
|
|
|
struct stream_out {
|
|
|
|
struct audio_stream_out stream;
|
2013-02-27 22:31:02 +00:00
|
|
|
pthread_mutex_t lock; /* see note below on mutex acquisition order */
|
2013-07-17 22:22:04 +00:00
|
|
|
pthread_cond_t cond;
|
2013-01-18 00:50:22 +00:00
|
|
|
struct pcm_config config;
|
2013-07-17 22:22:04 +00:00
|
|
|
struct compr_config compr_config;
|
2013-01-18 00:50:22 +00:00
|
|
|
struct pcm *pcm;
|
2013-07-17 22:22:04 +00:00
|
|
|
struct compress *compr;
|
2013-01-18 00:50:22 +00:00
|
|
|
int standby;
|
|
|
|
int pcm_device_id;
|
2013-07-17 22:22:04 +00:00
|
|
|
unsigned int sample_rate;
|
2013-01-18 00:50:22 +00:00
|
|
|
audio_channel_mask_t channel_mask;
|
2013-07-17 22:22:04 +00:00
|
|
|
audio_format_t format;
|
2013-01-18 00:50:22 +00:00
|
|
|
audio_devices_t devices;
|
|
|
|
audio_output_flags_t flags;
|
|
|
|
audio_usecase_t usecase;
|
|
|
|
/* Array of supported channel mask configurations. +1 so that the last entry is always 0 */
|
|
|
|
audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1];
|
2013-04-04 16:19:12 +00:00
|
|
|
bool muted;
|
2013-09-10 16:04:31 +00:00
|
|
|
uint64_t written; /* total frames written, not cleared when entering standby */
|
2013-09-13 00:45:53 +00:00
|
|
|
audio_io_handle_t handle;
|
2014-03-10 21:43:05 +00:00
|
|
|
struct stream_app_type_cfg app_type_cfg;
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2013-07-17 22:22:04 +00:00
|
|
|
int non_blocking;
|
|
|
|
int playback_started;
|
|
|
|
int offload_state;
|
|
|
|
pthread_cond_t offload_cond;
|
|
|
|
pthread_t offload_thread;
|
|
|
|
struct listnode offload_cmd_list;
|
|
|
|
bool offload_thread_blocked;
|
|
|
|
|
|
|
|
stream_callback_t offload_callback;
|
|
|
|
void *offload_cookie;
|
2013-07-26 07:00:15 +00:00
|
|
|
struct compr_gapless_mdata gapless_mdata;
|
|
|
|
int send_new_metadata;
|
2014-05-11 19:35:52 +00:00
|
|
|
int pcm_error_type;
|
2013-01-18 00:50:22 +00:00
|
|
|
|
|
|
|
struct audio_device *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stream_in {
|
|
|
|
struct audio_stream_in stream;
|
2013-02-27 22:31:02 +00:00
|
|
|
pthread_mutex_t lock; /* see note below on mutex acquisition order */
|
2013-01-18 00:50:22 +00:00
|
|
|
struct pcm_config config;
|
|
|
|
struct pcm *pcm;
|
|
|
|
int standby;
|
|
|
|
int source;
|
|
|
|
int pcm_device_id;
|
|
|
|
int device;
|
|
|
|
audio_channel_mask_t channel_mask;
|
|
|
|
audio_usecase_t usecase;
|
2013-04-16 22:55:53 +00:00
|
|
|
bool enable_aec;
|
2013-11-07 23:42:19 +00:00
|
|
|
bool enable_ns;
|
2013-11-15 23:21:40 +00:00
|
|
|
audio_format_t format;
|
2014-05-11 19:35:52 +00:00
|
|
|
int pcm_error_type;
|
2013-01-18 00:50:22 +00:00
|
|
|
|
|
|
|
struct audio_device *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PCM_PLAYBACK,
|
|
|
|
PCM_CAPTURE,
|
2013-11-15 23:21:40 +00:00
|
|
|
VOICE_CALL,
|
2013-11-05 23:57:39 +00:00
|
|
|
VOIP_CALL,
|
|
|
|
PCM_HFP_CALL
|
2013-01-18 00:50:22 +00:00
|
|
|
} usecase_type_t;
|
|
|
|
|
2013-03-01 04:54:57 +00:00
|
|
|
union stream_ptr {
|
|
|
|
struct stream_in *in;
|
|
|
|
struct stream_out *out;
|
|
|
|
};
|
|
|
|
|
2013-01-18 00:50:22 +00:00
|
|
|
struct audio_usecase {
|
2013-02-28 07:01:21 +00:00
|
|
|
struct listnode list;
|
2013-01-18 00:50:22 +00:00
|
|
|
audio_usecase_t id;
|
|
|
|
usecase_type_t type;
|
|
|
|
audio_devices_t devices;
|
2013-03-11 06:50:28 +00:00
|
|
|
snd_device_t out_snd_device;
|
|
|
|
snd_device_t in_snd_device;
|
2013-03-01 04:54:57 +00:00
|
|
|
union stream_ptr stream;
|
2013-01-18 00:50:22 +00:00
|
|
|
};
|
|
|
|
|
2014-05-11 19:35:52 +00:00
|
|
|
struct sound_card_status {
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
int state;
|
|
|
|
};
|
|
|
|
|
2014-03-10 21:43:05 +00:00
|
|
|
struct stream_format {
|
|
|
|
struct listnode list;
|
|
|
|
audio_format_t format;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct streams_output_cfg {
|
|
|
|
struct listnode list;
|
|
|
|
audio_output_flags_t flags;
|
|
|
|
struct listnode format_list;
|
|
|
|
struct stream_app_type_cfg app_type_cfg;
|
|
|
|
};
|
|
|
|
|
2013-01-18 00:50:22 +00:00
|
|
|
struct audio_device {
|
|
|
|
struct audio_hw_device device;
|
2013-02-27 22:31:02 +00:00
|
|
|
pthread_mutex_t lock; /* see note below on mutex acquisition order */
|
2013-01-18 00:50:22 +00:00
|
|
|
struct mixer *mixer;
|
|
|
|
audio_mode_t mode;
|
|
|
|
audio_devices_t out_device;
|
2013-02-15 03:04:54 +00:00
|
|
|
struct stream_in *active_input;
|
2013-03-01 04:54:57 +00:00
|
|
|
struct stream_out *primary_output;
|
2013-01-18 00:50:22 +00:00
|
|
|
bool bluetooth_nrec;
|
|
|
|
bool screen_off;
|
2013-05-14 22:27:20 +00:00
|
|
|
int *snd_dev_ref_cnt;
|
2013-02-28 07:01:21 +00:00
|
|
|
struct listnode usecase_list;
|
2014-03-10 21:43:05 +00:00
|
|
|
struct listnode streams_output_cfg_list;
|
2013-01-18 00:50:22 +00:00
|
|
|
struct audio_route *audio_route;
|
|
|
|
int acdb_settings;
|
2013-05-24 23:55:17 +00:00
|
|
|
bool speaker_lr_swap;
|
2013-10-01 22:49:05 +00:00
|
|
|
struct voice voice;
|
2013-10-06 19:52:49 +00:00
|
|
|
unsigned int cur_hdmi_channels;
|
2014-02-14 22:45:49 +00:00
|
|
|
unsigned int cur_wfd_channels;
|
2013-01-18 00:50:22 +00:00
|
|
|
|
2013-12-04 19:57:47 +00:00
|
|
|
int snd_card;
|
2013-05-14 22:27:20 +00:00
|
|
|
void *platform;
|
2014-04-02 04:03:10 +00:00
|
|
|
unsigned int offload_usecases_state;
|
2013-09-13 00:45:53 +00:00
|
|
|
void *visualizer_lib;
|
2013-11-13 21:31:50 +00:00
|
|
|
int (*visualizer_start_output)(audio_io_handle_t, int);
|
|
|
|
int (*visualizer_stop_output)(audio_io_handle_t, int);
|
|
|
|
void *offload_effects_lib;
|
|
|
|
int (*offload_effects_start_output)(audio_io_handle_t, int);
|
|
|
|
int (*offload_effects_stop_output)(audio_io_handle_t, int);
|
2014-05-11 19:35:52 +00:00
|
|
|
|
|
|
|
struct sound_card_status snd_card_status;
|
2013-01-18 00:50:22 +00:00
|
|
|
};
|
|
|
|
|
2013-10-06 21:39:35 +00:00
|
|
|
int select_devices(struct audio_device *adev,
|
|
|
|
audio_usecase_t uc_id);
|
|
|
|
int disable_audio_route(struct audio_device *adev,
|
2014-04-24 18:55:48 +00:00
|
|
|
struct audio_usecase *usecase);
|
2013-10-06 21:39:35 +00:00
|
|
|
int disable_snd_device(struct audio_device *adev,
|
2014-04-24 18:55:48 +00:00
|
|
|
snd_device_t snd_device);
|
2013-10-28 21:06:03 +00:00
|
|
|
int enable_snd_device(struct audio_device *adev,
|
2014-04-24 18:55:48 +00:00
|
|
|
snd_device_t snd_device);
|
|
|
|
|
2013-10-28 21:06:03 +00:00
|
|
|
int enable_audio_route(struct audio_device *adev,
|
2014-04-24 18:55:48 +00:00
|
|
|
struct audio_usecase *usecase);
|
|
|
|
|
2013-10-06 21:39:35 +00:00
|
|
|
struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
|
|
|
|
audio_usecase_t uc_id);
|
2013-11-22 04:39:59 +00:00
|
|
|
|
2014-04-02 04:03:10 +00:00
|
|
|
bool is_offload_usecase(audio_usecase_t uc_id);
|
|
|
|
|
2013-11-22 04:39:59 +00:00
|
|
|
#define LITERAL_TO_STRING(x) #x
|
|
|
|
#define CHECK(condition) LOG_ALWAYS_FATAL_IF(!(condition), "%s",\
|
|
|
|
__FILE__ ":" LITERAL_TO_STRING(__LINE__)\
|
|
|
|
" ASSERT_FATAL(" #condition ") failed.")
|
|
|
|
|
2013-02-27 22:31:02 +00:00
|
|
|
/*
|
|
|
|
* NOTE: when multiple mutexes have to be acquired, always take the
|
|
|
|
* stream_in or stream_out mutex first, followed by the audio_device mutex.
|
|
|
|
*/
|
|
|
|
|
2013-05-14 22:27:20 +00:00
|
|
|
#endif // QCOM_AUDIO_HW_H
|