decoder/{opus,vorbis}: support embedded pictures (METADATA_BLOCK_PICTURE)
More for https://github.com/MusicPlayerDaemon/MPD/issues/42
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "VorbisComments.hxx"
|
||||
#include "VorbisPicture.hxx"
|
||||
#include "XiphTags.hxx"
|
||||
#include "tag/Table.hxx"
|
||||
#include "tag/Handler.hxx"
|
||||
@@ -84,6 +85,12 @@ vorbis_copy_comment(StringView comment,
|
||||
static void
|
||||
vorbis_scan_comment(StringView comment, TagHandler &handler) noexcept
|
||||
{
|
||||
const auto picture_b64 = handler.WantPicture()
|
||||
? GetVorbisCommentValue(comment, "METADATA_BLOCK_PICTURE")
|
||||
: nullptr;
|
||||
if (!picture_b64.IsNull())
|
||||
return ScanVorbisPicture(picture_b64, handler);
|
||||
|
||||
if (handler.WantPair()) {
|
||||
const auto split = comment.Split('=');
|
||||
if (!split.first.empty() && !split.second.IsNull())
|
||||
|
56
src/lib/xiph/VorbisPicture.cxx
Normal file
56
src/lib/xiph/VorbisPicture.cxx
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "VorbisPicture.hxx"
|
||||
#include "lib/crypto/Base64.hxx"
|
||||
#include "tag/Id3Picture.hxx"
|
||||
#include "tag/Handler.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
void
|
||||
ScanVorbisPicture(StringView value, TagHandler &handler) noexcept
|
||||
{
|
||||
#ifdef HAVE_BASE64
|
||||
if (value.size > 1024 * 1024)
|
||||
/* ignore image files which are too huge */
|
||||
return;
|
||||
|
||||
size_t debase64_size = CalculateBase64OutputSize(value.size);
|
||||
std::unique_ptr<uint8_t[]> debase64_buffer;
|
||||
debase64_buffer.reset(new uint8_t[debase64_size]);
|
||||
|
||||
try {
|
||||
debase64_size =
|
||||
DecodeBase64({debase64_buffer.get(), debase64_size},
|
||||
value);
|
||||
} catch (...) {
|
||||
// TODO: log?
|
||||
return;
|
||||
}
|
||||
|
||||
return ScanId3Apic({debase64_buffer.get(), debase64_size}, handler);
|
||||
#else
|
||||
(void)value;
|
||||
(void)handler;
|
||||
#endif
|
||||
}
|
29
src/lib/xiph/VorbisPicture.hxx
Normal file
29
src/lib/xiph/VorbisPicture.hxx
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_VORBIS_PICTURE_HXX
|
||||
#define MPD_VORBIS_PICTURE_HXX
|
||||
|
||||
struct StringView;
|
||||
class TagHandler;
|
||||
|
||||
void
|
||||
ScanVorbisPicture(StringView value, TagHandler &handler) noexcept;
|
||||
|
||||
#endif
|
@@ -47,6 +47,7 @@ endif
|
||||
xiph = static_library(
|
||||
'xiph',
|
||||
'VorbisComments.cxx',
|
||||
'VorbisPicture.cxx',
|
||||
'XiphTags.cxx',
|
||||
include_directories: inc,
|
||||
)
|
||||
|
Reference in New Issue
Block a user