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
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_SIMPLE_C2_INTERFACE_H_
#define ANDROID_SIMPLE_C2_INTERFACE_H_
#include <C2Component.h>
#include <C2Config.h>
#include <util/C2InterfaceHelper.h>
namespace android {
/**
* Wrap a common interface object (such as Codec2Client::Interface, or C2InterfaceHelper into
* a C2ComponentInterface.
*
* \param T common interface type
*/
template <typename T>
class SimpleC2Interface : public C2ComponentInterface {
public:
SimpleC2Interface(const char *name, c2_node_id_t id, const std::shared_ptr<T> &impl)
: mName(name),
mId(id),
mImpl(impl) {
}
~SimpleC2Interface() override = default;
// From C2ComponentInterface
C2String getName() const override { return mName; }
c2_node_id_t getId() const override { return mId; }
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 {
return mImpl->query(stackParams, heapParamIndices, mayBlock, heapParams);
}
c2_status_t config_vb(
const std::vector<C2Param*> ¶ms,
c2_blocking_t mayBlock,
std::vector<std::unique_ptr<C2SettingResult>>* const failures) override {
return mImpl->config(params, mayBlock, failures);
}
c2_status_t createTunnel_sm(c2_node_id_t) override { return C2_OMITTED; }
c2_status_t releaseTunnel_sm(c2_node_id_t) override { return C2_OMITTED; }
c2_status_t querySupportedParams_nb(
std::vector<std::shared_ptr<C2ParamDescriptor>> * const params) const override {
return mImpl->querySupportedParams(params);
}
c2_status_t querySupportedValues_vb(
std::vector<C2FieldSupportedValuesQuery> &fields,
c2_blocking_t mayBlock) const override {
return mImpl->querySupportedValues(fields, mayBlock);
}
private:
C2String mName;
const c2_node_id_t mId;
const std::shared_ptr<T> mImpl;
};
/**
* Utility classes for common interfaces.
*/
template<>
class SimpleC2Interface<void> {
public:
/**
* Base Codec 2.0 parameters required for all components.
*/
struct BaseParams : C2InterfaceHelper {
explicit BaseParams(
const std::shared_ptr<C2ReflectorHelper> &helper,
C2String name,
C2Component::kind_t kind,
C2Component::domain_t domain,
C2String mediaType,
std::vector<C2String> aliases = std::vector<C2String>());
/// Marks that this component has no input latency. Otherwise, component must
/// add support for C2PortRequestedDelayTuning::input and C2PortActualDelayTuning::input.
void noInputLatency();
/// Marks that this component has no output latency. Otherwise, component must
/// add support for C2PortRequestedDelayTuning::output and C2PortActualDelayTuning::output.
void noOutputLatency();
/// Marks that this component has no pipeline latency. Otherwise, component must
/// add support for C2RequestedPipelineDelayTuning and C2ActualPipelineDelayTuning.
void noPipelineLatency();
/// Marks that this component has no need for private buffers. Otherwise, component must
/// add support for C2MaxPrivateBufferCountTuning, C2PrivateAllocatorsTuning and
/// C2PrivateBlockPoolsTuning.
void noPrivateBuffers();
/// Marks that this component holds no references to input buffers. Otherwise, component
/// must add support for C2StreamMaxReferenceAgeTuning::input and
/// C2StreamMaxReferenceCountTuning::input.
void noInputReferences();
/// Marks that this component holds no references to output buffers. Otherwise, component
/// must add support for C2StreamMaxReferenceAgeTuning::output and
/// C2StreamMaxReferenceCountTuning::output.
void noOutputReferences();
/// Marks that this component does not stretch time. Otherwise, component
/// must add support for C2ComponentTimeStretchTuning.
void noTimeStretch();
std::shared_ptr<C2ApiLevelSetting> mApiLevel;
std::shared_ptr<C2ApiFeaturesSetting> mApiFeatures;
std::shared_ptr<C2PlatformLevelSetting> mPlatformLevel;
std::shared_ptr<C2PlatformFeaturesSetting> mPlatformFeatures;
std::shared_ptr<C2ComponentNameSetting> mName;
std::shared_ptr<C2ComponentAliasesSetting> mAliases;
std::shared_ptr<C2ComponentKindSetting> mKind;
std::shared_ptr<C2ComponentDomainSetting> mDomain;
std::shared_ptr<C2ComponentAttributesSetting> mAttrib;
std::shared_ptr<C2ComponentTimeStretchTuning> mTimeStretch;
std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
std::shared_ptr<C2PortRequestedDelayTuning::input> mRequestedInputDelay;
std::shared_ptr<C2PortRequestedDelayTuning::output> mRequestedOutputDelay;
std::shared_ptr<C2RequestedPipelineDelayTuning> mRequestedPipelineDelay;
std::shared_ptr<C2PortActualDelayTuning::input> mActualInputDelay;
std::shared_ptr<C2PortActualDelayTuning::output> mActualOutputDelay;
std::shared_ptr<C2ActualPipelineDelayTuning> mActualPipelineDelay;
std::shared_ptr<C2StreamMaxReferenceAgeTuning::input> mMaxInputReferenceAge;
std::shared_ptr<C2StreamMaxReferenceCountTuning::input> mMaxInputReferenceCount;
std::shared_ptr<C2StreamMaxReferenceAgeTuning::output> mMaxOutputReferenceAge;
std::shared_ptr<C2StreamMaxReferenceCountTuning::output> mMaxOutputReferenceCount;
std::shared_ptr<C2MaxPrivateBufferCountTuning> mMaxPrivateBufferCount;
std::shared_ptr<C2PortStreamCountTuning::input> mInputStreamCount;
std::shared_ptr<C2PortStreamCountTuning::output> mOutputStreamCount;
std::shared_ptr<C2SubscribedParamIndicesTuning> mSubscribedParamIndices;
std::shared_ptr<C2PortSuggestedBufferCountTuning::input> mSuggestedInputBufferCount;
std::shared_ptr<C2PortSuggestedBufferCountTuning::output> mSuggestedOutputBufferCount;
std::shared_ptr<C2CurrentWorkTuning> mCurrentWorkOrdinal;
std::shared_ptr<C2LastWorkQueuedTuning::input> mLastInputQueuedWorkOrdinal;
std::shared_ptr<C2LastWorkQueuedTuning::output> mLastOutputQueuedWorkOrdinal;
std::shared_ptr<C2PortAllocatorsTuning::input> mInputAllocators;
std::shared_ptr<C2PortAllocatorsTuning::output> mOutputAllocators;
std::shared_ptr<C2PrivateAllocatorsTuning> mPrivateAllocators;
std::shared_ptr<C2PortBlockPoolsTuning::output> mOutputPoolIds;
std::shared_ptr<C2PrivateBlockPoolsTuning> mPrivatePoolIds;
std::shared_ptr<C2TrippedTuning> mTripped;
std::shared_ptr<C2OutOfMemoryTuning> mOutOfMemory;
std::shared_ptr<C2PortConfigCounterTuning::input> mInputConfigCounter;
std::shared_ptr<C2PortConfigCounterTuning::output> mOutputConfigCounter;
std::shared_ptr<C2ConfigCounterTuning> mDirectConfigCounter;
};
};
template<typename T>
using SimpleInterface = SimpleC2Interface<T>;
template<typename T, typename ...Args>
std::shared_ptr<T> AllocSharedString(const Args(&... args), const char *str) {
size_t len = strlen(str) + 1;
std::shared_ptr<T> ret = T::AllocShared(len, args...);
strcpy(ret->m.value, str);
return ret;
}
template<typename T, typename ...Args>
std::shared_ptr<T> AllocSharedString(const Args(&... args), const std::string &str) {
std::shared_ptr<T> ret = T::AllocShared(str.length() + 1, args...);
strcpy(ret->m.value, str.c_str());
return ret;
}
template <typename T>
struct Setter {
typedef typename std::remove_reference<T>::type type;
static C2R NonStrictValueWithNoDeps(
bool mayBlock, C2InterfaceHelper::C2P<type> &me) {
(void)mayBlock;
return me.F(me.v.value).validatePossible(me.v.value);
}
static C2R NonStrictValuesWithNoDeps(
bool mayBlock, C2InterfaceHelper::C2P<type> &me) {
(void)mayBlock;
C2R res = C2R::Ok();
for (size_t ix = 0; ix < me.v.flexCount(); ++ix) {
res.plus(me.F(me.v.m.values[ix]).validatePossible(me.v.m.values[ix]));
}
return res;
}
static C2R StrictValueWithNoDeps(
bool mayBlock,
const C2InterfaceHelper::C2P<type> &old,
C2InterfaceHelper::C2P<type> &me) {
(void)mayBlock;
if (!me.F(me.v.value).supportsNow(me.v.value)) {
me.set().value = old.v.value;
}
return me.F(me.v.value).validatePossible(me.v.value);
}
};
} // namespace android
#endif // ANDROID_SIMPLE_C2_INTERFACE_H_
|