/* Create and link output pad: selector:src%d ! output_pad */ GstPad * setup_output_pad (GstElement * element) { GstPad *srcpad = NULL, *output_pad = NULL; gulong probe_id = 0; /* create output_pad */ output_pad = gst_pad_new_from_static_template (&sinktemplate, "sink"); fail_if (output_pad == NULL, "Could not create a output_pad"); /* add probe */ probe_id = gst_pad_add_data_probe (output_pad, G_CALLBACK (probe_cb), NULL); g_object_set_data (G_OBJECT (output_pad), "probe_id", GINT_TO_POINTER (probe_id)); /* request src pad */ srcpad = gst_element_get_request_pad (element, "src%d"); fail_if (srcpad == NULL, "Could not get source pad from %s", GST_ELEMENT_NAME (element)); /* link pads and activate */ fail_unless (gst_pad_link (srcpad, output_pad) == GST_PAD_LINK_OK, "Could not link %s source and output pad", GST_ELEMENT_NAME (element)); gst_pad_set_active (output_pad, TRUE); GST_DEBUG_OBJECT (output_pad, "set up %" GST_PTR_FORMAT " ! %" GST_PTR_FORMAT, srcpad, output_pad); gst_object_unref (srcpad); ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); return output_pad; }
int main (int argc, char *argv[]) { TestPipeline *pipeline = test_pipeline_new (argc, argv); if (!pipeline) { return 1; } g_object_set (pipeline->src, "mode", 2, NULL); GstElement *filesink = gst_element_factory_make ("filesink", NULL); gst_element_set_locked_state (filesink, TRUE); g_object_set (filesink, "location", "foo.yuv", NULL); gst_bin_add (GST_BIN (pipeline->pipeline), filesink); if (!gst_element_link_pads (pipeline->src, "vidsrc", filesink, "sink")) { g_printerr ("Failed to link filesink"); return 1; } GstPad *pad = gst_element_get_static_pad (pipeline->src, "vidsrc"); gst_pad_add_data_probe (pad, G_CALLBACK (vidsrc_data_probe), filesink); gst_object_unref (pad); g_timeout_add (5000, start_video_capture, pipeline); g_timeout_add (10000, stop_video_capture, pipeline); return test_pipeline_exec (pipeline, 11000); }
static void fs_rtp_sub_stream_add_probe_locked (FsRtpSubStream *substream) { if (!substream->priv->blocking_id) substream->priv->blocking_id = gst_pad_add_data_probe ( substream->priv->rtpbin_pad, G_CALLBACK (_rtpbin_pad_have_data_callback), substream); }
void PerformWProbe (GstPad *srcpad, GstPad *sinkpad, const std::function<void ()>& functor) { auto data = new CallbackData { functor, sinkpad, 0 }; #if GST_VERSION_MAJOR < 1 data->ID_ = gst_pad_add_data_probe (srcpad, G_CALLBACK (ProbeHandler), data); #else gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_IDLE, ProbeHandler, data, nullptr); #endif }
void test_buffer_probe_n_times() { GstElement *pipeline, *fakesrc, *fakesink; GstBus *bus; GstMessage *message; GstPad *pad; xmlfile = "gstutils_test_buffer_probe_n_times"; std_log(LOG_FILENAME_LINE, "Test Started gstutils_test_buffer_probe_n_times"); pipeline = gst_element_factory_make ("pipeline", NULL); fakesrc = gst_element_factory_make ("fakesrc", NULL); fakesink = gst_element_factory_make ("fakesink", NULL); g_object_set (fakesrc, "num-buffers", (int) 10, NULL); gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL); gst_element_link (fakesrc, fakesink); pad = gst_element_get_pad (fakesink, "sink"); gst_pad_add_data_probe (pad, G_CALLBACK (data_probe), SPECIAL_POINTER (0)); gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe), SPECIAL_POINTER (1)); gst_pad_add_event_probe (pad, G_CALLBACK (event_probe), SPECIAL_POINTER (2)); gst_object_unref (pad); gst_element_set_state (pipeline, GST_STATE_PLAYING); bus = gst_element_get_bus (pipeline); message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1); gst_message_unref (message); gst_object_unref (bus); g_assert (n_buffer_probes == 10); /* one for every buffer */ g_assert (n_event_probes == 3); /* new segment, latency and eos */ g_assert (n_data_probes == 13); /* duh */ gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); /* make sure nothing was sent in addition to the above when shutting down */ g_assert (n_buffer_probes == 10); /* one for every buffer */ g_assert (n_event_probes == 3); /* new segment, latency and eos */ g_assert (n_data_probes == 13); /* duh */ std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
void test_buffer_probe_once() { GstElement *pipeline, *fakesrc, *fakesink; GstBus *bus; GstMessage *message; GstPad *pad; guint id1, id2, id3; xmlfile = "gstutils_test_buffer_probe_once"; std_log(LOG_FILENAME_LINE, "Test Started gstutils_test_buffer_probe_once"); pipeline = gst_element_factory_make ("pipeline", NULL); fakesrc = gst_element_factory_make ("fakesrc", NULL); fakesink = gst_element_factory_make ("fakesink", NULL); g_object_set (fakesrc, "num-buffers", (int) 10, NULL); gst_bin_add_many (GST_BIN (pipeline), fakesrc, fakesink, NULL); gst_element_link (fakesrc, fakesink); pad = gst_element_get_pad (fakesink, "sink"); id1 = gst_pad_add_data_probe (pad, G_CALLBACK (data_probe_once), &id1); id2 = gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_once), &id2); id3 = gst_pad_add_event_probe (pad, G_CALLBACK (event_probe_once), &id3); gst_object_unref (pad); gst_element_set_state (pipeline, GST_STATE_PLAYING); bus = gst_element_get_bus (pipeline); message = gst_bus_poll (bus, GST_MESSAGE_EOS, -1); gst_message_unref (message); gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); g_assert (n_buffer_probes_once == 1); /* can we hit it and quit? */ g_assert (n_event_probes_once == 1); /* i said, can we hit it and quit? */ g_assert (n_data_probes_once == 1); /* let's hit it and quit!!! */ std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static void update_video_sink (GstFPSDisplaySink * self, GstElement * video_sink) { GstPad *sink_pad; if (self->video_sink) { /* remove pad probe */ sink_pad = gst_element_get_static_pad (self->video_sink, "sink"); gst_pad_remove_data_probe (sink_pad, self->data_probe_id); gst_object_unref (sink_pad); self->data_probe_id = -1; /* remove ghost pad target */ gst_ghost_pad_set_target (GST_GHOST_PAD (self->ghost_pad), NULL); /* remove old sink */ gst_bin_remove (GST_BIN (self), self->video_sink); gst_object_unref (self->video_sink); } /* create child elements */ self->video_sink = video_sink; if (self->video_sink == NULL) return; fps_display_sink_update_sink_sync (self); /* take a ref before bin takes the ownership */ gst_object_ref (self->video_sink); gst_bin_add (GST_BIN (self), self->video_sink); /* attach or pad probe */ sink_pad = gst_element_get_static_pad (self->video_sink, "sink"); self->data_probe_id = gst_pad_add_data_probe (sink_pad, G_CALLBACK (on_video_sink_data_flow), (gpointer) self); gst_object_unref (sink_pad); }
/* Create input-selector with given number of sink pads and switch given number of input buffers to each sink pad. */ void run_input_selector_buffer_count (gint num_input_pads, gint num_buffers_per_input) { /* set up input_pads ! selector ! output_pad */ gint i = 0, probe_id = 0; GList *input_pads = NULL, *output_pads = NULL; GstElement *sel = gst_check_setup_element ("input-selector"); GstPad *output_pad = gst_check_setup_sink_pad (sel, &sinktemplate, NULL); output_pads = g_list_append (output_pads, output_pad); gst_pad_set_active (output_pad, TRUE); for (i = 0; i < num_input_pads; i++) { input_pads = g_list_append (input_pads, setup_input_pad (sel)); } /* add probe */ probe_id = gst_pad_add_data_probe (output_pad, G_CALLBACK (probe_cb), NULL); g_object_set_data (G_OBJECT (output_pad), "probe_id", GINT_TO_POINTER (probe_id)); /* run the test */ fail_unless (gst_element_set_state (sel, GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, "could not set to playing"); push_switched_buffers (input_pads, sel, input_pads, num_buffers_per_input); count_output_buffers (output_pads, (num_input_pads * num_buffers_per_input)); fail_unless (gst_element_set_state (sel, GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); /* clean up */ gst_pad_remove_data_probe (output_pad, probe_id); gst_pad_set_active (output_pad, FALSE); gst_check_teardown_sink_pad (sel); GST_DEBUG ("setting selector pad to NULL"); selector_set_active_pad (sel, NULL); // unref input-selector active pad g_list_foreach (input_pads, (GFunc) cleanup_pad, sel); g_list_free (input_pads); g_list_free (output_pads); gst_check_teardown_element (sel); }
gboolean shmdata_base_reader_attach (shmdata_base_reader_t *reader) { g_mutex_lock (&reader->mutex_); if (reader->attached_) { g_mutex_unlock (&reader->mutex_); return FALSE; } reader->attached_ = TRUE; reader->source_ = gst_element_factory_make ("shmsrc", NULL); reader->deserializer_ = gst_element_factory_make ("gdpdepay", NULL); GstPad *pad = gst_element_get_static_pad(reader->deserializer_, "src"); gst_pad_add_data_probe (pad, G_CALLBACK (shmdata_base_reader_reset_time), reader); gst_object_unref(pad); reader->typefind_ = gst_element_factory_make ("typefind", NULL); if (NULL == reader->typefind_) { g_warning ("no typefind !"); g_mutex_unlock (&reader->mutex_); return FALSE; } reader->have_type_handler_id_ = g_signal_connect (reader->typefind_, "have-type", G_CALLBACK (shmdata_base_reader_on_type_found), reader); if (reader->do_absolute_) reader->timereset_ = FALSE; if (!reader->source_) { g_critical ("Reader: \"shmsrc\" element could not be created"); g_mutex_unlock (&reader->mutex_); return FALSE; } if (!reader->deserializer_) { g_critical ("Reader: \"gdpdepay\" element could not be created."); g_mutex_unlock (&reader->mutex_); return FALSE; } if (!reader->typefind_) { g_critical ("Reader: \"typefind\" element could not be created."); g_mutex_unlock (&reader->mutex_); return FALSE; } g_object_set_data (G_OBJECT (reader->source_), "shmdata_base_reader", (gpointer)reader); g_object_set_data (G_OBJECT (reader->deserializer_), "shmdata_base_reader", (gpointer)reader); g_object_set (G_OBJECT (reader->source_), "socket-path", reader->socket_name_, NULL); gst_bin_add_many (GST_BIN (reader->bin_), reader->source_, reader->deserializer_, reader->typefind_, NULL); GstPad *src_pad = gst_element_get_static_pad (reader->typefind_, "src"); GstPad *sink_pad = gst_element_get_compatible_pad (reader->sink_, src_pad, GST_PAD_CAPS(src_pad)); gst_element_link_many (reader->source_, reader->deserializer_, reader->typefind_, NULL); gst_pad_link (src_pad, sink_pad); gst_object_unref(sink_pad); gst_object_unref(src_pad); gst_element_set_state (reader->typefind_,GST_STATE_TARGET(reader->bin_)); gst_element_set_state (reader->deserializer_,GST_STATE_TARGET(reader->bin_)); gst_element_set_state (reader->source_,GST_STATE_TARGET(reader->bin_)); g_mutex_unlock (&reader->mutex_); return FALSE; //for g_idle_add }