Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void *bus_msgs_thread(void *pipeline)
- {
- GstBus *bus = gst_element_get_bus((GstElement *)pipeline);
- GstMessage *msg = NULL;
- gboolean keep_running = TRUE;
- GstClockTime recTimeout = 10000000000;
- GError *err;
- gchar *debug_info;
- GstStateChangeReturn ret;
- do {
- msg = gst_bus_timed_pop(bus,recTimeout);
- if(msg != NULL)
- {
- //g_print("%s: Got %s message \n", __func__,GST_MESSAGE_TYPE_NAME(msg));
- 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 - %d\n",
- GST_OBJECT_NAME(msg->src), err->message, err->code);
- g_printerr("Debugging information: %s\n",
- debug_info ? debug_info : "none");
- g_clear_error(&err);
- g_free(debug_info);
- if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_NULL)) == GST_STATE_CHANGE_SUCCESS)
- {
- sleep(2);
- if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_PLAYING)) == GST_STATE_CHANGE_ASYNC)
- {
- printf("Restarted the pipeline\n");
- }
- else
- {
- printf("Failed to Restart the pipeline. Returned : %d\n",ret);
- }
- }
- else
- {
- printf("Failed to set the pipeline to NULL. Returned : %d\n",ret);
- }
- break;
- case GST_MESSAGE_EOS:
- g_print("***End-Of-Stream occurred unintentionally. STOPPING and STARTING pipeline***\n");
- if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_NULL)) == GST_STATE_CHANGE_SUCCESS)
- {
- sleep(2);
- if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_PLAYING)) == GST_STATE_CHANGE_ASYNC)
- {
- printf("Restarted the pipeline\n");
- }
- else
- {
- printf("Failed to Restart the pipeline. Returned : %d\n",ret);
- }
- }
- else
- {
- printf("Failed to set the pipeline to NULL. Returned : %d\n",ret);
- }
- break;
- case GST_MESSAGE_ASYNC_DONE:
- g_print("Message async done reached.\n");
- break;
- case GST_MESSAGE_STATE_CHANGED:
- {
- GstState oldState, newState;
- gst_message_parse_state_changed(msg, &oldState, &newState, NULL);
- if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline) || GST_MESSAGE_SRC (msg) == GST_OBJECT (destination))
- g_print("Element %s state changed from %s to %s\n", GST_OBJECT_NAME(msg->src), gst_element_state_get_name(oldState), gst_element_state_get_name(newState));
- }
- break;
- case GST_MESSAGE_STREAM_STATUS:
- case GST_MESSAGE_PROGRESS:
- case GST_MESSAGE_NEW_CLOCK:
- case GST_MESSAGE_ELEMENT:
- //gst_message_parse_stream_status(msg, type, NULL);
- //g_print("Stream status.... \n");
- break;
- case GST_MESSAGE_APPLICATION:
- g_print("application specific msg.... \n");
- break;
- default:
- // We should not reach here because we only asked for ERRORs and EOS
- g_printerr("Unexpected message received. %s\n",
- GST_MESSAGE_TYPE_NAME(msg));
- break;
- }
- gst_message_unref(msg);
- }
- else
- {
- printf("msg is NULL\n");
- }
- //pthread_testcancel();
- }while(keep_running);
- pthread_exit(NULL);
- }
Add Comment
Please, Sign In to add comment