blob: 55f4f300905c205992abad624b929030f20c7830 [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07003 * Not a Contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08006 *
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
20#define LOG_TAG "audio_hw_primary"
21/*#define LOG_NDEBUG 0*/
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070022/*#define VERY_VERY_VERBOSE_LOGGING*/
23#ifdef VERY_VERY_VERBOSE_LOGGING
24#define ALOGVV ALOGV
25#else
26#define ALOGVV(a...) do { } while(0)
27#endif
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080028
29#include <errno.h>
30#include <pthread.h>
31#include <stdint.h>
32#include <sys/time.h>
33#include <stdlib.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080034#include <math.h>
Eric Laurentc4aef752013-09-12 17:45:53 -070035#include <dlfcn.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070036#include <sys/resource.h>
37#include <sys/prctl.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080038
39#include <cutils/log.h>
40#include <cutils/str_parms.h>
41#include <cutils/properties.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070042#include <cutils/atomic.h>
43#include <cutils/sched_policy.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080044
Eric Laurentb23d5282013-05-14 15:27:20 -070045#include <hardware/audio_effect.h>
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070046#include <system/thread_defs.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070047#include <audio_effects/effect_aec.h>
48#include <audio_effects/effect_ns.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080049#include "audio_hw.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070050#include "platform_api.h"
51#include <platform.h>
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070052#include "audio_extn.h"
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080053#include "voice_extn.h"
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080054
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070055#include "sound/compress_params.h"
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080056#include "sound/asound.h"
ApurupaPattapu2e084df2013-12-18 15:47:59 -080057
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -070058#define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4
59/* ToDo: Check and update a proper value in msec */
60#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96
61#define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000
62
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080063
Haynes Mathew Georgebf143712013-12-03 13:02:53 -080064#define USECASE_AUDIO_PLAYBACK_PRIMARY USECASE_AUDIO_PLAYBACK_DEEP_BUFFER
65
Eric Laurentb23d5282013-05-14 15:27:20 -070066struct pcm_config pcm_config_deep_buffer = {
67 .channels = 2,
68 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
69 .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
70 .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
71 .format = PCM_FORMAT_S16_LE,
72 .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
73 .stop_threshold = INT_MAX,
74 .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
75};
76
77struct pcm_config pcm_config_low_latency = {
78 .channels = 2,
79 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
80 .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE,
81 .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT,
82 .format = PCM_FORMAT_S16_LE,
83 .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
84 .stop_threshold = INT_MAX,
85 .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
86};
87
88struct pcm_config pcm_config_hdmi_multi = {
89 .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */
90 .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */
91 .period_size = HDMI_MULTI_PERIOD_SIZE,
92 .period_count = HDMI_MULTI_PERIOD_COUNT,
93 .format = PCM_FORMAT_S16_LE,
94 .start_threshold = 0,
95 .stop_threshold = INT_MAX,
96 .avail_min = 0,
97};
98
99struct pcm_config pcm_config_audio_capture = {
100 .channels = 2,
Eric Laurentb23d5282013-05-14 15:27:20 -0700101 .period_count = AUDIO_CAPTURE_PERIOD_COUNT,
102 .format = PCM_FORMAT_S16_LE,
103};
104
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800105const char * const use_case_table[AUDIO_USECASE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700106 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
107 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
108 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
Shruthi Krishnaace10852013-10-25 14:32:12 -0700109 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback",
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700110#ifdef MULTIPLE_OFFLOAD_ENABLED
111 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = "compress-offload-playback2",
112 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = "compress-offload-playback3",
113 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = "compress-offload-playback4",
114 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = "compress-offload-playback5",
115 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = "compress-offload-playback6",
116 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = "compress-offload-playback7",
117 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = "compress-offload-playback8",
118 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = "compress-offload-playback9",
119#endif
Eric Laurentb23d5282013-05-14 15:27:20 -0700120 [USECASE_AUDIO_RECORD] = "audio-record",
Mingming Yine62d7842013-10-25 16:26:03 -0700121 [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress",
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700123 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700124 [USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800125 [USECASE_AUDIO_HFP_SCO] = "hfp-sco",
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800126 [USECASE_AUDIO_HFP_SCO_WB] = "hfp-sco-wb",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700127 [USECASE_VOICE_CALL] = "voice-call",
Mingming Yin3ee55c62014-08-04 14:23:35 -0700128
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700129 [USECASE_VOICE2_CALL] = "voice2-call",
130 [USECASE_VOLTE_CALL] = "volte-call",
131 [USECASE_QCHAT_CALL] = "qchat-call",
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800132 [USECASE_VOWLAN_CALL] = "vowlan-call",
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800133 [USECASE_COMPRESS_VOIP_CALL] = "compress-voip-call",
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700134 [USECASE_INCALL_REC_UPLINK] = "incall-rec-uplink",
135 [USECASE_INCALL_REC_DOWNLINK] = "incall-rec-downlink",
136 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = "incall-rec-uplink-and-downlink",
Helen Zenge56b4852013-12-03 16:54:40 -0800137 [USECASE_INCALL_REC_UPLINK_COMPRESS] = "incall-rec-uplink-compress",
138 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = "incall-rec-downlink-compress",
139 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = "incall-rec-uplink-and-downlink-compress",
140
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700141 [USECASE_INCALL_MUSIC_UPLINK] = "incall_music_uplink",
142 [USECASE_INCALL_MUSIC_UPLINK2] = "incall_music_uplink2",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700143 [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib",
144 [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record",
Eric Laurentb23d5282013-05-14 15:27:20 -0700145};
146
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700147static const audio_usecase_t offload_usecases[] = {
148 USECASE_AUDIO_PLAYBACK_OFFLOAD,
149#ifdef MULTIPLE_OFFLOAD_ENABLED
150 USECASE_AUDIO_PLAYBACK_OFFLOAD2,
151 USECASE_AUDIO_PLAYBACK_OFFLOAD3,
152 USECASE_AUDIO_PLAYBACK_OFFLOAD4,
153 USECASE_AUDIO_PLAYBACK_OFFLOAD5,
154 USECASE_AUDIO_PLAYBACK_OFFLOAD6,
155 USECASE_AUDIO_PLAYBACK_OFFLOAD7,
156 USECASE_AUDIO_PLAYBACK_OFFLOAD8,
157 USECASE_AUDIO_PLAYBACK_OFFLOAD9,
158#endif
159};
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800160
161#define STRING_TO_ENUM(string) { #string, string }
162
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800163struct string_to_enum {
164 const char *name;
165 uint32_t value;
166};
167
168static const struct string_to_enum out_channels_name_to_enum_table[] = {
169 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
170 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
171 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
172};
173
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700174static struct audio_device *adev = NULL;
175static pthread_mutex_t adev_init_lock;
Kiran Kandi910e1862013-10-29 13:29:42 -0700176static unsigned int audio_device_ref_count;
177
Haynes Mathew George5191a852013-09-11 14:19:36 -0700178static int set_voice_volume_l(struct audio_device *adev, float volume);
Krishnankutty Kolathappilly6d8788b2014-01-09 12:45:31 -0800179
Krishnankutty Kolathappilly6d8788b2014-01-09 12:45:31 -0800180static int check_and_set_gapless_mode(struct audio_device *adev) {
181
182
183 char value[PROPERTY_VALUE_MAX] = {0};
184 bool gapless_enabled = false;
185 const char *mixer_ctl_name = "Compress Gapless Playback";
186 struct mixer_ctl *ctl;
187
188 ALOGV("%s:", __func__);
189 property_get("audio.offload.gapless.enabled", value, NULL);
190 gapless_enabled = atoi(value) || !strncmp("true", value, 4);
191
192 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
193 if (!ctl) {
194 ALOGE("%s: Could not get ctl for mixer cmd - %s",
195 __func__, mixer_ctl_name);
196 return -EINVAL;
197 }
198
199 if (mixer_ctl_set_value(ctl, 0, gapless_enabled) < 0) {
200 ALOGE("%s: Could not set gapless mode %d",
201 __func__, gapless_enabled);
202 return -EINVAL;
203 }
204 return 0;
205}
Haynes Mathew George5191a852013-09-11 14:19:36 -0700206
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700207static bool is_supported_format(audio_format_t format)
208{
Eric Laurent86e17132013-09-12 17:49:30 -0700209 if (format == AUDIO_FORMAT_MP3 ||
Ashish Jainf9b78162014-08-25 20:36:25 +0530210 format == AUDIO_FORMAT_AAC_LC ||
211 format == AUDIO_FORMAT_AAC_HE_V1 ||
212 format == AUDIO_FORMAT_AAC_HE_V2 ||
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -0800213 format == AUDIO_FORMAT_PCM_16_BIT_OFFLOAD ||
Mingming Yin3ee55c62014-08-04 14:23:35 -0700214 format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD ||
215 format == AUDIO_FORMAT_FLAC)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -0800216 return true;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700217
218 return false;
219}
220
221static int get_snd_codec_id(audio_format_t format)
222{
223 int id = 0;
224
Ashish Jainf9b78162014-08-25 20:36:25 +0530225 switch (format & AUDIO_FORMAT_MAIN_MASK) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700226 case AUDIO_FORMAT_MP3:
227 id = SND_AUDIOCODEC_MP3;
228 break;
229 case AUDIO_FORMAT_AAC:
230 id = SND_AUDIOCODEC_AAC;
231 break;
Ashish Jainf9b78162014-08-25 20:36:25 +0530232 case AUDIO_FORMAT_PCM_OFFLOAD:
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -0800233 id = SND_AUDIOCODEC_PCM;
234 break;
Mingming Yin3ee55c62014-08-04 14:23:35 -0700235 case AUDIO_FORMAT_FLAC:
236 id = SND_AUDIOCODEC_FLAC;
237 break;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700238 default:
Mingming Yin90310102013-11-13 16:57:00 -0800239 ALOGE("%s: Unsupported audio format :%x", __func__, format);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700240 }
241
242 return id;
243}
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800244
Venkata Narendra Kumar Guttaed0f94f2014-07-09 16:29:28 +0530245int get_snd_card_state(struct audio_device *adev)
Naresh Tanniru80659832014-06-04 18:17:56 +0530246{
247 int snd_scard_state;
248
249 if (!adev)
250 return SND_CARD_STATE_OFFLINE;
251
252 pthread_mutex_lock(&adev->snd_card_status.lock);
253 snd_scard_state = adev->snd_card_status.state;
254 pthread_mutex_unlock(&adev->snd_card_status.lock);
255
256 return snd_scard_state;
257}
258
259static int set_snd_card_state(struct audio_device *adev, int snd_scard_state)
260{
261 if (!adev)
262 return -ENOSYS;
263
264 pthread_mutex_lock(&adev->snd_card_status.lock);
265 adev->snd_card_status.state = snd_scard_state;
266 pthread_mutex_unlock(&adev->snd_card_status.lock);
267
268 return 0;
269}
270
Avinash Vaish71a8b972014-07-24 15:36:33 +0530271static int enable_audio_route_for_voice_usecases(struct audio_device *adev,
272 struct audio_usecase *uc_info)
273{
274 struct listnode *node;
275 struct audio_usecase *usecase;
276
277 if (uc_info == NULL)
278 return -EINVAL;
279
280 /* Re-route all voice usecases on the shared backend other than the
281 specified usecase to new snd devices */
282 list_for_each(node, &adev->usecase_list) {
283 usecase = node_to_item(node, struct audio_usecase, list);
284 if ((usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) &&
285 (usecase != uc_info))
286 enable_audio_route(adev, usecase);
287 }
288 return 0;
289}
290
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700291int enable_audio_route(struct audio_device *adev,
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700292 struct audio_usecase *usecase)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800293{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700294 snd_device_t snd_device;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700295 char mixer_path[MIXER_PATH_MAX_LENGTH];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800296
297 if (usecase == NULL)
298 return -EINVAL;
299
300 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
301
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800302 if (usecase->type == PCM_CAPTURE)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700303 snd_device = usecase->in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800304 else
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700305 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800306
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -0800307#ifdef DS1_DOLBY_DAP_ENABLED
308 audio_extn_dolby_set_dmid(adev);
309 audio_extn_dolby_set_endpoint(adev);
310#endif
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -0700311 audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_BUSY);
Dhananjay Kumar45b71742014-05-29 21:47:27 +0530312 audio_extn_listen_update_stream_status(usecase, LISTEN_EVENT_STREAM_BUSY);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700313 audio_extn_utils_send_audio_calibration(adev, usecase);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700314 audio_extn_utils_send_app_type_cfg(usecase);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800315 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 platform_add_backend_name(mixer_path, snd_device);
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700317 ALOGV("%s: apply mixer and update path: %s", __func__, mixer_path);
318 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800319 ALOGV("%s: exit", __func__);
320 return 0;
321}
322
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700323int disable_audio_route(struct audio_device *adev,
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700324 struct audio_usecase *usecase)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800325{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700326 snd_device_t snd_device;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700327 char mixer_path[MIXER_PATH_MAX_LENGTH];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800328
329 if (usecase == NULL)
330 return -EINVAL;
331
332 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700333 if (usecase->type == PCM_CAPTURE)
334 snd_device = usecase->in_snd_device;
335 else
336 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800337 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 platform_add_backend_name(mixer_path, snd_device);
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700339 ALOGV("%s: reset and update mixer path: %s", __func__, mixer_path);
340 audio_route_reset_and_update_path(adev->audio_route, mixer_path);
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -0700341 audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_FREE);
Dhananjay Kumar45b71742014-05-29 21:47:27 +0530342 audio_extn_listen_update_stream_status(usecase, LISTEN_EVENT_STREAM_FREE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800343 ALOGV("%s: exit", __func__);
344 return 0;
345}
346
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700347int enable_snd_device(struct audio_device *adev,
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700348 snd_device_t snd_device)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800349{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700350 char device_name[DEVICE_NAME_MAX_SIZE] = {0};
351
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800352 if (snd_device < SND_DEVICE_MIN ||
353 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800354 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800355 return -EINVAL;
356 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700357
358 adev->snd_dev_ref_cnt[snd_device]++;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700359
360 if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) {
361 ALOGE("%s: Invalid sound device returned", __func__);
362 return -EINVAL;
363 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700364 if (adev->snd_dev_ref_cnt[snd_device] > 1) {
Eric Laurent994a6932013-07-17 11:51:42 -0700365 ALOGV("%s: snd_device(%d: %s) is already active",
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700366 __func__, snd_device, device_name);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700367 return 0;
368 }
369
Gopikrishnaiah Anandane85d0462014-06-30 21:41:20 -0700370 if (audio_extn_spkr_prot_is_enabled())
371 audio_extn_spkr_prot_calib_cancel(adev);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700372 /* start usb playback thread */
373 if(SND_DEVICE_OUT_USB_HEADSET == snd_device ||
374 SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device)
375 audio_extn_usb_start_playback(adev);
376
377 /* start usb capture thread */
378 if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
379 audio_extn_usb_start_capture(adev);
380
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -0800381 if ((snd_device == SND_DEVICE_OUT_SPEAKER ||
382 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) &&
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700383 audio_extn_spkr_prot_is_enabled()) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700384 if (audio_extn_spkr_prot_get_acdb_id(snd_device) < 0) {
385 adev->snd_dev_ref_cnt[snd_device]--;
386 return -EINVAL;
387 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -0800388 if (audio_extn_spkr_prot_start_processing(snd_device)) {
389 ALOGE("%s: spkr_start_processing failed", __func__);
390 return -EINVAL;
391 }
392 } else {
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700393 ALOGV("%s: snd_device(%d: %s)", __func__,
394 snd_device, device_name);
Bharath Ramachandramurthy0de16782014-03-28 21:34:33 -0700395 /* due to the possibility of calibration overwrite between listen
396 and audio, notify listen hal before audio calibration is sent */
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -0700397 audio_extn_sound_trigger_update_device_status(snd_device,
398 ST_EVENT_SND_DEVICE_BUSY);
Dhananjay Kumar45b71742014-05-29 21:47:27 +0530399 audio_extn_listen_update_device_status(snd_device,
400 LISTEN_EVENT_SND_DEVICE_BUSY);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700401 if (platform_get_snd_device_acdb_id(snd_device) < 0) {
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700402 adev->snd_dev_ref_cnt[snd_device]--;
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -0700403 audio_extn_sound_trigger_update_device_status(snd_device,
404 ST_EVENT_SND_DEVICE_FREE);
Dhananjay Kumar45b71742014-05-29 21:47:27 +0530405 audio_extn_listen_update_device_status(snd_device,
406 LISTEN_EVENT_SND_DEVICE_FREE);
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700407 return -EINVAL;
408 }
Lior Barenboim0b61bc72014-05-13 13:01:37 +0300409 audio_extn_dev_arbi_acquire(snd_device);
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700410 audio_route_apply_and_update_path(adev->audio_route, device_name);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800411 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800412 return 0;
413}
414
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700415int disable_snd_device(struct audio_device *adev,
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700416 snd_device_t snd_device)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800417{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700418 char device_name[DEVICE_NAME_MAX_SIZE] = {0};
419
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800420 if (snd_device < SND_DEVICE_MIN ||
421 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800422 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800423 return -EINVAL;
424 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700425 if (adev->snd_dev_ref_cnt[snd_device] <= 0) {
426 ALOGE("%s: device ref cnt is already 0", __func__);
427 return -EINVAL;
428 }
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700429
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700430 adev->snd_dev_ref_cnt[snd_device]--;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700431
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700432 if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0) {
433 ALOGE("%s: Invalid sound device returned", __func__);
434 return -EINVAL;
435 }
436
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700437 if (adev->snd_dev_ref_cnt[snd_device] == 0) {
Eric Laurent994a6932013-07-17 11:51:42 -0700438 ALOGV("%s: snd_device(%d: %s)", __func__,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700439 snd_device, device_name);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -0800440 /* exit usb play back thread */
441 if(SND_DEVICE_OUT_USB_HEADSET == snd_device ||
442 SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device)
443 audio_extn_usb_stop_playback();
444
445 /* exit usb capture thread */
446 if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -0700447 audio_extn_usb_stop_capture();
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -0800448
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -0800449 if ((snd_device == SND_DEVICE_OUT_SPEAKER ||
450 snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) &&
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700451 audio_extn_spkr_prot_is_enabled()) {
Anish Kumar46c7b872014-09-09 01:49:44 -0700452 audio_extn_spkr_prot_stop_processing(snd_device);
Lior Barenboim0b61bc72014-05-13 13:01:37 +0300453 } else {
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700454 audio_route_reset_and_update_path(adev->audio_route, device_name);
Lior Barenboim0b61bc72014-05-13 13:01:37 +0300455 audio_extn_dev_arbi_release(snd_device);
456 }
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -0700457
458 audio_extn_sound_trigger_update_device_status(snd_device,
459 ST_EVENT_SND_DEVICE_FREE);
Dhananjay Kumar45b71742014-05-29 21:47:27 +0530460 audio_extn_listen_update_device_status(snd_device,
Kiran Kandide144c82013-11-20 15:58:32 -0800461 LISTEN_EVENT_SND_DEVICE_FREE);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700462 }
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700463
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800464 return 0;
465}
466
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700467static void check_usecases_codec_backend(struct audio_device *adev,
468 struct audio_usecase *uc_info,
469 snd_device_t snd_device)
470{
471 struct listnode *node;
472 struct audio_usecase *usecase;
473 bool switch_device[AUDIO_USECASE_MAX];
474 int i, num_uc_to_switch = 0;
475
476 /*
477 * This function is to make sure that all the usecases that are active on
478 * the hardware codec backend are always routed to any one device that is
479 * handled by the hardware codec.
480 * For example, if low-latency and deep-buffer usecases are currently active
481 * on speaker and out_set_parameters(headset) is received on low-latency
482 * output, then we have to make sure deep-buffer is also switched to headset,
483 * because of the limitation that both the devices cannot be enabled
484 * at the same time as they share the same backend.
485 */
Mingming Yin3ee55c62014-08-04 14:23:35 -0700486 /*
487 * This call is to check if we need to force routing for a particular stream
488 * If there is a backend configuration change for the device when a
489 * new stream starts, then ADM needs to be closed and re-opened with the new
490 * configuraion. This call check if we need to re-route all the streams
491 * associated with the backend. Touch tone + 24 bit playback.
492 */
493 bool force_routing = platform_check_and_set_codec_backend_cfg(adev, uc_info);
494
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700495 /* Disable all the usecases on the shared backend other than the
496 specified usecase */
497 for (i = 0; i < AUDIO_USECASE_MAX; i++)
498 switch_device[i] = false;
499
500 list_for_each(node, &adev->usecase_list) {
501 usecase = node_to_item(node, struct audio_usecase, list);
Shiv Maliyappanahalli80ac6282013-12-20 18:56:15 -0800502 if (usecase->type != PCM_CAPTURE &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700503 usecase != uc_info &&
Mingming Yin3ee55c62014-08-04 14:23:35 -0700504 (usecase->out_snd_device != snd_device || force_routing) &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700505 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
506 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
507 __func__, use_case_table[usecase->id],
Eric Laurentb23d5282013-05-14 15:27:20 -0700508 platform_get_snd_device_name(usecase->out_snd_device));
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700509 disable_audio_route(adev, usecase);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700510 switch_device[usecase->id] = true;
511 num_uc_to_switch++;
512 }
513 }
514
515 if (num_uc_to_switch) {
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700516 /* All streams have been de-routed. Disable the device */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700517
Venkata Narendra Kumar Gutta7610e632014-04-14 23:16:38 +0530518 /* Make sure the previous devices to be disabled first and then enable the
519 selected devices */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700520 list_for_each(node, &adev->usecase_list) {
521 usecase = node_to_item(node, struct audio_usecase, list);
522 if (switch_device[usecase->id]) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700523 disable_snd_device(adev, usecase->out_snd_device);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700524 }
525 }
526
Krishnankutty Kolathappillydc4f7572013-11-01 20:07:13 -0700527 list_for_each(node, &adev->usecase_list) {
528 usecase = node_to_item(node, struct audio_usecase, list);
529 if (switch_device[usecase->id]) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700530 enable_snd_device(adev, snd_device);
Krishnankutty Kolathappillydc4f7572013-11-01 20:07:13 -0700531 }
532 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700533
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700534 /* Re-route all the usecases on the shared backend other than the
535 specified usecase to new snd devices */
536 list_for_each(node, &adev->usecase_list) {
537 usecase = node_to_item(node, struct audio_usecase, list);
538 /* Update the out_snd_device only before enabling the audio route */
539 if (switch_device[usecase->id] ) {
540 usecase->out_snd_device = snd_device;
Avinash Vaish71a8b972014-07-24 15:36:33 +0530541 if (usecase->type != VOICE_CALL && usecase->type != VOIP_CALL)
542 enable_audio_route(adev, usecase);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700543 }
544 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700545 }
546}
547
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700548static void check_and_route_capture_usecases(struct audio_device *adev,
549 struct audio_usecase *uc_info,
550 snd_device_t snd_device)
551{
552 struct listnode *node;
553 struct audio_usecase *usecase;
554 bool switch_device[AUDIO_USECASE_MAX];
555 int i, num_uc_to_switch = 0;
556
557 /*
558 * This function is to make sure that all the active capture usecases
559 * are always routed to the same input sound device.
560 * For example, if audio-record and voice-call usecases are currently
561 * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece)
562 * is received for voice call then we have to make sure that audio-record
563 * usecase is also switched to earpiece i.e. voice-dmic-ef,
564 * because of the limitation that two devices cannot be enabled
565 * at the same time if they share the same backend.
566 */
567 for (i = 0; i < AUDIO_USECASE_MAX; i++)
568 switch_device[i] = false;
569
570 list_for_each(node, &adev->usecase_list) {
571 usecase = node_to_item(node, struct audio_usecase, list);
Shiv Maliyappanahalli80ac6282013-12-20 18:56:15 -0800572 if (usecase->type != PCM_PLAYBACK &&
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700573 usecase != uc_info &&
574 usecase->in_snd_device != snd_device) {
575 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
576 __func__, use_case_table[usecase->id],
Devin Kim1e5f3532013-08-09 07:48:29 -0700577 platform_get_snd_device_name(usecase->in_snd_device));
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700578 disable_audio_route(adev, usecase);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700579 switch_device[usecase->id] = true;
580 num_uc_to_switch++;
581 }
582 }
583
584 if (num_uc_to_switch) {
Haynes Mathew Georgeef1e3d32014-04-24 11:53:44 -0700585 /* All streams have been de-routed. Disable the device */
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700586
Venkata Narendra Kumar Gutta7610e632014-04-14 23:16:38 +0530587 /* Make sure the previous devices to be disabled first and then enable the
588 selected devices */
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700589 list_for_each(node, &adev->usecase_list) {
590 usecase = node_to_item(node, struct audio_usecase, list);
591 if (switch_device[usecase->id]) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700592 disable_snd_device(adev, usecase->in_snd_device);
Shiv Maliyappanahalli80ac6282013-12-20 18:56:15 -0800593 }
594 }
595
596 list_for_each(node, &adev->usecase_list) {
597 usecase = node_to_item(node, struct audio_usecase, list);
598 if (switch_device[usecase->id]) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700599 enable_snd_device(adev, snd_device);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700600 }
601 }
602
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700603 /* Re-route all the usecases on the shared backend other than the
604 specified usecase to new snd devices */
605 list_for_each(node, &adev->usecase_list) {
606 usecase = node_to_item(node, struct audio_usecase, list);
607 /* Update the in_snd_device only before enabling the audio route */
608 if (switch_device[usecase->id] ) {
609 usecase->in_snd_device = snd_device;
Avinash Vaish71a8b972014-07-24 15:36:33 +0530610 if (usecase->type != VOICE_CALL && usecase->type != VOIP_CALL)
611 enable_audio_route(adev, usecase);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700612 }
613 }
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700614 }
615}
616
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800617/* must be called with hw device mutex locked */
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700618static int read_hdmi_channel_masks(struct stream_out *out)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800619{
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700620 int ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700621 int channels = platform_edid_get_max_channels(out->dev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800622
623 switch (channels) {
624 /*
625 * Do not handle stereo output in Multi-channel cases
626 * Stereo case is handled in normal playback path
627 */
628 case 6:
629 ALOGV("%s: HDMI supports 5.1", __func__);
630 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
631 break;
632 case 8:
633 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
634 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
635 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
636 break;
637 default:
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700638 ALOGE("HDMI does not support multi channel playback");
639 ret = -ENOSYS;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800640 break;
641 }
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700642 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800643}
644
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700645static audio_usecase_t get_voice_usecase_id_from_list(struct audio_device *adev)
646{
647 struct audio_usecase *usecase;
648 struct listnode *node;
649
650 list_for_each(node, &adev->usecase_list) {
651 usecase = node_to_item(node, struct audio_usecase, list);
652 if (usecase->type == VOICE_CALL) {
653 ALOGV("%s: usecase id %d", __func__, usecase->id);
654 return usecase->id;
655 }
656 }
657 return USECASE_INVALID;
658}
659
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700660struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700661 audio_usecase_t uc_id)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700662{
663 struct audio_usecase *usecase;
664 struct listnode *node;
665
666 list_for_each(node, &adev->usecase_list) {
667 usecase = node_to_item(node, struct audio_usecase, list);
668 if (usecase->id == uc_id)
669 return usecase;
670 }
671 return NULL;
672}
673
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700674int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800675{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800676 snd_device_t out_snd_device = SND_DEVICE_NONE;
677 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700678 struct audio_usecase *usecase = NULL;
679 struct audio_usecase *vc_usecase = NULL;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800680 struct audio_usecase *voip_usecase = NULL;
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800681 struct audio_usecase *hfp_usecase = NULL;
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800682 audio_usecase_t hfp_ucid;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800683 struct listnode *node;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700684 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800685
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700686 usecase = get_usecase_from_list(adev, uc_id);
687 if (usecase == NULL) {
688 ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
689 return -EINVAL;
690 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800691
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800692 if ((usecase->type == VOICE_CALL) ||
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800693 (usecase->type == VOIP_CALL) ||
694 (usecase->type == PCM_HFP_CALL)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700695 out_snd_device = platform_get_output_snd_device(adev->platform,
696 usecase->stream.out->devices);
697 in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700698 usecase->devices = usecase->stream.out->devices;
699 } else {
700 /*
701 * If the voice call is active, use the sound devices of voice call usecase
702 * so that it would not result any device switch. All the usecases will
703 * be switched to new device when select_devices() is called for voice call
704 * usecase. This is to avoid switching devices for voice call when
705 * check_usecases_codec_backend() is called below.
706 */
Vidyakumar Athotaad34d572014-08-05 18:20:42 -0700707 if (adev->voice.in_call && adev->mode == AUDIO_MODE_IN_CALL) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700708 vc_usecase = get_usecase_from_list(adev,
709 get_voice_usecase_id_from_list(adev));
Mingming Yin2d8aa2e2014-08-14 00:00:51 -0700710 if ((vc_usecase) && ((vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) ||
711 (usecase->devices == AUDIO_DEVICE_IN_VOICE_CALL))) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700712 in_snd_device = vc_usecase->in_snd_device;
713 out_snd_device = vc_usecase->out_snd_device;
714 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800715 } else if (voice_extn_compress_voip_is_active(adev)) {
716 voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL);
Mingming Yin2d8aa2e2014-08-14 00:00:51 -0700717 if ((voip_usecase) && ((voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) &&
Avinash Vaish4d6167d2014-06-25 12:20:37 +0530718 (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) &&
Mingming Yin2d8aa2e2014-08-14 00:00:51 -0700719 (voip_usecase->stream.out != adev->primary_output))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800720 in_snd_device = voip_usecase->in_snd_device;
721 out_snd_device = voip_usecase->out_snd_device;
722 }
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800723 } else if (audio_extn_hfp_is_active(adev)) {
Vimal Puthanveed41fcff22014-01-23 15:56:53 -0800724 hfp_ucid = audio_extn_hfp_get_usecase();
725 hfp_usecase = get_usecase_from_list(adev, hfp_ucid);
Mingming Yin2d8aa2e2014-08-14 00:00:51 -0700726 if ((hfp_usecase) && (hfp_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) {
Vimal Puthanveed37b4a1c2014-01-07 16:47:47 -0800727 in_snd_device = hfp_usecase->in_snd_device;
728 out_snd_device = hfp_usecase->out_snd_device;
729 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700730 }
731 if (usecase->type == PCM_PLAYBACK) {
732 usecase->devices = usecase->stream.out->devices;
733 in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700734 if (out_snd_device == SND_DEVICE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700735 out_snd_device = platform_get_output_snd_device(adev->platform,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700736 usecase->stream.out->devices);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700737 if (usecase->stream.out == adev->primary_output &&
738 adev->active_input &&
739 adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
740 select_devices(adev, adev->active_input->usecase);
741 }
742 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700743 } else if (usecase->type == PCM_CAPTURE) {
744 usecase->devices = usecase->stream.in->device;
745 out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700746 if (in_snd_device == SND_DEVICE_NONE) {
747 if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
748 adev->primary_output && !adev->primary_output->standby) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700749 in_snd_device = platform_get_input_snd_device(adev->platform,
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700750 adev->primary_output->devices);
751 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700752 in_snd_device = platform_get_input_snd_device(adev->platform,
753 AUDIO_DEVICE_NONE);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700754 }
755 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700756 }
757 }
758
759 if (out_snd_device == usecase->out_snd_device &&
760 in_snd_device == usecase->in_snd_device) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800761 return 0;
762 }
763
sangwoobc677242013-08-08 16:53:43 +0900764 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700765 out_snd_device, platform_get_snd_device_name(out_snd_device),
766 in_snd_device, platform_get_snd_device_name(in_snd_device));
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800767
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800768 /*
769 * Limitation: While in call, to do a device switch we need to disable
770 * and enable both RX and TX devices though one of them is same as current
771 * device.
772 */
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700773 if ((usecase->type == VOICE_CALL) &&
774 (usecase->in_snd_device != SND_DEVICE_NONE) &&
775 (usecase->out_snd_device != SND_DEVICE_NONE)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700776 status = platform_switch_voice_call_device_pre(adev->platform);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800777 }
778
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700779 /* Disable current sound devices */
780 if (usecase->out_snd_device != SND_DEVICE_NONE) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700781 disable_audio_route(adev, usecase);
782 disable_snd_device(adev, usecase->out_snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800783 }
784
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700785 if (usecase->in_snd_device != SND_DEVICE_NONE) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700786 disable_audio_route(adev, usecase);
787 disable_snd_device(adev, usecase->in_snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800788 }
789
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800790 /* Applicable only on the targets that has external modem.
791 * New device information should be sent to modem before enabling
792 * the devices to reduce in-call device switch time.
793 */
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700794 if ((usecase->type == VOICE_CALL) &&
795 (usecase->in_snd_device != SND_DEVICE_NONE) &&
796 (usecase->out_snd_device != SND_DEVICE_NONE)) {
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800797 status = platform_switch_voice_call_enable_device_config(adev->platform,
798 out_snd_device,
799 in_snd_device);
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700800 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800801
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700802 /* Enable new sound devices */
803 if (out_snd_device != SND_DEVICE_NONE) {
804 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
805 check_usecases_codec_backend(adev, usecase, out_snd_device);
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700806 enable_snd_device(adev, out_snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800807 }
808
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700809 if (in_snd_device != SND_DEVICE_NONE) {
810 check_and_route_capture_usecases(adev, usecase, in_snd_device);
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700811 enable_snd_device(adev, in_snd_device);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700812 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700813
Avinash Vaish71a8b972014-07-24 15:36:33 +0530814 if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700815 status = platform_switch_voice_call_device_post(adev->platform,
816 out_snd_device,
817 in_snd_device);
Avinash Vaish71a8b972014-07-24 15:36:33 +0530818 enable_audio_route_for_voice_usecases(adev, usecase);
819 }
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800820
sangwoo170731f2013-06-08 15:36:36 +0900821 usecase->in_snd_device = in_snd_device;
822 usecase->out_snd_device = out_snd_device;
823
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530824 if (usecase->type == PCM_PLAYBACK) {
825 if ((24 == usecase->stream.out->bit_width) &&
826 (AUDIO_DEVICE_OUT_SPEAKER == usecase->stream.out->devices)) {
827 audio_extn_utils_update_stream_app_type_cfg(adev->platform,
828 &adev->streams_output_cfg_list,
829 usecase->stream.out->flags,
830 usecase->stream.out->format,
831 DEFAULT_OUTPUT_SAMPLING_RATE,
832 usecase->stream.out->bit_width,
833 &usecase->stream.out->app_type_cfg);
834 } else {
835 audio_extn_utils_update_stream_app_type_cfg(adev->platform,
836 &adev->streams_output_cfg_list,
837 usecase->stream.out->flags,
838 usecase->stream.out->format,
839 usecase->stream.out->sample_rate,
840 usecase->stream.out->bit_width,
841 &usecase->stream.out->app_type_cfg);
842 }
843 ALOGI("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
844 }
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700845 enable_audio_route(adev, usecase);
sangwoo170731f2013-06-08 15:36:36 +0900846
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800847 /* Applicable only on the targets that has external modem.
848 * Enable device command should be sent to modem only after
849 * enabling voice call mixer controls
850 */
Vidyakumar Athota339342f2014-07-01 15:30:57 -0700851 if (usecase->type == VOICE_CALL)
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800852 status = platform_switch_voice_call_usecase_route_post(adev->platform,
853 out_snd_device,
854 in_snd_device);
Sidipotu Ashokf43018c2014-05-02 16:21:50 +0530855 ALOGD("%s: done",__func__);
856
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800857 return status;
858}
859
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800860static int stop_input_stream(struct stream_in *in)
861{
862 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800863 struct audio_usecase *uc_info;
864 struct audio_device *adev = in->dev;
865
Eric Laurentc8400632013-02-14 19:04:54 -0800866 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800867
Eric Laurent994a6932013-07-17 11:51:42 -0700868 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700869 in->usecase, use_case_table[in->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800870 uc_info = get_usecase_from_list(adev, in->usecase);
871 if (uc_info == NULL) {
872 ALOGE("%s: Could not find the usecase (%d) in the list",
873 __func__, in->usecase);
874 return -EINVAL;
875 }
876
Vidyakumar Athota2850d532013-11-19 16:02:12 -0800877 /* Close in-call recording streams */
878 voice_check_and_stop_incall_rec_usecase(adev, in);
879
Eric Laurent150dbfe2013-02-27 14:31:02 -0800880 /* 1. Disable stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700881 disable_audio_route(adev, uc_info);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700882
883 /* 2. Disable the tx device */
Haynes Mathew George1376ca62014-04-24 11:55:48 -0700884 disable_snd_device(adev, uc_info->in_snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800885
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800886 list_remove(&uc_info->list);
887 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800888
Eric Laurent994a6932013-07-17 11:51:42 -0700889 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800890 return ret;
891}
892
893int start_input_stream(struct stream_in *in)
894{
895 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800896 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800897 struct audio_usecase *uc_info;
898 struct audio_device *adev = in->dev;
Naresh Tanniru80659832014-06-04 18:17:56 +0530899 int snd_card_status = get_snd_card_state(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800900
Mingming Yine62d7842013-10-25 16:26:03 -0700901 in->usecase = platform_update_usecase_from_source(in->source,in->usecase);
Sidipotu Ashokf43018c2014-05-02 16:21:50 +0530902 ALOGD("%s: enter: stream(%p)usecase(%d: %s)",
903 __func__, &in->stream, in->usecase, use_case_table[in->usecase]);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700904
Naresh Tanniru80659832014-06-04 18:17:56 +0530905
906 if (SND_CARD_STATE_OFFLINE == snd_card_status) {
Naresh Tanniru4c630392014-05-12 01:05:52 +0530907 ALOGE("%s: sound card is not active/SSR returning error", __func__);
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +0530908 ret = -EIO;
Naresh Tanniru4c630392014-05-12 01:05:52 +0530909 goto error_config;
910 }
Naresh Tanniru4c630392014-05-12 01:05:52 +0530911
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700912 /* Check if source matches incall recording usecase criteria */
913 ret = voice_check_and_set_incall_rec_usecase(adev, in);
914 if (ret)
915 goto error_config;
916 else
917 ALOGV("%s: usecase(%d)", __func__, in->usecase);
918
Eric Laurentb23d5282013-05-14 15:27:20 -0700919 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800920 if (in->pcm_device_id < 0) {
921 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
922 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800923 ret = -EINVAL;
924 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800925 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700926
927 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800928 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700929
930 if (!uc_info) {
931 ret = -ENOMEM;
932 goto error_config;
933 }
934
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800935 uc_info->id = in->usecase;
936 uc_info->type = PCM_CAPTURE;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800937 uc_info->stream.in = in;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700938 uc_info->devices = in->device;
939 uc_info->in_snd_device = SND_DEVICE_NONE;
940 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800941
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800942 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700943 select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800944
Eric Laurentc8400632013-02-14 19:04:54 -0800945 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800946 __func__, adev->snd_card,
947 in->pcm_device_id, in->config.channels);
948 in->pcm = pcm_open(adev->snd_card,
949 in->pcm_device_id, PCM_IN, &in->config);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800950 if (in->pcm && !pcm_is_ready(in->pcm)) {
951 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
952 pcm_close(in->pcm);
953 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800954 ret = -EIO;
955 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800956 }
Naresh Tanniru4c630392014-05-12 01:05:52 +0530957
Eric Laurent994a6932013-07-17 11:51:42 -0700958 ALOGV("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800959 return ret;
960
961error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800962 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800963
964error_config:
965 adev->active_input = NULL;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700966 ALOGD("%s: exit: status(%d)", __func__, ret);
Eric Laurentc8400632013-02-14 19:04:54 -0800967
968 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800969}
970
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700971/* must be called with out->lock locked */
972static int send_offload_cmd_l(struct stream_out* out, int command)
973{
974 struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd));
975
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700976 if (!cmd) {
977 ALOGE("failed to allocate mem for command 0x%x", command);
978 return -ENOMEM;
979 }
980
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700981 ALOGVV("%s %d", __func__, command);
982
983 cmd->cmd = command;
984 list_add_tail(&out->offload_cmd_list, &cmd->node);
985 pthread_cond_signal(&out->offload_cond);
986 return 0;
987}
988
989/* must be called iwth out->lock locked */
990static void stop_compressed_output_l(struct stream_out *out)
991{
992 out->offload_state = OFFLOAD_STATE_IDLE;
993 out->playback_started = 0;
Haynes Mathew George352f27b2013-07-26 00:00:15 -0700994 out->send_new_metadata = 1;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700995 if (out->compr != NULL) {
996 compress_stop(out->compr);
997 while (out->offload_thread_blocked) {
998 pthread_cond_wait(&out->cond, &out->lock);
999 }
1000 }
1001}
1002
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001003bool is_offload_usecase(audio_usecase_t uc_id)
1004{
1005 unsigned int i;
1006 for (i = 0; i < sizeof(offload_usecases)/sizeof(offload_usecases[0]); i++) {
1007 if (uc_id == offload_usecases[i])
1008 return true;
1009 }
1010 return false;
1011}
1012
1013static audio_usecase_t get_offload_usecase(struct audio_device *adev)
1014{
1015 audio_usecase_t ret = USECASE_AUDIO_PLAYBACK_OFFLOAD;
1016 unsigned int i, num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
1017 char value[PROPERTY_VALUE_MAX] = {0};
1018
1019 property_get("audio.offload.multiple.enabled", value, NULL);
1020 if (!(atoi(value) || !strncmp("true", value, 4)))
1021 num_usecase = 1; /* If prop is not set, limit the num of offload usecases to 1 */
1022
1023 ALOGV("%s: num_usecase: %d", __func__, num_usecase);
1024 for (i = 0; i < num_usecase; i++) {
1025 if (!(adev->offload_usecases_state & (0x1<<i))) {
1026 adev->offload_usecases_state |= 0x1 << i;
1027 ret = offload_usecases[i];
1028 break;
1029 }
1030 }
1031 ALOGV("%s: offload usecase is %d", __func__, ret);
1032 return ret;
1033}
1034
1035static void free_offload_usecase(struct audio_device *adev,
1036 audio_usecase_t uc_id)
1037{
1038 unsigned int i;
1039 for (i = 0; i < sizeof(offload_usecases)/sizeof(offload_usecases[0]); i++) {
1040 if (offload_usecases[i] == uc_id) {
1041 adev->offload_usecases_state &= ~(0x1<<i);
1042 break;
1043 }
1044 }
1045 ALOGV("%s: free offload usecase %d", __func__, uc_id);
1046}
1047
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001048static void *offload_thread_loop(void *context)
1049{
1050 struct stream_out *out = (struct stream_out *) context;
1051 struct listnode *item;
Krishnankutty Kolathappillyd4f1d132014-01-06 18:33:58 -08001052 int ret = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001053
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001054 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
1055 set_sched_policy(0, SP_FOREGROUND);
1056 prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0);
1057
1058 ALOGV("%s", __func__);
1059 pthread_mutex_lock(&out->lock);
1060 for (;;) {
1061 struct offload_cmd *cmd = NULL;
1062 stream_callback_event_t event;
1063 bool send_callback = false;
1064
1065 ALOGVV("%s offload_cmd_list %d out->offload_state %d",
1066 __func__, list_empty(&out->offload_cmd_list),
1067 out->offload_state);
1068 if (list_empty(&out->offload_cmd_list)) {
1069 ALOGV("%s SLEEPING", __func__);
1070 pthread_cond_wait(&out->offload_cond, &out->lock);
1071 ALOGV("%s RUNNING", __func__);
1072 continue;
1073 }
1074
1075 item = list_head(&out->offload_cmd_list);
1076 cmd = node_to_item(item, struct offload_cmd, node);
1077 list_remove(item);
1078
1079 ALOGVV("%s STATE %d CMD %d out->compr %p",
1080 __func__, out->offload_state, cmd->cmd, out->compr);
1081
1082 if (cmd->cmd == OFFLOAD_CMD_EXIT) {
1083 free(cmd);
1084 break;
1085 }
1086
1087 if (out->compr == NULL) {
1088 ALOGE("%s: Compress handle is NULL", __func__);
1089 pthread_cond_signal(&out->cond);
1090 continue;
1091 }
1092 out->offload_thread_blocked = true;
1093 pthread_mutex_unlock(&out->lock);
1094 send_callback = false;
1095 switch(cmd->cmd) {
1096 case OFFLOAD_CMD_WAIT_FOR_BUFFER:
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001097 ALOGD("copl(%p):calling compress_wait", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001098 compress_wait(out->compr, -1);
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001099 ALOGD("copl(%p):out of compress_wait", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001100 send_callback = true;
1101 event = STREAM_CBK_EVENT_WRITE_READY;
1102 break;
1103 case OFFLOAD_CMD_PARTIAL_DRAIN:
Krishnankutty Kolathappillyd4f1d132014-01-06 18:33:58 -08001104 ret = compress_next_track(out->compr);
Sidipotu Ashok55820562014-02-10 16:16:38 +05301105 if(ret == 0) {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001106 ALOGD("copl(%p):calling compress_partial_drain", out);
Krishnankutty Kolathappillyd4f1d132014-01-06 18:33:58 -08001107 compress_partial_drain(out->compr);
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001108 ALOGD("copl(%p):out of compress_partial_drain", out);
Sidipotu Ashok55820562014-02-10 16:16:38 +05301109 }
Krishnankutty Kolathappillyd4f1d132014-01-06 18:33:58 -08001110 else if(ret == -ETIMEDOUT)
1111 compress_drain(out->compr);
1112 else
1113 ALOGE("%s: Next track returned error %d",__func__, ret);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001114 send_callback = true;
1115 event = STREAM_CBK_EVENT_DRAIN_READY;
1116 break;
1117 case OFFLOAD_CMD_DRAIN:
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001118 ALOGD("copl(%p):calling compress_drain", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001119 compress_drain(out->compr);
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001120 ALOGD("copl(%p):calling compress_drain", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001121 send_callback = true;
1122 event = STREAM_CBK_EVENT_DRAIN_READY;
1123 break;
1124 default:
1125 ALOGE("%s unknown command received: %d", __func__, cmd->cmd);
1126 break;
1127 }
1128 pthread_mutex_lock(&out->lock);
1129 out->offload_thread_blocked = false;
1130 pthread_cond_signal(&out->cond);
Eric Laurent6e895242013-09-05 16:10:57 -07001131 if (send_callback) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001132 out->offload_callback(event, NULL, out->offload_cookie);
Eric Laurent6e895242013-09-05 16:10:57 -07001133 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001134 free(cmd);
1135 }
1136
1137 pthread_cond_signal(&out->cond);
1138 while (!list_empty(&out->offload_cmd_list)) {
1139 item = list_head(&out->offload_cmd_list);
1140 list_remove(item);
1141 free(node_to_item(item, struct offload_cmd, node));
1142 }
1143 pthread_mutex_unlock(&out->lock);
1144
1145 return NULL;
1146}
1147
1148static int create_offload_callback_thread(struct stream_out *out)
1149{
1150 pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL);
1151 list_init(&out->offload_cmd_list);
1152 pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL,
1153 offload_thread_loop, out);
1154 return 0;
1155}
1156
1157static int destroy_offload_callback_thread(struct stream_out *out)
1158{
1159 pthread_mutex_lock(&out->lock);
1160 stop_compressed_output_l(out);
1161 send_offload_cmd_l(out, OFFLOAD_CMD_EXIT);
1162
1163 pthread_mutex_unlock(&out->lock);
1164 pthread_join(out->offload_thread, (void **) NULL);
1165 pthread_cond_destroy(&out->offload_cond);
1166
1167 return 0;
1168}
1169
Eric Laurent07eeafd2013-10-06 12:52:49 -07001170static bool allow_hdmi_channel_config(struct audio_device *adev)
1171{
1172 struct listnode *node;
1173 struct audio_usecase *usecase;
1174 bool ret = true;
1175
1176 list_for_each(node, &adev->usecase_list) {
1177 usecase = node_to_item(node, struct audio_usecase, list);
1178 if (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1179 /*
1180 * If voice call is already existing, do not proceed further to avoid
1181 * disabling/enabling both RX and TX devices, CSD calls, etc.
1182 * Once the voice call done, the HDMI channels can be configured to
1183 * max channels of remaining use cases.
1184 */
1185 if (usecase->id == USECASE_VOICE_CALL) {
1186 ALOGD("%s: voice call is active, no change in HDMI channels",
1187 __func__);
1188 ret = false;
1189 break;
1190 } else if (usecase->id == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1191 ALOGD("%s: multi channel playback is active, "
1192 "no change in HDMI channels", __func__);
1193 ret = false;
1194 break;
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001195 } else if (is_offload_usecase(usecase->id) &&
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07001196 audio_channel_count_from_out_mask(usecase->stream.out->channel_mask) > 2) {
Mingming Yin139f1072014-02-24 17:56:01 -08001197 ALOGD("%s: multi-channel(%x) compress offload playback is active, "
1198 "no change in HDMI channels", __func__, usecase->stream.out->channel_mask);
1199 ret = false;
1200 break;
Eric Laurent07eeafd2013-10-06 12:52:49 -07001201 }
1202 }
1203 }
1204 return ret;
1205}
1206
1207static int check_and_set_hdmi_channels(struct audio_device *adev,
1208 unsigned int channels)
1209{
1210 struct listnode *node;
1211 struct audio_usecase *usecase;
1212
1213 /* Check if change in HDMI channel config is allowed */
1214 if (!allow_hdmi_channel_config(adev))
1215 return 0;
1216
1217 if (channels == adev->cur_hdmi_channels) {
Mingming Yin10fef6a2013-11-26 17:17:01 -08001218 ALOGD("%s: Requested channels are same as current channels(%d)", __func__, channels);
Eric Laurent07eeafd2013-10-06 12:52:49 -07001219 return 0;
1220 }
1221
1222 platform_set_hdmi_channels(adev->platform, channels);
1223 adev->cur_hdmi_channels = channels;
1224
1225 /*
1226 * Deroute all the playback streams routed to HDMI so that
1227 * the back end is deactivated. Note that backend will not
1228 * be deactivated if any one stream is connected to it.
1229 */
1230 list_for_each(node, &adev->usecase_list) {
1231 usecase = node_to_item(node, struct audio_usecase, list);
1232 if (usecase->type == PCM_PLAYBACK &&
1233 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001234 disable_audio_route(adev, usecase);
Eric Laurent07eeafd2013-10-06 12:52:49 -07001235 }
1236 }
1237
1238 /*
1239 * Enable all the streams disabled above. Now the HDMI backend
1240 * will be activated with new channel configuration
1241 */
1242 list_for_each(node, &adev->usecase_list) {
1243 usecase = node_to_item(node, struct audio_usecase, list);
1244 if (usecase->type == PCM_PLAYBACK &&
1245 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001246 enable_audio_route(adev, usecase);
Eric Laurent07eeafd2013-10-06 12:52:49 -07001247 }
1248 }
1249
1250 return 0;
1251}
1252
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001253static int stop_output_stream(struct stream_out *out)
1254{
1255 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001256 struct audio_usecase *uc_info;
1257 struct audio_device *adev = out->dev;
1258
Eric Laurent994a6932013-07-17 11:51:42 -07001259 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001260 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001261 uc_info = get_usecase_from_list(adev, out->usecase);
1262 if (uc_info == NULL) {
1263 ALOGE("%s: Could not find the usecase (%d) in the list",
1264 __func__, out->usecase);
1265 return -EINVAL;
1266 }
1267
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001268 if (is_offload_usecase(out->usecase)) {
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08001269 if (adev->visualizer_stop_output != NULL)
1270 adev->visualizer_stop_output(out->handle, out->pcm_device_id);
1271 if (adev->offload_effects_stop_output != NULL)
1272 adev->offload_effects_stop_output(out->handle, out->pcm_device_id);
1273 }
Eric Laurentc4aef752013-09-12 17:45:53 -07001274
Eric Laurent150dbfe2013-02-27 14:31:02 -08001275 /* 1. Get and set stream specific mixer controls */
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001276 disable_audio_route(adev, uc_info);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001277
1278 /* 2. Disable the rx device */
Haynes Mathew George1376ca62014-04-24 11:55:48 -07001279 disable_snd_device(adev, uc_info->out_snd_device);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001280
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001281 list_remove(&uc_info->list);
1282 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001283
Eric Laurent07eeafd2013-10-06 12:52:49 -07001284 /* Must be called after removing the usecase from list */
1285 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
1286 check_and_set_hdmi_channels(adev, DEFAULT_HDMI_OUT_CHANNELS);
1287
Eric Laurent994a6932013-07-17 11:51:42 -07001288 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001289 return ret;
1290}
1291
1292int start_output_stream(struct stream_out *out)
1293{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001294 int ret = 0;
Mingming Yin9c041392014-05-01 15:37:31 -07001295 int sink_channels = 0;
1296 char prop_value[PROPERTY_VALUE_MAX] = {0};
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001297 struct audio_usecase *uc_info;
1298 struct audio_device *adev = out->dev;
Naresh Tanniru80659832014-06-04 18:17:56 +05301299 int snd_card_status = get_snd_card_state(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001300
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001301 if ((out->usecase < 0) || (out->usecase >= AUDIO_USECASE_MAX)) {
1302 ret = -EINVAL;
1303 goto error_config;
1304 }
1305
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05301306 ALOGD("%s: enter: stream(%p)usecase(%d: %s) devices(%#x)",
1307 __func__, &out->stream, out->usecase, use_case_table[out->usecase],
1308 out->devices);
Naresh Tanniru4c630392014-05-12 01:05:52 +05301309
Naresh Tanniru80659832014-06-04 18:17:56 +05301310 if (SND_CARD_STATE_OFFLINE == snd_card_status) {
Naresh Tanniru4c630392014-05-12 01:05:52 +05301311 ALOGE("%s: sound card is not active/SSR returning error", __func__);
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +05301312 ret = -EIO;
Naresh Tanniru4c630392014-05-12 01:05:52 +05301313 goto error_config;
1314 }
Naresh Tanniru4c630392014-05-12 01:05:52 +05301315
Eric Laurentb23d5282013-05-14 15:27:20 -07001316 out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001317 if (out->pcm_device_id < 0) {
1318 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
1319 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001320 ret = -EINVAL;
1321 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001322 }
1323
1324 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001325
1326 if (!uc_info) {
1327 ret = -ENOMEM;
1328 goto error_config;
1329 }
1330
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001331 uc_info->id = out->usecase;
1332 uc_info->type = PCM_PLAYBACK;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001333 uc_info->stream.out = out;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001334 uc_info->devices = out->devices;
1335 uc_info->in_snd_device = SND_DEVICE_NONE;
1336 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001337
Eric Laurent07eeafd2013-10-06 12:52:49 -07001338 /* This must be called before adding this usecase to the list */
Mingming Yin10fef6a2013-11-26 17:17:01 -08001339 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Mingming Yin9c041392014-05-01 15:37:31 -07001340 property_get("audio.use.hdmi.sink.cap", prop_value, NULL);
1341 if (!strncmp("true", prop_value, 4)) {
1342 sink_channels = platform_edid_get_max_channels(out->dev->platform);
1343 ALOGD("%s: set HDMI channel count[%d] based on sink capability", __func__, sink_channels);
1344 check_and_set_hdmi_channels(adev, sink_channels);
1345 } else {
1346 if (is_offload_usecase(out->usecase))
1347 check_and_set_hdmi_channels(adev, out->compr_config.codec->ch_in);
1348 else
1349 check_and_set_hdmi_channels(adev, out->config.channels);
1350 }
Mingming Yin10fef6a2013-11-26 17:17:01 -08001351 }
Eric Laurent07eeafd2013-10-06 12:52:49 -07001352
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001353 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001354
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001355 select_devices(adev, out->usecase);
1356
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001357 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
1358 __func__, 0, out->pcm_device_id);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001359 if (!is_offload_usecase(out->usecase)) {
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001360 out->pcm = pcm_open(adev->snd_card,
1361 out->pcm_device_id,
1362 PCM_OUT | PCM_MONOTONIC, &out->config);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001363 if (out->pcm && !pcm_is_ready(out->pcm)) {
1364 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
1365 pcm_close(out->pcm);
1366 out->pcm = NULL;
1367 ret = -EIO;
1368 goto error_open;
1369 }
1370 } else {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001371 out->pcm = NULL;
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001372 out->compr = compress_open(adev->snd_card,
1373 out->pcm_device_id,
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001374 COMPRESS_IN, &out->compr_config);
1375 if (out->compr && !is_compress_ready(out->compr)) {
1376 ALOGE("%s: %s", __func__, compress_get_error(out->compr));
1377 compress_close(out->compr);
1378 out->compr = NULL;
1379 ret = -EIO;
1380 goto error_open;
1381 }
1382 if (out->offload_callback)
1383 compress_nonblock(out->compr, out->non_blocking);
Eric Laurentc4aef752013-09-12 17:45:53 -07001384
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08001385#ifdef DS1_DOLBY_DDP_ENABLED
1386 if (audio_extn_is_dolby_format(out->format))
1387 audio_extn_dolby_send_ddp_endp_params(adev);
1388#endif
1389
Eric Laurentc4aef752013-09-12 17:45:53 -07001390 if (adev->visualizer_start_output != NULL)
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08001391 adev->visualizer_start_output(out->handle, out->pcm_device_id);
1392 if (adev->offload_effects_start_output != NULL)
1393 adev->offload_effects_start_output(out->handle, out->pcm_device_id);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001394 }
Eric Laurent994a6932013-07-17 11:51:42 -07001395 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001396 return 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001397error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001398 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001399error_config:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001400 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001401}
1402
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001403static int check_input_parameters(uint32_t sample_rate,
1404 audio_format_t format,
1405 int channel_count)
1406{
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001407 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001408
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001409 if ((format != AUDIO_FORMAT_PCM_16_BIT) &&
Mingming Yine62d7842013-10-25 16:26:03 -07001410 !voice_extn_compress_voip_is_format_supported(format) &&
1411 !audio_extn_compr_cap_format_supported(format)) ret = -EINVAL;
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001412
1413 switch (channel_count) {
1414 case 1:
1415 case 2:
1416 case 6:
1417 break;
1418 default:
1419 ret = -EINVAL;
1420 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001421
1422 switch (sample_rate) {
1423 case 8000:
1424 case 11025:
1425 case 12000:
1426 case 16000:
1427 case 22050:
1428 case 24000:
1429 case 32000:
1430 case 44100:
1431 case 48000:
1432 break;
1433 default:
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001434 ret = -EINVAL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001435 }
1436
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001437 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001438}
1439
1440static size_t get_input_buffer_size(uint32_t sample_rate,
1441 audio_format_t format,
1442 int channel_count)
1443{
1444 size_t size = 0;
1445
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001446 if (check_input_parameters(sample_rate, format, channel_count) != 0)
1447 return 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001448
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001449 size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
1450 /* ToDo: should use frame_size computed based on the format and
1451 channel_count here. */
1452 size *= sizeof(short) * channel_count;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001453
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001454 /* make sure the size is multiple of 64 */
1455 size += 0x3f;
1456 size &= ~0x3f;
1457
1458 return size;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001459}
1460
1461static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1462{
1463 struct stream_out *out = (struct stream_out *)stream;
1464
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001465 return out->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001466}
1467
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001468static int out_set_sample_rate(struct audio_stream *stream __unused,
1469 uint32_t rate __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001470{
1471 return -ENOSYS;
1472}
1473
1474static size_t out_get_buffer_size(const struct audio_stream *stream)
1475{
1476 struct stream_out *out = (struct stream_out *)stream;
1477
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001478 if (is_offload_usecase(out->usecase))
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001479 return out->compr_config.fragment_size;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001480 else if(out->usecase == USECASE_COMPRESS_VOIP_CALL)
1481 return voice_extn_compress_voip_out_get_buffer_size(out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001482
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07001483 return out->config.period_size *
1484 audio_stream_out_frame_size((const struct audio_stream_out *)stream);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001485}
1486
1487static uint32_t out_get_channels(const struct audio_stream *stream)
1488{
1489 struct stream_out *out = (struct stream_out *)stream;
1490
1491 return out->channel_mask;
1492}
1493
1494static audio_format_t out_get_format(const struct audio_stream *stream)
1495{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001496 struct stream_out *out = (struct stream_out *)stream;
1497
1498 return out->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001499}
1500
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001501static int out_set_format(struct audio_stream *stream __unused,
1502 audio_format_t format __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001503{
1504 return -ENOSYS;
1505}
1506
1507static int out_standby(struct audio_stream *stream)
1508{
1509 struct stream_out *out = (struct stream_out *)stream;
1510 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001511
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05301512 ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__,
1513 stream, out->usecase, use_case_table[out->usecase]);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001514 if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
1515 /* Ignore standby in case of voip call because the voip output
1516 * stream is closed in adev_close_output_stream()
1517 */
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05301518 ALOGD("%s: Ignore Standby in VOIP call", __func__);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001519 return 0;
1520 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001521
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001522 pthread_mutex_lock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001523 if (!out->standby) {
Ravi Kumar Alamanda8bba9e92013-11-11 21:09:07 -08001524 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001525 out->standby = true;
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001526 if (!is_offload_usecase(out->usecase)) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001527 if (out->pcm) {
1528 pcm_close(out->pcm);
1529 out->pcm = NULL;
1530 }
1531 } else {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001532 ALOGD("copl(%p):standby", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001533 stop_compressed_output_l(out);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001534 out->gapless_mdata.encoder_delay = 0;
1535 out->gapless_mdata.encoder_padding = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001536 if (out->compr != NULL) {
1537 compress_close(out->compr);
1538 out->compr = NULL;
1539 }
Eric Laurent150dbfe2013-02-27 14:31:02 -08001540 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001541 stop_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001542 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001543 }
1544 pthread_mutex_unlock(&out->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001545 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001546 return 0;
1547}
1548
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001549static int out_dump(const struct audio_stream *stream __unused,
1550 int fd __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001551{
1552 return 0;
1553}
1554
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001555static int parse_compress_metadata(struct stream_out *out, struct str_parms *parms)
1556{
1557 int ret = 0;
1558 char value[32];
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001559 bool is_meta_data_params = false;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001560 struct compr_gapless_mdata tmp_mdata;
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001561 tmp_mdata.encoder_delay = 0;
1562 tmp_mdata.encoder_padding = 0;
ApurupaPattapu2e084df2013-12-18 15:47:59 -08001563
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001564 if (!out || !parms) {
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001565 ALOGE("%s: return invalid ",__func__);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001566 return -EINVAL;
1567 }
1568
ApurupaPattapu2e084df2013-12-18 15:47:59 -08001569 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FORMAT, value, sizeof(value));
1570 if (ret >= 0) {
1571 if (atoi(value) == SND_AUDIOSTREAMFORMAT_MP4ADTS) {
1572 out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4ADTS;
1573 ALOGV("ADTS format is set in offload mode");
1574 }
1575 out->send_new_metadata = 1;
1576 }
1577
Mingming Yin3ee55c62014-08-04 14:23:35 -07001578 if (out->format == AUDIO_FORMAT_FLAC) {
1579 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_BLK_SIZE, value, sizeof(value));
1580 if (ret >= 0) {
1581 out->compr_config.codec->options.flac_dec.min_blk_size = atoi(value);
1582 out->send_new_metadata = 1;
1583 }
1584 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_BLK_SIZE, value, sizeof(value));
1585 if (ret >= 0) {
1586 out->compr_config.codec->options.flac_dec.max_blk_size = atoi(value);
1587 out->send_new_metadata = 1;
1588 }
1589 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MIN_FRAME_SIZE, value, sizeof(value));
1590 if (ret >= 0) {
1591 out->compr_config.codec->options.flac_dec.min_frame_size = atoi(value);
1592 out->send_new_metadata = 1;
1593 }
1594 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FLAC_MAX_FRAME_SIZE, value, sizeof(value));
1595 if (ret >= 0) {
1596 out->compr_config.codec->options.flac_dec.max_frame_size = atoi(value);
1597 out->send_new_metadata = 1;
1598 }
1599 }
1600
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001601 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_SAMPLE_RATE, value, sizeof(value));
1602 if(ret >= 0)
1603 is_meta_data_params = true;
1604 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_NUM_CHANNEL, value, sizeof(value));
1605 if(ret >= 0 )
1606 is_meta_data_params = true;
1607 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE, value, sizeof(value));
1608 if(ret >= 0 )
1609 is_meta_data_params = true;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001610 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, value, sizeof(value));
1611 if (ret >= 0) {
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001612 is_meta_data_params = true;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001613 tmp_mdata.encoder_delay = atoi(value); //whats a good limit check?
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001614 }
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001615 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, value, sizeof(value));
1616 if (ret >= 0) {
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001617 is_meta_data_params = true;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001618 tmp_mdata.encoder_padding = atoi(value);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001619 }
1620
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001621 if(!is_meta_data_params) {
1622 ALOGV("%s: Not gapless meta data params", __func__);
1623 return 0;
1624 }
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001625 out->gapless_mdata = tmp_mdata;
1626 out->send_new_metadata = 1;
1627 ALOGV("%s new encoder delay %u and padding %u", __func__,
1628 out->gapless_mdata.encoder_delay, out->gapless_mdata.encoder_padding);
1629
1630 return 0;
1631}
1632
1633
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001634static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1635{
1636 struct stream_out *out = (struct stream_out *)stream;
1637 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001638 struct audio_usecase *usecase;
1639 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001640 struct str_parms *parms;
1641 char value[32];
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001642 int ret = 0, val = 0, err;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001643 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001644
sangwoobc677242013-08-08 16:53:43 +09001645 ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001646 __func__, out->usecase, use_case_table[out->usecase], kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001647 parms = str_parms_create_str(kvpairs);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001648 err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1649 if (err >= 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001650 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001651 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001652 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001653
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001654 /*
Dhanalakshmi Siddani929a1f12014-04-18 22:26:56 +05301655 * When HDMI cable is unplugged/usb hs is disconnected the
1656 * music playback is paused and the policy manager sends routing=0
1657 * But the audioflingercontinues to write data until standby time
1658 * (3sec). As the HDMI core is turned off, the write gets blocked.
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001659 * Avoid this by routing audio to speaker until standby.
1660 */
Dhanalakshmi Siddani929a1f12014-04-18 22:26:56 +05301661 if ((out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
1662 out->devices == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET) &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001663 val == AUDIO_DEVICE_NONE) {
1664 val = AUDIO_DEVICE_OUT_SPEAKER;
1665 }
1666
1667 /*
1668 * select_devices() call below switches all the usecases on the same
1669 * backend to the new device. Refer to check_usecases_codec_backend() in
1670 * the select_devices(). But how do we undo this?
1671 *
1672 * For example, music playback is active on headset (deep-buffer usecase)
1673 * and if we go to ringtones and select a ringtone, low-latency usecase
1674 * will be started on headset+speaker. As we can't enable headset+speaker
1675 * and headset devices at the same time, select_devices() switches the music
1676 * playback to headset+speaker while starting low-lateny usecase for ringtone.
1677 * So when the ringtone playback is completed, how do we undo the same?
1678 *
1679 * We are relying on the out_set_parameters() call on deep-buffer output,
1680 * once the ringtone playback is ended.
1681 * NOTE: We should not check if the current devices are same as new devices.
1682 * Because select_devices() must be called to switch back the music
1683 * playback to headset.
1684 */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001685 if (val != 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001686 out->devices = val;
1687
1688 if (!out->standby)
1689 select_devices(adev, out->usecase);
1690
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001691 if ((adev->mode == AUDIO_MODE_IN_CALL) &&
Vidyakumar Athotaad34d572014-08-05 18:20:42 -07001692 !adev->voice.in_call &&
1693 (out == adev->primary_output)) {
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001694 ret = voice_start_call(adev);
Vidyakumar Athotaad34d572014-08-05 18:20:42 -07001695 } else if ((adev->mode == AUDIO_MODE_IN_CALL) &&
1696 adev->voice.in_call &&
1697 (out == adev->primary_output)) {
Narsinga Rao Chella22d8d7a2014-02-06 14:05:14 -08001698 voice_update_devices_for_all_voice_usecases(adev);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001699 }
1700 }
1701
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001702 if ((adev->mode == AUDIO_MODE_NORMAL) &&
Vidyakumar Athotaad34d572014-08-05 18:20:42 -07001703 adev->voice.in_call &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001704 (out == adev->primary_output)) {
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08001705 ret = voice_stop_call(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001706 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001707
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001708 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001709 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001710 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001711
1712 if (out == adev->primary_output) {
1713 pthread_mutex_lock(&adev->lock);
1714 audio_extn_set_parameters(adev, parms);
1715 pthread_mutex_unlock(&adev->lock);
1716 }
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001717 if (is_offload_usecase(out->usecase)) {
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001718 pthread_mutex_lock(&out->lock);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001719 parse_compress_metadata(out, parms);
Krishnankutty Kolathappillyeb78be72013-12-15 12:03:07 -08001720 pthread_mutex_unlock(&out->lock);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001721 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001722
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001723 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001724 ALOGV("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001725 return ret;
1726}
1727
1728static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1729{
1730 struct stream_out *out = (struct stream_out *)stream;
1731 struct str_parms *query = str_parms_create_str(keys);
1732 char *str;
1733 char value[256];
1734 struct str_parms *reply = str_parms_create();
1735 size_t i, j;
1736 int ret;
1737 bool first = true;
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001738
1739 if (!query || !reply) {
1740 ALOGE("out_get_parameters: failed to allocate mem for query or reply");
1741 return NULL;
1742 }
1743
Eric Laurent994a6932013-07-17 11:51:42 -07001744 ALOGV("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001745 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1746 if (ret >= 0) {
1747 value[0] = '\0';
1748 i = 0;
1749 while (out->supported_channel_masks[i] != 0) {
1750 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1751 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1752 if (!first) {
1753 strcat(value, "|");
1754 }
1755 strcat(value, out_channels_name_to_enum_table[j].name);
1756 first = false;
1757 break;
1758 }
1759 }
1760 i++;
1761 }
1762 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1763 str = str_parms_to_str(reply);
1764 } else {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001765 voice_extn_out_get_parameters(out, query, reply);
1766 str = str_parms_to_str(reply);
1767 if (!strncmp(str, "", sizeof(""))) {
Narsinga Rao Chella29b8fc72014-01-29 12:52:19 -08001768 free(str);
1769 str = strdup(keys);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001770 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001771 }
1772 str_parms_destroy(query);
1773 str_parms_destroy(reply);
Eric Laurent994a6932013-07-17 11:51:42 -07001774 ALOGV("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001775 return str;
1776}
1777
1778static uint32_t out_get_latency(const struct audio_stream_out *stream)
1779{
1780 struct stream_out *out = (struct stream_out *)stream;
1781
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001782 if (is_offload_usecase(out->usecase))
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001783 return COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
1784
1785 return (out->config.period_count * out->config.period_size * 1000) /
1786 (out->config.rate);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001787}
1788
1789static int out_set_volume(struct audio_stream_out *stream, float left,
1790 float right)
1791{
Eric Laurenta9024de2013-04-04 09:19:12 -07001792 struct stream_out *out = (struct stream_out *)stream;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001793 int volume[2];
1794
Eric Laurenta9024de2013-04-04 09:19:12 -07001795 if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1796 /* only take left channel into account: the API is for stereo anyway */
1797 out->muted = (left == 0.0f);
1798 return 0;
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001799 } else if (is_offload_usecase(out->usecase)) {
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08001800 char mixer_ctl_name[128];
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001801 struct audio_device *adev = out->dev;
1802 struct mixer_ctl *ctl;
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08001803 int pcm_device_id = platform_get_pcm_device_id(out->usecase,
1804 PCM_PLAYBACK);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001805
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08001806 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
1807 "Compress Playback %d Volume", pcm_device_id);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001808 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1809 if (!ctl) {
1810 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1811 __func__, mixer_ctl_name);
1812 return -EINVAL;
1813 }
1814 volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX);
1815 volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX);
1816 mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0]));
1817 return 0;
Eric Laurenta9024de2013-04-04 09:19:12 -07001818 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001819
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001820 return -ENOSYS;
1821}
1822
1823static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1824 size_t bytes)
1825{
1826 struct stream_out *out = (struct stream_out *)stream;
1827 struct audio_device *adev = out->dev;
Naresh Tanniru80659832014-06-04 18:17:56 +05301828 int snd_scard_state = get_snd_card_state(adev);
Eric Laurent6e895242013-09-05 16:10:57 -07001829 ssize_t ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001830
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001831 pthread_mutex_lock(&out->lock);
Naresh Tanniru4c630392014-05-12 01:05:52 +05301832
Naresh Tanniru80659832014-06-04 18:17:56 +05301833 if (SND_CARD_STATE_OFFLINE == snd_scard_state) {
1834 if (out->pcm) {
Naresh Tanniru4c630392014-05-12 01:05:52 +05301835 ALOGD(" %s: sound card is not active/SSR state", __func__);
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +05301836 ret= -EIO;
Naresh Tanniru4c630392014-05-12 01:05:52 +05301837 goto exit;
Naresh Tanniru80659832014-06-04 18:17:56 +05301838 } else if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1839 //during SSR for compress usecase we should return error to flinger
1840 ALOGD(" copl %s: sound card is not active/SSR state", __func__);
1841 pthread_mutex_unlock(&out->lock);
1842 return -ENETRESET;
Naresh Tanniru4c630392014-05-12 01:05:52 +05301843 }
1844 }
1845
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001846 if (out->standby) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001847 out->standby = false;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001848 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001849 if (out->usecase == USECASE_COMPRESS_VOIP_CALL)
1850 ret = voice_extn_compress_voip_start_output_stream(out);
1851 else
1852 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001853 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001854 /* ToDo: If use case is compress offload should return 0 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001855 if (ret != 0) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001856 out->standby = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001857 goto exit;
1858 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001859 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001860
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001861 if (is_offload_usecase(out->usecase)) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001862 ALOGD("copl(%p): writing buffer (%zu bytes) to compress device", out, bytes);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001863 if (out->send_new_metadata) {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07001864 ALOGD("copl(%p):send new gapless metadata", out);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001865 compress_set_gapless_metadata(out->compr, &out->gapless_mdata);
1866 out->send_new_metadata = 0;
1867 }
1868
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001869 ret = compress_write(out->compr, buffer, bytes);
Dhanalakshmi Siddani37ca1d62014-08-20 12:28:34 +05301870 if (ret < 0)
1871 ret = -errno;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001872 ALOGVV("%s: writing buffer (%d bytes) to compress device returned %d", __func__, bytes, ret);
Eric Laurent6e895242013-09-05 16:10:57 -07001873 if (ret >= 0 && ret < (ssize_t)bytes) {
Sidipotu Ashok55820562014-02-10 16:16:38 +05301874 ALOGD("No space available in compress driver, post msg to cb thread");
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001875 send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER);
Naresh Tanniru80659832014-06-04 18:17:56 +05301876 } else if (-ENETRESET == ret) {
1877 ALOGE("copl %s: received sound card offline state on compress write", __func__);
1878 set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
1879 pthread_mutex_unlock(&out->lock);
1880 out_standby(&out->stream.common);
1881 return ret;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001882 }
Naresh Tanniru80659832014-06-04 18:17:56 +05301883 if (!out->playback_started && ret >= 0) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001884 compress_start(out->compr);
1885 out->playback_started = 1;
1886 out->offload_state = OFFLOAD_STATE_PLAYING;
1887 }
1888 pthread_mutex_unlock(&out->lock);
1889 return ret;
1890 } else {
1891 if (out->pcm) {
1892 if (out->muted)
1893 memset((void *)buffer, 0, bytes);
1894 ALOGVV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1895 ret = pcm_write(out->pcm, (void *)buffer, bytes);
Dhanalakshmi Siddani37ca1d62014-08-20 12:28:34 +05301896 if (ret < 0)
1897 ret = -errno;
1898 else if (ret == 0)
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001899 out->written += bytes / (out->config.channels * sizeof(short));
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001900 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001901 }
1902
1903exit:
Dhanalakshmi Siddani8fc6d912014-05-26 18:03:42 +05301904 /* ToDo: There may be a corner case when SSR happens back to back during
1905 start/stop. Need to post different error to handle that. */
Naresh Tanniru4c630392014-05-12 01:05:52 +05301906 if (-ENETRESET == ret) {
Naresh Tanniru80659832014-06-04 18:17:56 +05301907 set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
Naresh Tanniru4c630392014-05-12 01:05:52 +05301908 }
1909
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001910 pthread_mutex_unlock(&out->lock);
1911
1912 if (ret != 0) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001913 if (out->pcm)
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001914 ALOGE("%s: error %ld - %s", __func__, ret, pcm_get_error(out->pcm));
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05301915 if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05301916 pthread_mutex_lock(&adev->lock);
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05301917 voice_extn_compress_voip_close_output_stream(&out->stream.common);
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05301918 pthread_mutex_unlock(&adev->lock);
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05301919 out->standby = true;
1920 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001921 out_standby(&out->stream.common);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07001922 usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) /
Naresh Tanniru4c630392014-05-12 01:05:52 +05301923 out_get_sample_rate(&out->stream.common));
1924
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001925 }
1926 return bytes;
1927}
1928
1929static int out_get_render_position(const struct audio_stream_out *stream,
1930 uint32_t *dsp_frames)
1931{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001932 struct stream_out *out = (struct stream_out *)stream;
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001933 if (is_offload_usecase(out->usecase) && (dsp_frames != NULL)) {
Naresh Tanniru80659832014-06-04 18:17:56 +05301934 ssize_t ret = -EINVAL;
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001935 *dsp_frames = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001936 pthread_mutex_lock(&out->lock);
1937 if (out->compr != NULL) {
Naresh Tanniru80659832014-06-04 18:17:56 +05301938 ret = compress_get_tstamp(out->compr, (unsigned long *)dsp_frames,
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001939 &out->sample_rate);
Dhanalakshmi Siddani37ca1d62014-08-20 12:28:34 +05301940 if (ret < 0)
1941 ret = -errno;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001942 ALOGVV("%s rendered frames %d sample_rate %d",
1943 __func__, *dsp_frames, out->sample_rate);
1944 }
1945 pthread_mutex_unlock(&out->lock);
Naresh Tanniru80659832014-06-04 18:17:56 +05301946 if (-ENETRESET == ret) {
1947 ALOGE(" ERROR: sound card not active Unable to get time stamp from compress driver");
1948 set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
1949 return -EINVAL;
1950 } else if(ret < 0) {
1951 ALOGE(" ERROR: Unable to get time stamp from compress driver");
1952 return -EINVAL;
1953 } else {
1954 return 0;
1955 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001956 } else
1957 return -EINVAL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001958}
1959
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001960static int out_add_audio_effect(const struct audio_stream *stream __unused,
1961 effect_handle_t effect __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001962{
1963 return 0;
1964}
1965
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001966static int out_remove_audio_effect(const struct audio_stream *stream __unused,
1967 effect_handle_t effect __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001968{
1969 return 0;
1970}
1971
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001972static int out_get_next_write_timestamp(const struct audio_stream_out *stream __unused,
1973 int64_t *timestamp __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001974{
1975 return -EINVAL;
1976}
1977
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001978static int out_get_presentation_position(const struct audio_stream_out *stream,
1979 uint64_t *frames, struct timespec *timestamp)
1980{
1981 struct stream_out *out = (struct stream_out *)stream;
1982 int ret = -1;
Eric Laurent949a0892013-09-20 09:20:13 -07001983 unsigned long dsp_frames;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001984
1985 pthread_mutex_lock(&out->lock);
1986
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07001987 if (is_offload_usecase(out->usecase)) {
Eric Laurent949a0892013-09-20 09:20:13 -07001988 if (out->compr != NULL) {
1989 compress_get_tstamp(out->compr, &dsp_frames,
1990 &out->sample_rate);
1991 ALOGVV("%s rendered frames %ld sample_rate %d",
1992 __func__, dsp_frames, out->sample_rate);
1993 *frames = dsp_frames;
1994 ret = 0;
1995 /* this is the best we can do */
1996 clock_gettime(CLOCK_MONOTONIC, timestamp);
1997 }
1998 } else {
1999 if (out->pcm) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002000 unsigned int avail;
Eric Laurent949a0892013-09-20 09:20:13 -07002001 if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
2002 size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
Eric Laurent949a0892013-09-20 09:20:13 -07002003 int64_t signed_frames = out->written - kernel_buffer_size + avail;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002004 // This adjustment accounts for buffering after app processor.
2005 // It is based on estimated DSP latency per use case, rather than exact.
2006 signed_frames -=
2007 (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL);
2008
Eric Laurent949a0892013-09-20 09:20:13 -07002009 // It would be unusual for this value to be negative, but check just in case ...
2010 if (signed_frames >= 0) {
2011 *frames = signed_frames;
2012 ret = 0;
2013 }
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07002014 }
2015 }
2016 }
2017
2018 pthread_mutex_unlock(&out->lock);
2019
2020 return ret;
2021}
2022
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002023static int out_set_callback(struct audio_stream_out *stream,
2024 stream_callback_t callback, void *cookie)
2025{
2026 struct stream_out *out = (struct stream_out *)stream;
2027
2028 ALOGV("%s", __func__);
2029 pthread_mutex_lock(&out->lock);
2030 out->offload_callback = callback;
2031 out->offload_cookie = cookie;
2032 pthread_mutex_unlock(&out->lock);
2033 return 0;
2034}
2035
2036static int out_pause(struct audio_stream_out* stream)
2037{
2038 struct stream_out *out = (struct stream_out *)stream;
2039 int status = -ENOSYS;
2040 ALOGV("%s", __func__);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002041 if (is_offload_usecase(out->usecase)) {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002042 ALOGD("copl(%p):pause compress driver", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002043 pthread_mutex_lock(&out->lock);
2044 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) {
Naresh Tanniru80659832014-06-04 18:17:56 +05302045 struct audio_device *adev = out->dev;
2046 int snd_scard_state = get_snd_card_state(adev);
2047
2048 if (SND_CARD_STATE_ONLINE == snd_scard_state)
2049 status = compress_pause(out->compr);
2050
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002051 out->offload_state = OFFLOAD_STATE_PAUSED;
2052 }
2053 pthread_mutex_unlock(&out->lock);
2054 }
2055 return status;
2056}
2057
2058static int out_resume(struct audio_stream_out* stream)
2059{
2060 struct stream_out *out = (struct stream_out *)stream;
2061 int status = -ENOSYS;
2062 ALOGV("%s", __func__);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002063 if (is_offload_usecase(out->usecase)) {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002064 ALOGD("copl(%p):resume compress driver", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002065 status = 0;
2066 pthread_mutex_lock(&out->lock);
2067 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) {
Naresh Tanniru80659832014-06-04 18:17:56 +05302068 struct audio_device *adev = out->dev;
2069 int snd_scard_state = get_snd_card_state(adev);
2070
2071 if (SND_CARD_STATE_ONLINE == snd_scard_state)
2072 status = compress_resume(out->compr);
2073
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002074 out->offload_state = OFFLOAD_STATE_PLAYING;
2075 }
2076 pthread_mutex_unlock(&out->lock);
2077 }
2078 return status;
2079}
2080
2081static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type )
2082{
2083 struct stream_out *out = (struct stream_out *)stream;
2084 int status = -ENOSYS;
2085 ALOGV("%s", __func__);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002086 if (is_offload_usecase(out->usecase)) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002087 pthread_mutex_lock(&out->lock);
2088 if (type == AUDIO_DRAIN_EARLY_NOTIFY)
2089 status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN);
2090 else
2091 status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN);
2092 pthread_mutex_unlock(&out->lock);
2093 }
2094 return status;
2095}
2096
2097static int out_flush(struct audio_stream_out* stream)
2098{
2099 struct stream_out *out = (struct stream_out *)stream;
2100 ALOGV("%s", __func__);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002101 if (is_offload_usecase(out->usecase)) {
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002102 ALOGD("copl(%p):calling compress flush", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002103 pthread_mutex_lock(&out->lock);
2104 stop_compressed_output_l(out);
2105 pthread_mutex_unlock(&out->lock);
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07002106 ALOGD("copl(%p):out of compress flush", out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002107 return 0;
2108 }
2109 return -ENOSYS;
2110}
2111
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002112/** audio_stream_in implementation **/
2113static uint32_t in_get_sample_rate(const struct audio_stream *stream)
2114{
2115 struct stream_in *in = (struct stream_in *)stream;
2116
2117 return in->config.rate;
2118}
2119
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002120static int in_set_sample_rate(struct audio_stream *stream __unused,
2121 uint32_t rate __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002122{
2123 return -ENOSYS;
2124}
2125
2126static size_t in_get_buffer_size(const struct audio_stream *stream)
2127{
2128 struct stream_in *in = (struct stream_in *)stream;
2129
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002130 if(in->usecase == USECASE_COMPRESS_VOIP_CALL)
2131 return voice_extn_compress_voip_in_get_buffer_size(in);
Mingming Yine62d7842013-10-25 16:26:03 -07002132 else if(audio_extn_compr_cap_usecase_supported(in->usecase))
2133 return audio_extn_compr_cap_get_buffer_size(in->config.format);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002134
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002135 return in->config.period_size *
2136 audio_stream_in_frame_size((const struct audio_stream_in *)stream);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002137}
2138
2139static uint32_t in_get_channels(const struct audio_stream *stream)
2140{
2141 struct stream_in *in = (struct stream_in *)stream;
2142
2143 return in->channel_mask;
2144}
2145
2146static audio_format_t in_get_format(const struct audio_stream *stream)
2147{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002148 struct stream_in *in = (struct stream_in *)stream;
2149
2150 return in->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002151}
2152
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002153static int in_set_format(struct audio_stream *stream __unused,
2154 audio_format_t format __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002155{
2156 return -ENOSYS;
2157}
2158
2159static int in_standby(struct audio_stream *stream)
2160{
2161 struct stream_in *in = (struct stream_in *)stream;
2162 struct audio_device *adev = in->dev;
2163 int status = 0;
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302164 ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__,
2165 stream, in->usecase, use_case_table[in->usecase]);
2166
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002167 if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
2168 /* Ignore standby in case of voip call because the voip input
2169 * stream is closed in adev_close_input_stream()
2170 */
2171 ALOGV("%s: Ignore Standby in VOIP call", __func__);
2172 return status;
2173 }
2174
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002175 pthread_mutex_lock(&in->lock);
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002176 if (!in->standby && in->is_st_session) {
2177 ALOGD("%s: sound trigger pcm stop lab", __func__);
2178 audio_extn_sound_trigger_stop_lab(in);
2179 in->standby = 1;
2180 }
2181
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002182 if (!in->standby) {
Ravi Kumar Alamanda8bba9e92013-11-11 21:09:07 -08002183 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002184 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08002185 if (in->pcm) {
2186 pcm_close(in->pcm);
2187 in->pcm = NULL;
2188 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002189 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08002190 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002191 }
2192 pthread_mutex_unlock(&in->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07002193 ALOGV("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002194 return status;
2195}
2196
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002197static int in_dump(const struct audio_stream *stream __unused,
2198 int fd __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002199{
2200 return 0;
2201}
2202
2203static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
2204{
2205 struct stream_in *in = (struct stream_in *)stream;
2206 struct audio_device *adev = in->dev;
2207 struct str_parms *parms;
2208 char *str;
2209 char value[32];
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002210 int ret = 0, val = 0, err;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002211
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302212 ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002213 parms = str_parms_create_str(kvpairs);
2214
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002215 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08002216 pthread_mutex_lock(&adev->lock);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002217
2218 err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
2219 if (err >= 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002220 val = atoi(value);
2221 /* no audio source uses val == 0 */
2222 if ((in->source != val) && (val != 0)) {
2223 in->source = val;
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08002224 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
2225 (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
2226 (voice_extn_compress_voip_is_format_supported(in->format)) &&
2227 (in->config.rate == 8000 || in->config.rate == 16000) &&
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002228 (audio_channel_count_from_in_mask(in->channel_mask) == 1)) {
Narsinga Rao Chella7d5a3e82014-02-04 16:23:52 -08002229 err = voice_extn_compress_voip_open_input_stream(in);
2230 if (err != 0) {
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08002231 ALOGE("%s: Compress voip input cannot be opened, error:%d",
Narsinga Rao Chella7d5a3e82014-02-04 16:23:52 -08002232 __func__, err);
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08002233 }
2234 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002235 }
2236 }
2237
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002238 err = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
2239 if (err >= 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002240 val = atoi(value);
2241 if ((in->device != val) && (val != 0)) {
2242 in->device = val;
2243 /* If recording is in progress, change the tx device to new device */
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002244 if (!in->standby && !in->is_st_session)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002245 ret = select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002246 }
2247 }
2248
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08002249done:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002250 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08002251 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002252
2253 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07002254 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002255 return ret;
2256}
2257
2258static char* in_get_parameters(const struct audio_stream *stream,
2259 const char *keys)
2260{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002261 struct stream_in *in = (struct stream_in *)stream;
2262 struct str_parms *query = str_parms_create_str(keys);
2263 char *str;
2264 char value[256];
2265 struct str_parms *reply = str_parms_create();
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07002266
2267 if (!query || !reply) {
2268 ALOGE("in_get_parameters: failed to create query or reply");
2269 return NULL;
2270 }
2271
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002272 ALOGV("%s: enter: keys - %s", __func__, keys);
2273
2274 voice_extn_in_get_parameters(in, query, reply);
2275
2276 str = str_parms_to_str(reply);
2277 str_parms_destroy(query);
2278 str_parms_destroy(reply);
2279
2280 ALOGV("%s: exit: returns - %s", __func__, str);
2281 return str;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002282}
2283
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002284static int in_set_gain(struct audio_stream_in *stream __unused,
2285 float gain __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002286{
2287 return 0;
2288}
2289
2290static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
2291 size_t bytes)
2292{
2293 struct stream_in *in = (struct stream_in *)stream;
2294 struct audio_device *adev = in->dev;
2295 int i, ret = -1;
Naresh Tanniru80659832014-06-04 18:17:56 +05302296 int snd_scard_state = get_snd_card_state(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002297
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002298 pthread_mutex_lock(&in->lock);
Naresh Tanniru4c630392014-05-12 01:05:52 +05302299
2300 if (in->pcm) {
Naresh Tanniru80659832014-06-04 18:17:56 +05302301 if(SND_CARD_STATE_OFFLINE == snd_scard_state) {
Naresh Tanniru4c630392014-05-12 01:05:52 +05302302 ALOGD(" %s: sound card is not active/SSR state", __func__);
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +05302303 ret= -EIO;;
Naresh Tanniru4c630392014-05-12 01:05:52 +05302304 goto exit;
Naresh Tanniru4c630392014-05-12 01:05:52 +05302305 }
2306 }
2307
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002308 if (in->standby) {
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002309 if (!in->is_st_session) {
2310 pthread_mutex_lock(&adev->lock);
2311 if (in->usecase == USECASE_COMPRESS_VOIP_CALL)
2312 ret = voice_extn_compress_voip_start_input_stream(in);
2313 else
2314 ret = start_input_stream(in);
2315 pthread_mutex_unlock(&adev->lock);
2316 if (ret != 0) {
2317 goto exit;
2318 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002319 }
2320 in->standby = 0;
2321 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002322
2323 if (in->pcm) {
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002324 if (audio_extn_ssr_get_enabled() &&
2325 audio_channel_count_from_in_mask(in->channel_mask) == 6)
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002326 ret = audio_extn_ssr_read(stream, buffer, bytes);
Mingming Yine62d7842013-10-25 16:26:03 -07002327 else if (audio_extn_compr_cap_usecase_supported(in->usecase))
2328 ret = audio_extn_compr_cap_read(in, buffer, bytes);
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002329 else
2330 ret = pcm_read(in->pcm, buffer, bytes);
Dhanalakshmi Siddani37ca1d62014-08-20 12:28:34 +05302331 if (ret < 0)
2332 ret = -errno;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002333 }
2334
2335 /*
2336 * Instead of writing zeroes here, we could trust the hardware
2337 * to always provide zeroes when muted.
2338 */
kunleizc5a639b2014-04-24 18:46:22 +08002339 if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in))
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002340 memset(buffer, 0, bytes);
2341
2342exit:
Dhanalakshmi Siddani8fc6d912014-05-26 18:03:42 +05302343 /* ToDo: There may be a corner case when SSR happens back to back during
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +05302344 start/stop. Need to post different error to handle that. */
Naresh Tanniru4c630392014-05-12 01:05:52 +05302345 if (-ENETRESET == ret) {
Naresh Tanniru80659832014-06-04 18:17:56 +05302346 set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
Naresh Tanniru4c630392014-05-12 01:05:52 +05302347 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002348 pthread_mutex_unlock(&in->lock);
2349
2350 if (ret != 0) {
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05302351 if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05302352 pthread_mutex_lock(&adev->lock);
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05302353 voice_extn_compress_voip_close_input_stream(&in->stream.common);
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05302354 pthread_mutex_unlock(&adev->lock);
Venkata Narendra Kumar Guttabc9c9ca2014-06-25 20:38:03 +05302355 in->standby = true;
2356 }
Dhanalakshmi Siddani4d57e992014-07-17 16:37:51 +05302357 memset(buffer, 0, bytes);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002358 in_standby(&in->stream.common);
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002359 ALOGV("%s: read failed status %d- sleeping for buffer duration", __func__, ret);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002360 usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) /
Naresh Tanniru4c630392014-05-12 01:05:52 +05302361 in_get_sample_rate(&in->stream.common));
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002362 }
2363 return bytes;
2364}
2365
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002366static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002367{
2368 return 0;
2369}
2370
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002371static int add_remove_audio_effect(const struct audio_stream *stream,
2372 effect_handle_t effect,
2373 bool enable)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002374{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002375 struct stream_in *in = (struct stream_in *)stream;
2376 int status = 0;
2377 effect_descriptor_t desc;
2378
2379 status = (*effect)->get_descriptor(effect, &desc);
2380 if (status != 0)
2381 return status;
2382
2383 pthread_mutex_lock(&in->lock);
2384 pthread_mutex_lock(&in->dev->lock);
2385 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
2386 in->enable_aec != enable &&
2387 (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
2388 in->enable_aec = enable;
2389 if (!in->standby)
2390 select_devices(in->dev, in->usecase);
2391 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002392 if (in->enable_ns != enable &&
2393 (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) {
2394 in->enable_ns = enable;
2395 if (!in->standby)
2396 select_devices(in->dev, in->usecase);
2397 }
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002398 pthread_mutex_unlock(&in->dev->lock);
2399 pthread_mutex_unlock(&in->lock);
2400
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002401 return 0;
2402}
2403
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002404static int in_add_audio_effect(const struct audio_stream *stream,
2405 effect_handle_t effect)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002406{
Eric Laurent994a6932013-07-17 11:51:42 -07002407 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002408 return add_remove_audio_effect(stream, effect, true);
2409}
2410
2411static int in_remove_audio_effect(const struct audio_stream *stream,
2412 effect_handle_t effect)
2413{
Eric Laurent994a6932013-07-17 11:51:42 -07002414 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07002415 return add_remove_audio_effect(stream, effect, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002416}
2417
2418static int adev_open_output_stream(struct audio_hw_device *dev,
2419 audio_io_handle_t handle,
2420 audio_devices_t devices,
2421 audio_output_flags_t flags,
2422 struct audio_config *config,
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002423 struct audio_stream_out **stream_out,
2424 const char *address __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002425{
2426 struct audio_device *adev = (struct audio_device *)dev;
2427 struct stream_out *out;
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -08002428 int i, ret = 0;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002429 audio_format_t format;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +05302430 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002431
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002432 *stream_out = NULL;
Naresh Tanniru80659832014-06-04 18:17:56 +05302433
2434 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
2435 (SND_CARD_STATE_OFFLINE == get_snd_card_state(adev))) {
2436 ALOGE(" sound card is not active rejecting compress output open request");
2437 return -EINVAL;
2438 }
2439
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002440 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
2441
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302442 ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)\
2443 stream_handle(%p)",__func__, config->sample_rate, config->channel_mask,
2444 devices, flags, &out->stream);
2445
2446
Haynes Mathew Georgeb9012ab2013-12-10 13:44:56 -08002447 if (!out) {
2448 return -ENOMEM;
2449 }
2450
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002451 if (devices == AUDIO_DEVICE_NONE)
2452 devices = AUDIO_DEVICE_OUT_SPEAKER;
2453
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002454 out->flags = flags;
2455 out->devices = devices;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002456 out->dev = adev;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002457 format = out->format = config->format;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002458 out->sample_rate = config->sample_rate;
2459 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
2460 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
Eric Laurentc4aef752013-09-12 17:45:53 -07002461 out->handle = handle;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002462 out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002463
2464 /* Init use case and pcm_config */
Apoorv Raghuvanshi947cb902013-12-09 13:45:39 -08002465 if ((out->flags == AUDIO_OUTPUT_FLAG_DIRECT) &&
2466 (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ||
2467 out->devices & AUDIO_DEVICE_OUT_PROXY)) {
2468
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002469 pthread_mutex_lock(&adev->lock);
Apoorv Raghuvanshi947cb902013-12-09 13:45:39 -08002470 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
2471 ret = read_hdmi_channel_masks(out);
2472
2473 if (out->devices & AUDIO_DEVICE_OUT_PROXY)
2474 ret = audio_extn_read_afe_proxy_channel_masks(out);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002475 pthread_mutex_unlock(&adev->lock);
Eric Laurent07eeafd2013-10-06 12:52:49 -07002476 if (ret != 0)
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002477 goto error_open;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002478
2479 if (config->sample_rate == 0)
2480 config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
2481 if (config->channel_mask == 0)
2482 config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
2483
2484 out->channel_mask = config->channel_mask;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002485 out->sample_rate = config->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002486 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
2487 out->config = pcm_config_hdmi_multi;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002488 out->config.rate = config->sample_rate;
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002489 out->config.channels = audio_channel_count_from_out_mask(out->channel_mask);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002490 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002491 } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
2492 (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) &&
Narsinga Rao Chella1eceff82013-12-02 19:25:28 -08002493 (voice_extn_compress_voip_is_config_supported(config))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002494 ret = voice_extn_compress_voip_open_output_stream(out);
2495 if (ret != 0) {
2496 ALOGE("%s: Compress voip output cannot be opened, error:%d",
2497 __func__, ret);
2498 goto error_open;
2499 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002500 } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
2501 if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version ||
2502 config->offload_info.size != AUDIO_INFO_INITIALIZER.size) {
2503 ALOGE("%s: Unsupported Offload information", __func__);
2504 ret = -EINVAL;
2505 goto error_open;
2506 }
Mingming Yin90310102013-11-13 16:57:00 -08002507 if (!is_supported_format(config->offload_info.format) &&
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08002508 !audio_extn_is_dolby_format(config->offload_info.format)) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002509 ALOGE("%s: Unsupported audio format", __func__);
2510 ret = -EINVAL;
2511 goto error_open;
2512 }
2513
2514 out->compr_config.codec = (struct snd_codec *)
2515 calloc(1, sizeof(struct snd_codec));
2516
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07002517 if (!out->compr_config.codec) {
2518 ret = -ENOMEM;
2519 goto error_open;
2520 }
2521
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002522 out->usecase = get_offload_usecase(adev);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002523 if (config->offload_info.channel_mask)
2524 out->channel_mask = config->offload_info.channel_mask;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002525 else if (config->channel_mask) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002526 out->channel_mask = config->channel_mask;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002527 config->offload_info.channel_mask = config->channel_mask;
2528 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002529 format = out->format = config->offload_info.format;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002530 out->sample_rate = config->offload_info.sample_rate;
2531
2532 out->stream.set_callback = out_set_callback;
2533 out->stream.pause = out_pause;
2534 out->stream.resume = out_resume;
2535 out->stream.drain = out_drain;
2536 out->stream.flush = out_flush;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002537 out->bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002538
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08002539 if (audio_extn_is_dolby_format(config->offload_info.format))
Mingming Yin90310102013-11-13 16:57:00 -08002540 out->compr_config.codec->id =
Subhash Chandra Bose Naripeddy7690c562013-12-14 00:34:53 -08002541 audio_extn_dolby_get_snd_codec_id(adev, out,
2542 config->offload_info.format);
Mingming Yin90310102013-11-13 16:57:00 -08002543 else
2544 out->compr_config.codec->id =
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002545 get_snd_codec_id(config->offload_info.format);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002546 if (audio_is_offload_pcm(config->offload_info.format)) {
2547 out->compr_config.fragment_size =
2548 platform_get_pcm_offload_buffer_size(&config->offload_info);
2549 } else {
2550 out->compr_config.fragment_size =
2551 platform_get_compress_offload_buffer_size(&config->offload_info);
2552 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002553 out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS;
2554 out->compr_config.codec->sample_rate =
2555 compress_get_alsa_rate(config->offload_info.sample_rate);
2556 out->compr_config.codec->bit_rate =
2557 config->offload_info.bit_rate;
2558 out->compr_config.codec->ch_in =
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002559 audio_channel_count_from_out_mask(config->channel_mask);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002560 out->compr_config.codec->ch_out = out->compr_config.codec->ch_in;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002561 out->bit_width = PCM_OUTPUT_BIT_WIDTH;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002562
Mingming Yin3ee55c62014-08-04 14:23:35 -07002563 if (config->offload_info.format == AUDIO_FORMAT_AAC)
2564 out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002565 if (config->offload_info.format == AUDIO_FORMAT_PCM_16_BIT_OFFLOAD)
2566 out->compr_config.codec->format = SNDRV_PCM_FORMAT_S16_LE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002567 if(config->offload_info.format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08002568 out->compr_config.codec->format = SNDRV_PCM_FORMAT_S24_LE;
2569
Mingming Yin3ee55c62014-08-04 14:23:35 -07002570 if (out->bit_width == 24) {
2571 out->compr_config.codec->format = SNDRV_PCM_FORMAT_S24_LE;
2572 }
2573
2574 if (out->bit_width == 24 && !platform_check_24_bit_support()) {
2575 ALOGW("24 bit support is not enabled, using 16 bit backend");
2576 out->compr_config.codec->format = SNDRV_PCM_FORMAT_S16_LE;
2577 }
2578
Amit Shekhar6f461b12014-08-01 14:52:58 -07002579 if (config->offload_info.format == AUDIO_FORMAT_FLAC)
Mingming Yinc9efb4f2014-09-19 12:16:36 -07002580 out->compr_config.codec->options.flac_dec.sample_size = PCM_OUTPUT_BIT_WIDTH;
Mingming Yin3ee55c62014-08-04 14:23:35 -07002581
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002582 if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
2583 out->non_blocking = 1;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07002584
2585 out->send_new_metadata = 1;
Haynes Mathew Georgeb9012ab2013-12-10 13:44:56 -08002586 out->offload_state = OFFLOAD_STATE_IDLE;
2587 out->playback_started = 0;
2588
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002589 create_offload_callback_thread(out);
2590 ALOGV("%s: offloaded output offload_info version %04x bit rate %d",
2591 __func__, config->offload_info.version,
2592 config->offload_info.bit_rate);
Krishnankutty Kolathappillyb165a8a2014-01-07 11:25:51 -08002593 //Decide if we need to use gapless mode by default
Krishnankutty Kolathappilly6d8788b2014-01-09 12:45:31 -08002594 check_and_set_gapless_mode(adev);
Krishnankutty Kolathappillyb165a8a2014-01-07 11:25:51 -08002595
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -07002596 } else if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) {
2597 ret = voice_check_and_set_incall_music_usecase(adev, out);
2598 if (ret != 0) {
2599 ALOGE("%s: Incall music delivery usecase cannot be set error:%d",
2600 __func__, ret);
2601 goto error_open;
2602 }
Ravi Kumar Alamanda8f715d92013-11-01 20:37:38 -07002603 } else if (out->flags & AUDIO_OUTPUT_FLAG_FAST) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002604 format = AUDIO_FORMAT_PCM_16_BIT;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002605 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
2606 out->config = pcm_config_low_latency;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002607 out->sample_rate = out->config.rate;
Ravi Kumar Alamanda8f715d92013-11-01 20:37:38 -07002608 } else {
Haynes Mathew Georgebf143712013-12-03 13:02:53 -08002609 /* primary path is the default path selected if no other outputs are available/suitable */
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002610 format = AUDIO_FORMAT_PCM_16_BIT;
Haynes Mathew Georgebf143712013-12-03 13:02:53 -08002611 out->usecase = USECASE_AUDIO_PLAYBACK_PRIMARY;
Ravi Kumar Alamanda8f715d92013-11-01 20:37:38 -07002612 out->config = pcm_config_deep_buffer;
2613 out->sample_rate = out->config.rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002614 }
2615
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +05302616 if ((24 == out->bit_width) &&
2617 (devices == AUDIO_DEVICE_OUT_SPEAKER)) {
2618 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
2619 ALOGI("%s 24-bit playback on Speaker is allowed ONLY at 48khz. Hence changing sample rate to: %d",
2620 __func__, sample_rate);
2621 } else {
2622 sample_rate = out->sample_rate;
2623 }
2624
2625 ALOGV("%s flags %x, format %x, sample_rate %d, out->bit_width %d",
2626 __func__, flags, format, sample_rate, out->bit_width);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07002627 audio_extn_utils_update_stream_app_type_cfg(adev->platform,
2628 &adev->streams_output_cfg_list,
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +05302629 flags, format, sample_rate,
Amit Shekhar6f461b12014-08-01 14:52:58 -07002630 out->bit_width, &out->app_type_cfg);
Haynes Mathew Georgebf143712013-12-03 13:02:53 -08002631 if ((out->usecase == USECASE_AUDIO_PLAYBACK_PRIMARY) ||
2632 (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) {
2633 /* Ensure the default output is not selected twice */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002634 if(adev->primary_output == NULL)
2635 adev->primary_output = out;
2636 else {
2637 ALOGE("%s: Primary output is already opened", __func__);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002638 ret = -EEXIST;
2639 goto error_open;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002640 }
2641 }
2642
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002643 /* Check if this usecase is already existing */
2644 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella7ce05352014-04-17 20:00:41 -07002645 if ((get_usecase_from_list(adev, out->usecase) != NULL) &&
2646 (out->usecase != USECASE_COMPRESS_VOIP_CALL)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002647 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002648 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002649 ret = -EEXIST;
2650 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002651 }
2652 pthread_mutex_unlock(&adev->lock);
2653
2654 out->stream.common.get_sample_rate = out_get_sample_rate;
2655 out->stream.common.set_sample_rate = out_set_sample_rate;
2656 out->stream.common.get_buffer_size = out_get_buffer_size;
2657 out->stream.common.get_channels = out_get_channels;
2658 out->stream.common.get_format = out_get_format;
2659 out->stream.common.set_format = out_set_format;
2660 out->stream.common.standby = out_standby;
2661 out->stream.common.dump = out_dump;
2662 out->stream.common.set_parameters = out_set_parameters;
2663 out->stream.common.get_parameters = out_get_parameters;
2664 out->stream.common.add_audio_effect = out_add_audio_effect;
2665 out->stream.common.remove_audio_effect = out_remove_audio_effect;
2666 out->stream.get_latency = out_get_latency;
2667 out->stream.set_volume = out_set_volume;
2668 out->stream.write = out_write;
2669 out->stream.get_render_position = out_get_render_position;
2670 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07002671 out->stream.get_presentation_position = out_get_presentation_position;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002672
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002673 out->standby = 1;
Eric Laurenta9024de2013-04-04 09:19:12 -07002674 /* out->muted = false; by calloc() */
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07002675 /* out->written = 0; by calloc() */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002676
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002677 pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL);
2678 pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL);
2679
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002680 config->format = out->stream.common.get_format(&out->stream.common);
2681 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
2682 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
2683
2684 *stream_out = &out->stream;
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302685 ALOGD("%s: Stream (%p) picks up usecase (%s)", __func__, &out->stream,
2686 use_case_table[out->usecase]);
Eric Laurent994a6932013-07-17 11:51:42 -07002687 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002688 return 0;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002689
2690error_open:
2691 free(out);
2692 *stream_out = NULL;
2693 ALOGD("%s: exit: ret %d", __func__, ret);
2694 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002695}
2696
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002697static void adev_close_output_stream(struct audio_hw_device *dev __unused,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002698 struct audio_stream_out *stream)
2699{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002700 struct stream_out *out = (struct stream_out *)stream;
2701 struct audio_device *adev = out->dev;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002702 int ret = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002703
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302704 ALOGD("%s: enter:stream_handle(%p)",__func__, out);
2705
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002706 if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05302707 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002708 ret = voice_extn_compress_voip_close_output_stream(&stream->common);
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05302709 pthread_mutex_unlock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002710 if(ret != 0)
2711 ALOGE("%s: Compress voip output cannot be closed, error:%d",
2712 __func__, ret);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002713 } else
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002714 out_standby(&stream->common);
2715
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002716 if (is_offload_usecase(out->usecase)) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002717 destroy_offload_callback_thread(out);
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07002718 free_offload_usecase(adev, out->usecase);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002719 if (out->compr_config.codec != NULL)
2720 free(out->compr_config.codec);
2721 }
2722 pthread_cond_destroy(&out->cond);
2723 pthread_mutex_destroy(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002724 free(stream);
Eric Laurent994a6932013-07-17 11:51:42 -07002725 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002726}
2727
2728static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
2729{
2730 struct audio_device *adev = (struct audio_device *)dev;
2731 struct str_parms *parms;
2732 char *str;
2733 char value[32];
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002734 int val;
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002735 int ret;
2736 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002737
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002738 ALOGD("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002739 parms = str_parms_create_str(kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002740
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002741 ret = str_parms_get_str(parms, "SND_CARD_STATUS", value, sizeof(value));
2742 if (ret >= 0) {
Naresh Tanniru4c630392014-05-12 01:05:52 +05302743 char *snd_card_status = value+2;
Naresh Tanniru4c630392014-05-12 01:05:52 +05302744 if (strstr(snd_card_status, "OFFLINE")) {
Naresh Tanniru80659832014-06-04 18:17:56 +05302745 struct listnode *node;
2746 struct audio_usecase *usecase;
2747
Naresh Tanniru4c630392014-05-12 01:05:52 +05302748 ALOGD("Received sound card OFFLINE status");
Naresh Tanniru80659832014-06-04 18:17:56 +05302749 set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
2750
2751 pthread_mutex_lock(&adev->lock);
2752 //close compress session on OFFLINE status
2753 usecase = get_usecase_from_list(adev,USECASE_AUDIO_PLAYBACK_OFFLOAD);
2754 if (usecase && usecase->stream.out) {
2755 ALOGD(" %s closing compress session on OFFLINE state", __func__);
2756
2757 struct stream_out *out = usecase->stream.out;
2758
2759 pthread_mutex_unlock(&adev->lock);
2760 out_standby(&out->stream.common);
2761 } else
2762 pthread_mutex_unlock(&adev->lock);
Naresh Tanniru4c630392014-05-12 01:05:52 +05302763 } else if (strstr(snd_card_status, "ONLINE")) {
2764 ALOGD("Received sound card ONLINE status");
Naresh Tanniru80659832014-06-04 18:17:56 +05302765 set_snd_card_state(adev,SND_CARD_STATE_ONLINE);
Naresh Tanniru4c630392014-05-12 01:05:52 +05302766 }
Naresh Tanniru4c630392014-05-12 01:05:52 +05302767 }
2768
2769 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002770 status = voice_set_parameters(adev, parms);
2771 if (status != 0)
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002772 goto done;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002773
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002774 status = platform_set_parameters(adev->platform, parms);
2775 if (status != 0)
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002776 goto done;
2777
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002778 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
2779 if (ret >= 0) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002780 /* When set to false, HAL should disable EC and NS */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002781 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
2782 adev->bluetooth_nrec = true;
2783 else
2784 adev->bluetooth_nrec = false;
2785 }
2786
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002787 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
2788 if (ret >= 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002789 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
2790 adev->screen_off = false;
2791 else
2792 adev->screen_off = true;
2793 }
2794
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002795 ret = str_parms_get_int(parms, "rotation", &val);
2796 if (ret >= 0) {
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002797 bool reverse_speakers = false;
2798 switch(val) {
2799 // FIXME: note that the code below assumes that the speakers are in the correct placement
2800 // relative to the user when the device is rotated 90deg from its default rotation. This
2801 // assumption is device-specific, not platform-specific like this code.
2802 case 270:
2803 reverse_speakers = true;
2804 break;
2805 case 0:
2806 case 90:
2807 case 180:
2808 break;
2809 default:
2810 ALOGE("%s: unexpected rotation of %d", __func__, val);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002811 status = -EINVAL;
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002812 }
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002813 if (status == 0) {
2814 if (adev->speaker_lr_swap != reverse_speakers) {
2815 adev->speaker_lr_swap = reverse_speakers;
2816 // only update the selected device if there is active pcm playback
2817 struct audio_usecase *usecase;
2818 struct listnode *node;
2819 list_for_each(node, &adev->usecase_list) {
2820 usecase = node_to_item(node, struct audio_usecase, list);
2821 if (usecase->type == PCM_PLAYBACK) {
2822 select_devices(adev, usecase->id);
2823 break;
2824 }
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002825 }
2826 }
2827 }
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002828 }
2829
Mingming Yin514a8bc2014-07-29 15:22:21 -07002830 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_SCO_WB, value, sizeof(value));
2831 if (ret >= 0) {
2832 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
2833 adev->bt_wb_speech_enabled = true;
2834 else
2835 adev->bt_wb_speech_enabled = false;
2836 }
2837
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002838 audio_extn_set_parameters(adev, parms);
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002839
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002840done:
2841 str_parms_destroy(parms);
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002842 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002843 ALOGV("%s: exit with code(%d)", __func__, status);
2844 return status;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002845}
2846
2847static char* adev_get_parameters(const struct audio_hw_device *dev,
2848 const char *keys)
2849{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002850 struct audio_device *adev = (struct audio_device *)dev;
2851 struct str_parms *reply = str_parms_create();
2852 struct str_parms *query = str_parms_create_str(keys);
2853 char *str;
Naresh Tannirud7205b62014-06-20 02:54:48 +05302854 char value[256] = {0};
2855 int ret = 0;
2856
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07002857 if (!query || !reply) {
2858 ALOGE("adev_get_parameters: failed to create query or reply");
2859 return NULL;
2860 }
2861
Naresh Tannirud7205b62014-06-20 02:54:48 +05302862 ret = str_parms_get_str(query, "SND_CARD_STATUS", value,
2863 sizeof(value));
2864 if (ret >=0) {
2865 int val = 1;
2866 pthread_mutex_lock(&adev->snd_card_status.lock);
2867 if (SND_CARD_STATE_OFFLINE == adev->snd_card_status.state)
2868 val = 0;
2869 pthread_mutex_unlock(&adev->snd_card_status.lock);
2870 str_parms_add_int(reply, "SND_CARD_STATUS", val);
2871 goto exit;
2872 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002873
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002874 pthread_mutex_lock(&adev->lock);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002875 audio_extn_get_parameters(adev, query, reply);
Shiv Maliyappanahallif9308492013-12-12 12:18:09 -08002876 voice_get_parameters(adev, query, reply);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002877 platform_get_parameters(adev->platform, query, reply);
Naresh Tanniru80659832014-06-04 18:17:56 +05302878 pthread_mutex_unlock(&adev->lock);
2879
Naresh Tannirud7205b62014-06-20 02:54:48 +05302880exit:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002881 str = str_parms_to_str(reply);
2882 str_parms_destroy(query);
2883 str_parms_destroy(reply);
2884
2885 ALOGV("%s: exit: returns - %s", __func__, str);
2886 return str;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002887}
2888
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002889static int adev_init_check(const struct audio_hw_device *dev __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002890{
2891 return 0;
2892}
2893
2894static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
2895{
Haynes Mathew George5191a852013-09-11 14:19:36 -07002896 int ret;
2897 struct audio_device *adev = (struct audio_device *)dev;
2898 pthread_mutex_lock(&adev->lock);
2899 /* cache volume */
Shruthi Krishnaace10852013-10-25 14:32:12 -07002900 ret = voice_set_volume(adev, volume);
Haynes Mathew George5191a852013-09-11 14:19:36 -07002901 pthread_mutex_unlock(&adev->lock);
2902 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002903}
2904
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002905static int adev_set_master_volume(struct audio_hw_device *dev __unused,
2906 float volume __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002907{
2908 return -ENOSYS;
2909}
2910
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002911static int adev_get_master_volume(struct audio_hw_device *dev __unused,
2912 float *volume __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002913{
2914 return -ENOSYS;
2915}
2916
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002917static int adev_set_master_mute(struct audio_hw_device *dev __unused,
2918 bool muted __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002919{
2920 return -ENOSYS;
2921}
2922
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002923static int adev_get_master_mute(struct audio_hw_device *dev __unused,
2924 bool *muted __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002925{
2926 return -ENOSYS;
2927}
2928
2929static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
2930{
2931 struct audio_device *adev = (struct audio_device *)dev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002932 pthread_mutex_lock(&adev->lock);
2933 if (adev->mode != mode) {
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -07002934 ALOGD("%s mode %d\n", __func__, mode);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002935 adev->mode = mode;
2936 }
2937 pthread_mutex_unlock(&adev->lock);
2938 return 0;
2939}
2940
2941static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
2942{
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002943 int ret;
2944
2945 pthread_mutex_lock(&adev->lock);
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002946 ALOGD("%s state %d\n", __func__, state);
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002947 ret = voice_set_mic_mute((struct audio_device *)dev, state);
2948 pthread_mutex_unlock(&adev->lock);
2949
2950 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002951}
2952
2953static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
2954{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002955 *state = voice_get_mic_mute((struct audio_device *)dev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002956 return 0;
2957}
2958
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002959static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev __unused,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002960 const struct audio_config *config)
2961{
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002962 int channel_count = audio_channel_count_from_in_mask(config->channel_mask);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002963
2964 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
2965}
2966
2967static int adev_open_input_stream(struct audio_hw_device *dev,
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002968 audio_io_handle_t handle __unused,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002969 audio_devices_t devices,
2970 struct audio_config *config,
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002971 struct audio_stream_in **stream_in,
2972 audio_input_flags_t flags __unused,
2973 const char *address __unused,
2974 audio_source_t source __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002975{
2976 struct audio_device *adev = (struct audio_device *)dev;
2977 struct stream_in *in;
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08002978 int ret = 0, buffer_size, frame_size;
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07002979 int channel_count = audio_channel_count_from_in_mask(config->channel_mask);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002980
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302981
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002982 *stream_in = NULL;
2983 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
2984 return -EINVAL;
2985
2986 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07002987
2988 if (!in) {
2989 ALOGE("failed to allocate input stream");
2990 return -ENOMEM;
2991 }
2992
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05302993 ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x)\
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07002994 stream_handle(%p) io_handle(%d)",__func__, config->sample_rate, config->channel_mask,
2995 devices, &in->stream, handle);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002996
Ravi Kumar Alamanda40703102014-04-24 10:34:41 -07002997 pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
2998
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002999 in->stream.common.get_sample_rate = in_get_sample_rate;
3000 in->stream.common.set_sample_rate = in_set_sample_rate;
3001 in->stream.common.get_buffer_size = in_get_buffer_size;
3002 in->stream.common.get_channels = in_get_channels;
3003 in->stream.common.get_format = in_get_format;
3004 in->stream.common.set_format = in_set_format;
3005 in->stream.common.standby = in_standby;
3006 in->stream.common.dump = in_dump;
3007 in->stream.common.set_parameters = in_set_parameters;
3008 in->stream.common.get_parameters = in_get_parameters;
3009 in->stream.common.add_audio_effect = in_add_audio_effect;
3010 in->stream.common.remove_audio_effect = in_remove_audio_effect;
3011 in->stream.set_gain = in_set_gain;
3012 in->stream.read = in_read;
3013 in->stream.get_input_frames_lost = in_get_input_frames_lost;
3014
3015 in->device = devices;
3016 in->source = AUDIO_SOURCE_DEFAULT;
3017 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003018 in->standby = 1;
3019 in->channel_mask = config->channel_mask;
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003020 in->capture_handle = handle;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003021
3022 /* Update config params with the requested sample rate and channels */
3023 in->usecase = USECASE_AUDIO_RECORD;
3024 in->config = pcm_config_audio_capture;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003025 in->config.rate = config->sample_rate;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08003026 in->format = config->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003027
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08003028 if (channel_count == 6) {
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08003029 if(audio_extn_ssr_get_enabled()) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07003030 if(audio_extn_ssr_init(in)) {
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08003031 ALOGE("%s: audio_extn_ssr_init failed", __func__);
3032 ret = -EINVAL;
3033 goto err_open;
3034 }
3035 } else {
Mingming Yin3cf99da2014-09-16 17:41:33 -07003036 ALOGW("%s: surround sound recording is not supported", __func__);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08003037 }
Mingming Yine62d7842013-10-25 16:26:03 -07003038 } else if (audio_extn_compr_cap_enabled() &&
Narsinga Rao Chella2a99dea2014-01-24 15:33:23 -08003039 audio_extn_compr_cap_format_supported(config->format) &&
3040 (in->dev->mode != AUDIO_MODE_IN_COMMUNICATION)) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07003041 audio_extn_compr_cap_init(in);
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003042 } else {
3043 in->config.channels = channel_count;
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07003044 frame_size = audio_stream_in_frame_size(&in->stream);
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003045 buffer_size = get_input_buffer_size(config->sample_rate,
3046 config->format,
3047 channel_count);
3048 in->config.period_size = buffer_size / frame_size;
3049 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003050
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003051 /* This stream could be for sound trigger lab,
3052 get sound trigger pcm if present */
3053 audio_extn_sound_trigger_check_and_get_session(in);
3054
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003055 *stream_in = &in->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07003056 ALOGV("%s: exit", __func__);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08003057 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003058
3059err_open:
3060 free(in);
3061 *stream_in = NULL;
3062 return ret;
3063}
3064
3065static void adev_close_input_stream(struct audio_hw_device *dev,
3066 struct audio_stream_in *stream)
3067{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08003068 int ret;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003069 struct stream_in *in = (struct stream_in *)stream;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07003070 struct audio_device *adev = (struct audio_device *)dev;
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05303071
Sidipotu Ashokf43018c2014-05-02 16:21:50 +05303072 ALOGD("%s: enter:stream_handle(%p)",__func__, in);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08003073
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05303074 /* Disable echo reference while closing input stream */
3075 platform_set_echo_reference(adev->platform, false);
3076
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08003077 if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05303078 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08003079 ret = voice_extn_compress_voip_close_input_stream(&stream->common);
Venkata Narendra Kumar Gutta91812142014-08-11 18:20:49 +05303080 pthread_mutex_unlock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08003081 if (ret != 0)
3082 ALOGE("%s: Compress voip input cannot be closed, error:%d",
3083 __func__, ret);
3084 } else
3085 in_standby(&stream->common);
3086
Ravi Kumar Alamandac3bc0812014-09-08 15:34:32 -07003087 if (audio_extn_ssr_get_enabled() &&
3088 (audio_channel_count_from_in_mask(in->channel_mask) == 6)) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07003089 audio_extn_ssr_deinit();
3090 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003091
Mingming Yine62d7842013-10-25 16:26:03 -07003092 if(audio_extn_compr_cap_enabled() &&
3093 audio_extn_compr_cap_format_supported(in->config.format))
3094 audio_extn_compr_cap_deinit();
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003095
3096 free(stream);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003097 return;
3098}
3099
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07003100static int adev_dump(const audio_hw_device_t *device __unused,
3101 int fd __unused)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003102{
3103 return 0;
3104}
3105
3106static int adev_close(hw_device_t *device)
3107{
3108 struct audio_device *adev = (struct audio_device *)device;
Kiran Kandi910e1862013-10-29 13:29:42 -07003109
3110 if (!adev)
3111 return 0;
3112
3113 pthread_mutex_lock(&adev_init_lock);
3114
3115 if ((--audio_device_ref_count) == 0) {
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003116 audio_extn_sound_trigger_deinit(adev);
Kiran Kandide144c82013-11-20 15:58:32 -08003117 audio_extn_listen_deinit(adev);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07003118 audio_extn_utils_release_streams_output_cfg_list(&adev->streams_output_cfg_list);
Kiran Kandi910e1862013-10-29 13:29:42 -07003119 audio_route_free(adev->audio_route);
3120 free(adev->snd_dev_ref_cnt);
3121 platform_deinit(adev->platform);
Kiran Kandi910e1862013-10-29 13:29:42 -07003122 free(device);
3123 adev = NULL;
3124 }
3125 pthread_mutex_unlock(&adev_init_lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003126 return 0;
3127}
3128
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003129static int adev_open(const hw_module_t *module, const char *name,
3130 hw_device_t **device)
3131{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07003132 int i, ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003133
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08003134 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003135 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
3136
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07003137 pthread_mutex_lock(&adev_init_lock);
Kiran Kandi910e1862013-10-29 13:29:42 -07003138 if (audio_device_ref_count != 0){
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07003139 *device = &adev->device.common;
Kiran Kandi910e1862013-10-29 13:29:42 -07003140 audio_device_ref_count++;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07003141 ALOGD("%s: returning existing instance of adev", __func__);
3142 ALOGD("%s: exit", __func__);
3143 pthread_mutex_unlock(&adev_init_lock);
3144 return 0;
3145 }
3146
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003147 adev = calloc(1, sizeof(struct audio_device));
3148
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07003149 if (!adev) {
3150 pthread_mutex_unlock(&adev_init_lock);
3151 return -ENOMEM;
3152 }
3153
Ravi Kumar Alamanda40703102014-04-24 10:34:41 -07003154 pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL);
3155
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003156 adev->device.common.tag = HARDWARE_DEVICE_TAG;
3157 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
3158 adev->device.common.module = (struct hw_module_t *)module;
3159 adev->device.common.close = adev_close;
3160
3161 adev->device.init_check = adev_init_check;
3162 adev->device.set_voice_volume = adev_set_voice_volume;
3163 adev->device.set_master_volume = adev_set_master_volume;
3164 adev->device.get_master_volume = adev_get_master_volume;
3165 adev->device.set_master_mute = adev_set_master_mute;
3166 adev->device.get_master_mute = adev_get_master_mute;
3167 adev->device.set_mode = adev_set_mode;
3168 adev->device.set_mic_mute = adev_set_mic_mute;
3169 adev->device.get_mic_mute = adev_get_mic_mute;
3170 adev->device.set_parameters = adev_set_parameters;
3171 adev->device.get_parameters = adev_get_parameters;
3172 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
3173 adev->device.open_output_stream = adev_open_output_stream;
3174 adev->device.close_output_stream = adev_close_output_stream;
3175 adev->device.open_input_stream = adev_open_input_stream;
3176 adev->device.close_input_stream = adev_close_input_stream;
3177 adev->device.dump = adev_dump;
3178
3179 /* Set the default route before the PCM stream is opened */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003180 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08003181 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08003182 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003183 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003184 adev->bluetooth_nrec = true;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08003185 adev->acdb_settings = TTY_MODE_OFF;
Eric Laurent07eeafd2013-10-06 12:52:49 -07003186 /* adev->cur_hdmi_channels = 0; by calloc() */
Mingming Yin3ee55c62014-08-04 14:23:35 -07003187 adev->cur_codec_backend_samplerate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3188 adev->cur_codec_backend_bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Eric Laurentb23d5282013-05-14 15:27:20 -07003189 adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003190 voice_init(adev);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08003191 list_init(&adev->usecase_list);
Krishnankutty Kolathappilly0b2de1c2014-02-14 14:45:49 -08003192 adev->cur_wfd_channels = 2;
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -07003193 adev->offload_usecases_state = 0;
Naresh Tanniru4c630392014-05-12 01:05:52 +05303194
3195 pthread_mutex_init(&adev->snd_card_status.lock, (const pthread_mutexattr_t *) NULL);
3196 adev->snd_card_status.state = SND_CARD_STATE_OFFLINE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003197 /* Loads platform specific libraries dynamically */
Eric Laurentb23d5282013-05-14 15:27:20 -07003198 adev->platform = platform_init(adev);
3199 if (!adev->platform) {
3200 free(adev->snd_dev_ref_cnt);
3201 free(adev);
3202 ALOGE("%s: Failed to init platform data, aborting.", __func__);
3203 *device = NULL;
Apoorv Raghuvanshi6e57d7e2013-12-16 16:02:45 -08003204 pthread_mutex_unlock(&adev_init_lock);
Eric Laurentb23d5282013-05-14 15:27:20 -07003205 return -EINVAL;
3206 }
Eric Laurentc4aef752013-09-12 17:45:53 -07003207
Naresh Tanniru4c630392014-05-12 01:05:52 +05303208 adev->snd_card_status.state = SND_CARD_STATE_ONLINE;
3209
Eric Laurentc4aef752013-09-12 17:45:53 -07003210 if (access(VISUALIZER_LIBRARY_PATH, R_OK) == 0) {
3211 adev->visualizer_lib = dlopen(VISUALIZER_LIBRARY_PATH, RTLD_NOW);
3212 if (adev->visualizer_lib == NULL) {
3213 ALOGE("%s: DLOPEN failed for %s", __func__, VISUALIZER_LIBRARY_PATH);
3214 } else {
3215 ALOGV("%s: DLOPEN successful for %s", __func__, VISUALIZER_LIBRARY_PATH);
3216 adev->visualizer_start_output =
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08003217 (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib,
Eric Laurentc4aef752013-09-12 17:45:53 -07003218 "visualizer_hal_start_output");
3219 adev->visualizer_stop_output =
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08003220 (int (*)(audio_io_handle_t, int))dlsym(adev->visualizer_lib,
Eric Laurentc4aef752013-09-12 17:45:53 -07003221 "visualizer_hal_stop_output");
3222 }
3223 }
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08003224 audio_extn_listen_init(adev, adev->snd_card);
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003225 audio_extn_sound_trigger_init(adev);
Eric Laurentc4aef752013-09-12 17:45:53 -07003226
Subhash Chandra Bose Naripeddy1d089162013-11-13 13:31:50 -08003227 if (access(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, R_OK) == 0) {
3228 adev->offload_effects_lib = dlopen(OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH, RTLD_NOW);
3229 if (adev->offload_effects_lib == NULL) {
3230 ALOGE("%s: DLOPEN failed for %s", __func__,
3231 OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH);
3232 } else {
3233 ALOGV("%s: DLOPEN successful for %s", __func__,
3234 OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH);
3235 adev->offload_effects_start_output =
3236 (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib,
3237 "offload_effects_bundle_hal_start_output");
3238 adev->offload_effects_stop_output =
3239 (int (*)(audio_io_handle_t, int))dlsym(adev->offload_effects_lib,
3240 "offload_effects_bundle_hal_stop_output");
3241 }
3242 }
3243
Mingming Yin514a8bc2014-07-29 15:22:21 -07003244 adev->bt_wb_speech_enabled = false;
3245
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003246 *device = &adev->device.common;
3247
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07003248 audio_extn_utils_update_streams_output_cfg_list(adev->platform, adev->mixer,
3249 &adev->streams_output_cfg_list);
3250
Kiran Kandi910e1862013-10-29 13:29:42 -07003251 audio_device_ref_count++;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07003252 pthread_mutex_unlock(&adev_init_lock);
3253
Eric Laurent994a6932013-07-17 11:51:42 -07003254 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003255 return 0;
3256}
3257
Mingming Yin07972cc2014-06-06 17:11:23 -07003258int pcm_ioctl(struct pcm *pcm, int request, ...)
3259{
3260 va_list ap;
3261 void * arg;
3262 int pcm_fd = *(int*)pcm;
3263
3264 va_start(ap, request);
3265 arg = va_arg(ap, void *);
3266 va_end(ap);
3267
3268 return ioctl(pcm_fd, request, arg);
3269}
3270
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003271static struct hw_module_methods_t hal_module_methods = {
3272 .open = adev_open,
3273};
3274
3275struct audio_module HAL_MODULE_INFO_SYM = {
3276 .common = {
3277 .tag = HARDWARE_MODULE_TAG,
3278 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
3279 .hal_api_version = HARDWARE_HAL_API_VERSION,
3280 .id = AUDIO_HARDWARE_MODULE_ID,
3281 .name = "QCOM Audio HAL",
Duy Truongfae19622013-11-24 02:17:54 -08003282 .author = "The Linux Foundation",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08003283 .methods = &hal_module_methods,
3284 },
3285};