1 /* 2 * Copyright (C) 2014 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 OFFLOAD_EFFECT_BUNDLE_H 18 #define OFFLOAD_EFFECT_BUNDLE_H 19 20 #include <tinyalsa/asoundlib.h> 21 #include <sound/audio_effects.h> 22 #include "effect_api.h" 23 24 /* Retry for delay for mixer open */ 25 #define RETRY_NUMBER 10 26 #define RETRY_US 500000 27 28 #define MIXER_CARD 0 29 #define SOUND_CARD 0 30 31 extern const struct effect_interface_s effect_interface; 32 33 typedef struct output_context_s output_context_t; 34 typedef struct effect_ops_s effect_ops_t; 35 typedef struct effect_context_s effect_context_t; 36 37 struct output_context_s { 38 /* node in active_outputs_list */ 39 struct listnode outputs_list_node; 40 /* io handle */ 41 audio_io_handle_t handle; 42 /* list of effects attached to this output */ 43 struct listnode effects_list; 44 /* pcm device id */ 45 int pcm_device_id; 46 struct mixer *mixer; 47 struct mixer_ctl *ctl; 48 }; 49 50 /* effect specific operations. 51 * Only the init() and process() operations must be defined. 52 * Others are optional. 53 */ 54 struct effect_ops_s { 55 int (*init)(effect_context_t *context); 56 int (*release)(effect_context_t *context); 57 int (*reset)(effect_context_t *context); 58 int (*enable)(effect_context_t *context); 59 int (*start)(effect_context_t *context, output_context_t *output); 60 int (*stop)(effect_context_t *context, output_context_t *output); 61 int (*disable)(effect_context_t *context); 62 int (*process)(effect_context_t *context, audio_buffer_t *in, audio_buffer_t *out); 63 int (*set_parameter)(effect_context_t *context, effect_param_t *param, uint32_t size); 64 int (*get_parameter)(effect_context_t *context, effect_param_t *param, uint32_t *size); 65 int (*set_device)(effect_context_t *context, uint32_t device); 66 int (*command)(effect_context_t *context, uint32_t cmdCode, uint32_t cmdSize, 67 void *pCmdData, uint32_t *replySize, void *pReplyData); 68 }; 69 70 struct effect_context_s { 71 const struct effect_interface_s *itfe; 72 /* node in created_effects_list */ 73 struct listnode effects_list_node; 74 /* node in output_context_t.effects_list */ 75 struct listnode output_node; 76 effect_config_t config; 77 const effect_descriptor_t *desc; 78 /* io handle of the output the effect is attached to */ 79 audio_io_handle_t out_handle; 80 uint32_t state; 81 bool offload_enabled; 82 effect_ops_t ops; 83 }; 84 85 int set_config(effect_context_t *context, effect_config_t *config); 86 87 bool effect_is_active(effect_context_t *context); 88 89 #endif /* OFFLOAD_EFFECT_BUNDLE_H */ 90