2006-09-02 14:28:55 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
2006-05-11 17:59:59 +00:00
|
|
|
* 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
|
|
|
*
|
|
|
|
* gstv4l2object.c: base class for V4L2 elements
|
2006-05-11 17:59:59 +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 Free Software
|
2012-11-04 00:07:18 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
|
2009-08-04 07:14:20 +00:00
|
|
|
* USA.
|
2006-05-11 17:59:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2017-07-24 18:19:02 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2009-07-03 06:38:43 +00:00
|
|
|
#ifdef HAVE_GUDEV
|
|
|
|
#include <gudev/gudev.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-30 02:19:42 +00:00
|
|
|
#include "ext/videodev2.h"
|
2017-07-13 00:49:47 +00:00
|
|
|
#include "gstv4l2object.h"
|
2006-05-11 17:59:59 +00:00
|
|
|
#include "gstv4l2tuner.h"
|
|
|
|
#include "gstv4l2colorbalance.h"
|
|
|
|
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2011-07-08 12:34:40 +00:00
|
|
|
#include <gst/video/video.h>
|
2018-08-01 17:07:52 +00:00
|
|
|
#include <gst/allocators/gstdmabuf.h>
|
2011-07-08 12:34:40 +00:00
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
|
|
|
|
#define GST_CAT_DEFAULT v4l2_debug
|
|
|
|
|
2013-05-29 19:57:09 +00:00
|
|
|
#define DEFAULT_PROP_DEVICE_NAME NULL
|
2008-03-26 15:10:08 +00:00
|
|
|
#define DEFAULT_PROP_DEVICE_FD -1
|
2006-09-26 13:18:06 +00:00
|
|
|
#define DEFAULT_PROP_FLAGS 0
|
2010-04-04 11:43:41 +00:00
|
|
|
#define DEFAULT_PROP_TV_NORM 0
|
2011-07-18 16:54:49 +00:00
|
|
|
#define DEFAULT_PROP_IO_MODE GST_V4L2_IO_AUTO
|
2006-09-26 13:18:06 +00:00
|
|
|
|
2023-05-05 09:01:50 +00:00
|
|
|
#define ENCODED_BUFFER_MIN_SIZE (256 * 1024)
|
2022-05-10 08:20:46 +00:00
|
|
|
#define GST_V4L2_DEFAULT_WIDTH 320
|
|
|
|
#define GST_V4L2_DEFAULT_HEIGHT 240
|
2013-12-12 17:18:45 +00:00
|
|
|
|
2006-05-18 19:34:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
V4L2_STD_OBJECT_PROPS,
|
|
|
|
};
|
|
|
|
|
2014-03-13 17:21:41 +00:00
|
|
|
/*
|
|
|
|
* common format / caps utilities:
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2024-08-14 13:52:54 +00:00
|
|
|
GST_V4L2_RESOLUTION_AND_RATE = 1u << 4,
|
|
|
|
GST_V4L2_RAW = (1u << 0) | GST_V4L2_RESOLUTION_AND_RATE,
|
|
|
|
GST_V4L2_CODEC = 1u << 1,
|
|
|
|
GST_V4L2_TRANSPORT = 1u << 2,
|
|
|
|
GST_V4L2_NO_PARSE = 1u << 3,
|
2024-08-14 19:21:44 +00:00
|
|
|
GST_V4L2_BAYER = GST_V4L2_RAW | (1u << 5),
|
2014-03-13 17:21:41 +00:00
|
|
|
GST_V4L2_ALL = 0xffff
|
|
|
|
} GstV4L2FormatFlags;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
guint32 v4l2_format;
|
|
|
|
GstVideoFormat gst_format;
|
2014-03-13 17:21:41 +00:00
|
|
|
GstV4L2FormatFlags flags;
|
|
|
|
} GstV4L2FormatDesc;
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
#define MAP_FMT(v4l2_format, gst_fmt) V4L2_PIX_FMT_##v4l2_format, GST_VIDEO_FORMAT_##gst_fmt
|
2014-03-13 17:21:41 +00:00
|
|
|
static const GstV4L2FormatDesc gst_v4l2_formats[] = {
|
2015-12-18 20:49:43 +00:00
|
|
|
/* RGB formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (RGB332, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (ARGB555, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (XRGB555, RGB15), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (XRGB555X, RGB15), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (ARGB555X, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB565, RGB16), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB565X, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGR666, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGR24, BGR), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB24, RGB), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (ABGR32, BGRA), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (XBGR32, BGRx), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGRA32, ABGR), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGRX32, xBGR), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGBA32, RGBA), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGBX32, RGBx), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (ARGB32, ARGB), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (XRGB32, xRGB), GST_V4L2_RAW},
|
2015-12-18 20:49:43 +00:00
|
|
|
|
|
|
|
/* Deprecated Packed RGB Image Formats (alpha ambiguity) */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (RGB444, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB555, RGB15), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB555X, BGR15), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGR32, BGRx), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (BGR32, BGRA), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB32, xRGB), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (RGB32, ARGB), GST_V4L2_RAW},
|
2015-12-18 20:49:43 +00:00
|
|
|
|
|
|
|
/* Grey formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (GREY, GRAY8), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y4, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y6, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y10, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y12, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y16, GRAY16_LE), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y16_BE, GRAY16_BE), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y10BPACK, UNKNOWN), GST_V4L2_RAW},
|
2015-12-18 20:49:43 +00:00
|
|
|
|
|
|
|
/* Palette formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (PAL8, UNKNOWN), GST_V4L2_RAW},
|
2015-12-18 20:49:43 +00:00
|
|
|
|
|
|
|
/* Chrominance formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (UV8, UNKNOWN), GST_V4L2_RAW},
|
2015-12-18 20:49:43 +00:00
|
|
|
|
|
|
|
/* Luminance+Chrominance formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (YVU410, YVU9), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YVU420M, YV12), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YVU420, YV12), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUYV, YUY2), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YYUV, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YVYU, YVYU), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (UYVY, UYVY), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (VYUY, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV422M, Y42B), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV422P, Y42B), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV411P, Y41B), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (Y41P, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV444, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV555, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV565, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV32, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV410, YUV9), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV420M, I420), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (YUV420, I420), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (HI240, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (M420, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
|
|
|
|
/* two planes -- one Y, one Cr + Cb interleaved */
|
|
|
|
{MAP_FMT (NV12M, NV12), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12, NV12), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12MT, NV12_64Z32), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12MT_16X16, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12_16L16, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12M_8L128, NV12_8L128), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV12M_10BE_8L128, NV12_10BE_8L128), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV21M, NV21), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV21, NV21), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV16M, NV16), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV16, NV16), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV61M, NV61), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV61, NV61), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV24, NV24), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (NV42, UNKNOWN), GST_V4L2_RAW},
|
|
|
|
{MAP_FMT (MM21, NV12_16L32S), GST_V4L2_RAW},
|
2014-03-13 17:21:41 +00:00
|
|
|
|
2015-12-18 20:49:43 +00:00
|
|
|
/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (SBGGR8, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGBRG8, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGRBG8, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SRGGB8, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SBGGR10, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGBRG10, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGRBG10, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SRGGB10, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SBGGR12, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGBRG12, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGRBG12, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SRGGB12, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SBGGR14, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGBRG14, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGRBG14, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SRGGB14, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SBGGR16, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGBRG16, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SGRBG16, ENCODED), GST_V4L2_BAYER},
|
|
|
|
{MAP_FMT (SRGGB16, ENCODED), GST_V4L2_BAYER},
|
2014-03-13 17:21:41 +00:00
|
|
|
|
|
|
|
/* compressed formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (MJPEG, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (JPEG, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (PJPG, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (DV, ENCODED), GST_V4L2_TRANSPORT},
|
|
|
|
{MAP_FMT (MPEG, ENCODED), GST_V4L2_TRANSPORT},
|
|
|
|
{MAP_FMT (FWHT, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (H264, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (H264_NO_SC, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (H264_MVC, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (HEVC, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (H263, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (MPEG1, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (MPEG2, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (MPEG4, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (XVID, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (VC1_ANNEX_G, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (VC1_ANNEX_L, ENCODED), GST_V4L2_CODEC},
|
|
|
|
{MAP_FMT (VP8, ENCODED), GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
|
|
|
|
{MAP_FMT (VP9, ENCODED), GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
|
2014-03-13 17:21:41 +00:00
|
|
|
|
|
|
|
/* Vendor-specific formats */
|
2024-08-14 19:21:44 +00:00
|
|
|
{MAP_FMT (WNVA, ENCODED), GST_V4L2_CODEC | GST_V4L2_RESOLUTION_AND_RATE},
|
|
|
|
{MAP_FMT (SN9C10X, ENCODED), GST_V4L2_CODEC | GST_V4L2_RESOLUTION_AND_RATE},
|
|
|
|
{MAP_FMT (PWC1, ENCODED), GST_V4L2_CODEC | GST_V4L2_RESOLUTION_AND_RATE},
|
|
|
|
{MAP_FMT (PWC2, ENCODED), GST_V4L2_CODEC | GST_V4L2_RESOLUTION_AND_RATE},
|
2014-03-13 17:21:41 +00:00
|
|
|
};
|
2024-08-14 19:21:44 +00:00
|
|
|
#undef MAP_FMT
|
|
|
|
/* *INDENT-ON* */
|
2014-03-13 17:21:41 +00:00
|
|
|
#define GST_V4L2_FORMAT_COUNT (G_N_ELEMENTS (gst_v4l2_formats))
|
|
|
|
|
2013-08-19 17:19:42 +00:00
|
|
|
static GSList *gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object);
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_V4L2_DEVICE_FLAGS (gst_v4l2_device_get_type ())
|
2010-03-17 17:23:00 +00:00
|
|
|
static GType
|
2006-05-11 17:59:59 +00:00
|
|
|
gst_v4l2_device_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4l2_device_type = 0;
|
|
|
|
|
|
|
|
if (v4l2_device_type == 0) {
|
|
|
|
static const GFlagsValue values[] = {
|
2006-09-26 13:18:06 +00:00
|
|
|
{V4L2_CAP_VIDEO_CAPTURE, "Device supports video capture", "capture"},
|
|
|
|
{V4L2_CAP_VIDEO_OUTPUT, "Device supports video playback", "output"},
|
|
|
|
{V4L2_CAP_VIDEO_OVERLAY, "Device supports video overlay", "overlay"},
|
|
|
|
|
|
|
|
{V4L2_CAP_VBI_CAPTURE, "Device supports the VBI capture", "vbi-capture"},
|
|
|
|
{V4L2_CAP_VBI_OUTPUT, "Device supports the VBI output", "vbi-output"},
|
|
|
|
|
|
|
|
{V4L2_CAP_TUNER, "Device has a tuner or modulator", "tuner"},
|
|
|
|
{V4L2_CAP_AUDIO, "Device has audio inputs or outputs", "audio"},
|
2006-05-11 17:59:59 +00:00
|
|
|
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
v4l2_device_type =
|
|
|
|
g_flags_register_static ("GstV4l2DeviceTypeFlags", values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return v4l2_device_type;
|
|
|
|
}
|
|
|
|
|
2010-04-04 11:43:41 +00:00
|
|
|
#define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_v4l2_tv_norm_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4l2_tv_norm = 0;
|
|
|
|
|
|
|
|
if (!v4l2_tv_norm) {
|
|
|
|
static const GEnumValue tv_norms[] = {
|
|
|
|
{0, "none", "none"},
|
|
|
|
|
|
|
|
{V4L2_STD_NTSC, "NTSC", "NTSC"},
|
|
|
|
{V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"},
|
|
|
|
{V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"},
|
|
|
|
{V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"},
|
|
|
|
{V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"},
|
|
|
|
|
|
|
|
{V4L2_STD_PAL, "PAL", "PAL"},
|
|
|
|
{V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"},
|
|
|
|
{V4L2_STD_PAL_B, "PAL-B", "PAL-B"},
|
|
|
|
{V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"},
|
|
|
|
{V4L2_STD_PAL_G, "PAL-G", "PAL-G"},
|
|
|
|
{V4L2_STD_PAL_H, "PAL-H", "PAL-H"},
|
|
|
|
{V4L2_STD_PAL_I, "PAL-I", "PAL-I"},
|
|
|
|
{V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"},
|
|
|
|
{V4L2_STD_PAL_D, "PAL-D", "PAL-D"},
|
|
|
|
{V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"},
|
|
|
|
{V4L2_STD_PAL_K, "PAL-K", "PAL-K"},
|
|
|
|
{V4L2_STD_PAL_M, "PAL-M", "PAL-M"},
|
|
|
|
{V4L2_STD_PAL_N, "PAL-N", "PAL-N"},
|
|
|
|
{V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"},
|
|
|
|
{V4L2_STD_PAL_60, "PAL-60", "PAL-60"},
|
|
|
|
|
|
|
|
{V4L2_STD_SECAM, "SECAM", "SECAM"},
|
|
|
|
{V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"},
|
|
|
|
{V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"},
|
|
|
|
{V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"},
|
|
|
|
{V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"},
|
|
|
|
{V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"},
|
|
|
|
{V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"},
|
|
|
|
{V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"},
|
|
|
|
{V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"},
|
|
|
|
{V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"},
|
|
|
|
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms);
|
|
|
|
}
|
|
|
|
|
|
|
|
return v4l2_tv_norm;
|
|
|
|
}
|
|
|
|
|
2013-11-28 21:59:59 +00:00
|
|
|
GType
|
2011-07-18 16:54:49 +00:00
|
|
|
gst_v4l2_io_mode_get_type (void)
|
|
|
|
{
|
|
|
|
static GType v4l2_io_mode = 0;
|
|
|
|
|
|
|
|
if (!v4l2_io_mode) {
|
|
|
|
static const GEnumValue io_modes[] = {
|
|
|
|
{GST_V4L2_IO_AUTO, "GST_V4L2_IO_AUTO", "auto"},
|
|
|
|
{GST_V4L2_IO_RW, "GST_V4L2_IO_RW", "rw"},
|
|
|
|
{GST_V4L2_IO_MMAP, "GST_V4L2_IO_MMAP", "mmap"},
|
|
|
|
{GST_V4L2_IO_USERPTR, "GST_V4L2_IO_USERPTR", "userptr"},
|
2013-02-19 10:47:20 +00:00
|
|
|
{GST_V4L2_IO_DMABUF, "GST_V4L2_IO_DMABUF", "dmabuf"},
|
2014-04-14 16:19:39 +00:00
|
|
|
{GST_V4L2_IO_DMABUF_IMPORT, "GST_V4L2_IO_DMABUF_IMPORT",
|
|
|
|
"dmabuf-import"},
|
2011-07-18 16:54:49 +00:00
|
|
|
|
|
|
|
{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
v4l2_io_mode = g_enum_register_static ("GstV4l2IOMode", io_modes);
|
|
|
|
}
|
|
|
|
return v4l2_io_mode;
|
|
|
|
}
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
void
|
2009-08-04 07:14:20 +00:00
|
|
|
gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
|
|
|
|
const char *default_device)
|
2006-05-11 17:59:59 +00:00
|
|
|
{
|
2006-09-26 13:18:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE,
|
|
|
|
g_param_spec_string ("device", "Device", "Device location",
|
2010-06-21 09:15:14 +00:00
|
|
|
default_device, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2006-09-26 13:18:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
|
|
|
|
g_param_spec_string ("device-name", "Device name",
|
2010-06-21 09:15:14 +00:00
|
|
|
"Name of the device", DEFAULT_PROP_DEVICE_NAME,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2008-03-26 15:10:08 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
|
|
|
|
g_param_spec_int ("device-fd", "File descriptor",
|
|
|
|
"File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
|
2010-06-21 09:15:14 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2006-09-26 13:18:06 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FLAGS,
|
|
|
|
g_param_spec_flags ("flags", "Flags", "Device type flags",
|
2010-06-21 09:15:14 +00:00
|
|
|
GST_TYPE_V4L2_DEVICE_FLAGS, DEFAULT_PROP_FLAGS,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2010-06-22 12:48:04 +00:00
|
|
|
|
2010-09-15 16:02:57 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:brightness:
|
2010-09-15 16:02:57 +00:00
|
|
|
*
|
|
|
|
* Picture brightness, or more precisely, the black level
|
|
|
|
*/
|
2010-06-22 12:48:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
|
|
|
|
g_param_spec_int ("brightness", "Brightness",
|
|
|
|
"Picture brightness, or more precisely, the black level", G_MININT,
|
|
|
|
G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
|
2010-09-15 16:02:57 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:contrast:
|
2010-09-15 16:02:57 +00:00
|
|
|
*
|
|
|
|
* Picture contrast or luma gain
|
|
|
|
*/
|
2010-06-22 12:48:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTRAST,
|
|
|
|
g_param_spec_int ("contrast", "Contrast",
|
|
|
|
"Picture contrast or luma gain", G_MININT,
|
|
|
|
G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
|
2010-09-15 16:02:57 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:saturation:
|
2010-09-15 16:02:57 +00:00
|
|
|
*
|
|
|
|
* Picture color saturation or chroma gain
|
|
|
|
*/
|
2010-06-22 12:48:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SATURATION,
|
|
|
|
g_param_spec_int ("saturation", "Saturation",
|
|
|
|
"Picture color saturation or chroma gain", G_MININT,
|
|
|
|
G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
|
2010-09-15 16:02:57 +00:00
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:hue:
|
2010-09-15 16:02:57 +00:00
|
|
|
*
|
|
|
|
* Hue or color balance
|
|
|
|
*/
|
2010-06-22 12:48:04 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_HUE,
|
|
|
|
g_param_spec_int ("hue", "Hue",
|
|
|
|
"Hue or color balance", G_MININT,
|
|
|
|
G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
|
2010-04-04 11:43:41 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:norm:
|
2010-04-04 11:43:41 +00:00
|
|
|
*
|
|
|
|
* TV norm
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TV_NORM,
|
|
|
|
g_param_spec_enum ("norm", "TV norm",
|
|
|
|
"video standard",
|
|
|
|
GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-07-18 16:54:49 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:io-mode:
|
2011-07-18 16:54:49 +00:00
|
|
|
*
|
|
|
|
* IO Mode
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_IO_MODE,
|
|
|
|
g_param_spec_enum ("io-mode", "IO mode",
|
|
|
|
"I/O mode",
|
|
|
|
GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2013-05-20 14:45:37 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:extra-controls:
|
2013-05-20 14:45:37 +00:00
|
|
|
*
|
|
|
|
* Additional v4l2 controls for the device. The controls are identified
|
|
|
|
* by the control name (lowercase with '_' for any non-alphanumeric
|
|
|
|
* characters).
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
|
|
|
|
g_param_spec_boxed ("extra-controls", "Extra Controls",
|
|
|
|
"Extra v4l2 controls (CIDs) for the device",
|
|
|
|
GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2013-06-04 06:26:33 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:pixel-aspect-ratio:
|
2013-06-04 06:26:33 +00:00
|
|
|
*
|
|
|
|
* The pixel aspect ratio of the device. This overwrites the pixel aspect
|
|
|
|
* ratio queried from the device.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
|
|
|
|
g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
|
|
|
|
"Overwrite the pixel aspect ratio of the device", "1/1",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
2013-11-18 14:44:36 +00:00
|
|
|
* GstV4l2Src:force-aspect-ratio:
|
2013-06-04 06:26:33 +00:00
|
|
|
*
|
|
|
|
* When enabled, the pixel aspect ratio queried from the device or set
|
|
|
|
* with the pixel-aspect-ratio property will be enforced.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
|
|
|
|
g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
|
|
|
|
"When enabled, the pixel aspect ratio will be enforced", TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2020-06-05 22:42:25 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_V4L2_DEVICE_FLAGS, 0);
|
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_V4L2_TV_NORM, 0);
|
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_V4L2_IO_MODE, 0);
|
2006-05-11 17:59:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 22:08:53 +00:00
|
|
|
void
|
|
|
|
gst_v4l2_object_install_m2m_properties_helper (GObjectClass * gobject_class)
|
|
|
|
{
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE,
|
|
|
|
g_param_spec_string ("device", "Device", "Device location",
|
|
|
|
NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
|
|
|
|
g_param_spec_string ("device-name", "Device name",
|
|
|
|
"Name of the device", DEFAULT_PROP_DEVICE_NAME,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
|
|
|
|
g_param_spec_int ("device-fd", "File descriptor",
|
|
|
|
"File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_OUTPUT_IO_MODE,
|
|
|
|
g_param_spec_enum ("output-io-mode", "Output IO mode",
|
|
|
|
"Output side I/O mode (matches sink pad)",
|
|
|
|
GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
|
|
|
|
g_param_spec_enum ("capture-io-mode", "Capture IO mode",
|
|
|
|
"Capture I/O mode (matches src pad)",
|
|
|
|
GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
|
|
|
|
g_param_spec_boxed ("extra-controls", "Extra Controls",
|
|
|
|
"Extra v4l2 controls (CIDs) for the device",
|
|
|
|
GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
2018-03-07 19:16:02 +00:00
|
|
|
/* Support for 32bit off_t, this wrapper is casting off_t to gint64 */
|
|
|
|
#ifdef HAVE_LIBV4L2
|
|
|
|
#if SIZEOF_OFF_T < 8
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
v4l2_mmap_wrapper (gpointer start, gsize length, gint prot, gint flags, gint fd,
|
|
|
|
off_t offset)
|
|
|
|
{
|
|
|
|
return v4l2_mmap (start, length, prot, flags, fd, (gint64) offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define v4l2_mmap v4l2_mmap_wrapper
|
|
|
|
|
|
|
|
#endif /* SIZEOF_OFF_T < 8 */
|
|
|
|
#endif /* HAVE_LIBV4L2 */
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
GstV4l2Object *
|
2006-05-19 18:31:25 +00:00
|
|
|
gst_v4l2_object_new (GstElement * element,
|
2017-12-13 19:39:47 +00:00
|
|
|
GstObject * debug_object,
|
2009-08-04 07:14:20 +00:00
|
|
|
enum v4l2_buf_type type,
|
2010-03-19 23:54:14 +00:00
|
|
|
const char *default_device,
|
2006-05-11 17:59:59 +00:00
|
|
|
GstV4l2GetInOutFunction get_in_out_func,
|
2007-05-30 14:57:44 +00:00
|
|
|
GstV4l2SetInOutFunction set_in_out_func,
|
|
|
|
GstV4l2UpdateFpsFunction update_fps_func)
|
2006-05-11 17:59:59 +00:00
|
|
|
{
|
|
|
|
GstV4l2Object *v4l2object;
|
|
|
|
|
|
|
|
/*
|
2009-08-04 07:14:20 +00:00
|
|
|
* some default values
|
2006-05-11 17:59:59 +00:00
|
|
|
*/
|
|
|
|
v4l2object = g_new0 (GstV4l2Object, 1);
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
v4l2object->type = type;
|
|
|
|
v4l2object->formats = NULL;
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
v4l2object->element = element;
|
2017-12-13 19:39:47 +00:00
|
|
|
v4l2object->dbg_obj = debug_object;
|
2006-05-11 17:59:59 +00:00
|
|
|
v4l2object->get_in_out_func = get_in_out_func;
|
|
|
|
v4l2object->set_in_out_func = set_in_out_func;
|
2007-05-30 14:57:44 +00:00
|
|
|
v4l2object->update_fps_func = update_fps_func;
|
2006-05-11 17:59:59 +00:00
|
|
|
|
|
|
|
v4l2object->video_fd = -1;
|
2011-07-13 09:19:28 +00:00
|
|
|
v4l2object->active = FALSE;
|
2009-08-04 07:14:20 +00:00
|
|
|
v4l2object->videodev = g_strdup (default_device);
|
2006-05-11 17:59:59 +00:00
|
|
|
|
sys/v4l2/: Renamed some properties to match the tuner interface naming.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c:
(gst_v4l2_object_install_properties_helper), (gst_v4l2_object_new),
(gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_create):
* sys/v4l2/gstv4l2tuner.c: (gst_v4l2_tuner_contains_channel),
(gst_v4l2_tuner_list_channels),
(gst_v4l2_tuner_set_channel_and_notify),
(gst_v4l2_tuner_get_channel), (gst_v4l2_tuner_contains_norm),
(gst_v4l2_tuner_list_norms), (gst_v4l2_tuner_set_norm_and_notify),
(gst_v4l2_tuner_get_norm):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_fill_lists), (gst_v4l2_empty_lists):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_get_fps):
Renamed some properties to match the tuner interface naming.
2006-09-27 17:04:22 +00:00
|
|
|
v4l2object->norms = NULL;
|
|
|
|
v4l2object->channels = NULL;
|
2006-05-11 17:59:59 +00:00
|
|
|
v4l2object->colors = NULL;
|
|
|
|
|
2013-06-04 06:26:33 +00:00
|
|
|
v4l2object->keep_aspect = TRUE;
|
|
|
|
|
2013-11-13 12:05:40 +00:00
|
|
|
v4l2object->n_v4l2_planes = 0;
|
|
|
|
|
2013-11-28 22:10:29 +00:00
|
|
|
v4l2object->no_initial_format = FALSE;
|
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
v4l2object->poll = gst_poll_new (TRUE);
|
|
|
|
v4l2object->can_poll_device = TRUE;
|
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
/* We now disable libv4l2 by default, but have an env to enable it. */
|
|
|
|
#ifdef HAVE_LIBV4L2
|
|
|
|
if (g_getenv ("GST_V4L2_USE_LIBV4L2")) {
|
|
|
|
v4l2object->fd_open = v4l2_fd_open;
|
|
|
|
v4l2object->close = v4l2_close;
|
|
|
|
v4l2object->dup = v4l2_dup;
|
|
|
|
v4l2object->ioctl = v4l2_ioctl;
|
|
|
|
v4l2object->read = v4l2_read;
|
|
|
|
v4l2object->mmap = v4l2_mmap;
|
|
|
|
v4l2object->munmap = v4l2_munmap;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
v4l2object->fd_open = NULL;
|
|
|
|
v4l2object->close = close;
|
|
|
|
v4l2object->dup = dup;
|
|
|
|
v4l2object->ioctl = ioctl;
|
|
|
|
v4l2object->read = read;
|
2017-12-19 09:37:58 +00:00
|
|
|
v4l2object->mmap = mmap;
|
2017-07-24 18:19:02 +00:00
|
|
|
v4l2object->munmap = munmap;
|
|
|
|
}
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
return v4l2object;
|
|
|
|
}
|
|
|
|
|
2023-04-12 21:18:13 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
g_slist_foreach (v4l2object->formats, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (v4l2object->formats);
|
|
|
|
v4l2object->formats = NULL;
|
|
|
|
v4l2object->fmtdesc = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
void
|
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
|
|
|
gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
|
2006-05-11 17:59:59 +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
|
|
|
g_return_if_fail (v4l2object != NULL);
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2015-11-15 05:51:11 +00:00
|
|
|
g_free (v4l2object->videodev);
|
2020-09-08 15:35:50 +00:00
|
|
|
g_free (v4l2object->par);
|
2015-11-15 05:51:11 +00:00
|
|
|
g_free (v4l2object->channel);
|
2008-08-26 12:27:11 +00:00
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
gst_poll_free (v4l2object->poll);
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
if (v4l2object->formats) {
|
|
|
|
gst_v4l2_object_clear_format_list (v4l2object);
|
|
|
|
}
|
|
|
|
|
2012-10-22 21:58:07 +00:00
|
|
|
if (v4l2object->probed_caps) {
|
|
|
|
gst_caps_unref (v4l2object->probed_caps);
|
|
|
|
}
|
|
|
|
|
2016-10-27 10:01:55 +00:00
|
|
|
if (v4l2object->extra_controls) {
|
|
|
|
gst_structure_free (v4l2object->extra_controls);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
g_free (v4l2object);
|
2006-05-11 17:59:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2010-06-22 12:48:04 +00:00
|
|
|
static gint
|
|
|
|
gst_v4l2_object_prop_to_cid (guint prop_id)
|
|
|
|
{
|
|
|
|
gint cid = -1;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_BRIGHTNESS:
|
|
|
|
cid = V4L2_CID_BRIGHTNESS;
|
|
|
|
break;
|
|
|
|
case PROP_CONTRAST:
|
|
|
|
cid = V4L2_CID_CONTRAST;
|
|
|
|
break;
|
|
|
|
case PROP_SATURATION:
|
|
|
|
cid = V4L2_CID_SATURATION;
|
|
|
|
break;
|
|
|
|
case PROP_HUE:
|
|
|
|
cid = V4L2_CID_HUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("unmapped property id: %d", prop_id);
|
|
|
|
}
|
|
|
|
return cid;
|
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
gboolean
|
2006-05-19 18:31:25 +00:00
|
|
|
gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
|
2006-05-11 17:59:59 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DEVICE:
|
Small cleanups.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_set_property_helper),
(gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_get_read),
(gst_v4l2src_create):
* sys/v4l2/gstv4l2xoverlay.c: (gst_v4l2_xoverlay_open):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_fill_lists), (gst_v4l2_open), (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_grab_frame), (gst_v4l2src_get_capture),
(gst_v4l2src_set_capture), (gst_v4l2src_capture_init),
(gst_v4l2src_capture_start), (gst_v4l2src_capture_stop),
(gst_v4l2src_buffer_new):
* tests/icles/v4l2src-test.c: (my_bus_callback), (main):
Small cleanups.
Fix error messages.
Use locks when getting timestamps.
Fix leaks in test.
Add licensing header to tests.
2006-09-27 16:14:18 +00:00
|
|
|
g_free (v4l2object->videodev);
|
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
|
|
|
v4l2object->videodev = g_value_dup_string (value);
|
2006-05-11 17:59:59 +00:00
|
|
|
break;
|
2010-06-22 12:48:04 +00:00
|
|
|
case PROP_BRIGHTNESS:
|
|
|
|
case PROP_CONTRAST:
|
|
|
|
case PROP_SATURATION:
|
|
|
|
case PROP_HUE:
|
|
|
|
{
|
|
|
|
gint cid = gst_v4l2_object_prop_to_cid (prop_id);
|
|
|
|
|
|
|
|
if (cid != -1) {
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object)) {
|
|
|
|
gst_v4l2_set_attribute (v4l2object, cid, g_value_get_int (value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-04 11:43:41 +00:00
|
|
|
case PROP_TV_NORM:
|
|
|
|
v4l2object->tv_norm = g_value_get_enum (value);
|
2006-05-11 17:59:59 +00:00
|
|
|
break;
|
2010-04-04 11:43:41 +00:00
|
|
|
#if 0
|
sys/v4l2/: Renamed some properties to match the tuner interface naming.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c:
(gst_v4l2_object_install_properties_helper), (gst_v4l2_object_new),
(gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_create):
* sys/v4l2/gstv4l2tuner.c: (gst_v4l2_tuner_contains_channel),
(gst_v4l2_tuner_list_channels),
(gst_v4l2_tuner_set_channel_and_notify),
(gst_v4l2_tuner_get_channel), (gst_v4l2_tuner_contains_norm),
(gst_v4l2_tuner_list_norms), (gst_v4l2_tuner_set_norm_and_notify),
(gst_v4l2_tuner_get_norm):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_fill_lists), (gst_v4l2_empty_lists):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_get_fps):
Renamed some properties to match the tuner interface naming.
2006-09-27 17:04:22 +00:00
|
|
|
case PROP_CHANNEL:
|
2006-05-11 17:59:59 +00:00
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object)) {
|
|
|
|
GstTuner *tuner = GST_TUNER (v4l2object->element);
|
|
|
|
GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner,
|
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
|
|
|
(gchar *) g_value_get_string (value));
|
2006-05-11 17:59:59 +00:00
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
/* like gst_tuner_set_channel (tuner, channel)
|
|
|
|
without g_object_notify */
|
|
|
|
gst_v4l2_tuner_set_channel (v4l2object, channel);
|
|
|
|
}
|
|
|
|
} else {
|
sys/v4l2/: Renamed some properties to match the tuner interface naming.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c:
(gst_v4l2_object_install_properties_helper), (gst_v4l2_object_new),
(gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_create):
* sys/v4l2/gstv4l2tuner.c: (gst_v4l2_tuner_contains_channel),
(gst_v4l2_tuner_list_channels),
(gst_v4l2_tuner_set_channel_and_notify),
(gst_v4l2_tuner_get_channel), (gst_v4l2_tuner_contains_norm),
(gst_v4l2_tuner_list_norms), (gst_v4l2_tuner_set_norm_and_notify),
(gst_v4l2_tuner_get_norm):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_fill_lists), (gst_v4l2_empty_lists):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_get_fps):
Renamed some properties to match the tuner interface naming.
2006-09-27 17:04:22 +00:00
|
|
|
g_free (v4l2object->channel);
|
|
|
|
v4l2object->channel = g_value_dup_string (value);
|
2006-05-11 17:59:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_FREQUENCY:
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object)) {
|
|
|
|
GstTuner *tuner = GST_TUNER (v4l2object->element);
|
|
|
|
GstTunerChannel *channel = gst_tuner_get_channel (tuner);
|
|
|
|
|
|
|
|
if (channel &&
|
|
|
|
GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
|
|
|
|
/* like
|
|
|
|
gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value))
|
|
|
|
without g_object_notify */
|
|
|
|
gst_v4l2_tuner_set_frequency (v4l2object, channel,
|
|
|
|
g_value_get_ulong (value));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
v4l2object->frequency = g_value_get_ulong (value);
|
|
|
|
}
|
|
|
|
break;
|
sys/v4l2/: Fix EIO handing when capturing. Add new property to specify the number of buffers to enque (and remove the...
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c:
(gst_v4l2_object_install_properties_helper),
(gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_init), (gst_v4l2src_set_property),
(gst_v4l2src_get_property), (gst_v4l2src_set_caps):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_fill_format_list),
(gst_v4l2src_grab_frame), (gst_v4l2src_set_capture),
(gst_v4l2src_capture_init), (gst_v4l2src_capture_start),
(gst_v4l2src_capture_deinit):
Fix EIO handing when capturing. Add new property to specify the number of
buffers to enque (and remove the borked num-buffers usage).
2007-01-17 14:30:50 +00:00
|
|
|
#endif
|
2014-05-15 22:08:53 +00:00
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
case PROP_IO_MODE:
|
|
|
|
v4l2object->req_mode = g_value_get_enum (value);
|
|
|
|
break;
|
2014-05-15 22:08:53 +00:00
|
|
|
case PROP_CAPTURE_IO_MODE:
|
|
|
|
g_return_val_if_fail (!V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
|
|
|
|
v4l2object->req_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_IO_MODE:
|
|
|
|
g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
|
|
|
|
v4l2object->req_mode = g_value_get_enum (value);
|
|
|
|
break;
|
2013-05-20 14:45:37 +00:00
|
|
|
case PROP_EXTRA_CONTROLS:{
|
|
|
|
const GstStructure *s = gst_value_get_structure (value);
|
|
|
|
|
|
|
|
if (v4l2object->extra_controls)
|
|
|
|
gst_structure_free (v4l2object->extra_controls);
|
|
|
|
|
|
|
|
v4l2object->extra_controls = s ? gst_structure_copy (s) : NULL;
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object))
|
|
|
|
gst_v4l2_set_controls (v4l2object, v4l2object->extra_controls);
|
|
|
|
break;
|
|
|
|
}
|
2013-06-04 06:26:33 +00:00
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
2017-09-13 15:52:09 +00:00
|
|
|
if (v4l2object->par) {
|
|
|
|
g_value_unset (v4l2object->par);
|
|
|
|
g_free (v4l2object->par);
|
|
|
|
}
|
2013-06-04 06:26:33 +00:00
|
|
|
v4l2object->par = g_new0 (GValue, 1);
|
|
|
|
g_value_init (v4l2object->par, GST_TYPE_FRACTION);
|
|
|
|
if (!g_value_transform (value, v4l2object->par)) {
|
|
|
|
g_warning ("Could not transform string to aspect ratio");
|
|
|
|
gst_value_set_fraction (v4l2object->par, 1, 1);
|
|
|
|
}
|
2017-09-13 15:52:09 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "set PAR to %d/%d",
|
2013-06-04 06:26:33 +00:00
|
|
|
gst_value_get_fraction_numerator (v4l2object->par),
|
|
|
|
gst_value_get_fraction_denominator (v4l2object->par));
|
|
|
|
break;
|
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
v4l2object->keep_aspect = g_value_get_boolean (value);
|
|
|
|
break;
|
2006-05-11 17:59:59 +00:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
2006-05-19 18:31:25 +00:00
|
|
|
gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object,
|
2006-05-11 17:59:59 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DEVICE:
|
|
|
|
g_value_set_string (value, v4l2object->videodev);
|
|
|
|
break;
|
|
|
|
case PROP_DEVICE_NAME:
|
|
|
|
{
|
2018-05-17 00:16:44 +00:00
|
|
|
const guchar *name = NULL;
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2018-05-17 00:16:44 +00:00
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object))
|
|
|
|
name = v4l2object->vcap.card;
|
|
|
|
|
|
|
|
g_value_set_string (value, (gchar *) name);
|
2006-05-11 17:59:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-26 15:10:08 +00:00
|
|
|
case PROP_DEVICE_FD:
|
|
|
|
{
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object))
|
|
|
|
g_value_set_int (value, v4l2object->video_fd);
|
|
|
|
else
|
|
|
|
g_value_set_int (value, DEFAULT_PROP_DEVICE_FD);
|
|
|
|
break;
|
|
|
|
}
|
2006-05-11 17:59:59 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
{
|
|
|
|
guint flags = 0;
|
|
|
|
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object)) {
|
2016-07-02 08:56:07 +00:00
|
|
|
flags |= v4l2object->device_caps &
|
2006-05-11 17:59:59 +00:00
|
|
|
(V4L2_CAP_VIDEO_CAPTURE |
|
|
|
|
V4L2_CAP_VIDEO_OUTPUT |
|
2006-09-27 15:14:07 +00:00
|
|
|
V4L2_CAP_VIDEO_OVERLAY |
|
|
|
|
V4L2_CAP_VBI_CAPTURE |
|
|
|
|
V4L2_CAP_VBI_OUTPUT | V4L2_CAP_TUNER | V4L2_CAP_AUDIO);
|
2013-11-13 12:05:40 +00:00
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
if (v4l2object->device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
|
2013-11-13 12:05:40 +00:00
|
|
|
flags |= V4L2_CAP_VIDEO_CAPTURE;
|
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
if (v4l2object->device_caps & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
|
2013-11-13 12:05:40 +00:00
|
|
|
flags |= V4L2_CAP_VIDEO_OUTPUT;
|
2006-05-11 17:59:59 +00:00
|
|
|
}
|
|
|
|
g_value_set_flags (value, flags);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-22 12:48:04 +00:00
|
|
|
case PROP_BRIGHTNESS:
|
|
|
|
case PROP_CONTRAST:
|
|
|
|
case PROP_SATURATION:
|
|
|
|
case PROP_HUE:
|
|
|
|
{
|
|
|
|
gint cid = gst_v4l2_object_prop_to_cid (prop_id);
|
|
|
|
|
|
|
|
if (cid != -1) {
|
|
|
|
if (GST_V4L2_IS_OPEN (v4l2object)) {
|
|
|
|
gint v;
|
|
|
|
if (gst_v4l2_get_attribute (v4l2object, cid, &v)) {
|
|
|
|
g_value_set_int (value, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-04 11:43:41 +00:00
|
|
|
case PROP_TV_NORM:
|
|
|
|
g_value_set_enum (value, v4l2object->tv_norm);
|
|
|
|
break;
|
2011-07-18 16:54:49 +00:00
|
|
|
case PROP_IO_MODE:
|
|
|
|
g_value_set_enum (value, v4l2object->req_mode);
|
|
|
|
break;
|
2014-05-15 22:08:53 +00:00
|
|
|
case PROP_CAPTURE_IO_MODE:
|
|
|
|
g_return_val_if_fail (!V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
|
|
|
|
g_value_set_enum (value, v4l2object->req_mode);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT_IO_MODE:
|
|
|
|
g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
|
|
|
|
g_value_set_enum (value, v4l2object->req_mode);
|
|
|
|
break;
|
2013-05-20 14:45:37 +00:00
|
|
|
case PROP_EXTRA_CONTROLS:
|
|
|
|
gst_value_set_structure (value, v4l2object->extra_controls);
|
|
|
|
break;
|
2013-06-04 06:26:33 +00:00
|
|
|
case PROP_PIXEL_ASPECT_RATIO:
|
|
|
|
if (v4l2object->par)
|
|
|
|
g_value_transform (v4l2object->par, value);
|
|
|
|
break;
|
|
|
|
case PROP_FORCE_ASPECT_RATIO:
|
|
|
|
g_value_set_boolean (value, v4l2object->keep_aspect);
|
|
|
|
break;
|
2006-05-11 17:59:59 +00:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-30 11:12:35 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_get_driver_min_buffers (GstV4l2Object * v4l2object)
|
|
|
|
{
|
2015-06-05 19:32:10 +00:00
|
|
|
struct v4l2_control control = { 0, };
|
2015-03-30 11:12:35 +00:00
|
|
|
|
2015-06-05 19:32:10 +00:00
|
|
|
g_return_if_fail (GST_V4L2_IS_OPEN (v4l2object));
|
2015-03-30 11:12:35 +00:00
|
|
|
|
2015-06-05 19:32:10 +00:00
|
|
|
if (V4L2_TYPE_IS_OUTPUT (v4l2object->type))
|
|
|
|
control.id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT;
|
|
|
|
else
|
|
|
|
control.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE;
|
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) == 0) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2015-06-05 19:32:10 +00:00
|
|
|
"driver requires a minimum of %d buffers", control.value);
|
|
|
|
v4l2object->min_buffers = control.value;
|
2015-03-30 11:12:35 +00:00
|
|
|
} else {
|
|
|
|
v4l2object->min_buffers = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_set_defaults (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
GstTunerNorm *norm = NULL;
|
|
|
|
GstTunerChannel *channel = NULL;
|
2009-08-04 07:14:20 +00:00
|
|
|
GstTuner *tuner;
|
|
|
|
|
|
|
|
if (!GST_IS_TUNER (v4l2object->element))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tuner = GST_TUNER (v4l2object->element);
|
2006-05-11 17:59:59 +00:00
|
|
|
|
2010-04-04 11:43:41 +00:00
|
|
|
if (v4l2object->tv_norm)
|
|
|
|
norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "tv_norm=0x%" G_GINT64_MODIFIER "x, "
|
2011-09-29 14:41:53 +00:00
|
|
|
"norm=%p", (guint64) v4l2object->tv_norm, norm);
|
2006-05-11 17:59:59 +00:00
|
|
|
if (norm) {
|
|
|
|
gst_tuner_set_norm (tuner, norm);
|
|
|
|
} else {
|
|
|
|
norm =
|
|
|
|
GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element)));
|
|
|
|
if (norm) {
|
2010-04-04 11:43:41 +00:00
|
|
|
v4l2object->tv_norm =
|
|
|
|
gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm);
|
2006-05-11 17:59:59 +00:00
|
|
|
gst_tuner_norm_changed (tuner, norm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
sys/v4l2/: Renamed some properties to match the tuner interface naming.
Original commit message from CVS:
* sys/v4l2/gstv4l2object.c:
(gst_v4l2_object_install_properties_helper), (gst_v4l2_object_new),
(gst_v4l2_object_set_property_helper),
(gst_v4l2_object_get_property_helper), (gst_v4l2_set_defaults):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_create):
* sys/v4l2/gstv4l2tuner.c: (gst_v4l2_tuner_contains_channel),
(gst_v4l2_tuner_list_channels),
(gst_v4l2_tuner_set_channel_and_notify),
(gst_v4l2_tuner_get_channel), (gst_v4l2_tuner_contains_norm),
(gst_v4l2_tuner_list_norms), (gst_v4l2_tuner_set_norm_and_notify),
(gst_v4l2_tuner_get_norm):
* sys/v4l2/v4l2_calls.c: (gst_v4l2_get_capabilities),
(gst_v4l2_fill_lists), (gst_v4l2_empty_lists):
* sys/v4l2/v4l2src_calls.c: (gst_v4l2src_get_fps):
Renamed some properties to match the tuner interface naming.
2006-09-27 17:04:22 +00:00
|
|
|
if (v4l2object->channel)
|
|
|
|
channel = gst_tuner_find_channel_by_name (tuner, v4l2object->channel);
|
2006-05-11 17:59:59 +00:00
|
|
|
if (channel) {
|
|
|
|
gst_tuner_set_channel (tuner, channel);
|
|
|
|
} else {
|
|
|
|
channel =
|
2008-08-23 15:33:49 +00:00
|
|
|
GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER
|
|
|
|
(v4l2object->element)));
|
2007-02-22 17:53:26 +00:00
|
|
|
if (channel) {
|
|
|
|
g_free (v4l2object->channel);
|
|
|
|
v4l2object->channel = g_strdup (channel->label);
|
|
|
|
gst_tuner_channel_changed (tuner, channel);
|
|
|
|
}
|
2006-05-11 17:59:59 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 17:53:26 +00:00
|
|
|
if (channel
|
|
|
|
&& GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
|
2006-05-11 17:59:59 +00:00
|
|
|
if (v4l2object->frequency != 0) {
|
|
|
|
gst_tuner_set_frequency (tuner, channel, v4l2object->frequency);
|
|
|
|
} else {
|
|
|
|
v4l2object->frequency = gst_tuner_get_frequency (tuner, channel);
|
|
|
|
if (v4l2object->frequency == 0) {
|
|
|
|
/* guess */
|
|
|
|
gst_tuner_set_frequency (tuner, channel, 1000);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_init_poll (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
gst_poll_fd_init (&v4l2object->pollfd);
|
|
|
|
v4l2object->pollfd.fd = v4l2object->video_fd;
|
|
|
|
gst_poll_add_fd (v4l2object->poll, &v4l2object->pollfd);
|
|
|
|
if (V4L2_TYPE_IS_OUTPUT (v4l2object->type))
|
|
|
|
gst_poll_fd_ctl_write (v4l2object->poll, &v4l2object->pollfd, TRUE);
|
|
|
|
else
|
|
|
|
gst_poll_fd_ctl_read (v4l2object->poll, &v4l2object->pollfd, TRUE);
|
|
|
|
|
|
|
|
v4l2object->can_poll_device = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
gboolean
|
2020-08-06 11:15:10 +00:00
|
|
|
gst_v4l2_object_open (GstV4l2Object * v4l2object, GstV4l2Error * error)
|
2006-05-11 17:59:59 +00:00
|
|
|
{
|
2020-08-06 11:15:10 +00:00
|
|
|
if (gst_v4l2_open (v4l2object, error))
|
2006-05-11 17:59:59 +00:00
|
|
|
gst_v4l2_set_defaults (v4l2object);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
gst_v4l2_object_init_poll (v4l2object);
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-28 22:09:26 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_open_shared (GstV4l2Object * v4l2object, GstV4l2Object * other)
|
|
|
|
{
|
2023-04-15 02:22:06 +00:00
|
|
|
if (gst_v4l2_dup (v4l2object, other)) {
|
|
|
|
gst_v4l2_object_init_poll (v4l2object);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-28 22:09:26 +00:00
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
return FALSE;
|
2013-11-28 22:09:26 +00:00
|
|
|
}
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
gboolean
|
2011-07-13 14:33:58 +00:00
|
|
|
gst_v4l2_object_close (GstV4l2Object * v4l2object)
|
2006-05-11 17:59:59 +00:00
|
|
|
{
|
|
|
|
if (!gst_v4l2_close (v4l2object))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-11-18 13:27:48 +00:00
|
|
|
gst_caps_replace (&v4l2object->probed_caps, NULL);
|
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
/* reset our copy of the device caps */
|
|
|
|
v4l2object->device_caps = 0;
|
|
|
|
|
2009-08-14 08:11:25 +00:00
|
|
|
if (v4l2object->formats) {
|
|
|
|
gst_v4l2_object_clear_format_list (v4l2object);
|
|
|
|
}
|
|
|
|
|
2017-09-13 15:52:09 +00:00
|
|
|
if (v4l2object->par) {
|
|
|
|
g_value_unset (v4l2object->par);
|
|
|
|
g_free (v4l2object->par);
|
|
|
|
v4l2object->par = NULL;
|
|
|
|
}
|
2018-08-19 13:39:16 +00:00
|
|
|
|
2018-08-02 06:40:17 +00:00
|
|
|
if (v4l2object->channel) {
|
|
|
|
g_free (v4l2object->channel);
|
|
|
|
v4l2object->channel = NULL;
|
|
|
|
}
|
2017-09-13 15:52:09 +00:00
|
|
|
|
2023-12-18 02:03:57 +00:00
|
|
|
/* remove old fd from poll */
|
|
|
|
if (v4l2object->poll)
|
|
|
|
gst_poll_remove_fd (v4l2object->poll, &v4l2object->pollfd);
|
|
|
|
|
2006-05-11 17:59:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
static struct v4l2_fmtdesc *
|
|
|
|
gst_v4l2_object_get_format_from_fourcc (GstV4l2Object * v4l2object,
|
|
|
|
guint32 fourcc)
|
|
|
|
{
|
|
|
|
struct v4l2_fmtdesc *fmt;
|
|
|
|
GSList *walk;
|
|
|
|
|
|
|
|
if (fourcc == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
walk = gst_v4l2_object_get_format_list (v4l2object);
|
|
|
|
while (walk) {
|
|
|
|
fmt = (struct v4l2_fmtdesc *) walk->data;
|
|
|
|
if (fmt->pixelformat == fourcc)
|
|
|
|
return fmt;
|
|
|
|
/* special case for jpeg */
|
2011-02-15 18:59:32 +00:00
|
|
|
if (fmt->pixelformat == V4L2_PIX_FMT_MJPEG ||
|
2014-03-15 10:13:05 +00:00
|
|
|
fmt->pixelformat == V4L2_PIX_FMT_JPEG ||
|
|
|
|
fmt->pixelformat == V4L2_PIX_FMT_PJPG) {
|
|
|
|
if (fourcc == V4L2_PIX_FMT_JPEG || fourcc == V4L2_PIX_FMT_MJPEG ||
|
|
|
|
fourcc == V4L2_PIX_FMT_PJPG) {
|
2011-02-15 18:59:32 +00:00
|
|
|
return fmt;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
walk = g_slist_next (walk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* complete made up ranking, the values themselves are meaningless */
|
2011-12-02 12:01:22 +00:00
|
|
|
/* These ranks MUST be X such that X<<15 fits on a signed int - see
|
|
|
|
the comment at the end of gst_v4l2_object_format_get_rank. */
|
2009-08-04 07:14:20 +00:00
|
|
|
#define YUV_BASE_RANK 1000
|
|
|
|
#define JPEG_BASE_RANK 500
|
|
|
|
#define DV_BASE_RANK 200
|
|
|
|
#define RGB_BASE_RANK 100
|
|
|
|
#define YUV_ODD_BASE_RANK 50
|
|
|
|
#define RGB_ODD_BASE_RANK 25
|
|
|
|
#define BAYER_BASE_RANK 15
|
|
|
|
#define S910_BASE_RANK 10
|
|
|
|
#define GREY_BASE_RANK 5
|
|
|
|
#define PWC_BASE_RANK 1
|
|
|
|
|
|
|
|
static gint
|
2009-09-03 18:38:50 +00:00
|
|
|
gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
2009-09-03 18:38:50 +00:00
|
|
|
guint32 fourcc = fmt->pixelformat;
|
2009-09-03 18:40:17 +00:00
|
|
|
gboolean emulated = ((fmt->flags & V4L2_FMT_FLAG_EMULATED) != 0);
|
2009-09-03 18:38:50 +00:00
|
|
|
gint rank = 0;
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
switch (fourcc) {
|
|
|
|
case V4L2_PIX_FMT_MJPEG:
|
2011-02-15 18:59:32 +00:00
|
|
|
case V4L2_PIX_FMT_PJPG:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = JPEG_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_JPEG:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = JPEG_BASE_RANK + 1;
|
|
|
|
break;
|
2009-09-07 16:28:51 +00:00
|
|
|
case V4L2_PIX_FMT_MPEG: /* MPEG */
|
|
|
|
rank = JPEG_BASE_RANK + 2;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_RGB332:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_ARGB555:
|
|
|
|
case V4L2_PIX_FMT_XRGB555:
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_RGB555:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_ARGB555X:
|
|
|
|
case V4L2_PIX_FMT_XRGB555X:
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_RGB555X:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_BGR666:
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
case V4L2_PIX_FMT_RGB565X:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_RGB444:
|
|
|
|
case V4L2_PIX_FMT_Y4:
|
|
|
|
case V4L2_PIX_FMT_Y6:
|
|
|
|
case V4L2_PIX_FMT_Y10:
|
|
|
|
case V4L2_PIX_FMT_Y12:
|
|
|
|
case V4L2_PIX_FMT_Y10BPACK:
|
|
|
|
case V4L2_PIX_FMT_YUV555:
|
|
|
|
case V4L2_PIX_FMT_YUV565:
|
|
|
|
case V4L2_PIX_FMT_YUV32:
|
|
|
|
case V4L2_PIX_FMT_NV12MT_16X16:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
case V4L2_PIX_FMT_H264_MVC:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = RGB_ODD_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_RGB24:
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = RGB_BASE_RANK - 1;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_ABGR32:
|
|
|
|
case V4L2_PIX_FMT_XBGR32:
|
2019-09-23 12:34:20 +00:00
|
|
|
case V4L2_PIX_FMT_BGRA32:
|
|
|
|
case V4L2_PIX_FMT_BGRX32:
|
|
|
|
case V4L2_PIX_FMT_RGBA32:
|
|
|
|
case V4L2_PIX_FMT_RGBX32:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_ARGB32:
|
|
|
|
case V4L2_PIX_FMT_XRGB32:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = RGB_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = GREY_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2013-12-10 19:29:55 +00:00
|
|
|
case V4L2_PIX_FMT_NV12MT: /* NV12 64x32 tile */
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
|
2013-11-13 12:05:40 +00:00
|
|
|
case V4L2_PIX_FMT_NV21M: /* Same as NV21 */
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
|
|
|
|
case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
|
2015-11-13 12:34:02 +00:00
|
|
|
case V4L2_PIX_FMT_NV16: /* 16 Y/CbCr 4:2:2 */
|
|
|
|
case V4L2_PIX_FMT_NV16M: /* Same as NV16 */
|
|
|
|
case V4L2_PIX_FMT_NV61: /* 16 Y/CrCb 4:2:2 */
|
|
|
|
case V4L2_PIX_FMT_NV61M: /* Same as NV61 */
|
|
|
|
case V4L2_PIX_FMT_NV24: /* 24 Y/CrCb 4:4:4 */
|
2022-01-25 19:34:32 +00:00
|
|
|
case V4L2_PIX_FMT_MM21: /* NV12 Y 16x32, UV 16x16 tile */
|
2021-10-19 06:41:04 +00:00
|
|
|
case V4L2_PIX_FMT_NV12M_8L128:
|
|
|
|
case V4L2_PIX_FMT_NV12M_10BE_8L128:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_ODD_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_YVU410: /* YVU9, 9 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 3;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YUV410: /* YUV9, 9 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 2;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YUV420: /* I420, 12 bits per pixel */
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_YUV420M:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 7;
|
|
|
|
break;
|
2018-12-10 13:10:05 +00:00
|
|
|
case V4L2_PIX_FMT_NV12: /* Y/CbCr 4:2:0, 12 bits per pixel */
|
|
|
|
case V4L2_PIX_FMT_NV12M: /* Same as NV12 */
|
|
|
|
rank = YUV_BASE_RANK + 8;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YUYV: /* YUY2, 16 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 10;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YVU420: /* YV12, 12 bits per pixel */
|
2023-03-28 07:29:46 +00:00
|
|
|
case V4L2_PIX_FMT_YVU420M:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 6;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_UYVY: /* UYVY, 16 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 9;
|
|
|
|
break;
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_YUV444:
|
|
|
|
rank = YUV_BASE_RANK + 6;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_Y41P: /* Y41P, 12 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 5;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YUV411P: /* Y41B, 12 bits per pixel */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 4;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_YUV422P: /* Y42B, 16 bits per pixel */
|
2024-04-12 09:17:53 +00:00
|
|
|
case V4L2_PIX_FMT_YUV422M:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = YUV_BASE_RANK + 8;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_DV:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = DV_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
case V4L2_PIX_FMT_WNVA: /* Winnov hw compress */
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = 0;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_SBGGR8:
|
2014-12-11 15:13:15 +00:00
|
|
|
case V4L2_PIX_FMT_SGBRG8:
|
|
|
|
case V4L2_PIX_FMT_SGRBG8:
|
|
|
|
case V4L2_PIX_FMT_SRGGB8:
|
2023-02-06 02:55:52 +00:00
|
|
|
case V4L2_PIX_FMT_SBGGR10:
|
|
|
|
case V4L2_PIX_FMT_SGBRG10:
|
|
|
|
case V4L2_PIX_FMT_SGRBG10:
|
|
|
|
case V4L2_PIX_FMT_SRGGB10:
|
|
|
|
case V4L2_PIX_FMT_SBGGR12:
|
|
|
|
case V4L2_PIX_FMT_SGBRG12:
|
|
|
|
case V4L2_PIX_FMT_SGRBG12:
|
|
|
|
case V4L2_PIX_FMT_SRGGB12:
|
|
|
|
case V4L2_PIX_FMT_SBGGR14:
|
|
|
|
case V4L2_PIX_FMT_SGBRG14:
|
|
|
|
case V4L2_PIX_FMT_SGRBG14:
|
|
|
|
case V4L2_PIX_FMT_SRGGB14:
|
|
|
|
case V4L2_PIX_FMT_SBGGR16:
|
|
|
|
case V4L2_PIX_FMT_SGBRG16:
|
|
|
|
case V4L2_PIX_FMT_SGRBG16:
|
|
|
|
case V4L2_PIX_FMT_SRGGB16:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = BAYER_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_SN9C10X:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = S910_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
case V4L2_PIX_FMT_PWC1:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = PWC_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_PWC2:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = PWC_BASE_RANK;
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
default:
|
2009-09-03 18:38:50 +00:00
|
|
|
rank = 0;
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-03 18:38:50 +00:00
|
|
|
/* All ranks are below 1<<15 so a shift by 15
|
|
|
|
* will a) make all non-emulated formats larger
|
|
|
|
* than emulated and b) will not overflow
|
|
|
|
*/
|
|
|
|
if (!emulated)
|
|
|
|
rank <<= 15;
|
|
|
|
|
|
|
|
return rank;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
format_cmp_func (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
2009-09-03 18:38:50 +00:00
|
|
|
const struct v4l2_fmtdesc *fa = a;
|
|
|
|
const struct v4l2_fmtdesc *fb = b;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2009-09-03 18:38:50 +00:00
|
|
|
if (fa->pixelformat == fb->pixelformat)
|
2009-08-04 07:14:20 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-08-06 17:07:46 +00:00
|
|
|
return gst_v4l2_object_format_get_rank (fb) -
|
|
|
|
gst_v4l2_object_format_get_rank (fa);
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* gst_v4l2_object_fill_format_list():
|
|
|
|
* create list of supported capture formats
|
|
|
|
* return value: TRUE on success, FALSE on error
|
|
|
|
******************************************************/
|
|
|
|
static gboolean
|
2013-11-13 12:05:40 +00:00
|
|
|
gst_v4l2_object_fill_format_list (GstV4l2Object * v4l2object,
|
|
|
|
enum v4l2_buf_type type)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
|
|
|
gint n;
|
|
|
|
struct v4l2_fmtdesc *format;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "getting src format enumerations");
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
/* format enumeration */
|
|
|
|
for (n = 0;; n++) {
|
|
|
|
format = g_new0 (struct v4l2_fmtdesc, 1);
|
|
|
|
|
|
|
|
format->index = n;
|
2013-11-13 12:05:40 +00:00
|
|
|
format->type = type;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
|
2009-08-04 07:14:20 +00:00
|
|
|
if (errno == EINVAL) {
|
|
|
|
g_free (format);
|
|
|
|
break; /* end of enumeration */
|
|
|
|
} else {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "index: %u", format->index);
|
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "type: %d", format->type);
|
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "flags: %08x", format->flags);
|
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "description: '%s'",
|
2009-08-04 07:14:20 +00:00
|
|
|
format->description);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "pixelformat: %" GST_FOURCC_FORMAT,
|
2009-08-04 07:14:20 +00:00
|
|
|
GST_FOURCC_ARGS (format->pixelformat));
|
|
|
|
|
|
|
|
/* sort formats according to our preference; we do this, because caps
|
|
|
|
* are probed in the order the formats are in the list, and the order of
|
|
|
|
* formats in the final probed caps matters for things like fixation */
|
|
|
|
v4l2object->formats = g_slist_insert_sorted (v4l2object->formats, format,
|
|
|
|
(GCompareFunc) format_cmp_func);
|
|
|
|
}
|
|
|
|
|
2010-08-06 19:04:59 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj, "got %d format(s):", n);
|
2010-08-06 19:04:59 +00:00
|
|
|
for (l = v4l2object->formats; l != NULL; l = l->next) {
|
|
|
|
format = l->data;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj,
|
2010-08-06 19:04:59 +00:00
|
|
|
" %" GST_FOURCC_FORMAT "%s", GST_FOURCC_ARGS (format->pixelformat),
|
|
|
|
((format->flags & V4L2_FMT_FLAG_EMULATED)) ? " (emulated)" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
failed:
|
|
|
|
{
|
2016-07-11 22:29:01 +00:00
|
|
|
g_free (format);
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
if (v4l2object->element)
|
2016-07-11 22:29:01 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
|
2016-07-11 21:38:00 +00:00
|
|
|
(_("Failed to enumerate possible video formats device '%s' can work "
|
|
|
|
"with"), v4l2object->videodev),
|
|
|
|
("Failed to get number %d in pixelformat enumeration for %s. (%d - %s)",
|
|
|
|
n, v4l2object->videodev, errno, g_strerror (errno)));
|
2016-07-11 22:29:01 +00:00
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 07:26:23 +00:00
|
|
|
/*
|
2013-11-13 12:05:40 +00:00
|
|
|
* Get the list of supported capture formats, a list of
|
2019-05-29 20:06:58 +00:00
|
|
|
* `struct v4l2_fmtdesc`.
|
2013-11-13 12:05:40 +00:00
|
|
|
*/
|
2012-10-22 21:58:07 +00:00
|
|
|
static GSList *
|
2009-08-04 07:14:20 +00:00
|
|
|
gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
|
|
|
|
{
|
2013-11-13 12:05:40 +00:00
|
|
|
if (!v4l2object->formats) {
|
|
|
|
|
|
|
|
/* check usual way */
|
|
|
|
gst_v4l2_object_fill_format_list (v4l2object, v4l2object->type);
|
|
|
|
|
|
|
|
/* if our driver supports multi-planar
|
|
|
|
* and if formats are still empty then we can workaround driver bug
|
|
|
|
* by also looking up formats as if our device was not supporting
|
|
|
|
* multiplanar */
|
|
|
|
if (!v4l2object->formats) {
|
|
|
|
switch (v4l2object->type) {
|
|
|
|
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
|
|
|
|
gst_v4l2_object_fill_format_list (v4l2object,
|
|
|
|
V4L2_BUF_TYPE_VIDEO_CAPTURE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
|
|
|
|
gst_v4l2_object_fill_format_list (v4l2object,
|
|
|
|
V4L2_BUF_TYPE_VIDEO_OUTPUT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
return v4l2object->formats;
|
|
|
|
}
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
static const GstV4L2FormatDesc *
|
|
|
|
gst_v4l2_object_get_desc_from_v4l2fourcc (guint32 fourcc)
|
2013-12-03 23:27:47 +00:00
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
gint i;
|
2013-12-03 23:27:47 +00:00
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
|
|
|
|
if (gst_v4l2_formats[i].v4l2_format == fourcc) {
|
|
|
|
return &gst_v4l2_formats[i];
|
|
|
|
}
|
2013-12-03 23:27:47 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstVideoFormat
|
|
|
|
gst_v4l2_object_v4l2fourcc_to_video_format (guint32 fourcc)
|
|
|
|
{
|
|
|
|
const GstV4L2FormatDesc *desc;
|
|
|
|
desc = gst_v4l2_object_get_desc_from_v4l2fourcc (fourcc);
|
|
|
|
if (!desc)
|
|
|
|
return GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
return desc->gst_format;
|
2013-12-03 23:27:47 +00:00
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
|
2016-01-19 20:14:59 +00:00
|
|
|
static gboolean
|
2016-01-21 22:41:55 +00:00
|
|
|
gst_v4l2_object_v4l2fourcc_is_rgb (guint32 fourcc)
|
2016-01-19 20:14:59 +00:00
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
const GstV4L2FormatDesc *desc;
|
|
|
|
const GstVideoFormatInfo *finfo;
|
2016-01-19 20:14:59 +00:00
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
desc = gst_v4l2_object_get_desc_from_v4l2fourcc (fourcc);
|
|
|
|
if (!desc || desc->gst_format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
finfo = gst_video_format_get_info (desc->gst_format);
|
|
|
|
if (finfo) {
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_RGB (finfo))
|
|
|
|
return TRUE;
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_GRAY (finfo))
|
|
|
|
return TRUE;
|
2016-01-19 20:14:59 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
if ((desc->flags & GST_V4L2_BAYER) == GST_V4L2_BAYER)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2016-01-19 20:14:59 +00:00
|
|
|
}
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
static const GstV4L2FormatDesc *
|
|
|
|
gst_v4l2_object_get_desc_from_video_format (GstVideoFormat format,
|
|
|
|
const GstV4L2FormatDesc ** fallback)
|
2023-02-13 08:49:40 +00:00
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
const GstV4L2FormatDesc *ret = NULL;
|
2023-02-13 08:49:40 +00:00
|
|
|
gint i;
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
if (fallback)
|
|
|
|
*fallback = NULL;
|
|
|
|
|
2023-02-13 08:49:40 +00:00
|
|
|
for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
|
2024-08-14 19:21:44 +00:00
|
|
|
if (gst_v4l2_formats[i].gst_format == format) {
|
|
|
|
if (!ret)
|
|
|
|
ret = &gst_v4l2_formats[i];
|
|
|
|
else if (fallback && !*fallback)
|
|
|
|
*fallback = &gst_v4l2_formats[i];
|
2023-02-13 08:49:40 +00:00
|
|
|
else
|
2024-08-14 19:21:44 +00:00
|
|
|
break;
|
2023-02-13 08:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_v4l2fourcc_is_codec (guint32 fourcc)
|
|
|
|
{
|
|
|
|
const GstV4L2FormatDesc *desc;
|
|
|
|
|
|
|
|
desc = gst_v4l2_object_get_desc_from_v4l2fourcc (fourcc);
|
|
|
|
if (!desc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (desc->flags & (GST_V4L2_CODEC | GST_V4L2_TRANSPORT))
|
|
|
|
return TRUE;
|
|
|
|
|
2023-02-13 08:49:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
static GstStructure *
|
|
|
|
gst_v4l2_object_v4l2fourcc_to_bare_struct (guint32 fourcc)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure = NULL;
|
2023-02-06 02:55:52 +00:00
|
|
|
const gchar *bayer_format = NULL;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
switch (fourcc) {
|
|
|
|
case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
|
2011-02-15 18:59:32 +00:00
|
|
|
case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
|
2023-01-31 15:02:03 +00:00
|
|
|
structure = gst_structure_new ("image/jpeg",
|
|
|
|
"parsed", G_TYPE_BOOLEAN, TRUE, NULL);
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
2013-12-12 19:22:26 +00:00
|
|
|
case V4L2_PIX_FMT_MPEG1:
|
|
|
|
structure = gst_structure_new ("video/mpeg",
|
2019-09-25 12:36:32 +00:00
|
|
|
"mpegversion", G_TYPE_INT, 1, NULL);
|
2013-12-12 19:22:26 +00:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_MPEG2:
|
|
|
|
structure = gst_structure_new ("video/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 2, NULL);
|
|
|
|
break;
|
2012-07-10 13:29:40 +00:00
|
|
|
case V4L2_PIX_FMT_MPEG4:
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_XVID:
|
2012-07-10 13:29:40 +00:00
|
|
|
structure = gst_structure_new ("video/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 4, "systemstream",
|
|
|
|
G_TYPE_BOOLEAN, FALSE, NULL);
|
|
|
|
break;
|
2018-09-10 19:20:52 +00:00
|
|
|
case V4L2_PIX_FMT_FWHT:
|
|
|
|
structure = gst_structure_new_empty ("video/x-fwht");
|
|
|
|
break;
|
2012-07-10 13:29:40 +00:00
|
|
|
case V4L2_PIX_FMT_H263:
|
|
|
|
structure = gst_structure_new ("video/x-h263",
|
|
|
|
"variant", G_TYPE_STRING, "itu", NULL);
|
|
|
|
break;
|
2012-04-16 22:08:21 +00:00
|
|
|
case V4L2_PIX_FMT_H264: /* H.264 */
|
2013-06-05 03:34:04 +00:00
|
|
|
structure = gst_structure_new ("video/x-h264",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream", "alignment",
|
|
|
|
G_TYPE_STRING, "au", NULL);
|
2012-04-16 22:08:21 +00:00
|
|
|
break;
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_H264_NO_SC:
|
|
|
|
structure = gst_structure_new ("video/x-h264",
|
|
|
|
"stream-format", G_TYPE_STRING, "avc", "alignment",
|
|
|
|
G_TYPE_STRING, "au", NULL);
|
|
|
|
break;
|
2018-09-13 03:16:32 +00:00
|
|
|
case V4L2_PIX_FMT_HEVC: /* H.265 */
|
|
|
|
structure = gst_structure_new ("video/x-h265",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream", "alignment",
|
|
|
|
G_TYPE_STRING, "au", NULL);
|
|
|
|
break;
|
2015-12-18 20:49:43 +00:00
|
|
|
case V4L2_PIX_FMT_VC1_ANNEX_G:
|
|
|
|
case V4L2_PIX_FMT_VC1_ANNEX_L:
|
|
|
|
structure = gst_structure_new ("video/x-wmv",
|
|
|
|
"wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
|
|
|
|
break;
|
2013-12-16 22:29:30 +00:00
|
|
|
case V4L2_PIX_FMT_VP8:
|
|
|
|
structure = gst_structure_new_empty ("video/x-vp8");
|
|
|
|
break;
|
2017-08-02 21:13:55 +00:00
|
|
|
case V4L2_PIX_FMT_VP9:
|
|
|
|
structure = gst_structure_new_empty ("video/x-vp9");
|
|
|
|
break;
|
2009-08-04 07:14:20 +00:00
|
|
|
case V4L2_PIX_FMT_DV:
|
|
|
|
structure =
|
|
|
|
gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_MPEG: /* MPEG */
|
2014-03-29 21:21:17 +00:00
|
|
|
structure = gst_structure_new ("video/mpegts",
|
|
|
|
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
2019-09-02 12:27:35 +00:00
|
|
|
case V4L2_PIX_FMT_WNVA: /* Winnov hw compress */
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SBGGR8:
|
2023-02-06 02:55:52 +00:00
|
|
|
bayer_format = "bggr";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SBGGR10:
|
|
|
|
bayer_format = "bggr10le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SBGGR12:
|
|
|
|
bayer_format = "bggr12le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SBGGR14:
|
|
|
|
bayer_format = "bggr14le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SBGGR16:
|
|
|
|
bayer_format = "bggr16le";
|
|
|
|
break;
|
2014-12-11 15:13:15 +00:00
|
|
|
case V4L2_PIX_FMT_SGBRG8:
|
2023-02-06 02:55:52 +00:00
|
|
|
bayer_format = "gbrgle";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGBRG10:
|
|
|
|
bayer_format = "gbrg10le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGBRG12:
|
|
|
|
bayer_format = "gbrg12le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGBRG14:
|
|
|
|
bayer_format = "gbrg14le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGBRG16:
|
|
|
|
bayer_format = "gbrg16le";
|
|
|
|
break;
|
2014-12-11 15:13:15 +00:00
|
|
|
case V4L2_PIX_FMT_SGRBG8:
|
2023-02-06 02:55:52 +00:00
|
|
|
bayer_format = "grbgle";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGRBG10:
|
|
|
|
bayer_format = "grbg10le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGRBG12:
|
|
|
|
bayer_format = "grbg12le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGRBG14:
|
|
|
|
bayer_format = "grbg14le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SGRBG16:
|
|
|
|
bayer_format = "grbg16le";
|
|
|
|
break;
|
2014-12-11 15:13:15 +00:00
|
|
|
case V4L2_PIX_FMT_SRGGB8:
|
2023-02-06 02:55:52 +00:00
|
|
|
bayer_format = "rggble";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SRGGB10:
|
|
|
|
bayer_format = "rggb10le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SRGGB12:
|
|
|
|
bayer_format = "rggb12le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SRGGB14:
|
|
|
|
bayer_format = "rggb14le";
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SRGGB16:
|
|
|
|
bayer_format = "rggb16le";
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_SN9C10X:
|
2011-10-29 07:09:45 +00:00
|
|
|
structure = gst_structure_new_empty ("video/x-sonix");
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_PWC1:
|
2011-10-29 07:09:45 +00:00
|
|
|
structure = gst_structure_new_empty ("video/x-pwc1");
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_PWC2:
|
2011-10-29 07:09:45 +00:00
|
|
|
structure = gst_structure_new_empty ("video/x-pwc2");
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-02-06 02:55:52 +00:00
|
|
|
if (bayer_format)
|
|
|
|
structure = gst_structure_new ("video/x-bayer", "format", G_TYPE_STRING,
|
|
|
|
bayer_format, NULL);
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
if (!structure) {
|
|
|
|
GstVideoFormat format;
|
|
|
|
format = gst_v4l2_object_v4l2fourcc_to_video_format (fourcc);
|
|
|
|
|
|
|
|
if (format <= GST_VIDEO_FORMAT_ENCODED)
|
|
|
|
GST_DEBUG ("Unsupported V4L2 fourcc 0x%08x %" GST_FOURCC_FORMAT,
|
|
|
|
fourcc, GST_FOURCC_ARGS (fourcc));
|
|
|
|
else
|
|
|
|
structure = gst_structure_new ("video/x-raw",
|
|
|
|
"format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
|
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
return structure;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:38:30 +00:00
|
|
|
GstStructure *
|
|
|
|
gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
|
|
|
|
{
|
|
|
|
GstStructure *template;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
template = gst_v4l2_object_v4l2fourcc_to_bare_struct (fourcc);
|
|
|
|
|
|
|
|
if (template == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
|
2024-08-14 19:21:44 +00:00
|
|
|
if (gst_v4l2_formats[i].v4l2_format != fourcc)
|
2014-05-03 01:38:30 +00:00
|
|
|
continue;
|
|
|
|
|
2024-08-14 13:52:54 +00:00
|
|
|
if (gst_v4l2_formats[i].flags & GST_V4L2_RESOLUTION_AND_RATE) {
|
2014-05-03 01:38:30 +00:00
|
|
|
gst_structure_set (template,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
|
2015-07-24 13:10:05 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
2014-05-03 01:38:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
|
2023-04-20 21:31:32 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_is_raw (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&v4l2object->info) != GST_VIDEO_FORMAT_ENCODED)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
|
2024-08-14 19:21:44 +00:00
|
|
|
if (gst_v4l2_formats[i].v4l2_format == GST_V4L2_PIXELFORMAT (v4l2object)) {
|
2023-04-20 21:31:32 +00:00
|
|
|
return !!(gst_v4l2_formats[i].flags & GST_V4L2_RAW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
/* Add an 'alternate' variant of the caps with the feature */
|
|
|
|
static void
|
|
|
|
add_alternate_variant (GstV4l2Object * v4l2object, GstCaps * caps,
|
|
|
|
GstStructure * structure)
|
|
|
|
{
|
|
|
|
GstStructure *alt_s;
|
|
|
|
|
|
|
|
if (v4l2object && v4l2object->never_interlaced)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!gst_structure_has_name (structure, "video/x-raw"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
alt_s = gst_structure_copy (structure);
|
|
|
|
gst_structure_set (alt_s, "interlace-mode", G_TYPE_STRING, "alternate", NULL);
|
|
|
|
|
|
|
|
gst_caps_append_structure_full (caps, alt_s,
|
|
|
|
gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL));
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2024-07-29 01:07:40 +00:00
|
|
|
static void
|
|
|
|
add_non_colorimetry_caps (GstV4l2Object * v4l2object, GstCaps * caps)
|
|
|
|
{
|
|
|
|
gint caps_size;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
caps_size = gst_caps_get_size (caps);
|
|
|
|
for (i = 0; i < caps_size; i++) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, i);
|
|
|
|
GstCapsFeatures *features = gst_caps_get_features (caps, i);
|
|
|
|
|
|
|
|
if (gst_structure_has_name (structure, "video/x-raw")
|
|
|
|
&& gst_structure_has_field (structure, "colorimetry")) {
|
|
|
|
GstStructure *alt_s = gst_structure_copy (structure);
|
|
|
|
gst_structure_remove_field (alt_s, "colorimetry");
|
|
|
|
if (gst_caps_features_contains (features,
|
|
|
|
GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY))
|
|
|
|
gst_caps_append_structure (caps, alt_s);
|
|
|
|
else
|
|
|
|
gst_caps_append_structure_full (caps, alt_s,
|
|
|
|
gst_caps_features_copy (features));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:44:51 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_v4l2_object_get_caps_helper (GstV4L2FormatFlags flags)
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
2020-11-12 01:32:30 +00:00
|
|
|
GstCaps *caps, *caps_interlaced;
|
2013-12-06 19:44:51 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty ();
|
2020-11-12 01:32:30 +00:00
|
|
|
caps_interlaced = gst_caps_new_empty ();
|
2013-12-06 19:44:51 +00:00
|
|
|
for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
|
2024-08-14 19:21:44 +00:00
|
|
|
guint32 fourcc = gst_v4l2_formats[i].v4l2_format;
|
2013-12-06 19:44:51 +00:00
|
|
|
|
|
|
|
if ((gst_v4l2_formats[i].flags & flags) == 0)
|
|
|
|
continue;
|
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
structure = gst_v4l2_object_v4l2fourcc_to_bare_struct (fourcc);
|
2014-03-19 21:00:56 +00:00
|
|
|
|
2013-12-06 19:44:51 +00:00
|
|
|
if (structure) {
|
2014-03-19 21:00:56 +00:00
|
|
|
GstStructure *alt_s = NULL;
|
|
|
|
|
2024-08-14 13:52:54 +00:00
|
|
|
if (gst_v4l2_formats[i].flags & GST_V4L2_RESOLUTION_AND_RATE) {
|
2013-12-06 19:44:51 +00:00
|
|
|
gst_structure_set (structure,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
|
2015-07-24 13:10:05 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
2013-12-06 19:44:51 +00:00
|
|
|
}
|
2014-03-19 21:00:56 +00:00
|
|
|
|
2024-08-14 19:21:44 +00:00
|
|
|
switch (fourcc) {
|
2014-03-19 21:00:56 +00:00
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
alt_s = gst_structure_copy (structure);
|
|
|
|
gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
alt_s = gst_structure_copy (structure);
|
|
|
|
gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:44:51 +00:00
|
|
|
gst_caps_append_structure (caps, structure);
|
2014-03-19 21:00:56 +00:00
|
|
|
|
2020-11-12 01:32:30 +00:00
|
|
|
if (alt_s) {
|
2014-03-19 21:00:56 +00:00
|
|
|
gst_caps_append_structure (caps, alt_s);
|
2020-11-12 01:32:30 +00:00
|
|
|
add_alternate_variant (NULL, caps_interlaced, alt_s);
|
|
|
|
}
|
2018-08-08 07:27:19 +00:00
|
|
|
|
2020-11-12 01:32:30 +00:00
|
|
|
add_alternate_variant (NULL, caps_interlaced, structure);
|
2013-12-06 19:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 01:32:30 +00:00
|
|
|
caps = gst_caps_simplify (caps);
|
|
|
|
caps_interlaced = gst_caps_simplify (caps_interlaced);
|
|
|
|
|
|
|
|
return gst_caps_merge (caps, caps_interlaced);
|
2013-12-06 19:44:51 +00:00
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_v4l2_object_get_all_caps (void)
|
|
|
|
{
|
|
|
|
static GstCaps *caps = NULL;
|
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
if (g_once_init_enter (&caps)) {
|
|
|
|
GstCaps *all_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_ALL);
|
|
|
|
GST_MINI_OBJECT_FLAG_SET (all_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
|
|
|
g_once_init_leave (&caps, all_caps);
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
return caps;
|
2013-12-06 19:44:51 +00:00
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2013-12-06 19:44:51 +00:00
|
|
|
GstCaps *
|
|
|
|
gst_v4l2_object_get_raw_caps (void)
|
|
|
|
{
|
|
|
|
static GstCaps *caps = NULL;
|
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
if (g_once_init_enter (&caps)) {
|
|
|
|
GstCaps *raw_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_RAW);
|
|
|
|
GST_MINI_OBJECT_FLAG_SET (raw_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
|
|
|
g_once_init_leave (&caps, raw_caps);
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
return caps;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 19:44:51 +00:00
|
|
|
GstCaps *
|
|
|
|
gst_v4l2_object_get_codec_caps (void)
|
|
|
|
{
|
|
|
|
static GstCaps *caps = NULL;
|
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
if (g_once_init_enter (&caps)) {
|
|
|
|
GstCaps *codec_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_CODEC);
|
|
|
|
GST_MINI_OBJECT_FLAG_SET (codec_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
|
|
|
g_once_init_leave (&caps, codec_caps);
|
|
|
|
}
|
2013-12-06 19:44:51 +00:00
|
|
|
|
2017-02-10 13:32:57 +00:00
|
|
|
return caps;
|
2013-12-06 19:44:51 +00:00
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
/* collect data for the given caps
|
|
|
|
* @caps: given input caps
|
|
|
|
* @format: location for the v4l format
|
|
|
|
* @w/@h: location for width and height
|
|
|
|
* @fps_n/@fps_d: location for framerate
|
|
|
|
* @size: location for expected size of the frame or 0 if unknown
|
|
|
|
*/
|
2011-07-12 18:03:32 +00:00
|
|
|
static gboolean
|
2009-08-04 07:14:20 +00:00
|
|
|
gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
|
2011-07-13 11:00:42 +00:00
|
|
|
struct v4l2_fmtdesc **format, GstVideoInfo * info)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
2014-03-07 21:39:29 +00:00
|
|
|
guint32 fourcc = 0, fourcc_nc = 0;
|
2009-08-04 07:14:20 +00:00
|
|
|
const gchar *mimetype;
|
2014-03-07 21:39:29 +00:00
|
|
|
struct v4l2_fmtdesc *fmt = NULL;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2009-09-07 16:28:51 +00:00
|
|
|
mimetype = gst_structure_get_name (structure);
|
|
|
|
|
2013-05-03 10:46:37 +00:00
|
|
|
if (!gst_video_info_from_caps (info, caps))
|
|
|
|
goto invalid_format;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2013-05-03 10:46:37 +00:00
|
|
|
if (g_str_equal (mimetype, "video/x-raw")) {
|
2024-08-14 19:21:44 +00:00
|
|
|
const GstV4L2FormatDesc *desc, *fallback_desc;
|
|
|
|
GstVideoFormat format = GST_VIDEO_INFO_FORMAT (info);
|
|
|
|
desc = gst_v4l2_object_get_desc_from_video_format (format, &fallback_desc);
|
|
|
|
if (desc)
|
|
|
|
fourcc_nc = desc->v4l2_format;
|
|
|
|
if (fallback_desc)
|
|
|
|
fourcc = fallback_desc->v4l2_format;
|
2024-08-14 19:26:58 +00:00
|
|
|
} else if (g_str_equal (mimetype, "video/mpegts")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_MPEG;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-dv")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_DV;
|
|
|
|
} else if (g_str_equal (mimetype, "image/jpeg")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_JPEG;
|
|
|
|
} else if (g_str_equal (mimetype, "video/mpeg")) {
|
|
|
|
gint version;
|
|
|
|
if (gst_structure_get_int (structure, "mpegversion", &version)) {
|
|
|
|
switch (version) {
|
|
|
|
case 1:
|
|
|
|
fourcc = V4L2_PIX_FMT_MPEG1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fourcc = V4L2_PIX_FMT_MPEG2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
fourcc = V4L2_PIX_FMT_MPEG4;
|
|
|
|
fourcc_nc = V4L2_PIX_FMT_XVID;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-03-08 12:03:55 +00:00
|
|
|
}
|
2011-07-13 11:00:42 +00:00
|
|
|
}
|
2024-08-14 19:26:58 +00:00
|
|
|
} else if (g_str_equal (mimetype, "video/x-fwht")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_FWHT;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-h263")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_H263;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-h264")) {
|
|
|
|
const gchar *stream_format =
|
|
|
|
gst_structure_get_string (structure, "stream-format");
|
|
|
|
if (g_str_equal (stream_format, "avc"))
|
|
|
|
fourcc = V4L2_PIX_FMT_H264_NO_SC;
|
|
|
|
else
|
|
|
|
fourcc = V4L2_PIX_FMT_H264;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-h265")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_HEVC;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-vp8")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_VP8;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-vp9")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_VP9;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-bayer")) {
|
|
|
|
const gchar *format = gst_structure_get_string (structure, "format");
|
|
|
|
if (format) {
|
|
|
|
if (!g_ascii_strcasecmp (format, "bggr"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SBGGR8;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "gbrg"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGBRG8;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "grbg"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGRBG8;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "rggb"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SRGGB8;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "bggr10le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SBGGR10;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "gbrg10le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGBRG10;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "grbg10le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGRBG10;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "rggb10le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SRGGB10;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "bggr12le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SBGGR12;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "gbrg12le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGBRG12;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "grbg12le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGRBG12;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "rggb12le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SRGGB12;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "bggr14le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SBGGR14;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "gbrg14le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGBRG14;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "grbg14le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGRBG14;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "rggb14le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SRGGB14;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "bggr16le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SBGGR16;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "gbrg16le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGBRG16;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "grbg16le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SGRBG16;
|
|
|
|
else if (!g_ascii_strcasecmp (format, "rggb16le"))
|
|
|
|
fourcc = V4L2_PIX_FMT_SRGGB16;
|
|
|
|
}
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-sonix")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_SN9C10X;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-pwc1")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_PWC1;
|
|
|
|
} else if (g_str_equal (mimetype, "video/x-pwc2")) {
|
|
|
|
fourcc = V4L2_PIX_FMT_PWC2;
|
2011-07-13 11:00:42 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 21:39:29 +00:00
|
|
|
/* Prefer the non-contiguous if supported */
|
|
|
|
v4l2object->prefered_non_contiguous = TRUE;
|
|
|
|
|
|
|
|
if (fourcc_nc)
|
|
|
|
fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc_nc);
|
|
|
|
else if (fourcc == 0)
|
|
|
|
goto unhandled_format;
|
2013-12-04 20:09:10 +00:00
|
|
|
|
2014-03-07 21:39:29 +00:00
|
|
|
if (fmt == NULL) {
|
|
|
|
fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
|
|
|
|
v4l2object->prefered_non_contiguous = FALSE;
|
2013-12-04 20:09:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 17:20:43 +00:00
|
|
|
if (fmt == NULL)
|
|
|
|
goto unsupported_format;
|
|
|
|
|
|
|
|
*format = fmt;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2011-07-08 12:34:40 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
invalid_format:
|
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Invalid format %" GST_PTR_FORMAT, caps);
|
2011-07-08 12:34:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unhandled_format:
|
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Unhandled format %" GST_PTR_FORMAT, caps);
|
2011-07-08 12:34:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-19 17:20:43 +00:00
|
|
|
unsupported_format:
|
|
|
|
{
|
2024-08-14 19:21:44 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Unsupported format: %" GST_PTR_FORMAT, caps);
|
2011-07-19 17:20:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
2010-11-04 17:36:09 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
|
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
|
|
|
guint32 pixelformat, gint * width, gint * height);
|
2010-11-04 17:36:09 +00:00
|
|
|
|
2013-06-04 06:26:33 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_add_aspect_ratio (GstV4l2Object * v4l2object, GstStructure * s)
|
|
|
|
{
|
2017-07-14 20:21:38 +00:00
|
|
|
if (v4l2object->keep_aspect && v4l2object->par)
|
|
|
|
gst_structure_set_value (s, "pixel-aspect-ratio", v4l2object->par);
|
2013-06-04 06:26:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 16:20:14 +00:00
|
|
|
/* returns TRUE if the value was changed in place, otherwise FALSE */
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2src_value_simplify (GValue * val)
|
|
|
|
{
|
|
|
|
/* simplify list of one value to one value */
|
|
|
|
if (GST_VALUE_HOLDS_LIST (val) && gst_value_list_get_size (val) == 1) {
|
|
|
|
const GValue *list_val;
|
|
|
|
GValue new_val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
list_val = gst_value_list_get_value (val, 0);
|
|
|
|
g_value_init (&new_val, G_VALUE_TYPE (list_val));
|
|
|
|
g_value_copy (list_val, &new_val);
|
|
|
|
g_value_unset (val);
|
|
|
|
*val = new_val;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
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
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_get_interlace_mode (enum v4l2_field field,
|
|
|
|
GstVideoInterlaceMode * interlace_mode)
|
|
|
|
{
|
|
|
|
switch (field) {
|
|
|
|
case V4L2_FIELD_ANY:
|
|
|
|
GST_ERROR
|
|
|
|
("Driver bug detected - check driver with v4l2-compliance from http://git.linuxtv.org/v4l-utils.git\n");
|
2021-04-22 07:01:32 +00:00
|
|
|
return FALSE;
|
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
|
|
|
case V4L2_FIELD_NONE:
|
|
|
|
*interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
|
|
|
return TRUE;
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
case V4L2_FIELD_INTERLACED_TB:
|
|
|
|
case V4L2_FIELD_INTERLACED_BT:
|
|
|
|
*interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
|
|
|
return TRUE;
|
2018-08-08 07:27:19 +00:00
|
|
|
case V4L2_FIELD_ALTERNATE:
|
|
|
|
*interlace_mode = GST_VIDEO_INTERLACE_MODE_ALTERNATE;
|
|
|
|
return TRUE;
|
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
|
|
|
default:
|
|
|
|
GST_ERROR ("Unknown enum v4l2_field %d", field);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 14:29:24 +00:00
|
|
|
static gboolean
|
2020-12-15 02:41:40 +00:00
|
|
|
gst_v4l2_object_get_colorspace (GstV4l2Object * v4l2object,
|
|
|
|
struct v4l2_format *fmt, GstVideoColorimetry * cinfo)
|
2015-01-19 14:29:24 +00:00
|
|
|
{
|
2023-02-13 08:49:40 +00:00
|
|
|
gboolean is_rgb = FALSE;
|
2016-05-18 08:17:12 +00:00
|
|
|
enum v4l2_colorspace colorspace;
|
|
|
|
enum v4l2_quantization range;
|
|
|
|
enum v4l2_ycbcr_encoding matrix;
|
|
|
|
enum v4l2_xfer_func transfer;
|
2023-02-13 08:49:40 +00:00
|
|
|
guint32 pixelformat;
|
2015-06-08 21:24:38 +00:00
|
|
|
gboolean ret = TRUE;
|
2015-01-19 14:29:24 +00:00
|
|
|
|
2016-05-18 08:17:12 +00:00
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (fmt->type)) {
|
|
|
|
colorspace = fmt->fmt.pix_mp.colorspace;
|
|
|
|
range = fmt->fmt.pix_mp.quantization;
|
|
|
|
matrix = fmt->fmt.pix_mp.ycbcr_enc;
|
|
|
|
transfer = fmt->fmt.pix_mp.xfer_func;
|
2023-02-13 08:49:40 +00:00
|
|
|
pixelformat = fmt->fmt.pix_mp.pixelformat;
|
2016-05-18 08:17:12 +00:00
|
|
|
} else {
|
|
|
|
colorspace = fmt->fmt.pix.colorspace;
|
|
|
|
range = fmt->fmt.pix.quantization;
|
|
|
|
matrix = fmt->fmt.pix.ycbcr_enc;
|
|
|
|
transfer = fmt->fmt.pix.xfer_func;
|
2023-02-13 08:49:40 +00:00
|
|
|
pixelformat = fmt->fmt.pix.pixelformat;
|
2016-05-18 08:17:12 +00:00
|
|
|
}
|
|
|
|
|
2023-02-13 08:49:40 +00:00
|
|
|
/* Detect that we are dealing with RGB, this can be that the pixelformat is
|
|
|
|
* an RGB format, or we have an encoded format for which RGB color matrix
|
|
|
|
* was set in set_format. */
|
|
|
|
if (gst_v4l2_object_v4l2fourcc_is_rgb (pixelformat) ||
|
|
|
|
(v4l2object->matrix == GST_VIDEO_COLOR_MATRIX_RGB &&
|
|
|
|
gst_v4l2_object_v4l2fourcc_is_codec (pixelformat)))
|
|
|
|
is_rgb = TRUE;
|
|
|
|
else
|
|
|
|
is_rgb = FALSE;
|
|
|
|
|
2015-06-08 21:24:38 +00:00
|
|
|
/* First step, set the defaults for each primaries */
|
2015-01-19 14:29:24 +00:00
|
|
|
switch (colorspace) {
|
|
|
|
case V4L2_COLORSPACE_SMPTE170M:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
2021-01-18 14:54:43 +00:00
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT601;
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
|
2015-01-19 14:29:24 +00:00
|
|
|
break;
|
|
|
|
case V4L2_COLORSPACE_REC709:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
|
2015-01-19 14:29:24 +00:00
|
|
|
break;
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_COLORSPACE_SRGB:
|
2024-07-29 18:39:06 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
|
|
|
|
break;
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_COLORSPACE_JPEG:
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
|
|
|
|
break;
|
2019-03-05 19:53:47 +00:00
|
|
|
case V4L2_COLORSPACE_OPRGB:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_ADOBERGB;
|
2015-06-08 21:24:38 +00:00
|
|
|
break;
|
|
|
|
case V4L2_COLORSPACE_BT2020:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
|
2017-07-18 15:28:37 +00:00
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020;
|
2015-06-08 21:24:38 +00:00
|
|
|
break;
|
2015-01-19 14:29:24 +00:00
|
|
|
case V4L2_COLORSPACE_SMPTE240M:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
|
2015-01-19 14:29:24 +00:00
|
|
|
break;
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_COLORSPACE_470_SYSTEM_M:
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470M;
|
|
|
|
break;
|
|
|
|
case V4L2_COLORSPACE_470_SYSTEM_BG:
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470BG;
|
|
|
|
break;
|
|
|
|
case V4L2_COLORSPACE_RAW:
|
|
|
|
/* Explicitly unknown */
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
|
|
|
|
cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
|
2015-01-19 14:29:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG ("Unknown enum v4l2_colorspace %d", colorspace);
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-08 21:24:38 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Second step, apply any custom variation */
|
|
|
|
switch (range) {
|
|
|
|
case V4L2_QUANTIZATION_FULL_RANGE:
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
|
|
|
|
break;
|
|
|
|
case V4L2_QUANTIZATION_LIM_RANGE:
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
|
|
|
break;
|
|
|
|
case V4L2_QUANTIZATION_DEFAULT:
|
2016-03-04 14:09:45 +00:00
|
|
|
/* replicated V4L2_MAP_QUANTIZATION_DEFAULT macro behavior */
|
2024-07-29 15:37:29 +00:00
|
|
|
if (is_rgb || colorspace == V4L2_COLORSPACE_JPEG)
|
2016-03-04 14:09:45 +00:00
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
|
|
|
|
else
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
|
2015-06-08 21:24:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("Unknown enum v4l2_quantization value %d", range);
|
|
|
|
cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (matrix) {
|
|
|
|
case V4L2_YCBCR_ENC_XV601:
|
|
|
|
case V4L2_YCBCR_ENC_SYCC:
|
|
|
|
GST_FIXME ("XV601 and SYCC not defined, assuming 601");
|
2015-06-29 15:05:44 +00:00
|
|
|
/* fallthrough */
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_YCBCR_ENC_601:
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
|
|
|
|
break;
|
|
|
|
case V4L2_YCBCR_ENC_XV709:
|
|
|
|
GST_FIXME ("XV709 not defined, assuming 709");
|
2015-06-29 15:05:44 +00:00
|
|
|
/* fallthrough */
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_YCBCR_ENC_709:
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
|
|
|
|
break;
|
|
|
|
case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
|
2017-09-05 14:30:40 +00:00
|
|
|
GST_FIXME ("BT2020 with constant luma is not defined, assuming BT2020");
|
2015-06-29 15:05:44 +00:00
|
|
|
/* fallthrough */
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_YCBCR_ENC_BT2020:
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
|
|
|
|
break;
|
2015-06-08 23:10:34 +00:00
|
|
|
case V4L2_YCBCR_ENC_SMPTE240M:
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
|
|
|
|
break;
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_YCBCR_ENC_DEFAULT:
|
|
|
|
/* nothing, just use defaults for colorspace */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("Unknown enum v4l2_ycbcr_encoding value %d", matrix);
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-18 08:17:12 +00:00
|
|
|
/* Set identity matrix for R'G'B' formats to avoid creating
|
|
|
|
* confusion. This though is cosmetic as it's now properly ignored by
|
|
|
|
* the video info API and videoconvert. */
|
|
|
|
if (is_rgb)
|
|
|
|
cinfo->matrix = GST_VIDEO_COLOR_MATRIX_RGB;
|
|
|
|
|
2015-06-08 21:24:38 +00:00
|
|
|
switch (transfer) {
|
|
|
|
case V4L2_XFER_FUNC_709:
|
2018-04-09 00:42:16 +00:00
|
|
|
if (colorspace == V4L2_COLORSPACE_BT2020 && fmt->fmt.pix.height >= 2160)
|
2017-07-18 15:28:37 +00:00
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
|
2021-01-18 14:54:43 +00:00
|
|
|
else if (colorspace == V4L2_COLORSPACE_SMPTE170M)
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT601;
|
2017-07-18 15:28:37 +00:00
|
|
|
else
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
|
2020-12-15 02:41:40 +00:00
|
|
|
|
|
|
|
if (v4l2object->transfer)
|
|
|
|
cinfo->transfer = v4l2object->transfer;
|
2015-06-08 21:24:38 +00:00
|
|
|
break;
|
|
|
|
case V4L2_XFER_FUNC_SRGB:
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
|
|
|
|
break;
|
2019-03-05 19:53:47 +00:00
|
|
|
case V4L2_XFER_FUNC_OPRGB:
|
2016-01-21 09:49:44 +00:00
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
|
2015-06-08 21:24:38 +00:00
|
|
|
break;
|
|
|
|
case V4L2_XFER_FUNC_SMPTE240M:
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
|
|
|
|
break;
|
|
|
|
case V4L2_XFER_FUNC_NONE:
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_GAMMA10;
|
|
|
|
break;
|
2021-03-19 02:52:26 +00:00
|
|
|
case V4L2_XFER_FUNC_SMPTE2084:
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE2084;
|
|
|
|
break;
|
2015-06-08 21:24:38 +00:00
|
|
|
case V4L2_XFER_FUNC_DEFAULT:
|
|
|
|
/* nothing, just use defaults for colorspace */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("Unknown enum v4l2_xfer_func value %d", transfer);
|
|
|
|
cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2015-01-19 14:29:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-27 02:43:21 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_get_streamparm (GstV4l2Object * v4l2object, GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
struct v4l2_streamparm streamparm;
|
|
|
|
memset (&streamparm, 0x00, sizeof (struct v4l2_streamparm));
|
|
|
|
streamparm.type = v4l2object->type;
|
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_PARM, &streamparm) < 0) {
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj, "VIDIOC_G_PARM failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-08-09 02:46:30 +00:00
|
|
|
if ((streamparm.parm.capture.timeperframe.numerator != 0)
|
|
|
|
&& (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|
|
|
|
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
|
2021-07-27 02:43:21 +00:00
|
|
|
GST_VIDEO_INFO_FPS_N (info) =
|
|
|
|
streamparm.parm.capture.timeperframe.denominator;
|
|
|
|
GST_VIDEO_INFO_FPS_D (info) =
|
|
|
|
streamparm.parm.capture.timeperframe.numerator;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int
|
|
|
|
gst_v4l2_object_try_fmt (GstV4l2Object * v4l2object,
|
|
|
|
struct v4l2_format *try_fmt)
|
|
|
|
{
|
|
|
|
int fd = v4l2object->video_fd;
|
|
|
|
struct v4l2_format fmt;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
memcpy (&fmt, try_fmt, sizeof (fmt));
|
2017-07-24 18:19:02 +00:00
|
|
|
r = v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &fmt);
|
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
|
|
|
|
|
|
|
if (r < 0 && errno == ENOTTY) {
|
|
|
|
/* The driver might not implement TRY_FMT, in which case we will try
|
|
|
|
S_FMT to probe */
|
|
|
|
if (GST_V4L2_IS_ACTIVE (v4l2object))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
memcpy (&fmt, try_fmt, sizeof (fmt));
|
2017-07-24 18:19:02 +00:00
|
|
|
r = v4l2object->ioctl (fd, VIDIOC_S_FMT, &fmt);
|
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
|
|
|
}
|
|
|
|
memcpy (try_fmt, &fmt, sizeof (fmt));
|
2017-07-20 02:05:49 +00:00
|
|
|
|
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
|
|
|
return r;
|
|
|
|
|
|
|
|
error:
|
|
|
|
memcpy (try_fmt, &fmt, sizeof (fmt));
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
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
|
|
|
"Unable to try format: %s", g_strerror (errno));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4l2_object_add_interlace_mode (GstV4l2Object * v4l2object,
|
|
|
|
GstStructure * s, guint32 width, guint32 height, guint32 pixelformat)
|
|
|
|
{
|
|
|
|
struct v4l2_format fmt;
|
|
|
|
GValue interlace_formats = { 0, };
|
2018-08-08 07:27:19 +00:00
|
|
|
enum v4l2_field formats[] = { V4L2_FIELD_NONE,
|
|
|
|
V4L2_FIELD_INTERLACED, V4L2_FIELD_ALTERNATE
|
|
|
|
};
|
2018-08-08 07:27:09 +00:00
|
|
|
gsize i;
|
2015-04-22 16:05:24 +00:00
|
|
|
GstVideoInterlaceMode interlace_mode, prev = -1;
|
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
|
|
|
|
|
|
|
if (!g_str_equal (gst_structure_get_name (s), "video/x-raw"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (v4l2object->never_interlaced) {
|
|
|
|
gst_structure_set (s, "interlace-mode", G_TYPE_STRING, "progressive", NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_init (&interlace_formats, GST_TYPE_LIST);
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
/* Try thrice - once for NONE, once for INTERLACED and once for ALTERNATE. */
|
2018-08-08 07:27:09 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
|
|
|
|
memset (&fmt, 0, sizeof (fmt));
|
|
|
|
fmt.type = v4l2object->type;
|
|
|
|
fmt.fmt.pix.width = width;
|
|
|
|
fmt.fmt.pix.height = height;
|
|
|
|
fmt.fmt.pix.pixelformat = pixelformat;
|
|
|
|
fmt.fmt.pix.field = formats[i];
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
if (fmt.fmt.pix.field == V4L2_FIELD_ALTERNATE)
|
|
|
|
fmt.fmt.pix.height /= 2;
|
|
|
|
|
|
|
|
/* if skip_try_fmt_probes is set it's up to the caller to filter out the
|
|
|
|
* formats from the formats requested by peer.
|
|
|
|
* For this negotiation to work with 'alternate' we need the caps to contain
|
|
|
|
* the feature so we have an intersection with downstream caps.
|
|
|
|
*/
|
|
|
|
if (!v4l2object->skip_try_fmt_probes
|
|
|
|
&& gst_v4l2_object_try_fmt (v4l2object, &fmt) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)
|
2018-08-08 07:27:09 +00:00
|
|
|
&& prev != interlace_mode) {
|
|
|
|
GValue interlace_enum = { 0, };
|
|
|
|
const gchar *mode_string;
|
|
|
|
g_value_init (&interlace_enum, G_TYPE_STRING);
|
|
|
|
mode_string = gst_video_interlace_mode_to_string (interlace_mode);
|
|
|
|
g_value_set_string (&interlace_enum, mode_string);
|
|
|
|
gst_value_list_append_and_take_value (&interlace_formats,
|
|
|
|
&interlace_enum);
|
|
|
|
prev = interlace_mode;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-12-14 18:15:03 +00:00
|
|
|
if (gst_v4l2src_value_simplify (&interlace_formats)
|
|
|
|
|| gst_value_list_get_size (&interlace_formats) > 0)
|
2016-12-06 12:12:31 +00:00
|
|
|
gst_structure_take_value (s, "interlace-mode", &interlace_formats);
|
|
|
|
else
|
2023-04-15 03:38:34 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Failed to determine interlace mode");
|
2016-12-06 12:12:31 +00:00
|
|
|
|
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
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-01 11:41:23 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_fill_colorimetry_list (GValue * list,
|
|
|
|
GstVideoColorimetry * cinfo)
|
|
|
|
{
|
|
|
|
GValue colorimetry = G_VALUE_INIT;
|
|
|
|
guint size;
|
|
|
|
guint i;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
g_value_init (&colorimetry, G_TYPE_STRING);
|
|
|
|
g_value_take_string (&colorimetry, gst_video_colorimetry_to_string (cinfo));
|
|
|
|
|
|
|
|
/* only insert if no duplicate */
|
|
|
|
size = gst_value_list_get_size (list);
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
const GValue *tmp;
|
|
|
|
|
|
|
|
tmp = gst_value_list_get_value (list, i);
|
|
|
|
if (gst_value_compare (&colorimetry, tmp) == GST_VALUE_EQUAL) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
gst_value_list_append_and_take_value (list, &colorimetry);
|
2016-04-12 09:56:08 +00:00
|
|
|
else
|
|
|
|
g_value_unset (&colorimetry);
|
2015-10-01 11:41:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 14:29:24 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_add_colorspace (GstV4l2Object * v4l2object, GstStructure * s,
|
|
|
|
guint32 width, guint32 height, guint32 pixelformat)
|
|
|
|
{
|
|
|
|
struct v4l2_format fmt;
|
2015-10-01 11:41:23 +00:00
|
|
|
GValue list = G_VALUE_INIT;
|
2015-01-19 14:29:24 +00:00
|
|
|
GstVideoColorimetry cinfo;
|
2015-10-01 11:41:23 +00:00
|
|
|
enum v4l2_colorspace req_cspace;
|
2015-01-19 14:29:24 +00:00
|
|
|
|
|
|
|
memset (&fmt, 0, sizeof (fmt));
|
|
|
|
fmt.type = v4l2object->type;
|
|
|
|
fmt.fmt.pix.width = width;
|
|
|
|
fmt.fmt.pix.height = height;
|
|
|
|
fmt.fmt.pix.pixelformat = pixelformat;
|
|
|
|
|
2015-10-01 11:41:23 +00:00
|
|
|
g_value_init (&list, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
/* step 1: get device default colorspace and insert it first as
|
|
|
|
* it should be the preferred one */
|
2015-01-19 14:29:24 +00:00
|
|
|
if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
|
2020-12-15 02:41:40 +00:00
|
|
|
if (gst_v4l2_object_get_colorspace (v4l2object, &fmt, &cinfo))
|
2015-10-01 11:41:23 +00:00
|
|
|
gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
|
2015-01-19 14:29:24 +00:00
|
|
|
}
|
2015-10-01 11:41:23 +00:00
|
|
|
|
|
|
|
/* step 2: probe all colorspace other than default
|
|
|
|
* We don't probe all colorspace, range, matrix and transfer combination to
|
|
|
|
* avoid ioctl flooding which could greatly increase initialization time
|
|
|
|
* with low-speed devices (UVC...) */
|
|
|
|
for (req_cspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
req_cspace <= V4L2_COLORSPACE_RAW; req_cspace++) {
|
|
|
|
/* V4L2_COLORSPACE_BT878 is deprecated and shall not be used, so skip */
|
|
|
|
if (req_cspace == V4L2_COLORSPACE_BT878)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
|
|
|
|
fmt.fmt.pix_mp.colorspace = req_cspace;
|
|
|
|
else
|
|
|
|
fmt.fmt.pix.colorspace = req_cspace;
|
|
|
|
|
|
|
|
if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
|
|
|
|
enum v4l2_colorspace colorspace;
|
|
|
|
|
2016-05-18 08:17:12 +00:00
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
|
2015-10-01 11:41:23 +00:00
|
|
|
colorspace = fmt.fmt.pix_mp.colorspace;
|
2016-05-18 08:17:12 +00:00
|
|
|
else
|
2015-10-01 11:41:23 +00:00
|
|
|
colorspace = fmt.fmt.pix.colorspace;
|
|
|
|
|
|
|
|
if (colorspace == req_cspace) {
|
2020-12-15 02:41:40 +00:00
|
|
|
if (gst_v4l2_object_get_colorspace (v4l2object, &fmt, &cinfo))
|
2015-10-01 11:41:23 +00:00
|
|
|
gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
|
2022-07-25 03:44:10 +00:00
|
|
|
if (colorspace == V4L2_COLORSPACE_REC709) {
|
|
|
|
/* support for full-range variants of colorspaces V4L2_COLORSPACE_REC709
|
|
|
|
* (such as Apple's full-range bt709 variant 1:3:5:1) */
|
|
|
|
struct v4l2_format alt_fmt;
|
|
|
|
memcpy (&alt_fmt, &fmt, sizeof (alt_fmt));
|
|
|
|
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
|
|
|
|
alt_fmt.fmt.pix_mp.quantization = V4L2_QUANTIZATION_FULL_RANGE;
|
|
|
|
else
|
|
|
|
alt_fmt.fmt.pix.quantization = V4L2_QUANTIZATION_FULL_RANGE;
|
|
|
|
|
|
|
|
if (gst_v4l2_object_get_colorspace (v4l2object, &alt_fmt, &cinfo))
|
|
|
|
gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
|
|
|
|
}
|
2015-10-01 11:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_value_list_get_size (&list) > 0)
|
|
|
|
gst_structure_take_value (s, "colorimetry", &list);
|
2016-04-12 09:56:08 +00:00
|
|
|
else
|
|
|
|
g_value_unset (&list);
|
2015-10-01 11:41:23 +00:00
|
|
|
|
|
|
|
return;
|
2015-01-19 14:29:24 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
/* The frame interval enumeration code first appeared in Linux 2.6.19. */
|
|
|
|
static GstStructure *
|
|
|
|
gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
|
|
|
|
guint32 pixelformat,
|
|
|
|
guint32 width, guint32 height, const GstStructure * template)
|
|
|
|
{
|
|
|
|
gint fd = v4l2object->video_fd;
|
|
|
|
struct v4l2_frmivalenum ival;
|
|
|
|
guint32 num, denom;
|
|
|
|
GstStructure *s;
|
|
|
|
GValue rates = { 0, };
|
|
|
|
|
|
|
|
memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
|
|
|
|
ival.index = 0;
|
|
|
|
ival.pixel_format = pixelformat;
|
|
|
|
ival.width = width;
|
|
|
|
ival.height = height;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
|
|
|
|
GST_FOURCC_ARGS (pixelformat));
|
|
|
|
|
|
|
|
/* keep in mind that v4l2 gives us frame intervals (durations); we invert the
|
|
|
|
* fraction to get framerate */
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
|
2009-08-04 07:14:20 +00:00
|
|
|
goto enum_frameintervals_failed;
|
|
|
|
|
|
|
|
if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
|
|
|
|
GValue rate = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&rates, GST_TYPE_LIST);
|
|
|
|
g_value_init (&rate, GST_TYPE_FRACTION);
|
|
|
|
|
|
|
|
do {
|
|
|
|
num = ival.discrete.numerator;
|
|
|
|
denom = ival.discrete.denominator;
|
|
|
|
|
|
|
|
if (num > G_MAXINT || denom > G_MAXINT) {
|
|
|
|
/* let us hope we don't get here... */
|
|
|
|
num >>= 1;
|
|
|
|
denom >>= 1;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "adding discrete framerate: %d/%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
denom, num);
|
|
|
|
|
|
|
|
/* swap to get the framerate */
|
|
|
|
gst_value_set_fraction (&rate, denom, num);
|
|
|
|
gst_value_list_append_value (&rates, &rate);
|
|
|
|
|
|
|
|
ival.index++;
|
2017-07-24 18:19:02 +00:00
|
|
|
} while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
|
2009-08-04 07:14:20 +00:00
|
|
|
} else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
|
|
|
|
GValue min = { 0, };
|
|
|
|
GValue step = { 0, };
|
|
|
|
GValue max = { 0, };
|
|
|
|
gboolean added = FALSE;
|
|
|
|
guint32 minnum, mindenom;
|
|
|
|
guint32 maxnum, maxdenom;
|
|
|
|
|
|
|
|
g_value_init (&rates, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
g_value_init (&min, GST_TYPE_FRACTION);
|
|
|
|
g_value_init (&step, GST_TYPE_FRACTION);
|
|
|
|
g_value_init (&max, GST_TYPE_FRACTION);
|
|
|
|
|
|
|
|
/* get the min */
|
|
|
|
minnum = ival.stepwise.min.numerator;
|
|
|
|
mindenom = ival.stepwise.min.denominator;
|
|
|
|
if (minnum > G_MAXINT || mindenom > G_MAXINT) {
|
|
|
|
minnum >>= 1;
|
|
|
|
mindenom >>= 1;
|
|
|
|
}
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise min frame interval: %d/%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
minnum, mindenom);
|
|
|
|
gst_value_set_fraction (&min, minnum, mindenom);
|
|
|
|
|
|
|
|
/* get the max */
|
|
|
|
maxnum = ival.stepwise.max.numerator;
|
|
|
|
maxdenom = ival.stepwise.max.denominator;
|
|
|
|
if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
|
|
|
|
maxnum >>= 1;
|
|
|
|
maxdenom >>= 1;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise max frame interval: %d/%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
maxnum, maxdenom);
|
|
|
|
gst_value_set_fraction (&max, maxnum, maxdenom);
|
|
|
|
|
|
|
|
/* get the step */
|
|
|
|
num = ival.stepwise.step.numerator;
|
|
|
|
denom = ival.stepwise.step.denominator;
|
|
|
|
if (num > G_MAXINT || denom > G_MAXINT) {
|
|
|
|
num >>= 1;
|
|
|
|
denom >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num == 0 || denom == 0) {
|
|
|
|
/* in this case we have a wrong fraction or no step, set the step to max
|
|
|
|
* so that we only add the min value in the loop below */
|
|
|
|
num = maxnum;
|
|
|
|
denom = maxdenom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* since we only have gst_value_fraction_subtract and not add, negate the
|
|
|
|
* numerator */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise step frame interval: %d/%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
num, denom);
|
|
|
|
gst_value_set_fraction (&step, -num, denom);
|
|
|
|
|
2011-12-02 12:07:24 +00:00
|
|
|
while (gst_value_compare (&min, &max) != GST_VALUE_GREATER_THAN) {
|
2009-08-04 07:14:20 +00:00
|
|
|
GValue rate = { 0, };
|
|
|
|
|
|
|
|
num = gst_value_get_fraction_numerator (&min);
|
|
|
|
denom = gst_value_get_fraction_denominator (&min);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "adding stepwise framerate: %d/%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
denom, num);
|
|
|
|
|
|
|
|
/* invert to get the framerate */
|
|
|
|
g_value_init (&rate, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&rate, denom, num);
|
|
|
|
gst_value_list_append_value (&rates, &rate);
|
|
|
|
added = TRUE;
|
|
|
|
|
|
|
|
/* we're actually adding because step was negated above. This is because
|
|
|
|
* there is no _add function... */
|
|
|
|
if (!gst_value_fraction_subtract (&min, &min, &step)) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj, "could not step fraction!");
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!added) {
|
|
|
|
/* no range was added, leave the default range from the template */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"no range added, leaving default");
|
|
|
|
g_value_unset (&rates);
|
|
|
|
}
|
|
|
|
} else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
|
|
|
|
guint32 maxnum, maxdenom;
|
|
|
|
|
|
|
|
g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
|
|
|
|
|
|
|
|
num = ival.stepwise.min.numerator;
|
|
|
|
denom = ival.stepwise.min.denominator;
|
|
|
|
if (num > G_MAXINT || denom > G_MAXINT) {
|
|
|
|
num >>= 1;
|
|
|
|
denom >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxnum = ival.stepwise.max.numerator;
|
|
|
|
maxdenom = ival.stepwise.max.denominator;
|
|
|
|
if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
|
|
|
|
maxnum >>= 1;
|
|
|
|
maxdenom >>= 1;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
|
|
|
|
num);
|
|
|
|
|
|
|
|
gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
|
|
|
|
} else {
|
|
|
|
goto unknown_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return_data:
|
|
|
|
s = gst_structure_copy (template);
|
|
|
|
gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
|
2013-06-04 06:26:33 +00:00
|
|
|
"height", G_TYPE_INT, (gint) height, NULL);
|
2017-07-20 02:05:49 +00:00
|
|
|
|
2013-06-04 06:26:33 +00:00
|
|
|
gst_v4l2_object_add_aspect_ratio (v4l2object, s);
|
2017-07-20 02:09:38 +00:00
|
|
|
|
|
|
|
if (!v4l2object->skip_try_fmt_probes) {
|
|
|
|
gst_v4l2_object_add_interlace_mode (v4l2object, s, width, height,
|
|
|
|
pixelformat);
|
|
|
|
gst_v4l2_object_add_colorspace (v4l2object, s, width, height, pixelformat);
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
if (G_IS_VALUE (&rates)) {
|
2014-05-12 16:20:14 +00:00
|
|
|
gst_v4l2src_value_simplify (&rates);
|
2009-08-04 07:14:20 +00:00
|
|
|
/* only change the framerate on the template when we have a valid probed new
|
|
|
|
* value */
|
2014-05-12 16:23:19 +00:00
|
|
|
gst_structure_take_value (s, "framerate", &rates);
|
2013-12-12 21:46:09 +00:00
|
|
|
} else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
|
|
|
|
v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
|
2015-07-24 13:10:05 +00:00
|
|
|
gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT,
|
|
|
|
1, NULL);
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
enum_frameintervals_failed:
|
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height);
|
|
|
|
goto return_data;
|
|
|
|
}
|
|
|
|
unknown_type:
|
|
|
|
{
|
|
|
|
/* I don't see how this is actually an error, we ignore the format then */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
sort_by_frame_size (GstStructure * s1, GstStructure * s2)
|
|
|
|
{
|
|
|
|
int w1, h1, w2, h2;
|
|
|
|
|
|
|
|
gst_structure_get_int (s1, "width", &w1);
|
|
|
|
gst_structure_get_int (s1, "height", &h1);
|
|
|
|
gst_structure_get_int (s2, "width", &w2);
|
|
|
|
gst_structure_get_int (s2, "height", &h2);
|
|
|
|
|
|
|
|
/* I think it's safe to assume that this won't overflow for a while */
|
|
|
|
return ((w2 * h2) - (w1 * h1));
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
static void
|
|
|
|
check_alternate_and_append_struct (GstCaps * caps, GstStructure * s)
|
|
|
|
{
|
|
|
|
const GValue *mode;
|
|
|
|
|
|
|
|
mode = gst_structure_get_value (s, "interlace-mode");
|
|
|
|
if (!mode)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (mode)) {
|
|
|
|
/* Add the INTERLACED feature if the mode is alternate */
|
|
|
|
if (!g_strcmp0 (gst_structure_get_string (s, "interlace-mode"),
|
|
|
|
"alternate")) {
|
|
|
|
GstCapsFeatures *feat;
|
|
|
|
|
|
|
|
feat = gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL);
|
|
|
|
gst_caps_set_features (caps, gst_caps_get_size (caps) - 1, feat);
|
|
|
|
}
|
|
|
|
} else if (GST_VALUE_HOLDS_LIST (mode)) {
|
|
|
|
/* If the mode is a list containing alternate, remove it from the list and add a
|
|
|
|
* variant with interlace-mode=alternate and the INTERLACED feature. */
|
|
|
|
GValue alter = G_VALUE_INIT;
|
|
|
|
GValue inter = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&alter, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&alter, "alternate");
|
|
|
|
|
|
|
|
/* Cannot use gst_value_can_intersect() as it requires args to have the
|
|
|
|
* same type. */
|
|
|
|
if (gst_value_intersect (&inter, mode, &alter)) {
|
|
|
|
GValue minus_alter = G_VALUE_INIT;
|
|
|
|
GstStructure *copy;
|
|
|
|
|
|
|
|
gst_value_subtract (&minus_alter, mode, &alter);
|
|
|
|
gst_structure_take_value (s, "interlace-mode", &minus_alter);
|
|
|
|
|
|
|
|
copy = gst_structure_copy (s);
|
|
|
|
gst_structure_take_value (copy, "interlace-mode", &inter);
|
|
|
|
gst_caps_append_structure_full (caps, copy,
|
|
|
|
gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL));
|
|
|
|
}
|
|
|
|
g_value_unset (&alter);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_caps_append_structure (caps, s);
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:40:31 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_update_and_append (GstV4l2Object * v4l2object,
|
|
|
|
guint32 format, GstCaps * caps, GstStructure * s)
|
|
|
|
{
|
2014-03-19 21:00:56 +00:00
|
|
|
GstStructure *alt_s = NULL;
|
|
|
|
|
2014-01-10 17:40:31 +00:00
|
|
|
/* Encoded stream on output buffer need to be parsed */
|
|
|
|
if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
|
|
|
|
v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
for (; i < GST_V4L2_FORMAT_COUNT; i++) {
|
2024-08-14 19:21:44 +00:00
|
|
|
if (format == gst_v4l2_formats[i].v4l2_format &&
|
2014-02-25 21:10:54 +00:00
|
|
|
gst_v4l2_formats[i].flags & GST_V4L2_CODEC &&
|
|
|
|
!(gst_v4l2_formats[i].flags & GST_V4L2_NO_PARSE)) {
|
2014-01-10 17:40:31 +00:00
|
|
|
gst_structure_set (s, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:00:56 +00:00
|
|
|
if (v4l2object->has_alpha_component &&
|
|
|
|
(v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
|
|
|
|
v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
|
|
|
|
switch (format) {
|
|
|
|
case V4L2_PIX_FMT_RGB32:
|
|
|
|
alt_s = gst_structure_copy (s);
|
|
|
|
gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
alt_s = gst_structure_copy (s);
|
|
|
|
gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
check_alternate_and_append_struct (caps, s);
|
2014-03-19 21:00:56 +00:00
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
if (alt_s) {
|
|
|
|
check_alternate_and_append_struct (caps, alt_s);
|
|
|
|
}
|
2014-01-10 17:40:31 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 21:58:07 +00:00
|
|
|
static GstCaps *
|
2009-08-04 07:14:20 +00:00
|
|
|
gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
|
|
|
|
guint32 pixelformat, const GstStructure * template)
|
|
|
|
{
|
|
|
|
GstCaps *ret = gst_caps_new_empty ();
|
|
|
|
GstStructure *tmp;
|
|
|
|
gint fd = v4l2object->video_fd;
|
|
|
|
struct v4l2_frmsizeenum size;
|
|
|
|
GList *results = NULL;
|
|
|
|
guint32 w, h;
|
|
|
|
|
2014-01-10 17:39:16 +00:00
|
|
|
if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')) {
|
|
|
|
gst_caps_append_structure (ret, gst_structure_copy (template));
|
|
|
|
return ret;
|
|
|
|
}
|
2009-09-07 16:28:51 +00:00
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
|
|
|
|
size.index = 0;
|
|
|
|
size.pixel_format = pixelformat;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2013-11-13 10:42:21 +00:00
|
|
|
"Enumerating frame sizes for %" GST_FOURCC_FORMAT,
|
|
|
|
GST_FOURCC_ARGS (pixelformat));
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
|
2009-08-04 07:14:20 +00:00
|
|
|
goto enum_framesizes_failed;
|
|
|
|
|
|
|
|
if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
|
2023-05-05 09:01:50 +00:00
|
|
|
guint32 maxw = 0, maxh = 0;
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
do {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "got discrete frame size %dx%d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.discrete.width, size.discrete.height);
|
|
|
|
|
|
|
|
w = MIN (size.discrete.width, G_MAXINT);
|
|
|
|
h = MIN (size.discrete.height, G_MAXINT);
|
|
|
|
|
|
|
|
if (w && h) {
|
|
|
|
tmp =
|
|
|
|
gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
|
|
|
|
pixelformat, w, h, template);
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
results = g_list_prepend (results, tmp);
|
|
|
|
}
|
|
|
|
|
2023-05-05 09:01:50 +00:00
|
|
|
if (w > maxw && h > maxh) {
|
|
|
|
maxw = w;
|
|
|
|
maxh = h;
|
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
size.index++;
|
2017-07-24 18:19:02 +00:00
|
|
|
} while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
|
2023-05-05 09:01:50 +00:00
|
|
|
|
|
|
|
v4l2object->max_width = maxw;
|
|
|
|
v4l2object->max_height = maxh;
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"done iterating discrete frame sizes");
|
|
|
|
} else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
|
2014-06-30 09:29:54 +00:00
|
|
|
guint32 maxw, maxh, step_w, step_h;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have stepwise frame sizes:");
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.min_width);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.min_height);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.max_width);
|
2023-05-06 03:17:43 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max height: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.max_height);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step width: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.step_width);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step height: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.step_height);
|
|
|
|
|
2014-06-30 09:29:54 +00:00
|
|
|
step_w = MAX (size.stepwise.step_width, 1);
|
|
|
|
step_h = MAX (size.stepwise.step_height, 1);
|
2023-05-06 03:17:43 +00:00
|
|
|
w = MAX (size.stepwise.min_width, step_w);
|
|
|
|
h = MAX (size.stepwise.min_height, step_h);
|
|
|
|
maxw = MIN (size.stepwise.max_width, G_MAXINT);
|
|
|
|
maxh = MIN (size.stepwise.max_height, G_MAXINT);
|
2014-06-30 09:29:54 +00:00
|
|
|
|
|
|
|
/* FIXME: check for sanity and that min/max are multiples of the steps */
|
|
|
|
|
|
|
|
/* we only query details for the max width/height since it's likely the
|
|
|
|
* most restricted if there are any resolution-dependent restrictions */
|
|
|
|
tmp = gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
|
|
|
|
pixelformat, maxw, maxh, template);
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2014-06-30 09:29:54 +00:00
|
|
|
if (tmp) {
|
|
|
|
GValue step_range = G_VALUE_INIT;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2014-06-30 09:29:54 +00:00
|
|
|
g_value_init (&step_range, GST_TYPE_INT_RANGE);
|
|
|
|
gst_value_set_int_range_step (&step_range, w, maxw, step_w);
|
|
|
|
gst_structure_set_value (tmp, "width", &step_range);
|
|
|
|
|
|
|
|
gst_value_set_int_range_step (&step_range, h, maxh, step_h);
|
|
|
|
gst_structure_take_value (tmp, "height", &step_range);
|
|
|
|
|
|
|
|
/* no point using the results list here, since there's only one struct */
|
|
|
|
gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
|
2023-05-05 09:01:50 +00:00
|
|
|
|
|
|
|
v4l2object->max_width = maxw;
|
|
|
|
v4l2object->max_height = maxh;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
} else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
|
|
|
|
guint32 maxw, maxh;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have continuous frame sizes:");
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.min_width);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.min_height);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.max_width);
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
|
2009-08-04 07:14:20 +00:00
|
|
|
size.stepwise.max_height);
|
|
|
|
|
|
|
|
w = MAX (size.stepwise.min_width, 1);
|
|
|
|
h = MAX (size.stepwise.min_height, 1);
|
|
|
|
maxw = MIN (size.stepwise.max_width, G_MAXINT);
|
|
|
|
maxh = MIN (size.stepwise.max_height, G_MAXINT);
|
|
|
|
|
|
|
|
tmp =
|
|
|
|
gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
|
|
|
|
w, h, template);
|
|
|
|
if (tmp) {
|
|
|
|
gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
|
|
|
|
(gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* no point using the results list here, since there's only one struct */
|
2014-01-10 17:40:31 +00:00
|
|
|
gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
|
2023-05-05 09:01:50 +00:00
|
|
|
|
|
|
|
v4l2object->max_width = maxw;
|
|
|
|
v4l2object->max_height = maxh;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
goto unknown_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we use an intermediary list to store and then sort the results of the
|
|
|
|
* probing because we can't make any assumptions about the order in which
|
|
|
|
* the driver will give us the sizes, but we want the final caps to contain
|
|
|
|
* the results starting with the highest resolution and having the lowest
|
|
|
|
* resolution last, since order in caps matters for things like fixation. */
|
|
|
|
results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
|
|
|
|
while (results != NULL) {
|
2014-01-10 17:40:31 +00:00
|
|
|
gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret,
|
|
|
|
results->data);
|
2009-08-04 07:14:20 +00:00
|
|
|
results = g_list_delete_link (results, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (ret))
|
|
|
|
goto enum_framesizes_no_results;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
enum_framesizes_failed:
|
|
|
|
{
|
|
|
|
/* I don't see how this is actually an error */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
|
|
|
|
" (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
|
|
|
|
goto default_frame_sizes;
|
|
|
|
}
|
|
|
|
enum_framesizes_no_results:
|
|
|
|
{
|
|
|
|
/* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
|
|
|
|
* question doesn't actually support it yet */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"No results for pixelformat %" GST_FOURCC_FORMAT
|
|
|
|
" enumerating frame sizes, trying fallback",
|
|
|
|
GST_FOURCC_ARGS (pixelformat));
|
|
|
|
goto default_frame_sizes;
|
|
|
|
}
|
|
|
|
unknown_type:
|
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
|
|
|
|
": %u", GST_FOURCC_ARGS (pixelformat), size.type);
|
|
|
|
goto default_frame_sizes;
|
|
|
|
}
|
2014-03-15 10:13:05 +00:00
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
default_frame_sizes:
|
|
|
|
{
|
|
|
|
gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
|
|
|
|
|
|
|
|
/* This code is for Linux < 2.6.19 */
|
|
|
|
min_w = min_h = 1;
|
|
|
|
max_w = max_h = GST_V4L2_MAX_SIZE;
|
|
|
|
if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
|
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
|
|
|
&min_h)) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Could not probe minimum capture size for pixelformat %"
|
|
|
|
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
|
|
|
|
}
|
|
|
|
if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
|
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
|
|
|
&max_h)) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"Could not probe maximum capture size for pixelformat %"
|
|
|
|
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
|
|
|
|
}
|
2021-11-29 14:35:36 +00:00
|
|
|
if (min_w == 0 || min_h == 0)
|
|
|
|
min_w = min_h = 1;
|
|
|
|
if (max_w == 0 || max_h == 0)
|
|
|
|
max_w = max_h = GST_V4L2_MAX_SIZE;
|
2024-03-21 09:07:42 +00:00
|
|
|
v4l2object->max_width = max_w;
|
|
|
|
v4l2object->max_height = max_h;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
/* Since we can't get framerate directly, try to use the current norm */
|
2010-04-04 11:43:41 +00:00
|
|
|
if (v4l2object->tv_norm && v4l2object->norms) {
|
2009-08-04 07:14:20 +00:00
|
|
|
GList *norms;
|
2010-06-15 17:47:16 +00:00
|
|
|
GstTunerNorm *norm = NULL;
|
2010-04-04 11:43:41 +00:00
|
|
|
GstTunerNorm *current =
|
|
|
|
gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
|
|
|
|
norm = (GstTunerNorm *) norms->data;
|
2010-04-04 11:43:41 +00:00
|
|
|
if (!strcmp (norm->label, current->label))
|
2009-08-04 07:14:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* If it's possible, set framerate to that (discrete) value */
|
|
|
|
if (norm) {
|
|
|
|
fix_num = gst_value_get_fraction_numerator (&norm->framerate);
|
|
|
|
fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = gst_structure_copy (template);
|
|
|
|
if (fix_num) {
|
2009-08-09 13:19:42 +00:00
|
|
|
gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
|
|
|
|
fix_denom, NULL);
|
2013-12-12 21:46:09 +00:00
|
|
|
} else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
|
|
|
|
v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
|
2009-08-04 07:14:20 +00:00
|
|
|
/* if norm can't be used, copy the template framerate */
|
2009-08-09 13:19:42 +00:00
|
|
|
gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
|
2015-07-24 13:10:05 +00:00
|
|
|
G_MAXINT, 1, NULL);
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
2009-08-09 13:19:42 +00:00
|
|
|
|
|
|
|
if (min_w == max_w)
|
|
|
|
gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
|
|
|
|
else
|
|
|
|
gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
|
|
|
|
|
|
|
|
if (min_h == max_h)
|
|
|
|
gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
|
|
|
|
else
|
|
|
|
gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
|
|
|
|
|
2013-06-04 06:26:33 +00:00
|
|
|
gst_v4l2_object_add_aspect_ratio (v4l2object, tmp);
|
2017-07-20 02:09:38 +00:00
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
/* We could consider setting interlace mode from min and max. */
|
|
|
|
gst_v4l2_object_add_interlace_mode (v4l2object, tmp, max_w, max_h,
|
|
|
|
pixelformat);
|
|
|
|
|
2017-07-20 02:09:38 +00:00
|
|
|
if (!v4l2object->skip_try_fmt_probes) {
|
2020-12-11 03:24:14 +00:00
|
|
|
gint probed_w, probed_h;
|
|
|
|
if (v4l2object->info.width >= min_w && v4l2object->info.width <= max_w &&
|
|
|
|
v4l2object->info.height >= min_h
|
|
|
|
&& v4l2object->info.height <= max_h) {
|
|
|
|
probed_w = v4l2object->info.width;
|
|
|
|
probed_h = v4l2object->info.height;
|
|
|
|
} else {
|
|
|
|
probed_w = max_w;
|
|
|
|
probed_h = max_h;
|
|
|
|
}
|
2017-07-20 02:09:38 +00:00
|
|
|
/* We could consider to check colorspace for min too, in case it depends on
|
|
|
|
* the size. But in this case, min and max could not be enough */
|
2020-12-11 03:24:14 +00:00
|
|
|
gst_v4l2_object_add_colorspace (v4l2object, tmp, probed_w, probed_h,
|
2017-07-20 02:09:38 +00:00
|
|
|
pixelformat);
|
|
|
|
}
|
2010-11-04 17:36:09 +00:00
|
|
|
|
2014-01-10 17:40:31 +00:00
|
|
|
gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
|
2009-08-04 07:14:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
|
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
|
|
|
guint32 pixelformat, gint * width, gint * height)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
2014-06-27 10:33:06 +00:00
|
|
|
struct v4l2_format fmt;
|
2013-12-31 12:31:52 +00:00
|
|
|
gboolean ret = FALSE;
|
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
|
|
|
GstVideoInterlaceMode interlace_mode;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (width != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (height != NULL, FALSE);
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
|
|
|
|
*width, *height, GST_FOURCC_ARGS (pixelformat));
|
|
|
|
|
2013-12-03 23:27:47 +00:00
|
|
|
memset (&fmt, 0, sizeof (struct v4l2_format));
|
2011-08-08 09:54:26 +00:00
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
/* get size delimiters */
|
|
|
|
memset (&fmt, 0, sizeof (fmt));
|
|
|
|
fmt.type = v4l2object->type;
|
|
|
|
fmt.fmt.pix.width = *width;
|
|
|
|
fmt.fmt.pix.height = *height;
|
|
|
|
fmt.fmt.pix.pixelformat = pixelformat;
|
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
|
|
|
fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
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
|
|
|
if (gst_v4l2_object_try_fmt (v4l2object, &fmt) < 0)
|
|
|
|
goto error;
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj,
|
2009-08-04 07:14:20 +00:00
|
|
|
"got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
|
|
|
|
|
|
|
|
*width = fmt.fmt.pix.width;
|
|
|
|
*height = fmt.fmt.pix.height;
|
|
|
|
|
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
|
|
|
if (!gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2014-08-29 10:01:27 +00:00
|
|
|
"Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u: %u",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), *width, *height, fmt.fmt.pix.field);
|
|
|
|
goto error;
|
2010-11-04 17:36:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 12:31:52 +00:00
|
|
|
ret = TRUE;
|
2011-08-08 09:54:26 +00:00
|
|
|
|
|
|
|
error:
|
2013-12-31 12:31:52 +00:00
|
|
|
if (!ret) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2013-12-31 12:31:52 +00:00
|
|
|
"Unable to try format: %s", g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 02:19:42 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_is_dmabuf_supported (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
struct v4l2_exportbuffer expbuf = {
|
|
|
|
.type = v4l2object->type,
|
|
|
|
.index = -1,
|
|
|
|
.plane = -1,
|
|
|
|
.flags = O_CLOEXEC | O_RDWR,
|
|
|
|
};
|
|
|
|
|
2022-01-26 14:55:09 +00:00
|
|
|
if (v4l2object->fmtdesc &&
|
|
|
|
v4l2object->fmtdesc->flags & V4L2_FMT_FLAG_EMULATED) {
|
2018-04-11 20:28:00 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"libv4l2 converter detected, disabling DMABuf");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
2017-09-30 02:19:42 +00:00
|
|
|
/* Expected to fail, but ENOTTY tells us that it is not implemented. */
|
2017-10-07 14:39:18 +00:00
|
|
|
v4l2object->ioctl (v4l2object->video_fd, VIDIOC_EXPBUF, &expbuf);
|
2017-11-29 10:29:31 +00:00
|
|
|
if (errno == ENOTTY)
|
2017-09-30 02:19:42 +00:00
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-13 14:33:58 +00:00
|
|
|
static gboolean
|
2011-07-15 15:26:06 +00:00
|
|
|
gst_v4l2_object_setup_pool (GstV4l2Object * v4l2object, GstCaps * caps)
|
2011-07-13 14:33:58 +00:00
|
|
|
{
|
2011-07-26 09:54:23 +00:00
|
|
|
GstV4l2IOMode mode;
|
2011-07-18 16:54:49 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "initializing the %s system",
|
2014-07-23 16:39:50 +00:00
|
|
|
V4L2_TYPE_IS_OUTPUT (v4l2object->type) ? "output" : "capture");
|
2011-07-13 14:33:58 +00:00
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (v4l2object);
|
|
|
|
GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
|
|
|
|
|
2011-07-26 09:54:23 +00:00
|
|
|
/* find transport */
|
|
|
|
mode = v4l2object->req_mode;
|
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
if (v4l2object->device_caps & V4L2_CAP_READWRITE) {
|
2011-07-26 09:54:23 +00:00
|
|
|
if (v4l2object->req_mode == GST_V4L2_IO_AUTO)
|
|
|
|
mode = GST_V4L2_IO_RW;
|
|
|
|
} else if (v4l2object->req_mode == GST_V4L2_IO_RW)
|
|
|
|
goto method_not_supported;
|
|
|
|
|
2016-07-02 08:56:07 +00:00
|
|
|
if (v4l2object->device_caps & V4L2_CAP_STREAMING) {
|
2017-09-30 02:19:42 +00:00
|
|
|
if (v4l2object->req_mode == GST_V4L2_IO_AUTO) {
|
|
|
|
if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type) &&
|
|
|
|
gst_v4l2_object_is_dmabuf_supported (v4l2object)) {
|
|
|
|
mode = GST_V4L2_IO_DMABUF;
|
|
|
|
} else {
|
|
|
|
mode = GST_V4L2_IO_MMAP;
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 16:05:45 +00:00
|
|
|
} else if (v4l2object->req_mode == GST_V4L2_IO_MMAP ||
|
|
|
|
v4l2object->req_mode == GST_V4L2_IO_DMABUF)
|
2011-07-26 09:54:23 +00:00
|
|
|
goto method_not_supported;
|
2011-07-13 14:33:58 +00:00
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
/* if still no transport selected, error out */
|
2011-07-26 09:54:23 +00:00
|
|
|
if (mode == GST_V4L2_IO_AUTO)
|
2011-07-18 16:54:49 +00:00
|
|
|
goto no_supported_capture_method;
|
2011-07-13 14:33:58 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj, "accessing buffers via mode %d", mode);
|
2011-07-26 09:54:23 +00:00
|
|
|
v4l2object->mode = mode;
|
|
|
|
|
2015-03-30 11:12:35 +00:00
|
|
|
/* If min_buffers is not set, the driver either does not support the control or
|
|
|
|
it has not been asked yet via propose_allocation/decide_allocation. */
|
|
|
|
if (!v4l2object->min_buffers)
|
|
|
|
gst_v4l2_get_driver_min_buffers (v4l2object);
|
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
/* Map the buffers */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "initiating buffer pool");
|
2011-07-13 14:33:58 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
{
|
|
|
|
GstBufferPool *pool = gst_v4l2_buffer_pool_new (v4l2object, caps);
|
|
|
|
GST_OBJECT_LOCK (v4l2object->element);
|
|
|
|
v4l2object->pool = pool;
|
|
|
|
GST_OBJECT_UNLOCK (v4l2object->element);
|
|
|
|
if (!pool)
|
|
|
|
goto buffer_pool_new_failed;
|
|
|
|
}
|
2011-07-13 14:33:58 +00:00
|
|
|
|
|
|
|
GST_V4L2_SET_ACTIVE (v4l2object);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
buffer_pool_new_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
|
|
|
|
(_("Could not map buffers from device '%s'"),
|
|
|
|
v4l2object->videodev),
|
|
|
|
("Failed to create buffer pool: %s", g_strerror (errno)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-26 09:54:23 +00:00
|
|
|
method_not_supported:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
|
|
|
|
(_("The driver of device '%s' does not support the IO method %d"),
|
|
|
|
v4l2object->videodev, mode), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-13 14:33:58 +00:00
|
|
|
no_supported_capture_method:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
|
2011-07-26 09:54:23 +00:00
|
|
|
(_("The driver of device '%s' does not support any known IO "
|
2011-07-13 14:33:58 +00:00
|
|
|
"method."), v4l2object->videodev), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 06:32:22 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_reset_compose_region (GstV4l2Object * obj)
|
|
|
|
{
|
|
|
|
struct v4l2_selection sel = { 0 };
|
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (obj);
|
|
|
|
|
|
|
|
sel.type = obj->type;
|
|
|
|
sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
|
|
|
|
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_G_SELECTION, &sel) < 0) {
|
|
|
|
if (errno == ENOTTY) {
|
|
|
|
/* No-op when selection API is not supported */
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Failed to get default compose rectangle with VIDIOC_G_SELECTION: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sel.target = V4L2_SEL_TGT_COMPOSE;
|
|
|
|
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_S_SELECTION, &sel) < 0) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Failed to set default compose rectangle with VIDIOC_S_SELECTION: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-25 14:49:39 +00:00
|
|
|
static void
|
2014-05-06 16:58:59 +00:00
|
|
|
gst_v4l2_object_set_stride (GstVideoInfo * info, GstVideoAlignment * align,
|
|
|
|
gint plane, gint stride)
|
2014-03-25 14:49:39 +00:00
|
|
|
{
|
2014-05-06 16:58:59 +00:00
|
|
|
const GstVideoFormatInfo *finfo = info->finfo;
|
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
|
2022-11-15 18:50:13 +00:00
|
|
|
gint x_tiles, y_tiles, tile_height, padded_height;
|
2014-05-06 16:58:59 +00:00
|
|
|
|
2022-11-15 18:50:13 +00:00
|
|
|
tile_height = GST_VIDEO_FORMAT_INFO_TILE_HEIGHT (finfo, plane);
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
padded_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, plane,
|
|
|
|
info->height + align->padding_top + align->padding_bottom);
|
|
|
|
|
2022-11-15 18:50:13 +00:00
|
|
|
x_tiles = stride / GST_VIDEO_FORMAT_INFO_TILE_STRIDE (finfo, plane);
|
2023-10-11 13:36:11 +00:00
|
|
|
y_tiles = (padded_height + tile_height - 1) / tile_height;
|
2014-05-06 16:58:59 +00:00
|
|
|
info->stride[plane] = GST_VIDEO_TILE_MAKE_STRIDE (x_tiles, y_tiles);
|
|
|
|
} else {
|
|
|
|
info->stride[plane] = stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_v4l2_object_extrapolate_info (GstV4l2Object * v4l2object,
|
|
|
|
GstVideoInfo * info, GstVideoAlignment * align, gint stride)
|
|
|
|
{
|
|
|
|
const GstVideoFormatInfo *finfo = info->finfo;
|
|
|
|
gint i, estride, padded_height;
|
|
|
|
gsize offs = 0;
|
2014-03-25 14:49:39 +00:00
|
|
|
|
|
|
|
g_return_if_fail (v4l2object->n_v4l2_planes == 1);
|
|
|
|
|
2020-01-30 06:39:12 +00:00
|
|
|
padded_height =
|
|
|
|
GST_VIDEO_INFO_FIELD_HEIGHT (info) + align->padding_top +
|
|
|
|
align->padding_bottom;
|
2014-05-06 16:58:59 +00:00
|
|
|
|
2014-03-25 14:49:39 +00:00
|
|
|
for (i = 0; i < finfo->n_planes; i++) {
|
2022-01-25 19:08:47 +00:00
|
|
|
estride = gst_video_format_info_extrapolate_stride (finfo, i, stride);
|
2014-03-25 14:49:39 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
gst_v4l2_object_set_stride (info, align, i, estride);
|
|
|
|
|
|
|
|
info->offset[i] = offs;
|
2014-05-13 17:44:20 +00:00
|
|
|
offs += estride *
|
2014-05-06 16:58:59 +00:00
|
|
|
GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, padded_height);
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2014-05-06 16:58:59 +00:00
|
|
|
"Extrapolated for plane %d with base stride %d: "
|
|
|
|
"stride %d, offset %" G_GSIZE_FORMAT, i, stride, info->stride[i],
|
|
|
|
info->offset[i]);
|
2014-03-25 14:49:39 +00:00
|
|
|
}
|
2017-01-03 00:29:04 +00:00
|
|
|
|
|
|
|
/* Update the image size according the amount of data we are going to
|
|
|
|
* read/write. This workaround bugs in driver where the sizeimage provided
|
|
|
|
* by TRY/S_FMT represent the buffer length (maximum size) rather then the expected
|
|
|
|
* bytesused (buffer size). */
|
|
|
|
if (offs < info->size)
|
|
|
|
info->size = offs;
|
2014-03-25 14:49:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:34:17 +00:00
|
|
|
static void
|
|
|
|
gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
|
|
|
|
struct v4l2_fmtdesc *fmtdesc, struct v4l2_format *format,
|
2014-04-15 19:07:23 +00:00
|
|
|
GstVideoInfo * info, GstVideoAlignment * align)
|
2013-12-10 19:34:17 +00:00
|
|
|
{
|
|
|
|
const GstVideoFormatInfo *finfo = info->finfo;
|
2014-05-06 16:58:59 +00:00
|
|
|
gboolean standard_stride = TRUE;
|
2018-01-17 10:10:37 +00:00
|
|
|
gint stride, pstride, padded_width, padded_height, i;
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (info) == GST_VIDEO_FORMAT_ENCODED) {
|
|
|
|
v4l2object->n_v4l2_planes = 1;
|
|
|
|
info->size = format->fmt.pix.sizeimage;
|
|
|
|
goto store_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust right padding */
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
|
|
|
|
stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
|
|
|
|
else
|
|
|
|
stride = format->fmt.pix.bytesperline;
|
|
|
|
|
2018-01-17 10:10:37 +00:00
|
|
|
pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (finfo, 0);
|
|
|
|
if (pstride) {
|
|
|
|
padded_width = stride / pstride;
|
|
|
|
} else {
|
|
|
|
/* pstride can be 0 for complex formats */
|
2023-04-15 03:38:34 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2018-01-17 10:10:37 +00:00
|
|
|
"format %s has a pstride of 0, cannot compute padded with",
|
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (info)));
|
2024-07-01 02:00:42 +00:00
|
|
|
padded_width = format->fmt.pix.width;
|
2018-01-17 10:10:37 +00:00
|
|
|
}
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
if (padded_width < format->fmt.pix.width)
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2018-01-17 10:08:25 +00:00
|
|
|
"Driver bug detected, stride (%d) is too small for the width (%d)",
|
|
|
|
padded_width, format->fmt.pix.width);
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
align->padding_right = padded_width - info->width - align->padding_left;
|
|
|
|
|
|
|
|
/* adjust bottom padding */
|
|
|
|
padded_height = format->fmt.pix.height;
|
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
|
2022-11-15 18:50:13 +00:00
|
|
|
guint tile_height;
|
|
|
|
tile_height = GST_VIDEO_FORMAT_INFO_TILE_HEIGHT (finfo, 0);
|
2024-03-29 02:14:54 +00:00
|
|
|
/* Round-up to tile_height as drivers are not forced to do so */
|
|
|
|
padded_height =
|
|
|
|
(padded_height + tile_height - 1) / tile_height * tile_height;
|
2014-05-06 16:58:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 06:39:12 +00:00
|
|
|
align->padding_bottom =
|
|
|
|
padded_height - GST_VIDEO_INFO_FIELD_HEIGHT (info) - align->padding_top;
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
/* setup the strides and offset */
|
2013-12-10 19:34:17 +00:00
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type)) {
|
2014-05-06 16:58:59 +00:00
|
|
|
struct v4l2_pix_format_mplane *pix_mp = &format->fmt.pix_mp;
|
|
|
|
|
2013-12-10 19:34:17 +00:00
|
|
|
/* figure out the frame layout */
|
2014-05-06 16:58:59 +00:00
|
|
|
v4l2object->n_v4l2_planes = MAX (1, pix_mp->num_planes);
|
|
|
|
info->size = 0;
|
2014-04-08 22:17:31 +00:00
|
|
|
for (i = 0; i < v4l2object->n_v4l2_planes; i++) {
|
2014-05-06 16:58:59 +00:00
|
|
|
stride = pix_mp->plane_fmt[i].bytesperline;
|
|
|
|
|
|
|
|
if (info->stride[i] != stride)
|
|
|
|
standard_stride = FALSE;
|
|
|
|
|
|
|
|
gst_v4l2_object_set_stride (info, align, i, stride);
|
|
|
|
info->offset[i] = info->size;
|
|
|
|
info->size += pix_mp->plane_fmt[i].sizeimage;
|
2013-12-10 19:34:17 +00:00
|
|
|
}
|
2014-03-25 14:49:39 +00:00
|
|
|
|
|
|
|
/* Extrapolate stride if planar format are being set in 1 v4l2 plane */
|
|
|
|
if (v4l2object->n_v4l2_planes < finfo->n_planes) {
|
|
|
|
stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
|
2014-05-06 16:58:59 +00:00
|
|
|
gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
|
2014-03-25 14:49:39 +00:00
|
|
|
}
|
2013-12-10 19:34:17 +00:00
|
|
|
} else {
|
|
|
|
/* only one plane in non-MPLANE mode */
|
|
|
|
v4l2object->n_v4l2_planes = 1;
|
2014-05-06 16:58:59 +00:00
|
|
|
info->size = format->fmt.pix.sizeimage;
|
2014-03-25 14:49:39 +00:00
|
|
|
stride = format->fmt.pix.bytesperline;
|
2013-12-10 19:34:17 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
if (info->stride[0] != stride)
|
|
|
|
standard_stride = FALSE;
|
2013-12-10 19:34:17 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
|
|
|
|
}
|
2014-04-15 19:07:23 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
/* adjust the offset to take into account left and top */
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
|
|
|
|
if ((align->padding_left + align->padding_top) > 0)
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2014-05-06 16:58:59 +00:00
|
|
|
"Left and top padding is not permitted for tiled formats");
|
2024-07-29 15:40:01 +00:00
|
|
|
memset (v4l2object->plane_size, 0, sizeof (v4l2object->plane_size));
|
2014-05-06 16:58:59 +00:00
|
|
|
} else {
|
2023-06-22 14:10:43 +00:00
|
|
|
if (!gst_video_info_align_full (info, align, v4l2object->plane_size)) {
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj, "Failed to align video info");
|
2014-05-06 16:58:59 +00:00
|
|
|
}
|
2014-03-18 19:49:49 +00:00
|
|
|
}
|
2014-04-15 19:07:23 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
store_info:
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got sizeimage %" G_GSIZE_FORMAT,
|
2014-05-06 16:58:59 +00:00
|
|
|
info->size);
|
|
|
|
|
2017-03-23 21:13:05 +00:00
|
|
|
/* to avoid copies we need video meta if there is padding */
|
2014-05-06 16:58:59 +00:00
|
|
|
v4l2object->need_video_meta =
|
2017-03-23 21:13:05 +00:00
|
|
|
((align->padding_top + align->padding_left + align->padding_right +
|
|
|
|
align->padding_bottom) != 0);
|
2014-05-06 16:58:59 +00:00
|
|
|
|
|
|
|
/* ... or if stride is non "standard" */
|
|
|
|
if (!standard_stride)
|
|
|
|
v4l2object->need_video_meta = TRUE;
|
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
/* ... or also video meta if we use multiple, non-contiguous, planes */
|
|
|
|
if (v4l2object->n_v4l2_planes > 1)
|
|
|
|
v4l2object->need_video_meta = TRUE;
|
|
|
|
|
2013-12-10 19:34:17 +00:00
|
|
|
v4l2object->info = *info;
|
2014-04-15 19:07:23 +00:00
|
|
|
v4l2object->align = *align;
|
2014-03-27 22:41:07 +00:00
|
|
|
v4l2object->format = *format;
|
2013-12-10 19:34:17 +00:00
|
|
|
v4l2object->fmtdesc = fmtdesc;
|
|
|
|
|
|
|
|
/* if we have a framerate pre-calculate duration */
|
|
|
|
if (info->fps_n > 0 && info->fps_d > 0) {
|
|
|
|
v4l2object->duration = gst_util_uint64_scale_int (GST_SECOND, info->fps_d,
|
|
|
|
info->fps_n);
|
2018-08-08 07:27:19 +00:00
|
|
|
if (GST_VIDEO_INFO_INTERLACE_MODE (info) ==
|
|
|
|
GST_VIDEO_INTERLACE_MODE_ALTERNATE)
|
|
|
|
v4l2object->duration /= 2;
|
2013-12-10 19:34:17 +00:00
|
|
|
} else {
|
|
|
|
v4l2object->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
static enum v4l2_field
|
|
|
|
get_v4l2_field_for_info (GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
if (!GST_VIDEO_INFO_IS_INTERLACED (info))
|
|
|
|
return V4L2_FIELD_NONE;
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_INTERLACE_MODE (info) ==
|
|
|
|
GST_VIDEO_INTERLACE_MODE_ALTERNATE)
|
|
|
|
return V4L2_FIELD_ALTERNATE;
|
|
|
|
|
|
|
|
switch (GST_VIDEO_INFO_FIELD_ORDER (info)) {
|
|
|
|
case GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST:
|
|
|
|
return V4L2_FIELD_INTERLACED_TB;
|
|
|
|
case GST_VIDEO_FIELD_ORDER_BOTTOM_FIELD_FIRST:
|
|
|
|
return V4L2_FIELD_INTERLACED_BT;
|
|
|
|
case GST_VIDEO_FIELD_ORDER_UNKNOWN:
|
|
|
|
default:
|
|
|
|
return V4L2_FIELD_INTERLACED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:08:59 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_video_colorimetry_matches (const GstVideoColorimetry * cinfo,
|
2021-03-23 08:59:28 +00:00
|
|
|
GstCaps * caps)
|
2018-08-09 13:08:59 +00:00
|
|
|
{
|
2021-03-23 08:59:28 +00:00
|
|
|
GstVideoInfo info;
|
2018-08-09 13:08:59 +00:00
|
|
|
static const GstVideoColorimetry ci_likely_jpeg = {
|
2018-09-11 00:20:39 +00:00
|
|
|
GST_VIDEO_COLOR_RANGE_0_255, GST_VIDEO_COLOR_MATRIX_BT601,
|
|
|
|
GST_VIDEO_TRANSFER_UNKNOWN, GST_VIDEO_COLOR_PRIMARIES_UNKNOWN
|
|
|
|
};
|
2018-08-09 13:08:59 +00:00
|
|
|
static const GstVideoColorimetry ci_jpeg = {
|
2018-09-11 00:20:39 +00:00
|
|
|
GST_VIDEO_COLOR_RANGE_0_255, GST_VIDEO_COLOR_MATRIX_BT601,
|
|
|
|
GST_VIDEO_TRANSFER_SRGB, GST_VIDEO_COLOR_PRIMARIES_BT709
|
|
|
|
};
|
2018-08-09 13:08:59 +00:00
|
|
|
|
2021-03-23 08:59:28 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
2018-08-09 13:08:59 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2021-03-26 08:26:22 +00:00
|
|
|
/* if colorimetry in caps is unknown, use the default one */
|
|
|
|
if (info.colorimetry.primaries == GST_VIDEO_COLOR_PRIMARIES_UNKNOWN)
|
|
|
|
info.colorimetry.primaries = cinfo->primaries;
|
|
|
|
if (info.colorimetry.range == GST_VIDEO_COLOR_RANGE_UNKNOWN)
|
|
|
|
info.colorimetry.range = cinfo->range;
|
|
|
|
if (info.colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_UNKNOWN)
|
|
|
|
info.colorimetry.matrix = cinfo->matrix;
|
|
|
|
if (info.colorimetry.transfer == GST_VIDEO_TRANSFER_UNKNOWN)
|
|
|
|
info.colorimetry.transfer = cinfo->transfer;
|
|
|
|
|
2021-03-23 08:59:28 +00:00
|
|
|
if (gst_video_colorimetry_is_equal (&info.colorimetry, cinfo))
|
2018-08-09 13:08:59 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Allow 1:4:0:0 (produced by jpegdec) if the device expects 1:4:7:1 */
|
2021-03-23 08:59:28 +00:00
|
|
|
if (gst_video_colorimetry_is_equal (&info.colorimetry, &ci_likely_jpeg)
|
2018-08-09 13:08:59 +00:00
|
|
|
&& gst_video_colorimetry_is_equal (cinfo, &ci_jpeg))
|
|
|
|
return TRUE;
|
|
|
|
|
2024-07-22 11:28:13 +00:00
|
|
|
/* bypass check the below GST_VIDEO_TRANSFER_ARIB_STD_B67 type,
|
|
|
|
* because kernel do not support it. GST_VIDEO_TRANSFER_ARIB_STD_B67 is cast
|
|
|
|
* to GST_VIDEO_TRANSFER_BT2020_12 type in gst_v4l2_object_get_colorspace */
|
|
|
|
if (info.colorimetry.transfer == GST_VIDEO_TRANSFER_ARIB_STD_B67) {
|
|
|
|
info.colorimetry.transfer = cinfo->transfer;
|
|
|
|
GST_WARNING
|
|
|
|
("v4l2 framework do not support GST_VIDEO_TRANSFER_ARIB_STD_B67");
|
|
|
|
|
|
|
|
if (gst_video_colorimetry_is_equal (&info.colorimetry, cinfo))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-11-21 07:35:58 +00:00
|
|
|
/* bypass check the below transfer types, because those types are cast to
|
|
|
|
* V4L2_XFER_FUNC_NONE type when try format or set format and V4L2_XFER_FUNC_NONE
|
|
|
|
* type is cast to GST_VIDEO_TRANSFER_GAMMA10 type in gst_v4l2_object_get_colorspace */
|
|
|
|
if ((info.colorimetry.transfer == GST_VIDEO_TRANSFER_GAMMA18) ||
|
|
|
|
(info.colorimetry.transfer == GST_VIDEO_TRANSFER_GAMMA20) ||
|
|
|
|
(info.colorimetry.transfer == GST_VIDEO_TRANSFER_GAMMA22) ||
|
|
|
|
(info.colorimetry.transfer == GST_VIDEO_TRANSFER_GAMMA28)) {
|
|
|
|
info.colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA10;
|
|
|
|
if (gst_video_colorimetry_is_equal (&info.colorimetry, cinfo))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:08:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-05 07:33:51 +00:00
|
|
|
static const gchar *
|
|
|
|
field_to_str (enum v4l2_field f)
|
|
|
|
{
|
|
|
|
switch (f) {
|
|
|
|
case V4L2_FIELD_ANY:
|
|
|
|
return "any";
|
|
|
|
case V4L2_FIELD_NONE:
|
|
|
|
return "none";
|
|
|
|
case V4L2_FIELD_TOP:
|
|
|
|
return "top";
|
|
|
|
case V4L2_FIELD_BOTTOM:
|
|
|
|
return "bottom";
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
return "interlaced";
|
|
|
|
case V4L2_FIELD_SEQ_TB:
|
|
|
|
return "seq-tb";
|
|
|
|
case V4L2_FIELD_SEQ_BT:
|
|
|
|
return "seq-bt";
|
|
|
|
case V4L2_FIELD_ALTERNATE:
|
|
|
|
return "alternate";
|
|
|
|
case V4L2_FIELD_INTERLACED_TB:
|
|
|
|
return "interlaced-tb";
|
|
|
|
case V4L2_FIELD_INTERLACED_BT:
|
|
|
|
return "interlaced-bt";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2023-05-05 09:01:50 +00:00
|
|
|
static guint
|
|
|
|
calculate_max_sizeimage (GstV4l2Object * v4l2object, guint pixel_bitdepth)
|
|
|
|
{
|
|
|
|
guint max_width, max_height;
|
|
|
|
guint sizeimage;
|
|
|
|
|
|
|
|
max_width = v4l2object->max_width;
|
|
|
|
max_height = v4l2object->max_height;
|
|
|
|
sizeimage = max_width * max_height * pixel_bitdepth / 8 / 2;
|
|
|
|
|
|
|
|
return MAX (ENCODED_BUFFER_MIN_SIZE, sizeimage);
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:47:55 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
|
2016-06-07 20:04:52 +00:00
|
|
|
gboolean try_only, GstV4l2Error * error)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
|
|
|
gint fd = v4l2object->video_fd;
|
2011-07-13 11:00:42 +00:00
|
|
|
struct v4l2_format format;
|
|
|
|
struct v4l2_streamparm streamparm;
|
2010-12-04 19:43:11 +00:00
|
|
|
enum v4l2_field field;
|
2011-07-12 18:03:32 +00:00
|
|
|
guint32 pixelformat;
|
|
|
|
struct v4l2_fmtdesc *fmtdesc;
|
2011-07-13 11:00:42 +00:00
|
|
|
GstVideoInfo info;
|
2014-04-15 19:07:23 +00:00
|
|
|
GstVideoAlignment align;
|
2013-12-04 21:23:18 +00:00
|
|
|
gint width, height, fps_n, fps_d;
|
2023-05-05 09:01:50 +00:00
|
|
|
guint pixel_bitdepth = 8;
|
2014-04-15 19:07:23 +00:00
|
|
|
gint n_v4l_planes;
|
2013-11-13 12:05:40 +00:00
|
|
|
gint i = 0;
|
2014-12-09 20:09:56 +00:00
|
|
|
gboolean is_mplane;
|
2014-09-29 09:49:45 +00:00
|
|
|
enum v4l2_colorspace colorspace = 0;
|
2015-06-08 23:11:41 +00:00
|
|
|
enum v4l2_quantization range = 0;
|
|
|
|
enum v4l2_ycbcr_encoding matrix = 0;
|
|
|
|
enum v4l2_xfer_func transfer = 0;
|
2017-07-20 02:09:38 +00:00
|
|
|
GstStructure *s;
|
2021-04-22 07:01:32 +00:00
|
|
|
gboolean disable_interlacing = FALSE;
|
2019-11-18 18:27:42 +00:00
|
|
|
gboolean disable_colorimetry = FALSE;
|
2017-07-20 02:09:38 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (!v4l2object->skip_try_fmt_probes ||
|
|
|
|
gst_caps_is_writable (caps), FALSE);
|
2013-11-13 12:05:40 +00:00
|
|
|
|
2013-12-04 20:09:44 +00:00
|
|
|
GST_V4L2_CHECK_OPEN (v4l2object);
|
2015-03-13 18:47:55 +00:00
|
|
|
if (!try_only)
|
|
|
|
GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
|
2013-12-04 20:09:44 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
is_mplane = V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type);
|
|
|
|
|
|
|
|
gst_video_info_init (&info);
|
|
|
|
gst_video_alignment_reset (&align);
|
2020-12-15 02:41:40 +00:00
|
|
|
v4l2object->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
|
2023-02-13 08:49:40 +00:00
|
|
|
v4l2object->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
|
2014-04-15 19:07:23 +00:00
|
|
|
|
2013-12-04 20:09:10 +00:00
|
|
|
if (!gst_v4l2_object_get_caps_info (v4l2object, caps, &fmtdesc, &info))
|
|
|
|
goto invalid_caps;
|
2011-07-12 18:03:32 +00:00
|
|
|
|
|
|
|
pixelformat = fmtdesc->pixelformat;
|
2011-07-13 11:00:42 +00:00
|
|
|
width = GST_VIDEO_INFO_WIDTH (&info);
|
2020-01-30 06:39:12 +00:00
|
|
|
height = GST_VIDEO_INFO_FIELD_HEIGHT (&info);
|
2022-05-10 08:20:46 +00:00
|
|
|
/* if caps has no width and height info, use default value */
|
|
|
|
if (V4L2_TYPE_IS_OUTPUT (v4l2object->type) && width == 0 && height == 0) {
|
|
|
|
width = GST_V4L2_DEFAULT_WIDTH;
|
|
|
|
height = GST_V4L2_DEFAULT_HEIGHT;
|
|
|
|
}
|
2011-07-13 11:00:42 +00:00
|
|
|
fps_n = GST_VIDEO_INFO_FPS_N (&info);
|
|
|
|
fps_d = GST_VIDEO_INFO_FPS_D (&info);
|
2010-12-04 19:43:11 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
/* if encoded format (GST_VIDEO_INFO_N_PLANES return 0)
|
2019-09-02 12:27:35 +00:00
|
|
|
* or if contiguous is preferred */
|
2014-04-15 19:07:23 +00:00
|
|
|
n_v4l_planes = GST_VIDEO_INFO_N_PLANES (&info);
|
|
|
|
if (!n_v4l_planes || !v4l2object->prefered_non_contiguous)
|
|
|
|
n_v4l_planes = 1;
|
2013-11-13 12:05:40 +00:00
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
field = get_v4l2_field_for_info (&info);
|
|
|
|
if (field != V4L2_FIELD_NONE)
|
2023-04-15 03:38:34 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "interlaced video");
|
2018-08-08 07:27:19 +00:00
|
|
|
else
|
2023-04-15 03:38:34 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "progressive video");
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2018-08-09 13:12:57 +00:00
|
|
|
/* We first pick the main colorspace from the primaries */
|
2018-04-08 17:43:56 +00:00
|
|
|
switch (info.colorimetry.primaries) {
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_BT709:
|
2024-07-29 18:39:06 +00:00
|
|
|
/* There is three colorspaces using these primaries, use the range
|
|
|
|
* and format type to differentiate them */
|
|
|
|
if (info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) {
|
|
|
|
if (GST_VIDEO_INFO_IS_RGB (&info))
|
|
|
|
colorspace = V4L2_COLORSPACE_SRGB;
|
|
|
|
else
|
|
|
|
colorspace = V4L2_COLORSPACE_REC709;
|
|
|
|
} else {
|
|
|
|
colorspace = V4L2_COLORSPACE_JPEG;
|
|
|
|
}
|
2018-04-08 17:43:56 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_BT2020:
|
|
|
|
colorspace = V4L2_COLORSPACE_BT2020;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_BT470M:
|
|
|
|
colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
|
|
|
|
colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
|
|
|
|
colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
|
|
|
|
colorspace = V4L2_COLORSPACE_SMPTE240M;
|
|
|
|
break;
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_FILM:
|
|
|
|
case GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:
|
|
|
|
/* We don't know, we will guess */
|
|
|
|
break;
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Unknown colorimetry primaries %d", info.colorimetry.primaries);
|
|
|
|
break;
|
|
|
|
}
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
switch (info.colorimetry.range) {
|
|
|
|
case GST_VIDEO_COLOR_RANGE_0_255:
|
|
|
|
range = V4L2_QUANTIZATION_FULL_RANGE;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_RANGE_16_235:
|
|
|
|
range = V4L2_QUANTIZATION_LIM_RANGE;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_RANGE_UNKNOWN:
|
|
|
|
/* We let the driver pick a default one */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Unknown colorimetry range %d", info.colorimetry.range);
|
|
|
|
break;
|
|
|
|
}
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
switch (info.colorimetry.matrix) {
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_RGB:
|
2023-02-13 08:49:40 +00:00
|
|
|
/* save the matrix so we can restore it on get() call from default */
|
|
|
|
v4l2object->matrix = GST_VIDEO_COLOR_MATRIX_RGB;
|
2018-04-08 17:43:56 +00:00
|
|
|
/* Unspecified, leave to default */
|
|
|
|
break;
|
|
|
|
/* FCC is about the same as BT601 with less digit */
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_FCC:
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_BT601:
|
|
|
|
matrix = V4L2_YCBCR_ENC_601;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_BT709:
|
|
|
|
matrix = V4L2_YCBCR_ENC_709;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
|
|
|
|
matrix = V4L2_YCBCR_ENC_SMPTE240M;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_BT2020:
|
|
|
|
matrix = V4L2_YCBCR_ENC_BT2020;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
|
|
|
|
/* We let the driver pick a default one */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Unknown colorimetry matrix %d", info.colorimetry.matrix);
|
|
|
|
break;
|
|
|
|
}
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
switch (info.colorimetry.transfer) {
|
|
|
|
case GST_VIDEO_TRANSFER_GAMMA18:
|
|
|
|
case GST_VIDEO_TRANSFER_GAMMA20:
|
|
|
|
case GST_VIDEO_TRANSFER_GAMMA22:
|
|
|
|
case GST_VIDEO_TRANSFER_GAMMA28:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"GAMMA 18, 20, 22, 28 transfer functions not supported");
|
|
|
|
/* fallthrough */
|
|
|
|
case GST_VIDEO_TRANSFER_GAMMA10:
|
|
|
|
transfer = V4L2_XFER_FUNC_NONE;
|
|
|
|
break;
|
2021-03-19 02:52:26 +00:00
|
|
|
case GST_VIDEO_TRANSFER_SMPTE2084:
|
|
|
|
transfer = V4L2_XFER_FUNC_SMPTE2084;
|
|
|
|
break;
|
2021-01-18 14:54:43 +00:00
|
|
|
case GST_VIDEO_TRANSFER_BT601:
|
2018-04-08 17:43:56 +00:00
|
|
|
case GST_VIDEO_TRANSFER_BT2020_12:
|
2020-12-15 02:41:40 +00:00
|
|
|
case GST_VIDEO_TRANSFER_BT2020_10:
|
2018-04-08 17:43:56 +00:00
|
|
|
case GST_VIDEO_TRANSFER_BT709:
|
2020-12-15 02:41:40 +00:00
|
|
|
v4l2object->transfer = info.colorimetry.transfer;
|
2018-04-08 17:43:56 +00:00
|
|
|
transfer = V4L2_XFER_FUNC_709;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_TRANSFER_SMPTE240M:
|
|
|
|
transfer = V4L2_XFER_FUNC_SMPTE240M;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_TRANSFER_SRGB:
|
|
|
|
transfer = V4L2_XFER_FUNC_SRGB;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_TRANSFER_LOG100:
|
|
|
|
case GST_VIDEO_TRANSFER_LOG316:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"LOG 100, 316 transfer functions not supported");
|
|
|
|
/* FIXME No known sensible default, maybe AdobeRGB ? */
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_TRANSFER_UNKNOWN:
|
|
|
|
/* We let the driver pick a default one */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2019-09-02 12:27:35 +00:00
|
|
|
"Unknown colorimetry transfer %d", info.colorimetry.transfer);
|
2018-04-08 17:43:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-08 23:11:41 +00:00
|
|
|
|
2018-04-08 17:43:56 +00:00
|
|
|
if (colorspace == 0) {
|
|
|
|
/* Try to guess colorspace according to pixelformat and size */
|
|
|
|
if (GST_VIDEO_INFO_IS_YUV (&info)) {
|
2018-08-09 13:08:59 +00:00
|
|
|
if (range == V4L2_QUANTIZATION_FULL_RANGE
|
|
|
|
&& matrix == V4L2_YCBCR_ENC_601 && transfer == 0) {
|
|
|
|
/* Full range BT.601 YCbCr encoding with unknown primaries and transfer
|
|
|
|
* function most likely is JPEG */
|
|
|
|
colorspace = V4L2_COLORSPACE_JPEG;
|
|
|
|
transfer = V4L2_XFER_FUNC_SRGB;
|
|
|
|
} else {
|
|
|
|
/* SD streams likely use SMPTE170M and HD streams REC709 */
|
2020-01-30 06:39:12 +00:00
|
|
|
if (width <= 720 && GST_VIDEO_INFO_HEIGHT (&info) <= 576)
|
2018-08-09 13:08:59 +00:00
|
|
|
colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
else
|
|
|
|
colorspace = V4L2_COLORSPACE_REC709;
|
|
|
|
}
|
2018-04-08 17:43:56 +00:00
|
|
|
} else if (GST_VIDEO_INFO_IS_RGB (&info)) {
|
|
|
|
colorspace = V4L2_COLORSPACE_SRGB;
|
|
|
|
transfer = V4L2_XFER_FUNC_NONE;
|
2014-09-29 09:49:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format %dx%d, format "
|
2011-07-18 16:54:49 +00:00
|
|
|
"%" GST_FOURCC_FORMAT " stride: %d", width, height,
|
2014-04-15 19:07:23 +00:00
|
|
|
GST_FOURCC_ARGS (pixelformat), GST_VIDEO_INFO_PLANE_STRIDE (&info, 0));
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2023-05-05 09:01:50 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (gst_structure_has_field (s, "bit-depth-chroma")) {
|
|
|
|
gst_structure_get_uint (s, "bit-depth-chroma", &pixel_bitdepth);
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->element, "Got pixel bit depth %u from caps",
|
|
|
|
pixel_bitdepth);
|
|
|
|
}
|
|
|
|
|
2011-07-13 11:00:42 +00:00
|
|
|
memset (&format, 0x00, sizeof (struct v4l2_format));
|
|
|
|
format.type = v4l2object->type;
|
2011-07-12 16:13:42 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
if (is_mplane) {
|
|
|
|
format.type = v4l2object->type;
|
|
|
|
format.fmt.pix_mp.pixelformat = pixelformat;
|
|
|
|
format.fmt.pix_mp.width = width;
|
|
|
|
format.fmt.pix_mp.height = height;
|
|
|
|
format.fmt.pix_mp.field = field;
|
|
|
|
format.fmt.pix_mp.num_planes = n_v4l_planes;
|
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* try to ask our preferred stride but it's not a failure if not
|
2014-03-18 19:45:18 +00:00
|
|
|
* accepted */
|
|
|
|
for (i = 0; i < n_v4l_planes; i++) {
|
|
|
|
gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, i);
|
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
|
2022-11-15 18:50:13 +00:00
|
|
|
stride = GST_VIDEO_TILE_X_TILES (stride) *
|
|
|
|
GST_VIDEO_FORMAT_INFO_TILE_STRIDE (info.finfo, i);
|
2014-03-18 19:45:18 +00:00
|
|
|
|
|
|
|
format.fmt.pix_mp.plane_fmt[i].bytesperline = stride;
|
|
|
|
}
|
2014-04-15 19:07:23 +00:00
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
|
2023-05-05 09:01:50 +00:00
|
|
|
format.fmt.pix_mp.plane_fmt[0].sizeimage =
|
|
|
|
calculate_max_sizeimage (v4l2object, pixel_bitdepth);
|
2014-04-15 19:07:23 +00:00
|
|
|
} else {
|
2014-03-18 19:45:18 +00:00
|
|
|
gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, 0);
|
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
format.type = v4l2object->type;
|
2017-12-13 20:23:46 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
format.fmt.pix.width = width;
|
|
|
|
format.fmt.pix.height = height;
|
|
|
|
format.fmt.pix.pixelformat = pixelformat;
|
|
|
|
format.fmt.pix.field = field;
|
2014-03-18 19:45:18 +00:00
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
|
2022-11-15 18:50:13 +00:00
|
|
|
stride = GST_VIDEO_TILE_X_TILES (stride) *
|
|
|
|
GST_VIDEO_FORMAT_INFO_TILE_STRIDE (info.finfo, i);
|
2014-03-18 19:45:18 +00:00
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* try to ask our preferred stride */
|
2014-03-18 19:45:18 +00:00
|
|
|
format.fmt.pix.bytesperline = stride;
|
2013-12-12 17:18:45 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
|
2023-05-05 09:01:50 +00:00
|
|
|
format.fmt.pix.sizeimage =
|
|
|
|
calculate_max_sizeimage (v4l2object, pixel_bitdepth);
|
2014-04-15 19:07:23 +00:00
|
|
|
}
|
2013-11-13 12:05:40 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format is %dx%d, format "
|
2014-03-18 19:45:18 +00:00
|
|
|
"%" GST_FOURCC_FORMAT ", nb planes %d", format.fmt.pix.width,
|
|
|
|
format.fmt.pix_mp.height,
|
|
|
|
GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
|
|
|
|
is_mplane ? format.fmt.pix_mp.num_planes : 1);
|
|
|
|
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (is_mplane) {
|
|
|
|
for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
|
2014-03-18 19:45:18 +00:00
|
|
|
format.fmt.pix_mp.plane_fmt[i].bytesperline);
|
|
|
|
} else {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
|
2014-03-18 19:45:18 +00:00
|
|
|
format.fmt.pix.bytesperline);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-27 20:57:29 +00:00
|
|
|
if (is_mplane) {
|
|
|
|
format.fmt.pix_mp.colorspace = colorspace;
|
|
|
|
format.fmt.pix_mp.quantization = range;
|
|
|
|
format.fmt.pix_mp.ycbcr_enc = matrix;
|
|
|
|
format.fmt.pix_mp.xfer_func = transfer;
|
|
|
|
} else {
|
2018-08-09 15:24:35 +00:00
|
|
|
format.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
|
2018-06-27 20:57:29 +00:00
|
|
|
format.fmt.pix.colorspace = colorspace;
|
|
|
|
format.fmt.pix.quantization = range;
|
|
|
|
format.fmt.pix.ycbcr_enc = matrix;
|
|
|
|
format.fmt.pix.xfer_func = transfer;
|
2014-09-29 09:49:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 20:57:29 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired colorspace is %d:%d:%d:%d",
|
|
|
|
colorspace, range, matrix, transfer);
|
|
|
|
|
2015-03-13 18:47:55 +00:00
|
|
|
if (try_only) {
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &format) < 0)
|
2015-03-13 18:47:55 +00:00
|
|
|
goto try_fmt_failed;
|
|
|
|
} else {
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_S_FMT, &format) < 0)
|
2015-03-13 18:47:55 +00:00
|
|
|
goto set_fmt_failed;
|
|
|
|
}
|
2013-11-13 12:05:40 +00:00
|
|
|
|
v4l2object: complete colorspace info in debug log
The desired colorimetry is logged with all parameters (colorpsace,
range, matrix, and transfer function), but of the values actually
set by the driver, only colorspace is logged. Complete the debug
log message to display all colorimetry parameters:
Desired colorspace is 8:1:1:1
Got format of 640x480, format YU12, nb planes 1, colorspace 8
->
Desired colorspace is 8:1:1:1
Got format of 640x480, format YU12, nb planes 1, colorspace 8:0:0:0
https://bugzilla.gnome.org/show_bug.cgi?id=796940
2018-08-09 13:14:05 +00:00
|
|
|
if (is_mplane) {
|
|
|
|
colorspace = format.fmt.pix_mp.colorspace;
|
|
|
|
range = format.fmt.pix_mp.quantization;
|
|
|
|
matrix = format.fmt.pix_mp.ycbcr_enc;
|
|
|
|
transfer = format.fmt.pix_mp.xfer_func;
|
|
|
|
} else {
|
|
|
|
colorspace = format.fmt.pix.colorspace;
|
|
|
|
range = format.fmt.pix.quantization;
|
|
|
|
matrix = format.fmt.pix.ycbcr_enc;
|
|
|
|
transfer = format.fmt.pix.xfer_func;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got format of %dx%d, format "
|
2020-02-05 07:33:51 +00:00
|
|
|
"%" GST_FOURCC_FORMAT ", nb planes %d, colorspace %d:%d:%d:%d field: %s",
|
2014-09-29 09:49:45 +00:00
|
|
|
format.fmt.pix.width, format.fmt.pix_mp.height,
|
2014-04-15 19:07:23 +00:00
|
|
|
GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
|
2014-09-29 09:49:45 +00:00
|
|
|
is_mplane ? format.fmt.pix_mp.num_planes : 1,
|
2020-02-05 07:33:51 +00:00
|
|
|
colorspace, range, matrix, transfer, field_to_str (format.fmt.pix.field));
|
2013-11-13 12:05:40 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (is_mplane) {
|
|
|
|
for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
|
2014-03-18 19:45:18 +00:00
|
|
|
format.fmt.pix_mp.plane_fmt[i].bytesperline,
|
|
|
|
format.fmt.pix_mp.plane_fmt[i].sizeimage);
|
|
|
|
} else {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
|
2014-03-18 19:45:18 +00:00
|
|
|
format.fmt.pix.bytesperline, format.fmt.pix.sizeimage);
|
2013-11-13 12:05:40 +00:00
|
|
|
}
|
2014-04-15 19:07:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (format.fmt.pix.pixelformat != pixelformat)
|
|
|
|
goto invalid_pixelformat;
|
|
|
|
|
2023-04-12 08:22:17 +00:00
|
|
|
/* Passing HDR10 information
|
|
|
|
*
|
2023-09-05 20:56:44 +00:00
|
|
|
* TODO:
|
2023-08-22 01:28:47 +00:00
|
|
|
* - Missing capture (v4l2src) HDR10 configuration and/or reporting
|
|
|
|
* - The API is not capable of HDR to HDR conversion as controls are not specific to queues
|
2023-04-12 08:22:17 +00:00
|
|
|
*/
|
|
|
|
if (V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
|
|
|
|
GstVideoMasteringDisplayInfo video_master_display_info;
|
|
|
|
GstVideoContentLightLevel video_content_light_level;
|
|
|
|
struct v4l2_ext_control ext_control[2];
|
|
|
|
struct v4l2_ctrl_hdr10_mastering_display hdr10_mastering_display;
|
|
|
|
struct v4l2_ctrl_hdr10_cll_info hdr10_cll_info;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Passing HDR10 medata");
|
|
|
|
memset (&hdr10_cll_info, 0, sizeof (struct v4l2_ctrl_hdr10_cll_info));
|
|
|
|
memset (&hdr10_mastering_display,
|
|
|
|
0, sizeof (struct v4l2_ctrl_hdr10_mastering_display));
|
|
|
|
|
|
|
|
if (gst_video_mastering_display_info_from_caps (&video_master_display_info,
|
|
|
|
caps)) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"video mastering display info: %d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
|
|
|
|
video_master_display_info.display_primaries[0].x,
|
|
|
|
video_master_display_info.display_primaries[0].y,
|
|
|
|
video_master_display_info.display_primaries[1].x,
|
|
|
|
video_master_display_info.display_primaries[1].y,
|
|
|
|
video_master_display_info.display_primaries[2].x,
|
|
|
|
video_master_display_info.display_primaries[2].y,
|
|
|
|
video_master_display_info.white_point.x,
|
|
|
|
video_master_display_info.white_point.y,
|
|
|
|
video_master_display_info.max_display_mastering_luminance,
|
|
|
|
video_master_display_info.min_display_mastering_luminance);
|
|
|
|
|
|
|
|
hdr10_mastering_display.display_primaries_x[2] =
|
|
|
|
video_master_display_info.display_primaries[0].x;
|
|
|
|
hdr10_mastering_display.display_primaries_y[2] =
|
|
|
|
video_master_display_info.display_primaries[0].y;
|
|
|
|
hdr10_mastering_display.display_primaries_x[0] =
|
|
|
|
video_master_display_info.display_primaries[1].x;
|
|
|
|
hdr10_mastering_display.display_primaries_y[0] =
|
|
|
|
video_master_display_info.display_primaries[1].y;
|
|
|
|
hdr10_mastering_display.display_primaries_x[1] =
|
|
|
|
video_master_display_info.display_primaries[2].x;
|
|
|
|
hdr10_mastering_display.display_primaries_y[1] =
|
|
|
|
video_master_display_info.display_primaries[2].y;
|
|
|
|
hdr10_mastering_display.white_point_x =
|
|
|
|
video_master_display_info.white_point.x;
|
|
|
|
hdr10_mastering_display.white_point_y =
|
|
|
|
video_master_display_info.white_point.y;
|
|
|
|
hdr10_mastering_display.min_display_mastering_luminance =
|
|
|
|
video_master_display_info.min_display_mastering_luminance;
|
|
|
|
hdr10_mastering_display.max_display_mastering_luminance =
|
|
|
|
video_master_display_info.max_display_mastering_luminance;
|
|
|
|
|
|
|
|
ext_control[count].id = V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY;
|
|
|
|
ext_control[count].size =
|
|
|
|
sizeof (struct v4l2_ctrl_hdr10_mastering_display);
|
|
|
|
ext_control[count].ptr = &hdr10_mastering_display;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_video_content_light_level_from_caps (&video_content_light_level,
|
|
|
|
caps)) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "video content light level: %d:%d",
|
|
|
|
video_content_light_level.max_content_light_level,
|
|
|
|
video_content_light_level.max_frame_average_light_level);
|
|
|
|
|
|
|
|
hdr10_cll_info.max_content_light_level =
|
|
|
|
video_content_light_level.max_content_light_level;
|
|
|
|
hdr10_cll_info.max_pic_average_light_level =
|
|
|
|
video_content_light_level.max_frame_average_light_level;
|
|
|
|
|
|
|
|
ext_control[count].id = V4L2_CID_COLORIMETRY_HDR10_CLL_INFO;
|
|
|
|
ext_control[count].size = sizeof (struct v4l2_ctrl_hdr10_cll_info);
|
|
|
|
ext_control[count].ptr = &hdr10_cll_info;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
struct v4l2_ext_controls ext_controls = {
|
|
|
|
.ctrl_class = V4L2_CTRL_CLASS_COLORIMETRY,
|
|
|
|
.count = count,
|
|
|
|
.controls = ext_control,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_S_EXT_CTRLS, &ext_controls) < 0) {
|
|
|
|
if (errno != ENOTTY) {
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Failed to set HDR10 metadata, err: %s", g_strerror (errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
/* Only negotiate size with raw data.
|
|
|
|
* For some codecs the dimensions are *not* in the bitstream, IIRC VC1
|
|
|
|
* in ASF mode for example, there is also not reason for a driver to
|
|
|
|
* change the size. */
|
|
|
|
if (info.finfo->format != GST_VIDEO_FORMAT_ENCODED) {
|
|
|
|
/* We can crop larger images */
|
|
|
|
if (format.fmt.pix.width < width || format.fmt.pix.height < height)
|
|
|
|
goto invalid_dimensions;
|
|
|
|
|
|
|
|
/* Note, this will be adjusted if upstream has non-centered cropping. */
|
|
|
|
align.padding_top = 0;
|
|
|
|
align.padding_bottom = format.fmt.pix.height - height;
|
|
|
|
align.padding_left = 0;
|
|
|
|
align.padding_right = format.fmt.pix.width - width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_mplane && format.fmt.pix_mp.num_planes != n_v4l_planes)
|
|
|
|
goto invalid_planes;
|
2011-07-26 14:15:05 +00:00
|
|
|
|
2018-10-19 02:23:31 +00:00
|
|
|
/* used to check colorimetry and interlace mode fields presence */
|
2021-04-22 07:01:32 +00:00
|
|
|
if (gst_v4l2_object_get_interlace_mode (format.fmt.pix.field,
|
|
|
|
&info.interlace_mode)) {
|
|
|
|
if (gst_structure_has_field (s, "interlace-mode")) {
|
|
|
|
if (format.fmt.pix.field != field)
|
|
|
|
goto invalid_field;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* The driver (or libv4l2) is miss-behaving, just ignore interlace-mode from
|
|
|
|
* the TRY_FMT */
|
|
|
|
disable_interlacing = TRUE;
|
|
|
|
if (gst_structure_has_field (s, "interlace-mode"))
|
|
|
|
gst_structure_remove_field (s, "interlace-mode");
|
2018-10-19 02:23:31 +00:00
|
|
|
}
|
2017-07-20 01:56:14 +00:00
|
|
|
|
2020-12-15 02:41:40 +00:00
|
|
|
if (gst_v4l2_object_get_colorspace (v4l2object, &format, &info.colorimetry)) {
|
2019-11-18 18:27:42 +00:00
|
|
|
if (gst_structure_has_field (s, "colorimetry")) {
|
2021-03-23 08:59:28 +00:00
|
|
|
if (!gst_v4l2_video_colorimetry_matches (&info.colorimetry, caps))
|
2019-11-18 18:27:42 +00:00
|
|
|
goto invalid_colorimetry;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* The driver (or libv4l2) is miss-behaving, just ignore colorimetry from
|
|
|
|
* the TRY_FMT */
|
|
|
|
disable_colorimetry = TRUE;
|
|
|
|
if (gst_structure_has_field (s, "colorimetry"))
|
|
|
|
gst_structure_remove_field (s, "colorimetry");
|
2017-07-22 03:34:59 +00:00
|
|
|
}
|
2017-07-20 02:01:26 +00:00
|
|
|
|
2017-07-20 02:09:38 +00:00
|
|
|
/* In case we have skipped the try_fmt probes, we'll need to set the
|
2021-04-22 07:01:32 +00:00
|
|
|
* interlace-mode and colorimetry back into the caps. */
|
2017-07-20 02:09:38 +00:00
|
|
|
if (v4l2object->skip_try_fmt_probes) {
|
2021-04-22 07:01:32 +00:00
|
|
|
if (!disable_interlacing && !gst_structure_has_field (s, "interlace-mode")) {
|
|
|
|
gst_structure_set (s, "interlace-mode", G_TYPE_STRING,
|
|
|
|
gst_video_interlace_mode_to_string (info.interlace_mode), NULL);
|
|
|
|
}
|
2019-11-18 18:27:42 +00:00
|
|
|
if (!disable_colorimetry && !gst_structure_has_field (s, "colorimetry")) {
|
2017-07-20 02:09:38 +00:00
|
|
|
gchar *str = gst_video_colorimetry_to_string (&info.colorimetry);
|
|
|
|
gst_structure_set (s, "colorimetry", G_TYPE_STRING, str, NULL);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:47:55 +00:00
|
|
|
if (try_only) /* good enough for trying only */
|
|
|
|
return TRUE;
|
|
|
|
|
2014-03-19 21:00:56 +00:00
|
|
|
if (GST_VIDEO_INFO_HAS_ALPHA (&info)) {
|
|
|
|
struct v4l2_control ctl = { 0, };
|
|
|
|
ctl.id = V4L2_CID_ALPHA_COMPONENT;
|
|
|
|
ctl.value = 0xff;
|
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_S_CTRL, &ctl) < 0)
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2014-03-19 21:00:56 +00:00
|
|
|
"Failed to set alpha component value");
|
|
|
|
}
|
|
|
|
|
2011-07-13 09:19:28 +00:00
|
|
|
/* Is there a reason we require the caller to always specify a framerate? */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired framerate: %u/%u", fps_n,
|
2011-07-13 09:19:28 +00:00
|
|
|
fps_d);
|
|
|
|
|
2011-07-13 11:00:42 +00:00
|
|
|
memset (&streamparm, 0x00, sizeof (struct v4l2_streamparm));
|
|
|
|
streamparm.type = v4l2object->type;
|
2011-07-13 09:19:28 +00:00
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_G_PARM, &streamparm) < 0)
|
2011-07-13 09:19:28 +00:00
|
|
|
goto get_parm_failed;
|
|
|
|
|
2013-11-13 12:05:40 +00:00
|
|
|
if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|
|
|
|
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
|
2016-03-16 15:22:48 +00:00
|
|
|
GST_VIDEO_INFO_FPS_N (&info) =
|
|
|
|
streamparm.parm.capture.timeperframe.denominator;
|
|
|
|
GST_VIDEO_INFO_FPS_D (&info) =
|
|
|
|
streamparm.parm.capture.timeperframe.numerator;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got capture framerate: %u/%u",
|
2011-07-13 11:00:42 +00:00
|
|
|
streamparm.parm.capture.timeperframe.denominator,
|
|
|
|
streamparm.parm.capture.timeperframe.numerator);
|
2011-07-13 09:29:26 +00:00
|
|
|
|
2011-08-29 11:43:59 +00:00
|
|
|
/* We used to skip frame rate setup if the camera was already setup
|
|
|
|
* with the requested frame rate. This breaks some cameras though,
|
|
|
|
* causing them to not output data (several models of Thinkpad cameras
|
|
|
|
* have this problem at least).
|
|
|
|
* So, don't skip. */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting capture framerate to %u/%u",
|
2016-03-16 15:22:48 +00:00
|
|
|
fps_n, fps_d);
|
2011-08-29 11:43:59 +00:00
|
|
|
/* We want to change the frame rate, so check whether we can. Some cheap USB
|
|
|
|
* cameras don't have the capability */
|
|
|
|
if ((streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2016-03-16 15:22:48 +00:00
|
|
|
"Not setting capture framerate (not supported)");
|
2011-08-29 11:43:59 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2011-07-12 15:46:21 +00:00
|
|
|
|
2024-08-13 20:38:37 +00:00
|
|
|
/* Variable framerate is not a V4L2 concept, simply default to 30fps */
|
|
|
|
if (fps_n == 0 && fps_d == 1) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Variable framerate not supported, assuming 30fps");
|
|
|
|
streamparm.parm.capture.timeperframe.numerator = 1;
|
|
|
|
streamparm.parm.capture.timeperframe.denominator = 30;
|
|
|
|
} else {
|
|
|
|
/* Note: V4L2 wants the frame interval, we have the frame rate */
|
|
|
|
streamparm.parm.capture.timeperframe.numerator = fps_d;
|
|
|
|
streamparm.parm.capture.timeperframe.denominator = fps_n;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2011-08-29 11:43:59 +00:00
|
|
|
/* some cheap USB cam's won't accept any change */
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
|
2011-08-29 11:43:59 +00:00
|
|
|
goto set_parm_failed;
|
2011-07-12 15:46:21 +00:00
|
|
|
|
2024-08-13 20:38:37 +00:00
|
|
|
if (fps_n == 0 && fps_d == 1) {
|
|
|
|
/* just keep reporting variable framerate */
|
|
|
|
} else if (streamparm.parm.capture.timeperframe.numerator > 0 &&
|
2015-03-13 18:47:55 +00:00
|
|
|
streamparm.parm.capture.timeperframe.denominator > 0) {
|
2014-11-14 11:59:31 +00:00
|
|
|
/* get new values */
|
|
|
|
fps_d = streamparm.parm.capture.timeperframe.numerator;
|
|
|
|
fps_n = streamparm.parm.capture.timeperframe.denominator;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj, "Set capture framerate to %u/%u",
|
2016-03-16 15:22:48 +00:00
|
|
|
fps_n, fps_d);
|
2014-11-14 11:59:31 +00:00
|
|
|
} else {
|
|
|
|
/* fix v4l2 capture driver to provide framerate values */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2015-03-13 18:47:55 +00:00
|
|
|
"Reuse caps framerate %u/%u - fix v4l2 capture driver", fps_n, fps_d);
|
2014-11-14 11:59:31 +00:00
|
|
|
}
|
2011-07-13 11:00:42 +00:00
|
|
|
|
2016-03-16 15:22:48 +00:00
|
|
|
GST_VIDEO_INFO_FPS_N (&info) = fps_n;
|
|
|
|
GST_VIDEO_INFO_FPS_D (&info) = fps_d;
|
|
|
|
} else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
|
|
|
|
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
|
|
|
GST_VIDEO_INFO_FPS_N (&info) =
|
|
|
|
streamparm.parm.output.timeperframe.denominator;
|
|
|
|
GST_VIDEO_INFO_FPS_D (&info) =
|
|
|
|
streamparm.parm.output.timeperframe.numerator;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got output framerate: %u/%u",
|
2016-03-16 15:22:48 +00:00
|
|
|
streamparm.parm.output.timeperframe.denominator,
|
|
|
|
streamparm.parm.output.timeperframe.numerator);
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting output framerate to %u/%u",
|
2016-03-16 15:22:48 +00:00
|
|
|
fps_n, fps_d);
|
|
|
|
if ((streamparm.parm.output.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2016-03-16 15:22:48 +00:00
|
|
|
"Not setting output framerate (not supported)");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2024-08-13 20:38:37 +00:00
|
|
|
/* Variable framerate is not a V4L2 concept, simply default to 30fps */
|
|
|
|
if (fps_n == 0 && fps_d == 1) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Variable framerate not supported, assuming 30fps");
|
|
|
|
streamparm.parm.output.timeperframe.numerator = 1;
|
|
|
|
streamparm.parm.output.timeperframe.denominator = 30;
|
|
|
|
} else {
|
|
|
|
/* Note: V4L2 wants the frame interval, we have the frame rate */
|
|
|
|
streamparm.parm.output.timeperframe.numerator = fps_d;
|
|
|
|
streamparm.parm.output.timeperframe.denominator = fps_n;
|
|
|
|
}
|
2016-03-16 15:22:48 +00:00
|
|
|
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
|
2016-03-16 15:22:48 +00:00
|
|
|
goto set_parm_failed;
|
|
|
|
|
2024-08-13 20:38:37 +00:00
|
|
|
if (fps_n == 0 && fps_d == 1) {
|
|
|
|
/* just keep reporting variable framerate */
|
|
|
|
} else if (streamparm.parm.output.timeperframe.numerator > 0 &&
|
2016-03-16 15:22:48 +00:00
|
|
|
streamparm.parm.output.timeperframe.denominator > 0) {
|
|
|
|
/* get new values */
|
|
|
|
fps_d = streamparm.parm.output.timeperframe.numerator;
|
|
|
|
fps_n = streamparm.parm.output.timeperframe.denominator;
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj, "Set output framerate to %u/%u",
|
2016-03-16 15:22:48 +00:00
|
|
|
fps_n, fps_d);
|
|
|
|
} else {
|
|
|
|
/* fix v4l2 output driver to provide framerate values */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
2016-03-16 15:22:48 +00:00
|
|
|
"Reuse caps framerate %u/%u - fix v4l2 output driver", fps_n, fps_d);
|
|
|
|
}
|
|
|
|
|
2011-08-29 11:43:59 +00:00
|
|
|
GST_VIDEO_INFO_FPS_N (&info) = fps_n;
|
|
|
|
GST_VIDEO_INFO_FPS_D (&info) = fps_d;
|
2011-07-13 09:19:28 +00:00
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2011-07-13 09:19:28 +00:00
|
|
|
done:
|
2014-05-06 16:58:59 +00:00
|
|
|
/* add boolean return, so we can fail on drivers bugs */
|
2014-04-15 19:07:23 +00:00
|
|
|
gst_v4l2_object_save_format (v4l2object, fmtdesc, &format, &info, &align);
|
2009-08-04 07:14:20 +00:00
|
|
|
|
2021-10-15 06:32:22 +00:00
|
|
|
/* reset composition region to match the S_FMT size */
|
|
|
|
gst_v4l2_object_reset_compose_region (v4l2object);
|
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
/* now configure the pool */
|
2011-07-15 15:26:06 +00:00
|
|
|
if (!gst_v4l2_object_setup_pool (v4l2object, caps))
|
2011-07-13 14:33:58 +00:00
|
|
|
goto pool_failed;
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2011-07-12 18:03:32 +00:00
|
|
|
invalid_caps:
|
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "can't parse caps %" GST_PTR_FORMAT,
|
2011-07-12 18:03:32 +00:00
|
|
|
caps);
|
2020-02-05 06:30:00 +00:00
|
|
|
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Invalid caps")), ("Can't parse caps %" GST_PTR_FORMAT, caps));
|
2011-07-12 18:03:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-03-13 18:47:55 +00:00
|
|
|
try_fmt_failed:
|
|
|
|
{
|
2017-07-20 02:03:29 +00:00
|
|
|
if (errno == EINVAL) {
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' has no supported format"), v4l2object->videodev),
|
|
|
|
("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height,
|
|
|
|
g_strerror (errno)));
|
|
|
|
} else {
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, FAILED,
|
|
|
|
(_("Device '%s' failed during initialization"),
|
|
|
|
v4l2object->videodev),
|
2015-03-13 18:47:55 +00:00
|
|
|
("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height,
|
|
|
|
g_strerror (errno)));
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
set_fmt_failed:
|
|
|
|
{
|
2011-09-08 11:28:24 +00:00
|
|
|
if (errno == EBUSY) {
|
2016-06-07 20:04:52 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, BUSY,
|
2011-09-08 11:28:24 +00:00
|
|
|
(_("Device '%s' is busy"), v4l2object->videodev),
|
|
|
|
("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height,
|
|
|
|
g_strerror (errno)));
|
2017-07-20 02:03:29 +00:00
|
|
|
} else if (errno == EINVAL) {
|
2016-06-07 20:04:52 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
2017-07-20 02:03:29 +00:00
|
|
|
(_("Device '%s' has no supported format"), v4l2object->videodev),
|
|
|
|
("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height,
|
|
|
|
g_strerror (errno)));
|
|
|
|
} else {
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, FAILED,
|
|
|
|
(_("Device '%s' failed during initialization"),
|
|
|
|
v4l2object->videodev),
|
2011-09-08 11:28:24 +00:00
|
|
|
("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
|
|
|
|
GST_FOURCC_ARGS (pixelformat), width, height,
|
|
|
|
g_strerror (errno)));
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_dimensions:
|
|
|
|
{
|
2017-07-20 02:07:32 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' cannot capture at %dx%d"),
|
|
|
|
v4l2object->videodev, width, height),
|
|
|
|
("Tried to capture at %dx%d, but device returned size %dx%d",
|
|
|
|
width, height, format.fmt.pix.width, format.fmt.pix.height));
|
2009-08-04 07:14:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_pixelformat:
|
|
|
|
{
|
2017-07-20 02:07:32 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' cannot capture in the specified format"),
|
|
|
|
v4l2object->videodev),
|
|
|
|
("Tried to capture in %" GST_FOURCC_FORMAT
|
|
|
|
", but device returned format" " %" GST_FOURCC_FORMAT,
|
|
|
|
GST_FOURCC_ARGS (pixelformat),
|
|
|
|
GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
|
2009-08-04 07:14:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-13 12:05:40 +00:00
|
|
|
invalid_planes:
|
|
|
|
{
|
2017-07-20 02:07:32 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' does support non-contiguous planes"),
|
|
|
|
v4l2object->videodev),
|
|
|
|
("Device wants %d planes", format.fmt.pix_mp.num_planes));
|
2013-11-13 12:05:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-20 01:56:14 +00:00
|
|
|
invalid_field:
|
|
|
|
{
|
|
|
|
enum v4l2_field wanted_field;
|
|
|
|
|
|
|
|
if (is_mplane)
|
|
|
|
wanted_field = format.fmt.pix_mp.field;
|
|
|
|
else
|
|
|
|
wanted_field = format.fmt.pix.field;
|
|
|
|
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' does not support %s interlacing"),
|
|
|
|
v4l2object->videodev,
|
|
|
|
field == V4L2_FIELD_NONE ? "progressive" : "interleaved"),
|
|
|
|
("Device wants %s interlacing",
|
|
|
|
wanted_field == V4L2_FIELD_NONE ? "progressive" : "interleaved"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-20 02:01:26 +00:00
|
|
|
invalid_colorimetry:
|
|
|
|
{
|
|
|
|
gchar *wanted_colorimetry;
|
|
|
|
|
|
|
|
wanted_colorimetry = gst_video_colorimetry_to_string (&info.colorimetry);
|
|
|
|
|
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
|
|
|
(_("Device '%s' does not support %s colorimetry"),
|
|
|
|
v4l2object->videodev, gst_structure_get_string (s, "colorimetry")),
|
|
|
|
("Device wants %s colorimetry", wanted_colorimetry));
|
|
|
|
|
|
|
|
g_free (wanted_colorimetry);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-13 09:19:28 +00:00
|
|
|
get_parm_failed:
|
|
|
|
{
|
2011-07-13 09:36:54 +00:00
|
|
|
/* it's possible that this call is not supported */
|
2012-07-05 16:02:27 +00:00
|
|
|
if (errno != EINVAL && errno != ENOTTY) {
|
2016-06-07 20:04:52 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
2011-07-13 09:36:54 +00:00
|
|
|
(_("Could not get parameters on device '%s'"),
|
|
|
|
v4l2object->videodev), GST_ERROR_SYSTEM);
|
|
|
|
}
|
2011-07-13 09:19:28 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
set_parm_failed:
|
|
|
|
{
|
2016-06-07 20:04:52 +00:00
|
|
|
GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
|
2011-07-13 14:33:58 +00:00
|
|
|
(_("Video device did not accept new frame rate setting.")),
|
2011-07-13 09:19:28 +00:00
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
goto done;
|
|
|
|
}
|
2011-07-13 14:33:58 +00:00
|
|
|
pool_failed:
|
|
|
|
{
|
2014-04-08 22:18:57 +00:00
|
|
|
/* setup_pool already send the error */
|
2011-07-13 14:33:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 18:47:55 +00:00
|
|
|
gboolean
|
2016-06-07 20:04:52 +00:00
|
|
|
gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps,
|
|
|
|
GstV4l2Error * error)
|
2015-03-13 18:47:55 +00:00
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Setting format to %" GST_PTR_FORMAT,
|
2017-07-20 02:05:49 +00:00
|
|
|
caps);
|
2016-06-07 20:04:52 +00:00
|
|
|
return gst_v4l2_object_set_format_full (v4l2object, caps, FALSE, error);
|
2015-03-13 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-06-07 20:04:52 +00:00
|
|
|
gst_v4l2_object_try_format (GstV4l2Object * v4l2object, GstCaps * caps,
|
|
|
|
GstV4l2Error * error)
|
2015-03-13 18:47:55 +00:00
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Trying format %" GST_PTR_FORMAT,
|
2017-07-20 02:05:49 +00:00
|
|
|
caps);
|
2016-06-07 20:04:52 +00:00
|
|
|
return gst_v4l2_object_set_format_full (v4l2object, caps, TRUE, error);
|
2015-03-13 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 18:51:13 +00:00
|
|
|
/**
|
2014-03-13 18:24:51 +00:00
|
|
|
* gst_v4l2_object_acquire_format:
|
2019-04-23 16:28:23 +00:00
|
|
|
* @v4l2object: the object
|
|
|
|
* @info: a GstVideoInfo to be filled
|
2013-12-05 18:51:13 +00:00
|
|
|
*
|
2019-09-02 12:27:35 +00:00
|
|
|
* Acquire the driver chosen format. This is useful in decoder or encoder elements where
|
|
|
|
* the output format is chosen by the HW.
|
2013-12-05 18:51:13 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE on failure.
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-04-15 19:07:23 +00:00
|
|
|
gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info)
|
2013-12-05 18:51:13 +00:00
|
|
|
{
|
|
|
|
struct v4l2_fmtdesc *fmtdesc;
|
|
|
|
struct v4l2_format fmt;
|
|
|
|
struct v4l2_crop crop;
|
2016-05-13 12:45:02 +00:00
|
|
|
struct v4l2_selection sel;
|
|
|
|
struct v4l2_rect *r = NULL;
|
2013-12-05 18:51:13 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
guint width, height;
|
2014-04-15 19:07:23 +00:00
|
|
|
GstVideoAlignment align;
|
2018-08-08 07:27:19 +00:00
|
|
|
GstVideoInterlaceMode interlace_mode;
|
2013-12-05 18:51:13 +00:00
|
|
|
|
|
|
|
gst_video_info_init (info);
|
2014-04-15 19:07:23 +00:00
|
|
|
gst_video_alignment_reset (&align);
|
2022-05-24 08:07:13 +00:00
|
|
|
v4l2object->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
|
2023-02-13 08:49:40 +00:00
|
|
|
v4l2object->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
|
2013-12-05 18:51:13 +00:00
|
|
|
|
|
|
|
memset (&fmt, 0x00, sizeof (struct v4l2_format));
|
|
|
|
fmt.type = v4l2object->type;
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_FMT, &fmt) < 0)
|
2013-12-05 18:51:13 +00:00
|
|
|
goto get_fmt_failed;
|
|
|
|
|
|
|
|
fmtdesc = gst_v4l2_object_get_format_from_fourcc (v4l2object,
|
|
|
|
fmt.fmt.pix.pixelformat);
|
|
|
|
if (fmtdesc == NULL)
|
|
|
|
goto unsupported_format;
|
|
|
|
|
|
|
|
/* No need to care about mplane, the four first params are the same */
|
|
|
|
format = gst_v4l2_object_v4l2fourcc_to_video_format (fmt.fmt.pix.pixelformat);
|
2013-12-31 16:38:09 +00:00
|
|
|
|
|
|
|
/* fails if we do no translate the fmt.pix.pixelformat to GstVideoFormat */
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
goto unsupported_format;
|
|
|
|
|
|
|
|
if (fmt.fmt.pix.width == 0 || fmt.fmt.pix.height == 0)
|
|
|
|
goto invalid_dimensions;
|
|
|
|
|
2013-12-05 18:51:13 +00:00
|
|
|
width = fmt.fmt.pix.width;
|
|
|
|
height = fmt.fmt.pix.height;
|
|
|
|
|
2016-05-13 12:45:02 +00:00
|
|
|
/* Use the default compose rectangle */
|
|
|
|
memset (&sel, 0, sizeof (struct v4l2_selection));
|
|
|
|
sel.type = v4l2object->type;
|
|
|
|
sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_SELECTION, &sel) >= 0) {
|
2016-05-13 12:45:02 +00:00
|
|
|
r = &sel.r;
|
|
|
|
} else {
|
|
|
|
/* For ancient kernels, fall back to G_CROP */
|
|
|
|
memset (&crop, 0, sizeof (struct v4l2_crop));
|
|
|
|
crop.type = v4l2object->type;
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CROP, &crop) >= 0)
|
2016-05-13 12:45:02 +00:00
|
|
|
r = &crop.c;
|
|
|
|
}
|
|
|
|
if (r) {
|
|
|
|
align.padding_left = r->left;
|
|
|
|
align.padding_top = r->top;
|
|
|
|
align.padding_right = width - r->width - r->left;
|
|
|
|
align.padding_bottom = height - r->height - r->top;
|
|
|
|
width = r->width;
|
|
|
|
height = r->height;
|
2013-12-05 18:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt.fmt.pix.field) {
|
|
|
|
case V4L2_FIELD_ANY:
|
|
|
|
case V4L2_FIELD_NONE:
|
2018-08-08 07:27:19 +00:00
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
2013-12-05 18:51:13 +00:00
|
|
|
break;
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
case V4L2_FIELD_INTERLACED_TB:
|
|
|
|
case V4L2_FIELD_INTERLACED_BT:
|
2018-08-08 07:27:19 +00:00
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
|
|
|
break;
|
|
|
|
case V4L2_FIELD_ALTERNATE:
|
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_ALTERNATE;
|
2013-12-05 18:51:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unsupported_field;
|
|
|
|
}
|
|
|
|
|
2023-09-05 20:56:44 +00:00
|
|
|
if (!gst_video_info_set_interlaced_format (info, format, interlace_mode,
|
|
|
|
width, height))
|
|
|
|
goto invalid_dimensions;
|
2018-08-08 07:27:19 +00:00
|
|
|
|
2020-12-15 02:41:40 +00:00
|
|
|
gst_v4l2_object_get_colorspace (v4l2object, &fmt, &info->colorimetry);
|
2021-07-27 02:43:21 +00:00
|
|
|
gst_v4l2_object_get_streamparm (v4l2object, info);
|
2021-08-09 02:46:30 +00:00
|
|
|
if ((info->fps_n == 0 && v4l2object->info.fps_d != 0)
|
|
|
|
&& (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
|
2021-07-27 02:43:21 +00:00
|
|
|
|| v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
|
|
|
|
info->fps_d = v4l2object->info.fps_d;
|
|
|
|
info->fps_n = v4l2object->info.fps_n;
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Set capture fps to %d/%d",
|
|
|
|
info->fps_n, info->fps_d);
|
|
|
|
}
|
2016-05-13 14:39:25 +00:00
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
gst_v4l2_object_save_format (v4l2object, fmtdesc, &fmt, info, &align);
|
2013-12-05 18:51:13 +00:00
|
|
|
|
|
|
|
/* Shall we setup the pool ? */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
get_fmt_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
|
|
|
|
(_("Video device did not provide output format.")), GST_ERROR_SYSTEM);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-12-07 15:31:15 +00:00
|
|
|
invalid_dimensions:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
|
|
|
|
(_("Video device returned invalid dimensions.")),
|
|
|
|
("Expected non 0 dimensions, got %dx%d", fmt.fmt.pix.width,
|
|
|
|
fmt.fmt.pix.height));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-12-05 18:51:13 +00:00
|
|
|
unsupported_field:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
|
2017-02-17 23:50:32 +00:00
|
|
|
(_("Video device uses an unsupported interlacing method.")),
|
2013-12-05 18:51:13 +00:00
|
|
|
("V4L2 field type %d not supported", fmt.fmt.pix.field));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsupported_format:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
|
2017-02-17 23:50:32 +00:00
|
|
|
(_("Video device uses an unsupported pixel format.")),
|
2013-12-05 18:51:13 +00:00
|
|
|
("V4L2 format %" GST_FOURCC_FORMAT " not supported",
|
|
|
|
GST_FOURCC_ARGS (fmt.fmt.pix.pixelformat)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 08:56:56 +00:00
|
|
|
/**
|
|
|
|
* gst_v4l2_object_set_crop:
|
|
|
|
* @obj: the object
|
|
|
|
* @crop_rect: the region to crop
|
|
|
|
*
|
|
|
|
* Crop the video data to the regions specified in the @crop_rect.
|
|
|
|
*
|
|
|
|
* For capture devices, this crop the image sensor / video stream provided by
|
|
|
|
* the V4L2 device.
|
|
|
|
* For output devices, this crops the memory buffer that GStreamer passed to
|
|
|
|
* the V4L2 device.
|
|
|
|
*
|
|
|
|
* The crop_rect may be modified by the V4L2 device to a region that
|
|
|
|
* fulfills H/W requirements.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE on failure.
|
|
|
|
*/
|
2014-03-20 19:31:22 +00:00
|
|
|
gboolean
|
2023-03-15 18:52:48 +00:00
|
|
|
gst_v4l2_object_set_crop (GstV4l2Object * obj, struct v4l2_rect *crop_rect)
|
2014-03-20 19:31:22 +00:00
|
|
|
{
|
2018-06-25 14:03:17 +00:00
|
|
|
struct v4l2_selection sel = { 0 };
|
2014-03-20 19:31:22 +00:00
|
|
|
struct v4l2_crop crop = { 0 };
|
|
|
|
|
2021-09-30 08:56:56 +00:00
|
|
|
GST_V4L2_CHECK_OPEN (obj);
|
|
|
|
|
2018-06-25 14:03:17 +00:00
|
|
|
sel.type = obj->type;
|
|
|
|
sel.target = V4L2_SEL_TGT_CROP;
|
|
|
|
sel.flags = 0;
|
2021-09-30 08:56:56 +00:00
|
|
|
sel.r = *crop_rect;
|
2018-06-25 14:03:17 +00:00
|
|
|
|
2014-03-20 19:31:22 +00:00
|
|
|
crop.type = obj->type;
|
2018-06-25 14:03:17 +00:00
|
|
|
crop.c = sel.r;
|
2014-03-20 19:31:22 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-03-20 19:31:22 +00:00
|
|
|
"Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
|
|
|
|
crop.c.width, crop.c.height);
|
|
|
|
|
2018-06-25 14:03:17 +00:00
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_S_SELECTION, &sel) < 0) {
|
|
|
|
if (errno != ENOTTY) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Failed to set crop rectangle with VIDIOC_S_SELECTION: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_S_CROP failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-03-20 19:31:22 +00:00
|
|
|
|
2018-06-25 14:03:17 +00:00
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_G_CROP, &crop) < 0) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_G_CROP failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sel.r = crop.c;
|
|
|
|
}
|
2014-09-05 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-03-20 19:31:22 +00:00
|
|
|
"Got cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
|
|
|
|
crop.c.width, crop.c.height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-30 08:56:56 +00:00
|
|
|
/**
|
|
|
|
* gst_v4l2_object_setup_padding:
|
|
|
|
* @obj: v4l2 object
|
|
|
|
*
|
|
|
|
* Crop away the padding around the video data as specified
|
|
|
|
* in GstVideoAlignement data stored in @obj.
|
|
|
|
*
|
|
|
|
* For capture devices, this crop the image sensor / video stream provided by
|
|
|
|
* the V4L2 device.
|
|
|
|
* For output devices, this crops the memory buffer that GStreamer passed to
|
|
|
|
* the V4L2 device.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success, %FALSE on failure.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_setup_padding (GstV4l2Object * obj)
|
|
|
|
{
|
|
|
|
GstVideoAlignment *align = &obj->align;
|
|
|
|
struct v4l2_rect crop;
|
|
|
|
|
|
|
|
if (align->padding_left + align->padding_top
|
|
|
|
+ align->padding_right + align->padding_bottom == 0) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "no cropping needed");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
crop.left = align->padding_left;
|
|
|
|
crop.top = align->padding_top;
|
|
|
|
crop.width = obj->info.width;
|
|
|
|
crop.height = GST_VIDEO_INFO_FIELD_HEIGHT (&obj->info);
|
|
|
|
|
|
|
|
return gst_v4l2_object_set_crop (obj, &crop);
|
|
|
|
}
|
|
|
|
|
2021-10-13 08:33:12 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_get_crop_rect (GstV4l2Object * obj, guint target,
|
|
|
|
struct v4l2_rect *result)
|
|
|
|
{
|
|
|
|
struct v4l2_rect *res_rect;
|
|
|
|
|
|
|
|
struct v4l2_selection sel = { 0 };
|
|
|
|
struct v4l2_cropcap cropcap = { 0 };
|
|
|
|
|
|
|
|
GST_V4L2_CHECK_OPEN (obj);
|
|
|
|
|
|
|
|
if (target != V4L2_SEL_TGT_CROP_BOUNDS && target != V4L2_SEL_TGT_CROP_DEFAULT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sel.type = obj->type;
|
|
|
|
sel.target = target;
|
|
|
|
|
|
|
|
res_rect = &sel.r;
|
|
|
|
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_G_SELECTION, &sel) < 0) {
|
|
|
|
if (errno != ENOTTY) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Failed to get default crop rectangle with VIDIOC_G_SELECTION: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_CROPCAP, &cropcap) < 0) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_CROPCAP failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (target == V4L2_SEL_TGT_CROP_BOUNDS)
|
|
|
|
res_rect = &cropcap.bounds;
|
|
|
|
else if (target == V4L2_SEL_TGT_CROP_DEFAULT)
|
|
|
|
res_rect = &cropcap.defrect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = *res_rect;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2023-03-15 18:52:48 +00:00
|
|
|
gst_v4l2_object_get_crop_bounds (GstV4l2Object * obj, struct v4l2_rect *result)
|
2021-10-13 08:33:12 +00:00
|
|
|
{
|
|
|
|
return gst_v4l2_object_get_crop_rect (obj, V4L2_SEL_TGT_CROP_BOUNDS, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2023-03-15 18:52:48 +00:00
|
|
|
gst_v4l2_object_get_crop_default (GstV4l2Object * obj, struct v4l2_rect *result)
|
2021-10-13 08:33:12 +00:00
|
|
|
{
|
|
|
|
return gst_v4l2_object_get_crop_rect (obj, V4L2_SEL_TGT_CROP_DEFAULT, result);
|
|
|
|
}
|
|
|
|
|
2013-05-17 08:16:48 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
|
|
|
|
{
|
2014-05-09 16:10:04 +00:00
|
|
|
GstStructure *config;
|
2013-05-17 08:16:48 +00:00
|
|
|
GstCaps *oldcaps;
|
2014-05-09 16:10:04 +00:00
|
|
|
gboolean ret;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
2013-05-17 08:16:48 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!pool)
|
2013-05-17 08:16:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2014-05-09 16:10:04 +00:00
|
|
|
gst_buffer_pool_config_get_params (config, &oldcaps, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
ret = oldcaps && gst_caps_is_equal (caps, oldcaps);
|
2013-05-17 08:16:48 +00:00
|
|
|
|
2014-05-09 16:10:04 +00:00
|
|
|
gst_structure_free (config);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_object_unref (pool);
|
2014-05-09 16:10:04 +00:00
|
|
|
return ret;
|
2013-05-17 08:16:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 07:14:20 +00:00
|
|
|
gboolean
|
2018-07-11 16:21:44 +00:00
|
|
|
gst_v4l2_object_caps_is_subset (GstV4l2Object * v4l2object, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *oldcaps;
|
|
|
|
gboolean ret;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
2018-07-11 16:21:44 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!pool)
|
2018-07-11 16:21:44 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2018-07-11 16:21:44 +00:00
|
|
|
gst_buffer_pool_config_get_params (config, &oldcaps, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
ret = oldcaps && gst_caps_is_subset (oldcaps, caps);
|
|
|
|
|
|
|
|
gst_structure_free (config);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_object_unref (pool);
|
2018-07-11 16:21:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_v4l2_object_get_current_caps (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *oldcaps;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
2018-07-11 16:21:44 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!pool)
|
2018-07-11 16:21:44 +00:00
|
|
|
return NULL;
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2018-07-11 16:21:44 +00:00
|
|
|
gst_buffer_pool_config_get_params (config, &oldcaps, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (oldcaps)
|
|
|
|
gst_caps_ref (oldcaps);
|
|
|
|
|
|
|
|
gst_structure_free (config);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_object_unref (pool);
|
2018-07-11 16:21:44 +00:00
|
|
|
return oldcaps;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-07-18 16:54:49 +00:00
|
|
|
gst_v4l2_object_unlock (GstV4l2Object * v4l2object)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
2014-05-25 00:20:07 +00:00
|
|
|
gboolean ret = TRUE;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
2014-05-23 18:12:10 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "start flushing");
|
2014-05-25 00:20:07 +00:00
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
gst_poll_set_flushing (v4l2object->poll, TRUE);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!pool)
|
|
|
|
return ret;
|
2014-05-25 00:20:07 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (gst_buffer_pool_is_active (pool))
|
|
|
|
gst_buffer_pool_set_flushing (pool, TRUE);
|
|
|
|
|
|
|
|
gst_object_unref (pool);
|
2014-05-25 00:20:07 +00:00
|
|
|
return ret;
|
2011-07-18 16:54:49 +00:00
|
|
|
}
|
2011-07-13 14:33:58 +00:00
|
|
|
|
2011-07-18 16:54:49 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object)
|
|
|
|
{
|
2014-05-25 00:20:07 +00:00
|
|
|
gboolean ret = TRUE;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
2011-07-15 09:27:18 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "stop flushing");
|
2014-05-25 00:20:07 +00:00
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
gst_poll_set_flushing (v4l2object->poll, FALSE);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!pool)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (gst_buffer_pool_is_active (pool))
|
|
|
|
gst_buffer_pool_set_flushing (pool, FALSE);
|
2014-05-25 00:20:07 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_object_unref (pool);
|
2014-05-25 00:20:07 +00:00
|
|
|
return ret;
|
2009-08-04 07:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-07-13 14:33:58 +00:00
|
|
|
gst_v4l2_object_stop (GstV4l2Object * v4l2object)
|
2009-08-04 07:14:20 +00:00
|
|
|
{
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool;
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "stopping");
|
2011-07-13 14:33:58 +00:00
|
|
|
|
|
|
|
if (!GST_V4L2_IS_OPEN (v4l2object))
|
|
|
|
goto done;
|
|
|
|
if (!GST_V4L2_IS_ACTIVE (v4l2object))
|
|
|
|
goto done;
|
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
gst_poll_set_flushing (v4l2object->poll, TRUE);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
pool = gst_v4l2_object_get_buffer_pool (v4l2object);
|
|
|
|
if (pool) {
|
|
|
|
if (!gst_v4l2_buffer_pool_orphan (v4l2object)) {
|
2019-05-27 09:08:54 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "deactivating pool");
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_buffer_pool_set_active (pool, FALSE);
|
|
|
|
|
|
|
|
{
|
|
|
|
GstBufferPool *old_pool;
|
|
|
|
GST_OBJECT_LOCK (v4l2object->element);
|
|
|
|
old_pool = v4l2object->pool;
|
|
|
|
v4l2object->pool = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (v4l2object->element);
|
|
|
|
if (old_pool)
|
|
|
|
gst_object_unref (old_pool);
|
|
|
|
}
|
2019-05-27 09:08:54 +00:00
|
|
|
}
|
2023-01-25 00:52:28 +00:00
|
|
|
gst_object_unref (pool);
|
2011-07-13 14:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_V4L2_SET_INACTIVE (v4l2object);
|
|
|
|
|
|
|
|
done:
|
2011-07-12 17:13:45 +00:00
|
|
|
return TRUE;
|
2011-07-13 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 21:58:07 +00:00
|
|
|
GstCaps *
|
2015-03-27 14:02:33 +00:00
|
|
|
gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
|
2012-10-22 21:58:07 +00:00
|
|
|
{
|
|
|
|
GstCaps *ret;
|
|
|
|
GSList *walk;
|
|
|
|
GSList *formats;
|
2023-04-12 21:18:13 +00:00
|
|
|
guint32 fourcc = 0;
|
|
|
|
|
|
|
|
if (v4l2object->fmtdesc)
|
|
|
|
fourcc = GST_V4L2_PIXELFORMAT (v4l2object);
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2023-04-12 21:18:13 +00:00
|
|
|
gst_v4l2_object_clear_format_list (v4l2object);
|
2015-03-27 14:02:33 +00:00
|
|
|
formats = gst_v4l2_object_get_format_list (v4l2object);
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2023-04-12 21:18:13 +00:00
|
|
|
/* Recover the fmtdesc, it may no longer exist, in which case it will be set
|
|
|
|
* to null */
|
|
|
|
if (fourcc)
|
|
|
|
v4l2object->fmtdesc =
|
|
|
|
gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
|
|
|
|
|
2015-03-27 14:02:33 +00:00
|
|
|
ret = gst_caps_new_empty ();
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2017-07-14 20:21:38 +00:00
|
|
|
if (v4l2object->keep_aspect && !v4l2object->par) {
|
|
|
|
struct v4l2_cropcap cropcap;
|
|
|
|
|
|
|
|
memset (&cropcap, 0, sizeof (cropcap));
|
|
|
|
|
|
|
|
cropcap.type = v4l2object->type;
|
2017-07-24 18:19:02 +00:00
|
|
|
if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_CROPCAP, &cropcap) < 0) {
|
2024-02-28 03:28:23 +00:00
|
|
|
|
|
|
|
switch (errno) {
|
|
|
|
case ENODATA:
|
|
|
|
case ENOTTY:
|
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Driver does not support VIDIOC_CROPCAP (%s), assuming pixel aspect ratio 1/1",
|
|
|
|
g_strerror (errno));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
}
|
|
|
|
v4l2object->par = g_new0 (GValue, 1);
|
|
|
|
g_value_init (v4l2object->par, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (v4l2object->par, 1, 1);
|
|
|
|
|
2018-09-11 00:18:32 +00:00
|
|
|
} else if (cropcap.pixelaspect.numerator && cropcap.pixelaspect.denominator) {
|
2017-07-14 20:21:38 +00:00
|
|
|
v4l2object->par = g_new0 (GValue, 1);
|
|
|
|
g_value_init (v4l2object->par, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (v4l2object->par, cropcap.pixelaspect.numerator,
|
|
|
|
cropcap.pixelaspect.denominator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:02:33 +00:00
|
|
|
for (walk = formats; walk; walk = walk->next) {
|
|
|
|
struct v4l2_fmtdesc *format;
|
|
|
|
GstStructure *template;
|
2017-07-14 15:54:57 +00:00
|
|
|
GstCaps *tmp;
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2015-03-27 14:02:33 +00:00
|
|
|
format = (struct v4l2_fmtdesc *) walk->data;
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2015-12-18 20:49:43 +00:00
|
|
|
template = gst_v4l2_object_v4l2fourcc_to_bare_struct (format->pixelformat);
|
2012-10-22 21:58:07 +00:00
|
|
|
|
2017-07-14 15:54:57 +00:00
|
|
|
if (!template) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
2017-07-14 16:12:56 +00:00
|
|
|
"unknown format %" GST_FOURCC_FORMAT,
|
|
|
|
GST_FOURCC_ARGS (format->pixelformat));
|
2017-07-14 15:54:57 +00:00
|
|
|
continue;
|
2012-10-22 21:58:07 +00:00
|
|
|
}
|
2017-07-14 15:54:57 +00:00
|
|
|
|
|
|
|
/* If we have a filter, check if we need to probe this format or not */
|
|
|
|
if (filter) {
|
|
|
|
GstCaps *format_caps = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
gst_caps_append_structure (format_caps, gst_structure_copy (template));
|
|
|
|
|
|
|
|
if (!gst_caps_can_intersect (format_caps, filter)) {
|
|
|
|
gst_caps_unref (format_caps);
|
|
|
|
gst_structure_free (template);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (format_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = gst_v4l2_object_probe_caps_for_format (v4l2object,
|
|
|
|
format->pixelformat, template);
|
2018-08-08 07:27:19 +00:00
|
|
|
if (tmp) {
|
2017-07-14 15:54:57 +00:00
|
|
|
gst_caps_append (ret, tmp);
|
|
|
|
|
2018-08-08 07:27:19 +00:00
|
|
|
/* Add a variant of the caps with the Interlaced feature so we can negotiate it if needed */
|
|
|
|
add_alternate_variant (v4l2object, ret, gst_caps_get_structure (ret,
|
|
|
|
gst_caps_get_size (ret) - 1));
|
|
|
|
}
|
|
|
|
|
2017-07-14 15:54:57 +00:00
|
|
|
gst_structure_free (template);
|
2012-10-22 21:58:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 14:02:33 +00:00
|
|
|
if (filter) {
|
2016-05-18 09:12:15 +00:00
|
|
|
GstCaps *tmp;
|
|
|
|
|
|
|
|
tmp = ret;
|
2015-03-27 14:02:33 +00:00
|
|
|
ret = gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
|
2016-05-18 09:12:15 +00:00
|
|
|
gst_caps_unref (tmp);
|
2015-03-27 14:02:33 +00:00
|
|
|
}
|
|
|
|
|
2024-07-29 01:07:40 +00:00
|
|
|
/* Add a variant of the caps without the colorimetry so that we can negotiate
|
|
|
|
successfully even if the detected colorimetry from upstream is not supported
|
|
|
|
by the device */
|
|
|
|
if (ret) {
|
|
|
|
add_non_colorimetry_caps (v4l2object, ret);
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj, "probed caps: %" GST_PTR_FORMAT, ret);
|
2017-07-14 15:54:57 +00:00
|
|
|
|
2015-03-27 14:02:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_v4l2_object_get_caps (GstV4l2Object * v4l2object, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *ret;
|
|
|
|
|
|
|
|
if (v4l2object->probed_caps == NULL)
|
|
|
|
v4l2object->probed_caps = gst_v4l2_object_probe_caps (v4l2object, NULL);
|
|
|
|
|
2012-10-22 21:58:07 +00:00
|
|
|
if (filter) {
|
|
|
|
ret = gst_caps_intersect_full (filter, v4l2object->probed_caps,
|
|
|
|
GST_CAPS_INTERSECT_FIRST);
|
|
|
|
} else {
|
|
|
|
ret = gst_caps_ref (v4l2object->probed_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2013-12-05 23:48:15 +00:00
|
|
|
|
2019-05-21 08:31:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_match_buffer_layout (GstV4l2Object * obj, guint n_planes,
|
|
|
|
gsize offset[GST_VIDEO_MAX_PLANES], gint stride[GST_VIDEO_MAX_PLANES],
|
|
|
|
gsize buffer_size, guint padded_height)
|
|
|
|
{
|
|
|
|
guint p;
|
|
|
|
gboolean need_fmt_update = FALSE;
|
|
|
|
|
|
|
|
if (n_planes != GST_VIDEO_INFO_N_PLANES (&obj->info)) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
2019-05-25 19:19:21 +00:00
|
|
|
"Cannot match buffers with different number planes");
|
2019-05-21 08:31:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = 0; p < n_planes; p++) {
|
|
|
|
if (stride[p] < obj->info.stride[p]) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2019-05-25 19:19:21 +00:00
|
|
|
"Not matching as remote stride %i is smaller than %i on plane %u",
|
2019-05-21 08:31:46 +00:00
|
|
|
stride[p], obj->info.stride[p], p);
|
|
|
|
return FALSE;
|
|
|
|
} else if (stride[p] > obj->info.stride[p]) {
|
|
|
|
GST_LOG_OBJECT (obj->dbg_obj,
|
|
|
|
"remote stride %i is higher than %i on plane %u",
|
|
|
|
stride[p], obj->info.stride[p], p);
|
|
|
|
need_fmt_update = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset[p] < obj->info.offset[p]) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2019-05-25 19:19:21 +00:00
|
|
|
"Not matching as offset %" G_GSIZE_FORMAT
|
2019-05-21 08:31:46 +00:00
|
|
|
" is smaller than %" G_GSIZE_FORMAT " on plane %u",
|
|
|
|
offset[p], obj->info.offset[p], p);
|
|
|
|
return FALSE;
|
|
|
|
} else if (offset[p] > obj->info.offset[p]) {
|
|
|
|
GST_LOG_OBJECT (obj->dbg_obj,
|
|
|
|
"Remote offset %" G_GSIZE_FORMAT
|
|
|
|
" is higher than %" G_GSIZE_FORMAT " on plane %u",
|
|
|
|
offset[p], obj->info.offset[p], p);
|
|
|
|
need_fmt_update = TRUE;
|
|
|
|
}
|
2021-11-01 03:08:32 +00:00
|
|
|
|
|
|
|
if (padded_height) {
|
|
|
|
guint fmt_height;
|
|
|
|
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (obj->type))
|
|
|
|
fmt_height = obj->format.fmt.pix_mp.height;
|
|
|
|
else
|
|
|
|
fmt_height = obj->format.fmt.pix.height;
|
|
|
|
|
|
|
|
if (padded_height > fmt_height)
|
|
|
|
need_fmt_update = TRUE;
|
|
|
|
}
|
2019-05-21 08:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_fmt_update) {
|
|
|
|
struct v4l2_format format;
|
|
|
|
gint wanted_stride[GST_VIDEO_MAX_PLANES] = { 0, };
|
|
|
|
|
|
|
|
format = obj->format;
|
|
|
|
|
|
|
|
if (padded_height) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Padded height %u", padded_height);
|
|
|
|
|
|
|
|
obj->align.padding_bottom =
|
2020-01-30 06:39:12 +00:00
|
|
|
padded_height - GST_VIDEO_INFO_FIELD_HEIGHT (&obj->info);
|
2019-05-21 08:31:46 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Failed to compute padded height; keep the default one");
|
|
|
|
padded_height = format.fmt.pix_mp.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update the current format with the stride we want to import from */
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (obj->type)) {
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Wanted strides:");
|
|
|
|
|
|
|
|
for (i = 0; i < obj->n_v4l2_planes; i++) {
|
|
|
|
gint plane_stride = stride[i];
|
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (obj->info.finfo))
|
2022-11-15 18:50:13 +00:00
|
|
|
plane_stride = GST_VIDEO_TILE_X_TILES (plane_stride) *
|
|
|
|
GST_VIDEO_FORMAT_INFO_TILE_STRIDE (obj->info.finfo, i);
|
2019-05-21 08:31:46 +00:00
|
|
|
|
|
|
|
format.fmt.pix_mp.plane_fmt[i].bytesperline = plane_stride;
|
|
|
|
format.fmt.pix_mp.height = padded_height;
|
|
|
|
wanted_stride[i] = plane_stride;
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, " [%u] %i", i, wanted_stride[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gint plane_stride = stride[0];
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Wanted stride: %i", plane_stride);
|
|
|
|
|
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (obj->info.finfo))
|
2022-11-15 18:50:13 +00:00
|
|
|
plane_stride = GST_VIDEO_TILE_X_TILES (plane_stride) *
|
|
|
|
GST_VIDEO_FORMAT_INFO_TILE_STRIDE (obj->info.finfo, 0);
|
2019-05-21 08:31:46 +00:00
|
|
|
|
|
|
|
format.fmt.pix.bytesperline = plane_stride;
|
|
|
|
format.fmt.pix.height = padded_height;
|
|
|
|
wanted_stride[0] = plane_stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->ioctl (obj->video_fd, VIDIOC_S_FMT, &format) < 0) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Something went wrong trying to update current format: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_v4l2_object_save_format (obj, obj->fmtdesc, &format, &obj->info,
|
|
|
|
&obj->align);
|
|
|
|
|
|
|
|
if (V4L2_TYPE_IS_MULTIPLANAR (obj->type)) {
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < obj->n_v4l2_planes; i++) {
|
|
|
|
if (format.fmt.pix_mp.plane_fmt[i].bytesperline != wanted_stride[i]) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"[%i] Driver did not accept the new stride (wants %i, got %i)",
|
|
|
|
i, wanted_stride[i], format.fmt.pix_mp.plane_fmt[i].bytesperline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format.fmt.pix_mp.height != padded_height) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"Driver did not accept the padded height (wants %i, got %i)",
|
|
|
|
padded_height, format.fmt.pix_mp.height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (format.fmt.pix.bytesperline != wanted_stride[0]) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"Driver did not accept the new stride (wants %i, got %i)",
|
|
|
|
wanted_stride[0], format.fmt.pix.bytesperline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format.fmt.pix.height != padded_height) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"Driver did not accept the padded height (wants %i, got %i)",
|
|
|
|
padded_height, format.fmt.pix.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->align.padding_bottom) {
|
|
|
|
/* Crop because of vertical padding */
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "crop because of bottom padding of %d",
|
|
|
|
obj->align.padding_bottom);
|
2021-09-30 08:56:56 +00:00
|
|
|
gst_v4l2_object_setup_padding (obj);
|
2019-05-21 08:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-23 08:49:39 +00:00
|
|
|
static gboolean
|
|
|
|
validate_video_meta_struct (GstV4l2Object * obj, const GstStructure * s)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < gst_structure_n_fields (s); i++) {
|
|
|
|
const gchar *name = gst_structure_nth_field_name (s, i);
|
|
|
|
|
|
|
|
if (!g_str_equal (name, "padding-top")
|
|
|
|
&& !g_str_equal (name, "padding-bottom")
|
|
|
|
&& !g_str_equal (name, "padding-left")
|
|
|
|
&& !g_str_equal (name, "padding-right")) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "Unknown video meta field: '%s'", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_v4l2_object_match_buffer_layout_from_struct (GstV4l2Object * obj,
|
|
|
|
const GstStructure * s, GstCaps * caps, guint buffer_size)
|
|
|
|
{
|
|
|
|
GstVideoInfo info;
|
|
|
|
GstVideoAlignment align;
|
|
|
|
gsize plane_size[GST_VIDEO_MAX_PLANES];
|
|
|
|
|
|
|
|
if (!validate_video_meta_struct (obj, s))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps)) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "Failed to create video info");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_alignment_reset (&align);
|
|
|
|
|
|
|
|
gst_structure_get_uint (s, "padding-top", &align.padding_top);
|
|
|
|
gst_structure_get_uint (s, "padding-bottom", &align.padding_bottom);
|
|
|
|
gst_structure_get_uint (s, "padding-left", &align.padding_left);
|
|
|
|
gst_structure_get_uint (s, "padding-right", &align.padding_right);
|
|
|
|
|
|
|
|
if (align.padding_top || align.padding_bottom || align.padding_left ||
|
|
|
|
align.padding_right) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"Upstream requested padding (top: %d bottom: %d left: %d right: %d)",
|
|
|
|
align.padding_top, align.padding_bottom, align.padding_left,
|
|
|
|
align.padding_right);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_video_info_align_full (&info, &align, plane_size)) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "Failed to align video info");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_SIZE (&info) != buffer_size) {
|
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj,
|
|
|
|
"Requested buffer size (%d) doesn't match video info size (%"
|
|
|
|
G_GSIZE_FORMAT ")", buffer_size, GST_VIDEO_INFO_SIZE (&info));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"try matching buffer layout requested by downstream");
|
|
|
|
|
|
|
|
gst_v4l2_object_match_buffer_layout (obj, GST_VIDEO_INFO_N_PLANES (&info),
|
|
|
|
info.offset, info.stride, buffer_size,
|
|
|
|
GST_VIDEO_INFO_PLANE_HEIGHT (&info, 0, plane_size));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query)
|
|
|
|
{
|
2014-03-16 11:44:14 +00:00
|
|
|
GstCaps *caps;
|
2022-11-28 22:26:50 +00:00
|
|
|
GstBufferPool *pool = NULL, *other_pool = NULL, *obj_pool = NULL;
|
2014-04-08 22:20:25 +00:00
|
|
|
GstStructure *config;
|
2014-04-18 18:45:00 +00:00
|
|
|
guint size, min, max, own_min = 0;
|
2013-12-05 23:48:15 +00:00
|
|
|
gboolean update;
|
2014-05-06 16:58:59 +00:00
|
|
|
gboolean has_video_meta;
|
2014-04-11 21:10:11 +00:00
|
|
|
gboolean can_share_own_pool, pushing_from_our_pool = FALSE;
|
2014-05-24 22:45:30 +00:00
|
|
|
GstAllocator *allocator = NULL;
|
|
|
|
GstAllocationParams params = { 0 };
|
2019-05-23 08:49:39 +00:00
|
|
|
guint video_idx;
|
2013-12-05 23:48:15 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "decide allocation");
|
2013-12-05 23:48:15 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
|
|
|
|
obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
|
|
|
|
|
2014-03-16 11:44:14 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
2013-12-05 23:48:44 +00:00
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
obj_pool = gst_v4l2_object_get_buffer_pool (obj);
|
|
|
|
if (obj_pool == NULL) {
|
2013-12-05 23:48:44 +00:00
|
|
|
if (!gst_v4l2_object_setup_pool (obj, caps))
|
|
|
|
goto pool_failed;
|
2022-11-28 22:26:50 +00:00
|
|
|
obj_pool = gst_v4l2_object_get_buffer_pool (obj);
|
|
|
|
if (obj_pool == NULL)
|
|
|
|
goto pool_failed;
|
2013-12-05 23:48:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 22:45:30 +00:00
|
|
|
if (gst_query_get_n_allocation_params (query) > 0)
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
update = TRUE;
|
|
|
|
} else {
|
|
|
|
pool = NULL;
|
|
|
|
min = max = 0;
|
|
|
|
size = 0;
|
|
|
|
update = FALSE;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "allocation: size:%u min:%u max:%u pool:%"
|
2013-12-05 23:48:15 +00:00
|
|
|
GST_PTR_FORMAT, size, min, max, pool);
|
|
|
|
|
2014-04-15 19:07:23 +00:00
|
|
|
has_video_meta =
|
2019-05-23 08:49:39 +00:00
|
|
|
gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE,
|
|
|
|
&video_idx);
|
|
|
|
|
|
|
|
if (has_video_meta) {
|
|
|
|
const GstStructure *params;
|
|
|
|
gst_query_parse_nth_allocation_meta (query, video_idx, ¶ms);
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
gst_v4l2_object_match_buffer_layout_from_struct (obj, params, caps, size);
|
|
|
|
}
|
2014-04-15 19:07:23 +00:00
|
|
|
|
2014-05-06 16:58:59 +00:00
|
|
|
can_share_own_pool = (has_video_meta || !obj->need_video_meta);
|
2014-04-15 19:07:23 +00:00
|
|
|
|
2015-03-30 11:12:35 +00:00
|
|
|
gst_v4l2_get_driver_min_buffers (obj);
|
2014-07-08 18:31:59 +00:00
|
|
|
/* We can't share our own pool, if it exceed V4L2 capacity */
|
2014-09-04 19:11:40 +00:00
|
|
|
if (min + obj->min_buffers + 1 > VIDEO_MAX_FRAME)
|
2014-07-08 18:31:59 +00:00
|
|
|
can_share_own_pool = FALSE;
|
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
/* select a pool */
|
|
|
|
switch (obj->mode) {
|
|
|
|
case GST_V4L2_IO_RW:
|
2014-04-15 19:07:23 +00:00
|
|
|
if (pool) {
|
2013-12-05 23:48:15 +00:00
|
|
|
/* in READ/WRITE mode, prefer a downstream pool because our own pool
|
|
|
|
* doesn't help much, we have to write to it as well */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2013-12-05 23:48:15 +00:00
|
|
|
"read/write mode: using downstream pool");
|
|
|
|
/* use the bigest size, when we use our own pool we can't really do any
|
|
|
|
* other size than what the hardware gives us but for downstream pools
|
|
|
|
* we can try */
|
2014-05-06 16:58:59 +00:00
|
|
|
size = MAX (size, obj->info.size);
|
2014-04-11 21:10:11 +00:00
|
|
|
} else if (can_share_own_pool) {
|
2014-04-15 19:07:23 +00:00
|
|
|
/* no downstream pool, use our own then */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-04-15 19:07:23 +00:00
|
|
|
"read/write mode: no downstream pool, using our own");
|
2022-11-28 22:26:50 +00:00
|
|
|
pool = gst_object_ref (obj_pool);
|
2014-05-06 16:58:59 +00:00
|
|
|
size = obj->info.size;
|
2014-04-11 21:10:11 +00:00
|
|
|
pushing_from_our_pool = TRUE;
|
2013-12-05 23:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-04-11 21:10:11 +00:00
|
|
|
|
2014-04-14 16:19:39 +00:00
|
|
|
case GST_V4L2_IO_USERPTR:
|
|
|
|
case GST_V4L2_IO_DMABUF_IMPORT:
|
2014-04-11 21:10:11 +00:00
|
|
|
/* in importing mode, prefer our own pool, and pass the other pool to
|
|
|
|
* our own, so it can serve itself */
|
|
|
|
if (pool == NULL)
|
|
|
|
goto no_downstream_pool;
|
2022-11-28 22:26:50 +00:00
|
|
|
gst_v4l2_buffer_pool_set_other_pool (GST_V4L2_BUFFER_POOL (obj_pool),
|
2014-04-11 21:10:11 +00:00
|
|
|
pool);
|
|
|
|
other_pool = pool;
|
|
|
|
gst_object_unref (pool);
|
2022-11-28 22:26:50 +00:00
|
|
|
pool = gst_object_ref (obj_pool);
|
2014-05-06 16:58:59 +00:00
|
|
|
size = obj->info.size;
|
2014-04-11 21:10:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_V4L2_IO_MMAP:
|
|
|
|
case GST_V4L2_IO_DMABUF:
|
2013-12-05 23:48:15 +00:00
|
|
|
/* in streaming mode, prefer our own pool */
|
2014-04-15 19:07:23 +00:00
|
|
|
/* Check if we can use it ... */
|
2014-04-11 21:10:11 +00:00
|
|
|
if (can_share_own_pool) {
|
2014-04-15 19:07:23 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2022-11-28 22:26:50 +00:00
|
|
|
pool = gst_object_ref (obj_pool);
|
2014-05-06 16:58:59 +00:00
|
|
|
size = obj->info.size;
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-04-15 19:07:23 +00:00
|
|
|
"streaming mode: using our own pool %" GST_PTR_FORMAT, pool);
|
2014-04-11 21:10:11 +00:00
|
|
|
pushing_from_our_pool = TRUE;
|
2014-04-15 19:07:23 +00:00
|
|
|
} else if (pool) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-04-15 19:07:23 +00:00
|
|
|
"streaming mode: copying to downstream pool %" GST_PTR_FORMAT,
|
|
|
|
pool);
|
2014-04-08 22:54:09 +00:00
|
|
|
} else {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-04-08 22:54:09 +00:00
|
|
|
"streaming mode: no usable pool, copying to generic pool");
|
2014-05-06 16:58:59 +00:00
|
|
|
size = MAX (size, obj->info.size);
|
2014-04-15 19:07:23 +00:00
|
|
|
}
|
2013-12-05 23:48:15 +00:00
|
|
|
break;
|
|
|
|
case GST_V4L2_IO_AUTO:
|
|
|
|
default:
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_WARNING_OBJECT (obj->dbg_obj, "unhandled mode");
|
2013-12-05 23:48:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-08 22:20:25 +00:00
|
|
|
if (size == 0)
|
|
|
|
goto no_size;
|
|
|
|
|
2014-04-18 18:45:00 +00:00
|
|
|
/* If pushing from our own pool, configure it with queried minimum,
|
|
|
|
* otherwise use the minimum required */
|
|
|
|
if (pushing_from_our_pool) {
|
|
|
|
/* When pushing from our own pool, we need what downstream one, to be able
|
|
|
|
* to fill the pipeline, the minimum required to decoder according to the
|
2017-05-24 13:07:51 +00:00
|
|
|
* driver and 2 more, so we don't endup up with everything downstream or
|
|
|
|
* held by the decoder. We account 2 buffers for v4l2 so when one is being
|
|
|
|
* pushed downstream the other one can already be queued for the next
|
|
|
|
* frame. */
|
|
|
|
own_min = min + obj->min_buffers + 2;
|
2015-02-20 04:12:31 +00:00
|
|
|
|
|
|
|
/* If no allocation parameters where provided, allow for a little more
|
|
|
|
* buffers and enable copy threshold */
|
|
|
|
if (!update) {
|
2017-05-24 13:07:51 +00:00
|
|
|
own_min += 2;
|
2015-02-20 04:12:31 +00:00
|
|
|
gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
|
|
|
|
TRUE);
|
|
|
|
} else {
|
|
|
|
gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:45:00 +00:00
|
|
|
} else {
|
|
|
|
/* In this case we'll have to configure two buffer pool. For our buffer
|
|
|
|
* pool, we'll need what the driver one, and one more, so we can dequeu */
|
2014-09-04 19:11:40 +00:00
|
|
|
own_min = obj->min_buffers + 1;
|
2020-01-30 07:05:02 +00:00
|
|
|
own_min = MAX (own_min, GST_V4L2_MIN_BUFFERS (obj));
|
2014-04-18 18:45:00 +00:00
|
|
|
|
|
|
|
/* for the downstream pool, we keep what downstream wants, though ensure
|
|
|
|
* at least a minimum if downstream didn't suggest anything (we are
|
|
|
|
* expecting the base class to create a default one for the context) */
|
2020-01-30 07:05:02 +00:00
|
|
|
min = MAX (min, GST_V4L2_MIN_BUFFERS (obj));
|
2014-05-24 22:56:32 +00:00
|
|
|
|
|
|
|
/* To import we need the other pool to hold at least own_min */
|
2022-11-28 22:26:50 +00:00
|
|
|
if (obj_pool == pool)
|
2014-05-24 22:56:32 +00:00
|
|
|
min += own_min;
|
2014-04-18 18:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-08 22:20:25 +00:00
|
|
|
/* Request a bigger max, if one was suggested but it's too small */
|
|
|
|
if (max != 0)
|
|
|
|
max = MAX (min, max);
|
|
|
|
|
|
|
|
/* First step, configure our own pool */
|
2022-11-28 22:26:50 +00:00
|
|
|
config = gst_buffer_pool_get_config (obj_pool);
|
2014-05-06 17:37:47 +00:00
|
|
|
|
2014-05-24 22:56:32 +00:00
|
|
|
if (obj->need_video_meta || has_video_meta) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
|
2014-04-08 22:20:25 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
2014-04-08 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 22:45:30 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
2014-04-18 18:45:00 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, own_min, 0);
|
2014-04-08 22:20:25 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "setting own pool config to %"
|
2014-04-18 18:45:00 +00:00
|
|
|
GST_PTR_FORMAT, config);
|
2014-04-08 22:20:25 +00:00
|
|
|
|
|
|
|
/* Our pool often need to adjust the value */
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!gst_buffer_pool_set_config (obj_pool, config)) {
|
|
|
|
config = gst_buffer_pool_get_config (obj_pool);
|
2014-04-08 22:20:25 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "own pool config changed to %"
|
2014-04-18 18:45:00 +00:00
|
|
|
GST_PTR_FORMAT, config);
|
2014-04-08 22:20:25 +00:00
|
|
|
|
|
|
|
/* our pool will adjust the maximum buffer, which we are fine with */
|
2022-11-28 22:26:50 +00:00
|
|
|
if (!gst_buffer_pool_set_config (obj_pool, config))
|
2014-04-08 22:20:25 +00:00
|
|
|
goto config_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now configure the other pool if different */
|
2022-11-28 22:26:50 +00:00
|
|
|
if (obj_pool != pool)
|
2014-04-11 21:10:11 +00:00
|
|
|
other_pool = pool;
|
|
|
|
|
|
|
|
if (other_pool) {
|
2014-05-24 22:56:32 +00:00
|
|
|
config = gst_buffer_pool_get_config (other_pool);
|
2014-05-24 22:45:30 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
2013-12-05 23:48:15 +00:00
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, min, max);
|
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "setting other pool config to %"
|
2014-04-18 18:45:00 +00:00
|
|
|
GST_PTR_FORMAT, config);
|
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
/* if downstream supports video metadata, add this to the pool config */
|
2014-04-15 19:07:23 +00:00
|
|
|
if (has_video_meta) {
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
|
2013-12-05 23:48:15 +00:00
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
}
|
|
|
|
|
2014-05-24 22:56:32 +00:00
|
|
|
if (!gst_buffer_pool_set_config (other_pool, config)) {
|
|
|
|
config = gst_buffer_pool_get_config (other_pool);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_validate_params (config, caps, size, min,
|
|
|
|
max)) {
|
|
|
|
gst_structure_free (config);
|
|
|
|
goto config_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (other_pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
2013-12-05 23:48:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 19:21:18 +00:00
|
|
|
if (pool) {
|
|
|
|
/* For simplicity, simply read back the active configuration, so our base
|
|
|
|
* class get the right information */
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_get_params (config, NULL, &size, &min, &max);
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
2014-05-25 03:49:19 +00:00
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
if (update)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
2014-05-24 22:45:30 +00:00
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
2014-04-16 21:04:42 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
2022-11-28 22:26:50 +00:00
|
|
|
if (obj_pool)
|
|
|
|
gst_object_unref (obj_pool);
|
|
|
|
|
2013-12-05 23:48:15 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
pool_failed:
|
2014-04-08 22:20:25 +00:00
|
|
|
{
|
|
|
|
/* setup_pool already send the error */
|
2014-04-16 21:04:42 +00:00
|
|
|
goto cleanup;
|
2014-04-08 22:20:25 +00:00
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
|
|
|
|
(_("Failed to configure internal buffer pool.")), (NULL));
|
2014-04-16 21:04:42 +00:00
|
|
|
goto cleanup;
|
2014-04-08 22:20:25 +00:00
|
|
|
}
|
|
|
|
no_size:
|
2013-12-05 23:48:15 +00:00
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
|
2014-04-08 22:20:25 +00:00
|
|
|
(_("Video device did not suggest any buffer size.")), (NULL));
|
2014-04-16 21:04:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2022-11-28 22:26:50 +00:00
|
|
|
no_downstream_pool:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
|
|
|
|
(_("No downstream pool to import from.")),
|
|
|
|
("When importing DMABUF or USERPTR, we need a pool to import from"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-04-16 21:04:42 +00:00
|
|
|
cleanup:
|
|
|
|
{
|
2014-05-24 22:45:30 +00:00
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
2014-04-16 21:04:42 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
2022-11-28 22:26:50 +00:00
|
|
|
|
|
|
|
if (obj_pool)
|
|
|
|
gst_object_unref (obj_pool);
|
2014-04-11 21:10:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-12-05 23:48:15 +00:00
|
|
|
}
|
2014-03-27 17:20:53 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_propose_allocation (GstV4l2Object * obj, GstQuery * query)
|
|
|
|
{
|
2020-06-26 17:11:04 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
2014-04-05 02:36:37 +00:00
|
|
|
/* we need at least 2 buffers to operate */
|
|
|
|
guint size, min, max;
|
2014-03-27 17:20:53 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
gboolean need_pool;
|
|
|
|
|
2014-04-05 02:36:37 +00:00
|
|
|
/* Set defaults allocation parameters */
|
2014-05-06 16:58:59 +00:00
|
|
|
size = obj->info.size;
|
2020-01-30 07:05:02 +00:00
|
|
|
min = GST_V4L2_MIN_BUFFERS (obj);
|
2014-04-05 02:36:37 +00:00
|
|
|
max = VIDEO_MAX_FRAME;
|
|
|
|
|
2014-03-27 17:20:53 +00:00
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
2018-08-22 19:23:53 +00:00
|
|
|
switch (obj->mode) {
|
|
|
|
case GST_V4L2_IO_MMAP:
|
|
|
|
case GST_V4L2_IO_DMABUF:
|
2022-11-28 22:26:50 +00:00
|
|
|
if (need_pool) {
|
|
|
|
GstBufferPool *obj_pool = gst_v4l2_object_get_buffer_pool (obj);
|
|
|
|
if (obj_pool) {
|
|
|
|
if (!gst_buffer_pool_is_active (obj_pool))
|
|
|
|
pool = gst_object_ref (obj_pool);
|
|
|
|
|
|
|
|
gst_object_unref (obj_pool);
|
|
|
|
}
|
2020-06-26 17:11:04 +00:00
|
|
|
}
|
2018-08-22 19:23:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-03-27 17:20:53 +00:00
|
|
|
|
|
|
|
if (pool != NULL) {
|
|
|
|
GstCaps *pcaps;
|
|
|
|
GstStructure *config;
|
|
|
|
|
|
|
|
/* we had a pool, check caps */
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2014-04-05 02:36:37 +00:00
|
|
|
gst_buffer_pool_config_get_params (config, &pcaps, NULL, NULL, NULL);
|
2014-03-27 17:20:53 +00:00
|
|
|
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
2014-03-27 17:20:53 +00:00
|
|
|
"we had a pool with caps %" GST_PTR_FORMAT, pcaps);
|
|
|
|
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
|
|
gst_structure_free (config);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
goto different_caps;
|
|
|
|
}
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
2015-03-30 11:12:35 +00:00
|
|
|
gst_v4l2_get_driver_min_buffers (obj);
|
2014-07-25 15:42:20 +00:00
|
|
|
|
2020-01-30 07:05:02 +00:00
|
|
|
min = MAX (obj->min_buffers, GST_V4L2_MIN_BUFFERS (obj));
|
2014-09-04 16:35:46 +00:00
|
|
|
|
2014-04-05 02:36:37 +00:00
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
2014-03-27 17:20:53 +00:00
|
|
|
|
|
|
|
/* we also support various metadata */
|
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "no caps specified");
|
2014-03-27 17:20:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
different_caps:
|
|
|
|
{
|
|
|
|
/* different caps, we can't use this pool */
|
2017-12-13 19:39:47 +00:00
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "pool has different caps");
|
2014-03-27 17:20:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2018-08-01 17:07:52 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_try_import (GstV4l2Object * obj, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstVideoMeta *vmeta;
|
|
|
|
guint n_mem = gst_buffer_n_memory (buffer);
|
|
|
|
|
|
|
|
/* only import if requested */
|
|
|
|
switch (obj->mode) {
|
|
|
|
case GST_V4L2_IO_USERPTR:
|
|
|
|
case GST_V4L2_IO_DMABUF_IMPORT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj,
|
|
|
|
"The io-mode does not enable importation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmeta = gst_buffer_get_video_meta (buffer);
|
|
|
|
if (!vmeta && obj->need_video_meta) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Downstream buffer uses standard "
|
|
|
|
"stride/offset while the driver does not.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need matching strides/offsets and size */
|
|
|
|
if (vmeta) {
|
2019-05-21 08:31:46 +00:00
|
|
|
guint plane_height[GST_VIDEO_MAX_PLANES] = { 0, };
|
2018-08-01 17:07:52 +00:00
|
|
|
|
2019-05-21 08:31:46 +00:00
|
|
|
gst_video_meta_get_plane_height (vmeta, plane_height);
|
2018-08-01 17:07:52 +00:00
|
|
|
|
2019-05-21 08:31:46 +00:00
|
|
|
if (!gst_v4l2_object_match_buffer_layout (obj, vmeta->n_planes,
|
|
|
|
vmeta->offset, vmeta->stride, gst_buffer_get_size (buffer),
|
|
|
|
plane_height[0]))
|
|
|
|
return FALSE;
|
2018-08-01 17:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we can always import single memory buffer, but otherwise we need the same
|
|
|
|
* amount of memory object. */
|
|
|
|
if (n_mem != 1 && n_mem != obj->n_v4l2_planes) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Can only import %i memory, "
|
|
|
|
"buffers contains %u memory", obj->n_v4l2_planes, n_mem);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For DMABuf importation we need DMABuf of course */
|
|
|
|
if (obj->mode == GST_V4L2_IO_DMABUF_IMPORT) {
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_mem; i++) {
|
|
|
|
GstMemory *mem = gst_buffer_peek_memory (buffer, i);
|
|
|
|
|
|
|
|
if (!gst_is_dmabuf_memory (mem)) {
|
|
|
|
GST_DEBUG_OBJECT (obj->dbg_obj, "Cannot import non-DMABuf memory.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for the remaining, only the kernel driver can tell */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-11-28 22:26:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_v4l2_object_get_buffer_pool:
|
|
|
|
* @src: a #GstV4l2Object
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer full): the instance of the #GstBufferPool used
|
|
|
|
* by the v4l2object; unref it after usage.
|
|
|
|
*/
|
|
|
|
GstBufferPool *
|
|
|
|
gst_v4l2_object_get_buffer_pool (GstV4l2Object * v4l2object)
|
|
|
|
{
|
|
|
|
GstBufferPool *ret = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (v4l2object != NULL, NULL);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (v4l2object->element);
|
|
|
|
if (v4l2object->pool)
|
|
|
|
ret = gst_object_ref (v4l2object->pool);
|
|
|
|
GST_OBJECT_UNLOCK (v4l2object->element);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2023-04-15 02:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_v4l2_object_poll:
|
|
|
|
* @v4l2object: a #GstV4l2Object
|
|
|
|
* @timeout: timeout of type #GstClockTime
|
|
|
|
*
|
|
|
|
* Poll the video file descriptor for read when this is a capture, write when
|
|
|
|
* this is an output. It will also watch for errors and source change events.
|
|
|
|
* If a source change event is received, %GST_V4L2_FLOW_RESOLUTION_CHANGE will
|
|
|
|
* be returned. If the poll was interrupted, %GST_FLOW_FLUSHING is returned.
|
|
|
|
* If there was no read or write indicator, %GST_V4L2_FLOW_LAST_BUFFER is
|
|
|
|
* returned. It may also return %GST_FLOW_ERROR if some unexpected error
|
|
|
|
* occured.
|
|
|
|
*
|
|
|
|
* Returns: GST_FLOW_OK if buffers are ready to be queued or dequeued.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_v4l2_object_poll (GstV4l2Object * v4l2object, GstClockTime timeout)
|
|
|
|
{
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
if (!v4l2object->can_poll_device) {
|
|
|
|
if (timeout != 0)
|
|
|
|
goto done;
|
|
|
|
else
|
|
|
|
goto no_buffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (v4l2object->dbg_obj, "polling device");
|
|
|
|
|
|
|
|
again:
|
|
|
|
ret = gst_poll_wait (v4l2object->poll, timeout);
|
|
|
|
if (G_UNLIKELY (ret < 0)) {
|
|
|
|
switch (errno) {
|
|
|
|
case EBUSY:
|
|
|
|
goto stopped;
|
|
|
|
case EAGAIN:
|
|
|
|
case EINTR:
|
|
|
|
goto again;
|
|
|
|
case ENXIO:
|
|
|
|
GST_WARNING_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"v4l2 device doesn't support polling. Disabling"
|
|
|
|
" using libv4l2 in this case may cause deadlocks");
|
|
|
|
v4l2object->can_poll_device = FALSE;
|
|
|
|
goto done;
|
|
|
|
default:
|
|
|
|
goto select_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_poll_fd_has_error (v4l2object->poll, &v4l2object->pollfd))
|
|
|
|
goto select_error;
|
|
|
|
|
|
|
|
/* PRI is used to signal that events are available */
|
|
|
|
if (gst_poll_fd_has_pri (v4l2object->poll, &v4l2object->pollfd)) {
|
|
|
|
struct v4l2_event event = { 0, };
|
|
|
|
|
|
|
|
if (!gst_v4l2_dequeue_event (v4l2object, &event))
|
|
|
|
goto dqevent_failed;
|
|
|
|
|
|
|
|
if (event.type != V4L2_EVENT_SOURCE_CHANGE) {
|
|
|
|
GST_INFO_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Received unhandled event, ignoring.");
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((event.u.src_change.changes & V4L2_EVENT_SRC_CH_RESOLUTION) == 0) {
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj,
|
|
|
|
"Received non-resolution source-change, ignoring.");
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2023-08-22 01:57:14 +00:00
|
|
|
if (v4l2object->formats)
|
|
|
|
gst_v4l2_object_clear_format_list (v4l2object);
|
|
|
|
|
2023-04-15 02:22:06 +00:00
|
|
|
return GST_V4L2_FLOW_RESOLUTION_CHANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
goto no_buffers;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
stopped:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (v4l2object->dbg_obj, "stop called");
|
|
|
|
return GST_FLOW_FLUSHING;
|
|
|
|
}
|
|
|
|
select_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ, (NULL),
|
|
|
|
("poll error %d: %s (%d)", ret, g_strerror (errno), errno));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
no_buffers:
|
|
|
|
{
|
|
|
|
return GST_V4L2_FLOW_LAST_BUFFER;
|
|
|
|
}
|
|
|
|
dqevent_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ, (NULL),
|
|
|
|
("dqevent error: %s (%d)", g_strerror (errno), errno));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_v4l2_object_subscribe_event:
|
|
|
|
* @v4l2object: a #GstV4l2Object
|
|
|
|
* @event: the event ID
|
|
|
|
*
|
|
|
|
* Subscribe to an event, and enable polling for these. Note that only
|
|
|
|
* %V4L2_EVENT_SOURCE_CHANGE is currently supported by the poll helper.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the driver supports this event
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_v4l2_object_subscribe_event (GstV4l2Object * v4l2object, guint32 event)
|
|
|
|
{
|
|
|
|
guint32 id = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (v4l2object != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_V4L2_IS_OPEN (v4l2object), FALSE);
|
|
|
|
|
|
|
|
v4l2object->get_in_out_func (v4l2object, &id);
|
|
|
|
|
|
|
|
if (gst_v4l2_subscribe_event (v4l2object, event, id)) {
|
|
|
|
gst_poll_fd_ctl_pri (v4l2object->poll, &v4l2object->pollfd, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|