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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
/*
* 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>
#ifdef ALSA_UCM_DEBUG_TIME
#include <sys/time.h>
#include <time.h>
#endif
#include "tizen-audio-internal.h"
#ifdef ALSA_UCM_DEBUG_TIME
#define SND_USE_CASE_SET __set_use_case_with_time
#else
#define SND_USE_CASE_SET snd_use_case_set
#endif
#define UCM_PREFIX_CURRENT ">>> UCM current"
#define UCM_PREFIX_REQUESTED "> UCM requested"
#define UCM_PREFIX_CHANGED "<<< UCM changed"
#define DUMP_LEN 512
static void __dump_use_case(const char* prefix, const char *verb, const char *devices[], int dev_count, const char *modifiers[], int mod_count)
{
int i;
dump_data_t* dump = NULL;
if (!(dump = _audio_dump_new(DUMP_LEN))) {
AUDIO_LOG_ERROR("Failed to create dump string...");
return;
}
/* Verb */
_audio_dump_add_str(dump, "Verb [ %s ] Devices [ ", verb ? verb : AUDIO_USE_CASE_VERB_INACTIVE);
/* Devices */
if (devices) {
for (i = 0; i < dev_count; i++) {
_audio_dump_add_str(dump, (i != dev_count - 1) ? "%s, " : "%s", devices[i]);
}
}
_audio_dump_add_str(dump, " ] Modifier [ ");
/* Modifiers */
if (modifiers) {
for (i = 0; i < mod_count; i++) {
_audio_dump_add_str(dump, (i != mod_count - 1) ? "%s, " : "%s", modifiers[i]);
}
}
_audio_dump_add_str(dump, " ]");
AUDIO_LOG_INFO("TEST %s : %s", prefix, _audio_dump_get_str(dump));
_audio_dump_free(dump);
}
#ifdef ALSA_UCM_DEBUG_TIME
static inline int __set_use_case_with_time(snd_use_case_mgr_t *uc_mgr, const char *identifier, const char *value)
{
int ret = 0;
struct timeval t_start, t_stop;
unsigned long long t_diff = 0;
gettimeofday(&t_start, NULL);
ret = snd_use_case_set(uc_mgr, identifier, value);
gettimeofday(&t_stop, NULL);
if (t_start.tv_sec < t_stop.tv_sec)
t_diff = (t_stop.tv_sec - t_start.tv_sec) * 1000000;
t_diff += (t_stop.tv_usec - t_start.tv_usec);
AUDIO_LOG_DEBUG("identifier %s value %s takes %lluusec", identifier, value, t_diff);
return ret;
}
#endif
audio_return_t _ucm_init(audio_hal_t *ah)
{
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
snd_use_case_mgr_open(&ah->ucm.uc_mgr, ALSA_DEFAULT_CARD);
if (!ah->ucm.uc_mgr) {
AUDIO_LOG_ERROR("uc_mgr open failed");
return AUDIO_ERR_RESOURCE;
}
return AUDIO_RET_OK;
}
audio_return_t _ucm_deinit(audio_hal_t *ah)
{
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
if (ah->ucm.uc_mgr) {
snd_use_case_mgr_close(ah->ucm.uc_mgr);
ah->ucm.uc_mgr = NULL;
}
return AUDIO_RET_OK;
}
/* UCM sequence
1) If verb is null or verb is not changed
1-1) If device is changed
(If there is request for same device, it will be ignored)
-> Set "Inactive" verb, disable modifiers & devices, set current verb again, enable devices & modifiers
(playback/capture device will be enabled again if there is no request for playback/capture device)
1-2) If device is not changed
1-2-1) If modifier is changed
(If there is request for same modifier, it will be ignored)
-> Disable modifiers, enable modifiers
2) If verb is changed
-> Reset, set new verb, enable devices & modifiers
*/
audio_return_t _ucm_set_use_case(audio_hal_t *ah, const char *verb, const char *devices[], const char *modifiers[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_dev_changed = 0, is_mod_changed = 0;
const char *old_verb = NULL, **old_dev_list = NULL, **old_mod_list = NULL;
int old_dev_count = 0, dev_count = 0;
int old_mod_count = 0, mod_count = 0;
const char **dis_dev_list = NULL, **ena_dev_list = NULL;
const char **dis_mod_list = NULL, **ena_mod_list = NULL;
int dis_dev_count = 0, ena_dev_count = 0;
int dis_mod_count = 0, ena_mod_count = 0;
int i = 0, j = 0;
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list);
old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list);
__dump_use_case(UCM_PREFIX_CURRENT, old_verb, old_dev_list, old_dev_count, old_mod_list, old_mod_count);
if (devices) {
for (dev_count = 0; devices[dev_count]; dev_count++);
}
if (modifiers) {
for (mod_count = 0; modifiers[mod_count]; mod_count++);
}
__dump_use_case(UCM_PREFIX_REQUESTED, verb, devices, dev_count, modifiers, mod_count);
if (old_verb && streq(verb, old_verb)) {
AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely");
if (old_dev_count > 0) {
dis_dev_list = (const char **)malloc(sizeof(const char *) * old_dev_count);
for (i = 0; i < old_dev_count; i++) {
dis_dev_list[i] = NULL;
}
}
if (dev_count > 0) {
ena_dev_list = (const char **)malloc(sizeof(const char *) * dev_count);
for (i = 0; i < dev_count; i++) {
ena_dev_list[i] = NULL;
}
}
if (old_mod_count > 0) {
dis_mod_list = (const char **)malloc(sizeof(const char *) * old_mod_count);
for (i = 0; i < old_mod_count; i++) {
dis_mod_list[i] = NULL;
}
}
if (mod_count > 0) {
ena_mod_list = (const char **)malloc(sizeof(const char *) * mod_count);
for (i = 0; i < mod_count; i++) {
ena_mod_list[i] = NULL;
}
}
/* update disable modifiers list which are not present in new modifier list */
for (i = 0; i < old_mod_count; i++) {
int need_disable_mod = 1;
for (j = 0; j < mod_count; j++) {
if (streq(old_mod_list[i], modifiers[j])) {
need_disable_mod = 0;
break;
}
}
if (need_disable_mod) {
if (is_mod_changed == 0)
is_mod_changed = 1;
dis_mod_list[dis_mod_count++] = old_mod_list[i];
}
}
/* update disable devices list which are not present in new device list */
for (i = 0; i < old_dev_count; i++) {
int need_disable_dev = 1;
for (j = 0; j < dev_count; j++) {
if (streq(old_dev_list[i], devices[j])) {
need_disable_dev = 0;
break;
}
}
if (need_disable_dev) {
if (is_dev_changed == 0)
is_dev_changed = 1;
dis_dev_list[dis_dev_count++] = old_dev_list[i];
}
}
/* update enable devices list which are not present in old device list */
for (i = 0; i < dev_count; i++) {
int need_enable_dev = 1;
for (j = 0; j < old_dev_count; j++) {
if (streq(devices[i], old_dev_list[j])) {
need_enable_dev = 0;
break;
}
}
if (need_enable_dev) {
if (is_dev_changed == 0)
is_dev_changed = 1;
ena_dev_list[ena_dev_count++] = devices[i];
}
}
/* update enable modifiers list which are not present in old modifier list */
for (i = 0; i < mod_count; i++) {
int need_enable_mod = 1;
for (j = 0; j < old_mod_count; j++) {
if (streq(modifiers[i], old_mod_list[j])) {
need_enable_mod = 0;
break;
}
}
if (need_enable_mod) {
if (is_mod_changed == 0)
is_mod_changed = 1;
ena_mod_list[ena_mod_count++] = modifiers[i];
}
}
/* disable modifiers */
for (i = 0; i < dis_mod_count; i++) {
AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]);
}
/* disable devices */
for (i = 0; i < dis_dev_count; i++) {
AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]);
}
/* enable devices */
for (i = 0; i < ena_dev_count; i++) {
AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]);
}
/* enable modifiers */
for (i = 0; i < ena_mod_count; i++) {
AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]);
}
} else {
is_verb_changed = 1;
AUDIO_LOG_DEBUG("Setting new verb: %s", verb);
/* set new verb */
if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
}
/* enable devices */
for (i = 0; i < dev_count; i++) {
AUDIO_LOG_DEBUG("Enable device : %s", devices[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0)
AUDIO_LOG_ERROR("Enable %s device failed", devices[i]);
}
/* enable modifiers */
for (i = 0; i < mod_count; i++) {
AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]);
}
}
exit:
if (old_verb)
free((void *)old_verb);
if (old_dev_list)
snd_use_case_free_list(old_dev_list, old_dev_count);
if (old_mod_list)
snd_use_case_free_list(old_mod_list, old_mod_count);
if (dis_dev_list)
free((void *)dis_dev_list);
if (ena_dev_list)
free((void *)ena_dev_list);
if (dis_mod_list)
free((void *)dis_mod_list);
if (ena_mod_list)
free((void *)ena_mod_list);
if (is_verb_changed == 1 || is_dev_changed == 1 || is_mod_changed == 1) {
const char *new_verb = NULL, **new_dev_list = NULL, **new_mod_list = NULL;
int new_dev_count = 0, new_mod_count = 0;
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list);
new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list);
__dump_use_case(UCM_PREFIX_CHANGED, new_verb, new_dev_list, new_dev_count, new_mod_list, new_mod_count);
if (new_verb)
free((void *)new_verb);
if (new_dev_list)
snd_use_case_free_list(new_dev_list, new_dev_count);
if (new_mod_list)
snd_use_case_free_list(new_mod_list, new_mod_count);
}
return audio_ret;
}
audio_return_t _ucm_set_devices(audio_hal_t *ah, const char *verb, const char *devices[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_dev_changed = 0;
const char *old_verb = NULL, **old_dev_list = NULL;
int old_dev_count = 0, dev_count = 0;
const char **dis_dev_list = NULL, **ena_dev_list = NULL;
int dis_dev_count = 0, ena_dev_count = 0;
int i = 0, j = 0;
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list);
__dump_use_case(UCM_PREFIX_CURRENT, old_verb, old_dev_list, old_dev_count, NULL, 0);
if (devices) {
for (dev_count = 0; devices[dev_count]; dev_count++);
}
__dump_use_case(UCM_PREFIX_REQUESTED, verb, devices, dev_count, NULL, 0);
if (old_verb && streq(verb, old_verb)) {
AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely");
if (old_dev_count > 0) {
dis_dev_list = (const char **)malloc(sizeof(const char *) * old_dev_count);
for (i = 0; i < old_dev_count; i++) {
dis_dev_list[i] = NULL;
}
}
if (dev_count > 0) {
ena_dev_list = (const char **)malloc(sizeof(const char *) * dev_count);
for (i = 0; i < dev_count; i++) {
ena_dev_list[i] = NULL;
}
}
/* update disable devices list which are not present in new device list */
for (i = 0; i < old_dev_count; i++) {
int need_disable_dev = 1;
for (j = 0; j < dev_count; j++) {
if (streq(old_dev_list[i], devices[j])) {
need_disable_dev = 0;
break;
}
}
if (need_disable_dev) {
if (is_dev_changed == 0)
is_dev_changed = 1;
dis_dev_list[dis_dev_count++] = old_dev_list[i];
}
}
/* update enable devices list which are not present in old device list */
for (i = 0; i < dev_count; i++) {
int need_enable_dev = 1;
for (j = 0; j < old_dev_count; j++) {
if (streq(devices[i], old_dev_list[j])) {
need_enable_dev = 0;
break;
}
}
if (need_enable_dev) {
if (is_dev_changed == 0)
is_dev_changed = 1;
ena_dev_list[ena_dev_count++] = devices[i];
}
}
/* disable devices */
for (i = 0; i < dis_dev_count; i++) {
AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]);
}
/* enable devices */
for (i = 0; i < ena_dev_count; i++) {
AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]);
}
} else {
is_verb_changed = 1;
AUDIO_LOG_INFO("Setting new verb: %s", verb);
/* set new verb */
if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
}
/* enable devices */
for (i = 0; i < dev_count; i++) {
AUDIO_LOG_INFO("Enable device : %s", devices[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0)
AUDIO_LOG_ERROR("Enable %s device failed", devices[i]);
}
}
exit:
if (old_verb)
free((void *)old_verb);
if (old_dev_list)
snd_use_case_free_list(old_dev_list, old_dev_count);
if (dis_dev_list)
free((void *)dis_dev_list);
if (ena_dev_list)
free((void *)ena_dev_list);
if (is_verb_changed == 1 || is_dev_changed == 1) {
const char *new_verb = NULL, **new_dev_list = NULL;
int new_dev_count = 0;
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list);
__dump_use_case(UCM_PREFIX_CHANGED, new_verb, new_dev_list, new_dev_count, NULL, 0);
if (new_verb)
free((void *)new_verb);
if (new_dev_list)
snd_use_case_free_list(new_dev_list, new_dev_count);
}
return audio_ret;
}
audio_return_t _ucm_set_modifiers(audio_hal_t *ah, const char *verb, const char *modifiers[])
{
audio_return_t audio_ret = AUDIO_RET_OK;
int is_verb_changed = 0, is_mod_changed = 0;
const char *old_verb = NULL, **old_mod_list = NULL;
int old_mod_count = 0, mod_count = 0;
const char **dis_mod_list = NULL, **ena_mod_list = NULL;
int dis_mod_count = 0, ena_mod_count = 0;
int i = 0, j = 0;
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(modifiers, AUDIO_ERR_PARAMETER);
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb);
old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list);
__dump_use_case(UCM_PREFIX_CURRENT, old_verb, NULL, 0, old_mod_list, old_mod_count);
if (modifiers) {
for (mod_count = 0; modifiers[mod_count]; mod_count++);
}
__dump_use_case(UCM_PREFIX_REQUESTED, verb, NULL, 0, modifiers, mod_count);
if (old_verb && streq(verb, old_verb)) {
AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely");
if (old_mod_count > 0) {
dis_mod_list = (const char **)malloc(sizeof(const char *) * old_mod_count);
for (i = 0; i < old_mod_count; i++) {
dis_mod_list[i] = NULL;
}
}
if (mod_count > 0) {
ena_mod_list = (const char **)malloc(sizeof(const char *) * mod_count);
for (i = 0; i < mod_count; i++) {
ena_mod_list[i] = NULL;
}
}
/* update disable modifiers list which are not present in new modifier list */
for (i = 0; i < old_mod_count; i++) {
int need_disable_mod = 1;
for (j = 0; j < mod_count; j++) {
if (streq(old_mod_list[i], modifiers[j])) {
need_disable_mod = 0;
break;
}
}
if (need_disable_mod) {
if (is_mod_changed == 0)
is_mod_changed = 1;
dis_mod_list[dis_mod_count++] = old_mod_list[i];
}
}
/* update enable modifiers list which are not present in old modifier list */
for (i = 0; i < mod_count; i++) {
int need_enable_mod = 1;
for (j = 0; j < old_mod_count; j++) {
if (streq(modifiers[i], old_mod_list[j])) {
need_enable_mod = 0;
break;
}
}
if (need_enable_mod) {
if (is_mod_changed == 0)
is_mod_changed = 1;
ena_mod_list[ena_mod_count++] = modifiers[i];
}
}
/* disable modifiers */
for (i = 0; i < dis_mod_count; i++) {
AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0)
AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]);
}
/* enable modifiers */
for (i = 0; i < ena_mod_count; i++) {
AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0)
AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]);
}
} else {
is_verb_changed = 1;
AUDIO_LOG_DEBUG("Setting new verb: %s", verb);
/* set new verb */
if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) {
AUDIO_LOG_ERROR("Setting verb %s failed", verb);
audio_ret = AUDIO_ERR_UNDEFINED;
goto exit;
}
/* enable modifiers */
for (i = 0; i < mod_count; i++) {
AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]);
if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0)
AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]);
}
}
exit:
if (old_verb)
free((void *)old_verb);
if (old_mod_list)
snd_use_case_free_list(old_mod_list, old_mod_count);
if (dis_mod_list)
free((void *)dis_mod_list);
if (ena_mod_list)
free((void *)ena_mod_list);
if (is_verb_changed == 1 || is_mod_changed == 1) {
const char *new_verb = NULL, **new_mod_list = NULL;
int new_mod_count = 0;
snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb);
new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list);
__dump_use_case(UCM_PREFIX_CHANGED, new_verb, NULL, 0, new_mod_list, new_mod_count);
if (new_verb)
free((void *)new_verb);
if (new_mod_list)
snd_use_case_free_list(new_mod_list, new_mod_count);
}
return audio_ret;
}
audio_return_t _ucm_get_verb(audio_hal_t *ah, const char **value)
{
audio_return_t ret = AUDIO_RET_OK;
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(value, AUDIO_ERR_PARAMETER);
if ((ret = snd_use_case_get(ah->ucm.uc_mgr, "_verb", value)) < 0) {
AUDIO_LOG_ERROR("Getting current verb failed: Reason %d", ret);
ret = AUDIO_ERR_UNDEFINED;
}
return ret;
}
audio_return_t _ucm_reset_use_case(audio_hal_t *ah)
{
audio_return_t ret = AUDIO_RET_OK;
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER);
AUDIO_LOG_INFO(">>> UCM reset Verb [ %s ]", AUDIO_USE_CASE_VERB_INACTIVE);
if ((ret = snd_use_case_set(ah->ucm.uc_mgr, "_verb", AUDIO_USE_CASE_VERB_INACTIVE)) < 0) {
AUDIO_LOG_ERROR("Reset use case failed: Reason %d", ret);
ret = AUDIO_ERR_UNDEFINED;
}
return ret;
}
|