Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 "C2SoftAomEnc" |
| 19 | #include <log/log.h> |
| 20 | |
| 21 | #include <media/stagefright/foundation/AUtils.h> |
| 22 | #include <media/stagefright/foundation/MediaDefs.h> |
| 23 | |
| 24 | #include <C2Debug.h> |
Harish Mahendrakar | 7de78d4 | 2023-02-06 17:12:18 -0800 | [diff] [blame] | 25 | #include <Codec2CommonUtils.h> |
Aayush Soni | 643b918 | 2023-01-18 20:23:56 +0530 | [diff] [blame] | 26 | #include <Codec2Mapper.h> |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 27 | #include <C2PlatformSupport.h> |
| 28 | #include <SimpleC2Interface.h> |
| 29 | |
| 30 | #include "C2SoftAomEnc.h" |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | constexpr char COMPONENT_NAME[] = "c2.android.av1.encoder"; |
| 35 | |
| 36 | #define DEFAULT_SPEED 10 |
| 37 | |
| 38 | C2SoftAomEnc::IntfImpl::IntfImpl(const std::shared_ptr<C2ReflectorHelper>& helper) |
| 39 | : SimpleInterface<void>::BaseParams(helper, COMPONENT_NAME, C2Component::KIND_ENCODER, |
| 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 | setDerivedInstance(this); |
| 47 | |
| 48 | addParameter(DefineParam(mUsage, C2_PARAMKEY_INPUT_STREAM_USAGE) |
| 49 | .withConstValue(new C2StreamUsageTuning::input( |
| 50 | 0u, (uint64_t)C2MemoryUsage::CPU_READ)) |
| 51 | .build()); |
| 52 | |
| 53 | addParameter(DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE) |
| 54 | .withDefault(new C2StreamPictureSizeInfo::input(0u, 320, 240)) |
| 55 | .withFields({ |
| 56 | C2F(mSize, width).inRange(2, 2048, 2), |
| 57 | C2F(mSize, height).inRange(2, 2048, 2), |
| 58 | }) |
| 59 | .withSetter(SizeSetter) |
| 60 | .build()); |
| 61 | |
| 62 | addParameter(DefineParam(mBitrateMode, C2_PARAMKEY_BITRATE_MODE) |
| 63 | .withDefault(new C2StreamBitrateModeTuning::output( |
| 64 | 0u, C2Config::BITRATE_VARIABLE)) |
| 65 | .withFields({C2F(mBitrateMode, value) |
| 66 | .oneOf({C2Config::BITRATE_CONST, |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 67 | C2Config::BITRATE_VARIABLE, |
| 68 | C2Config::BITRATE_IGNORE})}) |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 69 | .withSetter(Setter<decltype(*mBitrateMode)>::StrictValueWithNoDeps) |
| 70 | .build()); |
| 71 | |
| 72 | addParameter(DefineParam(mFrameRate, C2_PARAMKEY_FRAME_RATE) |
| 73 | .withDefault(new C2StreamFrameRateInfo::output(0u, 30.)) |
| 74 | // TODO: More restriction? |
| 75 | .withFields({C2F(mFrameRate, value).greaterThan(0.)}) |
| 76 | .withSetter(Setter<decltype(*mFrameRate)>::StrictValueWithNoDeps) |
| 77 | .build()); |
| 78 | |
| 79 | addParameter(DefineParam(mSyncFramePeriod, C2_PARAMKEY_SYNC_FRAME_INTERVAL) |
| 80 | .withDefault(new C2StreamSyncFrameIntervalTuning::output(0u, 1000000)) |
| 81 | .withFields({C2F(mSyncFramePeriod, value).any()}) |
| 82 | .withSetter(Setter<decltype(*mSyncFramePeriod)>::StrictValueWithNoDeps) |
| 83 | .build()); |
| 84 | |
| 85 | addParameter(DefineParam(mBitrate, C2_PARAMKEY_BITRATE) |
| 86 | .withDefault(new C2StreamBitrateInfo::output(0u, 64000)) |
| 87 | .withFields({C2F(mBitrate, value).inRange(4096, 40000000)}) |
| 88 | .withSetter(BitrateSetter) |
| 89 | .build()); |
| 90 | |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 91 | addParameter(DefineParam(mComplexity, C2_PARAMKEY_COMPLEXITY) |
| 92 | .withDefault(new C2StreamComplexityTuning::output(0u, 0)) |
| 93 | .withFields({C2F(mComplexity, value).inRange(0, 5)}) |
| 94 | .withSetter(Setter<decltype(*mComplexity)>::NonStrictValueWithNoDeps) |
| 95 | .build()); |
| 96 | |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 97 | addParameter(DefineParam(mQuality, C2_PARAMKEY_QUALITY) |
| 98 | .withDefault(new C2StreamQualityTuning::output(0u, 80)) |
| 99 | .withFields({C2F(mQuality, value).inRange(0, 100)}) |
| 100 | .withSetter(Setter<decltype(*mQuality)>::NonStrictValueWithNoDeps) |
| 101 | .build()); |
| 102 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 103 | addParameter(DefineParam(mIntraRefresh, C2_PARAMKEY_INTRA_REFRESH) |
| 104 | .withConstValue(new C2StreamIntraRefreshTuning::output( |
| 105 | 0u, C2Config::INTRA_REFRESH_DISABLED, 0.)) |
| 106 | .build()); |
| 107 | |
| 108 | addParameter(DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL) |
| 109 | .withDefault(new C2StreamProfileLevelInfo::output(0u, PROFILE_AV1_0, |
Harish Mahendrakar | 7d482b2 | 2023-08-21 20:08:01 -0700 | [diff] [blame] | 110 | LEVEL_AV1_2)) |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 111 | .withFields({ |
| 112 | C2F(mProfileLevel, profile).equalTo(PROFILE_AV1_0), |
Fyodor Kyslov | a809232 | 2022-10-09 02:47:33 +0000 | [diff] [blame] | 113 | C2F(mProfileLevel, level) |
| 114 | .oneOf({LEVEL_AV1_2, LEVEL_AV1_2_1, LEVEL_AV1_2_2, |
| 115 | LEVEL_AV1_2_3, LEVEL_AV1_3, LEVEL_AV1_3_1, |
| 116 | LEVEL_AV1_3_2, LEVEL_AV1_3_3, LEVEL_AV1_4, |
| 117 | LEVEL_AV1_4_1}), |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 118 | }) |
mtk12101 | c1670e9 | 2023-02-10 09:34:02 +0800 | [diff] [blame] | 119 | .withSetter(ProfileLevelSetter, mSize, mFrameRate, mBitrate) |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 120 | .build()); |
| 121 | |
Harish Mahendrakar | 7de78d4 | 2023-02-06 17:12:18 -0800 | [diff] [blame] | 122 | std::vector<uint32_t> pixelFormats = {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, |
| 123 | HAL_PIXEL_FORMAT_YCBCR_420_888}; |
| 124 | if (isHalPixelFormatSupported((AHardwareBuffer_Format)HAL_PIXEL_FORMAT_YCBCR_P010)) { |
| 125 | pixelFormats.push_back(HAL_PIXEL_FORMAT_YCBCR_P010); |
| 126 | } |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 127 | addParameter(DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT) |
Harish Mahendrakar | 7de78d4 | 2023-02-06 17:12:18 -0800 | [diff] [blame] | 128 | .withDefault(new C2StreamPixelFormatInfo::input( |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 129 | 0u, HAL_PIXEL_FORMAT_YCBCR_420_888)) |
Harish Mahendrakar | 7de78d4 | 2023-02-06 17:12:18 -0800 | [diff] [blame] | 130 | .withFields({C2F(mPixelFormat, value).oneOf({pixelFormats})}) |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 131 | .withSetter((Setter<decltype(*mPixelFormat)>::StrictValueWithNoDeps)) |
| 132 | .build()); |
| 133 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 134 | addParameter(DefineParam(mRequestSync, C2_PARAMKEY_REQUEST_SYNC_FRAME) |
| 135 | .withDefault(new C2StreamRequestSyncFrameTuning::output(0u, C2_FALSE)) |
| 136 | .withFields({C2F(mRequestSync, value).oneOf({C2_FALSE, C2_TRUE})}) |
| 137 | .withSetter(Setter<decltype(*mRequestSync)>::NonStrictValueWithNoDeps) |
| 138 | .build()); |
| 139 | addParameter( |
| 140 | DefineParam(mColorAspects, C2_PARAMKEY_COLOR_ASPECTS) |
| 141 | .withDefault(new C2StreamColorAspectsInfo::input( |
| 142 | 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED, |
| 143 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 144 | .withFields( |
| 145 | {C2F(mColorAspects, range) |
| 146 | .inRange(C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 147 | C2F(mColorAspects, primaries) |
| 148 | .inRange(C2Color::PRIMARIES_UNSPECIFIED, |
| 149 | C2Color::PRIMARIES_OTHER), |
| 150 | C2F(mColorAspects, transfer) |
| 151 | .inRange(C2Color::TRANSFER_UNSPECIFIED, |
| 152 | C2Color::TRANSFER_OTHER), |
| 153 | C2F(mColorAspects, matrix) |
| 154 | .inRange(C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER)}) |
| 155 | .withSetter(ColorAspectsSetter) |
| 156 | .build()); |
| 157 | |
| 158 | addParameter( |
| 159 | DefineParam(mCodedColorAspects, C2_PARAMKEY_VUI_COLOR_ASPECTS) |
| 160 | .withDefault(new C2StreamColorAspectsInfo::output( |
| 161 | 0u, C2Color::RANGE_LIMITED, C2Color::PRIMARIES_UNSPECIFIED, |
| 162 | C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED)) |
| 163 | .withFields( |
| 164 | {C2F(mCodedColorAspects, range) |
| 165 | .inRange(C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER), |
| 166 | C2F(mCodedColorAspects, primaries) |
| 167 | .inRange(C2Color::PRIMARIES_UNSPECIFIED, |
| 168 | C2Color::PRIMARIES_OTHER), |
| 169 | C2F(mCodedColorAspects, transfer) |
| 170 | .inRange(C2Color::TRANSFER_UNSPECIFIED, |
| 171 | C2Color::TRANSFER_OTHER), |
| 172 | C2F(mCodedColorAspects, matrix) |
| 173 | .inRange(C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER)}) |
| 174 | .withSetter(CodedColorAspectsSetter, mColorAspects) |
| 175 | .build()); |
| 176 | } |
| 177 | |
| 178 | C2R C2SoftAomEnc::IntfImpl::BitrateSetter(bool mayBlock, C2P<C2StreamBitrateInfo::output>& me) { |
| 179 | (void)mayBlock; |
| 180 | C2R res = C2R::Ok(); |
| 181 | if (me.v.value < 4096) { |
| 182 | me.set().value = 4096; |
| 183 | } |
| 184 | return res; |
| 185 | } |
| 186 | |
| 187 | C2R C2SoftAomEnc::IntfImpl::SizeSetter(bool mayBlock, |
| 188 | const C2P<C2StreamPictureSizeInfo::input>& oldMe, |
| 189 | C2P<C2StreamPictureSizeInfo::input>& me) { |
| 190 | (void)mayBlock; |
| 191 | C2R res = C2R::Ok(); |
| 192 | if (!me.F(me.v.width).supportsAtAll(me.v.width)) { |
| 193 | res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.width))); |
| 194 | me.set().width = oldMe.v.width; |
| 195 | } |
| 196 | if (!me.F(me.v.height).supportsAtAll(me.v.height)) { |
| 197 | res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.height))); |
| 198 | me.set().height = oldMe.v.height; |
| 199 | } |
| 200 | return res; |
| 201 | } |
| 202 | |
| 203 | C2R C2SoftAomEnc::IntfImpl::ProfileLevelSetter(bool mayBlock, |
mtk12101 | c1670e9 | 2023-02-10 09:34:02 +0800 | [diff] [blame] | 204 | C2P<C2StreamProfileLevelInfo::output>& me, |
| 205 | const C2P<C2StreamPictureSizeInfo::input>& size, |
| 206 | const C2P<C2StreamFrameRateInfo::output>& frameRate, |
| 207 | const C2P<C2StreamBitrateInfo::output>& bitrate) { |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 208 | (void)mayBlock; |
| 209 | if (!me.F(me.v.profile).supportsAtAll(me.v.profile)) { |
| 210 | me.set().profile = PROFILE_AV1_0; |
| 211 | } |
mtk12101 | c1670e9 | 2023-02-10 09:34:02 +0800 | [diff] [blame] | 212 | struct LevelLimits { |
| 213 | C2Config::level_t level; |
| 214 | float samplesPerSec; |
| 215 | uint64_t samples; |
| 216 | uint32_t bitrate; |
| 217 | size_t maxHSize; |
| 218 | size_t maxVSize; |
| 219 | }; |
| 220 | constexpr LevelLimits kLimits[] = { |
| 221 | {LEVEL_AV1_2, 4423680, 147456, 1500000, 2048, 1152}, |
| 222 | {LEVEL_AV1_2_1, 8363520, 278784, 3000000, 2816, 1584}, |
| 223 | {LEVEL_AV1_3, 19975680, 665856, 6000000, 4352, 2448}, |
| 224 | {LEVEL_AV1_3_1, 37950720, 1065024, 10000000, 5504, 3096}, |
| 225 | {LEVEL_AV1_4, 70778880, 2359296, 12000000, 6144, 3456}, |
| 226 | {LEVEL_AV1_4_1, 141557760, 2359296, 20000000, 6144, 3456}, |
| 227 | }; |
| 228 | |
| 229 | uint64_t samples = size.v.width * size.v.height; |
| 230 | float samplesPerSec = float(samples) * frameRate.v.value; |
| 231 | |
| 232 | // Check if the supplied level meets the samples / bitrate requirements. |
| 233 | // If not, update the level with the lowest level meeting the requirements. |
| 234 | bool found = false; |
| 235 | |
| 236 | // By default needsUpdate = false in case the supplied level does meet |
| 237 | // the requirements. |
| 238 | bool needsUpdate = false; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 239 | if (!me.F(me.v.level).supportsAtAll(me.v.level)) { |
mtk12101 | c1670e9 | 2023-02-10 09:34:02 +0800 | [diff] [blame] | 240 | needsUpdate = true; |
| 241 | } |
| 242 | for (const LevelLimits& limit : kLimits) { |
| 243 | if (samples <= limit.samples && samplesPerSec <= limit.samplesPerSec && |
| 244 | bitrate.v.value <= limit.bitrate && size.v.width <= limit.maxHSize && |
| 245 | size.v.height <= limit.maxVSize) { |
| 246 | // This is the lowest level that meets the requirements, and if |
| 247 | // we haven't seen the supplied level yet, that means we don't |
| 248 | // need the update. |
| 249 | if (needsUpdate) { |
| 250 | ALOGD("Given level %x does not cover current configuration: " |
| 251 | "adjusting to %x", |
| 252 | me.v.level, limit.level); |
| 253 | me.set().level = limit.level; |
| 254 | } |
| 255 | found = true; |
| 256 | break; |
| 257 | } |
| 258 | if (me.v.level == limit.level) { |
| 259 | // We break out of the loop when the lowest feasible level is |
| 260 | // found. The fact that we're here means that our level doesn't |
| 261 | // meet the requirement and needs to be updated. |
| 262 | needsUpdate = true; |
| 263 | } |
| 264 | } |
| 265 | if (!found) { |
| 266 | // We set to the highest supported level. |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 267 | me.set().level = LEVEL_AV1_4_1; |
| 268 | } |
| 269 | return C2R::Ok(); |
| 270 | } |
| 271 | |
| 272 | uint32_t C2SoftAomEnc::IntfImpl::getSyncFramePeriod() const { |
| 273 | if (mSyncFramePeriod->value < 0 || mSyncFramePeriod->value == INT64_MAX) { |
| 274 | return 0; |
| 275 | } |
| 276 | double period = mSyncFramePeriod->value / 1e6 * mFrameRate->value; |
| 277 | return (uint32_t)c2_max(c2_min(period + 0.5, double(UINT32_MAX)), 1.); |
| 278 | } |
| 279 | |
| 280 | C2R C2SoftAomEnc::IntfImpl::ColorAspectsSetter(bool mayBlock, |
| 281 | C2P<C2StreamColorAspectsInfo::input>& me) { |
| 282 | (void)mayBlock; |
| 283 | if (me.v.range > C2Color::RANGE_OTHER) { |
| 284 | me.set().range = C2Color::RANGE_OTHER; |
| 285 | } |
| 286 | if (me.v.primaries > C2Color::PRIMARIES_OTHER) { |
| 287 | me.set().primaries = C2Color::PRIMARIES_OTHER; |
| 288 | } |
| 289 | if (me.v.transfer > C2Color::TRANSFER_OTHER) { |
| 290 | me.set().transfer = C2Color::TRANSFER_OTHER; |
| 291 | } |
| 292 | if (me.v.matrix > C2Color::MATRIX_OTHER) { |
| 293 | me.set().matrix = C2Color::MATRIX_OTHER; |
| 294 | } |
| 295 | return C2R::Ok(); |
| 296 | } |
| 297 | C2R C2SoftAomEnc::IntfImpl::CodedColorAspectsSetter( |
| 298 | bool mayBlock, C2P<C2StreamColorAspectsInfo::output>& me, |
| 299 | const C2P<C2StreamColorAspectsInfo::input>& coded) { |
| 300 | (void)mayBlock; |
| 301 | me.set().range = coded.v.range; |
| 302 | me.set().primaries = coded.v.primaries; |
| 303 | me.set().transfer = coded.v.transfer; |
| 304 | me.set().matrix = coded.v.matrix; |
| 305 | return C2R::Ok(); |
| 306 | } |
| 307 | |
Harish Mahendrakar | 7d482b2 | 2023-08-21 20:08:01 -0700 | [diff] [blame] | 308 | uint32_t C2SoftAomEnc::IntfImpl::getLevel_l() const { |
| 309 | return mProfileLevel->level - LEVEL_AV1_2; |
| 310 | } |
| 311 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 312 | C2SoftAomEnc::C2SoftAomEnc(const char* name, c2_node_id_t id, |
| 313 | const std::shared_ptr<IntfImpl>& intfImpl) |
| 314 | : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)), |
| 315 | mIntf(intfImpl), |
| 316 | mCodecContext(nullptr), |
| 317 | mCodecConfiguration(nullptr), |
| 318 | mCodecInterface(nullptr), |
| 319 | mStrideAlign(2), |
| 320 | mBitrateControlMode(AOM_VBR), |
| 321 | mMinQuantizer(0), |
| 322 | mMaxQuantizer(0), |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 323 | mLastTimestamp(INT64_MAX), |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 324 | mSignalledOutputEos(false), |
| 325 | mSignalledError(false), |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 326 | mHeadersReceived(false), |
| 327 | mIs10Bit(false) { |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 328 | ALOGV("Constructor"); |
| 329 | } |
| 330 | |
| 331 | C2SoftAomEnc::~C2SoftAomEnc() { |
| 332 | ALOGV("Destructor"); |
| 333 | onRelease(); |
| 334 | } |
| 335 | |
| 336 | c2_status_t C2SoftAomEnc::onInit() { |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 337 | return C2_OK; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | c2_status_t C2SoftAomEnc::onStop() { |
| 341 | onRelease(); |
| 342 | return C2_OK; |
| 343 | } |
| 344 | |
| 345 | void C2SoftAomEnc::onReset() { |
| 346 | (void)onStop(); |
| 347 | } |
| 348 | |
| 349 | void C2SoftAomEnc::onRelease() { |
| 350 | if (mCodecContext) { |
| 351 | aom_codec_destroy(mCodecContext); |
| 352 | delete mCodecContext; |
| 353 | mCodecContext = nullptr; |
| 354 | } |
| 355 | |
| 356 | if (mCodecConfiguration) { |
| 357 | delete mCodecConfiguration; |
| 358 | mCodecConfiguration = nullptr; |
| 359 | } |
| 360 | |
| 361 | // this one is not allocated by us |
| 362 | mCodecInterface = nullptr; |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 363 | mHeadersReceived = false; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | c2_status_t C2SoftAomEnc::onFlush_sm() { |
| 367 | return onStop(); |
| 368 | } |
| 369 | |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 370 | // c2Quality is in range of 0-100 (the more - the better), |
| 371 | // for AOM quality we are using a range of 15-50 (the less - the better) |
| 372 | static int MapC2QualityToAOMQuality (int c2Quality) { |
| 373 | return 15 + 35 * (100 - c2Quality) / 100; |
| 374 | } |
| 375 | |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 376 | static int MapC2ComplexityToAOMSpeed (int c2Complexity) { |
| 377 | int mapping[6] = {10, 9, 8, 7, 6, 6}; |
| 378 | if (c2Complexity > 5 || c2Complexity < 0) { |
| 379 | ALOGW("Wrong complexity setting. Falling back to speed 10"); |
| 380 | return 10; |
| 381 | } |
| 382 | return mapping[c2Complexity]; |
| 383 | } |
| 384 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 385 | aom_codec_err_t C2SoftAomEnc::setupCodecParameters() { |
| 386 | aom_codec_err_t codec_return = AOM_CODEC_OK; |
| 387 | |
Harish Mahendrakar | 7d482b2 | 2023-08-21 20:08:01 -0700 | [diff] [blame] | 388 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_TARGET_SEQ_LEVEL_IDX, mAV1EncLevel); |
| 389 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 390 | |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 391 | codec_return = aom_codec_control(mCodecContext, AOME_SET_CPUUSED, |
| 392 | MapC2ComplexityToAOMSpeed(mComplexity->value)); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 393 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 394 | |
| 395 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ROW_MT, 1); |
| 396 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 397 | |
| 398 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_CDEF, 1); |
| 399 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 400 | |
| 401 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_TPL_MODEL, 0); |
| 402 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 403 | |
| 404 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_DELTAQ_MODE, 0); |
| 405 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 406 | |
| 407 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_ORDER_HINT, 0); |
| 408 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 409 | |
| 410 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_AQ_MODE, 3); |
| 411 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 412 | |
| 413 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_COEFF_COST_UPD_FREQ, 3); |
| 414 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 415 | |
| 416 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_MODE_COST_UPD_FREQ, 3); |
| 417 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 418 | |
| 419 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_MV_COST_UPD_FREQ, 3); |
| 420 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 421 | |
| 422 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_PALETTE, 0); |
| 423 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 424 | |
| 425 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_OBMC, 0); |
| 426 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 427 | |
| 428 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_NOISE_SENSITIVITY, 0); |
| 429 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 430 | |
| 431 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_WARPED_MOTION, 0); |
| 432 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 433 | |
| 434 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_GLOBAL_MOTION, 0); |
| 435 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 436 | |
| 437 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_REF_FRAME_MVS, 0); |
| 438 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 439 | |
| 440 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_CFL_INTRA, 0); |
| 441 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 442 | |
| 443 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_SMOOTH_INTRA, 0); |
| 444 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 445 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_ANGLE_DELTA, 0); |
| 446 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 447 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_FILTER_INTRA, 0); |
| 448 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 449 | |
| 450 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 1); |
| 451 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 452 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_DISABLE_TRELLIS_QUANT, 1); |
| 453 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 454 | |
| 455 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_DIST_WTD_COMP, 0); |
| 456 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 457 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_DIFF_WTD_COMP, 0); |
| 458 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 459 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_DUAL_FILTER, 0); |
| 460 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 461 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_INTERINTRA_COMP, 0); |
| 462 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 463 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_INTERINTRA_WEDGE, 0); |
| 464 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 465 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_INTRA_EDGE_FILTER, 0); |
| 466 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 467 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_INTRABC, 0); |
| 468 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 469 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_MASKED_COMP, 0); |
| 470 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 471 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_PAETH_INTRA, 0); |
| 472 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 473 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_QM, 0); |
| 474 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 475 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_RECT_PARTITIONS, 0); |
| 476 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 477 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_RESTORATION, 0); |
| 478 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 479 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_SMOOTH_INTERINTRA, 0); |
| 480 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 481 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_ENABLE_TX64, 0); |
| 482 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 483 | |
| 484 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_MAX_REFERENCE_FRAMES, 3); |
| 485 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 486 | |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 487 | if (mBitrateControlMode == AOM_Q) { |
| 488 | const int aomCQLevel = MapC2QualityToAOMQuality(mQuality->value); |
| 489 | ALOGV("Set Q from %d to CQL %d", |
| 490 | mQuality->value, aomCQLevel); |
| 491 | |
| 492 | codec_return = aom_codec_control(mCodecContext, AOME_SET_CQ_LEVEL, aomCQLevel); |
| 493 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 494 | } |
| 495 | |
Aayush Soni | 643b918 | 2023-01-18 20:23:56 +0530 | [diff] [blame] | 496 | ColorAspects sfAspects; |
| 497 | if (!C2Mapper::map(mColorAspects->primaries, &sfAspects.mPrimaries)) { |
| 498 | sfAspects.mPrimaries = android::ColorAspects::PrimariesUnspecified; |
| 499 | } |
| 500 | if (!C2Mapper::map(mColorAspects->range, &sfAspects.mRange)) { |
| 501 | sfAspects.mRange = android::ColorAspects::RangeUnspecified; |
| 502 | } |
| 503 | if (!C2Mapper::map(mColorAspects->matrix, &sfAspects.mMatrixCoeffs)) { |
| 504 | sfAspects.mMatrixCoeffs = android::ColorAspects::MatrixUnspecified; |
| 505 | } |
| 506 | if (!C2Mapper::map(mColorAspects->transfer, &sfAspects.mTransfer)) { |
| 507 | sfAspects.mTransfer = android::ColorAspects::TransferUnspecified; |
| 508 | } |
| 509 | int32_t primaries, transfer, matrixCoeffs; |
| 510 | bool range; |
| 511 | ColorUtils::convertCodecColorAspectsToIsoAspects(sfAspects, |
| 512 | &primaries, |
| 513 | &transfer, |
| 514 | &matrixCoeffs, |
| 515 | &range); |
| 516 | |
| 517 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_COLOR_RANGE, range); |
| 518 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 519 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_COLOR_PRIMARIES, primaries); |
| 520 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 521 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_TRANSFER_CHARACTERISTICS, transfer); |
| 522 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 523 | codec_return = aom_codec_control(mCodecContext, AV1E_SET_MATRIX_COEFFICIENTS, matrixCoeffs); |
| 524 | if (codec_return != AOM_CODEC_OK) goto BailOut; |
| 525 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 526 | BailOut: |
| 527 | return codec_return; |
| 528 | } |
| 529 | |
| 530 | status_t C2SoftAomEnc::initEncoder() { |
| 531 | aom_codec_err_t codec_return; |
| 532 | status_t result = UNKNOWN_ERROR; |
| 533 | { |
| 534 | IntfImpl::Lock lock = mIntf->lock(); |
| 535 | // Fetch config |
| 536 | mSize = mIntf->getSize_l(); |
| 537 | mBitrate = mIntf->getBitrate_l(); |
| 538 | mBitrateMode = mIntf->getBitrateMode_l(); |
| 539 | mFrameRate = mIntf->getFrameRate_l(); |
| 540 | mIntraRefresh = mIntf->getIntraRefresh_l(); |
| 541 | mRequestSync = mIntf->getRequestSync_l(); |
Aayush Soni | 643b918 | 2023-01-18 20:23:56 +0530 | [diff] [blame] | 542 | mColorAspects = mIntf->getCodedColorAspects_l(); |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 543 | mQuality = mIntf->getQuality_l(); |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 544 | mComplexity = mIntf->getComplexity_l(); |
Harish Mahendrakar | 7d482b2 | 2023-08-21 20:08:01 -0700 | [diff] [blame] | 545 | mAV1EncLevel = mIntf->getLevel_l(); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 548 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 549 | switch (mBitrateMode->value) { |
| 550 | case C2Config::BITRATE_CONST: |
| 551 | mBitrateControlMode = AOM_CBR; |
| 552 | break; |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 553 | case C2Config::BITRATE_IGNORE: |
| 554 | mBitrateControlMode = AOM_Q; |
| 555 | break; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 556 | case C2Config::BITRATE_VARIABLE: |
| 557 | [[fallthrough]]; |
| 558 | default: |
| 559 | mBitrateControlMode = AOM_VBR; |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | mCodecInterface = aom_codec_av1_cx(); |
| 564 | if (!mCodecInterface) goto CleanUp; |
| 565 | |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 566 | ALOGD("AOM: initEncoder. BRMode: %u. KF: %u. QP: %u - %u, 10Bit: %d, comlexity %d", |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 567 | (uint32_t)mBitrateControlMode, |
Fyodor Kyslov | 3e3a92b | 2023-03-15 00:39:36 +0000 | [diff] [blame] | 568 | mIntf->getSyncFramePeriod(), mMinQuantizer, mMaxQuantizer, mIs10Bit, mComplexity->value); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 569 | |
| 570 | mCodecConfiguration = new aom_codec_enc_cfg_t; |
| 571 | if (!mCodecConfiguration) goto CleanUp; |
| 572 | |
| 573 | codec_return = aom_codec_enc_config_default(mCodecInterface, mCodecConfiguration, |
| 574 | AOM_USAGE_REALTIME); // RT mode |
| 575 | if (codec_return != AOM_CODEC_OK) { |
| 576 | ALOGE("Error populating default configuration for aom encoder."); |
| 577 | goto CleanUp; |
| 578 | } |
| 579 | |
| 580 | mCodecConfiguration->g_w = mSize->width; |
| 581 | mCodecConfiguration->g_h = mSize->height; |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 582 | mCodecConfiguration->g_bit_depth = mIs10Bit ? AOM_BITS_10 : AOM_BITS_8; |
| 583 | mCodecConfiguration->g_input_bit_depth = mIs10Bit ? 10 : 8; |
| 584 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 585 | |
| 586 | mCodecConfiguration->g_threads = 0; |
| 587 | mCodecConfiguration->g_error_resilient = 0; |
| 588 | |
| 589 | // timebase unit is microsecond |
| 590 | // g_timebase is in seconds (i.e. 1/1000000 seconds) |
| 591 | mCodecConfiguration->g_timebase.num = 1; |
| 592 | mCodecConfiguration->g_timebase.den = 1000000; |
| 593 | // rc_target_bitrate is in kbps, mBitrate in bps |
| 594 | mCodecConfiguration->rc_target_bitrate = (mBitrate->value + 500) / 1000; |
Fyodor Kyslov | 58d8dea | 2023-02-10 02:15:54 +0000 | [diff] [blame] | 595 | mCodecConfiguration->rc_end_usage = mBitrateControlMode == AOM_Q ? AOM_Q : AOM_CBR; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 596 | // Disable frame drop - not allowed in MediaCodec now. |
| 597 | mCodecConfiguration->rc_dropframe_thresh = 0; |
| 598 | // Disable lagged encoding. |
| 599 | mCodecConfiguration->g_lag_in_frames = 0; |
| 600 | |
| 601 | // Disable spatial resizing. |
| 602 | mCodecConfiguration->rc_resize_mode = 0; |
| 603 | // Single-pass mode. |
| 604 | mCodecConfiguration->g_pass = AOM_RC_ONE_PASS; |
| 605 | |
| 606 | // Maximum key frame interval - for CBR boost to 3000 |
| 607 | mCodecConfiguration->kf_max_dist = 3000; |
| 608 | // Encoder determines optimal key frame placement automatically. |
| 609 | mCodecConfiguration->kf_mode = AOM_KF_AUTO; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 610 | // The amount of data that may be buffered by the decoding |
| 611 | // application in ms. |
| 612 | mCodecConfiguration->rc_buf_sz = 1000; |
| 613 | |
| 614 | if (mBitrateControlMode == AOM_CBR) { |
Fyodor Kyslov | 90d99d6 | 2023-05-02 23:28:45 +0000 | [diff] [blame] | 615 | // Initial value of the buffer level in ms. |
| 616 | mCodecConfiguration->rc_buf_initial_sz = 500; |
| 617 | // Amount of data that the encoder should try to maintain in ms. |
| 618 | mCodecConfiguration->rc_buf_optimal_sz = 600; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 619 | // Maximum amount of bits that can be subtracted from the target |
| 620 | // bitrate - expressed as percentage of the target bitrate. |
| 621 | mCodecConfiguration->rc_undershoot_pct = 100; |
| 622 | // Maximum amount of bits that can be added to the target |
| 623 | // bitrate - expressed as percentage of the target bitrate. |
| 624 | mCodecConfiguration->rc_overshoot_pct = 10; |
| 625 | } else { |
| 626 | // Maximum amount of bits that can be subtracted from the target |
| 627 | // bitrate - expressed as percentage of the target bitrate. |
| 628 | mCodecConfiguration->rc_undershoot_pct = 100; |
| 629 | // Maximum amount of bits that can be added to the target |
| 630 | // bitrate - expressed as percentage of the target bitrate. |
Fyodor Kyslov | 90d99d6 | 2023-05-02 23:28:45 +0000 | [diff] [blame] | 631 | mCodecConfiguration->rc_overshoot_pct = 100; |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | if (mIntf->getSyncFramePeriod() >= 0) { |
| 635 | mCodecConfiguration->kf_max_dist = mIntf->getSyncFramePeriod(); |
| 636 | mCodecConfiguration->kf_min_dist = mIntf->getSyncFramePeriod(); |
| 637 | mCodecConfiguration->kf_mode = AOM_KF_AUTO; |
| 638 | } |
| 639 | if (mMinQuantizer > 0) { |
| 640 | mCodecConfiguration->rc_min_quantizer = mMinQuantizer; |
| 641 | } |
| 642 | if (mMaxQuantizer > 0) { |
| 643 | mCodecConfiguration->rc_max_quantizer = mMaxQuantizer; |
Fyodor Kyslov | 90d99d6 | 2023-05-02 23:28:45 +0000 | [diff] [blame] | 644 | } else { |
| 645 | if (mBitrateControlMode == AOM_VBR) { |
| 646 | // For VBR we are limiting MaxQP to 52 (down 11 steps) to maintain quality |
| 647 | // 52 comes from experiments done on libaom standalone app |
| 648 | mCodecConfiguration->rc_max_quantizer = 52; |
| 649 | } |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | mCodecContext = new aom_codec_ctx_t; |
| 653 | if (!mCodecContext) goto CleanUp; |
| 654 | codec_return = aom_codec_enc_init(mCodecContext, mCodecInterface, mCodecConfiguration, |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 655 | mIs10Bit ? AOM_CODEC_USE_HIGHBITDEPTH : 0); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 656 | if (codec_return != AOM_CODEC_OK) { |
| 657 | ALOGE("Error initializing aom encoder"); |
| 658 | goto CleanUp; |
| 659 | } |
| 660 | |
| 661 | codec_return = setupCodecParameters(); |
| 662 | if (codec_return != AOM_CODEC_OK) { |
| 663 | ALOGE("Error setting up codec parameters"); |
| 664 | goto CleanUp; |
| 665 | } |
| 666 | |
| 667 | mHeadersReceived = false; |
| 668 | |
| 669 | { |
| 670 | uint32_t width = mSize->width; |
| 671 | uint32_t height = mSize->height; |
| 672 | if (((uint64_t)width * height) > ((uint64_t)INT32_MAX / 3)) { |
| 673 | ALOGE("b/25812794, Buffer size is too big, width=%u, height=%u.", width, height); |
| 674 | } else { |
| 675 | uint32_t stride = (width + mStrideAlign - 1) & ~(mStrideAlign - 1); |
| 676 | uint32_t vstride = (height + mStrideAlign - 1) & ~(mStrideAlign - 1); |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 677 | mConversionBuffer = MemoryBlock::Allocate(stride * vstride * 3 / (mIs10Bit? 1 : 2)); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 678 | if (!mConversionBuffer.size()) { |
| 679 | ALOGE("Allocating conversion buffer failed."); |
| 680 | } else { |
| 681 | mNumInputFrames = -1; |
| 682 | return OK; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | CleanUp: |
| 688 | onRelease(); |
| 689 | return result; |
| 690 | } |
| 691 | |
| 692 | void C2SoftAomEnc::process(const std::unique_ptr<C2Work>& work, |
| 693 | const std::shared_ptr<C2BlockPool>& pool) { |
| 694 | // Initialize output work |
| 695 | work->result = C2_OK; |
| 696 | work->workletsProcessed = 1u; |
| 697 | work->worklets.front()->output.flags = work->input.flags; |
| 698 | |
| 699 | if (mSignalledError || mSignalledOutputEos) { |
| 700 | work->result = C2_BAD_VALUE; |
| 701 | return; |
| 702 | } |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 703 | |
Suyog Pawar | 0ed520b | 2023-05-12 14:16:24 +0000 | [diff] [blame] | 704 | std::shared_ptr<C2GraphicView> rView; |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 705 | std::shared_ptr<C2Buffer> inputBuffer; |
| 706 | if (!work->input.buffers.empty()) { |
| 707 | inputBuffer = work->input.buffers[0]; |
Suyog Pawar | 0ed520b | 2023-05-12 14:16:24 +0000 | [diff] [blame] | 708 | rView = std::make_shared<C2GraphicView>( |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 709 | inputBuffer->data().graphicBlocks().front().map().get()); |
| 710 | if (rView->error() != C2_OK) { |
| 711 | ALOGE("graphic view map err = %d", rView->error()); |
| 712 | work->result = C2_CORRUPTED; |
| 713 | return; |
| 714 | } |
| 715 | } else { |
| 716 | ALOGV("Empty input Buffer"); |
| 717 | uint32_t flags = 0; |
| 718 | if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) { |
| 719 | flags |= C2FrameData::FLAG_END_OF_STREAM; |
| 720 | } |
| 721 | work->worklets.front()->output.flags = (C2FrameData::flags_t)flags; |
| 722 | work->worklets.front()->output.buffers.clear(); |
| 723 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 724 | work->workletsProcessed = 1u; |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | bool end_of_stream = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0); |
| 729 | aom_image_t raw_frame; |
| 730 | const C2PlanarLayout& layout = rView->layout(); |
| 731 | if (!mHeadersReceived) { |
| 732 | mIs10Bit = (layout.planes[layout.PLANE_Y].bitDepth == 10); |
| 733 | |
| 734 | // Re-Initialize encoder |
| 735 | if (mCodecContext){ |
| 736 | onRelease(); |
| 737 | } |
| 738 | } |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 739 | if (!mCodecContext && OK != initEncoder()) { |
| 740 | ALOGE("Failed to initialize encoder"); |
| 741 | mSignalledError = true; |
| 742 | work->result = C2_CORRUPTED; |
| 743 | return; |
| 744 | } |
| 745 | |
Suyog Pawar | 0ed520b | 2023-05-12 14:16:24 +0000 | [diff] [blame] | 746 | //(b/279387842) |
| 747 | //workaround for incorrect crop size in view when using surface mode |
| 748 | rView->setCrop_be(C2Rect(mSize->width, mSize->height)); |
| 749 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 750 | if (!mHeadersReceived) { |
| 751 | Av1Config av1_config; |
| 752 | constexpr uint32_t header_length = 2048; |
| 753 | uint8_t header[header_length]; |
| 754 | size_t header_bytes; |
| 755 | aom_fixed_buf_t* obu_sequence_header = aom_codec_get_global_headers(mCodecContext); |
| 756 | int ret = 1; |
| 757 | if (obu_sequence_header) { |
| 758 | if (get_av1config_from_obu(reinterpret_cast<const uint8_t*>(obu_sequence_header->buf), |
| 759 | obu_sequence_header->sz, false, &av1_config) == 0) { |
| 760 | ret = write_av1config(&av1_config, header_length, &header_bytes, header); |
| 761 | |
| 762 | } else { |
| 763 | ALOGE("Can not get config"); |
| 764 | } |
| 765 | free(obu_sequence_header->buf); |
| 766 | free(obu_sequence_header); |
| 767 | } |
| 768 | |
| 769 | if (ret) { |
| 770 | ALOGE("Can not write config"); |
| 771 | mSignalledError = true; |
| 772 | work->result = C2_NO_MEMORY; |
| 773 | work->workletsProcessed = 1u; |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | mHeadersReceived = true; |
| 778 | std::unique_ptr<C2StreamInitDataInfo::output> csd = |
| 779 | C2StreamInitDataInfo::output::AllocUnique(header_bytes, 0u); |
| 780 | if (!csd) { |
| 781 | ALOGE("CSD allocation failed"); |
| 782 | mSignalledError = true; |
| 783 | work->result = C2_NO_MEMORY; |
| 784 | work->workletsProcessed = 1u; |
| 785 | return; |
| 786 | } |
| 787 | memcpy(csd->m.value, header, header_bytes); |
| 788 | work->worklets.front()->output.configUpdate.push_back(std::move(csd)); |
| 789 | ALOGV("CSD Produced of size %zu bytes", header_bytes); |
| 790 | } |
| 791 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 792 | const C2ConstGraphicBlock inBuffer = inputBuffer->data().graphicBlocks().front(); |
| 793 | if (inBuffer.width() < mSize->width || inBuffer.height() < mSize->height) { |
| 794 | ALOGE("unexpected Input buffer attributes %d(%d) x %d(%d)", inBuffer.width(), mSize->width, |
| 795 | inBuffer.height(), mSize->height); |
| 796 | mSignalledError = true; |
| 797 | work->result = C2_BAD_VALUE; |
| 798 | return; |
| 799 | } |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 800 | |
| 801 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 802 | uint32_t width = mSize->width; |
| 803 | uint32_t height = mSize->height; |
| 804 | if (width > 0x8000 || height > 0x8000) { |
| 805 | ALOGE("Image too big: %u x %u", width, height); |
| 806 | work->result = C2_BAD_VALUE; |
| 807 | return; |
| 808 | } |
| 809 | uint32_t stride = (width + mStrideAlign - 1) & ~(mStrideAlign - 1); |
| 810 | uint32_t vstride = (height + mStrideAlign - 1) & ~(mStrideAlign - 1); |
| 811 | switch (layout.type) { |
| 812 | case C2PlanarLayout::TYPE_RGB: |
| 813 | case C2PlanarLayout::TYPE_RGBA: { |
| 814 | std::shared_ptr<C2StreamColorAspectsInfo::output> colorAspects; |
| 815 | { |
| 816 | IntfImpl::Lock lock = mIntf->lock(); |
| 817 | colorAspects = mIntf->getCodedColorAspects_l(); |
| 818 | } |
| 819 | ConvertRGBToPlanarYUV(mConversionBuffer.data(), stride, vstride, |
| 820 | mConversionBuffer.size(), *rView.get(), colorAspects->matrix, |
| 821 | colorAspects->range); |
| 822 | aom_img_wrap(&raw_frame, AOM_IMG_FMT_I420, width, height, mStrideAlign, |
| 823 | mConversionBuffer.data()); |
| 824 | break; |
| 825 | } |
| 826 | case C2PlanarLayout::TYPE_YUV: { |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 827 | const bool isYUV420_10bit = IsYUV420_10bit(*rView); |
| 828 | if (!IsYUV420(*rView) && !isYUV420_10bit) { |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 829 | ALOGE("input is not YUV420"); |
| 830 | work->result = C2_BAD_VALUE; |
| 831 | return; |
| 832 | } |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 833 | if (!isYUV420_10bit) { |
| 834 | if (IsI420(*rView)) { |
| 835 | // I420 compatible - though with custom offset and stride |
| 836 | aom_img_wrap(&raw_frame, AOM_IMG_FMT_I420, width, height, mStrideAlign, |
| 837 | (uint8_t*)rView->data()[0]); |
| 838 | raw_frame.planes[1] = (uint8_t*)rView->data()[1]; |
| 839 | raw_frame.planes[2] = (uint8_t*)rView->data()[2]; |
| 840 | raw_frame.stride[0] = layout.planes[layout.PLANE_Y].rowInc; |
| 841 | raw_frame.stride[1] = layout.planes[layout.PLANE_U].rowInc; |
| 842 | raw_frame.stride[2] = layout.planes[layout.PLANE_V].rowInc; |
| 843 | } else { |
| 844 | // TODO(kyslov): Add image wrap for NV12 |
| 845 | // copy to I420 |
| 846 | MediaImage2 img = CreateYUV420PlanarMediaImage2(width, height, stride, vstride); |
| 847 | if (mConversionBuffer.size() >= stride * vstride * 3 / 2) { |
| 848 | status_t err = ImageCopy(mConversionBuffer.data(), &img, *rView); |
| 849 | if (err != OK) { |
| 850 | ALOGE("Buffer conversion failed: %d", err); |
| 851 | work->result = C2_BAD_VALUE; |
| 852 | return; |
| 853 | } |
| 854 | aom_img_wrap(&raw_frame, AOM_IMG_FMT_I420, stride, vstride, mStrideAlign, |
| 855 | mConversionBuffer.data()); |
| 856 | aom_img_set_rect(&raw_frame, 0, 0, width, height, 0); |
| 857 | } else { |
| 858 | ALOGE("Conversion buffer is too small: %u x %u for %zu", stride, vstride, |
| 859 | mConversionBuffer.size()); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 860 | work->result = C2_BAD_VALUE; |
| 861 | return; |
| 862 | } |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 863 | } |
| 864 | } else { // 10 bits |
| 865 | if (IsP010(*rView)) { |
| 866 | if (mConversionBuffer.size() >= stride * vstride * 3) { |
| 867 | uint16_t *dstY, *dstU, *dstV; |
| 868 | dstY = (uint16_t*)mConversionBuffer.data(); |
Aayush Soni | 698e2f2 | 2023-02-18 01:10:53 +0530 | [diff] [blame] | 869 | dstU = dstY + stride * vstride; |
| 870 | dstV = dstU + (stride * vstride) / 4; |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 871 | convertP010ToYUV420Planar16(dstY, dstU, dstV, (uint16_t*)(rView->data()[0]), |
Aayush Soni | 698e2f2 | 2023-02-18 01:10:53 +0530 | [diff] [blame] | 872 | (uint16_t*)(rView->data()[1]), |
| 873 | layout.planes[layout.PLANE_Y].rowInc / 2, |
| 874 | layout.planes[layout.PLANE_U].rowInc / 2, |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 875 | stride, stride / 2, stride / 2, stride, |
| 876 | vstride); |
| 877 | aom_img_wrap(&raw_frame, AOM_IMG_FMT_I42016, stride, vstride, mStrideAlign, |
| 878 | mConversionBuffer.data()); |
| 879 | aom_img_set_rect(&raw_frame, 0, 0, width, height, 0); |
| 880 | } else { |
| 881 | ALOGE("Conversion buffer is too small: %u x %u for %zu", stride, vstride, |
| 882 | mConversionBuffer.size()); |
| 883 | work->result = C2_BAD_VALUE; |
| 884 | return; |
| 885 | } |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 886 | } else { |
Fyodor Kyslov | d97e991 | 2022-11-07 19:23:21 +0000 | [diff] [blame] | 887 | ALOGE("Image format conversion is not supported."); |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 888 | work->result = C2_BAD_VALUE; |
| 889 | return; |
| 890 | } |
| 891 | } |
| 892 | break; |
| 893 | } |
Aayush Soni | 5e82a6c | 2023-02-27 18:34:23 +0530 | [diff] [blame] | 894 | case C2PlanarLayout::TYPE_YUVA: { |
| 895 | if (mConversionBuffer.size() >= stride * vstride * 3) { |
| 896 | uint16_t *dstY, *dstU, *dstV; |
| 897 | dstY = (uint16_t*)mConversionBuffer.data(); |
| 898 | dstU = dstY + stride * vstride; |
| 899 | dstV = dstU + (stride * vstride) / 4; |
| 900 | convertRGBA1010102ToYUV420Planar16(dstY, dstU, dstV, (uint32_t*)(rView->data()[0]), |
| 901 | layout.planes[layout.PLANE_Y].rowInc / 4, stride, |
| 902 | vstride, mColorAspects->matrix, |
| 903 | mColorAspects->range); |
| 904 | aom_img_wrap(&raw_frame, AOM_IMG_FMT_I42016, stride, vstride, mStrideAlign, |
| 905 | mConversionBuffer.data()); |
| 906 | aom_img_set_rect(&raw_frame, 0, 0, width, height, 0); |
| 907 | } else { |
| 908 | ALOGE("Conversion buffer is too small: %u x %u for %zu", stride, vstride, |
| 909 | mConversionBuffer.size()); |
| 910 | work->result = C2_BAD_VALUE; |
| 911 | return; |
| 912 | } |
| 913 | break; |
| 914 | } |
| 915 | |
Fyodor Kyslov | adc7114 | 2022-09-15 16:47:03 +0000 | [diff] [blame] | 916 | default: |
| 917 | ALOGE("Unrecognized plane type: %d", layout.type); |
| 918 | work->result = C2_BAD_VALUE; |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | aom_enc_frame_flags_t flags = 0; |
| 923 | // handle dynamic config parameters |
| 924 | { |
| 925 | IntfImpl::Lock lock = mIntf->lock(); |
| 926 | std::shared_ptr<C2StreamIntraRefreshTuning::output> intraRefresh = |
| 927 | mIntf->getIntraRefresh_l(); |
| 928 | std::shared_ptr<C2StreamBitrateInfo::output> bitrate = mIntf->getBitrate_l(); |
| 929 | std::shared_ptr<C2StreamRequestSyncFrameTuning::output> requestSync = |
| 930 | mIntf->getRequestSync_l(); |
| 931 | lock.unlock(); |
| 932 | |
| 933 | if (intraRefresh != mIntraRefresh) { |
| 934 | mIntraRefresh = intraRefresh; |
| 935 | ALOGV("Got mIntraRefresh request"); |
| 936 | } |
| 937 | |
| 938 | if (requestSync != mRequestSync) { |
| 939 | // we can handle IDR immediately |
| 940 | if (requestSync->value) { |
| 941 | // unset request |
| 942 | C2StreamRequestSyncFrameTuning::output clearSync(0u, C2_FALSE); |
| 943 | std::vector<std::unique_ptr<C2SettingResult>> failures; |
| 944 | mIntf->config({&clearSync}, C2_MAY_BLOCK, &failures); |
| 945 | ALOGV("Got sync request"); |
| 946 | flags |= AOM_EFLAG_FORCE_KF; |
| 947 | } |
| 948 | mRequestSync = requestSync; |
| 949 | } |
| 950 | |
| 951 | if (bitrate != mBitrate) { |
| 952 | mBitrate = bitrate; |
| 953 | mCodecConfiguration->rc_target_bitrate = (mBitrate->value + 500) / 1000; |
| 954 | aom_codec_err_t res = aom_codec_enc_config_set(mCodecContext, mCodecConfiguration); |
| 955 | if (res != AOM_CODEC_OK) { |
| 956 | ALOGE("aom encoder failed to update bitrate: %s", aom_codec_err_to_string(res)); |
| 957 | mSignalledError = true; |
| 958 | work->result = C2_CORRUPTED; |
| 959 | return; |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | uint64_t input_timestamp = work->input.ordinal.timestamp.peekull(); |
| 965 | uint32_t frame_duration; |
| 966 | if (input_timestamp > mLastTimestamp) { |
| 967 | frame_duration = (uint32_t)(input_timestamp - mLastTimestamp); |
| 968 | } else { |
| 969 | // Use default of 30 fps in case of 0 frame rate. |
| 970 | float frame_rate = mFrameRate->value; |
| 971 | if (frame_rate < 0.001) { |
| 972 | frame_rate = 30.0; |
| 973 | } |
| 974 | frame_duration = (uint32_t)(1000000 / frame_rate + 0.5); |
| 975 | } |
| 976 | mLastTimestamp = input_timestamp; |
| 977 | |
| 978 | aom_codec_err_t codec_return = |
| 979 | aom_codec_encode(mCodecContext, &raw_frame, input_timestamp, frame_duration, flags); |
| 980 | if (codec_return != AOM_CODEC_OK) { |
| 981 | ALOGE("aom encoder failed to encode frame"); |
| 982 | mSignalledError = true; |
| 983 | work->result = C2_CORRUPTED; |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | bool populated = false; |
| 988 | aom_codec_iter_t encoded_packet_iterator = nullptr; |
| 989 | const aom_codec_cx_pkt_t* encoded_packet; |
| 990 | while ((encoded_packet = aom_codec_get_cx_data(mCodecContext, &encoded_packet_iterator))) { |
| 991 | if (encoded_packet->kind == AOM_CODEC_CX_FRAME_PKT) { |
| 992 | std::shared_ptr<C2LinearBlock> block; |
| 993 | C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE}; |
| 994 | c2_status_t err = pool->fetchLinearBlock(encoded_packet->data.frame.sz, usage, &block); |
| 995 | if (err != C2_OK) { |
| 996 | ALOGE("fetchLinearBlock for Output failed with status %d", err); |
| 997 | work->result = C2_NO_MEMORY; |
| 998 | return; |
| 999 | } |
| 1000 | C2WriteView wView = block->map().get(); |
| 1001 | if (wView.error()) { |
| 1002 | ALOGE("write view map failed %d", wView.error()); |
| 1003 | work->result = C2_CORRUPTED; |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | memcpy(wView.data(), encoded_packet->data.frame.buf, encoded_packet->data.frame.sz); |
| 1008 | ++mNumInputFrames; |
| 1009 | |
| 1010 | ALOGD("bytes generated %zu", encoded_packet->data.frame.sz); |
| 1011 | uint32_t flags = 0; |
| 1012 | if (end_of_stream) { |
| 1013 | flags |= C2FrameData::FLAG_END_OF_STREAM; |
| 1014 | } |
| 1015 | |
| 1016 | work->worklets.front()->output.flags = (C2FrameData::flags_t)flags; |
| 1017 | work->worklets.front()->output.buffers.clear(); |
| 1018 | std::shared_ptr<C2Buffer> buffer = |
| 1019 | createLinearBuffer(block, 0, encoded_packet->data.frame.sz); |
| 1020 | if (encoded_packet->data.frame.flags & AOM_FRAME_IS_KEY) { |
| 1021 | buffer->setInfo(std::make_shared<C2StreamPictureTypeMaskInfo::output>( |
| 1022 | 0u /* stream id */, C2Config::SYNC_FRAME)); |
| 1023 | } |
| 1024 | work->worklets.front()->output.buffers.push_back(buffer); |
| 1025 | work->worklets.front()->output.ordinal = work->input.ordinal; |
| 1026 | work->worklets.front()->output.ordinal.timestamp = encoded_packet->data.frame.pts; |
| 1027 | work->workletsProcessed = 1u; |
| 1028 | populated = true; |
| 1029 | if (end_of_stream) { |
| 1030 | mSignalledOutputEos = true; |
| 1031 | ALOGV("signalled End Of Stream"); |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | if (!populated) { |
| 1036 | work->workletsProcessed = 0u; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | c2_status_t C2SoftAomEnc::drain(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool) { |
| 1041 | (void)pool; |
| 1042 | if (drainMode == NO_DRAIN) { |
| 1043 | ALOGW("drain with NO_DRAIN: no-op"); |
| 1044 | return C2_OK; |
| 1045 | } |
| 1046 | if (drainMode == DRAIN_CHAIN) { |
| 1047 | ALOGW("DRAIN_CHAIN not supported"); |
| 1048 | return C2_OMITTED; |
| 1049 | } |
| 1050 | |
| 1051 | return C2_OK; |
| 1052 | } |
| 1053 | |
| 1054 | class C2SoftAomEncFactory : public C2ComponentFactory { |
| 1055 | public: |
| 1056 | C2SoftAomEncFactory() |
| 1057 | : mHelper(std::static_pointer_cast<C2ReflectorHelper>( |
| 1058 | GetCodec2PlatformComponentStore()->getParamReflector())) {} |
| 1059 | |
| 1060 | virtual c2_status_t createComponent(c2_node_id_t id, |
| 1061 | std::shared_ptr<C2Component>* const component, |
| 1062 | std::function<void(C2Component*)> deleter) override { |
| 1063 | *component = std::shared_ptr<C2Component>( |
| 1064 | new C2SoftAomEnc(COMPONENT_NAME, id, |
| 1065 | std::make_shared<C2SoftAomEnc::IntfImpl>(mHelper)), |
| 1066 | deleter); |
| 1067 | return C2_OK; |
| 1068 | } |
| 1069 | |
| 1070 | virtual c2_status_t createInterface( |
| 1071 | c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, |
| 1072 | std::function<void(C2ComponentInterface*)> deleter) override { |
| 1073 | *interface = std::shared_ptr<C2ComponentInterface>( |
| 1074 | new SimpleInterface<C2SoftAomEnc::IntfImpl>( |
| 1075 | COMPONENT_NAME, id, std::make_shared<C2SoftAomEnc::IntfImpl>(mHelper)), |
| 1076 | deleter); |
| 1077 | return C2_OK; |
| 1078 | } |
| 1079 | |
| 1080 | virtual ~C2SoftAomEncFactory() override = default; |
| 1081 | |
| 1082 | private: |
| 1083 | std::shared_ptr<C2ReflectorHelper> mHelper; |
| 1084 | }; |
| 1085 | |
| 1086 | } // namespace android |
| 1087 | |
| 1088 | __attribute__((cfi_canonical_jump_table)) extern "C" ::C2ComponentFactory* CreateCodec2Factory() { |
| 1089 | ALOGV("in %s", __func__); |
| 1090 | return new ::android::C2SoftAomEncFactory(); |
| 1091 | } |
| 1092 | |
| 1093 | __attribute__((cfi_canonical_jump_table)) extern "C" void DestroyCodec2Factory( |
| 1094 | ::C2ComponentFactory* factory) { |
| 1095 | ALOGV("in %s", __func__); |
| 1096 | delete factory; |
| 1097 | } |