mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-01-08 21:14:14 +00:00
minor changes
This commit is contained in:
parent
ca801f1829
commit
91264dc166
200
Input.h
Normal file
200
Input.h
Normal file
@ -0,0 +1,200 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#define SS_KBE_FLAG_NON_NORMALIZED 0x01
|
||||
|
||||
// netfloat is just a little-endian float in byte form
|
||||
// for network transmission.
|
||||
typedef uint8_t netfloat[4];
|
||||
|
||||
typedef struct _NV_INPUT_HEADER {
|
||||
uint32_t size; // Size of packet (excluding this field) - Big Endian
|
||||
uint32_t magic; // Packet type - Little Endian
|
||||
} NV_INPUT_HEADER, *PNV_INPUT_HEADER;
|
||||
|
||||
#define ENABLE_HAPTICS_MAGIC 0x0000000D
|
||||
typedef struct _NV_HAPTICS_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint16_t enable;
|
||||
} NV_HAPTICS_PACKET, *PNV_HAPTICS_PACKET;
|
||||
|
||||
#define KEY_DOWN_EVENT_MAGIC 0x00000003
|
||||
#define KEY_UP_EVENT_MAGIC 0x00000004
|
||||
typedef struct _NV_KEYBOARD_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
char flags;
|
||||
short keyCode;
|
||||
char modifiers;
|
||||
short zero2;
|
||||
} NV_KEYBOARD_PACKET, *PNV_KEYBOARD_PACKET;
|
||||
|
||||
#define UTF8_TEXT_EVENT_MAGIC 0x00000017
|
||||
#define UTF8_TEXT_EVENT_MAX_COUNT 32
|
||||
typedef struct _NV_UNICODE_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
char text[UTF8_TEXT_EVENT_MAX_COUNT];
|
||||
} NV_UNICODE_PACKET, *PNV_UNICODE_PACKET;
|
||||
|
||||
#define MOUSE_MOVE_REL_MAGIC 0x00000006
|
||||
#define MOUSE_MOVE_REL_MAGIC_GEN5 0x00000007
|
||||
typedef struct _NV_REL_MOUSE_MOVE_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
short deltaX;
|
||||
short deltaY;
|
||||
} NV_REL_MOUSE_MOVE_PACKET, *PNV_REL_MOUSE_MOVE_PACKET;
|
||||
|
||||
#define MOUSE_MOVE_ABS_MAGIC 0x00000005
|
||||
typedef struct _NV_ABS_MOUSE_MOVE_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
|
||||
short x;
|
||||
short y;
|
||||
|
||||
short unused;
|
||||
|
||||
// Used on the server-side as a reference to scale x and y
|
||||
// to screen coordinates.
|
||||
short width;
|
||||
short height;
|
||||
} NV_ABS_MOUSE_MOVE_PACKET, *PNV_ABS_MOUSE_MOVE_PACKET;
|
||||
|
||||
#define MOUSE_BUTTON_DOWN_EVENT_MAGIC_GEN5 0x00000008
|
||||
#define MOUSE_BUTTON_UP_EVENT_MAGIC_GEN5 0x00000009
|
||||
typedef struct _NV_MOUSE_BUTTON_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t button;
|
||||
} NV_MOUSE_BUTTON_PACKET, *PNV_MOUSE_BUTTON_PACKET;
|
||||
|
||||
#define CONTROLLER_MAGIC 0x0000000A
|
||||
#define C_HEADER_B 0x1400
|
||||
#define C_TAIL_A 0x0000009C
|
||||
#define C_TAIL_B 0x0055
|
||||
typedef struct _NV_CONTROLLER_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
short headerB;
|
||||
short buttonFlags;
|
||||
unsigned char leftTrigger;
|
||||
unsigned char rightTrigger;
|
||||
short leftStickX;
|
||||
short leftStickY;
|
||||
short rightStickX;
|
||||
short rightStickY;
|
||||
int tailA;
|
||||
short tailB;
|
||||
} NV_CONTROLLER_PACKET, *PNV_CONTROLLER_PACKET;
|
||||
|
||||
#define MULTI_CONTROLLER_MAGIC 0x0000000D
|
||||
#define MULTI_CONTROLLER_MAGIC_GEN5 0x0000000C
|
||||
#define MC_HEADER_B 0x001A
|
||||
#define MC_MID_B 0x0014
|
||||
#define MC_TAIL_A 0x009C
|
||||
#define MC_TAIL_B 0x0055
|
||||
typedef struct _NV_MULTI_CONTROLLER_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
short headerB;
|
||||
short controllerNumber;
|
||||
short activeGamepadMask;
|
||||
short midB;
|
||||
short buttonFlags;
|
||||
unsigned char leftTrigger;
|
||||
unsigned char rightTrigger;
|
||||
short leftStickX;
|
||||
short leftStickY;
|
||||
short rightStickX;
|
||||
short rightStickY;
|
||||
short tailA;
|
||||
short buttonFlags2; // Sunshine protocol extension (always 0 for GFE)
|
||||
short tailB;
|
||||
} NV_MULTI_CONTROLLER_PACKET, *PNV_MULTI_CONTROLLER_PACKET;
|
||||
|
||||
#define SCROLL_MAGIC 0x00000009
|
||||
#define SCROLL_MAGIC_GEN5 0x0000000A
|
||||
typedef struct _NV_SCROLL_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
short scrollAmt1;
|
||||
short scrollAmt2;
|
||||
short zero3;
|
||||
} NV_SCROLL_PACKET, *PNV_SCROLL_PACKET;
|
||||
|
||||
#define SS_HSCROLL_MAGIC 0x55000001
|
||||
typedef struct _SS_HSCROLL_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
short scrollAmount;
|
||||
} SS_HSCROLL_PACKET, *PSS_HSCROLL_PACKET;
|
||||
|
||||
#define SS_TOUCH_MAGIC 0x55000002
|
||||
typedef struct _SS_TOUCH_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t eventType;
|
||||
uint8_t zero[1]; // Alignment/reserved
|
||||
uint16_t rotation;
|
||||
uint32_t pointerId;
|
||||
netfloat x;
|
||||
netfloat y;
|
||||
netfloat pressureOrDistance;
|
||||
netfloat contactAreaMajor;
|
||||
netfloat contactAreaMinor;
|
||||
} SS_TOUCH_PACKET, *PSS_TOUCH_PACKET;
|
||||
|
||||
#define SS_PEN_MAGIC 0x55000003
|
||||
typedef struct _SS_PEN_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t eventType;
|
||||
uint8_t toolType;
|
||||
uint8_t penButtons;
|
||||
uint8_t zero[1]; // Alignment/reserved
|
||||
netfloat x;
|
||||
netfloat y;
|
||||
netfloat pressureOrDistance;
|
||||
uint16_t rotation;
|
||||
uint8_t tilt;
|
||||
uint8_t zero2[1];
|
||||
netfloat contactAreaMajor;
|
||||
netfloat contactAreaMinor;
|
||||
} SS_PEN_PACKET, *PSS_PEN_PACKET;
|
||||
|
||||
#define SS_CONTROLLER_ARRIVAL_MAGIC 0x55000004
|
||||
typedef struct _SS_CONTROLLER_ARRIVAL_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t controllerNumber;
|
||||
uint8_t type;
|
||||
uint16_t capabilities;
|
||||
uint32_t supportedButtonFlags;
|
||||
} SS_CONTROLLER_ARRIVAL_PACKET, *PSS_CONTROLLER_ARRIVAL_PACKET;
|
||||
|
||||
#define SS_CONTROLLER_TOUCH_MAGIC 0x55000005
|
||||
typedef struct _SS_CONTROLLER_TOUCH_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t controllerNumber;
|
||||
uint8_t eventType;
|
||||
uint8_t zero[2]; // Alignment/reserved
|
||||
uint32_t pointerId;
|
||||
netfloat x;
|
||||
netfloat y;
|
||||
netfloat pressure;
|
||||
} SS_CONTROLLER_TOUCH_PACKET, *PSS_CONTROLLER_TOUCH_PACKET;
|
||||
|
||||
#define SS_CONTROLLER_MOTION_MAGIC 0x55000006
|
||||
typedef struct _SS_CONTROLLER_MOTION_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t controllerNumber;
|
||||
uint8_t motionType;
|
||||
uint8_t zero[2]; // Alignment/reserved
|
||||
netfloat x;
|
||||
netfloat y;
|
||||
netfloat z;
|
||||
} SS_CONTROLLER_MOTION_PACKET, *PSS_CONTROLLER_MOTION_PACKET;
|
||||
|
||||
#define SS_CONTROLLER_BATTERY_MAGIC 0x55000007
|
||||
typedef struct _SS_CONTROLLER_BATTERY_PACKET {
|
||||
NV_INPUT_HEADER header;
|
||||
uint8_t controllerNumber;
|
||||
uint8_t batteryState;
|
||||
uint8_t batteryPercentage;
|
||||
uint8_t zero[1]; // Alignment/reserved
|
||||
} SS_CONTROLLER_BATTERY_PACKET, *PSS_CONTROLLER_BATTERY_PACKET;
|
||||
|
||||
#pragma pack(pop)
|
||||
@ -2,17 +2,40 @@ package main
|
||||
|
||||
/*
|
||||
#include "smemory.h"
|
||||
#include "Input.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void
|
||||
write(Queue* queue, void* data, int size) {
|
||||
int new_index = queue->index + 1;
|
||||
Packet* block = &queue->array[new_index % QUEUE_SIZE];
|
||||
block->size = size;
|
||||
memcpy(block->data,data,size);
|
||||
queue->index = new_index;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
keyboard_passthrough(Queue* queue, int keycode, int up, int scancode) {
|
||||
NV_KEYBOARD_PACKET packet = {0};
|
||||
packet.header.magic = up == 0
|
||||
? KEY_DOWN_EVENT_MAGIC
|
||||
: KEY_UP_EVENT_MAGIC;
|
||||
packet.keyCode = keycode;
|
||||
write(queue,&packet,sizeof(NV_KEYBOARD_PACKET));
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -33,30 +56,9 @@ func byteSliceToString(s []byte) string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
func copyAndCapture(r io.Reader) {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, err := r.Read(buf[:])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if n < 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
lines := strings.Split(string(buf[:n]), "\n")
|
||||
for _, line := range lines {
|
||||
sublines := strings.Split(line, "\r")
|
||||
for _, subline := range sublines {
|
||||
if len(subline) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("sunshine: %s\n", subline)
|
||||
}
|
||||
}
|
||||
}
|
||||
func ConvertBEEdian(in uint16) C.short {
|
||||
bytes := binary.BigEndian.AppendUint16([]byte{}, in)
|
||||
return C.short(binary.LittleEndian.Uint16(bytes))
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -112,28 +114,74 @@ func main() {
|
||||
indexes[i] = &j
|
||||
}
|
||||
|
||||
for queue_type, i := range indexes {
|
||||
go func(queue *C.Queue, index *int) {
|
||||
buffer := make([]byte, int(C.PACKET_SIZE))
|
||||
payloader := payloaders[queue.metadata.codec]()
|
||||
go func(queue *C.Queue, index *int) {
|
||||
buffer := make([]byte, int(C.PACKET_SIZE))
|
||||
payloader := payloaders[queue.metadata.codec]()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
for int(queue.index) > *index {
|
||||
new_index := *index + 1
|
||||
real_index := new_index % C.QUEUE_SIZE
|
||||
block := queue.array[real_index]
|
||||
|
||||
C.memcpy(unsafe.Pointer(&buffer[0]), unsafe.Pointer(&block.data[0]), C.ulonglong(block.size))
|
||||
payloads := payloader.Payload(1200, buffer[:block.size])
|
||||
fmt.Printf("Queue type %d, downstream index %d, upstream index %d, receive size %d\n", queue_type, new_index, queue.index, len(payloads))
|
||||
|
||||
*index = new_index
|
||||
}
|
||||
|
||||
time.Sleep(time.Microsecond * 100)
|
||||
queue.events[C.Idr].value_number = 1
|
||||
queue.events[C.Idr].read = 0
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}(&memory.queues[queue_type], i)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
for int(queue.index) > *index {
|
||||
new_index := *index + 1
|
||||
real_index := new_index % C.QUEUE_SIZE
|
||||
block := queue.array[real_index]
|
||||
|
||||
C.memcpy(unsafe.Pointer(&buffer[0]), unsafe.Pointer(&block.data[0]), C.ulonglong(block.size))
|
||||
payloads := payloader.Payload(1200, buffer[:block.size])
|
||||
fmt.Printf("downstream index %d, upstream index %d, receive size %d\n", new_index, queue.index, len(payloads))
|
||||
|
||||
*index = new_index
|
||||
}
|
||||
|
||||
time.Sleep(time.Microsecond * 100)
|
||||
}
|
||||
}(&memory.queues[C.Video0], indexes[C.Video0])
|
||||
|
||||
go func(queue *C.Queue, index *int) {
|
||||
buffer := make([]byte, 32)
|
||||
for {
|
||||
_, err := os.Stdin.Read(buffer)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
command := buffer[0]
|
||||
switch command {
|
||||
// case []byte("n")[0]:
|
||||
// packet := C.NV_REL_MOUSE_MOVE_PACKET{
|
||||
// header: C.NV_INPUT_HEADER{
|
||||
// magic: C.MOUSE_MOVE_REL_MAGIC_GEN5,
|
||||
// },
|
||||
// deltaX: ConvertBEEdian(10),
|
||||
// deltaY: ConvertBEEdian(10),
|
||||
// }
|
||||
|
||||
// Write(queue, unsafe.Pointer(&packet), int(unsafe.Sizeof(packet)))
|
||||
// _ = packet // use packet here to avoid go gc clear packet var
|
||||
// case []byte("m")[0]:
|
||||
// packet := C.NV_ABS_MOUSE_MOVE_PACKET{
|
||||
// header: C.NV_INPUT_HEADER{
|
||||
// magic: C.MOUSE_MOVE_ABS_MAGIC,
|
||||
// },
|
||||
// x: ConvertBEEdian(1920),
|
||||
// y: ConvertBEEdian(1080),
|
||||
// width: ConvertBEEdian(3840),
|
||||
// height: ConvertBEEdian(2160),
|
||||
// }
|
||||
|
||||
// Write(queue, unsafe.Pointer(&packet), int(unsafe.Sizeof(packet)))
|
||||
// _ = packet // use packet here to avoid go gc clear packet var
|
||||
case []byte("k")[0]:
|
||||
C.keyboard_passthrough(queue, 0, 1, 0)
|
||||
}
|
||||
}
|
||||
}(&memory.queues[C.Input], indexes[C.Input])
|
||||
|
||||
fmt.Printf("execute sunshine with command : ./sunshine.exe \"%s\" 0\n", byteSliceToString(buffer))
|
||||
chann := make(chan os.Signal, 16)
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
* @brief Implementation for globally accessible variables and functions.
|
||||
*/
|
||||
#include "interprocess.h"
|
||||
#include "logging.h"
|
||||
|
||||
#include <thread>
|
||||
#include <stdio.h>
|
||||
@ -76,5 +77,6 @@ peek_event(Queue* memory, EventType type){
|
||||
Event
|
||||
pop_event(Queue* queue, EventType type){
|
||||
queue->events[type].read = true;
|
||||
BOOST_LOG(info) << "Receive event " << type;
|
||||
return queue->events[type];
|
||||
}
|
||||
@ -144,7 +144,9 @@ main(int argc, char *argv[]) {
|
||||
|
||||
int queuetype = -1;
|
||||
std::stringstream ss; ss << argv[2]; ss >> queuetype;
|
||||
if(queuetype != QueueType::Audio && queuetype != QueueType::Input) {
|
||||
if(queuetype != QueueType::Audio &&
|
||||
queuetype != QueueType::Input &&
|
||||
queuetype != QueueType::Microphone) {
|
||||
if (video::probe_encoders()) {
|
||||
BOOST_LOG(error) << "Video failed to find working encoder"sv;
|
||||
return -1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user