blob: 974ce62724a2cf2dd8263120b0dcdcd253702b82 [file] [log] [blame]
Eric Laurent801a1182010-06-09 00:17:29 -07001/*
2 * Copyright (C) 2009 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#ifndef ANDROID_AUDIOEFFECT_H
18#define ANDROID_AUDIOEFFECT_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <media/IAudioFlinger.h>
Eric Laurent801a1182010-06-09 00:17:29 -070024#include <media/AudioSystem.h>
Mikhail Naganov00260b52016-10-13 12:54:24 -070025#include <system/audio_effect.h>
Philip P. Moltmannbda45752020-07-17 16:41:18 -070026#include <android/media/permission/Identity.h>
Eric Laurent801a1182010-06-09 00:17:29 -070027
28#include <utils/RefBase.h>
29#include <utils/Errors.h>
30#include <binder/IInterface.h>
31
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070032#include "android/media/IEffect.h"
33#include "android/media/BnEffectClient.h"
34
Eric Laurent801a1182010-06-09 00:17:29 -070035namespace android {
36
37// ----------------------------------------------------------------------------
38
Glenn Kasten01d3acb2014-02-06 08:24:07 -080039struct effect_param_cblk_t;
Eric Laurent801a1182010-06-09 00:17:29 -070040
41// ----------------------------------------------------------------------------
42
43class AudioEffect : public RefBase
44{
45public:
46
47 /*
Eric Laurent801a1182010-06-09 00:17:29 -070048 * Static methods for effects enumeration.
49 */
50
51 /*
52 * Returns the number of effects available. This method together
Eric Laurentffe9c252010-06-23 17:38:20 -070053 * with queryEffect() is used to enumerate all effects:
Eric Laurent801a1182010-06-09 00:17:29 -070054 * The enumeration sequence is:
Eric Laurentffe9c252010-06-23 17:38:20 -070055 * queryNumberEffects(&num_effects);
56 * for (i = 0; i < num_effects; i++)
57 * queryEffect(i,...);
Eric Laurent801a1182010-06-09 00:17:29 -070058 *
59 * Parameters:
Eric Laurentffe9c252010-06-23 17:38:20 -070060 * numEffects: address where the number of effects should be returned.
Eric Laurent801a1182010-06-09 00:17:29 -070061 *
62 * Returned status (from utils/Errors.h) can be:
63 * NO_ERROR successful operation.
64 * PERMISSION_DENIED could not get AudioFlinger interface
65 * NO_INIT effect library failed to initialize
66 * BAD_VALUE invalid numEffects pointer
67 *
68 * Returned value
69 * *numEffects: updated with number of effects available
70 */
71 static status_t queryNumberEffects(uint32_t *numEffects);
72
73 /*
Eric Laurentffe9c252010-06-23 17:38:20 -070074 * Returns an effect descriptor during effect
Eric Laurent801a1182010-06-09 00:17:29 -070075 * enumeration.
76 *
77 * Parameters:
Eric Laurentffe9c252010-06-23 17:38:20 -070078 * index: index of the queried effect.
79 * descriptor: address where the effect descriptor should be returned.
Eric Laurent801a1182010-06-09 00:17:29 -070080 *
81 * Returned status (from utils/Errors.h) can be:
82 * NO_ERROR successful operation.
Eric Laurent801a1182010-06-09 00:17:29 -070083 * PERMISSION_DENIED could not get AudioFlinger interface
84 * NO_INIT effect library failed to initialize
Eric Laurentffe9c252010-06-23 17:38:20 -070085 * BAD_VALUE invalid descriptor pointer or index
Eric Laurent801a1182010-06-09 00:17:29 -070086 * INVALID_OPERATION effect list has changed since last execution of queryNumberEffects()
87 *
88 * Returned value
89 * *descriptor: updated with effect descriptor
90 */
Eric Laurentffe9c252010-06-23 17:38:20 -070091 static status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor);
Eric Laurent801a1182010-06-09 00:17:29 -070092
Eric Laurent801a1182010-06-09 00:17:29 -070093 /*
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -070094 * Returns a descriptor for the specified effect uuid or type.
95 *
96 * Lookup an effect by uuid, or if that's unspecified (EFFECT_UUID_NULL),
97 * do so by type and preferred flags instead.
Eric Laurent801a1182010-06-09 00:17:29 -070098 *
99 * Parameters:
100 * uuid: pointer to effect uuid.
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700101 * type: pointer to effect type uuid.
102 * preferredTypeFlags: if multiple effects of the given type exist,
103 * one with a matching type flag will be chosen over one without.
104 * Use EFFECT_FLAG_TYPE_MASK to indicate no preference.
Eric Laurent801a1182010-06-09 00:17:29 -0700105 * descriptor: address where the effect descriptor should be returned.
106 *
107 * Returned status (from utils/Errors.h) can be:
108 * NO_ERROR successful operation.
109 * PERMISSION_DENIED could not get AudioFlinger interface
110 * NO_INIT effect library failed to initialize
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700111 * BAD_VALUE invalid type or descriptor pointers
Eric Laurent801a1182010-06-09 00:17:29 -0700112 * NAME_NOT_FOUND no effect with this uuid found
113 *
114 * Returned value
115 * *descriptor updated with effect descriptor
116 */
Glenn Kasten5e92a782012-01-30 07:40:52 -0800117 static status_t getEffectDescriptor(const effect_uuid_t *uuid,
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700118 const effect_uuid_t *type,
119 uint32_t preferredTypeFlag,
120 effect_descriptor_t *descriptor);
Eric Laurent801a1182010-06-09 00:17:29 -0700121
122 /*
Eric Laurent57dae992011-07-24 13:36:09 -0700123 * Returns a list of descriptors corresponding to the pre processings enabled by default
124 * on an AudioRecord with the supplied audio session ID.
125 *
126 * Parameters:
127 * audioSession: audio session ID.
128 * descriptors: address where the effect descriptors should be returned.
129 * count: as input, the maximum number of descriptor than should be returned
130 * as output, the number of descriptor returned if status is NO_ERROR or the actual
131 * number of enabled pre processings if status is NO_MEMORY
132 *
133 * Returned status (from utils/Errors.h) can be:
134 * NO_ERROR successful operation.
135 * NO_MEMORY the number of descriptor to return is more than the maximum number
136 * indicated by count.
137 * PERMISSION_DENIED could not get AudioFlinger interface
138 * NO_INIT effect library failed to initialize
139 * BAD_VALUE invalid audio session or descriptor pointers
140 *
141 * Returned value
142 * *descriptor updated with descriptors of pre processings enabled by default
Eric Laurent74adca92014-11-05 12:15:36 -0800143 * *count number of descriptors returned if returned status is NO_ERROR.
Eric Laurent57dae992011-07-24 13:36:09 -0700144 * total number of pre processing enabled by default if returned status is
145 * NO_MEMORY. This happens if the count passed as input is less than the number
Eric Laurent74adca92014-11-05 12:15:36 -0800146 * of descriptors to return.
147 * *count is limited to kMaxPreProcessing on return.
Eric Laurent57dae992011-07-24 13:36:09 -0700148 */
Glenn Kastend848eb42016-03-08 13:42:11 -0800149 static status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700150 effect_descriptor_t *descriptors,
151 uint32_t *count);
152
153 /*
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700154 * Gets a new system-wide unique effect id.
155 *
156 * Parameters:
157 * id: The address to return the generated id.
158 *
159 * Returned status (from utils/Errors.h) can be:
160 * NO_ERROR successful operation.
161 * PERMISSION_DENIED could not get AudioFlinger interface
162 * or caller lacks required permissions.
163 * Returned value
164 * *id: The new unique system-wide effect id.
165 */
166 static status_t newEffectUniqueId(audio_unique_id_t* id);
167
168 /*
169 * Static methods for adding/removing system-wide effects.
170 */
171
172 /*
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700173 * Adds an effect to the list of default output effects for a given source type.
174 *
175 * If the effect is no longer available when a source of the given type
176 * is created, the system will continue without adding it.
177 *
178 * Parameters:
179 * typeStr: Type uuid of effect to be a default: can be null if uuidStr is specified.
180 * This may correspond to the OpenSL ES interface implemented by this effect,
181 * or could be some vendor-defined type.
182 * opPackageName: The package name used for app op checks.
183 * uuidStr: Uuid of effect to be a default: can be null if type is specified.
184 * This uuid corresponds to a particular implementation of an effect type.
185 * Note if both uuidStr and typeStr are specified, typeStr is ignored.
186 * priority: Requested priority for effect control: the priority level corresponds to the
187 * value of priority parameter: negative values indicate lower priorities, positive
188 * values higher priorities, 0 being the normal priority.
189 * source: The source this effect should be a default for.
190 * id: Address where the system-wide unique id of the default effect should be returned.
191 *
192 * Returned status (from utils/Errors.h) can be:
193 * NO_ERROR successful operation.
194 * PERMISSION_DENIED could not get AudioFlinger interface
195 * or caller lacks required permissions.
196 * NO_INIT effect library failed to initialize.
197 * BAD_VALUE invalid source, type uuid or implementation uuid.
198 * NAME_NOT_FOUND no effect with this uuid or type found.
199 *
200 * Returned value
201 * *id: The system-wide unique id of the added default effect.
202 */
203 static status_t addSourceDefaultEffect(const char* typeStr,
204 const String16& opPackageName,
205 const char* uuidStr,
206 int32_t priority,
207 audio_source_t source,
208 audio_unique_id_t* id);
209
210 /*
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700211 * Adds an effect to the list of default output effects for a given stream type.
212 *
213 * If the effect is no longer available when a stream of the given type
214 * is created, the system will continue without adding it.
215 *
216 * Parameters:
217 * typeStr: Type uuid of effect to be a default: can be null if uuidStr is specified.
218 * This may correspond to the OpenSL ES interface implemented by this effect,
219 * or could be some vendor-defined type.
220 * opPackageName: The package name used for app op checks.
221 * uuidStr: Uuid of effect to be a default: can be null if type is specified.
222 * This uuid corresponds to a particular implementation of an effect type.
223 * Note if both uuidStr and typeStr are specified, typeStr is ignored.
224 * priority: Requested priority for effect control: the priority level corresponds to the
225 * value of priority parameter: negative values indicate lower priorities, positive
226 * values higher priorities, 0 being the normal priority.
227 * usage: The usage this effect should be a default for. Unrecognized values will be
228 * treated as AUDIO_USAGE_UNKNOWN.
229 * id: Address where the system-wide unique id of the default effect should be returned.
230 *
231 * Returned status (from utils/Errors.h) can be:
232 * NO_ERROR successful operation.
233 * PERMISSION_DENIED could not get AudioFlinger interface
234 * or caller lacks required permissions.
235 * NO_INIT effect library failed to initialize.
236 * BAD_VALUE invalid type uuid or implementation uuid.
237 * NAME_NOT_FOUND no effect with this uuid or type found.
238 *
239 * Returned value
240 * *id: The system-wide unique id of the added default effect.
241 */
242 static status_t addStreamDefaultEffect(const char* typeStr,
243 const String16& opPackageName,
244 const char* uuidStr,
245 int32_t priority,
246 audio_usage_t usage,
247 audio_unique_id_t* id);
248
249 /*
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700250 * Removes an effect from the list of default output effects for a given source type.
251 *
252 * Parameters:
253 * id: The system-wide unique id of the effect that should no longer be a default.
254 *
255 * Returned status (from utils/Errors.h) can be:
256 * NO_ERROR successful operation.
257 * PERMISSION_DENIED could not get AudioFlinger interface
258 * or caller lacks required permissions.
259 * NO_INIT effect library failed to initialize.
260 * BAD_VALUE invalid id.
261 */
262 static status_t removeSourceDefaultEffect(audio_unique_id_t id);
263
264 /*
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700265 * Removes an effect from the list of default output effects for a given stream type.
266 *
267 * Parameters:
268 * id: The system-wide unique id of the effect that should no longer be a default.
269 *
270 * Returned status (from utils/Errors.h) can be:
271 * NO_ERROR successful operation.
272 * PERMISSION_DENIED could not get AudioFlinger interface
273 * or caller lacks required permissions.
274 * NO_INIT effect library failed to initialize.
275 * BAD_VALUE invalid id.
276 */
277 static status_t removeStreamDefaultEffect(audio_unique_id_t id);
278
279 /*
Eric Laurent801a1182010-06-09 00:17:29 -0700280 * Events used by callback function (effect_callback_t).
281 */
282 enum event_type {
283 EVENT_CONTROL_STATUS_CHANGED = 0,
284 EVENT_ENABLE_STATUS_CHANGED = 1,
285 EVENT_PARAMETER_CHANGED = 2,
286 EVENT_ERROR = 3
287 };
288
289 /* Callback function notifying client application of a change in effect engine state or
290 * configuration.
291 * An effect engine can be shared by several applications but only one has the control
292 * of the engine activity and configuration at a time.
293 * The EVENT_CONTROL_STATUS_CHANGED event is received when an application loses or
294 * retrieves the control of the effect engine. Loss of control happens
295 * if another application requests the use of the engine by creating an AudioEffect for
296 * the same effect type but with a higher priority. Control is returned when the
297 * application having the control deletes its AudioEffect object.
298 * The EVENT_ENABLE_STATUS_CHANGED event is received by all applications not having the
299 * control of the effect engine when the effect is enabled or disabled.
300 * The EVENT_PARAMETER_CHANGED event is received by all applications not having the
301 * control of the effect engine when an effect parameter is changed.
302 * The EVENT_ERROR event is received when the media server process dies.
303 *
304 * Parameters:
305 *
306 * event: type of event notified (see enum AudioEffect::event_type).
307 * user: Pointer to context for use by the callback receiver.
308 * info: Pointer to optional parameter according to event type:
309 * - EVENT_CONTROL_STATUS_CHANGED: boolean indicating if control is granted (true)
310 * or stolen (false).
311 * - EVENT_ENABLE_STATUS_CHANGED: boolean indicating if effect is now enabled (true)
312 * or disabled (false).
313 * - EVENT_PARAMETER_CHANGED: pointer to a effect_param_t structure.
314 * - EVENT_ERROR: status_t indicating the error (DEAD_OBJECT when media server dies).
315 */
316
317 typedef void (*effect_callback_t)(int32_t event, void* user, void *info);
318
319
320 /* Constructor.
321 * AudioEffect is the base class for creating and controlling an effect engine from
322 * the application process. Creating an AudioEffect object will create the effect engine
323 * in the AudioFlinger if no engine of the specified type exists. If one exists, this engine
324 * will be used. The application creating the AudioEffect object (or a derived class like
325 * Reverb for instance) will either receive control of the effect engine or not, depending
326 * on the priority parameter. If priority is higher than the priority used by the current
327 * effect engine owner, the control will be transfered to the new application. Otherwise
328 * control will remain to the previous application. In this case, the new application will be
329 * notified of changes in effect engine state or control ownership by the effect callback.
330 * After creating the AudioEffect, the application must call the initCheck() method and
331 * check the creation status before trying to control the effect engine (see initCheck()).
332 * If the effect is to be applied to an AudioTrack or MediaPlayer only the application
333 * must specify the audio session ID corresponding to this player.
334 */
335
336 /* Simple Constructor.
Svet Ganovbe71aa22015-04-28 12:06:02 -0700337 *
338 * Parameters:
339 *
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700340 * client: Identity for app-op checks
Eric Laurent801a1182010-06-09 00:17:29 -0700341 */
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700342 explicit AudioEffect(const media::permission::Identity& client);
Eric Laurent801a1182010-06-09 00:17:29 -0700343
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700344 /* Terminates the AudioEffect and unregisters it from AudioFlinger.
345 * The effect engine is also destroyed if this AudioEffect was the last controlling
346 * the engine.
347 */
348 ~AudioEffect();
Eric Laurent801a1182010-06-09 00:17:29 -0700349
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700350 /**
351 * Initialize an uninitialized AudioEffect.
Eric Laurent801a1182010-06-09 00:17:29 -0700352 *
353 * Parameters:
354 *
355 * type: type of effect created: can be null if uuid is specified. This corresponds to
356 * the OpenSL ES interface implemented by this effect.
357 * uuid: Uuid of effect created: can be null if type is specified. This uuid corresponds to
358 * a particular implementation of an effect type.
359 * priority: requested priority for effect control: the priority level corresponds to the
360 * value of priority parameter: negative values indicate lower priorities, positive values
361 * higher priorities, 0 being the normal priority.
362 * cbf: optional callback function (see effect_callback_t)
363 * user: pointer to context for use by the callback receiver.
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700364 * sessionId: audio session this effect is associated to.
Glenn Kasten684d4732014-03-25 17:41:42 -0700365 * If equal to AUDIO_SESSION_OUTPUT_MIX, the effect will be global to
366 * the output mix. Otherwise, the effect will be applied to all players
Eric Laurent801a1182010-06-09 00:17:29 -0700367 * (AudioTrack or MediaPLayer) within the same audio session.
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700368 * io: HAL audio output or input stream to which this effect must be attached. Leave at 0 for
Eric Laurent801a1182010-06-09 00:17:29 -0700369 * automatic output selection by AudioFlinger.
Eric Laurent94876032019-11-13 12:45:28 -0800370 * device: An audio device descriptor. Only used when "sessionID" is AUDIO_SESSION_DEVICE.
371 * Specifies the audio device type and address the effect must be attached to.
372 * If "sessionID" is AUDIO_SESSION_DEVICE then "io" must be AUDIO_IO_HANDLE_NONE.
Eric Laurent2fe0acd2020-03-13 14:30:46 -0700373 * probe: true if created in a degraded mode to only verify if effect creation is possible.
374 * In this mode, no IEffect interface to AudioFlinger is created and all actions
375 * besides getters implemented in client AudioEffect object are no ops
376 * after effect creation.
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700377 *
378 * Returned status (from utils/Errors.h) can be:
379 * - NO_ERROR or ALREADY_EXISTS: successful initialization
380 * - INVALID_OPERATION: AudioEffect is already initialized
381 * - BAD_VALUE: invalid parameter
382 * - NO_INIT: audio flinger or audio hardware not initialized
Eric Laurent801a1182010-06-09 00:17:29 -0700383 */
Eric Laurent801a1182010-06-09 00:17:29 -0700384 status_t set(const effect_uuid_t *type,
385 const effect_uuid_t *uuid = NULL,
386 int32_t priority = 0,
Glenn Kastena0d68332012-01-27 16:47:15 -0800387 effect_callback_t cbf = NULL,
388 void* user = NULL,
Glenn Kastend848eb42016-03-08 13:42:11 -0800389 audio_session_t sessionId = AUDIO_SESSION_OUTPUT_MIX,
Eric Laurent94876032019-11-13 12:45:28 -0800390 audio_io_handle_t io = AUDIO_IO_HANDLE_NONE,
Eric Laurent2fe0acd2020-03-13 14:30:46 -0700391 const AudioDeviceTypeAddr& device = {},
392 bool probe = false);
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700393 /*
394 * Same as above but with type and uuid specified by character strings.
395 */
396 status_t set(const char *typeStr,
397 const char *uuidStr = NULL,
398 int32_t priority = 0,
399 effect_callback_t cbf = NULL,
400 void* user = NULL,
401 audio_session_t sessionId = AUDIO_SESSION_OUTPUT_MIX,
402 audio_io_handle_t io = AUDIO_IO_HANDLE_NONE,
403 const AudioDeviceTypeAddr& device = {},
404 bool probe = false);
Eric Laurent801a1182010-06-09 00:17:29 -0700405
406 /* Result of constructing the AudioEffect. This must be checked
407 * before using any AudioEffect API.
408 * initCheck() can return:
409 * - NO_ERROR: the effect engine is successfully created and the application has control.
410 * - ALREADY_EXISTS: the effect engine is successfully created but the application does not
411 * have control.
412 * - NO_INIT: the effect creation failed.
413 *
414 */
415 status_t initCheck() const;
416
417
418 /* Returns the unique effect Id for the controlled effect engine. This ID is unique
419 * system wide and is used for instance in the case of auxiliary effects to attach
420 * the effect to an AudioTrack or MediaPlayer.
421 *
422 */
423 int32_t id() const { return mId; }
424
Eric Laurente1315cf2011-05-17 19:16:02 -0700425 /* Returns a descriptor for the effect (see effect_descriptor_t in audio_effect.h).
Eric Laurent801a1182010-06-09 00:17:29 -0700426 */
427 effect_descriptor_t descriptor() const;
428
429 /* Returns effect control priority of this AudioEffect object.
430 */
431 int32_t priority() const { return mPriority; }
432
433
Eric Laurentda7581b2010-07-02 08:12:41 -0700434 /* Enables or disables the effect engine.
Eric Laurent801a1182010-06-09 00:17:29 -0700435 *
436 * Parameters:
Eric Laurentda7581b2010-07-02 08:12:41 -0700437 * enabled: requested enable state.
Eric Laurent801a1182010-06-09 00:17:29 -0700438 *
439 * Returned status (from utils/Errors.h) can be:
440 * - NO_ERROR: successful operation
Eric Laurentda7581b2010-07-02 08:12:41 -0700441 * - INVALID_OPERATION: the application does not have control of the effect engine or the
442 * effect is already in the requested state.
Eric Laurent801a1182010-06-09 00:17:29 -0700443 */
Eric Laurentda7581b2010-07-02 08:12:41 -0700444 virtual status_t setEnabled(bool enabled);
445 bool getEnabled() const;
Eric Laurent801a1182010-06-09 00:17:29 -0700446
447 /* Sets a parameter value.
448 *
449 * Parameters:
450 * param: pointer to effect_param_t structure containing the parameter
Eric Laurente1315cf2011-05-17 19:16:02 -0700451 * and its value (See audio_effect.h).
Eric Laurent801a1182010-06-09 00:17:29 -0700452 * Returned status (from utils/Errors.h) can be:
453 * - NO_ERROR: successful operation.
454 * - INVALID_OPERATION: the application does not have control of the effect engine.
455 * - BAD_VALUE: invalid parameter identifier or value.
456 * - DEAD_OBJECT: the effect engine has been deleted.
457 */
Eric Laurentda7581b2010-07-02 08:12:41 -0700458 virtual status_t setParameter(effect_param_t *param);
Eric Laurent801a1182010-06-09 00:17:29 -0700459
460 /* Prepare a new parameter value that will be set by next call to
461 * setParameterCommit(). This method can be used to set multiple parameters
462 * in a synchronous manner or to avoid multiple binder calls for each
463 * parameter.
464 *
465 * Parameters:
466 * param: pointer to effect_param_t structure containing the parameter
Eric Laurente1315cf2011-05-17 19:16:02 -0700467 * and its value (See audio_effect.h).
Eric Laurent801a1182010-06-09 00:17:29 -0700468 *
469 * Returned status (from utils/Errors.h) can be:
470 * - NO_ERROR: successful operation.
471 * - INVALID_OPERATION: the application does not have control of the effect engine.
472 * - NO_MEMORY: no more space available in shared memory used for deferred parameter
473 * setting.
474 */
Eric Laurentda7581b2010-07-02 08:12:41 -0700475 virtual status_t setParameterDeferred(effect_param_t *param);
Eric Laurent801a1182010-06-09 00:17:29 -0700476
477 /* Commit all parameter values previously prepared by setParameterDeferred().
478 *
479 * Parameters:
480 * none
481 *
482 * Returned status (from utils/Errors.h) can be:
483 * - NO_ERROR: successful operation.
484 * - INVALID_OPERATION: No new parameter values ready for commit.
485 * - BAD_VALUE: invalid parameter identifier or value: there is no indication
486 * as to which of the parameters caused this error.
487 * - DEAD_OBJECT: the effect engine has been deleted.
488 */
Eric Laurentda7581b2010-07-02 08:12:41 -0700489 virtual status_t setParameterCommit();
Eric Laurent801a1182010-06-09 00:17:29 -0700490
491 /* Gets a parameter value.
492 *
493 * Parameters:
494 * param: pointer to effect_param_t structure containing the parameter
Eric Laurente1315cf2011-05-17 19:16:02 -0700495 * and the returned value (See audio_effect.h).
Eric Laurent801a1182010-06-09 00:17:29 -0700496 *
497 * Returned status (from utils/Errors.h) can be:
498 * - NO_ERROR: successful operation.
499 * - INVALID_OPERATION: the AudioEffect was not successfully initialized.
500 * - BAD_VALUE: invalid parameter identifier.
501 * - DEAD_OBJECT: the effect engine has been deleted.
502 */
Eric Laurentda7581b2010-07-02 08:12:41 -0700503 virtual status_t getParameter(effect_param_t *param);
Eric Laurent801a1182010-06-09 00:17:29 -0700504
505 /* Sends a command and receives a response to/from effect engine.
Eric Laurente1315cf2011-05-17 19:16:02 -0700506 * See audio_effect.h for details on effect command() function, valid command codes
Eric Laurent801a1182010-06-09 00:17:29 -0700507 * and formats.
508 */
Eric Laurent25f43952010-07-28 05:40:18 -0700509 virtual status_t command(uint32_t cmdCode,
510 uint32_t cmdSize,
Eric Laurentda7581b2010-07-02 08:12:41 -0700511 void *cmdData,
Eric Laurent25f43952010-07-28 05:40:18 -0700512 uint32_t *replySize,
Eric Laurentda7581b2010-07-02 08:12:41 -0700513 void *replyData);
Eric Laurent801a1182010-06-09 00:17:29 -0700514
515
516 /*
517 * Utility functions.
518 */
519
520 /* Converts the string passed as first argument to the effect_uuid_t
521 * pointed to by second argument
522 */
523 static status_t stringToGuid(const char *str, effect_uuid_t *guid);
524 /* Converts the effect_uuid_t pointed to by first argument to the
525 * string passed as second argument
526 */
527 static status_t guidToString(const effect_uuid_t *guid, char *str, size_t maxLen);
528
Eric Laurent74adca92014-11-05 12:15:36 -0800529 // kMaxPreProcessing is a reasonable value for the maximum number of preprocessing effects
530 // that can be applied simultaneously.
531 static const uint32_t kMaxPreProcessing = 10;
532
Eric Laurentda7581b2010-07-02 08:12:41 -0700533protected:
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700534 media::permission::Identity mClientIdentity; // Identity used for app op checks.
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700535 bool mEnabled = false; // enable state
536 audio_session_t mSessionId = AUDIO_SESSION_OUTPUT_MIX; // audio session ID
537 int32_t mPriority = 0; // priority for effect control
538 status_t mStatus = NO_INIT; // effect status
539 bool mProbe = false; // effect created in probe mode: all commands
Eric Laurent2fe0acd2020-03-13 14:30:46 -0700540 // are no ops because mIEffect is NULL
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700541 effect_callback_t mCbf = nullptr; // callback function for status, control and
Eric Laurentda7581b2010-07-02 08:12:41 -0700542 // parameter changes notifications
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700543 void* mUserData = nullptr;// client context for callback function
544 effect_descriptor_t mDescriptor = {}; // effect descriptor
545 int32_t mId = -1; // system wide unique effect engine instance ID
Svet Ganovbe71aa22015-04-28 12:06:02 -0700546 Mutex mLock; // Mutex for mEnabled access
547
Eric Laurentda7581b2010-07-02 08:12:41 -0700548
Jean-Michel Trivi3476de62012-04-15 17:15:07 -0700549 // IEffectClient
550 virtual void controlStatusChanged(bool controlGranted);
551 virtual void enableStatusChanged(bool enabled);
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700552 virtual void commandExecuted(int32_t cmdCode,
553 const std::vector<uint8_t>& cmdData,
554 const std::vector<uint8_t>& replyData);
Jean-Michel Trivi3476de62012-04-15 17:15:07 -0700555
Eric Laurent801a1182010-06-09 00:17:29 -0700556private:
557
558 // Implements the IEffectClient interface
Eric Laurenteecd7652015-06-04 16:20:16 -0700559 class EffectClient :
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700560 public media::BnEffectClient, public android::IBinder::DeathRecipient
Eric Laurent801a1182010-06-09 00:17:29 -0700561 {
562 public:
563
564 EffectClient(AudioEffect *effect) : mEffect(effect){}
565
566 // IEffectClient
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700567 binder::Status controlStatusChanged(bool controlGranted) override {
Eric Laurenteecd7652015-06-04 16:20:16 -0700568 sp<AudioEffect> effect = mEffect.promote();
569 if (effect != 0) {
570 effect->controlStatusChanged(controlGranted);
571 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700572 return binder::Status::ok();
Eric Laurentda7581b2010-07-02 08:12:41 -0700573 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700574 binder::Status enableStatusChanged(bool enabled) override {
Eric Laurenteecd7652015-06-04 16:20:16 -0700575 sp<AudioEffect> effect = mEffect.promote();
576 if (effect != 0) {
577 effect->enableStatusChanged(enabled);
578 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700579 return binder::Status::ok();
Eric Laurentda7581b2010-07-02 08:12:41 -0700580 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700581 binder::Status commandExecuted(int32_t cmdCode,
582 const std::vector<uint8_t>& cmdData,
583 const std::vector<uint8_t>& replyData) override {
Eric Laurenteecd7652015-06-04 16:20:16 -0700584 sp<AudioEffect> effect = mEffect.promote();
585 if (effect != 0) {
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700586 effect->commandExecuted(cmdCode, cmdData, replyData);
Eric Laurenteecd7652015-06-04 16:20:16 -0700587 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700588 return binder::Status::ok();
Eric Laurent801a1182010-06-09 00:17:29 -0700589 }
590
591 // IBinder::DeathRecipient
Dan Willemsenb5fc9e52016-12-13 20:34:11 -0800592 virtual void binderDied(const wp<IBinder>& /*who*/) {
Eric Laurenteecd7652015-06-04 16:20:16 -0700593 sp<AudioEffect> effect = mEffect.promote();
594 if (effect != 0) {
595 effect->binderDied();
596 }
597 }
Eric Laurent801a1182010-06-09 00:17:29 -0700598
599 private:
Eric Laurenteecd7652015-06-04 16:20:16 -0700600 wp<AudioEffect> mEffect;
Eric Laurent801a1182010-06-09 00:17:29 -0700601 };
602
Eric Laurent801a1182010-06-09 00:17:29 -0700603 void binderDied();
604
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700605 sp<media::IEffect> mIEffect; // IEffect binder interface
Eric Laurent801a1182010-06-09 00:17:29 -0700606 sp<EffectClient> mIEffectClient; // IEffectClient implementation
607 sp<IMemory> mCblkMemory; // shared memory for deferred parameter setting
Mikhail Naganov416fffe2020-07-31 17:36:08 -0700608 effect_param_cblk_t* mCblk = nullptr; // control block for deferred parameter setting
Eric Laurent801a1182010-06-09 00:17:29 -0700609};
610
611
612}; // namespace android
613
614#endif // ANDROID_AUDIOEFFECT_H