-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmfx_c2_component.h
More file actions
executable file
·261 lines (203 loc) · 8.86 KB
/
mfx_c2_component.h
File metadata and controls
executable file
·261 lines (203 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright (c) 2017-2021 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <C2Component.h>
#include "mfx_defs.h"
#include "mfx_c2_param_storage.h"
#include "util/C2InterfaceHelper.h"
#include <mutex>
class MfxC2Component : public C2ComponentInterface,
public C2Component,
public std::enable_shared_from_this<MfxC2Component>,
public C2InterfaceHelper
{
public:
struct CreateConfig
{
int flags{0};
bool dump_output{false};
};
protected:
/* State diagram:
+---------- release ---------------|
| +------- stop ------- ERROR
| | ^
| | |
| | error
| | |
| +------- | -- release --------+ |
| | | | |
| | | +-----start ----> RUNNING
V V V | | | ^
RELEASED <- STOPPED <--- stop ------+ | |
^ ^ | |
| | config |
| | error |
| | | start
| | V |
| +------- stop ------- TRIPPED
+---------- release ----------------|
Operations permitted:
Tunings could be applied in all states.
Settings could be applied in STOPPED state only.
*/
enum class State
{
STOPPED,
RUNNING,
TRIPPED,
ERROR,
RELEASED
};
protected:
MfxC2Component(const C2String& name, const CreateConfig& config, std::shared_ptr<C2ReflectorHelper> reflector);
MFX_CLASS_NO_COPY(MfxC2Component)
// provides static Create method to registrate in components registry
// variadic template args to be passed into component constructor
template<typename ComponentClass, typename... ArgTypes>
struct Factory;
public:
virtual ~MfxC2Component();
#ifdef ONEVPL_EXPERIMENTAL
bool isdGPU() { return dedicated;}
#endif
private: // Non-virtual interface methods optionally overridden in descendants
virtual c2_status_t Init() = 0;
virtual c2_status_t DoStart();
virtual c2_status_t DoStop(bool abort);
virtual c2_status_t Pause() { return C2_OK; }
virtual c2_status_t Resume() { return C2_OK; }
virtual c2_status_t Release() { return C2_OK; }
virtual c2_status_t UpdateMfxParamToC2(std::unique_lock<std::mutex>/*state_lock*/,
const std::vector<C2Param*>&/*stackParams*/,
const std::vector<C2Param::Index> &/*heapParamIndices*/,
c2_blocking_t /*mayBlock*/,
std::vector<std::unique_ptr<C2Param>>* const /*heapParams*/) const { return C2_OMITTED; }
virtual c2_status_t UpdateC2ParamToMfx(std::unique_lock<std::mutex>/*state_lock*/,
const std::vector<C2Param*> &/*params*/,
c2_blocking_t /*mayBlock*/,
std::vector<std::unique_ptr<C2SettingResult>>* const /*failures*/) { return C2_OMITTED; }
virtual c2_status_t Queue(std::list<std::unique_ptr<C2Work>>* const /*items*/) { return C2_OMITTED; }
virtual c2_status_t Flush(std::list<std::unique_ptr<C2Work>>* const /*flushedWork*/) { return C2_OK; }
protected: // C2ComponentInterface overrides
C2String getName() const override;
c2_node_id_t getId() const override;
c2_status_t query_vb(
const std::vector<C2Param*> &stackParams,
const std::vector<C2Param::Index> &heapParamIndices,
c2_blocking_t mayBlock,
std::vector<std::unique_ptr<C2Param>>* const heapParams) const override;
c2_status_t config_vb(
const std::vector<C2Param*> ¶ms,
c2_blocking_t mayBlock,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
c2_status_t createTunnel_sm(c2_node_id_t targetComponent) override;
c2_status_t releaseTunnel_sm(c2_node_id_t targetComponent) override;
c2_status_t querySupportedParams_nb(
std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const override;
c2_status_t querySupportedValues_vb(
std::vector<C2FieldSupportedValuesQuery> &queries, c2_blocking_t mayBlock) const override;
protected: // C2Component
c2_status_t queue_nb(std::list<std::unique_ptr<C2Work>>* const items) override;
c2_status_t announce_nb(const std::vector<C2WorkOutline> &items) override;
c2_status_t flush_sm(flush_mode_t mode, std::list<std::unique_ptr<C2Work>>* const flushedWork) override;
c2_status_t drain_nb(drain_mode_t mode) override;
c2_status_t start() override;
c2_status_t stop() override;
c2_status_t reset() override;
c2_status_t release() override;
std::shared_ptr<C2ComponentInterface> intf() override;
c2_status_t setListener_vb(
const std::shared_ptr<Listener> &listener, c2_blocking_t mayBlock) override;
protected:
void NotifyListeners(std::function<void(std::shared_ptr<Listener>)> notify);
void NotifyWorkDone(std::unique_ptr<C2Work>&& work, c2_status_t sts);
void ConfigError(const std::vector<std::shared_ptr<C2SettingResult>>& setting_result);
void FatalError(c2_status_t error);
std::unique_lock<std::mutex> AcquireStableStateLock(bool may_block) const;
std::unique_lock<std::mutex> AcquireRunningStateLock(bool may_block) const;
#ifdef ONEVPL_EXPERIMENTAL
void detectdGPU(mfxU16 deviceId) {
// DG2 paiid from kernel/include/drm/i915_pciids.h#696
if (deviceId >= 0x5690 && deviceId <= 0x56B3)
dedicated = true;
else
dedicated = false;
}
#endif
private:
c2_status_t CheckStateTransitionConflict(
const std::unique_lock<std::mutex>& state_lock,
State next_state);
protected: // variables
State m_state = State::STOPPED;
State m_nextState = State::STOPPED;
// If next_state_ != state_ then it is a transition state.
// If they are equal it is a stable state.
mutable std::mutex m_stateMutex;
mutable std::condition_variable m_condStateStable; // notified when state gets stable
mutable std::mutex m_releaseMutex;
C2String m_name;
CreateConfig m_createConfig;
mfxIMPL m_mfxImplementation;
private:
std::list<std::shared_ptr<Listener>> m_listeners;
std::mutex m_listenersMutex;
#ifdef ONEVPL_EXPERIMENTAL
bool dedicated = false;
#endif
};
typedef MfxC2Component* (CreateMfxC2ComponentFunc)(const char* name,
const MfxC2Component::CreateConfig& config,
std::shared_ptr<C2ReflectorHelper> reflector, c2_status_t* status);
template<typename ComponentClass, typename... ArgTypes>
struct MfxC2Component::Factory
{
// method to create and init instance of component
// variadic args are passed to constructor
template<ArgTypes... arg_values>
static MfxC2Component* Create(const char* name, const CreateConfig& config,
std::shared_ptr<C2ReflectorHelper> reflector, c2_status_t* status)
{
c2_status_t result = C2_OK;
// class to make constructor public and get access to new operator
struct ConstructedClass : public ComponentClass
{
public:
ConstructedClass(const char* name, const CreateConfig& config,
std::shared_ptr<C2ReflectorHelper> reflector, ArgTypes... constructor_args) :
ComponentClass(name, config, std::move(reflector), constructor_args...) { }
};
MfxC2Component* component =
new (std::nothrow) ConstructedClass(name, config, std::move(reflector), arg_values...);
if(component != nullptr) {
result = component->Init();
if(result != C2_OK) {
delete component;
component = nullptr;
}
}
else {
result = C2_NO_MEMORY;
}
if (nullptr != status) *status = result;
return component;
}
};