video: add video format

start working on v4l2 source
This commit is contained in:
Wim Taymans 2016-07-05 17:58:34 +02:00
parent 3c029cba53
commit beedb65f00
25 changed files with 1878 additions and 43 deletions

View file

@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <getopt.h>
#include <sys/time.h>
#include <math.h>
#define CHECK(s,msg) if ((err = (s)) < 0) { printf (msg ": %s\n", snd_strerror(err)); return err; }
static int
spa_v4l2_open (SpaV4l2Source *this)
{
struct stat st;
fprintf (stderr, "Playback device is '%s'\n", this->props.device);
if (stat (this->props.device, &st) < 0) {
fprintf(stderr, "Cannot identify '%s': %d, %s\n",
this->props.device, errno, strerror (errno));
return -1;
}
if (!S_ISCHR (st.st_mode)) {
fprintf(stderr, "%s is no device\n", this->props.device);
return -1;
}
this->state.fd = open (this->props.device, O_RDWR | O_NONBLOCK, 0);
if (this->state.fd == -1) {
fprintf(stderr, "Cannot open '%s': %d, %s\n",
this->props.device, errno, strerror (errno));
return -1;
}
return 0;
}
static int
spa_v4l2_close (SpaV4l2Source *this)
{
if (close(this->state.fd))
fprintf(stderr, "Cannot close %d, %s\n",
errno, strerror (errno));
this->state.fd = -1;
return 0;
}
static void *
v4l2_loop (void *user_data)
{
return NULL;
}
static int
spa_v4l2_start (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state;
int err;
state->running = true;
if ((err = pthread_create (&state->thread, NULL, v4l2_loop, this)) != 0) {
printf ("can't create thread: %d", err);
state->running = false;
}
return err;
}
static int
spa_v4l2_stop (SpaV4l2Source *this)
{
SpaV4l2State *state = &this->state;
if (state->running) {
state->running = false;
pthread_join (state->thread, NULL);
}
return 0;
}