Debian Codegraph @

media_softlet/agnostic/common/shared/media_capstable.h

raw
1 /*
2 * Copyright (c) 2021, 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 #ifndef __MEDIA_CAPSTABLE_H__
24 #define __MEDIA_CAPSTABLE_H__
25
26 #include "igfxfmid.h"
27 #include "stdint.h"
28 #include "media_class_trace.h"
29
30 // This struct is designed to store common information
31
32 typedef struct PlatformInfo
33 {
34 // ipVersion -Intellectual Property
35 uint32_t ipVersion;
36 // usRevId -user reversion ID
37 uint32_t usRevId;
38
39 // std::map key need to overload operator< function
40 bool operator<(const PlatformInfo &rhs) const
41 {
42 // Make table in descending order.This is for GetCapsTablePlatform()
43 // to get the highest version which is lower than request.
44 // std::map in asending order according to the value of the key. By default, it uses std::less<KEY>.
45 // sort example {{4865 0}<{4615 4}<{4615 1}<{4561 0}<{4608 0}}
46 return (((this->ipVersion << 16) | (this->usRevId)) > ((rhs.ipVersion << 16) | (rhs.usRevId)));
47 }
48
49 } PlatformInfo;
50
51 template <typename _attributeCapsTable>
52 class MediaCapsTable
53 {
54 public:
55 typedef typename std::map<PlatformInfo, const _attributeCapsTable> OsCapsTable;
56 typedef typename OsCapsTable::iterator Iterator;
57
58 //!
59 //! \brief Constructor
60 //!
61 MediaCapsTable() {}
62
63 //!
64 //! \brief virtual destructor
65 //!
66 virtual ~MediaCapsTable() {}
67
68 // pltCaps: map to store the captable information
69 static OsCapsTable &GetOsCapsTable()
70 {
71 static OsCapsTable pltCaps = {};
72 return pltCaps;
73 }
74
75 //!
76 // \brief caps register for different Platform
77 //! \para [in] KeyType
78 //! Specific the concret platform
79 //! \para [in]_attributeCapsTable
80 //! value mapped to sepcifci KeyType(PlatformInfo)
81 //! \return bool
82 //! return fail if insert pair fail
83 //!
84 static bool RegisterCaps(PlatformInfo pltInfo, const _attributeCapsTable attrCapsTable , bool forceReplace = false)
85 {
86 Iterator attrCapsTableItem = GetOsCapsTable().find(pltInfo);
87 if (attrCapsTableItem == GetOsCapsTable().end())
88 {
89 std::pair<Iterator, bool> result =
90 GetOsCapsTable().insert(std::make_pair(pltInfo, attrCapsTable));
91 return result.second;
92 }
93 else
94 {
95 if (forceReplace)
96 {
97 GetOsCapsTable().erase(attrCapsTableItem);
98 std::pair<Iterator, bool> result =
99 GetOsCapsTable().insert(std::make_pair(pltInfo, attrCapsTable));
100 return result.second;
101 }
102 return true;
103 }
104 }
105
106 bool IsLastIterator(Iterator iterator)
107 {
108 //DDI_FUNCTION_ENTER;
109 return (iterator == GetOsCapsTable().end());
110 }
111
112 //!
113 //! \brief Get attributeCapsTable
114 //! \params [out] iter
115 //! attributeCapsTable iter
116 //! \param [in] PlatformInfo
117 //! Specific the concret platform
118 //! \return bool
119 //! return true if success
120 //!
121 //!
122 bool GetCapsTablePlatform(const PlatformInfo &pltInfo, Iterator &iter)
123 {
124 //DDI_FUNCTION_ENTER;
125
126 //get the table item w/ (table.ipversion == request.ipversion, table.revision <= request.request)
127 iter = GetOsCapsTable().lower_bound(pltInfo);
128 if (iter == GetOsCapsTable().end())
129 {
130 //DDI_NORMALMESSAGE("can't find expected PlatformInfo in GetOsCapsTable()");
131 return false;
132 }
133 if (iter->first.ipVersion != pltInfo.ipVersion)
134 {
135 //DDI_NORMALMESSAGE("Cannot find request ipVersion!");
136 return false;
137 }
138 return true;
139 }
140
141 MEDIA_CLASS_DEFINE_END(MediaCapsTable)
142 };
143
144 #endif