mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-08-13 02:21:50 +00:00
format ivshmem code
This commit is contained in:
parent
7caa9b7ea9
commit
5772a92df2
@ -24,8 +24,77 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <initguid.h>
|
||||
#include <smemory.h>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
DEFINE_GUID(GUID_DEVINTERFACE_IVSHMEM, 0xdf576976, 0x569d, 0x4672, 0x95, 0xa0, 0xf5, 0x7e, 0x4e,
|
||||
0xa0, 0xb2, 0x10);
|
||||
// {df576976-569d-4672-95a0-f57e4ea0b210}
|
||||
|
||||
typedef UINT16 IVSHMEM_PEERID;
|
||||
typedef UINT64 IVSHMEM_SIZE;
|
||||
|
||||
#define IVSHMEM_CACHE_NONCACHED 0
|
||||
#define IVSHMEM_CACHE_CACHED 1
|
||||
#define IVSHMEM_CACHE_WRITECOMBINED 2
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REQUEST_MMAP IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_MMAP_CONFIG {
|
||||
UINT8 cacheMode; // the caching mode of the mapping, see IVSHMEM_CACHE_* for options
|
||||
} IVSHMEM_MMAP_CONFIG, *PIVSHMEM_MMAP_CONFIG;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REQUEST_MMAP IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_MMAP {
|
||||
IVSHMEM_PEERID peerID; // our peer id
|
||||
IVSHMEM_SIZE size; // the size of the memory region
|
||||
PVOID ptr; // pointer to the memory region
|
||||
UINT16 vectors; // the number of vectors available
|
||||
} IVSHMEM_MMAP, *PIVSHMEM_MMAP;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_RING_DOORBELL IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_RING {
|
||||
IVSHMEM_PEERID peerID; // the id of the peer to ring
|
||||
UINT16 vector; // the doorbell to ring
|
||||
} IVSHMEM_RING, *PIVSHMEM_RING;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REGISTER_EVENT IOCTL
|
||||
|
||||
Please Note:
|
||||
- The IVSHMEM driver has a hard limit of 32 events.
|
||||
- Events that are singleShot are released after they have been set.
|
||||
- At this time repeating events are only released when the driver device
|
||||
handle is closed, closing the event handle doesn't release it from the
|
||||
drivers list. While this won't cause a problem in the driver, it will
|
||||
cause you to run out of event slots.
|
||||
*/
|
||||
typedef struct IVSHMEM_EVENT {
|
||||
UINT16 vector; // the vector that triggers the event
|
||||
HANDLE event; // the event to trigger
|
||||
BOOLEAN singleShot; // set to TRUE if you want the driver to only trigger this event once
|
||||
} IVSHMEM_EVENT, *PIVSHMEM_EVENT;
|
||||
|
||||
#define IOCTL_IVSHMEM_REQUEST_PEERID \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REQUEST_SIZE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REQUEST_MMAP \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_RELEASE_MMAP \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_RING_DOORBELL \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REGISTER_EVENT \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
IVSHMEM *IVSHMEM::m_instance = NULL;
|
||||
|
||||
IVSHMEM::IVSHMEM(char *path)
|
||||
|
||||
@ -19,77 +19,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <initguid.h>
|
||||
#include <smemory.h>
|
||||
#include <stdbool.h>
|
||||
#include <windows.h>
|
||||
|
||||
DEFINE_GUID(GUID_DEVINTERFACE_IVSHMEM, 0xdf576976, 0x569d, 0x4672, 0x95, 0xa0, 0xf5, 0x7e, 0x4e,
|
||||
0xa0, 0xb2, 0x10);
|
||||
// {df576976-569d-4672-95a0-f57e4ea0b210}
|
||||
|
||||
typedef UINT16 IVSHMEM_PEERID;
|
||||
typedef UINT64 IVSHMEM_SIZE;
|
||||
|
||||
#define IVSHMEM_CACHE_NONCACHED 0
|
||||
#define IVSHMEM_CACHE_CACHED 1
|
||||
#define IVSHMEM_CACHE_WRITECOMBINED 2
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REQUEST_MMAP IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_MMAP_CONFIG {
|
||||
UINT8 cacheMode; // the caching mode of the mapping, see IVSHMEM_CACHE_* for options
|
||||
} IVSHMEM_MMAP_CONFIG, *PIVSHMEM_MMAP_CONFIG;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REQUEST_MMAP IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_MMAP {
|
||||
IVSHMEM_PEERID peerID; // our peer id
|
||||
IVSHMEM_SIZE size; // the size of the memory region
|
||||
PVOID ptr; // pointer to the memory region
|
||||
UINT16 vectors; // the number of vectors available
|
||||
} IVSHMEM_MMAP, *PIVSHMEM_MMAP;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_RING_DOORBELL IOCTL
|
||||
*/
|
||||
typedef struct IVSHMEM_RING {
|
||||
IVSHMEM_PEERID peerID; // the id of the peer to ring
|
||||
UINT16 vector; // the doorbell to ring
|
||||
} IVSHMEM_RING, *PIVSHMEM_RING;
|
||||
|
||||
/*
|
||||
This structure is for use with the IOCTL_IVSHMEM_REGISTER_EVENT IOCTL
|
||||
|
||||
Please Note:
|
||||
- The IVSHMEM driver has a hard limit of 32 events.
|
||||
- Events that are singleShot are released after they have been set.
|
||||
- At this time repeating events are only released when the driver device
|
||||
handle is closed, closing the event handle doesn't release it from the
|
||||
drivers list. While this won't cause a problem in the driver, it will
|
||||
cause you to run out of event slots.
|
||||
*/
|
||||
typedef struct IVSHMEM_EVENT {
|
||||
UINT16 vector; // the vector that triggers the event
|
||||
HANDLE event; // the event to trigger
|
||||
BOOLEAN singleShot; // set to TRUE if you want the driver to only trigger this event once
|
||||
} IVSHMEM_EVENT, *PIVSHMEM_EVENT;
|
||||
|
||||
#define IOCTL_IVSHMEM_REQUEST_PEERID \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REQUEST_SIZE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REQUEST_MMAP \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_RELEASE_MMAP \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_RING_DOORBELL \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_IVSHMEM_REGISTER_EVENT \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
class IVSHMEM {
|
||||
public:
|
||||
IVSHMEM(char *path);
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@ -165,7 +165,6 @@ int main(int argc, char *argv[]) {
|
||||
auto idr = mail->event<bool>(mail::idr);
|
||||
|
||||
auto expected_index = queue->outindex;
|
||||
auto last_bitrate = 6;
|
||||
char buffer[DATA_PACKET_SIZE] = {0};
|
||||
while (!process_shutdown_event->peek() && !local_shutdown->peek()) {
|
||||
while (expected_index == queue->outindex)
|
||||
@ -182,18 +181,9 @@ int main(int argc, char *argv[]) {
|
||||
if (buffer[1] == 0)
|
||||
break;
|
||||
|
||||
last_bitrate = buffer[1];
|
||||
BOOST_LOG(info) << "bitrate changed to " << (buffer[1] * 1000);
|
||||
bitrate->raise(buffer[1] * 1000);
|
||||
break;
|
||||
case EventType::BufferOverflow:
|
||||
if (last_bitrate <= 1)
|
||||
break;
|
||||
|
||||
last_bitrate--;
|
||||
BOOST_LOG(info) << "overflow, bitrate changed to " << (last_bitrate * 1000);
|
||||
bitrate->raise(last_bitrate * 1000);
|
||||
break;
|
||||
case EventType::Framerate:
|
||||
if (buffer[1] < 20)
|
||||
break;
|
||||
@ -205,10 +195,6 @@ int main(int argc, char *argv[]) {
|
||||
BOOST_LOG(debug) << "IDR";
|
||||
idr->raise(true);
|
||||
break;
|
||||
case EventType::Stop:
|
||||
BOOST_LOG(debug) << "Received shutdown event from shm";
|
||||
process_shutdown_event->raise(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user