1 /*****************************************************************************
2 * media_discoverer.c - libvlc smoke test
3 *****************************************************************************
4 * Copyright © 2016 VLC authors, and VideoLAN
6 * This program is free software; you can redistribute it and/or modify
7 * it 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 *****************************************************************************/
26 ml_item_event(const struct libvlc_event_t
*p_ev
, const char *psz_event
)
28 char *psz_mrl
= libvlc_media_get_mrl(p_ev
->u
.media_list_item_added
.item
);
31 test_log("item %s(%d): '%s'\n", psz_event
,
32 p_ev
->u
.media_list_item_added
.index
, psz_mrl
);
37 ml_item_added(const struct libvlc_event_t
*p_ev
, void *p_data
)
40 ml_item_event(p_ev
, "added");
44 ml_item_deleted(const struct libvlc_event_t
*p_ev
, void *p_data
)
47 ml_item_event(p_ev
, "deleted");
51 test_discoverer(libvlc_instance_t
*p_vlc
, const char *psz_name
, bool b_wait
)
53 test_log("creating and starting discoverer %s\n", psz_name
);
55 libvlc_media_discoverer_t
*p_md
=
56 libvlc_media_discoverer_new(p_vlc
, psz_name
);
59 libvlc_media_list_t
*p_ml
= libvlc_media_discoverer_media_list(p_md
);
62 libvlc_event_manager_t
*p_evm
= libvlc_media_list_event_manager(p_ml
);
66 i_ret
= libvlc_event_attach(p_evm
, libvlc_MediaListItemAdded
,
69 i_ret
= libvlc_event_attach(p_evm
, libvlc_MediaListItemDeleted
,
70 ml_item_deleted
, NULL
);
73 if (libvlc_media_discoverer_start(p_md
) == -1)
75 test_log("warn: could not start md (not critical)\n");
79 assert(libvlc_media_discoverer_is_running(p_md
));
82 test_log("Press any keys to stop\n");
85 libvlc_media_discoverer_stop(p_md
);
88 libvlc_event_detach(p_evm
, libvlc_MediaListItemAdded
,
90 libvlc_event_detach(p_evm
, libvlc_MediaListItemDeleted
,
91 ml_item_deleted
, NULL
);
93 libvlc_media_list_release(p_ml
);
94 libvlc_media_discoverer_release(p_md
);
98 main(int i_argc
, char *ppsz_argv
[])
102 char *psz_test_name
= i_argc
> 1 ? ppsz_argv
[1] : NULL
;
104 libvlc_instance_t
*p_vlc
= libvlc_new(test_defaults_nargs
,
106 assert(p_vlc
!= NULL
);
108 if (psz_test_name
!= NULL
)
110 /* Test a specific service discovery from command line */
112 test_discoverer(p_vlc
, psz_test_name
, true);
113 libvlc_release(p_vlc
);
117 for(libvlc_media_discoverer_category_t i_cat
= libvlc_media_discoverer_devices
;
118 i_cat
<= libvlc_media_discoverer_localdirs
; i_cat
++)
120 test_log("== getting list of media_discoverer for %d category ==\n", i_cat
);
122 libvlc_media_discoverer_description_t
**pp_services
;
124 libvlc_media_discoverer_list_get(p_vlc
, i_cat
, &pp_services
);
127 test_log("warn: no discoverers (not critical)\n");
130 assert(pp_services
!= NULL
);
132 for (unsigned int i
= 0; i
< i_count
; ++i
)
134 libvlc_media_discoverer_description_t
*p_service
= pp_services
[i
];
136 assert(i_cat
== p_service
->i_cat
);
137 test_log("= discoverer: name: '%s', longname: '%s' =\n",
138 p_service
->psz_name
, p_service
->psz_longname
);
141 if (!strncasecmp(p_service
->psz_name
, "podcast", 7)
142 || i_cat
== libvlc_media_discoverer_lan
)
144 /* see comment in libvlc_media_discoverer_new() */
147 test_discoverer(p_vlc
, p_service
->psz_name
, false);
150 libvlc_media_discoverer_list_release(pp_services
, i_count
);
152 libvlc_release(p_vlc
);