mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Message Box on Session Quit
This commit is contained in:
parent
8e15f498c2
commit
f886995295
8 changed files with 87 additions and 14 deletions
|
@ -75,11 +75,13 @@ class StreamSession : public QObject
|
|||
|
||||
void PushAudioFrame(int16_t *buf, size_t samples_count);
|
||||
void PushVideoSample(uint8_t *buf, size_t buf_size);
|
||||
void Event(ChiakiEvent *event);
|
||||
|
||||
public:
|
||||
explicit StreamSession(const StreamSessionConnectInfo &connect_info, QObject *parent = nullptr);
|
||||
~StreamSession();
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||
|
@ -91,6 +93,7 @@ class StreamSession : public QObject
|
|||
|
||||
signals:
|
||||
void CurrentImageUpdated();
|
||||
void SessionQuit(ChiakiQuitReason reason);
|
||||
|
||||
private slots:
|
||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||
|
@ -99,4 +102,6 @@ class StreamSession : public QObject
|
|||
void SendFeedbackState();
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ChiakiQuitReason)
|
||||
|
||||
#endif // CHIAKI_STREAMSESSION_H
|
||||
|
|
|
@ -46,6 +46,7 @@ class StreamWindow: public QMainWindow
|
|||
|
||||
private slots:
|
||||
void FramesAvailable();
|
||||
void SessionQuit(ChiakiQuitReason reason);
|
||||
};
|
||||
|
||||
#endif // CHIAKI_GUI_STREAMWINDOW_H
|
||||
|
|
|
@ -22,6 +22,8 @@ int RunMain(QApplication &app);
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qRegisterMetaType<ChiakiQuitReason>();
|
||||
|
||||
QApplication app(argc, argv);
|
||||
QApplication::setApplicationName("Chiaki");
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
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 EventCb(ChiakiEvent *event, void *user);
|
||||
|
||||
StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObject *parent)
|
||||
: QObject(parent)
|
||||
|
@ -93,14 +94,7 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
|||
|
||||
chiaki_session_set_audio_frame_cb(&session, AudioFrameCb, this);
|
||||
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
||||
|
||||
err = chiaki_session_start(&session);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
chiaki_session_fini(&session);
|
||||
throw ChiakiException("Chiaki Session Start failed");
|
||||
}
|
||||
|
||||
chiaki_session_set_event_cb(&session, EventCb, this);
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
|
||||
|
@ -117,6 +111,16 @@ StreamSession::~StreamSession()
|
|||
chiaki_session_fini(&session);
|
||||
}
|
||||
|
||||
void StreamSession::Start()
|
||||
{
|
||||
ChiakiErrorCode err = chiaki_session_start(&session);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
chiaki_session_fini(&session);
|
||||
throw ChiakiException("Chiaki Session Start failed");
|
||||
}
|
||||
}
|
||||
|
||||
void StreamSession::Stop()
|
||||
{
|
||||
chiaki_session_stop(&session);
|
||||
|
@ -247,11 +251,22 @@ void StreamSession::PushVideoSample(uint8_t *buf, size_t buf_size)
|
|||
video_decoder.PutFrame(buf, buf_size);
|
||||
}
|
||||
|
||||
void StreamSession::Event(ChiakiEvent *event)
|
||||
{
|
||||
switch(event->type)
|
||||
{
|
||||
case CHIAKI_EVENT_QUIT:
|
||||
emit SessionQuit(event->quit.reason);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
class StreamSessionPrivate
|
||||
{
|
||||
public:
|
||||
static void PushAudioFrame(StreamSession *session, int16_t *buf, size_t samples_count) { session->PushAudioFrame(buf, samples_count); }
|
||||
static void PushVideoSample(StreamSession *session, uint8_t *buf, size_t buf_size) { session->PushVideoSample(buf, buf_size); }
|
||||
static void Event(StreamSession *session, ChiakiEvent *event) { session->Event(event); }
|
||||
};
|
||||
|
||||
static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user)
|
||||
|
@ -264,4 +279,10 @@ static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user)
|
|||
{
|
||||
auto session = reinterpret_cast<StreamSession *>(user);
|
||||
StreamSessionPrivate::PushVideoSample(session, buf, buf_size);
|
||||
}
|
||||
|
||||
static void EventCb(ChiakiEvent *event, void *user)
|
||||
{
|
||||
auto session = reinterpret_cast<StreamSession *>(user);
|
||||
StreamSessionPrivate::Event(session, event);
|
||||
}
|
|
@ -33,10 +33,14 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget
|
|||
|
||||
session = new StreamSession(connect_info, this);
|
||||
|
||||
connect(session, &StreamSession::SessionQuit, this, &StreamWindow::SessionQuit);
|
||||
|
||||
connect(session->GetVideoDecoder(), &VideoDecoder::FramesAvailable, this, &StreamWindow::FramesAvailable);
|
||||
FramesAvailable();
|
||||
|
||||
grabKeyboard();
|
||||
|
||||
session->Start();
|
||||
}
|
||||
|
||||
StreamWindow::~StreamWindow()
|
||||
|
@ -58,7 +62,7 @@ void StreamWindow::keyReleaseEvent(QKeyEvent *event)
|
|||
session->HandleKeyboardEvent(event);
|
||||
}
|
||||
|
||||
void StreamWindow::closeEvent(QCloseEvent *event)
|
||||
void StreamWindow::closeEvent(QCloseEvent *)
|
||||
{
|
||||
session->Stop();
|
||||
}
|
||||
|
@ -78,3 +82,11 @@ void StreamWindow::FramesAvailable()
|
|||
SetImage(prev);
|
||||
}
|
||||
}
|
||||
|
||||
void StreamWindow::SessionQuit(ChiakiQuitReason reason)
|
||||
{
|
||||
if(reason == CHIAKI_QUIT_REASON_STOPPED)
|
||||
return;
|
||||
QMessageBox::critical(this, tr("Session has quit"), tr("Chiaki Session has quit:") + "\n" + chiaki_quit_reason_string(reason));
|
||||
close();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue