VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_media_source.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_media_source.h
3 *****************************************************************************
4 * Copyright (C) 2018 VLC authors and VideoLAN
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20
21#ifndef VLC_MEDIA_SOURCE_H
22#define VLC_MEDIA_SOURCE_H
23
24#include <vlc_common.h>
25#include <vlc_input_item.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 * \defgroup media_source Media source
34 * \ingroup input
35 * @{
36 */
37
38/**
39 * Media source API aims to manage "services discovery" easily from UI clients.
40 *
41 * A "media source provider", associated to the libvlc instance, allows to
42 * retrieve media sources (each associated to a services discovery module).
43 *
44 * Requesting a services discovery that is not open will automatically open it.
45 * If several "clients" request the same media source (i.e. by requesting the
46 * same name), they will receive the same (refcounted) media source instance.
47 * As soon as a media source is released by all its clients, the associated
48 * services discovery is closed.
49 *
50 * Each media source holds a media tree, used to store both the media
51 * detected by the services discovery and the media detected by preparsing.
52 * Clients may listen to the tree to be notified of changes.
53 *
54 * To preparse a media belonging to a media tree, use vlc_media_tree_Preparse().
55 * If subitems are detected during the preparsing, the media tree is updated
56 * accordingly.
57 */
58
59/**
60 * Media tree.
61 *
62 * Nodes must be traversed with locked held (vlc_media_tree_Lock()).
63 */
64typedef struct vlc_media_tree {
68/**
69 * Callbacks to receive media tree events.
70 */
73 /**
74 * Called when the whole content of a subtree has changed.
75 *
76 * \param playlist the playlist
77 * \param node the node having its children reset (may be root)
78 * \param userdata userdata provided to AddListener()
79 */
80 void
82 void *userdata);
83
84 /**
85 * Called when children has been added to a node.
86 *
87 * The children may themselves contain children, which will not be notified
88 * separately.
89 *
90 * \param playlist the playlist
91 * \param node the node having children added
92 * \param children the children added
93 * \param count the number of children added
94 * \param userdata userdata provided to AddListener()
95 */
96 void
98 input_item_node_t *const children[], size_t count,
99 void *userdata);
100
101 /**
102 * Called when children has been removed from a node.
103 *
104 * \param playlist the playlist
105 * \param node the node having children removed
106 * \param children the children removed
107 * \param count the number of children removed
108 * \param userdata userdata provided to AddListener()
109 */
110 void
112 input_item_node_t *const children[], size_t count,
113 void *userdata);
114
115 /**
116 * Called when the preparsing of a node is complete
117 *
118 * \param tree the media tree
119 * \param node the node being parsed
120 * \param status the reason for the preparsing termination
121 * \param userdata userdata provided to AddListener()
122 */
123 void
125 enum input_item_preparse_status status,
126 void *userdata);
127};
128
129/**
130 * Create an empty media tree.
131 */
134
135/**
136 * Listener for media tree events.
137 */
140/**
141 * Add a listener. The lock must NOT be held.
142 *
143 * \param tree the media tree, unlocked
144 * \param cbs the callbacks (must be valid until the listener
145 * is removed)
146 * \param userdata userdata provided as a parameter in callbacks
147 * \param notify_current_state true to notify the current state immediately via
148 * callbacks
149 */
152 const struct vlc_media_tree_callbacks *cbs,
153 void *userdata, bool notify_current_state);
154
155/**
156 * Remove a listener. The lock must NOT be held.
157 *
158 * \param tree the media tree, unlocked
159 * \param listener the listener identifier returned by
160 * vlc_media_tree_AddListener()
161 */
162VLC_API void
165
166/**
167 * Increase the media tree reference count.
168 *
169 * \param tree the media tree, unlocked
170 */
171VLC_API void
173
174/**
175 * Decrease the media tree reference count.
176 *
177 * Destroy the media tree if it reaches 0.
178 *
179 * \param tree the media tree, unlocked
180 */
181VLC_API void
183
184/**
185 * Lock the media tree (non-recursive).
186 */
187VLC_API void
189
190/**
191 * Unlock the media tree.
192 */
193VLC_API void
195
196/**
197 * Add an item to the media tree.
198 *
199 * \param tree the media tree, locked
200 * \param parent the parent node, belonging to the media tree
201 * \param media the media to add as a child of `parent`
202 */
205 input_item_t *media);
206
207/**
208 * Remove an item from the media tree.
209 *
210 * \param tree the media tree, locked
211 * \param media the media to remove
212 */
213VLC_API bool
215
216/**
217 * Find the node containing the requested input item (and its parent).
218 *
219 * \param tree the media tree, locked
220 * \param media the media to look for in the tree
221 * \param result point to the matching node if the function returns true [OUT]
222 * \param result_parent if not NULL, point to the matching node parent
223 * if the function returns true [OUT]
224 *
225 * \retval true if item was found
226 * \retval false if item was not found
227 */
228VLC_API bool
230 input_item_node_t **result,
231 input_item_node_t **result_parent);
232
233/**
234 * Preparse a media, and expand it in the media tree on subitems added.
235 *
236 * \param tree the media tree (not necessarily locked)
237 * \param libvlc the libvlc instance
238 * \param media the media to preparse
239 * \param id a task identifier
240 */
241VLC_API void
243 input_item_t *media, void *id);
244
245
246/**
247 * Cancel a media tree preparse request
248 *
249 * \param libvlc the libvlc instance
250 * \param id the preparse task id
251 */
252VLC_API void
254
255/**
256 * Media source.
257 *
258 * A media source is associated to a "service discovery". It stores the
259 * detected media in a media tree.
260 */
261typedef struct vlc_media_source_t
267/**
268 * Increase the media source reference count.
269 */
270VLC_API void
272
273/**
274 * Decrease the media source reference count.
275 *
276 * Destroy the media source and close the associated "service discovery" if it
277 * reaches 0.
278 */
279VLC_API void
281
282/**
283 * Media source provider (opaque pointer), used to get media sources.
284 */
287/**
288 * Return the media source provider associated to the libvlc instance.
289 */
292
293/**
294 * Return the media source identified by psz_name.
295 *
296 * The resulting media source must be released by vlc_media_source_Release().
297 */
300 const char *name);
301
302/**
303 * Structure containing the description of a media source.
304 */
312/** List of media source metadata (opaque). */
315/**
316 * Return the list of metadata of available media sources.
317 *
318 * If category is not 0, then only media sources for the requested category are
319 * listed.
320 *
321 * The result must be deleted by vlc_media_source_meta_list_Delete() (if not
322 * null).
323 *
324 * Return NULL either on error or on empty list (this is due to the behavior
325 * of the underlying vlc_sd_GetNames()).
326 *
327 * \param provider the media source provider
328 * \param category the category to list (0 for all)
329 */
332 enum services_discovery_category_e category);
333
334/**
335 * Return the number of items in the list.
336 */
337VLC_API size_t
339
340/**
341 * Return the item at index.
342 */
345
346/**
347 * Delete the list.
348 *
349 * Any struct vlc_media_source_meta retrieved from this list become invalid
350 * after this call.
351 */
352VLC_API void
354
355/** @} */
356
357#ifdef __cplusplus
358}
359#endif
360
361#endif
size_t count
Definition core.c:403
#define VLC_API
Definition fourcc_gen.c:31
struct vlc_media_tree vlc_media_tree_t
Media source API aims to manage "services discovery" easily from UI clients.
vlc_media_source_t * vlc_media_source_provider_GetMediaSource(vlc_media_source_provider_t *, const char *name)
Return the media source identified by psz_name.
Definition media_source.c:259
bool vlc_media_tree_Remove(vlc_media_tree_t *tree, input_item_t *media)
Remove an item from the media tree.
Definition media_tree.c:322
size_t vlc_media_source_meta_list_Count(vlc_media_source_meta_list_t *)
Return the number of items in the list.
Definition media_source.c:331
void vlc_media_source_Release(vlc_media_source_t *)
Decrease the media source reference count.
Definition media_source.c:177
void vlc_media_tree_PreparseCancel(libvlc_int_t *libvlc, void *id)
Cancel a media tree preparse request.
Definition media_tree.c:362
vlc_media_source_provider_t * vlc_media_source_provider_Get(libvlc_int_t *)
Return the media source provider associated to the libvlc instance.
Definition media_source.c:197
void vlc_media_tree_RemoveListener(vlc_media_tree_t *tree, vlc_media_tree_listener_id *listener)
Remove a listener.
Definition media_tree.c:283
void vlc_media_tree_Unlock(vlc_media_tree_t *)
Unlock the media tree.
Definition media_tree.c:233
void vlc_media_tree_Lock(vlc_media_tree_t *)
Lock the media tree (non-recursive).
Definition media_tree.c:226
vlc_media_tree_t * vlc_media_tree_New(void)
Create an empty media tree.
Definition media_tree.c:54
input_item_node_t * vlc_media_tree_Add(vlc_media_tree_t *tree, input_item_node_t *parent, input_item_t *media)
Add an item to the media tree.
Definition media_tree.c:294
void vlc_media_tree_Preparse(vlc_media_tree_t *tree, libvlc_int_t *libvlc, input_item_t *media, void *id)
Preparse a media, and expand it in the media tree on subitems added.
Definition media_tree.c:343
vlc_media_source_meta_list_t * vlc_media_source_provider_List(vlc_media_source_provider_t *, enum services_discovery_category_e category)
Return the list of metadata of available media sources.
Definition media_source.c:279
void vlc_media_source_meta_list_Delete(vlc_media_source_meta_list_t *)
Delete the list.
Definition media_source.c:343
void vlc_media_tree_Hold(vlc_media_tree_t *tree)
Increase the media tree reference count.
Definition media_tree.c:211
struct vlc_media_source_meta * vlc_media_source_meta_list_Get(vlc_media_source_meta_list_t *, size_t index)
Return the item at index.
Definition media_source.c:337
void vlc_media_source_Hold(vlc_media_source_t *)
Increase the media source reference count.
Definition media_source.c:170
void vlc_media_tree_Release(vlc_media_tree_t *tree)
Decrease the media tree reference count.
Definition media_tree.c:218
vlc_media_tree_listener_id * vlc_media_tree_AddListener(vlc_media_tree_t *tree, const struct vlc_media_tree_callbacks *cbs, void *userdata, bool notify_current_state)
Add a listener.
Definition media_tree.c:260
bool vlc_media_tree_Find(vlc_media_tree_t *tree, const input_item_t *media, input_item_node_t **result, input_item_node_t **result_parent)
Find the node containing the requested input item (and its parent).
Definition media_tree.c:309
const char name[16]
Definition httpd.c:1298
Definition vlc_input_item.h:210
Describes an input and is used to spawn input_thread_t objects.
Definition vlc_input_item.h:98
Definition vlc_objects.h:103
Definition media_source.c:274
Structure containing the description of a media source.
Definition vlc_media_source.h:307
char * longname
Definition vlc_media_source.h:309
enum services_discovery_category_e category
Definition vlc_media_source.h:310
char * name
Definition vlc_media_source.h:308
Definition media_source.c:52
Media source.
Definition vlc_media_source.h:263
const char * description
Definition vlc_media_source.h:265
vlc_media_tree_t * tree
Definition vlc_media_source.h:264
Callbacks to receive media tree events.
Definition vlc_media_source.h:73
void(* on_children_added)(vlc_media_tree_t *tree, input_item_node_t *node, input_item_node_t *const children[], size_t count, void *userdata)
Called when children has been added to a node.
Definition vlc_media_source.h:98
void(* on_children_reset)(vlc_media_tree_t *tree, input_item_node_t *node, void *userdata)
Called when the whole content of a subtree has changed.
Definition vlc_media_source.h:82
void(* on_children_removed)(vlc_media_tree_t *tree, input_item_node_t *node, input_item_node_t *const children[], size_t count, void *userdata)
Called when children has been removed from a node.
Definition vlc_media_source.h:112
void(* on_preparse_end)(vlc_media_tree_t *tree, input_item_node_t *node, enum input_item_preparse_status status, void *userdata)
Called when the preparsing of a node is complete.
Definition vlc_media_source.h:125
Definition media_tree.c:36
void * userdata
Definition media_tree.c:38
const struct vlc_media_tree_callbacks * cbs
Definition media_tree.c:37
Media source API aims to manage "services discovery" easily from UI clients.
Definition vlc_media_source.h:65
input_item_node_t root
Definition vlc_media_source.h:66
This file is a collection of common definitions and types.
This file defines functions, structures and enums for input items in vlc.
input_item_preparse_status
Definition vlc_input_item.h:524
This file lists functions and structures for service discovery (SD) in vlc.
services_discovery_category_e
Service discovery categories.
Definition vlc_services_discovery.h:84