mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
spa: improve the AEC interface
Place the methods on the interface so that we can call them. Rename create to init because that is what it does. Add support for listener and events so that we can signal property changes later.
This commit is contained in:
parent
9386c70b3a
commit
c5c9ecdd87
5 changed files with 130 additions and 130 deletions
|
|
@ -24,7 +24,6 @@
|
|||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "module-echo-cancel/echo-cancel.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -188,7 +187,7 @@ struct impl {
|
|||
uint32_t out_ringsize;
|
||||
struct spa_ringbuffer out_ring;
|
||||
|
||||
const struct echo_cancel_info *aec_info;
|
||||
struct spa_audio_aec *aec;
|
||||
uint32_t aec_blocksize;
|
||||
|
||||
unsigned int capture_ready:1;
|
||||
|
|
@ -288,7 +287,7 @@ static void process(struct impl *impl)
|
|||
pw_stream_queue_buffer(impl->playback, pout);
|
||||
|
||||
/* Now run the canceller */
|
||||
echo_cancel_run(impl->aec_info, impl->spa_handle, rec, play_delayed, out, size / sizeof(float));
|
||||
spa_audio_aec_run(impl->aec, rec, play_delayed, out, size / sizeof(float));
|
||||
|
||||
/* Next, copy over the output to the output ringbuffer */
|
||||
avail = spa_ringbuffer_get_write_index(&impl->out_ring, &oindex);
|
||||
|
|
@ -652,8 +651,8 @@ static int setup_streams(struct impl *impl)
|
|||
pw_properties_set(props, PW_KEY_NODE_LINK_GROUP, str);
|
||||
if ((str = pw_properties_get(impl->source_props, PW_KEY_NODE_LATENCY)) != NULL)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, str);
|
||||
else if (impl->aec_info->latency)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec_info->latency);
|
||||
else if (impl->aec->latency)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec->latency);
|
||||
|
||||
impl->capture = pw_stream_new(impl->core,
|
||||
"Echo-Cancel Capture", props);
|
||||
|
|
@ -685,8 +684,8 @@ static int setup_streams(struct impl *impl)
|
|||
pw_properties_set(props, PW_KEY_NODE_LINK_GROUP, str);
|
||||
if ((str = pw_properties_get(impl->sink_props, PW_KEY_NODE_LATENCY)) != NULL)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, str);
|
||||
else if (impl->aec_info->latency)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec_info->latency);
|
||||
else if (impl->aec->latency)
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec->latency);
|
||||
|
||||
impl->playback = pw_stream_new(impl->core,
|
||||
"Echo-Cancel Playback", props);
|
||||
|
|
@ -999,42 +998,42 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_AEC, &iface)) < 0) {
|
||||
pw_log_error("can't get %s interface %d", SPA_TYPE_INTERFACE_AEC, res);
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_AUDIO_AEC, &iface)) < 0) {
|
||||
pw_log_error("can't get %s interface %d", SPA_TYPE_INTERFACE_AUDIO_AEC, res);
|
||||
return res;
|
||||
}
|
||||
impl->aec_info = iface;
|
||||
impl->aec = iface;
|
||||
impl->spa_handle = handle;
|
||||
if (impl->aec_info->iface.version != SPA_VERSION_AUDIO_AEC) {
|
||||
if (impl->aec->iface.version != SPA_VERSION_AUDIO_AEC) {
|
||||
pw_log_error("codec plugin %s has incompatible ABI version (%d != %d)",
|
||||
SPA_NAME_AEC, impl->aec_info->iface.version, SPA_VERSION_AUDIO_AEC);
|
||||
SPA_NAME_AEC, impl->aec->iface.version, SPA_VERSION_AUDIO_AEC);
|
||||
res = -ENOENT;
|
||||
goto error;
|
||||
}
|
||||
|
||||
(void)SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_AEC, (struct echo_cancel_info *)impl->aec_info);
|
||||
(void)SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_AUDIO_AEC, (struct spa_audio_aec *)impl->aec);
|
||||
|
||||
pw_log_info("Using plugin AEC %s", impl->aec_info->name);
|
||||
pw_log_info("Using plugin AEC %s", impl->aec->name);
|
||||
|
||||
if ((str = pw_properties_get(props, "aec.args")) != NULL)
|
||||
aec_props = pw_properties_new_string(str);
|
||||
else
|
||||
aec_props = pw_properties_new(NULL, NULL);
|
||||
|
||||
if (echo_cancel_create(impl->aec_info, impl->spa_handle, &aec_props->dict, &impl->info)) {
|
||||
pw_log_error("codec plugin %s create failed", impl->aec_info->name);
|
||||
if (spa_audio_aec_init(impl->aec, &aec_props->dict, &impl->info)) {
|
||||
pw_log_error("codec plugin %s create failed", impl->aec->name);
|
||||
res = -ENOENT;
|
||||
goto error;
|
||||
}
|
||||
|
||||
pw_properties_free(aec_props);
|
||||
|
||||
if (impl->aec_info->latency) {
|
||||
if (impl->aec->latency) {
|
||||
unsigned int num, denom, req_num, req_denom;
|
||||
unsigned int factor = 0;
|
||||
unsigned int new_num = 0;
|
||||
|
||||
spa_assert_se(sscanf(impl->aec_info->latency, "%u/%u", &num, &denom) == 2);
|
||||
spa_assert_se(sscanf(impl->aec->latency, "%u/%u", &num, &denom) == 2);
|
||||
|
||||
if ((str = pw_properties_get(props, PW_KEY_NODE_LATENCY)) != NULL) {
|
||||
sscanf(str, "%u/%u", &req_num, &req_denom);
|
||||
|
|
@ -1043,8 +1042,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
}
|
||||
|
||||
if (factor == 0 || new_num == 0) {
|
||||
pw_log_info("Setting node latency to %s", impl->aec_info->latency);
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec_info->latency);
|
||||
pw_log_info("Setting node latency to %s", impl->aec->latency);
|
||||
pw_properties_set(props, PW_KEY_NODE_LATENCY, impl->aec->latency);
|
||||
impl->aec_blocksize = sizeof(float) * impl->info.rate * num / denom;
|
||||
} else {
|
||||
pw_log_info("Setting node latency to %u/%u", new_num, req_denom);
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/* PipeWire
|
||||
*
|
||||
* Copyright © 2021 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include <spa/utils/dict.h>
|
||||
#include <spa/utils/hook.h>
|
||||
#include <spa/param/audio/raw.h>
|
||||
#include <spa/support/plugin.h>
|
||||
|
||||
#include <pipewire/properties.h>
|
||||
|
||||
#define echo_cancel_create(i,...) (i)->create(__VA_ARGS__)
|
||||
#define echo_cancel_run(i,...) (i)->run(__VA_ARGS__)
|
||||
Loading…
Add table
Add a link
Reference in a new issue