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 // helpers to handle async calls
73 AMFSurface *delayed_surface;
74 AVFrame *delayed_frame;
76 // shift dts back by max_b_frames in timing
77 AVFifoBuffer *timestamp_list;
78 int64_t timestamp_last;
81 // common encoder options
85 // Static options, have to be set before Init() call
92 int ref_b_frame_delta_qp;
94 // Dynamic options, can be set after Init() call
96 int rate_control_mode;
107 int intra_refresh_mb;
113 // HEVC - specific options
116 int header_insertion_mode;
125 * Common encoder initization function
127 int ff_amf_encode_init(AVCodecContext *avctx);
129 * Common encoder termination function
131 int ff_amf_encode_close(AVCodecContext *avctx);
134 * Ecoding one frame - common function for all AMF encoders
137 int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
138 int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
143 extern const enum AVPixelFormat ff_amf_pix_fmts[];
146 * Error handling helper
148 #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
150 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
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 } \
158 #endif //AVCODEC_AMFENC_H