From 272b3f85f474180b19ec17ab6e1b53ab4dddbc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 13 Jan 2024 12:38:04 +0200 Subject: [PATCH] decomp: add Zstandard support --- NEWS | 1 + modules/stream_filter/decomp.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/NEWS b/NEWS index 5e47ec8486..591efc1603 100644 --- a/NEWS +++ b/NEWS @@ -69,6 +69,7 @@ Access: * Deprecates Audio CD CDDB lookups in favor of more accurate Musicbrainz * Improved CD-TEXT and added Shift-JIS encoding support * Support for YoutubeDL (where available). + * On-the-fly Zstandard (zstd) file decompression (where available). Access output: * Added support for the RIST (Reliable Internet Stream Transport) Protocol diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c index 4a12a3278d..04033cdf02 100644 --- a/modules/stream_filter/decomp.c +++ b/modules/stream_filter/decomp.c @@ -46,12 +46,17 @@ static int OpenGzip (vlc_object_t *); static int OpenBzip2 (vlc_object_t *); static int OpenXZ (vlc_object_t *); +static int OpenZstd(vlc_object_t *); static void Close (vlc_object_t *); vlc_module_begin () set_subcategory (SUBCAT_INPUT_STREAM_FILTER) set_capability ("stream_filter", 320) + set_description (N_("Zstandard decompression")) + set_callbacks (OpenZstd, Close) + + add_submodule () set_description (N_("LZMA decompression")) set_callbacks (OpenXZ, Close) @@ -396,3 +401,23 @@ static int OpenXZ (vlc_object_t *obj) msg_Dbg (obj, "detected xz compressed stream"); return Open (stream, "xzcat"); } + +/** + * Detects zstd file format + */ +static int OpenZstd(vlc_object_t *obj) +{ + stream_t *stream = (stream_t *)obj; + const uint8_t *peek; + + /* (Try to) parse the Zstd frame header (minimum size is 6 bytes) */ + if (vlc_stream_Peek(stream->s, &peek, 6) < 6) + return VLC_ENOTSUP; + if (memcmp(peek, "\x28\xb5\x2f\xfd", 4)) /* magic number */ + return VLC_ENOTSUP; + if (peek[4] & 0x08) /* reserved bit */ + return VLC_ENOTSUP; + + msg_Dbg(obj, "detected zstd compressed stream"); + return Open(stream, "zstdcat"); +}