Go to the documentation of this file.
34 typedef struct API_AVAILABLE(macos(10.11),
ios(8.0)) YADIFVTContext {
41 id<MTLDevice> mtlDevice;
42 id<MTLLibrary> mtlLibrary;
43 id<MTLCommandQueue> mtlQueue;
44 id<MTLComputePipelineState> mtlPipeline;
45 id<MTLFunction> mtlFunction;
46 id<MTLBuffer> mtlParamsBuffer;
48 CVMetalTextureCacheRef textureCache;
49 } YADIFVTContext API_AVAILABLE(macos(10.11),
ios(8.0));
54 #define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10)
56 struct mtlYadifParams {
61 bool skip_spatial_check;
72 int tff) API_AVAILABLE(macos(10.11),
ios(8.0))
74 YADIFVTContext *
s =
ctx->priv;
75 id<MTLCommandBuffer>
buffer =
s->mtlQueue.commandBuffer;
76 id<MTLComputeCommandEncoder> encoder =
buffer.computeCommandEncoder;
77 struct mtlYadifParams *params = (
struct mtlYadifParams *)
s->mtlParamsBuffer.contents;
78 *params = (
struct mtlYadifParams){
82 .is_second_field = !(
parity ^ tff),
83 .skip_spatial_check =
s->yadif.mode&2,
84 .field_mode =
s->yadif.current_field
87 [encoder setTexture:dst atIndex:0];
88 [encoder setTexture:prev atIndex:1];
89 [encoder setTexture:cur atIndex:2];
90 [encoder setTexture:next atIndex:3];
91 [encoder setBuffer:s->mtlParamsBuffer offset:0 atIndex:4];
93 [encoder endEncoding];
96 [buffer waitUntilCompleted];
103 int parity,
int tff) API_AVAILABLE(macos(10.11),
ios(8.0))
105 YADIFVTContext *
s =
ctx->priv;
112 CVMetalTextureRef prev, cur, next, dest;
113 id<MTLTexture> tex_prev, tex_cur, tex_next, tex_dest;
116 if (
comp->plane <
i) {
122 pixel_size = (
comp->depth +
comp->shift) / 8;
128 switch (pixel_size) {
130 format =
channels == 1 ? MTLPixelFormatR8Unorm : MTLPixelFormatRG8Unorm;
133 format =
channels == 1 ? MTLPixelFormatR16Unorm : MTLPixelFormatRG16Unorm;
140 "Deinterlacing plane %d: pixel_size: %d channels: %d\n",
148 tex_prev = CVMetalTextureGetTexture(prev);
149 tex_cur = CVMetalTextureGetTexture(cur);
150 tex_next = CVMetalTextureGetTexture(next);
151 tex_dest = CVMetalTextureGetTexture(dest);
162 CVBufferPropagateAttachments((CVPixelBufferRef)y->
cur->
data[3], (CVPixelBufferRef)dst->data[3]);
174 YADIFVTContext *
s =
ctx->priv;
183 s->input_frames =
NULL;
192 if (
s->textureCache) {
193 CFRelease(
s->textureCache);
194 s->textureCache =
NULL;
201 if (@
available(macOS 10.11, iOS 8.0, *)) {
208 YADIFVTContext *
s =
ctx->priv;
212 s->mtlDevice = MTLCreateSystemDefaultDevice();
220 dispatch_data_t libData = dispatch_data_create(
225 s->mtlLibrary = [s->mtlDevice newLibraryWithData:libData error:&err];
226 dispatch_release(libData);
233 s->mtlFunction = [s->mtlLibrary newFunctionWithName:@"deint"];
234 if (!
s->mtlFunction) {
239 s->mtlQueue =
s->mtlDevice.newCommandQueue;
245 s->mtlPipeline = [s->mtlDevice
246 newComputePipelineStateWithFunction:s->mtlFunction
249 av_log(
ctx,
AV_LOG_ERROR,
"Failed to create Metal compute pipeline: %s\n", err.description.UTF8String);
253 s->mtlParamsBuffer = [s->mtlDevice
254 newBufferWithLength:sizeof(struct mtlYadifParams)
255 options:MTLResourceStorageModeShared];
256 if (!
s->mtlParamsBuffer) {
261 ret = CVMetalTextureCacheCreate(
268 if (
ret != kCVReturnSuccess) {
275 yadif_videotoolbox_uninit(
ctx);
281 if (@
available(macOS 10.11, iOS 8.0, *)) {
283 static_assert(
YADIF_VT_CTX_SIZE ==
sizeof(YADIFVTContext),
"Incorrect YADIF_VT_CTX_SIZE value!");
294 YADIFVTContext *
s =
ctx->priv;
296 if (!
inlink->hw_frames_ctx) {
298 "required to associate the processing device.\n");
303 if (!
s->input_frames_ref) {
316 if (@
available(macOS 10.11, iOS 8.0, *)) {
317 return do_config_input(
inlink);
328 YADIFVTContext *
s =
ctx->priv;
334 if (!
s->device_ref) {
351 output_frames->
sw_format =
s->input_frames->sw_format;
352 output_frames->
width =
ctx->inputs[0]->w;
353 output_frames->
height =
ctx->inputs[0]->h;
362 "context for output: %d\n",
ret);
391 if (@
available(macOS 10.11, iOS 8.0, *)) {
392 return do_config_output(
link);
399 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
400 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
402 static const AVOption yadif_videotoolbox_options[] = {
403 #define OFFSET(x) offsetof(YADIFContext, x)
425 static const AVFilterPad yadif_videotoolbox_inputs[] = {
434 static const AVFilterPad yadif_videotoolbox_outputs[] = {
444 .
name =
"yadif_videotoolbox",
447 .priv_class = &yadif_videotoolbox_class,
448 .init = yadif_videotoolbox_init,
449 .uninit = yadif_videotoolbox_uninit,
@ YADIF_MODE_SEND_FIELD
send 1 frame for each field
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...
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
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
const AVPixFmtDescriptor * csp
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.
static void ff_objc_release(NSObject **obj)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
@ YADIF_MODE_SEND_FRAME
send 1 frame for each frame
@ YADIF_MODE_SEND_FIELD_NOSPATIAL
send 1 frame for each field but skips spatial interlacing check
@ YADIF_PARITY_AUTO
auto detection
@ YADIF_MODE_SEND_FRAME_NOSPATIAL
send 1 frame for each frame but skips spatial interlacing check
const AVFilter ff_vf_yadif_videotoolbox
A filter pad used for either input or output.
static int config_output(AVFilterLink *outlink)
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
#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
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
static int config_input(AVFilterLink *inlink)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
uint8_t nb_components
The number of components each pixel has, (1-4)
Rational number (pair of numerator and denominator).
CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass, CVMetalTextureCacheRef textureCache, CVPixelBufferRef pixbuf, int plane, MTLPixelFormat format) API_AVAILABLE(macos(10.11)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void(* filter)(AVFilterContext *ctx, AVFrame *dstpic, int parity, int tff)
AVRational time_base
Time base for the timestamps in this frame.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_INFO
Standard information.
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
static CUresult call_kernel(AVFilterContext *ctx, CUfunction func, CUdeviceptr prev, CUdeviceptr cur, CUdeviceptr next, CUarray_format format, int channels, int src_width, int src_height, int src_pitch, CUdeviceptr dst, int dst_width, int dst_height, int dst_pitch, int parity, int tff)
#define i(width, name, range_min, range_max)
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
@ YADIF_DEINT_ALL
deinterlace all frames
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
@ YADIF_FIELD_END
The first or last field in a sequence.
int ff_yadif_request_frame(AVFilterLink *link)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ YADIF_DEINT_INTERLACED
only deinterlace frames marked as interlaced
@ YADIF_FIELD_NORMAL
A normal field in the middle of a sequence.
@ YADIF_PARITY_TFF
top field first
A reference to a data buffer.
int current_field
YADIFCurrentField.
#define FILTER_OUTPUTS(array)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
void ff_metal_compute_encoder_dispatch(id< MTLDevice > device, id< MTLComputePipelineState > pipeline, id< MTLComputeCommandEncoder > encoder, NSUInteger width, NSUInteger height) API_AVAILABLE(macos(10.11)
int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
@ YADIF_PARITY_BFF
bottom field first
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.