Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,29 @@ jobs:
runs-on: ubuntu-22.04
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Install dependencies
timeout-minutes: 10
run: |
sudo apt-get update
# Based on: https://github.com/happycube/ld-decode/wiki/Installation
# Added: cmake qt6-base-dev libgl-dev (needed by QtGui)
sudo apt-get install -y --no-install-recommends git cmake make python3-setuptools python3-numpy python3-scipy python3-matplotlib qt6-base-dev libgl-dev libfftw3-dev python3-numba libavformat-dev libavcodec-dev libavutil-dev ffmpeg libsqlite3-dev libqt6sql6-sqlite

- name: Set up build dir
timeout-minutes: 1
run: mkdir build

- name: Configure
timeout-minutes: 5
run: cd build && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
- name: Install Nix
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Build
timeout-minutes: 15
run: make -C build VERBOSE=1
- name: Show Nix info
run: nix --version

- name: Install
timeout-minutes: 5
run: make -C build install DESTDIR=/tmp/staging && ls -lR /tmp/staging
- name: Build (Nix)
timeout-minutes: 20
run: nix build .#

- name: Run tests
timeout-minutes: 10
run: cd build && ctest --output-on-failure
- name: Configure, build, and test (Nix dev shell)
timeout-minutes: 20
run: |
nix develop -c bash -lc "
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo &&
cmake --build build --verbose &&
cmake --install build --prefix /tmp/staging &&
ctest --test-dir build --output-on-failure
"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ ld_decode.egg-info/

# Compilation script
compile.bat

# Nix artefacts
result
38 changes: 38 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Build (Nix)

This project uses a Nix dev shell to provide a consistent build environment.

## Enter the dev shell

```bash
nix develop
```

This exposes all build dependencies (CMake, Ninja, Qt6, FFmpeg, FFTW, SQLite, OpenGL, etc.).

## Configure and build

```bash
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
ninja -C build
```

Artifacts will be under `build/`.

## Build without entering the shell (one-off)

```bash
nix develop -c cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
nix develop -c ninja -C build
```

## Optional: clean build

```bash
rm -rf build
```

## Notes

- The flake sets `-DEZPWD_DIR`, `-DAPP_BRANCH`, and `-DAPP_COMMIT` automatically for package builds.
- The dev shell exports `EZPWD_DIR`, so manual builds via `nix develop` pick it up automatically.
203 changes: 154 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,40 @@ option(BUILD_PYTHON
OFF
)

# Path to ezpwd headers (can be overridden by external builds)
set(EZPWD_DIR "" CACHE PATH
"Path to ezpwd C++ headers (directory containing ezpwd/rs_base)"
)

if(NOT EZPWD_DIR AND DEFINED ENV{EZPWD_DIR})
set(EZPWD_DIR "$ENV{EZPWD_DIR}" CACHE PATH
"Path to ezpwd C++ headers (directory containing ezpwd/rs_base)"
FORCE
)
endif()

if(NOT EZPWD_DIR)
set(_EZPWD_CANDIDATES
"${CMAKE_SOURCE_DIR}/src/efm-decoder/libs/ezpwd/c++"
"${CMAKE_SOURCE_DIR}/src/efm-decoder/libs/ezpwd"
)
foreach(_EZPWD_CANDIDATE IN LISTS _EZPWD_CANDIDATES)
if(EXISTS "${_EZPWD_CANDIDATE}/ezpwd/rs_base")
set(EZPWD_DIR "${_EZPWD_CANDIDATE}" CACHE PATH
"Path to ezpwd C++ headers (directory containing ezpwd/rs_base)"
FORCE
)
break()
endif()
endforeach()
unset(_EZPWD_CANDIDATES)
unset(_EZPWD_CANDIDATE)
endif()

if(NOT EZPWD_DIR OR NOT EXISTS "${EZPWD_DIR}/ezpwd/rs_base")
message(FATAL_ERROR "EZPWD_DIR is not set or invalid. Set -DEZPWD_DIR=/path/to/ezpwd/c++ or initialize the ezpwd submodule at src/efm-decoder/libs/ezpwd. (Nix builds pass this automatically).")
endif()

# Check for dependencies

# When using Qt 6.3, you can replace the code block below with qt_standard_project_setup()
Expand All @@ -90,56 +124,16 @@ message(STATUS "Qt Version: ${QT_VERSION}")

find_package(PkgConfig REQUIRED)

if(NOT MSVC)
pkg_check_modules(FFTW IMPORTED_TARGET fftw3)
if(FFTW_FOUND)
# .....
set(FFTW_INCLUDE_DIR ${FFTW_INCLUDE_DIRS})
set(FFTW_LIBRARY PkgConfig::FFTW)
else()
find_package(FFTW REQUIRED)
endif()
else()
# pkg-config seems to
# result in trying to link to m.lib
# which breaks build on
# MSVC, so just use the cmake.config from
# the vcpkg install instead.
find_package(FFTW3 REQUIRED)
set(FFTW_INCLUDE_DIR ${FFTW3_INCLUDE_DIRS})
find_library(FFTW_LIBRARY ${FFTW3_LIBRARIES} ${FFTW3_LIBRARY_DIRS})
endif()

# Get the Git branch and revision

execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Check if there are uncommitted changes
execute_process(
COMMAND git diff-index --quiet HEAD --
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_DIRTY
)
pkg_check_modules(FFTW REQUIRED IMPORTED_TARGET fftw3)
set(FFTW_INCLUDE_DIR ${FFTW_INCLUDE_DIRS})
set(FFTW_LIBRARY PkgConfig::FFTW)

# Add -dirty suffix if there are uncommitted changes
if(GIT_DIRTY)
set(GIT_COMMIT_HASH "${GIT_COMMIT_HASH}-dirty")
endif()
# Build metadata (set by Nix or other build systems)
set(APP_BRANCH "nix" CACHE STRING "Build source identifier")
set(APP_COMMIT "0.0.0" CACHE STRING "Build version identifier")

add_compile_definitions(APP_BRANCH=\"${GIT_BRANCH}\")
add_compile_definitions(APP_COMMIT=\"${GIT_COMMIT_HASH}\")
add_compile_definitions(APP_BRANCH=\"${APP_BRANCH}\")
add_compile_definitions(APP_COMMIT=\"${APP_COMMIT}\")

# Subdirectories

Expand All @@ -164,5 +158,116 @@ if(BUILD_TESTING)
add_subdirectory(src/library/tbc/testmetadata)
add_subdirectory(src/library/tbc/testvbidecoder)
add_subdirectory(src/library/tbc/testvitcdecoder)
include(LdDecodeTests)

# Tests for the ld-decode tools.
# Most of the tests expect that you have cloned (or symlinked) the
# ld-decode-testdata repo within the source directory as "testdata".
# Chroma tests run sequentially to avoid file conflicts

set(SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/scripts)
set(TESTDATA_DIR ${CMAKE_SOURCE_DIR}/testdata)

add_test(
NAME chroma-ntsc-rgb
COMMAND ${SCRIPTS_DIR}/test-chroma
--build ${CMAKE_BINARY_DIR}
--system ntsc
--expect-psnr 25
--expect-psnr-range 0.5
)

add_test(
NAME chroma-ntsc-ycbcr
COMMAND ${SCRIPTS_DIR}/test-chroma
--build ${CMAKE_BINARY_DIR}
--system ntsc
--expect-psnr 25
--expect-psnr-range 0.5
--input-format yuv
)
set_tests_properties(chroma-ntsc-ycbcr PROPERTIES DEPENDS chroma-ntsc-rgb)

add_test(
NAME chroma-pal-rgb
COMMAND ${SCRIPTS_DIR}/test-chroma
--build ${CMAKE_BINARY_DIR}
--system pal
--expect-psnr 25
--expect-psnr-range 0.5
)
set_tests_properties(chroma-pal-rgb PROPERTIES DEPENDS chroma-ntsc-ycbcr)

add_test(
NAME chroma-pal-ycbcr
COMMAND ${SCRIPTS_DIR}/test-chroma
--build ${CMAKE_BINARY_DIR}
--system pal
--expect-psnr 25
--expect-psnr-range 0.5
--input-format yuv
)
set_tests_properties(chroma-pal-ycbcr PROPERTIES DEPENDS chroma-pal-rgb)

# Tests using pre-generated TBC files (ld-decode/ld-cut not part of this repo)
# Note: These tests were previously named ld-cut-ntsc and decode-ntsc-cav but both
# used the same source file. Now using pre-generated TBC, they test the same pipeline.
add_test(
NAME decode-pretbc-ntsc-cav
COMMAND ${SCRIPTS_DIR}/test-decode-pretbc
--build ${CMAKE_BINARY_DIR}
--decoder mono --decoder ntsc2d --decoder ntsc3d
--expect-frames 29
--expect-bpsnr 43.3
--expect-vbi 9151563,15925840,15925840
--expect-efm-samples 40572
${CMAKE_SOURCE_DIR}/test-data/ntsc/ve-snw-cut
)

add_test(
NAME decode-pretbc-ntsc-clv
COMMAND ${SCRIPTS_DIR}/test-decode-pretbc
--build ${CMAKE_BINARY_DIR}
--no-efm-timecodes
--expect-frames 4
--expect-bpsnr 37.6
--expect-vbi 9167913,15785241,15785241
${CMAKE_SOURCE_DIR}/test-data/ntsc/issue176
)

add_test(
NAME decode-pretbc-pal-cav
COMMAND ${SCRIPTS_DIR}/test-decode-pretbc
--build ${CMAKE_BINARY_DIR}
--pal
--decoder mono --decoder pal2d --decoder transform2d --decoder transform3d
--expect-frames 4
--expect-bpsnr 38.4
--expect-vbi 9151527,16065688,16065688
--expect-vitc 2,10,8,13,4,3,0,1
--expect-efm-samples 5292
${CMAKE_SOURCE_DIR}/test-data/pal/jason-testpattern
)

add_test(
NAME decode-pretbc-pal-clv
COMMAND ${SCRIPTS_DIR}/test-decode-pretbc
--build ${CMAKE_BINARY_DIR}
--pal
--no-efm
--expect-frames 9
--expect-bpsnr 30.3
--expect-vbi 0,8449774,8449774
${CMAKE_SOURCE_DIR}/test-data/pal/kagemusha-leadout-cbar
)

add_test(
NAME decode-pretbc-pal-ggv
COMMAND ${SCRIPTS_DIR}/test-decode-pretbc
--build ${CMAKE_BINARY_DIR}
--pal
--no-efm # GGV discs do not contain EFM data
--expect-frames 24
--expect-vbi 9152512,15730528,15730528
${CMAKE_SOURCE_DIR}/test-data/pal/ggv-mb-1khz
)
endif()
39 changes: 39 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Installation (Nix)

This project ships a Nix flake that provides both a build and a development environment. The simplest way to install is with Nix flakes.

## Prerequisites

- Nix with flakes enabled.
- Ensure `experimental-features = nix-command flakes` is set in your Nix config.

## Install with Nix

### Install into your user profile

```bash
nix profile install .#
```

This installs the tools into your Nix profile (for example, `~/.nix-profile/bin`).

### Build without installing

```bash
nix build .#
```

The build output will be available under `./result`.

### Run from the build output

```bash
./result/bin/ld-analyse
```

Replace `ld-analyse` with any other tool from the suite.

## Notes

- The flake pins all required dependencies, including Qt6, FFmpeg, FFTW, SQLite, and OpenGL.
- Build metadata (branch/commit) is set by the flake during the build.
Loading