• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "avcodec.h"
30 #include "hwconfig.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     int                 hwsurfaces_in_queue;
67     int                 hwsurfaces_in_queue_max;
68 
69     // helpers to handle async calls
70     int                 delayed_drain;
71     AMFSurface         *delayed_surface;
72     AVFrame            *delayed_frame;
73 
74     // shift dts back by max_b_frames in timing
75     AVFifoBuffer       *timestamp_list;
76     int64_t             dts_delay;
77 
78     // common encoder option options
79 
80     int                 log_to_dbg;
81 
82     // Static options, have to be set before Init() call
83     int                 usage;
84     int                 profile;
85     int                 level;
86     int                 preanalysis;
87     int                 quality;
88     int                 b_frame_delta_qp;
89     int                 ref_b_frame_delta_qp;
90 
91     // Dynamic options, can be set after Init() call
92 
93     int                 rate_control_mode;
94     int                 enforce_hrd;
95     int                 filler_data;
96     int                 enable_vbaq;
97     int                 skip_frame;
98     int                 qp_i;
99     int                 qp_p;
100     int                 qp_b;
101     int                 max_au_size;
102     int                 header_spacing;
103     int                 b_frame_ref;
104     int                 intra_refresh_mb;
105     int                 coding_mode;
106     int                 me_half_pel;
107     int                 me_quarter_pel;
108     int                 aud;
109 
110     // HEVC - specific options
111 
112     int                 gops_per_idr;
113     int                 header_insertion_mode;
114     int                 min_qp_i;
115     int                 max_qp_i;
116     int                 min_qp_p;
117     int                 max_qp_p;
118     int                 tier;
119 } AmfContext;
120 
121 extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
122 
123 /**
124 * Common encoder initization function
125 */
126 int ff_amf_encode_init(AVCodecContext *avctx);
127 /**
128 * Common encoder termination function
129 */
130 int ff_amf_encode_close(AVCodecContext *avctx);
131 
132 /**
133 * Ecoding one frame - common function for all AMF encoders
134 */
135 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
136 
137 /**
138 * Supported formats
139 */
140 extern const enum AVPixelFormat ff_amf_pix_fmts[];
141 
142 /**
143 * Error handling helper
144 */
145 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
146     if (!(exp)) { \
147         av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
148         return ret_value; \
149     }
150 
151 #endif //AVCODEC_AMFENC_H
152