[Android] libvlc: Backport taglib patch to fix AAC metadata extraction

Hugo Beauzée-Luyssen git at videolan.org
Mon Feb 28 14:53:12 UTC 2022


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Feb 28 09:19:03 2022 +0100| [0de8334b797d9baf54662c1624076d9bf52f35b3] | committer: Nicolas Pomepuy

libvlc: Backport taglib patch to fix AAC metadata extraction

> https://code.videolan.org/videolan/vlc-android/commit/0de8334b797d9baf54662c1624076d9bf52f35b3
---

 ...contrib-taglib-Update-patch-from-upstream.patch | 252 +++++++++++++++++++++
 1 file changed, 252 insertions(+)

diff --git a/libvlc/patches/vlc3/0014-contrib-taglib-Update-patch-from-upstream.patch b/libvlc/patches/vlc3/0014-contrib-taglib-Update-patch-from-upstream.patch
new file mode 100644
index 000000000..fc3c4da85
--- /dev/null
+++ b/libvlc/patches/vlc3/0014-contrib-taglib-Update-patch-from-upstream.patch
@@ -0,0 +1,252 @@
+From 5923b1d788f6d343c73bd90e29b2191d6980af44 Mon Sep 17 00:00:00 2001
+Message-Id: <5923b1d788f6d343c73bd90e29b2191d6980af44.1646036660.git.hugo at beauzee.fr>
+From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo at beauzee.fr>
+Date: Wed, 16 Feb 2022 09:52:38 +0100
+Subject: [PATCH] taglib: Fix extraction of AAC metadata
+
+---
+ ...-Fix-IOStream-usage-with-custom-reso.patch | 130 ++++++++++++++++++
+ contrib/src/taglib/rules.mak                  |   1 +
+ modules/meta_engine/taglib.cpp                |  38 ++++-
+ 3 files changed, 165 insertions(+), 4 deletions(-)
+ create mode 100644 contrib/src/taglib/0001-FileTypeResolver-Fix-IOStream-usage-with-custom-reso.patch
+
+diff --git a/contrib/src/taglib/0001-FileTypeResolver-Fix-IOStream-usage-with-custom-reso.patch b/contrib/src/taglib/0001-FileTypeResolver-Fix-IOStream-usage-with-custom-reso.patch
+new file mode 100644
+index 0000000000..ba797aadba
+--- /dev/null
++++ b/contrib/src/taglib/0001-FileTypeResolver-Fix-IOStream-usage-with-custom-reso.patch
+@@ -0,0 +1,130 @@
++From 62fdfd554aaa68fe765afd873e225d583cd31c29 Mon Sep 17 00:00:00 2001
++From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo at beauzee.fr>
++Date: Wed, 9 Feb 2022 13:51:42 +0100
++Subject: [PATCH] FileTypeResolver: Add a StreamTypeResolver interface
++
++---
++ taglib/fileref.cpp      | 22 ++++++++++++++++++++++
++ taglib/fileref.h        | 10 ++++++++++
++ taglib/toolkit/taglib.h |  2 ++
++ tests/test_fileref.cpp  | 23 +++++++++++++++++++++++
++ 4 files changed, 57 insertions(+)
++
++diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp
++index f91209a0..b71d6571 100644
++--- a/taglib/fileref.cpp
+++++ b/taglib/fileref.cpp
++@@ -84,6 +84,22 @@ namespace
++     return 0;
++   }
++ 
+++  File *detectByResolvers(IOStream* stream, bool readAudioProperties,
+++                          AudioProperties::ReadStyle audioPropertiesStyle)
+++  {
+++    for(ResolverList::ConstIterator it = fileTypeResolvers.begin();
+++        it != fileTypeResolvers.end(); ++it) {
+++      if(const FileRef::StreamTypeResolver *streamResolver =
+++           dynamic_cast<const FileRef::StreamTypeResolver*>(*it)) {
+++        if(File *file = streamResolver->createFileFromStream(
+++             stream, readAudioProperties, audioPropertiesStyle))
+++          return file;
+++      }
+++    }
+++
+++    return 0;
+++  }
+++
++   // Detect the file type based on the file extension.
++ 
++   File* detectByExtension(IOStream *stream, bool readAudioProperties,
++@@ -480,6 +496,12 @@ void FileRef::parse(FileName fileName, bool readAudioProperties,
++ void FileRef::parse(IOStream *stream, bool readAudioProperties,
++                     AudioProperties::ReadStyle audioPropertiesStyle)
++ {
+++  // Try user-defined stream resolvers.
+++
+++  d->file = detectByResolvers(stream, readAudioProperties, audioPropertiesStyle);
+++  if(d->file)
+++    return;
+++
++   // Try user-defined resolvers.
++ 
++   d->file = detectByResolvers(stream->name(), readAudioProperties, audioPropertiesStyle);
++diff --git a/taglib/fileref.h b/taglib/fileref.h
++index 76e694e4..75d14926 100644
++--- a/taglib/fileref.h
+++++ b/taglib/fileref.h
++@@ -108,6 +108,16 @@ namespace TagLib {
++                                audioPropertiesStyle = AudioProperties::Average) const = 0;
++     };
++ 
+++    class TAGLIB_EXPORT StreamTypeResolver : public FileTypeResolver
+++    {
+++      TAGLIB_IGNORE_MISSING_DESTRUCTOR
+++    public:
+++      virtual File *createFileFromStream(IOStream *stream,
+++                               bool readAudioProperties = true,
+++                               AudioProperties::ReadStyle
+++                               audioPropertiesStyle = AudioProperties::Average) const = 0;
+++    };
+++
++     /*!
++      * Creates a null FileRef.
++      */
++diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h
++index ffce61f7..2bb56994 100644
++--- a/taglib/toolkit/taglib.h
+++++ b/taglib/toolkit/taglib.h
++@@ -54,6 +54,8 @@
++ #define TAGLIB_DEPRECATED
++ #endif
++ 
+++#define VLC_PATCHED_TAGLIB_IOSTREAM_RESOLVERS
+++
++ #include <string>
++ 
++ //! A namespace for all TagLib related classes and functions
++diff --git a/tests/test_fileref.cpp b/tests/test_fileref.cpp
++index 1fc5def9..b2631827 100644
++--- a/tests/test_fileref.cpp
+++++ b/tests/test_fileref.cpp
++@@ -60,6 +60,20 @@ namespace
++       return new Ogg::Vorbis::File(fileName);
++     }
++   };
+++
+++  class DummyStreamResolver : public FileRef::StreamTypeResolver
+++  {
+++  public:
+++    virtual File *createFile(FileName, bool, AudioProperties::ReadStyle) const
+++    {
+++      return 0;
+++    }
+++
+++    virtual File *createFileFromStream(IOStream *s, bool, AudioProperties::ReadStyle) const
+++    {
+++      return new MP4::File(s);
+++    }
+++  };
++ }
++ 
++ class TestFileRef : public CppUnit::TestFixture
++@@ -387,6 +401,15 @@ public:
++       FileRef f(TEST_FILE_PATH_C("xing.mp3"));
++       CPPUNIT_ASSERT(dynamic_cast<Ogg::Vorbis::File *>(f.file()) != NULL);
++     }
+++
+++    DummyStreamResolver streamResolver;
+++    FileRef::addFileTypeResolver(&streamResolver);
+++
+++    {
+++      FileStream s(TEST_FILE_PATH_C("xing.mp3"));
+++      FileRef f(&s);
+++      CPPUNIT_ASSERT(dynamic_cast<MP4::File *>(f.file()) != NULL);
+++    }
++   }
++ 
++ };
++-- 
++2.34.1
++
+diff --git a/contrib/src/taglib/rules.mak b/contrib/src/taglib/rules.mak
+index 1e4cdf5657..9f818406e2 100644
+--- a/contrib/src/taglib/rules.mak
++++ b/contrib/src/taglib/rules.mak
+@@ -16,6 +16,7 @@ $(TARBALLS)/taglib-$(TAGLIB_VERSION).tar.gz:
+ taglib: taglib-$(TAGLIB_VERSION).tar.gz .sum-taglib
+ 	$(UNPACK)
+ 	$(APPLY) $(SRC)/taglib/0001-Implement-ID3v2-readStyle-avoid-worst-case.patch
++	$(APPLY) $(SRC)/taglib/0001-FileTypeResolver-Fix-IOStream-usage-with-custom-reso.patch
+ 	$(MOVE)
+ 
+ .taglib: taglib toolchain.cmake
+diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp
+index 04a44c30e8..f4a774d367 100644
+--- a/modules/meta_engine/taglib.cpp
++++ b/modules/meta_engine/taglib.cpp
+@@ -94,15 +94,27 @@ using namespace TagLib;
+ #include <algorithm>
+ #include <limits>
+ 
++#if defined(VLC_PATCHED_TAGLIB_IOSTREAM_RESOLVERS) || \
++    TAGLIB_VERSION >= VERSION_INT(1, 13, 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;
+@@ -110,7 +122,7 @@ namespace VLCTagLib
+ }
+ 
+ template <class T>
+-VLCTagLib::ExtResolver<T>::ExtResolver(const std::string & ext) : FileTypeResolver()
++VLCTagLib::ExtResolver<T>::ExtResolver(const std::string & ext)
+ {
+     this->ext = ext;
+     std::transform(this->ext.begin(), this->ext.end(), this->ext.begin(), ::toupper);
+@@ -130,9 +142,28 @@ File *VLCTagLib::ExtResolver<T>::createFile(FileName fileName, bool, AudioProper
+             return new T(fileName, false, AudioProperties::Fast);
+     }
+ 
+-    return 0;
++    return nullptr;
+ }
+ 
++#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
++
+ static VLCTagLib::ExtResolver<MPEG::File> aacresolver(".aac");
+ static bool b_extensions_registered = false;
+ 
+@@ -879,7 +910,6 @@ static int ReadMeta( vlc_object_t* p_this)
+     vlc_mutex_locker locker (&taglib_lock);
+     demux_meta_t*   p_demux_meta = (demux_meta_t *)p_this;
+     vlc_meta_t*     p_meta;
+-    FileRef f;
+ 
+     p_demux_meta->p_meta = NULL;
+ 
+@@ -915,7 +945,7 @@ static int ReadMeta( vlc_object_t* p_this)
+     else
+         s.setMaxSequentialRead( 1024 * 2048 );
+ #endif
+-    f = FileRef( &s, false, AudioProperties::ReadStyle::Fast );
++    FileRef f( &s, false, AudioProperties::ReadStyle::Fast );
+ 
+     if( f.isNull() )
+         return VLC_EGENERIC;
+-- 
+2.34.1
+



More information about the Android mailing list