mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
v0: improve compatibility
Implement RequestClockUpdate event and ClockUpdate message for old clients.
This commit is contained in:
parent
c12f2276c4
commit
293932d4ec
7 changed files with 152 additions and 21 deletions
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <spa/node/node.h>
|
||||
#include <spa/node/utils.h>
|
||||
#include <spa/node/io.h>
|
||||
#include <spa/pod/filter.h>
|
||||
#include <spa/utils/keys.h>
|
||||
|
||||
|
|
@ -65,6 +66,9 @@
|
|||
|
||||
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
|
||||
|
||||
extern uint32_t pw_protocol_native0_type_from_v2(struct pw_impl_client *client, uint32_t type);
|
||||
extern uint32_t pw_protocol_native0_name_to_v2(struct pw_impl_client *client, const char *name);
|
||||
|
||||
struct mem {
|
||||
uint32_t id;
|
||||
int ref;
|
||||
|
|
@ -111,6 +115,8 @@ struct node {
|
|||
struct spa_hook_list hooks;
|
||||
struct spa_callbacks callbacks;
|
||||
|
||||
struct spa_io_position *position;
|
||||
|
||||
struct pw_resource *resource;
|
||||
|
||||
struct spa_source data_source;
|
||||
|
|
@ -310,7 +316,20 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
|
||||
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
struct node *this = object;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(this != NULL, -EINVAL);
|
||||
|
||||
switch(id) {
|
||||
case SPA_IO_Position:
|
||||
this->position = data;
|
||||
break;
|
||||
default:
|
||||
res = -ENOTSUP;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline void do_flush(struct node *this)
|
||||
|
|
@ -320,6 +339,36 @@ static inline void do_flush(struct node *this)
|
|||
|
||||
}
|
||||
|
||||
static int send_clock_update(struct node *this)
|
||||
{
|
||||
struct pw_impl_client *client = this->resource->client;
|
||||
uint32_t type = pw_protocol_native0_name_to_v2(client, SPA_TYPE_INFO_NODE_COMMAND_BASE "ClockUpdate");
|
||||
struct timespec ts;
|
||||
int64_t now;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
now = SPA_TIMESPEC_TO_NSEC(&ts);
|
||||
pw_log_trace(NAME " %p: now %"PRIi64, this, now);
|
||||
|
||||
struct spa_command_node0_clock_update cu =
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_INIT(type,
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_TIME |
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_SCALE |
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_STATE |
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_LATENCY, /* change_mask */
|
||||
SPA_USEC_PER_SEC, /* rate */
|
||||
now / SPA_NSEC_PER_USEC, /* ticks */
|
||||
now, /* monotonic_time */
|
||||
0, /* offset */
|
||||
(1 << 16) | 1, /* scale */
|
||||
SPA_CLOCK0_STATE_RUNNING, /* state */
|
||||
SPA_COMMAND_NODE0_CLOCK_UPDATE_FLAG_LIVE, /* flags */
|
||||
0); /* latency */
|
||||
|
||||
pw_client_node0_resource_command(this->resource, this->seq, (const struct spa_command*)&cu);
|
||||
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
||||
}
|
||||
|
||||
static int impl_node_send_command(void *object, const struct spa_command *command)
|
||||
{
|
||||
struct node *this = object;
|
||||
|
|
@ -330,6 +379,10 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
|
|||
if (this->resource == NULL)
|
||||
return -EIO;
|
||||
|
||||
if (SPA_NODE_COMMAND_ID(command) == SPA_NODE_COMMAND_Start) {
|
||||
send_clock_update(this);
|
||||
}
|
||||
|
||||
pw_client_node0_resource_command(this->resource, this->seq, command);
|
||||
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
||||
}
|
||||
|
|
@ -365,8 +418,6 @@ impl_node_sync(void *object, int seq)
|
|||
return this->init_pending;
|
||||
}
|
||||
|
||||
extern uint32_t pw_protocol_native0_type_from_v2(struct pw_impl_client *client, uint32_t type);
|
||||
extern uint32_t pw_protocol_native0_type_to_v2(struct pw_impl_client *client, uint32_t type);
|
||||
|
||||
extern struct spa_pod *pw_protocol_native0_pod_from_v2(struct pw_impl_client *client, const struct spa_pod *pod);
|
||||
extern int pw_protocol_native0_pod_to_v2(struct pw_impl_client *client, const struct spa_pod *pod,
|
||||
|
|
@ -1015,7 +1066,14 @@ static void client_node0_event(void *data, struct spa_event *event)
|
|||
{
|
||||
struct impl *impl = data;
|
||||
struct node *this = &impl->node;
|
||||
spa_node_emit_event(&this->hooks, event);
|
||||
|
||||
switch (SPA_EVENT_TYPE(event)) {
|
||||
case SPA_NODE0_EVENT_RequestClockUpdate:
|
||||
send_clock_update(this);
|
||||
break;
|
||||
default:
|
||||
spa_node_emit_event(&this->hooks, event);
|
||||
}
|
||||
}
|
||||
|
||||
static struct pw_client_node0_methods client_node0_methods = {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,50 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** The state of the clock */
|
||||
enum spa_clock0_state {
|
||||
SPA_CLOCK0_STATE_STOPPED, /*< the clock is stopped */
|
||||
SPA_CLOCK0_STATE_PAUSED, /*< the clock is paused */
|
||||
SPA_CLOCK0_STATE_RUNNING, /*< the clock is running */
|
||||
};
|
||||
|
||||
struct spa_command_node0_clock_update_body {
|
||||
struct spa_pod_object_body body;
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_TIME (1 << 0)
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_SCALE (1 << 1)
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_STATE (1 << 2)
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_LATENCY (1 << 3)
|
||||
struct spa_pod_int change_mask SPA_ALIGNED(8);
|
||||
struct spa_pod_int rate SPA_ALIGNED(8);
|
||||
struct spa_pod_long ticks SPA_ALIGNED(8);
|
||||
struct spa_pod_long monotonic_time SPA_ALIGNED(8);
|
||||
struct spa_pod_long offset SPA_ALIGNED(8);
|
||||
struct spa_pod_int scale SPA_ALIGNED(8);
|
||||
struct spa_pod_int state SPA_ALIGNED(8);
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_FLAG_LIVE (1 << 0)
|
||||
struct spa_pod_int flags SPA_ALIGNED(8);
|
||||
struct spa_pod_long latency SPA_ALIGNED(8);
|
||||
};
|
||||
|
||||
struct spa_command_node0_clock_update {
|
||||
struct spa_pod pod;
|
||||
struct spa_command_node0_clock_update_body body;
|
||||
};
|
||||
|
||||
#define SPA_COMMAND_NODE0_CLOCK_UPDATE_INIT(type,change_mask,rate,ticks,monotonic_time,offset,scale,state,flags,latency) \
|
||||
SPA_COMMAND_INIT_FULL(struct spa_command_node0_clock_update, \
|
||||
sizeof(struct spa_command_node0_clock_update_body), 0, type, \
|
||||
SPA_POD_INIT_Int(change_mask), \
|
||||
SPA_POD_INIT_Int(rate), \
|
||||
SPA_POD_INIT_Long(ticks), \
|
||||
SPA_POD_INIT_Long(monotonic_time), \
|
||||
SPA_POD_INIT_Long(offset), \
|
||||
SPA_POD_INIT_Int(scale), \
|
||||
SPA_POD_INIT_Int(state), \
|
||||
SPA_POD_INIT_Int(flags), \
|
||||
SPA_POD_INIT_Long(latency))
|
||||
|
||||
|
||||
/** \class pw_impl_client_node0
|
||||
*
|
||||
* PipeWire client node interface
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@
|
|||
extern uint32_t pw_protocol_native0_find_type(struct pw_impl_client *client, const char *type);
|
||||
extern int pw_protocol_native0_pod_to_v2(struct pw_impl_client *client, const struct spa_pod *pod,
|
||||
struct spa_pod_builder *b);
|
||||
extern struct spa_pod * pw_protocol_native0_pod_from_v2(struct pw_impl_client *client,
|
||||
const struct spa_pod *pod);
|
||||
extern uint32_t pw_protocol_native0_type_to_v2(struct pw_impl_client *client,
|
||||
const struct spa_type_info *info, uint32_t type);
|
||||
|
||||
|
|
@ -137,7 +139,10 @@ client_node_marshal_command(void *object, uint32_t seq, const struct spa_command
|
|||
|
||||
spa_pod_builder_push_struct(b, &f);
|
||||
spa_pod_builder_add(b, "i", seq, NULL);
|
||||
pw_protocol_native0_pod_to_v2(client, (struct spa_pod *)command, b);
|
||||
if (SPA_COMMAND_TYPE(command) == 0)
|
||||
spa_pod_builder_add(b, "P", command, NULL);
|
||||
else
|
||||
pw_protocol_native0_pod_to_v2(client, (struct spa_pod *)command, b);
|
||||
spa_pod_builder_pop(b, &f);
|
||||
|
||||
pw_protocol_native_end_resource(resource, b);
|
||||
|
|
@ -440,15 +445,22 @@ static int client_node_demarshal_set_active(void *object, const struct pw_protoc
|
|||
static int client_node_demarshal_event_method(void *object, const struct pw_protocol_native_message *msg)
|
||||
{
|
||||
struct pw_resource *resource = object;
|
||||
struct pw_impl_client *client = pw_resource_get_client(resource);
|
||||
struct spa_pod_parser prs;
|
||||
struct spa_event *event;
|
||||
int res;
|
||||
|
||||
spa_pod_parser_init(&prs, msg->data, msg->size);
|
||||
if (spa_pod_parser_get_struct(&prs,
|
||||
"O", &event) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
return pw_resource_notify(resource, struct pw_client_node0_methods, event, 0, event);
|
||||
event = (struct spa_event*)pw_protocol_native0_pod_from_v2(client, (struct spa_pod *)event);
|
||||
|
||||
res = pw_resource_notify(resource, struct pw_client_node0_methods, event, 0, event);
|
||||
free(event);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int client_node_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue