FFmpeg
load_helper.c
Go to the documentation of this file.
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 
21 #include "libavutil/hwcontext.h"
23 #include "libavutil/cuda_check.h"
24 
25 #if CONFIG_PTX_COMPRESSION
26 #include <zlib.h>
27 #define CHUNK_SIZE 1024 * 64
28 #endif
29 
30 #include "load_helper.h"
31 
32 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, cu, x)
33 
34 int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module,
35  const unsigned char *data, const unsigned int length)
36 {
37  CudaFunctions *cu = hwctx->internal->cuda_dl;
38 
39 #if CONFIG_PTX_COMPRESSION
40  z_stream stream = { 0 };
41  uint8_t *buf, *tmp;
42  uint64_t buf_size;
43  int ret;
44 
45  if (inflateInit2(&stream, 32 + 15) != Z_OK) {
46  av_log(avctx, AV_LOG_ERROR, "Error during zlib initialisation: %s\n", stream.msg);
47  return AVERROR(ENOSYS);
48  }
49 
50  buf_size = CHUNK_SIZE * 4;
51  buf = av_realloc(NULL, buf_size);
52  if (!buf) {
53  inflateEnd(&stream);
54  return AVERROR(ENOMEM);
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 
64  ret = inflate(&stream, Z_FINISH);
65  if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
66  av_log(avctx, AV_LOG_ERROR, "zlib inflate error(%d): %s\n", ret, stream.msg);
67  inflateEnd(&stream);
68  av_free(buf);
69  return AVERROR(EINVAL);
70  }
71 
72  if (stream.avail_out == 0) {
73  buf_size += CHUNK_SIZE;
74  tmp = av_realloc(buf, buf_size);
75  if (!tmp) {
76  inflateEnd(&stream);
77  av_free(buf);
78  return AVERROR(ENOMEM);
79  }
80  buf = tmp;
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));
91  av_free(buf);
92  return ret;
93 #else
94  return CHECK_CU(cu->cuModuleLoadData(cu_module, data));
95 #endif
96 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
hwcontext_cuda_internal.h
CHUNK_SIZE
#define CHUNK_SIZE
Definition: act.c:28
ff_cuda_load_module
int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module, const unsigned char *data, const unsigned int length)
Loads a CUDA module and applies any decompression, if neccesary.
Definition: load_helper.c:34
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
data
const char data[16]
Definition: mxf.c:148
CHECK_CU
#define CHECK_CU(x)
Definition: load_helper.c:32
inflate
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
Definition: vf_neighbor.c:194
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
load_helper.h
NULL
#define NULL
Definition: coverity.c:32
AVCUDADeviceContext::internal
AVCUDADeviceContextInternal * internal
Definition: hwcontext_cuda.h:45
AVCUDADeviceContextInternal::cuda_dl
CudaFunctions * cuda_dl
Definition: hwcontext_cuda_internal.h:32
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
ret
ret
Definition: filter_design.txt:187
cuda_check.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153