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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
|
/*
* avsystem
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
*
* 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.
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "avsys-common.h"
#include "avsys-audio-shm.h"
#include "avsys-audio-sync.h"
#include "avsys-debug.h"
#include "avsys-audio-handle.h"
#include "avsys-audio-shm.h"
#include "avsys-audio-path.h"
#include "avsys-audio-logical-volume.h"
#include "avsys-audio-pactrl.h"
#define DEFAULT_VOLUME_SYSTEM 2
#define DEFAULT_VOLUME_RINGTONE 6
#define DEFAULT_VOLUME_MEDIA 11
#define DEFAULT_VOLUME_NOTIFICATION 6
#define DEFAULT_VOLUME_ALARM 6
#define DEFAULT_VOLUME_CALL 6
#define DEFAULT_VOLUME_FIXED 0
#define DEFAULT_VOLUME_JAVA 11
#define AVSYS_GET_SHM(SHM,ERROR) do { \
if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, (void **)SHM))) { \
avsys_error(AVAUDIO,"avsys_audio_get_shm() failed in %s\n", __func__); \
return ERROR; \
} \
} while (0)
#define AVSYS_LOCK_SYNC() do { \
if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) { \
avsys_error(AVAUDIO,"avsys_audio_lock_sync() failed in %s\n", __func__); \
return AVSYS_STATE_ERR_INTERNAL; \
} \
} while (0)
#define AVSYS_UNLOCK_SYNC() do { \
if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) { \
avsys_error(AVAUDIO,"avsys_audio_unlock_sync() failed in %s\n", __func__); \
return AVSYS_STATE_ERR_INTERNAL; \
} \
} while (0)
EXPORT_API
int avsys_audio_handle_init(void)
{
int i, err = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
/* Check root user */
err = avsys_check_root_privilege();
if (AVSYS_FAIL(err)) {
return err;
}
if (AVSYS_FAIL(avsys_audio_create_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_create_sync() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
if (AVSYS_FAIL(avsys_audio_create_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_create_shm() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
if (control == NULL) {
avsys_error(AVAUDIO, "control is null in %s\n", __func__);
return AVSYS_STATE_ERR_NULL_POINTER;
}
/* init allocted bits */
control->allocated = 0;
control->handle_amp = 0;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_0] = DEFAULT_VOLUME_SYSTEM;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_1] = DEFAULT_VOLUME_NOTIFICATION;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_2] = DEFAULT_VOLUME_ALARM;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_3] = DEFAULT_VOLUME_RINGTONE;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_4] = DEFAULT_VOLUME_MEDIA;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_5] = DEFAULT_VOLUME_CALL;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_6] = DEFAULT_VOLUME_FIXED;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_7] = DEFAULT_VOLUME_JAVA;
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_8] = DEFAULT_VOLUME_MEDIA;
control->ext_device_amp = AVSYS_AUDIO_HANDLE_EXT_DEV_NONE;
control->primary_volume_pid = 0;
control->primary_volume_type = -1;
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
control->handle_priority[i] = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
}
for (i = 0; i < AVSYS_AUDIO_LOCK_SLOT_MAX; i++) {
control->handlelock_pid[i] = -1;
}
return AVSYS_STATE_SUCCESS;
}
EXPORT_API
int avsys_audio_handle_fini(void)
{
AVSYS_LOCK_SYNC();
if (AVSYS_FAIL(avsys_audio_remove_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_remove_shm() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
AVSYS_UNLOCK_SYNC();
if (AVSYS_FAIL(avsys_audio_remove_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_remove_sync() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
return AVSYS_STATE_SUCCESS;
}
EXPORT_API
int avsys_audio_handle_reset(int *volume_value)
{
int i = 0, err = 0;
long long int flag = 0x01;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
int lvolume[AVSYS_AUDIO_VOLUME_TYPE_MAX] = { 0, };
int default_volume[] = { DEFAULT_VOLUME_SYSTEM, DEFAULT_VOLUME_NOTIFICATION,
DEFAULT_VOLUME_ALARM, DEFAULT_VOLUME_RINGTONE,
DEFAULT_VOLUME_MEDIA, DEFAULT_VOLUME_CALL,
DEFAULT_VOLUME_FIXED, DEFAULT_VOLUME_JAVA};
temp = &control;
/* Check root user */
err = avsys_check_root_privilege();
if (AVSYS_FAIL(err)) {
return err;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
if (control == NULL) {
avsys_error(AVAUDIO, "control is null in %s\n", __func__);
return AVSYS_STATE_ERR_NULL_POINTER;
}
if (volume_value == NULL) {
for (i = 0; i < AVSYS_AUDIO_VOLUME_TYPE_MAX; i++) {
lvolume[i] = default_volume[i];
}
} else {
avsys_audio_path_ex_info_t *path_control = NULL;
if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)&path_control))) {
avsys_error(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
if (path_control == NULL) {
avsys_error(AVAUDIO, "control is null in %s\n", __func__);
return AVSYS_STATE_ERR_NULL_POINTER;
}
for (i = 0; i < AVSYS_AUDIO_VOLUME_TYPE_MAX; i++) {
lvolume[i] = volume_value[i];
}
}
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (control->allocated & (flag << i)) { /* allocated condition */
if (AVSYS_FAIL(avsys_check_process(control->handles[i].pid))) {
/* process dead */
if (AVSYS_FAIL(avsys_audio_handle_free(i))) {
avsys_error(AVAUDIO, "Cleanup handle %d failed\n", i);
}
}
}
}
while (control->allocated) {
if (++i > 5)
break;
avsys_warning(AVAUDIO, "(%d)Waiting...0.5 sec for resume from hibernation\n", i);
printf("(%d)Waiting...0.5 sec for resume from hibernation\n", i);
usleep(500);
}
AVSYS_LOCK_SYNC();
if (volume_value == NULL) {
control->allocated = 0;
control->handle_amp = 0;
}
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_0] = lvolume[0]; /* DEFAULT_VOLUME_SYSTEM */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_1] = lvolume[1]; /* DEFAULT_VOLUME_NOTIFICATION */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_2] = lvolume[2]; /* DEFAULT_VOLUME_ALARM */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_3] = lvolume[3]; /* DEFAULT_VOLUME_RINGTONE */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_4] = lvolume[4]; /* DEFAULT_VOLUME_MEDIA */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_5] = lvolume[5]; /* DEFAULT_VOLUME_CALL */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_6] = lvolume[6]; /* DEFAULT_VOLUME_FIXED */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_7] = lvolume[7]; /* DEFAULT_VOLUME_JAVA */
control->volume_value[AVSYS_AUDIO_LVOL_GAIN_TYPE_8] = lvolume[4]; /* DEFAULT_VOLUME_MEDIA */
avsys_error(AVAUDIO, "[zeud] avsys_audio_handle_reset lvolume[0][%d]", lvolume[0]);
control->ext_device_amp = AVSYS_AUDIO_HANDLE_EXT_DEV_NONE;
control->primary_volume_pid = 0;
control->primary_volume_type = -1;
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
control->handle_priority[i] = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
}
/* Clear semaphore condition */
for (i = 0; i < AVSYS_AUDIO_LOCK_SLOT_MAX; i++) {
control->handlelock_pid[i] = -1;
}
AVSYS_UNLOCK_SYNC();
return AVSYS_STATE_SUCCESS;
}
EXPORT_API
int avsys_audio_handle_rejuvenation(void)
{
int i = 0;
long long int flag = 0x01;
int dead_handle = 0x00;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
int dead_pids[AVSYS_AUDIO_HANDLE_MAX];
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
if (control == NULL) {
avsys_error(AVAUDIO, "control is null in %s\n", __func__);
return AVSYS_STATE_ERR_NULL_POINTER;
}
AVSYS_LOCK_SYNC();
/* Clear semaphore condition */
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
dead_pids[i] = -1;
if (control->allocated & (flag << i)) { /* allocated condition */
/* check pid of handle... still alive? */
if (AVSYS_FAIL(avsys_check_process(control->handles[i].pid))) {
avsys_error(AVAUDIO, "handle %d is dead\n", i);
dead_handle |= (flag << i);
dead_pids[i] = control->handles[i].pid;
}
}
}
AVSYS_UNLOCK_SYNC();
avsys_warning(AVAUDIO, "dead_handle : 0x%0X\n", dead_handle);
/* Cleanup dead handle... */
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (dead_handle & (flag << i)) {
/* set priority of dead handle as lowest */
control->handle_priority[i] = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
/* free this handle */
avsys_error(AVAUDIO, "Cleanup handle %d...\n", i);
if (AVSYS_FAIL(avsys_audio_handle_free(i)))
avsys_error(AVAUDIO, "Cleanup handle %d failed\n", i);
}
}
if (dead_handle) {
char high_priority_exist = 0;
AVSYS_LOCK_SYNC();
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (control->handle_priority[i] > AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0) {
high_priority_exist = 1;
break;
}
}
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (control->handle_priority[i] == AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0) {
if (high_priority_exist) {
/* sink input mute immediately */
if (control->handles[i].mute == AVSYS_AUDIO_UNMUTE) {
if (AVSYS_FAIL(avsys_audio_pa_ctrl_mute_by_index(control->handles[i].stream_index, AVSYS_AUDIO_MUTE))) {
avsys_error(AVAUDIO, "set sink input mute for %d failed\n", control->handles[i].stream_index);
} else {
avsys_warning(AVAUDIO, "set sink input mute for %d success\n", control->handles[i].stream_index);
}
control->handles[i].mute = AVSYS_AUDIO_MUTE;
}
} else {
/* sink input unmute immediately */
if (control->handles[i].mute == AVSYS_AUDIO_MUTE) {
if (AVSYS_FAIL(avsys_audio_pa_ctrl_mute_by_index(control->handles[i].stream_index, AVSYS_AUDIO_UNMUTE))) {
avsys_error(AVAUDIO, "set sink input unmute for %d failed\n", control->handles[i].stream_index);
} else {
avsys_warning(AVAUDIO, "set sink input unmute for %d success\n", control->handles[i].stream_index);
}
control->handles[i].mute = AVSYS_AUDIO_UNMUTE;
}
}
} else { /* this is high priority case */
/* sink input unmute immediately */
if (control->handles[i].mute == AVSYS_AUDIO_MUTE) {
if (AVSYS_FAIL(avsys_audio_pa_ctrl_mute_by_index(control->handles[i].stream_index, AVSYS_AUDIO_UNMUTE))) {
avsys_error(AVAUDIO, "set sink input unmute for %d failed\n", control->handles[i].stream_index);
} else {
avsys_warning(AVAUDIO, "set sink input unmute for %d success\n", control->handles[i].stream_index);
}
control->handles[i].mute = AVSYS_AUDIO_UNMUTE;
}
}
}
AVSYS_UNLOCK_SYNC();
}
return AVSYS_STATE_SUCCESS;
}
EXPORT_API
int avsys_audio_handle_dump(void)
{
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
char *vol_str[] = { "System", "Notification", "Alarm", "Ringtone", "Media", "Call", "Fixed", "Java", "Media-HL" };
char *dev_str[] = { "Speaker", "Headset", "BTHeadset" };
int i = 0;
long long int flag = 0x01;
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
if (control == NULL) {
avsys_error(AVAUDIO, "control is null in %s\n", __func__);
return AVSYS_STATE_ERR_NULL_POINTER;
}
fprintf(stdout, "======================================================================\n");
fprintf(stdout, " Opened Handles Information \n");
fprintf(stdout, "======================================================================\n");
fprintf(stdout, " Avsystem Handle alloc : %016x\n", control->allocated);
for (i = 0; i < AVSYS_AUDIO_LOCK_SLOT_MAX; i++) {
if (control->handlelock_pid[i] > 0) {
fprintf(stdout, " Handle Lock PIDs : %d\n", control->handlelock_pid[i]);
}
}
fprintf(stdout, "----------------------------------------------------------------------\n");
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (control->allocated & (flag << i)) { /* allocated condition */
fprintf(stdout, " Avsystem Handle ID : %2d\n", i);
fprintf(stdout, " Run Process ID : 0x%08X (%d)\n", control->handles[i].pid, control->handles[i].pid);
fprintf(stdout, " Run Thread ID : 0x%08X (%d)\n", control->handles[i].tid, control->handles[i].tid);
fprintf(stdout, " Open Mode : %2d\n", control->handles[i].mode);
fprintf(stdout, " Format : %2d\n", control->handles[i].format);
fprintf(stdout, " Channels : %2d\n", control->handles[i].channels);
fprintf(stdout, " Samplerate : %2d\n", control->handles[i].samplerate);
fprintf(stdout, " Priority : %2d\n", control->handle_priority[i]);
if(control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_CLOCK ||
control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_VIDEO || control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY
|| control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_AP_CALL) {
if (control->handles[i].dirty_volume) {
fprintf(stdout, " Dirty volume : %s\n", vol_str[control->handles[i].gain_setting.vol_type]);
} else {
fprintf(stdout, " Volume Type : %s\n", vol_str[control->handles[i].gain_setting.vol_type]);
}
fprintf(stdout, " Target device : %s\n", dev_str[control->handles[i].gain_setting.dev_type]);
fprintf(stdout, " Maximum Len : %2d\n", control->handles[i].gain_setting.max_len);
fprintf(stdout, " UI setted volume : L:%3d R:%3d\n", control->handles[i].setting_vol.level[0], control->handles[i].setting_vol.level[1]);
fprintf(stdout, " Real working volume : L:%3d R:%3d\n", control->handles[i].working_vol.level[0], control->handles[i].working_vol.level[1]);
}
fprintf(stdout, " ----------------------------------------------------------------------\n");
}
}
fprintf(stdout, " ----------------------------------------------------------------------\n");
fprintf(stdout, " External dev amp : 0x%08X\n", control->ext_device_amp);
fprintf(stdout, " External dev status : 0x%08X\n", control->ext_device_status);
if (control->primary_volume_type >= 0) {
fprintf(stdout, " Primary Volume type : %s\n", vol_str[control->primary_volume_type]);
}
fprintf(stdout, " Volume [System] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_SYSTEM]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_SYSTEM]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Notification] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Alarm] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_ALARM]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_ALARM]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Ringtone] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Media] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [MediaHL] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Call] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_CALL]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_CALL]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Android] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, " Volume [Java] : %2d ", control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA]);
for (i = 0; i < control->volume_value[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA]; i++)
fprintf(stdout, "+");
fprintf(stdout, "\n");
fprintf(stdout, "======================================================================\n");
return AVSYS_STATE_SUCCESS;
}
int avsys_audio_handle_alloc(int *handle)
{
long long int flag = 0x01;
int i;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s\n", __func__);
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if ((control->allocated & flag) == 0) { /* alloc condition */
control->allocated |= flag;
break;
} else {
flag <<= 1;
}
}
AVSYS_UNLOCK_SYNC();
if (i == AVSYS_AUDIO_HANDLE_MAX) {
*handle = -1;
return AVSYS_STATE_ERR_RANGE_OVER;
} else {
avsys_info(AVAUDIO, "handle allocated %d\n", i);
memset(&control->handles[i], 0, sizeof(avsys_audio_handle_t));
control->handles[i].pid = getpid();
control->handles[i].tid = avsys_gettid();
*handle = i;
return AVSYS_STATE_SUCCESS;
}
}
int avsys_audio_handle_free(int handle)
{
long long int flag = 0x01;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s, handle=[%d]\n", __func__, handle);
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
flag <<= handle;
AVSYS_LOCK_SYNC();
if (control->allocated & flag) { /* find condition */
control->allocated &= ~flag;
/* clear handle mute field */
if (control->handle_amp & flag) {
control->handle_amp &= ~flag;
}
AVSYS_UNLOCK_SYNC();
return AVSYS_STATE_SUCCESS;
} else {
AVSYS_UNLOCK_SYNC();
return AVSYS_STATE_ERR_INVALID_VALUE;
}
}
int avsys_audio_handle_get_ptr(int handle, avsys_audio_handle_t **ptr, const int mode)
{
long long int flag = 0x01;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
int ret = AVSYS_STATE_SUCCESS;
//avsys_info(AVAUDIO, "%s handle %d\n", __func__, handle);
if (handle < 0 || handle >= AVSYS_AUDIO_HANDLE_MAX) {
*ptr = NULL;
return AVSYS_STATE_ERR_INVALID_HANDLE;
}
if (mode < 0 || mode >= HANDLE_PTR_MODE_NUM) {
*ptr = NULL;
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
temp = &control;
if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, (void **)temp))) {
avsys_error(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
*ptr = NULL;
return AVSYS_STATE_ERR_INTERNAL;
}
flag <<= handle;
if (mode == HANDLE_PTR_MODE_NORMAL) {
if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
*ptr = NULL;
return AVSYS_STATE_ERR_INTERNAL;
}
}
if (control->allocated & flag) {
//avsys_info(AVAUDIO, "input handle %d flag %x allocated %x\n", handle, flag, control->allocated);
*ptr = &(control->handles[handle]);
ret = AVSYS_STATE_SUCCESS;
} else {
*ptr = NULL;
ret = AVSYS_STATE_ERR_INVALID_VALUE;
}
if (mode == HANDLE_PTR_MODE_NORMAL) {
if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
*ptr = NULL;
return AVSYS_STATE_ERR_INTERNAL;
}
}
return ret;
}
int avsys_audio_handle_release_ptr(int handle, const int mode)
{
long long int flag = 0x01;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
int ret = AVSYS_STATE_SUCCESS;
//avsys_info(AVAUDIO, "%s handle %d\n", __func__, handle);
if (handle < 0 || handle >= AVSYS_AUDIO_HANDLE_MAX) {
return AVSYS_STATE_ERR_INVALID_HANDLE;
}
if (mode < 0 || mode >= HANDLE_PTR_MODE_NUM) {
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
flag <<= handle;
//avsys_info(AVAUDIO, "input handle %d flag %x allocated %x\n", handle, flag, control->allocated);
if (mode == HANDLE_PTR_MODE_NORMAL) {
AVSYS_LOCK_SYNC();
}
if (control->allocated & flag) {
ret = AVSYS_STATE_SUCCESS;
} else {
ret = AVSYS_STATE_ERR_INVALID_VALUE;
}
if (mode == HANDLE_PTR_MODE_NORMAL) {
AVSYS_UNLOCK_SYNC();
}
return ret;
}
int avsys_audio_handle_set_mute(int handle, int mute)
{
long long int flag = 0x01;
int result = AVSYS_STATE_SUCCESS;
int path_mute = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
avsys_audio_handle_t *ptr = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s_%d_%d\n", __func__, handle, mute);
if (mute > AVSYS_AUDIO_MUTE || mute < AVSYS_AUDIO_UNMUTE) {
avsys_error_r(AVAUDIO, "input parameter range error : mute %d\n", mute);
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
flag <<= handle;
AVSYS_LOCK_SYNC();
if (control->allocated & flag) { /* find condition */
/* update mute information for input handle parameter */
ptr = &(control->handles[handle]);
ptr->mute = mute;
avsys_audio_pa_ctrl_mute_by_index(ptr->stream_index, mute);
/* update handle amp information */
if (mute == AVSYS_AUDIO_UNMUTE) {
#ifdef _VERBOSE_
if (control->handle_amp & flag)
avsys_warning(AVAUDIO, "handle 0x%x already powered\n");
else
control->handle_amp |= flag;
#else
if (!(control->handle_amp & flag))
control->handle_amp |= flag;
/* reset fadedown mute */
ptr->fadeup_vol = 0;
#endif
} else if (mute == AVSYS_AUDIO_MUTE) {
/* clear handle amp field */
if (control->handle_amp & flag)
control->handle_amp &= ~flag;
#ifdef _VERBOSE_
else
avsys_warning(AVAUDIO, "handle 0x%x already off\n");
#endif
}
result = AVSYS_STATE_SUCCESS;
} else {
avsys_warning(AVAUDIO, "[%s] handle %d does not allocated\n", __func__, handle);
if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
avsys_error(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
return AVSYS_STATE_ERR_INVALID_VALUE;
}
if (control->handle_amp | control->ext_device_amp)
path_mute = AVSYS_AUDIO_UNMUTE;
else
path_mute = AVSYS_AUDIO_MUTE;
AVSYS_UNLOCK_SYNC();
if (AVSYS_FAIL(avsys_audio_path_ex_set_mute(path_mute))) {
avsys_error_r(AVAUDIO, "Path mute control failed. %s_%d\n", __func__, path_mute);
result = AVSYS_STATE_ERR_IO_CONTROL;
}
return result;
}
int avsys_audio_handle_ext_dev_set_mute(avsysaudio_ext_device_t device_type, int mute)
{
int bit = 0;
int result = AVSYS_STATE_SUCCESS;
int path_mute = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s_%d_%d\n", __func__, (int)device_type, mute);
if (mute > AVSYS_AUDIO_MUTE || mute < AVSYS_AUDIO_UNMUTE) {
avsys_error_r(AVAUDIO, "input parameter range error : mute %d\n", mute);
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
switch (device_type) {
case AVSYS_AUDIO_EXT_DEVICE_FMRADIO:
bit = AVSYS_AUDIO_HANDLE_EXT_DEV_FMRADIO;
break;
default:
avsys_error(AVAUDIO, "Unknown device type %d\n", (int)device_type);
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
if (mute == AVSYS_AUDIO_MUTE) {
control->ext_device_amp |= bit;
} else {
control->ext_device_amp &= ~bit;
}
if (control->handle_amp | control->ext_device_amp)
path_mute = AVSYS_AUDIO_UNMUTE;
else
path_mute = AVSYS_AUDIO_MUTE;
AVSYS_UNLOCK_SYNC();
if (AVSYS_FAIL(avsys_audio_path_ex_set_mute(path_mute))) {
avsys_error_r(AVAUDIO, "Path mute control failed. %s_%d\n", __func__, path_mute);
result = AVSYS_STATE_ERR_IO_CONTROL;
}
return result;
}
int avsys_audio_handle_ext_dev_status(avsysaudio_ext_device_t device_type, int *onoff)
{
int result = AVSYS_STATE_SUCCESS;
int ext_dev_state = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s\n", __func__);
if (onoff == NULL) {
avsys_error(AVAUDIO, "Null pointer input parameter\n");
return AVSYS_STATE_ERR_NULL_POINTER;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
switch (device_type) {
case AVSYS_AUDIO_EXT_DEVICE_FMRADIO:
if (control->ext_device_status & AVSYS_AUDIO_HANDLE_EXT_DEV_FMRADIO) {
ext_dev_state = 1;
} else {
ext_dev_state = 0;
}
*onoff = ext_dev_state;
break;
default:
avsys_error(AVAUDIO, "Invalid device type %d\n", device_type);
result = AVSYS_STATE_ERR_INTERNAL;
break;
}
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_ext_dev_status_update(avsysaudio_ext_device_t device_type, int onoff)
{
int bit = 0;
int result = AVSYS_STATE_SUCCESS;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s_%d_%d\n", __func__, (int)device_type, onoff);
switch (device_type) {
case AVSYS_AUDIO_EXT_DEVICE_FMRADIO:
bit = AVSYS_AUDIO_HANDLE_EXT_DEV_FMRADIO;
break;
default:
avsys_error(AVAUDIO, "Unknown device type %d\n", (int)device_type);
return AVSYS_STATE_ERR_INVALID_PARAMETER;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
if (onoff > 0) {
control->ext_device_status |= bit;
} else if (onoff == 0) {
control->ext_device_status &= ~bit;
} else {
avsys_error(AVAUDIO, "[%s] Unknown parameter %d. To nothing\n", __func__, onoff);
}
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_current_playing_volume_type(int *type)
{
int result = AVSYS_STATE_SUCCESS;
int i = 0;
char used_table[AVSYS_AUDIO_VOLUME_TYPE_MAX] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char capture_used = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
long long int flag = 0x01;
flag <<= i;
if (control->allocated & flag) {
if(control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT ||
control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_CLOCK ||
control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_VIDEO ||
control->handles[i].mode == AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY ) {
used_table[control->handles[i].gain_setting.vol_type] = 1;
}
else if(control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT ||
control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY ||
control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_LOW_LATENCY) {
capture_used = 1;
}
}
}
if (control->ext_device_status & AVSYS_AUDIO_HANDLE_EXT_DEV_FMRADIO) {
used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA] = 1;
}
avsys_warning(AVAUDIO,"Call[%d] Ringtone[%d] Media[%d] MediaHL[%d] Alarm[%d] Notification[%d] System[%d] Android[%d] Java[%d] Capture[%d]\n",
used_table[AVSYS_AUDIO_VOLUME_TYPE_CALL],
used_table[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE],
used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA],
used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL],
used_table[AVSYS_AUDIO_VOLUME_TYPE_ALARM],
used_table[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION],
used_table[AVSYS_AUDIO_VOLUME_TYPE_SYSTEM],
used_table[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_ANDROID],
used_table[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA],
capture_used);
if (control->primary_volume_pid > 2 && AVSYS_FAIL(avsys_check_process(control->primary_volume_pid))) {
avsys_warning(AVAUDIO, "Primary volume set pid does not exist anymore. clean primary volume\n");
control->primary_volume_type = -1;
control->primary_volume_pid = 0;
}
if (control->primary_volume_type != -1) {
*type = control->primary_volume_type;
avsys_warning(AVAUDIO, "Primary volume is %d\n", control->primary_volume_type);
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_CALL]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_CALL;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_RINGTONE]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_RINGTONE;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_MEDIA;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_MEDIA_HL]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_MEDIA;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_ALARM]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_ALARM;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_NOTIFICATION;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_SYSTEM]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_SYSTEM;
} else if (used_table[AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA]) {
*type = AVSYS_AUDIO_VOLUME_TYPE_EXT_SYSTEM_JAVA;
} else if (capture_used) {
/* No Playing instance just capture only. */
result = AVSYS_STATE_ERR_INVALID_MODE;
avsys_error(AVAUDIO, "Capture handle only...\n");
} else {
/* not playing */
result = AVSYS_STATE_ERR_ALLOCATION;
avsys_error(AVAUDIO, "There is no running handles...\n");
}
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_update_volume(avsys_audio_handle_t *p, const int vol_type)
{
int result = AVSYS_STATE_SUCCESS;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_audio_volume_t *set_volume = NULL;
int volume_type = vol_type;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
set_volume = &(p->setting_vol);
set_volume->level[AVSYS_AUDIO_CHANNEL_LEFT] = control->volume_value[volume_type];
set_volume->level[AVSYS_AUDIO_CHANNEL_RIGHT] = control->volume_value[volume_type];
result = avsys_audio_logical_volume_convert(set_volume, &(p->working_vol), &(p->gain_setting));
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_update_volume_by_type(const int volume_type, const int volume_value)
{
int i;
int result = AVSYS_STATE_SUCCESS;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s\n", __func__);
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
control->volume_value[volume_type] = volume_value;
avsys_error(AVAUDIO, "[zeud] avsys_audio_handle_update_volume_by_type volume_value[%d]", volume_value);
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
int mode;
avsys_audio_volume_t *set_volume = NULL;
long long int flag = 0x01;
flag <<= i;
if ((control->allocated & flag) == 0) {
continue;
}
mode = control->handles[i].mode;
if (mode != AVSYS_AUDIO_MODE_OUTPUT && mode != AVSYS_AUDIO_MODE_OUTPUT_CLOCK
&& mode != AVSYS_AUDIO_MODE_OUTPUT_VIDEO && mode != AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY
&& mode != AVSYS_AUDIO_MODE_OUTPUT_AP_CALL) {
continue;
}
if (control->handles[i].gain_setting.vol_type != volume_type) {
continue;
}
if (control->handles[i].dirty_volume) {
/* This is volatile volume per handle */
continue;
}
set_volume = &(control->handles[i].setting_vol);
set_volume->level[AVSYS_AUDIO_CHANNEL_LEFT] = control->volume_value[volume_type];
set_volume->level[AVSYS_AUDIO_CHANNEL_RIGHT] = control->volume_value[volume_type];
avsys_error(AVAUDIO, "[zeud] avsys_audio_handle_update_volume_by_type control->volume_value[volume_type][%d]", control->volume_value[volume_type]);
result = avsys_audio_logical_volume_convert(set_volume, &(control->handles[i].working_vol), &(control->handles[i].gain_setting));
if (AVSYS_FAIL(result)) {
avsys_error(AVAUDIO, "Can not set volume for handle %d. Error 0x%x\n", i, result);
break;
}
avsys_warning(AVAUDIO, "stream index %d\n", control->handles[i].stream_index);
if (AVSYS_FAIL(avsys_audio_pa_ctrl_volume_by_index(control->handles[i].stream_index, control->handles[i].working_vol.level[AVSYS_AUDIO_CHANNEL_LEFT], control->handles[i].channels))) {
avsys_error(AVAUDIO, "avsys_audio_pa_ctrl_volume_by_index() failed\n");
}
}
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_set_primary_volume_type(const int pid, const int type, const int command)
{
int result = AVSYS_STATE_SUCCESS;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
temp = &control;
avsys_info(AVAUDIO, "%s\n", __func__);
if (type < AVSYS_AUDIO_VOLUME_TYPE_SYSTEM || type >= AVSYS_AUDIO_VOLUME_TYPE_MAX || type == AVSYS_AUDIO_VOLUME_TYPE_FIXED) {
avsys_error(AVAUDIO, "Invalid primary type primary type\n");
return AVSYS_STATE_ERR_INTERNAL;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
if (command == AVSYS_AUDIO_PRIMARY_VOLUME_SET) {
if (control->primary_volume_type != -1) {
avsys_warning(AVAUDIO,"Previous primary volume set by %d to %d\n",
control->primary_volume_pid,
control->primary_volume_type
);
}
avsys_warning(AVAUDIO, "Primary Volume Type Set to %d [%d]\n", type, pid);
control->primary_volume_pid = pid;
control->primary_volume_type = type;
} else if (command == AVSYS_AUDIO_PRIMARY_VOLUME_CLEAR) {
if (pid != control->primary_volume_pid) {
avsys_error(AVAUDIO, "Primary volume set api pair is not matched [%d] [%d]\n", control->primary_volume_pid, pid);
} else {
avsys_warning(AVAUDIO, "Primary Volume Type Clear [%d]\n", pid);
control->primary_volume_pid = 0;
control->primary_volume_type = -1;
}
} else {
avsys_error(AVAUDIO, "Unknown Parameter : %d\n", command);
result = AVSYS_STATE_ERR_INVALID_PARAMETER;
}
AVSYS_UNLOCK_SYNC();
return result;
}
int avsys_audio_handle_update_priority(int handle, int priority, int handle_route, int cmd)
{
long long int flag = 0x01;
int path_mute = 0, i = 0;
char high_priority_exist = 0;
char transition_effect = 0;
int lpriority = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
int sink_info = 0;
temp = &control;
if (cmd < AVSYS_AUDIO_SET_PRIORITY || cmd > AVSYS_AUDIO_UNSET_PRIORITY) {
avsys_error_r(AVAUDIO, "Invalid command %s\n", __func__);
return AVSYS_STATE_ERR_INTERNAL;
}
if (priority >= AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_MAX || priority < AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0) {
avsys_error(AVAUDIO, "input parameter range error : priority %d. set lowest\n", priority);
lpriority = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
} else {
lpriority = priority;
}
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
flag <<= handle;
AVSYS_LOCK_SYNC();
if (control->allocated & flag) { /* find condition */
/* update for allocated handle */
if (cmd == AVSYS_AUDIO_SET_PRIORITY) {
control->handle_priority[handle] = lpriority;
} else if (cmd == AVSYS_AUDIO_UNSET_PRIORITY) {
control->handle_priority[handle] = AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0;
if (lpriority == AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_2) { /* unset with priority 2 */
transition_effect = 1;
}
}
} else {
avsys_warning(AVAUDIO, "[%s] handle %d does not allocated\n", __func__, handle);
AVSYS_UNLOCK_SYNC();
return AVSYS_STATE_ERR_INVALID_VALUE;
}
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
if (control->handle_priority[i] == AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_1) {
high_priority_exist = 1;
} else if (control->handle_priority[i] == AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_2) {
high_priority_exist = 1;
transition_effect = 1;
}
}
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
flag = 0x01;
flag <<= i;
if (!(control->allocated & flag))
continue;
if (control->handles[i].stream_index == 0) {
avsys_warning(AVAUDIO, "handle[%d] has stream index 0, skip....(only mono sink-input use 0)\n", i);
continue;
}
if (control->handle_priority[i] == AVSYS_AUDIO_HANDLE_PRIORITY_TYPE_0) {
if (high_priority_exist) { /* mute */
if (transition_effect) {
/* set fade out */
if (control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_LEFT] >= control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_RIGHT]) {
control->handles[i].fadeup_vol = (-1) * control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_LEFT];
} else {
control->handles[i].fadeup_vol = (-1) * control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_RIGHT];
}
control->handles[i].fadeup_multiplier = 0;
} else {
/* mute immediately */
if (AVSYS_FAIL(avsys_audio_pa_ctrl_mute_by_index(control->handles[i].stream_index, AVSYS_AUDIO_MUTE))) {
avsys_error(AVAUDIO, "set sink input mute for %d failed\n", control->handles[i].stream_index);
} else {
avsys_warning(AVAUDIO, "set sink input mute for %d success\n", control->handles[i].stream_index);
}
control->handles[i].mute = AVSYS_AUDIO_MUTE;
}
} else { /* unmute */
if (transition_effect) {
/* set fade in */
if (control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_LEFT] >= control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_RIGHT]) {
control->handles[i].fadeup_vol = control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_LEFT];
} else {
control->handles[i].fadeup_vol = control->handles[i].setting_vol.level[AVSYS_AUDIO_CHANNEL_RIGHT];
}
control->handles[i].fadeup_multiplier = 0;
} else {
/* unmute immediately */
if (control->handles[i].mute != AVSYS_AUDIO_UNMUTE) {
if (AVSYS_FAIL(avsys_audio_pa_ctrl_mute_by_index(control->handles[i].stream_index, AVSYS_AUDIO_UNMUTE))) {
avsys_error(AVAUDIO, "set sink input unmute for %d failed\n", control->handles[i].stream_index);
} else {
avsys_warning(AVAUDIO, "set sink input unmute for %d success\n", control->handles[i].stream_index);
}
control->handles[i].mute = AVSYS_AUDIO_UNMUTE;
}
}
}
}
}
AVSYS_UNLOCK_SYNC();
if (transition_effect)
sleep(1);
else if (!transition_effect && high_priority_exist)
usleep(20);
return AVSYS_STATE_SUCCESS;
}
int avsys_audio_handle_current_capture_status(int *on_capture)
{
int i = 0;
char capture_used = 0;
avsys_audio_handle_info_t *control = NULL;
avsys_audio_handle_info_t **temp = NULL;
if (!on_capture)
return AVSYS_STATE_ERR_INVALID_PARAMETER;
temp = &control;
AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL);
AVSYS_LOCK_SYNC();
for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) {
long long int flag = 0x01;
flag <<= i;
if (control->allocated & flag) {
if(control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT ||
control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_HIGH_LATENCY ||
control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_LOW_LATENCY ||
control->handles[i].mode == AVSYS_AUDIO_MODE_INPUT_AP_CALL) {
capture_used = 1;
break;
}
}
}
if (capture_used) {
avsys_info(AVAUDIO, "Audio capture is running\n");
*on_capture = 1;
} else {
*on_capture = 0;
}
AVSYS_UNLOCK_SYNC();
return AVSYS_STATE_SUCCESS;
}
|