Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when requesting libav stream of non-published topic #59

Closed
jabailey opened this issue Feb 21, 2018 · 6 comments
Closed

Comments

@jabailey
Copy link
Contributor

jabailey commented Feb 21, 2018

To reproduce: run web_video_server like normal, then point browser to http://localhost:8080/stream_viewer?topic=/some/unpublished/topic&type=vp8

Results:

root@master:/catkin_ws# rosrun web_video_server web_video_server
[ INFO] [1519240063.734495445]: Waiting For connections on 0.0.0.0:8080
[ INFO] [1519240067.188024505]: Handling Request: /stream_viewer?topic=/some/unpublished/topic&type=vp8
[ INFO] [1519240067.303481877]: Handling Request: /stream?topic=/some/unpublished/topic&type=vp8
[ INFO] [1519240067.732592846]: Removed Stream: /some/unpublished/topic
Segmentation fault (core dumped)

The segfault seems to stem from referencing format_context_ in the LibavStreamer destructor before it's been allocated: https://github.com/RobotWebTools/web_video_server/blob/develop/src/libav_streamer.cpp#L80

Quick fix (tested on a local branch):

diff --git a/src/libav_streamer.cpp b/src/libav_streamer.cpp
index 08980e4..8682667 100644
--- a/src/libav_streamer.cpp
+++ b/src/libav_streamer.cpp
@@ -77,10 +77,11 @@ LibavStreamer::~LibavStreamer()
   }
   if (io_buffer_)
     delete io_buffer_;
-  if (format_context_->pb)
-    av_free(format_context_->pb);
-  if (format_context_)
+  if (format_context_) {
+    if (format_context_->pb)
+      av_free(format_context_->pb);
     avformat_free_context(format_context_);
+  }
   if (sws_context_)
     sws_freeContext(sws_context_);
 }
@SystemDiagnosticss
Copy link

@jabailey Please say, after your fix this bug your videostreaming (with codec vp8) has big latency or not?? Can show it(in youtube or anywhere )?

@jihoonl
Copy link
Member

jihoonl commented Feb 24, 2018

Patch looks good to me. could you create a PR to patch this?

jabailey added a commit to jabailey/web_video_server that referenced this issue Feb 26, 2018
@jabailey
Copy link
Contributor Author

@jihoonl #60

@jabailey
Copy link
Contributor Author

@SystemDiagnosticss Yes, I've found that there is high latency - the stream takes about 5-10 seconds to initialize, and the frames play 5-10 seconds behind. I don't see how my change could affect that, but I'll admit I'm not very familiar with this code. Is the latency lower without my change?

@jihoonl
Copy link
Member

jihoonl commented Feb 26, 2018

I saw the high latency too with codec vp8. @randoms do you have any idea?

@SystemDiagnosticss
Copy link

@jabailey @jihoonl In case mjpeg stream I have 2-3 sec latency. But its very very big latency. I am new in ROS but situation with videostream is very funny for me. I work with videostream without ROS (Raspberry Pi to web page) and has latency 0.2 sec. Its uv4l libs for videostream. https://www.linux-projects.org/uv4l/tutorials/ This project use webrtc. I try use webrts for ROS (http://wiki.ros.org/webrtc_ros) but I can't install it. I create questions on rosanswer, stackoverflow but not receive an answer. I don't understand is it really in ROS does not have good videostreaming solution ?? This is very strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants