GstPipeline and bus call

killerrats koreysjunkmail at gmail.com
Wed Aug 16 16:54:44 UTC 2017


edited the code from what i gave you and may be that state change will give
you a pause or ready or something. then maybe if it goes to paused 10 times
and it will quit the loop.

/************* 
global values 
*****    ***********/

GstElement *pipeline;
GMainLoop *loop;
GstBus *bus;
GstMessage* msg;
GstState* state;

#define GST_PLAYER_UDP "udpsrc port=5555 caps=\"application/x-rtp,
media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264,
payload=(int)96\"\ 
                ! rtph264depay ! decodebin ! videoconvert ! autovideosink" 

static gboolean bus_cb (GstBus *bus, GstMessage *msg, gpointer *data);
				
int main()
{
	/* Initialize GStreamer */
	gst_init (&argc, &argv);

	/* Build the pipeline */
	pipeline = gst_parse_launch (GST_PLAYER_UDP, &error); 
	if (!pipeline){ 
			g_print ("\tParse error: %s\n", error->message); 
			return 0; 
	} 
	
	loop = g_main_loop_new (NULL, FALSE);

	/* Start playing */
	gst_element_set_state (pipeline, GST_STATE_PLAYING);

	/* Wait until error or EOS */
	 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); 
	 if(bus == NULL)
	 {
		std::cout << "\nNo Bus\n";
		return 0;
	 }
	gst_bus_add_signal_watch(bus);
	g_signal_connect (bus, "message", G_CALLBACK (bus_cb), this->apPipeline);
	
	g_timeout_add_seconds (1, timeout_cb, loop);
	
	g_main_loop_run(loop);
	
	/* Free resources */
	gst_object_unref (bus);
	gst_element_set_state (pipeline, GST_STATE_NULL);
	gst_object_unref (pipeline);
} 


/********************** 
    bus method
******************/
gboolean bus_cb (GstBus *bus, GstMessage *msg, gpointer *data) {

  switch (GST_MESSAGE_TYPE (msg)) {
	case GST_MESSAGE_ERROR: {
      GError *err;
      gchar *debug;

      gst_message_parse_error (msg, &err, &debug);
      g_print ("Error: %s\n", err->message);
      g_error_free (err);
      g_free (debug);

      gst_element_set_state (pipeline, GST_STATE_READY);
      g_main_loop_quit (loop);
      return FALSE;
    }
    case GST_MESSAGE_EOS:
      /* end-of-stream */
      gst_element_set_state (pipeline, GST_STATE_READY);
      g_main_loop_quit (loop);
      return FALSE;
    case GST_MESSAGE_STATE_CHANGED:
	{
        GstElement* source =
gst_bin_get_by_name(GST_BIN(pipeline),"source");

		if (GST_MESSAGE_SRC (msg) == GST_OBJECT(source)) {
            GstState old_state, new_state, pending_state;
            gst_message_parse_state_changed (msg, &old_state, &new_state,
&pending_state);
			std::string oldstate(gst_element_state_get_name (old_state));
			std::string newstate(gst_element_state_get_name (new_state));
			std::string changestate = "Pipeline state changed from "+oldstate+" to "
+ newstate;
                        std::cout << changestate;
		state = new_state;
		gst_object_unref(source);
	}
	break;
    default:
      /* Unhandled message */
      break;
    }
      return TRUE;
}

gboolean PipelineClass::timeout_cb (gpointer user_data)
{
	static int time = 0;
	static int timeout = 0;
	int MaxTimeout = 10;	
						
		switch (state)
		{
                case GST_STATE_READY:
                {
                   std::cout << "STATE Ready";
                 }
		case GST_STATE_PLAYING:
			{
                               std::cout << "STATE Playing":
			  timeout = 0;
			}
			break;
		case GST_STATE_PAUSED:
			{
                               std::cout << "STATE Paused":
				if(timeout == MaxTimeout)
                                {
                                   g_main_loop_quit(loop);
                                }
				timeout++;
				break;
			}
		case GST_STATE_NULL:
                               std::cout << "STATE Null":
			return FALSE;
		default:
			break;
		}
  return TRUE;
}



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GstPipeline-and-bus-call-tp4684199p4684232.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list