1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "config.h"
20
24
25 #if CONFIG_PTX_COMPRESSION
26 #include <zlib.h>
27 #define CHUNK_SIZE 1024 * 64
28 #endif
29
31
32 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, cu, x)
33
35 const unsigned char *
data,
const unsigned int length)
36 {
38
39 #if CONFIG_PTX_COMPRESSION
40 z_stream stream = { 0 };
42 uint64_t buf_size;
44
45 if (inflateInit2(&stream, 32 + 15) != Z_OK) {
48 }
49
52 if (!buf) {
53 inflateEnd(&stream);
55 }
56
57 stream.next_in =
data;
58 stream.avail_in = length;
59
60 do {
61 stream.avail_out = buf_size - stream.total_out;
62 stream.next_out = buf + stream.total_out;
63
65 if (
ret != Z_OK &&
ret != Z_STREAM_END &&
ret != Z_BUF_ERROR) {
67 inflateEnd(&stream);
70 }
71
72 if (stream.avail_out == 0) {
76 inflateEnd(&stream);
79 }
81 }
82 }
while (
ret != Z_STREAM_END);
83
84 // NULL-terminate string
85 // there is guaranteed to be space for this, due to condition in loop
86 buf[stream.total_out] = 0;
87
88 inflateEnd(&stream);
89
90 ret =
CHECK_CU(cu->cuModuleLoadData(cu_module, buf));
93 #else
95 #endif
96 }