From 8a65985c7f8af18e66e2c214991333afa551cf90 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Mon, 5 Feb 2024 08:24:39 -0800 Subject: [PATCH 1/7] Add an option for passing in the offscreen window for thumbnail genertion --- lib/tlTimelineUI/TimelineItem.cpp | 6 ++++-- lib/tlTimelineUI/TimelineItem.h | 7 +++++++ lib/tlTimelineUI/TimelineWidget.cpp | 12 ++++++++++++ lib/tlUI/ThumbnailSystem.cpp | 22 ++++++++++++++-------- lib/tlUI/ThumbnailSystem.h | 12 ++++++++++-- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/tlTimelineUI/TimelineItem.cpp b/lib/tlTimelineUI/TimelineItem.cpp index d78c33976..e8da77e10 100644 --- a/lib/tlTimelineUI/TimelineItem.cpp +++ b/lib/tlTimelineUI/TimelineItem.cpp @@ -120,6 +120,7 @@ namespace tl double scale, const ItemOptions& options, const std::shared_ptr& itemData, + const std::shared_ptr& window, const std::shared_ptr& context, const std::shared_ptr& parent) { @@ -143,7 +144,7 @@ namespace tl p.player = player; - p.thumbnailGenerator = ui::ThumbnailGenerator::create(context); + p.thumbnailGenerator = ui::ThumbnailGenerator::create(context, window); const auto otioTimeline = p.player->getTimeline()->getTimeline(); int trackIndex = 0; @@ -268,11 +269,12 @@ namespace tl double scale, const ItemOptions& options, const std::shared_ptr& itemData, + const std::shared_ptr& window, const std::shared_ptr& context, const std::shared_ptr& parent) { auto out = std::shared_ptr(new TimelineItem); - out->_init(player, stack, scale, options, itemData, context, parent); + out->_init(player, stack, scale, options, itemData, window, context, parent); return out; } diff --git a/lib/tlTimelineUI/TimelineItem.h b/lib/tlTimelineUI/TimelineItem.h index b21aaf139..3e6b4ba8a 100644 --- a/lib/tlTimelineUI/TimelineItem.h +++ b/lib/tlTimelineUI/TimelineItem.h @@ -10,6 +10,11 @@ namespace tl { + namespace gl + { + class GLFWWindow; + } + namespace timelineui { //! Track types. @@ -36,6 +41,7 @@ namespace tl double scale, const ItemOptions&, const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr&, const std::shared_ptr& parent); @@ -51,6 +57,7 @@ namespace tl double scale, const ItemOptions&, const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr&, const std::shared_ptr& parent = nullptr); diff --git a/lib/tlTimelineUI/TimelineWidget.cpp b/lib/tlTimelineUI/TimelineWidget.cpp index a59ef131f..5daa15e44 100644 --- a/lib/tlTimelineUI/TimelineWidget.cpp +++ b/lib/tlTimelineUI/TimelineWidget.cpp @@ -6,6 +6,9 @@ #include +#include +#include + namespace tl { namespace timelineui @@ -25,6 +28,8 @@ namespace tl std::shared_ptr > itemOptions; bool sizeInit = true; + std::shared_ptr window; + std::shared_ptr scrollWidget; std::shared_ptr timelineItem; @@ -61,6 +66,12 @@ namespace tl p.stopOnScrub = observer::Value::create(true); p.itemOptions = observer::Value::create(); + p.window = gl::GLFWWindow::create( + "tl::timelineui::TimelineWidget", + math::Size2i(1, 1), + context, + static_cast(gl::GLFWWindowOptions::None)); + p.scrollWidget = ui::ScrollWidget::create( context, ui::ScrollType::Both, @@ -505,6 +516,7 @@ namespace tl p.scale, p.itemOptions->get(), p.itemData, + p.window, context); p.timelineItem->setEditable(p.editable->get()); p.timelineItem->setStopOnScrub(p.stopOnScrub->get()); diff --git a/lib/tlUI/ThumbnailSystem.cpp b/lib/tlUI/ThumbnailSystem.cpp index 2e697d551..0d59d09ce 100644 --- a/lib/tlUI/ThumbnailSystem.cpp +++ b/lib/tlUI/ThumbnailSystem.cpp @@ -275,7 +275,8 @@ namespace tl }; void ThumbnailGenerator::_init( - const std::shared_ptr& context) + const std::shared_ptr& context, + const std::shared_ptr& window) { TLRENDER_P(); @@ -283,11 +284,15 @@ namespace tl p.cache = context->getSystem()->getCache(); - p.window = gl::GLFWWindow::create( - "tl::ui::ThumbnailGenerator", - math::Size2i(1, 1), - context, - static_cast(gl::GLFWWindowOptions::None)); + p.window = window; + if (!p.window) + { + p.window = gl::GLFWWindow::create( + "tl::ui::ThumbnailGenerator", + math::Size2i(1, 1), + context, + static_cast(gl::GLFWWindowOptions::None)); + } p.thread.ioCache.setMax(1000); p.thread.running = true; @@ -335,10 +340,11 @@ namespace tl } std::shared_ptr ThumbnailGenerator::create( - const std::shared_ptr& context) + const std::shared_ptr& context, + const std::shared_ptr& window) { auto out = std::shared_ptr(new ThumbnailGenerator); - out->_init(context); + out->_init(context, window); return out; } diff --git a/lib/tlUI/ThumbnailSystem.h b/lib/tlUI/ThumbnailSystem.h index 1c1819662..ecb263e15 100644 --- a/lib/tlUI/ThumbnailSystem.h +++ b/lib/tlUI/ThumbnailSystem.h @@ -17,6 +17,11 @@ namespace tl { + namespace gl + { + class GLFWWindow; + } + namespace ui { //! Information request. @@ -135,7 +140,9 @@ namespace tl class ThumbnailGenerator : public std::enable_shared_from_this { protected: - void _init(const std::shared_ptr&); + void _init( + const std::shared_ptr&, + const std::shared_ptr&); ThumbnailGenerator(); @@ -144,7 +151,8 @@ namespace tl //! Create a new thumbnail generator. static std::shared_ptr create( - const std::shared_ptr&); + const std::shared_ptr&, + const std::shared_ptr& = nullptr); //! Get information. InfoRequest getInfo( From acfdb6180263a5832fb674d4cb01147252dd8e59 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Thu, 8 Feb 2024 10:01:05 -0800 Subject: [PATCH 2/7] Only build required libraries --- lib/CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 3af261a87..fc73b1748 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,28 +1,28 @@ -add_subdirectory(tlBaseApp) add_subdirectory(tlCore) add_subdirectory(tlGL) add_subdirectory(tlDevice) add_subdirectory(tlIO) add_subdirectory(tlPlay) -add_subdirectory(tlResourceApp) add_subdirectory(tlTimeline) add_subdirectory(tlTimelineUI) add_subdirectory(tlUI) if(TLRENDER_GLFW) - add_subdirectory(tlTimelineGL) - if(TLRENDER_PROGRAMS OR TLRENDER_EXAMPLES) - add_subdirectory(tlUIApp) - endif() - if(TLRENDER_PROGRAMS) - add_subdirectory(tlBakeApp) - add_subdirectory(tlPlayApp) - endif() + add_subdirectory(tlTimelineGL) + if(TLRENDER_PROGRAMS OR TLRENDER_EXAMPLES) + add_subdirectory(tlBaseApp) + add_subdirectory(tlUIApp) + endif() + if(TLRENDER_PROGRAMS) + add_subdirectory(tlBakeApp) + add_subdirectory(tlPlayApp) + add_subdirectory(tlResourceApp) + endif() endif() if(TLRENDER_QT6 OR TLRENDER_QT5 AND NOT "${TLRENDER_API}" STREQUAL "GLES_2") add_subdirectory(tlQt) add_subdirectory(tlQtQuick) add_subdirectory(tlQtWidget) - if(TLRENDER_PROGRAMS) - add_subdirectory(tlPlayQtApp) - endif() + if(TLRENDER_PROGRAMS) + add_subdirectory(tlPlayQtApp) + endif() endif() From 7a49f82c4ace6f1c805f393ab904aa739516bc77 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Thu, 8 Feb 2024 10:07:30 -0800 Subject: [PATCH 3/7] Build fix --- lib/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index fc73b1748..2f1b0f479 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -8,8 +8,10 @@ add_subdirectory(tlTimelineUI) add_subdirectory(tlUI) if(TLRENDER_GLFW) add_subdirectory(tlTimelineGL) - if(TLRENDER_PROGRAMS OR TLRENDER_EXAMPLES) + if(TLRENDER_PROGRAMS OR TLRENDER_EXAMPLES OR TLRENDER_TESTS) add_subdirectory(tlBaseApp) + endif() + if(TLRENDER_PROGRAMS OR TLRENDER_EXAMPLES) add_subdirectory(tlUIApp) endif() if(TLRENDER_PROGRAMS) From 23f45286fc457785e73de985c88a51f10cad7863 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Wed, 14 Feb 2024 17:11:10 -0800 Subject: [PATCH 4/7] Max digits fixes --- lib/tlCore/Path.cpp | 1 + lib/tlIO/Cache.cpp | 62 +++++++++++++++--------------- lib/tlIO/Cache.h | 26 +++++++------ lib/tlIO/FFmpegRead.cpp | 16 ++++---- lib/tlIO/Plugin.h | 1 - lib/tlIO/SequenceIORead.cpp | 19 ++++----- lib/tlIO/SequenceIOReadPrivate.h | 2 - lib/tlTimeline/ReadCache.cpp | 35 +++++++---------- lib/tlTimeline/Util.cpp | 4 +- lib/tlTimelineUI/AudioClipItem.cpp | 14 +++---- lib/tlTimelineUI/AudioClipItem.h | 2 - lib/tlTimelineUI/VideoClipItem.cpp | 31 +++++---------- lib/tlTimelineUI/VideoClipItem.h | 7 ---- 13 files changed, 93 insertions(+), 127 deletions(-) diff --git a/lib/tlCore/Path.cpp b/lib/tlCore/Path.cpp index 69dc10a82..47b0c438d 100644 --- a/lib/tlCore/Path.cpp +++ b/lib/tlCore/Path.cpp @@ -62,6 +62,7 @@ namespace tl for (; i > 0 && value[i - 1] >= '0' && value[i - 1] <= '9'; --i) ; if (value[i] >= '0' && value[i] <= '9' && + options.maxNumberDigits > 0 && (j - i) <= options.maxNumberDigits) { _number = value.substr(i, j - i); diff --git a/lib/tlIO/Cache.cpp b/lib/tlIO/Cache.cpp index 15247fa04..577bcb3bd 100644 --- a/lib/tlIO/Cache.cpp +++ b/lib/tlIO/Cache.cpp @@ -14,6 +14,38 @@ namespace tl { namespace io { + std::string getCacheKey( + const file::Path& path, + const otime::RationalTime& time, + const Options& options) + { + std::vector s; + s.push_back(path.get()); + s.push_back(path.getNumber()); + s.push_back(string::Format("{0}").arg(time)); + for (const auto& i : options) + { + s.push_back(string::Format("{0}:{1}").arg(i.first).arg(i.second)); + } + return string::join(s, ';'); + } + + std::string getCacheKey( + const file::Path& path, + const otime::TimeRange& timeRange, + const Options& options) + { + std::vector s; + s.push_back(path.get()); + s.push_back(path.getNumber()); + s.push_back(string::Format("{0}").arg(timeRange)); + for (const auto& i : options) + { + s.push_back(string::Format("{0}:{1}").arg(i.first).arg(i.second)); + } + return string::join(s, ';'); + } + struct Cache::Private { size_t max = memory::gigabyte; @@ -71,21 +103,6 @@ namespace tl static_cast(p.video.getMax() + p.audio.getMax()) * 100.F; } - std::string Cache::getVideoKey( - const std::string& fileName, - const otime::RationalTime& time, - const Options& options) - { - std::vector s; - s.push_back(fileName); - s.push_back(string::Format("{0}").arg(time)); - for (const auto& i : options) - { - s.push_back(string::Format("{0}:{1}").arg(i.first).arg(i.second)); - } - return string::join(s, ';'); - } - void Cache::addVideo(const std::string& key, const VideoData& videoData) { TLRENDER_P(); @@ -110,21 +127,6 @@ namespace tl return p.video.get(key, videoData); } - std::string Cache::getAudioKey( - const std::string& fileName, - const otime::TimeRange& timeRange, - const Options& options) - { - std::vector s; - s.push_back(fileName); - s.push_back(string::Format("{0}").arg(timeRange)); - for (const auto& i : options) - { - s.push_back(string::Format("{0}:{1}").arg(i.first).arg(i.second)); - } - return string::join(s, ';'); - } - void Cache::addAudio(const std::string& key, const AudioData& audioData) { TLRENDER_P(); diff --git a/lib/tlIO/Cache.h b/lib/tlIO/Cache.h index e598c13f8..38e6d35d9 100644 --- a/lib/tlIO/Cache.h +++ b/lib/tlIO/Cache.h @@ -6,10 +6,24 @@ #include +#include + namespace tl { namespace io { + //! Get a cache key. + std::string getCacheKey( + const file::Path&, + const otime::RationalTime&, + const Options& = Options()); + + //! Get a cache key. + std::string getCacheKey( + const file::Path&, + const otime::TimeRange&, + const Options& = Options()); + //! I/O cache. class Cache : public std::enable_shared_from_this { @@ -38,12 +52,6 @@ namespace tl //! Get the current cache size as a percentage. float getPercentage() const; - //! Get a video cache key. - static std::string getVideoKey( - const std::string& fileName, - const otime::RationalTime&, - const Options&); - //! Add video to the cache. void addVideo(const std::string& key, const VideoData&); @@ -53,12 +61,6 @@ namespace tl //! Get video from the cache. bool getVideo(const std::string& key, VideoData&) const; - //! Get an audio cache key. - static std::string getAudioKey( - const std::string& fileName, - const otime::TimeRange&, - const Options&); - //! Add audio to the cache. void addAudio(const std::string& key, const AudioData&); diff --git a/lib/tlIO/FFmpegRead.cpp b/lib/tlIO/FFmpegRead.cpp index 66f80854d..7f579a0b2 100644 --- a/lib/tlIO/FFmpegRead.cpp +++ b/lib/tlIO/FFmpegRead.cpp @@ -381,8 +381,8 @@ namespace tl io::VideoData videoData; if (videoRequest && _cache) { - const std::string cacheKey = io::Cache::getVideoKey( - _path.get(), + const std::string cacheKey = io::getCacheKey( + _path, videoRequest->time, videoRequest->options); if (_cache->getVideo(cacheKey, videoData)) @@ -421,8 +421,8 @@ namespace tl if (_cache) { - const std::string cacheKey = io::Cache::getVideoKey( - _path.get(), + const std::string cacheKey = io::getCacheKey( + _path, videoRequest->time, videoRequest->options); _cache->addVideo(cacheKey, data); @@ -500,8 +500,8 @@ namespace tl io::AudioData audioData; if (request && _cache) { - const std::string cacheKey = io::Cache::getAudioKey( - _path.get(), + const std::string cacheKey = io::getCacheKey( + _path, request->timeRange, request->options); if (_cache->getAudio(cacheKey, audioData)) @@ -557,8 +557,8 @@ namespace tl if (_cache) { - const std::string cacheKey = io::Cache::getAudioKey( - _path.get(), + const std::string cacheKey = io::getCacheKey( + _path, request->timeRange, request->options); _cache->addAudio(cacheKey, audioData); diff --git a/lib/tlIO/Plugin.h b/lib/tlIO/Plugin.h index e07212001..01fb8e2de 100644 --- a/lib/tlIO/Plugin.h +++ b/lib/tlIO/Plugin.h @@ -7,7 +7,6 @@ #include #include -#include #include #include diff --git a/lib/tlIO/SequenceIORead.cpp b/lib/tlIO/SequenceIORead.cpp index 42cb9386b..43a0eadf5 100644 --- a/lib/tlIO/SequenceIORead.cpp +++ b/lib/tlIO/SequenceIORead.cpp @@ -130,7 +130,6 @@ namespace tl { TLRENDER_P(); auto request = std::make_shared(); - request->fileName = _path.get(-1, file::PathType::Path); request->time = time; request->options = merge(options, _options); auto future = request->promise.get_future(); @@ -214,33 +213,29 @@ namespace tl videoRequests.pop_front(); VideoData videoData; - const std::string cacheKey = Cache::getVideoKey( - request->fileName, + const std::string cacheKey = getCacheKey( + _path, request->time, request->options); if (_cache && _cache->getVideo(cacheKey, videoData)) { - //std::cout << "cache: " << request->fileName << " " << - // request->time << std::endl; request->promise.set_value(videoData); } else { - //std::cout << "request: " << request->fileName << " " << - // request->time << std::endl; bool seq = false; + std::string fileName; if (!_path.getNumber().empty()) { seq = true; - request->fileName = _path.get( + fileName = _path.get( static_cast(request->time.value()), file::PathType::Path); } else { - request->fileName = _path.get(-1, file::PathType::Path); + fileName = _path.get(-1, file::PathType::Path); } - const std::string fileName = request->fileName; const otime::RationalTime time = request->time; const Options options = request->options; request->future = std::async( @@ -285,8 +280,8 @@ namespace tl if (_cache) { - const std::string cacheKey = Cache::getVideoKey( - (*requestIt)->fileName, + const std::string cacheKey = getCacheKey( + _path, (*requestIt)->time, (*requestIt)->options); _cache->addVideo(cacheKey, videoData); diff --git a/lib/tlIO/SequenceIOReadPrivate.h b/lib/tlIO/SequenceIOReadPrivate.h index d15a9b78d..170f1cd8c 100644 --- a/lib/tlIO/SequenceIOReadPrivate.h +++ b/lib/tlIO/SequenceIOReadPrivate.h @@ -40,8 +40,6 @@ namespace tl otime::RationalTime time = time::invalidTime; Options options; std::promise promise; - - std::string fileName; std::future future; }; diff --git a/lib/tlTimeline/ReadCache.cpp b/lib/tlTimeline/ReadCache.cpp index 21ee5ed64..e919a57bc 100644 --- a/lib/tlTimeline/ReadCache.cpp +++ b/lib/tlTimeline/ReadCache.cpp @@ -5,29 +5,27 @@ #include #include +#include +#include namespace tl { namespace timeline { - struct ReadCache::Private + namespace { - enum class FileNameType - { - Regular, - Sequence - }; - - static FileNameType getFileNameType(const file::Path& path) + std::string getKey(const file::Path& path) { - return path.getNumber().empty() ? - FileNameType::Regular : - FileNameType::Sequence; + std::vector out; + out.push_back(path.get()); + out.push_back(path.getNumber()); + return string::join(out, ';'); } + } - typedef std::pair Key; - - memory::LRUCache cache; + struct ReadCache::Private + { + memory::LRUCache cache; }; void ReadCache::_init() @@ -52,18 +50,13 @@ namespace tl void ReadCache::add(const ReadCacheItem& read) { const file::Path& path = read.read->getPath(); - const Private::Key key( - path.get(), - Private::getFileNameType(path)); + const std::string key = getKey(path); _p->cache.add(key, read); } bool ReadCache::get(const file::Path& path, ReadCacheItem& out) { - const Private::Key key( - path.get(), - Private::getFileNameType(path)); - return _p->cache.get(key, out); + return _p->cache.get(getKey(path), out); } void ReadCache::setMax(size_t value) diff --git a/lib/tlTimeline/Util.cpp b/lib/tlTimeline/Util.cpp index 7eb921937..d8f386b45 100644 --- a/lib/tlTimeline/Util.cpp +++ b/lib/tlTimeline/Util.cpp @@ -304,9 +304,9 @@ namespace tl file::Path getPath( const std::string& url, const std::string& directory, - const file::PathOptions& options) + const file::PathOptions& pathOptions) { - file::Path out(url); + file::Path out(url, pathOptions); if (out.isFileProtocol() && !out.isAbsolute()) { out.setDirectory(file::appendSeparator(directory) + out.getDirectory()); diff --git a/lib/tlTimelineUI/AudioClipItem.cpp b/lib/tlTimelineUI/AudioClipItem.cpp index 6a4989fc5..b98db0d6d 100644 --- a/lib/tlTimelineUI/AudioClipItem.cpp +++ b/lib/tlTimelineUI/AudioClipItem.cpp @@ -149,7 +149,7 @@ namespace tl i->second.future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { const auto mesh = i->second.future.get(); - _data->waveforms[_getWaveformKey(i->second.timeRange)] = mesh; + _data->waveforms[io::getCacheKey(p.path, i->second.timeRange, _data->options.ioOptions)] = mesh; i = p.waveformRequests.erase(i); _updates |= ui::Update::Draw; } @@ -196,12 +196,6 @@ namespace tl } } - std::string AudioClipItem::_getWaveformKey(const otime::TimeRange& timeRange) const - { - TLRENDER_P(); - return string::Format("{0}_{1}").arg(p.path.get()).arg(timeRange); - } - void AudioClipItem::_drawWaveforms( const math::Box2i& drawRect, const ui::DrawEvent& event) @@ -268,7 +262,8 @@ namespace tl _trimmedRange, p.ioInfo->audio.sampleRate); - const auto i = _data->waveforms.find(_getWaveformKey(mediaRange)); + const auto i = _data->waveforms.find( + io::getCacheKey(p.path, mediaRange, _data->options.ioOptions)); if (i != _data->waveforms.end()) { if (i->second) @@ -288,7 +283,8 @@ namespace tl p.path, p.memoryRead, box.getSize(), - mediaRange); + mediaRange, + _data->options.ioOptions); } } } diff --git a/lib/tlTimelineUI/AudioClipItem.h b/lib/tlTimelineUI/AudioClipItem.h index f1056fced..cc57b1c52 100644 --- a/lib/tlTimelineUI/AudioClipItem.h +++ b/lib/tlTimelineUI/AudioClipItem.h @@ -57,8 +57,6 @@ namespace tl void drawEvent(const math::Box2i&, const ui::DrawEvent&) override; private: - std::string _getWaveformKey(const otime::TimeRange&) const; - void _drawWaveforms( const math::Box2i&, const ui::DrawEvent&); diff --git a/lib/tlTimelineUI/VideoClipItem.cpp b/lib/tlTimelineUI/VideoClipItem.cpp index 557249a02..5f5c61858 100644 --- a/lib/tlTimelineUI/VideoClipItem.cpp +++ b/lib/tlTimelineUI/VideoClipItem.cpp @@ -18,7 +18,7 @@ namespace tl { struct VideoClipItem::Private { - io::Options ioOptions; + std::string clipName; file::Path path; std::vector memoryRead; std::shared_ptr thumbnailGenerator; @@ -62,7 +62,7 @@ namespace tl parent); TLRENDER_P(); - p.ioOptions["USD/cameraName"] = clip->name(); + p.clipName = clip->name(); p.path = path; p.memoryRead = timeline::getMemoryRead(clip->media_reference()); p.thumbnailGenerator = thumbnailGenerator; @@ -151,7 +151,9 @@ namespace tl i->second.future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { const auto image = i->second.future.get(); - _data->thumbnails[_getThumbnailKey(i->first, p.ioOptions)] = image; + io::Options ioOptions = _data->options.ioOptions; + ioOptions["USD/cameraName"] = p.clipName; + _data->thumbnails[io::getCacheKey(p.path, i->first, ioOptions)] = image; i = p.thumbnailRequests.erase(i); _updates |= ui::Update::Draw; } @@ -205,22 +207,6 @@ namespace tl } } - std::string VideoClipItem::_getThumbnailKey( - const otime::RationalTime& time, - const io::Options& ioOptions) const - { - TLRENDER_P(); - std::vector s; - s.push_back(p.path.get()); - s.push_back(string::Format("{0}").arg(time)); - for (const auto& i : ioOptions) - { - s.push_back(i.first); - s.push_back(i.second); - } - return string::join(s, '_'); - } - void VideoClipItem::_drawThumbnails( const math::Box2i& drawRect, const ui::DrawEvent& event) @@ -284,7 +270,10 @@ namespace tl _trimmedRange, p.ioInfo->videoTime.duration().rate()); - const auto i = _data->thumbnails.find(_getThumbnailKey(mediaTime, p.ioOptions)); + io::Options ioOptions = _data->options.ioOptions; + ioOptions["USD/cameraName"] = p.clipName; + const auto i = _data->thumbnails.find( + io::getCacheKey(p.path, mediaTime, ioOptions)); if (i != _data->thumbnails.end()) { if (i->second) @@ -302,7 +291,7 @@ namespace tl p.memoryRead, _options.thumbnailHeight, mediaTime, - p.ioOptions); + ioOptions); } } } diff --git a/lib/tlTimelineUI/VideoClipItem.h b/lib/tlTimelineUI/VideoClipItem.h index fb5049d79..39b0e9199 100644 --- a/lib/tlTimelineUI/VideoClipItem.h +++ b/lib/tlTimelineUI/VideoClipItem.h @@ -57,13 +57,6 @@ namespace tl void drawEvent(const math::Box2i&, const ui::DrawEvent&) override; private: - std::string _getThumbnailKey( - const otime::RationalTime&, - const io::Options&) const; - - void _drawInfo( - const math::Box2i&, - const ui::DrawEvent&); void _drawThumbnails( const math::Box2i&, const ui::DrawEvent&); From 4486b6847362ba176c6b1e43eecaba497ecbd8c7 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Thu, 15 Feb 2024 10:40:13 -0800 Subject: [PATCH 5/7] USD fixes --- lib/tlIO/USDRender.cpp | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/tlIO/USDRender.cpp b/lib/tlIO/USDRender.cpp index 191aec683..aa9186d8a 100644 --- a/lib/tlIO/USDRender.cpp +++ b/lib/tlIO/USDRender.cpp @@ -292,10 +292,16 @@ namespace tl const UsdStageRefPtr& stage, const std::string& name = std::string()) { - const TfToken primaryCameraName = UsdUtilsGetPrimaryCameraName(); - UsdGeomCamera out = UsdAppUtilsGetCameraAtPath( - stage, - SdfPath(!name.empty() ? name : primaryCameraName)); + UsdGeomCamera out; + if (!name.empty()) + { + out = UsdAppUtilsGetCameraAtPath(stage, SdfPath(name)); + } + if (!out) + { + const TfToken primaryCameraName = UsdUtilsGetPrimaryCameraName(); + out = UsdAppUtilsGetCameraAtPath(stage, SdfPath(primaryCameraName)); + } if (!out) { for (const auto& prim : stage->Traverse()) @@ -511,7 +517,7 @@ namespace tl } if (infoRequest) { - const std::string fileName = infoRequest->path.get(); + const std::string fileName = infoRequest->path.get(-1, file::PathType::Path); Private::StageCacheItem stageCacheItem; if (!p.thread.stageCache.get(fileName, stageCacheItem)) { @@ -557,8 +563,8 @@ namespace tl io::VideoData videoData; if (request && p.cache) { - const std::string cacheKey = io::Cache::getVideoKey( - request->path.get(), + const std::string cacheKey = io::getCacheKey( + request->path, request->time, ioOptions); if (p.cache->getVideo(cacheKey, videoData)) @@ -571,10 +577,13 @@ namespace tl // Check the disk cache. if (request) { - const std::string fileName = request->path.get(); std::shared_ptr diskCacheItem; + const std::string cacheKey = io::getCacheKey( + request->path, + request->time, + ioOptions); if (diskCacheByteCount > 0 && - p.thread.diskCache.get(io::Cache::getVideoKey(fileName, request->time, ioOptions), diskCacheItem)) + p.thread.diskCache.get(cacheKey, diskCacheItem)) { std::shared_ptr image; try @@ -608,10 +617,6 @@ namespace tl if (p.cache) { - const std::string cacheKey = io::Cache::getVideoKey( - fileName, - request->time, - ioOptions); p.cache->addVideo(cacheKey, videoData); } @@ -622,11 +627,15 @@ namespace tl // Handle requests. if (request) { - const std::string fileName = request->path.get(); std::shared_ptr image; + const std::string cacheKey = io::getCacheKey( + request->path, + request->time, + ioOptions); try { // Check the stage cache for a previously opened stage. + const std::string fileName = request->path.get(-1, file::PathType::Path); Private::StageCacheItem stageCacheItem; if (!p.thread.stageCache.get(fileName, stageCacheItem)) { @@ -811,10 +820,7 @@ namespace tl tempFile->writeU32(static_cast(image->getPixelType())); const size_t byteCount = image->getDataByteCount(); tempFile->write(image->getData(), byteCount); - p.thread.diskCache.add( - io::Cache::getVideoKey(fileName, request->time, ioOptions), - diskCacheItem, - byteCount); + p.thread.diskCache.add(cacheKey, diskCacheItem, byteCount); } } } @@ -836,10 +842,6 @@ namespace tl if (p.cache) { - const std::string cacheKey = io::Cache::getVideoKey( - fileName, - request->time, - ioOptions); p.cache->addVideo(cacheKey, videoData); } } From f53b174e1d03cea6adb0e0703292e3061b42f25c Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Mon, 19 Feb 2024 13:08:57 -0800 Subject: [PATCH 6/7] Blending fixes --- lib/tlTimelineGL/RenderPrims.cpp | 6 +++--- lib/tlTimelineGL/RenderVideo.cpp | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/tlTimelineGL/RenderPrims.cpp b/lib/tlTimelineGL/RenderPrims.cpp index b05e6cea2..7dc3ca042 100644 --- a/lib/tlTimelineGL/RenderPrims.cpp +++ b/lib/tlTimelineGL/RenderPrims.cpp @@ -343,13 +343,13 @@ namespace tl switch (imageOptions.alphaBlend) { case timeline::AlphaBlend::None: - glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE); + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); break; case timeline::AlphaBlend::Straight: - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; case timeline::AlphaBlend::Premultiplied: - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; default: break; } diff --git a/lib/tlTimelineGL/RenderVideo.cpp b/lib/tlTimelineGL/RenderVideo.cpp index dc80c03e0..be873b12f 100644 --- a/lib/tlTimelineGL/RenderVideo.cpp +++ b/lib/tlTimelineGL/RenderVideo.cpp @@ -692,7 +692,18 @@ namespace tl if (p.buffers["video"]) { - glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + switch (imageOptions ? imageOptions->alphaBlend : timeline::AlphaBlend::Straight) + { + case timeline::AlphaBlend::None: + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); + break; + case timeline::AlphaBlend::Straight: + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + break; + case timeline::AlphaBlend::Premultiplied: + glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + break; + } glViewport( viewportPrev[0], From e1d8d6789f48bb4149c1917b7abc16af6d792769 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Mon, 19 Feb 2024 13:10:11 -0800 Subject: [PATCH 7/7] Set checkers background --- examples/player/player.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/player/player.cpp b/examples/player/player.cpp index 8081a65e9..2206931d2 100644 --- a/examples/player/player.cpp +++ b/examples/player/player.cpp @@ -43,6 +43,9 @@ namespace tl addWindow(_window); auto viewport = timelineui::TimelineViewport::create(context, _window); + timeline::BackgroundOptions backgroundOptions; + backgroundOptions.type = timeline::Background::Checkers; + viewport->setBackgroundOptions(backgroundOptions); viewport->setPlayers({ _player }); _window->show();