mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
x11: use GstVideoInfo to parse caps
Use GstVideoInfo to keep track of the configured format. Add GstMetaVideo to buffers, disabled by default for now until we can have it enabled with a property on the bufferpool configuration.
This commit is contained in:
parent
7426f19027
commit
5eeb468c75
2 changed files with 55 additions and 33 deletions
|
@ -27,6 +27,10 @@
|
||||||
/* Debugging category */
|
/* Debugging category */
|
||||||
#include <gst/gstinfo.h>
|
#include <gst/gstinfo.h>
|
||||||
|
|
||||||
|
/* Helper functions */
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/video/gstmetavideo.h>
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_EXTERN (gst_debug_ximagepool);
|
GST_DEBUG_CATEGORY_EXTERN (gst_debug_ximagepool);
|
||||||
#define GST_CAT_DEFAULT gst_debug_ximagepool
|
#define GST_CAT_DEFAULT gst_debug_ximagepool
|
||||||
|
|
||||||
|
@ -429,7 +433,8 @@ static void gst_ximage_buffer_pool_finalize (GObject * object);
|
||||||
struct _GstXImageBufferPoolPrivate
|
struct _GstXImageBufferPoolPrivate
|
||||||
{
|
{
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
gint width, height;
|
GstVideoInfo info;
|
||||||
|
gboolean add_metavideo;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstXImageBufferPool, gst_ximage_buffer_pool,
|
G_DEFINE_TYPE (GstXImageBufferPool, gst_ximage_buffer_pool,
|
||||||
|
@ -440,8 +445,7 @@ ximage_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
{
|
{
|
||||||
GstXImageBufferPool *xpool = GST_XIMAGE_BUFFER_POOL_CAST (pool);
|
GstXImageBufferPool *xpool = GST_XIMAGE_BUFFER_POOL_CAST (pool);
|
||||||
GstXImageBufferPoolPrivate *priv = xpool->priv;
|
GstXImageBufferPoolPrivate *priv = xpool->priv;
|
||||||
GstStructure *structure;
|
GstVideoInfo info;
|
||||||
gint width, height;
|
|
||||||
const GstCaps *caps;
|
const GstCaps *caps;
|
||||||
|
|
||||||
if (!gst_buffer_pool_config_get (config, &caps, NULL, NULL, NULL, NULL, NULL))
|
if (!gst_buffer_pool_config_get (config, &caps, NULL, NULL, NULL, NULL, NULL))
|
||||||
|
@ -451,20 +455,20 @@ ximage_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
goto no_caps;
|
goto no_caps;
|
||||||
|
|
||||||
/* now parse the caps from the config */
|
/* now parse the caps from the config */
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
if (!gst_video_info_from_caps (&info, caps))
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "width", &width) ||
|
|
||||||
!gst_structure_get_int (structure, "height", &height))
|
|
||||||
goto wrong_caps;
|
goto wrong_caps;
|
||||||
|
|
||||||
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, width, height, caps);
|
priv->info = info;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height,
|
||||||
|
caps);
|
||||||
|
|
||||||
/* keep track of the width and height and caps */
|
/* keep track of the width and height and caps */
|
||||||
if (priv->caps)
|
if (priv->caps)
|
||||||
gst_caps_unref (priv->caps);
|
gst_caps_unref (priv->caps);
|
||||||
priv->caps = gst_caps_copy (caps);
|
priv->caps = gst_caps_copy (caps);
|
||||||
priv->width = width;
|
/* FIXME, configure based on config of the bufferpool */
|
||||||
priv->height = height;
|
priv->add_metavideo = FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -499,12 +503,17 @@ ximage_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
||||||
|
|
||||||
ximage = gst_buffer_new ();
|
ximage = gst_buffer_new ();
|
||||||
meta =
|
meta =
|
||||||
gst_buffer_add_meta_ximage (ximage, xpool->sink, priv->width,
|
gst_buffer_add_meta_ximage (ximage, xpool->sink, priv->info.width,
|
||||||
priv->height);
|
priv->info.height);
|
||||||
if (meta == NULL) {
|
if (meta == NULL) {
|
||||||
gst_buffer_unref (ximage);
|
gst_buffer_unref (ximage);
|
||||||
goto no_buffer;
|
goto no_buffer;
|
||||||
}
|
}
|
||||||
|
if (priv->add_metavideo) {
|
||||||
|
/* these are just the defaults for now */
|
||||||
|
gst_buffer_add_meta_video (ximage, 0, priv->info.format, priv->info.width,
|
||||||
|
priv->info.height);
|
||||||
|
}
|
||||||
*buffer = ximage;
|
*buffer = ximage;
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
/* Debugging category */
|
/* Debugging category */
|
||||||
#include <gst/gstinfo.h>
|
#include <gst/gstinfo.h>
|
||||||
|
|
||||||
|
/* Helper functions */
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/video/gstmetavideo.h>
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_EXTERN (gst_debug_xvimagepool);
|
GST_DEBUG_CATEGORY_EXTERN (gst_debug_xvimagepool);
|
||||||
#define GST_CAT_DEFAULT gst_debug_xvimagepool
|
#define GST_CAT_DEFAULT gst_debug_xvimagepool
|
||||||
|
|
||||||
|
@ -461,8 +465,9 @@ static void gst_xvimage_buffer_pool_finalize (GObject * object);
|
||||||
struct _GstXvImageBufferPoolPrivate
|
struct _GstXvImageBufferPoolPrivate
|
||||||
{
|
{
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
gint width, height;
|
|
||||||
gint im_format;
|
gint im_format;
|
||||||
|
GstVideoInfo info;
|
||||||
|
gboolean add_metavideo;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstXvImageBufferPool, gst_xvimage_buffer_pool,
|
G_DEFINE_TYPE (GstXvImageBufferPool, gst_xvimage_buffer_pool,
|
||||||
|
@ -473,8 +478,7 @@ xvimage_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
{
|
{
|
||||||
GstXvImageBufferPool *xvpool = GST_XVIMAGE_BUFFER_POOL_CAST (pool);
|
GstXvImageBufferPool *xvpool = GST_XVIMAGE_BUFFER_POOL_CAST (pool);
|
||||||
GstXvImageBufferPoolPrivate *priv = xvpool->priv;
|
GstXvImageBufferPoolPrivate *priv = xvpool->priv;
|
||||||
GstStructure *structure;
|
GstVideoInfo info;
|
||||||
gint width, height;
|
|
||||||
const GstCaps *caps;
|
const GstCaps *caps;
|
||||||
|
|
||||||
if (!gst_buffer_pool_config_get (config, &caps, NULL, NULL, NULL, NULL, NULL))
|
if (!gst_buffer_pool_config_get (config, &caps, NULL, NULL, NULL, NULL, NULL))
|
||||||
|
@ -484,31 +488,24 @@ xvimage_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
goto no_caps;
|
goto no_caps;
|
||||||
|
|
||||||
/* now parse the caps from the config */
|
/* now parse the caps from the config */
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
if (!gst_video_info_from_caps (&info, caps))
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "width", &width) ||
|
|
||||||
!gst_structure_get_int (structure, "height", &height))
|
|
||||||
goto wrong_caps;
|
goto wrong_caps;
|
||||||
|
|
||||||
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, width, height, caps);
|
priv->info = info;
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, info.width, info.height,
|
||||||
|
caps);
|
||||||
|
|
||||||
/* keep track of the width and height and caps */
|
/* keep track of the width and height and caps */
|
||||||
if (priv->caps)
|
if (priv->caps)
|
||||||
gst_caps_unref (priv->caps);
|
gst_caps_unref (priv->caps);
|
||||||
priv->caps = gst_caps_copy (caps);
|
priv->caps = gst_caps_copy (caps);
|
||||||
priv->width = width;
|
|
||||||
priv->height = height;
|
|
||||||
priv->im_format =
|
priv->im_format =
|
||||||
gst_xvimagesink_get_format_from_caps (xvpool->sink, (GstCaps *) caps);
|
gst_xvimagesink_get_format_from_caps (xvpool->sink, (GstCaps *) caps);
|
||||||
|
/* FIXME, enable metadata based on config of the pool */
|
||||||
if (priv->im_format == -1) {
|
priv->add_metavideo = FALSE;
|
||||||
GST_WARNING_OBJECT (xvpool->sink, "failed to get format from caps %"
|
if (priv->im_format == -1)
|
||||||
GST_PTR_FORMAT, caps);
|
goto unknown_format;
|
||||||
GST_ELEMENT_ERROR (xvpool->sink, RESOURCE, WRITE,
|
|
||||||
("Failed to create output image buffer of %dx%d pixels",
|
|
||||||
priv->width, priv->height), ("Invalid input caps"));
|
|
||||||
goto wrong_config;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -529,6 +526,15 @@ wrong_caps:
|
||||||
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
unknown_format:
|
||||||
|
{
|
||||||
|
GST_WARNING_OBJECT (xvpool->sink, "failed to get format from caps %"
|
||||||
|
GST_PTR_FORMAT, caps);
|
||||||
|
GST_ELEMENT_ERROR (xvpool->sink, RESOURCE, WRITE,
|
||||||
|
("Failed to create output image buffer of %dx%d pixels",
|
||||||
|
priv->info.width, priv->info.height), ("Invalid input caps"));
|
||||||
|
return FALSE;;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function handles GstXImageBuffer creation depending on XShm availability */
|
/* This function handles GstXImageBuffer creation depending on XShm availability */
|
||||||
|
@ -543,12 +549,19 @@ xvimage_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
||||||
|
|
||||||
xvimage = gst_buffer_new ();
|
xvimage = gst_buffer_new ();
|
||||||
meta =
|
meta =
|
||||||
gst_buffer_add_meta_xvimage (xvimage, xvpool->sink, priv->width,
|
gst_buffer_add_meta_xvimage (xvimage, xvpool->sink, priv->info.width,
|
||||||
priv->height, priv->im_format);
|
priv->info.height, priv->im_format);
|
||||||
if (meta == NULL) {
|
if (meta == NULL) {
|
||||||
gst_buffer_unref (xvimage);
|
gst_buffer_unref (xvimage);
|
||||||
goto no_buffer;
|
goto no_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (priv->add_metavideo) {
|
||||||
|
/* these are just the defaults for now */
|
||||||
|
gst_buffer_add_meta_video (xvimage, 0, priv->info.format, priv->info.width,
|
||||||
|
priv->info.height);
|
||||||
|
}
|
||||||
|
|
||||||
*buffer = xvimage;
|
*buffer = xvimage;
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
|
|
Loading…
Reference in a new issue