basetextoverlay: Correctly handle empty text buffers
This commit is contained in:
parent
dc2f2c9a40
commit
c4fb8d1e69
@ -2210,40 +2210,45 @@ wait_for_text_buf:
|
|||||||
in_text = (gchar *) map.data;
|
in_text = (gchar *) map.data;
|
||||||
in_size = map.size;
|
in_size = map.size;
|
||||||
|
|
||||||
/* g_markup_escape_text() absolutely requires valid UTF8 input, it
|
if (in_size > 0) {
|
||||||
* might crash otherwise. We don't fall back on GST_SUBTITLE_ENCODING
|
/* g_markup_escape_text() absolutely requires valid UTF8 input, it
|
||||||
* here on purpose, this is something that needs fixing upstream */
|
* might crash otherwise. We don't fall back on GST_SUBTITLE_ENCODING
|
||||||
if (!g_utf8_validate (in_text, in_size, NULL)) {
|
* here on purpose, this is something that needs fixing upstream */
|
||||||
const gchar *end = NULL;
|
if (!g_utf8_validate (in_text, in_size, NULL)) {
|
||||||
|
const gchar *end = NULL;
|
||||||
|
|
||||||
GST_WARNING_OBJECT (overlay, "received invalid UTF-8");
|
GST_WARNING_OBJECT (overlay, "received invalid UTF-8");
|
||||||
in_text = g_strndup (in_text, in_size);
|
in_text = g_strndup (in_text, in_size);
|
||||||
while (!g_utf8_validate (in_text, in_size, &end) && end)
|
while (!g_utf8_validate (in_text, in_size, &end) && end)
|
||||||
*((gchar *) end) = '*';
|
*((gchar *) end) = '*';
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the string */
|
|
||||||
if (overlay->have_pango_markup) {
|
|
||||||
text = g_strndup (in_text, in_size);
|
|
||||||
} else {
|
|
||||||
text = g_markup_escape_text (in_text, in_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text != NULL && *text != '\0') {
|
|
||||||
gint text_len = strlen (text);
|
|
||||||
|
|
||||||
while (text_len > 0 && (text[text_len - 1] == '\n' ||
|
|
||||||
text[text_len - 1] == '\r')) {
|
|
||||||
--text_len;
|
|
||||||
}
|
}
|
||||||
GST_DEBUG_OBJECT (overlay, "Rendering text '%*s'", text_len, text);
|
|
||||||
gst_base_text_overlay_render_text (overlay, text, text_len);
|
/* Get the string */
|
||||||
|
if (overlay->have_pango_markup) {
|
||||||
|
text = g_strndup (in_text, in_size);
|
||||||
|
} else {
|
||||||
|
text = g_markup_escape_text (in_text, in_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text != NULL && *text != '\0') {
|
||||||
|
gint text_len = strlen (text);
|
||||||
|
|
||||||
|
while (text_len > 0 && (text[text_len - 1] == '\n' ||
|
||||||
|
text[text_len - 1] == '\r')) {
|
||||||
|
--text_len;
|
||||||
|
}
|
||||||
|
GST_DEBUG_OBJECT (overlay, "Rendering text '%*s'", text_len, text);
|
||||||
|
gst_base_text_overlay_render_text (overlay, text, text_len);
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (overlay, "No text to render (empty buffer)");
|
||||||
|
gst_base_text_overlay_render_text (overlay, " ", 1);
|
||||||
|
}
|
||||||
|
if (in_text != (gchar *) map.data)
|
||||||
|
g_free (in_text);
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (overlay, "No text to render (empty buffer)");
|
GST_DEBUG_OBJECT (overlay, "No text to render (empty buffer)");
|
||||||
gst_base_text_overlay_render_text (overlay, " ", 1);
|
gst_base_text_overlay_render_text (overlay, " ", 1);
|
||||||
}
|
}
|
||||||
if (in_text != (gchar *) map.data)
|
|
||||||
g_free (in_text);
|
|
||||||
|
|
||||||
gst_buffer_unmap (overlay->text_buffer, &map);
|
gst_buffer_unmap (overlay->text_buffer, &map);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user