mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -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 <thread>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include "host.h"
|
||||
#include "settings.h"
|
||||
#include "discoverymanager.h"
|
||||
#include "host.h"
|
||||
#include "io.h"
|
||||
#include "settings.h"
|
||||
|
||||
class HostInterface : public brls::List
|
||||
{
|
||||
private:
|
||||
IO * io;
|
||||
Host * host;
|
||||
Settings * settings;
|
||||
IO *io;
|
||||
Host *host;
|
||||
Settings *settings;
|
||||
bool connected = false;
|
||||
|
||||
public:
|
||||
HostInterface(IO * io, Host * host, Settings * settings);
|
||||
HostInterface(Host *host);
|
||||
~HostInterface();
|
||||
|
||||
static void Register(IO * io, Host * host,
|
||||
Settings * settings, std::function<void()> success_cb = nullptr);
|
||||
static void Register(Host *host, std::function<void()> success_cb = nullptr);
|
||||
void Register();
|
||||
void Wakeup(brls::View * view);
|
||||
void Connect(brls::View * view);
|
||||
void Wakeup(brls::View *view);
|
||||
void Connect(brls::View *view);
|
||||
void ConnectSession();
|
||||
void Disconnect();
|
||||
bool Stream();
|
||||
bool CloseStream(ChiakiQuitEvent * quit);
|
||||
void Stream();
|
||||
void CloseStream(ChiakiQuitEvent *quit);
|
||||
};
|
||||
|
||||
class MainApplication
|
||||
{
|
||||
private:
|
||||
Settings * settings;
|
||||
ChiakiLog * log;
|
||||
DiscoveryManager * discoverymanager;
|
||||
IO * io;
|
||||
brls::TabFrame * rootFrame;
|
||||
Settings *settings;
|
||||
ChiakiLog *log;
|
||||
DiscoveryManager *discoverymanager;
|
||||
IO *io;
|
||||
brls::TabFrame *rootFrame;
|
||||
std::map<Host *, HostInterface *> host_menuitems;
|
||||
// add_host local settings
|
||||
std::string remote_display_name = "";
|
||||
std::string remote_addr = "";
|
||||
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 *);
|
||||
public:
|
||||
MainApplication(DiscoveryManager * discoverymanager, IO * io);
|
||||
|
||||
public:
|
||||
MainApplication(DiscoveryManager *discoverymanager);
|
||||
~MainApplication();
|
||||
bool Load();
|
||||
};
|
||||
|
@ -67,24 +67,23 @@ class MainApplication
|
|||
class PSRemotePlay : public brls::View
|
||||
{
|
||||
private:
|
||||
brls::AppletFrame * frame;
|
||||
brls::AppletFrame *frame;
|
||||
// to display stream on screen
|
||||
IO * io;
|
||||
IO *io;
|
||||
// to send gamepad inputs
|
||||
Host * host;
|
||||
brls::Label * label;
|
||||
ChiakiControllerState state = { 0 };
|
||||
Host *host;
|
||||
brls::Label *label;
|
||||
ChiakiControllerState state = {0};
|
||||
// FPS calculation
|
||||
// double base_time;
|
||||
// int frame_counter = 0;
|
||||
// int fps = 0;
|
||||
|
||||
public:
|
||||
PSRemotePlay(IO * io, Host * host);
|
||||
PSRemotePlay(Host *host);
|
||||
~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
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
class DiscoveryManager;
|
||||
static void Discovery(ChiakiDiscoveryHost *, void *);
|
||||
static void InitAudioCB(unsigned int channels, unsigned int rate, 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 RegistEventCB(ChiakiRegistEvent * event, void * user);
|
||||
static void EventCB(ChiakiEvent * event, 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 void AudioCB(int16_t *buf, size_t samples_count, void *user);
|
||||
static void EventCB(ChiakiEvent *event, void *user);
|
||||
static void RegistEventCB(ChiakiRegistEvent *event, void *user);
|
||||
|
||||
enum RegistError
|
||||
{
|
||||
|
@ -37,8 +37,8 @@ class Settings;
|
|||
class Host
|
||||
{
|
||||
private:
|
||||
ChiakiLog * log = nullptr;
|
||||
Settings * settings = nullptr;
|
||||
ChiakiLog *log = nullptr;
|
||||
Settings *settings = nullptr;
|
||||
//video config
|
||||
ChiakiVideoResolutionPreset video_resolution = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
|
||||
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_failed = 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
|
||||
bool discovered = false;
|
||||
|
@ -95,7 +98,8 @@ class Host
|
|||
void StartSession();
|
||||
void SendFeedbackState(ChiakiControllerState *);
|
||||
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 GetHostAddr();
|
||||
ChiakiTarget GetChiakiTarget();
|
||||
|
@ -104,6 +108,9 @@ class Host
|
|||
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
|
||||
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
|
||||
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 IsDiscovered();
|
||||
bool IsReady();
|
||||
|
|
|
@ -3,15 +3,14 @@
|
|||
#ifndef CHIAKI_IO_H
|
||||
#define CHIAKI_IO_H
|
||||
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <glad.h> // glad library (OpenGL loader)
|
||||
|
||||
#include <chiaki/session.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
|
||||
|
@ -37,8 +36,8 @@ extern "C"
|
|||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
#include <chiaki/log.h>
|
||||
#include <chiaki/controller.h>
|
||||
#include <chiaki/log.h>
|
||||
|
||||
#include "exception.h"
|
||||
|
||||
|
@ -47,8 +46,11 @@ extern "C"
|
|||
|
||||
class IO
|
||||
{
|
||||
protected:
|
||||
IO();
|
||||
static IO * instance;
|
||||
private:
|
||||
ChiakiLog * log;
|
||||
ChiakiLog *log;
|
||||
int video_width;
|
||||
int video_height;
|
||||
bool quit = false;
|
||||
|
@ -57,15 +59,12 @@ class IO
|
|||
// default nintendo switch res
|
||||
int screen_width = 1280;
|
||||
int screen_height = 720;
|
||||
std::function<bool()> chiaki_event_connected_cb = nullptr;
|
||||
std::function<bool(bool)> chiaki_even_login_pin_request_cb = nullptr;
|
||||
std::function<bool(ChiakiQuitEvent *)> chiaki_event_quit_cb = nullptr;
|
||||
AVCodec * codec;
|
||||
AVCodecContext * codec_context;
|
||||
AVFrame * frame;
|
||||
AVCodec *codec;
|
||||
AVCodecContext *codec_context;
|
||||
AVFrame *frame;
|
||||
SDL_AudioDeviceID sdl_audio_device_id = 0;
|
||||
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 vbo;
|
||||
GLuint tex[PLANES_COUNT];
|
||||
|
@ -73,49 +72,38 @@ class IO
|
|||
GLuint vert;
|
||||
GLuint frag;
|
||||
GLuint prog;
|
||||
private:
|
||||
bool InitAVCodec();
|
||||
bool InitOpenGl();
|
||||
bool InitOpenGlTextures();
|
||||
bool InitOpenGlShader();
|
||||
void OpenGlDraw();
|
||||
#ifdef DEBUG_OPENGL
|
||||
void CheckGLError(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 CheckGLError(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);
|
||||
#endif
|
||||
GLuint CreateAndCompileShader(GLenum type, const char * source);
|
||||
void SetOpenGlYUVPixels(AVFrame * frame);
|
||||
bool ReadGameKeys(SDL_Event * event, ChiakiControllerState * state);
|
||||
bool ReadGameTouchScreen(ChiakiControllerState * state);
|
||||
GLuint CreateAndCompileShader(GLenum type, const char *source);
|
||||
void SetOpenGlYUVPixels(AVFrame *frame);
|
||||
bool ReadGameKeys(SDL_Event *event, ChiakiControllerState *state);
|
||||
bool ReadGameTouchScreen(ChiakiControllerState *state);
|
||||
|
||||
public:
|
||||
IO(ChiakiLog * log);
|
||||
// singleton configuration
|
||||
IO(const IO&) = delete;
|
||||
void operator=(const IO&) = delete;
|
||||
static IO * GetInstance();
|
||||
|
||||
~IO();
|
||||
void SetMesaConfig();
|
||||
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;
|
||||
};
|
||||
bool VideoCB(uint8_t *buf, size_t buf_size);
|
||||
void InitAudioCB(unsigned int channels, unsigned int rate);
|
||||
void AudioCB(int16_t * buf, size_t samples_count);
|
||||
void EventCB(ChiakiEvent *event);
|
||||
void AudioCB(int16_t *buf, size_t samples_count);
|
||||
bool InitVideo(int video_width, int video_height, int screen_width, int screen_height);
|
||||
bool FreeVideo();
|
||||
bool InitJoystick();
|
||||
bool FreeJoystick();
|
||||
bool ReadUserKeyboard(char * buffer, size_t buffer_size);
|
||||
bool MainLoop(ChiakiControllerState * state);
|
||||
bool ReadUserKeyboard(char *buffer, size_t buffer_size);
|
||||
bool MainLoop(ChiakiControllerState *state);
|
||||
};
|
||||
|
||||
#endif //CHIAKI_IO_H
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue