taglib: Implement new StreamTypeResolver interface when available
authorHugo Beauzée-Luyssen <hugo@beauzee.fr>
Wed, 9 Feb 2022 13:14:08 +0000 (14:14 +0100)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 14 Jan 2025 22:09:47 +0000 (23:09 +0100)
refs #26602

(cherry picked from commit 268b5b8bc1f1109c4fc69b22e53095c6d81faa76) (rebased)

Gbp-Pq: Name 0049-taglib-Implement-new-StreamTypeResolver-interface-wh.patch

modules/meta_engine/taglib.cpp

index a52adfe4497700fc629f9f109be2cca6b5559009..e3e80cc6abef3ced11a81219f8e1d78555623565 100644 (file)
@@ -101,15 +101,27 @@ using namespace TagLib;
 #include <algorithm>
 #include <limits>
 
+#if defined(VLC_PATCHED_TAGLIB_IOSTREAM_RESOLVERS) || \
+    TAGLIB_VERSION >= VERSION_INT(1, 12, 0)
+#define USE_IOSTREAM_RESOLVER 1
+#endif
+
 namespace VLCTagLib
 {
     template <class T>
+#ifdef USE_IOSTREAM_RESOLVER
+    class ExtResolver : public FileRef::StreamTypeResolver
+#else
     class ExtResolver : public FileRef::FileTypeResolver
+#endif
     {
         public:
             ExtResolver(const std::string &);
             ~ExtResolver() {}
             virtual File *createFile(FileName, bool, AudioProperties::ReadStyle) const;
+#ifdef USE_IOSTREAM_RESOLVER
+            virtual File *createFileFromStream(IOStream*, bool, AudioProperties::ReadStyle) const;
+#endif
 
         protected:
             std::string ext;
@@ -140,6 +152,25 @@ File *VLCTagLib::ExtResolver<T>::createFile(FileName fileName, bool, AudioProper
     return 0;
 }
 
+#ifdef USE_IOSTREAM_RESOLVER
+template<class T>
+File* VLCTagLib::ExtResolver<T>::createFileFromStream(IOStream* s, bool, AudioProperties::ReadStyle) const
+{
+    std::string filename = std::string(s->name());
+    std::size_t namesize = filename.size();
+
+    if (namesize > ext.length())
+    {
+        std::string fext = filename.substr(namesize - ext.length(), ext.length());
+        std::transform(fext.begin(), fext.end(), fext.begin(), ::toupper);
+        if(fext == ext)
+            return new T(s, ID3v2::FrameFactory::instance(), false, AudioProperties::Fast);
+    }
+
+    return nullptr;
+}
+#endif
+
 #if TAGLIB_VERSION >= TAGLIB_VERSION_1_11
 static VLCTagLib::ExtResolver<MPEG::File> aacresolver(".aac");
 #endif