Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #ifndef ANDROID_C2_SOFT_HEVC_DEC_H_ |
| 18 | #define ANDROID_C2_SOFT_HEVC_DEC_H_ |
| 19 | |
| 20 | #include <media/stagefright/foundation/ColorUtils.h> |
| 21 | |
Rakesh Kumar | 3bfa6e7 | 2019-02-18 10:41:14 +0530 | [diff] [blame] | 22 | #include <atomic> |
Ray Essick | 2475494 | 2022-04-16 09:50:35 -0700 | [diff] [blame] | 23 | #include <inttypes.h> |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 24 | #include <SimpleC2Component.h> |
| 25 | |
| 26 | #include "ihevc_typedefs.h" |
Shivaansh Agrawal | f01aba9 | 2020-12-28 18:20:58 +0530 | [diff] [blame] | 27 | #include "ihevcd_cxa.h" |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | #define ivdec_api_function ihevcd_cxa_api_function |
| 32 | #define ivdext_create_ip_t ihevcd_cxa_create_ip_t |
| 33 | #define ivdext_create_op_t ihevcd_cxa_create_op_t |
| 34 | #define ivdext_delete_ip_t ihevcd_cxa_delete_ip_t |
| 35 | #define ivdext_delete_op_t ihevcd_cxa_delete_op_t |
| 36 | #define ivdext_ctl_set_num_cores_ip_t ihevcd_cxa_ctl_set_num_cores_ip_t |
| 37 | #define ivdext_ctl_set_num_cores_op_t ihevcd_cxa_ctl_set_num_cores_op_t |
| 38 | #define ivdext_ctl_get_vui_params_ip_t ihevcd_cxa_ctl_get_vui_params_ip_t |
| 39 | #define ivdext_ctl_get_vui_params_op_t ihevcd_cxa_ctl_get_vui_params_op_t |
Harish Mahendrakar | e403bf7 | 2021-10-21 10:30:35 -0700 | [diff] [blame] | 40 | #define ALIGN128(x) ((((x) + 127) >> 7) << 7) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 41 | #define MAX_NUM_CORES 4 |
| 42 | #define IVDEXT_CMD_CTL_SET_NUM_CORES \ |
| 43 | (IVD_CONTROL_API_COMMAND_TYPE_T)IHEVCD_CXA_CMD_CTL_SET_NUM_CORES |
| 44 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 45 | |
| 46 | |
| 47 | struct C2SoftHevcDec : public SimpleC2Component { |
| 48 | class IntfImpl; |
| 49 | |
| 50 | C2SoftHevcDec(const char* name, c2_node_id_t id, |
| 51 | const std::shared_ptr<IntfImpl>& intfImpl); |
| 52 | virtual ~C2SoftHevcDec(); |
| 53 | |
| 54 | // From SimpleC2Component |
| 55 | c2_status_t onInit() override; |
| 56 | c2_status_t onStop() override; |
| 57 | void onReset() override; |
| 58 | void onRelease() override; |
| 59 | c2_status_t onFlush_sm() override; |
| 60 | void process( |
| 61 | const std::unique_ptr<C2Work> &work, |
| 62 | const std::shared_ptr<C2BlockPool> &pool) override; |
| 63 | c2_status_t drain( |
| 64 | uint32_t drainMode, |
| 65 | const std::shared_ptr<C2BlockPool> &pool) override; |
| 66 | private: |
| 67 | status_t createDecoder(); |
| 68 | status_t setNumCores(); |
| 69 | status_t setParams(size_t stride, IVD_VIDEO_DECODE_MODE_T dec_mode); |
| 70 | status_t getVersion(); |
| 71 | status_t initDecoder(); |
| 72 | bool setDecodeArgs(ivd_video_decode_ip_t *ps_decode_ip, |
| 73 | ivd_video_decode_op_t *ps_decode_op, |
| 74 | C2ReadView *inBuffer, |
| 75 | C2GraphicView *outBuffer, |
| 76 | size_t inOffset, |
| 77 | size_t inSize, |
| 78 | uint32_t tsMarker); |
| 79 | bool getVuiParams(); |
| 80 | // TODO:This is not the right place for colorAspects functions. These should |
| 81 | // be part of c2-vndk so that they can be accessed by all video plugins |
| 82 | // until then, make them feel at home |
| 83 | bool colorAspectsDiffer(const ColorAspects &a, const ColorAspects &b); |
| 84 | void updateFinalColorAspects( |
| 85 | const ColorAspects &otherAspects, const ColorAspects &preferredAspects); |
| 86 | status_t handleColorAspectsChange(); |
| 87 | c2_status_t ensureDecoderState(const std::shared_ptr<C2BlockPool> &pool); |
| 88 | void finishWork(uint64_t index, const std::unique_ptr<C2Work> &work); |
| 89 | status_t setFlushMode(); |
| 90 | c2_status_t drainInternal( |
| 91 | uint32_t drainMode, |
| 92 | const std::shared_ptr<C2BlockPool> &pool, |
| 93 | const std::unique_ptr<C2Work> &work); |
| 94 | status_t resetDecoder(); |
| 95 | void resetPlugin(); |
| 96 | status_t deleteDecoder(); |
| 97 | |
| 98 | // TODO:This is not the right place for this enum. These should |
| 99 | // be part of c2-vndk so that they can be accessed by all video plugins |
| 100 | // until then, make them feel at home |
| 101 | enum { |
| 102 | kNotSupported, |
| 103 | kPreferBitstream, |
| 104 | kPreferContainer, |
| 105 | }; |
| 106 | |
| 107 | std::shared_ptr<IntfImpl> mIntf; |
| 108 | iv_obj_t *mDecHandle; |
| 109 | std::shared_ptr<C2GraphicBlock> mOutBlock; |
| 110 | uint8_t *mOutBufferFlush; |
| 111 | |
| 112 | size_t mNumCores; |
| 113 | IV_COLOR_FORMAT_T mIvColorformat; |
Harish Mahendrakar | 343be8a | 2019-08-01 12:38:58 -0700 | [diff] [blame] | 114 | uint32_t mOutputDelay; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 115 | uint32_t mWidth; |
| 116 | uint32_t mHeight; |
| 117 | uint32_t mStride; |
| 118 | bool mSignalledOutputEos; |
| 119 | bool mSignalledError; |
| 120 | bool mHeaderDecoded; |
Rakesh Kumar | 3bfa6e7 | 2019-02-18 10:41:14 +0530 | [diff] [blame] | 121 | std::atomic_uint64_t mOutIndex; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 122 | |
| 123 | // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid |
| 124 | // converting them to C2 values for each frame |
| 125 | struct VuiColorAspects { |
| 126 | uint8_t primaries; |
| 127 | uint8_t transfer; |
| 128 | uint8_t coeffs; |
| 129 | uint8_t fullRange; |
| 130 | |
| 131 | // default color aspects |
| 132 | VuiColorAspects() |
| 133 | : primaries(2), transfer(2), coeffs(2), fullRange(0) { } |
| 134 | |
Satish Yalla | 892344a | 2024-06-11 01:36:45 +0000 | [diff] [blame] | 135 | bool operator==(const VuiColorAspects &o) { |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 136 | return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs |
| 137 | && fullRange == o.fullRange; |
| 138 | } |
| 139 | } mBitstreamColorAspects; |
| 140 | |
| 141 | // profile |
Ray Essick | 2475494 | 2022-04-16 09:50:35 -0700 | [diff] [blame] | 142 | nsecs_t mTimeStart = 0; |
| 143 | nsecs_t mTimeEnd = 0; |
Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 144 | |
| 145 | C2_DO_NOT_COPY(C2SoftHevcDec); |
| 146 | }; |
| 147 | |
| 148 | } // namespace android |
| 149 | |
| 150 | #endif // ANDROID_C2_SOFT_HEVC_DEC_H_ |