xref: /aosp_15_r20/frameworks/av/media/libstagefright/codecs/aacdec/SoftAAC2.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright (C) 2012 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 SOFT_AAC_2_H_
18 #define SOFT_AAC_2_H_
19 
20 #include <media/stagefright/omx/SimpleSoftOMXComponent.h>
21 
22 #include "aacdecoder_lib.h"
23 #include "DrcPresModeWrap.h"
24 
25 namespace android {
26 
27 struct SoftAAC2 : public SimpleSoftOMXComponent {
28     SoftAAC2(const char *name,
29             const OMX_CALLBACKTYPE *callbacks,
30             OMX_PTR appData,
31             OMX_COMPONENTTYPE **component);
32 
33 protected:
34     virtual ~SoftAAC2();
35 
36     virtual OMX_ERRORTYPE internalGetParameter(
37             OMX_INDEXTYPE index, OMX_PTR params);
38 
39     virtual OMX_ERRORTYPE internalSetParameter(
40             OMX_INDEXTYPE index, const OMX_PTR params);
41 
42     virtual void onQueueFilled(OMX_U32 portIndex);
43     virtual void onPortFlushCompleted(OMX_U32 portIndex);
44     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
45     virtual void onReset();
46 
47 private:
48     enum {
49         kNumInputBuffers        = 4,
50         kNumOutputBuffers       = 4,
51         kNumDelayBlocksMax      = 8,
52     };
53 
54     HANDLE_AACDECODER mAACDecoder;
55     CStreamInfo *mStreamInfo;
56     bool mIsADTS;
57     bool mIsFirst;
58     size_t mInputBufferCount;
59     size_t mOutputBufferCount;
60     bool mSignalledError;
61     OMX_BUFFERHEADERTYPE *mLastInHeader;
62     Vector<int32_t> mBufferSizes;
63     Vector<int32_t> mDecodedSizes;
64     Vector<int64_t> mBufferTimestamps;
65 
66     CDrcPresModeWrapper mDrcWrap;
67 
68     enum {
69         NONE,
70         AWAITING_DISABLED,
71         AWAITING_ENABLED
72     } mOutputPortSettingsChange;
73 
74     void initPorts();
75     status_t initDecoder();
76     bool isConfigured() const;
77     void drainDecoder();
78 
79 //      delay compensation
80     bool mEndOfInput;
81     bool mEndOfOutput;
82     int32_t mOutputDelayCompensated;
83     int32_t mOutputDelayRingBufferSize;
84     int16_t *mOutputDelayRingBuffer;
85     int32_t mOutputDelayRingBufferWritePos;
86     int32_t mOutputDelayRingBufferReadPos;
87     int32_t mOutputDelayRingBufferFilled;
88 
89     //drc
90     int32_t mDrcCompressMode;
91     int32_t mDrcTargetRefLevel;
92     int32_t mDrcEncTargetLevel;
93     int32_t mDrcBoostFactor;
94     int32_t mDrcAttenuationFactor;
95     int32_t mDrcEffectType;
96     int32_t mDrcAlbumMode;
97     int32_t mDrcOutputLoudness;
98 
99     bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples);
100     int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples);
101     int32_t outputDelayRingBufferSamplesAvailable();
102     int32_t outputDelayRingBufferSpaceLeft();
103 
104     DISALLOW_EVIL_CONSTRUCTORS(SoftAAC2);
105 };
106 
107 }  // namespace android
108 
109 #endif  // SOFT_AAC_2_H_
110