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.

159 lines
4.8KB

  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. // helpers to handle async calls
  58. int delayed_drain;
  59. AMFSurface *delayed_surface;
  60. AVFrame *delayed_frame;
  61. // shift dts back by max_b_frames in timing
  62. AVFifoBuffer *timestamp_list;
  63. int64_t timestamp_last;
  64. int64_t dts_delay;
  65. // common encoder options
  66. int log_to_dbg;
  67. char *writer_id;
  68. // Static options, have to be set before Init() call
  69. int usage;
  70. int profile;
  71. int level;
  72. int preanalysis;
  73. int quality;
  74. int b_frame_delta_qp;
  75. int ref_b_frame_delta_qp;
  76. // Dynamic options, can be set after Init() call
  77. int rate_control_mode;
  78. int enforce_hrd;
  79. int filler_data;
  80. int enable_vbaq;
  81. int skip_frame;
  82. int qp_i;
  83. int qp_p;
  84. int qp_b;
  85. int max_au_size;
  86. int header_spacing;
  87. int b_frame_ref;
  88. int intra_refresh_mb;
  89. int coding_mode;
  90. int me_half_pel;
  91. int me_quarter_pel;
  92. int aud;
  93. // HEVC - specific options
  94. int gops_per_idr;
  95. int header_insertion_mode;
  96. int min_qp_i;
  97. int max_qp_i;
  98. int min_qp_p;
  99. int max_qp_p;
  100. int tier;
  101. } AmfContext;
  102. /**
  103. * Common encoder initization function
  104. */
  105. int ff_amf_encode_init(AVCodecContext *avctx);
  106. /**
  107. * Common encoder termination function
  108. */
  109. int ff_amf_encode_close(AVCodecContext *avctx);
  110. /**
  111. * Ecoding one frame - common function for all AMF encoders
  112. */
  113. int ff_amf_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  114. int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  115. /**
  116. * Supported formats
  117. */
  118. extern const enum AVPixelFormat ff_amf_pix_fmts[];
  119. /**
  120. * Error handling helper
  121. */
  122. #define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
  123. if (!(exp)) { \
  124. av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
  125. return ret_value; \
  126. }
  127. #define AMF_COMMON_OPTIONS \
  128. { "log_to_dbg", "Enable AMF logging to debug output", OFFSET(log_to_dbg), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, \
  129. { "writer_id", "Enable AMF logging to writer id", OFFSET(writer_id), AV_OPT_TYPE_STRING, { .str = "libavcodec" }, 0, 1, VE } \
  130. #endif //AVCODEC_AMFENC_H