Add ChiakiException

This commit is contained in:
Florian Märkl 2019-08-01 20:07:44 +02:00
commit 1a5654bd49
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
4 changed files with 40 additions and 12 deletions

View file

@ -33,6 +33,16 @@ class QAudioOutput;
class QIODevice;
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
{
friend class StreamSessionPrivate;
@ -60,6 +70,8 @@ class StreamSession : public QObject
explicit StreamSession(const QString &host, const QString &registkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent = nullptr);
~StreamSession();
void Stop();
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
QGamepad *GetGamepad() { return gamepad; }
#endif

View file

@ -60,20 +60,15 @@ StreamSession::StreamSession(const QString &host, const QString &registkey, cons
QByteArray morning_str = morning.toUtf8();
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))
{
printf("morning invalid.\n");
throw std::exception(); // TODO: proper exception
}
throw ChiakiException("Morning invalid");
size_t did_size = sizeof(connect_info.did);
QByteArray did_str = did.toUtf8();
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))
{
printf("did invalid.\n");
throw std::exception(); // TODO: proper exception
}
throw ChiakiException("Did invalid");
// TODO: move audio init out of here and use values from audio header
QAudioFormat audio_format;
audio_format.setSampleRate(48000);
audio_format.setChannelCount(2);
@ -92,10 +87,20 @@ StreamSession::StreamSession(const QString &host, const QString &registkey, cons
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_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
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
@ -112,6 +117,10 @@ StreamSession::~StreamSession()
chiaki_session_fini(&session);
}
void StreamSession::Stop()
{
}
void StreamSession::HandleKeyboardEvent(QKeyEvent *event)
{
uint64_t button_mask;