FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ffmpeg_vaapi.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "config.h"
20 
21 #include <fcntl.h>
22 #include <unistd.h>
23 
24 #include <va/va.h>
25 #if HAVE_VAAPI_X11
26 # include <va/va_x11.h>
27 #endif
28 #if HAVE_VAAPI_DRM
29 # include <va/va_drm.h>
30 #endif
31 
32 #include "libavutil/avassert.h"
33 #include "libavutil/avconfig.h"
34 #include "libavutil/buffer.h"
35 #include "libavutil/frame.h"
36 #include "libavutil/hwcontext.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/pixfmt.h"
41 
42 #include "libavcodec/vaapi.h"
43 
44 #include "ffmpeg.h"
45 
46 
47 static AVClass vaapi_class = {
48  .class_name = "vaapi",
49  .item_name = av_default_item_name,
50  .version = LIBAVUTIL_VERSION_INT,
51 };
52 
53 #define DEFAULT_SURFACES 20
54 
55 typedef struct VAAPIDecoderContext {
56  const AVClass *class;
57 
62 
63  VAProfile va_profile;
64  VAEntrypoint va_entrypoint;
65  VAConfigID va_config;
66  VAContextID va_context;
67 
72 
73  // The output need not have the same format, width and height as the
74  // decoded frames - the copy for non-direct-mapped access is actually
75  // a whole vpp instance which can do arbitrary scaling and format
76  // conversion.
78 
81 
82 
84 {
85  InputStream *ist = avctx->opaque;
87  int err;
88 
89  err = av_hwframe_get_buffer(ctx->frames_ref, frame, 0);
90  if (err < 0) {
91  av_log(ctx, AV_LOG_ERROR, "Failed to allocate decoder surface.\n");
92  } else {
93  av_log(ctx, AV_LOG_DEBUG, "Decoder given surface %#x.\n",
94  (unsigned int)(uintptr_t)frame->data[3]);
95  }
96  return err;
97 }
98 
99 static int vaapi_retrieve_data(AVCodecContext *avctx, AVFrame *input)
100 {
101  InputStream *ist = avctx->opaque;
103  AVFrame *output = 0;
104  int err;
105 
107 
108  if (ctx->output_format == AV_PIX_FMT_VAAPI) {
109  // Nothing to do.
110  return 0;
111  }
112 
113  av_log(ctx, AV_LOG_DEBUG, "Retrieve data from surface %#x.\n",
114  (unsigned int)(uintptr_t)input->data[3]);
115 
116  output = av_frame_alloc();
117  if (!output)
118  return AVERROR(ENOMEM);
119 
120  output->format = ctx->output_format;
121 
122  err = av_hwframe_transfer_data(output, input, 0);
123  if (err < 0) {
124  av_log(ctx, AV_LOG_ERROR, "Failed to transfer data to "
125  "output frame: %d.\n", err);
126  goto fail;
127  }
128 
129  err = av_frame_copy_props(output, input);
130  if (err < 0) {
131  av_frame_unref(output);
132  goto fail;
133  }
134 
135  av_frame_unref(input);
136  av_frame_move_ref(input, output);
137  av_frame_free(&output);
138 
139  return 0;
140 
141 fail:
142  if (output)
143  av_frame_free(&output);
144  return err;
145 }
146 
147 
148 static const struct {
151  VAProfile va_profile;
152 } vaapi_profile_map[] = {
153 #define MAP(c, p, v) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v }
154  MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
155  MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
156  MAP(H263, UNKNOWN, H263Baseline),
157  MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
158  MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
159  MPEG4AdvancedSimple),
160  MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
161  MAP(H264, H264_CONSTRAINED_BASELINE,
162  H264ConstrainedBaseline),
163  MAP(H264, H264_BASELINE, H264Baseline),
164  MAP(H264, H264_MAIN, H264Main ),
165  MAP(H264, H264_HIGH, H264High ),
166 #if VA_CHECK_VERSION(0, 37, 0)
167  MAP(HEVC, HEVC_MAIN, HEVCMain ),
168 #endif
169  MAP(WMV3, VC1_SIMPLE, VC1Simple ),
170  MAP(WMV3, VC1_MAIN, VC1Main ),
171  MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
172  MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
173  MAP(VC1, VC1_SIMPLE, VC1Simple ),
174  MAP(VC1, VC1_MAIN, VC1Main ),
175  MAP(VC1, VC1_COMPLEX, VC1Advanced ),
176  MAP(VC1, VC1_ADVANCED, VC1Advanced ),
177 #if VA_CHECK_VERSION(0, 35, 0)
178  MAP(VP8, UNKNOWN, VP8Version0_3 ),
179 #endif
180 #if VA_CHECK_VERSION(0, 37, 1)
181  MAP(VP9, VP9_0, VP9Profile0 ),
182 #endif
183 #undef MAP
184 };
185 
187  AVCodecContext *avctx,
188  int fallback_allowed)
189 {
190  AVVAAPIDeviceContext *hwctx = ctx->device->hwctx;
191  AVVAAPIHWConfig *hwconfig = NULL;
192  AVHWFramesConstraints *constraints = NULL;
193  VAStatus vas;
194  int err, i, j;
195  int loglevel = fallback_allowed ? AV_LOG_VERBOSE : AV_LOG_ERROR;
196  const AVCodecDescriptor *codec_desc;
197  const AVPixFmtDescriptor *pix_desc;
198  enum AVPixelFormat pix_fmt;
199  VAProfile profile, *profile_list = NULL;
200  int profile_count, exact_match, alt_profile;
201 
202  codec_desc = avcodec_descriptor_get(avctx->codec_id);
203  if (!codec_desc) {
204  err = AVERROR(EINVAL);
205  goto fail;
206  }
207 
208  profile_count = vaMaxNumProfiles(hwctx->display);
209  profile_list = av_malloc(profile_count * sizeof(VAProfile));
210  if (!profile_list) {
211  err = AVERROR(ENOMEM);
212  goto fail;
213  }
214 
215  vas = vaQueryConfigProfiles(hwctx->display,
216  profile_list, &profile_count);
217  if (vas != VA_STATUS_SUCCESS) {
218  av_log(ctx, loglevel, "Failed to query profiles: %d (%s).\n",
219  vas, vaErrorStr(vas));
220  err = AVERROR(EIO);
221  goto fail;
222  }
223 
224  profile = VAProfileNone;
225  exact_match = 0;
226 
227  for (i = 0; i < FF_ARRAY_ELEMS(vaapi_profile_map); i++) {
228  int profile_match = 0;
229  if (avctx->codec_id != vaapi_profile_map[i].codec_id)
230  continue;
231  if (avctx->profile == vaapi_profile_map[i].codec_profile)
232  profile_match = 1;
233  profile = vaapi_profile_map[i].va_profile;
234  for (j = 0; j < profile_count; j++) {
235  if (profile == profile_list[j]) {
236  exact_match = profile_match;
237  break;
238  }
239  }
240  if (j < profile_count) {
241  if (exact_match)
242  break;
243  alt_profile = vaapi_profile_map[i].codec_profile;
244  }
245  }
246  av_freep(&profile_list);
247 
248  if (profile == VAProfileNone) {
249  av_log(ctx, loglevel, "No VAAPI support for codec %s.\n",
250  codec_desc->name);
251  err = AVERROR(ENOSYS);
252  goto fail;
253  }
254  if (!exact_match) {
255  if (fallback_allowed || !hwaccel_lax_profile_check) {
256  av_log(ctx, loglevel, "No VAAPI support for codec %s "
257  "profile %d.\n", codec_desc->name, avctx->profile);
258  if (!fallback_allowed) {
259  av_log(ctx, AV_LOG_WARNING, "If you want attempt decoding "
260  "anyway with a possibly-incompatible profile, add "
261  "the option -hwaccel_lax_profile_check.\n");
262  }
263  err = AVERROR(EINVAL);
264  goto fail;
265  } else {
266  av_log(ctx, AV_LOG_WARNING, "No VAAPI support for codec %s "
267  "profile %d: trying instead with profile %d.\n",
268  codec_desc->name, avctx->profile, alt_profile);
269  av_log(ctx, AV_LOG_WARNING, "This may fail or give "
270  "incorrect results, depending on your hardware.\n");
271  }
272  }
273 
274  ctx->va_profile = profile;
275  ctx->va_entrypoint = VAEntrypointVLD;
276 
277  vas = vaCreateConfig(hwctx->display, ctx->va_profile,
278  ctx->va_entrypoint, 0, 0, &ctx->va_config);
279  if (vas != VA_STATUS_SUCCESS) {
280  av_log(ctx, AV_LOG_ERROR, "Failed to create decode pipeline "
281  "configuration: %d (%s).\n", vas, vaErrorStr(vas));
282  err = AVERROR(EIO);
283  goto fail;
284  }
285 
286  hwconfig = av_hwdevice_hwconfig_alloc(ctx->device_ref);
287  if (!hwconfig) {
288  err = AVERROR(ENOMEM);
289  goto fail;
290  }
291  hwconfig->config_id = ctx->va_config;
292 
294  hwconfig);
295  if (!constraints)
296  goto fail;
297 
298  // Decide on the decoder target format.
299  // If the user specified something with -hwaccel_output_format then
300  // try to use that to minimise conversions later.
302  if (ctx->output_format != AV_PIX_FMT_NONE &&
304  for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
305  if (constraints->valid_sw_formats[i] == ctx->decode_format) {
306  ctx->decode_format = ctx->output_format;
307  av_log(ctx, AV_LOG_DEBUG, "Using decode format %s (output "
308  "format).\n", av_get_pix_fmt_name(ctx->decode_format));
309  break;
310  }
311  }
312  }
313  // Otherwise, we would like to try to choose something which matches the
314  // decoder output, but there isn't enough information available here to
315  // do so. Assume for now that we are always dealing with YUV 4:2:0, so
316  // pick a format which does that.
317  if (ctx->decode_format == AV_PIX_FMT_NONE) {
318  for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
319  pix_fmt = constraints->valid_sw_formats[i];
320  pix_desc = av_pix_fmt_desc_get(pix_fmt);
321  if (pix_desc->nb_components == 3 &&
322  pix_desc->log2_chroma_w == 1 &&
323  pix_desc->log2_chroma_h == 1) {
324  ctx->decode_format = pix_fmt;
325  av_log(ctx, AV_LOG_DEBUG, "Using decode format %s (format "
326  "matched).\n", av_get_pix_fmt_name(ctx->decode_format));
327  break;
328  }
329  }
330  }
331  // Otherwise pick the first in the list and hope for the best.
332  if (ctx->decode_format == AV_PIX_FMT_NONE) {
333  ctx->decode_format = constraints->valid_sw_formats[0];
334  av_log(ctx, AV_LOG_DEBUG, "Using decode format %s (first in list).\n",
336  if (i > 1) {
337  // There was a choice, and we picked randomly. Warn the user
338  // that they might want to choose intelligently instead.
339  av_log(ctx, AV_LOG_WARNING, "Using randomly chosen decode "
340  "format %s.\n", av_get_pix_fmt_name(ctx->decode_format));
341  }
342  }
343 
344  // Ensure the picture size is supported by the hardware.
345  ctx->decode_width = avctx->coded_width;
346  ctx->decode_height = avctx->coded_height;
347  if (ctx->decode_width < constraints->min_width ||
348  ctx->decode_height < constraints->min_height ||
349  ctx->decode_width > constraints->max_width ||
350  ctx->decode_height >constraints->max_height) {
351  av_log(ctx, AV_LOG_ERROR, "VAAPI hardware does not support image "
352  "size %dx%d (constraints: width %d-%d height %d-%d).\n",
353  ctx->decode_width, ctx->decode_height,
354  constraints->min_width, constraints->max_width,
355  constraints->min_height, constraints->max_height);
356  err = AVERROR(EINVAL);
357  goto fail;
358  }
359 
360  av_hwframe_constraints_free(&constraints);
361  av_freep(&hwconfig);
362 
363  // Decide how many reference frames we need. This might be doable more
364  // nicely based on the codec and input stream?
366  // For frame-threaded decoding, one additional surfaces is needed for
367  // each thread.
368  if (avctx->active_thread_type & FF_THREAD_FRAME)
369  ctx->decode_surfaces += avctx->thread_count;
370 
371  return 0;
372 
373 fail:
374  av_hwframe_constraints_free(&constraints);
375  av_freep(&hwconfig);
376  vaDestroyConfig(hwctx->display, ctx->va_config);
377  av_freep(&profile_list);
378  return err;
379 }
380 
382 {
383  InputStream *ist = avctx->opaque;
385 
386  if (ctx) {
387  AVVAAPIDeviceContext *hwctx = ctx->device->hwctx;
388 
389  if (ctx->va_context != VA_INVALID_ID) {
390  vaDestroyContext(hwctx->display, ctx->va_context);
391  ctx->va_context = VA_INVALID_ID;
392  }
393  if (ctx->va_config != VA_INVALID_ID) {
394  vaDestroyConfig(hwctx->display, ctx->va_config);
395  ctx->va_config = VA_INVALID_ID;
396  }
397 
400  av_free(ctx);
401  }
402 
404 
405  ist->hwaccel_ctx = 0;
406  ist->hwaccel_uninit = 0;
407  ist->hwaccel_get_buffer = 0;
408  ist->hwaccel_retrieve_data = 0;
409 }
410 
412 {
413  InputStream *ist = avctx->opaque;
414  AVVAAPIDeviceContext *hwctx;
415  AVVAAPIFramesContext *avfc;
417  VAStatus vas;
418  int err;
419  int loglevel = (ist->hwaccel_id != HWACCEL_VAAPI ? AV_LOG_VERBOSE
420  : AV_LOG_ERROR);
421 
422  if (ist->hwaccel_ctx)
423  vaapi_decode_uninit(avctx);
424 
425  // We have -hwaccel without -vaapi_device, so just initialise here with
426  // the device passed as -hwaccel_device (if -vaapi_device was passed, it
427  // will always have been called before now).
428  if (!hw_device_ctx) {
429  err = vaapi_device_init(ist->hwaccel_device);
430  if (err < 0)
431  return err;
432  }
433 
434  ctx = av_mallocz(sizeof(*ctx));
435  if (!ctx)
436  return AVERROR(ENOMEM);
437  ctx->class = &vaapi_class;
438 
440  ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
441 
442  ctx->va_config = VA_INVALID_ID;
443  ctx->va_context = VA_INVALID_ID;
444 
445  hwctx = ctx->device->hwctx;
446 
448 
449  err = vaapi_build_decoder_config(ctx, avctx,
450  ist->hwaccel_id != HWACCEL_VAAPI);
451  if (err < 0) {
452  av_log(ctx, loglevel, "No supported configuration for this codec.");
453  goto fail;
454  }
455 
456  avctx->pix_fmt = ctx->output_format;
457 
459  if (!ctx->frames_ref) {
460  av_log(ctx, loglevel, "Failed to create VAAPI frame context.\n");
461  err = AVERROR(ENOMEM);
462  goto fail;
463  }
464 
465  ctx->frames = (AVHWFramesContext*)ctx->frames_ref->data;
466 
468  ctx->frames->sw_format = ctx->decode_format;
469  ctx->frames->width = ctx->decode_width;
470  ctx->frames->height = ctx->decode_height;
472 
473  err = av_hwframe_ctx_init(ctx->frames_ref);
474  if (err < 0) {
475  av_log(ctx, loglevel, "Failed to initialise VAAPI frame "
476  "context: %d\n", err);
477  goto fail;
478  }
479 
480  avfc = ctx->frames->hwctx;
481 
482  vas = vaCreateContext(hwctx->display, ctx->va_config,
483  ctx->decode_width, ctx->decode_height,
484  VA_PROGRESSIVE,
485  avfc->surface_ids, avfc->nb_surfaces,
486  &ctx->va_context);
487  if (vas != VA_STATUS_SUCCESS) {
488  av_log(ctx, AV_LOG_ERROR, "Failed to create decode pipeline "
489  "context: %d (%s).\n", vas, vaErrorStr(vas));
490  err = AVERROR(EINVAL);
491  goto fail;
492  }
493 
494  av_log(ctx, AV_LOG_DEBUG, "VAAPI decoder (re)init complete.\n");
495 
496  // We would like to set this on the AVCodecContext for use by whoever gets
497  // the frames from the decoder, but unfortunately the AVCodecContext we
498  // have here need not be the "real" one (H.264 makes many copies for
499  // threading purposes). To avoid the problem, we instead store it in the
500  // InputStream and propagate it from there.
502  if (!ist->hw_frames_ctx) {
503  err = AVERROR(ENOMEM);
504  goto fail;
505  }
506 
507  ist->hwaccel_ctx = ctx;
511 
512  ctx->decoder_vaapi_context.display = hwctx->display;
515  avctx->hwaccel_context = &ctx->decoder_vaapi_context;
516 
517  return 0;
518 
519 fail:
520  vaapi_decode_uninit(avctx);
521  return err;
522 }
523 
525 
526 av_cold int vaapi_device_init(const char *device)
527 {
528  int err;
529 
531  device, NULL, 0);
532  if (err < 0) {
533  av_log(&vaapi_log, AV_LOG_ERROR, "Failed to create a VAAPI device\n");
534  return err;
535  }
536 
537  return 0;
538 }
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:53
#define NULL
Definition: coverity.c:32
enum AVCodecID codec_id
Definition: ffmpeg_vaapi.c:149
static enum AVPixelFormat pix_fmt
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:124
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2222
VAAPI-specific data associated with a frame pool.
static const struct @25 vaapi_profile_map[]
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
AVHWDeviceContext * device
Definition: ffmpeg_vaapi.c:59
VAConfigID va_config
Definition: ffmpeg_vaapi.c:65
#define DEFAULT_SURFACES
Definition: ffmpeg_vaapi.c:53
AVBufferRef * hw_frames_ctx
Definition: ffmpeg.h:342
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1851
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static int vaapi_build_decoder_config(VAAPIDecoderContext *ctx, AVCodecContext *avctx, int fallback_allowed)
Definition: ffmpeg_vaapi.c:186
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
const AVClass * class
Definition: ffmpeg_vaapi.c:56
uint32_t context_id
Context ID (video decode pipeline)
Definition: vaapi.h:75
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:221
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1877
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
Definition: hwcontext.c:411
VAContextID va_context
Definition: ffmpeg_vaapi.c:66
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:201
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:508
This structure is used to share data between the FFmpeg library and the client video application...
Definition: vaapi.h:52
int(* hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags)
Definition: ffmpeg.h:338
int vaapi_decode_init(AVCodecContext *avctx)
Definition: ffmpeg_vaapi.c:411
int profile
profile
Definition: avcodec.h:3153
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
int max_width
The maximum size of frames in this hw_frames_ctx.
Definition: hwcontext.h:390
Definition: ftp.c:34
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition: hwcontext.c:447
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:140
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:2980
struct vaapi_context decoder_vaapi_context
Definition: ffmpeg_vaapi.c:79
AVOptions.
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:84
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition: hwcontext.c:456
VAEntrypoint va_entrypoint
Definition: ffmpeg_vaapi.c:64
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static AVClass vaapi_class
Definition: ffmpeg_vaapi.c:47
#define av_log(a,...)
enum AVPixelFormat output_format
Definition: ffmpeg_vaapi.c:77
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:189
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
VAAPI hardware pipeline configuration details.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
void(* hwaccel_uninit)(AVCodecContext *s)
Definition: ffmpeg.h:337
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:153
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3098
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
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.
Definition: hwcontext.c:260
static int vaapi_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: ffmpeg_vaapi.c:83
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:387
#define fail()
Definition: checkasm.h:81
int hwaccel_lax_profile_check
Definition: ffmpeg_opt.c:92
reference-counted frame API
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2956
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition: hwcontext.c:361
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:191
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3090
enum AVPixelFormat decode_format
Definition: ffmpeg_vaapi.c:68
AVHWFramesContext * frames
Definition: ffmpeg_vaapi.c:61
AVFormatContext * ctx
Definition: movenc.c:48
AVBufferRef * frames_ref
Definition: ffmpeg_vaapi.c:60
int(* hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame)
Definition: ffmpeg.h:339
#define FF_ARRAY_ELEMS(a)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3079
VADisplay display
The VADisplay handle, to be filled by the user.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
void * display
Window system dependent data.
Definition: vaapi.h:59
#define MAP(c, p, v)
int min_width
The minimum size of frames in this hw_frames_ctx.
Definition: hwcontext.h:383
av_cold int vaapi_device_init(const char *device)
Definition: ffmpeg_vaapi.c:526
VAProfile va_profile
Definition: ffmpeg_vaapi.c:63
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:365
enum AVCodecID codec_id
Definition: avcodec.h:1666
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:1649
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...
Definition: hwcontext.c:422
uint8_t * data
The data buffer.
Definition: buffer.h:89
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:154
AVBufferRef * device_ref
Definition: ffmpeg_vaapi.c:58
int coded_height
Definition: avcodec.h:1851
Describe the class of an AVClass context structure.
Definition: log.h:67
static int vaapi_retrieve_data(AVCodecContext *avctx, AVFrame *input)
Definition: ffmpeg_vaapi.c:99
Public libavcodec VA API header.
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:116
refcounted data buffer API
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:665
mfxU16 profile
Definition: qsvenc.c:42
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:657
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:332
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:484
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
A reference to a data buffer.
Definition: buffer.h:81
static void vaapi_decode_uninit(AVCodecContext *avctx)
Definition: ffmpeg_vaapi.c:381
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:174
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
int codec_profile
Definition: ffmpeg_vaapi.c:150
AVBufferRef * hw_device_ctx
Definition: ffmpeg_opt.c:93
pixel format definitions
#define av_free(p)
static AVClass * vaapi_log
Definition: ffmpeg_vaapi.c:524
void * hwaccel_ctx
Definition: ffmpeg.h:336
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:377
VAAPI connection details.
VAConfigID config_id
ID of a VAAPI pipeline configuration.
char * hwaccel_device
Definition: ffmpeg.h:331
#define av_freep(p)
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
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.
Definition: pixdesc.c:2138
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:330
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:214
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
VAProfile va_profile
Definition: ffmpeg_vaapi.c:151
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
void * opaque
Private data of the user, can be used to carry app specific stuff.
Definition: avcodec.h:1706
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:580
uint32_t config_id
Configuration ID.
Definition: vaapi.h:67