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.

116 lines
3.1KB

  1. /*
  2. * Intel MediaSDK QSV encoder/decoder shared code
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <mfx/mfxvideo.h>
  21. #include "libavutil/error.h"
  22. #include "avcodec.h"
  23. #include "qsv_internal.h"
  24. int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
  25. {
  26. switch (codec_id) {
  27. case AV_CODEC_ID_H264:
  28. return MFX_CODEC_AVC;
  29. case AV_CODEC_ID_MPEG1VIDEO:
  30. case AV_CODEC_ID_MPEG2VIDEO:
  31. return MFX_CODEC_MPEG2;
  32. case AV_CODEC_ID_VC1:
  33. return MFX_CODEC_VC1;
  34. default:
  35. break;
  36. }
  37. return AVERROR(ENOSYS);
  38. }
  39. int ff_qsv_error(int mfx_err)
  40. {
  41. switch (mfx_err) {
  42. case MFX_ERR_NONE:
  43. return 0;
  44. case MFX_ERR_MEMORY_ALLOC:
  45. case MFX_ERR_NOT_ENOUGH_BUFFER:
  46. return AVERROR(ENOMEM);
  47. case MFX_ERR_INVALID_HANDLE:
  48. return AVERROR(EINVAL);
  49. case MFX_ERR_DEVICE_FAILED:
  50. case MFX_ERR_DEVICE_LOST:
  51. case MFX_ERR_LOCK_MEMORY:
  52. return AVERROR(EIO);
  53. case MFX_ERR_NULL_PTR:
  54. case MFX_ERR_UNDEFINED_BEHAVIOR:
  55. case MFX_ERR_NOT_INITIALIZED:
  56. return AVERROR_BUG;
  57. case MFX_ERR_UNSUPPORTED:
  58. case MFX_ERR_NOT_FOUND:
  59. return AVERROR(ENOSYS);
  60. case MFX_ERR_MORE_DATA:
  61. case MFX_ERR_MORE_SURFACE:
  62. case MFX_ERR_MORE_BITSTREAM:
  63. return AVERROR(EAGAIN);
  64. case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM:
  65. case MFX_ERR_INVALID_VIDEO_PARAM:
  66. return AVERROR(EINVAL);
  67. case MFX_ERR_ABORTED:
  68. case MFX_ERR_UNKNOWN:
  69. default:
  70. return AVERROR_UNKNOWN;
  71. }
  72. }
  73. int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session)
  74. {
  75. mfxIMPL impl = MFX_IMPL_AUTO_ANY;
  76. mfxVersion ver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
  77. const char *desc;
  78. int ret;
  79. ret = MFXInit(impl, &ver, session);
  80. if (ret < 0) {
  81. av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX session\n");
  82. return ff_qsv_error(ret);
  83. }
  84. MFXQueryIMPL(*session, &impl);
  85. switch (MFX_IMPL_BASETYPE(impl)) {
  86. case MFX_IMPL_SOFTWARE:
  87. desc = "software";
  88. break;
  89. case MFX_IMPL_HARDWARE:
  90. case MFX_IMPL_HARDWARE2:
  91. case MFX_IMPL_HARDWARE3:
  92. case MFX_IMPL_HARDWARE4:
  93. desc = "hardware accelerated";
  94. break;
  95. default:
  96. desc = "unknown";
  97. }
  98. av_log(avctx, AV_LOG_VERBOSE,
  99. "Initialized an internal MFX session using %s implementation\n",
  100. desc);
  101. return 0;
  102. }