]> git.sesse.net Git - vlc/blob - modules/demux/mkv/util.cpp
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / demux / mkv / util.cpp
1 /*****************************************************************************
2  * mkv.cpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Steve Lhomme <steve.lhomme@free.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "util.hpp"
26
27 /*****************************************************************************
28  * Local prototypes
29  *****************************************************************************/
30
31 #ifdef HAVE_ZLIB_H
32 block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block ) {
33     int result, dstsize, n;
34     unsigned char *dst;
35     block_t *p_block;
36     z_stream d_stream;
37
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);
42     if( result != Z_OK )
43     {
44         msg_Dbg( p_this, "inflateInit() failed. Result: %d", result );
45         return NULL;
46     }
47
48     d_stream.next_in = (Bytef *)p_in_block->p_buffer;
49     d_stream.avail_in = p_in_block->i_buffer;
50     n = 0;
51     p_block = block_New( p_this, 0 );
52     dst = NULL;
53     do
54     {
55         n++;
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 ) )
62         {
63             msg_Dbg( p_this, "Zlib decompression failed. Result: %d", result );
64             return NULL;
65         }
66     }
67     while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) &&
68            ( result != Z_STREAM_END ) );
69
70     dstsize = d_stream.total_out;
71     inflateEnd( &d_stream );
72
73     p_block = block_Realloc( p_block, 0, dstsize );
74     p_block->i_buffer = dstsize;
75     block_Release( p_in_block );
76
77     return p_block;
78 }
79 #endif
80
81