FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vaapi_decode.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 "libavutil/avassert.h"
20 #include "libavutil/common.h"
21 #include "libavutil/pixdesc.h"
22 
23 #include "avcodec.h"
24 #include "internal.h"
25 #include "vaapi_decode.h"
26 
27 
29  VAAPIDecodePicture *pic,
30  int type,
31  const void *data,
32  size_t size)
33 {
35  VAStatus vas;
36  VABufferID buffer;
37 
39 
40  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
41  type, size, 1, (void*)data, &buffer);
42  if (vas != VA_STATUS_SUCCESS) {
43  av_log(avctx, AV_LOG_ERROR, "Failed to create parameter "
44  "buffer (type %d): %d (%s).\n",
45  type, vas, vaErrorStr(vas));
46  return AVERROR(EIO);
47  }
48 
49  pic->param_buffers[pic->nb_param_buffers++] = buffer;
50 
51  av_log(avctx, AV_LOG_DEBUG, "Param buffer (type %d, %zu bytes) "
52  "is %#x.\n", type, size, buffer);
53  return 0;
54 }
55 
56 
58  VAAPIDecodePicture *pic,
59  const void *params_data,
60  size_t params_size,
61  const void *slice_data,
62  size_t slice_size)
63 {
65  VAStatus vas;
66  int index;
67 
69  if (pic->nb_slices == pic->slices_allocated) {
70  if (pic->slices_allocated > 0)
71  pic->slices_allocated *= 2;
72  else
73  pic->slices_allocated = 64;
74 
75  pic->slice_buffers =
77  pic->slices_allocated,
78  2 * sizeof(*pic->slice_buffers));
79  if (!pic->slice_buffers)
80  return AVERROR(ENOMEM);
81  }
82  av_assert0(pic->nb_slices + 1 <= pic->slices_allocated);
83 
84  index = 2 * pic->nb_slices;
85 
86  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
87  VASliceParameterBufferType,
88  params_size, 1, (void*)params_data,
89  &pic->slice_buffers[index]);
90  if (vas != VA_STATUS_SUCCESS) {
91  av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
92  "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
93  return AVERROR(EIO);
94  }
95 
96  av_log(avctx, AV_LOG_DEBUG, "Slice %d param buffer (%zu bytes) "
97  "is %#x.\n", pic->nb_slices, params_size,
98  pic->slice_buffers[index]);
99 
100  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
101  VASliceDataBufferType,
102  slice_size, 1, (void*)slice_data,
103  &pic->slice_buffers[index + 1]);
104  if (vas != VA_STATUS_SUCCESS) {
105  av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
106  "data buffer (size %zu): %d (%s).\n",
107  slice_size, vas, vaErrorStr(vas));
108  vaDestroyBuffer(ctx->hwctx->display,
109  pic->slice_buffers[index]);
110  return AVERROR(EIO);
111  }
112 
113  av_log(avctx, AV_LOG_DEBUG, "Slice %d data buffer (%zu bytes) "
114  "is %#x.\n", pic->nb_slices, slice_size,
115  pic->slice_buffers[index + 1]);
116 
117  ++pic->nb_slices;
118  return 0;
119 }
120 
122  VAAPIDecodePicture *pic)
123 {
125  VAStatus vas;
126  int i;
127 
128  for (i = 0; i < pic->nb_param_buffers; i++) {
129  vas = vaDestroyBuffer(ctx->hwctx->display,
130  pic->param_buffers[i]);
131  if (vas != VA_STATUS_SUCCESS) {
132  av_log(avctx, AV_LOG_ERROR, "Failed to destroy "
133  "parameter buffer %#x: %d (%s).\n",
134  pic->param_buffers[i], vas, vaErrorStr(vas));
135  }
136  }
137 
138  for (i = 0; i < 2 * pic->nb_slices; i++) {
139  vas = vaDestroyBuffer(ctx->hwctx->display,
140  pic->slice_buffers[i]);
141  if (vas != VA_STATUS_SUCCESS) {
142  av_log(avctx, AV_LOG_ERROR, "Failed to destroy slice "
143  "slice buffer %#x: %d (%s).\n",
144  pic->slice_buffers[i], vas, vaErrorStr(vas));
145  }
146  }
147 }
148 
150  VAAPIDecodePicture *pic)
151 {
153  VAStatus vas;
154  int err;
155 
156  av_log(avctx, AV_LOG_DEBUG, "Decode to surface %#x.\n",
157  pic->output_surface);
158 
159  vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
160  pic->output_surface);
161  if (vas != VA_STATUS_SUCCESS) {
162  av_log(avctx, AV_LOG_ERROR, "Failed to begin picture decode "
163  "issue: %d (%s).\n", vas, vaErrorStr(vas));
164  err = AVERROR(EIO);
165  goto fail_with_picture;
166  }
167 
168  vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
169  pic->param_buffers, pic->nb_param_buffers);
170  if (vas != VA_STATUS_SUCCESS) {
171  av_log(avctx, AV_LOG_ERROR, "Failed to upload decode "
172  "parameters: %d (%s).\n", vas, vaErrorStr(vas));
173  err = AVERROR(EIO);
174  goto fail_with_picture;
175  }
176 
177  vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context,
178  pic->slice_buffers, 2 * pic->nb_slices);
179  if (vas != VA_STATUS_SUCCESS) {
180  av_log(avctx, AV_LOG_ERROR, "Failed to upload slices: "
181  "%d (%s).\n", vas, vaErrorStr(vas));
182  err = AVERROR(EIO);
183  goto fail_with_picture;
184  }
185 
186  vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
187  if (vas != VA_STATUS_SUCCESS) {
188  av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
189  "issue: %d (%s).\n", vas, vaErrorStr(vas));
190  err = AVERROR(EIO);
191  if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
193  goto fail;
194  else
195  goto fail_at_end;
196  }
197 
198  if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
201 
202  pic->nb_param_buffers = 0;
203  pic->nb_slices = 0;
204  pic->slices_allocated = 0;
205  av_freep(&pic->slice_buffers);
206 
207  return 0;
208 
209 fail_with_picture:
210  vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
211  if (vas != VA_STATUS_SUCCESS) {
212  av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
213  "after error: %d (%s).\n", vas, vaErrorStr(vas));
214  }
215 fail:
217 fail_at_end:
218  return err;
219 }
220 
222  VAAPIDecodePicture *pic)
223 {
225 
226  pic->nb_param_buffers = 0;
227  pic->nb_slices = 0;
228  pic->slices_allocated = 0;
229  av_freep(&pic->slice_buffers);
230 
231  return 0;
232 }
233 
234 static const struct {
237  VAProfile va_profile;
238 } vaapi_profile_map[] = {
239 #define MAP(c, p, v) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v }
240  MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
241  MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
242  MAP(H263, UNKNOWN, H263Baseline),
243  MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
244  MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
245  MPEG4AdvancedSimple),
246  MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
247  MAP(H264, H264_CONSTRAINED_BASELINE,
248  H264ConstrainedBaseline),
249  MAP(H264, H264_MAIN, H264Main ),
250  MAP(H264, H264_HIGH, H264High ),
251 #if VA_CHECK_VERSION(0, 37, 0)
252  MAP(HEVC, HEVC_MAIN, HEVCMain ),
253  MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
254 #endif
255  MAP(WMV3, VC1_SIMPLE, VC1Simple ),
256  MAP(WMV3, VC1_MAIN, VC1Main ),
257  MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
258  MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
259  MAP(VC1, VC1_SIMPLE, VC1Simple ),
260  MAP(VC1, VC1_MAIN, VC1Main ),
261  MAP(VC1, VC1_COMPLEX, VC1Advanced ),
262  MAP(VC1, VC1_ADVANCED, VC1Advanced ),
263 #if VA_CHECK_VERSION(0, 35, 0)
264  MAP(VP8, UNKNOWN, VP8Version0_3 ),
265 #endif
266 #if VA_CHECK_VERSION(0, 38, 0)
267  MAP(VP9, VP9_0, VP9Profile0 ),
268 #endif
269 #if VA_CHECK_VERSION(0, 39, 0)
270  MAP(VP9, VP9_2, VP9Profile2 ),
271 #endif
272 #undef MAP
273 };
274 
276 {
278 
279  AVVAAPIHWConfig *hwconfig = NULL;
280  AVHWFramesConstraints *constraints = NULL;
281  VAStatus vas;
282  int err, i, j;
283  const AVCodecDescriptor *codec_desc;
284  VAProfile profile, va_profile, *profile_list = NULL;
285  int profile_count, exact_match, alt_profile;
286  const AVPixFmtDescriptor *sw_desc, *desc;
287 
288  codec_desc = avcodec_descriptor_get(avctx->codec_id);
289  if (!codec_desc) {
290  err = AVERROR(EINVAL);
291  goto fail;
292  }
293 
294  profile_count = vaMaxNumProfiles(ctx->hwctx->display);
295  profile_list = av_malloc_array(profile_count,
296  sizeof(VAProfile));
297  if (!profile_list) {
298  err = AVERROR(ENOMEM);
299  goto fail;
300  }
301 
302  vas = vaQueryConfigProfiles(ctx->hwctx->display,
303  profile_list, &profile_count);
304  if (vas != VA_STATUS_SUCCESS) {
305  av_log(avctx, AV_LOG_ERROR, "Failed to query profiles: "
306  "%d (%s).\n", vas, vaErrorStr(vas));
307  err = AVERROR(ENOSYS);
308  goto fail;
309  }
310 
311  profile = VAProfileNone;
312  exact_match = 0;
313 
314  for (i = 0; i < FF_ARRAY_ELEMS(vaapi_profile_map); i++) {
315  int profile_match = 0;
316  if (avctx->codec_id != vaapi_profile_map[i].codec_id)
317  continue;
318  if (avctx->profile == vaapi_profile_map[i].codec_profile)
319  profile_match = 1;
320  profile = vaapi_profile_map[i].va_profile;
321  for (j = 0; j < profile_count; j++) {
322  if (profile == profile_list[j]) {
323  exact_match = profile_match;
324  break;
325  }
326  }
327  if (j < profile_count) {
328  if (exact_match)
329  break;
330  alt_profile = vaapi_profile_map[i].codec_profile;
331  va_profile = vaapi_profile_map[i].va_profile;
332  }
333  }
334  av_freep(&profile_list);
335 
336  if (profile == VAProfileNone) {
337  av_log(avctx, AV_LOG_ERROR, "No support for codec %s "
338  "profile %d.\n", codec_desc->name, avctx->profile);
339  err = AVERROR(ENOSYS);
340  goto fail;
341  }
342  if (!exact_match) {
343  if (avctx->hwaccel_flags &
345  av_log(avctx, AV_LOG_VERBOSE, "Codec %s profile %d not "
346  "supported for hardware decode.\n",
347  codec_desc->name, avctx->profile);
348  av_log(avctx, AV_LOG_WARNING, "Using possibly-"
349  "incompatible profile %d instead.\n",
350  alt_profile);
351  profile = va_profile;
352  } else {
353  av_log(avctx, AV_LOG_VERBOSE, "Codec %s profile %d not "
354  "supported for hardware decode.\n",
355  codec_desc->name, avctx->profile);
356  err = AVERROR(EINVAL);
357  goto fail;
358  }
359  }
360 
361  ctx->va_profile = profile;
362  ctx->va_entrypoint = VAEntrypointVLD;
363 
364  vas = vaCreateConfig(ctx->hwctx->display, ctx->va_profile,
365  ctx->va_entrypoint, NULL, 0,
366  &ctx->va_config);
367  if (vas != VA_STATUS_SUCCESS) {
368  av_log(avctx, AV_LOG_ERROR, "Failed to create decode "
369  "configuration: %d (%s).\n", vas, vaErrorStr(vas));
370  err = AVERROR(EIO);
371  goto fail;
372  }
373 
374  hwconfig = av_hwdevice_hwconfig_alloc(avctx->hw_device_ctx ?
375  avctx->hw_device_ctx :
376  ctx->frames->device_ref);
377  if (!hwconfig) {
378  err = AVERROR(ENOMEM);
379  goto fail;
380  }
381  hwconfig->config_id = ctx->va_config;
382 
383  constraints =
385  avctx->hw_device_ctx :
386  ctx->frames->device_ref,
387  hwconfig);
388  if (!constraints) {
389  err = AVERROR(ENOMEM);
390  goto fail;
391  }
392 
393  if (avctx->coded_width < constraints->min_width ||
394  avctx->coded_height < constraints->min_height ||
395  avctx->coded_width > constraints->max_width ||
396  avctx->coded_height > constraints->max_height) {
397  av_log(avctx, AV_LOG_ERROR, "Hardware does not support image "
398  "size %dx%d (constraints: width %d-%d height %d-%d).\n",
399  avctx->coded_width, avctx->coded_height,
400  constraints->min_width, constraints->max_width,
401  constraints->min_height, constraints->max_height);
402  err = AVERROR(EINVAL);
403  goto fail;
404  }
405  if (!constraints->valid_sw_formats ||
406  constraints->valid_sw_formats[0] == AV_PIX_FMT_NONE) {
407  av_log(avctx, AV_LOG_ERROR, "Hardware does not offer any "
408  "usable surface formats.\n");
409  err = AVERROR(EINVAL);
410  goto fail;
411  }
412 
413  // Find the first format in the list which matches the expected
414  // bit depth and subsampling. If none are found (this can happen
415  // when 10-bit streams are decoded to 8-bit surfaces, for example)
416  // then just take the first format on the list.
417  ctx->surface_format = constraints->valid_sw_formats[0];
418  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
419  for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
420  desc = av_pix_fmt_desc_get(constraints->valid_sw_formats[i]);
421  if (desc->nb_components != sw_desc->nb_components ||
422  desc->log2_chroma_w != sw_desc->log2_chroma_w ||
423  desc->log2_chroma_h != sw_desc->log2_chroma_h)
424  continue;
425  for (j = 0; j < desc->nb_components; j++) {
426  if (desc->comp[j].depth != sw_desc->comp[j].depth)
427  break;
428  }
429  if (j < desc->nb_components)
430  continue;
431  ctx->surface_format = constraints->valid_sw_formats[i];
432  break;
433  }
434 
435  // Start with at least four surfaces.
436  ctx->surface_count = 4;
437  // Add per-codec number of surfaces used for storing reference frames.
438  switch (avctx->codec_id) {
439  case AV_CODEC_ID_H264:
440  case AV_CODEC_ID_HEVC:
441  ctx->surface_count += 16;
442  break;
443  case AV_CODEC_ID_VP9:
444  ctx->surface_count += 8;
445  break;
446  case AV_CODEC_ID_VP8:
447  ctx->surface_count += 3;
448  break;
449  default:
450  ctx->surface_count += 2;
451  }
452  // Add an additional surface per thread is frame threading is enabled.
453  if (avctx->active_thread_type & FF_THREAD_FRAME)
454  ctx->surface_count += avctx->thread_count;
455 
456  av_hwframe_constraints_free(&constraints);
457  av_freep(&hwconfig);
458 
459  return 0;
460 
461 fail:
462  av_hwframe_constraints_free(&constraints);
463  av_freep(&hwconfig);
464  if (ctx->va_config != VA_INVALID_ID) {
465  vaDestroyConfig(ctx->hwctx->display, ctx->va_config);
466  ctx->va_config = VA_INVALID_ID;
467  }
468  av_freep(&profile_list);
469  return err;
470 }
471 
473 {
475  VAStatus vas;
476  int err;
477 
478  ctx->va_config = VA_INVALID_ID;
479  ctx->va_context = VA_INVALID_ID;
480 
481 #if FF_API_STRUCT_VAAPI_CONTEXT
482  if (avctx->hwaccel_context) {
483  av_log(avctx, AV_LOG_WARNING, "Using deprecated struct "
484  "vaapi_context in decode.\n");
485 
486  ctx->have_old_context = 1;
487  ctx->old_context = avctx->hwaccel_context;
488 
489  // Really we only want the VAAPI device context, but this
490  // allocates a whole generic device context because we don't
491  // have any other way to determine how big it should be.
492  ctx->device_ref =
494  if (!ctx->device_ref) {
495  err = AVERROR(ENOMEM);
496  goto fail;
497  }
498  ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
499  ctx->hwctx = ctx->device->hwctx;
500 
501  ctx->hwctx->display = ctx->old_context->display;
502 
503  // The old VAAPI decode setup assumed this quirk was always
504  // present, so set it here to avoid the behaviour changing.
505  ctx->hwctx->driver_quirks =
507 
508  } else
509 #endif
510  if (avctx->hw_frames_ctx) {
511  // This structure has a shorter lifetime than the enclosing
512  // AVCodecContext, so we inherit the references from there
513  // and do not need to make separate ones.
514 
515  ctx->frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
516  ctx->hwfc = ctx->frames->hwctx;
517  ctx->device = ctx->frames->device_ctx;
518  ctx->hwctx = ctx->device->hwctx;
519 
520  } else if (avctx->hw_device_ctx) {
521  ctx->device = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
522  ctx->hwctx = ctx->device->hwctx;
523 
524  if (ctx->device->type != AV_HWDEVICE_TYPE_VAAPI) {
525  av_log(avctx, AV_LOG_ERROR, "Device supplied for VAAPI "
526  "decoding must be a VAAPI device (not %d).\n",
527  ctx->device->type);
528  err = AVERROR(EINVAL);
529  goto fail;
530  }
531 
532  } else {
533  av_log(avctx, AV_LOG_ERROR, "A hardware device or frames context "
534  "is required for VAAPI decoding.\n");
535  err = AVERROR(EINVAL);
536  goto fail;
537  }
538 
539 #if FF_API_STRUCT_VAAPI_CONTEXT
540  if (ctx->have_old_context) {
541  ctx->va_config = ctx->old_context->config_id;
542  ctx->va_context = ctx->old_context->context_id;
543 
544  av_log(avctx, AV_LOG_DEBUG, "Using user-supplied decoder "
545  "context: %#x/%#x.\n", ctx->va_config, ctx->va_context);
546  } else {
547 #endif
548 
549  err = vaapi_decode_make_config(avctx);
550  if (err)
551  goto fail;
552 
553  if (!avctx->hw_frames_ctx) {
555  if (!avctx->hw_frames_ctx) {
556  err = AVERROR(ENOMEM);
557  goto fail;
558  }
559  ctx->frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
560 
562  ctx->frames->width = avctx->coded_width;
563  ctx->frames->height = avctx->coded_height;
564 
565  ctx->frames->sw_format = ctx->surface_format;
567 
568  err = av_hwframe_ctx_init(avctx->hw_frames_ctx);
569  if (err < 0) {
570  av_log(avctx, AV_LOG_ERROR, "Failed to initialise internal "
571  "frames context: %d.\n", err);
572  goto fail;
573  }
574 
575  ctx->hwfc = ctx->frames->hwctx;
576  }
577 
578  vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
579  avctx->coded_width, avctx->coded_height,
580  VA_PROGRESSIVE,
581  ctx->hwfc->surface_ids,
582  ctx->hwfc->nb_surfaces,
583  &ctx->va_context);
584  if (vas != VA_STATUS_SUCCESS) {
585  av_log(avctx, AV_LOG_ERROR, "Failed to create decode "
586  "context: %d (%s).\n", vas, vaErrorStr(vas));
587  err = AVERROR(EIO);
588  goto fail;
589  }
590 
591  av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: "
592  "%#x/%#x.\n", ctx->va_config, ctx->va_context);
593 #if FF_API_STRUCT_VAAPI_CONTEXT
594  }
595 #endif
596 
597  return 0;
598 
599 fail:
600  ff_vaapi_decode_uninit(avctx);
601  return err;
602 }
603 
605 {
607  VAStatus vas;
608 
609 #if FF_API_STRUCT_VAAPI_CONTEXT
610  if (ctx->have_old_context) {
612  } else {
613 #endif
614 
615  if (ctx->va_context != VA_INVALID_ID) {
616  vas = vaDestroyContext(ctx->hwctx->display, ctx->va_context);
617  if (vas != VA_STATUS_SUCCESS) {
618  av_log(avctx, AV_LOG_ERROR, "Failed to destroy decode "
619  "context %#x: %d (%s).\n",
620  ctx->va_context, vas, vaErrorStr(vas));
621  }
622  }
623  if (ctx->va_config != VA_INVALID_ID) {
624  vas = vaDestroyConfig(ctx->hwctx->display, ctx->va_config);
625  if (vas != VA_STATUS_SUCCESS) {
626  av_log(avctx, AV_LOG_ERROR, "Failed to destroy decode "
627  "configuration %#x: %d (%s).\n",
628  ctx->va_config, vas, vaErrorStr(vas));
629  }
630  }
631 
632 #if FF_API_STRUCT_VAAPI_CONTEXT
633  }
634 #endif
635 
636  return 0;
637 }
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:58
#define NULL
Definition: coverity.c:32
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:125
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2419
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1963
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
const char * desc
Definition: nvenc.c:60
static void ff_vaapi_decode_destroy_buffers(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:121
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, int type, const void *data, size_t size)
Definition: vaapi_decode.c:28
#define MAP(c, p, v)
uint32_t context_id
Context ID (video decode pipeline)
Definition: vaapi.h:79
FF_ENABLE_DEPRECATION_WARNINGS AVHWDeviceContext * device
Definition: vaapi_decode.h:69
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:226
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
Definition: hwcontext.c:518
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:206
int profile
profile
Definition: avcodec.h:3266
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:455
Definition: ftp.c:34
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition: hwcontext.c:554
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_vaapi_decode_uninit(AVCodecContext *avctx)
Definition: vaapi_decode.c:604
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:3094
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:149
static int vaapi_decode_make_config(AVCodecContext *avctx)
Definition: vaapi_decode.c:275
AVHWFramesContext * frames
Definition: vaapi_decode.h:72
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:89
AVVAAPIDeviceContext * hwctx
Definition: vaapi_decode.h:70
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
enum AVPixelFormat surface_format
Definition: vaapi_decode.h:75
ptrdiff_t size
Definition: opengl_enc.c:101
VAEntrypoint va_entrypoint
Definition: vaapi_decode.h:57
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:184
#define av_log(a,...)
int codec_profile
Definition: vaapi_decode.c:236
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:214
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVVAAPIFramesContext * hwfc
Definition: vaapi_decode.h:73
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
#define AVERROR(e)
Definition: error.h:43
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3211
#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().
VAProfile va_profile
Definition: vaapi_decode.c:237
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:323
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:76
#define fail()
Definition: checkasm.h:109
FF_DISABLE_DEPRECATION_WARNINGS int have_old_context
Definition: vaapi_decode.h:63
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3121
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:196
VAProfile va_profile
Definition: vaapi_decode.h:56
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:3203
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:146
int ff_vaapi_decode_init(AVCodecContext *avctx)
Definition: vaapi_decode.c:472
AVBufferRef * device_ref
Definition: vaapi_decode.h:65
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3616
AVFormatContext * ctx
Definition: movenc.c:48
VABufferID * slice_buffers
Definition: vaapi_decode.h:51
enum AVCodecID codec_id
Definition: vaapi_decode.c:235
struct vaapi_context * old_context
Definition: vaapi_decode.h:64
#define FF_ARRAY_ELEMS(a)
VABufferID param_buffers[MAX_PARAM_BUFFERS]
Definition: vaapi_decode.h:48
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3192
VADisplay display
The VADisplay handle, to be filled by the user.
VASurfaceID output_surface
Definition: vaapi_decode.h:45
void * display
Window system dependent data.
Definition: vaapi.h:63
int min_width
The minimum size of frames in this hw_frames_ctx.
Definition: hwcontext.h:448
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
Definition: hwcontext.c:129
Libavcodec external API header.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:430
enum AVCodecID codec_id
Definition: avcodec.h:1778
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:1761
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:529
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:159
unsigned int driver_quirks
Driver quirks to apply - this is filled by av_hwdevice_ctx_init(), with reference to a table of known...
GLint GLenum type
Definition: opengl_enc.c:105
int coded_height
Definition: avcodec.h:1963
int index
Definition: gxfenc.c:89
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:121
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:711
int ff_vaapi_decode_cancel(AVCodecContext *avctx, VAAPIDecodePicture *pic)
Definition: vaapi_decode.c:221
mfxU16 profile
Definition: qsvenc.c:44
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:703
VAContextID va_context
Definition: vaapi_decode.h:59
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:138
common internal api header.
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:237
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:192
VAConfigID va_config
Definition: vaapi_decode.h:58
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1811
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:442
VAConfigID config_id
ID of a VAAPI pipeline configuration.
#define av_freep(p)
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH
Hardware acceleration should still be attempted for decoding when the codec profile does not match th...
Definition: avcodec.h:4040
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active)...
Definition: avcodec.h:3677
#define av_malloc_array(a, b)
static const struct @124 vaapi_profile_map[]
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:3668
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:219
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, size_t params_size, const void *slice_data, size_t slice_size)
Definition: vaapi_decode.c:57
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3467
GLuint buffer
Definition: opengl_enc.c:102
uint32_t config_id
Configuration ID.
Definition: vaapi.h:71