Initial commit

This commit is contained in:
Sergey Lapin
2021-03-25 10:26:38 +03:00
commit 7d1a9fe59b
10 changed files with 5977 additions and 0 deletions

18
indent.sh Normal file
View File

@@ -0,0 +1,18 @@
INDENT=indent
for i in 1 2; do
$INDENT \
--braces-on-if-line \
--case-brace-indentation0 \
--case-indentation2 \
--braces-after-struct-decl-line \
--line-length80 \
--no-tabs \
--cuddle-else \
--dont-line-up-parentheses \
--continuation-indentation4 \
--honour-newlines \
--tab-size8 \
--indent-level2 \
--leave-preprocessor-space \
*.c || exit $?
done

168
linux/media-bus-format.h Normal file
View File

@@ -0,0 +1,168 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Media Bus API header
*
* Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __LINUX_MEDIA_BUS_FORMAT_H
#define __LINUX_MEDIA_BUS_FORMAT_H
/*
* These bus formats uniquely identify data formats on the data bus. Format 0
* is reserved, MEDIA_BUS_FMT_FIXED shall be used by host-client pairs, where
* the data format is fixed. Additionally, "2X8" means that one pixel is
* transferred in two 8-bit samples, "BE" or "LE" specify in which order those
* samples are transferred over the bus: "LE" means that the least significant
* bits are transferred first, "BE" means that the most significant bits are
* transferred first, and "PADHI" and "PADLO" define which bits - low or high,
* in the incomplete high byte, are filled with padding bits.
*
* The bus formats are grouped by type, bus_width, bits per component, samples
* per pixel and order of subsamples. Numerical values are sorted using generic
* numerical sort order (8 thus comes before 10).
*
* As their value can't change when a new bus format is inserted in the
* enumeration, the bus formats are explicitly given a numerical value. The next
* free values for each category are listed below, update them when inserting
* new pixel codes.
*/
#define MEDIA_BUS_FMT_FIXED 0x0001
/* RGB - next is 0x101e */
#define MEDIA_BUS_FMT_RGB444_1X12 0x1016
#define MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE 0x1001
#define MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE 0x1002
#define MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE 0x1003
#define MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE 0x1004
#define MEDIA_BUS_FMT_RGB565_1X16 0x1017
#define MEDIA_BUS_FMT_BGR565_2X8_BE 0x1005
#define MEDIA_BUS_FMT_BGR565_2X8_LE 0x1006
#define MEDIA_BUS_FMT_RGB565_2X8_BE 0x1007
#define MEDIA_BUS_FMT_RGB565_2X8_LE 0x1008
#define MEDIA_BUS_FMT_RGB666_1X18 0x1009
#define MEDIA_BUS_FMT_RBG888_1X24 0x100e
#define MEDIA_BUS_FMT_RGB666_1X24_CPADHI 0x1015
#define MEDIA_BUS_FMT_RGB666_1X7X3_SPWG 0x1010
#define MEDIA_BUS_FMT_BGR888_1X24 0x1013
#define MEDIA_BUS_FMT_BGR888_3X8 0x101b
#define MEDIA_BUS_FMT_GBR888_1X24 0x1014
#define MEDIA_BUS_FMT_RGB888_1X24 0x100a
#define MEDIA_BUS_FMT_RGB888_2X12_BE 0x100b
#define MEDIA_BUS_FMT_RGB888_2X12_LE 0x100c
#define MEDIA_BUS_FMT_RGB888_3X8 0x101c
#define MEDIA_BUS_FMT_RGB888_3X8_DELTA 0x101d
#define MEDIA_BUS_FMT_RGB888_1X7X4_SPWG 0x1011
#define MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA 0x1012
#define MEDIA_BUS_FMT_ARGB8888_1X32 0x100d
#define MEDIA_BUS_FMT_RGB888_1X32_PADHI 0x100f
#define MEDIA_BUS_FMT_RGB101010_1X30 0x1018
#define MEDIA_BUS_FMT_RGB121212_1X36 0x1019
#define MEDIA_BUS_FMT_RGB161616_1X48 0x101a
/* YUV (including grey) - next is 0x202e */
#define MEDIA_BUS_FMT_Y8_1X8 0x2001
#define MEDIA_BUS_FMT_UV8_1X8 0x2015
#define MEDIA_BUS_FMT_UYVY8_1_5X8 0x2002
#define MEDIA_BUS_FMT_VYUY8_1_5X8 0x2003
#define MEDIA_BUS_FMT_YUYV8_1_5X8 0x2004
#define MEDIA_BUS_FMT_YVYU8_1_5X8 0x2005
#define MEDIA_BUS_FMT_UYVY8_2X8 0x2006
#define MEDIA_BUS_FMT_VYUY8_2X8 0x2007
#define MEDIA_BUS_FMT_YUYV8_2X8 0x2008
#define MEDIA_BUS_FMT_YVYU8_2X8 0x2009
#define MEDIA_BUS_FMT_Y10_1X10 0x200a
#define MEDIA_BUS_FMT_Y10_2X8_PADHI_LE 0x202c
#define MEDIA_BUS_FMT_UYVY10_2X10 0x2018
#define MEDIA_BUS_FMT_VYUY10_2X10 0x2019
#define MEDIA_BUS_FMT_YUYV10_2X10 0x200b
#define MEDIA_BUS_FMT_YVYU10_2X10 0x200c
#define MEDIA_BUS_FMT_Y12_1X12 0x2013
#define MEDIA_BUS_FMT_UYVY12_2X12 0x201c
#define MEDIA_BUS_FMT_VYUY12_2X12 0x201d
#define MEDIA_BUS_FMT_YUYV12_2X12 0x201e
#define MEDIA_BUS_FMT_YVYU12_2X12 0x201f
#define MEDIA_BUS_FMT_Y14_1X14 0x202d
#define MEDIA_BUS_FMT_UYVY8_1X16 0x200f
#define MEDIA_BUS_FMT_VYUY8_1X16 0x2010
#define MEDIA_BUS_FMT_YUYV8_1X16 0x2011
#define MEDIA_BUS_FMT_YVYU8_1X16 0x2012
#define MEDIA_BUS_FMT_YDYUYDYV8_1X16 0x2014
#define MEDIA_BUS_FMT_UYVY10_1X20 0x201a
#define MEDIA_BUS_FMT_VYUY10_1X20 0x201b
#define MEDIA_BUS_FMT_YUYV10_1X20 0x200d
#define MEDIA_BUS_FMT_YVYU10_1X20 0x200e
#define MEDIA_BUS_FMT_VUY8_1X24 0x2024
#define MEDIA_BUS_FMT_YUV8_1X24 0x2025
#define MEDIA_BUS_FMT_UYYVYY8_0_5X24 0x2026
#define MEDIA_BUS_FMT_UYVY12_1X24 0x2020
#define MEDIA_BUS_FMT_VYUY12_1X24 0x2021
#define MEDIA_BUS_FMT_YUYV12_1X24 0x2022
#define MEDIA_BUS_FMT_YVYU12_1X24 0x2023
#define MEDIA_BUS_FMT_YUV10_1X30 0x2016
#define MEDIA_BUS_FMT_UYYVYY10_0_5X30 0x2027
#define MEDIA_BUS_FMT_AYUV8_1X32 0x2017
#define MEDIA_BUS_FMT_UYYVYY12_0_5X36 0x2028
#define MEDIA_BUS_FMT_YUV12_1X36 0x2029
#define MEDIA_BUS_FMT_YUV16_1X48 0x202a
#define MEDIA_BUS_FMT_UYYVYY16_0_5X48 0x202b
/* Bayer - next is 0x3021 */
#define MEDIA_BUS_FMT_SBGGR8_1X8 0x3001
#define MEDIA_BUS_FMT_SGBRG8_1X8 0x3013
#define MEDIA_BUS_FMT_SGRBG8_1X8 0x3002
#define MEDIA_BUS_FMT_SRGGB8_1X8 0x3014
#define MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8 0x3015
#define MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8 0x3016
#define MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8 0x3017
#define MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8 0x3018
#define MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8 0x300b
#define MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8 0x300c
#define MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8 0x3009
#define MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8 0x300d
#define MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE 0x3003
#define MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE 0x3004
#define MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE 0x3005
#define MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE 0x3006
#define MEDIA_BUS_FMT_SBGGR10_1X10 0x3007
#define MEDIA_BUS_FMT_SGBRG10_1X10 0x300e
#define MEDIA_BUS_FMT_SGRBG10_1X10 0x300a
#define MEDIA_BUS_FMT_SRGGB10_1X10 0x300f
#define MEDIA_BUS_FMT_SBGGR12_1X12 0x3008
#define MEDIA_BUS_FMT_SGBRG12_1X12 0x3010
#define MEDIA_BUS_FMT_SGRBG12_1X12 0x3011
#define MEDIA_BUS_FMT_SRGGB12_1X12 0x3012
#define MEDIA_BUS_FMT_SBGGR14_1X14 0x3019
#define MEDIA_BUS_FMT_SGBRG14_1X14 0x301a
#define MEDIA_BUS_FMT_SGRBG14_1X14 0x301b
#define MEDIA_BUS_FMT_SRGGB14_1X14 0x301c
#define MEDIA_BUS_FMT_SBGGR16_1X16 0x301d
#define MEDIA_BUS_FMT_SGBRG16_1X16 0x301e
#define MEDIA_BUS_FMT_SGRBG16_1X16 0x301f
#define MEDIA_BUS_FMT_SRGGB16_1X16 0x3020
/* JPEG compressed formats - next is 0x4002 */
#define MEDIA_BUS_FMT_JPEG_1X8 0x4001
/* Vendor specific formats - next is 0x5002 */
/* S5C73M3 sensor specific interleaved UYVY and JPEG */
#define MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8 0x5001
/* HSV - next is 0x6002 */
#define MEDIA_BUS_FMT_AHSV8888_1X32 0x6001
/*
* This format should be used when the same driver handles
* both sides of the link and the bus format is a fixed
* metadata format that is not configurable from userspace.
* Width and height will be set to 0 for this format.
*/
#define MEDIA_BUS_FMT_METADATA_FIXED 0x7001
#endif /* __LINUX_MEDIA_BUS_FORMAT_H */

419
linux/media.h Normal file
View File

@@ -0,0 +1,419 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Multimedia device API
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
#ifndef __LINUX_MEDIA_H
#define __LINUX_MEDIA_H
#include <stdint.h>
#include <linux/ioctl.h>
#include <linux/types.h>
struct media_device_info {
char driver[16];
char model[32];
char serial[40];
char bus_info[32];
__u32 media_version;
__u32 hw_revision;
__u32 driver_version;
__u32 reserved[31];
};
/*
* Base number ranges for entity functions
*
* NOTE: Userspace should not rely on these ranges to identify a group
* of function types, as newer functions can be added with any name within
* the full u32 range.
*
* Some older functions use the MEDIA_ENT_F_OLD_*_BASE range. Do not
* change this, this is for backwards compatibility. When adding new
* functions always use MEDIA_ENT_F_BASE.
*/
#define MEDIA_ENT_F_BASE 0x00000000
#define MEDIA_ENT_F_OLD_BASE 0x00010000
#define MEDIA_ENT_F_OLD_SUBDEV_BASE 0x00020000
/*
* Initial value to be used when a new entity is created
* Drivers should change it to something useful.
*/
#define MEDIA_ENT_F_UNKNOWN MEDIA_ENT_F_BASE
/*
* Subdevs are initialized with MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN in order
* to preserve backward compatibility. Drivers must change to the proper
* subdev type before registering the entity.
*/
#define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN MEDIA_ENT_F_OLD_SUBDEV_BASE
/*
* DVB entity functions
*/
#define MEDIA_ENT_F_DTV_DEMOD (MEDIA_ENT_F_BASE + 0x00001)
#define MEDIA_ENT_F_TS_DEMUX (MEDIA_ENT_F_BASE + 0x00002)
#define MEDIA_ENT_F_DTV_CA (MEDIA_ENT_F_BASE + 0x00003)
#define MEDIA_ENT_F_DTV_NET_DECAP (MEDIA_ENT_F_BASE + 0x00004)
/*
* I/O entity functions
*/
#define MEDIA_ENT_F_IO_V4L (MEDIA_ENT_F_OLD_BASE + 1)
#define MEDIA_ENT_F_IO_DTV (MEDIA_ENT_F_BASE + 0x01001)
#define MEDIA_ENT_F_IO_VBI (MEDIA_ENT_F_BASE + 0x01002)
#define MEDIA_ENT_F_IO_SWRADIO (MEDIA_ENT_F_BASE + 0x01003)
/*
* Sensor functions
*/
#define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
#define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
#define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
/*
* Digital TV, analog TV, radio and/or software defined radio tuner functions.
*
* It is a responsibility of the master/bridge drivers to add connectors
* and links for MEDIA_ENT_F_TUNER. Please notice that some old tuners
* may require the usage of separate I2C chips to decode analog TV signals,
* when the master/bridge chipset doesn't have its own TV standard decoder.
* On such cases, the IF-PLL staging is mapped via one or two entities:
* MEDIA_ENT_F_IF_VID_DECODER and/or MEDIA_ENT_F_IF_AUD_DECODER.
*/
#define MEDIA_ENT_F_TUNER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
/*
* Analog TV IF-PLL decoder functions
*
* It is a responsibility of the master/bridge drivers to create links
* for MEDIA_ENT_F_IF_VID_DECODER and MEDIA_ENT_F_IF_AUD_DECODER.
*/
#define MEDIA_ENT_F_IF_VID_DECODER (MEDIA_ENT_F_BASE + 0x02001)
#define MEDIA_ENT_F_IF_AUD_DECODER (MEDIA_ENT_F_BASE + 0x02002)
/*
* Audio entity functions
*/
#define MEDIA_ENT_F_AUDIO_CAPTURE (MEDIA_ENT_F_BASE + 0x03001)
#define MEDIA_ENT_F_AUDIO_PLAYBACK (MEDIA_ENT_F_BASE + 0x03002)
#define MEDIA_ENT_F_AUDIO_MIXER (MEDIA_ENT_F_BASE + 0x03003)
/*
* Processing entity functions
*/
#define MEDIA_ENT_F_PROC_VIDEO_COMPOSER (MEDIA_ENT_F_BASE + 0x4001)
#define MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER (MEDIA_ENT_F_BASE + 0x4002)
#define MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV (MEDIA_ENT_F_BASE + 0x4003)
#define MEDIA_ENT_F_PROC_VIDEO_LUT (MEDIA_ENT_F_BASE + 0x4004)
#define MEDIA_ENT_F_PROC_VIDEO_SCALER (MEDIA_ENT_F_BASE + 0x4005)
#define MEDIA_ENT_F_PROC_VIDEO_STATISTICS (MEDIA_ENT_F_BASE + 0x4006)
#define MEDIA_ENT_F_PROC_VIDEO_ENCODER (MEDIA_ENT_F_BASE + 0x4007)
#define MEDIA_ENT_F_PROC_VIDEO_DECODER (MEDIA_ENT_F_BASE + 0x4008)
/*
* Switch and bridge entity functions
*/
#define MEDIA_ENT_F_VID_MUX (MEDIA_ENT_F_BASE + 0x5001)
#define MEDIA_ENT_F_VID_IF_BRIDGE (MEDIA_ENT_F_BASE + 0x5002)
/*
* Video decoder/encoder functions
*/
#define MEDIA_ENT_F_ATV_DECODER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
#define MEDIA_ENT_F_DV_DECODER (MEDIA_ENT_F_BASE + 0x6001)
#define MEDIA_ENT_F_DV_ENCODER (MEDIA_ENT_F_BASE + 0x6002)
/* Entity flags */
#define MEDIA_ENT_FL_DEFAULT (1 << 0)
#define MEDIA_ENT_FL_CONNECTOR (1 << 1)
/* OR with the entity id value to find the next entity */
#define MEDIA_ENT_ID_FLAG_NEXT (1U << 31)
struct media_entity_desc {
__u32 id;
char name[32];
__u32 type;
__u32 revision;
__u32 flags;
__u32 group_id;
__u16 pads;
__u16 links;
__u32 reserved[4];
union {
/* Node specifications */
struct {
__u32 major;
__u32 minor;
} dev;
/*
* TODO: this shouldn't have been added without
* actual drivers that use this. When the first real driver
* appears that sets this information, special attention
* should be given whether this information is 1) enough, and
* 2) can deal with udev rules that rename devices. The struct
* dev would not be sufficient for this since that does not
* contain the subdevice information. In addition, struct dev
* can only refer to a single device, and not to multiple (e.g.
* pcm and mixer devices).
*/
struct {
__u32 card;
__u32 device;
__u32 subdevice;
} alsa;
/*
* DEPRECATED: previous node specifications. Kept just to
* avoid breaking compilation. Use media_entity_desc.dev
* instead.
*/
struct {
__u32 major;
__u32 minor;
} v4l;
struct {
__u32 major;
__u32 minor;
} fb;
int dvb;
/* Sub-device specifications */
/* Nothing needed yet */
__u8 raw[184];
};
};
#define MEDIA_PAD_FL_SINK (1 << 0)
#define MEDIA_PAD_FL_SOURCE (1 << 1)
#define MEDIA_PAD_FL_MUST_CONNECT (1 << 2)
struct media_pad_desc {
__u32 entity; /* entity ID */
__u16 index; /* pad index */
__u32 flags; /* pad flags */
__u32 reserved[2];
};
#define MEDIA_LNK_FL_ENABLED (1 << 0)
#define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
#define MEDIA_LNK_FL_DYNAMIC (1 << 2)
#define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
# define MEDIA_LNK_FL_DATA_LINK (0 << 28)
# define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28)
struct media_link_desc {
struct media_pad_desc source;
struct media_pad_desc sink;
__u32 flags;
__u32 reserved[2];
};
struct media_links_enum {
__u32 entity;
/* Should have enough room for pads elements */
struct media_pad_desc *pads;
/* Should have enough room for links elements */
struct media_link_desc *links;
__u32 reserved[4];
};
/* Interface type ranges */
#define MEDIA_INTF_T_DVB_BASE 0x00000100
#define MEDIA_INTF_T_V4L_BASE 0x00000200
/* Interface types */
#define MEDIA_INTF_T_DVB_FE (MEDIA_INTF_T_DVB_BASE)
#define MEDIA_INTF_T_DVB_DEMUX (MEDIA_INTF_T_DVB_BASE + 1)
#define MEDIA_INTF_T_DVB_DVR (MEDIA_INTF_T_DVB_BASE + 2)
#define MEDIA_INTF_T_DVB_CA (MEDIA_INTF_T_DVB_BASE + 3)
#define MEDIA_INTF_T_DVB_NET (MEDIA_INTF_T_DVB_BASE + 4)
#define MEDIA_INTF_T_V4L_VIDEO (MEDIA_INTF_T_V4L_BASE)
#define MEDIA_INTF_T_V4L_VBI (MEDIA_INTF_T_V4L_BASE + 1)
#define MEDIA_INTF_T_V4L_RADIO (MEDIA_INTF_T_V4L_BASE + 2)
#define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
#define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
#define MEDIA_INTF_T_V4L_TOUCH (MEDIA_INTF_T_V4L_BASE + 5)
#define MEDIA_INTF_T_ALSA_BASE 0x00000300
#define MEDIA_INTF_T_ALSA_PCM_CAPTURE (MEDIA_INTF_T_ALSA_BASE)
#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK (MEDIA_INTF_T_ALSA_BASE + 1)
#define MEDIA_INTF_T_ALSA_CONTROL (MEDIA_INTF_T_ALSA_BASE + 2)
/*
* MC next gen API definitions
*/
/*
* Appeared in 4.19.0.
*
* The media_version argument comes from the media_version field in
* struct media_device_info.
*/
#define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \
((media_version) >= ((4 << 16) | (19 << 8) | 0))
struct media_v2_entity {
__u32 id;
char name[64];
__u32 function; /* Main function of the entity */
__u32 flags;
__u32 reserved[5];
} __attribute__ ((packed));
/* Should match the specific fields at media_intf_devnode */
struct media_v2_intf_devnode {
__u32 major;
__u32 minor;
} __attribute__ ((packed));
struct media_v2_interface {
__u32 id;
__u32 intf_type;
__u32 flags;
__u32 reserved[9];
union {
struct media_v2_intf_devnode devnode;
__u32 raw[16];
};
} __attribute__ ((packed));
/*
* Appeared in 4.19.0.
*
* The media_version argument comes from the media_version field in
* struct media_device_info.
*/
#define MEDIA_V2_PAD_HAS_INDEX(media_version) \
((media_version) >= ((4 << 16) | (19 << 8) | 0))
struct media_v2_pad {
__u32 id;
__u32 entity_id;
__u32 flags;
__u32 index;
__u32 reserved[4];
} __attribute__ ((packed));
struct media_v2_link {
__u32 id;
__u32 source_id;
__u32 sink_id;
__u32 flags;
__u32 reserved[6];
} __attribute__ ((packed));
struct media_v2_topology {
__u64 topology_version;
__u32 num_entities;
__u32 reserved1;
__u64 ptr_entities;
__u32 num_interfaces;
__u32 reserved2;
__u64 ptr_interfaces;
__u32 num_pads;
__u32 reserved3;
__u64 ptr_pads;
__u32 num_links;
__u32 reserved4;
__u64 ptr_links;
} __attribute__ ((packed));
/* ioctls */
#define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info)
#define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
#define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum)
#define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc)
#define MEDIA_IOC_G_TOPOLOGY _IOWR('|', 0x04, struct media_v2_topology)
#define MEDIA_IOC_REQUEST_ALLOC _IOR ('|', 0x05, int)
/*
* These ioctls are called on the request file descriptor as returned
* by MEDIA_IOC_REQUEST_ALLOC.
*/
#define MEDIA_REQUEST_IOC_QUEUE _IO('|', 0x80)
#define MEDIA_REQUEST_IOC_REINIT _IO('|', 0x81)
/*
* Legacy symbols used to avoid userspace compilation breakages.
* Do not use any of this in new applications!
*
* Those symbols map the entity function into types and should be
* used only on legacy programs for legacy hardware. Don't rely
* on those for MEDIA_IOC_G_TOPOLOGY.
*/
#define MEDIA_ENT_TYPE_SHIFT 16
#define MEDIA_ENT_TYPE_MASK 0x00ff0000
#define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff
#define MEDIA_ENT_T_DEVNODE_UNKNOWN (MEDIA_ENT_F_OLD_BASE | \
MEDIA_ENT_SUBTYPE_MASK)
#define MEDIA_ENT_T_DEVNODE MEDIA_ENT_F_OLD_BASE
#define MEDIA_ENT_T_DEVNODE_V4L MEDIA_ENT_F_IO_V4L
#define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_F_OLD_BASE + 2)
#define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_F_OLD_BASE + 3)
#define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_F_OLD_BASE + 4)
#define MEDIA_ENT_T_UNKNOWN MEDIA_ENT_F_UNKNOWN
#define MEDIA_ENT_T_V4L2_VIDEO MEDIA_ENT_F_IO_V4L
#define MEDIA_ENT_T_V4L2_SUBDEV MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR MEDIA_ENT_F_CAM_SENSOR
#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH MEDIA_ENT_F_FLASH
#define MEDIA_ENT_T_V4L2_SUBDEV_LENS MEDIA_ENT_F_LENS
#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER MEDIA_ENT_F_ATV_DECODER
#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER MEDIA_ENT_F_TUNER
#define MEDIA_ENT_F_DTV_DECODER MEDIA_ENT_F_DV_DECODER
/*
* There is still no full ALSA support in the media controller. These
* defines should not have been added and we leave them here only
* in case some application tries to use these defines.
*
* The ALSA defines that are in use have been moved into __KERNEL__
* scope. As support gets added to these interface types, they should
* be moved into __KERNEL__ scope with the code that uses them.
*/
#define MEDIA_INTF_T_ALSA_COMPRESS (MEDIA_INTF_T_ALSA_BASE + 3)
#define MEDIA_INTF_T_ALSA_RAWMIDI (MEDIA_INTF_T_ALSA_BASE + 4)
#define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5)
#define MEDIA_INTF_T_ALSA_SEQUENCER (MEDIA_INTF_T_ALSA_BASE + 6)
#define MEDIA_INTF_T_ALSA_TIMER (MEDIA_INTF_T_ALSA_BASE + 7)
/* Obsolete symbol for media_version, no longer used in the kernel */
#define MEDIA_API_VERSION ((0 << 16) | (1 << 8) | 0)
#endif /* __LINUX_MEDIA_H */

108
linux/v4l2-common.h Normal file
View File

@@ -0,0 +1,108 @@
/* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */
/*
* include/linux/v4l2-common.h
*
* Common V4L2 and V4L2 subdev definitions.
*
* Users are advised to #include this file either through videodev2.h
* (V4L2) or through v4l2-subdev.h (V4L2 subdev) rather than to refer
* to this file directly.
*
* Copyright (C) 2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* Alternatively you can redistribute this file under the terms of the
* BSD license as stated below:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __V4L2_COMMON__
#define __V4L2_COMMON__
#include <linux/types.h>
/*
*
* Selection interface definitions
*
*/
/* Current cropping area */
#define V4L2_SEL_TGT_CROP 0x0000
/* Default cropping area */
#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001
/* Cropping bounds */
#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002
/* Native frame size */
#define V4L2_SEL_TGT_NATIVE_SIZE 0x0003
/* Current composing area */
#define V4L2_SEL_TGT_COMPOSE 0x0100
/* Default composing area */
#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101
/* Composing bounds */
#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102
/* Current composing area plus all padding pixels */
#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103
/* Selection flags */
#define V4L2_SEL_FLAG_GE (1 << 0)
#define V4L2_SEL_FLAG_LE (1 << 1)
#define V4L2_SEL_FLAG_KEEP_CONFIG (1 << 2)
struct v4l2_edid {
__u32 pad;
__u32 start_block;
__u32 blocks;
__u32 reserved[5];
__u8 *edid;
};
/* Backward compatibility target definitions --- to be removed. */
#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP
#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE
#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP
#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE
#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS
#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS
/* Backward compatibility flag definitions --- to be removed. */
#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE V4L2_SEL_FLAG_GE
#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE V4L2_SEL_FLAG_LE
#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG V4L2_SEL_FLAG_KEEP_CONFIG
#endif /* __V4L2_COMMON__ */

1643
linux/v4l2-controls.h Normal file

File diff suppressed because it is too large Load Diff

150
linux/v4l2-mediabus.h Normal file
View File

@@ -0,0 +1,150 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Media Bus API header
*
* Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __LINUX_V4L2_MEDIABUS_H
#define __LINUX_V4L2_MEDIABUS_H
#include <linux/media-bus-format.h>
#include <linux/types.h>
#include <linux/videodev2.h>
#define V4L2_MBUS_FRAMEFMT_SET_CSC 0x0001
/**
* struct v4l2_mbus_framefmt - frame format on the media bus
* @width: image width
* @height: image height
* @code: data format code (from enum v4l2_mbus_pixelcode)
* @field: used interlacing type (from enum v4l2_field)
* @colorspace: colorspace of the data (from enum v4l2_colorspace)
* @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding)
* @hsv_enc: HSV encoding of the data (from enum v4l2_hsv_encoding)
* @quantization: quantization of the data (from enum v4l2_quantization)
* @xfer_func: transfer function of the data (from enum v4l2_xfer_func)
* @flags: flags (V4L2_MBUS_FRAMEFMT_*)
* @reserved: reserved bytes that can be later used
*/
struct v4l2_mbus_framefmt {
__u32 width;
__u32 height;
__u32 code;
__u32 field;
__u32 colorspace;
union {
/* enum v4l2_ycbcr_encoding */
__u16 ycbcr_enc;
/* enum v4l2_hsv_encoding */
__u16 hsv_enc;
};
__u16 quantization;
__u16 xfer_func;
__u16 flags;
__u16 reserved[10];
};
/*
* enum v4l2_mbus_pixelcode and its definitions are now deprecated, and
* MEDIA_BUS_FMT_ definitions (defined in media-bus-format.h) should be
* used instead.
*
* New defines should only be added to media-bus-format.h. The
* v4l2_mbus_pixelcode enum is frozen.
*/
#define V4L2_MBUS_FROM_MEDIA_BUS_FMT(name) \
V4L2_MBUS_FMT_ ## name = MEDIA_BUS_FMT_ ## name
enum v4l2_mbus_pixelcode {
V4L2_MBUS_FROM_MEDIA_BUS_FMT(FIXED),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB444_2X8_PADHI_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB444_2X8_PADHI_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB555_2X8_PADHI_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB555_2X8_PADHI_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(BGR565_2X8_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(BGR565_2X8_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB565_2X8_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB565_2X8_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB666_1X18),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB888_1X24),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB888_2X12_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(RGB888_2X12_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(ARGB8888_1X32),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(Y8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UV8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY8_1_5X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY8_1_5X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV8_1_5X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU8_1_5X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY8_2X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY8_2X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV8_2X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU8_2X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(Y10_1X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY10_2X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY10_2X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV10_2X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU10_2X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(Y12_1X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY8_1X16),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY8_1X16),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV8_1X16),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU8_1X16),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YDYUYDYV8_1X16),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY10_1X20),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY10_1X20),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV10_1X20),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU10_1X20),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUV10_1X30),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(AYUV8_1X32),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY12_2X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY12_2X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV12_2X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU12_2X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(UYVY12_1X24),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(VYUY12_1X24),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YUYV12_1X24),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(YVYU12_1X24),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGBRG8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGRBG8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SRGGB8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_ALAW8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGBRG10_ALAW8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGRBG10_ALAW8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SRGGB10_ALAW8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_DPCM8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGBRG10_DPCM8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGRBG10_DPCM8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SRGGB10_DPCM8_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_2X8_PADHI_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_2X8_PADHI_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_2X8_PADLO_BE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_2X8_PADLO_LE),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR10_1X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGBRG10_1X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGRBG10_1X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SRGGB10_1X10),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SBGGR12_1X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGBRG12_1X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SGRBG12_1X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(SRGGB12_1X12),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(JPEG_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(S5C_UYVY_JPEG_1X8),
V4L2_MBUS_FROM_MEDIA_BUS_FMT(AHSV8888_1X32),
};
#endif

209
linux/v4l2-subdev.h Normal file
View File

@@ -0,0 +1,209 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* V4L2 subdev userspace API
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LINUX_V4L2_SUBDEV_H
#define __LINUX_V4L2_SUBDEV_H
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/v4l2-common.h>
#include <linux/v4l2-mediabus.h>
/**
* enum v4l2_subdev_format_whence - Media bus format type
* @V4L2_SUBDEV_FORMAT_TRY: try format, for negotiation only
* @V4L2_SUBDEV_FORMAT_ACTIVE: active format, applied to the device
*/
enum v4l2_subdev_format_whence {
V4L2_SUBDEV_FORMAT_TRY = 0,
V4L2_SUBDEV_FORMAT_ACTIVE = 1,
};
/**
* struct v4l2_subdev_format - Pad-level media bus format
* @which: format type (from enum v4l2_subdev_format_whence)
* @pad: pad number, as reported by the media API
* @format: media bus format (format code and frame size)
*/
struct v4l2_subdev_format {
__u32 which;
__u32 pad;
struct v4l2_mbus_framefmt format;
__u32 reserved[8];
};
/**
* struct v4l2_subdev_crop - Pad-level crop settings
* @which: format type (from enum v4l2_subdev_format_whence)
* @pad: pad number, as reported by the media API
* @rect: pad crop rectangle boundaries
*/
struct v4l2_subdev_crop {
__u32 which;
__u32 pad;
struct v4l2_rect rect;
__u32 reserved[8];
};
#define V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE 0x00000001
#define V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC 0x00000002
#define V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC 0x00000004
#define V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC
#define V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION 0x00000008
/**
* struct v4l2_subdev_mbus_code_enum - Media bus format enumeration
* @pad: pad number, as reported by the media API
* @index: format index during enumeration
* @code: format code (MEDIA_BUS_FMT_ definitions)
* @which: format type (from enum v4l2_subdev_format_whence)
* @flags: flags set by the driver, (V4L2_SUBDEV_MBUS_CODE_*)
*/
struct v4l2_subdev_mbus_code_enum {
__u32 pad;
__u32 index;
__u32 code;
__u32 which;
__u32 flags;
__u32 reserved[7];
};
/**
* struct v4l2_subdev_frame_size_enum - Media bus format enumeration
* @pad: pad number, as reported by the media API
* @index: format index during enumeration
* @code: format code (MEDIA_BUS_FMT_ definitions)
* @which: format type (from enum v4l2_subdev_format_whence)
*/
struct v4l2_subdev_frame_size_enum {
__u32 index;
__u32 pad;
__u32 code;
__u32 min_width;
__u32 max_width;
__u32 min_height;
__u32 max_height;
__u32 which;
__u32 reserved[8];
};
/**
* struct v4l2_subdev_frame_interval - Pad-level frame rate
* @pad: pad number, as reported by the media API
* @interval: frame interval in seconds
*/
struct v4l2_subdev_frame_interval {
__u32 pad;
struct v4l2_fract interval;
__u32 reserved[9];
};
/**
* struct v4l2_subdev_frame_interval_enum - Frame interval enumeration
* @pad: pad number, as reported by the media API
* @index: frame interval index during enumeration
* @code: format code (MEDIA_BUS_FMT_ definitions)
* @width: frame width in pixels
* @height: frame height in pixels
* @interval: frame interval in seconds
* @which: format type (from enum v4l2_subdev_format_whence)
*/
struct v4l2_subdev_frame_interval_enum {
__u32 index;
__u32 pad;
__u32 code;
__u32 width;
__u32 height;
struct v4l2_fract interval;
__u32 which;
__u32 reserved[8];
};
/**
* struct v4l2_subdev_selection - selection info
*
* @which: either V4L2_SUBDEV_FORMAT_ACTIVE or V4L2_SUBDEV_FORMAT_TRY
* @pad: pad number, as reported by the media API
* @target: Selection target, used to choose one of possible rectangles,
* defined in v4l2-common.h; V4L2_SEL_TGT_* .
* @flags: constraint flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*.
* @r: coordinates of the selection window
* @reserved: for future use, set to zero for now
*
* Hardware may use multiple helper windows to process a video stream.
* The structure is used to exchange this selection areas between
* an application and a driver.
*/
struct v4l2_subdev_selection {
__u32 which;
__u32 pad;
__u32 target;
__u32 flags;
struct v4l2_rect r;
__u32 reserved[8];
};
/**
* struct v4l2_subdev_capability - subdev capabilities
* @version: the driver versioning number
* @capabilities: the subdev capabilities, see V4L2_SUBDEV_CAP_*
* @reserved: for future use, set to zero for now
*/
struct v4l2_subdev_capability {
__u32 version;
__u32 capabilities;
__u32 reserved[14];
};
/* The v4l2 sub-device video device node is registered in read-only mode. */
#define V4L2_SUBDEV_CAP_RO_SUBDEV 0x00000001
/* Backwards compatibility define --- to be removed */
#define v4l2_subdev_edid v4l2_edid
#define VIDIOC_SUBDEV_QUERYCAP _IOR('V', 0, struct v4l2_subdev_capability)
#define VIDIOC_SUBDEV_G_FMT _IOWR('V', 4, struct v4l2_subdev_format)
#define VIDIOC_SUBDEV_S_FMT _IOWR('V', 5, struct v4l2_subdev_format)
#define VIDIOC_SUBDEV_G_FRAME_INTERVAL _IOWR('V', 21, struct v4l2_subdev_frame_interval)
#define VIDIOC_SUBDEV_S_FRAME_INTERVAL _IOWR('V', 22, struct v4l2_subdev_frame_interval)
#define VIDIOC_SUBDEV_ENUM_MBUS_CODE _IOWR('V', 2, struct v4l2_subdev_mbus_code_enum)
#define VIDIOC_SUBDEV_ENUM_FRAME_SIZE _IOWR('V', 74, struct v4l2_subdev_frame_size_enum)
#define VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL _IOWR('V', 75, struct v4l2_subdev_frame_interval_enum)
#define VIDIOC_SUBDEV_G_CROP _IOWR('V', 59, struct v4l2_subdev_crop)
#define VIDIOC_SUBDEV_S_CROP _IOWR('V', 60, struct v4l2_subdev_crop)
#define VIDIOC_SUBDEV_G_SELECTION _IOWR('V', 61, struct v4l2_subdev_selection)
#define VIDIOC_SUBDEV_S_SELECTION _IOWR('V', 62, struct v4l2_subdev_selection)
/* The following ioctls are identical to the ioctls in videodev2.h */
#define VIDIOC_SUBDEV_G_STD _IOR('V', 23, v4l2_std_id)
#define VIDIOC_SUBDEV_S_STD _IOW('V', 24, v4l2_std_id)
#define VIDIOC_SUBDEV_ENUMSTD _IOWR('V', 25, struct v4l2_standard)
#define VIDIOC_SUBDEV_G_EDID _IOWR('V', 40, struct v4l2_edid)
#define VIDIOC_SUBDEV_S_EDID _IOWR('V', 41, struct v4l2_edid)
#define VIDIOC_SUBDEV_QUERYSTD _IOR('V', 63, v4l2_std_id)
#define VIDIOC_SUBDEV_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)
#define VIDIOC_SUBDEV_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings)
#define VIDIOC_SUBDEV_ENUM_DV_TIMINGS _IOWR('V', 98, struct v4l2_enum_dv_timings)
#define VIDIOC_SUBDEV_QUERY_DV_TIMINGS _IOR('V', 99, struct v4l2_dv_timings)
#define VIDIOC_SUBDEV_DV_TIMINGS_CAP _IOWR('V', 100, struct v4l2_dv_timings_cap)
#endif

2552
linux/videodev2.h Normal file

File diff suppressed because it is too large Load Diff

50
meson.build Normal file
View File

@@ -0,0 +1,50 @@
project('gst-template', 'c', version : '0.0.0.1', license : 'LGPL')
plugins_install_dir = join_paths(get_option('libdir'), 'gstreamer-1.0')
cc = meson.get_compiler('c')
gst_version = meson.project_version()
api_version = '1.0'
gst_req = '==1.16.2'
gst_dep = dependency('gstreamer-1.0', version : gst_req,
required : true, fallback : ['gstreamer', 'gst_dep'])
gstvideo_dep = dependency('gstreamer-video-1.0', version : gst_req,
fallback : ['gst-plugins-base', 'video_dep'])
gstbase_dep = dependency('gstreamer-base-1.0', version : gst_req,
fallback : ['gstreamer', 'gst_base_dep'])
gstpluginsbase_dep = dependency('gstreamer-plugins-base-1.0', version : gst_req,
fallback : ['gst-plugins-base', 'gst_dep'])
threads_dep = dependency('threads')
plugin_c_args = ['-DHAVE_CONFIG_H']
cdata = configuration_data()
cdata.set_quoted('PACKAGE_VERSION', gst_version)
cdata.set_quoted('PACKAGE', 'gst-v4l2pinesrc-plugin')
cdata.set_quoted('GST_LICENSE', 'LGPL')
cdata.set_quoted('GST_API_VERSION', api_version)
cdata.set_quoted('GST_PACKAGE_NAME', 'GStreamer Pine64 pinephone camera v4l2 plug-in')
cdata.set_quoted('GST_PACKAGE_ORIGIN', 'http://www.example.com')
cdata.set_quoted('DATADIR', join_paths(get_option('prefix'), get_option('datadir')))
cdata.set_quoted('SYSCONFDIR', get_option('sysconfdir'))
configure_file(output : 'config.h', configuration : cdata)
# Plugin 1
plugin_sources = [
'pinesrcbin.c'
]
gstpluginexample = library('gstpinesrcbin',
plugin_sources,
c_args: plugin_c_args,
dependencies : [gst_dep, gstbase_dep, gstpluginsbase_dep, gstvideo_dep, threads_dep],
install : true,
install_dir : plugins_install_dir,
)

660
pinesrcbin.c Normal file
View File

@@ -0,0 +1,660 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <gst/gst.h>
#include <glib.h>
#include <linux/media.h>
#include <linux/videodev2.h>
#define GST_TYPE_PINESRCBIN (gst_pinesrcbin_get_type())
#define GST_PINESRCBIN(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINESRCBIN, GstPineSrcBin))
#define GST_PINE64SRCBIN_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PINESRCBIN, GstPineSrcBinClass))
#define GST_IS_PINESRCBIN(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINESRCBIN))
#define GST_IS_PINESRCBIN_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINESRCBIN))
#define GST_PINESRCBIN_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINESRCBIN, GstPineSrcBinClass))
#define gst_pinesrcbin_parent_class parent_class
#define DEFAULT_SYNC TRUE
enum
{
PROP_0,
PROP_CAPS,
PROP_SYNC,
};
struct device_data;
typedef struct _GstPineSrcBin
{
GstBin parent;
GList *media_list;
struct device_data *media_if;
/* configuration for subclasses */
const gchar *media_klass; /* Audio/Video/... */
GstElementFlags flag; /* GST_ELEMENT_FLAG_{SINK/SOURCE} */
/* explicit pointers to stuff used */
GstPad *pad;
GstCaps *filter_caps;
gboolean sync;
/* < private > */
GstElement *kid;
gboolean has_sync;
const gchar *type_klass; /* Source/Sink */
const gchar *media_klass_lc, *type_klass_lc; /* lower case versions */
const struct media_v2_entity *v4l2entity;
const struct media_v2_pad *v4l2pad;
const struct media_v2_interface *v4l2interface;
char devnode_path[260];
int fd;
gboolean autofocus;
int gain_ctrl;
int gain_max;
} GstPineSrcBin;
typedef struct _GstPineSrcBinClass
{
GstBinClass parent_class;
/*< private > */
/* virtual methods for subclasses */
void (*configure) (GstPineSrcBin * self, GstElement * kid);
GstElement *(*create_fake_element) (GstPineSrcBin * bin);
} GstPineSrcBinClass;
G_DEFINE_TYPE (GstPineSrcBin, gst_pinesrcbin, GST_TYPE_BIN);
static int
xioctl (int fd, int request, void *arg)
{
int r;
do {
r = ioctl (fd, request, arg);
} while (r == -1 && errno == EINTR);
return r;
}
static void
gst_pinesrcbin_clear_kid (GstPineSrcBin * self)
{
if (self->kid) {
gst_element_set_state (self->kid, GST_STATE_NULL);
gst_bin_remove (GST_BIN (self), self->kid);
self->kid = NULL;
}
}
static GstElement *
gst_pinesrcbin_create_fake_element_default (GstPineSrcBin * self)
{
GstElement *fake;
gchar dummy_factory[10], dummy_name[20];
sprintf (dummy_factory, "fake%s", self->type_klass_lc);
sprintf (dummy_name, "fake-%s-%s", self->media_klass_lc, self->type_klass_lc);
fake = gst_element_factory_make (dummy_factory, dummy_name);
g_object_set (fake, "sync", self->sync, NULL);
return fake;
}
static GstElement *
gst_pinesrcbin_create_fake_element (GstPineSrcBin * self)
{
GstPineSrcBinClass *klass = GST_PINESRCBIN_GET_CLASS (self);
GstElement *fake;
if (klass->create_fake_element)
fake = klass->create_fake_element (self);
else
fake = gst_pinesrcbin_create_fake_element_default (self);
return fake;
}
static gboolean
gst_pinesrcbin_attach_ghost_pad (GstPineSrcBin * self)
{
GstPad *target = gst_element_get_static_pad (self->kid, self->type_klass_lc);
gboolean res = gst_ghost_pad_set_target (GST_GHOST_PAD (self->pad), target);
gst_object_unref (target);
return res;
}
static void
gst_pinesrcbin_reset (GstPineSrcBin * self)
{
gst_pinesrcbin_clear_kid (self);
/* placeholder element */
self->kid = gst_pinesrcbin_create_fake_element (self);
gst_bin_add (GST_BIN (self), self->kid);
gst_pinesrcbin_attach_ghost_pad (self);
}
static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw");
static void
gst_pinesrcbin_constructed (GObject * object)
{
GstPineSrcBin *self = GST_PINESRCBIN (object);
if (G_OBJECT_CLASS (parent_class)->constructed)
G_OBJECT_CLASS (parent_class)->constructed (object);
self->type_klass = (self->flag == GST_ELEMENT_FLAG_SINK) ? "Sink" : "Source";
self->filter_caps = gst_static_caps_get (&raw_video_caps);
self->type_klass_lc = (self->flag == GST_ELEMENT_FLAG_SINK) ? "sink" : "src";
self->media_klass_lc = "video";
self->pad = gst_ghost_pad_new_no_target (self->type_klass_lc,
(self->flag == GST_ELEMENT_FLAG_SINK) ? GST_PAD_SINK : GST_PAD_SRC);
gst_element_add_pad (GST_ELEMENT (self), self->pad);
gst_pinesrcbin_reset (self);
GST_OBJECT_FLAG_SET (self, self->flag);
gst_bin_set_suppressed_flags (GST_BIN (self),
GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK);
}
static void
gst_pinesrcbin_dispose (GObject * object)
{
GstPineSrcBin *self = GST_PINESRCBIN (object);
gst_pinesrcbin_clear_kid (self);
if (self->filter_caps)
gst_caps_unref (self->filter_caps);
self->filter_caps = NULL;
G_OBJECT_CLASS (parent_class)->dispose ((GObject *) self);
}
static void
gst_pinesrcbin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstPineSrcBin *self = GST_PINESRCBIN (object);
switch (prop_id) {
case PROP_CAPS:
if (self->filter_caps)
gst_caps_unref (self->filter_caps);
self->filter_caps = gst_caps_copy (gst_value_get_caps (value));
break;
case PROP_SYNC:
self->sync = g_value_get_boolean (value);
if (self->kid && self->has_sync)
g_object_set_property (G_OBJECT (self->kid), pspec->name, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_pinesrcbin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstPineSrcBin *self = GST_PINESRCBIN (object);
switch (prop_id) {
case PROP_CAPS:
gst_value_set_caps (value, self->filter_caps);
break;
case PROP_SYNC:
g_value_set_boolean (value, self->sync);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gst_pinesrcbin_detect (GstPineSrcBin * self)
{
GstElement *kid;
GstPineSrcBinClass *klass = GST_PINESRCBIN_GET_CLASS (self);
gst_pinesrcbin_clear_kid (self);
kid = gst_element_factory_make ("v4l2src", NULL);
#if 0
/* find element */
GST_DEBUG_OBJECT (self, "Creating new kid");
if (!(kid = gst_pinesrcbin_find_best (self)))
#endif
if (!kid)
goto no_sink;
self->has_sync =
g_object_class_find_property (G_OBJECT_GET_CLASS (kid), "sync") != NULL;
if (self->has_sync)
g_object_set (G_OBJECT (kid), "sync", self->sync, NULL);
g_object_set (G_OBJECT (kid), "device", self->devnode_path, NULL);
if (klass->configure) {
klass->configure (self, kid);
}
self->kid = kid;
gst_bin_add (GST_BIN (self), kid);
/* Ensure the child is brought up to the right state to match the parent. */
if (GST_STATE (self->kid) < GST_STATE (self))
gst_element_set_state (self->kid, GST_STATE (self));
/* attach ghost pad */
GST_DEBUG_OBJECT (self, "Re-assigning ghostpad");
if (!gst_pinesrcbin_attach_ghost_pad (self))
goto target_failed;
GST_DEBUG_OBJECT (self, "done changing auto %s %s", self->media_klass_lc,
self->type_klass_lc);
return TRUE;
/* ERRORS */
no_sink:
{
GST_ELEMENT_ERROR (self, LIBRARY, INIT, (NULL),
("Failed to find a supported sink"));
return FALSE;
}
target_failed:
{
GST_ELEMENT_ERROR (self, LIBRARY, INIT, (NULL),
("Failed to set target pad"));
return FALSE;
}
}
static GstStateChangeReturn
gst_pinesrcbin_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstPineSrcBin *sink = GST_PINESRCBIN (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_pinesrcbin_detect (sink))
return GST_STATE_CHANGE_FAILURE;
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
gst_pinesrcbin_reset (sink);
break;
default:
break;
}
return ret;
}
static void
gst_pinesrcbin_class_init (GstPineSrcBinClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *eklass;
gobject_class = G_OBJECT_CLASS (klass);
eklass = GST_ELEMENT_CLASS (klass);
gobject_class->constructed = gst_pinesrcbin_constructed;
gobject_class->dispose = gst_pinesrcbin_dispose;
gobject_class->set_property = gst_pinesrcbin_set_property;
gobject_class->get_property = gst_pinesrcbin_get_property;
eklass->change_state = GST_DEBUG_FUNCPTR (gst_pinesrcbin_change_state);
}
GST_DEBUG_CATEGORY (pinesrcbin_debug);
struct device_data
{
char path[261];
int fd;
struct media_v2_topology topology;
struct media_device_info info;
struct media_v2_entity *entities;
size_t num_entities;
struct media_v2_interface *interfaces;
size_t num_interfaces;
struct media_v2_pad *pads;
size_t num_pads;
struct media_v2_link *links;
size_t num_links;
};
static const struct media_v2_link *
gst_pinesrcbin_get_link_from_entity (struct device_data *dev, uint32_t id)
{
int i;
for (i = 0; i < dev->num_links; i++)
if (dev->links[i].sink_id == id)
return &dev->links[i];
return NULL;
}
static const struct media_v2_interface *
gst_pinesrcbin_get_interface_by_id (struct device_data *dev, uint32_t id)
{
int i;
for (i = 0; i < dev->num_interfaces; i++)
if (dev->interfaces[i].id == id)
return &dev->interfaces[i];
return NULL;
}
static const struct media_v2_interface *
gst_pinesrcbin_get_entity_interface (struct device_data *dev, uint32_t id)
{
const struct media_v2_link *link =
gst_pinesrcbin_get_link_from_entity (dev, id);
g_print ("entity id: %d\n", id);
if (!link)
return NULL;
g_print ("link id: %d %d\n", link->sink_id, link->source_id);
return gst_pinesrcbin_get_interface_by_id (dev, link->source_id);
}
static const struct media_v2_pad *
gst_pinesrcbin_get_pad_from_entity (struct device_data *dev, uint32_t id)
{
int i;
for (i = 0; i < dev->num_pads; i++) {
if (dev->pads[i].entity_id == id)
return &dev->pads[i];
}
return NULL;
}
static const struct media_v2_entity *
gst_pinesrcbin_find_media_entity (struct device_data *dev,
const char *driver_name)
{
int length = strlen (driver_name);
int i;
for (i = 0; i < dev->num_entities; i++)
g_print ("%s: entity: %s:%s\n", dev->path, dev->entities[i].name,
driver_name);
for (i = 0; i < dev->num_entities; i++) {
if (!strncmp (dev->entities[i].name, driver_name, length))
return &dev->entities[i];
}
return NULL;
}
static struct device_data *
gst_pinesrcbin_find_media_device (GstPineSrcBin * self, const char *driver_name)
{
int length = strlen (driver_name);
GList *l = self->media_list;
while (l) {
struct device_data *dev = l->data;
const struct media_device_info *info = &dev->info;
g_print ("device %s:%s:%s\n", dev->path, info->driver, driver_name);
if (!strncmp (info->driver, driver_name, length))
return dev;
l = l->next;
}
return NULL;
}
static gboolean
get_device_path (struct media_v2_intf_devnode devnode, char *path, int length)
{
char uevent_path[256];
snprintf (uevent_path, 256, "/sys/dev/char/%d:%d/uevent", devnode.major,
devnode.minor);
FILE *f = fopen (uevent_path, "r");
if (!f) {
return FALSE;
}
char line[512];
while (fgets (line, 512, f)) {
if (strncmp (line, "DEVNAME=", 8) == 0) {
// Drop newline
int length = strlen (line);
if (line[length - 1] == '\n')
line[length - 1] = '\0';
snprintf (path, length, "/dev/%s", line + 8);
fclose (f);
return TRUE;
}
}
fclose (f);
return FALSE;
}
static gboolean
query_autofocus (int fd)
{
struct v4l2_query_ext_ctrl ctrl = { };
ctrl.id = V4L2_CID_FOCUS_AUTO;
int rc = xioctl (fd, VIDIOC_QUERY_EXT_CTRL, &ctrl);
if (rc < 0)
return FALSE;
return TRUE;
}
static void
setup_gain (int fd, int *gain_ctrl, int *gain_max)
{
struct v4l2_query_ext_ctrl ctrl = { };
ctrl.id = V4L2_CID_GAIN;
int rc = xioctl (fd, VIDIOC_QUERY_EXT_CTRL, &ctrl);
if (rc >= 0) {
*gain_ctrl = ctrl.id;
*gain_max = ctrl.maximum;
return;
}
ctrl.id = V4L2_CID_ANALOGUE_GAIN;
rc = xioctl (fd, VIDIOC_QUERY_EXT_CTRL, &ctrl);
if (rc >= 0) {
*gain_ctrl = ctrl.id;
*gain_max = ctrl.maximum;
return;
}
}
static gboolean
camera_control (int fd, uint32_t id, int request, uint32_t * value)
{
struct v4l2_ext_control ctrl = { };
ctrl.id = id;
ctrl.value = *value;
struct v4l2_ext_controls ctrls = {
.ctrl_class = 0,
.which = V4L2_CTRL_WHICH_CUR_VAL,
.count = 1,
.controls = &ctrl,
};
if (xioctl (fd, request, &ctrls) == -1) {
return TRUE;
}
*value = ctrl.value;
return FALSE;
}
static inline const struct media_v2_pad *
get_device_pad (const struct device_data *dev, uint32_t id)
{
int i;
for (i = 0; i < dev->num_pads; i++) {
if (dev->pads[i].id == id) {
return &dev->pads[i];
}
}
return NULL;
}
/* TODO - get media device pad and video device pad and set up link */
static gboolean
setup_link (const struct device_data *dev, uint32_t source_pad_id,
uint32_t sink_pad_id, gboolean enabled)
{
const struct media_v2_pad *source_pad = get_device_pad (dev, source_pad_id);
g_return_val_if_fail (source_pad, FALSE);
const struct media_v2_pad *sink_pad = get_device_pad (dev, sink_pad_id);
g_return_val_if_fail (sink_pad, FALSE);
struct media_link_desc link = { };
link.flags = enabled ? MEDIA_LNK_FL_ENABLED : 0;
link.source.entity = source_pad->entity_id;
link.source.index = 0;
link.sink.entity = sink_pad->entity_id;
link.sink.index = 0;
if (xioctl (dev->fd, MEDIA_IOC_SETUP_LINK, &link) == -1) {
g_printerr ("MEDIA_IOC_SETUP_LINK: %d %s", errno, strerror (errno));
return FALSE;
}
return TRUE;
}
static void
gst_pinesrcbin_init (GstPineSrcBin * self)
{
self->media_list = NULL;
struct dirent *dir;
g_print ("starting device scan\n");
DIR *d = opendir ("/dev");
while ((dir = readdir (d)) != NULL) {
if (strncmp (dir->d_name, "media", 5) == 0) {
char path[261];
int fd;
snprintf (path, 261, "/dev/%s", dir->d_name);
fd = open (path, O_RDWR);
g_print ("opened device: %s: fd=%d\n", path, fd);
if (fd >= 0) {
int rc = -1;
struct device_data *dev = g_new0 (struct device_data, 1);
if (!dev)
goto out;
dev->fd = fd;
strncpy (dev->path, path, sizeof (dev->path));
g_print ("topology x1\n");
rc = xioctl (dev->fd, MEDIA_IOC_G_TOPOLOGY, &dev->topology);
if (rc < 0) {
g_printerr ("topology x1 error %d %d %s\n", rc,
errno, strerror (errno));
goto out;
}
dev->entities =
calloc (dev->topology.num_entities,
sizeof (struct media_v2_entity));
dev->num_entities = dev->topology.num_entities;
dev->interfaces =
calloc (dev->topology.num_interfaces,
sizeof (struct media_v2_interface));
dev->num_interfaces = dev->topology.num_interfaces;
dev->pads =
calloc (dev->topology.num_pads, sizeof (struct media_v2_pad));
dev->num_pads = dev->topology.num_pads;
dev->links =
calloc (dev->topology.num_links, sizeof (struct media_v2_link));
dev->num_links = dev->topology.num_links;
dev->topology.ptr_entities = (uint64_t) dev->entities;
dev->topology.ptr_interfaces = (uint64_t) dev->interfaces;
dev->topology.ptr_pads = (uint64_t) dev->pads;
dev->topology.ptr_links = (uint64_t) dev->links;
g_print ("topology x2\n");
rc = xioctl (dev->fd, MEDIA_IOC_G_TOPOLOGY, &dev->topology);
if (rc < 0)
goto out;
g_print ("device info\n");
rc = xioctl (dev->fd, MEDIA_IOC_DEVICE_INFO, &dev->info);
if (rc < 0)
goto out;
self->media_list = g_list_append (self->media_list, dev);
g_print ("added device %s %s\n", dev->path, dev->info.driver);
out:
if (rc < 0 && dev)
g_free (dev);
}
}
}
self->media_if = gst_pinesrcbin_find_media_device (self, "sun6i-csi");
if (!self->media_if)
g_printerr ("can't find device sun6i-csi\n");
self->v4l2entity =
gst_pinesrcbin_find_media_entity (self->media_if, "sun6i-csi");
if (!self->v4l2entity)
g_printerr ("can't find entity sun6i-csi\n");
/* This is pad for host controller */
self->v4l2pad =
gst_pinesrcbin_get_pad_from_entity (self->media_if, self->v4l2entity->id);
if (!self->v4l2pad)
g_printerr ("can't find interface pad sun6i-csi\n");
self->v4l2interface =
gst_pinesrcbin_get_entity_interface (self->media_if,
self->v4l2entity->id);
if (!self->v4l2interface)
g_printerr ("can't find interface sun6i-csi\n");
if (!get_device_path (self->v4l2interface->devnode,
self->devnode_path, sizeof (self->devnode_path)))
g_printerr ("Failed to get devnode path\n");
g_print ("devnode: %s\n", self->devnode_path);
/* TODO: source pad? sink pad? */
// setup_link(self->media_if, ,self->v4l2interface->pad_id, false);
self->fd = open (self->devnode_path, O_RDWR);
if (self->fd < 0)
g_printerr ("failed to open %s\n", self->devnode_path);
self->autofocus = FALSE;
if (query_autofocus (self->fd)) {
uint32_t enable = 1U;
g_print ("autofocus possible\n");
self->autofocus = TRUE;
camera_control (self->fd, V4L2_CID_FOCUS_AUTO, VIDIOC_S_EXT_CTRLS, &enable);
}
setup_gain (self->fd, &self->gain_ctrl, &self->gain_max);
self->sync = DEFAULT_SYNC;
}
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (pinesrcbin_debug, "pinesrcbin", 0,
"pinephone v4lsrc camera wrapper");
return gst_element_register (plugin, "pinesrcbin",
GST_RANK_NONE, GST_TYPE_PINESRCBIN);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR,
pinesrcbin,
"pinephone v4lsrc camera wrapper",
plugin_init, "0.0", GST_LICENSE, "pinesrcbin", "omp")