blob: 9dca5c1df43f49e154c5203ae361edf250ce2930 [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a contribution.
4 *
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08005 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Eric Laurentb23d5282013-05-14 15:27:20 -070020#ifndef QCOM_AUDIO_HW_H
21#define QCOM_AUDIO_HW_H
22
23#include <cutils/list.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080024#include <hardware/audio.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080025#include <tinyalsa/asoundlib.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070026#include <tinycompress/tinycompress.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080027
28#include <audio_route/audio_route.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070029#include "voice.h"
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080030
Eric Laurentc4aef752013-09-12 17:45:53 -070031#define VISUALIZER_LIBRARY_PATH "/system/lib/soundfx/libqcomvisualizer.so"
32
Eric Laurentb23d5282013-05-14 15:27:20 -070033/* Flags used to initialize acdb_settings variable that goes to ACDB library */
34#define DMIC_FLAG 0x00000002
Mingming Yin8e5a4f62013-10-07 15:23:41 -070035#define QMIC_FLAG 0x00000004
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define TTY_MODE_OFF 0x00000010
37#define TTY_MODE_FULL 0x00000020
38#define TTY_MODE_VCO 0x00000040
39#define TTY_MODE_HCO 0x00000080
40#define TTY_MODE_CLEAR 0xFFFFFF0F
41
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080042#define ACDB_DEV_TYPE_OUT 1
43#define ACDB_DEV_TYPE_IN 2
44
Eric Laurentb23d5282013-05-14 15:27:20 -070045#define MAX_SUPPORTED_CHANNEL_MASKS 2
Eric Laurent07eeafd2013-10-06 12:52:49 -070046#define DEFAULT_HDMI_OUT_CHANNELS 2
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080047
Eric Laurentb23d5282013-05-14 15:27:20 -070048typedef int snd_device_t;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080049
50/* These are the supported use cases by the hardware.
51 * Each usecase is mapped to a specific PCM device.
52 * Refer to pcm_device_table[].
53 */
54typedef enum {
55 USECASE_INVALID = -1,
56 /* Playback usecases */
57 USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0,
58 USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
59 USECASE_AUDIO_PLAYBACK_MULTI_CH,
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070060 USECASE_AUDIO_PLAYBACK_OFFLOAD,
Shruthi Krishnaace10852013-10-25 14:32:12 -070061
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -070062 /* FM usecase */
63 USECASE_AUDIO_PLAYBACK_FM,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080064
65 /* Capture usecases */
66 USECASE_AUDIO_RECORD,
67 USECASE_AUDIO_RECORD_LOW_LATENCY,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -070068 USECASE_AUDIO_RECORD_FM_VIRTUAL,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080069
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070070 /* Voice usecase */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080071 USECASE_VOICE_CALL,
72
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070073 /* Voice extension usecases */
74 USECASE_VOICE2_CALL,
75 USECASE_VOLTE_CALL,
76 USECASE_QCHAT_CALL,
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080077 USECASE_COMPRESS_VOIP_CALL,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070078
Shiv Maliyappanahallida107642013-10-17 11:16:13 -070079 USECASE_INCALL_REC_UPLINK,
80 USECASE_INCALL_REC_DOWNLINK,
81 USECASE_INCALL_REC_UPLINK_AND_DOWNLINK,
82
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -070083 USECASE_INCALL_MUSIC_UPLINK,
84 USECASE_INCALL_MUSIC_UPLINK2,
85
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -070086 USECASE_AUDIO_SPKR_CALIB_RX,
87 USECASE_AUDIO_SPKR_CALIB_TX,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080088 AUDIO_USECASE_MAX
89} audio_usecase_t;
90
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080091#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
92
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080093/*
94 * tinyAlsa library interprets period size as number of frames
95 * one frame = channel_count * sizeof (pcm sample)
96 * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
97 * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
98 * We should take care of returning proper size when AudioFlinger queries for
99 * the buffer size of an input/output stream
100 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800101
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700102enum {
103 OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/
104 OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */
105 OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */
106 OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */
107};
108
109enum {
110 OFFLOAD_STATE_IDLE,
111 OFFLOAD_STATE_PLAYING,
112 OFFLOAD_STATE_PAUSED,
113};
114
115struct offload_cmd {
116 struct listnode node;
117 int cmd;
118 int data[];
119};
120
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800121struct stream_out {
122 struct audio_stream_out stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800123 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700124 pthread_cond_t cond;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800125 struct pcm_config config;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700126 struct compr_config compr_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800127 struct pcm *pcm;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700128 struct compress *compr;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800129 int standby;
130 int pcm_device_id;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700131 unsigned int sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800132 audio_channel_mask_t channel_mask;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700133 audio_format_t format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800134 audio_devices_t devices;
135 audio_output_flags_t flags;
136 audio_usecase_t usecase;
137 /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */
138 audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1];
Eric Laurenta9024de2013-04-04 09:19:12 -0700139 bool muted;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -0700140 uint64_t written; /* total frames written, not cleared when entering standby */
Eric Laurentc4aef752013-09-12 17:45:53 -0700141 audio_io_handle_t handle;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800142
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700143 int non_blocking;
144 int playback_started;
145 int offload_state;
146 pthread_cond_t offload_cond;
147 pthread_t offload_thread;
148 struct listnode offload_cmd_list;
149 bool offload_thread_blocked;
150
151 stream_callback_t offload_callback;
152 void *offload_cookie;
Haynes Mathew George352f27b2013-07-26 00:00:15 -0700153 struct compr_gapless_mdata gapless_mdata;
154 int send_new_metadata;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800155
156 struct audio_device *dev;
157};
158
159struct stream_in {
160 struct audio_stream_in stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800161 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800162 struct pcm_config config;
163 struct pcm *pcm;
164 int standby;
165 int source;
166 int pcm_device_id;
167 int device;
168 audio_channel_mask_t channel_mask;
169 audio_usecase_t usecase;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700170 bool enable_aec;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800171 bool enable_ns;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800172 audio_format_t format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800173
174 struct audio_device *dev;
175};
176
177typedef enum {
178 PCM_PLAYBACK,
179 PCM_CAPTURE,
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800180 VOICE_CALL,
181 VOIP_CALL
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800182} usecase_type_t;
183
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800184union stream_ptr {
185 struct stream_in *in;
186 struct stream_out *out;
187};
188
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800189struct audio_usecase {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800190 struct listnode list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800191 audio_usecase_t id;
192 usecase_type_t type;
193 audio_devices_t devices;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700194 snd_device_t out_snd_device;
195 snd_device_t in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800196 union stream_ptr stream;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800197};
198
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800199struct audio_device {
200 struct audio_hw_device device;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800201 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800202 struct mixer *mixer;
203 audio_mode_t mode;
204 audio_devices_t out_device;
Eric Laurentc8400632013-02-14 19:04:54 -0800205 struct stream_in *active_input;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800206 struct stream_out *primary_output;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800207 bool bluetooth_nrec;
208 bool screen_off;
Eric Laurentb23d5282013-05-14 15:27:20 -0700209 int *snd_dev_ref_cnt;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800210 struct listnode usecase_list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800211 struct audio_route *audio_route;
212 int acdb_settings;
Jean-Michel Trivic56336b2013-05-24 16:55:17 -0700213 bool speaker_lr_swap;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700214 struct voice voice;
Eric Laurent07eeafd2013-10-06 12:52:49 -0700215 unsigned int cur_hdmi_channels;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800216
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 void *platform;
Eric Laurentc4aef752013-09-12 17:45:53 -0700218
219 void *visualizer_lib;
220 int (*visualizer_start_output)(audio_io_handle_t);
221 int (*visualizer_stop_output)(audio_io_handle_t);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800222};
223
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700224int select_devices(struct audio_device *adev,
225 audio_usecase_t uc_id);
226int disable_audio_route(struct audio_device *adev,
227 struct audio_usecase *usecase,
228 bool update_mixer);
229int disable_snd_device(struct audio_device *adev,
230 snd_device_t snd_device,
231 bool update_mixer);
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700232int enable_snd_device(struct audio_device *adev,
233 snd_device_t snd_device,
234 bool update_mixer);
235int enable_audio_route(struct audio_device *adev,
236 struct audio_usecase *usecase,
237 bool update_mixer);
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700238struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
239 audio_usecase_t uc_id);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800240/*
241 * NOTE: when multiple mutexes have to be acquired, always take the
242 * stream_in or stream_out mutex first, followed by the audio_device mutex.
243 */
244
Eric Laurentb23d5282013-05-14 15:27:20 -0700245#endif // QCOM_AUDIO_HW_H