demux: mp4: check handler before dereferencing sample entry
[vlc.git] / test / libvlc / renderer_discoverer.c
blobaa60d99b8eededaf37ef395a69cf98ee36ec1e91
1 /*****************************************************************************
2 * renderer_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 item_event(const libvlc_renderer_item_t *p_item, const char *psz_event)
28 log("item %s: name: '%s', type: '%s', flags: 0x%X\n", psz_event,
29 libvlc_renderer_item_name(p_item), libvlc_renderer_item_type(p_item),
30 libvlc_renderer_item_flags(p_item));
33 static void
34 renderer_discoverer_item_added(const struct libvlc_event_t *p_ev, void *p_data)
36 (void) p_data;
37 item_event(p_ev->u.renderer_discoverer_item_added.item, "added");
40 static void
41 renderer_discoverer_item_deleted(const struct libvlc_event_t *p_ev, void *p_data)
43 (void) p_data;
44 item_event(p_ev->u.renderer_discoverer_item_deleted.item, "deleted");
47 static void
48 test_discoverer(libvlc_instance_t *p_vlc, const char *psz_name)
50 log("creating and starting discoverer %s\n", psz_name);
52 libvlc_renderer_discoverer_t *p_rd =
53 libvlc_renderer_discoverer_new(p_vlc, psz_name);
54 assert(p_rd != NULL);
56 libvlc_event_manager_t *p_evm = libvlc_renderer_discoverer_event_manager(p_rd);
57 assert(p_evm);
59 int i_ret;
60 i_ret = libvlc_event_attach(p_evm, libvlc_RendererDiscovererItemAdded,
61 renderer_discoverer_item_added, NULL);
62 assert(i_ret == 0);
63 i_ret = libvlc_event_attach(p_evm, libvlc_RendererDiscovererItemDeleted,
64 renderer_discoverer_item_deleted, NULL);
65 assert(i_ret == 0);
67 if (libvlc_renderer_discoverer_start(p_rd) == -1)
69 log("warn: could not start md (not critical)\n");
71 else
73 log("Press any keys to stop\n");
74 getchar();
75 libvlc_renderer_discoverer_stop(p_rd);
78 libvlc_renderer_discoverer_release(p_rd);
81 int
82 main(int i_argc, char *ppsz_argv[])
84 test_init();
86 char *psz_test_name = i_argc > 1 ? ppsz_argv[1] : NULL;
88 libvlc_instance_t *p_vlc = libvlc_new(test_defaults_nargs,
89 test_defaults_args);
90 assert(p_vlc != NULL);
92 if (psz_test_name != NULL)
94 /* Test a specific service discovery from command line */
95 alarm(0);
96 test_discoverer(p_vlc, psz_test_name);
97 libvlc_release(p_vlc);
98 return 0;
101 log("== getting the list of renderer_discoverer ==\n");
103 libvlc_rd_description_t **pp_services;
104 ssize_t i_count =
105 libvlc_renderer_discoverer_list_get(p_vlc, &pp_services);
106 if (i_count <= 0)
108 log("warn: no discoverers (not critical)\n");
109 goto end;
111 assert(pp_services != NULL);
113 for (unsigned int i = 0; i < i_count; ++i)
115 libvlc_rd_description_t *p_service = pp_services[i];
117 log("= discoverer: name: '%s', longname: '%s' =\n",
118 p_service->psz_name, p_service->psz_longname);
121 libvlc_renderer_discoverer_list_release(pp_services, i_count);
123 end:
124 libvlc_release(p_vlc);
126 return 0;