2012-09-16 11:23:09 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2012 Matthew Waters <ystree00@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-09-16 11:23:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-07-10 15:03:04 +00:00
|
|
|
#include "gl.h"
|
2012-09-16 11:23:09 +00:00
|
|
|
#include "gstgldownload.h"
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstgldownload
|
|
|
|
* @short_description: an object that downloads GL textures
|
|
|
|
* @see_also: #GstGLUpload, #GstGLMemory
|
|
|
|
*
|
|
|
|
* #GstGLDownload is an object that downloads GL textures into system memory.
|
|
|
|
*
|
2013-07-18 09:37:32 +00:00
|
|
|
* A #GstGLDownload can be created with gst_gl_download_new()
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL)
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL3)
|
|
|
|
#define USING_GLES(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES)
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2)
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES3)
|
|
|
|
|
|
|
|
static void _do_download (GstGLContext * context, GstGLDownload * download);
|
|
|
|
static void _init_download (GstGLContext * context, GstGLDownload * download);
|
|
|
|
static gboolean _init_download_shader (GstGLContext * context,
|
2012-09-16 11:23:09 +00:00
|
|
|
GstGLDownload * download);
|
2013-07-18 09:37:32 +00:00
|
|
|
static gboolean _gst_gl_download_perform_with_data_unlocked (GstGLDownload *
|
2012-09-16 11:23:09 +00:00
|
|
|
download, GLuint texture_id, gpointer data[GST_VIDEO_MAX_PLANES]);
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-09-15 04:23:43 +00:00
|
|
|
static void _do_download_draw_rgb_opengl (GstGLContext * context,
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLDownload * download);
|
2013-09-15 04:23:43 +00:00
|
|
|
static void _do_download_draw_yuv_opengl (GstGLContext * context,
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLDownload * download);
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-09-15 04:23:43 +00:00
|
|
|
static void _do_download_draw_rgb_gles2 (GstGLContext * context,
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLDownload * download);
|
2013-09-15 04:23:43 +00:00
|
|
|
static void _do_download_draw_yuv_gles2 (GstGLContext * context,
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLDownload * download);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
|
2014-03-24 13:50:30 +00:00
|
|
|
/* FIXME: use the colormatrix support from videoconvert */
|
|
|
|
|
2013-07-12 12:20:05 +00:00
|
|
|
#define RGB_TO_YUV_COEFFICIENTS \
|
2014-03-24 13:50:30 +00:00
|
|
|
"uniform vec3 offset;\n" \
|
|
|
|
"uniform vec3 ycoeff;\n" \
|
|
|
|
"uniform vec3 ucoeff;\n" \
|
|
|
|
"uniform vec3 vcoeff;\n"
|
|
|
|
|
|
|
|
/* Matrix inverses of the color matrices found in gstglupload */
|
|
|
|
/* BT. 601 standard with the following ranges:
|
|
|
|
* Y = [16..235] (of 255)
|
|
|
|
* Cb/Cr = [16..240] (of 255)
|
|
|
|
*/
|
|
|
|
static const gfloat bt601_offset[] = {0.0625, 0.5, 0.5};
|
|
|
|
static const gfloat bt601_ycoeff[] = {0.256816, 0.504154, 0.0979137};
|
|
|
|
static const gfloat bt601_ucoeff[] = {-0.148246, -0.29102, 0.439266};
|
|
|
|
static const gfloat bt601_vcoeff[] = {0.439271, -0.367833, -0.071438};
|
|
|
|
|
|
|
|
/* BT. 709 standard with the following ranges:
|
|
|
|
* Y = [16..235] (of 255)
|
|
|
|
* Cb/Cr = [16..240] (of 255)
|
|
|
|
*/
|
|
|
|
static const gfloat bt709_offset[] = {0.0625, 0.5, 0.5};
|
|
|
|
static const gfloat bt709_ycoeff[] = {0.213392, 0.718140,-0.072426};
|
|
|
|
static const gfloat bt709_ucoeff[] = {0.117608, 0.395793,-0.513401};
|
|
|
|
static const gfloat bt709_vcoeff[] = {0.420599,-0.467775, 0.047176};
|
|
|
|
|
2013-07-12 12:20:05 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2012-09-16 11:23:09 +00:00
|
|
|
/* YUY2:y2,u,y1,v
|
|
|
|
UYVY:v,y1,u,y2 */
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_YUY2_UYVY_opengl =
|
2013-11-15 07:28:49 +00:00
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform float width;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
RGB_TO_YUV_COEFFICIENTS
|
2012-12-06 07:40:26 +00:00
|
|
|
"void main(void) {\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" vec3 rgb1, rgb2;\n"
|
|
|
|
" float fx,fy,y1,y2,u,v;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" fx = gl_TexCoord[0].x;\n"
|
|
|
|
" fy = gl_TexCoord[0].y;\n"
|
2013-11-15 07:28:49 +00:00
|
|
|
" rgb1=texture2D(tex,vec2(fx*2.0,fy)).rgb;\n"
|
|
|
|
" rgb2=texture2D(tex,vec2(fx*2.0+1.0/width,fy)).rgb;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" y1=dot(rgb1, ycoeff);\n"
|
|
|
|
" y2=dot(rgb2, ycoeff);\n"
|
|
|
|
" u=dot(rgb1, ucoeff);\n"
|
|
|
|
" v=dot(rgb1, vcoeff);\n"
|
|
|
|
" y1+=offset.x;\n"
|
|
|
|
" y2+=offset.x;\n"
|
|
|
|
" u+=offset.y;\n"
|
|
|
|
" v+=offset.z;\n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" gl_FragColor=vec4(%s);\n"
|
|
|
|
"}\n";
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_I420_YV12_opengl =
|
2013-11-15 07:28:49 +00:00
|
|
|
"uniform sampler2D tex;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
"uniform float w, h;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
RGB_TO_YUV_COEFFICIENTS
|
2012-09-16 11:23:09 +00:00
|
|
|
"void main(void) {\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" vec3 rgb1, rgb2;\n"
|
|
|
|
" float y,u,v;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" vec2 nxy=gl_TexCoord[0].xy;\n"
|
|
|
|
" vec2 nxy2=nxy*2.0;\n"
|
2013-11-15 07:28:49 +00:00
|
|
|
" rgb1=texture2D(tex,nxy).rgb;\n"
|
|
|
|
" rgb2=texture2D(tex,nxy2).rgb;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" y=dot(rgb1, ycoeff);\n"
|
|
|
|
" u=dot(rgb2, ucoeff);\n"
|
|
|
|
" v=dot(rgb2, vcoeff);\n"
|
|
|
|
" y+=offset.x;\n"
|
|
|
|
" u+=offset.y;\n"
|
|
|
|
" v+=offset.z;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" gl_FragData[0] = vec4(y, 0.0, 0.0, 1.0);\n"
|
|
|
|
" gl_FragData[1] = vec4(u, 0.0, 0.0, 1.0);\n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" gl_FragData[2] = vec4(v, 0.0, 0.0, 1.0);\n"
|
|
|
|
"}\n";
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_AYUV_opengl =
|
2013-11-15 07:28:49 +00:00
|
|
|
"uniform sampler2D tex;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
RGB_TO_YUV_COEFFICIENTS
|
2012-12-06 07:40:26 +00:00
|
|
|
"void main(void) {\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" vec3 rgb;\n"
|
|
|
|
" float y,u,v;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" vec2 nxy=gl_TexCoord[0].xy;\n"
|
2013-11-15 07:28:49 +00:00
|
|
|
" rgb=texture2D(tex,nxy).rgb;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" y=dot(rgb, ycoeff);\n"
|
|
|
|
" u=dot(rgb, ucoeff);\n"
|
|
|
|
" v=dot(rgb, vcoeff);\n"
|
|
|
|
" y+=offset.x;\n"
|
|
|
|
" u+=offset.y;\n"
|
|
|
|
" v+=offset.z;\n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" gl_FragColor=vec4(y,u,v,1.0);\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
#define text_vertex_shader_opengl NULL
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_OPENGL */
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_YUY2_UYVY_gles2 =
|
2012-12-06 07:40:26 +00:00
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texCoord;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
RGB_TO_YUV_COEFFICIENTS
|
2012-12-06 07:40:26 +00:00
|
|
|
"void main(void) {\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" vec3 rgb1, rgb2;\n"
|
|
|
|
" float fx,fy,y1,y2,u,v;\n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" fx = v_texCoord.x;\n"
|
|
|
|
" fy = v_texCoord.y;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" rgb1=texture2D(tex,vec2(fx*2.0,fy)).rgb;\n"
|
|
|
|
" rgb2=texture2D(tex,vec2(fx*2.0+1.0,fy)).rgb;\n"
|
|
|
|
" y1=dot(rgb1, ycoeff);\n"
|
|
|
|
" y2=dot(rgb2, ycoeff);\n"
|
|
|
|
" u=dot(rgb1, ucoeff);\n"
|
|
|
|
" v=dot(rgb1, vcoeff);\n"
|
|
|
|
" y1+=offset.x;\n"
|
|
|
|
" y2+=offset.x;\n"
|
|
|
|
" u+=offset.y;\n"
|
|
|
|
" v+=offset.z;\n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" gl_FragColor=vec4(%s);\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
/* no OpenGL ES 2.0 support because for now it's not possible
|
|
|
|
* to attach multiple textures to a frame buffer object
|
|
|
|
*/
|
|
|
|
#define text_shader_I420_YV12_gles2 NULL
|
|
|
|
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_AYUV_gles2 =
|
2012-12-06 07:40:26 +00:00
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texCoord;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
RGB_TO_YUV_COEFFICIENTS
|
2012-12-06 07:40:26 +00:00
|
|
|
"void main(void) {\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" vec3 rgb;\n"
|
|
|
|
" float y,u,v;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" vec2 nxy=v_texCoord.xy;\n"
|
2013-07-12 12:20:05 +00:00
|
|
|
" rgb=texture2D(tex,nxy).rgb;\n"
|
|
|
|
" y=dot(rgb, ycoeff);\n"
|
|
|
|
" u=dot(rgb, ucoeff);\n"
|
|
|
|
" v=dot(rgb, vcoeff);\n"
|
|
|
|
" y+=offset.x;\n"
|
|
|
|
" u+=offset.y;\n"
|
|
|
|
" v+=offset.z;\n"
|
2012-09-16 11:23:09 +00:00
|
|
|
" gl_FragColor=vec4(1.0,y,u,v);\n"
|
|
|
|
"}\n";
|
|
|
|
|
2013-07-15 15:08:42 +00:00
|
|
|
static const gchar *text_shader_ARGB_gles2 =
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"varying vec2 v_texCoord;\n"
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"void main(void) {\n"
|
|
|
|
" vec4 rgba;\n"
|
|
|
|
" vec2 nxy = v_texCoord.xy;\n"
|
|
|
|
" rgba.rgb=texture2D(tex,nxy).rgb;\n"
|
|
|
|
" rgba.a = 1.0;\n"
|
|
|
|
" gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n"
|
|
|
|
"}\n";
|
|
|
|
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_vertex_shader_gles2 =
|
2012-09-16 11:23:09 +00:00
|
|
|
"attribute vec4 a_position; \n"
|
|
|
|
"attribute vec2 a_texCoord; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
|
|
|
" gl_Position = a_position; \n"
|
2012-12-06 07:40:26 +00:00
|
|
|
" v_texCoord = a_texCoord; \n"
|
|
|
|
"} \n";
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-12 12:26:58 +00:00
|
|
|
static const gchar *text_shader_RGB_gles2 =
|
2012-09-16 11:23:09 +00:00
|
|
|
"precision mediump float; \n"
|
|
|
|
"varying vec2 v_texCoord; \n"
|
2013-07-15 15:08:42 +00:00
|
|
|
"uniform sampler2D tex; \n"
|
2012-09-16 11:23:09 +00:00
|
|
|
"void main() \n"
|
|
|
|
"{ \n"
|
2013-07-15 15:08:42 +00:00
|
|
|
" gl_FragColor = texture2D(tex, v_texCoord ); \n"
|
2012-09-16 11:23:09 +00:00
|
|
|
"} \n";
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_GLES2 */
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
struct _GstGLDownloadPrivate
|
|
|
|
{
|
|
|
|
const gchar *YUY2_UYVY;
|
|
|
|
const gchar *I420_YV12;
|
|
|
|
const gchar *AYUV;
|
2013-07-15 15:08:42 +00:00
|
|
|
const gchar *ARGB;
|
2012-12-06 07:40:26 +00:00
|
|
|
const gchar *vert_shader;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
void (*do_rgb) (GstGLContext * context, GstGLDownload * download);
|
|
|
|
void (*do_yuv) (GstGLContext * context, GstGLDownload * download);
|
2013-07-19 06:48:03 +00:00
|
|
|
|
|
|
|
gboolean result;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_download_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_download_debug
|
|
|
|
|
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_download_debug, "gldownload", 0, "download");
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDownload, gst_gl_download, G_TYPE_OBJECT,
|
|
|
|
DEBUG_INIT);
|
|
|
|
static void gst_gl_download_finalize (GObject * object);
|
|
|
|
|
|
|
|
#define GST_GL_DOWNLOAD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
|
|
|
|
GST_TYPE_GL_DOWNLOAD, GstGLDownloadPrivate))
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_download_class_init (GstGLDownloadClass * klass)
|
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLDownloadPrivate));
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_download_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_download_init (GstGLDownload * download)
|
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
download->priv = GST_GL_DOWNLOAD_GET_PRIVATE (download);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
download->context = NULL;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
g_mutex_init (&download->lock);
|
|
|
|
|
|
|
|
download->fbo = 0;
|
|
|
|
download->depth_buffer = 0;
|
|
|
|
download->in_texture = 0;
|
|
|
|
download->shader = NULL;
|
|
|
|
|
|
|
|
download->shader_attr_position_loc = 0;
|
|
|
|
download->shader_attr_texture_loc = 0;
|
|
|
|
|
|
|
|
gst_video_info_init (&download->info);
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_download_new:
|
2013-09-15 04:23:43 +00:00
|
|
|
* @context: a #GstGLContext
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
|
|
|
* Returns: a new #GstGLDownload object
|
|
|
|
*/
|
2012-09-16 11:23:09 +00:00
|
|
|
GstGLDownload *
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_download_new (GstGLContext * context)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
|
|
|
GstGLDownload *download;
|
2012-12-06 07:40:26 +00:00
|
|
|
GstGLDownloadPrivate *priv;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
download = g_object_new (GST_TYPE_GL_DOWNLOAD, NULL);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
download->context = gst_object_ref (context);
|
2012-12-06 07:40:26 +00:00
|
|
|
priv = download->priv;
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_OPENGL (context)) {
|
2012-12-06 07:40:26 +00:00
|
|
|
priv->YUY2_UYVY = text_shader_YUY2_UYVY_opengl;
|
|
|
|
priv->I420_YV12 = text_shader_I420_YV12_opengl;
|
|
|
|
priv->AYUV = text_shader_AYUV_opengl;
|
2013-07-15 15:08:42 +00:00
|
|
|
priv->ARGB = NULL;
|
2012-12-06 07:40:26 +00:00
|
|
|
priv->vert_shader = text_vertex_shader_opengl;
|
|
|
|
priv->do_rgb = _do_download_draw_rgb_opengl;
|
|
|
|
priv->do_yuv = _do_download_draw_yuv_opengl;
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_GLES2 (context)) {
|
2012-12-06 07:40:26 +00:00
|
|
|
priv->YUY2_UYVY = text_shader_YUY2_UYVY_gles2;
|
|
|
|
priv->I420_YV12 = text_shader_I420_YV12_gles2;
|
|
|
|
priv->AYUV = text_shader_AYUV_gles2;
|
2013-07-15 15:08:42 +00:00
|
|
|
priv->ARGB = text_shader_ARGB_gles2;
|
2012-12-06 07:40:26 +00:00
|
|
|
priv->vert_shader = text_vertex_shader_gles2;
|
|
|
|
priv->do_rgb = _do_download_draw_rgb_gles2;
|
|
|
|
priv->do_yuv = _do_download_draw_yuv_gles2;
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
return download;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_download_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLDownload *download;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
download = GST_GL_DOWNLOAD (object);
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
|
|
|
if (download->out_texture[i]) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_del_texture (download->context, &download->out_texture[i]);
|
2012-09-16 11:23:09 +00:00
|
|
|
download->out_texture[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
if (download->in_texture) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_del_texture (download->context, &download->in_texture);
|
2012-09-16 11:23:09 +00:00
|
|
|
download->in_texture = 0;
|
|
|
|
}
|
|
|
|
if (download->fbo || download->depth_buffer) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_del_fbo (download->context, download->fbo,
|
2012-09-16 11:23:09 +00:00
|
|
|
download->depth_buffer);
|
|
|
|
download->fbo = 0;
|
|
|
|
download->depth_buffer = 0;
|
|
|
|
}
|
|
|
|
if (download->shader) {
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (download->shader);
|
2012-09-16 11:23:09 +00:00
|
|
|
download->shader = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (download->context) {
|
|
|
|
gst_object_unref (download->context);
|
|
|
|
download->context = NULL;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_clear (&download->lock);
|
2013-06-13 04:36:41 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_gl_download_parent_class)->finalize (object);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_download_init_format:
|
|
|
|
* @download: a #GstGLDownload
|
|
|
|
* @v_format: a #GstVideoFormat
|
|
|
|
* @out_width: the width to download to
|
|
|
|
* @out_height: the height to download to
|
|
|
|
*
|
|
|
|
* Initializes @download with the information required for download.
|
|
|
|
*
|
|
|
|
* Returns: whether the initialization was successful
|
|
|
|
*/
|
2012-09-18 11:39:21 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_download_init_format (GstGLDownload * download, GstVideoFormat v_format,
|
2012-09-25 05:20:21 +00:00
|
|
|
guint out_width, guint out_height)
|
2012-09-18 11:39:21 +00:00
|
|
|
{
|
|
|
|
GstVideoInfo info;
|
2013-07-19 06:48:03 +00:00
|
|
|
gboolean ret;
|
2012-09-18 11:39:21 +00:00
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
g_return_val_if_fail (download != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (v_format != GST_VIDEO_FORMAT_UNKNOWN, FALSE);
|
|
|
|
g_return_val_if_fail (v_format != GST_VIDEO_FORMAT_ENCODED, FALSE);
|
|
|
|
g_return_val_if_fail (out_width > 0 && out_height > 0, FALSE);
|
2012-09-18 11:39:21 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
g_mutex_lock (&download->lock);
|
|
|
|
|
2012-09-18 11:39:21 +00:00
|
|
|
if (download->initted) {
|
|
|
|
g_mutex_unlock (&download->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:20:21 +00:00
|
|
|
gst_video_info_set_format (&info, v_format, out_width, out_height);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
download->info = info;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_thread_add (download->context,
|
|
|
|
(GstGLContextThreadFunc) _init_download, download);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-19 06:48:03 +00:00
|
|
|
ret = download->initted = download->priv->result;
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
g_mutex_unlock (&download->lock);
|
|
|
|
|
2013-07-19 06:48:03 +00:00
|
|
|
return ret;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_download_perform_with_memory:
|
|
|
|
* @download: a #GstGLDownload
|
|
|
|
* @gl_mem: a #GstGLMemory
|
|
|
|
*
|
|
|
|
* Downloads the texture in @gl_mem
|
|
|
|
*
|
|
|
|
* Returns: whether the download was successful
|
|
|
|
*/
|
2012-09-18 11:39:21 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_download_perform_with_memory (GstGLDownload * download,
|
|
|
|
GstGLMemory * gl_mem)
|
|
|
|
{
|
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES];
|
|
|
|
guint i;
|
|
|
|
gboolean ret;
|
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
if (!GST_GL_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_MEMORY_FLAG_DOWNLOAD_INITTED))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!GST_GL_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD)) {
|
2012-09-18 11:39:21 +00:00
|
|
|
return FALSE;
|
2013-07-18 09:37:32 +00:00
|
|
|
}
|
2012-09-18 11:39:21 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
g_mutex_lock (&download->lock);
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&download->info); i++) {
|
|
|
|
data[i] = (guint8 *) gl_mem->data +
|
|
|
|
GST_VIDEO_INFO_PLANE_OFFSET (&download->info, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret =
|
2013-07-18 09:37:32 +00:00
|
|
|
_gst_gl_download_perform_with_data_unlocked (download, gl_mem->tex_id,
|
2012-09-16 11:23:09 +00:00
|
|
|
data);
|
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
if (ret)
|
|
|
|
GST_GL_MEMORY_FLAG_UNSET (gl_mem, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
g_mutex_unlock (&download->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_download_perform_with_data:
|
|
|
|
* @download: a #GstGLDownload
|
|
|
|
* @texture_id: the texture id to download
|
|
|
|
* @data: (out): where the downloaded data should go
|
|
|
|
*
|
|
|
|
* Downloads @texture_id into @data. @data size and format is specified by
|
|
|
|
* the #GstVideoFormat passed to gst_gl_download_init_format()
|
|
|
|
*
|
|
|
|
* Returns: whether the download was successful
|
|
|
|
*/
|
2012-09-16 11:23:09 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_download_perform_with_data (GstGLDownload * download, GLuint texture_id,
|
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES])
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (download != NULL, FALSE);
|
|
|
|
|
|
|
|
g_mutex_lock (&download->lock);
|
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
ret =
|
|
|
|
_gst_gl_download_perform_with_data_unlocked (download, texture_id, data);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
g_mutex_unlock (&download->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
static gboolean
|
|
|
|
_gst_gl_download_perform_with_data_unlocked (GstGLDownload * download,
|
|
|
|
GLuint texture_id, gpointer data[GST_VIDEO_MAX_PLANES])
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (download != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (texture_id > 0, FALSE);
|
|
|
|
g_return_val_if_fail (GST_VIDEO_INFO_FORMAT (&download->info) !=
|
|
|
|
GST_VIDEO_FORMAT_UNKNOWN
|
|
|
|
&& GST_VIDEO_INFO_FORMAT (&download->info) != GST_VIDEO_FORMAT_ENCODED,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&download->info); i++) {
|
|
|
|
g_return_val_if_fail (data[i] != NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
download->in_texture = texture_id;
|
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&download->info); i++) {
|
|
|
|
download->data[i] = data[i];
|
|
|
|
}
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_thread_add (download->context,
|
|
|
|
(GstGLContextThreadFunc) _do_download, download);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-19 06:48:03 +00:00
|
|
|
return download->priv->result;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_init_download (GstGLContext * context, GstGLDownload * download)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-09-16 11:23:09 +00:00
|
|
|
GstVideoFormat v_format;
|
2012-09-25 05:20:21 +00:00
|
|
|
guint out_width, out_height;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
2012-09-25 05:20:21 +00:00
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&download->info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&download->info);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-15 15:08:42 +00:00
|
|
|
GST_TRACE ("initializing texture download for format %s",
|
|
|
|
gst_video_format_to_string (v_format));
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_OPENGL (context)) {
|
2012-12-06 07:40:26 +00:00
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
goto no_convert;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
/* color space conversion is needed */
|
|
|
|
{
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
if (!gl->GenFramebuffers) {
|
2012-09-16 11:23:09 +00:00
|
|
|
/* Frame buffer object is a requirement
|
|
|
|
* when using GLSL colorspace conversion
|
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-09-16 11:23:09 +00:00
|
|
|
"Context, EXT_framebuffer_object supported: no");
|
2013-07-19 06:48:03 +00:00
|
|
|
goto error;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
GST_INFO ("Context, EXT_framebuffer_object supported: yes");
|
|
|
|
|
|
|
|
/* setup FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenFramebuffers (1, &download->fbo);
|
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, download->fbo);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2012-09-25 05:20:21 +00:00
|
|
|
/* setup the render buffer for depth */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenRenderbuffers (1, &download->depth_buffer);
|
|
|
|
gl->BindRenderbuffer (GL_RENDERBUFFER, download->depth_buffer);
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_OPENGL (context)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
|
2012-12-06 07:40:26 +00:00
|
|
|
out_width, out_height);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
|
2012-12-06 07:40:26 +00:00
|
|
|
out_width, out_height);
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_GLES2 (context)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->RenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
|
2012-12-06 07:40:26 +00:00
|
|
|
out_width, out_height);
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup a first texture to render to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenTextures (1, &download->out_texture[0]);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->out_texture[0]);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
|
2012-09-25 05:20:21 +00:00
|
|
|
out_width, out_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* attach the first texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
2013-11-15 07:28:49 +00:00
|
|
|
GL_TEXTURE_2D, download->out_texture[0], 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
if (v_format == GST_VIDEO_FORMAT_I420 ||
|
|
|
|
v_format == GST_VIDEO_FORMAT_YV12) {
|
|
|
|
/* setup a second texture to render to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenTextures (1, &download->out_texture[1]);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->out_texture[1]);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
|
2012-09-25 05:20:21 +00:00
|
|
|
out_width, out_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* attach the second texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER,
|
2013-11-15 07:28:49 +00:00
|
|
|
GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, download->out_texture[1], 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* setup a third texture to render to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GenTextures (1, &download->out_texture[2]);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->out_texture[2]);
|
|
|
|
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
|
2012-09-25 05:20:21 +00:00
|
|
|
out_width, out_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* attach the third texture to the FBO to renderer to */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferTexture2D (GL_FRAMEBUFFER,
|
2013-11-15 07:28:49 +00:00
|
|
|
GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, download->out_texture[2], 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attach the depth render buffer to the FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferRenderbuffer (GL_FRAMEBUFFER,
|
|
|
|
GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, download->depth_buffer);
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_OPENGL (context)) {
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->FramebufferRenderbuffer (GL_FRAMEBUFFER,
|
|
|
|
GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, download->depth_buffer);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-02-23 00:27:23 +00:00
|
|
|
if (!gst_gl_context_check_framebuffer_status (context)) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context, "GL framebuffer status incomplete");
|
2014-02-23 00:27:23 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* unbind the FBO */
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context, "Unsupported download video format %d",
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
no_convert:
|
2013-09-15 04:23:43 +00:00
|
|
|
download->priv->result = _init_download_shader (context, download);
|
2013-07-19 06:48:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
download->priv->result = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
static gboolean
|
2013-09-15 04:23:43 +00:00
|
|
|
_create_shader (GstGLContext * context, const gchar * vertex_src,
|
2012-12-06 07:40:26 +00:00
|
|
|
const gchar * fragment_src, GstGLShader ** out_shader)
|
|
|
|
{
|
|
|
|
GstGLShader *shader;
|
2013-01-17 12:12:35 +00:00
|
|
|
GError *error = NULL;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (vertex_src != NULL || fragment_src != NULL, FALSE);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
shader = gst_gl_shader_new (context);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
if (vertex_src)
|
|
|
|
gst_gl_shader_set_vertex_source (shader, vertex_src);
|
|
|
|
if (fragment_src)
|
|
|
|
gst_gl_shader_set_fragment_source (shader, fragment_src);
|
|
|
|
|
|
|
|
if (!gst_gl_shader_compile (shader, &error)) {
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context, "%s", error->message);
|
2012-12-06 07:40:26 +00:00
|
|
|
g_error_free (error);
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (context);
|
2013-06-13 04:36:41 +00:00
|
|
|
gst_object_unref (shader);
|
2012-12-06 07:40:26 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_shader = shader;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-19 06:48:03 +00:00
|
|
|
static gboolean
|
2013-09-15 04:23:43 +00:00
|
|
|
_init_download_shader (GstGLContext * context, GstGLDownload * download)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-09-16 11:23:09 +00:00
|
|
|
GstVideoFormat v_format;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = download->context->gl_vtable;
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
|
|
|
|
2013-07-15 15:08:42 +00:00
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_RGB (download->info.finfo)
|
2013-09-15 04:23:43 +00:00
|
|
|
&& !USING_GLES2 (context)) {
|
2013-07-15 15:08:42 +00:00
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
2013-07-19 06:48:03 +00:00
|
|
|
return TRUE;
|
2013-07-15 15:08:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* color space conversion is needed */
|
|
|
|
|
|
|
|
/* check if fragment shader is available, then load them
|
|
|
|
* GLSL is a requirement for download
|
|
|
|
*/
|
|
|
|
if (!gl->CreateProgramObject && !gl->CreateProgram) {
|
|
|
|
/* colorspace conversion is not possible */
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2013-07-15 15:08:42 +00:00
|
|
|
"Context, ARB_fragment_shader supported: no");
|
2013-07-19 06:48:03 +00:00
|
|
|
return FALSE;;
|
2013-07-15 15:08:42 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
switch (v_format) {
|
2013-07-15 15:08:42 +00:00
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2013-07-15 15:08:42 +00:00
|
|
|
gchar text_shader_download_YUY2[2048];
|
|
|
|
|
|
|
|
sprintf (text_shader_download_YUY2,
|
|
|
|
download->priv->YUY2_UYVY, "y2,u,y1,v");
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (_create_shader (context, download->priv->vert_shader,
|
2013-07-15 15:08:42 +00:00
|
|
|
text_shader_download_YUY2, &download->shader)) {
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_GLES2 (context)) {
|
2012-12-06 07:40:26 +00:00
|
|
|
download->shader_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_position");
|
|
|
|
download->shader_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_texCoord");
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
2013-07-15 15:08:42 +00:00
|
|
|
{
|
|
|
|
gchar text_shader_download_UYVY[2048];
|
|
|
|
|
|
|
|
sprintf (text_shader_download_UYVY,
|
|
|
|
download->priv->YUY2_UYVY, "v,y1,u,y2");
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (_create_shader (context, download->priv->vert_shader,
|
2013-07-15 15:08:42 +00:00
|
|
|
text_shader_download_UYVY, &download->shader)) {
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_GLES2 (context)) {
|
2013-07-15 15:08:42 +00:00
|
|
|
download->shader_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_position");
|
|
|
|
download->shader_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_texCoord");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-09-16 11:23:09 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
2013-07-15 15:08:42 +00:00
|
|
|
{
|
2013-09-15 04:23:43 +00:00
|
|
|
_create_shader (context, download->priv->vert_shader,
|
2013-07-15 15:08:42 +00:00
|
|
|
download->priv->I420_YV12, &download->shader);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
{
|
2013-09-15 04:23:43 +00:00
|
|
|
if (_create_shader (context, download->priv->vert_shader,
|
2013-07-15 15:08:42 +00:00
|
|
|
download->priv->AYUV, &download->shader)) {
|
2013-09-15 04:23:43 +00:00
|
|
|
if (USING_GLES2 (context)) {
|
2013-07-15 15:08:42 +00:00
|
|
|
download->shader_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_position");
|
|
|
|
download->shader_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_texCoord");
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
2013-07-15 15:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
2013-07-15 19:44:20 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2013-07-15 15:08:42 +00:00
|
|
|
{
|
|
|
|
gchar text_shader_ARGB[2048];
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
switch (v_format) {
|
2013-07-15 15:08:42 +00:00
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
sprintf (text_shader_ARGB, download->priv->ARGB, 'b', 'g', 'r', 'a');
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
2013-07-15 15:08:42 +00:00
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
sprintf (text_shader_ARGB, download->priv->ARGB, 'a', 'r', 'g', 'b');
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
2013-07-15 15:08:42 +00:00
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
sprintf (text_shader_ARGB, download->priv->ARGB, 'a', 'b', 'g', 'r');
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-07-17 11:17:03 +00:00
|
|
|
memcpy (text_shader_ARGB, text_shader_RGB_gles2,
|
2013-07-19 08:07:54 +00:00
|
|
|
strlen (text_shader_RGB_gles2) + 1);
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-15 15:08:42 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (_create_shader (context, download->priv->vert_shader,
|
2013-07-15 15:08:42 +00:00
|
|
|
text_shader_ARGB, &download->shader)) {
|
|
|
|
download->shader_attr_position_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_position");
|
|
|
|
download->shader_attr_texture_loc =
|
|
|
|
gst_gl_shader_get_attribute_location (download->shader,
|
|
|
|
"a_texCoord");
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
2013-07-15 15:08:42 +00:00
|
|
|
}
|
2013-07-15 19:44:20 +00:00
|
|
|
#else
|
|
|
|
g_assert_not_reached ();
|
2013-07-19 06:48:03 +00:00
|
|
|
return FALSE;
|
2013-07-15 19:44:20 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2012-09-16 11:23:09 +00:00
|
|
|
default:
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2013-07-15 15:08:42 +00:00
|
|
|
"Unsupported download video format %d", v_format);
|
2012-09-16 11:23:09 +00:00
|
|
|
g_assert_not_reached ();
|
2013-07-19 06:48:03 +00:00
|
|
|
return FALSE;
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-19 06:48:03 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called in the gl thread */
|
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_do_download (GstGLContext * context, GstGLDownload * download)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
|
|
|
GstVideoFormat v_format;
|
2012-09-25 05:20:21 +00:00
|
|
|
guint out_width, out_height;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
2012-09-25 05:20:21 +00:00
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&download->info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&download->info);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
GST_TRACE ("downloading texture:%u format:%d, dimensions:%ux%u",
|
2012-09-25 05:20:21 +00:00
|
|
|
download->in_texture, v_format, out_width, out_height);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
|
|
|
/* color space conversion is not needed */
|
2013-09-15 04:23:43 +00:00
|
|
|
download->priv->do_rgb (context, download);
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
/* color space conversion is needed */
|
2013-09-15 04:23:43 +00:00
|
|
|
download->priv->do_yuv (context, download);
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context, "Unsupported download video format %d",
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 06:48:03 +00:00
|
|
|
|
|
|
|
download->priv->result = TRUE;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2012-09-16 11:23:09 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_do_download_draw_rgb_opengl (GstGLContext * context, GstGLDownload * download)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-09-16 11:23:09 +00:00
|
|
|
GstVideoFormat v_format;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = download->context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (context);
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Enable (GL_TEXTURE_2D);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_RGBA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
2012-09-16 11:23:09 +00:00
|
|
|
#else
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#endif /* G_BYTE_ORDER */
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_RGBA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
|
|
|
#else
|
2013-11-15 07:28:49 +00:00
|
|
|
glGetTexImage (GL_TEXTURE_2D, 0, GL_RGBA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#endif /* G_BYTE_ORDER */
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_RGB,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->GetTexImage (GL_TEXTURE_2D, 0, GL_BGR,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-12-06 07:40:26 +00:00
|
|
|
"Download video format inconsistency %d", v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Disable (GL_TEXTURE_2D);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2012-12-06 07:40:26 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_do_download_draw_rgb_gles2 (GstGLContext * context, GstGLDownload * download)
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-12-06 07:40:26 +00:00
|
|
|
GstVideoFormat v_format;
|
2012-09-25 05:20:21 +00:00
|
|
|
guint out_width, out_height;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-15 15:20:00 +00:00
|
|
|
GLint viewport_dim[4];
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
const GLfloat vVertices[] = { 1.0f, -1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
-1.0f, -1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
-1.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = download->context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-09-26 07:18:53 +00:00
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&download->info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&download->info);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, download->fbo);
|
2012-09-26 07:18:53 +00:00
|
|
|
|
2013-07-15 15:20:00 +00:00
|
|
|
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, out_width, out_height);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (download->shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (download->shader_attr_position_loc, 3,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (download->shader_attr_texture_loc, 2,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->EnableVertexAttribArray (download->shader_attr_position_loc);
|
|
|
|
gl->EnableVertexAttribArray (download->shader_attr_texture_loc);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2013-07-15 15:08:42 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (download->shader, "tex", 0);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (context);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-07-15 15:20:00 +00:00
|
|
|
gl->Viewport (viewport_dim[0], viewport_dim[1], viewport_dim[2],
|
|
|
|
viewport_dim[3]);
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
case GST_VIDEO_FORMAT_RGBx:
|
|
|
|
case GST_VIDEO_FORMAT_xRGB:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
2012-12-06 07:40:26 +00:00
|
|
|
case GST_VIDEO_FORMAT_BGRx:
|
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
case GST_VIDEO_FORMAT_xBGR:
|
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
2013-07-15 15:08:42 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[0]);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
2012-09-16 11:23:09 +00:00
|
|
|
case GST_VIDEO_FORMAT_BGR:
|
2013-07-15 15:08:42 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_RGB, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[0]);
|
2012-09-16 11:23:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-09-16 11:23:09 +00:00
|
|
|
"Download video format inconsistency %d", v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
2013-07-15 15:11:59 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2013-07-15 15:11:59 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
#endif
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2012-09-16 11:23:09 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_do_download_draw_yuv_opengl (GstGLContext * context, GstGLDownload * download)
|
2012-09-16 11:23:09 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-09-16 11:23:09 +00:00
|
|
|
GstVideoFormat v_format;
|
2013-01-16 04:21:44 +00:00
|
|
|
guint out_width = GST_VIDEO_INFO_WIDTH (&download->info);
|
|
|
|
guint out_height = GST_VIDEO_INFO_HEIGHT (&download->info);
|
2014-03-24 13:50:30 +00:00
|
|
|
const gfloat *cms_offset;
|
|
|
|
const gfloat *cms_ycoeff;
|
|
|
|
const gfloat *cms_ucoeff;
|
|
|
|
const gfloat *cms_vcoeff;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
GLenum multipleRT[] = {
|
2013-01-16 04:21:44 +00:00
|
|
|
GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_COLOR_ATTACHMENT1,
|
|
|
|
GL_COLOR_ATTACHMENT2
|
2012-09-16 11:23:09 +00:00
|
|
|
};
|
|
|
|
|
2013-01-17 12:12:35 +00:00
|
|
|
gfloat verts[8] = { 1.0f, -1.0f,
|
|
|
|
-1.0f, -1.0f,
|
|
|
|
-1.0f, 1.0f,
|
|
|
|
1.0f, 1.0f
|
2013-01-16 04:21:44 +00:00
|
|
|
};
|
2013-11-15 07:28:49 +00:00
|
|
|
gfloat texcoords[8] = { 1.0, 0.0,
|
2013-01-17 12:12:35 +00:00
|
|
|
0.0, 0.0,
|
2013-11-15 07:28:49 +00:00
|
|
|
0.0, 1.0,
|
|
|
|
1.0, 1.0
|
2013-01-16 04:21:44 +00:00
|
|
|
};
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
|
|
|
|
2012-09-25 05:20:21 +00:00
|
|
|
GST_TRACE ("doing YUV download of texture:%u (%ux%u) using fbo:%u",
|
|
|
|
download->in_texture, out_width, out_height, download->fbo);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, download->fbo);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->PushAttrib (GL_VIEWPORT_BIT);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->PushMatrix ();
|
|
|
|
gl->LoadIdentity ();
|
2012-09-25 05:20:21 +00:00
|
|
|
gluOrtho2D (0.0, out_width, 0.0, out_height);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->PushMatrix ();
|
|
|
|
gl->LoadIdentity ();
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, out_width, out_height);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawBuffer (GL_COLOR_ATTACHMENT0);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (download->shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (download->shader, "tex", 0);
|
2013-11-15 07:28:49 +00:00
|
|
|
gst_gl_shader_set_uniform_1f (download->shader, "width", out_width);
|
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawBuffers (3, multipleRT);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (download->shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->LoadIdentity ();
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-17 12:12:35 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (download->shader, "tex", 0);
|
2012-09-25 05:20:21 +00:00
|
|
|
gst_gl_shader_set_uniform_1f (download->shader, "w", (gfloat) out_width);
|
|
|
|
gst_gl_shader_set_uniform_1f (download->shader, "h", (gfloat) out_height);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-09-16 11:23:09 +00:00
|
|
|
"Download video format inconsistensy %d", v_format);
|
|
|
|
}
|
|
|
|
|
2014-03-24 13:50:30 +00:00
|
|
|
if (gst_video_colorimetry_matches (&download->info.colorimetry,
|
|
|
|
GST_VIDEO_COLORIMETRY_BT709)) {
|
|
|
|
cms_offset = bt709_offset;
|
|
|
|
cms_ycoeff = bt709_ycoeff;
|
|
|
|
cms_ucoeff = bt709_ucoeff;
|
|
|
|
cms_vcoeff = bt709_vcoeff;
|
|
|
|
} else if (gst_video_colorimetry_matches (&download->info.colorimetry,
|
|
|
|
GST_VIDEO_COLORIMETRY_BT601)) {
|
|
|
|
cms_offset = bt601_offset;
|
|
|
|
cms_ycoeff = bt601_ycoeff;
|
|
|
|
cms_ucoeff = bt601_ucoeff;
|
|
|
|
cms_vcoeff = bt601_vcoeff;
|
|
|
|
} else {
|
|
|
|
/* defaults */
|
|
|
|
cms_offset = bt601_offset;
|
|
|
|
cms_ycoeff = bt601_ycoeff;
|
|
|
|
cms_ucoeff = bt601_ucoeff;
|
|
|
|
cms_vcoeff = bt601_vcoeff;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "offset", 1,
|
|
|
|
(gfloat *) cms_offset);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "ycoeff", 1,
|
|
|
|
(gfloat *) cms_ycoeff);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "ucoeff", 1,
|
|
|
|
(gfloat *) cms_ucoeff);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "vcoeff", 1,
|
|
|
|
(gfloat *) cms_vcoeff);
|
|
|
|
|
2013-01-17 12:12:35 +00:00
|
|
|
gl->ClientActiveTexture (GL_TEXTURE0);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->EnableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->EnableClientState (GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
gl->VertexPointer (2, GL_FLOAT, 0, &verts);
|
|
|
|
gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords);
|
|
|
|
|
2013-01-17 12:12:35 +00:00
|
|
|
gl->DrawArrays (GL_QUADS, 0, 4);
|
2013-01-16 04:21:44 +00:00
|
|
|
|
|
|
|
gl->DisableClientState (GL_VERTEX_ARRAY);
|
|
|
|
gl->DisableClientState (GL_TEXTURE_COORD_ARRAY);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawBuffer (GL_NONE);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
/* don't check if GLSL is available
|
|
|
|
* because download yuv is not available
|
|
|
|
* without GLSL (whereas rgb is)
|
|
|
|
*/
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->UseProgramObject (0);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->Disable (GL_TEXTURE_2D);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->MatrixMode (GL_PROJECTION);
|
|
|
|
gl->PopMatrix ();
|
|
|
|
gl->MatrixMode (GL_MODELVIEW);
|
|
|
|
gl->PopMatrix ();
|
|
|
|
gl->PopAttrib ();
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, download->fbo);
|
|
|
|
gl->ReadBuffer (GL_COLOR_ATTACHMENT0);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_BGRA,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
|
|
|
#else
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_BGRA,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2, out_height, GL_BGRA,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#else
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2, out_height, GL_BGRA,
|
2012-09-16 11:23:09 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_LUMINANCE,
|
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadBuffer (GL_COLOR_ATTACHMENT1);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-09-25 05:20:21 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
2012-09-16 11:23:09 +00:00
|
|
|
download->data[1]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadBuffer (GL_COLOR_ATTACHMENT2);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-09-25 05:20:21 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
2012-09-16 11:23:09 +00:00
|
|
|
download->data[2]);
|
|
|
|
}
|
|
|
|
break;
|
2012-09-18 11:42:24 +00:00
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_LUMINANCE,
|
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
2012-09-18 11:42:24 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadBuffer (GL_COLOR_ATTACHMENT1);
|
2012-09-18 11:42:24 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-09-25 05:20:21 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
2012-09-18 11:42:24 +00:00
|
|
|
download->data[2]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadBuffer (GL_COLOR_ATTACHMENT2);
|
2012-09-18 11:42:24 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-09-25 05:20:21 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
2012-09-18 11:42:24 +00:00
|
|
|
download->data[1]);
|
|
|
|
}
|
|
|
|
break;
|
2012-09-16 11:23:09 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-09-16 11:23:09 +00:00
|
|
|
"Download video format inconsistensy %d", v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadBuffer (GL_NONE);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2012-12-06 07:40:26 +00:00
|
|
|
static void
|
2013-09-15 04:23:43 +00:00
|
|
|
_do_download_draw_yuv_gles2 (GstGLContext * context, GstGLDownload * download)
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
GstGLFuncs *gl;
|
2012-12-06 07:40:26 +00:00
|
|
|
GstVideoFormat v_format;
|
|
|
|
guint out_width, out_height;
|
2014-03-24 13:50:30 +00:00
|
|
|
const gfloat *cms_offset;
|
|
|
|
const gfloat *cms_ycoeff;
|
|
|
|
const gfloat *cms_ucoeff;
|
|
|
|
const gfloat *cms_vcoeff;
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
GLint viewport_dim[4];
|
|
|
|
|
|
|
|
const GLfloat vVertices[] = { 1.0f, -1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
-1.0f, -1.0f, 0.0f,
|
|
|
|
0.0f, .0f,
|
|
|
|
-1.0f, 1.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f
|
|
|
|
};
|
|
|
|
|
|
|
|
GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-01-16 04:21:44 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
out_width = GST_VIDEO_INFO_WIDTH (&download->info);
|
|
|
|
out_height = GST_VIDEO_INFO_HEIGHT (&download->info);
|
|
|
|
v_format = GST_VIDEO_INFO_FORMAT (&download->info);
|
|
|
|
|
|
|
|
GST_TRACE ("doing YUV download of texture:%u (%ux%u) using fbo:%u",
|
|
|
|
download->in_texture, out_width, out_height, download->fbo);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, download->fbo);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->GetIntegerv (GL_VIEWPORT, viewport_dim);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (0, 0, out_width, out_height);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (download->shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (download->shader_attr_position_loc, 3,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), vVertices);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->VertexAttribPointer (download->shader_attr_texture_loc, 2,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_FLOAT, GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->EnableVertexAttribArray (download->shader_attr_position_loc);
|
|
|
|
gl->EnableVertexAttribArray (download->shader_attr_texture_loc);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (download->shader, "tex", 0);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ClearColor (0.0, 0.0, 0.0, 0.0);
|
|
|
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
gst_gl_shader_use (download->shader);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ActiveTexture (GL_TEXTURE0);
|
2012-12-06 07:40:26 +00:00
|
|
|
gst_gl_shader_set_uniform_1i (download->shader, "tex", 0);
|
|
|
|
gst_gl_shader_set_uniform_1f (download->shader, "w", (gfloat) out_width);
|
|
|
|
gst_gl_shader_set_uniform_1f (download->shader, "h", (gfloat) out_height);
|
2013-11-15 07:28:49 +00:00
|
|
|
gl->BindTexture (GL_TEXTURE_2D, download->in_texture);
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-12-06 07:40:26 +00:00
|
|
|
"Download video format inconsistensy %d", v_format);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-24 13:50:30 +00:00
|
|
|
if (gst_video_colorimetry_matches (&download->info.colorimetry,
|
|
|
|
GST_VIDEO_COLORIMETRY_BT709)) {
|
|
|
|
cms_offset = bt709_offset;
|
|
|
|
cms_ycoeff = bt709_ycoeff;
|
|
|
|
cms_ucoeff = bt709_ucoeff;
|
|
|
|
cms_vcoeff = bt709_vcoeff;
|
|
|
|
} else if (gst_video_colorimetry_matches (&download->info.colorimetry,
|
|
|
|
GST_VIDEO_COLORIMETRY_BT601)) {
|
|
|
|
cms_offset = bt601_offset;
|
|
|
|
cms_ycoeff = bt601_ycoeff;
|
|
|
|
cms_ucoeff = bt601_ucoeff;
|
|
|
|
cms_vcoeff = bt601_vcoeff;
|
|
|
|
} else {
|
|
|
|
/* defaults */
|
|
|
|
cms_offset = bt601_offset;
|
|
|
|
cms_ycoeff = bt601_ycoeff;
|
|
|
|
cms_ucoeff = bt601_ucoeff;
|
|
|
|
cms_vcoeff = bt601_vcoeff;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "offset", 1,
|
|
|
|
(gfloat *) cms_offset);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "ycoeff", 1,
|
|
|
|
(gfloat *) cms_ycoeff);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "ucoeff", 1,
|
|
|
|
(gfloat *) cms_ucoeff);
|
|
|
|
gst_gl_shader_set_uniform_3fv (download->shader, "vcoeff", 1,
|
|
|
|
(gfloat *) cms_vcoeff);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
/* don't check if GLSL is available
|
|
|
|
* because download yuv is not available
|
|
|
|
* without GLSL (whereas rgb is)
|
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_clear_shader (context);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->Viewport (viewport_dim[0], viewport_dim[1], viewport_dim[2],
|
2012-12-06 07:40:26 +00:00
|
|
|
viewport_dim[3]);
|
|
|
|
|
|
|
|
switch (v_format) {
|
|
|
|
case GST_VIDEO_FORMAT_AYUV:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
|
|
|
#else
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2, out_height, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV, download->data[0]);
|
|
|
|
#else
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2, out_height, GL_BGRA,
|
2012-12-06 07:40:26 +00:00
|
|
|
GL_UNSIGNED_INT_8_8_8_8, download->data[0]);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_LUMINANCE,
|
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-12-06 07:40:26 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[1]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-12-06 07:40:26 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[2]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
{
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, out_width, out_height, GL_LUMINANCE,
|
|
|
|
GL_UNSIGNED_BYTE, download->data[0]);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-12-06 07:40:26 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[2]);
|
|
|
|
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->ReadPixels (0, 0, GST_ROUND_UP_2 (out_width) / 2,
|
2012-12-06 07:40:26 +00:00
|
|
|
GST_ROUND_UP_2 (out_height) / 2, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
|
|
|
download->data[1]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_set_error (context,
|
2012-12-06 07:40:26 +00:00
|
|
|
"Download video format inconsistensy %d", v_format);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gst_gl_context_check_framebuffer_status (context);
|
2013-01-16 04:21:44 +00:00
|
|
|
gl->BindFramebuffer (GL_FRAMEBUFFER, 0);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
2012-12-06 07:40:26 +00:00
|
|
|
#endif
|