qsv_internal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Intel MediaSDK QSV encoder/decoder shared code
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_QSV_INTERNAL_H
  21. #define AVCODEC_QSV_INTERNAL_H
  22. #include "config.h"
  23. #if CONFIG_VAAPI
  24. #define AVCODEC_QSV_LINUX_SESSION_HANDLE
  25. #endif //CONFIG_VAAPI
  26. #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
  27. #include <stdio.h>
  28. #include <string.h>
  29. #if HAVE_UNISTD_H
  30. #include <unistd.h>
  31. #endif
  32. #include <fcntl.h>
  33. #include <va/va.h>
  34. #include <va/va_drm.h>
  35. #include "libavutil/hwcontext_vaapi.h"
  36. #endif
  37. #include <mfx/mfxvideo.h>
  38. #include "libavutil/frame.h"
  39. #include "avcodec.h"
  40. #define QSV_VERSION_MAJOR 1
  41. #define QSV_VERSION_MINOR 1
  42. #define ASYNC_DEPTH_DEFAULT 4 // internal parallelism
  43. #define QSV_MAX_ENC_PAYLOAD 2 // # of mfxEncodeCtrl payloads supported
  44. #define QSV_VERSION_ATLEAST(MAJOR, MINOR) \
  45. (MFX_VERSION_MAJOR > (MAJOR) || \
  46. MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
  47. #define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
  48. ((MFX_VERSION.Major > (MAJOR)) || \
  49. (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
  50. typedef struct QSVMid {
  51. AVBufferRef *hw_frames_ref;
  52. mfxHDL handle;
  53. AVFrame *locked_frame;
  54. AVFrame *hw_frame;
  55. mfxFrameSurface1 surf;
  56. } QSVMid;
  57. typedef struct QSVFrame {
  58. AVFrame *frame;
  59. mfxFrameSurface1 surface;
  60. mfxEncodeCtrl enc_ctrl;
  61. mfxExtDecodedFrameInfo dec_info;
  62. mfxExtBuffer *ext_param;
  63. int queued;
  64. int used;
  65. struct QSVFrame *next;
  66. } QSVFrame;
  67. typedef struct QSVSession {
  68. mfxSession session;
  69. #ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
  70. AVBufferRef *va_device_ref;
  71. AVHWDeviceContext *va_device_ctx;
  72. #endif
  73. } QSVSession;
  74. typedef struct QSVFramesContext {
  75. AVBufferRef *hw_frames_ctx;
  76. void *logctx;
  77. /* The memory ids for the external frames.
  78. * Refcounted, since we need one reference owned by the QSVFramesContext
  79. * (i.e. by the encoder/decoder) and another one given to the MFX session
  80. * from the frame allocator. */
  81. AVBufferRef *mids_buf;
  82. QSVMid *mids;
  83. int nb_mids;
  84. } QSVFramesContext;
  85. int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
  86. const char *extra_string);
  87. /**
  88. * Convert a libmfx error code into an ffmpeg error code.
  89. */
  90. int ff_qsv_map_error(mfxStatus mfx_err, const char **desc);
  91. int ff_qsv_print_error(void *log_ctx, mfxStatus err,
  92. const char *error_string);
  93. int ff_qsv_print_warning(void *log_ctx, mfxStatus err,
  94. const char *warning_string);
  95. int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
  96. int ff_qsv_level_to_mfx(enum AVCodecID codec_id, int level);
  97. enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc);
  98. int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
  99. enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
  100. enum AVFieldOrder ff_qsv_map_picstruct(int mfx_pic_struct);
  101. int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
  102. const char *load_plugins, int gpu_copy);
  103. int ff_qsv_close_internal_session(QSVSession *qs);
  104. int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession,
  105. AVBufferRef *device_ref, const char *load_plugins,
  106. int gpu_copy);
  107. int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *session,
  108. QSVFramesContext *qsv_frames_ctx,
  109. const char *load_plugins, int opaque, int gpu_copy);
  110. int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
  111. #endif /* AVCODEC_QSV_INTERNAL_H */