Commit 58875422 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

v4l2: duplicate InitVideo() for access and access_demux

There is not that much common code left for the access case, except for
debug messages. The resulting code is a lot easier to read IMHO.
Also I have no way to test the access plugin, so lets split it where it
will not get more broken.
parent edd6b80c
......@@ -27,6 +27,7 @@
# include "config.h"
#endif
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
......@@ -40,6 +41,7 @@
static block_t *AccessRead( access_t * );
static ssize_t AccessReadStream( access_t *, uint8_t *, size_t );
static int AccessControl( access_t *, int, va_list );
static int InitVideo(access_t *, int);
int AccessOpen( vlc_object_t *obj )
{
......@@ -76,7 +78,7 @@ int AccessOpen( vlc_object_t *obj )
fd = rawfd;
}
if (InitVideo (obj, fd, sys, false))
if (InitVideo (access, fd))
{
v4l2_close (fd);
goto error;
......@@ -95,6 +97,127 @@ error:
return VLC_EGENERIC;
}
int InitVideo (access_t *access, int fd)
{
demux_sys_t *sys = (demux_sys_t *)access->p_sys;
unsigned int i_min;
enum v4l2_buf_type buf_type;
/* Get device capabilites */
struct v4l2_capability cap;
if (v4l2_ioctl (fd, VIDIOC_QUERYCAP, &cap) < 0)
{
msg_Err (access, "cannot get device capabilities: %m");
return -1;
}
msg_Dbg (access, "device %s using driver %s (version %u.%u.%u) on %s",
cap.card, cap.driver, (cap.version >> 16) & 0xFF,
(cap.version >> 8) & 0xFF, cap.version & 0xFF, cap.bus_info);
msg_Dbg (access, "the device has the capabilities: 0x%08X",
cap.capabilities);
msg_Dbg (access, " (%c) Video Capture, (%c) Audio, (%c) Tuner, (%c) Radio",
(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ? 'X':' '),
(cap.capabilities & V4L2_CAP_AUDIO ? 'X':' '),
(cap.capabilities & V4L2_CAP_TUNER ? 'X':' '),
(cap.capabilities & V4L2_CAP_RADIO ? 'X':' '));
msg_Dbg (access, " (%c) Read/Write, (%c) Streaming, (%c) Asynchronous",
(cap.capabilities & V4L2_CAP_READWRITE ? 'X':' '),
(cap.capabilities & V4L2_CAP_STREAMING ? 'X':' '),
(cap.capabilities & V4L2_CAP_ASYNCIO ? 'X':' '));
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
msg_Err (access, "not a video capture device");
return -1;
}
if (cap.capabilities & V4L2_CAP_STREAMING)
sys->io = IO_METHOD_MMAP;
else if (cap.capabilities & V4L2_CAP_READWRITE)
sys->io = IO_METHOD_READ;
else
{
msg_Err (access, "no supported I/O method");
return -1;
}
if (SetupInput (VLC_OBJECT(access), fd))
return -1;
sys->controls = ControlsInit (VLC_OBJECT(access), fd);
/* Try and find default resolution if not specified */
struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
if (v4l2_ioctl (fd, VIDIOC_G_FMT, &fmt) < 0)
{
msg_Err (access, "cannot get default format: %m");
return -1;
}
/* Print extra info */
msg_Dbg (access, "%d bytes maximum for complete image",
fmt.fmt.pix.sizeimage );
/* Check interlacing */
switch (fmt.fmt.pix.field)
{
case V4L2_FIELD_INTERLACED:
msg_Dbg (access, "Interlacing setting: interleaved");
/*if (NTSC)
sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
else*/
sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
break;
case V4L2_FIELD_INTERLACED_TB:
msg_Dbg (access, "Interlacing setting: interleaved top bottom" );
sys->i_block_flags = BLOCK_FLAG_TOP_FIELD_FIRST;
break;
case V4L2_FIELD_INTERLACED_BT:
msg_Dbg (access, "Interlacing setting: interleaved bottom top" );
sys->i_block_flags = BLOCK_FLAG_BOTTOM_FIELD_FIRST;
break;
default:
break;
}
/* Init I/O method */
switch (sys->io)
{
case IO_METHOD_READ:
sys->blocksize = fmt.fmt.pix.sizeimage;
break;
case IO_METHOD_MMAP:
if (InitMmap (VLC_OBJECT(access), sys, fd))
return -1;
for (unsigned int i = 0; i < sys->i_nbuffers; i++)
{
struct v4l2_buffer buf = {
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
.memory = V4L2_MEMORY_MMAP,
.index = i,
};
if (v4l2_ioctl (fd, VIDIOC_QBUF, &buf) < 0)
{
msg_Err (access, "cannot queue buffer: %m");
return -1;
}
}
buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (v4l2_ioctl (fd, VIDIOC_STREAMON, &buf_type) < 0)
{
msg_Err (access, "cannot start streaming: %m" );
return -1;
}
break;
default:
assert (0);
}
return 0;
}
void AccessClose( vlc_object_t *obj )
{
access_t *access = (access_t *)obj;
......
This diff is collapsed.
......@@ -110,8 +110,9 @@ struct buffer_t
/* video.c */
void ParseMRL(vlc_object_t *, const char *);
int SetupInput (vlc_object_t *, int fd);
int InitMmap (vlc_object_t *, demux_sys_t *, int);
block_t* GrabVideo(vlc_object_t *, demux_sys_t *);
int InitVideo(vlc_object_t *, int fd, demux_sys_t *, bool demux);
/* demux.c */
int DemuxOpen(vlc_object_t *);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment