ttml: add refcounting to GstSubtitleStlyeSet type

https://bugzilla.gnome.org/show_bug.cgi?id=780402
This commit is contained in:
Chris Bass 2017-03-21 13:50:12 +00:00 committed by Sebastian Dröge
parent 4f790d13a6
commit 9f0a06245b
3 changed files with 62 additions and 22 deletions

View file

@ -1242,7 +1242,7 @@ map_fail:
typedef struct
{
const GstSubtitleElement *element;
GstSubtitleElement *element;
gchar *text;
} UnifiedElement;

View file

@ -32,6 +32,22 @@
#include "subtitle.h"
/**
* gst_subtitle_style_set_free:
* @style_set: A #GstSubtitleStyleSet.
*
* Free @style_set and its associated memory.
*/
static void
_gst_subtitle_style_set_free (GstSubtitleStyleSet * style_set)
{
g_return_if_fail (style_set != NULL);
g_free (style_set->font_family);
g_slice_free (GstSubtitleStyleSet, style_set);
}
GST_DEFINE_MINI_OBJECT_TYPE (GstSubtitleStyleSet, gst_subtitle_style_set);
/**
* gst_subtitle_style_set_new:
*
@ -46,6 +62,10 @@ gst_subtitle_style_set_new (void)
GstSubtitleColor white = { 255, 255, 255, 255 };
GstSubtitleColor transparent = { 0, 0, 0, 0 };
gst_mini_object_init (GST_MINI_OBJECT_CAST (ret), 0,
gst_subtitle_style_set_get_type (), NULL, NULL,
(GstMiniObjectFreeFunction) _gst_subtitle_style_set_free);
ret->font_family = g_strdup ("default");
ret->font_size = 1.0;
ret->line_height = 1.25;
@ -60,26 +80,12 @@ gst_subtitle_style_set_new (void)
return ret;
}
/**
* gst_subtitle_style_set_free:
* @style_set: A #GstSubtitleStyleSet.
*
* Free @style_set and its associated memory.
*/
void
gst_subtitle_style_set_free (GstSubtitleStyleSet * style_set)
{
g_return_if_fail (style_set != NULL);
g_free (style_set->font_family);
g_slice_free (GstSubtitleStyleSet, style_set);
}
static void
_gst_subtitle_element_free (GstSubtitleElement * element)
{
g_return_if_fail (element != NULL);
gst_subtitle_style_set_free (element->style_set);
gst_subtitle_style_set_unref (element->style_set);
g_slice_free (GstSubtitleElement, element);
}
@ -121,7 +127,7 @@ static void
_gst_subtitle_block_free (GstSubtitleBlock * block)
{
g_return_if_fail (block != NULL);
gst_subtitle_style_set_free (block->style_set);
gst_subtitle_style_set_unref (block->style_set);
g_ptr_array_unref (block->elements);
g_slice_free (GstSubtitleBlock, block);
}
@ -202,7 +208,7 @@ gst_subtitle_block_get_element_count (const GstSubtitleBlock * block)
* function does not return a reference; the caller should obtain a reference
* using gst_subtitle_element_ref(), if needed.
*/
const GstSubtitleElement *
GstSubtitleElement *
gst_subtitle_block_get_element (const GstSubtitleBlock * block, guint index)
{
g_return_val_if_fail (block != NULL, NULL);
@ -217,7 +223,7 @@ static void
_gst_subtitle_region_free (GstSubtitleRegion * region)
{
g_return_if_fail (region != NULL);
gst_subtitle_style_set_free (region->style_set);
gst_subtitle_style_set_unref (region->style_set);
g_ptr_array_unref (region->blocks);
g_slice_free (GstSubtitleRegion, region);
}

View file

@ -366,7 +366,10 @@ typedef enum {
* all object types. The types to which each attribute applies is given in the
* description of that attribute below.
*/
struct _GstSubtitleStyleSet {
struct _GstSubtitleStyleSet
{
GstMiniObject mini_object;
GstSubtitleTextDirection text_direction;
gchar *font_family;
gdouble font_size;
@ -388,11 +391,42 @@ struct _GstSubtitleStyleSet {
GstSubtitleWritingMode writing_mode;
GstSubtitleBackgroundMode show_background;
GstSubtitleOverflowMode overflow;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GType gst_subtitle_style_set_get_type (void);
GstSubtitleStyleSet * gst_subtitle_style_set_new (void);
void gst_subtitle_style_set_free (GstSubtitleStyleSet * style_set);
/**
* gst_subtitle_style_set_ref:
* @style_set: A #GstSubtitleStyleSet.
*
* Increments the refcount of @style_set.
*
* Returns: (transfer full): @style_set.
*/
static inline GstSubtitleStyleSet *
gst_subtitle_style_set_ref (GstSubtitleStyleSet * style_set)
{
return (GstSubtitleStyleSet *)
gst_mini_object_ref (GST_MINI_OBJECT_CAST (style_set));
}
/**
* gst_subtitle_style_set_unref:
* @style_set: (transfer full): A #GstSubtitleStyleSet.
*
* Decrements the refcount of @style_set. If the refcount reaches 0, @style_set
* will be freed.
*/
static inline void
gst_subtitle_style_set_unref (GstSubtitleStyleSet * style_set)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (style_set));
}
/**
@ -489,7 +523,7 @@ void gst_subtitle_block_add_element (
guint gst_subtitle_block_get_element_count (const GstSubtitleBlock * block);
const GstSubtitleElement * gst_subtitle_block_get_element (
GstSubtitleElement * gst_subtitle_block_get_element (
const GstSubtitleBlock * block, guint index);
/**