34 int type,
char *
data,
size_t bit_len)
38 VABufferID param_buffer, data_buffer;
40 VAEncPackedHeaderParameterBuffer
params = {
42 .bit_length = bit_len,
43 .has_emulation_bytes = 1,
52 VAEncPackedHeaderParameterBufferType,
53 sizeof(params), 1, ¶ms, ¶m_buffer);
54 if (vas != VA_STATUS_SUCCESS) {
56 "for packed header (type %d): %d (%s).\n",
57 type, vas, vaErrorStr(vas));
63 VAEncPackedHeaderDataBufferType,
64 (bit_len + 7) / 8, 1, data, &data_buffer);
65 if (vas != VA_STATUS_SUCCESS) {
67 "for packed header (type %d): %d (%s).\n",
68 type, vas, vaErrorStr(vas));
74 "(%zu bits).\n", type, param_buffer, data_buffer, bit_len);
93 type, len, 1, data, &buffer);
94 if (vas != VA_STATUS_SUCCESS) {
96 "(type %d): %d (%s).\n", type, vas, vaErrorStr(vas));
124 if (vas != VA_STATUS_SUCCESS) {
126 "%d (%s).\n", vas, vaErrorStr(vas));
154 for (i = 0; i < pic->
nb_refs; i++) {
162 for (i = 0; i < pic->
nb_refs; i++) {
167 if (ctx->
issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING)
215 VAEncMiscParameterBufferType,
225 VAEncSequenceParameterBufferType,
236 "parameters: %d.\n", err);
240 VAEncPictureParameterBufferType,
250 bit_len = 8 *
sizeof(
data);
254 "header: %d.\n", err);
267 bit_len = 8 *
sizeof(
data);
271 "header: %d.\n", err);
291 "buffer %d: %d.\n", i, err);
306 bit_len = 8 *
sizeof(
data);
313 "header %d: %d.\n", i, err);
347 "parameters: %d.\n", err);
354 bit_len = 8 *
sizeof(
data);
359 "header: %d.\n", err);
371 VAEncSliceParameterBufferType,
381 if (vas != VA_STATUS_SUCCESS) {
383 "%d (%s).\n", vas, vaErrorStr(vas));
385 goto fail_with_picture;
390 if (vas != VA_STATUS_SUCCESS) {
392 "%d (%s).\n", vas, vaErrorStr(vas));
394 goto fail_with_picture;
398 if (vas != VA_STATUS_SUCCESS) {
400 "%d (%s).\n", vas, vaErrorStr(vas));
416 if (vas != VA_STATUS_SUCCESS) {
418 "param buffer %#x: %d (%s).\n",
427 if (ctx->
issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING)
457 VACodedBufferSegment *buf_list, *
buf;
468 if (vas != VA_STATUS_SUCCESS) {
470 "%d (%s).\n", vas, vaErrorStr(vas));
475 for (buf = buf_list;
buf; buf = buf->next) {
477 "(status %08x).\n", buf->size, buf->status);
483 memcpy(pkt->
data, buf->buf, buf->size);
492 if (vas != VA_STATUS_SUCCESS) {
494 "%d (%s).\n", vas, vaErrorStr(vas));
521 "%"PRId64
"/%"PRId64
".\n",
585 if (ctx->
issue_mode == ISSUE_MODE_SERIALISE_EVERYTHING ||
586 ctx->
issue_mode == ISSUE_MODE_MINIMISE_LATENCY) {
601 for (i = 0; i < pic->
nb_refs; i++) {
613 }
else if (ctx->
issue_mode == ISSUE_MODE_MAXIMISE_THROUGHPUT) {
625 for (i = 0; i < pic->
nb_refs; i++) {
629 if (i < pic->nb_refs)
698 for (i = 0; i < ctx->
b_per_p &&
725 for (i = 0, pic = start; pic; i++, pic = pic->
next) {
783 for (pic = ctx->
pic_start; pic != last_pic; pic = pic->
next) {
786 pic->
refs[1] = last_pic;
797 for (pic = last_pic->
next; pic; pic = next) {
832 for (pic = old->
next; pic; pic = pic->
next) {
835 for (i = 0; i < pic->
nb_refs; i++) {
836 if (pic->
refs[i] == old) {
854 const AVFrame *input_image,
int *got_packet)
886 pic->
pts = input_image->
pts;
937 pkt->
dts = INT64_MIN;
969 VAEntrypoint *entrypoints =
NULL;
970 VAConfigAttrib attr[] = {
971 { VAConfigAttribRTFormat },
972 { VAConfigAttribRateControl },
973 { VAConfigAttribEncMaxRefFrames },
974 { VAConfigAttribEncPackedHeaders },
983 vas = vaQueryConfigProfiles(ctx->
hwctx->
display, profiles, &n);
984 if (vas != VA_STATUS_SUCCESS) {
986 vas, vaErrorStr(vas));
990 for (i = 0; i <
n; i++) {
1009 if (vas != VA_STATUS_SUCCESS) {
1012 vas, vaErrorStr(vas));
1016 for (i = 0; i <
n; i++) {
1030 if (vas != VA_STATUS_SUCCESS) {
1032 "attributes: %d (%s).\n", vas, vaErrorStr(vas));
1037 if (attr[i].
value == VA_ATTRIB_NOT_SUPPORTED) {
1045 switch (attr[i].
type) {
1046 case VAConfigAttribRTFormat:
1049 "is not supported (mask %#x).\n",
1056 .type = VAConfigAttribRTFormat,
1060 case VAConfigAttribRateControl:
1067 !(attr[i].value & VA_RC_VBR) &&
1068 (attr[i].value & VA_RC_CBR)) {
1070 "not supported with this driver version; " 1071 "using CBR instead.\n");
1076 "is not supported (mask: %#x).\n",
1083 .type = VAConfigAttribRateControl,
1087 case VAConfigAttribEncMaxRefFrames:
1089 unsigned int ref_l0 = attr[i].value & 0xffff;
1090 unsigned int ref_l1 = (attr[i].value >> 16) & 0xffff;
1092 if (avctx->
gop_size > 1 && ref_l0 < 1) {
1094 "supported (%#x).\n", attr[i].
value);
1100 "supported (%#x) by the underlying driver.\n",
1106 case VAConfigAttribEncPackedHeaders:
1113 "headers are not supported (want %#x, got %#x).\n",
1119 .type = VAConfigAttribEncPackedHeaders,
1124 av_assert0(0 &&
"Unexpected config attribute.");
1138 int rc_bits_per_second;
1139 int rc_target_percentage;
1141 int hrd_buffer_size;
1142 int hrd_initial_buffer_fullness;
1147 "higher is not supported.\n");
1158 hrd_initial_buffer_fullness = hrd_buffer_size * 3 / 4;
1161 rc_bits_per_second = avctx->
bit_rate;
1162 rc_target_percentage = 100;
1163 rc_window_size = 1000;
1167 rc_bits_per_second = avctx->
bit_rate;
1168 rc_target_percentage = 100;
1171 rc_target_percentage = (avctx->
bit_rate * 100) / rc_bits_per_second;
1173 rc_window_size = (hrd_buffer_size * 1000) / avctx->
bit_rate;
1176 ctx->
rc_params.
misc.type = VAEncMiscParameterTypeRateControl;
1177 ctx->
rc_params.
rc = (VAEncMiscParameterRateControl) {
1178 .bits_per_second = rc_bits_per_second,
1179 .target_percentage = rc_target_percentage,
1180 .window_size = rc_window_size,
1182 .min_qp = (avctx->
qmin > 0 ? avctx->
qmin : 0),
1183 .basic_unit_size = 0,
1192 .initial_buffer_fullness = hrd_initial_buffer_fullness,
1193 .buffer_size = hrd_buffer_size,
1208 ctx->
fr_params.
fr.framerate = (
unsigned int)fr_den << 16 | fr_num;
1210 #if VA_CHECK_VERSION(0, 40, 0) 1225 VABufferID buffer_id;
1227 buffer_id = (VABufferID)(uintptr_t)
data;
1239 VABufferID buffer_id;
1248 VAEncCodedBufferType,
1250 (1 << 16), 1, 0, &buffer_id);
1251 if (vas != VA_STATUS_SUCCESS) {
1253 "output buffer: %d (%s).\n", vas, vaErrorStr(vas));
1322 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
1351 "frame context: %d.\n", err);
1371 "required to associate the encoding device.\n");
1409 if (vas != VA_STATUS_SUCCESS) {
1411 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
1427 if (vas != VA_STATUS_SUCCESS) {
1429 "context: %d (%s).\n", vas, vaErrorStr(vas));
1455 #if VA_CHECK_VERSION(0, 36, 0) 1456 VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
1462 if (vas != VA_STATUS_SUCCESS) {
1464 "attribute: will use default compression level.\n");
1468 "level: valid range is 0-%d, using %d.\n",
1469 attr.value, attr.value);
1473 ctx->quality_params.
misc.type =
1474 VAEncMiscParameterTypeQualityLevel;
1475 ctx->quality_params.quality.quality_level =
1479 &ctx->quality_params.
misc;
1481 sizeof(ctx->quality_params);
1485 "option is not supported with this VAAPI version.\n");
1519 "failed: %d.\n", err);
1526 ctx->
issue_mode = ISSUE_MODE_MAXIMISE_THROUGHPUT;
1531 size_t bit_len = 8 *
sizeof(
data);
1536 "for extradata: %d.\n", err);
1562 for (pic = ctx->
pic_start; pic; pic = next) {
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
VASurfaceID input_surface
VAEncMiscParameterBuffer misc
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
VAAPI-specific data associated with a frame pool.
This structure describes decoded (raw) audio or video data.
VAEntrypoint va_entrypoint
char codec_options_data[0]
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
enum VAAPIEncodeContext::@138 issue_mode
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
int width
The allocated dimensions of the frames in this pool.
static int vaapi_encode_make_packed_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t bit_len)
static const char *const picture_type_name[]
static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void * codec_sequence_params
AVBufferRef * input_frames_ref
VAEncMiscParameterHRD hrd
size_t picture_params_size
AVHWDeviceContext * device
static int vaapi_encode_clear_old(AVCodecContext *avctx)
static int vaapi_encode_wait(AVCodecContext *avctx, VAAPIEncodePicture *pic)
int(* init_picture_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic)
int max_width
The maximum size of frames in this hw_frames_ctx.
static int vaapi_encode_discard(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static int vaapi_encode_make_param_buffer(AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t len)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
unsigned int va_packed_headers
#define av_assert0(cond)
assert() equivalent, that is always enabled.
VAEncMiscParameterFrameRate fr
static VAAPIEncodePicture * vaapi_encode_alloc(void)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int vaapi_encode_issue(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static av_cold int end(AVCodecContext *avctx)
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static AVBufferRef * vaapi_encode_alloc_output_buffer(void *opaque, int size)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVBufferRef * output_buffer_ref
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
VABufferID * param_buffers
#define AVERROR_EOF
End of file.
VASurfaceID recon_surface
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES]
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
AVHWFramesContext * input_frames
int(* configure)(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
VAAPI hardware pipeline configuration details.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int(* init_sequence_params)(AVCodecContext *avctx)
int(* write_picture_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
VAEncMiscParameterBuffer * global_params[MAX_GLOBAL_PARAMS]
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
void * codec_picture_params
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
AVHWFramesContext * recon_frames
int flags
A combination of AV_PKT_FLAG values.
int rc_buffer_size
decoder bitstream buffer size
VAAPIEncodeSlice * slices
int initial_pool_size
Initial size of the frame pool.
enum AVPictureType pict_type
Picture type of the frame.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
unsigned int va_rt_format
struct VAAPIEncodePicture * next
struct VAAPIEncodeContext::@135 rc_params
int(* write_extra_buffer)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
void * codec_picture_params
int64_t ts_ring[MAX_REORDER_DELAY *3]
AVBufferPool * output_buffer_pool
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
#define FF_ARRAY_ELEMS(a)
VADisplay display
The VADisplay handle, to be filled by the user.
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
int min_width
The minimum size of frames in this hw_frames_ctx.
int(* init_slice_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
const struct VAAPIEncodeType * codec
Libavcodec external API header.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
VAAPIEncodePicture * pic_start
main external API structure.
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
uint8_t * data
The data buffer.
int qmin
minimum quantizer
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
unsigned int driver_quirks
Driver quirks to apply - this is filled by av_hwdevice_ctx_init(), with reference to a table of known...
static const AVProfile profiles[]
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
struct VAAPIEncodeContext::@137 fr_params
This struct describes a set or pool of "hardware" frames (i.e.
static int vaapi_encode_step(AVCodecContext *avctx, VAAPIEncodePicture *target)
int(* write_extra_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
AVBufferRef * recon_frames_ref
static int vaapi_encode_truncate_gop(AVCodecContext *avctx)
VAAPIEncodePicture * pic_end
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
struct VAAPIEncodeContext::@136 hrd_params
size_t global_params_size[MAX_GLOBAL_PARAMS]
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
VAEncMiscParameterRateControl rc
A reference to a data buffer.
size_t sequence_params_size
const char const char * params
common internal and external API header
static int ref[MAX_W *MAX_W]
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int vaapi_encode_get_next(AVCodecContext *avctx, VAAPIEncodePicture **pic_out)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx)
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
void * codec_slice_params
static int vaapi_encode_free(AVCodecContext *avctx, VAAPIEncodePicture *pic)
VAConfigID config_id
ID of a VAAPI pipeline configuration.
static void vaapi_encode_free_output_buffer(void *opaque, uint8_t *data)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define av_malloc_array(a, b)
static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
int64_t rc_max_rate
maximum bitrate
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
static int vaapi_encode_output(AVCodecContext *avctx, VAAPIEncodePicture *pic, AVPacket *pkt)
AVVAAPIDeviceContext * hwctx
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)