| 1 |
/* |
| 2 |
* Copyright (c) 2018 - 2025, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
//! |
| 24 |
//! \file media_feature_manager.h |
| 25 |
//! \brief Defines the common interface for encode feature manager |
| 26 |
//! \details The media feature manager is further sub-divided by codec type |
| 27 |
//! this file is for the base interface which is shared by all components. |
| 28 |
//! |
| 29 |
|
| 30 |
#ifndef __MEDIA_FEATURE_MANAGER_H__ |
| 31 |
#define __MEDIA_FEATURE_MANAGER_H__ |
| 32 |
#include <vector> |
| 33 |
#include <stdint.h> |
| 34 |
#include <map> |
| 35 |
#include <memory> |
| 36 |
#include <utility> |
| 37 |
#include "media_user_setting.h" |
| 38 |
#include "media_utils.h" |
| 39 |
#include "mos_defs.h" |
| 40 |
#include "media_feature_const_settings.h" |
| 41 |
|
| 42 |
#define CONSTRUCTFEATUREID(_componentID, _subComponentID, _featureID) \ |
| 43 |
(_componentID << 24 | _subComponentID << 16 | _featureID) |
| 44 |
|
| 45 |
enum ComponentIDs |
| 46 |
{ |
| 47 |
FEATURE_COMPONENT_COMMON = 0, |
| 48 |
FEATURE_COMPONENT_ENCODE, |
| 49 |
FEATURE_COMPONENT_DECODE, |
| 50 |
FEATURE_COMPONENT_VP, |
| 51 |
FEATURE_COMPONENT_OTHER |
| 52 |
}; |
| 53 |
|
| 54 |
enum SubComponentIDs |
| 55 |
{ |
| 56 |
FEATURE_SUBCOMPONENT_COMMON = 0, |
| 57 |
FEATURE_SUBCOMPONENT_HEVC, |
| 58 |
FEATURE_SUBCOMPONENT_VP9, |
| 59 |
FEATURE_SUBCOMPONENT_AVC, |
| 60 |
FEATURE_SUBCOMPONENT_AV1, |
| 61 |
FEATURE_SUBCOMPONENT_JPEG |
| 62 |
}; |
| 63 |
|
| 64 |
struct FeatureIDs |
| 65 |
{ |
| 66 |
enum CommonFeatureIDs |
| 67 |
{ |
| 68 |
basicFeature = CONSTRUCTFEATUREID(FEATURE_COMPONENT_COMMON, FEATURE_SUBCOMPONENT_COMMON, 0), |
| 69 |
encodeTile, |
| 70 |
preEncFeature, |
| 71 |
saliencyFeature, |
| 72 |
}; |
| 73 |
}; |
| 74 |
//! |
| 75 |
//! \def RUN_FEATURE_INTERFACE_RETURN(_featureClassName, _featureID, _featureInterface, ...) |
| 76 |
//! Run _featureInterface if it exit |
| 77 |
//! |
| 78 |
#define RUN_FEATURE_INTERFACE_RETURN(_featureClassName, _featureID, _featureInterface, ...) \ |
| 79 |
{ \ |
| 80 |
if(m_featureManager){ \ |
| 81 |
auto feature = static_cast<_featureClassName*>(m_featureManager->GetFeature(_featureID)); \ |
| 82 |
if (feature) \ |
| 83 |
{ \ |
| 84 |
MEDIA_CHK_STATUS_RETURN(feature->_featureInterface(__VA_ARGS__)); \ |
| 85 |
} \ |
| 86 |
} \ |
| 87 |
} |
| 88 |
|
| 89 |
//! |
| 90 |
//! \def RUN_FEATURE_INTERFACE_NO_RETURN(_featureClassName, _featureID, _featureInterface, ...) |
| 91 |
//! Run _featureInterface if it exit |
| 92 |
//! |
| 93 |
#define RUN_FEATURE_INTERFACE_NO_RETURN(_featureClassName, _featureID, _featureInterface, ...) \ |
| 94 |
{ \ |
| 95 |
if(m_featureManager){ \ |
| 96 |
auto feature = static_cast<_featureClassName*>(m_featureManager->GetFeature(_featureID)); \ |
| 97 |
if (feature) \ |
| 98 |
{ \ |
| 99 |
feature->_featureInterface(__VA_ARGS__); \ |
| 100 |
} \ |
| 101 |
} \ |
| 102 |
} |
| 103 |
|
| 104 |
class MediaFeature; |
| 105 |
|
| 106 |
enum class LIST_TYPE |
| 107 |
{ |
| 108 |
BLOCK_LIST, |
| 109 |
ALLOW_LIST, |
| 110 |
}; |
| 111 |
|
| 112 |
class MediaFeatureManager // for pipe line use |
| 113 |
{ |
| 114 |
protected: |
| 115 |
using container_t = std::map<int, MediaFeature *>; |
| 116 |
|
| 117 |
public: |
| 118 |
class ManagerLite final // for packet use |
| 119 |
{ |
| 120 |
friend class MediaFeatureManager; |
| 121 |
|
| 122 |
public: |
| 123 |
class iterator : public container_t::iterator |
| 124 |
{ |
| 125 |
public: |
| 126 |
explicit iterator(container_t::iterator it) : container_t::iterator(it) {} |
| 127 |
|
| 128 |
container_t::mapped_type operator*() { return (*this)->second; } |
| 129 |
}; |
| 130 |
|
| 131 |
ManagerLite() = default; |
| 132 |
|
| 133 |
iterator begin() { return iterator(m_features.begin()); } |
| 134 |
|
| 135 |
iterator end() { return iterator(m_features.end()); } |
| 136 |
|
| 137 |
MediaFeature *GetFeature(int featureID) |
| 138 |
{ |
| 139 |
auto iter = m_features.find(featureID); |
| 140 |
if (iter == m_features.end()) |
| 141 |
{ |
| 142 |
return nullptr; |
| 143 |
} |
| 144 |
return iter->second; |
| 145 |
} |
| 146 |
|
| 147 |
private: |
| 148 |
container_t m_features; |
| 149 |
}; |
| 150 |
|
| 151 |
public: |
| 152 |
class iterator : public container_t::iterator |
| 153 |
{ |
| 154 |
public: |
| 155 |
explicit iterator(container_t::iterator it) : container_t::iterator(it) {} |
| 156 |
|
| 157 |
container_t::mapped_type operator*() { return (*this)->second; } |
| 158 |
}; |
| 159 |
|
| 160 |
//! |
| 161 |
//! \brief MediaFeatureManager constructor |
| 162 |
//! |
| 163 |
MediaFeatureManager(){}; |
| 164 |
|
| 165 |
//! |
| 166 |
//! \brief MediaFeatureManager deconstructor |
| 167 |
//! |
| 168 |
virtual ~MediaFeatureManager() { Destroy(); } |
| 169 |
|
| 170 |
iterator begin() { return iterator(m_features.begin()); } |
| 171 |
|
| 172 |
iterator end() { return iterator(m_features.end()); } |
| 173 |
|
| 174 |
//! |
| 175 |
//! \brief Initialize all features |
| 176 |
//! \param [in] settings |
| 177 |
//! Pointer to the initialize settings |
| 178 |
//! \return MOS_STATUS |
| 179 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 180 |
//! |
| 181 |
virtual MOS_STATUS Init(void *settings) { return MOS_STATUS_UNIMPLEMENTED; } |
| 182 |
|
| 183 |
//! |
| 184 |
//! \brief Register features, if last two parameters use |
| 185 |
//! default values, feature to be registered will |
| 186 |
//! not be blocked by any packet |
| 187 |
//! \param [in] featureID |
| 188 |
//! ID of the feature to be reigstered |
| 189 |
//! \param [in] feature |
| 190 |
//! Pointer to the feature to be registered |
| 191 |
//! \param [in] packetIds |
| 192 |
//! Packet ID list, if it is an allow list, feature will |
| 193 |
//! be only added to packets in the list, otherwise feature |
| 194 |
//! will be added to packets not in the list, by default it |
| 195 |
//! is an empty list |
| 196 |
//! \param [in] packetIdListType |
| 197 |
//! Indicate whether packet ID list is a block list |
| 198 |
//! or an allow list, by default it is a block list. |
| 199 |
//! \return MOS_STATUS |
| 200 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 201 |
//! |
| 202 |
MOS_STATUS RegisterFeatures( |
| 203 |
int featureID, |
| 204 |
MediaFeature * feature, |
| 205 |
std::vector<int> &&packetIds = {}, |
| 206 |
LIST_TYPE packetIdListType = LIST_TYPE::BLOCK_LIST); |
| 207 |
|
| 208 |
//! |
| 209 |
//! \brief Get packet level feature manager |
| 210 |
//! \param [in] packetId |
| 211 |
//! ID of packet |
| 212 |
//! \return std::shared_ptr<ManagerLite> |
| 213 |
//! A pointer to packet level feature manager |
| 214 |
//! |
| 215 |
std::shared_ptr<ManagerLite> GetPacketLevelFeatureManager(int packetId); |
| 216 |
|
| 217 |
//! |
| 218 |
//! \brief Update all features |
| 219 |
//! \param [in] params |
| 220 |
//! Pointer to the params |
| 221 |
//! \return MOS_STATUS |
| 222 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 223 |
//! |
| 224 |
MOS_STATUS Update(void *params); |
| 225 |
|
| 226 |
//! |
| 227 |
//! \brief Destroy all features |
| 228 |
//! \return MOS_STATUS |
| 229 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 230 |
//! |
| 231 |
MOS_STATUS Destroy(); |
| 232 |
|
| 233 |
//! |
| 234 |
//! \brief Get feature |
| 235 |
//! \param [in] featureID |
| 236 |
//! feature ID to get the feature |
| 237 |
//! \return MediaFeature* |
| 238 |
//! Pointer of the feature |
| 239 |
//! |
| 240 |
virtual MediaFeature *GetFeature(int featureID) |
| 241 |
{ |
| 242 |
auto iter = m_features.find(featureID); |
| 243 |
if (iter == m_features.end()) |
| 244 |
{ |
| 245 |
return nullptr; |
| 246 |
} |
| 247 |
return iter->second; |
| 248 |
} |
| 249 |
//! |
| 250 |
//! \brief Get Pass Number |
| 251 |
//! \return uint8_t |
| 252 |
//! actual pass number after feature check |
| 253 |
//! |
| 254 |
uint8_t GetNumPass() { return m_passNum; }; |
| 255 |
MediaFeatureConstSettings *GetFeatureSettings() { return m_featureConstSettings; }; |
| 256 |
//! |
| 257 |
//! \brief Check the conflict between features |
| 258 |
//! \param [in] params |
| 259 |
//! encode parameters |
| 260 |
//! \return MOS_STATUS |
| 261 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 262 |
//! |
| 263 |
virtual MOS_STATUS CheckFeatures(void *params) { return MOS_STATUS_SUCCESS; }; |
| 264 |
|
| 265 |
//! |
| 266 |
//! \brief Get DDI Target Usage |
| 267 |
//! \return uint8_t |
| 268 |
//! return the DDI target usage. |
| 269 |
//! |
| 270 |
uint8_t GetDDITargetUsage(){return m_ddiTargetUsage;} |
| 271 |
void SetUserSettingPtr(MediaUserSettingSharedPtr userSettingPtr); |
| 272 |
|
| 273 |
protected: |
| 274 |
|
| 275 |
//! |
| 276 |
//! \brief Create feature const settings |
| 277 |
//! \return MOS_STATUS |
| 278 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 279 |
//! |
| 280 |
virtual MOS_STATUS CreateConstSettings() { return MOS_STATUS_SUCCESS; }; |
| 281 |
|
| 282 |
//! |
| 283 |
//! \brief Create features |
| 284 |
//! \param [in] constsettings |
| 285 |
//! feature const settings |
| 286 |
//! \return MOS_STATUS |
| 287 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 288 |
//! |
| 289 |
virtual MOS_STATUS CreateFeatures(void *constSettings) { return MOS_STATUS_SUCCESS; }; |
| 290 |
|
| 291 |
//! |
| 292 |
//! \brief Get Target Usage |
| 293 |
//! \return uint8_t |
| 294 |
//! return the target usage. |
| 295 |
//! |
| 296 |
uint8_t GetTargetUsage(){return m_targetUsage;} |
| 297 |
|
| 298 |
container_t m_features; |
| 299 |
std::map<int, std::vector<int>> m_packetIdList; // map feature ID to a vector of packet ID |
| 300 |
std::map<int, LIST_TYPE> m_packetIdListTypes; // map feature ID to a flag, indicates whether packet ID vector is a block list or an allow list |
| 301 |
MediaFeatureConstSettings *m_featureConstSettings = nullptr; |
| 302 |
uint8_t m_ddiTargetUsage = 0; // for user input setting report |
| 303 |
uint8_t m_targetUsage = 0; |
| 304 |
uint8_t m_passNum = 1; |
| 305 |
uint8_t m_forceTargetUsage = 0; |
| 306 |
|
| 307 |
// Media user setting instance |
| 308 |
MediaUserSettingSharedPtr m_userSettingPtr = nullptr; |
| 309 |
MEDIA_CLASS_DEFINE_END(MediaFeatureManager) |
| 310 |
}; |
| 311 |
|
| 312 |
#endif // !__MEDIA_FEATURE_MANAGER_H__ |