amfenc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/VideoEncoderVCE.h>
  22. #include <AMF/components/VideoEncoderHEVC.h>
  23. #include "libavutil/fifo.h"
  24. #include "avcodec.h"
  25. /**
  26. * AMF trace writer callback class
  27. * Used to capture all AMF logging
  28. */
  29. typedef struct AmfTraceWriter {
  30. AMFTraceWriterVtbl *vtbl;
  31. AVCodecContext *avctx;
  32. } AmfTraceWriter;
  33. /**
  34. * AMF encoder context
  35. */
  36. typedef struct AmfContext {
  37. AVClass *avclass;
  38. // access to AMF runtime
  39. amf_handle library; ///< handle to DLL library
  40. AMFFactory *factory; ///< pointer to AMF factory
  41. AMFDebug *debug; ///< pointer to AMF debug interface
  42. AMFTrace *trace; ///< pointer to AMF trace interface
  43. amf_uint64 version; ///< version of AMF runtime
  44. AmfTraceWriter tracer; ///< AMF writer registered with AMF
  45. AMFContext *context; ///< AMF context
  46. //encoder
  47. AMFComponent *encoder; ///< AMF encoder object
  48. amf_bool eof; ///< flag indicating EOF happened
  49. AMF_SURFACE_FORMAT format; ///< AMF surface format
  50. AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
  51. AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
  52. int hwsurfaces_in_queue;
  53. int hwsurfaces_in_queue_max;
  54. // helpers to handle async calls
  55. int delayed_drain;
  56. AMFSurface *delayed_surface;
  57. AVFrame *delayed_frame;
  58. // shift dts back by max_b_frames in timing
  59. AVFifoBuffer *timestamp_list;
  60. int64_t dts_delay;
  61. // common encoder option options
  62. int log_to_dbg;
  63. // Static options, have to be set before Init() call
  64. int usage;
  65. int profile;
  66. int level;
  67. int preanalysis;
  68. int quality;
  69. int b_frame_delta_qp;
  70. int ref_b_frame_delta_qp;
  71. // Dynamic options, can be set after Init() call
  72. int rate_control_mode;
  73. int enforce_hrd;
  74. int filler_data;
  75. int enable_vbaq;
  76. int skip_frame;
  77. int qp_i;
  78. int qp_p;
  79. int qp_b;
  80. int max_au_size;
  81. int header_spacing;
  82. int b_frame_ref;
  83. int intra_refresh_mb;
  84. int coding_mode;
  85. int me_half_pel;
  86. int me_quarter_pel;
  87. int aud;
  88. // HEVC - specific options
  89. int gops_per_idr;
  90. int header_insertion_mode;
  91. int min_qp_i;
  92. int max_qp_i;
  93. int min_qp_p;
  94. int max_qp_p;
  95. int tier;
  96. } AmfContext;
  97. /**
  98. * Common encoder initization function
  99. */
  100. int ff_amf_encode_init(AVCodecContext *avctx);
  101. /**
  102. * Common encoder termination function
  103. */
  104. int ff_amf_encode_close(AVCodecContext *avctx);
  105. /**
  106. * Ecoding one frame - common function for all AMF encoders
  107. */
  108. int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  109. /**
  110. * Supported formats
  111. */
  112. extern const enum AVPixelFormat ff_amf_pix_fmts[];
  113. /**
  114. * Error handling helper
  115. */
  116. #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
  117. if (!(exp)) { \
  118. av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
  119. return ret_value; \
  120. }
  121. #endif //AVCODEC_AMFENC_H