Patch Detail
Show a patch.
GET /api/1.1/patches/3253/?format=api
{ "id": 3253, "url": "https://patchwork.libcamera.org/api/1.1/patches/3253/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3253/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200323142205.28342-11-laurent.pinchart@ideasonboard.com>", "date": "2020-03-23T14:21:54", "name": "[libcamera-devel,10/21] qcam: main_window: Document functions and reorganize member data", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "08e26595d943c1bfba298ce41705393fd249aced", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3253/mbox/", "series": [ { "id": 760, "url": "https://patchwork.libcamera.org/api/1.1/series/760/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=760", "date": "2020-03-23T14:21:44", "name": "qcam: Bypass format conversion when not required", "version": 1, "mbox": "https://patchwork.libcamera.org/series/760/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3253/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3253/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@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 C18B062C22\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 15:22:21 +0100 (CET)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 63651308\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 15:22:21 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584973341;\n\tbh=mdukGe9jiXqn/6rO4HZjMRjti0q8kRW7aHP1MeueCPQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=T9XABiXCUdB44Ru4mNg8JBfF057TO2VIphwsj9aRfs8YLBMic4JNuutappZHa7f9a\n\tzezc9KmU+2uMRzChrbJw24ALUI40amaLGwsZD0CUlezhz2qYDWERC+fsHLtP51datz\n\tOiXeup6KNxDVqdkLgouc3aMurxHUBhazcKnLi68A=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 23 Mar 2020 16:21:54 +0200", "Message-Id": "<20200323142205.28342-11-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>", "References": "<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 10/21] qcam: main_window: Document\n\tfunctions and reorganize member data", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "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, 23 Mar 2020 14:22:25 -0000" }, "content": "The qcam application is our reference implementation of a libcamera GUI\napplication. Document the code of the MainWindow class to make it easier\nto follow, and reorganize the member data in logical groups for clarity.\nNo code change.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/main_window.cpp | 69 +++++++++++++++++++++++++++++++++++++++-\n src/qcam/main_window.h | 24 ++++++++------\n 2 files changed, 82 insertions(+), 11 deletions(-)", "diff": "diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 7aaa73e9a709..21a8fcfe711d 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -32,6 +32,9 @@\n \n using namespace libcamera;\n \n+/**\n+ * \\brief Custom QEvent to signal capture completion\n+ */\n class CaptureEvent : public QEvent\n {\n public:\n@@ -52,6 +55,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n {\n \tint ret;\n \n+\t/*\n+\t * Initialize the UI: Create the toolbar, set the window title and\n+\t * create the viewfinder widget.\n+\t */\n \tcreateToolbars();\n \n \ttitle_ = \"QCam \" + QString::fromStdString(CameraManager::version());\n@@ -62,6 +69,7 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)\n \tsetCentralWidget(viewfinder_);\n \tadjustSize();\n \n+\t/* Open the camera and start capture. */\n \tret = openCamera();\n \tif (ret < 0)\n \t\tquit();\n@@ -97,13 +105,14 @@ int MainWindow::createToolbars()\n \t/* Disable right click context menu. */\n \ttoolbar_->setContextMenuPolicy(Qt::PreventContextMenu);\n \n+\t/* Quit action. */\n \taction = toolbar_->addAction(QIcon::fromTheme(\"application-exit\",\n \t\t\t\t\t\t QIcon(\":x-circle.svg\")),\n \t\t\t\t \"Quit\");\n \taction->setShortcut(Qt::CTRL | Qt::Key_Q);\n \tconnect(action, &QAction::triggered, this, &MainWindow::quit);\n \n-\t/* Camera selection. */\n+\t/* Camera selector. */\n \tQComboBox *cameraCombo = new QComboBox();\n \tconnect(cameraCombo, QOverload<int>::of(&QComboBox::activated),\n \t\tthis, &MainWindow::switchCamera);\n@@ -115,6 +124,7 @@ int MainWindow::createToolbars()\n \n \ttoolbar_->addSeparator();\n \n+\t/* Start/Stop action. */\n \taction = toolbar_->addAction(QIcon::fromTheme(\"media-playback-start\",\n \t\t\t\t\t\t QIcon(\":play-circle.svg\")),\n \t\t\t\t \"Start Capture\");\n@@ -123,6 +133,7 @@ int MainWindow::createToolbars()\n \tconnect(action, &QAction::toggled, this, &MainWindow::toggleCapture);\n \tstartStopAction_ = action;\n \n+\t/* Save As... action. */\n \taction = toolbar_->addAction(QIcon::fromTheme(\"document-save-as\",\n \t\t\t\t\t\t QIcon(\":save.svg\")),\n \t\t\t\t \"Save As...\");\n@@ -140,6 +151,7 @@ void MainWindow::quit()\n \n void MainWindow::updateTitle()\n {\n+\t/* Calculate the average frame rate over the last period. */\n \tunsigned int duration = frameRateInterval_.elapsed();\n \tunsigned int frames = framesCaptured_ - previousFrames_;\n \tdouble fps = frames * 1000.0 / duration;\n@@ -151,8 +163,13 @@ void MainWindow::updateTitle()\n \tsetWindowTitle(title_ + \" : \" + QString::number(fps, 'f', 2) + \" fps\");\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Camera Selection\n+ */\n+\n void MainWindow::switchCamera(int index)\n {\n+\t/* Get and acquire the new camera. */\n \tconst auto &cameras = cm_->cameras();\n \tif (static_cast<unsigned int>(index) >= cameras.size())\n \t\treturn;\n@@ -166,6 +183,10 @@ void MainWindow::switchCamera(int index)\n \n \tstd::cout << \"Switching to camera \" << cam->name() << std::endl;\n \n+\t/*\n+\t * Stop the capture session, release the current camera, replace it with\n+\t * the new camera and start a new capture session.\n+\t */\n \tstartStopAction_->setChecked(false);\n \n \tcamera_->release();\n@@ -179,9 +200,11 @@ std::string MainWindow::chooseCamera()\n \tQStringList cameras;\n \tbool result;\n \n+\t/* If only one camera is available, use it automatically. */\n \tif (cm_->cameras().size() == 1)\n \t\treturn cm_->cameras()[0]->name();\n \n+\t/* Present a dialog box to pick a camera. */\n \tfor (const std::shared_ptr<Camera> &cam : cm_->cameras())\n \t\tcameras.append(QString::fromStdString(cam->name()));\n \n@@ -198,6 +221,10 @@ int MainWindow::openCamera()\n {\n \tstd::string cameraName;\n \n+\t/*\n+\t * Use the camera specified on the command line, if any, or display the\n+\t * camera selection dialog box otherwise.\n+\t */\n \tif (options_.isSet(OptCamera))\n \t\tcameraName = static_cast<std::string>(options_[OptCamera]);\n \telse\n@@ -206,6 +233,7 @@ int MainWindow::openCamera()\n \tif (cameraName == \"\")\n \t\treturn -EINVAL;\n \n+\t/* Get and acquire the camera. */\n \tcamera_ = cm_->get(cameraName);\n \tif (!camera_) {\n \t\tstd::cout << \"Camera \" << cameraName << \" not found\"\n@@ -224,6 +252,10 @@ int MainWindow::openCamera()\n \treturn 0;\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Capture Start & Stop\n+ */\n+\n void MainWindow::toggleCapture(bool start)\n {\n \tif (start) {\n@@ -235,10 +267,16 @@ void MainWindow::toggleCapture(bool start)\n \t}\n }\n \n+/**\n+ * \\brief Start capture with the current camera\n+ *\n+ * This function shall not be called directly, use toggleCapture() instead.\n+ */\n int MainWindow::startCapture()\n {\n \tint ret;\n \n+\t/* Configure the camera. */\n \tconfig_ = camera_->generateConfiguration({ StreamRole::Viewfinder });\n \n \tStreamConfiguration &cfg = config_->at(0);\n@@ -275,6 +313,7 @@ int MainWindow::startCapture()\n \t\treturn ret;\n \t}\n \n+\t/* Configure the viewfinder. */\n \tStream *stream = cfg.stream();\n \tret = viewfinder_->setFormat(cfg.pixelFormat,\n \t\t\t\t QSize(cfg.size.width, cfg.size.height));\n@@ -285,6 +324,7 @@ int MainWindow::startCapture()\n \n \tadjustSize();\n \n+\t/* Allocate buffers and requests. */\n \tallocator_ = new FrameBufferAllocator(camera_);\n \tret = allocator_->allocate(stream);\n \tif (ret < 0) {\n@@ -317,6 +357,7 @@ int MainWindow::startCapture()\n \t\t\tstd::make_pair(memory, plane.length);\n \t}\n \n+\t/* Start the title timer and the camera. */\n \ttitleTimer_.start(2000);\n \tframeRateInterval_.start();\n \tpreviousFrames_ = 0;\n@@ -331,6 +372,7 @@ int MainWindow::startCapture()\n \n \tcamera_->requestCompleted.connect(this, &MainWindow::requestComplete);\n \n+\t/* Queue all requests. */\n \tfor (Request *request : requests) {\n \t\tret = camera_->queueRequest(request);\n \t\tif (ret < 0) {\n@@ -364,6 +406,12 @@ error:\n \treturn ret;\n }\n \n+/**\n+ * \\brief Stop ongoing capture\n+ *\n+ * This function may be called directly when tearing down the MainWindow. Use\n+ * toggleCapture() instead in all other cases.\n+ */\n void MainWindow::stopCapture()\n {\n \tif (!isCapturing_)\n@@ -399,6 +447,10 @@ void MainWindow::stopCapture()\n \tsetWindowTitle(title_);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Image Save\n+ */\n+\n void MainWindow::saveImageAs()\n {\n \tQImage image = viewfinder_->getCurrentImage();\n@@ -414,11 +466,20 @@ void MainWindow::saveImageAs()\n \twriter.write(image);\n }\n \n+/* -----------------------------------------------------------------------------\n+ * Request Completion Handling\n+ */\n+\n void MainWindow::requestComplete(Request *request)\n {\n \tif (request->status() == Request::RequestCancelled)\n \t\treturn;\n \n+\t/*\n+\t * We're running in the libcamera thread context, expensive operations\n+\t * are not allowed. Add the buffer to the done queue and post a\n+\t * CaptureEvent for the application thread to handle.\n+\t */\n \tconst std::map<Stream *, FrameBuffer *> &buffers = request->buffers();\n \tFrameBuffer *buffer = buffers.begin()->second;\n \n@@ -432,6 +493,11 @@ void MainWindow::requestComplete(Request *request)\n \n void MainWindow::processCapture()\n {\n+\t/*\n+\t * Retrieve the next buffer from the done queue. The queue may be empty\n+\t * if stopCapture() has been called while a CaptureEvent was posted but\n+\t * not processed yet. Return immediately in that case.\n+\t */\n \tFrameBuffer *buffer;\n \t{\n \t\tQMutexLocker locker(&mutex_);\n@@ -455,6 +521,7 @@ void MainWindow::processCapture()\n \t\t << \" fps: \" << std::fixed << std::setprecision(2) << fps\n \t\t << std::endl;\n \n+\t/* Display the buffer and requeue it to the camera. */\n \tdisplay(buffer);\n \n \tqueueRequest(buffer);\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 3d8d02b44696..fcde88c14f77 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -56,6 +56,7 @@ private Q_SLOTS:\n \n private:\n \tint createToolbars();\n+\n \tstd::string chooseCamera();\n \tint openCamera();\n \n@@ -67,31 +68,34 @@ private:\n \tint display(FrameBuffer *buffer);\n \tvoid queueRequest(FrameBuffer *buffer);\n \n+\t/* UI elements */\n+\tQToolBar *toolbar_;\n+\tQAction *startStopAction_;\n+\tViewFinder *viewfinder_;\n+\n \tQString title_;\n \tQTimer titleTimer_;\n \n+\t/* Options */\n \tconst OptionsParser::Options &options_;\n \n+\t/* Camera manager, camera, configuration and buffers */\n \tCameraManager *cm_;\n \tstd::shared_ptr<Camera> camera_;\n \tFrameBufferAllocator *allocator_;\n \n-\tbool isCapturing_;\n \tstd::unique_ptr<CameraConfiguration> config_;\n+\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n \n-\tuint64_t lastBufferTime_;\n+\t/* Capture state, buffers queue and statistics */\n+\tbool isCapturing_;\n+\tQQueue<FrameBuffer *> doneQueue_;\n+\tQMutex mutex_;\t/* Protects doneQueue_ */\n \n+\tuint64_t lastBufferTime_;\n \tQElapsedTimer frameRateInterval_;\n \tuint32_t previousFrames_;\n \tuint32_t framesCaptured_;\n-\n-\tQMutex mutex_;\n-\tQQueue<FrameBuffer *> doneQueue_;\n-\n-\tQToolBar *toolbar_;\n-\tQAction *startStopAction_;\n-\tViewFinder *viewfinder_;\n-\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n };\n \n #endif /* __QCAM_MAIN_WINDOW__ */\n", "prefixes": [ "libcamera-devel", "10/21" ] }