{"id":953,"url":"https://patchwork.libcamera.org/api/1.1/patches/953/?format=json","web_url":"https://patchwork.libcamera.org/patch/953/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190408135006.15423-5-niklas.soderlund@ragnatech.se>","date":"2019-04-08T13:50:05","name":"[libcamera-devel,v4,4/5] cam: Extend request completion handler to deal with multiple streams","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"ab682ff1c8745f17c8a403ce07610406cb675063","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/953/mbox/","series":[{"id":246,"url":"https://patchwork.libcamera.org/api/1.1/series/246/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=246","date":"2019-04-08T13:50:01","name":"cam: Add support to specify multiple stream configurations with roles","version":4,"mbox":"https://patchwork.libcamera.org/series/246/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/953/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/953/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F34360B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Apr 2019 15:50:55 +0200 (CEST)","from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 4d1f2556-5a05-11e9-846a-005056917a89;\n\tMon, 08 Apr 2019 15:50:48 +0200 (CEST)"],"X-Halon-ID":"4d1f2556-5a05-11e9-846a-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  8 Apr 2019 15:50:05 +0200","Message-Id":"<20190408135006.15423-5-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190408135006.15423-1-niklas.soderlund@ragnatech.se>","References":"<20190408135006.15423-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 4/5] cam: Extend request completion\n\thandler to deal with multiple streams","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":"Mon, 08 Apr 2019 13:50:55 -0000"},"content":"The completion handler needs to handle all buffers in the request. Solve\nthis by iterating over all buffers in the completed request. The streams\nare named automatically streamX, where X is the order of which the\nstream was passed to configureStream().\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/main.cpp | 48 +++++++++++++++++++++++++++++++++++-------------\n 1 file changed, 35 insertions(+), 13 deletions(-)","diff":"diff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex ac4c7e78c597a2c5..337933d412451e20 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -11,6 +11,7 @@\n #include <limits.h>\n #include <map>\n #include <signal.h>\n+#include <sstream>\n #include <string.h>\n \n #include <libcamera/libcamera.h>\n@@ -23,6 +24,7 @@ using namespace libcamera;\n \n OptionsParser::Options options;\n std::shared_ptr<Camera> camera;\n+std::map<Stream *, std::string> streamInfo;\n EventLoop *loop;\n BufferWriter *writer;\n \n@@ -87,9 +89,12 @@ static int prepareCameraConfig(CameraConfiguration *config)\n {\n \tstd::vector<StreamUsage> roles;\n \n+\tstreamInfo.clear();\n+\n \t/* If no configuration is provided assume a single video stream. */\n \tif (!options.isSet(OptStream)) {\n \t\t*config = camera->streamConfiguration({ Stream::VideoRecording() });\n+\t\tstreamInfo[config->front()] = \"stream0\";\n \t\treturn 0;\n \t}\n \n@@ -142,31 +147,48 @@ static int prepareCameraConfig(CameraConfiguration *config)\n \t\t\t(*config)[stream].pixelFormat = conf[\"pixelformat\"];\n \t}\n \n+\tunsigned int index = 0;\n+\tfor (Stream *stream : *config) {\n+\t\tstreamInfo[stream] = \"stream\" + std::to_string(index);\n+\t\tindex++;\n+\t}\n+\n \treturn 0;\n }\n \n static void requestComplete(Request *request, const std::map<Stream *, Buffer *> &buffers)\n {\n-\tstatic uint64_t last = 0;\n+\tstatic uint64_t now, last = 0;\n+\tdouble fps = 0.0;\n \n \tif (request->status() == Request::RequestCancelled)\n \t\treturn;\n \n-\tBuffer *buffer = buffers.begin()->second;\n+\tstruct timespec time;\n+\tclock_gettime(CLOCK_MONOTONIC, &time);\n+\tnow = time.tv_sec * 1000 + time.tv_nsec / 1000000;\n+\tfps = now - last;\n+\tfps = last && fps ? 1000.0 / fps : 0.0;\n+\tlast = now;\n \n-\tdouble fps = buffer->timestamp() - last;\n-\tfps = last && fps ? 1000000000.0 / fps : 0.0;\n-\tlast = buffer->timestamp();\n+\tstd::stringstream info;\n+\tinfo << \"fps: \" << std::fixed << std::setprecision(2) << fps;\n \n-\tstd::cout << \"seq: \" << std::setw(6) << std::setfill('0') << buffer->sequence()\n-\t\t  << \" buf: \" << buffer->index()\n-\t\t  << \" bytesused: \" << buffer->bytesused()\n-\t\t  << \" timestamp: \" << buffer->timestamp()\n-\t\t  << \" fps: \" << std::fixed << std::setprecision(2) << fps\n-\t\t  << std::endl;\n+\tfor (auto it = buffers.begin(); it != buffers.end(); ++it) {\n+\t\tStream *stream = it->first;\n+\t\tBuffer *buffer = it->second;\n+\t\tstd::string name = streamInfo[stream];\n \n-\tif (writer)\n-\t\twriter->write(buffer, \"stream0\");\n+\t\tinfo << \" \" << name\n+\t\t     << \" (\" << buffer->index() << \")\"\n+\t\t     << \" seq: \" << std::setw(6) << std::setfill('0') << buffer->sequence()\n+\t\t     << \" bytesused: \" << buffer->bytesused();\n+\n+\t\tif (writer)\n+\t\t\twriter->write(buffer, name);\n+\t}\n+\n+\tstd::cout << info.str() << std::endl;\n \n \trequest = camera->createRequest();\n \tif (!request) {\n","prefixes":["libcamera-devel","v4","4/5"]}