Compile time configuration WITH_MATROSKA

This commit is contained in:
Urs Fleisch
2025-08-05 21:58:02 +02:00
parent f94843614f
commit 4546c00417
9 changed files with 91 additions and 76 deletions

View File

@ -100,6 +100,7 @@ include(ConfigureChecks.cmake)
option(WITH_APE "Build with APE, MPC, WavPack" ON)
option(WITH_ASF "Build with ASF" ON)
option(WITH_DSF "Build with DSF" ON)
option(WITH_MATROSKA "Build with Matroska" ON)
option(WITH_MOD "Build with Tracker modules" ON)
option(WITH_MP4 "Build with MP4" ON)
option(WITH_RIFF "Build with AIFF, RIFF, WAV" ON)
@ -197,6 +198,9 @@ endif()
if(WITH_DSF)
set(TAGLIB_WITH_DSF TRUE)
endif()
if(WITH_MATROSKA)
set(TAGLIB_WITH_MATROSKA TRUE)
endif()
if(WITH_MOD)
set(TAGLIB_WITH_MOD TRUE)
endif()

View File

@ -63,6 +63,7 @@ and ID3 tags cannot be disabled. The following CMake options are available:
| `WITH_APE` | Build with APE, MPC, WavPack (default ON) |
| `WITH_ASF` | Build with ASF (default ON) |
| `WITH_DSF` | Build with DSF (default ON) |
| `WITH_MATROSKA` | Build with Matroska (default ON) |
| `WITH_MOD` | Build with Tracker modules (default ON) |
| `WITH_MP4` | Build with MP4 (default ON) |
| `WITH_RIFF` | Build with AIFF, RIFF, WAV (default ON) |

View File

@ -39,15 +39,17 @@ target_link_libraries(framelist tag)
add_executable(strip-id3v1 strip-id3v1.cpp)
target_link_libraries(strip-id3v1 tag)
########### next target ###############
if(WITH_MATROSKA)
########### next target ###############
add_executable(matroskareader matroskareader.cpp)
target_link_libraries(matroskareader tag)
add_executable(matroskareader matroskareader.cpp)
target_link_libraries(matroskareader tag)
########### next target ###############
########### next target ###############
add_executable(matroskawriter matroskawriter.cpp)
target_link_libraries(matroskawriter tag)
add_executable(matroskawriter matroskawriter.cpp)
target_link_libraries(matroskawriter tag)
endif()
install(TARGETS tagreader tagreader_c tagwriter framelist strip-id3v1
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

View File

@ -5,8 +5,6 @@ set(tag_HDR_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2/frames
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
${CMAKE_CURRENT_SOURCE_DIR}/matroska
${CMAKE_CURRENT_SOURCE_DIR}/matroska/ebml
)
if(WITH_ASF)
set(tag_HDR_DIRS ${tag_HDR_DIRS}
@ -66,9 +64,15 @@ if(WITH_SHORTEN)
${CMAKE_CURRENT_SOURCE_DIR}/shorten
)
endif()
if(WITH_MATROSKA)
set(tag_HDR_DIRS ${tag_HDR_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/matroska
${CMAKE_CURRENT_SOURCE_DIR}/matroska/ebml
)
endif()
include_directories(${tag_HDR_DIRS})
set(tag_PUBLIC_HDRS
set(tag_HDRS
tag.h
fileref.h
audioproperties.h
@ -92,12 +96,6 @@ set(tag_PUBLIC_HDRS
toolkit/tpropertymap.h
toolkit/tdebuglistener.h
toolkit/tversionnumber.h
matroska/matroskaattachedfile.h
matroska/matroskaattachments.h
matroska/matroskafile.h
matroska/matroskatag.h
matroska/matroskasimpletag.h
matroska/matroskaelement.h
mpeg/mpegfile.h
mpeg/mpegproperties.h
mpeg/mpegheader.h
@ -228,49 +226,32 @@ if(WITH_SHORTEN)
shorten/shortentag.h
)
endif()
set(tag_PRIVATE_HDRS
matroska/matroskaseekhead.h
matroska/matroskasegment.h
matroska/ebml/ebmlbinaryelement.h
matroska/ebml/ebmlelement.h
matroska/ebml/ebmlmasterelement.h
matroska/ebml/ebmlmkattachments.h
matroska/ebml/ebmlmkseekhead.h
matroska/ebml/ebmlmksegment.h
matroska/ebml/ebmlmktags.h
matroska/ebml/ebmlstringelement.h
matroska/ebml/ebmluintelement.h
matroska/ebml/ebmlutils.h
matroska/ebml/ebmlvoidelement.h
)
set(tag_HDRS ${tag_PUBLIC_HDRS} ${tag_PRIVATE_HDRS})
set(matroska_SRCS
matroska/matroskaattachedfile.cpp
matroska/matroskaattachments.cpp
matroska/matroskaelement.cpp
matroska/matroskafile.cpp
matroska/matroskaseekhead.cpp
matroska/matroskasegment.cpp
matroska/matroskasimpletag.cpp
matroska/matroskatag.cpp
)
set(ebml_SRCS
matroska/ebml/ebmlbinaryelement.cpp
matroska/ebml/ebmlelement.cpp
matroska/ebml/ebmlmasterelement.cpp
matroska/ebml/ebmlmkattachments.cpp
matroska/ebml/ebmlmkseekhead.cpp
matroska/ebml/ebmlmksegment.cpp
matroska/ebml/ebmlmktags.cpp
matroska/ebml/ebmlstringelement.cpp
matroska/ebml/ebmluintelement.cpp
matroska/ebml/ebmlutils.cpp
matroska/ebml/ebmlvoidelement.cpp
)
if(WITH_MATROSKA)
set(tag_HDRS ${tag_HDRS}
matroska/matroskafile.h
matroska/matroskatag.h
matroska/matroskasimpletag.h
matroska/matroskaattachedfile.h
matroska/matroskaattachments.h
matroska/matroskafile.h
matroska/matroskatag.h
matroska/matroskasimpletag.h
matroska/matroskaelement.h
matroska/matroskaseekhead.h
matroska/matroskasegment.h
matroska/ebml/ebmlbinaryelement.h
matroska/ebml/ebmlelement.h
matroska/ebml/ebmlmasterelement.h
matroska/ebml/ebmlmkattachments.h
matroska/ebml/ebmlmkseekhead.h
matroska/ebml/ebmlmksegment.h
matroska/ebml/ebmlmktags.h
matroska/ebml/ebmlstringelement.h
matroska/ebml/ebmluintelement.h
matroska/ebml/ebmlutils.h
matroska/ebml/ebmlvoidelement.h
)
endif()
set(mpeg_SRCS
mpeg/mpegfile.cpp
@ -461,6 +442,33 @@ if(WITH_SHORTEN)
)
endif()
if(WITH_MATROSKA)
set(matroska_SRCS
matroska/matroskaattachedfile.cpp
matroska/matroskaattachments.cpp
matroska/matroskaelement.cpp
matroska/matroskafile.cpp
matroska/matroskaseekhead.cpp
matroska/matroskasegment.cpp
matroska/matroskasimpletag.cpp
matroska/matroskatag.cpp
)
set(ebml_SRCS
matroska/ebml/ebmlbinaryelement.cpp
matroska/ebml/ebmlelement.cpp
matroska/ebml/ebmlmasterelement.cpp
matroska/ebml/ebmlmkattachments.cpp
matroska/ebml/ebmlmkseekhead.cpp
matroska/ebml/ebmlmksegment.cpp
matroska/ebml/ebmlmktags.cpp
matroska/ebml/ebmlstringelement.cpp
matroska/ebml/ebmluintelement.cpp
matroska/ebml/ebmlutils.cpp
matroska/ebml/ebmlvoidelement.cpp
)
endif()
set(toolkit_SRCS
toolkit/tstring.cpp
toolkit/tstringlist.cpp
@ -480,11 +488,11 @@ set(toolkit_SRCS
)
set(tag_LIB_SRCS
${matroska_SRCS} ${ebml_SRCS} ${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS} ${riff_SRCS} ${aiff_SRCS} ${wav_SRCS}
${asf_SRCS} ${mp4_SRCS} ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS} ${opus_SRCS}
${dsf_SRCS} ${dsdiff_SRCS} ${shorten_SRCS}
${dsf_SRCS} ${dsdiff_SRCS} ${shorten_SRCS} ${matroska_SRCS} ${ebml_SRCS}
tag.cpp
tagunion.cpp
fileref.cpp
@ -509,13 +517,8 @@ set_target_properties(tag PROPERTIES
SOVERSION ${TAGLIB_SOVERSION_MAJOR}
INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR}
DEFINE_SYMBOL MAKE_TAGLIB_LIB
<<<<<<< HEAD
INTERFACE_LINK_LIBRARIES "${ZLIB_INTERFACE_LINK_LIBRARIES}"
PUBLIC_HEADER "${tag_HDRS}"
=======
LINK_INTERFACE_LIBRARIES ""
PUBLIC_HEADER "${tag_PUBLIC_HDRS}"
>>>>>>> 770c1012 (Initial matroska support)
)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(tag PUBLIC TAGLIB_STATIC)

View File

@ -38,7 +38,6 @@
#include "tstringlist.h"
#include "tvariant.h"
#include "tdebug.h"
#include "matroskafile.h"
#include "mpegfile.h"
#ifdef TAGLIB_WITH_RIFF
#include "aifffile.h"
@ -78,6 +77,9 @@
#ifdef TAGLIB_WITH_SHORTEN
#include "shortenfile.h"
#endif
#ifdef TAGLIB_WITH_MATROSKA
#include "matroskafile.h"
#endif
using namespace TagLib;
@ -221,8 +223,10 @@ namespace
else if(ext == "SHN")
file = new Shorten::File(stream, readAudioProperties, audioPropertiesStyle);
#endif
#ifdef TAGLIB_WITH_MATROSKA
else if(ext == "MKA" || ext == "MKV" || ext == "WEBM")
file = new Matroska::File(stream, readAudioProperties);
#endif
// if file is not valid, leave it to content-based detection.

View File

@ -59,11 +59,10 @@ ByteVector EBML::UIntElement::render()
ByteVector buffer = renderId();
buffer.append(renderVINT(dataSize, 0));
unsigned long long value = this->value;
static const auto byteOrder = Utils::systemByteOrder();
if(byteOrder == Utils::LittleEndian)
value = Utils::byteSwap((unsigned long long) value);
uint64_t value = this->value;
static const auto byteOrder = Utils::systemByteOrder();
if (byteOrder == Utils::LittleEndian)
value = Utils::byteSwap(value);
buffer.append(ByteVector((char*) &value + (sizeof(value) - dataSize), dataSize));
return buffer;

View File

@ -97,14 +97,14 @@ ByteVector EBML::renderVINT(uint64_t number, int minSizeLength)
int numBytes = std::max(minSizeLength, minSize(number));
number |= (1ULL << (numBytes * 7));
static const auto byteOrder = Utils::systemByteOrder();
if(byteOrder == Utils::LittleEndian)
number = Utils::byteSwap(static_cast<unsigned long long>(number));
return ByteVector((char*) &number + (sizeof(number) - numBytes), numBytes);
if (byteOrder == Utils::LittleEndian)
number = Utils::byteSwap(number);
return ByteVector((char*) &number + (sizeof(number) - numBytes), numBytes);
}
unsigned long long EBML::randomUID()
{
static std::random_device device;
static std::random_device device;
static std::mt19937 generator(device());
static std::uniform_int_distribution<unsigned long long> distribution;
return distribution(generator);

View File

@ -24,6 +24,7 @@
#include <memory>
#include "taglib_export.h"
#include "taglib.h"
#include "tutils.h"
#include "tbytevector.h"
#include "tlist.h"
@ -76,4 +77,4 @@ namespace TagLib {
}
#endif
#endif
#endif

View File

@ -6,6 +6,7 @@
#cmakedefine TAGLIB_WITH_APE 1
#cmakedefine TAGLIB_WITH_ASF 1
#cmakedefine TAGLIB_WITH_DSF 1
#cmakedefine TAGLIB_WITH_MATROSKA 1
#cmakedefine TAGLIB_WITH_MOD 1
#cmakedefine TAGLIB_WITH_MP4 1
#cmakedefine TAGLIB_WITH_RIFF 1