mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
assrender: fix leak of tag samples in the tag list
Move handling of a GstSample in a separate function, and unref the sample after calling it. libass copies the font data so we don't need to keep it around. https://bugzilla.gnome.org/show_bug.cgi?id=755759
This commit is contained in:
parent
c6ce769a18
commit
5d0db38df3
1 changed files with 60 additions and 48 deletions
|
@ -1424,7 +1424,7 @@ beach:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
gst_ass_render_handle_tag_sample (GstAssRender * render, GstSample * sample)
|
||||||
{
|
{
|
||||||
static const gchar *mimetypes[] = {
|
static const gchar *mimetypes[] = {
|
||||||
"application/x-font-ttf",
|
"application/x-font-ttf",
|
||||||
|
@ -1435,6 +1435,60 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
||||||
".otf",
|
".otf",
|
||||||
".ttf"
|
".ttf"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GstBuffer *buf;
|
||||||
|
const GstStructure *structure;
|
||||||
|
gboolean valid_mimetype, valid_extension;
|
||||||
|
guint i;
|
||||||
|
const gchar *filename;
|
||||||
|
|
||||||
|
buf = gst_sample_get_buffer (sample);
|
||||||
|
structure = gst_sample_get_info (sample);
|
||||||
|
|
||||||
|
if (!buf || !structure)
|
||||||
|
return;
|
||||||
|
|
||||||
|
valid_mimetype = FALSE;
|
||||||
|
valid_extension = FALSE;
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (mimetypes); i++) {
|
||||||
|
if (gst_structure_has_name (structure, mimetypes[i])) {
|
||||||
|
valid_mimetype = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filename = gst_structure_get_string (structure, "filename");
|
||||||
|
if (!filename)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!valid_mimetype) {
|
||||||
|
guint len = strlen (filename);
|
||||||
|
const gchar *extension = filename + len - 4;
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (extensions); i++) {
|
||||||
|
if (g_ascii_strcasecmp (extension, extensions[i]) == 0) {
|
||||||
|
valid_extension = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid_mimetype || valid_extension) {
|
||||||
|
GstMapInfo map;
|
||||||
|
|
||||||
|
g_mutex_lock (&render->ass_mutex);
|
||||||
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
||||||
|
ass_add_font (render->ass_library, (gchar *) filename,
|
||||||
|
(gchar *) map.data, map.size);
|
||||||
|
gst_buffer_unmap (buf, &map);
|
||||||
|
GST_DEBUG_OBJECT (render, "registered new font %s", filename);
|
||||||
|
g_mutex_unlock (&render->ass_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
||||||
|
{
|
||||||
guint tag_size;
|
guint tag_size;
|
||||||
|
|
||||||
if (!taglist)
|
if (!taglist)
|
||||||
|
@ -1442,58 +1496,16 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
||||||
|
|
||||||
tag_size = gst_tag_list_get_tag_size (taglist, GST_TAG_ATTACHMENT);
|
tag_size = gst_tag_list_get_tag_size (taglist, GST_TAG_ATTACHMENT);
|
||||||
if (tag_size > 0 && render->embeddedfonts) {
|
if (tag_size > 0 && render->embeddedfonts) {
|
||||||
GstSample *sample;
|
|
||||||
GstBuffer *buf;
|
|
||||||
const GstStructure *structure;
|
|
||||||
gboolean valid_mimetype, valid_extension;
|
|
||||||
guint j;
|
|
||||||
const gchar *filename;
|
|
||||||
guint index;
|
guint index;
|
||||||
GstMapInfo map;
|
GstSample *sample;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (render, "TAG event has attachments");
|
GST_DEBUG_OBJECT (render, "TAG event has attachments");
|
||||||
|
|
||||||
for (index = 0; index < tag_size; index++) {
|
for (index = 0; index < tag_size; index++) {
|
||||||
if (!gst_tag_list_get_sample_index (taglist, GST_TAG_ATTACHMENT, index,
|
if (gst_tag_list_get_sample_index (taglist, GST_TAG_ATTACHMENT, index,
|
||||||
&sample))
|
&sample)) {
|
||||||
continue;
|
gst_ass_render_handle_tag_sample (render, sample);
|
||||||
buf = gst_sample_get_buffer (sample);
|
gst_sample_unref (sample);
|
||||||
structure = gst_sample_get_info (sample);
|
|
||||||
if (!buf || !structure)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
valid_mimetype = FALSE;
|
|
||||||
valid_extension = FALSE;
|
|
||||||
|
|
||||||
for (j = 0; j < G_N_ELEMENTS (mimetypes); j++) {
|
|
||||||
if (gst_structure_has_name (structure, mimetypes[j])) {
|
|
||||||
valid_mimetype = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filename = gst_structure_get_string (structure, "filename");
|
|
||||||
if (!filename)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!valid_mimetype) {
|
|
||||||
guint len = strlen (filename);
|
|
||||||
const gchar *extension = filename + len - 4;
|
|
||||||
for (j = 0; j < G_N_ELEMENTS (extensions); j++) {
|
|
||||||
if (g_ascii_strcasecmp (extension, extensions[j]) == 0) {
|
|
||||||
valid_extension = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid_mimetype || valid_extension) {
|
|
||||||
g_mutex_lock (&render->ass_mutex);
|
|
||||||
gst_buffer_map (buf, &map, GST_MAP_READ);
|
|
||||||
ass_add_font (render->ass_library, (gchar *) filename,
|
|
||||||
(gchar *) map.data, map.size);
|
|
||||||
gst_buffer_unmap (buf, &map);
|
|
||||||
GST_DEBUG_OBJECT (render, "registered new font %s", filename);
|
|
||||||
g_mutex_unlock (&render->ass_mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue