From patchwork Wed Oct 9 23:49:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sheu X-Patchwork-Id: 3013291 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 656439F245 for ; Wed, 9 Oct 2013 23:58:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BB49202B8 for ; Wed, 9 Oct 2013 23:58:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A33D202A7 for ; Wed, 9 Oct 2013 23:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086Ab3JIX6R (ORCPT ); Wed, 9 Oct 2013 19:58:17 -0400 Received: from mail-ie0-f201.google.com ([209.85.223.201]:39570 "EHLO mail-ie0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755191Ab3JIX6Q (ORCPT ); Wed, 9 Oct 2013 19:58:16 -0400 Received: by mail-ie0-f201.google.com with SMTP id tp5so450186ieb.0 for ; Wed, 09 Oct 2013 16:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=86f9IqO+9Any0gETfkPR5gdrA1UmKaMK5Iw8WTMYECo=; b=XL/QGNGPAFOGRI8O0YcSygn4NK/a2Wj32ZLN2Ou7ytHxZNGBxrueHyESoSPccWBCE3 Z8LVoH8yt8E36Tk4I1myUq8pLeQjj+44LEl9ryUZVD7s5+WL6TmrItqFfCbTaKTfKTNa hW5BaGHsmoxV38p+32RtaozR+KBKycTn7vEfYcroWXKUZ49SQ/LWaD/Tx7fZjyrvuRq9 lHJk2JhGWd4e7Ft1OVcCeLny48A0VuBnHz5/oEy0G5y+ho3EzQ4+JB1dOon+D9xzdLTD O7x3M0ehBodSBz0c0UeOaj/qkMeljyivsv0zBdZTeKUdzR1RSoxdmPuuZlTAZANfjjCB IgMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=86f9IqO+9Any0gETfkPR5gdrA1UmKaMK5Iw8WTMYECo=; b=f484UYwSWAkNGfHJ34H7v4pBXRqyoH1S5/BV2CiIXjx5p4rK4cM4SWR5rUwagL2RVf 2ocudzCxZKC7BLujZ09+EjEOzpaIjDnVxQ5X+P4AZa4GLPfH1K8L6EHq6IUodBAOjlVS fr3ZpgQrM4/xUaoXbE5A8Uee2y8zFPvOdVpeHpDhKtoB/xCxK5mvQVK2pdcTNwOoMG9g dtwuRtGv16nT/gN60MT1wsgjj9Inz8n3CBymD0GciHuCq7EoMr7Rv2ZtrKtJVO5dI7Pz egi4gA2770A264kHLsyU83QkhBOoW6Rm/EW+p0Jsh+kX07MPMNH1+93vUasQaImWrFYP 3B7g== X-Gm-Message-State: ALoCoQlhEphQSzWxDwAX17bToixd7NCeIzoEnjwMPh3Gbdih1FJQY1i3tAt0NF7eW/F6or4xEjHUWw5TWg9fS6cw5X0QqShNFSDgQ9WtxZTixGWiwhLHPed/KjEaVM+v57IlqmW2uW07tkWBDPN0RQlvopSPC7M1cokJdJLpg4wsu8BUMgFDWmX6gmitABnq+z877Um0G/N0Fn923NfvQQKgfqpX6xliBg== X-Received: by 10.182.109.200 with SMTP id hu8mr2798802obb.20.1381362636473; Wed, 09 Oct 2013 16:50:36 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id y62si2384675yha.0.1969.12.31.16.00.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 09 Oct 2013 16:50:36 -0700 (PDT) Received: from shortskirt.mtv.corp.google.com (shortskirt.mtv.corp.google.com [172.22.70.255]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 40C645A42EB; Wed, 9 Oct 2013 16:50:36 -0700 (PDT) Received: by shortskirt.mtv.corp.google.com (Postfix, from userid 157237) id EAC88C0A3F; Wed, 9 Oct 2013 16:50:35 -0700 (PDT) From: John Sheu To: linux-media@vger.kernel.org Cc: John Sheu , m.chehab@samsung.com, k.debski@samsung.com, pawel@osciak.com Subject: [PATCH 3/6] [media] s5p-mfc: add support for VIDIOC_{G, S}_CROP to encoder Date: Wed, 9 Oct 2013 16:49:46 -0700 Message-Id: <1381362589-32237-4-git-send-email-sheu@google.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1381362589-32237-1-git-send-email-sheu@google.com> References: <1381362589-32237-1-git-send-email-sheu@google.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow userspace to set the crop rect of the input image buffer to encode. Signed-off-by: John Sheu --- drivers/media/platform/s5p-mfc/s5p_mfc_common.h | 6 ++- drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 7 ++-- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 54 ++++++++++++++++++++++++- drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c | 16 +++++--- 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h index 6920b54..48f706f 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h @@ -428,8 +428,10 @@ struct s5p_mfc_vp8_enc_params { * struct s5p_mfc_enc_params - general encoding parameters */ struct s5p_mfc_enc_params { - u16 width; - u16 height; + u16 crop_left_offset; + u16 crop_right_offset; + u16 crop_top_offset; + u16 crop_bottom_offset; u16 gop_size; enum v4l2_mpeg_video_multi_slice_mode slice_mode; diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c index 8faf969..e99bcb8 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c @@ -334,10 +334,9 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) ctx->state >= MFCINST_HEAD_PARSED && ctx->state < MFCINST_ABORT) { /* This is run on CAPTURE (decode output) */ - /* Width and height are set to the dimensions - of the movie, the buffer is bigger and - further processing stages should crop to this - rectangle. */ + /* Width and height are set to the dimensions of the buffer, + The movie's dimensions may be smaller; the cropping rectangle + required should be queried with VIDIOC_G_CROP. */ pix_mp->width = ctx->buf_width; pix_mp->height = ctx->buf_height; pix_mp->field = V4L2_FIELD_NONE; diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c index 8b24829..4ad9349 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c @@ -1599,7 +1599,57 @@ static int vidioc_g_parm(struct file *file, void *priv, a->parm.output.timeperframe.numerator = ctx->enc_params.rc_framerate_denom; } else { - mfc_err("Setting FPS is only possible for the output queue\n"); + mfc_err("Getting FPS is only possible for the output queue\n"); + return -EINVAL; + } + return 0; +} + +static int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *a) +{ + struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); + struct s5p_mfc_enc_params *p = &ctx->enc_params; + + if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + a->c.left = p->crop_left_offset; + a->c.top = p->crop_top_offset; + a->c.width = ctx->img_width - + (p->crop_left_offset + p->crop_right_offset); + a->c.height = ctx->img_height - + (p->crop_top_offset + p->crop_bottom_offset); + } else { + mfc_err("Getting crop is only possible for the output queue\n"); + return -EINVAL; + } + return 0; +} + +static int vidioc_s_crop(struct file *file, void *priv, + const struct v4l2_crop *a) +{ + struct s5p_mfc_ctx *ctx = fh_to_ctx(priv); + struct s5p_mfc_enc_params *p = &ctx->enc_params; + + if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + int left, right, top, bottom; + left = round_down(a->c.left, 16); + right = ctx->img_width - (left + a->c.width); + top = round_down(a->c.top, 16); + bottom = ctx->img_height - (top + a->c.height); + if (left > ctx->img_width) + left = ctx->img_width; + if (right < 0) + right = 0; + if (top > ctx->img_height) + top = ctx->img_height; + if (bottom < 0) + bottom = 0; + p->crop_left_offset = left; + p->crop_right_offset = right; + p->crop_top_offset = top; + p->crop_bottom_offset = bottom; + } else { + mfc_err("Setting crop is only possible for the output queue\n"); return -EINVAL; } return 0; @@ -1679,6 +1729,8 @@ static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = { .vidioc_streamoff = vidioc_streamoff, .vidioc_s_parm = vidioc_s_parm, .vidioc_g_parm = vidioc_g_parm, + .vidioc_g_crop = vidioc_g_crop, + .vidioc_s_crop = vidioc_s_crop, .vidioc_encoder_cmd = vidioc_encoder_cmd, .vidioc_subscribe_event = vidioc_subscribe_event, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c index 5bf6efd..1bb487c 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c @@ -600,12 +600,16 @@ static int s5p_mfc_set_enc_params(struct s5p_mfc_ctx *ctx) /* height */ WRITEL(ctx->img_height, S5P_FIMV_E_FRAME_HEIGHT_V6); /* 16 align */ - /* cropped width */ - WRITEL(ctx->img_width, S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6); - /* cropped height */ - WRITEL(ctx->img_height, S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6); - /* cropped offset */ - WRITEL(0x0, S5P_FIMV_E_FRAME_CROP_OFFSET_V6); + /* cropped width, pixels */ + WRITEL(ctx->img_width - (p->crop_left_offset + p->crop_right_offset), + S5P_FIMV_E_CROPPED_FRAME_WIDTH_V6); + /* cropped height, pixels */ + WRITEL(ctx->img_height - (p->crop_top_offset + p->crop_bottom_offset), + S5P_FIMV_E_CROPPED_FRAME_HEIGHT_V6); + /* cropped offset, macroblocks */ + WRITEL(((p->crop_left_offset / 16) & 0x2FF) | + (((p->crop_top_offset / 16) & 0x2FF) << 10), + S5P_FIMV_E_FRAME_CROP_OFFSET_V6); /* pictype : IDR period */ reg = 0;