]> git.sesse.net Git - vlc/commitdiff
decomp: add support for xz compressed streams (LZMA)
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 19 Nov 2009 17:29:40 +0000 (19:29 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 19 Nov 2009 17:30:54 +0000 (19:30 +0200)
modules/stream_filter/decomp.c

index b74bd1c9f0fc6f995067361824a57d480f88d919..91f917c2032a4c0869c8ceb715ecf53a5b90161c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * decomp.c : Decompression module for vlc
  *****************************************************************************
- * Copyright © 2008 Rémi Denis-Courmont
+ * Copyright © 2008-2009 Rémi Denis-Courmont
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -47,6 +47,7 @@
 
 static int  OpenGzip (vlc_object_t *);
 static int  OpenBzip2 (vlc_object_t *);
+static int  OpenXZ (vlc_object_t *);
 static void Close (vlc_object_t *);
 
 vlc_module_begin ()
@@ -54,6 +55,9 @@ vlc_module_begin ()
     set_category (CAT_INPUT)
     set_subcategory (SUBCAT_INPUT_STREAM_FILTER)
     set_capability ("stream_filter", 20)
+    set_callbacks (OpenXZ, Close)
+
+    add_submodule ()
     set_callbacks (OpenBzip2, Close)
     /* TODO: access shortnames for stream_UrlNew() */
 
@@ -408,3 +412,21 @@ static int OpenBzip2 (vlc_object_t *obj)
     return Open (stream, "bzcat");
 }
 
+/**
+ * Detects xz file format
+ */
+static int OpenXZ (vlc_object_t *obj)
+{
+    stream_t      *stream = (stream_t *)obj;
+    const uint8_t *peek;
+
+    /* (Try to) parse the xz stream header */
+    if (stream_Peek (stream->p_source, &peek, 8) < 8)
+        return VLC_EGENERIC;
+
+    if (memcmp (peek, "\xfd\x37\x7a\x58\x5a", 6))
+        return VLC_EGENERIC;
+
+    msg_Dbg (obj, "detected xz compressed stream");
+    return Open (stream, "xzcat");
+}