QSV_Encoder_Internal.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. This file is provided under a dual BSD/GPLv2 license. When using or
  3. redistributing this file, you may do so under either license.
  4. GPL LICENSE SUMMARY
  5. Copyright(c) Oct. 2015 Intel Corporation.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. Contact Information:
  14. Seung-Woo Kim, [email protected]
  15. 705 5th Ave S #500, Seattle, WA 98104
  16. BSD LICENSE
  17. Copyright(c) <date> Intel Corporation.
  18. Redistribution and use in source and binary forms, with or without
  19. modification, are permitted provided that the following conditions
  20. are met:
  21. * Redistributions of source code must retain the above copyright
  22. notice, this list of conditions and the following disclaimer.
  23. * Redistributions in binary form must reproduce the above copyright
  24. notice, this list of conditions and the following disclaimer in
  25. the documentation and/or other materials provided with the
  26. distribution.
  27. * Neither the name of Intel Corporation nor the names of its
  28. contributors may be used to endorse or promote products derived
  29. from this software without specific prior written permission.
  30. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  33. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  36. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  37. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  38. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  40. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41. */
  42. #pragma once
  43. #define ONEVPL_EXPERIMENTAL
  44. #include <vpl/mfxstructures.h>
  45. #include <vpl/mfxvideo++.h>
  46. #include "QSV_Encoder.h"
  47. #include "common_utils.h"
  48. #include <vector>
  49. class QSV_Encoder_Internal {
  50. public:
  51. QSV_Encoder_Internal(mfxVersion &version, bool useTexAlloc);
  52. ~QSV_Encoder_Internal();
  53. mfxStatus Open(qsv_param_t *pParams, enum qsv_codec codec);
  54. void GetSPSPPS(mfxU8 **pSPSBuf, mfxU8 **pPPSBuf, mfxU16 *pnSPSBuf, mfxU16 *pnPPSBuf);
  55. void GetVpsSpsPps(mfxU8 **pVPSBuf, mfxU8 **pSPSBuf, mfxU8 **pPPSBuf, mfxU16 *pnVPSBuf, mfxU16 *pnSPSBuf,
  56. mfxU16 *pnPPSBuf);
  57. mfxStatus Encode(uint64_t ts, uint8_t *pDataY, uint8_t *pDataUV, uint32_t strideY, uint32_t strideUV,
  58. mfxBitstream **pBS);
  59. mfxStatus Encode_tex(uint64_t ts, void *tex, uint64_t lock_key, uint64_t *next_key, mfxBitstream **pBS);
  60. mfxStatus ClearData();
  61. mfxStatus Reset(qsv_param_t *pParams, enum qsv_codec codec);
  62. mfxStatus ReconfigureEncoder();
  63. bool UpdateParams(qsv_param_t *pParams);
  64. void AddROI(mfxU32 left, mfxU32 top, mfxU32 right, mfxU32 bottom, mfxI16 delta);
  65. void ClearROI();
  66. protected:
  67. mfxStatus InitParams(qsv_param_t *pParams, enum qsv_codec codec);
  68. mfxStatus AllocateSurfaces();
  69. mfxStatus GetVideoParam(enum qsv_codec codec);
  70. mfxStatus InitBitstream();
  71. mfxStatus LoadNV12(mfxFrameSurface1 *pSurface, uint8_t *pDataY, uint8_t *pDataUV, uint32_t strideY,
  72. uint32_t strideUV);
  73. mfxStatus LoadP010(mfxFrameSurface1 *pSurface, uint8_t *pDataY, uint8_t *pDataUV, uint32_t strideY,
  74. uint32_t strideUV);
  75. mfxStatus Drain();
  76. int GetFreeTaskIndex(Task *pTaskPool, mfxU16 nPoolSize);
  77. private:
  78. mfxVersion m_ver;
  79. mfxSession m_session;
  80. void *m_sessionData;
  81. mfxFrameAllocator m_mfxAllocator;
  82. mfxVideoParam m_mfxEncParams;
  83. mfxFrameAllocResponse m_mfxResponse{};
  84. mfxFrameSurface1 **m_pmfxSurfaces;
  85. mfxU16 m_nSurfNum;
  86. MFXVideoENCODE *m_pmfxENC;
  87. mfxU8 m_VPSBuffer[1024];
  88. mfxU8 m_SPSBuffer[1024];
  89. mfxU8 m_PPSBuffer[1024];
  90. mfxU16 m_nVPSBufferSize;
  91. mfxU16 m_nSPSBufferSize;
  92. mfxU16 m_nPPSBufferSize;
  93. mfxVideoParam m_parameter;
  94. std::vector<mfxExtBuffer *> extendedBuffers;
  95. mfxExtCodingOption3 m_co3;
  96. mfxExtCodingOption2 m_co2;
  97. mfxExtCodingOption m_co;
  98. mfxExtHEVCParam m_ExtHEVCParam{};
  99. mfxExtAV1TileParam m_ExtAv1TileParam{};
  100. #if (MFX_VERSION_MAJOR >= 2 && MFX_VERSION_MINOR >= 11) || MFX_VERSION_MAJOR > 2
  101. mfxExtAV1ScreenContentTools m_ExtAV1ScreenContentTools{};
  102. #endif
  103. mfxExtVideoSignalInfo m_ExtVideoSignalInfo{};
  104. mfxExtChromaLocInfo m_ExtChromaLocInfo{};
  105. mfxExtMasteringDisplayColourVolume m_ExtMasteringDisplayColourVolume{};
  106. mfxExtContentLightLevelInfo m_ExtContentLightLevelInfo{};
  107. mfxU16 m_nTaskPool;
  108. Task *m_pTaskPool;
  109. int m_nTaskIdx;
  110. int m_nFirstSyncTask;
  111. mfxBitstream m_outBitstream;
  112. bool m_bUseD3D11;
  113. bool m_bUseTexAlloc;
  114. static mfxU16 g_numEncodersOpen;
  115. static mfxHDL g_GFX_Handle; // we only want one handle for all instances to use;
  116. mfxEncodeCtrl m_ctrl;
  117. mfxExtEncoderROI m_roi;
  118. std::vector<mfxExtBuffer *> m_extbuf;
  119. };