2019-12-03 19:23:33 +00:00
|
|
|
//
|
|
|
|
// Created by loki on 6/21/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SUNSHINE_COMMON_H
|
|
|
|
#define SUNSHINE_COMMON_H
|
|
|
|
|
2019-12-04 23:59:01 +00:00
|
|
|
#include <string>
|
2019-12-08 17:55:58 +00:00
|
|
|
#include "sunshine/utility.h"
|
2019-12-03 19:23:33 +00:00
|
|
|
|
|
|
|
namespace platf {
|
2020-01-25 00:05:43 +00:00
|
|
|
constexpr auto MAX_GAMEPADS = 2;
|
|
|
|
|
2020-01-18 22:52:22 +00:00
|
|
|
constexpr std::uint16_t DPAD_UP = 0x0001;
|
|
|
|
constexpr std::uint16_t DPAD_DOWN = 0x0002;
|
|
|
|
constexpr std::uint16_t DPAD_LEFT = 0x0004;
|
|
|
|
constexpr std::uint16_t DPAD_RIGHT = 0x0008;
|
|
|
|
constexpr std::uint16_t START = 0x0010;
|
|
|
|
constexpr std::uint16_t BACK = 0x0020;
|
|
|
|
constexpr std::uint16_t LEFT_STICK = 0x0040;
|
|
|
|
constexpr std::uint16_t RIGHT_STICK = 0x0080;
|
|
|
|
constexpr std::uint16_t LEFT_BUTTON = 0x0100;
|
|
|
|
constexpr std::uint16_t RIGHT_BUTTON = 0x0200;
|
|
|
|
constexpr std::uint16_t HOME = 0x0400;
|
|
|
|
constexpr std::uint16_t A = 0x1000;
|
|
|
|
constexpr std::uint16_t B = 0x2000;
|
|
|
|
constexpr std::uint16_t X = 0x4000;
|
|
|
|
constexpr std::uint16_t Y = 0x8000;
|
|
|
|
|
|
|
|
struct gamepad_state_t {
|
|
|
|
std::uint16_t buttonFlags;
|
|
|
|
std::uint8_t lt;
|
|
|
|
std::uint8_t rt;
|
|
|
|
std::int16_t lsX;
|
|
|
|
std::int16_t lsY;
|
|
|
|
std::int16_t rsX;
|
|
|
|
std::int16_t rsY;
|
|
|
|
};
|
2019-12-03 19:23:33 +00:00
|
|
|
|
2019-12-30 10:09:35 +00:00
|
|
|
struct img_t {
|
|
|
|
public:
|
2020-01-11 00:17:57 +00:00
|
|
|
std::uint8_t *data {};
|
|
|
|
std::int32_t width {};
|
|
|
|
std::int32_t height {};
|
2020-01-23 01:40:48 +00:00
|
|
|
std::int32_t pixel_pitch {};
|
|
|
|
std::int32_t row_pitch {};
|
2020-01-11 00:17:57 +00:00
|
|
|
|
|
|
|
img_t() = default;
|
|
|
|
img_t(const img_t&) = delete;
|
|
|
|
img_t(img_t&&) = delete;
|
2019-12-30 10:09:35 +00:00
|
|
|
|
2020-01-09 11:12:18 +00:00
|
|
|
virtual ~img_t() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class capture_e : int {
|
|
|
|
ok,
|
|
|
|
reinit,
|
|
|
|
timeout,
|
|
|
|
error
|
2019-12-30 10:09:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class display_t {
|
|
|
|
public:
|
2020-01-15 17:31:28 +00:00
|
|
|
virtual capture_e snapshot(img_t *img, bool cursor) = 0;
|
2020-01-09 11:12:18 +00:00
|
|
|
virtual std::unique_ptr<img_t> alloc_img() = 0;
|
|
|
|
|
2019-12-30 10:49:45 +00:00
|
|
|
virtual ~display_t() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
class mic_t {
|
|
|
|
public:
|
2020-01-15 17:31:28 +00:00
|
|
|
virtual capture_e sample(std::vector<std::int16_t> &frame_buffer) = 0;
|
2019-12-30 10:49:45 +00:00
|
|
|
|
|
|
|
virtual ~mic_t() = default;
|
2019-12-30 10:09:35 +00:00
|
|
|
};
|
|
|
|
|
2020-01-19 23:22:13 +00:00
|
|
|
|
2019-12-06 15:33:13 +00:00
|
|
|
void freeInput(void*);
|
2019-12-03 19:23:33 +00:00
|
|
|
|
2020-01-09 11:12:18 +00:00
|
|
|
using input_t = util::safe_ptr<void, freeInput>;
|
2019-12-05 23:13:16 +00:00
|
|
|
|
2020-01-21 01:34:22 +00:00
|
|
|
std::string get_mac_address(const std::string_view &address);
|
2019-12-06 15:33:13 +00:00
|
|
|
|
2020-01-15 17:31:28 +00:00
|
|
|
std::unique_ptr<mic_t> microphone(std::uint32_t sample_rate);
|
2020-01-31 19:57:34 +00:00
|
|
|
std::unique_ptr<display_t> display();
|
2019-12-03 19:23:33 +00:00
|
|
|
|
2019-12-06 15:33:13 +00:00
|
|
|
input_t input();
|
|
|
|
void move_mouse(input_t &input, int deltaX, int deltaY);
|
|
|
|
void button_mouse(input_t &input, int button, bool release);
|
|
|
|
void scroll(input_t &input, int distance);
|
|
|
|
void keyboard(input_t &input, uint16_t modcode, bool release);
|
2020-01-25 19:46:14 +00:00
|
|
|
void gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state);
|
2020-01-31 19:57:34 +00:00
|
|
|
|
|
|
|
int alloc_gamepad(input_t &input, int nr);
|
|
|
|
void free_gamepad(input_t &input, int nr);
|
2019-12-03 19:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SUNSHINE_COMMON_H
|