[vlc-commits] [Git][videolan/vlc][master] 5 commits: meta: move ID3 picture defines to ID3Pictures.h
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Sep 25 13:14:39 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
c344cc44 by François Cartegnie at 2024-09-25T12:59:37+00:00
meta: move ID3 picture defines to ID3Pictures.h
- - - - -
4240ef82 by François Cartegnie at 2024-09-25T12:59:37+00:00
meta: taglib: refactor setting up picture as attachment
- - - - -
d5f7b25d by François Cartegnie at 2024-09-25T12:59:37+00:00
meta: taglib: template default picture lookup
- - - - -
02586bac by François Cartegnie at 2024-09-25T12:59:37+00:00
meta: taglib: process FLAC pictures
- - - - -
e4b04ce3 by François Cartegnie at 2024-09-25T12:59:37+00:00
meta: taglib: simplify processing Ogg pictures
- - - - -
7 changed files:
- modules/demux/Makefile.am
- modules/demux/meson.build
- modules/demux/xiph_metadata.c
- + modules/meta_engine/ID3Pictures.h
- modules/meta_engine/Makefile.am
- modules/meta_engine/meson.build
- modules/meta_engine/taglib.cpp
Changes:
=====================================
modules/demux/Makefile.am
=====================================
@@ -1,7 +1,8 @@
demuxdir = $(pluginsdir)/demux
demux_LTLIBRARIES =
-libxiph_metadata_la_SOURCES = demux/xiph_metadata.h demux/xiph_metadata.c
+libxiph_metadata_la_SOURCES = demux/xiph_metadata.h demux/xiph_metadata.c \
+ meta_engine/ID3Pictures.h
libxiph_metadata_la_LDFLAGS = -static
noinst_LTLIBRARIES += libxiph_metadata.la
=====================================
modules/demux/meson.build
=====================================
@@ -4,7 +4,7 @@
# Common Xiph metadata library
xiph_meta_lib = static_library('xiph_metadata',
- sources: files('xiph_metadata.c'),
+ sources: files('xiph_metadata.c', '../meta_engine/ID3Pictures.h'),
include_directories: [vlc_include_dirs],
install: false,
pic: true
=====================================
modules/demux/xiph_metadata.c
=====================================
@@ -34,35 +34,11 @@
#include <vlc_arrays.h>
#include <vlc_input.h>
#include "xiph_metadata.h"
+#include "../meta_engine/ID3Pictures.h"
input_attachment_t* ParseFlacPicture( const uint8_t *p_data, size_t size,
int i_attachments, int *i_cover_score, int *i_cover_idx )
{
- /* TODO: Merge with ID3v2 copy in modules/meta_engine/taglib.cpp. */
- static const char pi_cover_score[] = {
- 0, /* Other */
- 5, /* 32x32 PNG image that should be used as the file icon */
- 4, /* File icon of a different size or format. */
- 20, /* Front cover image of the album. */
- 19, /* Back cover image of the album. */
- 13, /* Inside leaflet page of the album. */
- 18, /* Image from the album itself. */
- 17, /* Picture of the lead artist or soloist. */
- 16, /* Picture of the artist or performer. */
- 14, /* Picture of the conductor. */
- 15, /* Picture of the band or orchestra. */
- 9, /* Picture of the composer. */
- 8, /* Picture of the lyricist or text writer. */
- 7, /* Picture of the recording location or studio. */
- 10, /* Picture of the artists during recording. */
- 11, /* Picture of the artists during performance. */
- 6, /* Picture from a movie or video related to the track. */
- 1, /* Picture of a large, coloured fish. */
- 12, /* Illustration related to the track. */
- 3, /* Logo of the band or performer. */
- 2 /* Logo of the publisher (record company). */
- };
-
uint32_t type, len;
if( size < 8 )
@@ -136,11 +112,11 @@ input_attachment_t* ParseFlacPicture( const uint8_t *p_data, size_t size,
p_attachment = vlc_input_attachment_New( name, mime, description, p_data,
size /* XXX: len instead? */ );
- if( type < ARRAY_SIZE(pi_cover_score) &&
- *i_cover_score < pi_cover_score[type] )
+ if( type < ARRAY_SIZE(ID3v2_cover_scores) &&
+ *i_cover_score < ID3v2_cover_scores[type] )
{
*i_cover_idx = i_attachments;
- *i_cover_score = pi_cover_score[type];
+ *i_cover_score = ID3v2_cover_scores[type];
}
error:
=====================================
modules/meta_engine/ID3Pictures.h
=====================================
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * ID3Pictures.h : ID3v2 Pictures definitions
+ *****************************************************************************
+ * Copyright (C) 2016-2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 ID3PICTURES_H
+#define ID3PICTURES_H
+
+enum
+{
+ ID3_PICTURE_OTHER = 0x00, // Other
+ ID3_PICTURE_FILE_ICON = 0x01, // 32x32 PNG image that should be used as the file icon
+ ID3_PICTURE_OTHER_FILE_ICON = 0x02, // File icon of a different size or format.
+ ID3_PICTURE_FRONT_COVER = 0x03, // Front cover image of the album.
+ ID3_PICTURE_BACK_COVER = 0x04, // Back cover image of the album
+ ID3_PICTURE_LEAFLET_PAGE = 0x05, // Inside leaflet page of the album
+ ID3_PICTURE_MEDIA = 0x06, // Image from the album itself
+ ID3_PICTURE_LEAD_ARTIST = 0x07, // Picture of the lead artist or soloist
+ ID3_PICTURE_ARTIST = 0x08, // Picture of the artist or performer
+ ID3_PICTURE_CONDUCTOR = 0x09, // Picture of the conductor
+ ID3_PICTURE_BAND = 0x0A, // Picture of the band or orchestra
+ ID3_PICTURE_COMPOSER = 0x0B, // Picture of the composer
+ ID3_PICTURE_LYRICIST = 0x0C, // Picture of the lyricist or text writer
+ ID3_PICTURE_RECORDING_LOCATION = 0x0D, // Picture of the recording location or studio
+ ID3_PICTURE_DURING_RECORDING = 0x0E, // Picture of the artists during recording
+ ID3_PICTURE_DURING_PERFORMANCE = 0x0F, // Picture of the artists during performance
+ ID3_PICTURE_MOVIE_SCREEN_CAPTURE = 0x10, // Picture from a movie or video related to the track
+ ID3_PICTURE_COLORED_FISH = 0x11, // Picture of a large, coloured fish
+ ID3_PICTURE_ILLUSTRATION = 0x12, // Illustration related to the track
+ ID3_PICTURE_BAND_LOGO = 0x13, // Logo of the band or performer
+ ID3_PICTURE_PUBLISHER_LOGO = 0x14, // Logo of the publisher (record company)
+ ID3_PICTURE_COUNT
+};
+
+/* Preferred type of image
+ * The 21 types are defined in id3v2 standard:
+ * http://www.id3.org/id3v2.4.0-frames */
+static const char ID3v2_cover_scores[] = {
+ [ID3_PICTURE_OTHER] = 0,
+ [ID3_PICTURE_FILE_ICON] = 1,
+ [ID3_PICTURE_OTHER_FILE_ICON] = 4,
+ [ID3_PICTURE_FRONT_COVER] = 20,
+ [ID3_PICTURE_BACK_COVER] = 19,
+ [ID3_PICTURE_LEAFLET_PAGE] = 13,
+ [ID3_PICTURE_MEDIA] = 18,
+ [ID3_PICTURE_LEAD_ARTIST] = 17,
+ [ID3_PICTURE_ARTIST] = 16,
+ [ID3_PICTURE_CONDUCTOR] = 14,
+ [ID3_PICTURE_BAND] = 15,
+ [ID3_PICTURE_COMPOSER] = 9,
+ [ID3_PICTURE_LYRICIST] = 8,
+ [ID3_PICTURE_RECORDING_LOCATION] = 7,
+ [ID3_PICTURE_DURING_RECORDING] = 10,
+ [ID3_PICTURE_DURING_PERFORMANCE] = 11,
+ [ID3_PICTURE_MOVIE_SCREEN_CAPTURE] = 6,
+ [ID3_PICTURE_COLORED_FISH] = 1,
+ [ID3_PICTURE_ILLUSTRATION] = 12,
+ [ID3_PICTURE_BAND_LOGO] = 3,
+ [ID3_PICTURE_PUBLISHER_LOGO] = 2
+};
+
+static_assert(ARRAY_SIZE(ID3v2_cover_scores) == ID3_PICTURE_COUNT, "mismatched scoring table size");
+
+#endif
=====================================
modules/meta_engine/Makefile.am
=====================================
@@ -4,7 +4,7 @@ libfolder_plugin_la_SOURCES = meta_engine/folder.c
meta_LTLIBRARIES = libfolder_plugin.la
libtaglib_plugin_la_SOURCES = meta_engine/taglib.cpp \
- demux/xiph_metadata.h demux/xiph_metadata.c
+ meta_engine/ID3Pictures.h
libtaglib_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(TAGLIB_CFLAGS)
libtaglib_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(metadir)'
libtaglib_plugin_la_LIBADD = $(TAGLIB_LIBS) -lz
=====================================
modules/meta_engine/meson.build
=====================================
@@ -9,7 +9,7 @@ taglib_dep = dependency('taglib', version: '>= 1.11', required: get_option('tagl
if taglib_dep.found()
vlc_modules += {
'name' : 'taglib',
- 'sources' : files('taglib.cpp', '../demux/xiph_metadata.c'),
+ 'sources' : files('taglib.cpp'),
'dependencies' : [taglib_dep, z_dep]
}
endif
=====================================
modules/meta_engine/taglib.cpp
=====================================
@@ -36,6 +36,7 @@
#include <vlc_url.h> /* vlc_uri2path */
#include <vlc_mime.h> /* mime type */
#include <vlc_fs.h>
+#include <vlc_charset.h>
#include <vlc_cxx_helpers.hpp>
#include <sys/stat.h>
@@ -70,13 +71,14 @@
#include <asffile.h>
#include <apetag.h>
#include <flacfile.h>
+#include <flacpicture.h>
#include <mpcfile.h>
#include <mpegfile.h>
#include <mp4file.h>
#include <oggfile.h>
#include <oggflacfile.h>
#include <opusfile.h>
-#include "../demux/xiph_metadata.h"
+#include "ID3Pictures.h"
#include <aifffile.h>
#include <wavfile.h>
@@ -547,61 +549,77 @@ static void ReadMetaFromASF( ASF::Tag* tag, demux_meta_t* p_demux_meta, vlc_meta
}
}
+static void AddAPICToAttachments( demux_meta_t* p_demux_meta,
+ vlc_meta_t* p_meta,
+ const String &mimeType,
+ const String &description,
+ const char *p_data,
+ size_t i_data,
+ bool b_default = false )
+{
+ char *psz_name;
+ if( asprintf( &psz_name, "%i", p_demux_meta->i_attachments ) == -1 )
+ return;
+
+ input_attachment_t *p_attachment =
+ vlc_input_attachment_New( psz_name,
+ mimeType.toCString(),
+ description.toCString(),
+ p_data, i_data );
+ free( psz_name );
+ if( !p_attachment )
+ return;
+
+ msg_Dbg( p_demux_meta, "Found embedded art: %s (%zu bytes)",
+ p_attachment->psz_mime, p_attachment->i_data );
+
+ TAB_APPEND_CAST( (input_attachment_t**),
+ p_demux_meta->i_attachments, p_demux_meta->attachments,
+ p_attachment );
+
+ if( b_default )
+ {
+ char *psz_url;
+ if( asprintf( &psz_url, "attachment://%s",
+ p_attachment->psz_name ) == -1 )
+ return;
+ vlc_meta_SetArtURL( p_meta, psz_url );
+ free( psz_url );
+ }
+}
+
/**
* Fills attachments list from ID3 APIC tags
* @param tag: the APIC tags list
* @param p_demux_meta: the demuxer meta
* @param p_meta: the meta
*/
-static void ProcessAPICListFromId3v2( const ID3v2::FrameList &list,
- demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
-{
- /* Preferred type of image
- * The 21 types are defined in id3v2 standard:
- * http://www.id3.org/id3v2.4.0-frames */
- static const uint8_t scores[] = {
- 0, /* Other */
- 5, /* 32x32 PNG image that should be used as the file icon */
- 4, /* File icon of a different size or format. */
- 20, /* Front cover image of the album. */
- 19, /* Back cover image of the album. */
- 13, /* Inside leaflet page of the album. */
- 18, /* Image from the album itself. */
- 17, /* Picture of the lead artist or soloist. */
- 16, /* Picture of the artist or performer. */
- 14, /* Picture of the conductor. */
- 15, /* Picture of the band or orchestra. */
- 9, /* Picture of the composer. */
- 8, /* Picture of the lyricist or text writer. */
- 7, /* Picture of the recording location or studio. */
- 10, /* Picture of the artists during recording. */
- 11, /* Picture of the artists during performance. */
- 6, /* Picture from a movie or video related to the track. */
- 1, /* Picture of a large, coloured fish. */
- 12, /* Illustration related to the track. */
- 3, /* Logo of the band or performer. */
- 2 /* Logo of the publisher (record company). */
- };
- const ID3v2::AttachedPictureFrame *defaultPic = nullptr;
+template<class T, class L>
+ const T * getDefaultPic(const L &list)
+{
+ const T *defaultPic = nullptr;
+ int bestscore = 0;
for( auto iter = list.begin(); iter != list.end(); ++iter )
{
- const ID3v2::AttachedPictureFrame* p =
- dynamic_cast<const ID3v2::AttachedPictureFrame*>(*iter);
+ const T* p = static_cast<const T*>(*iter);
if( !p )
continue;
- if(defaultPic == nullptr)
+ int score = p->type() >= ARRAY_SIZE(ID3v2_cover_scores) ? 0 : ID3v2_cover_scores[p->type()];
+ if(defaultPic == nullptr || score > bestscore)
{
defaultPic = p;
- }
- else
- {
- int scorea = defaultPic->type() >= ARRAY_SIZE(scores) ? 0 : scores[defaultPic->type()];
- int scoreb = p->type() >= ARRAY_SIZE(scores) ? 0 : scores[p->type()];
- if(scoreb > scorea)
- defaultPic = p;
+ bestscore = score;
}
}
+ return defaultPic;
+}
+
+static void ProcessAPICListFromId3v2( const ID3v2::FrameList &list,
+ demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
+{
+ const ID3v2::AttachedPictureFrame *defaultPic =
+ getDefaultPic<ID3v2::AttachedPictureFrame, ID3v2::FrameList>(list);
for( auto iter = list.begin(); iter != list.end(); ++iter )
{
@@ -623,36 +641,28 @@ static void ProcessAPICListFromId3v2( const ID3v2::FrameList &list,
continue;
}
- char *psz_name;
- if( asprintf( &psz_name, "%i", p_demux_meta->i_attachments ) == -1 )
- continue;
-
- input_attachment_t *p_attachment =
- vlc_input_attachment_New( psz_name,
- mimeType.toCString(),
- description.toCString(),
- p->picture().data(),
- p->picture().size() );
- free( psz_name );
- if( !p_attachment )
- continue;
-
- msg_Dbg( p_demux_meta, "Found embedded art: %s (%zu bytes)",
- p_attachment->psz_mime, p_attachment->i_data );
+ AddAPICToAttachments( p_demux_meta, p_meta,
+ mimeType, description,
+ p->picture().data(), p->picture().size(),
+ p == defaultPic );
+ }
+}
- TAB_APPEND_CAST( (input_attachment_t**),
- p_demux_meta->i_attachments, p_demux_meta->attachments,
- p_attachment );
+static void ProcessAPICListFromFLAC( const List< FLAC::Picture * > &list,
+ demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
+{
+ const FLAC::Picture *defaultPic =
+ getDefaultPic<FLAC::Picture, List< FLAC::Picture * >>(list);
- if( p == defaultPic )
- {
- char *psz_url;
- if( asprintf( &psz_url, "attachment://%s",
- p_attachment->psz_name ) == -1 )
- continue;
- vlc_meta_SetArtURL( p_meta, psz_url );
- free( psz_url );
- }
+ for( auto iter = list.begin(); iter != list.end(); ++iter )
+ {
+ const FLAC::Picture* p = static_cast<const FLAC::Picture*>(*iter);
+ if( !p )
+ continue;
+ AddAPICToAttachments( p_demux_meta, p_meta,
+ p->mimeType(), p->description(),
+ p->data().data(), p->data().size(),
+ p == defaultPic );
}
}
@@ -839,61 +849,8 @@ static void ReadMetaFromXiph( Ogg::XiphComment* tag, demux_meta_t* p_demux_meta,
}
}
- // Try now to get embedded art
- StringList mime_list { tag->fieldListMap()[ "COVERARTMIME" ] };
- StringList art_list { tag->fieldListMap()[ "COVERART" ] };
-
- input_attachment_t *p_attachment;
-
- if( mime_list.size() != 0 && art_list.size() != 0 )
- {
- // We get only the first cover art
- if( mime_list.size() > 1 || art_list.size() > 1 )
- msg_Warn( p_demux_meta, "Found %i embedded arts, so using only the first one",
- art_list.size() );
-
- const char* psz_name = "cover";
- const char* psz_mime = mime_list[0].toCString(true);
- const char* psz_description = "cover";
-
- uint8_t *p_data;
- int i_data = vlc_b64_decode_binary( &p_data, art_list[0].toCString(false) );
-
- msg_Dbg( p_demux_meta, "Found embedded art: %s (%s) is %i bytes",
- psz_name, psz_mime, i_data );
-
- p_attachment = vlc_input_attachment_New( psz_name, psz_mime,
- psz_description, p_data, i_data );
- free( p_data );
- }
- else
- {
- StringList block_picture_list { tag->fieldListMap()[ "METADATA_BLOCK_PICTURE" ] };
- if( block_picture_list.size() == 0 )
- return;
-
- uint8_t *p_data;
- int i_cover_score;
- int i_cover_idx;
- int i_data = vlc_b64_decode_binary( &p_data, block_picture_list[0].toCString(false) );
- i_cover_score = i_cover_idx = 0;
- /* TODO: Use i_cover_score / i_cover_idx to select the picture. */
- p_attachment = ParseFlacPicture( p_data, i_data, 0,
- &i_cover_score, &i_cover_idx );
- free( p_data );
- }
-
- if (p_attachment) {
- TAB_APPEND_CAST( (input_attachment_t**),
- p_demux_meta->i_attachments, p_demux_meta->attachments,
- p_attachment );
-
- char *psz_url;
- if( asprintf( &psz_url, "attachment://%s", p_attachment->psz_name ) != -1 ) {
- vlc_meta_SetArtURL( p_meta, psz_url );
- free( psz_url );
- }
- }
+ // Taglib extracts if(key == "METADATA_BLOCK_PICTURE" || key == "COVERART")
+ ProcessAPICListFromFLAC( tag->pictureList(), p_demux_meta, p_meta );
}
/**
@@ -1065,6 +1022,7 @@ static int ReadMeta( vlc_object_t* p_this)
ReadMetaFromId3v2( flac->ID3v2Tag(), p_demux_meta, p_meta );
else if( flac->xiphComment() )
ReadMetaFromXiph( flac->xiphComment(), p_demux_meta, p_meta );
+ ProcessAPICListFromFLAC( flac->pictureList(), p_demux_meta, p_meta );
}
else if( MP4::File *mp4 = dynamic_cast<MP4::File*>(f.file()) )
{
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bbd294d1e46b86653873ec88d49e9a15cbaae68f...e4b04ce37b02cb9c257612b52aaf5abb2b1e14fe
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bbd294d1e46b86653873ec88d49e9a15cbaae68f...e4b04ce37b02cb9c257612b52aaf5abb2b1e14fe
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list