四、Gstreamer RTSP client timeout issues

1 background

After checking the DeepStream source code, I found that DeepStream in my project is running in another thread. After turning on the RTSP stream reconnection function, sometimes it will be blocked in the setting status function (no matter which element in the bin is set, it will be blocked). This is not the case for the time being. Another machine is available for me to study whether it is caused by a version problem or a thread problem. I tried to solve it through other methods.

  if (gst_element_set_state (src_bin->bin,
          GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE) {
    
    
    g_message ("%s:err\n", __func__);
    GST_ERROR_OBJECT (src_bin->bin, "Can't set source bin to NULL");
    return FALSE;
  }

Gstreamer RTSP client timeout issues

question:

I'm having some issues with Gstreamer's RTSP client. So, I have a client program and I want it to give me an appropriate response from a watchdog function whenever the RTSP client receives/sends a message or returns an error etc. and exits with a code accordingly if there is an error. What I want to do is,

  1. I just create an RTSP server using VLC on my machine and connect to this server. Apparently I can successfully create the connection.
  2. I stopped the server by simply closing VLC. So now the watch dog function should receive the correct error code and print it to the screen. But it never does. In Gstreamer's RTSP documentation, there is a function called gst_rtsp_connection_connect, which accepts a connection and a timeout value, and it is stated in the documentation that if the timeout is NULL, the function may block forever. So I thought that since I set NULL in the timeout field it never times out and thinks it's still connected to the server and therefore never enters any watchdog function. However, when I apply a 5 second timeout, then it directly terminates the connection after 5-7 seconds and enters some watchdog function. I don't want my code to give an error right away, even though there is a correct connection and the server is still working, I just want it to give some error when the server is actually down and the timeout has elapsed. How can I solve this problem?
/*
 * INCLUDES
 * /usr/include/gstreamer-1.0
 * /usr/include/glib-2.0
 * /usr/lib/x86_64-linux-gnu/glib-2.0/include
 * /usr/include/gstreamer-1.0/gst/rtsp
 *
 * LIBRARIES
 * gstreamer-1.0
 * gstrtsp-1.0
 * gobject-2.0
 * glib-2.0
 *
 * MISC.
 * -std=c99
 *
 *
 *
 * */
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <gst/rtsp/gstrtspmessage.h>
#include <gst/rtsp/gstrtspurl.h>
#include <gst/rtsp/gstrtspdefs.h>
#include <gst/rtsp/gstrtsptransport.h>
#include <gst/rtsp/gstrtspconnection.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
static GstRTSPStatusCode
tunnel_start (GstRTSPWatch * watch, gpointer user_data)
{
    
    
  g_print("tunnel_start\n");
  return GST_RTSP_STS_OK;
}
static GstRTSPResult
tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
{
    
    
    g_print("tunnel_complete\n");
  return GST_RTSP_OK;
}
static GstRTSPResult
tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
{
    
    
    g_print("tunnel_lost\n");
  return GST_RTSP_OK;
}
static GstRTSPResult
closed (GstRTSPWatch * watch, gpointer user_data)
{
    
    
    g_print("closed\n");
  return GST_RTSP_OK;
}
static GstRTSPResult
message_sent (GstRTSPWatch * watch, guint id, gpointer user_data)
{
    
    
    g_print("message_sent\n");
  return GST_RTSP_OK;
}
static GstRTSPResult
message_received (GstRTSPWatch *watch, GstRTSPMessage *message, gpointer user_data) {
    
    
    g_print("message_received\n");
  return GST_RTSP_OK;
}
static  GstRTSPResult
error (GstRTSPWatch *watch, GstRTSPResult result, gpointer user_data) {
    
    
    g_print("error\n");
  return GST_RTSP_OK;
}
static  GstRTSPResult
error_full (GstRTSPWatch *watch, GstRTSPResult result, GstRTSPMessage *message, guint id, gpointer user_data) {
    
    
    g_print("error_full\n");
  return GST_RTSP_OK;
}
static GstRTSPWatchFuncs watch_funcs = {
    
    
  message_received,
  message_sent,
  closed,
  error,
  tunnel_start,
  tunnel_complete,
  error_full,
  tunnel_lost
};
/* main method */
int main (int argc, char *argv[]) {
    
    
    GMainLoop *loop;
    loop = g_main_loop_new (NULL, FALSE);
    GstRTSPUrl *url = NULL;
    GstRTSPConnection *conn = NULL;
    GstRTSPResult res;
    GstRTSPWatch *watch;
    GTimeVal *timeout;
    timeout->tv_sec = 5;
    timeout->tv_usec = 5000000;
    res = gst_rtsp_url_parse ("rtsp://localhost:5000/test", &url);
    res = gst_rtsp_connection_create (url, &conn);
    if (res == GST_RTSP_OK) {
    
    
      g_print("Connection created.\n");
    }
    res = gst_rtsp_connection_connect (conn, timeout);
    if (res == GST_RTSP_OK) {
    
    
      g_print("Connection connected.\n");
    } else {
    
    
      g_printerr("Connection not connected. Exiting with code 500.\n");
      exit(500);
    }
    watch = gst_rtsp_watch_new (conn, &watch_funcs, loop, NULL);
    if (watch == NULL) {
    
    
        g_print("Failed to create watch.\n");
    }
    gst_rtsp_watch_attach (watch, NULL);
    gst_rtsp_url_free (url);
    g_main_loop_run (loop);
    return 0;
}
  • You can pass NULL->PLAYING in the bus function
  • According to gst-rtsp-server

Guess you like

Origin blog.csdn.net/Creationyang/article/details/129257216