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
25
26 #if CONFIG_PTX_COMPRESSION
27 #include <zlib.h>
28 #define CHUNK_SIZE 1024 * 64
29 #endif
30
32
33 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, cu, x)
34
36 const unsigned char *
data,
const unsigned int length)
37 {
39
40 #if CONFIG_PTX_COMPRESSION
41 z_stream stream = { 0 };
43 uint64_t buf_size;
45
46 if (inflateInit2(&stream, 32 + 15) != Z_OK) {
49 }
50
53 if (!buf) {
54 inflateEnd(&stream);
56 }
57
58 stream.next_in =
data;
59 stream.avail_in = length;
60
61 do {
62 stream.avail_out = buf_size - stream.total_out;
63 stream.next_out = buf + stream.total_out;
64
66 if (
ret != Z_OK &&
ret != Z_STREAM_END &&
ret != Z_BUF_ERROR) {
68 inflateEnd(&stream);
71 }
72
73 if (stream.avail_out == 0) {
77 inflateEnd(&stream);
80 }
82 }
83 }
while (
ret != Z_STREAM_END);
84
85 // NULL-terminate string
86 // there is guaranteed to be space for this, due to condition in loop
87 buf[stream.total_out] = 0;
88
89 inflateEnd(&stream);
90
91 ret =
CHECK_CU(cu->cuModuleLoadData(cu_module, buf));
94 #else
96 #endif
97 }