From 594dd26817732b7e1a71cbdab6ab2fd94c3b04ad Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Sat, 11 Jul 2015 00:02:09 +0100 Subject: [PATCH] WIP pango: init PangoFontMap and PangoContext when going to READY state videosink on osx may use NSFont to set title on their window: initWithContentRect:rect styleMask: NSTitledWindowMask This function will crash when using the custom NSApp loop in glimagesink and osxvideosink: [__NSCFType symbolicTraits]: unrecognized selector [__NSFontTypefaceInfo _postscriptName] https://bugzilla.gnome.org/show_bug.cgi?id=752147 --- ext/pango/gstbasetextoverlay.c | 66 ++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/ext/pango/gstbasetextoverlay.c b/ext/pango/gstbasetextoverlay.c index b1b3b93..350ceff 100644 --- a/ext/pango/gstbasetextoverlay.c +++ b/ext/pango/gstbasetextoverlay.c @@ -304,19 +304,6 @@ gst_base_text_overlay_get_text (GstBaseTextOverlay * overlay, static void gst_base_text_overlay_base_init (gpointer g_class) { - GstBaseTextOverlayClass *klass = GST_BASE_TEXT_OVERLAY_CLASS (g_class); - PangoFontMap *fontmap; - - /* Only lock for the subclasses here, the base class - * doesn't have this mutex yet and it's not necessary - * here */ - if (klass->pango_lock) - g_mutex_lock (klass->pango_lock); - fontmap = pango_cairo_font_map_get_default (); - klass->pango_context = - pango_font_map_create_context (PANGO_FONT_MAP (fontmap)); - if (klass->pango_lock) - g_mutex_unlock (klass->pango_lock); } static void @@ -546,7 +533,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, GstBaseTextOverlayClass * klass) { GstPadTemplate *template; - PangoFontDescription *desc; /* video sink */ template = gst_static_pad_template_get (&video_sink_template_factory); @@ -591,13 +577,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, g_mutex_lock (GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock); overlay->line_align = DEFAULT_PROP_LINE_ALIGNMENT; - overlay->layout = - pango_layout_new (GST_BASE_TEXT_OVERLAY_GET_CLASS - (overlay)->pango_context); - desc = - pango_context_get_font_description (GST_BASE_TEXT_OVERLAY_GET_CLASS - (overlay)->pango_context); - gst_base_text_overlay_adjust_values_with_fontdesc (overlay, desc); overlay->color = DEFAULT_PROP_COLOR; overlay->outline_color = DEFAULT_PROP_OUTLINE_COLOR; @@ -624,7 +603,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, overlay->need_render = TRUE; overlay->text_image = NULL; overlay->use_vertical_render = DEFAULT_PROP_VERTICAL_RENDER; - gst_base_text_overlay_update_render_mode (overlay); overlay->text_buffer = NULL; overlay->text_linked = FALSE; @@ -636,6 +614,37 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, } static void +gst_base_text_overlay_setup_pango (GstBaseTextOverlay * overlay) +{ + static gsize val = 0; + PangoFontDescription *desc = NULL; + + if (g_once_init_enter (&val)) { + gsize setup_value = 1; + PangoFontMap *fontmap = pango_cairo_font_map_get_default (); + + GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_context = + pango_font_map_create_context (PANGO_FONT_MAP (fontmap)); + + g_once_init_leave (&val, setup_value); + } + + g_mutex_lock (GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock); + + overlay->layout = + pango_layout_new (GST_BASE_TEXT_OVERLAY_GET_CLASS + (overlay)->pango_context); + desc = + pango_context_get_font_description (GST_BASE_TEXT_OVERLAY_GET_CLASS + (overlay)->pango_context); + gst_base_text_overlay_adjust_values_with_fontdesc (overlay, desc); + gst_base_text_overlay_update_render_mode (overlay); + + g_mutex_unlock (GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock); +} + + +static void gst_base_text_overlay_update_wrap_mode (GstBaseTextOverlay * overlay) { if (overlay->wrap_mode == GST_BASE_TEXT_OVERLAY_WRAP_MODE_NONE) { @@ -916,7 +925,10 @@ gst_base_text_overlay_set_property (GObject * object, guint prop_id, fontdesc_str = g_value_get_string (value); g_mutex_lock (GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock); - desc = pango_font_description_from_string (fontdesc_str); + // TODO: if not in ready state then cache fontdesc_str and set it + // after creating overlay->layout + // desc = pango_font_description_from_string (fontdesc_str); + desc = NULL; if (desc) { GST_LOG_OBJECT (overlay, "font description set: %s", fontdesc_str); pango_layout_set_font_description (overlay->layout, desc); @@ -1050,10 +1062,11 @@ gst_base_text_overlay_get_property (GObject * object, guint prop_id, break; case PROP_FONT_DESC: { - const PangoFontDescription *desc; + const PangoFontDescription *desc = NULL; g_mutex_lock (GST_BASE_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock); - desc = pango_layout_get_font_description (overlay->layout); + if (overlay->layout) + desc = pango_layout_get_font_description (overlay->layout); if (!desc) g_value_set_string (value, ""); else { @@ -2626,6 +2639,9 @@ gst_base_text_overlay_change_state (GstElement * element, return ret; switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + gst_base_text_overlay_setup_pango (overlay); + break; case GST_STATE_CHANGE_READY_TO_PAUSED: GST_BASE_TEXT_OVERLAY_LOCK (overlay); overlay->text_flushing = FALSE; -- 2.3.2 (Apple Git-55)