summaryrefslogtreecommitdiff
path: root/tizen-audio-routing.c
blob: fcf297a5a7786ff913a8b2400ca1f8f527ad1c89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
 * audio-hal
 *
 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "tizen-audio-internal.h"
#include "tizen-audio-impl.h"

/* #define DEBUG_TIMING */

static device_type_t outDeviceTypes[] = {
    { AUDIO_DEVICE_OUT_SPEAKER, "speaker" },
    { AUDIO_DEVICE_OUT_BT_SCO, "bt-sco-headset" },
    { AUDIO_DEVICE_OUT_BT_SCO_8K_NB, "bt-8k-sco-nb-headset" },
    { AUDIO_DEVICE_OUT_BT_SCO_16K_NB, "bt-16k-sco-nb-headset" },
    { AUDIO_DEVICE_OUT_BT_SCO_8K_WB, "bt-8k-sco-wb-headset" },
    { AUDIO_DEVICE_OUT_BT_SCO_16K_WB, "bt-16k-sco-wb-headset" },
    { 0, 0 },
};

static device_type_t inDeviceTypes[] = {
    { AUDIO_DEVICE_IN_MAIN_MIC, "main-mic" },
    { AUDIO_DEVICE_IN_BT_SCO, "bt-sco-mic" },
    { AUDIO_DEVICE_IN_BT_SCO_8K_NB, "bt-8k-sco-nb-mic" },
    { AUDIO_DEVICE_IN_BT_SCO_16K_NB, "bt-16k-sco-nb-mic" },
    { AUDIO_DEVICE_IN_BT_SCO_8K_WB, "bt-8k-sco-wb-mic" },
    { AUDIO_DEVICE_IN_BT_SCO_16K_WB, "bt-16k-sco-wb-mic" },
    { 0, 0 },
};

static const char* mode_to_verb_str[] = {
    AUDIO_USE_CASE_VERB_HIFI,
    AUDIO_USE_CASE_VERB_VOICECALL,
    AUDIO_USE_CASE_VERB_VOIP,
};

static bool __is_acive_device_bt_sco_for_call(audio_hal_t *ah)
{
    if (!ah) {
        AUDIO_LOG_WARN("ah is null");
        return false;
    }

    if (ah->device.active_in & AUDIO_DEVICE_IN_BT_SCO_8K_NB &&
        ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO_8K_NB)
        return true;
    if (ah->device.active_in & AUDIO_DEVICE_IN_BT_SCO_16K_NB &&
        ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO_16K_NB)
        return true;
    if (ah->device.active_in & AUDIO_DEVICE_IN_BT_SCO_8K_WB &&
        ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO_8K_WB)
        return true;
    if (ah->device.active_in & AUDIO_DEVICE_IN_BT_SCO_16K_WB &&
        ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO_16K_WB)
        return true;

    return false;
}

static uint32_t __convert_device_string_to_enum(audio_hal_t *ah, const char *verb, const char* device_str, uint32_t direction)
{
    uint32_t device = 0;

    AUDIO_LOG_INFO("verb(%s), device string(%s), direction(%d)", verb, device_str, direction);

    if (!strncmp(device_str, "builtin-speaker", MAX_NAME_LEN)) {
        device = AUDIO_DEVICE_OUT_SPEAKER;

    } else if ((!strncmp(device_str, "bt-sco", MAX_NAME_LEN)) && (direction == AUDIO_DIRECTION_OUT)) {
        if (!strncmp(verb, AUDIO_USE_CASE_VERB_HIFI, MAX_NAME_LEN)) {
            device = AUDIO_DEVICE_OUT_BT_SCO;
        } else if (!strncmp(verb, AUDIO_USE_CASE_VERB_VOICECALL, MAX_NAME_LEN)) {
            AUDIO_LOG_INFO("device.bt_widband(%d), call_wideband(%d)", ah->device.bt_wideband, ah->call_wideband);
            if (ah->device.bt_wideband) {
                if (ah->call_wideband)
                    device = AUDIO_DEVICE_OUT_BT_SCO_16K_WB;
                else
                    device = AUDIO_DEVICE_OUT_BT_SCO_16K_NB;
            } else {
                if (ah->call_wideband)
                    device = AUDIO_DEVICE_OUT_BT_SCO_8K_WB;
                else
                    device = AUDIO_DEVICE_OUT_BT_SCO_8K_NB;
            }
        } else {
            device = AUDIO_DEVICE_OUT_BT_SCO;
            AUDIO_LOG_WARN("invalid verb, set device(%d) forcedly", device);
        }

    } else if ((!strncmp(device_str, "builtin-mic", MAX_NAME_LEN))) {
        device = AUDIO_DEVICE_IN_MAIN_MIC;

    } else if ((!strncmp(device_str, "bt-sco", MAX_NAME_LEN)) && (direction == AUDIO_DIRECTION_IN)) {
        if (!strncmp(verb, AUDIO_USE_CASE_VERB_HIFI, MAX_NAME_LEN)) {
            device = AUDIO_DEVICE_IN_BT_SCO;
        } else if (!strncmp(verb, AUDIO_USE_CASE_VERB_VOICECALL, MAX_NAME_LEN)) {
            AUDIO_LOG_INFO("device.bt_widband(%d), call_wideband(%d)", ah->device.bt_wideband, ah->call_wideband);
            if (ah->device.bt_wideband) {
                if (ah->call_wideband)
                    device = AUDIO_DEVICE_IN_BT_SCO_16K_WB;
                else
                    device = AUDIO_DEVICE_IN_BT_SCO_16K_NB;
            } else {
                if (ah->call_wideband)
                    device = AUDIO_DEVICE_IN_BT_SCO_8K_WB;
                else
                    device = AUDIO_DEVICE_IN_BT_SCO_8K_NB;
            }
        } else {
            device = AUDIO_DEVICE_IN_BT_SCO;
            AUDIO_LOG_WARN("invalid verb, set device(%d) forcedly", device);
        }

    } else {
        device = AUDIO_DEVICE_NONE;
    }

    AUDIO_LOG_INFO("device type(%s), enum(0x%x)", device_str, device);
    return device;
}

static audio_return_t __set_devices(audio_hal_t *ah, const char *verb, device_info_t *devices, uint32_t num_of_devices)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    uint32_t new_device = 0;
    const char *active_devices[MAX_DEVICES] = {NULL,};
    int i = 0, j = 0, dev_idx = 0;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(num_of_devices, AUDIO_ERR_PARAMETER);

    if (num_of_devices > MAX_DEVICES) {
        num_of_devices = MAX_DEVICES;
        AUDIO_LOG_ERROR("error: num_of_devices");
        return AUDIO_ERR_PARAMETER;
    }

    if (devices[0].direction == AUDIO_DIRECTION_OUT) {
        ah->device.active_out &= 0x0;
        if (ah->device.active_in) {
            /* check the active in devices */
            for (j = 0; j < inDeviceTypes[j].type; j++) {
                if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[j].type))
                    active_devices[dev_idx++] = inDeviceTypes[j].name;
            }
        }
    } else if (devices[0].direction == AUDIO_DIRECTION_IN) {
        ah->device.active_in &= 0x0;
        if (ah->device.active_out) {
            /* check the active out devices */
            for (j = 0; j < outDeviceTypes[j].type; j++) {
                if (ah->device.active_out & outDeviceTypes[j].type)
                    active_devices[dev_idx++] = outDeviceTypes[j].name;
            }
        }
    }

    for (i = 0; i < num_of_devices; i++) {
        new_device = __convert_device_string_to_enum(ah, verb, devices[i].type, devices[i].direction);
        if (new_device & AUDIO_DEVICE_IN) {
            for (j = 0; j < inDeviceTypes[j].type; j++) {
                if (new_device == inDeviceTypes[j].type) {
                    active_devices[dev_idx++] = inDeviceTypes[j].name;
                    ah->device.active_in |= new_device;
                }
            }
        } else {
            for (j = 0; j < outDeviceTypes[j].type; j++) {
                if (new_device == outDeviceTypes[j].type) {
                    active_devices[dev_idx++] = outDeviceTypes[j].name;
                    ah->device.active_out |= new_device;
                }
            }
        }
    }

    if (active_devices[0] == NULL) {
        AUDIO_LOG_ERROR("Failed to set device: active device is NULL");
        return AUDIO_ERR_PARAMETER;
    }

    audio_ret = _ucm_set_devices(ah, verb, active_devices);
    if (audio_ret)
        AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret);

    return audio_ret;
}

static audio_return_t __update_route_ap_playback_capture(audio_hal_t *ah, audio_route_info_t *route_info)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    device_info_t *devices = NULL;
    const char *verb = mode_to_verb_str[VERB_NORMAL];

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(route_info, AUDIO_ERR_PARAMETER);

    if (ah->device.mode != VERB_NORMAL) {
       _reset_pcm_devices(ah);
       ah->device.mode = VERB_NORMAL;
    }

    devices = route_info->device_infos;

    AUDIO_LOG_INFO("update_route_ap_playback_capture++ ");

    audio_ret = __set_devices(ah, verb, devices, route_info->num_of_devices);
    if (audio_ret) {
        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
        return audio_ret;
    }

    return audio_ret;
}

static audio_return_t __update_route_voicecall(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    const char *verb = mode_to_verb_str[VERB_VOICECALL];

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("update_route_voicecall++");

    if ((audio_ret = __set_devices(ah, verb, devices, num_of_devices))) {
        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
        return audio_ret;
    }

    if (ah->device.mode != VERB_VOICECALL) {
        ah->device.mode = VERB_VOICECALL;
        _reset_pcm_devices(ah);
    } else {
        /* if this request is for BT SCO device */
        if (__is_acive_device_bt_sco_for_call(ah)) {
            if (_is_bt_pcm_opened_all(ah)) {
                AUDIO_LOG_INFO("bt pcm device is already opened, skip it");
                return audio_ret;
            }
            if ((audio_ret = _bt_pcm_open_all(ah))) {
                AUDIO_LOG_ERROR("Failed to open bt pcm device: error = 0x%x", audio_ret);
                return audio_ret;
            }
        }

        if (_is_voice_pcm_opened_all(ah)) {
            AUDIO_LOG_INFO("voice pcm device is already opened, skip it");
            return audio_ret;
        }
        if ((audio_ret = _voice_pcm_open_all(ah))) {
            AUDIO_LOG_ERROR("Failed to open voice pcm device: error = 0x%x", audio_ret);
            return audio_ret;
        }
    }

    return audio_ret;
}

static audio_return_t __update_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    const char *verb = mode_to_verb_str[VERB_NORMAL];

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("update_route_voip++");

    if ((audio_ret = __set_devices(ah, verb, devices, num_of_devices))) {
        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
        return audio_ret;
    }
    /* FIXME. If necessary, set VERB_VOIP */
    ah->device.mode = VERB_NORMAL;

    /* TO DO: Set modifiers */
    return audio_ret;
}

static audio_return_t __update_route_voice_recognition(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    const char *verb = mode_to_verb_str[VERB_NORMAL];

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("update_route_voice_recognition++");

    if ((audio_ret = __set_devices(ah, verb, devices, num_of_devices))) {
        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
        return audio_ret;
    }

    if (ah->device.mode != VERB_NORMAL) {
        ah->device.mode = VERB_NORMAL;
       _reset_pcm_devices(ah);
    }

    /* if this request is for BT SCO device */
    if (ah->device.active_in & AUDIO_DEVICE_IN_BT_SCO) {
        if (_is_bt_pcm_opened_all(ah)) {
            AUDIO_LOG_INFO("bt pcm device is already opened, skip it");
            return audio_ret;
        }

        if ((audio_ret = _bt_pcm_open_all(ah))) {
            AUDIO_LOG_ERROR("Failed to open bt pcm device: error = 0x%x", audio_ret);
            return audio_ret;
        }
    }

    return audio_ret;
}

static audio_return_t __update_route_voice_information(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    const char *verb = mode_to_verb_str[VERB_NORMAL];

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("update_route_voice_information++");

    audio_ret = __set_devices(ah, verb, devices, num_of_devices);
    if (audio_ret) {
        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
        return audio_ret;
    }

    if (ah->device.mode != VERB_NORMAL) {
        ah->device.mode = VERB_NORMAL;
       _reset_pcm_devices(ah);
    }
    /* if this request is for BT SCO device */
    if (ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO) {
        if (_is_bt_pcm_opened_all(ah)) {
            AUDIO_LOG_INFO("bt pcm device is already opened, skip it");
            return audio_ret;
        }

        if ((audio_ret = _bt_pcm_open_all(ah))) {
            AUDIO_LOG_ERROR("Failed to open bt pcm device: error = 0x%x", audio_ret);
            return audio_ret;
        }
    }

    return audio_ret;
}

static audio_return_t __update_route_reset(audio_hal_t *ah, uint32_t direction)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    const char *active_devices[MAX_DEVICES] = {NULL,};
    int i = 0, dev_idx = 0;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("update_route_reset++, direction(0x%x)", direction);

    if (direction == AUDIO_DIRECTION_OUT) {
        ah->device.active_out &= 0x0;
        if (ah->device.active_in) {
            /* check the active in devices */
            for (i = 0; i < inDeviceTypes[i].type; i++) {
                if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[i].type)) {
                    active_devices[dev_idx++] = inDeviceTypes[i].name;
                    AUDIO_LOG_INFO("added for in : %s", inDeviceTypes[i].name);
                }
            }
        }
    } else {
        ah->device.active_in &= 0x0;
        if (ah->device.active_out) {
            /* check the active out devices */
            for (i = 0; i < outDeviceTypes[i].type; i++) {
                if (ah->device.active_out & outDeviceTypes[i].type) {
                    active_devices[dev_idx++] = outDeviceTypes[i].name;
                    AUDIO_LOG_INFO("added for out : %s", outDeviceTypes[i].name);
                }
            }
        }
    }

    if (ah->device.mode == VERB_VOICECALL) {
        if ((audio_ret = _bt_pcm_close_all(ah)))
            AUDIO_LOG_ERROR("failed to _bt_pcm_close(), ret(0x%x)", audio_ret);
        if ((audio_ret = _voice_pcm_close_all(ah)))
            AUDIO_LOG_ERROR("failed to _voice_pcm_close(), ret(0x%x)", audio_ret);
        if (!ah->device.active_in && !ah->device.active_out)
            ah->device.mode = VERB_NORMAL;
    } else if (ah->device.mode == VERB_NORMAL) {
        if (direction == AUDIO_DIRECTION_IN) {
            /* voice-recognition case */
            if ((audio_ret = _bt_pcm_close_all(ah)))
                AUDIO_LOG_ERROR("failed to _bt_pcm_close(), ret(0x%x)", audio_ret);
        }
    }

    if (active_devices[0] == NULL) {
        AUDIO_LOG_DEBUG("active device is NULL, no need to update.");
        return AUDIO_RET_OK;
    }

    if ((audio_ret = _ucm_set_devices(ah, mode_to_verb_str[ah->device.mode], active_devices)))
        AUDIO_LOG_ERROR("failed to _ucm_set_devices(), ret(0x%x)", audio_ret);

    /* reset bandwidth information */
    ah->device.bt_wideband = false;
    ah->call_wideband = false;

    return audio_ret;
}

audio_return_t _audio_update_route_voicecall(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
{
    return __update_route_voicecall(ah, devices, num_of_devices);
}

audio_return_t _audio_routing_init(audio_hal_t *ah)
{
    audio_return_t audio_ret = AUDIO_RET_OK;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);

    ah->device.active_in = 0x0;
    ah->device.active_out = 0x0;
    ah->device.mode = VERB_NORMAL;

    if ((audio_ret = _ucm_init(ah)))
        AUDIO_LOG_ERROR("failed to _ucm_init(), ret(0x%x)", audio_ret);

    return audio_ret;
}

audio_return_t _audio_routing_deinit(audio_hal_t *ah)
{
    audio_return_t audio_ret = AUDIO_RET_OK;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);

    if ((audio_ret = _ucm_deinit(ah)))
        AUDIO_LOG_ERROR("failed to _ucm_deinit(), ret(0x%x)", audio_ret);

    return audio_ret;
}

audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    audio_hal_t *ah = (audio_hal_t *)audio_handle;
    device_info_t *devices = NULL;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(info, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(info->role, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("role:%s", info->role);

    devices = info->device_infos;

    if (!strncmp("call-voice", info->role, MAX_NAME_LEN)) {
        if ((audio_ret = __update_route_voicecall(ah, devices, info->num_of_devices)))
            AUDIO_LOG_WARN("update voicecall route return 0x%x", audio_ret);

    } else if (!strncmp("voip", info->role, MAX_NAME_LEN)) {
        if ((audio_ret = __update_route_voip(ah, devices, info->num_of_devices)))
            AUDIO_LOG_WARN("update voip route return 0x%x", audio_ret);

    } else if (!strncmp("voice-recognition", info->role, MAX_NAME_LEN) ||
               !strncmp("voice-recognition-service", info->role, MAX_NAME_LEN)) {
        if ((audio_ret = __update_route_voice_recognition(ah, devices, info->num_of_devices)))
            AUDIO_LOG_WARN("update voice-recognition route return 0x%x", audio_ret);

    } else if (!strncmp("voice-information", info->role, MAX_NAME_LEN)) {
        if ((audio_ret = __update_route_voice_information(ah, devices, info->num_of_devices)))
            AUDIO_LOG_WARN("update voice-information route return 0x%x", audio_ret);

    } else if (!strncmp("reset", info->role, MAX_NAME_LEN)) {
        if ((audio_ret = __update_route_reset(ah, devices->direction)))
            AUDIO_LOG_WARN("update reset return 0x%x", audio_ret);

    } else {
        /* need to prepare for "alarm","notification","emergency","ringtone" */
        if ((audio_ret = __update_route_ap_playback_capture(ah, info)))
            AUDIO_LOG_WARN("update playback route return 0x%x", audio_ret);
    }
    return audio_ret;
}

audio_return_t audio_update_route_option(void *audio_handle, audio_route_option_t *option)
{
    audio_return_t audio_ret = AUDIO_RET_OK;
    audio_hal_t *ah = (audio_hal_t *)audio_handle;

    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
    AUDIO_RETURN_VAL_IF_FAIL(option, AUDIO_ERR_PARAMETER);

    AUDIO_LOG_INFO("role:%s, name:%s, value:%d", option->role, option->name, option->value);
    if (!strncmp("voice-recognition", option->role, MAX_NAME_LEN) ||
        !strncmp("voice-information", option->role, MAX_NAME_LEN)) {
        if (!strncmp("bt-wideband", option->name, MAX_NAME_LEN))
            ah->device.bt_wideband = (option->value > 0) ? true : false;

    } else if (!strncmp("call-voice", option->role, MAX_NAME_LEN)) {
        if (!strncmp("bt-wideband", option->name, MAX_NAME_LEN))
            ah->device.bt_wideband = (option->value > 0) ? true : false;
        if (!strncmp("call-wideband", option->name, MAX_NAME_LEN))
            ah->call_wideband = (option->value > 0) ? true : false;
    }

    return audio_ret;
}