Bugfix Stream timeout initialization test

This commit is contained in:
Bruno Herbelin
2021-12-31 14:24:51 +01:00
parent d5092b1765
commit 2b5b8ad02c
2 changed files with 12 additions and 9 deletions

View File

@@ -114,7 +114,6 @@ GstFlowReturn callback_stream_discoverer (GstAppSink *sink, gpointer p)
// release info to let StreamDiscoverer go forward
info->discovered.notify_all();
}
gst_caps_unref(caps);
}
else
ret = GST_FLOW_FLUSHING;
@@ -287,7 +286,7 @@ void Stream::execute_open()
opened_ = true;
// launch a timeout to check on open status
std::thread( timeout_open, this ).detach();
std::thread( timeout_initialize, this ).detach();
}
void Stream::fail(const std::string &message)
@@ -296,12 +295,13 @@ void Stream::fail(const std::string &message)
failed_ = true;
}
void Stream::timeout_open(Stream *str)
void Stream::timeout_initialize(Stream *str)
{
// vait for timeout
std::this_thread::sleep_for(std::chrono::seconds(TIMEOUT));
if (!str->textureinitialized_)
// wait for the condition that source was initialized successfully in
std::mutex mtx;
std::unique_lock<std::mutex> lck(mtx);
if ( str->initialized_.wait_for(lck,std::chrono::seconds(TIMEOUT)) == std::cv_status::timeout )
// if waited more than TIMEOUT, its dead :(
str->fail("Failed to initialize");
}
@@ -552,7 +552,9 @@ void Stream::init_texture(guint index)
}
glBindTexture(GL_TEXTURE_2D, 0);
// done
textureinitialized_ = true;
initialized_.notify_all();
}

View File

@@ -211,13 +211,14 @@ protected:
// gst pipeline control
virtual void execute_open();
virtual void fail(const std::string &message);
static void timeout_open(Stream *str);
// gst frame filling
std::atomic<bool> textureinitialized_;
bool textureinitialized_;
void init_texture(guint index);
void fill_texture(guint index);
bool fill_frame(GstBuffer *buf, FrameStatus status);
std::condition_variable initialized_;
static void timeout_initialize(Stream *str);
// gst callbacks
static void callback_end_of_stream (GstAppSink *, gpointer);