Starting stream from a main thread;

Handle stream start errors.
This commit is contained in:
rock88 2020-05-25 21:47:17 +03:00
parent 363d553979
commit 8008ba9c00
4 changed files with 15 additions and 14 deletions

View file

@ -8,8 +8,6 @@
#pragma once
extern void perform_async(std::function<void()> task);
template <typename T>
struct GSResult {
public:

View file

@ -157,7 +157,7 @@ void MoonlightSession::audio_renderer_decode_and_play_sample(char* sample_data,
// MARK: MoonlightSession
void MoonlightSession::start(std::function<void(bool)> callback) {
void MoonlightSession::start(ServerCallback<bool> callback) {
LiInitializeStreamConfiguration(&m_config);
int h = Settings::settings()->resolution();
@ -218,17 +218,18 @@ void MoonlightSession::start(std::function<void(bool)> callback) {
if (result.isSuccess()) {
m_config = result.value();
perform_async([this, callback] {
auto m_data = GameStreamClient::client()->server_data(m_address);
LiStartConnection(&m_data.serverInfo, &m_config, &m_connection_callbacks, &m_video_callbacks, &m_audio_callbacks, NULL, 0, NULL, 0);
nanogui::async([this, callback] {
callback(true);
});
});
auto m_data = GameStreamClient::client()->server_data(m_address);
int result = LiStartConnection(&m_data.serverInfo, &m_config, &m_connection_callbacks, &m_video_callbacks, &m_audio_callbacks, NULL, 0, NULL, 0);
if (result != 0) {
LiStopConnection();
callback(GSResult<bool>::failure("Failed to start stream..."));
} else {
callback(GSResult<bool>::success(true));
}
} else {
LOG_FMT("Failed to start stream: %s\n", result.error().c_str());
callback(false);
callback(GSResult<bool>::failure(result.error()));
}
});
}

View file

@ -26,7 +26,7 @@ public:
m_audio_renderer = audio_renderer;
}
void start(std::function<void(bool)> callback);
void start(ServerCallback<bool> callback);
void stop(int terminate_app);
void draw();

View file

@ -45,9 +45,11 @@ StreamWindow::StreamWindow(Widget *parent, const std::string &address, int app_i
m_loader = NULL;
}
if (result) {
if (result.isSuccess()) {
//
} else {
screen()->add<MessageDialog>(MessageDialog::Type::Information, "Error", result.error());
auto app = static_cast<Application *>(screen());
app->pop_window();
}