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#include <vlc_preparser.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 * \defgroup media_source Media source
35 * \ingroup input
36 * @{
37 */
38
39/**
40 * Media source API aims to manage "services discovery" easily from UI clients.
41 *
42 * A "media source provider", associated to the libvlc instance, allows to
43 * retrieve media sources (each associated to a services discovery module).
44 *
45 * Requesting a services discovery that is not open will automatically open it.
46 * If several "clients" request the same media source (i.e. by requesting the
47 * same name), they will receive the same (refcounted) media source instance.
48 * As soon as a media source is released by all its clients, the associated
49 * services discovery is closed.
50 *
51 * Each media source holds a media tree, used to store both the media
52 * detected by the services discovery and the media detected by preparsing.
53 * Clients may listen to the tree to be notified of changes.
54 *
55 * To preparse a media belonging to a media tree, use vlc_media_tree_Preparse().
56 * If subitems are detected during the preparsing, the media tree is updated
57 * accordingly.
58 */
59
60/**
61 * Media tree.
62 *
63 * Nodes must be traversed with locked held (vlc_media_tree_Lock()).
64 */
65typedef struct vlc_media_tree {
69/**
70 * Callbacks to receive media tree events.
71 */
74 /**
75 * Called when the whole content of a subtree has changed.
76 *
77 * \param playlist the playlist
78 * \param node the node having its children reset (may be root)
79 * \param userdata userdata provided to AddListener()
80 */
81 void
83 void *userdata);
84
85 /**
86 * Called when children has been added to a node.
87 *
88 * The children may themselves contain children, which will not be notified
89 * separately.
90 *
91 * \param playlist the playlist
92 * \param node the node having children added
93 * \param children the children added
94 * \param count the number of children added
95 * \param userdata userdata provided to AddListener()
96 */
97 void
99 input_item_node_t *const children[], size_t count,
100 void *userdata);
101
102 /**
103 * Called when children has been removed from a node.
104 *
105 * \param playlist the playlist
106 * \param node the node having children removed
107 * \param children the children removed
108 * \param count the number of children removed
109 * \param userdata userdata provided to AddListener()
110 */
111 void
113 input_item_node_t *const children[], size_t count,
114 void *userdata);
115
116 /**
117 * Called when the preparsing of a node is complete
118 *
119 * \param tree the media tree
120 * \param node the node being parsed
121 * \param status the reason for the preparsing termination
122 * \param userdata userdata provided to AddListener()
123 */
124 void
126 int status, 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 parser a valid preparser
238 * \param media the media to preparse
239 * \returns VLC_PREPARSER_REQ_ID_INVALID in case of error, or a valid id if the
240 * item was scheduled for preparsing. Cancel it vlc_preparser_Cancel().
241 */
244 input_item_t *media);
245
246/**
247 * Media source.
248 *
249 * A media source is associated to a "service discovery". It stores the
250 * detected media in a media tree.
251 */
252typedef struct vlc_media_source_t
258/**
259 * Increase the media source reference count.
260 */
261VLC_API void
263
264/**
265 * Decrease the media source reference count.
266 *
267 * Destroy the media source and close the associated "service discovery" if it
268 * reaches 0.
269 */
270VLC_API void
272
273/**
274 * Media source provider (opaque pointer), used to get media sources.
275 */
278/**
279 * Return the media source provider associated to the libvlc instance.
280 */
283
284/**
285 * Return the media source identified by psz_name.
286 *
287 * The resulting media source must be released by vlc_media_source_Release().
288 */
291 const char *name);
292
293/**
294 * Structure containing the description of a media source.
295 */
303/** List of media source metadata (opaque). */
306/**
307 * Return the list of metadata of available media sources.
308 *
309 * If category is not 0, then only media sources for the requested category are
310 * listed.
311 *
312 * The result must be deleted by vlc_media_source_meta_list_Delete() (if not
313 * null).
314 *
315 * Return NULL either on error or on empty list (this is due to the behavior
316 * of the underlying vlc_sd_GetNames()).
317 *
318 * \param provider the media source provider
319 * \param category the category to list (0 for all)
320 */
323 enum services_discovery_category_e category);
324
325/**
326 * Return the number of items in the list.
327 */
328VLC_API size_t
330
331/**
332 * Return the item at index.
333 */
336
337/**
338 * Delete the list.
339 *
340 * Any struct vlc_media_source_meta retrieved from this list become invalid
341 * after this call.
342 */
343VLC_API void
345
346/** @} */
347
348#ifdef __cplusplus
349}
350#endif
351
352#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:321
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
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:282
void vlc_media_tree_Unlock(vlc_media_tree_t *)
Unlock the media tree.
Definition media_tree.c:232
void vlc_media_tree_Lock(vlc_media_tree_t *)
Lock the media tree (non-recursive).
Definition media_tree.c:225
vlc_media_tree_t * vlc_media_tree_New(void)
Create an empty media tree.
Definition media_tree.c:55
vlc_preparser_req_id vlc_media_tree_Preparse(vlc_media_tree_t *tree, vlc_preparser_t *parser, input_item_t *media)
Preparse a media, and expand it in the media tree on subitems added.
Definition media_tree.c:342
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:293
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:210
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:217
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:259
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:308
size_t vlc_preparser_req_id
Definition vlc_preparser.h:46
const char name[16]
Definition httpd.c:1298
Definition vlc_input_item.h:204
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:298
char * longname
Definition vlc_media_source.h:300
enum services_discovery_category_e category
Definition vlc_media_source.h:301
char * name
Definition vlc_media_source.h:299
Definition media_source.c:52
Media source.
Definition vlc_media_source.h:254
const char * description
Definition vlc_media_source.h:256
vlc_media_tree_t * tree
Definition vlc_media_source.h:255
Callbacks to receive media tree events.
Definition vlc_media_source.h:74
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:99
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:83
void(* on_preparse_end)(vlc_media_tree_t *tree, input_item_node_t *node, int status, void *userdata)
Called when the preparsing of a node is complete.
Definition vlc_media_source.h:126
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:113
Definition media_tree.c:37
void * userdata
Definition media_tree.c:39
const struct vlc_media_tree_callbacks * cbs
Definition media_tree.c:38
Media source API aims to manage "services discovery" easily from UI clients.
Definition vlc_media_source.h:66
input_item_node_t root
Definition vlc_media_source.h:67
Definition preparser.c:41
This file is a collection of common definitions and types.
This file defines functions, structures and enums for input items in vlc.
VLC Preparser API.
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