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 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#define MAX_MEM_ALLOCS 100 30#define MAX_CHANNEL_COUNT 8 /* maximum number of audio channels that can be decoded */ 31#define MAX_NUM_BLOCKS 8 /* maximum number of audio blocks that can be decoded */ 32 33extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, 34 WORD32 i_cmd, WORD32 i_idx, pVOID pv_value); 35 36namespace android { 37 38struct C2SoftXaacDec : public SimpleC2Component { 39 class IntfImpl; 40 41 C2SoftXaacDec(const char* name, c2_node_id_t id, 42 const std::shared_ptr<IntfImpl>& intfImpl); 43 virtual ~C2SoftXaacDec(); 44 45 // From SimpleC2Component 46 c2_status_t onInit() override; 47 c2_status_t onStop() override; 48 void onReset() override; 49 void onRelease() override; 50 c2_status_t onFlush_sm() override; 51 void process( 52 const std::unique_ptr<C2Work> &work, 53 const std::shared_ptr<C2BlockPool> &pool) override; 54 c2_status_t drain( 55 uint32_t drainMode, 56 const std::shared_ptr<C2BlockPool> &pool) override; 57 58private: 59 enum { 60 kOutputDrainBufferSize = 2048 * MAX_CHANNEL_COUNT * MAX_NUM_BLOCKS, 61 }; 62 63 std::shared_ptr<IntfImpl> mIntf; 64 void* mXheaacCodecHandle; 65 uint32_t mInputBufferSize; 66 uint32_t mOutputFrameLength; 67 int8_t* mInputBuffer; 68 int8_t* mOutputBuffer; 69 int32_t mSampFreq; 70 int32_t mNumChannels; 71 int32_t mPcmWdSz; 72 int32_t mChannelMask; 73 int32_t mNumOutBytes; 74 uint64_t mCurFrameIndex; 75 uint64_t mCurTimestamp; 76 bool mIsCodecInitialized; 77 bool mIsCodecConfigFlushRequired; 78 79 void* mMemoryArray[MAX_MEM_ALLOCS]; 80 int32_t mMallocCount; 81 82 size_t mInputBufferCount __unused; 83 size_t mOutputBufferCount __unused; 84 bool mSignalledOutputEos; 85 bool mSignalledError; 86 short* mOutputDrainBuffer; 87 uint32_t mOutputDrainBufferWritePos; 88 89 status_t initDecoder(); 90 void configflushDecode(); 91 int drainDecoder(); 92 93 void finishWork(const std::unique_ptr<C2Work>& work, 94 const std::shared_ptr<C2BlockPool>& pool); 95 96 status_t initXAACDrc(); 97 int initXAACDecoder(); 98 int deInitXAACDecoder(); 99 int configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength); 100 int decodeXAACStream(uint8_t* inBuffer, 101 uint32_t inBufferLength, 102 int32_t* bytesConsumed, 103 int32_t* outBytes); 104 IA_ERRORCODE getXAACStreamInfo(); 105 106 C2_DO_NOT_COPY(C2SoftXaacDec); 107}; 108 109} // namespace android 110 111#endif // C2_SOFT_XAAC_H_ 112