Skip to content

Commit 2e5c64d

Browse files
committed
libmatroska2: add Zstandard compression support
1 parent cc81e20 commit 2e5c64d

File tree

5 files changed

+232
-7
lines changed

5 files changed

+232
-7
lines changed

libmatroska2/CMakeLists.txt

+25-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ project("matroska2" VERSION 0.22.3 LANGUAGES C)
22

33
option(CONFIG_BZLIB "Enable bzlib (de)compression in libmatroska2" ON)
44
option(CONFIG_LZO1X "Enable lzo (de)compression in libmatroska2" ON)
5+
option(CONFIG_ZSTD "Enable Zstandard/zstd (de)compression in libmatroska2" ON)
56
option(CONFIG_NOCODEC_HELPER "Enable Vorbis frame durations in libmatroska2" ON)
67

78
set(matroska2_SOURCES
@@ -40,12 +41,34 @@ if (CONFIG_BZLIB)
4041
add_subdirectory("bzip2")
4142
target_link_libraries("matroska2" PRIVATE $<BUILD_INTERFACE:bzlib>)
4243
endif(CONFIG_BZLIB)
44+
if (CONFIG_ZSTD)
45+
include(FetchContent)
46+
47+
set(ZSTD_BUILD_STATIC ON)
48+
set(ZSTD_BUILD_SHARED OFF)
49+
set(ZSTD_BUILD_PROGRAMS OFF)
50+
set(ZSTD_BUILD_TESTS OFF)
51+
set(ZSTD_LEGACY_SUPPORT OFF)
52+
53+
FetchContent_Declare(
54+
zstd
55+
URL "https://github.com/facebook/zstd/releases/download/v1.5.6/zstd-1.5.6.tar.gz"
56+
URL_HASH SHA512=54a578f2484da0520a6e9a24f501b9540a3fe3806785d6bc9db79fc095b7c142a7c121387c7eecd460ca71446603584ef1ba4d29a33ca90873338c9ffbd04f14
57+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
58+
SOURCE_SUBDIR build/cmake
59+
)
60+
61+
FetchContent_MakeAvailable(zstd)
62+
63+
target_include_directories("matroska2" PRIVATE ${zstd_SOURCE_DIR}/lib )
64+
target_link_libraries("matroska2" PRIVATE $<BUILD_INTERFACE:libzstd_static>)
65+
endif(CONFIG_ZSTD)
4366
if (NOT CONFIG_NOCODEC_HELPER)
4467
add_subdirectory("tremor")
4568
target_link_libraries("matroska2" PRIVATE $<BUILD_INTERFACE:tremor>)
4669
endif(NOT CONFIG_NOCODEC_HELPER)
4770

48-
set_target_properties("matroska2" PROPERTIES
71+
set_target_properties("matroska2" PROPERTIES
4972
PUBLIC_HEADER "${matroska2_PUBLIC_HEADERS}"
5073
C_STANDARD 11
5174
)
@@ -59,7 +82,7 @@ endif (BUILD_SHARED_LIBS)
5982

6083
include(GNUInstallDirs)
6184

62-
install(TARGETS "matroska2"
85+
install(TARGETS "matroska2"
6386
EXPORT Matroska2
6487
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/matroska2
6588
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

libmatroska2/matroska2/matroska.h

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ static INLINE err_t CompressFrameZLib(const uint8_t *Cursor, size_t CursorSize,
131131
return ERR_NOT_SUPPORTED;
132132
}
133133
#endif // !CONFIG_ZLIB
134+
#if defined(CONFIG_ZSTD)
135+
MATROSKA_DLL err_t CompressFrameZstd(const uint8_t *Cursor, size_t CursorSize, uint8_t **OutBuf, size_t *OutSize);
136+
#else // !CONFIG_ZLIB
137+
static INLINE err_t CompressFrameZstd(const uint8_t *Cursor, size_t CursorSize, uint8_t **OutBuf, size_t *OutSize)
138+
{
139+
return ERR_NOT_SUPPORTED;
140+
}
141+
#endif // !CONFIG_ZLIB
134142
#endif
135143

136144
MATROSKA_DLL void MATROSKA_ClusterSort(matroska_cluster *Cluster); // not good with P frames!!!

libmatroska2/matroska2/matroska_sem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ typedef enum {
367367
MATROSKA_TRACK_ENCODING_COMP_BZLIB = 1, // bzip2 compression (BZIP2) **SHOULD NOT** be used.
368368
MATROSKA_TRACK_ENCODING_COMP_LZO1X = 2, // Lempel-Ziv-Oberhumer compression (LZO) **SHOULD NOT** be used.
369369
MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP = 3, // Octets in `ContentCompSettings` ((#contentcompsettings-element)) have been stripped from each frame.
370+
MATROSKA_TRACK_ENCODING_COMP_ZSTD = 4, // Zstandard (zstd).
370371
} MatroskaTrackEncodingCompAlgo;
371372

372373
/**
@@ -644,7 +645,7 @@ typedef enum {
644645
*Indicates what type of content the `ChapterAtom` contains and might be skipped. It can be used to automatically skip content based on the type.
645646
If a `ChapterAtom` is inside a `ChapterAtom` that has a `ChapterSkipType` set, it **MUST NOT** have a `ChapterSkipType` or have a `ChapterSkipType` with the same value as it's parent `ChapterAtom`.
646647
If the `ChapterAtom` doesn't contain a `ChapterTimeEnd`, the value of the `ChapterSkipType` is only valid until the next `ChapterAtom` with a `ChapterSkipType` value or the end of the file.
647-
648+
648649
*/
649650
typedef enum {
650651
MATROSKA_CHAPTERSKIPTYPE_NO_SKIPPING = 0, // Content which should not be skipped.

libmatroska2/matroska_config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// for libmatroska2
22
#cmakedefine CONFIG_LZO1X
33
#cmakedefine CONFIG_BZLIB
4+
#cmakedefine CONFIG_ZSTD
45
#cmakedefine CONFIG_NOCODEC_HELPER
56

67
#define LIBMATROSKA2_PROJECT_VERSION T("@matroska2_VERSION_MAJOR@.@matroska2_VERSION_MINOR@.@matroska2_VERSION_PATCH@")

0 commit comments

Comments
 (0)