cfg_params.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2021 Intel Corporation
  6. #ifndef OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP
  7. #define OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP
  8. #include <map>
  9. #include <memory>
  10. #include <string>
  11. #include <opencv2/gapi/streaming/source.hpp>
  12. #include <opencv2/gapi/util/variant.hpp>
  13. namespace cv {
  14. namespace gapi {
  15. namespace wip {
  16. namespace onevpl {
  17. /**
  18. * @brief Public class is using for creation of onevpl::GSource instances.
  19. *
  20. * Class members available through methods @ref CfgParam::get_name() and @ref CfgParam::get_value() are used by
  21. * onevpl::GSource inner logic to create or find oneVPL particular implementation
  22. * (software/hardware, specific API version and etc.).
  23. *
  24. * @note Because oneVPL may provide several implementations which are satisfying with multiple (or single one) @ref CfgParam
  25. * criteria therefore it is possible to configure `preferred` parameters. This kind of CfgParams are created
  26. * using `is_major = false` argument in @ref CfgParam::create method and are not used by creating oneVPL particular implementations.
  27. * Instead they fill out a "score table" to select preferable implementation from available list. Implementation are satisfying
  28. * with most of these optional params would be chosen.
  29. * If no one optional CfgParam params were present then first of available oneVPL implementation would be applied.
  30. * Please get on https://spec.oneapi.io/versions/latest/elements/oneVPL/source/API_ref/VPL_disp_api_func.html?highlight=mfxcreateconfig#mfxsetconfigfilterproperty
  31. * for using OneVPL configuration. In this schema `mfxU8 *name` represents @ref CfgParam::get_name() and
  32. * `mfxVariant value` is @ref CfgParam::get_value()
  33. */
  34. struct GAPI_EXPORTS CfgParam {
  35. using name_t = std::string;
  36. using value_t = cv::util::variant<uint8_t, int8_t,
  37. uint16_t, int16_t,
  38. uint32_t, int32_t,
  39. uint64_t, int64_t,
  40. float_t,
  41. double_t,
  42. void*,
  43. std::string>;
  44. /**
  45. * @brief frames_pool_size_name
  46. *
  47. * Special configuration parameter name for onevp::GSource:
  48. *
  49. * @note frames_pool_size_name allows to allocate surfaces pool appropriate size to keep
  50. * decoded frames in accelerator memory ready before
  51. * they would be consumed by onevp::GSource::pull operation. If you see
  52. * a lot of WARNING about lack of free surface then it's time to increase
  53. * frames_pool_size_name but be aware of accelerator free memory volume.
  54. * If not set then MFX implementation use
  55. * mfxFrameAllocRequest::NumFrameSuggested behavior
  56. *
  57. */
  58. static constexpr const char *frames_pool_size_name() { return "frames_pool_size"; }
  59. static CfgParam create_frames_pool_size(size_t value);
  60. /**
  61. * @brief acceleration_mode_name
  62. *
  63. * Special configuration parameter names for onevp::GSource:
  64. *
  65. * @note acceleration_mode_name allows to activate hardware acceleration &
  66. * device memory management.
  67. * Supported values:
  68. * - MFX_ACCEL_MODE_VIA_D3D11 Will activate DX11 acceleration and will produces
  69. * MediaFrames with data allocated in DX11 device memory
  70. *
  71. * If not set then MFX implementation will use default acceleration behavior:
  72. * all decoding operation uses default GPU resources but MediaFrame produces
  73. * data allocated by using host RAM
  74. *
  75. */
  76. static constexpr const char *acceleration_mode_name() { return "mfxImplDescription.AccelerationMode"; }
  77. static CfgParam create_acceleration_mode(uint32_t value);
  78. static CfgParam create_acceleration_mode(const char* value);
  79. /**
  80. * @brief decoder_id_name
  81. *
  82. * Special configuration parameter names for onevp::GSource:
  83. *
  84. * @note decoder_id_name allows to specify VPL decoder type which MUST present
  85. * in case of RAW video input data and MUST NOT present as CfgParam if video
  86. * stream incapsulated into container(*.mp4, *.mkv and so on). In latter case
  87. * onevp::GSource will determine it automatically
  88. * Supported values:
  89. * - MFX_CODEC_AVC
  90. * - MFX_CODEC_HEVC
  91. * - MFX_CODEC_MPEG2
  92. * - MFX_CODEC_VC1
  93. * - MFX_CODEC_CAPTURE
  94. * - MFX_CODEC_VP9
  95. * - MFX_CODEC_AV1
  96. *
  97. */
  98. static constexpr const char *decoder_id_name() { return "mfxImplDescription.mfxDecoderDescription.decoder.CodecID"; }
  99. static CfgParam create_decoder_id(uint32_t value);
  100. static CfgParam create_decoder_id(const char* value);
  101. static constexpr const char *implementation_name() { return "mfxImplDescription.Impl"; }
  102. static CfgParam create_implementation(uint32_t value);
  103. static CfgParam create_implementation(const char* value);
  104. static constexpr const char *vpp_frames_pool_size_name() { return "vpp_frames_pool_size"; }
  105. static CfgParam create_vpp_frames_pool_size(size_t value);
  106. static constexpr const char *vpp_in_width_name() { return "vpp.In.Width"; }
  107. static CfgParam create_vpp_in_width(uint16_t value);
  108. static constexpr const char *vpp_in_height_name() { return "vpp.In.Height"; }
  109. static CfgParam create_vpp_in_height(uint16_t value);
  110. static constexpr const char *vpp_in_crop_x_name() { return "vpp.In.CropX"; }
  111. static CfgParam create_vpp_in_crop_x(uint16_t value);
  112. static constexpr const char *vpp_in_crop_y_name() { return "vpp.In.CropY"; }
  113. static CfgParam create_vpp_in_crop_y(uint16_t value);
  114. static constexpr const char *vpp_in_crop_w_name() { return "vpp.In.CropW"; }
  115. static CfgParam create_vpp_in_crop_w(uint16_t value);
  116. static constexpr const char *vpp_in_crop_h_name() { return "vpp.In.CropH"; }
  117. static CfgParam create_vpp_in_crop_h(uint16_t value);
  118. static constexpr const char *vpp_out_fourcc_name() { return "vpp.Out.FourCC"; }
  119. static CfgParam create_vpp_out_fourcc(uint32_t value);
  120. static constexpr const char *vpp_out_chroma_format_name() { return "vpp.Out.ChromaFormat"; }
  121. static CfgParam create_vpp_out_chroma_format(uint16_t value);
  122. static constexpr const char *vpp_out_width_name() { return "vpp.Out.Width"; }
  123. static CfgParam create_vpp_out_width(uint16_t value);
  124. static constexpr const char *vpp_out_height_name() { return "vpp.Out.Height"; }
  125. static CfgParam create_vpp_out_height(uint16_t value);
  126. static constexpr const char *vpp_out_crop_x_name() { return "vpp.Out.CropX"; }
  127. static CfgParam create_vpp_out_crop_x(uint16_t value);
  128. static constexpr const char *vpp_out_crop_y_name() { return "vpp.Out.CropY"; }
  129. static CfgParam create_vpp_out_crop_y(uint16_t value);
  130. static constexpr const char *vpp_out_crop_w_name() { return "vpp.Out.CropW"; }
  131. static CfgParam create_vpp_out_crop_w(uint16_t value);
  132. static constexpr const char *vpp_out_crop_h_name() { return "vpp.Out.CropH"; }
  133. static CfgParam create_vpp_out_crop_h(uint16_t value);
  134. static constexpr const char *vpp_out_pic_struct_name() { return "vpp.Out.PicStruct"; }
  135. static CfgParam create_vpp_out_pic_struct(uint16_t value);
  136. static constexpr const char *vpp_out_framerate_n_name() { return "vpp.Out.FrameRateExtN"; }
  137. static CfgParam create_vpp_out_framerate_n(uint32_t value);
  138. static constexpr const char *vpp_out_framerate_d_name() { return "vpp.Out.FrameRateExtD"; }
  139. static CfgParam create_vpp_out_framerate_d(uint32_t value);
  140. /**
  141. * Create generic onevp::GSource configuration parameter.
  142. *
  143. *@param name name of parameter.
  144. *@param value value of parameter.
  145. *@param is_major TRUE if parameter MUST be provided by OneVPL inner implementation, FALSE for optional (for resolve multiple available implementations).
  146. *
  147. */
  148. template<typename ValueType>
  149. static CfgParam create(const std::string& name, ValueType&& value, bool is_major = true) {
  150. CfgParam param(name, CfgParam::value_t(std::forward<ValueType>(value)), is_major);
  151. return param;
  152. }
  153. struct Priv;
  154. const name_t& get_name() const;
  155. const value_t& get_value() const;
  156. bool is_major() const;
  157. std::string to_string() const;
  158. bool operator==(const CfgParam& rhs) const;
  159. bool operator< (const CfgParam& rhs) const;
  160. bool operator!=(const CfgParam& rhs) const;
  161. CfgParam& operator=(const CfgParam& src);
  162. CfgParam& operator=(CfgParam&& src);
  163. CfgParam(const CfgParam& src);
  164. CfgParam(CfgParam&& src);
  165. ~CfgParam();
  166. private:
  167. CfgParam(const std::string& param_name, value_t&& param_value, bool is_major_param);
  168. std::shared_ptr<Priv> m_priv;
  169. };
  170. } //namespace onevpl
  171. } // namespace wip
  172. } // namespace gapi
  173. } // namespace cv
  174. #endif // OPENCV_GAPI_STREAMING_ONEVPL_CFG_PARAMS_HPP