Make events and command specific to the node
Remove some unused code
Improve state changes
Use easier fixate by just taking the element default value
Fix reuse buffer in the proxy
This commit is contained in:
Wim Taymans 2016-09-06 16:43:37 +02:00
parent ac3cd24d5c
commit 8ada6736c0
29 changed files with 686 additions and 708 deletions

View file

@ -123,12 +123,30 @@ struct _SpaV4l2Source {
SpaV4l2SourceProps props[2];
SpaEventCallback event_cb;
SpaNodeEventCallback event_cb;
void *user_data;
SpaV4l2State state[1];
};
static void
update_state (SpaV4l2Source *this, SpaNodeState state)
{
SpaNodeEvent event;
SpaNodeEventStateChange sc;
if (this->node.state == state)
return;
this->node.state = state;
event.type = SPA_NODE_EVENT_TYPE_STATE_CHANGE;
event.data = ≻
event.size = sizeof (sc);
sc.state = state;
this->event_cb (&this->node, &event, this->user_data);
}
#include "v4l2-utils.c"
enum {
@ -201,27 +219,9 @@ spa_v4l2_source_node_set_props (SpaNode *node,
return res;
}
static void
update_state (SpaV4l2Source *this, SpaNodeState state)
{
SpaEvent event;
SpaEventStateChange sc;
if (this->node.state == state)
return;
this->node.state = state;
event.type = SPA_EVENT_TYPE_STATE_CHANGE;
event.data = ≻
event.size = sizeof (sc);
sc.state = state;
this->event_cb (&this->node, &event, this->user_data);
}
static SpaResult
spa_v4l2_source_node_send_command (SpaNode *node,
SpaCommand *command)
spa_v4l2_source_node_send_command (SpaNode *node,
SpaNodeCommand *command)
{
SpaV4l2Source *this;
SpaResult res;
@ -232,10 +232,10 @@ spa_v4l2_source_node_send_command (SpaNode *node,
this = (SpaV4l2Source *) node->handle;
switch (command->type) {
case SPA_COMMAND_INVALID:
case SPA_NODE_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_START:
case SPA_NODE_COMMAND_START:
{
SpaV4l2State *state = &this->state[0];
@ -248,10 +248,9 @@ spa_v4l2_source_node_send_command (SpaNode *node,
if ((res = spa_v4l2_start (this)) < 0)
return res;
update_state (this, SPA_NODE_STATE_STREAMING);
break;
}
case SPA_COMMAND_PAUSE:
case SPA_NODE_COMMAND_PAUSE:
{
SpaV4l2State *state = &this->state[0];
@ -264,22 +263,21 @@ spa_v4l2_source_node_send_command (SpaNode *node,
if ((res = spa_v4l2_pause (this)) < 0)
return res;
update_state (this, SPA_NODE_STATE_PAUSED);
break;
}
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
case SPA_COMMAND_MARKER:
case SPA_NODE_COMMAND_FLUSH:
case SPA_NODE_COMMAND_DRAIN:
case SPA_NODE_COMMAND_MARKER:
return SPA_RESULT_NOT_IMPLEMENTED;
}
return SPA_RESULT_OK;
}
static SpaResult
spa_v4l2_source_node_set_event_callback (SpaNode *node,
SpaEventCallback event,
void *user_data)
spa_v4l2_source_node_set_event_callback (SpaNode *node,
SpaNodeEventCallback event,
void *user_data)
{
SpaV4l2Source *this;
@ -647,17 +645,17 @@ spa_v4l2_source_node_port_get_status (SpaNode *node,
}
static SpaResult
spa_v4l2_source_node_port_push_input (SpaNode *node,
unsigned int n_info,
SpaInputInfo *info)
spa_v4l2_source_node_port_push_input (SpaNode *node,
unsigned int n_info,
SpaPortInputInfo *info)
{
return SPA_RESULT_INVALID_PORT;
}
static SpaResult
spa_v4l2_source_node_port_pull_output (SpaNode *node,
unsigned int n_info,
SpaOutputInfo *info)
spa_v4l2_source_node_port_pull_output (SpaNode *node,
unsigned int n_info,
SpaPortOutputInfo *info)
{
SpaV4l2Source *this;
SpaV4l2State *state;
@ -706,9 +704,9 @@ spa_v4l2_source_node_port_pull_output (SpaNode *node,
}
static SpaResult
spa_v4l2_source_node_port_push_event (SpaNode *node,
uint32_t port_id,
SpaEvent *event)
spa_v4l2_source_node_port_push_event (SpaNode *node,
uint32_t port_id,
SpaNodeEvent *event)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}

View file

@ -450,9 +450,8 @@ again:
i = ++state->frmival.index;
}
fmt->infos[pi].n_range_values = i;
if (i == 1) {
fmt->framerate = fmt->framerates[0];
} else {
fmt->framerate = fmt->framerates[0];
if (i > 1) {
SPA_PROPS_INDEX_UNSET (&fmt->fmt.props, pi);
}
pi = ++fmt->fmt.props.n_prop_info;
@ -561,10 +560,11 @@ mmap_read (SpaV4l2Source *this)
if (xioctl (state->fd, VIDIOC_DQBUF, &buf) < 0) {
switch (errno) {
case EAGAIN:
return 0;
return SPA_RESULT_ERROR;
case EIO:
default:
perror ("VIDIOC_DQBUF");
usleep (50 * 1000);
return SPA_RESULT_ERROR;
}
}
@ -583,13 +583,13 @@ static int
v4l2_on_fd_events (SpaPollNotifyData *data)
{
SpaV4l2Source *this = data->user_data;
SpaEvent event;
SpaEventHaveOutput ho;
SpaNodeEvent event;
SpaNodeEventHaveOutput ho;
if (mmap_read (this) < 0)
return 0;
event.type = SPA_EVENT_TYPE_HAVE_OUTPUT;
event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT;
event.size = sizeof (ho);
event.data = &ho;
ho.port_id = 0;
@ -849,7 +849,7 @@ spa_v4l2_start (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state[0];
enum v4l2_buf_type type;
SpaEvent event;
SpaNodeEvent event;
if (state->started)
return SPA_RESULT_OK;
@ -859,8 +859,10 @@ spa_v4l2_start (SpaV4l2Source *this)
perror ("VIDIOC_STREAMON");
return SPA_RESULT_ERROR;
}
state->started = true;
update_state (this, SPA_NODE_STATE_STREAMING);
event.type = SPA_EVENT_TYPE_ADD_POLL;
event.type = SPA_NODE_EVENT_TYPE_ADD_POLL;
event.data = &state->poll;
event.size = sizeof (state->poll);
@ -878,8 +880,6 @@ spa_v4l2_start (SpaV4l2Source *this)
state->poll.user_data = this;
this->event_cb (&this->node, &event, this->user_data);
state->started = true;
return SPA_RESULT_OK;
}
@ -888,12 +888,12 @@ spa_v4l2_pause (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state[0];
enum v4l2_buf_type type;
SpaEvent event;
SpaNodeEvent event;
if (!state->started)
return SPA_RESULT_OK;
event.type = SPA_EVENT_TYPE_REMOVE_POLL;
event.type = SPA_NODE_EVENT_TYPE_REMOVE_POLL;
event.data = &state->poll;
event.size = sizeof (state->poll);
this->event_cb (&this->node, &event, this->user_data);
@ -905,6 +905,7 @@ spa_v4l2_pause (SpaV4l2Source *this)
perror ("VIDIOC_STREAMOFF");
return SPA_RESULT_ERROR;
}
update_state (this, SPA_NODE_STATE_PAUSED);
return SPA_RESULT_OK;
}