xref: /aosp_15_r20/frameworks/av/media/libstagefright/codecs/xaacdec/SoftXAAC.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 SOFTXAAC_H_
18 #define SOFTXAAC_H_
19 
20 #include <media/stagefright/omx/SimpleSoftOMXComponent.h>
21 
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 
26 #include "ixheaacd_type_def.h"
27 #include "ixheaacd_error_standards.h"
28 #include "ixheaacd_error_handler.h"
29 #include "ixheaacd_apicmd_standards.h"
30 #include "ixheaacd_memory_standards.h"
31 #include "ixheaacd_aac_config.h"
32 
33 #include "impd_apicmd_standards.h"
34 #include "impd_drc_config_params.h"
35 
36 extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
37                                          pVOID pv_value);
38 extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
39                                        pVOID pv_value);
40 extern "C" IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj, pWORD32 pi_samp_freq,
41                                                   pWORD32 pi_num_chan, pWORD32 pi_pcm_wd_sz,
42                                                   pWORD32 pi_channel_mask);
43 
44 namespace android {
45 
46 struct SoftXAAC : public SimpleSoftOMXComponent {
47     SoftXAAC(const char* name, const OMX_CALLBACKTYPE* callbacks, OMX_PTR appData,
48              OMX_COMPONENTTYPE** component);
49 
50    protected:
51     virtual ~SoftXAAC();
52 
53     virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params);
54 
55     virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params);
56 
57     virtual void onQueueFilled(OMX_U32 portIndex);
58     virtual void onPortFlushCompleted(OMX_U32 portIndex);
59     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
60     virtual void onReset();
61 
62    private:
63     enum {
64         kNumInputBuffers = 4,
65         kNumOutputBuffers = 4,
66         kNumDelayBlocksMax = 8,
67     };
68 
69     bool mIsADTS;
70     size_t mInputBufferCount;
71     size_t mOutputBufferCount;
72     bool mSignalledError;
73     OMX_BUFFERHEADERTYPE* mLastInHeader;
74     int64_t mPrevTimestamp;
75     int64_t mCurrentTimestamp;
76     uint32_t mBufSize;
77 
78     enum { NONE, AWAITING_DISABLED, AWAITING_ENABLED } mOutputPortSettingsChange;
79 
80     void initPorts();
81     IA_ERRORCODE initDecoder();
82     bool isConfigured() const;
83     IA_ERRORCODE drainDecoder();
84     IA_ERRORCODE initXAACDecoder();
85     IA_ERRORCODE deInitXAACDecoder();
86     IA_ERRORCODE initMPEGDDDrc();
87     IA_ERRORCODE deInitMPEGDDDrc();
88     IA_ERRORCODE configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength);
89     IA_ERRORCODE configMPEGDDrc();
90     IA_ERRORCODE decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength,
91                                   int32_t* bytesConsumed, int32_t* outBytes);
92 
93     IA_ERRORCODE configflushDecode();
94     IA_ERRORCODE getXAACStreamInfo();
95     IA_ERRORCODE setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, int32_t drcRefLevel,
96                                 int32_t drcHeavyCompression
97 #ifdef ENABLE_MPEG_D_DRC
98                                 ,
99                                 int32_t drEffectType
100 #endif
101     );
102 
103     bool mEndOfInput;
104     bool mEndOfOutput;
105 
106     void* mXheaacCodecHandle;
107     void* mMpegDDrcHandle;
108     uint32_t mInputBufferSize;
109     uint32_t mOutputFrameLength;
110     int8_t* mInputBuffer;
111     int8_t* mOutputBuffer;
112     int32_t mSampFreq;
113     int32_t mNumChannels;
114     int32_t mPcmWdSz;
115     int32_t mChannelMask;
116     bool mIsCodecInitialized;
117     bool mIsCodecConfigFlushRequired;
118     int8_t* mDrcInBuf;
119     int8_t* mDrcOutBuf;
120     int32_t mMpegDDRCPresent;
121     int32_t mDRCFlag;
122     Vector<void*> mMemoryVec;
123     Vector<void*> mDrcMemoryVec;
124 
125     DISALLOW_EVIL_CONSTRUCTORS(SoftXAAC);
126 };
127 
128 }  // namespace android
129 
130 #endif  // SOFTXAAC_H_
131