Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 "C2SoftAvcDec" |
| 19 | #include <log/log.h> |
| 20 | |
| 21 | #include <media/stagefright/foundation/MediaDefs.h> |
| 22 | |
| 23 | #include <C2Debug.h> |
| 24 | #include <C2PlatformSupport.h> |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 25 | #include <Codec2BufferUtils.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 26 | #include <Codec2Mapper.h> |
| 27 | #include <SimpleC2Interface.h> |
| 28 | |
| 29 | #include "C2SoftAvcDec.h" |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | namespace { |
Harish Mahendrakar | e55c471 | 2019-07-26 12:32:13 -0700 | [diff] [blame] | 34 | constexpr size_t kMinInputBufferSize = 2 * 1024 * 1024; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 35 | constexpr char COMPONENT_NAME[] = "c2.android.avc.decoder"; |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 36 | constexpr uint32_t kDefaultOutputDelay = 8; |
Harish Mahendrakar | 7b8409e | 2020-08-12 20:34:42 -0700 | [diff] [blame] | 37 | /* avc specification allows for a maximum delay of 16 frames. |
| 38 | As soft avc decoder supports interlaced, this delay would be 32 fields. |
| 39 | And avc decoder implementation has an additional delay of 2 decode calls. |
| 40 | So total maximum output delay is 34 */ |
| 41 | constexpr uint32_t kMaxOutputDelay = 34; |
Harish Mahendrakar | a17cf65 | 2020-04-02 05:45:05 +0530 | [diff] [blame] | 42 | constexpr uint32_t kMinInputBytes = 4; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 43 | } // namespace |
| 44 | |
| 45 | class C2SoftAvcDec::IntfImpl : public SimpleInterface<void>::BaseParams { |
| 46 | public: |
| 47 | explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper) |
| 48 | : SimpleInterface<void>::BaseParams( |
| 49 | helper, |
| 50 | COMPONENT_NAME, |
| 51 | C2Component::KIND_DECODER, |
| 52 | C2Component::DOMAIN_VIDEO, |
| 53 | MEDIA_MIMETYPE_VIDEO_AVC) { |
| 54 | noPrivateBuffers(); // TODO: account for our buffers here |
| 55 | noInputReferences(); |
| 56 | noOutputReferences(); |
| 57 | noInputLatency(); |
| 58 | noTimeStretch(); |
| 59 | |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 60 | // TODO: Proper support for reorder depth. |
| 61 | addParameter( |
| 62 | DefineParam(mActualOutputDelay, C2_PARAMKEY_OUTPUT_DELAY) |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 63 | .withDefault(new C2PortActualDelayTuning::output(kDefaultOutputDelay)) |
| 64 | .withFields({C2F(mActualOutputDelay, value).inRange(0, kMaxOutputDelay)}) |
| 65 | .withSetter(Setter<decltype(*mActualOutputDelay)>::StrictValueWithNoDeps) |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 66 | .build()); |
| 67 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 68 | // TODO: output latency and reordering |
| 69 | |
| 70 | addParameter( |
| 71 | DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES) |
| 72 | .withConstValue(new C2ComponentAttributesSetting(C2Component::ATTRIB_IS_TEMPORAL)) |
| 73 | .build()); |
| 74 | |
| 75 | // coded and output picture size is the same for this codec |
| 76 | addParameter( |
| 77 | DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE) |
| 78 | .withDefault(new C2StreamPictureSizeInfo::output(0u, 320, 240)) |
| 79 | .withFields({ |
| 80 | C2F(mSize, width).inRange(2, 4080, 2), |
| 81 | C2F(mSize, height).inRange(2, 4080, 2), |
| 82 | }) |
| 83 | .withSetter(SizeSetter) |
| 84 | .build()); |
| 85 | |
| 86 | addParameter( |
| 87 | DefineParam(mMaxSize, C2_PARAMKEY_MAX_PICTURE_SIZE) |
| 88 | .withDefault(new C2StreamMaxPictureSizeTuning::output(0u, 320, 240)) |
| 89 | .withFields({ |
| 90 | C2F(mSize, width).inRange(2, 4080, 2), |
| 91 | C2F(mSize, height).inRange(2, 4080, 2), |
| 92 | }) |
| 93 | .withSetter(MaxPictureSizeSetter, mSize) |
| 94 | .build()); |
| 95 | |
| 96 | addParameter( |
| 97 | DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL) |
| 98 | .withDefault(new C2StreamProfileLevelInfo::input(0u, |
| 99 | C2Config::PROFILE_AVC_CONSTRAINED_BASELINE, C2Config::LEVEL_AVC_5_2)) |
| 100 | .withFields({ |
| 101 | C2F(mProfileLevel, profile).oneOf({ |
| 102 | C2Config::PROFILE_AVC_CONSTRAINED_BASELINE, |
| 103 | C2Config::PROFILE_AVC_BASELINE, |
| 104 | C2Config::PROFILE_AVC_MAIN, |
| 105 | C2Config::PROFILE_AVC_CONSTRAINED_HIGH, |
| 106 | C2Config::PROFILE_AVC_PROGRESSIVE_HIGH, |
| 107 | C2Config::PROFILE_AVC_HIGH}), |
| 108 | C2F(mProfileLevel, level).oneOf({ |
| 109 | C2Config::LEVEL_AVC_1, C2Config::LEVEL_AVC_1B, C2Config::LEVEL_AVC_1_1, |
| 110 | C2Config::LEVEL_AVC_1_2, C2Config::LEVEL_AVC_1_3, |
| 111 | C2Config::LEVEL_AVC_2, C2Config::LEVEL_AVC_2_1, C2Config::LEVEL_AVC_2_2, |
| 112 | C2Config::LEVEL_AVC_3, C2Config::LEVEL_AVC_3_1, C2Config::LEVEL_AVC_3_2, |
| 113 | C2Config::LEVEL_AVC_4, C2Config::LEVEL_AVC_4_1, C2Config::LEVEL_AVC_4_2, |
| 114 | C2Config::LEVEL_AVC_5, C2Config::LEVEL_AVC_5_1, C2Config::LEVEL_AVC_5_2 |
| 115 | }) |
| 116 | }) |
| 117 | .withSetter(ProfileLevelSetter, mSize) |
| 118 | .build()); |
| 119 | |
| 120 | addParameter( |
| 121 | DefineParam(mMaxInputSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE) |
Harish Mahendrakar | e55c471 | 2019-07-26 12:32:13 -0700 | [diff] [blame] | 122 | .withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kMinInputBufferSize)) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 123 | .withFields({ |
| 124 | C2F(mMaxInputSize, value).any(), |
| 125 | }) |
| 126 | .calculatedAs(MaxInputSizeSetter, mMaxSize) |
| 127 | .build()); |
| 128 | |
| 129 | C2ChromaOffsetStruct locations[1] = { C2ChromaOffsetStruct::ITU_YUV_420_0() }; |
| 130 | std::shared_ptr<C2StreamColorInfo::output> defaultColorInfo = |
| 131 | C2StreamColorInfo::output::AllocShared( |
| 132 | 1u, 0u, 8u /* bitDepth */, C2Color::YUV_420); |
| 133 | memcpy(defaultColorInfo->m.locations, locations, sizeof(locations)); |
| 134 | |
| 135 | defaultColorInfo = |
| 136 | C2StreamColorInfo::output::AllocShared( |
| 137 | { C2ChromaOffsetStruct::ITU_YUV_420_0() }, |
| 138 | 0u, 8u /* bitDepth */, C2Color::YUV_420); |
| 139 | helper->addStructDescriptors<C2ChromaOffsetStruct>(); |
| 140 | |
| 141 | addParameter( |
| 142 | DefineParam(mColorInfo, C2_PARAMKEY_CODED_COLOR_INFO) |
| 143 | .withConstValue(defaultColorInfo) |
| 144 | .build()); |
| 145 | |
| 146 | addParameter( |
| 147 | DefineParam(mDefaultColorAspects, C2_PARAMKEY_DEFAULT_COLOR_ASPECTS) |
| 148 | .withDefault(new C2StreamColorAspectsTuning::output( |
| 149 | 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED, |
| 150 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 151 | .withFields({ |
| 152 | C2F(mDefaultColorAspects, range).inRange( |
| 153 | C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 154 | C2F(mDefaultColorAspects, primaries).inRange( |
| 155 | C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER), |
| 156 | C2F(mDefaultColorAspects, transfer).inRange( |
| 157 | C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER), |
| 158 | C2F(mDefaultColorAspects, matrix).inRange( |
| 159 | C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER) |
| 160 | }) |
| 161 | .withSetter(DefaultColorAspectsSetter) |
| 162 | .build()); |
| 163 | |
| 164 | addParameter( |
| 165 | DefineParam(mCodedColorAspects, C2_PARAMKEY_VUI_COLOR_ASPECTS) |
| 166 | .withDefault(new C2StreamColorAspectsInfo::input( |
| 167 | 0u, C2Color::RANGE_LIMITED, C2Color::PRIMARIES_UNSPECIFIED, |
| 168 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 169 | .withFields({ |
| 170 | C2F(mCodedColorAspects, range).inRange( |
| 171 | C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 172 | C2F(mCodedColorAspects, primaries).inRange( |
| 173 | C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER), |
| 174 | C2F(mCodedColorAspects, transfer).inRange( |
| 175 | C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER), |
| 176 | C2F(mCodedColorAspects, matrix).inRange( |
| 177 | C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER) |
| 178 | }) |
| 179 | .withSetter(CodedColorAspectsSetter) |
| 180 | .build()); |
| 181 | |
| 182 | addParameter( |
| 183 | DefineParam(mColorAspects, C2_PARAMKEY_COLOR_ASPECTS) |
| 184 | .withDefault(new C2StreamColorAspectsInfo::output( |
| 185 | 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED, |
| 186 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 187 | .withFields({ |
| 188 | C2F(mColorAspects, range).inRange( |
| 189 | C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 190 | C2F(mColorAspects, primaries).inRange( |
| 191 | C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER), |
| 192 | C2F(mColorAspects, transfer).inRange( |
| 193 | C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER), |
| 194 | C2F(mColorAspects, matrix).inRange( |
| 195 | C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER) |
| 196 | }) |
| 197 | .withSetter(ColorAspectsSetter, mDefaultColorAspects, mCodedColorAspects) |
| 198 | .build()); |
| 199 | |
| 200 | // TODO: support more formats? |
| 201 | addParameter( |
| 202 | DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT) |
| 203 | .withConstValue(new C2StreamPixelFormatInfo::output( |
| 204 | 0u, HAL_PIXEL_FORMAT_YCBCR_420_888)) |
| 205 | .build()); |
| 206 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 207 | static C2R SizeSetter(bool mayBlock, const C2P<C2StreamPictureSizeInfo::output> &oldMe, |
Lajos Molnar | 3bb81cd | 2019-02-20 15:10:30 -0800 | [diff] [blame] | 208 | C2P<C2StreamPictureSizeInfo::output> &me) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 209 | (void)mayBlock; |
| 210 | C2R res = C2R::Ok(); |
| 211 | if (!me.F(me.v.width).supportsAtAll(me.v.width)) { |
| 212 | res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.width))); |
| 213 | me.set().width = oldMe.v.width; |
| 214 | } |
| 215 | if (!me.F(me.v.height).supportsAtAll(me.v.height)) { |
| 216 | res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.height))); |
| 217 | me.set().height = oldMe.v.height; |
| 218 | } |
| 219 | return res; |
| 220 | } |
| 221 | |
| 222 | static C2R MaxPictureSizeSetter(bool mayBlock, C2P<C2StreamMaxPictureSizeTuning::output> &me, |
| 223 | const C2P<C2StreamPictureSizeInfo::output> &size) { |
| 224 | (void)mayBlock; |
| 225 | // TODO: get max width/height from the size's field helpers vs. hardcoding |
| 226 | me.set().width = c2_min(c2_max(me.v.width, size.v.width), 4080u); |
| 227 | me.set().height = c2_min(c2_max(me.v.height, size.v.height), 4080u); |
| 228 | return C2R::Ok(); |
| 229 | } |
| 230 | |
| 231 | static C2R MaxInputSizeSetter(bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input> &me, |
| 232 | const C2P<C2StreamMaxPictureSizeTuning::output> &maxSize) { |
| 233 | (void)mayBlock; |
| 234 | // assume compression ratio of 2 |
Harish Mahendrakar | e55c471 | 2019-07-26 12:32:13 -0700 | [diff] [blame] | 235 | me.set().value = c2_max((((maxSize.v.width + 15) / 16) |
| 236 | * ((maxSize.v.height + 15) / 16) * 192), kMinInputBufferSize); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 237 | return C2R::Ok(); |
| 238 | } |
| 239 | |
| 240 | static C2R ProfileLevelSetter(bool mayBlock, C2P<C2StreamProfileLevelInfo::input> &me, |
| 241 | const C2P<C2StreamPictureSizeInfo::output> &size) { |
| 242 | (void)mayBlock; |
| 243 | (void)size; |
| 244 | (void)me; // TODO: validate |
| 245 | return C2R::Ok(); |
| 246 | } |
| 247 | |
| 248 | static C2R DefaultColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsTuning::output> &me) { |
| 249 | (void)mayBlock; |
| 250 | if (me.v.range > C2Color::RANGE_OTHER) { |
| 251 | me.set().range = C2Color::RANGE_OTHER; |
| 252 | } |
| 253 | if (me.v.primaries > C2Color::PRIMARIES_OTHER) { |
| 254 | me.set().primaries = C2Color::PRIMARIES_OTHER; |
| 255 | } |
| 256 | if (me.v.transfer > C2Color::TRANSFER_OTHER) { |
| 257 | me.set().transfer = C2Color::TRANSFER_OTHER; |
| 258 | } |
| 259 | if (me.v.matrix > C2Color::MATRIX_OTHER) { |
| 260 | me.set().matrix = C2Color::MATRIX_OTHER; |
| 261 | } |
| 262 | return C2R::Ok(); |
| 263 | } |
| 264 | |
| 265 | static C2R CodedColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::input> &me) { |
| 266 | (void)mayBlock; |
| 267 | if (me.v.range > C2Color::RANGE_OTHER) { |
| 268 | me.set().range = C2Color::RANGE_OTHER; |
| 269 | } |
| 270 | if (me.v.primaries > C2Color::PRIMARIES_OTHER) { |
| 271 | me.set().primaries = C2Color::PRIMARIES_OTHER; |
| 272 | } |
| 273 | if (me.v.transfer > C2Color::TRANSFER_OTHER) { |
| 274 | me.set().transfer = C2Color::TRANSFER_OTHER; |
| 275 | } |
| 276 | if (me.v.matrix > C2Color::MATRIX_OTHER) { |
| 277 | me.set().matrix = C2Color::MATRIX_OTHER; |
| 278 | } |
| 279 | return C2R::Ok(); |
| 280 | } |
| 281 | |
| 282 | static C2R ColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::output> &me, |
| 283 | const C2P<C2StreamColorAspectsTuning::output> &def, |
| 284 | const C2P<C2StreamColorAspectsInfo::input> &coded) { |
| 285 | (void)mayBlock; |
| 286 | // take default values for all unspecified fields, and coded values for specified ones |
| 287 | me.set().range = coded.v.range == RANGE_UNSPECIFIED ? def.v.range : coded.v.range; |
| 288 | me.set().primaries = coded.v.primaries == PRIMARIES_UNSPECIFIED |
| 289 | ? def.v.primaries : coded.v.primaries; |
| 290 | me.set().transfer = coded.v.transfer == TRANSFER_UNSPECIFIED |
| 291 | ? def.v.transfer : coded.v.transfer; |
| 292 | me.set().matrix = coded.v.matrix == MATRIX_UNSPECIFIED ? def.v.matrix : coded.v.matrix; |
| 293 | return C2R::Ok(); |
| 294 | } |
| 295 | |
| 296 | std::shared_ptr<C2StreamColorAspectsInfo::output> getColorAspects_l() { |
| 297 | return mColorAspects; |
| 298 | } |
| 299 | |
| 300 | private: |
| 301 | std::shared_ptr<C2StreamProfileLevelInfo::input> mProfileLevel; |
| 302 | std::shared_ptr<C2StreamPictureSizeInfo::output> mSize; |
| 303 | std::shared_ptr<C2StreamMaxPictureSizeTuning::output> mMaxSize; |
| 304 | std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize; |
| 305 | std::shared_ptr<C2StreamColorInfo::output> mColorInfo; |
| 306 | std::shared_ptr<C2StreamColorAspectsInfo::input> mCodedColorAspects; |
| 307 | std::shared_ptr<C2StreamColorAspectsTuning::output> mDefaultColorAspects; |
| 308 | std::shared_ptr<C2StreamColorAspectsInfo::output> mColorAspects; |
| 309 | std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormat; |
| 310 | }; |
| 311 | |
| 312 | static size_t getCpuCoreCount() { |
| 313 | long cpuCoreCount = 1; |
| 314 | #if defined(_SC_NPROCESSORS_ONLN) |
| 315 | cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN); |
| 316 | #else |
| 317 | // _SC_NPROC_ONLN must be defined... |
| 318 | cpuCoreCount = sysconf(_SC_NPROC_ONLN); |
| 319 | #endif |
| 320 | CHECK(cpuCoreCount >= 1); |
| 321 | ALOGV("Number of CPU cores: %ld", cpuCoreCount); |
| 322 | return (size_t)cpuCoreCount; |
| 323 | } |
| 324 | |
| 325 | static void *ivd_aligned_malloc(void *ctxt, WORD32 alignment, WORD32 size) { |
| 326 | (void) ctxt; |
| 327 | return memalign(alignment, size); |
| 328 | } |
| 329 | |
| 330 | static void ivd_aligned_free(void *ctxt, void *mem) { |
| 331 | (void) ctxt; |
| 332 | free(mem); |
| 333 | } |
| 334 | |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 335 | static IV_COLOR_FORMAT_T GetIvColorFormat() { |
| 336 | static IV_COLOR_FORMAT_T sColorFormat = |
| 337 | (GetYuv420FlexibleLayout() == FLEX_LAYOUT_SEMIPLANAR_UV) ? IV_YUV_420SP_UV : |
| 338 | (GetYuv420FlexibleLayout() == FLEX_LAYOUT_SEMIPLANAR_VU) ? IV_YUV_420SP_VU : |
| 339 | IV_YUV_420P; |
| 340 | return sColorFormat; |
| 341 | } |
| 342 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 343 | C2SoftAvcDec::C2SoftAvcDec( |
| 344 | const char *name, |
| 345 | c2_node_id_t id, |
| 346 | const std::shared_ptr<IntfImpl> &intfImpl) |
| 347 | : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)), |
| 348 | mIntf(intfImpl), |
| 349 | mDecHandle(nullptr), |
| 350 | mOutBufferFlush(nullptr), |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 351 | mOutputDelay(kDefaultOutputDelay), |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 352 | mWidth(320), |
| 353 | mHeight(240), |
Rakesh Kumar | 4ec85ae | 2019-02-13 00:50:07 +0530 | [diff] [blame] | 354 | mHeaderDecoded(false), |
| 355 | mOutIndex(0u) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 356 | GENERATE_FILE_NAMES(); |
| 357 | CREATE_DUMP_FILE(mInFile); |
| 358 | } |
| 359 | |
| 360 | C2SoftAvcDec::~C2SoftAvcDec() { |
| 361 | onRelease(); |
| 362 | } |
| 363 | |
| 364 | c2_status_t C2SoftAvcDec::onInit() { |
| 365 | status_t err = initDecoder(); |
| 366 | return err == OK ? C2_OK : C2_CORRUPTED; |
| 367 | } |
| 368 | |
| 369 | c2_status_t C2SoftAvcDec::onStop() { |
| 370 | if (OK != resetDecoder()) return C2_CORRUPTED; |
| 371 | resetPlugin(); |
| 372 | return C2_OK; |
| 373 | } |
| 374 | |
| 375 | void C2SoftAvcDec::onReset() { |
| 376 | (void) onStop(); |
| 377 | } |
| 378 | |
| 379 | void C2SoftAvcDec::onRelease() { |
| 380 | (void) deleteDecoder(); |
| 381 | if (mOutBufferFlush) { |
| 382 | ivd_aligned_free(nullptr, mOutBufferFlush); |
| 383 | mOutBufferFlush = nullptr; |
| 384 | } |
| 385 | if (mOutBlock) { |
| 386 | mOutBlock.reset(); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | c2_status_t C2SoftAvcDec::onFlush_sm() { |
| 391 | if (OK != setFlushMode()) return C2_CORRUPTED; |
| 392 | |
| 393 | uint32_t bufferSize = mStride * mHeight * 3 / 2; |
| 394 | mOutBufferFlush = (uint8_t *)ivd_aligned_malloc(nullptr, 128, bufferSize); |
| 395 | if (!mOutBufferFlush) { |
| 396 | ALOGE("could not allocate tmp output buffer (for flush) of size %u ", bufferSize); |
| 397 | return C2_NO_MEMORY; |
| 398 | } |
| 399 | |
| 400 | while (true) { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 401 | ih264d_video_decode_ip_t s_h264d_decode_ip = {}; |
| 402 | ih264d_video_decode_op_t s_h264d_decode_op = {}; |
| 403 | ivd_video_decode_ip_t *ps_decode_ip = &s_h264d_decode_ip.s_ivd_video_decode_ip_t; |
| 404 | ivd_video_decode_op_t *ps_decode_op = &s_h264d_decode_op.s_ivd_video_decode_op_t; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 405 | |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 406 | setDecodeArgs(ps_decode_ip, ps_decode_op, nullptr, nullptr, 0, 0, 0); |
| 407 | (void) ivdec_api_function(mDecHandle, &s_h264d_decode_ip, &s_h264d_decode_op); |
| 408 | if (0 == ps_decode_op->u4_output_present) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 409 | resetPlugin(); |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | if (mOutBufferFlush) { |
| 415 | ivd_aligned_free(nullptr, mOutBufferFlush); |
| 416 | mOutBufferFlush = nullptr; |
| 417 | } |
| 418 | |
| 419 | return C2_OK; |
| 420 | } |
| 421 | |
| 422 | status_t C2SoftAvcDec::createDecoder() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 423 | ivdext_create_ip_t s_create_ip = {}; |
| 424 | ivdext_create_op_t s_create_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 425 | |
| 426 | s_create_ip.s_ivd_create_ip_t.u4_size = sizeof(ivdext_create_ip_t); |
| 427 | s_create_ip.s_ivd_create_ip_t.e_cmd = IVD_CMD_CREATE; |
| 428 | s_create_ip.s_ivd_create_ip_t.u4_share_disp_buf = 0; |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 429 | s_create_ip.s_ivd_create_ip_t.e_output_format = GetIvColorFormat(); |
| 430 | switch (s_create_ip.s_ivd_create_ip_t.e_output_format) { |
| 431 | case IV_YUV_420P: ALOGD("Flex Planar"); break; |
| 432 | case IV_YUV_420SP_UV: ALOGD("Flex Semi-planar UV"); break; |
| 433 | case IV_YUV_420SP_VU: ALOGD("Flex Semi-planar VU"); break; |
| 434 | default: ALOGD("Unknown"); break; |
| 435 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 436 | s_create_ip.s_ivd_create_ip_t.pf_aligned_alloc = ivd_aligned_malloc; |
| 437 | s_create_ip.s_ivd_create_ip_t.pf_aligned_free = ivd_aligned_free; |
| 438 | s_create_ip.s_ivd_create_ip_t.pv_mem_ctxt = nullptr; |
| 439 | s_create_op.s_ivd_create_op_t.u4_size = sizeof(ivdext_create_op_t); |
| 440 | IV_API_CALL_STATUS_T status = ivdec_api_function(nullptr, |
| 441 | &s_create_ip, |
| 442 | &s_create_op); |
| 443 | if (status != IV_SUCCESS) { |
| 444 | ALOGE("error in %s: 0x%x", __func__, |
| 445 | s_create_op.s_ivd_create_op_t.u4_error_code); |
| 446 | return UNKNOWN_ERROR; |
| 447 | } |
| 448 | mDecHandle = (iv_obj_t*)s_create_op.s_ivd_create_op_t.pv_handle; |
| 449 | mDecHandle->pv_fxns = (void *)ivdec_api_function; |
| 450 | mDecHandle->u4_size = sizeof(iv_obj_t); |
| 451 | |
| 452 | return OK; |
| 453 | } |
| 454 | |
| 455 | status_t C2SoftAvcDec::setNumCores() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 456 | ivdext_ctl_set_num_cores_ip_t s_set_num_cores_ip = {}; |
| 457 | ivdext_ctl_set_num_cores_op_t s_set_num_cores_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 458 | |
| 459 | s_set_num_cores_ip.u4_size = sizeof(ivdext_ctl_set_num_cores_ip_t); |
| 460 | s_set_num_cores_ip.e_cmd = IVD_CMD_VIDEO_CTL; |
| 461 | s_set_num_cores_ip.e_sub_cmd = IVDEXT_CMD_CTL_SET_NUM_CORES; |
| 462 | s_set_num_cores_ip.u4_num_cores = mNumCores; |
| 463 | s_set_num_cores_op.u4_size = sizeof(ivdext_ctl_set_num_cores_op_t); |
| 464 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 465 | &s_set_num_cores_ip, |
| 466 | &s_set_num_cores_op); |
| 467 | if (IV_SUCCESS != status) { |
| 468 | ALOGD("error in %s: 0x%x", __func__, s_set_num_cores_op.u4_error_code); |
| 469 | return UNKNOWN_ERROR; |
| 470 | } |
| 471 | |
| 472 | return OK; |
| 473 | } |
| 474 | |
| 475 | status_t C2SoftAvcDec::setParams(size_t stride, IVD_VIDEO_DECODE_MODE_T dec_mode) { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 476 | ih264d_ctl_set_config_ip_t s_h264d_set_dyn_params_ip = {}; |
| 477 | ih264d_ctl_set_config_op_t s_h264d_set_dyn_params_op = {}; |
| 478 | ivd_ctl_set_config_ip_t *ps_set_dyn_params_ip = |
| 479 | &s_h264d_set_dyn_params_ip.s_ivd_ctl_set_config_ip_t; |
| 480 | ivd_ctl_set_config_op_t *ps_set_dyn_params_op = |
| 481 | &s_h264d_set_dyn_params_op.s_ivd_ctl_set_config_op_t; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 482 | |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 483 | ps_set_dyn_params_ip->u4_size = sizeof(ih264d_ctl_set_config_ip_t); |
| 484 | ps_set_dyn_params_ip->e_cmd = IVD_CMD_VIDEO_CTL; |
| 485 | ps_set_dyn_params_ip->e_sub_cmd = IVD_CMD_CTL_SETPARAMS; |
| 486 | ps_set_dyn_params_ip->u4_disp_wd = (UWORD32) stride; |
| 487 | ps_set_dyn_params_ip->e_frm_skip_mode = IVD_SKIP_NONE; |
| 488 | ps_set_dyn_params_ip->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT; |
| 489 | ps_set_dyn_params_ip->e_vid_dec_mode = dec_mode; |
| 490 | ps_set_dyn_params_op->u4_size = sizeof(ih264d_ctl_set_config_op_t); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 491 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 492 | &s_h264d_set_dyn_params_ip, |
| 493 | &s_h264d_set_dyn_params_op); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 494 | if (status != IV_SUCCESS) { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 495 | ALOGE("error in %s: 0x%x", __func__, ps_set_dyn_params_op->u4_error_code); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 496 | return UNKNOWN_ERROR; |
| 497 | } |
| 498 | |
| 499 | return OK; |
| 500 | } |
| 501 | |
| 502 | void C2SoftAvcDec::getVersion() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 503 | ivd_ctl_getversioninfo_ip_t s_get_versioninfo_ip = {}; |
| 504 | ivd_ctl_getversioninfo_op_t s_get_versioninfo_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 505 | UWORD8 au1_buf[512]; |
| 506 | |
| 507 | s_get_versioninfo_ip.u4_size = sizeof(ivd_ctl_getversioninfo_ip_t); |
| 508 | s_get_versioninfo_ip.e_cmd = IVD_CMD_VIDEO_CTL; |
| 509 | s_get_versioninfo_ip.e_sub_cmd = IVD_CMD_CTL_GETVERSION; |
| 510 | s_get_versioninfo_ip.pv_version_buffer = au1_buf; |
| 511 | s_get_versioninfo_ip.u4_version_buffer_size = sizeof(au1_buf); |
| 512 | s_get_versioninfo_op.u4_size = sizeof(ivd_ctl_getversioninfo_op_t); |
| 513 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 514 | &s_get_versioninfo_ip, |
| 515 | &s_get_versioninfo_op); |
| 516 | if (status != IV_SUCCESS) { |
| 517 | ALOGD("error in %s: 0x%x", __func__, |
| 518 | s_get_versioninfo_op.u4_error_code); |
| 519 | } else { |
| 520 | ALOGV("ittiam decoder version number: %s", |
| 521 | (char *) s_get_versioninfo_ip.pv_version_buffer); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | status_t C2SoftAvcDec::initDecoder() { |
| 526 | if (OK != createDecoder()) return UNKNOWN_ERROR; |
| 527 | mNumCores = MIN(getCpuCoreCount(), MAX_NUM_CORES); |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 528 | mStride = ALIGN32(mWidth); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 529 | mSignalledError = false; |
| 530 | resetPlugin(); |
| 531 | (void) setNumCores(); |
| 532 | if (OK != setParams(mStride, IVD_DECODE_FRAME)) return UNKNOWN_ERROR; |
| 533 | (void) getVersion(); |
| 534 | |
| 535 | return OK; |
| 536 | } |
| 537 | |
| 538 | bool C2SoftAvcDec::setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip, |
| 539 | ivd_video_decode_op_t *ps_decode_op, |
| 540 | C2ReadView *inBuffer, |
| 541 | C2GraphicView *outBuffer, |
| 542 | size_t inOffset, |
| 543 | size_t inSize, |
| 544 | uint32_t tsMarker) { |
| 545 | uint32_t displayStride = mStride; |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 546 | if (outBuffer) { |
| 547 | C2PlanarLayout layout; |
| 548 | layout = outBuffer->layout(); |
| 549 | displayStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc; |
| 550 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 551 | uint32_t displayHeight = mHeight; |
| 552 | size_t lumaSize = displayStride * displayHeight; |
| 553 | size_t chromaSize = lumaSize >> 2; |
| 554 | |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 555 | if (mStride != displayStride) { |
| 556 | mStride = displayStride; |
| 557 | if (OK != setParams(mStride, IVD_DECODE_FRAME)) return false; |
| 558 | } |
| 559 | |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 560 | ps_decode_ip->u4_size = sizeof(ih264d_video_decode_ip_t); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 561 | ps_decode_ip->e_cmd = IVD_CMD_VIDEO_DECODE; |
| 562 | if (inBuffer) { |
| 563 | ps_decode_ip->u4_ts = tsMarker; |
| 564 | ps_decode_ip->pv_stream_buffer = const_cast<uint8_t *>(inBuffer->data() + inOffset); |
| 565 | ps_decode_ip->u4_num_Bytes = inSize; |
| 566 | } else { |
| 567 | ps_decode_ip->u4_ts = 0; |
| 568 | ps_decode_ip->pv_stream_buffer = nullptr; |
| 569 | ps_decode_ip->u4_num_Bytes = 0; |
| 570 | } |
| 571 | ps_decode_ip->s_out_buffer.u4_min_out_buf_size[0] = lumaSize; |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 572 | if (GetIvColorFormat() == IV_YUV_420P) { |
| 573 | ps_decode_ip->s_out_buffer.u4_min_out_buf_size[1] = chromaSize; |
| 574 | ps_decode_ip->s_out_buffer.u4_min_out_buf_size[2] = chromaSize; |
| 575 | } else { |
| 576 | ps_decode_ip->s_out_buffer.u4_min_out_buf_size[1] = chromaSize * 2; |
| 577 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 578 | if (outBuffer) { |
Jason Macnak | 3a8a46c | 2020-04-30 17:41:53 -0700 | [diff] [blame] | 579 | if (outBuffer->height() < displayHeight) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 580 | ALOGE("Output buffer too small: provided (%dx%d) required (%ux%u)", |
| 581 | outBuffer->width(), outBuffer->height(), displayStride, displayHeight); |
| 582 | return false; |
| 583 | } |
| 584 | ps_decode_ip->s_out_buffer.pu1_bufs[0] = outBuffer->data()[C2PlanarLayout::PLANE_Y]; |
| 585 | ps_decode_ip->s_out_buffer.pu1_bufs[1] = outBuffer->data()[C2PlanarLayout::PLANE_U]; |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 586 | if (GetIvColorFormat() == IV_YUV_420P) { |
| 587 | ps_decode_ip->s_out_buffer.pu1_bufs[2] = outBuffer->data()[C2PlanarLayout::PLANE_V]; |
| 588 | } else if (GetIvColorFormat() == IV_YUV_420SP_VU) { |
| 589 | ps_decode_ip->s_out_buffer.pu1_bufs[1] = outBuffer->data()[C2PlanarLayout::PLANE_V]; |
| 590 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 591 | } else { |
| 592 | ps_decode_ip->s_out_buffer.pu1_bufs[0] = mOutBufferFlush; |
| 593 | ps_decode_ip->s_out_buffer.pu1_bufs[1] = mOutBufferFlush + lumaSize; |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 594 | if (GetIvColorFormat() == IV_YUV_420P) { |
| 595 | ps_decode_ip->s_out_buffer.pu1_bufs[2] = mOutBufferFlush + lumaSize + chromaSize; |
| 596 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 597 | } |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 598 | if (GetIvColorFormat() == IV_YUV_420P) { |
| 599 | ps_decode_ip->s_out_buffer.u4_num_bufs = 3; |
| 600 | } else { |
| 601 | ps_decode_ip->s_out_buffer.u4_num_bufs = 2; |
| 602 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 603 | ps_decode_op->u4_size = sizeof(ih264d_video_decode_op_t); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 604 | |
| 605 | return true; |
| 606 | } |
| 607 | |
| 608 | bool C2SoftAvcDec::getVuiParams() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 609 | ivdext_ctl_get_vui_params_ip_t s_get_vui_params_ip = {}; |
| 610 | ivdext_ctl_get_vui_params_op_t s_get_vui_params_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 611 | |
| 612 | s_get_vui_params_ip.u4_size = sizeof(ivdext_ctl_get_vui_params_ip_t); |
| 613 | s_get_vui_params_ip.e_cmd = IVD_CMD_VIDEO_CTL; |
| 614 | s_get_vui_params_ip.e_sub_cmd = |
| 615 | (IVD_CONTROL_API_COMMAND_TYPE_T) IH264D_CMD_CTL_GET_VUI_PARAMS; |
| 616 | s_get_vui_params_op.u4_size = sizeof(ivdext_ctl_get_vui_params_op_t); |
| 617 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 618 | &s_get_vui_params_ip, |
| 619 | &s_get_vui_params_op); |
| 620 | if (status != IV_SUCCESS) { |
| 621 | ALOGD("error in %s: 0x%x", __func__, s_get_vui_params_op.u4_error_code); |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | VuiColorAspects vuiColorAspects; |
| 626 | vuiColorAspects.primaries = s_get_vui_params_op.u1_colour_primaries; |
| 627 | vuiColorAspects.transfer = s_get_vui_params_op.u1_tfr_chars; |
| 628 | vuiColorAspects.coeffs = s_get_vui_params_op.u1_matrix_coeffs; |
| 629 | vuiColorAspects.fullRange = s_get_vui_params_op.u1_video_full_range_flag; |
| 630 | |
| 631 | // convert vui aspects to C2 values if changed |
| 632 | if (!(vuiColorAspects == mBitstreamColorAspects)) { |
| 633 | mBitstreamColorAspects = vuiColorAspects; |
| 634 | ColorAspects sfAspects; |
| 635 | C2StreamColorAspectsInfo::input codedAspects = { 0u }; |
| 636 | ColorUtils::convertIsoColorAspectsToCodecAspects( |
| 637 | vuiColorAspects.primaries, vuiColorAspects.transfer, vuiColorAspects.coeffs, |
| 638 | vuiColorAspects.fullRange, sfAspects); |
| 639 | if (!C2Mapper::map(sfAspects.mPrimaries, &codedAspects.primaries)) { |
| 640 | codedAspects.primaries = C2Color::PRIMARIES_UNSPECIFIED; |
| 641 | } |
| 642 | if (!C2Mapper::map(sfAspects.mRange, &codedAspects.range)) { |
| 643 | codedAspects.range = C2Color::RANGE_UNSPECIFIED; |
| 644 | } |
| 645 | if (!C2Mapper::map(sfAspects.mMatrixCoeffs, &codedAspects.matrix)) { |
| 646 | codedAspects.matrix = C2Color::MATRIX_UNSPECIFIED; |
| 647 | } |
| 648 | if (!C2Mapper::map(sfAspects.mTransfer, &codedAspects.transfer)) { |
| 649 | codedAspects.transfer = C2Color::TRANSFER_UNSPECIFIED; |
| 650 | } |
| 651 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 652 | (void)mIntf->config({&codedAspects}, C2_MAY_BLOCK, &failures); |
| 653 | } |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | status_t C2SoftAvcDec::setFlushMode() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 658 | ivd_ctl_flush_ip_t s_set_flush_ip = {}; |
| 659 | ivd_ctl_flush_op_t s_set_flush_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 660 | |
| 661 | s_set_flush_ip.u4_size = sizeof(ivd_ctl_flush_ip_t); |
| 662 | s_set_flush_ip.e_cmd = IVD_CMD_VIDEO_CTL; |
| 663 | s_set_flush_ip.e_sub_cmd = IVD_CMD_CTL_FLUSH; |
| 664 | s_set_flush_op.u4_size = sizeof(ivd_ctl_flush_op_t); |
| 665 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 666 | &s_set_flush_ip, |
| 667 | &s_set_flush_op); |
| 668 | if (status != IV_SUCCESS) { |
| 669 | ALOGE("error in %s: 0x%x", __func__, s_set_flush_op.u4_error_code); |
| 670 | return UNKNOWN_ERROR; |
| 671 | } |
| 672 | |
| 673 | return OK; |
| 674 | } |
| 675 | |
| 676 | status_t C2SoftAvcDec::resetDecoder() { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 677 | ivd_ctl_reset_ip_t s_reset_ip = {}; |
| 678 | ivd_ctl_reset_op_t s_reset_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 679 | |
| 680 | s_reset_ip.u4_size = sizeof(ivd_ctl_reset_ip_t); |
| 681 | s_reset_ip.e_cmd = IVD_CMD_VIDEO_CTL; |
| 682 | s_reset_ip.e_sub_cmd = IVD_CMD_CTL_RESET; |
| 683 | s_reset_op.u4_size = sizeof(ivd_ctl_reset_op_t); |
| 684 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 685 | &s_reset_ip, |
| 686 | &s_reset_op); |
| 687 | if (IV_SUCCESS != status) { |
| 688 | ALOGE("error in %s: 0x%x", __func__, s_reset_op.u4_error_code); |
| 689 | return UNKNOWN_ERROR; |
| 690 | } |
| 691 | mStride = 0; |
| 692 | (void) setNumCores(); |
| 693 | mSignalledError = false; |
| 694 | mHeaderDecoded = false; |
| 695 | |
| 696 | return OK; |
| 697 | } |
| 698 | |
| 699 | void C2SoftAvcDec::resetPlugin() { |
| 700 | mSignalledOutputEos = false; |
| 701 | gettimeofday(&mTimeStart, nullptr); |
| 702 | gettimeofday(&mTimeEnd, nullptr); |
| 703 | } |
| 704 | |
| 705 | status_t C2SoftAvcDec::deleteDecoder() { |
| 706 | if (mDecHandle) { |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 707 | ivdext_delete_ip_t s_delete_ip = {}; |
| 708 | ivdext_delete_op_t s_delete_op = {}; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 709 | |
| 710 | s_delete_ip.s_ivd_delete_ip_t.u4_size = sizeof(ivdext_delete_ip_t); |
| 711 | s_delete_ip.s_ivd_delete_ip_t.e_cmd = IVD_CMD_DELETE; |
| 712 | s_delete_op.s_ivd_delete_op_t.u4_size = sizeof(ivdext_delete_op_t); |
| 713 | IV_API_CALL_STATUS_T status = ivdec_api_function(mDecHandle, |
| 714 | &s_delete_ip, |
| 715 | &s_delete_op); |
| 716 | if (status != IV_SUCCESS) { |
| 717 | ALOGE("error in %s: 0x%x", __func__, |
| 718 | s_delete_op.s_ivd_delete_op_t.u4_error_code); |
| 719 | return UNKNOWN_ERROR; |
| 720 | } |
| 721 | mDecHandle = nullptr; |
| 722 | } |
| 723 | |
| 724 | return OK; |
| 725 | } |
| 726 | |
| 727 | static void fillEmptyWork(const std::unique_ptr<C2Work> &work) { |
| 728 | uint32_t flags = 0; |
| 729 | if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) { |
| 730 | flags |= C2FrameData::FLAG_END_OF_STREAM; |
| 731 | ALOGV("signalling eos"); |
| 732 | } |
| 733 | work->worklets.front()->output.flags = (C2FrameData::flags_t)flags; |
| 734 | work->worklets.front()->output.buffers.clear(); |
| 735 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 736 | work->workletsProcessed = 1u; |
| 737 | } |
| 738 | |
| 739 | void C2SoftAvcDec::finishWork(uint64_t index, const std::unique_ptr<C2Work> &work) { |
| 740 | std::shared_ptr<C2Buffer> buffer = createGraphicBuffer(std::move(mOutBlock), |
| 741 | C2Rect(mWidth, mHeight)); |
| 742 | mOutBlock = nullptr; |
| 743 | { |
| 744 | IntfImpl::Lock lock = mIntf->lock(); |
| 745 | buffer->setInfo(mIntf->getColorAspects_l()); |
| 746 | } |
| 747 | |
Rakesh Kumar | 4ec85ae | 2019-02-13 00:50:07 +0530 | [diff] [blame] | 748 | class FillWork { |
| 749 | public: |
| 750 | FillWork(uint32_t flags, C2WorkOrdinalStruct ordinal, |
| 751 | const std::shared_ptr<C2Buffer>& buffer) |
| 752 | : mFlags(flags), mOrdinal(ordinal), mBuffer(buffer) {} |
| 753 | ~FillWork() = default; |
| 754 | |
| 755 | void operator()(const std::unique_ptr<C2Work>& work) { |
| 756 | work->worklets.front()->output.flags = (C2FrameData::flags_t)mFlags; |
| 757 | work->worklets.front()->output.buffers.clear(); |
| 758 | work->worklets.front()->output.ordinal = mOrdinal; |
| 759 | work->workletsProcessed = 1u; |
| 760 | work->result = C2_OK; |
| 761 | if (mBuffer) { |
| 762 | work->worklets.front()->output.buffers.push_back(mBuffer); |
| 763 | } |
| 764 | ALOGV("timestamp = %lld, index = %lld, w/%s buffer", |
| 765 | mOrdinal.timestamp.peekll(), mOrdinal.frameIndex.peekll(), |
| 766 | mBuffer ? "" : "o"); |
| 767 | } |
| 768 | |
| 769 | private: |
| 770 | const uint32_t mFlags; |
| 771 | const C2WorkOrdinalStruct mOrdinal; |
| 772 | const std::shared_ptr<C2Buffer> mBuffer; |
| 773 | }; |
| 774 | |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 775 | auto fillWork = [buffer](const std::unique_ptr<C2Work> &work) { |
| 776 | work->worklets.front()->output.flags = (C2FrameData::flags_t)0; |
| 777 | work->worklets.front()->output.buffers.clear(); |
| 778 | work->worklets.front()->output.buffers.push_back(buffer); |
| 779 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 780 | work->workletsProcessed = 1u; |
| 781 | }; |
| 782 | if (work && c2_cntr64_t(index) == work->input.ordinal.frameIndex) { |
Rakesh Kumar | 4ec85ae | 2019-02-13 00:50:07 +0530 | [diff] [blame] | 783 | bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0); |
| 784 | // TODO: Check if cloneAndSend can be avoided by tracking number of frames remaining |
| 785 | if (eos) { |
| 786 | if (buffer) { |
| 787 | mOutIndex = index; |
| 788 | C2WorkOrdinalStruct outOrdinal = work->input.ordinal; |
| 789 | cloneAndSend( |
| 790 | mOutIndex, work, |
| 791 | FillWork(C2FrameData::FLAG_INCOMPLETE, outOrdinal, buffer)); |
| 792 | buffer.reset(); |
| 793 | } |
| 794 | } else { |
| 795 | fillWork(work); |
| 796 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 797 | } else { |
| 798 | finish(index, fillWork); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | c2_status_t C2SoftAvcDec::ensureDecoderState(const std::shared_ptr<C2BlockPool> &pool) { |
| 803 | if (!mDecHandle) { |
| 804 | ALOGE("not supposed to be here, invalid decoder context"); |
| 805 | return C2_CORRUPTED; |
| 806 | } |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 807 | if (mOutBlock && |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 808 | (mOutBlock->width() != ALIGN32(mWidth) || mOutBlock->height() != mHeight)) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 809 | mOutBlock.reset(); |
| 810 | } |
| 811 | if (!mOutBlock) { |
Wonsik Kim | 8f183eb | 2021-04-05 14:51:39 -0700 | [diff] [blame^] | 812 | uint32_t format = HAL_PIXEL_FORMAT_YCBCR_420_888; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 813 | C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 814 | c2_status_t err = |
| 815 | pool->fetchGraphicBlock(ALIGN32(mWidth), mHeight, format, usage, &mOutBlock); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 816 | if (err != C2_OK) { |
| 817 | ALOGE("fetchGraphicBlock for Output failed with status %d", err); |
| 818 | return err; |
| 819 | } |
| 820 | ALOGV("provided (%dx%d) required (%dx%d)", |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 821 | mOutBlock->width(), mOutBlock->height(), ALIGN32(mWidth), mHeight); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | return C2_OK; |
| 825 | } |
| 826 | |
| 827 | // TODO: can overall error checking be improved? |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 828 | // TODO: pass coloraspects information to surface |
| 829 | // TODO: test support for dynamic change in resolution |
| 830 | // TODO: verify if the decoder sent back all frames |
| 831 | void C2SoftAvcDec::process( |
| 832 | const std::unique_ptr<C2Work> &work, |
| 833 | const std::shared_ptr<C2BlockPool> &pool) { |
| 834 | // Initialize output work |
| 835 | work->result = C2_OK; |
| 836 | work->workletsProcessed = 0u; |
| 837 | work->worklets.front()->output.flags = work->input.flags; |
| 838 | if (mSignalledError || mSignalledOutputEos) { |
| 839 | work->result = C2_BAD_VALUE; |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | size_t inOffset = 0u; |
| 844 | size_t inSize = 0u; |
| 845 | uint32_t workIndex = work->input.ordinal.frameIndex.peeku() & 0xFFFFFFFF; |
| 846 | C2ReadView rView = mDummyReadView; |
| 847 | if (!work->input.buffers.empty()) { |
| 848 | rView = work->input.buffers[0]->data().linearBlocks().front().map().get(); |
| 849 | inSize = rView.capacity(); |
| 850 | if (inSize && rView.error()) { |
| 851 | ALOGE("read view map failed %d", rView.error()); |
| 852 | work->result = rView.error(); |
| 853 | return; |
| 854 | } |
| 855 | } |
| 856 | bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0); |
| 857 | bool hasPicture = false; |
| 858 | |
| 859 | ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x", |
| 860 | inSize, (int)work->input.ordinal.timestamp.peeku(), |
| 861 | (int)work->input.ordinal.frameIndex.peeku(), work->input.flags); |
| 862 | size_t inPos = 0; |
Harish Mahendrakar | a17cf65 | 2020-04-02 05:45:05 +0530 | [diff] [blame] | 863 | while (inPos < inSize && inSize - inPos >= kMinInputBytes) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 864 | if (C2_OK != ensureDecoderState(pool)) { |
| 865 | mSignalledError = true; |
| 866 | work->workletsProcessed = 1u; |
| 867 | work->result = C2_CORRUPTED; |
| 868 | return; |
| 869 | } |
| 870 | |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 871 | ih264d_video_decode_ip_t s_h264d_decode_ip = {}; |
| 872 | ih264d_video_decode_op_t s_h264d_decode_op = {}; |
| 873 | ivd_video_decode_ip_t *ps_decode_ip = &s_h264d_decode_ip.s_ivd_video_decode_ip_t; |
| 874 | ivd_video_decode_op_t *ps_decode_op = &s_h264d_decode_op.s_ivd_video_decode_op_t; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 875 | { |
| 876 | C2GraphicView wView = mOutBlock->map().get(); |
| 877 | if (wView.error()) { |
| 878 | ALOGE("graphic view map failed %d", wView.error()); |
| 879 | work->result = wView.error(); |
| 880 | return; |
| 881 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 882 | if (!setDecodeArgs(ps_decode_ip, ps_decode_op, &rView, &wView, |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 883 | inOffset + inPos, inSize - inPos, workIndex)) { |
| 884 | mSignalledError = true; |
| 885 | work->workletsProcessed = 1u; |
| 886 | work->result = C2_CORRUPTED; |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | if (false == mHeaderDecoded) { |
| 891 | /* Decode header and get dimensions */ |
| 892 | setParams(mStride, IVD_DECODE_HEADER); |
| 893 | } |
| 894 | |
| 895 | WORD32 delay; |
| 896 | GETTIME(&mTimeStart, nullptr); |
| 897 | TIME_DIFF(mTimeEnd, mTimeStart, delay); |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 898 | (void) ivdec_api_function(mDecHandle, &s_h264d_decode_ip, &s_h264d_decode_op); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 899 | WORD32 decodeTime; |
| 900 | GETTIME(&mTimeEnd, nullptr); |
| 901 | TIME_DIFF(mTimeStart, mTimeEnd, decodeTime); |
| 902 | ALOGV("decodeTime=%6d delay=%6d numBytes=%6d", decodeTime, delay, |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 903 | ps_decode_op->u4_num_bytes_consumed); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 904 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 905 | if (IVD_MEM_ALLOC_FAILED == (ps_decode_op->u4_error_code & IVD_ERROR_MASK)) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 906 | ALOGE("allocation failure in decoder"); |
| 907 | mSignalledError = true; |
| 908 | work->workletsProcessed = 1u; |
| 909 | work->result = C2_CORRUPTED; |
| 910 | return; |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 911 | } else if (IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED == |
| 912 | (ps_decode_op->u4_error_code & IVD_ERROR_MASK)) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 913 | ALOGE("unsupported resolution : %dx%d", mWidth, mHeight); |
| 914 | mSignalledError = true; |
| 915 | work->workletsProcessed = 1u; |
| 916 | work->result = C2_CORRUPTED; |
| 917 | return; |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 918 | } else if (IVD_RES_CHANGED == (ps_decode_op->u4_error_code & IVD_ERROR_MASK)) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 919 | ALOGV("resolution changed"); |
| 920 | drainInternal(DRAIN_COMPONENT_NO_EOS, pool, work); |
| 921 | resetDecoder(); |
| 922 | resetPlugin(); |
| 923 | work->workletsProcessed = 0u; |
| 924 | |
| 925 | /* Decode header and get new dimensions */ |
| 926 | setParams(mStride, IVD_DECODE_HEADER); |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 927 | (void) ivdec_api_function(mDecHandle, ps_decode_ip, ps_decode_op); |
| 928 | } else if (IS_IVD_FATAL_ERROR(ps_decode_op->u4_error_code)) { |
| 929 | ALOGE("Fatal error in decoder 0x%x", ps_decode_op->u4_error_code); |
Harish Mahendrakar | 8f98eee | 2019-04-16 11:34:33 -0700 | [diff] [blame] | 930 | mSignalledError = true; |
| 931 | work->workletsProcessed = 1u; |
| 932 | work->result = C2_CORRUPTED; |
| 933 | return; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 934 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 935 | if (ps_decode_op->i4_reorder_depth >= 0 && mOutputDelay != ps_decode_op->i4_reorder_depth) { |
| 936 | mOutputDelay = ps_decode_op->i4_reorder_depth; |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 937 | ALOGV("New Output delay %d ", mOutputDelay); |
| 938 | |
| 939 | C2PortActualDelayTuning::output outputDelay(mOutputDelay); |
| 940 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 941 | c2_status_t err = |
| 942 | mIntf->config({&outputDelay}, C2_MAY_BLOCK, &failures); |
| 943 | if (err == OK) { |
| 944 | work->worklets.front()->output.configUpdate.push_back( |
| 945 | C2Param::Copy(outputDelay)); |
| 946 | } else { |
| 947 | ALOGE("Cannot set output delay"); |
| 948 | mSignalledError = true; |
| 949 | work->workletsProcessed = 1u; |
| 950 | work->result = C2_CORRUPTED; |
| 951 | return; |
| 952 | } |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 953 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 954 | if (0 < ps_decode_op->u4_pic_wd && 0 < ps_decode_op->u4_pic_ht) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 955 | if (mHeaderDecoded == false) { |
| 956 | mHeaderDecoded = true; |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 957 | mStride = ALIGN32(ps_decode_op->u4_pic_wd); |
Harish Mahendrakar | dc1d2d9 | 2019-10-18 16:27:38 -0700 | [diff] [blame] | 958 | setParams(mStride, IVD_DECODE_FRAME); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 959 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 960 | if (ps_decode_op->u4_pic_wd != mWidth || ps_decode_op->u4_pic_ht != mHeight) { |
| 961 | mWidth = ps_decode_op->u4_pic_wd; |
| 962 | mHeight = ps_decode_op->u4_pic_ht; |
| 963 | CHECK_EQ(0u, ps_decode_op->u4_output_present); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 964 | |
Lajos Molnar | 3bb81cd | 2019-02-20 15:10:30 -0800 | [diff] [blame] | 965 | C2StreamPictureSizeInfo::output size(0u, mWidth, mHeight); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 966 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 967 | c2_status_t err = mIntf->config({&size}, C2_MAY_BLOCK, &failures); |
| 968 | if (err == OK) { |
| 969 | work->worklets.front()->output.configUpdate.push_back( |
| 970 | C2Param::Copy(size)); |
| 971 | } else { |
| 972 | ALOGE("Cannot set width and height"); |
| 973 | mSignalledError = true; |
| 974 | work->workletsProcessed = 1u; |
| 975 | work->result = C2_CORRUPTED; |
| 976 | return; |
| 977 | } |
| 978 | continue; |
| 979 | } |
| 980 | } |
| 981 | (void)getVuiParams(); |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 982 | hasPicture |= (1 == ps_decode_op->u4_frame_decoded_flag); |
| 983 | if (ps_decode_op->u4_output_present) { |
| 984 | finishWork(ps_decode_op->u4_ts, work); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 985 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 986 | inPos += ps_decode_op->u4_num_bytes_consumed; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 987 | } |
| 988 | if (eos) { |
| 989 | drainInternal(DRAIN_COMPONENT_WITH_EOS, pool, work); |
| 990 | mSignalledOutputEos = true; |
| 991 | } else if (!hasPicture) { |
| 992 | fillEmptyWork(work); |
| 993 | } |
Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 994 | |
| 995 | work->input.buffers.clear(); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | c2_status_t C2SoftAvcDec::drainInternal( |
| 999 | uint32_t drainMode, |
| 1000 | const std::shared_ptr<C2BlockPool> &pool, |
| 1001 | const std::unique_ptr<C2Work> &work) { |
| 1002 | if (drainMode == NO_DRAIN) { |
| 1003 | ALOGW("drain with NO_DRAIN: no-op"); |
| 1004 | return C2_OK; |
| 1005 | } |
| 1006 | if (drainMode == DRAIN_CHAIN) { |
| 1007 | ALOGW("DRAIN_CHAIN not supported"); |
| 1008 | return C2_OMITTED; |
| 1009 | } |
| 1010 | |
| 1011 | if (OK != setFlushMode()) return C2_CORRUPTED; |
| 1012 | while (true) { |
| 1013 | if (C2_OK != ensureDecoderState(pool)) { |
| 1014 | mSignalledError = true; |
| 1015 | work->workletsProcessed = 1u; |
| 1016 | work->result = C2_CORRUPTED; |
| 1017 | return C2_CORRUPTED; |
| 1018 | } |
| 1019 | C2GraphicView wView = mOutBlock->map().get(); |
| 1020 | if (wView.error()) { |
| 1021 | ALOGE("graphic view map failed %d", wView.error()); |
| 1022 | return C2_CORRUPTED; |
| 1023 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 1024 | ih264d_video_decode_ip_t s_h264d_decode_ip = {}; |
| 1025 | ih264d_video_decode_op_t s_h264d_decode_op = {}; |
| 1026 | ivd_video_decode_ip_t *ps_decode_ip = &s_h264d_decode_ip.s_ivd_video_decode_ip_t; |
| 1027 | ivd_video_decode_op_t *ps_decode_op = &s_h264d_decode_op.s_ivd_video_decode_op_t; |
| 1028 | if (!setDecodeArgs(ps_decode_ip, ps_decode_op, nullptr, &wView, 0, 0, 0)) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1029 | mSignalledError = true; |
| 1030 | work->workletsProcessed = 1u; |
| 1031 | return C2_CORRUPTED; |
| 1032 | } |
Shivaansh Agrawal | 193b612 | 2020-12-20 14:31:04 +0530 | [diff] [blame] | 1033 | (void) ivdec_api_function(mDecHandle, &s_h264d_decode_ip, &s_h264d_decode_op); |
| 1034 | if (ps_decode_op->u4_output_present) { |
| 1035 | finishWork(ps_decode_op->u4_ts, work); |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1036 | } else { |
| 1037 | fillEmptyWork(work); |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | return C2_OK; |
| 1043 | } |
| 1044 | |
| 1045 | c2_status_t C2SoftAvcDec::drain( |
| 1046 | uint32_t drainMode, |
| 1047 | const std::shared_ptr<C2BlockPool> &pool) { |
| 1048 | return drainInternal(drainMode, pool, nullptr); |
| 1049 | } |
| 1050 | |
| 1051 | class C2SoftAvcDecFactory : public C2ComponentFactory { |
| 1052 | public: |
| 1053 | C2SoftAvcDecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>( |
| 1054 | GetCodec2PlatformComponentStore()->getParamReflector())) { |
| 1055 | } |
| 1056 | |
| 1057 | virtual c2_status_t createComponent( |
| 1058 | c2_node_id_t id, |
| 1059 | std::shared_ptr<C2Component>* const component, |
| 1060 | std::function<void(C2Component*)> deleter) override { |
| 1061 | *component = std::shared_ptr<C2Component>( |
| 1062 | new C2SoftAvcDec(COMPONENT_NAME, |
| 1063 | id, |
| 1064 | std::make_shared<C2SoftAvcDec::IntfImpl>(mHelper)), |
| 1065 | deleter); |
| 1066 | return C2_OK; |
| 1067 | } |
| 1068 | |
| 1069 | virtual c2_status_t createInterface( |
| 1070 | c2_node_id_t id, |
| 1071 | std::shared_ptr<C2ComponentInterface>* const interface, |
| 1072 | std::function<void(C2ComponentInterface*)> deleter) override { |
| 1073 | *interface = std::shared_ptr<C2ComponentInterface>( |
| 1074 | new SimpleInterface<C2SoftAvcDec::IntfImpl>( |
| 1075 | COMPONENT_NAME, id, std::make_shared<C2SoftAvcDec::IntfImpl>(mHelper)), |
| 1076 | deleter); |
| 1077 | return C2_OK; |
| 1078 | } |
| 1079 | |
| 1080 | virtual ~C2SoftAvcDecFactory() override = default; |
| 1081 | |
| 1082 | private: |
| 1083 | std::shared_ptr<C2ReflectorHelper> mHelper; |
| 1084 | }; |
| 1085 | |
| 1086 | } // namespace android |
| 1087 | |
Cindy Zhou | f6c0c3c | 2020-12-02 10:53:40 -0800 | [diff] [blame] | 1088 | __attribute__((cfi_canonical_jump_table)) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1089 | extern "C" ::C2ComponentFactory* CreateCodec2Factory() { |
| 1090 | ALOGV("in %s", __func__); |
| 1091 | return new ::android::C2SoftAvcDecFactory(); |
| 1092 | } |
| 1093 | |
Cindy Zhou | f6c0c3c | 2020-12-02 10:53:40 -0800 | [diff] [blame] | 1094 | __attribute__((cfi_canonical_jump_table)) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1095 | extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) { |
| 1096 | ALOGV("in %s", __func__); |
| 1097 | delete factory; |
| 1098 | } |