From 0eae04ab8366a72d4fa18fc5c6590d43a4823f6c Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Tue, 16 Jan 2024 18:47:54 +0100 Subject: [PATCH] BugFix Accept empty string to create Text source --- src/Mixer.cpp | 12 ++++++++---- src/TextSource.cpp | 30 ++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/Mixer.cpp b/src/Mixer.cpp index 412b1d9..30cc4b5 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -444,10 +444,14 @@ Source *Mixer::createSourceText(const std::string &contents, glm::ivec2 res) s->setContents(contents, res); // propose a new name based on contents - std::string basestring = BaseToolkit::transliterate(contents); - basestring = BaseToolkit::splitted(basestring, '\n').front(); - if (SystemToolkit::file_exists(basestring)) - basestring = SystemToolkit::base_filename(basestring); + std::string basestring = "Text"; + if (contents.size() > 1) { + basestring = BaseToolkit::transliterate(contents); + if (SystemToolkit::file_exists(basestring)) + basestring = SystemToolkit::base_filename(basestring); + else + basestring = BaseToolkit::splitted(basestring, '\n').front(); + } s->setName( basestring ); return s; diff --git a/src/TextSource.cpp b/src/TextSource.cpp index 3f88858..781e8a1 100644 --- a/src/TextSource.cpp +++ b/src/TextSource.cpp @@ -220,24 +220,22 @@ void TextContents::open(const std::string &text, glm::ivec2 res) { std::string gstreamer_pattern = "videotestsrc pattern=black background-color=0x00000000 ! " - "textoverlay text=\"! no text !\" halignment=center valignment=center "; + "textoverlay text=\"\" halignment=center valignment=center "; - if (!text.empty() && text_.compare(text) != 0) { - // set text - text_ = text; - // test if text is the filename of a subtitle - if (TextContents::SubtitleDiscoverer(text_)) { - // setup a pipeline that reads the file and parses subtitle - // Log::Info("Using %s as subtitle file", text.c_str()); - gstreamer_pattern = "filesrc name=src ! subparse ! queue ! txt. "; - } else { - // else, setup a pipeline with custom appsrc - // Log::Info("Using '%s' as raw text content", text.c_str()); - gstreamer_pattern = ""; - } - gstreamer_pattern += "videotestsrc name=bg pattern=black background-color=0x00000000 ! " - "textoverlay name=txt "; + // set text + text_ = text; + // test if text is the filename of a subtitle + if (TextContents::SubtitleDiscoverer(text_)) { + // setup a pipeline that reads the file and parses subtitle + // Log::Info("Using %s as subtitle file", text.c_str()); + gstreamer_pattern = "filesrc name=src ! subparse ! queue ! txt. "; + } else { + // else, setup a pipeline with custom appsrc + // Log::Info("Using '%s' as raw text content", text.c_str()); + gstreamer_pattern = ""; } + gstreamer_pattern += "videotestsrc name=bg pattern=black background-color=0x00000000 ! " + "textoverlay name=txt "; // (private) open stream Stream::open(gstreamer_pattern, res.x, res.y);