FFmpeg: libavfilter/vf_transpose_npp.c Source File
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 <nppi.h>
20 #include <stdio.h>
21 #include <string.h>
22
30
35
36 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
37
41 };
42
47 };
48
54 };
55
60 };
61
66 struct {
73
78
79 int passthrough;
///< PassthroughType, landscape passthrough mode enabled
80 int dir;
///< TransposeDir
82
84 {
87
90 if (!
s->stages[
i].frame)
92 }
93
97
98 return 0;
99 }
100
102 {
105
109 }
110
112 }
113
115 {
118 int in_sw, in_sh, out_sw, out_sh;
120
123
127 }
128
134 }
135
137 if (!out_ref)
140
145
149
154
159
160 return 0;
161
165 }
166
168 {
170
173 return 1;
174
175 return 0;
176 }
177
179 int out_width, int out_height)
180 {
184 int i,
ret, last_stage = -1;
185 int rot_width = out_width, rot_height = out_height;
186
187 /* check that we have a hw context */
188 if (!
ctx->inputs[0]->hw_frames_ctx) {
191 }
192
195
200 }
201
204 }
205
208
209 /* Rotating by 180° in case of clock_flip, or not at all for cclock_flip, so width/height unchanged by rotation */
210 rot_width = in_width;
211 rot_height = in_height;
212 }
213
226
227 /* init the hardware contexts */
229 if (!
s->stages[
i].stage_needed)
230 continue;
235 }
236
237 if (last_stage >= 0) {
238 ctx->outputs[0]->hw_frames_ctx =
av_buffer_ref(
s->stages[last_stage].frames_ctx);
239 } else {
242 }
243
244 if (!
ctx->outputs[0]->hw_frames_ctx)
246
247 return 0;
248 }
249
251 {
256
259 {
260 if (
inlink->hw_frames_ctx) {
264 }
265
267 "w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
269 return 0;
270 } else {
272 }
273
277
281
284
285 return 0;
286 }
287
290 {
292 NppStatus err;
294
300
301 // nppRotate uses 0,0 as the rotation point
302 // need to shift the image accordingly after rotation
303 // need to substract 1 to get the correct coordinates
307
308 err = nppiRotate_8u_C1R(in->
data[
i], (NppiSize){ iw, ih },
309 in->
linesize[
i], (NppiRect){ 0, 0, iw, ih },
311 (NppiRect){ 0, 0, ow, oh },
312 angle, shiftw, shifth, NPPI_INTER_NN);
313 if (err != NPP_SUCCESS) {
316 }
317 }
318
319 return 0;
320 }
321
324 {
325 NppStatus err;
327
331
334 (NppiSize){ iw, ih });
335 if (err != NPP_SUCCESS) {
338 }
339 }
340
341 return 0;
342 }
343
348 };
349
351 {
354 int i,
ret, last_stage = -1;
355
357 if (!
s->stages[
i].stage_needed)
358 continue;
359
363
364 src =
s->stages[
i].frame;
366 }
367
368 if (last_stage < 0)
370
374
377
381
382 return 0;
383 }
384
386 {
395
398
403 }
404
405 ret =
CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
408
410
411 CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&
dummy));
414
416
418
423 }
424
425 #define OFFSET(x) offsetof(NPPTransposeContext, x)
426 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
427
439 };
440
446 };
447
449 {
453 },
454 };
455
457 {
461 },
462 };
463
465 .
name =
"transpose_npp",
475 };
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
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
static int npptranspose_filter(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static int npptranspose_init(AVFilterContext *ctx)
#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.
static const AVClass npptranspose_class
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
static enum AVPixelFormat supported_formats[]
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.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
static const AVOption options[]
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
static int init_stage(NPPTransposeStageContext *stage, AVBufferRef *device_ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const AVFilter ff_vf_transpose_npp
static int npptranspose_config_props(AVFilterLink *outlink)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
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)
struct NPPTransposeStageContext::@243 planes_out[3]
struct NPPTransposeStageContext::@243 planes_in[3]
static int npptranspose_rotate(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int format_is_supported(enum AVPixelFormat fmt)
@ 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.
const char * av_default_item_name(void *ptr)
Return the context name.
static int(*const npptranspose_process[])(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
@ NPP_TRANSPOSE_PT_TYPE_PORTRAIT
@ NPP_TRANSPOSE_PT_TYPE_LANDSCAPE
static void npptranspose_uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum AVPixelFormat out_fmt
enum AVPixelFormat in_fmt
AVFilterContext * src
source filter
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
@ NPP_TRANSPOSE_CLOCK_FLIP
#define i(width, name, range_min, range_max)
int passthrough
PassthroughType, landscape passthrough mode enabled.
NPPTransposeStageContext stages[STAGE_NB]
int w
agreed upon image width
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
static const AVFilterPad npptranspose_outputs[]
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.
const char * name
Pad name.
static int npptranspose_transpose(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
int h
agreed upon image height
static int npptranspose_filter_frame(AVFilterLink *link, AVFrame *in)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ NPP_TRANSPOSE_PT_TYPE_NONE
A reference to a data buffer.
#define FILTER_OUTPUTS(array)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ NPP_TRANSPOSE_CCLOCK_FLIP
static const AVFilterPad npptranspose_inputs[]
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
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.
Generated on Wed Aug 24 2022 21:42:10 for FFmpeg by
doxygen
1.8.17