diff options
author | Chris Bass <floobleflam@gmail.com> | 2016-12-23 11:07:00 +0000 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-03-15 13:28:36 +0200 |
commit | 4ac2a8d6a6587d4afbecdb6d3d0ed60d427a720b (patch) | |
tree | 7f360b859ca9e4ac71261ef77cf071def1445ad4 /ext/ttml | |
parent | 141f3b2f4d6dfbaf481f5c87417109b20aae0f65 (diff) | |
download | gstreamer-plugins-bad-4ac2a8d6a6587d4afbecdb6d3d0ed60d427a720b.tar.gz |
ttml: Replace assertions
Remove assertions and replace, where necessary, with code that handles
the error cases.
https://bugzilla.gnome.org/show_bug.cgi?id=776436
Diffstat (limited to 'ext/ttml')
-rw-r--r-- | ext/ttml/gstttmlrender.c | 34 | ||||
-rw-r--r-- | ext/ttml/ttmlparse.c | 38 |
2 files changed, 41 insertions, 31 deletions
diff --git a/ext/ttml/gstttmlrender.c b/ext/ttml/gstttmlrender.c index 2e3e25793..a2f08d48b 100644 --- a/ext/ttml/gstttmlrender.c +++ b/ext/ttml/gstttmlrender.c @@ -2164,11 +2164,12 @@ gst_ttml_render_render_text_region (GstTtmlRender * render, gst_ttml_render_rendered_image_free (blocks_image); } - GST_CAT_DEBUG (ttmlrender_debug, "Height of rendered region: %u", - region_image->height); - - ret = gst_ttml_render_compose_overlay (region_image); - gst_ttml_render_rendered_image_free (region_image); + if (region_image) { + GST_CAT_DEBUG (ttmlrender_debug, "Height of rendered region: %u", + region_image->height); + ret = gst_ttml_render_compose_overlay (region_image); + gst_ttml_render_rendered_image_free (region_image); + } return ret; } @@ -2324,17 +2325,18 @@ wait_for_text_buf: } subtitle_meta = gst_buffer_get_subtitle_meta (render->text_buffer); - g_assert (subtitle_meta != NULL); - - for (i = 0; i < subtitle_meta->regions->len; ++i) { - GstVideoOverlayComposition *composition; - region = g_ptr_array_index (subtitle_meta->regions, i); - g_assert (region != NULL); - composition = gst_ttml_render_render_text_region (render, region, - render->text_buffer); - if (composition) { - render->compositions = g_list_append (render->compositions, - composition); + if (!subtitle_meta) { + GST_CAT_WARNING (ttmlrender_debug, "Failed to get subtitle meta."); + } else { + for (i = 0; i < subtitle_meta->regions->len; ++i) { + GstVideoOverlayComposition *composition; + region = g_ptr_array_index (subtitle_meta->regions, i); + composition = gst_ttml_render_render_text_region (render, region, + render->text_buffer); + if (composition) { + render->compositions = g_list_append (render->compositions, + composition); + } } } render->need_render = FALSE; diff --git a/ext/ttml/ttmlparse.c b/ext/ttml/ttmlparse.c index 51bc5b623..181474ccd 100644 --- a/ext/ttml/ttmlparse.c +++ b/ext/ttml/ttmlparse.c @@ -1513,9 +1513,7 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, TtmlElement *element; GNode *node; - element = tree->data; - g_assert (element->type == TTML_ELEMENT_TYPE_REGION); - + element = tree->data; /* Region element */ region_style = gst_subtitle_style_set_new (); ttml_update_style_set (region_style, element->style_set, cellres_x, cellres_y); @@ -1525,9 +1523,7 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, if (!node) return region; - g_assert (node->next == NULL); - element = node->data; - g_assert (element->type == TTML_ELEMENT_TYPE_BODY); + element = node->data; /* Body element */ block_color = ttml_parse_colorstring (ttml_style_set_get_attr (element->style_set, "backgroundColor")); @@ -1537,7 +1533,12 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, GstSubtitleColor div_color; element = node->data; - g_assert (element->type == TTML_ELEMENT_TYPE_DIV); + if (element->type != TTML_ELEMENT_TYPE_DIV) { + GST_CAT_WARNING (ttmlparse_debug, + "Ignoring %s child of body element: only a div is allowed here.", + ttml_get_element_type_string (element)); + continue; + } div_color = ttml_parse_colorstring (ttml_style_set_get_attr (element->style_set, "backgroundColor")); @@ -1550,7 +1551,12 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, GstSubtitleColor p_color; element = p_node->data; - g_assert (element->type == TTML_ELEMENT_TYPE_P); + if (element->type != TTML_ELEMENT_TYPE_P) { + GST_CAT_WARNING (ttmlparse_debug, + "Ignoring %s child of div element: only a p is allowed here.", + ttml_get_element_type_string (element)); + continue; + } p_color = ttml_parse_colorstring (ttml_style_set_get_attr (element->style_set, "backgroundColor")); @@ -1561,7 +1567,6 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, cellres_y); block_style->background_color = block_color; block = gst_subtitle_block_new (block_style); - g_assert (block != NULL); for (content_node = p_node->children; content_node; content_node = content_node->next) { @@ -1581,19 +1586,21 @@ ttml_create_subtitle_region (GNode * tree, GstBuffer * buf, guint cellres_x, || element->type == TTML_ELEMENT_TYPE_ANON_SPAN) { ttml_add_element (block, element, buf, cellres_x, cellres_y); } else { - GST_CAT_ERROR (ttmlparse_debug, - "Element type not allowed at this level of document."); + GST_CAT_WARNING (ttmlparse_debug, + "Ignoring illegally positioned %s element.", + ttml_get_element_type_string (element)); } } } else { - GST_CAT_ERROR (ttmlparse_debug, - "Element type not allowed at this level of document."); + GST_CAT_WARNING (ttmlparse_debug, + "Ignoring illegally positioned %s element.", + ttml_get_element_type_string (element)); } } gst_subtitle_region_add_block (region, block); GST_CAT_DEBUG (ttmlparse_debug, - "Added block to region; there are now %u blocks" " in the region.", + "Added block to region; there are now %u blocks in the region.", gst_subtitle_region_get_block_count (region)); } } @@ -1628,7 +1635,8 @@ ttml_attach_scene_metadata (GList * scenes, guint cellres_x, guint cellres_y) region = ttml_create_subtitle_region (tree, scene->buf, cellres_x, cellres_y); - g_ptr_array_add (regions, region); + if (region) + g_ptr_array_add (regions, region); } gst_buffer_add_subtitle_meta (scene->buf, regions); |