四、Gstreamer RTSP client timeout issues

1 背景

查看DeepStream源码后,我的项目中DeepStream在另一个线程中运行,开启RTSP流重连功能后,有时会堵塞在设定状态函数(无论设定哪一个bin中的元素,都会阻塞),暂时没有另一台机器供我研究是否因为版本问题造成的,或者线程问题。我试图通过其他办法进行解决。

  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

问题:

我有一些问题与Gstreamer的RTSP客户端。因此,我有一个客户端程序,我希望它从一个看门狗函数给我适当的响应,每当RTSP客户端接收/发送消息或返回错误等,并相应地退出代码,如果有错误。我要做的是,

  1. 我只需在我的机器上使用VLC创建一个RTSP服务器,并连接到这个服务器。显然我可以成功地创建连接。
  2. 我通过简单地关闭VLC来停止服务器。所以现在watch dog函数应该接收到正确的错误码,并将其打印到屏幕上。但它从来不这样做。在Gstreamer的RTSP文档中,有一个名为gst_rtsp_connection_connect的函数,它接受一个连接和一个超时值,在文档中指出,如果超时为NULL,该函数可能永远阻塞。所以我认为,由于我在timeout字段中设置了NULL,它永远不会超时,并且认为它仍然连接到服务器,因此永远不会进入任何看门狗函数。然而,当我申请一个5秒的超时,然后它直接在5-7秒后终止连接,并进入一些看门狗函数。我不希望我的代码立即给出错误,即使有一个正确的连接,服务器仍然在工作中,我只是希望它在服务器实际关闭时给出一些错误,并且超时时间已经过去。我该如何解决这个问题?
/*
 * 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;
}
  • 可以通过bus函数中NULL->PLAYING
  • 依据gst-rtsp-server
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值