Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/zlib_wrapper.c
Line
Count
Source
1
/*
2
 * Wrappers for zlib
3
 * Copyright (C) 2022 Andreas Rheinhardt
4
 *
5
 * This file is part of FFmpeg.
6
 *
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.
11
 *
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.
16
 *
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
20
 */
21
22
#include <zlib.h>
23
24
#include "config.h"
25
#include "libavutil/error.h"
26
#include "libavutil/log.h"
27
#include "libavutil/mem.h"
28
#include "zlib_wrapper.h"
29
30
static void *alloc_wrapper(void *opaque, uInt items, uInt size)
31
165k
{
32
165k
    return av_malloc_array(items, size);
33
165k
}
34
35
static void free_wrapper(void *opaque, void *ptr)
36
165k
{
37
165k
    av_free(ptr);
38
165k
}
39
40
#if CONFIG_INFLATE_WRAPPER
41
int ff_inflate_init(FFZStream *z, void *logctx)
42
105k
{
43
105k
    z_stream *const zstream = &z->zstream;
44
105k
    int zret;
45
46
105k
    z->inited = 0;
47
105k
    zstream->next_in  = Z_NULL;
48
105k
    zstream->avail_in = 0;
49
105k
    zstream->zalloc   = alloc_wrapper;
50
105k
    zstream->zfree    = free_wrapper;
51
105k
    zstream->opaque   = Z_NULL;
52
53
105k
    zret = inflateInit(zstream);
54
105k
    if (zret == Z_OK) {
55
105k
        z->inited = 1;
56
105k
    } else {
57
0
        av_log(logctx, AV_LOG_ERROR, "inflateInit error %d, message: %s\n",
58
0
               zret, zstream->msg ? zstream->msg : "");
59
0
        return AVERROR_EXTERNAL;
60
0
    }
61
105k
    return 0;
62
105k
}
63
64
void ff_inflate_end(FFZStream *z)
65
106k
{
66
106k
    if (z->inited) {
67
105k
        z->inited = 0;
68
105k
        inflateEnd(&z->zstream);
69
105k
    }
70
106k
}
71
#endif
72
73
#if CONFIG_DEFLATE_WRAPPER
74
int ff_deflate_init(FFZStream *z, int level, void *logctx)
75
6.55k
{
76
6.55k
    z_stream *const zstream = &z->zstream;
77
6.55k
    int zret;
78
79
6.55k
    z->inited = 0;
80
6.55k
    zstream->zalloc = alloc_wrapper;
81
6.55k
    zstream->zfree  = free_wrapper;
82
6.55k
    zstream->opaque = Z_NULL;
83
84
6.55k
    zret = deflateInit(zstream, level);
85
6.55k
    if (zret == Z_OK) {
86
6.55k
        z->inited = 1;
87
6.55k
    } else {
88
0
        av_log(logctx, AV_LOG_ERROR, "deflateInit error %d, message: %s\n",
89
0
               zret, zstream->msg ? zstream->msg : "");
90
0
        return AVERROR_EXTERNAL;
91
0
    }
92
6.55k
    return 0;
93
6.55k
}
94
95
void ff_deflate_end(FFZStream *z)
96
6.58k
{
97
6.58k
    if (z->inited) {
98
6.55k
        z->inited = 0;
99
6.55k
        deflateEnd(&z->zstream);
100
6.55k
    }
101
6.58k
}
102
#endif