Skip to content

Commit 85868df

Browse files
AlaricSenatjbkempf
authored andcommitted
taglib: wav: fix RIFF INFO tags parsing
TagLib does not provide an union of both ID3v2 and INFO tags via the usual `File::tag()` method. Their justification lies in the code for now: ```cpp /*! * Returns the ID3v2 Tag for this file. * * \note This method does not return all the tags for this file for * backward compatibility. Will be fixed in TagLib 2.0. */ ID3v2::Tag *tag() const; ``` To support WAV files providing RIFF INFO tags, we must specifically parse them before TagLib 2.0 (not released yet). Fixes #25690 (cherry picked from commit a26e2ba)
1 parent 06dff2e commit 85868df

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

modules/meta_engine/taglib.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,28 @@ static void ReadMetaFromMP4( MP4::Tag* tag, demux_meta_t *p_demux_meta, vlc_meta
845845
}
846846
}
847847

848+
static int ReadWAVMeta( const RIFF::WAV::File *wav, demux_meta_t *demux_meta )
849+
{
850+
if( !wav->hasID3v2Tag() && !wav->hasInfoTag() )
851+
return VLC_EGENERIC;
852+
853+
demux_meta->p_meta = vlc_meta_New();
854+
if( !demux_meta->p_meta )
855+
return VLC_ENOMEM;
856+
857+
TAB_INIT( demux_meta->i_attachments, demux_meta->attachments );
858+
859+
if( wav->hasInfoTag() )
860+
ReadMetaFromBasicTag( wav->InfoTag(), demux_meta->p_meta );
861+
if( wav->hasID3v2Tag() )
862+
{
863+
// Re-read basic tags from id3 to prioritize it against INFO tags.
864+
ReadMetaFromBasicTag( wav->ID3v2Tag(), demux_meta->p_meta );
865+
ReadMetaFromId3v2( wav->ID3v2Tag(), demux_meta, demux_meta->p_meta );
866+
}
867+
return VLC_SUCCESS;
868+
}
869+
848870
/**
849871
* Get the tags from the file using TagLib
850872
* @param p_this: the demux object
@@ -920,14 +942,21 @@ static int ReadMeta( vlc_object_t* p_this)
920942

921943
if( f.isNull() )
922944
return VLC_EGENERIC;
945+
946+
// XXX: Workaround a quirk in TagLib that doesn't merge id3 tags and RIFF
947+
// INFO tags in `Wav::File::tag()`'s return value.
948+
// This forces us to parse WAV separately for now.
949+
const auto* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file());
950+
if (riff_wav != nullptr)
951+
return ReadWAVMeta(riff_wav, p_demux_meta);
952+
923953
if( !f.tag() || f.tag()->isEmpty() )
924954
return VLC_EGENERIC;
925955

926956
p_demux_meta->p_meta = p_meta = vlc_meta_New();
927957
if( !p_meta )
928958
return VLC_ENOMEM;
929959

930-
931960
// Read the tags from the file
932961
ReadMetaFromBasicTag(f.tag(), p_meta);
933962

@@ -982,12 +1011,9 @@ static int ReadMeta( vlc_object_t* p_this)
9821011
ReadMetaFromXiph( ogg_opus->tag(), p_demux_meta, p_meta );
9831012
#endif
9841013
}
985-
else if( dynamic_cast<RIFF::File*>(f.file()) )
1014+
else if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
9861015
{
987-
if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
988-
ReadMetaFromId3v2( riff_aiff->tag(), p_demux_meta, p_meta );
989-
else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
990-
ReadMetaFromId3v2( riff_wav->tag(), p_demux_meta, p_meta );
1016+
ReadMetaFromId3v2( riff_aiff->tag(), p_demux_meta, p_meta );
9911017
}
9921018
else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
9931019
{

0 commit comments

Comments
 (0)