Proper usage of zlib for decompression.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11394 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
mosu 2003-11-05 15:04:50 +00:00
parent a0cb7264d9
commit fc386d59ca
1 changed files with 32 additions and 20 deletions

View File

@ -238,10 +238,6 @@ typedef struct mkv_track {
// Generic content encoding support. // Generic content encoding support.
vector<mkv_content_encoding_t> *c_encodings; vector<mkv_content_encoding_t> *c_encodings;
#ifdef HAVE_ZLIB
z_stream zstream;
bool zstream_initiated;
#endif
} mkv_track_t; } mkv_track_t;
typedef struct mkv_demuxer { typedef struct mkv_demuxer {
@ -719,7 +715,7 @@ static bool mkv_parse_idx(mkv_track_t *t) {
static bool reverse_encodings(mkv_track_t *track, unsigned char *&data, static bool reverse_encodings(mkv_track_t *track, unsigned char *&data,
uint32_t &size, uint32_t type) { uint32_t &size, uint32_t type) {
int new_size; int new_size, n;
unsigned char *new_data, *old_data; unsigned char *new_data, *old_data;
bool modified; bool modified;
vector<mkv_content_encoding_t>::iterator ce; vector<mkv_content_encoding_t>::iterator ce;
@ -738,33 +734,49 @@ static bool reverse_encodings(mkv_track_t *track, unsigned char *&data,
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
if (ce->comp_algo == 0) { if (ce->comp_algo == 0) {
int result; int result;
z_stream zstream;
old_data = new_data; old_data = new_data;
new_data = (unsigned char *)safemalloc(new_size * 20);
track->zstream.zalloc = (alloc_func)0; zstream.zalloc = (alloc_func)0;
track->zstream.zfree = (free_func)0; zstream.zfree = (free_func)0;
track->zstream.opaque = (voidpf)0; zstream.opaque = (voidpf)0;
inflateInit(&track->zstream); result = inflateInit(&zstream);
track->zstream.next_in = (Bytef *)old_data;
track->zstream.next_out = (Bytef *)new_data;
track->zstream.avail_in = new_size;
track->zstream.avail_out = 20 * new_size;
result = inflate(&track->zstream, Z_FULL_FLUSH);
if (result != Z_OK) { if (result != Z_OK) {
mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Zlib decompression failed. " mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Zlib initialization failed. "
"Result: %d\n", result); "Result: %d\n", result);
safefree(new_data); safefree(new_data);
data = old_data; data = old_data;
size = new_size; size = new_size;
inflateEnd(&track->zstream);
return modified; return modified;
} }
zstream.next_in = (Bytef *)old_data;
zstream.avail_in = new_size;
n = 0;
new_data = NULL;
do {
n++;
new_data = (unsigned char *)realloc(new_data, n * 4000);
zstream.next_out = (Bytef *)&new_data[(n - 1) * 4000];
zstream.avail_out = 4000;
result = inflate(&zstream, Z_NO_FLUSH);
if ((result != Z_OK) && (result != Z_STREAM_END)) {
mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Zlib decompression failed. "
"Result: %d \n", result);
safefree(new_data);
data = old_data;
size = new_size;
inflateEnd(&zstream);
return modified;
}
} while ((zstream.avail_out == 0) &&
(zstream.avail_in != 0) && (result != Z_STREAM_END));
mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] zlib decompression: from %d to " mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] zlib decompression: from %d to "
"%d\n", new_size, 20 * new_size - track->zstream.avail_out); "%d \n", new_size, zstream.total_out);
new_size = 20 * new_size - track->zstream.avail_out; new_size = zstream.total_out;
inflateEnd(&track->zstream); inflateEnd(&zstream);
if (modified) if (modified)
safefree(old_data); safefree(old_data);