24 #include <mfx/mfxvideo.h> 71 mfxExtBuffer *ext_buffers[1];
119 static mfxStatus
frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
120 mfxFrameAllocResponse *resp)
125 if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
126 !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
127 !(req->Type & MFX_MEMTYPE_EXTERNAL_FRAME))
128 return MFX_ERR_UNSUPPORTED;
136 static mfxStatus
frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
141 static mfxStatus
frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
143 return MFX_ERR_UNSUPPORTED;
146 static mfxStatus
frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
148 return MFX_ERR_UNSUPPORTED;
158 MFX_HANDLE_VA_DISPLAY,
159 MFX_HANDLE_D3D9_DEVICE_MANAGER,
160 MFX_HANDLE_D3D11_DEVICE,
171 int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
173 mfxHDL handle =
NULL;
182 err = MFXQueryIMPL(device_hwctx->session, &impl);
183 if (err == MFX_ERR_NONE)
184 err = MFXQueryVersion(device_hwctx->session, &ver);
185 if (err != MFX_ERR_NONE) {
191 err = MFXVideoCORE_GetHandle(device_hwctx->session,
handle_types[i], &handle);
192 if (err == MFX_ERR_NONE) {
200 err = MFXInit(impl, &ver, &s->
session);
201 if (err != MFX_ERR_NONE) {
207 err = MFXVideoCORE_SetHandle(s->
session, handle_type, handle);
208 if (err != MFX_ERR_NONE)
212 memset(&par, 0,
sizeof(par));
219 for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
229 s->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
237 par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
239 mfxFrameAllocator frame_allocator = {
252 for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
253 s->
mem_ids[i] = hw_frames_hwctx->surfaces[i].Data.MemId;
256 err = MFXVideoCORE_SetFrameAllocator(s->
session, &frame_allocator);
257 if (err != MFX_ERR_NONE)
260 par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
265 par.vpp.In = hw_frames_hwctx->surfaces[0].Info;
267 par.vpp.In.CropW = ctx->
inputs[0]->
w;
268 par.vpp.In.CropH = ctx->
inputs[0]->
h;
278 par.vpp.Out = par.vpp.In;
288 err = MFXVideoVPP_Init(s->
session, &par);
289 if (err != MFX_ERR_NONE) {
341 if (!cur->
surface.Data.Locked) {
397 MFX_PICSTRUCT_FIELD_BFF);
399 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
401 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
403 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
424 mfxFrameSurface1 *surf_in)
431 mfxFrameSurface1 *surf_out;
444 surf_out = (mfxFrameSurface1*)out->
data[3];
445 surf_out->Info.CropW = outlink->
w;
446 surf_out->Info.CropH = outlink->
h;
447 surf_out->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
450 err = MFXVideoVPP_RunFrameVPPAsync(s->
session, surf_in, surf_out,
452 if (err == MFX_WRN_DEVICE_BUSY)
454 }
while (err == MFX_WRN_DEVICE_BUSY);
456 if (err == MFX_ERR_MORE_DATA) {
461 if ((err < 0 && err != MFX_ERR_MORE_SURFACE) || !
sync) {
466 if (err == MFX_ERR_MORE_SURFACE)
470 err = MFXVideoCORE_SyncOperation(s->session,
sync, 1000);
471 }
while (err == MFX_WRN_IN_EXECUTION);
482 out->width = outlink->w;
483 out->height = outlink->h;
484 out->interlaced_frame = 0;
487 if (
out->pts == s->last_pts)
489 s->last_pts =
out->pts;
505 mfxFrameSurface1 *surf_in;
536 #define OFFSET(x) offsetof(QSVDeintContext, x) 537 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM 569 .
name =
"deinterlace_qsv",
576 .priv_class = &qsvdeint_class,
578 .
inputs = qsvdeint_inputs,
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
static int get_free_frame(QSVDeintContext *s, QSVFrame **f)
static const AVClass qsvdeint_class
static const AVFilterPad qsvdeint_inputs[]
static const AVFilterPad outputs[]
Main libavfilter public API header.
mfxHandleType handle_type
This struct is allocated as AVHWFramesContext.hwctx.
int h
agreed upon image height
int repeat_pict
When decoding, this signals how much the picture must be delayed.
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int sync(AVFormatContext *s, uint8_t *header)
Read input until we find the next ident.
#define FF_ARRAY_ELEMS(a)
mfxFrameSurface1 * surface
int av_usleep(unsigned usec)
Sleep for a period of time.
static int qsvdeint_request_frame(AVFilterLink *outlink)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int qsvdeint_query_formats(AVFilterContext *ctx)
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int process_frame(AVFilterContext *ctx, const AVFrame *in, mfxFrameSurface1 *surf_in)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static void qsvdeint_uninit(AVFilterContext *ctx)
static int qsvdeint_config_props(AVFilterLink *outlink)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static int qsvdeint_filter_frame(AVFilterLink *link, AVFrame *in)
int interlaced_frame
The content of the picture is interlaced.
static mfxStatus frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
This struct is allocated as AVHWDeviceContext.hwctx.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
mfxExtBuffer * ext_buffers[1]
void * priv
private data for use by the filter
AVFilter ff_vf_deinterlace_qsv
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static mfxStatus frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
int w
agreed upon image width
common internal API header
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
AVBufferRef * hw_frames_ctx
AVFilterContext * src
source filter
static const mfxHandleType handle_types[]
static void clear_unused_frames(QSVDeintContext *s)
static const AVOption options[]
uint8_t * data
The data buffer.
static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, mfxFrameAllocResponse *resp)
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
static int submit_frame(AVFilterContext *ctx, AVFrame *frame, mfxFrameSurface1 **surface)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
rational number numerator/denominator
This struct describes a set or pool of "hardware" frames (i.e.
static const AVFilterPad qsvdeint_outputs[]
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
mfxFrameSurface1 ** surface_ptrs
A reference to a data buffer.
common internal and external API header
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int top_field_first
If the content is interlaced, is top field displayed first.
mfxExtOpaqueSurfaceAlloc opaque_alloc
AVFilterContext * dst
dest filter
static void * av_mallocz_array(size_t nmemb, size_t size)
An API-specific header for AV_HWDEVICE_TYPE_QSV.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
AVPixelFormat
Pixel format.
static int init_out_session(AVFilterContext *ctx)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_NOPTS_VALUE
Undefined timestamp value.