v4l2: continue work on the capture device

Remove activate and deactivate commands.
Add STEP property range type for v4l2 frame sizes later
v4l2: implement negotiation and data capture
This commit is contained in:
Wim Taymans 2016-07-06 19:43:37 +02:00
parent beedb65f00
commit a1a27328e2
17 changed files with 976 additions and 308 deletions

View file

@ -52,6 +52,7 @@ reset_alsa_sink_props (SpaALSASinkProps *props)
}
typedef struct {
bool opened;
snd_pcm_t *handle;
snd_output_t *output;
snd_pcm_sframes_t buffer_size;
@ -77,8 +78,6 @@ struct _SpaALSASink {
SpaALSASinkProps tmp_props;
SpaALSASinkProps props;
bool activated;
SpaEventCallback event_cb;
void *user_data;
@ -223,47 +222,37 @@ spa_alsa_sink_node_send_command (SpaHandle *handle,
case SPA_COMMAND_INVALID:
return SPA_RESULT_INVALID_COMMAND;
case SPA_COMMAND_ACTIVATE:
if (!this->activated) {
spa_alsa_open (this);
this->activated = true;
}
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_ACTIVATED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_DEACTIVATE:
if (this->activated) {
spa_alsa_close (this);
this->activated = false;
}
if (this->event_cb) {
SpaEvent event;
event.refcount = 1;
event.notify = NULL;
event.type = SPA_EVENT_TYPE_DEACTIVATED;
event.port_id = -1;
event.data = NULL;
event.size = 0;
this->event_cb (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_START:
spa_alsa_start (this);
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 (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_STOP:
spa_alsa_stop (this);
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 (handle, &event, this->user_data);
}
break;
case SPA_COMMAND_FLUSH:
case SPA_COMMAND_DRAIN:
@ -375,7 +364,7 @@ spa_alsa_sink_node_enum_port_formats (SpaHandle *handle,
static SpaResult
spa_alsa_sink_node_set_port_format (SpaHandle *handle,
uint32_t port_id,
int test_only,
bool test_only,
const SpaFormat *format)
{
SpaALSASink *this = (SpaALSASink *) handle;

View file

@ -310,6 +310,9 @@ spa_alsa_open (SpaALSASink *this)
SpaALSAState *state = &this->state;
int err;
if (state->opened)
return 0;
CHECK (snd_output_stdio_attach (&state->output, stdout, 0), "attach failed");
printf ("Playback device is '%s'\n", this->props.device);
@ -321,15 +324,36 @@ spa_alsa_open (SpaALSASink *this)
SND_PCM_NO_AUTO_CHANNELS |
SND_PCM_NO_AUTO_FORMAT), "open failed");
state->opened = true;
return 0;
}
static int
spa_alsa_close (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err = 0;
if (!state->opened)
return 0;
CHECK (snd_pcm_close (state->handle), "close failed");
state->opened = false;
return err;
}
static int
spa_alsa_start (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err;
if (spa_alsa_open (this) < 0)
return -1;
CHECK (set_hwparams (this), "hwparams");
CHECK (set_swparams (this), "swparams");
@ -352,16 +376,7 @@ spa_alsa_stop (SpaALSASink *this)
state->running = false;
pthread_join (state->thread, NULL);
}
spa_alsa_close (this);
return 0;
}
static int
spa_alsa_close (SpaALSASink *this)
{
SpaALSAState *state = &this->state;
int err = 0;
CHECK (snd_pcm_close (state->handle), "close failed");
return err;
}