From bfc818ab459cd2a8d9a6d9c4a469b3b46c83bd83 Mon Sep 17 00:00:00 2001 From: Paulchen Panther Date: Wed, 27 Jan 2021 18:55:21 +0100 Subject: [PATCH] Improvements --- .gitignore | 3 ++ include/grabber/MFGrabber.h | 2 +- libsrc/grabber/mediafoundation/MFGrabber.cpp | 51 ++++++++++++------- .../mediafoundation/MFSourceReaderCB.h | 10 +++- libsrc/grabber/mediafoundation/MFThread.cpp | 5 +- libsrc/hyperion/Grabber.cpp | 3 +- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 0713ddb3..ea25d9d4 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ libsrc/flatbufserver/hyperion_request_generated.h # Visual Studio 2015/2017/2019 cache/options directory .vs/ CMakeSettings.json + +# LedDevice 'File' output +NULL diff --git a/include/grabber/MFGrabber.h b/include/grabber/MFGrabber.h index a8a4219e..31b89a31 100644 --- a/include/grabber/MFGrabber.h +++ b/include/grabber/MFGrabber.h @@ -102,7 +102,7 @@ private: void process_image(const void *frameImageBuffer, int size); void checkSignalDetectionEnabled(Image image); - QString _deviceName; + QString _currentDeviceName, _newDeviceName; QMap _deviceProperties; HRESULT _hr; SourceReaderCB* _sourceReaderCB; diff --git a/libsrc/grabber/mediafoundation/MFGrabber.cpp b/libsrc/grabber/mediafoundation/MFGrabber.cpp index 0e40a9ac..d0f0e7f0 100644 --- a/libsrc/grabber/mediafoundation/MFGrabber.cpp +++ b/libsrc/grabber/mediafoundation/MFGrabber.cpp @@ -6,7 +6,8 @@ namespace { const bool verbose = false; } MFGrabber::MFGrabber(const QString & device, unsigned width, unsigned height, unsigned fps, int pixelDecimation, QString flipMode) : Grabber("V4L2:"+device) - , _deviceName(device) + , _currentDeviceName(device) + , _newDeviceName(device) , _hr(S_FALSE) , _sourceReader(nullptr) , _pixelDecimation(pixelDecimation) @@ -59,14 +60,14 @@ bool MFGrabber::init() { QString foundDevice = ""; int foundIndex = -1, bestGuess = -1, bestGuessMinX = INT_MAX, bestGuessMinFPS = INT_MAX; - bool autoDiscovery = (QString::compare(_deviceName, "auto", Qt::CaseInsensitive) == 0 ); + bool autoDiscovery = (QString::compare(_currentDeviceName, "auto", Qt::CaseInsensitive) == 0 ); // enumerate the video capture devices on the user's system enumVideoCaptureDevices(); - if(!autoDiscovery && !_deviceProperties.contains(_deviceName)) + if(!autoDiscovery && !_deviceProperties.contains(_currentDeviceName)) { - Debug(_log, "Device '%s' is not available. Changing to auto.", QSTRING_CSTR(_deviceName)); + Debug(_log, "Device '%s' is not available. Changing to auto.", QSTRING_CSTR(_currentDeviceName)); autoDiscovery = true; } @@ -76,12 +77,12 @@ bool MFGrabber::init() if(_deviceProperties.count()>0) { foundDevice = _deviceProperties.firstKey(); - _deviceName = foundDevice; - Debug(_log, "Auto discovery set to %s", QSTRING_CSTR(_deviceName)); + _currentDeviceName = foundDevice; + Debug(_log, "Auto discovery set to %s", QSTRING_CSTR(_currentDeviceName)); } } else - foundDevice = _deviceName; + foundDevice = _currentDeviceName; if(foundDevice.isNull() || foundDevice.isEmpty() || !_deviceProperties.contains(foundDevice)) { @@ -132,7 +133,7 @@ bool MFGrabber::init() if(foundIndex < 0 && bestGuess >= 0) { - if(!autoDiscovery) + if(!autoDiscovery && _width != 0 && _height != 0) Warning(_log, "Selected resolution not found in supported modes. Forcing best resolution"); else Debug(_log, "Forcing best resolution"); @@ -157,7 +158,7 @@ void MFGrabber::uninit() // stop if the grabber was not stopped if(_initialized) { - Debug(_log,"uninit grabber: %s", QSTRING_CSTR(_deviceName)); + Debug(_log,"uninit grabber: %s", QSTRING_CSTR(_newDeviceName)); stop(); } } @@ -608,14 +609,17 @@ bool MFGrabber::start() { try { - _threadManager.start(); - DebugIf(verbose, _log, "Decoding threads: %d",_threadManager._maxThreads); - - if(init()) + if(!_initialized) { - start_capturing(); - Info(_log, "Started"); - return true; + _threadManager.start(); + DebugIf(verbose, _log, "Decoding threads: %d",_threadManager._maxThreads); + + if(init()) + { + start_capturing(); + Info(_log, "Started"); + return true; + } } } catch(std::exception& e) @@ -743,9 +747,9 @@ void MFGrabber::setCecDetectionEnable(bool enable) bool MFGrabber::setDevice(QString device) { - if(_deviceName != device) + if(_currentDeviceName != device) { - _deviceName = device; + _currentDeviceName = device; return true; } return false; @@ -767,9 +771,16 @@ bool MFGrabber::setWidthHeight(int width, int height) { if(Grabber::setWidthHeight(width, height)) { - Debug(_log,"Set width:height to: %i:%i", width, height); + Debug(_log,"Set device resolution to width: %i, height: %i", width, height); return true; } + else if(width == 0 && height == 0) + { + _width = _height = 0; + Debug(_log,"Set device resolution to 'Automatic'"); + return true; + } + return false; } @@ -827,6 +838,8 @@ void MFGrabber::reloadGrabber() uninit(); // restore pixelformat to configs value _pixelFormat = _pixelFormatConfig; + // set _newDeviceName + _newDeviceName = _currentDeviceName; // start grabber start(); } diff --git a/libsrc/grabber/mediafoundation/MFSourceReaderCB.h b/libsrc/grabber/mediafoundation/MFSourceReaderCB.h index 2b78832f..ca11a2e7 100644 --- a/libsrc/grabber/mediafoundation/MFSourceReaderCB.h +++ b/libsrc/grabber/mediafoundation/MFSourceReaderCB.h @@ -43,6 +43,8 @@ public: , _grabber(grabber) , _bEOS(FALSE) , _hrStatus(S_OK) + , _transform(nullptr) + , _pixelformat(PixelFormat::NO_CHANGE) { InitializeCriticalSection(&_critsec); } @@ -333,8 +335,12 @@ public: private: virtual ~SourceReaderCB() { - _transform->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, 0); - _transform->ProcessMessage(MFT_MESSAGE_NOTIFY_END_STREAMING, 0); + if (_transform) + { + _transform->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, 0); + _transform->ProcessMessage(MFT_MESSAGE_NOTIFY_END_STREAMING, 0); + } + SAFE_RELEASE(_transform); } diff --git a/libsrc/grabber/mediafoundation/MFThread.cpp b/libsrc/grabber/mediafoundation/MFThread.cpp index 5c8c7345..8f03d5af 100644 --- a/libsrc/grabber/mediafoundation/MFThread.cpp +++ b/libsrc/grabber/mediafoundation/MFThread.cpp @@ -24,10 +24,7 @@ MFThread::~MFThread() tjDestroy(_decompress); if (_localData) - { - free(_localData); - _localData = nullptr; - } + tjFree(_localData); } void MFThread::setup( diff --git a/libsrc/hyperion/Grabber.cpp b/libsrc/hyperion/Grabber.cpp index ba33e85f..285dab81 100644 --- a/libsrc/hyperion/Grabber.cpp +++ b/libsrc/hyperion/Grabber.cpp @@ -28,7 +28,7 @@ void Grabber::setEnabled(bool enable) void Grabber::setVideoMode(VideoMode mode) { - Debug(_log,"Set videomode to %d", mode); + Debug(_log,"Set videomode to %s", QSTRING_CSTR(videoMode2String(mode))); _videoMode = mode; if ( _useImageResampler ) { @@ -98,6 +98,7 @@ bool Grabber::setWidthHeight(int width, int height) Error(_log, "Rejecting invalid width/height values as it collides with image cropping: width: %d, height: %d", width, height); return false; } + Debug(_log, "Set new width: %d, height: %d for capture", width, height); _width = width; _height = height;