2002-09-09 07:14:35 +00:00
|
|
|
/* G-Streamer Video4linux2 video-capture plugin - system calls
|
|
|
|
* Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-11-07 12:47:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-09-09 07:14:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "v4l2src_calls.h"
|
|
|
|
#include <sys/time.h>
|
2004-01-12 02:19:57 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT v4l2src_debug
|
|
|
|
|
|
|
|
/* lalala... */
|
|
|
|
#define GST_V4L2_SET_ACTIVE(element) (element)->buffer = GINT_TO_POINTER (-1)
|
|
|
|
#define GST_V4L2_SET_INACTIVE(element) (element)->buffer = NULL
|
2002-09-09 07:14:35 +00:00
|
|
|
|
|
|
|
#define DEBUG(format, args...) \
|
2005-12-06 19:55:58 +00:00
|
|
|
GST_CAT_DEBUG_OBJECT (\
|
|
|
|
v4l2src_debug, v4l2src, \
|
|
|
|
"V4L2SRC: " format, ##args)
|
2002-09-09 07:14:35 +00:00
|
|
|
|
|
|
|
/* On some systems MAP_FAILED seems to be missing */
|
|
|
|
#ifndef MAP_FAILED
|
|
|
|
#define MAP_FAILED ( (caddr_t) -1 )
|
|
|
|
#endif
|
|
|
|
|
2002-11-13 12:35:56 +00:00
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_fill_format_list():
|
|
|
|
* create list of supported capture formats
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_fill_format_list (GstV4l2Src * v4l2src)
|
2002-11-13 12:35:56 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
gint n;
|
|
|
|
struct v4l2_fmtdesc *format;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (v4l2src, "getting src format enumerations");
|
|
|
|
|
|
|
|
/* format enumeration */
|
2004-03-14 22:34:33 +00:00
|
|
|
for (n = 0;; n++) {
|
2004-01-12 02:19:57 +00:00
|
|
|
format = g_new (struct v4l2_fmtdesc, 1);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
format->index = n;
|
|
|
|
format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_ENUM_FMT,
|
2004-03-15 19:32:27 +00:00
|
|
|
format) < 0) {
|
2004-01-12 02:19:57 +00:00
|
|
|
if (errno == EINVAL) {
|
2004-03-15 19:32:27 +00:00
|
|
|
break; /* end of enumeration */
|
2004-01-12 02:19:57 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
|
|
|
|
("failed to get number %d in pixelformat enumeration for %s: %s",
|
|
|
|
n, GST_V4L2ELEMENT (v4l2src)->device, g_strerror (errno)));
|
|
|
|
g_free (format);
|
|
|
|
return FALSE;
|
2004-01-12 02:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
Update for GST_FOURCC_FORMAT API change.
Original commit message from CVS:
* ext/directfb/dfbvideosink.c:
(gst_dfbvideosink_get_format_from_caps):
* ext/sdl/sdlvideosink.c: (gst_sdlvideosink_create):
* gst/qtdemux/qtdemux.c: (gst_qtdemux_loop_header),
(qtdemux_parse), (qtdemux_type_get), (qtdemux_node_dump_foreach),
(qtdemux_dump_hdlr), (qtdemux_dump_dref), (qtdemux_dump_stsd),
(qtdemux_dump_dcom), (qtdemux_parse_trak), (qtdemux_video_caps),
(qtdemux_audio_caps):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_v4l2fourcc_to_caps):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_fill_format_list),
(gst_v4l2src_capture_init), (gst_v4l2src_get_size_limits):
Update for GST_FOURCC_FORMAT API change.
2005-11-21 14:39:04 +00:00
|
|
|
GST_LOG_OBJECT (v4l2src, "got format %" GST_FOURCC_FORMAT,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_FOURCC_ARGS (format->pixelformat));
|
2004-01-12 02:19:57 +00:00
|
|
|
v4l2src->formats = g_slist_prepend (v4l2src->formats, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2002-11-13 12:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
2004-01-12 02:19:57 +00:00
|
|
|
* gst_v4l2src_clear_format_list():
|
2002-11-13 12:35:56 +00:00
|
|
|
* free list of supported capture formats
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_clear_format_list (GstV4l2Src * v4l2src)
|
2002-11-13 12:35:56 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
g_slist_foreach (v4l2src->formats, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (v4l2src->formats);
|
2004-10-24 18:15:23 +00:00
|
|
|
v4l2src->formats = NULL;
|
2002-11-13 12:35:56 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
return TRUE;
|
2002-11-13 12:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-09 07:14:35 +00:00
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_queue_frame():
|
|
|
|
* queue a frame for capturing
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_queue_frame (GstV4l2Src * v4l2src, guint i)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_LOG_OBJECT (v4l2src, "queueing frame %u", i);
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_QBUF,
|
2004-03-15 19:32:27 +00:00
|
|
|
&v4l2src->pool->buffers[i].buffer) < 0) {
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, WRITE,
|
2004-03-15 19:32:27 +00:00
|
|
|
(_("Could not write to device \"%s\"."),
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device),
|
|
|
|
("Error queueing buffer %u on device %s", i, g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
return TRUE;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
2004-01-12 02:19:57 +00:00
|
|
|
* gst_v4l2src_grab_frame ():
|
|
|
|
* grab a frame for capturing
|
2002-09-09 07:14:35 +00:00
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
gint
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_grab_frame (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
struct v4l2_buffer buffer;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
2004-03-14 22:34:33 +00:00
|
|
|
while (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_DQBUF, &buffer) < 0) {
|
2004-01-12 02:19:57 +00:00
|
|
|
/* if the sync() got interrupted, we can retry */
|
|
|
|
if (errno != EINTR) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SYNC, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("could not sync on a buffer on device %s: %s",
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device, g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (v4l2src, "grab got interrupted");
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (v4l2src, "grabbed frame %d", buffer.index);
|
|
|
|
|
|
|
|
return buffer.index;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_get_capture():
|
|
|
|
* get capture parameters
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_get_capture (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
DEBUG ("Getting capture format");
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
v4l2src->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_G_FMT,
|
2004-03-15 19:32:27 +00:00
|
|
|
&v4l2src->format) < 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("failed to get pixelformat for device %s: %s",
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device, g_strerror (errno)));
|
2004-03-14 22:34:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
return TRUE;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_set_capture():
|
|
|
|
* set capture parameters
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_set_capture (GstV4l2Src * v4l2src,
|
|
|
|
struct v4l2_fmtdesc * fmt, gint width, gint height)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
DEBUG ("Setting capture format to %dx%d, format %s",
|
|
|
|
width, height, fmt->description);
|
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
GST_V4L2_CHECK_NOT_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
|
|
|
|
memset (&v4l2src->format, 0, sizeof (struct v4l2_format));
|
|
|
|
v4l2src->format.fmt.pix.width = width;
|
|
|
|
v4l2src->format.fmt.pix.height = height;
|
|
|
|
v4l2src->format.fmt.pix.pixelformat = fmt->pixelformat;
|
|
|
|
v4l2src->format.fmt.pix.field = V4L2_FIELD_INTERLACED;
|
|
|
|
v4l2src->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
|
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_S_FMT,
|
2004-03-15 19:32:27 +00:00
|
|
|
&v4l2src->format) < 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, SETTINGS, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("failed to set pixelformat to %s @ %dx%d for device %s: %s",
|
|
|
|
fmt->description, width, height, GST_V4L2ELEMENT (v4l2src)->device,
|
|
|
|
g_strerror (errno)));
|
2004-03-14 22:34:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update internal info */
|
|
|
|
return gst_v4l2src_get_capture (v4l2src);
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_capture_init():
|
|
|
|
* initialize the capture system
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_capture_init (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
gint n;
|
|
|
|
guint buffers;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (v4l2src, "initting the capture system");
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
GST_V4L2_CHECK_NOT_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
2004-01-12 02:19:57 +00:00
|
|
|
|
|
|
|
/* request buffer info */
|
|
|
|
buffers = v4l2src->breq.count;
|
|
|
|
if (v4l2src->breq.count > GST_V4L2_MAX_BUFFERS) {
|
|
|
|
v4l2src->breq.count = GST_V4L2_MAX_BUFFERS;
|
|
|
|
}
|
|
|
|
if (v4l2src->breq.count < GST_V4L2_MIN_BUFFERS) {
|
|
|
|
v4l2src->breq.count = GST_V4L2_MIN_BUFFERS;
|
|
|
|
}
|
|
|
|
v4l2src->breq.type = v4l2src->format.type;
|
|
|
|
v4l2src->breq.memory = V4L2_MEMORY_MMAP;
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_REQBUFS,
|
2004-03-15 19:32:27 +00:00
|
|
|
&v4l2src->breq) < 0) {
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ,
|
2004-03-15 19:32:27 +00:00
|
|
|
(_("Could not get buffers from device \"%s\"."),
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device),
|
|
|
|
("error requesting %d buffers: %s", v4l2src->breq.count,
|
|
|
|
g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v4l2src->breq.count < GST_V4L2_MIN_BUFFERS) {
|
2004-01-29 23:20:45 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ,
|
2004-03-15 19:32:27 +00:00
|
|
|
(_("Could not get enough buffers from device \"%s\"."),
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device),
|
|
|
|
("we received %d, we want at least %d", v4l2src->breq.count,
|
|
|
|
GST_V4L2_MIN_BUFFERS));
|
2004-01-12 02:19:57 +00:00
|
|
|
v4l2src->breq.count = buffers;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (v4l2src->breq.count != buffers)
|
|
|
|
g_object_notify (G_OBJECT (v4l2src), "num_buffers");
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_INFO_OBJECT (v4l2src,
|
Update for GST_FOURCC_FORMAT API change.
Original commit message from CVS:
* ext/directfb/dfbvideosink.c:
(gst_dfbvideosink_get_format_from_caps):
* ext/sdl/sdlvideosink.c: (gst_sdlvideosink_create):
* gst/qtdemux/qtdemux.c: (gst_qtdemux_loop_header),
(qtdemux_parse), (qtdemux_type_get), (qtdemux_node_dump_foreach),
(qtdemux_dump_hdlr), (qtdemux_dump_dref), (qtdemux_dump_stsd),
(qtdemux_dump_dcom), (qtdemux_parse_trak), (qtdemux_video_caps),
(qtdemux_audio_caps):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_v4l2fourcc_to_caps):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_fill_format_list),
(gst_v4l2src_capture_init), (gst_v4l2src_get_size_limits):
Update for GST_FOURCC_FORMAT API change.
2005-11-21 14:39:04 +00:00
|
|
|
"Got %d buffers (%" GST_FOURCC_FORMAT ") of size %d KB\n",
|
2004-03-14 22:34:33 +00:00
|
|
|
v4l2src->breq.count,
|
|
|
|
GST_FOURCC_ARGS (v4l2src->format.fmt.pix.pixelformat),
|
2004-01-12 02:19:57 +00:00
|
|
|
v4l2src->format.fmt.pix.sizeimage / 1024);
|
|
|
|
|
|
|
|
/* Map the buffers */
|
|
|
|
v4l2src->pool = g_new (GstV4l2BufferPool, 1);
|
|
|
|
gst_atomic_int_init (&v4l2src->pool->refcount, 1);
|
|
|
|
v4l2src->pool->video_fd = GST_V4L2ELEMENT (v4l2src)->video_fd;
|
|
|
|
v4l2src->pool->buffer_count = v4l2src->breq.count;
|
|
|
|
v4l2src->pool->buffers = g_new0 (GstV4l2Buffer, v4l2src->breq.count);
|
|
|
|
|
|
|
|
for (n = 0; n < v4l2src->breq.count; n++) {
|
|
|
|
GstV4l2Buffer *buffer = &v4l2src->pool->buffers[n];
|
|
|
|
|
|
|
|
gst_atomic_int_init (&buffer->refcount, 1);
|
|
|
|
buffer->pool = v4l2src->pool;
|
|
|
|
buffer->buffer.index = n;
|
|
|
|
buffer->buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_QUERYBUF,
|
2004-03-15 19:32:27 +00:00
|
|
|
&buffer->buffer) < 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Could not get buffer properties of buffer %d: %s", n,
|
|
|
|
g_strerror (errno)));
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_capture_deinit (v4l2src);
|
2004-01-12 02:19:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
buffer->start =
|
2004-03-15 19:32:27 +00:00
|
|
|
mmap (0, buffer->buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED,
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->video_fd, buffer->buffer.m.offset);
|
2004-01-12 02:19:57 +00:00
|
|
|
if (buffer->start == MAP_FAILED) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, READ, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Could not mmap video buffer %d: %s", n, g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
buffer->start = 0;
|
|
|
|
gst_v4l2src_capture_deinit (v4l2src);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
buffer->length = buffer->buffer.length;
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_v4l2src_queue_frame (v4l2src, n)) {
|
2004-01-12 02:19:57 +00:00
|
|
|
gst_v4l2src_capture_deinit (v4l2src);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_V4L2_SET_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
2004-10-24 15:47:40 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
return TRUE;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_capture_start():
|
|
|
|
* start streaming capture
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_capture_start (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
gint type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2src, "starting the capturing");
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
if (!GST_V4L2_IS_ACTIVE (GST_V4L2ELEMENT (v4l2src))) {
|
2004-01-12 02:19:57 +00:00
|
|
|
gst_pad_renegotiate (v4l2src->srcpad);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_V4L2_CHECK_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
v4l2src->quit = FALSE;
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_STREAMON, &type) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, OPEN_READ, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Error starting streaming capture from device %s: %s",
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device, g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2004-10-24 15:47:40 +00:00
|
|
|
v4l2src->is_capturing = TRUE;
|
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
return TRUE;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_capture_stop():
|
|
|
|
* stop streaming capture
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_capture_stop (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
gint type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (v4l2src, "stopping capturing");
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
GST_V4L2_CHECK_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
2004-01-12 02:19:57 +00:00
|
|
|
|
|
|
|
/* we actually need to sync on all queued buffers but not
|
|
|
|
* on the non-queued ones */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_STREAMOFF, &type) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2src, RESOURCE, CLOSE, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Error stopping streaming capture from device %s: %s",
|
|
|
|
GST_V4L2ELEMENT (v4l2src)->device, g_strerror (errno)));
|
2004-01-12 02:19:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make an optional pending wait stop */
|
|
|
|
v4l2src->quit = TRUE;
|
2004-10-24 15:47:40 +00:00
|
|
|
v4l2src->is_capturing = FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-05-21 06:33:18 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_buffer_pool_free (GstV4l2BufferPool * pool, gboolean do_close)
|
2004-01-12 02:19:57 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < pool->buffer_count; i++) {
|
|
|
|
gst_atomic_int_destroy (&pool->buffers[i].refcount);
|
|
|
|
munmap (pool->buffers[i].start, pool->buffers[i].length);
|
|
|
|
}
|
|
|
|
g_free (pool->buffers);
|
|
|
|
gst_atomic_int_destroy (&pool->refcount);
|
|
|
|
if (do_close)
|
|
|
|
close (pool->video_fd);
|
|
|
|
g_free (pool);
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_free_buffer (GstBuffer * buffer)
|
2004-01-12 02:19:57 +00:00
|
|
|
{
|
|
|
|
GstV4l2Buffer *buf = (GstV4l2Buffer *) GST_BUFFER_PRIVATE (buffer);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_LOG ("freeing buffer %p (nr. %d)", buffer, buf->buffer.index);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
if (!gst_atomic_int_dec_and_test (&buf->refcount)) {
|
|
|
|
/* we're still in use, add to queue again
|
|
|
|
note: this might fail because the device is already stopped (race) */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ioctl (buf->pool->video_fd, VIDIOC_QBUF, &buf->buffer) < 0)
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_INFO ("readding to queue failed, assuming video device is stopped");
|
|
|
|
}
|
|
|
|
if (gst_atomic_int_dec_and_test (&buf->pool->refcount)) {
|
|
|
|
/* we're last thing that used all this */
|
|
|
|
gst_v4l2src_buffer_pool_free (buf->pool, TRUE);
|
|
|
|
}
|
|
|
|
}
|
2002-09-09 07:14:35 +00:00
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2src_capture_deinit():
|
|
|
|
* deinitialize the capture system
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_capture_deinit (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2004-01-12 02:19:57 +00:00
|
|
|
gint i, dequeue = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2src, "deinitting capture system");
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
GST_V4L2_CHECK_ACTIVE (GST_V4L2ELEMENT (v4l2src));
|
2004-01-12 02:19:57 +00:00
|
|
|
|
|
|
|
/* free the buffers */
|
|
|
|
for (i = 0; i < v4l2src->breq.count; i++) {
|
|
|
|
if (gst_atomic_int_dec_and_test (&v4l2src->pool->buffers[i].refcount))
|
|
|
|
dequeue++;
|
|
|
|
}
|
|
|
|
for (i = 0; i < dequeue; i++) {
|
|
|
|
struct v4l2_buffer buffer;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_DQBUF, &buffer) < 0)
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
2004-03-15 19:32:27 +00:00
|
|
|
"Could not dequeue buffer on uninitialization");
|
2004-01-12 02:19:57 +00:00
|
|
|
}
|
|
|
|
if (gst_atomic_int_dec_and_test (&v4l2src->pool->refcount)) {
|
|
|
|
/* we're last thing that used all this */
|
|
|
|
gst_v4l2src_buffer_pool_free (v4l2src->pool, FALSE);
|
|
|
|
}
|
|
|
|
v4l2src->pool = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_V4L2_SET_INACTIVE (GST_V4L2ELEMENT (v4l2src));
|
|
|
|
return TRUE;
|
2002-09-09 07:14:35 +00:00
|
|
|
}
|
2003-05-10 14:36:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_v4l2src_get_size_limits (GstV4l2Src * v4l2src,
|
|
|
|
struct v4l2_fmtdesc * format,
|
|
|
|
gint * min_w, gint * max_w, gint * min_h, gint * max_h)
|
2003-05-10 14:36:34 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
struct v4l2_format fmt;
|
|
|
|
|
Update for GST_FOURCC_FORMAT API change.
Original commit message from CVS:
* ext/directfb/dfbvideosink.c:
(gst_dfbvideosink_get_format_from_caps):
* ext/sdl/sdlvideosink.c: (gst_sdlvideosink_create):
* gst/qtdemux/qtdemux.c: (gst_qtdemux_loop_header),
(qtdemux_parse), (qtdemux_type_get), (qtdemux_node_dump_foreach),
(qtdemux_dump_hdlr), (qtdemux_dump_dref), (qtdemux_dump_stsd),
(qtdemux_dump_dcom), (qtdemux_parse_trak), (qtdemux_video_caps),
(qtdemux_audio_caps):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_v4l2fourcc_to_caps):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_fill_format_list),
(gst_v4l2src_capture_init), (gst_v4l2src_get_size_limits):
Update for GST_FOURCC_FORMAT API change.
2005-11-21 14:39:04 +00:00
|
|
|
GST_LOG_OBJECT (v4l2src,
|
|
|
|
"getting size limits with format %" GST_FOURCC_FORMAT,
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_FOURCC_ARGS (format->pixelformat));
|
|
|
|
|
|
|
|
/* get size delimiters */
|
|
|
|
memset (&fmt, 0, sizeof (fmt));
|
|
|
|
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
fmt.fmt.pix.width = 0;
|
|
|
|
fmt.fmt.pix.height = 0;
|
|
|
|
fmt.fmt.pix.pixelformat = format->pixelformat;
|
|
|
|
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
|
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_TRY_FMT, &fmt) < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_w)
|
|
|
|
*min_w = fmt.fmt.pix.width;
|
|
|
|
if (min_h)
|
|
|
|
*min_h = fmt.fmt.pix.height;
|
|
|
|
GST_LOG_OBJECT (v4l2src, "got min size %dx%d", fmt.fmt.pix.width,
|
|
|
|
fmt.fmt.pix.height);
|
|
|
|
|
|
|
|
fmt.fmt.pix.width = G_MAXINT;
|
|
|
|
fmt.fmt.pix.height = 576;
|
|
|
|
if (ioctl (GST_V4L2ELEMENT (v4l2src)->video_fd, VIDIOC_TRY_FMT, &fmt) < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_w)
|
|
|
|
*max_w = fmt.fmt.pix.width;
|
|
|
|
if (max_h)
|
|
|
|
*max_h = fmt.fmt.pix.height;
|
|
|
|
GST_LOG_OBJECT (v4l2src, "got max size %dx%d", fmt.fmt.pix.width,
|
|
|
|
fmt.fmt.pix.height);
|
|
|
|
|
|
|
|
return TRUE;
|
2003-05-10 14:36:34 +00:00
|
|
|
}
|