diff options
author | Ryan Rector <rmrector@gmail.com> | 2023-08-19 15:19:05 -0600 |
---|---|---|
committer | Ryan Rector <rmrector@gmail.com> | 2023-09-13 16:58:58 -0600 |
commit | 1bebf11c701e5fb39002f8daf364c9a454b6735d (patch) | |
tree | 2082574ec0457bd3d4c605808673fe7d20e3db38 | |
parent | 7df905b77bb4a8aeb7f31b42368ac418e849660f (diff) |
add thumb loader for chapters
-rw-r--r-- | xbmc/TextureCacheJob.cpp | 6 | ||||
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDFileInfo.cpp | 8 | ||||
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDFileInfo.h | 3 | ||||
-rw-r--r-- | xbmc/imagefiles/SpecialImageLoaderFactory.cpp | 2 | ||||
-rw-r--r-- | xbmc/imagefiles/SpecialImageLoaderFactory.h | 2 | ||||
-rw-r--r-- | xbmc/video/CMakeLists.txt | 6 | ||||
-rw-r--r-- | xbmc/video/VideoChapterImageFileLoader.cpp | 54 | ||||
-rw-r--r-- | xbmc/video/VideoChapterImageFileLoader.h | 31 |
8 files changed, 106 insertions, 6 deletions
diff --git a/xbmc/TextureCacheJob.cpp b/xbmc/TextureCacheJob.cpp index 0139993f3a..66edb39202 100644 --- a/xbmc/TextureCacheJob.cpp +++ b/xbmc/TextureCacheJob.cpp @@ -212,6 +212,12 @@ std::string CTextureCacheJob::DecodeImageURL(const std::string &url, unsigned in scalingAlgorithm = CPictureScalingAlgorithm::FromString(thumbURL.GetOption("scaling_algorithm")); } + if (StringUtils::StartsWith(url, "chapter://")) + { + // workaround for chapter thumbnail paths, which don't yet conform to the image:// path. + additional_info = "videochapter"; + } + // Handle special case about audiodecoder addon music files, e.g. SACD if (StringUtils::EndsWith(URIUtils::GetExtension(image), KODI_ADDON_AUDIODECODER_TRACK_EXT)) { diff --git a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp index 73e5729e72..cdd5736970 100644 --- a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp +++ b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp @@ -270,7 +270,8 @@ bool CDVDFileInfo::ExtractThumb(const CFileItem& fileItem, CTextureDetails& deta return bOk; } -std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& fileItem) +std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& fileItem, + int chapterNumber) { if (!CanExtract(fileItem)) return {}; @@ -349,7 +350,10 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f if (pVideoCodec) { int nTotalLen = pDemuxer->GetStreamLength(); - int64_t nSeekTo = nTotalLen / 3; + + bool seekToChapter = chapterNumber > 0 && pDemuxer->GetChapterCount() > 0; + int64_t nSeekTo = + seekToChapter ? pDemuxer->GetChapterPos(chapterNumber) * 1000 : nTotalLen / 3; CLog::LogF(LOGDEBUG, "seeking to pos {}ms (total: {}ms) in {}", nSeekTo, nTotalLen, redactPath); diff --git a/xbmc/cores/VideoPlayer/DVDFileInfo.h b/xbmc/cores/VideoPlayer/DVDFileInfo.h index bbb9776326..0c306e50e8 100644 --- a/xbmc/cores/VideoPlayer/DVDFileInfo.h +++ b/xbmc/cores/VideoPlayer/DVDFileInfo.h @@ -26,7 +26,8 @@ public: // Extract a thumbnail image from the media referenced by fileItem static bool ExtractThumb(const CFileItem& fileItem, CTextureDetails& details, int64_t pos); - static std::unique_ptr<CTexture> ExtractThumbToTexture(const CFileItem& fileItem); + static std::unique_ptr<CTexture> ExtractThumbToTexture(const CFileItem& fileItem, + int chapterNumber = 0); /*! * @brief Can a thumbnail image and file stream details be extracted from this file item? diff --git a/xbmc/imagefiles/SpecialImageLoaderFactory.cpp b/xbmc/imagefiles/SpecialImageLoaderFactory.cpp index 0fae961884..c143ad1ef4 100644 --- a/xbmc/imagefiles/SpecialImageLoaderFactory.cpp +++ b/xbmc/imagefiles/SpecialImageLoaderFactory.cpp @@ -11,6 +11,7 @@ #include "guilib/Texture.h" #include "music/MusicEmbeddedImageFileLoader.h" #include "pictures/PictureFolderImageFileLoader.h" +#include "video/VideoChapterImageFileLoader.h" #include "video/VideoEmbeddedImageFileLoader.h" #include "video/VideoGeneratedImageFileLoader.h" @@ -22,6 +23,7 @@ CSpecialImageLoaderFactory::CSpecialImageLoaderFactory() m_specialImageLoaders[1] = std::make_unique<MUSIC_INFO::CMusicEmbeddedImageFileLoader>(); m_specialImageLoaders[2] = std::make_unique<VIDEO::CVideoGeneratedImageFileLoader>(); m_specialImageLoaders[3] = std::make_unique<CPictureFolderImageFileLoader>(); + m_specialImageLoaders[4] = std::make_unique<VIDEO::CVideoChapterImageFileLoader>(); } std::unique_ptr<CTexture> CSpecialImageLoaderFactory::Load(const std::string& specialType, diff --git a/xbmc/imagefiles/SpecialImageLoaderFactory.h b/xbmc/imagefiles/SpecialImageLoaderFactory.h index d633c617f1..e5bb7b6259 100644 --- a/xbmc/imagefiles/SpecialImageLoaderFactory.h +++ b/xbmc/imagefiles/SpecialImageLoaderFactory.h @@ -29,6 +29,6 @@ public: unsigned int preferredHeight) const; private: - std::array<std::unique_ptr<ISpecialImageFileLoader>, 4> m_specialImageLoaders{}; + std::array<std::unique_ptr<ISpecialImageFileLoader>, 5> m_specialImageLoaders{}; }; } // namespace IMAGE_FILES diff --git a/xbmc/video/CMakeLists.txt b/xbmc/video/CMakeLists.txt index b5068599b7..06e559c938 100644 --- a/xbmc/video/CMakeLists.txt +++ b/xbmc/video/CMakeLists.txt @@ -3,7 +3,7 @@ set(SOURCES Bookmark.cpp GUIViewStateVideo.cpp PlayerController.cpp Teletext.cpp - VideoItemArtworkHandler.cpp + VideoChapterImageFileLoader.cpp VideoDatabase.cpp VideoDbUrl.cpp VideoEmbeddedImageFileLoader.cpp @@ -11,6 +11,7 @@ set(SOURCES Bookmark.cpp VideoInfoDownloader.cpp VideoInfoScanner.cpp VideoInfoTag.cpp + VideoItemArtworkHandler.cpp VideoLibraryQueue.cpp VideoThumbLoader.cpp VideoUtils.cpp @@ -23,7 +24,7 @@ set(HEADERS Bookmark.h PlayerController.h Teletext.h TeletextDefines.h - VideoItemArtworkHandler.h + VideoChapterImageFileLoader.h VideoDatabase.h VideoDbUrl.h VideoEmbeddedImageFileLoader.h @@ -31,6 +32,7 @@ set(HEADERS Bookmark.h VideoInfoDownloader.h VideoInfoScanner.h VideoInfoTag.h + VideoItemArtworkHandler.h VideoLibraryQueue.h VideoThumbLoader.h VideoUtils.h diff --git a/xbmc/video/VideoChapterImageFileLoader.cpp b/xbmc/video/VideoChapterImageFileLoader.cpp new file mode 100644 index 0000000000..5cb0704ff4 --- /dev/null +++ b/xbmc/video/VideoChapterImageFileLoader.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2023 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "VideoChapterImageFileLoader.h" + +#include "DVDFileInfo.h" +#include "FileItem.h" +#include "ServiceBroker.h" +#include "guilib/Texture.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" +#include "utils/log.h" + +bool VIDEO::CVideoChapterImageFileLoader::CanLoad(const std::string& specialType) const +{ + return specialType == "videochapter"; +} + +std::unique_ptr<CTexture> VIDEO::CVideoChapterImageFileLoader::Load( + const std::string& specialType, + const std::string& goofyChapterPath, + unsigned int, + unsigned int) const +{ + // "goofy" chapter path because these paths don't yet conform to 'image://' path standard + + // 10 = length of "chapter://" string prefix from GUIDialogVideoBookmarks + size_t lastSlashPos = goofyChapterPath.rfind("/"); + std::string cleanname = goofyChapterPath.substr(10, lastSlashPos - 10); + + int chapterNum = 0; + try + { + chapterNum = std::stoi(goofyChapterPath.substr(lastSlashPos + 1)); + } + catch (...) + { + // invalid_argument because these paths can come from anywhere + // out_of_range mostly for the same reason - 32k+ seems high for a chapter count + return {}; + } + if (chapterNum < 1) + { + return {}; + } + + CFileItem item{cleanname, false}; + return CDVDFileInfo::ExtractThumbToTexture(item, chapterNum); +} diff --git a/xbmc/video/VideoChapterImageFileLoader.h b/xbmc/video/VideoChapterImageFileLoader.h new file mode 100644 index 0000000000..9cd2eab496 --- /dev/null +++ b/xbmc/video/VideoChapterImageFileLoader.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2023 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "imagefiles/SpecialImageFileLoader.h" + +namespace VIDEO +{ +/*! + * @brief Generates a texture for a thumbnail of a video chapter. +*/ +class CVideoChapterImageFileLoader : public IMAGE_FILES::ISpecialImageFileLoader +{ +public: + CVideoChapterImageFileLoader() = default; + ~CVideoChapterImageFileLoader() override = default; + + bool CanLoad(const std::string& specialType) const override; + std::unique_ptr<CTexture> Load(const std::string& specialType, + const std::string& goofyChapterPath, + unsigned int preferredWidth, + unsigned int preferredHeight) const override; +}; + +} // namespace VIDEO |