[088/906] fix some caps negociations those pipelines works fine : gst-launch-0.10 -v videotestsrc ! video/x-raw-yuv, width=320, height=240 ! glgraphicmaker ! video/x-raw-gl, width=720 , height=576 ! glfiltercube ! glimagesink and gst-launch-0.10 -v videotestsrc ! video/x-raw-yuv, width=320, height=240 ! glgraphicmaker ! video/x-raw-gl, width=720 , height=576 ! glimagesink

git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@500 93df14bb-0f41-7a43-8087-d3e2a2f0e464
This commit is contained in:
Julien Isorce 2008-06-10 22:08:11 +00:00 committed by Matthew Waters
parent 752357e283
commit 268d9cd781
6 changed files with 191 additions and 52 deletions

View File

@ -93,7 +93,8 @@ gst_gl_buffer_get_type (void)
GstGLBuffer*
gst_gl_buffer_new_from_video_format (GstGLDisplay* display,
GstVideoFormat video_format, gint context_width, gint context_height,
GstVideoFormat video_format, gint context_width, gint context_height,
gint widthGL, gint heightGL,
gint width, gint height)
{
GstGLBuffer *buffer;
@ -109,8 +110,8 @@ gst_gl_buffer_new_from_video_format (GstGLDisplay* display,
buffer->width = width;
buffer->height = height;
buffer->video_format = video_format;
buffer->widthGL = context_width;
buffer->heightGL = context_height;
buffer->widthGL = widthGL;
buffer->heightGL = heightGL;
GST_BUFFER_SIZE (buffer) = gst_gl_buffer_format_get_size (video_format, context_width, context_height);
//blocking call, init texture

View File

@ -59,7 +59,8 @@ GType gst_gl_buffer_get_type (void);
#define gst_gl_buffer_unref(x) (gst_buffer_unref((GstBuffer *)(x)))
GstGLBuffer* gst_gl_buffer_new_from_video_format (GstGLDisplay* display, GstVideoFormat format,
gint context_width, gint context_height,
gint context_width, gint context_height,
gint widthGL, gint heightGL,
gint width, gint height);
gint gst_gl_buffer_format_get_size (GstVideoFormat format, gint width, gint height);
gboolean gst_gl_buffer_format_parse_caps (GstCaps* caps, GstVideoFormat* format,

View File

@ -254,6 +254,7 @@ gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
gl_outbuf = gst_gl_buffer_new_from_video_format (filter->display,
filter->video_format,
filter->width, filter->height,
filter->width, filter->height,
gl_inbuf->width, gl_inbuf->height);
*buf = GST_BUFFER (gl_outbuf);

View File

@ -76,6 +76,8 @@ static gboolean gst_gl_graphicmaker_set_caps (GstBaseTransform* bt,
GstCaps* incaps, GstCaps* outcaps);
static GstCaps *gst_gl_graphicmaker_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps);
static void gst_gl_graphicmaker_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps);
static gboolean gst_gl_graphicmaker_start (GstBaseTransform* bt);
static gboolean gst_gl_graphicmaker_stop (GstBaseTransform* bt);
static GstFlowReturn gst_gl_graphicmaker_prepare_output_buffer (GstBaseTransform* trans,
@ -110,6 +112,7 @@ gst_gl_graphicmaker_class_init (GstGLGraphicmakerClass * klass)
GST_BASE_TRANSFORM_CLASS (klass)->transform_caps =
gst_gl_graphicmaker_transform_caps;
GST_BASE_TRANSFORM_CLASS (klass)->fixate_caps = gst_gl_graphicmaker_fixate_caps;
GST_BASE_TRANSFORM_CLASS (klass)->transform = gst_gl_graphicmaker_transform;
GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_graphicmaker_start;
GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_graphicmaker_stop;
@ -186,74 +189,203 @@ gst_gl_graphicmaker_transform_caps (GstBaseTransform* bt,
GstPadDirection direction, GstCaps* caps)
{
GstGLGraphicmaker* graphicmaker = GST_GL_GRAPHICMAKER (bt);
GstStructure* structure;
GstCaps* newcaps, *newothercaps;
GstStructure* newstruct;
const GValue* width_value;
const GValue* height_value;
const GValue* framerate_value;
const GValue* par_value;
GstStructure* structure = gst_caps_get_structure (caps, 0);
GstCaps* newcaps = NULL;
const GValue* framerate_value = NULL;
const GValue* par_value = NULL;
GST_ERROR ("transform caps %" GST_PTR_FORMAT, caps);
structure = gst_caps_get_structure (caps, 0);
width_value = gst_structure_get_value (structure, "width");
height_value = gst_structure_get_value (structure, "height");
framerate_value = gst_structure_get_value (structure, "framerate");
framerate_value = gst_structure_get_value (structure, "framerate");
par_value = gst_structure_get_value (structure, "pixel-aspect-ratio");
if (direction == GST_PAD_SRC)
{
newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
newstruct = gst_caps_get_structure (newothercaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
gst_structure_set_value (newstruct, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
else
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
gst_caps_append(newcaps, newothercaps);
newstruct = gst_caps_get_structure (newcaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
}
else
if (direction == GST_PAD_SRC)
{
newcaps = gst_caps_new_simple ("video/x-raw-gl", NULL);
newstruct = gst_caps_get_structure (newcaps, 0);
gst_structure_set_value (newstruct, "width", width_value);
gst_structure_set_value (newstruct, "height", height_value);
}
GstCaps* newothercaps = gst_caps_new_simple ("video/x-raw-rgb", NULL);
newcaps = gst_caps_new_simple ("video/x-raw-yuv", NULL);
gst_caps_append(newcaps, newothercaps);
}
else
newcaps = gst_caps_new_simple ("video/x-raw-gl", NULL);
structure = gst_structure_copy (gst_caps_get_structure (newcaps, 0));
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
gst_structure_set_value (newstruct, "framerate", framerate_value);
gst_structure_set_value (structure, "framerate", framerate_value);
if (par_value)
gst_structure_set_value (newstruct, "pixel-aspect-ratio", par_value);
gst_structure_set_value (structure, "pixel-aspect-ratio", par_value);
else
gst_structure_set (newstruct, "pixel-aspect-ratio", GST_TYPE_FRACTION,
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION,
1, 1, NULL);
gst_caps_merge_structure (newcaps, gst_structure_copy (structure));
GST_ERROR ("new caps %" GST_PTR_FORMAT, newcaps);
return newcaps;
}
/* from gst-plugins-base "videoscale" code */
static void
gst_gl_graphicmaker_fixate_caps (GstBaseTransform* base, GstPadDirection direction,
GstCaps* caps, GstCaps* othercaps)
{
GstStructure *ins, *outs;
const GValue *from_par, *to_par;
g_return_if_fail (gst_caps_is_fixed (caps));
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
ins = gst_caps_get_structure (caps, 0);
outs = gst_caps_get_structure (othercaps, 0);
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
//we have both PAR but they might not be fixated
if (from_par && to_par)
{
gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
gint count = 0, w = 0, h = 0;
guint num, den;
//from_par should be fixed
g_return_if_fail (gst_value_is_fixed (from_par));
from_par_n = gst_value_get_fraction_numerator (from_par);
from_par_d = gst_value_get_fraction_denominator (from_par);
//fixate the out PAR
if (!gst_value_is_fixed (to_par))
{
GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", from_par_n,
from_par_d);
gst_structure_fixate_field_nearest_fraction (outs, "pixel-aspect-ratio",
from_par_n, from_par_d);
}
to_par_n = gst_value_get_fraction_numerator (to_par);
to_par_d = gst_value_get_fraction_denominator (to_par);
//f both width and height are already fixed, we can't do anything
//about it anymore
if (gst_structure_get_int (outs, "width", &w))
++count;
if (gst_structure_get_int (outs, "height", &h))
++count;
if (count == 2)
{
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
w, h);
return;
}
gst_structure_get_int (ins, "width", &from_w);
gst_structure_get_int (ins, "height", &from_h);
if (!gst_video_calculate_display_ratio (&num, &den, from_w, from_h,
from_par_n, from_par_d, to_par_n, to_par_d))
{
GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
("Error calculating the output scaled size - integer overflow"));
return;
}
GST_DEBUG_OBJECT (base,
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
GST_DEBUG_OBJECT (base, "resulting output should respect ratio of %d/%d",
num, den);
//now find a width x height that respects this display ratio.
//prefer those that have one of w/h the same as the incoming video
//using wd / hd = num / den
//if one of the output width or height is fixed, we work from there
if (h)
{
GST_DEBUG_OBJECT (base, "height is fixed,scaling width");
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (w)
{
GST_DEBUG_OBJECT (base, "width is fixed, scaling height");
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
//none of width or height is fixed, figure out both of them based only on
//the input width and height
//check hd / den is an integer scale factor, and scale wd with the PAR
if (from_h % den == 0)
{
GST_DEBUG_OBJECT (base, "keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
else if (from_w % num == 0)
{
GST_DEBUG_OBJECT (base, "keeping video width");
w = from_w;
h = (guint) gst_util_uint64_scale_int (w, den, num);
}
else
{
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
h = from_h;
w = (guint) gst_util_uint64_scale_int (h, num, den);
}
}
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
//now fixate
gst_structure_fixate_field_nearest_int (outs, "width", w);
gst_structure_fixate_field_nearest_int (outs, "height", h);
}
else
{
gint width, height;
if (gst_structure_get_int (ins, "width", &width))
{
if (gst_structure_has_field (outs, "width"))
gst_structure_fixate_field_nearest_int (outs, "width", width);
}
if (gst_structure_get_int (ins, "height", &height)) {
if (gst_structure_has_field (outs, "height")) {
gst_structure_fixate_field_nearest_int (outs, "height", height);
}
}
}
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
}
static gboolean
gst_gl_graphicmaker_set_caps (GstBaseTransform* bt, GstCaps* incaps,
GstCaps* outcaps)
{
GstGLGraphicmaker* graphicmaker = GST_GL_GRAPHICMAKER (bt);
gboolean ret = FALSE;
GstVideoFormat video_format = GST_VIDEO_FORMAT_UNKNOWN;
static gint glcontext_y = 0;
GST_DEBUG ("called with %" GST_PTR_FORMAT, incaps);
ret = gst_video_format_parse_caps (incaps, &graphicmaker->video_format,
&graphicmaker->width, &graphicmaker->height);
ret = gst_video_format_parse_caps (outcaps, &video_format,
&graphicmaker->outWidth, &graphicmaker->outHeight);
ret |= gst_video_format_parse_caps (incaps, &graphicmaker->video_format,
&graphicmaker->inWidth, &graphicmaker->inHeight);
if (!ret)
{
@ -265,9 +397,9 @@ gst_gl_graphicmaker_set_caps (GstBaseTransform* bt, GstCaps* incaps,
//init unvisible opengl context
gst_gl_display_initGLContext (graphicmaker->display,
50, glcontext_y++ * (graphicmaker->height+50) + 50,
graphicmaker->width, graphicmaker->height,
graphicmaker->width, graphicmaker->height, 0, FALSE);
50, glcontext_y++ * (graphicmaker->inHeight+50) + 50,
graphicmaker->inWidth, graphicmaker->inHeight,
graphicmaker->inWidth, graphicmaker->inHeight, 0, FALSE);
return ret;
}
@ -314,8 +446,9 @@ gst_gl_graphicmaker_prepare_output_buffer (GstBaseTransform* trans,
//blocking call
gl_outbuf = gst_gl_buffer_new_from_video_format (graphicmaker->display,
graphicmaker->video_format,
graphicmaker->width, graphicmaker->height,
graphicmaker->width, graphicmaker->height);
graphicmaker->outWidth, graphicmaker->outHeight,
graphicmaker->inWidth, graphicmaker->inHeight,
graphicmaker->inWidth, graphicmaker->inHeight);
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);

View File

@ -49,8 +49,10 @@ struct _GstGLGraphicmaker
GstGLDisplay *display;
GstVideoFormat video_format;
gint width;
gint height;
gint inWidth;
gint inHeight;
gint outWidth;
gint outHeight;
};
struct _GstGLGraphicmakerClass

View File

@ -446,6 +446,7 @@ gst_glimage_sink_render (GstBaseSink* bsink, GstBuffer* buf)
//blocking call
gl_buffer = gst_gl_buffer_new_from_video_format (glimage_sink->display,
glimage_sink->format, glimage_sink->width, glimage_sink->height,
glimage_sink->width, glimage_sink->height,
glimage_sink->width, glimage_sink->height);
//blocking call