2015-03-13 09:13:00 +02:00
|
|
|
/*
|
|
|
|
* Intel MediaSDK QSV encoder/decoder shared code
|
|
|
|
*
|
2015-03-28 02:16:21 +02:00
|
|
|
* This file is part of FFmpeg.
|
2015-03-13 09:13:00 +02:00
|
|
|
*
|
2015-03-28 02:16:21 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2015-03-13 09:13:00 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-28 02:16:21 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2015-03-13 09:13:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2015-03-28 02:16:21 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2015-03-13 09:13:00 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_QSV_INTERNAL_H
|
|
|
|
#define AVCODEC_QSV_INTERNAL_H
|
|
|
|
|
2020-05-31 10:12:36 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2023-04-14 16:39:06 +02:00
|
|
|
#if CONFIG_VAAPI && !defined(_WIN32) // Do not enable for libva-win32 on Windows
|
2019-09-19 22:45:26 +02:00
|
|
|
#define AVCODEC_QSV_LINUX_SESSION_HANDLE
|
2023-04-14 16:39:06 +02:00
|
|
|
#endif //CONFIG_VAAPI && !defined(_WIN32)
|
2019-09-19 22:45:26 +02:00
|
|
|
|
|
|
|
#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <va/va.h>
|
|
|
|
#include "libavutil/hwcontext_vaapi.h"
|
|
|
|
#endif
|
|
|
|
|
2020-09-08 05:17:27 +02:00
|
|
|
#include <mfxvideo.h>
|
2015-03-13 11:20:31 +02:00
|
|
|
|
|
|
|
#include "libavutil/frame.h"
|
|
|
|
|
2016-02-15 19:49:29 +02:00
|
|
|
#include "avcodec.h"
|
|
|
|
|
2015-03-13 09:13:00 +02:00
|
|
|
#define QSV_VERSION_MAJOR 1
|
2016-10-21 19:57:12 +02:00
|
|
|
#define QSV_VERSION_MINOR 1
|
2015-03-13 09:13:00 +02:00
|
|
|
|
|
|
|
#define ASYNC_DEPTH_DEFAULT 4 // internal parallelism
|
|
|
|
|
2015-10-27 19:08:45 +02:00
|
|
|
#define QSV_MAX_ENC_PAYLOAD 2 // # of mfxEncodeCtrl payloads supported
|
2022-10-18 06:59:24 +02:00
|
|
|
#define QSV_MAX_ENC_EXTPARAM 8 // # of mfxEncodeCtrl extparam supported
|
2022-06-08 07:02:48 +02:00
|
|
|
|
|
|
|
#define QSV_MAX_ROI_NUM 256
|
2015-10-27 19:08:45 +02:00
|
|
|
|
2022-01-24 10:24:53 +02:00
|
|
|
#define QSV_MAX_FRAME_EXT_PARAMS 4
|
|
|
|
|
2015-06-16 18:22:11 +02:00
|
|
|
#define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
|
|
|
|
(MFX_VERSION_MAJOR > (MAJOR) || \
|
|
|
|
MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
|
|
|
|
|
2018-04-02 15:17:23 +02:00
|
|
|
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
|
2019-03-27 12:18:15 +02:00
|
|
|
((MFX_VERSION.Major > (MAJOR)) || \
|
|
|
|
(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
|
2018-04-02 15:17:23 +02:00
|
|
|
|
2020-08-18 09:20:38 +02:00
|
|
|
#define QSV_ONEVPL QSV_VERSION_ATLEAST(2, 0)
|
2020-08-19 03:43:12 +02:00
|
|
|
#define QSV_HAVE_OPAQUE !QSV_ONEVPL
|
2020-08-18 09:20:38 +02:00
|
|
|
|
2016-08-10 08:29:23 +02:00
|
|
|
typedef struct QSVMid {
|
2016-08-10 09:38:21 +02:00
|
|
|
AVBufferRef *hw_frames_ref;
|
2021-08-20 23:48:02 +02:00
|
|
|
mfxHDLPair *handle_pair;
|
2016-08-10 09:38:21 +02:00
|
|
|
|
|
|
|
AVFrame *locked_frame;
|
|
|
|
AVFrame *hw_frame;
|
|
|
|
mfxFrameSurface1 surf;
|
2016-08-10 08:29:23 +02:00
|
|
|
} QSVMid;
|
|
|
|
|
2015-03-13 11:20:31 +02:00
|
|
|
typedef struct QSVFrame {
|
|
|
|
AVFrame *frame;
|
2016-08-09 12:05:49 +02:00
|
|
|
mfxFrameSurface1 surface;
|
2015-10-27 19:08:45 +02:00
|
|
|
mfxEncodeCtrl enc_ctrl;
|
2018-04-04 11:51:29 +02:00
|
|
|
mfxExtDecodedFrameInfo dec_info;
|
2022-01-24 10:24:55 +02:00
|
|
|
#if QSV_VERSION_ATLEAST(1, 34)
|
|
|
|
mfxExtAV1FilmGrainParam av1_film_grain_param;
|
|
|
|
#endif
|
2022-11-21 04:31:24 +02:00
|
|
|
|
|
|
|
#if QSV_VERSION_ATLEAST(1, 35)
|
|
|
|
mfxExtMasteringDisplayColourVolume mdcv;
|
|
|
|
mfxExtContentLightLevelInfo clli;
|
|
|
|
#endif
|
|
|
|
|
2022-01-24 10:24:53 +02:00
|
|
|
mfxExtBuffer *ext_param[QSV_MAX_FRAME_EXT_PARAMS];
|
|
|
|
int num_ext_params;
|
2015-03-13 11:20:31 +02:00
|
|
|
|
2021-09-25 12:20:20 +02:00
|
|
|
mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload
|
2022-06-08 07:02:48 +02:00
|
|
|
mfxExtBuffer *extparam[QSV_MAX_ENC_EXTPARAM]; ///< used for enc_ctrl.ExtParam
|
2021-09-25 12:20:20 +02:00
|
|
|
|
2015-07-14 18:16:26 +02:00
|
|
|
int queued;
|
2016-08-09 12:05:49 +02:00
|
|
|
int used;
|
2015-07-14 18:16:26 +02:00
|
|
|
|
2015-03-13 11:20:31 +02:00
|
|
|
struct QSVFrame *next;
|
|
|
|
} QSVFrame;
|
|
|
|
|
2019-09-19 22:45:26 +02:00
|
|
|
typedef struct QSVSession {
|
|
|
|
mfxSession session;
|
|
|
|
#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
|
|
|
|
AVBufferRef *va_device_ref;
|
|
|
|
AVHWDeviceContext *va_device_ctx;
|
|
|
|
#endif
|
2021-01-04 04:46:14 +02:00
|
|
|
void *loader;
|
2019-09-19 22:45:26 +02:00
|
|
|
} QSVSession;
|
|
|
|
|
2016-10-21 19:57:12 +02:00
|
|
|
typedef struct QSVFramesContext {
|
|
|
|
AVBufferRef *hw_frames_ctx;
|
2016-08-10 09:38:21 +02:00
|
|
|
void *logctx;
|
|
|
|
|
|
|
|
/* The memory ids for the external frames.
|
|
|
|
* Refcounted, since we need one reference owned by the QSVFramesContext
|
|
|
|
* (i.e. by the encoder/decoder) and another one given to the MFX session
|
|
|
|
* from the frame allocator. */
|
|
|
|
AVBufferRef *mids_buf;
|
2016-08-10 08:29:23 +02:00
|
|
|
QSVMid *mids;
|
|
|
|
int nb_mids;
|
2016-10-21 19:57:12 +02:00
|
|
|
} QSVFramesContext;
|
2015-07-13 16:17:54 +02:00
|
|
|
|
2019-09-19 22:45:27 +02:00
|
|
|
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
|
|
|
|
const char *extra_string);
|
|
|
|
|
2016-06-25 21:38:10 +02:00
|
|
|
int ff_qsv_print_error(void *log_ctx, mfxStatus err,
|
|
|
|
const char *error_string);
|
2015-03-13 09:13:00 +02:00
|
|
|
|
2016-07-14 12:56:35 +02:00
|
|
|
int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
|
|
|
|
const char *warning_string);
|
|
|
|
|
2015-03-13 09:13:00 +02:00
|
|
|
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
|
|
|
|
|
2019-08-13 08:11:08 +02:00
|
|
|
enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc);
|
|
|
|
|
2022-10-06 09:35:34 +02:00
|
|
|
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shift);
|
2018-04-04 11:51:29 +02:00
|
|
|
enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
|
2016-06-22 11:41:26 +02:00
|
|
|
|
2019-08-13 08:11:07 +02:00
|
|
|
enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct);
|
|
|
|
|
2019-09-19 22:45:26 +02:00
|
|
|
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
|
2019-10-08 15:41:02 +02:00
|
|
|
const char *load_plugins, int gpu_copy);
|
2016-10-21 19:57:12 +02:00
|
|
|
|
2019-09-19 22:45:26 +02:00
|
|
|
int ff_qsv_close_internal_session(QSVSession *qs);
|
|
|
|
|
2017-03-05 01:57:35 +02:00
|
|
|
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
|
2019-10-08 15:41:02 +02:00
|
|
|
AVBufferRef *device_ref, const char *load_plugins,
|
|
|
|
int gpu_copy);
|
2017-03-05 01:57:35 +02:00
|
|
|
|
|
|
|
int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *session,
|
|
|
|
QSVFramesContext *qsv_frames_ctx,
|
2019-10-08 15:41:02 +02:00
|
|
|
const char *load_plugins, int opaque, int gpu_copy);
|
2015-03-13 09:13:00 +02:00
|
|
|
|
2016-08-10 08:29:23 +02:00
|
|
|
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
|
|
|
|
|
2022-01-24 10:24:53 +02:00
|
|
|
void ff_qsv_frame_add_ext_param(AVCodecContext *avctx, QSVFrame *frame,
|
|
|
|
mfxExtBuffer *param);
|
|
|
|
|
2022-04-06 10:48:03 +02:00
|
|
|
int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface);
|
|
|
|
|
|
|
|
|
2015-03-13 09:13:00 +02:00
|
|
|
#endif /* AVCODEC_QSV_INTERNAL_H */
|