Skip to content

Commit

Permalink
contrib: taglib: Fix custom resolvers with IOStream
Browse files Browse the repository at this point in the history
upstreamed at: taglib/taglib#1040
Fix #26602
  • Loading branch information
chouquette committed Feb 17, 2022
1 parent 93842f6 commit 2f82d6b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
@@ -0,0 +1,101 @@
From cb9b013217b2e77066141656029cf92cf854054d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Wed, 9 Feb 2022 13:51:42 +0100
Subject: [PATCH] FileTypeResolver: Add a StreamTypeResolver interface

---
taglib/fileref.cpp | 19 ++++++++++++++++++-
taglib/fileref.h | 10 ++++++++++
taglib/toolkit/taglib.h | 2 ++
tests/test_fileref.cpp | 4 ++++
4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp
index f91209a0..88e53ed1 100644
--- a/taglib/fileref.cpp
+++ b/taglib/fileref.cpp
@@ -84,6 +84,23 @@ namespace
return 0;
}

+ File *detectByResolvers(IOStream* stream, bool readAudioProperties,
+ AudioProperties::ReadStyle audioPropertiesStyle)
+ {
+ ResolverList::ConstIterator it = fileTypeResolvers.begin();
+ for(; it != fileTypeResolvers.end(); ++it) {
+ const FileRef::StreamTypeResolver* streamResolver =
+ dynamic_cast<const FileRef::StreamTypeResolver*>(*it);
+ if (!streamResolver)
+ continue;
+ File *file = streamResolver->createFileFromStream(stream, readAudioProperties, audioPropertiesStyle);
+ if(file)
+ return file;
+ }
+
+ return 0;
+ }
+
// Detect the file type based on the file extension.

File* detectByExtension(IOStream *stream, bool readAudioProperties,
@@ -482,7 +499,7 @@ void FileRef::parse(IOStream *stream, bool readAudioProperties,
{
// Try user-defined resolvers.

- d->file = detectByResolvers(stream->name(), readAudioProperties, audioPropertiesStyle);
+ d->file = detectByResolvers(stream, readAudioProperties, audioPropertiesStyle);
if(d->file)
return;

diff --git a/taglib/fileref.h b/taglib/fileref.h
index 76e694e4..37f44a0e 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..c8136129 100644
--- a/tests/test_fileref.cpp
+++ b/tests/test_fileref.cpp
@@ -59,6 +59,10 @@ namespace
{
return new Ogg::Vorbis::File(fileName);
}
+ virtual File *createFile(IOStream* s, bool, AudioProperties::ReadStyle) const
+ {
+ return new Ogg::Vorbis::File(s);
+ }
};
}

--
2.34.1

1 change: 1 addition & 0 deletions contrib/src/taglib/rules.mak
Expand Up @@ -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
Expand Down

0 comments on commit 2f82d6b

Please sign in to comment.