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
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
|
/*
**
** Copyright 2007, The Android Open Source Project
**
** 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.
*/
#define LOG_TAG "IAudioFlinger"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IAudioFlinger.h>
namespace android {
enum {
CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
OPEN_RECORD,
SAMPLE_RATE,
RESERVED, // obsolete, was CHANNEL_COUNT
FORMAT,
FRAME_COUNT,
LATENCY,
SET_MASTER_VOLUME,
SET_MASTER_MUTE,
MASTER_VOLUME,
MASTER_MUTE,
SET_STREAM_VOLUME,
SET_STREAM_MUTE,
STREAM_VOLUME,
STREAM_MUTE,
SET_MODE,
SET_MIC_MUTE,
GET_MIC_MUTE,
SET_PARAMETERS,
GET_PARAMETERS,
REGISTER_CLIENT,
GET_INPUTBUFFERSIZE,
OPEN_OUTPUT,
OPEN_DUPLICATE_OUTPUT,
CLOSE_OUTPUT,
SUSPEND_OUTPUT,
RESTORE_OUTPUT,
OPEN_INPUT,
CLOSE_INPUT,
INVALIDATE_STREAM,
SET_VOICE_VOLUME,
GET_RENDER_POSITION,
GET_INPUT_FRAMES_LOST,
NEW_AUDIO_SESSION_ID,
ACQUIRE_AUDIO_SESSION_ID,
RELEASE_AUDIO_SESSION_ID,
QUERY_NUM_EFFECTS,
QUERY_EFFECT,
GET_EFFECT_DESCRIPTOR,
CREATE_EFFECT,
MOVE_EFFECTS,
LOAD_HW_MODULE,
GET_PRIMARY_OUTPUT_SAMPLING_RATE,
GET_PRIMARY_OUTPUT_FRAME_COUNT,
SET_LOW_RAM_DEVICE,
LIST_AUDIO_PORTS,
GET_AUDIO_PORT,
CREATE_AUDIO_PATCH,
RELEASE_AUDIO_PATCH,
LIST_AUDIO_PATCHES,
SET_AUDIO_PORT_CONFIG,
GET_AUDIO_HW_SYNC
};
class BpAudioFlinger : public BpInterface<IAudioFlinger>
{
public:
BpAudioFlinger(const sp<IBinder>& impl)
: BpInterface<IAudioFlinger>(impl)
{
}
virtual sp<IAudioTrack> createTrack(
audio_stream_type_t streamType,
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
size_t *pFrameCount,
track_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
pid_t tid,
int *sessionId,
int clientUid,
status_t *status)
{
Parcel data, reply;
sp<IAudioTrack> track;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) streamType);
data.writeInt32(sampleRate);
data.writeInt32(format);
data.writeInt32(channelMask);
size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
data.writeInt64(frameCount);
track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
data.writeInt32(lFlags);
// haveSharedBuffer
if (sharedBuffer != 0) {
data.writeInt32(true);
data.writeStrongBinder(sharedBuffer->asBinder());
} else {
data.writeInt32(false);
}
data.writeInt32((int32_t) output);
data.writeInt32((int32_t) tid);
int lSessionId = AUDIO_SESSION_ALLOCATE;
if (sessionId != NULL) {
lSessionId = *sessionId;
}
data.writeInt32(lSessionId);
data.writeInt32(clientUid);
status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
if (lStatus != NO_ERROR) {
ALOGE("createTrack error: %s", strerror(-lStatus));
} else {
frameCount = reply.readInt64();
if (pFrameCount != NULL) {
*pFrameCount = frameCount;
}
lFlags = reply.readInt32();
if (flags != NULL) {
*flags = lFlags;
}
lSessionId = reply.readInt32();
if (sessionId != NULL) {
*sessionId = lSessionId;
}
lStatus = reply.readInt32();
track = interface_cast<IAudioTrack>(reply.readStrongBinder());
if (lStatus == NO_ERROR) {
if (track == 0) {
ALOGE("createTrack should have returned an IAudioTrack");
lStatus = UNKNOWN_ERROR;
}
} else {
if (track != 0) {
ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
track.clear();
}
}
}
if (status != NULL) {
*status = lStatus;
}
return track;
}
virtual sp<IAudioRecord> openRecord(
audio_io_handle_t input,
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
size_t *pFrameCount,
track_flags_t *flags,
pid_t tid,
int *sessionId,
size_t *notificationFrames,
sp<IMemory>& cblk,
sp<IMemory>& buffers,
status_t *status)
{
Parcel data, reply;
sp<IAudioRecord> record;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) input);
data.writeInt32(sampleRate);
data.writeInt32(format);
data.writeInt32(channelMask);
size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
data.writeInt64(frameCount);
track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
data.writeInt32(lFlags);
data.writeInt32((int32_t) tid);
int lSessionId = AUDIO_SESSION_ALLOCATE;
if (sessionId != NULL) {
lSessionId = *sessionId;
}
data.writeInt32(lSessionId);
data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
cblk.clear();
buffers.clear();
status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
if (lStatus != NO_ERROR) {
ALOGE("openRecord error: %s", strerror(-lStatus));
} else {
frameCount = reply.readInt64();
if (pFrameCount != NULL) {
*pFrameCount = frameCount;
}
lFlags = reply.readInt32();
if (flags != NULL) {
*flags = lFlags;
}
lSessionId = reply.readInt32();
if (sessionId != NULL) {
*sessionId = lSessionId;
}
size_t lNotificationFrames = (size_t) reply.readInt64();
if (notificationFrames != NULL) {
*notificationFrames = lNotificationFrames;
}
lStatus = reply.readInt32();
record = interface_cast<IAudioRecord>(reply.readStrongBinder());
cblk = interface_cast<IMemory>(reply.readStrongBinder());
if (cblk != 0 && cblk->pointer() == NULL) {
cblk.clear();
}
buffers = interface_cast<IMemory>(reply.readStrongBinder());
if (buffers != 0 && buffers->pointer() == NULL) {
buffers.clear();
}
if (lStatus == NO_ERROR) {
if (record == 0) {
ALOGE("openRecord should have returned an IAudioRecord");
lStatus = UNKNOWN_ERROR;
} else if (cblk == 0) {
ALOGE("openRecord should have returned a cblk");
lStatus = NO_MEMORY;
}
// buffers is permitted to be 0
} else {
if (record != 0 || cblk != 0 || buffers != 0) {
ALOGE("openRecord returned an IAudioRecord, cblk, "
"or buffers but with status %d", lStatus);
}
}
if (lStatus != NO_ERROR) {
record.clear();
cblk.clear();
buffers.clear();
}
}
if (status != NULL) {
*status = lStatus;
}
return record;
}
virtual uint32_t sampleRate(audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(SAMPLE_RATE, data, &reply);
return reply.readInt32();
}
virtual audio_format_t format(audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(FORMAT, data, &reply);
return (audio_format_t) reply.readInt32();
}
virtual size_t frameCount(audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(FRAME_COUNT, data, &reply);
return reply.readInt64();
}
virtual uint32_t latency(audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(LATENCY, data, &reply);
return reply.readInt32();
}
virtual status_t setMasterVolume(float value)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeFloat(value);
remote()->transact(SET_MASTER_VOLUME, data, &reply);
return reply.readInt32();
}
virtual status_t setMasterMute(bool muted)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(muted);
remote()->transact(SET_MASTER_MUTE, data, &reply);
return reply.readInt32();
}
virtual float masterVolume() const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
remote()->transact(MASTER_VOLUME, data, &reply);
return reply.readFloat();
}
virtual bool masterMute() const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
remote()->transact(MASTER_MUTE, data, &reply);
return reply.readInt32();
}
virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
audio_io_handle_t output)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) stream);
data.writeFloat(value);
data.writeInt32((int32_t) output);
remote()->transact(SET_STREAM_VOLUME, data, &reply);
return reply.readInt32();
}
virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) stream);
data.writeInt32(muted);
remote()->transact(SET_STREAM_MUTE, data, &reply);
return reply.readInt32();
}
virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) stream);
data.writeInt32((int32_t) output);
remote()->transact(STREAM_VOLUME, data, &reply);
return reply.readFloat();
}
virtual bool streamMute(audio_stream_type_t stream) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) stream);
remote()->transact(STREAM_MUTE, data, &reply);
return reply.readInt32();
}
virtual status_t setMode(audio_mode_t mode)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(mode);
remote()->transact(SET_MODE, data, &reply);
return reply.readInt32();
}
virtual status_t setMicMute(bool state)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(state);
remote()->transact(SET_MIC_MUTE, data, &reply);
return reply.readInt32();
}
virtual bool getMicMute() const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
remote()->transact(GET_MIC_MUTE, data, &reply);
return reply.readInt32();
}
virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) ioHandle);
data.writeString8(keyValuePairs);
remote()->transact(SET_PARAMETERS, data, &reply);
return reply.readInt32();
}
virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) ioHandle);
data.writeString8(keys);
remote()->transact(GET_PARAMETERS, data, &reply);
return reply.readString8();
}
virtual void registerClient(const sp<IAudioFlingerClient>& client)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeStrongBinder(client->asBinder());
remote()->transact(REGISTER_CLIENT, data, &reply);
}
virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
audio_channel_mask_t channelMask) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(sampleRate);
data.writeInt32(format);
data.writeInt32(channelMask);
remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
return reply.readInt64();
}
virtual status_t openOutput(audio_module_handle_t module,
audio_io_handle_t *output,
audio_config_t *config,
audio_devices_t *devices,
const String8& address,
uint32_t *latencyMs,
audio_output_flags_t flags)
{
if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(module);
data.write(config, sizeof(audio_config_t));
data.writeInt32(*devices);
data.writeString8(address);
data.writeInt32((int32_t) flags);
status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
if (status != NO_ERROR) {
*output = AUDIO_IO_HANDLE_NONE;
return status;
}
status = (status_t)reply.readInt32();
if (status != NO_ERROR) {
*output = AUDIO_IO_HANDLE_NONE;
return status;
}
*output = (audio_io_handle_t)reply.readInt32();
ALOGV("openOutput() returned output, %d", *output);
reply.read(config, sizeof(audio_config_t));
*devices = (audio_devices_t)reply.readInt32();
*latencyMs = reply.readInt32();
return NO_ERROR;
}
virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
audio_io_handle_t output2)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output1);
data.writeInt32((int32_t) output2);
remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
return (audio_io_handle_t) reply.readInt32();
}
virtual status_t closeOutput(audio_io_handle_t output)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(CLOSE_OUTPUT, data, &reply);
return reply.readInt32();
}
virtual status_t suspendOutput(audio_io_handle_t output)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(SUSPEND_OUTPUT, data, &reply);
return reply.readInt32();
}
virtual status_t restoreOutput(audio_io_handle_t output)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(RESTORE_OUTPUT, data, &reply);
return reply.readInt32();
}
virtual status_t openInput(audio_module_handle_t module,
audio_io_handle_t *input,
audio_config_t *config,
audio_devices_t *device,
const String8& address,
audio_source_t source,
audio_input_flags_t flags)
{
if (input == NULL || config == NULL || device == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(module);
data.writeInt32(*input);
data.write(config, sizeof(audio_config_t));
data.writeInt32(*device);
data.writeString8(address);
data.writeInt32(source);
data.writeInt32(flags);
status_t status = remote()->transact(OPEN_INPUT, data, &reply);
if (status != NO_ERROR) {
*input = AUDIO_IO_HANDLE_NONE;
return status;
}
status = (status_t)reply.readInt32();
if (status != NO_ERROR) {
*input = AUDIO_IO_HANDLE_NONE;
return status;
}
*input = (audio_io_handle_t)reply.readInt32();
reply.read(config, sizeof(audio_config_t));
*device = (audio_devices_t)reply.readInt32();
return NO_ERROR;
}
virtual status_t closeInput(int input)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(input);
remote()->transact(CLOSE_INPUT, data, &reply);
return reply.readInt32();
}
virtual status_t invalidateStream(audio_stream_type_t stream)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) stream);
remote()->transact(INVALIDATE_STREAM, data, &reply);
return reply.readInt32();
}
virtual status_t setVoiceVolume(float volume)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeFloat(volume);
remote()->transact(SET_VOICE_VOLUME, data, &reply);
return reply.readInt32();
}
virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
audio_io_handle_t output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) output);
remote()->transact(GET_RENDER_POSITION, data, &reply);
status_t status = reply.readInt32();
if (status == NO_ERROR) {
uint32_t tmp = reply.readInt32();
if (halFrames != NULL) {
*halFrames = tmp;
}
tmp = reply.readInt32();
if (dspFrames != NULL) {
*dspFrames = tmp;
}
}
return status;
}
virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int32_t) ioHandle);
status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
if (status != NO_ERROR) {
return 0;
}
return (uint32_t) reply.readInt32();
}
virtual audio_unique_id_t newAudioUniqueId()
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
if (status == NO_ERROR) {
id = reply.readInt32();
}
return id;
}
virtual void acquireAudioSessionId(int audioSession, int pid)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(audioSession);
data.writeInt32(pid);
remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
}
virtual void releaseAudioSessionId(int audioSession, int pid)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(audioSession);
data.writeInt32(pid);
remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
}
virtual status_t queryNumberEffects(uint32_t *numEffects) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
if (status != NO_ERROR) {
return status;
}
status = reply.readInt32();
if (status != NO_ERROR) {
return status;
}
if (numEffects != NULL) {
*numEffects = (uint32_t)reply.readInt32();
}
return NO_ERROR;
}
virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
{
if (pDescriptor == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(index);
status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
if (status != NO_ERROR) {
return status;
}
status = reply.readInt32();
if (status != NO_ERROR) {
return status;
}
reply.read(pDescriptor, sizeof(effect_descriptor_t));
return NO_ERROR;
}
virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
effect_descriptor_t *pDescriptor) const
{
if (pUuid == NULL || pDescriptor == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(pUuid, sizeof(effect_uuid_t));
status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
if (status != NO_ERROR) {
return status;
}
status = reply.readInt32();
if (status != NO_ERROR) {
return status;
}
reply.read(pDescriptor, sizeof(effect_descriptor_t));
return NO_ERROR;
}
virtual sp<IEffect> createEffect(
effect_descriptor_t *pDesc,
const sp<IEffectClient>& client,
int32_t priority,
audio_io_handle_t output,
int sessionId,
status_t *status,
int *id,
int *enabled)
{
Parcel data, reply;
sp<IEffect> effect;
if (pDesc == NULL) {
return effect;
if (status != NULL) {
*status = BAD_VALUE;
}
}
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(pDesc, sizeof(effect_descriptor_t));
data.writeStrongBinder(client->asBinder());
data.writeInt32(priority);
data.writeInt32((int32_t) output);
data.writeInt32(sessionId);
status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
if (lStatus != NO_ERROR) {
ALOGE("createEffect error: %s", strerror(-lStatus));
} else {
lStatus = reply.readInt32();
int tmp = reply.readInt32();
if (id != NULL) {
*id = tmp;
}
tmp = reply.readInt32();
if (enabled != NULL) {
*enabled = tmp;
}
effect = interface_cast<IEffect>(reply.readStrongBinder());
reply.read(pDesc, sizeof(effect_descriptor_t));
}
if (status != NULL) {
*status = lStatus;
}
return effect;
}
virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
audio_io_handle_t dstOutput)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(session);
data.writeInt32((int32_t) srcOutput);
data.writeInt32((int32_t) dstOutput);
remote()->transact(MOVE_EFFECTS, data, &reply);
return reply.readInt32();
}
virtual audio_module_handle_t loadHwModule(const char *name)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeCString(name);
remote()->transact(LOAD_HW_MODULE, data, &reply);
return (audio_module_handle_t) reply.readInt32();
}
virtual uint32_t getPrimaryOutputSamplingRate()
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
return reply.readInt32();
}
virtual size_t getPrimaryOutputFrameCount()
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
return reply.readInt64();
}
virtual status_t setLowRamDevice(bool isLowRamDevice)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32((int) isLowRamDevice);
remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
return reply.readInt32();
}
virtual status_t listAudioPorts(unsigned int *num_ports,
struct audio_port *ports)
{
if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(*num_ports);
status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
if (status != NO_ERROR ||
(status = (status_t)reply.readInt32()) != NO_ERROR) {
return status;
}
*num_ports = (unsigned int)reply.readInt32();
reply.read(ports, *num_ports * sizeof(struct audio_port));
return status;
}
virtual status_t getAudioPort(struct audio_port *port)
{
if (port == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(port, sizeof(struct audio_port));
status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
if (status != NO_ERROR ||
(status = (status_t)reply.readInt32()) != NO_ERROR) {
return status;
}
reply.read(port, sizeof(struct audio_port));
return status;
}
virtual status_t createAudioPatch(const struct audio_patch *patch,
audio_patch_handle_t *handle)
{
if (patch == NULL || handle == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(patch, sizeof(struct audio_patch));
data.write(handle, sizeof(audio_patch_handle_t));
status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
if (status != NO_ERROR ||
(status = (status_t)reply.readInt32()) != NO_ERROR) {
return status;
}
reply.read(handle, sizeof(audio_patch_handle_t));
return status;
}
virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(&handle, sizeof(audio_patch_handle_t));
status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
if (status != NO_ERROR) {
status = (status_t)reply.readInt32();
}
return status;
}
virtual status_t listAudioPatches(unsigned int *num_patches,
struct audio_patch *patches)
{
if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(*num_patches);
status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
if (status != NO_ERROR ||
(status = (status_t)reply.readInt32()) != NO_ERROR) {
return status;
}
*num_patches = (unsigned int)reply.readInt32();
reply.read(patches, *num_patches * sizeof(struct audio_patch));
return status;
}
virtual status_t setAudioPortConfig(const struct audio_port_config *config)
{
if (config == NULL) {
return BAD_VALUE;
}
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.write(config, sizeof(struct audio_port_config));
status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
if (status != NO_ERROR) {
status = (status_t)reply.readInt32();
}
return status;
}
virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
data.writeInt32(sessionId);
status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
if (status != NO_ERROR) {
return AUDIO_HW_SYNC_INVALID;
}
return (audio_hw_sync_t)reply.readInt32();
}
};
IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
// ----------------------------------------------------------------------
status_t BnAudioFlinger::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch (code) {
case CREATE_TRACK: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int streamType = data.readInt32();
uint32_t sampleRate = data.readInt32();
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
size_t frameCount = data.readInt64();
track_flags_t flags = (track_flags_t) data.readInt32();
bool haveSharedBuffer = data.readInt32() != 0;
sp<IMemory> buffer;
if (haveSharedBuffer) {
buffer = interface_cast<IMemory>(data.readStrongBinder());
}
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
pid_t tid = (pid_t) data.readInt32();
int sessionId = data.readInt32();
int clientUid = data.readInt32();
status_t status;
sp<IAudioTrack> track;
if ((haveSharedBuffer && (buffer == 0)) ||
((buffer != 0) && (buffer->pointer() == NULL))) {
ALOGW("CREATE_TRACK: cannot retrieve shared memory");
status = DEAD_OBJECT;
} else {
track = createTrack(
(audio_stream_type_t) streamType, sampleRate, format,
channelMask, &frameCount, &flags, buffer, output, tid,
&sessionId, clientUid, &status);
LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
}
reply->writeInt64(frameCount);
reply->writeInt32(flags);
reply->writeInt32(sessionId);
reply->writeInt32(status);
reply->writeStrongBinder(track->asBinder());
return NO_ERROR;
} break;
case OPEN_RECORD: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
uint32_t sampleRate = data.readInt32();
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
size_t frameCount = data.readInt64();
track_flags_t flags = (track_flags_t) data.readInt32();
pid_t tid = (pid_t) data.readInt32();
int sessionId = data.readInt32();
size_t notificationFrames = data.readInt64();
sp<IMemory> cblk;
sp<IMemory> buffers;
status_t status;
sp<IAudioRecord> record = openRecord(input,
sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
¬ificationFrames,
cblk, buffers, &status);
LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
reply->writeInt64(frameCount);
reply->writeInt32(flags);
reply->writeInt32(sessionId);
reply->writeInt64(notificationFrames);
reply->writeInt32(status);
reply->writeStrongBinder(record->asBinder());
reply->writeStrongBinder(cblk->asBinder());
reply->writeStrongBinder(buffers->asBinder());
return NO_ERROR;
} break;
case SAMPLE_RATE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
return NO_ERROR;
} break;
case FORMAT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
return NO_ERROR;
} break;
case FRAME_COUNT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
return NO_ERROR;
} break;
case LATENCY: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
return NO_ERROR;
} break;
case SET_MASTER_VOLUME: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( setMasterVolume(data.readFloat()) );
return NO_ERROR;
} break;
case SET_MASTER_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( setMasterMute(data.readInt32()) );
return NO_ERROR;
} break;
case MASTER_VOLUME: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeFloat( masterVolume() );
return NO_ERROR;
} break;
case MASTER_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( masterMute() );
return NO_ERROR;
} break;
case SET_STREAM_VOLUME: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int stream = data.readInt32();
float volume = data.readFloat();
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
return NO_ERROR;
} break;
case SET_STREAM_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int stream = data.readInt32();
reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
return NO_ERROR;
} break;
case STREAM_VOLUME: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int stream = data.readInt32();
int output = data.readInt32();
reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
return NO_ERROR;
} break;
case STREAM_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int stream = data.readInt32();
reply->writeInt32( streamMute((audio_stream_type_t) stream) );
return NO_ERROR;
} break;
case SET_MODE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_mode_t mode = (audio_mode_t) data.readInt32();
reply->writeInt32( setMode(mode) );
return NO_ERROR;
} break;
case SET_MIC_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int state = data.readInt32();
reply->writeInt32( setMicMute(state) );
return NO_ERROR;
} break;
case GET_MIC_MUTE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32( getMicMute() );
return NO_ERROR;
} break;
case SET_PARAMETERS: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
String8 keyValuePairs(data.readString8());
reply->writeInt32(setParameters(ioHandle, keyValuePairs));
return NO_ERROR;
} break;
case GET_PARAMETERS: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
String8 keys(data.readString8());
reply->writeString8(getParameters(ioHandle, keys));
return NO_ERROR;
} break;
case REGISTER_CLIENT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
data.readStrongBinder());
registerClient(client);
return NO_ERROR;
} break;
case GET_INPUTBUFFERSIZE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
uint32_t sampleRate = data.readInt32();
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
return NO_ERROR;
} break;
case OPEN_OUTPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
audio_config_t config;
data.read(&config, sizeof(audio_config_t));
audio_devices_t devices = (audio_devices_t)data.readInt32();
String8 address(data.readString8());
audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
uint32_t latencyMs;
audio_io_handle_t output;
status_t status = openOutput(module, &output, &config,
&devices, address, &latencyMs, flags);
ALOGV("OPEN_OUTPUT output, %d", output);
reply->writeInt32((int32_t)status);
if (status == NO_ERROR) {
reply->writeInt32((int32_t)output);
reply->write(&config, sizeof(audio_config_t));
reply->writeInt32(devices);
reply->writeInt32(latencyMs);
}
return NO_ERROR;
} break;
case OPEN_DUPLICATE_OUTPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
return NO_ERROR;
} break;
case CLOSE_OUTPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
return NO_ERROR;
} break;
case SUSPEND_OUTPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
return NO_ERROR;
} break;
case RESTORE_OUTPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
return NO_ERROR;
} break;
case OPEN_INPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
audio_config_t config;
data.read(&config, sizeof(audio_config_t));
audio_devices_t device = (audio_devices_t)data.readInt32();
String8 address(data.readString8());
audio_source_t source = (audio_source_t)data.readInt32();
audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
status_t status = openInput(module, &input, &config,
&device, address, source, flags);
reply->writeInt32((int32_t) status);
if (status == NO_ERROR) {
reply->writeInt32((int32_t) input);
reply->write(&config, sizeof(audio_config_t));
reply->writeInt32(device);
}
return NO_ERROR;
} break;
case CLOSE_INPUT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
return NO_ERROR;
} break;
case INVALIDATE_STREAM: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
reply->writeInt32(invalidateStream(stream));
return NO_ERROR;
} break;
case SET_VOICE_VOLUME: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
float volume = data.readFloat();
reply->writeInt32( setVoiceVolume(volume) );
return NO_ERROR;
} break;
case GET_RENDER_POSITION: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
uint32_t halFrames;
uint32_t dspFrames;
status_t status = getRenderPosition(&halFrames, &dspFrames, output);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->writeInt32(halFrames);
reply->writeInt32(dspFrames);
}
return NO_ERROR;
}
case GET_INPUT_FRAMES_LOST: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
return NO_ERROR;
} break;
case NEW_AUDIO_SESSION_ID: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(newAudioUniqueId());
return NO_ERROR;
} break;
case ACQUIRE_AUDIO_SESSION_ID: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int audioSession = data.readInt32();
int pid = data.readInt32();
acquireAudioSessionId(audioSession, pid);
return NO_ERROR;
} break;
case RELEASE_AUDIO_SESSION_ID: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int audioSession = data.readInt32();
int pid = data.readInt32();
releaseAudioSessionId(audioSession, pid);
return NO_ERROR;
} break;
case QUERY_NUM_EFFECTS: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
uint32_t numEffects;
status_t status = queryNumberEffects(&numEffects);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->writeInt32((int32_t)numEffects);
}
return NO_ERROR;
}
case QUERY_EFFECT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
effect_descriptor_t desc;
status_t status = queryEffect(data.readInt32(), &desc);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->write(&desc, sizeof(effect_descriptor_t));
}
return NO_ERROR;
}
case GET_EFFECT_DESCRIPTOR: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
effect_uuid_t uuid;
data.read(&uuid, sizeof(effect_uuid_t));
effect_descriptor_t desc;
status_t status = getEffectDescriptor(&uuid, &desc);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->write(&desc, sizeof(effect_descriptor_t));
}
return NO_ERROR;
}
case CREATE_EFFECT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
effect_descriptor_t desc;
data.read(&desc, sizeof(effect_descriptor_t));
sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
int32_t priority = data.readInt32();
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
int sessionId = data.readInt32();
status_t status;
int id;
int enabled;
sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
&status, &id, &enabled);
reply->writeInt32(status);
reply->writeInt32(id);
reply->writeInt32(enabled);
reply->writeStrongBinder(effect->asBinder());
reply->write(&desc, sizeof(effect_descriptor_t));
return NO_ERROR;
} break;
case MOVE_EFFECTS: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
int session = data.readInt32();
audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
return NO_ERROR;
} break;
case LOAD_HW_MODULE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(loadHwModule(data.readCString()));
return NO_ERROR;
} break;
case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(getPrimaryOutputSamplingRate());
return NO_ERROR;
} break;
case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt64(getPrimaryOutputFrameCount());
return NO_ERROR;
} break;
case SET_LOW_RAM_DEVICE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
bool isLowRamDevice = data.readInt32() != 0;
reply->writeInt32(setLowRamDevice(isLowRamDevice));
return NO_ERROR;
} break;
case LIST_AUDIO_PORTS: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
unsigned int num_ports = data.readInt32();
struct audio_port *ports =
(struct audio_port *)calloc(num_ports,
sizeof(struct audio_port));
status_t status = listAudioPorts(&num_ports, ports);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->writeInt32(num_ports);
reply->write(&ports, num_ports * sizeof(struct audio_port));
}
free(ports);
return NO_ERROR;
} break;
case GET_AUDIO_PORT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
struct audio_port port;
data.read(&port, sizeof(struct audio_port));
status_t status = getAudioPort(&port);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->write(&port, sizeof(struct audio_port));
}
return NO_ERROR;
} break;
case CREATE_AUDIO_PATCH: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
struct audio_patch patch;
data.read(&patch, sizeof(struct audio_patch));
audio_patch_handle_t handle;
data.read(&handle, sizeof(audio_patch_handle_t));
status_t status = createAudioPatch(&patch, &handle);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->write(&handle, sizeof(audio_patch_handle_t));
}
return NO_ERROR;
} break;
case RELEASE_AUDIO_PATCH: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_patch_handle_t handle;
data.read(&handle, sizeof(audio_patch_handle_t));
status_t status = releaseAudioPatch(handle);
reply->writeInt32(status);
return NO_ERROR;
} break;
case LIST_AUDIO_PATCHES: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
unsigned int num_patches = data.readInt32();
struct audio_patch *patches =
(struct audio_patch *)calloc(num_patches,
sizeof(struct audio_patch));
status_t status = listAudioPatches(&num_patches, patches);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->writeInt32(num_patches);
reply->write(&patches, num_patches * sizeof(struct audio_patch));
}
free(patches);
return NO_ERROR;
} break;
case SET_AUDIO_PORT_CONFIG: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
struct audio_port_config config;
data.read(&config, sizeof(struct audio_port_config));
status_t status = setAudioPortConfig(&config);
reply->writeInt32(status);
return NO_ERROR;
} break;
case GET_AUDIO_HW_SYNC: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
return NO_ERROR;
} break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
// ----------------------------------------------------------------------------
}; // namespace android
|