Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "SimpleC2Interface" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | // use MediaDefs here vs. MediaCodecConstants as this is not MediaCodec specific/dependent |
| 22 | #include <media/stagefright/foundation/MediaDefs.h> |
| 23 | |
Wonsik Kim | 0e89f31 | 2020-03-31 22:30:27 -0700 | [diff] [blame] | 24 | #include <C2PlatformSupport.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 25 | #include <SimpleC2Interface.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | /* SimpleInterface */ |
| 30 | |
| 31 | SimpleInterface<void>::BaseParams::BaseParams( |
| 32 | const std::shared_ptr<C2ReflectorHelper> &reflector, |
| 33 | C2String name, |
| 34 | C2Component::kind_t kind, |
| 35 | C2Component::domain_t domain, |
| 36 | C2String mediaType, |
| 37 | std::vector<C2String> aliases) |
| 38 | : C2InterfaceHelper(reflector) { |
| 39 | setDerivedInstance(this); |
| 40 | |
| 41 | addParameter( |
| 42 | DefineParam(mName, C2_PARAMKEY_COMPONENT_NAME) |
| 43 | .withConstValue(AllocSharedString<C2ComponentNameSetting>(name.c_str())) |
| 44 | .build()); |
| 45 | |
| 46 | if (aliases.size()) { |
| 47 | C2String joined; |
| 48 | for (const C2String &alias : aliases) { |
| 49 | if (joined.length()) { |
| 50 | joined += ","; |
| 51 | } |
| 52 | joined += alias; |
| 53 | } |
| 54 | addParameter( |
| 55 | DefineParam(mAliases, C2_PARAMKEY_COMPONENT_ALIASES) |
| 56 | .withConstValue(AllocSharedString<C2ComponentAliasesSetting>(joined.c_str())) |
| 57 | .build()); |
| 58 | } |
| 59 | |
| 60 | addParameter( |
| 61 | DefineParam(mKind, C2_PARAMKEY_COMPONENT_KIND) |
| 62 | .withConstValue(new C2ComponentKindSetting(kind)) |
| 63 | .build()); |
| 64 | |
| 65 | addParameter( |
| 66 | DefineParam(mDomain, C2_PARAMKEY_COMPONENT_DOMAIN) |
| 67 | .withConstValue(new C2ComponentDomainSetting(domain)) |
| 68 | .build()); |
| 69 | |
| 70 | // simple interfaces have single streams |
| 71 | addParameter( |
| 72 | DefineParam(mInputStreamCount, C2_PARAMKEY_INPUT_STREAM_COUNT) |
| 73 | .withConstValue(new C2PortStreamCountTuning::input(1)) |
| 74 | .build()); |
| 75 | |
| 76 | addParameter( |
| 77 | DefineParam(mOutputStreamCount, C2_PARAMKEY_OUTPUT_STREAM_COUNT) |
| 78 | .withConstValue(new C2PortStreamCountTuning::output(1)) |
| 79 | .build()); |
| 80 | |
| 81 | // set up buffer formats and allocators |
| 82 | |
| 83 | // default to linear buffers and no media type |
| 84 | C2BufferData::type_t rawBufferType = C2BufferData::LINEAR; |
| 85 | C2String rawMediaType; |
| 86 | C2Allocator::id_t rawAllocator = C2AllocatorStore::DEFAULT_LINEAR; |
| 87 | C2BlockPool::local_id_t rawPoolId = C2BlockPool::BASIC_LINEAR; |
| 88 | C2BufferData::type_t codedBufferType = C2BufferData::LINEAR; |
Wonsik Kim | 0e89f31 | 2020-03-31 22:30:27 -0700 | [diff] [blame] | 89 | int poolMask = GetCodec2PoolMask(); |
| 90 | C2Allocator::id_t preferredLinearId = GetPreferredLinearAllocatorId(poolMask); |
| 91 | C2Allocator::id_t codedAllocator = preferredLinearId; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 92 | C2BlockPool::local_id_t codedPoolId = C2BlockPool::BASIC_LINEAR; |
| 93 | |
| 94 | switch (domain) { |
Wonsik Kim | 0e89f31 | 2020-03-31 22:30:27 -0700 | [diff] [blame] | 95 | case C2Component::DOMAIN_IMAGE: [[fallthrough]]; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 96 | case C2Component::DOMAIN_VIDEO: |
| 97 | // TODO: should we define raw image? The only difference is timestamp handling |
| 98 | rawBufferType = C2BufferData::GRAPHIC; |
| 99 | rawMediaType = MEDIA_MIMETYPE_VIDEO_RAW; |
Wonsik Kim | 0e89f31 | 2020-03-31 22:30:27 -0700 | [diff] [blame] | 100 | rawAllocator = C2PlatformAllocatorStore::GRALLOC; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 101 | rawPoolId = C2BlockPool::BASIC_GRAPHIC; |
| 102 | break; |
| 103 | case C2Component::DOMAIN_AUDIO: |
| 104 | rawBufferType = C2BufferData::LINEAR; |
| 105 | rawMediaType = MEDIA_MIMETYPE_AUDIO_RAW; |
Wonsik Kim | 0e89f31 | 2020-03-31 22:30:27 -0700 | [diff] [blame] | 106 | rawAllocator = preferredLinearId; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 107 | rawPoolId = C2BlockPool::BASIC_LINEAR; |
| 108 | break; |
| 109 | default: |
| 110 | break; |
| 111 | } |
| 112 | bool isEncoder = kind == C2Component::KIND_ENCODER; |
| 113 | |
| 114 | // handle raw decoders |
| 115 | if (mediaType == rawMediaType) { |
| 116 | codedBufferType = rawBufferType; |
| 117 | codedAllocator = rawAllocator; |
| 118 | codedPoolId = rawPoolId; |
| 119 | } |
| 120 | |
| 121 | addParameter( |
| 122 | DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE) |
| 123 | .withConstValue(new C2StreamBufferTypeSetting::input( |
| 124 | 0u, isEncoder ? rawBufferType : codedBufferType)) |
| 125 | .build()); |
| 126 | |
| 127 | addParameter( |
| 128 | DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE) |
| 129 | .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>( |
| 130 | isEncoder ? rawMediaType : mediaType)) |
| 131 | .build()); |
| 132 | |
| 133 | addParameter( |
| 134 | DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE) |
| 135 | .withConstValue(new C2StreamBufferTypeSetting::output( |
| 136 | 0u, isEncoder ? codedBufferType : rawBufferType)) |
| 137 | .build()); |
| 138 | |
| 139 | addParameter( |
| 140 | DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE) |
| 141 | .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>( |
| 142 | isEncoder ? mediaType : rawMediaType)) |
| 143 | .build()); |
| 144 | |
| 145 | C2Allocator::id_t inputAllocators[1] = { isEncoder ? rawAllocator : codedAllocator }; |
| 146 | C2Allocator::id_t outputAllocators[1] = { isEncoder ? codedAllocator : rawAllocator }; |
| 147 | C2BlockPool::local_id_t outputPoolIds[1] = { isEncoder ? codedPoolId : rawPoolId }; |
| 148 | |
| 149 | addParameter( |
| 150 | DefineParam(mInputAllocators, C2_PARAMKEY_INPUT_ALLOCATORS) |
| 151 | .withDefault(C2PortAllocatorsTuning::input::AllocShared(inputAllocators)) |
| 152 | .withFields({ C2F(mInputAllocators, m.values[0]).any(), |
| 153 | C2F(mInputAllocators, m.values).inRange(0, 1) }) |
| 154 | .withSetter(Setter<C2PortAllocatorsTuning::input>::NonStrictValuesWithNoDeps) |
| 155 | .build()); |
| 156 | |
| 157 | addParameter( |
| 158 | DefineParam(mOutputAllocators, C2_PARAMKEY_OUTPUT_ALLOCATORS) |
| 159 | .withDefault(C2PortAllocatorsTuning::output::AllocShared(outputAllocators)) |
| 160 | .withFields({ C2F(mOutputAllocators, m.values[0]).any(), |
| 161 | C2F(mOutputAllocators, m.values).inRange(0, 1) }) |
| 162 | .withSetter(Setter<C2PortAllocatorsTuning::output>::NonStrictValuesWithNoDeps) |
| 163 | .build()); |
| 164 | |
| 165 | addParameter( |
| 166 | DefineParam(mOutputPoolIds, C2_PARAMKEY_OUTPUT_BLOCK_POOLS) |
| 167 | .withDefault(C2PortBlockPoolsTuning::output::AllocShared(outputPoolIds)) |
| 168 | .withFields({ C2F(mOutputPoolIds, m.values[0]).any(), |
| 169 | C2F(mOutputPoolIds, m.values).inRange(0, 1) }) |
| 170 | .withSetter(Setter<C2PortBlockPoolsTuning::output>::NonStrictValuesWithNoDeps) |
| 171 | .build()); |
| 172 | |
| 173 | // add stateless params |
| 174 | addParameter( |
| 175 | DefineParam(mSubscribedParamIndices, C2_PARAMKEY_SUBSCRIBED_PARAM_INDICES) |
| 176 | .withDefault(C2SubscribedParamIndicesTuning::AllocShared(0u)) |
| 177 | .withFields({ C2F(mSubscribedParamIndices, m.values[0]).any(), |
| 178 | C2F(mSubscribedParamIndices, m.values).any() }) |
| 179 | .withSetter(Setter<C2SubscribedParamIndicesTuning>::NonStrictValuesWithNoDeps) |
| 180 | .build()); |
| 181 | |
| 182 | /* TODO |
| 183 | |
| 184 | addParameter( |
| 185 | DefineParam(mCurrentWorkOrdinal, C2_PARAMKEY_CURRENT_WORK) |
| 186 | .withDefault(new C2CurrentWorkTuning()) |
| 187 | .withFields({ C2F(mCurrentWorkOrdinal, m.timeStamp).any(), |
| 188 | C2F(mCurrentWorkOrdinal, m.frameIndex).any(), |
| 189 | C2F(mCurrentWorkOrdinal, m.customOrdinal).any() }) |
| 190 | .withSetter(Setter<C2CurrentWorkTuning>::NonStrictValuesWithNoDeps) |
| 191 | .build()); |
| 192 | |
| 193 | addParameter( |
| 194 | DefineParam(mLastInputQueuedWorkOrdinal, C2_PARAMKEY_LAST_INPUT_QUEUED) |
| 195 | .withDefault(new C2LastWorkQueuedTuning::input()) |
| 196 | .withFields({ C2F(mLastInputQueuedWorkOrdinal, m.timeStamp).any(), |
| 197 | C2F(mLastInputQueuedWorkOrdinal, m.frameIndex).any(), |
| 198 | C2F(mLastInputQueuedWorkOrdinal, m.customOrdinal).any() }) |
| 199 | .withSetter(Setter<C2LastWorkQueuedTuning::input>::NonStrictValuesWithNoDeps) |
| 200 | .build()); |
| 201 | |
| 202 | addParameter( |
| 203 | DefineParam(mLastOutputQueuedWorkOrdinal, C2_PARAMKEY_LAST_OUTPUT_QUEUED) |
| 204 | .withDefault(new C2LastWorkQueuedTuning::output()) |
| 205 | .withFields({ C2F(mLastOutputQueuedWorkOrdinal, m.timeStamp).any(), |
| 206 | C2F(mLastOutputQueuedWorkOrdinal, m.frameIndex).any(), |
| 207 | C2F(mLastOutputQueuedWorkOrdinal, m.customOrdinal).any() }) |
| 208 | .withSetter(Setter<C2LastWorkQueuedTuning::output>::NonStrictValuesWithNoDeps) |
| 209 | .build()); |
| 210 | |
| 211 | std::shared_ptr<C2OutOfMemoryTuning> mOutOfMemory; |
| 212 | |
| 213 | std::shared_ptr<C2PortConfigCounterTuning::input> mInputConfigCounter; |
| 214 | std::shared_ptr<C2PortConfigCounterTuning::output> mOutputConfigCounter; |
| 215 | std::shared_ptr<C2ConfigCounterTuning> mDirectConfigCounter; |
| 216 | |
| 217 | */ |
| 218 | } |
| 219 | |
| 220 | void SimpleInterface<void>::BaseParams::noInputLatency() { |
| 221 | addParameter( |
| 222 | DefineParam(mRequestedInputDelay, C2_PARAMKEY_INPUT_DELAY_REQUEST) |
| 223 | .withConstValue(new C2PortRequestedDelayTuning::input(0u)) |
| 224 | .build()); |
| 225 | |
| 226 | addParameter( |
| 227 | DefineParam(mActualInputDelay, C2_PARAMKEY_INPUT_DELAY) |
| 228 | .withConstValue(new C2PortActualDelayTuning::input(0u)) |
| 229 | .build()); |
| 230 | } |
| 231 | |
| 232 | void SimpleInterface<void>::BaseParams::noOutputLatency() { |
| 233 | addParameter( |
| 234 | DefineParam(mRequestedOutputDelay, C2_PARAMKEY_OUTPUT_DELAY_REQUEST) |
| 235 | .withConstValue(new C2PortRequestedDelayTuning::output(0u)) |
| 236 | .build()); |
| 237 | |
| 238 | addParameter( |
| 239 | DefineParam(mActualOutputDelay, C2_PARAMKEY_OUTPUT_DELAY) |
| 240 | .withConstValue(new C2PortActualDelayTuning::output(0u)) |
| 241 | .build()); |
| 242 | } |
| 243 | |
| 244 | void SimpleInterface<void>::BaseParams::noPipelineLatency() { |
| 245 | addParameter( |
| 246 | DefineParam(mRequestedPipelineDelay, C2_PARAMKEY_PIPELINE_DELAY_REQUEST) |
| 247 | .withConstValue(new C2RequestedPipelineDelayTuning(0u)) |
| 248 | .build()); |
| 249 | |
| 250 | addParameter( |
| 251 | DefineParam(mActualPipelineDelay, C2_PARAMKEY_PIPELINE_DELAY) |
| 252 | .withConstValue(new C2ActualPipelineDelayTuning(0u)) |
| 253 | .build()); |
| 254 | } |
| 255 | |
| 256 | void SimpleInterface<void>::BaseParams::noPrivateBuffers() { |
| 257 | addParameter( |
| 258 | DefineParam(mPrivateAllocators, C2_PARAMKEY_PRIVATE_ALLOCATORS) |
| 259 | .withConstValue(C2PrivateAllocatorsTuning::AllocShared(0u)) |
| 260 | .build()); |
| 261 | |
| 262 | addParameter( |
| 263 | DefineParam(mMaxPrivateBufferCount, C2_PARAMKEY_MAX_PRIVATE_BUFFER_COUNT) |
| 264 | .withConstValue(C2MaxPrivateBufferCountTuning::AllocShared(0u)) |
| 265 | .build()); |
| 266 | |
| 267 | addParameter( |
| 268 | DefineParam(mPrivatePoolIds, C2_PARAMKEY_PRIVATE_BLOCK_POOLS) |
| 269 | .withConstValue(C2PrivateBlockPoolsTuning::AllocShared(0u)) |
| 270 | .build()); |
| 271 | } |
| 272 | |
| 273 | void SimpleInterface<void>::BaseParams::noInputReferences() { |
| 274 | addParameter( |
| 275 | DefineParam(mMaxInputReferenceAge, C2_PARAMKEY_INPUT_MAX_REFERENCE_AGE) |
| 276 | .withConstValue(new C2StreamMaxReferenceAgeTuning::input(0u)) |
| 277 | .build()); |
| 278 | |
| 279 | addParameter( |
| 280 | DefineParam(mMaxInputReferenceCount, C2_PARAMKEY_INPUT_MAX_REFERENCE_COUNT) |
| 281 | .withConstValue(new C2StreamMaxReferenceCountTuning::input(0u)) |
| 282 | .build()); |
| 283 | } |
| 284 | |
| 285 | void SimpleInterface<void>::BaseParams::noOutputReferences() { |
| 286 | addParameter( |
| 287 | DefineParam(mMaxOutputReferenceAge, C2_PARAMKEY_OUTPUT_MAX_REFERENCE_AGE) |
| 288 | .withConstValue(new C2StreamMaxReferenceAgeTuning::output(0u)) |
| 289 | .build()); |
| 290 | |
| 291 | addParameter( |
| 292 | DefineParam(mMaxOutputReferenceCount, C2_PARAMKEY_OUTPUT_MAX_REFERENCE_COUNT) |
| 293 | .withConstValue(new C2StreamMaxReferenceCountTuning::output(0u)) |
| 294 | .build()); |
| 295 | } |
| 296 | |
| 297 | void SimpleInterface<void>::BaseParams::noTimeStretch() { |
| 298 | addParameter( |
| 299 | DefineParam(mTimeStretch, C2_PARAMKEY_TIME_STRETCH) |
| 300 | .withConstValue(new C2ComponentTimeStretchTuning(1.f)) |
| 301 | .build()); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | Clients need to handle the following base params due to custom dependency. |
| 306 | |
| 307 | std::shared_ptr<C2ApiLevelSetting> mApiLevel; |
| 308 | std::shared_ptr<C2ApiFeaturesSetting> mApiFeatures; |
| 309 | std::shared_ptr<C2ComponentAttributesSetting> mAttrib; |
| 310 | |
| 311 | std::shared_ptr<C2PortSuggestedBufferCountTuning::input> mSuggestedInputBufferCount; |
| 312 | std::shared_ptr<C2PortSuggestedBufferCountTuning::output> mSuggestedOutputBufferCount; |
| 313 | |
| 314 | std::shared_ptr<C2TrippedTuning> mTripped; |
| 315 | |
| 316 | */ |
| 317 | |
| 318 | } // namespace android |