2015-02-19 07:51:20 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
*
|
|
|
|
* Copyright (C) <2015> Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2015-02-19 07:51:20 +00:00
|
|
|
|
|
|
|
#include "ges-structure-parser.h"
|
|
|
|
|
2015-02-23 16:41:59 +00:00
|
|
|
#include <ges/ges.h>
|
|
|
|
|
2015-02-19 07:51:20 +00:00
|
|
|
G_DEFINE_TYPE (GESStructureParser, ges_structure_parser, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_structure_parser_init (GESStructureParser * self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:41:59 +00:00
|
|
|
static void
|
|
|
|
_finalize (GObject * self)
|
|
|
|
{
|
2015-09-28 04:21:11 +00:00
|
|
|
GESStructureParser *parser = GES_STRUCTURE_PARSER (self);
|
2015-02-23 16:41:59 +00:00
|
|
|
|
2015-09-28 04:21:11 +00:00
|
|
|
g_list_free_full (parser->structures, (GDestroyNotify) gst_structure_free);
|
|
|
|
g_list_free_full (parser->wrong_strings, (GDestroyNotify) g_free);
|
2019-01-12 12:51:36 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (ges_structure_parser_parent_class)->finalize (self);
|
2015-02-23 16:41:59 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 07:51:20 +00:00
|
|
|
static void
|
|
|
|
ges_structure_parser_class_init (GESStructureParserClass * klass)
|
|
|
|
{
|
2015-02-23 16:41:59 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = _finalize;
|
2015-02-19 07:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ges_structure_parser_parse_string (GESStructureParser * self,
|
|
|
|
const gchar * text, gboolean is_symbol)
|
|
|
|
{
|
|
|
|
gchar *new_string = NULL;
|
|
|
|
|
|
|
|
if (self->current_string) {
|
|
|
|
new_string = g_strconcat (self->current_string, text, NULL);
|
|
|
|
} else if (is_symbol) {
|
|
|
|
new_string = g_strdup (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (self->current_string);
|
|
|
|
self->current_string = new_string;
|
|
|
|
}
|
|
|
|
|
2019-10-29 17:03:14 +00:00
|
|
|
void
|
|
|
|
ges_structure_parser_parse_value (GESStructureParser * self, const gchar * text)
|
|
|
|
{
|
|
|
|
/* text starts with '=' */
|
|
|
|
gchar *val_string = g_strconcat ("=(string)", text + 1, NULL);
|
|
|
|
ges_structure_parser_parse_string (self, val_string, FALSE);
|
|
|
|
g_free (val_string);
|
|
|
|
}
|
|
|
|
|
2015-02-19 07:51:20 +00:00
|
|
|
void
|
|
|
|
ges_structure_parser_parse_default (GESStructureParser * self,
|
|
|
|
const gchar * text)
|
|
|
|
{
|
|
|
|
gchar *new_string = NULL;
|
|
|
|
|
|
|
|
if (self->add_comma && self->current_string) {
|
|
|
|
new_string = g_strconcat (self->current_string, ",", text, NULL);
|
|
|
|
g_free (self->current_string);
|
|
|
|
self->current_string = new_string;
|
|
|
|
self->add_comma = FALSE;
|
|
|
|
} else {
|
|
|
|
ges_structure_parser_parse_string (self, text, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ges_structure_parser_parse_whitespace (GESStructureParser * self)
|
|
|
|
{
|
|
|
|
self->add_comma = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_finish_structure (GESStructureParser * self)
|
|
|
|
{
|
2021-01-12 18:55:52 +00:00
|
|
|
GstStructure *structure;
|
2015-02-19 17:28:41 +00:00
|
|
|
|
2021-01-12 18:55:52 +00:00
|
|
|
if (!self->current_string)
|
|
|
|
return;
|
2015-02-23 16:41:59 +00:00
|
|
|
|
2021-01-12 18:55:52 +00:00
|
|
|
structure = gst_structure_new_from_string (self->current_string);
|
2015-02-19 17:28:41 +00:00
|
|
|
|
2021-01-12 18:55:52 +00:00
|
|
|
if (structure == NULL) {
|
|
|
|
GST_ERROR ("Could not parse %s", self->current_string);
|
2015-02-19 17:28:41 +00:00
|
|
|
|
2021-01-12 18:55:52 +00:00
|
|
|
self->wrong_strings = g_list_append (self->wrong_strings,
|
|
|
|
g_strdup (self->current_string));
|
|
|
|
|
|
|
|
return;
|
2015-02-19 07:51:20 +00:00
|
|
|
}
|
2021-01-12 18:55:52 +00:00
|
|
|
|
|
|
|
self->structures = g_list_append (self->structures, structure);
|
|
|
|
g_free (self->current_string);
|
|
|
|
self->current_string = NULL;
|
2015-02-19 07:51:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 18:55:52 +00:00
|
|
|
|
2015-02-19 07:51:20 +00:00
|
|
|
void
|
|
|
|
ges_structure_parser_end_of_file (GESStructureParser * self)
|
|
|
|
{
|
|
|
|
_finish_structure (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ges_structure_parser_parse_symbol (GESStructureParser * self,
|
|
|
|
const gchar * symbol)
|
|
|
|
{
|
|
|
|
_finish_structure (self);
|
|
|
|
|
2015-03-13 12:02:30 +00:00
|
|
|
while (*symbol == ' ' || *symbol == '+')
|
2015-02-19 07:51:20 +00:00
|
|
|
symbol++;
|
2015-02-25 17:01:38 +00:00
|
|
|
|
|
|
|
self->add_comma = FALSE;
|
|
|
|
if (!g_ascii_strncasecmp (symbol, "clip", 4))
|
2019-10-29 17:03:14 +00:00
|
|
|
ges_structure_parser_parse_string (self, "clip, uri=(string)", TRUE);
|
2015-04-03 15:38:53 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "test-clip", 9))
|
2019-10-29 17:03:14 +00:00
|
|
|
ges_structure_parser_parse_string (self, "test-clip, pattern=(string)",
|
|
|
|
TRUE);
|
2015-02-25 17:01:38 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "effect", 6))
|
2019-10-29 17:03:14 +00:00
|
|
|
ges_structure_parser_parse_string (self, "effect, bin-description=(string)",
|
|
|
|
TRUE);
|
2015-02-25 17:01:38 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "transition", 10))
|
2019-10-29 17:03:14 +00:00
|
|
|
ges_structure_parser_parse_string (self, "transition, type=(string)", TRUE);
|
2018-03-30 21:17:13 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "title", 5))
|
|
|
|
ges_structure_parser_parse_string (self, "title, text=(string)", TRUE);
|
2021-01-12 18:55:52 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "track", 5))
|
|
|
|
ges_structure_parser_parse_string (self, "track, type=(string)", TRUE);
|
2021-01-15 12:27:31 +00:00
|
|
|
else if (!g_ascii_strncasecmp (symbol, "keyframes", 8)) {
|
|
|
|
ges_structure_parser_parse_string (self,
|
|
|
|
"keyframes, property-name=(string)", TRUE);
|
|
|
|
}
|
2015-02-19 07:51:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 12:15:25 +00:00
|
|
|
void
|
|
|
|
ges_structure_parser_parse_setter (GESStructureParser * self,
|
|
|
|
const gchar * setter)
|
|
|
|
{
|
|
|
|
gchar *parsed_setter;
|
|
|
|
|
2015-02-19 18:16:44 +00:00
|
|
|
_finish_structure (self);
|
|
|
|
|
2015-02-19 12:15:25 +00:00
|
|
|
while (*setter == '-' || *setter == ' ')
|
|
|
|
setter++;
|
|
|
|
|
|
|
|
while (*setter != '-')
|
|
|
|
setter++;
|
|
|
|
|
|
|
|
setter++;
|
|
|
|
|
2019-10-29 17:03:14 +00:00
|
|
|
parsed_setter = g_strdup_printf ("set-property, property=(string)%s, "
|
|
|
|
"value=(string)", setter);
|
2015-02-19 12:15:25 +00:00
|
|
|
self->add_comma = FALSE;
|
|
|
|
ges_structure_parser_parse_string (self, parsed_setter, TRUE);
|
|
|
|
g_free (parsed_setter);
|
|
|
|
}
|
|
|
|
|
2015-02-19 07:51:20 +00:00
|
|
|
GESStructureParser *
|
|
|
|
ges_structure_parser_new (void)
|
|
|
|
{
|
|
|
|
return (g_object_new (GES_TYPE_STRUCTURE_PARSER, NULL));
|
|
|
|
}
|
2015-02-23 16:41:59 +00:00
|
|
|
|
|
|
|
GError *
|
|
|
|
ges_structure_parser_get_error (GESStructureParser * self)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GError *error = NULL;
|
|
|
|
GString *msg = NULL;
|
|
|
|
|
|
|
|
if (self->wrong_strings == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
msg = g_string_new ("Could not parse: ");
|
|
|
|
|
|
|
|
|
|
|
|
for (tmp = self->wrong_strings; tmp; tmp = tmp->next) {
|
|
|
|
g_string_append_printf (msg, " %s", (gchar *) tmp->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = g_error_new_literal (GES_ERROR, 0, msg->str);
|
|
|
|
g_string_free (msg, TRUE);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|