проблемы линковки элементов gstreamer
Пишу программу на с++ для захвата экрана и предачи потока по udp, использую api GStreamer. Столкнулся с проблемой линковки элементов(я так думаю), кто-то знает, как понять где проблема?
static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
void sendVideo(int argc, char *argv[])
{
GstElement *pipeline, *source, *sink, *videoscale, *videoconvert, *x264enc, *rtph264pay;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
gst_init (&argc, &argv);
source = gst_element_factory_make ("ximagesrc", "source");
sink = gst_element_factory_make ("udpsink", "sink");
videoscale = gst_element_factory_make ("videoscale", "videoscale");
videoconvert = gst_element_factory_make ("videoconvert", "videoconvert");
x264enc = gst_element_factory_make ("x264enc", "x264enc");
rtph264pay = gst_element_factory_make ("rtph264pay", "rtph264pay");
pipeline = gst_pipeline_new ("test-pipeline");
// g_object_set(source, "startx", 1920, NULL);
// g_object_set(source, "endx", 3839, NULL);
g_object_set(x264enc, "tune", 0x00000004, NULL);
g_object_set(x264enc, "bitrate", 1000, NULL);
g_object_set(x264enc, "speed-preset", 2, NULL);
// g_object_set(sink, "host", "127.0.0.1", NULL);
// g_object_set(sink, "port", 5005, NULL);
if (!pipeline || !source || !sink || !videoscale || !videoconvert || !x264enc || !rtph264pay) {
g_printerr ("Not all elements could be created.\n");
return;
}
gst_bin_add_many (GST_BIN (pipeline), source, videoscale, videoconvert, x264enc, rtph264pay, sink, NULL);
// if (gst_element_link_many (source, videoscale, rtph264pay, sink) != TRUE) {
// g_printerr ("Elements could not be linked.\n");
// gst_object_unref (pipeline);
// return;
// }
gst_element_link(source, videoscale);
gst_element_link(videoscale, videoconvert);
gst_element_link(videoconvert, x264enc);
gst_element_link(x264enc, rtph264pay);
gst_element_link(rtph264pay, sink);
// g_signal_connect (source, "pad-added", G_CALLBACK (on_pad_added), videoscale);
// g_signal_connect (videoscale, "pad-added", G_CALLBACK (on_pad_added), rtph264pay);
// g_signal_connect (rtph264pay, "pad-added", G_CALLBACK (on_pad_added), sink);
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return;
}
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg =
gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n",
GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n",
debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
}
использую данные элементы, так как запуская через консоль все прекрасно работает.
gst-launch-1.0 -v ximagesrc startx = 0 endx = 1920 ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=1000 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000