2014-10-21 08:35:48 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2001 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
* 2004-2008 Edward Hervey <bilboed@bilboed.com>
|
2014-06-27 10:15:10 +00:00
|
|
|
* 2014 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
|
|
|
|
* 2014 Thibault Saunier <tsaunier@gnome.org>
|
2014-10-21 08:35:48 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
#include "nle.h"
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-15 13:48:14 +00:00
|
|
|
* SECTION:element-nlecomposition
|
2014-10-21 08:35:48 +00:00
|
|
|
*
|
2014-08-15 13:48:14 +00:00
|
|
|
* A NleComposition contains NleObjects such as NleSources and NleOperations,
|
2014-10-21 08:35:48 +00:00
|
|
|
* and connects them dynamically to create a composition timeline.
|
|
|
|
*/
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static GstStaticPadTemplate nle_composition_src_template =
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
2014-06-24 11:44:13 +00:00
|
|
|
GST_PAD_ALWAYS,
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (nlecomposition_debug);
|
|
|
|
#define GST_CAT_DEFAULT nlecomposition_debug
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
#define _do_init \
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (nlecomposition_debug,"nlecomposition", GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "GNonLin Composition");
|
|
|
|
#define nle_composition_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (NleComposition, nle_composition, NLE_TYPE_OBJECT,
|
2014-10-21 08:35:48 +00:00
|
|
|
_do_init);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DEACTIVATED_ELEMENTS_STATE,
|
|
|
|
PROP_LAST,
|
|
|
|
};
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* Properties from NleObject */
|
2014-10-21 08:35:48 +00:00
|
|
|
enum
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NLEOBJECT_PROP_START,
|
|
|
|
NLEOBJECT_PROP_STOP,
|
|
|
|
NLEOBJECT_PROP_DURATION,
|
|
|
|
NLEOBJECT_PROP_LAST
|
2014-10-21 08:35:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COMMIT_SIGNAL,
|
2014-06-27 14:12:12 +00:00
|
|
|
COMMITED_SIGNAL,
|
2014-11-04 14:38:05 +00:00
|
|
|
QUERY_POSITION_SIGNAL,
|
2014-10-21 08:35:48 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2014-07-11 16:27:25 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COMP_UPDATE_STACK_INITIALIZE,
|
|
|
|
COMP_UPDATE_STACK_ON_COMMIT,
|
|
|
|
COMP_UPDATE_STACK_ON_EOS,
|
2014-09-19 10:49:52 +00:00
|
|
|
COMP_UPDATE_STACK_ON_SEEK,
|
|
|
|
COMP_UPDATE_STACK_NONE
|
2014-08-15 13:48:14 +00:00
|
|
|
} NleUpdateStackReason;
|
2014-07-11 16:27:25 +00:00
|
|
|
|
|
|
|
static const char *UPDATE_PIPELINE_REASONS[] = {
|
|
|
|
"Initialize", "Commit", "EOS", "Seek"
|
|
|
|
};
|
|
|
|
|
2014-07-01 16:08:32 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp;
|
2014-07-01 16:08:32 +00:00
|
|
|
GstEvent *event;
|
|
|
|
} SeekData;
|
|
|
|
|
2014-07-02 15:33:35 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp;
|
|
|
|
NleObject *object;
|
2014-07-02 15:33:35 +00:00
|
|
|
} ChildIOData;
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp;
|
2014-07-25 08:55:52 +00:00
|
|
|
gint32 seqnum;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
NleUpdateStackReason reason;
|
2014-07-25 08:55:52 +00:00
|
|
|
} UpdateCompositionData;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
struct _NleCompositionPrivate
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
gboolean dispose_has_run;
|
|
|
|
|
|
|
|
/*
|
2014-08-15 13:48:14 +00:00
|
|
|
Sorted List of NleObjects , ThreadSafe
|
2014-10-21 08:35:48 +00:00
|
|
|
objects_start : sorted by start-time then priority
|
|
|
|
objects_stop : sorted by stop-time then priority
|
2014-07-14 14:12:00 +00:00
|
|
|
objects_hash : contains all controlled objects
|
2014-07-14 15:52:36 +00:00
|
|
|
|
|
|
|
Those list should be manipulated exclusively in the main context
|
|
|
|
or while the task is totally stopped.
|
2014-10-21 08:35:48 +00:00
|
|
|
*/
|
|
|
|
GList *objects_start;
|
|
|
|
GList *objects_stop;
|
|
|
|
GHashTable *objects_hash;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* List of NleObject to be inserted or removed from the composition on the
|
2014-06-30 14:21:30 +00:00
|
|
|
* next commit */
|
|
|
|
GHashTable *pending_io;
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
gulong ghosteventprobe;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* current stack, list of NleObject* */
|
2014-10-21 08:35:48 +00:00
|
|
|
GNode *current;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* List of NleObject whose start/duration will be the same as the composition */
|
2014-10-21 08:35:48 +00:00
|
|
|
GList *expandables;
|
|
|
|
|
|
|
|
/*
|
|
|
|
current segment seek start/stop time.
|
|
|
|
Reconstruct pipeline ONLY if seeking outside of those values
|
|
|
|
FIXME : segment_start isn't always the earliest time before which the
|
|
|
|
timeline doesn't need to be modified
|
|
|
|
*/
|
|
|
|
GstClockTime segment_start;
|
|
|
|
GstClockTime segment_stop;
|
|
|
|
|
|
|
|
/* Seek segment handler */
|
|
|
|
GstSegment *segment;
|
|
|
|
GstSegment *outside_segment;
|
|
|
|
|
|
|
|
/* Next running base_time to set on outgoing segment */
|
|
|
|
guint64 next_base_time;
|
|
|
|
|
|
|
|
/*
|
|
|
|
OUR sync_handler on the child_bus
|
2014-08-15 13:48:14 +00:00
|
|
|
We are called before nle_object_sync_handler
|
2014-10-21 08:35:48 +00:00
|
|
|
*/
|
2014-08-15 13:48:14 +00:00
|
|
|
GstPadEventFunction nle_event_pad_func;
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean send_stream_start;
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
/* Protect the actions list */
|
|
|
|
GMutex actions_lock;
|
|
|
|
GCond actions_cond;
|
|
|
|
GList *actions;
|
2014-06-27 10:15:10 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean running;
|
2014-06-30 13:12:38 +00:00
|
|
|
gboolean initialized;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
GstElement *current_bin;
|
2014-07-03 14:46:21 +00:00
|
|
|
|
|
|
|
gboolean seeking_itself;
|
2014-07-04 09:05:41 +00:00
|
|
|
gint real_eos_seqnum;
|
2014-07-11 17:13:29 +00:00
|
|
|
gint next_eos_seqnum;
|
2014-07-11 13:41:50 +00:00
|
|
|
gint flush_seqnum;
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-07-14 13:50:58 +00:00
|
|
|
/* 0 means that we already received the right caps or segment */
|
2014-09-19 10:49:52 +00:00
|
|
|
gint seqnum_to_restart_task;
|
2014-09-23 13:01:56 +00:00
|
|
|
gboolean waiting_for_buffer;
|
2014-07-29 21:41:45 +00:00
|
|
|
|
|
|
|
gboolean tearing_down_stack;
|
2014-09-19 10:49:52 +00:00
|
|
|
|
|
|
|
NleUpdateStackReason updating_reason;
|
2014-10-21 08:35:48 +00:00
|
|
|
};
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
typedef struct _Action
|
|
|
|
{
|
|
|
|
GCClosure closure;
|
|
|
|
gint priority;
|
|
|
|
} Action;
|
|
|
|
|
|
|
|
#define ACTION_CALLBACK(__action) (((GCClosure*) (__action))->callback)
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
static guint _signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static GParamSpec *nleobject_properties[NLEOBJECT_PROP_LAST];
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
#define OBJECT_IN_ACTIVE_SEGMENT(comp,element) \
|
2014-08-15 13:48:14 +00:00
|
|
|
((NLE_OBJECT_START(element) < comp->priv->segment_stop) && \
|
|
|
|
(NLE_OBJECT_STOP(element) >= comp->priv->segment_start))
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static void nle_composition_dispose (GObject * object);
|
|
|
|
static void nle_composition_finalize (GObject * object);
|
|
|
|
static void nle_composition_reset (NleComposition * comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static gboolean nle_composition_add_object (GstBin * bin, GstElement * element);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_remove_object (GstBin * bin, GstElement * element);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_change_state (GstElement * element, GstStateChange transition);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static inline void nle_composition_reset_target_pad (NleComposition * comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
seek_handling (NleComposition * comp, gint32 seqnum,
|
|
|
|
NleUpdateStackReason update_stack_reason);
|
|
|
|
static gint objects_start_compare (NleObject * a, NleObject * b);
|
|
|
|
static gint objects_stop_compare (NleObject * a, NleObject * b);
|
|
|
|
static GstClockTime get_current_position (NleComposition * comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
static gboolean update_pipeline (NleComposition * comp,
|
2014-07-25 08:55:52 +00:00
|
|
|
GstClockTime currenttime, gint32 seqnum,
|
2014-08-15 13:48:14 +00:00
|
|
|
NleUpdateStackReason update_stack_reason);
|
|
|
|
static gboolean nle_composition_commit_func (NleObject * object,
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean recurse);
|
2014-08-15 13:48:14 +00:00
|
|
|
static void update_start_stop_duration (NleComposition * comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_event_handler (GstPad * ghostpad, GstObject * parent,
|
2014-06-24 11:44:13 +00:00
|
|
|
GstEvent * event);
|
2014-08-15 13:48:14 +00:00
|
|
|
static void _relink_single_node (NleComposition * comp, GNode * node,
|
2014-07-03 09:36:20 +00:00
|
|
|
GstEvent * toplevel_seek);
|
2014-08-20 11:15:30 +00:00
|
|
|
static void _update_pipeline_func (NleComposition * comp,
|
|
|
|
UpdateCompositionData * ucompo);
|
|
|
|
static void _commit_func (NleComposition * comp,
|
|
|
|
UpdateCompositionData * ucompo);
|
2014-08-15 13:48:14 +00:00
|
|
|
static GstEvent *get_new_seek_event (NleComposition * comp, gboolean initial,
|
2014-07-01 16:08:32 +00:00
|
|
|
gboolean updatestoponly);
|
2014-08-20 11:15:30 +00:00
|
|
|
static gboolean _nle_composition_add_object (NleComposition * comp,
|
|
|
|
NleObject * object);
|
|
|
|
static gboolean _nle_composition_remove_object (NleComposition * comp,
|
|
|
|
NleObject * object);
|
2014-08-15 13:48:14 +00:00
|
|
|
static void _deactivate_stack (NleComposition * comp,
|
2014-07-11 14:08:20 +00:00
|
|
|
gboolean flush_downstream);
|
2014-08-15 13:48:14 +00:00
|
|
|
static gboolean _set_real_eos_seqnum_from_seek (NleComposition * comp,
|
2014-07-11 14:08:20 +00:00
|
|
|
GstEvent * event);
|
2014-08-20 11:15:30 +00:00
|
|
|
static void _emit_commited_signal_func (NleComposition * comp, gpointer udata);
|
2014-09-19 10:49:52 +00:00
|
|
|
static void _restart_task (NleComposition * comp);
|
2014-08-20 11:15:30 +00:00
|
|
|
static void
|
|
|
|
_add_action (NleComposition * comp, GCallback func, gpointer data,
|
|
|
|
gint priority);
|
2014-09-19 10:49:52 +00:00
|
|
|
static gboolean
|
|
|
|
_is_ready_to_restart_task (NleComposition * comp, GstEvent * event);
|
2014-06-24 11:44:13 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* COMP_REAL_START: actual position to start current playback at. */
|
|
|
|
#define COMP_REAL_START(comp) \
|
2014-08-15 13:48:14 +00:00
|
|
|
(MAX (comp->priv->segment->start, NLE_OBJECT_START (comp)))
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
#define COMP_REAL_STOP(comp) \
|
|
|
|
(GST_CLOCK_TIME_IS_VALID (comp->priv->segment->stop) ? \
|
2014-08-15 13:48:14 +00:00
|
|
|
(MIN (comp->priv->segment->stop, NLE_OBJECT_STOP (comp))) : \
|
|
|
|
NLE_OBJECT_STOP (comp))
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
#define ACTIONS_LOCK(comp) G_STMT_START { \
|
|
|
|
GST_LOG_OBJECT (comp, "Getting ACTIONS_LOCK in thread %p", \
|
2014-06-27 10:15:10 +00:00
|
|
|
g_thread_self()); \
|
2014-08-20 11:15:30 +00:00
|
|
|
g_mutex_lock(&((NleComposition*)comp)->priv->actions_lock); \
|
|
|
|
GST_LOG_OBJECT (comp, "Got ACTIONS_LOCK in thread %p", \
|
2014-06-27 10:15:10 +00:00
|
|
|
g_thread_self()); \
|
|
|
|
} G_STMT_END
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
#define ACTIONS_UNLOCK(comp) G_STMT_START { \
|
|
|
|
g_mutex_unlock(&((NleComposition*)comp)->priv->actions_lock); \
|
|
|
|
GST_LOG_OBJECT (comp, "Unlocked ACTIONS_LOCK in thread %p", \
|
2014-06-27 10:15:10 +00:00
|
|
|
g_thread_self()); \
|
|
|
|
} G_STMT_END
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
#define WAIT_FOR_AN_ACTION(comp) G_STMT_START { \
|
|
|
|
GST_LOG_OBJECT (comp, "Waiting for an action in thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
g_cond_wait(&((NleComposition*)comp)->priv->actions_cond, \
|
|
|
|
&((NleComposition*)comp)->priv->actions_lock); \
|
|
|
|
GST_LOG_OBJECT (comp, "Done WAITING for an action in thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define SIGNAL_NEW_ACTION(comp) G_STMT_START { \
|
|
|
|
GST_LOG_OBJECT (comp, "Signalling new action from thread %p", \
|
|
|
|
g_thread_self()); \
|
|
|
|
g_cond_signal(&((NleComposition*)comp)->priv->actions_cond); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
#define GET_TASK_LOCK(comp) (&(NLE_COMPOSITION(comp)->task_rec_lock))
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-15 00:37:25 +00:00
|
|
|
static inline gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_have_to_flush_downstream (NleUpdateStackReason update_reason)
|
2014-07-15 00:37:25 +00:00
|
|
|
{
|
|
|
|
if (update_reason == COMP_UPDATE_STACK_ON_COMMIT ||
|
2014-07-21 14:54:46 +00:00
|
|
|
update_reason == COMP_UPDATE_STACK_ON_SEEK ||
|
|
|
|
update_reason == COMP_UPDATE_STACK_INITIALIZE)
|
2014-07-15 00:37:25 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-07-14 15:47:07 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_assert_proper_thread (NleComposition * comp)
|
2014-07-14 15:47:07 +00:00
|
|
|
{
|
|
|
|
if (comp->task && gst_task_get_state (comp->task) != GST_TASK_STOPPED &&
|
|
|
|
g_thread_self () != comp->task->thread) {
|
|
|
|
g_warning ("Trying to touch children in a thread different from"
|
|
|
|
" its dedicated thread!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_actions_for_type (NleComposition * comp, GCallback callback)
|
2014-07-14 15:47:07 +00:00
|
|
|
{
|
2014-08-20 11:15:30 +00:00
|
|
|
GList *tmp;
|
2014-07-14 15:47:07 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
ACTIONS_LOCK (comp);
|
|
|
|
for (tmp = comp->priv->actions; tmp; tmp = tmp->next) {
|
|
|
|
Action *act = tmp->data;
|
|
|
|
|
|
|
|
if (ACTION_CALLBACK (act) == callback) {
|
|
|
|
g_closure_unref ((GClosure *) act);
|
|
|
|
comp->priv->actions = g_list_delete_link (comp->priv->actions, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ACTIONS_UNLOCK (comp);
|
2014-07-14 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-27 10:15:10 +00:00
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_execute_actions (NleComposition * comp)
|
2014-06-27 10:15:10 +00:00
|
|
|
{
|
2014-08-20 11:15:30 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
|
|
|
|
|
|
|
ACTIONS_LOCK (comp);
|
|
|
|
if (priv->running == FALSE) {
|
2014-06-27 10:15:10 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Not running anymore");
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
ACTIONS_UNLOCK (comp);
|
2014-06-27 10:15:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
if (priv->actions == NULL)
|
|
|
|
WAIT_FOR_AN_ACTION (comp);
|
|
|
|
|
|
|
|
if (comp->priv->running == FALSE) {
|
|
|
|
GST_INFO_OBJECT (comp, "Done waiting but not running anymore");
|
|
|
|
|
|
|
|
ACTIONS_UNLOCK (comp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->actions) {
|
|
|
|
GValue params[1] = { G_VALUE_INIT };
|
|
|
|
GList *lact;
|
|
|
|
|
|
|
|
g_value_init (¶ms[0], G_TYPE_OBJECT);
|
|
|
|
g_value_set_object (¶ms[0], comp);
|
|
|
|
|
|
|
|
lact = priv->actions;
|
|
|
|
priv->actions = priv->actions->next;
|
|
|
|
ACTIONS_UNLOCK (comp);
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (comp, "Invoking %p:%s",
|
|
|
|
lact->data, GST_DEBUG_FUNCPTR_NAME ((ACTION_CALLBACK (lact->data))));
|
|
|
|
g_closure_invoke (lact->data, NULL, 1, params, NULL);
|
2014-09-19 10:55:51 +00:00
|
|
|
g_value_unset (¶ms[0]);
|
2014-08-20 11:15:30 +00:00
|
|
|
} else {
|
|
|
|
ACTIONS_UNLOCK (comp);
|
|
|
|
}
|
2014-06-27 10:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_start_task (NleComposition * comp)
|
2014-06-27 10:15:10 +00:00
|
|
|
{
|
2014-06-27 14:40:19 +00:00
|
|
|
GstTask *task;
|
2014-06-27 10:15:10 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
ACTIONS_LOCK (comp);
|
2014-06-27 10:15:10 +00:00
|
|
|
comp->priv->running = TRUE;
|
2014-08-20 11:15:30 +00:00
|
|
|
ACTIONS_UNLOCK (comp);
|
2014-06-27 14:40:19 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (comp);
|
|
|
|
|
|
|
|
task = comp->task;
|
|
|
|
if (task == NULL) {
|
2014-09-19 10:49:52 +00:00
|
|
|
gchar *taskname =
|
|
|
|
g_strdup_printf ("%s_update_management", GST_OBJECT_NAME (comp));
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
task = gst_task_new ((GstTaskFunction) _execute_actions, comp, NULL);
|
2014-09-19 10:49:52 +00:00
|
|
|
gst_object_set_name (GST_OBJECT_CAST (task), taskname);
|
2014-06-27 14:40:19 +00:00
|
|
|
gst_task_set_lock (task, GET_TASK_LOCK (comp));
|
2014-10-28 16:33:09 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "created task %p", task);
|
2014-06-27 14:40:19 +00:00
|
|
|
comp->task = task;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_task_set_state (task, GST_TASK_STARTED);
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
2014-06-27 10:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_stop_task (NleComposition * comp)
|
2014-06-27 10:15:10 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2014-06-27 14:40:19 +00:00
|
|
|
GstTask *task;
|
2014-06-27 10:15:10 +00:00
|
|
|
|
2014-07-07 19:28:28 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Stoping children management task");
|
2014-06-27 10:15:10 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
ACTIONS_LOCK (comp);
|
2014-06-27 10:15:10 +00:00
|
|
|
comp->priv->running = FALSE;
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
/* Make sure we do not stay blocked trying to execute an action */
|
|
|
|
SIGNAL_NEW_ACTION (comp);
|
|
|
|
ACTIONS_UNLOCK (comp);
|
2014-06-27 10:15:10 +00:00
|
|
|
|
2014-06-27 14:40:19 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "stop task");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (comp);
|
|
|
|
task = comp->task;
|
|
|
|
if (task == NULL)
|
|
|
|
goto no_task;
|
|
|
|
comp->task = NULL;
|
|
|
|
res = gst_task_set_state (task, GST_TASK_STOPPED);
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
|
|
|
|
|
|
|
if (!gst_task_join (task))
|
|
|
|
goto join_failed;
|
|
|
|
|
|
|
|
gst_object_unref (task);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
no_task:
|
|
|
|
{
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
|
|
|
|
|
|
|
/* this is not an error */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
join_failed:
|
|
|
|
{
|
|
|
|
/* this is bad, possibly the application tried to join the task from
|
|
|
|
* the task's thread. We install the task again so that it will be stopped
|
|
|
|
* again from the right thread next time hopefully. */
|
|
|
|
GST_OBJECT_LOCK (comp);
|
|
|
|
GST_DEBUG_OBJECT (comp, "join failed");
|
|
|
|
/* we can only install this task if there was no other task */
|
|
|
|
if (comp->task == NULL)
|
|
|
|
comp->task = task;
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-27 10:15:10 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_post_start_composition_update (NleComposition * comp,
|
|
|
|
gint32 seqnum, NleUpdateStackReason reason)
|
2014-07-25 08:55:52 +00:00
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
|
|
|
|
msg = gst_message_new_element (GST_OBJECT (comp),
|
2014-08-15 13:48:14 +00:00
|
|
|
gst_structure_new ("NleCompositionStartUpdate",
|
2014-07-25 08:55:52 +00:00
|
|
|
"reason", G_TYPE_STRING, UPDATE_PIPELINE_REASONS[reason], NULL));
|
|
|
|
|
|
|
|
gst_message_set_seqnum (msg, seqnum);
|
|
|
|
gst_element_post_message (GST_ELEMENT (comp), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_post_start_composition_update_done (NleComposition * comp,
|
|
|
|
gint32 seqnum, NleUpdateStackReason reason)
|
2014-07-25 08:55:52 +00:00
|
|
|
{
|
|
|
|
GstMessage *msg = gst_message_new_element (GST_OBJECT (comp),
|
2014-08-15 13:48:14 +00:00
|
|
|
gst_structure_new ("NleCompositionUpdateDone",
|
2014-07-25 08:55:52 +00:00
|
|
|
"reason", G_TYPE_STRING, UPDATE_PIPELINE_REASONS[reason],
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
gst_message_set_seqnum (msg, seqnum);
|
|
|
|
gst_element_post_message (GST_ELEMENT (comp), msg);
|
|
|
|
}
|
|
|
|
|
2014-07-11 15:22:24 +00:00
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_seek_pipeline_func (NleComposition * comp, SeekData * seekd)
|
2014-07-01 16:08:32 +00:00
|
|
|
{
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
2014-08-20 11:15:30 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-07-01 16:08:32 +00:00
|
|
|
|
|
|
|
gst_event_parse_seek (seekd->event, &rate, &format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (seekd->comp,
|
|
|
|
"start:%" GST_TIME_FORMAT " -- stop:%" GST_TIME_FORMAT " flags:%d",
|
|
|
|
GST_TIME_ARGS (cur), GST_TIME_ARGS (stop), flags);
|
|
|
|
|
|
|
|
gst_segment_do_seek (priv->segment,
|
|
|
|
rate, format, flags, cur_type, cur, stop_type, stop, NULL);
|
|
|
|
gst_segment_do_seek (priv->outside_segment,
|
|
|
|
rate, format, flags, cur_type, cur, stop_type, stop, NULL);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (seekd->comp, "Segment now has flags:%d",
|
|
|
|
priv->segment->flags);
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (priv->segment->start >= NLE_OBJECT_STOP (seekd->comp)) {
|
2014-07-01 16:08:32 +00:00
|
|
|
GST_INFO_OBJECT (seekd->comp,
|
|
|
|
"Start %" GST_TIME_FORMAT " > comp->stop: %" GST_TIME_FORMAT
|
|
|
|
" Not seeking", GST_TIME_ARGS (priv->segment->start),
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_TIME_ARGS (NLE_OBJECT_STOP (seekd->comp)));
|
2014-07-01 16:08:32 +00:00
|
|
|
GST_FIXME_OBJECT (seekd->comp, "HANDLE error async!");
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-07-01 16:08:32 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update (seekd->comp,
|
|
|
|
gst_event_get_seqnum (seekd->event), COMP_UPDATE_STACK_ON_SEEK);
|
|
|
|
|
2014-07-01 16:08:32 +00:00
|
|
|
/* crop the segment start/stop values */
|
|
|
|
/* Only crop segment start value if we don't have a default object */
|
|
|
|
if (priv->expandables == NULL)
|
|
|
|
priv->segment->start =
|
2014-08-15 13:48:14 +00:00
|
|
|
MAX (priv->segment->start, NLE_OBJECT_START (seekd->comp));
|
2014-07-01 16:08:32 +00:00
|
|
|
priv->segment->stop =
|
2014-08-15 13:48:14 +00:00
|
|
|
MIN (priv->segment->stop, NLE_OBJECT_STOP (seekd->comp));
|
2014-07-01 16:08:32 +00:00
|
|
|
|
|
|
|
priv->next_base_time = 0;
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
seek_handling (seekd->comp, gst_event_get_seqnum (seekd->event),
|
|
|
|
COMP_UPDATE_STACK_ON_SEEK);
|
|
|
|
|
|
|
|
_post_start_composition_update_done (seekd->comp,
|
|
|
|
gst_event_get_seqnum (seekd->event), COMP_UPDATE_STACK_ON_SEEK);
|
2014-07-01 16:08:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 12:35:09 +00:00
|
|
|
/* Must be called with OBJECTS_LOCK taken */
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_process_pending_entries (NleComposition * comp)
|
2014-08-12 12:35:09 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object;
|
2014-08-12 12:35:09 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gboolean deactivated_stack = FALSE;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-08-12 12:35:09 +00:00
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, priv->pending_io);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) & object, NULL)) {
|
|
|
|
if (g_hash_table_contains (priv->objects_hash, object)) {
|
|
|
|
|
|
|
|
if (GST_OBJECT_PARENT (object) == GST_OBJECT_CAST (priv->current_bin) &&
|
|
|
|
deactivated_stack == FALSE) {
|
|
|
|
deactivated_stack = TRUE;
|
|
|
|
|
|
|
|
_deactivate_stack (comp, TRUE);
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_remove_object (comp, object);
|
2014-08-12 12:35:09 +00:00
|
|
|
} else {
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_add_object (comp, object);
|
2014-08-12 12:35:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_remove_all (priv->pending_io);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_commit_values (NleComposition * comp)
|
2014-08-12 12:35:09 +00:00
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
gboolean commited = FALSE;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-08-12 12:35:09 +00:00
|
|
|
|
|
|
|
for (tmp = priv->objects_start; tmp; tmp = tmp->next) {
|
2014-08-15 13:48:14 +00:00
|
|
|
if (nle_object_commit (tmp->data, TRUE))
|
2014-08-12 12:35:09 +00:00
|
|
|
commited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "Linking up commit vmethod");
|
2014-08-15 13:48:14 +00:00
|
|
|
commited |= NLE_OBJECT_CLASS (parent_class)->commit (NLE_OBJECT (comp), TRUE);
|
2014-08-12 12:35:09 +00:00
|
|
|
|
|
|
|
return commited;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_commit_all_values (NleComposition * comp)
|
2014-08-12 12:35:09 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-08-12 12:35:09 +00:00
|
|
|
|
|
|
|
priv->next_base_time = 0;
|
|
|
|
|
|
|
|
_process_pending_entries (comp);
|
|
|
|
|
|
|
|
if (_commit_values (comp) == FALSE) {
|
|
|
|
|
|
|
|
return FALSE;;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The topology of the composition might have changed, update the lists */
|
|
|
|
priv->objects_start = g_list_sort
|
|
|
|
(priv->objects_start, (GCompareFunc) objects_start_compare);
|
|
|
|
priv->objects_stop = g_list_sort
|
|
|
|
(priv->objects_stop, (GCompareFunc) objects_stop_compare);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-07-01 16:08:32 +00:00
|
|
|
|
2014-06-30 13:12:38 +00:00
|
|
|
static gboolean
|
2014-08-20 11:15:30 +00:00
|
|
|
_initialize_stack_func (NleComposition * comp, UpdateCompositionData * ucompo)
|
2014-06-30 13:12:38 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-06-30 13:12:38 +00:00
|
|
|
|
2014-08-12 12:35:09 +00:00
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update (comp, ucompo->seqnum, ucompo->reason);
|
2014-09-19 15:13:52 +00:00
|
|
|
|
|
|
|
_commit_all_values (comp);
|
|
|
|
update_start_stop_duration (comp);
|
2014-07-21 14:57:14 +00:00
|
|
|
comp->priv->next_base_time = 0;
|
2014-06-30 13:12:38 +00:00
|
|
|
/* set ghostpad target */
|
2014-07-11 16:27:25 +00:00
|
|
|
if (!(update_pipeline (comp, COMP_REAL_START (comp),
|
2014-07-25 08:55:52 +00:00
|
|
|
ucompo->seqnum, COMP_UPDATE_STACK_INITIALIZE))) {
|
2014-06-30 13:12:38 +00:00
|
|
|
GST_FIXME_OBJECT (comp, "PLEASE signal state change failure ASYNC");
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update_done (comp, ucompo->seqnum, ucompo->reason);
|
2014-06-30 13:12:38 +00:00
|
|
|
priv->initialized = TRUE;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2014-07-02 15:33:35 +00:00
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_object_func (NleComposition * comp, ChildIOData * childio)
|
2014-07-02 15:33:35 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object = childio->object;
|
2014-07-02 15:33:35 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
|
|
|
NleObject *in_pending_io;
|
2014-06-30 14:21:30 +00:00
|
|
|
|
|
|
|
in_pending_io = g_hash_table_lookup (priv->pending_io, object);
|
|
|
|
|
2014-07-14 14:12:00 +00:00
|
|
|
if (!g_hash_table_contains (priv->objects_hash, object)) {
|
2014-06-30 14:21:30 +00:00
|
|
|
if (in_pending_io) {
|
|
|
|
GST_INFO_OBJECT (comp, "Object %" GST_PTR_FORMAT " was marked"
|
|
|
|
" for addition, removing it from the addition list", object);
|
|
|
|
|
|
|
|
g_hash_table_remove (priv->pending_io, object);
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (comp, "Object %" GST_PTR_FORMAT " is "
|
|
|
|
" not in the composition", object);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_pending_io) {
|
|
|
|
GST_WARNING_OBJECT (comp, "Object %" GST_PTR_FORMAT " is already marked"
|
|
|
|
" for removal", object);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_add (priv->pending_io, object);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-07-02 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_remove_object_action (NleComposition * comp, NleObject * object)
|
2014-07-02 15:33:35 +00:00
|
|
|
{
|
|
|
|
ChildIOData *childio = g_slice_new0 (ChildIOData);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Adding Action");
|
2014-07-10 14:26:48 +00:00
|
|
|
|
2014-07-02 15:33:35 +00:00
|
|
|
childio->comp = comp;
|
|
|
|
childio->object = object;
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_action (comp, G_CALLBACK (_remove_object_func),
|
|
|
|
childio, G_PRIORITY_DEFAULT);
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
static void
|
|
|
|
_add_object_func (NleComposition * comp, ChildIOData * childio)
|
2014-07-02 15:33:35 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object = childio->object;
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
|
|
|
NleObject *in_pending_io;
|
2014-06-30 14:21:30 +00:00
|
|
|
|
|
|
|
in_pending_io = g_hash_table_lookup (priv->pending_io, object);
|
|
|
|
|
2014-07-14 14:12:00 +00:00
|
|
|
if (g_hash_table_contains (priv->objects_hash, object)) {
|
2015-01-12 12:05:30 +00:00
|
|
|
|
|
|
|
if (in_pending_io) {
|
|
|
|
GST_INFO_OBJECT (comp, "Object already in but marked in pendings"
|
|
|
|
" removing from pendings");
|
|
|
|
g_hash_table_remove (priv->pending_io, object);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2014-06-30 14:21:30 +00:00
|
|
|
GST_ERROR_OBJECT (comp, "Object %" GST_PTR_FORMAT " is "
|
|
|
|
" already in the composition", object);
|
2014-07-15 13:16:23 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_pending_io) {
|
|
|
|
GST_WARNING_OBJECT (comp, "Object %" GST_PTR_FORMAT " is already marked"
|
|
|
|
" for addition", object);
|
2014-07-15 13:16:23 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-30 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_hash_table_add (priv->pending_io, object);
|
2014-07-02 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_add_object_action (NleComposition * comp, NleObject * object)
|
2014-07-02 15:33:35 +00:00
|
|
|
{
|
|
|
|
ChildIOData *childio = g_slice_new0 (ChildIOData);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Adding Action");
|
2014-07-10 14:26:48 +00:00
|
|
|
|
2014-07-02 15:33:35 +00:00
|
|
|
childio->comp = comp;
|
|
|
|
childio->object = object;
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_action (comp, G_CALLBACK (_add_object_func), childio,
|
|
|
|
G_PRIORITY_DEFAULT);
|
2014-07-02 15:33:35 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
static void
|
2014-08-20 11:15:30 +00:00
|
|
|
_free_action (Action * action, gpointer udata)
|
|
|
|
{
|
|
|
|
if (ACTION_CALLBACK (action) == _seek_pipeline_func) {
|
|
|
|
SeekData *seekd = (SeekData *) udata;
|
|
|
|
|
|
|
|
gst_event_unref (seekd->event);
|
|
|
|
g_slice_free (SeekData, seekd);
|
|
|
|
} else if (ACTION_CALLBACK (action) == _remove_object_func ||
|
|
|
|
ACTION_CALLBACK (action) == _add_object_func) {
|
|
|
|
g_slice_free (ChildIOData, udata);
|
|
|
|
} else if (ACTION_CALLBACK (action) == _update_pipeline_func ||
|
|
|
|
ACTION_CALLBACK (action) == _commit_func ||
|
|
|
|
ACTION_CALLBACK (action) == _initialize_stack_func) {
|
|
|
|
g_slice_free (UpdateCompositionData, udata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_add_action (NleComposition * comp, GCallback func,
|
|
|
|
gpointer data, gint priority)
|
|
|
|
{
|
|
|
|
Action *action;
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
|
|
|
|
|
|
|
|
|
|
|
action = (Action *) g_closure_new_simple (sizeof (Action), data);
|
|
|
|
g_closure_add_finalize_notifier ((GClosure *) action, data,
|
|
|
|
(GClosureNotify) _free_action);
|
|
|
|
ACTION_CALLBACK (action) = func;
|
|
|
|
action->priority = priority;
|
|
|
|
g_closure_set_marshal ((GClosure *) action, g_cclosure_marshal_VOID__VOID);
|
|
|
|
|
|
|
|
ACTIONS_LOCK (comp);
|
|
|
|
GST_INFO_OBJECT (comp, "Adding Action for function: %p:%s",
|
|
|
|
action, GST_DEBUG_FUNCPTR_NAME (func));
|
|
|
|
|
|
|
|
if (func == G_CALLBACK (_emit_commited_signal_func))
|
|
|
|
priv->actions = g_list_prepend (priv->actions, action);
|
|
|
|
else
|
|
|
|
priv->actions = g_list_append (priv->actions, action);
|
|
|
|
|
|
|
|
SIGNAL_NEW_ACTION (comp);
|
|
|
|
ACTIONS_UNLOCK (comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_add_seek_action (NleComposition * comp, GstEvent * event)
|
|
|
|
{
|
|
|
|
SeekData *seekd = g_slice_new0 (SeekData);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "Adding Action");
|
|
|
|
|
|
|
|
seekd->comp = comp;
|
|
|
|
seekd->event = event;
|
|
|
|
|
|
|
|
comp->priv->next_eos_seqnum = 0;
|
|
|
|
comp->priv->real_eos_seqnum = 0;
|
|
|
|
_add_action (comp, G_CALLBACK (_seek_pipeline_func), seekd,
|
|
|
|
G_PRIORITY_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_remove_update_actions (NleComposition * comp)
|
|
|
|
{
|
|
|
|
_remove_actions_for_type (comp, G_CALLBACK (_update_pipeline_func));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_remove_seek_actions (NleComposition * comp)
|
|
|
|
{
|
|
|
|
_remove_actions_for_type (comp, G_CALLBACK (_seek_pipeline_func));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_add_update_compo_action (NleComposition * comp,
|
|
|
|
GCallback callback, NleUpdateStackReason reason)
|
2014-07-25 08:55:52 +00:00
|
|
|
{
|
|
|
|
UpdateCompositionData *ucompo = g_slice_new0 (UpdateCompositionData);
|
|
|
|
|
|
|
|
ucompo->comp = comp;
|
|
|
|
ucompo->reason = reason;
|
|
|
|
ucompo->seqnum = gst_util_seqnum_next ();
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (comp, "Updating because: %s -- Setting seqnum: %i",
|
|
|
|
UPDATE_PIPELINE_REASONS[reason], ucompo->seqnum);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_action (comp, callback, ucompo, G_PRIORITY_DEFAULT);
|
2014-07-25 08:55:52 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 21:41:45 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_handle_message (GstBin * bin, GstMessage * message)
|
2014-07-29 21:41:45 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp = (NleComposition *) bin;
|
2014-07-29 21:41:45 +00:00
|
|
|
|
|
|
|
if (comp->priv->tearing_down_stack) {
|
|
|
|
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
|
|
|
|
GST_FIXME_OBJECT (comp, "Dropping %" GST_PTR_FORMAT " message from "
|
|
|
|
" %" GST_PTR_FORMAT " being teared down to READY",
|
|
|
|
message, GST_MESSAGE_SRC (message));
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "Dropping message %" GST_PTR_FORMAT " from "
|
|
|
|
"object being teared down to READY!", message);
|
|
|
|
gst_message_unref (message);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BIN_CLASS (parent_class)->handle_message (bin, message);
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_class_init (NleCompositionClass * klass)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBinClass *gstbin_class;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObjectClass *nleobject_class;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbin_class = (GstBinClass *) klass;
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_class = (NleObjectClass *) klass;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (NleCompositionPrivate));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2014-08-15 13:48:14 +00:00
|
|
|
"GNonLin Composition", "Filter/Editor", "Combines NLE objects",
|
2014-07-14 14:24:46 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>, Edward Hervey <bilboed@bilboed.com>,"
|
|
|
|
" Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>,"
|
|
|
|
" Thibault Saunier <tsaunier@gnome.org>");
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (nle_composition_dispose);
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (nle_composition_finalize);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
gstelement_class->change_state = nle_composition_change_state;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
gstbin_class->add_element = GST_DEBUG_FUNCPTR (nle_composition_add_object);
|
2014-10-21 08:35:48 +00:00
|
|
|
gstbin_class->remove_element =
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_FUNCPTR (nle_composition_remove_object);
|
2014-07-29 21:41:45 +00:00
|
|
|
gstbin_class->handle_message =
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_FUNCPTR (nle_composition_handle_message);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2014-08-15 13:48:14 +00:00
|
|
|
gst_static_pad_template_get (&nle_composition_src_template));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* Get the paramspec of the NleObject klass so we can do
|
2014-10-21 08:35:48 +00:00
|
|
|
* fast notifies */
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_START] =
|
2014-10-21 08:35:48 +00:00
|
|
|
g_object_class_find_property (gobject_class, "start");
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_STOP] =
|
2014-10-21 08:35:48 +00:00
|
|
|
g_object_class_find_property (gobject_class, "stop");
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_DURATION] =
|
2014-10-21 08:35:48 +00:00
|
|
|
g_object_class_find_property (gobject_class, "duration");
|
|
|
|
|
2014-06-29 20:35:34 +00:00
|
|
|
_signals[COMMITED_SIGNAL] =
|
|
|
|
g_signal_new ("commited", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
|
|
|
|
0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_BOOLEAN);
|
2014-06-27 14:12:12 +00:00
|
|
|
|
2014-11-04 14:38:05 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2015-01-26 18:25:02 +00:00
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_seek_pipeline_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_remove_object_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_add_object_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_update_pipeline_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_commit_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_emit_commited_signal_func);
|
|
|
|
GST_DEBUG_REGISTER_FUNCPTR (_initialize_stack_func);
|
2014-09-22 16:58:43 +00:00
|
|
|
|
|
|
|
/* Just be useless, so the compiler does not warn us
|
|
|
|
* about our uselessness */
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_class->commit = nle_composition_commit_func;
|
2014-07-11 15:31:34 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_init (NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_OBJECT_FLAG_SET (comp, NLE_OBJECT_SOURCE);
|
|
|
|
GST_OBJECT_FLAG_SET (comp, NLE_OBJECT_COMPOSITION);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
priv = G_TYPE_INSTANCE_GET_PRIVATE (comp, NLE_TYPE_COMPOSITION,
|
|
|
|
NleCompositionPrivate);
|
2014-10-21 08:35:48 +00:00
|
|
|
priv->objects_start = NULL;
|
|
|
|
priv->objects_stop = NULL;
|
|
|
|
|
|
|
|
priv->segment = gst_segment_new ();
|
|
|
|
priv->outside_segment = gst_segment_new ();
|
|
|
|
|
2014-06-27 14:40:19 +00:00
|
|
|
g_rec_mutex_init (&comp->task_rec_lock);
|
|
|
|
|
2014-07-14 14:12:00 +00:00
|
|
|
priv->objects_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
g_mutex_init (&priv->actions_lock);
|
|
|
|
g_cond_init (&priv->actions_cond);
|
2014-06-30 14:21:30 +00:00
|
|
|
|
|
|
|
priv->pending_io = g_hash_table_new (g_direct_hash, g_direct_equal);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
comp->priv = priv;
|
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
priv->current_bin = gst_bin_new ("current-bin");
|
|
|
|
gst_bin_add (GST_BIN (comp), priv->current_bin);
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset (comp);
|
2014-06-24 11:44:13 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
priv->nle_event_pad_func = GST_PAD_EVENTFUNC (NLE_OBJECT_SRC (comp));
|
|
|
|
gst_pad_set_event_function (NLE_OBJECT_SRC (comp),
|
|
|
|
GST_DEBUG_FUNCPTR (nle_composition_event_handler));
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_dispose (GObject * object)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-07-14 14:30:35 +00:00
|
|
|
GList *iter;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp = NLE_COMPOSITION (object);
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (priv->dispose_has_run)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->dispose_has_run = TRUE;
|
|
|
|
|
2014-07-14 14:30:35 +00:00
|
|
|
iter = priv->objects_start;
|
|
|
|
while (iter) {
|
|
|
|
GList *next = iter->next;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_remove_object (comp, iter->data);
|
2014-07-14 14:30:35 +00:00
|
|
|
iter = next;
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 14:30:35 +00:00
|
|
|
g_list_free (priv->objects_stop);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
if (priv->expandables) {
|
2014-07-06 13:46:22 +00:00
|
|
|
GList *iter;
|
|
|
|
|
|
|
|
iter = priv->expandables;
|
|
|
|
|
|
|
|
while (iter) {
|
|
|
|
GList *next = iter->next;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_remove_object (comp, iter->data);
|
2014-07-06 13:46:22 +00:00
|
|
|
iter = next;
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
priv->expandables = NULL;
|
|
|
|
}
|
2014-07-14 14:30:35 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset_target_pad (comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_finalize (GObject * object)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp = NLE_COMPOSITION (object);
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-14 15:47:07 +00:00
|
|
|
_assert_proper_thread (comp);
|
|
|
|
|
2014-07-14 14:30:35 +00:00
|
|
|
if (priv->current) {
|
|
|
|
g_node_destroy (priv->current);
|
|
|
|
priv->current = NULL;
|
2014-07-06 13:46:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
g_hash_table_destroy (priv->objects_hash);
|
|
|
|
|
|
|
|
gst_segment_free (priv->segment);
|
|
|
|
gst_segment_free (priv->outside_segment);
|
|
|
|
|
2014-06-27 14:40:19 +00:00
|
|
|
g_rec_mutex_clear (&comp->task_rec_lock);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2014-06-30 14:29:50 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
g_mutex_clear (&priv->actions_lock);
|
|
|
|
g_cond_clear (&priv->actions_cond);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* signal_duration_change
|
|
|
|
* Creates a new GST_MESSAGE_DURATION_CHANGED with the currently configured
|
|
|
|
* composition duration and sends that on the bus.
|
|
|
|
*/
|
|
|
|
static inline void
|
2014-08-15 13:48:14 +00:00
|
|
|
signal_duration_change (NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (comp),
|
|
|
|
gst_message_new_duration_changed (GST_OBJECT_CAST (comp)));
|
|
|
|
}
|
|
|
|
|
2014-07-03 12:32:18 +00:00
|
|
|
static gboolean
|
|
|
|
_remove_child (GValue * item, GValue * ret G_GNUC_UNUSED, GstBin * bin)
|
|
|
|
{
|
|
|
|
GstElement *child = g_value_get_object (item);
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (child))
|
|
|
|
nle_operation_hard_cleanup (NLE_OPERATION (child));
|
2014-07-09 10:51:36 +00:00
|
|
|
|
|
|
|
|
2014-07-03 12:32:18 +00:00
|
|
|
gst_bin_remove (bin, child);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_empty_bin (GstBin * bin)
|
|
|
|
{
|
|
|
|
GstIterator *children;
|
|
|
|
|
|
|
|
children = gst_bin_iterate_elements (bin);
|
|
|
|
|
|
|
|
while (G_UNLIKELY (gst_iterator_fold (children,
|
|
|
|
(GstIteratorFoldFunction) _remove_child, NULL,
|
|
|
|
bin) == GST_ITERATOR_RESYNC)) {
|
|
|
|
gst_iterator_resync (children);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_iterator_free (children);
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset (NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "resetting");
|
|
|
|
|
2014-07-14 15:47:07 +00:00
|
|
|
_assert_proper_thread (comp);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
priv->segment_start = GST_CLOCK_TIME_NONE;
|
|
|
|
priv->segment_stop = GST_CLOCK_TIME_NONE;
|
|
|
|
priv->next_base_time = 0;
|
|
|
|
|
|
|
|
gst_segment_init (priv->segment, GST_FORMAT_TIME);
|
|
|
|
gst_segment_init (priv->outside_segment, GST_FORMAT_TIME);
|
|
|
|
|
|
|
|
if (priv->current)
|
|
|
|
g_node_destroy (priv->current);
|
|
|
|
priv->current = NULL;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset_target_pad (comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-30 13:12:38 +00:00
|
|
|
priv->initialized = FALSE;
|
2014-10-21 08:35:48 +00:00
|
|
|
priv->send_stream_start = TRUE;
|
2014-07-10 13:43:26 +00:00
|
|
|
priv->real_eos_seqnum = 0;
|
2014-07-11 17:13:29 +00:00
|
|
|
priv->next_eos_seqnum = 0;
|
2014-07-11 13:41:50 +00:00
|
|
|
priv->flush_seqnum = 0;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-03 12:32:18 +00:00
|
|
|
_empty_bin (GST_BIN_CAST (priv->current_bin));
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Composition now resetted");
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadProbeReturn
|
|
|
|
ghost_event_probe_handler (GstPad * ghostpad G_GNUC_UNUSED,
|
2014-08-15 13:48:14 +00:00
|
|
|
GstPadProbeInfo * info, NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
GstPadProbeReturn retval = GST_PAD_PROBE_OK;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-09-23 13:01:56 +00:00
|
|
|
GstEvent *event;
|
|
|
|
|
|
|
|
if (GST_IS_BUFFER (info->data)) {
|
2014-11-25 18:14:59 +00:00
|
|
|
if (priv->waiting_for_buffer) {
|
|
|
|
GST_INFO_OBJECT (comp, "update_pipeline DONE");
|
2014-09-23 13:01:56 +00:00
|
|
|
_restart_task (comp);
|
2014-11-25 18:14:59 +00:00
|
|
|
}
|
2014-09-23 13:01:56 +00:00
|
|
|
|
|
|
|
return GST_PAD_PROBE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
event = GST_PAD_PROBE_INFO_EVENT (info);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "event: %s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2014-09-19 10:49:52 +00:00
|
|
|
if (_is_ready_to_restart_task (comp, event))
|
|
|
|
_restart_task (comp);
|
|
|
|
|
2014-07-11 13:41:50 +00:00
|
|
|
if (gst_event_get_seqnum (event) != comp->priv->flush_seqnum) {
|
2014-09-19 10:49:52 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Dropping flush stop %d -- %d",
|
|
|
|
gst_event_get_seqnum (event), priv->seqnum_to_restart_task);
|
2014-07-11 13:41:50 +00:00
|
|
|
retval = GST_PAD_PROBE_DROP;
|
|
|
|
} else {
|
2014-07-14 15:06:05 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Forwarding our flush stop with seqnum %i",
|
2014-07-11 14:08:20 +00:00
|
|
|
comp->priv->flush_seqnum);
|
2014-07-15 00:37:25 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
event = gst_event_new_flush_stop (TRUE);
|
|
|
|
GST_PAD_PROBE_INFO_DATA (info) = event;
|
|
|
|
gst_event_set_seqnum (event, comp->priv->flush_seqnum);
|
2014-07-11 13:41:50 +00:00
|
|
|
comp->priv->flush_seqnum = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
if (gst_event_get_seqnum (event) != comp->priv->flush_seqnum) {
|
2014-07-14 15:06:05 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Dropping flush start");
|
2014-07-11 13:41:50 +00:00
|
|
|
retval = GST_PAD_PROBE_DROP;
|
|
|
|
} else {
|
2014-07-14 15:06:05 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Forwarding our flush start with seqnum %i",
|
2014-07-11 14:08:20 +00:00
|
|
|
comp->priv->flush_seqnum);
|
2014-07-11 13:41:50 +00:00
|
|
|
}
|
2014-10-21 08:35:48 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_STREAM_START:
|
|
|
|
if (g_atomic_int_compare_and_exchange (&priv->send_stream_start, TRUE,
|
|
|
|
FALSE)) {
|
|
|
|
/* FIXME: Do we want to create a new stream ID here? */
|
|
|
|
GST_DEBUG_OBJECT (comp, "forward stream-start %p", event);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (comp, "dropping stream-start %p", event);
|
|
|
|
retval = GST_PAD_PROBE_DROP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
{
|
|
|
|
guint64 rstart, rstop;
|
|
|
|
const GstSegment *segment;
|
|
|
|
GstSegment copy;
|
|
|
|
GstEvent *event2;
|
|
|
|
/* next_base_time */
|
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
if (_is_ready_to_restart_task (comp, event))
|
|
|
|
_restart_task (comp);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
gst_segment_copy_into (segment, ©);
|
|
|
|
|
|
|
|
rstart =
|
|
|
|
gst_segment_to_running_time (segment, GST_FORMAT_TIME,
|
|
|
|
segment->start);
|
|
|
|
rstop =
|
|
|
|
gst_segment_to_running_time (segment, GST_FORMAT_TIME, segment->stop);
|
|
|
|
copy.base = comp->priv->next_base_time;
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Updating base time to %" GST_TIME_FORMAT ", next:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (comp->priv->next_base_time),
|
|
|
|
GST_TIME_ARGS (comp->priv->next_base_time + rstop - rstart));
|
|
|
|
comp->priv->next_base_time += rstop - rstart;
|
|
|
|
|
|
|
|
event2 = gst_event_new_segment (©);
|
|
|
|
GST_EVENT_SEQNUM (event2) = GST_EVENT_SEQNUM (event);
|
2014-07-04 09:05:41 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_PAD_PROBE_INFO_DATA (info) = event2;
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
{
|
2014-07-04 09:05:41 +00:00
|
|
|
gint seqnum = gst_event_get_seqnum (event);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Got EOS, last EOS seqnum id : %i current "
|
2014-07-04 09:05:41 +00:00
|
|
|
"seq num is: %i", comp->priv->real_eos_seqnum, seqnum);
|
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
if (_is_ready_to_restart_task (comp, event)) {
|
2014-07-08 20:53:57 +00:00
|
|
|
GST_INFO_OBJECT (comp, "We got an EOS right after seeing the right"
|
|
|
|
" segment, restarting task");
|
2014-07-25 08:55:52 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
_restart_task (comp);
|
2014-07-08 20:53:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
if (g_atomic_int_compare_and_exchange (&comp->priv->real_eos_seqnum,
|
|
|
|
seqnum, 1)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-11 14:08:20 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Got EOS for real, seq ID is %i, fowarding it",
|
|
|
|
seqnum);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
return GST_PAD_PROBE_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-11 17:13:29 +00:00
|
|
|
if (priv->next_eos_seqnum == seqnum)
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_update_compo_action (comp, G_CALLBACK (_update_pipeline_func),
|
2014-07-25 08:55:52 +00:00
|
|
|
COMP_UPDATE_STACK_ON_EOS);
|
2014-07-11 17:13:29 +00:00
|
|
|
else
|
|
|
|
GST_INFO_OBJECT (comp,
|
|
|
|
"Got an EOS but it seqnum %i != next eos seqnum %i", seqnum,
|
|
|
|
priv->next_eos_seqnum);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
retval = GST_PAD_PROBE_DROP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2014-08-15 13:48:14 +00:00
|
|
|
priority_comp (NleObject * a, NleObject * b)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
if (a->priority < b->priority)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (a->priority > b->priority)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
have_to_update_pipeline (NleComposition * comp,
|
|
|
|
NleUpdateStackReason update_stack_reason)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-11 16:27:25 +00:00
|
|
|
if (update_stack_reason == COMP_UPDATE_STACK_ON_EOS)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"segment[%" GST_TIME_FORMAT "--%" GST_TIME_FORMAT "] current[%"
|
|
|
|
GST_TIME_FORMAT "--%" GST_TIME_FORMAT "]",
|
|
|
|
GST_TIME_ARGS (priv->segment->start),
|
|
|
|
GST_TIME_ARGS (priv->segment->stop),
|
|
|
|
GST_TIME_ARGS (priv->segment_start), GST_TIME_ARGS (priv->segment_stop));
|
|
|
|
|
|
|
|
if (priv->segment->start < priv->segment_start)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (priv->segment->start >= priv->segment_stop)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_commit_func (NleObject * object, gboolean recurse)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_update_compo_action (NLE_COMPOSITION (object),
|
|
|
|
G_CALLBACK (_commit_func), COMP_UPDATE_STACK_ON_COMMIT);
|
2014-07-14 15:06:05 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_new_seek_event:
|
|
|
|
*
|
|
|
|
* Returns a seek event for the currently configured segment
|
|
|
|
* and start/stop values
|
|
|
|
*
|
|
|
|
* The GstSegment and segment_start|stop must have been configured
|
|
|
|
* before calling this function.
|
|
|
|
*/
|
|
|
|
static GstEvent *
|
2014-08-15 13:48:14 +00:00
|
|
|
get_new_seek_event (NleComposition * comp, gboolean initial,
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean updatestoponly)
|
|
|
|
{
|
|
|
|
GstSeekFlags flags = GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstSeekType starttype = GST_SEEK_TYPE_SET;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "initial:%d", initial);
|
|
|
|
/* remove the seek flag */
|
|
|
|
if (!initial)
|
|
|
|
flags |= (GstSeekFlags) priv->segment->flags;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"private->segment->start:%" GST_TIME_FORMAT " segment_start%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (priv->segment->start),
|
|
|
|
GST_TIME_ARGS (priv->segment_start));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"private->segment->stop:%" GST_TIME_FORMAT " segment_stop%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (priv->segment->stop),
|
|
|
|
GST_TIME_ARGS (priv->segment_stop));
|
|
|
|
|
2015-02-03 11:02:42 +00:00
|
|
|
start = GST_CLOCK_TIME_IS_VALID (priv->segment->start)
|
|
|
|
? MAX (priv->segment->start, priv->segment_start)
|
|
|
|
: priv->segment_start;
|
2014-10-21 08:35:48 +00:00
|
|
|
stop = GST_CLOCK_TIME_IS_VALID (priv->segment->stop)
|
|
|
|
? MIN (priv->segment->stop, priv->segment_stop)
|
|
|
|
: priv->segment_stop;
|
|
|
|
|
|
|
|
if (updatestoponly) {
|
|
|
|
starttype = GST_SEEK_TYPE_NONE;
|
|
|
|
start = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Created new seek event. Flags:%d, start:%" GST_TIME_FORMAT ", stop:%"
|
|
|
|
GST_TIME_FORMAT ", rate:%lf", flags, GST_TIME_ARGS (start),
|
|
|
|
GST_TIME_ARGS (stop), priv->segment->rate);
|
|
|
|
|
|
|
|
return gst_event_new_seek (priv->segment->rate,
|
|
|
|
priv->segment->format, flags, starttype, start, GST_SEEK_TYPE_SET, stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OBJECTS LOCK must be taken when calling this ! */
|
|
|
|
static GstClockTime
|
2014-08-15 13:48:14 +00:00
|
|
|
get_current_position (NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
GstPad *pad;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *obj;
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean res;
|
|
|
|
gint64 value = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2014-11-04 14:38:05 +00:00
|
|
|
GstPad *peer;
|
2014-06-24 11:44:13 +00:00
|
|
|
|
2014-11-04 14:38:05 +00:00
|
|
|
g_signal_emit (comp, _signals[QUERY_POSITION_SIGNAL], 0, &value);
|
|
|
|
|
|
|
|
if (value >= 0) {
|
|
|
|
GST_DEBUG_OBJECT (comp, "Got position %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (value));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-11-04 14:38:05 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try querying position downstream */
|
|
|
|
peer = gst_pad_get_peer (NLE_OBJECT (comp)->srcpad);
|
2014-06-24 11:44:13 +00:00
|
|
|
if (peer) {
|
|
|
|
res = gst_pad_query_position (peer, GST_FORMAT_TIME, &value);
|
|
|
|
gst_object_unref (peer);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
if (res) {
|
2014-07-14 15:06:05 +00:00
|
|
|
GST_DEBUG_OBJECT (comp,
|
2014-06-24 11:44:13 +00:00
|
|
|
"Successfully got downstream position %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS ((guint64) value));
|
|
|
|
goto beach;
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
2014-06-24 11:44:13 +00:00
|
|
|
}
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Downstream position query failed");
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
/* resetting format/value */
|
|
|
|
value = GST_CLOCK_TIME_NONE;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-25 17:17:55 +00:00
|
|
|
/* If downstream fails , try within the current stack */
|
2014-10-21 08:35:48 +00:00
|
|
|
if (!priv->current) {
|
|
|
|
GST_DEBUG_OBJECT (comp, "No current stack, can't send query");
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
obj = (NleObject *) priv->current->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
pad = NLE_OBJECT_SRC (obj);
|
2014-10-21 08:35:48 +00:00
|
|
|
res = gst_pad_query_position (pad, GST_FORMAT_TIME, &value);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (res == FALSE)) {
|
2014-06-24 11:44:13 +00:00
|
|
|
GST_WARNING_OBJECT (comp, "query position failed");
|
2014-10-21 08:35:48 +00:00
|
|
|
value = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (comp, "Query returned %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS ((guint64) value));
|
|
|
|
}
|
|
|
|
|
|
|
|
beach:
|
2014-07-07 20:58:27 +00:00
|
|
|
|
2014-09-25 12:53:36 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (value)) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (comp->priv->segment_start)) {
|
|
|
|
value = comp->priv->segment_start;
|
|
|
|
} else {
|
|
|
|
GST_INFO_OBJECT (comp, "Current position is unknown, " "setting it to 0");
|
2014-07-07 20:58:27 +00:00
|
|
|
|
2014-09-25 12:53:36 +00:00
|
|
|
value = 0;
|
|
|
|
}
|
2014-07-07 20:58:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
return (guint64) value;
|
|
|
|
}
|
|
|
|
|
2014-07-14 15:06:05 +00:00
|
|
|
/* WITH OBJECTS LOCK TAKEN */
|
2014-10-21 08:35:48 +00:00
|
|
|
static gboolean
|
|
|
|
update_base_time (GNode * node, GstClockTime * timestamp)
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (node->data))
|
|
|
|
nle_operation_update_base_time (NLE_OPERATION (node->data), *timestamp);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WITH OBJECTS LOCK TAKEN */
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
update_operations_base_time (NleComposition * comp, gboolean reverse)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
timestamp = comp->priv->segment->stop;
|
|
|
|
else
|
|
|
|
timestamp = comp->priv->segment->start;
|
|
|
|
|
|
|
|
g_node_traverse (comp->priv->current, G_IN_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
(GNodeTraverseFunc) update_base_time, ×tamp);
|
|
|
|
}
|
|
|
|
|
2014-07-14 15:06:05 +00:00
|
|
|
/* WITH OBJECTS LOCK TAKEN */
|
2014-07-10 13:48:50 +00:00
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_seek_current_stack (NleComposition * comp, GstEvent * event,
|
2014-07-15 12:59:54 +00:00
|
|
|
gboolean flush_downstream)
|
2014-07-10 13:48:50 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
|
|
|
GstPad *peer = gst_pad_get_peer (NLE_OBJECT_SRC (comp));
|
2014-07-10 13:48:50 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (comp, "Seeking itself %" GST_PTR_FORMAT, event);
|
|
|
|
|
2014-07-15 00:37:25 +00:00
|
|
|
if (flush_downstream) {
|
|
|
|
priv->flush_seqnum = gst_event_get_seqnum (event);
|
2014-10-22 11:49:27 +00:00
|
|
|
GST_INFO_OBJECT (comp, "sending flushes downstream with seqnum %d",
|
2014-07-15 00:37:25 +00:00
|
|
|
priv->flush_seqnum);
|
|
|
|
}
|
2014-07-11 13:41:50 +00:00
|
|
|
|
2014-07-10 13:48:50 +00:00
|
|
|
priv->seeking_itself = TRUE;
|
|
|
|
res = gst_pad_push_event (peer, event);
|
|
|
|
priv->seeking_itself = FALSE;
|
|
|
|
gst_object_unref (peer);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "Done seeking");
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
/*
|
|
|
|
Figures out if pipeline needs updating.
|
|
|
|
Updates it and sends the seek event.
|
|
|
|
Sends flush events downstream if needed.
|
|
|
|
can be called by user_seek or segment_done
|
|
|
|
|
2014-07-14 15:06:05 +00:00
|
|
|
update_stack_reason: The reason for which we need to handle 'seek'
|
2014-10-21 08:35:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
seek_handling (NleComposition * comp, gint32 seqnum,
|
|
|
|
NleUpdateStackReason update_stack_reason)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-07-25 08:55:52 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Seek hanlding update pipeline reason: %s",
|
2014-07-11 16:27:25 +00:00
|
|
|
UPDATE_PIPELINE_REASONS[update_stack_reason]);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-11 16:27:25 +00:00
|
|
|
if (have_to_update_pipeline (comp, update_stack_reason)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
if (comp->priv->segment->rate >= 0.0)
|
2014-07-25 08:55:52 +00:00
|
|
|
update_pipeline (comp, comp->priv->segment->start, seqnum,
|
|
|
|
update_stack_reason);
|
2014-10-21 08:35:48 +00:00
|
|
|
else
|
2014-07-25 08:55:52 +00:00
|
|
|
update_pipeline (comp, comp->priv->segment->stop, seqnum,
|
|
|
|
update_stack_reason);
|
2014-10-21 08:35:48 +00:00
|
|
|
} else {
|
2014-07-10 16:01:32 +00:00
|
|
|
GstEvent *toplevel_seek = get_new_seek_event (comp, FALSE, FALSE);
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
gst_event_set_seqnum (toplevel_seek, seqnum);
|
2014-07-10 16:01:32 +00:00
|
|
|
_set_real_eos_seqnum_from_seek (comp, toplevel_seek);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_update_actions (comp);
|
2014-09-26 16:28:16 +00:00
|
|
|
update_operations_base_time (comp, !(comp->priv->segment->rate >= 0.0));
|
2014-07-15 12:59:54 +00:00
|
|
|
_seek_current_stack (comp, toplevel_seek,
|
2014-07-15 13:01:59 +00:00
|
|
|
_have_to_flush_downstream (update_stack_reason));
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_event_handler (GstPad * ghostpad, GstObject * parent,
|
2014-10-21 08:35:48 +00:00
|
|
|
GstEvent * event)
|
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp = (NleComposition *) parent;
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
gboolean res = TRUE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "event type:%s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2014-07-03 14:46:21 +00:00
|
|
|
if (!priv->seeking_itself) {
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_seek_action (comp, event);
|
2014-07-03 14:46:21 +00:00
|
|
|
event = NULL;
|
|
|
|
GST_FIXME_OBJECT (comp, "HANDLE seeking errors!");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
case GST_EVENT_QOS:
|
|
|
|
{
|
|
|
|
gdouble prop;
|
|
|
|
GstQOSType qostype;
|
|
|
|
GstClockTimeDiff diff;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
gst_event_parse_qos (event, &qostype, &prop, &diff, ×tamp);
|
|
|
|
|
2014-07-15 13:17:43 +00:00
|
|
|
GST_DEBUG_OBJECT (comp,
|
2014-10-21 08:35:48 +00:00
|
|
|
"timestamp:%" GST_TIME_FORMAT " segment.start:%" GST_TIME_FORMAT
|
|
|
|
" segment.stop:%" GST_TIME_FORMAT " segment_start%" GST_TIME_FORMAT
|
|
|
|
" segment_stop:%" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (priv->outside_segment->start),
|
|
|
|
GST_TIME_ARGS (priv->outside_segment->stop),
|
|
|
|
GST_TIME_ARGS (priv->segment_start),
|
|
|
|
GST_TIME_ARGS (priv->segment_stop));
|
|
|
|
|
|
|
|
/* The problem with QoS events is the following:
|
|
|
|
* At each new internal segment (i.e. when we re-arrange our internal
|
|
|
|
* elements) we send flushing seeks to those elements (to properly
|
|
|
|
* configure their playback range) but don't let the FLUSH events get
|
|
|
|
* downstream.
|
|
|
|
*
|
|
|
|
* The problem is that the QoS running timestamps we receive from
|
|
|
|
* downstream will not have taken into account those flush.
|
|
|
|
*
|
|
|
|
* What we need to do is to translate to our internal running timestamps
|
|
|
|
* which for each configured segment starts at 0 for those elements.
|
|
|
|
*
|
|
|
|
* The generic algorithm for the incoming running timestamp translation
|
|
|
|
* is therefore:
|
|
|
|
* (original_seek_time : original seek position received from usptream)
|
|
|
|
* (current_segment_start : Start position of the currently configured
|
|
|
|
* timeline segment)
|
|
|
|
*
|
|
|
|
* difference = original_seek_time - current_segment_start
|
|
|
|
* new_qos_position = upstream_qos_position - difference
|
|
|
|
*
|
|
|
|
* The new_qos_position is only valid when:
|
|
|
|
* * it applies to the current segment (difference > 0)
|
|
|
|
* * The QoS difference + timestamp is greater than the difference
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (priv->outside_segment->start)) {
|
|
|
|
GstClockTimeDiff curdiff;
|
|
|
|
|
|
|
|
/* We'll either create a new event or discard it */
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
if (priv->segment->rate < 0.0)
|
|
|
|
curdiff = priv->outside_segment->stop - priv->segment_stop;
|
|
|
|
else
|
|
|
|
curdiff = priv->segment_start - priv->outside_segment->start;
|
|
|
|
GST_DEBUG ("curdiff %" GST_TIME_FORMAT, GST_TIME_ARGS (curdiff));
|
|
|
|
if ((curdiff != 0) && ((timestamp < curdiff)
|
|
|
|
|| (curdiff > timestamp + diff))) {
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"QoS event outside of current segment, discarding");
|
|
|
|
/* The QoS timestamp is before the currently set-up pipeline */
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Substract the amount of running time we've already outputted
|
|
|
|
* until the currently configured pipeline from the QoS timestamp.*/
|
|
|
|
timestamp -= curdiff;
|
2014-07-15 13:17:43 +00:00
|
|
|
GST_DEBUG_OBJECT (comp,
|
2014-10-21 08:35:48 +00:00
|
|
|
"Creating new QoS event with timestamp %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timestamp));
|
|
|
|
event = gst_event_new_qos (qostype, prop, diff, timestamp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
if (res) {
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "About to call nle_event_pad_func: %p",
|
|
|
|
priv->nle_event_pad_func);
|
|
|
|
res = priv->nle_event_pad_func (NLE_OBJECT (comp)->srcpad, parent, event);
|
|
|
|
GST_DEBUG_OBJECT (comp, "Done calling nle_event_pad_func() %d", res);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
beach:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
static inline void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset_target_pad (NleComposition * comp)
|
2014-06-24 11:44:13 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-06-24 11:44:13 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "Removing ghostpad");
|
|
|
|
|
|
|
|
if (priv->ghosteventprobe) {
|
|
|
|
GstPad *target;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
target = gst_ghost_pad_get_target ((GstGhostPad *) NLE_OBJECT_SRC (comp));
|
2014-06-24 11:44:13 +00:00
|
|
|
if (target)
|
|
|
|
gst_pad_remove_probe (target, priv->ghosteventprobe);
|
|
|
|
priv->ghosteventprobe = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_ghost_pad_set_target (NLE_OBJECT (comp),
|
|
|
|
NLE_OBJECT_SRC (comp), NULL);
|
2014-06-24 11:44:13 +00:00
|
|
|
priv->send_stream_start = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* nle_composition_ghost_pad_set_target:
|
2014-10-21 08:35:48 +00:00
|
|
|
* target: The target #GstPad. The refcount will be decremented (given to the ghostpad).
|
|
|
|
*/
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_ghost_pad_set_target (NleComposition * comp, GstPad * target)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-06-24 11:44:13 +00:00
|
|
|
GstPad *ptarget;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (target)
|
2014-06-24 11:44:13 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "target:%s:%s", GST_DEBUG_PAD_NAME (target));
|
2014-10-21 08:35:48 +00:00
|
|
|
else
|
2014-06-24 11:44:13 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Removing target");
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
|
2014-06-24 11:44:13 +00:00
|
|
|
ptarget =
|
2014-08-15 13:48:14 +00:00
|
|
|
gst_ghost_pad_get_target (GST_GHOST_PAD (NLE_OBJECT (comp)->srcpad));
|
2014-07-14 15:06:05 +00:00
|
|
|
if (ptarget) {
|
2014-06-24 11:44:13 +00:00
|
|
|
gst_object_unref (ptarget);
|
2014-07-14 15:06:05 +00:00
|
|
|
|
|
|
|
if (ptarget == target) {
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Target of srcpad is the same as existing one, not changing");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-24 11:44:13 +00:00
|
|
|
}
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* Actually set the target */
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_ghost_pad_set_target ((NleObject *) comp,
|
|
|
|
NLE_OBJECT (comp)->srcpad, target);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (target && (priv->ghosteventprobe == 0)) {
|
|
|
|
priv->ghosteventprobe =
|
|
|
|
gst_pad_add_probe (target,
|
2014-09-23 13:01:56 +00:00
|
|
|
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | GST_PAD_PROBE_TYPE_EVENT_FLUSH |
|
|
|
|
GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
|
2014-10-21 08:35:48 +00:00
|
|
|
(GstPadProbeCallback) ghost_event_probe_handler, comp, NULL);
|
|
|
|
GST_DEBUG_OBJECT (comp, "added event probe %lu", priv->ghosteventprobe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
refine_start_stop_in_region_above_priority (NleComposition * composition,
|
2014-10-21 08:35:48 +00:00
|
|
|
GstClockTime timestamp, GstClockTime start,
|
|
|
|
GstClockTime stop,
|
|
|
|
GstClockTime * rstart, GstClockTime * rstop, guint32 priority)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object;
|
2014-10-21 08:35:48 +00:00
|
|
|
GstClockTime nstart = start, nstop = stop;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (composition,
|
|
|
|
"timestamp:%" GST_TIME_FORMAT " start: %" GST_TIME_FORMAT " stop: %"
|
|
|
|
GST_TIME_FORMAT " priority:%u", GST_TIME_ARGS (timestamp),
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop), priority);
|
|
|
|
|
|
|
|
for (tmp = composition->priv->objects_start; tmp; tmp = tmp->next) {
|
2014-08-15 13:48:14 +00:00
|
|
|
object = (NleObject *) tmp->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (object, "START %" GST_TIME_FORMAT "--%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (object->start), GST_TIME_ARGS (object->stop));
|
|
|
|
|
2015-07-08 16:59:33 +00:00
|
|
|
if ((object->priority >= priority) || (!NLE_OBJECT_ACTIVE (object)))
|
2014-10-21 08:35:48 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (object->start <= timestamp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (object->start >= nstop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nstop = object->start;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (composition,
|
|
|
|
"START Found %s [prio:%u] at %" GST_TIME_FORMAT,
|
|
|
|
GST_OBJECT_NAME (object), object->priority,
|
|
|
|
GST_TIME_ARGS (object->start));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tmp = composition->priv->objects_stop; tmp; tmp = tmp->next) {
|
2014-08-15 13:48:14 +00:00
|
|
|
object = (NleObject *) tmp->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (object, "STOP %" GST_TIME_FORMAT "--%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (object->start), GST_TIME_ARGS (object->stop));
|
|
|
|
|
2015-07-08 16:59:33 +00:00
|
|
|
if ((object->priority >= priority) || (!NLE_OBJECT_ACTIVE (object)))
|
2014-10-21 08:35:48 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (object->stop >= timestamp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (object->stop <= nstart)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nstart = object->stop;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (composition,
|
|
|
|
"STOP Found %s [prio:%u] at %" GST_TIME_FORMAT,
|
|
|
|
GST_OBJECT_NAME (object), object->priority,
|
|
|
|
GST_TIME_ARGS (object->start));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*rstart)
|
|
|
|
*rstart = nstart;
|
|
|
|
|
|
|
|
if (*rstop)
|
|
|
|
*rstop = nstop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts a sorted list to a tree
|
|
|
|
* Recursive
|
|
|
|
*
|
|
|
|
* stack will be set to the next item to use in the parent.
|
|
|
|
* If operations number of sinks is limited, it will only use that number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GNode *
|
|
|
|
convert_list_to_tree (GList ** stack, GstClockTime * start,
|
|
|
|
GstClockTime * stop, guint32 * highprio)
|
|
|
|
{
|
|
|
|
GNode *ret;
|
|
|
|
guint nbsinks;
|
|
|
|
gboolean limit;
|
|
|
|
GList *tmp;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (!stack || !*stack)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
object = (NleObject *) (*stack)->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("object:%s , *start:%" GST_TIME_FORMAT ", *stop:%"
|
|
|
|
GST_TIME_FORMAT " highprio:%d",
|
|
|
|
GST_ELEMENT_NAME (object), GST_TIME_ARGS (*start),
|
|
|
|
GST_TIME_ARGS (*stop), *highprio);
|
|
|
|
|
|
|
|
/* update earliest stop */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (*stop)) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (object->stop) && (*stop > object->stop))
|
|
|
|
*stop = object->stop;
|
|
|
|
} else {
|
|
|
|
*stop = object->stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (*start)) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (object->start) && (*start < object->start))
|
|
|
|
*start = object->start;
|
|
|
|
} else {
|
|
|
|
*start = object->start;
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_OBJECT_IS_SOURCE (object)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
*stack = g_list_next (*stack);
|
|
|
|
|
|
|
|
/* update highest priority.
|
|
|
|
* We do this here, since it's only used with sources (leafs of the tree) */
|
|
|
|
if (object->priority > *highprio)
|
|
|
|
*highprio = object->priority;
|
|
|
|
|
|
|
|
ret = g_node_new (object);
|
|
|
|
|
|
|
|
goto beach;
|
|
|
|
} else {
|
2014-08-15 13:48:14 +00:00
|
|
|
/* NleOperation */
|
|
|
|
NleOperation *oper = (NleOperation *) object;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (oper, "operation, num_sinks:%d", oper->num_sinks);
|
|
|
|
|
|
|
|
ret = g_node_new (object);
|
|
|
|
limit = (oper->dynamicsinks == FALSE);
|
|
|
|
nbsinks = oper->num_sinks;
|
|
|
|
|
|
|
|
/* FIXME : if num_sinks == -1 : request the proper number of pads */
|
|
|
|
for (tmp = g_list_next (*stack); tmp && (!limit || nbsinks);) {
|
|
|
|
g_node_append (ret, convert_list_to_tree (&tmp, start, stop, highprio));
|
|
|
|
if (limit)
|
|
|
|
nbsinks--;
|
|
|
|
}
|
|
|
|
|
|
|
|
*stack = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
beach:
|
|
|
|
GST_DEBUG_OBJECT (object,
|
|
|
|
"*start:%" GST_TIME_FORMAT " *stop:%" GST_TIME_FORMAT
|
|
|
|
" priority:%u", GST_TIME_ARGS (*start), GST_TIME_ARGS (*stop), *highprio);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_stack_list:
|
2014-08-15 13:48:14 +00:00
|
|
|
* @comp: The #NleComposition
|
2014-10-21 08:35:48 +00:00
|
|
|
* @timestamp: The #GstClockTime to look at
|
|
|
|
* @priority: The priority level to start looking from
|
|
|
|
* @activeonly: Only look for active elements if TRUE
|
|
|
|
* @start: The biggest start time of the objects in the stack
|
|
|
|
* @stop: The smallest stop time of the objects in the stack
|
|
|
|
* @highprio: The highest priority in the stack
|
|
|
|
*
|
|
|
|
* Not MT-safe, you should take the objects lock before calling it.
|
|
|
|
* Returns: A tree of #GNode sorted in priority order, corresponding
|
|
|
|
* to the given search arguments. The returned value can be #NULL.
|
|
|
|
*
|
|
|
|
* WITH OBJECTS LOCK TAKEN
|
|
|
|
*/
|
|
|
|
static GNode *
|
2014-08-15 13:48:14 +00:00
|
|
|
get_stack_list (NleComposition * comp, GstClockTime timestamp,
|
2014-10-21 08:35:48 +00:00
|
|
|
guint32 priority, gboolean activeonly, GstClockTime * start,
|
|
|
|
GstClockTime * stop, guint * highprio)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GList *stack = NULL;
|
|
|
|
GNode *ret = NULL;
|
|
|
|
GstClockTime nstart = GST_CLOCK_TIME_NONE;
|
|
|
|
GstClockTime nstop = GST_CLOCK_TIME_NONE;
|
|
|
|
GstClockTime first_out_of_stack = GST_CLOCK_TIME_NONE;
|
|
|
|
guint32 highest = 0;
|
|
|
|
gboolean reverse = (comp->priv->segment->rate < 0.0);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"timestamp:%" GST_TIME_FORMAT ", priority:%u, activeonly:%d",
|
|
|
|
GST_TIME_ARGS (timestamp), priority, activeonly);
|
|
|
|
|
|
|
|
GST_LOG ("objects_start:%p objects_stop:%p", comp->priv->objects_start,
|
|
|
|
comp->priv->objects_stop);
|
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
for (tmp = comp->priv->objects_stop; tmp; tmp = g_list_next (tmp)) {
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object = (NleObject *) tmp->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (object,
|
|
|
|
"start: %" GST_TIME_FORMAT ", stop:%" GST_TIME_FORMAT " , duration:%"
|
|
|
|
GST_TIME_FORMAT ", priority:%u, active:%d",
|
|
|
|
GST_TIME_ARGS (object->start), GST_TIME_ARGS (object->stop),
|
|
|
|
GST_TIME_ARGS (object->duration), object->priority, object->active);
|
|
|
|
|
|
|
|
if (object->stop >= timestamp) {
|
|
|
|
if ((object->start < timestamp) &&
|
|
|
|
(object->priority >= priority) &&
|
2015-07-08 16:59:33 +00:00
|
|
|
((!activeonly) || (NLE_OBJECT_ACTIVE (object)))) {
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_LOG_OBJECT (comp, "adding %s: sorted to the stack",
|
|
|
|
GST_OBJECT_NAME (object));
|
|
|
|
stack = g_list_insert_sorted (stack, object,
|
|
|
|
(GCompareFunc) priority_comp);
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (object))
|
|
|
|
nle_operation_update_base_time (NLE_OPERATION (object), timestamp);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (comp, "too far, stopping iteration");
|
|
|
|
first_out_of_stack = object->stop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (tmp = comp->priv->objects_start; tmp; tmp = g_list_next (tmp)) {
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object = (NleObject *) tmp->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (object,
|
|
|
|
"start: %" GST_TIME_FORMAT " , stop:%" GST_TIME_FORMAT " , duration:%"
|
|
|
|
GST_TIME_FORMAT ", priority:%u", GST_TIME_ARGS (object->start),
|
|
|
|
GST_TIME_ARGS (object->stop), GST_TIME_ARGS (object->duration),
|
|
|
|
object->priority);
|
|
|
|
|
|
|
|
if (object->start <= timestamp) {
|
|
|
|
if ((object->stop > timestamp) &&
|
|
|
|
(object->priority >= priority) &&
|
2015-07-08 16:59:33 +00:00
|
|
|
((!activeonly) || (NLE_OBJECT_ACTIVE (object)))) {
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_LOG_OBJECT (comp, "adding %s: sorted to the stack",
|
|
|
|
GST_OBJECT_NAME (object));
|
|
|
|
stack = g_list_insert_sorted (stack, object,
|
|
|
|
(GCompareFunc) priority_comp);
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (object))
|
|
|
|
nle_operation_update_base_time (NLE_OPERATION (object), timestamp);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (comp, "too far, stopping iteration");
|
|
|
|
first_out_of_stack = object->start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the expandables */
|
2014-08-15 13:48:14 +00:00
|
|
|
if (G_LIKELY (timestamp < NLE_OBJECT_STOP (comp)))
|
2014-10-21 08:35:48 +00:00
|
|
|
for (tmp = comp->priv->expandables; tmp; tmp = tmp->next) {
|
|
|
|
GST_DEBUG_OBJECT (comp, "Adding expandable %s sorted to the list",
|
|
|
|
GST_OBJECT_NAME (tmp->data));
|
|
|
|
stack = g_list_insert_sorted (stack, tmp->data,
|
|
|
|
(GCompareFunc) priority_comp);
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (tmp->data))
|
|
|
|
nle_operation_update_base_time (NLE_OPERATION (tmp->data), timestamp);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert that list to a stack */
|
|
|
|
tmp = stack;
|
|
|
|
ret = convert_list_to_tree (&tmp, &nstart, &nstop, &highest);
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (first_out_of_stack)) {
|
|
|
|
if (reverse && nstart < first_out_of_stack)
|
|
|
|
nstart = first_out_of_stack;
|
|
|
|
else if (!reverse && nstop > first_out_of_stack)
|
|
|
|
nstop = first_out_of_stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("nstart:%" GST_TIME_FORMAT ", nstop:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (nstart), GST_TIME_ARGS (nstop));
|
|
|
|
|
|
|
|
if (*stop)
|
|
|
|
*stop = nstop;
|
|
|
|
if (*start)
|
|
|
|
*start = nstart;
|
|
|
|
if (highprio)
|
|
|
|
*highprio = highest;
|
|
|
|
|
|
|
|
g_list_free (stack);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_clean_toplevel_stack:
|
2014-08-15 13:48:14 +00:00
|
|
|
* @comp: The #NleComposition
|
2014-10-21 08:35:48 +00:00
|
|
|
* @timestamp: The #GstClockTime to look at
|
|
|
|
* @stop_time: Pointer to a #GstClockTime for min stop time of returned stack
|
|
|
|
* @start_time: Pointer to a #GstClockTime for greatest start time of returned stack
|
|
|
|
*
|
2014-08-15 13:48:14 +00:00
|
|
|
* Returns: The new current stack for the given #NleComposition and @timestamp.
|
2014-10-21 08:35:48 +00:00
|
|
|
*
|
|
|
|
* WITH OBJECTS LOCK TAKEN
|
|
|
|
*/
|
|
|
|
static GNode *
|
2014-08-15 13:48:14 +00:00
|
|
|
get_clean_toplevel_stack (NleComposition * comp, GstClockTime * timestamp,
|
2014-10-21 08:35:48 +00:00
|
|
|
GstClockTime * start_time, GstClockTime * stop_time)
|
|
|
|
{
|
|
|
|
GNode *stack = NULL;
|
|
|
|
GstClockTime start = G_MAXUINT64;
|
|
|
|
GstClockTime stop = G_MAXUINT64;
|
|
|
|
guint highprio;
|
|
|
|
gboolean reverse = (comp->priv->segment->rate < 0.0);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "timestamp:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (*timestamp));
|
|
|
|
GST_DEBUG ("start:%" GST_TIME_FORMAT ", stop:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
|
|
|
|
|
|
|
stack = get_stack_list (comp, *timestamp, 0, TRUE, &start, &stop, &highprio);
|
|
|
|
|
|
|
|
if (!stack &&
|
|
|
|
((reverse && (*timestamp > COMP_REAL_START (comp))) ||
|
|
|
|
(!reverse && (*timestamp < COMP_REAL_STOP (comp))))) {
|
|
|
|
GST_ELEMENT_ERROR (comp, STREAM, WRONG_TYPE,
|
|
|
|
("Gaps ( at %" GST_TIME_FORMAT
|
|
|
|
") in the stream is not supported, the application is responsible"
|
|
|
|
" for filling them", GST_TIME_ARGS (*timestamp)),
|
|
|
|
("Gap in the composition this should never"
|
|
|
|
"append, make sure to fill them"));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("start:%" GST_TIME_FORMAT ", stop:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
|
|
|
|
|
|
|
if (stack) {
|
2014-08-15 13:48:14 +00:00
|
|
|
guint32 top_priority = NLE_OBJECT_PRIORITY (stack->data);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* Figure out if there's anything blocking us with smaller priority */
|
|
|
|
refine_start_stop_in_region_above_priority (comp, *timestamp, start,
|
|
|
|
stop, &start, &stop, (highprio == 0) ? top_priority : highprio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*stop_time) {
|
|
|
|
if (stack)
|
|
|
|
*stop_time = stop;
|
|
|
|
else
|
|
|
|
*stop_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*start_time) {
|
|
|
|
if (stack)
|
|
|
|
*start_time = start;
|
|
|
|
else
|
|
|
|
*start_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Returning timestamp:%" GST_TIME_FORMAT " , start_time:%"
|
|
|
|
GST_TIME_FORMAT " , stop_time:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (*timestamp), GST_TIME_ARGS (*start_time),
|
|
|
|
GST_TIME_ARGS (*stop_time));
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:51:51 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
_drop_all_cb (GstPad * pad G_GNUC_UNUSED,
|
2014-08-15 13:48:14 +00:00
|
|
|
GstPadProbeInfo * info, NleComposition * comp)
|
2014-07-13 09:51:51 +00:00
|
|
|
{
|
|
|
|
return GST_PAD_PROBE_DROP;
|
|
|
|
}
|
|
|
|
|
2014-07-07 20:54:25 +00:00
|
|
|
/* Must be called with OBJECTS_LOCK taken */
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_set_current_bin_to_ready (NleComposition * comp, gboolean flush_downstream)
|
2014-07-07 20:54:25 +00:00
|
|
|
{
|
2014-07-13 09:51:51 +00:00
|
|
|
gint probe_id = -1;
|
|
|
|
GstPad *ptarget = NULL;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-07-31 14:02:06 +00:00
|
|
|
GstEvent *flush_event;
|
2014-07-07 20:54:25 +00:00
|
|
|
|
2014-07-29 21:41:45 +00:00
|
|
|
comp->priv->tearing_down_stack = TRUE;
|
2014-07-11 12:11:21 +00:00
|
|
|
if (flush_downstream) {
|
2014-08-15 13:48:14 +00:00
|
|
|
ptarget = gst_ghost_pad_get_target (GST_GHOST_PAD (NLE_OBJECT_SRC (comp)));
|
2014-07-07 20:54:25 +00:00
|
|
|
if (ptarget) {
|
2014-07-11 13:41:50 +00:00
|
|
|
|
2014-07-13 09:51:51 +00:00
|
|
|
/* Make sure that between the flush_start/flush_stop
|
|
|
|
* and the time we set the current_bin to READY, no
|
|
|
|
* buffer can ever get prerolled which would lead to
|
|
|
|
* a deadlock */
|
|
|
|
probe_id = gst_pad_add_probe (ptarget,
|
|
|
|
GST_PAD_PROBE_TYPE_DATA_BOTH | GST_PAD_PROBE_TYPE_EVENT_BOTH,
|
|
|
|
(GstPadProbeCallback) _drop_all_cb, comp, NULL);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "added event probe %lu", priv->ghosteventprobe);
|
|
|
|
|
2014-07-22 16:22:09 +00:00
|
|
|
flush_event = gst_event_new_flush_start ();
|
|
|
|
priv->flush_seqnum = gst_event_get_seqnum (flush_event);
|
|
|
|
GST_INFO_OBJECT (comp, "sending flushes downstream with seqnum %d",
|
2014-07-25 08:55:52 +00:00
|
|
|
priv->flush_seqnum);
|
2014-07-22 16:22:09 +00:00
|
|
|
gst_pad_push_event (ptarget, flush_event);
|
2014-07-07 20:54:25 +00:00
|
|
|
|
|
|
|
}
|
2014-07-14 15:10:35 +00:00
|
|
|
|
2014-07-07 20:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_locked_state (priv->current_bin, TRUE);
|
|
|
|
gst_element_set_state (priv->current_bin, GST_STATE_READY);
|
2014-07-13 09:51:51 +00:00
|
|
|
|
2014-07-14 15:10:35 +00:00
|
|
|
if (ptarget) {
|
2014-08-12 12:35:09 +00:00
|
|
|
if (flush_downstream) {
|
2014-07-31 14:02:06 +00:00
|
|
|
flush_event = gst_event_new_flush_stop (TRUE);
|
|
|
|
gst_event_set_seqnum (flush_event, priv->flush_seqnum);
|
2014-09-19 10:52:45 +00:00
|
|
|
|
|
|
|
/* Force ad activation so that the event can actually travel.
|
|
|
|
* Not doing that would lead to the event being discarded.
|
|
|
|
*/
|
|
|
|
gst_pad_set_active (ptarget, TRUE);
|
2014-07-31 14:02:06 +00:00
|
|
|
gst_pad_push_event (ptarget, flush_event);
|
2014-09-19 10:52:45 +00:00
|
|
|
gst_pad_set_active (ptarget, FALSE);
|
2014-07-31 14:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 09:51:51 +00:00
|
|
|
gst_pad_remove_probe (ptarget, probe_id);
|
2014-07-14 15:10:35 +00:00
|
|
|
gst_object_unref (ptarget);
|
|
|
|
}
|
2014-07-31 14:02:06 +00:00
|
|
|
|
|
|
|
comp->priv->tearing_down_stack = FALSE;
|
2014-07-07 20:54:25 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
static void
|
|
|
|
_emit_commited_signal_func (NleComposition * comp, gpointer udata)
|
2014-07-07 21:07:15 +00:00
|
|
|
{
|
2014-07-08 11:28:57 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Emiting COMMITED now that the stack " "is ready");
|
2014-07-07 21:07:15 +00:00
|
|
|
|
|
|
|
g_signal_emit (comp, _signals[COMMITED_SIGNAL], 0, TRUE);
|
|
|
|
}
|
|
|
|
|
2014-07-11 16:29:17 +00:00
|
|
|
static void
|
2014-09-19 10:49:52 +00:00
|
|
|
_restart_task (NleComposition * comp)
|
2014-07-07 21:07:15 +00:00
|
|
|
{
|
2014-07-25 08:55:52 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Restarting task! after %s DONE",
|
2014-09-19 10:49:52 +00:00
|
|
|
UPDATE_PIPELINE_REASONS[comp->priv->updating_reason]);
|
2014-07-25 08:55:52 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
if (comp->priv->updating_reason == COMP_UPDATE_STACK_ON_COMMIT)
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_action (comp, G_CALLBACK (_emit_commited_signal_func), comp,
|
2014-07-11 16:29:17 +00:00
|
|
|
G_PRIORITY_HIGH);
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
comp->priv->seqnum_to_restart_task = 0;
|
2014-09-23 13:01:56 +00:00
|
|
|
comp->priv->waiting_for_buffer = FALSE;
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
comp->priv->updating_reason = COMP_UPDATE_STACK_NONE;
|
2015-02-04 14:21:55 +00:00
|
|
|
GST_OBJECT_LOCK (comp);
|
|
|
|
if (comp->task)
|
|
|
|
gst_task_start (comp->task);
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
2014-07-07 21:07:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 16:29:17 +00:00
|
|
|
static gboolean
|
2014-09-19 10:49:52 +00:00
|
|
|
_is_ready_to_restart_task (NleComposition * comp, GstEvent * event)
|
2014-07-07 21:07:15 +00:00
|
|
|
{
|
2014-09-23 13:01:56 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-09-19 10:49:52 +00:00
|
|
|
gint seqnum = gst_event_get_seqnum (event);
|
2014-07-25 08:55:52 +00:00
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
if (comp->priv->seqnum_to_restart_task == seqnum) {
|
2015-07-01 09:35:42 +00:00
|
|
|
gchar *name = g_strdup_printf ("%s-new-stack__%" GST_TIME_FORMAT "--%"
|
|
|
|
GST_TIME_FORMAT "", GST_OBJECT_NAME (comp),
|
|
|
|
GST_TIME_ARGS (comp->priv->segment_start),
|
2014-09-19 10:49:52 +00:00
|
|
|
GST_TIME_ARGS (comp->priv->segment_stop));
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Got %s with proper seqnum"
|
|
|
|
" done with stack reconfiguration %" GST_PTR_FORMAT,
|
|
|
|
GST_EVENT_TYPE_NAME (event), event);
|
2014-07-25 08:55:52 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (comp),
|
|
|
|
GST_DEBUG_GRAPH_SHOW_ALL, name);
|
|
|
|
g_free (name);
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-11-25 18:14:59 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
|
|
|
GST_INFO_OBJECT (comp, "update_pipeline DONE");
|
2014-09-23 13:01:56 +00:00
|
|
|
return TRUE;
|
2014-11-25 18:14:59 +00:00
|
|
|
}
|
2014-09-23 13:01:56 +00:00
|
|
|
|
|
|
|
priv->waiting_for_buffer = TRUE;
|
|
|
|
return FALSE;
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-09-19 10:49:52 +00:00
|
|
|
} else if (comp->priv->seqnum_to_restart_task) {
|
|
|
|
GST_INFO_OBJECT (comp, "WARNING: %s seqnum %i != wanted %i",
|
|
|
|
GST_EVENT_TYPE_NAME (event), seqnum,
|
|
|
|
comp->priv->seqnum_to_restart_task);
|
2014-07-07 21:07:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 16:29:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
static void
|
|
|
|
_commit_func (NleComposition * comp, UpdateCompositionData * ucompo)
|
2014-07-07 21:01:24 +00:00
|
|
|
{
|
|
|
|
GstClockTime curpos;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-07-07 21:01:24 +00:00
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update (comp, ucompo->seqnum, ucompo->reason);
|
|
|
|
|
2014-07-07 20:58:27 +00:00
|
|
|
/* Get current so that it represent the duration it was
|
|
|
|
* before commiting children */
|
|
|
|
curpos = get_current_position (comp);
|
2014-07-07 20:33:09 +00:00
|
|
|
|
2014-08-12 12:35:09 +00:00
|
|
|
if (!_commit_all_values (comp)) {
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Nothing to commit, leaving");
|
2014-07-07 21:01:24 +00:00
|
|
|
|
2014-06-27 14:12:12 +00:00
|
|
|
g_signal_emit (comp, _signals[COMMITED_SIGNAL], 0, FALSE);
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update_done (comp, ucompo->seqnum, ucompo->reason);
|
2014-07-07 21:01:24 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
return;
|
2014-06-27 14:12:12 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 13:12:38 +00:00
|
|
|
if (priv->initialized == FALSE) {
|
2014-07-07 21:07:15 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Not initialized yet, just updating values");
|
|
|
|
|
2014-06-29 20:35:34 +00:00
|
|
|
update_start_stop_duration (comp);
|
2014-07-07 21:07:15 +00:00
|
|
|
|
|
|
|
g_signal_emit (comp, _signals[COMMITED_SIGNAL], 0, TRUE);
|
|
|
|
|
2014-06-29 20:35:34 +00:00
|
|
|
} else {
|
|
|
|
/* And update the pipeline at current position if needed */
|
2014-07-07 20:58:27 +00:00
|
|
|
|
|
|
|
update_start_stop_duration (comp);
|
2014-07-25 08:55:52 +00:00
|
|
|
update_pipeline (comp, curpos, ucompo->seqnum, COMP_UPDATE_STACK_ON_COMMIT);
|
2014-07-07 20:58:27 +00:00
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
if (!priv->current) {
|
|
|
|
GST_INFO_OBJECT (comp, "No new stack set, we can go and keep acting on"
|
|
|
|
" our children");
|
2014-07-10 13:42:48 +00:00
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
g_signal_emit (comp, _signals[COMMITED_SIGNAL], 0, TRUE);
|
|
|
|
}
|
2014-06-29 20:35:34 +00:00
|
|
|
}
|
2014-06-27 14:12:12 +00:00
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update_done (comp, ucompo->seqnum, ucompo->reason);
|
2014-06-27 14:12:12 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
static void
|
|
|
|
_update_pipeline_func (NleComposition * comp, UpdateCompositionData * ucompo)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-06-27 10:15:10 +00:00
|
|
|
gboolean reverse;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-07-25 08:55:52 +00:00
|
|
|
|
|
|
|
_post_start_composition_update (comp, ucompo->seqnum, ucompo->reason);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-27 10:15:10 +00:00
|
|
|
/* Set up a non-initial seek on segment_stop */
|
|
|
|
reverse = (priv->segment->rate < 0.0);
|
|
|
|
if (!reverse) {
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Setting segment->start to segment_stop:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (priv->segment_stop));
|
|
|
|
priv->segment->start = priv->segment_stop;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Setting segment->stop to segment_start:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (priv->segment_start));
|
|
|
|
priv->segment->stop = priv->segment_start;
|
|
|
|
}
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
seek_handling (comp, ucompo->seqnum, COMP_UPDATE_STACK_ON_EOS);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-27 13:00:48 +00:00
|
|
|
/* Post segment done if last seek was a segment seek */
|
|
|
|
if (!priv->current && (priv->segment->flags & GST_SEEK_FLAG_SEGMENT)) {
|
|
|
|
gint64 epos;
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (priv->segment->stop))
|
2014-08-15 13:48:14 +00:00
|
|
|
epos = (MIN (priv->segment->stop, NLE_OBJECT_STOP (comp)));
|
2014-06-27 13:00:48 +00:00
|
|
|
else
|
2014-08-15 13:48:14 +00:00
|
|
|
epos = NLE_OBJECT_STOP (comp);
|
2014-06-27 13:00:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (comp, "Emitting segment done pos %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (epos));
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (comp),
|
|
|
|
gst_message_new_segment_done (GST_OBJECT (comp),
|
2014-06-29 20:35:34 +00:00
|
|
|
priv->segment->format, epos));
|
2014-08-15 13:48:14 +00:00
|
|
|
gst_pad_push_event (NLE_OBJECT (comp)->srcpad,
|
2014-06-27 13:00:48 +00:00
|
|
|
gst_event_new_segment_done (priv->segment->format, epos));
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
_post_start_composition_update_done (comp, ucompo->seqnum, ucompo->reason);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 15:42:06 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_set_all_children_state (NleComposition * comp, GstState state)
|
2014-07-03 15:42:06 +00:00
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
2014-07-07 21:08:56 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Setting all children state to %s",
|
|
|
|
gst_element_state_get_name (state));
|
|
|
|
|
2014-07-29 21:41:45 +00:00
|
|
|
comp->priv->tearing_down_stack = TRUE;
|
2014-07-03 15:42:06 +00:00
|
|
|
gst_element_set_state (comp->priv->current_bin, state);
|
|
|
|
for (tmp = comp->priv->objects_start; tmp; tmp = tmp->next)
|
|
|
|
gst_element_set_state (tmp->data, state);
|
|
|
|
|
2014-07-07 21:08:56 +00:00
|
|
|
for (tmp = comp->priv->expandables; tmp; tmp = tmp->next)
|
|
|
|
gst_element_set_state (tmp->data, state);
|
2014-07-29 21:41:45 +00:00
|
|
|
comp->priv->tearing_down_stack = FALSE;
|
2014-07-03 15:42:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
static GstStateChangeReturn
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_change_state (GstElement * element, GstStateChange transition)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleComposition *comp = (NleComposition *) element;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "%s => %s",
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
|
|
|
|
gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
|
|
|
|
|
|
|
|
switch (transition) {
|
2014-07-11 19:59:43 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
_start_task (comp);
|
|
|
|
break;
|
2014-10-21 08:35:48 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2014-07-07 21:07:15 +00:00
|
|
|
/* state-lock all elements */
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"Setting all children to READY and locking their state");
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_update_compo_action (comp, G_CALLBACK (_initialize_stack_func),
|
2014-07-25 08:55:52 +00:00
|
|
|
COMP_UPDATE_STACK_INITIALIZE);
|
2014-10-21 08:35:48 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2014-07-14 15:47:07 +00:00
|
|
|
_stop_task (comp);
|
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_update_actions (comp);
|
|
|
|
_remove_seek_actions (comp);
|
2014-07-03 15:42:06 +00:00
|
|
|
_set_all_children_state (comp, GST_STATE_READY);
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset (comp);
|
2014-07-14 15:47:07 +00:00
|
|
|
|
|
|
|
_start_task (comp);
|
2014-07-03 12:48:25 +00:00
|
|
|
break;
|
2014-10-21 08:35:48 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2014-07-11 19:59:43 +00:00
|
|
|
_stop_task (comp);
|
2014-07-15 07:46:03 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_update_actions (comp);
|
|
|
|
_remove_seek_actions (comp);
|
2014-07-03 15:42:06 +00:00
|
|
|
_set_all_children_state (comp, GST_STATE_NULL);
|
2014-10-21 08:35:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-14 13:50:58 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2014-08-15 13:48:14 +00:00
|
|
|
objects_start_compare (NleObject * a, NleObject * b)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
if (a->start == b->start) {
|
|
|
|
if (a->priority < b->priority)
|
|
|
|
return -1;
|
|
|
|
if (a->priority > b->priority)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (a->start < b->start)
|
|
|
|
return -1;
|
|
|
|
if (a->start > b->start)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2014-08-15 13:48:14 +00:00
|
|
|
objects_stop_compare (NleObject * a, NleObject * b)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
|
|
|
if (a->stop == b->stop) {
|
|
|
|
if (a->priority < b->priority)
|
|
|
|
return -1;
|
|
|
|
if (a->priority > b->priority)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (b->stop < a->stop)
|
|
|
|
return -1;
|
|
|
|
if (b->stop > a->stop)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WITH OBJECTS LOCK TAKEN */
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
update_start_stop_duration (NleComposition * comp)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *obj;
|
|
|
|
NleObject *cobj = (NleObject *) comp;
|
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-14 15:47:07 +00:00
|
|
|
_assert_proper_thread (comp);
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
if (!priv->objects_start) {
|
2014-09-19 15:13:52 +00:00
|
|
|
GST_INFO_OBJECT (comp, "no objects, resetting everything to 0");
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (cobj->start) {
|
|
|
|
cobj->start = cobj->pending_start = 0;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_START]);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cobj->duration) {
|
|
|
|
cobj->pending_duration = cobj->duration = 0;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_DURATION]);
|
2014-10-21 08:35:48 +00:00
|
|
|
signal_duration_change (comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cobj->stop) {
|
|
|
|
cobj->stop = 0;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_STOP]);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a default object, the start position is 0 */
|
|
|
|
if (priv->expandables) {
|
2014-09-19 15:13:52 +00:00
|
|
|
GST_INFO_OBJECT (cobj,
|
2014-10-21 08:35:48 +00:00
|
|
|
"Setting start to 0 because we have a default object");
|
|
|
|
|
|
|
|
if (cobj->start != 0) {
|
|
|
|
cobj->pending_start = cobj->start = 0;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_START]);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Else it's the first object's start value */
|
2014-08-15 13:48:14 +00:00
|
|
|
obj = (NleObject *) priv->objects_start->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (obj->start != cobj->start) {
|
2014-09-19 15:13:52 +00:00
|
|
|
GST_INFO_OBJECT (obj, "setting start from %s to %" GST_TIME_FORMAT,
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_OBJECT_NAME (obj), GST_TIME_ARGS (obj->start));
|
|
|
|
cobj->pending_start = cobj->start = obj->start;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_START]);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
obj = (NleObject *) priv->objects_stop->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (obj->stop != cobj->stop) {
|
2014-09-19 15:13:52 +00:00
|
|
|
GST_INFO_OBJECT (obj, "setting stop from %s to %" GST_TIME_FORMAT,
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_OBJECT_NAME (obj), GST_TIME_ARGS (obj->stop));
|
|
|
|
|
|
|
|
if (priv->expandables) {
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (comp, "RE-setting all expandables duration and commit");
|
|
|
|
for (tmp = priv->expandables; tmp; tmp = tmp->next) {
|
|
|
|
g_object_set (tmp->data, "duration", obj->stop, NULL);
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_commit (NLE_OBJECT (tmp->data), FALSE);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->segment->stop = obj->stop;
|
|
|
|
cobj->stop = obj->stop;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_STOP]);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((cobj->stop - cobj->start) != cobj->duration) {
|
|
|
|
cobj->pending_duration = cobj->duration = cobj->stop - cobj->start;
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (cobj),
|
2014-08-15 13:48:14 +00:00
|
|
|
nleobject_properties[NLEOBJECT_PROP_DURATION]);
|
2014-10-21 08:35:48 +00:00
|
|
|
signal_duration_change (comp);
|
|
|
|
}
|
|
|
|
|
2014-09-19 15:13:52 +00:00
|
|
|
GST_INFO_OBJECT (comp,
|
2014-10-21 08:35:48 +00:00
|
|
|
"start:%" GST_TIME_FORMAT
|
|
|
|
" stop:%" GST_TIME_FORMAT
|
|
|
|
" duration:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (cobj->start),
|
|
|
|
GST_TIME_ARGS (cobj->stop), GST_TIME_ARGS (cobj->duration));
|
|
|
|
}
|
|
|
|
|
2014-06-25 17:39:29 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_link_to_parent (NleComposition * comp, NleObject * newobj,
|
|
|
|
NleObject * newparent)
|
2014-06-25 17:39:29 +00:00
|
|
|
{
|
|
|
|
GstPad *sinkpad;
|
|
|
|
|
|
|
|
/* relink to new parent in required order */
|
|
|
|
GST_LOG_OBJECT (comp, "Linking %s and %s",
|
|
|
|
GST_ELEMENT_NAME (GST_ELEMENT (newobj)),
|
|
|
|
GST_ELEMENT_NAME (GST_ELEMENT (newparent)));
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
sinkpad = get_unlinked_sink_ghost_pad ((NleOperation *) newparent);
|
2014-06-25 17:39:29 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (sinkpad == NULL)) {
|
|
|
|
GST_WARNING_OBJECT (comp,
|
|
|
|
"Couldn't find an unlinked sinkpad from %s",
|
|
|
|
GST_ELEMENT_NAME (newparent));
|
|
|
|
} else {
|
2014-08-15 13:48:14 +00:00
|
|
|
if (G_UNLIKELY (gst_pad_link_full (NLE_OBJECT_SRC (newobj), sinkpad,
|
2014-06-25 17:39:29 +00:00
|
|
|
GST_PAD_LINK_CHECK_NOTHING) != GST_PAD_LINK_OK)) {
|
|
|
|
GST_WARNING_OBJECT (comp, "Failed to link pads %s:%s - %s:%s",
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_DEBUG_PAD_NAME (NLE_OBJECT_SRC (newobj)),
|
2014-06-25 17:39:29 +00:00
|
|
|
GST_DEBUG_PAD_NAME (sinkpad));
|
|
|
|
}
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_relink_children_recursively (NleComposition * comp,
|
|
|
|
NleObject * newobj, GNode * node, GstEvent * toplevel_seek)
|
2014-06-25 17:39:29 +00:00
|
|
|
{
|
|
|
|
GNode *child;
|
|
|
|
guint nbchildren = g_node_n_children (node);
|
2014-08-15 13:48:14 +00:00
|
|
|
NleOperation *oper = (NleOperation *) newobj;
|
2014-06-25 17:39:29 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (newobj, "is a %s operation, analyzing the %d children",
|
|
|
|
oper->dynamicsinks ? "dynamic" : "regular", nbchildren);
|
|
|
|
/* Update the operation's number of sinks, that will make it have the proper
|
|
|
|
* number of sink pads to connect the children to. */
|
|
|
|
if (oper->dynamicsinks)
|
|
|
|
g_object_set (G_OBJECT (newobj), "sinks", nbchildren, NULL);
|
|
|
|
|
|
|
|
for (child = node->children; child; child = child->next)
|
2014-07-02 19:01:31 +00:00
|
|
|
_relink_single_node (comp, child, toplevel_seek);
|
2014-06-25 17:39:29 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (nbchildren < oper->num_sinks))
|
|
|
|
GST_ERROR ("Not enough sinkpads to link all objects to the operation ! "
|
|
|
|
"%d / %d", oper->num_sinks, nbchildren);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (nbchildren == 0))
|
|
|
|
GST_ERROR ("Operation has no child objects to be connected to !!!");
|
|
|
|
/* Make sure we have enough sinkpads */
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
/*
|
|
|
|
* recursive depth-first relink stack function on new stack
|
|
|
|
*
|
|
|
|
* _ relink nodes with changed parent/order
|
|
|
|
* _ links new nodes with parents
|
|
|
|
* _ unblocks available source pads (except for toplevel)
|
|
|
|
*
|
|
|
|
* WITH OBJECTS LOCK TAKEN
|
|
|
|
*/
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_relink_single_node (NleComposition * comp, GNode * node,
|
2014-07-03 09:36:20 +00:00
|
|
|
GstEvent * toplevel_seek)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *newobj;
|
|
|
|
NleObject *newparent;
|
2014-10-21 08:35:48 +00:00
|
|
|
GstPad *srcpad = NULL, *sinkpad = NULL;
|
2014-07-02 19:01:31 +00:00
|
|
|
GstEvent *translated_seek;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!node))
|
|
|
|
return;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
newparent = G_NODE_IS_ROOT (node) ? NULL : (NleObject *) node->parent->data;
|
|
|
|
newobj = (NleObject *) node->data;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp, "newobj:%s",
|
|
|
|
GST_ELEMENT_NAME ((GstElement *) newobj));
|
2014-06-24 11:44:13 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
srcpad = NLE_OBJECT_SRC (newobj);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-09-19 10:55:51 +00:00
|
|
|
gst_bin_add (GST_BIN (comp->priv->current_bin), GST_ELEMENT (newobj));
|
2014-07-02 19:01:31 +00:00
|
|
|
gst_element_sync_state_with_parent (GST_ELEMENT_CAST (newobj));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
translated_seek = nle_object_translate_incoming_seek (newobj, toplevel_seek);
|
2014-07-02 19:01:31 +00:00
|
|
|
|
|
|
|
gst_element_send_event (GST_ELEMENT (newobj), translated_seek);
|
2014-06-25 17:18:29 +00:00
|
|
|
|
|
|
|
/* link to parent if needed. */
|
2014-06-24 11:44:13 +00:00
|
|
|
if (newparent) {
|
2014-07-02 19:01:31 +00:00
|
|
|
_link_to_parent (comp, newobj, newparent);
|
2014-06-25 17:39:29 +00:00
|
|
|
|
|
|
|
/* If there's an operation, inform it about priority changes */
|
2014-06-24 11:44:13 +00:00
|
|
|
sinkpad = gst_pad_get_peer (srcpad);
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_operation_signal_input_priority_changed ((NleOperation *)
|
2014-06-24 11:44:13 +00:00
|
|
|
newparent, sinkpad, newobj->priority);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
}
|
|
|
|
|
2014-06-25 17:39:29 +00:00
|
|
|
/* Handle children */
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_IS_OPERATION (newobj))
|
2014-07-02 19:01:31 +00:00
|
|
|
_relink_children_recursively (comp, newobj, node, toplevel_seek);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (comp, "done with object %s",
|
|
|
|
GST_ELEMENT_NAME (GST_ELEMENT (newobj)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compare_relink_stack:
|
2014-08-15 13:48:14 +00:00
|
|
|
* @comp: The #NleComposition
|
2014-10-21 08:35:48 +00:00
|
|
|
* @stack: The new stack
|
|
|
|
* @modify: TRUE if the timeline has changed and needs downstream flushes.
|
|
|
|
*
|
|
|
|
* Compares the given stack to the current one and relinks it if needed.
|
|
|
|
*
|
|
|
|
* WITH OBJECTS LOCK TAKEN
|
|
|
|
*
|
2014-08-15 13:48:14 +00:00
|
|
|
* Returns: The #GList of #NleObject no longer used
|
2014-10-21 08:35:48 +00:00
|
|
|
*/
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_deactivate_stack (NleComposition * comp, gboolean flush_downstream)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-07-03 09:36:20 +00:00
|
|
|
GstPad *ptarget;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-11-25 18:14:59 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Deactivating current stack (flushing downstream: %d",
|
|
|
|
flush_downstream);
|
2014-07-11 12:11:21 +00:00
|
|
|
_set_current_bin_to_ready (comp, flush_downstream);
|
2014-07-02 19:01:31 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
ptarget = gst_ghost_pad_get_target (GST_GHOST_PAD (NLE_OBJECT_SRC (comp)));
|
2014-07-02 19:01:31 +00:00
|
|
|
_empty_bin (GST_BIN_CAST (comp->priv->current_bin));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-03 09:36:20 +00:00
|
|
|
if (comp->priv->ghosteventprobe) {
|
2014-07-04 09:05:41 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Removing old ghost pad probe");
|
|
|
|
|
2014-07-03 09:36:20 +00:00
|
|
|
gst_pad_remove_probe (ptarget, comp->priv->ghosteventprobe);
|
|
|
|
comp->priv->ghosteventprobe = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
if (ptarget)
|
|
|
|
gst_object_unref (ptarget);
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-11-25 18:14:59 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Stack desctivated");
|
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
/* priv->current = NULL;
|
|
|
|
*/
|
2014-07-04 09:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-15 13:48:14 +00:00
|
|
|
_relink_new_stack (NleComposition * comp, GNode * stack,
|
2014-07-04 09:05:41 +00:00
|
|
|
GstEvent * toplevel_seek)
|
|
|
|
{
|
2014-07-08 20:58:02 +00:00
|
|
|
_relink_single_node (comp, stack, toplevel_seek);
|
|
|
|
|
2014-07-03 15:36:01 +00:00
|
|
|
gst_event_unref (toplevel_seek);
|
2014-07-07 21:07:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static void
|
2014-08-15 13:48:14 +00:00
|
|
|
* unlock_activate_stack (NleComposition * comp, GNode * node, GstState state)
|
2014-07-07 21:07:15 +00:00
|
|
|
* {
|
|
|
|
* GNode *child;
|
2014-07-11 15:22:24 +00:00
|
|
|
*
|
2014-07-07 21:07:15 +00:00
|
|
|
* GST_LOG_OBJECT (comp, "object:%s",
|
|
|
|
* GST_ELEMENT_NAME ((GstElement *) (node->data)));
|
2014-07-11 15:22:24 +00:00
|
|
|
*
|
2014-07-07 21:07:15 +00:00
|
|
|
* gst_element_set_locked_state ((GstElement *) (node->data), FALSE);
|
|
|
|
* gst_element_set_state (GST_ELEMENT (node->data), state);
|
2014-07-11 15:22:24 +00:00
|
|
|
*
|
2014-07-07 21:07:15 +00:00
|
|
|
* for (child = node->children; child; child = child->next)
|
|
|
|
* unlock_activate_stack (comp, child, state);
|
|
|
|
* }
|
|
|
|
*/
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
are_same_stacks (GNode * stack1, GNode * stack2)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
/* TODO : FIXME : we should also compare start/inpoint */
|
|
|
|
/* stacks are not equal if one of them is NULL but not the other */
|
|
|
|
if ((!stack1 && stack2) || (stack1 && !stack2))
|
|
|
|
goto beach;
|
|
|
|
|
|
|
|
if (stack1 && stack2) {
|
|
|
|
GNode *child1, *child2;
|
|
|
|
|
|
|
|
/* if they don't contain the same source, not equal */
|
|
|
|
if (!(stack1->data == stack2->data))
|
|
|
|
goto beach;
|
|
|
|
|
|
|
|
/* if they don't have the same number of children, not equal */
|
|
|
|
if (!(g_node_n_children (stack1) == g_node_n_children (stack2)))
|
|
|
|
goto beach;
|
|
|
|
|
|
|
|
child1 = stack1->children;
|
|
|
|
child2 = stack2->children;
|
|
|
|
while (child1 && child2) {
|
|
|
|
if (!(are_same_stacks (child1, child2)))
|
|
|
|
goto beach;
|
|
|
|
child1 = g_node_next_sibling (child1);
|
|
|
|
child2 = g_node_next_sibling (child2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there's a difference in child number, stacks are not equal */
|
|
|
|
if (child1 || child2)
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if stack1 AND stack2 are NULL, then they're equal (both empty) */
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
beach:
|
|
|
|
GST_LOG ("Stacks are equal : %d", res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
static inline gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_activate_new_stack (NleComposition * comp)
|
2014-06-26 21:48:09 +00:00
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
GstElement *topelement;
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-06-26 21:48:09 +00:00
|
|
|
|
|
|
|
if (!priv->current) {
|
|
|
|
if ((!priv->objects_start)) {
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_reset_target_pad (comp);
|
2014-06-26 21:48:09 +00:00
|
|
|
priv->segment_start = 0;
|
|
|
|
priv->segment_stop = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "Nothing else in the composition"
|
2014-06-26 21:48:09 +00:00
|
|
|
", update 'worked'");
|
2014-07-12 18:54:55 +00:00
|
|
|
goto resync_state;
|
2014-06-26 21:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The stack is entirely ready, send seek out synchronously */
|
|
|
|
topelement = GST_ELEMENT (priv->current->data);
|
|
|
|
/* Get toplevel object source pad */
|
2014-08-15 13:48:14 +00:00
|
|
|
pad = NLE_OBJECT_SRC (topelement);
|
2014-06-26 21:48:09 +00:00
|
|
|
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_INFO_OBJECT (comp,
|
2014-06-26 21:48:09 +00:00
|
|
|
"We have a valid toplevel element pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_ghost_pad_set_target (comp, pad);
|
2014-06-26 21:48:09 +00:00
|
|
|
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "New stack activated!");
|
2014-07-12 18:54:55 +00:00
|
|
|
|
|
|
|
resync_state:
|
|
|
|
gst_element_set_locked_state (priv->current_bin, FALSE);
|
2014-08-20 11:15:30 +00:00
|
|
|
GST_DEBUG ("going back to parent state");
|
2014-07-12 18:54:55 +00:00
|
|
|
gst_element_sync_state_with_parent (priv->current_bin);
|
2014-08-20 11:15:30 +00:00
|
|
|
GST_DEBUG ("gone back to parent state");
|
2014-07-12 18:54:55 +00:00
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
/* WITH OBJECTS LOCK TAKEN */
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_set_real_eos_seqnum_from_seek (NleComposition * comp, GstEvent * event)
|
2014-07-04 09:05:41 +00:00
|
|
|
{
|
|
|
|
GList *tmp;
|
2014-07-10 13:33:23 +00:00
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
gboolean should_check_objects = FALSE;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-07-10 13:33:23 +00:00
|
|
|
gboolean reverse = (priv->segment->rate < 0);
|
2014-07-10 13:45:19 +00:00
|
|
|
gint stack_seqnum = gst_event_get_seqnum (event);
|
2014-07-04 09:05:41 +00:00
|
|
|
|
2014-07-10 13:33:23 +00:00
|
|
|
if (reverse && GST_CLOCK_TIME_IS_VALID (priv->segment_start))
|
2014-07-04 09:05:41 +00:00
|
|
|
should_check_objects = TRUE;
|
2014-07-10 13:33:23 +00:00
|
|
|
else if (!reverse && GST_CLOCK_TIME_IS_VALID (priv->segment_stop))
|
2014-07-04 09:05:41 +00:00
|
|
|
should_check_objects = TRUE;
|
|
|
|
|
|
|
|
if (should_check_objects) {
|
2014-07-10 13:33:23 +00:00
|
|
|
for (tmp = priv->objects_stop; tmp; tmp = g_list_next (tmp)) {
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object = (NleObject *) tmp->data;
|
2014-07-04 09:05:41 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (!NLE_IS_SOURCE (object))
|
2014-07-04 09:05:41 +00:00
|
|
|
continue;
|
|
|
|
|
2014-07-10 13:33:23 +00:00
|
|
|
if ((!reverse && priv->segment_stop < object->stop) ||
|
|
|
|
(reverse && priv->segment_start > object->start)) {
|
2014-07-15 13:17:43 +00:00
|
|
|
priv->next_eos_seqnum = stack_seqnum;
|
2014-07-10 13:45:19 +00:00
|
|
|
g_atomic_int_set (&priv->real_eos_seqnum, 0);
|
2014-07-04 09:05:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-15 13:17:43 +00:00
|
|
|
priv->next_eos_seqnum = stack_seqnum;
|
2014-07-10 13:45:19 +00:00
|
|
|
g_atomic_int_set (&priv->real_eos_seqnum, stack_seqnum);
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
/*
|
|
|
|
* update_pipeline:
|
2014-08-15 13:48:14 +00:00
|
|
|
* @comp: The #NleComposition
|
2014-10-21 08:35:48 +00:00
|
|
|
* @currenttime: The #GstClockTime to update at, can be GST_CLOCK_TIME_NONE.
|
2014-07-11 16:27:25 +00:00
|
|
|
* @update_reason: Reason why we are updating the pipeline
|
2014-10-21 08:35:48 +00:00
|
|
|
*
|
|
|
|
* Updates the internal pipeline and properties. If @currenttime is
|
|
|
|
* GST_CLOCK_TIME_NONE, it will not modify the current pipeline
|
|
|
|
*
|
|
|
|
* Returns: FALSE if there was an error updating the pipeline.
|
|
|
|
*
|
|
|
|
* WITH OBJECTS LOCK TAKEN
|
|
|
|
*/
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
update_pipeline (NleComposition * comp, GstClockTime currenttime, gint32 seqnum,
|
|
|
|
NleUpdateStackReason update_reason)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-07-04 09:05:41 +00:00
|
|
|
|
|
|
|
GstEvent *toplevel_seek;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
GNode *stack = NULL;
|
|
|
|
gboolean samestack = FALSE;
|
2014-07-04 09:05:41 +00:00
|
|
|
gboolean updatestoponly = FALSE;
|
2014-10-21 08:35:48 +00:00
|
|
|
GstState state = GST_STATE (comp);
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
GstClockTime new_stop = GST_CLOCK_TIME_NONE;
|
|
|
|
GstClockTime new_start = GST_CLOCK_TIME_NONE;
|
2015-02-03 11:02:42 +00:00
|
|
|
GstClockTime duration = NLE_OBJECT (comp)->duration - 1;
|
2014-07-04 09:05:41 +00:00
|
|
|
|
2014-10-21 08:35:48 +00:00
|
|
|
GstState nextstate = (GST_STATE_NEXT (comp) == GST_STATE_VOID_PENDING) ?
|
|
|
|
GST_STATE (comp) : GST_STATE_NEXT (comp);
|
|
|
|
|
2014-07-14 15:47:07 +00:00
|
|
|
_assert_proper_thread (comp);
|
|
|
|
|
2015-02-03 11:02:42 +00:00
|
|
|
if (currenttime >= duration) {
|
|
|
|
currenttime = duration;
|
|
|
|
priv->segment->start = GST_CLOCK_TIME_NONE;
|
|
|
|
priv->segment->stop = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
GST_INFO_OBJECT (comp,
|
2014-10-21 08:35:48 +00:00
|
|
|
"currenttime:%" GST_TIME_FORMAT
|
2014-07-25 08:55:52 +00:00
|
|
|
" Reason: %s, Seqnum: %i", GST_TIME_ARGS (currenttime),
|
|
|
|
UPDATE_PIPELINE_REASONS[update_reason], seqnum);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (currenttime))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (state == GST_STATE_NULL && nextstate == GST_STATE_NULL) {
|
|
|
|
GST_DEBUG_OBJECT (comp, "STATE_NULL: not updating pipeline");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (comp,
|
|
|
|
"now really updating the pipeline, current-state:%s",
|
|
|
|
gst_element_state_get_name (state));
|
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
/* Get new stack and compare it to current one */
|
2014-10-21 08:35:48 +00:00
|
|
|
stack = get_clean_toplevel_stack (comp, ¤ttime, &new_start, &new_stop);
|
|
|
|
samestack = are_same_stacks (priv->current, stack);
|
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
/* set new segment_start/stop (the current zone over which the new stack
|
|
|
|
* is valid) */
|
2014-10-21 08:35:48 +00:00
|
|
|
if (priv->segment->rate >= 0.0) {
|
|
|
|
priv->segment_start = currenttime;
|
|
|
|
priv->segment_stop = new_stop;
|
|
|
|
} else {
|
|
|
|
priv->segment_start = new_start;
|
|
|
|
priv->segment_stop = currenttime;
|
|
|
|
}
|
|
|
|
|
2014-07-14 11:36:31 +00:00
|
|
|
# if 0
|
|
|
|
/* FIXME -- We should be ablt to use updatestoponly in that case,
|
|
|
|
* but it simply does not work! Not using it leads to same
|
|
|
|
* behaviour, but less optimized */
|
|
|
|
|
|
|
|
gboolean startchanged, stopchanged;
|
|
|
|
|
|
|
|
if (priv->segment->rate >= 0.0) {
|
|
|
|
startchanged = priv->segment_start != currenttime;
|
|
|
|
stopchanged = priv->segment_stop != new_stop;
|
|
|
|
} else {
|
|
|
|
startchanged = priv->segment_start != new_start;
|
|
|
|
stopchanged = priv->segment_stop != currenttime;
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:05:41 +00:00
|
|
|
if (samestack) {
|
|
|
|
if (startchanged || stopchanged) {
|
|
|
|
/* Update seek events need to be flushing if not in PLAYING,
|
|
|
|
* else we will encounter deadlocks. */
|
|
|
|
updatestoponly = (state == GST_STATE_PLAYING) ? FALSE : TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 11:36:31 +00:00
|
|
|
#endif
|
2014-07-04 09:05:41 +00:00
|
|
|
|
|
|
|
toplevel_seek = get_new_seek_event (comp, TRUE, updatestoponly);
|
2014-07-25 08:55:52 +00:00
|
|
|
gst_event_set_seqnum (toplevel_seek, seqnum);
|
2014-07-10 13:45:19 +00:00
|
|
|
_set_real_eos_seqnum_from_seek (comp, toplevel_seek);
|
2014-07-04 09:05:41 +00:00
|
|
|
|
2014-08-20 11:15:30 +00:00
|
|
|
_remove_update_actions (comp);
|
2014-07-11 17:13:29 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
/* If stacks are different, unlink/relink objects */
|
2014-07-04 09:05:41 +00:00
|
|
|
if (!samestack) {
|
2014-07-15 13:01:59 +00:00
|
|
|
_deactivate_stack (comp, _have_to_flush_downstream (update_reason));
|
2014-07-04 09:05:41 +00:00
|
|
|
_relink_new_stack (comp, stack, toplevel_seek);
|
|
|
|
}
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
/* Unlock all elements in new stack */
|
2014-07-10 14:26:48 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Setting current stack [%" GST_TIME_FORMAT " - %"
|
|
|
|
GST_TIME_FORMAT "]", GST_TIME_ARGS (priv->segment_start),
|
|
|
|
GST_TIME_ARGS (priv->segment_stop));
|
2014-10-21 08:35:48 +00:00
|
|
|
priv->current = stack;
|
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
if (priv->current) {
|
2014-07-25 08:55:52 +00:00
|
|
|
UpdateCompositionData *ucompo = g_slice_new0 (UpdateCompositionData);
|
2014-07-11 16:27:25 +00:00
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
GST_INFO_OBJECT (comp, "New stack set and ready to run, probing src pad"
|
|
|
|
" and stopping children thread until we are actually ready with"
|
|
|
|
" that new stack");
|
|
|
|
|
2014-07-25 08:55:52 +00:00
|
|
|
ucompo->comp = comp;
|
|
|
|
ucompo->reason = update_reason;
|
|
|
|
ucompo->seqnum = seqnum;
|
2014-09-23 13:01:56 +00:00
|
|
|
|
|
|
|
comp->priv->updating_reason = update_reason;
|
2014-09-19 10:49:52 +00:00
|
|
|
comp->priv->seqnum_to_restart_task = seqnum;
|
2014-07-07 21:07:15 +00:00
|
|
|
|
2014-07-28 18:24:50 +00:00
|
|
|
GST_OBJECT_LOCK (comp);
|
|
|
|
if (comp->task == NULL) {
|
|
|
|
GST_INFO_OBJECT (comp,
|
|
|
|
"No task set, it must have been stopped, returning");
|
|
|
|
GST_OBJECT_UNLOCK (comp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:07:15 +00:00
|
|
|
gst_task_pause (comp->task);
|
2014-07-28 18:24:50 +00:00
|
|
|
GST_OBJECT_UNLOCK (comp);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 21:48:09 +00:00
|
|
|
/* Activate stack */
|
2014-07-10 13:48:50 +00:00
|
|
|
if (!samestack)
|
2014-07-07 20:27:21 +00:00
|
|
|
return _activate_new_stack (comp);
|
2014-07-10 13:48:50 +00:00
|
|
|
else
|
2014-07-15 12:59:54 +00:00
|
|
|
return _seek_current_stack (comp, toplevel_seek,
|
2014-07-15 13:01:59 +00:00
|
|
|
_have_to_flush_downstream (update_reason));
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_add_object (GstBin * bin, GstElement * element)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object;
|
|
|
|
NleComposition *comp = (NleComposition *) bin;
|
2014-07-02 19:01:31 +00:00
|
|
|
|
|
|
|
if (element == comp->priv->current_bin) {
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Adding internal bin");
|
2014-07-02 19:01:31 +00:00
|
|
|
return GST_BIN_CLASS (parent_class)->add_element (bin, element);
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
g_return_val_if_fail (NLE_IS_OBJECT (element), FALSE);
|
2014-07-02 19:01:31 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
object = NLE_OBJECT (element);
|
2014-09-19 10:55:51 +00:00
|
|
|
gst_object_ref_sink (object);
|
2014-07-19 09:41:56 +00:00
|
|
|
|
|
|
|
object->in_composition = TRUE;
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_add_object_action (comp, object);
|
2014-07-19 09:41:56 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2014-07-02 19:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_add_object (NleComposition * comp, NleObject * object)
|
2014-07-02 19:01:31 +00:00
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "element %s", GST_OBJECT_NAME (object));
|
|
|
|
GST_DEBUG_OBJECT (object, "%" GST_TIME_FORMAT "--%" GST_TIME_FORMAT,
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_TIME_ARGS (NLE_OBJECT_START (object)),
|
|
|
|
GST_TIME_ARGS (NLE_OBJECT_STOP (object)));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if ((NLE_OBJECT_IS_EXPANDABLE (object)) &&
|
2014-07-02 19:01:31 +00:00
|
|
|
g_list_find (priv->expandables, object)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
GST_WARNING_OBJECT (comp,
|
|
|
|
"We already have an expandable, remove it before adding new one");
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
goto chiringuito;
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_set_caps (object, NLE_OBJECT (comp)->caps);
|
|
|
|
nle_object_set_commit_needed (NLE_OBJECT (comp));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
2014-07-02 19:01:31 +00:00
|
|
|
GST_WARNING_OBJECT (comp, "couldn't add object");
|
2014-10-21 08:35:48 +00:00
|
|
|
goto chiringuito;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lock state of child ! */
|
2014-07-02 19:01:31 +00:00
|
|
|
GST_LOG_OBJECT (comp, "Locking state of %s", GST_ELEMENT_NAME (object));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_OBJECT_IS_EXPANDABLE (object)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
/* Only react on non-default objects properties */
|
2014-07-02 19:01:31 +00:00
|
|
|
g_object_set (object,
|
2014-10-21 08:35:48 +00:00
|
|
|
"start", (GstClockTime) 0,
|
|
|
|
"inpoint", (GstClockTime) 0,
|
2014-08-15 13:48:14 +00:00
|
|
|
"duration", (GstClockTimeDiff) NLE_OBJECT_STOP (comp), NULL);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
GST_INFO_OBJECT (object, "Used as expandable, commiting now");
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_commit (NLE_OBJECT (object), FALSE);
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ...and add it to the hash table */
|
2014-07-14 14:12:00 +00:00
|
|
|
g_hash_table_add (priv->objects_hash, object);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
/* Set the caps of the composition on the NleObject it handles */
|
|
|
|
if (G_UNLIKELY (!gst_caps_is_any (((NleObject *) comp)->caps)))
|
|
|
|
nle_object_set_caps ((NleObject *) object, ((NleObject *) comp)->caps);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* Special case for default source. */
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_OBJECT_IS_EXPANDABLE (object)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
/* It doesn't get added to objects_start and objects_stop. */
|
2014-07-02 19:01:31 +00:00
|
|
|
priv->expandables = g_list_prepend (priv->expandables, object);
|
2014-10-21 08:35:48 +00:00
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add it sorted to the objects list */
|
|
|
|
priv->objects_start = g_list_insert_sorted
|
2014-07-02 19:01:31 +00:00
|
|
|
(priv->objects_start, object, (GCompareFunc) objects_start_compare);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
if (priv->objects_start)
|
|
|
|
GST_LOG_OBJECT (comp,
|
|
|
|
"Head of objects_start is now %s [%" GST_TIME_FORMAT "--%"
|
|
|
|
GST_TIME_FORMAT "]",
|
|
|
|
GST_OBJECT_NAME (priv->objects_start->data),
|
2014-08-15 13:48:14 +00:00
|
|
|
GST_TIME_ARGS (NLE_OBJECT_START (priv->objects_start->data)),
|
|
|
|
GST_TIME_ARGS (NLE_OBJECT_STOP (priv->objects_start->data)));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
priv->objects_stop = g_list_insert_sorted
|
2014-07-02 19:01:31 +00:00
|
|
|
(priv->objects_stop, object, (GCompareFunc) objects_stop_compare);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* Now the object is ready to be commited and then used */
|
|
|
|
|
|
|
|
beach:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
chiringuito:
|
|
|
|
{
|
|
|
|
update_start_stop_duration (comp);
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_composition_remove_object (GstBin * bin, GstElement * element)
|
2014-10-21 08:35:48 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleObject *object;
|
|
|
|
NleComposition *comp = (NleComposition *) bin;
|
2014-07-02 19:01:31 +00:00
|
|
|
|
|
|
|
if (element == comp->priv->current_bin) {
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_INFO_OBJECT (comp, "Adding internal bin");
|
2014-07-02 19:01:31 +00:00
|
|
|
return GST_BIN_CLASS (parent_class)->remove_element (bin, element);
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
g_return_val_if_fail (NLE_IS_OBJECT (element), FALSE);
|
2014-07-02 19:01:31 +00:00
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
object = NLE_OBJECT (element);
|
2014-07-19 09:41:56 +00:00
|
|
|
|
|
|
|
object->in_composition = FALSE;
|
2014-08-20 11:15:30 +00:00
|
|
|
_add_remove_object_action (comp, object);
|
2014-07-19 09:41:56 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2014-07-02 19:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-15 13:48:14 +00:00
|
|
|
_nle_composition_remove_object (NleComposition * comp, NleObject * object)
|
2014-07-02 19:01:31 +00:00
|
|
|
{
|
2014-08-15 13:48:14 +00:00
|
|
|
NleCompositionPrivate *priv = comp->priv;
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-11 12:17:36 +00:00
|
|
|
GST_DEBUG_OBJECT (comp, "removing object %s", GST_OBJECT_NAME (object));
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-14 14:12:00 +00:00
|
|
|
if (!g_hash_table_contains (priv->objects_hash, object)) {
|
|
|
|
GST_INFO_OBJECT (comp, "object was not in composition");
|
|
|
|
return FALSE;
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
gst_element_set_locked_state (GST_ELEMENT (object), FALSE);
|
2014-07-06 13:46:22 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (object), GST_STATE_NULL);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* handle default source */
|
2014-08-15 13:48:14 +00:00
|
|
|
if (NLE_OBJECT_IS_EXPANDABLE (object)) {
|
2014-10-21 08:35:48 +00:00
|
|
|
/* Find it in the list */
|
2014-07-02 19:01:31 +00:00
|
|
|
priv->expandables = g_list_remove (priv->expandables, object);
|
2014-10-21 08:35:48 +00:00
|
|
|
} else {
|
|
|
|
/* remove it from the objects list and resort the lists */
|
2014-07-02 19:01:31 +00:00
|
|
|
priv->objects_start = g_list_remove (priv->objects_start, object);
|
|
|
|
priv->objects_stop = g_list_remove (priv->objects_stop, object);
|
|
|
|
GST_LOG_OBJECT (object, "Removed from the objects start/stop list");
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 13:48:14 +00:00
|
|
|
if (priv->current && NLE_OBJECT (priv->current->data) == NLE_OBJECT (object))
|
|
|
|
nle_composition_reset_target_pad (comp);
|
2014-06-27 14:26:09 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
g_hash_table_remove (priv->objects_hash, object);
|
2014-10-21 08:35:48 +00:00
|
|
|
|
2014-07-02 19:01:31 +00:00
|
|
|
GST_LOG_OBJECT (object, "Done removing from the composition, now updating");
|
2014-10-21 08:35:48 +00:00
|
|
|
|
|
|
|
/* Make it possible to reuse the same object later */
|
2014-08-15 13:48:14 +00:00
|
|
|
nle_object_reset (NLE_OBJECT (object));
|
2014-07-02 19:01:31 +00:00
|
|
|
gst_object_unref (object);
|
2014-06-24 11:44:13 +00:00
|
|
|
|
2014-07-14 14:12:00 +00:00
|
|
|
return TRUE;
|
2014-10-21 08:35:48 +00:00
|
|
|
}
|