Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2018 The Chromium 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 WEBRTC_APM_H_ |
| 7 | #define WEBRTC_APM_H_ |
| 8 | |
Hsin-Yu Chao | 2583e8a | 2018-11-13 17:13:09 +0800 | [diff] [blame] | 9 | #include <iniparser.h> |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #define WEBRTC_APM_API __attribute__((visibility("default"))) |
| 14 | |
| 15 | /* Pointer to a webrtc::AudioProcessing instance. */ |
| 16 | typedef void* webrtc_apm; |
| 17 | |
Hsin-Yu Chao | b3dfb0e | 2021-04-20 08:04:00 +0000 | [diff] [blame] | 18 | /* Enables UMA metrics in webrtc APM. |
| 19 | * Args: |
| 20 | * prefix - String to append to existing histogram name. |
| 21 | */ |
| 22 | WEBRTC_APM_API void webrtc_apm_init_metrics(const char *prefix); |
| 23 | |
Per Åhgren | aa5a43f | 2021-03-30 08:29:43 +0200 | [diff] [blame] | 24 | /* Creates a webrtc_apm for forward stream properties using optional enforcement |
| 25 | * of the effects that are specified in the config files. In CRAS use case it |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 26 | * is usually created for input stream. |
| 27 | * Args: |
Per Åhgren | aa5a43f | 2021-03-30 08:29:43 +0200 | [diff] [blame] | 28 | * num_channels - Number of channels of the forward stream. |
| 29 | * frame_rate - Frame rate used by forward stream. |
| 30 | * aec_config - Pointer to aec config. |
| 31 | * apm_config - Pointer to apm config. |
| 32 | * enforce_aec_on - When set to 1, enforces the aec to be activated |
| 33 | * regardless of settings in apm.ini |
| 34 | * enforce_ns_on - When set to 1, enforces the ns to be activated |
| 35 | * regardless of settings in apm.ini |
| 36 | * enforce_agc_on - When set to 1, enforces the agc to be activated |
| 37 | * regardless of settings in apm.ini |
| 38 | */ |
| 39 | WEBRTC_APM_API webrtc_apm webrtc_apm_create_with_enforced_effects( |
| 40 | unsigned int num_channels, |
| 41 | unsigned int frame_rate, |
| 42 | dictionary *aec_ini, |
| 43 | dictionary *apm_ini, |
| 44 | unsigned int enforce_aec_on, |
| 45 | unsigned int enforce_ns_on, |
| 46 | unsigned int enforce_agc_on); |
| 47 | |
| 48 | /* Deprecated: Should be removed. |
| 49 | * Creates a webrtc_apm for forward stream properties using the parameters in |
| 50 | * the configs. In CRAS use case it is usually created for input stream. |
| 51 | * Args: |
| 52 | * num_channels - Number of channels of the forward stream. |
| 53 | * frame_rate - Frame rate used by forward stream. |
| 54 | * aec_config - Pointer to aec config. |
| 55 | * apm_config - Pointer to apm config. |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 56 | */ |
| 57 | WEBRTC_APM_API webrtc_apm webrtc_apm_create( |
| 58 | unsigned int num_channels, |
| 59 | unsigned int frame_rate, |
Hsin-Yu Chao | 2583e8a | 2018-11-13 17:13:09 +0800 | [diff] [blame] | 60 | dictionary *aec_ini, |
| 61 | dictionary *apm_ini); |
| 62 | |
| 63 | /* Dumps configs content. |
| 64 | * Args: |
| 65 | * apm_ini - APM config file in ini format. |
| 66 | * aec_ini - AEC3 config file in ini format. |
| 67 | */ |
| 68 | WEBRTC_APM_API void webrtc_apm_dump_configs( |
| 69 | dictionary *apm_ini, |
| 70 | dictionary *aec_ini); |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 71 | |
| 72 | /* Destroys a webrtc_apm instance. */ |
| 73 | WEBRTC_APM_API void webrtc_apm_destroy(webrtc_apm apm); |
| 74 | |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 75 | /* Processes deinterleaved float data in reverse stream. Expecting data |
| 76 | * size be 10 ms equivalent of frames. */ |
| 77 | WEBRTC_APM_API int webrtc_apm_process_reverse_stream_f( |
| 78 | webrtc_apm ptr, |
| 79 | int num_channels, int rate, |
| 80 | float *const *data); |
| 81 | |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 82 | /* Processes deinterleaved float data in forward stream. Expecting data |
| 83 | * size be 10 ms equivalent of frames. */ |
| 84 | WEBRTC_APM_API int webrtc_apm_process_stream_f(webrtc_apm ptr, |
| 85 | int num_channels, |
| 86 | int rate, |
| 87 | float *const *data); |
| 88 | |
| 89 | /* Sets the delay in ms between apm analyzes a frame in reverse stream |
| 90 | * (playback) and this frame received as echo in forward stream (record) |
| 91 | * This is required for echo cancellation enabled apm. |
| 92 | * Args: |
| 93 | * ptr - Pointer to the webrtc_apm instance. |
| 94 | * delay_ms - The delay in ms. |
| 95 | */ |
| 96 | WEBRTC_APM_API int webrtc_apm_set_stream_delay(webrtc_apm ptr, int delay_ms); |
| 97 | |
Hsin-Yu Chao | b6f63cd | 2018-03-17 16:52:35 +0800 | [diff] [blame] | 98 | /* Dump aec debug info to a file. |
| 99 | * Args: |
| 100 | * ptr - Pointer to the webrtc_apm instance. |
| 101 | * work_queue - Pointer holding or to hold the allocated task queue for |
| 102 | * aec dump. Will be deleted when aec dump stops. |
| 103 | * start - True to start dumping, false to stop. |
| 104 | * handle - Pointer of the file storing aec dump. |
| 105 | */ |
| 106 | WEBRTC_APM_API int webrtc_apm_aec_dump( |
| 107 | webrtc_apm ptr, void** work_queue, |
| 108 | int start, FILE *handle); |
| 109 | |
| 110 | #endif /* WEBRTC_APM_H_ */ |