blob: df040e20c6e2c45d0dcdf651af5f8dd7c3b53d48 [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08005 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
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"
56
57#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
58#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
Eric Laurentb23d5282013-05-14 15:27:20 -070063struct pcm_config pcm_config_deep_buffer = {
64 .channels = 2,
65 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
66 .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
67 .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
68 .format = PCM_FORMAT_S16_LE,
69 .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
70 .stop_threshold = INT_MAX,
71 .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
72};
73
74struct pcm_config pcm_config_low_latency = {
75 .channels = 2,
76 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
77 .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE,
78 .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT,
79 .format = PCM_FORMAT_S16_LE,
80 .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
81 .stop_threshold = INT_MAX,
82 .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
83};
84
85struct pcm_config pcm_config_hdmi_multi = {
86 .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */
87 .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */
88 .period_size = HDMI_MULTI_PERIOD_SIZE,
89 .period_count = HDMI_MULTI_PERIOD_COUNT,
90 .format = PCM_FORMAT_S16_LE,
91 .start_threshold = 0,
92 .stop_threshold = INT_MAX,
93 .avail_min = 0,
94};
95
96struct pcm_config pcm_config_audio_capture = {
97 .channels = 2,
Eric Laurentb23d5282013-05-14 15:27:20 -070098 .period_count = AUDIO_CAPTURE_PERIOD_COUNT,
99 .format = PCM_FORMAT_S16_LE,
100};
101
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -0800102const char * const use_case_table[AUDIO_USECASE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700103 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
104 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
105 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
Shruthi Krishnaace10852013-10-25 14:32:12 -0700106 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700107 [USECASE_AUDIO_RECORD] = "audio-record",
Mingming Yine62d7842013-10-25 16:26:03 -0700108 [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress",
Eric Laurentb23d5282013-05-14 15:27:20 -0700109 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700110 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700111 [USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700112 [USECASE_VOICE_CALL] = "voice-call",
Shruthi Krishnaace10852013-10-25 14:32:12 -0700113
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700114 [USECASE_VOICE2_CALL] = "voice2-call",
115 [USECASE_VOLTE_CALL] = "volte-call",
116 [USECASE_QCHAT_CALL] = "qchat-call",
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800117 [USECASE_COMPRESS_VOIP_CALL] = "compress-voip-call",
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700118 [USECASE_INCALL_REC_UPLINK] = "incall-rec-uplink",
119 [USECASE_INCALL_REC_DOWNLINK] = "incall-rec-downlink",
120 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = "incall-rec-uplink-and-downlink",
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700121 [USECASE_INCALL_MUSIC_UPLINK] = "incall_music_uplink",
122 [USECASE_INCALL_MUSIC_UPLINK2] = "incall_music_uplink2",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700123 [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib",
124 [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record",
Eric Laurentb23d5282013-05-14 15:27:20 -0700125};
126
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800127
128#define STRING_TO_ENUM(string) { #string, string }
129
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800130struct string_to_enum {
131 const char *name;
132 uint32_t value;
133};
134
135static const struct string_to_enum out_channels_name_to_enum_table[] = {
136 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
137 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
138 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
139};
140
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700141static struct audio_device *adev = NULL;
142static pthread_mutex_t adev_init_lock;
Kiran Kandi910e1862013-10-29 13:29:42 -0700143static unsigned int audio_device_ref_count;
144
Haynes Mathew George5191a852013-09-11 14:19:36 -0700145static int set_voice_volume_l(struct audio_device *adev, float volume);
146
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700147static bool is_supported_format(audio_format_t format)
148{
Eric Laurent86e17132013-09-12 17:49:30 -0700149 if (format == AUDIO_FORMAT_MP3 ||
150 format == AUDIO_FORMAT_AAC)
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700151 return true;
152
153 return false;
154}
155
156static int get_snd_codec_id(audio_format_t format)
157{
158 int id = 0;
159
160 switch (format) {
161 case AUDIO_FORMAT_MP3:
162 id = SND_AUDIOCODEC_MP3;
163 break;
164 case AUDIO_FORMAT_AAC:
165 id = SND_AUDIOCODEC_AAC;
166 break;
167 default:
168 ALOGE("%s: Unsupported audio format", __func__);
169 }
170
171 return id;
172}
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800173
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700174int enable_audio_route(struct audio_device *adev,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700175 struct audio_usecase *usecase,
176 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800177{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700178 snd_device_t snd_device;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700179 char mixer_path[MIXER_PATH_MAX_LENGTH];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800180
181 if (usecase == NULL)
182 return -EINVAL;
183
184 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
185
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800186 if (usecase->type == PCM_CAPTURE)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700187 snd_device = usecase->in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800188 else
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700189 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800190
191 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700192 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700193 ALOGV("%s: apply mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700194 audio_route_apply_path(adev->audio_route, mixer_path);
195 if (update_mixer)
196 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800197
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800198 ALOGV("%s: exit", __func__);
199 return 0;
200}
201
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700202int disable_audio_route(struct audio_device *adev,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700203 struct audio_usecase *usecase,
204 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800205{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700206 snd_device_t snd_device;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700207 char mixer_path[MIXER_PATH_MAX_LENGTH];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800208
209 if (usecase == NULL)
210 return -EINVAL;
211
212 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700213 if (usecase->type == PCM_CAPTURE)
214 snd_device = usecase->in_snd_device;
215 else
216 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800217 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700218 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700219 ALOGV("%s: reset mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700220 audio_route_reset_path(adev->audio_route, mixer_path);
221 if (update_mixer)
222 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800223
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800224 ALOGV("%s: exit", __func__);
225 return 0;
226}
227
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700228int enable_snd_device(struct audio_device *adev,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700229 snd_device_t snd_device,
230 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800231{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700232 char device_name[DEVICE_NAME_MAX_SIZE] = {0};
233
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800234 if (snd_device < SND_DEVICE_MIN ||
235 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800236 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800237 return -EINVAL;
238 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700239
240 adev->snd_dev_ref_cnt[snd_device]++;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700241
242 if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0 ) {
243 ALOGE("%s: Invalid sound device returned", __func__);
244 return -EINVAL;
245 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700246 if (adev->snd_dev_ref_cnt[snd_device] > 1) {
Eric Laurent994a6932013-07-17 11:51:42 -0700247 ALOGV("%s: snd_device(%d: %s) is already active",
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700248 __func__, snd_device, device_name);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700249 return 0;
250 }
251
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700252 /* start usb playback thread */
253 if(SND_DEVICE_OUT_USB_HEADSET == snd_device ||
254 SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device)
255 audio_extn_usb_start_playback(adev);
256
257 /* start usb capture thread */
258 if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
259 audio_extn_usb_start_capture(adev);
260
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700261 if (snd_device == SND_DEVICE_OUT_SPEAKER &&
262 audio_extn_spkr_prot_is_enabled()) {
263 if (audio_extn_spkr_prot_start_processing(snd_device)) {
264 ALOGE("%s: spkr_start_processing failed", __func__);
265 return -EINVAL;
266 }
267 } else {
268 ALOGV("%s: snd_device(%d: %s)", __func__,
269 snd_device, device_name);
270 if (platform_send_audio_calibration(adev->platform, snd_device) < 0) {
271 adev->snd_dev_ref_cnt[snd_device]--;
272 return -EINVAL;
273 }
Kiran Kandide144c82013-11-20 15:58:32 -0800274 audio_extn_listen_update_status(snd_device,
275 LISTEN_EVENT_SND_DEVICE_BUSY);
276
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700277 audio_route_apply_path(adev->audio_route, device_name);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800278 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700279 if (update_mixer)
280 audio_route_update_mixer(adev->audio_route);
281
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800282 return 0;
283}
284
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700285int disable_snd_device(struct audio_device *adev,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700286 snd_device_t snd_device,
287 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800288{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700289 char device_name[DEVICE_NAME_MAX_SIZE] = {0};
290
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800291 if (snd_device < SND_DEVICE_MIN ||
292 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800293 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800294 return -EINVAL;
295 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700296 if (adev->snd_dev_ref_cnt[snd_device] <= 0) {
297 ALOGE("%s: device ref cnt is already 0", __func__);
298 return -EINVAL;
299 }
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700300
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700301 adev->snd_dev_ref_cnt[snd_device]--;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700302
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700303 if(platform_get_snd_device_name_extn(adev->platform, snd_device, device_name) < 0) {
304 ALOGE("%s: Invalid sound device returned", __func__);
305 return -EINVAL;
306 }
307
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700308 if (adev->snd_dev_ref_cnt[snd_device] == 0) {
Eric Laurent994a6932013-07-17 11:51:42 -0700309 ALOGV("%s: snd_device(%d: %s)", __func__,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700310 snd_device, device_name);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -0800311 /* exit usb play back thread */
312 if(SND_DEVICE_OUT_USB_HEADSET == snd_device ||
313 SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device)
314 audio_extn_usb_stop_playback();
315
316 /* exit usb capture thread */
317 if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
318 audio_extn_usb_stop_capture(adev);
319
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700320 if (snd_device == SND_DEVICE_OUT_SPEAKER &&
321 audio_extn_spkr_prot_is_enabled()) {
322 audio_extn_spkr_prot_stop_processing();
323 } else
324 audio_route_reset_path(adev->audio_route, device_name);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -0800325
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700326 if (update_mixer)
327 audio_route_update_mixer(adev->audio_route);
Kiran Kandide144c82013-11-20 15:58:32 -0800328
329 audio_extn_listen_update_status(snd_device,
330 LISTEN_EVENT_SND_DEVICE_FREE);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700331 }
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700332
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800333 return 0;
334}
335
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700336static void check_usecases_codec_backend(struct audio_device *adev,
337 struct audio_usecase *uc_info,
338 snd_device_t snd_device)
339{
340 struct listnode *node;
341 struct audio_usecase *usecase;
342 bool switch_device[AUDIO_USECASE_MAX];
343 int i, num_uc_to_switch = 0;
344
345 /*
346 * This function is to make sure that all the usecases that are active on
347 * the hardware codec backend are always routed to any one device that is
348 * handled by the hardware codec.
349 * For example, if low-latency and deep-buffer usecases are currently active
350 * on speaker and out_set_parameters(headset) is received on low-latency
351 * output, then we have to make sure deep-buffer is also switched to headset,
352 * because of the limitation that both the devices cannot be enabled
353 * at the same time as they share the same backend.
354 */
355 /* Disable all the usecases on the shared backend other than the
356 specified usecase */
357 for (i = 0; i < AUDIO_USECASE_MAX; i++)
358 switch_device[i] = false;
359
360 list_for_each(node, &adev->usecase_list) {
361 usecase = node_to_item(node, struct audio_usecase, list);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700362 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700363 usecase != uc_info &&
364 usecase->out_snd_device != snd_device &&
365 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
366 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
367 __func__, use_case_table[usecase->id],
Eric Laurentb23d5282013-05-14 15:27:20 -0700368 platform_get_snd_device_name(usecase->out_snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700369 disable_audio_route(adev, usecase, false);
370 switch_device[usecase->id] = true;
371 num_uc_to_switch++;
372 }
373 }
374
375 if (num_uc_to_switch) {
376 /* Make sure all the streams are de-routed before disabling the device */
377 audio_route_update_mixer(adev->audio_route);
378
379 list_for_each(node, &adev->usecase_list) {
380 usecase = node_to_item(node, struct audio_usecase, list);
381 if (switch_device[usecase->id]) {
382 disable_snd_device(adev, usecase->out_snd_device, false);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700383 }
384 }
385
Krishnankutty Kolathappillydc4f7572013-11-01 20:07:13 -0700386 list_for_each(node, &adev->usecase_list) {
387 usecase = node_to_item(node, struct audio_usecase, list);
388 if (switch_device[usecase->id]) {
389 enable_snd_device(adev, snd_device, false);
390 }
391 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700392 /* Make sure new snd device is enabled before re-routing the streams */
393 audio_route_update_mixer(adev->audio_route);
394
395 /* Re-route all the usecases on the shared backend other than the
396 specified usecase to new snd devices */
397 list_for_each(node, &adev->usecase_list) {
398 usecase = node_to_item(node, struct audio_usecase, list);
399 /* Update the out_snd_device only before enabling the audio route */
400 if (switch_device[usecase->id] ) {
401 usecase->out_snd_device = snd_device;
402 enable_audio_route(adev, usecase, false);
403 }
404 }
405
406 audio_route_update_mixer(adev->audio_route);
407 }
408}
409
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700410static void check_and_route_capture_usecases(struct audio_device *adev,
411 struct audio_usecase *uc_info,
412 snd_device_t snd_device)
413{
414 struct listnode *node;
415 struct audio_usecase *usecase;
416 bool switch_device[AUDIO_USECASE_MAX];
417 int i, num_uc_to_switch = 0;
418
419 /*
420 * This function is to make sure that all the active capture usecases
421 * are always routed to the same input sound device.
422 * For example, if audio-record and voice-call usecases are currently
423 * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece)
424 * is received for voice call then we have to make sure that audio-record
425 * usecase is also switched to earpiece i.e. voice-dmic-ef,
426 * because of the limitation that two devices cannot be enabled
427 * at the same time if they share the same backend.
428 */
429 for (i = 0; i < AUDIO_USECASE_MAX; i++)
430 switch_device[i] = false;
431
432 list_for_each(node, &adev->usecase_list) {
433 usecase = node_to_item(node, struct audio_usecase, list);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700434 if (usecase->type == PCM_CAPTURE &&
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700435 usecase != uc_info &&
436 usecase->in_snd_device != snd_device) {
437 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
438 __func__, use_case_table[usecase->id],
Devin Kim1e5f3532013-08-09 07:48:29 -0700439 platform_get_snd_device_name(usecase->in_snd_device));
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700440 disable_audio_route(adev, usecase, false);
441 switch_device[usecase->id] = true;
442 num_uc_to_switch++;
443 }
444 }
445
446 if (num_uc_to_switch) {
447 /* Make sure all the streams are de-routed before disabling the device */
448 audio_route_update_mixer(adev->audio_route);
449
450 list_for_each(node, &adev->usecase_list) {
451 usecase = node_to_item(node, struct audio_usecase, list);
452 if (switch_device[usecase->id]) {
453 disable_snd_device(adev, usecase->in_snd_device, false);
454 enable_snd_device(adev, snd_device, false);
455 }
456 }
457
458 /* Make sure new snd device is enabled before re-routing the streams */
459 audio_route_update_mixer(adev->audio_route);
460
461 /* Re-route all the usecases on the shared backend other than the
462 specified usecase to new snd devices */
463 list_for_each(node, &adev->usecase_list) {
464 usecase = node_to_item(node, struct audio_usecase, list);
465 /* Update the in_snd_device only before enabling the audio route */
466 if (switch_device[usecase->id] ) {
467 usecase->in_snd_device = snd_device;
468 enable_audio_route(adev, usecase, false);
469 }
470 }
471
472 audio_route_update_mixer(adev->audio_route);
473 }
474}
475
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700476static int disable_all_usecases_of_type(struct audio_device *adev,
477 usecase_type_t usecase_type,
478 bool update_mixer)
479{
480 struct audio_usecase *usecase;
481 struct listnode *node;
482 int ret = 0;
483
484 list_for_each(node, &adev->usecase_list) {
485 usecase = node_to_item(node, struct audio_usecase, list);
486 if (usecase->type == usecase_type) {
487 ALOGV("%s: usecase id %d", __func__, usecase->id);
488 ret = disable_audio_route(adev, usecase, update_mixer);
489 if (ret) {
490 ALOGE("%s: Failed to disable usecase id %d",
491 __func__, usecase->id);
492 }
493 }
494 }
495
496 return ret;
497}
498
499static int enable_all_usecases_of_type(struct audio_device *adev,
500 usecase_type_t usecase_type,
501 bool update_mixer)
502{
503 struct audio_usecase *usecase;
504 struct listnode *node;
505 int ret = 0;
506
507 list_for_each(node, &adev->usecase_list) {
508 usecase = node_to_item(node, struct audio_usecase, list);
509 if (usecase->type == usecase_type) {
510 ALOGV("%s: usecase id %d", __func__, usecase->id);
511 ret = enable_audio_route(adev, usecase, update_mixer);
512 if (ret) {
513 ALOGE("%s: Failed to enable usecase id %d",
514 __func__, usecase->id);
515 }
516 }
517 }
518
519 return ret;
520}
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800521
522/* must be called with hw device mutex locked */
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700523static int read_hdmi_channel_masks(struct stream_out *out)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800524{
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700525 int ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700526 int channels = platform_edid_get_max_channels(out->dev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800527
528 switch (channels) {
529 /*
530 * Do not handle stereo output in Multi-channel cases
531 * Stereo case is handled in normal playback path
532 */
533 case 6:
534 ALOGV("%s: HDMI supports 5.1", __func__);
535 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
536 break;
537 case 8:
538 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
539 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
540 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
541 break;
542 default:
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700543 ALOGE("HDMI does not support multi channel playback");
544 ret = -ENOSYS;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800545 break;
546 }
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700547 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800548}
549
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700550static audio_usecase_t get_voice_usecase_id_from_list(struct audio_device *adev)
551{
552 struct audio_usecase *usecase;
553 struct listnode *node;
554
555 list_for_each(node, &adev->usecase_list) {
556 usecase = node_to_item(node, struct audio_usecase, list);
557 if (usecase->type == VOICE_CALL) {
558 ALOGV("%s: usecase id %d", __func__, usecase->id);
559 return usecase->id;
560 }
561 }
562 return USECASE_INVALID;
563}
564
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700565struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700566 audio_usecase_t uc_id)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700567{
568 struct audio_usecase *usecase;
569 struct listnode *node;
570
571 list_for_each(node, &adev->usecase_list) {
572 usecase = node_to_item(node, struct audio_usecase, list);
573 if (usecase->id == uc_id)
574 return usecase;
575 }
576 return NULL;
577}
578
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700579int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800580{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800581 snd_device_t out_snd_device = SND_DEVICE_NONE;
582 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700583 struct audio_usecase *usecase = NULL;
584 struct audio_usecase *vc_usecase = NULL;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800585 struct audio_usecase *voip_usecase = NULL;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800586 struct listnode *node;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700587 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800588
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700589 usecase = get_usecase_from_list(adev, uc_id);
590 if (usecase == NULL) {
591 ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
592 return -EINVAL;
593 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800594
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800595 if ((usecase->type == VOICE_CALL) ||
596 (usecase->type == VOIP_CALL)) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700597 out_snd_device = platform_get_output_snd_device(adev->platform,
598 usecase->stream.out->devices);
599 in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700600 usecase->devices = usecase->stream.out->devices;
601 } else {
602 /*
603 * If the voice call is active, use the sound devices of voice call usecase
604 * so that it would not result any device switch. All the usecases will
605 * be switched to new device when select_devices() is called for voice call
606 * usecase. This is to avoid switching devices for voice call when
607 * check_usecases_codec_backend() is called below.
608 */
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700609 if (voice_is_in_call(adev)) {
610 vc_usecase = get_usecase_from_list(adev,
611 get_voice_usecase_id_from_list(adev));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700612 if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
613 in_snd_device = vc_usecase->in_snd_device;
614 out_snd_device = vc_usecase->out_snd_device;
615 }
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800616 } else if (voice_extn_compress_voip_is_active(adev)) {
617 voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL);
618 if (voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
619 in_snd_device = voip_usecase->in_snd_device;
620 out_snd_device = voip_usecase->out_snd_device;
621 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700622 }
623 if (usecase->type == PCM_PLAYBACK) {
624 usecase->devices = usecase->stream.out->devices;
625 in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700626 if (out_snd_device == SND_DEVICE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700627 out_snd_device = platform_get_output_snd_device(adev->platform,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700628 usecase->stream.out->devices);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700629 if (usecase->stream.out == adev->primary_output &&
630 adev->active_input &&
631 adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
632 select_devices(adev, adev->active_input->usecase);
633 }
634 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700635 } else if (usecase->type == PCM_CAPTURE) {
636 usecase->devices = usecase->stream.in->device;
637 out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700638 if (in_snd_device == SND_DEVICE_NONE) {
639 if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
640 adev->primary_output && !adev->primary_output->standby) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700641 in_snd_device = platform_get_input_snd_device(adev->platform,
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700642 adev->primary_output->devices);
643 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700644 in_snd_device = platform_get_input_snd_device(adev->platform,
645 AUDIO_DEVICE_NONE);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700646 }
647 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700648 }
649 }
650
651 if (out_snd_device == usecase->out_snd_device &&
652 in_snd_device == usecase->in_snd_device) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800653 return 0;
654 }
655
sangwoobc677242013-08-08 16:53:43 +0900656 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700657 out_snd_device, platform_get_snd_device_name(out_snd_device),
658 in_snd_device, platform_get_snd_device_name(in_snd_device));
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800659
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800660 /*
661 * Limitation: While in call, to do a device switch we need to disable
662 * and enable both RX and TX devices though one of them is same as current
663 * device.
664 */
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800665 if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700666 status = platform_switch_voice_call_device_pre(adev->platform);
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800667 disable_all_usecases_of_type(adev, VOICE_CALL, true);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800668 }
669
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700670 /* Disable current sound devices */
671 if (usecase->out_snd_device != SND_DEVICE_NONE) {
672 disable_audio_route(adev, usecase, true);
673 disable_snd_device(adev, usecase->out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800674 }
675
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700676 if (usecase->in_snd_device != SND_DEVICE_NONE) {
677 disable_audio_route(adev, usecase, true);
678 disable_snd_device(adev, usecase->in_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800679 }
680
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700681 /* Enable new sound devices */
682 if (out_snd_device != SND_DEVICE_NONE) {
683 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
684 check_usecases_codec_backend(adev, usecase, out_snd_device);
685 enable_snd_device(adev, out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800686 }
687
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700688 if (in_snd_device != SND_DEVICE_NONE) {
689 check_and_route_capture_usecases(adev, usecase, in_snd_device);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700690 enable_snd_device(adev, in_snd_device, false);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700691 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700692
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800693 if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)
Eric Laurentb23d5282013-05-14 15:27:20 -0700694 status = platform_switch_voice_call_device_post(adev->platform,
695 out_snd_device,
696 in_snd_device);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800697
sangwoo170731f2013-06-08 15:36:36 +0900698 audio_route_update_mixer(adev->audio_route);
699
700 usecase->in_snd_device = in_snd_device;
701 usecase->out_snd_device = out_snd_device;
702
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800703 if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)
704 enable_all_usecases_of_type(adev, usecase->type, true);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700705 else
706 enable_audio_route(adev, usecase, true);
sangwoo170731f2013-06-08 15:36:36 +0900707
Vidyakumar Athota1fd21792013-11-15 14:50:57 -0800708 /* Applicable only on the targets that has external modem.
709 * Enable device command should be sent to modem only after
710 * enabling voice call mixer controls
711 */
712 if (usecase->type == VOICE_CALL)
713 status = platform_switch_voice_call_usecase_route_post(adev->platform,
714 out_snd_device,
715 in_snd_device);
716
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800717 return status;
718}
719
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800720static int stop_input_stream(struct stream_in *in)
721{
722 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800723 struct audio_usecase *uc_info;
724 struct audio_device *adev = in->dev;
725
Eric Laurentc8400632013-02-14 19:04:54 -0800726 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800727
Eric Laurent994a6932013-07-17 11:51:42 -0700728 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700729 in->usecase, use_case_table[in->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800730 uc_info = get_usecase_from_list(adev, in->usecase);
731 if (uc_info == NULL) {
732 ALOGE("%s: Could not find the usecase (%d) in the list",
733 __func__, in->usecase);
734 return -EINVAL;
735 }
736
Eric Laurent150dbfe2013-02-27 14:31:02 -0800737 /* 1. Disable stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700738 disable_audio_route(adev, uc_info, true);
739
740 /* 2. Disable the tx device */
741 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800742
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800743 list_remove(&uc_info->list);
744 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800745
Eric Laurent994a6932013-07-17 11:51:42 -0700746 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800747 return ret;
748}
749
750int start_input_stream(struct stream_in *in)
751{
752 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800753 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800754 struct audio_usecase *uc_info;
755 struct audio_device *adev = in->dev;
756
Mingming Yine62d7842013-10-25 16:26:03 -0700757 in->usecase = platform_update_usecase_from_source(in->source,in->usecase);
Eric Laurent994a6932013-07-17 11:51:42 -0700758 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700759
760 /* Check if source matches incall recording usecase criteria */
761 ret = voice_check_and_set_incall_rec_usecase(adev, in);
762 if (ret)
763 goto error_config;
764 else
765 ALOGV("%s: usecase(%d)", __func__, in->usecase);
766
Eric Laurentb23d5282013-05-14 15:27:20 -0700767 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800768 if (in->pcm_device_id < 0) {
769 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
770 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800771 ret = -EINVAL;
772 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800773 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700774
775 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800776 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
777 uc_info->id = in->usecase;
778 uc_info->type = PCM_CAPTURE;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800779 uc_info->stream.in = in;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700780 uc_info->devices = in->device;
781 uc_info->in_snd_device = SND_DEVICE_NONE;
782 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800783
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800784 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700785 select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800786
Eric Laurentc8400632013-02-14 19:04:54 -0800787 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
788 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800789 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
790 PCM_IN, &in->config);
791 if (in->pcm && !pcm_is_ready(in->pcm)) {
792 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
793 pcm_close(in->pcm);
794 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800795 ret = -EIO;
796 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800797 }
Eric Laurent994a6932013-07-17 11:51:42 -0700798 ALOGV("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800799 return ret;
800
801error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800802 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800803
804error_config:
805 adev->active_input = NULL;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700806 ALOGD("%s: exit: status(%d)", __func__, ret);
Eric Laurentc8400632013-02-14 19:04:54 -0800807
808 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800809}
810
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700811/* must be called with out->lock locked */
812static int send_offload_cmd_l(struct stream_out* out, int command)
813{
814 struct offload_cmd *cmd = (struct offload_cmd *)calloc(1, sizeof(struct offload_cmd));
815
816 ALOGVV("%s %d", __func__, command);
817
818 cmd->cmd = command;
819 list_add_tail(&out->offload_cmd_list, &cmd->node);
820 pthread_cond_signal(&out->offload_cond);
821 return 0;
822}
823
824/* must be called iwth out->lock locked */
825static void stop_compressed_output_l(struct stream_out *out)
826{
827 out->offload_state = OFFLOAD_STATE_IDLE;
828 out->playback_started = 0;
Haynes Mathew George352f27b2013-07-26 00:00:15 -0700829 out->send_new_metadata = 1;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700830 if (out->compr != NULL) {
831 compress_stop(out->compr);
832 while (out->offload_thread_blocked) {
833 pthread_cond_wait(&out->cond, &out->lock);
834 }
835 }
836}
837
838static void *offload_thread_loop(void *context)
839{
840 struct stream_out *out = (struct stream_out *) context;
841 struct listnode *item;
842
843 out->offload_state = OFFLOAD_STATE_IDLE;
844 out->playback_started = 0;
845
846 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
847 set_sched_policy(0, SP_FOREGROUND);
848 prctl(PR_SET_NAME, (unsigned long)"Offload Callback", 0, 0, 0);
849
850 ALOGV("%s", __func__);
851 pthread_mutex_lock(&out->lock);
852 for (;;) {
853 struct offload_cmd *cmd = NULL;
854 stream_callback_event_t event;
855 bool send_callback = false;
856
857 ALOGVV("%s offload_cmd_list %d out->offload_state %d",
858 __func__, list_empty(&out->offload_cmd_list),
859 out->offload_state);
860 if (list_empty(&out->offload_cmd_list)) {
861 ALOGV("%s SLEEPING", __func__);
862 pthread_cond_wait(&out->offload_cond, &out->lock);
863 ALOGV("%s RUNNING", __func__);
864 continue;
865 }
866
867 item = list_head(&out->offload_cmd_list);
868 cmd = node_to_item(item, struct offload_cmd, node);
869 list_remove(item);
870
871 ALOGVV("%s STATE %d CMD %d out->compr %p",
872 __func__, out->offload_state, cmd->cmd, out->compr);
873
874 if (cmd->cmd == OFFLOAD_CMD_EXIT) {
875 free(cmd);
876 break;
877 }
878
879 if (out->compr == NULL) {
880 ALOGE("%s: Compress handle is NULL", __func__);
881 pthread_cond_signal(&out->cond);
882 continue;
883 }
884 out->offload_thread_blocked = true;
885 pthread_mutex_unlock(&out->lock);
886 send_callback = false;
887 switch(cmd->cmd) {
888 case OFFLOAD_CMD_WAIT_FOR_BUFFER:
889 compress_wait(out->compr, -1);
890 send_callback = true;
891 event = STREAM_CBK_EVENT_WRITE_READY;
892 break;
893 case OFFLOAD_CMD_PARTIAL_DRAIN:
Haynes Mathew George352f27b2013-07-26 00:00:15 -0700894 compress_next_track(out->compr);
895 compress_partial_drain(out->compr);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700896 send_callback = true;
897 event = STREAM_CBK_EVENT_DRAIN_READY;
898 break;
899 case OFFLOAD_CMD_DRAIN:
900 compress_drain(out->compr);
901 send_callback = true;
902 event = STREAM_CBK_EVENT_DRAIN_READY;
903 break;
904 default:
905 ALOGE("%s unknown command received: %d", __func__, cmd->cmd);
906 break;
907 }
908 pthread_mutex_lock(&out->lock);
909 out->offload_thread_blocked = false;
910 pthread_cond_signal(&out->cond);
Eric Laurent6e895242013-09-05 16:10:57 -0700911 if (send_callback) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700912 out->offload_callback(event, NULL, out->offload_cookie);
Eric Laurent6e895242013-09-05 16:10:57 -0700913 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -0700914 free(cmd);
915 }
916
917 pthread_cond_signal(&out->cond);
918 while (!list_empty(&out->offload_cmd_list)) {
919 item = list_head(&out->offload_cmd_list);
920 list_remove(item);
921 free(node_to_item(item, struct offload_cmd, node));
922 }
923 pthread_mutex_unlock(&out->lock);
924
925 return NULL;
926}
927
928static int create_offload_callback_thread(struct stream_out *out)
929{
930 pthread_cond_init(&out->offload_cond, (const pthread_condattr_t *) NULL);
931 list_init(&out->offload_cmd_list);
932 pthread_create(&out->offload_thread, (const pthread_attr_t *) NULL,
933 offload_thread_loop, out);
934 return 0;
935}
936
937static int destroy_offload_callback_thread(struct stream_out *out)
938{
939 pthread_mutex_lock(&out->lock);
940 stop_compressed_output_l(out);
941 send_offload_cmd_l(out, OFFLOAD_CMD_EXIT);
942
943 pthread_mutex_unlock(&out->lock);
944 pthread_join(out->offload_thread, (void **) NULL);
945 pthread_cond_destroy(&out->offload_cond);
946
947 return 0;
948}
949
Eric Laurent07eeafd2013-10-06 12:52:49 -0700950static bool allow_hdmi_channel_config(struct audio_device *adev)
951{
952 struct listnode *node;
953 struct audio_usecase *usecase;
954 bool ret = true;
955
956 list_for_each(node, &adev->usecase_list) {
957 usecase = node_to_item(node, struct audio_usecase, list);
958 if (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
959 /*
960 * If voice call is already existing, do not proceed further to avoid
961 * disabling/enabling both RX and TX devices, CSD calls, etc.
962 * Once the voice call done, the HDMI channels can be configured to
963 * max channels of remaining use cases.
964 */
965 if (usecase->id == USECASE_VOICE_CALL) {
966 ALOGD("%s: voice call is active, no change in HDMI channels",
967 __func__);
968 ret = false;
969 break;
970 } else if (usecase->id == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
971 ALOGD("%s: multi channel playback is active, "
972 "no change in HDMI channels", __func__);
973 ret = false;
974 break;
975 }
976 }
977 }
978 return ret;
979}
980
981static int check_and_set_hdmi_channels(struct audio_device *adev,
982 unsigned int channels)
983{
984 struct listnode *node;
985 struct audio_usecase *usecase;
986
987 /* Check if change in HDMI channel config is allowed */
988 if (!allow_hdmi_channel_config(adev))
989 return 0;
990
991 if (channels == adev->cur_hdmi_channels) {
992 ALOGD("%s: Requested channels are same as current", __func__);
993 return 0;
994 }
995
996 platform_set_hdmi_channels(adev->platform, channels);
997 adev->cur_hdmi_channels = channels;
998
999 /*
1000 * Deroute all the playback streams routed to HDMI so that
1001 * the back end is deactivated. Note that backend will not
1002 * be deactivated if any one stream is connected to it.
1003 */
1004 list_for_each(node, &adev->usecase_list) {
1005 usecase = node_to_item(node, struct audio_usecase, list);
1006 if (usecase->type == PCM_PLAYBACK &&
1007 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1008 disable_audio_route(adev, usecase, true);
1009 }
1010 }
1011
1012 /*
1013 * Enable all the streams disabled above. Now the HDMI backend
1014 * will be activated with new channel configuration
1015 */
1016 list_for_each(node, &adev->usecase_list) {
1017 usecase = node_to_item(node, struct audio_usecase, list);
1018 if (usecase->type == PCM_PLAYBACK &&
1019 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1020 enable_audio_route(adev, usecase, true);
1021 }
1022 }
1023
1024 return 0;
1025}
1026
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001027static int stop_output_stream(struct stream_out *out)
1028{
1029 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001030 struct audio_usecase *uc_info;
1031 struct audio_device *adev = out->dev;
1032
Eric Laurent994a6932013-07-17 11:51:42 -07001033 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001034 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001035 uc_info = get_usecase_from_list(adev, out->usecase);
1036 if (uc_info == NULL) {
1037 ALOGE("%s: Could not find the usecase (%d) in the list",
1038 __func__, out->usecase);
1039 return -EINVAL;
1040 }
1041
Eric Laurentc4aef752013-09-12 17:45:53 -07001042 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD &&
1043 adev->visualizer_stop_output != NULL)
1044 adev->visualizer_stop_output(out->handle);
1045
Eric Laurent150dbfe2013-02-27 14:31:02 -08001046 /* 1. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001047 disable_audio_route(adev, uc_info, true);
1048
1049 /* 2. Disable the rx device */
1050 disable_snd_device(adev, uc_info->out_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001051
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001052 list_remove(&uc_info->list);
1053 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001054
Eric Laurent07eeafd2013-10-06 12:52:49 -07001055 /* Must be called after removing the usecase from list */
1056 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
1057 check_and_set_hdmi_channels(adev, DEFAULT_HDMI_OUT_CHANNELS);
1058
Eric Laurent994a6932013-07-17 11:51:42 -07001059 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001060 return ret;
1061}
1062
1063int start_output_stream(struct stream_out *out)
1064{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001065 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001066 struct audio_usecase *uc_info;
1067 struct audio_device *adev = out->dev;
1068
Eric Laurent994a6932013-07-17 11:51:42 -07001069 ALOGV("%s: enter: usecase(%d: %s) devices(%#x)",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001070 __func__, out->usecase, use_case_table[out->usecase], out->devices);
Eric Laurentb23d5282013-05-14 15:27:20 -07001071 out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001072 if (out->pcm_device_id < 0) {
1073 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
1074 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001075 ret = -EINVAL;
1076 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001077 }
1078
1079 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
1080 uc_info->id = out->usecase;
1081 uc_info->type = PCM_PLAYBACK;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001082 uc_info->stream.out = out;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001083 uc_info->devices = out->devices;
1084 uc_info->in_snd_device = SND_DEVICE_NONE;
1085 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001086
Eric Laurent07eeafd2013-10-06 12:52:49 -07001087 /* This must be called before adding this usecase to the list */
1088 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
1089 check_and_set_hdmi_channels(adev, out->config.channels);
1090
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001091 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001092
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001093 select_devices(adev, out->usecase);
1094
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001095 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
1096 __func__, 0, out->pcm_device_id);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001097 if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1098 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001099 PCM_OUT | PCM_MONOTONIC, &out->config);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001100 if (out->pcm && !pcm_is_ready(out->pcm)) {
1101 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
1102 pcm_close(out->pcm);
1103 out->pcm = NULL;
1104 ret = -EIO;
1105 goto error_open;
1106 }
1107 } else {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001108 out->pcm = NULL;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001109 out->compr = compress_open(SOUND_CARD, out->pcm_device_id,
1110 COMPRESS_IN, &out->compr_config);
1111 if (out->compr && !is_compress_ready(out->compr)) {
1112 ALOGE("%s: %s", __func__, compress_get_error(out->compr));
1113 compress_close(out->compr);
1114 out->compr = NULL;
1115 ret = -EIO;
1116 goto error_open;
1117 }
1118 if (out->offload_callback)
1119 compress_nonblock(out->compr, out->non_blocking);
Eric Laurentc4aef752013-09-12 17:45:53 -07001120
1121 if (adev->visualizer_start_output != NULL)
1122 adev->visualizer_start_output(out->handle);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001123 }
Eric Laurent994a6932013-07-17 11:51:42 -07001124 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001125 return 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001126error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001127 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001128error_config:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001129 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001130}
1131
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001132static int check_input_parameters(uint32_t sample_rate,
1133 audio_format_t format,
1134 int channel_count)
1135{
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001136 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001137
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001138 if ((format != AUDIO_FORMAT_PCM_16_BIT) &&
Mingming Yine62d7842013-10-25 16:26:03 -07001139 !voice_extn_compress_voip_is_format_supported(format) &&
1140 !audio_extn_compr_cap_format_supported(format)) ret = -EINVAL;
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001141
1142 switch (channel_count) {
1143 case 1:
1144 case 2:
1145 case 6:
1146 break;
1147 default:
1148 ret = -EINVAL;
1149 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001150
1151 switch (sample_rate) {
1152 case 8000:
1153 case 11025:
1154 case 12000:
1155 case 16000:
1156 case 22050:
1157 case 24000:
1158 case 32000:
1159 case 44100:
1160 case 48000:
1161 break;
1162 default:
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001163 ret = -EINVAL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001164 }
1165
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08001166 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001167}
1168
1169static size_t get_input_buffer_size(uint32_t sample_rate,
1170 audio_format_t format,
1171 int channel_count)
1172{
1173 size_t size = 0;
1174
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001175 if (check_input_parameters(sample_rate, format, channel_count) != 0)
1176 return 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001177
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001178 size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
1179 /* ToDo: should use frame_size computed based on the format and
1180 channel_count here. */
1181 size *= sizeof(short) * channel_count;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001182
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -07001183 /* make sure the size is multiple of 64 */
1184 size += 0x3f;
1185 size &= ~0x3f;
1186
1187 return size;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001188}
1189
1190static uint32_t out_get_sample_rate(const struct audio_stream *stream)
1191{
1192 struct stream_out *out = (struct stream_out *)stream;
1193
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001194 return out->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001195}
1196
1197static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1198{
1199 return -ENOSYS;
1200}
1201
1202static size_t out_get_buffer_size(const struct audio_stream *stream)
1203{
1204 struct stream_out *out = (struct stream_out *)stream;
1205
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001206 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD)
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001207 return out->compr_config.fragment_size;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001208 else if(out->usecase == USECASE_COMPRESS_VOIP_CALL)
1209 return voice_extn_compress_voip_out_get_buffer_size(out);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001210
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001211 return out->config.period_size * audio_stream_frame_size(stream);
1212}
1213
1214static uint32_t out_get_channels(const struct audio_stream *stream)
1215{
1216 struct stream_out *out = (struct stream_out *)stream;
1217
1218 return out->channel_mask;
1219}
1220
1221static audio_format_t out_get_format(const struct audio_stream *stream)
1222{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001223 struct stream_out *out = (struct stream_out *)stream;
1224
1225 return out->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001226}
1227
1228static int out_set_format(struct audio_stream *stream, audio_format_t format)
1229{
1230 return -ENOSYS;
1231}
1232
1233static int out_standby(struct audio_stream *stream)
1234{
1235 struct stream_out *out = (struct stream_out *)stream;
1236 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001237
Eric Laurent994a6932013-07-17 11:51:42 -07001238 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001239 out->usecase, use_case_table[out->usecase]);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001240 if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
1241 /* Ignore standby in case of voip call because the voip output
1242 * stream is closed in adev_close_output_stream()
1243 */
1244 ALOGV("%s: Ignore Standby in VOIP call", __func__);
1245 return 0;
1246 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001247
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001248 pthread_mutex_lock(&out->lock);
Krishnankutty Kolathappillydc4f7572013-11-01 20:07:13 -07001249 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001250 if (!out->standby) {
1251 out->standby = true;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001252 if (out->usecase != USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1253 if (out->pcm) {
1254 pcm_close(out->pcm);
1255 out->pcm = NULL;
1256 }
1257 } else {
1258 stop_compressed_output_l(out);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001259 out->gapless_mdata.encoder_delay = 0;
1260 out->gapless_mdata.encoder_padding = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001261 if (out->compr != NULL) {
1262 compress_close(out->compr);
1263 out->compr = NULL;
1264 }
Eric Laurent150dbfe2013-02-27 14:31:02 -08001265 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001266 stop_output_stream(out);
1267 }
Krishnankutty Kolathappillydc4f7572013-11-01 20:07:13 -07001268 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001269 pthread_mutex_unlock(&out->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001270 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001271 return 0;
1272}
1273
1274static int out_dump(const struct audio_stream *stream, int fd)
1275{
1276 return 0;
1277}
1278
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001279static int parse_compress_metadata(struct stream_out *out, struct str_parms *parms)
1280{
1281 int ret = 0;
1282 char value[32];
1283 struct compr_gapless_mdata tmp_mdata;
1284
1285 if (!out || !parms) {
1286 return -EINVAL;
1287 }
1288
1289 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES, value, sizeof(value));
1290 if (ret >= 0) {
1291 tmp_mdata.encoder_delay = atoi(value); //whats a good limit check?
1292 } else {
1293 return -EINVAL;
1294 }
1295
1296 ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES, value, sizeof(value));
1297 if (ret >= 0) {
1298 tmp_mdata.encoder_padding = atoi(value);
1299 } else {
1300 return -EINVAL;
1301 }
1302
1303 out->gapless_mdata = tmp_mdata;
1304 out->send_new_metadata = 1;
1305 ALOGV("%s new encoder delay %u and padding %u", __func__,
1306 out->gapless_mdata.encoder_delay, out->gapless_mdata.encoder_padding);
1307
1308 return 0;
1309}
1310
1311
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001312static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
1313{
1314 struct stream_out *out = (struct stream_out *)stream;
1315 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001316 struct audio_usecase *usecase;
1317 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001318 struct str_parms *parms;
1319 char value[32];
1320 int ret, val = 0;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001321 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001322
sangwoobc677242013-08-08 16:53:43 +09001323 ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001324 __func__, out->usecase, use_case_table[out->usecase], kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001325 parms = str_parms_create_str(kvpairs);
1326 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1327 if (ret >= 0) {
1328 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001329 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001330 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001331
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001332 /*
1333 * When HDMI cable is unplugged the music playback is paused and
1334 * the policy manager sends routing=0. But the audioflinger
1335 * continues to write data until standby time (3sec).
1336 * As the HDMI core is turned off, the write gets blocked.
1337 * Avoid this by routing audio to speaker until standby.
1338 */
1339 if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL &&
1340 val == AUDIO_DEVICE_NONE) {
1341 val = AUDIO_DEVICE_OUT_SPEAKER;
1342 }
1343
1344 /*
1345 * select_devices() call below switches all the usecases on the same
1346 * backend to the new device. Refer to check_usecases_codec_backend() in
1347 * the select_devices(). But how do we undo this?
1348 *
1349 * For example, music playback is active on headset (deep-buffer usecase)
1350 * and if we go to ringtones and select a ringtone, low-latency usecase
1351 * will be started on headset+speaker. As we can't enable headset+speaker
1352 * and headset devices at the same time, select_devices() switches the music
1353 * playback to headset+speaker while starting low-lateny usecase for ringtone.
1354 * So when the ringtone playback is completed, how do we undo the same?
1355 *
1356 * We are relying on the out_set_parameters() call on deep-buffer output,
1357 * once the ringtone playback is ended.
1358 * NOTE: We should not check if the current devices are same as new devices.
1359 * Because select_devices() must be called to switch back the music
1360 * playback to headset.
1361 */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001362 if (val != 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001363 out->devices = val;
1364
1365 if (!out->standby)
1366 select_devices(adev, out->usecase);
1367
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001368 if ((adev->mode == AUDIO_MODE_IN_CALL) &&
1369 !voice_is_in_call(adev) &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001370 (out == adev->primary_output)) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001371 voice_start_call(adev);
1372 } else if ((adev->mode == AUDIO_MODE_IN_CALL) &&
1373 voice_is_in_call(adev) &&
1374 (out == adev->primary_output)) {
1375 select_devices(adev, get_voice_usecase_id_from_list(adev));
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001376 }
1377 }
1378
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001379 if ((adev->mode == AUDIO_MODE_NORMAL) &&
1380 voice_is_in_call(adev) &&
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001381 (out == adev->primary_output)) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001382 voice_stop_call(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001383 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001384
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001385 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001386 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001387 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001388
1389 if (out == adev->primary_output) {
1390 pthread_mutex_lock(&adev->lock);
1391 audio_extn_set_parameters(adev, parms);
1392 pthread_mutex_unlock(&adev->lock);
1393 }
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001394 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1395 parse_compress_metadata(out, parms);
1396 }
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07001397
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001398 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001399 ALOGV("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001400 return ret;
1401}
1402
1403static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
1404{
1405 struct stream_out *out = (struct stream_out *)stream;
1406 struct str_parms *query = str_parms_create_str(keys);
1407 char *str;
1408 char value[256];
1409 struct str_parms *reply = str_parms_create();
1410 size_t i, j;
1411 int ret;
1412 bool first = true;
Eric Laurent994a6932013-07-17 11:51:42 -07001413 ALOGV("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001414 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
1415 if (ret >= 0) {
1416 value[0] = '\0';
1417 i = 0;
1418 while (out->supported_channel_masks[i] != 0) {
1419 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
1420 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
1421 if (!first) {
1422 strcat(value, "|");
1423 }
1424 strcat(value, out_channels_name_to_enum_table[j].name);
1425 first = false;
1426 break;
1427 }
1428 }
1429 i++;
1430 }
1431 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1432 str = str_parms_to_str(reply);
1433 } else {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001434 voice_extn_out_get_parameters(out, query, reply);
1435 str = str_parms_to_str(reply);
1436 if (!strncmp(str, "", sizeof(""))) {
1437 str = strdup(keys);
1438 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001439 }
1440 str_parms_destroy(query);
1441 str_parms_destroy(reply);
Eric Laurent994a6932013-07-17 11:51:42 -07001442 ALOGV("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001443 return str;
1444}
1445
1446static uint32_t out_get_latency(const struct audio_stream_out *stream)
1447{
1448 struct stream_out *out = (struct stream_out *)stream;
1449
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001450 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD)
1451 return COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
1452
1453 return (out->config.period_count * out->config.period_size * 1000) /
1454 (out->config.rate);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001455}
1456
1457static int out_set_volume(struct audio_stream_out *stream, float left,
1458 float right)
1459{
Eric Laurenta9024de2013-04-04 09:19:12 -07001460 struct stream_out *out = (struct stream_out *)stream;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001461 int volume[2];
1462
Eric Laurenta9024de2013-04-04 09:19:12 -07001463 if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1464 /* only take left channel into account: the API is for stereo anyway */
1465 out->muted = (left == 0.0f);
1466 return 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001467 } else if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1468 const char *mixer_ctl_name = "Compress Playback Volume";
1469 struct audio_device *adev = out->dev;
1470 struct mixer_ctl *ctl;
1471
1472 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1473 if (!ctl) {
1474 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1475 __func__, mixer_ctl_name);
1476 return -EINVAL;
1477 }
1478 volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX);
1479 volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX);
1480 mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0]));
1481 return 0;
Eric Laurenta9024de2013-04-04 09:19:12 -07001482 }
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001483
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001484 return -ENOSYS;
1485}
1486
1487static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1488 size_t bytes)
1489{
1490 struct stream_out *out = (struct stream_out *)stream;
1491 struct audio_device *adev = out->dev;
Eric Laurent6e895242013-09-05 16:10:57 -07001492 ssize_t ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001493
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001494 pthread_mutex_lock(&out->lock);
1495 if (out->standby) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001496 out->standby = false;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001497 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001498 if (out->usecase == USECASE_COMPRESS_VOIP_CALL)
1499 ret = voice_extn_compress_voip_start_output_stream(out);
1500 else
1501 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001502 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001503 /* ToDo: If use case is compress offload should return 0 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001504 if (ret != 0) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001505 out->standby = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001506 goto exit;
1507 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001508 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001509
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001510 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001511 ALOGVV("%s: writing buffer (%d bytes) to compress device", __func__, bytes);
1512 if (out->send_new_metadata) {
1513 ALOGVV("send new gapless metadata");
1514 compress_set_gapless_metadata(out->compr, &out->gapless_mdata);
1515 out->send_new_metadata = 0;
1516 }
1517
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001518 ret = compress_write(out->compr, buffer, bytes);
Haynes Mathew George352f27b2013-07-26 00:00:15 -07001519 ALOGVV("%s: writing buffer (%d bytes) to compress device returned %d", __func__, bytes, ret);
Eric Laurent6e895242013-09-05 16:10:57 -07001520 if (ret >= 0 && ret < (ssize_t)bytes) {
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001521 send_offload_cmd_l(out, OFFLOAD_CMD_WAIT_FOR_BUFFER);
1522 }
1523 if (!out->playback_started) {
1524 compress_start(out->compr);
1525 out->playback_started = 1;
1526 out->offload_state = OFFLOAD_STATE_PLAYING;
1527 }
1528 pthread_mutex_unlock(&out->lock);
1529 return ret;
1530 } else {
1531 if (out->pcm) {
1532 if (out->muted)
1533 memset((void *)buffer, 0, bytes);
1534 ALOGVV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1535 ret = pcm_write(out->pcm, (void *)buffer, bytes);
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001536 if (ret == 0)
1537 out->written += bytes / (out->config.channels * sizeof(short));
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001538 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001539 }
1540
1541exit:
1542 pthread_mutex_unlock(&out->lock);
1543
1544 if (ret != 0) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001545 if (out->pcm)
1546 ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm));
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001547 out_standby(&out->stream.common);
1548 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1549 out_get_sample_rate(&out->stream.common));
1550 }
1551 return bytes;
1552}
1553
1554static int out_get_render_position(const struct audio_stream_out *stream,
1555 uint32_t *dsp_frames)
1556{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001557 struct stream_out *out = (struct stream_out *)stream;
1558 *dsp_frames = 0;
1559 if ((out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) && (dsp_frames != NULL)) {
1560 pthread_mutex_lock(&out->lock);
1561 if (out->compr != NULL) {
1562 compress_get_tstamp(out->compr, (unsigned long *)dsp_frames,
1563 &out->sample_rate);
1564 ALOGVV("%s rendered frames %d sample_rate %d",
1565 __func__, *dsp_frames, out->sample_rate);
1566 }
1567 pthread_mutex_unlock(&out->lock);
1568 return 0;
1569 } else
1570 return -EINVAL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001571}
1572
1573static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1574{
1575 return 0;
1576}
1577
1578static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1579{
1580 return 0;
1581}
1582
1583static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1584 int64_t *timestamp)
1585{
1586 return -EINVAL;
1587}
1588
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001589static int out_get_presentation_position(const struct audio_stream_out *stream,
1590 uint64_t *frames, struct timespec *timestamp)
1591{
1592 struct stream_out *out = (struct stream_out *)stream;
1593 int ret = -1;
Eric Laurent949a0892013-09-20 09:20:13 -07001594 unsigned long dsp_frames;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001595
1596 pthread_mutex_lock(&out->lock);
1597
Eric Laurent949a0892013-09-20 09:20:13 -07001598 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1599 if (out->compr != NULL) {
1600 compress_get_tstamp(out->compr, &dsp_frames,
1601 &out->sample_rate);
1602 ALOGVV("%s rendered frames %ld sample_rate %d",
1603 __func__, dsp_frames, out->sample_rate);
1604 *frames = dsp_frames;
1605 ret = 0;
1606 /* this is the best we can do */
1607 clock_gettime(CLOCK_MONOTONIC, timestamp);
1608 }
1609 } else {
1610 if (out->pcm) {
1611 size_t avail;
1612 if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
1613 size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
Eric Laurent949a0892013-09-20 09:20:13 -07001614 int64_t signed_frames = out->written - kernel_buffer_size + avail;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001615 // This adjustment accounts for buffering after app processor.
1616 // It is based on estimated DSP latency per use case, rather than exact.
1617 signed_frames -=
1618 (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL);
1619
Eric Laurent949a0892013-09-20 09:20:13 -07001620 // It would be unusual for this value to be negative, but check just in case ...
1621 if (signed_frames >= 0) {
1622 *frames = signed_frames;
1623 ret = 0;
1624 }
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07001625 }
1626 }
1627 }
1628
1629 pthread_mutex_unlock(&out->lock);
1630
1631 return ret;
1632}
1633
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001634static int out_set_callback(struct audio_stream_out *stream,
1635 stream_callback_t callback, void *cookie)
1636{
1637 struct stream_out *out = (struct stream_out *)stream;
1638
1639 ALOGV("%s", __func__);
1640 pthread_mutex_lock(&out->lock);
1641 out->offload_callback = callback;
1642 out->offload_cookie = cookie;
1643 pthread_mutex_unlock(&out->lock);
1644 return 0;
1645}
1646
1647static int out_pause(struct audio_stream_out* stream)
1648{
1649 struct stream_out *out = (struct stream_out *)stream;
1650 int status = -ENOSYS;
1651 ALOGV("%s", __func__);
1652 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1653 pthread_mutex_lock(&out->lock);
1654 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PLAYING) {
1655 status = compress_pause(out->compr);
1656 out->offload_state = OFFLOAD_STATE_PAUSED;
1657 }
1658 pthread_mutex_unlock(&out->lock);
1659 }
1660 return status;
1661}
1662
1663static int out_resume(struct audio_stream_out* stream)
1664{
1665 struct stream_out *out = (struct stream_out *)stream;
1666 int status = -ENOSYS;
1667 ALOGV("%s", __func__);
1668 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1669 status = 0;
1670 pthread_mutex_lock(&out->lock);
1671 if (out->compr != NULL && out->offload_state == OFFLOAD_STATE_PAUSED) {
1672 status = compress_resume(out->compr);
1673 out->offload_state = OFFLOAD_STATE_PLAYING;
1674 }
1675 pthread_mutex_unlock(&out->lock);
1676 }
1677 return status;
1678}
1679
1680static int out_drain(struct audio_stream_out* stream, audio_drain_type_t type )
1681{
1682 struct stream_out *out = (struct stream_out *)stream;
1683 int status = -ENOSYS;
1684 ALOGV("%s", __func__);
1685 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1686 pthread_mutex_lock(&out->lock);
1687 if (type == AUDIO_DRAIN_EARLY_NOTIFY)
1688 status = send_offload_cmd_l(out, OFFLOAD_CMD_PARTIAL_DRAIN);
1689 else
1690 status = send_offload_cmd_l(out, OFFLOAD_CMD_DRAIN);
1691 pthread_mutex_unlock(&out->lock);
1692 }
1693 return status;
1694}
1695
1696static int out_flush(struct audio_stream_out* stream)
1697{
1698 struct stream_out *out = (struct stream_out *)stream;
1699 ALOGV("%s", __func__);
1700 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
1701 pthread_mutex_lock(&out->lock);
1702 stop_compressed_output_l(out);
1703 pthread_mutex_unlock(&out->lock);
1704 return 0;
1705 }
1706 return -ENOSYS;
1707}
1708
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001709/** audio_stream_in implementation **/
1710static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1711{
1712 struct stream_in *in = (struct stream_in *)stream;
1713
1714 return in->config.rate;
1715}
1716
1717static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1718{
1719 return -ENOSYS;
1720}
1721
1722static size_t in_get_buffer_size(const struct audio_stream *stream)
1723{
1724 struct stream_in *in = (struct stream_in *)stream;
1725
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001726 if(in->usecase == USECASE_COMPRESS_VOIP_CALL)
1727 return voice_extn_compress_voip_in_get_buffer_size(in);
Mingming Yine62d7842013-10-25 16:26:03 -07001728 else if(audio_extn_compr_cap_usecase_supported(in->usecase))
1729 return audio_extn_compr_cap_get_buffer_size(in->config.format);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001730
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001731 return in->config.period_size * audio_stream_frame_size(stream);
1732}
1733
1734static uint32_t in_get_channels(const struct audio_stream *stream)
1735{
1736 struct stream_in *in = (struct stream_in *)stream;
1737
1738 return in->channel_mask;
1739}
1740
1741static audio_format_t in_get_format(const struct audio_stream *stream)
1742{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001743 struct stream_in *in = (struct stream_in *)stream;
1744
1745 return in->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001746}
1747
1748static int in_set_format(struct audio_stream *stream, audio_format_t format)
1749{
1750 return -ENOSYS;
1751}
1752
1753static int in_standby(struct audio_stream *stream)
1754{
1755 struct stream_in *in = (struct stream_in *)stream;
1756 struct audio_device *adev = in->dev;
1757 int status = 0;
Eric Laurent994a6932013-07-17 11:51:42 -07001758 ALOGV("%s: enter", __func__);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001759
1760 if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
1761 /* Ignore standby in case of voip call because the voip input
1762 * stream is closed in adev_close_input_stream()
1763 */
1764 ALOGV("%s: Ignore Standby in VOIP call", __func__);
1765 return status;
1766 }
1767
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001768 pthread_mutex_lock(&in->lock);
1769 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001770 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001771 if (in->pcm) {
1772 pcm_close(in->pcm);
1773 in->pcm = NULL;
1774 }
1775 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001776 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001777 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001778 }
1779 pthread_mutex_unlock(&in->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001780 ALOGV("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001781 return status;
1782}
1783
1784static int in_dump(const struct audio_stream *stream, int fd)
1785{
1786 return 0;
1787}
1788
1789static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1790{
1791 struct stream_in *in = (struct stream_in *)stream;
1792 struct audio_device *adev = in->dev;
1793 struct str_parms *parms;
1794 char *str;
1795 char value[32];
1796 int ret, val = 0;
1797
Eric Laurent994a6932013-07-17 11:51:42 -07001798 ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001799 parms = str_parms_create_str(kvpairs);
1800
1801 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1802
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001803 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001804 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001805 if (ret >= 0) {
1806 val = atoi(value);
1807 /* no audio source uses val == 0 */
1808 if ((in->source != val) && (val != 0)) {
1809 in->source = val;
1810 }
1811 }
1812
1813 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1814 if (ret >= 0) {
1815 val = atoi(value);
1816 if ((in->device != val) && (val != 0)) {
1817 in->device = val;
1818 /* If recording is in progress, change the tx device to new device */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001819 if (!in->standby)
1820 ret = select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001821 }
1822 }
1823
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001824 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001825 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001826
1827 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001828 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001829 return ret;
1830}
1831
1832static char* in_get_parameters(const struct audio_stream *stream,
1833 const char *keys)
1834{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001835 struct stream_in *in = (struct stream_in *)stream;
1836 struct str_parms *query = str_parms_create_str(keys);
1837 char *str;
1838 char value[256];
1839 struct str_parms *reply = str_parms_create();
1840 ALOGV("%s: enter: keys - %s", __func__, keys);
1841
1842 voice_extn_in_get_parameters(in, query, reply);
1843
1844 str = str_parms_to_str(reply);
1845 str_parms_destroy(query);
1846 str_parms_destroy(reply);
1847
1848 ALOGV("%s: exit: returns - %s", __func__, str);
1849 return str;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001850}
1851
1852static int in_set_gain(struct audio_stream_in *stream, float gain)
1853{
1854 return 0;
1855}
1856
1857static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1858 size_t bytes)
1859{
1860 struct stream_in *in = (struct stream_in *)stream;
1861 struct audio_device *adev = in->dev;
1862 int i, ret = -1;
1863
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001864 pthread_mutex_lock(&in->lock);
1865 if (in->standby) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001866 pthread_mutex_lock(&adev->lock);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001867 if (in->usecase == USECASE_COMPRESS_VOIP_CALL)
1868 ret = voice_extn_compress_voip_start_input_stream(in);
1869 else
1870 ret = start_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001871 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001872 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001873 goto exit;
1874 }
1875 in->standby = 0;
1876 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001877
1878 if (in->pcm) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001879 if (audio_extn_ssr_get_enabled() && popcount(in->channel_mask) == 6)
1880 ret = audio_extn_ssr_read(stream, buffer, bytes);
Mingming Yine62d7842013-10-25 16:26:03 -07001881 else if (audio_extn_compr_cap_usecase_supported(in->usecase))
1882 ret = audio_extn_compr_cap_read(in, buffer, bytes);
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001883 else
1884 ret = pcm_read(in->pcm, buffer, bytes);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001885 }
1886
1887 /*
1888 * Instead of writing zeroes here, we could trust the hardware
1889 * to always provide zeroes when muted.
1890 */
Helen Zenge0b186f2013-10-23 14:00:59 -07001891 if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call(adev))
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001892 memset(buffer, 0, bytes);
1893
1894exit:
1895 pthread_mutex_unlock(&in->lock);
1896
1897 if (ret != 0) {
1898 in_standby(&in->stream.common);
1899 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1900 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1901 in_get_sample_rate(&in->stream.common));
1902 }
1903 return bytes;
1904}
1905
1906static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1907{
1908 return 0;
1909}
1910
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001911static int add_remove_audio_effect(const struct audio_stream *stream,
1912 effect_handle_t effect,
1913 bool enable)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001914{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001915 struct stream_in *in = (struct stream_in *)stream;
1916 int status = 0;
1917 effect_descriptor_t desc;
1918
1919 status = (*effect)->get_descriptor(effect, &desc);
1920 if (status != 0)
1921 return status;
1922
1923 pthread_mutex_lock(&in->lock);
1924 pthread_mutex_lock(&in->dev->lock);
1925 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
1926 in->enable_aec != enable &&
1927 (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
1928 in->enable_aec = enable;
1929 if (!in->standby)
1930 select_devices(in->dev, in->usecase);
1931 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08001932 if (in->enable_ns != enable &&
1933 (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) {
1934 in->enable_ns = enable;
1935 if (!in->standby)
1936 select_devices(in->dev, in->usecase);
1937 }
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001938 pthread_mutex_unlock(&in->dev->lock);
1939 pthread_mutex_unlock(&in->lock);
1940
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001941 return 0;
1942}
1943
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001944static int in_add_audio_effect(const struct audio_stream *stream,
1945 effect_handle_t effect)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001946{
Eric Laurent994a6932013-07-17 11:51:42 -07001947 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001948 return add_remove_audio_effect(stream, effect, true);
1949}
1950
1951static int in_remove_audio_effect(const struct audio_stream *stream,
1952 effect_handle_t effect)
1953{
Eric Laurent994a6932013-07-17 11:51:42 -07001954 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001955 return add_remove_audio_effect(stream, effect, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001956}
1957
1958static int adev_open_output_stream(struct audio_hw_device *dev,
1959 audio_io_handle_t handle,
1960 audio_devices_t devices,
1961 audio_output_flags_t flags,
1962 struct audio_config *config,
1963 struct audio_stream_out **stream_out)
1964{
1965 struct audio_device *adev = (struct audio_device *)dev;
1966 struct stream_out *out;
1967 int i, ret;
1968
Eric Laurent994a6932013-07-17 11:51:42 -07001969 ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001970 __func__, config->sample_rate, config->channel_mask, devices, flags);
1971 *stream_out = NULL;
1972 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1973
1974 if (devices == AUDIO_DEVICE_NONE)
1975 devices = AUDIO_DEVICE_OUT_SPEAKER;
1976
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001977 out->flags = flags;
1978 out->devices = devices;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001979 out->dev = adev;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07001980 out->format = config->format;
1981 out->sample_rate = config->sample_rate;
1982 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1983 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
Eric Laurentc4aef752013-09-12 17:45:53 -07001984 out->handle = handle;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001985
1986 /* Init use case and pcm_config */
Ravi Kumar Alamanda86b0e2b2013-11-20 14:52:30 -08001987 if (out->flags == AUDIO_OUTPUT_FLAG_DIRECT &&
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001988 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001989 pthread_mutex_lock(&adev->lock);
1990 ret = read_hdmi_channel_masks(out);
1991 pthread_mutex_unlock(&adev->lock);
Eric Laurent07eeafd2013-10-06 12:52:49 -07001992 if (ret != 0)
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001993 goto error_open;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001994
1995 if (config->sample_rate == 0)
1996 config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1997 if (config->channel_mask == 0)
1998 config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1999
2000 out->channel_mask = config->channel_mask;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002001 out->sample_rate = config->sample_rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002002 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
2003 out->config = pcm_config_hdmi_multi;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002004 out->config.rate = config->sample_rate;
2005 out->config.channels = popcount(out->channel_mask);
2006 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002007 } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
2008 (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) &&
2009 (voice_extn_compress_voip_is_format_supported(out->format))) {
2010 ret = voice_extn_compress_voip_open_output_stream(out);
2011 if (ret != 0) {
2012 ALOGE("%s: Compress voip output cannot be opened, error:%d",
2013 __func__, ret);
2014 goto error_open;
2015 }
2016 out->config.rate = config->sample_rate;
2017 out->sample_rate = config->sample_rate;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002018 } else if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
2019 if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version ||
2020 config->offload_info.size != AUDIO_INFO_INITIALIZER.size) {
2021 ALOGE("%s: Unsupported Offload information", __func__);
2022 ret = -EINVAL;
2023 goto error_open;
2024 }
2025 if (!is_supported_format(config->offload_info.format)) {
2026 ALOGE("%s: Unsupported audio format", __func__);
2027 ret = -EINVAL;
2028 goto error_open;
2029 }
2030
2031 out->compr_config.codec = (struct snd_codec *)
2032 calloc(1, sizeof(struct snd_codec));
2033
2034 out->usecase = USECASE_AUDIO_PLAYBACK_OFFLOAD;
2035 if (config->offload_info.channel_mask)
2036 out->channel_mask = config->offload_info.channel_mask;
2037 else if (config->channel_mask)
2038 out->channel_mask = config->channel_mask;
2039 out->format = config->offload_info.format;
2040 out->sample_rate = config->offload_info.sample_rate;
2041
2042 out->stream.set_callback = out_set_callback;
2043 out->stream.pause = out_pause;
2044 out->stream.resume = out_resume;
2045 out->stream.drain = out_drain;
2046 out->stream.flush = out_flush;
2047
2048 out->compr_config.codec->id =
2049 get_snd_codec_id(config->offload_info.format);
2050 out->compr_config.fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
2051 out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS;
2052 out->compr_config.codec->sample_rate =
2053 compress_get_alsa_rate(config->offload_info.sample_rate);
2054 out->compr_config.codec->bit_rate =
2055 config->offload_info.bit_rate;
2056 out->compr_config.codec->ch_in =
2057 popcount(config->channel_mask);
2058 out->compr_config.codec->ch_out = out->compr_config.codec->ch_in;
2059
2060 if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
2061 out->non_blocking = 1;
Haynes Mathew George352f27b2013-07-26 00:00:15 -07002062
2063 out->send_new_metadata = 1;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002064 create_offload_callback_thread(out);
2065 ALOGV("%s: offloaded output offload_info version %04x bit rate %d",
2066 __func__, config->offload_info.version,
2067 config->offload_info.bit_rate);
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -07002068 } else if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) {
2069 ret = voice_check_and_set_incall_music_usecase(adev, out);
2070 if (ret != 0) {
2071 ALOGE("%s: Incall music delivery usecase cannot be set error:%d",
2072 __func__, ret);
2073 goto error_open;
2074 }
Ravi Kumar Alamanda8f715d92013-11-01 20:37:38 -07002075 } else if (out->flags & AUDIO_OUTPUT_FLAG_FAST) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002076 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
2077 out->config = pcm_config_low_latency;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002078 out->sample_rate = out->config.rate;
Ravi Kumar Alamanda8f715d92013-11-01 20:37:38 -07002079 } else {
2080 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
2081 out->config = pcm_config_deep_buffer;
2082 out->sample_rate = out->config.rate;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002083 }
2084
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002085 if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {
2086 if(adev->primary_output == NULL)
2087 adev->primary_output = out;
2088 else {
2089 ALOGE("%s: Primary output is already opened", __func__);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002090 ret = -EEXIST;
2091 goto error_open;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002092 }
2093 }
2094
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002095 /* Check if this usecase is already existing */
2096 pthread_mutex_lock(&adev->lock);
2097 if (get_usecase_from_list(adev, out->usecase) != NULL) {
2098 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002099 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002100 ret = -EEXIST;
2101 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002102 }
2103 pthread_mutex_unlock(&adev->lock);
2104
2105 out->stream.common.get_sample_rate = out_get_sample_rate;
2106 out->stream.common.set_sample_rate = out_set_sample_rate;
2107 out->stream.common.get_buffer_size = out_get_buffer_size;
2108 out->stream.common.get_channels = out_get_channels;
2109 out->stream.common.get_format = out_get_format;
2110 out->stream.common.set_format = out_set_format;
2111 out->stream.common.standby = out_standby;
2112 out->stream.common.dump = out_dump;
2113 out->stream.common.set_parameters = out_set_parameters;
2114 out->stream.common.get_parameters = out_get_parameters;
2115 out->stream.common.add_audio_effect = out_add_audio_effect;
2116 out->stream.common.remove_audio_effect = out_remove_audio_effect;
2117 out->stream.get_latency = out_get_latency;
2118 out->stream.set_volume = out_set_volume;
2119 out->stream.write = out_write;
2120 out->stream.get_render_position = out_get_render_position;
2121 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07002122 out->stream.get_presentation_position = out_get_presentation_position;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002123
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002124 out->standby = 1;
Eric Laurenta9024de2013-04-04 09:19:12 -07002125 /* out->muted = false; by calloc() */
Glenn Kasten2ccd7ba2013-09-10 09:04:31 -07002126 /* out->written = 0; by calloc() */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002127
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002128 pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL);
2129 pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002130
2131 config->format = out->stream.common.get_format(&out->stream.common);
2132 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
2133 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
2134
2135 *stream_out = &out->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07002136 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002137 return 0;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07002138
2139error_open:
2140 free(out);
2141 *stream_out = NULL;
2142 ALOGD("%s: exit: ret %d", __func__, ret);
2143 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002144}
2145
2146static void adev_close_output_stream(struct audio_hw_device *dev,
2147 struct audio_stream_out *stream)
2148{
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002149 struct stream_out *out = (struct stream_out *)stream;
2150 struct audio_device *adev = out->dev;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002151 int ret = 0;
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002152
Eric Laurent994a6932013-07-17 11:51:42 -07002153 ALOGV("%s: enter", __func__);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002154 if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
2155 ret = voice_extn_compress_voip_close_output_stream(&stream->common);
2156 if(ret != 0)
2157 ALOGE("%s: Compress voip output cannot be closed, error:%d",
2158 __func__, ret);
2159 }
2160 else
2161 out_standby(&stream->common);
2162
Ravi Kumar Alamanda4e02e552013-07-17 15:22:04 -07002163 if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
2164 destroy_offload_callback_thread(out);
2165
2166 if (out->compr_config.codec != NULL)
2167 free(out->compr_config.codec);
2168 }
2169 pthread_cond_destroy(&out->cond);
2170 pthread_mutex_destroy(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002171 free(stream);
Eric Laurent994a6932013-07-17 11:51:42 -07002172 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002173}
2174
2175static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
2176{
2177 struct audio_device *adev = (struct audio_device *)dev;
2178 struct str_parms *parms;
2179 char *str;
2180 char value[32];
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002181 int val;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002182 int ret;
2183
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002184 ALOGD("%s: enter: %s", __func__, kvpairs);
2185
2186 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002187 parms = str_parms_create_str(kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002188
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002189 voice_set_parameters(adev, parms);
2190 platform_set_parameters(adev->platform, parms);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002191
2192 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
2193 if (ret >= 0) {
2194 /* When set to false, HAL should disable EC and NS
2195 * But it is currently not supported.
2196 */
2197 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
2198 adev->bluetooth_nrec = true;
2199 else
2200 adev->bluetooth_nrec = false;
2201 }
2202
2203 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
2204 if (ret >= 0) {
2205 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
2206 adev->screen_off = false;
2207 else
2208 adev->screen_off = true;
2209 }
2210
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002211 ret = str_parms_get_int(parms, "rotation", &val);
2212 if (ret >= 0) {
2213 bool reverse_speakers = false;
2214 switch(val) {
2215 // FIXME: note that the code below assumes that the speakers are in the correct placement
2216 // relative to the user when the device is rotated 90deg from its default rotation. This
2217 // assumption is device-specific, not platform-specific like this code.
2218 case 270:
2219 reverse_speakers = true;
2220 break;
2221 case 0:
2222 case 90:
2223 case 180:
2224 break;
2225 default:
2226 ALOGE("%s: unexpected rotation of %d", __func__, val);
2227 }
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002228 if (adev->speaker_lr_swap != reverse_speakers) {
2229 adev->speaker_lr_swap = reverse_speakers;
2230 // only update the selected device if there is active pcm playback
2231 struct audio_usecase *usecase;
2232 struct listnode *node;
2233 list_for_each(node, &adev->usecase_list) {
2234 usecase = node_to_item(node, struct audio_usecase, list);
2235 if (usecase->type == PCM_PLAYBACK) {
2236 select_devices(adev, usecase->id);
2237 break;
2238 }
2239 }
2240 }
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07002241 }
2242
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002243 audio_extn_set_parameters(adev, parms);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002244 str_parms_destroy(parms);
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002245
2246 pthread_mutex_unlock(&adev->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07002247 ALOGV("%s: exit with code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002248 return ret;
2249}
2250
2251static char* adev_get_parameters(const struct audio_hw_device *dev,
2252 const char *keys)
2253{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002254 struct audio_device *adev = (struct audio_device *)dev;
2255 struct str_parms *reply = str_parms_create();
2256 struct str_parms *query = str_parms_create_str(keys);
2257 char *str;
2258
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002259 pthread_mutex_lock(&adev->lock);
2260
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002261 audio_extn_get_parameters(adev, query, reply);
2262 platform_get_parameters(adev->platform, query, reply);
2263 str = str_parms_to_str(reply);
2264 str_parms_destroy(query);
2265 str_parms_destroy(reply);
2266
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002267 pthread_mutex_unlock(&adev->lock);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002268 ALOGV("%s: exit: returns - %s", __func__, str);
2269 return str;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002270}
2271
2272static int adev_init_check(const struct audio_hw_device *dev)
2273{
2274 return 0;
2275}
2276
2277static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
2278{
Haynes Mathew George5191a852013-09-11 14:19:36 -07002279 int ret;
2280 struct audio_device *adev = (struct audio_device *)dev;
2281 pthread_mutex_lock(&adev->lock);
2282 /* cache volume */
Shruthi Krishnaace10852013-10-25 14:32:12 -07002283 ret = voice_set_volume(adev, volume);
Haynes Mathew George5191a852013-09-11 14:19:36 -07002284 pthread_mutex_unlock(&adev->lock);
2285 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002286}
2287
2288static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
2289{
2290 return -ENOSYS;
2291}
2292
2293static int adev_get_master_volume(struct audio_hw_device *dev,
2294 float *volume)
2295{
2296 return -ENOSYS;
2297}
2298
2299static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
2300{
2301 return -ENOSYS;
2302}
2303
2304static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
2305{
2306 return -ENOSYS;
2307}
2308
2309static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
2310{
2311 struct audio_device *adev = (struct audio_device *)dev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002312 pthread_mutex_lock(&adev->lock);
2313 if (adev->mode != mode) {
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -07002314 ALOGD("%s mode %d\n", __func__, mode);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002315 adev->mode = mode;
2316 }
2317 pthread_mutex_unlock(&adev->lock);
2318 return 0;
2319}
2320
2321static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
2322{
Shiv Maliyappanahalli3bb73582013-11-05 12:49:15 -08002323 int ret;
2324
2325 pthread_mutex_lock(&adev->lock);
2326 ret = voice_set_mic_mute((struct audio_device *)dev, state);
2327 pthread_mutex_unlock(&adev->lock);
2328
2329 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002330}
2331
2332static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
2333{
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002334 *state = voice_get_mic_mute((struct audio_device *)dev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002335 return 0;
2336}
2337
2338static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
2339 const struct audio_config *config)
2340{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002341 int channel_count = popcount(config->channel_mask);
2342
2343 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
2344}
2345
2346static int adev_open_input_stream(struct audio_hw_device *dev,
2347 audio_io_handle_t handle,
2348 audio_devices_t devices,
2349 struct audio_config *config,
2350 struct audio_stream_in **stream_in)
2351{
2352 struct audio_device *adev = (struct audio_device *)dev;
2353 struct stream_in *in;
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08002354 int ret = 0, buffer_size, frame_size;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002355 int channel_count = popcount(config->channel_mask);
2356
Eric Laurent994a6932013-07-17 11:51:42 -07002357 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002358 *stream_in = NULL;
2359 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
2360 return -EINVAL;
2361
2362 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
2363
2364 in->stream.common.get_sample_rate = in_get_sample_rate;
2365 in->stream.common.set_sample_rate = in_set_sample_rate;
2366 in->stream.common.get_buffer_size = in_get_buffer_size;
2367 in->stream.common.get_channels = in_get_channels;
2368 in->stream.common.get_format = in_get_format;
2369 in->stream.common.set_format = in_set_format;
2370 in->stream.common.standby = in_standby;
2371 in->stream.common.dump = in_dump;
2372 in->stream.common.set_parameters = in_set_parameters;
2373 in->stream.common.get_parameters = in_get_parameters;
2374 in->stream.common.add_audio_effect = in_add_audio_effect;
2375 in->stream.common.remove_audio_effect = in_remove_audio_effect;
2376 in->stream.set_gain = in_set_gain;
2377 in->stream.read = in_read;
2378 in->stream.get_input_frames_lost = in_get_input_frames_lost;
2379
2380 in->device = devices;
2381 in->source = AUDIO_SOURCE_DEFAULT;
2382 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002383 in->standby = 1;
2384 in->channel_mask = config->channel_mask;
2385
2386 /* Update config params with the requested sample rate and channels */
2387 in->usecase = USECASE_AUDIO_RECORD;
2388 in->config = pcm_config_audio_capture;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002389 in->config.rate = config->sample_rate;
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002390 in->format = config->format;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002391
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002392 if ((in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
2393 (voice_extn_compress_voip_is_format_supported(in->format))) {
2394 ret = voice_extn_compress_voip_open_input_stream(in);
2395 if (ret != 0)
2396 {
2397 ALOGE("%s: Compress voip input cannot be opened, error:%d",
2398 __func__, ret);
2399 goto err_open;
2400 }
Mingming Yine62d7842013-10-25 16:26:03 -07002401 } else if (channel_count == 6) {
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08002402 if(audio_extn_ssr_get_enabled()) {
2403 if(audio_extn_ssr_init(adev, in)) {
2404 ALOGE("%s: audio_extn_ssr_init failed", __func__);
2405 ret = -EINVAL;
2406 goto err_open;
2407 }
2408 } else {
2409 ret = -EINVAL;
2410 goto err_open;
2411 }
Mingming Yine62d7842013-10-25 16:26:03 -07002412 } else if (audio_extn_compr_cap_enabled() &&
2413 audio_extn_compr_cap_format_supported(config->format)) {
2414 audio_extn_compr_cap_init(adev, in);
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002415 } else {
2416 in->config.channels = channel_count;
2417 frame_size = audio_stream_frame_size((struct audio_stream *)in);
2418 buffer_size = get_input_buffer_size(config->sample_rate,
2419 config->format,
2420 channel_count);
2421 in->config.period_size = buffer_size / frame_size;
2422 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002423
2424 *stream_in = &in->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07002425 ALOGV("%s: exit", __func__);
Ravi Kumar Alamandafae42112013-11-07 23:31:54 -08002426 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002427
2428err_open:
2429 free(in);
2430 *stream_in = NULL;
2431 return ret;
2432}
2433
2434static void adev_close_input_stream(struct audio_hw_device *dev,
2435 struct audio_stream_in *stream)
2436{
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002437 int ret;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002438 struct stream_in *in = (struct stream_in *)stream;
Eric Laurent994a6932013-07-17 11:51:42 -07002439 ALOGV("%s", __func__);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002440
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002441 if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
2442 ret = voice_extn_compress_voip_close_input_stream(&stream->common);
2443 if (ret != 0)
2444 ALOGE("%s: Compress voip input cannot be closed, error:%d",
2445 __func__, ret);
2446 } else
2447 in_standby(&stream->common);
2448
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002449 if (audio_extn_ssr_get_enabled() && (popcount(in->channel_mask) == 6)) {
2450 audio_extn_ssr_deinit();
2451 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002452 free(stream);
2453
Mingming Yine62d7842013-10-25 16:26:03 -07002454 if(audio_extn_compr_cap_enabled() &&
2455 audio_extn_compr_cap_format_supported(in->config.format))
2456 audio_extn_compr_cap_deinit();
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002457 return;
2458}
2459
2460static int adev_dump(const audio_hw_device_t *device, int fd)
2461{
2462 return 0;
2463}
2464
2465static int adev_close(hw_device_t *device)
2466{
2467 struct audio_device *adev = (struct audio_device *)device;
Kiran Kandi910e1862013-10-29 13:29:42 -07002468
2469 if (!adev)
2470 return 0;
2471
2472 pthread_mutex_lock(&adev_init_lock);
2473
2474 if ((--audio_device_ref_count) == 0) {
Kiran Kandide144c82013-11-20 15:58:32 -08002475 audio_extn_listen_deinit(adev);
Kiran Kandi910e1862013-10-29 13:29:42 -07002476 audio_route_free(adev->audio_route);
2477 free(adev->snd_dev_ref_cnt);
2478 platform_deinit(adev->platform);
Kiran Kandi910e1862013-10-29 13:29:42 -07002479 free(device);
2480 adev = NULL;
2481 }
2482 pthread_mutex_unlock(&adev_init_lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002483 return 0;
2484}
2485
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002486static int adev_open(const hw_module_t *module, const char *name,
2487 hw_device_t **device)
2488{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07002489 int i, ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002490
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08002491 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002492 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
2493
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002494 pthread_mutex_lock(&adev_init_lock);
Kiran Kandi910e1862013-10-29 13:29:42 -07002495 if (audio_device_ref_count != 0){
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002496 *device = &adev->device.common;
Kiran Kandi910e1862013-10-29 13:29:42 -07002497 audio_device_ref_count++;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002498 ALOGD("%s: returning existing instance of adev", __func__);
2499 ALOGD("%s: exit", __func__);
2500 pthread_mutex_unlock(&adev_init_lock);
2501 return 0;
2502 }
2503
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002504 adev = calloc(1, sizeof(struct audio_device));
2505
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002506 adev->device.common.tag = HARDWARE_DEVICE_TAG;
2507 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
2508 adev->device.common.module = (struct hw_module_t *)module;
2509 adev->device.common.close = adev_close;
2510
2511 adev->device.init_check = adev_init_check;
2512 adev->device.set_voice_volume = adev_set_voice_volume;
2513 adev->device.set_master_volume = adev_set_master_volume;
2514 adev->device.get_master_volume = adev_get_master_volume;
2515 adev->device.set_master_mute = adev_set_master_mute;
2516 adev->device.get_master_mute = adev_get_master_mute;
2517 adev->device.set_mode = adev_set_mode;
2518 adev->device.set_mic_mute = adev_set_mic_mute;
2519 adev->device.get_mic_mute = adev_get_mic_mute;
2520 adev->device.set_parameters = adev_set_parameters;
2521 adev->device.get_parameters = adev_get_parameters;
2522 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
2523 adev->device.open_output_stream = adev_open_output_stream;
2524 adev->device.close_output_stream = adev_close_output_stream;
2525 adev->device.open_input_stream = adev_open_input_stream;
2526 adev->device.close_input_stream = adev_close_input_stream;
2527 adev->device.dump = adev_dump;
2528
2529 /* Set the default route before the PCM stream is opened */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002530 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08002531 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08002532 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002533 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002534 adev->bluetooth_nrec = true;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08002535 adev->acdb_settings = TTY_MODE_OFF;
Eric Laurent07eeafd2013-10-06 12:52:49 -07002536 /* adev->cur_hdmi_channels = 0; by calloc() */
Eric Laurentb23d5282013-05-14 15:27:20 -07002537 adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002538 voice_init(adev);
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08002539 list_init(&adev->usecase_list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002540
2541 /* Loads platform specific libraries dynamically */
Eric Laurentb23d5282013-05-14 15:27:20 -07002542 adev->platform = platform_init(adev);
2543 if (!adev->platform) {
2544 free(adev->snd_dev_ref_cnt);
2545 free(adev);
2546 ALOGE("%s: Failed to init platform data, aborting.", __func__);
2547 *device = NULL;
2548 return -EINVAL;
2549 }
Eric Laurentc4aef752013-09-12 17:45:53 -07002550
2551 if (access(VISUALIZER_LIBRARY_PATH, R_OK) == 0) {
2552 adev->visualizer_lib = dlopen(VISUALIZER_LIBRARY_PATH, RTLD_NOW);
2553 if (adev->visualizer_lib == NULL) {
2554 ALOGE("%s: DLOPEN failed for %s", __func__, VISUALIZER_LIBRARY_PATH);
2555 } else {
2556 ALOGV("%s: DLOPEN successful for %s", __func__, VISUALIZER_LIBRARY_PATH);
2557 adev->visualizer_start_output =
2558 (int (*)(audio_io_handle_t))dlsym(adev->visualizer_lib,
2559 "visualizer_hal_start_output");
2560 adev->visualizer_stop_output =
2561 (int (*)(audio_io_handle_t))dlsym(adev->visualizer_lib,
2562 "visualizer_hal_stop_output");
2563 }
2564 }
Kiran Kandide144c82013-11-20 15:58:32 -08002565 audio_extn_listen_init(adev, SOUND_CARD);
Eric Laurentc4aef752013-09-12 17:45:53 -07002566
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002567 *device = &adev->device.common;
2568
Kiran Kandi910e1862013-10-29 13:29:42 -07002569 audio_device_ref_count++;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002570 pthread_mutex_unlock(&adev_init_lock);
2571
Eric Laurent994a6932013-07-17 11:51:42 -07002572 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08002573 return 0;
2574}
2575
2576static struct hw_module_methods_t hal_module_methods = {
2577 .open = adev_open,
2578};
2579
2580struct audio_module HAL_MODULE_INFO_SYM = {
2581 .common = {
2582 .tag = HARDWARE_MODULE_TAG,
2583 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
2584 .hal_api_version = HARDWARE_HAL_API_VERSION,
2585 .id = AUDIO_HARDWARE_MODULE_ID,
2586 .name = "QCOM Audio HAL",
2587 .author = "Code Aurora Forum",
2588 .methods = &hal_module_methods,
2589 },
2590};