From 780a20689c607e6734aefcf4c8697f2b6e5b93be Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Sat, 1 Jan 2022 10:13:46 +0100 Subject: [PATCH] Improved user message for stream discovery failure --- Stream.cpp | 7 +++++-- Stream.h | 4 +++- StreamSource.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Stream.cpp b/Stream.cpp index f4ee8e3..e828873 100644 --- a/Stream.cpp +++ b/Stream.cpp @@ -157,7 +157,8 @@ StreamInfo StreamDiscoverer(const std::string &description, guint w, guint h) // wait for the callback_stream_discoverer to return, no more than 4 sec std::mutex mtx; std::unique_lock lck(mtx); - info.discovered.wait_for(lck,std::chrono::seconds(TIMEOUT)); + if ( info.discovered.wait_for(lck,std::chrono::seconds(TIMEOUT)) == std::cv_status::timeout) + info.message = "Time out."; // stop and delete pipeline GstStateChangeReturn ret = gst_element_set_state (_pipeline, GST_STATE_NULL); @@ -166,6 +167,8 @@ StreamInfo StreamDiscoverer(const std::string &description, guint w, guint h) gst_object_unref (_pipeline); } } + else + info.message = error->message; } // at this point, the info should be filled return info; @@ -631,7 +634,7 @@ void Stream::update() } // invalid info; fail else - fail("Failed to determine resolution"); + fail("Could not create stream: " + i.message); } } // wait next frame to display diff --git a/Stream.h b/Stream.h index 7d22fde..4b20bef 100644 --- a/Stream.h +++ b/Stream.h @@ -15,13 +15,14 @@ class Visitor; #define N_FRAME 3 -#define TIMEOUT 4 +#define TIMEOUT 5 struct StreamInfo { guint width; guint height; std::condition_variable discovered; + std::string message; StreamInfo(guint w=0, guint h=0) { width = w; @@ -31,6 +32,7 @@ struct StreamInfo { StreamInfo(const StreamInfo& b) { width = b.width; height = b.height; + message = b.message; } inline bool valid() { return width > 0 && height > 0; } diff --git a/StreamSource.cpp b/StreamSource.cpp index 0847c39..a86537b 100644 --- a/StreamSource.cpp +++ b/StreamSource.cpp @@ -45,7 +45,7 @@ GenericStreamSource::GenericStreamSource(uint64_t id) : StreamSource(id) void GenericStreamSource::setDescription(const std::string &desc) { - gst_description_ = desc; + gst_description_ = BaseToolkit::unwrapped(desc); gst_elements_ = BaseToolkit::splitted(desc, '!'); Log::Notify("Creating Source with Stream description '%s'", gst_description_.c_str());