mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
examples: update some examples with RequestProcess
Let video-src unconditionally call _trigger_process() when it is ready. This will either start the graph when it is the driver or emit a RequestProcess event to the driver. Let video-play-pull intercept the RequestProcess command and use it to do a trigger_process(). Otherwise use a timer to pull in the next frame.
This commit is contained in:
parent
baca092ba5
commit
a84e43e3ee
2 changed files with 42 additions and 17 deletions
|
|
@ -74,6 +74,7 @@ struct data {
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
SDL_Rect cursor_rect;
|
SDL_Rect cursor_rect;
|
||||||
bool is_yuv;
|
bool is_yuv;
|
||||||
|
bool have_request_process;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void handle_events(struct data *data)
|
static void handle_events(struct data *data)
|
||||||
|
|
@ -244,6 +245,25 @@ on_process(void *_data)
|
||||||
pw_stream_queue_buffer(stream, b);
|
pw_stream_queue_buffer(stream, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void enable_timeouts(struct data *data, bool enabled)
|
||||||
|
{
|
||||||
|
struct timespec timeout, interval, *to, *iv;
|
||||||
|
|
||||||
|
if (!enabled || data->have_request_process) {
|
||||||
|
to = iv = NULL;
|
||||||
|
} else {
|
||||||
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_nsec = 1;
|
||||||
|
interval.tv_sec = 0;
|
||||||
|
interval.tv_nsec = 80 * SPA_NSEC_PER_MSEC;
|
||||||
|
to = &timeout;
|
||||||
|
iv = &interval;
|
||||||
|
}
|
||||||
|
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
|
||||||
|
data->timer, to, iv, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void on_stream_state_changed(void *_data, enum pw_stream_state old,
|
static void on_stream_state_changed(void *_data, enum pw_stream_state old,
|
||||||
enum pw_stream_state state, const char *error)
|
enum pw_stream_state state, const char *error)
|
||||||
{
|
{
|
||||||
|
|
@ -254,22 +274,11 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old,
|
||||||
pw_main_loop_quit(data->loop);
|
pw_main_loop_quit(data->loop);
|
||||||
break;
|
break;
|
||||||
case PW_STREAM_STATE_PAUSED:
|
case PW_STREAM_STATE_PAUSED:
|
||||||
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
|
enable_timeouts(data, false);
|
||||||
data->timer, NULL, NULL, false);
|
|
||||||
break;
|
break;
|
||||||
case PW_STREAM_STATE_STREAMING:
|
case PW_STREAM_STATE_STREAMING:
|
||||||
{
|
enable_timeouts(data, true);
|
||||||
struct timespec timeout, interval;
|
|
||||||
|
|
||||||
timeout.tv_sec = 0;
|
|
||||||
timeout.tv_nsec = 1;
|
|
||||||
interval.tv_sec = 0;
|
|
||||||
interval.tv_nsec = 80 * SPA_NSEC_PER_MSEC;
|
|
||||||
|
|
||||||
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
|
|
||||||
data->timer, &timeout, &interval, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -297,9 +306,25 @@ on_trigger_done(void *_data)
|
||||||
static void on_timeout(void *userdata, uint64_t expirations)
|
static void on_timeout(void *userdata, uint64_t expirations)
|
||||||
{
|
{
|
||||||
struct data *data = userdata;
|
struct data *data = userdata;
|
||||||
|
if (!data->have_request_process)
|
||||||
pw_stream_trigger_process(data->stream);
|
pw_stream_trigger_process(data->stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_command(void *_data, const struct spa_command *command)
|
||||||
|
{
|
||||||
|
struct data *data = _data;
|
||||||
|
switch (SPA_NODE_COMMAND_ID(command)) {
|
||||||
|
case SPA_NODE_COMMAND_RequestProcess:
|
||||||
|
data->have_request_process = true;
|
||||||
|
enable_timeouts(data, false);
|
||||||
|
pw_stream_trigger_process(data->stream);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Be notified when the stream param changes. We're only looking at the
|
/* Be notified when the stream param changes. We're only looking at the
|
||||||
* format changes.
|
* format changes.
|
||||||
*
|
*
|
||||||
|
|
@ -432,6 +457,7 @@ static const struct pw_stream_events stream_events = {
|
||||||
.param_changed = on_stream_param_changed,
|
.param_changed = on_stream_param_changed,
|
||||||
.process = on_process,
|
.process = on_process,
|
||||||
.trigger_done = on_trigger_done,
|
.trigger_done = on_trigger_done,
|
||||||
|
.command = on_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
|
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,6 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
|
||||||
interval.tv_sec = 0;
|
interval.tv_sec = 0;
|
||||||
interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
|
interval.tv_nsec = 40 * SPA_NSEC_PER_MSEC;
|
||||||
|
|
||||||
if (pw_stream_is_driving(data->stream))
|
|
||||||
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
|
pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
|
||||||
data->timer, &timeout, &interval, false);
|
data->timer, &timeout, &interval, false);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue