From patchwork Thu Feb 26 15:59:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacek Anaszewski X-Patchwork-Id: 28420 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1YR0s1-0005Nq-Qb; Thu, 26 Feb 2015 17:01:01 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-7) with esmtp id 1YR0rz-0006PU-2T; Thu, 26 Feb 2015 17:01:01 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754445AbbBZQAw (ORCPT + 1 other); Thu, 26 Feb 2015 11:00:52 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:32211 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753933AbbBZQAt (ORCPT ); Thu, 26 Feb 2015 11:00:49 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NKD00A6NZ5B5I40@mailout1.samsung.com> for linux-media@vger.kernel.org; Fri, 27 Feb 2015 01:00:47 +0900 (KST) X-AuditID: cbfee61a-f79c06d000004e71-55-54ef432fcd8a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 4C.E0.20081.F234FE45; Fri, 27 Feb 2015 01:00:47 +0900 (KST) Received: from AMDC2362.DIGITAL.local ([106.120.53.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NKD00448Z32VO60@mmp2.samsung.com>; Fri, 27 Feb 2015 01:00:47 +0900 (KST) From: Jacek Anaszewski To: linux-media@vger.kernel.org Cc: sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, gjasny@googlemail.com, hdegoede@redhat.com, kyungmin.park@samsung.com, Jacek Anaszewski Subject: [v4l-utils PATCH/RFC v5 10/14] mediactl: libv4l2subdev: add support for setting pipeline format Date: Thu, 26 Feb 2015 16:59:20 +0100 Message-id: <1424966364-3647-11-git-send-email-j.anaszewski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1424966364-3647-1-git-send-email-j.anaszewski@samsung.com> References: <1424966364-3647-1-git-send-email-j.anaszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBLMWRmVeSWpSXmKPExsVy+t9jQV195/chBo3ftS2mT5nFaPHm+HQm i96rzxktzja9YbfonLiE3aJnw1ZWi09bvjE5sHs8nTCZ3WN2x0xWj3knAz3e77vK5tG3ZRWj x+dNcgFsUVw2Kak5mWWpRfp2CVwZH/pmshZckal4dK2VqYGxR7yLkZNDQsBEYtGX7WwQtpjE hXvrgWwuDiGB6YwSbdMaGCGcdiaJhx8/gFWxCRhK/HzxmgnEFhGQl3jSewOsg1lgN6PEs+V7 WEESwgJZEjMfzgUrYhFQlbhzCMLmFfCQWDvrJHsXIwfQOgWJOZNsQMKcQOGpXz4xgthCAu4S X98tZ5vAyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRnB4PZPawbiyweIQowAHoxIP b0L2uxAh1sSy4srcQ4wSHMxKIrz61u9DhHhTEiurUovy44tKc1KLDzFKc7AoifMq2beFCAmk J5akZqemFqQWwWSZODilGhiP/pGTfd6o9rnyQ9Ma7sed+rs/eU3pXSjievJ4cVnRqRkTwpgf bblze80DTcmrr0KbY7vz5/0WOxC57K/a1pwzKndCTsp4X35+Z9XJu5czO6cG3T21V5o5ZxNH ry3bRG+tNoW7lhN8/ByCxWq+i3gU/PVXXPlw8/n7308kahiEMGsfrpngwF2oxFKckWioxVxU nAgAr5uu2SsCAAA= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2015.2.26.154818 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' This patch adds a function for setting the media device pipeline format. Signed-off-by: Jacek Anaszewski Acked-by: Kyungmin Park --- utils/media-ctl/libv4l2subdev.c | 61 +++++++++++++++++++++++++++++++++++++++ utils/media-ctl/v4l2subdev.h | 15 ++++++++++ 2 files changed, 76 insertions(+) diff --git a/utils/media-ctl/libv4l2subdev.c b/utils/media-ctl/libv4l2subdev.c index b9a924c..cc3df1e 100644 --- a/utils/media-ctl/libv4l2subdev.c +++ b/utils/media-ctl/libv4l2subdev.c @@ -164,6 +164,67 @@ int v4l2_subdev_set_format(struct media_entity *entity, return 0; } +int v4l2_subdev_apply_pipeline_fmt(struct media_device *media, + struct v4l2_format *fmt) +{ + struct v4l2_mbus_framefmt mbus_fmt = { 0 }; + struct media_entity *entity = media->pipeline; + struct media_pad *pad; + int ret; + + while (entity) { + /* + * Source entity is linked only through a source pad + * and this pad should be used for setting the format. + * For other entities set the format on a sink pad. + */ + pad = entity->pipe_sink_pad ? entity->pipe_sink_pad : + entity->pipe_src_pad; + if (pad == NULL) + return -EINVAL; + + ret = v4l2_subdev_get_format(entity, &mbus_fmt, pad->index, + V4L2_SUBDEV_FORMAT_TRY); + + if (ret < 0) + return ret; + + media_dbg(media, "VIDIOC_SUBDEV_G_FMT %s:%d: mbus_code: %s, width: %d, height: %d\n", + media_entity_get_name(entity), pad->index, + v4l2_subdev_pixelcode_to_string(mbus_fmt.code), + mbus_fmt.width, mbus_fmt.height); + + ret = v4l2_subdev_set_format(entity, &mbus_fmt, pad->index, + V4L2_SUBDEV_FORMAT_ACTIVE); + if (ret < 0) + return ret; + + media_dbg(media, "VIDIOC_SUBDEV_S_FMT %s:%d: mbus_code: %s, width: %d, height: %d\n", + media_entity_get_name(entity), pad->index, + v4l2_subdev_pixelcode_to_string(mbus_fmt.code), + mbus_fmt.width, mbus_fmt.height); + + entity = entity->next; + + /* Last entity in the pipeline is not a sub-device */ + if (entity->next == NULL) + break; + } + + /* + * Sink entity represents a video device node and is not + * a sub-device. Nonetheless because it has associated + * file descriptor and can expose v4l2-controls the + * v4l2-subdev structure is used for caching the + * related data. + */ + ret = ioctl(entity->sd->fd, VIDIOC_S_FMT, fmt); + if (ret < 0) + return ret; + + return 0; +} + int v4l2_subdev_get_selection(struct media_entity *entity, struct v4l2_rect *rect, unsigned int pad, unsigned int target, enum v4l2_subdev_format_whence which) diff --git a/utils/media-ctl/v4l2subdev.h b/utils/media-ctl/v4l2subdev.h index 2f74975..2b48fb5 100644 --- a/utils/media-ctl/v4l2subdev.h +++ b/utils/media-ctl/v4l2subdev.h @@ -131,6 +131,21 @@ int v4l2_subdev_set_format(struct media_entity *entity, enum v4l2_subdev_format_whence which); /** + * @brief Set media device pipeline format + * @param media - media device. + * @param fmt - negotiated format. + * + * Set the active format on all the media device pipeline entities. + * The format has to be at first negotiated with VIDIOC_SUBDEV_S_FMT + * by struct v4l2_subdev_format's 'whence' property set to + * V4L2_SUBDEV_FORMAT_TRY. + * + * @return 0 on success, or a negative error code on failure. + */ +int v4l2_subdev_apply_pipeline_fmt(struct media_device *media, + struct v4l2_format *fmt); + +/** * @brief Retrieve a selection rectangle on a pad. * @param entity - subdev-device media entity. * @param r - rectangle to be filled.