mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Work on memory allocation
We now only allow per port preallocated buffers. We exchange the index into the array instead of passing the buffers around. We still use the refcount to track when a buffer can be reused. Improve API a little, allow passing the node as the first argument of the interface call. Implement alloc_buffer in v4l2 and improve the test.
This commit is contained in:
parent
7cfd1eb8ee
commit
05829f33e6
29 changed files with 2266 additions and 800 deletions
|
|
@ -73,6 +73,7 @@ struct _ALSABuffer {
|
|||
|
||||
struct _SpaALSASink {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaALSASinkProps props[2];
|
||||
|
||||
|
|
@ -172,14 +173,16 @@ static const SpaPropInfo prop_info[] =
|
|||
};
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_get_props (SpaHandle *handle,
|
||||
spa_alsa_sink_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -187,16 +190,19 @@ spa_alsa_sink_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_set_props (SpaHandle *handle,
|
||||
spa_alsa_sink_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASinkProps *p = &this->props[1];
|
||||
SpaALSASink *this;
|
||||
SpaALSASinkProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_alsa_sink_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -208,14 +214,16 @@ spa_alsa_sink_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_send_command (SpaHandle *handle,
|
||||
spa_alsa_sink_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -233,7 +241,7 @@ spa_alsa_sink_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_STOP:
|
||||
|
|
@ -249,7 +257,7 @@ spa_alsa_sink_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_FLUSH:
|
||||
|
|
@ -261,15 +269,17 @@ spa_alsa_sink_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_set_event_callback (SpaHandle *handle,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
spa_alsa_sink_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -277,13 +287,13 @@ spa_alsa_sink_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_get_n_ports (SpaHandle *handle,
|
||||
spa_alsa_sink_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -299,13 +309,13 @@ spa_alsa_sink_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_get_port_ids (SpaHandle *handle,
|
||||
spa_alsa_sink_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports > 0)
|
||||
|
|
@ -316,33 +326,35 @@ spa_alsa_sink_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_add_port (SpaHandle *handle,
|
||||
spa_alsa_sink_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_remove_port (SpaHandle *handle,
|
||||
spa_alsa_sink_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -365,17 +377,19 @@ spa_alsa_sink_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_set_format (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -393,15 +407,17 @@ spa_alsa_sink_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_get_format (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -414,15 +430,17 @@ spa_alsa_sink_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_get_info (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -432,7 +450,7 @@ spa_alsa_sink_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_get_props (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -440,7 +458,7 @@ spa_alsa_sink_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_set_props (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -448,15 +466,17 @@ spa_alsa_sink_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_get_status (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -466,7 +486,7 @@ spa_alsa_sink_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
|
|
@ -475,7 +495,7 @@ spa_alsa_sink_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -485,26 +505,38 @@ spa_alsa_sink_node_port_alloc_buffers (SpaHandle *handle,
|
|||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaBuffer *
|
||||
find_buffer (SpaALSASink *this, uint32_t id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_push_input (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
SpaALSASink *this = (SpaALSASink *) handle;
|
||||
SpaALSASink *this;
|
||||
unsigned int i;
|
||||
bool have_error = false, have_enough = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
SpaBuffer *buffer;
|
||||
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info[i].buffer != NULL) {
|
||||
buffer = find_buffer (this, info[i].id);
|
||||
|
||||
if (buffer != NULL) {
|
||||
if (!this->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
|
|
@ -516,7 +548,7 @@ spa_alsa_sink_node_port_push_input (SpaHandle *handle,
|
|||
have_enough = true;
|
||||
continue;
|
||||
}
|
||||
this->input_buffer = spa_buffer_ref (info[i].buffer);
|
||||
this->input_buffer = spa_buffer_ref (buffer);
|
||||
}
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -529,7 +561,7 @@ spa_alsa_sink_node_port_push_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_pull_output (SpaHandle *handle,
|
||||
spa_alsa_sink_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
|
|
@ -537,6 +569,7 @@ spa_alsa_sink_node_port_pull_output (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static const SpaNode alsasink_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_alsa_sink_node_get_props,
|
||||
spa_alsa_sink_node_set_props,
|
||||
|
|
@ -562,14 +595,18 @@ static const SpaNode alsasink_node = {
|
|||
static SpaResult
|
||||
spa_alsa_sink_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
void **interface)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaALSASink *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &alsasink_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -589,6 +626,8 @@ alsa_sink_init (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_alsa_sink_get_interface;
|
||||
|
||||
this = (SpaALSASink *) handle;
|
||||
this->node = alsasink_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ pull_input (SpaALSASink *this, void *data, snd_pcm_uframes_t frames)
|
|||
buffer->data[0].ptr_type = "sysmem";
|
||||
buffer->data[0].size = frames * sizeof (uint16_t) * 2;
|
||||
|
||||
this->event_cb (&this->handle, &event,this->user_data);
|
||||
this->event_cb (&this->node, &event,this->user_data);
|
||||
|
||||
spa_buffer_unref ((SpaBuffer *)event.data);
|
||||
}
|
||||
|
|
@ -378,7 +378,7 @@ spa_alsa_start (SpaALSASink *this)
|
|||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = alsa_on_fd_events;
|
||||
state->poll.user_data = this;
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
|
||||
mmap_write (this);
|
||||
err = snd_pcm_start (state->handle);
|
||||
|
|
@ -400,7 +400,7 @@ spa_alsa_stop (SpaALSASink *this)
|
|||
event.port_id = 0;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
|
||||
spa_alsa_close (this);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,28 +47,30 @@ struct _MixerBuffer {
|
|||
|
||||
typedef struct {
|
||||
bool valid;
|
||||
bool have_format;
|
||||
SpaAudioRawFormat format[2];
|
||||
SpaAudioMixerPortProps props[2];
|
||||
SpaPortInfo info;
|
||||
SpaPortStatus status;
|
||||
SpaBuffer *buffer;
|
||||
size_t buffer_index;
|
||||
size_t buffer_offset;
|
||||
size_t buffer_queued;
|
||||
MixerBuffer mix;
|
||||
|
||||
SpaBuffer **buffers;
|
||||
unsigned int n_buffers;
|
||||
SpaBuffer *buffer;
|
||||
} SpaAudioMixerPort;
|
||||
|
||||
struct _SpaAudioMixer {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaAudioMixerProps props[2];
|
||||
|
||||
SpaEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
bool have_format;
|
||||
SpaAudioRawFormat query_format;
|
||||
SpaAudioRawFormat current_format;
|
||||
|
||||
int port_count;
|
||||
int port_queued;
|
||||
SpaAudioMixerPort ports[MAX_PORTS];
|
||||
|
|
@ -89,14 +91,16 @@ reset_audiomixer_props (SpaAudioMixerProps *props)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_get_props (SpaHandle *handle,
|
||||
spa_audiomixer_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -104,16 +108,19 @@ spa_audiomixer_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_set_props (SpaHandle *handle,
|
||||
spa_audiomixer_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixerProps *p = &this->props[1];
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_audiomixer_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -124,14 +131,16 @@ spa_audiomixer_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_send_command (SpaHandle *handle,
|
||||
spa_audiomixer_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -147,7 +156,7 @@ spa_audiomixer_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -162,7 +171,7 @@ spa_audiomixer_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -175,15 +184,17 @@ spa_audiomixer_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_set_event_callback (SpaHandle *handle,
|
||||
spa_audiomixer_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -191,13 +202,13 @@ spa_audiomixer_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_get_n_ports (SpaHandle *handle,
|
||||
spa_audiomixer_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -213,18 +224,20 @@ spa_audiomixer_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_get_port_ids (SpaHandle *handle,
|
||||
spa_audiomixer_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
int i, idx;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (input_ids) {
|
||||
for (i = 1, idx = 0; i < MAX_PORTS && idx < n_input_ports; i++) {
|
||||
if (this->ports[i].valid)
|
||||
|
|
@ -238,34 +251,34 @@ spa_audiomixer_node_get_port_ids (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_add_port (SpaHandle *handle,
|
||||
spa_audiomixer_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
int i;
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL || port_id == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (direction != SPA_DIRECTION_INPUT)
|
||||
return SPA_RESULT_INVALID_DIRECTION;
|
||||
|
||||
for (i = 1; i < MAX_PORTS; i++)
|
||||
if (!this->ports[i].valid)
|
||||
break;
|
||||
if (i == MAX_PORTS)
|
||||
return SPA_RESULT_TOO_MANY_PORTS;
|
||||
if (port_id >= MAX_PORTS)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
this->ports[i].valid = true;
|
||||
*port_id = i;
|
||||
if (this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
this->ports[port_id].valid = true;
|
||||
this->port_count++;
|
||||
|
||||
this->ports[i].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER |
|
||||
SPA_PORT_INFO_FLAG_REMOVABLE |
|
||||
SPA_PORT_INFO_FLAG_OPTIONAL |
|
||||
SPA_PORT_INFO_FLAG_IN_PLACE;
|
||||
this->ports[i].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
this->ports[port_id].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER |
|
||||
SPA_PORT_INFO_FLAG_REMOVABLE |
|
||||
SPA_PORT_INFO_FLAG_OPTIONAL |
|
||||
SPA_PORT_INFO_FLAG_IN_PLACE;
|
||||
this->ports[port_id].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
|
||||
this->ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
|
||||
|
|
@ -273,14 +286,16 @@ spa_audiomixer_node_add_port (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_remove_port (SpaHandle *handle,
|
||||
spa_audiomixer_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id == 0 || port_id >= MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -299,105 +314,124 @@ spa_audiomixer_node_remove_port (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (port_id > MAX_PORTS)
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id > MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
spa_audio_raw_format_init (&this->query_format);
|
||||
spa_audio_raw_format_init (&port->format[0]);
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*format = &this->query_format.format;
|
||||
*format = &port->format[0].format;
|
||||
*(int*)state = ++index;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_set_format (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (port_id > MAX_PORTS)
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id > MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (format == NULL) {
|
||||
this->have_format = false;
|
||||
port->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
if ((res = spa_audio_raw_format_parse (format, &this->current_format)) < 0)
|
||||
if ((res = spa_audio_raw_format_parse (format, &port->format[1])) < 0)
|
||||
return res;
|
||||
|
||||
this->have_format = true;
|
||||
port->have_format = true;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_get_format (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id >= MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_format)
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = &this->current_format.format;
|
||||
*format = &port->format[1].format;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_get_info (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id >= MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*info = &this->ports[port_id].info;
|
||||
port = &this->ports[port_id];
|
||||
*info = &port->info;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_get_props (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -405,7 +439,7 @@ spa_audiomixer_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_set_props (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -413,28 +447,32 @@ spa_audiomixer_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_get_status (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (port_id >= MAX_PORTS || !this->ports[port_id].valid)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_format)
|
||||
port = &this->ports[port_id];
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*status = &this->ports[port_id].status;
|
||||
*status = &port->status;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
|
|
@ -443,7 +481,7 @@ spa_audiomixer_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -454,23 +492,25 @@ spa_audiomixer_node_port_alloc_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_push_input (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaBuffer *buffer;
|
||||
SpaEvent *event;
|
||||
SpaAudioMixer *this;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (this->ports[0].status.flags & SPA_PORT_STATUS_FLAG_HAVE_OUTPUT)
|
||||
return SPA_RESULT_HAVE_ENOUGH_INPUT;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
SpaBuffer *buffer;
|
||||
SpaAudioMixerPort *port;
|
||||
int idx = info[i].port_id;
|
||||
|
||||
if (idx >= MAX_PORTS || !this->ports[idx].valid) {
|
||||
|
|
@ -478,18 +518,17 @@ spa_audiomixer_node_port_push_input (SpaHandle *handle,
|
|||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
port = &this->ports[idx];
|
||||
buffer = port->buffers[info[i].id];
|
||||
|
||||
event = info[i].event;
|
||||
buffer = info[i].buffer;
|
||||
|
||||
if (buffer == NULL && event == NULL) {
|
||||
if (buffer == NULL) {
|
||||
info[i].status = SPA_RESULT_INVALID_ARGUMENTS;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
if (!this->have_format) {
|
||||
if (!port->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
|
|
@ -509,11 +548,6 @@ spa_audiomixer_node_port_push_input (SpaHandle *handle,
|
|||
if (this->port_queued == this->port_count)
|
||||
this->ports[0].status.flags |= SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
}
|
||||
if (event) {
|
||||
info[i].status = SPA_RESULT_NOT_IMPLEMENTED;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
|
|
@ -557,7 +591,7 @@ pull_port (SpaAudioMixer *this, uint32_t port_id, SpaOutputInfo *info, size_t pu
|
|||
buffer->data[0].ptr_type = "sysmem";
|
||||
buffer->data[0].size = pull_size;
|
||||
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -613,15 +647,12 @@ static SpaResult
|
|||
mix_data (SpaAudioMixer *this, SpaOutputInfo *info)
|
||||
{
|
||||
int i, min_size, min_port, pull_size;
|
||||
SpaBuffer *buf;
|
||||
|
||||
if (info->port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (info->buffer) {
|
||||
pull_size = info->buffer->size;
|
||||
} else {
|
||||
pull_size = 0;
|
||||
}
|
||||
pull_size = info->size;
|
||||
|
||||
min_size = 0;
|
||||
min_port = 0;
|
||||
|
|
@ -645,43 +676,42 @@ mix_data (SpaAudioMixer *this, SpaOutputInfo *info)
|
|||
if (min_port == 0)
|
||||
return SPA_RESULT_NEED_MORE_INPUT;
|
||||
|
||||
if (info->buffer) {
|
||||
if (info->buffer->size < min_size)
|
||||
min_size = info->buffer->size;
|
||||
else
|
||||
info->buffer->size = min_size;
|
||||
} else {
|
||||
info->buffer = this->ports[min_port].buffer;
|
||||
this->ports[min_port].buffer = NULL;
|
||||
this->ports[min_port].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
this->ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
}
|
||||
buf = this->ports[min_port].buffer;
|
||||
info->id = buf->id;
|
||||
this->ports[min_port].buffer = NULL;
|
||||
this->ports[min_port].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
this->ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
|
||||
for (i = 1; i < MAX_PORTS; i++) {
|
||||
if (!this->ports[i].valid || this->ports[i].buffer == NULL)
|
||||
continue;
|
||||
|
||||
add_port_data (this, info->buffer, &this->ports[i]);
|
||||
add_port_data (this, buf, &this->ports[i]);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_pull_output (SpaHandle *handle,
|
||||
spa_audiomixer_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaAudioMixer *this = (SpaAudioMixer *) handle;
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) node->handle;
|
||||
|
||||
if (info->port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_format)
|
||||
port = &this->ports[info->port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
// if (!(this->ports[0].status.flags & SPA_PORT_STATUS_FLAG_HAVE_OUTPUT))
|
||||
|
|
@ -700,7 +730,16 @@ spa_audiomixer_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static const SpaNode audiomixer_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_audiomixer_node_get_props,
|
||||
spa_audiomixer_node_set_props,
|
||||
|
|
@ -721,19 +760,24 @@ static const SpaNode audiomixer_node = {
|
|||
spa_audiomixer_node_port_get_status,
|
||||
spa_audiomixer_node_port_push_input,
|
||||
spa_audiomixer_node_port_pull_output,
|
||||
spa_audiomixer_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_audiomixer_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
void **interface)
|
||||
{
|
||||
SpaAudioMixer *this;
|
||||
|
||||
if (handle == NULL || interface == 0)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioMixer *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &audiomixer_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -753,6 +797,8 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_audiomixer_get_interface;
|
||||
|
||||
this = (SpaAudioMixer *) handle;
|
||||
this->node = audiomixer_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ typedef struct {
|
|||
|
||||
struct _SpaAudioTestSrc {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaAudioTestSrcProps props[2];
|
||||
|
||||
|
|
@ -121,14 +122,16 @@ reset_audiotestsrc_props (SpaAudioTestSrcProps *props)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_get_props (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -136,16 +139,19 @@ spa_audiotestsrc_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_set_props (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrcProps *p = &this->props[1];
|
||||
SpaAudioTestSrc *this;
|
||||
SpaAudioTestSrcProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_audiotestsrc_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -156,14 +162,16 @@ spa_audiotestsrc_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_send_command (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -179,7 +187,7 @@ spa_audiotestsrc_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -194,7 +202,7 @@ spa_audiotestsrc_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -207,15 +215,17 @@ spa_audiotestsrc_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_set_event_callback (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -223,13 +233,13 @@ spa_audiotestsrc_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_get_n_ports (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -245,13 +255,13 @@ spa_audiotestsrc_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_get_port_ids (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL || input_ids == NULL || output_ids == NULL)
|
||||
if (node == NULL || node->handle == NULL || input_ids == NULL || output_ids == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_output_ports > 0)
|
||||
|
|
@ -261,33 +271,35 @@ spa_audiotestsrc_node_get_port_ids (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_add_port (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_remove_port (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -307,17 +319,19 @@ spa_audiotestsrc_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_set_format (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -335,15 +349,17 @@ spa_audiotestsrc_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_get_format (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -356,15 +372,17 @@ spa_audiotestsrc_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_get_info (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -374,7 +392,7 @@ spa_audiotestsrc_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_get_props (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -382,7 +400,7 @@ spa_audiotestsrc_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_set_props (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -390,15 +408,17 @@ spa_audiotestsrc_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_get_status (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -411,7 +431,7 @@ spa_audiotestsrc_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
|
|
@ -420,7 +440,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -432,7 +452,7 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_push_input (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
|
|
@ -440,19 +460,21 @@ spa_audiotestsrc_node_port_push_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_pull_output (SpaHandle *handle,
|
||||
spa_audiotestsrc_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle;
|
||||
SpaAudioTestSrc *this;
|
||||
size_t j, size;
|
||||
uint8_t *ptr;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
|
|
@ -466,14 +488,7 @@ spa_audiotestsrc_node_port_pull_output (SpaHandle *handle,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (info[i].buffer == NULL || info[i].buffer->n_datas == 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_ARGUMENTS;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr = info[i].buffer->datas[0].ptr;
|
||||
size = info[i].buffer->datas[0].size;
|
||||
size = info[i].size;
|
||||
|
||||
for (j = 0; j < size; j++)
|
||||
ptr[j] = rand();
|
||||
|
|
@ -486,7 +501,16 @@ spa_audiotestsrc_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static const SpaNode audiotestsrc_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_audiotestsrc_node_get_props,
|
||||
spa_audiotestsrc_node_set_props,
|
||||
|
|
@ -507,19 +531,24 @@ static const SpaNode audiotestsrc_node = {
|
|||
spa_audiotestsrc_node_port_get_status,
|
||||
spa_audiotestsrc_node_port_push_input,
|
||||
spa_audiotestsrc_node_port_pull_output,
|
||||
spa_audiotestsrc_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_audiotestsrc_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
spa_audiotestsrc_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
void **interface)
|
||||
{
|
||||
SpaAudioTestSrc *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaAudioTestSrc *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &audiotestsrc_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -539,6 +568,8 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_audiotestsrc_get_interface;
|
||||
|
||||
this = (SpaAudioTestSrc *) handle;
|
||||
this->node = audiotestsrc_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ typedef struct {
|
|||
|
||||
struct _SpaFFMpegDec {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaFFMpegDecProps props[2];
|
||||
|
||||
|
|
@ -86,14 +87,16 @@ static const SpaPropInfo prop_info[] =
|
|||
};
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_get_props (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -101,16 +104,19 @@ spa_ffmpeg_dec_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_set_props (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDecProps *p = &this->props[1];
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegDecProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_ffmpeg_dec_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -122,14 +128,16 @@ spa_ffmpeg_dec_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_send_command (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -145,7 +153,7 @@ spa_ffmpeg_dec_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_STOP:
|
||||
|
|
@ -159,7 +167,7 @@ spa_ffmpeg_dec_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -172,15 +180,17 @@ spa_ffmpeg_dec_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_set_event_callback (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -188,13 +198,13 @@ spa_ffmpeg_dec_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_get_n_ports (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -210,13 +220,13 @@ spa_ffmpeg_dec_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_get_port_ids (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports > 0)
|
||||
|
|
@ -229,34 +239,36 @@ spa_ffmpeg_dec_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_add_port (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_remove_port (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegState *s;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -278,20 +290,22 @@ spa_ffmpeg_dec_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_set_format (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegState *state;
|
||||
SpaResult res;
|
||||
SpaFormat *f, *tf;
|
||||
size_t fs;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -324,16 +338,18 @@ spa_ffmpeg_dec_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_get_format (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegState *state;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -348,15 +364,17 @@ spa_ffmpeg_dec_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_get_info (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -366,7 +384,7 @@ spa_ffmpeg_dec_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_get_props (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -374,7 +392,7 @@ spa_ffmpeg_dec_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_set_props (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -382,15 +400,17 @@ spa_ffmpeg_dec_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_get_status (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -400,12 +420,12 @@ spa_ffmpeg_dec_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
|
|
@ -415,7 +435,7 @@ spa_ffmpeg_dec_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -427,7 +447,7 @@ spa_ffmpeg_dec_node_port_alloc_buffers (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_push_input (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
|
|
@ -435,18 +455,19 @@ spa_ffmpeg_dec_node_port_push_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_pull_output (SpaHandle *handle,
|
||||
spa_ffmpeg_dec_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaFFMpegDec *this = (SpaFFMpegDec *) handle;
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegState *state;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (info[i].port_id != OUTPUT_PORT_ID) {
|
||||
|
|
@ -469,7 +490,17 @@ spa_ffmpeg_dec_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
static const SpaNode ffmpeg_dec_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_ffmpeg_dec_node_get_props,
|
||||
spa_ffmpeg_dec_node_set_props,
|
||||
|
|
@ -490,19 +521,24 @@ static const SpaNode ffmpeg_dec_node = {
|
|||
spa_ffmpeg_dec_node_port_get_status,
|
||||
spa_ffmpeg_dec_node_port_push_input,
|
||||
spa_ffmpeg_dec_node_port_pull_output,
|
||||
spa_ffmpeg_dec_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_dec_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
spa_ffmpeg_dec_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
void **interface)
|
||||
{
|
||||
SpaFFMpegDec *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegDec *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &ffmpeg_dec_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -518,6 +554,8 @@ spa_ffmpeg_dec_init (SpaHandle *handle)
|
|||
handle->get_interface = spa_ffmpeg_dec_get_interface;
|
||||
|
||||
this = (SpaFFMpegDec *) handle;
|
||||
this->node = ffmpeg_dec_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ typedef struct {
|
|||
|
||||
struct _SpaFFMpegEnc {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaFFMpegEncProps props[2];
|
||||
|
||||
|
|
@ -86,14 +87,16 @@ static const SpaPropInfo prop_info[] =
|
|||
};
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_get_props (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -101,16 +104,19 @@ spa_ffmpeg_enc_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_set_props (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEncProps *p = &this->props[1];
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegEncProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_ffmpeg_enc_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -122,14 +128,16 @@ spa_ffmpeg_enc_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_send_command (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -145,7 +153,7 @@ spa_ffmpeg_enc_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_STOP:
|
||||
|
|
@ -159,7 +167,7 @@ spa_ffmpeg_enc_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -172,15 +180,17 @@ spa_ffmpeg_enc_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_set_event_callback (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -188,13 +198,13 @@ spa_ffmpeg_enc_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_get_n_ports (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -210,13 +220,13 @@ spa_ffmpeg_enc_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_get_port_ids (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports > 0)
|
||||
|
|
@ -229,34 +239,36 @@ spa_ffmpeg_enc_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_add_port (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_remove_port (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegState *s;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -278,20 +290,22 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_set_format (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegState *state;
|
||||
SpaResult res;
|
||||
SpaFormat *f, *tf;
|
||||
size_t fs;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -324,16 +338,18 @@ spa_ffmpeg_enc_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_get_format (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegState *state;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -348,15 +364,17 @@ spa_ffmpeg_enc_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_get_info (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -366,7 +384,7 @@ spa_ffmpeg_enc_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_get_props (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -374,7 +392,7 @@ spa_ffmpeg_enc_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_set_props (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -382,15 +400,17 @@ spa_ffmpeg_enc_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_get_status (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -400,12 +420,12 @@ spa_ffmpeg_enc_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (!IS_VALID_PORT (port_id))
|
||||
|
|
@ -415,7 +435,7 @@ spa_ffmpeg_enc_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -427,7 +447,7 @@ spa_ffmpeg_enc_node_port_alloc_buffers (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_push_input (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
|
|
@ -435,18 +455,20 @@ spa_ffmpeg_enc_node_port_push_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_pull_output (SpaHandle *handle,
|
||||
spa_ffmpeg_enc_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle;
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegState *state;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) node->handle;
|
||||
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (info[i].port_id != OUTPUT_PORT_ID) {
|
||||
|
|
@ -469,7 +491,16 @@ spa_ffmpeg_enc_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static const SpaNode ffmpeg_enc_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_ffmpeg_enc_node_get_props,
|
||||
spa_ffmpeg_enc_node_set_props,
|
||||
|
|
@ -490,19 +521,24 @@ static const SpaNode ffmpeg_enc_node = {
|
|||
spa_ffmpeg_enc_node_port_get_status,
|
||||
spa_ffmpeg_enc_node_port_push_input,
|
||||
spa_ffmpeg_enc_node_port_pull_output,
|
||||
spa_ffmpeg_enc_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_ffmpeg_enc_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
spa_ffmpeg_enc_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
void **interface)
|
||||
{
|
||||
SpaFFMpegEnc *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaFFMpegEnc *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &ffmpeg_enc_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -518,6 +554,8 @@ spa_ffmpeg_enc_init (SpaHandle *handle)
|
|||
handle->get_interface = spa_ffmpeg_enc_get_interface;
|
||||
|
||||
this = (SpaFFMpegEnc *) handle;
|
||||
this->node = ffmpeg_enc_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ subdir('alsa')
|
|||
subdir('audiomixer')
|
||||
subdir('audiotestsrc')
|
||||
subdir('ffmpeg')
|
||||
subdir('remote')
|
||||
#subdir('libva')
|
||||
subdir('volume')
|
||||
subdir('v4l2')
|
||||
|
|
|
|||
7
spa/plugins/remote/meson.build
Normal file
7
spa/plugins/remote/meson.build
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
remote_sources = ['proxy.c', 'plugin.c']
|
||||
|
||||
remotelib = shared_library('spa-remote',
|
||||
remote_sources,
|
||||
include_directories : inc,
|
||||
link_with : spalib,
|
||||
install : true)
|
||||
46
spa/plugins/remote/plugin.c
Normal file
46
spa/plugins/remote/plugin.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* Spa Volume plugin
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <spa/plugin.h>
|
||||
#include <spa/node.h>
|
||||
|
||||
extern const SpaHandleFactory spa_proxy_factory;
|
||||
|
||||
SpaResult
|
||||
spa_enum_handle_factory (const SpaHandleFactory **factory,
|
||||
void **state)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (factory == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*factory = &spa_proxy_factory;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*(int*)state = ++index;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
975
spa/plugins/remote/proxy.c
Normal file
975
spa/plugins/remote/proxy.c
Normal file
|
|
@ -0,0 +1,975 @@
|
|||
/* Spa
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
#include <spa/node.h>
|
||||
#include <spa/control.h>
|
||||
|
||||
#define MAX_INPUTS 64
|
||||
#define MAX_OUTPUTS 64
|
||||
#define MAX_PORTS (MAX_INPUTS + MAX_OUTPUTS)
|
||||
|
||||
#define CHECK_PORT_ID(this,id) ((id) < MAX_PORTS && (this)->ports[id].valid)
|
||||
#define CHECK_PORT_ID_DIR(this,id,dir) (CHECK_PORT_ID(this,id) && (this)->ports[i].direction == (dir))
|
||||
|
||||
typedef struct _SpaProxy SpaProxy;
|
||||
|
||||
typedef struct {
|
||||
SpaProps props;
|
||||
int socketfd;
|
||||
} SpaProxyProps;
|
||||
|
||||
typedef struct {
|
||||
SpaDirection direction;
|
||||
bool valid;
|
||||
bool have_format;
|
||||
SpaPortInfo info;
|
||||
SpaPortStatus status;
|
||||
SpaFormat formats[2];
|
||||
SpaBuffer **buffers;
|
||||
unsigned int n_buffers;
|
||||
} SpaProxyPort;
|
||||
|
||||
struct _SpaProxy {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaProxyProps props[2];
|
||||
|
||||
SpaEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
SpaPollFd fds[1];
|
||||
SpaPollItem poll;
|
||||
|
||||
unsigned int n_inputs;
|
||||
unsigned int n_outputs;
|
||||
SpaProxyPort ports[MAX_PORTS];
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_ID_SOCKET,
|
||||
PROP_ID_LAST,
|
||||
};
|
||||
|
||||
static const SpaPropInfo prop_info[PROP_ID_LAST] =
|
||||
{
|
||||
{ PROP_ID_SOCKET, "socket", "The Socket factor",
|
||||
SPA_PROP_FLAG_READWRITE,
|
||||
SPA_PROP_TYPE_INT, sizeof (int),
|
||||
sizeof (int), NULL,
|
||||
SPA_PROP_RANGE_TYPE_NONE, 0, NULL,
|
||||
NULL,
|
||||
offsetof (SpaProxyProps, socketfd),
|
||||
0, 0,
|
||||
NULL },
|
||||
};
|
||||
|
||||
static void
|
||||
reset_proxy_props (SpaProxyProps *props)
|
||||
{
|
||||
props->socketfd = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
update_poll (SpaProxy *this, int socketfd)
|
||||
{
|
||||
SpaEvent event;
|
||||
SpaProxyProps *p;
|
||||
|
||||
p = &this->props[1];
|
||||
|
||||
if (p->socketfd != -1) {
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
event.type = SPA_EVENT_TYPE_REMOVE_POLL;
|
||||
event.port_id = 0;
|
||||
event.data = &this->poll;
|
||||
event.size = sizeof (this->poll);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
p->socketfd = socketfd;
|
||||
|
||||
if (p->socketfd != -1) {
|
||||
this->fds[0].fd = p->socketfd;
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
event.type = SPA_EVENT_TYPE_ADD_POLL;
|
||||
event.port_id = 0;
|
||||
event.data = &this->poll;
|
||||
event.size = sizeof (this->poll);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyProps *op, *np;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
op = &this->props[1];
|
||||
np = &this->props[0];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_proxy_props (np);
|
||||
props = &np->props;
|
||||
}
|
||||
|
||||
/* copy new properties */
|
||||
res = spa_props_copy (props, &np->props);
|
||||
|
||||
/* compare changes */
|
||||
if (op->socketfd != np->socketfd)
|
||||
update_poll (this, np->socketfd);
|
||||
|
||||
/* commit changes */
|
||||
memcpy (op, np, sizeof (*np));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
||||
case SPA_COMMAND_START:
|
||||
if (this->event_cb) {
|
||||
SpaEvent event;
|
||||
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
event.type = SPA_EVENT_TYPE_STARTED;
|
||||
event.port_id = -1;
|
||||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
case SPA_COMMAND_STOP:
|
||||
if (this->event_cb) {
|
||||
SpaEvent event;
|
||||
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
event.type = SPA_EVENT_TYPE_STOPPED;
|
||||
event.port_id = -1;
|
||||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
case SPA_COMMAND_FLUSH:
|
||||
case SPA_COMMAND_DRAIN:
|
||||
case SPA_COMMAND_MARKER:
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (n_input_ports)
|
||||
*n_input_ports = this->n_inputs;
|
||||
if (n_output_ports)
|
||||
*n_output_ports = this->n_outputs;
|
||||
if (max_input_ports)
|
||||
*max_input_ports = MAX_INPUTS;
|
||||
if (max_output_ports)
|
||||
*max_output_ports = MAX_OUTPUTS;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
SpaProxy *this;
|
||||
int c, i;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (input_ids) {
|
||||
n_input_ports = SPA_MIN (n_input_ports, MAX_PORTS);
|
||||
for (c = 0, i = 0; i < n_input_ports; i++) {
|
||||
if (this->ports[i].valid && this->ports[i].direction == SPA_DIRECTION_INPUT)
|
||||
input_ids[c++] = i;
|
||||
}
|
||||
}
|
||||
if (output_ids) {
|
||||
n_output_ports = SPA_MIN (n_output_ports, MAX_PORTS);
|
||||
for (c = 0, i = 0; i < n_output_ports; i++) {
|
||||
if (this->ports[i].valid && this->ports[i].direction == SPA_DIRECTION_OUTPUT)
|
||||
output_ids[c++] = i;
|
||||
}
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
int index;
|
||||
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*format = &port->formats[0];
|
||||
*(int*)state = ++index;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
SpaControl control;
|
||||
SpaControlBuilder builder;
|
||||
SpaControlCmdSetFormat sf;
|
||||
uint8_t buf[128];
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
spa_control_builder_init_into (&builder, buf, sizeof (buf), NULL, 0);
|
||||
sf.port = port_id;
|
||||
sf.format = format;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_SET_FORMAT, &sf);
|
||||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control", this);
|
||||
|
||||
port->have_format = format != NULL;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = &port->formats[1];
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
*info = &port->info;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*status = &port->status;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
|
||||
if (node == NULL || node->handle == NULL || buffers == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
port->buffers = buffers;
|
||||
port->n_buffers = n_buffers;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t *n_buffers)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
|
||||
if (node == NULL || node->handle == NULL || buffers == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
if (!CHECK_PORT_ID (this, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
tmpfile_create (void *data, size_t size)
|
||||
{
|
||||
char filename[] = "/dev/shm/tmpfilepay.XXXXXX";
|
||||
int fd;
|
||||
|
||||
fd = mkostemp (filename, O_CLOEXEC);
|
||||
if (fd == -1) {
|
||||
fprintf (stderr, "Failed to create temporary file: %s", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
unlink (filename);
|
||||
|
||||
if (write (fd, data, size) != (ssize_t) size)
|
||||
fprintf (stderr, "Failed to write data: %s", strerror (errno));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaBuffer buffer;
|
||||
SpaData datas[16];
|
||||
int idx[16];
|
||||
SpaBuffer *orig;
|
||||
} MyBuffer;
|
||||
|
||||
static SpaResult
|
||||
send_buffer (SpaProxy *this, SpaBuffer *buffer)
|
||||
{
|
||||
SpaControl control;
|
||||
SpaControlBuilder builder;
|
||||
uint8_t buf[1024];
|
||||
int fds[16];
|
||||
SpaControlCmdAddBuffer ab;
|
||||
SpaControlCmdProcessBuffer pb;
|
||||
SpaControlCmdRemoveBuffer rb;
|
||||
bool tmpfile = false;
|
||||
unsigned int i;
|
||||
MyBuffer b;
|
||||
SpaResult res;
|
||||
|
||||
spa_control_builder_init_into (&builder, buf, 1024, fds, 16);
|
||||
|
||||
b.buffer.refcount = 1;
|
||||
b.buffer.notify = NULL;
|
||||
b.buffer.id = buffer->id;
|
||||
b.buffer.size = buffer->size;
|
||||
b.buffer.n_metas = buffer->n_metas;
|
||||
b.buffer.metas = buffer->metas;
|
||||
b.buffer.n_datas = buffer->n_datas;
|
||||
b.buffer.datas = b.datas;
|
||||
|
||||
for (i = 0; i < buffer->n_datas; i++) {
|
||||
SpaData *d = &buffer->datas[i];
|
||||
int fd;
|
||||
SpaControlCmdAddMem am;
|
||||
|
||||
if (d->type == SPA_DATA_TYPE_FD) {
|
||||
fd = *((int *)d->ptr);
|
||||
} else {
|
||||
fd = tmpfile_create (d->ptr, d->size + d->offset);
|
||||
tmpfile = true;
|
||||
}
|
||||
am.port = 0;
|
||||
am.id = i;
|
||||
am.type = 0;
|
||||
am.fd_index = spa_control_builder_add_fd (&builder, fd, tmpfile ? true : false);
|
||||
am.offset = 0;
|
||||
am.size = d->offset + d->size;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_ADD_MEM, &am);
|
||||
|
||||
b.idx[i] = i;
|
||||
b.datas[i].type = SPA_DATA_TYPE_MEMID;
|
||||
b.datas[i].ptr_type = NULL;
|
||||
b.datas[i].ptr = &b.idx[i];
|
||||
b.datas[i].offset = d->offset;
|
||||
b.datas[i].size = d->size;
|
||||
b.datas[i].stride = d->stride;
|
||||
}
|
||||
ab.port = 0;
|
||||
ab.buffer = &b.buffer;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_ADD_BUFFER, &ab);
|
||||
pb.port = 0;
|
||||
pb.id = b.buffer.id;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_PROCESS_BUFFER, &pb);
|
||||
rb.port = 0;
|
||||
rb.id = b.buffer.id;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_REMOVE_BUFFER, &rb);
|
||||
|
||||
for (i = 0; i < buffer->n_datas; i++) {
|
||||
SpaControlCmdRemoveMem rm;
|
||||
rm.port = 0;
|
||||
rm.id = i;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_REMOVE_MEM, &rm);
|
||||
}
|
||||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control", this);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
bool have_enough = false;
|
||||
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (!CHECK_PORT_ID_DIR (this, info[i].port_id, SPA_DIRECTION_INPUT)) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
port = &this->ports[info[i].port_id];
|
||||
|
||||
if (!port->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
if (have_enough)
|
||||
return SPA_RESULT_HAVE_ENOUGH_INPUT;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaProxy *this;
|
||||
SpaProxyPort *port;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
bool need_more = false;
|
||||
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (!CHECK_PORT_ID_DIR (this, info[i].port_id, SPA_DIRECTION_OUTPUT)) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
port = &this->ports[info[i].port_id];
|
||||
|
||||
if (!port->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
if (need_more)
|
||||
return SPA_RESULT_NEED_MORE_INPUT;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
parse_control (SpaProxy *this,
|
||||
SpaControl *ctrl)
|
||||
{
|
||||
SpaControlIter it;
|
||||
SpaResult res;
|
||||
|
||||
spa_control_iter_init (&it, ctrl);
|
||||
while (spa_control_iter_next (&it) == SPA_RESULT_OK) {
|
||||
SpaControlCmd cmd = spa_control_iter_get_cmd (&it);
|
||||
|
||||
switch (cmd) {
|
||||
case SPA_CONTROL_CMD_ADD_PORT:
|
||||
case SPA_CONTROL_CMD_REMOVE_PORT:
|
||||
case SPA_CONTROL_CMD_SET_FORMAT:
|
||||
case SPA_CONTROL_CMD_SET_PROPERTY:
|
||||
case SPA_CONTROL_CMD_END_CONFIGURE:
|
||||
case SPA_CONTROL_CMD_PAUSE:
|
||||
case SPA_CONTROL_CMD_START:
|
||||
case SPA_CONTROL_CMD_STOP:
|
||||
fprintf (stderr, "proxy %p: got unexpected control %d", this, cmd);
|
||||
break;
|
||||
|
||||
case SPA_CONTROL_CMD_NODE_UPDATE:
|
||||
case SPA_CONTROL_CMD_PORT_UPDATE:
|
||||
case SPA_CONTROL_CMD_PORT_REMOVED:
|
||||
fprintf (stderr, "proxy %p: command not implemented %d", this, cmd);
|
||||
break;
|
||||
|
||||
case SPA_CONTROL_CMD_START_CONFIGURE:
|
||||
{
|
||||
SpaControlBuilder builder;
|
||||
SpaControl control;
|
||||
uint8_t buf[128];
|
||||
|
||||
/* set port format */
|
||||
|
||||
/* send end-configure */
|
||||
spa_control_builder_init_into (&builder, buf, sizeof (buf), NULL, 0);
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_END_CONFIGURE, NULL);
|
||||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control: %d", this, res);
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_PORT_STATUS_CHANGE:
|
||||
{
|
||||
fprintf (stderr, "proxy %p: command not implemented %d", this, cmd);
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_START_ALLOC:
|
||||
{
|
||||
SpaControlBuilder builder;
|
||||
SpaControl control;
|
||||
uint8_t buf[128];
|
||||
|
||||
/* FIXME read port memory requirements */
|
||||
/* FIXME add_mem */
|
||||
|
||||
/* send start */
|
||||
spa_control_builder_init_into (&builder, buf, sizeof (buf), NULL, 0);
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_START, NULL);
|
||||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control %d", this, res);
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_NEED_INPUT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_HAVE_OUTPUT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case SPA_CONTROL_CMD_ADD_MEM:
|
||||
break;
|
||||
case SPA_CONTROL_CMD_REMOVE_MEM:
|
||||
break;
|
||||
case SPA_CONTROL_CMD_ADD_BUFFER:
|
||||
break;
|
||||
case SPA_CONTROL_CMD_REMOVE_BUFFER:
|
||||
break;
|
||||
|
||||
case SPA_CONTROL_CMD_PROCESS_BUFFER:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case SPA_CONTROL_CMD_REUSE_BUFFER:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf (stderr, "proxy %p: command unhandled %d", this, cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
spa_control_iter_end (&it);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
proxy_on_fd_events (SpaPollNotifyData *data)
|
||||
{
|
||||
SpaProxy *this = data->user_data;
|
||||
SpaResult res;
|
||||
|
||||
if (data->fds[0].revents & POLLIN) {
|
||||
SpaControl control;
|
||||
uint8_t buf[1024];
|
||||
int fds[16];
|
||||
|
||||
if ((res = spa_control_read (&control, data->fds[0].fd, buf, 1024, fds, 16)) < 0) {
|
||||
fprintf (stderr, "proxy %p: failed to read control: %d", this, res);
|
||||
return 0;
|
||||
}
|
||||
parse_control (this, &control);
|
||||
spa_control_clear (&control);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SpaNode proxy_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_proxy_node_get_props,
|
||||
spa_proxy_node_set_props,
|
||||
spa_proxy_node_send_command,
|
||||
spa_proxy_node_set_event_callback,
|
||||
spa_proxy_node_get_n_ports,
|
||||
spa_proxy_node_get_port_ids,
|
||||
spa_proxy_node_add_port,
|
||||
spa_proxy_node_remove_port,
|
||||
spa_proxy_node_port_enum_formats,
|
||||
spa_proxy_node_port_set_format,
|
||||
spa_proxy_node_port_get_format,
|
||||
spa_proxy_node_port_get_info,
|
||||
spa_proxy_node_port_get_props,
|
||||
spa_proxy_node_port_set_props,
|
||||
spa_proxy_node_port_use_buffers,
|
||||
spa_proxy_node_port_alloc_buffers,
|
||||
spa_proxy_node_port_get_status,
|
||||
spa_proxy_node_port_push_input,
|
||||
spa_proxy_node_port_pull_output,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_proxy_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
void **interface)
|
||||
{
|
||||
SpaProxy *this = (SpaProxy *) handle;
|
||||
|
||||
if (handle == NULL || interface == 0)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
proxy_instantiate (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
handle->get_interface = spa_proxy_get_interface;
|
||||
|
||||
this = (SpaProxy *) handle;
|
||||
this->node = proxy_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
this->props[1].props.get_prop = spa_props_generic_get_prop;
|
||||
reset_proxy_props (&this->props[1]);
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
|
||||
this->fds[0].fd = -1;
|
||||
this->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
this->fds[0].revents = 0;
|
||||
this->poll.id = 0;
|
||||
this->poll.fds = this->fds;
|
||||
this->poll.n_fds = 1;
|
||||
this->poll.idle_cb = NULL;
|
||||
this->poll.before_cb = NULL;
|
||||
this->poll.after_cb = proxy_on_fd_events;
|
||||
this->poll.user_data = this;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static const SpaInterfaceInfo proxy_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
proxy_enum_interface_info (const SpaHandleFactory *factory,
|
||||
const SpaInterfaceInfo **info,
|
||||
void **state)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (factory == NULL || info == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
index = (*state == NULL ? 0 : *(int*)state);
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
*info = &proxy_interfaces[index];
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*(int*)state = ++index;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
const SpaHandleFactory spa_proxy_factory =
|
||||
{ "proxy",
|
||||
NULL,
|
||||
sizeof (SpaProxy),
|
||||
proxy_instantiate,
|
||||
proxy_enum_interface_info,
|
||||
};
|
||||
|
|
@ -117,6 +117,7 @@ typedef struct {
|
|||
|
||||
struct _SpaV4l2Source {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaV4l2SourceProps props[2];
|
||||
|
||||
|
|
@ -167,14 +168,16 @@ static const SpaPropInfo prop_info[] =
|
|||
};
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -182,16 +185,19 @@ spa_v4l2_source_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_set_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2SourceProps *p = &this->props[1];
|
||||
SpaV4l2Source *this;
|
||||
SpaV4l2SourceProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_v4l2_source_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -203,14 +209,16 @@ spa_v4l2_source_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_send_command (SpaHandle *handle,
|
||||
spa_v4l2_source_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -228,7 +236,7 @@ spa_v4l2_source_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_STOP:
|
||||
|
|
@ -244,7 +252,7 @@ spa_v4l2_source_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -257,15 +265,17 @@ spa_v4l2_source_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_set_event_callback (SpaHandle *handle,
|
||||
spa_v4l2_source_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -273,13 +283,13 @@ spa_v4l2_source_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_n_ports (SpaHandle *handle,
|
||||
spa_v4l2_source_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -295,13 +305,13 @@ spa_v4l2_source_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_port_ids (SpaHandle *handle,
|
||||
spa_v4l2_source_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_output_ports > 0)
|
||||
|
|
@ -312,15 +322,15 @@ spa_v4l2_source_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_add_port (SpaHandle *handle,
|
||||
spa_v4l2_source_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_remove_port (SpaHandle *handle,
|
||||
spa_v4l2_source_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
|
@ -354,18 +364,20 @@ spa_v4l2_format_init (V4l2Format *f)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -375,20 +387,22 @@ spa_v4l2_source_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_set_format (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
SpaV4l2State *state;
|
||||
SpaResult res;
|
||||
V4l2Format *f, *tf;
|
||||
size_t fs;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -421,16 +435,18 @@ spa_v4l2_source_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_get_format (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
SpaV4l2State *state;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -445,15 +461,17 @@ spa_v4l2_source_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_get_info (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -463,7 +481,7 @@ spa_v4l2_source_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_get_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -471,7 +489,7 @@ spa_v4l2_source_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_set_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -479,15 +497,17 @@ spa_v4l2_source_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_get_status (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -497,16 +517,18 @@ spa_v4l2_source_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -516,19 +538,31 @@ spa_v4l2_source_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
unsigned int n_params,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t *n_buffers)
|
||||
unsigned int *n_buffers)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
spa_v4l2_alloc_buffers (this, params, n_params, buffers, n_buffers);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_push_input (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
|
|
@ -536,18 +570,20 @@ spa_v4l2_source_node_port_push_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_pull_output (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2Source *this;
|
||||
SpaV4l2State *state;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) node->handle;
|
||||
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
V4l2Buffer *b;
|
||||
|
|
@ -576,7 +612,7 @@ spa_v4l2_source_node_port_pull_output (SpaHandle *handle,
|
|||
|
||||
b->outstanding = true;
|
||||
|
||||
info[i].buffer = &b->buffer;
|
||||
info[i].id = b->buffer.id;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
|
|
@ -585,7 +621,17 @@ spa_v4l2_source_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
static const SpaNode v4l2source_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_v4l2_source_node_get_props,
|
||||
spa_v4l2_source_node_set_props,
|
||||
|
|
@ -606,19 +652,24 @@ static const SpaNode v4l2source_node = {
|
|||
spa_v4l2_source_node_port_get_status,
|
||||
spa_v4l2_source_node_port_push_input,
|
||||
spa_v4l2_source_node_port_pull_output,
|
||||
spa_v4l2_source_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
void **interface)
|
||||
{
|
||||
SpaV4l2Source *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaV4l2Source *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &v4l2source_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -638,6 +689,8 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_v4l2_source_get_interface;
|
||||
|
||||
this = (SpaV4l2Source *) handle;
|
||||
this->node = v4l2source_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -481,19 +481,20 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
|
|||
event.port_id = 0;
|
||||
event.size = 0;
|
||||
event.data = NULL;
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
v4l2_buffer_free (void *data)
|
||||
v4l2_buffer_recycle (void *data)
|
||||
{
|
||||
V4l2Buffer *b = (V4l2Buffer *) data;
|
||||
SpaV4l2Source *this = b->source;
|
||||
SpaBuffer *buf = data;
|
||||
SpaV4l2Source *this = buf->user_data;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
V4l2Buffer *b = &state->buffers[buf->id];
|
||||
|
||||
b->buffer.refcount = 1;
|
||||
b->imported->refcount = 1;
|
||||
b->outstanding = false;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_QBUF, &b->v4l2_buffer) < 0) {
|
||||
|
|
@ -531,10 +532,15 @@ spa_v4l2_import_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_bu
|
|||
|
||||
b = &state->buffers[i];
|
||||
|
||||
buffers[i]->notify = v4l2_buffer_recycle;
|
||||
buffers[i]->user_data = this;
|
||||
|
||||
fprintf (stderr, "import buffer %p\n", buffers[i]);
|
||||
|
||||
b->source = this;
|
||||
b->buffer.refcount = 0;
|
||||
b->buffer.notify = v4l2_buffer_free;
|
||||
b->buffer.id = i;
|
||||
b->buffer.notify = v4l2_buffer_recycle;
|
||||
b->buffer.id = buffers[i]->id;
|
||||
b->buffer.size = buffers[i]->size;
|
||||
b->buffer.n_metas = buffers[i]->n_metas;
|
||||
b->buffer.metas = buffers[i]->metas;
|
||||
|
|
@ -550,7 +556,7 @@ spa_v4l2_import_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_bu
|
|||
b->v4l2_buffer.m.userptr = (unsigned long) b->buffer.datas[0].ptr;
|
||||
b->v4l2_buffer.length = b->buffer.datas[0].size;
|
||||
|
||||
v4l2_buffer_free (b);
|
||||
v4l2_buffer_recycle (buffers[i]);
|
||||
}
|
||||
state->have_buffers = true;
|
||||
|
||||
|
|
@ -558,7 +564,11 @@ spa_v4l2_import_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_bu
|
|||
}
|
||||
|
||||
static int
|
||||
mmap_init (SpaV4l2Source *this)
|
||||
mmap_init (SpaV4l2Source *this,
|
||||
SpaAllocParam **params,
|
||||
unsigned int n_params,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers)
|
||||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
struct v4l2_requestbuffers reqbuf;
|
||||
|
|
@ -569,7 +579,7 @@ mmap_init (SpaV4l2Source *this)
|
|||
CLEAR(reqbuf);
|
||||
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
reqbuf.memory = state->memtype;
|
||||
reqbuf.count = MAX_BUFFERS;
|
||||
reqbuf.count = *n_buffers;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
|
||||
perror ("VIDIOC_REQBUFS");
|
||||
|
|
@ -577,6 +587,8 @@ mmap_init (SpaV4l2Source *this)
|
|||
}
|
||||
|
||||
fprintf (stderr, "got %d buffers\n", reqbuf.count);
|
||||
*n_buffers = reqbuf.count;
|
||||
|
||||
if (reqbuf.count < 2) {
|
||||
fprintf (stderr, "can't allocate enough buffers\n");
|
||||
return -1;
|
||||
|
|
@ -601,9 +613,13 @@ mmap_init (SpaV4l2Source *this)
|
|||
}
|
||||
|
||||
b = &state->buffers[i];
|
||||
|
||||
buffers[i] = &b->buffer;
|
||||
|
||||
b->source = this;
|
||||
b->buffer.refcount = 0;
|
||||
b->buffer.notify = v4l2_buffer_free;
|
||||
b->buffer.notify = v4l2_buffer_recycle;
|
||||
b->buffer.user_data = this;
|
||||
b->buffer.id = i;
|
||||
b->buffer.size = buf.length;
|
||||
b->buffer.n_metas = 1;
|
||||
|
|
@ -655,6 +671,7 @@ mmap_init (SpaV4l2Source *this)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
b->imported = &b->buffer;
|
||||
b->outstanding = true;
|
||||
|
||||
CLEAR (b->v4l2_buffer);
|
||||
|
|
@ -662,7 +679,7 @@ mmap_init (SpaV4l2Source *this)
|
|||
b->v4l2_buffer.memory = state->memtype;
|
||||
b->v4l2_buffer.index = i;
|
||||
|
||||
v4l2_buffer_free (b);
|
||||
v4l2_buffer_recycle (b);
|
||||
}
|
||||
state->have_buffers = true;
|
||||
|
||||
|
|
@ -681,6 +698,27 @@ read_init (SpaV4l2Source *this)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
spa_v4l2_alloc_buffers (SpaV4l2Source *this,
|
||||
SpaAllocParam **params,
|
||||
unsigned int n_params,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers)
|
||||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
|
||||
if (state->cap.capabilities & V4L2_CAP_STREAMING) {
|
||||
if (mmap_init (this, params, n_params, buffers, n_buffers) < 0)
|
||||
if (userptr_init (this) < 0)
|
||||
return -1;
|
||||
} else if (state->cap.capabilities & V4L2_CAP_READWRITE) {
|
||||
if (read_init (this) < 0)
|
||||
return -1;
|
||||
} else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
spa_v4l2_start (SpaV4l2Source *this)
|
||||
{
|
||||
|
|
@ -691,17 +729,9 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
if (spa_v4l2_open (this) < 0)
|
||||
return -1;
|
||||
|
||||
if (!state->have_buffers) {
|
||||
if (state->cap.capabilities & V4L2_CAP_STREAMING) {
|
||||
if (mmap_init (this) < 0)
|
||||
if (userptr_init (this) < 0)
|
||||
return -1;
|
||||
} else if (state->cap.capabilities & V4L2_CAP_READWRITE) {
|
||||
if (read_init (this) < 0)
|
||||
return -1;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
if (!state->have_buffers)
|
||||
return -1;
|
||||
|
||||
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
|
|
@ -714,13 +744,14 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
state->fds[0].events = POLLIN | POLLPRI | POLLERR;
|
||||
state->fds[0].revents = 0;
|
||||
|
||||
state->poll.id = 0;
|
||||
state->poll.fds = state->fds;
|
||||
state->poll.n_fds = 1;
|
||||
state->poll.idle_cb = NULL;
|
||||
state->poll.before_cb = NULL;
|
||||
state->poll.after_cb = v4l2_on_fd_events;
|
||||
state->poll.user_data = this;
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
|
||||
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl (state->fd, VIDIOC_STREAMON, &type) < 0) {
|
||||
|
|
@ -750,7 +781,7 @@ spa_v4l2_stop (SpaV4l2Source *this)
|
|||
b = &state->buffers[i];
|
||||
if (b->outstanding) {
|
||||
fprintf (stderr, "queueing outstanding buffer %p\n", b);
|
||||
v4l2_buffer_free (b);
|
||||
v4l2_buffer_recycle (b);
|
||||
}
|
||||
if (state->export_buf) {
|
||||
close (b->dmafd);
|
||||
|
|
@ -766,7 +797,7 @@ spa_v4l2_stop (SpaV4l2Source *this)
|
|||
event.port_id = 0;
|
||||
event.data = &state->poll;
|
||||
event.size = sizeof (state->poll);
|
||||
this->event_cb (&this->handle, &event, this->user_data);
|
||||
this->event_cb (&this->node, &event, this->user_data);
|
||||
|
||||
spa_v4l2_close (this);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,14 @@ typedef struct {
|
|||
bool have_format;
|
||||
SpaPortInfo info;
|
||||
SpaPortStatus status;
|
||||
SpaBuffer **buffers;
|
||||
unsigned int n_buffers;
|
||||
SpaBuffer *buffer;
|
||||
} SpaVolumePort;
|
||||
|
||||
struct _SpaVolume {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaVolumeProps props[2];
|
||||
|
||||
|
|
@ -50,7 +54,6 @@ struct _SpaVolume {
|
|||
SpaAudioRawFormat current_format;
|
||||
|
||||
SpaVolumePort ports[2];
|
||||
SpaBuffer *input_buffer;
|
||||
};
|
||||
|
||||
static const double default_volume = 1.0;
|
||||
|
|
@ -99,14 +102,16 @@ reset_volume_props (SpaVolumeProps *props)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_get_props (SpaHandle *handle,
|
||||
spa_volume_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -114,16 +119,19 @@ spa_volume_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_set_props (SpaHandle *handle,
|
||||
spa_volume_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolumeProps *p = &this->props[1];
|
||||
SpaVolume *this;
|
||||
SpaVolumeProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_volume_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -134,14 +142,16 @@ spa_volume_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_send_command (SpaHandle *handle,
|
||||
spa_volume_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -157,7 +167,7 @@ spa_volume_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -172,7 +182,7 @@ spa_volume_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -185,15 +195,17 @@ spa_volume_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_set_event_callback (SpaHandle *handle,
|
||||
spa_volume_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -201,13 +213,13 @@ spa_volume_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_get_n_ports (SpaHandle *handle,
|
||||
spa_volume_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -223,13 +235,13 @@ spa_volume_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_get_port_ids (SpaHandle *handle,
|
||||
spa_volume_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports > 0 && input_ids)
|
||||
|
|
@ -242,33 +254,35 @@ spa_volume_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_add_port (SpaHandle *handle,
|
||||
spa_volume_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_remove_port (SpaHandle *handle,
|
||||
spa_volume_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_volume_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -288,47 +302,57 @@ spa_volume_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_set_format (SpaHandle *handle,
|
||||
spa_volume_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (port_id >= 2)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (format == NULL) {
|
||||
this->ports[port_id].have_format = false;
|
||||
port->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
if ((res = spa_audio_raw_format_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
|
||||
this->ports[port_id].have_format = true;
|
||||
port->have_format = true;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_get_format (SpaHandle *handle,
|
||||
spa_volume_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (port_id >= 2)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->ports[port_id].have_format)
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = &this->current_format.format;
|
||||
|
|
@ -337,25 +361,29 @@ spa_volume_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_get_info (SpaHandle *handle,
|
||||
spa_volume_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (port_id >= 2)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*info = &this->ports[port_id].info;
|
||||
port = &this->ports[port_id];
|
||||
*info = &port->info;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_get_props (SpaHandle *handle,
|
||||
spa_volume_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -363,7 +391,7 @@ spa_volume_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_set_props (SpaHandle *handle,
|
||||
spa_volume_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -371,28 +399,33 @@ spa_volume_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_get_status (SpaHandle *handle,
|
||||
spa_volume_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (port_id >= 2)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->ports[port_id].have_format)
|
||||
port = &this->ports[port_id];
|
||||
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*status = &this->ports[port_id].status;
|
||||
*status = &port->status;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_volume_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
|
|
@ -401,7 +434,7 @@ spa_volume_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_volume_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -413,59 +446,56 @@ spa_volume_node_port_alloc_buffers (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_push_input (SpaHandle *handle,
|
||||
spa_volume_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaBuffer *buffer;
|
||||
SpaEvent *event;
|
||||
SpaVolume *this;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
bool have_enough = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
SpaVolumePort *port;
|
||||
SpaBuffer *buffer;
|
||||
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
event = info[i].event;
|
||||
buffer = info[i].buffer;
|
||||
port = &this->ports[info[i].port_id];
|
||||
buffer = port->buffers[info[i].id];
|
||||
|
||||
if (buffer == NULL && event == NULL) {
|
||||
if (buffer == NULL) {
|
||||
info[i].status = SPA_RESULT_INVALID_ARGUMENTS;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
if (!this->ports[0].have_format) {
|
||||
if (!port->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->input_buffer != NULL) {
|
||||
if (port->buffer != NULL) {
|
||||
info[i].status = SPA_RESULT_HAVE_ENOUGH_INPUT;
|
||||
have_enough = true;
|
||||
continue;
|
||||
}
|
||||
this->input_buffer = spa_buffer_ref (buffer);
|
||||
port->buffer = spa_buffer_ref (buffer);
|
||||
|
||||
this->ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
this->ports[1].status.flags |= SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
}
|
||||
if (event) {
|
||||
switch (event->type) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
|
|
@ -476,36 +506,44 @@ spa_volume_node_port_push_input (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
static SpaBuffer *
|
||||
find_free_buffer (SpaVolume *this, SpaVolumePort *port)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_pull_output (SpaHandle *handle,
|
||||
spa_volume_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
SpaVolume *this = (SpaVolume *) handle;
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
unsigned int si, di, i, n_samples, n_bytes, soff, doff ;
|
||||
SpaBuffer *sbuf, *dbuf;
|
||||
SpaData *sd, *dd;
|
||||
uint16_t *src, *dst;
|
||||
double volume;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) node->handle;
|
||||
|
||||
if (info->port_id != 1)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->ports[1].have_format)
|
||||
port = &this->ports[info[0].port_id];
|
||||
if (!port->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (this->input_buffer == NULL)
|
||||
if (this->ports[0].buffer == NULL)
|
||||
return SPA_RESULT_NEED_MORE_INPUT;
|
||||
|
||||
volume = this->props[1].volume;
|
||||
|
||||
sbuf = this->input_buffer;
|
||||
dbuf = info->buffer ? info->buffer : this->input_buffer;
|
||||
sbuf = this->ports[0].buffer;
|
||||
dbuf = find_free_buffer (this, port);
|
||||
|
||||
si = di = 0;
|
||||
soff = doff = 0;
|
||||
|
|
@ -528,7 +566,7 @@ spa_volume_node_port_pull_output (SpaHandle *handle,
|
|||
src = (uint16_t*) ((uint8_t*)sd->ptr + soff);
|
||||
dst = (uint16_t*) ((uint8_t*)dd->ptr + doff);
|
||||
|
||||
n_bytes = MIN (sd->size - soff, dd->size - doff);
|
||||
n_bytes = SPA_MIN (sd->size - soff, dd->size - doff);
|
||||
n_samples = n_bytes / sizeof (uint16_t);
|
||||
|
||||
for (i = 0; i < n_samples; i++)
|
||||
|
|
@ -550,8 +588,8 @@ spa_volume_node_port_pull_output (SpaHandle *handle,
|
|||
if (sbuf != dbuf)
|
||||
spa_buffer_unref (sbuf);
|
||||
|
||||
this->input_buffer = NULL;
|
||||
info->buffer = dbuf;
|
||||
this->ports[0].buffer = NULL;
|
||||
info->id = dbuf->id;
|
||||
|
||||
this->ports[0].status.flags |= SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
this->ports[1].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
||||
|
|
@ -559,7 +597,16 @@ spa_volume_node_port_pull_output (SpaHandle *handle,
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_volume_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static const SpaNode volume_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_volume_node_get_props,
|
||||
spa_volume_node_set_props,
|
||||
|
|
@ -580,19 +627,24 @@ static const SpaNode volume_node = {
|
|||
spa_volume_node_port_get_status,
|
||||
spa_volume_node_port_push_input,
|
||||
spa_volume_node_port_pull_output,
|
||||
spa_volume_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_volume_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
void **interface)
|
||||
{
|
||||
SpaVolume *this;
|
||||
|
||||
if (handle == NULL || interface == 0)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaVolume *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &volume_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -613,6 +665,8 @@ volume_instantiate (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_volume_get_interface;
|
||||
|
||||
this = (SpaVolume *) handle;
|
||||
this->node = volume_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ typedef struct {
|
|||
|
||||
struct _SpaXvSink {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
SpaXvSinkProps props[2];
|
||||
|
||||
|
|
@ -126,14 +127,16 @@ static const SpaPropInfo prop_info[] =
|
|||
};
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_get_props (SpaHandle *handle,
|
||||
spa_xv_sink_node_get_props (SpaNode *node,
|
||||
SpaProps **props)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || props == NULL)
|
||||
if (node == NULL || node->handle == NULL || props == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
||||
*props = &this->props[0].props;
|
||||
|
||||
|
|
@ -141,16 +144,19 @@ spa_xv_sink_node_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_set_props (SpaHandle *handle,
|
||||
spa_xv_sink_node_set_props (SpaNode *node,
|
||||
const SpaProps *props)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSinkProps *p = &this->props[1];
|
||||
SpaXvSink *this;
|
||||
SpaXvSinkProps *p;
|
||||
SpaResult res;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
p = &this->props[1];
|
||||
|
||||
if (props == NULL) {
|
||||
reset_xv_sink_props (p);
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -162,14 +168,16 @@ spa_xv_sink_node_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_send_command (SpaHandle *handle,
|
||||
SpaCommand *command)
|
||||
spa_xv_sink_node_send_command (SpaNode *node,
|
||||
SpaCommand *command)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || command == NULL)
|
||||
if (node == NULL || node->handle == NULL || command == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
switch (command->type) {
|
||||
case SPA_COMMAND_INVALID:
|
||||
return SPA_RESULT_INVALID_COMMAND;
|
||||
|
|
@ -187,7 +195,7 @@ spa_xv_sink_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
case SPA_COMMAND_STOP:
|
||||
|
|
@ -203,7 +211,7 @@ spa_xv_sink_node_send_command (SpaHandle *handle,
|
|||
event.data = NULL;
|
||||
event.size = 0;
|
||||
|
||||
this->event_cb (handle, &event, this->user_data);
|
||||
this->event_cb (node, &event, this->user_data);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -216,15 +224,17 @@ spa_xv_sink_node_send_command (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_set_event_callback (SpaHandle *handle,
|
||||
spa_xv_sink_node_set_event_callback (SpaNode *node,
|
||||
SpaEventCallback event,
|
||||
void *user_data)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
this->event_cb = event;
|
||||
this->user_data = user_data;
|
||||
|
||||
|
|
@ -232,13 +242,13 @@ spa_xv_sink_node_set_event_callback (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_get_n_ports (SpaHandle *handle,
|
||||
spa_xv_sink_node_get_n_ports (SpaNode *node,
|
||||
unsigned int *n_input_ports,
|
||||
unsigned int *max_input_ports,
|
||||
unsigned int *n_output_ports,
|
||||
unsigned int *max_output_ports)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_input_ports)
|
||||
|
|
@ -254,13 +264,13 @@ spa_xv_sink_node_get_n_ports (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_get_port_ids (SpaHandle *handle,
|
||||
spa_xv_sink_node_get_port_ids (SpaNode *node,
|
||||
unsigned int n_input_ports,
|
||||
uint32_t *input_ids,
|
||||
unsigned int n_output_ports,
|
||||
uint32_t *output_ids)
|
||||
{
|
||||
if (handle == NULL)
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (n_output_ports > 0)
|
||||
|
|
@ -271,33 +281,35 @@ spa_xv_sink_node_get_port_ids (SpaHandle *handle,
|
|||
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_add_port (SpaHandle *handle,
|
||||
spa_xv_sink_node_add_port (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t *port_id)
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_remove_port (SpaHandle *handle,
|
||||
spa_xv_sink_node_remove_port (SpaNode *node,
|
||||
uint32_t port_id)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_enum_formats (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_enum_formats (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaFormat **format,
|
||||
const SpaFormat *filter,
|
||||
void **state)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
int index;
|
||||
|
||||
if (handle == NULL || format == NULL || state == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -317,19 +329,21 @@ spa_xv_sink_node_port_enum_formats (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_set_format (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_set_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortFormatFlags flags,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
SpaResult res;
|
||||
SpaFormat *f, *tf;
|
||||
size_t fs;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -363,15 +377,17 @@ spa_xv_sink_node_port_set_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_get_format (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_get_format (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
if (node == NULL || node->handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -384,15 +400,17 @@ spa_xv_sink_node_port_get_format (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_get_info (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_get_info (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || info == NULL)
|
||||
if (node == NULL || node->handle == NULL || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -402,7 +420,7 @@ spa_xv_sink_node_port_get_info (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_get_props (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_get_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -410,7 +428,7 @@ spa_xv_sink_node_port_get_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_set_props (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_set_props (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -418,15 +436,17 @@ spa_xv_sink_node_port_set_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_get_status (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_get_status (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || status == NULL)
|
||||
if (node == NULL || node->handle == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) node->handle;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
|
|
@ -436,7 +456,7 @@ spa_xv_sink_node_port_get_status (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_use_buffers (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_use_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t n_buffers)
|
||||
|
|
@ -445,7 +465,7 @@ spa_xv_sink_node_port_use_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_alloc_buffers (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_alloc_buffers (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaAllocParam **params,
|
||||
uint32_t n_params,
|
||||
|
|
@ -456,63 +476,31 @@ spa_xv_sink_node_port_alloc_buffers (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_push_input (SpaHandle *handle,
|
||||
spa_xv_sink_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_node_port_pull_output (SpaHandle *handle,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
spa_xv_sink_node_port_push_event (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaEvent *event)
|
||||
{
|
||||
SpaXvSink *this = (SpaXvSink *) handle;
|
||||
SpaXvState *state;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
state = &this->state;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
XvBuffer *b;
|
||||
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (this->current_format == NULL) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (state->ready_count == 0) {
|
||||
info[i].status = SPA_RESULT_UNEXPECTED;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
b = state->ready;
|
||||
state->ready = b->next;
|
||||
state->ready_count--;
|
||||
|
||||
b->outstanding = true;
|
||||
|
||||
info[i].buffer = &b->buffer;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static const SpaNode xvsink_node = {
|
||||
NULL,
|
||||
sizeof (SpaNode),
|
||||
spa_xv_sink_node_get_props,
|
||||
spa_xv_sink_node_set_props,
|
||||
|
|
@ -533,19 +521,24 @@ static const SpaNode xvsink_node = {
|
|||
spa_xv_sink_node_port_get_status,
|
||||
spa_xv_sink_node_port_push_input,
|
||||
spa_xv_sink_node_port_pull_output,
|
||||
spa_xv_sink_node_port_push_event,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
spa_xv_sink_get_interface (SpaHandle *handle,
|
||||
uint32_t interface_id,
|
||||
const void **interface)
|
||||
void **interface)
|
||||
{
|
||||
SpaXvSink *this;
|
||||
|
||||
if (handle == NULL || interface == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaXvSink *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &xvsink_node;
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
|
@ -565,6 +558,8 @@ xv_sink_init (const SpaHandleFactory *factory,
|
|||
handle->get_interface = spa_xv_sink_get_interface;
|
||||
|
||||
this = (SpaXvSink *) handle;
|
||||
this->node = xvsink_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
this->props[1].props.prop_info = prop_info;
|
||||
this->props[1].props.set_prop = spa_props_generic_set_prop;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue