nlecomposition: Get overall pipeline position by recursing up

And handle NLEComposition inside NLEComposition

Fixes https://gitlab.freedesktop.org/gstreamer/gst-editing-services/issues/39
This commit is contained in:
Thibault Saunier 2019-01-17 15:12:42 -03:00 committed by Mathieu Duponchelle
parent d8f2a406a7
commit c596f80c63
3 changed files with 29 additions and 60 deletions

View file

@ -58,8 +58,6 @@ typedef struct
GstPad *srcpad; /* Timeline source pad */
GstPad *playsinkpad;
GstPad *encodebinpad;
guint query_position_id;
} OutputChain;
@ -753,18 +751,6 @@ no_track:
}
}
static GstClockTime
_query_position_cb (GstElement * composition, GESPipeline * self)
{
gint64 position;
if (gst_element_query_position (GST_ELEMENT (self), GST_FORMAT_TIME,
&position))
return position;
return GST_CLOCK_TIME_NONE;
}
static void
_link_track (GESPipeline * self, GESTrack * track)
{
@ -815,10 +801,6 @@ _link_track (GESPipeline * self, GESTrack * track)
return;
}
chain->query_position_id =
g_signal_connect (ges_track_get_composition (track), "query-position",
G_CALLBACK (_query_position_cb), self);
chain->srcpad = pad;
gst_object_unref (pad);
@ -989,11 +971,6 @@ _unlink_track (GESPipeline * self, GESTrack * track)
gst_element_set_state (chain->tee, GST_STATE_NULL);
gst_bin_remove (GST_BIN (self), chain->tee);
if (chain->query_position_id) {
g_signal_handler_disconnect (ges_track_get_composition (track),
chain->query_position_id);
chain->query_position_id = 0;
}
self->priv->chains = g_list_remove (self->priv->chains, chain);
g_free (chain);

View file

@ -66,7 +66,6 @@ enum
{
COMMIT_SIGNAL,
COMMITED_SIGNAL,
QUERY_POSITION_SIGNAL,
LAST_SIGNAL
};
@ -1006,22 +1005,6 @@ nle_composition_class_init (NleCompositionClass * klass)
0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
/**
* NleComposition::query-position
* @comp: a #NleComposition
*
* A signal that *has* to be connected and which should return the current
* position of the pipeline.
*
* This signal is used in order to know the current position of the whole
* pipeline so it is user's responsability to give that answer as there
* is no other way to precisely know the position in the whole pipeline.
*/
_signals[QUERY_POSITION_SIGNAL] =
g_signal_new ("query-position", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_UINT64, 0, NULL);
GST_DEBUG_REGISTER_FUNCPTR (_seek_pipeline_func);
GST_DEBUG_REGISTER_FUNCPTR (_remove_object_func);
GST_DEBUG_REGISTER_FUNCPTR (_add_object_func);
@ -1472,16 +1455,40 @@ get_current_position (NleComposition * comp)
NleCompositionPrivate *priv = comp->priv;
gboolean res;
gint64 value = GST_CLOCK_TIME_NONE;
GstObject *parent, *tmp;
GstPad *peer;
g_signal_emit (comp, _signals[QUERY_POSITION_SIGNAL], 0, &value);
parent = gst_object_get_parent (GST_OBJECT (comp));
while ((tmp = parent)) {
if (NLE_IS_COMPOSITION (parent)) {
GstClockTime parent_position =
get_current_position (NLE_COMPOSITION (parent));
if (value >= 0) {
GST_DEBUG_OBJECT (comp, "Got position %" GST_TIME_FORMAT,
GST_TIME_ARGS (value));
if (parent_position > NLE_OBJECT_STOP (comp)
|| parent_position < NLE_OBJECT_START (comp)) {
GST_INFO_OBJECT (comp,
"Global position outside of subcomposition, returning TIME_NONE");
return value;
return GST_CLOCK_TIME_NONE;
}
value =
parent_position - NLE_OBJECT_START (comp) + NLE_OBJECT_INPOINT (comp);
}
if (GST_IS_PIPELINE (parent)) {
if (gst_element_query_position (GST_ELEMENT (parent), GST_FORMAT_TIME,
&value)) {
gst_object_unref (parent);
return value;
}
}
parent = gst_object_get_parent (GST_OBJECT (parent));
gst_object_unref (tmp);
}
/* Try querying position downstream */

View file

@ -196,18 +196,6 @@ GST_START_TEST (test_remove_invalid_object)
GST_END_TEST;
static GstClockTime
_query_position_cb (GstElement * composition, GstPipeline * pipeline)
{
gint64 position;
if (gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
&position))
return position;
return GST_CLOCK_TIME_NONE;
}
GST_START_TEST (test_remove_last_object)
{
GstBin *composition;
@ -227,9 +215,6 @@ GST_START_TEST (test_remove_last_object)
composition = GST_BIN (gst_element_factory_make ("nlecomposition",
"composition"));
g_signal_connect (composition, "query-position",
G_CALLBACK (_query_position_cb), pipeline);
gst_element_set_state (GST_ELEMENT (composition), GST_STATE_READY);
fakesink = gst_element_factory_make ("fakesink", NULL);