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
|
|
|
*/
|
|
|
|
|
2014-05-30 00:27:14 +00:00
|
|
|
#define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))
|
|
|
|
#define USING_OPENGL3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 3, 1))
|
|
|
|
#define USING_GLES(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES, 1, 0))
|
|
|
|
#define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
|
|
|
|
#define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2014-05-29 05:50:56 +00:00
|
|
|
static gboolean _do_download (GstGLDownload * download, guint texture_id,
|
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES]);
|
2014-05-13 04:13:57 +00:00
|
|
|
static gboolean _init_download (GstGLDownload * download);
|
2013-07-18 09:37:32 +00:00
|
|
|
static gboolean _gst_gl_download_perform_with_data_unlocked (GstGLDownload *
|
2015-01-27 13:13:46 +00:00
|
|
|
download, GLuint texture_id, GLuint texture_target,
|
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES]);
|
2014-05-13 04:13:57 +00:00
|
|
|
static void gst_gl_download_reset (GstGLDownload * download);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
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;
|
|
|
|
|
2014-05-27 08:20:29 +00:00
|
|
|
GstGLMemory *in_tex[GST_VIDEO_MAX_PLANES];
|
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");
|
|
|
|
|
2014-05-08 05:30:49 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDownload, gst_gl_download, GST_TYPE_OBJECT,
|
2012-09-16 11:23:09 +00:00
|
|
|
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);
|
|
|
|
|
2012-09-16 11:23:09 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
download = g_object_new (GST_TYPE_GL_DOWNLOAD, NULL);
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
download->context = gst_object_ref (context);
|
2014-04-01 02:30:51 +00:00
|
|
|
download->convert = gst_gl_color_convert_new (context);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
return download;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_download_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLDownload *download;
|
|
|
|
|
|
|
|
download = GST_GL_DOWNLOAD (object);
|
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
gst_gl_download_reset (download);
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2014-04-01 02:30:51 +00:00
|
|
|
if (download->convert) {
|
|
|
|
gst_object_unref (download->convert);
|
|
|
|
download->convert = NULL;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
static void
|
|
|
|
gst_gl_download_reset (GstGLDownload * download)
|
2012-09-18 11:39:21 +00:00
|
|
|
{
|
2014-05-13 04:13:57 +00:00
|
|
|
guint i;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
2014-05-27 08:20:29 +00:00
|
|
|
if (download->priv->in_tex[i]) {
|
|
|
|
gst_memory_unref ((GstMemory *) download->priv->in_tex[i]);
|
|
|
|
download->priv->in_tex[i] = NULL;
|
2014-05-13 04:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
2014-05-13 04:13:57 +00:00
|
|
|
* gst_gl_download_set_format:
|
2012-09-27 05:53:46 +00:00
|
|
|
* @download: a #GstGLDownload
|
2015-03-18 17:12:49 +00:00
|
|
|
* @out_info: a #GstVideoInfo
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
2014-05-13 04:13:57 +00:00
|
|
|
* Initializes @download with the information required for download.
|
2012-09-27 05:53:46 +00:00
|
|
|
*/
|
2014-05-13 04:13:57 +00:00
|
|
|
void
|
|
|
|
gst_gl_download_set_format (GstGLDownload * download, GstVideoInfo * out_info)
|
2012-09-18 11:39:21 +00:00
|
|
|
{
|
2014-05-13 04:13:57 +00:00
|
|
|
g_return_if_fail (download != NULL);
|
|
|
|
g_return_if_fail (GST_VIDEO_INFO_FORMAT (out_info) !=
|
|
|
|
GST_VIDEO_FORMAT_UNKNOWN);
|
|
|
|
g_return_if_fail (GST_VIDEO_INFO_FORMAT (out_info) !=
|
|
|
|
GST_VIDEO_FORMAT_ENCODED);
|
2012-09-18 11:39:21 +00:00
|
|
|
|
2014-05-29 06:22:52 +00:00
|
|
|
GST_OBJECT_LOCK (download);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
if (gst_video_info_is_equal (&download->info, out_info)) {
|
2014-05-29 06:22:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (download);
|
2014-05-13 04:13:57 +00:00
|
|
|
return;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
gst_gl_download_reset (download);
|
|
|
|
download->initted = FALSE;
|
|
|
|
download->info = *out_info;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-29 06:22:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (download);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:11:06 +00:00
|
|
|
static GstCaps *
|
|
|
|
_set_caps_features (const GstCaps * caps, const gchar * feature_name)
|
|
|
|
{
|
|
|
|
GstCaps *tmp = gst_caps_copy (caps);
|
|
|
|
guint n = gst_caps_get_size (tmp);
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2015-03-06 17:54:24 +00:00
|
|
|
GstCapsFeatures *features;
|
2015-02-02 13:11:06 +00:00
|
|
|
|
2015-03-06 17:54:24 +00:00
|
|
|
features = gst_caps_features_new (feature_name, NULL);
|
|
|
|
gst_caps_set_features (tmp, i, features);
|
2015-02-02 13:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
gst_gl_download_transform_caps (GstGLContext * context,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *gl_templ, *templ, *result, *tmp;
|
|
|
|
|
|
|
|
templ =
|
|
|
|
gst_caps_from_string (GST_VIDEO_CAPS_MAKE (GST_GL_COLOR_CONVERT_FORMATS));
|
|
|
|
gl_templ =
|
|
|
|
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_GL_COLOR_CONVERT_FORMATS));
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SRC) {
|
|
|
|
tmp = gst_caps_intersect_full (caps, templ, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
result = _set_caps_features (tmp, GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
} else {
|
|
|
|
tmp = gst_caps_ref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
result =
|
|
|
|
gst_gl_color_convert_transform_caps (context, direction, tmp, filter);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
|
|
|
|
if (direction == GST_PAD_SINK) {
|
|
|
|
result = _set_caps_features (tmp, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
result = gst_caps_intersect_full (tmp, templ, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
tmp = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
|
|
|
result = tmp;
|
|
|
|
}
|
|
|
|
gst_caps_unref (templ);
|
|
|
|
gst_caps_unref (gl_templ);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-09-27 05:53:46 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_download_perform_with_data:
|
|
|
|
* @download: a #GstGLDownload
|
|
|
|
* @texture_id: the texture id to download
|
2015-01-27 13:13:46 +00:00
|
|
|
* @texture_target: the GL texture target
|
2012-09-27 05:53:46 +00:00
|
|
|
* @data: (out): where the downloaded data should go
|
|
|
|
*
|
|
|
|
* Downloads @texture_id into @data. @data size and format is specified by
|
2014-05-13 04:13:57 +00:00
|
|
|
* the #GstVideoFormat passed to gst_gl_download_set_format()
|
2012-09-27 05:53:46 +00:00
|
|
|
*
|
|
|
|
* Returns: whether the download was successful
|
|
|
|
*/
|
2012-09-16 11:23:09 +00:00
|
|
|
gboolean
|
2015-01-27 13:13:46 +00:00
|
|
|
gst_gl_download_perform_with_data (GstGLDownload * download,
|
|
|
|
GLuint texture_id, GLuint texture_target,
|
2012-09-16 11:23:09 +00:00
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES])
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (download != NULL, FALSE);
|
|
|
|
|
2014-05-29 06:22:52 +00:00
|
|
|
GST_OBJECT_LOCK (download);
|
2013-07-18 09:37:32 +00:00
|
|
|
ret =
|
2015-01-27 13:13:46 +00:00
|
|
|
_gst_gl_download_perform_with_data_unlocked (download,
|
|
|
|
texture_id, texture_target, data);
|
2014-05-29 06:22:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (download);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-18 09:37:32 +00:00
|
|
|
static gboolean
|
|
|
|
_gst_gl_download_perform_with_data_unlocked (GstGLDownload * download,
|
2015-01-27 13:13:46 +00:00
|
|
|
GLuint texture_id, GLuint texture_target,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-31 04:07:29 +00:00
|
|
|
if (!download->priv->in_tex[0]) {
|
|
|
|
GstVideoInfo temp_info;
|
|
|
|
|
|
|
|
gst_video_info_set_format (&temp_info, GST_VIDEO_FORMAT_RGBA,
|
|
|
|
GST_VIDEO_INFO_WIDTH (&download->info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (&download->info));
|
|
|
|
|
2014-05-27 08:20:29 +00:00
|
|
|
download->priv->in_tex[0] =
|
2015-01-27 13:13:46 +00:00
|
|
|
gst_gl_memory_wrapped_texture (download->context,
|
|
|
|
texture_id, texture_target, &temp_info, 0, NULL, NULL, NULL);
|
2014-07-31 04:07:29 +00:00
|
|
|
}
|
2014-04-02 06:43:52 +00:00
|
|
|
|
2014-05-27 08:20:29 +00:00
|
|
|
download->priv->in_tex[0]->tex_id = texture_id;
|
2014-04-02 06:43:52 +00:00
|
|
|
|
2014-05-29 05:50:56 +00:00
|
|
|
return _do_download (download, texture_id, data);
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
static gboolean
|
|
|
|
_init_download (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;
|
2014-04-01 02:30:51 +00:00
|
|
|
GstVideoInfo in_info;
|
2015-01-14 11:08:43 +00:00
|
|
|
GstCaps *in_caps, *out_caps;
|
|
|
|
GstCapsFeatures *in_gl_features, *out_gl_features;
|
|
|
|
gboolean res;
|
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
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
if (download->initted)
|
|
|
|
return TRUE;
|
|
|
|
|
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
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
if (USING_GLES2 (download->context) && !USING_GLES3 (download->context)) {
|
2014-04-01 02:30:51 +00:00
|
|
|
/* GL_RGBA is the only officially supported texture format in GLES2 */
|
|
|
|
if (v_format == GST_VIDEO_FORMAT_RGB || v_format == GST_VIDEO_FORMAT_BGR) {
|
2014-05-13 04:13:57 +00:00
|
|
|
gst_gl_context_set_error (download->context, "Cannot download RGB "
|
|
|
|
"textures in GLES2");
|
|
|
|
return FALSE;
|
2013-07-15 15:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
in_gl_features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
2014-04-02 06:43:52 +00:00
|
|
|
gst_video_info_set_format (&in_info, GST_VIDEO_FORMAT_RGBA, out_width,
|
|
|
|
out_height);
|
2015-01-14 11:08:43 +00:00
|
|
|
in_caps = gst_video_info_to_caps (&in_info);
|
|
|
|
gst_caps_set_features (in_caps, 0, in_gl_features);
|
2014-04-02 06:43:52 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
out_gl_features =
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
|
|
|
out_caps = gst_video_info_to_caps (&download->info);
|
|
|
|
gst_caps_set_features (out_caps, 0, out_gl_features);
|
2013-07-19 06:48:03 +00:00
|
|
|
|
2015-01-14 11:08:43 +00:00
|
|
|
res = gst_gl_color_convert_set_caps (download->convert, in_caps, out_caps);
|
|
|
|
|
|
|
|
gst_caps_unref (in_caps);
|
|
|
|
gst_caps_unref (out_caps);
|
|
|
|
|
|
|
|
return res;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 05:50:56 +00:00
|
|
|
static gboolean
|
|
|
|
_do_download (GstGLDownload * download, guint texture_id,
|
|
|
|
gpointer data[GST_VIDEO_MAX_PLANES])
|
2012-12-06 07:40:26 +00:00
|
|
|
{
|
2012-09-25 05:20:21 +00:00
|
|
|
guint out_width, out_height;
|
2014-05-27 08:20:29 +00:00
|
|
|
GstBuffer *inbuf, *outbuf;
|
2014-04-02 06:43:52 +00:00
|
|
|
GstMapInfo map_info;
|
2014-05-29 05:50:56 +00:00
|
|
|
gboolean ret = TRUE;
|
2014-04-02 06:43:52 +00:00
|
|
|
gint i;
|
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);
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
if (!download->initted) {
|
2014-05-29 05:50:56 +00:00
|
|
|
if (!_init_download (download))
|
|
|
|
return FALSE;
|
2014-05-13 04:13:57 +00:00
|
|
|
}
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-05-13 04:13:57 +00:00
|
|
|
GST_TRACE ("doing download of texture:%u (%ux%u)",
|
2014-05-27 08:20:29 +00:00
|
|
|
download->priv->in_tex[0]->tex_id, out_width, out_height);
|
|
|
|
|
|
|
|
inbuf = gst_buffer_new ();
|
|
|
|
gst_buffer_append_memory (inbuf,
|
|
|
|
gst_memory_ref ((GstMemory *) download->priv->in_tex[0]));
|
|
|
|
|
2014-05-29 05:50:56 +00:00
|
|
|
outbuf = gst_gl_color_convert_perform (download->convert, inbuf);
|
|
|
|
if (!outbuf)
|
|
|
|
return FALSE;
|
2012-09-16 11:23:09 +00:00
|
|
|
|
2014-04-02 06:43:52 +00:00
|
|
|
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&download->info); i++) {
|
2014-05-29 05:50:56 +00:00
|
|
|
GstMemory *out_mem = gst_buffer_peek_memory (outbuf, i);
|
|
|
|
gpointer temp_data = ((GstGLMemory *) out_mem)->data;
|
|
|
|
((GstGLMemory *) out_mem)->data = data[i];
|
|
|
|
|
2015-01-27 00:53:51 +00:00
|
|
|
gst_gl_memory_download_transfer ((GstGLMemory *) out_mem);
|
|
|
|
|
2014-05-29 05:50:56 +00:00
|
|
|
if (!gst_memory_map (out_mem, &map_info, GST_MAP_READ)) {
|
|
|
|
GST_ERROR_OBJECT (download, "Failed to map memory");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
gst_memory_unmap (out_mem, &map_info);
|
|
|
|
((GstGLMemory *) out_mem)->data = temp_data;
|
2012-12-06 07:40:26 +00:00
|
|
|
}
|
2014-05-27 08:20:29 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (inbuf);
|
2014-06-15 05:17:07 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
2014-05-29 05:50:56 +00:00
|
|
|
|
|
|
|
return ret;
|
2012-09-16 11:23:09 +00:00
|
|
|
}
|