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