]> git.sesse.net Git - ffmpeg/blob - libavcodec/amfenc.h
Add HW H.264 and HEVC encoding for AMD GPUs based on AMF SDK
[ffmpeg] / libavcodec / amfenc.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 AVCODEC_AMFENC_H
20 #define AVCODEC_AMFENC_H
21
22 #include <AMF/core/Factory.h>
23
24 #include <AMF/components/VideoEncoderVCE.h>
25 #include <AMF/components/VideoEncoderHEVC.h>
26
27 #include "libavutil/fifo.h"
28
29 #include "config.h"
30 #include "avcodec.h"
31
32
33 /**
34 * AMF trace writer callback class
35 * Used to capture all AMF logging
36 */
37
38 typedef struct AmfTraceWriter {
39     AMFTraceWriterVtbl *vtbl;
40     AVCodecContext     *avctx;
41 } AmfTraceWriter;
42
43 /**
44 * AMF encoder context
45 */
46
47 typedef struct AmfContext {
48     AVClass            *avclass;
49     // access to AMF runtime
50     amf_handle          library; ///< handle to DLL library
51     AMFFactory         *factory; ///< pointer to AMF factory
52     AMFDebug           *debug;   ///< pointer to AMF debug interface
53     AMFTrace           *trace;   ///< pointer to AMF trace interface
54
55     amf_uint64          version; ///< version of AMF runtime
56     AmfTraceWriter      tracer;  ///< AMF writer registered with AMF
57     AMFContext         *context; ///< AMF context
58     //encoder
59     AMFComponent       *encoder; ///< AMF encoder object
60     amf_bool            eof;     ///< flag indicating EOF happened
61     AMF_SURFACE_FORMAT  format;  ///< AMF surface format
62
63     AVBufferRef        *hw_device_ctx; ///< pointer to HW accelerator (decoder)
64     AVBufferRef        *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
65
66     // helpers to handle async calls
67     int                 delayed_drain;
68     AMFSurface         *delayed_surface;
69     AVFrame            *delayed_frame;
70
71     // shift dts back by max_b_frames in timing
72     AVFifoBuffer       *timestamp_list;
73     int64_t             dts_delay;
74
75     // common encoder option options
76
77     int                 log_to_dbg;
78
79     // Static options, have to be set before Init() call
80     int                 usage;
81     int                 profile;
82     int                 level;
83     int                 preanalysis;
84     int                 quality;
85     int                 b_frame_delta_qp;
86     int                 ref_b_frame_delta_qp;
87
88     // Dynamic options, can be set after Init() call
89
90     int                 rate_control_mode;
91     int                 enforce_hrd;
92     int                 filler_data;
93     int                 enable_vbaq;
94     int                 skip_frame;
95     int                 qp_i;
96     int                 qp_p;
97     int                 qp_b;
98     int                 max_au_size;
99     int                 header_spacing;
100     int                 b_frame_ref;
101     int                 intra_refresh_mb;
102     int                 coding_mode;
103     int                 me_half_pel;
104     int                 me_quarter_pel;
105     int                 aud;
106
107     // HEVC - specific options
108
109     int                 gops_per_idr;
110     int                 header_insertion_mode;
111     int                 min_qp_i;
112     int                 max_qp_i;
113     int                 min_qp_p;
114     int                 max_qp_p;
115     int                 tier;
116 } AmfContext;
117
118 /**
119 * Common encoder initization function
120 */
121 int ff_amf_encode_init(AVCodecContext *avctx);
122 /**
123 * Common encoder termination function
124 */
125 int ff_amf_encode_close(AVCodecContext *avctx);
126
127 /**
128 * Ecoding one frame - common function for all AMF encoders
129 */
130
131 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
132 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
133
134 /**
135 * Supported formats
136 */
137 extern const enum AVPixelFormat ff_amf_pix_fmts[];
138
139 /**
140 * Error handling helper
141 */
142 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
143     if (!(exp)) { \
144         av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
145         return ret_value; \
146     }
147
148 #endif //AVCODEC_AMFENC_H