From patchwork Tue Mar 22 09:22:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15502 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 183CAC3265 for ; Tue, 22 Mar 2022 09:23:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8BFB5632E8; Tue, 22 Mar 2022 10:23:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647940988; bh=Q3pB5gwKJwI3YcvZWJDX8RjHEP1L+Gzz2Qm7b36XTW0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=I6Z759dPxn0L64vbO7ZU++9WmX/4j/z/5QdQcUh7rSUzJ3/+ER013uZi9gFod+hXs 75enmAD99hIsTdFarKtNF+buxEtYTHstHAqoEebIdjugykb92X5bF5W8sa6GAcVT8O mk3/z8SLwB4pKqB2fO0CNa6kiIWkKhONKV8KsuBpYK0a27lM0uxTm5s3Q6Azzx2UoY ayiQmBAo3ALLhlI+CA3JchpJlBLCQujmy1Z0WIUZXNK8ah+yyfknYWcquXeW87Vjxe ZfFPj1fw2M0x402wskW3M/ei7h34V0iEx418fQr0Dsudgdlp4XDeg2IFT0qfN3KiKC Qz+nJgtvmK+LQ== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 179CF60397 for ; Tue, 22 Mar 2022 10:23:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hCv/Y/cb"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id 123-20020a1c1981000000b0038b3616a71aso922684wmz.4 for ; Tue, 22 Mar 2022 02:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HWiqsZ82lu+4g9I2xyM3lrW/napbwZNOsGa/P4WcuqY=; b=hCv/Y/cbVnBqkVk4fyaNFcvOfSIVI+4guz4LNUmxE/hObeOryN+NuAucpKqZzpoBSa a8GnNt2f8fXL5GMuGl6+UuEaaaOHUXHtN+m7nmEJNBlzmbruE1+uHH/YAWR0TOloDEzK ZPbe9N1AWIllSQE5hta0sLZi4Fvx5OWl4rFECkSY6x7HXsobX9Le+NCYGbipaMWl65P3 E5dlWCmg+DE4WfPf1cmVz+GjByrD3eQEo74t49e0kMPUG1IfGZB0GgB6iU9X+nVPavMY 9FVorm5xf3qDIC2K9u5SB2WEgq1macQiA/jXBms3wIl3YJ5j9GUyyQlz7NoaMZ1Lreea cb2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HWiqsZ82lu+4g9I2xyM3lrW/napbwZNOsGa/P4WcuqY=; b=X7XXkyBrWTklEp57/wSskD5yajuPwvGmovMQ5ONB5rfawllu/5nw8dquzjnQuks589 K4T7dlFGUVsiz18KsvwmVYCVGDTnNh5hq8R5V/4kx6qsFRL+mxIT59E4a7uoJ1q++Rtb BeIKRoh6o9azTJzsK75uKzu7a0qn+Q1InIcpQeq3B7s71/O2BfDm1dhr3vxmMX8auuED OPXMYnwbJkgeEi+bXbd1fEyM9k5mO2NQMUVbS4LuJEBGnh0JSvBl3VCJDRr5yR/gxyO5 mt5ohGadQr+cP5TL+XWJSW1avTjhX1ji2uAqqhw7ghTADTac98oow2UDvTlQNH14cVWU MwmQ== X-Gm-Message-State: AOAM530PETB6R7JogS9G+Gx/LX/1xfu19rylVIVAXub4T3+QarArV838 BHxfFwgiO/EBhAL2cczLP9qu9OMzY5234A== X-Google-Smtp-Source: ABdhPJym4Qvu7hMr/AfuxW3JNkBcpMKeNTgYPmWIoiIozTZLTBxOKrtK6/7zAMKnkTJKlmmRsCZ3iw== X-Received: by 2002:a5d:6d05:0:b0:203:781d:3f7b with SMTP id e5-20020a5d6d05000000b00203781d3f7bmr21167021wrq.442.1647940984288; Tue, 22 Mar 2022 02:23:04 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:9e9a:99af:e5a6:319b]) by smtp.gmail.com with ESMTPSA id r14-20020a05600c35ce00b0038c9f469979sm1471695wmq.40.2022.03.22.02.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Mar 2022 02:23:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Mar 2022 09:22:54 +0000 Message-Id: <20220322092257.2713521-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322092257.2713521-1-naush@raspberrypi.com> References: <20220322092257.2713521-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/8] libcamera: v4l2_videodevice: Better tracking of the device state X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the existing streaming_ state variable with an enum to track the following three state: Streaming, Stopping, and Stopped. The alternate states will be used in a subsequent commit. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/internal/v4l2_videodevice.h | 3 ++- src/libcamera/v4l2_videodevice.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..32e022543385 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -258,7 +258,8 @@ private: EventNotifier *fdBufferNotifier_; - bool streaming_; + enum class State { Streaming, Stopping, Stopped }; + State state_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..9cea6a608660 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -507,7 +507,7 @@ const std::string V4L2DeviceFormat::toString() const */ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) : V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr), - fdBufferNotifier_(nullptr), streaming_(false) + fdBufferNotifier_(nullptr), state_(State::Stopped) { /* * We default to an MMAP based CAPTURE video device, however this will @@ -1796,7 +1796,7 @@ int V4L2VideoDevice::streamOn() return ret; } - streaming_ = true; + state_ = State::Streaming; return 0; } @@ -1818,7 +1818,7 @@ int V4L2VideoDevice::streamOff() { int ret; - if (!streaming_ && queuedBuffers_.empty()) + if (state_ != State::Streaming && queuedBuffers_.empty()) return 0; ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); @@ -1828,6 +1828,8 @@ int V4L2VideoDevice::streamOff() return ret; } + state_ = State::Stopping; + /* Send back all queued buffers. */ for (auto it : queuedBuffers_) { FrameBuffer *buffer = it.second; @@ -1838,7 +1840,7 @@ int V4L2VideoDevice::streamOff() queuedBuffers_.clear(); fdBufferNotifier_->setEnabled(false); - streaming_ = false; + state_ = State::Stopped; return 0; }