1 /*
2  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3  * Not a contribution.
4  *
5  * Copyright (C) 2013 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef OFFLOAD_EFFECT_BUNDLE_H
21 #define OFFLOAD_EFFECT_BUNDLE_H
22 
23 #include <tinyalsa/asoundlib.h>
24 #include <sound/audio_effects.h>
25 #include "effect_api.h"
26 
27 /* Retry for delay for mixer open */
28 #define RETRY_NUMBER 10
29 #define RETRY_US 500000
30 
31 #define MIXER_CARD 0
32 #define SOUND_CARD 0
33 
34 extern const struct effect_interface_s effect_interface;
35 
36 typedef struct output_context_s output_context_t;
37 typedef struct effect_ops_s effect_ops_t;
38 typedef struct effect_context_s effect_context_t;
39 
40 struct output_context_s {
41     /* node in active_outputs_list */
42     struct listnode outputs_list_node;
43     /* io handle */
44     audio_io_handle_t handle;
45     /* list of effects attached to this output */
46     struct listnode effects_list;
47     /* pcm device id */
48     int pcm_device_id;
49     struct mixer *mixer;
50     struct mixer_ctl *ctl;
51 };
52 
53 /* effect specific operations.
54  * Only the init() and process() operations must be defined.
55  * Others are optional.
56  */
57 struct effect_ops_s {
58     int (*init)(effect_context_t *context);
59     int (*release)(effect_context_t *context);
60     int (*reset)(effect_context_t *context);
61     int (*enable)(effect_context_t *context);
62     int (*start)(effect_context_t *context, output_context_t *output);
63     int (*stop)(effect_context_t *context, output_context_t *output);
64     int (*disable)(effect_context_t *context);
65     int (*process)(effect_context_t *context, audio_buffer_t *in, audio_buffer_t *out);
66     int (*set_parameter)(effect_context_t *context, effect_param_t *param, uint32_t size);
67     int (*get_parameter)(effect_context_t *context, effect_param_t *param, uint32_t *size);
68     int (*set_device)(effect_context_t *context, uint32_t device);
69     int (*command)(effect_context_t *context, uint32_t cmdCode, uint32_t cmdSize,
70             void *pCmdData, uint32_t *replySize, void *pReplyData);
71 };
72 
73 struct effect_context_s {
74     const struct effect_interface_s *itfe;
75     /* node in created_effects_list */
76     struct listnode effects_list_node;
77     /* node in output_context_t.effects_list */
78     struct listnode output_node;
79     effect_config_t config;
80     const effect_descriptor_t *desc;
81     /* io handle of the output the effect is attached to */
82     audio_io_handle_t out_handle;
83     uint32_t state;
84     bool offload_enabled;
85     effect_ops_t ops;
86 };
87 
88 int set_config(effect_context_t *context, effect_config_t *config);
89 
90 bool effect_is_active(effect_context_t *context);
91 
92 #endif /* OFFLOAD_EFFECT_BUNDLE_H */
93