Commit c05bca6f authored by Max Kellermann's avatar Max Kellermann

tag/Handler: implement FullTagHandler::OnAudioFormat()

parent 73c95d1f
...@@ -100,9 +100,10 @@ ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler) noexcept ...@@ -100,9 +100,10 @@ ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler) noexcept
} }
bool bool
ScanFileTagsWithGeneric(Path path, TagBuilder &builder) noexcept ScanFileTagsWithGeneric(Path path, TagBuilder &builder,
AudioFormat *audio_format) noexcept
{ {
FullTagHandler h(builder); FullTagHandler h(builder, audio_format);
if (!ScanFileTagsNoGeneric(path, h)) if (!ScanFileTagsNoGeneric(path, h))
return false; return false;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "check.h" #include "check.h"
struct AudioFormat;
class Path; class Path;
class TagHandler; class TagHandler;
class TagBuilder; class TagBuilder;
...@@ -46,6 +47,7 @@ ScanFileTagsNoGeneric(Path path, TagHandler &handler) noexcept; ...@@ -46,6 +47,7 @@ ScanFileTagsNoGeneric(Path path, TagHandler &handler) noexcept;
* found) * found)
*/ */
bool bool
ScanFileTagsWithGeneric(Path path, TagBuilder &builder) noexcept; ScanFileTagsWithGeneric(Path path, TagBuilder &builder,
AudioFormat *audio_format=nullptr) noexcept;
#endif #endif
...@@ -85,11 +85,12 @@ try { ...@@ -85,11 +85,12 @@ try {
} }
bool bool
tag_stream_scan(InputStream &is, TagBuilder &builder) noexcept tag_stream_scan(InputStream &is, TagBuilder &builder,
AudioFormat *audio_format) noexcept
{ {
assert(is.IsReady()); assert(is.IsReady());
FullTagHandler h(builder); FullTagHandler h(builder, audio_format);
if (!tag_stream_scan(is, h)) if (!tag_stream_scan(is, h))
return false; return false;
...@@ -101,12 +102,13 @@ tag_stream_scan(InputStream &is, TagBuilder &builder) noexcept ...@@ -101,12 +102,13 @@ tag_stream_scan(InputStream &is, TagBuilder &builder) noexcept
} }
bool bool
tag_stream_scan(const char *uri, TagBuilder &builder) noexcept tag_stream_scan(const char *uri, TagBuilder &builder,
AudioFormat *audio_format) noexcept
try { try {
Mutex mutex; Mutex mutex;
auto is = InputStream::OpenReady(uri, mutex); auto is = InputStream::OpenReady(uri, mutex);
return tag_stream_scan(*is, builder); return tag_stream_scan(*is, builder, audio_format);
} catch (const std::exception &e) { } catch (const std::exception &e) {
return false; return false;
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "check.h" #include "check.h"
struct AudioFormat;
class InputStream; class InputStream;
class TagHandler; class TagHandler;
class TagBuilder; class TagBuilder;
...@@ -48,9 +49,11 @@ tag_stream_scan(const char *uri, TagHandler &handler) noexcept; ...@@ -48,9 +49,11 @@ tag_stream_scan(const char *uri, TagHandler &handler) noexcept;
* found) * found)
*/ */
bool bool
tag_stream_scan(InputStream &is, TagBuilder &builder) noexcept; tag_stream_scan(InputStream &is, TagBuilder &builder,
AudioFormat *audio_format=nullptr) noexcept;
bool bool
tag_stream_scan(const char *uri, TagBuilder &builder) noexcept; tag_stream_scan(const char *uri, TagBuilder &builder,
AudioFormat *audio_format=nullptr) noexcept;
#endif #endif
...@@ -57,3 +57,9 @@ FullTagHandler::OnPair(const char *name, gcc_unused const char *value) noexcept ...@@ -57,3 +57,9 @@ FullTagHandler::OnPair(const char *name, gcc_unused const char *value) noexcept
tag.SetHasPlaylist(true); tag.SetHasPlaylist(true);
} }
void
FullTagHandler::OnAudioFormat(AudioFormat af) noexcept
{
if (audio_format != nullptr)
*audio_format = af;
}
...@@ -140,15 +140,23 @@ public: ...@@ -140,15 +140,23 @@ public:
* attribute. * attribute.
*/ */
class FullTagHandler : public AddTagHandler { class FullTagHandler : public AddTagHandler {
AudioFormat *const audio_format;
protected: protected:
FullTagHandler(unsigned _want_mask, TagBuilder &_builder) noexcept FullTagHandler(unsigned _want_mask, TagBuilder &_builder,
:AddTagHandler(WANT_PAIR|_want_mask, _builder) {} AudioFormat *_audio_format) noexcept
:AddTagHandler(WANT_PAIR|_want_mask
|(_audio_format ? WANT_AUDIO_FORMAT : 0),
_builder),
audio_format(_audio_format) {}
public: public:
explicit FullTagHandler(TagBuilder &_builder) noexcept explicit FullTagHandler(TagBuilder &_builder,
:FullTagHandler(0, _builder) {} AudioFormat *_audio_format=nullptr) noexcept
:FullTagHandler(0, _builder, _audio_format) {}
void OnPair(const char *key, const char *value) noexcept override; void OnPair(const char *key, const char *value) noexcept override;
void OnAudioFormat(AudioFormat af) noexcept override;
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment