From patchwork Wed Aug 19 18:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724821 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 894C8138C for ; Wed, 19 Aug 2020 18:05:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D0A220786 for ; Wed, 19 Aug 2020 18:05:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="arbnsihp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbgHSSFH (ORCPT ); Wed, 19 Aug 2020 14:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbgHSSFC (ORCPT ); Wed, 19 Aug 2020 14:05:02 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55A69C061757 for ; Wed, 19 Aug 2020 11:05:02 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id mw10so1478453pjb.2 for ; Wed, 19 Aug 2020 11:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sv87vM7p7z6RA/m4QyohJmK6RcFUCusmzqFQmHL0cjo=; b=arbnsihphQtZ1oi7VuwyfqLXA1f3iqIU6JchkF10yYvfiaOlgb5eOq6AkNTLRUojXw jQaTSQS+lkWibN1ozHgfUyLZPbpdfMFQ2Pc5PSUbnaY4iZTtpJOxfHDo2zu04mWsUjOc 6QEpwuu3SAiLHcdAAjkSk7XTXehCMkiPeDtMJsVkTaykVsDgEYOaB0CSrMMa+6jU2MGc 6X+Bq8XjUo0jsJhUl+JZ/Mw/L5dD4ZaWh7aNdcmz7RoPo9iVm1iCnoD5UXyj/bVQGE7U FpUfqNSP3rFhdeedKwbbsLBefIN3Xvl3zyn0PWwQpQm1mGwxhwCZvLxmGeswxT2xiVsu JOfw== 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=Sv87vM7p7z6RA/m4QyohJmK6RcFUCusmzqFQmHL0cjo=; b=N7isw4lqomXIvel5RkuBXhsb7Eefxpc1m9JiqHVxkMB5E6NlEmvoDf1F5RnfNsezVu cleEX61Km8y8+DXuNyVo5g8Ae2ligO4bOJSSZbNTnpB0fGPpbDDmEHQ5qplb+84f5P+S asy6fgiBLQYofq1PktNZvtqflQAwRbm3TY9WXb8pYtPqNTPR9sbZueqpGcCzKo2dIhb6 Q3FMWTql3V4jsfr7qQLbGv9ZiWAW/nfJ29vaCiw0goxRGL42pxk2CyptKyvOogEG7d/G 98q1Ab0wecq/TZQhY/wow+tHwv4ibeja8J3HwRuJp22T2+XeeWsKDBB2Kfi0OCIipRPG 5lXg== X-Gm-Message-State: AOAM530/WWgy8JLoEyoQGqd9aYe7YAagyJyGA3Tq9WppI6kAJZtd8Mrh VZf9CdlF3ofGn26uDN3ESU3r/Q== X-Google-Smtp-Source: ABdhPJzUmz9dXWmWwe06ZA+v+GGxWf/45X2KDEvKLzzrJ+r6CA5w/mS3u4y7I9NrxHdahBoYb6CSJQ== X-Received: by 2002:a17:90b:3597:: with SMTP id mm23mr4880234pjb.3.1597860301783; Wed, 19 Aug 2020 11:05:01 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id d22sm29422243pfd.42.2020.08.19.11.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:01 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 1/9] media: vimc: Move get_source_entity to vimc-common Date: Wed, 19 Aug 2020 23:34:34 +0530 Message-Id: <20200819180442.11630-2-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move the function vimc_get_source_entity() to vimc-common.c to make it reusable. Signed-off-by: Kaaira Gupta Reviewed-by: Kieran Bingham --- drivers/media/test-drivers/vimc/vimc-common.c | 14 +++++++++++ drivers/media/test-drivers/vimc/vimc-common.h | 12 ++++++++++ .../media/test-drivers/vimc/vimc-streamer.c | 24 ------------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-common.c b/drivers/media/test-drivers/vimc/vimc-common.c index 0d97b25ce21e..91c8992bb391 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.c +++ b/drivers/media/test-drivers/vimc/vimc-common.c @@ -417,3 +417,17 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved, media_entity_cleanup(&sd->entity); return ret; } + +struct media_entity *vimc_get_source_entity(struct media_entity *ent) +{ + struct media_pad *pad; + int i; + + for (i = 0; i < ent->num_pads; i++) { + if (ent->pads[i].flags & MEDIA_PAD_FL_SOURCE) + continue; + pad = media_entity_remote_pad(&ent->pads[i]); + return pad ? pad->entity : NULL; + } + return NULL; +} diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h index a289434e75ba..4c580d854007 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.h +++ b/drivers/media/test-drivers/vimc/vimc-common.h @@ -230,4 +230,16 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved, */ int vimc_vdev_link_validate(struct media_link *link); +/** + * vimc_get_source_entity - get the entity connected with the first sink pad + * + * @ent: reference media_entity + * + * Helper function that returns the media entity containing the source pad + * linked with the first sink pad from the given media entity pad list. + * + * Return: The source pad or NULL, if it wasn't found. + */ +struct media_entity *vimc_get_source_entity(struct media_entity *ent); + #endif diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index 451a32c0d034..4f8384246042 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -12,30 +12,6 @@ #include "vimc-streamer.h" -/** - * vimc_get_source_entity - get the entity connected with the first sink pad - * - * @ent: reference media_entity - * - * Helper function that returns the media entity containing the source pad - * linked with the first sink pad from the given media entity pad list. - * - * Return: The source pad or NULL, if it wasn't found. - */ -static struct media_entity *vimc_get_source_entity(struct media_entity *ent) -{ - struct media_pad *pad; - int i; - - for (i = 0; i < ent->num_pads; i++) { - if (ent->pads[i].flags & MEDIA_PAD_FL_SOURCE) - continue; - pad = media_entity_remote_pad(&ent->pads[i]); - return pad ? pad->entity : NULL; - } - return NULL; -} - /** * vimc_streamer_pipeline_terminate - Disable stream in all ved in stream * From patchwork Wed Aug 19 18:04:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD6CF138C for ; Wed, 19 Aug 2020 18:05:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B5ED20658 for ; Wed, 19 Aug 2020 18:05:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="lQk7Q038" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726836AbgHSSF2 (ORCPT ); Wed, 19 Aug 2020 14:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbgHSSFH (ORCPT ); Wed, 19 Aug 2020 14:05:07 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563ECC061383 for ; Wed, 19 Aug 2020 11:05:07 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d22so12078194pfn.5 for ; Wed, 19 Aug 2020 11:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+Hr38lItu4eVpChslvtYRcigjDMNh3B0lnEZweg9dnU=; b=lQk7Q038l0jssNstKbz+77SuBmA+tpST+f6F8/Np9AW1MszdzTbQ2lDiJYHBRL6JYH vDa790mumNZnckVLgI7yC+WS4M+Kzu4j3w2zfX5qD8xIOUTc80OcIlgrghkve+MT/7ox Z2HrbU8nAHBqUzmKThYHT1K5UrQV2oZla8kc+AKkS1tEFFZdL9GKTX+A173uOPD69EF2 nGn9m7GrLqlLBZFi0NCqLYDFRwwBTprHg/fe4Ey6vIqdFi4+r8ovpaBUyeHb1AniVYCK cocQE3z1Abw88Y8+dMS4r6YCdTGRN+3u5JadplNlr+oyv7Qts0FPLguPdaily1IvM8GP sWtA== 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=+Hr38lItu4eVpChslvtYRcigjDMNh3B0lnEZweg9dnU=; b=ofu/hQbhCMal2VRbSoDyaxvUiYI4/zhcRLo2PmWBi0oEs2JhO61dRJVE1UlZ6+qTpC xdSfu1wyn9b6FoHypdhQHm5/26lBmbcyMJrSgO4i0NCTNk/pTh28kRu6ubvpl6Us50mJ XlnPr4Ciy7+jt2DuUDU4N/DMrIM+WSmKmuluMnspXzHvlvNxx47O0mFoTXa3p0gQd2Lo pWabFp9YIFFaE199UeKZFQBHKYklaczrwhl4oU3unS4CfMIyYjg5OuhCk7+n/gbfjFEn oaPqZ9hkIpyfPY1VSIXriDN08CxQwwSQ5r1rcrvv3OmOCXhVhcepDYrXnV5Zweb1vuJS eS7w== X-Gm-Message-State: AOAM532lSJ/xFVQKdqB5jM7i/74XP7t5a/rJwwo0hiQnmHWVj4/Qo6fa kCAC0NNLToXoEvgQfg2pTn0VUw== X-Google-Smtp-Source: ABdhPJzrNXPBOT6f36UuHk1yHy/wZKcrDFdhp9P+sNWEBR0eqWdGATwfEX1e0Njxvc0BxFym+f/HJQ== X-Received: by 2002:a62:ee06:: with SMTP id e6mr19575083pfi.313.1597860306768; Wed, 19 Aug 2020 11:05:06 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id u65sm29095245pfb.102.2020.08.19.11.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:06 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 2/9] media: vimc: Add get_frame callback Date: Wed, 19 Aug 2020 23:34:35 +0530 Message-Id: <20200819180442.11630-3-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In the process of making vimc compatible for multiple streams, we need to create a frame passing process such that two different entities can get the frame from a common entity. This isn't possible currently without calling process_frame twice for the common entity, as process_frames returns the frame which gets passed on. So, to take care of this, add a get_frame callback to vimc device and use it to get the frames for an entity from previous entity instead of returning and passing the frames as an argument in process_frame. Signed-off-by: Kaaira Gupta Reviewed-by: Kieran Bingham --- .../media/test-drivers/vimc/vimc-capture.c | 18 +++++++++++++++--- drivers/media/test-drivers/vimc/vimc-common.h | 7 ++++--- .../media/test-drivers/vimc/vimc-debayer.c | 19 ++++++++++++++++--- drivers/media/test-drivers/vimc/vimc-scaler.c | 18 +++++++++++++++--- drivers/media/test-drivers/vimc/vimc-sensor.c | 11 +++++++++-- .../media/test-drivers/vimc/vimc-streamer.c | 10 ++++++---- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index c63496b17b9a..a8cbb8e4d5ba 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -355,12 +355,13 @@ static void vimc_cap_unregister(struct vimc_ent_device *ved) video_unregister_device(&vcap->vdev); } -static void *vimc_cap_process_frame(struct vimc_ent_device *ved, - const void *frame) +static int vimc_cap_process_frame(struct vimc_ent_device *ved) { struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device, ved); struct vimc_cap_buffer *vimc_buf; + struct v4l2_subdev *sd; + const void *frame; void *vbuf; spin_lock(&vcap->qlock); @@ -370,7 +371,7 @@ static void *vimc_cap_process_frame(struct vimc_ent_device *ved, typeof(*vimc_buf), list); if (!vimc_buf) { spin_unlock(&vcap->qlock); - return ERR_PTR(-EAGAIN); + return -EAGAIN; } /* Remove this entry from the list */ @@ -385,12 +386,22 @@ static void *vimc_cap_process_frame(struct vimc_ent_device *ved, vbuf = vb2_plane_vaddr(&vimc_buf->vb2.vb2_buf, 0); + sd = media_entity_to_v4l2_subdev(vimc_get_source_entity(ved->ent)); + ved = v4l2_get_subdevdata(sd); + frame = ved->get_frame(ved); + memcpy(vbuf, frame, vcap->format.sizeimage); /* Set it as ready */ vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0, vcap->format.sizeimage); vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE); + + return 0; +} + +static void *vimc_cap_get_frame(struct vimc_ent_device *ved) +{ return NULL; } @@ -455,6 +466,7 @@ static struct vimc_ent_device *vimc_cap_add(struct vimc_device *vimc, vcap->ved.ent = &vcap->vdev.entity; vcap->ved.process_frame = vimc_cap_process_frame; vcap->ved.vdev_get_format = vimc_cap_get_format; + vcap->ved.get_frame = vimc_cap_get_frame; vcap->ved.dev = vimc->mdev.dev; /* Initialize the video_device struct */ diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h index 4c580d854007..287d66edff49 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.h +++ b/drivers/media/test-drivers/vimc/vimc-common.h @@ -85,7 +85,8 @@ struct vimc_pix_map { * * @dev: a pointer of the device struct of the driver * @ent: the pointer to struct media_entity for the node - * @process_frame: callback send a frame to that node + * @get_frame: callback that sends a frame processed by the entity + * @process_frame: callback that processes a frame * @vdev_get_format: callback that returns the current format a pad, used * only when is_media_entity_v4l2_video_device(ent) returns * true @@ -101,8 +102,8 @@ struct vimc_pix_map { struct vimc_ent_device { struct device *dev; struct media_entity *ent; - void * (*process_frame)(struct vimc_ent_device *ved, - const void *frame); + void * (*get_frame)(struct vimc_ent_device *ved); + int (*process_frame)(struct vimc_ent_device *ved); void (*vdev_get_format)(struct vimc_ent_device *ved, struct v4l2_pix_format *fmt); }; diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c index c3f6fef34f68..f61e6e8899ac 100644 --- a/drivers/media/test-drivers/vimc/vimc-debayer.c +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c @@ -491,17 +491,22 @@ static void vimc_deb_calc_rgb_sink(struct vimc_deb_device *vdeb, } } -static void *vimc_deb_process_frame(struct vimc_ent_device *ved, - const void *sink_frame) +static int vimc_deb_process_frame(struct vimc_ent_device *ved) { struct vimc_deb_device *vdeb = container_of(ved, struct vimc_deb_device, ved); unsigned int rgb[3]; unsigned int i, j; + struct v4l2_subdev *sd; + const void *sink_frame; /* If the stream in this node is not active, just return */ if (!vdeb->src_frame) - return ERR_PTR(-EINVAL); + return -EINVAL; + + sd = media_entity_to_v4l2_subdev(vimc_get_source_entity(ved->ent)); + ved = v4l2_get_subdevdata(sd); + sink_frame = ved->get_frame(ved); for (i = 0; i < vdeb->sink_fmt.height; i++) for (j = 0; j < vdeb->sink_fmt.width; j++) { @@ -509,6 +514,13 @@ static void *vimc_deb_process_frame(struct vimc_ent_device *ved, vdeb->set_rgb_src(vdeb, i, j, rgb); } + return 0; +} + +static void *vimc_deb_get_frame(struct vimc_ent_device *ved) +{ + struct vimc_deb_device *vdeb = container_of(ved, struct vimc_deb_device, + ved); return vdeb->src_frame; } @@ -593,6 +605,7 @@ static struct vimc_ent_device *vimc_deb_add(struct vimc_device *vimc, goto err_free_hdl; vdeb->ved.process_frame = vimc_deb_process_frame; + vdeb->ved.get_frame = vimc_deb_get_frame; vdeb->ved.dev = vimc->mdev.dev; vdeb->mean_win_size = vimc_deb_ctrl_mean_win_size.def; diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/test-drivers/vimc/vimc-scaler.c index 121fa7d62a2e..347f9cd4a168 100644 --- a/drivers/media/test-drivers/vimc/vimc-scaler.c +++ b/drivers/media/test-drivers/vimc/vimc-scaler.c @@ -455,18 +455,29 @@ static void vimc_sca_fill_src_frame(const struct vimc_sca_device *const vsca, vimc_sca_scale_pix(vsca, i, j, sink_frame); } -static void *vimc_sca_process_frame(struct vimc_ent_device *ved, - const void *sink_frame) +static int vimc_sca_process_frame(struct vimc_ent_device *ved) { struct vimc_sca_device *vsca = container_of(ved, struct vimc_sca_device, ved); + const void *sink_frame; + struct v4l2_subdev *sd; /* If the stream in this node is not active, just return */ if (!vsca->src_frame) - return ERR_PTR(-EINVAL); + return -EINVAL; + sd = media_entity_to_v4l2_subdev(vimc_get_source_entity(ved->ent)); + ved = v4l2_get_subdevdata(sd); + sink_frame = ved->get_frame(ved); vimc_sca_fill_src_frame(vsca, sink_frame); + return 0; +}; + +static void *vimc_sca_get_frame(struct vimc_ent_device *ved) +{ + struct vimc_sca_device *vsca = container_of(ved, struct vimc_sca_device, + ved); return vsca->src_frame; }; @@ -505,6 +516,7 @@ static struct vimc_ent_device *vimc_sca_add(struct vimc_device *vimc, } vsca->ved.process_frame = vimc_sca_process_frame; + vsca->ved.get_frame = vimc_sca_get_frame; vsca->ved.dev = vimc->mdev.dev; /* Initialize the frame format */ diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c index ba5db5a150b4..32a2c39de2cd 100644 --- a/drivers/media/test-drivers/vimc/vimc-sensor.c +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c @@ -190,8 +190,7 @@ static const struct v4l2_subdev_pad_ops vimc_sen_pad_ops = { .set_fmt = vimc_sen_set_fmt, }; -static void *vimc_sen_process_frame(struct vimc_ent_device *ved, - const void *sink_frame) +static int vimc_sen_process_frame(struct vimc_ent_device *ved) { struct vimc_sen_device *vsen = container_of(ved, struct vimc_sen_device, ved); @@ -238,6 +237,13 @@ static void *vimc_sen_process_frame(struct vimc_ent_device *ved, break; } + return 0; +} + +static void *vimc_sen_get_frame(struct vimc_ent_device *ved) +{ + struct vimc_sen_device *vsen = container_of(ved, struct vimc_sen_device, + ved); return vsen->frame; } @@ -429,6 +435,7 @@ static struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc, goto err_free_tpg; vsen->ved.process_frame = vimc_sen_process_frame; + vsen->ved.get_frame = vimc_sen_get_frame; vsen->ved.dev = vimc->mdev.dev; /* Initialize the frame format */ diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index 4f8384246042..c1644d69686d 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -125,7 +125,8 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, static int vimc_streamer_thread(void *data) { struct vimc_stream *stream = data; - u8 *frame = NULL; + struct vimc_ent_device *ved; + int ret; int i; set_freezable(); @@ -136,9 +137,10 @@ static int vimc_streamer_thread(void *data) break; for (i = stream->pipe_size - 1; i >= 0; i--) { - frame = stream->ved_pipeline[i]->process_frame( - stream->ved_pipeline[i], frame); - if (!frame || IS_ERR(frame)) + ved = stream->ved_pipeline[i]; + ret = ved->process_frame(ved); + + if (ret) break; } //wait for 60hz From patchwork Wed Aug 19 18:04:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2149F1744 for ; Wed, 19 Aug 2020 18:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F358720786 for ; Wed, 19 Aug 2020 18:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="Q8MbWudY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726886AbgHSSFe (ORCPT ); Wed, 19 Aug 2020 14:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgHSSFM (ORCPT ); Wed, 19 Aug 2020 14:05:12 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462DEC061342 for ; Wed, 19 Aug 2020 11:05:12 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id d19so11765804pgl.10 for ; Wed, 19 Aug 2020 11:05:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VJOwxZD756f4d3HNd4Hpvhldk4W8KSHk0BSTu8cNd+0=; b=Q8MbWudYBHUtf3I/ngwkAVqIdwWbZXLatG/7b18xipE/k+EE9MX36XB+IV6lIDz+Br /GBMGIUAA4x5lZac1T1K9pRddO6E413r/7jUX2v8dMTPwpE26Ng2CBrBrGYDzSwmwmor 0sVjhNbFlZKmDjELnl2QpvUkUvBBEgHpTGUij2FQZF9Veuzx2opfvxfKBkkMm+dcK8gw 0dKMMeq+H4gqJS7OEXsyk2g5/2dfmwZeVMXRVU+RE27zG20TChgG+dz2GyFq2QKwoDdQ v/fUp8xgejoa264sKzFzTYoz5vQc+SMmgvMkPFy5SPIYorMT9c+YMsYc3PTckgfPYQQF fDJw== 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:mime-version:content-transfer-encoding; bh=VJOwxZD756f4d3HNd4Hpvhldk4W8KSHk0BSTu8cNd+0=; b=GywzY2u9YNeRFJhf9O2URMlrngG5hRHczrjif1n5wjR/LgcdDj0e6//aCBNijBTJ4Z Wf8aAmBxvORw9Sv5aZXbzRyicUQxQ5Dy05z87RBwqH4RxJYmetukUoO5bgCrGiRtLhLl rLqqtn4LqS1mCFN1dsadlTmbYpElgpEEf2DuGNWNZQUYe9rLPabP8LkY9eE9bK3iSddq n67m0C8Qpg6SD8tlujIhjVXwhsetjGPqfegtGgq8SW7myfP3i7h6ZrE3ZWXZJdtPBh89 op8DVkGd8QIQBsYjJmbBsQDYO9hPq+LQtnLYTz97OmLMSafqBLVZ/NFkXhqwOcmfrJ7q bw3w== X-Gm-Message-State: AOAM531gNQd7ec7Dim61GttW2MSruHzHdCX+wXtSWMEkcY74QLJJd3US RtBCyCw3DueweJMLI23Dh9EdszuVaTV8yQ== X-Google-Smtp-Source: ABdhPJzApiHr4zA8SCw8Y5N+Yqufm8PMxKzaoF12gzOBA8/fwujbFHlgOpVoA4yf/K9RAqfrd2W/9Q== X-Received: by 2002:a62:cd8f:: with SMTP id o137mr20689091pfg.241.1597860311717; Wed, 19 Aug 2020 11:05:11 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id w16sm29100810pfq.13.2020.08.19.11.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:11 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= , Kaaira Gupta Subject: [PATCH v3 3/9] media: vimc: Add usage count to subdevices Date: Wed, 19 Aug 2020 23:34:36 +0530 Message-Id: <20200819180442.11630-4-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Niklas Söderlund Prepare for multiple video streams from the same sensor by adding a use counter to vimc_ent_device. The counter is increased for every s_stream(1) and decremented for every s_stream(0) call. The subdevice stream is not started or stopped unless the usage count go from 0 to 1 (started) or from 1 to 0 (stopped). This allows for multiple s_stream() calls to try to either start or stop the device while only the first/last call will actually effect the state of the device. Initialise and increment use_count for capture as well, as use_count will be used in subsequent patches for starting process_frame as well. [Kaaira: moved use_count to vimc entity device instead of declaring it for each subdevice, used use_count for capture as well and rebased the patch on current HEAD of master to help with the current series] Signed-off-by: Niklas Söderlund Signed-off-by: Kaaira Gupta --- drivers/media/test-drivers/vimc/vimc-capture.c | 3 +++ drivers/media/test-drivers/vimc/vimc-common.h | 2 ++ drivers/media/test-drivers/vimc/vimc-debayer.c | 7 +++++++ drivers/media/test-drivers/vimc/vimc-scaler.c | 7 +++++++ drivers/media/test-drivers/vimc/vimc-sensor.c | 6 ++++++ 5 files changed, 25 insertions(+) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index a8cbb8e4d5ba..93418cb5a139 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -243,6 +243,7 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) struct media_entity *entity = &vcap->vdev.entity; int ret; + atomic_inc(&vcap->ved.use_count); vcap->sequence = 0; /* Start the media pipeline */ @@ -270,6 +271,7 @@ static void vimc_cap_stop_streaming(struct vb2_queue *vq) { struct vimc_cap_device *vcap = vb2_get_drv_priv(vq); + atomic_dec(&vcap->ved.use_count); vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0); /* Stop the media pipeline */ @@ -424,6 +426,7 @@ static struct vimc_ent_device *vimc_cap_add(struct vimc_device *vimc, vcap->vdev.entity.name = vcfg_name; vcap->vdev.entity.function = MEDIA_ENT_F_IO_V4L; vcap->pad.flags = MEDIA_PAD_FL_SINK; + atomic_set(&vcap->ved.use_count, 0); ret = media_entity_pads_init(&vcap->vdev.entity, 1, &vcap->pad); if (ret) diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h index 287d66edff49..c214f5ec7818 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.h +++ b/drivers/media/test-drivers/vimc/vimc-common.h @@ -85,6 +85,7 @@ struct vimc_pix_map { * * @dev: a pointer of the device struct of the driver * @ent: the pointer to struct media_entity for the node + * @use_count: a count to show the number of streams entity is part of * @get_frame: callback that sends a frame processed by the entity * @process_frame: callback that processes a frame * @vdev_get_format: callback that returns the current format a pad, used @@ -102,6 +103,7 @@ struct vimc_pix_map { struct vimc_ent_device { struct device *dev; struct media_entity *ent; + atomic_t use_count; void * (*get_frame)(struct vimc_ent_device *ved); int (*process_frame)(struct vimc_ent_device *ved); void (*vdev_get_format)(struct vimc_ent_device *ved, diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c index f61e6e8899ac..60c4c0ec2030 100644 --- a/drivers/media/test-drivers/vimc/vimc-debayer.c +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c @@ -343,6 +343,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; + if (atomic_inc_return(&vdeb->ved.use_count) != 1) + return 0; + if (vdeb->src_frame) return 0; @@ -368,6 +371,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable) return -ENOMEM; } else { + if (atomic_dec_return(&vdeb->ved.use_count) != 0) + return 0; + if (!vdeb->src_frame) return 0; @@ -608,6 +614,7 @@ static struct vimc_ent_device *vimc_deb_add(struct vimc_device *vimc, vdeb->ved.get_frame = vimc_deb_get_frame; vdeb->ved.dev = vimc->mdev.dev; vdeb->mean_win_size = vimc_deb_ctrl_mean_win_size.def; + atomic_set(&vdeb->ved.use_count, 0); /* Initialize the frame format */ vdeb->sink_fmt = sink_fmt_default; diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/test-drivers/vimc/vimc-scaler.c index 347f9cd4a168..d511e1f2152d 100644 --- a/drivers/media/test-drivers/vimc/vimc-scaler.c +++ b/drivers/media/test-drivers/vimc/vimc-scaler.c @@ -340,6 +340,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; + if (atomic_inc_return(&vsca->ved.use_count) != 1) + return 0; + if (vsca->src_frame) return 0; @@ -363,6 +366,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable) return -ENOMEM; } else { + if (atomic_dec_return(&vsca->ved.use_count) != 0) + return 0; + if (!vsca->src_frame) return 0; @@ -518,6 +524,7 @@ static struct vimc_ent_device *vimc_sca_add(struct vimc_device *vimc, vsca->ved.process_frame = vimc_sca_process_frame; vsca->ved.get_frame = vimc_sca_get_frame; vsca->ved.dev = vimc->mdev.dev; + atomic_set(&vsca->ved.use_count, 0); /* Initialize the frame format */ vsca->sink_fmt = sink_fmt_default; diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c index 32a2c39de2cd..ced8ef06b01e 100644 --- a/drivers/media/test-drivers/vimc/vimc-sensor.c +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c @@ -256,6 +256,9 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; + if (atomic_inc_return(&vsen->ved.use_count) != 1) + return 0; + vsen->start_stream_ts = ktime_get_ns(); /* Calculate the frame size */ @@ -275,6 +278,8 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable) vimc_sen_tpg_s_format(vsen); } else { + if (atomic_dec_return(&vsen->ved.use_count) != 0) + return 0; vfree(vsen->frame); vsen->frame = NULL; @@ -437,6 +442,7 @@ static struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc, vsen->ved.process_frame = vimc_sen_process_frame; vsen->ved.get_frame = vimc_sen_get_frame; vsen->ved.dev = vimc->mdev.dev; + atomic_set(&vsen->ved.use_count, 0); /* Initialize the frame format */ vsen->mbus_format = fmt_default; From patchwork Wed Aug 19 18:04:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 702611744 for ; Wed, 19 Aug 2020 18:06:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5225720786 for ; Wed, 19 Aug 2020 18:06:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="BEFAAR8M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbgHSSGa (ORCPT ); Wed, 19 Aug 2020 14:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726946AbgHSSFR (ORCPT ); Wed, 19 Aug 2020 14:05:17 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE26C061757 for ; Wed, 19 Aug 2020 11:05:17 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id 2so1462204pjx.5 for ; Wed, 19 Aug 2020 11:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Myk1HtWNfMPMH6mEsQn60wKu3fbOFzXiNMNij+F/fos=; b=BEFAAR8MyoIxxx+igVHbbPaDJnsuviiG++309FQfr/cS43lp+JqFtnDa+7fDIohDbq w+T/a135DyuxywUD1oltM3KnNAV5z77uRsrpCagXQHy7//9nmOFnm/NziWqcmCdX2u4d x7sDD0GCrBENSmRxoiNj0JiFhbJc7Mp/t9dT94k+Vo9JQX5WeCDh2Psz8/fTMXdrjBEb 2jnod+/vh743GzLDstutDeiEIDFhKhIXEebwzc5vZteiKuiYckfhlkSa60J5oA4r27o+ LHkyzNYqXfd0tD5bOnAIbVyS2Xsbqv4epqrZAdtuHTbvLz6bIMok11bOkskvOVnfKEeE QAMg== 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=Myk1HtWNfMPMH6mEsQn60wKu3fbOFzXiNMNij+F/fos=; b=EBL+ihMnveH7CEOSHUaj/TxcHYfFLLx+5zYG50JbO4vwx1xl6+lFa94YAdiMWwN0PJ 4JqjVufGwDsDB/nKfAyQOPsvJUUbqKK8wst3ObjY2ngC+VI53ZhQdaFMq85hUG792TdN MZPf0nv+6lDsceG5R64gngF7q/luwQ3wknIkehgCZCLg2OvZJCbcfut/vLuJytD/BmOo MmUuV2/Azi+fxLcICNfz950/xLue5Z5gesbhxlHZqrizx4jHzCOMv3tx5QfMfxbsaFd4 9KvWCX6UKIahDYPSxhqd5SWeJ2OKAxaGMnsj5LSOXqsNJhUjvAXNBVbUhLYKwxpjQMd/ OC2A== X-Gm-Message-State: AOAM530AsA2Qti4olFVnyEUEiqoK+gs+HEYVgHgLeCETjmu2U5YVFU64 0GQ6lazAmpyNx8HrU4Llj/BRyw== X-Google-Smtp-Source: ABdhPJyCF6pSzhOSPzo3kzgKW1dmCArD3GflbjqS+gar3ADhQpRU4N4E7ONKEES3VzeqFSvr3z5nXw== X-Received: by 2002:a17:902:bc8a:: with SMTP id bb10mr19731292plb.74.1597860316960; Wed, 19 Aug 2020 11:05:16 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id z25sm29482106pfn.159.2020.08.19.11.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:15 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 4/9] media: vimc: Separate starting stream from pipeline initialisation Date: Wed, 19 Aug 2020 23:34:37 +0530 Message-Id: <20200819180442.11630-5-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Separate the process of initialising pipeline array from starting streaming for all entities in path of a stream. This is needed because multiple streams can stream, but only one pipeline object is needed. Process frames only for those entities in a pipeline which are streaming. This is known through their use counts. Signed-off-by: Kaaira Gupta --- .../media/test-drivers/vimc/vimc-streamer.c | 95 ++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index c1644d69686d..cc40ecabe95a 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -40,33 +40,30 @@ static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) } /** - * vimc_streamer_pipeline_init - Initializes the stream structure + * vimc_streamer_stream_start - Starts streaming for all entities + * in a stream * - * @stream: the pointer to the stream structure to be initialized * @ved: the pointer to the vimc entity initializing the stream * - * Initializes the stream structure. Walks through the entity graph to - * construct the pipeline used later on the streamer thread. - * Calls vimc_streamer_s_stream() to enable stream in all entities of - * the pipeline. + * Walks through the entity graph to call vimc_streamer_s_stream() + * to enable stream in all entities in path of a stream. * * Return: 0 if success, error code otherwise. */ -static int vimc_streamer_pipeline_init(struct vimc_stream *stream, - struct vimc_ent_device *ved) +static int vimc_streamer_stream_start(struct vimc_stream *stream, + struct vimc_ent_device *ved) { struct media_entity *entity; struct video_device *vdev; struct v4l2_subdev *sd; + int stream_size = 0; int ret = 0; - stream->pipe_size = 0; - while (stream->pipe_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { + while (stream_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { if (!ved) { vimc_streamer_pipeline_terminate(stream); return -EINVAL; } - stream->ved_pipeline[stream->pipe_size++] = ved; if (is_media_entity_v4l2_subdev(ved->ent)) { sd = media_entity_to_v4l2_subdev(ved->ent); @@ -104,6 +101,73 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, entity); ved = video_get_drvdata(vdev); } + stream_size++; + } + + vimc_streamer_pipeline_terminate(stream); + return -EINVAL; +} + +/** + * vimc_streamer_pipeline_init - Initialises pipeline and pipe size + * + * @stream: the pointer to the stream structure + * @ved: the pointer to the vimc entity initializing the stream pipeline + * + * Walks through the entity graph to initialise ved_pipeline and updates + * pipe_size too. + * + * Return: 0 if success, error code otherwise. + */ +static int vimc_streamer_pipeline_init(struct vimc_stream *stream, + struct vimc_ent_device *ved) +{ + struct media_entity *entity; + struct media_device *mdev; + struct media_graph graph; + struct video_device *vdev; + struct v4l2_subdev *sd; + int ret; + + entity = ved->ent; + mdev = entity->graph_obj.mdev; + + ret = media_graph_walk_init(&graph, mdev); + if (ret) + return ret; + + media_graph_walk_start(&graph, entity); + + /* + * Start pipeline array initialisation from RAW Capture only to get + * entities in the correct order of their frame processing. + */ + if (!strncmp(entity->name, "RGB", 3)) { + entity = media_graph_walk_next(&graph); + mdev = entity->graph_obj.mdev; + media_graph_walk_cleanup(&graph); + + ret = media_graph_walk_init(&graph, mdev); + if (ret) + return ret; + media_graph_walk_start(&graph, entity); + } + + while (stream->pipe_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { + if (is_media_entity_v4l2_subdev(entity)) { + sd = media_entity_to_v4l2_subdev(entity); + ved = v4l2_get_subdevdata(sd); + } else { + vdev = container_of(entity, struct video_device, entity); + ved = video_get_drvdata(vdev); + } + stream->ved_pipeline[stream->pipe_size++] = ved; + entity = media_graph_walk_next(&graph); + + if (!strcmp(entity->name, stream->ved_pipeline[0]->ent->name)) { + media_graph_walk_cleanup(&graph); + return 0; + } } vimc_streamer_pipeline_terminate(stream); @@ -138,8 +202,11 @@ static int vimc_streamer_thread(void *data) for (i = stream->pipe_size - 1; i >= 0; i--) { ved = stream->ved_pipeline[i]; - ret = ved->process_frame(ved); + if (atomic_read(&ved->use_count) == 0) + continue; + + ret = ved->process_frame(ved); if (ret) break; } @@ -179,6 +246,10 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (stream->kthread) return 0; + ret = vimc_streamer_stream_start(stream, ved); + if (ret) + return ret; + ret = vimc_streamer_pipeline_init(stream, ved); if (ret) return ret; From patchwork Wed Aug 19 18:04:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724835 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEE39175D for ; Wed, 19 Aug 2020 18:06:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 927EF207DE for ; Wed, 19 Aug 2020 18:06:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="pTORjCFY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726578AbgHSSG1 (ORCPT ); Wed, 19 Aug 2020 14:06:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgHSSFX (ORCPT ); Wed, 19 Aug 2020 14:05:23 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 851B3C061342 for ; Wed, 19 Aug 2020 11:05:23 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id j13so1476602pjd.4 for ; Wed, 19 Aug 2020 11:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SodYVYOpelxlR/PUUgvyS/pSUCifZhOvHlkRHcqoLvU=; b=pTORjCFYTNHr6FJHpZFyhc7uKJQ9kxOEGXZ9jwLzM6DfpMu/Nf5UVQtBxfGdk5O/7P D3cnLRy9pXc/1iw3r9eApD81U6HkfzHu5s9StgxSriZvVgZ35VHOm910PlxGAP9puNUK wekAy52kocggf8/HsOO9LR6BOQYFGKZ34v1oZ7LSnRXlg9zaJTy8EISZ4Ws6w8SheO/Q t6ORKGcICcfWfGqNKZPnHqAu1BWwC5vXqNqU26yOVkOSbN84MS3Db78ISCqLM6KV79RA wMX+IjZWJ8nYjFQiyyT10lUkc5EVfCRH5unRULSawT7xk+uKDdm9MHMHjOJzOQJO7e5s FokQ== 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=SodYVYOpelxlR/PUUgvyS/pSUCifZhOvHlkRHcqoLvU=; b=HtBz87UQIYqXzXKi7TL2iEUKkxftqoVBlQbhbT/igOcQz8+nwKm/v4fdTbyldnKz9C PbMNHdeyteqvCZErcdewJMwWi4HhuQVGsPmpmG3IDvHJ+Og1Q8XQ4x94xsQm8UcAZ/MS 9BLrlIzOEwpSkPtUlKRBX77wSQY+RcnyBS2edg4jwoRibrf2Q7NV11sq0hEeRA4lUWnD 8Mofk8YZAehriD64+vgcMs6ApBCP6AzxlLoq+FOeZm7ihyqsNMV8OHNJLjf2sADlfK/H etTTayWp0n0rw7RLH0D8tL0VhlTkbY0AS61A20yahNCapHmcnMnz5dH3yfXRlmXHdWOI ZBXQ== X-Gm-Message-State: AOAM531f7muJS1MsDiZ8sNTo0+m9wtS3NqR2oeslHxs1xmkiZaCL9kZH oAKAAIbBcIDS0IgY3ShY9ykGzA== X-Google-Smtp-Source: ABdhPJy/usO0485ydU9ioIdrovWFV6oMfoabDkun3OhLArWczw0Ai9DvYBq+a94XaEYasHoJoHq2SA== X-Received: by 2002:a17:902:db83:: with SMTP id m3mr202906pld.68.1597860322843; Wed, 19 Aug 2020 11:05:22 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id f18sm29264531pfj.35.2020.08.19.11.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:22 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 5/9] media: vimc: Separate closing of stream and thread Date: Wed, 19 Aug 2020 23:34:38 +0530 Message-Id: <20200819180442.11630-6-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Make separate functions for stopping streaming of entities in path of a particular stream and stopping thread. This is needed to ensure that thread doesn't stop when one device stops streaming in case of multiple streams. Signed-off-by: Kaaira Gupta --- .../media/test-drivers/vimc/vimc-streamer.c | 82 ++++++++++++------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index cc40ecabe95a..6b5ea1537952 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -13,29 +13,59 @@ #include "vimc-streamer.h" /** - * vimc_streamer_pipeline_terminate - Disable stream in all ved in stream + * vimc_streamer_pipeline_terminate - Terminate the thread * - * @stream: the pointer to the stream structure with the pipeline to be - * disabled. + * @stream: the pointer to the stream structure * - * Calls s_stream to disable the stream in each entity of the pipeline + * Erases values of stream struct and terminates the thread * */ static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) { struct vimc_ent_device *ved; - struct v4l2_subdev *sd; while (stream->pipe_size) { stream->pipe_size--; ved = stream->ved_pipeline[stream->pipe_size]; stream->ved_pipeline[stream->pipe_size] = NULL; + } - if (!is_media_entity_v4l2_subdev(ved->ent)) - continue; + kthread_stop(stream->kthread); + stream->kthread = NULL; +} - sd = media_entity_to_v4l2_subdev(ved->ent); - v4l2_subdev_call(sd, video, s_stream, 0); +/** + * vimc_streamer_stream_terminate - Disable stream in all ved in stream + * + * @ved: pointer to the ved for which stream needs to be disabled + * + * Calls s_stream to disable the stream in each entity of the stream + * + */ +static void vimc_streamer_stream_terminate(struct vimc_ent_device *ved) +{ + struct media_entity *entity = ved->ent; + struct video_device *vdev; + struct v4l2_subdev *sd; + + while (entity) { + if (is_media_entity_v4l2_subdev(ved->ent)) { + sd = media_entity_to_v4l2_subdev(ved->ent); + v4l2_subdev_call(sd, video, s_stream, 0); + } + entity = vimc_get_source_entity(ved->ent); + if (!entity) + break; + + if (is_media_entity_v4l2_subdev(entity)) { + sd = media_entity_to_v4l2_subdev(entity); + ved = v4l2_get_subdevdata(sd); + } else { + vdev = container_of(entity, + struct video_device, + entity); + ved = video_get_drvdata(vdev); + } } } @@ -43,25 +73,25 @@ static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) * vimc_streamer_stream_start - Starts streaming for all entities * in a stream * - * @ved: the pointer to the vimc entity initializing the stream + * @cved: the pointer to the vimc entity initializing the stream * * Walks through the entity graph to call vimc_streamer_s_stream() * to enable stream in all entities in path of a stream. * * Return: 0 if success, error code otherwise. */ -static int vimc_streamer_stream_start(struct vimc_stream *stream, - struct vimc_ent_device *ved) +static int vimc_streamer_stream_start(struct vimc_ent_device *cved) { struct media_entity *entity; struct video_device *vdev; struct v4l2_subdev *sd; + struct vimc_ent_device *ved = cved; int stream_size = 0; int ret = 0; while (stream_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { if (!ved) { - vimc_streamer_pipeline_terminate(stream); + vimc_streamer_stream_terminate(cved); return -EINVAL; } @@ -71,7 +101,7 @@ static int vimc_streamer_stream_start(struct vimc_stream *stream, if (ret && ret != -ENOIOCTLCMD) { dev_err(ved->dev, "subdev_call error %s\n", ved->ent->name); - vimc_streamer_pipeline_terminate(stream); + vimc_streamer_stream_terminate(cved); return ret; } } @@ -84,7 +114,7 @@ static int vimc_streamer_stream_start(struct vimc_stream *stream, dev_err(ved->dev, "first entity in the pipe '%s' is not a source\n", ved->ent->name); - vimc_streamer_pipeline_terminate(stream); + vimc_streamer_stream_terminate(cved); pr_info ("first entry not source"); return -EPIPE; } @@ -104,7 +134,7 @@ static int vimc_streamer_stream_start(struct vimc_stream *stream, stream_size++; } - vimc_streamer_pipeline_terminate(stream); + vimc_streamer_stream_terminate(cved); return -EINVAL; } @@ -120,13 +150,14 @@ static int vimc_streamer_stream_start(struct vimc_stream *stream, * Return: 0 if success, error code otherwise. */ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, - struct vimc_ent_device *ved) + struct vimc_ent_device *cved) { struct media_entity *entity; struct media_device *mdev; struct media_graph graph; struct video_device *vdev; struct v4l2_subdev *sd; + struct vimc_ent_device *ved = cved; int ret; entity = ved->ent; @@ -170,6 +201,7 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, } } + vimc_streamer_stream_terminate(cved); vimc_streamer_pipeline_terminate(stream); return -EINVAL; } @@ -246,7 +278,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (stream->kthread) return 0; - ret = vimc_streamer_stream_start(stream, ved); + ret = vimc_streamer_stream_start(ved); if (ret) return ret; @@ -260,6 +292,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (IS_ERR(stream->kthread)) { ret = PTR_ERR(stream->kthread); dev_err(ved->dev, "kthread_run failed with %d\n", ret); + vimc_streamer_stream_terminate(ved); vimc_streamer_pipeline_terminate(stream); stream->kthread = NULL; return ret; @@ -269,18 +302,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (!stream->kthread) return 0; - ret = kthread_stop(stream->kthread); - /* - * kthread_stop returns -EINTR in cases when streamon was - * immediately followed by streamoff, and the thread didn't had - * a chance to run. Ignore errors to stop the stream in the - * pipeline. - */ - if (ret) - dev_dbg(ved->dev, "kthread_stop returned '%d'\n", ret); - - stream->kthread = NULL; - + vimc_streamer_stream_terminate(ved); vimc_streamer_pipeline_terminate(stream); } From patchwork Wed Aug 19 18:04:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724833 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F4AF1744 for ; Wed, 19 Aug 2020 18:06:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05743207DE for ; Wed, 19 Aug 2020 18:06:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="pPiEj6mZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727086AbgHSSGQ (ORCPT ); Wed, 19 Aug 2020 14:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgHSSF3 (ORCPT ); Wed, 19 Aug 2020 14:05:29 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53EB4C061383 for ; Wed, 19 Aug 2020 11:05:29 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id h2so783842plr.0 for ; Wed, 19 Aug 2020 11:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PTx1KB4WomfJKMJISUl/NMNKsl0lboyI/6kyDO0ot0Q=; b=pPiEj6mZwpCKBOJjNus5Xgep/xDdXOmefZBNFxUJ0UkuxtFwSb7XiteXDD/RpgGXAr BtDEJWc5AdhX/vXUpOw+12FcNkAKUvzhMlI48wXzWp+WW1UEwmc9o7pM9AWh8dqIBS0w ZrK9bc1pxSOM9KL9OIjHF3orwkNxAaEqG+FnrPfu69Hma4U5VTk1wguOemxqhTIiqm2L upiwLu3nHLFx9jLs31fQ+jKAQiueaxsZBtGMBq/Hjheed++gxnRnuKJWk3AKIZMJ0xQj HNSwbGV4VXv9Yj5CY34Hh2c+Q62B8EZ/RaVBZDw4guBlx/HrhlmobCF3ZfZ7eOVK8UKy t1xQ== 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:mime-version:content-transfer-encoding; bh=PTx1KB4WomfJKMJISUl/NMNKsl0lboyI/6kyDO0ot0Q=; b=ogn+agSy3DAd7xc4hr2kejT8+J/CKqdktDM0J0l1y81nU4B/35lBBc0sJgIbb/2VXo nrYXixum9gNkiQZP5rlmIoUeuyDrIyywwFcLgoTqItVxNG8f2k/+Oj6RP1xSuLUXCN8B fda5my9Dh/tgZBuVwGyW81vfkns1Wxrhfqx6Ao6/3kNP8jyc87xDdynr7fhb8pzDsUmI mNdKjVArWbxa1pz+j9oyeCN3P2Y1NT25+ZCycZFCWxtcymg3fQFVJWl8RUOuOnUg8fsq sxIpOs9qtxwg6yBBiIrXiaYgsASRjq9f6EIz2MsneqKtDu7hxfrt4vzfApLXo8/iXOSp Gqog== X-Gm-Message-State: AOAM530TedgvbD0BCL1k+v18q5EhDipB1F+4WN+XZJyxJ7e9NoVGUGJj 3+tRxMatgu6aeCMmVw7PttTftw== X-Google-Smtp-Source: ABdhPJyRHC2LN2rK2JG0ifUjrDVg3XtN1jTRkT7emzbh3uHC7nJPSWrn2om7LswmteBjqkTFI3drSA== X-Received: by 2002:a17:90b:23c9:: with SMTP id md9mr5114923pjb.173.1597860328786; Wed, 19 Aug 2020 11:05:28 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id u191sm24353638pgu.56.2020.08.19.11.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:28 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= , Kaaira Gupta Subject: [PATCH v3 6/9] media: vimc: Serialize vimc_streamer_s_stream() Date: Wed, 19 Aug 2020 23:34:39 +0530 Message-Id: <20200819180442.11630-7-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Niklas Söderlund Prepare for multiple video streams from the same sensor by serializing vimc_streamer_s_stream(). Multiple streams will allow for multiple concurrent calls to this function that could involve the same subdevices. If that happens the internal state of the involved subdevices could go out of sync as they are being started and stopped at the same time, prevent this by serializing starting and stopping of the vimc streamer. [Kaaira: only rebased the patch on current HEAD of media-tree] Signed-off-by: Niklas Söderlund Signed-off-by: Kaaira Gupta --- .../media/test-drivers/vimc/vimc-streamer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index 6b5ea1537952..f5c9e2f3bbcb 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -269,22 +269,27 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, struct vimc_ent_device *ved, int enable) { + static DEFINE_MUTEX(vimc_streamer_lock); int ret; if (!stream || !ved) return -EINVAL; + ret = mutex_lock_interruptible(&vimc_streamer_lock); + if (ret) + return ret; + if (enable) { if (stream->kthread) return 0; ret = vimc_streamer_stream_start(ved); if (ret) - return ret; + goto out; ret = vimc_streamer_pipeline_init(stream, ved); if (ret) - return ret; + goto out; stream->kthread = kthread_run(vimc_streamer_thread, stream, "vimc-streamer thread"); @@ -294,17 +299,16 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, dev_err(ved->dev, "kthread_run failed with %d\n", ret); vimc_streamer_stream_terminate(ved); vimc_streamer_pipeline_terminate(stream); - stream->kthread = NULL; - return ret; } } else { if (!stream->kthread) - return 0; + goto out; vimc_streamer_stream_terminate(ved); vimc_streamer_pipeline_terminate(stream); } - - return 0; +out: + mutex_unlock(&vimc_streamer_lock); + return ret; } From patchwork Wed Aug 19 18:04:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724831 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0E7C138C for ; Wed, 19 Aug 2020 18:06:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1FD220786 for ; Wed, 19 Aug 2020 18:06:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="A5kqoEla" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727033AbgHSSGA (ORCPT ); Wed, 19 Aug 2020 14:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgHSSFe (ORCPT ); Wed, 19 Aug 2020 14:05:34 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5442AC061757 for ; Wed, 19 Aug 2020 11:05:34 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d22so12078885pfn.5 for ; Wed, 19 Aug 2020 11:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8XgVLwUgTD8/U0v8SNRxtxRcYTbKexUokfLjtNYtAU8=; b=A5kqoElaAA/N2CUv0n2oki5dj1mSXiwNtEUgxibghuDJime1icMKoM80k41PgW9KZE yysb6ML4hMU9ddJfC6zoYjL9rVO1OBEIE32klDC++oKCQmqWhfMDRq3BuBsMFiVpNHqd lA0cIV0I7FDYDYS+WELzVv4TSdEFFdXLoKOdgl4wIZQXHUM50pnPqfGLsXcBEb4x9wCB cfFadem/MPCeax+ABbsilwpDd8PthlqMnj+gAB8b54dSikHpPTC2Zv+27G/lHmeBxfTp DjmtkcVIs8de3U4JHE70FAhrWk6R/bUxMgIhXpWu/b4gSOyqiWjZJ9Z7oFX8tGPdgpjm kztQ== 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=8XgVLwUgTD8/U0v8SNRxtxRcYTbKexUokfLjtNYtAU8=; b=FkYVhLgBFw8tlKlXst01q8AXMvogN9a4o3+j4xB3yO9j0cDCYIaDrSD5ysoVdx/Ct3 2gPV1rXfy/O1pvV0LAF2lTMbd4DZE3GpqGKawWXkHf4T4pbu8JdPRqpw+ZoULCLGfdzu 5a/yrwcAKx9P9kuQAglYgZ5OEXLdO0jtJvjRFGfsJ3CUUciHQidxPbPHeNYJIJP4rkIp Jk0N/obXlFrTCdvewm458GhxQyAyFN3UKoqYDeivwAVMC6OO5/iY+EYZ8f5puK1I7kGd TY8eQpoaw+AeKAc1gsuR+BmtaQdtgW7RWO6UFb/0U0mwFMIDhWvAYtEaAan0Na2qOi4+ XpIg== X-Gm-Message-State: AOAM530eS1vZjhTYCWkJeASVKh6Jx23fxyAQUHrfWBIdt23ocP5N7tHR Pg4WL30EOaUGDrmtHlcXWDmLMQ== X-Google-Smtp-Source: ABdhPJxJTvbZSSTkAXqY1VgDueP9cacg5w3JD9QPcJ2pKwNQkCJ18KWjcLNkPoQYa/V+4jA3uJmYdg== X-Received: by 2002:a63:705b:: with SMTP id a27mr15324783pgn.405.1597860333821; Wed, 19 Aug 2020 11:05:33 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id p9sm24941711pge.39.2020.08.19.11.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:33 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 7/9] media: vimc: Dynamically allocate stream struct Date: Wed, 19 Aug 2020 23:34:40 +0530 Message-Id: <20200819180442.11630-8-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Multiple streams will share same stream struct if we want them to run on same thread. So remove it from vimc_cap struct so that it doesn't get destroyed when one of the capture does, and allocate it memory dynamically. Use kref with it as it will be used by multiple captures. Signed-off-by: Kaaira Gupta --- drivers/media/test-drivers/vimc/vimc-capture.c | 15 +++++++++++---- drivers/media/test-drivers/vimc/vimc-streamer.c | 17 ++++++----------- drivers/media/test-drivers/vimc/vimc-streamer.h | 2 ++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index 93418cb5a139..73e5bdd17c57 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -28,7 +28,6 @@ struct vimc_cap_device { spinlock_t qlock; struct mutex lock; u32 sequence; - struct vimc_stream stream; struct media_pad pad; }; @@ -241,19 +240,25 @@ 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 vimc_stream *stream; int ret; atomic_inc(&vcap->ved.use_count); vcap->sequence = 0; + stream = kzalloc(sizeof(*stream), GFP_ATOMIC); + kref_init(&stream->refcount); + pipe = &stream->pipe; + /* Start the media pipeline */ - ret = media_pipeline_start(entity, &vcap->stream.pipe); + ret = media_pipeline_start(entity, pipe); if (ret) { vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); return ret; } - ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1); + ret = vimc_streamer_s_stream(stream, &vcap->ved, 1); if (ret) { media_pipeline_stop(entity); vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); @@ -270,9 +275,11 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) static void vimc_cap_stop_streaming(struct vb2_queue *vq) { struct vimc_cap_device *vcap = vb2_get_drv_priv(vq); + struct media_pipeline *pipe = vcap->ved.ent->pipe; + struct vimc_stream *stream = container_of(pipe, struct vimc_stream, pipe); atomic_dec(&vcap->ved.use_count); - vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0); + vimc_streamer_s_stream(stream, &vcap->ved, 0); /* Stop the media pipeline */ media_pipeline_stop(&vcap->vdev.entity); diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index f5c9e2f3bbcb..fade37bee26d 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -20,18 +20,13 @@ * Erases values of stream struct and terminates the thread * */ -static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) +static void vimc_streamer_pipeline_terminate(struct kref *ref) { - struct vimc_ent_device *ved; - - while (stream->pipe_size) { - stream->pipe_size--; - ved = stream->ved_pipeline[stream->pipe_size]; - stream->ved_pipeline[stream->pipe_size] = NULL; - } + struct vimc_stream *stream = container_of(ref, struct vimc_stream, refcount); kthread_stop(stream->kthread); stream->kthread = NULL; + kfree(stream); } /** @@ -202,7 +197,7 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, } vimc_streamer_stream_terminate(cved); - vimc_streamer_pipeline_terminate(stream); + kref_put(&stream->refcount, vimc_streamer_pipeline_terminate); return -EINVAL; } @@ -298,7 +293,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, ret = PTR_ERR(stream->kthread); dev_err(ved->dev, "kthread_run failed with %d\n", ret); vimc_streamer_stream_terminate(ved); - vimc_streamer_pipeline_terminate(stream); + kref_put(&stream->refcount, vimc_streamer_pipeline_terminate); } } else { @@ -306,7 +301,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, goto out; vimc_streamer_stream_terminate(ved); - vimc_streamer_pipeline_terminate(stream); + kref_put(&stream->refcount, vimc_streamer_pipeline_terminate); } out: mutex_unlock(&vimc_streamer_lock); diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.h b/drivers/media/test-drivers/vimc/vimc-streamer.h index 3bb6731b8d4d..533c88675362 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.h +++ b/drivers/media/test-drivers/vimc/vimc-streamer.h @@ -18,6 +18,7 @@ /** * struct vimc_stream - struct that represents a stream in the pipeline * + * @refcount: kref object associated with stream struct * @pipe: the media pipeline object associated with this stream * @ved_pipeline: array containing all the entities participating in the * stream. The order is from a video device (usually a @@ -32,6 +33,7 @@ * process frames for the stream. */ struct vimc_stream { + struct kref refcount; struct media_pipeline pipe; struct vimc_ent_device *ved_pipeline[VIMC_STREAMER_PIPELINE_MAX_SIZE]; unsigned int pipe_size; From patchwork Wed Aug 19 18:04:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724827 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 470BF17D5 for ; Wed, 19 Aug 2020 18:05:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CB7C20658 for ; Wed, 19 Aug 2020 18:05:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="AeQ4ZBAl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbgHSSFs (ORCPT ); Wed, 19 Aug 2020 14:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbgHSSFj (ORCPT ); Wed, 19 Aug 2020 14:05:39 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E882AC061342 for ; Wed, 19 Aug 2020 11:05:38 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id i10so6232710pgk.1 for ; Wed, 19 Aug 2020 11:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YTkbrQzh2/khdYZMeZxW8p1FtiayiX3Fupc8PvOvKFA=; b=AeQ4ZBAl/WGtJJIJ8F3iWM5NJqInykQjQe7mhJV277zDb7kDY387oqAMz9lvq6dHIM 9nm84PZsvzzY/Me5/wF1OYk8Il+rK1psPBwr9VXPnx6opJadazZcPk5EE1W3QIOfURBE yyvw9pNlGbbhVpaYA+59TBhq3A4mVSeU/sC8vLbVGFm2sAQLx2wbmqmyy5i0q3KrNWLu sWDOQ23uT7Sj3P2MfCq9awUv7wrkgX0nBz2sWUdD1+gfN2zqk5dt8jkb9nml0N35z7yQ Gme1o2RtWyXpxcSLvd9rniZqIwbnHEnYvb4aU7MAFrfu8k6QcecWGsTAOMYB1h5PnA7g eqQQ== 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=YTkbrQzh2/khdYZMeZxW8p1FtiayiX3Fupc8PvOvKFA=; b=FG5MtSk3SKhGxRixJ155CIPDvCYzM4EI6NJO/Q6G8iib5nZOJCFJOA5VknYzrbRd8E /H05vzYEoU8RW/6IcnodhnPUdUqhGWOEmF2CoFKJe/TeBdoCrExCkjREq8q5qrL952ER BL5Qt5h2AHLpbi2zoBM8Qda35BVPIWN4ZZtV9R5w9a6d1EhdMtmt2o+2ew7awluAndzH rb3+nIm92rOvfIZydNjsC+mgff4o007SEzFj0EVTcKf2a6iGACoBsQXcYuY02MB6TglN dnn1sSUnXr/+ArRQBPJAK/x5E8keqfI7KMJGGbXRZ20XS4xp2Nwd4mCM3OIwrlMUOyqY NS0w== X-Gm-Message-State: AOAM5325MGg7IJsTCJ0oEhzIQqpCrtgIKO1j6ZmPmEJYzf8QUrk2senz eGKDnZ1EgOakQjj0pQVS1ke3Pw== X-Google-Smtp-Source: ABdhPJz9FXVzBzbnxBPsiEp8FT3qSpFmvjrYy9qe91IbaGS1Dl5M07GnsQY0EV+otS5XqCXDSveb4g== X-Received: by 2002:aa7:9e45:: with SMTP id z5mr20645528pfq.166.1597860338426; Wed, 19 Aug 2020 11:05:38 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id y19sm28254632pfn.77.2020.08.19.11.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:38 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 8/9] media: vimc: Join pipeline if one already exists Date: Wed, 19 Aug 2020 23:34:41 +0530 Message-Id: <20200819180442.11630-9-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Start another capture, if one is already running, by checking for existing pipe. If it exists already, don't fail to start second capture, instead join it to the already running pipeline. Use the same stream struct used by already running capture. Signed-off-by: Kaaira Gupta --- drivers/media/test-drivers/vimc/vimc-capture.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index 73e5bdd17c57..4d20eda9335e 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -247,9 +247,15 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) atomic_inc(&vcap->ved.use_count); vcap->sequence = 0; - stream = kzalloc(sizeof(*stream), GFP_ATOMIC); - kref_init(&stream->refcount); - pipe = &stream->pipe; + if (vcap->ved.ent->pipe) { + pipe = vcap->ved.ent->pipe; + stream = container_of(pipe, struct vimc_stream, pipe); + kref_get(&stream->refcount); + } else { + stream = kzalloc(sizeof(*stream), GFP_ATOMIC); + kref_init(&stream->refcount); + pipe = &stream->pipe; + } /* Start the media pipeline */ ret = media_pipeline_start(entity, pipe); From patchwork Wed Aug 19 18:04:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 11724829 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6401017D5 for ; Wed, 19 Aug 2020 18:06:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C2EF20786 for ; Wed, 19 Aug 2020 18:06:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="DAYZaEy8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbgHSSFr (ORCPT ); Wed, 19 Aug 2020 14:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbgHSSFn (ORCPT ); Wed, 19 Aug 2020 14:05:43 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0727C061383 for ; Wed, 19 Aug 2020 11:05:42 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id y10so9639389plr.11 for ; Wed, 19 Aug 2020 11:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I7Vn+tJdn/z3Gni7/IFrsXgR9xBszu9wFJcFR8d7t7c=; b=DAYZaEy86+xUJSGKApxyGOw1UJsAyjFkzMLM5tSg7n2TcH2yRwDqVl0cjq3+FBqSA1 /rnPQh63tAwDge5VU8SR1vv0qKuje10IoqObeSEiAz3siLzce6e+Cv7UL0XNeFhzAEaw dinBxzAhcZlbdv8B+vDAnpD97Oefe7d4exSRz4g9obzEdBPXx7xwCdDFm5KqSZLjNSKv qBAxfA+xiMm4NugXUax/c5nuyBeszPMMostAdQcq0txo9xXH//20g6guUIAUQVqyZjlJ +KW1RCsZyNtyrSF4NnKa9U/sslH+g8I8H9x45oXuBDQCguoObxbsPVhoEwTGpmZ9MrnV q/Cg== 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=I7Vn+tJdn/z3Gni7/IFrsXgR9xBszu9wFJcFR8d7t7c=; b=lLPLhyK1Z3frUak0RmUuknq40l6DLpKtprt2EeV12tFbFiJXytbbSACe/Exmm7yyv5 xNHYGupmYKrBSHqh1Y8U7AZj2vqJTk91BaFmngvckl6GrZYBhfNsNkuy3oLgvwuiPVua X3lXo7mAr1z7gRQemK4vkyKZOFKJ5EZizmJXbqjVreflNmPFFbBhKerp22JAjD39xHkE z8S6GF9TPuTdKBE33czu6NtY/xn/X1YVmy76paahLrCvoBxZnEhkI0XzVVvwXugRA2Eh 0HNNgntqx6I28TQqPU4JhcO1N+6c4OrbkiiiZluC/IS+Upkzf77PPMt/WAtOgXM8rsd0 o3WQ== X-Gm-Message-State: AOAM531xWsQXhkj8uk2obrOVMty3GlKZB9lCdu80rrgxo2LLtJ7CCyzz MVzguAKmE4duiylk7iX1E9hWKg== X-Google-Smtp-Source: ABdhPJyFtSuf7vdw1h+onygga6DWqg010sj+RfgrrKxlJCVvaedkEPdzyOYvrUG3H5hWOzC4xQGrMA== X-Received: by 2002:a17:902:8504:: with SMTP id bj4mr192134plb.231.1597860342514; Wed, 19 Aug 2020 11:05:42 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.179]) by smtp.gmail.com with ESMTPSA id q2sm28843271pff.107.2020.08.19.11.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 11:05:42 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham Cc: Kaaira Gupta Subject: [PATCH v3 9/9] media: vimc: Run multiple captures on same thread Date: Wed, 19 Aug 2020 23:34:42 +0530 Message-Id: <20200819180442.11630-10-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200819180442.11630-1-kgupta@es.iitr.ac.in> References: <20200819180442.11630-1-kgupta@es.iitr.ac.in> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If multiple captures try to enable stream, start their stream but do not initialise the pipeline again. Also, don't start the thread separately. Starting their streams will update the use count and their frames would be processed by the already running thread. Signed-off-by: Kaaira Gupta --- drivers/media/test-drivers/vimc/vimc-streamer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index fade37bee26d..880c31759cc0 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/vimc/vimc-streamer.c @@ -275,13 +275,14 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, return ret; if (enable) { - if (stream->kthread) - return 0; ret = vimc_streamer_stream_start(ved); if (ret) goto out; + if (stream->kthread) + goto out; + ret = vimc_streamer_pipeline_init(stream, ved); if (ret) goto out;