mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-24 19:20:04 +01:00
stream: refactor the free function
In the destroy we first remove all listeners and then we clean up the memory. Move the memory cleanup to a separate function to make it easier to refcount later.
This commit is contained in:
parent
0d7cb9b39f
commit
b68698a086
2 changed files with 52 additions and 40 deletions
|
|
@ -1389,6 +1389,28 @@ static void free_port(struct filter *impl, struct port *port)
|
||||||
free(port);
|
free(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void filter_free(struct pw_filter *filter)
|
||||||
|
{
|
||||||
|
struct filter *impl = SPA_CONTAINER_OF(filter, struct filter, this);
|
||||||
|
|
||||||
|
pw_log_debug("%p: free", filter);
|
||||||
|
clear_params(impl, NULL, SPA_ID_INVALID);
|
||||||
|
|
||||||
|
free(filter->error);
|
||||||
|
|
||||||
|
pw_properties_free(filter->properties);
|
||||||
|
|
||||||
|
pw_map_clear(&impl->ports[SPA_DIRECTION_INPUT]);
|
||||||
|
pw_map_clear(&impl->ports[SPA_DIRECTION_OUTPUT]);
|
||||||
|
|
||||||
|
free(filter->name);
|
||||||
|
|
||||||
|
if (impl->data.context)
|
||||||
|
pw_context_destroy(impl->data.context);
|
||||||
|
|
||||||
|
free(impl);
|
||||||
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void pw_filter_destroy(struct pw_filter *filter)
|
void pw_filter_destroy(struct pw_filter *filter)
|
||||||
{
|
{
|
||||||
|
|
@ -1411,26 +1433,10 @@ void pw_filter_destroy(struct pw_filter *filter)
|
||||||
spa_hook_remove(&filter->core_listener);
|
spa_hook_remove(&filter->core_listener);
|
||||||
spa_list_remove(&filter->link);
|
spa_list_remove(&filter->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_params(impl, NULL, SPA_ID_INVALID);
|
|
||||||
|
|
||||||
pw_log_debug("%p: free", filter);
|
|
||||||
free(filter->error);
|
|
||||||
|
|
||||||
pw_properties_free(filter->properties);
|
|
||||||
|
|
||||||
spa_hook_list_clean(&impl->hooks);
|
spa_hook_list_clean(&impl->hooks);
|
||||||
spa_hook_list_clean(&filter->listener_list);
|
spa_hook_list_clean(&filter->listener_list);
|
||||||
|
|
||||||
pw_map_clear(&impl->ports[SPA_DIRECTION_INPUT]);
|
filter_free(filter);
|
||||||
pw_map_clear(&impl->ports[SPA_DIRECTION_OUTPUT]);
|
|
||||||
|
|
||||||
free(filter->name);
|
|
||||||
|
|
||||||
if (impl->data.context)
|
|
||||||
pw_context_destroy(impl->data.context);
|
|
||||||
|
|
||||||
free(impl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
|
|
@ -715,8 +715,9 @@ static int impl_send_command(void *object, const struct spa_command *command)
|
||||||
case SPA_NODE_COMMAND_Suspend:
|
case SPA_NODE_COMMAND_Suspend:
|
||||||
case SPA_NODE_COMMAND_Flush:
|
case SPA_NODE_COMMAND_Flush:
|
||||||
case SPA_NODE_COMMAND_Pause:
|
case SPA_NODE_COMMAND_Pause:
|
||||||
pw_loop_invoke(impl->main_loop,
|
/* this ensures we don't have any pending invokes in the queue after we
|
||||||
NULL, 0, NULL, 0, false, impl);
|
* emit the state change and/or command. */
|
||||||
|
pw_loop_invoke(impl->main_loop, NULL, 0, NULL, 0, false, impl);
|
||||||
if (stream->state == PW_STREAM_STATE_STREAMING && id != SPA_NODE_COMMAND_Flush) {
|
if (stream->state == PW_STREAM_STATE_STREAMING && id != SPA_NODE_COMMAND_Flush) {
|
||||||
pw_log_debug("%p: pause", stream);
|
pw_log_debug("%p: pause", stream);
|
||||||
stream_set_state(stream, PW_STREAM_STATE_PAUSED, 0, NULL);
|
stream_set_state(stream, PW_STREAM_STATE_PAUSED, 0, NULL);
|
||||||
|
|
@ -1748,11 +1749,35 @@ static int stream_disconnect(struct stream *impl)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void stream_free(struct pw_stream *stream)
|
||||||
|
{
|
||||||
|
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
|
||||||
|
struct control *c;
|
||||||
|
|
||||||
|
pw_log_debug("%p: free", stream);
|
||||||
|
clear_params(impl, SPA_ID_INVALID, 0);
|
||||||
|
|
||||||
|
free(stream->error);
|
||||||
|
|
||||||
|
pw_properties_free(stream->properties);
|
||||||
|
|
||||||
|
free(stream->name);
|
||||||
|
|
||||||
|
spa_list_consume(c, &stream->controls, link) {
|
||||||
|
spa_list_remove(&c->link);
|
||||||
|
free(c);
|
||||||
|
}
|
||||||
|
if (impl->data.context)
|
||||||
|
pw_context_destroy(impl->data.context);
|
||||||
|
|
||||||
|
pw_properties_free(impl->port_props);
|
||||||
|
free(impl);
|
||||||
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void pw_stream_destroy(struct pw_stream *stream)
|
void pw_stream_destroy(struct pw_stream *stream)
|
||||||
{
|
{
|
||||||
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
|
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
|
||||||
struct control *c;
|
|
||||||
|
|
||||||
ensure_loop(impl->main_loop, return);
|
ensure_loop(impl->main_loop, return);
|
||||||
|
|
||||||
|
|
@ -1768,29 +1793,10 @@ void pw_stream_destroy(struct pw_stream *stream)
|
||||||
spa_list_remove(&stream->link);
|
spa_list_remove(&stream->link);
|
||||||
stream->core = NULL;
|
stream->core = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_params(impl, SPA_ID_INVALID, 0);
|
|
||||||
|
|
||||||
pw_log_debug("%p: free", stream);
|
|
||||||
free(stream->error);
|
|
||||||
|
|
||||||
pw_properties_free(stream->properties);
|
|
||||||
|
|
||||||
free(stream->name);
|
|
||||||
|
|
||||||
spa_list_consume(c, &stream->controls, link) {
|
|
||||||
spa_list_remove(&c->link);
|
|
||||||
free(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
spa_hook_list_clean(&impl->hooks);
|
spa_hook_list_clean(&impl->hooks);
|
||||||
spa_hook_list_clean(&stream->listener_list);
|
spa_hook_list_clean(&stream->listener_list);
|
||||||
|
|
||||||
if (impl->data.context)
|
stream_free(stream);
|
||||||
pw_context_destroy(impl->data.context);
|
|
||||||
|
|
||||||
pw_properties_free(impl->port_props);
|
|
||||||
free(impl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue