composition: remove now useless notion of GnlCompositionEntry.

Co-Authored by: Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
This commit is contained in:
Thibault Saunier 2014-07-14 16:12:00 +02:00
parent caa916e509
commit 0b292ea2dc

View file

@ -86,8 +86,6 @@ static const char *UPDATE_PIPELINE_REASONS[] = {
"Initialize", "Commit", "EOS", "Seek" "Initialize", "Commit", "EOS", "Seek"
}; };
typedef struct _GnlCompositionEntry GnlCompositionEntry;
typedef struct typedef struct
{ {
GnlComposition *comp; GnlComposition *comp;
@ -108,7 +106,7 @@ struct _GnlCompositionPrivate
Sorted List of GnlObjects , ThreadSafe Sorted List of GnlObjects , ThreadSafe
objects_start : sorted by start-time then priority objects_start : sorted by start-time then priority
objects_stop : sorted by stop-time then priority objects_stop : sorted by stop-time then priority
objects_hash : contains signal handlers id for controlled objects objects_hash : contains all controlled objects
objects_lock : mutex to acces/modify any of those lists/hashtable objects_lock : mutex to acces/modify any of those lists/hashtable
*/ */
GList *objects_start; GList *objects_start;
@ -121,9 +119,7 @@ struct _GnlCompositionPrivate
GHashTable *pending_io; GHashTable *pending_io;
GMutex pending_io_lock; GMutex pending_io_lock;
/* source top-level ghostpad, probe and entry */
gulong ghosteventprobe; gulong ghosteventprobe;
GnlCompositionEntry *toplevelentry;
/* current stack, list of GnlObject* */ /* current stack, list of GnlObject* */
GNode *current; GNode *current;
@ -229,9 +225,9 @@ set_child_caps (GValue * item, GValue * ret G_GNUC_UNUSED, GnlObject * comp);
static GstEvent *get_new_seek_event (GnlComposition * comp, gboolean initial, static GstEvent *get_new_seek_event (GnlComposition * comp, gboolean initial,
gboolean updatestoponly); gboolean updatestoponly);
static gboolean static gboolean
_gnl_composition_add_entry (GnlComposition * comp, GnlObject * object); _gnl_composition_add_object (GnlComposition * comp, GnlObject * object);
static gboolean static gboolean
_gnl_composition_remove_entry (GnlComposition * comp, GnlObject * object); _gnl_composition_remove_object (GnlComposition * comp, GnlObject * object);
static void _deactivate_stack (GnlComposition * comp, static void _deactivate_stack (GnlComposition * comp,
gboolean flush_downstream); gboolean flush_downstream);
static gboolean _set_real_eos_seqnum_from_seek (GnlComposition * comp, static gboolean _set_real_eos_seqnum_from_seek (GnlComposition * comp,
@ -249,9 +245,6 @@ static void _restart_task (GnlComposition * comp, gboolean emit_commit);
(MIN (comp->priv->segment->stop, GNL_OBJECT_STOP (comp))) : \ (MIN (comp->priv->segment->stop, GNL_OBJECT_STOP (comp))) : \
GNL_OBJECT_STOP (comp)) GNL_OBJECT_STOP (comp))
#define COMP_ENTRY(comp, object) \
(g_hash_table_lookup (comp->priv->objects_hash, (gconstpointer) object))
#define COMP_OBJECTS_LOCK(comp) G_STMT_START { \ #define COMP_OBJECTS_LOCK(comp) G_STMT_START { \
GST_LOG_OBJECT (comp, "locking objects_lock from thread %p", \ GST_LOG_OBJECT (comp, "locking objects_lock from thread %p", \
g_thread_self()); \ g_thread_self()); \
@ -290,12 +283,6 @@ static void _restart_task (GnlComposition * comp, gboolean emit_commit);
#define GET_TASK_LOCK(comp) (&(GNL_COMPOSITION(comp)->task_rec_lock)) #define GET_TASK_LOCK(comp) (&(GNL_COMPOSITION(comp)->task_rec_lock))
struct _GnlCompositionEntry
{
GnlObject *object;
GnlComposition *comp;
};
static void static void
_remove_all_sources (GnlComposition * comp) _remove_all_sources (GnlComposition * comp)
{ {
@ -530,14 +517,12 @@ _remove_object_func (ChildIOData * childio)
GnlObject *object = childio->object; GnlObject *object = childio->object;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
GnlCompositionEntry *entry;
GnlObject *in_pending_io; GnlObject *in_pending_io;
COMP_OBJECTS_LOCK (comp); COMP_OBJECTS_LOCK (comp);
entry = COMP_ENTRY (comp, object);
in_pending_io = g_hash_table_lookup (priv->pending_io, object); in_pending_io = g_hash_table_lookup (priv->pending_io, object);
if (!entry) { if (!g_hash_table_contains (priv->objects_hash, object)) {
if (in_pending_io) { if (in_pending_io) {
GST_INFO_OBJECT (comp, "Object %" GST_PTR_FORMAT " was marked" GST_INFO_OBJECT (comp, "Object %" GST_PTR_FORMAT " was marked"
" for addition, removing it from the addition list", object); " for addition, removing it from the addition list", object);
@ -599,14 +584,12 @@ _add_object_func (ChildIOData * childio)
GnlComposition *comp = childio->comp; GnlComposition *comp = childio->comp;
GnlObject *object = childio->object; GnlObject *object = childio->object;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
GnlCompositionEntry *entry;
GnlObject *in_pending_io; GnlObject *in_pending_io;
COMP_OBJECTS_LOCK (comp); COMP_OBJECTS_LOCK (comp);
entry = COMP_ENTRY (comp, object);
in_pending_io = g_hash_table_lookup (priv->pending_io, object); in_pending_io = g_hash_table_lookup (priv->pending_io, object);
if (entry) { if (g_hash_table_contains (priv->objects_hash, object)) {
GST_ERROR_OBJECT (comp, "Object %" GST_PTR_FORMAT " is " GST_ERROR_OBJECT (comp, "Object %" GST_PTR_FORMAT " is "
" already in the composition", object); " already in the composition", object);
@ -745,12 +728,6 @@ gnl_composition_class_init (GnlCompositionClass * klass)
GST_DEBUG_FUNCPTR (_initialize_stack_func); GST_DEBUG_FUNCPTR (_initialize_stack_func);
} }
static void
hash_value_destroy (GnlCompositionEntry * entry)
{
g_slice_free (GnlCompositionEntry, entry);
}
static void static void
gnl_composition_init (GnlComposition * comp) gnl_composition_init (GnlComposition * comp)
{ {
@ -770,15 +747,10 @@ gnl_composition_init (GnlComposition * comp)
g_rec_mutex_init (&comp->task_rec_lock); g_rec_mutex_init (&comp->task_rec_lock);
priv->objects_hash = g_hash_table_new_full priv->objects_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
(g_direct_hash,
g_direct_equal, NULL, (GDestroyNotify) hash_value_destroy);
priv->mcontext = g_main_context_new (); priv->mcontext = g_main_context_new ();
g_mutex_init (&priv->mcontext_lock); g_mutex_init (&priv->mcontext_lock);
priv->objects_hash = g_hash_table_new_full
(g_direct_hash,
g_direct_equal, NULL, (GDestroyNotify) hash_value_destroy);
g_mutex_init (&priv->pending_io_lock); g_mutex_init (&priv->pending_io_lock);
priv->pending_io = g_hash_table_new (g_direct_hash, g_direct_equal); priv->pending_io = g_hash_table_new (g_direct_hash, g_direct_equal);
@ -820,7 +792,7 @@ gnl_composition_dispose (GObject * object)
while (iter) { while (iter) {
GList *next = iter->next; GList *next = iter->next;
_gnl_composition_remove_entry (comp, iter->data); _gnl_composition_remove_object (comp, iter->data);
iter = next; iter = next;
} }
@ -843,7 +815,7 @@ gnl_composition_finalize (GObject * object)
while (iter) { while (iter) {
GList *next = iter->next; GList *next = iter->next;
_gnl_composition_remove_entry (comp, iter->data); _gnl_composition_remove_object (comp, iter->data);
iter = next; iter = next;
} }
@ -879,17 +851,12 @@ signal_duration_change (GnlComposition * comp)
static gboolean static gboolean
reset_child (GValue * item, GValue * ret G_GNUC_UNUSED, gpointer user_data) reset_child (GValue * item, GValue * ret G_GNUC_UNUSED, gpointer user_data)
{ {
GnlCompositionEntry *entry; GnlObject *object = g_value_get_object (item);
GstElement *child = g_value_get_object (item);
GnlComposition *comp = GNL_COMPOSITION (user_data);
GnlObject *object;
GstPad *srcpad, *peerpad; GstPad *srcpad, *peerpad;
GST_DEBUG_OBJECT (child, "unlocking state"); GST_DEBUG_OBJECT (object, "unlocking state");
gst_element_set_locked_state (child, FALSE); gst_element_set_locked_state (GST_ELEMENT (object), FALSE);
entry = COMP_ENTRY (comp, child);
object = entry->object;
srcpad = object->srcpad; srcpad = object->srcpad;
peerpad = gst_pad_get_peer (srcpad); peerpad = gst_pad_get_peer (srcpad);
if (peerpad) { if (peerpad) {
@ -1528,17 +1495,14 @@ gnl_composition_reset_target_pad (GnlComposition * comp)
gnl_object_ghost_pad_set_target (GNL_OBJECT (comp), gnl_object_ghost_pad_set_target (GNL_OBJECT (comp),
GNL_OBJECT_SRC (comp), NULL); GNL_OBJECT_SRC (comp), NULL);
priv->toplevelentry = NULL;
priv->send_stream_start = TRUE; priv->send_stream_start = TRUE;
} }
/* gnl_composition_ghost_pad_set_target: /* gnl_composition_ghost_pad_set_target:
* target: The target #GstPad. The refcount will be decremented (given to the ghostpad). * target: The target #GstPad. The refcount will be decremented (given to the ghostpad).
* entry: The GnlCompositionEntry to which the pad belongs
*/ */
static void static void
gnl_composition_ghost_pad_set_target (GnlComposition * comp, GstPad * target, gnl_composition_ghost_pad_set_target (GnlComposition * comp, GstPad * target)
GnlCompositionEntry * entry)
{ {
GstPad *ptarget; GstPad *ptarget;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
@ -1562,9 +1526,6 @@ gnl_composition_ghost_pad_set_target (GnlComposition * comp, GstPad * target,
gnl_object_ghost_pad_set_target ((GnlObject *) comp, gnl_object_ghost_pad_set_target ((GnlObject *) comp,
GNL_OBJECT (comp)->srcpad, target); GNL_OBJECT (comp)->srcpad, target);
/* Set top-level entry (will be NULL if unsetting) */
priv->toplevelentry = entry;
if (target && (priv->ghosteventprobe == 0)) { if (target && (priv->ghosteventprobe == 0)) {
priv->ghosteventprobe = priv->ghosteventprobe =
gst_pad_add_probe (target, gst_pad_add_probe (target,
@ -2011,9 +1972,7 @@ _process_pending_entries (GnlComposition * comp)
g_hash_table_iter_init (&iter, priv->pending_io); g_hash_table_iter_init (&iter, priv->pending_io);
while (g_hash_table_iter_next (&iter, (gpointer *) & object, NULL)) { while (g_hash_table_iter_next (&iter, (gpointer *) & object, NULL)) {
GnlCompositionEntry *entry = COMP_ENTRY (comp, object); if (g_hash_table_contains (priv->objects_hash, object)) {
if (entry) {
if (GST_OBJECT_PARENT (object) == GST_OBJECT_CAST (priv->current_bin) && if (GST_OBJECT_PARENT (object) == GST_OBJECT_CAST (priv->current_bin) &&
deactivated_stack == FALSE) { deactivated_stack == FALSE) {
@ -2022,9 +1981,9 @@ _process_pending_entries (GnlComposition * comp)
_deactivate_stack (comp, TRUE); _deactivate_stack (comp, TRUE);
} }
_gnl_composition_remove_entry (comp, object); _gnl_composition_remove_object (comp, object);
} else { } else {
_gnl_composition_add_entry (comp, object); _gnl_composition_add_object (comp, object);
} }
} }
@ -2692,7 +2651,6 @@ _activate_new_stack (GnlComposition * comp)
{ {
GstPad *pad; GstPad *pad;
GstElement *topelement; GstElement *topelement;
GnlCompositionEntry *topentry;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
@ -2712,12 +2670,11 @@ _activate_new_stack (GnlComposition * comp)
topelement = GST_ELEMENT (priv->current->data); topelement = GST_ELEMENT (priv->current->data);
/* Get toplevel object source pad */ /* Get toplevel object source pad */
pad = GNL_OBJECT_SRC (topelement); pad = GNL_OBJECT_SRC (topelement);
topentry = COMP_ENTRY (comp, topelement);
GST_INFO_OBJECT (comp, GST_INFO_OBJECT (comp,
"We have a valid toplevel element pad %s:%s", GST_DEBUG_PAD_NAME (pad)); "We have a valid toplevel element pad %s:%s", GST_DEBUG_PAD_NAME (pad));
gnl_composition_ghost_pad_set_target (comp, pad, topentry); gnl_composition_ghost_pad_set_target (comp, pad);
GST_DEBUG_OBJECT (comp, "New stack activated!"); GST_DEBUG_OBJECT (comp, "New stack activated!");
@ -2944,11 +2901,9 @@ gnl_composition_add_object (GstBin * bin, GstElement * element)
} }
static gboolean static gboolean
_gnl_composition_add_entry (GnlComposition * comp, GnlObject * object) _gnl_composition_add_object (GnlComposition * comp, GnlObject * object)
{ {
gboolean ret = TRUE; gboolean ret = TRUE;
GnlCompositionEntry *entry;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
GST_DEBUG_OBJECT (comp, "element %s", GST_OBJECT_NAME (object)); GST_DEBUG_OBJECT (comp, "element %s", GST_OBJECT_NAME (object));
@ -2978,11 +2933,6 @@ _gnl_composition_add_entry (GnlComposition * comp, GnlObject * object)
/* lock state of child ! */ /* lock state of child ! */
GST_LOG_OBJECT (comp, "Locking state of %s", GST_ELEMENT_NAME (object)); GST_LOG_OBJECT (comp, "Locking state of %s", GST_ELEMENT_NAME (object));
/* wrap new element in a GnlCompositionEntry ... */
entry = g_slice_new0 (GnlCompositionEntry);
entry->object = (GnlObject *) object;
entry->comp = comp;
if (GNL_OBJECT_IS_EXPANDABLE (object)) { if (GNL_OBJECT_IS_EXPANDABLE (object)) {
/* Only react on non-default objects properties */ /* Only react on non-default objects properties */
g_object_set (object, g_object_set (object,
@ -2995,7 +2945,7 @@ _gnl_composition_add_entry (GnlComposition * comp, GnlObject * object)
} }
/* ...and add it to the hash table */ /* ...and add it to the hash table */
g_hash_table_insert (priv->objects_hash, object, entry); g_hash_table_add (priv->objects_hash, object);
/* Set the caps of the composition */ /* Set the caps of the composition */
if (G_UNLIKELY (!gst_caps_is_any (((GnlObject *) comp)->caps))) if (G_UNLIKELY (!gst_caps_is_any (((GnlObject *) comp)->caps)))
@ -3051,18 +3001,15 @@ gnl_composition_remove_object (GstBin * bin, GstElement * element)
} }
static gboolean static gboolean
_gnl_composition_remove_entry (GnlComposition * comp, GnlObject * object) _gnl_composition_remove_object (GnlComposition * comp, GnlObject * object)
{ {
gboolean ret = FALSE;
GnlCompositionEntry *entry;
GnlCompositionPrivate *priv = comp->priv; GnlCompositionPrivate *priv = comp->priv;
GST_DEBUG_OBJECT (comp, "removing object %s", GST_OBJECT_NAME (object)); GST_DEBUG_OBJECT (comp, "removing object %s", GST_OBJECT_NAME (object));
/* we only accept GnlObject */ if (!g_hash_table_contains (priv->objects_hash, object)) {
entry = COMP_ENTRY (comp, object); GST_INFO_OBJECT (comp, "object was not in composition");
if (entry == NULL) { return FALSE;
goto out;
} }
gst_element_set_locked_state (GST_ELEMENT (object), FALSE); gst_element_set_locked_state (GST_ELEMENT (object), FALSE);
@ -3090,6 +3037,5 @@ _gnl_composition_remove_entry (GnlComposition * comp, GnlObject * object)
gnl_object_reset (GNL_OBJECT (object)); gnl_object_reset (GNL_OBJECT (object));
gst_object_unref (object); gst_object_unref (object);
out: return TRUE;
return ret;
} }