1 /* GStreamer unit test for wasapi plugin
3 * Copyright (C) 2021 Jakub Janků <janku.jakub.jj@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
26 #include <gst/check/gstcheck.h>
36 bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
38 fail_unless (message->type != GST_MESSAGE_ERROR);
39 return G_SOURCE_CONTINUE;
43 state_timer_cb (gpointer user_data)
45 SinkPlayReadyTData *tdata = user_data;
46 GstState nxt_st = tdata->rem_st_changes % 2 == 1 ?
47 GST_STATE_READY : GST_STATE_PLAYING;
49 ASSERT_SET_STATE (tdata->pipe, nxt_st, GST_STATE_CHANGE_SUCCESS);
50 tdata->rem_st_changes--;
52 if (tdata->rem_st_changes == 0) {
53 g_main_loop_quit (tdata->loop);
54 return G_SOURCE_REMOVE;
56 return G_SOURCE_CONTINUE;
59 /* Test that the wasapisink can survive the state change
60 * from PLAYING to READY and then back to PLAYING */
61 GST_START_TEST (test_sink_play_ready)
63 SinkPlayReadyTData tdata;
66 tdata.pipe = gst_parse_launch ("audiotestsrc ! wasapisink async=false", NULL);
67 fail_unless (tdata.pipe != NULL);
68 bus = gst_element_get_bus (tdata.pipe);
69 fail_unless (bus != NULL);
70 gst_bus_add_watch (bus, bus_watch_cb, NULL);
72 ASSERT_SET_STATE (tdata.pipe, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
73 tdata.rem_st_changes = 3; /* -> READY -> PLAYING -> QUIT */
74 g_timeout_add_seconds (1, state_timer_cb, &tdata);
76 tdata.loop = g_main_loop_new (NULL, FALSE);
77 g_main_loop_run (tdata.loop);
79 g_main_loop_unref (tdata.loop);
80 gst_bus_remove_watch (bus);
81 gst_object_unref (bus);
82 gst_object_unref (tdata.pipe);
88 device_is_available (const gchar * factory_name)
93 elem = gst_element_factory_make (factory_name, NULL);
95 GST_INFO ("%s: not available", factory_name);
99 avail = gst_element_set_state (elem, GST_STATE_READY)
100 == GST_STATE_CHANGE_SUCCESS;
102 GST_INFO ("%s: cannot change state to ready", factory_name);
105 gst_element_set_state (elem, GST_STATE_NULL);
106 gst_object_unref (elem);
114 Suite *suite = suite_create ("wasapi");
115 TCase *tc_sink = tcase_create ("sink");
117 suite_add_tcase (suite, tc_sink);
119 if (device_is_available ("wasapisink")) {
120 tcase_add_test (tc_sink, test_sink_play_ready);
122 GST_INFO ("Sink not available, skipping sink tests");
128 GST_CHECK_MAIN (wasapi)