Ethan Chen | b6e32fd | 2015-06-07 11:34:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The CyanogenMod 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 CM_AUDIO_AMPLIFIER_INTERFACE_H |
| 18 | #define CM_AUDIO_AMPLIFIER_INTERFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/audio.h> |
| 25 | #include <hardware/hardware.h> |
| 26 | |
| 27 | #include <system/audio.h> |
| 28 | |
| 29 | __BEGIN_DECLS |
| 30 | |
| 31 | #define AMPLIFIER_HARDWARE_MODULE_ID "audio_amplifier" |
| 32 | |
| 33 | #define AMPLIFIER_HARDWARE_INTERFACE "audio_amplifier_hw_if" |
| 34 | |
| 35 | #define AMPLIFIER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 36 | |
| 37 | #define AMPLIFIER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
| 38 | #define AMPLIFIER_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) |
| 39 | #define AMPLIFIER_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1) |
| 40 | #define AMPLIFIER_DEVICE_API_VERSION_CURRENT AMPLIFIER_DEVICE_API_VERSION_2_1 |
| 41 | |
| 42 | struct str_parms; |
| 43 | |
| 44 | typedef struct amplifier_device { |
| 45 | /** |
| 46 | * Common methods of the amplifier device. This *must* be the first member |
| 47 | * of amplifier_device as users of this structure will cast a hw_device_t |
| 48 | * to amplifier_device pointer in contexts where it's known |
| 49 | * the hw_device_t references a amplifier_device. |
| 50 | */ |
| 51 | struct hw_device_t common; |
| 52 | |
| 53 | /** |
| 54 | * Notify amplifier device of current input devices |
| 55 | * |
| 56 | * This function should handle only input devices. |
| 57 | */ |
| 58 | int (*set_input_devices)(struct amplifier_device *device, uint32_t devices); |
| 59 | |
| 60 | /** |
| 61 | * Notify amplifier device of current output devices |
| 62 | * |
| 63 | * This function should handle only output devices. |
| 64 | */ |
| 65 | int (*set_output_devices)(struct amplifier_device *device, uint32_t devices); |
| 66 | |
| 67 | /** |
| 68 | * Notify amplifier device of output device enable/disable |
| 69 | * |
| 70 | * This function should handle only output devices. |
| 71 | */ |
| 72 | int (*enable_output_devices)(struct amplifier_device *device, |
| 73 | uint32_t devices, bool enable); |
| 74 | |
| 75 | /** |
| 76 | * Notify amplifier device of input device enable/disable |
| 77 | * |
| 78 | * This function should handle only input devices. |
| 79 | */ |
| 80 | int (*enable_input_devices)(struct amplifier_device *device, |
| 81 | uint32_t devices, bool enable); |
| 82 | |
| 83 | /** |
| 84 | * Notify amplifier device about current audio mode |
| 85 | */ |
| 86 | int (*set_mode)(struct amplifier_device *device, audio_mode_t mode); |
| 87 | |
| 88 | /** |
| 89 | * Notify amplifier device that an output stream has started |
| 90 | */ |
| 91 | int (*output_stream_start)(struct amplifier_device *device, |
| 92 | struct audio_stream_out *stream, bool offload); |
| 93 | |
| 94 | /** |
| 95 | * Notify amplifier device that an input stream has started |
| 96 | */ |
| 97 | int (*input_stream_start)(struct amplifier_device *device, |
| 98 | struct audio_stream_in *stream); |
| 99 | |
| 100 | /** |
| 101 | * Notify amplifier device that an output stream has stopped |
| 102 | */ |
| 103 | int (*output_stream_standby)(struct amplifier_device *device, |
| 104 | struct audio_stream_out *stream); |
| 105 | |
| 106 | /** |
| 107 | * Notify amplifier device that an input stream has stopped |
| 108 | */ |
| 109 | int (*input_stream_standby)(struct amplifier_device *device, |
| 110 | struct audio_stream_in *stream); |
| 111 | |
| 112 | /** |
| 113 | * set/get audio device parameters. |
| 114 | */ |
| 115 | int (*set_parameters)(struct amplifier_device *device, |
| 116 | struct str_parms *parms); |
| 117 | |
| 118 | /** |
| 119 | * set/get output stream parameters. |
| 120 | */ |
| 121 | int (*out_set_parameters)(struct amplifier_device *device, |
| 122 | struct str_parms *parms); |
| 123 | |
| 124 | /** |
| 125 | * set/get input stream parameters. |
| 126 | */ |
| 127 | int (*in_set_parameters)(struct amplifier_device *device, |
| 128 | struct str_parms *parms); |
| 129 | } amplifier_device_t; |
| 130 | |
| 131 | typedef struct amplifier_module { |
| 132 | /** |
| 133 | * Common methods of the amplifier module. This *must* be the first member |
| 134 | * of amplifier_module as users of this structure will cast a hw_module_t |
| 135 | * to amplifier_module pointer in contexts where it's known |
| 136 | * the hw_module_t references a amplifier_module. |
| 137 | */ |
| 138 | struct hw_module_t common; |
| 139 | } amplifier_module_t; |
| 140 | |
| 141 | /** convenience API for opening and closing a supported device */ |
| 142 | |
| 143 | static inline int amplifier_device_open(const struct hw_module_t *module, |
| 144 | struct amplifier_device **device) |
| 145 | { |
| 146 | return module->methods->open(module, AMPLIFIER_HARDWARE_INTERFACE, |
| 147 | (struct hw_device_t **) device); |
| 148 | } |
| 149 | |
| 150 | static inline int amplifier_device_close(struct amplifier_device *device) |
| 151 | { |
| 152 | return device->common.close(&device->common); |
| 153 | } |
| 154 | |
| 155 | __END_DECLS |
| 156 | |
| 157 | #endif // CM_AUDIO_AMPLIFIER_INTERFACE_H |