[vlc-devel] [PATCH] v4l2: split declarations
Francois Cartegnie
fcvlcdev at free.fr
Fri Dec 23 19:24:24 CET 2011
---
modules/access/Modules.am | 3 +
modules/access/v4l2/access.c | 1 +
modules/access/v4l2/controls.c | 1 +
modules/access/v4l2/demux.c | 1 +
modules/access/v4l2/v4l2.h | 24 +-----
modules/access/v4l2/v4l2_common.c | 162 +++++++++++++++++++++++++++++++++++++
modules/access/v4l2/v4l2_common.h | 31 +++++++
modules/access/v4l2/v4l2_input.h | 46 +++++++++++
modules/access/v4l2/video.c | 162 ++++++-------------------------------
9 files changed, 272 insertions(+), 159 deletions(-)
create mode 100644 modules/access/v4l2/v4l2_common.c
create mode 100644 modules/access/v4l2/v4l2_common.h
create mode 100644 modules/access/v4l2/v4l2_input.h
diff --git a/modules/access/Modules.am b/modules/access/Modules.am
index bbf0c5e..9e86086 100644
--- a/modules/access/Modules.am
+++ b/modules/access/Modules.am
@@ -161,6 +161,9 @@ libv4l2_plugin_la_SOURCES = \
v4l2/video.c \
v4l2/demux.c \
v4l2/access.c \
+ v4l2/v4l2_common.c \
+ v4l2/v4l2_common.h \
+ v4l2/v4l2_input.h \
v4l2/controls.c \
v4l2/v4l2.h
libv4l2_plugin_la_CFLAGS = $(AM_CFLAGS) $(LIBV4L2_CFLAGS)
diff --git a/modules/access/v4l2/access.c b/modules/access/v4l2/access.c
index 38348d2..df88c22 100644
--- a/modules/access/v4l2/access.c
+++ b/modules/access/v4l2/access.c
@@ -28,6 +28,7 @@
#endif
#include "v4l2.h"
+#include "v4l2_input.h"
#include <vlc_access.h>
#include <errno.h>
diff --git a/modules/access/v4l2/controls.c b/modules/access/v4l2/controls.c
index 2bfbabb..f4309a1 100644
--- a/modules/access/v4l2/controls.c
+++ b/modules/access/v4l2/controls.c
@@ -28,6 +28,7 @@
#endif
#include "v4l2.h"
+#include "v4l2_input.h"
#include <ctype.h>
#include <assert.h>
#include <sys/ioctl.h>
diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index bdbeb95..74c4076 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -28,6 +28,7 @@
#endif
#include "v4l2.h"
+#include "v4l2_input.h"
#include <vlc_demux.h>
#include <errno.h>
#include <sys/ioctl.h>
diff --git a/modules/access/v4l2/v4l2.h b/modules/access/v4l2/v4l2.h
index 8b227d1..91207e6 100644
--- a/modules/access/v4l2/v4l2.h
+++ b/modules/access/v4l2/v4l2.h
@@ -69,8 +69,6 @@
# define v4l2_munmap munmap
#endif
-#define CFG_PREFIX "v4l2-"
-
/* TODO: remove this, use callbacks */
typedef enum {
IO_METHOD_READ=1,
@@ -92,7 +90,7 @@ struct demux_sys_t
unsigned int i_nbuffers;
#define blocksize i_nbuffers /* HACK HACK */
- int i_fourcc;
+ vlc_fourcc_t i_fourcc;
uint32_t i_block_flags;
es_out_id_t *p_es;
@@ -109,23 +107,3 @@ struct buffer_t
void * start;
size_t length;
};
-
-/* video.c */
-void ParseMRL(vlc_object_t *, const char *);
-int OpenVideo(vlc_object_t *, demux_sys_t *, bool);
-block_t* GrabVideo(vlc_object_t *, demux_sys_t *);
-
-/* demux.c */
-int DemuxOpen(vlc_object_t *);
-void DemuxClose(vlc_object_t *);
-float GetAbsoluteMaxFrameRate(vlc_object_t *, int fd, uint32_t fmt);
-void GetMaxDimensions(vlc_object_t *, int fd, uint32_t fmt, float fps_min,
- uint32_t *pwidth, uint32_t *pheight);
-
-/* access.c */
-int AccessOpen(vlc_object_t *);
-void AccessClose(vlc_object_t *);
-
-/* controls.c */
-vlc_v4l2_ctrl_t *ControlsInit(vlc_object_t *, int fd);
-void ControlsDeinit(vlc_object_t *, vlc_v4l2_ctrl_t *);
diff --git a/modules/access/v4l2/v4l2_common.c b/modules/access/v4l2/v4l2_common.c
new file mode 100644
index 0000000..8ece257
--- /dev/null
+++ b/modules/access/v4l2/v4l2_common.c
@@ -0,0 +1,162 @@
+/*****************************************************************************
+ * v4l2_common.c : Video4Linux2 input module for vlc
+ *****************************************************************************
+ * Copyright (C) 2002-2011 the VideoLAN team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "v4l2_common.h"
+#include "v4l2.h"
+
+#include <vlc_fourcc.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
+static const struct
+{
+ unsigned int i_v4l2;
+ vlc_fourcc_t i_fourcc;
+ int i_rmask;
+ int i_gmask;
+ int i_bmask;
+} v4l2chroma_to_fourcc[] =
+{
+ /* Raw data types */
+ { V4L2_PIX_FMT_GREY, VLC_CODEC_GREY, 0, 0, 0 },
+ { V4L2_PIX_FMT_HI240, VLC_FOURCC('I','2','4','0'), 0, 0, 0 },
+ { V4L2_PIX_FMT_RGB555, VLC_CODEC_RGB15, 0x001f,0x03e0,0x7c00 },
+ { V4L2_PIX_FMT_RGB565, VLC_CODEC_RGB16, 0x001f,0x07e0,0xf800 },
+ /* Won't work since we don't know how to handle such gmask values
+ * correctly
+ { V4L2_PIX_FMT_RGB555X, VLC_CODEC_RGB15, 0x007c,0xe003,0x1f00 },
+ { V4L2_PIX_FMT_RGB565X, VLC_CODEC_RGB16, 0x00f8,0xe007,0x1f00 },
+ */
+ { V4L2_PIX_FMT_BGR24, VLC_CODEC_RGB24, 0xff0000,0xff00,0xff },
+ { V4L2_PIX_FMT_RGB24, VLC_CODEC_RGB24, 0xff,0xff00,0xff0000 },
+ { V4L2_PIX_FMT_BGR32, VLC_CODEC_RGB32, 0xff0000,0xff00,0xff },
+ { V4L2_PIX_FMT_RGB32, VLC_CODEC_RGB32, 0xff,0xff00,0xff0000 },
+ { V4L2_PIX_FMT_YUYV, VLC_CODEC_YUYV, 0, 0, 0 },
+ { V4L2_PIX_FMT_UYVY, VLC_CODEC_UYVY, 0, 0, 0 },
+ { V4L2_PIX_FMT_Y41P, VLC_FOURCC('I','4','1','N'), 0, 0, 0 },
+ { V4L2_PIX_FMT_YUV422P, VLC_CODEC_I422, 0, 0, 0 },
+ { V4L2_PIX_FMT_YVU420, VLC_CODEC_YV12, 0, 0, 0 },
+ { V4L2_PIX_FMT_YUV411P, VLC_CODEC_I411, 0, 0, 0 },
+ { V4L2_PIX_FMT_YUV410, VLC_CODEC_I410, 0, 0, 0 },
+
+ /* Raw data types, not in V4L2 spec but still in videodev2.h and supported
+ * by VLC */
+ { V4L2_PIX_FMT_YUV420, VLC_CODEC_I420, 0, 0, 0 },
+ /* FIXME { V4L2_PIX_FMT_RGB444, VLC_CODEC_RGB32 }, */
+
+ /* Compressed data types */
+ { V4L2_PIX_FMT_MJPEG, VLC_CODEC_MJPG, 0, 0, 0 },
+ { V4L2_PIX_FMT_JPEG, VLC_CODEC_JPEG, 0, 0, 0 },
+#if 0
+ { V4L2_PIX_FMT_DV, VLC_FOURCC('?','?','?','?') },
+ { V4L2_PIX_FMT_MPEG, VLC_FOURCC('?','?','?','?') },
+#endif
+ { 0, 0, 0, 0, 0 }
+};
+
+bool get_v4l2pixelformat_by_fourcc( unsigned int *found, vlc_fourcc_t i_requested_fourcc )
+{
+ for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
+ {
+ if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
+ {
+ *found = v4l2chroma_to_fourcc[i].i_v4l2;
+ return true;
+ }
+ }
+ return false;
+}
+
+bool get_fourcc_by_v4l2pixelformat( vlc_fourcc_t *i_fourcc, int *i_rmask, int *i_gmask, int *i_bmask, unsigned int pixelformat )
+{
+ for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
+ {
+ if( v4l2chroma_to_fourcc[i].i_v4l2 == pixelformat )
+ {
+ *i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
+ *i_rmask = v4l2chroma_to_fourcc[i].i_rmask;
+ *i_gmask = v4l2chroma_to_fourcc[i].i_gmask;
+ *i_bmask = v4l2chroma_to_fourcc[i].i_bmask;
+ return true;
+ }
+ }
+ return false;
+}
+/*****************************************************************************
+ * Helper function to initalise video IO using the mmap method
+ *****************************************************************************/
+int InitMmap( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd )
+{
+ struct v4l2_requestbuffers req;
+
+ memset( &req, 0, sizeof(req) );
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_MMAP;
+
+ if( v4l2_ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
+ {
+ msg_Err( p_demux, "device does not support mmap I/O" );
+ return -1;
+ }
+
+ if( req.count < 2 )
+ {
+ msg_Err( p_demux, "insufficient buffers" );
+ return -1;
+ }
+
+ p_sys->p_buffers = calloc( req.count, sizeof( *p_sys->p_buffers ) );
+ if( unlikely(!p_sys->p_buffers) )
+ return -1;
+
+ for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < req.count; ++p_sys->i_nbuffers )
+ {
+ struct v4l2_buffer buf;
+
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = p_sys->i_nbuffers;
+
+ if( v4l2_ioctl( i_fd, VIDIOC_QUERYBUF, &buf ) < 0 )
+ {
+ msg_Err( p_demux, "VIDIOC_QUERYBUF: %m" );
+ return -1;
+ }
+
+ p_sys->p_buffers[p_sys->i_nbuffers].length = buf.length;
+ p_sys->p_buffers[p_sys->i_nbuffers].start =
+ v4l2_mmap( NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, buf.m.offset );
+
+ if( p_sys->p_buffers[p_sys->i_nbuffers].start == MAP_FAILED )
+ {
+ msg_Err( p_demux, "mmap failed: %m" );
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/modules/access/v4l2/v4l2_common.h b/modules/access/v4l2/v4l2_common.h
new file mode 100644
index 0000000..c56b7b3
--- /dev/null
+++ b/modules/access/v4l2/v4l2_common.h
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * v4l2_common.h : Video4Linux2 input module for vlc
+ *****************************************************************************
+ * Copyright (C) 2002-2011 the VideoLAN team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef V4L2_COMMON_H
+#define V4L2_COMMON_H
+
+#include <vlc_common.h>
+
+int InitMmap( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd );
+
+bool get_fourcc_by_v4l2pixelformat( vlc_fourcc_t *i_fourcc, int *i_rmask, int *i_gmask, int *i_bmask, unsigned int pixelformat );
+bool get_v4l2pixelformat_by_fourcc( unsigned int *found, vlc_fourcc_t i_requested_fourcc );
+
+
+#endif // V4L2_COMMON_H
diff --git a/modules/access/v4l2/v4l2_input.h b/modules/access/v4l2/v4l2_input.h
new file mode 100644
index 0000000..ffb102a
--- /dev/null
+++ b/modules/access/v4l2/v4l2_input.h
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * v4l2_input.h : Video4Linux2 input module for vlc
+ *****************************************************************************
+ * Copyright (C) 2002-2011 the VideoLAN team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef V4L2_INPUT_H
+#define V4L2_INPUT_H
+
+#define CFG_PREFIX "v4l2-"
+
+/* video.c */
+void ParseMRL(vlc_object_t *, const char *);
+int OpenVideo(vlc_object_t *, demux_sys_t *, bool);
+block_t* GrabVideo(vlc_object_t *, demux_sys_t *);
+
+/* demux.c */
+int DemuxOpen(vlc_object_t *);
+void DemuxClose(vlc_object_t *);
+float GetAbsoluteMaxFrameRate(vlc_object_t *, int fd, uint32_t fmt);
+void GetMaxDimensions(vlc_object_t *, int fd, uint32_t fmt, float fps_min,
+ uint32_t *pwidth, uint32_t *pheight);
+
+/* access.c */
+int AccessOpen(vlc_object_t *);
+void AccessClose(vlc_object_t *);
+
+/* controls.c */
+vlc_v4l2_ctrl_t *ControlsInit(vlc_object_t *, int fd);
+void ControlsDeinit(vlc_object_t *, vlc_v4l2_ctrl_t *);
+
+#endif // V4L2_INPUT_H
diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
index 951213d..5c33934 100644
--- a/modules/access/v4l2/video.c
+++ b/modules/access/v4l2/video.c
@@ -38,6 +38,8 @@
#endif
#include "v4l2.h"
+#include "v4l2_input.h"
+#include "v4l2_common.h"
#include <vlc_plugin.h>
#include <vlc_fs.h>
#include <vlc_demux.h>
@@ -460,52 +462,6 @@ vlc_module_end ()
static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size_t );
-static const struct
-{
- unsigned int i_v4l2;
- vlc_fourcc_t i_fourcc;
- int i_rmask;
- int i_gmask;
- int i_bmask;
-} v4l2chroma_to_fourcc[] =
-{
- /* Raw data types */
- { V4L2_PIX_FMT_GREY, VLC_CODEC_GREY, 0, 0, 0 },
- { V4L2_PIX_FMT_HI240, VLC_FOURCC('I','2','4','0'), 0, 0, 0 },
- { V4L2_PIX_FMT_RGB555, VLC_CODEC_RGB15, 0x001f,0x03e0,0x7c00 },
- { V4L2_PIX_FMT_RGB565, VLC_CODEC_RGB16, 0x001f,0x07e0,0xf800 },
- /* Won't work since we don't know how to handle such gmask values
- * correctly
- { V4L2_PIX_FMT_RGB555X, VLC_CODEC_RGB15, 0x007c,0xe003,0x1f00 },
- { V4L2_PIX_FMT_RGB565X, VLC_CODEC_RGB16, 0x00f8,0xe007,0x1f00 },
- */
- { V4L2_PIX_FMT_BGR24, VLC_CODEC_RGB24, 0xff0000,0xff00,0xff },
- { V4L2_PIX_FMT_RGB24, VLC_CODEC_RGB24, 0xff,0xff00,0xff0000 },
- { V4L2_PIX_FMT_BGR32, VLC_CODEC_RGB32, 0xff0000,0xff00,0xff },
- { V4L2_PIX_FMT_RGB32, VLC_CODEC_RGB32, 0xff,0xff00,0xff0000 },
- { V4L2_PIX_FMT_YUYV, VLC_CODEC_YUYV, 0, 0, 0 },
- { V4L2_PIX_FMT_UYVY, VLC_CODEC_UYVY, 0, 0, 0 },
- { V4L2_PIX_FMT_Y41P, VLC_FOURCC('I','4','1','N'), 0, 0, 0 },
- { V4L2_PIX_FMT_YUV422P, VLC_CODEC_I422, 0, 0, 0 },
- { V4L2_PIX_FMT_YVU420, VLC_CODEC_YV12, 0, 0, 0 },
- { V4L2_PIX_FMT_YUV411P, VLC_CODEC_I411, 0, 0, 0 },
- { V4L2_PIX_FMT_YUV410, VLC_CODEC_I410, 0, 0, 0 },
-
- /* Raw data types, not in V4L2 spec but still in videodev2.h and supported
- * by VLC */
- { V4L2_PIX_FMT_YUV420, VLC_CODEC_I420, 0, 0, 0 },
- /* FIXME { V4L2_PIX_FMT_RGB444, VLC_CODEC_RGB32 }, */
-
- /* Compressed data types */
- { V4L2_PIX_FMT_MJPEG, VLC_CODEC_MJPG, 0, 0, 0 },
- { V4L2_PIX_FMT_JPEG, VLC_CODEC_JPEG, 0, 0, 0 },
-#if 0
- { V4L2_PIX_FMT_DV, VLC_FOURCC('?','?','?','?') },
- { V4L2_PIX_FMT_MPEG, VLC_FOURCC('?','?','?','?') },
-#endif
- { 0, 0, 0, 0, 0 }
-};
-
/**
* List of V4L2 chromas were confident enough to use as fallbacks if the
* user hasn't provided a --v4l2-chroma value.
@@ -673,63 +629,6 @@ static block_t* ProcessVideoFrame( vlc_object_t *p_demux, uint8_t *p_frame, size
}
/*****************************************************************************
- * Helper function to initalise video IO using the mmap method
- *****************************************************************************/
-static int InitMmap( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd )
-{
- struct v4l2_requestbuffers req;
-
- memset( &req, 0, sizeof(req) );
- req.count = 4;
- req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- req.memory = V4L2_MEMORY_MMAP;
-
- if( v4l2_ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
- {
- msg_Err( p_demux, "device does not support mmap I/O" );
- return -1;
- }
-
- if( req.count < 2 )
- {
- msg_Err( p_demux, "insufficient buffers" );
- return -1;
- }
-
- p_sys->p_buffers = calloc( req.count, sizeof( *p_sys->p_buffers ) );
- if( unlikely(!p_sys->p_buffers) )
- return -1;
-
- for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < req.count; ++p_sys->i_nbuffers )
- {
- struct v4l2_buffer buf;
-
- memset( &buf, 0, sizeof(buf) );
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- buf.memory = V4L2_MEMORY_MMAP;
- buf.index = p_sys->i_nbuffers;
-
- if( v4l2_ioctl( i_fd, VIDIOC_QUERYBUF, &buf ) < 0 )
- {
- msg_Err( p_demux, "VIDIOC_QUERYBUF: %m" );
- return -1;
- }
-
- p_sys->p_buffers[p_sys->i_nbuffers].length = buf.length;
- p_sys->p_buffers[p_sys->i_nbuffers].start =
- v4l2_mmap( NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, buf.m.offset );
-
- if( p_sys->p_buffers[p_sys->i_nbuffers].start == MAP_FAILED )
- {
- msg_Err( p_demux, "mmap failed: %m" );
- return -1;
- }
- }
-
- return 0;
-}
-
-/*****************************************************************************
* Helper function to initalise video IO using the userbuf method
*****************************************************************************/
static int InitUserP( vlc_object_t *p_demux, demux_sys_t *p_sys, int i_fd, unsigned int i_buffer_size )
@@ -1071,21 +970,17 @@ static int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
vlc_fourcc_to_char( codecs[i].pixelformat, fourcc_v4l2 );
bool b_codec_supported = false;
- for( unsigned j = 0; v4l2chroma_to_fourcc[j].i_v4l2 != 0; j++ )
- {
- if( v4l2chroma_to_fourcc[j].i_v4l2 == codecs[i].pixelformat )
- {
- char fourcc[5];
- memset( fourcc, 0, sizeof( fourcc ) );
- vlc_fourcc_to_char( v4l2chroma_to_fourcc[j].i_fourcc,
- fourcc );
- msg_Dbg( p_obj, "device supports chroma %4.4s [%s, %s]",
- fourcc, codecs[i].description, fourcc_v4l2 );
- b_codec_supported = true;
- }
- }
- if( !b_codec_supported )
+ vlc_fourcc_t i_fourcc;
+ int i_rmask, i_gmask, i_bmask;
+ b_codec_supported = get_fourcc_by_v4l2pixelformat( &i_fourcc, &i_rmask, &i_gmask, &i_bmask, codecs[i].pixelformat );
+ if( b_codec_supported )
{
+ char fourcc[5];
+ memset( fourcc, 0, sizeof( fourcc ) );
+ vlc_fourcc_to_char( i_fourcc, fourcc );
+ msg_Dbg( p_obj, "device supports chroma %4.4s [%s, %s]",
+ fourcc, codecs[i].description, fourcc_v4l2 );
+ } else {
msg_Dbg( p_obj, "device codec %4.4s (%s) not supported",
fourcc_v4l2, codecs[i].description );
}
@@ -1167,14 +1062,8 @@ static int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
const vlc_fourcc_t i_requested_fourcc =
vlc_fourcc_GetCodecFromString( VIDEO_ES, reqchroma );
- for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
- {
- if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
- {
- fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2;
- break;
- }
- }
+ get_v4l2pixelformat_by_fourcc( &fmt.fmt.pix.pixelformat, i_requested_fourcc );
+
/* Try and set user chroma */
bool b_error = !IsPixelFormatSupported( codecs, ncodec,
fmt.fmt.pix.pixelformat );
@@ -1309,18 +1198,19 @@ static int InitVideo( vlc_object_t *p_obj, int i_fd, demux_sys_t *p_sys,
}
/* Look up final fourcc */
- p_sys->i_fourcc = 0;
- for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
+ int i_rmask, i_gmask, i_bmask;
+ if ( get_fourcc_by_v4l2pixelformat( &p_sys->i_fourcc,
+ &i_rmask,
+ &i_gmask,
+ &i_bmask,
+ fmt.fmt.pix.pixelformat ) )
{
- if( v4l2chroma_to_fourcc[i].i_v4l2 == fmt.fmt.pix.pixelformat )
- {
- p_sys->i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
- es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
- es_fmt.video.i_rmask = v4l2chroma_to_fourcc[i].i_rmask;
- es_fmt.video.i_gmask = v4l2chroma_to_fourcc[i].i_gmask;
- es_fmt.video.i_bmask = v4l2chroma_to_fourcc[i].i_bmask;
- break;
- }
+ es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
+ es_fmt.video.i_rmask = i_rmask;
+ es_fmt.video.i_gmask = i_gmask;
+ es_fmt.video.i_bmask = i_bmask;
+ } else {
+ p_sys->i_fourcc = 0;
}
/* Buggy driver paranoia */
--
1.7.6
More information about the vlc-devel
mailing list