gstreamer C API

classic Classic list List threaded Threaded
2 messages Options
R C
Reply | Threaded
Open this post in threaded view
|

gstreamer C API

R C

Hello,


I have been playing with the "basic tutorial" C API a bit, and can create a stream in c code. However, when the strea is running, how can I quit/terminate that stream?


For example,  basic tutorial 3:


After creating a pipeline, one can start it. Then there's a loop that listens for msgs from the 'bus', in a loop. Whenever there is a msg, the loop runs through a switch, and and listens for a new msg again.

I want to create "some sort of event"  that terminates that loop (for example existence (or not) of a lock file.).

(or can I create a handler, set an option, that will make gst_element_get_bus(..)  return, even if there isn't a msg, with an empty msg or so?  (I am fairly sure, gst_element_get_bus, is not returning and only will if there is a msg waiting.)


Here's a/the code snippet from the basic tutorial 3 example:

  /* 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);

    /* 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);
          terminate = TRUE;
          break;
        case GST_MESSAGE_EOS:
          g_print ("End-Of-Stream reached.\n");
          terminate = TRUE;
          break;
        case GST_MESSAGE_STATE_CHANGED:
          /* We are only interested in state-changed messages from the pipeline */
          if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {
            GstState old_state, new_state, pending_state;
            gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
            g_print ("Pipeline state changed from %s to %s:\n",
                gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
          }
          break;
        default:
          /* We should not reach here */
          g_printerr ("Unexpected message received.\n");
          break;
      }
      gst_message_unref (msg);
    }
  } while (!terminate);

















_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
R C
Reply | Threaded
Open this post in threaded view
|

Re: gstreamer C API

R C

ever had that situation where you have been looking for an answer and right after you ask, you find it?


so,  thanks..  but never mind.


Ron

On 5/31/19 5:02 PM, R C wrote:

Hello,


I have been playing with the "basic tutorial" C API a bit, and can create a stream in c code. However, when the strea is running, how can I quit/terminate that stream?


For example,  basic tutorial 3:


After creating a pipeline, one can start it. Then there's a loop that listens for msgs from the 'bus', in a loop. Whenever there is a msg, the loop runs through a switch, and and listens for a new msg again.

I want to create "some sort of event"  that terminates that loop (for example existence (or not) of a lock file.).

(or can I create a handler, set an option, that will make gst_element_get_bus(..)  return, even if there isn't a msg, with an empty msg or so?  (I am fairly sure, gst_element_get_bus, is not returning and only will if there is a msg waiting.)


Here's a/the code snippet from the basic tutorial 3 example:

  /* 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);

    /* 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);
          terminate = TRUE;
          break;
        case GST_MESSAGE_EOS:
          g_print ("End-Of-Stream reached.\n");
          terminate = TRUE;
          break;
        case GST_MESSAGE_STATE_CHANGED:
          /* We are only interested in state-changed messages from the pipeline */
          if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {
            GstState old_state, new_state, pending_state;
            gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
            g_print ("Pipeline state changed from %s to %s:\n",
                gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
          }
          break;
        default:
          /* We should not reach here */
          g_printerr ("Unexpected message received.\n");
          break;
      }
      gst_message_unref (msg);
    }
  } while (!terminate);

















_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel