From aabcccffd5ee9df435987401dacd2c0fe9b84f45 Mon Sep 17 00:00:00 2001
From: Moritz Bunkus <moritz@bunkus.org>
Date: Fri, 16 May 2008 12:06:21 +0000
Subject: [PATCH] The BZIP2 API usage was wrong. Patch by Aurelien Jacobs.

---
 AUTHORS                    | 1 +
 ChangeLog                  | 5 +++++
 src/common/compression.cpp | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index b3c5c9dc2..0e66afa56 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -18,6 +18,7 @@ Hakobyan, Sergey <sergey.hakobyan@viragelogic.com>
 
 Jacobs, Aurelien <aurel@gnuage.org>
     * Support for RealAudio v3 in RealMedia files
+    * Bugfixes (e.g. BZIP2 compression)
 
 Le Guen, Nicolas (Goldenear) <nleguen@pepper-prod.com>
     * Enhancements and updates to the "CUE sheet to tags & chapter
diff --git a/ChangeLog b/ChangeLog
index af40a7bd1..2d0ab47cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-05-16  Moritz Bunkus  <moritz@bunkus.org>
+
+	* mkvmerge: bug fix: Using BZIP2 compression resulted in broken
+	streams. Patch by Aurelien Jacobs (see AUTHORS).
+
 2008-05-15  Moritz Bunkus  <moritz@bunkus.org>
 
 	* mkvmerge: new feature: Improved support for WAV files bigger
diff --git a/src/common/compression.cpp b/src/common/compression.cpp
index fa6459b7c..644a49a22 100644
--- a/src/common/compression.cpp
+++ b/src/common/compression.cpp
@@ -229,8 +229,8 @@ bzlib_compressor_c::compress(memory_cptr &buffer) {
   c_stream.next_out = (char *)dst;
   c_stream.avail_in = size;
   c_stream.avail_out = 2 * size;
-  result = BZ2_bzCompress(&c_stream, BZ_FLUSH);
-  if (result != BZ_RUN_OK)
+  result = BZ2_bzCompress(&c_stream, BZ_FINISH);
+  if (result != BZ_STREAM_END)
     mxerror("bzip2 compression failed. Result: %d\n", result);
 
   BZ2_bzCompressEnd(&c_stream);