From patchwork Wed Jun 16 23:44:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12624 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 57874BD78E for ; Wed, 16 Jun 2021 23:45:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 670CD68941; Thu, 17 Jun 2021 01:45:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ro/pbD+F"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F2C86029D for ; Thu, 17 Jun 2021 01:45:01 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DCD69E53; Thu, 17 Jun 2021 01:45:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1623887101; bh=qsvJH/LnPBeVM4aVFfNCSvj8QYxZUlvlCqyEYWN2rSs=; h=From:To:Cc:Subject:Date:From; b=Ro/pbD+Fmvr02FpnVvP9x+3q7zdf3CmGO2vxRaKzFZ8NyJ9AxZxYGA6UcujATyGZ8 MuM/zbVi8GMXJqsLSBG4dDJdtc/80HIhPcx697PAT5qT9abXMywiT2wV49qlwaC7Ul xb6x1FALTlgyDOr9eXQwUFPO6nkqKm0NNTVradc0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Jun 2021 02:44:22 +0300 Message-Id: <20210616234422.24789-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: pipeline: simple: Fix crash when storing timestamp in metadata 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Commit 922833f774f6 ("libcamera: simple: Report sensor timestamp") unconditionally tries to access the request through the capture buffer to store the capture timestamp in the metadata. This causes a null pointer dereference when using a converter, as the capture buffers are free-wheeling in that case, and not associated with a request. Fix this by getting the request from the user-facing buffer, which can be the capture buffer when no converter is used. Fixes: 922833f774f6 ("libcamera: simple: Report sensor timestamp") Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/simple/simple.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 36fd9b852b33..e63d0bfd2fcb 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -1127,14 +1127,28 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer) } /* - * Record the sensor's timestamp in the request metadata. + * Record the sensor's timestamp in the request metadata. The request + * needs to be obtained from the user-facing buffer, as internal + * buffers are free-wheeling and have no request associated with them. * * \todo The sensor timestamp should be better estimated by connecting * to the V4L2Device::frameStart signal if the platform provides it. */ Request *request = buffer->request(); - request->metadata().set(controls::SensorTimestamp, - buffer->metadata().timestamp); + + if (data->useConverter_ && !data->converterQueue_.empty()) { + const std::map &outputs = + data->converterQueue_.front(); + if (!outputs.empty()) { + FrameBuffer *outputBuffer = outputs.begin()->second; + if (outputBuffer) + request = outputBuffer->request(); + } + } + + if (request) + request->metadata().set(controls::SensorTimestamp, + buffer->metadata().timestamp); /* * Queue the captured and the request buffer to the converter if format