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: 5894471 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E7FCDBF6C3 for ; Thu, 26 Feb 2015 16:01:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F2FC2203AA for ; Thu, 26 Feb 2015 16:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F221C203A4 for ; Thu, 26 Feb 2015 16:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754445AbbBZQAw (ORCPT ); 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 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.