From f2507d5a39bc0f68b9429131be3145a25c213378 Mon Sep 17 00:00:00 2001 From: Andrey Konoplyankin Date: Sat, 24 Apr 2021 19:55:17 +0300 Subject: [PATCH] Few fixes for run on Windows --- src/Settings.cpp | 6 +++ src/crypto/Data.cpp | 3 ++ src/libgamestream/client.cpp | 2 +- src/streaming/video/GLVideoRenderer.cpp | 67 +++++++++++++++++++++---- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/Settings.cpp b/src/Settings.cpp index f2596e1..e368916 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -6,6 +6,12 @@ #include #include +#ifdef _WIN32 +static int mkdir(const char* dir, mode_t mode) { + return mkdir(dir); +} +#endif + static int mkdirtree(const char* directory) { char buffer[PATH_MAX]; char* p = buffer; diff --git a/src/crypto/Data.cpp b/src/crypto/Data.cpp index 7934821..b80e1bf 100644 --- a/src/crypto/Data.cpp +++ b/src/crypto/Data.cpp @@ -71,7 +71,10 @@ Data& Data::operator=(const Data& that) { Data Data::random_bytes(size_t size) { unsigned char* bytes = (unsigned char*)malloc(sizeof(char) * size); + + #ifndef _WIN32 srand(time(NULL)); + #endif for (int i = 0; i < size; i++) { bytes[i] = rand() % 255; diff --git a/src/libgamestream/client.cpp b/src/libgamestream/client.cpp index d2103f6..194160b 100644 --- a/src/libgamestream/client.cpp +++ b/src/libgamestream/client.cpp @@ -410,7 +410,7 @@ int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, b memcpy(config->remoteInputAesKey, rand.bytes(), 16); char url[4096]; - u_int32_t rikeyid = 0; + int rikeyid = 0; Data data; diff --git a/src/streaming/video/GLVideoRenderer.cpp b/src/streaming/video/GLVideoRenderer.cpp index 7eb8166..cf24cc1 100644 --- a/src/streaming/video/GLVideoRenderer.cpp +++ b/src/streaming/video/GLVideoRenderer.cpp @@ -1,14 +1,15 @@ #include "GLVideoRenderer.hpp" #include "Logger.hpp" +#ifdef GL_CORE static const char *vertex_shader_string = "\ #version 140\n\ in vec2 position;\n\ out mediump vec2 tex_position;\n\ \ void main() {\n\ -gl_Position = vec4(position, 1, 1);\n\ -tex_position = vec2((position.x + 1.0) / 2.0, (1.0 - position.y) / 2.0);\n\ + gl_Position = vec4(position, 1, 1);\n\ + tex_position = vec2((position.x + 1.0) / 2.0, (1.0 - position.y) / 2.0);\n\ }"; static const char *fragment_shader_string = "\ @@ -22,14 +23,42 @@ in mediump vec2 tex_position;\n\ out vec4 FragColor;\n\ \ void main() {\n\ -vec3 YCbCr = vec3(\n\ -texture(ymap, tex_position).r,\n\ -texture(umap, tex_position).r - 0.0,\n\ -texture(vmap, tex_position).r - 0.0\n\ -);\n\ -YCbCr -= offset;\n\ -FragColor = vec4(clamp(yuvmat * YCbCr, 0.0, 1.0), 1.0);\n\ + vec3 YCbCr = vec3(\n\ + texture(ymap, tex_position).r,\n\ + texture(umap, tex_position).r - 0.0,\n\ + texture(vmap, tex_position).r - 0.0\n\ + );\n\ + YCbCr -= offset;\n\ + FragColor = vec4(clamp(yuvmat * YCbCr, 0.0, 1.0), 1.0);\n\ }"; +#else +static const char *vertex_shader_string = "\ +attribute vec2 position;\n\ +varying vec2 tex_position;\n\ +\ +void main() {\n\ + gl_Position = vec4(position, 1, 1);\n\ + tex_position = vec2((position.x + 1.0) / 2.0, (1.0 - position.y) / 2.0);\n\ +}"; + +static const char *fragment_shader_string = "\ +uniform sampler2D ymap;\n\ +uniform sampler2D umap;\n\ +uniform sampler2D vmap;\n\ +uniform mat3 yuvmat;\n\ +uniform vec3 offset;\n\ +varying vec2 tex_position;\n\ +\ +void main() {\n\ + vec3 YCbCr = vec3(\n\ + texture(ymap, tex_position).r,\n\ + texture(umap, tex_position).r - 0.0,\n\ + texture(vmap, tex_position).r - 0.0\n\ + );\n\ + YCbCr -= offset;\n\ + gl_FragColor = vec4(clamp(yuvmat * YCbCr, 0.0, 1.0), 1.0);\n\ +}"; +#endif static const float vertices[] = { -1.f, -1.f, @@ -92,6 +121,24 @@ static const float* gl_color_matrix(enum AVColorSpace color_space, bool color_fu }; } +static void check_shader(GLuint handle) { + GLint success = 0; + glGetShaderiv(handle, GL_COMPILE_STATUS, &success); + + Logger::info("GL", "GL_COMPILE_STATUS: %i", success); + + if (!success) { + GLint length = 0; + glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &length); + + char* buffer = (char* )malloc(length); + + glGetShaderInfoLog(handle, length, &length, buffer); + Logger::error("GL", "Compile shader error: %s", buffer); + free(buffer); + } +} + GLVideoRenderer::~GLVideoRenderer() { Logger::info("GL", "Cleanup..."); @@ -123,9 +170,11 @@ void GLVideoRenderer::initialize() { glShaderSource(vert, 1, &vertex_shader_string, 0); glCompileShader(vert); + check_shader(vert); glShaderSource(frag, 1, &fragment_shader_string, 0); glCompileShader(frag); + check_shader(frag); glAttachShader(m_shader_program, vert); glAttachShader(m_shader_program, frag);