Skip to content

Commit 326d124

Browse files
committed
onvif: Make CI happy
- Re-flow settings.cpp / ptz-onvif.cpp / onvif-discovery.cpp through clang-format and CMakeLists.txt through gersemi to match the project's formatting rules. - Add `override` to every PTZOnvif override (description, set_config, get_config, get_obs_properties, do_update, pantilt_rel/abs/home, zoom_abs, set_autofocus, memory_set/recall/reset). Apple Clang treats -Winconsistent-missing-override as an error and the previous partial annotations failed the macOS build. - Replace the (QDate, QTime, Qt::TimeSpec) QDateTime constructor with setTimeZone(QTimeZone::utc()). The 3-arg form was deprecated in Qt 6.5 and MSVC's /WX in the Windows job turns the deprecation warning into a hard error. No behavior change. Signed-off-by: Jonatã Bolzan Loss <jonata@jonata.org>
1 parent a995cec commit 326d124

5 files changed

Lines changed: 54 additions & 55 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ if(ENABLE_ONVIF)
127127
add_compile_definitions(ENABLE_ONVIF)
128128
target_sources(
129129
${CMAKE_PROJECT_NAME}
130-
PRIVATE
131-
src/ptz-onvif.cpp
132-
src/ptz-onvif.hpp
133-
src/onvif-discovery.cpp
134-
src/onvif-discovery.hpp
130+
PRIVATE src/ptz-onvif.cpp src/ptz-onvif.hpp src/onvif-discovery.cpp src/onvif-discovery.hpp
135131
)
136132
endif()
137133

src/onvif-discovery.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <QSplitter>
3232
#include <QTableWidget>
3333
#include <QTableWidgetItem>
34+
#include <QTimeZone>
3435
#include <QtXml/QDomDocument>
3536
#include <QUrl>
3637
#include <QUuid>
@@ -49,8 +50,7 @@ static constexpr quint16 WSD_PORT = 3702;
4950
* — none of our authored payloads contain bare ampersands. */
5051
static QByteArray sanitizeXmlAmpersands(const QByteArray &xml)
5152
{
52-
static const QRegularExpression re(QStringLiteral(
53-
"&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)"));
53+
static const QRegularExpression re(QStringLiteral("&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)"));
5454
QString s = QString::fromUtf8(xml);
5555
s.replace(re, "&amp;");
5656
return s.toUtf8();
@@ -94,8 +94,7 @@ void OnvifDiscovery::start(int timeoutMs)
9494
* unicast responses sent back to our source port. ShareAddress lets
9595
* multiple processes on the host discover concurrently. */
9696
if (m_socket.state() != QAbstractSocket::BoundState) {
97-
if (!m_socket.bind(QHostAddress::AnyIPv4, 0,
98-
QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
97+
if (!m_socket.bind(QHostAddress::AnyIPv4, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
9998
emit errorOccurred(m_socket.errorString());
10099
m_running = false;
101100
emit finished();
@@ -208,8 +207,8 @@ void OnvifDiscovery::parseProbeMatch(const QByteArray &payload, const QHostAddre
208207
* even when reached via NAT or a different subnet), keep
209208
* the first XAddr's path but rewrite its host to the
210209
* responder. ODM and most other ONVIF clients do this. */
211-
QStringList urls = xaddrs.at(0).toElement().text().split(QRegularExpression("\\s+"),
212-
Qt::SkipEmptyParts);
210+
QStringList urls =
211+
xaddrs.at(0).toElement().text().split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
213212
QString chosen;
214213
for (const auto &u : urls) {
215214
QUrl url(u);
@@ -235,13 +234,13 @@ void OnvifDiscovery::parseProbeMatch(const QByteArray &payload, const QHostAddre
235234

236235
auto typesEl = m.elementsByTagNameNS(nsDisco, "Types");
237236
if (typesEl.length() > 0)
238-
info.types = typesEl.at(0).toElement().text().split(QRegularExpression("\\s+"),
239-
Qt::SkipEmptyParts);
237+
info.types =
238+
typesEl.at(0).toElement().text().split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
240239

241240
auto scopesEl = m.elementsByTagNameNS(nsDisco, "Scopes");
242241
if (scopesEl.length() > 0)
243-
info.scopes = scopesEl.at(0).toElement().text().split(QRegularExpression("\\s+"),
244-
Qt::SkipEmptyParts);
242+
info.scopes =
243+
scopesEl.at(0).toElement().text().split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
245244

246245
/* Extract manufacturer / model / name / location from scopes.
247246
* Scopes look like onvif://www.onvif.org/hardware/MODEL or
@@ -299,8 +298,8 @@ QString envelope(const QString &security, const QString &action, const QString &
299298
"</s:Header>"
300299
"<s:Body>%10</s:Body>"
301300
"</s:Envelope>")
302-
.arg(kNsSoap, kNsAddrSoap, kNsWsse, kNsWsu, kNsOnvifDevice, kNsOnvifMedia,
303-
kNsOnvifSchema, action, security, body);
301+
.arg(kNsSoap, kNsAddrSoap, kNsWsse, kNsWsu, kNsOnvifDevice, kNsOnvifMedia, kNsOnvifSchema, action,
302+
security, body);
304303
}
305304
} // namespace
306305

@@ -392,8 +391,8 @@ void OnvifMediaProbe::requestSystemDateAndTime()
392391
{
393392
/* Unauthenticated per spec; gives us the camera's clock for the rest
394393
* of the probe's WS-Security timestamps. */
395-
sendRequest(m_deviceXAddr, kNsOnvifDevice + "/GetSystemDateAndTime",
396-
"<tds:GetSystemDateAndTime/>", /*authenticated=*/false);
394+
sendRequest(m_deviceXAddr, kNsOnvifDevice + "/GetSystemDateAndTime", "<tds:GetSystemDateAndTime/>",
395+
/*authenticated=*/false);
397396
}
398397

399398
void OnvifMediaProbe::requestCapabilities()
@@ -415,14 +414,13 @@ void OnvifMediaProbe::requestNextStreamUri()
415414
return;
416415
}
417416
const QString token = m_profileTokens.at(m_profileIdx);
418-
const QString body = QStringLiteral(
419-
"<trt:GetStreamUri>"
420-
"<trt:StreamSetup>"
421-
"<tt:Stream>RTP-Unicast</tt:Stream>"
422-
"<tt:Transport><tt:Protocol>RTSP</tt:Protocol></tt:Transport>"
423-
"</trt:StreamSetup>"
424-
"<trt:ProfileToken>%1</trt:ProfileToken>"
425-
"</trt:GetStreamUri>")
417+
const QString body = QStringLiteral("<trt:GetStreamUri>"
418+
"<trt:StreamSetup>"
419+
"<tt:Stream>RTP-Unicast</tt:Stream>"
420+
"<tt:Transport><tt:Protocol>RTSP</tt:Protocol></tt:Transport>"
421+
"</trt:StreamSetup>"
422+
"<trt:ProfileToken>%1</trt:ProfileToken>"
423+
"</trt:GetStreamUri>")
426424
.arg(token);
427425
sendRequest(m_mediaXAddr, kNsOnvifMedia + "/GetStreamUri", body, /*authenticated=*/true);
428426
}
@@ -512,7 +510,11 @@ void OnvifMediaProbe::onReplyFinished(QNetworkReply *reply)
512510
int h = timeEl.firstChildElement("Hour", kNsOnvifSchema).text().toInt();
513511
int mi = timeEl.firstChildElement("Minute", kNsOnvifSchema).text().toInt();
514512
int se = timeEl.firstChildElement("Second", kNsOnvifSchema).text().toInt();
515-
QDateTime cameraTime(QDate(y, mo, d), QTime(h, mi, se), Qt::UTC);
513+
/* See PTZOnvif::handleGetSystemDateAndTimeResponse — the
514+
* (date, time, Qt::TimeSpec) constructor is deprecated
515+
* in Qt 6.5. */
516+
QDateTime cameraTime(QDate(y, mo, d), QTime(h, mi, se));
517+
cameraTime.setTimeZone(QTimeZone::utc());
516518
if (cameraTime.isValid())
517519
m_timeOffsetSecs = QDateTime::currentDateTimeUtc().secsTo(cameraTime);
518520
}

src/ptz-onvif.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QtXml/QDomDocument>
1515
#include <QXmlStreamWriter>
1616
#include <QRegularExpression>
17+
#include <QTimeZone>
1718

1819
void PTZOnvif::sendRequest(QString url, QString req)
1920
{
@@ -332,8 +333,7 @@ void PTZOnvif::handleResponse(QString response)
332333
* GetStreamUri responses with `&channel=`/`&protocol=`). That's
333334
* invalid XML and Qt's QDomDocument rejects the whole document.
334335
* Replace any bare '&' not starting a known entity with '&amp;'. */
335-
static const QRegularExpression ampFix(QStringLiteral(
336-
"&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)"));
336+
static const QRegularExpression ampFix(QStringLiteral("&(?!(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)"));
337337
response.replace(ampFix, "&amp;");
338338

339339
QDomDocument doc;
@@ -394,7 +394,12 @@ void PTZOnvif::handleGetSystemDateAndTimeResponse(QDomNode node)
394394
int h = timeEl.firstChildElement("Hour", nsOnvifSchema).text().toInt();
395395
int mi = timeEl.firstChildElement("Minute", nsOnvifSchema).text().toInt();
396396
int se = timeEl.firstChildElement("Second", nsOnvifSchema).text().toInt();
397-
QDateTime cameraTime(QDate(y, mo, d), QTime(h, mi, se), Qt::UTC);
397+
/* Construct as local-naive then re-anchor to UTC. The
398+
* (QDate, QTime, Qt::TimeSpec) constructor was deprecated in
399+
* Qt 6.5 (MSVC -Werror flags it); setTimeZone(QTimeZone::utc())
400+
* does the same thing and is portable back to Qt 5.2. */
401+
QDateTime cameraTime(QDate(y, mo, d), QTime(h, mi, se));
402+
cameraTime.setTimeZone(QTimeZone::utc());
398403
if (cameraTime.isValid()) {
399404
m_timeOffsetSecs = QDateTime::currentDateTimeUtc().secsTo(cameraTime);
400405
if (m_timeOffsetSecs > 60 || m_timeOffsetSecs < -60)
@@ -707,8 +712,7 @@ void PTZOnvif::requestFinished(QNetworkReply *reply)
707712
if (reply->error() > 0) {
708713
QByteArray body = reply->readAll();
709714
ptz_info("request to %s failed; error: %s, http: %i, body(<=200): %.200s", QT_TO_UTF8(url),
710-
QT_TO_UTF8(reply->errorString()), statusCodeV,
711-
QT_TO_UTF8(QString::fromUtf8(body).left(200)));
715+
QT_TO_UTF8(reply->errorString()), statusCodeV, QT_TO_UTF8(QString::fromUtf8(body).left(200)));
712716
++m_consecutiveFailures;
713717
if (m_consecutiveFailures >= 3 && isConnected())
714718
setConnected(false);
@@ -866,8 +870,8 @@ obs_properties_t *PTZOnvif::get_obs_properties()
866870
obs_properties_add_float_slider(config, "speed_boost", obs_module_text("PTZ.ONVIF.SpeedBoost"), 0.1, 10.0,
867871
0.01);
868872
obs_property_t *prof = obs_properties_add_list(config, "profile_token",
869-
obs_module_text("PTZ.ONVIF.MediaProfile"),
870-
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
873+
obs_module_text("PTZ.ONVIF.MediaProfile"), OBS_COMBO_TYPE_LIST,
874+
OBS_COMBO_FORMAT_STRING);
871875
if (m_mediaProfiles.isEmpty()) {
872876
obs_property_list_add_string(prof, obs_module_text("PTZ.ONVIF.NoProfilesYet"), "");
873877
obs_property_set_enabled(prof, false);

src/ptz-onvif.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,22 @@ private slots:
114114

115115
public:
116116
PTZOnvif(OBSData config);
117-
virtual QString description();
117+
QString description() override;
118118

119-
void set_config(OBSData ptz_data);
120-
OBSData get_config();
119+
void set_config(OBSData ptz_data) override;
120+
OBSData get_config() override;
121121

122-
obs_properties_t *get_obs_properties();
122+
obs_properties_t *get_obs_properties() override;
123123

124-
void do_update();
125-
void pantilt_rel(double pan, double tilt);
126-
void pantilt_abs(double pan, double tilt);
127-
void pantilt_home();
124+
void do_update() override;
125+
void pantilt_rel(double pan, double tilt) override;
126+
void pantilt_abs(double pan, double tilt) override;
127+
void pantilt_home() override;
128128
void pantilt_set_home() override;
129129
bool supportsSetHome() const override { return true; }
130-
void zoom_abs(double pos);
131-
void set_autofocus(bool enabled);
132-
void memory_reset(int i);
133-
void memory_set(int i);
134-
void memory_recall(int i);
130+
void zoom_abs(double pos) override;
131+
void set_autofocus(bool enabled) override;
132+
void memory_reset(int i) override;
133+
void memory_set(int i) override;
134+
void memory_recall(int i) override;
135135
};

src/settings.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,7 @@ void PTZSettings::on_addPTZ_clicked()
442442
if (!p.isEmpty())
443443
url.setPassword(p);
444444
}
445-
QString sourceName = cam.name.isEmpty()
446-
? QString("ONVIF %1").arg(cam.host)
447-
: cam.name;
445+
QString sourceName = cam.name.isEmpty() ? QString("ONVIF %1").arg(cam.host) : cam.name;
448446
OBSData settings = obs_data_create();
449447
obs_data_release(settings);
450448
obs_data_set_string(settings, "input", QT_TO_UTF8(url.toString()));
@@ -456,12 +454,11 @@ void PTZSettings::on_addPTZ_clicked()
456454
* default is UDP. */
457455
obs_data_set_string(settings, "input_format", "");
458456

459-
OBSSourceAutoRelease source = obs_source_create(
460-
"ffmpeg_source", QT_TO_UTF8(sourceName), settings, nullptr);
457+
OBSSourceAutoRelease source =
458+
obs_source_create("ffmpeg_source", QT_TO_UTF8(sourceName), settings, nullptr);
461459
if (source) {
462460
OBSSourceAutoRelease sceneSrc = obs_frontend_get_current_scene();
463-
obs_scene_t *scene = sceneSrc ? obs_scene_from_source(sceneSrc)
464-
: nullptr;
461+
obs_scene_t *scene = sceneSrc ? obs_scene_from_source(sceneSrc) : nullptr;
465462
if (scene)
466463
obs_scene_add(scene, source);
467464
}

0 commit comments

Comments
 (0)