]> git.sesse.net Git - ffmpeg/blob - libavcodec/amfenc.h
lavc: Add support for increasing hardware frame pool sizes
[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     // helpers to handle async calls
72     int                 delayed_drain;
73     AMFSurface         *delayed_surface;
74     AVFrame            *delayed_frame;
75
76     // shift dts back by max_b_frames in timing
77     AVFifoBuffer       *timestamp_list;
78     int64_t             timestamp_last;
79     int64_t             dts_delay;
80
81     // common encoder options
82     int                 log_to_dbg;
83     char                *writer_id;
84
85     // Static options, have to be set before Init() call
86     int                 usage;
87     int                 profile;
88     int                 level;
89     int                 preanalysis;
90     int                 quality;
91     int                 b_frame_delta_qp;
92     int                 ref_b_frame_delta_qp;
93
94     // Dynamic options, can be set after Init() call
95
96     int                 rate_control_mode;
97     int                 enforce_hrd;
98     int                 filler_data;
99     int                 enable_vbaq;
100     int                 skip_frame;
101     int                 qp_i;
102     int                 qp_p;
103     int                 qp_b;
104     int                 max_au_size;
105     int                 header_spacing;
106     int                 b_frame_ref;
107     int                 intra_refresh_mb;
108     int                 coding_mode;
109     int                 me_half_pel;
110     int                 me_quarter_pel;
111     int                 aud;
112
113     // HEVC - specific options
114
115     int                 gops_per_idr;
116     int                 header_insertion_mode;
117     int                 min_qp_i;
118     int                 max_qp_i;
119     int                 min_qp_p;
120     int                 max_qp_p;
121     int                 tier;
122 } AmfContext;
123
124 /**
125 * Common encoder initization function
126 */
127 int ff_amf_encode_init(AVCodecContext *avctx);
128 /**
129 * Common encoder termination function
130 */
131 int ff_amf_encode_close(AVCodecContext *avctx);
132
133 /**
134 * Ecoding one frame - common function for all AMF encoders
135 */
136
137 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
138 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
139
140 /**
141 * Supported formats
142 */
143 extern const enum AVPixelFormat ff_amf_pix_fmts[];
144
145 /**
146 * Error handling helper
147 */
148 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
149     if (!(exp)) { \
150         av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
151         return ret_value; \
152     }
153
154 #define AMF_COMMON_OPTIONS \
155     { "log_to_dbg",     "Enable AMF logging to debug output",   OFFSET(log_to_dbg), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
156     { "writer_id",      "Enable AMF logging to writer id",      OFFSET(writer_id),  AV_OPT_TYPE_STRING, { .str = "libavcodec" }, 0, 1, VE } \
157
158 #endif //AVCODEC_AMFENC_H