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

v4l2: inline OpenVideo()

parent c0a980e6
......@@ -28,11 +28,14 @@
#endif
#include "v4l2.h"
#include <vlc_access.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <vlc_access.h>
#include <vlc_fs.h>
static block_t *AccessRead( access_t * );
static ssize_t AccessReadStream( access_t *, uint8_t *, size_t );
static int AccessControl( access_t *, int, va_list );
......@@ -49,13 +52,36 @@ int AccessOpen( vlc_object_t *obj )
access->p_sys = (access_sys_t *)sys;
ParseMRL( obj, access->psz_location );
sys->i_fd = OpenVideo( obj, sys, false );
if( sys->i_fd == -1 )
char *path = var_InheritString (obj, CFG_PREFIX"dev");
if (unlikely(path == NULL))
goto error; /* probably OOM */
msg_Dbg (obj, "opening device '%s'", path);
int rawfd = vlc_open (path, O_RDWR);
if (rawfd == -1)
{
msg_Err (obj, "cannot open device '%s': %m", path);
free (path);
goto error;
}
free (path);
int fd = v4l2_fd_open (rawfd, 0);
if (fd == -1)
{
msg_Warn (obj, "cannot initialize user-space library: %m");
/* fallback to direct kernel mode anyway */
fd = rawfd;
}
if (InitVideo (obj, fd, sys, false))
{
free( sys );
return VLC_EGENERIC;
v4l2_close (fd);
goto error;
}
sys->i_fd = fd;
if( sys->io == IO_METHOD_READ )
access->pf_read = AccessReadStream;
else
......@@ -63,6 +89,9 @@ int AccessOpen( vlc_object_t *obj )
access->pf_seek = NULL;
access->pf_control = AccessControl;
return VLC_SUCCESS;
error:
free (sys);
return VLC_EGENERIC;
}
void AccessClose( vlc_object_t *obj )
......
......@@ -28,37 +28,67 @@
#endif
#include "v4l2.h"
#include <vlc_demux.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <poll.h>
#include <vlc_demux.h>
#include <vlc_fs.h>
static int DemuxControl( demux_t *, int, va_list );
static int Demux( demux_t * );
int DemuxOpen( vlc_object_t *obj )
{
demux_t *demux = (demux_t *)obj;
demux_sys_t *sys = calloc( 1, sizeof( demux_sys_t ) );
if( unlikely(sys == NULL) )
return VLC_ENOMEM;
demux->p_sys = sys;
ParseMRL( obj, demux->psz_location );
sys->i_fd = OpenVideo( obj, sys, true );
if( sys->i_fd == -1 )
char *path = var_InheritString (obj, CFG_PREFIX"dev");
if (unlikely(path == NULL))
goto error; /* probably OOM */
msg_Dbg (obj, "opening device '%s'", path);
int rawfd = vlc_open (path, O_RDWR);
if (rawfd == -1)
{
free( sys );
return VLC_EGENERIC;
msg_Err (obj, "cannot open device '%s': %m", path);
free (path);
goto error;
}
free (path);
int fd = v4l2_fd_open (rawfd, 0);
if (fd == -1)
{
msg_Warn (obj, "cannot initialize user-space library: %m");
/* fallback to direct kernel mode anyway */
fd = rawfd;
}
if (InitVideo (obj, fd, sys, true))
{
v4l2_close (fd);
goto error;
}
sys->i_fd = fd;
demux->pf_demux = Demux;
demux->pf_control = DemuxControl;
demux->info.i_update = 0;
demux->info.i_title = 0;
demux->info.i_seekpoint = 0;
return VLC_SUCCESS;
error:
free (sys);
return VLC_EGENERIC;
}
void DemuxClose( vlc_object_t *obj )
......
......@@ -112,8 +112,9 @@ struct buffer_t
/* video.c */
void ParseMRL(vlc_object_t *, const char *);
int OpenVideo(vlc_object_t *, demux_sys_t *, bool);
int SetupAudio (vlc_object_t *, int, const struct v4l2_input *);
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 *);
......
......@@ -39,13 +39,11 @@
#include "v4l2.h"
#include <vlc_plugin.h>
#include <vlc_fs.h>
#include <vlc_demux.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <poll.h>
......@@ -776,46 +774,8 @@ static bool IsPixelFormatSupported( struct v4l2_fmtdesc *codecs, size_t n,
}
static int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
bool b_demux );
/**
* Opens and sets up a video device
* \return file descriptor or -1 on error
*/
int OpenVideo( vlc_object_t *obj, demux_sys_t *sys, bool b_demux )
{
char *path = var_InheritString( obj, CFG_PREFIX"dev" );
if( unlikely(path == NULL) )
return -1; /* probably OOM */
msg_Dbg( obj, "opening device '%s'", path );
int fd = vlc_open( path, O_RDWR );
if( fd == -1 )
{
msg_Err( obj, "cannot open device '%s': %m", path );
free( path );
return -1;
}
free( path );
int libfd = v4l2_fd_open( fd, 0 );
if( libfd == -1 )
goto error;
libfd = fd;
if( InitVideo( obj, fd, sys, b_demux ) )
goto error;
return fd;
error:
close( fd );
return -1;
}
static int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
bool b_demux )
int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
bool b_demux )
{
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
......
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