2 * Intel MediaSDK QSV codec-independent code
4 * copyright (c) 2013 Luca Barbato
5 * copyright (c) 2015 Anton Khirnov <anton@khirnov.net>
7 * This file is part of FFmpeg.
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/types.h>
27 #include <mfx/mfxvideo.h>
29 #include "libavutil/common.h"
30 #include "libavutil/hwcontext.h"
31 #include "libavutil/hwcontext_qsv.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/log.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/pixfmt.h"
37 #include "libavutil/time.h"
38 #include "libavutil/imgutils.h"
44 #include "qsv_internal.h"
47 const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = {
48 &(const AVCodecHWConfigInternal) {
50 .pix_fmt = AV_PIX_FMT_QSV,
51 .methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |
52 AV_CODEC_HW_CONFIG_METHOD_AD_HOC,
53 .device_type = AV_HWDEVICE_TYPE_QSV,
60 static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
64 ff_decode_frame_props(avctx, frame);
66 frame->width = avctx->width;
67 frame->height = avctx->height;
69 switch (avctx->pix_fmt) {
71 frame->linesize[0] = FFALIGN(avctx->width, 128);
74 frame->linesize[0] = 2 * FFALIGN(avctx->width, 128);
77 av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
78 return AVERROR(EINVAL);
81 frame->linesize[1] = frame->linesize[0];
82 frame->buf[0] = av_buffer_pool_get(pool);
84 return AVERROR(ENOMEM);
86 frame->data[0] = frame->buf[0]->data;
87 frame->data[1] = frame->data[0] +
88 frame->linesize[0] * FFALIGN(avctx->height, 64);
90 ret = ff_attach_decode_data(frame);
97 static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session,
98 AVBufferRef *hw_frames_ref, AVBufferRef *hw_device_ref)
102 if (q->gpu_copy == MFX_GPUCOPY_ON &&
103 !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
104 av_log(avctx, AV_LOG_WARNING, "GPU-accelerated memory copy "
105 "only works in system memory mode.\n");
106 q->gpu_copy = MFX_GPUCOPY_OFF;
109 q->session = session;
110 } else if (hw_frames_ref) {
111 if (q->internal_qs.session) {
112 MFXClose(q->internal_qs.session);
113 q->internal_qs.session = NULL;
115 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
117 q->frames_ctx.hw_frames_ctx = av_buffer_ref(hw_frames_ref);
118 if (!q->frames_ctx.hw_frames_ctx)
119 return AVERROR(ENOMEM);
121 ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
122 &q->frames_ctx, q->load_plugins,
123 q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
126 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
130 q->session = q->internal_qs.session;
131 } else if (hw_device_ref) {
132 if (q->internal_qs.session) {
133 MFXClose(q->internal_qs.session);
134 q->internal_qs.session = NULL;
137 ret = ff_qsv_init_session_device(avctx, &q->internal_qs.session,
138 hw_device_ref, q->load_plugins, q->gpu_copy);
142 q->session = q->internal_qs.session;
144 if (!q->internal_qs.session) {
145 ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
146 q->load_plugins, q->gpu_copy);
151 q->session = q->internal_qs.session;
154 /* make sure the decoder is uninitialized */
155 MFXVideoDECODE_Close(q->session);
160 static inline unsigned int qsv_fifo_item_size(void)
162 return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
165 static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
167 return av_fifo_size(fifo) / qsv_fifo_item_size();
170 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
172 mfxSession session = NULL;
175 enum AVPixelFormat pix_fmts[3] = {
176 AV_PIX_FMT_QSV, /* opaque format in case of video memory output */
177 pix_fmt, /* system memory format obtained from bitstream parser */
180 ret = ff_get_format(avctx, pix_fmts);
182 q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
186 if (!q->async_fifo) {
187 q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
189 return AVERROR(ENOMEM);
192 if (avctx->pix_fmt == AV_PIX_FMT_QSV && avctx->hwaccel_context) {
193 AVQSVContext *user_ctx = avctx->hwaccel_context;
194 session = user_ctx->session;
195 iopattern = user_ctx->iopattern;
196 q->ext_buffers = user_ctx->ext_buffers;
197 q->nb_ext_buffers = user_ctx->nb_ext_buffers;
200 if (avctx->hw_frames_ctx) {
201 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
202 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
205 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
206 iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
207 else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
208 iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
213 iopattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
214 q->iopattern = iopattern;
216 ff_qsv_print_iopattern(avctx, q->iopattern, "Decoder");
218 ret = qsv_init_session(avctx, q, session, avctx->hw_frames_ctx, avctx->hw_device_ctx);
220 av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
224 param->IOPattern = q->iopattern;
225 param->AsyncDepth = q->async_depth;
226 param->ExtParam = q->ext_buffers;
227 param->NumExtParam = q->nb_ext_buffers;
232 static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVideoParam *param)
236 avctx->width = param->mfx.FrameInfo.CropW;
237 avctx->height = param->mfx.FrameInfo.CropH;
238 avctx->coded_width = param->mfx.FrameInfo.Width;
239 avctx->coded_height = param->mfx.FrameInfo.Height;
240 avctx->level = param->mfx.CodecLevel;
241 avctx->profile = param->mfx.CodecProfile;
242 avctx->field_order = ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
243 avctx->pix_fmt = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
245 ret = MFXVideoDECODE_Init(q->session, param);
247 return ff_qsv_print_error(avctx, ret,
248 "Error initializing the MFX video decoder");
250 q->frame_info = param->mfx.FrameInfo;
252 if (!avctx->hw_frames_ctx)
253 q->pool = av_buffer_pool_init(av_image_get_buffer_size(avctx->pix_fmt,
254 FFALIGN(avctx->width, 128), FFALIGN(avctx->height, 64), 1), av_buffer_allocz);
258 static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
262 mfxBitstream bs = { 0 };
265 bs.Data = avpkt->data;
266 bs.DataLength = avpkt->size;
267 bs.MaxLength = bs.DataLength;
268 bs.TimeStamp = avpkt->pts;
269 if (avctx->field_order == AV_FIELD_PROGRESSIVE)
270 bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
272 return AVERROR_INVALIDDATA;
276 ret = qsv_decode_preinit(avctx, q, pix_fmt, param);
281 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
285 param->mfx.CodecId = ret;
286 ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, param);
287 if (MFX_ERR_MORE_DATA == ret) {
288 return AVERROR(EAGAIN);
291 return ff_qsv_print_error(avctx, ret,
292 "Error decoding stream header");
297 static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
302 ret = ff_qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
304 ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
309 if (frame->frame->format == AV_PIX_FMT_QSV) {
310 frame->surface = *(mfxFrameSurface1*)frame->frame->data[3];
312 frame->surface.Info = q->frame_info;
314 frame->surface.Data.PitchLow = frame->frame->linesize[0];
315 frame->surface.Data.Y = frame->frame->data[0];
316 frame->surface.Data.UV = frame->frame->data[1];
319 if (q->frames_ctx.mids) {
320 ret = ff_qsv_find_surface_idx(&q->frames_ctx, frame);
324 frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
326 frame->surface.Data.ExtParam = &frame->ext_param;
327 frame->surface.Data.NumExtParam = 1;
328 frame->ext_param = (mfxExtBuffer*)&frame->dec_info;
329 frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
330 frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
337 static void qsv_clear_unused_frames(QSVContext *q)
339 QSVFrame *cur = q->work_frames;
341 if (cur->used && !cur->surface.Data.Locked && !cur->queued) {
343 av_frame_unref(cur->frame);
349 static int get_surface(AVCodecContext *avctx, QSVContext *q, mfxFrameSurface1 **surf)
351 QSVFrame *frame, **last;
354 qsv_clear_unused_frames(q);
356 frame = q->work_frames;
357 last = &q->work_frames;
360 ret = alloc_frame(avctx, q, frame);
363 *surf = &frame->surface;
371 frame = av_mallocz(sizeof(*frame));
373 return AVERROR(ENOMEM);
374 frame->frame = av_frame_alloc();
377 return AVERROR(ENOMEM);
381 ret = alloc_frame(avctx, q, frame);
385 *surf = &frame->surface;
390 static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
392 QSVFrame *cur = q->work_frames;
394 if (surf == &cur->surface)
401 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
402 AVFrame *frame, int *got_frame,
406 mfxFrameSurface1 *insurf;
407 mfxFrameSurface1 *outsurf;
409 mfxBitstream bs = { { { 0 } } };
413 bs.Data = avpkt->data;
414 bs.DataLength = avpkt->size;
415 bs.MaxLength = bs.DataLength;
416 bs.TimeStamp = avpkt->pts;
417 if (avctx->field_order == AV_FIELD_PROGRESSIVE)
418 bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
421 sync = av_mallocz(sizeof(*sync));
424 return AVERROR(ENOMEM);
428 ret = get_surface(avctx, q, &insurf);
434 ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
435 insurf, &outsurf, sync);
436 if (ret == MFX_WRN_DEVICE_BUSY)
439 } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
441 if (ret != MFX_ERR_NONE &&
442 ret != MFX_ERR_MORE_DATA &&
443 ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
444 ret != MFX_ERR_MORE_SURFACE) {
446 return ff_qsv_print_error(avctx, ret,
447 "Error during QSV decoding.");
450 /* make sure we do not enter an infinite loop if the SDK
451 * did not consume any data and did not return anything */
452 if (!*sync && !bs.DataOffset) {
453 bs.DataOffset = avpkt->size;
454 ++q->zero_consume_run;
455 if (q->zero_consume_run > 1)
456 ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
457 } else if (!*sync && bs.DataOffset) {
460 q->zero_consume_run = 0;
464 QSVFrame *out_frame = find_frame(q, outsurf);
467 av_log(avctx, AV_LOG_ERROR,
468 "The returned surface does not correspond to any frame\n");
473 out_frame->queued = 1;
474 av_fifo_generic_write(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
475 av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL);
480 if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
481 (!avpkt->size && av_fifo_size(q->async_fifo))) {
484 av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
485 av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
486 out_frame->queued = 0;
488 if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
490 ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
491 } while (ret == MFX_WRN_IN_EXECUTION);
496 src_frame = out_frame->frame;
498 ret = av_frame_ref(frame, src_frame);
502 outsurf = &out_frame->surface;
505 FF_DISABLE_DEPRECATION_WARNINGS
506 frame->pkt_pts = outsurf->Data.TimeStamp;
507 FF_ENABLE_DEPRECATION_WARNINGS
509 frame->pts = outsurf->Data.TimeStamp;
512 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_TRIPLING ? 4 :
513 outsurf->Info.PicStruct & MFX_PICSTRUCT_FRAME_DOUBLING ? 2 :
514 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_REPEATED ? 1 : 0;
515 frame->top_field_first =
516 outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
517 frame->interlaced_frame =
518 !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
519 frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
520 //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
521 if (avctx->codec_id == AV_CODEC_ID_H264)
522 frame->key_frame = !!(out_frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
524 /* update the surface properties */
525 if (avctx->pix_fmt == AV_PIX_FMT_QSV)
526 ((mfxFrameSurface1*)frame->data[3])->Info = outsurf->Info;
531 return bs.DataOffset;
534 int ff_qsv_decode_close(QSVContext *q)
536 QSVFrame *cur = q->work_frames;
539 MFXVideoDECODE_Close(q->session);
541 while (q->async_fifo && av_fifo_size(q->async_fifo)) {
545 av_fifo_generic_read(q->async_fifo, &out_frame, sizeof(out_frame), NULL);
546 av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
552 q->work_frames = cur->next;
553 av_frame_free(&cur->frame);
555 cur = q->work_frames;
558 av_fifo_free(q->async_fifo);
559 q->async_fifo = NULL;
561 ff_qsv_close_internal_session(&q->internal_qs);
563 av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
564 av_buffer_unref(&q->frames_ctx.mids_buf);
565 av_buffer_pool_uninit(&q->pool);
570 int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
571 AVFrame *frame, int *got_frame, AVPacket *pkt)
574 mfxVideoParam param = { 0 };
575 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NV12;
578 return qsv_decode(avctx, q, frame, got_frame, pkt);
580 /* TODO: flush delayed frames on reinit */
582 // sw_pix_fmt, coded_width/height should be set for ff_get_format(),
583 // assume sw_pix_fmt is NV12 and coded_width/height to be 1280x720,
584 // the assumption may be not corret but will be updated after header decoded if not true.
585 if (q->orig_pix_fmt != AV_PIX_FMT_NONE)
586 pix_fmt = q->orig_pix_fmt;
587 if (!avctx->coded_width)
588 avctx->coded_width = 1280;
589 if (!avctx->coded_height)
590 avctx->coded_height = 720;
592 ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
594 if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
595 avctx->coded_width != param.mfx.FrameInfo.Width ||
596 avctx->coded_height != param.mfx.FrameInfo.Height)) {
597 AVPacket zero_pkt = {0};
599 if (q->buffered_count) {
601 /* decode zero-size pkt to flush the buffered pkt before reinit */
603 return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
607 q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
609 avctx->coded_width = param.mfx.FrameInfo.Width;
610 avctx->coded_height = param.mfx.FrameInfo.Height;
612 ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
618 if (!q->initialized) {
619 ret = qsv_decode_init_context(avctx, q, ¶m);
625 return qsv_decode(avctx, q, frame, got_frame, pkt);
628 q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
632 void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
634 q->orig_pix_fmt = AV_PIX_FMT_NONE;
644 typedef struct QSVDecContext {
650 AVFifoBuffer *packet_fifo;
655 static void qsv_clear_buffers(QSVDecContext *s)
658 while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
659 av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
660 av_packet_unref(&pkt);
663 av_packet_unref(&s->buffer_pkt);
666 static av_cold int qsv_decode_close(AVCodecContext *avctx)
668 QSVDecContext *s = avctx->priv_data;
670 av_freep(&s->qsv.load_plugins);
672 ff_qsv_decode_close(&s->qsv);
674 qsv_clear_buffers(s);
676 av_fifo_free(s->packet_fifo);
681 static av_cold int qsv_decode_init(AVCodecContext *avctx)
683 QSVDecContext *s = avctx->priv_data;
686 if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != LOAD_PLUGIN_NONE) {
687 static const char * const uid_hevcdec_sw = "15dd936825ad475ea34e35f3f54217a6";
688 static const char * const uid_hevcdec_hw = "33a61c0b4c27454ca8d85dde757c6f8e";
690 if (s->qsv.load_plugins[0]) {
691 av_log(avctx, AV_LOG_WARNING,
692 "load_plugins is not empty, but load_plugin is not set to 'none'."
693 "The load_plugin value will be ignored.\n");
695 av_freep(&s->qsv.load_plugins);
697 if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
698 s->qsv.load_plugins = av_strdup(uid_hevcdec_sw);
700 s->qsv.load_plugins = av_strdup(uid_hevcdec_hw);
701 if (!s->qsv.load_plugins)
702 return AVERROR(ENOMEM);
706 s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
707 s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
708 if (!s->packet_fifo) {
709 ret = AVERROR(ENOMEM);
715 qsv_decode_close(avctx);
719 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
720 int *got_frame, AVPacket *avpkt)
722 QSVDecContext *s = avctx->priv_data;
723 AVFrame *frame = data;
726 /* buffer the input packet */
730 if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
731 ret = av_fifo_realloc2(s->packet_fifo,
732 av_fifo_size(s->packet_fifo) + sizeof(input_ref));
737 ret = av_packet_ref(&input_ref, avpkt);
740 av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
743 /* process buffered data */
744 while (!*got_frame) {
745 /* prepare the input data */
746 if (s->buffer_pkt.size <= 0) {
748 if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
749 return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
750 /* in progress of reinit, no read from fifo and keep the buffer_pkt */
751 if (!s->qsv.reinit_flag) {
752 av_packet_unref(&s->buffer_pkt);
753 av_fifo_generic_read(s->packet_fifo, &s->buffer_pkt, sizeof(s->buffer_pkt), NULL);
757 ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
759 /* Drop buffer_pkt when failed to decode the packet. Otherwise,
760 the decoder will keep decoding the failure packet. */
761 av_packet_unref(&s->buffer_pkt);
764 if (s->qsv.reinit_flag)
767 s->buffer_pkt.size -= ret;
768 s->buffer_pkt.data += ret;
774 static void qsv_decode_flush(AVCodecContext *avctx)
776 QSVDecContext *s = avctx->priv_data;
778 qsv_clear_buffers(s);
779 ff_qsv_decode_flush(avctx, &s->qsv);
782 #define OFFSET(x) offsetof(QSVDecContext, x)
783 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
785 #define DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, opt) \
786 static const AVClass x##_qsv_class = { \
787 .class_name = #x "_qsv", \
788 .item_name = av_default_item_name, \
790 .version = LIBAVUTIL_VERSION_INT, \
792 AVCodec ff_##x##_qsv_decoder = { \
794 .long_name = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
795 .priv_data_size = sizeof(QSVDecContext), \
796 .type = AVMEDIA_TYPE_VIDEO, \
797 .id = AV_CODEC_ID_##X, \
798 .init = qsv_decode_init, \
799 .decode = qsv_decode_frame, \
800 .flush = qsv_decode_flush, \
801 .close = qsv_decode_close, \
803 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID, \
804 .priv_class = &x##_qsv_class, \
805 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, \
809 .hw_configs = ff_qsv_hw_configs, \
810 .wrapper_name = "qsv", \
813 #define DEFINE_QSV_DECODER(x, X, bsf_name) DEFINE_QSV_DECODER_WITH_OPTION(x, X, bsf_name, options)
815 #if CONFIG_HEVC_QSV_DECODER
816 static const AVOption hevc_options[] = {
817 { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
819 { "load_plugin", "A user plugin to load in an internal session", OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_HEVC_HW }, LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VD, "load_plugin" },
820 { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE }, 0, 0, VD, "load_plugin" },
821 { "hevc_sw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_SW }, 0, 0, VD, "load_plugin" },
822 { "hevc_hw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_HEVC_HW }, 0, 0, VD, "load_plugin" },
824 { "load_plugins", "A :-separate list of hexadecimal plugin UIDs to load in an internal session",
825 OFFSET(qsv.load_plugins), AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
827 { "gpu_copy", "A GPU-accelerated copy between video and system memory", OFFSET(qsv.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_DEFAULT }, MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, VD, "gpu_copy"},
828 { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
829 { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
830 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
833 DEFINE_QSV_DECODER_WITH_OPTION(hevc, HEVC, "hevc_mp4toannexb", hevc_options)
836 static const AVOption options[] = {
837 { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
839 { "gpu_copy", "A GPU-accelerated copy between video and system memory", OFFSET(qsv.gpu_copy), AV_OPT_TYPE_INT, { .i64 = MFX_GPUCOPY_DEFAULT }, MFX_GPUCOPY_DEFAULT, MFX_GPUCOPY_OFF, VD, "gpu_copy"},
840 { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_DEFAULT }, 0, 0, VD, "gpu_copy"},
841 { "on", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_ON }, 0, 0, VD, "gpu_copy"},
842 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_GPUCOPY_OFF }, 0, 0, VD, "gpu_copy"},
846 #if CONFIG_H264_QSV_DECODER
847 DEFINE_QSV_DECODER(h264, H264, "h264_mp4toannexb")