Commit 68288a76 authored by Millan Castro Vilariño's avatar Millan Castro Vilariño Committed by Mathieu Duponchelle

markerlist: implement GESMarkerList

Co-authored by Mathieu Duponchelle <mathieu@centricular.com>
parent 19426863
Pipeline #58155 failed with stages
in 88 minutes and 57 seconds
......@@ -78,6 +78,7 @@ libges_@GST_API_VERSION@_la_SOURCES = \
ges-validate.c \
ges-structured-interface.c \
ges-structure-parser.c \
ges-marker-list.c \
gstframepositioner.c
libges_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/ges/
......@@ -142,6 +143,7 @@ libges_@GST_API_VERSION@include_HEADERS = \
ges-effect-asset.h \
ges-utils.h \
ges-group.h \
ges-marker-list.h \
ges-version.h
noinst_HEADERS = \
......
......@@ -450,6 +450,14 @@ G_GNUC_INTERNAL GESMultiFileURI * ges_multi_file_uri_new (const gchar * uri);
************************/
#define GES_PARAM_NO_SERIALIZATION (1 << (G_PARAM_USER_SHIFT + 1))
/*******************************
* GESMarkerList serialization *
*******************************/
G_GNUC_INTERNAL gchar * ges_marker_list_serialize (const GValue * v);
G_GNUC_INTERNAL gboolean ges_marker_list_deserialize (GValue *dest, const gchar *s);
/********************
* Gnonlin helpers *
********************/
......
This diff is collapsed.
/* GStreamer Editing Services
* Copyright (C) <2019> Mathieu Duponchelle <mathieu@centricular.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _GES_MARKER_LIST
#define _GES_MARKER_LIST
#include <glib-object.h>
#include <ges/ges-types.h>
G_BEGIN_DECLS
#define GES_TYPE_MARKER ges_marker_get_type ()
GES_API
G_DECLARE_FINAL_TYPE (GESMarker, ges_marker, GES, MARKER, GObject)
#define GES_TYPE_MARKER_LIST ges_marker_list_get_type ()
GES_API
G_DECLARE_FINAL_TYPE (GESMarkerList, ges_marker_list, GES, MARKER_LIST, GObject)
GES_API
GESMarkerList * ges_marker_list_new (void);
GES_API
GESMarker * ges_marker_list_add (GESMarkerList * list, GstClockTime position);
GES_API
gboolean ges_marker_list_remove (GESMarkerList * list, GESMarker *marker);
GES_API
guint ges_marker_list_size (GESMarkerList * list);
GES_API
GList *ges_marker_list_get_markers (GESMarkerList *list);
GES_API
gboolean ges_marker_list_move (GESMarkerList *list, GESMarker *marker, GstClockTime position);
G_END_DECLS
#endif /* _GES_MARKER_LIST */
......@@ -25,6 +25,7 @@
#include <gst/gst.h>
#include "ges-meta-container.h"
#include "ges-marker-list.h"
/**
* SECTION: gesmetacontainer
......@@ -37,8 +38,7 @@ static GQuark ges_meta_key;
G_DEFINE_INTERFACE_WITH_CODE (GESMetaContainer, ges_meta_container,
G_TYPE_OBJECT, ges_meta_key =
g_quark_from_static_string ("ges-meta-container-data");
);
g_quark_from_static_string ("ges-meta-container-data"););
enum
{
......@@ -434,6 +434,49 @@ ges_meta_container_set_meta (GESMetaContainer * container,
return _set_value (container, meta_item, value);
}
/**
* ges_meta_container_set_marker_list:
* @container: Target container
* @meta_item: Name of the meta item to set
* @list: (allow-none) (transfer none): List to set
*
* Associates a marker list with the given meta item
*
* Return: %TRUE if the meta could be added, %FALSE otherwise
* Since: 1.18
*/
gboolean
ges_meta_container_set_marker_list (GESMetaContainer * container,
const gchar * meta_item, const GESMarkerList * list)
{
gboolean ret;
GValue v = G_VALUE_INIT;
g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
g_return_val_if_fail (meta_item != NULL, FALSE);
if (list == NULL) {
GstStructure *structure = _meta_container_get_structure (container);
gst_structure_remove_field (structure, meta_item);
g_signal_emit (container, _signals[NOTIFY_SIGNAL], 0, meta_item, list);
return TRUE;
}
g_return_val_if_fail (GES_IS_MARKER_LIST ((gpointer) list), FALSE);
if (_can_write_value (container, meta_item, GES_TYPE_MARKER_LIST) == FALSE)
return FALSE;
g_value_init_from_instance (&v, (gpointer) list);
ret = _set_value (container, meta_item, &v);
g_value_unset (&v);
return ret;
}
/**
* ges_meta_container_metas_to_string:
* @container: a #GESMetaContainer
......@@ -914,6 +957,38 @@ ges_meta_container_get_meta (GESMetaContainer * container, const gchar * key)
return gst_structure_get_value (structure, key);
}
/**
* ges_meta_container_get_marker_list:
* @container: Target container
* @key: The key name of the list to retrieve
*
* Gets the value of a given meta item, returns NULL if @key
* can not be found.
*
* Returns: (transfer full): the #GESMarkerList corresponding to the meta with the given @key.
* Since: 1.18
*/
GESMarkerList *
ges_meta_container_get_marker_list (GESMetaContainer * container,
const gchar * key)
{
GstStructure *structure;
const GValue *v;
g_return_val_if_fail (GES_IS_META_CONTAINER (container), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
structure = _meta_container_get_structure (container);
v = gst_structure_get_value (structure, key);
if (v == NULL) {
return NULL;
}
return GES_MARKER_LIST (g_value_dup_object (v));
}
/**
* ges_meta_container_get_date:
* @container: Target container
......
......@@ -176,6 +176,11 @@ ges_meta_container_set_meta (GESMetaContainer * container,
const gchar* meta_item,
const GValue *value);
GES_API gboolean
ges_meta_container_set_marker_list (GESMetaContainer * container,
const gchar * meta_item,
const GESMarkerList *list);
GES_API gboolean
ges_meta_container_register_meta_boolean (GESMetaContainer *container,
GESMetaFlag flags,
......@@ -297,6 +302,10 @@ GES_API const gchar *
ges_meta_container_get_string (GESMetaContainer * container,
const gchar * meta_item);
GES_API GESMarkerList *
ges_meta_container_get_marker_list (GESMetaContainer * container,
const gchar * key);
GES_API const GValue *
ges_meta_container_get_meta (GESMetaContainer * container,
const gchar * key);
......
......@@ -188,6 +188,10 @@ typedef struct _GESVideoTrack GESVideoTrack;
typedef struct _GESAudioTrackClass GESAudioTrackClass;
typedef struct _GESAudioTrack GESAudioTrack;
typedef struct _GESMarkerList GESMarkerList;
typedef struct _GESMarker GESMarker;
G_END_DECLS
#endif /* __GES_TYPES_H__ */
......@@ -75,6 +75,13 @@ ges_init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
{
GESUriClipAssetClass *uriasset_klass = NULL;
GstElementFactory *nlecomposition_factory = NULL;
static GstValueTable gstvtable = {
G_TYPE_NONE,
(GstValueCompareFunc) NULL,
(GstValueSerializeFunc) ges_marker_list_serialize,
(GstValueDeserializeFunc) ges_marker_list_deserialize
};
static gboolean marker_list_registered = FALSE;
if (initialized_thread) {
GST_DEBUG ("already initialized ges");
......@@ -123,6 +130,12 @@ ges_init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
initialized_thread = g_thread_self ();
g_type_class_unref (uriasset_klass);
if (!marker_list_registered) {
gstvtable.type = GES_TYPE_MARKER_LIST;
gst_value_register (&gstvtable);
marker_list_registered = TRUE;
}
GST_DEBUG ("GStreamer Editing Services initialized");
return TRUE;
......
......@@ -83,6 +83,7 @@
#include <ges/ges-audio-track.h>
#include <ges/ges-video-track.h>
#include <ges/ges-version.h>
#include <ges/ges-marker-list.h>
G_BEGIN_DECLS
......
......@@ -61,6 +61,7 @@ ges_sources = files([
'ges-validate.c',
'ges-structured-interface.c',
'ges-structure-parser.c',
'ges-marker-list.c',
'gstframepositioner.c'
])
......@@ -122,7 +123,8 @@ ges_headers = files([
'ges-container.h',
'ges-effect-asset.h',
'ges-utils.h',
'ges-group.h'
'ges-group.h',
'ges-marker-list.h'
])
if libxml_dep.found()
......
......@@ -1462,6 +1462,70 @@ GST_START_TEST (test_layer_meta_value)
GST_END_TEST;
GST_START_TEST (test_layer_meta_marker_list)
{
GESTimeline *timeline;
GESLayer *layer, *layer2;
GESMarkerList *mlist, *mlist2;
GESMarker *marker;
gchar *metas1, *metas2;
ges_init ();
timeline = ges_timeline_new_audio_video ();
layer = ges_layer_new ();
ges_timeline_add_layer (timeline, layer);
layer2 = ges_layer_new ();
ges_timeline_add_layer (timeline, layer2);
mlist = ges_marker_list_new ();
marker = ges_marker_list_add (mlist, 42);
ges_meta_container_set_string (GES_META_CONTAINER (marker), "bar", "baz");
marker = ges_marker_list_add (mlist, 84);
ges_meta_container_set_string (GES_META_CONTAINER (marker), "lorem",
"ip\tsu\"m;");
ASSERT_OBJECT_REFCOUNT (mlist, "local ref", 1);
fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER (layer),
"foo", mlist));
ASSERT_OBJECT_REFCOUNT (mlist, "GstStructure + local ref", 2);
mlist2 =
ges_meta_container_get_marker_list (GES_META_CONTAINER (layer), "foo");
fail_unless (mlist == mlist2);
ASSERT_OBJECT_REFCOUNT (mlist, "GstStructure + getter + local ref", 3);
g_object_unref (mlist2);
ASSERT_OBJECT_REFCOUNT (mlist, "GstStructure + local ref", 2);
metas1 = ges_meta_container_metas_to_string (GES_META_CONTAINER (layer));
ges_meta_container_add_metas_from_string (GES_META_CONTAINER (layer2),
metas1);
metas2 = ges_meta_container_metas_to_string (GES_META_CONTAINER (layer2));
fail_unless_equals_string (metas1, metas2);
g_free (metas1);
g_free (metas2);
fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER (layer),
"foo", NULL));
ASSERT_OBJECT_REFCOUNT (mlist, "local ref", 1);
g_object_unref (mlist);
g_object_unref (timeline);
ges_deinit ();
}
GST_END_TEST;
GST_START_TEST (test_layer_meta_register)
{
GESTimeline *timeline;
......@@ -1667,6 +1731,7 @@ ges_suite (void)
tcase_add_test (tc_chain, test_layer_meta_date);
tcase_add_test (tc_chain, test_layer_meta_date_time);
tcase_add_test (tc_chain, test_layer_meta_value);
tcase_add_test (tc_chain, test_layer_meta_marker_list);
tcase_add_test (tc_chain, test_layer_meta_register);
tcase_add_test (tc_chain, test_layer_meta_foreach);
tcase_add_test (tc_chain, test_layer_get_clips_in_interval);
......
/* GStreamer Editing Services
*
* Copyright (C) <2019> Mathieu Duponchelle <mathieu@centricular.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test-utils.h"
#include <ges/ges.h>
#include <gst/check/gstcheck.h>
GST_START_TEST (test_add)
{
GESMarkerList *markerlist;
GESMarker *marker;
ges_init ();
markerlist = ges_marker_list_new ();
marker = ges_marker_list_add (markerlist, 42);
ASSERT_OBJECT_REFCOUNT (marker, "marker list", 1);
g_object_ref (marker);
ASSERT_OBJECT_REFCOUNT (marker, "marker list + local ref", 2);
g_object_unref (markerlist);
ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
g_object_unref (marker);
ges_deinit ();
}
GST_END_TEST;
GST_START_TEST (test_remove)
{
GESMarkerList *markerlist;
GESMarker *marker;
ges_init ();
markerlist = ges_marker_list_new ();
marker = ges_marker_list_add (markerlist, 42);
g_object_ref (marker);
fail_unless_equals_int (ges_marker_list_size (markerlist), 1);
fail_unless (ges_marker_list_remove (markerlist, marker));
fail_unless_equals_int (ges_marker_list_size (markerlist), 0);
ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
fail_if (ges_marker_list_remove (markerlist, marker));
g_object_unref (marker);
g_object_unref (markerlist);
ges_deinit ();
}
GST_END_TEST;
static void
marker_added_cb (GESMarkerList * mlist, GstClockTime position,
GESMarker * marker, gboolean * called)
{
fail_unless_equals_int (position, 42);
ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
*called = TRUE;
}
GST_START_TEST (test_signal_marker_added)
{
GESMarkerList *mlist;
GESMarker *marker;
gboolean called = FALSE;
ges_init ();
mlist = ges_marker_list_new ();
g_signal_connect (mlist, "marker-added", G_CALLBACK (marker_added_cb),
&called);
marker = ges_marker_list_add (mlist, 42);
ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
fail_unless (called == TRUE);
g_signal_handlers_disconnect_by_func (mlist, marker_added_cb, &called);
g_object_unref (mlist);
ges_deinit ();
}
GST_END_TEST;
static void
marker_removed_cb (GESMarkerList * mlist, GESMarker * marker, gboolean * called)
{
ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
*called = TRUE;
}
GST_START_TEST (test_signal_marker_removed)
{
GESMarkerList *mlist;
GESMarker *marker;
gboolean called = FALSE;
ges_init ();
mlist = ges_marker_list_new ();
marker = ges_marker_list_add (mlist, 42);
ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
g_signal_connect (mlist, "marker-removed", G_CALLBACK (marker_removed_cb),
&called);
fail_unless (ges_marker_list_remove (mlist, marker));
fail_unless (called == TRUE);
g_signal_handlers_disconnect_by_func (mlist, marker_removed_cb, &called);
g_object_unref (mlist);
ges_deinit ();
}
GST_END_TEST;
static void
marker_moved_cb (GESMarkerList * mlist, GstClockTime position,
GESMarker * marker, gboolean * called)
{
fail_unless_equals_int (position, 42);
ASSERT_OBJECT_REFCOUNT (marker, "local ref + signal", 2);
*called = TRUE;
}
GST_START_TEST (test_signal_marker_moved)
{
GESMarkerList *mlist;
GESMarker *marker;
gboolean called = FALSE;
ges_init ();
mlist = ges_marker_list_new ();
g_signal_connect (mlist, "marker-moved", G_CALLBACK (marker_moved_cb),
&called);
marker = ges_marker_list_add (mlist, 10);
ASSERT_OBJECT_REFCOUNT (marker, "local ref", 1);
fail_unless (ges_marker_list_move (mlist, marker, 42));
fail_unless (called == TRUE);
g_signal_handlers_disconnect_by_func (mlist, marker_moved_cb, &called);
g_object_unref (mlist);
ges_deinit ();
}
GST_END_TEST;
GST_START_TEST (test_get_markers)
{
GESMarkerList *markerlist;
GESMarker *marker1, *marker2, *marker3, *marker4;
GList *markers;
ges_init ();
markerlist = ges_marker_list_new ();
marker1 = ges_marker_list_add (markerlist, 0);
marker2 = ges_marker_list_add (markerlist, 10);
marker3 = ges_marker_list_add (markerlist, 20);
marker4 = ges_marker_list_add (markerlist, 30);
markers = ges_marker_list_get_markers (markerlist);
ASSERT_OBJECT_REFCOUNT (marker1, "local ref + markers", 2);
ASSERT_OBJECT_REFCOUNT (marker2, "local ref + markers", 2);
ASSERT_OBJECT_REFCOUNT (marker3, "local ref + markers", 2);
ASSERT_OBJECT_REFCOUNT (marker4, "local ref + markers", 2);
fail_unless (g_list_index (markers, marker1) == 0);
fail_unless (g_list_index (markers, marker2) == 1);
fail_unless (g_list_index (markers, marker3) == 2);
fail_unless (g_list_index (markers, marker4) == 3);
g_list_foreach (markers, (GFunc) gst_object_unref, NULL);
g_list_free (markers);
g_object_unref (markerlist);
ges_deinit ();
}
GST_END_TEST;
GST_START_TEST (test_move_marker)
{
GESMarkerList *markerlist;
GESMarker *marker_a, *marker_b;
GstClockTime position;
GList *range;
ges_init ();
markerlist = ges_marker_list_new ();
marker_a = ges_marker_list_add (markerlist, 10);
marker_b = ges_marker_list_add (markerlist, 30);
fail_unless (ges_marker_list_move (markerlist, marker_a, 20));
g_object_get (marker_a, "position", &position, NULL);
fail_unless_equals_int (position, 20);
range = ges_marker_list_get_markers (markerlist);
fail_unless (g_list_index (range, marker_a) == 0);
fail_unless (g_list_index (range, marker_b) == 1);
g_list_foreach (range, (GFunc) gst_object_unref, NULL);
g_list_free (range);
fail_unless (ges_marker_list_move (markerlist, marker_a, 35));
range = ges_marker_list_get_markers (markerlist);
fail_unless (g_list_index (range, marker_b) == 0);
fail_unless (g_list_index (range, marker_a) == 1);
g_list_foreach (range, (GFunc) gst_object_unref, NULL);
g_list_free (range);
fail_unless (ges_marker_list_move (markerlist, marker_a, 30));
g_object_get (marker_a, "position", &position, NULL);
fail_unless_equals_int (position, 30);
g_object_get (marker_b, "position", &position, NULL);
fail_unless_equals_int (position, 30);
fail_unless_equals_int (ges_marker_list_size (markerlist), 2);
ges_marker_list_remove (markerlist, marker_a);
fail_unless (!ges_marker_list_move (markerlist, marker_a, 20));
g_object_unref (markerlist);
ges_deinit ();
}
GST_END_TEST;
GST_START_TEST (test_serialize_deserialize)
{
GESMarkerList *markerlist1, *markerlist2;
gchar *metas1, *metas2;
GESTimeline *timeline1, *timeline2;
ges_init ();
timeline1 = ges_timeline_new_audio_video ();
markerlist1 = ges_marker_list_new ();
ges_marker_list_add (markerlist1, 0);
ges_marker_list_add (markerlist1, 10);
ASSERT_OBJECT_REFCOUNT (markerlist1, "local ref", 1);
fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER
(timeline1), "ges-test", markerlist1));
ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + local ref", 2);
markerlist2 =
ges_meta_container_get_marker_list (GES_META_CONTAINER (timeline1),
"ges-test");
fail_unless (markerlist1 == markerlist2);
ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + getter + local ref", 3);
g_object_unref (markerlist2);
ASSERT_OBJECT_REFCOUNT (markerlist1, "GstStructure + local ref", 2);
timeline2 = ges_timeline_new_audio_video ();
metas1 = ges_meta_container_metas_to_string (GES_META_CONTAINER (timeline1));
ges_meta_container_add_metas_from_string (GES_META_CONTAINER (timeline2),
metas1);
metas2 = ges_meta_container_metas_to_string (GES_META_CONTAINER (timeline2));
fail_unless_equals_string (metas1, metas2);
g_free (metas1);
g_free (metas2);
fail_unless (ges_meta_container_set_marker_list (GES_META_CONTAINER
(timeline1), "ges-test", NULL));
ASSERT_OBJECT_REFCOUNT (markerlist1, "local ref", 1);
g_object_unref (markerlist1);
g_object_unref (timeline1);
g_object_unref (timeline2);
ges_deinit ();
}
GST_END_TEST;
static Suite *
ges_suite (void)
{
Suite *s = suite_create ("ges-marker-list");
TCase *tc_chain = tcase_create ("markerlist");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_add);
tcase_add_test (tc_chain, test_remove);
tcase_add_test (tc_chain, test_signal_marker_added);
tcase_add_test (tc_chain, test_signal_marker_removed);
tcase_add_test (tc_chain, test_signal_marker_moved);
tcase_add_test (tc_chain, test_get_markers);
tcase_add_test (tc_chain, test_move_marker);
tcase_add_test (tc_chain, test_serialize_deserialize);
return s;
}
GST_CHECK_MAIN (ges);
......@@ -17,6 +17,7 @@ ges_tests = [
['ges/track'],
['ges/tempochange'],
['ges/negative'],
['ges/markerlist'],
['nle/simple'],
['nle/complex'],
['nle/nleoperation'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!