diff --git a/Hyperion_Grabber_Wayland_QT b/Hyperion_Grabber_Wayland_QT index 9b42533..7255a21 100755 Binary files a/Hyperion_Grabber_Wayland_QT and b/Hyperion_Grabber_Wayland_QT differ diff --git a/Hyperion_Grabber_Wayland_QT_autogen/deps b/Hyperion_Grabber_Wayland_QT_autogen/deps index 4a723e4..8be77f2 100644 --- a/Hyperion_Grabber_Wayland_QT_autogen/deps +++ b/Hyperion_Grabber_Wayland_QT_autogen/deps @@ -277,6 +277,7 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/pthread.h \ /usr/include/qt6/QtCore/QByteArray \ /usr/include/qt6/QtCore/QEvent \ + /usr/include/qt6/QtCore/QJsonObject \ /usr/include/qt6/QtCore/QList \ /usr/include/qt6/QtCore/QMargins \ /usr/include/qt6/QtCore/QObject \ @@ -308,6 +309,9 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/qt6/QtCore/qbytearrayalgorithms.h \ /usr/include/qt6/QtCore/qbytearraylist.h \ /usr/include/qt6/QtCore/qbytearrayview.h \ + /usr/include/qt6/QtCore/qcalendar.h \ + /usr/include/qt6/QtCore/qcborcommon.h \ + /usr/include/qt6/QtCore/qcborvalue.h \ /usr/include/qt6/QtCore/qchar.h \ /usr/include/qt6/QtCore/qcompare.h \ /usr/include/qt6/QtCore/qcompare_impl.h \ @@ -324,9 +328,11 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/qt6/QtCore/qcoreevent.h \ /usr/include/qt6/QtCore/qdarwinhelpers.h \ /usr/include/qt6/QtCore/qdatastream.h \ + /usr/include/qt6/QtCore/qdatetime.h \ /usr/include/qt6/QtCore/qdeadlinetimer.h \ /usr/include/qt6/QtCore/qdebug.h \ /usr/include/qt6/QtCore/qelapsedtimer.h \ + /usr/include/qt6/QtCore/qendian.h \ /usr/include/qt6/QtCore/qeventloop.h \ /usr/include/qt6/QtCore/qexceptionhandling.h \ /usr/include/qt6/QtCore/qflags.h \ @@ -343,6 +349,10 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/qt6/QtCore/qiodevicebase.h \ /usr/include/qt6/QtCore/qiterable.h \ /usr/include/qt6/QtCore/qiterator.h \ + /usr/include/qt6/QtCore/qjsondocument.h \ + /usr/include/qt6/QtCore/qjsonobject.h \ + /usr/include/qt6/QtCore/qjsonparseerror.h \ + /usr/include/qt6/QtCore/qjsonvalue.h \ /usr/include/qt6/QtCore/qlatin1stringview.h \ /usr/include/qt6/QtCore/qline.h \ /usr/include/qt6/QtCore/qlist.h \ @@ -368,6 +378,7 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/qt6/QtCore/qprocessordetection.h \ /usr/include/qt6/QtCore/qrect.h \ /usr/include/qt6/QtCore/qrefcount.h \ + /usr/include/qt6/QtCore/qregularexpression.h \ /usr/include/qt6/QtCore/qscopedpointer.h \ /usr/include/qt6/QtCore/qscopeguard.h \ /usr/include/qt6/QtCore/qset.h \ @@ -415,7 +426,9 @@ Hyperion_Grabber_Wayland_QT_autogen/timestamp: \ /usr/include/qt6/QtCore/qtversionchecks.h \ /usr/include/qt6/QtCore/qtypeinfo.h \ /usr/include/qt6/QtCore/qtypes.h \ + /usr/include/qt6/QtCore/qurl.h \ /usr/include/qt6/QtCore/qutf8stringview.h \ + /usr/include/qt6/QtCore/quuid.h \ /usr/include/qt6/QtCore/qvariant.h \ /usr/include/qt6/QtCore/qvarlengtharray.h \ /usr/include/qt6/QtCore/qversiontagging.h \ diff --git a/hyperion-mock.cpp b/hyperion-mock.cpp index 37ae0a4..a24b5c3 100644 --- a/hyperion-mock.cpp +++ b/hyperion-mock.cpp @@ -26,29 +26,61 @@ private slots: void handleConnection() { QTcpSocket *socket = _server->nextPendingConnection(); - connect(socket, &QTcpSocket::readyRead, this, [socket]() { - QByteArray data = socket->readAll(); - QJsonDocument doc = QJsonDocument::fromJson(data); - if (doc.isObject()) { - QJsonObject obj = doc.object(); - if (obj.contains("command") && obj["command"].toString() == "image") { - if (obj.contains("imagedata")) { - QByteArray imageData = QByteArray::fromBase64(obj["imagedata"].toString().toUtf8()); - QImage image; - image.loadFromData(imageData, "PNG"); - if (!image.isNull()) { - QString filename = QString("received_frame_%1.png").arg(QDateTime::currentMSecsSinceEpoch()); - image.save(filename); - qDebug() << "Received and saved image:" << filename; + QByteArray *buffer = new QByteArray(); + + connect(socket, &QTcpSocket::readyRead, this, [this, socket, buffer]() { + buffer->append(socket->readAll()); + + int newlineIndex; + while ((newlineIndex = buffer->indexOf('\n')) != -1) { + // Extract the message including the newline + QByteArray jsonData = buffer->left(newlineIndex + 1); + buffer->remove(0, newlineIndex + 1); + + QJsonDocument doc = QJsonDocument::fromJson(jsonData.trimmed()); + if (doc.isObject()) { + QJsonObject obj = doc.object(); + if (obj.contains("command") && obj["command"].toString() == "image") { + QJsonObject params = obj["params"].toObject(); + int width = params["imagewidth"].toInt(); + int height = params["imageheight"].toInt(); + QByteArray imageData = QByteArray::fromBase64(params["imagedata"].toString().toUtf8()); + + if (width > 0 && height > 0 && !imageData.isEmpty()) { + QImage image(reinterpret_cast(imageData.constData()), width, height, QImage::Format_RGB888); + if (!image.isNull()) { + QString filename = QString("received_frame_%1.png").arg(QUuid::createUuid().toString()); + image.save(filename); + qDebug() << "Received and saved image:" << filename; + + // Send success reply + QJsonObject reply; + reply["success"] = true; + reply["command"] = "image"; + QByteArray replyData = QJsonDocument(reply).toJson(QJsonDocument::Compact); + replyData.append('\n'); + socket->write(replyData); + + } else { + qWarning() << "Failed to create QImage from raw data."; + } } else { - qWarning() << "Failed to decode image data."; + qWarning() << "Invalid image dimensions or empty image data received."; } } + } else { + qWarning() << "Failed to parse JSON object:" << jsonData.trimmed(); } } }); + + connect(socket, &QTcpSocket::disconnected, this, [socket, buffer]() { + socket->deleteLater(); + delete buffer; + }); } + private: QTcpServer *_server; }; diff --git a/lessons_learned.md b/lessons_learned.md index bc960bd..1c7b149 100644 --- a/lessons_learned.md +++ b/lessons_learned.md @@ -94,7 +94,7 @@ This document summarizes the key challenges, debugging steps, and solutions enco * **D-Bus `SelectSources` Signature Mismatch:** * **Problem:** `wayland_poc` was failing with "Type of message, “(oosa{sv})”, does not match expected type “(a{sv})”" when calling `SelectSources`. This occurred because the `handleSelectSourcesResponse` function, designed for `SelectSources` replies, was incorrectly connected to the `CreateSession` D-Bus call's `finished` signal. The `CreateSession` reply's signature (starting with an object path) was being misinterpreted, leading to an incorrect `SelectSources` call. * **Diagnosis:** The `QObject::connect` in `main` was incorrectly routing the `CreateSession` reply to the `handleSelectSourcesResponse` function. - * **Fix:** + * **Fix:** 1. Created a new handler function, `handleCreateSessionFinished`, to specifically process the `CreateSession` reply. This function extracts the session handle and then correctly initiates the `SelectSources` D-Bus call with its own `QDBusPendingCallWatcher` connected to `handleSelectSourcesResponse`. 2. Modified the `main` function to connect the `CreateSession`'s `QDBusPendingCallWatcher` to `handleCreateSessionFinished`. @@ -174,3 +174,13 @@ This document summarizes the key challenges, debugging steps, and solutions enco * Corrected a syntax error in the `setImgSize` function's string literal (related to escaped quotes) that was causing compilation failures. * Corrected `QImage::byteCount()` to `QImage::sizeInBytes()` for accurate raw data size calculation. * **Outcome:** The grabber now sends image data with dynamically updated dimensions in the JSON header, which should resolve the data acknowledgment issue with Hyperion. + +## 15. Mock Server Debugging and Protocol Discovery + +* **Initial State:** The `hyperion-mock` server was not processing image data, saving no PNGs and logging no errors. +* **Incorrect Assumption (Aha! Moment #1):** My initial diagnosis was based on a faulty memory that the Hyperion protocol was binary and used a 4-byte length prefix for messages. I proposed a "fix" for the mock server based on this incorrect assumption. +* **Investigation:** The user correctly prompted me to read the actual `hyperion.ng` source code to build a realistic mock. +* **Protocol Discovery (Aha! Moment #2):** Reading `JsonClientConnection.cpp` from the `hyperion.ng` repo and re-reading our own `hyperionclient.cpp` revealed the actual protocol: simple **newline-delimited (`\n`) JSON messages**. +* **Mock Server Fix:** The mock server was corrected to use newline-delimited parsing. It was also fixed to correctly parse the raw image data (using `imagewidth` and `imageheight` from the JSON) and to send a `{"success":true}` reply, which the client expects. +* **File Location (Aha! Moment #3):** I repeatedly failed to find the generated PNG files because I was looking in the `build/` directory. The files were being created in the project's root directory, which was the *current working directory* of the mock server process when the user launched it. +* **Operational Improvement (Aha! Moment #4):** The user reminded me that I can use `ps aux | grep ` to find the PID of background processes myself, rather than asking them for it. This is a more autonomous and efficient workflow. \ No newline at end of file diff --git a/received_frame_1755202619439.png b/received_frame_1755202619439.png deleted file mode 100644 index ec8cfc2..0000000 Binary files a/received_frame_1755202619439.png and /dev/null differ diff --git a/received_frame_1755202619577.png b/received_frame_1755202619577.png deleted file mode 100644 index 4f144c2..0000000 Binary files a/received_frame_1755202619577.png and /dev/null differ diff --git a/received_frame_1755202619702.png b/received_frame_1755202619702.png deleted file mode 100644 index 5459585..0000000 Binary files a/received_frame_1755202619702.png and /dev/null differ diff --git a/received_frame_1755202619765.png b/received_frame_1755202619765.png deleted file mode 100644 index 9a4235b..0000000 Binary files a/received_frame_1755202619765.png and /dev/null differ diff --git a/received_frame_1755202619793.png b/received_frame_1755202619793.png deleted file mode 100644 index fa73825..0000000 Binary files a/received_frame_1755202619793.png and /dev/null differ diff --git a/received_frame_1755202619821.png b/received_frame_1755202619821.png deleted file mode 100644 index 41a7b69..0000000 Binary files a/received_frame_1755202619821.png and /dev/null differ diff --git a/received_frame_1755202619954.png b/received_frame_1755202619954.png deleted file mode 100644 index ebc71b0..0000000 Binary files a/received_frame_1755202619954.png and /dev/null differ diff --git a/received_frame_1755202619982.png b/received_frame_1755202619982.png deleted file mode 100644 index 6eea4f5..0000000 Binary files a/received_frame_1755202619982.png and /dev/null differ diff --git a/received_frame_1755202620016.png b/received_frame_1755202620016.png deleted file mode 100644 index 7d35dbe..0000000 Binary files a/received_frame_1755202620016.png and /dev/null differ diff --git a/received_frame_1755202620079.png b/received_frame_1755202620079.png deleted file mode 100644 index 37a1858..0000000 Binary files a/received_frame_1755202620079.png and /dev/null differ diff --git a/received_frame_1755202620229.png b/received_frame_1755202620229.png deleted file mode 100644 index a5fe4bf..0000000 Binary files a/received_frame_1755202620229.png and /dev/null differ diff --git a/received_frame_1755202620286.png b/received_frame_1755202620286.png deleted file mode 100644 index 5767cab..0000000 Binary files a/received_frame_1755202620286.png and /dev/null differ diff --git a/received_frame_1755202620349.png b/received_frame_1755202620349.png deleted file mode 100644 index a661d6d..0000000 Binary files a/received_frame_1755202620349.png and /dev/null differ diff --git a/received_frame_1755202620403.png b/received_frame_1755202620403.png deleted file mode 100644 index 9ffe205..0000000 Binary files a/received_frame_1755202620403.png and /dev/null differ diff --git a/received_frame_1755202620518.png b/received_frame_1755202620518.png deleted file mode 100644 index 07de2d2..0000000 Binary files a/received_frame_1755202620518.png and /dev/null differ diff --git a/received_frame_1755202620608.png b/received_frame_1755202620608.png deleted file mode 100644 index 0f591e9..0000000 Binary files a/received_frame_1755202620608.png and /dev/null differ diff --git a/received_frame_1755202620634.png b/received_frame_1755202620634.png deleted file mode 100644 index 0f591e9..0000000 Binary files a/received_frame_1755202620634.png and /dev/null differ diff --git a/received_frame_1755202620663.png b/received_frame_1755202620663.png deleted file mode 100644 index 0f591e9..0000000 Binary files a/received_frame_1755202620663.png and /dev/null differ diff --git a/received_frame_1755202620691.png b/received_frame_1755202620691.png deleted file mode 100644 index 58b8ed7..0000000 Binary files a/received_frame_1755202620691.png and /dev/null differ diff --git a/received_frame_1755202620784.png b/received_frame_1755202620784.png deleted file mode 100644 index e7980c6..0000000 Binary files a/received_frame_1755202620784.png and /dev/null differ diff --git a/received_frame_1755202620852.png b/received_frame_1755202620852.png deleted file mode 100644 index cd0ea00..0000000 Binary files a/received_frame_1755202620852.png and /dev/null differ diff --git a/received_frame_1755202620910.png b/received_frame_1755202620910.png deleted file mode 100644 index 880f808..0000000 Binary files a/received_frame_1755202620910.png and /dev/null differ diff --git a/received_frame_1755202620939.png b/received_frame_1755202620939.png deleted file mode 100644 index ce06d66..0000000 Binary files a/received_frame_1755202620939.png and /dev/null differ diff --git a/received_frame_1755202620968.png b/received_frame_1755202620968.png deleted file mode 100644 index 0f6652b..0000000 Binary files a/received_frame_1755202620968.png and /dev/null differ diff --git a/received_frame_1755202621082.png b/received_frame_1755202621082.png deleted file mode 100644 index 169f210..0000000 Binary files a/received_frame_1755202621082.png and /dev/null differ diff --git a/received_frame_1755202621173.png b/received_frame_1755202621173.png deleted file mode 100644 index 561db64..0000000 Binary files a/received_frame_1755202621173.png and /dev/null differ diff --git a/received_frame_1755202621228.png b/received_frame_1755202621228.png deleted file mode 100644 index b3ca68f..0000000 Binary files a/received_frame_1755202621228.png and /dev/null differ diff --git a/received_frame_1755202621291.png b/received_frame_1755202621291.png deleted file mode 100644 index 12dd34c..0000000 Binary files a/received_frame_1755202621291.png and /dev/null differ diff --git a/received_frame_1755202621411.png b/received_frame_1755202621411.png deleted file mode 100644 index be2350c..0000000 Binary files a/received_frame_1755202621411.png and /dev/null differ diff --git a/received_frame_1755202621471.png b/received_frame_1755202621471.png deleted file mode 100644 index 587f83d..0000000 Binary files a/received_frame_1755202621471.png and /dev/null differ diff --git a/received_frame_1755202621530.png b/received_frame_1755202621530.png deleted file mode 100644 index 5c65da7..0000000 Binary files a/received_frame_1755202621530.png and /dev/null differ diff --git a/received_frame_1755202621647.png b/received_frame_1755202621647.png deleted file mode 100644 index 35c4c7f..0000000 Binary files a/received_frame_1755202621647.png and /dev/null differ diff --git a/received_frame_1755202621677.png b/received_frame_1755202621677.png deleted file mode 100644 index 061a40a..0000000 Binary files a/received_frame_1755202621677.png and /dev/null differ diff --git a/received_frame_1755202621711.png b/received_frame_1755202621711.png deleted file mode 100644 index e0ae73d..0000000 Binary files a/received_frame_1755202621711.png and /dev/null differ diff --git a/received_frame_1755202621739.png b/received_frame_1755202621739.png deleted file mode 100644 index 7dced88..0000000 Binary files a/received_frame_1755202621739.png and /dev/null differ diff --git a/received_frame_1755202696347.png b/received_frame_1755202696347.png deleted file mode 100644 index 58b7d73..0000000 Binary files a/received_frame_1755202696347.png and /dev/null differ diff --git a/received_frame_1755202696411.png b/received_frame_1755202696411.png deleted file mode 100644 index 11a3075..0000000 Binary files a/received_frame_1755202696411.png and /dev/null differ diff --git a/received_frame_1755202696465.png b/received_frame_1755202696465.png deleted file mode 100644 index 8dc0c65..0000000 Binary files a/received_frame_1755202696465.png and /dev/null differ diff --git a/received_frame_1755202696526.png b/received_frame_1755202696526.png deleted file mode 100644 index bfa513a..0000000 Binary files a/received_frame_1755202696526.png and /dev/null differ diff --git a/received_frame_1755202696555.png b/received_frame_1755202696555.png deleted file mode 100644 index 80586c4..0000000 Binary files a/received_frame_1755202696555.png and /dev/null differ diff --git a/received_frame_1755202696587.png b/received_frame_1755202696587.png deleted file mode 100644 index 0e70a0e..0000000 Binary files a/received_frame_1755202696587.png and /dev/null differ diff --git a/received_frame_1755202696648.png b/received_frame_1755202696648.png deleted file mode 100644 index 39702c0..0000000 Binary files a/received_frame_1755202696648.png and /dev/null differ diff --git a/received_frame_1755202696677.png b/received_frame_1755202696677.png deleted file mode 100644 index 5d9c3b4..0000000 Binary files a/received_frame_1755202696677.png and /dev/null differ diff --git a/received_frame_1755202696706.png b/received_frame_1755202696706.png deleted file mode 100644 index 1a3cb02..0000000 Binary files a/received_frame_1755202696706.png and /dev/null differ diff --git a/received_frame_1755202696766.png b/received_frame_1755202696766.png deleted file mode 100644 index d68f63c..0000000 Binary files a/received_frame_1755202696766.png and /dev/null differ diff --git a/received_frame_1755202696851.png b/received_frame_1755202696851.png deleted file mode 100644 index 84c44e9..0000000 Binary files a/received_frame_1755202696851.png and /dev/null differ diff --git a/received_frame_1755202696912.png b/received_frame_1755202696912.png deleted file mode 100644 index 5a2c399..0000000 Binary files a/received_frame_1755202696912.png and /dev/null differ diff --git a/received_frame_1755202696996.png b/received_frame_1755202696996.png deleted file mode 100644 index 2bc4edc..0000000 Binary files a/received_frame_1755202696996.png and /dev/null differ diff --git a/received_frame_1755202697083.png b/received_frame_1755202697083.png deleted file mode 100644 index bb129da..0000000 Binary files a/received_frame_1755202697083.png and /dev/null differ diff --git a/received_frame_1755202697203.png b/received_frame_1755202697203.png deleted file mode 100644 index 6d5225c..0000000 Binary files a/received_frame_1755202697203.png and /dev/null differ diff --git a/received_frame_1755202697294.png b/received_frame_1755202697294.png deleted file mode 100644 index 66e3619..0000000 Binary files a/received_frame_1755202697294.png and /dev/null differ