mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Add ChiakiException
This commit is contained in:
parent
01111d62e4
commit
1a5654bd49
4 changed files with 40 additions and 12 deletions
|
@ -33,6 +33,16 @@ class QAudioOutput;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
|
|
||||||
|
class ChiakiException : public std::exception
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
QString msg;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ChiakiException(const QString &msg) : msg(msg) {}
|
||||||
|
const char *what() const noexcept override { return msg.toLocal8Bit().constData(); }
|
||||||
|
};
|
||||||
|
|
||||||
class StreamSession : public QObject
|
class StreamSession : public QObject
|
||||||
{
|
{
|
||||||
friend class StreamSessionPrivate;
|
friend class StreamSessionPrivate;
|
||||||
|
@ -60,6 +70,8 @@ class StreamSession : public QObject
|
||||||
explicit StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent = nullptr);
|
explicit StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent = nullptr);
|
||||||
~StreamSession();
|
~StreamSession();
|
||||||
|
|
||||||
|
void Stop();
|
||||||
|
|
||||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
QGamepad *GetGamepad() { return gamepad; }
|
QGamepad *GetGamepad() { return gamepad; }
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,20 +60,15 @@ StreamSession::StreamSession(const QString &host, const QString ®istkey, cons
|
||||||
QByteArray morning_str = morning.toUtf8();
|
QByteArray morning_str = morning.toUtf8();
|
||||||
ChiakiErrorCode err = chiaki_base64_decode(morning_str.constData(), morning_str.length(), connect_info.morning, &morning_size);
|
ChiakiErrorCode err = chiaki_base64_decode(morning_str.constData(), morning_str.length(), connect_info.morning, &morning_size);
|
||||||
if(err != CHIAKI_ERR_SUCCESS || morning_size != sizeof(connect_info.morning))
|
if(err != CHIAKI_ERR_SUCCESS || morning_size != sizeof(connect_info.morning))
|
||||||
{
|
throw ChiakiException("Morning invalid");
|
||||||
printf("morning invalid.\n");
|
|
||||||
throw std::exception(); // TODO: proper exception
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t did_size = sizeof(connect_info.did);
|
size_t did_size = sizeof(connect_info.did);
|
||||||
QByteArray did_str = did.toUtf8();
|
QByteArray did_str = did.toUtf8();
|
||||||
err = chiaki_base64_decode(did_str.constData(), did_str.length(), connect_info.did, &did_size);
|
err = chiaki_base64_decode(did_str.constData(), did_str.length(), connect_info.did, &did_size);
|
||||||
if(err != CHIAKI_ERR_SUCCESS || did_size != sizeof(connect_info.did))
|
if(err != CHIAKI_ERR_SUCCESS || did_size != sizeof(connect_info.did))
|
||||||
{
|
throw ChiakiException("Did invalid");
|
||||||
printf("did invalid.\n");
|
|
||||||
throw std::exception(); // TODO: proper exception
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO: move audio init out of here and use values from audio header
|
||||||
QAudioFormat audio_format;
|
QAudioFormat audio_format;
|
||||||
audio_format.setSampleRate(48000);
|
audio_format.setSampleRate(48000);
|
||||||
audio_format.setChannelCount(2);
|
audio_format.setChannelCount(2);
|
||||||
|
@ -92,10 +87,20 @@ StreamSession::StreamSession(const QString &host, const QString ®istkey, cons
|
||||||
|
|
||||||
memset(&keyboard_state, 0, sizeof(keyboard_state));
|
memset(&keyboard_state, 0, sizeof(keyboard_state));
|
||||||
|
|
||||||
chiaki_session_init(&session, &connect_info);
|
err = chiaki_session_init(&session, &connect_info);
|
||||||
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
|
throw ChiakiException("Chiaki Session Init failed");
|
||||||
|
|
||||||
chiaki_session_set_audio_frame_cb(&session, AudioFrameCb, this);
|
chiaki_session_set_audio_frame_cb(&session, AudioFrameCb, this);
|
||||||
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
||||||
chiaki_session_start(&session);
|
|
||||||
|
err = chiaki_session_start(&session);
|
||||||
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
chiaki_session_fini(&session);
|
||||||
|
throw ChiakiException("Chiaki Session Start failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
|
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
|
||||||
|
@ -112,6 +117,10 @@ StreamSession::~StreamSession()
|
||||||
chiaki_session_fini(&session);
|
chiaki_session_fini(&session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamSession::Stop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void StreamSession::HandleKeyboardEvent(QKeyEvent *event)
|
void StreamSession::HandleKeyboardEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
uint64_t button_mask;
|
uint64_t button_mask;
|
||||||
|
|
|
@ -146,6 +146,7 @@ typedef struct chiaki_session_t
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info);
|
||||||
CHIAKI_EXPORT void chiaki_session_fini(ChiakiSession *session);
|
CHIAKI_EXPORT void chiaki_session_fini(ChiakiSession *session);
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_start(ChiakiSession *session);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_start(ChiakiSession *session);
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_stop(ChiakiSession *session);
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_join(ChiakiSession *session);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_join(ChiakiSession *session);
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_set_controller_state(ChiakiSession *session, ChiakiControllerState *state);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_set_controller_state(ChiakiSession *session, ChiakiControllerState *state);
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,12 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_start(ChiakiSession *session)
|
||||||
return chiaki_thread_create(&session->session_thread, session_thread_func, session);
|
return chiaki_thread_create(&session->session_thread, session_thread_func, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_stop(ChiakiSession *session)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return CHIAKI_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_join(ChiakiSession *session)
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_join(ChiakiSession *session)
|
||||||
{
|
{
|
||||||
return chiaki_thread_join(&session->session_thread, NULL);
|
return chiaki_thread_join(&session->session_thread, NULL);
|
||||||
|
@ -183,7 +189,7 @@ static void *session_thread_func(void *arg)
|
||||||
goto quit_ctrl;
|
goto quit_ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHIAKI_LOGI(&session->log, "Starting Senkusha");
|
//CHIAKI_LOGI(&session->log, "Starting Senkusha");
|
||||||
|
|
||||||
/* TODO err = chiaki_senkusha_run(session);
|
/* TODO err = chiaki_senkusha_run(session);
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
|
@ -196,7 +202,7 @@ static void *session_thread_func(void *arg)
|
||||||
session->mtu = 1454;
|
session->mtu = 1454;
|
||||||
session->rtt = 12;
|
session->rtt = 12;
|
||||||
|
|
||||||
CHIAKI_LOGI(&session->log, "Senkusha completed successfully");
|
//CHIAKI_LOGI(&session->log, "Senkusha completed successfully");
|
||||||
|
|
||||||
err = chiaki_random_bytes(session->handshake_key, sizeof(session->handshake_key));
|
err = chiaki_random_bytes(session->handshake_key, sizeof(session->handshake_key));
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue