[vlc-commits] lib: renderer_discoverer: add item hold/release
Thomas Guillem
git at videolan.org
Wed Jul 26 16:32:55 CEST 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jul 26 16:32:29 2017 +0200| [a24cd3f685f96e463385f3146bd74de17f8c371a] | committer: Thomas Guillem
lib: renderer_discoverer: add item hold/release
Libvlc users need to hold a reference to an item before using it. This avoid
use-after-free if the delete callback is called while an item is used by the
media player.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a24cd3f685f96e463385f3146bd74de17f8c371a
---
include/vlc/libvlc_events.h | 4 ++--
include/vlc/libvlc_renderer_discoverer.h | 26 +++++++++++++++++++++++++-
lib/renderer_discoverer.c | 13 +++++++++++++
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index b69c5ce2be..f8b0e9b5b2 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -277,11 +277,11 @@ typedef struct libvlc_event_t
struct
{
- const libvlc_renderer_item_t *item;
+ libvlc_renderer_item_t *item;
} renderer_discoverer_item_added;
struct
{
- const libvlc_renderer_item_t *item;
+ libvlc_renderer_item_t *item;
} renderer_discoverer_item_deleted;
} u; /**< Type-dependent event description */
} libvlc_event_t;
diff --git a/include/vlc/libvlc_renderer_discoverer.h b/include/vlc/libvlc_renderer_discoverer.h
index 45095061e0..e63a8c9c2a 100644
--- a/include/vlc/libvlc_renderer_discoverer.h
+++ b/include/vlc/libvlc_renderer_discoverer.h
@@ -66,6 +66,29 @@ typedef struct libvlc_rd_description_t
*/
typedef struct libvlc_renderer_item_t libvlc_renderer_item_t;
+
+/**
+ * Hold a renderer item, i.e. creates a new reference
+ *
+ * This functions need to called from the libvlc_RendererDiscovererItemAdded
+ * callback if the libvlc user wants to use this item after. (for display or
+ * for passing it to the mediaplayer for example).
+ *
+ * \version LibVLC 3.0.0 or later
+ *
+ * \return the current item
+ */
+LIBVLC_API libvlc_renderer_item_t *
+libvlc_renderer_item_hold(libvlc_renderer_item_t *p_item);
+
+/**
+ * Releases a renderer item, i.e. decrements its reference counter
+ *
+ * \version LibVLC 3.0.0 or later
+ */
+LIBVLC_API void
+libvlc_renderer_item_release(libvlc_renderer_item_t *p_item);
+
/**
* Get the human readable name of a renderer item
*
@@ -178,7 +201,8 @@ libvlc_renderer_discoverer_stop( libvlc_renderer_discoverer_t *p_rd );
* and @ref libvlc_RendererDiscovererItemDeleted.
*
* The @ref libvlc_renderer_item_t struct passed to event callbacks is owned by
- * VLC, users should take care of copying this struct for their internal usage.
+ * VLC, users should take care of holding/releasing this struct for their
+ * internal usage.
*
* \see libvlc_event_t.u.renderer_discoverer_item_added.item
* \see libvlc_event_t.u.renderer_discoverer_item_removed.item
diff --git a/lib/renderer_discoverer.c b/lib/renderer_discoverer.c
index c2adf26480..a9aaee35c5 100644
--- a/lib/renderer_discoverer.c
+++ b/lib/renderer_discoverer.c
@@ -90,6 +90,19 @@ static void renderer_discovery_item_removed( vlc_renderer_discovery_t *rd,
vlc_renderer_item_release( p_item );
}
+libvlc_renderer_item_t *
+libvlc_renderer_item_hold(libvlc_renderer_item_t *p_item)
+{
+ vlc_renderer_item_hold( (vlc_renderer_item_t *) p_item );
+ return p_item;
+}
+
+void
+libvlc_renderer_item_release(libvlc_renderer_item_t *p_item)
+{
+ vlc_renderer_item_release( (vlc_renderer_item_t *) p_item );
+}
+
const char *
libvlc_renderer_item_name( const libvlc_renderer_item_t *p_item )
{
More information about the vlc-commits
mailing list