2006-03-11 22:50:03 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2017-02-26 00:47:03 +00:00
|
|
|
* 2006 Edgard Lima <edgard.lima@gmail.com>
|
2006-09-02 14:28:55 +00:00
|
|
|
*
|
|
|
|
* gstv4l2.c: plugin for v4l2 elements
|
2003-09-13 08:58:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2003-09-13 08:58:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-03 16:31:07 +00:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
# define _GNU_SOURCE /* O_CLOEXEC */
|
|
|
|
#endif
|
|
|
|
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2004-01-20 01:51:47 +00:00
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "ext/videodev2.h"
|
2021-02-16 14:29:06 +00:00
|
|
|
#include "gstv4l2elements.h"
|
2014-05-03 01:38:30 +00:00
|
|
|
#include "v4l2-utils.h"
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
#include "gstv4l2object.h"
|
2003-09-13 08:58:49 +00:00
|
|
|
#include "gstv4l2src.h"
|
2009-08-04 07:14:20 +00:00
|
|
|
#include "gstv4l2sink.h"
|
2011-03-26 22:19:58 +00:00
|
|
|
#include "gstv4l2radio.h"
|
2013-11-28 22:14:18 +00:00
|
|
|
#include "gstv4l2videodec.h"
|
2018-09-10 19:20:52 +00:00
|
|
|
#include "gstv4l2fwhtenc.h"
|
2017-07-31 20:09:30 +00:00
|
|
|
#include "gstv4l2h263enc.h"
|
2017-05-23 18:40:56 +00:00
|
|
|
#include "gstv4l2h264enc.h"
|
2018-10-18 06:59:00 +00:00
|
|
|
#include "gstv4l2h265enc.h"
|
2018-09-10 16:18:30 +00:00
|
|
|
#include "gstv4l2jpegenc.h"
|
2017-07-26 19:18:01 +00:00
|
|
|
#include "gstv4l2mpeg4enc.h"
|
2017-08-01 20:01:11 +00:00
|
|
|
#include "gstv4l2vp8enc.h"
|
|
|
|
#include "gstv4l2vp9enc.h"
|
2014-03-04 23:31:27 +00:00
|
|
|
#include "gstv4l2transform.h"
|
2006-03-11 22:50:03 +00:00
|
|
|
|
2021-04-19 15:39:03 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
|
|
|
|
#define GST_CAT_DEFAULT v4l2_debug
|
|
|
|
|
2015-11-13 17:35:59 +00:00
|
|
|
#ifdef GST_V4L2_ENABLE_PROBE
|
2014-05-03 01:38:30 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_probe_and_register (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GstV4l2Iterator *it;
|
|
|
|
gint video_fd = -1;
|
|
|
|
struct v4l2_capability vcap;
|
2016-07-02 08:56:07 +00:00
|
|
|
guint32 device_caps;
|
2024-08-15 17:07:31 +00:00
|
|
|
enum v4l2_buf_type output_type, capture_type;
|
2014-05-03 01:38:30 +00:00
|
|
|
|
2021-04-19 15:39:03 +00:00
|
|
|
v4l2_element_init (plugin);
|
|
|
|
|
2018-09-10 16:18:45 +00:00
|
|
|
GST_DEBUG ("Probing devices");
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
it = gst_v4l2_iterator_new ();
|
|
|
|
|
|
|
|
while (gst_v4l2_iterator_next (it)) {
|
|
|
|
GstCaps *src_caps, *sink_caps;
|
|
|
|
gchar *basename;
|
|
|
|
|
2014-05-05 11:07:25 +00:00
|
|
|
if (video_fd >= 0)
|
2014-05-03 01:38:30 +00:00
|
|
|
close (video_fd);
|
|
|
|
|
2024-08-15 17:07:31 +00:00
|
|
|
/* FIXME, missing libv4l2 support */
|
2015-11-03 16:31:07 +00:00
|
|
|
video_fd = open (it->device_path, O_RDWR | O_CLOEXEC);
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
if (video_fd == -1) {
|
|
|
|
GST_DEBUG ("Failed to open %s: %s", it->device_path, g_strerror (errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset (&vcap, 0, sizeof (vcap));
|
|
|
|
|
|
|
|
if (ioctl (video_fd, VIDIOC_QUERYCAP, &vcap) < 0) {
|
2024-08-15 17:07:31 +00:00
|
|
|
GST_DEBUG ("Failed to get device '%s' capabilities: %s",
|
|
|
|
it->device_path, g_strerror (errno));
|
2014-05-03 01:38:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
if (vcap.capabilities & V4L2_CAP_DEVICE_CAPS)
|
|
|
|
device_caps = vcap.device_caps;
|
|
|
|
else
|
2016-07-07 22:53:54 +00:00
|
|
|
device_caps = vcap.capabilities;
|
2016-07-02 08:56:07 +00:00
|
|
|
|
2018-07-13 19:58:36 +00:00
|
|
|
if (!GST_V4L2_IS_M2M (device_caps))
|
2014-05-03 01:38:30 +00:00
|
|
|
continue;
|
|
|
|
|
2024-08-15 17:07:31 +00:00
|
|
|
if (device_caps & V4L2_CAP_VIDEO_M2M_MPLANE) {
|
|
|
|
output_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
|
|
|
|
capture_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
|
|
|
|
} else {
|
|
|
|
output_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
|
|
|
|
capture_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
GST_DEBUG ("Probing '%s' located at '%s'",
|
|
|
|
it->device_name ? it->device_name : (const gchar *) vcap.driver,
|
|
|
|
it->device_path);
|
|
|
|
|
|
|
|
/* get sink supported format (no MPLANE for codec) */
|
2024-08-15 17:07:31 +00:00
|
|
|
sink_caps = gst_v4l2_object_probe_template_caps (it->device_path,
|
|
|
|
video_fd, output_type);
|
2014-05-03 01:38:30 +00:00
|
|
|
/* get src supported format */
|
2024-08-15 17:07:31 +00:00
|
|
|
src_caps = gst_v4l2_object_probe_template_caps (it->device_path,
|
|
|
|
video_fd, capture_type);
|
2014-05-03 01:38:30 +00:00
|
|
|
|
2015-11-19 22:20:55 +00:00
|
|
|
/* Skip devices without any supported formats */
|
|
|
|
if (gst_caps_is_empty (sink_caps) || gst_caps_is_empty (src_caps)) {
|
|
|
|
gst_caps_unref (sink_caps);
|
|
|
|
gst_caps_unref (src_caps);
|
2024-08-15 17:07:31 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Skipping unsupported device '%s' located at '%s'",
|
|
|
|
it->device_name ? it->device_name : (const gchar *) vcap.driver,
|
|
|
|
it->device_path);
|
2015-11-19 22:20:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
basename = g_path_get_basename (it->device_path);
|
|
|
|
|
2019-01-17 14:30:25 +00:00
|
|
|
/* Caps won't be freed if the subclass is not instantiated */
|
|
|
|
GST_MINI_OBJECT_FLAG_SET (sink_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
|
|
|
GST_MINI_OBJECT_FLAG_SET (src_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
|
|
|
|
2017-07-27 14:51:07 +00:00
|
|
|
if (gst_v4l2_is_video_dec (sink_caps, src_caps)) {
|
|
|
|
gst_v4l2_video_dec_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2017-08-02 13:36:08 +00:00
|
|
|
} else if (gst_v4l2_is_video_enc (sink_caps, src_caps, NULL)) {
|
2018-09-10 19:20:52 +00:00
|
|
|
if (gst_v4l2_is_fwht_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_fwht_enc_register (plugin, basename, it->device_path,
|
|
|
|
sink_caps, src_caps);
|
|
|
|
|
2017-07-26 19:18:01 +00:00
|
|
|
if (gst_v4l2_is_h264_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_h264_enc_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2017-07-26 19:18:01 +00:00
|
|
|
|
2018-10-18 06:59:00 +00:00
|
|
|
if (gst_v4l2_is_h265_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_h265_enc_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2018-10-18 06:59:00 +00:00
|
|
|
|
2017-07-26 19:18:01 +00:00
|
|
|
if (gst_v4l2_is_mpeg4_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_mpeg4_enc_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2017-07-31 20:09:30 +00:00
|
|
|
|
|
|
|
if (gst_v4l2_is_h263_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_h263_enc_register (plugin, basename, it->device_path,
|
|
|
|
sink_caps, src_caps);
|
2018-09-10 16:18:30 +00:00
|
|
|
|
|
|
|
if (gst_v4l2_is_jpeg_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_jpeg_enc_register (plugin, basename, it->device_path,
|
|
|
|
sink_caps, src_caps);
|
2017-08-01 20:01:11 +00:00
|
|
|
|
|
|
|
if (gst_v4l2_is_vp8_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_vp8_enc_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2017-08-01 20:01:11 +00:00
|
|
|
|
|
|
|
if (gst_v4l2_is_vp9_enc (sink_caps, src_caps))
|
|
|
|
gst_v4l2_vp9_enc_register (plugin, basename, it->device_path,
|
2019-03-04 11:05:29 +00:00
|
|
|
video_fd, sink_caps, src_caps);
|
2017-07-27 14:51:07 +00:00
|
|
|
} else if (gst_v4l2_is_transform (sink_caps, src_caps)) {
|
|
|
|
gst_v4l2_transform_register (plugin, basename, it->device_path,
|
2014-03-04 23:31:27 +00:00
|
|
|
sink_caps, src_caps);
|
2017-07-27 14:51:07 +00:00
|
|
|
}
|
2014-05-03 01:38:30 +00:00
|
|
|
/* else if ( ... etc. */
|
|
|
|
|
|
|
|
gst_caps_unref (sink_caps);
|
|
|
|
gst_caps_unref (src_caps);
|
|
|
|
g_free (basename);
|
|
|
|
}
|
|
|
|
|
2014-05-05 11:07:25 +00:00
|
|
|
if (video_fd >= 0)
|
2014-05-03 01:38:30 +00:00
|
|
|
close (video_fd);
|
|
|
|
|
|
|
|
gst_v4l2_iterator_free (it);
|
|
|
|
|
2017-07-27 14:51:07 +00:00
|
|
|
return TRUE;
|
2014-05-03 01:38:30 +00:00
|
|
|
}
|
2015-11-13 17:35:59 +00:00
|
|
|
#endif
|
2003-09-13 08:58:49 +00:00
|
|
|
|
2003-11-03 22:47:52 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-09-13 08:58:49 +00:00
|
|
|
{
|
2021-02-16 14:29:06 +00:00
|
|
|
gboolean ret = FALSE;
|
2015-11-13 17:35:59 +00:00
|
|
|
const gchar *paths[] = { "/dev", "/dev/v4l2", NULL };
|
|
|
|
const gchar *names[] = { "video", NULL };
|
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* Add some dependency, so the dynamic features get updated upon changes in
|
2015-11-13 17:35:59 +00:00
|
|
|
* /dev/video* */
|
|
|
|
gst_plugin_add_dependency (plugin,
|
|
|
|
NULL, paths, names, GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX);
|
|
|
|
|
|
|
|
#ifdef GST_V4L2_ENABLE_PROBE
|
2021-02-16 14:29:06 +00:00
|
|
|
ret |= gst_v4l2_probe_and_register (plugin);
|
2015-11-13 17:35:59 +00:00
|
|
|
#endif
|
2003-09-13 08:58:49 +00:00
|
|
|
|
2021-02-16 14:29:06 +00:00
|
|
|
ret |= GST_ELEMENT_REGISTER (v4l2src, plugin);
|
|
|
|
ret |= GST_ELEMENT_REGISTER (v4l2sink, plugin);
|
|
|
|
ret |= GST_ELEMENT_REGISTER (v4l2radio, plugin);
|
|
|
|
ret |= GST_DEVICE_PROVIDER_REGISTER (v4l2deviceprovider, plugin);
|
2004-01-19 15:45:55 +00:00
|
|
|
|
2021-02-16 14:29:06 +00:00
|
|
|
return ret;
|
2003-09-13 08:58:49 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 15:36:38 +00:00
|
|
|
video4linux2,
|
2006-03-11 22:50:03 +00:00
|
|
|
"elements for Video 4 Linux",
|
2006-04-01 10:09:11 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|