]> git.sesse.net Git - ffmpeg/blob - libavcodec/amfenc.h
6d13eb05ac1e686a88c77c13b747d75b19deffa0
[ffmpeg] / libavcodec / amfenc.h
1 /*
2  * AMD AMF support
3  * Copyright (C) 2017 Luca Barbato
4  * Copyright (C) 2017 Mikhail Mironov <mikhail.mironov@amd.com>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23
24 #ifndef AVCODEC_AMFENC_H
25 #define AVCODEC_AMFENC_H
26
27 #include <AMF/core/Factory.h>
28
29 #include <AMF/components/VideoEncoderVCE.h>
30 #include <AMF/components/VideoEncoderHEVC.h>
31
32 #include "libavutil/fifo.h"
33
34 #include "config.h"
35 #include "avcodec.h"
36
37
38 /**
39 * AMF trace writer callback class
40 * Used to capture all AMF logging
41 */
42
43 typedef struct AmfTraceWriter {
44     AMFTraceWriterVtbl *vtbl;
45     AVCodecContext     *avctx;
46 } AmfTraceWriter;
47
48 /**
49 * AMF encoder context
50 */
51
52 typedef struct AmfContext {
53     AVClass            *avclass;
54     // access to AMF runtime
55     amf_handle          library; ///< handle to DLL library
56     AMFFactory         *factory; ///< pointer to AMF factory
57     AMFDebug           *debug;   ///< pointer to AMF debug interface
58     AMFTrace           *trace;   ///< pointer to AMF trace interface
59
60     amf_uint64          version; ///< version of AMF runtime
61     AmfTraceWriter      tracer;  ///< AMF writer registered with AMF
62     AMFContext         *context; ///< AMF context
63     //encoder
64     AMFComponent       *encoder; ///< AMF encoder object
65     amf_bool            eof;     ///< flag indicating EOF happened
66     AMF_SURFACE_FORMAT  format;  ///< AMF surface format
67
68     AVBufferRef        *hw_device_ctx; ///< pointer to HW accelerator (decoder)
69     AVBufferRef        *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
70
71     int                 hwsurfaces_in_queue;
72     int                 hwsurfaces_in_queue_max;
73
74     // helpers to handle async calls
75     int                 delayed_drain;
76     AMFSurface         *delayed_surface;
77     AVFrame            *delayed_frame;
78
79     // shift dts back by max_b_frames in timing
80     AVFifoBuffer       *timestamp_list;
81     int64_t             timestamp_last;
82     int64_t             dts_delay;
83
84     // common encoder options
85     int                 log_to_dbg;
86
87     // Static options, have to be set before Init() call
88     int                 usage;
89     int                 profile;
90     int                 level;
91     int                 preanalysis;
92     int                 quality;
93     int                 b_frame_delta_qp;
94     int                 ref_b_frame_delta_qp;
95
96     // Dynamic options, can be set after Init() call
97
98     int                 rate_control_mode;
99     int                 enforce_hrd;
100     int                 filler_data;
101     int                 enable_vbaq;
102     int                 skip_frame;
103     int                 qp_i;
104     int                 qp_p;
105     int                 qp_b;
106     int                 max_au_size;
107     int                 header_spacing;
108     int                 b_frame_ref;
109     int                 intra_refresh_mb;
110     int                 coding_mode;
111     int                 me_half_pel;
112     int                 me_quarter_pel;
113     int                 aud;
114
115     // HEVC - specific options
116
117     int                 gops_per_idr;
118     int                 header_insertion_mode;
119     int                 min_qp_i;
120     int                 max_qp_i;
121     int                 min_qp_p;
122     int                 max_qp_p;
123     int                 tier;
124 } AmfContext;
125
126 /**
127 * Common encoder initization function
128 */
129 int ff_amf_encode_init(AVCodecContext *avctx);
130 /**
131 * Common encoder termination function
132 */
133 int ff_amf_encode_close(AVCodecContext *avctx);
134
135 /**
136 * Ecoding one frame - common function for all AMF encoders
137 */
138
139 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
140 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
141
142 /**
143 * Supported formats
144 */
145 extern const enum AVPixelFormat ff_amf_pix_fmts[];
146
147 /**
148 * Error handling helper
149 */
150 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
151     if (!(exp)) { \
152         av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
153         return ret_value; \
154     }
155
156 #define AMF_COMMON_OPTIONS \
157     { "log_to_dbg",     "Enable AMF logging to debug output",   OFFSET(log_to_dbg), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE } \
158
159 #endif //AVCODEC_AMFENC_H