mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
Add versions to structures
Use versions instead of size Remove user_data from callbacks, we can simply pass the callback struct.
This commit is contained in:
parent
4a219e81dd
commit
c3b73ba47d
45 changed files with 344 additions and 303 deletions
|
|
@ -111,8 +111,7 @@ struct impl {
|
|||
uint8_t props_buffer[512];
|
||||
struct props props;
|
||||
|
||||
struct spa_node_callbacks callbacks;
|
||||
void *user_data;
|
||||
const struct spa_node_callbacks *callbacks;
|
||||
|
||||
struct spa_source timer_source;
|
||||
struct itimerspec timerspec;
|
||||
|
|
@ -222,7 +221,7 @@ static int fill_buffer(struct impl *this, struct buffer *b)
|
|||
|
||||
static void set_timer(struct impl *this, bool enabled)
|
||||
{
|
||||
if (this->callbacks.have_output || this->props.live) {
|
||||
if ((this->callbacks && this->callbacks->have_output) || this->props.live) {
|
||||
if (enabled) {
|
||||
if (this->props.live) {
|
||||
uint64_t next_time = this->start_time + this->elapsed_time;
|
||||
|
|
@ -244,7 +243,7 @@ static void read_timer(struct impl *this)
|
|||
{
|
||||
uint64_t expirations;
|
||||
|
||||
if (this->callbacks.have_output || this->props.live) {
|
||||
if ((this->callbacks && this->callbacks->have_output) || this->props.live) {
|
||||
if (read(this->timer_source.fd, &expirations, sizeof(uint64_t)) < sizeof(uint64_t))
|
||||
perror("read timerfd");
|
||||
}
|
||||
|
|
@ -301,7 +300,7 @@ static void on_output(struct spa_source *source)
|
|||
res = make_buffer(this);
|
||||
|
||||
if (res == SPA_RESULT_HAVE_BUFFER)
|
||||
this->callbacks.have_output(&this->node, this->user_data);
|
||||
this->callbacks->have_output(this->callbacks, &this->node);
|
||||
}
|
||||
|
||||
static int impl_node_send_command(struct spa_node *node, struct spa_command *command)
|
||||
|
|
@ -355,9 +354,7 @@ static int impl_node_send_command(struct spa_node *node, struct spa_command *com
|
|||
|
||||
static int
|
||||
impl_node_set_callbacks(struct spa_node *node,
|
||||
const struct spa_node_callbacks *callbacks,
|
||||
size_t callbacks_size,
|
||||
void *user_data)
|
||||
const struct spa_node_callbacks *callbacks)
|
||||
{
|
||||
struct impl *this;
|
||||
|
||||
|
|
@ -365,12 +362,11 @@ impl_node_set_callbacks(struct spa_node *node,
|
|||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
|
||||
if (this->data_loop == NULL && callbacks->have_output != NULL) {
|
||||
if (this->data_loop == NULL && callbacks != NULL && callbacks->have_output != NULL) {
|
||||
spa_log_error(this->log, "a data_loop is needed for async operation");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->callbacks = *callbacks;
|
||||
this->user_data = user_data;
|
||||
this->callbacks = callbacks;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -810,14 +806,15 @@ static int impl_node_process_output(struct spa_node *node)
|
|||
this->io->buffer_id = SPA_ID_INVALID;
|
||||
}
|
||||
|
||||
if (!this->callbacks.have_output && (io->status == SPA_RESULT_NEED_BUFFER))
|
||||
if ((this->callbacks == NULL || this->callbacks->have_output == NULL) &&
|
||||
(io->status == SPA_RESULT_NEED_BUFFER))
|
||||
return make_buffer(this);
|
||||
else
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static const struct spa_node impl_node = {
|
||||
sizeof(struct spa_node),
|
||||
SPA_VERSION_NODE,
|
||||
NULL,
|
||||
impl_node_get_props,
|
||||
impl_node_set_props,
|
||||
|
|
@ -878,7 +875,7 @@ impl_clock_get_time(struct spa_clock *clock,
|
|||
}
|
||||
|
||||
static const struct spa_clock impl_clock = {
|
||||
sizeof(struct spa_clock),
|
||||
SPA_VERSION_CLOCK,
|
||||
NULL,
|
||||
SPA_CLOCK_STATE_STOPPED,
|
||||
impl_clock_get_props,
|
||||
|
|
@ -1004,6 +1001,7 @@ impl_enum_interface_info(const struct spa_handle_factory *factory,
|
|||
}
|
||||
|
||||
const struct spa_handle_factory spa_videotestsrc_factory = {
|
||||
SPA_VERSION_HANDLE_FACTORY,
|
||||
NAME,
|
||||
NULL,
|
||||
sizeof(struct impl),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue