mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Add Verbose Logging Setting
This commit is contained in:
parent
8d8b756df4
commit
862c11bc8f
10 changed files with 93 additions and 23 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include <chiaki/log.h>
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDir>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
class QFile;
|
class QFile;
|
||||||
|
@ -45,6 +46,7 @@ class SessionLog
|
||||||
ChiakiLog *GetChiakiLog() { return &log; }
|
ChiakiLog *GetChiakiLog() { return &log; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QString GetLogBaseDir();
|
||||||
QString CreateLogFilename();
|
QString CreateLogFilename();
|
||||||
|
|
||||||
#endif //CHIAKI_SESSIONLOG_H
|
#endif //CHIAKI_SESSIONLOG_H
|
||||||
|
|
|
@ -39,9 +39,13 @@ class Settings : public QObject
|
||||||
public:
|
public:
|
||||||
explicit Settings(QObject *parent = nullptr);
|
explicit Settings(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool GetDiscoveryEnabled() { return settings.value("settings/auto_discovery", true).toBool(); }
|
bool GetDiscoveryEnabled() const { return settings.value("settings/auto_discovery", true).toBool(); }
|
||||||
void SetDiscoveryEnabled(bool enabled) { settings.setValue("settings/auto_discovery", enabled); }
|
void SetDiscoveryEnabled(bool enabled) { settings.setValue("settings/auto_discovery", enabled); }
|
||||||
|
|
||||||
|
bool GetLogVerbose() const { return settings.value("settings/log_verbose", false).toBool(); }
|
||||||
|
void SetLogVerbose(bool enabled) { settings.setValue("settings/log_verbose", enabled); }
|
||||||
|
uint32_t GetLogLevelMask();
|
||||||
|
|
||||||
ChiakiVideoResolutionPreset GetResolution() const;
|
ChiakiVideoResolutionPreset GetResolution() const;
|
||||||
void SetResolution(ChiakiVideoResolutionPreset resolution);
|
void SetResolution(ChiakiVideoResolutionPreset resolution);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
class Settings;
|
class Settings;
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
|
class QCheckBox;
|
||||||
|
|
||||||
class SettingsDialog : public QDialog
|
class SettingsDialog : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,8 @@ class SettingsDialog : public QDialog
|
||||||
private:
|
private:
|
||||||
Settings *settings;
|
Settings *settings;
|
||||||
|
|
||||||
|
QCheckBox *log_verbose_check_box;
|
||||||
|
|
||||||
QComboBox *resolution_combo_box;
|
QComboBox *resolution_combo_box;
|
||||||
QComboBox *fps_combo_box;
|
QComboBox *fps_combo_box;
|
||||||
|
|
||||||
|
@ -38,6 +41,8 @@ class SettingsDialog : public QDialog
|
||||||
QPushButton *delete_registered_host_button;
|
QPushButton *delete_registered_host_button;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void LogVerboseChanged();
|
||||||
|
|
||||||
void ResolutionSelected();
|
void ResolutionSelected();
|
||||||
void FPSSelected();
|
void FPSSelected();
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class QGamepad;
|
||||||
class QAudioOutput;
|
class QAudioOutput;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
|
class Settings;
|
||||||
|
|
||||||
class ChiakiException: public Exception
|
class ChiakiException: public Exception
|
||||||
{
|
{
|
||||||
|
@ -49,6 +50,9 @@ struct StreamSessionConnectInfo
|
||||||
QByteArray regist_key;
|
QByteArray regist_key;
|
||||||
QByteArray morning;
|
QByteArray morning;
|
||||||
ChiakiConnectVideoProfile video_profile;
|
ChiakiConnectVideoProfile video_profile;
|
||||||
|
|
||||||
|
StreamSessionConnectInfo();
|
||||||
|
StreamSessionConnectInfo(Settings *settings, QString host, QByteArray regist_key, QByteArray morning);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StreamSession : public QObject
|
class StreamSession : public QObject
|
||||||
|
|
|
@ -89,32 +89,25 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QString host = args[1];
|
QString host = args[1];
|
||||||
|
|
||||||
StreamSessionConnectInfo connect_info;
|
if(parser.value(regist_key_option).isEmpty() || parser.value(morning_option).isEmpty())
|
||||||
|
parser.showHelp(1);
|
||||||
|
|
||||||
connect_info.log_level_mask = CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE;
|
QByteArray regist_key = parser.value(regist_key_option).toUtf8();
|
||||||
connect_info.log_file = CreateLogFilename();
|
if(regist_key.length() > sizeof(ChiakiConnectInfo::regist_key))
|
||||||
|
|
||||||
connect_info.host = host;
|
|
||||||
|
|
||||||
connect_info.regist_key = parser.value(regist_key_option).toUtf8();
|
|
||||||
if(connect_info.regist_key.length() > sizeof(ChiakiConnectInfo::regist_key))
|
|
||||||
{
|
{
|
||||||
printf("Given regist key is too long.\n");
|
printf("Given regist key is too long.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
connect_info.regist_key += QByteArray(sizeof(ChiakiConnectInfo::regist_key) - connect_info.regist_key.length(), 0);
|
regist_key += QByteArray(sizeof(ChiakiConnectInfo::regist_key) - regist_key.length(), 0);
|
||||||
|
|
||||||
connect_info.morning = QByteArray::fromBase64(parser.value(morning_option).toUtf8());
|
QByteArray morning = QByteArray::fromBase64(parser.value(morning_option).toUtf8());
|
||||||
if(connect_info.morning.length() != sizeof(ChiakiConnectInfo::morning))
|
if(morning.length() != sizeof(ChiakiConnectInfo::morning))
|
||||||
{
|
{
|
||||||
printf("Given morning has invalid size (expected %llu)", (unsigned long long)sizeof(ChiakiConnectInfo::morning));
|
printf("Given morning has invalid size (expected %llu)", (unsigned long long)sizeof(ChiakiConnectInfo::morning));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
chiaki_connect_video_profile_preset(&connect_info.video_profile, settings.GetResolution(), settings.GetFPS());
|
StreamSessionConnectInfo connect_info(&settings, host, regist_key, morning);
|
||||||
|
|
||||||
if(connect_info.regist_key.isEmpty() || connect_info.morning.isEmpty())
|
|
||||||
parser.showHelp(1);
|
|
||||||
|
|
||||||
return RunStream(app, connect_info);
|
return RunStream(app, connect_info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,8 +124,7 @@ RegistExecuteDialog::RegistExecuteDialog(Settings *settings, const ChiakiRegistI
|
||||||
layout->addWidget(button_box);
|
layout->addWidget(button_box);
|
||||||
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
// TODO: respect verbose setting
|
chiaki_log_init(&log, settings->GetLogLevelMask(), RegistExecuteDialogLogCb, this);
|
||||||
chiaki_log_init(&log, CHIAKI_LOG_ALL/* & ~CHIAKI_LOG_VERBOSE*/, RegistExecuteDialogLogCb, this);
|
|
||||||
chiaki_regist_start(®ist, &log, ®ist_info, RegistExecuteDialogRegistCb, this);
|
chiaki_regist_start(®ist, &log, ®ist_info, RegistExecuteDialogRegistCb, this);
|
||||||
|
|
||||||
setWindowTitle(tr("Register Console"));
|
setWindowTitle(tr("Register Console"));
|
||||||
|
|
|
@ -90,12 +90,8 @@ static void LogCb(ChiakiLogLevel level, const char *msg, void *user)
|
||||||
|
|
||||||
#define KEEP_LOG_FILES_COUNT 5
|
#define KEEP_LOG_FILES_COUNT 5
|
||||||
|
|
||||||
QString CreateLogFilename()
|
QString GetLogBaseDir()
|
||||||
{
|
{
|
||||||
static const QString date_format = "yyyy-MM-dd_HH-mm-ss-zzzzzz";
|
|
||||||
static const QString session_log_wildcard = "chiaki_session_*.log";
|
|
||||||
static const QRegularExpression session_log_regex("chiaki_session_(.*).log");
|
|
||||||
|
|
||||||
auto base_dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
auto base_dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
if(base_dir.isEmpty())
|
if(base_dir.isEmpty())
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -106,6 +102,20 @@ QString CreateLogFilename()
|
||||||
if(!dir.cd("log"))
|
if(!dir.cd("log"))
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
|
return dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CreateLogFilename()
|
||||||
|
{
|
||||||
|
static const QString date_format = "yyyy-MM-dd_HH-mm-ss-zzzzzz";
|
||||||
|
static const QString session_log_wildcard = "chiaki_session_*.log";
|
||||||
|
static const QRegularExpression session_log_regex("chiaki_session_(.*).log");
|
||||||
|
|
||||||
|
QString dir_str = GetLogBaseDir();
|
||||||
|
if(dir_str.isEmpty())
|
||||||
|
return QString();
|
||||||
|
QDir dir = QDir(dir_str);
|
||||||
|
|
||||||
dir.setNameFilters({ session_log_wildcard });
|
dir.setNameFilters({ session_log_wildcard });
|
||||||
auto existing_files = dir.entryList();
|
auto existing_files = dir.entryList();
|
||||||
QVector<QPair<QString, QDateTime>> existing_files_date;
|
QVector<QPair<QString, QDateTime>> existing_files_date;
|
||||||
|
|
|
@ -25,6 +25,14 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
LoadRegisteredHosts();
|
LoadRegisteredHosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Settings::GetLogLevelMask()
|
||||||
|
{
|
||||||
|
uint32_t mask = CHIAKI_LOG_ALL;
|
||||||
|
if(!GetLogVerbose())
|
||||||
|
mask &= ~CHIAKI_LOG_VERBOSE;
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
static const QMap<ChiakiVideoResolutionPreset, QString> resolutions = {
|
static const QMap<ChiakiVideoResolutionPreset, QString> resolutions = {
|
||||||
{ CHIAKI_VIDEO_RESOLUTION_PRESET_360p, "360p"},
|
{ CHIAKI_VIDEO_RESOLUTION_PRESET_360p, "360p"},
|
||||||
{ CHIAKI_VIDEO_RESOLUTION_PRESET_540p, "540p"},
|
{ CHIAKI_VIDEO_RESOLUTION_PRESET_540p, "540p"},
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <settingsdialog.h>
|
#include <settingsdialog.h>
|
||||||
#include <settings.h>
|
#include <settings.h>
|
||||||
#include <registdialog.h>
|
#include <registdialog.h>
|
||||||
|
#include <sessionlog.h>
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
@ -28,6 +29,8 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(Settings *settings, QWidget *parent) : QDialog(parent)
|
SettingsDialog::SettingsDialog(Settings *settings, QWidget *parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +40,26 @@ SettingsDialog::SettingsDialog(Settings *settings, QWidget *parent) : QDialog(pa
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
|
||||||
|
// General
|
||||||
|
|
||||||
|
auto general_group_box = new QGroupBox(tr("General"));
|
||||||
|
layout->addWidget(general_group_box);
|
||||||
|
|
||||||
|
auto general_layout = new QFormLayout();
|
||||||
|
general_group_box->setLayout(general_layout);
|
||||||
|
if(general_layout->spacing() < 16)
|
||||||
|
general_layout->setSpacing(16);
|
||||||
|
|
||||||
|
log_verbose_check_box = new QCheckBox(this);
|
||||||
|
general_layout->addRow(tr("Verbose Logging:\nWarning: This logs A LOT!\nDon't enable for regular use."), log_verbose_check_box);
|
||||||
|
log_verbose_check_box->setChecked(settings->GetLogVerbose());
|
||||||
|
connect(log_verbose_check_box, &QCheckBox::stateChanged, this, &SettingsDialog::LogVerboseChanged);
|
||||||
|
|
||||||
|
auto log_directory_label = new QLineEdit(GetLogBaseDir(), this);
|
||||||
|
log_directory_label->setReadOnly(true);
|
||||||
|
general_layout->addRow(tr("Log Directory:"), log_directory_label);
|
||||||
|
|
||||||
|
|
||||||
// Stream Settings
|
// Stream Settings
|
||||||
|
|
||||||
auto stream_settings_group_box = new QGroupBox(tr("Stream Settings"));
|
auto stream_settings_group_box = new QGroupBox(tr("Stream Settings"));
|
||||||
|
@ -118,6 +141,11 @@ void SettingsDialog::ResolutionSelected()
|
||||||
settings->SetResolution((ChiakiVideoResolutionPreset)resolution_combo_box->currentData().toInt());
|
settings->SetResolution((ChiakiVideoResolutionPreset)resolution_combo_box->currentData().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::LogVerboseChanged()
|
||||||
|
{
|
||||||
|
settings->SetLogVerbose(log_verbose_check_box->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsDialog::FPSSelected()
|
void SettingsDialog::FPSSelected()
|
||||||
{
|
{
|
||||||
settings->SetFPS((ChiakiVideoFPSPreset)fps_combo_box->currentData().toInt());
|
settings->SetFPS((ChiakiVideoFPSPreset)fps_combo_box->currentData().toInt());
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <streamsession.h>
|
#include <streamsession.h>
|
||||||
|
#include <settings.h>
|
||||||
|
|
||||||
#include <chiaki/base64.h>
|
#include <chiaki/base64.h>
|
||||||
|
|
||||||
|
@ -29,6 +30,22 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
StreamSessionConnectInfo::StreamSessionConnectInfo()
|
||||||
|
{
|
||||||
|
log_level_mask = CHIAKI_LOG_ALL;
|
||||||
|
std::memset(&video_profile, 0, sizeof(video_profile));
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamSessionConnectInfo::StreamSessionConnectInfo(Settings *settings, QString host, QByteArray regist_key, QByteArray morning)
|
||||||
|
{
|
||||||
|
log_level_mask = settings->GetLogLevelMask();
|
||||||
|
log_file = CreateLogFilename();
|
||||||
|
chiaki_connect_video_profile_preset(&video_profile, settings->GetResolution(), settings->GetFPS());
|
||||||
|
this->host = host;
|
||||||
|
this->regist_key = regist_key;
|
||||||
|
this->morning = morning;
|
||||||
|
}
|
||||||
|
|
||||||
static void AudioSettingsCb(uint32_t channels, uint32_t rate, void *user);
|
static void AudioSettingsCb(uint32_t channels, uint32_t rate, void *user);
|
||||||
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
||||||
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue