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
|
|
|
*
|
2006-10-03 13:18:59 +00:00
|
|
|
* gstv4l2src.c: Video4Linux2 source element
|
2002-09-09 07:14:35 +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.
|
2002-09-09 07:14:35 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-17 19:43:32 +00:00
|
|
|
/**
|
2006-09-26 14:17:54 +00:00
|
|
|
* SECTION:element-v4l2src
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: v4l2src
|
2006-04-17 19:43:32 +00:00
|
|
|
*
|
2009-01-29 08:10:08 +00:00
|
|
|
* v4l2src can be used to capture video from v4l2 devices, like webcams and tv
|
|
|
|
* cards.
|
|
|
|
*
|
2018-10-22 09:39:24 +00:00
|
|
|
* ## Example launch lines
|
2009-01-29 08:10:08 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 v4l2src ! xvimagesink
|
2009-01-29 08:10:08 +00:00
|
|
|
* ]| This pipeline shows the video captured from /dev/video0 tv card and for
|
2006-10-03 13:18:59 +00:00
|
|
|
* webcams.
|
2009-01-29 08:10:08 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 v4l2src ! jpegdec ! xvimagesink
|
2009-01-29 08:10:08 +00:00
|
|
|
* ]| This pipeline shows the video captured from a webcam that delivers jpeg
|
2007-07-18 11:55:13 +00:00
|
|
|
* images.
|
2017-07-24 18:19:02 +00:00
|
|
|
*
|
|
|
|
* Since 1.14, the use of libv4l2 has been disabled due to major bugs in the
|
|
|
|
* emulation layer. To enable usage of this library, set the environment
|
|
|
|
* variable GST_V4L2_USE_LIBV4L2=1.
|
2006-04-17 19:43:32 +00:00
|
|
|
*/
|
|
|
|
|
2003-07-03 15:55:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-03-11 22:50:03 +00:00
|
|
|
#include <config.h>
|
2003-07-03 15:55:12 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-09 07:14:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
2006-03-11 22:50:03 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-04-16 22:06:21 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
#include <gst/video/gstvideopool.h>
|
2011-07-27 11:43:08 +00:00
|
|
|
|
2021-02-16 14:29:06 +00:00
|
|
|
#include "gstv4l2elements.h"
|
2011-07-13 16:32:00 +00:00
|
|
|
#include "gstv4l2src.h"
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
#include "gstv4l2colorbalance.h"
|
|
|
|
#include "gstv4l2tuner.h"
|
2006-09-19 13:08:35 +00:00
|
|
|
#include "gstv4l2vidorient.h"
|
2006-03-11 22:50:03 +00:00
|
|
|
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
GST_DEBUG_CATEGORY (v4l2src_debug);
|
|
|
|
#define GST_CAT_DEFAULT v4l2src_debug
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
#define DEFAULT_PROP_DEVICE "/dev/video0"
|
|
|
|
|
2006-05-18 19:34:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
V4L2_STD_OBJECT_PROPS,
|
2021-10-14 08:22:19 +00:00
|
|
|
PROP_CROP_TOP,
|
|
|
|
PROP_CROP_LEFT,
|
|
|
|
PROP_CROP_BOTTOM,
|
|
|
|
PROP_CROP_RIGHT,
|
|
|
|
PROP_CROP_BOUNDS,
|
2012-09-13 08:56:27 +00:00
|
|
|
PROP_LAST
|
2006-05-18 19:34:47 +00:00
|
|
|
};
|
|
|
|
|
2012-04-16 22:06:21 +00:00
|
|
|
/* signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_PRE_SET_FORMAT,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_v4l2_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2006-05-18 19:34:47 +00:00
|
|
|
GST_IMPLEMENT_V4L2_COLOR_BALANCE_METHODS (GstV4l2Src, gst_v4l2src);
|
|
|
|
GST_IMPLEMENT_V4L2_TUNER_METHODS (GstV4l2Src, gst_v4l2src);
|
2006-09-19 13:08:35 +00:00
|
|
|
GST_IMPLEMENT_V4L2_VIDORIENT_METHODS (GstV4l2Src, gst_v4l2src);
|
2006-05-18 19:34:47 +00:00
|
|
|
|
2009-11-08 10:49:14 +00:00
|
|
|
static void gst_v4l2src_uri_handler_init (gpointer g_iface,
|
|
|
|
gpointer iface_data);
|
|
|
|
|
2011-07-08 10:49:12 +00:00
|
|
|
#define gst_v4l2src_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstV4l2Src, gst_v4l2src, GST_TYPE_PUSH_SRC,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_v4l2src_uri_handler_init);
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER, gst_v4l2src_tuner_interface_init);
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE,
|
|
|
|
gst_v4l2src_color_balance_interface_init);
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION,
|
2011-12-21 10:59:46 +00:00
|
|
|
gst_v4l2src_video_orientation_interface_init));
|
2021-02-16 14:29:06 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2src,
|
|
|
|
"v4l2src", GST_RANK_PRIMARY, GST_TYPE_V4L2SRC, v4l2_element_init (plugin));
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
struct PreferredCapsInfo
|
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint fps_n;
|
|
|
|
gint fps_d;
|
|
|
|
};
|
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
static void gst_v4l2src_finalize (GstV4l2Src * v4l2src);
|
2003-05-02 21:16:56 +00:00
|
|
|
|
2009-06-22 12:56:58 +00:00
|
|
|
/* element methods */
|
|
|
|
static GstStateChangeReturn gst_v4l2src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
/* basesrc methods */
|
|
|
|
static gboolean gst_v4l2src_start (GstBaseSrc * src);
|
2009-03-01 18:55:26 +00:00
|
|
|
static gboolean gst_v4l2src_unlock (GstBaseSrc * src);
|
|
|
|
static gboolean gst_v4l2src_unlock_stop (GstBaseSrc * src);
|
2006-03-11 22:50:03 +00:00
|
|
|
static gboolean gst_v4l2src_stop (GstBaseSrc * src);
|
2011-07-08 10:49:12 +00:00
|
|
|
static GstCaps *gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter);
|
2007-09-05 14:43:16 +00:00
|
|
|
static gboolean gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query);
|
2011-08-26 12:20:49 +00:00
|
|
|
static gboolean gst_v4l2src_decide_allocation (GstBaseSrc * src,
|
2011-07-15 14:55:50 +00:00
|
|
|
GstQuery * query);
|
2014-04-29 17:05:41 +00:00
|
|
|
static GstFlowReturn gst_v4l2src_create (GstPushSrc * src, GstBuffer ** out);
|
2017-07-20 02:25:49 +00:00
|
|
|
static GstCaps *gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
|
2021-02-10 15:48:48 +00:00
|
|
|
struct PreferredCapsInfo *pref);
|
2008-06-04 17:39:31 +00:00
|
|
|
static gboolean gst_v4l2src_negotiate (GstBaseSrc * basesrc);
|
|
|
|
|
2006-05-18 19:34:47 +00:00
|
|
|
static void gst_v4l2src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2006-03-25 05:31:28 +00:00
|
|
|
static void gst_v4l2src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2006-03-11 22:50:03 +00:00
|
|
|
|
2002-09-09 07:14:35 +00:00
|
|
|
static void
|
2006-03-11 22:50:03 +00:00
|
|
|
gst_v4l2src_class_init (GstV4l2SrcClass * klass)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2006-03-11 22:50:03 +00:00
|
|
|
GObjectClass *gobject_class;
|
2009-06-22 12:56:58 +00:00
|
|
|
GstElementClass *element_class;
|
2006-03-11 22:50:03 +00:00
|
|
|
GstBaseSrcClass *basesrc_class;
|
|
|
|
GstPushSrcClass *pushsrc_class;
|
2004-01-12 02:19:57 +00:00
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2009-06-22 12:56:58 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
2006-03-11 22:50:03 +00:00
|
|
|
basesrc_class = GST_BASE_SRC_CLASS (klass);
|
|
|
|
pushsrc_class = GST_PUSH_SRC_CLASS (klass);
|
2004-01-12 02:19:57 +00:00
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
gobject_class->finalize = (GObjectFinalizeFunc) gst_v4l2src_finalize;
|
2004-01-12 02:19:57 +00:00
|
|
|
gobject_class->set_property = gst_v4l2src_set_property;
|
|
|
|
gobject_class->get_property = gst_v4l2src_get_property;
|
|
|
|
|
2009-06-22 12:56:58 +00:00
|
|
|
element_class->change_state = gst_v4l2src_change_state;
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
gst_v4l2_object_install_properties_helper (gobject_class,
|
|
|
|
DEFAULT_PROP_DEVICE);
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
/**
|
|
|
|
* GstV4l2Src:crop-top:
|
|
|
|
*
|
|
|
|
* Number of pixels to crop from the top edge of captured video
|
|
|
|
* stream
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CROP_TOP,
|
|
|
|
g_param_spec_uint ("crop-top", "Crop top",
|
|
|
|
"Pixels to crop at top of video capture input",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstV4l2Src:crop-left:
|
|
|
|
*
|
|
|
|
* Number of pixels to crop from the left edge of captured video
|
|
|
|
* stream
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CROP_LEFT,
|
|
|
|
g_param_spec_uint ("crop-left", "Crop left",
|
|
|
|
"Pixels to crop at left of video capture input",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstV4l2Src:crop-bottom:
|
|
|
|
*
|
|
|
|
* Number of pixels to crop from the bottom edge of captured video
|
|
|
|
* stream
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CROP_BOTTOM,
|
|
|
|
g_param_spec_uint ("crop-bottom", "Crop bottom",
|
|
|
|
"Pixels to crop at bottom of video capture input",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstV4l2Src:crop-right:
|
|
|
|
*
|
|
|
|
* Number of pixels to crop from the right edge of captured video
|
|
|
|
* stream
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CROP_RIGHT,
|
|
|
|
g_param_spec_uint ("crop-right", "Crop right",
|
|
|
|
"Pixels to crop at right of video capture input",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstV4l2Src:crop-bounds:
|
|
|
|
*
|
|
|
|
* Crop bounding region. All crop regions must lie within this region.
|
|
|
|
* The bounds are represented as a four element array, that descibes the
|
|
|
|
* [x, y, width, height] of the area.
|
|
|
|
*
|
|
|
|
* The size and position of the crop
|
|
|
|
* bounds will only be known, once the v4l2 device is opened and the
|
|
|
|
* input source selected. Applications can connect to the
|
|
|
|
* "notify::crop-bounds" signal to be notified when the bounding region is
|
|
|
|
* updated, and set an appropriate crop region.
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CROP_BOUNDS,
|
|
|
|
gst_param_spec_array ("crop-bounds", "Crop bounds",
|
|
|
|
"The bounding region for crop rectangles ('<x, y, width, height>').",
|
|
|
|
g_param_spec_int ("rect-value", "Rectangle Value",
|
|
|
|
"One of x, y, width or height value.", G_MININT, G_MAXINT, -1,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS),
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-04-16 22:06:21 +00:00
|
|
|
/**
|
2012-04-19 07:40:53 +00:00
|
|
|
* GstV4l2Src::prepare-format:
|
2012-04-16 22:06:21 +00:00
|
|
|
* @v4l2src: the v4l2src instance
|
|
|
|
* @fd: the file descriptor of the current device
|
2013-01-08 07:56:45 +00:00
|
|
|
* @caps: the caps of the format being set
|
2012-04-16 22:06:21 +00:00
|
|
|
*
|
|
|
|
* This signal gets emitted before calling the v4l2 VIDIOC_S_FMT ioctl
|
|
|
|
* (set format). This allows for any custom configuration of the device to
|
|
|
|
* happen prior to the format being set.
|
|
|
|
* This is mostly useful for UVC H264 encoding cameras which need the H264
|
|
|
|
* Probe & Commit to happen prior to the normal Probe & Commit.
|
|
|
|
*/
|
2012-04-19 07:40:53 +00:00
|
|
|
gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT] = g_signal_new ("prepare-format",
|
2012-04-16 22:06:21 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2013-01-08 07:56:45 +00:00
|
|
|
0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_INT, GST_TYPE_CAPS);
|
2012-04-16 22:06:21 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2011-07-08 10:49:12 +00:00
|
|
|
"Video (video4linux2) Source", "Source/Video",
|
|
|
|
"Reads frames from a Video4Linux2 device",
|
2017-02-26 00:47:03 +00:00
|
|
|
"Edgard Lima <edgard.lima@gmail.com>, "
|
2011-07-11 10:04:57 +00:00
|
|
|
"Stefan Kost <ensonic@users.sf.net>");
|
2011-07-08 10:49:12 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template
|
|
|
|
(element_class,
|
|
|
|
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|
|
|
gst_v4l2_object_get_all_caps ()));
|
|
|
|
|
2007-09-05 14:43:16 +00:00
|
|
|
basesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2src_get_caps);
|
|
|
|
basesrc_class->start = GST_DEBUG_FUNCPTR (gst_v4l2src_start);
|
2009-03-01 18:55:26 +00:00
|
|
|
basesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock);
|
|
|
|
basesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_v4l2src_unlock_stop);
|
2007-09-05 14:43:16 +00:00
|
|
|
basesrc_class->stop = GST_DEBUG_FUNCPTR (gst_v4l2src_stop);
|
|
|
|
basesrc_class->query = GST_DEBUG_FUNCPTR (gst_v4l2src_query);
|
2008-06-04 17:39:31 +00:00
|
|
|
basesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_v4l2src_negotiate);
|
2011-08-26 12:20:49 +00:00
|
|
|
basesrc_class->decide_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_v4l2src_decide_allocation);
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2014-04-29 17:05:41 +00:00
|
|
|
pushsrc_class->create = GST_DEBUG_FUNCPTR (gst_v4l2src_create);
|
2011-07-08 10:49:12 +00:00
|
|
|
|
|
|
|
klass->v4l2_class_devices = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (v4l2src_debug, "v4l2src", 0, "V4L2 source element");
|
2006-03-11 22:50:03 +00:00
|
|
|
}
|
2002-09-09 07:14:35 +00:00
|
|
|
|
|
|
|
static void
|
2011-07-08 10:49:12 +00:00
|
|
|
gst_v4l2src_init (GstV4l2Src * v4l2src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
sys/v4l2/v4l2src_calls.*: Store the format list in the order that the driver gives it to us.
Original commit message from CVS:
2007-05-30 Andy Wingo <wingo@pobox.com>
* sys/v4l2/v4l2src_calls.h:
* sys/v4l2/v4l2src_calls.c (gst_v4l2src_fill_format_list): Store
the format list in the order that the driver gives it to us.
(gst_v4l2src_probe_caps_for_format_and_size)
(gst_v4l2src_probe_caps_for_format): New functions, fill GstCaps
based on the capabilities of the device.
(gst_v4l2src_grab_frame): Update for object variable renaming.
(gst_v4l2src_set_capture): Update to be strict in its parameters,
as in the set_caps below.
(gst_v4l2src_capture_init): Update for object variable renaming,
and reflow.
(gst_v4l2src_capture_start, gst_v4l2src_capture_stop)
(gst_v4l2src_capture_deinit): Update for object variable renaming.
(gst_v4l2src_update_fps, gst_v4l2src_set_fps)
(gst_v4l2src_get_fps): Remove; these functions don't have much
meaning outside of an atomic set_caps method.
(gst_v4l2src_buffer_new): Don't set buffer duration, it is not
known.
* sys/v4l2/gstv4l2tuner.c (gst_v4l2_tuner_set_channel): Remove
call to update_fps; not sure about this change.
(gst_v4l2_tuner_set_norm): Work around the fact that for the
moment we don't have an update_fps_func.
* sys/v4l2/gstv4l2src.h (struct _GstV4l2Src): Don't put v4l2
structures in the object, just store what we need. Do store the
probed caps of the device. Don't store the current frame rate.
* sys/v4l2/gstv4l2src.c (gst_v4l2src_init): Remove the
update_fps_function, for now. Update for new object variable
naming.
(gst_v4l2src_set_property, gst_v4l2src_get_property): Update for
new object variable naming.
(gst_v4l2src_v4l2fourcc_to_structure): Rename from ..._to_caps.
(gst_v4l2_structure_to_v4l2fourcc): Rename from ...caps_to_....
(gst_v4l2src_get_caps): Rework to probe the device for supported
frame sizes and frame rates.
(gst_v4l2src_set_caps): Rework to be strict in the given
parameters: if someone asks us to have a certain size and rate,
that is what we configure.
(gst_v4l2src_get_read): Update for object variable naming. Don't
leak buffers on short reads.
(gst_v4l2src_get_mmap): Update for object variable naming, and add
comments.
(gst_v4l2src_create): Update for object variable naming.
2007-05-30 14:40:53 +00:00
|
|
|
/* fixme: give an update_fps_function */
|
2006-05-19 18:31:25 +00:00
|
|
|
v4l2src->v4l2object = gst_v4l2_object_new (GST_ELEMENT (v4l2src),
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_OBJECT (GST_BASE_SRC_PAD (v4l2src)), V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
|
|
|
DEFAULT_PROP_DEVICE, gst_v4l2_get_input, gst_v4l2_set_input, NULL);
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
/* Avoid the slow probes */
|
|
|
|
v4l2src->v4l2object->skip_try_fmt_probes = TRUE;
|
|
|
|
|
2006-08-30 13:30:13 +00:00
|
|
|
gst_base_src_set_format (GST_BASE_SRC (v4l2src), GST_FORMAT_TIME);
|
2006-03-11 22:50:03 +00:00
|
|
|
gst_base_src_set_live (GST_BASE_SRC (v4l2src), TRUE);
|
2002-11-13 12:35:56 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 11:35:29 +00:00
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2src_finalize (GstV4l2Src * v4l2src)
|
|
|
|
{
|
|
|
|
gst_v4l2_object_destroy (v4l2src->v4l2object);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize ((GObject *) (v4l2src));
|
|
|
|
}
|
2006-04-13 21:45:57 +00:00
|
|
|
|
2007-07-17 11:35:29 +00:00
|
|
|
|
2002-11-13 12:35:56 +00:00
|
|
|
static void
|
2006-03-11 22:50:03 +00:00
|
|
|
gst_v4l2src_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
2002-11-13 12:35:56 +00:00
|
|
|
{
|
sys/v4l2/v4l2src_calls.*: Store the format list in the order that the driver gives it to us.
Original commit message from CVS:
2007-05-30 Andy Wingo <wingo@pobox.com>
* sys/v4l2/v4l2src_calls.h:
* sys/v4l2/v4l2src_calls.c (gst_v4l2src_fill_format_list): Store
the format list in the order that the driver gives it to us.
(gst_v4l2src_probe_caps_for_format_and_size)
(gst_v4l2src_probe_caps_for_format): New functions, fill GstCaps
based on the capabilities of the device.
(gst_v4l2src_grab_frame): Update for object variable renaming.
(gst_v4l2src_set_capture): Update to be strict in its parameters,
as in the set_caps below.
(gst_v4l2src_capture_init): Update for object variable renaming,
and reflow.
(gst_v4l2src_capture_start, gst_v4l2src_capture_stop)
(gst_v4l2src_capture_deinit): Update for object variable renaming.
(gst_v4l2src_update_fps, gst_v4l2src_set_fps)
(gst_v4l2src_get_fps): Remove; these functions don't have much
meaning outside of an atomic set_caps method.
(gst_v4l2src_buffer_new): Don't set buffer duration, it is not
known.
* sys/v4l2/gstv4l2tuner.c (gst_v4l2_tuner_set_channel): Remove
call to update_fps; not sure about this change.
(gst_v4l2_tuner_set_norm): Work around the fact that for the
moment we don't have an update_fps_func.
* sys/v4l2/gstv4l2src.h (struct _GstV4l2Src): Don't put v4l2
structures in the object, just store what we need. Do store the
probed caps of the device. Don't store the current frame rate.
* sys/v4l2/gstv4l2src.c (gst_v4l2src_init): Remove the
update_fps_function, for now. Update for new object variable
naming.
(gst_v4l2src_set_property, gst_v4l2src_get_property): Update for
new object variable naming.
(gst_v4l2src_v4l2fourcc_to_structure): Rename from ..._to_caps.
(gst_v4l2_structure_to_v4l2fourcc): Rename from ...caps_to_....
(gst_v4l2src_get_caps): Rework to probe the device for supported
frame sizes and frame rates.
(gst_v4l2src_set_caps): Rework to be strict in the given
parameters: if someone asks us to have a certain size and rate,
that is what we configure.
(gst_v4l2src_get_read): Update for object variable naming. Don't
leak buffers on short reads.
(gst_v4l2src_get_mmap): Update for object variable naming, and add
comments.
(gst_v4l2src_create): Update for object variable naming.
2007-05-30 14:40:53 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (object);
|
2002-09-09 07:14:35 +00:00
|
|
|
|
2006-05-19 18:31:25 +00:00
|
|
|
if (!gst_v4l2_object_set_property_helper (v4l2src->v4l2object,
|
2006-05-11 17:59:59 +00:00
|
|
|
prop_id, value, pspec)) {
|
|
|
|
switch (prop_id) {
|
2021-10-14 08:22:19 +00:00
|
|
|
case PROP_CROP_TOP:
|
|
|
|
v4l2src->crop_top = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_LEFT:
|
|
|
|
v4l2src->crop_left = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_BOTTOM:
|
|
|
|
v4l2src->crop_bottom = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_RIGHT:
|
|
|
|
v4l2src->crop_right = g_value_get_uint (value);
|
|
|
|
break;
|
2006-05-11 17:59:59 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2006-03-11 22:50:03 +00:00
|
|
|
}
|
2002-09-16 21:01:43 +00:00
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2src_set_rect_value (GValue * value, struct v4l2_rect *rect)
|
|
|
|
{
|
|
|
|
GValue val = { 0 };
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_INT);
|
|
|
|
g_value_reset (value);
|
|
|
|
|
|
|
|
g_value_set_int (&val, rect->left);
|
|
|
|
gst_value_array_append_value (value, &val);
|
|
|
|
|
|
|
|
g_value_set_int (&val, rect->top);
|
|
|
|
gst_value_array_append_value (value, &val);
|
|
|
|
|
|
|
|
g_value_set_int (&val, rect->width);
|
|
|
|
gst_value_array_append_value (value, &val);
|
|
|
|
|
|
|
|
g_value_set_int (&val, rect->height);
|
|
|
|
gst_value_array_append_value (value, &val);
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2src_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
sys/v4l2/v4l2src_calls.*: Store the format list in the order that the driver gives it to us.
Original commit message from CVS:
2007-05-30 Andy Wingo <wingo@pobox.com>
* sys/v4l2/v4l2src_calls.h:
* sys/v4l2/v4l2src_calls.c (gst_v4l2src_fill_format_list): Store
the format list in the order that the driver gives it to us.
(gst_v4l2src_probe_caps_for_format_and_size)
(gst_v4l2src_probe_caps_for_format): New functions, fill GstCaps
based on the capabilities of the device.
(gst_v4l2src_grab_frame): Update for object variable renaming.
(gst_v4l2src_set_capture): Update to be strict in its parameters,
as in the set_caps below.
(gst_v4l2src_capture_init): Update for object variable renaming,
and reflow.
(gst_v4l2src_capture_start, gst_v4l2src_capture_stop)
(gst_v4l2src_capture_deinit): Update for object variable renaming.
(gst_v4l2src_update_fps, gst_v4l2src_set_fps)
(gst_v4l2src_get_fps): Remove; these functions don't have much
meaning outside of an atomic set_caps method.
(gst_v4l2src_buffer_new): Don't set buffer duration, it is not
known.
* sys/v4l2/gstv4l2tuner.c (gst_v4l2_tuner_set_channel): Remove
call to update_fps; not sure about this change.
(gst_v4l2_tuner_set_norm): Work around the fact that for the
moment we don't have an update_fps_func.
* sys/v4l2/gstv4l2src.h (struct _GstV4l2Src): Don't put v4l2
structures in the object, just store what we need. Do store the
probed caps of the device. Don't store the current frame rate.
* sys/v4l2/gstv4l2src.c (gst_v4l2src_init): Remove the
update_fps_function, for now. Update for new object variable
naming.
(gst_v4l2src_set_property, gst_v4l2src_get_property): Update for
new object variable naming.
(gst_v4l2src_v4l2fourcc_to_structure): Rename from ..._to_caps.
(gst_v4l2_structure_to_v4l2fourcc): Rename from ...caps_to_....
(gst_v4l2src_get_caps): Rework to probe the device for supported
frame sizes and frame rates.
(gst_v4l2src_set_caps): Rework to be strict in the given
parameters: if someone asks us to have a certain size and rate,
that is what we configure.
(gst_v4l2src_get_read): Update for object variable naming. Don't
leak buffers on short reads.
(gst_v4l2src_get_mmap): Update for object variable naming, and add
comments.
(gst_v4l2src_create): Update for object variable naming.
2007-05-30 14:40:53 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (object);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2006-05-19 18:31:25 +00:00
|
|
|
if (!gst_v4l2_object_get_property_helper (v4l2src->v4l2object,
|
2006-05-11 17:59:59 +00:00
|
|
|
prop_id, value, pspec)) {
|
|
|
|
switch (prop_id) {
|
2021-10-14 08:22:19 +00:00
|
|
|
case PROP_CROP_TOP:
|
|
|
|
g_value_set_uint (value, v4l2src->crop_top);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_LEFT:
|
|
|
|
g_value_set_uint (value, v4l2src->crop_left);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_BOTTOM:
|
|
|
|
g_value_set_uint (value, v4l2src->crop_bottom);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_RIGHT:
|
|
|
|
g_value_set_uint (value, v4l2src->crop_right);
|
|
|
|
break;
|
|
|
|
case PROP_CROP_BOUNDS:
|
|
|
|
gst_v4l2src_set_rect_value (value, &v4l2src->crop_bounds);
|
|
|
|
break;
|
2006-05-11 17:59:59 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-09-16 21:01:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vl42_src_fixate_fields (GQuark field_id, GValue * value, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstStructure *s = user_data;
|
|
|
|
|
|
|
|
if (field_id == g_quark_from_string ("interlace-mode"))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (field_id == g_quark_from_string ("colorimetry"))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gst_structure_fixate_field (s, g_quark_to_string (field_id));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4l2_src_fixate_struct_with_preference (GstStructure * s,
|
2021-02-10 15:48:48 +00:00
|
|
|
struct PreferredCapsInfo *pref)
|
2017-07-20 02:25:49 +00:00
|
|
|
{
|
2017-09-13 20:05:08 +00:00
|
|
|
if (gst_structure_has_field (s, "width"))
|
2017-07-20 02:25:49 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "width", pref->width);
|
|
|
|
|
2017-09-13 20:05:08 +00:00
|
|
|
if (gst_structure_has_field (s, "height"))
|
2017-07-20 02:25:49 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "height", pref->height);
|
|
|
|
|
2017-09-13 20:05:08 +00:00
|
|
|
if (gst_structure_has_field (s, "framerate"))
|
2017-07-20 02:25:49 +00:00
|
|
|
gst_structure_fixate_field_nearest_fraction (s, "framerate", pref->fps_n,
|
|
|
|
pref->fps_d);
|
|
|
|
|
|
|
|
/* Finally, fixate everything else except the interlace-mode and colorimetry
|
|
|
|
* which still need further negotiation as it wasn't probed */
|
|
|
|
gst_structure_map_in_place (s, gst_vl42_src_fixate_fields, s);
|
|
|
|
}
|
|
|
|
|
2017-09-13 20:05:08 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_src_parse_fixed_struct (GstStructure * s,
|
|
|
|
gint * width, gint * height, gint * fps_n, gint * fps_d)
|
|
|
|
{
|
|
|
|
if (gst_structure_has_field (s, "width") && width)
|
|
|
|
gst_structure_get_int (s, "width", width);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (s, "height") && height)
|
|
|
|
gst_structure_get_int (s, "height", height);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (s, "framerate") && fps_n && fps_d)
|
|
|
|
gst_structure_get_fraction (s, "framerate", fps_n, fps_d);
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
static gint
|
2019-01-24 10:54:49 +00:00
|
|
|
gst_v4l2src_fixed_caps_compare (GstCaps * caps_a, GstCaps * caps_b,
|
2021-02-10 15:48:48 +00:00
|
|
|
struct PreferredCapsInfo *pref)
|
2017-07-20 02:25:49 +00:00
|
|
|
{
|
2019-01-24 10:54:49 +00:00
|
|
|
GstStructure *a, *b;
|
2023-12-07 04:42:32 +00:00
|
|
|
gint aw = G_MAXINT, ah = G_MAXINT;
|
|
|
|
gint bw = G_MAXINT, bh = G_MAXINT;
|
|
|
|
gint a_fps_n = G_MAXINT, a_fps_d = 1;
|
|
|
|
gint b_fps_n = G_MAXINT, b_fps_d = 1;
|
|
|
|
gint a_distance, b_distance;
|
2017-07-20 02:25:49 +00:00
|
|
|
|
2019-01-24 10:54:49 +00:00
|
|
|
a = gst_caps_get_structure (caps_a, 0);
|
|
|
|
b = gst_caps_get_structure (caps_b, 0);
|
|
|
|
|
2023-12-07 04:42:32 +00:00
|
|
|
gst_v4l2_src_parse_fixed_struct (a, &aw, &ah, &a_fps_n, &a_fps_d);
|
|
|
|
gst_v4l2_src_parse_fixed_struct (b, &bw, &bh, &b_fps_n, &b_fps_d);
|
2017-07-20 02:25:49 +00:00
|
|
|
|
2023-12-07 04:42:32 +00:00
|
|
|
// Sort first the one with closest framerate to preference. Note that any
|
|
|
|
// framerate lower then 1 frame per second will be considered the same. In
|
|
|
|
// practice this should be fine considering that these framerate only exists
|
|
|
|
// for still picture, in which case the resolution is most likely the key.
|
|
|
|
a_distance = ABS ((a_fps_n / a_fps_d) - (pref->fps_n / pref->fps_d));
|
|
|
|
b_distance = ABS ((b_fps_n / b_fps_d) - (pref->fps_n / pref->fps_d));
|
|
|
|
if (a_distance != b_distance)
|
|
|
|
return a_distance - b_distance;
|
2017-07-20 02:25:49 +00:00
|
|
|
|
2023-12-07 04:42:32 +00:00
|
|
|
// If same framerate, sort first the one with closest resolution to preference
|
|
|
|
a_distance = ABS (aw * ah - pref->width * pref->height);
|
|
|
|
b_distance = ABS (bw * bh - pref->width * pref->height);
|
2018-01-11 22:47:39 +00:00
|
|
|
|
2023-12-07 04:42:32 +00:00
|
|
|
gint ret = a_distance - b_distance;
|
2018-01-11 22:47:39 +00:00
|
|
|
|
2023-12-07 04:42:32 +00:00
|
|
|
GST_TRACE ("Placing %" GST_PTR_FORMAT " %s %" GST_PTR_FORMAT,
|
|
|
|
caps_a, ret > 0 ? "after" : "before", caps_b);
|
2018-01-11 22:47:39 +00:00
|
|
|
|
|
|
|
return ret;
|
2017-07-20 02:25:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_do_source_crop (GstV4l2Src * v4l2src)
|
|
|
|
{
|
|
|
|
struct v4l2_rect def_crop;
|
|
|
|
|
|
|
|
if (v4l2src->apply_crop_settings)
|
|
|
|
return gst_v4l2_object_set_crop (v4l2src->v4l2object, &v4l2src->crop_rect);
|
|
|
|
|
|
|
|
/* If no crop setting is given, reset to the default. Resetting the default
|
|
|
|
* crop may fail if the device does not support cropping. This should not
|
|
|
|
* be considered an error. */
|
|
|
|
if (gst_v4l2_object_get_crop_default (v4l2src->v4l2object, &def_crop))
|
|
|
|
gst_v4l2_object_set_crop (v4l2src->v4l2object, &def_crop);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_set_format (GstV4l2Src * v4l2src, GstCaps * caps,
|
|
|
|
GstV4l2Error * error)
|
|
|
|
{
|
|
|
|
GstV4l2Object *obj;
|
|
|
|
|
|
|
|
obj = v4l2src->v4l2object;
|
|
|
|
|
|
|
|
/* make sure we stop capturing and dealloc buffers */
|
|
|
|
if (!gst_v4l2_object_stop (obj))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_signal_emit (v4l2src, gst_v4l2_signals[SIGNAL_PRE_SET_FORMAT], 0,
|
|
|
|
v4l2src->v4l2object->video_fd, caps);
|
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
if (!gst_v4l2src_do_source_crop (v4l2src))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
return gst_v4l2_object_set_format (obj, caps, error);
|
|
|
|
}
|
|
|
|
|
2012-03-11 18:06:37 +00:00
|
|
|
static GstCaps *
|
2021-02-10 15:48:48 +00:00
|
|
|
gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
|
|
|
|
struct PreferredCapsInfo *pref)
|
configure.ac: Improve mpeg2enc detection. This is for distributions that do ship mjpegtools, but without mpeg2enc. Al...
Original commit message from CVS:
2003-12-21 Ronald Bultje <rbultje@ronald.bitfreak.net>
* configure.ac:
Improve mpeg2enc detection. This is for distributions that do
ship mjpegtools, but without mpeg2enc. Also does object check
for might there ever be ABI incompatibility.
* ext/mpeg2enc/gstmpeg2enc.cc:
Add Andrew as second maintainer (he's helping me), and also add
an error if no caps was set. This happens if I pull before capsnego
and that's something I should solve sometime else.
* gst/matroska/matroska-demux.c:
(gst_matroska_demux_parse_blockgroup):
Fix time parsing.
* gst/matroska/matroska-mux.c: (gst_matroska_mux_audio_pad_link),
(gst_matroska_mux_track_header):
Add caps to templates.
* gst/mpegaudioparse/gstmpegaudioparse.c: (mp3_sink_factory):
Add mpegversion=1 to prevent confusion with MPEG/AAC.
* gst/mpegstream/gstmpegdemux.c:
Remove layer since it causes warnings about unfixed caps.
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_get):
Fix obvious typo (we error out if caps were set, we should of
course error out if *no* caps were set).
* sys/oss/gstosselement.c: (gst_osselement_convert):
Fix format conversion, we confused bits/bytes.
* sys/oss/gstosselement.h:
Improve documentation for 'bps'.
* sys/v4l/TODO:
Remove stuff about plugins that need removing - this was done
ages ago.
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_init),
(gst_v4lmjpegsrc_src_convert), (gst_v4lmjpegsrc_src_query):
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_init), (gst_v4lsrc_src_convert),
(gst_v4lsrc_src_query):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_init),
(gst_v4l2src_src_convert), (gst_v4l2src_src_query):
Add get_query_types(), get_formats() and query() functions.
2003-12-21 18:44:34 +00:00
|
|
|
{
|
2017-07-20 02:25:49 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (basesrc);
|
|
|
|
GstV4l2Object *obj = v4l2src->v4l2object;
|
|
|
|
GList *caps_list = NULL;
|
|
|
|
GstStructure *s;
|
|
|
|
gint i = G_MAXINT;
|
|
|
|
GstV4l2Error error = GST_V4L2_ERROR_INIT;
|
|
|
|
GstCaps *fcaps = NULL;
|
configure.ac: Improve mpeg2enc detection. This is for distributions that do ship mjpegtools, but without mpeg2enc. Al...
Original commit message from CVS:
2003-12-21 Ronald Bultje <rbultje@ronald.bitfreak.net>
* configure.ac:
Improve mpeg2enc detection. This is for distributions that do
ship mjpegtools, but without mpeg2enc. Also does object check
for might there ever be ABI incompatibility.
* ext/mpeg2enc/gstmpeg2enc.cc:
Add Andrew as second maintainer (he's helping me), and also add
an error if no caps was set. This happens if I pull before capsnego
and that's something I should solve sometime else.
* gst/matroska/matroska-demux.c:
(gst_matroska_demux_parse_blockgroup):
Fix time parsing.
* gst/matroska/matroska-mux.c: (gst_matroska_mux_audio_pad_link),
(gst_matroska_mux_track_header):
Add caps to templates.
* gst/mpegaudioparse/gstmpegaudioparse.c: (mp3_sink_factory):
Add mpegversion=1 to prevent confusion with MPEG/AAC.
* gst/mpegstream/gstmpegdemux.c:
Remove layer since it causes warnings about unfixed caps.
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_get):
Fix obvious typo (we error out if caps were set, we should of
course error out if *no* caps were set).
* sys/oss/gstosselement.c: (gst_osselement_convert):
Fix format conversion, we confused bits/bytes.
* sys/oss/gstosselement.h:
Improve documentation for 'bps'.
* sys/v4l/TODO:
Remove stuff about plugins that need removing - this was done
ages ago.
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_init),
(gst_v4lmjpegsrc_src_convert), (gst_v4lmjpegsrc_src_query):
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_init), (gst_v4lsrc_src_convert),
(gst_v4lsrc_src_query):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_init),
(gst_v4l2src_src_convert), (gst_v4l2src_src_query):
Add get_query_types(), get_formats() and query() functions.
2003-12-21 18:44:34 +00:00
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "Fixating caps %" GST_PTR_FORMAT, caps);
|
|
|
|
GST_DEBUG_OBJECT (basesrc, "Preferred size %ix%i", pref->width, pref->height);
|
2018-01-11 22:47:39 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
/* Sort the structures to get the caps that is nearest to our preferences,
|
2019-01-24 10:54:49 +00:00
|
|
|
* first. Use single struct caps for sorting so we preserve the features. */
|
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
GstCaps *tmp = gst_caps_copy_nth (caps, i);
|
|
|
|
|
|
|
|
s = gst_caps_get_structure (tmp, 0);
|
2021-02-10 15:48:48 +00:00
|
|
|
gst_v4l2_src_fixate_struct_with_preference (s, pref);
|
2019-01-24 10:54:49 +00:00
|
|
|
|
|
|
|
caps_list = g_list_insert_sorted_with_data (caps_list, tmp,
|
2021-02-10 15:48:48 +00:00
|
|
|
(GCompareDataFunc) gst_v4l2src_fixed_caps_compare, pref);
|
2017-09-13 20:05:08 +00:00
|
|
|
}
|
2014-03-29 23:13:06 +00:00
|
|
|
|
2019-01-24 10:54:49 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = gst_caps_new_empty ();
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
while (caps_list) {
|
2019-01-24 10:54:49 +00:00
|
|
|
GstCaps *tmp = caps_list->data;
|
2017-07-20 02:25:49 +00:00
|
|
|
caps_list = g_list_delete_link (caps_list, caps_list);
|
2019-01-24 10:54:49 +00:00
|
|
|
gst_caps_append (caps, tmp);
|
2017-07-20 02:25:49 +00:00
|
|
|
}
|
2014-03-29 23:13:06 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "sorted and normalized caps %" GST_PTR_FORMAT,
|
|
|
|
caps);
|
2014-03-29 23:13:06 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
/* Each structure in the caps has been fixated, except for the
|
|
|
|
* interlace-mode and colorimetry. Now normalize the caps so we can
|
|
|
|
* enumerate the possibilities */
|
|
|
|
caps = gst_caps_normalize (caps);
|
v4l2: Clean up interlace support
Rather than try and guess interlace support as part of checking supported
sizes, look for interlace support specifically in its own function.
As a cleanup, use V4L2_FIELD_ANY when probing sizes, which should result in
the driver doing the right thing.
With my capture setup, this gets me the following sample caps:
For 1080i resolution:
video/x-raw, format=(string)YUY2, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)interleaved, framerate=(fraction){ 25/1, 30/1 }
For 720p resolution:
video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=(fraction){ 50/1, 60/1 }
For 576i/p resolution (both possible at the point of query):
video/x-raw, format=(string)YUY2, width=(int)720, height=(int)576, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string){ progressive, interleaved }, framerate=(fraction){ 25/1, 50/1 }
This, in turn, makes 576i work correctly; with the old code,
the caps would be interlace-mode=progressive for interlaced video.
https://bugzilla.gnome.org/show_bug.cgi?id=726194
2014-10-30 17:41:19 +00:00
|
|
|
|
2023-04-27 14:12:15 +00:00
|
|
|
/* try hard to avoid TRY_FMT since some UVC camera just crash when this
|
|
|
|
* is called at run-time. */
|
|
|
|
if (gst_v4l2_object_caps_is_subset (obj, caps)) {
|
|
|
|
fcaps = gst_v4l2_object_get_current_caps (obj);
|
|
|
|
GST_DEBUG_OBJECT (basesrc, "reuse current caps %" GST_PTR_FORMAT, fcaps);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
for (i = 0; i < gst_caps_get_size (caps); ++i) {
|
|
|
|
gst_v4l2_clear_error (&error);
|
|
|
|
if (fcaps)
|
|
|
|
gst_caps_unref (fcaps);
|
|
|
|
|
|
|
|
fcaps = gst_caps_copy_nth (caps, i);
|
|
|
|
|
2018-07-09 19:33:02 +00:00
|
|
|
/* Just check if the format is acceptable, once we know
|
|
|
|
* no buffers should be outstanding we try S_FMT.
|
|
|
|
*
|
|
|
|
* Basesrc will do an allocation query that
|
|
|
|
* should indirectly reclaim buffers, after that we can
|
|
|
|
* set the format and then configure our pool */
|
|
|
|
if (gst_v4l2_object_try_format (obj, fcaps, &error)) {
|
|
|
|
/* make sure the caps changed before doing anything */
|
|
|
|
if (gst_v4l2_object_caps_equal (obj, fcaps))
|
2017-07-20 02:25:49 +00:00
|
|
|
break;
|
2018-07-09 19:33:02 +00:00
|
|
|
|
|
|
|
v4l2src->renegotiation_adjust = v4l2src->offset + 1;
|
|
|
|
v4l2src->pending_set_fmt = TRUE;
|
|
|
|
break;
|
2017-07-20 02:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only EIVAL make sense, report any other errors, this way we don't keep
|
|
|
|
* probing if the device got disconnected, or if it's firmware stopped
|
|
|
|
* responding */
|
|
|
|
if (error.error->code != GST_RESOURCE_ERROR_SETTINGS) {
|
|
|
|
i = G_MAXINT;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-11 22:50:03 +00:00
|
|
|
}
|
2008-06-04 17:39:31 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
if (i >= gst_caps_get_size (caps)) {
|
|
|
|
gst_v4l2_error (v4l2src, &error);
|
|
|
|
if (fcaps)
|
|
|
|
gst_caps_unref (fcaps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-17 15:57:11 +00:00
|
|
|
|
2023-04-27 14:12:15 +00:00
|
|
|
out:
|
2017-07-20 02:25:49 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-03-11 18:06:37 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, fcaps);
|
configure.ac: Improve mpeg2enc detection. This is for distributions that do ship mjpegtools, but without mpeg2enc. Al...
Original commit message from CVS:
2003-12-21 Ronald Bultje <rbultje@ronald.bitfreak.net>
* configure.ac:
Improve mpeg2enc detection. This is for distributions that do
ship mjpegtools, but without mpeg2enc. Also does object check
for might there ever be ABI incompatibility.
* ext/mpeg2enc/gstmpeg2enc.cc:
Add Andrew as second maintainer (he's helping me), and also add
an error if no caps was set. This happens if I pull before capsnego
and that's something I should solve sometime else.
* gst/matroska/matroska-demux.c:
(gst_matroska_demux_parse_blockgroup):
Fix time parsing.
* gst/matroska/matroska-mux.c: (gst_matroska_mux_audio_pad_link),
(gst_matroska_mux_track_header):
Add caps to templates.
* gst/mpegaudioparse/gstmpegaudioparse.c: (mp3_sink_factory):
Add mpegversion=1 to prevent confusion with MPEG/AAC.
* gst/mpegstream/gstmpegdemux.c:
Remove layer since it causes warnings about unfixed caps.
* gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_get):
Fix obvious typo (we error out if caps were set, we should of
course error out if *no* caps were set).
* sys/oss/gstosselement.c: (gst_osselement_convert):
Fix format conversion, we confused bits/bytes.
* sys/oss/gstosselement.h:
Improve documentation for 'bps'.
* sys/v4l/TODO:
Remove stuff about plugins that need removing - this was done
ages ago.
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_init),
(gst_v4lmjpegsrc_src_convert), (gst_v4lmjpegsrc_src_query):
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_init), (gst_v4lsrc_src_convert),
(gst_v4lsrc_src_query):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_init),
(gst_v4l2src_src_convert), (gst_v4l2src_src_query):
Add get_query_types(), get_formats() and query() functions.
2003-12-21 18:44:34 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
return fcaps;
|
|
|
|
}
|
2008-06-04 17:39:31 +00:00
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_query_preferred_dv_timings (GstV4l2Src * v4l2src,
|
|
|
|
struct PreferredCapsInfo *pref)
|
2021-02-08 22:27:20 +00:00
|
|
|
{
|
2021-02-10 20:52:55 +00:00
|
|
|
GstV4l2Object *obj = v4l2src->v4l2object;
|
|
|
|
struct v4l2_dv_timings dv_timings = { 0, };
|
2021-02-10 21:37:01 +00:00
|
|
|
const struct v4l2_bt_timings *bt = &dv_timings.bt;
|
2022-11-28 22:26:50 +00:00
|
|
|
gboolean not_streaming;
|
2021-02-10 21:37:01 +00:00
|
|
|
gint tot_width, tot_height;
|
|
|
|
gint gcd;
|
2021-02-10 20:52:55 +00:00
|
|
|
|
|
|
|
if (!gst_v4l2_query_dv_timings (obj, &dv_timings))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-02-10 21:37:01 +00:00
|
|
|
pref->width = bt->width;
|
|
|
|
pref->height = bt->height;
|
|
|
|
|
|
|
|
tot_height = bt->height +
|
|
|
|
bt->vfrontporch + bt->vsync + bt->vbackporch +
|
|
|
|
bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch;
|
|
|
|
tot_width = bt->width + bt->hfrontporch + bt->hsync + bt->hbackporch;
|
|
|
|
|
|
|
|
pref->fps_n = bt->pixelclock;
|
|
|
|
pref->fps_d = tot_width * tot_height;
|
|
|
|
|
|
|
|
if (bt->interlaced)
|
|
|
|
pref->fps_d /= 2;
|
|
|
|
|
|
|
|
gcd = gst_util_greatest_common_divisor (pref->fps_n, pref->fps_d);
|
|
|
|
pref->fps_n /= gcd;
|
|
|
|
pref->fps_d /= gcd;
|
2021-02-10 20:52:55 +00:00
|
|
|
|
|
|
|
/* If are are not streaming (e.g. we received source-change event), lock the
|
|
|
|
* new timing immediatly so that TRY_FMT can properly work */
|
2022-11-28 22:26:50 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *obj_pool = gst_v4l2_object_get_buffer_pool (obj);
|
|
|
|
not_streaming = !obj_pool || !GST_V4L2_BUFFER_POOL_IS_STREAMING (obj_pool);
|
|
|
|
if (obj_pool)
|
|
|
|
gst_object_unref (obj_pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not_streaming) {
|
2021-02-10 20:52:55 +00:00
|
|
|
gst_v4l2_set_dv_timings (obj, &dv_timings);
|
2021-02-11 19:24:29 +00:00
|
|
|
/* Setting a new DV timings invalidates the probed caps. */
|
|
|
|
gst_caps_replace (&obj->probed_caps, NULL);
|
|
|
|
}
|
2021-02-10 20:52:55 +00:00
|
|
|
|
2021-02-10 21:37:01 +00:00
|
|
|
GST_INFO_OBJECT (v4l2src, "Using DV Timings: %i x %i (%i/%i fps)",
|
|
|
|
pref->width, pref->height, pref->fps_n, pref->fps_d);
|
|
|
|
|
2021-02-10 20:52:55 +00:00
|
|
|
return TRUE;
|
2021-02-08 22:27:20 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_query_preferred_size (GstV4l2Src * v4l2src,
|
|
|
|
struct PreferredCapsInfo *pref)
|
2021-02-08 22:26:20 +00:00
|
|
|
{
|
|
|
|
struct v4l2_input in = { 0, };
|
|
|
|
|
|
|
|
if (!gst_v4l2_get_input (v4l2src->v4l2object, &in.index))
|
2021-02-10 15:48:48 +00:00
|
|
|
return FALSE;
|
2021-02-08 22:26:20 +00:00
|
|
|
|
|
|
|
if (!gst_v4l2_query_input (v4l2src->v4l2object, &in))
|
2021-02-10 15:48:48 +00:00
|
|
|
return FALSE;
|
2021-02-08 22:26:20 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (v4l2src, "Detect input %u as `%s`", in.index, in.name);
|
|
|
|
|
|
|
|
/* Notify signal status using WARNING/INFO messages */
|
|
|
|
if (in.status & (V4L2_IN_ST_NO_POWER | V4L2_IN_ST_NO_SIGNAL)) {
|
|
|
|
if (!v4l2src->no_signal)
|
|
|
|
/* note: taken from decklinksrc element */
|
|
|
|
GST_ELEMENT_WARNING (v4l2src, RESOURCE, READ, ("Signal lost"),
|
|
|
|
("No input source was detected - video frames invalid"));
|
|
|
|
v4l2src->no_signal = TRUE;
|
|
|
|
} else if (v4l2src->no_signal) {
|
|
|
|
if (v4l2src->no_signal)
|
|
|
|
GST_ELEMENT_INFO (v4l2src, RESOURCE, READ,
|
|
|
|
("Signal recovered"), ("Input source detected"));
|
|
|
|
v4l2src->no_signal = FALSE;
|
|
|
|
}
|
2021-02-08 22:27:20 +00:00
|
|
|
|
|
|
|
if (in.capabilities & V4L2_IN_CAP_NATIVE_SIZE) {
|
|
|
|
GST_FIXME_OBJECT (v4l2src, "missing support for native video size");
|
2021-02-10 15:48:48 +00:00
|
|
|
return FALSE;
|
2021-02-08 22:27:20 +00:00
|
|
|
} else if (in.capabilities & V4L2_IN_CAP_DV_TIMINGS) {
|
2021-02-10 15:48:48 +00:00
|
|
|
return gst_v4l2src_query_preferred_dv_timings (v4l2src, pref);
|
2021-02-08 22:27:20 +00:00
|
|
|
} else if (in.capabilities & V4L2_IN_CAP_STD) {
|
|
|
|
GST_FIXME_OBJECT (v4l2src, "missing support for video standards");
|
2021-02-10 15:48:48 +00:00
|
|
|
return FALSE;
|
2021-02-08 22:27:20 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
return FALSE;
|
2021-02-08 22:26:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_setup_source_crop (GstV4l2Src * v4l2src,
|
|
|
|
struct PreferredCapsInfo *pref)
|
|
|
|
{
|
|
|
|
gint cropped_width, cropped_height;
|
|
|
|
struct v4l2_rect *crop_bounds = &v4l2src->crop_bounds;
|
|
|
|
|
|
|
|
v4l2src->apply_crop_settings = FALSE;
|
|
|
|
|
|
|
|
if (!gst_v4l2_object_get_crop_bounds (v4l2src->v4l2object, crop_bounds))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (v4l2src), "crop-bounds");
|
|
|
|
|
|
|
|
cropped_width = crop_bounds->width - v4l2src->crop_left - v4l2src->crop_right;
|
|
|
|
cropped_height =
|
|
|
|
crop_bounds->height - v4l2src->crop_top - v4l2src->crop_bottom;
|
|
|
|
|
|
|
|
if (v4l2src->crop_left < crop_bounds->left
|
|
|
|
|| v4l2src->crop_top < crop_bounds->top
|
|
|
|
|| cropped_width <= 0 || cropped_height <= 0) {
|
|
|
|
GST_WARNING_OBJECT (v4l2src, "Ignoring out of bounds crop region");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cropped_width == crop_bounds->width
|
|
|
|
&& cropped_height == crop_bounds->height) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2src,
|
|
|
|
"No cropping requested, keep current preferred size");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
v4l2src->crop_rect.left = v4l2src->crop_left;
|
|
|
|
v4l2src->crop_rect.top = v4l2src->crop_top;
|
|
|
|
v4l2src->crop_rect.width = cropped_width;
|
|
|
|
v4l2src->crop_rect.height = cropped_height;
|
|
|
|
v4l2src->apply_crop_settings = TRUE;
|
|
|
|
|
|
|
|
pref->width = cropped_width;
|
|
|
|
pref->height = cropped_height;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (v4l2src, "Updated preferred capture size to %i x %i",
|
|
|
|
pref->width, pref->height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-04 17:39:31 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_negotiate (GstBaseSrc * basesrc)
|
|
|
|
{
|
2021-02-10 15:48:48 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (basesrc);
|
2008-06-04 17:39:31 +00:00
|
|
|
GstCaps *thiscaps;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstCaps *peercaps = NULL;
|
|
|
|
gboolean result = FALSE;
|
2021-02-11 19:24:29 +00:00
|
|
|
/* Let's prefer a good resolution as of today's standard. */
|
|
|
|
struct PreferredCapsInfo pref = {
|
|
|
|
3840, 2160, 120, 1
|
|
|
|
};
|
|
|
|
gboolean have_pref;
|
|
|
|
|
|
|
|
/* For drivers that has DV timings or other default size query
|
|
|
|
* capabilities, we will prefer that resolution. This must happen before we
|
|
|
|
* probe the caps, as locking DV Timings or standards will change result of
|
|
|
|
* the caps enumeration. */
|
|
|
|
have_pref = gst_v4l2src_query_preferred_size (v4l2src, &pref);
|
2008-06-04 17:39:31 +00:00
|
|
|
|
2021-10-14 08:22:19 +00:00
|
|
|
have_pref |= gst_v4l2src_setup_source_crop (v4l2src, &pref);
|
|
|
|
|
2008-06-04 17:39:31 +00:00
|
|
|
/* first see what is possible on our source pad */
|
2011-11-15 15:55:27 +00:00
|
|
|
thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
|
2008-06-04 17:39:31 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2008-06-04 17:39:31 +00:00
|
|
|
/* nothing or anything is allowed, we're done */
|
|
|
|
if (thiscaps == NULL || gst_caps_is_any (thiscaps))
|
|
|
|
goto no_nego_needed;
|
|
|
|
|
2013-06-19 10:37:31 +00:00
|
|
|
/* get the peer caps without a filter as we'll filter ourselves later on */
|
|
|
|
peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
|
2008-06-04 17:39:31 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
|
|
|
|
if (peercaps && !gst_caps_is_any (peercaps)) {
|
|
|
|
/* Prefer the first caps we are compatible with that the peer proposed */
|
2017-07-20 02:25:49 +00:00
|
|
|
caps = gst_caps_intersect_full (peercaps, thiscaps,
|
2016-07-02 05:53:33 +00:00
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
2008-06-04 17:39:31 +00:00
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
GST_DEBUG_OBJECT (basesrc, "intersect: %" GST_PTR_FORMAT, caps);
|
|
|
|
|
2008-06-09 08:52:04 +00:00
|
|
|
gst_caps_unref (thiscaps);
|
2008-06-04 17:39:31 +00:00
|
|
|
} else {
|
|
|
|
/* no peer or peer have ANY caps, work with our own caps then */
|
|
|
|
caps = thiscaps;
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
if (caps) {
|
2008-06-04 17:39:31 +00:00
|
|
|
/* now fixate */
|
|
|
|
if (!gst_caps_is_empty (caps)) {
|
2021-02-08 22:26:20 +00:00
|
|
|
|
|
|
|
/* otherwise consider the first structure from peercaps to be a
|
|
|
|
* preference. This is useful for matching a reported native display,
|
|
|
|
* or simply to avoid transformation to happen downstream. */
|
2021-02-10 15:48:48 +00:00
|
|
|
if (!have_pref && peercaps && !gst_caps_is_any (peercaps)) {
|
|
|
|
GstStructure *pref_s = gst_caps_get_structure (peercaps, 0);
|
|
|
|
pref_s = gst_structure_copy (pref_s);
|
|
|
|
gst_v4l2_src_fixate_struct_with_preference (pref_s, &pref);
|
|
|
|
gst_v4l2_src_parse_fixed_struct (pref_s, &pref.width, &pref.height,
|
|
|
|
&pref.fps_n, &pref.fps_d);
|
|
|
|
gst_structure_free (pref_s);
|
|
|
|
}
|
2017-07-20 02:25:49 +00:00
|
|
|
|
2021-02-10 15:48:48 +00:00
|
|
|
caps = gst_v4l2src_fixate (basesrc, caps, &pref);
|
2017-07-20 02:25:49 +00:00
|
|
|
|
|
|
|
/* Fixating may fail as we now set the selected format */
|
|
|
|
if (!caps) {
|
|
|
|
result = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:27:20 +00:00
|
|
|
GST_INFO_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
|
2008-06-04 17:39:31 +00:00
|
|
|
|
|
|
|
if (gst_caps_is_any (caps)) {
|
|
|
|
/* hmm, still anything, so element can do anything and
|
|
|
|
* nego is not needed */
|
|
|
|
result = TRUE;
|
|
|
|
} else if (gst_caps_is_fixed (caps)) {
|
|
|
|
/* yay, fixed caps, use those then */
|
2011-08-04 14:35:46 +00:00
|
|
|
result = gst_base_src_set_caps (basesrc, caps);
|
2008-06-04 17:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
2017-07-20 02:25:49 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (peercaps)
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
|
2008-06-04 17:39:31 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
no_nego_needed:
|
|
|
|
{
|
2021-02-08 22:27:20 +00:00
|
|
|
GST_INFO_OBJECT (basesrc, "no negotiation needed");
|
2008-06-04 17:39:31 +00:00
|
|
|
if (thiscaps)
|
|
|
|
gst_caps_unref (thiscaps);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-12 02:19:57 +00:00
|
|
|
static GstCaps *
|
2011-07-08 10:49:12 +00:00
|
|
|
gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter)
|
2002-09-20 09:28:46 +00:00
|
|
|
{
|
2011-07-13 14:33:58 +00:00
|
|
|
GstV4l2Src *v4l2src;
|
|
|
|
GstV4l2Object *obj;
|
2004-01-12 02:19:57 +00:00
|
|
|
|
2011-07-13 14:33:58 +00:00
|
|
|
v4l2src = GST_V4L2SRC (src);
|
|
|
|
obj = v4l2src->v4l2object;
|
|
|
|
|
|
|
|
if (!GST_V4L2_IS_OPEN (obj)) {
|
2012-03-27 14:41:06 +00:00
|
|
|
return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (v4l2src));
|
2004-01-12 02:19:57 +00:00
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2012-10-22 21:58:07 +00:00
|
|
|
return gst_v4l2_object_get_caps (obj, filter);
|
2002-09-20 09:28:46 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 14:43:16 +00:00
|
|
|
static gboolean
|
2011-08-26 12:20:49 +00:00
|
|
|
gst_v4l2src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
|
2007-09-05 14:43:16 +00:00
|
|
|
{
|
2013-12-05 23:48:15 +00:00
|
|
|
GstV4l2Src *src = GST_V4L2SRC (bsrc);
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *bpool = gst_v4l2_object_get_buffer_pool (src->v4l2object);
|
2015-03-13 18:48:03 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
if (src->pending_set_fmt) {
|
|
|
|
GstCaps *caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (bsrc));
|
2017-07-20 02:25:49 +00:00
|
|
|
GstV4l2Error error = GST_V4L2_ERROR_INIT;
|
|
|
|
|
2022-12-02 17:15:34 +00:00
|
|
|
/* Setting the format replaces the current pool */
|
|
|
|
gst_clear_object (&bpool);
|
|
|
|
|
2017-07-20 02:25:49 +00:00
|
|
|
caps = gst_caps_make_writable (caps);
|
2021-02-04 21:59:44 +00:00
|
|
|
|
|
|
|
ret = gst_v4l2src_set_format (src, caps, &error);
|
|
|
|
if (ret) {
|
2022-12-02 17:15:34 +00:00
|
|
|
GstV4l2BufferPool *pool;
|
|
|
|
bpool = gst_v4l2_object_get_buffer_pool (src->v4l2object);
|
|
|
|
pool = GST_V4L2_BUFFER_POOL (bpool);
|
2021-02-04 21:59:44 +00:00
|
|
|
gst_v4l2_buffer_pool_enable_resolution_change (pool);
|
|
|
|
} else {
|
2017-07-20 02:25:49 +00:00
|
|
|
gst_v4l2_error (src, &error);
|
2021-02-04 21:59:44 +00:00
|
|
|
}
|
2011-07-15 14:55:50 +00:00
|
|
|
|
2015-03-13 18:48:03 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
src->pending_set_fmt = FALSE;
|
2022-11-28 22:26:50 +00:00
|
|
|
} else if (gst_buffer_pool_is_active (bpool)) {
|
2016-06-07 16:41:19 +00:00
|
|
|
/* Trick basesrc into not deactivating the active pool. Renegotiating here
|
|
|
|
* would otherwise turn off and on the camera. */
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
|
|
|
GstBufferPool *pool;
|
|
|
|
|
|
|
|
gst_base_src_get_allocator (bsrc, &allocator, ¶ms);
|
|
|
|
pool = gst_base_src_get_buffer_pool (bsrc);
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_params (query))
|
|
|
|
gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query))
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool,
|
|
|
|
src->v4l2object->info.size, 1, 0);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, src->v4l2object->info.size, 1,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
2022-11-28 22:26:50 +00:00
|
|
|
if (bpool)
|
|
|
|
gst_object_unref (bpool);
|
2016-06-07 16:41:19 +00:00
|
|
|
|
|
|
|
return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
|
2015-03-13 18:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
ret = gst_v4l2_object_decide_allocation (src->v4l2object, query);
|
|
|
|
if (ret)
|
|
|
|
ret = GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
|
|
|
|
}
|
2011-07-15 14:55:50 +00:00
|
|
|
|
2014-07-08 17:34:28 +00:00
|
|
|
if (ret) {
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!gst_buffer_pool_set_active (bpool, TRUE))
|
2014-07-08 17:34:28 +00:00
|
|
|
goto activate_failed;
|
|
|
|
}
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (bpool)
|
|
|
|
gst_object_unref (bpool);
|
2013-12-05 23:48:15 +00:00
|
|
|
return ret;
|
2014-07-08 17:34:28 +00:00
|
|
|
|
|
|
|
activate_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS,
|
|
|
|
(_("Failed to allocate required memory.")),
|
|
|
|
("Buffer pool activation failed"));
|
2022-11-28 22:26:50 +00:00
|
|
|
if (bpool)
|
|
|
|
gst_object_unref (bpool);
|
2014-07-08 17:34:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-15 14:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_query (GstBaseSrc * bsrc, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstV4l2Src *src;
|
2011-07-27 14:46:46 +00:00
|
|
|
GstV4l2Object *obj;
|
2007-09-05 14:43:16 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
src = GST_V4L2SRC (bsrc);
|
2011-07-27 14:46:46 +00:00
|
|
|
obj = src->v4l2object;
|
2007-09-05 14:43:16 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_LATENCY:{
|
|
|
|
GstClockTime min_latency, max_latency;
|
2011-07-13 09:19:28 +00:00
|
|
|
guint32 fps_n, fps_d;
|
2012-09-20 08:07:24 +00:00
|
|
|
guint num_buffers = 0;
|
2007-09-05 14:43:16 +00:00
|
|
|
|
|
|
|
/* device must be open */
|
2011-07-27 14:46:46 +00:00
|
|
|
if (!GST_V4L2_IS_OPEN (obj)) {
|
2008-08-12 12:04:24 +00:00
|
|
|
GST_WARNING_OBJECT (src,
|
|
|
|
"Can't give latency since device isn't open !");
|
2007-09-05 14:43:16 +00:00
|
|
|
goto done;
|
2008-08-12 12:04:24 +00:00
|
|
|
}
|
2007-09-05 14:43:16 +00:00
|
|
|
|
2011-07-27 14:46:46 +00:00
|
|
|
fps_n = GST_V4L2_FPS_N (obj);
|
|
|
|
fps_d = GST_V4L2_FPS_D (obj);
|
2011-07-13 09:19:28 +00:00
|
|
|
|
2007-09-05 14:43:16 +00:00
|
|
|
/* we must have a framerate */
|
2011-07-13 09:19:28 +00:00
|
|
|
if (fps_n <= 0 || fps_d <= 0) {
|
2008-08-12 12:04:24 +00:00
|
|
|
GST_WARNING_OBJECT (src,
|
|
|
|
"Can't give latency since framerate isn't fixated !");
|
2007-09-05 14:43:16 +00:00
|
|
|
goto done;
|
2008-08-12 12:04:24 +00:00
|
|
|
}
|
2007-09-05 14:43:16 +00:00
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
/* min latency is the time to capture one frame/field */
|
2011-07-13 09:19:28 +00:00
|
|
|
min_latency = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
|
2018-08-08 07:27:19 +00:00
|
|
|
if (GST_VIDEO_INFO_INTERLACE_MODE (&obj->info) ==
|
|
|
|
GST_VIDEO_INTERLACE_MODE_ALTERNATE)
|
|
|
|
min_latency /= 2;
|
2007-09-05 14:43:16 +00:00
|
|
|
|
|
|
|
/* max latency is total duration of the frame buffer */
|
2022-11-28 22:26:50 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *obj_pool = gst_v4l2_object_get_buffer_pool (obj);
|
|
|
|
if (obj_pool != NULL) {
|
|
|
|
num_buffers = GST_V4L2_BUFFER_POOL_CAST (obj_pool)->max_latency;
|
|
|
|
gst_object_unref (obj_pool);
|
|
|
|
}
|
|
|
|
}
|
2012-03-26 13:51:28 +00:00
|
|
|
|
2012-04-23 16:01:31 +00:00
|
|
|
if (num_buffers == 0)
|
2012-03-26 13:51:28 +00:00
|
|
|
max_latency = -1;
|
|
|
|
else
|
2012-04-23 16:01:31 +00:00
|
|
|
max_latency = num_buffers * min_latency;
|
2007-09-05 14:43:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (bsrc,
|
|
|
|
"report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency));
|
|
|
|
|
|
|
|
/* we are always live, the min latency is 1 frame and the max latency is
|
|
|
|
* the complete buffer of frames. */
|
|
|
|
gst_query_set_latency (query, TRUE, min_latency, max_latency);
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
/* start and stop are not symmetric -- start will open the device, but not start
|
sys/v4l2/: Fix pass at code cleanups, move errors cases out of the normal flow for additional code clarity.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c: (gst_v4l2_class_probe_devices),
(gst_v4l2_probe_needs_probe),
(gst_v4l2_object_install_properties_helper), (gst_v4l2_object_new),
(gst_v4l2_object_destroy), (gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults),
(gst_v4l2_object_start), (gst_v4l2_object_stop):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_init), (gst_v4l2src_dispose),
(gst_v4l2src_set_property), (gst_v4l2src_get_property),
(gst_v4l2src_fixate), (gst_v4l2src_get_caps),
(gst_v4l2src_set_caps), (gst_v4l2src_get_read),
(gst_v4l2src_get_mmap), (gst_v4l2src_create):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_open), (gst_v4l2_close), (gst_v4l2_get_norm),
(gst_v4l2_set_norm), (gst_v4l2_get_frequency),
(gst_v4l2_set_frequency), (gst_v4l2_signal_strength),
(gst_v4l2_get_attribute), (gst_v4l2_set_attribute),
(gst_v4l2_get_input), (gst_v4l2_set_input):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_fill_format_list),
(gst_v4l2src_queue_frame), (gst_v4l2src_grab_frame),
(gst_v4l2src_get_capture), (gst_v4l2src_set_capture),
(gst_v4l2src_capture_init), (gst_v4l2src_capture_start),
(gst_v4l2src_capture_stop), (gst_v4l2src_capture_deinit),
(gst_v4l2src_get_size_limits), (gst_v4l2src_set_fps),
(gst_v4l2src_get_fps), (gst_v4l2src_buffer_finalize),
(gst_v4l2src_buffer_new):
Fix pass at code cleanups, move errors cases out of the normal
flow for additional code clarity.
2006-09-26 11:06:17 +00:00
|
|
|
* capture. it's setcaps that will start capture, which is called via basesrc's
|
|
|
|
* negotiate method. stop will both stop capture and close the device.
|
|
|
|
*/
|
2006-03-11 22:50:03 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_start (GstBaseSrc * src)
|
2002-09-09 07:14:35 +00:00
|
|
|
{
|
2006-03-11 22:50:03 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (src);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
v4l2src->offset = 0;
|
2018-08-08 07:27:19 +00:00
|
|
|
v4l2src->next_offset_same = FALSE;
|
2015-03-27 20:09:44 +00:00
|
|
|
v4l2src->renegotiation_adjust = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2010-06-22 12:48:04 +00:00
|
|
|
/* activate settings for first frame */
|
|
|
|
v4l2src->ctrl_time = 0;
|
2011-11-04 17:41:36 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (src), v4l2src->ctrl_time);
|
2010-06-22 12:48:04 +00:00
|
|
|
|
2014-09-05 12:29:20 +00:00
|
|
|
v4l2src->has_bad_timestamp = FALSE;
|
|
|
|
v4l2src->last_timestamp = 0;
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2009-03-01 18:55:26 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_unlock (GstBaseSrc * src)
|
|
|
|
{
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (src);
|
2011-07-18 16:54:49 +00:00
|
|
|
return gst_v4l2_object_unlock (v4l2src->v4l2object);
|
2009-03-01 18:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_unlock_stop (GstBaseSrc * src)
|
|
|
|
{
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (src);
|
2014-09-05 12:29:20 +00:00
|
|
|
|
|
|
|
v4l2src->last_timestamp = 0;
|
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
return gst_v4l2_object_unlock_stop (v4l2src->v4l2object);
|
2009-03-01 18:55:26 +00:00
|
|
|
}
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_stop (GstBaseSrc * src)
|
|
|
|
{
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (src);
|
2011-07-13 14:33:58 +00:00
|
|
|
GstV4l2Object *obj = v4l2src->v4l2object;
|
2006-03-11 22:50:03 +00:00
|
|
|
|
2011-07-13 14:33:58 +00:00
|
|
|
if (GST_V4L2_IS_ACTIVE (obj)) {
|
|
|
|
if (!gst_v4l2_object_stop (obj))
|
2006-03-11 22:50:03 +00:00
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2015-03-13 18:48:03 +00:00
|
|
|
|
|
|
|
v4l2src->pending_set_fmt = FALSE;
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-22 12:56:58 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_v4l2src_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (element);
|
2011-07-13 14:33:58 +00:00
|
|
|
GstV4l2Object *obj = v4l2src->v4l2object;
|
2020-08-06 11:15:10 +00:00
|
|
|
GstV4l2Error error = GST_V4L2_ERROR_INIT;
|
2009-06-22 12:56:58 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
/* open the device */
|
2020-08-06 11:15:10 +00:00
|
|
|
if (!gst_v4l2_object_open (obj, &error)) {
|
|
|
|
gst_v4l2_error (v4l2src, &error);
|
2009-06-22 12:56:58 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2020-08-06 11:15:10 +00:00
|
|
|
}
|
2009-06-22 12:56:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
/* close the device */
|
2011-07-13 14:33:58 +00:00
|
|
|
if (!gst_v4l2_object_close (obj))
|
2009-06-22 12:56:58 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2009-08-14 08:11:25 +00:00
|
|
|
|
2009-06-22 12:56:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:27:42 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_handle_resolution_change (GstV4l2Src * v4l2src)
|
|
|
|
{
|
|
|
|
GST_INFO_OBJECT (v4l2src, "Resolution change detected.");
|
|
|
|
|
|
|
|
/* It is required to always cycle through streamoff, we also need to
|
|
|
|
* streamoff in order to allow locking a new DV_TIMING which will
|
|
|
|
* influence the output of TRY_FMT */
|
|
|
|
gst_v4l2src_stop (GST_BASE_SRC (v4l2src));
|
|
|
|
|
|
|
|
/* Force renegotiation */
|
|
|
|
v4l2src->renegotiation_adjust = v4l2src->offset + 1;
|
|
|
|
v4l2src->pending_set_fmt = TRUE;
|
|
|
|
|
|
|
|
return gst_base_src_negotiate (GST_BASE_SRC (v4l2src));
|
|
|
|
}
|
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
static GstFlowReturn
|
2014-04-29 17:05:41 +00:00
|
|
|
gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
|
2003-05-02 21:16:56 +00:00
|
|
|
{
|
2006-03-11 22:50:03 +00:00
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (src);
|
2011-07-13 16:32:00 +00:00
|
|
|
GstV4l2Object *obj = v4l2src->v4l2object;
|
2006-03-11 22:50:03 +00:00
|
|
|
GstFlowReturn ret;
|
2011-07-18 16:54:49 +00:00
|
|
|
GstClock *clock;
|
2012-04-25 07:41:46 +00:00
|
|
|
GstClockTime abs_time, base_time, timestamp, duration;
|
2012-04-24 10:37:33 +00:00
|
|
|
GstClockTime delay;
|
2014-11-14 13:18:51 +00:00
|
|
|
GstMessage *qos_msg;
|
2018-08-08 07:27:19 +00:00
|
|
|
gboolean half_frame;
|
2006-03-11 22:50:03 +00:00
|
|
|
|
2014-11-16 17:34:17 +00:00
|
|
|
do {
|
|
|
|
ret = GST_BASE_SRC_CLASS (parent_class)->alloc (GST_BASE_SRC (src), 0,
|
|
|
|
obj->info.size, buf);
|
2014-04-29 17:05:41 +00:00
|
|
|
|
2021-02-04 21:59:44 +00:00
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK)) {
|
|
|
|
if (ret == GST_V4L2_FLOW_RESOLUTION_CHANGE) {
|
2023-07-06 12:27:42 +00:00
|
|
|
if (!gst_v4l2src_handle_resolution_change (v4l2src)) {
|
2021-02-10 20:49:03 +00:00
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-02-04 21:59:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-16 17:34:17 +00:00
|
|
|
goto alloc_failed;
|
2021-02-04 21:59:44 +00:00
|
|
|
}
|
2014-11-16 17:34:17 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
{
|
|
|
|
GstV4l2BufferPool *obj_pool =
|
|
|
|
GST_V4L2_BUFFER_POOL_CAST (gst_v4l2_object_get_buffer_pool (obj));
|
|
|
|
ret = gst_v4l2_buffer_pool_process (obj_pool, buf, NULL);
|
|
|
|
if (obj_pool)
|
|
|
|
gst_object_unref (obj_pool);
|
2023-07-06 12:27:42 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (ret == GST_V4L2_FLOW_RESOLUTION_CHANGE)) {
|
|
|
|
if (!gst_v4l2src_handle_resolution_change (v4l2src)) {
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 22:26:50 +00:00
|
|
|
}
|
2014-04-29 17:05:41 +00:00
|
|
|
|
2021-02-04 21:59:44 +00:00
|
|
|
} while (ret == GST_V4L2_FLOW_CORRUPTED_BUFFER ||
|
|
|
|
ret == GST_V4L2_FLOW_RESOLUTION_CHANGE);
|
2009-06-29 18:43:07 +00:00
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
goto error;
|
2009-03-25 08:08:41 +00:00
|
|
|
|
2014-04-29 17:05:41 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (*buf);
|
2012-04-25 07:41:46 +00:00
|
|
|
duration = obj->duration;
|
|
|
|
|
|
|
|
/* timestamps, LOCK to get clock and base time. */
|
|
|
|
/* FIXME: element clock and base_time is rarely changing */
|
|
|
|
GST_OBJECT_LOCK (v4l2src);
|
|
|
|
if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
|
|
|
|
/* we have a clock, get base time and ref clock */
|
|
|
|
base_time = GST_ELEMENT (v4l2src)->base_time;
|
|
|
|
gst_object_ref (clock);
|
|
|
|
} else {
|
|
|
|
/* no clock, can't set timestamps */
|
|
|
|
base_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (v4l2src);
|
|
|
|
|
|
|
|
/* sample pipeline clock */
|
|
|
|
if (clock) {
|
|
|
|
abs_time = gst_clock_get_time (clock);
|
|
|
|
gst_object_unref (clock);
|
|
|
|
} else {
|
|
|
|
abs_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2012-04-24 10:37:33 +00:00
|
|
|
|
2014-09-05 12:29:20 +00:00
|
|
|
retry:
|
|
|
|
if (!v4l2src->has_bad_timestamp && timestamp != GST_CLOCK_TIME_NONE) {
|
2012-04-24 10:37:33 +00:00
|
|
|
struct timespec now;
|
|
|
|
GstClockTime gstnow;
|
|
|
|
|
|
|
|
/* v4l2 specs say to use the system time although many drivers switched to
|
|
|
|
* the more desirable monotonic time. We first try to use the monotonic time
|
|
|
|
* and see how that goes */
|
|
|
|
clock_gettime (CLOCK_MONOTONIC, &now);
|
|
|
|
gstnow = GST_TIMESPEC_TO_TIME (now);
|
|
|
|
|
2014-09-05 12:29:20 +00:00
|
|
|
if (timestamp > gstnow || (gstnow - timestamp) > (10 * GST_SECOND)) {
|
2012-04-24 10:37:33 +00:00
|
|
|
/* very large diff, fall back to system time */
|
2019-10-11 12:20:15 +00:00
|
|
|
gstnow = g_get_real_time () * GST_USECOND;
|
2012-04-24 10:37:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 12:29:20 +00:00
|
|
|
/* Detect buggy drivers here, and stop using their timestamp. Failing any
|
|
|
|
* of these condition would imply a very buggy driver:
|
|
|
|
* - Timestamp in the future
|
|
|
|
* - Timestamp is going backward compare to last seen timestamp
|
|
|
|
* - Timestamp is jumping forward for less then a frame duration
|
|
|
|
* - Delay is bigger then the actual timestamp
|
|
|
|
* */
|
|
|
|
if (timestamp > gstnow) {
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
|
|
|
"Timestamp in the future detected, ignoring driver timestamps");
|
|
|
|
v4l2src->has_bad_timestamp = TRUE;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v4l2src->last_timestamp > timestamp) {
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
|
|
|
"Timestamp going backward, ignoring driver timestamps");
|
|
|
|
v4l2src->has_bad_timestamp = TRUE;
|
|
|
|
goto retry;
|
2012-04-24 10:37:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 12:29:20 +00:00
|
|
|
delay = gstnow - timestamp;
|
|
|
|
|
|
|
|
if (delay > timestamp) {
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
|
|
|
"Timestamp does not correlate with any clock, ignoring driver timestamps");
|
|
|
|
v4l2src->has_bad_timestamp = TRUE;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save last timestamp for sanity checks */
|
|
|
|
v4l2src->last_timestamp = timestamp;
|
|
|
|
|
2012-04-24 10:37:33 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2src, "ts: %" GST_TIME_FORMAT " now %" GST_TIME_FORMAT
|
|
|
|
" delay %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (gstnow), GST_TIME_ARGS (delay));
|
|
|
|
} else {
|
2018-08-08 07:27:19 +00:00
|
|
|
/* we assume 1 frame/field latency otherwise */
|
2012-04-25 07:41:46 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration))
|
|
|
|
delay = duration;
|
|
|
|
else
|
|
|
|
delay = 0;
|
2012-04-24 10:37:33 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
/* set buffer metadata */
|
2014-11-14 12:48:51 +00:00
|
|
|
|
2012-04-25 07:41:46 +00:00
|
|
|
if (G_LIKELY (abs_time != GST_CLOCK_TIME_NONE)) {
|
2011-07-18 16:54:49 +00:00
|
|
|
/* the time now is the time of the clock minus the base time */
|
2012-04-25 07:41:46 +00:00
|
|
|
timestamp = abs_time - base_time;
|
2009-03-25 08:08:41 +00:00
|
|
|
|
2012-04-24 10:37:33 +00:00
|
|
|
/* adjust for delay in the device */
|
|
|
|
if (timestamp > delay)
|
|
|
|
timestamp -= delay;
|
|
|
|
else
|
|
|
|
timestamp = 0;
|
2012-04-25 07:41:46 +00:00
|
|
|
} else {
|
|
|
|
timestamp = GST_CLOCK_TIME_NONE;
|
2011-07-18 16:54:49 +00:00
|
|
|
}
|
2010-06-22 12:48:04 +00:00
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
/* activate settings for next frame */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration)) {
|
|
|
|
v4l2src->ctrl_time += duration;
|
|
|
|
} else {
|
|
|
|
/* this is not very good (as it should be the next timestamp),
|
|
|
|
* still good enough for linear fades (as long as it is not -1)
|
|
|
|
*/
|
|
|
|
v4l2src->ctrl_time = timestamp;
|
2009-03-25 08:08:41 +00:00
|
|
|
}
|
2011-11-04 17:41:36 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (src), v4l2src->ctrl_time);
|
2012-04-24 10:37:33 +00:00
|
|
|
|
2020-03-05 16:55:44 +00:00
|
|
|
GST_LOG_OBJECT (src, "sync to %" GST_TIME_FORMAT " out ts %" GST_TIME_FORMAT,
|
2012-04-24 10:37:33 +00:00
|
|
|
GST_TIME_ARGS (v4l2src->ctrl_time), GST_TIME_ARGS (timestamp));
|
2011-07-18 16:54:49 +00:00
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
if (v4l2src->next_offset_same &&
|
|
|
|
GST_BUFFER_OFFSET_IS_VALID (*buf) &&
|
|
|
|
GST_BUFFER_OFFSET (*buf) != v4l2src->offset) {
|
|
|
|
/* Probably had a lost field then, best to forget about last field. */
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
|
|
|
"lost field detected - ts: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timestamp));
|
|
|
|
v4l2src->next_offset_same = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
half_frame = (GST_BUFFER_FLAG_IS_SET (*buf, GST_VIDEO_BUFFER_FLAG_ONEFIELD));
|
|
|
|
if (half_frame)
|
|
|
|
v4l2src->next_offset_same = !v4l2src->next_offset_same;
|
|
|
|
|
2014-11-14 13:18:51 +00:00
|
|
|
/* use generated offset values only if there are not already valid ones
|
|
|
|
* set by the v4l2 device */
|
2016-02-19 15:03:04 +00:00
|
|
|
if (!GST_BUFFER_OFFSET_IS_VALID (*buf)
|
2020-05-20 21:30:59 +00:00
|
|
|
|| !GST_BUFFER_OFFSET_END_IS_VALID (*buf)
|
|
|
|
|| GST_BUFFER_OFFSET (*buf) <=
|
|
|
|
(v4l2src->offset - v4l2src->renegotiation_adjust)) {
|
2018-08-08 07:27:19 +00:00
|
|
|
GST_BUFFER_OFFSET (*buf) = v4l2src->offset;
|
|
|
|
GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset + 1;
|
|
|
|
if (!half_frame || !v4l2src->next_offset_same)
|
|
|
|
v4l2src->offset++;
|
2014-11-14 13:18:51 +00:00
|
|
|
} else {
|
2015-03-27 20:09:44 +00:00
|
|
|
/* adjust raw v4l2 device sequence, will restart at null in case of renegotiation
|
|
|
|
* (streamoff/streamon) */
|
|
|
|
GST_BUFFER_OFFSET (*buf) += v4l2src->renegotiation_adjust;
|
|
|
|
GST_BUFFER_OFFSET_END (*buf) += v4l2src->renegotiation_adjust;
|
2014-11-14 13:18:51 +00:00
|
|
|
/* check for frame loss with given (from v4l2 device) buffer offset */
|
2016-02-19 15:03:04 +00:00
|
|
|
if ((v4l2src->offset != 0)
|
2018-08-08 07:27:19 +00:00
|
|
|
&& (!half_frame || v4l2src->next_offset_same)
|
2016-02-19 15:03:04 +00:00
|
|
|
&& (GST_BUFFER_OFFSET (*buf) != (v4l2src->offset + 1))) {
|
2014-11-14 13:18:51 +00:00
|
|
|
guint64 lost_frame_count = GST_BUFFER_OFFSET (*buf) - v4l2src->offset - 1;
|
|
|
|
GST_WARNING_OBJECT (v4l2src,
|
2016-02-19 15:03:04 +00:00
|
|
|
"lost frames detected: count = %" G_GUINT64_FORMAT " - ts: %"
|
|
|
|
GST_TIME_FORMAT, lost_frame_count, GST_TIME_ARGS (timestamp));
|
2014-11-14 13:18:51 +00:00
|
|
|
|
|
|
|
qos_msg = gst_message_new_qos (GST_OBJECT_CAST (v4l2src), TRUE,
|
|
|
|
GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, timestamp,
|
2016-02-19 15:03:04 +00:00
|
|
|
GST_CLOCK_TIME_IS_VALID (duration) ? lost_frame_count *
|
|
|
|
duration : GST_CLOCK_TIME_NONE);
|
2014-11-14 13:18:51 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (v4l2src), qos_msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
v4l2src->offset = GST_BUFFER_OFFSET (*buf);
|
|
|
|
}
|
|
|
|
|
2014-04-29 17:05:41 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (*buf) = timestamp;
|
|
|
|
GST_BUFFER_DURATION (*buf) = duration;
|
2011-07-18 16:54:49 +00:00
|
|
|
|
2006-03-11 22:50:03 +00:00
|
|
|
return ret;
|
2011-07-18 16:54:49 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
2014-04-29 17:05:41 +00:00
|
|
|
alloc_failed:
|
|
|
|
{
|
|
|
|
if (ret != GST_FLOW_FLUSHING)
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, NO_SPACE_LEFT,
|
|
|
|
("Failed to allocate a buffer"), (NULL));
|
|
|
|
return ret;
|
|
|
|
}
|
2011-07-18 16:54:49 +00:00
|
|
|
error:
|
|
|
|
{
|
2016-11-24 13:41:52 +00:00
|
|
|
gst_buffer_replace (buf, NULL);
|
2014-11-16 17:34:17 +00:00
|
|
|
if (ret == GST_V4L2_FLOW_LAST_BUFFER) {
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
|
|
|
("Driver returned a buffer with no payload, this most likely "
|
|
|
|
"indicate a bug in the driver."), (NULL));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (src, "error processing buffer %d (%s)", ret,
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
}
|
2011-07-18 16:54:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2003-05-02 21:16:56 +00:00
|
|
|
}
|
2009-11-08 10:49:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* GstURIHandler interface */
|
|
|
|
static GstURIType
|
2011-07-08 10:49:12 +00:00
|
|
|
gst_v4l2src_uri_get_type (GType type)
|
2009-11-08 10:49:14 +00:00
|
|
|
{
|
|
|
|
return GST_URI_SRC;
|
|
|
|
}
|
|
|
|
|
2011-11-13 23:42:44 +00:00
|
|
|
static const gchar *const *
|
2011-07-08 10:49:12 +00:00
|
|
|
gst_v4l2src_uri_get_protocols (GType type)
|
2009-11-08 10:49:14 +00:00
|
|
|
{
|
2011-11-13 23:42:44 +00:00
|
|
|
static const gchar *protocols[] = { "v4l2", NULL };
|
2009-11-08 10:49:14 +00:00
|
|
|
|
|
|
|
return protocols;
|
|
|
|
}
|
|
|
|
|
2011-11-13 18:50:51 +00:00
|
|
|
static gchar *
|
2009-11-08 10:49:14 +00:00
|
|
|
gst_v4l2src_uri_get_uri (GstURIHandler * handler)
|
|
|
|
{
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
|
|
|
|
|
2010-01-05 09:47:00 +00:00
|
|
|
if (v4l2src->v4l2object->videodev != NULL) {
|
2011-11-13 18:50:51 +00:00
|
|
|
return g_strdup_printf ("v4l2://%s", v4l2src->v4l2object->videodev);
|
2010-01-05 09:47:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 18:50:51 +00:00
|
|
|
return g_strdup ("v4l2://");
|
2009-11-08 10:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-13 18:50:51 +00:00
|
|
|
gst_v4l2src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
|
|
|
|
GError ** error)
|
2009-11-08 10:49:14 +00:00
|
|
|
{
|
|
|
|
GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
|
|
|
|
const gchar *device = DEFAULT_PROP_DEVICE;
|
|
|
|
|
|
|
|
if (strcmp (uri, "v4l2://") != 0) {
|
|
|
|
device = uri + 7;
|
|
|
|
}
|
|
|
|
g_object_set (v4l2src, "device", device, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4l2src_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
|
|
|
|
|
|
|
iface->get_type = gst_v4l2src_uri_get_type;
|
|
|
|
iface->get_protocols = gst_v4l2src_uri_get_protocols;
|
|
|
|
iface->get_uri = gst_v4l2src_uri_get_uri;
|
|
|
|
iface->set_uri = gst_v4l2src_uri_set_uri;
|
|
|
|
}
|