static void udpsink_test (gboolean use_buffer_lists) { GstSegment segment; GstElement *udpsink; GstPad *srcpad; GstBufferList *list; guint data_size; list = create_buffer_list (&data_size); udpsink = gst_check_setup_element ("udpsink"); if (use_buffer_lists) set_render_list_function (udpsink); srcpad = gst_check_setup_src_pad_by_name (udpsink, &srctemplate, "sink"); gst_element_set_state (udpsink, GST_STATE_PLAYING); gst_pad_set_active (srcpad, TRUE); gst_pad_push_event (srcpad, gst_event_new_stream_start ("hey there!")); gst_segment_init (&segment, GST_FORMAT_TIME); gst_pad_push_event (srcpad, gst_event_new_segment (&segment)); fail_unless_equals_int (gst_pad_push_list (srcpad, list), GST_FLOW_OK); gst_check_teardown_pad_by_name (udpsink, "sink"); gst_check_teardown_element (udpsink); if (use_buffer_lists) fail_unless_equals_int (data_size, render_list_bytes_received); }
static void check_and_clear_events (gint expected, gboolean compare) { GList *p; GList *r; /* verify that there's as many queued events as expected */ fail_unless_equals_int (g_list_length (myreceivedevents), expected); if (compare) { fail_unless_equals_int (expected, g_list_length (mypushedevents)); /* verify that the events are queued in the expected order */ r = myreceivedevents; p = mypushedevents; while (p != NULL) { fail_unless_equals_pointer (p->data, r->data); p = g_list_next (p); r = g_list_next (r); } } g_list_free_full (myreceivedevents, (GDestroyNotify)gst_event_unref); myreceivedevents = NULL; g_list_free (mypushedevents); mypushedevents = NULL; }
static void _test_negotiation_notify_caps (GObject * src, GParamSpec * pspec, TestNegotiationData * data) { GstCaps *caps; GstStructure *s; gint width, height; gint par_n = 0, par_d = 0; g_object_get (src, "caps", &caps, NULL); if (caps == NULL) return; s = gst_caps_get_structure (caps, 0); fail_unless (gst_structure_get_int (s, "width", &width)); fail_unless (gst_structure_get_int (s, "height", &height)); fail_unless (gst_structure_get_fraction (s, "pixel-aspect-ratio", &par_n, &par_d) || (data->par_n == 1 && data->par_d == 1)); gst_caps_unref (caps); fail_unless_equals_int (width, data->width); fail_unless_equals_int (height, data->height); if (par_n != 0 || par_d != 0) { fail_unless_equals_int (par_n, data->par_n); fail_unless_equals_int (par_d, data->par_d); } data->ok = (width == data->width) && (height == data->height) && (par_n == data->par_n) && (par_d == data->par_d); g_main_loop_quit (data->loop); }
static void test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num) { guint n; GstCaps *outcaps; GST_LOG ("srt test: start_idx = %u, num = %u", start_idx, num); setup_subparse (); for (n = start_idx; n < start_idx + num; ++n) { GstBuffer *buf; buf = buffer_from_static_string (input[n].in); fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); } gst_pad_push_event (mysrcpad, gst_event_new_eos ()); fail_unless_equals_int (g_list_length (buffers), num); outcaps = gst_pad_get_current_caps (mysinkpad); for (n = start_idx; n < start_idx + num; ++n) { const GstStructure *buffer_caps_struct; GstBuffer *buf; GstMapInfo map; buf = g_list_nth_data (buffers, n - start_idx); fail_unless (buf != NULL); fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), input[n].to_ts - input[n].from_ts); gst_buffer_map (buf, &map, GST_MAP_READ); /* can be NULL */ if (map.data != NULL) { /* shouldn't have trailing newline characters */ fail_if (map.size > 0 && map.data[map.size - 1] == '\n'); /* shouldn't include NUL-terminator in data size */ fail_if (map.size > 0 && map.data[map.size - 1] == '\0'); /* but should still have a NUL-terminator behind the declared data */ fail_unless_equals_int (map.data[map.size], '\0'); /* make sure out string matches expected string */ fail_unless_equals_string ((gchar *) map.data, input[n].out); } gst_buffer_unmap (buf, &map); /* check caps */ fail_unless (outcaps != NULL); buffer_caps_struct = gst_caps_get_structure (outcaps, 0); fail_unless (gst_structure_has_name (buffer_caps_struct, "text/x-raw")); fail_unless_equals_string (gst_structure_get_string (buffer_caps_struct, "format"), "pango-markup"); } gst_caps_unref (outcaps); teardown_subparse (); }
static GstFlowReturn gst_test_reverse_negotiation_sink_render (GstBaseSink * bsink, GstBuffer * buffer) { GstTestReverseNegotiationSink *sink = GST_TEST_REVERSE_NEGOTIATION_SINK (bsink); GstCaps *caps = gst_buffer_get_caps (buffer); GstVideoFormat fmt; gint width, height; fail_unless (caps != NULL); fail_unless (gst_video_format_parse_caps (caps, &fmt, &width, &height)); sink->nbuffers++; /* The third buffer is still in the old size * because the ffmpegcolorspaces can't convert * the frame sizes */ if (sink->nbuffers > 3) { fail_unless_equals_int (width, 512); fail_unless_equals_int (height, 128); } gst_caps_unref (caps); return GST_FLOW_OK; }
static void _check_message_level (const gchar * factoryname, GstValidateReportLevel level, const gchar * message_id) { GList *reports; GstElement *element; GstValidateRunner *runner; GstValidateMonitor *monitor; element = gst_element_factory_make (factoryname, NULL); fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE)); runner = gst_validate_runner_new (); monitor = gst_validate_monitor_factory_create (GST_OBJECT (element), runner, NULL); GST_VALIDATE_REPORT (monitor, g_quark_from_string (message_id), "Just some fakery"); reports = gst_validate_runner_get_reports (runner); fail_unless_equals_int (g_list_length (reports), 1); fail_unless_equals_int (((GstValidateReport *) reports->data)->level, level); g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref); gst_object_unref (element); gst_object_unref (monitor); }
static GstFlowReturn gst_test_reverse_negotiation_sink_render (GstBaseSink * bsink, GstBuffer * buffer) { GstTestReverseNegotiationSink *sink = GST_TEST_REVERSE_NEGOTIATION_SINK (bsink); GstCaps *caps; GstVideoInfo info; caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (bsink)); fail_unless (caps != NULL); fail_unless (gst_video_info_from_caps (&info, caps)); sink->nbuffers++; /* The third buffer is still in the old size * because the videoconverts can't convert * the frame sizes */ if (sink->nbuffers > 3) { fail_unless_equals_int (GST_VIDEO_INFO_WIDTH (&info), 512); fail_unless_equals_int (GST_VIDEO_INFO_HEIGHT (&info), 128); } gst_caps_unref (caps); return GST_FLOW_OK; }
static void _test_flow_aggregation (GstFlowReturn flow, GstFlowReturn flow1, GstFlowReturn flow2, GstFlowReturn demux_flow, gboolean should_fail) { GstPad *srcpad; GstValidateReport *report; GstValidatePadMonitor *pmonitor, *pmonitor1, *pmonitor2; GstElement *demuxer = fake_demuxer_new (); GstBin *pipeline = GST_BIN (gst_pipeline_new ("validate-pipeline")); GList *reports; GstValidateRunner *runner; GstValidateMonitor *monitor; fail_unless (g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE)); runner = gst_validate_runner_new (); monitor = gst_validate_monitor_factory_create (GST_OBJECT (pipeline), runner, NULL); gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor)); gst_bin_add (pipeline, demuxer); fake_demuxer_prepare_pads (pipeline, demuxer, runner); srcpad = gst_pad_new ("srcpad1", GST_PAD_SRC); gst_pad_link (srcpad, demuxer->sinkpads->data); fail_unless (gst_pad_activate_mode (srcpad, GST_PAD_MODE_PUSH, TRUE)); gst_check_setup_events_with_stream_id (srcpad, demuxer, NULL, GST_FORMAT_TIME, "the-stream"); pmonitor = _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->data)); pmonitor1 = _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->data)); pmonitor2 = _get_pad_monitor (gst_pad_get_peer (demuxer->srcpads->next->next->data)); pmonitor->last_flow_return = flow; pmonitor1->last_flow_return = flow1; pmonitor2->last_flow_return = flow2; FAKE_DEMUXER (demuxer)->return_value = demux_flow; fail_unless_equals_int (gst_pad_push (srcpad, gst_buffer_new ()), demux_flow); reports = gst_validate_runner_get_reports (runner); if (should_fail) { assert_equals_int (g_list_length (reports), 1); report = reports->data; fail_unless_equals_int (report->level, GST_VALIDATE_REPORT_LEVEL_CRITICAL); fail_unless_equals_int (report->issue->issue_id, WRONG_FLOW_RETURN); } else { assert_equals_int (g_list_length (reports), 0); } g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref); clean_bus (GST_ELEMENT (pipeline)); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); ASSERT_OBJECT_REFCOUNT (pipeline, "ours", 1); check_destroyed (pipeline, demuxer, NULL); check_destroyed (monitor, pmonitor, NULL); }
static void _test_encodebin_reuse (GstEncodingProfile * prof1, GstEncodingProfile * prof2) { GstElement *ebin; ebin = gst_element_factory_make ("encodebin", NULL); /* Set a profile on encodebin... */ if (prof1) g_object_set (ebin, "profile", prof1, NULL); /* Make sure we can go to PAUSED */ fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED), GST_STATE_CHANGE_SUCCESS); /* Set back to NULL */ fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL), GST_STATE_CHANGE_SUCCESS); if (prof2) g_object_set (ebin, "profile", prof2, NULL); /* Make sure we can go to PLAYING */ fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_PAUSED), GST_STATE_CHANGE_SUCCESS); /* Set back to NULL */ fail_unless_equals_int (gst_element_set_state (ebin, GST_STATE_NULL), GST_STATE_CHANGE_SUCCESS); gst_object_unref (ebin); }
static void test_suburi_error_wrongproto (void) { GstElement *playbin, *fakesink; fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, gst_red_video_src_get_type ())); playbin = gst_element_factory_make ("playbin", "playbin"); fail_unless (playbin != NULL, "Failed to create playbin element"); fakesink = gst_element_factory_make ("fakesink", "fakesink"); fail_unless (fakesink != NULL, "Failed to create fakesink element"); ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); g_object_set (playbin, "video-sink", fakesink, NULL); /* wrong protocol for suburi: playbin should just ignore the suburi and * preroll normally */ g_object_set (playbin, "uri", "redvideo://", NULL); g_object_set (playbin, "suburi", "nosuchproto://foo.bar:80", NULL); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), GST_STATE_CHANGE_SUCCESS); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), GST_STATE_CHANGE_ASYNC); fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), GST_STATE_CHANGE_SUCCESS); gst_element_set_state (playbin, GST_STATE_NULL); gst_object_unref (playbin); }
static void test_suburi_error_unknowntype (void) { GstElement *playbin, *fakesink; fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, gst_red_video_src_get_type ())); playbin = gst_element_factory_make ("playbin", "playbin"); fail_unless (playbin != NULL, "Failed to create playbin element"); fakesink = gst_element_factory_make ("fakesink", "fakesink"); fail_unless (fakesink != NULL, "Failed to create fakesink element"); ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); g_object_set (playbin, "video-sink", fakesink, NULL); /* suburi file format unknown: playbin should just ignore the suburi and * preroll normally (if /dev/zero does not exist, this test should behave * the same as test_suburi_error_invalidfile() */ g_object_set (playbin, "uri", "redvideo://", NULL); g_object_set (playbin, "suburi", "file:///dev/zero", NULL); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), GST_STATE_CHANGE_SUCCESS); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), GST_STATE_CHANGE_ASYNC); fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), GST_STATE_CHANGE_SUCCESS); gst_element_set_state (playbin, GST_STATE_NULL); gst_object_unref (playbin); }
void test_flags() { GstElement *element; GError *err = NULL; xmlfile = "test_flags"; std_log(LOG_FILENAME_LINE, "Test Started test_flags"); /* avoid misleading 'no such element' error debug messages when using cvs */ if (!g_getenv ("GST_DEBUG")) gst_debug_set_default_threshold (GST_LEVEL_NONE); /* default behaviour is to return any already constructed bins/elements */ element = gst_parse_launch_full ("fakesrc ! coffeesink", NULL, 0, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element != NULL, "expected partial pipeline/element"); g_error_free (err); err = NULL; gst_object_unref (element); /* test GST_PARSE_FLAG_FATAL_ERRORS */ element = gst_parse_launch_full ("fakesrc ! coffeesink", NULL, GST_PARSE_FLAG_FATAL_ERRORS, &err); fail_unless (err != NULL, "expected error"); fail_unless_equals_int (err->code, GST_PARSE_ERROR_NO_SUCH_ELEMENT); fail_unless (element == NULL, "expected NULL return with FATAL_ERRORS"); g_error_free (err); err = NULL; std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
/* doesn't return a ref to the pixbuf */ static GdkPixbuf * check_message_pixbuf (GstMessage * msg, const gchar * name, gint channels, gboolean has_alpha) { GdkPixbuf *pixbuf; const GstStructure *s; fail_unless (gst_message_get_structure (msg) != NULL); s = gst_message_get_structure (msg); fail_unless_equals_string (gst_structure_get_name (s), name); fail_unless (gst_structure_has_field (s, "pixbuf")); fail_unless (gst_structure_has_field_typed (s, "pixel-aspect-ratio", GST_TYPE_FRACTION)); pixbuf = GDK_PIXBUF (g_value_get_object (gst_structure_get_value (s, "pixbuf"))); fail_unless (GDK_IS_PIXBUF (pixbuf)); fail_unless_equals_int (gdk_pixbuf_get_n_channels (pixbuf), channels); fail_unless_equals_int (gdk_pixbuf_get_has_alpha (pixbuf), has_alpha); fail_unless_equals_int (gdk_pixbuf_get_width (pixbuf), 319); fail_unless_equals_int (gdk_pixbuf_get_height (pixbuf), 241); return pixbuf; }
static void lose_and_recover_test (GstHarness * h, guint16 lost_seq, gconstpointer recbuf, gsize recbuf_size) { guint64 duration = 222222; guint64 timestamp = 111111; GstBuffer *bufout; push_lost_event (h, lost_seq, timestamp, duration, FALSE); bufout = gst_harness_pull (h); fail_unless_equals_int (gst_buffer_get_size (bufout), recbuf_size); fail_unless_equals_int (GST_BUFFER_PTS (bufout), timestamp); fail_unless (gst_buffer_memcmp (bufout, 0, recbuf, recbuf_size) == 0); fail_unless (!GST_BUFFER_FLAG_IS_SET (bufout, GST_RTP_BUFFER_FLAG_REDUNDANT)); gst_buffer_unref (bufout); /* Pushing the next buffer with discont flag set */ bufout = gst_buffer_new (); GST_BUFFER_FLAG_SET (bufout, GST_BUFFER_FLAG_DISCONT); bufout = gst_harness_push_and_pull (h, bufout); /* Checking the flag was unset */ fail_unless (!GST_BUFFER_IS_DISCONT (bufout)); gst_buffer_unref (bufout); }
static void sink_handoff_float32 (GstElement * element, GstBuffer * buffer, GstPad * pad, gpointer user_data) { gint i; GstMapInfo map; gfloat *data; GstCaps *caps, *ccaps; gint n = GPOINTER_TO_INT (user_data); guint64 mask; fail_unless (GST_IS_BUFFER (buffer)); gst_buffer_map (buffer, &map, GST_MAP_READ); data = (gfloat *) map.data; fail_unless_equals_int (map.size, 48000 * 2 * sizeof (gfloat)); fail_unless_equals_int (GST_BUFFER_DURATION (buffer), GST_SECOND); if (n == 0) { GstAudioChannelPosition pos[2] = { GST_AUDIO_CHANNEL_POSITION_NONE, GST_AUDIO_CHANNEL_POSITION_NONE }; gst_audio_channel_positions_to_mask (pos, 2, FALSE, &mask); } else if (n == 1) { GstAudioChannelPosition pos[2] = { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT }; gst_audio_channel_positions_to_mask (pos, 2, FALSE, &mask); } else if (n == 2) { GstAudioChannelPosition pos[2] = { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER }; gst_audio_channel_positions_to_mask (pos, 2, FALSE, &mask); } else { g_assert_not_reached (); } caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, GST_AUDIO_NE (F32), "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT, 48000, "layout", G_TYPE_STRING, "interleaved", "channel-mask", GST_TYPE_BITMASK, mask, NULL); ccaps = gst_pad_get_current_caps (pad); fail_unless (gst_caps_is_equal (caps, ccaps)); gst_caps_unref (ccaps); gst_caps_unref (caps); #ifdef HAVE_VALGRIND if (!(RUNNING_ON_VALGRIND)) #endif for (i = 0; i < 48000 * 2; i += 2) { fail_unless_equals_float (data[i], -1.0); fail_unless_equals_float (data[i + 1], 1.0); } gst_buffer_unmap (buffer, &map); have_data++; }
static void do_test (SubParseInputChunk * input, guint num, const gchar * media_type) { guint n; setup_subparse (); for (n = 0; n < num; ++n) { GstBuffer *buf; buf = buffer_from_static_string (input[n].in); fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); } gst_pad_push_event (mysrcpad, gst_event_new_eos ()); fail_unless_equals_int (g_list_length (buffers), num); for (n = 0; n < num; ++n) { const GstStructure *buffer_caps_struct; GstBuffer *buf; gchar *out; guint out_size; buf = g_list_nth_data (buffers, n); fail_unless (buf != NULL); /* check timestamp */ fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); /* might not be able to put a duration on the last buffer */ if (input[n].to_ts != GST_CLOCK_TIME_NONE) { /* check duration */ fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), input[n].to_ts - input[n].from_ts); } out = (gchar *) GST_BUFFER_DATA (buf); out_size = GST_BUFFER_SIZE (buf); /* shouldn't have trailing newline characters */ fail_if (out_size > 0 && out[out_size - 1] == '\n'); /* shouldn't include NUL-terminator in data size */ fail_if (out_size > 0 && out[out_size - 1] == '\0'); /* but should still have a NUL-terminator behind the declared data */ fail_unless_equals_int (out[out_size], '\0'); /* make sure out string matches expected string */ fail_unless_equals_string (out, input[n].out); /* check caps */ fail_unless (GST_BUFFER_CAPS (buf) != NULL); buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), media_type); } teardown_subparse (); }
static void do_two_buffers_test_apply (gboolean end_contiguous) { GstBuffer *buffer_in, *buffer_out; GList *node; g_object_set (element, "ntp-offset", NTP_OFFSET, "cseq", 0x12345678, "set-e-bit", TRUE, NULL); ASSERT_SET_STATE (element, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS); buffer_in = create_rtp_buffer (TIMESTAMP, FALSE); buffer_out = create_extension_buffer (buffer_in, FALSE, end_contiguous, FALSE, NTP_OFFSET, CSEQ); /* push initial events */ gst_check_setup_events (mysrcpad, element, NULL, GST_FORMAT_TIME); /* Push buffer */ fail_unless_equals_int (gst_pad_push (mysrcpad, buffer_in), GST_FLOW_OK); /* The buffer hasn't been pushed it as the element is waiting for the next * buffer. */ fail_unless_equals_int (g_list_length (buffers), 0); /* push an ntp-offset event to trigger a discontinuty */ fail_unless (gst_pad_push_event (mysrcpad, create_ntp_offset_event (NTP_OFFSET, end_contiguous))); /* A second buffer is pushed */ buffer_in = create_rtp_buffer (TIMESTAMP + 1, FALSE); fail_unless_equals_int (gst_pad_push (mysrcpad, buffer_in), GST_FLOW_OK); /* The first buffer has now been pushed out */ fail_unless_equals_int (g_list_length (buffers), 1); node = g_list_last (buffers); check_buffer_equal ((GstBuffer *) node->data, buffer_out); gst_buffer_unref (buffer_out); /* Push EOS */ fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ())); /* The second buffer has been pushed out */ fail_unless_equals_int (g_list_length (buffers), 2); /* Last buffer always has the 'E' flag */ buffer_out = create_extension_buffer (buffer_in, FALSE, TRUE, end_contiguous, NTP_OFFSET, CSEQ); node = g_list_last (buffers); check_buffer_equal ((GstBuffer *) node->data, buffer_out); gst_buffer_unref (buffer_out); ASSERT_SET_STATE (element, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); }
static void test_passthrough (int method) { GList *l1, *l2, *src_buffers = NULL, *sink_buffers = NULL; GstCaps **allowed_caps = NULL, **p; static const gint src_width = 640, src_height = 480; static const gint dest_width = 640, dest_height = 480; p = allowed_caps = videoscale_get_allowed_caps_for_method (method); while (*p) { GstCaps *caps = *p; /* skip formats that videoconvert can't handle */ if (!videoconvert_supports_caps (caps)) goto next; GST_DEBUG ("Running test for caps '%" GST_PTR_FORMAT "'" " from %dx%u to %dx%d with method %d", caps, src_width, src_height, dest_width, dest_height, method); run_test (caps, src_width, src_height, dest_width, dest_height, method, G_CALLBACK (on_src_handoff_passthrough), &src_buffers, G_CALLBACK (on_sink_handoff_passthrough), &sink_buffers); fail_unless (src_buffers && sink_buffers); fail_unless_equals_int (g_list_length (src_buffers), g_list_length (sink_buffers)); for (l1 = src_buffers, l2 = sink_buffers; l1 && l2; l1 = l1->next, l2 = l2->next) { GstBuffer *a = l1->data; GstBuffer *b = l2->data; GstMapInfo mapa, mapb; gst_buffer_map (a, &mapa, GST_MAP_READ); gst_buffer_map (b, &mapb, GST_MAP_READ); fail_unless_equals_int (mapa.size, mapb.size); fail_unless (mapa.data == mapb.data); gst_buffer_unmap (b, &mapb); gst_buffer_unmap (a, &mapa); gst_buffer_unref (a); gst_buffer_unref (b); } g_list_free (src_buffers); src_buffers = NULL; g_list_free (sink_buffers); sink_buffers = NULL; next: gst_caps_unref (caps); p++; } g_free (allowed_caps); }
static void compare_buffer (GstBuffer * buf, const guint8 * data, gsize size) { GstMapInfo map; gst_buffer_map (buf, &map, GST_MAP_READ); fail_unless_equals_int (map.size, size); fail_unless_equals_int (memcmp (map.data, data, size), 0); gst_buffer_unmap (buf, &map); }
static void check_buf_type_timestamp (GstBuffer * buf, gint packet_type, gint timestamp) { GstMapInfo map = GST_MAP_INFO_INIT; gst_buffer_map (buf, &map, GST_MAP_READ); fail_unless_equals_int (packet_type, map.data[0]); fail_unless_equals_int (timestamp, map.data[6]); gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); }
void test_preference_passthrough() { GstStateChangeReturn ret; GstElement *pipeline, *src; GstStructure *s; GstMessage *msg; GstCaps *caps; GstPad *pad; GstBus *bus; GError *error = NULL; gint rate = 0; xmlfile = "test_preference_passthrough"; std_log(LOG_FILENAME_LINE, "Test Started test_preference_passthrough"); pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! " "audioresample ! " "audio/x-raw-int,rate=8000,channels=1,width=16,depth=16,signed=(boolean)true,endianness=(int)BYTE_ORDER ! " "fakesink can-activate-pull=0 ", &error); fail_unless (pipeline != NULL, "Error parsing pipeline: %s", error ? error->message : "(invalid error)"); ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC); /* run until we receive EOS */ bus = gst_element_get_bus (pipeline); fail_if (bus == NULL); msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS); gst_message_unref (msg); gst_object_unref (bus); src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); fail_unless (src != NULL); pad = gst_element_get_static_pad (src, "src"); fail_unless (pad != NULL); caps = gst_pad_get_negotiated_caps (pad); GST_LOG ("negotiated audiotestsrc caps: %" GST_PTR_FORMAT, caps); fail_unless (caps != NULL); s = gst_caps_get_structure (caps, 0); fail_unless (gst_structure_get_int (s, "rate", &rate)); /* there's no need to resample, audiotestsrc supports any rate, so make * sure audioresample provided upstream with the right caps to negotiate * this correctly */ fail_unless_equals_int (rate, 8000); gst_caps_unref (caps); gst_object_unref (pad); gst_object_unref (src); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static void test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num) { guint n; GST_LOG ("srt test: start_idx = %u, num = %u", start_idx, num); setup_subparse (); for (n = start_idx; n < start_idx + num; ++n) { GstBuffer *buf; buf = buffer_from_static_string (input[n].in); fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); } gst_pad_push_event (mysrcpad, gst_event_new_eos ()); fail_unless_equals_int (g_list_length (buffers), num); for (n = start_idx; n < start_idx + num; ++n) { const GstStructure *buffer_caps_struct; GstBuffer *buf; gchar *out; guint out_size; buf = g_list_nth_data (buffers, n - start_idx); fail_unless (buf != NULL); fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), input[n].to_ts - input[n].from_ts); out = (gchar *) GST_BUFFER_DATA (buf); out_size = GST_BUFFER_SIZE (buf); /* shouldn't have trailing newline characters */ fail_if (out_size > 0 && out[out_size - 1] == '\n'); /* shouldn't include NUL-terminator in data size */ fail_if (out_size > 0 && out[out_size - 1] == '\0'); /* but should still have a NUL-terminator behind the declared data */ fail_unless_equals_int (out[out_size], '\0'); /* make sure out string matches expected string */ fail_unless_equals_string (out, input[n].out); /* check caps */ fail_unless (GST_BUFFER_CAPS (buf) != NULL); buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), "text/x-pango-markup"); } teardown_subparse (); }
static void test_passthrough (int method) { GList *l1, *l2, *src_buffers = NULL, *sink_buffers = NULL; GstCaps **allowed_caps = NULL, **p; static const gint src_width = 640, src_height = 480; static const gint dest_width = 640, dest_height = 480; p = allowed_caps = videoscale_get_allowed_caps_for_method (method); while (*p) { GstCaps *caps = *p; /* skip formats that ffmpegcolorspace can't handle */ if (caps_are_64bpp (caps)) goto skip; GST_DEBUG ("Running test for caps '%" GST_PTR_FORMAT "'" " from %dx%u to %dx%d with method %d", caps, src_width, src_height, dest_width, dest_height, method); run_test (caps, src_width, src_height, dest_width, dest_height, method, G_CALLBACK (on_src_handoff_passthrough), &src_buffers, G_CALLBACK (on_sink_handoff_passthrough), &sink_buffers); fail_unless (src_buffers && sink_buffers); fail_unless_equals_int (g_list_length (src_buffers), g_list_length (sink_buffers)); for (l1 = src_buffers, l2 = sink_buffers; l1 && l2; l1 = l1->next, l2 = l2->next) { GstBuffer *a = l1->data; GstBuffer *b = l2->data; fail_unless_equals_int (GST_BUFFER_SIZE (a), GST_BUFFER_SIZE (b)); fail_unless (GST_BUFFER_DATA (a) == GST_BUFFER_DATA (b)); gst_buffer_unref (a); gst_buffer_unref (b); } g_list_free (src_buffers); src_buffers = NULL; g_list_free (sink_buffers); sink_buffers = NULL; skip: gst_caps_unref (caps); p++; } g_free (allowed_caps); }
static void check_rtpulpfecdec_stats (GstHarness * h, guint packets_recovered, guint packets_unrecovered) { guint packets_recovered_out; guint packets_unrecovered_out; gst_harness_get (h, "rtpulpfecdec", "recovered", &packets_recovered_out, "unrecovered", &packets_unrecovered_out, NULL); fail_unless_equals_int (packets_recovered, packets_recovered_out); fail_unless_equals_int (packets_unrecovered, packets_unrecovered_out); }
static void basic_check_cb (GstPad * pad, int i) { GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT; fail_unless (buffers && g_list_length (buffers) == 1); gst_rtp_buffer_map (buffers->data, GST_MAP_READ, &rtpbuffer); fail_unless_equals_int (66, gst_rtp_buffer_get_ssrc (&rtpbuffer)); fail_unless_equals_int64 (200 - 57 + 1000 + i, gst_rtp_buffer_get_timestamp (&rtpbuffer)); fail_unless_equals_int (100 + 1 + i, gst_rtp_buffer_get_seq (&rtpbuffer)); gst_rtp_buffer_unmap (&rtpbuffer); }
static void check_date_1977_06_23 (const GstTagList * tags, const gchar * file) { GstDateTime *date = NULL; gst_tag_list_get_date_time (tags, GST_TAG_DATE_TIME, &date); fail_unless (date != NULL, "Tags from %s should contain a GST_TAG_DATE_TIME tag"); fail_unless_equals_int (gst_date_time_get_year (date), 1977); fail_unless_equals_int (gst_date_time_get_month (date), 6); fail_unless_equals_int (gst_date_time_get_day (date), 23); gst_date_time_unref (date); }
void test_large_discont() { GstElement *audiorate; GstCaps *caps; GstPad *srcpad, *sinkpad; GstBuffer *buf; //xmlfile = "test_large_discont"; std_log(LOG_FILENAME_LINE, "Test Started test_large_discont"); audiorate = gst_check_setup_element ("audiorate"); caps = gst_caps_new_simple ("audio/x-raw-float", "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 44100, "width", G_TYPE_INT, 32, NULL); srcpad = gst_check_setup_src_pad (audiorate, &srctemplate, caps); sinkpad = gst_check_setup_sink_pad (audiorate, &sinktemplate, caps); gst_pad_set_active (srcpad, TRUE); gst_pad_set_active (sinkpad, TRUE); fail_unless (gst_element_set_state (audiorate, GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, "failed to set audiorate playing"); buf = gst_buffer_new_and_alloc (4); gst_buffer_set_caps (buf, caps); GST_BUFFER_TIMESTAMP (buf) = 0; gst_pad_push (srcpad, buf); fail_unless_equals_int (g_list_length (buffers), 1); buf = gst_buffer_new_and_alloc (4); gst_buffer_set_caps (buf, caps); GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; gst_pad_push (srcpad, buf); /* Now we should have 3 more buffers: the one we injected, plus _two_ filler * buffers, because the gap is > 1 second (but less than 2 seconds) */ fail_unless_equals_int (g_list_length (buffers), 4); gst_element_set_state (audiorate, GST_STATE_NULL); gst_caps_unref (caps); gst_check_teardown_sink_pad (audiorate); gst_check_teardown_src_pad (audiorate); gst_object_unref (audiorate); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static void test_missing_suburisource_handler (void) { GstStructure *s; GstMessage *msg; GstElement *playbin; GError *err = NULL; GstBus *bus; playbin = create_playbin ("file:///does/not/exis.t"); g_object_set (playbin, "suburi", "cookie://withahint.of/cinnamon", NULL); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), GST_STATE_CHANGE_SUCCESS); fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), GST_STATE_CHANGE_FAILURE); /* there should be at least a missing-plugin message on the bus now and an * error message; the missing-plugin message should be first */ bus = gst_element_get_bus (playbin); msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); fail_unless (msg->structure != NULL); s = msg->structure; fail_unless (gst_structure_has_name (s, "missing-plugin")); fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); fail_unless_equals_string (gst_structure_get_string (s, "detail"), "cookie"); fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); gst_message_unref (msg); msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); /* make sure the error is a CORE MISSING_PLUGIN one */ gst_message_parse_error (msg, &err, NULL); fail_unless (err != NULL); fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " "%s instead of core-error-quark", g_quark_to_string (err->domain)); fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); g_error_free (err); gst_message_unref (msg); gst_object_unref (bus); gst_element_set_state (playbin, GST_STATE_NULL); gst_object_unref (playbin); }
static void gst_test_element_class_init (GstTestElementClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstPadTemplate *templ; gst_element_class_set_metadata (element_class, "Test element", "Element", "Does nothing", "Foo Bar <*****@*****.**>"); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 0); fail_unless (gst_element_class_get_pad_template (element_class, "test") == NULL); gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 1); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test2", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test2")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); /* Add "test" again, with NONE caps this time */ gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_NONE)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_empty (templ->caps)); }
static void sink_handoff_cb_xRGB (GstElement * object, GstBuffer * buffer, GstPad * pad, gpointer user_data) { guint *sink_pos = (guint *) user_data; gboolean contains_text = (*sink_pos == 1 || *sink_pos == 2); guint i, j; GstMapInfo map; gboolean all_red = TRUE; gst_buffer_map (buffer, &map, GST_MAP_READ); fail_unless_equals_int (map.size, 640 * 480 * 4); for (i = 0; i < 640; i++) { for (j = 0; j < 480; j++) { all_red = all_red && (map.data[i * 480 * 4 + j * 4 + 1] == 255 && map.data[i * 480 * 4 + j * 4 + 2] == 0 && map.data[i * 480 * 4 + j * 4 + 3] == 0); } } gst_buffer_unmap (buffer, &map); fail_unless (contains_text != all_red, "Frame %d is incorrect (all red %d, contains text %d)", *sink_pos, all_red, contains_text); *sink_pos = *sink_pos + 1; }