取消/中止GStreamer tcpclientsink超时的方法 [英] Method to Cancel/Abort GStreamer tcpclientsink Timeout

查看:190
本文介绍了取消/中止GStreamer tcpclientsink超时的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GStreamer通过tcpclientsink元素发送Motion JPEG视频流的应用程序.该应用程序运行正常,除非我通过将连接从有线切换为无线或将无线切换为有线来破坏网络.发生这种情况时,看起来tcpclientsink元素在等待15分钟后才响应消息.如果我在这段时间内尝试关闭应用程序,那将成为一个问题.这是我观察到的:

I am working on an application that uses GStreamer to send a Motion JPEG video stream through a tcpclientsink element. The application works fine, except if I disrupt the network by switching the connection from wired to wireless or wireless to wired. When that happens, it looks like the tcpclientsink element waits 15 minutes before responding to messages. That becomes a problem if I try to shut down the application during this time. Here is what I've observed:

  1. 使用tcpclientsink作为接收器,使用GStreamer启动Motion JPEG媒体流.推送视频的代码在其自己的线程中运行.
  2. 媒体流正在运行时,请通过切换网络连接的类型来中断连接.
  3. 开始关闭应用程序.呼叫gst_bus_post(bus, gst_message_new_eos(NULL)).这似乎被忽略了.
  4. 调用pthread_join等待视频线程退出.最多15分钟没有响应.
  1. Start a Motion JPEG media stream with GStreamer using tcpclientsink as the sink. The code pushing the video runs in its own thread.
  2. While the media stream is running, disrupt the connection by switching the type of network connection.
  3. Start shutting down the application. Call gst_bus_post(bus, gst_message_new_eos(NULL)). This seems to get ignored.
  4. Call pthread_join to wait for the video thread to exit. It does not respond for up to 15 minutes.

当我查看GST_DEBUG消息时,可以看到GStreamer tcpclientsink在写入时遇到错误.重试时显然要等待15分钟.

When I look at the GST_DEBUG messages, I can see that the GStreamer tcpclientsink hit an error while writing. It apparently waits 15 minutes while retrying.

有没有一种方法可以中止或取消与tcpclientsink相关的超时?我是否可以发送其他消息以使接收器立即终止?

Is there a way I can abort or cancel the timeout associated with tcpclientsink? Is there a different message I could send to cause the sink to terminate immediately?

我知道,如果GStreamer不能像我期望的那样快速响应,我可以使用pthread_timedjoin_nppthread_cancel杀死视频线程,但是我希望GStreamer尽可能干净地退出.

I know I can use pthread_timedjoin_np and pthread_cancel to kill the video thread if GStreamer does not respond as fast as I would like, but I would prefer to have GStreamer exit as cleanly as possible.

更新

我应该提到我正在使用GStreamer 0.10.36.不幸的是,这可能只是该版本的错误.我看到1.2.x中的处理方式发生了很大变化.我仍然希望对我使用的版本有一种解决方法.

I should have mentioned I'm using GStreamer 0.10.36. Unfortunately this might just be a bug with that version. I see the handling has changed quite a bit in 1.2.x. I'm still hoping there is a workaround for the version I'm using.

我能够使用gst-launch-0.10重新创建此问题.这可能会更多 不必要的复杂,但是对我有用:

I was able to recreate this problem using gst-launch-0.10. This might be more complicated than necessary, but it worked for me:

启动三个脚本:

  • 以下内容在消费者和生产者之间中继数据:

  • The following relays the data between the consumer and the producer:

同时[1] 做 gst-launch-0.10 tcpserversrc host = 0 port = $ {PORT_IN}! jpegdec! jpegenc! tcpserversink port = $ {PORT_OUT} 完成

while [ 1 ] do gst-launch-0.10 tcpserversrc host=0 port=${PORT_IN} ! jpegdec ! jpegenc ! tcpserversink port=${PORT_OUT} done

以下是消费者的脚本

gst-launch-0.10 tcpclientsrc主机= $ {IP_ADDR}端口= $ {PORT_OUT}! jpegdec! ffmpegcolorspace! ximagesink

gst-launch-0.10 tcpclientsrc host=${IP_ADDR} port=${PORT_OUT} ! jpegdec ! ffmpegcolorspace ! ximagesink

以下是生产者的脚本

gst-launch-0.10 ximagesrc!视频规模! video/x-raw-rgb,framerate = 1/1,width = 640,height = 320! ffmpegcolorspace!杰培根 ! tcpclientsink主机= $ {IP_ADDR}端口= $ {PORT_IN}

gst-launch-0.10 ximagesrc ! videoscale ! video/x-raw-rgb,framerate=1/1,width=640,height=320 ! ffmpegcolorspace ! jpegenc ! tcpclientsink host=${IP_ADDR} port=${PORT_IN}

我在一台机器上运行了前两个脚本,而第二台则运行了第三个脚本 机器.当我从切换第二台计算机上的网络连接时 通过有线连接到无线网络,tcpclientsink花了15分钟以上的时间报告了 错误.

I ran the first two scripts on one machine and the third script on a second machine. When I switched the network connection on the second machine from wired to wireless, it took 15+ minutes for the tcpclientsink to report an error.

推荐答案

为了解决此问题,我必须修补GStreamer.我在gsttcpclientsink.c的gst_tcp_client_sink_start()函数中添加了用于指定发送超时的代码

In order to fix the problem, I had to patch GStreamer. I added code to specify the send timeout in the gst_tcp_client_sink_start() function of gsttcpclientsink.c

struct timeval timeout;
timeout.tv_sec = 60;
timeout.tv_usec = 0;
...
setsockopt (this->sock_fd.fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));

现在,即使在流式传输视频时网络中断了,该应用程序也能在一分钟内关闭(对于我的情况而言是可以接受的).

Now the application is capable of shutting down within one minute (acceptable for my situation) even if the network was disrupted while streaming video.

注意:对于1.2.1版本,这似乎不是问题,但我需要保留0.10.36.

Note: It doesn't look like this will be a problem with version 1.2.1, but I need to stay with 0.10.36.

这篇关于取消/中止GStreamer tcpclientsink超时的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆