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