Guest User

gstreamer bus messages

a guest
Apr 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 KB | None | 0 0
  1. void *bus_msgs_thread(void *pipeline)
  2. {
  3.     GstBus *bus = gst_element_get_bus((GstElement *)pipeline);
  4.     GstMessage *msg = NULL;
  5.     gboolean keep_running = TRUE;
  6.     GstClockTime recTimeout = 10000000000;
  7.     GError *err;
  8.     gchar *debug_info;
  9.     GstStateChangeReturn ret;
  10.  
  11.     do {
  12.         msg = gst_bus_timed_pop(bus,recTimeout);
  13.         if(msg != NULL)
  14.         {
  15.             //g_print("%s: Got %s message \n", __func__,GST_MESSAGE_TYPE_NAME(msg));
  16.             switch (GST_MESSAGE_TYPE(msg)) {
  17.             case GST_MESSAGE_ERROR:
  18.                 gst_message_parse_error(msg, &err, &debug_info);
  19.                 g_printerr("Error received from element %s: %s - %d\n",
  20.                         GST_OBJECT_NAME(msg->src), err->message, err->code);
  21.                 g_printerr("Debugging information: %s\n",
  22.                         debug_info ? debug_info : "none");
  23.                 g_clear_error(&err);
  24.                 g_free(debug_info);
  25.                 if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_NULL)) == GST_STATE_CHANGE_SUCCESS)
  26.                 {
  27.                     sleep(2);
  28.  
  29.                     if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_PLAYING)) == GST_STATE_CHANGE_ASYNC)
  30.                     {
  31.                         printf("Restarted the pipeline\n");
  32.                     }
  33.                     else
  34.                     {
  35.                         printf("Failed to Restart the pipeline. Returned : %d\n",ret);
  36.                     }
  37.                 }
  38.                 else
  39.                 {
  40.                     printf("Failed to set the pipeline to NULL. Returned : %d\n",ret);
  41.                 }
  42.                 break;
  43.             case GST_MESSAGE_EOS:
  44.                 g_print("***End-Of-Stream occurred unintentionally. STOPPING and STARTING pipeline***\n");
  45.  
  46.                
  47.                 if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_NULL)) == GST_STATE_CHANGE_SUCCESS)
  48.                 {
  49.                    
  50.                     sleep(2);
  51.                     if((ret = gst_element_set_state ((GstElement *)pipeline, GST_STATE_PLAYING)) == GST_STATE_CHANGE_ASYNC)
  52.                     {
  53.                         printf("Restarted the pipeline\n");
  54.                     }
  55.                     else
  56.                     {
  57.                         printf("Failed to Restart the pipeline. Returned : %d\n",ret);
  58.                     }
  59.                 }
  60.                 else
  61.                 {
  62.                     printf("Failed to set the pipeline to NULL. Returned : %d\n",ret);
  63.                 }
  64.  
  65.  
  66.                 break;
  67.             case GST_MESSAGE_ASYNC_DONE:
  68.                 g_print("Message async done reached.\n");
  69.                 break;
  70.             case GST_MESSAGE_STATE_CHANGED:
  71.             {
  72.                 GstState oldState, newState;
  73.                 gst_message_parse_state_changed(msg, &oldState, &newState,  NULL);
  74.                  if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline) || GST_MESSAGE_SRC (msg) == GST_OBJECT (destination))
  75.                      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));
  76.             }
  77.                 break;
  78.             case GST_MESSAGE_STREAM_STATUS:
  79.             case GST_MESSAGE_PROGRESS:
  80.             case GST_MESSAGE_NEW_CLOCK:
  81.             case GST_MESSAGE_ELEMENT:
  82.                 //gst_message_parse_stream_status(msg, type, NULL);
  83.                 //g_print("Stream status.... \n");
  84.                 break;
  85.             case GST_MESSAGE_APPLICATION:
  86.                 g_print("application specific msg.... \n");
  87.                 break;
  88.             default:
  89.                 // We should not reach here because we only asked for ERRORs and EOS
  90.                 g_printerr("Unexpected message received. %s\n",
  91.                         GST_MESSAGE_TYPE_NAME(msg));
  92.                 break;
  93.             }
  94.             gst_message_unref(msg);
  95.         }
  96.         else
  97.         {
  98.             printf("msg is NULL\n");
  99.         }
  100.         //pthread_testcancel();
  101.  
  102.     }while(keep_running);
  103.  
  104. pthread_exit(NULL);
  105. }
Add Comment
Please, Sign In to add comment