mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Refactor IO class as singleton
This commit is contained in:
parent
a1b081bfce
commit
d31fb46ae8
8 changed files with 462 additions and 379 deletions
|
@ -11,55 +11,55 @@
|
||||||
|
|
||||||
#include <borealis.hpp>
|
#include <borealis.hpp>
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "host.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "discoverymanager.h"
|
#include "discoverymanager.h"
|
||||||
|
#include "host.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
class HostInterface : public brls::List
|
class HostInterface : public brls::List
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
IO * io;
|
IO *io;
|
||||||
Host * host;
|
Host *host;
|
||||||
Settings * settings;
|
Settings *settings;
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HostInterface(IO * io, Host * host, Settings * settings);
|
HostInterface(Host *host);
|
||||||
~HostInterface();
|
~HostInterface();
|
||||||
|
|
||||||
static void Register(IO * io, Host * host,
|
static void Register(Host *host, std::function<void()> success_cb = nullptr);
|
||||||
Settings * settings, std::function<void()> success_cb = nullptr);
|
|
||||||
void Register();
|
void Register();
|
||||||
void Wakeup(brls::View * view);
|
void Wakeup(brls::View *view);
|
||||||
void Connect(brls::View * view);
|
void Connect(brls::View *view);
|
||||||
void ConnectSession();
|
void ConnectSession();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
bool Stream();
|
void Stream();
|
||||||
bool CloseStream(ChiakiQuitEvent * quit);
|
void CloseStream(ChiakiQuitEvent *quit);
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainApplication
|
class MainApplication
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Settings * settings;
|
Settings *settings;
|
||||||
ChiakiLog * log;
|
ChiakiLog *log;
|
||||||
DiscoveryManager * discoverymanager;
|
DiscoveryManager *discoverymanager;
|
||||||
IO * io;
|
IO *io;
|
||||||
brls::TabFrame * rootFrame;
|
brls::TabFrame *rootFrame;
|
||||||
std::map<Host *, HostInterface *> host_menuitems;
|
std::map<Host *, HostInterface *> host_menuitems;
|
||||||
// add_host local settings
|
// add_host local settings
|
||||||
std::string remote_display_name = "";
|
std::string remote_display_name = "";
|
||||||
std::string remote_addr = "";
|
std::string remote_addr = "";
|
||||||
ChiakiTarget remote_ps_version = CHIAKI_TARGET_PS5_1;
|
ChiakiTarget remote_ps_version = CHIAKI_TARGET_PS5_1;
|
||||||
|
|
||||||
bool BuildConfigurationMenu(brls::List *, Host * host = nullptr);
|
bool BuildConfigurationMenu(brls::List *, Host *host = nullptr);
|
||||||
void BuildAddHostConfigurationMenu(brls::List *);
|
void BuildAddHostConfigurationMenu(brls::List *);
|
||||||
public:
|
|
||||||
MainApplication(DiscoveryManager * discoverymanager, IO * io);
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainApplication(DiscoveryManager *discoverymanager);
|
||||||
~MainApplication();
|
~MainApplication();
|
||||||
bool Load();
|
bool Load();
|
||||||
};
|
};
|
||||||
|
@ -67,24 +67,23 @@ class MainApplication
|
||||||
class PSRemotePlay : public brls::View
|
class PSRemotePlay : public brls::View
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
brls::AppletFrame * frame;
|
brls::AppletFrame *frame;
|
||||||
// to display stream on screen
|
// to display stream on screen
|
||||||
IO * io;
|
IO *io;
|
||||||
// to send gamepad inputs
|
// to send gamepad inputs
|
||||||
Host * host;
|
Host *host;
|
||||||
brls::Label * label;
|
brls::Label *label;
|
||||||
ChiakiControllerState state = { 0 };
|
ChiakiControllerState state = {0};
|
||||||
// FPS calculation
|
// FPS calculation
|
||||||
// double base_time;
|
// double base_time;
|
||||||
// int frame_counter = 0;
|
// int frame_counter = 0;
|
||||||
// int fps = 0;
|
// int fps = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PSRemotePlay(IO * io, Host * host);
|
PSRemotePlay(Host *host);
|
||||||
~PSRemotePlay();
|
~PSRemotePlay();
|
||||||
|
|
||||||
void draw(NVGcontext * vg, int x, int y, unsigned width, unsigned height, brls::Style * style, brls::FrameContext * ctx) override;
|
void draw(NVGcontext *vg, int x, int y, unsigned width, unsigned height, brls::Style *style, brls::FrameContext *ctx) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHIAKI_GUI_H
|
#endif // CHIAKI_GUI_H
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
|
|
||||||
class DiscoveryManager;
|
class DiscoveryManager;
|
||||||
static void Discovery(ChiakiDiscoveryHost *, void *);
|
static void Discovery(ChiakiDiscoveryHost *, void *);
|
||||||
static void InitAudioCB(unsigned int channels, unsigned int rate, void * user);
|
static void InitAudioCB(unsigned int channels, unsigned int rate, void *user);
|
||||||
static bool VideoCB(uint8_t * buf, size_t buf_size, void * user);
|
static bool VideoCB(uint8_t *buf, size_t buf_size, void *user);
|
||||||
static void AudioCB(int16_t * buf, size_t samples_count, void * user);
|
static void AudioCB(int16_t *buf, size_t samples_count, void *user);
|
||||||
static void RegistEventCB(ChiakiRegistEvent * event, void * user);
|
static void EventCB(ChiakiEvent *event, void *user);
|
||||||
static void EventCB(ChiakiEvent * event, void * user);
|
static void RegistEventCB(ChiakiRegistEvent *event, void *user);
|
||||||
|
|
||||||
enum RegistError
|
enum RegistError
|
||||||
{
|
{
|
||||||
|
@ -37,8 +37,8 @@ class Settings;
|
||||||
class Host
|
class Host
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ChiakiLog * log = nullptr;
|
ChiakiLog *log = nullptr;
|
||||||
Settings * settings = nullptr;
|
Settings *settings = nullptr;
|
||||||
//video config
|
//video config
|
||||||
ChiakiVideoResolutionPreset video_resolution = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
ChiakiVideoResolutionPreset video_resolution = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
||||||
ChiakiVideoFPSPreset video_fps = CHIAKI_VIDEO_FPS_PRESET_60;
|
ChiakiVideoFPSPreset video_fps = CHIAKI_VIDEO_FPS_PRESET_60;
|
||||||
|
@ -52,6 +52,9 @@ class Host
|
||||||
std::function<void()> chiaki_regist_event_type_finished_canceled = nullptr;
|
std::function<void()> chiaki_regist_event_type_finished_canceled = nullptr;
|
||||||
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
|
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
|
||||||
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
|
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
|
||||||
|
std::function<void()> chiaki_event_connected_cb = nullptr;
|
||||||
|
std::function<void(bool)> chiaki_even_login_pin_request_cb = nullptr;
|
||||||
|
std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
bool discovered = false;
|
bool discovered = false;
|
||||||
|
@ -95,7 +98,8 @@ class Host
|
||||||
void StartSession();
|
void StartSession();
|
||||||
void SendFeedbackState(ChiakiControllerState *);
|
void SendFeedbackState(ChiakiControllerState *);
|
||||||
void RegistCB(ChiakiRegistEvent *);
|
void RegistCB(ChiakiRegistEvent *);
|
||||||
bool GetVideoResolution(int * ret_width, int * ret_height);
|
void ConnectionEventCB(ChiakiEvent *);
|
||||||
|
bool GetVideoResolution(int *ret_width, int *ret_height);
|
||||||
std::string GetHostName();
|
std::string GetHostName();
|
||||||
std::string GetHostAddr();
|
std::string GetHostAddr();
|
||||||
ChiakiTarget GetChiakiTarget();
|
ChiakiTarget GetChiakiTarget();
|
||||||
|
@ -104,6 +108,9 @@ class Host
|
||||||
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
|
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
|
||||||
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
|
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
|
||||||
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
|
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
|
||||||
|
void SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb);
|
||||||
|
void SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb);
|
||||||
|
void SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb);
|
||||||
bool IsRegistered();
|
bool IsRegistered();
|
||||||
bool IsDiscovered();
|
bool IsDiscovered();
|
||||||
bool IsReady();
|
bool IsReady();
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
#ifndef CHIAKI_IO_H
|
#ifndef CHIAKI_IO_H
|
||||||
#define CHIAKI_IO_H
|
#define CHIAKI_IO_H
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <glad.h> // glad library (OpenGL loader)
|
#include <glad.h> // glad library (OpenGL loader)
|
||||||
|
|
||||||
#include <chiaki/session.h>
|
#include <chiaki/session.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
https://github.com/devkitPro/switch-glad/blob/master/include/glad/glad.h
|
https://github.com/devkitPro/switch-glad/blob/master/include/glad/glad.h
|
||||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&api=gl%3D4.3&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic
|
https://glad.dav1d.de/#profile=core&language=c&specification=gl&api=gl%3D4.3&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic
|
||||||
|
@ -37,8 +36,8 @@ extern "C"
|
||||||
#include <libswscale/swscale.h>
|
#include <libswscale/swscale.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include <chiaki/controller.h>
|
#include <chiaki/controller.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
|
@ -47,8 +46,11 @@ extern "C"
|
||||||
|
|
||||||
class IO
|
class IO
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
IO();
|
||||||
|
static IO * instance;
|
||||||
private:
|
private:
|
||||||
ChiakiLog * log;
|
ChiakiLog *log;
|
||||||
int video_width;
|
int video_width;
|
||||||
int video_height;
|
int video_height;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
@ -57,15 +59,12 @@ class IO
|
||||||
// default nintendo switch res
|
// default nintendo switch res
|
||||||
int screen_width = 1280;
|
int screen_width = 1280;
|
||||||
int screen_height = 720;
|
int screen_height = 720;
|
||||||
std::function<bool()> chiaki_event_connected_cb = nullptr;
|
AVCodec *codec;
|
||||||
std::function<bool(bool)> chiaki_even_login_pin_request_cb = nullptr;
|
AVCodecContext *codec_context;
|
||||||
std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
AVFrame *frame;
|
||||||
AVCodec * codec;
|
|
||||||
AVCodecContext * codec_context;
|
|
||||||
AVFrame * frame;
|
|
||||||
SDL_AudioDeviceID sdl_audio_device_id = 0;
|
SDL_AudioDeviceID sdl_audio_device_id = 0;
|
||||||
SDL_Event sdl_event;
|
SDL_Event sdl_event;
|
||||||
SDL_Joystick * sdl_joystick_ptr[SDL_JOYSTICK_COUNT] = {0};
|
SDL_Joystick *sdl_joystick_ptr[SDL_JOYSTICK_COUNT] = {0};
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
GLuint tex[PLANES_COUNT];
|
GLuint tex[PLANES_COUNT];
|
||||||
|
@ -73,49 +72,38 @@ class IO
|
||||||
GLuint vert;
|
GLuint vert;
|
||||||
GLuint frag;
|
GLuint frag;
|
||||||
GLuint prog;
|
GLuint prog;
|
||||||
private:
|
|
||||||
bool InitAVCodec();
|
bool InitAVCodec();
|
||||||
bool InitOpenGl();
|
bool InitOpenGl();
|
||||||
bool InitOpenGlTextures();
|
bool InitOpenGlTextures();
|
||||||
bool InitOpenGlShader();
|
bool InitOpenGlShader();
|
||||||
void OpenGlDraw();
|
void OpenGlDraw();
|
||||||
#ifdef DEBUG_OPENGL
|
#ifdef DEBUG_OPENGL
|
||||||
void CheckGLError(const char * func, const char * file, int line);
|
void CheckGLError(const char *func, const char *file, int line);
|
||||||
void DumpShaderError(GLuint prog, const char * func, const char * file, int line);
|
void DumpShaderError(GLuint prog, const char *func, const char *file, int line);
|
||||||
void DumpProgramError(GLuint prog, const char * func, const char * file, int line);
|
void DumpProgramError(GLuint prog, const char *func, const char *file, int line);
|
||||||
#endif
|
#endif
|
||||||
GLuint CreateAndCompileShader(GLenum type, const char * source);
|
GLuint CreateAndCompileShader(GLenum type, const char *source);
|
||||||
void SetOpenGlYUVPixels(AVFrame * frame);
|
void SetOpenGlYUVPixels(AVFrame *frame);
|
||||||
bool ReadGameKeys(SDL_Event * event, ChiakiControllerState * state);
|
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
|
||||||
bool ReadGameTouchScreen(ChiakiControllerState * state);
|
bool ReadGameTouchScreen(ChiakiControllerState *state);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IO(ChiakiLog * log);
|
// singleton configuration
|
||||||
|
IO(const IO&) = delete;
|
||||||
|
void operator=(const IO&) = delete;
|
||||||
|
static IO * GetInstance();
|
||||||
|
|
||||||
~IO();
|
~IO();
|
||||||
void SetMesaConfig();
|
void SetMesaConfig();
|
||||||
bool VideoCB(uint8_t * buf, size_t buf_size);
|
bool VideoCB(uint8_t *buf, size_t buf_size);
|
||||||
void SetEventConnectedCallback(std::function<bool()> chiaki_event_connected_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
|
|
||||||
};
|
|
||||||
void SetEventLoginPinRequestCallback(std::function<bool(bool)> chiaki_even_login_pin_request_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
|
|
||||||
};
|
|
||||||
void SetEventQuitCallback(std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb)
|
|
||||||
{
|
|
||||||
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
|
|
||||||
};
|
|
||||||
void InitAudioCB(unsigned int channels, unsigned int rate);
|
void InitAudioCB(unsigned int channels, unsigned int rate);
|
||||||
void AudioCB(int16_t * buf, size_t samples_count);
|
void AudioCB(int16_t *buf, size_t samples_count);
|
||||||
void EventCB(ChiakiEvent *event);
|
|
||||||
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
||||||
bool FreeVideo();
|
bool FreeVideo();
|
||||||
bool InitJoystick();
|
bool InitJoystick();
|
||||||
bool FreeJoystick();
|
bool FreeJoystick();
|
||||||
bool ReadUserKeyboard(char * buffer, size_t buffer_size);
|
bool ReadUserKeyboard(char *buffer, size_t buffer_size);
|
||||||
bool MainLoop(ChiakiControllerState * state);
|
bool MainLoop(ChiakiControllerState *state);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CHIAKI_IO_H
|
#endif //CHIAKI_IO_H
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#define SCREEN_W 1280
|
#define SCREEN_W 1280
|
||||||
#define SCREEN_H 720
|
#define SCREEN_H 720
|
||||||
|
@ -9,34 +9,39 @@
|
||||||
// TODO
|
// TODO
|
||||||
using namespace brls::i18n::literals; // for _i18n
|
using namespace brls::i18n::literals; // for _i18n
|
||||||
|
|
||||||
#define DIALOG(dialog, r) \
|
#define DIALOG(dialog, r) \
|
||||||
brls::Dialog* d_##dialog = new brls::Dialog(r); \
|
brls::Dialog *d_##dialog = new brls::Dialog(r); \
|
||||||
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View* view) \
|
brls::GenericEvent::Callback cb_##dialog = [d_##dialog](brls::View *view) { \
|
||||||
{ \
|
d_##dialog->close(); \
|
||||||
d_##dialog->close(); \
|
}; \
|
||||||
}; \
|
d_##dialog->addButton("Ok", cb_##dialog); \
|
||||||
d_##dialog->addButton("Ok", cb_##dialog); \
|
d_##dialog->setCancelable(false); \
|
||||||
d_##dialog->setCancelable(false); \
|
d_##dialog->open(); \
|
||||||
d_##dialog->open(); \
|
|
||||||
brls::Logger::info("Dialog: {0}", r);
|
brls::Logger::info("Dialog: {0}", r);
|
||||||
|
|
||||||
|
HostInterface::HostInterface(Host *host)
|
||||||
HostInterface::HostInterface(IO * io, Host * host, Settings * settings)
|
: host(host)
|
||||||
: io(io), host(host), settings(settings)
|
|
||||||
{
|
{
|
||||||
brls::ListItem* connect = new brls::ListItem("Connect");
|
this->settings = Settings::GetInstance();
|
||||||
|
this->io = IO::GetInstance();
|
||||||
|
|
||||||
|
brls::ListItem *connect = new brls::ListItem("Connect");
|
||||||
connect->getClickEvent()->subscribe(std::bind(&HostInterface::Connect, this, std::placeholders::_1));
|
connect->getClickEvent()->subscribe(std::bind(&HostInterface::Connect, this, std::placeholders::_1));
|
||||||
this->addView(connect);
|
this->addView(connect);
|
||||||
|
|
||||||
brls::ListItem* wakeup = new brls::ListItem("Wakeup");
|
brls::ListItem *wakeup = new brls::ListItem("Wakeup");
|
||||||
wakeup->getClickEvent()->subscribe(std::bind(&HostInterface::Wakeup, this, std::placeholders::_1));
|
wakeup->getClickEvent()->subscribe(std::bind(&HostInterface::Wakeup, this, std::placeholders::_1));
|
||||||
this->addView(wakeup);
|
this->addView(wakeup);
|
||||||
|
|
||||||
// message delimiter
|
// message delimiter
|
||||||
brls::Label* info = new brls::Label(brls::LabelStyle::REGULAR,
|
brls::Label *info = new brls::Label(brls::LabelStyle::REGULAR,
|
||||||
"Host configuration", true);
|
"Host configuration", true);
|
||||||
this->addView(info);
|
this->addView(info);
|
||||||
|
|
||||||
|
// push opengl chiaki stream
|
||||||
|
// when the host is connected
|
||||||
|
this->host->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
|
||||||
|
this->host->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
HostInterface::~HostInterface()
|
HostInterface::~HostInterface()
|
||||||
|
@ -44,8 +49,11 @@ HostInterface::~HostInterface()
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Register(IO * io, Host * host, Settings * settings, std::function<void()> success_cb)
|
void HostInterface::Register(Host *host, std::function<void()> success_cb)
|
||||||
{
|
{
|
||||||
|
Settings *settings = Settings::GetInstance();
|
||||||
|
IO *io = IO::GetInstance();
|
||||||
|
|
||||||
// user must provide psn id for registration
|
// user must provide psn id for registration
|
||||||
std::string account_id = settings->GetPSNAccountID(host);
|
std::string account_id = settings->GetPSNAccountID(host);
|
||||||
std::string online_id = settings->GetPSNOnlineID(host);
|
std::string online_id = settings->GetPSNOnlineID(host);
|
||||||
|
@ -65,35 +73,32 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
}
|
}
|
||||||
|
|
||||||
// add HostConnected function to regist_event_type_finished_success
|
// add HostConnected function to regist_event_type_finished_success
|
||||||
auto event_type_finished_success_cb = [settings, success_cb]()
|
auto event_type_finished_success_cb = [settings, success_cb]() {
|
||||||
{
|
// save RP keys
|
||||||
// save RP keys
|
settings->WriteFile();
|
||||||
settings->WriteFile();
|
if(success_cb != nullptr)
|
||||||
if(success_cb != nullptr)
|
{
|
||||||
{
|
// FIXME: may raise a connection refused
|
||||||
// FIXME: may raise a connection refused
|
// when the connection is triggered
|
||||||
// when the connection is triggered
|
// just after the register success
|
||||||
// just after the register success
|
sleep(2);
|
||||||
sleep(2);
|
success_cb();
|
||||||
success_cb();
|
}
|
||||||
}
|
// decrement block input token number
|
||||||
// decrement block input token number
|
brls::Application::unblockInputs();
|
||||||
brls::Application::unblockInputs();
|
|
||||||
};
|
};
|
||||||
host->SetRegistEventTypeFinishedSuccess(event_type_finished_success_cb);
|
host->SetRegistEventTypeFinishedSuccess(event_type_finished_success_cb);
|
||||||
|
|
||||||
auto event_type_finished_failed_cb = []()
|
auto event_type_finished_failed_cb = []() {
|
||||||
{
|
// unlock user inputs
|
||||||
// unlock user inputs
|
brls::Application::unblockInputs();
|
||||||
brls::Application::unblockInputs();
|
brls::Application::notify("Registration failed");
|
||||||
brls::Application::notify("Registration failed");
|
|
||||||
};
|
};
|
||||||
host->SetRegistEventTypeFinishedFailed(event_type_finished_failed_cb);
|
host->SetRegistEventTypeFinishedFailed(event_type_finished_failed_cb);
|
||||||
|
|
||||||
// the host is not registered yet
|
// the host is not registered yet
|
||||||
brls::Dialog* peprpc = new brls::Dialog("Please enter your PlayStation registration PIN code");
|
brls::Dialog *peprpc = new brls::Dialog("Please enter your PlayStation registration PIN code");
|
||||||
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View* view)
|
brls::GenericEvent::Callback cb_peprpc = [host, io, peprpc](brls::View *view) {
|
||||||
{
|
|
||||||
bool pin_provided = false;
|
bool pin_provided = false;
|
||||||
char pin_input[9] = {0};
|
char pin_input[9] = {0};
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
|
@ -133,11 +138,10 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
|
||||||
void HostInterface::Register()
|
void HostInterface::Register()
|
||||||
{
|
{
|
||||||
// use Connect just after the registration to save user inputs
|
// use Connect just after the registration to save user inputs
|
||||||
HostInterface::Register(this->io, this->host,
|
HostInterface::Register(this->host, std::bind(&HostInterface::ConnectSession, this));
|
||||||
this->settings, std::bind(&HostInterface::ConnectSession, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Wakeup(brls::View * view)
|
void HostInterface::Wakeup(brls::View *view)
|
||||||
{
|
{
|
||||||
if(!this->host->HasRPkey())
|
if(!this->host->HasRPkey())
|
||||||
{
|
{
|
||||||
|
@ -158,7 +162,7 @@ void HostInterface::Wakeup(brls::View * view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HostInterface::Connect(brls::View * view)
|
void HostInterface::Connect(brls::View *view)
|
||||||
{
|
{
|
||||||
// check that all requirements are met
|
// check that all requirements are met
|
||||||
if(!this->host->IsDiscovered() && !this->host->HasRPkey())
|
if(!this->host->IsDiscovered() && !this->host->HasRPkey())
|
||||||
|
@ -194,11 +198,6 @@ void HostInterface::ConnectSession()
|
||||||
// user inputs are restored with the CloseStream
|
// user inputs are restored with the CloseStream
|
||||||
brls::Application::blockInputs();
|
brls::Application::blockInputs();
|
||||||
|
|
||||||
// push opengl chiaki stream
|
|
||||||
// when the host is connected
|
|
||||||
this->io->SetEventConnectedCallback(std::bind(&HostInterface::Stream, this));
|
|
||||||
this->io->SetEventQuitCallback(std::bind(&HostInterface::CloseStream, this, std::placeholders::_1));
|
|
||||||
|
|
||||||
// connect host sesssion
|
// connect host sesssion
|
||||||
this->host->InitSession(this->io);
|
this->host->InitSession(this->io);
|
||||||
this->host->StartSession();
|
this->host->StartSession();
|
||||||
|
@ -212,10 +211,11 @@ void HostInterface::Disconnect()
|
||||||
this->host->StopSession();
|
this->host->StopSession();
|
||||||
this->connected = false;
|
this->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->host->FiniSession();
|
this->host->FiniSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HostInterface::Stream()
|
void HostInterface::Stream()
|
||||||
{
|
{
|
||||||
this->connected = true;
|
this->connected = true;
|
||||||
// https://github.com/natinusala/borealis/issues/59
|
// https://github.com/natinusala/borealis/issues/59
|
||||||
|
@ -226,11 +226,10 @@ bool HostInterface::Stream()
|
||||||
// brls::Application::setDisplayFramerate(true);
|
// brls::Application::setDisplayFramerate(true);
|
||||||
|
|
||||||
// push raw opengl stream over borealis
|
// push raw opengl stream over borealis
|
||||||
brls::Application::pushView(new PSRemotePlay(this->io, this->host));
|
brls::Application::pushView(new PSRemotePlay(this->host));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
|
void HostInterface::CloseStream(ChiakiQuitEvent *quit)
|
||||||
{
|
{
|
||||||
// session QUIT call back
|
// session QUIT call back
|
||||||
brls::Application::unblockInputs();
|
brls::Application::unblockInputs();
|
||||||
|
@ -244,14 +243,14 @@ bool HostInterface::CloseStream(ChiakiQuitEvent * quit)
|
||||||
*/
|
*/
|
||||||
brls::Application::notify(chiaki_quit_reason_string(quit->reason));
|
brls::Application::notify(chiaki_quit_reason_string(quit->reason));
|
||||||
Disconnect();
|
Disconnect();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApplication::MainApplication(DiscoveryManager * discoverymanager, IO * io)
|
MainApplication::MainApplication(DiscoveryManager *discoverymanager)
|
||||||
: discoverymanager(discoverymanager), io(io)
|
: discoverymanager(discoverymanager)
|
||||||
{
|
{
|
||||||
this->settings = Settings::GetInstance();
|
this->settings = Settings::GetInstance();
|
||||||
this->log = this->settings->GetLogger();
|
this->log = this->settings->GetLogger();
|
||||||
|
this->io = IO::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApplication::~MainApplication()
|
MainApplication::~MainApplication()
|
||||||
|
@ -268,7 +267,7 @@ bool MainApplication::Load()
|
||||||
brls::Logger::setLogLevel(brls::LogLevel::DEBUG);
|
brls::Logger::setLogLevel(brls::LogLevel::DEBUG);
|
||||||
|
|
||||||
brls::i18n::loadTranslations();
|
brls::i18n::loadTranslations();
|
||||||
if (!brls::Application::init("Chiaki Remote play"))
|
if(!brls::Application::init("Chiaki Remote play"))
|
||||||
{
|
{
|
||||||
brls::Logger::error("Unable to init Borealis application");
|
brls::Logger::error("Unable to init Borealis application");
|
||||||
return false;
|
return false;
|
||||||
|
@ -293,8 +292,8 @@ bool MainApplication::Load()
|
||||||
this->rootFrame->setTitle("Chiaki: Open Source PlayStation Remote Play Client");
|
this->rootFrame->setTitle("Chiaki: Open Source PlayStation Remote Play Client");
|
||||||
this->rootFrame->setIcon(BOREALIS_ASSET("icon.jpg"));
|
this->rootFrame->setIcon(BOREALIS_ASSET("icon.jpg"));
|
||||||
|
|
||||||
brls::List* config = new brls::List();
|
brls::List *config = new brls::List();
|
||||||
brls::List* add_host = new brls::List();
|
brls::List *add_host = new brls::List();
|
||||||
|
|
||||||
BuildConfigurationMenu(config);
|
BuildConfigurationMenu(config);
|
||||||
BuildAddHostConfigurationMenu(add_host);
|
BuildAddHostConfigurationMenu(add_host);
|
||||||
|
@ -306,16 +305,15 @@ bool MainApplication::Load()
|
||||||
// Add the root view to the stack
|
// Add the root view to the stack
|
||||||
brls::Application::pushView(this->rootFrame);
|
brls::Application::pushView(this->rootFrame);
|
||||||
|
|
||||||
std::map<std::string, Host> * hosts = this->settings->GetHostsMap();
|
std::map<std::string, Host> *hosts = this->settings->GetHostsMap();
|
||||||
while(brls::Application::mainLoop())
|
while(brls::Application::mainLoop())
|
||||||
{
|
{
|
||||||
for(auto it = hosts->begin(); it != hosts->end(); it++)
|
for(auto it = hosts->begin(); it != hosts->end(); it++)
|
||||||
{
|
{
|
||||||
// add host to the gui only if the host is registered or discovered
|
// add host to the gui only if the host is registered or discovered
|
||||||
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end()
|
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end() && (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
|
||||||
&& (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
|
|
||||||
{
|
{
|
||||||
HostInterface * new_host = new HostInterface(this->io, &it->second, this->settings);
|
HostInterface *new_host = new HostInterface(&it->second);
|
||||||
this->host_menuitems[&it->second] = new_host;
|
this->host_menuitems[&it->second] = new_host;
|
||||||
// create host if udefined
|
// create host if udefined
|
||||||
BuildConfigurationMenu(new_host, &it->second);
|
BuildConfigurationMenu(new_host, &it->second);
|
||||||
|
@ -326,13 +324,12 @@ bool MainApplication::Load()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
bool MainApplication::BuildConfigurationMenu(brls::List *ls, Host *host)
|
||||||
{
|
{
|
||||||
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
|
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
|
||||||
brls::ListItem* psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
|
brls::ListItem *psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
|
||||||
psn_account_id->setValue(psn_account_id_string.c_str());
|
psn_account_id->setValue(psn_account_id_string.c_str());
|
||||||
auto psn_account_id_cb = [this, host, psn_account_id](brls::View * view)
|
auto psn_account_id_cb = [this, host, psn_account_id](brls::View *view) {
|
||||||
{
|
|
||||||
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
|
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
|
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -349,10 +346,9 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
ls->addView(psn_account_id);
|
ls->addView(psn_account_id);
|
||||||
|
|
||||||
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
|
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
|
||||||
brls::ListItem* psn_online_id = new brls::ListItem("PSN Online ID");
|
brls::ListItem *psn_online_id = new brls::ListItem("PSN Online ID");
|
||||||
psn_online_id->setValue(psn_online_id_string.c_str());
|
psn_online_id->setValue(psn_online_id_string.c_str());
|
||||||
auto psn_online_id_cb = [this, host, psn_online_id](brls::View * view)
|
auto psn_online_id_cb = [this, host, psn_online_id](brls::View *view) {
|
||||||
{
|
|
||||||
char online_id[256] = {0};
|
char online_id[256] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
|
bool input = this->io->ReadUserKeyboard(online_id, sizeof(online_id));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -383,11 +379,10 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
brls::SelectListItem* resolution = new brls::SelectListItem(
|
brls::SelectListItem *resolution = new brls::SelectListItem(
|
||||||
"Resolution", { "720p", "540p", "360p" }, value);
|
"Resolution", {"720p", "540p", "360p"}, value);
|
||||||
|
|
||||||
auto resolution_cb = [this, host](int result)
|
auto resolution_cb = [this, host](int result) {
|
||||||
{
|
|
||||||
ChiakiVideoResolutionPreset value = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
ChiakiVideoResolutionPreset value = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
|
@ -418,11 +413,10 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
brls::SelectListItem* fps = new brls::SelectListItem(
|
brls::SelectListItem *fps = new brls::SelectListItem(
|
||||||
"FPS", { "60", "30"}, value);
|
"FPS", {"60", "30"}, value);
|
||||||
|
|
||||||
auto fps_cb = [this, host](int result)
|
auto fps_cb = [this, host](int result) {
|
||||||
{
|
|
||||||
ChiakiVideoFPSPreset value = CHIAKI_VIDEO_FPS_PRESET_60;
|
ChiakiVideoFPSPreset value = CHIAKI_VIDEO_FPS_PRESET_60;
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
|
@ -443,49 +437,47 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
|
||||||
if(host != nullptr)
|
if(host != nullptr)
|
||||||
{
|
{
|
||||||
// message delimiter
|
// message delimiter
|
||||||
brls::Label* info = new brls::Label(brls::LabelStyle::REGULAR,
|
brls::Label *info = new brls::Label(brls::LabelStyle::REGULAR,
|
||||||
"Host information", true);
|
"Host information", true);
|
||||||
ls->addView(info);
|
ls->addView(info);
|
||||||
|
|
||||||
std::string host_name_string = this->settings->GetHostName(host);
|
std::string host_name_string = this->settings->GetHostName(host);
|
||||||
brls::ListItem* host_name = new brls::ListItem("PS Hostname");
|
brls::ListItem *host_name = new brls::ListItem("PS Hostname");
|
||||||
host_name->setValue(host_name_string.c_str());
|
host_name->setValue(host_name_string.c_str());
|
||||||
ls->addView(host_name);
|
ls->addView(host_name);
|
||||||
|
|
||||||
std::string host_addr_string = settings->GetHostAddr(host);
|
std::string host_addr_string = settings->GetHostAddr(host);
|
||||||
brls::ListItem* host_addr = new brls::ListItem("PS4 Address");
|
brls::ListItem *host_addr = new brls::ListItem("PS4 Address");
|
||||||
host_addr->setValue(host_addr_string.c_str());
|
host_addr->setValue(host_addr_string.c_str());
|
||||||
ls->addView(host_addr);
|
ls->addView(host_addr);
|
||||||
|
|
||||||
std::string host_rp_regist_key_string = settings->GetHostRPRegistKey(host);
|
std::string host_rp_regist_key_string = settings->GetHostRPRegistKey(host);
|
||||||
brls::ListItem* host_rp_regist_key = new brls::ListItem("RP Register Key");
|
brls::ListItem *host_rp_regist_key = new brls::ListItem("RP Register Key");
|
||||||
host_rp_regist_key->setValue(host_rp_regist_key_string.c_str());
|
host_rp_regist_key->setValue(host_rp_regist_key_string.c_str());
|
||||||
ls->addView(host_rp_regist_key);
|
ls->addView(host_rp_regist_key);
|
||||||
|
|
||||||
std::string host_rp_key_string = settings->GetHostRPKey(host);
|
std::string host_rp_key_string = settings->GetHostRPKey(host);
|
||||||
brls::ListItem* host_rp_key = new brls::ListItem("RP Key");
|
brls::ListItem *host_rp_key = new brls::ListItem("RP Key");
|
||||||
host_rp_key->setValue(host_rp_key_string.c_str());
|
host_rp_key->setValue(host_rp_key_string.c_str());
|
||||||
ls->addView(host_rp_key);
|
ls->addView(host_rp_key);
|
||||||
|
|
||||||
std::string host_rp_key_type_string = std::to_string(settings->GetHostRPKeyType(host));
|
std::string host_rp_key_type_string = std::to_string(settings->GetHostRPKeyType(host));
|
||||||
brls::ListItem* host_rp_key_type = new brls::ListItem("RP Key type");
|
brls::ListItem *host_rp_key_type = new brls::ListItem("RP Key type");
|
||||||
host_rp_key_type->setValue(host_rp_key_type_string.c_str());
|
host_rp_key_type->setValue(host_rp_key_type_string.c_str());
|
||||||
ls->addView(host_rp_key_type);
|
ls->addView(host_rp_key_type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
void MainApplication::BuildAddHostConfigurationMenu(brls::List *add_host)
|
||||||
{
|
{
|
||||||
// create host for wan connection
|
// create host for wan connection
|
||||||
// brls::Label* add_host_label = new brls::Label(brls::LabelStyle::REGULAR,
|
// brls::Label* add_host_label = new brls::Label(brls::LabelStyle::REGULAR,
|
||||||
// "Add Host configuration", true);
|
// "Add Host configuration", true);
|
||||||
|
|
||||||
brls::ListItem* display_name = new brls::ListItem("Display name");
|
brls::ListItem *display_name = new brls::ListItem("Display name");
|
||||||
auto display_name_cb = [this, display_name](brls::View * view)
|
auto display_name_cb = [this, display_name](brls::View *view) {
|
||||||
{
|
|
||||||
char name[16] = {0};
|
char name[16] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
|
bool input = this->io->ReadUserKeyboard(name, sizeof(name));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -499,9 +491,8 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
display_name->getClickEvent()->subscribe(display_name_cb);
|
display_name->getClickEvent()->subscribe(display_name_cb);
|
||||||
add_host->addView(display_name);
|
add_host->addView(display_name);
|
||||||
|
|
||||||
brls::ListItem* address = new brls::ListItem("Remote IP/name");
|
brls::ListItem *address = new brls::ListItem("Remote IP/name");
|
||||||
auto address_cb = [this, address](brls::View * view)
|
auto address_cb = [this, address](brls::View *view) {
|
||||||
{
|
|
||||||
char addr[256] = {0};
|
char addr[256] = {0};
|
||||||
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
|
bool input = this->io->ReadUserKeyboard(addr, sizeof(addr));
|
||||||
if(input)
|
if(input)
|
||||||
|
@ -515,15 +506,13 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
address->getClickEvent()->subscribe(address_cb);
|
address->getClickEvent()->subscribe(address_cb);
|
||||||
add_host->addView(address);
|
add_host->addView(address);
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
|
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
|
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
|
||||||
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
|
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
|
||||||
brls::SelectListItem* ps_version = new brls::SelectListItem("PlayStation Version",
|
brls::SelectListItem *ps_version = new brls::SelectListItem("PlayStation Version",
|
||||||
{ "PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
|
{"PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
|
||||||
auto ps_version_cb = [this, ps_version](int result)
|
auto ps_version_cb = [this, ps_version](int result) {
|
||||||
{
|
|
||||||
switch(result)
|
switch(result)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -547,9 +536,8 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
ps_version->getValueSelectedEvent()->subscribe(ps_version_cb);
|
ps_version->getValueSelectedEvent()->subscribe(ps_version_cb);
|
||||||
add_host->addView(ps_version);
|
add_host->addView(ps_version);
|
||||||
|
|
||||||
brls::ListItem* register_host = new brls::ListItem("Register");
|
brls::ListItem *register_host = new brls::ListItem("Register");
|
||||||
auto register_host_cb = [this](brls::View * view)
|
auto register_host_cb = [this](brls::View *view) {
|
||||||
{
|
|
||||||
bool err = false;
|
bool err = false;
|
||||||
if(this->remote_display_name.length() <= 0)
|
if(this->remote_display_name.length() <= 0)
|
||||||
{
|
{
|
||||||
|
@ -572,29 +560,31 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
|
||||||
if(err)
|
if(err)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Host * host = this->settings->GetOrCreateHost(&this->remote_display_name);
|
Host *host = this->settings->GetOrCreateHost(&this->remote_display_name);
|
||||||
host->SetHostAddr(this->remote_addr);
|
host->SetHostAddr(this->remote_addr);
|
||||||
host->SetChiakiTarget(this->remote_ps_version);
|
host->SetChiakiTarget(this->remote_ps_version);
|
||||||
|
|
||||||
HostInterface::Register(this->io, host, this->settings);
|
HostInterface::Register(host);
|
||||||
};
|
};
|
||||||
register_host->getClickEvent()->subscribe(register_host_cb);
|
register_host->getClickEvent()->subscribe(register_host_cb);
|
||||||
|
|
||||||
add_host->addView(register_host);
|
add_host->addView(register_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
PSRemotePlay::PSRemotePlay(IO * io, Host * host)
|
PSRemotePlay::PSRemotePlay(Host *host)
|
||||||
: io(io), host(host)
|
: host(host)
|
||||||
{
|
{
|
||||||
|
this->io = IO::GetInstance();
|
||||||
|
|
||||||
// store joycon/touchpad keys
|
// store joycon/touchpad keys
|
||||||
for(int x=0; x < CHIAKI_CONTROLLER_TOUCHES_MAX; x++)
|
for(int x = 0; x < CHIAKI_CONTROLLER_TOUCHES_MAX; x++)
|
||||||
// start touchpad as "untouched"
|
// start touchpad as "untouched"
|
||||||
this->state.touches[x].id = -1;
|
this->state.touches[x].id = -1;
|
||||||
|
|
||||||
// this->base_time=glfwGetTime();
|
// this->base_time=glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSRemotePlay::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
|
void PSRemotePlay::draw(NVGcontext *vg, int x, int y, unsigned width, unsigned height, brls::Style *style, brls::FrameContext *ctx)
|
||||||
{
|
{
|
||||||
this->io->MainLoop(&this->state);
|
this->io->MainLoop(&this->state);
|
||||||
this->host->SendFeedbackState(&this->state);
|
this->host->SendFeedbackState(&this->state);
|
||||||
|
@ -622,4 +612,3 @@ void PSRemotePlay::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned h
|
||||||
PSRemotePlay::~PSRemotePlay()
|
PSRemotePlay::~PSRemotePlay()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,33 +7,33 @@
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
static void InitAudioCB(unsigned int channels, unsigned int rate, void * user)
|
static void InitAudioCB(unsigned int channels, unsigned int rate, void *user)
|
||||||
{
|
{
|
||||||
IO * io = (IO *)user;
|
IO *io = (IO *)user;
|
||||||
io->InitAudioCB(channels, rate);
|
io->InitAudioCB(channels, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool VideoCB(uint8_t * buf, size_t buf_size, void * user)
|
static bool VideoCB(uint8_t *buf, size_t buf_size, void *user)
|
||||||
{
|
{
|
||||||
IO * io = (IO *)user;
|
IO *io = (IO *)user;
|
||||||
return io->VideoCB(buf, buf_size);
|
return io->VideoCB(buf, buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AudioCB(int16_t * buf, size_t samples_count, void * user)
|
static void AudioCB(int16_t *buf, size_t samples_count, void *user)
|
||||||
{
|
{
|
||||||
IO * io = (IO *)user;
|
IO *io = (IO *)user;
|
||||||
io->AudioCB(buf, samples_count);
|
io->AudioCB(buf, samples_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EventCB(ChiakiEvent * event, void * user)
|
static void EventCB(ChiakiEvent *event, void *user)
|
||||||
{
|
{
|
||||||
IO * io = (IO *)user;
|
Host *host = (Host *)user;
|
||||||
io->EventCB(event);
|
host->ConnectionEventCB(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegistEventCB(ChiakiRegistEvent * event, void * user)
|
static void RegistEventCB(ChiakiRegistEvent *event, void *user)
|
||||||
{
|
{
|
||||||
Host * host = (Host *)user;
|
Host *host = (Host *)user;
|
||||||
host->RegistCB(event);
|
host->RegistCB(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ int Host::Register(std::string pin)
|
||||||
return HOST_REGISTER_OK;
|
return HOST_REGISTER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Host::InitSession(IO * user)
|
int Host::InitSession(IO *user)
|
||||||
{
|
{
|
||||||
chiaki_connect_video_profile_preset(&(this->video_profile),
|
chiaki_connect_video_profile_preset(&(this->video_profile),
|
||||||
this->video_resolution, this->video_fps);
|
this->video_resolution, this->video_fps);
|
||||||
|
@ -158,7 +158,7 @@ int Host::InitSession(IO * user)
|
||||||
chiaki_opus_decoder_get_sink(&this->opus_decoder, &audio_sink);
|
chiaki_opus_decoder_get_sink(&this->opus_decoder, &audio_sink);
|
||||||
chiaki_session_set_audio_sink(&(this->session), &audio_sink);
|
chiaki_session_set_audio_sink(&(this->session), &audio_sink);
|
||||||
chiaki_session_set_video_sample_cb(&(this->session), VideoCB, user);
|
chiaki_session_set_video_sample_cb(&(this->session), VideoCB, user);
|
||||||
chiaki_session_set_event_cb(&(this->session), EventCB, user);
|
chiaki_session_set_event_cb(&(this->session), EventCB, this);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +166,7 @@ int Host::FiniSession()
|
||||||
{
|
{
|
||||||
if(this->session_init)
|
if(this->session_init)
|
||||||
{
|
{
|
||||||
|
this->session_init = false;
|
||||||
chiaki_session_join(&this->session);
|
chiaki_session_join(&this->session);
|
||||||
chiaki_session_fini(&this->session);
|
chiaki_session_fini(&this->session);
|
||||||
chiaki_opus_decoder_fini(&this->opus_decoder);
|
chiaki_opus_decoder_fini(&this->opus_decoder);
|
||||||
|
@ -188,13 +189,35 @@ void Host::StartSession()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::SendFeedbackState(ChiakiControllerState * state)
|
void Host::SendFeedbackState(ChiakiControllerState *state)
|
||||||
{
|
{
|
||||||
// send controller/joystick key
|
// send controller/joystick key
|
||||||
chiaki_session_set_controller_state(&this->session, state);
|
chiaki_session_set_controller_state(&this->session, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::RegistCB(ChiakiRegistEvent * event)
|
void Host::ConnectionEventCB(ChiakiEvent *event)
|
||||||
|
{
|
||||||
|
switch(event->type)
|
||||||
|
{
|
||||||
|
case CHIAKI_EVENT_CONNECTED:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
|
||||||
|
if(this->chiaki_event_connected_cb != nullptr)
|
||||||
|
this->chiaki_event_connected_cb();
|
||||||
|
break;
|
||||||
|
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
|
||||||
|
if(this->chiaki_even_login_pin_request_cb != nullptr)
|
||||||
|
this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
|
||||||
|
break;
|
||||||
|
case CHIAKI_EVENT_QUIT:
|
||||||
|
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
|
||||||
|
if(this->chiaki_event_quit_cb != nullptr)
|
||||||
|
this->chiaki_event_quit_cb(&event->quit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Host::RegistCB(ChiakiRegistEvent *event)
|
||||||
{
|
{
|
||||||
// Chiaki callback fuction
|
// Chiaki callback fuction
|
||||||
// fuction called by lib chiaki regist
|
// fuction called by lib chiaki regist
|
||||||
|
@ -205,71 +228,71 @@ void Host::RegistCB(ChiakiRegistEvent * event)
|
||||||
this->registered = false;
|
this->registered = false;
|
||||||
switch(event->type)
|
switch(event->type)
|
||||||
{
|
{
|
||||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_CANCELED:
|
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_CANCELED:
|
||||||
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_CANCELED");
|
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_CANCELED");
|
||||||
if(this->chiaki_regist_event_type_finished_canceled != nullptr)
|
if(this->chiaki_regist_event_type_finished_canceled != nullptr)
|
||||||
|
{
|
||||||
|
this->chiaki_regist_event_type_finished_canceled();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_FAILED:
|
||||||
|
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_FAILED");
|
||||||
|
if(this->chiaki_regist_event_type_finished_failed != nullptr)
|
||||||
|
{
|
||||||
|
this->chiaki_regist_event_type_finished_failed();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_SUCCESS:
|
||||||
{
|
{
|
||||||
this->chiaki_regist_event_type_finished_canceled();
|
ChiakiRegisteredHost *r_host = event->registered_host;
|
||||||
}
|
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_SUCCESS");
|
||||||
break;
|
// copy values form ChiakiRegisteredHost object
|
||||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_FAILED:
|
this->ap_ssid = r_host->ap_ssid;
|
||||||
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_FAILED");
|
this->ap_key = r_host->ap_key;
|
||||||
if(this->chiaki_regist_event_type_finished_failed != nullptr)
|
this->ap_name = r_host->ap_name;
|
||||||
{
|
memcpy(&(this->server_mac), &(r_host->server_mac), sizeof(this->server_mac));
|
||||||
this->chiaki_regist_event_type_finished_failed();
|
this->server_nickname = r_host->server_nickname;
|
||||||
}
|
memcpy(&(this->rp_regist_key), &(r_host->rp_regist_key), sizeof(this->rp_regist_key));
|
||||||
break;
|
this->rp_key_type = r_host->rp_key_type;
|
||||||
case CHIAKI_REGIST_EVENT_TYPE_FINISHED_SUCCESS:
|
memcpy(&(this->rp_key), &(r_host->rp_key), sizeof(this->rp_key));
|
||||||
{
|
// mark host as registered
|
||||||
ChiakiRegisteredHost * r_host = event->registered_host;
|
this->registered = true;
|
||||||
CHIAKI_LOGI(this->log, "Register event CHIAKI_REGIST_EVENT_TYPE_FINISHED_SUCCESS");
|
this->rp_key_data = true;
|
||||||
// copy values form ChiakiRegisteredHost object
|
CHIAKI_LOGI(this->log, "Register Success %s", this->host_name.c_str());
|
||||||
this->ap_ssid = r_host->ap_ssid;
|
|
||||||
this->ap_key = r_host->ap_key;
|
|
||||||
this->ap_name = r_host->ap_name;
|
|
||||||
memcpy(&(this->server_mac), &(r_host->server_mac), sizeof(this->server_mac));
|
|
||||||
this->server_nickname = r_host->server_nickname;
|
|
||||||
memcpy(&(this->rp_regist_key), &(r_host->rp_regist_key), sizeof(this->rp_regist_key));
|
|
||||||
this->rp_key_type = r_host->rp_key_type;
|
|
||||||
memcpy(&(this->rp_key), &(r_host->rp_key), sizeof(this->rp_key));
|
|
||||||
// mark host as registered
|
|
||||||
this->registered = true;
|
|
||||||
this->rp_key_data = true;
|
|
||||||
CHIAKI_LOGI(this->log, "Register Success %s", this->host_name.c_str());
|
|
||||||
|
|
||||||
if(this->chiaki_regist_event_type_finished_success != nullptr)
|
if(this->chiaki_regist_event_type_finished_success != nullptr)
|
||||||
this->chiaki_regist_event_type_finished_success();
|
this->chiaki_regist_event_type_finished_success();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// close registration socket
|
// close registration socket
|
||||||
chiaki_regist_stop(&this->regist);
|
chiaki_regist_stop(&this->regist);
|
||||||
chiaki_regist_fini(&this->regist);
|
chiaki_regist_fini(&this->regist);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Host::GetVideoResolution(int * ret_width, int * ret_height)
|
bool Host::GetVideoResolution(int *ret_width, int *ret_height)
|
||||||
{
|
{
|
||||||
switch(this->video_resolution)
|
switch(this->video_resolution)
|
||||||
{
|
{
|
||||||
case CHIAKI_VIDEO_RESOLUTION_PRESET_360p:
|
case CHIAKI_VIDEO_RESOLUTION_PRESET_360p:
|
||||||
*ret_width = 640;
|
*ret_width = 640;
|
||||||
*ret_height = 360;
|
*ret_height = 360;
|
||||||
break;
|
break;
|
||||||
case CHIAKI_VIDEO_RESOLUTION_PRESET_540p:
|
case CHIAKI_VIDEO_RESOLUTION_PRESET_540p:
|
||||||
*ret_width = 950;
|
*ret_width = 950;
|
||||||
*ret_height = 540;
|
*ret_height = 540;
|
||||||
break;
|
break;
|
||||||
case CHIAKI_VIDEO_RESOLUTION_PRESET_720p:
|
case CHIAKI_VIDEO_RESOLUTION_PRESET_720p:
|
||||||
*ret_width = 1280;
|
*ret_width = 1280;
|
||||||
*ret_height = 720;
|
*ret_height = 720;
|
||||||
break;
|
break;
|
||||||
case CHIAKI_VIDEO_RESOLUTION_PRESET_1080p:
|
case CHIAKI_VIDEO_RESOLUTION_PRESET_1080p:
|
||||||
*ret_width = 1920;
|
*ret_width = 1920;
|
||||||
*ret_height = 1080;
|
*ret_height = 1080;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -314,6 +337,21 @@ void Host::SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist
|
||||||
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
|
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Host::SetEventConnectedCallback(std::function<void()> chiaki_event_connected_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_event_connected_cb = chiaki_event_connected_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Host::SetEventLoginPinRequestCallback(std::function<void(bool)> chiaki_even_login_pin_request_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_even_login_pin_request_cb = chiaki_even_login_pin_request_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Host::SetEventQuitCallback(std::function<void(ChiakiQuitEvent *)> chiaki_event_quit_cb)
|
||||||
|
{
|
||||||
|
this->chiaki_event_quit_cb = chiaki_event_quit_cb;
|
||||||
|
}
|
||||||
|
|
||||||
bool Host::IsRegistered()
|
bool Host::IsRegistered()
|
||||||
{
|
{
|
||||||
return this->registered;
|
return this->registered;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
// https://github.com/torvalds/linux/blob/41ba50b0572e90ed3d24fe4def54567e9050bc47/drivers/hid/hid-sony.c#L2742
|
// https://github.com/torvalds/linux/blob/41ba50b0572e90ed3d24fe4def54567e9050bc47/drivers/hid/hid-sony.c#L2742
|
||||||
#define DS4_TRACKPAD_MAX_X 1920
|
#define DS4_TRACKPAD_MAX_X 1920
|
||||||
|
@ -24,7 +25,7 @@
|
||||||
// use OpenGl to decode YUV
|
// use OpenGl to decode YUV
|
||||||
// the aim is to spare CPU load on nintendo switch
|
// the aim is to spare CPU load on nintendo switch
|
||||||
|
|
||||||
static const char* shader_vert_glsl = R"glsl(
|
static const char *shader_vert_glsl = R"glsl(
|
||||||
#version 150 core
|
#version 150 core
|
||||||
in vec2 pos_attr;
|
in vec2 pos_attr;
|
||||||
out vec2 uv_var;
|
out vec2 uv_var;
|
||||||
|
@ -60,12 +61,23 @@ static const float vert_pos[] = {
|
||||||
0.0f, 0.0f,
|
0.0f, 0.0f,
|
||||||
0.0f, 1.0f,
|
0.0f, 1.0f,
|
||||||
1.0f, 0.0f,
|
1.0f, 0.0f,
|
||||||
1.0f, 1.0f
|
1.0f, 1.0f};
|
||||||
};
|
|
||||||
|
|
||||||
IO::IO(ChiakiLog * log)
|
IO *IO::instance = nullptr;
|
||||||
: log(log)
|
|
||||||
|
IO *IO::GetInstance()
|
||||||
{
|
{
|
||||||
|
if(instance == nullptr)
|
||||||
|
{
|
||||||
|
instance = new IO;
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
IO::IO()
|
||||||
|
{
|
||||||
|
Settings *settings = Settings::GetInstance();
|
||||||
|
this->log = settings->GetLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
IO::~IO()
|
IO::~IO()
|
||||||
|
@ -99,11 +111,15 @@ void IO::SetMesaConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_OPENGL
|
#ifdef DEBUG_OPENGL
|
||||||
#define D(x){ (x); CheckGLError(__func__, __FILE__, __LINE__); }
|
#define D(x) \
|
||||||
void IO::CheckGLError(const char* func, const char* file, int line)
|
{ \
|
||||||
|
(x); \
|
||||||
|
CheckGLError(__func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
|
void IO::CheckGLError(const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLenum err;
|
GLenum err;
|
||||||
while( (err = glGetError()) != GL_NO_ERROR )
|
while((err = glGetError()) != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(this->log, "glGetError: %x function: %s from %s line %d", err, func, file, line);
|
CHIAKI_LOGE(this->log, "glGetError: %x function: %s from %s line %d", err, func, file, line);
|
||||||
//GL_INVALID_VALUE, 0x0501
|
//GL_INVALID_VALUE, 0x0501
|
||||||
|
@ -115,37 +131,51 @@ void IO::CheckGLError(const char* func, const char* file, int line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DS(x){ DumpShaderError(x, __func__, __FILE__, __LINE__); }
|
#define DS(x) \
|
||||||
void IO::DumpShaderError(GLuint shader, const char* func, const char* file, int line)
|
{ \
|
||||||
|
DumpShaderError(x, __func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
|
void IO::DumpShaderError(GLuint shader, const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLchar str[512+1];
|
GLchar str[512 + 1];
|
||||||
GLsizei len = 0;
|
GLsizei len = 0;
|
||||||
glGetShaderInfoLog(shader, 512, &len, str);
|
glGetShaderInfoLog(shader, 512, &len, str);
|
||||||
if (len > 512) len = 512;
|
if(len > 512)
|
||||||
|
len = 512;
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
CHIAKI_LOGE(this->log, "glGetShaderInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
CHIAKI_LOGE(this->log, "glGetShaderInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DP(x){ DumpProgramError(x, __func__, __FILE__, __LINE__); }
|
#define DP(x) \
|
||||||
void IO::DumpProgramError(GLuint prog, const char* func, const char* file, int line)
|
{ \
|
||||||
|
DumpProgramError(x, __func__, __FILE__, __LINE__); \
|
||||||
|
}
|
||||||
|
void IO::DumpProgramError(GLuint prog, const char *func, const char *file, int line)
|
||||||
{
|
{
|
||||||
GLchar str[512+1];
|
GLchar str[512 + 1];
|
||||||
GLsizei len = 0;
|
GLsizei len = 0;
|
||||||
glGetProgramInfoLog(prog, 512, &len, str);
|
glGetProgramInfoLog(prog, 512, &len, str);
|
||||||
if (len > 512) len = 512;
|
if(len > 512)
|
||||||
|
len = 512;
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
CHIAKI_LOGE(this->log, "glGetProgramInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
CHIAKI_LOGE(this->log, "glGetProgramInfoLog: %s function: %s from %s line %d", str, func, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// do nothing
|
// do nothing
|
||||||
#define D(x){ (x); }
|
#define D(x) \
|
||||||
#define DS(x){ }
|
{ \
|
||||||
#define DP(x){ }
|
(x); \
|
||||||
|
}
|
||||||
|
#define DS(x) \
|
||||||
|
{ \
|
||||||
|
}
|
||||||
|
#define DP(x) \
|
||||||
|
{ \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool IO::VideoCB(uint8_t *buf, size_t buf_size)
|
||||||
bool IO::VideoCB(uint8_t * buf, size_t buf_size)
|
|
||||||
{
|
{
|
||||||
// callback function to decode video buffer
|
// callback function to decode video buffer
|
||||||
|
|
||||||
|
@ -153,7 +183,7 @@ bool IO::VideoCB(uint8_t * buf, size_t buf_size)
|
||||||
av_init_packet(&packet);
|
av_init_packet(&packet);
|
||||||
packet.data = buf;
|
packet.data = buf;
|
||||||
packet.size = buf_size;
|
packet.size = buf_size;
|
||||||
AVFrame * frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
if(!frame)
|
if(!frame)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(this->log, "UpdateFrame Failed to alloc AVFrame");
|
CHIAKI_LOGE(this->log, "UpdateFrame Failed to alloc AVFrame");
|
||||||
|
@ -204,7 +234,6 @@ send_packet:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IO::InitAudioCB(unsigned int channels, unsigned int rate)
|
void IO::InitAudioCB(unsigned int channels, unsigned int rate)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec want, have, test;
|
SDL_AudioSpec want, have, test;
|
||||||
|
@ -241,12 +270,12 @@ void IO::InitAudioCB(unsigned int channels, unsigned int rate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IO::AudioCB(int16_t * buf, size_t samples_count)
|
void IO::AudioCB(int16_t *buf, size_t samples_count)
|
||||||
{
|
{
|
||||||
for(int x=0; x < samples_count*2; x++)
|
for(int x = 0; x < samples_count * 2; x++)
|
||||||
{
|
{
|
||||||
// boost audio volume
|
// boost audio volume
|
||||||
int sample = buf[x]*1.80;
|
int sample = buf[x] * 1.80;
|
||||||
// Hard clipping (audio compression)
|
// Hard clipping (audio compression)
|
||||||
// truncate value that overflow/underflow int16
|
// truncate value that overflow/underflow int16
|
||||||
if(sample > INT16_MAX)
|
if(sample > INT16_MAX)
|
||||||
|
@ -260,9 +289,9 @@ void IO::AudioCB(int16_t * buf, size_t samples_count)
|
||||||
CHIAKI_LOGD(this->log, "Audio Hard clipping INT16_MIN > %d", sample);
|
CHIAKI_LOGD(this->log, "Audio Hard clipping INT16_MIN > %d", sample);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
buf[x] = (int16_t) sample;
|
buf[x] = (int16_t)sample;
|
||||||
}
|
}
|
||||||
int success = SDL_QueueAudio(this->sdl_audio_device_id, buf, sizeof(int16_t)*samples_count*2);
|
int success = SDL_QueueAudio(this->sdl_audio_device_id, buf, sizeof(int16_t) * samples_count * 2);
|
||||||
if(success != 0)
|
if(success != 0)
|
||||||
CHIAKI_LOGE(this->log, "SDL_QueueAudio failed: %s\n", SDL_GetError());
|
CHIAKI_LOGE(this->log, "SDL_QueueAudio failed: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
@ -289,33 +318,6 @@ bool IO::InitVideo(int video_width, int video_height, int screen_width, int scre
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IO::EventCB(ChiakiEvent *event)
|
|
||||||
{
|
|
||||||
switch(event->type)
|
|
||||||
{
|
|
||||||
case CHIAKI_EVENT_CONNECTED:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_CONNECTED");
|
|
||||||
if(this->chiaki_event_connected_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_event_connected_cb();
|
|
||||||
else
|
|
||||||
this->quit = false;
|
|
||||||
break;
|
|
||||||
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_LOGIN_PIN_REQUEST");
|
|
||||||
if(this->chiaki_even_login_pin_request_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_even_login_pin_request_cb(event->login_pin_request.pin_incorrect);
|
|
||||||
break;
|
|
||||||
case CHIAKI_EVENT_QUIT:
|
|
||||||
CHIAKI_LOGI(this->log, "EventCB CHIAKI_EVENT_QUIT");
|
|
||||||
if(this->chiaki_event_quit_cb != nullptr)
|
|
||||||
this->quit = !this->chiaki_event_quit_cb(&event->quit);
|
|
||||||
else
|
|
||||||
this->quit = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool IO::FreeVideo()
|
bool IO::FreeVideo()
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
@ -344,12 +346,12 @@ bool IO::ReadUserKeyboard(char *buffer, size_t buffer_size)
|
||||||
SwkbdConfig kbd;
|
SwkbdConfig kbd;
|
||||||
Result rc = swkbdCreate(&kbd, 0);
|
Result rc = swkbdCreate(&kbd, 0);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if(R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
swkbdConfigMakePresetDefault(&kbd);
|
swkbdConfigMakePresetDefault(&kbd);
|
||||||
rc = swkbdShow(&kbd, buffer, buffer_size);
|
rc = swkbdShow(&kbd, buffer, buffer_size);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc))
|
if(R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
CHIAKI_LOGI(this->log, "Got user input: %s\n", buffer);
|
CHIAKI_LOGI(this->log, "Got user input: %s\n", buffer);
|
||||||
}
|
}
|
||||||
|
@ -377,7 +379,7 @@ bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if(!touch_count)
|
if(!touch_count)
|
||||||
{
|
{
|
||||||
for(int i=0; i < CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
for(int i = 0; i < CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||||
{
|
{
|
||||||
if(state->touches[i].id != -1)
|
if(state->touches[i].id != -1)
|
||||||
{
|
{
|
||||||
|
@ -393,7 +395,7 @@ bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
||||||
}
|
}
|
||||||
|
|
||||||
touchPosition touch;
|
touchPosition touch;
|
||||||
for(int i=0; i < touch_count && i < CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
for(int i = 0; i < touch_count && i < CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||||
{
|
{
|
||||||
hidTouchRead(&touch, i);
|
hidTouchRead(&touch, i);
|
||||||
|
|
||||||
|
@ -403,11 +405,10 @@ bool IO::ReadGameTouchScreen(ChiakiControllerState *state)
|
||||||
uint16_t y = touch.py * (DS4_TRACKPAD_MAX_Y / SWITCH_TOUCHSCREEN_MAX_Y);
|
uint16_t y = touch.py * (DS4_TRACKPAD_MAX_Y / SWITCH_TOUCHSCREEN_MAX_Y);
|
||||||
|
|
||||||
// use nintendo switch border's 5% to
|
// use nintendo switch border's 5% to
|
||||||
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95)
|
if(x <= (SWITCH_TOUCHSCREEN_MAX_X * 0.05) || x >= (SWITCH_TOUCHSCREEN_MAX_X * 0.95) || y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
|
||||||
|| y <= (SWITCH_TOUCHSCREEN_MAX_Y * 0.05) || y >= (SWITCH_TOUCHSCREEN_MAX_Y * 0.95))
|
|
||||||
{
|
{
|
||||||
state->buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD; // touchscreen
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_TOUCHPAD; // touchscreen
|
||||||
// printf("CHIAKI_CONTROLLER_BUTTON_TOUCHPAD\n");
|
// printf("CHIAKI_CONTROLLER_BUTTON_TOUCHPAD\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -459,7 +460,7 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
|
||||||
else
|
else
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
else if (event->jaxis.which == 1)
|
else if(event->jaxis.which == 1)
|
||||||
{
|
{
|
||||||
// right joystick
|
// right joystick
|
||||||
if(event->jaxis.axis == 0)
|
if(event->jaxis.axis == 0)
|
||||||
|
@ -479,26 +480,58 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
|
||||||
// event->jbutton.which, event->jbutton.button);
|
// event->jbutton.which, event->jbutton.button);
|
||||||
switch(event->jbutton.button)
|
switch(event->jbutton.button)
|
||||||
{
|
{
|
||||||
case 0: state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
|
case 0:
|
||||||
case 1: state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_MOON;
|
||||||
case 2: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
|
break; // KEY_A
|
||||||
case 3: state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
|
case 1:
|
||||||
case 12: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_CROSS;
|
||||||
case 14: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
|
break; // KEY_B
|
||||||
case 13: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
|
case 2:
|
||||||
case 15: state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
|
||||||
case 6: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
|
break; // KEY_X
|
||||||
case 7: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
|
case 3:
|
||||||
case 8: state->l2_state = 0xff; break; // KEY_ZL
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_BOX;
|
||||||
case 9: state->r2_state = 0xff; break; // KEY_ZR
|
break; // KEY_Y
|
||||||
case 4: state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
|
case 12:
|
||||||
case 5: state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
|
||||||
case 10: state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
|
break; // KEY_DLEFT
|
||||||
|
case 14:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||||
|
break; // KEY_DRIGHT
|
||||||
|
case 13:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
|
||||||
|
break; // KEY_DUP
|
||||||
|
case 15:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
|
||||||
|
break; // KEY_DDOWN
|
||||||
|
case 6:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L1;
|
||||||
|
break; // KEY_L
|
||||||
|
case 7:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R1;
|
||||||
|
break; // KEY_R
|
||||||
|
case 8:
|
||||||
|
state->l2_state = 0xff;
|
||||||
|
break; // KEY_ZL
|
||||||
|
case 9:
|
||||||
|
state->r2_state = 0xff;
|
||||||
|
break; // KEY_ZR
|
||||||
|
case 4:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_L3;
|
||||||
|
break; // KEY_LSTICK
|
||||||
|
case 5:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_R3;
|
||||||
|
break; // KEY_RSTICK
|
||||||
|
case 10:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
|
||||||
|
break; // KEY_PLUS
|
||||||
// FIXME
|
// FIXME
|
||||||
// case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
// case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
||||||
case 11: state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
|
case 11:
|
||||||
|
state->buttons |= CHIAKI_CONTROLLER_BUTTON_PS;
|
||||||
|
break; // KEY_MINUS
|
||||||
default:
|
default:
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
|
@ -506,25 +539,57 @@ bool IO::ReadGameKeys(SDL_Event *event, ChiakiControllerState *state)
|
||||||
// event->jbutton.which, event->jbutton.button);
|
// event->jbutton.which, event->jbutton.button);
|
||||||
switch(event->jbutton.button)
|
switch(event->jbutton.button)
|
||||||
{
|
{
|
||||||
case 0: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON; break; // KEY_A
|
case 0:
|
||||||
case 1: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS; break; // KEY_B
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_MOON;
|
||||||
case 2: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID; break; // KEY_X
|
break; // KEY_A
|
||||||
case 3: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX; break; // KEY_Y
|
case 1:
|
||||||
case 12: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT; break; // KEY_DLEFT
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_CROSS;
|
||||||
case 14: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT; break; // KEY_DRIGHT
|
break; // KEY_B
|
||||||
case 13: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP; break; // KEY_DUP
|
case 2:
|
||||||
case 15: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN; break; // KEY_DDOWN
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PYRAMID;
|
||||||
case 6: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1; break; // KEY_L
|
break; // KEY_X
|
||||||
case 7: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1; break; // KEY_R
|
case 3:
|
||||||
case 8: state->l2_state = 0x00; break; // KEY_ZL
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_BOX;
|
||||||
case 9: state->r2_state = 0x00; break; // KEY_ZR
|
break; // KEY_Y
|
||||||
case 4: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3; break; // KEY_LSTICK
|
case 12:
|
||||||
case 5: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3; break; // KEY_RSTICK
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT;
|
||||||
case 10: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS; break; // KEY_PLUS
|
break; // KEY_DLEFT
|
||||||
//case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
case 14:
|
||||||
case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS; break; // KEY_MINUS
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT;
|
||||||
|
break; // KEY_DRIGHT
|
||||||
|
case 13:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_UP;
|
||||||
|
break; // KEY_DUP
|
||||||
|
case 15:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN;
|
||||||
|
break; // KEY_DDOWN
|
||||||
|
case 6:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L1;
|
||||||
|
break; // KEY_L
|
||||||
|
case 7:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R1;
|
||||||
|
break; // KEY_R
|
||||||
|
case 8:
|
||||||
|
state->l2_state = 0x00;
|
||||||
|
break; // KEY_ZL
|
||||||
|
case 9:
|
||||||
|
state->r2_state = 0x00;
|
||||||
|
break; // KEY_ZR
|
||||||
|
case 4:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_L3;
|
||||||
|
break; // KEY_LSTICK
|
||||||
|
case 5:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_R3;
|
||||||
|
break; // KEY_RSTICK
|
||||||
|
case 10:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_OPTIONS;
|
||||||
|
break; // KEY_PLUS
|
||||||
|
//case 11: state->buttons ^= CHIAKI_CONTROLLER_BUTTON_SHARE; break; // KEY_MINUS
|
||||||
|
case 11:
|
||||||
|
state->buttons ^= CHIAKI_CONTROLLER_BUTTON_PS;
|
||||||
|
break; // KEY_MINUS
|
||||||
default:
|
default:
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -582,7 +647,7 @@ bool IO::InitOpenGlTextures()
|
||||||
D(glGenTextures(PLANES_COUNT, this->tex));
|
D(glGenTextures(PLANES_COUNT, this->tex));
|
||||||
D(glGenBuffers(PLANES_COUNT, this->pbo));
|
D(glGenBuffers(PLANES_COUNT, this->pbo));
|
||||||
uint8_t uv_default[] = {0x7f, 0x7f};
|
uint8_t uv_default[] = {0x7f, 0x7f};
|
||||||
for(int i=0; i < PLANES_COUNT; i++)
|
for(int i = 0; i < PLANES_COUNT; i++)
|
||||||
{
|
{
|
||||||
D(glBindTexture(GL_TEXTURE_2D, this->tex[i]));
|
D(glBindTexture(GL_TEXTURE_2D, this->tex[i]));
|
||||||
D(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
D(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
|
@ -595,7 +660,7 @@ bool IO::InitOpenGlTextures()
|
||||||
D(glUseProgram(this->prog));
|
D(glUseProgram(this->prog));
|
||||||
// bind only as many planes as we need
|
// bind only as many planes as we need
|
||||||
const char *plane_names[] = {"plane1", "plane2", "plane3"};
|
const char *plane_names[] = {"plane1", "plane2", "plane3"};
|
||||||
for(int i=0; i < PLANES_COUNT; i++)
|
for(int i = 0; i < PLANES_COUNT; i++)
|
||||||
D(glUniform1i(glGetUniformLocation(this->prog, plane_names[i]), i));
|
D(glUniform1i(glGetUniformLocation(this->prog, plane_names[i]), i));
|
||||||
|
|
||||||
D(glGenVertexArrays(1, &this->vao));
|
D(glGenVertexArrays(1, &this->vao));
|
||||||
|
@ -615,14 +680,14 @@ bool IO::InitOpenGlTextures()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint IO::CreateAndCompileShader(GLenum type, const char* source)
|
GLuint IO::CreateAndCompileShader(GLenum type, const char *source)
|
||||||
{
|
{
|
||||||
GLint success;
|
GLint success;
|
||||||
GLchar msg[512];
|
GLchar msg[512];
|
||||||
|
|
||||||
GLuint handle;
|
GLuint handle;
|
||||||
D(handle = glCreateShader(type));
|
D(handle = glCreateShader(type));
|
||||||
if (!handle)
|
if(!handle)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(this->log, "%u: cannot create shader", type);
|
CHIAKI_LOGE(this->log, "%u: cannot create shader", type);
|
||||||
DP(this->prog);
|
DP(this->prog);
|
||||||
|
@ -632,7 +697,7 @@ GLuint IO::CreateAndCompileShader(GLenum type, const char* source)
|
||||||
D(glCompileShader(handle));
|
D(glCompileShader(handle));
|
||||||
D(glGetShaderiv(handle, GL_COMPILE_STATUS, &success));
|
D(glGetShaderiv(handle, GL_COMPILE_STATUS, &success));
|
||||||
|
|
||||||
if (!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
D(glGetShaderInfoLog(handle, sizeof(msg), nullptr, msg));
|
D(glGetShaderInfoLog(handle, sizeof(msg), nullptr, msg));
|
||||||
CHIAKI_LOGE(this->log, "%u: %s\n", type, msg);
|
CHIAKI_LOGE(this->log, "%u: %s\n", type, msg);
|
||||||
|
@ -658,7 +723,7 @@ bool IO::InitOpenGlShader()
|
||||||
|
|
||||||
GLint success;
|
GLint success;
|
||||||
D(glGetProgramiv(this->prog, GL_LINK_STATUS, &success));
|
D(glGetProgramiv(this->prog, GL_LINK_STATUS, &success));
|
||||||
if (!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
glGetProgramInfoLog(this->prog, sizeof(buf), nullptr, buf);
|
glGetProgramInfoLog(this->prog, sizeof(buf), nullptr, buf);
|
||||||
|
@ -672,15 +737,15 @@ bool IO::InitOpenGlShader()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void IO::SetOpenGlYUVPixels(AVFrame * frame)
|
inline void IO::SetOpenGlYUVPixels(AVFrame *frame)
|
||||||
{
|
{
|
||||||
D(glUseProgram(this->prog));
|
D(glUseProgram(this->prog));
|
||||||
|
|
||||||
int planes[][3] = {
|
int planes[][3] = {
|
||||||
// { width_divide, height_divider, data_per_pixel }
|
// { width_divide, height_divider, data_per_pixel }
|
||||||
{ 1, 1, 1 }, // Y
|
{1, 1, 1}, // Y
|
||||||
{ 2, 2, 1 }, // U
|
{2, 2, 1}, // U
|
||||||
{ 2, 2, 1 } // V
|
{2, 2, 1} // V
|
||||||
};
|
};
|
||||||
|
|
||||||
this->mtx.lock();
|
this->mtx.lock();
|
||||||
|
@ -689,7 +754,7 @@ inline void IO::SetOpenGlYUVPixels(AVFrame * frame)
|
||||||
int width = frame->width / planes[i][0];
|
int width = frame->width / planes[i][0];
|
||||||
int height = frame->height / planes[i][1];
|
int height = frame->height / planes[i][1];
|
||||||
int size = width * height * planes[i][2];
|
int size = width * height * planes[i][2];
|
||||||
uint8_t * buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
D(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->pbo[i]));
|
D(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->pbo[i]));
|
||||||
D(glBufferData(GL_PIXEL_UNPACK_BUFFER, size, nullptr, GL_STREAM_DRAW));
|
D(glBufferData(GL_PIXEL_UNPACK_BUFFER, size, nullptr, GL_STREAM_DRAW));
|
||||||
|
@ -700,7 +765,7 @@ inline void IO::SetOpenGlYUVPixels(AVFrame * frame)
|
||||||
D(glGetBufferParameteriv(GL_PIXEL_UNPACK_BUFFER, GL_BUFFER_SIZE, &data));
|
D(glGetBufferParameteriv(GL_PIXEL_UNPACK_BUFFER, GL_BUFFER_SIZE, &data));
|
||||||
CHIAKI_LOGE(this->log, "AVOpenGLFrame failed to map PBO");
|
CHIAKI_LOGE(this->log, "AVOpenGLFrame failed to map PBO");
|
||||||
CHIAKI_LOGE(this->log, "Info buf == %p. size %d frame %d * %d, divs %d, %d, pbo %d GL_BUFFER_SIZE %x",
|
CHIAKI_LOGE(this->log, "Info buf == %p. size %d frame %d * %d, divs %d, %d, pbo %d GL_BUFFER_SIZE %x",
|
||||||
buf, size, frame->width, frame->height, planes[i][0], planes[i][1], pbo[i], data);
|
buf, size, frame->width, frame->height, planes[i][0], planes[i][1], pbo[i], data);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,10 +777,10 @@ inline void IO::SetOpenGlYUVPixels(AVFrame * frame)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// UV
|
// UV
|
||||||
for(int l=0; l<height; l++)
|
for(int l = 0; l < height; l++)
|
||||||
memcpy(buf + width * l * planes[i][2],
|
memcpy(buf + width * l * planes[i][2],
|
||||||
frame->data[i] + frame->linesize[i] * l,
|
frame->data[i] + frame->linesize[i] * l,
|
||||||
width * planes[i][2]);
|
width * planes[i][2]);
|
||||||
}
|
}
|
||||||
D(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER));
|
D(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER));
|
||||||
D(glBindTexture(GL_TEXTURE_2D, tex[i]));
|
D(glBindTexture(GL_TEXTURE_2D, tex[i]));
|
||||||
|
@ -736,7 +801,7 @@ inline void IO::OpenGlDraw()
|
||||||
//avcodec_flush_buffers(this->codec_context);
|
//avcodec_flush_buffers(this->codec_context);
|
||||||
D(glBindVertexArray(this->vao));
|
D(glBindVertexArray(this->vao));
|
||||||
|
|
||||||
for(int i=0; i< PLANES_COUNT; i++)
|
for(int i = 0; i < PLANES_COUNT; i++)
|
||||||
{
|
{
|
||||||
D(glActiveTexture(GL_TEXTURE0 + i));
|
D(glActiveTexture(GL_TEXTURE0 + i));
|
||||||
D(glBindTexture(GL_TEXTURE_2D, this->tex[i]));
|
D(glBindTexture(GL_TEXTURE_2D, this->tex[i]));
|
||||||
|
@ -753,10 +818,10 @@ bool IO::InitJoystick()
|
||||||
// open CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2
|
// open CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2
|
||||||
// when railed, both joycons are mapped to joystick #0,
|
// when railed, both joycons are mapped to joystick #0,
|
||||||
// else joycons are individually mapped to joystick #0, joystick #1, ...
|
// else joycons are individually mapped to joystick #0, joystick #1, ...
|
||||||
for (int i = 0; i < SDL_JOYSTICK_COUNT; i++)
|
for(int i = 0; i < SDL_JOYSTICK_COUNT; i++)
|
||||||
{
|
{
|
||||||
this->sdl_joystick_ptr[i] = SDL_JoystickOpen(i);
|
this->sdl_joystick_ptr[i] = SDL_JoystickOpen(i);
|
||||||
if (sdl_joystick_ptr[i] == nullptr)
|
if(sdl_joystick_ptr[i] == nullptr)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(this->log, "SDL_JoystickOpen: %s\n", SDL_GetError());
|
CHIAKI_LOGE(this->log, "SDL_JoystickOpen: %s\n", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
|
@ -767,7 +832,7 @@ bool IO::InitJoystick()
|
||||||
|
|
||||||
bool IO::FreeJoystick()
|
bool IO::FreeJoystick()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SDL_JOYSTICK_COUNT; i++)
|
for(int i = 0; i < SDL_JOYSTICK_COUNT; i++)
|
||||||
{
|
{
|
||||||
if(SDL_JoystickGetAttached(sdl_joystick_ptr[i]))
|
if(SDL_JoystickGetAttached(sdl_joystick_ptr[i]))
|
||||||
SDL_JoystickClose(sdl_joystick_ptr[i]);
|
SDL_JoystickClose(sdl_joystick_ptr[i]);
|
||||||
|
@ -775,7 +840,7 @@ bool IO::FreeJoystick()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IO::MainLoop(ChiakiControllerState * state)
|
bool IO::MainLoop(ChiakiControllerState *state)
|
||||||
{
|
{
|
||||||
D(glUseProgram(this->prog));
|
D(glUseProgram(this->prog));
|
||||||
|
|
||||||
|
@ -798,4 +863,3 @@ bool IO::MainLoop(ChiakiControllerState * state)
|
||||||
|
|
||||||
return !this->quit;
|
return !this->quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,9 +134,8 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// build sdl OpenGl and AV decoders graphical interface
|
// build sdl OpenGl and AV decoders graphical interface
|
||||||
IO io = IO(log); // open Input Output class
|
|
||||||
DiscoveryManager discoverymanager = DiscoveryManager();
|
DiscoveryManager discoverymanager = DiscoveryManager();
|
||||||
MainApplication app = MainApplication(&discoverymanager, &io);
|
MainApplication app = MainApplication(&discoverymanager);
|
||||||
app.Load();
|
app.Load();
|
||||||
|
|
||||||
CHIAKI_LOGI(log, "Quit applet");
|
CHIAKI_LOGI(log, "Quit applet");
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
#if defined(__SWITCH__) && !defined(CHIAKI_ENABLE_SWITCH_NXLINK)
|
#if defined(__SWITCH__)
|
||||||
// null log for switch version
|
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE ^ CHIAKI_LOG_DEBUG, chiaki_log_cb_print, NULL);
|
||||||
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
|
||||||
#else
|
#else
|
||||||
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
chiaki_log_init(&this->log, CHIAKI_LOG_ALL, chiaki_log_cb_print, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue