mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 05:23:12 -07:00
Refactor StreamSessionConnectInfo
This commit is contained in:
parent
686ef011f8
commit
8d8b756df4
4 changed files with 26 additions and 21 deletions
|
@ -46,8 +46,8 @@ struct StreamSessionConnectInfo
|
||||||
uint32_t log_level_mask;
|
uint32_t log_level_mask;
|
||||||
QString log_file;
|
QString log_file;
|
||||||
QString host;
|
QString host;
|
||||||
QString regist_key;
|
QByteArray regist_key;
|
||||||
QString morning;
|
QByteArray morning;
|
||||||
ChiakiConnectVideoProfile video_profile;
|
ChiakiConnectVideoProfile video_profile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,23 @@ int main(int argc, char *argv[])
|
||||||
connect_info.log_file = CreateLogFilename();
|
connect_info.log_file = CreateLogFilename();
|
||||||
|
|
||||||
connect_info.host = host;
|
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,
|
connect_info.regist_key = parser.value(regist_key_option).toUtf8();
|
||||||
CHIAKI_VIDEO_RESOLUTION_PRESET_720p,
|
if(connect_info.regist_key.length() > sizeof(ChiakiConnectInfo::regist_key))
|
||||||
CHIAKI_VIDEO_FPS_PRESET_30);
|
{
|
||||||
|
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())
|
if(connect_info.regist_key.isEmpty() || connect_info.morning.isEmpty())
|
||||||
parser.showHelp(1);
|
parser.showHelp(1);
|
||||||
|
@ -142,9 +153,7 @@ int RunMain(QApplication &app, Settings *settings)
|
||||||
int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info)
|
int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info)
|
||||||
{
|
{
|
||||||
StreamWindow window(connect_info);
|
StreamWindow window(connect_info);
|
||||||
window.resize(connect_info.video_profile.width, connect_info.video_profile.height);
|
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
app.setQuitOnLastWindowClosed(true);
|
app.setQuitOnLastWindowClosed(true);
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,23 +50,17 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
||||||
chiaki_connect_info.host = host_str.constData();
|
chiaki_connect_info.host = host_str.constData();
|
||||||
chiaki_connect_info.video_profile = connect_info.video_profile;
|
chiaki_connect_info.video_profile = connect_info.video_profile;
|
||||||
|
|
||||||
QByteArray auth_str = connect_info.regist_key.toUtf8();
|
if(connect_info.regist_key.size() != sizeof(chiaki_connect_info.regist_key))
|
||||||
size_t auth_len = auth_str.length();
|
throw ChiakiException("RegistKey invalid");
|
||||||
if(auth_len > sizeof(chiaki_connect_info.regist_key))
|
memcpy(chiaki_connect_info.regist_key, connect_info.regist_key.constData(), 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);
|
|
||||||
|
|
||||||
size_t morning_size = sizeof(chiaki_connect_info.morning);
|
if(connect_info.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))
|
|
||||||
throw ChiakiException("Morning invalid");
|
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));
|
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)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
throw ChiakiException("Chiaki Session Init failed: " + QString::fromLocal8Bit(chiaki_error_string(err)));
|
throw ChiakiException("Chiaki Session Init failed: " + QString::fromLocal8Bit(chiaki_error_string(err)));
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget
|
||||||
grabKeyboard();
|
grabKeyboard();
|
||||||
|
|
||||||
session->Start();
|
session->Start();
|
||||||
|
|
||||||
|
resize(connect_info.video_profile.width, connect_info.video_profile.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamWindow::~StreamWindow()
|
StreamWindow::~StreamWindow()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue