diff --git a/tests/check/elements/decodebin2.c b/tests/check/elements/decodebin2.c index e8b5524300..4523fa6896 100644 --- a/tests/check/elements/decodebin2.c +++ b/tests/check/elements/decodebin2.c @@ -3,6 +3,7 @@ * Copyright (C) 2006 Tim-Philipp Müller * Copyright (C) 2011 Hewlett-Packard Development Company, L.P. * Author: Tim-Philipp Müller , Collabora Ltd. + * Sebastian Dröge , Collabora Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -26,6 +27,7 @@ #include #include +#include #include static const gchar dummytext[] = @@ -361,6 +363,263 @@ GST_START_TEST (test_mp3_parser_loop) GST_END_TEST; +/* Fake parser/decoder for parser_negotiation test */ +static GType gst_fake_h264_parser_get_type (void); +static GType gst_fake_h264_decoder_get_type (void); + +#undef parent_class +#define parent_class fake_h264_parser_parent_class +typedef struct _GstFakeH264Parser GstFakeH264Parser; +typedef GstBaseTransformClass GstFakeH264ParserClass; + +struct _GstFakeH264Parser +{ + GstBaseTransform parent; +}; + +GST_BOILERPLATE (GstFakeH264Parser, gst_fake_h264_parser, GstBaseTransform, + GST_TYPE_BASE_TRANSFORM); + +static void +gst_fake_h264_parser_base_init (gpointer klass) +{ + static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-h264")); + static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-h264, " + "stream-format=(string) { avc, byte-stream }")); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_templ)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_templ)); + gst_element_class_set_details_simple (element_class, + "FakeH264Parser", "Codec/Parser/Converter/Video", "yep", "me"); +} + +static GstFlowReturn +gst_fake_h264_parser_transform (GstBaseTransform * trans, GstBuffer * inbuf, + GstBuffer * outbuf) +{ + return GST_FLOW_OK; +} + +static GstCaps * +gst_fake_h264_parser_transform_caps (GstBaseTransform * trans, + GstPadDirection direction, GstCaps * caps) +{ + if (direction == GST_PAD_SRC) + return gst_caps_from_string ("video/x-h264"); + else + return gst_caps_from_string ("video/x-h264, " + "stream-format=(string) { avc, byte-stream }"); +} + +static gboolean +gst_fake_h264_parser_get_unit_size (GstBaseTransform * trans, GstCaps * caps, + guint * size) +{ + *size = 1; + return TRUE; +} + +static gboolean +gst_fake_h264_parser_set_caps (GstBaseTransform * trans, GstCaps * incaps, + GstCaps * outcaps) +{ + GstStructure *s; + const gchar *stream_format; + + s = gst_caps_get_structure (incaps, 0); + fail_unless (gst_structure_has_name (s, "video/x-h264")); + + s = gst_caps_get_structure (outcaps, 0); + fail_unless (gst_structure_has_name (s, "video/x-h264")); + stream_format = gst_structure_get_string (s, "stream-format"); + fail_unless_equals_string ("byte-stream", stream_format); + + return TRUE; +} + +static void +gst_fake_h264_parser_class_init (GstFakeH264ParserClass * klass) +{ + GstBaseTransformClass *basetrans_class = (GstBaseTransformClass *) klass; + + basetrans_class->transform = gst_fake_h264_parser_transform; + basetrans_class->transform_caps = gst_fake_h264_parser_transform_caps; + basetrans_class->get_unit_size = gst_fake_h264_parser_get_unit_size; + basetrans_class->set_caps = gst_fake_h264_parser_set_caps; +} + +static void +gst_fake_h264_parser_init (GstFakeH264Parser * self, + GstFakeH264ParserClass * klass) +{ +} + +#undef parent_class +#define parent_class fake_h264_decoder_parent_class +typedef struct _GstFakeH264Decoder GstFakeH264Decoder; +typedef GstBaseTransformClass GstFakeH264DecoderClass; + +struct _GstFakeH264Decoder +{ + GstBaseTransform parent; +}; + +GST_BOILERPLATE (GstFakeH264Decoder, gst_fake_h264_decoder, GstBaseTransform, + GST_TYPE_BASE_TRANSFORM); + +static void +gst_fake_h264_decoder_base_init (gpointer klass) +{ + static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-h264, " "stream-format=(string) byte-stream")); + static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-raw-yuv")); + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_templ)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_templ)); + gst_element_class_set_details_simple (element_class, + "FakeH264Decoder", "Codec/Decoder/Video", "yep", "me"); +} + +static GstFlowReturn +gst_fake_h264_decoder_transform (GstBaseTransform * trans, GstBuffer * inbuf, + GstBuffer * outbuf) +{ + return GST_FLOW_OK; +} + +static GstCaps * +gst_fake_h264_decoder_transform_caps (GstBaseTransform * trans, + GstPadDirection direction, GstCaps * caps) +{ + if (direction == GST_PAD_SRC) + return gst_caps_from_string ("video/x-h264, " + "stream-format=(string) byte-stream"); + else + return gst_caps_from_string ("video/x-raw-yuv"); +} + +static gboolean +gst_fake_h264_decoder_get_unit_size (GstBaseTransform * trans, GstCaps * caps, + guint * size) +{ + *size = 1; + return TRUE; +} + +static gboolean +gst_fake_h264_decoder_set_caps (GstBaseTransform * trans, GstCaps * incaps, + GstCaps * outcaps) +{ + GstStructure *s; + const gchar *stream_format; + + s = gst_caps_get_structure (incaps, 0); + fail_unless (gst_structure_has_name (s, "video/x-h264")); + stream_format = gst_structure_get_string (s, "stream-format"); + fail_unless_equals_string ("byte-stream", stream_format); + + s = gst_caps_get_structure (outcaps, 0); + fail_unless (gst_structure_has_name (s, "video/x-raw-yuv")); + + return TRUE; +} + +static void +gst_fake_h264_decoder_class_init (GstFakeH264DecoderClass * klass) +{ + GstBaseTransformClass *basetrans_class = (GstBaseTransformClass *) klass; + + basetrans_class->transform = gst_fake_h264_decoder_transform; + basetrans_class->transform_caps = gst_fake_h264_decoder_transform_caps; + basetrans_class->get_unit_size = gst_fake_h264_decoder_get_unit_size; + basetrans_class->set_caps = gst_fake_h264_decoder_set_caps; +} + +static void +gst_fake_h264_decoder_init (GstFakeH264Decoder * self, + GstFakeH264DecoderClass * klass) +{ +} + +static void +parser_negotiation_pad_added_cb (GstElement * dec, GstPad * pad, + gpointer user_data) +{ + GstBin *pipe = user_data; + GstElement *sink; + GstPad *sinkpad; + + sink = gst_element_factory_make ("fakesink", NULL); + gst_bin_add (pipe, sink); + gst_element_sync_state_with_parent (sink); + sinkpad = gst_element_get_static_pad (sink, "sink"); + gst_pad_link (pad, sinkpad); + gst_object_unref (sinkpad); +} + +GST_START_TEST (test_parser_negotiation) +{ + GstStateChangeReturn sret; + GstMessage *msg; + GstCaps *caps; + GstElement *pipe, *src, *filter, *dec; + + gst_element_register (NULL, "fakeh264parse", GST_RANK_PRIMARY + 101, + gst_fake_h264_parser_get_type ()); + gst_element_register (NULL, "fakeh264dec", GST_RANK_PRIMARY + 100, + gst_fake_h264_decoder_get_type ()); + + pipe = gst_pipeline_new (NULL); + + src = gst_element_factory_make ("fakesrc", NULL); + fail_unless (src != NULL); + g_object_set (G_OBJECT (src), "num-buffers", 5, "sizetype", 2, "filltype", 2, + "can-activate-pull", FALSE, NULL); + + filter = gst_element_factory_make ("capsfilter", NULL); + fail_unless (filter != NULL); + caps = gst_caps_from_string ("video/x-h264"); + g_object_set (G_OBJECT (filter), "caps", caps, NULL); + gst_caps_unref (caps); + + dec = gst_element_factory_make ("decodebin2", NULL); + fail_unless (dec != NULL); + + g_signal_connect (dec, "pad-added", + G_CALLBACK (parser_negotiation_pad_added_cb), pipe); + + gst_bin_add_many (GST_BIN (pipe), src, filter, dec, NULL); + gst_element_link_many (src, filter, dec, NULL); + + sret = gst_element_set_state (pipe, GST_STATE_PLAYING); + fail_unless_equals_int (sret, GST_STATE_CHANGE_ASYNC); + + /* wait for EOS or error */ + msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), + GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); + fail_unless (msg != NULL); + fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); + gst_message_unref (msg); + + gst_element_set_state (pipe, GST_STATE_NULL); + gst_object_unref (pipe); +} + +GST_END_TEST; + static Suite * decodebin2_suite (void) { @@ -371,6 +630,7 @@ decodebin2_suite (void) tcase_add_test (tc_chain, test_text_plain_streams); tcase_add_test (tc_chain, test_reuse_without_decoders); tcase_add_test (tc_chain, test_mp3_parser_loop); + tcase_add_test (tc_chain, test_parser_negotiation); return s; }