mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 23:06: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
|
||||
gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
||||
gst_ass_render_handle_tag_sample (GstAssRender * render, GstSample * sample)
|
||||
{
|
||||
static const gchar *mimetypes[] = {
|
||||
"application/x-font-ttf",
|
||||
|
@ -1435,51 +1435,38 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
|||
".otf",
|
||||
".ttf"
|
||||
};
|
||||
guint tag_size;
|
||||
|
||||
if (!taglist)
|
||||
return;
|
||||
|
||||
tag_size = gst_tag_list_get_tag_size (taglist, GST_TAG_ATTACHMENT);
|
||||
if (tag_size > 0 && render->embeddedfonts) {
|
||||
GstSample *sample;
|
||||
GstBuffer *buf;
|
||||
const GstStructure *structure;
|
||||
gboolean valid_mimetype, valid_extension;
|
||||
guint j;
|
||||
guint i;
|
||||
const gchar *filename;
|
||||
guint index;
|
||||
GstMapInfo map;
|
||||
|
||||
GST_DEBUG_OBJECT (render, "TAG event has attachments");
|
||||
|
||||
for (index = 0; index < tag_size; index++) {
|
||||
if (!gst_tag_list_get_sample_index (taglist, GST_TAG_ATTACHMENT, index,
|
||||
&sample))
|
||||
continue;
|
||||
buf = gst_sample_get_buffer (sample);
|
||||
structure = gst_sample_get_info (sample);
|
||||
|
||||
if (!buf || !structure)
|
||||
continue;
|
||||
return;
|
||||
|
||||
valid_mimetype = FALSE;
|
||||
valid_extension = FALSE;
|
||||
|
||||
for (j = 0; j < G_N_ELEMENTS (mimetypes); j++) {
|
||||
if (gst_structure_has_name (structure, mimetypes[j])) {
|
||||
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)
|
||||
continue;
|
||||
return;
|
||||
|
||||
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) {
|
||||
for (i = 0; i < G_N_ELEMENTS (extensions); i++) {
|
||||
if (g_ascii_strcasecmp (extension, extensions[i]) == 0) {
|
||||
valid_extension = TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -1487,6 +1474,8 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
|||
}
|
||||
|
||||
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,
|
||||
|
@ -1496,6 +1485,29 @@ gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
|||
g_mutex_unlock (&render->ass_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_ass_render_handle_tags (GstAssRender * render, GstTagList * taglist)
|
||||
{
|
||||
guint tag_size;
|
||||
|
||||
if (!taglist)
|
||||
return;
|
||||
|
||||
tag_size = gst_tag_list_get_tag_size (taglist, GST_TAG_ATTACHMENT);
|
||||
if (tag_size > 0 && render->embeddedfonts) {
|
||||
guint index;
|
||||
GstSample *sample;
|
||||
|
||||
GST_DEBUG_OBJECT (render, "TAG event has attachments");
|
||||
|
||||
for (index = 0; index < tag_size; index++) {
|
||||
if (gst_tag_list_get_sample_index (taglist, GST_TAG_ATTACHMENT, index,
|
||||
&sample)) {
|
||||
gst_ass_render_handle_tag_sample (render, sample);
|
||||
gst_sample_unref (sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue