3 * Copyright (C) 2017 Luca Barbato
4 * Copyright (C) 2017 Mikhail Mironov <mikhail.mironov@amd.com>
6 * This file is part of Libav.
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.
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.
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
24 #ifndef AVCODEC_AMFENC_H
25 #define AVCODEC_AMFENC_H
27 #include <AMF/core/Factory.h>
29 #include <AMF/components/VideoEncoderVCE.h>
30 #include <AMF/components/VideoEncoderHEVC.h>
32 #include "libavutil/fifo.h"
39 * AMF trace writer callback class
40 * Used to capture all AMF logging
43 typedef struct AmfTraceWriter {
44 AMFTraceWriterVtbl *vtbl;
45 AVCodecContext *avctx;
52 typedef struct AmfContext {
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
60 amf_uint64 version; ///< version of AMF runtime
61 AmfTraceWriter tracer; ///< AMF writer registered with AMF
62 AMFContext *context; ///< AMF context
64 AMFComponent *encoder; ///< AMF encoder object
65 amf_bool eof; ///< flag indicating EOF happened
66 AMF_SURFACE_FORMAT format; ///< AMF surface format
68 AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
69 AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
71 int hwsurfaces_in_queue;
72 int hwsurfaces_in_queue_max;
74 // helpers to handle async calls
76 AMFSurface *delayed_surface;
77 AVFrame *delayed_frame;
79 // shift dts back by max_b_frames in timing
80 AVFifoBuffer *timestamp_list;
81 int64_t timestamp_last;
84 // common encoder options
87 // Static options, have to be set before Init() call
94 int ref_b_frame_delta_qp;
96 // Dynamic options, can be set after Init() call
98 int rate_control_mode;
109 int intra_refresh_mb;
115 // HEVC - specific options
118 int header_insertion_mode;
127 * Common encoder initization function
129 int ff_amf_encode_init(AVCodecContext *avctx);
131 * Common encoder termination function
133 int ff_amf_encode_close(AVCodecContext *avctx);
136 * Ecoding one frame - common function for all AMF encoders
139 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
140 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
145 extern const enum AVPixelFormat ff_amf_pix_fmts[];
148 * Error handling helper
150 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
152 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
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 } \
159 #endif //AVCODEC_AMFENC_H