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
47 changes: 33 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -yq ninja-build
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Setup MSVC dev environment
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'

- name: Configure
run: cmake -B build -G Ninja
run: cmake --preset ${{ runner.os == 'Windows' && 'x64-debug' || runner.os == 'macOS' && 'macos-debug' || 'linux-debug' }}

- name: Build
run: cmake --build --preset ${{ runner.os == 'Windows' && 'x64-debug' || runner.os == 'macOS' && 'macos-debug' || 'linux-debug' }}

- name: Run string tests
run: >
out/build/${{ runner.os == 'Windows' && 'x64-debug' || runner.os == 'macOS' && 'macos-debug' || 'linux-debug' }}/test/mbmff-string-test${{ runner.os == 'Windows' && '.exe' || '' }}

- name: Build (includes constexpr tests)
run: cmake --build build
- name: Run page test on sample HEIC
run: >
out/build/${{ runner.os == 'Windows' && 'x64-debug' || runner.os == 'macOS' && 'macos-debug' || 'linux-debug' }}/test/mbmff-test${{ runner.os == 'Windows' && '.exe' || '' }}
test/assets/sample.heic

- name: Run tests on AVIF samples
run: |
for f in test/assets/*.avif; do
echo "=== $f ==="
./build/test/mbmff-test "$f"
done
- name: Run page test on sample AVIF
run: >
out/build/${{ runner.os == 'Windows' && 'x64-debug' || runner.os == 'macOS' && 'macos-debug' || 'linux-debug' }}/test/mbmff-test${{ runner.os == 'Windows' && '.exe' || '' }}
test/assets/avif_sample.avif
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ install(EXPORT mbmffTargets
)

option(MBMFF_BUILD_TEST "Build tests" ${PROJECT_IS_TOP_LEVEL})
if (MBMFF_BUILD_TEST)
add_subdirectory(test)
endif()

option(MBMFF_ENABLE_CONSTEXPR_TEST
"Enable compile-time constexpr tests in headers"
${PROJECT_IS_TOP_LEVEL}
)
if (MBMFF_ENABLE_CONSTEXPR_TEST)
target_compile_definitions(mbmff INTERFACE MBMFF_ENABLE_CONSTEXPR_TEST)

if (MBMFF_BUILD_TEST)
add_subdirectory(test)
endif()
63 changes: 55 additions & 8 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
"CMAKE_BUILD_TYPE": "Release"
}
},
{
Expand All @@ -48,17 +46,15 @@
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
"CMAKE_BUILD_TYPE": "Release"
}
},
{
Expand Down Expand Up @@ -100,6 +96,57 @@
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "clang-debug",
"displayName": "Clang Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang",
"CMAKE_BUILD_TYPE": "Debug",
"MBMFF_ENABLE_CONSTEXPR_TEST": "ON",
"MBMFF_TEST_CXX_STANDARD": "26"
}
}
],
"buildPresets": [
{
"name": "x64-debug",
"displayName": "x64 Debug",
"configurePreset": "x64-debug"
},
{
"name": "x64-release",
"displayName": "x64 Release",
"configurePreset": "x64-release"
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"configurePreset": "x86-debug"
},
{
"name": "x86-release",
"displayName": "x86 Release",
"configurePreset": "x86-release"
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"configurePreset": "linux-debug"
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"configurePreset": "macos-debug"
},
{
"name": "clang-debug",
"displayName": "Clang Debug",
"configurePreset": "clang-debug"
}
]
}
62 changes: 62 additions & 0 deletions include/mbmff/boxes/avc3.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once
#include "box_view.hpp"

namespace mbmff {

struct avc3_data {
std::uint16_t data_reference_index;
std::uint16_t width;
std::uint16_t height;
std::uint32_t horizresolution;
std::uint32_t vertresolution;
std::uint16_t frame_count;
std::span<const std::byte> compressorname;
std::uint16_t depth;
};

template <>
struct basic_box_view<mbmff::box_type::avc3> : public mbmff::box_view_base {
constexpr static mbmff::box_properties properties = mbmff::box_properties::container;
constexpr static auto validate(mbmff::any_box_view box) noexcept -> mbmff::result<mbmff::any_box_view>;
constexpr auto value() const noexcept -> mbmff::avc3_data;
};

inline constexpr auto mbmff::basic_box_view<mbmff::box_type::avc3>::validate(mbmff::any_box_view box) noexcept
-> mbmff::result<mbmff::any_box_view>
{
if (box.payload.size() < 78) {
return mbmff::make_result<mbmff::any_box_view>(mbmff::error_code::need_more_data, 78);
}
box.payload = box.payload.subspan(78);
return {box};
}

inline constexpr auto mbmff::basic_box_view<mbmff::box_type::avc3>::value() const noexcept -> mbmff::avc3_data
{
if (payload.empty() && payload.data() == nullptr) {
return {};
}
auto span = std::span<const std::byte>(payload.data() - 78, 78);
return {
mbmff::read_be<std::uint16_t>(span.subspan(6)),
mbmff::read_be<std::uint16_t>(span.subspan(24)),
mbmff::read_be<std::uint16_t>(span.subspan(26)),
mbmff::read_be<std::uint32_t>(span.subspan(28)),
mbmff::read_be<std::uint32_t>(span.subspan(32)),
mbmff::read_be<std::uint16_t>(span.subspan(40)),
span.subspan(42, 32),
mbmff::read_be<std::uint16_t>(span.subspan(74)),
};
}

#ifdef MBMFF_ENABLE_CONSTEXPR_TEST
static_assert(
!mbmff::basic_box_view<mbmff::box_type::avc3>::validate({mbmff::box_header{}, std::span<const std::byte>{}})
);

static_assert(static_cast<bool>(mbmff::basic_box_view<mbmff::box_type::avc3>::validate(
{mbmff::box_header{}, std::span<const std::byte>(std::array<std::byte, 78>{}.data(), 78)}
)));
#endif

} // namespace mbmff
Loading
Loading