3 * Copyright (C) 2022 Andreas Rheinhardt
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavutil/error.h"
26 #include "libavutil/log.h"
27 #include "libavutil/mem.h"
28 #include "zlib_wrapper.h"
30 static void *alloc_wrapper(void *opaque
, uInt items
, uInt size
)
32 return av_malloc_array(items
, size
);
35 static void free_wrapper(void *opaque
, void *ptr
)
40 #if CONFIG_INFLATE_WRAPPER
41 int ff_inflate_init(FFZStream
*z
, void *logctx
)
43 z_stream
*const zstream
= &z
->zstream
;
47 zstream
->next_in
= Z_NULL
;
48 zstream
->avail_in
= 0;
49 zstream
->zalloc
= alloc_wrapper
;
50 zstream
->zfree
= free_wrapper
;
51 zstream
->opaque
= Z_NULL
;
53 zret
= inflateInit(zstream
);
57 av_log(logctx
, AV_LOG_ERROR
, "inflateInit error %d, message: %s\n",
58 zret
, zstream
->msg
? zstream
->msg
: "");
59 return AVERROR_EXTERNAL
;
64 void ff_inflate_end(FFZStream
*z
)
68 inflateEnd(&z
->zstream
);
73 #if CONFIG_DEFLATE_WRAPPER
74 int ff_deflate_init(FFZStream
*z
, int level
, void *logctx
)
76 z_stream
*const zstream
= &z
->zstream
;
80 zstream
->zalloc
= alloc_wrapper
;
81 zstream
->zfree
= free_wrapper
;
82 zstream
->opaque
= Z_NULL
;
84 zret
= deflateInit(zstream
, level
);
88 av_log(logctx
, AV_LOG_ERROR
, "deflateInit error %d, message: %s\n",
89 zret
, zstream
->msg
? zstream
->msg
: "");
90 return AVERROR_EXTERNAL
;
95 void ff_deflate_end(FFZStream
*z
)
99 deflateEnd(&z
->zstream
);