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