Commit 314ba92f authored by Ghislain MARY's avatar Ghislain MARY

Enable generic OpenGL display filter on Windows.

parent b0f14b97
......@@ -95,6 +95,7 @@ cmake_dependent_option(ENABLE_RESAMPLE "Build mediastreamer2 with the resampling
option(ENABLE_VIDEO "Build mediastreamer2 with video support." YES)
cmake_dependent_option(ENABLE_FFMPEG "Build mediastreamer2 with ffmpeg video support." YES "ENABLE_VIDEO" NO)
cmake_dependent_option(ENABLE_GL "Enable generic OpenGL rendering support." YES "ENABLE_VIDEO" NO)
cmake_dependent_option(ENABLE_GLX "Enable X11+OpenGL rendering support (requires glx and glew)." ${ENABLE_GLX_DEFAULT_VALUE} "ENABLE_VIDEO;UNIX" NO)
cmake_dependent_option(ENABLE_SDL "Enable SDL support." NO "ENABLE_FFMPEG" NO)
cmake_dependent_option(ENABLE_V4L "Enable Video4Linux support." YES "ENABLE_VIDEO;LINUX_OR_BSD" NO)
......@@ -270,10 +271,27 @@ if(ENABLE_XV)
set(ENABLE_XV OFF CACHE BOOL "Enable XV support." FORCE)
endif()
endif()
if(ENABLE_GL)
if(WIN32)
find_package(Qt5 COMPONENTS Gui)
if(Qt5Gui_FOUND)
set(HAVE_GL 1)
else()
set(ENABLE_GL OFF CACHE BOOL "Enable generic OpenGL rendering support." FORCE)
endif()
else()
find_package(GL)
if(GL_FOUND)
set(HAVE_GL 1)
else()
set(ENABLE_GL OFF CACHE BOOL "Enable generic OpenGL rendering support." FORCE)
endif()
endif()
endif()
if(ENABLE_GLX)
find_package(GLX)
if(GLX_FOUND)
set(HAVE_GL 1)
set(HAVE_GLX 1)
else()
set(ENABLE_GLX OFF CACHE BOOL "Enable X11+OpenGL rendering support (requires glx and glew)." FORCE)
endif()
......@@ -408,6 +426,12 @@ endif()
if(XV_FOUND)
include_directories(${XV_INCLUDE_DIRS})
endif()
if(Qt5Gui_FOUND)
include_directories(${Qt5Gui_INCLUDE_DIRS} ${Qt5Gui_EGL_INCLUDE_DIRS})
endif()
if(GL_FOUND)
include_directories(${GL_INCLUDE_DIRS})
endif()
if(GLX_FOUND)
include_directories(${GLX_INCLUDE_DIRS})
endif()
......
############################################################################
# FindGL.txt
# Copyright (C) 2014 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
#
# - Find the GL include file and library
#
# GL_FOUND - system has GL
# GL_INCLUDE_DIRS - the GL include directory
# GL_LIBRARIES - The libraries needed to use GL
include(CheckIncludeFile)
include(CheckSymbolExists)
find_path(GL_INCLUDE_DIRS
NAMES GL/gl.h
PATH_SUFFIXES include
)
if(GL_INCLUDE_DIRS)
if(WIN32)
check_include_file(GL/gl.h HAVE_GL_GL_H "-include windows.h")
else()
check_include_file(GL/gl.h HAVE_GL_GL_H)
endif()
endif()
find_library(GL_LIBRARY
NAMES GL
PATH_SUFFIXES bin lib
)
if(GL_LIBRARIES)
# TODO: check symbols in gl
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GL
DEFAULT_MSG
GL_INCLUDE_DIRS HAVE_GL_GL_H GL_LIBRARIES
)
mark_as_advanced(GL_INCLUDE_DIRS HAVE_GL_GL_H GL_LIBRARIES)
......@@ -48,6 +48,11 @@ if(@ENABLE_ZRTP@)
find_package(BZRTP)
endif()
endif()
if(@ENABLE_GL@)
if(WIN32)
find_package(Qt5 COMPONENTS Gui)
endif()
endif()
get_filename_component(MEDIASTREAMER2_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
......@@ -70,6 +75,10 @@ if(BZRTP_FOUND)
list(APPEND MEDIASTREAMER2_INCLUDE_DIRS ${BZRTP_INCLUDE_DIRS})
list(APPEND MEDIASTREAMER2_LIBRARIES ${BZRTP_LIBRARIES})
endif()
if(Qt5Gui_FOUND)
list(APPEND MEDIASTREAMER2_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Gui_EGL_INCLUDE_DIRS})
list(APPEND MEDIASTREAMER2_LIBRARIES ${Qt5Gui_LIBRARIES})
endif()
set(MEDIASTREAMER2_CPPFLAGS @MEDIASTREAMER2_CPPFLAGS@)
set(MEDIASTREAMER2_LDFLAGS "@LINK_FLAGS_STR@")
set(MEDIASTREAMER2_FOUND 1)
......@@ -30,8 +30,9 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#elif defined(_WIN32)
#include <windows.h>
#include <GL/gl.h>
#if !defined(QOPENGLFUNCTIONS_H)
#include <GLES2/gl2.h>
#endif
#elif !defined(QOPENGLFUNCTIONS_H) // glew is already included by QT.
#include <GL/glew.h>
#define GLEW_ENABLED 1
......
......@@ -59,6 +59,7 @@
#cmakedefine HAVE_FUN_av_frame_free 1
#cmakedefine HAVE_FUN_av_frame_unref 1
#cmakedefine HAVE_GL 1
#cmakedefine HAVE_GLX 1
#cmakedefine HAVE_X11_XLIB_H 1
#cmakedefine HAVE_XV 1
#cmakedefine HAVE_LINUX_VIDEODEV_H 1
......
......@@ -394,15 +394,17 @@ if(ENABLE_VIDEO)
videofilters/turbojpegwriter.c
)
endif()
if(GLX_FOUND)
if(GL_FOUND OR Qt5Gui_FOUND)
list(APPEND VOIP_SOURCE_FILES_C
utils/opengl_functions.c
utils/opengles_display.c
utils/shader_util.c
videofilters/generic_opengl_display.c
videofilters/glxvideo.c
)
endif()
if(GLX_FOUND)
list(APPEND VOIP_SOURCE_FILES_C videofilters/glxvideo.c)
endif()
if(SDL_FOUND)
list(APPEND VOIP_SOURCE_FILES_C videofilters/videoout.c)
endif()
......@@ -453,7 +455,7 @@ add_custom_target(ms2-voipdescs-header
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/voipdescs.h"
)
if(APPLE OR ANDROID OR GLX_FOUND)
if(APPLE OR ANDROID OR GL_FOUND OR Qt5Gui_FOUND)
find_package(PythonInterp REQUIRED)
find_program(SED_PROGRAM sed)
if(NOT SED_PROGRAM)
......@@ -595,6 +597,12 @@ endif()
if(XV_FOUND)
list(APPEND VOIP_LIBS ${XV_LIBRARIES})
endif()
if(Qt5Gui_FOUND)
list(APPEND VOIP_LIBS ${Qt5Gui_LIBRARIES})
endif()
if(GL_FOUND)
list(APPEND VOIP_LIBS ${GL_LIBRARIES})
endif()
if(GLX_FOUND)
list(APPEND VOIP_LIBS ${GLX_LIBRARIES})
endif()
......@@ -621,7 +629,7 @@ if (BCGG729_FOUND)
list(APPEND VOIP_LIBS ${BCG729_LIBRARIES})
endif()
set(MS2_VOIP_DEPENDENCIES ms2-git-version ms2-voipdescs-header)
if(APPLE OR ANDROID OR GLX_FOUND)
if(APPLE OR ANDROID OR GL_FOUND OR Qt5Gui_FOUND)
list(APPEND MS2_VOIP_DEPENDENCIES ms2-yuv2rgb-fs-header ms2-yuv2rgb-vs-header)
endif()
......
......@@ -35,7 +35,7 @@ enum ImageType {
static void check_GL_errors (const OpenGlFunctions *f, const char *context);
static bool_t load_shaders (const OpenGlFunctions *f, GLuint *program, GLint *uniforms);
static void allocate_gl_textures (struct opengles_display *gldisp, int w, int h, enum ImageType type);
static void load_orthographic_matrix (float left, float right, float bottom, float top, float near, float far, float *mat);
static void load_orthographic_matrix (float left, float right, float bottom, float top, float _near, float _far, float *mat);
static unsigned int align_on_power_of_2 (unsigned int value);
static bool_t update_textures_with_yuv (struct opengles_display *gldisp, enum ImageType type);
......@@ -47,8 +47,14 @@ static bool_t update_textures_with_yuv (struct opengles_display *gldisp, enum Im
(x); \
check_GL_errors(#x); \
} while (0);
#define GL_OPERATION_RET(x, ret) \
do { \
ret = (x); \
check_GL_errors(#x); \
} while (0);
#else
#define GL_OPERATION(x) (x);
#define GL_OPERATION_RET(x, ret) ret = (x);
#endif
enum {
......@@ -171,7 +177,7 @@ void ogl_display_init (struct opengles_display *gldisp, const OpenGlFunctions *f
}
// Update gl functions.
gldisp->functions = f ?: gldisp->default_functions;
gldisp->functions = f ? f : gldisp->default_functions;
f = gldisp->functions;
ms_message("init opengles_display (%d x %d, gl initialized:%d)", width, height, gldisp->glResourcesInitialized);
......@@ -297,8 +303,8 @@ static void ogl_display_render_type(
float uLeft, uRight, vTop, vBottom;
GLfloat squareUvs[8];
GLfloat squareVertices[8];
int screenW, screenH;
int x,y,w,h;
GLfloat screenW, screenH;
GLfloat x,y,w,h;
GLfloat mat[16];
float rad;
......@@ -336,11 +342,11 @@ static void ogl_display_render_type(
GL_OPERATION(f->glClear(GL_COLOR_BUFFER_BIT))
// drawing surface dimensions
screenW = gldisp->backingWidth;
screenH = gldisp->backingHeight;
screenW = (GLfloat)gldisp->backingWidth;
screenH = (GLfloat)gldisp->backingHeight;
if (orientation == 90 || orientation == 270) {
screenW = screenH;
screenH = gldisp->backingWidth;
screenH = (GLfloat)gldisp->backingWidth;
}
// Fill the smallest dimension, then compute the other one using the image ratio
......@@ -365,18 +371,18 @@ static void ogl_display_render_type(
x = vpx * screenW;
y = vpy * screenH;
squareVertices[0] = (x - w * 0.5) / screenW - 0.;
squareVertices[1] = (y - h * 0.5) / screenH - 0.;
squareVertices[2] = (x + w * 0.5) / screenW - 0.;
squareVertices[3] = (y - h * 0.5) / screenH - 0.;
squareVertices[4] = (x - w * 0.5) / screenW - 0.;
squareVertices[5] = (y + h * 0.5) / screenH - 0.;
squareVertices[6] = (x + w * 0.5) / screenW - 0.;
squareVertices[7] = (y + h * 0.5) / screenH - 0.;
squareVertices[0] = (x - w * 0.5f) / screenW;
squareVertices[1] = (y - h * 0.5f) / screenH;
squareVertices[2] = (x + w * 0.5f) / screenW;
squareVertices[3] = (y - h * 0.5f) / screenH;
squareVertices[4] = (x - w * 0.5f) / screenW;
squareVertices[5] = (y + h * 0.5f) / screenH;
squareVertices[6] = (x + w * 0.5f) / screenW;
squareVertices[7] = (y + h * 0.5f) / screenH;
#define VP_SIZE 1.0f
if (type == REMOTE_IMAGE) {
float scale_factor = 1.0 / gldisp->zoom_factor;
float scale_factor = 1.0f / gldisp->zoom_factor;
float vpDim = (VP_SIZE * scale_factor) / 2;
#define ENSURE_RANGE_A_INSIDE_RANGE_B(a, aSize, bMin, bMax) \
......@@ -404,7 +410,7 @@ static void ogl_display_render_type(
GL_OPERATION(f->glUniformMatrix4fv(gldisp->uniforms[UNIFORM_PROJ_MATRIX], 1, GL_FALSE, mat))
rad = (2.0 * 3.14157 * orientation / 360.0); // Convert orientation to radian
rad = (2.0f * 3.14157f * orientation / 360.0f); // Convert orientation to radian
GL_OPERATION(f->glUniform1f(gldisp->uniforms[UNIFORM_ROTATION], rad))
......@@ -481,27 +487,27 @@ static bool_t load_shaders (const OpenGlFunctions *f, GLuint *program, GLint *un
if (!glueLinkProgram(f, *program))
return FALSE;
uniforms[UNIFORM_PROJ_MATRIX] = glGetUniformLocation(*program, "proj_matrix");
uniforms[UNIFORM_ROTATION] = glGetUniformLocation(*program, "rotation");
uniforms[UNIFORM_TEXTURE_Y] = glGetUniformLocation(*program, "t_texture_y");
uniforms[UNIFORM_TEXTURE_U] = glGetUniformLocation(*program, "t_texture_u");
uniforms[UNIFORM_TEXTURE_V] = glGetUniformLocation(*program, "t_texture_v");
GL_OPERATION_RET(f->glGetUniformLocation(*program, "proj_matrix"), uniforms[UNIFORM_PROJ_MATRIX])
GL_OPERATION_RET(f->glGetUniformLocation(*program, "rotation"), uniforms[UNIFORM_ROTATION])
GL_OPERATION_RET(f->glGetUniformLocation(*program, "t_texture_y"), uniforms[UNIFORM_TEXTURE_Y])
GL_OPERATION_RET(f->glGetUniformLocation(*program, "t_texture_u"), uniforms[UNIFORM_TEXTURE_U])
GL_OPERATION_RET(f->glGetUniformLocation(*program, "t_texture_v"), uniforms[UNIFORM_TEXTURE_V])
glDeleteShader(vertShader);
glDeleteShader(fragShader);
GL_OPERATION(f->glDeleteShader(vertShader))
GL_OPERATION(f->glDeleteShader(fragShader))
return TRUE;
check_GL_errors(f, "load_shaders");
}
static void load_orthographic_matrix (float left, float right, float bottom, float top, float near, float far, float *mat) {
static void load_orthographic_matrix (float left, float right, float bottom, float top, float _near, float _far, float *mat) {
float r_l = right - left;
float t_b = top - bottom;
float f_n = far - near;
float f_n = _far - _near;
float tx = - (right + left) / (right - left);
float ty = - (top + bottom) / (top - bottom);
float tz = - (far + near) / (far - near);
float tz = - (_far + _near) / (_far - _near);
mat[0] = (2.0f / r_l);
mat[1] = mat[2] = mat[3] = 0.0f;
......@@ -650,8 +656,8 @@ static bool_t update_textures_with_yuv (struct opengles_display *gldisp, enum Im
void ogl_display_zoom (struct opengles_display *gldisp, float *params) {
gldisp->zoom_factor = params[0];
gldisp->zoom_cx = params[1] - 0.5;
gldisp->zoom_cy = params[2] - 0.5;
gldisp->zoom_cx = params[1] - 0.5f;
gldisp->zoom_cy = params[2] - 0.5f;
}
#ifdef ANDROID
......
......@@ -242,7 +242,7 @@ const char *video_stream_get_default_video_renderer(void){
return "MSOSXGLDisplay";
#elif defined (HAVE_XV)
return "MSX11Video";
#elif defined(HAVE_GL)
#elif defined(HAVE_GLX)
return "MSGLXVideo";
#elif defined(__ios)
return "IOSDisplay";
......
......@@ -280,7 +280,7 @@ static void setup_media_streams(MediastreamDatas *args) {
MSVideoSize disp_size;
int tmp = 1;
#if defined(HAVE_GL)
#if defined(HAVE_GLX)
display_name = "MSGLXVideo";
#elif defined(HAVE_XV)
display_name = "MSX11Video";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment