34 int type,
char *
data,
size_t bit_len)
38 VABufferID param_buffer, data_buffer;
39 VAEncPackedHeaderParameterBuffer
params = {
41 .bit_length = bit_len,
42 .has_emulation_bytes = 1,
48 VAEncPackedHeaderParameterBufferType,
49 sizeof(params), 1, ¶ms, ¶m_buffer);
50 if (vas != VA_STATUS_SUCCESS) {
52 "for packed header (type %d): %d (%s).\n",
53 type, vas, vaErrorStr(vas));
59 VAEncPackedHeaderDataBufferType,
60 (bit_len + 7) / 8, 1, data, &data_buffer);
61 if (vas != VA_STATUS_SUCCESS) {
63 "for packed header (type %d): %d (%s).\n",
64 type, vas, vaErrorStr(vas));
70 "(%zu bits).\n", type, param_buffer, data_buffer, bit_len);
85 type, len, 1, data, &buffer);
86 if (vas != VA_STATUS_SUCCESS) {
88 "(type %d): %d (%s).\n", type, vas, vaErrorStr(vas));
116 if (vas != VA_STATUS_SUCCESS) {
118 "%d (%s).\n", vas, vaErrorStr(vas));
146 for (i = 0; i < pic->
nb_refs; i++) {
154 for (i = 0; i < pic->
nb_refs; i++) {
182 VAEncCodedBufferType,
185 if (vas != VA_STATUS_SUCCESS) {
187 "output buffer: %d (%s).\n", vas, vaErrorStr(vas));
211 VAEncMiscParameterBufferType,
221 VAEncSequenceParameterBufferType,
232 "parameters: %d.\n", err);
236 VAEncPictureParameterBufferType,
245 bit_len = 8 *
sizeof(
data);
249 "header: %d.\n", err);
261 bit_len = 8 *
sizeof(
data);
265 "header: %d.\n", err);
285 "buffer %d: %d.\n", i, err);
317 "parameters: %d.\n", err);
323 bit_len = 8 *
sizeof(
data);
328 "header: %d.\n", err);
340 VAEncSliceParameterBufferType,
350 if (vas != VA_STATUS_SUCCESS) {
352 "%d (%s).\n", vas, vaErrorStr(vas));
354 goto fail_with_picture;
359 if (vas != VA_STATUS_SUCCESS) {
361 "%d (%s).\n", vas, vaErrorStr(vas));
363 goto fail_with_picture;
367 if (vas != VA_STATUS_SUCCESS) {
369 "%d (%s).\n", vas, vaErrorStr(vas));
396 VACodedBufferSegment *buf_list, *
buf;
407 if (vas != VA_STATUS_SUCCESS) {
409 "%d (%s).\n", vas, vaErrorStr(vas));
414 for (buf = buf_list;
buf; buf = buf->next) {
416 "(status %08x).\n", buf->size, buf->status);
422 memcpy(pkt->
data, buf->buf, buf->size);
431 if (vas != VA_STATUS_SUCCESS) {
433 "%d (%s).\n", vas, vaErrorStr(vas));
463 "%"PRId64
"/%"PRId64
".\n",
540 for (i = 0; i < pic->
nb_refs; i++) {
560 for (i = 0; i < pic->
nb_refs; i++) {
564 if (i < pic->nb_refs)
643 for (i = 0; i < ctx->
b_per_p; i++) {
660 for (i = 0, pic = start; pic; i++, pic = pic->
next) {
680 pic->display_order, pic->encode_order);
718 for (pic = ctx->
pic_start; pic != last_pic; pic = pic->
next) {
721 pic->
refs[1] = last_pic;
732 for (pic = last_pic->
next; pic; pic = next) {
767 for (pic = old->
next; pic; pic = pic->
next) {
770 for (i = 0; i < pic->
nb_refs; i++) {
771 if (pic->
refs[i] == old) {
789 const AVFrame *input_image,
int *got_packet)
814 pic->
pts = input_image->
pts;
865 pkt->
dts = INT64_MIN;
897 VAEntrypoint *entrypoints =
NULL;
898 VAConfigAttrib attr[] = {
899 { VAConfigAttribRateControl },
900 { VAConfigAttribEncMaxRefFrames },
909 vas = vaQueryConfigProfiles(ctx->
hwctx->
display, profiles, &n);
910 if (vas != VA_STATUS_SUCCESS) {
912 vas, vaErrorStr(vas));
916 for (i = 0; i <
n; i++) {
935 if (vas != VA_STATUS_SUCCESS) {
938 vas, vaErrorStr(vas));
942 for (i = 0; i <
n; i++) {
956 if (vas != VA_STATUS_SUCCESS) {
958 "attributes: %d (%s).\n", vas, vaErrorStr(vas));
963 if (attr[i].
value == VA_ATTRIB_NOT_SUPPORTED) {
969 switch (attr[i].
type) {
970 case VAConfigAttribRateControl:
973 "supported: %x\n", attr[i].
value);
978 case VAConfigAttribEncMaxRefFrames:
980 unsigned int ref_l0 = attr[i].value & 0xffff;
981 unsigned int ref_l1 = (attr[i].value >> 16) & 0xffff;
983 if (avctx->
gop_size > 1 && ref_l0 < 1) {
985 "supported (%x).\n", attr[i].
value);
991 "supported (%x).\n", attr[i].
value);
1020 "required to associate the encoding device.\n");
1063 if (vas != VA_STATUS_SUCCESS) {
1065 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
1110 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
1137 "frame context: %d.\n", err);
1148 if (vas != VA_STATUS_SUCCESS) {
1150 "context: %d (%s).\n", vas, vaErrorStr(vas));
1181 "failed: %d.\n", err);
1210 for (pic = ctx->
pic_start; pic; pic = next) {
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
VASurfaceID input_surface
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.
VAAPIEncodeSlice * slices[MAX_PICTURE_SLICES]
VAEntrypoint va_entrypoint
ptrdiff_t const GLvoid * data
static const char * picture_type_name[]
static int vaapi_encode_free(AVCodecContext *avctx, VAAPIEncodePicture *pic)
char codec_options_data[0]
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...
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
int width
The allocated dimensions of the frames in this pool.
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.
int(* write_slice_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
void * codec_sequence_params
AVBufferRef * input_frames_ref
size_t picture_params_size
AVHWDeviceContext * device
int max_width
The maximum size of frames in this hw_frames_ctx.
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
static int vaapi_encode_mangle_end(AVCodecContext *avctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static av_cold int end(AVCodecContext *avctx)
int(* write_picture_header)(AVCodecContext *avctx, VAAPIEncodePicture *pic, 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.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx, const VAAPIEncodeType *type)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define AVERROR_EOF
End of file.
VASurfaceID recon_surface
#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]
AVHWFramesContext * input_frames
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
VAAPI hardware pipeline configuration details.
static int vaapi_encode_step(AVCodecContext *avctx, VAAPIEncodePicture *target)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
#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().
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int(* init_picture_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic)
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 initial_pool_size
Initial size of the frame pool.
static int vaapi_encode_get_next(AVCodecContext *avctx, VAAPIEncodePicture **pic_out)
AVBufferRef * hw_frames_ctx
Encoding only.
static int vaapi_encode_make_param_buffer(AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t len)
GLsizei GLboolean const GLfloat * value
int(* close)(AVCodecContext *avctx)
struct VAAPIEncodePicture * next
static int vaapi_encode_discard(AVCodecContext *avctx, VAAPIEncodePicture *pic)
void * codec_picture_params
int64_t ts_ring[MAX_REORDER_DELAY *3]
#define FF_ARRAY_ELEMS(a)
VADisplay display
The VADisplay handle, to be filled by the user.
int(* write_sequence_header)(AVCodecContext *avctx, char *data, size_t *data_len)
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
int min_width
The minimum size of frames in this hw_frames_ctx.
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(* write_extra_buffer)(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
static VAAPIEncodePicture * vaapi_encode_alloc(void)
VABufferID param_buffers[MAX_PARAM_BUFFERS]
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
AVBufferRef * recon_frames_ref
static av_cold int vaapi_encode_check_config(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.
size_t global_params_size[MAX_GLOBAL_PARAMS]
static int vaapi_encode_issue(AVCodecContext *avctx, VAAPIEncodePicture *pic)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
size_t sequence_params_size
static const AVProfile profiles[]
static int vaapi_encode_clear_old(AVCodecContext *avctx)
common internal and external API header
static int vaapi_encode_output(AVCodecContext *avctx, VAAPIEncodePicture *pic, AVPacket *pkt)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
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
int(* init_slice_params)(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
static int vaapi_encode_wait(AVCodecContext *avctx, VAAPIEncodePicture *pic)
VAConfigID config_id
ID of a VAAPI pipeline configuration.
int(* init_sequence_params)(AVCodecContext *avctx)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int vaapi_encode_make_packed_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int type, char *data, size_t bit_len)
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
#define av_malloc_array(a, b)
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.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int(* init)(AVCodecContext *avctx)
AVVAAPIDeviceContext * hwctx