Go to the documentation of this file.
44 #define DIV_UP(a, b) (((a) + (b)-1) / (b))
48 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
88 if (
s->hwctx &&
s->cu_module) {
89 CudaFunctions* cu =
s->hwctx->internal->cuda_dl;
92 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
93 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
130 s->own_frame->width =
width;
134 s->frames_ctx = out_ref;
159 if (!
ctx->inputs[0]->hw_frames_ctx) {
185 if (!
ctx->outputs[0]->hw_frames_ctx)
194 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
195 CudaFunctions* cu =
s->hwctx->internal->cuda_dl;
198 extern const unsigned char ff_vf_colorspace_cuda_ptx_data[];
199 extern const unsigned int ff_vf_colorspace_cuda_ptx_len;
206 ff_vf_colorspace_cuda_ptx_data,
207 ff_vf_colorspace_cuda_ptx_len);
234 s->hwctx = device_hwctx;
235 s->cu_stream =
s->hwctx->stream;
244 if (
inlink->sample_aspect_ratio.num) {
247 inlink->sample_aspect_ratio);
262 CudaFunctions* cu =
s->hwctx->internal->cuda_dl;
263 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
270 out->color_range =
s->range;
272 for (
int i = 0;
i <
s->num_planes;
i++) {
275 switch (
s->pix_fmt) {
290 if (!
s->cu_convert[
out->color_range]) {
332 s->own_frame->width = outlink->
w;
333 s->own_frame->height = outlink->
h;
347 CudaFunctions* cu =
s->hwctx->internal->cuda_dl;
359 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
369 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
382 #define OFFSET(x) offsetof(CUDAColorspaceContext, x)
383 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
417 .
name =
"colorspace_cuda",
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
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
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
static av_cold int cudacolorspace_config_props(AVFilterLink *outlink)
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 necessary.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold void cudacolorspace_uninit(AVFilterContext *ctx)
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
@ AVCOL_RANGE_JPEG
Full range content.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
CUfunction cu_convert[AVCOL_RANGE_NB]
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
enum AVPixelFormat pix_fmt
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static int format_is_supported(enum AVPixelFormat fmt)
@ AVCOL_RANGE_NB
Not part of ABI.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
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 link
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
static int cudacolorspace_conv(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
@ AVCOL_RANGE_UNSPECIFIED
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat supported_formats[]
AVFilterContext * src
source filter
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define i(width, name, range_min, range_max)
static const AVFilterPad cudacolorspace_inputs[]
int w
agreed upon image width
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static av_cold int init_hwframe_ctx(CUDAColorspaceContext *s, AVBufferRef *device_ctx, int width, int height)
const char * name
Pad name.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
const AVFilter ff_vf_colorspace_cuda
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold int cudacolorspace_init(AVFilterContext *ctx)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
int h
agreed upon image height
static int cudacolorspace_filter_frame(AVFilterLink *link, AVFrame *in)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
A reference to a data buffer.
static int conv_cuda_convert(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
#define FILTER_OUTPUTS(array)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static const AVClass cudacolorspace_class
static const AVFilterPad cudacolorspace_outputs[]
static av_cold int cudacolorspace_load_functions(AVFilterContext *ctx)
AVColorRange
Visual content value range.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
AVCUDADeviceContext * hwctx
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
static const AVOption options[]