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