ges:clip: Add a method to look for a list of TrackElement-s

+ Add unit tests to check it works properly.

API:
  + ges_clip_find_track_elements
This commit is contained in:
Thibault Saunier 2014-05-19 12:21:52 +02:00
parent 84f02f288e
commit 1fed9555cf
4 changed files with 124 additions and 0 deletions

View file

@ -497,6 +497,7 @@ GESCreateTrackElementsFunc
GESFillTrackElementFunc
ges_clip_get_layer
ges_clip_find_track_element
ges_clip_find_track_elements
ges_clip_add_asset
ges_clip_get_top_effects
ges_clip_get_top_effect_position

View file

@ -1424,4 +1424,58 @@ ges_clip_add_asset (GESClip * clip, GESAsset * asset)
return NULL;
return element;
}
/**
* ges_clip_find_track_elements:
* @clip: a #GESClip
* @track: (allow-none): a #GESTrack or NULL
* @track_type: a #GESTrackType indicating the type of tracks in which elements
* should be searched.
* @type: a #GType indicating the type of track element you are looking
* for or %G_TYPE_NONE if you do not care about the track type.
*
* Finds all the #GESTrackElement controlled by @clip that is used in @track. You
* may optionally specify a GType to further narrow search criteria.
*
* Returns: (transfer full) (element-type GESTrackElement): a #GList of the
* #GESTrackElement contained in @clip.
* The refcount of the objects will be increased. The user will have to
* unref each #GESTrackElement and free the #GList.
*/
GList *
ges_clip_find_track_elements (GESClip * clip, GESTrack * track,
GESTrackType track_type, GType type)
{
GList *tmp;
GESTrack *tmptrack;
GESTrackElement *otmp;
GESTrackElement *foundElement;
GList *ret = NULL;
g_return_val_if_fail (GES_IS_CLIP (clip), NULL);
g_return_val_if_fail (!(track == NULL && type == G_TYPE_NONE &&
track_type == GES_TRACK_TYPE_UNKNOWN), NULL);
for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = g_list_next (tmp)) {
otmp = (GESTrackElement *) tmp->data;
if ((type != G_TYPE_NONE) && !G_TYPE_CHECK_INSTANCE_TYPE (tmp->data, type))
continue;
tmptrack = ges_track_element_get_track (otmp);
if (((track != NULL && tmptrack == track)) ||
(track_type != GES_TRACK_TYPE_UNKNOWN
&& tmptrack->type == track_type)) {
foundElement = GES_TRACK_ELEMENT (tmp->data);
ret = g_list_append (ret, gst_object_ref (foundElement));
}
}
return ret;
}

View file

@ -147,6 +147,8 @@ void ges_clip_set_supported_formats (GESClip *clip, GESTrackType
GESTrackElement* ges_clip_add_asset (GESClip *clip, GESAsset *asset);
GESTrackElement* ges_clip_find_track_element (GESClip *clip, GESTrack *track,
GType type);
GList * ges_clip_find_track_elements (GESClip * clip, GESTrack * track,
GESTrackType track_type, GType type);
/****************************************************
* Layer *

View file

@ -361,6 +361,72 @@ GST_START_TEST (test_clip_refcount_remove_child)
GST_END_TEST;
GST_START_TEST (test_clip_find_track_element)
{
GESClip *clip;
GList *foundelements;
GESTimeline *timeline;
GESTrack *track, *track1, *track2;
GESTrackElement *effect, *effect1, *effect2, *foundelem;
ges_init ();
clip = GES_CLIP (ges_test_clip_new ());
track = GES_TRACK (ges_audio_track_new ());
track1 = GES_TRACK (ges_audio_track_new ());
track2 = GES_TRACK (ges_video_track_new ());
timeline = ges_timeline_new ();
fail_unless (ges_timeline_add_track (timeline, track));
fail_unless (ges_timeline_add_track (timeline, track1));
fail_unless (ges_timeline_add_track (timeline, track2));
effect = GES_TRACK_ELEMENT (ges_effect_new ("identity"));
fail_unless (ges_track_add_element (track, effect));
fail_unless (ges_container_add (GES_CONTAINER (clip),
GES_TIMELINE_ELEMENT (effect)));
effect1 = GES_TRACK_ELEMENT (ges_effect_new ("identity"));
fail_unless (ges_track_add_element (track1, effect1));
fail_unless (ges_container_add (GES_CONTAINER (clip),
GES_TIMELINE_ELEMENT (effect1)));
effect2 = GES_TRACK_ELEMENT (ges_effect_new ("identity"));
fail_unless (ges_track_add_element (track2, effect2));
fail_unless (ges_container_add (GES_CONTAINER (clip),
GES_TIMELINE_ELEMENT (effect2)));
foundelem = ges_clip_find_track_element (clip, track, G_TYPE_NONE);
fail_unless (foundelem == effect);
gst_object_unref (foundelem);
foundelem = ges_clip_find_track_element (clip, NULL, GES_TYPE_SOURCE);
fail_unless (foundelem == NULL);
foundelements = ges_clip_find_track_elements (clip, NULL,
GES_TRACK_TYPE_AUDIO, G_TYPE_NONE);
fail_unless_equals_int (g_list_length (foundelements), 2);
g_list_free_full (foundelements, gst_object_unref);
foundelements = ges_clip_find_track_elements (clip, NULL,
GES_TRACK_TYPE_VIDEO, G_TYPE_NONE);
fail_unless_equals_int (g_list_length (foundelements), 1);
g_list_free_full (foundelements, gst_object_unref);
foundelements = ges_clip_find_track_elements (clip, track,
GES_TRACK_TYPE_VIDEO, G_TYPE_NONE);
fail_unless_equals_int (g_list_length (foundelements), 2);
fail_unless (g_list_find (foundelements, effect2) != NULL,
"In the video track");
fail_unless (g_list_find (foundelements, effect2) != NULL, "In 'track'");
g_list_free_full (foundelements, gst_object_unref);
gst_object_unref (timeline);
}
GST_END_TEST;
static Suite *
ges_suite (void)
{
@ -373,6 +439,7 @@ ges_suite (void)
tcase_add_test (tc_chain, test_split_object);
tcase_add_test (tc_chain, test_clip_group_ungroup);
tcase_add_test (tc_chain, test_clip_refcount_remove_child);
tcase_add_test (tc_chain, test_clip_find_track_element);
return s;
}