You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.7KB

  1. /*
  2. * AMD AMF support
  3. * Copyright (C) 2017 Luca Barbato
  4. * Copyright (C) 2017 Mikhail Mironov <mikhail.mironov@amd.com>
  5. *
  6. * This file is part of Libav.
  7. *
  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.
  12. *
  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.
  17. *
  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
  21. */
  22. #ifndef AVCODEC_AMFENC_H
  23. #define AVCODEC_AMFENC_H
  24. #include <AMF/core/Factory.h>
  25. #include <AMF/components/VideoEncoderVCE.h>
  26. #include <AMF/components/VideoEncoderHEVC.h>
  27. #include "libavutil/fifo.h"
  28. #include "config.h"
  29. #include "avcodec.h"
  30. /**
  31. * AMF trace writer callback class
  32. * Used to capture all AMF logging
  33. */
  34. typedef struct AmfTraceWriter {
  35. AMFTraceWriterVtbl *vtbl;
  36. AVCodecContext *avctx;
  37. } AmfTraceWriter;
  38. /**
  39. * AMF encoder context
  40. */
  41. typedef struct AmfContext {
  42. AVClass *avclass;
  43. // access to AMF runtime
  44. amf_handle library; ///< handle to DLL library
  45. AMFFactory *factory; ///< pointer to AMF factory
  46. AMFDebug *debug; ///< pointer to AMF debug interface
  47. AMFTrace *trace; ///< pointer to AMF trace interface
  48. amf_uint64 version; ///< version of AMF runtime
  49. AmfTraceWriter tracer; ///< AMF writer registered with AMF
  50. AMFContext *context; ///< AMF context
  51. //encoder
  52. AMFComponent *encoder; ///< AMF encoder object
  53. amf_bool eof; ///< flag indicating EOF happened
  54. AMF_SURFACE_FORMAT format; ///< AMF surface format
  55. AVBufferRef *hw_device_ctx; ///< pointer to HW accelerator (decoder)
  56. AVBufferRef *hw_frames_ctx; ///< pointer to HW accelerator (frame allocator)
  57. int hwsurfaces_in_queue;
  58. int hwsurfaces_in_queue_max;
  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. AVFifoBuffer *timestamp_list;
  65. int64_t timestamp_last;
  66. int64_t dts_delay;
  67. // common encoder options
  68. int log_to_dbg;
  69. // Static options, have to be set before Init() call
  70. int usage;
  71. int profile;
  72. int level;
  73. int preanalysis;
  74. int quality;
  75. int b_frame_delta_qp;
  76. int ref_b_frame_delta_qp;
  77. // Dynamic options, can be set after Init() call
  78. int rate_control_mode;
  79. int enforce_hrd;
  80. int filler_data;
  81. int enable_vbaq;
  82. int skip_frame;
  83. int qp_i;
  84. int qp_p;
  85. int qp_b;
  86. int max_au_size;
  87. int header_spacing;
  88. int b_frame_ref;
  89. int intra_refresh_mb;
  90. int coding_mode;
  91. int me_half_pel;
  92. int me_quarter_pel;
  93. int aud;
  94. // HEVC - specific options
  95. int gops_per_idr;
  96. int header_insertion_mode;
  97. int min_qp_i;
  98. int max_qp_i;
  99. int min_qp_p;
  100. int max_qp_p;
  101. int tier;
  102. } AmfContext;
  103. /**
  104. * Common encoder initization function
  105. */
  106. int ff_amf_encode_init(AVCodecContext *avctx);
  107. /**
  108. * Common encoder termination function
  109. */
  110. int ff_amf_encode_close(AVCodecContext *avctx);
  111. /**
  112. * Ecoding one frame - common function for all AMF encoders
  113. */
  114. int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  115. int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  116. /**
  117. * Supported formats
  118. */
  119. extern const enum AVPixelFormat ff_amf_pix_fmts[];
  120. /**
  121. * Error handling helper
  122. */
  123. #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
  124. if (!(exp)) { \
  125. av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
  126. return ret_value; \
  127. }
  128. #define AMF_COMMON_OPTIONS \
  129. { "log_to_dbg", "Enable AMF logging to debug output", OFFSET(log_to_dbg), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE } \
  130. #endif //AVCODEC_AMFENC_H