From patchwork Tue Sep 30 14:05:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 5003131 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 931BD9F2F0 for ; Tue, 30 Sep 2014 14:05:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9F109201C7 for ; Tue, 30 Sep 2014 14:05:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B2A7201FB for ; Tue, 30 Sep 2014 14:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbaI3OFU (ORCPT ); Tue, 30 Sep 2014 10:05:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40256 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751830AbaI3OFS (ORCPT ); Tue, 30 Sep 2014 10:05:18 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8UE56xW029937 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 30 Sep 2014 10:05:07 -0400 Received: from shalem.localdomain.com (vpn1-6-133.ams2.redhat.com [10.36.6.133]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8UE52po019192; Tue, 30 Sep 2014 10:05:05 -0400 From: Hans de Goede To: Linux Media Mailing List , Nicolas Dufresne Cc: Hans de Goede Subject: [PATCH 3/3] libv4l2: Move alignment of dest_fmt resolution to v4l2_set_src_and_dest_format Date: Tue, 30 Sep 2014 16:05:01 +0200 Message-Id: <1412085901-18528-3-git-send-email-hdegoede@redhat.com> In-Reply-To: <1412085901-18528-1-git-send-email-hdegoede@redhat.com> References: <1412085901-18528-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 So that we always do the alignment, this is necessary because there are several code paths where dest_fmt gets set to a fmt which has not been passed through libv4lconvert_try_fmt, and thus is not aligned. Also call v4lconvert_fixup_fmt when aligment has changed the height / width, so that bytesperline and sizeimage get set correctly. Signed-off-by: Hans de Goede --- lib/include/libv4lconvert.h | 3 +++ lib/libv4l2/libv4l2.c | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/include/libv4lconvert.h b/lib/include/libv4lconvert.h index e94d3bd..d425c51 100644 --- a/lib/include/libv4lconvert.h +++ b/lib/include/libv4lconvert.h @@ -147,6 +147,9 @@ LIBV4L_PUBLIC int v4lconvert_supported_dst_format(unsigned int pixelformat); LIBV4L_PUBLIC int v4lconvert_get_fps(struct v4lconvert_data *data); LIBV4L_PUBLIC void v4lconvert_set_fps(struct v4lconvert_data *data, int fps); +/* Fixup bytesperline and sizeimage for supported destination formats */ +LIBV4L_PUBLIC void v4lconvert_fixup_fmt(struct v4l2_format *fmt); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c index bdfb2fe..966a000 100644 --- a/lib/libv4l2/libv4l2.c +++ b/lib/libv4l2/libv4l2.c @@ -765,16 +765,6 @@ no_capture: v4l2_set_src_and_dest_format(index, &devices[index].src_fmt, &devices[index].dest_fmt); - /* When a user does a try_fmt with the current dest_fmt and the dest_fmt - is a supported one we will align the resolution (see try_fmt for why). - Do the same here now, so that a try_fmt on the result of a get_fmt done - immediately after open leaves the fmt unchanged. */ - if (v4lconvert_supported_dst_format( - devices[index].dest_fmt.fmt.pix.pixelformat)) { - devices[index].dest_fmt.fmt.pix.width &= ~7; - devices[index].dest_fmt.fmt.pix.height &= ~1; - } - pthread_mutex_init(&devices[index].stream_lock, NULL); devices[index].no_frames = 0; @@ -948,6 +938,18 @@ static int v4l2_pix_fmt_identical(struct v4l2_format *a, struct v4l2_format *b) static void v4l2_set_src_and_dest_format(int index, struct v4l2_format *src_fmt, struct v4l2_format *dest_fmt) { + /* + * When a user does a try_fmt with the current dest_fmt and the + * dest_fmt is a supported one we will align the resolution (see + * libv4lconvert_try_fmt). We do this here too, in case dest_fmt gets + * set without having gone through libv4lconvert_try_fmt, so that a + * try_fmt on the result of a get_fmt always returns the same result. + */ + if (v4lconvert_supported_dst_format(dest_fmt->fmt.pix.pixelformat)) { + dest_fmt->fmt.pix.width &= ~7; + dest_fmt->fmt.pix.height &= ~1; + } + /* Sigh some drivers (pwc) do not properly reflect what one really gets after a s_fmt in their try_fmt answer. So update dest format (which we report as result from s_fmt / g_fmt to the app) with all info from the src @@ -958,7 +960,8 @@ static void v4l2_set_src_and_dest_format(int index, if (v4l2_pix_fmt_compat(src_fmt, dest_fmt)) { dest_fmt->fmt.pix.bytesperline = src_fmt->fmt.pix.bytesperline; dest_fmt->fmt.pix.sizeimage = src_fmt->fmt.pix.sizeimage; - } + } else + v4lconvert_fixup_fmt(dest_fmt); devices[index].src_fmt = *src_fmt; devices[index].dest_fmt = *dest_fmt;