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_XAAC_DEC_H_ 18 #define ANDROID_C2_SOFT_XAAC_DEC_H_ 19 #include <utils/Vector.h> 20 #include <SimpleC2Component.h> 21 #include <util/C2InterfaceHelper.h> 22 23 #include "ixheaacd_type_def.h" 24 #include "ixheaacd_error_standards.h" 25 #include "ixheaacd_error_handler.h" 26 #include "ixheaacd_apicmd_standards.h" 27 #include "ixheaacd_memory_standards.h" 28 #include "ixheaacd_aac_config.h" 29 30 #include "impd_apicmd_standards.h" 31 #include "impd_drc_config_params.h" 32 33 #define MAX_CHANNEL_COUNT 8 /* maximum number of audio channels that can be decoded */ 34 #define MAX_NUM_BLOCKS 8 /* maximum number of audio blocks that can be decoded */ 35 36 extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, 37 WORD32 i_cmd, WORD32 i_idx, pVOID pv_value); 38 extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, 39 WORD32 i_cmd, WORD32 i_idx, pVOID pv_value); 40 extern "C" IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj, 41 pWORD32 pi_samp_freq, 42 pWORD32 pi_num_chan, 43 pWORD32 pi_pcm_wd_sz, 44 pWORD32 pi_channel_mask); 45 46 namespace android { 47 48 struct C2SoftXaacDec : public SimpleC2Component { 49 class IntfImpl; 50 51 C2SoftXaacDec(const char* name, c2_node_id_t id, 52 const std::shared_ptr<IntfImpl>& intfImpl); 53 C2SoftXaacDec(const char* name, c2_node_id_t id, 54 const std::shared_ptr<C2ReflectorHelper>& helper); 55 virtual ~C2SoftXaacDec(); 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 70 private: 71 enum { 72 kOutputDrainBufferSize = 2048 * MAX_CHANNEL_COUNT * MAX_NUM_BLOCKS, 73 }; 74 75 std::shared_ptr<IntfImpl> mIntf; 76 void* mXheaacCodecHandle; 77 void* mMpegDDrcHandle; 78 uint32_t mInputBufferSize; 79 uint32_t mOutputFrameLength; 80 int8_t* mInputBuffer; 81 int8_t* mOutputBuffer; 82 int32_t mSampFreq; 83 int32_t mNumChannels; 84 int32_t mPcmWdSz; 85 int32_t mChannelMask; 86 int32_t mNumOutBytes; 87 uint64_t mCurFrameIndex; 88 uint64_t mCurTimestamp; 89 bool mIsCodecInitialized; 90 bool mIsCodecConfigFlushRequired; 91 int8_t* mDrcInBuf; 92 int8_t* mDrcOutBuf; 93 int32_t mMpegDDRCPresent; 94 int32_t mDRCFlag; 95 96 Vector<void*> mMemoryVec; 97 Vector<void*> mDrcMemoryVec; 98 99 size_t mInputBufferCount __unused; 100 size_t mOutputBufferCount __unused; 101 bool mSignalledOutputEos; 102 bool mSignalledError; 103 char* mOutputDrainBuffer; 104 uint32_t mOutputDrainBufferWritePos; 105 106 IA_ERRORCODE initDecoder(); 107 IA_ERRORCODE setDrcParameter(); 108 IA_ERRORCODE configflushDecode(); 109 IA_ERRORCODE drainDecoder(); 110 void finishWork(const std::unique_ptr<C2Work>& work, 111 const std::shared_ptr<C2BlockPool>& pool); 112 113 IA_ERRORCODE initXAACDrc(); 114 IA_ERRORCODE initXAACDecoder(); 115 IA_ERRORCODE deInitXAACDecoder(); 116 IA_ERRORCODE initMPEGDDDrc(); 117 IA_ERRORCODE deInitMPEGDDDrc(); 118 IA_ERRORCODE configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength); 119 int configMPEGDDrc(); 120 IA_ERRORCODE decodeXAACStream(uint8_t* inBuffer, 121 uint32_t inBufferLength, 122 int32_t* bytesConsumed, 123 int32_t* outBytes); 124 IA_ERRORCODE getXAACStreamInfo(); 125 IA_ERRORCODE setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, 126 int32_t drcRefLevel, int32_t drcHeavyCompression, 127 int32_t drEffectType); 128 129 C2_DO_NOT_COPY(C2SoftXaacDec); 130 }; 131 132 } // namespace android 133 134 #endif // C2_SOFT_XAAC_H_ 135