How to restart when source IP address is not available for some time

Shubham Shrivastava shubham333vm at gmail.com
Thu Nov 22 11:10:59 UTC 2018


As if my server gets down or if their is some problem with my camera.
So i want if there is an element provided by you people so that i can
listen if ip address is available or not if not it sends a message ip
address is not available.

I resolve this problem by calling a method recursively because whenever it
does not get any data from source it give a msg end of stream or error so
after getting that msg i deference all elements and at the end i
recursively call same method so that i can check if source is available or
not but after two three call backs it give segmentation fault.
I also tried with ping methodology but give same result.

Here is my code..

void * camera1(void * u)

  {

        printf("Thread starting....\n");
        GstMessage *msg;
        CustomData data;
        guint bus_watch_id;
        GstBus *bus;
        GstStateChangeReturn ret;
        gboolean terminate = FALSE;
        char cam2[9]="cam2";
        printf("start playing11..\n");
        data.source = gst_element_factory_make ("uridecodebin", "source");
        data.convert = gst_element_factory_make ("videoconvert", "convert");
       // data.sink = gst_element_factory_make ("autoaudiosink", "sink");
       // data.videoconvert1 = gst_element_factory_make("videoconvert",
"videoconvert1");
    data.videoconvert2 = gst_element_factory_make("videoconvert",
"videoconvert2");
    //data.queue1 = gst_element_factory_make("queue", "queue1");
    data.queue2 = gst_element_factory_make("queue", "queue2");
    data.tee = gst_element_factory_make("tee", "tee");

    data.frameratefilter = gst_element_factory_make("capsfilter", NULL);
    data.videorate = gst_element_factory_make("videorate", NULL);
    data.avenc = gst_element_factory_make("avenc_mpeg2video", NULL);
    data.avimux = gst_element_factory_make("avimux", NULL);
    data.filesink = gst_element_factory_make("multifilesink", "filesink");
   // data.splitmuxsink = gst_element_factory_make("splitmuxsink",
"splitmuxsink");
    printf("start playing22..\n");
     /* Create the empty pipeline */
       data.pipeline = gst_pipeline_new ("test-pipeline");

  if (!data.pipeline || !data.source || !data.convert ||
!data.videoconvert2 || !data.queue2 || !data.tee || !data.filesink  ) {
    g_printerr ("Not all elements could be created.\n");
    return 0;
  }
   printf("start playing33..\n");
        g_object_set(G_OBJECT(data.frameratefilter), "caps",
gst_caps_from_string("video/x-raw,framerate=50/1"), NULL);

   printf("start playing44..\n");

  /* Build the pipeline. Note that we are NOT linking the source at this
   * point. We will do it later. */
  gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.convert
,data.videoconvert2, data.queue2, data.tee,data.frameratefilter,
data.videorate,data.avenc,data.avimux,data.filesink,NULL);
  if (!gst_element_link (data.convert, data.tee)) {
    g_printerr ("Elements could not be linked.\n");
    gst_object_unref (data.pipeline);
    return 0;
  }printf("start playing..\n");
    if (!gst_element_link_many(data.queue2, data.videorate,
data.frameratefilter, data.videoconvert2, data.avenc,data.avimux,
data.filesink, NULL))
        g_error("Failed to link save elements!");

    if ( !(data.tee_src_pad_template = gst_element_class_get_pad_template
(GST_ELEMENT_GET_CLASS (data.tee), "src_%u"))) {
      g_critical ("Unable to get pad template!");
      return;
     }
printf("start playing..\n");
       // data.qpad1 = gst_element_get_static_pad(data.queue1, "sink");
    data.qpad2 = gst_element_get_static_pad(data.queue2, "sink");
  //  data.teepad1 = gst_element_request_pad (data.tee,
data.tee_src_pad_template, NULL, NULL);
    //g_print ("Obtained request pad %s for queue1 branch.\n",
gst_pad_get_name (data.teepad1));
    data.teepad2 = gst_element_request_pad (data.tee,
data.tee_src_pad_template, NULL, NULL);
    g_print ("Obtained request pad %s for queue2 branch.\n",
gst_pad_get_name (data.teepad2));

    if( !data.teepad2 || !data.qpad2){
        g_error("Creation of one tee pad failed.");
        return;
    }
printf("start playing..\n");
  //  gst_pad_link (data.teepad1, data.qpad1);
    gst_pad_link (data.teepad2, data.qpad2);

 //   gst_object_unref (GST_OBJECT (data.qpad1));
    gst_object_unref (GST_OBJECT (data.qpad2));
    //gst_object_unref (GST_OBJECT (data.teepad1));
    gst_object_unref (GST_OBJECT (data.teepad2));

    printf("start playing.12345.\n");
    GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(data.pipeline),
GST_DEBUG_GRAPH_SHOW_ALL, "pipeline_graph");

   printf("%s",message[6]+10);

  /* Set the URI to play */
  g_object_set (data.source, "uri",message[7]+10, NULL);

  /* Connect to the pad-added signal */
  g_signal_connect (data.source, "pad-added", G_CALLBACK
(pad_added_handler), &data);
  //printf("%s",*prop);
  /* Start playing */
  printf("start playing12..\n");
  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 0;
  }


    g_object_set(G_OBJECT
(data.filesink),"location","/home/bitcomm-31/Videos/Cam1/shubham_%03d.mp4","async",0,
NULL);
    g_object_set(G_OBJECT (data.filesink),"post-messages", TRUE,
"multifilesink", 0, NULL);
    g_object_set(G_OBJECT (data.filesink),"next-file", 4,"multifilesink",
0, NULL);
    g_object_set(G_OBJECT (data.filesink), "max-file-size", 500000,
"multifilesink", 0, NULL);
    g_object_set(G_OBJECT (data.filesink), "max-files ",5, "multifilesink",
0, NULL);


printf("Thread Start.. Listen to bus\n");

/* Listen to the bus */
  bus = gst_element_get_bus (data.pipeline);
printf("Bus status fetched\n");
  do {
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
    GST_MESSAGE_ANY);
    //msg=GST_MESSAGE_EOS;
   printf("Enetring switch case\n");
    /* Parse message */
    if (msg != NULL) {
      GError *err;
      gchar *debug_info;
      printf("msg.type %u\n",GST_MESSAGE_TYPE (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\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;
          //////START
          case GST_MESSAGE_UNKNOWN:
        g_print("GST_MESSAGE_UNKNOWN\n");
break;
//case GST_MESSAGE_ELEMENT:
//g_print("########################GST_MESSAGE_ELEMENT     START
#################\n");
//g_message ("get message %s", gst_structure_get_name
(gst_message_get_structure(msg)));
//g_print ("filenemae %d",gst_message_get_structure(msg))->index);
//g_print("########################GST_MESSAGE_ELEMENT     END
#################\n");
//break;

case GST_MESSAGE_ELEMENT:


        s = gst_message_get_structure (msg);
   if (gst_structure_has_name(s, "GstMultiFileSink"))
    {

         //time_t t = time(NULL);
        // struct tm *tm = localtime(&t);
        // printf("%s\n", asctime(tm));
    //==================================================date time
spaceless====================\\



    //localtime() uses the time pointed by t ,
    // to fill a tm structure with the
    // values that represent the
    // corresponding local time.

     time_t t ;
     struct tm *tmp ;

     time( &t );

     tmp = localtime( &t );

    // using strftime to display time
    strftime(MY_TIME, sizeof(MY_TIME), "%c", tmp);
    printf("date and timeopjofizdfvbid%s\n", MY_TIME );



     //==================================================date time
spaceless====================\\


         g_print("########################GST_MESSAGE_ELEMENT
START#################\n");
         g_print("File written.\n");
         filename = gst_structure_get_string (s, "filename");
        // g_print ("filename------------ %s\n",filename);
          char path[1000]={0,};
          sprintf(path,"%s",filename);
          printf("path---########----------%s\n",path);
           g_print ("name-after strcpy--path--------- %s\n",path);
          char path3[]="/home/bitcomm-31/Videos/Cam1/";
          char date[100]={0,};

          sprintf(date,"%s",MY_TIME);

          strcat(date,".mp4");

          char path2[2000]={0,};

          strcat(path2,path3);
          strcat(path2,date);


    int value;


   value = rename(path, path2);


    if(!value)
    {
        printf("%s\n", "File name changed successfully");
    }
    else
    {
        perror("Error");
    }

         g_print("########################GST_MESSAGE_ELEMENT
END#################\n");
    }
    break;


          //////END
        default:
          /* We should not reach here */
          //g_printerr ("Unexpected message received.\n");
          break;
      }
      gst_message_unref (msg);
    }
printf("value of terminate %d\n",terminate);
  } while (!terminate);

  gst_element_set_state (data.pipeline, GST_STATE_NULL);
  gst_object_unref (data.pipeline);

return camera1 (void) ;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20181122/fc087eb8/attachment-0001.html>


More information about the gstreamer-devel mailing list