1 /* Copyright 2018 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #ifndef CRAS_APM_LIST_H_ 7 #define CRAS_APM_LIST_H_ 8 9 #include "cras_types.h" 10 11 struct cras_audio_area; 12 struct cras_audio_format; 13 struct cras_apm; 14 struct cras_apm_list; 15 struct float_buffer; 16 17 #ifdef HAVE_WEBRTC_APM 18 19 /* Initialize the apm list for analyzing output data. */ 20 int cras_apm_list_init(const char *device_config_dir); 21 22 /* Reloads the aec config. Used for debug and tuning. */ 23 void cras_apm_list_reload_aec_config(); 24 25 /* Deinitialize apm list to free all allocated resources. */ 26 int cras_apm_list_deinit(); 27 28 /* 29 * Creates an list to hold all APM instances created when a stream 30 * attaches to an iodev. 31 * Args: 32 * stream_ptr - Pointer to the stream. 33 * effects - Bit map specifying the enabled effects on this stream. 34 */ 35 struct cras_apm_list *cras_apm_list_create(void *stream_ptr, 36 uint64_t effects); 37 38 /* 39 * Creates a cras_apm and adds it to the list. 40 * Args: 41 * list - The list holding APM instances. 42 * dev_ptr - Pointer to the iodev to add new APM for. 43 * fmt - Format of the audio data used for this cras_apm. 44 */ 45 struct cras_apm *cras_apm_list_add(struct cras_apm_list *list, 46 void *dev_ptr, 47 const struct cras_audio_format *fmt); 48 49 /* 50 * Gets the cras_apm instance in the list that associates with given dev. 51 * Args: 52 * list - The list holding APM instances. 53 * dev_ptr - The iodev as key to look up associated APM. 54 */ 55 struct cras_apm *cras_apm_list_get(struct cras_apm_list *list, 56 void *dev_ptr); 57 58 /* 59 * Gets the effects bit map of the APM list. 60 * Args: 61 * list - The list holding APM instances. 62 */ 63 uint64_t cras_apm_list_get_effects(struct cras_apm_list *list); 64 65 /* Removes a cras_apm from list and destroys it. */ 66 int cras_apm_list_destroy(struct cras_apm_list *list); 67 68 /* 69 * Removes an APM from the list, expected to be used when an iodev is no 70 * longer open for the client stream holding the APM list. 71 * Args: 72 * list - The list holding APM instances. 73 * dev_ptr - Device pointer used to look up which apm to remove. 74 */ 75 void cras_apm_list_remove(struct cras_apm_list *list, void *dev_ptr); 76 77 /* Passes audio data from hardware for cras_apm to process. 78 * Args: 79 * apm - The cras_apm instance. 80 * input - Float buffer from device for apm to process. 81 * offset - Offset in |input| to note the data position to start 82 * reading. 83 */ 84 int cras_apm_list_process(struct cras_apm *apm, 85 struct float_buffer *input, 86 unsigned int offset); 87 88 /* Gets the APM processed data in the form of audio area. 89 * Args: 90 * apm - The cras_apm instance that owns the audio area pointer and 91 * processed data. 92 * Returns: 93 * The audio area used to read processed data. No need to free 94 * by caller. 95 */ 96 struct cras_audio_area *cras_apm_list_get_processed(struct cras_apm *apm); 97 98 /* Tells |apm| that |frames| of processed data has been used, so |apm| 99 * can allocate space to read more from input device. 100 * Args: 101 * apm - The cras_apm instance owns the processed data. 102 * frames - The number in frames of processed data to mark as used. 103 */ 104 void cras_apm_list_put_processed(struct cras_apm *apm, unsigned int frames); 105 106 /* Gets the format of the actual data processed by webrtc-apm library. 107 * Args: 108 * apm - The cras_apm instance holding audio data and format info. 109 */ 110 struct cras_audio_format *cras_apm_list_get_format(struct cras_apm *apm); 111 112 /* Sets debug recording to start or stop. 113 * Args: 114 * list - List contains the apm instance to start/stop debug recording. 115 * dev_ptr - Use as key to look up specific apm to do aec dump. 116 * start - True to set debug recording start, otherwise stop. 117 * fd - File descriptor to aec dump destination. 118 */ 119 void cras_apm_list_set_aec_dump(struct cras_apm_list *list, 120 void *dev_ptr, 121 int start, 122 int fd); 123 124 #else 125 126 /* 127 * If webrtc audio processing library is not available then define all 128 * cras_apm_list functions as dummy. As long as cras_apm_list_add returns 129 * NULL, non of the other functions should be called. 130 */ 131 static inline int cras_apm_list_init(const char *device_config_dir) 132 { 133 return 0; 134 } 135 static inline void cras_apm_list_reload_aec_config() 136 { 137 } 138 static inline struct cras_apm_list *cras_apm_list_create(void *stream_ptr, 139 unsigned int effects) 140 { 141 return NULL; 142 } 143 static inline struct cras_apm *cras_apm_list_add( 144 struct cras_apm_list *list, 145 void *dev_ptr, 146 const struct cras_audio_format *fmt) 147 { 148 return NULL; 149 } 150 static inline struct cras_apm *cras_apm_list_get(struct cras_apm_list *list, 151 void *dev_ptr) 152 { 153 return NULL; 154 } 155 static inline uint64_t cras_apm_list_get_effects(struct cras_apm_list *list) 156 { 157 return 0; 158 } 159 static inline int cras_apm_list_destroy(struct cras_apm_list *list) 160 { 161 return 0; 162 } 163 static inline void cras_apm_list_remove(struct cras_apm_list *list, 164 void *dev_ptr) 165 { 166 } 167 168 static inline int cras_apm_list_process(struct cras_apm *apm, 169 struct float_buffer *input, 170 unsigned int offset) 171 { 172 return 0; 173 } 174 175 static inline struct cras_audio_area *cras_apm_list_get_processed( 176 struct cras_apm *apm) 177 { 178 return NULL; 179 } 180 181 static inline void cras_apm_list_put_processed(struct cras_apm *apm, 182 unsigned int frames) 183 { 184 } 185 186 static inline struct cras_audio_format *cras_apm_list_get_format( 187 struct cras_apm *apm) 188 { 189 return NULL; 190 } 191 192 static inline void cras_apm_list_set_aec_dump(struct cras_apm_list *list, 193 void *dev_ptr, 194 int start, 195 int fd) 196 { 197 } 198 199 #endif /* HAVE_WEBRTC_APM */ 200 201 #endif /* CRAS_APM_LIST_H_ */ 202