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 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 virtual ~C2SoftAacDec(); 33 34 // From SimpleC2Component 35 c2_status_t onInit() override; 36 c2_status_t onStop() override; 37 void onReset() override; 38 void onRelease() override; 39 c2_status_t onFlush_sm() override; 40 void process( 41 const std::unique_ptr<C2Work> &work, 42 const std::shared_ptr<C2BlockPool> &pool) override; 43 c2_status_t drain( 44 uint32_t drainMode, 45 const std::shared_ptr<C2BlockPool> &pool) override; 46 47 private: 48 enum { 49 kNumDelayBlocksMax = 8, 50 }; 51 52 std::shared_ptr<IntfImpl> mIntf; 53 54 HANDLE_AACDECODER mAACDecoder; 55 CStreamInfo *mStreamInfo; 56 bool mIsFirst; 57 size_t mInputBufferCount; 58 size_t mOutputBufferCount; 59 bool mSignalledError; 60 size_t mOutputPortDelay; 61 struct Info { 62 uint64_t frameIndex; 63 size_t bufferSize; 64 uint64_t timestamp; 65 std::vector<int32_t> decodedSizes; 66 }; 67 std::list<Info> mBuffersInfo; 68 69 CDrcPresModeWrapper mDrcWrap; 70 71 enum { 72 NONE, 73 AWAITING_DISABLED, 74 AWAITING_ENABLED 75 } mOutputPortSettingsChange; 76 77 void initPorts(); 78 status_t initDecoder(); 79 bool isConfigured() const; 80 void drainDecoder(); 81 82 void drainRingBuffer( 83 const std::unique_ptr<C2Work> &work, 84 const std::shared_ptr<C2BlockPool> &pool, 85 bool eos); 86 c2_status_t drainInternal( 87 uint32_t drainMode, 88 const std::shared_ptr<C2BlockPool> &pool, 89 const std::unique_ptr<C2Work> &work); 90 91 // delay compensation 92 bool mEndOfInput; 93 bool mEndOfOutput; 94 int32_t mOutputDelayCompensated; 95 int32_t mOutputDelayRingBufferSize; 96 short *mOutputDelayRingBuffer; 97 int32_t mOutputDelayRingBufferWritePos; 98 int32_t mOutputDelayRingBufferReadPos; 99 int32_t mOutputDelayRingBufferFilled; 100 bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples); 101 int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples); 102 int32_t outputDelayRingBufferSamplesAvailable(); 103 int32_t outputDelayRingBufferSpaceLeft(); 104 105 C2_DO_NOT_COPY(C2SoftAacDec); 106 }; 107 108 } // namespace android 109 110 #endif // ANDROID_C2_SOFT_AAC_DEC_H_ 111