Commit graph

169 commits

Author SHA1 Message Date
Sebastian Dröge
a1c0ca3ac0 bus: Make setting/replacing/clearing the sync handler thread-safe
Previously we would use the object lock only for storing the sync
handler and its user_data in a local variable, then unlock it and only
then call the sync handler. Between unlocking and calling the sync
handler it might be unset and the user_data be freed, causing it to be
called with a freed pointer.

To prevent this add a refcounting wrapper struct around the sync
handler, hold the object lock while retrieving it and increasing the
reference count and only actually free it once the reference count
reaches zero.

As a side-effect we can now also allow to actually replace the sync
handler. Previously it was only allowed to clear it after initially
setting it according to the docs, but the code still allowed to clear it
and then set a different one.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/506
2020-02-14 18:51:35 +00:00
Sebastian Dröge
2108c6228a bus: Make removing of signal/bus watches thread-safe
Between getting the GSource with the mutex and destroying it, something
else might've destroyed it already and we would have a dangling pointer.

Keep an additional reference just in case.
2019-02-15 13:23:37 +02:00
Sebastian Dröge
8de3344ecc bus: Don't allow removing signal watches with gst_bus_remove_watch()
Signal watches are reference counted and gst_bus_remove_watch() would
immediately remove it, breaking the reference counting. Only
gst_bus_remove_signal_watch() should be used for removing signal
watches.
2019-02-15 13:21:35 +02:00
Mathieu Duponchelle
9831c9bbdb bus: add missing (out) annotation to get_poll_fd() 2018-07-20 23:52:01 +02:00
Tim-Philipp Müller
2db8e3705f Update for g_type_class_add_private() deprecation in recent GLib
https://gitlab.gnome.org/GNOME/glib/merge_requests/7
2018-06-24 12:49:14 +02:00
Arun Raghavan
b5028383ab gst: Fix up a bunch of GIR annotations
This is mostly on nullable return values, and some other minor ones that
I ran across.

https://bugzilla.gnome.org/show_bug.cgi?id=789319
2018-01-27 10:41:24 +00:00
Umang Jain
52d2891fe3 docs: GstBus: Provide more information for ref/unref during bus watch.
https://bugzilla.gnome.org/show_bug.cgi?id=791588
2017-12-14 09:34:59 +00:00
Tim-Philipp Müller
f05bd2a016 docs: Fix a few gtk-doc warnings
Broken links mostly.
2017-12-07 12:16:57 +00:00
Sebastian Dröge
daa98fc02a gst: Don't ref_sink() GstObject subclasses in instance_init/constructor
This is something bindings can't handle and it causes leaks. Instead
move the ref_sink() to the explicit, new() constructors.

This means that abstract classes, and anything that can have subclasses,
will have to do ref_sink() in their new() function now. Specifically
this affects GstClock and GstControlSource.

https://bugzilla.gnome.org/show_bug.cgi?id=743062
2017-05-17 10:40:37 +03:00
Sebastian Dröge
c77f661f6d bus: Add function to get the file descriptor of the bus
This is useful for integration with other event loops that work by
polling file descriptors. G_IO_IN will always be set whenever a message
is available currently.

https://bugzilla.gnome.org/show_bug.cgi?id=776126
2017-05-09 15:01:46 +02:00
Tim-Philipp Müller
519d64881f Don't use deprecated g_object_newv()
Use g_object_new() instead which nowadays has a shortcut for the
no-properties check. It still does an extra GType check in the
function guard, but there's a pending patch to remove that
and it's hardly going to be a performance issue in practice,
even less so on a system that's compiled without run-time checks.

Alternative would be to move to the new g_object_new_properties()
with a fallback define for older glib versions, but it makes the
code look more unwieldy and doesn't seem worth it.

Fixes deprecation warnings when building against newer GLib versions.

https://bugzilla.gnome.org/show_bug.cgi?id=780903
2017-04-08 09:49:59 +01:00
Thibault Saunier
a87b4551a6 Port gtk-doc comments to their equivalent markdown syntax
Modernizing our documentation and preparing a possible move to hotdoc.
This commits also adds missing @title metadatas to all SECTIONs
2017-01-27 16:36:38 -03:00
Sebastian Dröge
241d0f16f6 poll: #define EWOULDBLOCK to EAGAIN if it's not defined on Windows 2016-06-29 23:24:02 +02:00
Sebastian Dröge
4ff2721810 bus: Make sure to always read the control after popping a message
It might happen that we popped the message before writing of the control
happened. In this case we just have to retry again a bit later, and failure to
do so will cause an additional byte in the control and the GSource /
gst_poll_wait() to always wake up again immediately.

https://bugzilla.gnome.org/show_bug.cgi?id=750397
2016-06-29 21:21:04 +02:00
Guillaume Desmottes
e11539c30b bus: chain up GObject::constructed() to the parent class' implementation
Needed so GstBus can be tracked by the leaks tracer.

https://bugzilla.gnome.org/show_bug.cgi?id=768141
2016-06-28 17:23:17 +03:00
Sebastian Dröge
82e529cea5 Revert "bus: change GstBusSource to hold a weak ref to GstBus"
This reverts commit 894c67e642.
2016-02-29 23:33:03 +02:00
Sebastian Dröge
90b1b1dd96 Revert "bus: Make sure to remove the GPollFD from the GSources when destroying the bus"
This reverts commit 05700a7082.
2016-02-29 23:32:58 +02:00
Sebastian Dröge
05700a7082 bus: Make sure to remove the GPollFD from the GSources when destroying the bus
Otherwise the GSource can look into our already destroyed bus where the
GPollFD is stored.

https://bugzilla.gnome.org/show_bug.cgi?id=762849
2016-02-29 13:41:15 +02:00
James Stevenson
5048155f57 bus: Prevent gst_bus_add_watch_full_unlocked from a segfault if priv->poll == NULL
This happens if the process runs out of file descriptors. Better print
a critical warning instead of just crashing.

https://bugzilla.gnome.org/show_bug.cgi?id=762702
2016-02-26 12:11:30 +02:00
Thiago Santos
894c67e642 bus: change GstBusSource to hold a weak ref to GstBus
When holding a regular ref it will cause the GstBus to never
reach 0 references and it won't be destroyed unless the application
explicitly calls gst_bus_remove_signal_watch().

Switching to weakref will allow the GstBus to be destroyed.
The application is still responsible for destroying the
GSource.

https://bugzilla.gnome.org/show_bug.cgi?id=762552
2016-02-25 14:08:50 -03:00
Tim-Philipp Müller
3b6fa8e81a docs: bus: mention main loop requirement in gst_bus_add_watch() docs 2015-07-13 14:25:42 +01:00
Sebastian Dröge
2064a07feb bus: Add guards against invalid arguments to set_flushing() and poll()
https://bugzilla.gnome.org/show_bug.cgi?id=746871
2015-03-27 10:15:45 +01:00
Sebastian Dröge
d8f572647f bus: Use g_list_free_full() instead of manually unreffing and freeing
Also unref the messages, not the GList nodes.
2015-03-13 15:31:30 +00:00
Sebastian Dröge
f50d809c25 bus: Fix another case where we hold the object lock while unreffing a message 2015-03-13 13:42:46 +00:00
Vivia Nikolaidou
721539dc4f bus: Unreferencing messages outside the lock
Shouldn't take the lock while unreferencing messages, because that may cause
more messages to be sent, which will try to take the lock and cause the app to
hang.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=728777
2015-03-13 13:37:49 +00:00
Tim-Philipp Müller
da7847d1ad message, bus: fix async message delivery
Async message delivery (where the posting thread gets blocked
until the message has been processed and/or freed) was pretty
much completely broken.

For one, don't use GMutex implementation details to check
whether a mutex has been initialized or not, esp. not
implementation details that don't hold true any more with
newer GLib versions where atomic ops and futexes are used
(spotted by Josep Torras). This led to async message
delivery no longer blocking with newer GLib versions on
Linux.

Secondly, after async delivery don't free mutex/GCond
embedded inside the just-freed message structure.

Use a new (private) mini object flag to signal GstMessage
that the message being freed is part of an async delivery
on the bus so that the dispose handler can keep the message
alive and the bus can free it once it's done cleaning up
stuff.
2015-02-17 09:52:09 +00:00
Sebastian Dröge
154eefecc9 Don't compare booleans for equality to TRUE and FALSE
TRUE is 1, but every other non-zero value is also considered true. Comparing
for equality with TRUE would only consider 1 but not the others.

Also normalize booleans in a few places.
2014-12-01 09:51:37 +01:00
Luis de Bethencourt
c42b525848 doc: Do not use deprecated gtk-doc 'Rename to' tag
GObject introspection GTK-Doc tag "Rename to" has been deprecated, changing to
rename-to annotation.

https://bugzilla.gnome.org/show_bug.cgi?id=739514
2014-11-02 15:17:57 +00:00
Linus Svensson
c8b512d2f0 bus: Add a function to remove a bus watch
If a bus watch is added to the non default main context it's not
possible to remove it using g_source_remove().

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=735195
2014-10-14 10:31:18 +02:00
Linus Svensson
b0fff643dc bus: gst_bus_add_watch() can return 0 on error
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=735195
2014-08-28 10:10:37 +03:00
Philippe Normand
b1f2359809 bus: destroy signal watch from the context it was mapped to
Don't rely on g_source_remove() because it operates on the main
context. If a signal watch was added to a new thread-default context
g_source_remove() would have no effect. So simply use
g_source_destroy() to avoid this problem.

Additionally the source_id was removed from GstBusPrivate because it
was redundant with the signal watch GSource also stored in that
structure.

https://bugzilla.gnome.org/show_bug.cgi?id=734716
2014-08-13 18:44:39 +03:00
Evan Nemerson
2759882379 introspection: add missing (nullable) annotations to return values
Support for (nullable) was added to G-I at the same time as nullable
return values.  Previous versions of G-I will not mark return values as
nullable, even when an (allow-none) annotation is present, so it is
not necessary to add (allow-none) annotations for compatibility with
older versions of G-I.

https://bugzilla.gnome.org/show_bug.cgi?id=730957
2014-06-26 18:56:38 +02:00
Evan Nemerson
e10266e3f3 docs: convert NULL, TRUE, and FALSE to %NULL, %TRUE, and %FALSE
This should help improve documentation generated for
languages other than C.

https://bugzilla.gnome.org/show_bug.cgi?id=730961
2014-05-30 00:20:27 +01:00
Tim-Philipp Müller
6eb6d9ec38 docs: remove outdated and pointless 'Last reviewed' lines from docs
They are very confusing for people, and more often than not
also just not very accurate. Seeing 'last reviewed: 2005' in
your docs is not very confidence-inspiring. Let's just remove
those comments.
2014-04-26 21:21:51 +01:00
Jan Schmidt
4d7d3a1c02 Fix extended message handling with gst_bus_pop_timed_filtered()
Make sure extended message types don't get accidentally matched
when not asked for in the mask
2014-03-17 06:29:27 +11:00
Tim-Philipp Müller
5c47cf759a message, bus: do extended message types slightly differently
https://bugzilla.gnome.org/show_bug.cgi?id=678402
2014-03-16 14:38:07 +00:00
Stefan Sauer
8d816e9527 bus: fix the precondition for gst_bus_disable_sync_message_emission()
Use the right variable and invert the test. The precondition should catch
someone calling to once too often.
2013-04-10 21:50:53 +02:00
Stefan Sauer
627d111eb6 bus: update signal docs for gst_bus_enable_sync_message_emission() 2013-04-05 21:24:19 +02:00
Tim-Philipp Müller
666c8c11c6 Fix FSF address
https://bugzilla.gnome.org/show_bug.cgi?id=687520
2012-11-03 20:44:48 +00:00
Sebastian Dröge
314eec4ca6 bus: Add allow-none to the function argument of gst_bus_set_sync_handler()
https://bugzilla.gnome.org/show_bug.cgi?id=681139
2012-08-07 10:46:17 +02:00
Edward Hervey
d3ffa82639 Remove 0.10-related documentation and "Since" markers 2012-07-10 12:03:27 +02:00
Tim-Philipp Müller
c0c79188ca bus, clock: make sure these never have a floating ref
Clear the initial floating ref in the init function for
busses and clocks. These objects can be set on multiple
elements, so there's no clear parent-child relationship
here. Ideally we'd just not make them derive from
GInitiallyUnowned at all, but since we want to keep
using GstObject features for debugging, we'll just do
it like this.

This should also fix some problems with bindings, which
seem to get confused when they get floating refs from
non-constructor functions (or functions annotated to
have a 'transfer full' return type). This works now:

from gi.repository import GObject, Gst

GObject.threads_init()
Gst.init(None)

pipeline=Gst.Pipeline()
bus = pipeline.get_bus()
pipeline.set_state(Gst.State.NULL)
del pipeline;

https://bugzilla.gnome.org/show_bug.cgi?id=679286
https://bugzilla.gnome.org/show_bug.cgi?id=657202
2012-07-09 13:09:45 +01:00
Tim-Philipp Müller
0cb9ad013a Revert "bus: skip gst_bus_create_watch as GSource is not introspectable"
This reverts commit 930e36a89b.

This shouldn't have been pushed, since GSource is now handled
(https://bugzilla.gnome.org/show_bug.cgi?id=657725)
2012-06-26 18:22:33 +01:00
Johan Dahlin
930e36a89b bus: skip gst_bus_create_watch as GSource is not introspectable
https://bugzilla.gnome.org/show_bug.cgi?id=657640
2012-06-26 18:19:18 +01:00
Wim Taymans
6efb5c9b6b bus: add GDestroyNotify to set_sync_handler() 2012-06-20 12:29:35 +02:00
Evan Nemerson
6c6bb0e217 introspection: assorted introspection and documentation fixes
These changes are to clean up syntax issues such as missing colons,
missing spaces, etc., and minor issues such as argument names in
headers not matching the implementation and/or documentation.
2012-06-18 13:11:40 +02:00
Wim Taymans
9aa9751938 review some docs 2012-03-28 18:12:23 +02:00
Sebastian Dröge
9c4c9e3b6b bus: Change the timeout argument type of gst_bus_poll() from GstClockTimeDiff to GstClockTime
This is more consistent with the other GstBus methods that have a timeout.
2012-03-27 12:31:18 +02:00
Sebastian Dröge
cfe71423f0 gst: Remove gstmarshal.[ch] completely and use the generic marshaller
Fixes bug #671130.
2012-03-02 11:05:48 +01:00
Wim Taymans
b95ceeb09b remove some useless includes in .h 2012-02-27 09:48:06 +01:00