blob: 1f2cdbb11c57768a65a7f75afc9ed104560f86c3 [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 Alamanda75d924d2013-02-20 21:30:08 -080022#define LOG_NDDEBUG 0
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080023
24#include <errno.h>
25#include <pthread.h>
26#include <stdint.h>
27#include <sys/time.h>
28#include <stdlib.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080029#include <math.h>
30
31#include <cutils/log.h>
32#include <cutils/str_parms.h>
33#include <cutils/properties.h>
34
Eric Laurentb23d5282013-05-14 15:27:20 -070035#include <hardware/audio_effect.h>
36#include <audio_effects/effect_aec.h>
37#include <audio_effects/effect_ns.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080038#include "audio_hw.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070039#include "platform_api.h"
40#include <platform.h>
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070041#include "audio_extn.h"
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080042
Eric Laurentb23d5282013-05-14 15:27:20 -070043struct pcm_config pcm_config_deep_buffer = {
44 .channels = 2,
45 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
46 .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
47 .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
48 .format = PCM_FORMAT_S16_LE,
49 .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
50 .stop_threshold = INT_MAX,
51 .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
52};
53
54struct pcm_config pcm_config_low_latency = {
55 .channels = 2,
56 .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
57 .period_size = LOW_LATENCY_OUTPUT_PERIOD_SIZE,
58 .period_count = LOW_LATENCY_OUTPUT_PERIOD_COUNT,
59 .format = PCM_FORMAT_S16_LE,
60 .start_threshold = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
61 .stop_threshold = INT_MAX,
62 .avail_min = LOW_LATENCY_OUTPUT_PERIOD_SIZE / 4,
63};
64
65struct pcm_config pcm_config_hdmi_multi = {
66 .channels = HDMI_MULTI_DEFAULT_CHANNEL_COUNT, /* changed when the stream is opened */
67 .rate = DEFAULT_OUTPUT_SAMPLING_RATE, /* changed when the stream is opened */
68 .period_size = HDMI_MULTI_PERIOD_SIZE,
69 .period_count = HDMI_MULTI_PERIOD_COUNT,
70 .format = PCM_FORMAT_S16_LE,
71 .start_threshold = 0,
72 .stop_threshold = INT_MAX,
73 .avail_min = 0,
74};
75
76struct pcm_config pcm_config_audio_capture = {
77 .channels = 2,
Eric Laurentb23d5282013-05-14 15:27:20 -070078 .period_count = AUDIO_CAPTURE_PERIOD_COUNT,
79 .format = PCM_FORMAT_S16_LE,
80};
81
82struct pcm_config pcm_config_voice_call = {
83 .channels = 1,
84 .rate = 8000,
85 .period_size = 160,
86 .period_count = 2,
87 .format = PCM_FORMAT_S16_LE,
88};
89
90static const char * const use_case_table[AUDIO_USECASE_MAX] = {
91 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
92 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
93 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
94 [USECASE_AUDIO_RECORD] = "audio-record",
95 [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
96 [USECASE_VOICE_CALL] = "voice-call",
97};
98
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080099
100#define STRING_TO_ENUM(string) { #string, string }
101
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800102struct string_to_enum {
103 const char *name;
104 uint32_t value;
105};
106
107static const struct string_to_enum out_channels_name_to_enum_table[] = {
108 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
109 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
110 STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
111};
112
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -0800113
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700114static int enable_audio_route(struct audio_device *adev,
115 struct audio_usecase *usecase,
116 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800117{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700118 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800119 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800120
121 if (usecase == NULL)
122 return -EINVAL;
123
124 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
125
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800126 if (usecase->type == PCM_CAPTURE)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700127 snd_device = usecase->in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800128 else
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700129 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800130
131 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700132 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700133 ALOGV("%s: apply mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700134 audio_route_apply_path(adev->audio_route, mixer_path);
135 if (update_mixer)
136 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800137
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800138 ALOGV("%s: exit", __func__);
139 return 0;
140}
141
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700142static int disable_audio_route(struct audio_device *adev,
143 struct audio_usecase *usecase,
144 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800145{
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700146 snd_device_t snd_device;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800147 char mixer_path[50];
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800148
149 if (usecase == NULL)
150 return -EINVAL;
151
152 ALOGV("%s: enter: usecase(%d)", __func__, usecase->id);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700153 if (usecase->type == PCM_CAPTURE)
154 snd_device = usecase->in_snd_device;
155 else
156 snd_device = usecase->out_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800157 strcpy(mixer_path, use_case_table[usecase->id]);
Eric Laurentb23d5282013-05-14 15:27:20 -0700158 platform_add_backend_name(mixer_path, snd_device);
Eric Laurent994a6932013-07-17 11:51:42 -0700159 ALOGV("%s: reset mixer path: %s", __func__, mixer_path);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700160 audio_route_reset_path(adev->audio_route, mixer_path);
161 if (update_mixer)
162 audio_route_update_mixer(adev->audio_route);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800163
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800164 ALOGV("%s: exit", __func__);
165 return 0;
166}
167
168static int enable_snd_device(struct audio_device *adev,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700169 snd_device_t snd_device,
170 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800171{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800172 if (snd_device < SND_DEVICE_MIN ||
173 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800174 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800175 return -EINVAL;
176 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700177
178 adev->snd_dev_ref_cnt[snd_device]++;
179 if (adev->snd_dev_ref_cnt[snd_device] > 1) {
Eric Laurent994a6932013-07-17 11:51:42 -0700180 ALOGV("%s: snd_device(%d: %s) is already active",
Eric Laurentb23d5282013-05-14 15:27:20 -0700181 __func__, snd_device, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700182 return 0;
183 }
184
Eric Laurentb23d5282013-05-14 15:27:20 -0700185 if (platform_send_audio_calibration(adev->platform, snd_device) < 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700186 adev->snd_dev_ref_cnt[snd_device]--;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800187 return -EINVAL;
188 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800189
Eric Laurent994a6932013-07-17 11:51:42 -0700190 ALOGV("%s: snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700191 snd_device, platform_get_snd_device_name(snd_device));
192 audio_route_apply_path(adev->audio_route, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700193 if (update_mixer)
194 audio_route_update_mixer(adev->audio_route);
195
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800196 return 0;
197}
198
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700199static int disable_snd_device(struct audio_device *adev,
200 snd_device_t snd_device,
201 bool update_mixer)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800202{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800203 if (snd_device < SND_DEVICE_MIN ||
204 snd_device >= SND_DEVICE_MAX) {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800205 ALOGE("%s: Invalid sound device %d", __func__, snd_device);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800206 return -EINVAL;
207 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700208 if (adev->snd_dev_ref_cnt[snd_device] <= 0) {
209 ALOGE("%s: device ref cnt is already 0", __func__);
210 return -EINVAL;
211 }
212 adev->snd_dev_ref_cnt[snd_device]--;
213 if (adev->snd_dev_ref_cnt[snd_device] == 0) {
Eric Laurent994a6932013-07-17 11:51:42 -0700214 ALOGV("%s: snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 snd_device, platform_get_snd_device_name(snd_device));
216 audio_route_reset_path(adev->audio_route, platform_get_snd_device_name(snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700217 if (update_mixer)
218 audio_route_update_mixer(adev->audio_route);
219 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800220 return 0;
221}
222
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700223static void check_usecases_codec_backend(struct audio_device *adev,
224 struct audio_usecase *uc_info,
225 snd_device_t snd_device)
226{
227 struct listnode *node;
228 struct audio_usecase *usecase;
229 bool switch_device[AUDIO_USECASE_MAX];
230 int i, num_uc_to_switch = 0;
231
232 /*
233 * This function is to make sure that all the usecases that are active on
234 * the hardware codec backend are always routed to any one device that is
235 * handled by the hardware codec.
236 * For example, if low-latency and deep-buffer usecases are currently active
237 * on speaker and out_set_parameters(headset) is received on low-latency
238 * output, then we have to make sure deep-buffer is also switched to headset,
239 * because of the limitation that both the devices cannot be enabled
240 * at the same time as they share the same backend.
241 */
242 /* Disable all the usecases on the shared backend other than the
243 specified usecase */
244 for (i = 0; i < AUDIO_USECASE_MAX; i++)
245 switch_device[i] = false;
246
247 list_for_each(node, &adev->usecase_list) {
248 usecase = node_to_item(node, struct audio_usecase, list);
249 if (usecase->type != PCM_CAPTURE &&
250 usecase != uc_info &&
251 usecase->out_snd_device != snd_device &&
252 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
253 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
254 __func__, use_case_table[usecase->id],
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 platform_get_snd_device_name(usecase->out_snd_device));
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700256 disable_audio_route(adev, usecase, false);
257 switch_device[usecase->id] = true;
258 num_uc_to_switch++;
259 }
260 }
261
262 if (num_uc_to_switch) {
263 /* Make sure all the streams are de-routed before disabling the device */
264 audio_route_update_mixer(adev->audio_route);
265
266 list_for_each(node, &adev->usecase_list) {
267 usecase = node_to_item(node, struct audio_usecase, list);
268 if (switch_device[usecase->id]) {
269 disable_snd_device(adev, usecase->out_snd_device, false);
270 enable_snd_device(adev, snd_device, false);
271 }
272 }
273
274 /* Make sure new snd device is enabled before re-routing the streams */
275 audio_route_update_mixer(adev->audio_route);
276
277 /* Re-route all the usecases on the shared backend other than the
278 specified usecase to new snd devices */
279 list_for_each(node, &adev->usecase_list) {
280 usecase = node_to_item(node, struct audio_usecase, list);
281 /* Update the out_snd_device only before enabling the audio route */
282 if (switch_device[usecase->id] ) {
283 usecase->out_snd_device = snd_device;
284 enable_audio_route(adev, usecase, false);
285 }
286 }
287
288 audio_route_update_mixer(adev->audio_route);
289 }
290}
291
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700292static void check_and_route_capture_usecases(struct audio_device *adev,
293 struct audio_usecase *uc_info,
294 snd_device_t snd_device)
295{
296 struct listnode *node;
297 struct audio_usecase *usecase;
298 bool switch_device[AUDIO_USECASE_MAX];
299 int i, num_uc_to_switch = 0;
300
301 /*
302 * This function is to make sure that all the active capture usecases
303 * are always routed to the same input sound device.
304 * For example, if audio-record and voice-call usecases are currently
305 * active on speaker(rx) and speaker-mic (tx) and out_set_parameters(earpiece)
306 * is received for voice call then we have to make sure that audio-record
307 * usecase is also switched to earpiece i.e. voice-dmic-ef,
308 * because of the limitation that two devices cannot be enabled
309 * at the same time if they share the same backend.
310 */
311 for (i = 0; i < AUDIO_USECASE_MAX; i++)
312 switch_device[i] = false;
313
314 list_for_each(node, &adev->usecase_list) {
315 usecase = node_to_item(node, struct audio_usecase, list);
316 if (usecase->type != PCM_PLAYBACK &&
317 usecase != uc_info &&
318 usecase->in_snd_device != snd_device) {
319 ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
320 __func__, use_case_table[usecase->id],
Devin Kim1e5f3532013-08-09 07:48:29 -0700321 platform_get_snd_device_name(usecase->in_snd_device));
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700322 disable_audio_route(adev, usecase, false);
323 switch_device[usecase->id] = true;
324 num_uc_to_switch++;
325 }
326 }
327
328 if (num_uc_to_switch) {
329 /* Make sure all the streams are de-routed before disabling the device */
330 audio_route_update_mixer(adev->audio_route);
331
332 list_for_each(node, &adev->usecase_list) {
333 usecase = node_to_item(node, struct audio_usecase, list);
334 if (switch_device[usecase->id]) {
335 disable_snd_device(adev, usecase->in_snd_device, false);
336 enable_snd_device(adev, snd_device, false);
337 }
338 }
339
340 /* Make sure new snd device is enabled before re-routing the streams */
341 audio_route_update_mixer(adev->audio_route);
342
343 /* Re-route all the usecases on the shared backend other than the
344 specified usecase to new snd devices */
345 list_for_each(node, &adev->usecase_list) {
346 usecase = node_to_item(node, struct audio_usecase, list);
347 /* Update the in_snd_device only before enabling the audio route */
348 if (switch_device[usecase->id] ) {
349 usecase->in_snd_device = snd_device;
350 enable_audio_route(adev, usecase, false);
351 }
352 }
353
354 audio_route_update_mixer(adev->audio_route);
355 }
356}
357
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800358
359/* must be called with hw device mutex locked */
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700360static int read_hdmi_channel_masks(struct stream_out *out)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800361{
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700362 int ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -0700363 int channels = platform_edid_get_max_channels(out->dev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800364
365 switch (channels) {
366 /*
367 * Do not handle stereo output in Multi-channel cases
368 * Stereo case is handled in normal playback path
369 */
370 case 6:
371 ALOGV("%s: HDMI supports 5.1", __func__);
372 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
373 break;
374 case 8:
375 ALOGV("%s: HDMI supports 5.1 and 7.1 channels", __func__);
376 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_5POINT1;
377 out->supported_channel_masks[1] = AUDIO_CHANNEL_OUT_7POINT1;
378 break;
379 default:
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700380 ALOGE("HDMI does not support multi channel playback");
381 ret = -ENOSYS;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800382 break;
383 }
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -0700384 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800385}
386
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700387static struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
388 audio_usecase_t uc_id)
389{
390 struct audio_usecase *usecase;
391 struct listnode *node;
392
393 list_for_each(node, &adev->usecase_list) {
394 usecase = node_to_item(node, struct audio_usecase, list);
395 if (usecase->id == uc_id)
396 return usecase;
397 }
398 return NULL;
399}
400
401static int select_devices(struct audio_device *adev,
402 audio_usecase_t uc_id)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800403{
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800404 snd_device_t out_snd_device = SND_DEVICE_NONE;
405 snd_device_t in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700406 struct audio_usecase *usecase = NULL;
407 struct audio_usecase *vc_usecase = NULL;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800408 struct listnode *node;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700409 int status = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800410
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700411 usecase = get_usecase_from_list(adev, uc_id);
412 if (usecase == NULL) {
413 ALOGE("%s: Could not find the usecase(%d)", __func__, uc_id);
414 return -EINVAL;
415 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800416
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700417 if (usecase->type == VOICE_CALL) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700418 out_snd_device = platform_get_output_snd_device(adev->platform,
419 usecase->stream.out->devices);
420 in_snd_device = platform_get_input_snd_device(adev->platform, usecase->stream.out->devices);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700421 usecase->devices = usecase->stream.out->devices;
422 } else {
423 /*
424 * If the voice call is active, use the sound devices of voice call usecase
425 * so that it would not result any device switch. All the usecases will
426 * be switched to new device when select_devices() is called for voice call
427 * usecase. This is to avoid switching devices for voice call when
428 * check_usecases_codec_backend() is called below.
429 */
430 if (adev->in_call) {
431 vc_usecase = get_usecase_from_list(adev, USECASE_VOICE_CALL);
432 if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
433 in_snd_device = vc_usecase->in_snd_device;
434 out_snd_device = vc_usecase->out_snd_device;
435 }
436 }
437 if (usecase->type == PCM_PLAYBACK) {
438 usecase->devices = usecase->stream.out->devices;
439 in_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700440 if (out_snd_device == SND_DEVICE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700441 out_snd_device = platform_get_output_snd_device(adev->platform,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700442 usecase->stream.out->devices);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700443 if (usecase->stream.out == adev->primary_output &&
444 adev->active_input &&
445 adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
446 select_devices(adev, adev->active_input->usecase);
447 }
448 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700449 } else if (usecase->type == PCM_CAPTURE) {
450 usecase->devices = usecase->stream.in->device;
451 out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700452 if (in_snd_device == SND_DEVICE_NONE) {
453 if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
454 adev->primary_output && !adev->primary_output->standby) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700455 in_snd_device = platform_get_input_snd_device(adev->platform,
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700456 adev->primary_output->devices);
457 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -0700458 in_snd_device = platform_get_input_snd_device(adev->platform,
459 AUDIO_DEVICE_NONE);
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -0700460 }
461 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700462 }
463 }
464
465 if (out_snd_device == usecase->out_snd_device &&
466 in_snd_device == usecase->in_snd_device) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800467 return 0;
468 }
469
sangwoobc677242013-08-08 16:53:43 +0900470 ALOGD("%s: out_snd_device(%d: %s) in_snd_device(%d: %s)", __func__,
Eric Laurentb23d5282013-05-14 15:27:20 -0700471 out_snd_device, platform_get_snd_device_name(out_snd_device),
472 in_snd_device, platform_get_snd_device_name(in_snd_device));
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800473
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800474 /*
475 * Limitation: While in call, to do a device switch we need to disable
476 * and enable both RX and TX devices though one of them is same as current
477 * device.
478 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700479 if (usecase->type == VOICE_CALL) {
480 status = platform_switch_voice_call_device_pre(adev->platform);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800481 }
482
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700483 /* Disable current sound devices */
484 if (usecase->out_snd_device != SND_DEVICE_NONE) {
485 disable_audio_route(adev, usecase, true);
486 disable_snd_device(adev, usecase->out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800487 }
488
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700489 if (usecase->in_snd_device != SND_DEVICE_NONE) {
490 disable_audio_route(adev, usecase, true);
491 disable_snd_device(adev, usecase->in_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800492 }
493
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700494 /* Enable new sound devices */
495 if (out_snd_device != SND_DEVICE_NONE) {
496 if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
497 check_usecases_codec_backend(adev, usecase, out_snd_device);
498 enable_snd_device(adev, out_snd_device, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800499 }
500
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700501 if (in_snd_device != SND_DEVICE_NONE) {
502 check_and_route_capture_usecases(adev, usecase, in_snd_device);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700503 enable_snd_device(adev, in_snd_device, false);
Ravi Kumar Alamandac4ba7432013-06-05 14:11:39 -0700504 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700505
Eric Laurentb23d5282013-05-14 15:27:20 -0700506 if (usecase->type == VOICE_CALL)
507 status = platform_switch_voice_call_device_post(adev->platform,
508 out_snd_device,
509 in_snd_device);
Ravi Kumar Alamanda610e8cc2013-02-12 01:42:38 -0800510
sangwoo170731f2013-06-08 15:36:36 +0900511 audio_route_update_mixer(adev->audio_route);
512
513 usecase->in_snd_device = in_snd_device;
514 usecase->out_snd_device = out_snd_device;
515
516 enable_audio_route(adev, usecase, true);
517
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800518 return status;
519}
520
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800521static int stop_input_stream(struct stream_in *in)
522{
523 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800524 struct audio_usecase *uc_info;
525 struct audio_device *adev = in->dev;
526
Eric Laurentc8400632013-02-14 19:04:54 -0800527 adev->active_input = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800528
Eric Laurent994a6932013-07-17 11:51:42 -0700529 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700530 in->usecase, use_case_table[in->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800531 uc_info = get_usecase_from_list(adev, in->usecase);
532 if (uc_info == NULL) {
533 ALOGE("%s: Could not find the usecase (%d) in the list",
534 __func__, in->usecase);
535 return -EINVAL;
536 }
537
Eric Laurent150dbfe2013-02-27 14:31:02 -0800538 /* 1. Disable stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700539 disable_audio_route(adev, uc_info, true);
540
541 /* 2. Disable the tx device */
542 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800543
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800544 list_remove(&uc_info->list);
545 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800546
Eric Laurent994a6932013-07-17 11:51:42 -0700547 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800548 return ret;
549}
550
551int start_input_stream(struct stream_in *in)
552{
553 /* 1. Enable output device and stream routing controls */
Eric Laurentc8400632013-02-14 19:04:54 -0800554 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800555 struct audio_usecase *uc_info;
556 struct audio_device *adev = in->dev;
557
Eric Laurent994a6932013-07-17 11:51:42 -0700558 ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
Eric Laurentb23d5282013-05-14 15:27:20 -0700559 in->pcm_device_id = platform_get_pcm_device_id(in->usecase, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800560 if (in->pcm_device_id < 0) {
561 ALOGE("%s: Could not find PCM device id for the usecase(%d)",
562 __func__, in->usecase);
Eric Laurentc8400632013-02-14 19:04:54 -0800563 ret = -EINVAL;
564 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800565 }
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700566
567 adev->active_input = in;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800568 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
569 uc_info->id = in->usecase;
570 uc_info->type = PCM_CAPTURE;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800571 uc_info->stream.in = in;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700572 uc_info->devices = in->device;
573 uc_info->in_snd_device = SND_DEVICE_NONE;
574 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800575
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800576 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700577 select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800578
Eric Laurentc8400632013-02-14 19:04:54 -0800579 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d), channels %d",
580 __func__, SOUND_CARD, in->pcm_device_id, in->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800581 in->pcm = pcm_open(SOUND_CARD, in->pcm_device_id,
582 PCM_IN, &in->config);
583 if (in->pcm && !pcm_is_ready(in->pcm)) {
584 ALOGE("%s: %s", __func__, pcm_get_error(in->pcm));
585 pcm_close(in->pcm);
586 in->pcm = NULL;
Eric Laurentc8400632013-02-14 19:04:54 -0800587 ret = -EIO;
588 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800589 }
Eric Laurent994a6932013-07-17 11:51:42 -0700590 ALOGV("%s: exit", __func__);
Eric Laurentc8400632013-02-14 19:04:54 -0800591 return ret;
592
593error_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800594 stop_input_stream(in);
Eric Laurentc8400632013-02-14 19:04:54 -0800595
596error_config:
597 adev->active_input = NULL;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700598 ALOGD("%s: exit: status(%d)", __func__, ret);
Eric Laurentc8400632013-02-14 19:04:54 -0800599
600 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800601}
602
603static int stop_output_stream(struct stream_out *out)
604{
605 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800606 struct audio_usecase *uc_info;
607 struct audio_device *adev = out->dev;
608
Eric Laurent994a6932013-07-17 11:51:42 -0700609 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700610 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800611 uc_info = get_usecase_from_list(adev, out->usecase);
612 if (uc_info == NULL) {
613 ALOGE("%s: Could not find the usecase (%d) in the list",
614 __func__, out->usecase);
615 return -EINVAL;
616 }
617
Eric Laurent150dbfe2013-02-27 14:31:02 -0800618 /* 1. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700619 disable_audio_route(adev, uc_info, true);
620
621 /* 2. Disable the rx device */
622 disable_snd_device(adev, uc_info->out_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800623
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800624 list_remove(&uc_info->list);
625 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800626
Eric Laurent994a6932013-07-17 11:51:42 -0700627 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800628 return ret;
629}
630
631int start_output_stream(struct stream_out *out)
632{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800633 int ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800634 struct audio_usecase *uc_info;
635 struct audio_device *adev = out->dev;
636
Eric Laurent994a6932013-07-17 11:51:42 -0700637 ALOGV("%s: enter: usecase(%d: %s) devices(%#x)",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700638 __func__, out->usecase, use_case_table[out->usecase], out->devices);
Eric Laurentb23d5282013-05-14 15:27:20 -0700639 out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800640 if (out->pcm_device_id < 0) {
641 ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
642 __func__, out->pcm_device_id, out->usecase);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800643 ret = -EINVAL;
644 goto error_config;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800645 }
646
647 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
648 uc_info->id = out->usecase;
649 uc_info->type = PCM_PLAYBACK;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800650 uc_info->stream.out = out;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700651 uc_info->devices = out->devices;
652 uc_info->in_snd_device = SND_DEVICE_NONE;
653 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800654
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800655 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800656
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700657 select_devices(adev, out->usecase);
658
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800659 ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
660 __func__, 0, out->pcm_device_id);
661 out->pcm = pcm_open(SOUND_CARD, out->pcm_device_id,
662 PCM_OUT, &out->config);
663 if (out->pcm && !pcm_is_ready(out->pcm)) {
664 ALOGE("%s: %s", __func__, pcm_get_error(out->pcm));
665 pcm_close(out->pcm);
666 out->pcm = NULL;
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800667 ret = -EIO;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700668 goto error_pcm_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800669 }
Eric Laurent994a6932013-07-17 11:51:42 -0700670 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800671 return 0;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700672error_pcm_open:
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800673 stop_output_stream(out);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800674error_config:
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800675 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800676}
677
678static int stop_voice_call(struct audio_device *adev)
679{
680 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800681 struct audio_usecase *uc_info;
682
Eric Laurent994a6932013-07-17 11:51:42 -0700683 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800684 adev->in_call = false;
Eric Laurentb23d5282013-05-14 15:27:20 -0700685
686 ret = platform_stop_voice_call(adev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800687
688 /* 1. Close the PCM devices */
689 if (adev->voice_call_rx) {
690 pcm_close(adev->voice_call_rx);
691 adev->voice_call_rx = NULL;
692 }
693 if (adev->voice_call_tx) {
694 pcm_close(adev->voice_call_tx);
695 adev->voice_call_tx = NULL;
696 }
697
698 uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
699 if (uc_info == NULL) {
700 ALOGE("%s: Could not find the usecase (%d) in the list",
701 __func__, USECASE_VOICE_CALL);
702 return -EINVAL;
703 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800704
705 /* 2. Get and set stream specific mixer controls */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700706 disable_audio_route(adev, uc_info, true);
707
708 /* 3. Disable the rx and tx devices */
709 disable_snd_device(adev, uc_info->out_snd_device, false);
710 disable_snd_device(adev, uc_info->in_snd_device, true);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800711
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800712 list_remove(&uc_info->list);
713 free(uc_info);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800714
Eric Laurent994a6932013-07-17 11:51:42 -0700715 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800716 return ret;
717}
718
719static int start_voice_call(struct audio_device *adev)
720{
721 int i, ret = 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800722 struct audio_usecase *uc_info;
723 int pcm_dev_rx_id, pcm_dev_tx_id;
724
Eric Laurent994a6932013-07-17 11:51:42 -0700725 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800726
727 uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
728 uc_info->id = USECASE_VOICE_CALL;
729 uc_info->type = VOICE_CALL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800730 uc_info->stream.out = adev->primary_output;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700731 uc_info->devices = adev->primary_output->devices;
732 uc_info->in_snd_device = SND_DEVICE_NONE;
733 uc_info->out_snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800734
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800735 list_add_tail(&adev->usecase_list, &uc_info->list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800736
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700737 select_devices(adev, USECASE_VOICE_CALL);
738
Eric Laurentb23d5282013-05-14 15:27:20 -0700739 pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
740 pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800741
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800742 if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
743 ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
744 __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800745 ret = -EIO;
746 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800747 }
748
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800749 ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800750 __func__, SOUND_CARD, pcm_dev_rx_id);
751 adev->voice_call_rx = pcm_open(SOUND_CARD,
752 pcm_dev_rx_id,
753 PCM_OUT, &pcm_config_voice_call);
754 if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
755 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800756 ret = -EIO;
757 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800758 }
759
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800760 ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800761 __func__, SOUND_CARD, pcm_dev_tx_id);
762 adev->voice_call_tx = pcm_open(SOUND_CARD,
763 pcm_dev_tx_id,
764 PCM_IN, &pcm_config_voice_call);
765 if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
766 ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800767 ret = -EIO;
768 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800769 }
770 pcm_start(adev->voice_call_rx);
771 pcm_start(adev->voice_call_tx);
772
Eric Laurentb23d5282013-05-14 15:27:20 -0700773 ret = platform_start_voice_call(adev->platform);
774 if (ret < 0) {
775 ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
776 goto error_start_voice;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800777 }
778
779 adev->in_call = true;
Ravi Kumar Alamanda8b9c5c82013-02-20 16:59:34 -0800780 return 0;
781
782error_start_voice:
783 stop_voice_call(adev);
784
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -0800785 ALOGD("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800786 return ret;
787}
788
789static int check_input_parameters(uint32_t sample_rate,
790 audio_format_t format,
791 int channel_count)
792{
793 if (format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL;
794
795 if ((channel_count < 1) || (channel_count > 2)) return -EINVAL;
796
797 switch (sample_rate) {
798 case 8000:
799 case 11025:
800 case 12000:
801 case 16000:
802 case 22050:
803 case 24000:
804 case 32000:
805 case 44100:
806 case 48000:
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
815static size_t get_input_buffer_size(uint32_t sample_rate,
816 audio_format_t format,
817 int channel_count)
818{
819 size_t size = 0;
820
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -0700821 if (check_input_parameters(sample_rate, format, channel_count) != 0)
822 return 0;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800823
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -0700824 size = (sample_rate * AUDIO_CAPTURE_PERIOD_DURATION_MSEC) / 1000;
825 /* ToDo: should use frame_size computed based on the format and
826 channel_count here. */
827 size *= sizeof(short) * channel_count;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800828
Ravi Kumar Alamanda33d33062013-06-11 14:40:01 -0700829 /* make sure the size is multiple of 64 */
830 size += 0x3f;
831 size &= ~0x3f;
832
833 return size;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800834}
835
836static uint32_t out_get_sample_rate(const struct audio_stream *stream)
837{
838 struct stream_out *out = (struct stream_out *)stream;
839
840 return out->config.rate;
841}
842
843static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
844{
845 return -ENOSYS;
846}
847
848static size_t out_get_buffer_size(const struct audio_stream *stream)
849{
850 struct stream_out *out = (struct stream_out *)stream;
851
852 return out->config.period_size * audio_stream_frame_size(stream);
853}
854
855static uint32_t out_get_channels(const struct audio_stream *stream)
856{
857 struct stream_out *out = (struct stream_out *)stream;
858
859 return out->channel_mask;
860}
861
862static audio_format_t out_get_format(const struct audio_stream *stream)
863{
864 return AUDIO_FORMAT_PCM_16_BIT;
865}
866
867static int out_set_format(struct audio_stream *stream, audio_format_t format)
868{
869 return -ENOSYS;
870}
871
872static int out_standby(struct audio_stream *stream)
873{
874 struct stream_out *out = (struct stream_out *)stream;
875 struct audio_device *adev = out->dev;
Eric Laurent994a6932013-07-17 11:51:42 -0700876 ALOGV("%s: enter: usecase(%d: %s)", __func__,
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700877 out->usecase, use_case_table[out->usecase]);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800878 pthread_mutex_lock(&out->lock);
879
880 if (!out->standby) {
881 out->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800882 if (out->pcm) {
883 pcm_close(out->pcm);
884 out->pcm = NULL;
885 }
886 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800887 stop_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800888 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800889 }
890 pthread_mutex_unlock(&out->lock);
Eric Laurent994a6932013-07-17 11:51:42 -0700891 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800892 return 0;
893}
894
895static int out_dump(const struct audio_stream *stream, int fd)
896{
897 return 0;
898}
899
900static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
901{
902 struct stream_out *out = (struct stream_out *)stream;
903 struct audio_device *adev = out->dev;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800904 struct audio_usecase *usecase;
905 struct listnode *node;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800906 struct str_parms *parms;
907 char value[32];
908 int ret, val = 0;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800909 bool select_new_device = false;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800910
sangwoobc677242013-08-08 16:53:43 +0900911 ALOGD("%s: enter: usecase(%d: %s) kvpairs: %s",
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700912 __func__, out->usecase, use_case_table[out->usecase], kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800913 parms = str_parms_create_str(kvpairs);
914 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
915 if (ret >= 0) {
916 val = atoi(value);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800917 pthread_mutex_lock(&out->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800918 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800919
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700920 /*
921 * When HDMI cable is unplugged the music playback is paused and
922 * the policy manager sends routing=0. But the audioflinger
923 * continues to write data until standby time (3sec).
924 * As the HDMI core is turned off, the write gets blocked.
925 * Avoid this by routing audio to speaker until standby.
926 */
927 if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL &&
928 val == AUDIO_DEVICE_NONE) {
929 val = AUDIO_DEVICE_OUT_SPEAKER;
930 }
931
932 /*
933 * select_devices() call below switches all the usecases on the same
934 * backend to the new device. Refer to check_usecases_codec_backend() in
935 * the select_devices(). But how do we undo this?
936 *
937 * For example, music playback is active on headset (deep-buffer usecase)
938 * and if we go to ringtones and select a ringtone, low-latency usecase
939 * will be started on headset+speaker. As we can't enable headset+speaker
940 * and headset devices at the same time, select_devices() switches the music
941 * playback to headset+speaker while starting low-lateny usecase for ringtone.
942 * So when the ringtone playback is completed, how do we undo the same?
943 *
944 * We are relying on the out_set_parameters() call on deep-buffer output,
945 * once the ringtone playback is ended.
946 * NOTE: We should not check if the current devices are same as new devices.
947 * Because select_devices() must be called to switch back the music
948 * playback to headset.
949 */
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800950 if (val != 0) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700951 out->devices = val;
952
953 if (!out->standby)
954 select_devices(adev, out->usecase);
955
956 if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call &&
957 (out == adev->primary_output)) {
958 start_voice_call(adev);
959 } else if ((adev->mode == AUDIO_MODE_IN_CALL) && adev->in_call &&
960 (out == adev->primary_output)) {
961 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800962 }
963 }
964
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700965 if ((adev->mode != AUDIO_MODE_IN_CALL) && adev->in_call &&
966 (out == adev->primary_output)) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800967 stop_voice_call(adev);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800968 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800969
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800970 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800971 pthread_mutex_unlock(&out->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800972 }
973 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -0700974 ALOGV("%s: exit: code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800975 return ret;
976}
977
978static char* out_get_parameters(const struct audio_stream *stream, const char *keys)
979{
980 struct stream_out *out = (struct stream_out *)stream;
981 struct str_parms *query = str_parms_create_str(keys);
982 char *str;
983 char value[256];
984 struct str_parms *reply = str_parms_create();
985 size_t i, j;
986 int ret;
987 bool first = true;
Eric Laurent994a6932013-07-17 11:51:42 -0700988 ALOGV("%s: enter: keys - %s", __func__, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800989 ret = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value, sizeof(value));
990 if (ret >= 0) {
991 value[0] = '\0';
992 i = 0;
993 while (out->supported_channel_masks[i] != 0) {
994 for (j = 0; j < ARRAY_SIZE(out_channels_name_to_enum_table); j++) {
995 if (out_channels_name_to_enum_table[j].value == out->supported_channel_masks[i]) {
996 if (!first) {
997 strcat(value, "|");
998 }
999 strcat(value, out_channels_name_to_enum_table[j].name);
1000 first = false;
1001 break;
1002 }
1003 }
1004 i++;
1005 }
1006 str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
1007 str = str_parms_to_str(reply);
1008 } else {
1009 str = strdup(keys);
1010 }
1011 str_parms_destroy(query);
1012 str_parms_destroy(reply);
Eric Laurent994a6932013-07-17 11:51:42 -07001013 ALOGV("%s: exit: returns - %s", __func__, str);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001014 return str;
1015}
1016
1017static uint32_t out_get_latency(const struct audio_stream_out *stream)
1018{
1019 struct stream_out *out = (struct stream_out *)stream;
1020
1021 return (out->config.period_count * out->config.period_size * 1000) / (out->config.rate);
1022}
1023
1024static int out_set_volume(struct audio_stream_out *stream, float left,
1025 float right)
1026{
Eric Laurenta9024de2013-04-04 09:19:12 -07001027 struct stream_out *out = (struct stream_out *)stream;
1028 if (out->usecase == USECASE_AUDIO_PLAYBACK_MULTI_CH) {
1029 /* only take left channel into account: the API is for stereo anyway */
1030 out->muted = (left == 0.0f);
1031 return 0;
1032 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001033 return -ENOSYS;
1034}
1035
1036static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
1037 size_t bytes)
1038{
1039 struct stream_out *out = (struct stream_out *)stream;
1040 struct audio_device *adev = out->dev;
1041 int i, ret = -1;
1042
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001043 pthread_mutex_lock(&out->lock);
1044 if (out->standby) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001045 out->standby = false;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001046 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001047 ret = start_output_stream(out);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001048 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001049 if (ret != 0) {
Ravi Kumar Alamanda59d296d2013-05-02 11:25:27 -07001050 out->standby = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001051 goto exit;
1052 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001053 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001054
1055 if (out->pcm) {
Eric Laurenta9024de2013-04-04 09:19:12 -07001056 if (out->muted)
1057 memset((void *)buffer, 0, bytes);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001058 //ALOGV("%s: writing buffer (%d bytes) to pcm device", __func__, bytes);
1059 ret = pcm_write(out->pcm, (void *)buffer, bytes);
1060 }
1061
1062exit:
1063 pthread_mutex_unlock(&out->lock);
1064
1065 if (ret != 0) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001066 if (out->pcm)
1067 ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm));
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001068 out_standby(&out->stream.common);
1069 usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
1070 out_get_sample_rate(&out->stream.common));
1071 }
1072 return bytes;
1073}
1074
1075static int out_get_render_position(const struct audio_stream_out *stream,
1076 uint32_t *dsp_frames)
1077{
1078 return -EINVAL;
1079}
1080
1081static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1082{
1083 return 0;
1084}
1085
1086static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
1087{
1088 return 0;
1089}
1090
1091static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
1092 int64_t *timestamp)
1093{
1094 return -EINVAL;
1095}
1096
1097/** audio_stream_in implementation **/
1098static uint32_t in_get_sample_rate(const struct audio_stream *stream)
1099{
1100 struct stream_in *in = (struct stream_in *)stream;
1101
1102 return in->config.rate;
1103}
1104
1105static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
1106{
1107 return -ENOSYS;
1108}
1109
1110static size_t in_get_buffer_size(const struct audio_stream *stream)
1111{
1112 struct stream_in *in = (struct stream_in *)stream;
1113
1114 return in->config.period_size * audio_stream_frame_size(stream);
1115}
1116
1117static uint32_t in_get_channels(const struct audio_stream *stream)
1118{
1119 struct stream_in *in = (struct stream_in *)stream;
1120
1121 return in->channel_mask;
1122}
1123
1124static audio_format_t in_get_format(const struct audio_stream *stream)
1125{
1126 return AUDIO_FORMAT_PCM_16_BIT;
1127}
1128
1129static int in_set_format(struct audio_stream *stream, audio_format_t format)
1130{
1131 return -ENOSYS;
1132}
1133
1134static int in_standby(struct audio_stream *stream)
1135{
1136 struct stream_in *in = (struct stream_in *)stream;
1137 struct audio_device *adev = in->dev;
1138 int status = 0;
Eric Laurent994a6932013-07-17 11:51:42 -07001139 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001140 pthread_mutex_lock(&in->lock);
1141 if (!in->standby) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001142 in->standby = true;
Eric Laurent150dbfe2013-02-27 14:31:02 -08001143 if (in->pcm) {
1144 pcm_close(in->pcm);
1145 in->pcm = NULL;
1146 }
1147 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001148 status = stop_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001149 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001150 }
1151 pthread_mutex_unlock(&in->lock);
Eric Laurent994a6932013-07-17 11:51:42 -07001152 ALOGV("%s: exit: status(%d)", __func__, status);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001153 return status;
1154}
1155
1156static int in_dump(const struct audio_stream *stream, int fd)
1157{
1158 return 0;
1159}
1160
1161static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
1162{
1163 struct stream_in *in = (struct stream_in *)stream;
1164 struct audio_device *adev = in->dev;
1165 struct str_parms *parms;
1166 char *str;
1167 char value[32];
1168 int ret, val = 0;
1169
Eric Laurent994a6932013-07-17 11:51:42 -07001170 ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001171 parms = str_parms_create_str(kvpairs);
1172
1173 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
1174
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001175 pthread_mutex_lock(&in->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001176 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001177 if (ret >= 0) {
1178 val = atoi(value);
1179 /* no audio source uses val == 0 */
1180 if ((in->source != val) && (val != 0)) {
1181 in->source = val;
1182 }
1183 }
1184
1185 ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
1186 if (ret >= 0) {
1187 val = atoi(value);
1188 if ((in->device != val) && (val != 0)) {
1189 in->device = val;
1190 /* If recording is in progress, change the tx device to new device */
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001191 if (!in->standby)
1192 ret = select_devices(adev, in->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001193 }
1194 }
1195
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001196 pthread_mutex_unlock(&adev->lock);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001197 pthread_mutex_unlock(&in->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001198
1199 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001200 ALOGV("%s: exit: status(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001201 return ret;
1202}
1203
1204static char* in_get_parameters(const struct audio_stream *stream,
1205 const char *keys)
1206{
1207 return strdup("");
1208}
1209
1210static int in_set_gain(struct audio_stream_in *stream, float gain)
1211{
1212 return 0;
1213}
1214
1215static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
1216 size_t bytes)
1217{
1218 struct stream_in *in = (struct stream_in *)stream;
1219 struct audio_device *adev = in->dev;
1220 int i, ret = -1;
1221
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001222 pthread_mutex_lock(&in->lock);
1223 if (in->standby) {
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001224 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001225 ret = start_input_stream(in);
Eric Laurent150dbfe2013-02-27 14:31:02 -08001226 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001227 if (ret != 0) {
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001228 goto exit;
1229 }
1230 in->standby = 0;
1231 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001232
1233 if (in->pcm) {
1234 ret = pcm_read(in->pcm, buffer, bytes);
1235 }
1236
1237 /*
1238 * Instead of writing zeroes here, we could trust the hardware
1239 * to always provide zeroes when muted.
1240 */
1241 if (ret == 0 && adev->mic_mute)
1242 memset(buffer, 0, bytes);
1243
1244exit:
1245 pthread_mutex_unlock(&in->lock);
1246
1247 if (ret != 0) {
1248 in_standby(&in->stream.common);
1249 ALOGV("%s: read failed - sleeping for buffer duration", __func__);
1250 usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
1251 in_get_sample_rate(&in->stream.common));
1252 }
1253 return bytes;
1254}
1255
1256static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
1257{
1258 return 0;
1259}
1260
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001261static int add_remove_audio_effect(const struct audio_stream *stream,
1262 effect_handle_t effect,
1263 bool enable)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001264{
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001265 struct stream_in *in = (struct stream_in *)stream;
1266 int status = 0;
1267 effect_descriptor_t desc;
1268
1269 status = (*effect)->get_descriptor(effect, &desc);
1270 if (status != 0)
1271 return status;
1272
1273 pthread_mutex_lock(&in->lock);
1274 pthread_mutex_lock(&in->dev->lock);
1275 if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
1276 in->enable_aec != enable &&
1277 (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
1278 in->enable_aec = enable;
1279 if (!in->standby)
1280 select_devices(in->dev, in->usecase);
1281 }
1282 pthread_mutex_unlock(&in->dev->lock);
1283 pthread_mutex_unlock(&in->lock);
1284
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001285 return 0;
1286}
1287
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001288static int in_add_audio_effect(const struct audio_stream *stream,
1289 effect_handle_t effect)
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001290{
Eric Laurent994a6932013-07-17 11:51:42 -07001291 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001292 return add_remove_audio_effect(stream, effect, true);
1293}
1294
1295static int in_remove_audio_effect(const struct audio_stream *stream,
1296 effect_handle_t effect)
1297{
Eric Laurent994a6932013-07-17 11:51:42 -07001298 ALOGV("%s: effect %p", __func__, effect);
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -07001299 return add_remove_audio_effect(stream, effect, false);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001300}
1301
1302static int adev_open_output_stream(struct audio_hw_device *dev,
1303 audio_io_handle_t handle,
1304 audio_devices_t devices,
1305 audio_output_flags_t flags,
1306 struct audio_config *config,
1307 struct audio_stream_out **stream_out)
1308{
1309 struct audio_device *adev = (struct audio_device *)dev;
1310 struct stream_out *out;
1311 int i, ret;
1312
Eric Laurent994a6932013-07-17 11:51:42 -07001313 ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001314 __func__, config->sample_rate, config->channel_mask, devices, flags);
1315 *stream_out = NULL;
1316 out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
1317
1318 if (devices == AUDIO_DEVICE_NONE)
1319 devices = AUDIO_DEVICE_OUT_SPEAKER;
1320
1321 out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_STEREO;
1322 out->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
1323 out->flags = flags;
1324 out->devices = devices;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001325 out->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001326
1327 /* Init use case and pcm_config */
1328 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
1329 out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001330 pthread_mutex_lock(&adev->lock);
1331 ret = read_hdmi_channel_masks(out);
1332 pthread_mutex_unlock(&adev->lock);
1333 if (ret != 0) {
1334 /* If HDMI does not support multi channel playback, set the default */
1335 out->config.channels = popcount(out->channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001336 platform_set_hdmi_channels(adev->platform, out->config.channels);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001337 goto error_open;
1338 }
1339
1340 if (config->sample_rate == 0)
1341 config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
1342 if (config->channel_mask == 0)
1343 config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
1344
1345 out->channel_mask = config->channel_mask;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001346 out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
1347 out->config = pcm_config_hdmi_multi;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001348 out->config.rate = config->sample_rate;
1349 out->config.channels = popcount(out->channel_mask);
1350 out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
Eric Laurentb23d5282013-05-14 15:27:20 -07001351 platform_set_hdmi_channels(adev->platform, out->config.channels);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001352 } else if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) {
1353 out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
1354 out->config = pcm_config_deep_buffer;
1355 } else {
1356 out->usecase = USECASE_AUDIO_PLAYBACK_LOW_LATENCY;
1357 out->config = pcm_config_low_latency;
1358 }
1359
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001360 if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {
1361 if(adev->primary_output == NULL)
1362 adev->primary_output = out;
1363 else {
1364 ALOGE("%s: Primary output is already opened", __func__);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001365 ret = -EEXIST;
1366 goto error_open;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001367 }
1368 }
1369
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001370 /* Check if this usecase is already existing */
1371 pthread_mutex_lock(&adev->lock);
1372 if (get_usecase_from_list(adev, out->usecase) != NULL) {
1373 ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001374 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001375 ret = -EEXIST;
1376 goto error_open;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001377 }
1378 pthread_mutex_unlock(&adev->lock);
1379
1380 out->stream.common.get_sample_rate = out_get_sample_rate;
1381 out->stream.common.set_sample_rate = out_set_sample_rate;
1382 out->stream.common.get_buffer_size = out_get_buffer_size;
1383 out->stream.common.get_channels = out_get_channels;
1384 out->stream.common.get_format = out_get_format;
1385 out->stream.common.set_format = out_set_format;
1386 out->stream.common.standby = out_standby;
1387 out->stream.common.dump = out_dump;
1388 out->stream.common.set_parameters = out_set_parameters;
1389 out->stream.common.get_parameters = out_get_parameters;
1390 out->stream.common.add_audio_effect = out_add_audio_effect;
1391 out->stream.common.remove_audio_effect = out_remove_audio_effect;
1392 out->stream.get_latency = out_get_latency;
1393 out->stream.set_volume = out_set_volume;
1394 out->stream.write = out_write;
1395 out->stream.get_render_position = out_get_render_position;
1396 out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
1397
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001398 out->standby = 1;
Eric Laurenta9024de2013-04-04 09:19:12 -07001399 /* out->muted = false; by calloc() */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001400
1401 config->format = out->stream.common.get_format(&out->stream.common);
1402 config->channel_mask = out->stream.common.get_channels(&out->stream.common);
1403 config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
1404
1405 *stream_out = &out->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07001406 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001407 return 0;
Ravi Kumar Alamandab1995062013-03-21 23:18:20 -07001408
1409error_open:
1410 free(out);
1411 *stream_out = NULL;
1412 ALOGD("%s: exit: ret %d", __func__, ret);
1413 return ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001414}
1415
1416static void adev_close_output_stream(struct audio_hw_device *dev,
1417 struct audio_stream_out *stream)
1418{
Eric Laurent994a6932013-07-17 11:51:42 -07001419 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001420 out_standby(&stream->common);
1421 free(stream);
Eric Laurent994a6932013-07-17 11:51:42 -07001422 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001423}
1424
1425static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
1426{
1427 struct audio_device *adev = (struct audio_device *)dev;
1428 struct str_parms *parms;
1429 char *str;
1430 char value[32];
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001431 int val;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001432 int ret;
1433
Eric Laurent994a6932013-07-17 11:51:42 -07001434 ALOGV("%s: enter: %s", __func__, kvpairs);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001435
1436 parms = str_parms_create_str(kvpairs);
1437 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
1438 if (ret >= 0) {
1439 int tty_mode;
1440
1441 if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
1442 tty_mode = TTY_MODE_OFF;
1443 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
1444 tty_mode = TTY_MODE_VCO;
1445 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
1446 tty_mode = TTY_MODE_HCO;
1447 else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
1448 tty_mode = TTY_MODE_FULL;
1449 else
1450 return -EINVAL;
1451
1452 pthread_mutex_lock(&adev->lock);
1453 if (tty_mode != adev->tty_mode) {
1454 adev->tty_mode = tty_mode;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001455 adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
1456 if (adev->in_call)
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001457 select_devices(adev, USECASE_VOICE_CALL);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001458 }
1459 pthread_mutex_unlock(&adev->lock);
1460 }
1461
1462 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
1463 if (ret >= 0) {
1464 /* When set to false, HAL should disable EC and NS
1465 * But it is currently not supported.
1466 */
1467 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1468 adev->bluetooth_nrec = true;
1469 else
1470 adev->bluetooth_nrec = false;
1471 }
1472
1473 ret = str_parms_get_str(parms, "screen_state", value, sizeof(value));
1474 if (ret >= 0) {
1475 if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
1476 adev->screen_off = false;
1477 else
1478 adev->screen_off = true;
1479 }
1480
Jean-Michel Trivic56336b2013-05-24 16:55:17 -07001481 ret = str_parms_get_int(parms, "rotation", &val);
1482 if (ret >= 0) {
1483 bool reverse_speakers = false;
1484 switch(val) {
1485 // FIXME: note that the code below assumes that the speakers are in the correct placement
1486 // relative to the user when the device is rotated 90deg from its default rotation. This
1487 // assumption is device-specific, not platform-specific like this code.
1488 case 270:
1489 reverse_speakers = true;
1490 break;
1491 case 0:
1492 case 90:
1493 case 180:
1494 break;
1495 default:
1496 ALOGE("%s: unexpected rotation of %d", __func__, val);
1497 }
1498 pthread_mutex_lock(&adev->lock);
1499 if (adev->speaker_lr_swap != reverse_speakers) {
1500 adev->speaker_lr_swap = reverse_speakers;
1501 // only update the selected device if there is active pcm playback
1502 struct audio_usecase *usecase;
1503 struct listnode *node;
1504 list_for_each(node, &adev->usecase_list) {
1505 usecase = node_to_item(node, struct audio_usecase, list);
1506 if (usecase->type == PCM_PLAYBACK) {
1507 select_devices(adev, usecase->id);
1508 break;
1509 }
1510 }
1511 }
1512 pthread_mutex_unlock(&adev->lock);
1513 }
1514
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001515 audio_extn_set_parameters(adev, parms);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001516 str_parms_destroy(parms);
Eric Laurent994a6932013-07-17 11:51:42 -07001517 ALOGV("%s: exit with code(%d)", __func__, ret);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001518 return ret;
1519}
1520
1521static char* adev_get_parameters(const struct audio_hw_device *dev,
1522 const char *keys)
1523{
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07001524 return audio_extn_get_parameters(dev, keys);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001525}
1526
1527static int adev_init_check(const struct audio_hw_device *dev)
1528{
1529 return 0;
1530}
1531
1532static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
1533{
1534 struct audio_device *adev = (struct audio_device *)dev;
1535 int vol, err = 0;
1536
1537 pthread_mutex_lock(&adev->lock);
1538 adev->voice_volume = volume;
1539 if (adev->mode == AUDIO_MODE_IN_CALL) {
1540 if (volume < 0.0) {
1541 volume = 0.0;
1542 } else if (volume > 1.0) {
1543 volume = 1.0;
1544 }
1545
1546 vol = lrint(volume * 100.0);
1547
1548 // Voice volume levels from android are mapped to driver volume levels as follows.
1549 // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
1550 // So adjust the volume to get the correct volume index in driver
1551 vol = 100 - vol;
Eric Laurentb23d5282013-05-14 15:27:20 -07001552
1553 err = platform_set_voice_volume(adev->platform, vol);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001554 }
1555 pthread_mutex_unlock(&adev->lock);
1556 return err;
1557}
1558
1559static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
1560{
1561 return -ENOSYS;
1562}
1563
1564static int adev_get_master_volume(struct audio_hw_device *dev,
1565 float *volume)
1566{
1567 return -ENOSYS;
1568}
1569
1570static int adev_set_master_mute(struct audio_hw_device *dev, bool muted)
1571{
1572 return -ENOSYS;
1573}
1574
1575static int adev_get_master_mute(struct audio_hw_device *dev, bool *muted)
1576{
1577 return -ENOSYS;
1578}
1579
1580static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
1581{
1582 struct audio_device *adev = (struct audio_device *)dev;
1583
1584 pthread_mutex_lock(&adev->lock);
1585 if (adev->mode != mode) {
1586 adev->mode = mode;
1587 }
1588 pthread_mutex_unlock(&adev->lock);
1589 return 0;
1590}
1591
1592static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
1593{
1594 struct audio_device *adev = (struct audio_device *)dev;
1595 int err = 0;
1596
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001597 pthread_mutex_lock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001598 adev->mic_mute = state;
Eric Laurentb23d5282013-05-14 15:27:20 -07001599
1600 err = platform_set_mic_mute(adev->platform, state);
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001601 pthread_mutex_unlock(&adev->lock);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001602 return err;
1603}
1604
1605static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
1606{
1607 struct audio_device *adev = (struct audio_device *)dev;
1608
1609 *state = adev->mic_mute;
1610
1611 return 0;
1612}
1613
1614static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
1615 const struct audio_config *config)
1616{
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001617 int channel_count = popcount(config->channel_mask);
1618
1619 return get_input_buffer_size(config->sample_rate, config->format, channel_count);
1620}
1621
1622static int adev_open_input_stream(struct audio_hw_device *dev,
1623 audio_io_handle_t handle,
1624 audio_devices_t devices,
1625 struct audio_config *config,
1626 struct audio_stream_in **stream_in)
1627{
1628 struct audio_device *adev = (struct audio_device *)dev;
1629 struct stream_in *in;
1630 int ret, buffer_size, frame_size;
1631 int channel_count = popcount(config->channel_mask);
1632
Eric Laurent994a6932013-07-17 11:51:42 -07001633 ALOGV("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001634 *stream_in = NULL;
1635 if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
1636 return -EINVAL;
1637
1638 in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
1639
1640 in->stream.common.get_sample_rate = in_get_sample_rate;
1641 in->stream.common.set_sample_rate = in_set_sample_rate;
1642 in->stream.common.get_buffer_size = in_get_buffer_size;
1643 in->stream.common.get_channels = in_get_channels;
1644 in->stream.common.get_format = in_get_format;
1645 in->stream.common.set_format = in_set_format;
1646 in->stream.common.standby = in_standby;
1647 in->stream.common.dump = in_dump;
1648 in->stream.common.set_parameters = in_set_parameters;
1649 in->stream.common.get_parameters = in_get_parameters;
1650 in->stream.common.add_audio_effect = in_add_audio_effect;
1651 in->stream.common.remove_audio_effect = in_remove_audio_effect;
1652 in->stream.set_gain = in_set_gain;
1653 in->stream.read = in_read;
1654 in->stream.get_input_frames_lost = in_get_input_frames_lost;
1655
1656 in->device = devices;
1657 in->source = AUDIO_SOURCE_DEFAULT;
1658 in->dev = adev;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001659 in->standby = 1;
1660 in->channel_mask = config->channel_mask;
1661
1662 /* Update config params with the requested sample rate and channels */
1663 in->usecase = USECASE_AUDIO_RECORD;
1664 in->config = pcm_config_audio_capture;
1665 in->config.channels = channel_count;
1666 in->config.rate = config->sample_rate;
1667
1668 frame_size = audio_stream_frame_size((struct audio_stream *)in);
1669 buffer_size = get_input_buffer_size(config->sample_rate,
1670 config->format,
1671 channel_count);
1672 in->config.period_size = buffer_size / frame_size;
1673
1674 *stream_in = &in->stream;
Eric Laurent994a6932013-07-17 11:51:42 -07001675 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001676 return 0;
1677
1678err_open:
1679 free(in);
1680 *stream_in = NULL;
1681 return ret;
1682}
1683
1684static void adev_close_input_stream(struct audio_hw_device *dev,
1685 struct audio_stream_in *stream)
1686{
Eric Laurent994a6932013-07-17 11:51:42 -07001687 ALOGV("%s", __func__);
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001688
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001689 in_standby(&stream->common);
1690 free(stream);
1691
1692 return;
1693}
1694
1695static int adev_dump(const audio_hw_device_t *device, int fd)
1696{
1697 return 0;
1698}
1699
1700static int adev_close(hw_device_t *device)
1701{
1702 struct audio_device *adev = (struct audio_device *)device;
1703 audio_route_free(adev->audio_route);
Eric Laurentb23d5282013-05-14 15:27:20 -07001704 free(adev->snd_dev_ref_cnt);
1705 platform_deinit(adev->platform);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001706 free(device);
1707 return 0;
1708}
1709
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001710static int adev_open(const hw_module_t *module, const char *name,
1711 hw_device_t **device)
1712{
1713 struct audio_device *adev;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -07001714 int i, ret;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001715
Ravi Kumar Alamanda75d924d2013-02-20 21:30:08 -08001716 ALOGD("%s: enter", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001717 if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL;
1718
1719 adev = calloc(1, sizeof(struct audio_device));
1720
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001721 adev->device.common.tag = HARDWARE_DEVICE_TAG;
1722 adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
1723 adev->device.common.module = (struct hw_module_t *)module;
1724 adev->device.common.close = adev_close;
1725
1726 adev->device.init_check = adev_init_check;
1727 adev->device.set_voice_volume = adev_set_voice_volume;
1728 adev->device.set_master_volume = adev_set_master_volume;
1729 adev->device.get_master_volume = adev_get_master_volume;
1730 adev->device.set_master_mute = adev_set_master_mute;
1731 adev->device.get_master_mute = adev_get_master_mute;
1732 adev->device.set_mode = adev_set_mode;
1733 adev->device.set_mic_mute = adev_set_mic_mute;
1734 adev->device.get_mic_mute = adev_get_mic_mute;
1735 adev->device.set_parameters = adev_set_parameters;
1736 adev->device.get_parameters = adev_get_parameters;
1737 adev->device.get_input_buffer_size = adev_get_input_buffer_size;
1738 adev->device.open_output_stream = adev_open_output_stream;
1739 adev->device.close_output_stream = adev_close_output_stream;
1740 adev->device.open_input_stream = adev_open_input_stream;
1741 adev->device.close_input_stream = adev_close_input_stream;
1742 adev->device.dump = adev_dump;
1743
1744 /* Set the default route before the PCM stream is opened */
1745 pthread_mutex_lock(&adev->lock);
1746 adev->mode = AUDIO_MODE_NORMAL;
Eric Laurentc8400632013-02-14 19:04:54 -08001747 adev->active_input = NULL;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -08001748 adev->primary_output = NULL;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001749 adev->out_device = AUDIO_DEVICE_NONE;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001750 adev->voice_call_rx = NULL;
1751 adev->voice_call_tx = NULL;
1752 adev->voice_volume = 1.0f;
1753 adev->tty_mode = TTY_MODE_OFF;
1754 adev->bluetooth_nrec = true;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001755 adev->in_call = false;
Ravi Kumar Alamandaf9967042013-02-14 19:35:14 -08001756 adev->acdb_settings = TTY_MODE_OFF;
Eric Laurentb23d5282013-05-14 15:27:20 -07001757 adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -08001758 list_init(&adev->usecase_list);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001759 pthread_mutex_unlock(&adev->lock);
1760
1761 /* Loads platform specific libraries dynamically */
Eric Laurentb23d5282013-05-14 15:27:20 -07001762 adev->platform = platform_init(adev);
1763 if (!adev->platform) {
1764 free(adev->snd_dev_ref_cnt);
1765 free(adev);
1766 ALOGE("%s: Failed to init platform data, aborting.", __func__);
1767 *device = NULL;
1768 return -EINVAL;
1769 }
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001770 *device = &adev->device.common;
1771
Eric Laurent994a6932013-07-17 11:51:42 -07001772 ALOGV("%s: exit", __func__);
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001773 return 0;
1774}
1775
1776static struct hw_module_methods_t hal_module_methods = {
1777 .open = adev_open,
1778};
1779
1780struct audio_module HAL_MODULE_INFO_SYM = {
1781 .common = {
1782 .tag = HARDWARE_MODULE_TAG,
1783 .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
1784 .hal_api_version = HARDWARE_HAL_API_VERSION,
1785 .id = AUDIO_HARDWARE_MODULE_ID,
1786 .name = "QCOM Audio HAL",
1787 .author = "Code Aurora Forum",
1788 .methods = &hal_module_methods,
1789 },
1790};