From patchwork Fri Mar 25 09:09:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15548 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 35145C3264 for ; Fri, 25 Mar 2022 09:09:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E65CD604D5; Fri, 25 Mar 2022 10:09:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648199356; 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=kFzx16KZsedb0ZrJUb8cfN6fuqHFZm/TMwlnm95pdFYRVXGtG4y2WcvGxM6IvIBoE +CMHrIb8AKDxrBlGxA47LmUOTxuP0NA+lz8F90H0h+1bsLemBVfkeaKYoraY/7tgf5 ZqALzUoENQ26DlrHJwYW7jAULpSHpTjIEeijn9QH7d9UeqcjR8XaYqFwOtpZp2sggS 0AFu0CO1/SeBZPY1LhYb/eWoO3I04KeTPF8O3PwO0eGPrSLr3p0QhEIGRcWkqhM/Xd qby6toK8ea5z3xyY0wJqoYrY44DFUIM1sk5I2roF8QhRAJSa5Rj3CyVJ8NGa/tPRdv XNvsi312FoazQ== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5483B604C4 for ; Fri, 25 Mar 2022 10:09:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="AbJ3m93G"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id 123-20020a1c1981000000b0038b3616a71aso3978129wmz.4 for ; Fri, 25 Mar 2022 02:09:13 -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=AbJ3m93GA5nk2+YsiFwIjZ/1U568mSHusvwYIfcCfRiCX7vVCdD4hJEuvmGD7M5txU NN94uMqwzmT6Dq364ftTHVb6axOIi7NdM05hDFDSqpkUI6aQ4WU5ciKYv08Lf2c9TlZ3 bUJsWbrlG84DwnOqeEXq7aRrjOaWr4m5RfGtazJEbiGm067VYdda/AiPX5bSLZj1hItk EOJ/tSt7jCEkJrU+5O5DcRgP97bYRDeDGIsm0cYEMvA+iu43VnQ/aQNHf6EfS7mjSnJ5 kFSnRNpNrOtSzzwFIsisN8fCLGdy1GTF6vOxvNzthXLa1QEXzoS2eDiMqlb83xaxUZBg Ukhg== 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=Z1f9kB0ujk/4mW8PgCijuDdWe4y6mQ3Kt9uFCuI0XUdR1t08JXPI3no4WuMEaUBWh7 SKbWsdgkhxERc8AvLtPJgyhDPeNLL+z8DFXtx9Y0y/m0XCM4sA84Xievq7fqf6Ashtwm tuMLtzCjPtVWveen64t4ykF1Shpz+PC20azNHpbG96LdlZTij8sWKHfd1IqPEb7wz+5U Fy/3Gct/dPa7L5HEh/14rmIOccH/z6QDrrnyrEul2+lzdqXs/TYBHsqGneV9GM1F7G6X u9lc1jKsoDQVsOp6Omg2wuQBIrv6MoEOI9SY5rdrYU9dcdy95scQMj/sYH5AKjX1gUm8 g3fw== X-Gm-Message-State: AOAM533RxWc+MjWYqy7HRe7QBX5oJ84wTgV2AwI2E71HtwRMaQORztXp 3mjud4I5WrwYJBoRoHAZoL8mqVw6G0KFEQ== X-Google-Smtp-Source: ABdhPJwuqOZX3XP0sqWj806E6cukTxPXpZqiP2OSaRphETaABQu1kkSiIxJNfr1xDeX38hBiuJjkGA== X-Received: by 2002:a05:600c:3512:b0:38c:be56:fc9c with SMTP id h18-20020a05600c351200b0038cbe56fc9cmr15376466wmq.197.1648199351119; Fri, 25 Mar 2022 02:09:11 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:478c:773f:4734:d0bc]) by smtp.gmail.com with ESMTPSA id c4-20020a056000184400b0020584c40778sm4915297wri.103.2022.03.25.02.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 02:09:10 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Mar 2022 09:09:00 +0000 Message-Id: <20220325090903.880311-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220325090903.880311-1-naush@raspberrypi.com> References: <20220325090903.880311-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- 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; }