BugFix: clean interrupt stream when ending abruptly

This commit is contained in:
brunoherbelin
2021-03-30 19:03:33 +02:00
parent 8eef5465c9
commit 7293b8b9dd
2 changed files with 30 additions and 1 deletions

View File

@@ -187,6 +187,28 @@ void Streaming::removeStreams(const std::string &clientname)
streamers_lock_.unlock();
}
void Streaming::removeStream(const VideoStreamer *vs)
{
if ( vs!= nullptr && streamers_lock_.try_lock()) {
std::vector<VideoStreamer *>::const_iterator sit = streamers_.begin();
while ( sit != streamers_.end() ){
if ( *(sit) == vs) {
#ifdef STREAMER_DEBUG
NetworkToolkit::StreamConfig config = vs->config_;
Log::Info("Ending streaming to %s:%d", config.client_address.c_str(), config.port);
#endif
// remove from list
streamers_.erase(sit);
break;
}
else
sit++;
}
streamers_lock_.unlock();
}
}
void Streaming::refuseStream(const std::string &sender, int reply_to)
{
// get ip of client
@@ -263,7 +285,7 @@ void Streaming::addStream(const std::string &sender, int reply_to, const std::st
}
VideoStreamer::VideoStreamer(NetworkToolkit::StreamConfig conf): FrameGrabber(), config_(conf)
VideoStreamer::VideoStreamer(NetworkToolkit::StreamConfig conf): FrameGrabber(), config_(conf), stopped_(false)
{
}
@@ -386,6 +408,10 @@ void VideoStreamer::stop ()
// stop recording
FrameGrabber::stop ();
// inform streaming manager to remove myself
// NB: will not be effective if called inside a locked streamers_lock_
Streaming::manager().removeStream(this);
// force finished
finished_ = true;
}

View File

@@ -46,6 +46,7 @@ public:
inline bool enabled() const { return enabled_; }
void removeStreams(const std::string &clientname);
void removeStream(const std::string &sender, int port);
void removeStream(const VideoStreamer *vs);
bool busy();
std::vector<std::string> listStreams();
@@ -74,10 +75,12 @@ class VideoStreamer : public FrameGrabber
// connection information
NetworkToolkit::StreamConfig config_;
std::atomic<bool> stopped_;
public:
VideoStreamer(NetworkToolkit::StreamConfig conf);
virtual ~VideoStreamer() {}
std::string info() const override;
};