1 /*****************************************************************************
2 * renderer_discovery.c : Renderer Discovery functions
3 *****************************************************************************
4 * Copyright(C) 2016 VLC authors and VideoLAN
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.
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.
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 *****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_atomic.h>
29 #include <vlc_renderer_discovery.h>
30 #include <vlc_probe.h>
31 #include <vlc_modules.h>
34 struct vlc_renderer_item_t
40 char *psz_demux_filter
;
46 item_free(vlc_renderer_item_t
*p_item
)
48 free(p_item
->psz_name
);
49 free(p_item
->psz_type
);
50 free(p_item
->psz_sout
);
51 free(p_item
->psz_icon_uri
);
52 free(p_item
->psz_demux_filter
);
57 vlc_renderer_item_new(const char *psz_type
, const char *psz_name
,
58 const char *psz_uri
, const char *psz_extra_sout
,
59 const char *psz_demux_filter
, const char *psz_icon_uri
,
62 assert(psz_uri
!= NULL
);
63 vlc_renderer_item_t
*p_item
= NULL
;
65 vlc_UrlParse(&url
, psz_uri
);
67 if (url
.psz_protocol
== NULL
|| url
.psz_host
== NULL
)
70 p_item
= calloc(1, sizeof(vlc_renderer_item_t
));
71 if (unlikely(p_item
== NULL
))
74 if ((p_item
->psz_type
= strdup(psz_type
)) == NULL
)
78 p_item
->psz_name
= strdup(psz_name
);
79 else if (asprintf(&p_item
->psz_name
, "%s (%s)", url
.psz_protocol
,
81 p_item
->psz_name
= NULL
;
82 if (p_item
->psz_name
== NULL
)
85 if (asprintf(&p_item
->psz_sout
, "%s{ip=%s,port=%u%s%s}",
86 url
.psz_protocol
, url
.psz_host
, url
.i_port
,
87 psz_extra_sout
!= NULL
? "," : "",
88 psz_extra_sout
!= NULL
? psz_extra_sout
: "") == -1)
91 if (psz_icon_uri
&& (p_item
->psz_icon_uri
= strdup(psz_icon_uri
)) == NULL
)
94 if (psz_demux_filter
&& (p_item
->psz_demux_filter
= strdup(psz_demux_filter
)) == NULL
)
97 p_item
->i_flags
= i_flags
;
98 vlc_atomic_rc_init(&p_item
->rc
);
110 vlc_renderer_item_name(const vlc_renderer_item_t
*p_item
)
112 assert(p_item
!= NULL
);
114 return p_item
->psz_name
;
118 vlc_renderer_item_type(const vlc_renderer_item_t
*p_item
)
120 assert(p_item
!= NULL
);
122 return p_item
->psz_type
;
126 vlc_renderer_item_sout(const vlc_renderer_item_t
*p_item
)
128 assert(p_item
!= NULL
);
130 return p_item
->psz_sout
;
134 vlc_renderer_item_icon_uri(const vlc_renderer_item_t
*p_item
)
136 assert(p_item
!= NULL
);
138 return p_item
->psz_icon_uri
;
142 vlc_renderer_item_demux_filter(const vlc_renderer_item_t
*p_item
)
144 assert(p_item
!= NULL
);
146 return p_item
->psz_demux_filter
;
150 vlc_renderer_item_flags(const vlc_renderer_item_t
*p_item
)
152 assert(p_item
!= NULL
);
154 return p_item
->i_flags
;
157 vlc_renderer_item_t
*
158 vlc_renderer_item_hold(vlc_renderer_item_t
*p_item
)
160 assert(p_item
!= NULL
);
162 vlc_atomic_rc_inc(&p_item
->rc
);
167 vlc_renderer_item_release(vlc_renderer_item_t
*p_item
)
169 assert(p_item
!= NULL
);
171 if (vlc_atomic_rc_dec(&p_item
->rc
))
182 vlc_rd_probe_add(vlc_probe_t
*probe
, const char *psz_name
,
183 const char *psz_longname
)
185 struct vlc_rd_probe names
= { strdup(psz_name
), strdup(psz_longname
) };
187 if (unlikely(names
.psz_name
== NULL
|| names
.psz_longname
== NULL
188 || vlc_probe_add(probe
, &names
, sizeof(names
))))
190 free(names
.psz_name
);
191 free(names
.psz_longname
);
194 return VLC_PROBE_CONTINUE
;
197 #undef vlc_rd_get_names
199 vlc_rd_get_names(vlc_object_t
*p_obj
, char ***pppsz_names
,
200 char ***pppsz_longnames
)
203 struct vlc_rd_probe
*p_tab
= vlc_probe(p_obj
, "renderer probe", &i_count
);
211 char **ppsz_names
= vlc_alloc(i_count
+ 1, sizeof(char *));
212 char **ppsz_longnames
= vlc_alloc(i_count
+ 1, sizeof(char *));
214 if (unlikely(ppsz_names
== NULL
|| ppsz_longnames
== NULL
))
217 free(ppsz_longnames
);
222 for (size_t i
= 0; i
< i_count
; i
++)
224 ppsz_names
[i
] = p_tab
[i
].psz_name
;
225 ppsz_longnames
[i
] = p_tab
[i
].psz_longname
;
227 ppsz_names
[i_count
] = ppsz_longnames
[i_count
] = NULL
;
229 *pppsz_names
= ppsz_names
;
230 *pppsz_longnames
= ppsz_longnames
;
234 void vlc_rd_release(vlc_renderer_discovery_t
*p_rd
)
236 module_unneed(p_rd
, p_rd
->p_module
);
237 config_ChainDestroy(p_rd
->p_cfg
);
238 free(p_rd
->psz_name
);
239 vlc_object_release(p_rd
);
242 vlc_renderer_discovery_t
*
243 vlc_rd_new(vlc_object_t
*p_obj
, const char *psz_name
,
244 const struct vlc_renderer_discovery_owner
*restrict owner
)
246 vlc_renderer_discovery_t
*p_rd
;
248 p_rd
= vlc_custom_create(p_obj
, sizeof(*p_rd
), "renderer discovery");
251 free(config_ChainCreate(&p_rd
->psz_name
, &p_rd
->p_cfg
, psz_name
));
253 p_rd
->owner
= *owner
;
254 p_rd
->p_module
= module_need(p_rd
, "renderer_discovery",
255 p_rd
->psz_name
, true);
256 if (p_rd
->p_module
== NULL
)
258 msg_Err(p_rd
, "no suitable renderer discovery module for '%s'",
260 free(p_rd
->psz_name
);
261 config_ChainDestroy(p_rd
->p_cfg
);
262 vlc_object_release(p_rd
);