mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 13:33:13 -07:00
Add CHIAKI_GUI_ENABLE_QT_GAMEPAD option
This commit is contained in:
parent
8653afffce
commit
3f76782b6c
3 changed files with 64 additions and 30 deletions
|
@ -1,9 +1,14 @@
|
||||||
|
|
||||||
|
option(CHIAKI_GUI_ENABLE_QT_GAMEPAD "Use QtGamepad for Input" ON)
|
||||||
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Multimedia Gamepad)
|
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Multimedia)
|
||||||
|
if(CHIAKI_GUI_ENABLE_QT_GAMEPAD)
|
||||||
|
find_package(Qt5 REQUIRED COMPONENTS Gamepad)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(FFMPEG REQUIRED COMPONENTS avcodec)
|
find_package(FFMPEG REQUIRED COMPONENTS avcodec)
|
||||||
|
|
||||||
|
@ -29,4 +34,8 @@ target_include_directories(chiaki PRIVATE include)
|
||||||
|
|
||||||
target_link_libraries(chiaki chiaki-lib)
|
target_link_libraries(chiaki chiaki-lib)
|
||||||
target_link_libraries(chiaki FFMPEG::avcodec)
|
target_link_libraries(chiaki FFMPEG::avcodec)
|
||||||
target_link_libraries(chiaki Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Multimedia Qt5::Gamepad)
|
target_link_libraries(chiaki Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Multimedia)
|
||||||
|
if(CHIAKI_GUI_ENABLE_QT_GAMEPAD)
|
||||||
|
target_link_libraries(chiaki Qt5::Gamepad)
|
||||||
|
target_compile_definitions(chiaki CHIAKI_GUI_ENABLE_QT_GAMEPAD)
|
||||||
|
endif()
|
||||||
|
|
|
@ -25,7 +25,10 @@
|
||||||
|
|
||||||
#include <chiaki/session.h>
|
#include <chiaki/session.h>
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
class QGamepad;
|
class QGamepad;
|
||||||
|
#endif
|
||||||
|
|
||||||
class QAudioOutput;
|
class QAudioOutput;
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
|
||||||
|
@ -38,7 +41,9 @@ class StreamSession : public QObject
|
||||||
private:
|
private:
|
||||||
ChiakiSession session;
|
ChiakiSession session;
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
QGamepad *gamepad;
|
QGamepad *gamepad;
|
||||||
|
#endif
|
||||||
|
|
||||||
VideoDecoder video_decoder;
|
VideoDecoder video_decoder;
|
||||||
|
|
||||||
|
@ -52,14 +57,18 @@ class StreamSession : public QObject
|
||||||
explicit StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent = nullptr);
|
explicit StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent = nullptr);
|
||||||
~StreamSession();
|
~StreamSession();
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
QGamepad *GetGamepad() { return gamepad; }
|
QGamepad *GetGamepad() { return gamepad; }
|
||||||
|
#endif
|
||||||
VideoDecoder *GetVideoDecoder() { return &video_decoder; }
|
VideoDecoder *GetVideoDecoder() { return &video_decoder; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void CurrentImageUpdated();
|
void CurrentImageUpdated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
void UpdateGamepads();
|
void UpdateGamepads();
|
||||||
|
#endif
|
||||||
void SendFeedbackState();
|
void SendFeedbackState();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,12 @@
|
||||||
|
|
||||||
#include <chiaki/base64.h>
|
#include <chiaki/base64.h>
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
#include <QGamepadManager>
|
#include <QGamepadManager>
|
||||||
#include <QAudioOutput>
|
|
||||||
#include <QGamepad>
|
#include <QGamepad>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <QAudioOutput>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,8 +32,10 @@ static void AudioFrameCb(int16_t *buf, size_t samples_count, void *user);
|
||||||
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
||||||
|
|
||||||
StreamSession::StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent)
|
StreamSession::StreamSession(const QString &host, const QString ®istkey, const QString &ostype, const QString &auth, const QString &morning, const QString &did, QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent)
|
||||||
gamepad(nullptr)
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
|
,gamepad(nullptr)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
QByteArray host_str = host.toUtf8();
|
QByteArray host_str = host.toUtf8();
|
||||||
QByteArray registkey_str = registkey.toUtf8();
|
QByteArray registkey_str = registkey.toUtf8();
|
||||||
|
@ -88,16 +93,22 @@ StreamSession::StreamSession(const QString &host, const QString ®istkey, cons
|
||||||
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
chiaki_session_set_video_sample_cb(&session, VideoSampleCb, this);
|
||||||
chiaki_session_start(&session);
|
chiaki_session_start(&session);
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
|
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this, &StreamSession::UpdateGamepads);
|
||||||
UpdateGamepads();
|
UpdateGamepads();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSession::~StreamSession()
|
StreamSession::~StreamSession()
|
||||||
{
|
{
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
|
delete gamepad;
|
||||||
|
#endif
|
||||||
chiaki_session_join(&session);
|
chiaki_session_join(&session);
|
||||||
chiaki_session_fini(&session);
|
chiaki_session_fini(&session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
void StreamSession::UpdateGamepads()
|
void StreamSession::UpdateGamepads()
|
||||||
{
|
{
|
||||||
if(!gamepad || !gamepad->isConnected())
|
if(!gamepad || !gamepad->isConnected())
|
||||||
|
@ -139,13 +150,15 @@ void StreamSession::UpdateGamepads()
|
||||||
|
|
||||||
SendFeedbackState();
|
SendFeedbackState();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void StreamSession::SendFeedbackState()
|
void StreamSession::SendFeedbackState()
|
||||||
{
|
{
|
||||||
if(!gamepad)
|
ChiakiControllerState state = {};
|
||||||
return;
|
|
||||||
ChiakiControllerState state;
|
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||||
state.buttons = 0;
|
if(gamepad)
|
||||||
|
{
|
||||||
state.buttons |= gamepad->buttonA() ? CHIAKI_CONTROLLER_BUTTON_CROSS : 0;
|
state.buttons |= gamepad->buttonA() ? CHIAKI_CONTROLLER_BUTTON_CROSS : 0;
|
||||||
state.buttons |= gamepad->buttonB() ? CHIAKI_CONTROLLER_BUTTON_MOON : 0;
|
state.buttons |= gamepad->buttonB() ? CHIAKI_CONTROLLER_BUTTON_MOON : 0;
|
||||||
state.buttons |= gamepad->buttonX() ? CHIAKI_CONTROLLER_BUTTON_BOX : 0;
|
state.buttons |= gamepad->buttonX() ? CHIAKI_CONTROLLER_BUTTON_BOX : 0;
|
||||||
|
@ -167,6 +180,9 @@ void StreamSession::SendFeedbackState()
|
||||||
state.left_y = static_cast<int16_t>(gamepad->axisLeftY() * 0x7fff);
|
state.left_y = static_cast<int16_t>(gamepad->axisLeftY() * 0x7fff);
|
||||||
state.right_x = static_cast<int16_t>(gamepad->axisRightX() * 0x7fff);
|
state.right_x = static_cast<int16_t>(gamepad->axisRightX() * 0x7fff);
|
||||||
state.right_y = static_cast<int16_t>(gamepad->axisRightY() * 0x7fff);
|
state.right_y = static_cast<int16_t>(gamepad->axisRightY() * 0x7fff);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
chiaki_session_set_controller_state(&session, &state);
|
chiaki_session_set_controller_state(&session, &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue