From 2e93d91c6c5caa3732f0a3e5f6713b3882e74578 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 26 Jan 2010 02:52:12 +0000 Subject: More error checking. --- src/input/input_v4l2.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/input/input_v4l2.c b/src/input/input_v4l2.c index 69d0a3b75..903293057 100644 --- a/src/input/input_v4l2.c +++ b/src/input/input_v4l2.c @@ -91,19 +91,25 @@ typedef struct { v4l2_radio_t* radio; } v4l2_input_plugin_t; -static void v4l2_input_enqueue_video_buffer(v4l2_input_plugin_t *this, int idx); +static int v4l2_input_enqueue_video_buffer(v4l2_input_plugin_t *this, int idx); static int v4l2_input_dequeue_video_buffer(v4l2_input_plugin_t *this, buf_element_t *input); static int v4l2_input_setup_video_streaming(v4l2_input_plugin_t *this); static int v4l2_input_open(input_plugin_t *this_gen) { v4l2_input_plugin_t *this = (v4l2_input_plugin_t*) this_gen; + int ret; lprintf("Opening %s\n", this->mrl); this->fd = v4l2_open(this->mrl, O_RDWR); if (this->fd) { /* TODO: Clean up this mess */ this->events = xine_event_new_queue(this->stream); - v4l2_ioctl(this->fd, VIDIOC_QUERYCAP, &(this->cap)); + ret = v4l2_ioctl(this->fd, VIDIOC_QUERYCAP, &(this->cap)); + if (ret < 0) + { + lprintf ("Capability query failed: %s\n", strerror (-ret)); + return 0; + } if (this->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) { this->video = malloc(sizeof(v4l2_video_t)); this->video->headerSent = 0; @@ -180,7 +186,8 @@ static int v4l2_input_setup_video_streaming(v4l2_input_plugin_t *this) { this->video->bufcount = 0; return 0; } - v4l2_input_enqueue_video_buffer(this, i); + if (v4l2_input_enqueue_video_buffer(this, i) < 0) + goto fail; } struct v4l2_format fmt; @@ -232,6 +239,11 @@ static buf_element_t* v4l2_input_read_block(input_plugin_t *this_gen, fifo_buffe lprintf("Sending video frame (sent %d of %d)\n", this->video->index, this->video->buffers[this->video->inbuf.index].length); /* TODO: Add audio support */ this->video->headerSent = v4l2_input_dequeue_video_buffer(this, buf); + if (this->video->headerSent < 0) + { + buf->free_buffer (buf); + buf = NULL; + } } return buf; } @@ -251,12 +263,16 @@ static uint32_t v4l2_input_blocksize(input_plugin_t *this_gen) { static int v4l2_input_dequeue_video_buffer(v4l2_input_plugin_t *this, buf_element_t *output) { + int ret; + if (!this->video->index) { memset (&this->video->inbuf, 0, sizeof (this->video->inbuf)); this->video->inbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; this->video->inbuf.memory = V4L2_MEMORY_MMAP; - v4l2_ioctl(this->fd, VIDIOC_DQBUF, &this->video->inbuf); + ret = v4l2_ioctl(this->fd, VIDIOC_DQBUF, &this->video->inbuf); + if (ret < 0) + return -1; /* failure */ output->decoder_flags = BUF_FLAG_FRAME_START; } else @@ -275,20 +291,20 @@ static int v4l2_input_dequeue_video_buffer(v4l2_input_plugin_t *this, buf_elemen if (this->video->index == this->video->buffers[this->video->inbuf.index].length) { output->decoder_flags |= BUF_FLAG_FRAME_END; - v4l2_input_enqueue_video_buffer(this, this->video->inbuf.index); - return 0; + ret = v4l2_input_enqueue_video_buffer(this, this->video->inbuf.index); + return -(ret < 0); } return 1; } -static void v4l2_input_enqueue_video_buffer(v4l2_input_plugin_t *this, int idx) { +static int v4l2_input_enqueue_video_buffer(v4l2_input_plugin_t *this, int idx) { struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.index = idx; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; - v4l2_ioctl(this->fd, VIDIOC_QBUF, &buf); + return v4l2_ioctl(this->fd, VIDIOC_QBUF, &buf); } static void v4l2_input_dispose(input_plugin_t *this_gen) { -- cgit v1.2.3 From 17c42f308cccdffa51939504b39c167f0fe37aa4 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 26 Jan 2010 02:52:28 +0000 Subject: Get rid of a few compiler warnings. --- src/input/input_v4l2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input/input_v4l2.c b/src/input/input_v4l2.c index 903293057..88156d405 100644 --- a/src/input/input_v4l2.c +++ b/src/input/input_v4l2.c @@ -236,7 +236,7 @@ static buf_element_t* v4l2_input_read_block(input_plugin_t *this_gen, fifo_buffe this->video->index = 0; buf->type = BUF_VIDEO_YUY2; } else { - lprintf("Sending video frame (sent %d of %d)\n", this->video->index, this->video->buffers[this->video->inbuf.index].length); + lprintf("Sending video frame (sent %zd of %zd)\n", this->video->index, this->video->buffers[this->video->inbuf.index].length); /* TODO: Add audio support */ this->video->headerSent = v4l2_input_dequeue_video_buffer(this, buf); if (this->video->headerSent < 0) @@ -285,7 +285,7 @@ static int v4l2_input_dequeue_video_buffer(v4l2_input_plugin_t *this, buf_elemen if (output->size > output->max_size) output->size = output->max_size; - xine_fast_memcpy (output->content, this->video->buffers[this->video->inbuf.index].start + this->video->index, output->size); + xine_fast_memcpy (output->content, (char *)this->video->buffers[this->video->inbuf.index].start + this->video->index, output->size); this->video->index += output->size; if (this->video->index == this->video->buffers[this->video->inbuf.index].length) -- cgit v1.2.3 From 2f582c13386aeb7132c64851233245db4994c63d Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 26 Jan 2010 03:05:00 +0000 Subject: Switch off logging, convert some lprintf() to xine_log(), add a startup warning. --- src/input/input_v4l2.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/input/input_v4l2.c b/src/input/input_v4l2.c index 88156d405..fb27db5dc 100644 --- a/src/input/input_v4l2.c +++ b/src/input/input_v4l2.c @@ -26,9 +26,9 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif - +/* #define LOG - +*/ #include "input_plugin.h" #include "xine_plugin.h" #include "xine_internal.h" @@ -107,7 +107,8 @@ static int v4l2_input_open(input_plugin_t *this_gen) { ret = v4l2_ioctl(this->fd, VIDIOC_QUERYCAP, &(this->cap)); if (ret < 0) { - lprintf ("Capability query failed: %s\n", strerror (-ret)); + xine_log (this->stream->xine, XINE_LOG_MSG, + LOG_MODULE": %s: %s\n", _("capability query failed"), strerror (-ret)); return 0; } if (this->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) { @@ -123,16 +124,19 @@ static int v4l2_input_open(input_plugin_t *this_gen) { return 1; } else { /* TODO: Fallbacks */ - lprintf("Video streaming setup failed.\n"); + xine_log (this->stream->xine, XINE_LOG_MSG, + LOG_MODULE": %s\n", _("video streaming setup failed")); return 0; } } else { /* TODO: Radio streaming */ - lprintf("Sorry, only video is supported for now.\n"); + xine_log (this->stream->xine, XINE_LOG_MSG, + LOG_MODULE": %s\n", _("sorry, only video is supported for now")); return 0; } } else { - lprintf("Device doesn't support streaming. Prod the author to support the other methods.\n"); + xine_log (this->stream->xine, XINE_LOG_MSG, + LOG_MODULE": %s\n", _("device doesn't support streaming - prod the author to support the other methods")); return 0; } } else { @@ -414,6 +418,9 @@ static input_plugin_t *v4l2_class_get_instance(input_class_t *gen_cls, xine_stre this->radio = NULL; lprintf("Ready to read!\n"); + xine_log (this->stream->xine, XINE_LOG_MSG, + LOG_MODULE": %s\n", _("WARNING: this plugin is not of release quality")); + return &this->input_plugin; } -- cgit v1.2.3 From 392689a404398eb48005f519b187341fd1f91dec Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 26 Jan 2010 21:55:45 +0000 Subject: =?UTF-8?q?Convert=20xine=5Flog=20=E2=86=92=20xprintf.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/input/input_v4l2.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/input/input_v4l2.c b/src/input/input_v4l2.c index fb27db5dc..255b1f17c 100644 --- a/src/input/input_v4l2.c +++ b/src/input/input_v4l2.c @@ -107,8 +107,8 @@ static int v4l2_input_open(input_plugin_t *this_gen) { ret = v4l2_ioctl(this->fd, VIDIOC_QUERYCAP, &(this->cap)); if (ret < 0) { - xine_log (this->stream->xine, XINE_LOG_MSG, - LOG_MODULE": %s: %s\n", _("capability query failed"), strerror (-ret)); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE": capability query failed: %s\n", strerror (-ret)); return 0; } if (this->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) { @@ -124,19 +124,19 @@ static int v4l2_input_open(input_plugin_t *this_gen) { return 1; } else { /* TODO: Fallbacks */ - xine_log (this->stream->xine, XINE_LOG_MSG, - LOG_MODULE": %s\n", _("video streaming setup failed")); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE": video streaming setup failed\n"); return 0; } } else { /* TODO: Radio streaming */ - xine_log (this->stream->xine, XINE_LOG_MSG, - LOG_MODULE": %s\n", _("sorry, only video is supported for now")); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE": sorry, only video is supported for now\n"); return 0; } } else { - xine_log (this->stream->xine, XINE_LOG_MSG, - LOG_MODULE": %s\n", _("device doesn't support streaming - prod the author to support the other methods")); + xprintf (this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE": device doesn't support streaming - prod the author to support the other methods\n"); return 0; } } else { @@ -418,8 +418,8 @@ static input_plugin_t *v4l2_class_get_instance(input_class_t *gen_cls, xine_stre this->radio = NULL; lprintf("Ready to read!\n"); - xine_log (this->stream->xine, XINE_LOG_MSG, - LOG_MODULE": %s\n", _("WARNING: this plugin is not of release quality")); + xprintf (this->stream->xine, XINE_VERBOSITY_NONE, + LOG_MODULE": WARNING: this plugin is not of release quality\n"); return &this->input_plugin; } -- cgit v1.2.3 From 81e86315a6966e172f4988f8925f830e01072c53 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 29 Jan 2010 18:36:36 +0000 Subject: Link the v4l2 plugin with libv4l2 (if required); use pkgconfig to locate it. --- configure.ac | 13 ++++++++----- src/input/Makefile.am | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 6ca597502..01d0a5eb6 100644 --- a/configure.ac +++ b/configure.ac @@ -694,11 +694,14 @@ dnl ---------------------------------------------- AC_ARG_ENABLE([libv4l], AS_HELP_STRING([--disable-libv4l], [do not build with libv4l support])) -if test "x$enable_libv4l" != "xno"; then - AC_CHECK_HEADERS([libv4l2.h], [have_libv4l=yes], [have_libv4l=no]) - if test "x$enable_libv4l" = "xyes" && test "x$have_libv4l" = "xno"; then - AC_MSG_ERROR([libv4l requested but not found.]) - fi +if test "x$have_v4l" = xyes; then + have_libv4l=no + PKG_CHECK_MODULES([V4L2], [libv4l2], + [have_libv4l=yes + AC_DEFINE([HAVE_LIBV4L2_H], [1], [Define this if you have libv4l installed])]) + if test "x$enable_libv4l" = "xyes" && test "x$have_libv4l" = "xno"; then + AC_MSG_ERROR([libv4l requested but not found.]) + fi fi diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 3c700ea46..1c34f9aaa 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -141,8 +141,8 @@ xineplug_inp_v4l_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) xineplug_inp_v4l_la_LDFLAGS = -avoid-version -module xineplug_inp_v4l2_la_SOURCES = input_v4l2.c -xineplug_inp_v4l2_la_LIBADD = $(XINE_LIB) $(ALSA_LIBS) -xineplug_inp_v4l2_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) +xineplug_inp_v4l2_la_LIBADD = $(XINE_LIB) $(ALSA_LIBS) $(LTLIBINTL) $(V4L2_LIBS) +xineplug_inp_v4l2_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) $(V4L2_CFLAGS) xineplug_inp_v4l2_la_LDFLAGS = -avoid-version -module xineplug_inp_gnome_vfs_la_SOURCES = input_gnome_vfs.c net_buf_ctrl.c -- cgit v1.2.3