FFmpeg
amfenc.h
Go to the documentation of this file.
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 #include <AMF/components/VideoEncoderAV1.h>
27 
28 #include "libavutil/fifo.h"
29 
30 #include "avcodec.h"
31 #include "hwconfig.h"
32 
33 
34 /**
35 * AMF trace writer callback class
36 * Used to capture all AMF logging
37 */
38 
39 typedef struct AmfTraceWriter {
40  AMFTraceWriterVtbl *vtbl;
43 
44 /**
45 * AMF encoder context
46 */
47 
48 typedef struct AmfContext {
50  // access to AMF runtime
51  amf_handle library; ///< handle to DLL library
52  AMFFactory *factory; ///< pointer to AMF factory
53  AMFDebug *debug; ///< pointer to AMF debug interface
54  AMFTrace *trace; ///< pointer to AMF trace interface
55 
56  amf_uint64 version; ///< version of AMF runtime
57  AmfTraceWriter tracer; ///< AMF writer registered with AMF
58  AMFContext *context; ///< AMF context
59  //encoder
60  AMFComponent *encoder; ///< AMF encoder object
61  amf_bool eof; ///< flag indicating EOF happened
62  AMF_SURFACE_FORMAT format; ///< AMF surface format
63 
64  AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
65  AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
66 
69 
70  // helpers to handle async calls
72  AMFSurface *delayed_surface;
74 
75  // shift dts back by max_b_frames in timing
77  int64_t dts_delay;
78 
79  // common encoder option options
80 
82 
83  // Static options, have to be set before Init() call
84  int usage;
85  int profile;
86  int level;
88  int quality;
91 
92  // Dynamic options, can be set after Init() call
93 
99  int qp_i;
100  int qp_p;
101  int qp_b;
109  int aud;
110 
111  // HEVC - specific options
112 
115  int min_qp_i;
116  int max_qp_i;
117  int min_qp_p;
118  int max_qp_p;
119  int tier;
120 
121  // AV1 - specific options
122 
123  enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align;
124 
125 } AmfContext;
126 
127 extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
128 
129 /**
130 * Common encoder initization function
131 */
133 /**
134 * Common encoder termination function
135 */
137 
138 /**
139 * Ecoding one frame - common function for all AMF encoders
140 */
141 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
142 
143 /**
144 * Supported formats
145 */
146 extern const enum AVPixelFormat ff_amf_pix_fmts[];
147 
148 /**
149 * Error handling helper
150 */
151 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
152  if (!(exp)) { \
153  av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
154  return ret_value; \
155  }
156 
157 #endif //AVCODEC_AMFENC_H
AmfContext::header_spacing
int header_spacing
Definition: amfenc.h:103
hwconfig.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AmfContext::factory
AMFFactory * factory
pointer to AMF factory
Definition: amfenc.h:52
AmfContext::hwsurfaces_in_queue_max
int hwsurfaces_in_queue_max
Definition: amfenc.h:68
AmfContext::trace
AMFTrace * trace
pointer to AMF trace interface
Definition: amfenc.h:54
AmfContext::profile
int profile
Definition: amfenc.h:85
AmfContext::qp_i
int qp_i
Definition: amfenc.h:99
ff_amf_receive_packet
int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Ecoding one frame - common function for all AMF encoders.
Definition: amfenc.c:586
AmfContext::ref_b_frame_delta_qp
int ref_b_frame_delta_qp
Definition: amfenc.h:90
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
AmfContext::quality
int quality
Definition: amfenc.h:88
AmfTraceWriter::vtbl
AMFTraceWriterVtbl * vtbl
Definition: amfenc.h:40
AmfContext::library
amf_handle library
handle to DLL library
Definition: amfenc.h:51
AmfContext::qp_b
int qp_b
Definition: amfenc.h:101
AmfContext::enable_vbaq
int enable_vbaq
Definition: amfenc.h:97
AmfContext::level
int level
Definition: amfenc.h:86
AmfContext::skip_frame
int skip_frame
Definition: amfenc.h:98
AmfContext::delayed_frame
AVFrame * delayed_frame
Definition: amfenc.h:73
fifo.h
AmfContext::enforce_hrd
int enforce_hrd
Definition: amfenc.h:95
ff_amfenc_hw_configs
const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[]
Definition: amfenc.c:781
AmfContext::delayed_surface
AMFSurface * delayed_surface
Definition: amfenc.h:72
AmfContext::rate_control_mode
int rate_control_mode
Definition: amfenc.h:94
AmfContext::preanalysis
int preanalysis
Definition: amfenc.h:87
AmfContext::filler_data
int filler_data
Definition: amfenc.h:96
AmfContext::avclass
AVClass * avclass
Definition: amfenc.h:49
AmfContext::debug
AMFDebug * debug
pointer to AMF debug interface
Definition: amfenc.h:53
AmfContext::min_qp_i
int min_qp_i
Definition: amfenc.h:115
AmfContext::min_qp_p
int min_qp_p
Definition: amfenc.h:117
AmfTraceWriter::avctx
AVCodecContext * avctx
Definition: amfenc.h:41
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AmfContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
pointer to HW accelerator (frame allocator)
Definition: amfenc.h:65
AmfContext::max_au_size
int max_au_size
Definition: amfenc.h:102
AmfContext::timestamp_list
AVFifo * timestamp_list
Definition: amfenc.h:76
AmfContext::hwsurfaces_in_queue
int hwsurfaces_in_queue
Definition: amfenc.h:67
AmfContext::me_half_pel
int me_half_pel
Definition: amfenc.h:107
AmfTraceWriter
AMF trace writer callback class Used to capture all AMF logging.
Definition: amfenc.h:39
AmfContext::format
AMF_SURFACE_FORMAT format
AMF surface format.
Definition: amfenc.h:62
AVFifo
Definition: fifo.c:35
AVCodecHWConfigInternal
Definition: hwconfig.h:29
AmfContext::dts_delay
int64_t dts_delay
Definition: amfenc.h:77
ff_amf_pix_fmts
enum AVPixelFormat ff_amf_pix_fmts[]
Supported formats.
Definition: amfenc.c:54
AmfContext::usage
int usage
Definition: amfenc.h:84
AmfContext::encoder
AMFComponent * encoder
AMF encoder object.
Definition: amfenc.h:60
AmfContext::coding_mode
int coding_mode
Definition: amfenc.h:106
AmfContext::gops_per_idr
int gops_per_idr
Definition: amfenc.h:113
AmfContext::b_frame_delta_qp
int b_frame_delta_qp
Definition: amfenc.h:89
AmfContext::intra_refresh_mb
int intra_refresh_mb
Definition: amfenc.h:105
AmfContext::max_qp_i
int max_qp_i
Definition: amfenc.h:116
ff_amf_encode_close
int ff_amf_encode_close(AVCodecContext *avctx)
Common encoder termination function.
Definition: amfenc.c:375
avcodec.h
AmfContext::tier
int tier
Definition: amfenc.h:119
AmfContext::me_quarter_pel
int me_quarter_pel
Definition: amfenc.h:108
AmfContext::max_qp_p
int max_qp_p
Definition: amfenc.h:118
AmfContext::align
enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align
Definition: amfenc.h:123
AVCodecContext
main external API structure.
Definition: avcodec.h:398
AmfContext::header_insertion_mode
int header_insertion_mode
Definition: amfenc.h:114
AmfContext::version
amf_uint64 version
version of AMF runtime
Definition: amfenc.h:56
AmfContext::qp_p
int qp_p
Definition: amfenc.h:100
ff_amf_encode_init
int ff_amf_encode_init(AVCodecContext *avctx)
Common encoder initization function.
Definition: amfenc.c:501
AmfContext::log_to_dbg
int log_to_dbg
Definition: amfenc.h:81
AmfContext::aud
int aud
Definition: amfenc.h:109
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AmfContext::eof
amf_bool eof
flag indicating EOF happened
Definition: amfenc.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AmfContext::hw_device_ctx
AVBufferRef * hw_device_ctx
pointer to HW accelerator (decoder)
Definition: amfenc.h:64
AmfContext::b_frame_ref
int b_frame_ref
Definition: amfenc.h:104
AmfContext
AMF encoder context.
Definition: amfenc.h:48
AmfContext::tracer
AmfTraceWriter tracer
AMF writer registered with AMF.
Definition: amfenc.h:57
AmfContext::context
AMFContext * context
AMF context.
Definition: amfenc.h:58
AmfContext::delayed_drain
int delayed_drain
Definition: amfenc.h:71