summaryrefslogtreecommitdiffstats
path: root/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c')
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c375
1 files changed, 215 insertions, 160 deletions
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 49d0470f9a7e..ea54cc27e645 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -4,10 +4,11 @@
*
* Copyright © 2013 Raspberry Pi (Trading) Ltd.
*
- * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
- * Dave Stevenson <dsteve@broadcom.com>
- * Simon Mellor <simellor@broadcom.com>
- * Luke Diamand <luked@broadcom.com>
+ * Authors: Vincent Sanders @ Collabora
+ * Dave Stevenson @ Broadcom
+ * (now dave.stevenson@raspberrypi.org)
+ * Simon Mellor @ Broadcom
+ * Luke Diamand @ Broadcom
*/
#include <linux/errno.h>
@@ -79,7 +80,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_I420,
.depth = 12,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 1,
.remove_padding = 1,
}, {
@@ -88,7 +89,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_YUYV,
.depth = 16,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 2,
.remove_padding = 0,
}, {
@@ -97,7 +98,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_RGB24,
.depth = 24,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 3,
.remove_padding = 0,
}, {
@@ -106,7 +107,7 @@ static struct mmal_fmt formats[] = {
.flags = V4L2_FMT_FLAG_COMPRESSED,
.mmal = MMAL_ENCODING_JPEG,
.depth = 8,
- .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
+ .mmal_component = COMP_IMAGE_ENCODE,
.ybbp = 0,
.remove_padding = 0,
}, {
@@ -115,7 +116,7 @@ static struct mmal_fmt formats[] = {
.flags = V4L2_FMT_FLAG_COMPRESSED,
.mmal = MMAL_ENCODING_H264,
.depth = 8,
- .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+ .mmal_component = COMP_VIDEO_ENCODE,
.ybbp = 0,
.remove_padding = 0,
}, {
@@ -124,7 +125,7 @@ static struct mmal_fmt formats[] = {
.flags = V4L2_FMT_FLAG_COMPRESSED,
.mmal = MMAL_ENCODING_MJPEG,
.depth = 8,
- .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+ .mmal_component = COMP_VIDEO_ENCODE,
.ybbp = 0,
.remove_padding = 0,
}, {
@@ -133,7 +134,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_YVYU,
.depth = 16,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 2,
.remove_padding = 0,
}, {
@@ -142,7 +143,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_VYUY,
.depth = 16,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 2,
.remove_padding = 0,
}, {
@@ -151,7 +152,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_UYVY,
.depth = 16,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 2,
.remove_padding = 0,
}, {
@@ -160,7 +161,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_NV12,
.depth = 12,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 1,
.remove_padding = 1,
}, {
@@ -169,7 +170,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_BGR24,
.depth = 24,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 3,
.remove_padding = 0,
}, {
@@ -178,7 +179,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_YV12,
.depth = 12,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 1,
.remove_padding = 1,
}, {
@@ -187,7 +188,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_NV21,
.depth = 12,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 1,
.remove_padding = 1,
}, {
@@ -196,7 +197,7 @@ static struct mmal_fmt formats[] = {
.flags = 0,
.mmal = MMAL_ENCODING_BGRA,
.depth = 32,
- .mmal_component = MMAL_COMPONENT_CAMERA,
+ .mmal_component = COMP_CAMERA,
.ybbp = 4,
.remove_padding = 0,
},
@@ -235,6 +236,22 @@ static int queue_setup(struct vb2_queue *vq,
return -EINVAL;
}
+ /* Handle CREATE_BUFS situation - *nplanes != 0 */
+ if (*nplanes) {
+ if (*nplanes != 1 ||
+ sizes[0] < dev->capture.port->current_buffer.size) {
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "%s: dev:%p Invalid buffer request from CREATE_BUFS, size %u < %u, nplanes %u != 1\n",
+ __func__, dev, sizes[0],
+ dev->capture.port->current_buffer.size,
+ *nplanes);
+ return -EINVAL;
+ } else {
+ return 0;
+ }
+ }
+
+ /* Handle REQBUFS situation */
size = dev->capture.port->current_buffer.size;
if (size == 0) {
v4l2_err(&dev->v4l2_dev,
@@ -312,7 +329,7 @@ static void buffer_cleanup(struct vb2_buffer *vb)
static inline bool is_capturing(struct bm2835_mmal_dev *dev)
{
return dev->capture.camera_port ==
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
}
static void buffer_cb(struct vchiq_mmal_instance *instance,
@@ -327,25 +344,24 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
"%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
__func__, status, buf, length, mmal_flags, pts);
- if (status != 0) {
+ if (status) {
/* error in transfer */
if (buf) {
/* there was a buffer with the error so return it */
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
}
return;
- } else if (length == 0) {
+ }
+
+ if (length == 0) {
/* stream ended */
- if (buf) {
- /* this should only ever happen if the port is
- * disabled and there are buffers still queued
+ if (dev->capture.frame_count) {
+ /* empty buffer whilst capturing - expected to be an
+ * EOS, so grab another frame
*/
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
- pr_debug("Empty buffer");
- } else if (dev->capture.frame_count) {
- /* grab another frame */
if (is_capturing(dev)) {
- pr_debug("Grab another frame");
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Grab another frame");
vchiq_mmal_port_parameter_set(
instance,
dev->capture.camera_port,
@@ -353,48 +369,60 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
&dev->capture.frame_count,
sizeof(dev->capture.frame_count));
}
+ if (vchiq_mmal_submit_buffer(instance, port, buf))
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Failed to return EOS buffer");
} else {
- /* signal frame completion */
+ /* stopping streaming.
+ * return buffer, and signal frame completion
+ */
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
complete(&dev->capture.frame_cmplt);
}
+ return;
+ }
+
+ if (!dev->capture.frame_count) {
+ /* signal frame completion */
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
+ complete(&dev->capture.frame_cmplt);
+ return;
+ }
+
+ if (dev->capture.vc_start_timestamp != -1 && pts) {
+ ktime_t timestamp;
+ s64 runtime_us = pts -
+ dev->capture.vc_start_timestamp;
+ timestamp = ktime_add_us(dev->capture.kernel_start_ts,
+ runtime_us);
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Convert start time %llu and %llu with offset %llu to %llu\n",
+ ktime_to_ns(dev->capture.kernel_start_ts),
+ dev->capture.vc_start_timestamp, pts,
+ ktime_to_ns(timestamp));
+ buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
} else {
- if (dev->capture.frame_count) {
- if (dev->capture.vc_start_timestamp != -1 &&
- pts != 0) {
- ktime_t timestamp;
- s64 runtime_us = pts -
- dev->capture.vc_start_timestamp;
- timestamp = ktime_add_us(dev->capture.kernel_start_ts,
- runtime_us);
- v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
- "Convert start time %llu and %llu with offset %llu to %llu\n",
- ktime_to_ns(dev->capture.kernel_start_ts),
- dev->capture.vc_start_timestamp, pts,
- ktime_to_ns(timestamp));
- buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
- } else {
- buf->vb.vb2_buf.timestamp = ktime_get_ns();
- }
+ buf->vb.vb2_buf.timestamp = ktime_get_ns();
+ }
+ buf->vb.sequence = dev->capture.sequence++;
+ buf->vb.field = V4L2_FIELD_NONE;
- vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+ vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
+ if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
+ buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME;
- if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
- is_capturing(dev)) {
- v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
- "Grab another frame as buffer has EOS");
- vchiq_mmal_port_parameter_set(
- instance,
- dev->capture.camera_port,
- MMAL_PARAMETER_CAPTURE,
- &dev->capture.frame_count,
- sizeof(dev->capture.frame_count));
- }
- } else {
- /* signal frame completion */
- vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
- complete(&dev->capture.frame_cmplt);
- }
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
+
+ if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
+ is_capturing(dev)) {
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Grab another frame as buffer has EOS");
+ vchiq_mmal_port_parameter_set(
+ instance,
+ dev->capture.camera_port,
+ MMAL_PARAMETER_CAPTURE,
+ &dev->capture.frame_count,
+ sizeof(dev->capture.frame_count));
}
}
@@ -405,7 +433,7 @@ static int enable_camera(struct bm2835_mmal_dev *dev)
if (!dev->camera_use_count) {
ret = vchiq_mmal_port_parameter_set(
dev->instance,
- &dev->component[MMAL_COMPONENT_CAMERA]->control,
+ &dev->component[COMP_CAMERA]->control,
MMAL_PARAMETER_CAMERA_NUM, &dev->camera_num,
sizeof(dev->camera_num));
if (ret < 0) {
@@ -416,7 +444,7 @@ static int enable_camera(struct bm2835_mmal_dev *dev)
ret = vchiq_mmal_component_enable(
dev->instance,
- dev->component[MMAL_COMPONENT_CAMERA]);
+ dev->component[COMP_CAMERA]);
if (ret < 0) {
v4l2_err(&dev->v4l2_dev,
"Failed enabling camera, ret %d\n", ret);
@@ -448,7 +476,7 @@ static int disable_camera(struct bm2835_mmal_dev *dev)
ret =
vchiq_mmal_component_disable(
dev->instance,
- dev->component[MMAL_COMPONENT_CAMERA]);
+ dev->component[COMP_CAMERA]);
if (ret < 0) {
v4l2_err(&dev->v4l2_dev,
"Failed disabling camera, ret %d\n", ret);
@@ -456,7 +484,7 @@ static int disable_camera(struct bm2835_mmal_dev *dev)
}
vchiq_mmal_port_parameter_set(
dev->instance,
- &dev->component[MMAL_COMPONENT_CAMERA]->control,
+ &dev->component[COMP_CAMERA]->control,
MMAL_PARAMETER_CAMERA_NUM, &i,
sizeof(i));
}
@@ -505,10 +533,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
/* enable frame capture */
dev->capture.frame_count = 1;
+ /* reset sequence number */
+ dev->capture.sequence = 0;
+
/* if the preview is not already running, wait for a few frames for AGC
* to settle down.
*/
- if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
+ if (!dev->component[COMP_PREVIEW]->enabled)
msleep(300);
/* enable the connection from camera to encoder (if applicable) */
@@ -536,10 +567,11 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
/* Flag to indicate just to rely on kernel timestamps */
dev->capture.vc_start_timestamp = -1;
- } else
+ } else {
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
"Start time %lld size %d\n",
dev->capture.vc_start_timestamp, parameter_size);
+ }
dev->capture.kernel_start_ts = ktime_get();
@@ -549,8 +581,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
if (ret) {
v4l2_err(&dev->v4l2_dev,
- "Failed to enable capture port - error %d. Disabling camera port again\n",
- ret);
+ "Failed to enable capture port - error %d. Disabling camera port again\n",
+ ret);
vchiq_mmal_port_disable(dev->instance,
dev->capture.camera_port);
@@ -576,6 +608,7 @@ static void stop_streaming(struct vb2_queue *vq)
int ret;
unsigned long timeout;
struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
+ struct vchiq_mmal_port *port = dev->capture.port;
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
__func__, dev);
@@ -599,12 +632,6 @@ static void stop_streaming(struct vb2_queue *vq)
&dev->capture.frame_count,
sizeof(dev->capture.frame_count));
- /* wait for last frame to complete */
- timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
- if (timeout == 0)
- v4l2_err(&dev->v4l2_dev,
- "timed out waiting for frame completion\n");
-
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
"disabling connection\n");
@@ -619,6 +646,21 @@ static void stop_streaming(struct vb2_queue *vq)
ret);
}
+ /* wait for all buffers to be returned */
+ while (atomic_read(&port->buffers_with_vpu)) {
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "%s: Waiting for buffers to be returned - %d outstanding\n",
+ __func__, atomic_read(&port->buffers_with_vpu));
+ timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt,
+ HZ);
+ if (timeout == 0) {
+ v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
+ __func__,
+ atomic_read(&port->buffers_with_vpu));
+ break;
+ }
+ }
+
if (disable_camera(dev) < 0)
v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
}
@@ -730,9 +772,9 @@ static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
vidioc_try_fmt_vid_overlay(file, priv, f);
dev->overlay = f->fmt.win;
- if (dev->component[MMAL_COMPONENT_PREVIEW]->enabled) {
+ if (dev->component[COMP_PREVIEW]->enabled) {
set_overlay_params(dev,
- &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
+ &dev->component[COMP_PREVIEW]->input[0]);
}
return 0;
@@ -745,12 +787,12 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on)
struct vchiq_mmal_port *src;
struct vchiq_mmal_port *dst;
- if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
- (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
+ if ((on && dev->component[COMP_PREVIEW]->enabled) ||
+ (!on && !dev->component[COMP_PREVIEW]->enabled))
return 0; /* already in requested state */
src =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
if (!on) {
/* disconnect preview ports and disable component */
@@ -762,39 +804,39 @@ static int vidioc_overlay(struct file *file, void *f, unsigned int on)
if (ret >= 0)
ret = vchiq_mmal_component_disable(
dev->instance,
- dev->component[MMAL_COMPONENT_PREVIEW]);
+ dev->component[COMP_PREVIEW]);
disable_camera(dev);
return ret;
}
/* set preview port format and connect it to output */
- dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
+ dst = &dev->component[COMP_PREVIEW]->input[0];
ret = vchiq_mmal_port_set_format(dev->instance, src);
if (ret < 0)
- goto error;
+ return ret;
ret = set_overlay_params(dev, dst);
if (ret < 0)
- goto error;
+ return ret;
if (enable_camera(dev) < 0)
- goto error;
+ return -EINVAL;
ret = vchiq_mmal_component_enable(
dev->instance,
- dev->component[MMAL_COMPONENT_PREVIEW]);
+ dev->component[COMP_PREVIEW]);
if (ret < 0)
- goto error;
+ return ret;
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
src, dst);
ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
- if (!ret)
- ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
-error:
- return ret;
+ if (ret)
+ return ret;
+
+ return vchiq_mmal_port_enable(dev->instance, src, NULL);
}
static int vidioc_g_fbuf(struct file *file, void *fh,
@@ -805,7 +847,7 @@ static int vidioc_g_fbuf(struct file *file, void *fh,
*/
struct bm2835_mmal_dev *dev = video_drvdata(file);
struct vchiq_mmal_port *preview_port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY |
V4L2_FBUF_CAP_GLOBAL_ALPHA;
@@ -826,7 +868,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
struct v4l2_input *inp)
{
/* only a single camera input */
- if (inp->index != 0)
+ if (inp->index)
return -EINVAL;
inp->type = V4L2_INPUT_TYPE_CAMERA;
@@ -842,7 +884,7 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
{
- if (i != 0)
+ if (i)
return -EINVAL;
return 0;
@@ -935,14 +977,27 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1, 0);
f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
if (!mfmt->remove_padding) {
- int align_mask = ((32 * mfmt->depth) >> 3) - 1;
- /* GPU isn't removing padding, so stride is aligned to 32 */
- f->fmt.pix.bytesperline =
- (f->fmt.pix.bytesperline + align_mask) & ~align_mask;
+ if (mfmt->depth == 24) {
+ /*
+ * 24bpp is a pain as we can't use simple masking.
+ * Min stride is width aligned to 16, times 24bpp.
+ */
+ f->fmt.pix.bytesperline =
+ ((f->fmt.pix.width + 15) & ~15) * 3;
+ } else {
+ /*
+ * GPU isn't removing padding, so stride is aligned to
+ * 32
+ */
+ int align_mask = ((32 * mfmt->depth) >> 3) - 1;
+
+ f->fmt.pix.bytesperline =
+ (f->fmt.pix.bytesperline + align_mask) &
+ ~align_mask;
+ }
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
- "Not removing padding, so bytes/line = %d, "
- "(align_mask %d)\n",
- f->fmt.pix.bytesperline, align_mask);
+ "Not removing padding, so bytes/line = %d\n",
+ f->fmt.pix.bytesperline);
}
/* Image buffer has to be padded to allow for alignment, even though
@@ -1003,27 +1058,28 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
}
/* format dependent port setup */
switch (mfmt->mmal_component) {
- case MMAL_COMPONENT_CAMERA:
+ case COMP_CAMERA:
/* Make a further decision on port based on resolution */
if (f->fmt.pix.width <= max_video_width &&
f->fmt.pix.height <= max_video_height)
- camera_port = port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO];
+ camera_port =
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO];
else
- camera_port = port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+ camera_port =
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
+ port = camera_port;
break;
- case MMAL_COMPONENT_IMAGE_ENCODE:
- encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
- port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
+ case COMP_IMAGE_ENCODE:
+ encode_component = dev->component[COMP_IMAGE_ENCODE];
+ port = &dev->component[COMP_IMAGE_ENCODE]->output[0];
camera_port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_CAPTURE];
break;
- case MMAL_COMPONENT_VIDEO_ENCODE:
- encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
- port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+ case COMP_VIDEO_ENCODE:
+ encode_component = dev->component[COMP_VIDEO_ENCODE];
+ port = &dev->component[COMP_VIDEO_ENCODE]->output[0];
camera_port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO];
break;
default:
break;
@@ -1063,13 +1119,13 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
- if (!ret &&
- camera_port ==
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_VIDEO]) {
+ if (!ret
+ && camera_port ==
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_VIDEO]) {
bool overlay_enabled =
- !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
+ !!dev->component[COMP_PREVIEW]->enabled;
struct vchiq_mmal_port *preview_port =
- &dev->component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_PREVIEW];
+ &dev->component[COMP_CAMERA]->output[CAM_PORT_PREVIEW];
/* Preview and encode ports need to match on resolution */
if (overlay_enabled) {
/* Need to disable the overlay before we can update
@@ -1100,7 +1156,7 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
ret = vchiq_mmal_port_connect_tunnel(
dev->instance,
preview_port,
- &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
+ &dev->component[COMP_PREVIEW]->input[0]);
if (!ret)
ret = vchiq_mmal_port_enable(dev->instance,
preview_port,
@@ -1154,11 +1210,11 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
port->format.encoding_variant = 0;
/* Set any encoding specific parameters */
switch (mfmt->mmal_component) {
- case MMAL_COMPONENT_VIDEO_ENCODE:
+ case COMP_VIDEO_ENCODE:
port->format.bitrate =
dev->capture.encode_bitrate;
break;
- case MMAL_COMPONENT_IMAGE_ENCODE:
+ case COMP_IMAGE_ENCODE:
/* Could set EXIF parameters here */
break;
default:
@@ -1202,9 +1258,8 @@ static int mmal_setup_components(struct bm2835_mmal_dev *dev,
port->current_buffer.size);
port->current_buffer.size =
(f->fmt.pix.sizeimage <
- (100 << 10))
- ? (100 << 10)
- : f->fmt.pix.sizeimage;
+ (100 << 10)) ?
+ (100 << 10) : f->fmt.pix.sizeimage;
}
v4l2_dbg(1, bcm2835_v4l2_debug,
&dev->v4l2_dev,
@@ -1277,7 +1332,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
}
ret = mmal_setup_components(dev, f);
- if (ret != 0) {
+ if (ret) {
v4l2_err(&dev->v4l2_dev,
"%s: failed to setup mmal components: %d\n",
__func__, ret);
@@ -1288,7 +1343,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
}
static int vidioc_enum_framesizes(struct file *file, void *fh,
- struct v4l2_frmsizeenum *fsize)
+ struct v4l2_frmsizeenum *fsize)
{
struct bm2835_mmal_dev *dev = video_drvdata(file);
static const struct v4l2_frmsize_stepwise sizes = {
@@ -1529,14 +1584,14 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
/* get the camera component ready */
ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
- &dev->component[MMAL_COMPONENT_CAMERA]);
+ &dev->component[COMP_CAMERA]);
if (ret < 0)
goto unreg_mmal;
- camera = dev->component[MMAL_COMPONENT_CAMERA];
- if (camera->outputs < MMAL_CAMERA_PORT_COUNT) {
+ camera = dev->component[COMP_CAMERA];
+ if (camera->outputs < CAM_PORT_COUNT) {
v4l2_err(&dev->v4l2_dev, "%s: too few camera outputs %d needed %d\n",
- __func__, camera->outputs, MMAL_CAMERA_PORT_COUNT);
+ __func__, camera->outputs, CAM_PORT_COUNT);
ret = -EINVAL;
goto unreg_camera;
}
@@ -1558,7 +1613,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
dev->rgb_bgr_swapped = true;
param_size = sizeof(supported_encodings);
ret = vchiq_mmal_port_parameter_get(dev->instance,
- &camera->output[MMAL_CAMERA_PORT_CAPTURE],
+ &camera->output[CAM_PORT_CAPTURE],
MMAL_PARAMETER_SUPPORTED_ENCODINGS,
&supported_encodings,
&param_size);
@@ -1579,7 +1634,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
}
}
}
- format = &camera->output[MMAL_CAMERA_PORT_PREVIEW].format;
+ format = &camera->output[CAM_PORT_PREVIEW].format;
format->encoding = MMAL_ENCODING_OPAQUE;
format->encoding_variant = MMAL_ENCODING_I420;
@@ -1593,7 +1648,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
format->es->video.frame_rate.num = 0; /* Rely on fps_range */
format->es->video.frame_rate.den = 1;
- format = &camera->output[MMAL_CAMERA_PORT_VIDEO].format;
+ format = &camera->output[CAM_PORT_VIDEO].format;
format->encoding = MMAL_ENCODING_OPAQUE;
format->encoding_variant = MMAL_ENCODING_I420;
@@ -1607,7 +1662,7 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
format->es->video.frame_rate.num = 0; /* Rely on fps_range */
format->es->video.frame_rate.den = 1;
- format = &camera->output[MMAL_CAMERA_PORT_CAPTURE].format;
+ format = &camera->output[CAM_PORT_CAPTURE].format;
format->encoding = MMAL_ENCODING_OPAQUE;
@@ -1631,49 +1686,49 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
/* get the preview component ready */
ret = vchiq_mmal_component_init(
dev->instance, "ril.video_render",
- &dev->component[MMAL_COMPONENT_PREVIEW]);
+ &dev->component[COMP_PREVIEW]);
if (ret < 0)
goto unreg_camera;
- if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
+ if (dev->component[COMP_PREVIEW]->inputs < 1) {
ret = -EINVAL;
v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
- __func__, dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
+ __func__, dev->component[COMP_PREVIEW]->inputs, 1);
goto unreg_preview;
}
/* get the image encoder component ready */
ret = vchiq_mmal_component_init(
dev->instance, "ril.image_encode",
- &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+ &dev->component[COMP_IMAGE_ENCODE]);
if (ret < 0)
goto unreg_preview;
- if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
+ if (dev->component[COMP_IMAGE_ENCODE]->inputs < 1) {
ret = -EINVAL;
v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
- __func__, dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
+ __func__, dev->component[COMP_IMAGE_ENCODE]->inputs,
1);
goto unreg_image_encoder;
}
/* get the video encoder component ready */
ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
- &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+ &dev->component[COMP_VIDEO_ENCODE]);
if (ret < 0)
goto unreg_image_encoder;
- if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
+ if (dev->component[COMP_VIDEO_ENCODE]->inputs < 1) {
ret = -EINVAL;
v4l2_err(&dev->v4l2_dev, "%s: too few input ports %d needed %d\n",
- __func__, dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
+ __func__, dev->component[COMP_VIDEO_ENCODE]->inputs,
1);
goto unreg_vid_encoder;
}
{
struct vchiq_mmal_port *encoder_port =
- &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
+ &dev->component[COMP_VIDEO_ENCODE]->output[0];
encoder_port->format.encoding = MMAL_ENCODING_H264;
ret = vchiq_mmal_port_set_format(dev->instance,
encoder_port);
@@ -1684,12 +1739,12 @@ static int mmal_init(struct bm2835_mmal_dev *dev)
vchiq_mmal_port_parameter_set(
dev->instance,
- &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
+ &dev->component[COMP_VIDEO_ENCODE]->control,
MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
&enable, sizeof(enable));
vchiq_mmal_port_parameter_set(dev->instance,
- &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
+ &dev->component[COMP_VIDEO_ENCODE]->control,
MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
&enable,
sizeof(enable));
@@ -1707,23 +1762,23 @@ unreg_vid_encoder:
pr_err("Cleanup: Destroy video encoder\n");
vchiq_mmal_component_finalise(
dev->instance,
- dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+ dev->component[COMP_VIDEO_ENCODE]);
unreg_image_encoder:
pr_err("Cleanup: Destroy image encoder\n");
vchiq_mmal_component_finalise(
dev->instance,
- dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+ dev->component[COMP_IMAGE_ENCODE]);
unreg_preview:
pr_err("Cleanup: Destroy video render\n");
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_PREVIEW]);
+ dev->component[COMP_PREVIEW]);
unreg_camera:
pr_err("Cleanup: Destroy camera\n");
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_CAMERA]);
+ dev->component[COMP_CAMERA]);
unreg_mmal:
vchiq_mmal_finalise(dev->instance);
@@ -1779,19 +1834,19 @@ static void bcm2835_cleanup_instance(struct bm2835_mmal_dev *dev)
dev->capture.encode_component);
}
vchiq_mmal_component_disable(dev->instance,
- dev->component[MMAL_COMPONENT_CAMERA]);
+ dev->component[COMP_CAMERA]);
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
+ dev->component[COMP_VIDEO_ENCODE]);
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
+ dev->component[COMP_IMAGE_ENCODE]);
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_PREVIEW]);
+ dev->component[COMP_PREVIEW]);
vchiq_mmal_component_finalise(dev->instance,
- dev->component[MMAL_COMPONENT_CAMERA]);
+ dev->component[COMP_CAMERA]);
v4l2_ctrl_handler_free(&dev->ctrl_handler);