After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 578933 - Need generic "deep-element-added" signal and/or playbin "element-setup" signal
Need generic "deep-element-added" signal and/or playbin "element-setup" signal
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal enhancement
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 708889 753637 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-04-14 14:52 UTC by Patrick Radizi
Modified: 2016-05-16 09:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
bin: add "element-added-deep" signal (4.57 KB, patch)
2016-05-14 10:29 UTC, Tim-Philipp Müller
none Details | Review
playbin: add "element-setup" signal (3.09 KB, patch)
2016-05-14 10:30 UTC, Tim-Philipp Müller
none Details | Review
bin: add "deep-element-added" and "deep-element-removed" signals (9.45 KB, patch)
2016-05-15 15:04 UTC, Tim-Philipp Müller
committed Details | Review
bin: emit deep-element-{added,removed} for children of newly-added/removed bin (5.07 KB, patch)
2016-05-15 15:04 UTC, Tim-Philipp Müller
committed Details | Review
playbin: add "element-setup" signal (3.09 KB, patch)
2016-05-15 15:05 UTC, Tim-Philipp Müller
none Details | Review
playbin: add "element-setup" signal (3.18 KB, patch)
2016-05-16 08:59 UTC, Tim-Philipp Müller
committed Details | Review

Description Patrick Radizi 2009-04-14 14:52:03 UTC
When using the element-added signal on the playbin2 pipeline, the registered callback function is only called for the 'first half' of the pipline. It's not called when the sink element is added.
Comment 1 Patrick Radizi 2009-06-12 12:12:55 UTC
A small clarification. I use playbin2 to decode a video/audio stream, and the real problem is that the element-added signal is not generated when the decoders are added. This makes it impossible to set properties on these if needed. The fact that there is no element added signal for the sink is a bit less serious since the sink can be set as a property.
Comment 2 Tim-Philipp Müller 2009-06-12 12:33:47 UTC
Have you tried "deep-notify::element-added" as well?
Comment 3 Patrick Radizi 2009-06-18 15:01:49 UTC
Not sure how the deep-notify signal would help. If I understand that signal correct it only fires when a property has changed, but the decoder element is not a property of playbin so I would never get a signal.

Comment 4 Olivier Crête 2009-06-18 15:38:18 UTC
Maybe you should look at FsElementAddedNotifier from farsight2, it is basically a "deep-element-added"
Comment 5 Tim-Philipp Müller 2009-06-19 18:35:33 UTC
Patrick: you are perfectly right of course. Not sure what I was thinking (it was late) :)

What's your use case exactly? What kind of properties do you need to set?
Comment 6 Wim Taymans 2009-06-19 19:14:00 UTC
I think the play was that playbin2 was only going to add the playsink bin when going from NULL->READY and remove it again when doing READY->NULL.
Comment 7 Patrick Radizi 2009-06-23 08:04:35 UTC
I just tested again and now I actually get a signal when decodebin and what's in it gets added! I haven't tested this since I upgraded to gst-plugins-base 10-22. Either I did something wrong before or something has changed, either way all that's in decodebin is now accessible, which is good since that was the most serious problem. 

The only thing still not signaled is the sink part. This is less serious since you can set your own video/audio sink as a property on playbin, but for consistency I think it would still be nice if that worked to. Also, perhaps someone needs to be able to set a property on some of the other elements of vbin or abin? It simply gives an application greater flexibility if all elements of the pipeline is available.

I had a look in playbin2.c and found that the reason that elemtent-added doesn't work for the sink is that the playsink element is added to playbin inside the playbin init function. If this is instead done in the state change function when going from NULL to READY it works a bit better. Then you get a signal for playsink, vbin and abin. However for some unknown reason you still don't get a signal for the elements being added to vbin and abin.


Tim, I'm using decoder and sink for and embedded system using TI hardware. Both elements have a number of properties that needs to be set, device file names, buffer sizes, output resolutions etc etc.
Since playbin can't know anything about this it's up to the application to set these properties 'manually'. This is why I must have access to these elements.
Comment 8 Sebastian Dröge (slomo) 2011-03-28 18:05:19 UTC
You can get playsink from playbin2 by using the GstBin API to get the children of playbin2. You can then get the abin and vbin from playsink by looking at the element-added signal and the elements inside this bins by using the GstBin API again (they are added to abin/vbin before abin/vbin is added to playsink).

Not sure what we can do about this to make it easier
Comment 9 Stefan Sauer (gstreamer, gtkdoc dev) 2011-05-02 10:31:43 UTC
(In reply to comment #8)
> You can get playsink from playbin2 by using the GstBin API to get the children
> of playbin2. You can then get the abin and vbin from playsink by looking at the
> element-added signal and the elements inside this bins by using the GstBin API
> again (they are added to abin/vbin before abin/vbin is added to playsink).
> 
> Not sure what we can do about this to make it easier

What about wims suggestion in comment #6? That sounds good to me.
Comment 10 Sebastian Dröge (slomo) 2011-05-03 07:06:42 UTC
How would that really help? There are still other bins that contain elements before going to READY. Or would you suggest to disallow this and require all bins to add elements when going to READY and removing them again when going back to NULL?

Btw, something like the deep-element-added idea would be nice to have IMHO
Comment 11 Stefan Sauer (gstreamer, gtkdoc dev) 2011-05-03 08:42:17 UTC
(In reply to comment #10)
> How would that really help? There are still other bins that contain elements
> before going to READY. Or would you suggest to disallow this and require all
> bins to add elements when going to READY and removing them again when going
> back to NULL?

Yes, that would be the idea. Otherwise people won't catch elements that are added at bin_init time.

> 
> Btw, something like the deep-element-added idea would be nice to have IMHO
Comment 12 Sebastian Dröge (slomo) 2012-06-11 10:14:43 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > How would that really help? There are still other bins that contain elements
> > before going to READY. Or would you suggest to disallow this and require all
> > bins to add elements when going to READY and removing them again when going
> > back to NULL?
> 
> Yes, that would be the idea. Otherwise people won't catch elements that are
> added at bin_init time.

Or when a child bin is added to a parent bin, a deep-element-added signal is emitted from the parent bin for the child bin and *all* children of that child bin.
Comment 13 Tim-Philipp Müller 2013-09-27 08:24:10 UTC
*** Bug 708889 has been marked as a duplicate of this bug. ***
Comment 14 Tim-Philipp Müller 2015-08-15 09:29:56 UTC
*** Bug 753637 has been marked as a duplicate of this bug. ***
Comment 15 Olivier Crête 2015-08-15 18:29:32 UTC
playbin "element-setup" is not enough for what people have been using FsElementAddedNotifier for, we need it also for encodebin, farstream, etc. Basically, anything that does some kind of auto-plugging. The current implementation is not amazing and we could do something much better inside GstBin. Maybe have GstBin call an internal function on the parent GstBin to emit the "deep-element-added" signal? With a helper function that hooks the signal and calls the callback on all current elements, so it can be easily done race-free, which is a big feature of FsElementAddedNotifier
Comment 16 Tim-Philipp Müller 2015-08-16 07:42:33 UTC
Of course. I think the general feeling is just that something nicer/better can be done from inside GstBin/GStreamer.
Comment 17 Sebastian Dröge (slomo) 2015-08-16 07:44:04 UTC
And that's also where it belongs IMHO, and is more discoverable for users.
Comment 18 Tim-Philipp Müller 2016-05-14 10:29:17 UTC
Created attachment 327864 [details] [review]
bin: add "element-added-deep" signal

This means applications and bin sub-classes can easily track when a new child element is added to the pipeline sub-hierarchy.
Comment 19 Tim-Philipp Müller 2016-05-14 10:30:03 UTC
Created attachment 327865 [details] [review]
playbin: add "element-setup" signal

Allows configuration of plugged elements.
Comment 20 Sebastian Dröge (slomo) 2016-05-15 07:33:35 UTC
Comment on attachment 327864 [details] [review]
bin: add "element-added-deep" signal

This seems asymmetric :) Please add a element_removed_deep too. Also I don't like the name, what about deep-element-added/removed? It's also deep-notify and not notify-deep.
Comment 21 Sebastian Dröge (slomo) 2016-05-15 07:35:05 UTC
(In reply to Sebastian Dröge (slomo) from comment #20)
> Comment on attachment 327864 [details] [review] [review]
> bin: add "element-added-deep" signal
> 
> This seems asymmetric :) Please add a element_removed_deep too. Also I don't
> like the name, what about deep-element-added/removed? It's also deep-notify
> and not notify-deep.

Also maybe when a bin is added to another bin, we would maybe want to recursively emit the signal for everything that is inside the bin? The behaviour should be documented in any case (i.e. that it doesn't do that currently)
Comment 22 Sebastian Dröge (slomo) 2016-05-15 07:36:16 UTC
Review of attachment 327865 [details] [review]:

::: gst/playback/gstplaybin2.c
@@ +3041,3 @@
+{
+  GST_ERROR_OBJECT (playbin, "element %" GST_PTR_FORMAT " was added to "
+      "%" GST_PTR_FORMAT, child, sub_bin);

Debug leftover, this should probably be GST_DEBUG_OBJECT() instead
Comment 23 Tim-Philipp Müller 2016-05-15 08:15:37 UTC
- Name: yes, I didn't like it either, "deep-element-added" works for me

- asymetric: sure, I was going to add an element-removed equivalent too, just didn't make the patch yet.

- I'll try to make it work for the existing hierarchy of a bin being added
Comment 24 Tim-Philipp Müller 2016-05-15 15:04:31 UTC
Created attachment 327935 [details] [review]
bin: add "deep-element-added" and "deep-element-removed" signals
Comment 25 Tim-Philipp Müller 2016-05-15 15:04:58 UTC
Created attachment 327936 [details] [review]
bin: emit deep-element-{added,removed} for children of newly-added/removed bin
Comment 26 Tim-Philipp Müller 2016-05-15 15:05:46 UTC
Created attachment 327937 [details] [review]
playbin: add "element-setup" signal
Comment 27 Tim-Philipp Müller 2016-05-15 15:07:39 UTC
It's symmetric now (add + remove), but we use two more vfunc slots of course, so only two left now.
Comment 28 Sebastian Dröge (slomo) 2016-05-15 15:36:11 UTC
Comment on attachment 327937 [details] [review]
playbin: add "element-setup" signal

You don't emit the signal anywhere :)
Comment 29 Sebastian Dröge (slomo) 2016-05-15 15:38:24 UTC
Review of attachment 327936 [details] [review]:

::: gst/gstbin.c
@@ +1139,3 @@
+      ires = gst_iterator_foreach (it, bin_deep_iterator_foreach, &elements);
+      if (ires != GST_ITERATOR_DONE) {
+        g_queue_foreach (&elements, (GFunc) g_object_unref, NULL);

You can also get RESYNC which is not really a problem and you just iterate again

@@ +1146,3 @@
+      GstElement *e;
+
+      while ((e = g_queue_pop_head (&elements))) {

Why don't you just emit in the foreach function? No lock is taken (which is why you can get RESYNC).
Comment 30 Tim-Philipp Müller 2016-05-15 15:48:31 UTC
> You can also get RESYNC which is not really a problem and
> you just iterate again

Yes, this is handled two lines below those lines you quoted, the while() repeats if we get a RESYNC, but we need to clear the list if we get a RESYNC (or ERROR) otherwise we get duplicate entries in the list.

 
> @@ +1146,3 @@
> +      GstElement *e;
> +
> +      while ((e = g_queue_pop_head (&elements))) {
> 
> Why don't you just emit in the foreach function? No lock is taken (which is
> why you can get RESYNC).

Because then in case of RESYNC we start over and would possibly emit the signal multiple times for the same element, which is not nice. Or obsolete elements. Unless we keep track of the already-emitted elements in a list, which we could also do I suppose (has the advantage that we don't need to put a ref in the list and can just check pointer values).

Doing it the way it is now has the advantage that you are guaranteed to emit the signals for a specific snapshot of the elements at one point in time. Any other way and it might be a mix of old and new I think.
Comment 31 Tim-Philipp Müller 2016-05-16 08:59:52 UTC
Created attachment 327961 [details] [review]
playbin: add "element-setup" signal

This time with actual signal emission :)