FFmpeg
hwcontext.h
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 AVUTIL_HWCONTEXT_H
20 #define AVUTIL_HWCONTEXT_H
21 
22 #include "buffer.h"
23 #include "frame.h"
24 #include "log.h"
25 #include "pixfmt.h"
26 
27 enum AVHWDeviceType {
28  AV_HWDEVICE_TYPE_NONE,
29  AV_HWDEVICE_TYPE_VDPAU,
30  AV_HWDEVICE_TYPE_CUDA,
31  AV_HWDEVICE_TYPE_VAAPI,
32  AV_HWDEVICE_TYPE_DXVA2,
33  AV_HWDEVICE_TYPE_QSV,
34  AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
35  AV_HWDEVICE_TYPE_D3D11VA,
36  AV_HWDEVICE_TYPE_DRM,
37  AV_HWDEVICE_TYPE_OPENCL,
38  AV_HWDEVICE_TYPE_MEDIACODEC,
39 };
40 
42 
60 typedef struct AVHWDeviceContext {
64  const AVClass *av_class;
65 
70  AVHWDeviceInternal *internal;
71 
78  enum AVHWDeviceType type;
79 
91  void *hwctx;
92 
103  void (*free)(struct AVHWDeviceContext *ctx);
104 
108  void *user_opaque;
110 
112 
123 typedef struct AVHWFramesContext {
128 
134 
141 
149 
161  void *hwctx;
162 
169  void (*free)(struct AVHWFramesContext *ctx);
170 
174  void *user_opaque;
175 
190 
199 
209 
222 
228  int width, height;
230 
238 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
239 
246 const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
247 
256 enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
257 
265 AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type);
266 
275 int av_hwdevice_ctx_init(AVBufferRef *ref);
276 
302 int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type,
303  const char *device, AVDictionary *opts, int flags);
304 
326 int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx,
327  enum AVHWDeviceType type,
328  AVBufferRef *src_ctx, int flags);
329 
330 
340 AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ctx);
341 
350 int av_hwframe_ctx_init(AVBufferRef *ref);
351 
361 int av_hwframe_get_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame, int flags);
362 
392 int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags);
393 
394 enum AVHWFrameTransferDirection {
398  AV_HWFRAME_TRANSFER_DIRECTION_FROM,
399 
403  AV_HWFRAME_TRANSFER_DIRECTION_TO,
404 };
405 
421 int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ctx,
422  enum AVHWFrameTransferDirection dir,
423  enum AVPixelFormat **formats, int flags);
424 
425 
432 typedef struct AVHWFramesConstraints {
438 
445 
451  int min_height;
452 
458  int max_height;
460 
471 void *av_hwdevice_hwconfig_alloc(AVBufferRef *device_ctx);
472 
485 AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
486  const void *hwconfig);
487 
493 void av_hwframe_constraints_free(AVHWFramesConstraints **constraints);
494 
495 
499 enum {
503  AV_HWFRAME_MAP_READ = 1 << 0,
507  AV_HWFRAME_MAP_WRITE = 1 << 1,
513  AV_HWFRAME_MAP_OVERWRITE = 1 << 2,
519  AV_HWFRAME_MAP_DIRECT = 1 << 3,
520 };
521 
558 int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags);
559 
560 
578 int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
579  enum AVPixelFormat format,
580  AVBufferRef *derived_device_ctx,
581  AVBufferRef *source_frame_ctx,
582  int flags);
583 
584 #endif /* AVUTIL_HWCONTEXT_H */
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
void * user_opaque
Arbitrary user data, to be used e.g.
Definition: hwcontext.h:174
int max_width
The maximum size of frames in this hw_frames_ctx.
Definition: hwcontext.h:457
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
Definition: buffer_internal.h:76
const AVClass * av_class
A class for logging.
Definition: hwcontext.h:127
Definition: dict.c:30
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:78
reference-counted frame API
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:198
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:148
Definition: hwcontext_internal.h:102
int min_width
The minimum size of frames in this hw_frames_ctx.
Definition: hwcontext.h:450
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:432
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:161
const AVClass * av_class
A class for logging.
Definition: hwcontext.h:64
Describe the class of an AVClass context structure.
Definition: log.h:67
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
Definition: hwcontext_internal.h:113
refcounted data buffer API
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:437
void * user_opaque
Arbitrary user data, to be used e.g.
Definition: hwcontext.h:108
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:140
A reference to a data buffer.
Definition: buffer.h:81
pixel format definitions
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
Definition: hwcontext.h:189
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:444
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
Definition: hwcontext.h:103
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60