1 /*
2 * Copyright (c) 2018 - 2019, 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 "media_feature.h"
34 #include "media_feature_const_settings.h"
35 
36 #define CONSTRUCTFEATUREID(_componentID, _subComponentID, _featureID) \
37     (_componentID << 24 | _subComponentID << 16 | _featureID)
38 
39 enum ComponentIDs
40 {
41     FEATURE_COMPONENT_COMMON = 0,
42     FEATURE_COMPONENT_ENCODE,
43     FEATURE_COMPONENT_DECODE,
44     FEATURE_COMPONENT_VP,
45 };
46 
47 enum SubComponentIDs
48 {
49     FEATURE_SUBCOMPONENT_COMMON = 0,
50     FEATURE_SUBCOMPONENT_HEVC,
51 };
52 
53 struct FeatureIDs
54 {
55     enum CommonFeatureIDs
56     {
57         basicFeature = CONSTRUCTFEATUREID(FEATURE_COMPONENT_COMMON, FEATURE_SUBCOMPONENT_COMMON, 0),
58         encodeTile,
59 
60         reserve6,
61         reserve7,
62         reserve8,
63 
64         // Decode specific feature
65         decodePredication,
66         decodeMarker,
67     };
68 };
69 //!
70 //! \def RUN_FEATURE_INTERFACE_RETURN(_featureClassName, _featureID, _featureInterface, ...)
71 //!  Run _featureInterface if it exit
72 //!
73 #define RUN_FEATURE_INTERFACE_RETURN(_featureClassName, _featureID, _featureInterface, ...)                \
74 {                                                                                                   \
75     if(m_featureManager){                                                                           \
76         auto feature = static_cast<_featureClassName*>(m_featureManager->GetFeature(_featureID));   \
77         if (feature)                                                                                \
78         {                                                                                           \
79             MEDIA_CHK_STATUS_RETURN(feature->_featureInterface(__VA_ARGS__));                       \
80         }                                                                                           \
81     }                                                                                               \
82 }
83 
84 //!
85 //! \def RUN_FEATURE_INTERFACE_NO_RETURN(_featureClassName, _featureID, _featureInterface, ...)
86 //!  Run _featureInterface if it exit
87 //!
88 #define RUN_FEATURE_INTERFACE_NO_RETURN(_featureClassName, _featureID, _featureInterface, ...)                \
89 {                                                                                                   \
90     if(m_featureManager){                                                                           \
91         auto feature = static_cast<_featureClassName*>(m_featureManager->GetFeature(_featureID));   \
92         if (feature)                                                                                \
93         {                                                                                           \
94             feature->_featureInterface(__VA_ARGS__);                              \
95         }                                                                                           \
96     }                                                                                               \
97 }
98 
99 
100 class MediaFeature;
101 
102 class MediaFeatureManager
103 {
104 public:
105     //!
106     //! \brief  MediaFeatureManager constructor
107     //!
MediaFeatureManager()108     MediaFeatureManager() {};
109 
110     //!
111     //! \brief  MediaFeatureManager deconstructor
112     //!
~MediaFeatureManager()113     virtual ~MediaFeatureManager() { Destroy(); }
114 
115     //!
116     //! \brief  Initialize all features
117     //! \param  [in] settings
118     //!         Pointer to the initialize settings
119     //! \return MOS_STATUS
120     //!         MOS_STATUS_SUCCESS if success, else fail reason
121     //!
122     MOS_STATUS Init(void *settings);
123 
124     //!
125     //! \brief  Register features
126     //! \param  [in] featureID
127     //!         ID of the feature to be reigstered
128     //! \param  [in] feature
129     //!         Pointer to the feature to be registered
130     //! \return MOS_STATUS
131     //!         MOS_STATUS_SUCCESS if success, else fail reason
132     //!
133     MOS_STATUS RegisterFeatures(int featureID, MediaFeature *feature);
134 
135     //!
136     //! \brief  Update all features
137     //! \param  [in] params
138     //!         Pointer to the params
139     //! \return MOS_STATUS
140     //!         MOS_STATUS_SUCCESS if success, else fail reason
141     //!
142     MOS_STATUS Update(void *params);
143 
144     //!
145     //! \brief  Destroy all features
146     //! \return MOS_STATUS
147     //!         MOS_STATUS_SUCCESS if success, else fail reason
148     //!
149     MOS_STATUS Destroy();
150 
151     //!
152     //! \brief  Get feature
153     //! \param  [in] featureID
154     //!         feature ID to get the feature
155     //! \return MediaFeature*
156     //!         Pointer of the feature
157     //!
GetFeature(int featureID)158     virtual MediaFeature *GetFeature(int featureID)
159     {
160         auto iter = m_features.find(featureID);
161         if (iter == m_features.end())
162         {
163             return nullptr;
164         }
165         return iter->second;
166     }
167     //!
168     //! \brief  Get Pass Number
169     //! \return uint8_t
170     //!         actual pass number after feature check
171     //!
GetNumPass()172     uint8_t GetNumPass() { return m_passNum; };
GetFeatureSettings()173     MediaFeatureConstSettings *GetFeatureSettings() { return m_featureConstSettings; };
174     //!
175     //! \brief  Check the conflict between features
176     //! \param  [in] params
177     //!         encode parameters
178     //! \return MOS_STATUS
179     //!         MOS_STATUS_SUCCESS if success, else fail reason
180     //!
CheckFeatures(void * params)181     virtual MOS_STATUS CheckFeatures(void *params) { return MOS_STATUS_SUCCESS; };
182 
183 protected:
184 
185     //!
186     //! \brief  Create feature const settings
187     //! \return MOS_STATUS
188     //!         MOS_STATUS_SUCCESS if success, else fail reason
189     //!
CreateConstSettigs()190     virtual MOS_STATUS CreateConstSettigs() { return MOS_STATUS_SUCCESS; };
191 
192     //!
193     //! \brief  Create features
194     //! \param  [in] constsettings
195     //!         feature const settings
196     //! \return MOS_STATUS
197     //!         MOS_STATUS_SUCCESS if success, else fail reason
198     //!
CreateFeatures(void * constSettings)199     virtual MOS_STATUS CreateFeatures(void *constSettings) { return MOS_STATUS_SUCCESS; };
200 
201     //!
202     //! \brief  Get Target Usage
203     //! \return uint8_t
204     //!         return the target usage.
205     //!
GetTargetUsage()206     uint8_t GetTargetUsage(){return m_targetUsage;}
207 
208     std::map<int, MediaFeature *> m_features;
209     MediaFeatureConstSettings *m_featureConstSettings = nullptr;
210     uint8_t m_targetUsage = 0;
211     uint8_t m_passNum = 1;
212 };
213 
214 #endif  // !__MEDIA_FEATURE_MANAGER_H__
215