mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
encodebin: refactor tests
Add a new test to demo how to get missing plugin message. Split some tests that unneccesarily munge unrelated checks into one test.
This commit is contained in:
parent
4dd30bbd16
commit
465dfe4920
1 changed files with 134 additions and 84 deletions
|
@ -23,10 +23,24 @@
|
|||
#endif
|
||||
|
||||
#include <gst/pbutils/encoding-profile.h>
|
||||
#include <gst/pbutils/missing-plugins.h>
|
||||
#include <gst/check/gstcheck.h>
|
||||
|
||||
/* Helper functions to create profiles */
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_ogg_profile ()
|
||||
{
|
||||
GstEncodingContainerProfile *prof;
|
||||
GstCaps *ogg;
|
||||
|
||||
ogg = gst_caps_new_empty_simple ("application/ogg");
|
||||
prof = gst_encoding_container_profile_new ((gchar *) "myprofile", NULL, ogg,
|
||||
NULL);
|
||||
gst_caps_unref (ogg);
|
||||
return (GstEncodingProfile *) prof;
|
||||
}
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_ogg_vorbis_profile (guint presence, gchar * preset)
|
||||
{
|
||||
|
@ -90,6 +104,21 @@ create_vorbis_only_profile (void)
|
|||
return prof;
|
||||
}
|
||||
|
||||
static GstEncodingProfile *
|
||||
create_unsupported_profile (void)
|
||||
{
|
||||
GstEncodingProfile *prof;
|
||||
GstCaps *caps;
|
||||
|
||||
caps = gst_caps_new_empty_simple ("audio/x-bogus");
|
||||
prof =
|
||||
(GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, NULL,
|
||||
0);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
return prof;
|
||||
}
|
||||
|
||||
static void
|
||||
_caps_match (GstPad * sinkpad, const gchar * capsname)
|
||||
{
|
||||
|
@ -107,11 +136,46 @@ _caps_match (GstPad * sinkpad, const gchar * capsname)
|
|||
gst_caps_unref (caps);
|
||||
}
|
||||
|
||||
GST_START_TEST (test_encodebin_states)
|
||||
static void
|
||||
set_profile (GstElement * ebin, GstEncodingProfile * prof)
|
||||
{
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
}
|
||||
|
||||
/* Tests */
|
||||
|
||||
GST_START_TEST (test_encodebin_set_profile)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof, *prof2;
|
||||
GstCaps *ogg;
|
||||
|
||||
/* Create an encodebin and check that it correctly changes states
|
||||
* according to whether a profile is set or not */
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* Set a profile on encodebin... */
|
||||
prof = create_ogg_profile ();
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
/* ... and check the profile has been properly set */
|
||||
g_object_get (ebin, "profile", &prof2, NULL);
|
||||
|
||||
fail_unless (gst_encoding_profile_is_equal (prof, prof2));
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
gst_encoding_profile_unref (prof2);
|
||||
|
||||
gst_object_unref (ebin);
|
||||
};
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_encodebin_can_go_to_ready_without_profile)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstPad *srcpad;
|
||||
GstPad *target;
|
||||
|
||||
|
@ -138,21 +202,28 @@ GST_START_TEST (test_encodebin_states)
|
|||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
|
||||
GST_STATE_CHANGE_FAILURE);
|
||||
|
||||
/* Set back to NULL */
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL),
|
||||
GST_STATE_CHANGE_SUCCESS);
|
||||
|
||||
gst_object_unref (ebin);
|
||||
};
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_encodebin_can_go_to_paused_with_profile)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstPad *srcpad;
|
||||
GstPad *target;
|
||||
|
||||
/* Create an encodebin and check that it correctly changes states
|
||||
* according to whether a profile is set or not */
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* Set a profile on encodebin... */
|
||||
ogg = gst_caps_new_empty_simple ("application/ogg");
|
||||
prof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
|
||||
"myprofile", NULL, ogg, NULL);
|
||||
gst_caps_unref (ogg);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
/* ... and check the profile has been properly set */
|
||||
g_object_get (ebin, "profile", &prof2, NULL);
|
||||
|
||||
fail_unless (gst_encoding_profile_is_equal (prof, prof2));
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
gst_encoding_profile_unref (prof2);
|
||||
set_profile (ebin, create_ogg_profile ());
|
||||
|
||||
/* Make sure we can go to PAUSED */
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
|
||||
|
@ -176,10 +247,10 @@ GST_START_TEST (test_encodebin_states)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
|
||||
GST_START_TEST (test_encodebin_sink_pads_static)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
|
||||
/* Create an encodebin and check that it properly creates the sink pads
|
||||
|
@ -188,11 +259,7 @@ GST_START_TEST (test_encodebin_sink_pads_static)
|
|||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* streamprofile that has a forced presence of 1 */
|
||||
prof = create_ogg_vorbis_profile (1, NULL);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_vorbis_profile (1, NULL));
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
|
||||
GST_STATE_CHANGE_SUCCESS);
|
||||
|
@ -221,17 +288,15 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_preset)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
guint64 max_delay = 0;
|
||||
GstPreset *oggmuxpreset;
|
||||
GstEncodingProfile *prof;
|
||||
|
||||
/* Create an encodebin with a bogus preset and check it fails switching states */
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
oggmuxpreset = GST_PRESET (gst_element_factory_make ("oggmux", NULL));
|
||||
|
||||
/* streamprofile that has a forced presence of 1 */
|
||||
prof = create_ogg_vorbis_profile (1, NULL);
|
||||
/* We also set the name as the load_preset call will reset the element name to
|
||||
* what is described in the preset... which might not be very smart tbh */
|
||||
g_object_set (oggmuxpreset, "max-delay", (guint64) 12, "name",
|
||||
|
@ -240,12 +305,13 @@ GST_START_TEST (test_encodebin_preset)
|
|||
/* Give a name someone should never use outside of that test */
|
||||
gst_preset_save_preset (oggmuxpreset, "test_encodebin_preset");
|
||||
|
||||
/* streamprofile that has a forced presence of 1 */
|
||||
prof = create_ogg_vorbis_profile (1, NULL);
|
||||
|
||||
gst_encoding_profile_set_preset (prof, "test_encodebin_preset");
|
||||
gst_encoding_profile_set_preset_name (prof, "oggmux");
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, prof);
|
||||
|
||||
/* It will go to READY... */
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
|
||||
|
@ -269,18 +335,14 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_sink_pads_nopreset_static)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
|
||||
/* Create an encodebin with a bogus preset and check it fails switching states */
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* streamprofile that has a forced presence of 1 */
|
||||
prof = create_ogg_vorbis_profile (1, (gchar *) "nowaythispresetexists");
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin,
|
||||
create_ogg_vorbis_profile (1, (gchar *) "nowaythispresetexists"));
|
||||
|
||||
/* It will go to READY... */
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_READY),
|
||||
|
@ -299,7 +361,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_sink_pads_dynamic)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
GstPad *srcpad, *sinkpad;
|
||||
GstCaps *sinkcaps;
|
||||
|
||||
|
@ -309,11 +370,7 @@ GST_START_TEST (test_encodebin_sink_pads_dynamic)
|
|||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* streamprofile that has non-forced presence */
|
||||
prof = create_ogg_vorbis_profile (0, NULL);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
|
||||
|
||||
/* Check if the source pad was properly created */
|
||||
srcpad = gst_element_get_static_pad (ebin, "src");
|
||||
|
@ -353,7 +410,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_sink_pads_multiple_static)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
GstPad *srcpad, *sinkpadvorbis, *sinkpadtheora;
|
||||
|
||||
/* Create an encodebin and check that it properly creates the sink pads */
|
||||
|
@ -361,11 +417,7 @@ GST_START_TEST (test_encodebin_sink_pads_multiple_static)
|
|||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* First try is with a streamprofile that has a forced presence of 1 */
|
||||
prof = create_ogg_theora_vorbis_profile (1, 1);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_theora_vorbis_profile (1, 1));
|
||||
|
||||
fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED),
|
||||
GST_STATE_CHANGE_SUCCESS);
|
||||
|
@ -399,7 +451,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_sink_pads_multiple_dynamic)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
GstPad *srcpad, *sinkpadvorbis, *sinkpadtheora;
|
||||
|
||||
/* Create an encodebin and check that it properly creates the sink pads
|
||||
|
@ -408,11 +459,7 @@ GST_START_TEST (test_encodebin_sink_pads_multiple_dynamic)
|
|||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* multi-stream profile that has non-forced presence */
|
||||
prof = create_ogg_theora_vorbis_profile (0, 0);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_theora_vorbis_profile (0, 0));
|
||||
|
||||
/* Check if the source pad was properly created */
|
||||
srcpad = gst_element_get_static_pad (ebin, "src");
|
||||
|
@ -449,7 +496,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_sink_pads_dynamic_encoder)
|
||||
{
|
||||
GstElement *ebin;
|
||||
GstEncodingProfile *prof;
|
||||
GstPad *srcpad, *sinkpad = NULL;
|
||||
GstCaps *vorbiscaps;
|
||||
|
||||
|
@ -459,11 +505,7 @@ GST_START_TEST (test_encodebin_sink_pads_dynamic_encoder)
|
|||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
/* streamprofile that has non-forced presence */
|
||||
prof = create_ogg_vorbis_profile (0, NULL);
|
||||
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
|
||||
|
||||
/* Check if the source pad was properly created */
|
||||
srcpad = gst_element_get_static_pad (ebin, "src");
|
||||
|
@ -494,7 +536,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_render_audio_static)
|
||||
{
|
||||
GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
|
||||
GstEncodingProfile *prof;
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
|
||||
|
@ -507,10 +548,7 @@ GST_START_TEST (test_encodebin_render_audio_static)
|
|||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
prof = create_ogg_vorbis_profile (1, NULL);
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_vorbis_profile (1, NULL));
|
||||
|
||||
gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, ebin, fakesink, NULL);
|
||||
|
||||
|
@ -553,7 +591,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_render_audio_only_static)
|
||||
{
|
||||
GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
|
||||
GstEncodingProfile *prof;
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
GstPad *sinkpad;
|
||||
|
@ -567,10 +604,7 @@ GST_START_TEST (test_encodebin_render_audio_only_static)
|
|||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
prof = create_vorbis_only_profile ();
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_vorbis_only_profile ());
|
||||
|
||||
gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, ebin, fakesink, NULL);
|
||||
|
||||
|
@ -622,7 +656,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_render_audio_dynamic)
|
||||
{
|
||||
GstElement *ebin, *pipeline, *audiotestsrc, *fakesink;
|
||||
GstEncodingProfile *prof;
|
||||
GstBus *bus;
|
||||
GstPad *sinkpad, *srcpad;
|
||||
gboolean done = FALSE;
|
||||
|
@ -636,10 +669,7 @@ GST_START_TEST (test_encodebin_render_audio_dynamic)
|
|||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
prof = create_ogg_vorbis_profile (0, NULL);
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_vorbis_profile (0, NULL));
|
||||
|
||||
gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, ebin, fakesink, NULL);
|
||||
|
||||
|
@ -696,7 +726,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_render_audio_video_static)
|
||||
{
|
||||
GstElement *ebin, *pipeline, *audiotestsrc, *videotestsrc, *fakesink;
|
||||
GstEncodingProfile *prof;
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
|
||||
|
@ -711,10 +740,7 @@ GST_START_TEST (test_encodebin_render_audio_video_static)
|
|||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
prof = create_ogg_theora_vorbis_profile (1, 1);
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_theora_vorbis_profile (1, 1));
|
||||
|
||||
gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, videotestsrc, ebin,
|
||||
fakesink, NULL);
|
||||
|
@ -759,7 +785,6 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_encodebin_render_audio_video_dynamic)
|
||||
{
|
||||
GstElement *ebin, *pipeline, *audiotestsrc, *videotestsrc, *fakesink;
|
||||
GstEncodingProfile *prof;
|
||||
GstBus *bus;
|
||||
gboolean done = FALSE;
|
||||
GstPad *sinkpad1, *sinkpad2, *srcpad;
|
||||
|
@ -775,10 +800,7 @@ GST_START_TEST (test_encodebin_render_audio_video_dynamic)
|
|||
fakesink = gst_element_factory_make ("fakesink", NULL);
|
||||
|
||||
ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
|
||||
prof = create_ogg_theora_vorbis_profile (0, 0);
|
||||
g_object_set (ebin, "profile", prof, NULL);
|
||||
gst_encoding_profile_unref (prof);
|
||||
set_profile (ebin, create_ogg_theora_vorbis_profile (0, 0));
|
||||
|
||||
gst_bin_add_many ((GstBin *) pipeline, audiotestsrc, videotestsrc, ebin,
|
||||
fakesink, NULL);
|
||||
|
@ -1020,6 +1042,31 @@ GST_START_TEST (test_encodebin_named_requests)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_encodebin_missing_plugin_messages)
|
||||
{
|
||||
GstElement *pipeline = gst_pipeline_new ("test");
|
||||
GstBus *bus = gst_pipeline_get_bus ((GstPipeline *) pipeline);
|
||||
GstElement *ebin = gst_element_factory_make ("encodebin", NULL);
|
||||
GstMessage *message;
|
||||
|
||||
/* first add to bin, then set profile */
|
||||
gst_bin_add ((GstBin *) pipeline, ebin);
|
||||
set_profile (ebin, create_unsupported_profile ());
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_READY);
|
||||
|
||||
message = gst_bus_pop_filtered (bus, GST_MESSAGE_ELEMENT);
|
||||
fail_if (message == NULL);
|
||||
fail_if (!gst_is_missing_plugin_message (message));
|
||||
gst_message_unref (message);
|
||||
|
||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||
gst_object_unref (bus);
|
||||
gst_object_unref (pipeline);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static Suite *
|
||||
encodebin_suite (void)
|
||||
{
|
||||
|
@ -1027,7 +1074,9 @@ encodebin_suite (void)
|
|||
TCase *tc_chain = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc_chain);
|
||||
tcase_add_test (tc_chain, test_encodebin_states);
|
||||
tcase_add_test (tc_chain, test_encodebin_set_profile);
|
||||
tcase_add_test (tc_chain, test_encodebin_can_go_to_ready_without_profile);
|
||||
tcase_add_test (tc_chain, test_encodebin_can_go_to_paused_with_profile);
|
||||
tcase_add_test (tc_chain, test_encodebin_sink_pads_static);
|
||||
tcase_add_test (tc_chain, test_encodebin_sink_pads_nopreset_static);
|
||||
tcase_add_test (tc_chain, test_encodebin_preset);
|
||||
|
@ -1043,6 +1092,7 @@ encodebin_suite (void)
|
|||
tcase_add_test (tc_chain, test_encodebin_impossible_element_combination);
|
||||
tcase_add_test (tc_chain, test_encodebin_reuse);
|
||||
tcase_add_test (tc_chain, test_encodebin_named_requests);
|
||||
tcase_add_test (tc_chain, test_encodebin_missing_plugin_messages);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue