5#include <QtCore/QDateTime>
8#include <QtCore/QFileInfo>
9#include <QtCore/QStandardPaths>
10#include <QtCore/QStringList>
20 constexpr qsizetype kMaxTagLength = (255 - 24) / 4;
23 for (
const QChar c : tag.left(kMaxTagLength)) {
24 safe.append((c.isLetterOrNumber() || (c == u
'-') || (c == u
'_')) ? c : u
'_');
26 return safe.isEmpty() ? QStringLiteral(
"graph") : safe;
32 constexpr int kMaxDotFiles = 10;
34 if (!pipeline || directory.isEmpty()) {
37 const QDir dir(directory);
40 QFileInfoList existing =
41 dir.entryInfoList(QStringList{QStringLiteral(
"*.dot")}, QDir::Files, QDir::Time | QDir::Reversed);
42 while (existing.size() >= kMaxDotFiles) {
43 QFile::remove(existing.takeFirst().absoluteFilePath());
51 const QString fullPath = dir.absoluteFilePath(
52 QStringLiteral(
"%1-%2.dot")
53 .arg(
dotFileTag(tag), QDateTime::currentDateTimeUtc().toString(QStringLiteral(
"yyyyMMdd-HHmmss-zzz"))));
56 fullPath, QByteArray::fromRawData(data.get(),
static_cast<qsizetype
>(qstrlen(data.get()))));
57 return wrote ? fullPath : QString{};
62 _pipelineName = receiverName.isEmpty() ? QByteArrayLiteral(
"receiver")
63 : (QStringLiteral(
"receiver-") +
dotFileTag(receiverName)).toUtf8();
70 [[maybe_unused]]
static const bool dotDirHinted =
72 if (qEnvironmentVariableIsEmpty(
"GST_DEBUG_DUMP_DOT_DIR")) {
73 qCDebug(GstVideoReceiverLog)
74 <<
"Pipeline dot-graph dumps are disabled. Set GST_DEBUG_DUMP_DOT_DIR=/path/to/dir to enable.";
82 const QByteArray fileName = _pipelineName +
'-' + tag;
92 dump(pipeline, safeTag.toUtf8().constData());
95 if (!qEnvironmentVariableIsEmpty(
"GST_DEBUG_DUMP_DOT_DIR")) {
98 const QString cacheRoot = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
99 if (cacheRoot.isEmpty()) {
102 const QString dotPath =
writePipelineDot(pipeline, QString::fromUtf8(_pipelineName) + u
'-' + safeTag,
103 cacheRoot + QStringLiteral(
"/qgc-pipeline-dot"));
104 if (!dotPath.isEmpty()) {
105 qCDebug(GstVideoReceiverLog) <<
"Pipeline graph saved to" << dotPath;
struct _GstElement GstElement
static QString dotFileTag(QStringView tag)
static QString writePipelineDot(GstElement *pipeline, QStringView tag, const QString &directory)
static constexpr GstDebugGraphDetails kDiagnosticDotGraphDetails
Every pipeline graph QGC writes omits element properties, because source properties can contain crede...
void snapshot(GstElement *pipeline, const QString &tag) const
void dump(GstElement *pipeline, const char *tag) const
Into GST_DEBUG_DUMP_DOT_DIR as "<pipeline name>-<tag>.dot", when that is set. No-op without a pipelin...
void setReceiverName(const QString &receiverName)
GCharPtr adoptGChar(gchar *str) noexcept
std::unique_ptr< gchar, GFreeDeleter > GCharPtr
bool atomicWrite(const QString &filePath, const QByteArray &data)