Skip to content

Commit

Permalink
Merge pull request mixxxdj#13044 from acolombier/feat/add-support-for…
Browse files Browse the repository at this point in the history
…-stem-files

Add simple support for STEM files
  • Loading branch information
daschuer committed May 26, 2024
2 parents 0efba8a + 76b12c7 commit 3c27ef3
Show file tree
Hide file tree
Showing 23 changed files with 1,239 additions and 42 deletions.
86 changes: 55 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
set(MIXXX_COMMON_PRECOMPILED_HEADER
src/util/assert.h
)
target_precompile_headers(mixxx-lib PUBLIC
set(MIXXX_LIB_PRECOMPILED_HEADER
src/audio/frame.h
src/audio/signalinfo.h
src/audio/streaminfo.h
Expand Down Expand Up @@ -1491,7 +1491,6 @@ target_precompile_headers(mixxx-lib PUBLIC
src/util/workerthread.h
src/util/workerthreadscheduler.h
src/util/xml.h
${MIXXX_COMMON_PRECOMPILED_HEADER}
)
if (NOT QML)
target_sources(mixxx-lib PRIVATE
Expand Down Expand Up @@ -2198,40 +2197,13 @@ add_executable(mixxx-test
src/test/wwidgetstack_test.cpp
src/util/moc_included_test.cpp
)
target_precompile_headers(mixxx-test REUSE_FROM mixxx-lib)
find_package(GTest CONFIG REQUIRED)
set_target_properties(mixxx-test PROPERTIES AUTOMOC ON)
target_link_libraries(mixxx-test PRIVATE mixxx-lib mixxx-gitinfostore GTest::gtest GTest::gmock)

find_package(benchmark)
target_link_libraries(mixxx-test PRIVATE benchmark::benchmark)

# Test Suite
include(CTest)
include(GoogleTest)
enable_testing()
gtest_add_tests(
TARGET mixxx-test
EXTRA_ARGS --logLevel info
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
TEST_LIST testsuite
)
if (NOT WIN32)
# Default to offscreen rendering during tests.
# This is required if the build system like Fedora koji/mock does not
# allow to pass environment variables into the ctest macro expansion.
set_tests_properties(${testsuite} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
endif()

# Benchmarking
add_custom_target(mixxx-benchmark
COMMAND $<TARGET_FILE:mixxx-test> --benchmark
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Mixxx Benchmarks"
VERBATIM
)
add_dependencies(mixxx-benchmark mixxx-test)

#
# Resources
#
Expand Down Expand Up @@ -3485,6 +3457,52 @@ if(FFMPEG)
target_include_directories(mixxx-lib PUBLIC "${FFMPEG_INCLUDE_DIRS}")
endif()

# STEM file support
default_option(STEM "STEM file support" "FFMPEG_FOUND;FFMPEG")
if (STEM)
if(NOT FFMPEG)
message(FATAL_ERROR "STEM requires that also FFMPEG is enabled")
endif()
target_compile_definitions(mixxx-lib PUBLIC __STEM__)
target_compile_definitions(mixxx-test PUBLIC __STEM__)
target_sources(mixxx-test PUBLIC
src/test/stemtest.cpp
src/test/steminfotest.cpp
)
list(APPEND MIXXX_LIB_PRECOMPILED_HEADER src/track/steminfo.h)
target_sources(mixxx-lib PRIVATE
src/sources/soundsourcestem.cpp
src/track/steminfoimporter.cpp
src/track/steminfo.cpp
)
endif()

# Test Suite
include(CTest)
include(GoogleTest)
enable_testing()
gtest_add_tests(
TARGET mixxx-test
EXTRA_ARGS --logLevel info
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
TEST_LIST testsuite
)
if (NOT WIN32)
# Default to offscreen rendering during tests.
# This is required if the build system like Fedora koji/mock does not
# allow to pass environment variables into the ctest macro expansion.
set_tests_properties(${testsuite} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
endif()

# Benchmarking
add_custom_target(mixxx-benchmark
COMMAND $<TARGET_FILE:mixxx-test> --benchmark
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Mixxx Benchmarks"
VERBATIM
)
add_dependencies(mixxx-benchmark mixxx-test)

# Google PerfTools
option(GPERFTOOLS "Google PerfTools libtcmalloc linkage" OFF)
option(GPERFTOOLSPROFILER "Google PerfTools libprofiler linkage" OFF)
Expand Down Expand Up @@ -3592,8 +3610,8 @@ if(OPUS)
src/encoder/encoderopussettings.cpp
)
target_compile_definitions(mixxx-lib PUBLIC __OPUS__)
target_link_libraries(mixxx-lib PRIVATE OpusFile::OpusFile)
target_link_libraries(mixxx-lib PRIVATE Opus::Opus)
target_link_libraries(mixxx-lib PRIVATE OpusFile::OpusFile Opus::Opus)
target_link_libraries(mixxx-test PRIVATE OpusFile::OpusFile Opus::Opus)
endif()

# MAD MP3 Decoder
Expand Down Expand Up @@ -3795,6 +3813,12 @@ if(WAVPACK)
target_link_libraries(mixxx-lib PRIVATE WavPack::wavpack)
endif()

target_precompile_headers(mixxx-lib PUBLIC
${MIXXX_LIB_PRECOMPILED_HEADER}
${MIXXX_COMMON_PRECOMPILED_HEADER}
)
target_precompile_headers(mixxx-test REUSE_FROM mixxx-lib)

# Configure file with build options
file(RELATIVE_PATH MIXXX_INSTALL_DOCDIR_RELATIVE_TO_DATADIR "${CMAKE_INSTALL_PREFIX}/${MIXXX_INSTALL_DATADIR}" "${CMAKE_INSTALL_PREFIX}/${MIXXX_INSTALL_DOCDIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/config.h" @ONLY)
Expand Down
14 changes: 13 additions & 1 deletion src/sources/soundsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QMimeType>

#include "sources/soundsourceproxy.h"
#include "track/steminfoimporter.h"
#include "util/logger.h"

namespace mixxx {
Expand Down Expand Up @@ -52,9 +53,20 @@ QString SoundSource::getTypeFromFile(const QFileInfo& fileInfo) {
// https://mixxx.zulipchat.com/#narrow/stream/109171-development/topic/mimetype.20sometimes.20wrong
return fileSuffix;
}

QMimeType mimeType = QMimeDatabase().mimeTypeForFile(
fileInfo, QMimeDatabase::MatchContent);
#ifdef __STEM__
if (
// STEM files will be detected as normal MP4, so we check if the file
// is looking like a MP4
StemInfoImporter::maybeStemFile(fileInfo.filePath(), mimeType) &&
// If yes, we search a STEM atom and assume they are valid STEM file
// if they do contain one
StemInfoImporter::hasStemAtom(fileInfo.filePath())) {
return QLatin1String("stem.mp4");
}
#endif

// According to the documentation mimeTypeForFile always returns a valid
// type, using the generic type application/octet-stream as a fallback.
// This might also occur for missing files as seen on Qt 5.12.
Expand Down
17 changes: 17 additions & 0 deletions src/sources/soundsourceproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#ifdef __MEDIAFOUNDATION__
#include "sources/soundsourcemediafoundation.h"
#endif
#ifdef __STEM__
#include "sources/soundsourcestem.h"
#endif

#include "library/coverartutils.h"
#include "track/globaltrackcache.h"
Expand Down Expand Up @@ -177,6 +180,15 @@ QList<QMimeType> mimeTypesForFileType(const QString& fileType) {
}
}
}
if (fileType == "stem.mp4" || fileType == "stem.m4a") {
// *.stem.mp4 and *.stem.m4a suffix do not have a specific MIME type
// associated with them, and simply fall back to MP4 mime type. To
// prevent conflicts with the MP4 decoder which is already mapped for
// the MP4 mime type, able to decode arbitrary MP4 file (such as video,
// extracting just the audio track), we don't return any MIME here. In
// the future, if NI STEM gets assigned a MIME, we should return it.
return {};
}
return mimeTypes;
}

Expand Down Expand Up @@ -223,6 +235,11 @@ bool SoundSourceProxy::registerProviders() {
registerSoundSourceProvider(
&s_soundSourceProviders,
std::make_shared<mixxx::SoundSourceProviderSndFile>());
#endif
#ifdef __STEM__
registerSoundSourceProvider(
&s_soundSourceProviders,
std::make_shared<mixxx::SoundSourceProviderSTEM>());
#endif
// Register the high-priority reference providers AFTER all other
// providers to verify that their priorities are correct.
Expand Down
Loading

0 comments on commit 3c27ef3

Please sign in to comment.