mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-07 16:26:19 +00:00
Initial commit
This commit is contained in:
22
limelight-common.sln
Normal file
22
limelight-common.sln
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "limelight-common", "limelight-common\limelight-common.vcxproj", "{15D85395-B083-4688-B578-58AB22C85BE5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{15D85395-B083-4688-B578-58AB22C85BE5}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{15D85395-B083-4688-B578-58AB22C85BE5}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{15D85395-B083-4688-B578-58AB22C85BE5}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{15D85395-B083-4688-B578-58AB22C85BE5}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
98
limelight-common/ByteBuffer.cpp
Normal file
98
limelight-common/ByteBuffer.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder) {
|
||||
buff->buffer = data;
|
||||
buff->offset = offset;
|
||||
buff->length = length;
|
||||
buff->position = 0;
|
||||
buff->byteOrder = byteOrder;
|
||||
}
|
||||
|
||||
static int byteSwapInt(PBYTE_BUFFER buff, int i) {
|
||||
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
||||
return htonl(i);
|
||||
}
|
||||
else {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
static int byteSwapShort(PBYTE_BUFFER buff, short s) {
|
||||
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
||||
return htons(s);
|
||||
}
|
||||
else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
int BbGet(PBYTE_BUFFER buff, char *c) {
|
||||
if (buff->position + sizeof(c) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(c, &buff[buff->position], sizeof(*c));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BbGetShort(PBYTE_BUFFER buff, short *s) {
|
||||
if (buff->position + sizeof(s) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(s, &buff[buff->position], sizeof(*s));
|
||||
|
||||
*s = byteSwapShort(buff, *s);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BbGetInt(PBYTE_BUFFER buff, int *i) {
|
||||
if (buff->position + sizeof(i) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(i, &buff[buff->position], sizeof(*i));
|
||||
|
||||
*i = byteSwapInt(buff, *i);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BbPutInt(PBYTE_BUFFER buff, int i) {
|
||||
if (buff->position + sizeof(i) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = byteSwapInt(buff, i);
|
||||
|
||||
memcpy(&buff[buff->position], &i, sizeof(i));
|
||||
buff->position += sizeof(i);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BbPutShort(PBYTE_BUFFER buff, short s) {
|
||||
if (buff->position + sizeof(s) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = byteSwapShort(buff, s);
|
||||
|
||||
memcpy(&buff[buff->position], &s, sizeof(s));
|
||||
buff->position += sizeof(s);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BbPut(PBYTE_BUFFER buff, char c) {
|
||||
if (buff->position + sizeof(c) >= buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(&buff[buff->position], &c, sizeof(c));
|
||||
buff->position += sizeof(c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
22
limelight-common/ByteBuffer.h
Normal file
22
limelight-common/ByteBuffer.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "Platform.h"
|
||||
|
||||
#define BYTE_ORDER_LITTLE 1
|
||||
#define BYTE_ORDER_BIG 2
|
||||
|
||||
typedef struct _BYTE_BUFFER {
|
||||
char* buffer;
|
||||
int offset;
|
||||
int length;
|
||||
int position;
|
||||
int byteOrder;
|
||||
} BYTE_BUFFER, *PBYTE_BUFFER;
|
||||
|
||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
|
||||
|
||||
int BbGet(PBYTE_BUFFER buff, char *c);
|
||||
int BbGetShort(PBYTE_BUFFER buff, short *s);
|
||||
int BbGetInt(PBYTE_BUFFER buff, int *i);
|
||||
|
||||
int BbPutInt(PBYTE_BUFFER buff, int i);
|
||||
int BbPutShort(PBYTE_BUFFER buff, short s);
|
||||
int BbPut(PBYTE_BUFFER buff, char c);
|
||||
106
limelight-common/Config.cpp
Normal file
106
limelight-common/Config.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "Limelight.h"
|
||||
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
const int UNKNOWN_CONFIG [] = {
|
||||
70151,
|
||||
68291329,
|
||||
1280,
|
||||
68291584,
|
||||
1280,
|
||||
68291840,
|
||||
15360,
|
||||
68292096,
|
||||
25600,
|
||||
68292352,
|
||||
2048,
|
||||
68292608,
|
||||
1024,
|
||||
68289024,
|
||||
262144,
|
||||
17957632,
|
||||
302055424,
|
||||
134217729,
|
||||
16777490,
|
||||
70153,
|
||||
68293120,
|
||||
768000,
|
||||
17961216,
|
||||
303235072,
|
||||
335609857,
|
||||
838861842,
|
||||
352321536,
|
||||
1006634002,
|
||||
369098752,
|
||||
335545362,
|
||||
385875968,
|
||||
1042,
|
||||
402653184,
|
||||
134218770,
|
||||
419430400,
|
||||
167773202,
|
||||
436207616,
|
||||
855638290,
|
||||
266779,
|
||||
7000,
|
||||
266780,
|
||||
2000,
|
||||
266781,
|
||||
50,
|
||||
266782,
|
||||
3000,
|
||||
266783,
|
||||
2,
|
||||
266794,
|
||||
5000,
|
||||
266795,
|
||||
500,
|
||||
266784,
|
||||
75,
|
||||
266785,
|
||||
25,
|
||||
266786,
|
||||
10,
|
||||
266787,
|
||||
60,
|
||||
266788,
|
||||
30,
|
||||
266789,
|
||||
3,
|
||||
266790,
|
||||
1000,
|
||||
266791,
|
||||
5000,
|
||||
266792,
|
||||
5000,
|
||||
266793,
|
||||
5000,
|
||||
70190,
|
||||
68301063,
|
||||
10240,
|
||||
68301312,
|
||||
6400,
|
||||
68301568,
|
||||
768000,
|
||||
68299776,
|
||||
768,
|
||||
68300032,
|
||||
2560,
|
||||
68300544,
|
||||
0,
|
||||
34746368,
|
||||
(int) 0xFE000000
|
||||
};
|
||||
|
||||
const int CONFIG_SIZE = sizeof(UNKNOWN_CONFIG) +(8 * 4) + 3;
|
||||
|
||||
char* allocateConfigDataForStreamConfig(PSTREAM_CONFIGURATION streamConfig) {
|
||||
BYTE_BUFFER bb;
|
||||
char* config = (char *)malloc(CONFIG_SIZE);
|
||||
if (config == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BbInitializeWrappedBuffer(&bb, config, 0, CONFIG_SIZE, BYTE_ORDER_LITTLE);
|
||||
|
||||
}
|
||||
80
limelight-common/Handshake.cpp
Normal file
80
limelight-common/Handshake.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "PlatformSockets.h"
|
||||
|
||||
const char HELLO [] = {
|
||||
0x07, 0x00, 0x00, 0x00,
|
||||
0x61, 0x6e, 0x64, 0x72,
|
||||
0x6f, 0x69, 0x64, 0x03,
|
||||
0x01, 0x00, 0x00
|
||||
};
|
||||
|
||||
const char PACKET2 [] = {
|
||||
0x01, 0x03, 0x02, 0x00,
|
||||
0x08, 0x00
|
||||
};
|
||||
|
||||
const char PACKET3 [] = {
|
||||
0x04, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const char PACKET4 [] = {
|
||||
0x01, 0x01, 0x00, 0x0
|
||||
};
|
||||
|
||||
static int waitAndDiscardResponse(SOCKET sock) {
|
||||
char temp[256];
|
||||
return recv(sock, temp, sizeof(temp), 0);
|
||||
}
|
||||
|
||||
int performHandshake(IP_ADDRESS host) {
|
||||
SOCKET s;
|
||||
int err;
|
||||
|
||||
s = connectTcpSocket(host, 47991);
|
||||
if (s == INVALID_SOCKET) {
|
||||
return LastSocketError();
|
||||
}
|
||||
|
||||
err = send(s, HELLO, sizeof(HELLO), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET2, sizeof(PACKET2), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET3, sizeof(PACKET3), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET4, sizeof(PACKET4), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
closesocket(s);
|
||||
return 0;
|
||||
|
||||
CleanupError:
|
||||
closesocket(s);
|
||||
return LastSocketError();
|
||||
}
|
||||
7
limelight-common/Limelight.h
Normal file
7
limelight-common/Limelight.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "Platform.h"
|
||||
|
||||
typedef struct _STREAM_CONFIGURATION {
|
||||
int width;
|
||||
int height;
|
||||
int fps;
|
||||
} STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION;
|
||||
4
limelight-common/Platform.h
Normal file
4
limelight-common/Platform.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#endif
|
||||
22
limelight-common/PlatformSockets.cpp
Normal file
22
limelight-common/PlatformSockets.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "PlatformSockets.h"
|
||||
|
||||
SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port) {
|
||||
SOCKET s;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (s == INVALID_SOCKET) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
memcpy(&addr.sin_addr, &dstaddr, sizeof(dstaddr));
|
||||
if (connect(s, (struct sockaddr*) &addr, sizeof(addr)) == SOCKET_ERROR) {
|
||||
closesocket(s);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
15
limelight-common/PlatformSockets.h
Normal file
15
limelight-common/PlatformSockets.h
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#define LastSocketError() WSAGetLastError()
|
||||
#else
|
||||
#define SOCKET int
|
||||
#define LastSocketError() errno
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#define closesocket(x) close(x)
|
||||
#endif
|
||||
|
||||
#define IP_ADDRESS unsigned int
|
||||
|
||||
SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port);
|
||||
79
limelight-common/limelight-common.vcxproj
Normal file
79
limelight-common/limelight-common.vcxproj
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{15D85395-B083-4688-B578-58AB22C85BE5}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>limelightcommon</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
20
limelight-common/limelight-common.vcxproj.filters
Normal file
20
limelight-common/limelight-common.vcxproj.filters
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user