1 /*
2  * Copyright (C) 2013 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 
17 #include <hardware/audio_effect.h>
18 
19 
20 extern "C" {
21 
22 extern const struct effect_interface_s gCTSEffectInterface;
23 
24 const effect_descriptor_t gCTSEffectsDescriptor = {
25         {0xf2a4bb20, 0x0c3c, 0x11e3, 0x8b07, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
26         {0xff93e360, 0x0c3c, 0x11e3, 0x8a97, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
27         EFFECT_CONTROL_API_VERSION,
28         0,
29         0,
30         1,
31         "CTS test Effect",
32         "The Android Open Source Project",
33 };
34 
35 struct CTSEffectsContext {
36     const struct effect_interface_s *mItfe;
37     effect_config_t mConfig;
38 };
39 
40 //
41 //--- Effect Library Interface Implementation
42 //
43 
CTSEffectsLib_Create(const effect_uuid_t * uuid,int32_t sessionId,int32_t ioId,effect_handle_t * pHandle)44 int CTSEffectsLib_Create(const effect_uuid_t *uuid,
45                          int32_t sessionId,
46                          int32_t ioId,
47                          effect_handle_t *pHandle) {
48     if (pHandle == NULL || uuid == NULL) {
49         return -EINVAL;
50     }
51 
52     if (memcmp(uuid, &gCTSEffectsDescriptor.uuid, sizeof(effect_uuid_t)) != 0) {
53         return -EINVAL;
54     }
55 
56     CTSEffectsContext *pContext = new CTSEffectsContext;
57 
58     pContext->mItfe = &gCTSEffectInterface;
59 
60     *pHandle = (effect_handle_t)pContext;
61 
62     return 0;
63 
64 }
65 
CTSEffectsLib_Release(effect_handle_t handle)66 int CTSEffectsLib_Release(effect_handle_t handle) {
67     CTSEffectsContext * pContext = (CTSEffectsContext *)handle;
68 
69     if (pContext == NULL) {
70         return -EINVAL;
71     }
72     delete pContext;
73 
74     return 0;
75 }
76 
CTSEffectsLib_GetDescriptor(const effect_uuid_t * uuid,effect_descriptor_t * pDescriptor)77 int CTSEffectsLib_GetDescriptor(const effect_uuid_t *uuid,
78                                 effect_descriptor_t *pDescriptor) {
79 
80     if (pDescriptor == NULL || uuid == NULL){
81         return -EINVAL;
82     }
83 
84     if (memcmp(uuid, &gCTSEffectsDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
85         *pDescriptor = gCTSEffectsDescriptor;
86         return 0;
87     }
88 
89     return  -EINVAL;
90 } /* end CTSEffectsLib_GetDescriptor */
91 
92 //
93 //--- Effect Control Interface Implementation
94 //
95 
CTSEffects_process(effect_handle_t self,audio_buffer_t * inBuffer,audio_buffer_t * outBuffer)96 int CTSEffects_process(
97         effect_handle_t self,audio_buffer_t *inBuffer, audio_buffer_t *outBuffer)
98 {
99     return 0;
100 }   // end CTSEffects_process
101 
CTSEffects_command(effect_handle_t self,uint32_t cmdCode,uint32_t cmdSize,void * pCmdData,uint32_t * replySize,void * pReplyData)102 int CTSEffects_command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize,
103         void *pCmdData, uint32_t *replySize, void *pReplyData) {
104 
105     CTSEffectsContext * pContext = (CTSEffectsContext *)self;
106 
107     if (pContext == NULL) {
108         return -EINVAL;
109     }
110 
111     switch (cmdCode) {
112     case EFFECT_CMD_INIT:
113         if (pReplyData == NULL || *replySize != sizeof(int)) {
114             return -EINVAL;
115         }
116         *(int *) pReplyData = 0;
117         break;
118     case EFFECT_CMD_SET_CONFIG:
119         if (pCmdData == NULL || cmdSize != sizeof(effect_config_t)
120                 || pReplyData == NULL || *replySize != sizeof(int)) {
121             return -EINVAL;
122         }
123         memcpy(&pContext->mConfig, pCmdData, cmdSize);
124         *(int *) pReplyData = 0;
125         break;
126     case EFFECT_CMD_GET_CONFIG:
127         if (pReplyData == NULL ||
128             *replySize != sizeof(effect_config_t)) {
129             return -EINVAL;
130         }
131         memcpy(pReplyData, &pContext->mConfig, *replySize);
132         break;
133     case EFFECT_CMD_RESET:
134         break;
135     case EFFECT_CMD_ENABLE:
136     case EFFECT_CMD_DISABLE:
137         if (pReplyData == NULL || *replySize != sizeof(int)) {
138             return -EINVAL;
139         }
140         *(int *)pReplyData = 0;
141         break;
142     case EFFECT_CMD_GET_PARAM: {
143         if (pCmdData == NULL ||
144             cmdSize != (int)(sizeof(effect_param_t)) ||
145             pReplyData == NULL ||
146             *replySize < (int)(sizeof(effect_param_t))) {
147             return -EINVAL;
148         }
149         effect_param_t *p = (effect_param_t *)pReplyData;
150         p->status = 0;
151         } break;
152     case EFFECT_CMD_SET_PARAM: {
153         if (pCmdData == NULL ||
154             cmdSize != (int)(sizeof(effect_param_t)) ||
155             pReplyData == NULL || *replySize != sizeof(int32_t)) {
156             return -EINVAL;
157         }
158         *(int32_t *)pReplyData = 0;
159         } break;
160     default:
161         break;
162     }
163 
164     return 0;
165 }
166 
167 /* Effect Control Interface Implementation: get_descriptor */
CTSEffects_getDescriptor(effect_handle_t self,effect_descriptor_t * pDescriptor)168 int CTSEffects_getDescriptor(effect_handle_t   self,
169                                     effect_descriptor_t *pDescriptor)
170 {
171     CTSEffectsContext * pContext = (CTSEffectsContext *) self;
172 
173     if (pContext == NULL || pDescriptor == NULL) {
174         return -EINVAL;
175     }
176 
177     *pDescriptor = gCTSEffectsDescriptor;
178 
179     return 0;
180 }   /* end CTSEffects_getDescriptor */
181 
182 // effect_handle_t interface implementation for test effect
183 const struct effect_interface_s gCTSEffectInterface = {
184         CTSEffects_process,
185         CTSEffects_command,
186         CTSEffects_getDescriptor,
187         NULL,
188 };
189 
190 // This is the only symbol that needs to be exported
191 __attribute__ ((visibility ("default")))
192 audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
193     tag : AUDIO_EFFECT_LIBRARY_TAG,
194     version : EFFECT_LIBRARY_API_VERSION,
195     name : "CTS Effects Library",
196     implementor : "The Android Open Source Project",
197     create_effect : CTSEffectsLib_Create,
198     release_effect : CTSEffectsLib_Release,
199     get_descriptor : CTSEffectsLib_GetDescriptor,
200 };
201 
202 }; // extern "C"
203