use autodetected PAR if none specified. add directfb workaround.

Original commit message from CVS:
use autodetected PAR if none specified. add directfb workaround.
This commit is contained in:
Thomas Vander Stichele 2004-07-28 21:28:34 +00:00
parent a7b89a7bc7
commit 8330cdfbad
3 changed files with 111 additions and 50 deletions

View file

@ -1,3 +1,17 @@
2004-07-28 Thomas Vander Stichele <thomas at apestaart dot org>
* sys/ximage/ximagesink.c: (gst_ximagesink_renegotiate_size),
(gst_ximagesink_calculate_pixel_aspect_ratio),
(gst_ximagesink_xcontext_get), (gst_ximagesink_getcaps),
(gst_ximagesink_sink_link), (gst_ximagesink_change_state),
(gst_ximagesink_set_xwindow_id), (gst_ximagesink_set_property),
(gst_ximagesink_get_property), (gst_ximagesink_init):
* sys/ximage/ximagesink.h:
allocate PAR's dynamically.
use autodetected PAR if no object-set PAR is given.
add workaround for directfb's X not setting physical size.
fix to xvimagesink will follow tomorrow.
2004-07-28 Zaheer Abbas Merali <zaheerabbas at merali dot org> 2004-07-28 Zaheer Abbas Merali <zaheerabbas at merali dot org>
* ext/lame/gstlame.c: (gst_lame_chain): send tag events downstream * ext/lame/gstlame.c: (gst_lame_chain): send tag events downstream

View file

@ -531,9 +531,9 @@ gst_ximagesink_renegotiate_size (GstXImageSink * ximagesink)
if (GST_VIDEOSINK_WIDTH (ximagesink) != ximagesink->xwindow->width || if (GST_VIDEOSINK_WIDTH (ximagesink) != ximagesink->xwindow->width ||
GST_VIDEOSINK_HEIGHT (ximagesink) != ximagesink->xwindow->height) { GST_VIDEOSINK_HEIGHT (ximagesink) != ximagesink->xwindow->height) {
GstPadLinkReturn r; GstPadLinkReturn r;
GstCaps *caps;
r = gst_pad_try_set_caps (GST_VIDEOSINK_PAD (ximagesink), caps = gst_caps_new_simple ("video/x-raw-rgb",
gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, ximagesink->xcontext->bpp, "bpp", G_TYPE_INT, ximagesink->xcontext->bpp,
"depth", G_TYPE_INT, ximagesink->xcontext->depth, "depth", G_TYPE_INT, ximagesink->xcontext->depth,
"endianness", G_TYPE_INT, ximagesink->xcontext->endianness, "endianness", G_TYPE_INT, ximagesink->xcontext->endianness,
@ -542,11 +542,18 @@ gst_ximagesink_renegotiate_size (GstXImageSink * ximagesink)
"blue_mask", G_TYPE_INT, ximagesink->xcontext->visual->blue_mask, "blue_mask", G_TYPE_INT, ximagesink->xcontext->visual->blue_mask,
"width", G_TYPE_INT, ximagesink->xwindow->width, "width", G_TYPE_INT, ximagesink->xwindow->width,
"height", G_TYPE_INT, ximagesink->xwindow->height, "height", G_TYPE_INT, ximagesink->xwindow->height,
/* for now we use the object-set value for par */ "framerate", G_TYPE_DOUBLE, ximagesink->framerate, NULL);
"pixel-aspect-ratio", GST_TYPE_FRACTION,
gst_value_get_fraction_numerator (&ximagesink->par), if (ximagesink->par) {
gst_value_get_fraction_denominator (&ximagesink->par), int nom, den;
"framerate", G_TYPE_DOUBLE, ximagesink->framerate, NULL));
nom = gst_value_get_fraction_numerator (ximagesink->par);
den = gst_value_get_fraction_denominator (ximagesink->par);
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
nom, den, NULL);
}
r = gst_pad_try_set_caps (GST_VIDEOSINK_PAD (ximagesink), caps);
if ((r == GST_PAD_LINK_OK) || (r == GST_PAD_LINK_DONE)) { if ((r == GST_PAD_LINK_OK) || (r == GST_PAD_LINK_DONE)) {
/* Renegotiation succeeded, we update our size and image */ /* Renegotiation succeeded, we update our size and image */
@ -684,6 +691,12 @@ gst_ximagesink_calculate_pixel_aspect_ratio (GstXContext * xcontext)
* which is the "physical" w/h divided by the w/h in pixels of the display */ * which is the "physical" w/h divided by the w/h in pixels of the display */
ratio = xcontext->widthmm * xcontext->height ratio = xcontext->widthmm * xcontext->height
/ (xcontext->heightmm * xcontext->width); / (xcontext->heightmm * xcontext->width);
/* DirectFB's X in 720x576 reports the physical dimensions wrong, so
* override here */
if (xcontext->width == 720 && xcontext->height == 576) {
ratio = 4.0 * 576 / (3.0 * 720);
}
GST_DEBUG ("calculated pixel aspect ratio: %f", ratio); GST_DEBUG ("calculated pixel aspect ratio: %f", ratio);
/* now find the one from par[][2] with the lowest delta to the real one */ /* now find the one from par[][2] with the lowest delta to the real one */
@ -702,8 +715,13 @@ gst_ximagesink_calculate_pixel_aspect_ratio (GstXContext * xcontext)
GST_DEBUG ("Decided on index %d (%d/%d)", index, GST_DEBUG ("Decided on index %d (%d/%d)", index,
par[index][0], par[index][1]); par[index][0], par[index][1]);
g_value_init (&xcontext->par, GST_TYPE_FRACTION); g_free (xcontext->par);
gst_value_set_fraction (&xcontext->par, par[index][0], par[index][1]); xcontext->par = g_new0 (GValue, 1);
g_value_init (xcontext->par, GST_TYPE_FRACTION);
gst_value_set_fraction (xcontext->par, par[index][0], par[index][1]);
GST_DEBUG ("set xcontext PAR to %d/%d",
gst_value_get_fraction_numerator (xcontext->par),
gst_value_get_fraction_denominator (xcontext->par));
} }
/* This function gets the X Display and global info about it. Everything is /* This function gets the X Display and global info about it. Everything is
@ -805,11 +823,15 @@ gst_ximagesink_xcontext_get (GstXImageSink * ximagesink)
"blue_mask", G_TYPE_INT, xcontext->visual->blue_mask, "blue_mask", G_TYPE_INT, xcontext->visual->blue_mask,
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT, "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT, "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
/* for now we use the object-set value for par */
"pixel-aspect-ratio", GST_TYPE_FRACTION,
gst_value_get_fraction_numerator (&ximagesink->par),
gst_value_get_fraction_denominator (&ximagesink->par),
"framerate", GST_TYPE_DOUBLE_RANGE, 0.0, G_MAXDOUBLE, NULL); "framerate", GST_TYPE_DOUBLE_RANGE, 0.0, G_MAXDOUBLE, NULL);
if (ximagesink->par) {
int nom, den;
nom = gst_value_get_fraction_numerator (ximagesink->par);
den = gst_value_get_fraction_denominator (ximagesink->par);
gst_caps_set_simple (xcontext->caps, "pixel-aspect-ratio",
GST_TYPE_FRACTION, nom, den, NULL);
}
g_mutex_unlock (ximagesink->x_lock); g_mutex_unlock (ximagesink->x_lock);
@ -824,6 +846,7 @@ gst_ximagesink_xcontext_clear (GstXImageSink * ximagesink)
g_return_if_fail (GST_IS_XIMAGESINK (ximagesink)); g_return_if_fail (GST_IS_XIMAGESINK (ximagesink));
gst_caps_free (ximagesink->xcontext->caps); gst_caps_free (ximagesink->xcontext->caps);
g_free (ximagesink->xcontext->par);
g_mutex_lock (ximagesink->x_lock); g_mutex_lock (ximagesink->x_lock);
@ -898,9 +921,14 @@ gst_ximagesink_getcaps (GstPad * pad)
for (i = 0; i < gst_caps_get_size (caps); ++i) { for (i = 0; i < gst_caps_get_size (caps); ++i) {
GstStructure *structure = gst_caps_get_structure (caps, i); GstStructure *structure = gst_caps_get_structure (caps, i);
gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, if (ximagesink->par) {
gst_value_get_fraction_numerator (&ximagesink->par), int nom, den;
gst_value_get_fraction_denominator (&ximagesink->par), NULL);
nom = gst_value_get_fraction_numerator (ximagesink->par);
den = gst_value_get_fraction_denominator (ximagesink->par);
gst_structure_set (structure, "pixel-aspect-ratio",
GST_TYPE_FRACTION, nom, den, NULL);
}
} }
return caps; return caps;
} }
@ -936,7 +964,7 @@ gst_ximagesink_sink_link (GstPad * pad, const GstCaps * caps)
* otherwise linking should fail */ * otherwise linking should fail */
par = gst_structure_get_value (structure, "pixel-aspect-ratio"); par = gst_structure_get_value (structure, "pixel-aspect-ratio");
if (par) { if (par) {
if (gst_value_compare (par, &ximagesink->par) != GST_VALUE_EQUAL) { if (gst_value_compare (par, ximagesink->par) != GST_VALUE_EQUAL) {
GST_INFO_OBJECT (ximagesink, "pixel aspect ratio does not match"); GST_INFO_OBJECT (ximagesink, "pixel aspect ratio does not match");
return GST_PAD_LINK_REFUSED; return GST_PAD_LINK_REFUSED;
} }
@ -984,6 +1012,12 @@ gst_ximagesink_change_state (GstElement * element)
ximagesink->xcontext = gst_ximagesink_xcontext_get (ximagesink); ximagesink->xcontext = gst_ximagesink_xcontext_get (ximagesink);
if (!ximagesink->xcontext) if (!ximagesink->xcontext)
return GST_STATE_FAILURE; return GST_STATE_FAILURE;
/* update object's par with calculated one if not set yet */
if (!ximagesink->par) {
ximagesink->par = g_new0 (GValue, 1);
gst_value_init_and_copy (ximagesink->par, ximagesink->xcontext->par);
GST_DEBUG_OBJECT (ximagesink, "set calculated PAR on object's PAR");
}
/* call XSynchronize with the current value of synchronous */ /* call XSynchronize with the current value of synchronous */
GST_DEBUG_OBJECT (ximagesink, "XSynchronize called with %s", GST_DEBUG_OBJECT (ximagesink, "XSynchronize called with %s",
ximagesink->synchronous ? "TRUE" : "FALSE"); ximagesink->synchronous ? "TRUE" : "FALSE");
@ -1022,6 +1056,8 @@ gst_ximagesink_change_state (GstElement * element)
gst_ximagesink_xcontext_clear (ximagesink); gst_ximagesink_xcontext_clear (ximagesink);
ximagesink->xcontext = NULL; ximagesink->xcontext = NULL;
} }
g_free (ximagesink->par);
ximagesink->par = NULL;
break; break;
} }
@ -1303,9 +1339,9 @@ gst_ximagesink_set_xwindow_id (GstXOverlay * overlay, XID xwindow_id)
(xwindow->width != GST_VIDEOSINK_WIDTH (ximagesink) || (xwindow->width != GST_VIDEOSINK_WIDTH (ximagesink) ||
xwindow->height != GST_VIDEOSINK_HEIGHT (ximagesink))) { xwindow->height != GST_VIDEOSINK_HEIGHT (ximagesink))) {
GstPadLinkReturn r; GstPadLinkReturn r;
GstCaps *caps;
r = gst_pad_try_set_caps (GST_VIDEOSINK_PAD (ximagesink), caps = gst_caps_new_simple ("video/x-raw-rgb",
gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, ximagesink->xcontext->bpp, "bpp", G_TYPE_INT, ximagesink->xcontext->bpp,
"depth", G_TYPE_INT, ximagesink->xcontext->depth, "depth", G_TYPE_INT, ximagesink->xcontext->depth,
"endianness", G_TYPE_INT, ximagesink->xcontext->endianness, "endianness", G_TYPE_INT, ximagesink->xcontext->endianness,
@ -1316,11 +1352,17 @@ gst_ximagesink_set_xwindow_id (GstXOverlay * overlay, XID xwindow_id)
ximagesink->xcontext->visual->blue_mask, ximagesink->xcontext->visual->blue_mask,
"width", G_TYPE_INT, xwindow->width, "width", G_TYPE_INT, xwindow->width,
"height", G_TYPE_INT, xwindow->height, "height", G_TYPE_INT, xwindow->height,
/* for now we use the object-set value for par */ "framerate", G_TYPE_DOUBLE, ximagesink->framerate, NULL);
"pixel-aspect-ratio", GST_TYPE_FRACTION,
gst_value_get_fraction_numerator (&ximagesink->par), if (ximagesink->par) {
gst_value_get_fraction_denominator (&ximagesink->par), int nom, den;
"framerate", G_TYPE_DOUBLE, ximagesink->framerate, NULL));
nom = gst_value_get_fraction_numerator (ximagesink->par);
den = gst_value_get_fraction_denominator (ximagesink->par);
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
nom, den, NULL);
}
r = gst_pad_try_set_caps (GST_VIDEOSINK_PAD (ximagesink), caps);
/* If caps nego succeded updating our size */ /* If caps nego succeded updating our size */
if ((r == GST_PAD_LINK_OK) || (r == GST_PAD_LINK_DONE)) { if ((r == GST_PAD_LINK_OK) || (r == GST_PAD_LINK_DONE)) {
@ -1402,11 +1444,16 @@ gst_ximagesink_set_property (GObject * object, guint prop_id,
} }
break; break;
case ARG_PIXEL_ASPECT_RATIO: case ARG_PIXEL_ASPECT_RATIO:
if (!g_value_transform (value, &ximagesink->par)) g_free (ximagesink->par);
ximagesink->par = g_new0 (GValue, 1);
g_value_init (ximagesink->par, GST_TYPE_FRACTION);
if (!g_value_transform (value, ximagesink->par)) {
g_warning ("Could not transform string to aspect ratio"); g_warning ("Could not transform string to aspect ratio");
gst_value_set_fraction (ximagesink->par, 1, 1);
}
GST_DEBUG_OBJECT (ximagesink, "set PAR to %d/%d", GST_DEBUG_OBJECT (ximagesink, "set PAR to %d/%d",
gst_value_get_fraction_numerator (&ximagesink->par), gst_value_get_fraction_numerator (ximagesink->par),
gst_value_get_fraction_denominator (&ximagesink->par)); gst_value_get_fraction_denominator (ximagesink->par));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1432,7 +1479,8 @@ gst_ximagesink_get_property (GObject * object, guint prop_id,
g_value_set_boolean (value, ximagesink->synchronous); g_value_set_boolean (value, ximagesink->synchronous);
break; break;
case ARG_PIXEL_ASPECT_RATIO: case ARG_PIXEL_ASPECT_RATIO:
g_value_transform (&ximagesink->par, value); if (ximagesink->par)
g_value_transform (ximagesink->par, value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1496,8 +1544,7 @@ gst_ximagesink_init (GstXImageSink * ximagesink)
ximagesink->sw_scaling_failed = FALSE; ximagesink->sw_scaling_failed = FALSE;
ximagesink->synchronous = FALSE; ximagesink->synchronous = FALSE;
g_value_init (&ximagesink->par, GST_TYPE_FRACTION); ximagesink->par = NULL;
gst_value_set_fraction (&ximagesink->par, 1, 1);
GST_FLAG_SET (ximagesink, GST_ELEMENT_THREAD_SUGGESTED); GST_FLAG_SET (ximagesink, GST_ELEMENT_THREAD_SUGGESTED);
GST_FLAG_SET (ximagesink, GST_ELEMENT_EVENT_AWARE); GST_FLAG_SET (ximagesink, GST_ELEMENT_EVENT_AWARE);

View file

@ -77,7 +77,7 @@ struct _GstXContext {
gint width, height; gint width, height;
gint widthmm, heightmm; gint widthmm, heightmm;
GValue par; /* calculated pixel aspect ratio */ GValue *par; /* calculated pixel aspect ratio */
gboolean use_xshm; gboolean use_xshm;
@ -122,7 +122,7 @@ struct _GstXImageSink {
/* Unused */ /* Unused */
gint pixel_width, pixel_height; gint pixel_width, pixel_height;
GValue par; /* object-set pixel aspect ratio */ GValue *par; /* object-set pixel aspect ratio */
GstClockTime time; GstClockTime time;