mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-10 03:19:40 +00:00
validate:media-descriptor-parser: Add a way to create from a string
So it is simple to make use of it from the testsuite https://bugzilla.gnome.org/show_bug.cgi?id=736138
This commit is contained in:
parent
f793d06783
commit
cd9a3640b2
2 changed files with 47 additions and 8 deletions
|
@ -263,26 +263,42 @@ static const GMarkupParser content_parser = {
|
|||
&on_error_cb
|
||||
};
|
||||
|
||||
static gboolean
|
||||
_set_content (GstMediaDescriptorParser * parser,
|
||||
const gchar * content, gsize size, GError ** error)
|
||||
{
|
||||
GError *err = NULL;
|
||||
GstMediaDescriptorParserPrivate *priv = parser->priv;
|
||||
|
||||
priv->parsecontext = g_markup_parse_context_new (&content_parser,
|
||||
G_MARKUP_TREAT_CDATA_AS_TEXT, parser, NULL);
|
||||
|
||||
if (g_markup_parse_context_parse (priv->parsecontext, content,
|
||||
size, &err) == FALSE)
|
||||
goto failed;
|
||||
|
||||
return TRUE;
|
||||
|
||||
failed:
|
||||
g_propagate_error (error, err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_xml_path (GstMediaDescriptorParser * parser, const gchar * path,
|
||||
GError ** error)
|
||||
{
|
||||
gsize xmlsize;
|
||||
gchar *content;
|
||||
GError *err = NULL;
|
||||
GstMediaDescriptorParserPrivate *priv = parser->priv;
|
||||
|
||||
if (!g_file_get_contents (path, &priv->xmlcontent, &xmlsize, &err))
|
||||
if (!g_file_get_contents (path, &content, &xmlsize, &err))
|
||||
goto failed;
|
||||
|
||||
priv->xmlpath = g_strdup (path);
|
||||
priv->parsecontext = g_markup_parse_context_new (&content_parser,
|
||||
G_MARKUP_TREAT_CDATA_AS_TEXT, parser, NULL);
|
||||
|
||||
if (g_markup_parse_context_parse (priv->parsecontext, priv->xmlcontent,
|
||||
xmlsize, &err) == FALSE)
|
||||
goto failed;
|
||||
|
||||
return TRUE;
|
||||
return _set_content (parser, content, xmlsize, error);
|
||||
|
||||
failed:
|
||||
g_propagate_error (error, err);
|
||||
|
@ -381,6 +397,25 @@ gst_media_descriptor_parser_new (GstValidateRunner * runner,
|
|||
return parser;
|
||||
}
|
||||
|
||||
GstMediaDescriptorParser *
|
||||
gst_media_descriptor_parser_new_from_xml (GstValidateRunner * runner,
|
||||
const gchar * xml, GError ** error)
|
||||
{
|
||||
GstMediaDescriptorParser *parser;
|
||||
|
||||
parser = g_object_new (GST_TYPE_MEDIA_DESCRIPTOR_PARSER, "validate-runner",
|
||||
runner, NULL);
|
||||
if (_set_content (parser, g_strdup (xml), strlen (xml) * sizeof (gchar),
|
||||
error) == FALSE) {
|
||||
g_object_unref (parser);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
gchar *
|
||||
gst_media_descriptor_parser_get_xml_path (GstMediaDescriptorParser * parser)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,10 @@ typedef struct {
|
|||
GstMediaDescriptorParser * gst_media_descriptor_parser_new (GstValidateRunner *runner,
|
||||
const gchar * xmlpath,
|
||||
GError **error);
|
||||
GstMediaDescriptorParser *
|
||||
gst_media_descriptor_parser_new_from_xml (GstValidateRunner * runner,
|
||||
const gchar * xml,
|
||||
GError ** error);
|
||||
gchar * gst_media_descriptor_parser_get_xml_path (GstMediaDescriptorParser *parser);
|
||||
gboolean gst_media_descriptor_parser_add_stream (GstMediaDescriptorParser *parser,
|
||||
GstPad *pad);
|
||||
|
|
Loading…
Reference in a new issue