1 /* 2 * Copyright (C) 2017 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_AAC_DEC_H_ 18 #define ANDROID_C2_SOFT_AAC_DEC_H_ 19 20 #include <SimpleC2Component.h> 21 #include <util/C2InterfaceHelper.h> 22 23 #include "aacdecoder_lib.h" 24 #include "DrcPresModeWrap.h" 25 26 namespace android { 27 28 struct C2SoftAacDec : public SimpleC2Component { 29 class IntfImpl; 30 31 C2SoftAacDec(const char *name, c2_node_id_t id, const std::shared_ptr<IntfImpl> &intfImpl); 32 C2SoftAacDec(const char *name, c2_node_id_t id, 33 const std::shared_ptr<C2ReflectorHelper> &helper); 34 virtual ~C2SoftAacDec(); 35 36 // From SimpleC2Component 37 c2_status_t onInit() override; 38 c2_status_t onStop() override; 39 void onReset() override; 40 void onRelease() override; 41 c2_status_t onFlush_sm() override; 42 void process( 43 const std::unique_ptr<C2Work> &work, 44 const std::shared_ptr<C2BlockPool> &pool) override; 45 c2_status_t drain( 46 uint32_t drainMode, 47 const std::shared_ptr<C2BlockPool> &pool) override; 48 49 private: 50 enum { 51 kNumDelayBlocksMax = 8, 52 }; 53 54 std::shared_ptr<IntfImpl> mIntf; 55 56 HANDLE_AACDECODER mAACDecoder; 57 CStreamInfo *mStreamInfo; 58 bool mIsFirst; 59 size_t mInputBufferCount; 60 size_t mOutputBufferCount; 61 bool mSignalledError; 62 size_t mOutputPortDelay; 63 struct Info { 64 uint64_t frameIndex; 65 size_t bufferSize; 66 uint64_t timestamp; 67 std::vector<int32_t> decodedSizes; 68 }; 69 std::list<Info> mBuffersInfo; 70 71 CDrcPresModeWrapper mDrcWrap; 72 73 enum { 74 NONE, 75 AWAITING_DISABLED, 76 AWAITING_ENABLED 77 } mOutputPortSettingsChange; 78 79 void initPorts(); 80 status_t initDecoder(); 81 bool isConfigured() const; 82 void drainDecoder(); 83 84 void drainRingBuffer( 85 const std::unique_ptr<C2Work> &work, 86 const std::shared_ptr<C2BlockPool> &pool, 87 bool eos); 88 c2_status_t drainInternal( 89 uint32_t drainMode, 90 const std::shared_ptr<C2BlockPool> &pool, 91 const std::unique_ptr<C2Work> &work); 92 93 // delay compensation 94 bool mEndOfInput; 95 bool mEndOfOutput; 96 int32_t mOutputDelayCompensated; 97 int32_t mOutputDelayRingBufferSize; 98 std::unique_ptr<short[]> mOutputDelayRingBuffer; 99 int32_t mOutputDelayRingBufferWritePos; 100 int32_t mOutputDelayRingBufferReadPos; 101 int32_t mOutputDelayRingBufferFilled; 102 int mDeviceApiLevel; 103 bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples); 104 int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples); 105 int32_t outputDelayRingBufferSamplesAvailable(); 106 int32_t outputDelayRingBufferSpaceLeft(); 107 uint32_t maskFromCount(uint32_t channelCount); 108 109 C2_DO_NOT_COPY(C2SoftAacDec); 110 }; 111 112 } // namespace android 113 114 #endif // ANDROID_C2_SOFT_AAC_DEC_H_ 115