From patchwork Fri Oct 20 21:50:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 10021051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7EA260234 for ; Fri, 20 Oct 2017 21:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBA8028F67 for ; Fri, 20 Oct 2017 21:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C06D928F6D; Fri, 20 Oct 2017 21:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51CA728F67 for ; Fri, 20 Oct 2017 21:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753461AbdJTVxT (ORCPT ); Fri, 20 Oct 2017 17:53:19 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:56842 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753343AbdJTVvA (ORCPT ); Fri, 20 Oct 2017 17:51:00 -0400 Received: by mail-qk0-f194.google.com with SMTP id l194so15989887qke.13; Fri, 20 Oct 2017 14:50:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aDNbC454OgyVZ4naQk975483pQW7ajNRjwobxgdNPsY=; b=mm8swQhiszQ0511MEd3oXjUmw/30Y9unSB5fLtLnfE3zg2TpgchKQ4++fETbDoDSBY jye4x822i8eVDQVwzOr2chzqRFepeDqw4rmDJOPY3kIGVmHB7Kay9B/4nmBo90VGTSYh /z47wkkX4M+48F+XhOHCI5bTEqDcir6gCb7tm7pjL0c2TPNfRba5sb4zdSaDRXXW2L3A Cv0ZyQOu92y7eGyBQDBwsTvjvvAshPXwEsahgV+LuBAssZHZvfkTIe6fiW291yhtvLdI iNJuY3nJgh4kWAOsmqzIzm+nopWCl/+/PKNOFTH0sfKvSBMsWMgaT9gypilHufql0kG6 01MA== X-Gm-Message-State: AMCzsaXNeQRay1d0E8gwYoT4JrgRbT0R3WwVqMne98ShbTxPypQxVWBL swedvEOnKTHZf9H3rlgK6PsaoGvB X-Google-Smtp-Source: ABhQp+RTG7MBvjSQcU2puuezaPiqft4pDP+Km5lMUSmIMdvZ43InB8GxzfOMRbPoYNPa50K3Er3aQQ== X-Received: by 10.55.91.199 with SMTP id p190mr9209070qkb.291.1508536258944; Fri, 20 Oct 2017 14:50:58 -0700 (PDT) Received: from localhost.localdomain (189-19-125-192.dsl.telesp.net.br. [189.19.125.192]) by smtp.gmail.com with ESMTPSA id j4sm1167039qkf.75.2017.10.20.14.50.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 14:50:58 -0700 (PDT) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [RFC v4 11/17] [media] vb2: check earlier if stream can be started Date: Fri, 20 Oct 2017 19:50:06 -0200 Message-Id: <20171020215012.20646-12-gustavo@padovan.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020215012.20646-1-gustavo@padovan.org> References: <20171020215012.20646-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan To support explicit synchronization we need to run all operations that can fail before we queue the buffer to the driver. With fences the queueing will be delayed if the fence is not signaled yet and it will be better if such callback do not fail. For that we move the vb2_start_streaming() before the queuing for the buffer may happen. Signed-off-by: Gustavo Padovan --- drivers/media/v4l2-core/videobuf2-core.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index cb115ba6a1d2..60f8b582396a 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1399,29 +1399,27 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) trace_vb2_qbuf(q, vb); /* - * If already streaming, give the buffer to driver for processing. - * If not, the buffer will be given to driver on next streamon. - */ - if (q->start_streaming_called) - __enqueue_in_driver(vb); - - /* Fill buffer information for the userspace */ - if (pb) - call_void_bufop(q, fill_user_buffer, vb, pb); - - /* * If streamon has been called, and we haven't yet called * start_streaming() since not enough buffers were queued, and * we now have reached the minimum number of queued buffers, * then we can finally call start_streaming(). + * + * If already streaming, give the buffer to driver for processing. + * If not, the buffer will be given to driver on next streamon. */ if (q->streaming && !q->start_streaming_called && q->queued_count >= q->min_buffers_needed) { ret = vb2_start_streaming(q); if (ret) return ret; + } else if (q->start_streaming_called) { + __enqueue_in_driver(vb); } + /* Fill buffer information for the userspace */ + if (pb) + call_void_bufop(q, fill_user_buffer, vb, pb); + dprintk(2, "qbuf of buffer %d succeeded\n", vb->index); return 0; }