mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-22 06:59:59 -05:00
command: make commands dynamic
Ensure format object type.
This commit is contained in:
parent
4d9f2c5161
commit
c44a7c9735
36 changed files with 549 additions and 604 deletions
|
|
@ -211,10 +211,10 @@ typedef struct {
|
|||
PinosClientNodeBuffer *buffers);
|
||||
void (*node_command) (void *object,
|
||||
uint32_t seq,
|
||||
const SpaNodeCommand *command);
|
||||
const SpaCommand *command);
|
||||
void (*port_command) (void *object,
|
||||
uint32_t port_id,
|
||||
const SpaNodeCommand *command);
|
||||
const SpaCommand *command);
|
||||
void (*transport) (void *object,
|
||||
int memfd,
|
||||
uint32_t offset,
|
||||
|
|
|
|||
|
|
@ -836,7 +836,7 @@ client_node_demarshal_node_command (void *object,
|
|||
{
|
||||
PinosProxy *proxy = object;
|
||||
SpaPODIter it;
|
||||
const SpaNodeCommand *command;
|
||||
const SpaCommand *command;
|
||||
uint32_t seq;
|
||||
|
||||
if (!spa_pod_iter_struct (&it, data, size) ||
|
||||
|
|
@ -857,7 +857,7 @@ client_node_demarshal_port_command (void *object,
|
|||
{
|
||||
PinosProxy *proxy = object;
|
||||
SpaPODIter it;
|
||||
const SpaNodeCommand *command;
|
||||
const SpaCommand *command;
|
||||
uint32_t port_id;
|
||||
|
||||
if (!spa_pod_iter_struct (&it, data, size) ||
|
||||
|
|
|
|||
|
|
@ -573,58 +573,45 @@ handle_node_event (PinosStream *stream,
|
|||
}
|
||||
|
||||
static bool
|
||||
handle_node_command (PinosStream *stream,
|
||||
uint32_t seq,
|
||||
const SpaNodeCommand *command)
|
||||
handle_node_command (PinosStream *stream,
|
||||
uint32_t seq,
|
||||
const SpaCommand *command)
|
||||
{
|
||||
PinosStreamImpl *impl = SPA_CONTAINER_OF (stream, PinosStreamImpl, this);
|
||||
PinosContext *context = stream->context;
|
||||
|
||||
switch (SPA_NODE_COMMAND_TYPE (command)) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
break;
|
||||
case SPA_NODE_COMMAND_PAUSE:
|
||||
{
|
||||
pinos_log_debug ("stream %p: pause %d", stream, seq);
|
||||
if (SPA_COMMAND_TYPE (command) == context->uri.node_commands.Pause) {
|
||||
pinos_log_debug ("stream %p: pause %d", stream, seq);
|
||||
|
||||
add_state_change (stream, SPA_NODE_STATE_PAUSED, false);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_COMMAND_START:
|
||||
{
|
||||
pinos_log_debug ("stream %p: start %d", stream, seq);
|
||||
add_state_change (stream, SPA_NODE_STATE_STREAMING, false);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
||||
add_state_change (stream, SPA_NODE_STATE_PAUSED, false);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_PAUSED, NULL);
|
||||
}
|
||||
else if (SPA_COMMAND_TYPE (command) == context->uri.node_commands.Start) {
|
||||
pinos_log_debug ("stream %p: start %d", stream, seq);
|
||||
add_state_change (stream, SPA_NODE_STATE_STREAMING, false);
|
||||
add_async_complete (stream, seq, SPA_RESULT_OK, true);
|
||||
|
||||
if (impl->direction == SPA_DIRECTION_INPUT)
|
||||
send_need_input (stream);
|
||||
if (impl->direction == SPA_DIRECTION_INPUT)
|
||||
send_need_input (stream);
|
||||
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_COMMAND_FLUSH:
|
||||
case SPA_NODE_COMMAND_DRAIN:
|
||||
case SPA_NODE_COMMAND_MARKER:
|
||||
{
|
||||
pinos_log_warn ("unhandled node command %d", SPA_NODE_COMMAND_TYPE (command));
|
||||
add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED, true);
|
||||
break;
|
||||
}
|
||||
case SPA_NODE_COMMAND_CLOCK_UPDATE:
|
||||
{
|
||||
SpaNodeCommandClockUpdate *cu = (SpaNodeCommandClockUpdate *) command;
|
||||
if (cu->body.flags.value & SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE) {
|
||||
pinos_properties_set (stream->properties,
|
||||
"pinos.latency.is-live", "1");
|
||||
pinos_properties_setf (stream->properties,
|
||||
"pinos.latency.min", "%"PRId64, cu->body.latency.value);
|
||||
}
|
||||
impl->last_ticks = cu->body.ticks.value;
|
||||
impl->last_rate = cu->body.rate.value;
|
||||
impl->last_monotonic = cu->body.monotonic_time.value;
|
||||
break;
|
||||
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING, NULL);
|
||||
}
|
||||
else if (SPA_COMMAND_TYPE (command) == context->uri.node_commands.ClockUpdate) {
|
||||
SpaNodeCommandClockUpdate *cu = (SpaNodeCommandClockUpdate *) command;
|
||||
if (cu->body.flags.value & SPA_NODE_COMMAND_CLOCK_UPDATE_FLAG_LIVE) {
|
||||
pinos_properties_set (stream->properties,
|
||||
"pinos.latency.is-live", "1");
|
||||
pinos_properties_setf (stream->properties,
|
||||
"pinos.latency.min", "%"PRId64, cu->body.latency.value);
|
||||
}
|
||||
impl->last_ticks = cu->body.ticks.value;
|
||||
impl->last_rate = cu->body.rate.value;
|
||||
impl->last_monotonic = cu->body.monotonic_time.value;
|
||||
}
|
||||
else {
|
||||
pinos_log_warn ("unhandled node command %d", SPA_COMMAND_TYPE (command));
|
||||
add_async_complete (stream, seq, SPA_RESULT_NOT_IMPLEMENTED, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -853,9 +840,9 @@ client_node_use_buffers (void *object,
|
|||
}
|
||||
|
||||
static void
|
||||
client_node_node_command (void *object,
|
||||
uint32_t seq,
|
||||
const SpaNodeCommand *command)
|
||||
client_node_node_command (void *object,
|
||||
uint32_t seq,
|
||||
const SpaCommand *command)
|
||||
{
|
||||
PinosProxy *proxy = object;
|
||||
PinosStream *stream = proxy->user_data;
|
||||
|
|
@ -863,9 +850,9 @@ client_node_node_command (void *object,
|
|||
}
|
||||
|
||||
static void
|
||||
client_node_port_command (void *object,
|
||||
uint32_t port_id,
|
||||
const SpaNodeCommand *command)
|
||||
client_node_port_command (void *object,
|
||||
uint32_t port_id,
|
||||
const SpaCommand *command)
|
||||
{
|
||||
pinos_log_warn ("port command not supported");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,5 @@ pinos_uri_init (PinosURI *uri)
|
|||
uri->spa_monitor = spa_id_map_get_id (uri->map, SPA_MONITOR_URI);
|
||||
|
||||
spa_node_events_map (uri->map, &uri->node_events);
|
||||
spa_node_commands_map (uri->map, &uri->node_commands);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ struct _PinosURI {
|
|||
uint32_t spa_monitor;
|
||||
|
||||
SpaNodeEvents node_events;
|
||||
SpaNodeCommands node_commands;
|
||||
};
|
||||
|
||||
void pinos_uri_init (PinosURI *uri);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ typedef struct {
|
|||
uint32_t *media_subtype;
|
||||
} MediaType;
|
||||
|
||||
static uint32_t format_type;
|
||||
static SpaMediaTypes media_types = { 0, };
|
||||
static SpaMediaSubtypes media_subtypes = { 0, };
|
||||
static SpaMediaSubtypesVideo media_subtypes_video = { 0, };
|
||||
|
|
@ -49,14 +50,17 @@ static SpaAudioFormats audio_formats = { 0, };
|
|||
static void
|
||||
ensure_types (void)
|
||||
{
|
||||
spa_media_types_fill (&media_types, spa_id_map_get_default ());
|
||||
spa_media_subtypes_map (spa_id_map_get_default (), &media_subtypes);
|
||||
spa_media_subtypes_video_map (spa_id_map_get_default (), &media_subtypes_video);
|
||||
spa_media_subtypes_audio_map (spa_id_map_get_default (), &media_subtypes_audio);
|
||||
spa_prop_video_map (spa_id_map_get_default (), &prop_video);
|
||||
spa_prop_audio_map (spa_id_map_get_default (), &prop_audio);
|
||||
spa_video_formats_map (spa_id_map_get_default (), &video_formats);
|
||||
spa_audio_formats_map (spa_id_map_get_default (), &audio_formats);
|
||||
SpaIDMap *map = spa_id_map_get_default ();
|
||||
|
||||
format_type = spa_id_map_get_id (map, SPA_FORMAT_URI);
|
||||
spa_media_types_fill (&media_types, map);
|
||||
spa_media_subtypes_map (map, &media_subtypes);
|
||||
spa_media_subtypes_video_map (map, &media_subtypes_video);
|
||||
spa_media_subtypes_audio_map (map, &media_subtypes_audio);
|
||||
spa_prop_video_map (map, &prop_video);
|
||||
spa_prop_audio_map (map, &prop_audio);
|
||||
spa_video_formats_map (map, &video_formats);
|
||||
spa_audio_formats_map (map, &audio_formats);
|
||||
}
|
||||
|
||||
static const MediaType media_type_map[] = {
|
||||
|
|
@ -516,7 +520,7 @@ convert_1 (GstCapsFeatures *cf, GstStructure *cs)
|
|||
|
||||
d.b.write = write_pod;
|
||||
|
||||
spa_pod_builder_push_format (&d.b, &f,
|
||||
spa_pod_builder_push_format (&d.b, &f, format_type,
|
||||
*d.type->media_type,
|
||||
*d.type->media_subtype);
|
||||
|
||||
|
|
|
|||
|
|
@ -185,11 +185,12 @@ send_have_output (SpaProxy *this)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_send_command (SpaNode *node,
|
||||
SpaNodeCommand *command)
|
||||
spa_proxy_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
PinosCore *core;
|
||||
|
||||
if (node == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -199,30 +200,22 @@ spa_proxy_node_send_command (SpaNode *node,
|
|||
if (this->resource == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
switch (SPA_NODE_COMMAND_TYPE (command)) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
core = this->pnode->core;
|
||||
|
||||
case SPA_NODE_COMMAND_START:
|
||||
case SPA_NODE_COMMAND_PAUSE:
|
||||
case SPA_NODE_COMMAND_FLUSH:
|
||||
case SPA_NODE_COMMAND_DRAIN:
|
||||
case SPA_NODE_COMMAND_MARKER:
|
||||
/* send start */
|
||||
pinos_client_node_notify_node_command (this->resource,
|
||||
this->seq,
|
||||
command);
|
||||
if (SPA_NODE_COMMAND_TYPE (command) == SPA_NODE_COMMAND_START)
|
||||
send_need_input (this);
|
||||
if (SPA_COMMAND_TYPE (command) == core->uri.node_commands.ClockUpdate) {
|
||||
pinos_client_node_notify_node_command (this->resource,
|
||||
this->seq++,
|
||||
command);
|
||||
}
|
||||
else {
|
||||
/* send start */
|
||||
pinos_client_node_notify_node_command (this->resource,
|
||||
this->seq,
|
||||
command);
|
||||
if (SPA_COMMAND_TYPE (command) == core->uri.node_commands.Start)
|
||||
send_need_input (this);
|
||||
|
||||
res = SPA_RESULT_RETURN_ASYNC (this->seq++);
|
||||
break;
|
||||
|
||||
case SPA_NODE_COMMAND_CLOCK_UPDATE:
|
||||
pinos_client_node_notify_node_command (this->resource,
|
||||
this->seq++,
|
||||
command);
|
||||
break;
|
||||
res = SPA_RESULT_RETURN_ASYNC (this->seq++);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -790,33 +783,17 @@ static SpaResult
|
|||
spa_proxy_node_port_send_command (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
SpaNodeCommand *command)
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
|
||||
if (node == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaProxy, node);
|
||||
|
||||
switch (SPA_NODE_COMMAND_TYPE (command)) {
|
||||
case SPA_NODE_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
||||
case SPA_NODE_COMMAND_START:
|
||||
case SPA_NODE_COMMAND_PAUSE:
|
||||
case SPA_NODE_COMMAND_FLUSH:
|
||||
case SPA_NODE_COMMAND_DRAIN:
|
||||
case SPA_NODE_COMMAND_MARKER:
|
||||
break;
|
||||
|
||||
default:
|
||||
spa_log_warn (this->log, "unhandled command %d", SPA_NODE_COMMAND_TYPE (command));
|
||||
res = SPA_RESULT_NOT_IMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
spa_log_warn (this->log, "unhandled command %d", SPA_COMMAND_TYPE (command));
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "spa/include/spa/node-command.h"
|
||||
|
||||
#include "pinos/client/pinos.h"
|
||||
#include "pinos/client/interfaces.h"
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ pause_node (PinosNode *this)
|
|||
|
||||
pinos_log_debug ("node %p: pause node", this);
|
||||
{
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_PAUSE);
|
||||
SpaCommand cmd = SPA_COMMAND_INIT (this->core->uri.node_commands.Pause);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
|
|
@ -181,7 +183,7 @@ start_node (PinosNode *this)
|
|||
|
||||
pinos_log_debug ("node %p: start node", this);
|
||||
{
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_START);
|
||||
SpaCommand cmd = SPA_COMMAND_INIT (this->core->uri.node_commands.Start);
|
||||
if ((res = spa_node_send_command (this->node, &cmd)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
|
|
@ -224,6 +226,7 @@ send_clock_update (PinosNode *this)
|
|||
SpaResult res;
|
||||
SpaNodeCommandClockUpdate cu =
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_INIT(
|
||||
this->core->uri.node_commands.ClockUpdate,
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_TIME |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_SCALE |
|
||||
SPA_NODE_COMMAND_CLOCK_UPDATE_STATE |
|
||||
|
|
@ -245,7 +248,7 @@ send_clock_update (PinosNode *this)
|
|||
&cu.body.monotonic_time.value);
|
||||
}
|
||||
|
||||
if ((res = spa_node_send_command (this->node, (SpaNodeCommand *)&cu)) < 0)
|
||||
if ((res = spa_node_send_command (this->node, (SpaCommand *)&cu)) < 0)
|
||||
pinos_log_debug ("got error %d", res);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
|
||||
typedef struct _PinosNode PinosNode;
|
||||
|
||||
#include <spa/include/spa/clock.h>
|
||||
#include <spa/include/spa/node.h>
|
||||
|
||||
#include <pinos/client/mem.h>
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ no_mem:
|
|||
static SpaResult
|
||||
pinos_port_pause (PinosPort *port)
|
||||
{
|
||||
SpaNodeCommand cmd = SPA_NODE_COMMAND_INIT (SPA_NODE_COMMAND_PAUSE);
|
||||
SpaCommand cmd = SPA_COMMAND_INIT (port->node->core->uri.node_commands.Pause);
|
||||
return spa_node_port_send_command (port->node->node,
|
||||
port->direction,
|
||||
port->port_id,
|
||||
|
|
|
|||
|
|
@ -742,9 +742,9 @@ client_node_marshal_use_buffers (void *object,
|
|||
}
|
||||
|
||||
static void
|
||||
client_node_marshal_node_command (void *object,
|
||||
uint32_t seq,
|
||||
const SpaNodeCommand *command)
|
||||
client_node_marshal_node_command (void *object,
|
||||
uint32_t seq,
|
||||
const SpaCommand *command)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosConnection *connection = resource->client->protocol_private;
|
||||
|
|
@ -761,9 +761,9 @@ client_node_marshal_node_command (void *object,
|
|||
}
|
||||
|
||||
static void
|
||||
client_node_marshal_port_command (void *object,
|
||||
uint32_t port_id,
|
||||
const SpaNodeCommand *command)
|
||||
client_node_marshal_port_command (void *object,
|
||||
uint32_t port_id,
|
||||
const SpaCommand *command)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosConnection *connection = resource->client->protocol_private;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue