[Bf-blender-cvs] [5fa3e49] experimental-build: Decklink test build

Benoit Bolsee noreply at git.blender.org
Thu Jun 9 21:31:52 CEST 2016


Commit: 5fa3e490ad643770aca8e4f225b20f1bbf3de6db
Author: Benoit Bolsee
Date:   Thu Jun 9 21:30:43 2016 +0200
Branches: experimental-build
https://developer.blender.org/rB5fa3e490ad643770aca8e4f225b20f1bbf3de6db

Decklink test build

===================================================================

M	CMakeLists.txt
M	build_files/cmake/macros.cmake
A	doc/python_api/examples/bge.texture.2.py
M	doc/python_api/rst/bge.logic.rst
M	doc/python_api/rst/bge.render.rst
M	doc/python_api/rst/bge.texture.rst
M	doc/python_api/rst/bge_types/bge.types.BL_Shader.rst
M	intern/CMakeLists.txt
M	intern/atomic/intern/atomic_ops_unix.h
A	intern/decklink/CMakeLists.txt
A	intern/decklink/DeckLinkAPI.cpp
A	intern/decklink/DeckLinkAPI.h
A	intern/decklink/linux/DeckLinkAPI.h
A	intern/decklink/linux/DeckLinkAPIConfiguration.h
A	intern/decklink/linux/DeckLinkAPIConfiguration_v10_2.h
A	intern/decklink/linux/DeckLinkAPIDeckControl.h
A	intern/decklink/linux/DeckLinkAPIDiscovery.h
A	intern/decklink/linux/DeckLinkAPIDispatch.cpp
A	intern/decklink/linux/DeckLinkAPIDispatch_v7_6.cpp
A	intern/decklink/linux/DeckLinkAPIDispatch_v8_0.cpp
A	intern/decklink/linux/DeckLinkAPIModes.h
A	intern/decklink/linux/DeckLinkAPITypes.h
A	intern/decklink/linux/DeckLinkAPIVersion.h
A	intern/decklink/linux/DeckLinkAPI_v10_2.h
A	intern/decklink/linux/DeckLinkAPI_v7_1.h
A	intern/decklink/linux/DeckLinkAPI_v7_3.h
A	intern/decklink/linux/DeckLinkAPI_v7_6.h
A	intern/decklink/linux/DeckLinkAPI_v7_9.h
A	intern/decklink/linux/DeckLinkAPI_v8_0.h
A	intern/decklink/linux/DeckLinkAPI_v8_1.h
A	intern/decklink/linux/DeckLinkAPI_v9_2.h
A	intern/decklink/linux/DeckLinkAPI_v9_9.h
A	intern/decklink/linux/LinuxCOM.h
A	intern/decklink/win/DeckLinkAPI_h.h
A	intern/decklink/win/DeckLinkAPI_i.c
M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.h
A	intern/gpudirect/CMakeLists.txt
A	intern/gpudirect/dvpapi.cpp
A	intern/gpudirect/dvpapi.h
M	intern/moto/include/MT_Matrix4x4.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/gpu/intern/gpu_texture.c
M	source/blender/python/generic/bgl.c
M	source/blenderplayer/CMakeLists.txt
M	source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
M	source/gameengine/GamePlayer/ghost/GPG_Application.cpp
M	source/gameengine/GamePlayer/ghost/GPG_Application.h
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
M	source/gameengine/Ketsji/BL_Shader.cpp
M	source/gameengine/Ketsji/BL_Shader.h
M	source/gameengine/Ketsji/KX_Dome.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.h
M	source/gameengine/Ketsji/KX_PythonInit.cpp
M	source/gameengine/Ketsji/KX_Scene.cpp
M	source/gameengine/Ketsji/KX_Scene.h
M	source/gameengine/Rasterizer/CMakeLists.txt
A	source/gameengine/Rasterizer/RAS_IOffScreen.h
M	source/gameengine/Rasterizer/RAS_IRasterizer.h
A	source/gameengine/Rasterizer/RAS_ISync.h
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h
M	source/gameengine/VideoTexture/CMakeLists.txt
M	source/gameengine/VideoTexture/Common.h
A	source/gameengine/VideoTexture/DeckLink.cpp
A	source/gameengine/VideoTexture/DeckLink.h
M	source/gameengine/VideoTexture/Exception.cpp
M	source/gameengine/VideoTexture/Exception.h
M	source/gameengine/VideoTexture/FilterBase.h
M	source/gameengine/VideoTexture/FilterSource.h
M	source/gameengine/VideoTexture/ImageBase.cpp
M	source/gameengine/VideoTexture/ImageBase.h
M	source/gameengine/VideoTexture/ImageMix.cpp
M	source/gameengine/VideoTexture/ImageRender.cpp
M	source/gameengine/VideoTexture/ImageRender.h
M	source/gameengine/VideoTexture/ImageViewport.cpp
M	source/gameengine/VideoTexture/ImageViewport.h
M	source/gameengine/VideoTexture/Texture.cpp
M	source/gameengine/VideoTexture/VideoBase.cpp
M	source/gameengine/VideoTexture/VideoBase.h
A	source/gameengine/VideoTexture/VideoDeckLink.cpp
A	source/gameengine/VideoTexture/VideoDeckLink.h
M	source/gameengine/VideoTexture/VideoFFmpeg.cpp
M	source/gameengine/VideoTexture/blendVideoTex.cpp

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b558fe1..1e94bb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -230,6 +230,7 @@ option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported
 mark_as_advanced(WITH_SYSTEM_BULLET)
 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
 option(WITH_PLAYER        "Build Player" OFF)
+option(WITH_DECKLINK      "Support BlackMagicDesign DeckLink cards in the BGE" ON)
 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
 
 # Compositor
@@ -273,6 +274,7 @@ endif()
 if(WITH_X11)
 	option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
 	option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
+	option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
 endif()
 
 if(UNIX AND NOT APPLE)
@@ -723,6 +725,7 @@ if(WITH_GHOST_SDL OR WITH_HEADLESS)
 	set(WITH_X11           OFF)
 	set(WITH_X11_XINPUT    OFF)
 	set(WITH_X11_XF86VMODE OFF)
+	set(WITH_X11_ALPHA     OFF)
 	set(WITH_GHOST_XDND    OFF)
 	set(WITH_INPUT_IME     OFF)
 endif()
@@ -862,6 +865,16 @@ if(WITH_X11)
 		endif()
 	endif()
 
+	if(WITH_X11_ALPHA)
+		find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
+		mark_as_advanced(X11_Xrender_LIB)
+		if (X11_Xrender_LIB)
+			list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
+		else()
+			set(WITH_X11_ALPHA OFF)
+		endif()
+	endif()
+
 endif()
 
 
@@ -3199,6 +3212,7 @@ if(FIRST_RUN)
 
 	info_cfg_text("System Options:")
 	info_cfg_option(WITH_INSTALL_PORTABLE)
+	info_cfg_option(WITH_X11_ALPHA)
 	info_cfg_option(WITH_X11_XF86VMODE)
 	info_cfg_option(WITH_X11_XINPUT)
 	info_cfg_option(WITH_MEM_JEMALLOC)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 3aa938b..15bee2a 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -685,6 +685,14 @@ function(SETUP_BLENDER_SORTED_LIBS)
 		list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
 	endif()
 
+	if(WITH_DECKLINK)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_decklink)
+	endif()
+
+	if(WIN32)
+		list(APPEND BLENDER_SORTED_LIBS bf_intern_gpudirect)
+	endif()
+
 	if(WITH_OPENSUBDIV)
 		list(APPEND BLENDER_SORTED_LIBS bf_intern_opensubdiv)
 	endif()
diff --git a/doc/python_api/examples/bge.texture.2.py b/doc/python_api/examples/bge.texture.2.py
new file mode 100644
index 0000000..f7e0170
--- /dev/null
+++ b/doc/python_api/examples/bge.texture.2.py
@@ -0,0 +1,239 @@
+"""
+Video Capture with DeckLink
++++++++++++++++++++++++++++
+Video frames captured with DeckLink cards have pixel formats that are generally not directly
+usable by OpenGL, they must be processed by a shader. The three shaders presented here should
+cover all common video capture cases.
+
+This file reflects the current video transfer method implemented in the Decklink module:
+whenever possible the video images are transferred as float texture because this is more 
+compatible with GPUs. Of course, only the pixel formats that have a correspondant GL format
+can be transferred as float. Look for fg_shaders in this file for an exhaustive list.
+
+Other pixel formats will be transferred as 32 bits integer red-channel texture but this
+won't work with certain GPU (Intel GMA); the corresponding shaders are not shown here. 
+However, it should not be necessary to use any of them as the list below covers all practical
+cases of video capture with all types of Decklink product.
+
+In other words, only use one of the pixel format below and you will be fine. Note that depending
+on the video stream, only certain pixel formats will be allowed (others will throw an exception).
+For example, to capture a PAL video stream, you must use one of the YUV formats. 
+
+To find which pixel format is suitable for a particular video stream, use the 'Media Express'
+utility that comes with the Decklink software : if you see the video in the 'Log and Capture'
+Window, you have selected the right pixel format and you can use the same in Blender.
+
+Notes: * these shaders only decode the RGB channel and set the alpha channel to a fixed
+value (look for color.a = ). It's up to you to add postprocessing to the color.
+       * these shaders are compatible with 2D and 3D video stream
+"""
+import bge
+from bge import logic
+from bge import texture as vt
+
+# The default vertex shader, because we need one
+#
+VertexShader = """
+#version 130
+   void main()
+   {
+      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+      gl_TexCoord[0] = gl_MultiTexCoord0;
+   }
+    
+"""
+
+# For use with RGB video stream: the pixel is directly usable
+#
+FragmentShader_R10l = """
+    #version 130
+    uniform sampler2D tex;
+    // stereo = 1.0 if 2D image, =0.5 if 3D (left eye below, right eye above)
+    uniform float stereo;
+    // eye = 0.0 for the left eye, 0.5 for the right eye
+    uniform float eye;
+
+    void main(void)
+    {
+        vec4 color;
+        float tx, ty;
+        tx = gl_TexCoord[0].x;
+        ty = eye+gl_TexCoord[0].y*stereo;
+        color = texture(tex, vec2(tx,ty));
+        color.a = 0.7;
+        gl_FragColor = color; 
+    }
+"""
+
+# For use with YUV video stream
+#
+FragmentShader_2vuy = """
+    #version 130
+    uniform sampler2D tex; 
+    // stereo = 1.0 if 2D image, =0.5 if 3D (left eye below, right eye above)
+    uniform float stereo;
+    // eye = 0.0 for the left eye, 0.5 for the right eye
+    uniform float eye;
+
+    void main(void) 
+    {
+        vec4 color;
+        float tx, ty, width, Y, Cb, Cr; 
+        int px;
+        tx = gl_TexCoord[0].x; 
+        ty = eye+gl_TexCoord[0].y*stereo;
+        width = float(textureSize(tex, 0).x);
+        color = texture(tex, vec2(tx, ty));
+        px = int(floor(fract(tx*width)*2.0));
+        switch (px) {
+        case 0:
+            Y = color.g;
+            break;
+        case 1:
+            Y = color.a;
+            break;
+        }
+        Y = (Y - 0.0625) * 1.168949772; 
+        Cb = (color.b - 0.0625) * 1.142857143 - 0.5; 
+        Cr = (color.r - 0.0625) * 1.142857143 - 0.5; 
+        color.r = Y + 1.5748 * Cr; 
+        color.g = Y - 0.1873 * Cb - 0.4681 * Cr;
+        color.b = Y + 1.8556 * Cb;
+        color.a = 0.7;
+        gl_FragColor = color; 
+    }
+"""
+
+# For use with high resolution YUV
+#
+FragmentShader_v210 = """
+    #version 130
+    uniform sampler2D tex; 
+    // stereo = 1.0 if 2D image, =0.5 if 3D (left eye below, right eye above)
+    uniform float stereo;
+    // eye = 0.0 for the left eye, 0.5 for the right eye
+    uniform float eye;
+
+    void main(void) 
+    {
+        vec4 color, color1, color2, color3;
+        int px;
+        float tx, ty, width, sx, dx, bx, Y, Cb, Cr; 
+        tx = gl_TexCoord[0].x; 
+        ty = eye+gl_TexCoord[0].y*stereo; 
+        width = float(textureSize(tex, 0).x);
+        // to sample macro pixels (6 pixels in 4 words)
+        sx = tx*width*0.25+0.01;
+        // index of display pixel in the macro pixel 0..5
+        px = int(floor(fract(sx)*6.0));
+        // increment as we sample the macro pixel
+        dx = 1.0/width;
+        // base x coord of macro pixel
+        bx = (floor(sx)+0.01)*dx*4.0;
+        color = texture(tex, vec2(bx, ty));
+        color1 = texture(tex, vec2(bx+dx, ty));
+        color2 = texture(tex, vec2(bx+dx*2.0, ty));
+        color3 = texture(tex, vec2(bx+dx*3.0, ty));
+        switch (px) {
+        case 0:
+        case 1:
+            Cb = color.b;
+            Cr = color.r;
+            break;
+        case 2:
+        case 3:
+            Cb = color1.g;
+            Cr = color2.b;
+            break;
+        default:
+            Cb = color2.r;
+            Cr = color3.g;
+            break;
+        }
+        switch (px) {
+        case 0:
+            Y = color.g;
+            break;
+        case 1:
+            Y = color1.b;
+            break;
+        case 2:
+            Y = color1.r;
+            break;
+        case 3:
+            Y = color2.g;
+            break;
+        case 4:
+            Y = color3.b;
+            break;
+        default:
+            Y = color3.r;
+            break;
+        }
+        Y = (Y - 0.0625) * 1.168949772; 
+        Cb = (Cb - 0.0625) * 1.142857143 - 0.5; 
+        Cr = (Cr - 0.0625) * 1.142857143 - 0.5; 
+        color.r = Y + 1.5748 * Cr; 
+        color.g = Y - 0.1873 * Cb - 0.4681 * Cr;
+        color.b = Y + 1.8556 * Cb;
+        color.a = 0.7;
+        gl_FragColor = color; 
+    }
+"""
+
+# The exhausitve list of pixel formats that are transferred as float texture
+# Only use those for greater efficiency and compatiblity.
+#
+fg_shaders = {
+    '2vuy'       :FragmentShader_2vuy,
+    '8BitYUV'    :FragmentShader_2vuy,
+    'v210'       :FragmentShader_v210,
+    '10BitYUV'   :FragmentShader_v210,
+    '8BitBGRA'   :FragmentShader_R10l,
+    'BGRA'       :FragmentShader_R10l,
+    '8BitARGB'   :FragmentShader_R10l,
+    '10BitRGBXLE':FragmentShader_R10l,
+    'R10l'       :FragmentShader_R10l
+    }
+
+
+    
+
+#
+# Helper function to attach a pixel shader to the material that receives the video frame.
+#
+
+def config_video(obj, format, pixel, is3D=False, mat=0, card=0):
+    if not pixel in fg_shaders:
+        raise('Unsuported shader')
+    shader = obj.meshes[0].materials[mat].getShader()
+    if shader != None and not shader.isValid():
+        shader.setSource(VertexShader, fg_shaders[pixel], True)
+        shader.setSampler('tex', 0)
+        shader.setUniformEyef("eye")
+        shader.setUniform1f("stereo", 0.5 if is3D else 1.0)
+    tex = vt.Texture(obj, mat)
+    tex.source = vt.VideoDeckLink(format + "/" + pixel + ("/3D" if is3D else ""), card)
+    print("frame rate: ", tex.source.framerate)
+    tex.source.play()
+    obj["video"] = tex
+
+#
+# Attach this function to an object that has a material with texture
+# and call it once to initialize the object
+# 
+def init(cont):
+    #config_video(cont.owner, 'HD720p5994', '8BitBGRA')    
+    #config_video(cont.owner, 'HD720p5994', '8BitYUV')    
+    #config_video(cont.owner, 'pal ', '10BitYUV')    
+    config_video(cont.owner, 'pal ', '8BitYUV')    
+       

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list