提交 7b3ad5ab 编写于 作者: E Eric Anholt 提交者: Greg Kroah-Hartman

staging: Import the BCM2835 MMAL-based V4L2 camera driver.

- Supports raw YUV capture, preview, JPEG and H264.
- Uses videobuf2 for data transfer, using dma_buf.
- Uses 3.6.10 timestamping
- Camera power based on use
- Uses immutable input mode on video encoder

This code comes from the Raspberry Pi kernel tree (rpi-4.9.y) as of
a15ba877dab4e61ea3fc7b006e2a73828b083c52.
Signed-off-by: NEric Anholt <eric@anholt.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 50e66ccb
此差异已折叠。
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*
* core driver device
*/
#define V4L2_CTRL_COUNT 29 /* number of v4l controls */
enum {
MMAL_COMPONENT_CAMERA = 0,
MMAL_COMPONENT_PREVIEW,
MMAL_COMPONENT_IMAGE_ENCODE,
MMAL_COMPONENT_VIDEO_ENCODE,
MMAL_COMPONENT_COUNT
};
enum {
MMAL_CAMERA_PORT_PREVIEW = 0,
MMAL_CAMERA_PORT_VIDEO,
MMAL_CAMERA_PORT_CAPTURE,
MMAL_CAMERA_PORT_COUNT
};
#define PREVIEW_LAYER 2
extern int bcm2835_v4l2_debug;
struct bm2835_mmal_dev {
/* v4l2 devices */
struct v4l2_device v4l2_dev;
struct video_device vdev;
struct mutex mutex;
/* controls */
struct v4l2_ctrl_handler ctrl_handler;
struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
enum v4l2_scene_mode scene_mode;
struct mmal_colourfx colourfx;
int hflip;
int vflip;
int red_gain;
int blue_gain;
enum mmal_parameter_exposuremode exposure_mode_user;
enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
/* active exposure mode may differ if selected via a scene mode */
enum mmal_parameter_exposuremode exposure_mode_active;
enum mmal_parameter_exposuremeteringmode metering_mode;
unsigned int manual_shutter_speed;
bool exp_auto_priority;
bool manual_iso_enabled;
uint32_t iso;
/* allocated mmal instance and components */
struct vchiq_mmal_instance *instance;
struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
int camera_use_count;
struct v4l2_window overlay;
struct {
unsigned int width; /* width */
unsigned int height; /* height */
unsigned int stride; /* stride */
unsigned int buffersize; /* buffer size with padding */
struct mmal_fmt *fmt;
struct v4l2_fract timeperframe;
/* H264 encode bitrate */
int encode_bitrate;
/* H264 bitrate mode. CBR/VBR */
int encode_bitrate_mode;
/* H264 profile */
enum v4l2_mpeg_video_h264_profile enc_profile;
/* H264 level */
enum v4l2_mpeg_video_h264_level enc_level;
/* JPEG Q-factor */
int q_factor;
struct vb2_queue vb_vidq;
/* VC start timestamp for streaming */
s64 vc_start_timestamp;
/* Kernel start timestamp for streaming */
struct timeval kernel_start_ts;
struct vchiq_mmal_port *port; /* port being used for capture */
/* camera port being used for capture */
struct vchiq_mmal_port *camera_port;
/* component being used for encode */
struct vchiq_mmal_component *encode_component;
/* number of frames remaining which driver should capture */
unsigned int frame_count;
/* last frame completion */
struct completion frame_cmplt;
} capture;
unsigned int camera_num;
unsigned int max_width;
unsigned int max_height;
unsigned int rgb_bgr_swapped;
};
int bm2835_mmal_init_controls(
struct bm2835_mmal_dev *dev,
struct v4l2_ctrl_handler *hdl);
int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
int set_framerate_params(struct bm2835_mmal_dev *dev);
/* Debug helpers */
#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
{ \
v4l2_dbg(level, debug, dev, \
"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
desc == NULL ? "" : desc, \
(pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
(pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
(pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
}
#define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \
{ \
v4l2_dbg(level, debug, dev, \
"%s: w %u h %u l %u t %u field %u chromakey %06X clip %p " \
"clipcount %u bitmap %p\n", \
desc == NULL ? "" : desc, \
(win_fmt)->w.width, (win_fmt)->w.height, \
(win_fmt)->w.left, (win_fmt)->w.top, \
(win_fmt)->field, \
(win_fmt)->chromakey, \
(win_fmt)->clips, (win_fmt)->clipcount, \
(win_fmt)->bitmap); \
}
此差异已折叠。
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*
* MMAL structures
*
*/
#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
/** Special value signalling that time is not known */
#define MMAL_TIME_UNKNOWN (1LL<<63)
/* mapping between v4l and mmal video modes */
struct mmal_fmt {
char *name;
u32 fourcc; /* v4l2 format id */
int flags; /* v4l2 flags field */
u32 mmal;
int depth;
u32 mmal_component; /* MMAL component index to be used to encode */
u32 ybbp; /* depth of first Y plane for planar formats */
};
/* buffer for one video frame */
struct mmal_buffer {
/* v4l buffer data -- must be first */
struct vb2_v4l2_buffer vb;
/* list of buffers available */
struct list_head list;
void *buffer; /* buffer pointer */
unsigned long buffer_size; /* size of allocated buffer */
};
/* */
struct mmal_colourfx {
s32 enable;
u32 u;
u32 v;
};
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*/
#ifndef MMAL_ENCODINGS_H
#define MMAL_ENCODINGS_H
#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
/** SAND Video (YUVUV128) format, native format understood by VideoCore.
* This format is *not* opaque - if requested you will receive full frames
* of YUV_UV video.
*/
#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
/** VideoCore opaque image format, image handles are returned to
* the host but not the actual image data.
*/
#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
/** An EGL image handle
*/
#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
/* }@ */
/** \name Pre-defined audio encodings */
/* @{ */
#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
/* Pre-defined H264 encoding variants */
/** ISO 14496-10 Annex B byte stream format */
#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
/** ISO 14496-15 AVC stream format */
#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
/** Implicitly delineated NAL units without emulation prevention */
#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
/** \defgroup MmalColorSpace List of pre-defined video color spaces
* This defines a list of common color spaces. This list isn't exhaustive and
* is only provided as a convenience to avoid clients having to use FourCC
* codes directly. However components are allowed to define and use their own
* FourCC codes.
*/
/* @{ */
/** Unknown color space */
#define MMAL_COLOR_SPACE_UNKNOWN 0
/** ITU-R BT.601-5 [SDTV] */
#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
/** ITU-R BT.709-3 [HDTV] */
#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
/** JPEG JFIF */
#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
/** Society of Motion Picture and Television Engineers 240M (1999) */
#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
/** ITU-R BT.470-2 System M */
#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
/** ITU-R BT.470-2 System BG */
#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
/** JPEG JFIF, but with 16..255 luma */
#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
/* @} MmalColorSpace List */
#endif /* MMAL_ENCODINGS_H */
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*/
#ifndef MMAL_MSG_COMMON_H
#define MMAL_MSG_COMMON_H
enum mmal_msg_status {
MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
MMAL_MSG_STATUS_EIO, /**< I/O error */
MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
MMAL_MSG_STATUS_EFAULT, /**< Bad address */
};
struct mmal_rect {
s32 x; /**< x coordinate (from left) */
s32 y; /**< y coordinate (from top) */
s32 width; /**< width */
s32 height; /**< height */
};
struct mmal_rational {
s32 num; /**< Numerator */
s32 den; /**< Denominator */
};
#endif /* MMAL_MSG_COMMON_H */
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*/
#ifndef MMAL_MSG_FORMAT_H
#define MMAL_MSG_FORMAT_H
#include "mmal-msg-common.h"
/* MMAL_ES_FORMAT_T */
struct mmal_audio_format {
u32 channels; /**< Number of audio channels */
u32 sample_rate; /**< Sample rate */
u32 bits_per_sample; /**< Bits per sample */
u32 block_align; /**< Size of a block of data */
};
struct mmal_video_format {
u32 width; /**< Width of frame in pixels */
u32 height; /**< Height of frame in rows of pixels */
struct mmal_rect crop; /**< Visible region of the frame */
struct mmal_rational frame_rate; /**< Frame rate */
struct mmal_rational par; /**< Pixel aspect ratio */
/* FourCC specifying the color space of the video stream. See the
* \ref MmalColorSpace "pre-defined color spaces" for some examples.
*/
u32 color_space;
};
struct mmal_subpicture_format {
u32 x_offset;
u32 y_offset;
};
union mmal_es_specific_format {
struct mmal_audio_format audio;
struct mmal_video_format video;
struct mmal_subpicture_format subpicture;
};
/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
struct mmal_es_format {
u32 type; /* enum mmal_es_type */
u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
u32 encoding_variant; /* FourCC specifying the specific
* encoding variant of the elementary
* stream.
*/
union mmal_es_specific_format *es; /* TODO: pointers in
* message serialisation?!?
*/
/* Type specific
* information for the
* elementary stream
*/
u32 bitrate; /**< Bitrate in bits per second */
u32 flags; /**< Flags describing properties of the elementary stream. */
u32 extradata_size; /**< Size of the codec specific data */
u8 *extradata; /**< Codec specific data */
};
#endif /* MMAL_MSG_FORMAT_H */
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*/
/* MMAL_PORT_TYPE_T */
enum mmal_port_type {
MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
MMAL_PORT_TYPE_CONTROL, /**< Control port */
MMAL_PORT_TYPE_INPUT, /**< Input port */
MMAL_PORT_TYPE_OUTPUT, /**< Output port */
MMAL_PORT_TYPE_CLOCK, /**< Clock port */
};
/** The port is pass-through and doesn't need buffer headers allocated */
#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
/** The port wants to allocate the buffer payloads.
* This signals a preference that payload allocation should be done
* on this port for efficiency reasons. */
#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
/** The port supports format change events.
* This applies to input ports and is used to let the client know
* whether the port supports being reconfigured via a format
* change event (i.e. without having to disable the port). */
#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
/* mmal port structure (MMAL_PORT_T)
*
* most elements are informational only, the pointer values for
* interogation messages are generally provided as additional
* strucures within the message. When used to set values only teh
* buffer_num, buffer_size and userdata parameters are writable.
*/
struct mmal_port {
void *priv; /* Private member used by the framework */
const char *name; /* Port name. Used for debugging purposes (RO) */
u32 type; /* Type of the port (RO) enum mmal_port_type */
u16 index; /* Index of the port in its type list (RO) */
u16 index_all; /* Index of the port in the list of all ports (RO) */
u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
struct mmal_es_format *format; /* Format of the elementary stream */
u32 buffer_num_min; /* Minimum number of buffers the port
* requires (RO). This is set by the
* component.
*/
u32 buffer_size_min; /* Minimum size of buffers the port
* requires (RO). This is set by the
* component.
*/
u32 buffer_alignment_min; /* Minimum alignment requirement for
* the buffers (RO). A value of
* zero means no special alignment
* requirements. This is set by the
* component.
*/
u32 buffer_num_recommended; /* Number of buffers the port
* recommends for optimal
* performance (RO). A value of
* zero means no special
* recommendation. This is set
* by the component.
*/
u32 buffer_size_recommended; /* Size of buffers the port
* recommends for optimal
* performance (RO). A value of
* zero means no special
* recommendation. This is set
* by the component.
*/
u32 buffer_num; /* Actual number of buffers the port will use.
* This is set by the client.
*/
u32 buffer_size; /* Actual maximum size of the buffers that
* will be sent to the port. This is set by
* the client.
*/
void *component; /* Component this port belongs to (Read Only) */
void *userdata; /* Field reserved for use by the client */
u32 capabilities; /* Flags describing the capabilities of a
* port (RO). Bitwise combination of \ref
* portcapabilities "Port capabilities"
* values.
*/
};
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*/
/* all the data structures which serialise the MMAL protocol. note
* these are directly mapped onto the recived message data.
*
* BEWARE: They seem to *assume* pointers are u32 and that there is no
* structure padding!
*
* NOTE: this implementation uses kernel types to ensure sizes. Rather
* than assigning values to enums to force their size the
* implementation uses fixed size types and not the enums (though the
* comments have the actual enum type
*/
#define VC_MMAL_VER 15
#define VC_MMAL_MIN_VER 10
#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
/* max total message size is 512 bytes */
#define MMAL_MSG_MAX_SIZE 512
/* with six 32bit header elements max payload is therefore 488 bytes */
#define MMAL_MSG_MAX_PAYLOAD 488
#include "mmal-msg-common.h"
#include "mmal-msg-format.h"
#include "mmal-msg-port.h"
enum mmal_msg_type {
MMAL_MSG_TYPE_QUIT = 1,
MMAL_MSG_TYPE_SERVICE_CLOSED,
MMAL_MSG_TYPE_GET_VERSION,
MMAL_MSG_TYPE_COMPONENT_CREATE,
MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
MMAL_MSG_TYPE_COMPONENT_ENABLE,
MMAL_MSG_TYPE_COMPONENT_DISABLE,
MMAL_MSG_TYPE_PORT_INFO_GET,
MMAL_MSG_TYPE_PORT_INFO_SET,
MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
MMAL_MSG_TYPE_BUFFER_FROM_HOST,
MMAL_MSG_TYPE_BUFFER_TO_HOST,
MMAL_MSG_TYPE_GET_STATS,
MMAL_MSG_TYPE_PORT_PARAMETER_SET,
MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
MMAL_MSG_TYPE_EVENT_TO_HOST,
MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
MMAL_MSG_TYPE_CONSUME_MEM,
MMAL_MSG_TYPE_LMK, /* 20 */
MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
MMAL_MSG_TYPE_DRM_GET_LHS32,
MMAL_MSG_TYPE_DRM_GET_TIME,
MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
MMAL_MSG_TYPE_HOST_LOG,
MMAL_MSG_TYPE_MSG_LAST
};
/* port action request messages differ depending on the action type */
enum mmal_msg_port_action_type {
MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
};
struct mmal_msg_header {
u32 magic;
u32 type; /** enum mmal_msg_type */
/* Opaque handle to the control service */
struct mmal_control_service *control_service;
struct mmal_msg_context *context; /** a u32 per message context */
u32 status; /** The status of the vchiq operation */
u32 padding;
};
/* Send from VC to host to report version */
struct mmal_msg_version {
u32 flags;
u32 major;
u32 minor;
u32 minimum;
};
/* request to VC to create component */
struct mmal_msg_component_create {
void *client_component; /* component context */
char name[128];
u32 pid; /* For debug */
};
/* reply from VC to component creation request */
struct mmal_msg_component_create_reply {
u32 status; /** enum mmal_msg_status - how does this differ to
* the one in the header?
*/
u32 component_handle; /* VideoCore handle for component */
u32 input_num; /* Number of input ports */
u32 output_num; /* Number of output ports */
u32 clock_num; /* Number of clock ports */
};
/* request to VC to destroy a component */
struct mmal_msg_component_destroy {
u32 component_handle;
};
struct mmal_msg_component_destroy_reply {
u32 status; /** The component destruction status */
};
/* request and reply to VC to enable a component */
struct mmal_msg_component_enable {
u32 component_handle;
};
struct mmal_msg_component_enable_reply {
u32 status; /** The component enable status */
};
/* request and reply to VC to disable a component */
struct mmal_msg_component_disable {
u32 component_handle;
};
struct mmal_msg_component_disable_reply {
u32 status; /** The component disable status */
};
/* request to VC to get port information */
struct mmal_msg_port_info_get {
u32 component_handle; /* component handle port is associated with */
u32 port_type; /* enum mmal_msg_port_type */
u32 index; /* port index to query */
};
/* reply from VC to get port info request */
struct mmal_msg_port_info_get_reply {
u32 status; /** enum mmal_msg_status */
u32 component_handle; /* component handle port is associated with */
u32 port_type; /* enum mmal_msg_port_type */
u32 port_index; /* port indexed in query */
s32 found; /* unused */
u32 port_handle; /**< Handle to use for this port */
struct mmal_port port;
struct mmal_es_format format; /* elementry stream format */
union mmal_es_specific_format es; /* es type specific data */
u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
};
/* request to VC to set port information */
struct mmal_msg_port_info_set {
u32 component_handle;
u32 port_type; /* enum mmal_msg_port_type */
u32 port_index; /* port indexed in query */
struct mmal_port port;
struct mmal_es_format format;
union mmal_es_specific_format es;
u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
};
/* reply from VC to port info set request */
struct mmal_msg_port_info_set_reply {
u32 status;
u32 component_handle; /* component handle port is associated with */
u32 port_type; /* enum mmal_msg_port_type */
u32 index; /* port indexed in query */
s32 found; /* unused */
u32 port_handle; /**< Handle to use for this port */
struct mmal_port port;
struct mmal_es_format format;
union mmal_es_specific_format es;
u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
};
/* port action requests that take a mmal_port as a parameter */
struct mmal_msg_port_action_port {
u32 component_handle;
u32 port_handle;
u32 action; /* enum mmal_msg_port_action_type */
struct mmal_port port;
};
/* port action requests that take handles as a parameter */
struct mmal_msg_port_action_handle {
u32 component_handle;
u32 port_handle;
u32 action; /* enum mmal_msg_port_action_type */
u32 connect_component_handle;
u32 connect_port_handle;
};
struct mmal_msg_port_action_reply {
u32 status; /** The port action operation status */
};
/* MMAL buffer transfer */
/** Size of space reserved in a buffer message for short messages. */
#define MMAL_VC_SHORT_DATA 128
/** Signals that the current payload is the end of the stream of data */
#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
/** Signals that the start of the current payload starts a frame */
#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
/** Signals that the end of the current payload ends a frame */
#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
/** Signals that the current payload contains only complete frames (>1) */
#define MMAL_BUFFER_HEADER_FLAG_FRAME \
(MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
/** Signals that the current payload is a keyframe (i.e. self decodable) */
#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
/** Signals a discontinuity in the stream of data (e.g. after a seek).
* Can be used for instance by a decoder to reset its state */
#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
/** Signals a buffer containing some kind of config data for the component
* (e.g. codec config data) */
#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
/** Signals an encrypted payload */
#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
/** Signals a buffer containing side information */
#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
/** Signals a buffer which is the snapshot/postview image from a stills
* capture
*/
#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
/** Signals a buffer which contains data known to be corrupted */
#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
/** Signals that a buffer failed to be transmitted */
#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
struct mmal_driver_buffer {
u32 magic;
u32 component_handle;
u32 port_handle;
void *client_context;
};
/* buffer header */
struct mmal_buffer_header {
struct mmal_buffer_header *next; /* next header */
void *priv; /* framework private data */
u32 cmd;
void *data;
u32 alloc_size;
u32 length;
u32 offset;
u32 flags;
s64 pts;
s64 dts;
void *type;
void *user_data;
};
struct mmal_buffer_header_type_specific {
union {
struct {
u32 planes;
u32 offset[4];
u32 pitch[4];
u32 flags;
} video;
} u;
};
struct mmal_msg_buffer_from_host {
/* The front 32 bytes of the buffer header are copied
* back to us in the reply to allow for context. This
* area is used to store two mmal_driver_buffer structures to
* allow for multiple concurrent service users.
*/
/* control data */
struct mmal_driver_buffer drvbuf;
/* referenced control data for passthrough buffer management */
struct mmal_driver_buffer drvbuf_ref;
struct mmal_buffer_header buffer_header; /* buffer header itself */
struct mmal_buffer_header_type_specific buffer_header_type_specific;
s32 is_zero_copy;
s32 has_reference;
/** allows short data to be xfered in control message */
u32 payload_in_message;
u8 short_data[MMAL_VC_SHORT_DATA];
};
/* port parameter setting */
#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
struct mmal_msg_port_parameter_set {
u32 component_handle; /* component */
u32 port_handle; /* port */
u32 id; /* Parameter ID */
u32 size; /* Parameter size */
uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
};
struct mmal_msg_port_parameter_set_reply {
u32 status; /** enum mmal_msg_status todo: how does this
* differ to the one in the header?
*/
};
/* port parameter getting */
struct mmal_msg_port_parameter_get {
u32 component_handle; /* component */
u32 port_handle; /* port */
u32 id; /* Parameter ID */
u32 size; /* Parameter size */
};
struct mmal_msg_port_parameter_get_reply {
u32 status; /* Status of mmal_port_parameter_get call */
u32 id; /* Parameter ID */
u32 size; /* Parameter size */
uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
};
/* event messages */
#define MMAL_WORKER_EVENT_SPACE 256
struct mmal_msg_event_to_host {
void *client_component; /* component context */
u32 port_type;
u32 port_num;
u32 cmd;
u32 length;
u8 data[MMAL_WORKER_EVENT_SPACE];
struct mmal_buffer_header *delayed_buffer;
};
/* all mmal messages are serialised through this structure */
struct mmal_msg {
/* header */
struct mmal_msg_header h;
/* payload */
union {
struct mmal_msg_version version;
struct mmal_msg_component_create component_create;
struct mmal_msg_component_create_reply component_create_reply;
struct mmal_msg_component_destroy component_destroy;
struct mmal_msg_component_destroy_reply component_destroy_reply;
struct mmal_msg_component_enable component_enable;
struct mmal_msg_component_enable_reply component_enable_reply;
struct mmal_msg_component_disable component_disable;
struct mmal_msg_component_disable_reply component_disable_reply;
struct mmal_msg_port_info_get port_info_get;
struct mmal_msg_port_info_get_reply port_info_get_reply;
struct mmal_msg_port_info_set port_info_set;
struct mmal_msg_port_info_set_reply port_info_set_reply;
struct mmal_msg_port_action_port port_action_port;
struct mmal_msg_port_action_handle port_action_handle;
struct mmal_msg_port_action_reply port_action_reply;
struct mmal_msg_buffer_from_host buffer_from_host;
struct mmal_msg_port_parameter_set port_parameter_set;
struct mmal_msg_port_parameter_set_reply
port_parameter_set_reply;
struct mmal_msg_port_parameter_get
port_parameter_get;
struct mmal_msg_port_parameter_get_reply
port_parameter_get_reply;
struct mmal_msg_event_to_host event_to_host;
u8 payload[MMAL_MSG_MAX_PAYLOAD];
} u;
};
此差异已折叠。
/*
* Broadcom BM2835 V4L2 driver
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*
* Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
* Dave Stevenson <dsteve@broadcom.com>
* Simon Mellor <simellor@broadcom.com>
* Luke Diamand <luked@broadcom.com>
*
* MMAL interface to VCHIQ message passing
*/
#ifndef MMAL_VCHIQ_H
#define MMAL_VCHIQ_H
#include "mmal-msg-format.h"
#define MAX_PORT_COUNT 4
/* Maximum size of the format extradata. */
#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
struct vchiq_mmal_instance;
enum vchiq_mmal_es_type {
MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
};
/* rectangle, used lots so it gets its own struct */
struct vchiq_mmal_rect {
s32 x;
s32 y;
s32 width;
s32 height;
};
struct vchiq_mmal_port_buffer {
unsigned int num; /* number of buffers */
u32 size; /* size of buffers */
u32 alignment; /* alignment of buffers */
};
struct vchiq_mmal_port;
typedef void (*vchiq_mmal_buffer_cb)(
struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port,
int status, struct mmal_buffer *buffer,
unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
struct vchiq_mmal_port {
bool enabled;
u32 handle;
u32 type; /* port type, cached to use on port info set */
u32 index; /* port index, cached to use on port info set */
/* component port belongs to, allows simple deref */
struct vchiq_mmal_component *component;
struct vchiq_mmal_port *connected; /* port conencted to */
/* buffer info */
struct vchiq_mmal_port_buffer minimum_buffer;
struct vchiq_mmal_port_buffer recommended_buffer;
struct vchiq_mmal_port_buffer current_buffer;
/* stream format */
struct mmal_es_format format;
/* elementry stream format */
union mmal_es_specific_format es;
/* data buffers to fill */
struct list_head buffers;
/* lock to serialise adding and removing buffers from list */
spinlock_t slock;
/* count of how many buffer header refils have failed because
* there was no buffer to satisfy them
*/
int buffer_underflow;
/* callback on buffer completion */
vchiq_mmal_buffer_cb buffer_cb;
/* callback context */
void *cb_ctx;
};
struct vchiq_mmal_component {
bool enabled;
u32 handle; /* VideoCore handle for component */
u32 inputs; /* Number of input ports */
u32 outputs; /* Number of output ports */
u32 clocks; /* Number of clock ports */
struct vchiq_mmal_port control; /* control port */
struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
};
int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
/* Initialise a mmal component and its ports
*
*/
int vchiq_mmal_component_init(
struct vchiq_mmal_instance *instance,
const char *name,
struct vchiq_mmal_component **component_out);
int vchiq_mmal_component_finalise(
struct vchiq_mmal_instance *instance,
struct vchiq_mmal_component *component);
int vchiq_mmal_component_enable(
struct vchiq_mmal_instance *instance,
struct vchiq_mmal_component *component);
int vchiq_mmal_component_disable(
struct vchiq_mmal_instance *instance,
struct vchiq_mmal_component *component);
/* enable a mmal port
*
* enables a port and if a buffer callback provided enque buffer
* headers as apropriate for the port.
*/
int vchiq_mmal_port_enable(
struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port,
vchiq_mmal_buffer_cb buffer_cb);
/* disable a port
*
* disable a port will dequeue any pending buffers
*/
int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port);
int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port,
u32 parameter,
void *value,
u32 value_size);
int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port,
u32 parameter,
void *value,
u32 *value_size);
int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port);
int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *src,
struct vchiq_mmal_port *dst);
int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
u32 *major_out,
u32 *minor_out);
int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_port *port,
struct mmal_buffer *buf);
#endif /* MMAL_VCHIQ_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册