summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotrek Brzeziński <thewildtree@outlook.com>2021-07-09 16:14:19 +0200
committerPiotrek Brzeziński <thewildtree@outlook.com>2021-08-14 00:10:06 +0200
commit9c03f99e58a472fae4d6ea84d69d793fec1e6a81 (patch)
tree9d533b4db84fcfcd9a8b783e7665886cd161c5b5
parent20c6668f5a7ce50eeae8b71230d0646ffdefedd9 (diff)
marker-list: Add flags (de)serialization
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/260>
-rw-r--r--ges/ges-marker-list.c44
-rw-r--r--tests/check/ges/markerlist.c5
2 files changed, 35 insertions, 14 deletions
diff --git a/ges/ges-marker-list.c b/ges/ges-marker-list.c
index d18caf25..30ed78e6 100644
--- a/ges/ges-marker-list.c
+++ b/ges/ges-marker-list.c
@@ -497,19 +497,21 @@ ges_marker_list_deserialize (GValue * dest, const gchar * s)
gboolean ret = FALSE;
GstCaps *caps = NULL;
GESMarkerList *list = ges_marker_list_new ();
- guint i, l;
- gsize len;
+ guint caps_len, i = 0;
+ gsize string_len;
gchar *escaped, *caps_str;
+ GstStructure *data_s;
+ gint flags;
- len = strlen (s);
- if (G_UNLIKELY (*s != '"' || len < 2 || s[len - 1] != '"')) {
+ string_len = strlen (s);
+ if (G_UNLIKELY (*s != '"' || string_len < 2 || s[string_len - 1] != '"')) {
/* "\"" is not an accepted string, so len must be at least 2 */
GST_ERROR ("Failed deserializing marker list: expected string to start "
"and end with '\"'");
goto done;
}
escaped = g_strdup (s + 1);
- escaped[len - 2] = '\0';
+ escaped[string_len - 2] = '\0';
/* removed trailing '"' */
caps_str = g_strcompress (escaped);
g_free (escaped);
@@ -521,19 +523,30 @@ ges_marker_list_deserialize (GValue * dest, const gchar * s)
goto done;
}
- l = gst_caps_get_size (caps);
- if (l == 0) {
+ caps_len = gst_caps_get_size (caps);
+ if (G_UNLIKELY (caps_len == 0)) {
GST_DEBUG ("Got empty caps: %s", s);
-
goto done;
}
- if (G_UNLIKELY (l % 2)) {
- GST_ERROR ("Failed deserializing marker list: expected evenly-sized caps");
- goto done;
+ data_s = gst_caps_get_structure (caps, i);
+ if (gst_structure_has_name (data_s, "marker-list-flags")) {
+ if (!gst_structure_get_int (data_s, "flags", &flags)) {
+ GST_ERROR_OBJECT (dest,
+ "Failed deserializing marker list: unexpected structure %"
+ GST_PTR_FORMAT, data_s);
+ goto done;
+ }
+
+ list->flags = flags;
+ i += 1;
+ }
+
+ if (G_UNLIKELY ((caps_len - i) % 2)) {
+ GST_ERROR ("Failed deserializing marker list: incomplete marker caps");
}
- for (i = 0; i < l - 1; i += 2) {
+ for (; i < caps_len - 1; i += 2) {
const GstStructure *pos_s = gst_caps_get_structure (caps, i);
const GstStructure *meta_s = gst_caps_get_structure (caps, i + 1);
GstClockTime position;
@@ -560,7 +573,6 @@ ges_marker_list_deserialize (GValue * dest, const gchar * s)
ges_meta_container_add_metas_from_string (GES_META_CONTAINER (marker),
metas);
g_free (metas);
-
}
ret = TRUE;
@@ -584,12 +596,16 @@ ges_marker_list_serialize (const GValue * v)
GSequenceIter *iter;
GstCaps *caps = gst_caps_new_empty ();
gchar *caps_str, *escaped, *res;
+ GstStructure *s;
+
+ s = gst_structure_new ("marker-list-flags", "flags", G_TYPE_INT,
+ list->flags, NULL);
+ gst_caps_append_structure (caps, s);
iter = g_sequence_get_begin_iter (list->markers);
while (!g_sequence_iter_is_end (iter)) {
GESMarker *marker = (GESMarker *) g_sequence_get (iter);
- GstStructure *s;
gchar *metas;
metas = ges_meta_container_metas_to_string (GES_META_CONTAINER (marker));
diff --git a/tests/check/ges/markerlist.c b/tests/check/ges/markerlist.c
index 9e79c9a0..e26dfbb0 100644
--- a/tests/check/ges/markerlist.c
+++ b/tests/check/ges/markerlist.c
@@ -354,6 +354,7 @@ GST_START_TEST (test_serialize_deserialize_in_value)
GList *markers;
guint64 position;
GValue val1 = G_VALUE_INIT, val2 = G_VALUE_INIT;
+ GESMarkerFlags flags;
ges_init ();
@@ -361,6 +362,7 @@ GST_START_TEST (test_serialize_deserialize_in_value)
g_value_init (&val2, GES_TYPE_MARKER_LIST);
markerlist1 = ges_marker_list_new ();
+ g_object_set (markerlist1, "flags", GES_MARKER_FLAG_SNAPPABLE, NULL);
marker = ges_marker_list_add (markerlist1, 0);
fail_unless (ges_meta_container_set_string (GES_META_CONTAINER (marker),
"str-val", test_string));
@@ -385,6 +387,9 @@ GST_START_TEST (test_serialize_deserialize_in_value)
markerlist2 = GES_MARKER_LIST (g_value_get_object (&val2));
ASSERT_OBJECT_REFCOUNT (markerlist2, "GValue", 1);
+ g_object_get (markerlist2, "flags", &flags, NULL);
+ fail_unless (flags == GES_MARKER_FLAG_SNAPPABLE);
+
fail_unless_equals_int (ges_marker_list_size (markerlist2), 2);
markers = ges_marker_list_get_markers (markerlist2);
marker = GES_MARKER (markers->data);