Ejemplo n.º 1
0
static int fimc_cap_s_fmt(struct file *file, void *priv,
			     struct v4l2_format *f)
{
	struct fimc_ctx *ctx = priv;
	struct fimc_dev *fimc = ctx->fimc_dev;
	struct fimc_frame *frame;
	struct v4l2_pix_format *pix;
	int ret;

	if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;

	ret = fimc_vidioc_try_fmt(file, priv, f);
	if (ret)
		return ret;

	if (mutex_lock_interruptible(&fimc->lock))
		return -ERESTARTSYS;

	if (fimc_capture_active(fimc)) {
		ret = -EBUSY;
		goto sf_unlock;
	}

	frame = &ctx->d_frame;

	pix = &f->fmt.pix;
	frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM);
	if (!frame->fmt) {
		err("fimc target format not found\n");
		ret = -EINVAL;
		goto sf_unlock;
	}

	/* Output DMA frame pixel size and offsets. */
	frame->f_width	= pix->bytesperline * 8 / frame->fmt->depth;
	frame->f_height = pix->height;
	frame->width	= pix->width;
	frame->height	= pix->height;
	frame->o_width	= pix->width;
	frame->o_height = pix->height;
	frame->size	= (pix->width * pix->height * frame->fmt->depth) >> 3;
	frame->offs_h	= 0;
	frame->offs_v	= 0;

	ret = sync_capture_fmt(ctx);

	ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);

sf_unlock:
	mutex_unlock(&fimc->lock);
	return ret;
}
Ejemplo n.º 2
0
static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
                                 struct v4l2_format *f)
{
    struct fimc_ctx *ctx = priv;
    struct fimc_dev *fimc = ctx->fimc_dev;
    struct fimc_frame *frame;
    struct v4l2_pix_format_mplane *pix;
    int ret;
    int i;

    if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
        return -EINVAL;

    ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
    if (ret)
        return ret;

    if (vb2_is_busy(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
        return -EBUSY;

    frame = &ctx->d_frame;

    pix = &f->fmt.pix_mp;
    frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM);
    if (!frame->fmt) {
        err("fimc target format not found\n");
        return -EINVAL;
    }

    for (i = 0; i < frame->fmt->colplanes; i++) {
        frame->payload[i] =
            (pix->width * pix->height * frame->fmt->depth[i]) >> 3;
    }

    /* Output DMA frame pixel size and offsets. */
    frame->f_width = pix->plane_fmt[0].bytesperline * 8
                     / frame->fmt->depth[0];
    frame->f_height = pix->height;
    frame->width	= pix->width;
    frame->height	= pix->height;
    frame->o_width	= pix->width;
    frame->o_height = pix->height;
    frame->offs_h	= 0;
    frame->offs_v	= 0;

    ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);

    ret = sync_capture_fmt(ctx);
    return ret;
}