<div dir="ltr">As if my server gets down or if their is some problem with my camera.<br>So i want if there is an element provided by you people so that i can<br>listen if ip address is available or not if not it sends a message ip<br>address is not available.<br><br>I resolve this problem by calling a method recursively because whenever it<br>does not get any data from source it give a msg end of stream or error so<br>after getting that msg i deference all elements and at the end i<br>recursively call same method so that i can check if source is available or<br>not but after two three call backs it give segmentation fault.<br>I also tried with ping methodology but give same result.<br><br>Here is my code..<br><br>void * camera1(void * u)<br><br>  {<br><br>        printf("Thread starting....\n");<br>        GstMessage *msg;<br>        CustomData data;<br>        guint bus_watch_id;<br>        GstBus *bus;<br>        GstStateChangeReturn ret;<br>        gboolean terminate = FALSE;<br>        char cam2[9]="cam2";<br>        printf("start playing11..\n");<br>        data.source = gst_element_factory_make ("uridecodebin", "source");<br>        data.convert = gst_element_factory_make ("videoconvert", "convert");<br>       // data.sink = gst_element_factory_make ("autoaudiosink", "sink");<br>       // data.videoconvert1 = gst_element_factory_make("videoconvert",<br>"videoconvert1");<br>    data.videoconvert2 = gst_element_factory_make("videoconvert",<br>"videoconvert2");<br>    //data.queue1 = gst_element_factory_make("queue", "queue1");<br>    data.queue2 = gst_element_factory_make("queue", "queue2");<br>    data.tee = gst_element_factory_make("tee", "tee");<br><br>    data.frameratefilter = gst_element_factory_make("capsfilter", NULL);<br>    data.videorate = gst_element_factory_make("videorate", NULL);<br>    data.avenc = gst_element_factory_make("avenc_mpeg2video", NULL);<br>    data.avimux = gst_element_factory_make("avimux", NULL);<br>    data.filesink = gst_element_factory_make("multifilesink", "filesink");<br>   // data.splitmuxsink = gst_element_factory_make("splitmuxsink",<br>"splitmuxsink");<br>    printf("start playing22..\n");<br>     /* Create the empty pipeline */<br>       data.pipeline = gst_pipeline_new ("test-pipeline");<br><br>  if (!data.pipeline || !data.source || !data.convert ||<br>!data.videoconvert2 || !data.queue2 || !data.tee || !data.filesink  ) {<br>    g_printerr ("Not all elements could be created.\n");<br>    return 0;<br>  }<br>   printf("start playing33..\n");<br>        g_object_set(G_OBJECT(data.frameratefilter), "caps",<br>gst_caps_from_string("video/x-raw,framerate=50/1"), NULL);<br><br>   printf("start playing44..\n");<br><br>  /* Build the pipeline. Note that we are NOT linking the source at this<br>   * point. We will do it later. */<br>  gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.convert<br>,data.videoconvert2, data.queue2, data.tee,data.frameratefilter,<br>data.videorate,data.avenc,data.avimux,data.filesink,NULL);<br>  if (!gst_element_link (data.convert, data.tee)) {<br>    g_printerr ("Elements could not be linked.\n");<br>    gst_object_unref (data.pipeline);<br>    return 0;<br>  }printf("start playing..\n");<br>    if (!gst_element_link_many(data.queue2, data.videorate,<br>data.frameratefilter, data.videoconvert2, data.avenc,data.avimux,<br>data.filesink, NULL))<br>        g_error("Failed to link save elements!");<br><br>    if ( !(data.tee_src_pad_template = gst_element_class_get_pad_template<br>(GST_ELEMENT_GET_CLASS (data.tee), "src_%u"))) {<br>      g_critical ("Unable to get pad template!");<br>      return;<br>     }<br>printf("start playing..\n");<br>       // data.qpad1 = gst_element_get_static_pad(data.queue1, "sink");<br>    data.qpad2 = gst_element_get_static_pad(data.queue2, "sink");<br>  //  data.teepad1 = gst_element_request_pad (data.tee,<br>data.tee_src_pad_template, NULL, NULL);<br>    //g_print ("Obtained request pad %s for queue1 branch.\n",<br>gst_pad_get_name (data.teepad1));<br>    data.teepad2 = gst_element_request_pad (data.tee,<br>data.tee_src_pad_template, NULL, NULL);<br>    g_print ("Obtained request pad %s for queue2 branch.\n",<br>gst_pad_get_name (data.teepad2));<br><br>    if( !data.teepad2 || !data.qpad2){<br>        g_error("Creation of one tee pad failed.");<br>        return;<br>    }<br>printf("start playing..\n");<br>  //  gst_pad_link (data.teepad1, data.qpad1);<br>    gst_pad_link (data.teepad2, data.qpad2);<br><br> //   gst_object_unref (GST_OBJECT (data.qpad1));<br>    gst_object_unref (GST_OBJECT (data.qpad2));<br>    //gst_object_unref (GST_OBJECT (data.teepad1));<br>    gst_object_unref (GST_OBJECT (data.teepad2));<br><br>    printf("start playing.12345.\n");<br>    GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(data.pipeline),<br>GST_DEBUG_GRAPH_SHOW_ALL, "pipeline_graph");<br><br>   printf("%s",message[6]+10);<br><br>  /* Set the URI to play */<br>  g_object_set (data.source, "uri",message[7]+10, NULL);<br><br>  /* Connect to the pad-added signal */<br>  g_signal_connect (data.source, "pad-added", G_CALLBACK<br>(pad_added_handler), &data);<br>  //printf("%s",*prop);<br>  /* Start playing */<br>  printf("start playing12..\n");<br>  ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);<br>  if (ret == GST_STATE_CHANGE_FAILURE) {<br>    g_printerr ("Unable to set the pipeline to the playing state.\n");<br>    gst_object_unref (data.pipeline);<br>    return 0;<br>  }<br><br><br>    g_object_set(G_OBJECT<br>(data.filesink),"location","/home/bitcomm-31/Videos/Cam1/shubham_%03d.mp4","async",0,<br>NULL);<br>    g_object_set(G_OBJECT (data.filesink),"post-messages", TRUE,<br>"multifilesink", 0, NULL);<br>    g_object_set(G_OBJECT (data.filesink),"next-file", 4,"multifilesink",<br>0, NULL);<br>    g_object_set(G_OBJECT (data.filesink), "max-file-size", 500000,<br>"multifilesink", 0, NULL);<br>    g_object_set(G_OBJECT (data.filesink), "max-files ",5, "multifilesink",<br>0, NULL);<br><br><br>printf("Thread Start.. Listen to bus\n");<br><br>/* Listen to the bus */<br>  bus = gst_element_get_bus (data.pipeline);<br>printf("Bus status fetched\n");<br>  do {<br>    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,<br>    GST_MESSAGE_ANY);<br>    //msg=GST_MESSAGE_EOS;<br>   printf("Enetring switch case\n");<br>    /* Parse message */<br>    if (msg != NULL) {<br>      GError *err;<br>      gchar *debug_info;<br>      printf("msg.type %u\n",GST_MESSAGE_TYPE (msg));<br>      switch (GST_MESSAGE_TYPE (msg)) {<br>      case GST_MESSAGE_ERROR:<br>       gst_message_parse_error (msg, &err, &debug_info);<br>       g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME<br>(msg->src), err->message);<br>       g_printerr ("Debugging information: %s\n", debug_info ? debug_info :<br>"none");<br>       g_clear_error (&err);<br>       g_free (debug_info);<br>       terminate = TRUE;<br>          break;<br>        case GST_MESSAGE_EOS:<br>          g_print ("End-Of-Stream reached.\n");<br>          terminate = TRUE;<br>          break;<br>        case GST_MESSAGE_STATE_CHANGED:<br>          /* We are only interested in state-changed messages from the<br>pipeline */<br>          if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data.pipeline)) {<br>            GstState old_state, new_state, pending_state;<br>            gst_message_parse_state_changed (msg, &old_state, &new_state,<br>&pending_state);<br>            g_print ("Pipeline state changed from %s to %s:\n",<br>                gst_element_state_get_name (old_state),<br>gst_element_state_get_name (new_state));<br>          }<br>          break;<br>          //////START<br>          case GST_MESSAGE_UNKNOWN:<br>        g_print("GST_MESSAGE_UNKNOWN\n");<br>break;<br>//case GST_MESSAGE_ELEMENT:<br>//g_print("########################GST_MESSAGE_ELEMENT     START<br>#################\n");<br>//g_message ("get message %s", gst_structure_get_name<br>(gst_message_get_structure(msg)));<br>//g_print ("filenemae %d",gst_message_get_structure(msg))->index);<br>//g_print("########################GST_MESSAGE_ELEMENT     END<br>#################\n");<br>//break;<br><br>case GST_MESSAGE_ELEMENT:<br><br><br>        s = gst_message_get_structure (msg);<br>   if (gst_structure_has_name(s, "GstMultiFileSink"))<br>    {<br><br>         //time_t t = time(NULL);<br>        // struct tm *tm = localtime(&t);<br>        // printf("%s\n", asctime(tm));<br>    //==================================================date time<br>spaceless====================\\<br><br><br><br>    //localtime() uses the time pointed by t ,<br>    // to fill a tm structure with the<br>    // values that represent the<br>    // corresponding local time.<br><br>     time_t t ;<br>     struct tm *tmp ;<br><br>     time( &t );<br><br>     tmp = localtime( &t );<br><br>    // using strftime to display time<br>    strftime(MY_TIME, sizeof(MY_TIME), "%c", tmp);<br>    printf("date and timeopjofizdfvbid%s\n", MY_TIME );<br><br><br><br>     //==================================================date time<br>spaceless====================\\<br><br><br>         g_print("########################GST_MESSAGE_ELEMENT<br>START#################\n");<br>         g_print("File written.\n");<br>         filename = gst_structure_get_string (s, "filename");<br>        // g_print ("filename------------ %s\n",filename);<br>          char path[1000]={0,};<br>          sprintf(path,"%s",filename);<br>          printf("path---########----------%s\n",path);<br>           g_print ("name-after strcpy--path--------- %s\n",path);<br>          char path3[]="/home/bitcomm-31/Videos/Cam1/";<br>          char date[100]={0,};<br><br>          sprintf(date,"%s",MY_TIME);<br><br>          strcat(date,".mp4");<br><br>          char path2[2000]={0,};<br><br>          strcat(path2,path3);<br>          strcat(path2,date);<br><br><br>    int value;<br><br><br>   value = rename(path, path2);<br><br><br>    if(!value)<br>    {<br>        printf("%s\n", "File name changed successfully");<br>    }<br>    else<br>    {<br>        perror("Error");<br>    }<br><br>         g_print("########################GST_MESSAGE_ELEMENT<br>END#################\n");<br>    }<br>    break;<br><br><br>          //////END<br>        default:<br>          /* We should not reach here */<br>          //g_printerr ("Unexpected message received.\n");<br>          break;<br>      }<br>      gst_message_unref (msg);<br>    }<br>printf("value of terminate %d\n",terminate);<br>  } while (!terminate);<br><br>  gst_element_set_state (data.pipeline, GST_STATE_NULL);<br>  gst_object_unref (data.pipeline);<br><br>return camera1 (void) ;<br><br>}  <br></div>