diff --git a/CHANGELOG.md b/CHANGELOG.md index 512f6196..4cd5d665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Standalone grabbers: Improved fps help/error text, fixed default address and port + ## Removed ## [2.0.12](https://github.com/hyperion-project/hyperion.ng/releases/tag/2.0.12) - 2021-11-20 diff --git a/include/commandline/DoubleOption.h b/include/commandline/DoubleOption.h index b7daa012..cb468e06 100644 --- a/include/commandline/DoubleOption.h +++ b/include/commandline/DoubleOption.h @@ -26,20 +26,28 @@ public: double minimum = -INFINITY, double maximum = INFINITY, int decimals = 1000) : ValidatorOption(names, description, valueName, defaultValue) { - setValidator(new QDoubleValidator(minimum, maximum, decimals)); + _minimum = minimum; + _maximum = maximum; + setValidator(new QDoubleValidator(_minimum, _maximum, decimals)); } DoubleOption(const QCommandLineOption &other, double minimum = -INFINITY, double maximum = INFINITY, int decimals = 1000) : ValidatorOption(other) { - setValidator(new QDoubleValidator(minimum, maximum, decimals)); + _minimum = minimum; + _maximum = maximum; + setValidator(new QDoubleValidator(_minimum, _maximum, decimals)); } double getDouble(Parser &parser, bool *ok = 0); double *getDoublePtr(Parser &parser, bool *ok = 0); + bool validate(Parser & parser, QString & value) override; + protected: double _double; + int _minimum; + int _maximum; }; } diff --git a/include/commandline/IntOption.h b/include/commandline/IntOption.h index 806bf0bb..faeb76a0 100644 --- a/include/commandline/IntOption.h +++ b/include/commandline/IntOption.h @@ -12,6 +12,8 @@ class IntOption: public ValidatorOption { protected: int _int; + int _minimum; + int _maximum; public: IntOption(const QString &name, @@ -31,18 +33,24 @@ public: int minimum = std::numeric_limits::min(), int maximum = std::numeric_limits::max()) : ValidatorOption(names, description, valueName, defaultValue) { - setValidator(new QIntValidator(minimum, maximum)); + _minimum = minimum; + _maximum = maximum; + setValidator(new QIntValidator(_minimum, _maximum)); } IntOption(const QCommandLineOption &other, int minimum = std::numeric_limits::min(), int maximum = std::numeric_limits::max()) : ValidatorOption(other) { - setValidator(new QIntValidator(minimum, maximum)); + _minimum = minimum; + _maximum = maximum; + setValidator(new QIntValidator(_minimum, _maximum)); } int getInt(Parser &parser, bool *ok = 0, int base = 10); int *getIntPtr(Parser &parser, bool *ok = 0, int base = 10); + + bool validate(Parser & parser, QString & value) override; }; } diff --git a/include/utils/NetUtils.h b/include/utils/NetUtils.h index 5756185e..73417f53 100644 --- a/include/utils/NetUtils.h +++ b/include/utils/NetUtils.h @@ -61,6 +61,11 @@ namespace NetUtils { /// inline bool resolveHostPort(const QString& address, QString& host, quint16& port) { + if (address.isEmpty()) + { + return false; + } + QString testUrl; if (address.at(0) != '[' && address.count(':') > 1) { @@ -87,10 +92,10 @@ namespace NetUtils { /// /// @brief Check if the port is in the valid range - /// @param log The logger of the caller to print - /// @param[in] address The port to be tested + /// @param log The logger of the caller to print + /// @param[in] address The port to be tested /// @param[out] hostAddress A hostname to make reference to during logging - /// @return True on success else false + /// @return True on success else false /// inline bool resolveHostAddress(Logger* log, const QString& address, QHostAddress& hostAddress) diff --git a/libsrc/commandline/DoubleOption.cpp b/libsrc/commandline/DoubleOption.cpp index 09f77248..7454b423 100644 --- a/libsrc/commandline/DoubleOption.cpp +++ b/libsrc/commandline/DoubleOption.cpp @@ -19,3 +19,15 @@ double *DoubleOption::getDoublePtr(Parser &parser, bool *ok) return nullptr; } + +bool DoubleOption::validate(Parser & parser, QString & value) +{ + if (ValidatorOption::validate(parser,value)) + { + return true; + } + + _error = QString("Value must be between %1 and %2.").arg(_minimum).arg(_maximum); + + return false; +} diff --git a/libsrc/commandline/IntOption.cpp b/libsrc/commandline/IntOption.cpp index 1bde9911..5de1f216 100644 --- a/libsrc/commandline/IntOption.cpp +++ b/libsrc/commandline/IntOption.cpp @@ -6,6 +6,7 @@ using namespace commandline; int IntOption::getInt(Parser &parser, bool *ok, int base) { _int = value(parser).toInt(ok, base); + return _int; } @@ -18,3 +19,15 @@ int *IntOption::getIntPtr(Parser &parser, bool *ok, int base) } return nullptr; } + +bool IntOption::validate(Parser & parser, QString & value) +{ + if (ValidatorOption::validate(parser,value)) + { + return true; + } + + _error = QString("Value must be between %1 and %2.").arg(_minimum).arg(_maximum); + + return false; +} diff --git a/libsrc/commandline/Parser.cpp b/libsrc/commandline/Parser.cpp index eb9da4bc..0bceb682 100644 --- a/libsrc/commandline/Parser.cpp +++ b/libsrc/commandline/Parser.cpp @@ -20,11 +20,11 @@ bool Parser::parse(const QStringList &arguments) if (!option->validate(*this, value)) { const QString error = option->getError(); if (!error.isEmpty()) { - _errorText = tr("%1 is not a valid option for %2\n%3").arg(value, option->name(), error); + _errorText = tr("\"%1\" is not a valid option for %2, %3").arg(value, option->name(), error); } else { - _errorText = tr("%1 is not a valid option for %2").arg(value, option->name()); + _errorText = tr("\"%1\" is not a valid option for %2").arg(value, option->name()); } return false; } @@ -37,7 +37,7 @@ void Parser::process(const QStringList &arguments) _parser.process(arguments); if (!parse(arguments)) { - fprintf(stdout, "%s", qPrintable(tr("Error: %1").arg(_errorText))); + fprintf(stdout, "%s\n\n", qPrintable(tr("Error: %1").arg(_errorText))); showHelp(EXIT_FAILURE); } } diff --git a/src/hyperion-aml/hyperion-aml.cpp b/src/hyperion-aml/hyperion-aml.cpp index bbdeffa4..4a678df8 100644 --- a/src/hyperion-aml/hyperion-aml.cpp +++ b/src/hyperion-aml/hyperion-aml.cpp @@ -44,7 +44,7 @@ int main(int argc, char ** argv) // create the option parser and initialize all parser Parser parser("AmLogic capture application for Hyperion. Will automatically search a Hyperion server if -a option isn't used. Please note that if you have more than one server running it's more or less random which one will be used."); - IntOption & argFps = parser.add ('f', "framerate", "Capture frame rate [default: %1]", QString::number(GrabberWrapper::DEFAULT_RATE_HZ), GrabberWrapper::DEFAULT_MIN_GRAB_RATE_HZ, GrabberWrapper::DEFAULT_MAX_GRAB_RATE_HZ); + IntOption & argFps = parser.add ('f', "framerate", "Capture frame rate. %1", QString("Range %1-%2fps, default: [%3]").arg(GrabberWrapper::DEFAULT_MIN_GRAB_RATE_HZ).arg(GrabberWrapper::DEFAULT_MAX_GRAB_RATE_HZ).arg(GrabberWrapper::DEFAULT_RATE_HZ), GrabberWrapper::DEFAULT_MIN_GRAB_RATE_HZ, GrabberWrapper::DEFAULT_MAX_GRAB_RATE_HZ); IntOption & argSizeDecimation = parser.add ('s', "size-decimator", "Decimation factor for the output image size [default=%1]", QString::number(GrabberWrapper::DEFAULT_PIXELDECIMATION), 1); IntOption & argCropLeft = parser.add (0x0, "crop-left", "Number of pixels to crop from the left of the picture before decimation"); @@ -54,7 +54,7 @@ int main(int argc, char ** argv) BooleanOption & arg3DSBS = parser.add(0x0, "3DSBS", "Interpret the incoming video stream as 3D side-by-side"); BooleanOption & arg3DTAB = parser.add(0x0, "3DTAB", "Interpret the incoming video stream as 3D top-and-bottom"); - Option & argAddress = parser.add