[{"id":23,"web_url":"https://patchwork.libcamera.org/comment/23/","msgid":"<6b92d8a6-5bdb-5946-0353-49ec4245d9d1@ideasonboard.com>","date":"2018-11-29T12:20:28","subject":"Re: [libcamera-devel] [PATCH] utils: ipu3: Add test capture script","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 28/11/2018 22:45, Laurent Pinchart wrote:\n> The script captures raw frames from cameras based on the Intel IPU3. It\n> takes the sensor name as an argument and isn't meant to depend on a\n> particular platform.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nLooks like a good addition to get us started.\n\nAcked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> ---\n>  utils/ipu3/ipu3-capture.sh | 182 +++++++++++++++++++++++++++++++++++++\n>  1 file changed, 182 insertions(+)\n>  create mode 100755 utils/ipu3/ipu3-capture.sh\n> \n> diff --git a/utils/ipu3/ipu3-capture.sh b/utils/ipu3/ipu3-capture.sh\n> new file mode 100755\n> index 000000000000..930e697e7b44\n> --- /dev/null\n> +++ b/utils/ipu3/ipu3-capture.sh\n> @@ -0,0 +1,182 @@\n> +#!/bin/bash\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +# Copyright (C) 2018, Google Inc.\n> +#\n> +# Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> +#\n> +# ipu3-capture.sh - Capture raw frames from cameras based on the Intel IPU3\n> +#\n> +# The scripts makes use of the following tools, which are expected to be\n> +# executable from the system-wide path or from the local directory:\n> +#\n> +# - media-ctl (from v4l-utils git://linuxtv.org/v4l-utils.git)\n> +# - raw2pnm (from nvt https://github.com/intel/nvt.git)\n> +# - yavta (from git://git.ideasonboard.org/yavta.git)\n> +\n> +# Locate the sensor entity\n> +find_sensor() {\n> +\tlocal bus\n> +\tlocal sensor_name=$1\n> +\n> +\tbus=$(grep \"$sensor_name\" /sys/class/video4linux/v4l-subdev*/name | cut -d ' ' -f 2)\n> +\tif [[ -z $bus ]]; then\n> +\t\techo \"Sensor '$sensor_name' not found.\" >&2\n> +\t\texit 1\n> +\tfi\n> +\n> +\techo \"$sensor_name $bus\"\n> +}\n> +\n> +# Locate the media device\n> +find_media_device() {\n> +\tlocal mdev\n> +\n> +\tfor mdev in /dev/media* ; do\n> +\t\tmedia-ctl -d $mdev -p | grep -q ipu3-cio2 && break\n> +\t\tmdev=\n> +\tdone\n> +\n> +\tif [[ -z $mdev ]] ; then\n> +\t       echo \"IPU3 media device not found.\" >&2\n> +\t       exit 1\n> +\tfi\n> +\n> +\techo $mdev\n> +}\n> +\n> +# Locate the CSI2 and CIO2 and get the sensor format\n> +parse_pipeline() {\n> +\tlocal cio2_queue\n> +\tlocal resolution\n> +\tlocal sensor=$1\n> +\n> +\tread cio2_queue bus_format sensor_size <<< $($mediactl -p | awk \"\n> +\t/^- entity [0-9]*:/ {\n> +\t\tsensor=0;\n> +\t}\n> +\n> +\t/^- entity [0-9]*: $sensor/ {\n> +\t\tsensor=1;\n> +\t}\n> +\n> +\t/^[ \\t]*(stream:0)?\\[fmt:/ {\n> +\t\tif (sensor) {\n> +\t\t\tgsub(\\\".*fmt:\\\", \\\"\\\");\n> +\t\t\tgsub(\\\"[] ].*\\\", \\\"\\\");\n> +\t\t\tgsub(\\\"/\\\", \\\" \\\");\n> +\t\t\tformat=\\$0;\n> +\t\t}\n> +\t}\n> +\n> +\t/^[ \\t]*->/ {\n> +\t\tif (sensor)\n> +\t\t\tcio2=substr(\\$3, 0, 1);\n> +\t}\n> +\n> +\tEND {\n> +\t\tprint cio2 \\\" \\\" format;\n> +\t}\n> +\t\")\n> +\n> +\tipu3_csi2=\"ipu3-csi2 $cio2_queue\"\n> +\tipu3_capture=\"ipu3-cio2 $cio2_queue\"\n> +\n> +\tsensor_width=$(echo $sensor_size | cut -d 'x' -f 1)\n> +\tsensor_height=$(echo $sensor_size | cut -d 'x' -f 2)\n> +\n> +\techo \"Using device $mdev with IPU3 CIO2 queue $cio2_queue\"\n> +}\n> +\n> +# Configure the pipeline\n> +configure_pipeline() {\n> +\tlocal format=\"fmt:$bus_format/$sensor_size\"\n> +\n> +\techo \"Configuring pipeline for $sensor in $format\"\n> +\n> +\t$mediactl -r\n> +\n> +\t$mediactl -l \"\\\"$sensor\\\":0 -> \\\"$ipu3_csi2\\\":0[1]\"\n> +\t$mediactl -l \"\\\"$ipu3_csi2\\\":1 -> \\\"$ipu3_capture\\\":0[1]\"\n> +\n> +\t$mediactl -V \"\\\"$sensor\\\":0 [$format]\"\n> +\t$mediactl -V \"\\\"$ipu3_csi2\\\":1 [$format]\"\n> +}\n> +\n> +# Capture frames\n> +capture_frames() {\n> +\tlocal file_op\n> +\tlocal frame_count=$1\n> +\tlocal ipu3_format=IPU3_${bus_format/_1X10/}\n> +\tlocal save_file=$2\n> +\n> +\tif [ $save_file -eq 1 ]; then\n> +\t\tfile_op=\"--file=/tmp/frame-#.bin\"\n> +\tfi\n> +\n> +\tyavta -c$frame_count -n5 -I -f $ipu3_format -s $sensor_size $file_op \\\n> +\t\t$($mediactl -e \"$ipu3_capture\")\n> +}\n> +\n> +# Convert captured files to ppm\n> +convert_files() {\n> +\tlocal frame_count=$1\n> +\tlocal format=${bus_format/_1X10/}\n> +\tlocal padded_width=$(expr \\( $sensor_width + 49 \\) / 50 \\* 50)\n> +\n> +\techo \"Converting ${sensor_width}x${sensor_height} (${padded_width}x${sensor_height})\"\n> +\n> +\tfor i in `seq -f '%06.0f' 0 $(($frame_count - 1))`; do\n> +\t\tipu3-unpack /tmp/frame-$i.bin /tmp/frame-$i.raw\n> +\t\traw2pnm -x$padded_width -y$sensor_height -f$format /tmp/frame-$i.raw /tmp/frame-$i.ppm\n> +\tdone\n> +}\n> +\n> +# Print usage message\n> +usage() {\n> +\techo \"Usage: $1 [options] sensor-name\"\n> +\techo \"Supported options:\"\n> +\techo \"-c,--count n      Number of frame to capture\"\n> +\techo \"--no-save         Do not save captured frames to disk\"\n> +}\n> +\n> +# Parse command line arguments\n> +frame_count=10\n> +save_file=1\n> +\n> +while (( \"$#\" )) ; do\n> +\tcase $1 in\n> +\t-c|--count)\n> +\t\tframe_count=$2\n> +\t\tshift 2\n> +\t\t;;\n> +\t--no-save)\n> +\t\tsave_file=0\n> +\t\tshift\n> +\t\t;;\n> +\t-*)\n> +\t\techo \"Unsupported option $1\" >&2\n> +\t\tusage $0\n> +\t\texit 1\n> +\t\t;;\n> +\t*)\n> +\t\tbreak\n> +\t\t;;\n> +\tesac\n> +done\n> +\n> +if [ $# != 1 ] ; then\n> +\tusage $0\n> +\texit 1\n> +fi\n> +\n> +sensor_name=$1\n> +\n> +sensor=$(find_sensor $sensor_name)\n> +mdev=$(find_media_device)\n> +\n> +mediactl=\"media-ctl -d $mdev\"\n> +\n> +parse_pipeline $sensor\n> +configure_pipeline\n> +capture_frames $frame_count $save_file\n> +[[ $save_file -eq 1 ]] && convert_files $frame_count\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D570560B0C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Nov 2018 13:20:31 +0100 (CET)","from [192.168.0.21]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3050455A;\n\tThu, 29 Nov 2018 13:20:31 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1543494031;\n\tbh=QeaZD7npWSecBs4/yaaPjA5OEl43XCAwdKV2f5xLYqg=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=PQhuQrdXJQJRkpVGUmocJmQHPyHr0BYSkmkdlQ/gmv/Hk/QcMcUJOv0tTPFDlT5lX\n\tXO+uhmlc04JTZmaErcCQq/YnvqEwO2ssTDULQcjCPd84lWPDt8qHuj0tkP3szysA5P\n\tDACUAnq4LhpQYUtiQEnXzZbvS0fALUn1FjeMVG2c=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20181128224507.24596-1-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\txsFNBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36\n\tOe9X9dXB8YSNt7VjOcO7BTmFn/Z8r92mSAfHXpb07YJWJosQOQARAQABzTBLaWVyYW4gQmlu\n\tZ2hhbSA8a2ll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6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<6b92d8a6-5bdb-5946-0353-49ec4245d9d1@ideasonboard.com>","Date":"Thu, 29 Nov 2018 12:20:28 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.2.1","MIME-Version":"1.0","In-Reply-To":"<20181128224507.24596-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH] utils: ipu3: Add test capture script","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 29 Nov 2018 12:20:32 -0000"}}]