[vlc-commits] v4l2: inline OpenVideo()
Rémi Denis-Courmont
git at videolan.org
Thu Mar 15 18:21:19 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Mar 15 18:24:17 2012 +0200| [77cd42306ea9a3b0b9532c85f89a5d8afaf9c79e] | committer: Rémi Denis-Courmont
v4l2: inline OpenVideo()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=77cd42306ea9a3b0b9532c85f89a5d8afaf9c79e
---
modules/access/v4l2/access.c | 39 ++++++++++++++++++++++++++++++++----
modules/access/v4l2/demux.c | 40 +++++++++++++++++++++++++++++++++----
modules/access/v4l2/v4l2.h | 3 +-
modules/access/v4l2/video.c | 44 +----------------------------------------
4 files changed, 73 insertions(+), 53 deletions(-)
diff --git a/modules/access/v4l2/access.c b/modules/access/v4l2/access.c
index e2e1863..e0c9c68 100644
--- a/modules/access/v4l2/access.c
+++ b/modules/access/v4l2/access.c
@@ -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 )
diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index c5bf6c5..71387fd 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -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 )
diff --git a/modules/access/v4l2/v4l2.h b/modules/access/v4l2/v4l2.h
index 705b7f4..903a348 100644
--- a/modules/access/v4l2/v4l2.h
+++ b/modules/access/v4l2/v4l2.h
@@ -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 *);
diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
index 7e24c0d..83437a6 100644
--- a/modules/access/v4l2/video.c
+++ b/modules/access/v4l2/video.c
@@ -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;
More information about the vlc-commits
mailing list