FFmpeg
Data Structures | Macros | Functions | Variables
vaapi_encode.c File Reference
#include <inttypes.h>
#include <string.h>
#include "config.h"
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/log.h"
#include "libavutil/pixdesc.h"
#include "vaapi_encode.h"
#include "encode.h"
#include "avcodec.h"
#include "refstruct.h"

Go to the source code of this file.

Data Structures

struct  VAAPIEncodeRTFormat
 

Macros

#define TRY_RC_MODE(mode, fail)
 

Functions

static int vaapi_encode_make_packed_header (AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t bit_len)
 
static int vaapi_encode_make_param_buffer (AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t len)
 
static int vaapi_encode_make_misc_param_buffer (AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, const void *data, size_t len)
 
static int vaapi_encode_wait (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static int vaapi_encode_make_row_slice (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static int vaapi_encode_make_tile_slice (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static int vaapi_encode_issue (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static int vaapi_encode_set_output_property (AVCodecContext *avctx, VAAPIEncodePicture *pic, AVPacket *pkt)
 
static int vaapi_encode_get_coded_buffer_size (AVCodecContext *avctx, VABufferID buf_id)
 
static int vaapi_encode_get_coded_buffer_data (AVCodecContext *avctx, VABufferID buf_id, uint8_t **dst)
 
static int vaapi_encode_get_coded_data (AVCodecContext *avctx, VAAPIEncodePicture *pic, AVPacket *pkt)
 
static int vaapi_encode_output (AVCodecContext *avctx, VAAPIEncodePicture *pic, AVPacket *pkt)
 
static int vaapi_encode_discard (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static VAAPIEncodePicturevaapi_encode_alloc (AVCodecContext *avctx)
 
static int vaapi_encode_free (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static void vaapi_encode_add_ref (AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodePicture *target, int is_ref, int in_dpb, int prev)
 
static void vaapi_encode_remove_refs (AVCodecContext *avctx, VAAPIEncodePicture *pic, int level)
 
static void vaapi_encode_set_b_pictures (AVCodecContext *avctx, VAAPIEncodePicture *start, VAAPIEncodePicture *end, VAAPIEncodePicture *prev, int current_depth, VAAPIEncodePicture **last)
 
static void vaapi_encode_add_next_prev (AVCodecContext *avctx, VAAPIEncodePicture *pic)
 
static int vaapi_encode_pick_next (AVCodecContext *avctx, VAAPIEncodePicture **pic_out)
 
static int vaapi_encode_clear_old (AVCodecContext *avctx)
 
static int vaapi_encode_check_frame (AVCodecContext *avctx, const AVFrame *frame)
 
static int vaapi_encode_send_frame (AVCodecContext *avctx, AVFrame *frame)
 
int ff_vaapi_encode_receive_packet (AVCodecContext *avctx, AVPacket *pkt)
 
static av_cold void vaapi_encode_add_global_param (AVCodecContext *avctx, int type, void *buffer, size_t size)
 
static av_cold int vaapi_encode_profile_entrypoint (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_rate_control (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_max_frame_size (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_gop_structure (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_row_slice_structure (AVCodecContext *avctx, uint32_t slice_structure)
 
static av_cold int vaapi_encode_init_tile_slice_structure (AVCodecContext *avctx, uint32_t slice_structure)
 
static av_cold int vaapi_encode_init_slice_structure (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_packed_headers (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_quality (AVCodecContext *avctx)
 
static av_cold int vaapi_encode_init_roi (AVCodecContext *avctx)
 
static void vaapi_encode_free_output_buffer (FFRefStructOpaque opaque, void *obj)
 
static int vaapi_encode_alloc_output_buffer (FFRefStructOpaque opaque, void *obj)
 
static av_cold int vaapi_encode_create_recon_frames (AVCodecContext *avctx)
 
av_cold int ff_vaapi_encode_init (AVCodecContext *avctx)
 
av_cold int ff_vaapi_encode_close (AVCodecContext *avctx)
 

Variables

const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs []
 
static const char *const picture_type_name [] = { "IDR", "I", "P", "B" }
 
static const VAAPIEncodeRTFormat vaapi_encode_rt_formats []
 
static const VAEntrypoint vaapi_encode_entrypoints_normal []
 
static const VAAPIEncodeRCMode vaapi_encode_rc_modes []
 

Macro Definition Documentation

◆ TRY_RC_MODE

#define TRY_RC_MODE (   mode,
  fail 
)
Value:
do { \
rc_mode = &vaapi_encode_rc_modes[mode]; \
if (!(rc_mode->va_mode & supported_va_rc_modes)) { \
if (fail) { \
av_log(avctx, AV_LOG_ERROR, "Driver does not support %s " \
"RC mode (supported modes: %s).\n", rc_mode->name, \
supported_rc_modes_string); \
return AVERROR(EINVAL); \
} \
av_log(avctx, AV_LOG_DEBUG, "Driver does not support %s " \
"RC mode.\n", rc_mode->name); \
rc_mode = NULL; \
} else { \
goto rc_mode_found; \
} \
} while (0)

Function Documentation

◆ vaapi_encode_make_packed_header()

static int vaapi_encode_make_packed_header ( AVCodecContext avctx,
VAAPIEncodePicture pic,
int  type,
char *  data,
size_t  bit_len 
)
static

Definition at line 42 of file vaapi_encode.c.

Referenced by vaapi_encode_issue().

◆ vaapi_encode_make_param_buffer()

static int vaapi_encode_make_param_buffer ( AVCodecContext avctx,
VAAPIEncodePicture pic,
int  type,
char *  data,
size_t  len 
)
static

Definition at line 88 of file vaapi_encode.c.

Referenced by vaapi_encode_issue(), and vaapi_encode_make_misc_param_buffer().

◆ vaapi_encode_make_misc_param_buffer()

static int vaapi_encode_make_misc_param_buffer ( AVCodecContext avctx,
VAAPIEncodePicture pic,
int  type,
const void *  data,
size_t  len 
)
static

Definition at line 116 of file vaapi_encode.c.

Referenced by vaapi_encode_issue().

◆ vaapi_encode_wait()

static int vaapi_encode_wait ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 139 of file vaapi_encode.c.

Referenced by vaapi_encode_discard(), and vaapi_encode_output().

◆ vaapi_encode_make_row_slice()

static int vaapi_encode_make_row_slice ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 184 of file vaapi_encode.c.

Referenced by vaapi_encode_issue().

◆ vaapi_encode_make_tile_slice()

static int vaapi_encode_make_tile_slice ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 239 of file vaapi_encode.c.

Referenced by vaapi_encode_issue().

◆ vaapi_encode_issue()

static int vaapi_encode_issue ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 266 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_receive_packet().

◆ vaapi_encode_set_output_property()

static int vaapi_encode_set_output_property ( AVCodecContext avctx,
VAAPIEncodePicture pic,
AVPacket pkt 
)
static

Definition at line 667 of file vaapi_encode.c.

Referenced by vaapi_encode_output().

◆ vaapi_encode_get_coded_buffer_size()

static int vaapi_encode_get_coded_buffer_size ( AVCodecContext avctx,
VABufferID  buf_id 
)
static

Definition at line 707 of file vaapi_encode.c.

Referenced by vaapi_encode_get_coded_data().

◆ vaapi_encode_get_coded_buffer_data()

static int vaapi_encode_get_coded_buffer_data ( AVCodecContext avctx,
VABufferID  buf_id,
uint8_t **  dst 
)
static

Definition at line 738 of file vaapi_encode.c.

Referenced by vaapi_encode_get_coded_data().

◆ vaapi_encode_get_coded_data()

static int vaapi_encode_get_coded_data ( AVCodecContext avctx,
VAAPIEncodePicture pic,
AVPacket pkt 
)
static

Definition at line 774 of file vaapi_encode.c.

Referenced by vaapi_encode_output().

◆ vaapi_encode_output()

static int vaapi_encode_output ( AVCodecContext avctx,
VAAPIEncodePicture pic,
AVPacket pkt 
)
static

Definition at line 819 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_receive_packet().

◆ vaapi_encode_discard()

static int vaapi_encode_discard ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 864 of file vaapi_encode.c.

Referenced by vaapi_encode_free().

◆ vaapi_encode_alloc()

static VAAPIEncodePicture* vaapi_encode_alloc ( AVCodecContext avctx)
static

Definition at line 881 of file vaapi_encode.c.

Referenced by vaapi_encode_send_frame().

◆ vaapi_encode_free()

static int vaapi_encode_free ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

◆ vaapi_encode_add_ref()

static void vaapi_encode_add_ref ( AVCodecContext avctx,
VAAPIEncodePicture pic,
VAAPIEncodePicture target,
int  is_ref,
int  in_dpb,
int  prev 
)
static

Definition at line 937 of file vaapi_encode.c.

Referenced by vaapi_encode_pick_next(), and vaapi_encode_set_b_pictures().

◆ vaapi_encode_remove_refs()

static void vaapi_encode_remove_refs ( AVCodecContext avctx,
VAAPIEncodePicture pic,
int  level 
)
static

Definition at line 971 of file vaapi_encode.c.

Referenced by vaapi_encode_clear_old().

◆ vaapi_encode_set_b_pictures()

static void vaapi_encode_set_b_pictures ( AVCodecContext avctx,
VAAPIEncodePicture start,
VAAPIEncodePicture end,
VAAPIEncodePicture prev,
int  current_depth,
VAAPIEncodePicture **  last 
)
static

Definition at line 1007 of file vaapi_encode.c.

Referenced by vaapi_encode_pick_next().

◆ vaapi_encode_add_next_prev()

static void vaapi_encode_add_next_prev ( AVCodecContext avctx,
VAAPIEncodePicture pic 
)
static

Definition at line 1071 of file vaapi_encode.c.

Referenced by vaapi_encode_pick_next().

◆ vaapi_encode_pick_next()

static int vaapi_encode_pick_next ( AVCodecContext avctx,
VAAPIEncodePicture **  pic_out 
)
static

Definition at line 1104 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_receive_packet().

◆ vaapi_encode_clear_old()

static int vaapi_encode_clear_old ( AVCodecContext avctx)
static

Definition at line 1256 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_receive_packet().

◆ vaapi_encode_check_frame()

static int vaapi_encode_check_frame ( AVCodecContext avctx,
const AVFrame frame 
)
static

Definition at line 1294 of file vaapi_encode.c.

Referenced by vaapi_encode_send_frame().

◆ vaapi_encode_send_frame()

static int vaapi_encode_send_frame ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1320 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_receive_packet().

◆ ff_vaapi_encode_receive_packet()

int ff_vaapi_encode_receive_packet ( AVCodecContext avctx,
AVPacket pkt 
)

if no B frame before repeat P frame, sent repeat P frame out.

loop to get an available pkt in encoder flushing.

Definition at line 1396 of file vaapi_encode.c.

◆ vaapi_encode_add_global_param()

static av_cold void vaapi_encode_add_global_param ( AVCodecContext avctx,
int  type,
void *  buffer,
size_t  size 
)
static

Definition at line 1495 of file vaapi_encode.c.

Referenced by vaapi_encode_init_quality(), and vaapi_encode_init_rate_control().

◆ vaapi_encode_profile_entrypoint()

static av_cold int vaapi_encode_profile_entrypoint ( AVCodecContext avctx)
static

Definition at line 1552 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_rate_control()

static av_cold int vaapi_encode_init_rate_control ( AVCodecContext avctx)
static

Definition at line 1773 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_max_frame_size()

static av_cold int vaapi_encode_init_max_frame_size ( AVCodecContext avctx)
static

Definition at line 2131 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_gop_structure()

static av_cold int vaapi_encode_init_gop_structure ( AVCodecContext avctx)
static

Definition at line 2188 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_row_slice_structure()

static av_cold int vaapi_encode_init_row_slice_structure ( AVCodecContext avctx,
uint32_t  slice_structure 
)
static

Definition at line 2309 of file vaapi_encode.c.

Referenced by vaapi_encode_init_slice_structure().

◆ vaapi_encode_init_tile_slice_structure()

static av_cold int vaapi_encode_init_tile_slice_structure ( AVCodecContext avctx,
uint32_t  slice_structure 
)
static

Definition at line 2354 of file vaapi_encode.c.

Referenced by vaapi_encode_init_slice_structure().

◆ vaapi_encode_init_slice_structure()

static av_cold int vaapi_encode_init_slice_structure ( AVCodecContext avctx)
static

Definition at line 2415 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_packed_headers()

static av_cold int vaapi_encode_init_packed_headers ( AVCodecContext avctx)
static

Definition at line 2506 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_quality()

static av_cold int vaapi_encode_init_quality ( AVCodecContext avctx)
static

Definition at line 2566 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_init_roi()

static av_cold int vaapi_encode_init_roi ( AVCodecContext avctx)
static

Definition at line 2613 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_free_output_buffer()

static void vaapi_encode_free_output_buffer ( FFRefStructOpaque  opaque,
void *  obj 
)
static

Definition at line 2646 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_alloc_output_buffer()

static int vaapi_encode_alloc_output_buffer ( FFRefStructOpaque  opaque,
void *  obj 
)
static

Definition at line 2659 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ vaapi_encode_create_recon_frames()

static av_cold int vaapi_encode_create_recon_frames ( AVCodecContext avctx)
static

Definition at line 2685 of file vaapi_encode.c.

Referenced by ff_vaapi_encode_init().

◆ ff_vaapi_encode_init()

av_cold int ff_vaapi_encode_init ( AVCodecContext avctx)

◆ ff_vaapi_encode_close()

av_cold int ff_vaapi_encode_close ( AVCodecContext avctx)

Variable Documentation

◆ ff_vaapi_encode_hw_configs

const AVCodecHWConfigInternal* const ff_vaapi_encode_hw_configs[]
Initial value:
= {
HW_CONFIG_ENCODER_FRAMES(VAAPI, VAAPI),
}

Definition at line 35 of file vaapi_encode.c.

◆ picture_type_name

const char* const picture_type_name[] = { "IDR", "I", "P", "B" }
static

Definition at line 40 of file vaapi_encode.c.

Referenced by vaapi_encode_issue().

◆ vaapi_encode_rt_formats

const VAAPIEncodeRTFormat vaapi_encode_rt_formats[]
static
Initial value:
= {
{ "YUV400", VA_RT_FORMAT_YUV400, 8, 1, },
{ "YUV420", VA_RT_FORMAT_YUV420, 8, 3, 1, 1 },
{ "YUV422", VA_RT_FORMAT_YUV422, 8, 3, 1, 0 },
{ "YUV444", VA_RT_FORMAT_YUV444, 8, 3, 0, 0 },
{ "XYUV", VA_RT_FORMAT_YUV444, 8, 3, 0, 0 },
{ "YUV411", VA_RT_FORMAT_YUV411, 8, 3, 2, 0 },
}

Definition at line 1518 of file vaapi_encode.c.

Referenced by vaapi_encode_profile_entrypoint().

◆ vaapi_encode_entrypoints_normal

const VAEntrypoint vaapi_encode_entrypoints_normal[]
static
Initial value:
= {
VAEntrypointEncSlice,
VAEntrypointEncPicture,
0
}

Definition at line 1537 of file vaapi_encode.c.

Referenced by vaapi_encode_profile_entrypoint().

◆ vaapi_encode_rc_modes

const VAAPIEncodeRCMode vaapi_encode_rc_modes[]
static
Initial value:
= {
{ 0 },
{ RC_MODE_CQP, "CQP", 1, VA_RC_CQP, 0, 0, 1, 0 },
{ RC_MODE_CBR, "CBR", 1, VA_RC_CBR, 1, 0, 0, 1 },
{ RC_MODE_VBR, "VBR", 1, VA_RC_VBR, 1, 1, 0, 1 },
{ RC_MODE_ICQ, "ICQ", 0 },
{ RC_MODE_QVBR, "QVBR", 0 },
{ RC_MODE_AVBR, "AVBR", 0 },
}

Definition at line 1752 of file vaapi_encode.c.

Referenced by vaapi_encode_init_rate_control().

RC_MODE_ICQ
@ RC_MODE_ICQ
Definition: vaapi_encode.h:170
AVERROR
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
fail
#define fail()
Definition: checkasm.h:179
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
NULL
#define NULL
Definition: coverity.c:32
RC_MODE_VBR
@ RC_MODE_VBR
Definition: vaapi_encode.h:169
vaapi_encode_rc_modes
static const VAAPIEncodeRCMode vaapi_encode_rc_modes[]
Definition: vaapi_encode.c:1752
HW_CONFIG_ENCODER_FRAMES
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition: hwconfig.h:98
mode
mode
Definition: ebur128.h:83
RC_MODE_AVBR
@ RC_MODE_AVBR
Definition: vaapi_encode.h:172
RC_MODE_CQP
@ RC_MODE_CQP
Definition: vaapi_encode.h:167
RC_MODE_CBR
@ RC_MODE_CBR
Definition: vaapi_encode.h:168
RC_MODE_QVBR
@ RC_MODE_QVBR
Definition: vaapi_encode.h:171
rc_mode
mfxU16 rc_mode
Definition: qsvenc.c:141