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