1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block ) {
33 int result, dstsize, n;
38 d_stream.zalloc = (alloc_func)0;
39 d_stream.zfree = (free_func)0;
40 d_stream.opaque = (voidpf)0;
41 result = inflateInit(&d_stream);
44 msg_Dbg( p_this, "inflateInit() failed. Result: %d", result );
48 d_stream.next_in = (Bytef *)p_in_block->p_buffer;
49 d_stream.avail_in = p_in_block->i_buffer;
51 p_block = block_New( p_this, 0 );
56 p_block = block_Realloc( p_block, 0, n * 1000 );
57 dst = (unsigned char *)p_block->p_buffer;
58 d_stream.next_out = (Bytef *)&dst[(n - 1) * 1000];
59 d_stream.avail_out = 1000;
60 result = inflate(&d_stream, Z_NO_FLUSH);
61 if( ( result != Z_OK ) && ( result != Z_STREAM_END ) )
63 msg_Dbg( p_this, "Zlib decompression failed. Result: %d", result );
67 while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) &&
68 ( result != Z_STREAM_END ) );
70 dstsize = d_stream.total_out;
71 inflateEnd( &d_stream );
73 p_block = block_Realloc( p_block, 0, dstsize );
74 p_block->i_buffer = dstsize;
75 block_Release( p_in_block );