Files

109 lines
5.5 KiB
C
Raw Permalink Normal View History

2022-05-28 12:57:21 +01:00
/*
* This file is part of the Aaru Data Preservation Suite.
2025-08-01 21:19:45 +01:00
* Copyright (c) 2019-2025 Natalia Portillo.
2022-05-28 12:57:21 +01:00
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
2019-03-16 17:40:39 +00:00
#ifndef LIBAARUFORMAT_CONSTS_H
#define LIBAARUFORMAT_CONSTS_H
2022-06-21 21:12:25 +01:00
#ifndef _MSC_VER
#pragma clang diagnostic push
2024-04-30 15:51:32 +01:00
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
2022-06-21 21:12:25 +01:00
#endif
/** \file aaruformat/consts.h
* \brief Core public constants and compiletime limits for the Aaru container format implementation.
*
* This header exposes magic identifiers, format version selectors, resource limits, codec parameter bounds,
* and bit masks used across libaaruformat. All values are immutable interface contracts; changing them breaks
* backward compatibility unless a new format version is declared.
*
* Summary:
* - Magic numbers (DIC_MAGIC, AARU_MAGIC) identify container families (legacy DiscImageChef vs AaruFormat).
* - Version macros distinguish format generations (V1 C# / legacy CRC endianness, V2 current C implementation).
* - Cache and table size limits provide protective upper bounds against runaway memory consumption.
* - Audio constants (SAMPLES_PER_SECTOR, MIN/MAX_FLAKE_BLOCK) align with Red Book (CDDA) and FLAC encoding best
* practices.
* - CD_* masks assist with extracting flags / positional subfields in deduplicated Compact Disc sector tables.
* - CRC64 constants implement ECMA182 polynomial and standard seed, enabling deterministic endtoend block
* integrity.
*
* Notes:
* - Magic values are stored littleendian on disk when written as 64bit integers; when inspecting raw bytes make
* sure to account for host endianness.
* - AARUF_VERSION must be incremented only when an incompatible ondisk layout change is introduced.
* - MAX_DDT_ENTRY_CACHE is a soft upper bound sized to balance deduplication hit rate vs RAM; tune in future builds
* via configuration if adaptive heuristics are introduced.
* - The LZMA properties length (5) derives from the standard LZMA header (lc/lp/pb + dict size) and is constant for
* raw LZMA streams used here.
* - FLAC sample block guidance: empirical evaluation shows >4608 samples per block does not yield meaningful ratio
* gains for typical optical audio captures while increasing decode buffer size.
*
* Thread safety: All macros are compiletime constants; no synchronization required.
* Portability: Constants chosen to fit within 64bit targets; arithmetic assumes two's complement.
*/
/** Magic identifier for legacy DiscImageChef container (ASCII "DICMFRMT").
* Retained for backward compatibility / migration tooling. */
#define DIC_MAGIC 0x544D52464D434944ULL
/** Magic identifier for AaruFormat container (ASCII "AARUFRMT").
* Used in the primary header to assert correct file type. */
#define AARU_MAGIC 0x544D524655524141ULL
/** Current image format major version (incompatible changes bump this).
* Readers should reject headers with a higher number unless explicitly forward compatible. */
#define AARUF_VERSION 2
/** First ondisk version (C# implementation).
* Quirk: CRC64 values were stored byteswapped relative to ECMA182 canonical output. */
#define AARUF_VERSION_V1 1
/** Second ondisk version (C implementation).
* Introduced: extended header (GUID, feature bitmaps), hierarchical DDT v2, improved index (v2/v3),
* multicodec compression, refined metadata blocks. */
#define AARUF_VERSION_V2 2
/** Maximum read cache size (bytes). 512 MiB chosen to prevent excessive resident memory while
* still enabling efficient sequential and moderate random access patterns. */
#define MAX_CACHE_SIZE 536870912ULL
/** Size in bytes of the fixed LZMA properties header (lc/lp/pb + dictionary size). */
2019-03-17 18:37:45 +00:00
#define LZMA_PROPERTIES_LENGTH 5
2019-03-16 17:51:33 +00:00
/** Maximum number of cached DDT entry descriptors retained in memory for fast duplicate detection.
* At 16,000,000 entries with a compact structure, this caps hash_map overhead while covering large images.
* (Approx memory just for lookup bookkeeping: ~16 bytes * N 256 MB worst case; typical effective <50% of cap.) */
#define MAX_DDT_ENTRY_CACHE 16000000
/** Red Book (CDDA) PCM samples per 2352byte sector: 44,100 Hz / 75 sectors per second = 588 samples. */
#define SAMPLES_PER_SECTOR 588
/** FLAC maximum block size used for encoding audio sectors.
* Empirically >4608 samples yields diminishing compression returns and higher decode latency. */
#define MAX_FLAKE_BLOCK 4608
/** FLAC minimum block size. CUETools.Codecs.FLAKE does not accept blocks smaller than 256 samples. */
#define MIN_FLAKE_BLOCK 256
/** Mask for extracting correction / fix flags in Compact Disc suffix/prefix DDT entries.
* High 8 bits store status (see SectorStatus / CdFixFlags relationships). */
#define CD_XFIX_MASK 0xFF000000U
/** Mask for extracting positional index (lower 24 bits) in Compact Disc suffix/prefix deduplicated block entries. */
#define CD_DFIX_MASK 0x00FFFFFFU
2022-06-21 21:12:25 +01:00
#ifndef _MSC_VER
#pragma clang diagnostic pop
#endif
#endif // LIBAARUFORMAT_CONSTS_H