mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +00:00
tests: wasapi2: Add more device reuse cases
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2402>
This commit is contained in:
parent
5932a853f8
commit
051b5de39e
1 changed files with 131 additions and 17 deletions
|
@ -32,10 +32,12 @@ typedef struct
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
guint n_buffers;
|
guint n_buffers;
|
||||||
guint restart_count;
|
guint restart_count;
|
||||||
|
GstState reuse_state;
|
||||||
} SrcReuseTestData;
|
} SrcReuseTestData;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
bus_handler (GstBus * bus, GstMessage * message, SrcReuseTestData * data)
|
src_reuse_bus_handler (GstBus * bus, GstMessage * message,
|
||||||
|
SrcReuseTestData * data)
|
||||||
{
|
{
|
||||||
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
|
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
|
||||||
GST_ERROR ("Got error message from pipeline");
|
GST_ERROR ("Got error message from pipeline");
|
||||||
|
@ -74,7 +76,7 @@ handle_handoff (SrcReuseTestData * data)
|
||||||
GstStateChangeReturn ret;
|
GstStateChangeReturn ret;
|
||||||
data->n_buffers = 0;
|
data->n_buffers = 0;
|
||||||
|
|
||||||
ret = gst_element_set_state (data->pipeline, GST_STATE_NULL);
|
ret = gst_element_set_state (data->pipeline, data->reuse_state);
|
||||||
fail_unless (ret != GST_STATE_CHANGE_FAILURE);
|
fail_unless (ret != GST_STATE_CHANGE_FAILURE);
|
||||||
|
|
||||||
if (data->restart_count < 2) {
|
if (data->restart_count < 2) {
|
||||||
|
@ -97,8 +99,8 @@ on_sink_handoff (GstElement * element, GstBuffer * buffer, GstPad * pad,
|
||||||
g_idle_add ((GSourceFunc) handle_handoff, data);
|
g_idle_add ((GSourceFunc) handle_handoff, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1110 */
|
static void
|
||||||
GST_START_TEST (test_wasapi2src_reuse)
|
wasapi2src_reuse (GstState reuse_state)
|
||||||
{
|
{
|
||||||
GstBus *bus;
|
GstBus *bus;
|
||||||
GstElement *sink;
|
GstElement *sink;
|
||||||
|
@ -111,6 +113,7 @@ GST_START_TEST (test_wasapi2src_reuse)
|
||||||
data.pipeline = gst_parse_launch ("wasapi2src provide-clock=false ! queue ! "
|
data.pipeline = gst_parse_launch ("wasapi2src provide-clock=false ! queue ! "
|
||||||
"fakesink name=sink async=false", NULL);
|
"fakesink name=sink async=false", NULL);
|
||||||
fail_unless (data.pipeline != NULL);
|
fail_unless (data.pipeline != NULL);
|
||||||
|
data.reuse_state = reuse_state;
|
||||||
|
|
||||||
sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "sink");
|
sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "sink");
|
||||||
fail_unless (sink);
|
fail_unless (sink);
|
||||||
|
@ -121,37 +124,138 @@ GST_START_TEST (test_wasapi2src_reuse)
|
||||||
bus = gst_element_get_bus (GST_ELEMENT (data.pipeline));
|
bus = gst_element_get_bus (GST_ELEMENT (data.pipeline));
|
||||||
fail_unless (bus != NULL);
|
fail_unless (bus != NULL);
|
||||||
|
|
||||||
gst_bus_add_watch (bus, (GstBusFunc) bus_handler, &data);
|
gst_bus_add_watch (bus, (GstBusFunc) src_reuse_bus_handler, &data);
|
||||||
start_pipeline (&data);
|
start_pipeline (&data);
|
||||||
g_main_loop_run (data.loop);
|
g_main_loop_run (data.loop);
|
||||||
|
|
||||||
fail_unless (data.restart_count == 2);
|
fail_unless (data.restart_count == 2);
|
||||||
|
|
||||||
|
gst_element_set_start_time (data.pipeline, GST_STATE_NULL);
|
||||||
|
gst_bus_remove_watch (bus);
|
||||||
|
gst_object_unref (bus);
|
||||||
|
|
||||||
gst_object_unref (data.pipeline);
|
gst_object_unref (data.pipeline);
|
||||||
g_main_loop_unref (data.loop);
|
g_main_loop_unref (data.loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1110 */
|
||||||
|
GST_START_TEST (test_wasapi2src_reuse_null)
|
||||||
|
{
|
||||||
|
wasapi2src_reuse (GST_STATE_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_wasapi2src_reuse_ready)
|
||||||
|
{
|
||||||
|
wasapi2src_reuse (GST_STATE_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GMainLoop *loop;
|
||||||
|
GstElement *pipe;
|
||||||
|
guint rem_st_changes;
|
||||||
|
GstState reuse_state;
|
||||||
|
} SinkPlayReadyTData;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sink_reuse_bus_watch_cb (GstBus * bus, GstMessage * message, gpointer user_data)
|
||||||
|
{
|
||||||
|
fail_unless (message->type != GST_MESSAGE_ERROR);
|
||||||
|
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
state_timer_cb (gpointer user_data)
|
||||||
|
{
|
||||||
|
SinkPlayReadyTData *tdata = user_data;
|
||||||
|
GstState nxt_st = tdata->rem_st_changes % 2 == 1 ?
|
||||||
|
tdata->reuse_state : GST_STATE_PLAYING;
|
||||||
|
|
||||||
|
ASSERT_SET_STATE (tdata->pipe, nxt_st, GST_STATE_CHANGE_SUCCESS);
|
||||||
|
tdata->rem_st_changes--;
|
||||||
|
|
||||||
|
if (tdata->rem_st_changes == 0) {
|
||||||
|
g_main_loop_quit (tdata->loop);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test that the wasapisink can survive the state change
|
||||||
|
* from PLAYING to READY and then back to PLAYING */
|
||||||
|
static void
|
||||||
|
wasapi2sink_reuse (GstState reuse_state)
|
||||||
|
{
|
||||||
|
SinkPlayReadyTData tdata;
|
||||||
|
GstBus *bus;
|
||||||
|
|
||||||
|
tdata.pipe =
|
||||||
|
gst_parse_launch ("audiotestsrc ! wasapi2sink async=false", NULL);
|
||||||
|
fail_unless (tdata.pipe != NULL);
|
||||||
|
bus = gst_element_get_bus (tdata.pipe);
|
||||||
|
fail_unless (bus != NULL);
|
||||||
|
gst_bus_add_watch (bus, sink_reuse_bus_watch_cb, NULL);
|
||||||
|
|
||||||
|
tdata.reuse_state = reuse_state;
|
||||||
|
|
||||||
|
ASSERT_SET_STATE (tdata.pipe, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
|
||||||
|
tdata.rem_st_changes = 3; /* -> READY -> PLAYING -> QUIT */
|
||||||
|
g_timeout_add_seconds (1, state_timer_cb, &tdata);
|
||||||
|
|
||||||
|
tdata.loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
g_main_loop_run (tdata.loop);
|
||||||
|
|
||||||
|
g_main_loop_unref (tdata.loop);
|
||||||
|
gst_bus_remove_watch (bus);
|
||||||
|
gst_object_unref (bus);
|
||||||
|
gst_object_unref (tdata.pipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_START_TEST (test_wasapi2sink_reuse_null)
|
||||||
|
{
|
||||||
|
wasapi2sink_reuse (GST_STATE_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_wasapi2sink_reuse_ready)
|
||||||
|
{
|
||||||
|
wasapi2sink_reuse (GST_STATE_READY);
|
||||||
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
check_wasapi2_src_available (void)
|
check_wasapi2_element (gboolean is_src)
|
||||||
{
|
{
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
GstElement *src;
|
GstElement *elem;
|
||||||
|
const gchar *elem_name;
|
||||||
|
|
||||||
src = gst_element_factory_make ("wasapi2src", NULL);
|
if (is_src)
|
||||||
if (!src) {
|
elem_name = "wasapi2src";
|
||||||
GST_INFO ("wasapisrc is not available");
|
else
|
||||||
|
elem_name = "wasapi2sink";
|
||||||
|
|
||||||
|
elem = gst_element_factory_make (elem_name, NULL);
|
||||||
|
if (!elem) {
|
||||||
|
GST_INFO ("%s is not available", elem_name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GST_STATE_READY is meaning that camera is available */
|
/* GST_STATE_READY is meaning that camera is available */
|
||||||
if (gst_element_set_state (src, GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) {
|
if (gst_element_set_state (elem, GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) {
|
||||||
GST_INFO ("cannot open device");
|
GST_INFO ("cannot open device");
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_element_set_state (src, GST_STATE_NULL);
|
gst_element_set_state (elem, GST_STATE_NULL);
|
||||||
gst_object_unref (src);
|
gst_object_unref (elem);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -162,15 +266,25 @@ wasapi2_suite (void)
|
||||||
Suite *s = suite_create ("wasapi2");
|
Suite *s = suite_create ("wasapi2");
|
||||||
TCase *tc_basic = tcase_create ("general");
|
TCase *tc_basic = tcase_create ("general");
|
||||||
gboolean have_src = FALSE;
|
gboolean have_src = FALSE;
|
||||||
|
gboolean have_sink = FALSE;
|
||||||
|
|
||||||
suite_add_tcase (s, tc_basic);
|
suite_add_tcase (s, tc_basic);
|
||||||
|
|
||||||
have_src = check_wasapi2_src_available ();
|
have_src = check_wasapi2_element (TRUE);
|
||||||
|
have_sink = check_wasapi2_element (FALSE);
|
||||||
|
|
||||||
if (have_src) {
|
if (!have_src && !have_sink) {
|
||||||
tcase_add_test (tc_basic, test_wasapi2src_reuse);
|
GST_INFO ("Skipping tests, wasapi2src/wasapi2sink are unavailable");
|
||||||
} else {
|
} else {
|
||||||
GST_INFO ("Skipping tests, wasapi2src is unavailable");
|
if (have_src) {
|
||||||
|
tcase_add_test (tc_basic, test_wasapi2src_reuse_null);
|
||||||
|
tcase_add_test (tc_basic, test_wasapi2src_reuse_ready);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (have_sink) {
|
||||||
|
tcase_add_test (tc_basic, test_wasapi2sink_reuse_null);
|
||||||
|
tcase_add_test (tc_basic, test_wasapi2sink_reuse_ready);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in a new issue