FFmpeg
hwconfig.h
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 #ifndef AVCODEC_HWCONFIG_H
20 #define AVCODEC_HWCONFIG_H
21 
22 #include "avcodec.h"
23 #include "hwaccels.h"
24 
25 typedef struct AVCodecHWConfigInternal {
26  /**
27  * This is the structure which will be returned to the user by
28  * avcodec_get_hw_config().
29  */
31  /**
32  * If this configuration uses a hwaccel, a pointer to it.
33  * If not, NULL.
34  */
35  const struct FFHWAccel *hwaccel;
37 
39 
40 // These macros are used to simplify AVCodecHWConfigInternal definitions.
41 
42 #define HW_CONFIG_HWACCEL(device, frames, ad_hoc, format, device_type_, name) \
43  &(const AVCodecHWConfigInternal) { \
44  .public = { \
45  .pix_fmt = AV_PIX_FMT_ ## format, \
46  .methods = (device ? AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
47  (frames ? AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
48  (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0), \
49  .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
50  }, \
51  .hwaccel = &name, \
52  }
53 
54 #define HW_CONFIG_INTERNAL(format) \
55  &(const AVCodecHWConfigInternal) { \
56  .public = { \
57  .pix_fmt = AV_PIX_FMT_ ## format, \
58  .methods = AV_CODEC_HW_CONFIG_METHOD_INTERNAL, \
59  .device_type = AV_HWDEVICE_TYPE_NONE, \
60  }, \
61  .hwaccel = NULL, \
62  }
63 
64 #define HWACCEL_DXVA2(codec) \
65  HW_CONFIG_HWACCEL(1, 1, 1, DXVA2_VLD, DXVA2, ff_ ## codec ## _dxva2_hwaccel)
66 #define HWACCEL_D3D11VA2(codec) \
67  HW_CONFIG_HWACCEL(1, 1, 0, D3D11, D3D11VA, ff_ ## codec ## _d3d11va2_hwaccel)
68 #define HWACCEL_NVDEC(codec) \
69  HW_CONFIG_HWACCEL(1, 1, 0, CUDA, CUDA, ff_ ## codec ## _nvdec_hwaccel)
70 #define HWACCEL_VAAPI(codec) \
71  HW_CONFIG_HWACCEL(1, 1, 1, VAAPI, VAAPI, ff_ ## codec ## _vaapi_hwaccel)
72 #define HWACCEL_VDPAU(codec) \
73  HW_CONFIG_HWACCEL(1, 1, 1, VDPAU, VDPAU, ff_ ## codec ## _vdpau_hwaccel)
74 #define HWACCEL_VIDEOTOOLBOX(codec) \
75  HW_CONFIG_HWACCEL(1, 1, 1, VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec ## _videotoolbox_hwaccel)
76 #define HWACCEL_VULKAN(codec) \
77  HW_CONFIG_HWACCEL(1, 1, 1, VULKAN, VULKAN, ff_ ## codec ## _vulkan_hwaccel)
78 #define HWACCEL_D3D11VA(codec) \
79  HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD, NONE, ff_ ## codec ## _d3d11va_hwaccel)
80 
81 #define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \
82  &(const AVCodecHWConfigInternal) { \
83  .public = { \
84  .pix_fmt = AV_PIX_FMT_ ## format, \
85  .methods = (device ? AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
86  (frames ? AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
87  (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0), \
88  .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
89  }, \
90  .hwaccel = NULL, \
91  }
92 
93 #define HW_CONFIG_ENCODER_DEVICE(format, device_type_) \
94  HW_CONFIG_ENCODER(1, 0, 0, format, device_type_)
95 
96 #define HW_CONFIG_ENCODER_FRAMES(format, device_type_) \
97  HW_CONFIG_ENCODER(0, 1, 0, format, device_type_)
98 
99 #endif /* AVCODEC_HWCONFIG_H */
hwaccels.h
FFHWAccel
Definition: hwaccel_internal.h:34
AVCodecHWConfigInternal::hwaccel
const struct FFHWAccel * hwaccel
If this configuration uses a hwaccel, a pointer to it.
Definition: hwconfig.h:35
ff_hwaccel_uninit
void ff_hwaccel_uninit(AVCodecContext *avctx)
Definition: decode.c:1252
AVCodecHWConfigInternal
Definition: hwconfig.h:25
avcodec.h
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AVCodecHWConfig
Definition: codec.h:341