hooks: use hook to implement the callbacks

This way we get the version check implemented and save some
code.
This commit is contained in:
Wim Taymans 2019-05-15 11:19:23 +02:00
parent a78617c6a8
commit 6ee192dff5
26 changed files with 121 additions and 111 deletions

View file

@ -51,8 +51,7 @@ struct impl {
struct spa_log *log;
struct spa_loop *main_loop;
const struct spa_monitor_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
struct udev *udev;
struct udev_monitor *umonitor;
@ -266,7 +265,7 @@ static int emit_device(struct impl *this, uint32_t id, struct udev_device *dev)
event = spa_pod_builder_add_object(&b, SPA_TYPE_EVENT_Monitor, id);
fill_item(this, dev, &item, &b);
this->callbacks->event(this->callbacks_data, event);
spa_monitor_call_event(&this->callbacks, event);
return 0;
}
@ -378,8 +377,7 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
this = SPA_CONTAINER_OF(monitor, struct impl, monitor);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
if (callbacks) {
if ((res = impl_udev_open(this)) < 0)

View file

@ -293,8 +293,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -292,8 +292,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct state, node);
this->callbacks = callbacks;
this->callbacks_data = data;
this->callbacks = SPA_HOOK_INIT(callbacks, data);
return 0;
}

View file

@ -750,7 +750,9 @@ again:
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
state->io->buffer_id = b->id;
spa_log_trace_fp(state->log, "alsa-util %p: reuse buffer %u", state, b->id);
state->callbacks->reuse_buffer(state->callbacks_data, 0, b->id);
spa_node_call_reuse_buffer(&state->callbacks, 0, b->id);
state->ready_offset = 0;
}
written += n_frames;
@ -953,7 +955,7 @@ static int handle_play(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
state->range->min_size = state->threshold * state->frame_size;
state->range->max_size = state->threshold * state->frame_size;
}
res = state->callbacks->ready(state->callbacks_data, SPA_STATUS_NEED_BUFFER);
res = spa_node_call_ready(&state->callbacks, SPA_STATUS_NEED_BUFFER);
}
else {
res = spa_alsa_write(state, 0);
@ -987,7 +989,7 @@ static int handle_capture(struct state *state, uint64_t nsec, snd_pcm_sframes_t
io->buffer_id = b->id;
io->status = SPA_STATUS_HAVE_BUFFER;
}
state->callbacks->ready(state->callbacks_data, SPA_STATUS_HAVE_BUFFER);
spa_node_call_ready(&state->callbacks, SPA_STATUS_HAVE_BUFFER);
}
return 0;
}

View file

@ -82,8 +82,7 @@ struct state {
snd_output_t *output;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
struct spa_hook callbacks;
uint64_t info_all;
struct spa_node_info info;