Few fixes for run on Windows

This commit is contained in:
Andrey Konoplyankin 2021-04-24 19:55:17 +03:00
parent 8698e3e5f0
commit f2507d5a39
4 changed files with 68 additions and 10 deletions

View file

@ -6,6 +6,12 @@
#include <limits.h>
#include <sys/stat.h>
#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;

View file

@ -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;

View file

@ -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;

View file

@ -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);