Commit a24cd3f6 authored by Thomas Guillem's avatar 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.
parent 9114d112
......@@ -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;
......
......@@ -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
......
......@@ -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 )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment