mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
v4l2: add support for buffer import
Add support for buffer import Rename some methods
This commit is contained in:
parent
5fa334a89b
commit
c5a31acf8c
13 changed files with 585 additions and 240 deletions
|
|
@ -50,27 +50,34 @@ typedef struct _V4l2Buffer V4l2Buffer;
|
|||
|
||||
struct _V4l2Buffer {
|
||||
SpaBuffer buffer;
|
||||
SpaMeta meta[1];
|
||||
SpaMeta metas[1];
|
||||
SpaMetaHeader header;
|
||||
SpaData data[1];
|
||||
V4l2Buffer *next;
|
||||
uint32_t index;
|
||||
SpaData datas[1];
|
||||
SpaV4l2Source *source;
|
||||
bool outstanding;
|
||||
SpaBuffer *imported;
|
||||
struct v4l2_buffer v4l2_buffer;
|
||||
V4l2Buffer *next;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
SpaVideoRawFormat raw_format[2];
|
||||
SpaFormat *current_format;
|
||||
bool opened;
|
||||
bool have_buffers;
|
||||
int fd;
|
||||
struct v4l2_capability cap;
|
||||
struct v4l2_format fmt;
|
||||
enum v4l2_buf_type type;
|
||||
enum v4l2_memory memtype;
|
||||
struct v4l2_requestbuffers reqbuf;
|
||||
V4l2Buffer buffers[MAX_BUFFERS];
|
||||
V4l2Buffer *ready;
|
||||
uint32_t ready_count;
|
||||
SpaPollFd fds[1];
|
||||
SpaPollItem poll;
|
||||
SpaPortInfo info;
|
||||
SpaPortStatus status;
|
||||
} SpaV4l2State;
|
||||
|
||||
struct _SpaV4l2Source {
|
||||
|
|
@ -81,13 +88,7 @@ struct _SpaV4l2Source {
|
|||
SpaEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
SpaVideoRawFormat raw_format[2];
|
||||
SpaFormat *current_format;
|
||||
|
||||
SpaV4l2State state;
|
||||
|
||||
SpaPortInfo info;
|
||||
SpaPortStatus status;
|
||||
SpaV4l2State state[1];
|
||||
};
|
||||
|
||||
#include "v4l2-utils.c"
|
||||
|
|
@ -291,12 +292,13 @@ spa_v4l2_source_node_remove_port (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_enum_port_formats (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_enum_formats (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
unsigned int index,
|
||||
SpaFormat **format)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2State *state;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -304,25 +306,28 @@ spa_v4l2_source_node_enum_port_formats (SpaHandle *handle,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
state = &this->state[port_id];
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
spa_video_raw_format_init (&this->raw_format[0]);
|
||||
spa_video_raw_format_init (&state->raw_format[0]);
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_ENUM_END;
|
||||
}
|
||||
*format = &this->raw_format[0].format;
|
||||
*format = &state->raw_format[0].format;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_set_port_format (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_set_format (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
bool test_only,
|
||||
const SpaFormat *format)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2State *state;
|
||||
SpaResult res;
|
||||
SpaFormat *f, *tf;
|
||||
size_t fs;
|
||||
|
|
@ -333,18 +338,20 @@ spa_v4l2_source_node_set_port_format (SpaHandle *handle,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
state = &this->state[port_id];
|
||||
|
||||
if (format == NULL) {
|
||||
this->current_format = NULL;
|
||||
state->current_format = NULL;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
|
||||
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
|
||||
if ((res = spa_video_raw_format_parse (format, &this->raw_format[0]) < 0))
|
||||
if ((res = spa_video_raw_format_parse (format, &state->raw_format[0]) < 0))
|
||||
return res;
|
||||
|
||||
f = &this->raw_format[0].format;
|
||||
tf = &this->raw_format[1].format;
|
||||
f = &state->raw_format[0].format;
|
||||
tf = &state->raw_format[1].format;
|
||||
fs = sizeof (SpaVideoRawFormat);
|
||||
} else
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
|
@ -356,18 +363,19 @@ spa_v4l2_source_node_set_port_format (SpaHandle *handle,
|
|||
|
||||
if (!test_only) {
|
||||
memcpy (tf, f, fs);
|
||||
this->current_format = tf;
|
||||
state->current_format = tf;
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_port_format (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_format (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
const SpaFormat **format)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
SpaV4l2State *state;
|
||||
|
||||
if (handle == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -375,16 +383,18 @@ spa_v4l2_source_node_get_port_format (SpaHandle *handle,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (this->current_format == NULL)
|
||||
state = &this->state[port_id];
|
||||
|
||||
if (state->current_format == NULL)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
*format = this->current_format;
|
||||
*format = state->current_format;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_port_info (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_info (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
const SpaPortInfo **info)
|
||||
{
|
||||
|
|
@ -396,13 +406,13 @@ spa_v4l2_source_node_get_port_info (SpaHandle *handle,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*info = &this->info;
|
||||
*info = &this->state[port_id].info;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_port_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_props (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
SpaProps **props)
|
||||
{
|
||||
|
|
@ -410,7 +420,7 @@ spa_v4l2_source_node_get_port_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_set_port_props (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_set_props (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
const SpaProps *props)
|
||||
{
|
||||
|
|
@ -418,7 +428,7 @@ spa_v4l2_source_node_set_port_props (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_get_port_status (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_get_status (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
|
|
@ -430,13 +440,42 @@ spa_v4l2_source_node_get_port_status (SpaHandle *handle,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*status = &this->status;
|
||||
*status = &this->state[port_id].status;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_push_port_input (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_use_buffers (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
SpaBuffer *buffers,
|
||||
uint32_t n_buffers)
|
||||
{
|
||||
SpaV4l2Source *this = (SpaV4l2Source *) handle;
|
||||
|
||||
if (handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
spa_v4l2_import_buffers (this, buffers, n_buffers);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_alloc_buffers (SpaHandle *handle,
|
||||
uint32_t port_id,
|
||||
SpaBuffer **buffers,
|
||||
uint32_t *n_buffers)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_port_push_input (SpaHandle *handle,
|
||||
unsigned int n_info,
|
||||
SpaInputInfo *info)
|
||||
{
|
||||
|
|
@ -444,7 +483,7 @@ spa_v4l2_source_node_push_port_input (SpaHandle *handle,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_source_node_pull_port_output (SpaHandle *handle,
|
||||
spa_v4l2_source_node_port_pull_output (SpaHandle *handle,
|
||||
unsigned int n_info,
|
||||
SpaOutputInfo *info)
|
||||
{
|
||||
|
|
@ -456,7 +495,6 @@ spa_v4l2_source_node_pull_port_output (SpaHandle *handle,
|
|||
if (handle == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
state = &this->state;
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
V4l2Buffer *b;
|
||||
|
|
@ -466,7 +504,9 @@ spa_v4l2_source_node_pull_port_output (SpaHandle *handle,
|
|||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (this->current_format == NULL) {
|
||||
state = &this->state[info[i].port_id];
|
||||
|
||||
if (state->current_format == NULL) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
|
|
@ -502,15 +542,17 @@ static const SpaNode v4l2source_node = {
|
|||
spa_v4l2_source_node_get_port_ids,
|
||||
spa_v4l2_source_node_add_port,
|
||||
spa_v4l2_source_node_remove_port,
|
||||
spa_v4l2_source_node_enum_port_formats,
|
||||
spa_v4l2_source_node_set_port_format,
|
||||
spa_v4l2_source_node_get_port_format,
|
||||
spa_v4l2_source_node_get_port_info,
|
||||
spa_v4l2_source_node_get_port_props,
|
||||
spa_v4l2_source_node_set_port_props,
|
||||
spa_v4l2_source_node_get_port_status,
|
||||
spa_v4l2_source_node_push_port_input,
|
||||
spa_v4l2_source_node_pull_port_output,
|
||||
spa_v4l2_source_node_port_enum_formats,
|
||||
spa_v4l2_source_node_port_set_format,
|
||||
spa_v4l2_source_node_port_get_format,
|
||||
spa_v4l2_source_node_port_get_info,
|
||||
spa_v4l2_source_node_port_get_props,
|
||||
spa_v4l2_source_node_port_set_props,
|
||||
spa_v4l2_source_node_port_use_buffers,
|
||||
spa_v4l2_source_node_port_alloc_buffers,
|
||||
spa_v4l2_source_node_port_get_status,
|
||||
spa_v4l2_source_node_port_push_input,
|
||||
spa_v4l2_source_node_port_pull_output,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -547,7 +589,7 @@ spa_v4l2_source_new (void)
|
|||
this->props[1].props.get_prop = spa_props_generic_get_prop;
|
||||
reset_v4l2_source_props (&this->props[1]);
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_NONE;
|
||||
this->status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
||||
this->state[0].info.flags = SPA_PORT_INFO_FLAG_NONE;
|
||||
this->state[0].status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
||||
return handle;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ xioctl (int fd, int request, void *arg)
|
|||
static int
|
||||
spa_v4l2_open (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
struct stat st;
|
||||
SpaV4l2SourceProps *props = &this->props[1];
|
||||
|
||||
|
|
@ -260,12 +260,15 @@ video_format_to_fourcc (SpaVideoFormat format)
|
|||
static int
|
||||
spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
int cmd = try_only ? VIDIOC_TRY_FMT : VIDIOC_S_FMT;
|
||||
struct v4l2_format reqfmt, fmt;
|
||||
struct v4l2_streamparm streamparm;
|
||||
|
||||
CLEAR (fmt);
|
||||
CLEAR (streamparm);
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
|
||||
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
|
||||
|
|
@ -275,8 +278,13 @@ spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
|
|||
fmt.fmt.pix.width = f->info.width;
|
||||
fmt.fmt.pix.height = f->info.height;
|
||||
fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
||||
fprintf (stderr, "set %08x %dx%d\n", fmt.fmt.pix.pixelformat,
|
||||
fmt.fmt.pix.width, fmt.fmt.pix.height);
|
||||
streamparm.parm.capture.timeperframe.numerator = f->info.framerate.denom;
|
||||
streamparm.parm.capture.timeperframe.denominator = f->info.framerate.num;
|
||||
|
||||
fprintf (stderr, "set %08x %dx%d %d/%d\n", fmt.fmt.pix.pixelformat,
|
||||
fmt.fmt.pix.width, fmt.fmt.pix.height, f->info.framerate.denom,
|
||||
f->info.framerate.num);
|
||||
|
||||
} else
|
||||
return -1;
|
||||
} else
|
||||
|
|
@ -292,6 +300,10 @@ spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* some cheap USB cam's won't accept any change */
|
||||
if (xioctl (state->fd, VIDIOC_S_PARM, &streamparm) < 0)
|
||||
perror ("VIDIOC_S_PARM");
|
||||
|
||||
if (reqfmt.fmt.pix.pixelformat != fmt.fmt.pix.pixelformat ||
|
||||
reqfmt.fmt.pix.width != fmt.fmt.pix.width ||
|
||||
reqfmt.fmt.pix.height != fmt.fmt.pix.height)
|
||||
|
|
@ -301,6 +313,15 @@ spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
|
|||
return 0;
|
||||
|
||||
state->fmt = fmt;
|
||||
state->info.flags = SPA_PORT_INFO_FLAG_CAN_GIVE_BUFFER;
|
||||
state->info.minsize = fmt.fmt.pix.sizeimage;
|
||||
state->info.stride = fmt.fmt.pix.bytesperline;
|
||||
state->info.min_buffers = 2;
|
||||
state->info.max_buffers = MAX_BUFFERS;
|
||||
state->info.align = 16;
|
||||
state->info.maxbuffering = -1;
|
||||
state->info.latency = -1;
|
||||
state->info.features = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -308,7 +329,7 @@ spa_v4l2_set_format (SpaV4l2Source *this, SpaFormat *format, bool try_only)
|
|||
static int
|
||||
spa_v4l2_close (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
|
||||
if (!state->opened)
|
||||
return 0;
|
||||
|
|
@ -318,6 +339,7 @@ spa_v4l2_close (SpaV4l2Source *this)
|
|||
|
||||
state->fd = -1;
|
||||
state->opened = false;
|
||||
state->have_buffers = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -325,13 +347,13 @@ spa_v4l2_close (SpaV4l2Source *this)
|
|||
static int
|
||||
mmap_read (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
struct v4l2_buffer buf;
|
||||
V4l2Buffer *b;
|
||||
|
||||
CLEAR(buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_MMAP;
|
||||
buf.memory = state->memtype;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_DQBUF, &buf) < 0) {
|
||||
switch (errno) {
|
||||
|
|
@ -376,32 +398,93 @@ v4l2_buffer_free (void *data)
|
|||
{
|
||||
V4l2Buffer *b = (V4l2Buffer *) data;
|
||||
SpaV4l2Source *this = b->source;
|
||||
SpaV4l2State *state = &this->state;
|
||||
struct v4l2_buffer buf;
|
||||
|
||||
CLEAR (buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_MMAP;
|
||||
buf.index = b->index;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
|
||||
b->buffer.refcount = 1;
|
||||
b->outstanding = false;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_QBUF, &buf) < 0) {
|
||||
if (xioctl (state->fd, VIDIOC_QBUF, &b->v4l2_buffer) < 0) {
|
||||
perror ("VIDIOC_QBUF");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_init (SpaV4l2Source *this)
|
||||
spa_v4l2_import_buffers (SpaV4l2Source *this, SpaBuffer *buffers, uint32_t n_buffers)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
struct v4l2_requestbuffers reqbuf;
|
||||
int i;
|
||||
|
||||
state->memtype = V4L2_MEMORY_USERPTR;
|
||||
|
||||
CLEAR(reqbuf);
|
||||
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
reqbuf.memory = V4L2_MEMORY_MMAP;
|
||||
reqbuf.memory = state->memtype;
|
||||
reqbuf.count = n_buffers;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
|
||||
perror ("VIDIOC_REQBUFS");
|
||||
return -1;
|
||||
}
|
||||
fprintf (stderr, "got %d buffers\n", reqbuf.count);
|
||||
if (reqbuf.count < 2) {
|
||||
fprintf (stderr, "can't allocate enough buffers\n");
|
||||
return -1;
|
||||
}
|
||||
state->reqbuf = reqbuf;
|
||||
|
||||
for (i = 0; i < reqbuf.count; i++) {
|
||||
V4l2Buffer *b;
|
||||
|
||||
b = &state->buffers[i];
|
||||
b->source = this;
|
||||
b->buffer.refcount = 0;
|
||||
b->buffer.notify = v4l2_buffer_free;
|
||||
b->buffer.size = buffers[i].size;
|
||||
b->buffer.n_metas = 1;
|
||||
b->buffer.metas = b->metas;
|
||||
b->buffer.n_datas = 1;
|
||||
b->buffer.datas = b->datas;
|
||||
|
||||
b->header.flags = 0;
|
||||
b->header.seq = 0;
|
||||
b->header.pts = 0;
|
||||
b->header.dts_offset = 0;
|
||||
|
||||
b->metas[0].type = SPA_META_TYPE_HEADER;
|
||||
b->metas[0].data = &b->header;
|
||||
b->metas[0].size = sizeof (b->header);
|
||||
|
||||
b->datas[0] = buffers[i].datas[0];
|
||||
b->imported = &buffers[i];
|
||||
b->outstanding = true;
|
||||
|
||||
CLEAR (b->v4l2_buffer);
|
||||
b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
b->v4l2_buffer.memory = state->memtype;
|
||||
b->v4l2_buffer.index = i;
|
||||
b->v4l2_buffer.m.userptr = (unsigned long) b->datas[0].data;
|
||||
b->v4l2_buffer.length = b->datas[0].size;
|
||||
|
||||
v4l2_buffer_free (b);
|
||||
}
|
||||
state->have_buffers = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mmap_init (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
struct v4l2_requestbuffers reqbuf;
|
||||
int i;
|
||||
|
||||
state->memtype = V4L2_MEMORY_MMAP;
|
||||
|
||||
CLEAR(reqbuf);
|
||||
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
reqbuf.memory = state->memtype;
|
||||
reqbuf.count = MAX_BUFFERS;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
|
||||
|
|
@ -423,7 +506,7 @@ mmap_init (SpaV4l2Source *this)
|
|||
|
||||
CLEAR (buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_MMAP;
|
||||
buf.memory = state->memtype;
|
||||
buf.index = i;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_QUERYBUF, &buf) < 0) {
|
||||
|
|
@ -432,54 +515,51 @@ mmap_init (SpaV4l2Source *this)
|
|||
}
|
||||
|
||||
b = &state->buffers[i];
|
||||
b->index = i;
|
||||
b->source = this;
|
||||
b->buffer.refcount = 1;
|
||||
b->buffer.refcount = 0;
|
||||
b->buffer.notify = v4l2_buffer_free;
|
||||
b->buffer.size = buf.length;
|
||||
b->buffer.n_metas = 1;
|
||||
b->buffer.metas = b->meta;
|
||||
b->buffer.metas = b->metas;
|
||||
b->buffer.n_datas = 1;
|
||||
b->buffer.datas = b->data;
|
||||
b->buffer.datas = b->datas;
|
||||
|
||||
b->header.flags = 0;
|
||||
b->header.seq = 0;
|
||||
b->header.pts = 0;
|
||||
b->header.dts_offset = 0;
|
||||
|
||||
b->meta[0].type = SPA_META_TYPE_HEADER;
|
||||
b->meta[0].data = &b->header;
|
||||
b->meta[0].size = sizeof (b->header);
|
||||
b->metas[0].type = SPA_META_TYPE_HEADER;
|
||||
b->metas[0].data = &b->header;
|
||||
b->metas[0].size = sizeof (b->header);
|
||||
|
||||
b->data[0].type = SPA_DATA_TYPE_MEMPTR;
|
||||
b->data[0].data = mmap (NULL,
|
||||
buf.length,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
state->fd,
|
||||
buf.m.offset);
|
||||
b->data[0].offset = 0;
|
||||
b->data[0].size = buf.length;
|
||||
b->data[0].stride = state->fmt.fmt.pix.bytesperline;
|
||||
b->datas[0].type = SPA_DATA_TYPE_MEMPTR;
|
||||
b->datas[0].data = mmap (NULL,
|
||||
buf.length,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
state->fd,
|
||||
buf.m.offset);
|
||||
b->datas[0].offset = 0;
|
||||
b->datas[0].size = buf.length;
|
||||
b->datas[0].stride = state->fmt.fmt.pix.bytesperline;
|
||||
b->imported = NULL;
|
||||
b->outstanding = true;
|
||||
|
||||
if (b->data[0].data == MAP_FAILED) {
|
||||
if (b->datas[0].data == MAP_FAILED) {
|
||||
perror ("mmap");
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->reqbuf.count; ++i) {
|
||||
struct v4l2_buffer buf;
|
||||
|
||||
CLEAR (buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_MMAP;
|
||||
buf.index = i;
|
||||
CLEAR (b->v4l2_buffer);
|
||||
b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
b->v4l2_buffer.memory = state->memtype;
|
||||
b->v4l2_buffer.index = i;
|
||||
|
||||
if (xioctl (state->fd, VIDIOC_QBUF, &buf) < 0) {
|
||||
perror ("VIDIOC_QBUF");
|
||||
return -1;
|
||||
}
|
||||
v4l2_buffer_free (b);
|
||||
}
|
||||
state->have_buffers = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -498,22 +578,24 @@ read_init (SpaV4l2Source *this)
|
|||
static int
|
||||
spa_v4l2_start (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
enum v4l2_buf_type type;
|
||||
SpaEvent event;
|
||||
|
||||
if (spa_v4l2_open (this) < 0)
|
||||
return -1;
|
||||
|
||||
if (state->cap.capabilities & V4L2_CAP_STREAMING) {
|
||||
if (mmap_init (this) < 0)
|
||||
if (userptr_init (this) < 0)
|
||||
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 if (state->cap.capabilities & V4L2_CAP_READWRITE) {
|
||||
if (read_init (this) < 0)
|
||||
} else
|
||||
return -1;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
event.refcount = 1;
|
||||
event.notify = NULL;
|
||||
|
|
@ -545,7 +627,7 @@ spa_v4l2_start (SpaV4l2Source *this)
|
|||
static int
|
||||
spa_v4l2_stop (SpaV4l2Source *this)
|
||||
{
|
||||
SpaV4l2State *state = &this->state;
|
||||
SpaV4l2State *state = &this->state[0];
|
||||
enum v4l2_buf_type type;
|
||||
SpaEvent event;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue