How do I add application/x-rtp to udp src in c++ code?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How do I add application/x-rtp to udp src in c++ code?

doktorsad
Good day. I want to broadcast a video stream via udp, but unfortunately I can't figure out how to add src --application/x-rtp to udp, because without this, an error occurs when sending the stream. I understand that application/x-rtp needs to be formed in caps, but what should I do with it next?

```
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>

void test( int argc, char *argv[] )
{
  gst_init (&argc, &argv);

  const auto source = gst_element_factory_make("udpsrc", "source");
  const auto sink = gst_element_factory_make("ximagesink", "sink");
  const auto appsrc = gst_element_factory_make ("appsrc", "source");
  const auto decodebin = gst_element_factory_make("decodebin", "decodebin");
  const auto videoconvert = gst_element_factory_make("videoconvert", "videoconvert");
  const auto rtph264depay = gst_element_factory_make("rtph264depay", "rtph264depay");
  const auto pipeline = gst_pipeline_new("test-pipeline");
  g_object_set(source, "port", 5000, NULL);
  g_object_set (appsrc, "caps",
            gst_caps_new_simple ("application/x-rtp",
                "media", G_TYPE_STRING, "video",
                "clock-rate", G_TYPE_INT, 90000,
                "encoding-name", G_TYPE_STRING, "H264",
                "payload", G_TYPE_INT, 96,
                NULL),
            NULL);
  // g_object_set (G_OBJECT (appsrc), "caps",
  //           gst_caps_new_simple ("video/x-raw",
  //               "format", G_TYPE_STRING, "RGB16",
  //               "width", G_TYPE_INT, 384,
  //               "height", G_TYPE_INT, 288,
  //               "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
  //               "framerate", GST_TYPE_FRACTION, 0, 1,
  //               NULL), NULL);
  if (!pipeline || !appsrc || !source || !sink || !videoconvert || !decodebin || !rtph264depay) {
    g_printerr ("Not all elements could be created.\n");
    return;
  }
  gst_bin_add_many (GST_BIN (pipeline), source, appsrc, rtph264depay, decodebin, videoconvert, sink, NULL);
  gst_element_link(source, appsrc);
  gst_element_link(appsrc, rtph264depay);
  gst_element_link(rtph264depay, decodebin);
  gst_element_link(decodebin, videoconvert);
  gst_element_link(videoconvert, sink);

  const auto 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 */
  GstBus* bus = gst_element_get_bus(pipeline);
  GstMessage* msg = gst_bus_timed_pop_filtered(
    bus,
    GST_CLOCK_TIME_NONE,
    static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));

  /* Parse message */
  if (msg != nullptr) {
    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);
}
int main( int argc, char *argv[] )
{
    test( argc, argv );
    return 0;
}

```