mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
[035/906] * sys/glsink/gstvideo-common.c: * sys/glsink/gstvideo-common.h: Pull together some common raw video functions into one location. This should eventually move to -base. * sys/glsink/Makefile.am: * sys/glsink/glimagesink.c: * sys/glsink/glimagesink.h: * sys/glsink/glvideo.c: * sys/glsink/glvideo.h: * sys/glsink/gstopengl.c: Use the new video-common.h stuff. Readd support for RGB video.
This commit is contained in:
parent
4f11558976
commit
4b7396917b
8 changed files with 784 additions and 107 deletions
|
@ -1,7 +1,14 @@
|
|||
|
||||
plugin_LTLIBRARIES = libgstglimagesink.la
|
||||
|
||||
libgstglimagesink_la_SOURCES = glimagesink.c glvideo.c
|
||||
libgstglimagesink_la_SOURCES = \
|
||||
glimagesink.h \
|
||||
glimagesink.c \
|
||||
glvideo.c \
|
||||
glvideo.h \
|
||||
gstopengl.c \
|
||||
gstvideo-common.h \
|
||||
gstvideo-common.c
|
||||
libgstglimagesink_la_CFLAGS = $(GST_CFLAGS) $(X_CFLAGS) $(GST_BASE_CFLAGS) \
|
||||
$(GST_PLUGINS_BASE_CFLAGS)
|
||||
libgstglimagesink_la_LIBADD = $(X_LIBS) $(XSHM_LIBS) -lGL \
|
||||
|
|
|
@ -30,50 +30,11 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "glvideo.h"
|
||||
#include <glimagesink.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_debug_glimage_sink);
|
||||
GST_DEBUG_CATEGORY (gst_debug_glimage_sink);
|
||||
#define GST_CAT_DEFAULT gst_debug_glimage_sink
|
||||
|
||||
#define GST_TYPE_GLIMAGE_SINK \
|
||||
(gst_glimage_sink_get_type())
|
||||
#define GST_GLIMAGE_SINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GLIMAGE_SINK,GstGLImageSink))
|
||||
#define GST_GLIMAGE_SINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GLIMAGE_SINK,GstGLImageSinkClass))
|
||||
#define GST_IS_GLIMAGE_SINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GLIMAGE_SINK))
|
||||
#define GST_IS_GLIMAGE_SINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GLIMAGE_SINK))
|
||||
|
||||
typedef struct _GstGLImageSink GstGLImageSink;
|
||||
typedef struct _GstGLImageSinkClass GstGLImageSinkClass;
|
||||
|
||||
struct _GstGLImageSink
|
||||
{
|
||||
GstVideoSink video_sink;
|
||||
|
||||
/* properties */
|
||||
char *display_name;
|
||||
|
||||
/* caps */
|
||||
GstCaps *caps;
|
||||
int fps_n, fps_d;
|
||||
int par_n, par_d;
|
||||
|
||||
GLVideoDisplay *display;
|
||||
GLVideoDrawable *drawable;
|
||||
GLVideoImageType type;
|
||||
|
||||
XID window_id;
|
||||
};
|
||||
|
||||
struct _GstGLImageSinkClass
|
||||
{
|
||||
GstVideoSinkClass video_sink_class;
|
||||
|
||||
};
|
||||
|
||||
static void gst_glimage_sink_init_interfaces (GType type);
|
||||
|
||||
static void gst_glimage_sink_finalize (GObject * object);
|
||||
|
@ -421,12 +382,12 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|||
{
|
||||
GstGLImageSink *glimage_sink;
|
||||
GstCaps *intersection;
|
||||
GstStructure *structure;
|
||||
int width;
|
||||
int height;
|
||||
gboolean ret;
|
||||
const GValue *fps;
|
||||
const GValue *par;
|
||||
gboolean ok;
|
||||
int fps_n, fps_d;
|
||||
int par_n, par_d;
|
||||
GstVideoFormat format;
|
||||
|
||||
GST_DEBUG ("set caps with %" GST_PTR_FORMAT, caps);
|
||||
|
||||
|
@ -440,51 +401,36 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|||
|
||||
gst_caps_unref (intersection);
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
ret = gst_structure_get_int (structure, "width", &width);
|
||||
ret &= gst_structure_get_int (structure, "height", &height);
|
||||
fps = gst_structure_get_value (structure, "framerate");
|
||||
ret &= (fps != NULL);
|
||||
par = gst_structure_get_value (structure, "pixel-aspect-ratio");
|
||||
ok = gst_video_parse_caps (caps, &format, &width, &height);
|
||||
ok &= gst_video_parse_caps_framerate (caps, &fps_n, &fps_d);
|
||||
ok &= gst_video_parse_caps_pixel_aspect_ratio (caps, &par_n, &par_d);
|
||||
|
||||
if (!ret)
|
||||
if (!ok)
|
||||
return FALSE;
|
||||
|
||||
glimage_sink->fps_n = gst_value_get_fraction_numerator (fps);
|
||||
glimage_sink->fps_d = gst_value_get_fraction_denominator (fps);
|
||||
if (par) {
|
||||
glimage_sink->par_n = gst_value_get_fraction_numerator (par);
|
||||
glimage_sink->par_d = gst_value_get_fraction_denominator (par);
|
||||
} else {
|
||||
glimage_sink->par_n = 1;
|
||||
glimage_sink->par_d = 1;
|
||||
}
|
||||
|
||||
GST_VIDEO_SINK_WIDTH (glimage_sink) = width;
|
||||
GST_VIDEO_SINK_HEIGHT (glimage_sink) = height;
|
||||
glimage_sink->format = format;
|
||||
glimage_sink->fps_n = fps_n;
|
||||
glimage_sink->fps_d = fps_d;
|
||||
glimage_sink->par_n = par_n;
|
||||
glimage_sink->par_d = par_d;
|
||||
|
||||
if (strcmp (gst_structure_get_name (structure), "video/x-raw-rgb") == 0) {
|
||||
int red_mask;
|
||||
|
||||
GST_DEBUG ("using RGB");
|
||||
gst_structure_get_int (structure, "red_mask", &red_mask);
|
||||
|
||||
if (red_mask == 0xff000000) {
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_RGBA;
|
||||
} else {
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_BGRA;
|
||||
}
|
||||
} else {
|
||||
unsigned int fourcc;
|
||||
|
||||
GST_DEBUG ("using YUV");
|
||||
|
||||
gst_structure_get_fourcc (structure, "format", &fourcc);
|
||||
if (fourcc == GST_MAKE_FOURCC ('Y', 'U', 'Y', '2')) {
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_YUY2;
|
||||
} else {
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_UYVY;
|
||||
}
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_RGBx;
|
||||
break;
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
glimage_sink->type = GLVIDEO_IMAGE_TYPE_BGRx;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -632,23 +578,3 @@ gst_glimage_sink_update_caps (GstGLImageSink * glimage_sink)
|
|||
|
||||
gst_caps_replace (&glimage_sink->caps, caps);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
if (!gst_element_register (plugin, "glimagesink",
|
||||
GST_RANK_MARGINAL, GST_TYPE_GLIMAGE_SINK))
|
||||
return FALSE;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_glimage_sink, "glimagesink", 0,
|
||||
"glimagesink element");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"glimagesink",
|
||||
"OpenGL video output plugin",
|
||||
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
||||
|
|
77
gst/gl/glimagesink.h
Normal file
77
gst/gl/glimagesink.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
|
||||
* Copyright (C) 2005,2006,2007 David A. Schleef <ds@schleef.org>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GLIMAGESINK_H_
|
||||
#define _GLIMAGESINK_H_
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/interfaces/xoverlay.h>
|
||||
#include <gst/video/gstvideosink.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include "glvideo.h"
|
||||
#include <gstvideo-common.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_debug_glimage_sink);
|
||||
|
||||
#define GST_TYPE_GLIMAGE_SINK \
|
||||
(gst_glimage_sink_get_type())
|
||||
#define GST_GLIMAGE_SINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GLIMAGE_SINK,GstGLImageSink))
|
||||
#define GST_GLIMAGE_SINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GLIMAGE_SINK,GstGLImageSinkClass))
|
||||
#define GST_IS_GLIMAGE_SINK(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GLIMAGE_SINK))
|
||||
#define GST_IS_GLIMAGE_SINK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GLIMAGE_SINK))
|
||||
|
||||
typedef struct _GstGLImageSink GstGLImageSink;
|
||||
typedef struct _GstGLImageSinkClass GstGLImageSinkClass;
|
||||
|
||||
struct _GstGLImageSink
|
||||
{
|
||||
GstVideoSink video_sink;
|
||||
|
||||
/* properties */
|
||||
char *display_name;
|
||||
|
||||
/* caps */
|
||||
GstCaps *caps;
|
||||
GstVideoFormat format;
|
||||
int fps_n, fps_d;
|
||||
int par_n, par_d;
|
||||
|
||||
GLVideoDisplay *display;
|
||||
GLVideoDrawable *drawable;
|
||||
GLVideoImageType type;
|
||||
|
||||
XID window_id;
|
||||
};
|
||||
|
||||
struct _GstGLImageSinkClass
|
||||
{
|
||||
GstVideoSinkClass video_sink_class;
|
||||
|
||||
};
|
||||
|
||||
GType gst_glimage_sink_get_type(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -328,13 +328,13 @@ glv_drawable_draw_image (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
switch (type) {
|
||||
case GLVIDEO_IMAGE_TYPE_RGBA:
|
||||
case GLVIDEO_IMAGE_TYPE_RGBx:
|
||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
break;
|
||||
case GLVIDEO_IMAGE_TYPE_BGRA:
|
||||
case GLVIDEO_IMAGE_TYPE_BGRx:
|
||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
|
||||
|
@ -351,6 +351,7 @@ glv_drawable_draw_image (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_REV_MESA, NULL);
|
||||
glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, width, height,
|
||||
GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, data);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ typedef struct _GLVideoDisplay GLVideoDisplay;
|
|||
typedef struct _GLVideoDrawable GLVideoDrawable;
|
||||
|
||||
typedef enum {
|
||||
GLVIDEO_IMAGE_TYPE_RGBA,
|
||||
GLVIDEO_IMAGE_TYPE_BGRA,
|
||||
GLVIDEO_IMAGE_TYPE_RGBx,
|
||||
GLVIDEO_IMAGE_TYPE_BGRx,
|
||||
GLVIDEO_IMAGE_TYPE_YUY2,
|
||||
GLVIDEO_IMAGE_TYPE_UYVY,
|
||||
} GLVideoImageType;
|
||||
|
|
53
gst/gl/gstopengl.c
Normal file
53
gst/gl/gstopengl.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2003 Julien Moutte <julien@moutte.net>
|
||||
* Copyright (C) 2005,2006,2007 David A. Schleef <ds@schleef.org>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/interfaces/xoverlay.h>
|
||||
#include <gst/video/gstvideosink.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glimagesink.h>
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_glimage_sink, "glimagesink", 0,
|
||||
"glimagesink element");
|
||||
|
||||
if (!gst_element_register (plugin, "glimagesink",
|
||||
GST_RANK_MARGINAL, GST_TYPE_GLIMAGE_SINK)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"glimagesink",
|
||||
"OpenGL video output plugin",
|
||||
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
560
gst/gl/gstvideo-common.c
Normal file
560
gst/gl/gstvideo-common.c
Normal file
|
@ -0,0 +1,560 @@
|
|||
/* gstvideo-common.c
|
||||
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
||||
*
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gstvideo-common.h>
|
||||
|
||||
|
||||
gboolean
|
||||
gst_video_parse_caps (GstCaps * caps, GstVideoFormat * format, int *width,
|
||||
int *height)
|
||||
{
|
||||
GstStructure *structure;
|
||||
gboolean ok = TRUE;
|
||||
|
||||
if (!gst_caps_is_fixed (caps))
|
||||
return FALSE;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if (format) {
|
||||
if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
|
||||
guint32 fourcc;
|
||||
|
||||
ok &= gst_structure_get_fourcc (structure, "format", &fourcc);
|
||||
|
||||
*format = gst_video_fourcc_to_format (fourcc);
|
||||
if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
|
||||
ok = FALSE;
|
||||
}
|
||||
} else if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
|
||||
int depth;
|
||||
int bpp;
|
||||
int endianness;
|
||||
int red_mask;
|
||||
int green_mask;
|
||||
int blue_mask;
|
||||
|
||||
ok &= gst_structure_get_int (structure, "depth", &depth);
|
||||
ok &= gst_structure_get_int (structure, "bpp", &bpp);
|
||||
ok &= gst_structure_get_int (structure, "endianness", &endianness);
|
||||
ok &= gst_structure_get_int (structure, "red_mask", &red_mask);
|
||||
ok &= gst_structure_get_int (structure, "green_mask", &green_mask);
|
||||
ok &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
|
||||
|
||||
if (depth != 24 || bpp != 32 || endianness != G_BIG_ENDIAN) {
|
||||
ok = FALSE;
|
||||
} else {
|
||||
*format = gst_video_rgb32_masks_to_format (red_mask, green_mask,
|
||||
blue_mask);
|
||||
if (*format == GST_VIDEO_FORMAT_UNKNOWN) {
|
||||
ok = FALSE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ok = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (width) {
|
||||
ok &= gst_structure_get_int (structure, "width", width);
|
||||
}
|
||||
|
||||
if (height) {
|
||||
ok &= gst_structure_get_int (structure, "height", height);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_video_parse_caps_framerate (GstCaps * caps, int *fps_n, int *fps_d)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
||||
if (!gst_caps_is_fixed (caps))
|
||||
return FALSE;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
return gst_structure_get_fraction (structure, "framerate", fps_n, fps_d);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_video_parse_caps_pixel_aspect_ratio (GstCaps * caps, int *par_n, int *par_d)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
||||
if (!gst_caps_is_fixed (caps))
|
||||
return FALSE;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio",
|
||||
par_n, par_d)) {
|
||||
*par_n = 1;
|
||||
*par_d = 1;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GstCaps *
|
||||
gst_video_create_caps (GstVideoFormat format, int width, int height,
|
||||
int framerate_n, int framerate_d, int par_n, int par_d)
|
||||
{
|
||||
if (gst_video_format_is_yuv (format)) {
|
||||
return gst_caps_new_simple ("video/x-raw-yuv",
|
||||
"format", GST_TYPE_FOURCC, gst_video_format_to_fourcc (format),
|
||||
"width", G_TYPE_INT, width,
|
||||
"height", G_TYPE_INT, height,
|
||||
"framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
|
||||
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
|
||||
}
|
||||
if (gst_video_format_is_rgb (format)) {
|
||||
int red_mask;
|
||||
int blue_mask;
|
||||
int green_mask;
|
||||
|
||||
red_mask =
|
||||
0xff000000U >> gst_video_format_get_component_offset (format, 0, width,
|
||||
height);
|
||||
green_mask =
|
||||
0xff000000U >> gst_video_format_get_component_offset (format, 1, width,
|
||||
height);
|
||||
blue_mask =
|
||||
0xff000000U >> gst_video_format_get_component_offset (format, 2, width,
|
||||
height);
|
||||
|
||||
return gst_caps_new_simple ("video/x-raw-rgb",
|
||||
"bpp", G_TYPE_INT, 32,
|
||||
"depth", G_TYPE_INT, 24,
|
||||
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
|
||||
"red_mask", G_TYPE_INT, red_mask,
|
||||
"green_mask", G_TYPE_INT, green_mask,
|
||||
"blue_mask", G_TYPE_INT, blue_mask,
|
||||
"width", G_TYPE_INT, width,
|
||||
"height", G_TYPE_INT, height,
|
||||
"framerate", GST_TYPE_FRACTION, framerate_n, framerate_d,
|
||||
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GstVideoFormat
|
||||
gst_video_fourcc_to_format (guint32 fourcc)
|
||||
{
|
||||
switch (fourcc) {
|
||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
||||
return GST_VIDEO_FORMAT_I420;
|
||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
||||
return GST_VIDEO_FORMAT_YV12;
|
||||
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
||||
return GST_VIDEO_FORMAT_YUY2;
|
||||
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
|
||||
return GST_VIDEO_FORMAT_UYVY;
|
||||
case GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'):
|
||||
return GST_VIDEO_FORMAT_AYUV;
|
||||
default:
|
||||
return GST_VIDEO_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
guint32
|
||||
gst_video_format_to_fourcc (GstVideoFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
return GST_MAKE_FOURCC ('I', '4', '2', '0');
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
return GST_MAKE_FOURCC ('Y', 'V', '1', '2');
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
return GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
return GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
return GST_MAKE_FOURCC ('A', 'Y', 'U', 'V');
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GstVideoFormat
|
||||
gst_video_rgb32_masks_to_format (int red_mask, int green_mask, int blue_mask)
|
||||
{
|
||||
if (red_mask == 0xff000000 && green_mask == 0x00ff0000 &&
|
||||
blue_mask == 0x0000ff00) {
|
||||
return GST_VIDEO_FORMAT_RGBx;
|
||||
}
|
||||
if (red_mask == 0x0000ff00 && green_mask == 0x00ff0000 &&
|
||||
blue_mask == 0xff000000) {
|
||||
return GST_VIDEO_FORMAT_BGRx;
|
||||
}
|
||||
|
||||
return GST_VIDEO_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_video_format_is_rgb (GstVideoFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
return FALSE;
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_video_format_is_yuv (GstVideoFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
return TRUE;
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_video_format_has_alpha (GstVideoFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
return FALSE;
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
return TRUE;
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
||||
int width)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
if (component == 0) {
|
||||
return GST_ROUND_UP_4 (width);
|
||||
} else {
|
||||
return GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2);
|
||||
}
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
return GST_ROUND_UP_4 (width * 2);
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return width * 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_pixel_stride (GstVideoFormat format, int component)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
return 1;
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
if (component == 0) {
|
||||
return 2;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_component_width (GstVideoFormat format, int component,
|
||||
int width)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
if (component == 0) {
|
||||
return width;
|
||||
} else {
|
||||
return GST_ROUND_UP_2 (width) / 2;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return width;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_component_height (GstVideoFormat format, int component,
|
||||
int height)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
if (component == 0) {
|
||||
return height;
|
||||
} else {
|
||||
return GST_ROUND_UP_2 (height) / 2;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return height;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
||||
int width, int height)
|
||||
{
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
if (component == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
int offset;
|
||||
|
||||
offset = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
|
||||
if (component == 2) {
|
||||
offset += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
|
||||
(GST_ROUND_UP_2 (height) / 2);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
if (component == 0)
|
||||
return 0;
|
||||
if (component == 1)
|
||||
return 1;
|
||||
if (component == 2)
|
||||
return 3;
|
||||
return 0;
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
if (component == 0)
|
||||
return 1;
|
||||
if (component == 1)
|
||||
return 0;
|
||||
if (component == 2)
|
||||
return 2;
|
||||
return 0;
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
if (component == 0)
|
||||
return 1;
|
||||
if (component == 1)
|
||||
return 2;
|
||||
if (component == 2)
|
||||
return 3;
|
||||
if (component == 3)
|
||||
return 0;
|
||||
return 0;
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
if (component == 0)
|
||||
return 0;
|
||||
if (component == 1)
|
||||
return 1;
|
||||
if (component == 2)
|
||||
return 2;
|
||||
if (component == 3)
|
||||
return 3;
|
||||
return 0;
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
if (component == 0)
|
||||
return 2;
|
||||
if (component == 1)
|
||||
return 1;
|
||||
if (component == 2)
|
||||
return 0;
|
||||
if (component == 3)
|
||||
return 3;
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gst_video_format_get_size (GstVideoFormat format, int width, int height)
|
||||
{
|
||||
int size;
|
||||
|
||||
switch (format) {
|
||||
case GST_VIDEO_FORMAT_I420:
|
||||
case GST_VIDEO_FORMAT_YV12:
|
||||
size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height);
|
||||
size += GST_ROUND_UP_4 (GST_ROUND_UP_2 (width) / 2) *
|
||||
(GST_ROUND_UP_2 (height) / 2) * 2;
|
||||
return size;
|
||||
case GST_VIDEO_FORMAT_YUY2:
|
||||
case GST_VIDEO_FORMAT_UYVY:
|
||||
return GST_ROUND_UP_4 (width * 2) * height;
|
||||
case GST_VIDEO_FORMAT_AYUV:
|
||||
case GST_VIDEO_FORMAT_RGBx:
|
||||
case GST_VIDEO_FORMAT_BGRx:
|
||||
return width * 4 * height;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
gst_video_convert (GstVideoFormat format, int width, int height,
|
||||
int fps_n, int fps_d,
|
||||
GstFormat src_format, gint64 src_value,
|
||||
GstFormat dest_format, gint64 * dest_value)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
int size;
|
||||
|
||||
size = gst_video_format_get_size (format, width, height);
|
||||
|
||||
GST_DEBUG ("converting value %" G_GINT64_FORMAT " from %s to %s",
|
||||
src_value, gst_format_get_name (src_format),
|
||||
gst_format_get_name (dest_format));
|
||||
|
||||
if (src_format == dest_format) {
|
||||
*dest_value = src_value;
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (src_value == -1) {
|
||||
*dest_value = -1;
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* bytes to frames */
|
||||
if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_DEFAULT) {
|
||||
if (size != 0) {
|
||||
*dest_value = gst_util_uint64_scale_int (src_value, 1, size);
|
||||
} else {
|
||||
GST_ERROR ("blocksize is 0");
|
||||
*dest_value = 0;
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* frames to bytes */
|
||||
if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_BYTES) {
|
||||
*dest_value = gst_util_uint64_scale_int (src_value, size, 1);
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* time to frames */
|
||||
if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_DEFAULT) {
|
||||
if (fps_d != 0) {
|
||||
*dest_value = gst_util_uint64_scale (src_value,
|
||||
fps_n, GST_SECOND * fps_d);
|
||||
} else {
|
||||
GST_ERROR ("framerate denominator is 0");
|
||||
*dest_value = 0;
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* frames to time */
|
||||
if (src_format == GST_FORMAT_DEFAULT && dest_format == GST_FORMAT_TIME) {
|
||||
if (fps_n != 0) {
|
||||
*dest_value = gst_util_uint64_scale (src_value,
|
||||
GST_SECOND * fps_d, fps_n);
|
||||
} else {
|
||||
GST_ERROR ("framerate numerator is 0");
|
||||
*dest_value = 0;
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* time to bytes */
|
||||
if (src_format == GST_FORMAT_TIME && dest_format == GST_FORMAT_BYTES) {
|
||||
if (fps_d != 0) {
|
||||
*dest_value = gst_util_uint64_scale (src_value,
|
||||
fps_n * size, GST_SECOND * fps_d);
|
||||
} else {
|
||||
GST_ERROR ("framerate denominator is 0");
|
||||
*dest_value = 0;
|
||||
}
|
||||
ret = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* bytes to time */
|
||||
if (src_format == GST_FORMAT_BYTES && dest_format == GST_FORMAT_TIME) {
|
||||
if (fps_n != 0 && size != 0) {
|
||||
*dest_value = gst_util_uint64_scale (src_value,
|
||||
GST_SECOND * fps_d, fps_n * size);
|
||||
} else {
|
||||
GST_ERROR ("framerate denominator and/or blocksize is 0");
|
||||
*dest_value = 0;
|
||||
}
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
GST_DEBUG ("ret=%d result %" G_GINT64_FORMAT, ret, *dest_value);
|
||||
|
||||
return ret;
|
||||
}
|
53
gst/gl/gstvideo-common.h
Normal file
53
gst/gl/gstvideo-common.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
#ifndef __GST_VIDEO_COMMON_H__
|
||||
#define __GST_VIDEO_COMMON_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
typedef enum {
|
||||
GST_VIDEO_FORMAT_UNKNOWN,
|
||||
GST_VIDEO_FORMAT_I420,
|
||||
GST_VIDEO_FORMAT_YV12,
|
||||
GST_VIDEO_FORMAT_YUY2,
|
||||
GST_VIDEO_FORMAT_UYVY,
|
||||
GST_VIDEO_FORMAT_AYUV,
|
||||
GST_VIDEO_FORMAT_RGBx,
|
||||
GST_VIDEO_FORMAT_BGRx
|
||||
} GstVideoFormat;
|
||||
|
||||
|
||||
|
||||
gboolean gst_video_parse_caps (GstCaps *caps, GstVideoFormat *format,
|
||||
int *width, int *height);
|
||||
gboolean gst_video_parse_caps_framerate (GstCaps *caps,
|
||||
int *fps_n, int *fps_d);
|
||||
gboolean gst_video_parse_caps_pixel_aspect_ratio (GstCaps *caps,
|
||||
int *par_n, int *par_d);
|
||||
GstCaps * gst_video_create_caps (GstVideoFormat format,
|
||||
int width, int height, int framerate_n, int framerate_d,
|
||||
int par_n, int par_d);
|
||||
GstVideoFormat gst_video_fourcc_to_format (guint32 fourcc);
|
||||
guint32 gst_video_format_to_fourcc (GstVideoFormat format);
|
||||
GstVideoFormat gst_video_rgb32_masks_to_format (int red_mask, int green_mask, int blue_mask);
|
||||
gboolean gst_video_format_is_rgb (GstVideoFormat format);
|
||||
gboolean gst_video_format_is_yuv (GstVideoFormat format);
|
||||
gboolean gst_video_format_has_alpha (GstVideoFormat format);
|
||||
int gst_video_format_get_row_stride (GstVideoFormat format, int component,
|
||||
int width);
|
||||
int gst_video_format_get_pixel_stride (GstVideoFormat format, int component);
|
||||
int gst_video_format_get_component_width (GstVideoFormat format, int component,
|
||||
int width);
|
||||
int gst_video_format_get_component_height (GstVideoFormat format, int component,
|
||||
int height);
|
||||
int gst_video_format_get_component_offset (GstVideoFormat format, int component,
|
||||
int width, int height);
|
||||
int gst_video_format_get_size (GstVideoFormat format, int width, int height);
|
||||
gboolean gst_video_convert (GstVideoFormat format, int width, int height,
|
||||
int fps_n, int fps_d,
|
||||
GstFormat src_format, gint64 src_value,
|
||||
GstFormat dest_format, gint64 * dest_value);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in a new issue