From 8d8b756df40d1728f02a7f4813d5d795e7a3c209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 16 Aug 2019 18:14:15 +0200 Subject: [PATCH] Refactor StreamSessionConnectInfo --- gui/include/streamsession.h | 4 ++-- gui/src/main.cpp | 23 ++++++++++++++++------- gui/src/streamsession.cpp | 18 ++++++------------ gui/src/streamwindow.cpp | 2 ++ 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/gui/include/streamsession.h b/gui/include/streamsession.h index bd8bdc3..ac5bd35 100644 --- a/gui/include/streamsession.h +++ b/gui/include/streamsession.h @@ -46,8 +46,8 @@ struct StreamSessionConnectInfo uint32_t log_level_mask; QString log_file; QString host; - QString regist_key; - QString morning; + QByteArray regist_key; + QByteArray morning; ChiakiConnectVideoProfile video_profile; }; diff --git a/gui/src/main.cpp b/gui/src/main.cpp index dd5fd83..826531c 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -95,12 +95,23 @@ int main(int argc, char *argv[]) connect_info.log_file = CreateLogFilename(); connect_info.host = host; - connect_info.regist_key = parser.value(regist_key_option); - connect_info.morning = parser.value(morning_option); - chiaki_connect_video_profile_preset(&connect_info.video_profile, - CHIAKI_VIDEO_RESOLUTION_PRESET_720p, - CHIAKI_VIDEO_FPS_PRESET_30); + 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"); + return 1; + } + connect_info.regist_key += QByteArray(sizeof(ChiakiConnectInfo::regist_key) - connect_info.regist_key.length(), 0); + + connect_info.morning = QByteArray::fromBase64(parser.value(morning_option).toUtf8()); + if(connect_info.morning.length() != sizeof(ChiakiConnectInfo::morning)) + { + printf("Given morning has invalid size (expected %llu)", (unsigned long long)sizeof(ChiakiConnectInfo::morning)); + return 1; + } + + chiaki_connect_video_profile_preset(&connect_info.video_profile, settings.GetResolution(), settings.GetFPS()); if(connect_info.regist_key.isEmpty() || connect_info.morning.isEmpty()) parser.showHelp(1); @@ -142,9 +153,7 @@ int RunMain(QApplication &app, Settings *settings) int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info) { StreamWindow window(connect_info); - window.resize(connect_info.video_profile.width, connect_info.video_profile.height); window.show(); - app.setQuitOnLastWindowClosed(true); return app.exec(); } diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index 451eb15..d6c64bd 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -50,23 +50,17 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje chiaki_connect_info.host = host_str.constData(); chiaki_connect_info.video_profile = connect_info.video_profile; - QByteArray auth_str = connect_info.regist_key.toUtf8(); - size_t auth_len = auth_str.length(); - if(auth_len > sizeof(chiaki_connect_info.regist_key)) - auth_len = sizeof(chiaki_connect_info.regist_key); - memcpy(chiaki_connect_info.regist_key, auth_str.constData(), auth_len); - if(auth_len < sizeof(chiaki_connect_info.regist_key)) - memset(chiaki_connect_info.regist_key + auth_len, 0, sizeof(chiaki_connect_info.regist_key) - auth_len); + if(connect_info.regist_key.size() != sizeof(chiaki_connect_info.regist_key)) + throw ChiakiException("RegistKey invalid"); + memcpy(chiaki_connect_info.regist_key, connect_info.regist_key.constData(), sizeof(chiaki_connect_info.regist_key)); - size_t morning_size = sizeof(chiaki_connect_info.morning); - QByteArray morning_str = connect_info.morning.toUtf8(); - ChiakiErrorCode err = chiaki_base64_decode(morning_str.constData(), morning_str.length(), chiaki_connect_info.morning, &morning_size); - if(err != CHIAKI_ERR_SUCCESS || morning_size != sizeof(chiaki_connect_info.morning)) + if(connect_info.morning.size() != sizeof(chiaki_connect_info.morning)) throw ChiakiException("Morning invalid"); + memcpy(chiaki_connect_info.morning, connect_info.morning.constData(), sizeof(chiaki_connect_info.morning)); memset(&keyboard_state, 0, sizeof(keyboard_state)); - err = chiaki_session_init(&session, &chiaki_connect_info, log.GetChiakiLog()); + ChiakiErrorCode err = chiaki_session_init(&session, &chiaki_connect_info, log.GetChiakiLog()); if(err != CHIAKI_ERR_SUCCESS) throw ChiakiException("Chiaki Session Init failed: " + QString::fromLocal8Bit(chiaki_error_string(err))); diff --git a/gui/src/streamwindow.cpp b/gui/src/streamwindow.cpp index f51f576..2d440b6 100644 --- a/gui/src/streamwindow.cpp +++ b/gui/src/streamwindow.cpp @@ -35,6 +35,8 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget grabKeyboard(); session->Start(); + + resize(connect_info.video_profile.width, connect_info.video_profile.height); } StreamWindow::~StreamWindow()