From 28fc8d17246886fcbbce1deaf5b07c0330601948 Mon Sep 17 00:00:00 2001 From: am0ebe <am0ebe@gmx.de> Date: Fri, 26 Jul 2024 16:03:08 +0200 Subject: [PATCH] save timestamp as ms (not ns), format time: only show h/m when dur long enough, _rec->showProgress() to add to camInfo, solved nasty auto keyword segfault bug, make progressbar smaller [40 digits] --- src/cam.cpp | 6 +----- src/core.cpp | 5 +---- src/frameprocessor.cpp | 14 ++------------ src/frameprocessor.h | 1 - src/iprinter.cpp | 18 +++++++++++++----- src/iprinter.h | 4 ++-- src/record.cpp | 38 +++++++++++++++----------------------- src/record.h | 3 ++- 8 files changed, 36 insertions(+), 53 deletions(-) diff --git a/src/cam.cpp b/src/cam.cpp index 515244b..3b20bce 100644 --- a/src/cam.cpp +++ b/src/cam.cpp @@ -206,15 +206,11 @@ QString Cam::camInfo() { QString camInfo = _name + DELIM + _ip + DELIM; - if( state() == Cam::disconnected ) return camInfo + "disconnected"; - try { - // camInfo += name() + DELIM; - // camInfo += ip() + DELIM; camInfo += id() + DELIM; std::string str; @@ -229,7 +225,7 @@ QString Cam::camInfo() camInfo += stateToString(_state) + DELIM; if( _state == recording) - _rec->showProgress(); //xxx string to add to camInfo + camInfo += _rec->getProgressBar() + DELIM; else camInfo += "recdur: " + formatTime( _rec->dur().count() * 1000 ) + DELIM; diff --git a/src/core.cpp b/src/core.cpp index ca0ae5d..12fe47b 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -204,12 +204,9 @@ void Core::showInfo() { print(QString("checkDirExists: %1").arg(cam()->rec()->checkDirExists())); showRecordingStats(); - // cam()->rec()->showStats(); } - //listCams - //showStats //checkDiskSpace (show progressbar) - // calcDirSize, checkDirExists, + //calcDirSize } diff --git a/src/frameprocessor.cpp b/src/frameprocessor.cpp index 7a7e1ed..db7d39c 100644 --- a/src/frameprocessor.cpp +++ b/src/frameprocessor.cpp @@ -47,6 +47,7 @@ void FrameProcessor::run() unsigned char* pdata = nullptr; _pframe->GetBuffer(pdata); _pframe->GetTimestamp(_timestamp); + _timestamp /= 1e6; //from ns to ms _pframe->GetWidth(_width); _pframe->GetHeight(_height); _pframe->GetPixelFormat(_pixelFormat); @@ -63,23 +64,12 @@ void FrameProcessor::run() qWarning() << "⚠️ Could not write frame to file: " << filename; - // auto dur_ms = static_cast<int>(_timestamp - _prev_timestamp) / 1e6; //from ns to ms - // qDebug() << "rcvd Frame #" << _count << ": dur in ms" << dur_ms << ", timestamp: " << _timestamp; - - - // qDebug() << "rcvd Frame #" << _count << ": " << _width << "x" << _height << "px, format: " << _pixelFormatStr << ", timestamp: " << _timestamp << ", file: " << filename; -// #ifdef DEBUG -// QThread::msleep(2000); //simulate processing time // testing -// #endif - _width = 0; _height = 0; _timestamp = 0; - _prev_timestamp = _timestamp; emit frameProcessed(_pframe); - //need to reset pframe? - // _pframe = FramePtr(nullptr); + // _pframe = FramePtr(nullptr); //need to reset pframe? } diff --git a/src/frameprocessor.h b/src/frameprocessor.h index cba0656..0278aa0 100644 --- a/src/frameprocessor.h +++ b/src/frameprocessor.h @@ -32,7 +32,6 @@ private: VmbUint32_t _width; VmbUint32_t _height; VmbUint64_t _timestamp; - VmbUint64_t _prev_timestamp; VmbPixelFormatType _pixelFormat; }; diff --git a/src/iprinter.cpp b/src/iprinter.cpp index afad9dc..ecdac25 100644 --- a/src/iprinter.cpp +++ b/src/iprinter.cpp @@ -119,11 +119,13 @@ QString IPrinter::progressBar(QTimer* timer, int width) int total_ms = timer->interval(); int remaining_ms = timer->remainingTime(); auto elapsed_ms = total_ms - remaining_ms; - int progressInPercent = (double) elapsed_ms / total_ms; + int progressInPercent = ((double) elapsed_ms / (double)total_ms) * 100; + //print in minutes and secs - auto s1 = QString(QString::number(progressInPercent) + "% | " + formatTime(elapsed_ms) + " < " + formatTime(remaining_ms)); - auto s2 = QString(progressBar(progressInPercent,width)); - return s1 + s2; + QString s1 = QString( formatTime(elapsed_ms) + " < " + formatTime(remaining_ms)); + QString s2 = QString::number(progressInPercent) + "% " + progressBar(progressInPercent,width); // auto keyword leads to segfault here... + // qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << s2; + return s1 + " " + s2; } QString IPrinter::progressBar(int percentage, int width) @@ -155,5 +157,11 @@ QString IPrinter::formatTime(const int& milliseconds) int hours = total_seconds / 3600; int minutes = (total_seconds % 3600) / 60; int seconds = total_seconds % 60; - return QString::asprintf("%02dh:%02dm:%02ds", hours, minutes, seconds); + + if( hours == 0 && minutes == 0 ) + return QString::asprintf("%02ds", seconds); + else if( hours == 0 ) + return QString::asprintf("%02dm:%02ds", minutes, seconds); + else + return QString::asprintf("%02dh:%02dm:%02ds", hours, minutes, seconds); } diff --git a/src/iprinter.h b/src/iprinter.h index 8e8ad29..a2732d7 100644 --- a/src/iprinter.h +++ b/src/iprinter.h @@ -40,8 +40,8 @@ public: void print(const char*, const seconds&); - QString progressBar(QTimer*, int width=0); - QString progressBar(int, int width=0); + QString progressBar(QTimer*, int width=40); + QString progressBar(int, int width=40); protected: QString formatTime(const int&); diff --git a/src/record.cpp b/src/record.cpp index b6a3107..0263d46 100644 --- a/src/record.cpp +++ b/src/record.cpp @@ -1,4 +1,5 @@ #include "record.h" +#include "opencv2/highgui.hpp" #include "qjsonvalue.h" #include "utils.h" #include "cam.h" @@ -27,7 +28,7 @@ _frames(FramePtrVector(utils::threadsPerCam())) _updateTimer->setInterval(duration_cast<milliseconds>(updateInterval)); - connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showProgress())); + connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showProgressBar())); } void Record::init(CamPtr cam) @@ -117,18 +118,9 @@ void Record::start() void Record::stop() { _updateTimer->stop(); + showProgressBar(); if(_timer->isActive()) - { - //user stop or error - info( progressBar(_timer) ); - _timer->stop(); - } - else - { - //normal stop - info( progressBar(100) ); - } - + _timer->stop(); //user stop or error try { @@ -160,13 +152,11 @@ void Record::showStats() info("get cam features:"); _cam->printCamFeatures({ "AcquisitionFrameRate", - "AcquisitionFrameCount", - "DeviceTemperature", - "SensorWidth", - "SensorHeight", "ExposureTime", "Gain", - "FileSize", + "SensorWidth", + "SensorHeight", + "DeviceTemperature", "PayloadSize", "PixelFormat", "PixelSize", @@ -175,8 +165,8 @@ void Record::showStats() info("-------------------------------"); info("get stream stats:"); _cam->printStreamFeatures({ + "StatFrameRate", "StatFrameDropped", - "StatLocalRate", "StatFrameRescued", "StatFrameShoved", "StatFrameUnderrun", @@ -190,12 +180,14 @@ void Record::showStats() }); } -void Record::showProgress() +void Record::showProgressBar() +{ + info( progressBar(_timer) ); // +} + +QString Record::getProgressBar() { - //TODO test - //fps? - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; - info( progressBar(_timer) ); + return progressBar(_timer); } void Record::checkDiskSpace(const QString &dir, seconds dur) diff --git a/src/record.h b/src/record.h index 66bcac6..dae9848 100644 --- a/src/record.h +++ b/src/record.h @@ -35,7 +35,8 @@ public: public slots: void stop(); void showStats(); - void showProgress(); + void showProgressBar(); + QString getProgressBar(); private: -- GitLab