demux: avi: PTSToByte remove useless casts and change type
[vlc.git] / test / libvlc / media_discoverer.c
blob3ab3d825490b8a2278893092543492853f702677
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 *****************************************************************************/
21 #include "test.h"
23 #include <string.h>
25 static void
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);
29 assert(psz_mrl);
31 log("item %s(%d): '%s'\n", psz_event, p_ev->u.media_list_item_added.index,
32 psz_mrl);
33 free(psz_mrl);
36 static void
37 ml_item_added(const struct libvlc_event_t *p_ev, void *p_data)
39 (void) p_data;
40 ml_item_event(p_ev, "added");
43 static void
44 ml_item_deleted(const struct libvlc_event_t *p_ev, void *p_data)
46 (void) p_data;
47 ml_item_event(p_ev, "deleted");
50 static void
51 test_discoverer(libvlc_instance_t *p_vlc, const char *psz_name, bool b_wait)
53 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);
57 assert(p_md != NULL);
59 libvlc_media_list_t *p_ml = libvlc_media_discoverer_media_list(p_md);
60 assert(p_ml != NULL);
62 libvlc_event_manager_t *p_evm = libvlc_media_list_event_manager(p_ml);
63 assert(p_evm);
65 int i_ret;
66 i_ret = libvlc_event_attach(p_evm, libvlc_MediaListItemAdded,
67 ml_item_added, NULL);
68 assert(i_ret == 0);
69 i_ret = libvlc_event_attach(p_evm, libvlc_MediaListItemDeleted,
70 ml_item_deleted, NULL);
71 assert(i_ret == 0);
73 if (libvlc_media_discoverer_start(p_md) == -1)
75 log("warn: could not start md (not critical)\n");
77 else
79 assert(libvlc_media_discoverer_is_running(p_md));
80 if (b_wait)
82 log("Press any keys to stop\n");
83 getchar();
85 libvlc_media_discoverer_stop(p_md);
88 libvlc_event_detach(p_evm, libvlc_MediaListItemAdded,
89 ml_item_added, NULL);
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);
97 int
98 main(int i_argc, char *ppsz_argv[])
100 test_init();
102 char *psz_test_name = i_argc > 1 ? ppsz_argv[1] : NULL;
104 libvlc_instance_t *p_vlc = libvlc_new(test_defaults_nargs,
105 test_defaults_args);
106 assert(p_vlc != NULL);
108 if (psz_test_name != NULL)
110 /* Test a specific service discovery from command line */
111 alarm(0);
112 test_discoverer(p_vlc, psz_test_name, true);
113 libvlc_release(p_vlc);
114 return 0;
117 for(libvlc_media_discoverer_category_t i_cat = libvlc_media_discoverer_devices;
118 i_cat <= libvlc_media_discoverer_localdirs; i_cat ++)
120 log("== getting list of media_discoverer for %d category ==\n", i_cat);
122 libvlc_media_discoverer_description_t **pp_services;
123 ssize_t i_count =
124 libvlc_media_discoverer_list_get(p_vlc, i_cat, &pp_services);
125 if (i_count <= 0)
127 log("warn: no discoverers (not critical)\n");
128 continue;
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 log("= discoverer: name: '%s', longname: '%s' =\n",
138 p_service->psz_name, p_service->psz_longname);
140 #if 0
141 if (!strncasecmp(p_service->psz_name, "podcast", 7)
142 || i_cat == libvlc_media_discoverer_lan)
144 /* see comment in libvlc_media_discoverer_new() */
145 continue;
147 test_discoverer(p_vlc, p_service->psz_name, false);
148 #endif
150 libvlc_media_discoverer_list_release(pp_services, i_count);
152 libvlc_release(p_vlc);
154 return 0;