0

I'm new to GStreamer and I'm trying to output the video on another port with the SRT protocol. So far I have done this and it doesn't work:

typedef struct _CustomData
{
  GstElement *pipeline;
  GstElement *source;
  GstElement *sink;
} CustomData;

static void pad_added_handler (GstElement * src, GstPad * pad, CustomData * data);

int main (int argc, char *argv[]) {
 CustomData data;
 GstBus *bus;
 GstMessage *msg;
 GstStateChangeReturn ret;
 gboolean terminate = FALSE;

 /* Initialize GStreamer */
 gst_init (&argc, &argv);

 /* Create the elements */
 data.source = gst_element_factory_make ("uridecodebin", "source");
 data.sink = gst_element_make_from_uri (GST_URI_SINK,"srt://my_uri", NULL, NULL);

 /* Create the empty pipeline */
 data.pipeline = gst_pipeline_new ("test-pipeline");

 if (!data.pipeline || !data.source || !data.sink) {
   g_printerr ("Not all elements could be created.\n");
   return -1;
 }

 /* Build the pipeline. Note that we are NOT linking the source at this point. We will do it later. */
 gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.sink, NULL);

 /* Set the URI to play */
 g_object_set (data.source, "uri", "srt://my_uri", NULL);

 /* Connect to the pad-added signal */
 g_signal_connect (data.source, "pad-added", G_CALLBACK (pad_added_handler), &data);

 /* Start playing */
 ret = gst_element_set_state (data.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 (data.pipeline);
   return -1;
 }

 /* Listen to the bus */
 bus = gst_element_get_bus (data.pipeline);
 do {
   msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
    GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
   ...
  } while (!terminate);

  /* Free resources */
  gst_object_unref (bus);
  gst_element_set_state (data.pipeline, GST_STATE_NULL);
  gst_object_unref (data.pipeline);
  return 0;
}

And pad_added_handler the function will be called by the padd-added signal:

/* This function will be called by the pad-added signal */
static void pad_added_handler (GstElement * src, GstPad * new_pad, CustomData * data)
{
  GstPad *sink_pad = gst_element_get_static_pad (data->sink, "sink");
  GstPadLinkReturn ret;
  GstCaps *new_pad_caps = NULL;
  GstStructure *new_pad_struct = NULL;
  const gchar *new_pad_type = NULL;

  g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (new_pad), GST_ELEMENT_NAME (src));
  
  /* If our converter is already linked, we have nothing to do here */
  if (gst_pad_is_linked (sink_pad)) {
    g_print ("We are already linked. Ignoring.\n");
    goto exit;
  }

  /* Check the new pad's type */
  new_pad_caps = gst_pad_get_current_caps (new_pad);
  new_pad_struct = gst_caps_get_structure (new_pad_caps, 0);
  new_pad_type = gst_structure_get_name (new_pad_struct);
  if (!g_str_has_prefix (new_pad_type, "video/x-raw")) {
    g_print ("It has type '%s' which is not raw audio. Ignoring.\n",new_pad_type);
   goto exit;
  }

  /* Attempt the link */
  ret = gst_pad_link (new_pad, sink_pad);
  if (GST_PAD_LINK_FAILED (ret)) {
    g_print ("Type is '%s' but link failed.\n", new_pad_type);
  } else {
    g_print ("Link succeeded (type '%s').\n", new_pad_type);
  }

  exit:
  /* Unreference the new pad's caps, if we got them */
  if (new_pad_caps != NULL)
    gst_caps_unref (new_pad_caps);

  /* Unreference the sink pad */
   gst_object_unref (sink_pad);
}

I don't get any error when running the code but when I try to read the media I get the following error: Operation not supported: Invalid socket ID.

user16217248
  • 3,119
  • 19
  • 19
  • 37
tyler
  • 13
  • 6

0 Answers0