amfenc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #ifndef AVCODEC_AMFENC_H
  19. #define AVCODEC_AMFENC_H
  20. #include <AMF/core/Factory.h>
  21. #include <AMF/components/ColorSpace.h>
  22. #include <AMF/components/VideoEncoderVCE.h>
  23. #include <AMF/components/VideoEncoderHEVC.h>
  24. #include <AMF/components/VideoEncoderAV1.h>
  25. #include "libavutil/fifo.h"
  26. #include "avcodec.h"
  27. #include "hwconfig.h"
  28. #define MAX_LOOKAHEAD_DEPTH 41
  29. /**
  30. * AMF trace writer callback class
  31. * Used to capture all AMF logging
  32. */
  33. typedef struct AmfTraceWriter {
  34. AMFTraceWriterVtbl *vtbl;
  35. AVCodecContext *avctx;
  36. } AmfTraceWriter;
  37. /**
  38. * AMF encoder context
  39. */
  40. typedef struct AmfContext {
  41. AVClass *avclass;
  42. // access to AMF runtime
  43. amf_handle library; ///< handle to DLL library
  44. AMFFactory *factory; ///< pointer to AMF factory
  45. AMFDebug *debug; ///< pointer to AMF debug interface
  46. AMFTrace *trace; ///< pointer to AMF trace interface
  47. amf_uint64 version; ///< version of AMF runtime
  48. AmfTraceWriter tracer; ///< AMF writer registered with AMF
  49. AMFContext *context; ///< AMF context
  50. //encoder
  51. AMFComponent *encoder; ///< AMF encoder object
  52. amf_bool eof; ///< flag indicating EOF happened
  53. AMF_SURFACE_FORMAT format; ///< AMF surface format
  54. AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
  55. AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
  56. int hwsurfaces_in_queue;
  57. int hwsurfaces_in_queue_max;
  58. int query_timeout_supported;
  59. // helpers to handle async calls
  60. int delayed_drain;
  61. AMFSurface *delayed_surface;
  62. AVFrame *delayed_frame;
  63. // shift dts back by max_b_frames in timing
  64. AVFifo *timestamp_list;
  65. int64_t dts_delay;
  66. int submitted_frame;
  67. amf_bool use_b_frame;
  68. // common encoder option options
  69. int log_to_dbg;
  70. // Static options, have to be set before Init() call
  71. int usage;
  72. int profile;
  73. int level;
  74. int latency;
  75. int preencode;
  76. int quality;
  77. int b_frame_delta_qp;
  78. int ref_b_frame_delta_qp;
  79. // Dynamic options, can be set after Init() call
  80. int rate_control_mode;
  81. int enforce_hrd;
  82. int filler_data;
  83. int enable_vbaq;
  84. int skip_frame;
  85. int qp_i;
  86. int qp_p;
  87. int qp_b;
  88. int max_au_size;
  89. int header_spacing;
  90. int b_frame_ref;
  91. int intra_refresh_mb;
  92. int coding_mode;
  93. int me_half_pel;
  94. int me_quarter_pel;
  95. int aud;
  96. int max_consecutive_b_frames;
  97. int max_b_frames;
  98. int qvbr_quality_level;
  99. int hw_high_motion_quality_boost;
  100. int forced_idr;
  101. // HEVC - specific options
  102. int gops_per_idr;
  103. int header_insertion_mode;
  104. int min_qp_i;
  105. int max_qp_i;
  106. int min_qp_p;
  107. int max_qp_p;
  108. int tier;
  109. // AV1 - specific options
  110. enum AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_ENUM align;
  111. enum AMF_VIDEO_ENCODER_AV1_AQ_MODE_ENUM aq_mode;
  112. // Preanalysis - specific options
  113. int preanalysis;
  114. int pa_activity_type;
  115. int pa_scene_change_detection;
  116. int pa_scene_change_detection_sensitivity;
  117. int pa_static_scene_detection;
  118. int pa_static_scene_detection_sensitivity;
  119. int pa_initial_qp;
  120. int pa_max_qp;
  121. int pa_caq_strength;
  122. int pa_frame_sad;
  123. int pa_ltr;
  124. int pa_lookahead_buffer_depth;
  125. int pa_paq_mode;
  126. int pa_taq_mode;
  127. int pa_high_motion_quality_boost_mode;
  128. int pa_adaptive_mini_gop;
  129. } AmfContext;
  130. extern const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[];
  131. /**
  132. * Common encoder initization function
  133. */
  134. int ff_amf_encode_init(AVCodecContext *avctx);
  135. /**
  136. * Common encoder termination function
  137. */
  138. int ff_amf_encode_close(AVCodecContext *avctx);
  139. /**
  140. * Ecoding one frame - common function for all AMF encoders
  141. */
  142. int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  143. /**
  144. * Supported formats
  145. */
  146. extern const enum AVPixelFormat ff_amf_pix_fmts[];
  147. int ff_amf_get_color_profile(AVCodecContext *avctx);
  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. #endif //AVCODEC_AMFENC_H