From patchwork Fri Aug 5 18:18:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16988 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 756E0BE173 for ; Fri, 5 Aug 2022 18:19:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2EFE86332F; Fri, 5 Aug 2022 20:19:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659723542; bh=jUULhcV8lDdhRTK48rcn6x/3aLIjh+YoUlTmj2AV7DI=; 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=02u2k3SIjDOzBfQEkMEMJsxvPUUJE+HCNc1J7Zj4j8AAWa2RULQxFnMM0yXzN6oGB 0qjxXHby6WwGOnC8f49eq8FvjaAaUhj7nM6Yk4cTp88L9a5nVNoTZdRIwoUbkcxoSG cecSREUBnLK+HIfxSA2ZYLAAHW5da3El5/BvrJixVKJPO3UywfXw9JFtB0D1bIbKYf OHgADpPLpV6Gl6MlFsdshtKi6UMuHnl4XCeFya8q63uXCHaoxAECxsQDYDaK0W/qzo XM/bHqUGWZyWgYJdThzr5H5OppjQum4wMnRWAYs65SNHVxpX9sSiixOTJXfXK5GVZm Fpsk+tGaHds8A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DFFC603F0 for ; Fri, 5 Aug 2022 20:18:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZIlBqN2m"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 57AF0480; Fri, 5 Aug 2022 20:18:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659723539; bh=jUULhcV8lDdhRTK48rcn6x/3aLIjh+YoUlTmj2AV7DI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZIlBqN2mlARrcrZnbkHHYMugiYNhgxzcHCnA+rseitdux6/9Ph4s6WrgV3YU89CqU jEhZBp+3A76mJje47j9RP3igec851JgdBmjD3KyczF6QhU52AwCkH+KGkTqhHvZGui pi+YAep9sV4u11PKdpijEH76cVAVF0t8/Lo8aPjU= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Aug 2022 23:48:46 +0530 Message-Id: <20220805181850.848886-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220805181850.848886-1-umang.jain@ideasonboard.com> References: <20220805181850.848886-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] utils: ipu3-process: Stream multiple frames using v4l2-ctl 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Stream IMGU using v4l2-ctl as it provides more granular controls on the video nodes. The goal here is to stream a single input file containing multiple frames in 10-bit IPU3 packed bayer format. Such an input file can be created using the ipu3-pack utility. This patch enables the IMGU's parameter node as well in configure_pipeline() without which the input node won't stream successive input frames. yavta commands have been replaced with equivalent v4l2-ctl commands. Also the v4l2-ctl outputs a single file(--stream-to=) as opposed to yavta's one frame per file, so the conversion via raw2pnm needed adjusting. raw2pnm will now read from a single input file (produced as a result of v4l2-ctl ... --stream-to) and use the bytes offset to output separate frames. Lastly, $nbufs have reduced to 4 and $frame_count has been increased to 10. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-process.sh | 54 +++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/utils/ipu3/ipu3-process.sh b/utils/ipu3/ipu3-process.sh index bb4abbe8..828a72f8 100755 --- a/utils/ipu3/ipu3-process.sh +++ b/utils/ipu3/ipu3-process.sh @@ -11,7 +11,7 @@ # # - media-ctl (from v4l-utils git://linuxtv.org/v4l-utils.git) # - raw2pnm (from nvt https://github.com/intel/nvt.git) -# - yavta (from git://git.ideasonboard.org/yavta.git) +# - v4l2-ctl (from http://git.linuxtv.org/v4l-utils.git) imgu_entity="ipu3-imgu 0" @@ -37,17 +37,19 @@ configure_pipeline() { local enable_3a=1 local enable_out=1 local enable_vf=1 + local enable_param=1 local mode=0 # Configure the links $mediactl -r $mediactl -l "\"$imgu_entity input\":0 -> \"$imgu_entity\":0[1]" + $mediactl -l "\"$imgu_entity parameters\":0 -> \"$imgu_entity\":1[$enable_param]" $mediactl -l "\"$imgu_entity\":2 -> \"$imgu_entity output\":0[$enable_out]" $mediactl -l "\"$imgu_entity\":3 -> \"$imgu_entity viewfinder\":0[$enable_vf]" $mediactl -l "\"$imgu_entity\":4 -> \"$imgu_entity 3a stat\":0[$enable_3a]" # Select processing mode (0 for video, 1 for still image) - yavta --no-query -w "0x009819c1 $mode" $($mediactl -e "$imgu_entity") + v4l2-ctl -d $($mediactl -e "$imgu_entity") -c 0x009819c1=$mode # Set formats. The media bus code doesn't matter as it is ignored by the # driver. We should use the FIXED format, but media-ctl doesn't support @@ -62,23 +64,41 @@ configure_pipeline() { process_frames() { configure_pipeline - local yavta="yavta -n $nbufs -c$frame_count" + local stream_setting=" --stream-mmap $nbufs --stream-count=$frame_count" + local out_width=$(echo $out_size | awk -F 'x' '{print $1}') + local out_height=$(echo $out_size | awk -F 'x' '{print $2}') + local vf_width=$(echo $vf_size | awk -F 'x' '{print $1}') + local vf_height=$(echo $vf_size | awk -F 'x' '{print $2}') + local in_width=$(echo $in_size | awk -F 'x' '{print $1}') + local in_height=$(echo $in_size | awk -F 'x' '{print $2}') # Save the main and viewfinder outputs to disk, capture and drop 3A - # statistics. Sleep 500ms between each execution of yavta to keep the + # statistics. Sleep 500ms between each execution of v4l2-ctl to keep the # stdout messages readable. - $yavta -f $IMGU_OUT_PIXELFORMAT -s $out_size "-F$output_dir/frame-out-#.bin" \ - $($mediactl -e "$imgu_entity output") & + v4l2-ctl -d$($mediactl -e "$imgu_entity output") \ + --set-fmt-video=pixelformat=$IMGU_OUT_PIXELFORMAT,width=$out_width,height=$out_height \ + $stream_setting --stream-to=$output_dir/frames-out.bin & sleep 0.5 - $yavta -f $IMGU_VF_PIXELFORMAT -s $vf_size "-F$output_dir/frame-vf-#.bin" \ - $($mediactl -e "$imgu_entity viewfinder") & + v4l2-ctl -d$($mediactl -e "$imgu_entity viewfinder") \ + --set-fmt-video=pixelformat=$IMGU_OUT_PIXELFORMAT,width=$vf_width,height=$vf_height \ + $stream_setting --stream-to=$output_dir/frames-vf.bin & sleep 0.5 - $yavta $($mediactl -e "$imgu_entity 3a stat") & + v4l2-ctl -d $($mediactl -e "$imgu_entity 3a stat") $stream_setting & sleep 0.5 # Feed the IMGU input. - $yavta -f $IMGU_IN_PIXELFORMAT -s $in_size "-F$in_file" \ - $($mediactl -e "$imgu_entity input") + + # To stream out $frame_count on output and vf nodes, input and parameters nodes need to atleast + # stream ($frame_count + $nbufs) frames. + local in_stream_count=$(expr $nbufs + $frame_count) + v4l2-ctl -d $($mediactl -e "$imgu_entity input") \ + --set-fmt-video-out=width=$in_width\,height=$in_height\,pixelformat=$IMGU_IN_PIXELFORMAT \ + --stream-out-mmap $nbufs --stream-from=$in_file --stream-count=$in_stream_count \ + --stream-loop --stream-poll & + + # The input node would not stream until parameters start streaming. + v4l2-ctl -d$($mediactl -e "$imgu_entity parameters") --stream-out-mmap 1 \ + --stream-count=$in_stream_count --stream-poll } # Convert captured files to ppm @@ -92,13 +112,15 @@ convert_files() { local height=$(echo $size | awk -F 'x' '{print $2}') local padded_width=$(expr $(expr $width + 63) / 64 \* 64) - raw2pnm -x$padded_width -y$height -f$format \ - $output_dir/frame-$type-$index.bin \ + local bytes_offset=$(expr $index \* $(expr $padded_width \* $height \* 12) / 8) + echo $bytes_offset + raw2pnm -x$padded_width -y$height -f$format -b $bytes_offset \ + $output_dir/frames-$type.bin \ $output_dir/frame-$type-$index.ppm } run_test() { - IMGU_IN_PIXELFORMAT=IPU3_SGRBG10 + IMGU_IN_PIXELFORMAT=ip3G IMGU_OUT_PIXELFORMAT=NV12 IMGU_VF_PIXELFORMAT=NV12 @@ -193,6 +215,6 @@ mediactl="media-ctl -d $mdev" echo "Using device $mdev" output_dir="/tmp" -frame_count=5 -nbufs=7 +frame_count=10 +nbufs=4 run_test From patchwork Fri Aug 5 18:18:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16989 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 29FE7C3275 for ; Fri, 5 Aug 2022 18:19:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91F37603E4; Fri, 5 Aug 2022 20:19:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659723542; bh=ZhNavlpmdRSddSQo8QA2pmbNcVOml11Ur7hNgZEMLEM=; 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=dSGeDmItjgYg7xtj4zq9CGrQ1qT4+lT7zTEjlhxXoftPVukRRzWXDirO1oEUGXSxp qPglM+zCsN+cyafgyEKvqaNDAcrkYW+SWdD5pkYT8wqBDadCmYD9RfPF/ZJbpAmtHw D9EFRRBaluEX+Bel9+9GH5V/LmxonE/jkz1QO38yPp826G5X8ynNfn19aPaQKGdIVb FPDxY/+fpe7sffm+VaFYfnDr7QjDw+hICF94ov+T0arVP7GUJEHLG9JbEhkrVcjbY5 MnKFprrpTwI4xxhQLZBs2Sa+kONqc4zUc+6gzyI07xc8XO/vCfA8PLt7rFm1evTYa+ uVCmvqKmCVVoQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4FF0F603E4 for ; Fri, 5 Aug 2022 20:19:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o4I/5B88"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4A9A26E0; Fri, 5 Aug 2022 20:19:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659723541; bh=ZhNavlpmdRSddSQo8QA2pmbNcVOml11Ur7hNgZEMLEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o4I/5B88+Zvp1Q9knRNCgP6daIRHr0TJMN+aw38WSAuiP3kYVRnVUL+Rh8LNLHA7+ dgbM4kPIzWG7Im50vSt9wU+iT56Mqym1WGwPzBC6xDTFGZTIfqZAy3c3N0+46XL4kx 0lIIRsgfvZPTd1Ahkmaus4STHbJtpcmxWgzZgrY8= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Aug 2022 23:48:47 +0530 Message-Id: <20220805181850.848886-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220805181850.848886-1-umang.jain@ideasonboard.com> References: <20220805181850.848886-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] utils: ipu3: Helper to generate IMGU input streaming file 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Usage: ipu3-gen-imgu-input.sh --count --size The input file is generated in 10-bit bayer which can be directly streamed to IMGU. Each frame (starting from 0) has a black background with a visible "Frame " label in the center. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-gen-imgu-input.sh | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 utils/ipu3/ipu3-gen-imgu-input.sh diff --git a/utils/ipu3/ipu3-gen-imgu-input.sh b/utils/ipu3/ipu3-gen-imgu-input.sh new file mode 100755 index 00000000..ea0d385d --- /dev/null +++ b/utils/ipu3/ipu3-gen-imgu-input.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2022, Google Inc. +# +# Author: Umang Jain +# +# ipu3-gen-imgu-input.sh - Generate input file for IMGU streaming +# +# The scripts makes use of the following tools, which are expected to be +# found in $PATH: +# +# - raw2pnm (from nvt https://github.com/intel/nvt.git) +# - pnm2raw (from nvt https://github.com/intel/nvt.git) +# - ipu-pack (from https://git.libcamera.org/libcamera/libcamera.git/) +# - convert (from https://github.com/ImageMagick/ImageMagick/tree/main/utilities) + +#default frame count +frame_count=10 + +validate_size() { + local size=$1 + local width=$(echo $size | awk -F 'x' '{print $1}') + local height=$(echo $size | awk -F 'x' '{print $2}') + + [[ "x${size}" == "x${width}x${height}" ]] +} + +# Print usage message +usage() { + echo "Usage: $(basename $1) --count --size " + echo "Supported options:" + echo "--count count Generate input file containing frames, default=10" + echo "--size size Frame size ('width' x 'height')" + echo "" +} + +# Parse command line arguments +while (( "$#" )) ; do + case $1 in + --count) + frame_count=$2 + shift 2 + ;; + --size) + in_size=$2 + if ! validate_size $in_size ; then + echo "Invalid size '$in_size'" + usage $0 + exit 1 + fi + shift 2 + ;; + -*) + echo "Unsupported option $1" >&2 + usage $0 + exit 1 + ;; + *) + break + ;; + esac +done + +if [[ -z ${in_size+x} ]] ; then + usage $0 + exit 1 +fi + +echo "Generating Input file frame-$in_size.raw" +for i in `seq 0 $(expr $frame_count - 1)` +do + convert -background "#000000" -size $in_size -fill "#ffffff" -pointsize 120 -gravity center label:"Frame $i" frame-$i.ppm + pnm2raw frame-$i.ppm frame-$i.raw + ipu3-pack frame-$i.raw - >> frame-$in_size.raw + + rm frame-$i.ppm + rm frame-$i.raw +done From patchwork Fri Aug 5 18:18:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16990 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 5DD07BE173 for ; Fri, 5 Aug 2022 18:19:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1479B63335; Fri, 5 Aug 2022 20:19:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659723545; bh=9lE0amTknXsyC7TQgRRPyXW7aTh/R/rja9omnQvnqq8=; 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=WYA6AkAJ9w1CwN6a97B/7oiUppYEie2FpotgJp1DaFY/ghwH3+SMYucq3WE7v2Y6f ZqAONXZ1vG5nwnF2Y/M87mU5vR31LaRKKQjtCNNfsVbDNHCxF7Jinyxqr8mxjcpoTx e+RXnqRiocIGNLt2oLd3yQL8zYSYGpHAvcMoN/BVOVM571pUKj+lbkEXqd7kslYXHF H0M0PW5Ag4myCBG8Lhydx5Mm26IWnkSJYuo3VuF1pFM5c6mBHXFOerfE68Mva/z2hn PS/Ixzq97qub29qfM8AK4Y3NYQQ38kbZX8TCgaOAbOv7TkkMCRjry8Sc+6IIvNSd8q T+5u9d4R4qYRQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 43618603F0 for ; Fri, 5 Aug 2022 20:19:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sKu+ARhB"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3D537480; Fri, 5 Aug 2022 20:19:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659723543; bh=9lE0amTknXsyC7TQgRRPyXW7aTh/R/rja9omnQvnqq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sKu+ARhBehGVC7hM7QuiZudhtlKt92A7SEI/lJRoWfFIVxynhw4sJ/SnNtuMafqcL 5v4h9XMXC19OAcR+67HUr6eRVTrLtU0nIFq1J/qXgnYAAokR4HaBTuk1Yr+81VvAkD x+ZAkBvofEA4+vhAMdd6CoEOEXoQphWFipou80oE= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Aug 2022 23:48:48 +0530 Message-Id: <20220805181850.848886-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220805181850.848886-1-umang.jain@ideasonboard.com> References: <20220805181850.848886-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] utils: ipu3-gen-imgu-input: Generate frames with different b/g 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Differ each input generated frame by background color. This would help us to deterimine how the IMGU statistics generation delay for each frame. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-gen-imgu-input.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/ipu3/ipu3-gen-imgu-input.sh b/utils/ipu3/ipu3-gen-imgu-input.sh index ea0d385d..9e233396 100755 --- a/utils/ipu3/ipu3-gen-imgu-input.sh +++ b/utils/ipu3/ipu3-gen-imgu-input.sh @@ -66,10 +66,14 @@ if [[ -z ${in_size+x} ]] ; then exit 1 fi +colors=(black red green violet yellow orange purple white brown pink gray) + echo "Generating Input file frame-$in_size.raw" for i in `seq 0 $(expr $frame_count - 1)` do - convert -background "#000000" -size $in_size -fill "#ffffff" -pointsize 120 -gravity center label:"Frame $i" frame-$i.ppm + color_index=$(expr $i % ${#colors[@]}) + convert -background "${colors[$color_index]}" -size $in_size -fill "white" \ + -pointsize 120 -gravity center label:"Frame $i" frame-$i.ppm pnm2raw frame-$i.ppm frame-$i.raw ipu3-pack frame-$i.raw - >> frame-$in_size.raw From patchwork Fri Aug 5 18:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16991 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 E4DF8BE173 for ; Fri, 5 Aug 2022 18:19:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A4CD963338; Fri, 5 Aug 2022 20:19:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659723546; bh=fGrdO2TuEep+O+72BRzStN55XplH5FweOMO9CGFaOEk=; 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=erFMzaWUWt6NoJESgtlimtVKVQpl4T3/XigjYRULK/i9wfFEAYAK9zjyRQdnx9wjh OjGzdaPXVatEebY6liYC765DXhF2u3qstHZ4Bvy6OwyD1WtvUWyZD5hEXD3lKpo2aX xM8yBPv9mtIDkQZ4rJkzhY2yJuaW2cGAtUO5mYi/bebIOZzLsTKUb6fEXovy8oytd+ EO9QB6oYrx9OS8usXoAaJ12Cw0ImHU/LAxaPhKHsz+k6s6Z6/yTf622JiPH/BsxVJP PRIXrzk+yl4Q3AMQt6L3gpLUiD9V/bNo5kun1X7tR8xaalDFhVQKkwcZ78NZPi/+uE a4JxMdP2e5VWw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A6E663338 for ; Fri, 5 Aug 2022 20:19:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uEWCf5So"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 61D9A480; Fri, 5 Aug 2022 20:19:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659723545; bh=fGrdO2TuEep+O+72BRzStN55XplH5FweOMO9CGFaOEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uEWCf5SoQE8DuL//UVHlSPxaDjd9XG+uDOYsdMkJEz5vuXy8IE2wvEPKP75uRKnMf dVbdJCdUu3J8K5pWWdmQ6bIM8nXWFryykToWYhfwDjzdK7PtuEcefXygE1uEbZI+cr RijytFdvSnvkGy1hjQoRDtzDEbC7SveriT0uH0Ss= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Aug 2022 23:48:49 +0530 Message-Id: <20220805181850.848886-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220805181850.848886-1-umang.jain@ideasonboard.com> References: <20220805181850.848886-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] utils: ipu3: Executable helper to read statistics 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Usage: ipu3-read-stats input-file output-file [Currently only reads R,G,B averages out of AWB] To be extended to dump more meaningful stats. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-read-stats.c | 168 +++++++++++++++++++++++++++++++++++ utils/ipu3/meson.build | 2 + 2 files changed, 170 insertions(+) create mode 100644 utils/ipu3/ipu3-read-stats.c diff --git a/utils/ipu3/ipu3-read-stats.c b/utils/ipu3/ipu3-read-stats.c new file mode 100644 index 00000000..cd342a63 --- /dev/null +++ b/utils/ipu3/ipu3-read-stats.c @@ -0,0 +1,168 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ipu3-read-stats - Dump IPU3 statistics + * + * Copyright 2022 Umang Jain + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/linux/intel-ipu3.h" + +static void usage(const char *argv0) +{ + printf("Utility for dumping IPU3 statistics\n"); + printf("Usage: %s --if --bds --gdc input-file output-file\n", + basename(argv0)); + printf(" widthxheight\n"); + printf("If the output-file '-', output data will be written to standard output\n"); +} + +void readSize(const char *size, unsigned int *w, unsigned int *h) +{ + char *sz = strdup(size); + const char *delim = "x"; + char *token = strtok(sz, delim); + if (token) + *w = atoi(token); + + token = strtok(NULL, delim); + if (token) + *h = atoi(token); +} + +int main(int argc, char *argv[]) +{ + int in_fd; + FILE *fout; + int ret; + unsigned int bds_w, bds_h = 0; + unsigned int iif_w, iif_h = 0; + unsigned int gdc_w, gdc_h = 0; + + if (argc != 9) { + usage(argv[0]); + return 1; + } + + if (strcmp(argv[1], "--if") == 0) { + readSize(argv[2], &iif_w, &iif_h); + } + + if (strcmp(argv[3], "--bds") == 0) { + readSize(argv[4], &bds_w, &bds_h); + } + + if (strcmp(argv[5], "--gdc") == 0) { + readSize(argv[6], &gdc_w, &gdc_h); + } + + if (!bds_w || !bds_h || !iif_w || !iif_h || !gdc_w || !gdc_h) { + usage(argv[0]); + return 1; + } + + in_fd = open(argv[7], O_RDONLY); + if (in_fd == -1) { + fprintf(stderr, "Failed to open statistics file '%s': %s\n", + argv[1], strerror(errno)); + return 1; + } + + if (strcmp(argv[8], "-") == 0) { + fout = stdout; + } else { + fout = fopen(argv[8], "w"); + if (!fout) { + fprintf(stderr, "Failed to open output file '%s': %s\n", + argv[4], strerror(errno)); + close(in_fd); + return 1; + } + } + + int frame = 0; + struct ipu3_uapi_stats_3a *stats = (struct ipu3_uapi_stats_3a *) malloc(sizeof(struct ipu3_uapi_stats_3a)); + + while (1) { + ret = read(in_fd, stats, sizeof(struct ipu3_uapi_stats_3a)); + if (ret < 0) { + fprintf(stderr, "Failed to read stats data: %s\n", + strerror(errno)); + goto done; + } + + if ((unsigned)ret < sizeof(struct ipu3_uapi_stats_3a)) { + if (ret != 0) + fprintf(stderr, "%u bytes of stray data at end of input\n", + ret); + goto done; + } + + /* ================ Dump AWB stats ================ */ + + uint32_t k_min_grid_w = 16; + uint32_t k_max_grid_w = 80; + uint32_t minError = UINT_MAX; + uint32_t best_log2 = 0; + uint32_t stride = 0; + + struct ipu3_uapi_grid_config grid = stats->stats_4a_config.awb_config.grid; + + for (uint32_t shift = grid.block_width_log2; shift <= 6; ++shift) { + uint32_t width = bds_w >> shift; + if (width < k_min_grid_w) + width = k_min_grid_w; + else if (width > k_max_grid_w) + width = k_max_grid_w; + + width = width << shift; + uint32_t error = bds_w > width ? bds_w - width : width - bds_w; + if (error >= minError) + continue; + + minError = error; + stride = width; + best_log2 = shift; + } + + stride = stride >> best_log2; + + /* Sum the per-channel averages */ + double red_sum = 0, green_sum = 0, blue_sum = 0; + for (unsigned int cellY = 0; cellY < grid.height; cellY++) { + for (unsigned int cellX = 0; cellX < grid.width; cellX++) { + uint32_t cell_pos = cellY * stride + cellX; + + const struct ipu3_uapi_awb_set_item *cell = + (const struct ipu3_uapi_awb_set_item *)( + &stats->awb_raw_buffer.meta_data[cell_pos] + ); + const uint8_t G_avg = (cell->Gr_avg + cell->Gb_avg) / 2; + + red_sum += cell->R_avg; + green_sum += G_avg; + blue_sum += cell->B_avg; + } + } + + fprintf(fout, "Frame: %d, redSum: %.1f, greenSum: %.1f, blueSum: %.1f\n", + frame, red_sum, green_sum, blue_sum); + frame++; + } + +done: + free(stats); + close(in_fd); + fclose(fout); + + return ret ? 1 : 0; +} diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build index c92cc658..88fc2a1b 100644 --- a/utils/ipu3/meson.build +++ b/utils/ipu3/meson.build @@ -2,3 +2,5 @@ ipu3_pack = executable('ipu3-pack', 'ipu3-pack.c') ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c') + +ipu3_read_stats = executable('ipu3-read-stats', 'ipu3-read-stats.c') From patchwork Fri Aug 5 18:18:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16992 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 5D189BE173 for ; Fri, 5 Aug 2022 18:19:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 223F463330; Fri, 5 Aug 2022 20:19:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659723549; bh=qFO9CDiF3ZTVw/nIY2glsWHEG/EBVrbg07sl2+XwL1U=; 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=ToJ2xDnv3t/Nz/q57AEdwx/BstI8qjHWkMMJ2uINFYBA2vj9W8JUZiB8k5/fqoBJ4 EvVAhMJR7se6WAjciCfysYJz9FLlLBdznM9l0Pb38Ryqj4V85o57v1DjWzxYdNexbs 87fTiKIxFTCOmCYQNZmLynk79zZdgE1mOSY+csMW5avBE8UABU40QZgw6lGLR69skj M4CH4fx2L/jeZx4nxpLg3OV34uHuL60IVsd+cu7R0+jenRlJXEA5PqrpEIpwsLAjGA OL+awNstR7MNa7WWMCQYOKEQWcCjFfgpdntgdvrngrJU4JylM6Oc41uifeIgkeaWRi A+K7fCJqL4pSw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 584A6603F0 for ; Fri, 5 Aug 2022 20:19:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="t8IeMJv9"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:69e0:a479:4ccc:ab2a:bf48]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 54CE5480; Fri, 5 Aug 2022 20:19:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659723547; bh=qFO9CDiF3ZTVw/nIY2glsWHEG/EBVrbg07sl2+XwL1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8IeMJv9phuwLoSro8pFKdHQdAYR3SjerUhFZZYCU6EVTfYAtRgWYWFHc3TXvLQi1 QgYiFcsuY+pXwcpYqeLKv81h3vZhQzN2+Dn6Seohx04TsZDhXnNwIk90fkvT37TpRg QATXX3eYeZpV5eSNt7SJxcb8GY9SlD+twkvEWOaM= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Aug 2022 23:48:50 +0530 Message-Id: <20220805181850.848886-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220805181850.848886-1-umang.jain@ideasonboard.com> References: <20220805181850.848886-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] utils: ipu3: ipu3-process Save generated stats to a file 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Save generated stats to a file, which can be dumped using ipu3-read-stats utility. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-process.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/ipu3/ipu3-process.sh b/utils/ipu3/ipu3-process.sh index 828a72f8..84f42302 100755 --- a/utils/ipu3/ipu3-process.sh +++ b/utils/ipu3/ipu3-process.sh @@ -83,7 +83,8 @@ process_frames() { --set-fmt-video=pixelformat=$IMGU_OUT_PIXELFORMAT,width=$vf_width,height=$vf_height \ $stream_setting --stream-to=$output_dir/frames-vf.bin & sleep 0.5 - v4l2-ctl -d $($mediactl -e "$imgu_entity 3a stat") $stream_setting & + v4l2-ctl -d $($mediactl -e "$imgu_entity 3a stat") $stream_setting \ + --stream-to=$output_dir/frames-stat.bin & sleep 0.5 # Feed the IMGU input.