Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "C2SoftGav1Dec" |
| 19 | #include "C2SoftGav1Dec.h" |
| 20 | |
| 21 | #include <C2Debug.h> |
| 22 | #include <C2PlatformSupport.h> |
Harish Mahendrakar | f0fa7a2 | 2021-12-10 20:36:32 -0800 | [diff] [blame] | 23 | #include <Codec2BufferUtils.h> |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 24 | #include <Codec2Mapper.h> |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 25 | #include <SimpleC2Interface.h> |
| 26 | #include <log/log.h> |
| 27 | #include <media/stagefright/foundation/AUtils.h> |
| 28 | #include <media/stagefright/foundation/MediaDefs.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Ray Essick | c2cc437 | 2019-08-21 14:02:28 -0700 | [diff] [blame] | 32 | // codecname set and passed in as a compile flag from Android.bp |
| 33 | constexpr char COMPONENT_NAME[] = CODECNAME; |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 34 | |
| 35 | class C2SoftGav1Dec::IntfImpl : public SimpleInterface<void>::BaseParams { |
| 36 | public: |
| 37 | explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper) |
| 38 | : SimpleInterface<void>::BaseParams( |
| 39 | helper, COMPONENT_NAME, C2Component::KIND_DECODER, |
| 40 | C2Component::DOMAIN_VIDEO, MEDIA_MIMETYPE_VIDEO_AV1) { |
| 41 | noPrivateBuffers(); // TODO: account for our buffers here. |
| 42 | noInputReferences(); |
| 43 | noOutputReferences(); |
| 44 | noInputLatency(); |
| 45 | noTimeStretch(); |
| 46 | |
| 47 | addParameter(DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES) |
| 48 | .withConstValue(new C2ComponentAttributesSetting( |
| 49 | C2Component::ATTRIB_IS_TEMPORAL)) |
| 50 | .build()); |
| 51 | |
| 52 | addParameter( |
| 53 | DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE) |
| 54 | .withDefault(new C2StreamPictureSizeInfo::output(0u, 320, 240)) |
| 55 | .withFields({ |
Vignesh Venkatasubramanian | 2d8d470 | 2021-01-25 09:42:44 -0800 | [diff] [blame] | 56 | C2F(mSize, width).inRange(2, 4096, 2), |
| 57 | C2F(mSize, height).inRange(2, 4096, 2), |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 58 | }) |
| 59 | .withSetter(SizeSetter) |
| 60 | .build()); |
| 61 | |
| 62 | addParameter(DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL) |
| 63 | .withDefault(new C2StreamProfileLevelInfo::input( |
| 64 | 0u, C2Config::PROFILE_AV1_0, C2Config::LEVEL_AV1_2_1)) |
| 65 | .withFields({C2F(mProfileLevel, profile) |
| 66 | .oneOf({C2Config::PROFILE_AV1_0, |
| 67 | C2Config::PROFILE_AV1_1}), |
| 68 | C2F(mProfileLevel, level) |
| 69 | .oneOf({ |
Harish Mahendrakar | 1ad8c3b | 2021-06-04 15:42:31 -0700 | [diff] [blame] | 70 | C2Config::LEVEL_AV1_2, C2Config::LEVEL_AV1_2_1, |
| 71 | C2Config::LEVEL_AV1_2_2, C2Config::LEVEL_AV1_2_3, |
| 72 | C2Config::LEVEL_AV1_3, C2Config::LEVEL_AV1_3_1, |
| 73 | C2Config::LEVEL_AV1_3_2, C2Config::LEVEL_AV1_3_3, |
| 74 | C2Config::LEVEL_AV1_4, C2Config::LEVEL_AV1_4_1, |
| 75 | C2Config::LEVEL_AV1_4_2, C2Config::LEVEL_AV1_4_3, |
| 76 | C2Config::LEVEL_AV1_5, C2Config::LEVEL_AV1_5_1, |
| 77 | C2Config::LEVEL_AV1_5_2, C2Config::LEVEL_AV1_5_3, |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 78 | })}) |
| 79 | .withSetter(ProfileLevelSetter, mSize) |
| 80 | .build()); |
| 81 | |
| 82 | mHdr10PlusInfoInput = C2StreamHdr10PlusInfo::input::AllocShared(0); |
| 83 | addParameter( |
| 84 | DefineParam(mHdr10PlusInfoInput, C2_PARAMKEY_INPUT_HDR10_PLUS_INFO) |
| 85 | .withDefault(mHdr10PlusInfoInput) |
| 86 | .withFields({ |
| 87 | C2F(mHdr10PlusInfoInput, m.value).any(), |
| 88 | }) |
| 89 | .withSetter(Hdr10PlusInfoInputSetter) |
| 90 | .build()); |
| 91 | |
| 92 | mHdr10PlusInfoOutput = C2StreamHdr10PlusInfo::output::AllocShared(0); |
| 93 | addParameter( |
| 94 | DefineParam(mHdr10PlusInfoOutput, C2_PARAMKEY_OUTPUT_HDR10_PLUS_INFO) |
| 95 | .withDefault(mHdr10PlusInfoOutput) |
| 96 | .withFields({ |
| 97 | C2F(mHdr10PlusInfoOutput, m.value).any(), |
| 98 | }) |
| 99 | .withSetter(Hdr10PlusInfoOutputSetter) |
| 100 | .build()); |
| 101 | |
| 102 | addParameter( |
| 103 | DefineParam(mMaxSize, C2_PARAMKEY_MAX_PICTURE_SIZE) |
| 104 | .withDefault(new C2StreamMaxPictureSizeTuning::output(0u, 320, 240)) |
| 105 | .withFields({ |
| 106 | C2F(mSize, width).inRange(2, 2048, 2), |
| 107 | C2F(mSize, height).inRange(2, 2048, 2), |
| 108 | }) |
| 109 | .withSetter(MaxPictureSizeSetter, mSize) |
| 110 | .build()); |
| 111 | |
| 112 | addParameter(DefineParam(mMaxInputSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE) |
| 113 | .withDefault(new C2StreamMaxBufferSizeInfo::input( |
| 114 | 0u, 320 * 240 * 3 / 4)) |
| 115 | .withFields({ |
| 116 | C2F(mMaxInputSize, value).any(), |
| 117 | }) |
| 118 | .calculatedAs(MaxInputSizeSetter, mMaxSize) |
| 119 | .build()); |
| 120 | |
| 121 | C2ChromaOffsetStruct locations[1] = {C2ChromaOffsetStruct::ITU_YUV_420_0()}; |
| 122 | std::shared_ptr<C2StreamColorInfo::output> defaultColorInfo = |
| 123 | C2StreamColorInfo::output::AllocShared(1u, 0u, 8u /* bitDepth */, |
| 124 | C2Color::YUV_420); |
| 125 | memcpy(defaultColorInfo->m.locations, locations, sizeof(locations)); |
| 126 | |
| 127 | defaultColorInfo = C2StreamColorInfo::output::AllocShared( |
| 128 | {C2ChromaOffsetStruct::ITU_YUV_420_0()}, 0u, 8u /* bitDepth */, |
| 129 | C2Color::YUV_420); |
| 130 | helper->addStructDescriptors<C2ChromaOffsetStruct>(); |
| 131 | |
| 132 | addParameter(DefineParam(mColorInfo, C2_PARAMKEY_CODED_COLOR_INFO) |
| 133 | .withConstValue(defaultColorInfo) |
| 134 | .build()); |
| 135 | |
| 136 | addParameter( |
| 137 | DefineParam(mDefaultColorAspects, C2_PARAMKEY_DEFAULT_COLOR_ASPECTS) |
| 138 | .withDefault(new C2StreamColorAspectsTuning::output( |
| 139 | 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED, |
| 140 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 141 | .withFields( |
| 142 | {C2F(mDefaultColorAspects, range) |
| 143 | .inRange(C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 144 | C2F(mDefaultColorAspects, primaries) |
| 145 | .inRange(C2Color::PRIMARIES_UNSPECIFIED, |
| 146 | C2Color::PRIMARIES_OTHER), |
| 147 | C2F(mDefaultColorAspects, transfer) |
| 148 | .inRange(C2Color::TRANSFER_UNSPECIFIED, |
| 149 | C2Color::TRANSFER_OTHER), |
| 150 | C2F(mDefaultColorAspects, matrix) |
| 151 | .inRange(C2Color::MATRIX_UNSPECIFIED, |
| 152 | C2Color::MATRIX_OTHER)}) |
| 153 | .withSetter(DefaultColorAspectsSetter) |
| 154 | .build()); |
| 155 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 156 | addParameter( |
| 157 | DefineParam(mCodedColorAspects, C2_PARAMKEY_VUI_COLOR_ASPECTS) |
| 158 | .withDefault(new C2StreamColorAspectsInfo::input( |
| 159 | 0u, C2Color::RANGE_LIMITED, C2Color::PRIMARIES_UNSPECIFIED, |
| 160 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 161 | .withFields({ |
| 162 | C2F(mCodedColorAspects, range).inRange( |
| 163 | C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 164 | C2F(mCodedColorAspects, primaries).inRange( |
| 165 | C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER), |
| 166 | C2F(mCodedColorAspects, transfer).inRange( |
| 167 | C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER), |
| 168 | C2F(mCodedColorAspects, matrix).inRange( |
| 169 | C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER) |
| 170 | }) |
| 171 | .withSetter(CodedColorAspectsSetter) |
| 172 | .build()); |
| 173 | |
| 174 | addParameter( |
| 175 | DefineParam(mColorAspects, C2_PARAMKEY_COLOR_ASPECTS) |
| 176 | .withDefault(new C2StreamColorAspectsInfo::output( |
| 177 | 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED, |
| 178 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 179 | .withFields({ |
| 180 | C2F(mColorAspects, range).inRange( |
| 181 | C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 182 | C2F(mColorAspects, primaries).inRange( |
| 183 | C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER), |
| 184 | C2F(mColorAspects, transfer).inRange( |
| 185 | C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER), |
| 186 | C2F(mColorAspects, matrix).inRange( |
| 187 | C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER) |
| 188 | }) |
| 189 | .withSetter(ColorAspectsSetter, mDefaultColorAspects, mCodedColorAspects) |
| 190 | .build()); |
| 191 | |
Harish Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 192 | std::vector<uint32_t> pixelFormats = {HAL_PIXEL_FORMAT_YCBCR_420_888}; |
| 193 | if (isAtLeastT()) { |
| 194 | pixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010); |
| 195 | } |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 196 | // TODO: support more formats? |
Harish Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 197 | addParameter( |
| 198 | DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT) |
| 199 | .withDefault(new C2StreamPixelFormatInfo::output( |
| 200 | 0u, HAL_PIXEL_FORMAT_YCBCR_420_888)) |
| 201 | .withFields({C2F(mPixelFormat, value).oneOf(pixelFormats)}) |
| 202 | .withSetter((Setter<decltype(*mPixelFormat)>::StrictValueWithNoDeps)) |
| 203 | .build()); |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static C2R SizeSetter(bool mayBlock, |
| 207 | const C2P<C2StreamPictureSizeInfo::output> &oldMe, |
| 208 | C2P<C2StreamPictureSizeInfo::output> &me) { |
| 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( |
| 223 | bool mayBlock, C2P<C2StreamMaxPictureSizeTuning::output> &me, |
| 224 | const C2P<C2StreamPictureSizeInfo::output> &size) { |
| 225 | (void)mayBlock; |
| 226 | // TODO: get max width/height from the size's field helpers vs. |
| 227 | // hardcoding |
| 228 | me.set().width = c2_min(c2_max(me.v.width, size.v.width), 4096u); |
| 229 | me.set().height = c2_min(c2_max(me.v.height, size.v.height), 4096u); |
| 230 | return C2R::Ok(); |
| 231 | } |
| 232 | |
| 233 | static C2R MaxInputSizeSetter( |
| 234 | bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input> &me, |
| 235 | const C2P<C2StreamMaxPictureSizeTuning::output> &maxSize) { |
| 236 | (void)mayBlock; |
| 237 | // assume compression ratio of 2 |
| 238 | me.set().value = |
| 239 | (((maxSize.v.width + 63) / 64) * ((maxSize.v.height + 63) / 64) * 3072); |
| 240 | return C2R::Ok(); |
| 241 | } |
| 242 | |
| 243 | static C2R DefaultColorAspectsSetter( |
| 244 | bool mayBlock, C2P<C2StreamColorAspectsTuning::output> &me) { |
| 245 | (void)mayBlock; |
| 246 | if (me.v.range > C2Color::RANGE_OTHER) { |
| 247 | me.set().range = C2Color::RANGE_OTHER; |
| 248 | } |
| 249 | if (me.v.primaries > C2Color::PRIMARIES_OTHER) { |
| 250 | me.set().primaries = C2Color::PRIMARIES_OTHER; |
| 251 | } |
| 252 | if (me.v.transfer > C2Color::TRANSFER_OTHER) { |
| 253 | me.set().transfer = C2Color::TRANSFER_OTHER; |
| 254 | } |
| 255 | if (me.v.matrix > C2Color::MATRIX_OTHER) { |
| 256 | me.set().matrix = C2Color::MATRIX_OTHER; |
| 257 | } |
| 258 | return C2R::Ok(); |
| 259 | } |
| 260 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 261 | static C2R CodedColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::input> &me) { |
| 262 | (void)mayBlock; |
| 263 | if (me.v.range > C2Color::RANGE_OTHER) { |
| 264 | me.set().range = C2Color::RANGE_OTHER; |
| 265 | } |
| 266 | if (me.v.primaries > C2Color::PRIMARIES_OTHER) { |
| 267 | me.set().primaries = C2Color::PRIMARIES_OTHER; |
| 268 | } |
| 269 | if (me.v.transfer > C2Color::TRANSFER_OTHER) { |
| 270 | me.set().transfer = C2Color::TRANSFER_OTHER; |
| 271 | } |
| 272 | if (me.v.matrix > C2Color::MATRIX_OTHER) { |
| 273 | me.set().matrix = C2Color::MATRIX_OTHER; |
| 274 | } |
| 275 | return C2R::Ok(); |
| 276 | } |
| 277 | |
| 278 | static C2R ColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::output> &me, |
| 279 | const C2P<C2StreamColorAspectsTuning::output> &def, |
| 280 | const C2P<C2StreamColorAspectsInfo::input> &coded) { |
| 281 | (void)mayBlock; |
| 282 | // take default values for all unspecified fields, and coded values for specified ones |
| 283 | me.set().range = coded.v.range == RANGE_UNSPECIFIED ? def.v.range : coded.v.range; |
| 284 | me.set().primaries = coded.v.primaries == PRIMARIES_UNSPECIFIED |
| 285 | ? def.v.primaries : coded.v.primaries; |
| 286 | me.set().transfer = coded.v.transfer == TRANSFER_UNSPECIFIED |
| 287 | ? def.v.transfer : coded.v.transfer; |
| 288 | me.set().matrix = coded.v.matrix == MATRIX_UNSPECIFIED ? def.v.matrix : coded.v.matrix; |
| 289 | return C2R::Ok(); |
| 290 | } |
| 291 | |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 292 | static C2R ProfileLevelSetter( |
| 293 | bool mayBlock, C2P<C2StreamProfileLevelInfo::input> &me, |
| 294 | const C2P<C2StreamPictureSizeInfo::output> &size) { |
| 295 | (void)mayBlock; |
| 296 | (void)size; |
| 297 | (void)me; // TODO: validate |
| 298 | return C2R::Ok(); |
| 299 | } |
| 300 | |
| 301 | std::shared_ptr<C2StreamColorAspectsTuning::output> |
| 302 | getDefaultColorAspects_l() { |
| 303 | return mDefaultColorAspects; |
| 304 | } |
| 305 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 306 | std::shared_ptr<C2StreamColorAspectsInfo::output> getColorAspects_l() { |
| 307 | return mColorAspects; |
| 308 | } |
| 309 | |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 310 | static C2R Hdr10PlusInfoInputSetter(bool mayBlock, |
| 311 | C2P<C2StreamHdr10PlusInfo::input> &me) { |
| 312 | (void)mayBlock; |
| 313 | (void)me; // TODO: validate |
| 314 | return C2R::Ok(); |
| 315 | } |
| 316 | |
| 317 | static C2R Hdr10PlusInfoOutputSetter(bool mayBlock, |
| 318 | C2P<C2StreamHdr10PlusInfo::output> &me) { |
| 319 | (void)mayBlock; |
| 320 | (void)me; // TODO: validate |
| 321 | return C2R::Ok(); |
| 322 | } |
| 323 | |
| 324 | private: |
| 325 | std::shared_ptr<C2StreamProfileLevelInfo::input> mProfileLevel; |
| 326 | std::shared_ptr<C2StreamPictureSizeInfo::output> mSize; |
| 327 | std::shared_ptr<C2StreamMaxPictureSizeTuning::output> mMaxSize; |
| 328 | std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize; |
| 329 | std::shared_ptr<C2StreamColorInfo::output> mColorInfo; |
| 330 | std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormat; |
| 331 | std::shared_ptr<C2StreamColorAspectsTuning::output> mDefaultColorAspects; |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 332 | std::shared_ptr<C2StreamColorAspectsInfo::input> mCodedColorAspects; |
| 333 | std::shared_ptr<C2StreamColorAspectsInfo::output> mColorAspects; |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 334 | std::shared_ptr<C2StreamHdr10PlusInfo::input> mHdr10PlusInfoInput; |
| 335 | std::shared_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfoOutput; |
| 336 | }; |
| 337 | |
| 338 | C2SoftGav1Dec::C2SoftGav1Dec(const char *name, c2_node_id_t id, |
| 339 | const std::shared_ptr<IntfImpl> &intfImpl) |
| 340 | : SimpleC2Component( |
| 341 | std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)), |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 342 | mIntf(intfImpl), |
| 343 | mCodecCtx(nullptr) { |
| 344 | gettimeofday(&mTimeStart, nullptr); |
| 345 | gettimeofday(&mTimeEnd, nullptr); |
| 346 | } |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 347 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 348 | C2SoftGav1Dec::~C2SoftGav1Dec() { onRelease(); } |
| 349 | |
| 350 | c2_status_t C2SoftGav1Dec::onInit() { |
| 351 | return initDecoder() ? C2_OK : C2_CORRUPTED; |
| 352 | } |
| 353 | |
| 354 | c2_status_t C2SoftGav1Dec::onStop() { |
| 355 | mSignalledError = false; |
| 356 | mSignalledOutputEos = false; |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 357 | return C2_OK; |
| 358 | } |
| 359 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 360 | void C2SoftGav1Dec::onReset() { |
| 361 | (void)onStop(); |
| 362 | c2_status_t err = onFlush_sm(); |
| 363 | if (err != C2_OK) { |
| 364 | ALOGW("Failed to flush the av1 decoder. Trying to hard reset."); |
| 365 | destroyDecoder(); |
| 366 | if (!initDecoder()) { |
| 367 | ALOGE("Hard reset failed."); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | void C2SoftGav1Dec::onRelease() { destroyDecoder(); } |
| 373 | |
| 374 | c2_status_t C2SoftGav1Dec::onFlush_sm() { |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 375 | Libgav1StatusCode status = mCodecCtx->SignalEOS(); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 376 | if (status != kLibgav1StatusOk) { |
| 377 | ALOGE("Failed to flush av1 decoder. status: %d.", status); |
| 378 | return C2_CORRUPTED; |
| 379 | } |
| 380 | |
| 381 | // Dequeue frame (if any) that was enqueued previously. |
| 382 | const libgav1::DecoderBuffer *buffer; |
| 383 | status = mCodecCtx->DequeueFrame(&buffer); |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 384 | if (status != kLibgav1StatusOk && status != kLibgav1StatusNothingToDequeue) { |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 385 | ALOGE("Failed to dequeue frame after flushing the av1 decoder. status: %d", |
| 386 | status); |
| 387 | return C2_CORRUPTED; |
| 388 | } |
| 389 | |
| 390 | mSignalledError = false; |
| 391 | mSignalledOutputEos = false; |
| 392 | |
| 393 | return C2_OK; |
| 394 | } |
| 395 | |
| 396 | static int GetCPUCoreCount() { |
| 397 | int cpuCoreCount = 1; |
| 398 | #if defined(_SC_NPROCESSORS_ONLN) |
| 399 | cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN); |
| 400 | #else |
| 401 | // _SC_NPROC_ONLN must be defined... |
| 402 | cpuCoreCount = sysconf(_SC_NPROC_ONLN); |
| 403 | #endif |
| 404 | CHECK(cpuCoreCount >= 1); |
| 405 | ALOGV("Number of CPU cores: %d", cpuCoreCount); |
| 406 | return cpuCoreCount; |
| 407 | } |
| 408 | |
| 409 | bool C2SoftGav1Dec::initDecoder() { |
| 410 | mSignalledError = false; |
| 411 | mSignalledOutputEos = false; |
Harish Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 412 | mHalPixelFormat = HAL_PIXEL_FORMAT_YV12; |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 413 | mCodecCtx.reset(new libgav1::Decoder()); |
| 414 | |
| 415 | if (mCodecCtx == nullptr) { |
| 416 | ALOGE("mCodecCtx is null"); |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | libgav1::DecoderSettings settings = {}; |
| 421 | settings.threads = GetCPUCoreCount(); |
| 422 | |
Vignesh Venkatasubramanian | 61ba2cf | 2019-06-24 10:04:00 -0700 | [diff] [blame] | 423 | ALOGV("Using libgav1 AV1 software decoder."); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 424 | Libgav1StatusCode status = mCodecCtx->Init(&settings); |
| 425 | if (status != kLibgav1StatusOk) { |
| 426 | ALOGE("av1 decoder failed to initialize. status: %d.", status); |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | void C2SoftGav1Dec::destroyDecoder() { mCodecCtx = nullptr; } |
| 434 | |
| 435 | void fillEmptyWork(const std::unique_ptr<C2Work> &work) { |
| 436 | uint32_t flags = 0; |
| 437 | if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) { |
| 438 | flags |= C2FrameData::FLAG_END_OF_STREAM; |
| 439 | ALOGV("signalling eos"); |
| 440 | } |
| 441 | work->worklets.front()->output.flags = (C2FrameData::flags_t)flags; |
| 442 | work->worklets.front()->output.buffers.clear(); |
| 443 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 444 | work->workletsProcessed = 1u; |
| 445 | } |
| 446 | |
| 447 | void C2SoftGav1Dec::finishWork(uint64_t index, |
| 448 | const std::unique_ptr<C2Work> &work, |
| 449 | const std::shared_ptr<C2GraphicBlock> &block) { |
| 450 | std::shared_ptr<C2Buffer> buffer = |
| 451 | createGraphicBuffer(block, C2Rect(mWidth, mHeight)); |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 452 | { |
| 453 | IntfImpl::Lock lock = mIntf->lock(); |
| 454 | buffer->setInfo(mIntf->getColorAspects_l()); |
| 455 | } |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 456 | auto fillWork = [buffer, index](const std::unique_ptr<C2Work> &work) { |
| 457 | uint32_t flags = 0; |
| 458 | if ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) && |
| 459 | (c2_cntr64_t(index) == work->input.ordinal.frameIndex)) { |
| 460 | flags |= C2FrameData::FLAG_END_OF_STREAM; |
| 461 | ALOGV("signalling eos"); |
| 462 | } |
| 463 | work->worklets.front()->output.flags = (C2FrameData::flags_t)flags; |
| 464 | work->worklets.front()->output.buffers.clear(); |
| 465 | work->worklets.front()->output.buffers.push_back(buffer); |
| 466 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 467 | work->workletsProcessed = 1u; |
| 468 | }; |
| 469 | if (work && c2_cntr64_t(index) == work->input.ordinal.frameIndex) { |
| 470 | fillWork(work); |
| 471 | } else { |
| 472 | finish(index, fillWork); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | void C2SoftGav1Dec::process(const std::unique_ptr<C2Work> &work, |
| 477 | const std::shared_ptr<C2BlockPool> &pool) { |
| 478 | work->result = C2_OK; |
| 479 | work->workletsProcessed = 0u; |
| 480 | work->worklets.front()->output.configUpdate.clear(); |
| 481 | work->worklets.front()->output.flags = work->input.flags; |
| 482 | if (mSignalledError || mSignalledOutputEos) { |
| 483 | work->result = C2_BAD_VALUE; |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | size_t inOffset = 0u; |
| 488 | size_t inSize = 0u; |
| 489 | C2ReadView rView = mDummyReadView; |
| 490 | if (!work->input.buffers.empty()) { |
| 491 | rView = work->input.buffers[0]->data().linearBlocks().front().map().get(); |
| 492 | inSize = rView.capacity(); |
| 493 | if (inSize && rView.error()) { |
| 494 | ALOGE("read view map failed %d", rView.error()); |
| 495 | work->result = C2_CORRUPTED; |
| 496 | return; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | bool codecConfig = |
| 501 | ((work->input.flags & C2FrameData::FLAG_CODEC_CONFIG) != 0); |
| 502 | bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0); |
| 503 | |
| 504 | ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x", inSize, |
| 505 | (int)work->input.ordinal.timestamp.peeku(), |
| 506 | (int)work->input.ordinal.frameIndex.peeku(), work->input.flags); |
| 507 | |
| 508 | if (codecConfig) { |
| 509 | fillEmptyWork(work); |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | int64_t frameIndex = work->input.ordinal.frameIndex.peekll(); |
| 514 | if (inSize) { |
| 515 | uint8_t *bitstream = const_cast<uint8_t *>(rView.data() + inOffset); |
| 516 | int32_t decodeTime = 0; |
| 517 | int32_t delay = 0; |
| 518 | |
| 519 | GETTIME(&mTimeStart, nullptr); |
| 520 | TIME_DIFF(mTimeEnd, mTimeStart, delay); |
| 521 | |
| 522 | const Libgav1StatusCode status = |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 523 | mCodecCtx->EnqueueFrame(bitstream, inSize, frameIndex, |
| 524 | /*buffer_private_data=*/nullptr); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 525 | |
| 526 | GETTIME(&mTimeEnd, nullptr); |
| 527 | TIME_DIFF(mTimeStart, mTimeEnd, decodeTime); |
| 528 | ALOGV("decodeTime=%4d delay=%4d\n", decodeTime, delay); |
| 529 | |
| 530 | if (status != kLibgav1StatusOk) { |
| 531 | ALOGE("av1 decoder failed to decode frame. status: %d.", status); |
| 532 | work->result = C2_CORRUPTED; |
| 533 | work->workletsProcessed = 1u; |
| 534 | mSignalledError = true; |
| 535 | return; |
| 536 | } |
| 537 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | (void)outputBuffer(pool, work); |
| 541 | |
| 542 | if (eos) { |
| 543 | drainInternal(DRAIN_COMPONENT_WITH_EOS, pool, work); |
| 544 | mSignalledOutputEos = true; |
| 545 | } else if (!inSize) { |
| 546 | fillEmptyWork(work); |
| 547 | } |
| 548 | } |
| 549 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 550 | void C2SoftGav1Dec::getVuiParams(const libgav1::DecoderBuffer *buffer) { |
| 551 | VuiColorAspects vuiColorAspects; |
| 552 | vuiColorAspects.primaries = buffer->color_primary; |
| 553 | vuiColorAspects.transfer = buffer->transfer_characteristics; |
| 554 | vuiColorAspects.coeffs = buffer->matrix_coefficients; |
| 555 | vuiColorAspects.fullRange = buffer->color_range; |
| 556 | |
| 557 | // convert vui aspects to C2 values if changed |
| 558 | if (!(vuiColorAspects == mBitstreamColorAspects)) { |
| 559 | mBitstreamColorAspects = vuiColorAspects; |
| 560 | ColorAspects sfAspects; |
| 561 | C2StreamColorAspectsInfo::input codedAspects = { 0u }; |
| 562 | ColorUtils::convertIsoColorAspectsToCodecAspects( |
| 563 | vuiColorAspects.primaries, vuiColorAspects.transfer, vuiColorAspects.coeffs, |
| 564 | vuiColorAspects.fullRange, sfAspects); |
| 565 | if (!C2Mapper::map(sfAspects.mPrimaries, &codedAspects.primaries)) { |
| 566 | codedAspects.primaries = C2Color::PRIMARIES_UNSPECIFIED; |
| 567 | } |
| 568 | if (!C2Mapper::map(sfAspects.mRange, &codedAspects.range)) { |
| 569 | codedAspects.range = C2Color::RANGE_UNSPECIFIED; |
| 570 | } |
| 571 | if (!C2Mapper::map(sfAspects.mMatrixCoeffs, &codedAspects.matrix)) { |
| 572 | codedAspects.matrix = C2Color::MATRIX_UNSPECIFIED; |
| 573 | } |
| 574 | if (!C2Mapper::map(sfAspects.mTransfer, &codedAspects.transfer)) { |
| 575 | codedAspects.transfer = C2Color::TRANSFER_UNSPECIFIED; |
| 576 | } |
| 577 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 578 | mIntf->config({&codedAspects}, C2_MAY_BLOCK, &failures); |
| 579 | } |
| 580 | } |
| 581 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 582 | bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool, |
| 583 | const std::unique_ptr<C2Work> &work) { |
| 584 | if (!(work && pool)) return false; |
| 585 | |
| 586 | const libgav1::DecoderBuffer *buffer; |
| 587 | const Libgav1StatusCode status = mCodecCtx->DequeueFrame(&buffer); |
| 588 | |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 589 | if (status != kLibgav1StatusOk && status != kLibgav1StatusNothingToDequeue) { |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 590 | ALOGE("av1 decoder DequeueFrame failed. status: %d.", status); |
| 591 | return false; |
| 592 | } |
| 593 | |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 594 | // |buffer| can be NULL if status was equal to kLibgav1StatusOk or |
| 595 | // kLibgav1StatusNothingToDequeue. This is not an error. This could mean one |
| 596 | // of two things: |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 597 | // - The EnqueueFrame() call was either a flush (called with nullptr). |
| 598 | // - The enqueued frame did not have any displayable frames. |
| 599 | if (!buffer) { |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | const int width = buffer->displayed_width[0]; |
| 604 | const int height = buffer->displayed_height[0]; |
| 605 | if (width != mWidth || height != mHeight) { |
| 606 | mWidth = width; |
| 607 | mHeight = height; |
| 608 | |
| 609 | C2StreamPictureSizeInfo::output size(0u, mWidth, mHeight); |
| 610 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 611 | c2_status_t err = mIntf->config({&size}, C2_MAY_BLOCK, &failures); |
| 612 | if (err == C2_OK) { |
| 613 | work->worklets.front()->output.configUpdate.push_back( |
| 614 | C2Param::Copy(size)); |
| 615 | } else { |
| 616 | ALOGE("Config update size failed"); |
| 617 | mSignalledError = true; |
| 618 | work->result = C2_CORRUPTED; |
| 619 | work->workletsProcessed = 1u; |
| 620 | return false; |
| 621 | } |
| 622 | } |
| 623 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 624 | getVuiParams(buffer); |
James Zern | 4d25d65 | 2021-06-22 18:10:13 -0700 | [diff] [blame] | 625 | if (!(buffer->image_format == libgav1::kImageFormatYuv420 || |
| 626 | buffer->image_format == libgav1::kImageFormatMonochrome400)) { |
| 627 | ALOGE("image_format %d not supported", buffer->image_format); |
| 628 | mSignalledError = true; |
| 629 | work->workletsProcessed = 1u; |
| 630 | work->result = C2_CORRUPTED; |
| 631 | return false; |
| 632 | } |
Vignesh Venkatasubramanian | ca7d1ab | 2021-02-04 12:39:06 -0800 | [diff] [blame] | 633 | const bool isMonochrome = |
| 634 | buffer->image_format == libgav1::kImageFormatMonochrome400; |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 635 | |
| 636 | std::shared_ptr<C2GraphicBlock> block; |
| 637 | uint32_t format = HAL_PIXEL_FORMAT_YV12; |
| 638 | if (buffer->bitdepth == 10) { |
| 639 | IntfImpl::Lock lock = mIntf->lock(); |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 640 | std::shared_ptr<C2StreamColorAspectsInfo::output> codedColorAspects = |
| 641 | mIntf->getColorAspects_l(); |
Harish Mahendrakar | 749a74c | 2022-01-27 16:47:09 -0800 | [diff] [blame] | 642 | bool allowRGBA1010102 = false; |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 643 | if (codedColorAspects->primaries == C2Color::PRIMARIES_BT2020 && |
| 644 | codedColorAspects->matrix == C2Color::MATRIX_BT2020 && |
| 645 | codedColorAspects->transfer == C2Color::TRANSFER_ST2084) { |
Harish Mahendrakar | 749a74c | 2022-01-27 16:47:09 -0800 | [diff] [blame] | 646 | allowRGBA1010102 = true; |
| 647 | } |
| 648 | format = getHalPixelFormatForBitDepth10(allowRGBA1010102); |
| 649 | if ((format == HAL_PIXEL_FORMAT_RGBA_1010102) && |
| 650 | (buffer->image_format != libgav1::kImageFormatYuv420)) { |
Vignesh Venkatasubramanian | ca7d1ab | 2021-02-04 12:39:06 -0800 | [diff] [blame] | 651 | ALOGE("Only YUV420 output is supported when targeting RGBA_1010102"); |
Harish Mahendrakar | 749a74c | 2022-01-27 16:47:09 -0800 | [diff] [blame] | 652 | mSignalledError = true; |
| 653 | work->result = C2_OMITTED; |
| 654 | work->workletsProcessed = 1u; |
| 655 | return false; |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
Harish Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 658 | |
| 659 | if (mHalPixelFormat != format) { |
| 660 | C2StreamPixelFormatInfo::output pixelFormat(0u, format); |
| 661 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 662 | c2_status_t err = mIntf->config({&pixelFormat }, C2_MAY_BLOCK, &failures); |
| 663 | if (err == C2_OK) { |
| 664 | work->worklets.front()->output.configUpdate.push_back( |
| 665 | C2Param::Copy(pixelFormat)); |
| 666 | } else { |
| 667 | ALOGE("Config update pixelFormat failed"); |
| 668 | mSignalledError = true; |
| 669 | work->workletsProcessed = 1u; |
| 670 | work->result = C2_CORRUPTED; |
| 671 | return UNKNOWN_ERROR; |
| 672 | } |
| 673 | mHalPixelFormat = format; |
| 674 | } |
| 675 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 676 | C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE}; |
| 677 | |
| 678 | c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format, |
| 679 | usage, &block); |
| 680 | |
| 681 | if (err != C2_OK) { |
| 682 | ALOGE("fetchGraphicBlock for Output failed with status %d", err); |
| 683 | work->result = err; |
| 684 | return false; |
| 685 | } |
| 686 | |
| 687 | C2GraphicView wView = block->map().get(); |
| 688 | |
| 689 | if (wView.error()) { |
| 690 | ALOGE("graphic view map failed %d", wView.error()); |
| 691 | work->result = C2_CORRUPTED; |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | ALOGV("provided (%dx%d) required (%dx%d), out frameindex %d", block->width(), |
| 696 | block->height(), mWidth, mHeight, (int)buffer->user_private_data); |
| 697 | |
ming.zhou | ac19c3d | 2019-10-11 11:14:07 +0800 | [diff] [blame] | 698 | uint8_t *dstY = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_Y]); |
| 699 | uint8_t *dstU = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_U]); |
| 700 | uint8_t *dstV = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_V]); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 701 | size_t srcYStride = buffer->stride[0]; |
| 702 | size_t srcUStride = buffer->stride[1]; |
| 703 | size_t srcVStride = buffer->stride[2]; |
| 704 | |
ming.zhou | ac19c3d | 2019-10-11 11:14:07 +0800 | [diff] [blame] | 705 | C2PlanarLayout layout = wView.layout(); |
| 706 | size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc; |
| 707 | size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc; |
| 708 | |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 709 | if (buffer->bitdepth == 10) { |
| 710 | const uint16_t *srcY = (const uint16_t *)buffer->plane[0]; |
| 711 | const uint16_t *srcU = (const uint16_t *)buffer->plane[1]; |
| 712 | const uint16_t *srcV = (const uint16_t *)buffer->plane[2]; |
| 713 | |
| 714 | if (format == HAL_PIXEL_FORMAT_RGBA_1010102) { |
Harish Mahendrakar | 5c46765 | 2022-04-28 19:47:28 -0700 | [diff] [blame] | 715 | convertYUV420Planar16ToY410OrRGBA1010102((uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2, |
| 716 | srcUStride / 2, srcVStride / 2, |
| 717 | dstYStride / sizeof(uint32_t), mWidth, mHeight); |
Harish Mahendrakar | 1b1aef2 | 2021-12-30 19:12:51 -0800 | [diff] [blame] | 718 | } else if (format == HAL_PIXEL_FORMAT_YCBCR_P010) { |
| 719 | convertYUV420Planar16ToP010((uint16_t *)dstY, (uint16_t *)dstU, srcY, srcU, srcV, |
| 720 | srcYStride / 2, srcUStride / 2, srcVStride / 2, dstYStride / 2, |
| 721 | dstUVStride / 2, mWidth, mHeight, isMonochrome); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 722 | } else { |
Harish Mahendrakar | 1b1aef2 | 2021-12-30 19:12:51 -0800 | [diff] [blame] | 723 | convertYUV420Planar16ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride / 2, |
| 724 | srcUStride / 2, srcVStride / 2, dstYStride, dstUVStride, mWidth, |
| 725 | mHeight, isMonochrome); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 726 | } |
| 727 | } else { |
| 728 | const uint8_t *srcY = (const uint8_t *)buffer->plane[0]; |
| 729 | const uint8_t *srcU = (const uint8_t *)buffer->plane[1]; |
| 730 | const uint8_t *srcV = (const uint8_t *)buffer->plane[2]; |
Harish Mahendrakar | 1b1aef2 | 2021-12-30 19:12:51 -0800 | [diff] [blame] | 731 | convertYUV420Planar8ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride, srcUStride, |
| 732 | srcVStride, dstYStride, dstUVStride, mWidth, mHeight, isMonochrome); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 733 | } |
| 734 | finishWork(buffer->user_private_data, work, std::move(block)); |
| 735 | block = nullptr; |
| 736 | return true; |
| 737 | } |
| 738 | |
| 739 | c2_status_t C2SoftGav1Dec::drainInternal( |
| 740 | uint32_t drainMode, const std::shared_ptr<C2BlockPool> &pool, |
| 741 | const std::unique_ptr<C2Work> &work) { |
| 742 | if (drainMode == NO_DRAIN) { |
| 743 | ALOGW("drain with NO_DRAIN: no-op"); |
| 744 | return C2_OK; |
| 745 | } |
| 746 | if (drainMode == DRAIN_CHAIN) { |
| 747 | ALOGW("DRAIN_CHAIN not supported"); |
| 748 | return C2_OMITTED; |
| 749 | } |
| 750 | |
James Zern | b7aee6e | 2020-06-26 13:49:53 -0700 | [diff] [blame] | 751 | const Libgav1StatusCode status = mCodecCtx->SignalEOS(); |
Vignesh Venkatasubramanian | 0f3e742 | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 752 | if (status != kLibgav1StatusOk) { |
| 753 | ALOGE("Failed to flush av1 decoder. status: %d.", status); |
| 754 | return C2_CORRUPTED; |
| 755 | } |
| 756 | |
| 757 | while (outputBuffer(pool, work)) { |
| 758 | } |
| 759 | |
| 760 | if (drainMode == DRAIN_COMPONENT_WITH_EOS && work && |
| 761 | work->workletsProcessed == 0u) { |
| 762 | fillEmptyWork(work); |
| 763 | } |
| 764 | |
| 765 | return C2_OK; |
| 766 | } |
| 767 | |
| 768 | c2_status_t C2SoftGav1Dec::drain(uint32_t drainMode, |
| 769 | const std::shared_ptr<C2BlockPool> &pool) { |
| 770 | return drainInternal(drainMode, pool, nullptr); |
| 771 | } |
| 772 | |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 773 | class C2SoftGav1Factory : public C2ComponentFactory { |
| 774 | public: |
| 775 | C2SoftGav1Factory() |
| 776 | : mHelper(std::static_pointer_cast<C2ReflectorHelper>( |
| 777 | GetCodec2PlatformComponentStore()->getParamReflector())) {} |
| 778 | |
| 779 | virtual c2_status_t createComponent( |
| 780 | c2_node_id_t id, std::shared_ptr<C2Component> *const component, |
| 781 | std::function<void(C2Component *)> deleter) override { |
| 782 | *component = std::shared_ptr<C2Component>( |
| 783 | new C2SoftGav1Dec(COMPONENT_NAME, id, |
| 784 | std::make_shared<C2SoftGav1Dec::IntfImpl>(mHelper)), |
| 785 | deleter); |
| 786 | return C2_OK; |
| 787 | } |
| 788 | |
| 789 | virtual c2_status_t createInterface( |
| 790 | c2_node_id_t id, std::shared_ptr<C2ComponentInterface> *const interface, |
| 791 | std::function<void(C2ComponentInterface *)> deleter) override { |
| 792 | *interface = std::shared_ptr<C2ComponentInterface>( |
| 793 | new SimpleInterface<C2SoftGav1Dec::IntfImpl>( |
| 794 | COMPONENT_NAME, id, |
| 795 | std::make_shared<C2SoftGav1Dec::IntfImpl>(mHelper)), |
| 796 | deleter); |
| 797 | return C2_OK; |
| 798 | } |
| 799 | |
| 800 | virtual ~C2SoftGav1Factory() override = default; |
| 801 | |
| 802 | private: |
| 803 | std::shared_ptr<C2ReflectorHelper> mHelper; |
| 804 | }; |
| 805 | |
| 806 | } // namespace android |
| 807 | |
Cindy Zhou | f6c0c3c | 2020-12-02 10:53:40 -0800 | [diff] [blame] | 808 | __attribute__((cfi_canonical_jump_table)) |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 809 | extern "C" ::C2ComponentFactory *CreateCodec2Factory() { |
| 810 | ALOGV("in %s", __func__); |
| 811 | return new ::android::C2SoftGav1Factory(); |
| 812 | } |
| 813 | |
Cindy Zhou | f6c0c3c | 2020-12-02 10:53:40 -0800 | [diff] [blame] | 814 | __attribute__((cfi_canonical_jump_table)) |
Vignesh Venkatasubramanian | b6d383d | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 815 | extern "C" void DestroyCodec2Factory(::C2ComponentFactory *factory) { |
| 816 | ALOGV("in %s", __func__); |
| 817 | delete factory; |
| 818 | } |