Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp258466ybg; Tue, 28 Jul 2020 05:26:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRrdrNcQWSllZeXEVzkAJ5by953dbKUOegP7LnhsON7/HBGP3O3rzyt6KlFvky2sRZANL4 X-Received: by 2002:a17:906:4157:: with SMTP id l23mr9110921ejk.491.1595939172129; Tue, 28 Jul 2020 05:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595939172; cv=none; d=google.com; s=arc-20160816; b=k9EAd+63dBe/5/AYs657qDj6tKzTpn7G+mckbK7NUmXnYFDvV8RQfjskkYfxritQxn z5vzyMjRfQwqkjqOvrkkgw0cehyFwbQP9pggaUZgtbF5maAdpdAaWXyZ5oTJ0ls6n/j4 LOsYgCvQzbhMl3eIITCitEncS8fc8YbU6p3NOsypbKbhDdTahVCZz5W8bIpcnvck4qce TTJ7YwvrpYOHvFyt5bJWtnpYRM21mJeTxJ+Vd1LNIAxfrhvEzwJ+pL0amXkOebfE+vKl sOTQgcxiCH2/87yj7wo0vNif8r7TocT4kjDGkIDd2YMZGRw26Ecew7iUuqYUG7NRQVgb eVZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=82AMymB+Y47VjZ9WUrDbczBHdyHozMzd62HuDGlPFF8=; b=x2MBypUSFFzDxkuTzmtwxXVmYlwYnwqKFDYOaYh/li6ufDTV+DHKlYcgA0JgNk245q I04el3arZ5o2YcsWSqTP6dw8e2MW54dE1mmRfEgu5OUpSq41O+pIXYdkojgU6BGoKP3b gp3c9lGq+wGPx2bGRCXg+kncvIpT00KG3AzW25U0x+jpXAB10sE5iQR/6Oe0EqTBZ6cU Buq0CjFqAPHrf95YxnIwoa20SSapGCMBDj5UzetQfjuB9qsdjgcS6v1bspvW6HrHSwyc qiqsYUh0xdxXQKyXrWckdIoVJAKu3opKV3OMODxuA0n4hg9YoLHUvgkcH9SFGKfx5tSt fcGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx8si7162552edb.170.2020.07.28.05.25.49; Tue, 28 Jul 2020 05:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729245AbgG1MYn (ORCPT + 99 others); Tue, 28 Jul 2020 08:24:43 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:52196 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728300AbgG1MYm (ORCPT ); Tue, 28 Jul 2020 08:24:42 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 87866297427 Subject: Re: [PATCH v2 3/3] media: vimc: Join pipeline if one already exists To: Kaaira Gupta , Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham , =?UTF-8?Q?Niklas_S=c3=b6derlund?= References: <20200724120213.17119-1-kgupta@es.iitr.ac.in> <20200724120213.17119-4-kgupta@es.iitr.ac.in> From: Dafna Hirschfeld Message-ID: Date: Tue, 28 Jul 2020 14:24:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200724120213.17119-4-kgupta@es.iitr.ac.in> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24.07.20 14:02, Kaaira Gupta wrote: > An output which is running is already part of a pipeline and trying to > start a new pipeline is not possible. This prevents two capture devices > from streaming at the same time. > > Instead of failing to start the second capture device allow it to join > the already running pipeline. This allows two (or more) capture devices > to independently be started and stopped. > > [Kaaira: Changed the search for an existing connected sensor, to search > for a non-NULL pipe instead, this helps to terminate the search at > output itself instead of going till the sensor, changed variable names, > commit message and conditions accordingly] > > Signed-off-by: Niklas Söderlund > Signed-off-by: Kaaira Gupta > --- > .../media/test-drivers/vimc/vimc-capture.c | 35 ++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c > index c63496b17b9a..423d5e5a508d 100644 > --- a/drivers/media/test-drivers/vimc/vimc-capture.c > +++ b/drivers/media/test-drivers/vimc/vimc-capture.c > @@ -237,16 +237,49 @@ static void vimc_cap_return_all_buffers(struct vimc_cap_device *vcap, > spin_unlock(&vcap->qlock); > } > > +static struct media_entity *vimc_cap_get_output(struct vimc_cap_device *vcap) > +{ > + struct media_entity *entity = &vcap->vdev.entity; > + struct media_device *mdev = entity->graph_obj.mdev; > + struct media_graph graph; > + > + mutex_lock(&mdev->graph_mutex); > + if (media_graph_walk_init(&graph, mdev)) { > + mutex_unlock(&mdev->graph_mutex); > + return NULL; > + } > + > + media_graph_walk_start(&graph, entity); > + > + while ((entity = media_graph_walk_next(&graph))) > + if (entity->pipe) > + break; > + > + mutex_unlock(&mdev->graph_mutex); > + > + media_graph_walk_cleanup(&graph); > + > + return entity; > +} > + > static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) > { > struct vimc_cap_device *vcap = vb2_get_drv_priv(vq); > struct media_entity *entity = &vcap->vdev.entity; > + struct media_pipeline *pipe = NULL; > + struct media_entity *oent; > int ret; > > vcap->sequence = 0; > > /* Start the media pipeline */ > - ret = media_pipeline_start(entity, &vcap->stream.pipe); > + oent = vimc_cap_get_output(vcap); > + if (oent) > + pipe = oent->pipe; > + else > + pipe = &vcap->stream.pipe; > + > + ret = media_pipeline_start(entity, pipe); > if (ret) { > vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); > return ret; > I think there is actually no need to iterate the graph. If the capture is already connected to another capture that streams, it means that they both have the same pipe in the media core. So actually the code can just be: if (vcap->ved.ent->pipe) pipe = vcap->ved.ent->pipe; else pipe = &vcap->stream.pipe; (and no need the function vimc_cap_get_output) Thanks, Dafna